MCPcopy Create free account
hub / github.com/webstudio-is/webstudio / extractCssCustomProperties

Function extractCssCustomProperties

packages/css-data/src/parse-css.ts:680–702  ·  view source on GitHub ↗
(
  css: string
)

Source from the content-addressed store, hash-verified

678 * to be resolved together as if they apply to the same element.
679 */
680export const extractCssCustomProperties = (
681 css: string
682): Map<string, string> => {
683 const map = new Map<string, string>();
684 const ast = cssTreeTryParse(css);
685 if (ast === undefined) {
686 return map;
687 }
688 csstree.walk(ast, {
689 visit: "Declaration",
690 enter(node) {
691 const decl = node as csstree.Declaration;
692 const prop = normalizeProperty(decl.property);
693 if (prop.startsWith("--")) {
694 const value = getRawDeclarationValue(css, decl);
695 if (value !== undefined && isValidCustomPropertyValue(value)) {
696 map.set(prop, normalizeCustomPropertyValue(value));
697 }
698 }
699 },
700 });
701 return map;
702};
703
704export const parseCss = (
705 css: string,

Callers 2

generateFragmentFromHtmlFunction · 0.90

Calls 1

cssTreeTryParseFunction · 0.85

Tested by

no test coverage detected