mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-10-27 23:27:09 +09:00
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.
18 lines
750 B
TypeScript
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);
|