@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,377 +0,0 @@
|
|
|
1
|
-
//#region src/pipeline/conditions.ts
|
|
2
|
-
/**
|
|
3
|
-
* Create a TRUE condition (matches everything)
|
|
4
|
-
*/
|
|
5
|
-
function trueCondition() {
|
|
6
|
-
return { kind: "true" };
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Create a FALSE condition (matches nothing)
|
|
10
|
-
*/
|
|
11
|
-
function falseCondition() {
|
|
12
|
-
return { kind: "false" };
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Create an AND compound condition
|
|
16
|
-
*/
|
|
17
|
-
function and(...children) {
|
|
18
|
-
const filtered = [];
|
|
19
|
-
for (const child of children) {
|
|
20
|
-
if (child.kind === "false") return falseCondition();
|
|
21
|
-
if (child.kind === "true") continue;
|
|
22
|
-
if (child.kind === "compound" && child.operator === "AND") filtered.push(...child.children);
|
|
23
|
-
else filtered.push(child);
|
|
24
|
-
}
|
|
25
|
-
if (filtered.length === 0) return trueCondition();
|
|
26
|
-
if (filtered.length === 1) return filtered[0];
|
|
27
|
-
return {
|
|
28
|
-
kind: "compound",
|
|
29
|
-
operator: "AND",
|
|
30
|
-
children: filtered
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Create an OR compound condition
|
|
35
|
-
*/
|
|
36
|
-
function or(...children) {
|
|
37
|
-
const filtered = [];
|
|
38
|
-
for (const child of children) {
|
|
39
|
-
if (child.kind === "true") return trueCondition();
|
|
40
|
-
if (child.kind === "false") continue;
|
|
41
|
-
if (child.kind === "compound" && child.operator === "OR") filtered.push(...child.children);
|
|
42
|
-
else filtered.push(child);
|
|
43
|
-
}
|
|
44
|
-
if (filtered.length === 0) return falseCondition();
|
|
45
|
-
if (filtered.length === 1) return filtered[0];
|
|
46
|
-
return {
|
|
47
|
-
kind: "compound",
|
|
48
|
-
operator: "OR",
|
|
49
|
-
children: filtered
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Negate a condition
|
|
54
|
-
*/
|
|
55
|
-
function not(node) {
|
|
56
|
-
if (node.kind === "true") return falseCondition();
|
|
57
|
-
if (node.kind === "false") return trueCondition();
|
|
58
|
-
if (node.kind === "state") return {
|
|
59
|
-
...node,
|
|
60
|
-
negated: !node.negated,
|
|
61
|
-
uniqueId: node.negated ? node.uniqueId.replace(/^!/, "") : `!${node.uniqueId}`
|
|
62
|
-
};
|
|
63
|
-
if (node.kind === "compound" && node.operator === "AND") return or(...node.children.map((c) => not(c)));
|
|
64
|
-
if (node.kind === "compound" && node.operator === "OR") return and(...node.children.map((c) => not(c)));
|
|
65
|
-
return node;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Check if a condition is a compound condition
|
|
69
|
-
*/
|
|
70
|
-
function isCompoundCondition(node) {
|
|
71
|
-
return node.kind === "compound";
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Generate a normalized unique ID for a modifier condition
|
|
75
|
-
*/
|
|
76
|
-
function modifierUniqueId(attribute, value, operator = "=", negated = false) {
|
|
77
|
-
const base = value ? `mod:${attribute}${operator}${value}` : `mod:${attribute}`;
|
|
78
|
-
return negated ? `!${base}` : base;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Generate a normalized unique ID for a pseudo condition
|
|
82
|
-
*/
|
|
83
|
-
function pseudoUniqueId(pseudo, negated = false) {
|
|
84
|
-
const base = `pseudo:${pseudo}`;
|
|
85
|
-
return negated ? `!${base}` : base;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Generate a normalized unique ID for a media condition
|
|
89
|
-
*/
|
|
90
|
-
function mediaUniqueId(subtype, props, negated = false) {
|
|
91
|
-
let base;
|
|
92
|
-
if (subtype === "dimension") {
|
|
93
|
-
const parts = [
|
|
94
|
-
"media",
|
|
95
|
-
"dim",
|
|
96
|
-
props.dimension
|
|
97
|
-
];
|
|
98
|
-
if (props.lowerBound) {
|
|
99
|
-
parts.push(props.lowerBound.inclusive ? ">=" : ">");
|
|
100
|
-
parts.push(props.lowerBound.value);
|
|
101
|
-
}
|
|
102
|
-
if (props.upperBound) {
|
|
103
|
-
parts.push(props.upperBound.inclusive ? "<=" : "<");
|
|
104
|
-
parts.push(props.upperBound.value);
|
|
105
|
-
}
|
|
106
|
-
base = parts.join(":");
|
|
107
|
-
} else if (subtype === "feature") base = props.featureValue ? `media:feat:${props.feature}:${props.featureValue}` : `media:feat:${props.feature}`;
|
|
108
|
-
else base = `media:type:${props.mediaType}`;
|
|
109
|
-
return negated ? `!${base}` : base;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Generate a normalized unique ID for a container condition
|
|
113
|
-
*/
|
|
114
|
-
function containerUniqueId(subtype, props, negated = false) {
|
|
115
|
-
let base;
|
|
116
|
-
const name = props.containerName || "_";
|
|
117
|
-
if (subtype === "dimension") {
|
|
118
|
-
const parts = [
|
|
119
|
-
"container",
|
|
120
|
-
"dim",
|
|
121
|
-
name,
|
|
122
|
-
props.dimension
|
|
123
|
-
];
|
|
124
|
-
if (props.lowerBound) {
|
|
125
|
-
parts.push(props.lowerBound.inclusive ? ">=" : ">");
|
|
126
|
-
parts.push(props.lowerBound.value);
|
|
127
|
-
}
|
|
128
|
-
if (props.upperBound) {
|
|
129
|
-
parts.push(props.upperBound.inclusive ? "<=" : "<");
|
|
130
|
-
parts.push(props.upperBound.value);
|
|
131
|
-
}
|
|
132
|
-
base = parts.join(":");
|
|
133
|
-
} else if (subtype === "raw") base = `container:raw:${name}:${props.rawCondition}`;
|
|
134
|
-
else base = props.propertyValue ? `container:style:${name}:--${props.property}:${props.propertyValue}` : `container:style:${name}:--${props.property}`;
|
|
135
|
-
return negated ? `!${base}` : base;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Generate a normalized unique ID for a root condition
|
|
139
|
-
*/
|
|
140
|
-
function rootUniqueId(selector, negated = false) {
|
|
141
|
-
const base = `root:${selector}`;
|
|
142
|
-
return negated ? `!${base}` : base;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Generate a normalized unique ID for an own condition
|
|
146
|
-
*/
|
|
147
|
-
function ownUniqueId(innerUniqueId, negated = false) {
|
|
148
|
-
const base = `own:${innerUniqueId}`;
|
|
149
|
-
return negated ? `!${base}` : base;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Generate a normalized unique ID for a starting condition
|
|
153
|
-
*/
|
|
154
|
-
function startingUniqueId(negated = false) {
|
|
155
|
-
return negated ? "!starting" : "starting";
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Generate a normalized unique ID for a supports condition
|
|
159
|
-
*/
|
|
160
|
-
function supportsUniqueId(subtype, condition, negated = false) {
|
|
161
|
-
const base = `supports:${subtype}:${condition}`;
|
|
162
|
-
return negated ? `!${base}` : base;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Create a modifier condition
|
|
166
|
-
*/
|
|
167
|
-
function createModifierCondition(attribute, value, operator = "=", negated = false, raw) {
|
|
168
|
-
return {
|
|
169
|
-
kind: "state",
|
|
170
|
-
type: "modifier",
|
|
171
|
-
negated,
|
|
172
|
-
raw: raw || (value ? `${attribute}${operator}${value}` : attribute),
|
|
173
|
-
uniqueId: modifierUniqueId(attribute, value, operator, negated),
|
|
174
|
-
attribute,
|
|
175
|
-
value,
|
|
176
|
-
operator: value ? operator : void 0
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Create a pseudo condition
|
|
181
|
-
*/
|
|
182
|
-
function createPseudoCondition(pseudo, negated = false, raw) {
|
|
183
|
-
return {
|
|
184
|
-
kind: "state",
|
|
185
|
-
type: "pseudo",
|
|
186
|
-
negated,
|
|
187
|
-
raw: raw || pseudo,
|
|
188
|
-
uniqueId: pseudoUniqueId(pseudo, negated),
|
|
189
|
-
pseudo
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Create a media dimension condition
|
|
194
|
-
*/
|
|
195
|
-
function createMediaDimensionCondition(dimension, lowerBound, upperBound, negated = false, raw) {
|
|
196
|
-
return {
|
|
197
|
-
kind: "state",
|
|
198
|
-
type: "media",
|
|
199
|
-
subtype: "dimension",
|
|
200
|
-
negated,
|
|
201
|
-
raw: raw || `@media(${dimension})`,
|
|
202
|
-
uniqueId: mediaUniqueId("dimension", {
|
|
203
|
-
dimension,
|
|
204
|
-
lowerBound,
|
|
205
|
-
upperBound
|
|
206
|
-
}, negated),
|
|
207
|
-
dimension,
|
|
208
|
-
lowerBound,
|
|
209
|
-
upperBound
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Create a media feature condition
|
|
214
|
-
*/
|
|
215
|
-
function createMediaFeatureCondition(feature, featureValue, negated = false, raw) {
|
|
216
|
-
return {
|
|
217
|
-
kind: "state",
|
|
218
|
-
type: "media",
|
|
219
|
-
subtype: "feature",
|
|
220
|
-
negated,
|
|
221
|
-
raw: raw || `@media(${feature}${featureValue ? `: ${featureValue}` : ""})`,
|
|
222
|
-
uniqueId: mediaUniqueId("feature", {
|
|
223
|
-
feature,
|
|
224
|
-
featureValue
|
|
225
|
-
}, negated),
|
|
226
|
-
feature,
|
|
227
|
-
featureValue
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Create a media type condition
|
|
232
|
-
*/
|
|
233
|
-
function createMediaTypeCondition(mediaType, negated = false, raw) {
|
|
234
|
-
return {
|
|
235
|
-
kind: "state",
|
|
236
|
-
type: "media",
|
|
237
|
-
subtype: "type",
|
|
238
|
-
negated,
|
|
239
|
-
raw: raw || `@media:${mediaType}`,
|
|
240
|
-
uniqueId: mediaUniqueId("type", { mediaType }, negated),
|
|
241
|
-
mediaType
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Create a container dimension condition
|
|
246
|
-
*/
|
|
247
|
-
function createContainerDimensionCondition(dimension, lowerBound, upperBound, containerName, negated = false, raw) {
|
|
248
|
-
return {
|
|
249
|
-
kind: "state",
|
|
250
|
-
type: "container",
|
|
251
|
-
subtype: "dimension",
|
|
252
|
-
negated,
|
|
253
|
-
raw: raw || `@(${containerName ? containerName + ", " : ""}${dimension})`,
|
|
254
|
-
uniqueId: containerUniqueId("dimension", {
|
|
255
|
-
containerName,
|
|
256
|
-
dimension,
|
|
257
|
-
lowerBound,
|
|
258
|
-
upperBound
|
|
259
|
-
}, negated),
|
|
260
|
-
containerName,
|
|
261
|
-
dimension,
|
|
262
|
-
lowerBound,
|
|
263
|
-
upperBound
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Create a container style condition
|
|
268
|
-
*/
|
|
269
|
-
function createContainerStyleCondition(property, propertyValue, containerName, negated = false, raw) {
|
|
270
|
-
return {
|
|
271
|
-
kind: "state",
|
|
272
|
-
type: "container",
|
|
273
|
-
subtype: "style",
|
|
274
|
-
negated,
|
|
275
|
-
raw: raw || `@(${containerName ? containerName + ", " : ""}$${property}${propertyValue ? "=" + propertyValue : ""})`,
|
|
276
|
-
uniqueId: containerUniqueId("style", {
|
|
277
|
-
containerName,
|
|
278
|
-
property,
|
|
279
|
-
propertyValue
|
|
280
|
-
}, negated),
|
|
281
|
-
containerName,
|
|
282
|
-
property,
|
|
283
|
-
propertyValue
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Create a container raw function condition (e.g., scroll-state(), style(), etc.)
|
|
288
|
-
* The condition string is passed through to CSS verbatim.
|
|
289
|
-
*/
|
|
290
|
-
function createContainerRawCondition(rawCondition, containerName, negated = false, raw) {
|
|
291
|
-
return {
|
|
292
|
-
kind: "state",
|
|
293
|
-
type: "container",
|
|
294
|
-
subtype: "raw",
|
|
295
|
-
negated,
|
|
296
|
-
raw: raw || `@(${containerName ? containerName + ", " : ""}${rawCondition})`,
|
|
297
|
-
uniqueId: containerUniqueId("raw", {
|
|
298
|
-
containerName,
|
|
299
|
-
rawCondition
|
|
300
|
-
}, negated),
|
|
301
|
-
containerName,
|
|
302
|
-
rawCondition
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Create a root condition
|
|
307
|
-
*/
|
|
308
|
-
function createRootCondition(selector, negated = false, raw) {
|
|
309
|
-
return {
|
|
310
|
-
kind: "state",
|
|
311
|
-
type: "root",
|
|
312
|
-
negated,
|
|
313
|
-
raw: raw || `@root(${selector})`,
|
|
314
|
-
uniqueId: rootUniqueId(selector, negated),
|
|
315
|
-
selector
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* Create an own condition
|
|
320
|
-
*/
|
|
321
|
-
function createOwnCondition(innerCondition, negated = false, raw) {
|
|
322
|
-
const innerUniqueId = getConditionUniqueId(innerCondition);
|
|
323
|
-
return {
|
|
324
|
-
kind: "state",
|
|
325
|
-
type: "own",
|
|
326
|
-
negated,
|
|
327
|
-
raw: raw || `@own(...)`,
|
|
328
|
-
uniqueId: ownUniqueId(innerUniqueId, negated),
|
|
329
|
-
innerCondition
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Create a starting condition
|
|
334
|
-
*/
|
|
335
|
-
function createStartingCondition(negated = false, raw) {
|
|
336
|
-
return {
|
|
337
|
-
kind: "state",
|
|
338
|
-
type: "starting",
|
|
339
|
-
negated,
|
|
340
|
-
raw: raw || "@starting",
|
|
341
|
-
uniqueId: startingUniqueId(negated)
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Create a supports condition
|
|
346
|
-
*
|
|
347
|
-
* @param subtype 'feature' for @supports(display: grid), 'selector' for @supports($, :has(*))
|
|
348
|
-
* @param condition The condition string (e.g., "display: grid" or ":has(*)")
|
|
349
|
-
*/
|
|
350
|
-
function createSupportsCondition(subtype, condition, negated = false, raw) {
|
|
351
|
-
return {
|
|
352
|
-
kind: "state",
|
|
353
|
-
type: "supports",
|
|
354
|
-
subtype,
|
|
355
|
-
negated,
|
|
356
|
-
raw: raw || `@supports(${condition})`,
|
|
357
|
-
uniqueId: supportsUniqueId(subtype, condition, negated),
|
|
358
|
-
condition
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Get the unique ID for any condition node
|
|
363
|
-
*/
|
|
364
|
-
function getConditionUniqueId(node) {
|
|
365
|
-
if (node.kind === "true") return "TRUE";
|
|
366
|
-
if (node.kind === "false") return "FALSE";
|
|
367
|
-
if (node.kind === "state") return node.uniqueId;
|
|
368
|
-
if (node.kind === "compound") {
|
|
369
|
-
const childIds = node.children.map(getConditionUniqueId).sort();
|
|
370
|
-
return `${node.operator}(${childIds.join(",")})`;
|
|
371
|
-
}
|
|
372
|
-
return "UNKNOWN";
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
//#endregion
|
|
376
|
-
export { and, createContainerDimensionCondition, createContainerRawCondition, createContainerStyleCondition, createMediaDimensionCondition, createMediaFeatureCondition, createMediaTypeCondition, createModifierCondition, createOwnCondition, createPseudoCondition, createRootCondition, createStartingCondition, createSupportsCondition, falseCondition, getConditionUniqueId, isCompoundCondition, not, or, trueCondition };
|
|
377
|
-
//# sourceMappingURL=conditions.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conditions.mjs","names":[],"sources":["../../src/pipeline/conditions.ts"],"sourcesContent":["/**\n * ConditionNode Types and Helpers\n *\n * Core data structures for representing style conditions as an abstract syntax tree.\n * Used throughout the pipeline for parsing, simplification, and CSS generation.\n */\n\n// ============================================================================\n// Core ConditionNode Types\n// ============================================================================\n\n/**\n * Base interface for all state conditions (leaf nodes)\n */\ninterface BaseStateCondition {\n kind: 'state';\n negated: boolean;\n raw: string; // Original string for debugging/caching\n uniqueId: string; // Normalized ID for comparison (built from props)\n}\n\n/**\n * Modifier condition: [data-attr] or [data-attr=\"value\"]\n */\nexport interface ModifierCondition extends BaseStateCondition {\n type: 'modifier';\n attribute: string; // e.g., 'data-theme', 'data-size'\n value?: string; // e.g., 'danger', 'large' (undefined = boolean attr)\n operator?: '=' | '^=' | '$=' | '*='; // Attribute match operator\n}\n\n/**\n * Pseudo-class condition: :hover, :focus-visible\n */\nexport interface PseudoCondition extends BaseStateCondition {\n type: 'pseudo';\n pseudo: string; // e.g., ':hover', ':focus-visible', ':nth-child(2n)'\n}\n\n/**\n * Numeric bound for dimension queries\n */\nexport interface NumericBound {\n value: string; // e.g., '768px', 'calc(var(--gap) * 40)'\n valueNumeric: number | null; // Parsed numeric value for comparison\n inclusive: boolean; // true for >=/<= , false for >/<\n}\n\n/**\n * Media query condition\n */\nexport interface MediaCondition extends BaseStateCondition {\n type: 'media';\n subtype: 'dimension' | 'feature' | 'type';\n\n // For dimension queries: @media(w < 768px), @media(600px <= w < 1200px)\n dimension?: 'width' | 'height' | 'inline-size' | 'block-size';\n lowerBound?: NumericBound; // >= or >\n upperBound?: NumericBound; // <= or <\n\n // For feature queries: @media(prefers-contrast: high)\n feature?: string; // e.g., 'prefers-contrast', 'prefers-color-scheme'\n featureValue?: string; // e.g., 'high', 'dark' (undefined = boolean feature)\n\n // For type queries: @media:print\n mediaType?: 'print' | 'screen' | 'all' | 'speech';\n}\n\n/**\n * Container query condition\n */\nexport interface ContainerCondition extends BaseStateCondition {\n type: 'container';\n subtype: 'dimension' | 'style' | 'raw';\n containerName?: string; // e.g., 'layout', 'sidebar' (undefined = nearest)\n\n // For dimension queries: @(w < 600px), @(layout, w < 600px)\n dimension?: 'width' | 'height' | 'inline-size' | 'block-size';\n lowerBound?: NumericBound;\n upperBound?: NumericBound;\n\n // For style queries: @(layout, $variant=danger), @($theme)\n property?: string; // CSS custom property name (without --)\n propertyValue?: string; // e.g., 'danger' (undefined = existence check)\n\n // For raw function queries: @(scroll-state(stuck: top)), @(style(display: flex))\n rawCondition?: string; // Verbatim CSS condition string\n}\n\n/**\n * Root state condition: @root(theme=dark)\n */\nexport interface RootCondition extends BaseStateCondition {\n type: 'root';\n selector: string; // e.g., '[data-theme=\"dark\"]'\n}\n\n/**\n * Own state condition: @own(hovered)\n */\nexport interface OwnCondition extends BaseStateCondition {\n type: 'own';\n innerCondition: ConditionNode; // The parsed inner condition\n}\n\n/**\n * Starting style condition: @starting\n */\nexport interface StartingCondition extends BaseStateCondition {\n type: 'starting';\n}\n\n/**\n * Supports query condition: @supports(display: grid), @supports($, :has(*))\n */\nexport interface SupportsCondition extends BaseStateCondition {\n type: 'supports';\n subtype: 'feature' | 'selector';\n // The raw condition string (e.g., \"display: grid\" or \":has(*)\")\n condition: string;\n}\n\n/**\n * Union of all state condition types\n */\nexport type StateCondition =\n | ModifierCondition\n | PseudoCondition\n | MediaCondition\n | ContainerCondition\n | RootCondition\n | OwnCondition\n | StartingCondition\n | SupportsCondition;\n\n/**\n * Compound node: combines conditions with AND/OR\n */\nexport interface CompoundCondition {\n kind: 'compound';\n operator: 'AND' | 'OR';\n children: ConditionNode[];\n}\n\n/**\n * True condition (matches everything)\n */\nexport interface TrueCondition {\n kind: 'true';\n}\n\n/**\n * False condition (matches nothing - skip this rule)\n */\nexport interface FalseCondition {\n kind: 'false';\n}\n\n/**\n * Union of all condition node types\n */\nexport type ConditionNode =\n | StateCondition\n | CompoundCondition\n | TrueCondition\n | FalseCondition;\n\n// ============================================================================\n// Constructor Functions\n// ============================================================================\n\n/**\n * Create a TRUE condition (matches everything)\n */\nexport function trueCondition(): TrueCondition {\n return { kind: 'true' };\n}\n\n/**\n * Create a FALSE condition (matches nothing)\n */\nexport function falseCondition(): FalseCondition {\n return { kind: 'false' };\n}\n\n/**\n * Create an AND compound condition\n */\nexport function and(...children: ConditionNode[]): ConditionNode {\n const filtered: ConditionNode[] = [];\n\n for (const child of children) {\n // Short-circuit on FALSE\n if (child.kind === 'false') {\n return falseCondition();\n }\n // Skip TRUE (identity for AND)\n if (child.kind === 'true') {\n continue;\n }\n // Flatten nested ANDs\n if (child.kind === 'compound' && child.operator === 'AND') {\n filtered.push(...child.children);\n } else {\n filtered.push(child);\n }\n }\n\n if (filtered.length === 0) {\n return trueCondition();\n }\n if (filtered.length === 1) {\n return filtered[0];\n }\n\n return {\n kind: 'compound',\n operator: 'AND',\n children: filtered,\n };\n}\n\n/**\n * Create an OR compound condition\n */\nexport function or(...children: ConditionNode[]): ConditionNode {\n const filtered: ConditionNode[] = [];\n\n for (const child of children) {\n // Short-circuit on TRUE\n if (child.kind === 'true') {\n return trueCondition();\n }\n // Skip FALSE (identity for OR)\n if (child.kind === 'false') {\n continue;\n }\n // Flatten nested ORs\n if (child.kind === 'compound' && child.operator === 'OR') {\n filtered.push(...child.children);\n } else {\n filtered.push(child);\n }\n }\n\n if (filtered.length === 0) {\n return falseCondition();\n }\n if (filtered.length === 1) {\n return filtered[0];\n }\n\n return {\n kind: 'compound',\n operator: 'OR',\n children: filtered,\n };\n}\n\n/**\n * Negate a condition\n */\nexport function not(node: ConditionNode): ConditionNode {\n // NOT(TRUE) = FALSE\n if (node.kind === 'true') {\n return falseCondition();\n }\n\n // NOT(FALSE) = TRUE\n if (node.kind === 'false') {\n return trueCondition();\n }\n\n // NOT(state) = toggle negated flag\n if (node.kind === 'state') {\n return {\n ...node,\n negated: !node.negated,\n uniqueId: node.negated\n ? node.uniqueId.replace(/^!/, '')\n : `!${node.uniqueId}`,\n };\n }\n\n // NOT(AND(a, b, ...)) = OR(NOT(a), NOT(b), ...) - De Morgan's law\n if (node.kind === 'compound' && node.operator === 'AND') {\n return or(...node.children.map((c) => not(c)));\n }\n\n // NOT(OR(a, b, ...)) = AND(NOT(a), NOT(b), ...) - De Morgan's law\n if (node.kind === 'compound' && node.operator === 'OR') {\n return and(...node.children.map((c) => not(c)));\n }\n\n // Fallback - should not reach here\n return node;\n}\n\n// ============================================================================\n// Condition Type Checking\n// ============================================================================\n\n/**\n * Check if a condition is a compound condition\n */\nexport function isCompoundCondition(\n node: ConditionNode,\n): node is CompoundCondition {\n return node.kind === 'compound';\n}\n\n// ============================================================================\n// UniqueId Generation\n// ============================================================================\n\n/**\n * Generate a normalized unique ID for a modifier condition\n */\nexport function modifierUniqueId(\n attribute: string,\n value?: string,\n operator = '=',\n negated = false,\n): string {\n const base = value\n ? `mod:${attribute}${operator}${value}`\n : `mod:${attribute}`;\n return negated ? `!${base}` : base;\n}\n\n/**\n * Generate a normalized unique ID for a pseudo condition\n */\nexport function pseudoUniqueId(\n pseudo: string,\n negated = false,\n): string {\n const base = `pseudo:${pseudo}`;\n return negated ? `!${base}` : base;\n}\n\n/**\n * Generate a normalized unique ID for a media condition\n */\nexport function mediaUniqueId(\n subtype: 'dimension' | 'feature' | 'type',\n props: {\n dimension?: string;\n lowerBound?: NumericBound;\n upperBound?: NumericBound;\n feature?: string;\n featureValue?: string;\n mediaType?: string;\n },\n negated = false,\n): string {\n let base: string;\n\n if (subtype === 'dimension') {\n const parts = ['media', 'dim', props.dimension];\n if (props.lowerBound) {\n parts.push(props.lowerBound.inclusive ? '>=' : '>');\n parts.push(props.lowerBound.value);\n }\n if (props.upperBound) {\n parts.push(props.upperBound.inclusive ? '<=' : '<');\n parts.push(props.upperBound.value);\n }\n base = parts.join(':');\n } else if (subtype === 'feature') {\n base = props.featureValue\n ? `media:feat:${props.feature}:${props.featureValue}`\n : `media:feat:${props.feature}`;\n } else {\n base = `media:type:${props.mediaType}`;\n }\n\n return negated ? `!${base}` : base;\n}\n\n/**\n * Generate a normalized unique ID for a container condition\n */\nexport function containerUniqueId(\n subtype: 'dimension' | 'style' | 'raw',\n props: {\n containerName?: string;\n dimension?: string;\n lowerBound?: NumericBound;\n upperBound?: NumericBound;\n property?: string;\n propertyValue?: string;\n rawCondition?: string;\n },\n negated = false,\n): string {\n let base: string;\n const name = props.containerName || '_';\n\n if (subtype === 'dimension') {\n const parts = ['container', 'dim', name, props.dimension];\n if (props.lowerBound) {\n parts.push(props.lowerBound.inclusive ? '>=' : '>');\n parts.push(props.lowerBound.value);\n }\n if (props.upperBound) {\n parts.push(props.upperBound.inclusive ? '<=' : '<');\n parts.push(props.upperBound.value);\n }\n base = parts.join(':');\n } else if (subtype === 'raw') {\n base = `container:raw:${name}:${props.rawCondition}`;\n } else {\n base = props.propertyValue\n ? `container:style:${name}:--${props.property}:${props.propertyValue}`\n : `container:style:${name}:--${props.property}`;\n }\n\n return negated ? `!${base}` : base;\n}\n\n/**\n * Generate a normalized unique ID for a root condition\n */\nexport function rootUniqueId(\n selector: string,\n negated = false,\n): string {\n const base = `root:${selector}`;\n return negated ? `!${base}` : base;\n}\n\n/**\n * Generate a normalized unique ID for an own condition\n */\nexport function ownUniqueId(\n innerUniqueId: string,\n negated = false,\n): string {\n const base = `own:${innerUniqueId}`;\n return negated ? `!${base}` : base;\n}\n\n/**\n * Generate a normalized unique ID for a starting condition\n */\nexport function startingUniqueId(negated = false): string {\n return negated ? '!starting' : 'starting';\n}\n\n/**\n * Generate a normalized unique ID for a supports condition\n */\nexport function supportsUniqueId(\n subtype: 'feature' | 'selector',\n condition: string,\n negated = false,\n): string {\n const base = `supports:${subtype}:${condition}`;\n return negated ? `!${base}` : base;\n}\n\n// ============================================================================\n// Condition Creation Helpers\n// ============================================================================\n\n/**\n * Create a modifier condition\n */\nexport function createModifierCondition(\n attribute: string,\n value?: string,\n operator: '=' | '^=' | '$=' | '*=' = '=',\n negated = false,\n raw?: string,\n): ModifierCondition {\n return {\n kind: 'state',\n type: 'modifier',\n negated,\n raw: raw || (value ? `${attribute}${operator}${value}` : attribute),\n uniqueId: modifierUniqueId(attribute, value, operator, negated),\n attribute,\n value,\n operator: value ? operator : undefined,\n };\n}\n\n/**\n * Create a pseudo condition\n */\nexport function createPseudoCondition(\n pseudo: string,\n negated = false,\n raw?: string,\n): PseudoCondition {\n return {\n kind: 'state',\n type: 'pseudo',\n negated,\n raw: raw || pseudo,\n uniqueId: pseudoUniqueId(pseudo, negated),\n pseudo,\n };\n}\n\n/**\n * Create a media dimension condition\n */\nexport function createMediaDimensionCondition(\n dimension: 'width' | 'height' | 'inline-size' | 'block-size',\n lowerBound?: NumericBound,\n upperBound?: NumericBound,\n negated = false,\n raw?: string,\n): MediaCondition {\n return {\n kind: 'state',\n type: 'media',\n subtype: 'dimension',\n negated,\n raw: raw || `@media(${dimension})`,\n uniqueId: mediaUniqueId(\n 'dimension',\n { dimension, lowerBound, upperBound },\n negated,\n ),\n dimension,\n lowerBound,\n upperBound,\n };\n}\n\n/**\n * Create a media feature condition\n */\nexport function createMediaFeatureCondition(\n feature: string,\n featureValue?: string,\n negated = false,\n raw?: string,\n): MediaCondition {\n return {\n kind: 'state',\n type: 'media',\n subtype: 'feature',\n negated,\n raw: raw || `@media(${feature}${featureValue ? `: ${featureValue}` : ''})`,\n uniqueId: mediaUniqueId('feature', { feature, featureValue }, negated),\n feature,\n featureValue,\n };\n}\n\n/**\n * Create a media type condition\n */\nexport function createMediaTypeCondition(\n mediaType: 'print' | 'screen' | 'all' | 'speech',\n negated = false,\n raw?: string,\n): MediaCondition {\n return {\n kind: 'state',\n type: 'media',\n subtype: 'type',\n negated,\n raw: raw || `@media:${mediaType}`,\n uniqueId: mediaUniqueId('type', { mediaType }, negated),\n mediaType,\n };\n}\n\n/**\n * Create a container dimension condition\n */\nexport function createContainerDimensionCondition(\n dimension: 'width' | 'height' | 'inline-size' | 'block-size',\n lowerBound?: NumericBound,\n upperBound?: NumericBound,\n containerName?: string,\n negated = false,\n raw?: string,\n): ContainerCondition {\n return {\n kind: 'state',\n type: 'container',\n subtype: 'dimension',\n negated,\n raw: raw || `@(${containerName ? containerName + ', ' : ''}${dimension})`,\n uniqueId: containerUniqueId(\n 'dimension',\n { containerName, dimension, lowerBound, upperBound },\n negated,\n ),\n containerName,\n dimension,\n lowerBound,\n upperBound,\n };\n}\n\n/**\n * Create a container style condition\n */\nexport function createContainerStyleCondition(\n property: string,\n propertyValue?: string,\n containerName?: string,\n negated = false,\n raw?: string,\n): ContainerCondition {\n return {\n kind: 'state',\n type: 'container',\n subtype: 'style',\n negated,\n raw:\n raw ||\n `@(${containerName ? containerName + ', ' : ''}$${property}${propertyValue ? '=' + propertyValue : ''})`,\n uniqueId: containerUniqueId(\n 'style',\n { containerName, property, propertyValue },\n negated,\n ),\n containerName,\n property,\n propertyValue,\n };\n}\n\n/**\n * Create a container raw function condition (e.g., scroll-state(), style(), etc.)\n * The condition string is passed through to CSS verbatim.\n */\nexport function createContainerRawCondition(\n rawCondition: string,\n containerName?: string,\n negated = false,\n raw?: string,\n): ContainerCondition {\n return {\n kind: 'state',\n type: 'container',\n subtype: 'raw',\n negated,\n raw:\n raw || `@(${containerName ? containerName + ', ' : ''}${rawCondition})`,\n uniqueId: containerUniqueId(\n 'raw',\n { containerName, rawCondition },\n negated,\n ),\n containerName,\n rawCondition,\n };\n}\n\n/**\n * Create a root condition\n */\nexport function createRootCondition(\n selector: string,\n negated = false,\n raw?: string,\n): RootCondition {\n return {\n kind: 'state',\n type: 'root',\n negated,\n raw: raw || `@root(${selector})`,\n uniqueId: rootUniqueId(selector, negated),\n selector,\n };\n}\n\n/**\n * Create an own condition\n */\nexport function createOwnCondition(\n innerCondition: ConditionNode,\n negated = false,\n raw?: string,\n): OwnCondition {\n const innerUniqueId = getConditionUniqueId(innerCondition);\n return {\n kind: 'state',\n type: 'own',\n negated,\n raw: raw || `@own(...)`,\n uniqueId: ownUniqueId(innerUniqueId, negated),\n innerCondition,\n };\n}\n\n/**\n * Create a starting condition\n */\nexport function createStartingCondition(\n negated = false,\n raw?: string,\n): StartingCondition {\n return {\n kind: 'state',\n type: 'starting',\n negated,\n raw: raw || '@starting',\n uniqueId: startingUniqueId(negated),\n };\n}\n\n/**\n * Create a supports condition\n *\n * @param subtype 'feature' for @supports(display: grid), 'selector' for @supports($, :has(*))\n * @param condition The condition string (e.g., \"display: grid\" or \":has(*)\")\n */\nexport function createSupportsCondition(\n subtype: 'feature' | 'selector',\n condition: string,\n negated = false,\n raw?: string,\n): SupportsCondition {\n return {\n kind: 'state',\n type: 'supports',\n subtype,\n negated,\n raw: raw || `@supports(${condition})`,\n uniqueId: supportsUniqueId(subtype, condition, negated),\n condition,\n };\n}\n\n// ============================================================================\n// Utility Functions\n// ============================================================================\n\n/**\n * Get the unique ID for any condition node\n */\nexport function getConditionUniqueId(node: ConditionNode): string {\n if (node.kind === 'true') {\n return 'TRUE';\n }\n if (node.kind === 'false') {\n return 'FALSE';\n }\n if (node.kind === 'state') {\n return node.uniqueId;\n }\n if (node.kind === 'compound') {\n const childIds = node.children.map(getConditionUniqueId).sort();\n return `${node.operator}(${childIds.join(',')})`;\n }\n return 'UNKNOWN';\n}\n"],"mappings":";;;;AA8KA,SAAgB,gBAA+B;AAC7C,QAAO,EAAE,MAAM,QAAQ;;;;;AAMzB,SAAgB,iBAAiC;AAC/C,QAAO,EAAE,MAAM,SAAS;;;;;AAM1B,SAAgB,IAAI,GAAG,UAA0C;CAC/D,MAAM,WAA4B,EAAE;AAEpC,MAAK,MAAM,SAAS,UAAU;AAE5B,MAAI,MAAM,SAAS,QACjB,QAAO,gBAAgB;AAGzB,MAAI,MAAM,SAAS,OACjB;AAGF,MAAI,MAAM,SAAS,cAAc,MAAM,aAAa,MAClD,UAAS,KAAK,GAAG,MAAM,SAAS;MAEhC,UAAS,KAAK,MAAM;;AAIxB,KAAI,SAAS,WAAW,EACtB,QAAO,eAAe;AAExB,KAAI,SA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,MAAM;EACN,MAAM;EACN;EACA,KAAK,OAAO;EACZ,UAAU,iBAAiB,QAAQ;EACpC;;;;;;;;AASH,SAAgB,wBACd,SACA,WACA,UAAU,OACV,KACmB;AACnB,QAAO;EACL,MAAM;EACN,MAAM;EACN;EACA;EACA,KAAK,OAAO,aAAa,UAAU;EACnC,UAAU,iBAAiB,SAAS,WAAW,QAAQ;EACvD;EACD;;;;;AAUH,SAAgB,qBAAqB,MAA6B;AAChE,KAAI,KAAK,SAAS,OAChB,QAAO;AAET,KAAI,KAAK,SAAS,QAChB,QAAO;AAET,KAAI,KAAK,SAAS,QAChB,QAAO,KAAK;AAEd,KAAI,KAAK,SAAS,YAAY;EAC5B,MAAM,WAAW,KAAK,SAAS,IAAI,qBAAqB,CAAC,MAAM;AAC/D,SAAO,GAAG,KAAK,SAAS,GAAG,SAAS,KAAK,IAAI,CAAC;;AAEhD,QAAO"}
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import { and, isCompoundCondition, not, trueCondition } from "./conditions.mjs";
|
|
2
|
-
import { simplifyCondition } from "./simplify.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/pipeline/exclusive.ts
|
|
5
|
-
/**
|
|
6
|
-
* Build exclusive conditions for a list of parsed style entries.
|
|
7
|
-
*
|
|
8
|
-
* The entries should be ordered by priority (highest priority first).
|
|
9
|
-
*
|
|
10
|
-
* For each entry, we compute:
|
|
11
|
-
* exclusiveCondition = condition & !prior[0] & !prior[1] & ...
|
|
12
|
-
*
|
|
13
|
-
* This ensures exactly one condition matches at any time.
|
|
14
|
-
*
|
|
15
|
-
* Example:
|
|
16
|
-
* Input (ordered highest to lowest priority):
|
|
17
|
-
* A: value1 (priority 2)
|
|
18
|
-
* B: value2 (priority 1)
|
|
19
|
-
* C: value3 (priority 0)
|
|
20
|
-
*
|
|
21
|
-
* Output:
|
|
22
|
-
* A: A
|
|
23
|
-
* B: B & !A
|
|
24
|
-
* C: C & !A & !B
|
|
25
|
-
*
|
|
26
|
-
* @param entries Parsed style entries ordered by priority (highest first)
|
|
27
|
-
* @returns Entries with exclusive conditions, filtered to remove impossible ones
|
|
28
|
-
*/
|
|
29
|
-
function buildExclusiveConditions(entries) {
|
|
30
|
-
const result = [];
|
|
31
|
-
const priorConditions = [];
|
|
32
|
-
for (const entry of entries) {
|
|
33
|
-
let exclusive = entry.condition;
|
|
34
|
-
for (const prior of priorConditions) if (prior.kind !== "true") exclusive = and(exclusive, not(prior));
|
|
35
|
-
const simplified = simplifyCondition(exclusive);
|
|
36
|
-
if (simplified.kind === "false") continue;
|
|
37
|
-
result.push({
|
|
38
|
-
...entry,
|
|
39
|
-
exclusiveCondition: simplified
|
|
40
|
-
});
|
|
41
|
-
if (entry.condition.kind !== "true") priorConditions.push(entry.condition);
|
|
42
|
-
}
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Parse style entries from a value mapping object.
|
|
47
|
-
*
|
|
48
|
-
* @param styleKey The style key (e.g., 'padding')
|
|
49
|
-
* @param valueMap The value mapping { '': '2x', 'compact': '1x', '@media(w < 768px)': '0.5x' }
|
|
50
|
-
* @param parseCondition Function to parse state keys into conditions
|
|
51
|
-
* @returns Parsed entries ordered by priority (highest first)
|
|
52
|
-
*/
|
|
53
|
-
function parseStyleEntries(styleKey, valueMap, parseCondition) {
|
|
54
|
-
const entries = [];
|
|
55
|
-
Object.keys(valueMap).forEach((stateKey, index) => {
|
|
56
|
-
const value = valueMap[stateKey];
|
|
57
|
-
const condition = stateKey === "" ? trueCondition() : parseCondition(stateKey);
|
|
58
|
-
entries.push({
|
|
59
|
-
styleKey,
|
|
60
|
-
stateKey,
|
|
61
|
-
value,
|
|
62
|
-
condition,
|
|
63
|
-
priority: index
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
entries.reverse();
|
|
67
|
-
return entries;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Check if a value is a style value mapping (object with state keys)
|
|
71
|
-
*/
|
|
72
|
-
function isValueMapping(value) {
|
|
73
|
-
return value !== null && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Expand OR conditions in parsed entries into multiple exclusive entries.
|
|
77
|
-
*
|
|
78
|
-
* For an entry with condition `A | B | C`, this creates 3 entries:
|
|
79
|
-
* - condition: A
|
|
80
|
-
* - condition: B & !A
|
|
81
|
-
* - condition: C & !A & !B
|
|
82
|
-
*
|
|
83
|
-
* This ensures OR branches are mutually exclusive BEFORE the main
|
|
84
|
-
* exclusive condition building pass.
|
|
85
|
-
*
|
|
86
|
-
* @param entries Parsed entries (may contain OR conditions)
|
|
87
|
-
* @returns Expanded entries with OR branches made exclusive
|
|
88
|
-
*/
|
|
89
|
-
function expandOrConditions(entries) {
|
|
90
|
-
const result = [];
|
|
91
|
-
for (const entry of entries) {
|
|
92
|
-
const expanded = expandSingleEntry(entry);
|
|
93
|
-
result.push(...expanded);
|
|
94
|
-
}
|
|
95
|
-
return result;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Expand a single entry's OR condition into multiple exclusive entries
|
|
99
|
-
*/
|
|
100
|
-
function expandSingleEntry(entry) {
|
|
101
|
-
const orBranches = collectOrBranches(entry.condition);
|
|
102
|
-
if (orBranches.length <= 1) return [entry];
|
|
103
|
-
const result = [];
|
|
104
|
-
const priorBranches = [];
|
|
105
|
-
for (let i = 0; i < orBranches.length; i++) {
|
|
106
|
-
const branch = orBranches[i];
|
|
107
|
-
let exclusiveBranch = branch;
|
|
108
|
-
for (const prior of priorBranches) exclusiveBranch = and(exclusiveBranch, not(prior));
|
|
109
|
-
const simplified = simplifyCondition(exclusiveBranch);
|
|
110
|
-
if (simplified.kind === "false") {
|
|
111
|
-
priorBranches.push(branch);
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
result.push({
|
|
115
|
-
...entry,
|
|
116
|
-
stateKey: `${entry.stateKey}[${i}]`,
|
|
117
|
-
condition: simplified
|
|
118
|
-
});
|
|
119
|
-
priorBranches.push(branch);
|
|
120
|
-
}
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Collect top-level OR branches from a condition.
|
|
125
|
-
*
|
|
126
|
-
* For `A | B | C`, returns [A, B, C]
|
|
127
|
-
* For `A & B`, returns [A & B] (single branch)
|
|
128
|
-
* For `A | (B & C)`, returns [A, B & C]
|
|
129
|
-
*/
|
|
130
|
-
function collectOrBranches(condition) {
|
|
131
|
-
if (condition.kind === "true" || condition.kind === "false") return [condition];
|
|
132
|
-
if (isCompoundCondition(condition) && condition.operator === "OR") {
|
|
133
|
-
const branches = [];
|
|
134
|
-
for (const child of condition.children) branches.push(...collectOrBranches(child));
|
|
135
|
-
return branches;
|
|
136
|
-
}
|
|
137
|
-
return [condition];
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Expand OR conditions in exclusive entries AFTER buildExclusiveConditions.
|
|
141
|
-
*
|
|
142
|
-
* This handles ORs that arise from De Morgan expansion during negation:
|
|
143
|
-
* !(A & B) = !A | !B
|
|
144
|
-
*
|
|
145
|
-
* These ORs need to be made exclusive to avoid overlapping CSS rules:
|
|
146
|
-
* !A | !B → !A | (A & !B)
|
|
147
|
-
*
|
|
148
|
-
* This is logically equivalent but ensures each branch has proper context.
|
|
149
|
-
*
|
|
150
|
-
* Example:
|
|
151
|
-
* Input: { "": V1, "@supports(...) & :has()": V2 }
|
|
152
|
-
* V2's exclusive = @supports & :has
|
|
153
|
-
* V1's exclusive = !(@supports & :has) = !@supports | !:has
|
|
154
|
-
*
|
|
155
|
-
* Without this fix: V1 gets two rules:
|
|
156
|
-
* - @supports (not ...) → V1 ✓
|
|
157
|
-
* - :not(:has()) → V1 ✗ (missing @supports context!)
|
|
158
|
-
*
|
|
159
|
-
* With this fix: V1 gets two exclusive rules:
|
|
160
|
-
* - @supports (not ...) → V1 ✓
|
|
161
|
-
* - @supports (...) { :not(:has()) } → V1 ✓ (proper context!)
|
|
162
|
-
*/
|
|
163
|
-
function expandExclusiveOrs(entries) {
|
|
164
|
-
const result = [];
|
|
165
|
-
for (const entry of entries) {
|
|
166
|
-
const expanded = expandExclusiveConditionOrs(entry);
|
|
167
|
-
result.push(...expanded);
|
|
168
|
-
}
|
|
169
|
-
return result;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Check if a condition involves at-rules (media, container, supports, starting)
|
|
173
|
-
*/
|
|
174
|
-
function hasAtRuleContext(node) {
|
|
175
|
-
if (node.kind === "true" || node.kind === "false") return false;
|
|
176
|
-
if (node.kind === "state") return node.type === "media" || node.type === "container" || node.type === "supports" || node.type === "starting";
|
|
177
|
-
if (node.kind === "compound") return node.children.some(hasAtRuleContext);
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Sort OR branches to prioritize at-rule conditions first.
|
|
182
|
-
*
|
|
183
|
-
* This is critical for correct CSS generation. For `!A | !B` where A is at-rule
|
|
184
|
-
* and B is modifier, we want:
|
|
185
|
-
* - Branch 0: !A (at-rule negation - covers "no @supports/media" case)
|
|
186
|
-
* - Branch 1: A & !B (modifier negation with at-rule context)
|
|
187
|
-
*
|
|
188
|
-
* If we process in wrong order (!B first), we'd get:
|
|
189
|
-
* - Branch 0: !B (modifier negation WITHOUT at-rule context - WRONG!)
|
|
190
|
-
* - Branch 1: B & !A (at-rule negation with modifier - incomplete coverage)
|
|
191
|
-
*/
|
|
192
|
-
function sortOrBranchesForExpansion(branches) {
|
|
193
|
-
return [...branches].sort((a, b) => {
|
|
194
|
-
const aHasAtRule = hasAtRuleContext(a);
|
|
195
|
-
const bHasAtRule = hasAtRuleContext(b);
|
|
196
|
-
if (aHasAtRule && !bHasAtRule) return -1;
|
|
197
|
-
if (!aHasAtRule && bHasAtRule) return 1;
|
|
198
|
-
return 0;
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Expand ORs in a single entry's exclusive condition
|
|
203
|
-
*/
|
|
204
|
-
function expandExclusiveConditionOrs(entry) {
|
|
205
|
-
let orBranches = collectOrBranches(entry.exclusiveCondition);
|
|
206
|
-
if (orBranches.length <= 1) return [entry];
|
|
207
|
-
orBranches = sortOrBranchesForExpansion(orBranches);
|
|
208
|
-
const result = [];
|
|
209
|
-
const priorBranches = [];
|
|
210
|
-
for (let i = 0; i < orBranches.length; i++) {
|
|
211
|
-
const branch = orBranches[i];
|
|
212
|
-
let exclusiveBranch = branch;
|
|
213
|
-
for (const prior of priorBranches) exclusiveBranch = and(exclusiveBranch, not(prior));
|
|
214
|
-
const simplified = simplifyCondition(exclusiveBranch);
|
|
215
|
-
if (simplified.kind === "false") {
|
|
216
|
-
priorBranches.push(branch);
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
result.push({
|
|
220
|
-
...entry,
|
|
221
|
-
stateKey: `${entry.stateKey}[or:${i}]`,
|
|
222
|
-
exclusiveCondition: simplified
|
|
223
|
-
});
|
|
224
|
-
priorBranches.push(branch);
|
|
225
|
-
}
|
|
226
|
-
return result;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
//#endregion
|
|
230
|
-
export { buildExclusiveConditions, expandExclusiveOrs, expandOrConditions, isValueMapping, parseStyleEntries };
|
|
231
|
-
//# sourceMappingURL=exclusive.mjs.map
|