| 14 | * Rule for @keyframes |
| 15 | */ |
| 16 | export class KeyframesRule { |
| 17 | type = 'keyframes' |
| 18 | |
| 19 | at = '@keyframes' |
| 20 | |
| 21 | isProcessed = false |
| 22 | |
| 23 | constructor(key, frames, options) { |
| 24 | const nameMatch = key.match(nameRegExp) |
| 25 | if (nameMatch && nameMatch[1]) { |
| 26 | this.name = nameMatch[1] |
| 27 | } else { |
| 28 | this.name = 'noname' |
| 29 | warning(false, `[JSS] Bad keyframes name ${key}`) |
| 30 | } |
| 31 | this.key = `${this.type}-${this.name}` |
| 32 | this.options = options |
| 33 | const {scoped, sheet, generateId} = options |
| 34 | this.id = scoped === false ? this.name : escape(generateId(this, sheet)) |
| 35 | this.rules = new RuleList({...options, parent: this}) |
| 36 | |
| 37 | for (const name in frames) { |
| 38 | this.rules.add(name, frames[name], { |
| 39 | ...options, |
| 40 | parent: this |
| 41 | }) |
| 42 | } |
| 43 | |
| 44 | this.rules.process() |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Generates a CSS string. |
| 49 | */ |
| 50 | toString(options = defaultToStringOptions) { |
| 51 | const {linebreak} = getWhitespaceSymbols(options) |
| 52 | if (options.indent == null) options.indent = defaultToStringOptions.indent |
| 53 | if (options.children == null) options.children = defaultToStringOptions.children |
| 54 | if (options.children === false) { |
| 55 | return `${this.at} ${this.id} {}` |
| 56 | } |
| 57 | let children = this.rules.toString(options) |
| 58 | if (children) children = `${linebreak}${children}${linebreak}` |
| 59 | return `${this.at} ${this.id} {${children}}` |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | const keyRegExp = /@keyframes\s+/ |
| 64 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…