@motir/design-system 0.14.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/theme/StyleVignette.js +3 -3
- package/dist/components/theme/StyleVignette.js.map +1 -1
- package/dist/components/ui/Combobox.js +27 -14
- package/dist/components/ui/Combobox.js.map +1 -1
- package/dist/components/ui/Modal.d.ts +3 -1
- package/dist/components/ui/Modal.js +28 -13
- package/dist/components/ui/Modal.js.map +1 -1
- package/dist/components/ui/MultiSelectPicker.js +26 -13
- package/dist/components/ui/MultiSelectPicker.js.map +1 -1
- package/dist/components/ui/Popover.js +36 -14
- package/dist/components/ui/Popover.js.map +1 -1
- package/dist/components/ui/Tooltip.js +28 -13
- package/dist/components/ui/Tooltip.js.map +1 -1
- package/dist/contexts/theme-context.js +25 -1
- package/dist/contexts/theme-context.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/mock/index.js +159 -1
- package/dist/mock/index.js.map +1 -1
- package/dist/mock/pruneUnmatchedRules.d.ts +16 -0
- package/dist/mock/pruneUnmatchedRules.js +160 -0
- package/dist/mock/pruneUnmatchedRules.js.map +1 -0
- package/dist/mock/renderMock.js +159 -1
- package/dist/mock/renderMock.js.map +1 -1
- package/dist/specimen/TokensSpecimen.js +3 -3
- package/dist/specimen/TokensSpecimen.js.map +1 -1
- package/dist/theme/fontSets.d.ts +38 -5
- package/dist/theme/fontSets.js +33 -3
- package/dist/theme/fontSets.js.map +1 -1
- package/dist/utils/fullscreen.d.ts +23 -4
- package/dist/utils/fullscreen.js +25 -2
- package/dist/utils/fullscreen.js.map +1 -1
- package/package.json +1 -1
- package/theme.css +107 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// src/mock/pruneUnmatchedRules.ts
|
|
2
|
+
var GROUPING_AT_RULES = /^@(?:media|supports|layer|container|scope|document)\b/i;
|
|
3
|
+
function parse(css) {
|
|
4
|
+
let i = 0;
|
|
5
|
+
function readNodes(untilClose) {
|
|
6
|
+
const nodes = [];
|
|
7
|
+
let start = i;
|
|
8
|
+
let buffer = "";
|
|
9
|
+
while (i < css.length) {
|
|
10
|
+
const ch = css[i];
|
|
11
|
+
if (ch === "\\") {
|
|
12
|
+
buffer += css.slice(i, i + 2);
|
|
13
|
+
i += 2;
|
|
14
|
+
} else if (ch === '"' || ch === "'") {
|
|
15
|
+
const end = closingQuote(css, i);
|
|
16
|
+
buffer += css.slice(i, end + 1);
|
|
17
|
+
i = end + 1;
|
|
18
|
+
} else if (ch === "/" && css[i + 1] === "*") {
|
|
19
|
+
const end = css.indexOf("*/", i + 2);
|
|
20
|
+
const stop = end === -1 ? css.length : end + 2;
|
|
21
|
+
buffer += css.slice(i, stop);
|
|
22
|
+
i = stop;
|
|
23
|
+
} else if (ch === "{") {
|
|
24
|
+
const prelude = buffer;
|
|
25
|
+
i += 1;
|
|
26
|
+
const children = readNodes(true);
|
|
27
|
+
nodes.push({ kind: "block", prelude, children, raw: css.slice(start, i) });
|
|
28
|
+
start = i;
|
|
29
|
+
buffer = "";
|
|
30
|
+
} else if (ch === "}") {
|
|
31
|
+
if (untilClose) {
|
|
32
|
+
if (i > start) nodes.push({ kind: "text", raw: css.slice(start, i) });
|
|
33
|
+
i += 1;
|
|
34
|
+
return nodes;
|
|
35
|
+
}
|
|
36
|
+
i += 1;
|
|
37
|
+
buffer += ch;
|
|
38
|
+
} else if (ch === ";") {
|
|
39
|
+
i += 1;
|
|
40
|
+
nodes.push({ kind: "text", raw: css.slice(start, i) });
|
|
41
|
+
start = i;
|
|
42
|
+
buffer = "";
|
|
43
|
+
} else {
|
|
44
|
+
buffer += ch;
|
|
45
|
+
i += 1;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (css.slice(start).length) nodes.push({ kind: "text", raw: css.slice(start) });
|
|
49
|
+
return nodes;
|
|
50
|
+
}
|
|
51
|
+
return readNodes(false);
|
|
52
|
+
}
|
|
53
|
+
function closingQuote(text, open) {
|
|
54
|
+
const quote = text[open];
|
|
55
|
+
let i = open + 1;
|
|
56
|
+
while (i < text.length && text[i] !== quote) i += text[i] === "\\" ? 2 : 1;
|
|
57
|
+
return Math.min(i, text.length - 1);
|
|
58
|
+
}
|
|
59
|
+
function splitSelectorList(prelude) {
|
|
60
|
+
const out = [];
|
|
61
|
+
let depth = 0;
|
|
62
|
+
let current = "";
|
|
63
|
+
for (let i = 0; i < prelude.length; i += 1) {
|
|
64
|
+
const ch = prelude[i];
|
|
65
|
+
if (ch === "\\") {
|
|
66
|
+
current += prelude.slice(i, i + 2);
|
|
67
|
+
i += 1;
|
|
68
|
+
} else if (ch === '"' || ch === "'") {
|
|
69
|
+
const end = closingQuote(prelude, i);
|
|
70
|
+
current += prelude.slice(i, end + 1);
|
|
71
|
+
i = end;
|
|
72
|
+
} else {
|
|
73
|
+
if (ch === "(" || ch === "[") depth += 1;
|
|
74
|
+
else if (ch === ")" || ch === "]") depth = Math.max(0, depth - 1);
|
|
75
|
+
if (ch === "," && depth === 0) {
|
|
76
|
+
out.push(current);
|
|
77
|
+
current = "";
|
|
78
|
+
} else {
|
|
79
|
+
current += ch;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
out.push(current);
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
function unescapeCssIdent(ident) {
|
|
87
|
+
return ident.replace(
|
|
88
|
+
/\\(?:([0-9a-fA-F]{1,6})[ \t\n]?|([\s\S]))/g,
|
|
89
|
+
(_, hex, char) => hex !== void 0 ? String.fromCodePoint(Number.parseInt(hex, 16)) : char
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
function requiredClasses(selector) {
|
|
93
|
+
const classes = [];
|
|
94
|
+
let depth = 0;
|
|
95
|
+
for (let i = 0; i < selector.length; i += 1) {
|
|
96
|
+
const ch = selector[i];
|
|
97
|
+
if (ch === "\\") {
|
|
98
|
+
i += 1;
|
|
99
|
+
} else if (ch === '"' || ch === "'") {
|
|
100
|
+
i = closingQuote(selector, i);
|
|
101
|
+
} else if (ch === "(" || ch === "[") {
|
|
102
|
+
depth += 1;
|
|
103
|
+
} else if (ch === ")" || ch === "]") {
|
|
104
|
+
depth = Math.max(0, depth - 1);
|
|
105
|
+
} else if (ch === "." && depth === 0) {
|
|
106
|
+
let j = i + 1;
|
|
107
|
+
let ident = "";
|
|
108
|
+
while (j < selector.length) {
|
|
109
|
+
const c = selector[j];
|
|
110
|
+
if (c === "\\") {
|
|
111
|
+
const hex = /^\\[0-9a-fA-F]{1,6}[ \t\n]?/.exec(selector.slice(j));
|
|
112
|
+
const step = hex ? hex[0].length : 2;
|
|
113
|
+
ident += selector.slice(j, j + step);
|
|
114
|
+
j += step;
|
|
115
|
+
} else if (/[-_a-zA-Z0-9\u0080-]/.test(c)) {
|
|
116
|
+
ident += c;
|
|
117
|
+
j += 1;
|
|
118
|
+
} else break;
|
|
119
|
+
}
|
|
120
|
+
if (ident) classes.push(unescapeCssIdent(ident));
|
|
121
|
+
i = j - 1;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return classes;
|
|
125
|
+
}
|
|
126
|
+
function cannotMatch(prelude, carried) {
|
|
127
|
+
const selectors = splitSelectorList(prelude.replace(/\/\*[\s\S]*?\*\//g, " "));
|
|
128
|
+
return selectors.every(
|
|
129
|
+
(selector) => requiredClasses(selector).some((name) => !carried.has(name))
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
function prune(nodes, carried) {
|
|
133
|
+
let out = "";
|
|
134
|
+
for (const node of nodes) {
|
|
135
|
+
if (node.kind === "text") {
|
|
136
|
+
out += node.raw;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const prelude = node.prelude.replace(/\/\*[\s\S]*?\*\//g, " ").trim();
|
|
140
|
+
if (prelude.startsWith("@")) {
|
|
141
|
+
if (GROUPING_AT_RULES.test(prelude) && !/^@layer\s+utilities\s*$/i.test(prelude)) {
|
|
142
|
+
const inner = prune(node.children, carried);
|
|
143
|
+
if (inner.trim() === "" && node.children.some((child) => child.raw.trim() !== "")) continue;
|
|
144
|
+
out += `${node.prelude}{${inner}}`;
|
|
145
|
+
} else {
|
|
146
|
+
out += node.raw;
|
|
147
|
+
}
|
|
148
|
+
} else if (!cannotMatch(prelude, carried)) {
|
|
149
|
+
out += node.raw;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
function pruneUnmatchedRules(css, carried) {
|
|
155
|
+
return prune(parse(css), new Set(carried));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export { pruneUnmatchedRules, requiredClasses, unescapeCssIdent };
|
|
159
|
+
//# sourceMappingURL=pruneUnmatchedRules.js.map
|
|
160
|
+
//# sourceMappingURL=pruneUnmatchedRules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/mock/pruneUnmatchedRules.ts"],"names":[],"mappings":";AA+BA,IAAM,iBAAA,GAAoB,wDAAA;AAG1B,SAAS,MAAM,GAAA,EAAwB;AACrC,EAAA,IAAI,CAAA,GAAI,CAAA;AAER,EAAA,SAAS,UAAU,UAAA,EAAgC;AACjD,IAAA,MAAM,QAAmB,EAAC;AAC1B,IAAA,IAAI,KAAA,GAAQ,CAAA;AACZ,IAAA,IAAI,MAAA,GAAS,EAAA;AACb,IAAA,OAAO,CAAA,GAAI,IAAI,MAAA,EAAQ;AACrB,MAAA,MAAM,EAAA,GAAK,IAAI,CAAC,CAAA;AAChB,MAAA,IAAI,OAAO,IAAA,EAAM;AACf,QAAA,MAAA,IAAU,GAAA,CAAI,KAAA,CAAM,CAAA,EAAG,CAAA,GAAI,CAAC,CAAA;AAC5B,QAAA,CAAA,IAAK,CAAA;AAAA,MACP,CAAA,MAAA,IAAW,EAAA,KAAO,GAAA,IAAO,EAAA,KAAO,GAAA,EAAK;AACnC,QAAA,MAAM,GAAA,GAAM,YAAA,CAAa,GAAA,EAAK,CAAC,CAAA;AAC/B,QAAA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AAK,CAAC,0BAAA,CAA2B,IAAA,CAAK,OAAO,CAAA,EAAG;AAChF,QAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,IAAA,CAAK,QAAA,EAAU,OAAO,CAAA;AAE1C,QAAA,IAAI,KAAA,CAAM,IAAA,EAAK,KAAM,EAAA,IAAM,KAAK,QAAA,CAAS,IAAA,CAAK,CAAC,KAAA,KAAU,KAAA,CAAM,GAAA,CAAI,IAAA,EAAK,KAAM,EAAE,CAAA,EAAG;AACnF,QAAA,GAAA,IAAO,CAAA,EAAG,IAAA,CAAK,OAAO,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA,CAAA;AAAA,MACjC,CAAA,MAAO;AACL,QAAA,GAAA,IAAO,IAAA,CAAK,GAAA;AAAA,MACd;AAAA,IACF,CAAA,MAAA,IAAW,CAAC,WAAA,CAAY,OAAA,EAAS,OAAO,CAAA,EAAG;AACzC,MAAA,GAAA,IAAO,IAAA,CAAK,GAAA;AAAA,IACd;AAAA,EACF;AACA,EAAA,OAAO,GAAA;AACT;AAOO,SAAS,mBAAA,CAAoB,KAAa,OAAA,EAAmC;AAClF,EAAA,OAAO,MAAM,KAAA,CAAM,GAAG,GAAG,IAAI,GAAA,CAAI,OAAO,CAAC,CAAA;AAC3C","file":"pruneUnmatchedRules.js","sourcesContent":["// pruneUnmatchedRules — drop the style rules a rendered mock can never match\n// (MOTIR-8565).\n//\n// `renderMock` compiles Tailwind over the markup with `theme.css` as input.\n// Tailwind writes a UTILITY only for a class the markup carries, but it copies\n// every plain rule of the input stylesheet through whole — so a component-scoped\n// rule such as `.style-vignette[data-style='aurora'] > .sv-canvas { … }` lands\n// in every mock, including the ones that render no `StyleVignette` at all.\n// A rule nothing matches is not harmless in a design asset: it is a measure a\n// reader can lift off the stylesheet and call \"the value the asset draws\"\n// (MOTIR-4150), and motir-core's design guard fails a mock that declares one\n// (`tests/design-mock-utility-correspondence.test.ts`, direction (B)).\n//\n// ⚠️ IT ONLY EVER DROPS A RULE THAT CANNOT MATCH. A rule goes when EVERY\n// selector in its list needs a class the markup does not carry. \"Needs\" is read\n// conservatively, so a doubtful rule stays:\n// • a class inside a functional pseudo-class — `:not(.fixed)`,\n// `:is(.border-b, .border-t)`, `:where(.group):hover *` — is NOT needed:\n// `:not` matches when the class is absent and `:is` with one present member;\n// • an attribute selector's value is not read as a class (`[data-x='a.b']`);\n// • a rule nested inside another style rule is kept or dropped with its parent;\n// • `@layer utilities` is left alone — Tailwind wrote every rule in it from the\n// markup's own candidates — and so are `@keyframes`, `@font-face`,\n// `@property` and every other at-rule that holds no style rules.\n\n/** One parsed node: a block (`prelude { … }`) or a statement (`@import …;`, a declaration). */\ntype CssNode =\n | { kind: 'block'; prelude: string; children: CssNode[]; raw: string }\n | { kind: 'text'; raw: string };\n\n/** At-rules whose blocks hold style rules — the only ones the pruner walks into. */\nconst GROUPING_AT_RULES = /^@(?:media|supports|layer|container|scope|document)\\b/i;\n\n/** Split CSS into top-level nodes, recursing into every block. Strings, comments and escapes are respected. */\nfunction parse(css: string): CssNode[] {\n let i = 0;\n\n function readNodes(untilClose: boolean): CssNode[] {\n const nodes: CssNode[] = [];\n let start = i;\n let buffer = '';\n while (i < css.length) {\n const ch = css[i]!;\n if (ch === '\\\\') {\n buffer += css.slice(i, i + 2);\n i += 2;\n } else if (ch === '\"' || ch === \"'\") {\n const end = closingQuote(css, i);\n buffer += css.slice(i, end + 1);\n i = end + 1;\n } else if (ch === '/' && css[i + 1] === '*') {\n const end = css.indexOf('*/', i + 2);\n const stop = end === -1 ? css.length : end + 2;\n buffer += css.slice(i, stop);\n i = stop;\n } else if (ch === '{') {\n const prelude = buffer;\n i += 1;\n const children = readNodes(true);\n nodes.push({ kind: 'block', prelude, children, raw: css.slice(start, i) });\n start = i;\n buffer = '';\n } else if (ch === '}') {\n if (untilClose) {\n if (i > start) nodes.push({ kind: 'text', raw: css.slice(start, i) });\n i += 1;\n return nodes;\n }\n // A stray `}` at the top level: keep it verbatim rather than lose bytes.\n i += 1;\n buffer += ch;\n } else if (ch === ';') {\n i += 1;\n nodes.push({ kind: 'text', raw: css.slice(start, i) });\n start = i;\n buffer = '';\n } else {\n buffer += ch;\n i += 1;\n }\n }\n if (css.slice(start).length) nodes.push({ kind: 'text', raw: css.slice(start) });\n return nodes;\n }\n\n return readNodes(false);\n}\n\n/** The index of the quote that closes the string opening at `open`. */\nfunction closingQuote(text: string, open: number): number {\n const quote = text[open];\n let i = open + 1;\n while (i < text.length && text[i] !== quote) i += text[i] === '\\\\' ? 2 : 1;\n return Math.min(i, text.length - 1);\n}\n\n/** Split a selector list on its top-level commas. */\nfunction splitSelectorList(prelude: string): string[] {\n const out: string[] = [];\n let depth = 0;\n let current = '';\n for (let i = 0; i < prelude.length; i += 1) {\n const ch = prelude[i]!;\n if (ch === '\\\\') {\n current += prelude.slice(i, i + 2);\n i += 1;\n } else if (ch === '\"' || ch === \"'\") {\n const end = closingQuote(prelude, i);\n current += prelude.slice(i, end + 1);\n i = end;\n } else {\n if (ch === '(' || ch === '[') depth += 1;\n else if (ch === ')' || ch === ']') depth = Math.max(0, depth - 1);\n if (ch === ',' && depth === 0) {\n out.push(current);\n current = '';\n } else {\n current += ch;\n }\n }\n }\n out.push(current);\n return out;\n}\n\n/** CSS identifier un-escaping: `\\(` → `(`, `\\:` → `:`, `\\32 xl` → `2xl`. */\nexport function unescapeCssIdent(ident: string): string {\n return ident.replace(\n /\\\\(?:([0-9a-fA-F]{1,6})[ \\t\\n]?|([\\s\\S]))/g,\n (_, hex?: string, char?: string) =>\n hex !== undefined ? String.fromCodePoint(Number.parseInt(hex, 16)) : char!,\n );\n}\n\n/**\n * The classes ONE complex selector cannot match without — every `.class` outside\n * a parenthesised group (a functional pseudo-class's argument) and outside an\n * attribute selector. Exported for its own test only.\n */\nexport function requiredClasses(selector: string): string[] {\n const classes: string[] = [];\n let depth = 0;\n for (let i = 0; i < selector.length; i += 1) {\n const ch = selector[i]!;\n if (ch === '\\\\') {\n i += 1;\n } else if (ch === '\"' || ch === \"'\") {\n i = closingQuote(selector, i);\n } else if (ch === '(' || ch === '[') {\n depth += 1;\n } else if (ch === ')' || ch === ']') {\n depth = Math.max(0, depth - 1);\n } else if (ch === '.' && depth === 0) {\n let j = i + 1;\n let ident = '';\n while (j < selector.length) {\n const c = selector[j]!;\n if (c === '\\\\') {\n // An escape: a hex run plus one optional whitespace, or one literal character.\n const hex = /^\\\\[0-9a-fA-F]{1,6}[ \\t\\n]?/.exec(selector.slice(j));\n const step = hex ? hex[0].length : 2;\n ident += selector.slice(j, j + step);\n j += step;\n } else if (/[-_a-zA-Z0-9\\u0080-]/.test(c)) {\n ident += c;\n j += 1;\n } else break;\n }\n if (ident) classes.push(unescapeCssIdent(ident));\n i = j - 1;\n }\n }\n return classes;\n}\n\n/** True when no selector in the rule's list can match markup carrying only `carried`. */\nfunction cannotMatch(prelude: string, carried: ReadonlySet<string>): boolean {\n const selectors = splitSelectorList(prelude.replace(/\\/\\*[\\s\\S]*?\\*\\//g, ' '));\n return selectors.every((selector) =>\n requiredClasses(selector).some((name) => !carried.has(name)),\n );\n}\n\nfunction prune(nodes: CssNode[], carried: ReadonlySet<string>): string {\n let out = '';\n for (const node of nodes) {\n if (node.kind === 'text') {\n out += node.raw;\n continue;\n }\n const prelude = node.prelude.replace(/\\/\\*[\\s\\S]*?\\*\\//g, ' ').trim();\n if (prelude.startsWith('@')) {\n // Walk only the grouping at-rules, and never `@layer utilities`.\n if (GROUPING_AT_RULES.test(prelude) && !/^@layer\\s+utilities\\s*$/i.test(prelude)) {\n const inner = prune(node.children, carried);\n // A group the prune emptied goes with its rules; one that was empty already stays.\n if (inner.trim() === '' && node.children.some((child) => child.raw.trim() !== '')) continue;\n out += `${node.prelude}{${inner}}`;\n } else {\n out += node.raw;\n }\n } else if (!cannotMatch(prelude, carried)) {\n out += node.raw;\n }\n }\n return out;\n}\n\n/**\n * The compiled stylesheet minus every style rule no element of the markup can\n * match, given the classes the markup carries. A stylesheet with nothing to drop\n * comes back byte-identical.\n */\nexport function pruneUnmatchedRules(css: string, carried: Iterable<string>): string {\n return prune(parse(css), new Set(carried));\n}\n"]}
|
package/dist/mock/renderMock.js
CHANGED
|
@@ -348,6 +348,163 @@ var DEFAULT_PALETTE_ID = "motir";
|
|
|
348
348
|
function isPaletteId(value) {
|
|
349
349
|
return typeof value === "string" && Object.prototype.hasOwnProperty.call(PALETTE_REGISTRY, value);
|
|
350
350
|
}
|
|
351
|
+
|
|
352
|
+
// src/mock/pruneUnmatchedRules.ts
|
|
353
|
+
var GROUPING_AT_RULES = /^@(?:media|supports|layer|container|scope|document)\b/i;
|
|
354
|
+
function parse(css) {
|
|
355
|
+
let i = 0;
|
|
356
|
+
function readNodes(untilClose) {
|
|
357
|
+
const nodes = [];
|
|
358
|
+
let start = i;
|
|
359
|
+
let buffer = "";
|
|
360
|
+
while (i < css.length) {
|
|
361
|
+
const ch = css[i];
|
|
362
|
+
if (ch === "\\") {
|
|
363
|
+
buffer += css.slice(i, i + 2);
|
|
364
|
+
i += 2;
|
|
365
|
+
} else if (ch === '"' || ch === "'") {
|
|
366
|
+
const end = closingQuote(css, i);
|
|
367
|
+
buffer += css.slice(i, end + 1);
|
|
368
|
+
i = end + 1;
|
|
369
|
+
} else if (ch === "/" && css[i + 1] === "*") {
|
|
370
|
+
const end = css.indexOf("*/", i + 2);
|
|
371
|
+
const stop = end === -1 ? css.length : end + 2;
|
|
372
|
+
buffer += css.slice(i, stop);
|
|
373
|
+
i = stop;
|
|
374
|
+
} else if (ch === "{") {
|
|
375
|
+
const prelude = buffer;
|
|
376
|
+
i += 1;
|
|
377
|
+
const children = readNodes(true);
|
|
378
|
+
nodes.push({ kind: "block", prelude, children, raw: css.slice(start, i) });
|
|
379
|
+
start = i;
|
|
380
|
+
buffer = "";
|
|
381
|
+
} else if (ch === "}") {
|
|
382
|
+
if (untilClose) {
|
|
383
|
+
if (i > start) nodes.push({ kind: "text", raw: css.slice(start, i) });
|
|
384
|
+
i += 1;
|
|
385
|
+
return nodes;
|
|
386
|
+
}
|
|
387
|
+
i += 1;
|
|
388
|
+
buffer += ch;
|
|
389
|
+
} else if (ch === ";") {
|
|
390
|
+
i += 1;
|
|
391
|
+
nodes.push({ kind: "text", raw: css.slice(start, i) });
|
|
392
|
+
start = i;
|
|
393
|
+
buffer = "";
|
|
394
|
+
} else {
|
|
395
|
+
buffer += ch;
|
|
396
|
+
i += 1;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
if (css.slice(start).length) nodes.push({ kind: "text", raw: css.slice(start) });
|
|
400
|
+
return nodes;
|
|
401
|
+
}
|
|
402
|
+
return readNodes(false);
|
|
403
|
+
}
|
|
404
|
+
function closingQuote(text, open) {
|
|
405
|
+
const quote = text[open];
|
|
406
|
+
let i = open + 1;
|
|
407
|
+
while (i < text.length && text[i] !== quote) i += text[i] === "\\" ? 2 : 1;
|
|
408
|
+
return Math.min(i, text.length - 1);
|
|
409
|
+
}
|
|
410
|
+
function splitSelectorList(prelude) {
|
|
411
|
+
const out = [];
|
|
412
|
+
let depth = 0;
|
|
413
|
+
let current = "";
|
|
414
|
+
for (let i = 0; i < prelude.length; i += 1) {
|
|
415
|
+
const ch = prelude[i];
|
|
416
|
+
if (ch === "\\") {
|
|
417
|
+
current += prelude.slice(i, i + 2);
|
|
418
|
+
i += 1;
|
|
419
|
+
} else if (ch === '"' || ch === "'") {
|
|
420
|
+
const end = closingQuote(prelude, i);
|
|
421
|
+
current += prelude.slice(i, end + 1);
|
|
422
|
+
i = end;
|
|
423
|
+
} else {
|
|
424
|
+
if (ch === "(" || ch === "[") depth += 1;
|
|
425
|
+
else if (ch === ")" || ch === "]") depth = Math.max(0, depth - 1);
|
|
426
|
+
if (ch === "," && depth === 0) {
|
|
427
|
+
out.push(current);
|
|
428
|
+
current = "";
|
|
429
|
+
} else {
|
|
430
|
+
current += ch;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
out.push(current);
|
|
435
|
+
return out;
|
|
436
|
+
}
|
|
437
|
+
function unescapeCssIdent(ident) {
|
|
438
|
+
return ident.replace(
|
|
439
|
+
/\\(?:([0-9a-fA-F]{1,6})[ \t\n]?|([\s\S]))/g,
|
|
440
|
+
(_, hex, char) => hex !== void 0 ? String.fromCodePoint(Number.parseInt(hex, 16)) : char
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
function requiredClasses(selector) {
|
|
444
|
+
const classes = [];
|
|
445
|
+
let depth = 0;
|
|
446
|
+
for (let i = 0; i < selector.length; i += 1) {
|
|
447
|
+
const ch = selector[i];
|
|
448
|
+
if (ch === "\\") {
|
|
449
|
+
i += 1;
|
|
450
|
+
} else if (ch === '"' || ch === "'") {
|
|
451
|
+
i = closingQuote(selector, i);
|
|
452
|
+
} else if (ch === "(" || ch === "[") {
|
|
453
|
+
depth += 1;
|
|
454
|
+
} else if (ch === ")" || ch === "]") {
|
|
455
|
+
depth = Math.max(0, depth - 1);
|
|
456
|
+
} else if (ch === "." && depth === 0) {
|
|
457
|
+
let j = i + 1;
|
|
458
|
+
let ident = "";
|
|
459
|
+
while (j < selector.length) {
|
|
460
|
+
const c = selector[j];
|
|
461
|
+
if (c === "\\") {
|
|
462
|
+
const hex = /^\\[0-9a-fA-F]{1,6}[ \t\n]?/.exec(selector.slice(j));
|
|
463
|
+
const step = hex ? hex[0].length : 2;
|
|
464
|
+
ident += selector.slice(j, j + step);
|
|
465
|
+
j += step;
|
|
466
|
+
} else if (/[-_a-zA-Z0-9\u0080-]/.test(c)) {
|
|
467
|
+
ident += c;
|
|
468
|
+
j += 1;
|
|
469
|
+
} else break;
|
|
470
|
+
}
|
|
471
|
+
if (ident) classes.push(unescapeCssIdent(ident));
|
|
472
|
+
i = j - 1;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return classes;
|
|
476
|
+
}
|
|
477
|
+
function cannotMatch(prelude, carried) {
|
|
478
|
+
const selectors = splitSelectorList(prelude.replace(/\/\*[\s\S]*?\*\//g, " "));
|
|
479
|
+
return selectors.every(
|
|
480
|
+
(selector) => requiredClasses(selector).some((name) => !carried.has(name))
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
function prune(nodes, carried) {
|
|
484
|
+
let out = "";
|
|
485
|
+
for (const node of nodes) {
|
|
486
|
+
if (node.kind === "text") {
|
|
487
|
+
out += node.raw;
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
const prelude = node.prelude.replace(/\/\*[\s\S]*?\*\//g, " ").trim();
|
|
491
|
+
if (prelude.startsWith("@")) {
|
|
492
|
+
if (GROUPING_AT_RULES.test(prelude) && !/^@layer\s+utilities\s*$/i.test(prelude)) {
|
|
493
|
+
const inner = prune(node.children, carried);
|
|
494
|
+
if (inner.trim() === "" && node.children.some((child) => child.raw.trim() !== "")) continue;
|
|
495
|
+
out += `${node.prelude}{${inner}}`;
|
|
496
|
+
} else {
|
|
497
|
+
out += node.raw;
|
|
498
|
+
}
|
|
499
|
+
} else if (!cannotMatch(prelude, carried)) {
|
|
500
|
+
out += node.raw;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return out;
|
|
504
|
+
}
|
|
505
|
+
function pruneUnmatchedRules(css, carried) {
|
|
506
|
+
return prune(parse(css), new Set(carried));
|
|
507
|
+
}
|
|
351
508
|
var THEME_CSS_URL = new URL("../../theme.css", import.meta.url);
|
|
352
509
|
function resolveAxes(axes) {
|
|
353
510
|
const fallbacks = [];
|
|
@@ -402,7 +559,8 @@ async function compileCss(markup) {
|
|
|
402
559
|
const input = `@import 'tailwindcss';
|
|
403
560
|
${themeCss}`;
|
|
404
561
|
const compiler = await compile(input, { base, loadStylesheet });
|
|
405
|
-
|
|
562
|
+
const candidates = extractClassCandidates(markup);
|
|
563
|
+
return pruneUnmatchedRules(compiler.build(candidates), candidates);
|
|
406
564
|
}
|
|
407
565
|
function escapeHtml(value) {
|
|
408
566
|
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|