@tenphi/tasty 0.1.0 → 0.1.2
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/_virtual/_rolldown/runtime.js +8 -0
- package/dist/zero/{babel.d.mts → babel.d.ts} +6 -6
- package/dist/zero/{babel.mjs → babel.js} +6 -6
- package/dist/zero/babel.js.map +1 -0
- package/dist/{css-writer.d.mts → zero/css-writer.d.ts} +1 -1
- package/dist/{css-writer.mjs → zero/css-writer.js} +1 -1
- package/dist/zero/css-writer.js.map +1 -0
- package/dist/{extractor.d.mts → zero/extractor.d.ts} +3 -2
- package/dist/{extractor.mjs → zero/extractor.js} +6 -6
- package/dist/zero/extractor.js.map +1 -0
- package/dist/zero/index.d.ts +3 -0
- package/dist/zero/{index.mjs → index.js} +2 -2
- package/dist/zero/{next.d.mts → next.d.ts} +1 -1
- package/dist/zero/{next.mjs → next.js} +2 -2
- package/dist/zero/next.js.map +1 -0
- package/package.json +16 -23
- package/dist/_virtual/_rolldown/runtime.mjs +0 -7
- package/dist/chunks/cacheKey.mjs +0 -70
- package/dist/chunks/cacheKey.mjs.map +0 -1
- package/dist/chunks/definitions.mjs +0 -260
- package/dist/chunks/definitions.mjs.map +0 -1
- package/dist/chunks/renderChunk.mjs +0 -61
- package/dist/chunks/renderChunk.mjs.map +0 -1
- package/dist/config.mjs +0 -231
- package/dist/config.mjs.map +0 -1
- package/dist/css-writer.mjs.map +0 -1
- package/dist/extractor.mjs.map +0 -1
- package/dist/injector/injector.mjs +0 -404
- package/dist/injector/injector.mjs.map +0 -1
- package/dist/injector/sheet-manager.mjs +0 -714
- package/dist/injector/sheet-manager.mjs.map +0 -1
- package/dist/injector/types.d.mts +0 -18
- package/dist/keyframes/index.mjs +0 -156
- package/dist/keyframes/index.mjs.map +0 -1
- package/dist/parser/classify.mjs +0 -319
- package/dist/parser/classify.mjs.map +0 -1
- package/dist/parser/const.mjs +0 -33
- package/dist/parser/const.mjs.map +0 -1
- package/dist/parser/lru.mjs +0 -109
- package/dist/parser/lru.mjs.map +0 -1
- package/dist/parser/parser.mjs +0 -116
- package/dist/parser/parser.mjs.map +0 -1
- package/dist/parser/tokenizer.mjs +0 -69
- package/dist/parser/tokenizer.mjs.map +0 -1
- package/dist/parser/types.d.mts +0 -37
- package/dist/parser/types.mjs +0 -46
- package/dist/parser/types.mjs.map +0 -1
- package/dist/pipeline/conditions.mjs +0 -377
- package/dist/pipeline/conditions.mjs.map +0 -1
- package/dist/pipeline/exclusive.mjs +0 -231
- package/dist/pipeline/exclusive.mjs.map +0 -1
- package/dist/pipeline/index.mjs +0 -635
- package/dist/pipeline/index.mjs.map +0 -1
- package/dist/pipeline/materialize.mjs +0 -821
- package/dist/pipeline/materialize.mjs.map +0 -1
- package/dist/pipeline/parseStateKey.mjs +0 -418
- package/dist/pipeline/parseStateKey.mjs.map +0 -1
- package/dist/pipeline/simplify.mjs +0 -557
- package/dist/pipeline/simplify.mjs.map +0 -1
- package/dist/plugins/okhsl-plugin.mjs +0 -345
- package/dist/plugins/okhsl-plugin.mjs.map +0 -1
- package/dist/plugins/types.d.mts +0 -49
- package/dist/properties/index.mjs +0 -141
- package/dist/properties/index.mjs.map +0 -1
- package/dist/states/index.mjs +0 -161
- package/dist/states/index.mjs.map +0 -1
- package/dist/styles/align.mjs +0 -14
- package/dist/styles/align.mjs.map +0 -1
- package/dist/styles/border.mjs +0 -114
- package/dist/styles/border.mjs.map +0 -1
- package/dist/styles/color.mjs +0 -23
- package/dist/styles/color.mjs.map +0 -1
- package/dist/styles/createStyle.mjs +0 -77
- package/dist/styles/createStyle.mjs.map +0 -1
- package/dist/styles/dimension.mjs +0 -97
- package/dist/styles/dimension.mjs.map +0 -1
- package/dist/styles/display.mjs +0 -67
- package/dist/styles/display.mjs.map +0 -1
- package/dist/styles/fade.mjs +0 -58
- package/dist/styles/fade.mjs.map +0 -1
- package/dist/styles/fill.mjs +0 -51
- package/dist/styles/fill.mjs.map +0 -1
- package/dist/styles/flow.mjs +0 -12
- package/dist/styles/flow.mjs.map +0 -1
- package/dist/styles/gap.mjs +0 -37
- package/dist/styles/gap.mjs.map +0 -1
- package/dist/styles/height.mjs +0 -20
- package/dist/styles/height.mjs.map +0 -1
- package/dist/styles/index.mjs +0 -9
- package/dist/styles/index.mjs.map +0 -1
- package/dist/styles/inset.mjs +0 -142
- package/dist/styles/inset.mjs.map +0 -1
- package/dist/styles/justify.mjs +0 -14
- package/dist/styles/justify.mjs.map +0 -1
- package/dist/styles/margin.mjs +0 -96
- package/dist/styles/margin.mjs.map +0 -1
- package/dist/styles/outline.mjs +0 -65
- package/dist/styles/outline.mjs.map +0 -1
- package/dist/styles/padding.mjs +0 -96
- package/dist/styles/padding.mjs.map +0 -1
- package/dist/styles/predefined.mjs +0 -232
- package/dist/styles/predefined.mjs.map +0 -1
- package/dist/styles/preset.mjs +0 -126
- package/dist/styles/preset.mjs.map +0 -1
- package/dist/styles/radius.mjs +0 -51
- package/dist/styles/radius.mjs.map +0 -1
- package/dist/styles/scrollbar.mjs +0 -105
- package/dist/styles/scrollbar.mjs.map +0 -1
- package/dist/styles/shadow.mjs +0 -24
- package/dist/styles/shadow.mjs.map +0 -1
- package/dist/styles/styledScrollbar.mjs +0 -38
- package/dist/styles/styledScrollbar.mjs.map +0 -1
- package/dist/styles/transition.mjs +0 -138
- package/dist/styles/transition.mjs.map +0 -1
- package/dist/styles/types.d.mts +0 -492
- package/dist/styles/width.mjs +0 -20
- package/dist/styles/width.mjs.map +0 -1
- package/dist/utils/cache-wrapper.mjs +0 -26
- package/dist/utils/cache-wrapper.mjs.map +0 -1
- package/dist/utils/case-converter.mjs +0 -8
- package/dist/utils/case-converter.mjs.map +0 -1
- package/dist/utils/hsl-to-rgb.mjs +0 -38
- package/dist/utils/hsl-to-rgb.mjs.map +0 -1
- package/dist/utils/is-dev-env.mjs +0 -19
- package/dist/utils/is-dev-env.mjs.map +0 -1
- package/dist/utils/merge-styles.mjs +0 -146
- package/dist/utils/merge-styles.mjs.map +0 -1
- package/dist/utils/okhsl-to-rgb.mjs +0 -296
- package/dist/utils/okhsl-to-rgb.mjs.map +0 -1
- package/dist/utils/process-tokens.mjs +0 -28
- package/dist/utils/process-tokens.mjs.map +0 -1
- package/dist/utils/resolve-recipes.mjs +0 -143
- package/dist/utils/resolve-recipes.mjs.map +0 -1
- package/dist/utils/string.mjs +0 -8
- package/dist/utils/string.mjs.map +0 -1
- package/dist/utils/styles.d.mts +0 -18
- package/dist/utils/styles.mjs +0 -346
- package/dist/utils/styles.mjs.map +0 -1
- package/dist/zero/babel.mjs.map +0 -1
- package/dist/zero/index.d.mts +0 -3
- package/dist/zero/next.mjs.map +0 -1
|
@@ -1,821 +0,0 @@
|
|
|
1
|
-
import { Lru } from "../parser/lru.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/pipeline/materialize.ts
|
|
4
|
-
/**
|
|
5
|
-
* CSS Materialization
|
|
6
|
-
*
|
|
7
|
-
* Converts condition trees into CSS selectors and at-rules.
|
|
8
|
-
* This is the final stage that produces actual CSS output.
|
|
9
|
-
*/
|
|
10
|
-
const conditionCache = new Lru(3e3);
|
|
11
|
-
/**
|
|
12
|
-
* Convert a condition tree to CSS components
|
|
13
|
-
*/
|
|
14
|
-
function conditionToCSS(node) {
|
|
15
|
-
const key = getConditionKey(node);
|
|
16
|
-
const cached = conditionCache.get(key);
|
|
17
|
-
if (cached) return cached;
|
|
18
|
-
const result = conditionToCSSInner(node);
|
|
19
|
-
conditionCache.set(key, result);
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Create an empty selector variant
|
|
24
|
-
*/
|
|
25
|
-
function emptyVariant() {
|
|
26
|
-
return {
|
|
27
|
-
modifierConditions: [],
|
|
28
|
-
pseudoConditions: [],
|
|
29
|
-
ownConditions: [],
|
|
30
|
-
mediaConditions: [],
|
|
31
|
-
containerConditions: [],
|
|
32
|
-
supportsConditions: [],
|
|
33
|
-
rootConditions: [],
|
|
34
|
-
startingStyle: false
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function conditionToCSSInner(node) {
|
|
38
|
-
if (node.kind === "true") return {
|
|
39
|
-
variants: [emptyVariant()],
|
|
40
|
-
isImpossible: false
|
|
41
|
-
};
|
|
42
|
-
if (node.kind === "false") return {
|
|
43
|
-
variants: [],
|
|
44
|
-
isImpossible: true
|
|
45
|
-
};
|
|
46
|
-
if (node.kind === "state") return stateToCSS(node);
|
|
47
|
-
if (node.kind === "compound") if (node.operator === "AND") return andToCSS(node.children);
|
|
48
|
-
else return orToCSS(node.children);
|
|
49
|
-
return {
|
|
50
|
-
variants: [emptyVariant()],
|
|
51
|
-
isImpossible: false
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Convert a state condition to CSS
|
|
56
|
-
*/
|
|
57
|
-
function stateToCSS(state) {
|
|
58
|
-
switch (state.type) {
|
|
59
|
-
case "media": return {
|
|
60
|
-
variants: mediaToParsed(state).map((mediaCond) => {
|
|
61
|
-
const v = emptyVariant();
|
|
62
|
-
v.mediaConditions.push(mediaCond);
|
|
63
|
-
return v;
|
|
64
|
-
}),
|
|
65
|
-
isImpossible: false
|
|
66
|
-
};
|
|
67
|
-
default: {
|
|
68
|
-
const variant = emptyVariant();
|
|
69
|
-
switch (state.type) {
|
|
70
|
-
case "modifier":
|
|
71
|
-
variant.modifierConditions.push(modifierToParsed(state));
|
|
72
|
-
break;
|
|
73
|
-
case "pseudo":
|
|
74
|
-
variant.pseudoConditions.push(pseudoToParsed(state));
|
|
75
|
-
break;
|
|
76
|
-
case "container":
|
|
77
|
-
variant.containerConditions.push(containerToParsed(state));
|
|
78
|
-
break;
|
|
79
|
-
case "supports":
|
|
80
|
-
variant.supportsConditions.push(supportsToParsed(state));
|
|
81
|
-
break;
|
|
82
|
-
case "root":
|
|
83
|
-
variant.rootConditions.push(rootToParsed(state));
|
|
84
|
-
break;
|
|
85
|
-
case "own":
|
|
86
|
-
variant.ownConditions.push(...ownToParsed(state));
|
|
87
|
-
break;
|
|
88
|
-
case "starting":
|
|
89
|
-
variant.startingStyle = !state.negated;
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
variants: [variant],
|
|
94
|
-
isImpossible: false
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Convert modifier condition to parsed structure
|
|
101
|
-
*/
|
|
102
|
-
function modifierToParsed(state) {
|
|
103
|
-
return {
|
|
104
|
-
attribute: state.attribute,
|
|
105
|
-
value: state.value,
|
|
106
|
-
operator: state.operator,
|
|
107
|
-
negated: state.negated ?? false
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Convert parsed modifier to CSS selector string (for final output)
|
|
112
|
-
*/
|
|
113
|
-
function modifierToCSS(mod) {
|
|
114
|
-
let selector;
|
|
115
|
-
if (mod.value !== void 0) {
|
|
116
|
-
const op = mod.operator || "=";
|
|
117
|
-
selector = `[${mod.attribute}${op}"${mod.value}"]`;
|
|
118
|
-
} else selector = `[${mod.attribute}]`;
|
|
119
|
-
if (mod.negated) return `:not(${selector})`;
|
|
120
|
-
return selector;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Convert pseudo condition to parsed structure
|
|
124
|
-
*/
|
|
125
|
-
function pseudoToParsed(state) {
|
|
126
|
-
return {
|
|
127
|
-
pseudo: state.pseudo,
|
|
128
|
-
negated: state.negated ?? false
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Convert parsed pseudo to CSS selector string (for final output)
|
|
133
|
-
*/
|
|
134
|
-
function pseudoToCSS(pseudo) {
|
|
135
|
-
if (pseudo.negated) {
|
|
136
|
-
if (pseudo.pseudo.startsWith(":not(")) return pseudo.pseudo.slice(5, -1);
|
|
137
|
-
return `:not(${pseudo.pseudo})`;
|
|
138
|
-
}
|
|
139
|
-
return pseudo.pseudo;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Convert media condition to parsed structure(s)
|
|
143
|
-
* Returns an array because negated ranges produce OR branches (two separate conditions)
|
|
144
|
-
*/
|
|
145
|
-
function mediaToParsed(state) {
|
|
146
|
-
if (state.subtype === "type") {
|
|
147
|
-
const mediaType = state.mediaType || "all";
|
|
148
|
-
return [{
|
|
149
|
-
subtype: "type",
|
|
150
|
-
negated: state.negated ?? false,
|
|
151
|
-
condition: mediaType,
|
|
152
|
-
mediaType: state.mediaType
|
|
153
|
-
}];
|
|
154
|
-
} else if (state.subtype === "feature") {
|
|
155
|
-
let condition;
|
|
156
|
-
if (state.featureValue) condition = `(${state.feature}: ${state.featureValue})`;
|
|
157
|
-
else condition = `(${state.feature})`;
|
|
158
|
-
return [{
|
|
159
|
-
subtype: "feature",
|
|
160
|
-
negated: state.negated ?? false,
|
|
161
|
-
condition,
|
|
162
|
-
feature: state.feature,
|
|
163
|
-
featureValue: state.featureValue
|
|
164
|
-
}];
|
|
165
|
-
} else return dimensionToMediaParsed(state.dimension || "width", state.lowerBound, state.upperBound, state.negated ?? false);
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Convert dimension bounds to parsed media condition(s)
|
|
169
|
-
* Uses CSS Media Queries Level 4 `not (condition)` syntax for negation.
|
|
170
|
-
*/
|
|
171
|
-
function dimensionToMediaParsed(dimension, lowerBound, upperBound, negated) {
|
|
172
|
-
let condition;
|
|
173
|
-
if (lowerBound && upperBound) {
|
|
174
|
-
const lowerOp = lowerBound.inclusive ? "<=" : "<";
|
|
175
|
-
const upperOp = upperBound.inclusive ? "<=" : "<";
|
|
176
|
-
condition = `(${lowerBound.value} ${lowerOp} ${dimension} ${upperOp} ${upperBound.value})`;
|
|
177
|
-
} else if (upperBound) condition = `(${dimension} ${upperBound.inclusive ? "<=" : "<"} ${upperBound.value})`;
|
|
178
|
-
else if (lowerBound) condition = `(${dimension} ${lowerBound.inclusive ? ">=" : ">"} ${lowerBound.value})`;
|
|
179
|
-
else condition = `(${dimension})`;
|
|
180
|
-
return [{
|
|
181
|
-
subtype: "dimension",
|
|
182
|
-
negated: negated ?? false,
|
|
183
|
-
condition,
|
|
184
|
-
dimension,
|
|
185
|
-
lowerBound,
|
|
186
|
-
upperBound
|
|
187
|
-
}];
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Convert container condition to parsed structure
|
|
191
|
-
* This enables structured analysis for contradiction detection and condition combining
|
|
192
|
-
*/
|
|
193
|
-
function containerToParsed(state) {
|
|
194
|
-
let condition;
|
|
195
|
-
if (state.subtype === "style") if (state.propertyValue) condition = `style(--${state.property}: ${state.propertyValue})`;
|
|
196
|
-
else condition = `style(--${state.property})`;
|
|
197
|
-
else if (state.subtype === "raw") condition = state.rawCondition;
|
|
198
|
-
else condition = dimensionToContainerCondition(state.dimension || "width", state.lowerBound, state.upperBound);
|
|
199
|
-
return {
|
|
200
|
-
name: state.containerName,
|
|
201
|
-
condition,
|
|
202
|
-
negated: state.negated ?? false,
|
|
203
|
-
subtype: state.subtype,
|
|
204
|
-
property: state.property,
|
|
205
|
-
propertyValue: state.propertyValue
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Convert dimension bounds to container query condition (single string)
|
|
210
|
-
* Container queries support "not (condition)", so no need to invert manually
|
|
211
|
-
*/
|
|
212
|
-
function dimensionToContainerCondition(dimension, lowerBound, upperBound) {
|
|
213
|
-
if (lowerBound && upperBound) {
|
|
214
|
-
const lowerOp = lowerBound.inclusive ? "<=" : "<";
|
|
215
|
-
const upperOp = upperBound.inclusive ? "<=" : "<";
|
|
216
|
-
return `(${lowerBound.value} ${lowerOp} ${dimension} ${upperOp} ${upperBound.value})`;
|
|
217
|
-
} else if (upperBound) return `(${dimension} ${upperBound.inclusive ? "<=" : "<"} ${upperBound.value})`;
|
|
218
|
-
else if (lowerBound) return `(${dimension} ${lowerBound.inclusive ? ">=" : ">"} ${lowerBound.value})`;
|
|
219
|
-
return "(width)";
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Convert supports condition to parsed structure
|
|
223
|
-
*/
|
|
224
|
-
function supportsToParsed(state) {
|
|
225
|
-
return {
|
|
226
|
-
subtype: state.subtype,
|
|
227
|
-
condition: state.condition,
|
|
228
|
-
negated: state.negated ?? false
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Convert root condition to parsed structure
|
|
233
|
-
*/
|
|
234
|
-
function rootToParsed(state) {
|
|
235
|
-
return {
|
|
236
|
-
selector: state.selector,
|
|
237
|
-
negated: state.negated ?? false
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Convert parsed root conditions to CSS selector prefix (for final output)
|
|
242
|
-
*/
|
|
243
|
-
function rootConditionsToCSS(roots) {
|
|
244
|
-
if (roots.length === 0) return void 0;
|
|
245
|
-
let prefix = ":root";
|
|
246
|
-
for (const root of roots) if (root.negated) prefix += `:not(${root.selector})`;
|
|
247
|
-
else prefix += root.selector;
|
|
248
|
-
return prefix;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Convert own condition to parsed structures for sub-element
|
|
252
|
-
*/
|
|
253
|
-
function ownToParsed(state) {
|
|
254
|
-
const innerCSS = conditionToCSS(state.innerCondition);
|
|
255
|
-
if (innerCSS.isImpossible || innerCSS.variants.length === 0) return [];
|
|
256
|
-
const allConditions = [];
|
|
257
|
-
for (const variant of innerCSS.variants) {
|
|
258
|
-
for (const mod of variant.modifierConditions) allConditions.push({
|
|
259
|
-
...mod,
|
|
260
|
-
negated: state.negated ? !mod.negated : mod.negated
|
|
261
|
-
});
|
|
262
|
-
for (const pseudo of variant.pseudoConditions) allConditions.push({
|
|
263
|
-
...pseudo,
|
|
264
|
-
negated: state.negated ? !pseudo.negated : pseudo.negated
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
return allConditions;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Get unique key for a modifier condition
|
|
271
|
-
*/
|
|
272
|
-
function getModifierKey(mod) {
|
|
273
|
-
const base = mod.value ? `${mod.attribute}${mod.operator || "="}${mod.value}` : mod.attribute;
|
|
274
|
-
return mod.negated ? `!${base}` : base;
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Get unique key for a pseudo condition
|
|
278
|
-
*/
|
|
279
|
-
function getPseudoKey(pseudo) {
|
|
280
|
-
return pseudo.negated ? `!${pseudo.pseudo}` : pseudo.pseudo;
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Get unique key for a root condition
|
|
284
|
-
*/
|
|
285
|
-
function getRootKey(root) {
|
|
286
|
-
return root.negated ? `!${root.selector}` : root.selector;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Deduplicate modifier conditions
|
|
290
|
-
*/
|
|
291
|
-
function dedupeModifierConditions(conditions) {
|
|
292
|
-
const seen = /* @__PURE__ */ new Set();
|
|
293
|
-
const result = [];
|
|
294
|
-
for (const c of conditions) {
|
|
295
|
-
const key = getModifierKey(c);
|
|
296
|
-
if (!seen.has(key)) {
|
|
297
|
-
seen.add(key);
|
|
298
|
-
result.push(c);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return result;
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Deduplicate pseudo conditions
|
|
305
|
-
*/
|
|
306
|
-
function dedupePseudoConditions(conditions) {
|
|
307
|
-
const seen = /* @__PURE__ */ new Set();
|
|
308
|
-
const result = [];
|
|
309
|
-
for (const c of conditions) {
|
|
310
|
-
const key = getPseudoKey(c);
|
|
311
|
-
if (!seen.has(key)) {
|
|
312
|
-
seen.add(key);
|
|
313
|
-
result.push(c);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
return result;
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* Deduplicate root conditions
|
|
320
|
-
*/
|
|
321
|
-
function dedupeRootConditions(conditions) {
|
|
322
|
-
const seen = /* @__PURE__ */ new Set();
|
|
323
|
-
const result = [];
|
|
324
|
-
for (const c of conditions) {
|
|
325
|
-
const key = getRootKey(c);
|
|
326
|
-
if (!seen.has(key)) {
|
|
327
|
-
seen.add(key);
|
|
328
|
-
result.push(c);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
return result;
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Deduplicate own conditions (modifiers or pseudos)
|
|
335
|
-
*/
|
|
336
|
-
function dedupeOwnConditions(conditions) {
|
|
337
|
-
const seen = /* @__PURE__ */ new Set();
|
|
338
|
-
const result = [];
|
|
339
|
-
for (const c of conditions) {
|
|
340
|
-
const key = "attribute" in c ? `mod:${getModifierKey(c)}` : `pseudo:${getPseudoKey(c)}`;
|
|
341
|
-
if (!seen.has(key)) {
|
|
342
|
-
seen.add(key);
|
|
343
|
-
result.push(c);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
return result;
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Check for modifier contradiction: same attribute with opposite negation
|
|
350
|
-
*/
|
|
351
|
-
function hasModifierContradiction(conditions) {
|
|
352
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
353
|
-
for (const mod of conditions) {
|
|
354
|
-
const baseKey = mod.value ? `${mod.attribute}${mod.operator || "="}${mod.value}` : mod.attribute;
|
|
355
|
-
const existing = byKey.get(baseKey);
|
|
356
|
-
if (existing !== void 0 && existing !== !mod.negated) return true;
|
|
357
|
-
byKey.set(baseKey, !mod.negated);
|
|
358
|
-
}
|
|
359
|
-
return false;
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Check for pseudo contradiction: same pseudo with opposite negation
|
|
363
|
-
*/
|
|
364
|
-
function hasPseudoContradiction(conditions) {
|
|
365
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
366
|
-
for (const pseudo of conditions) {
|
|
367
|
-
const existing = byKey.get(pseudo.pseudo);
|
|
368
|
-
if (existing !== void 0 && existing !== !pseudo.negated) return true;
|
|
369
|
-
byKey.set(pseudo.pseudo, !pseudo.negated);
|
|
370
|
-
}
|
|
371
|
-
return false;
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* Check for root condition contradiction: same selector with opposite negation
|
|
375
|
-
*/
|
|
376
|
-
function hasRootContradiction(conditions) {
|
|
377
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
378
|
-
for (const root of conditions) {
|
|
379
|
-
const existing = byKey.get(root.selector);
|
|
380
|
-
if (existing !== void 0 && existing !== !root.negated) return true;
|
|
381
|
-
byKey.set(root.selector, !root.negated);
|
|
382
|
-
}
|
|
383
|
-
return false;
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Check for own condition contradiction
|
|
387
|
-
*/
|
|
388
|
-
function hasOwnConditionContradiction(conditions) {
|
|
389
|
-
const modifiers = [];
|
|
390
|
-
const pseudos = [];
|
|
391
|
-
for (const c of conditions) if ("attribute" in c) modifiers.push(c);
|
|
392
|
-
else pseudos.push(c);
|
|
393
|
-
return hasModifierContradiction(modifiers) || hasPseudoContradiction(pseudos);
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Merge two selector variants (AND operation)
|
|
397
|
-
* Deduplicates conditions and checks for contradictions
|
|
398
|
-
*/
|
|
399
|
-
function mergeVariants(a, b) {
|
|
400
|
-
const mergedMedia = dedupeMediaConditions([...a.mediaConditions, ...b.mediaConditions]);
|
|
401
|
-
if (hasMediaContradiction(mergedMedia)) return null;
|
|
402
|
-
const mergedRoots = dedupeRootConditions([...a.rootConditions, ...b.rootConditions]);
|
|
403
|
-
if (hasRootContradiction(mergedRoots)) return null;
|
|
404
|
-
const mergedModifiers = dedupeModifierConditions([...a.modifierConditions, ...b.modifierConditions]);
|
|
405
|
-
if (hasModifierContradiction(mergedModifiers)) return null;
|
|
406
|
-
const mergedPseudos = dedupePseudoConditions([...a.pseudoConditions, ...b.pseudoConditions]);
|
|
407
|
-
if (hasPseudoContradiction(mergedPseudos)) return null;
|
|
408
|
-
const mergedOwn = dedupeOwnConditions([...a.ownConditions, ...b.ownConditions]);
|
|
409
|
-
if (hasOwnConditionContradiction(mergedOwn)) return null;
|
|
410
|
-
const mergedContainers = dedupeContainerConditions([...a.containerConditions, ...b.containerConditions]);
|
|
411
|
-
if (hasContainerStyleContradiction(mergedContainers)) return null;
|
|
412
|
-
const mergedSupports = dedupeSupportsConditions([...a.supportsConditions, ...b.supportsConditions]);
|
|
413
|
-
if (hasSupportsContradiction(mergedSupports)) return null;
|
|
414
|
-
return {
|
|
415
|
-
modifierConditions: mergedModifiers,
|
|
416
|
-
pseudoConditions: mergedPseudos,
|
|
417
|
-
ownConditions: mergedOwn,
|
|
418
|
-
mediaConditions: mergedMedia,
|
|
419
|
-
containerConditions: mergedContainers,
|
|
420
|
-
supportsConditions: mergedSupports,
|
|
421
|
-
rootConditions: mergedRoots,
|
|
422
|
-
startingStyle: a.startingStyle || b.startingStyle
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* Deduplicate media conditions by their key (subtype + condition + negated)
|
|
427
|
-
*/
|
|
428
|
-
function dedupeMediaConditions(conditions) {
|
|
429
|
-
const seen = /* @__PURE__ */ new Set();
|
|
430
|
-
const result = [];
|
|
431
|
-
for (const c of conditions) {
|
|
432
|
-
const key = `${c.subtype}|${c.condition}|${c.negated}`;
|
|
433
|
-
if (!seen.has(key)) {
|
|
434
|
-
seen.add(key);
|
|
435
|
-
result.push(c);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
return result;
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Deduplicate container conditions by their key (name + condition + negated)
|
|
442
|
-
*/
|
|
443
|
-
function dedupeContainerConditions(conditions) {
|
|
444
|
-
const seen = /* @__PURE__ */ new Set();
|
|
445
|
-
const result = [];
|
|
446
|
-
for (const c of conditions) {
|
|
447
|
-
const key = `${c.name ?? ""}|${c.condition}|${c.negated}`;
|
|
448
|
-
if (!seen.has(key)) {
|
|
449
|
-
seen.add(key);
|
|
450
|
-
result.push(c);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return result;
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Deduplicate supports conditions by their key (subtype + condition + negated)
|
|
457
|
-
*/
|
|
458
|
-
function dedupeSupportsConditions(conditions) {
|
|
459
|
-
const seen = /* @__PURE__ */ new Set();
|
|
460
|
-
const result = [];
|
|
461
|
-
for (const c of conditions) {
|
|
462
|
-
const key = `${c.subtype}|${c.condition}|${c.negated}`;
|
|
463
|
-
if (!seen.has(key)) {
|
|
464
|
-
seen.add(key);
|
|
465
|
-
result.push(c);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
return result;
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* Check if supports conditions contain contradictions
|
|
472
|
-
* e.g., @supports(display: grid) AND NOT @supports(display: grid)
|
|
473
|
-
*/
|
|
474
|
-
function hasSupportsContradiction(conditions) {
|
|
475
|
-
const conditionMap = /* @__PURE__ */ new Map();
|
|
476
|
-
for (const cond of conditions) {
|
|
477
|
-
const key = `${cond.subtype}|${cond.condition}`;
|
|
478
|
-
const existing = conditionMap.get(key);
|
|
479
|
-
if (existing !== void 0 && existing !== !cond.negated) return true;
|
|
480
|
-
conditionMap.set(key, !cond.negated);
|
|
481
|
-
}
|
|
482
|
-
return false;
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* Check if a set of media conditions contains contradictions
|
|
486
|
-
* e.g., (prefers-color-scheme: light) AND NOT (prefers-color-scheme: light)
|
|
487
|
-
* or (width >= 900px) AND (width < 600px)
|
|
488
|
-
*
|
|
489
|
-
* Uses parsed media conditions for efficient analysis without regex parsing.
|
|
490
|
-
*/
|
|
491
|
-
function hasMediaContradiction(conditions) {
|
|
492
|
-
const featureConditions = /* @__PURE__ */ new Map();
|
|
493
|
-
const typeConditions = /* @__PURE__ */ new Map();
|
|
494
|
-
const dimensionConditions = /* @__PURE__ */ new Map();
|
|
495
|
-
const dimensionsByDim = /* @__PURE__ */ new Map();
|
|
496
|
-
for (const cond of conditions) if (cond.subtype === "type") {
|
|
497
|
-
const key = cond.mediaType || "all";
|
|
498
|
-
const existing = typeConditions.get(key);
|
|
499
|
-
if (existing !== void 0 && existing !== !cond.negated) return true;
|
|
500
|
-
typeConditions.set(key, !cond.negated);
|
|
501
|
-
} else if (cond.subtype === "feature") {
|
|
502
|
-
const key = cond.condition;
|
|
503
|
-
const existing = featureConditions.get(key);
|
|
504
|
-
if (existing !== void 0 && existing !== !cond.negated) return true;
|
|
505
|
-
featureConditions.set(key, !cond.negated);
|
|
506
|
-
} else if (cond.subtype === "dimension") {
|
|
507
|
-
const condKey = cond.condition;
|
|
508
|
-
const existing = dimensionConditions.get(condKey);
|
|
509
|
-
if (existing !== void 0 && existing !== !cond.negated) return true;
|
|
510
|
-
dimensionConditions.set(condKey, !cond.negated);
|
|
511
|
-
if (!cond.negated) {
|
|
512
|
-
const dim = cond.dimension || "width";
|
|
513
|
-
let bounds = dimensionsByDim.get(dim);
|
|
514
|
-
if (!bounds) {
|
|
515
|
-
bounds = {
|
|
516
|
-
lowerBound: null,
|
|
517
|
-
upperBound: null
|
|
518
|
-
};
|
|
519
|
-
dimensionsByDim.set(dim, bounds);
|
|
520
|
-
}
|
|
521
|
-
if (cond.lowerBound?.valueNumeric != null) {
|
|
522
|
-
const value = cond.lowerBound.valueNumeric;
|
|
523
|
-
if (bounds.lowerBound === null || value > bounds.lowerBound) bounds.lowerBound = value;
|
|
524
|
-
}
|
|
525
|
-
if (cond.upperBound?.valueNumeric != null) {
|
|
526
|
-
const value = cond.upperBound.valueNumeric;
|
|
527
|
-
if (bounds.upperBound === null || value < bounds.upperBound) bounds.upperBound = value;
|
|
528
|
-
}
|
|
529
|
-
if (bounds.lowerBound !== null && bounds.upperBound !== null && bounds.lowerBound >= bounds.upperBound) return true;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
return false;
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* Check if container conditions contain contradictions in style queries
|
|
536
|
-
* e.g., style(--variant: danger) and style(--variant: success) together
|
|
537
|
-
* Same property with different values = always false
|
|
538
|
-
*
|
|
539
|
-
* Uses parsed container conditions for efficient analysis without regex parsing.
|
|
540
|
-
*/
|
|
541
|
-
function hasContainerStyleContradiction(conditions) {
|
|
542
|
-
const styleQueries = /* @__PURE__ */ new Map();
|
|
543
|
-
for (const cond of conditions) {
|
|
544
|
-
if (cond.subtype !== "style" || !cond.property) continue;
|
|
545
|
-
const property = cond.property;
|
|
546
|
-
const value = cond.propertyValue;
|
|
547
|
-
if (!styleQueries.has(property)) styleQueries.set(property, {
|
|
548
|
-
hasExistence: false,
|
|
549
|
-
values: /* @__PURE__ */ new Set(),
|
|
550
|
-
hasNegatedExistence: false
|
|
551
|
-
});
|
|
552
|
-
const entry = styleQueries.get(property);
|
|
553
|
-
if (cond.negated) {
|
|
554
|
-
if (value === void 0) entry.hasNegatedExistence = true;
|
|
555
|
-
} else if (value === void 0) entry.hasExistence = true;
|
|
556
|
-
else entry.values.add(value);
|
|
557
|
-
}
|
|
558
|
-
for (const [, entry] of styleQueries) {
|
|
559
|
-
if (entry.hasExistence && entry.hasNegatedExistence) return true;
|
|
560
|
-
if (entry.values.size > 1) return true;
|
|
561
|
-
if (entry.hasNegatedExistence && entry.values.size > 0) return true;
|
|
562
|
-
}
|
|
563
|
-
return false;
|
|
564
|
-
}
|
|
565
|
-
/**
|
|
566
|
-
* Get a unique key for a variant (for deduplication)
|
|
567
|
-
*/
|
|
568
|
-
function getVariantKey(v) {
|
|
569
|
-
const modifierKey = v.modifierConditions.map(getModifierKey).sort().join("|");
|
|
570
|
-
const pseudoKey = v.pseudoConditions.map(getPseudoKey).sort().join("|");
|
|
571
|
-
const ownKey = v.ownConditions.map((c) => "attribute" in c ? `mod:${getModifierKey(c)}` : `pseudo:${getPseudoKey(c)}`).sort().join("|");
|
|
572
|
-
const containerKey = v.containerConditions.map((c) => `${c.name ?? ""}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|");
|
|
573
|
-
return [
|
|
574
|
-
modifierKey,
|
|
575
|
-
pseudoKey,
|
|
576
|
-
ownKey,
|
|
577
|
-
v.mediaConditions.map((c) => `${c.subtype}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|"),
|
|
578
|
-
containerKey,
|
|
579
|
-
v.supportsConditions.map((c) => `${c.subtype}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|"),
|
|
580
|
-
v.rootConditions.map(getRootKey).sort().join("|"),
|
|
581
|
-
v.startingStyle ? "1" : "0"
|
|
582
|
-
].join("###");
|
|
583
|
-
}
|
|
584
|
-
/**
|
|
585
|
-
* Check if variant A is a superset of variant B (A is more restrictive)
|
|
586
|
-
*
|
|
587
|
-
* If A has all of B's conditions plus more, then A is redundant
|
|
588
|
-
* because B already covers the same cases (and more).
|
|
589
|
-
*
|
|
590
|
-
* Example:
|
|
591
|
-
* A: :not([size=large]):not([size=medium]):not([size=small])
|
|
592
|
-
* B: :not([size=large])
|
|
593
|
-
* A is a superset of B, so A is redundant when B exists.
|
|
594
|
-
*/
|
|
595
|
-
function isVariantSuperset(a, b) {
|
|
596
|
-
if (a.startingStyle !== b.startingStyle) return false;
|
|
597
|
-
if (!isRootConditionsSuperset(a.rootConditions, b.rootConditions)) return false;
|
|
598
|
-
if (!isMediaConditionsSuperset(a.mediaConditions, b.mediaConditions)) return false;
|
|
599
|
-
if (!isContainerConditionsSuperset(a.containerConditions, b.containerConditions)) return false;
|
|
600
|
-
if (!isSupportsConditionsSuperset(a.supportsConditions, b.supportsConditions)) return false;
|
|
601
|
-
if (!isModifierConditionsSuperset(a.modifierConditions, b.modifierConditions)) return false;
|
|
602
|
-
if (!isPseudoConditionsSuperset(a.pseudoConditions, b.pseudoConditions)) return false;
|
|
603
|
-
if (!isOwnConditionsSuperset(a.ownConditions, b.ownConditions)) return false;
|
|
604
|
-
return a.mediaConditions.length + a.containerConditions.length + a.supportsConditions.length + a.modifierConditions.length + a.pseudoConditions.length + a.rootConditions.length + a.ownConditions.length > b.mediaConditions.length + b.containerConditions.length + b.supportsConditions.length + b.modifierConditions.length + b.pseudoConditions.length + b.rootConditions.length + b.ownConditions.length;
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* Check if media conditions A is a superset of B
|
|
608
|
-
*/
|
|
609
|
-
function isMediaConditionsSuperset(a, b) {
|
|
610
|
-
const aKeys = new Set(a.map((c) => `${c.subtype}|${c.condition}|${c.negated}`));
|
|
611
|
-
for (const c of b) {
|
|
612
|
-
const key = `${c.subtype}|${c.condition}|${c.negated}`;
|
|
613
|
-
if (!aKeys.has(key)) return false;
|
|
614
|
-
}
|
|
615
|
-
return true;
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Check if container conditions A is a superset of B
|
|
619
|
-
*/
|
|
620
|
-
function isContainerConditionsSuperset(a, b) {
|
|
621
|
-
const aKeys = new Set(a.map((c) => `${c.name ?? ""}|${c.condition}|${c.negated}`));
|
|
622
|
-
for (const c of b) {
|
|
623
|
-
const key = `${c.name ?? ""}|${c.condition}|${c.negated}`;
|
|
624
|
-
if (!aKeys.has(key)) return false;
|
|
625
|
-
}
|
|
626
|
-
return true;
|
|
627
|
-
}
|
|
628
|
-
/**
|
|
629
|
-
* Check if supports conditions A is a superset of B
|
|
630
|
-
*/
|
|
631
|
-
function isSupportsConditionsSuperset(a, b) {
|
|
632
|
-
const aKeys = new Set(a.map((c) => `${c.subtype}|${c.condition}|${c.negated}`));
|
|
633
|
-
for (const c of b) {
|
|
634
|
-
const key = `${c.subtype}|${c.condition}|${c.negated}`;
|
|
635
|
-
if (!aKeys.has(key)) return false;
|
|
636
|
-
}
|
|
637
|
-
return true;
|
|
638
|
-
}
|
|
639
|
-
/**
|
|
640
|
-
* Check if modifier conditions A is a superset of B
|
|
641
|
-
*/
|
|
642
|
-
function isModifierConditionsSuperset(a, b) {
|
|
643
|
-
const aKeys = new Set(a.map(getModifierKey));
|
|
644
|
-
for (const c of b) if (!aKeys.has(getModifierKey(c))) return false;
|
|
645
|
-
return true;
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* Check if pseudo conditions A is a superset of B
|
|
649
|
-
*/
|
|
650
|
-
function isPseudoConditionsSuperset(a, b) {
|
|
651
|
-
const aKeys = new Set(a.map(getPseudoKey));
|
|
652
|
-
for (const c of b) if (!aKeys.has(getPseudoKey(c))) return false;
|
|
653
|
-
return true;
|
|
654
|
-
}
|
|
655
|
-
/**
|
|
656
|
-
* Check if root conditions A is a superset of B
|
|
657
|
-
*/
|
|
658
|
-
function isRootConditionsSuperset(a, b) {
|
|
659
|
-
const aKeys = new Set(a.map(getRootKey));
|
|
660
|
-
for (const c of b) if (!aKeys.has(getRootKey(c))) return false;
|
|
661
|
-
return true;
|
|
662
|
-
}
|
|
663
|
-
/**
|
|
664
|
-
* Check if own conditions A is a superset of B
|
|
665
|
-
*/
|
|
666
|
-
function isOwnConditionsSuperset(a, b) {
|
|
667
|
-
const aKeys = new Set(a.map((c) => "attribute" in c ? `mod:${getModifierKey(c)}` : `pseudo:${getPseudoKey(c)}`));
|
|
668
|
-
for (const c of b) {
|
|
669
|
-
const key = "attribute" in c ? `mod:${getModifierKey(c)}` : `pseudo:${getPseudoKey(c)}`;
|
|
670
|
-
if (!aKeys.has(key)) return false;
|
|
671
|
-
}
|
|
672
|
-
return true;
|
|
673
|
-
}
|
|
674
|
-
/**
|
|
675
|
-
* Deduplicate variants
|
|
676
|
-
*
|
|
677
|
-
* Removes:
|
|
678
|
-
* 1. Exact duplicates (same key)
|
|
679
|
-
* 2. Superset variants (more restrictive selectors that are redundant)
|
|
680
|
-
*/
|
|
681
|
-
function dedupeVariants(variants) {
|
|
682
|
-
const seen = /* @__PURE__ */ new Set();
|
|
683
|
-
const result = [];
|
|
684
|
-
for (const v of variants) {
|
|
685
|
-
const key = getVariantKey(v);
|
|
686
|
-
if (!seen.has(key)) {
|
|
687
|
-
seen.add(key);
|
|
688
|
-
result.push(v);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
result.sort((a, b) => {
|
|
692
|
-
return a.modifierConditions.length + a.pseudoConditions.length + a.ownConditions.length + a.mediaConditions.length + a.containerConditions.length + a.supportsConditions.length + a.rootConditions.length - (b.modifierConditions.length + b.pseudoConditions.length + b.ownConditions.length + b.mediaConditions.length + b.containerConditions.length + b.supportsConditions.length + b.rootConditions.length);
|
|
693
|
-
});
|
|
694
|
-
const filtered = [];
|
|
695
|
-
for (const candidate of result) {
|
|
696
|
-
let isRedundant = false;
|
|
697
|
-
for (const kept of filtered) if (isVariantSuperset(candidate, kept)) {
|
|
698
|
-
isRedundant = true;
|
|
699
|
-
break;
|
|
700
|
-
}
|
|
701
|
-
if (!isRedundant) filtered.push(candidate);
|
|
702
|
-
}
|
|
703
|
-
return filtered;
|
|
704
|
-
}
|
|
705
|
-
/**
|
|
706
|
-
* Combine AND conditions into CSS
|
|
707
|
-
*
|
|
708
|
-
* AND of conditions means cartesian product of variants:
|
|
709
|
-
* (A1 | A2) & (B1 | B2) = A1&B1 | A1&B2 | A2&B1 | A2&B2
|
|
710
|
-
*
|
|
711
|
-
* Variants that result in contradictions (e.g., conflicting media rules)
|
|
712
|
-
* are filtered out.
|
|
713
|
-
*/
|
|
714
|
-
function andToCSS(children) {
|
|
715
|
-
let currentVariants = [emptyVariant()];
|
|
716
|
-
for (const child of children) {
|
|
717
|
-
const childCSS = conditionToCSSInner(child);
|
|
718
|
-
if (childCSS.isImpossible || childCSS.variants.length === 0) return {
|
|
719
|
-
variants: [],
|
|
720
|
-
isImpossible: true
|
|
721
|
-
};
|
|
722
|
-
const newVariants = [];
|
|
723
|
-
for (const current of currentVariants) for (const childVariant of childCSS.variants) {
|
|
724
|
-
const merged = mergeVariants(current, childVariant);
|
|
725
|
-
if (merged !== null) newVariants.push(merged);
|
|
726
|
-
}
|
|
727
|
-
if (newVariants.length === 0) return {
|
|
728
|
-
variants: [],
|
|
729
|
-
isImpossible: true
|
|
730
|
-
};
|
|
731
|
-
currentVariants = dedupeVariants(newVariants);
|
|
732
|
-
}
|
|
733
|
-
return {
|
|
734
|
-
variants: currentVariants,
|
|
735
|
-
isImpossible: false
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
|
-
/**
|
|
739
|
-
* Combine OR conditions into CSS
|
|
740
|
-
*
|
|
741
|
-
* OR in CSS means multiple selector variants (DNF).
|
|
742
|
-
* Each variant becomes a separate selector in the comma-separated list,
|
|
743
|
-
* or multiple CSS rules if they have different at-rules.
|
|
744
|
-
*
|
|
745
|
-
* Note: OR exclusivity is handled at the pipeline level (expandOrConditions),
|
|
746
|
-
* so here we just collect all variants. Any remaining ORs in the condition
|
|
747
|
-
* tree (e.g., from De Morgan expansion) are handled as simple alternatives.
|
|
748
|
-
*/
|
|
749
|
-
function orToCSS(children) {
|
|
750
|
-
const allVariants = [];
|
|
751
|
-
for (const child of children) {
|
|
752
|
-
const childCSS = conditionToCSSInner(child);
|
|
753
|
-
if (childCSS.isImpossible) continue;
|
|
754
|
-
allVariants.push(...childCSS.variants);
|
|
755
|
-
}
|
|
756
|
-
if (allVariants.length === 0) return {
|
|
757
|
-
variants: [],
|
|
758
|
-
isImpossible: true
|
|
759
|
-
};
|
|
760
|
-
return {
|
|
761
|
-
variants: dedupeVariants(allVariants),
|
|
762
|
-
isImpossible: false
|
|
763
|
-
};
|
|
764
|
-
}
|
|
765
|
-
/**
|
|
766
|
-
* Get a cache key for a condition
|
|
767
|
-
*/
|
|
768
|
-
function getConditionKey(node) {
|
|
769
|
-
if (node.kind === "true") return "TRUE";
|
|
770
|
-
if (node.kind === "false") return "FALSE";
|
|
771
|
-
if (node.kind === "state") return node.uniqueId;
|
|
772
|
-
if (node.kind === "compound") {
|
|
773
|
-
const childKeys = node.children.map(getConditionKey).sort();
|
|
774
|
-
return `${node.operator}(${childKeys.join(",")})`;
|
|
775
|
-
}
|
|
776
|
-
return "UNKNOWN";
|
|
777
|
-
}
|
|
778
|
-
/**
|
|
779
|
-
* Build at-rules array from a variant
|
|
780
|
-
*/
|
|
781
|
-
function buildAtRulesFromVariant(variant) {
|
|
782
|
-
const atRules = [];
|
|
783
|
-
if (variant.mediaConditions.length > 0) {
|
|
784
|
-
const conditionParts = variant.mediaConditions.map((c) => {
|
|
785
|
-
if (c.subtype === "type") return c.negated ? `not ${c.condition}` : c.condition;
|
|
786
|
-
else return c.negated ? `(not ${c.condition})` : c.condition;
|
|
787
|
-
});
|
|
788
|
-
atRules.push(`@media ${conditionParts.join(" and ")}`);
|
|
789
|
-
}
|
|
790
|
-
if (variant.containerConditions.length > 0) {
|
|
791
|
-
const byName = /* @__PURE__ */ new Map();
|
|
792
|
-
for (const cond of variant.containerConditions) {
|
|
793
|
-
const group = byName.get(cond.name) || [];
|
|
794
|
-
group.push(cond);
|
|
795
|
-
byName.set(cond.name, group);
|
|
796
|
-
}
|
|
797
|
-
for (const [name, conditions] of byName) {
|
|
798
|
-
const conditionParts = conditions.map((c) => c.negated ? `(not ${c.condition})` : c.condition);
|
|
799
|
-
const namePrefix = name ? `${name} ` : "";
|
|
800
|
-
atRules.push(`@container ${namePrefix}${conditionParts.join(" and ")}`);
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
if (variant.supportsConditions.length > 0) {
|
|
804
|
-
const conditionParts = variant.supportsConditions.map((c) => {
|
|
805
|
-
if (c.subtype === "selector") {
|
|
806
|
-
const selectorCond = `selector(${c.condition})`;
|
|
807
|
-
return c.negated ? `(not ${selectorCond})` : selectorCond;
|
|
808
|
-
} else {
|
|
809
|
-
const featureCond = `(${c.condition})`;
|
|
810
|
-
return c.negated ? `(not ${featureCond})` : featureCond;
|
|
811
|
-
}
|
|
812
|
-
});
|
|
813
|
-
atRules.push(`@supports ${conditionParts.join(" and ")}`);
|
|
814
|
-
}
|
|
815
|
-
if (variant.startingStyle) atRules.push("@starting-style");
|
|
816
|
-
return atRules;
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
//#endregion
|
|
820
|
-
export { buildAtRulesFromVariant, conditionToCSS, modifierToCSS, pseudoToCSS, rootConditionsToCSS };
|
|
821
|
-
//# sourceMappingURL=materialize.mjs.map
|