diff options
| author | Adam Mathes <adam@adammathes.com> | 2026-02-13 21:34:48 -0800 |
|---|---|---|
| committer | Adam Mathes <adam@adammathes.com> | 2026-02-13 21:34:48 -0800 |
| commit | 76cb9c2a39d477a64824a985ade40507e3bbade1 (patch) | |
| tree | 41e997aa9c6f538d3a136af61dae9424db2005a9 /vanilla/node_modules/@acemir/cssom/lib/CSSStyleRule.js | |
| parent | 819a39a21ac992b1393244a4c283bbb125208c69 (diff) | |
| download | neko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.gz neko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.bz2 neko-76cb9c2a39d477a64824a985ade40507e3bbade1.zip | |
feat(vanilla): add testing infrastructure and tests (NK-wjnczv)
Diffstat (limited to 'vanilla/node_modules/@acemir/cssom/lib/CSSStyleRule.js')
| -rw-r--r-- | vanilla/node_modules/@acemir/cssom/lib/CSSStyleRule.js | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/vanilla/node_modules/@acemir/cssom/lib/CSSStyleRule.js b/vanilla/node_modules/@acemir/cssom/lib/CSSStyleRule.js new file mode 100644 index 0000000..a7c81d0 --- /dev/null +++ b/vanilla/node_modules/@acemir/cssom/lib/CSSStyleRule.js @@ -0,0 +1,109 @@ +//.CommonJS +var CSSOM = { + CSSStyleDeclaration: require("./CSSStyleDeclaration").CSSStyleDeclaration, + CSSRule: require("./CSSRule").CSSRule, + CSSRuleList: require("./CSSRuleList").CSSRuleList, + CSSGroupingRule: require("./CSSGroupingRule").CSSGroupingRule, +}; +var regexPatterns = require("./regexPatterns").regexPatterns; +// Use cssstyle if available +try { + CSSOM.CSSStyleDeclaration = require("cssstyle").CSSStyleDeclaration; +} catch (e) { + // ignore +} +///CommonJS + + +/** + * @constructor + * @see http://dev.w3.org/csswg/cssom/#cssstylerule + * @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleRule + */ +CSSOM.CSSStyleRule = function CSSStyleRule() { + CSSOM.CSSGroupingRule.call(this); + this.__selectorText = ""; + this.__style = new CSSOM.CSSStyleDeclaration(); + this.__style.parentRule = this; +}; + +CSSOM.CSSStyleRule.prototype = Object.create(CSSOM.CSSGroupingRule.prototype); +CSSOM.CSSStyleRule.prototype.constructor = CSSOM.CSSStyleRule; + +Object.setPrototypeOf(CSSOM.CSSStyleRule, CSSOM.CSSGroupingRule); + +Object.defineProperty(CSSOM.CSSStyleRule.prototype, "type", { + value: 1, + writable: false +}); + +Object.defineProperty(CSSOM.CSSStyleRule.prototype, "selectorText", { + get: function() { + return this.__selectorText; + }, + set: function(value) { + if (typeof value === "string") { + // Don't trim if the value ends with a hex escape sequence followed by space + // (e.g., ".\31 " where the space is part of the escape terminator) + var endsWithHexEscapeRegExp = regexPatterns.endsWithHexEscapeRegExp; + var endsWithEscape = endsWithHexEscapeRegExp.test(value); + var trimmedValue = endsWithEscape ? value.replace(/\s+$/, ' ').trimStart() : value.trim(); + + if (trimmedValue === '') { + return; + } + + // TODO: Setting invalid selectorText should be ignored + // There are some validations already on lib/parse.js + // but the same validations should be applied here. + // Check if we can move these validation logic to a shared function. + + this.__selectorText = trimmedValue; + } + }, + configurable: true +}); + +Object.defineProperty(CSSOM.CSSStyleRule.prototype, "style", { + get: function() { + return this.__style; + }, + set: function(value) { + if (typeof value === "string") { + this.__style.cssText = value; + } else { + this.__style = value; + } + }, + configurable: true +}); + +Object.defineProperty(CSSOM.CSSStyleRule.prototype, "cssText", { + get: function() { + var text; + if (this.selectorText) { + var values = ""; + if (this.cssRules.length) { + var valuesArr = [" {"]; + this.style.cssText && valuesArr.push(this.style.cssText); + valuesArr.push(this.cssRules.reduce(function(acc, rule){ + if (rule.cssText !== "") { + acc.push(rule.cssText); + } + return acc; + }, []).join("\n ")); + values = valuesArr.join("\n ") + "\n}"; + } else { + values = " {" + (this.style.cssText ? " " + this.style.cssText : "") + " }"; + } + text = this.selectorText + values; + } else { + text = ""; + } + return text; + } +}); + +//.CommonJS +exports.CSSStyleRule = CSSOM.CSSStyleRule; +///CommonJS |
