mirror of
https://github.com/idanoo/GoScrobble
synced 2025-07-03 06:32:19 +00:00
0.2.0 - Mid migration
This commit is contained in:
parent
139e6a915e
commit
7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions
92
web/node_modules/jss/src/plugins/conditionalRule.js
generated
vendored
Normal file
92
web/node_modules/jss/src/plugins/conditionalRule.js
generated
vendored
Normal file
|
@ -0,0 +1,92 @@
|
|||
// @flow
|
||||
import RuleList from '../RuleList'
|
||||
import type {CSSMediaRule, Rule, RuleOptions, ToCssOptions, JssStyle, ContainerRule} from '../types'
|
||||
|
||||
const defaultToStringOptions = {
|
||||
indent: 1,
|
||||
children: true
|
||||
}
|
||||
|
||||
const atRegExp = /@([\w-]+)/
|
||||
|
||||
/**
|
||||
* Conditional rule for @media, @supports
|
||||
*/
|
||||
export class ConditionalRule implements ContainerRule {
|
||||
type: string = 'conditional'
|
||||
|
||||
at: string
|
||||
|
||||
key: string
|
||||
|
||||
query: string
|
||||
|
||||
rules: RuleList
|
||||
|
||||
options: RuleOptions
|
||||
|
||||
isProcessed: boolean = false
|
||||
|
||||
renderable: ?CSSMediaRule
|
||||
|
||||
constructor(key: string, styles: Object, options: RuleOptions) {
|
||||
this.key = key
|
||||
const atMatch = key.match(atRegExp)
|
||||
this.at = atMatch ? atMatch[1] : 'unknown'
|
||||
// Key might contain a unique suffix in case the `name` passed by user was duplicate.
|
||||
this.query = options.name || `@${this.at}`
|
||||
this.options = options
|
||||
this.rules = new RuleList({...options, parent: this})
|
||||
|
||||
for (const name in styles) {
|
||||
this.rules.add(name, styles[name])
|
||||
}
|
||||
|
||||
this.rules.process()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a rule.
|
||||
*/
|
||||
getRule(name: string): Rule {
|
||||
return this.rules.get(name)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get index of a rule.
|
||||
*/
|
||||
indexOf(rule: Rule): number {
|
||||
return this.rules.indexOf(rule)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and register rule, run plugins.
|
||||
*/
|
||||
addRule(name: string, style: JssStyle, options?: RuleOptions): Rule | null {
|
||||
const rule = this.rules.add(name, style, options)
|
||||
if (!rule) return null
|
||||
this.options.jss.plugins.onProcessRule(rule)
|
||||
return rule
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a CSS string.
|
||||
*/
|
||||
toString(options?: ToCssOptions = defaultToStringOptions): string {
|
||||
if (options.indent == null) options.indent = defaultToStringOptions.indent
|
||||
if (options.children == null) options.children = defaultToStringOptions.children
|
||||
if (options.children === false) {
|
||||
return `${this.query} {}`
|
||||
}
|
||||
const children = this.rules.toString(options)
|
||||
return children ? `${this.query} {\n${children}\n}` : ''
|
||||
}
|
||||
}
|
||||
|
||||
const keyRegExp = /@media|@supports\s+/
|
||||
|
||||
export default {
|
||||
onCreateRule(key: string, styles: JssStyle, options: RuleOptions): ConditionalRule | null {
|
||||
return keyRegExp.test(key) ? new ConditionalRule(key, styles, options) : null
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue