mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-08 21:15:18 +09:00
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.
22 lines
851 B
TypeScript
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);
|