MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / parseCssRules

Function parseCssRules

packages/sdk/src/engine/cssWriter.ts:23–58  ·  view source on GitHub ↗
(css: string)

Source from the content-addressed store, hash-verified

21
22// fallow-ignore-next-line complexity
23function parseCssRules(css: string): CssRule[] {
24 const rules: CssRule[] = [];
25 let i = 0;
26 const len = css.length;
27 while (i < len) {
28 const braceOpen = css.indexOf("{", i);
29 if (braceOpen === -1) break;
30 const selector = css.slice(i, braceOpen).trim();
31 if (!selector) {
32 i = braceOpen + 1;
33 continue;
34 }
35 // skip leading whitespace to get the true selector start
36 let selStart = i;
37 while (selStart < braceOpen && " \t\r\n".includes(css[selStart]!)) selStart++;
38 // find closing }, respecting quoted strings so `content: "}"` doesn't end the rule
39 let j = braceOpen + 1;
40 let quote: string | null = null;
41 while (j < len) {
42 const ch = css[j]!;
43 if (quote) {
44 if (ch === "\\" && j + 1 < len)
45 j++; // skip escaped char
46 else if (ch === quote) quote = null;
47 } else if (ch === '"' || ch === "'") {
48 quote = ch;
49 } else if (ch === "}") {
50 break;
51 }
52 j++;
53 }
54 rules.push({ selector, body: css.slice(braceOpen + 1, j), start: selStart, end: j + 1 });
55 i = j + 1;
56 }
57 return rules;
58}
59
60// fallow-ignore-next-line complexity
61function parseDeclarations(body: string): Record<string, string> {

Callers 1

upsertCssRuleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected