@tenphi/tasty 0.0.0-snapshot.26b4630 → 0.0.0-snapshot.2705ab9
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/README.md +315 -159
- package/dist/chunks/cacheKey.js +16 -8
- package/dist/chunks/cacheKey.js.map +1 -1
- package/dist/chunks/definitions.d.ts +1 -1
- package/dist/chunks/definitions.js +2 -3
- package/dist/chunks/definitions.js.map +1 -1
- package/dist/chunks/renderChunk.js +31 -32
- package/dist/chunks/renderChunk.js.map +1 -1
- package/dist/config.d.ts +98 -12
- package/dist/config.js +134 -33
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +11 -10
- package/dist/core/index.js +8 -7
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/debug.d.ts +26 -141
- package/dist/debug.js +356 -635
- package/dist/debug.js.map +1 -1
- package/dist/font-face/index.js +63 -0
- package/dist/font-face/index.js.map +1 -0
- package/dist/hooks/resolve-ssr-collector.js +15 -0
- package/dist/hooks/resolve-ssr-collector.js.map +1 -0
- package/dist/hooks/useCounterStyle.d.ts +50 -0
- package/dist/hooks/useCounterStyle.js +47 -0
- package/dist/hooks/useCounterStyle.js.map +1 -0
- package/dist/hooks/useFontFace.d.ts +43 -0
- package/dist/hooks/useFontFace.js +71 -0
- package/dist/hooks/useFontFace.js.map +1 -0
- package/dist/hooks/useGlobalStyles.d.ts +3 -0
- package/dist/hooks/useGlobalStyles.js +24 -1
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.js +14 -3
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.js +32 -13
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.js +9 -1
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.d.ts +5 -0
- package/dist/hooks/useStyles.js +115 -46
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +22 -11
- package/dist/index.js +10 -7
- package/dist/injector/index.d.ts +28 -2
- package/dist/injector/index.js +27 -1
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +28 -1
- package/dist/injector/injector.js +93 -32
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +16 -7
- package/dist/injector/sheet-manager.js +31 -11
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +70 -1
- package/dist/parser/classify.js +5 -4
- package/dist/parser/classify.js.map +1 -1
- package/dist/parser/const.js +17 -1
- package/dist/parser/const.js.map +1 -1
- package/dist/parser/parser.js +1 -1
- package/dist/pipeline/conditions.js +14 -8
- package/dist/pipeline/conditions.js.map +1 -1
- package/dist/pipeline/index.d.ts +3 -1
- package/dist/pipeline/index.js +137 -69
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize.js +404 -208
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.d.ts +1 -1
- package/dist/pipeline/parseStateKey.js +37 -20
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js +111 -152
- package/dist/pipeline/simplify.js.map +1 -1
- package/dist/pipeline/warnings.js +18 -0
- package/dist/pipeline/warnings.js.map +1 -0
- package/dist/plugins/okhsl-plugin.js +2 -275
- package/dist/plugins/okhsl-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +9 -2
- package/dist/properties/index.js +82 -17
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/property-type-resolver.d.ts +24 -0
- package/dist/properties/property-type-resolver.js +91 -0
- package/dist/properties/property-type-resolver.js.map +1 -0
- package/dist/ssr/astro.d.ts +29 -0
- package/dist/ssr/astro.js +65 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/async-storage.d.ts +17 -0
- package/dist/ssr/async-storage.js +35 -0
- package/dist/ssr/async-storage.js.map +1 -0
- package/dist/ssr/collect-auto-properties.js +40 -0
- package/dist/ssr/collect-auto-properties.js.map +1 -0
- package/dist/ssr/collector.d.ts +102 -0
- package/dist/ssr/collector.js +227 -0
- package/dist/ssr/collector.js.map +1 -0
- package/dist/ssr/context.d.ts +8 -0
- package/dist/ssr/context.js +14 -0
- package/dist/ssr/context.js.map +1 -0
- package/dist/ssr/format-global-rules.js +22 -0
- package/dist/ssr/format-global-rules.js.map +1 -0
- package/dist/ssr/format-keyframes.js +70 -0
- package/dist/ssr/format-keyframes.js.map +1 -0
- package/dist/ssr/format-property.js +50 -0
- package/dist/ssr/format-property.js.map +1 -0
- package/dist/ssr/format-rules.js +73 -0
- package/dist/ssr/format-rules.js.map +1 -0
- package/dist/ssr/hydrate.d.ts +22 -0
- package/dist/ssr/hydrate.js +50 -0
- package/dist/ssr/hydrate.js.map +1 -0
- package/dist/ssr/index.d.ts +5 -0
- package/dist/ssr/index.js +12 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next.d.ts +45 -0
- package/dist/ssr/next.js +71 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/ssr/ssr-collector-ref.js +12 -0
- package/dist/ssr/ssr-collector-ref.js.map +1 -0
- package/dist/states/index.js +12 -257
- package/dist/states/index.js.map +1 -1
- package/dist/styles/align.d.ts +1 -1
- package/dist/styles/align.js.map +1 -1
- package/dist/styles/border.d.ts +1 -1
- package/dist/styles/border.js +2 -2
- package/dist/styles/border.js.map +1 -1
- package/dist/styles/color.d.ts +2 -2
- package/dist/styles/color.js +9 -5
- package/dist/styles/color.js.map +1 -1
- package/dist/styles/createStyle.js +25 -22
- package/dist/styles/createStyle.js.map +1 -1
- package/dist/styles/fade.d.ts +1 -1
- package/dist/styles/fade.js.map +1 -1
- package/dist/styles/fill.d.ts +14 -16
- package/dist/styles/fill.js +6 -5
- package/dist/styles/fill.js.map +1 -1
- package/dist/styles/flow.d.ts +3 -3
- package/dist/styles/flow.js.map +1 -1
- package/dist/styles/index.js +1 -1
- package/dist/styles/justify.d.ts +1 -1
- package/dist/styles/justify.js.map +1 -1
- package/dist/styles/predefined.d.ts +0 -2
- package/dist/styles/predefined.js +1 -4
- package/dist/styles/predefined.js.map +1 -1
- package/dist/styles/preset.d.ts +5 -0
- package/dist/styles/preset.js +48 -47
- package/dist/styles/preset.js.map +1 -1
- package/dist/styles/radius.d.ts +1 -1
- package/dist/styles/radius.js.map +1 -1
- package/dist/styles/scrollbar.d.ts +9 -5
- package/dist/styles/scrollbar.js +25 -82
- package/dist/styles/scrollbar.js.map +1 -1
- package/dist/styles/shadow.d.ts +2 -2
- package/dist/styles/shadow.js.map +1 -1
- package/dist/styles/transition.d.ts +1 -1
- package/dist/styles/transition.js +1 -1
- package/dist/styles/transition.js.map +1 -1
- package/dist/styles/types.d.ts +70 -21
- package/dist/tasty.d.ts +30 -893
- package/dist/tasty.js +60 -19
- package/dist/tasty.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/utils/cache-wrapper.js +4 -8
- package/dist/utils/cache-wrapper.js.map +1 -1
- package/dist/utils/color-math.d.ts +46 -0
- package/dist/utils/color-math.js +749 -0
- package/dist/utils/color-math.js.map +1 -0
- package/dist/utils/color-space.d.ts +5 -0
- package/dist/utils/color-space.js +229 -0
- package/dist/utils/color-space.js.map +1 -0
- package/dist/utils/colors.d.ts +1 -1
- package/dist/utils/colors.js +3 -1
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/css-types.d.ts +1 -1
- package/dist/utils/dotize.d.ts +1 -1
- package/dist/utils/has-keys.js +13 -0
- package/dist/utils/has-keys.js.map +1 -0
- package/dist/utils/mod-attrs.js +2 -2
- package/dist/utils/mod-attrs.js.map +1 -1
- package/dist/utils/process-tokens.d.ts +3 -13
- package/dist/utils/process-tokens.js +18 -98
- package/dist/utils/process-tokens.js.map +1 -1
- package/dist/utils/selector-transform.js +32 -0
- package/dist/utils/selector-transform.js.map +1 -0
- package/dist/utils/string.js.map +1 -1
- package/dist/utils/styles.d.ts +4 -88
- package/dist/utils/styles.js +34 -398
- package/dist/utils/styles.js.map +1 -1
- package/dist/utils/typography.d.ts +24 -13
- package/dist/utils/typography.js +14 -16
- package/dist/utils/typography.js.map +1 -1
- package/dist/zero/babel.d.ts +67 -8
- package/dist/zero/babel.js +109 -17
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/extractor.js +118 -1
- package/dist/zero/extractor.js.map +1 -1
- package/dist/zero/next.d.ts +44 -30
- package/dist/zero/next.js +102 -38
- package/dist/zero/next.js.map +1 -1
- package/docs/PIPELINE.md +519 -0
- package/docs/README.md +31 -0
- package/docs/adoption.md +296 -0
- package/docs/comparison.md +420 -0
- package/docs/configuration.md +326 -0
- package/docs/debug.md +318 -0
- package/docs/design-system.md +424 -0
- package/docs/dsl.md +673 -0
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +528 -0
- package/docs/methodology.md +567 -0
- package/docs/runtime.md +485 -0
- package/docs/ssr.md +384 -0
- package/docs/styles.md +579 -0
- package/docs/tasty-static.md +433 -0
- package/package.json +98 -28
- package/dist/styles/styledScrollbar.d.ts +0 -47
- package/dist/styles/styledScrollbar.js +0 -38
- package/dist/styles/styledScrollbar.js.map +0 -1
- package/dist/tokens/typography.d.ts +0 -19
- package/dist/tokens/typography.js +0 -237
- package/dist/tokens/typography.js.map +0 -1
- package/dist/utils/hsl-to-rgb.js +0 -38
- package/dist/utils/hsl-to-rgb.js.map +0 -1
- package/dist/utils/okhsl-to-rgb.js +0 -296
- package/dist/utils/okhsl-to-rgb.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Lru } from "../parser/lru.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getConditionUniqueId } from "./conditions.js";
|
|
3
3
|
|
|
4
4
|
//#region src/pipeline/materialize.ts
|
|
5
5
|
/**
|
|
@@ -13,25 +13,23 @@ const conditionCache = new Lru(3e3);
|
|
|
13
13
|
* Convert a condition tree to CSS components
|
|
14
14
|
*/
|
|
15
15
|
function conditionToCSS(node) {
|
|
16
|
-
const key =
|
|
16
|
+
const key = getConditionUniqueId(node);
|
|
17
17
|
const cached = conditionCache.get(key);
|
|
18
18
|
if (cached) return cached;
|
|
19
19
|
const result = conditionToCSSInner(node);
|
|
20
20
|
conditionCache.set(key, result);
|
|
21
21
|
return result;
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Create an empty selector variant
|
|
25
|
-
*/
|
|
26
23
|
function emptyVariant() {
|
|
27
24
|
return {
|
|
28
25
|
modifierConditions: [],
|
|
29
26
|
pseudoConditions: [],
|
|
30
|
-
|
|
27
|
+
selectorGroups: [],
|
|
28
|
+
ownGroups: [],
|
|
31
29
|
mediaConditions: [],
|
|
32
30
|
containerConditions: [],
|
|
33
31
|
supportsConditions: [],
|
|
34
|
-
|
|
32
|
+
rootGroups: [],
|
|
35
33
|
parentGroups: [],
|
|
36
34
|
startingStyle: false
|
|
37
35
|
};
|
|
@@ -66,9 +64,9 @@ function stateToCSS(state) {
|
|
|
66
64
|
}),
|
|
67
65
|
isImpossible: false
|
|
68
66
|
};
|
|
69
|
-
case "root": return innerConditionToVariants(state.innerCondition, state.negated ?? false, "
|
|
67
|
+
case "root": return innerConditionToVariants(state.innerCondition, state.negated ?? false, "rootGroups");
|
|
70
68
|
case "parent": return parentConditionToVariants(state.innerCondition, state.negated ?? false, state.direct);
|
|
71
|
-
case "own": return innerConditionToVariants(state.innerCondition, state.negated ?? false, "
|
|
69
|
+
case "own": return innerConditionToVariants(state.innerCondition, state.negated ?? false, "ownGroups");
|
|
72
70
|
case "modifier": {
|
|
73
71
|
const v = emptyVariant();
|
|
74
72
|
v.modifierConditions.push(modifierToParsed(state));
|
|
@@ -144,14 +142,31 @@ function pseudoToParsed(state) {
|
|
|
144
142
|
};
|
|
145
143
|
}
|
|
146
144
|
/**
|
|
147
|
-
* Convert parsed pseudo to CSS selector string (for final output)
|
|
145
|
+
* Convert parsed pseudo to CSS selector string (for final output).
|
|
146
|
+
*
|
|
147
|
+
* :not() is normalized to negated :is() at parse time, so pseudo.pseudo
|
|
148
|
+
* never starts with ':not(' here. When negated:
|
|
149
|
+
* - :is(X) → :not(X) (unwrap :is)
|
|
150
|
+
* - :where(X) → :not(X) (unwrap :where)
|
|
151
|
+
* - :has(X) → :not(:has(X))
|
|
152
|
+
* - other → :not(other)
|
|
153
|
+
*
|
|
154
|
+
* When not negated, single-argument :is()/:where() is unwrapped when the
|
|
155
|
+
* inner content is a simple compound selector that can safely append to
|
|
156
|
+
* the base selector (this happens after double-negation of :not()).
|
|
148
157
|
*/
|
|
149
158
|
function pseudoToCSS(pseudo) {
|
|
159
|
+
const p = pseudo.pseudo;
|
|
150
160
|
if (pseudo.negated) {
|
|
151
|
-
if (
|
|
152
|
-
return `:not(${
|
|
161
|
+
if (p.startsWith(":is(") || p.startsWith(":where(")) return `:not(${p.slice(p.indexOf("(") + 1, -1)})`;
|
|
162
|
+
return `:not(${p})`;
|
|
163
|
+
}
|
|
164
|
+
if ((p.startsWith(":is(") || p.startsWith(":where(")) && !p.includes(",")) {
|
|
165
|
+
const inner = p.slice(p.indexOf("(") + 1, -1);
|
|
166
|
+
const ch = inner[0];
|
|
167
|
+
if ((ch === ":" || ch === "." || ch === "[" || ch === "#") && !/\s/.test(inner)) return inner;
|
|
153
168
|
}
|
|
154
|
-
return
|
|
169
|
+
return p;
|
|
155
170
|
}
|
|
156
171
|
/**
|
|
157
172
|
* Convert media condition to parsed structure(s)
|
|
@@ -250,40 +265,50 @@ function collectSelectorConditions(variant) {
|
|
|
250
265
|
return [...variant.modifierConditions, ...variant.pseudoConditions];
|
|
251
266
|
}
|
|
252
267
|
/**
|
|
253
|
-
* Convert an inner condition tree into
|
|
254
|
-
*
|
|
268
|
+
* Convert an inner condition tree into a single SelectorVariant with
|
|
269
|
+
* one SelectorGroup whose branches represent the inner OR alternatives.
|
|
255
270
|
* Shared by @root() and @own().
|
|
271
|
+
*
|
|
272
|
+
* Both positive and negated cases produce one variant with one group.
|
|
273
|
+
* Negation simply sets the `negated` flag, which swaps :is() for :not()
|
|
274
|
+
* in the final CSS output — no De Morgan transformation is needed.
|
|
275
|
+
*
|
|
276
|
+
* This mirrors parentConditionToVariants: OR branches are kept inside
|
|
277
|
+
* a single group and rendered as comma-separated arguments in
|
|
278
|
+
* :is()/:not(), e.g. :root:is([a], [b]) or [el]:not([a], [b]).
|
|
256
279
|
*/
|
|
257
280
|
function innerConditionToVariants(innerCondition, negated, target) {
|
|
258
|
-
const innerCSS = conditionToCSS(
|
|
281
|
+
const innerCSS = conditionToCSS(innerCondition);
|
|
259
282
|
if (innerCSS.isImpossible || innerCSS.variants.length === 0) return {
|
|
260
283
|
variants: [],
|
|
261
284
|
isImpossible: true
|
|
262
285
|
};
|
|
263
|
-
const
|
|
286
|
+
const branches = [];
|
|
264
287
|
for (const innerVariant of innerCSS.variants) {
|
|
265
288
|
const conditions = collectSelectorConditions(innerVariant);
|
|
266
|
-
if (conditions.length > 0)
|
|
267
|
-
const v = emptyVariant();
|
|
268
|
-
v[target].push(...conditions);
|
|
269
|
-
variants.push(v);
|
|
270
|
-
}
|
|
289
|
+
if (conditions.length > 0) branches.push(conditions);
|
|
271
290
|
}
|
|
272
|
-
if (
|
|
291
|
+
if (branches.length === 0) return {
|
|
273
292
|
variants: [emptyVariant()],
|
|
274
293
|
isImpossible: false
|
|
275
294
|
};
|
|
295
|
+
const v = emptyVariant();
|
|
296
|
+
v[target].push({
|
|
297
|
+
branches,
|
|
298
|
+
negated
|
|
299
|
+
});
|
|
276
300
|
return {
|
|
277
|
-
variants,
|
|
301
|
+
variants: [v],
|
|
278
302
|
isImpossible: false
|
|
279
303
|
};
|
|
280
304
|
}
|
|
281
305
|
/**
|
|
282
|
-
* Convert a @parent() inner condition into
|
|
306
|
+
* Convert a @parent() inner condition into a single SelectorVariant with
|
|
307
|
+
* one ParentGroup whose branches represent the inner OR alternatives.
|
|
283
308
|
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
309
|
+
* Both positive and negated cases produce one variant with one group.
|
|
310
|
+
* Negation simply sets the `negated` flag, which swaps :is() for :not()
|
|
311
|
+
* in the final CSS output — no structural transformation is needed.
|
|
287
312
|
*/
|
|
288
313
|
function parentConditionToVariants(innerCondition, negated, direct) {
|
|
289
314
|
const innerCSS = conditionToCSS(innerCondition);
|
|
@@ -291,68 +316,178 @@ function parentConditionToVariants(innerCondition, negated, direct) {
|
|
|
291
316
|
variants: [],
|
|
292
317
|
isImpossible: true
|
|
293
318
|
};
|
|
294
|
-
|
|
295
|
-
const v = emptyVariant();
|
|
296
|
-
for (const innerVariant of innerCSS.variants) {
|
|
297
|
-
const conditions = collectSelectorConditions(innerVariant);
|
|
298
|
-
if (conditions.length > 0) v.parentGroups.push({
|
|
299
|
-
conditions,
|
|
300
|
-
direct,
|
|
301
|
-
negated: true
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
if (v.parentGroups.length === 0) return {
|
|
305
|
-
variants: [emptyVariant()],
|
|
306
|
-
isImpossible: false
|
|
307
|
-
};
|
|
308
|
-
return {
|
|
309
|
-
variants: [v],
|
|
310
|
-
isImpossible: false
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
const variants = [];
|
|
319
|
+
const branches = [];
|
|
314
320
|
for (const innerVariant of innerCSS.variants) {
|
|
315
321
|
const conditions = collectSelectorConditions(innerVariant);
|
|
316
|
-
if (conditions.length > 0)
|
|
317
|
-
const v = emptyVariant();
|
|
318
|
-
v.parentGroups.push({
|
|
319
|
-
conditions,
|
|
320
|
-
direct,
|
|
321
|
-
negated: false
|
|
322
|
-
});
|
|
323
|
-
variants.push(v);
|
|
324
|
-
}
|
|
322
|
+
if (conditions.length > 0) branches.push(conditions);
|
|
325
323
|
}
|
|
326
|
-
if (
|
|
324
|
+
if (branches.length === 0) return {
|
|
327
325
|
variants: [emptyVariant()],
|
|
328
326
|
isImpossible: false
|
|
329
327
|
};
|
|
328
|
+
const v = emptyVariant();
|
|
329
|
+
v.parentGroups.push({
|
|
330
|
+
branches,
|
|
331
|
+
direct,
|
|
332
|
+
negated
|
|
333
|
+
});
|
|
330
334
|
return {
|
|
331
|
-
variants,
|
|
335
|
+
variants: [v],
|
|
332
336
|
isImpossible: false
|
|
333
337
|
};
|
|
334
338
|
}
|
|
335
339
|
/**
|
|
336
|
-
*
|
|
340
|
+
* Sort key for canonical condition output within selectors.
|
|
341
|
+
*
|
|
342
|
+
* Priority order:
|
|
343
|
+
* 0: Boolean attribute selectors ([data-hovered])
|
|
344
|
+
* 1: Value attribute selectors ([data-size="small"])
|
|
345
|
+
* 2: Negated boolean attributes (:not([data-disabled]))
|
|
346
|
+
* 3: Negated value attributes (:not([data-size="small"]))
|
|
347
|
+
* 4: Pseudo-classes (:hover, :focus)
|
|
348
|
+
* 5: Negated pseudo-classes (:not(:disabled))
|
|
349
|
+
*
|
|
350
|
+
* Secondary sort: alphabetical by attribute name / pseudo string.
|
|
351
|
+
*/
|
|
352
|
+
function conditionSortKey(cond) {
|
|
353
|
+
if ("attribute" in cond) {
|
|
354
|
+
const hasValue = cond.value !== void 0 ? 1 : 0;
|
|
355
|
+
return `${(cond.negated ? 2 : 0) + hasValue}|${cond.attribute}|${cond.value ?? ""}`;
|
|
356
|
+
}
|
|
357
|
+
return `${cond.negated ? 5 : 4}|${cond.pseudo}`;
|
|
358
|
+
}
|
|
359
|
+
function sortConditions(conditions) {
|
|
360
|
+
return conditions.toSorted((a, b) => conditionSortKey(a).localeCompare(conditionSortKey(b)));
|
|
361
|
+
}
|
|
362
|
+
function branchToCSS(branch) {
|
|
363
|
+
let parts = "";
|
|
364
|
+
for (const cond of sortConditions(branch)) parts += selectorConditionToCSS(cond);
|
|
365
|
+
return parts;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Wrap serialized selector arguments in :is() or :not().
|
|
369
|
+
* Arguments are sorted for canonical output.
|
|
370
|
+
*/
|
|
371
|
+
function wrapInIsOrNot(args, negated) {
|
|
372
|
+
return `${negated ? ":not" : ":is"}(${args.sort().join(", ")})`;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Convert a selector group to a CSS selector fragment.
|
|
376
|
+
*
|
|
377
|
+
* Single-branch groups are unwrapped (no :is() wrapper).
|
|
378
|
+
* Multi-branch groups use :is() or :not().
|
|
379
|
+
* Negation swaps :is() for :not().
|
|
380
|
+
*/
|
|
381
|
+
function selectorGroupToCSS(group) {
|
|
382
|
+
if (group.branches.length === 0) return "";
|
|
383
|
+
if (group.branches.length === 1) {
|
|
384
|
+
const parts = branchToCSS(group.branches[0]);
|
|
385
|
+
if (group.negated) return `:not(${parts})`;
|
|
386
|
+
return parts;
|
|
387
|
+
}
|
|
388
|
+
return wrapInIsOrNot(group.branches.map(branchToCSS), group.negated);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Collect facts about modifier conditions for subsumption analysis.
|
|
392
|
+
* Tracks negated boolean attrs (:not([attr])) and positive exact values ([attr="X"]).
|
|
337
393
|
*/
|
|
338
|
-
function
|
|
339
|
-
|
|
394
|
+
function collectSubsumptionFacts(modifiers) {
|
|
395
|
+
const negatedBooleanAttrs = /* @__PURE__ */ new Set();
|
|
396
|
+
const positiveExactValuesByAttr = /* @__PURE__ */ new Map();
|
|
397
|
+
for (const mod of modifiers) {
|
|
398
|
+
if (mod.negated && mod.value === void 0) negatedBooleanAttrs.add(mod.attribute);
|
|
399
|
+
if (!mod.negated && mod.value !== void 0 && (mod.operator ?? "=") === "=") {
|
|
400
|
+
let vals = positiveExactValuesByAttr.get(mod.attribute);
|
|
401
|
+
if (!vals) {
|
|
402
|
+
vals = /* @__PURE__ */ new Set();
|
|
403
|
+
positiveExactValuesByAttr.set(mod.attribute, vals);
|
|
404
|
+
}
|
|
405
|
+
vals.add(mod.value);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return {
|
|
409
|
+
negatedBooleanAttrs,
|
|
410
|
+
positiveExactValuesByAttr
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Check if a negated-value modifier is subsumed by stronger facts:
|
|
415
|
+
* - :not([attr]) subsumes :not([attr="val"])
|
|
416
|
+
* - [attr="X"] implies :not([attr="Y"]) is redundant (single exact value)
|
|
417
|
+
*
|
|
418
|
+
* Only applies to exact-match (=) operators; substring operators don't
|
|
419
|
+
* imply exclusivity between values.
|
|
420
|
+
*/
|
|
421
|
+
function isSubsumedNegatedModifier(mod, facts) {
|
|
422
|
+
if (!mod.negated || mod.value === void 0) return false;
|
|
423
|
+
if (facts.negatedBooleanAttrs.has(mod.attribute)) return true;
|
|
424
|
+
if ((mod.operator ?? "=") === "=") {
|
|
425
|
+
const posVals = facts.positiveExactValuesByAttr.get(mod.attribute);
|
|
426
|
+
if (posVals && posVals.size === 1 && !posVals.has(mod.value)) return true;
|
|
427
|
+
}
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Remove redundant single-condition groups that are subsumed by stronger
|
|
432
|
+
* groups on the same attribute. O(n) — only inspects single-branch,
|
|
433
|
+
* single-condition groups.
|
|
434
|
+
*/
|
|
435
|
+
function optimizeGroups(groups) {
|
|
436
|
+
if (groups.length <= 1) return groups;
|
|
437
|
+
const seen = /* @__PURE__ */ new Set();
|
|
438
|
+
const result = [];
|
|
439
|
+
for (const g of groups) {
|
|
440
|
+
const key = getSelectorGroupKey(g);
|
|
441
|
+
if (!seen.has(key)) {
|
|
442
|
+
seen.add(key);
|
|
443
|
+
result.push(g);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (result.length <= 1) return result;
|
|
447
|
+
const effectiveModifiers = [];
|
|
448
|
+
for (const g of result) {
|
|
449
|
+
if (g.branches.length !== 1 || g.branches[0].length !== 1) continue;
|
|
450
|
+
const cond = g.branches[0][0];
|
|
451
|
+
if (!("attribute" in cond)) continue;
|
|
452
|
+
effectiveModifiers.push({
|
|
453
|
+
...cond,
|
|
454
|
+
negated: g.negated !== cond.negated
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
const facts = collectSubsumptionFacts(effectiveModifiers);
|
|
458
|
+
if (facts.negatedBooleanAttrs.size === 0 && facts.positiveExactValuesByAttr.size === 0) return result;
|
|
459
|
+
return result.filter((g) => {
|
|
460
|
+
if (g.branches.length !== 1 || g.branches[0].length !== 1) return true;
|
|
461
|
+
const cond = g.branches[0][0];
|
|
462
|
+
if (!("attribute" in cond) || !g.negated || cond.negated || cond.value === void 0) return true;
|
|
463
|
+
return !isSubsumedNegatedModifier({
|
|
464
|
+
...cond,
|
|
465
|
+
negated: true
|
|
466
|
+
}, facts);
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Convert root groups to CSS selector prefix (for final output)
|
|
471
|
+
*/
|
|
472
|
+
function rootGroupsToCSS(groups) {
|
|
473
|
+
if (groups.length === 0) return void 0;
|
|
474
|
+
const optimized = optimizeGroups(groups);
|
|
475
|
+
if (optimized.length === 0) return void 0;
|
|
340
476
|
let prefix = ":root";
|
|
341
|
-
for (const
|
|
477
|
+
for (const group of optimized) prefix += selectorGroupToCSS(group);
|
|
342
478
|
return prefix;
|
|
343
479
|
}
|
|
344
480
|
/**
|
|
345
481
|
* Convert parent groups to CSS selector fragments (for final output).
|
|
346
|
-
* Each group produces its own :is() wrapper
|
|
482
|
+
* Each group produces its own :is()/:not() wrapper with a combinator
|
|
483
|
+
* suffix (` *` or ` > *`) appended to each branch.
|
|
347
484
|
*/
|
|
348
485
|
function parentGroupsToCSS(groups) {
|
|
349
486
|
let result = "";
|
|
350
487
|
for (const group of groups) {
|
|
351
488
|
const combinator = group.direct ? " > *" : " *";
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
const wrapper = group.negated ? ":not" : ":is";
|
|
355
|
-
result += `${wrapper}(${parts}${combinator})`;
|
|
489
|
+
const args = group.branches.map((branch) => branchToCSS(branch) + combinator);
|
|
490
|
+
result += wrapInIsOrNot(args, group.negated);
|
|
356
491
|
}
|
|
357
492
|
return result;
|
|
358
493
|
}
|
|
@@ -388,7 +523,7 @@ function getSelectorConditionKey(cond) {
|
|
|
388
523
|
*/
|
|
389
524
|
function dedupeSelectorConditions(conditions) {
|
|
390
525
|
const seen = /* @__PURE__ */ new Set();
|
|
391
|
-
|
|
526
|
+
const result = [];
|
|
392
527
|
for (const c of conditions) {
|
|
393
528
|
const key = getSelectorConditionKey(c);
|
|
394
529
|
if (!seen.has(key)) {
|
|
@@ -396,30 +531,12 @@ function dedupeSelectorConditions(conditions) {
|
|
|
396
531
|
result.push(c);
|
|
397
532
|
}
|
|
398
533
|
}
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
if (!("attribute" in c))
|
|
403
|
-
|
|
404
|
-
const op = c.operator ?? "=";
|
|
405
|
-
if (!c.negated && c.value !== void 0 && op === "=") {
|
|
406
|
-
let values = positiveExactValuesByAttr.get(c.attribute);
|
|
407
|
-
if (!values) {
|
|
408
|
-
values = /* @__PURE__ */ new Set();
|
|
409
|
-
positiveExactValuesByAttr.set(c.attribute, values);
|
|
410
|
-
}
|
|
411
|
-
values.add(c.value);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
result = result.filter((c) => {
|
|
415
|
-
if (!("attribute" in c) || !c.negated || c.value === void 0) return true;
|
|
416
|
-
if (negatedBooleanAttrs.has(c.attribute)) return false;
|
|
417
|
-
if ((c.operator ?? "=") !== "=") return true;
|
|
418
|
-
const positiveValues = positiveExactValuesByAttr.get(c.attribute);
|
|
419
|
-
if (positiveValues !== void 0 && positiveValues.size === 1 && !positiveValues.has(c.value)) return false;
|
|
420
|
-
return true;
|
|
534
|
+
const facts = collectSubsumptionFacts(result.filter((c) => "attribute" in c));
|
|
535
|
+
if (facts.negatedBooleanAttrs.size === 0 && facts.positiveExactValuesByAttr.size === 0) return result;
|
|
536
|
+
return result.filter((c) => {
|
|
537
|
+
if (!("attribute" in c)) return true;
|
|
538
|
+
return !isSubsumedNegatedModifier(c, facts);
|
|
421
539
|
});
|
|
422
|
-
return result;
|
|
423
540
|
}
|
|
424
541
|
/**
|
|
425
542
|
* Check for modifier contradiction: same attribute with opposite negation
|
|
@@ -462,10 +579,32 @@ function hasSelectorConditionContradiction(conditions) {
|
|
|
462
579
|
* with opposite negation. E.g. :not([data-hovered] *) and :is([data-hovered] *)
|
|
463
580
|
* in the same variant is impossible.
|
|
464
581
|
*/
|
|
582
|
+
function getBranchesKey(branches) {
|
|
583
|
+
if (branches.length === 1) {
|
|
584
|
+
const b = branches[0];
|
|
585
|
+
if (b.length === 1) return getSelectorConditionKey(b[0]);
|
|
586
|
+
return b.map(getSelectorConditionKey).sort().join("+");
|
|
587
|
+
}
|
|
588
|
+
return branches.map((b) => b.map(getSelectorConditionKey).sort().join("+")).sort().join(",");
|
|
589
|
+
}
|
|
465
590
|
function hasParentGroupContradiction(groups) {
|
|
466
591
|
const byBaseKey = /* @__PURE__ */ new Map();
|
|
467
592
|
for (const g of groups) {
|
|
468
|
-
const baseKey = `${g.direct ? ">" : ""}(${g.
|
|
593
|
+
const baseKey = `${g.direct ? ">" : ""}(${getBranchesKey(g.branches)})`;
|
|
594
|
+
const existing = byBaseKey.get(baseKey);
|
|
595
|
+
if (existing !== void 0 && existing !== !g.negated) return true;
|
|
596
|
+
byBaseKey.set(baseKey, !g.negated);
|
|
597
|
+
}
|
|
598
|
+
return false;
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Check for selector group contradiction: same branches with opposite negation.
|
|
602
|
+
* E.g. :is([data-a]) and :not([data-a]) in the same variant is impossible.
|
|
603
|
+
*/
|
|
604
|
+
function hasSelectorGroupContradiction(groups) {
|
|
605
|
+
const byBaseKey = /* @__PURE__ */ new Map();
|
|
606
|
+
for (const g of groups) {
|
|
607
|
+
const baseKey = getBranchesKey(g.branches);
|
|
469
608
|
const existing = byBaseKey.get(baseKey);
|
|
470
609
|
if (existing !== void 0 && existing !== !g.negated) return true;
|
|
471
610
|
byBaseKey.set(baseKey, !g.negated);
|
|
@@ -479,15 +618,17 @@ function hasParentGroupContradiction(groups) {
|
|
|
479
618
|
function mergeVariants(a, b) {
|
|
480
619
|
const mergedMedia = dedupeMediaConditions([...a.mediaConditions, ...b.mediaConditions]);
|
|
481
620
|
if (hasMediaContradiction(mergedMedia)) return null;
|
|
482
|
-
const
|
|
483
|
-
if (
|
|
621
|
+
const mergedRootGroups = optimizeGroups([...a.rootGroups, ...b.rootGroups]);
|
|
622
|
+
if (hasSelectorGroupContradiction(mergedRootGroups)) return null;
|
|
484
623
|
const mergedModifiers = dedupeSelectorConditions([...a.modifierConditions, ...b.modifierConditions]);
|
|
485
624
|
const mergedPseudos = dedupeSelectorConditions([...a.pseudoConditions, ...b.pseudoConditions]);
|
|
486
625
|
if (hasSelectorConditionContradiction([...mergedModifiers, ...mergedPseudos])) return null;
|
|
626
|
+
const mergedSelectorGroups = optimizeGroups([...a.selectorGroups, ...b.selectorGroups]);
|
|
627
|
+
if (hasSelectorGroupContradiction(mergedSelectorGroups)) return null;
|
|
487
628
|
const mergedParentGroups = [...a.parentGroups, ...b.parentGroups];
|
|
488
629
|
if (hasParentGroupContradiction(mergedParentGroups)) return null;
|
|
489
|
-
const
|
|
490
|
-
if (
|
|
630
|
+
const mergedOwnGroups = optimizeGroups([...a.ownGroups, ...b.ownGroups]);
|
|
631
|
+
if (hasSelectorGroupContradiction(mergedOwnGroups)) return null;
|
|
491
632
|
const mergedContainers = dedupeContainerConditions([...a.containerConditions, ...b.containerConditions]);
|
|
492
633
|
if (hasContainerStyleContradiction(mergedContainers)) return null;
|
|
493
634
|
const mergedSupports = dedupeSupportsConditions([...a.supportsConditions, ...b.supportsConditions]);
|
|
@@ -495,59 +636,40 @@ function mergeVariants(a, b) {
|
|
|
495
636
|
return {
|
|
496
637
|
modifierConditions: mergedModifiers,
|
|
497
638
|
pseudoConditions: mergedPseudos,
|
|
498
|
-
|
|
639
|
+
selectorGroups: mergedSelectorGroups,
|
|
640
|
+
ownGroups: mergedOwnGroups,
|
|
499
641
|
mediaConditions: mergedMedia,
|
|
500
642
|
containerConditions: mergedContainers,
|
|
501
643
|
supportsConditions: mergedSupports,
|
|
502
|
-
|
|
644
|
+
rootGroups: mergedRootGroups,
|
|
503
645
|
parentGroups: mergedParentGroups,
|
|
504
646
|
startingStyle: a.startingStyle || b.startingStyle
|
|
505
647
|
};
|
|
506
648
|
}
|
|
507
649
|
/**
|
|
508
|
-
*
|
|
650
|
+
* Generic deduplication by a key extraction function.
|
|
651
|
+
* Preserves insertion order, keeping the first occurrence of each key.
|
|
509
652
|
*/
|
|
510
|
-
function
|
|
653
|
+
function dedupeByKey(items, getKey) {
|
|
511
654
|
const seen = /* @__PURE__ */ new Set();
|
|
512
655
|
const result = [];
|
|
513
|
-
for (const
|
|
514
|
-
const key =
|
|
656
|
+
for (const item of items) {
|
|
657
|
+
const key = getKey(item);
|
|
515
658
|
if (!seen.has(key)) {
|
|
516
659
|
seen.add(key);
|
|
517
|
-
result.push(
|
|
660
|
+
result.push(item);
|
|
518
661
|
}
|
|
519
662
|
}
|
|
520
663
|
return result;
|
|
521
664
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
665
|
+
function dedupeMediaConditions(conditions) {
|
|
666
|
+
return dedupeByKey(conditions, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
|
|
667
|
+
}
|
|
525
668
|
function dedupeContainerConditions(conditions) {
|
|
526
|
-
|
|
527
|
-
const result = [];
|
|
528
|
-
for (const c of conditions) {
|
|
529
|
-
const key = `${c.name ?? ""}|${c.condition}|${c.negated}`;
|
|
530
|
-
if (!seen.has(key)) {
|
|
531
|
-
seen.add(key);
|
|
532
|
-
result.push(c);
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
return result;
|
|
669
|
+
return dedupeByKey(conditions, (c) => `${c.name ?? ""}|${c.condition}|${c.negated}`);
|
|
536
670
|
}
|
|
537
|
-
/**
|
|
538
|
-
* Deduplicate supports conditions by their key (subtype + condition + negated)
|
|
539
|
-
*/
|
|
540
671
|
function dedupeSupportsConditions(conditions) {
|
|
541
|
-
|
|
542
|
-
const result = [];
|
|
543
|
-
for (const c of conditions) {
|
|
544
|
-
const key = `${c.subtype}|${c.condition}|${c.negated}`;
|
|
545
|
-
if (!seen.has(key)) {
|
|
546
|
-
seen.add(key);
|
|
547
|
-
result.push(c);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
return result;
|
|
672
|
+
return dedupeByKey(conditions, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
|
|
551
673
|
}
|
|
552
674
|
/**
|
|
553
675
|
* Check if supports conditions contain contradictions
|
|
@@ -644,26 +766,50 @@ function hasContainerStyleContradiction(conditions) {
|
|
|
644
766
|
}
|
|
645
767
|
return false;
|
|
646
768
|
}
|
|
769
|
+
const variantKeyCache = /* @__PURE__ */ new WeakMap();
|
|
647
770
|
/**
|
|
648
|
-
* Get a unique key for a variant (for deduplication)
|
|
771
|
+
* Get a unique key for a variant (for deduplication).
|
|
772
|
+
* Cached via WeakMap since variants are compared multiple times during
|
|
773
|
+
* deduplication and sorting.
|
|
649
774
|
*/
|
|
650
|
-
function
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
775
|
+
function getSelectorGroupKey(g) {
|
|
776
|
+
return `${g.negated ? "!" : ""}(${getBranchesKey(g.branches)})`;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Get a context key for a variant — everything except flat modifier/pseudo
|
|
780
|
+
* conditions. Variants with the same context key can be merged into an
|
|
781
|
+
* :is() group. Also used by getVariantKey as the shared non-selector portion.
|
|
782
|
+
*/
|
|
783
|
+
function getVariantContextKey(v) {
|
|
655
784
|
return [
|
|
656
|
-
modifierKey,
|
|
657
|
-
pseudoKey,
|
|
658
|
-
ownKey,
|
|
659
785
|
v.mediaConditions.map((c) => `${c.subtype}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|"),
|
|
660
|
-
|
|
786
|
+
v.containerConditions.map((c) => `${c.name ?? ""}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|"),
|
|
661
787
|
v.supportsConditions.map((c) => `${c.subtype}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|"),
|
|
662
|
-
v.
|
|
788
|
+
v.rootGroups.map(getSelectorGroupKey).sort().join("|"),
|
|
663
789
|
v.parentGroups.map(getParentGroupKey).sort().join("|"),
|
|
790
|
+
v.ownGroups.map(getSelectorGroupKey).sort().join("|"),
|
|
791
|
+
v.selectorGroups.map(getSelectorGroupKey).sort().join("|"),
|
|
664
792
|
v.startingStyle ? "1" : "0"
|
|
665
793
|
].join("###");
|
|
666
794
|
}
|
|
795
|
+
function getVariantKey(v) {
|
|
796
|
+
const cached = variantKeyCache.get(v);
|
|
797
|
+
if (cached !== void 0) return cached;
|
|
798
|
+
const modifierKey = v.modifierConditions.map(getModifierKey).sort().join("|");
|
|
799
|
+
const pseudoKey = v.pseudoConditions.map(getPseudoKey).sort().join("|");
|
|
800
|
+
const key = modifierKey + "###" + pseudoKey + "###" + getVariantContextKey(v);
|
|
801
|
+
variantKeyCache.set(v, key);
|
|
802
|
+
return key;
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Total number of leaf conditions in a variant (for superset / dedup comparisons).
|
|
806
|
+
*/
|
|
807
|
+
function groupConditionCount(groups) {
|
|
808
|
+
return groups.reduce((sum, g) => sum + g.branches.reduce((s, b) => s + b.length, 0), 0);
|
|
809
|
+
}
|
|
810
|
+
function variantConditionCount(v) {
|
|
811
|
+
return v.modifierConditions.length + v.pseudoConditions.length + groupConditionCount(v.selectorGroups) + groupConditionCount(v.ownGroups) + v.mediaConditions.length + v.containerConditions.length + v.supportsConditions.length + groupConditionCount(v.rootGroups) + groupConditionCount(v.parentGroups);
|
|
812
|
+
}
|
|
667
813
|
/**
|
|
668
814
|
* Check if variant A is a superset of variant B (A is more restrictive)
|
|
669
815
|
*
|
|
@@ -677,74 +823,42 @@ function getVariantKey(v) {
|
|
|
677
823
|
*/
|
|
678
824
|
function isVariantSuperset(a, b) {
|
|
679
825
|
if (a.startingStyle !== b.startingStyle) return false;
|
|
680
|
-
if (!
|
|
826
|
+
if (!isSelectorGroupsSuperset(a.rootGroups, b.rootGroups)) return false;
|
|
681
827
|
if (!isMediaConditionsSuperset(a.mediaConditions, b.mediaConditions)) return false;
|
|
682
828
|
if (!isContainerConditionsSuperset(a.containerConditions, b.containerConditions)) return false;
|
|
683
829
|
if (!isSupportsConditionsSuperset(a.supportsConditions, b.supportsConditions)) return false;
|
|
684
830
|
if (!isModifierConditionsSuperset(a.modifierConditions, b.modifierConditions)) return false;
|
|
685
831
|
if (!isPseudoConditionsSuperset(a.pseudoConditions, b.pseudoConditions)) return false;
|
|
686
|
-
if (!
|
|
832
|
+
if (!isSelectorGroupsSuperset(a.selectorGroups, b.selectorGroups)) return false;
|
|
833
|
+
if (!isSelectorGroupsSuperset(a.ownGroups, b.ownGroups)) return false;
|
|
687
834
|
if (!isParentGroupsSuperset(a.parentGroups, b.parentGroups)) return false;
|
|
688
|
-
|
|
689
|
-
return a.mediaConditions.length + a.containerConditions.length + a.supportsConditions.length + a.modifierConditions.length + a.pseudoConditions.length + a.rootConditions.length + parentConditionCount(a.parentGroups) + a.ownConditions.length > b.mediaConditions.length + b.containerConditions.length + b.supportsConditions.length + b.modifierConditions.length + b.pseudoConditions.length + b.rootConditions.length + parentConditionCount(b.parentGroups) + b.ownConditions.length;
|
|
835
|
+
return variantConditionCount(a) > variantConditionCount(b);
|
|
690
836
|
}
|
|
691
837
|
/**
|
|
692
|
-
*
|
|
838
|
+
* Generic superset check: true if every item in B has a matching key in A.
|
|
693
839
|
*/
|
|
840
|
+
function isConditionsSuperset(a, b, getKey) {
|
|
841
|
+
const aKeys = new Set(a.map(getKey));
|
|
842
|
+
return b.every((c) => aKeys.has(getKey(c)));
|
|
843
|
+
}
|
|
694
844
|
function isMediaConditionsSuperset(a, b) {
|
|
695
|
-
|
|
696
|
-
for (const c of b) {
|
|
697
|
-
const key = `${c.subtype}|${c.condition}|${c.negated}`;
|
|
698
|
-
if (!aKeys.has(key)) return false;
|
|
699
|
-
}
|
|
700
|
-
return true;
|
|
845
|
+
return isConditionsSuperset(a, b, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
|
|
701
846
|
}
|
|
702
|
-
/**
|
|
703
|
-
* Check if container conditions A is a superset of B
|
|
704
|
-
*/
|
|
705
847
|
function isContainerConditionsSuperset(a, b) {
|
|
706
|
-
|
|
707
|
-
for (const c of b) {
|
|
708
|
-
const key = `${c.name ?? ""}|${c.condition}|${c.negated}`;
|
|
709
|
-
if (!aKeys.has(key)) return false;
|
|
710
|
-
}
|
|
711
|
-
return true;
|
|
848
|
+
return isConditionsSuperset(a, b, (c) => `${c.name ?? ""}|${c.condition}|${c.negated}`);
|
|
712
849
|
}
|
|
713
|
-
/**
|
|
714
|
-
* Check if supports conditions A is a superset of B
|
|
715
|
-
*/
|
|
716
850
|
function isSupportsConditionsSuperset(a, b) {
|
|
717
|
-
|
|
718
|
-
for (const c of b) {
|
|
719
|
-
const key = `${c.subtype}|${c.condition}|${c.negated}`;
|
|
720
|
-
if (!aKeys.has(key)) return false;
|
|
721
|
-
}
|
|
722
|
-
return true;
|
|
851
|
+
return isConditionsSuperset(a, b, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
|
|
723
852
|
}
|
|
724
|
-
/**
|
|
725
|
-
* Check if modifier conditions A is a superset of B
|
|
726
|
-
*/
|
|
727
853
|
function isModifierConditionsSuperset(a, b) {
|
|
728
|
-
|
|
729
|
-
for (const c of b) if (!aKeys.has(getModifierKey(c))) return false;
|
|
730
|
-
return true;
|
|
854
|
+
return isConditionsSuperset(a, b, getModifierKey);
|
|
731
855
|
}
|
|
732
|
-
/**
|
|
733
|
-
* Check if pseudo conditions A is a superset of B
|
|
734
|
-
*/
|
|
735
856
|
function isPseudoConditionsSuperset(a, b) {
|
|
736
|
-
|
|
737
|
-
for (const c of b) if (!aKeys.has(getPseudoKey(c))) return false;
|
|
738
|
-
return true;
|
|
857
|
+
return isConditionsSuperset(a, b, getPseudoKey);
|
|
739
858
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
*/
|
|
744
|
-
function isSelectorConditionsSuperset(a, b) {
|
|
745
|
-
const aKeys = new Set(a.map(getSelectorConditionKey));
|
|
746
|
-
for (const c of b) if (!aKeys.has(getSelectorConditionKey(c))) return false;
|
|
747
|
-
return true;
|
|
859
|
+
function isSelectorGroupsSuperset(a, b) {
|
|
860
|
+
if (a.length < b.length) return false;
|
|
861
|
+
return isConditionsSuperset(a, b, getSelectorGroupKey);
|
|
748
862
|
}
|
|
749
863
|
/**
|
|
750
864
|
* Check if parent groups A is a superset of B.
|
|
@@ -752,12 +866,10 @@ function isSelectorConditionsSuperset(a, b) {
|
|
|
752
866
|
*/
|
|
753
867
|
function isParentGroupsSuperset(a, b) {
|
|
754
868
|
if (a.length < b.length) return false;
|
|
755
|
-
|
|
756
|
-
for (const g of b) if (!aKeys.has(getParentGroupKey(g))) return false;
|
|
757
|
-
return true;
|
|
869
|
+
return isConditionsSuperset(a, b, getParentGroupKey);
|
|
758
870
|
}
|
|
759
871
|
function getParentGroupKey(g) {
|
|
760
|
-
return `${g.negated ? "!" : ""}${g.direct ? ">" : ""}(${g.
|
|
872
|
+
return `${g.negated ? "!" : ""}${g.direct ? ">" : ""}(${getBranchesKey(g.branches)})`;
|
|
761
873
|
}
|
|
762
874
|
/**
|
|
763
875
|
* Deduplicate variants
|
|
@@ -767,6 +879,7 @@ function getParentGroupKey(g) {
|
|
|
767
879
|
* 2. Superset variants (more restrictive selectors that are redundant)
|
|
768
880
|
*/
|
|
769
881
|
function dedupeVariants(variants) {
|
|
882
|
+
if (variants.length <= 1) return variants;
|
|
770
883
|
const seen = /* @__PURE__ */ new Set();
|
|
771
884
|
const result = [];
|
|
772
885
|
for (const v of variants) {
|
|
@@ -776,7 +889,7 @@ function dedupeVariants(variants) {
|
|
|
776
889
|
result.push(v);
|
|
777
890
|
}
|
|
778
891
|
}
|
|
779
|
-
|
|
892
|
+
if (result.length <= 1) return result;
|
|
780
893
|
result.sort((a, b) => variantConditionCount(a) - variantConditionCount(b));
|
|
781
894
|
const filtered = [];
|
|
782
895
|
for (const candidate of result) {
|
|
@@ -826,8 +939,8 @@ function andToCSS(children) {
|
|
|
826
939
|
* Combine OR conditions into CSS
|
|
827
940
|
*
|
|
828
941
|
* OR in CSS means multiple selector variants (DNF).
|
|
829
|
-
*
|
|
830
|
-
*
|
|
942
|
+
* After deduplication, variants that differ only in their base
|
|
943
|
+
* modifier/pseudo conditions are merged into :is() groups.
|
|
831
944
|
*
|
|
832
945
|
* Note: OR exclusivity is handled at the pipeline level (expandOrConditions),
|
|
833
946
|
* so here we just collect all variants. Any remaining ORs in the condition
|
|
@@ -850,17 +963,101 @@ function orToCSS(children) {
|
|
|
850
963
|
};
|
|
851
964
|
}
|
|
852
965
|
/**
|
|
853
|
-
*
|
|
966
|
+
* Find keys present in ALL condition arrays.
|
|
967
|
+
*/
|
|
968
|
+
function findCommonKeys(conditionSets, getKey) {
|
|
969
|
+
if (conditionSets.length === 0) return /* @__PURE__ */ new Set();
|
|
970
|
+
const common = new Set(conditionSets[0].map(getKey));
|
|
971
|
+
for (let i = 1; i < conditionSets.length; i++) {
|
|
972
|
+
const keys = new Set(conditionSets[i].map(getKey));
|
|
973
|
+
for (const key of common) if (!keys.has(key)) common.delete(key);
|
|
974
|
+
}
|
|
975
|
+
return common;
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
* Merge OR variants that share the same "context" (at-rules, root, parent,
|
|
979
|
+
* own, starting) into a single variant with a SelectorGroup.
|
|
980
|
+
*
|
|
981
|
+
* Variants with no modifier/pseudo conditions are kept separate (they match
|
|
982
|
+
* unconditionally and can't be expressed inside :is()).
|
|
983
|
+
*/
|
|
984
|
+
function mergeVariantsIntoSelectorGroups(variants) {
|
|
985
|
+
if (variants.length <= 1) return variants;
|
|
986
|
+
const groups = /* @__PURE__ */ new Map();
|
|
987
|
+
for (const v of variants) {
|
|
988
|
+
const key = getVariantContextKey(v);
|
|
989
|
+
const group = groups.get(key);
|
|
990
|
+
if (group) group.push(v);
|
|
991
|
+
else groups.set(key, [v]);
|
|
992
|
+
}
|
|
993
|
+
const result = [];
|
|
994
|
+
for (const group of groups.values()) {
|
|
995
|
+
if (group.length === 1) {
|
|
996
|
+
result.push(group[0]);
|
|
997
|
+
continue;
|
|
998
|
+
}
|
|
999
|
+
const withSelectors = [];
|
|
1000
|
+
const withoutSelectors = [];
|
|
1001
|
+
for (const v of group) if (v.modifierConditions.length === 0 && v.pseudoConditions.length === 0) withoutSelectors.push(v);
|
|
1002
|
+
else withSelectors.push(v);
|
|
1003
|
+
result.push(...withoutSelectors);
|
|
1004
|
+
if (withSelectors.length <= 1) {
|
|
1005
|
+
result.push(...withSelectors);
|
|
1006
|
+
continue;
|
|
1007
|
+
}
|
|
1008
|
+
result.push(factorAndGroup(withSelectors));
|
|
1009
|
+
}
|
|
1010
|
+
return result;
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Factor common modifier/pseudo conditions out of variants and create
|
|
1014
|
+
* a single variant with a SelectorGroup for the remaining (differing)
|
|
1015
|
+
* conditions.
|
|
1016
|
+
*
|
|
1017
|
+
* Precondition: all variants must share the same context key (identical
|
|
1018
|
+
* at-rules, root/parent/own/selector groups, startingStyle).
|
|
854
1019
|
*/
|
|
855
|
-
function
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
1020
|
+
function factorAndGroup(variants) {
|
|
1021
|
+
{
|
|
1022
|
+
const key0 = getVariantContextKey(variants[0]);
|
|
1023
|
+
for (let i = 1; i < variants.length; i++) {
|
|
1024
|
+
const keyI = getVariantContextKey(variants[i]);
|
|
1025
|
+
if (keyI !== key0) throw new Error(`factorAndGroup: context key mismatch at index ${i}.\n expected: ${key0}\n got: ${keyI}`);
|
|
1026
|
+
}
|
|
862
1027
|
}
|
|
863
|
-
|
|
1028
|
+
const commonModKeys = findCommonKeys(variants.map((v) => v.modifierConditions), getModifierKey);
|
|
1029
|
+
const commonPseudoKeys = findCommonKeys(variants.map((v) => v.pseudoConditions), getPseudoKey);
|
|
1030
|
+
const commonModifiers = variants[0].modifierConditions.filter((m) => commonModKeys.has(getModifierKey(m)));
|
|
1031
|
+
const commonPseudos = variants[0].pseudoConditions.filter((p) => commonPseudoKeys.has(getPseudoKey(p)));
|
|
1032
|
+
const branches = [];
|
|
1033
|
+
let hasEmptyBranch = false;
|
|
1034
|
+
for (const v of variants) {
|
|
1035
|
+
const branch = [];
|
|
1036
|
+
for (const mod of v.modifierConditions) if (!commonModKeys.has(getModifierKey(mod))) branch.push(mod);
|
|
1037
|
+
for (const pseudo of v.pseudoConditions) if (!commonPseudoKeys.has(getPseudoKey(pseudo))) branch.push(pseudo);
|
|
1038
|
+
if (branch.length > 0) branches.push(branch);
|
|
1039
|
+
else hasEmptyBranch = true;
|
|
1040
|
+
}
|
|
1041
|
+
if (hasEmptyBranch) return {
|
|
1042
|
+
...variants[0],
|
|
1043
|
+
modifierConditions: commonModifiers,
|
|
1044
|
+
pseudoConditions: commonPseudos
|
|
1045
|
+
};
|
|
1046
|
+
return {
|
|
1047
|
+
modifierConditions: commonModifiers,
|
|
1048
|
+
pseudoConditions: commonPseudos,
|
|
1049
|
+
selectorGroups: [...variants[0].selectorGroups, {
|
|
1050
|
+
branches,
|
|
1051
|
+
negated: false
|
|
1052
|
+
}],
|
|
1053
|
+
ownGroups: [...variants[0].ownGroups],
|
|
1054
|
+
mediaConditions: [...variants[0].mediaConditions],
|
|
1055
|
+
containerConditions: [...variants[0].containerConditions],
|
|
1056
|
+
supportsConditions: [...variants[0].supportsConditions],
|
|
1057
|
+
rootGroups: [...variants[0].rootGroups],
|
|
1058
|
+
parentGroups: [...variants[0].parentGroups],
|
|
1059
|
+
startingStyle: variants[0].startingStyle
|
|
1060
|
+
};
|
|
864
1061
|
}
|
|
865
1062
|
/**
|
|
866
1063
|
* Build at-rules array from a variant
|
|
@@ -899,10 +1096,9 @@ function buildAtRulesFromVariant(variant) {
|
|
|
899
1096
|
});
|
|
900
1097
|
atRules.push(`@supports ${conditionParts.join(" and ")}`);
|
|
901
1098
|
}
|
|
902
|
-
if (variant.startingStyle) atRules.push("@starting-style");
|
|
903
1099
|
return atRules;
|
|
904
1100
|
}
|
|
905
1101
|
|
|
906
1102
|
//#endregion
|
|
907
|
-
export { buildAtRulesFromVariant, conditionToCSS,
|
|
1103
|
+
export { branchToCSS, buildAtRulesFromVariant, conditionToCSS, mergeVariantsIntoSelectorGroups, optimizeGroups, parentGroupsToCSS, rootGroupsToCSS, selectorGroupToCSS };
|
|
908
1104
|
//# sourceMappingURL=materialize.js.map
|