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/CSSPropertyRule.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/CSSPropertyRule.js')
| -rw-r--r-- | vanilla/node_modules/@acemir/cssom/lib/CSSPropertyRule.js | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/vanilla/node_modules/@acemir/cssom/lib/CSSPropertyRule.js b/vanilla/node_modules/@acemir/cssom/lib/CSSPropertyRule.js new file mode 100644 index 0000000..892bb59 --- /dev/null +++ b/vanilla/node_modules/@acemir/cssom/lib/CSSPropertyRule.js @@ -0,0 +1,122 @@ +//.CommonJS +var CSSOM = { + CSSRule: require("./CSSRule").CSSRule +}; +///CommonJS + + +/** + * @constructor + * @see https://drafts.css-houdini.org/css-properties-values-api/#the-css-property-rule-interface + */ +CSSOM.CSSPropertyRule = function CSSPropertyRule() { + CSSOM.CSSRule.call(this); + this.__name = ""; + this.__syntax = ""; + this.__inherits = false; + this.__initialValue = null; +}; + +CSSOM.CSSPropertyRule.prototype = Object.create(CSSOM.CSSRule.prototype); +CSSOM.CSSPropertyRule.prototype.constructor = CSSOM.CSSPropertyRule; + +Object.setPrototypeOf(CSSOM.CSSPropertyRule, CSSOM.CSSRule); + +Object.defineProperty(CSSOM.CSSPropertyRule.prototype, "type", { + value: 0, + writable: false +}); + +Object.defineProperty(CSSOM.CSSPropertyRule.prototype, "cssText", { + get: function() { + var text = "@property " + this.name + " {"; + if (this.syntax !== "") { + text += " syntax: \"" + this.syntax.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + "\";"; + } + text += " inherits: " + (this.inherits ? "true" : "false") + ";"; + if (this.initialValue !== null) { + text += " initial-value: " + this.initialValue + ";"; + } + text += " }"; + return text; + } +}); + +Object.defineProperty(CSSOM.CSSPropertyRule.prototype, "name", { + get: function() { + return this.__name; + } +}); + +Object.defineProperty(CSSOM.CSSPropertyRule.prototype, "syntax", { + get: function() { + return this.__syntax; + } +}); + +Object.defineProperty(CSSOM.CSSPropertyRule.prototype, "inherits", { + get: function() { + return this.__inherits; + } +}); + +Object.defineProperty(CSSOM.CSSPropertyRule.prototype, "initialValue", { + get: function() { + return this.__initialValue; + } +}); + +/** + * NON-STANDARD + * Rule text parser. + * @param {string} cssText + * @returns {boolean} True if the rule is valid and was parsed successfully + */ +Object.defineProperty(CSSOM.CSSPropertyRule.prototype, "parse", { + value: function(cssText) { + // Extract the name from "@property <name> { ... }" + var match = cssText.match(/@property\s+(--[^\s{]+)\s*\{([^]*)\}/); + if (!match) { + return false; + } + + this.__name = match[1]; + var bodyText = match[2]; + + // Parse syntax descriptor (REQUIRED) + var syntaxMatch = bodyText.match(/syntax\s*:\s*(['"])([^]*?)\1\s*;/); + if (!syntaxMatch) { + return false; // syntax is required + } + this.__syntax = syntaxMatch[2]; + + // Syntax cannot be empty + if (this.__syntax === "") { + return false; + } + + // Parse inherits descriptor (REQUIRED) + var inheritsMatch = bodyText.match(/inherits\s*:\s*(true|false)\s*;/); + if (!inheritsMatch) { + return false; // inherits is required + } + this.__inherits = inheritsMatch[1] === "true"; + + // Parse initial-value descriptor (OPTIONAL, but required if syntax is not "*") + var initialValueMatch = bodyText.match(/initial-value\s*:\s*([^;]+);/); + if (initialValueMatch) { + this.__initialValue = initialValueMatch[1].trim(); + } else { + // If syntax is not "*", initial-value is required + if (this.__syntax !== "*") { + return false; + } + } + + return true; // Successfully parsed + } +}); + +//.CommonJS +exports.CSSPropertyRule = CSSOM.CSSPropertyRule; +///CommonJS |
