MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / fromCSS

Method fromCSS

src/theme/builder.js:306–324  ·  view source on GitHub ↗

* Creates a theme from a CSS string * @param {string} name * @param {string} css * @returns {ThemeBuilder}

(name, css)

Source from the content-addressed store, hash-verified

304 * @returns {ThemeBuilder}
305 */
306 static fromCSS(name, css) {
307 const themeBuilder = new ThemeBuilder(name);
308
309 // get rules using regex
310 const rules = css.match(/:root\s*{([^}]*)}/);
311 if (!rules) throw new Error("Invalid CSS string");
312
313 // get variables using regex
314 const variables = rules[1].match(/--[\w-]+:\s*[^;]+/g);
315 if (!variables) throw new Error("Invalid CSS string");
316
317 // set variables
318 variables.forEach((variable) => {
319 const [key, value] = variable.split(":");
320 themeBuilder(ThemeBuilder.#toPascal(key.trim()), value.trim());
321 });
322
323 return themeBuilder;
324 }
325
326 static fromJSON(theme) {
327 if (!theme) throw new Error("Theme is required");

Callers

nothing calls this directly

Calls 1

#toPascalMethod · 0.80

Tested by

no test coverage detected