Files
Oleg Isonen 8de2fd47f6 fix: CSS shorthand properties not saved when value contains var() (#5688)
Shorthand properties like background: var(--color) were silently dropped
when pasting into the CSS editor because the shorthand expander can't
handle unresolved var() references.

Fix: CSS vars from the current element's computed styles are now
resolved before expanding shorthands. Inline and nested fallbacks
(var(--a, var(--b))) are supported. If a var still can't be resolved, a
toast error is shown instead of silently dropping the property.
2026-04-12 17:14:01 +02:00

18 lines
750 B
TypeScript

import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import type { StyleValue } from "@webstudio-is/css-engine";
import { parseCss } from "../src/parse-css";
const css = readFileSync("./src/html.css", "utf8");
const { styles: parsed } = parseCss(css, new Map());
const result: [string, StyleValue][] = [];
for (const styleDecl of parsed) {
result.push([`${styleDecl.selector}:${styleDecl.property}`, styleDecl.value]);
}
let code = "";
code += `import type { StyleValue } from "@webstudio-is/css-engine";\n\n`;
const type = "Map<string, StyleValue>";
code += `export const html: ${type} = new Map(${JSON.stringify(result)})`;
mkdirSync("./src/__generated__", { recursive: true });
writeFileSync("./src/__generated__/html.ts", code);