| 12 | * Conditional rule for @media, @supports |
| 13 | */ |
| 14 | export class ConditionalRule { |
| 15 | type = 'conditional' |
| 16 | |
| 17 | isProcessed = false |
| 18 | |
| 19 | constructor(key, styles, options) { |
| 20 | this.key = key |
| 21 | const atMatch = key.match(atRegExp) |
| 22 | this.at = atMatch ? atMatch[1] : 'unknown' |
| 23 | // Key might contain a unique suffix in case the `name` passed by user was duplicate. |
| 24 | this.query = options.name || `@${this.at}` |
| 25 | this.options = options |
| 26 | this.rules = new RuleList({...options, parent: this}) |
| 27 | |
| 28 | for (const name in styles) { |
| 29 | this.rules.add(name, styles[name]) |
| 30 | } |
| 31 | |
| 32 | this.rules.process() |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Get a rule. |
| 37 | */ |
| 38 | getRule(name) { |
| 39 | return this.rules.get(name) |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get index of a rule. |
| 44 | */ |
| 45 | indexOf(rule) { |
| 46 | return this.rules.indexOf(rule) |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Create and register rule, run plugins. |
| 51 | */ |
| 52 | addRule(name, style, options) { |
| 53 | const rule = this.rules.add(name, style, options) |
| 54 | if (!rule) return null |
| 55 | this.options.jss.plugins.onProcessRule(rule) |
| 56 | return rule |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Replace rule, run plugins. |
| 61 | */ |
| 62 | replaceRule(name, style, options) { |
| 63 | const newRule = this.rules.replace(name, style, options) |
| 64 | if (newRule) this.options.jss.plugins.onProcessRule(newRule) |
| 65 | return newRule |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Generates a CSS string. |
| 70 | */ |
| 71 | toString(options = defaultToStringOptions) { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…