Files
webstudio/packages/css-data/bin/html.css.ts
T
Bogdan Chadkin 78a0fa98c1 refactor: output hyphenated properties from css parser (#4900)
We are going to switch to hyphenated properties in styles. Here
refactored css parser to output hyphenated property instead of camel
case and added camelCaseProperty utility which does the opposite of
hyphenateProperty.
2025-02-22 18:11:57 +07:00

22 lines
851 B
TypeScript

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