* Add/update the CssRule. * @param {String} selectors Selector string, eg. `.myclass` * @param {Object} style Style properties and values. If the rule exists, styles will be replaced unless `addStyles` option is used. * @param {Object} [opts={}] Additional properties. * @param {String}
(selectors: any, style: CssRuleProperties['style'] = {}, opts: SetRuleOptions = {})
| 391 | * // output: .class1 { color: blue; background: red } |
| 392 | */ |
| 393 | setRule(selectors: any, style: CssRuleProperties['style'] = {}, opts: SetRuleOptions = {}) { |
| 394 | const { atRuleType, atRuleParams } = opts; |
| 395 | const node = this.em.Parser.parserCss.checkNode({ |
| 396 | selectors, |
| 397 | style, |
| 398 | })[0]; |
| 399 | const { state, selectorsAdd } = node; |
| 400 | const sm = this.em.Selectors; |
| 401 | const selector = sm.add(node.selectors as any); |
| 402 | const rule = this.add(selector, state, atRuleParams, { |
| 403 | selectorsAdd, |
| 404 | atRule: atRuleType, |
| 405 | }); |
| 406 | |
| 407 | if (opts.addStyles) { |
| 408 | rule.addStyle(style, opts); |
| 409 | } else { |
| 410 | rule.setStyle(style, opts); |
| 411 | } |
| 412 | |
| 413 | return rule; |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * Get the CssRule. |