@tenphi/tasty 0.0.0-snapshot.c11c8b8 → 0.0.0-snapshot.c8bdaeb

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.
Files changed (71) hide show
  1. package/README.md +27 -11
  2. package/dist/debug.js +1 -1
  3. package/dist/debug.js.map +1 -1
  4. package/dist/index.d.ts +9 -1
  5. package/dist/pipeline/conditions.d.ts +1 -1
  6. package/dist/pipeline/conditions.js +16 -10
  7. package/dist/pipeline/conditions.js.map +1 -1
  8. package/dist/pipeline/index.js +61 -42
  9. package/dist/pipeline/index.js.map +1 -1
  10. package/dist/pipeline/materialize.js +220 -196
  11. package/dist/pipeline/materialize.js.map +1 -1
  12. package/dist/pipeline/parseStateKey.d.ts +0 -3
  13. package/dist/pipeline/parseStateKey.js +24 -16
  14. package/dist/pipeline/parseStateKey.js.map +1 -1
  15. package/dist/pipeline/simplify.js +111 -152
  16. package/dist/pipeline/simplify.js.map +1 -1
  17. package/dist/pipeline/warnings.js +18 -0
  18. package/dist/pipeline/warnings.js.map +1 -0
  19. package/dist/styles/align.d.ts +1 -1
  20. package/dist/styles/align.js.map +1 -1
  21. package/dist/styles/border.d.ts +1 -1
  22. package/dist/styles/border.js.map +1 -1
  23. package/dist/styles/color.d.ts +2 -2
  24. package/dist/styles/color.js.map +1 -1
  25. package/dist/styles/createStyle.js +1 -1
  26. package/dist/styles/createStyle.js.map +1 -1
  27. package/dist/styles/fade.d.ts +1 -1
  28. package/dist/styles/fade.js.map +1 -1
  29. package/dist/styles/fill.d.ts +14 -16
  30. package/dist/styles/fill.js.map +1 -1
  31. package/dist/styles/flow.d.ts +3 -3
  32. package/dist/styles/flow.js.map +1 -1
  33. package/dist/styles/inset.d.ts +3 -1
  34. package/dist/styles/inset.js +48 -40
  35. package/dist/styles/inset.js.map +1 -1
  36. package/dist/styles/justify.d.ts +1 -1
  37. package/dist/styles/justify.js.map +1 -1
  38. package/dist/styles/margin.d.ts +1 -5
  39. package/dist/styles/margin.js +48 -40
  40. package/dist/styles/margin.js.map +1 -1
  41. package/dist/styles/padding.d.ts +1 -5
  42. package/dist/styles/padding.js +48 -40
  43. package/dist/styles/padding.js.map +1 -1
  44. package/dist/styles/predefined.js.map +1 -1
  45. package/dist/styles/radius.d.ts +1 -1
  46. package/dist/styles/radius.js.map +1 -1
  47. package/dist/styles/scrollbar.d.ts +1 -1
  48. package/dist/styles/scrollbar.js +19 -12
  49. package/dist/styles/scrollbar.js.map +1 -1
  50. package/dist/styles/shadow.d.ts +2 -2
  51. package/dist/styles/shadow.js.map +1 -1
  52. package/dist/styles/styledScrollbar.d.ts +1 -1
  53. package/dist/styles/styledScrollbar.js.map +1 -1
  54. package/dist/styles/transition.d.ts +1 -1
  55. package/dist/styles/transition.js +26 -6
  56. package/dist/styles/transition.js.map +1 -1
  57. package/dist/tasty.d.ts +3 -3
  58. package/dist/tasty.js +16 -1
  59. package/dist/tasty.js.map +1 -1
  60. package/dist/types.d.ts +2 -2
  61. package/dist/utils/colors.d.ts +1 -1
  62. package/dist/utils/colors.js.map +1 -1
  63. package/dist/utils/css-types.d.ts +1 -1
  64. package/dist/utils/dotize.d.ts +1 -1
  65. package/dist/utils/mod-attrs.js.map +1 -1
  66. package/dist/utils/string.js.map +1 -1
  67. package/dist/utils/styles.d.ts +7 -12
  68. package/dist/utils/styles.js +13 -8
  69. package/dist/utils/styles.js.map +1 -1
  70. package/package.json +55 -4
  71. package/tasty.config.ts +14 -0
@@ -1,4 +1,5 @@
1
1
  import { Lru } from "../parser/lru.js";
2
+ import { getConditionUniqueId, not } from "./conditions.js";
2
3
 
3
4
  //#region src/pipeline/materialize.ts
4
5
  /**
@@ -12,16 +13,13 @@ const conditionCache = new Lru(3e3);
12
13
  * Convert a condition tree to CSS components
13
14
  */
14
15
  function conditionToCSS(node) {
15
- const key = getConditionKey(node);
16
+ const key = getConditionUniqueId(node);
16
17
  const cached = conditionCache.get(key);
17
18
  if (cached) return cached;
18
19
  const result = conditionToCSSInner(node);
19
20
  conditionCache.set(key, result);
20
21
  return result;
21
22
  }
22
- /**
23
- * Create an empty selector variant
24
- */
25
23
  function emptyVariant() {
26
24
  return {
27
25
  modifierConditions: [],
@@ -31,8 +29,7 @@ function emptyVariant() {
31
29
  containerConditions: [],
32
30
  supportsConditions: [],
33
31
  rootConditions: [],
34
- parentConditions: [],
35
- parentDirect: false,
32
+ parentGroups: [],
36
33
  startingStyle: false
37
34
  };
38
35
  }
@@ -66,37 +63,46 @@ function stateToCSS(state) {
66
63
  }),
67
64
  isImpossible: false
68
65
  };
69
- default: {
70
- const variant = emptyVariant();
71
- switch (state.type) {
72
- case "modifier":
73
- variant.modifierConditions.push(modifierToParsed(state));
74
- break;
75
- case "pseudo":
76
- variant.pseudoConditions.push(pseudoToParsed(state));
77
- break;
78
- case "container":
79
- variant.containerConditions.push(containerToParsed(state));
80
- break;
81
- case "supports":
82
- variant.supportsConditions.push(supportsToParsed(state));
83
- break;
84
- case "root":
85
- variant.rootConditions.push(...extractInnerConditions(state.innerCondition, state.negated ?? false));
86
- break;
87
- case "parent":
88
- variant.parentConditions.push(...extractInnerConditions(state.innerCondition, state.negated ?? false));
89
- variant.parentDirect = state.direct;
90
- break;
91
- case "own":
92
- variant.ownConditions.push(...extractInnerConditions(state.innerCondition, state.negated ?? false));
93
- break;
94
- case "starting":
95
- variant.startingStyle = !state.negated;
96
- break;
97
- }
66
+ case "root": return innerConditionToVariants(state.innerCondition, state.negated ?? false, "rootConditions");
67
+ case "parent": return parentConditionToVariants(state.innerCondition, state.negated ?? false, state.direct);
68
+ case "own": return innerConditionToVariants(state.innerCondition, state.negated ?? false, "ownConditions");
69
+ case "modifier": {
70
+ const v = emptyVariant();
71
+ v.modifierConditions.push(modifierToParsed(state));
72
+ return {
73
+ variants: [v],
74
+ isImpossible: false
75
+ };
76
+ }
77
+ case "pseudo": {
78
+ const v = emptyVariant();
79
+ v.pseudoConditions.push(pseudoToParsed(state));
80
+ return {
81
+ variants: [v],
82
+ isImpossible: false
83
+ };
84
+ }
85
+ case "container": {
86
+ const v = emptyVariant();
87
+ v.containerConditions.push(containerToParsed(state));
98
88
  return {
99
- variants: [variant],
89
+ variants: [v],
90
+ isImpossible: false
91
+ };
92
+ }
93
+ case "supports": {
94
+ const v = emptyVariant();
95
+ v.supportsConditions.push(supportsToParsed(state));
96
+ return {
97
+ variants: [v],
98
+ isImpossible: false
99
+ };
100
+ }
101
+ case "starting": {
102
+ const v = emptyVariant();
103
+ v.startingStyle = !state.negated;
104
+ return {
105
+ variants: [v],
100
106
  isImpossible: false
101
107
  };
102
108
  }
@@ -235,24 +241,93 @@ function supportsToParsed(state) {
235
241
  };
236
242
  }
237
243
  /**
238
- * Extract modifier/pseudo conditions from an inner condition tree.
239
- * Shared by @own(), @root(), and @parent().
244
+ * Collect all modifier and pseudo conditions from a variant as a flat array.
245
+ */
246
+ function collectSelectorConditions(variant) {
247
+ return [...variant.modifierConditions, ...variant.pseudoConditions];
248
+ }
249
+ /**
250
+ * Convert an inner condition tree into SelectorVariants.
251
+ * Each inner OR branch becomes a separate variant, preserving disjunction.
252
+ * Shared by @root() and @own().
253
+ */
254
+ function innerConditionToVariants(innerCondition, negated, target) {
255
+ const innerCSS = conditionToCSS(negated ? not(innerCondition) : innerCondition);
256
+ if (innerCSS.isImpossible || innerCSS.variants.length === 0) return {
257
+ variants: [],
258
+ isImpossible: true
259
+ };
260
+ const variants = [];
261
+ for (const innerVariant of innerCSS.variants) {
262
+ const conditions = collectSelectorConditions(innerVariant);
263
+ if (conditions.length > 0) {
264
+ const v = emptyVariant();
265
+ v[target].push(...conditions);
266
+ variants.push(v);
267
+ }
268
+ }
269
+ if (variants.length === 0) return {
270
+ variants: [emptyVariant()],
271
+ isImpossible: false
272
+ };
273
+ return {
274
+ variants,
275
+ isImpossible: false
276
+ };
277
+ }
278
+ /**
279
+ * Convert a @parent() inner condition into SelectorVariants with ParentGroups.
280
+ *
281
+ * Positive: each inner OR branch becomes a separate variant with one :is() group.
282
+ * Negated: !(A | B) = !A & !B — all branches become :not() groups collected
283
+ * into a single variant so they produce :not([a] *):not([b] *) on one element.
240
284
  */
241
- function extractInnerConditions(innerCondition, negated) {
285
+ function parentConditionToVariants(innerCondition, negated, direct) {
242
286
  const innerCSS = conditionToCSS(innerCondition);
243
- if (innerCSS.isImpossible || innerCSS.variants.length === 0) return [];
244
- const result = [];
245
- for (const variant of innerCSS.variants) {
246
- for (const mod of variant.modifierConditions) result.push({
247
- ...mod,
248
- negated: negated ? !mod.negated : mod.negated
249
- });
250
- for (const pseudo of variant.pseudoConditions) result.push({
251
- ...pseudo,
252
- negated: negated ? !pseudo.negated : pseudo.negated
253
- });
287
+ if (innerCSS.isImpossible || innerCSS.variants.length === 0) return {
288
+ variants: [],
289
+ isImpossible: true
290
+ };
291
+ if (negated) {
292
+ const v = emptyVariant();
293
+ for (const innerVariant of innerCSS.variants) {
294
+ const conditions = collectSelectorConditions(innerVariant);
295
+ if (conditions.length > 0) v.parentGroups.push({
296
+ conditions,
297
+ direct,
298
+ negated: true
299
+ });
300
+ }
301
+ if (v.parentGroups.length === 0) return {
302
+ variants: [emptyVariant()],
303
+ isImpossible: false
304
+ };
305
+ return {
306
+ variants: [v],
307
+ isImpossible: false
308
+ };
254
309
  }
255
- return result;
310
+ const variants = [];
311
+ for (const innerVariant of innerCSS.variants) {
312
+ const conditions = collectSelectorConditions(innerVariant);
313
+ if (conditions.length > 0) {
314
+ const v = emptyVariant();
315
+ v.parentGroups.push({
316
+ conditions,
317
+ direct,
318
+ negated: false
319
+ });
320
+ variants.push(v);
321
+ }
322
+ }
323
+ if (variants.length === 0) return {
324
+ variants: [emptyVariant()],
325
+ isImpossible: false
326
+ };
327
+ return {
328
+ variants,
329
+ isImpossible: false
330
+ };
256
331
  }
257
332
  /**
258
333
  * Convert parsed root conditions to CSS selector prefix (for final output)
@@ -264,14 +339,19 @@ function rootConditionsToCSS(roots) {
264
339
  return prefix;
265
340
  }
266
341
  /**
267
- * Convert parsed parent conditions to CSS selector fragment (for final output)
342
+ * Convert parent groups to CSS selector fragments (for final output).
343
+ * Each group produces its own :is() wrapper.
268
344
  */
269
- function parentConditionsToCSS(parents, direct) {
270
- if (parents.length === 0) return "";
271
- const combinator = direct ? " > *" : " *";
272
- let selectorParts = "";
273
- for (const cond of parents) selectorParts += selectorConditionToCSS(cond);
274
- return `:is(${selectorParts}${combinator})`;
345
+ function parentGroupsToCSS(groups) {
346
+ let result = "";
347
+ for (const group of groups) {
348
+ const combinator = group.direct ? " > *" : " *";
349
+ let parts = "";
350
+ for (const cond of group.conditions) parts += selectorConditionToCSS(cond);
351
+ const wrapper = group.negated ? ":not" : ":is";
352
+ result += `${wrapper}(${parts}${combinator})`;
353
+ }
354
+ return result;
275
355
  }
276
356
  /**
277
357
  * Convert a modifier or pseudo condition to a CSS selector fragment
@@ -300,36 +380,6 @@ function getSelectorConditionKey(cond) {
300
380
  return "attribute" in cond ? `mod:${getModifierKey(cond)}` : `pseudo:${getPseudoKey(cond)}`;
301
381
  }
302
382
  /**
303
- * Deduplicate modifier conditions
304
- */
305
- function dedupeModifierConditions(conditions) {
306
- const seen = /* @__PURE__ */ new Set();
307
- const result = [];
308
- for (const c of conditions) {
309
- const key = getModifierKey(c);
310
- if (!seen.has(key)) {
311
- seen.add(key);
312
- result.push(c);
313
- }
314
- }
315
- return result;
316
- }
317
- /**
318
- * Deduplicate pseudo conditions
319
- */
320
- function dedupePseudoConditions(conditions) {
321
- const seen = /* @__PURE__ */ new Set();
322
- const result = [];
323
- for (const c of conditions) {
324
- const key = getPseudoKey(c);
325
- if (!seen.has(key)) {
326
- seen.add(key);
327
- result.push(c);
328
- }
329
- }
330
- return result;
331
- }
332
- /**
333
383
  * Deduplicate selector conditions (modifiers or pseudos).
334
384
  * Shared by root, parent, and own conditions.
335
385
  */
@@ -344,17 +394,26 @@ function dedupeSelectorConditions(conditions) {
344
394
  }
345
395
  }
346
396
  const negatedBooleanAttrs = /* @__PURE__ */ new Set();
347
- const positiveValueByAttr = /* @__PURE__ */ new Map();
397
+ const positiveExactValuesByAttr = /* @__PURE__ */ new Map();
348
398
  for (const c of result) {
349
399
  if (!("attribute" in c)) continue;
350
400
  if (c.negated && c.value === void 0) negatedBooleanAttrs.add(c.attribute);
351
- if (!c.negated && c.value !== void 0) positiveValueByAttr.set(c.attribute, c.value);
401
+ const op = c.operator ?? "=";
402
+ if (!c.negated && c.value !== void 0 && op === "=") {
403
+ let values = positiveExactValuesByAttr.get(c.attribute);
404
+ if (!values) {
405
+ values = /* @__PURE__ */ new Set();
406
+ positiveExactValuesByAttr.set(c.attribute, values);
407
+ }
408
+ values.add(c.value);
409
+ }
352
410
  }
353
411
  result = result.filter((c) => {
354
412
  if (!("attribute" in c) || !c.negated || c.value === void 0) return true;
355
413
  if (negatedBooleanAttrs.has(c.attribute)) return false;
356
- const positiveValue = positiveValueByAttr.get(c.attribute);
357
- if (positiveValue !== void 0 && c.value !== positiveValue) return false;
414
+ if ((c.operator ?? "=") !== "=") return true;
415
+ const positiveValues = positiveExactValuesByAttr.get(c.attribute);
416
+ if (positiveValues !== void 0 && positiveValues.size === 1 && !positiveValues.has(c.value)) return false;
358
417
  return true;
359
418
  });
360
419
  return result;
@@ -396,6 +455,21 @@ function hasSelectorConditionContradiction(conditions) {
396
455
  return hasModifierContradiction(modifiers) || hasPseudoContradiction(pseudos);
397
456
  }
398
457
  /**
458
+ * Check for parent group contradiction: same target (direct + conditions)
459
+ * with opposite negation. E.g. :not([data-hovered] *) and :is([data-hovered] *)
460
+ * in the same variant is impossible.
461
+ */
462
+ function hasParentGroupContradiction(groups) {
463
+ const byBaseKey = /* @__PURE__ */ new Map();
464
+ for (const g of groups) {
465
+ const baseKey = `${g.direct ? ">" : ""}(${g.conditions.map(getSelectorConditionKey).sort().join(",")})`;
466
+ const existing = byBaseKey.get(baseKey);
467
+ if (existing !== void 0 && existing !== !g.negated) return true;
468
+ byBaseKey.set(baseKey, !g.negated);
469
+ }
470
+ return false;
471
+ }
472
+ /**
399
473
  * Merge two selector variants (AND operation)
400
474
  * Deduplicates conditions and checks for contradictions
401
475
  */
@@ -404,12 +478,11 @@ function mergeVariants(a, b) {
404
478
  if (hasMediaContradiction(mergedMedia)) return null;
405
479
  const mergedRoots = dedupeSelectorConditions([...a.rootConditions, ...b.rootConditions]);
406
480
  if (hasSelectorConditionContradiction(mergedRoots)) return null;
407
- const mergedModifiers = dedupeModifierConditions([...a.modifierConditions, ...b.modifierConditions]);
408
- if (hasModifierContradiction(mergedModifiers)) return null;
409
- const mergedPseudos = dedupePseudoConditions([...a.pseudoConditions, ...b.pseudoConditions]);
410
- if (hasPseudoContradiction(mergedPseudos)) return null;
411
- const mergedParents = dedupeSelectorConditions([...a.parentConditions, ...b.parentConditions]);
412
- if (hasSelectorConditionContradiction(mergedParents)) return null;
481
+ const mergedModifiers = dedupeSelectorConditions([...a.modifierConditions, ...b.modifierConditions]);
482
+ const mergedPseudos = dedupeSelectorConditions([...a.pseudoConditions, ...b.pseudoConditions]);
483
+ if (hasSelectorConditionContradiction([...mergedModifiers, ...mergedPseudos])) return null;
484
+ const mergedParentGroups = [...a.parentGroups, ...b.parentGroups];
485
+ if (hasParentGroupContradiction(mergedParentGroups)) return null;
413
486
  const mergedOwn = dedupeSelectorConditions([...a.ownConditions, ...b.ownConditions]);
414
487
  if (hasSelectorConditionContradiction(mergedOwn)) return null;
415
488
  const mergedContainers = dedupeContainerConditions([...a.containerConditions, ...b.containerConditions]);
@@ -424,55 +497,34 @@ function mergeVariants(a, b) {
424
497
  containerConditions: mergedContainers,
425
498
  supportsConditions: mergedSupports,
426
499
  rootConditions: mergedRoots,
427
- parentConditions: mergedParents,
428
- parentDirect: a.parentDirect || b.parentDirect,
500
+ parentGroups: mergedParentGroups,
429
501
  startingStyle: a.startingStyle || b.startingStyle
430
502
  };
431
503
  }
432
504
  /**
433
- * Deduplicate media conditions by their key (subtype + condition + negated)
505
+ * Generic deduplication by a key extraction function.
506
+ * Preserves insertion order, keeping the first occurrence of each key.
434
507
  */
435
- function dedupeMediaConditions(conditions) {
508
+ function dedupeByKey(items, getKey) {
436
509
  const seen = /* @__PURE__ */ new Set();
437
510
  const result = [];
438
- for (const c of conditions) {
439
- const key = `${c.subtype}|${c.condition}|${c.negated}`;
511
+ for (const item of items) {
512
+ const key = getKey(item);
440
513
  if (!seen.has(key)) {
441
514
  seen.add(key);
442
- result.push(c);
515
+ result.push(item);
443
516
  }
444
517
  }
445
518
  return result;
446
519
  }
447
- /**
448
- * Deduplicate container conditions by their key (name + condition + negated)
449
- */
520
+ function dedupeMediaConditions(conditions) {
521
+ return dedupeByKey(conditions, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
522
+ }
450
523
  function dedupeContainerConditions(conditions) {
451
- const seen = /* @__PURE__ */ new Set();
452
- const result = [];
453
- for (const c of conditions) {
454
- const key = `${c.name ?? ""}|${c.condition}|${c.negated}`;
455
- if (!seen.has(key)) {
456
- seen.add(key);
457
- result.push(c);
458
- }
459
- }
460
- return result;
524
+ return dedupeByKey(conditions, (c) => `${c.name ?? ""}|${c.condition}|${c.negated}`);
461
525
  }
462
- /**
463
- * Deduplicate supports conditions by their key (subtype + condition + negated)
464
- */
465
526
  function dedupeSupportsConditions(conditions) {
466
- const seen = /* @__PURE__ */ new Set();
467
- const result = [];
468
- for (const c of conditions) {
469
- const key = `${c.subtype}|${c.condition}|${c.negated}`;
470
- if (!seen.has(key)) {
471
- seen.add(key);
472
- result.push(c);
473
- }
474
- }
475
- return result;
527
+ return dedupeByKey(conditions, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
476
528
  }
477
529
  /**
478
530
  * Check if supports conditions contain contradictions
@@ -569,15 +621,20 @@ function hasContainerStyleContradiction(conditions) {
569
621
  }
570
622
  return false;
571
623
  }
624
+ const variantKeyCache = /* @__PURE__ */ new WeakMap();
572
625
  /**
573
- * Get a unique key for a variant (for deduplication)
626
+ * Get a unique key for a variant (for deduplication).
627
+ * Cached via WeakMap since variants are compared multiple times during
628
+ * deduplication and sorting.
574
629
  */
575
630
  function getVariantKey(v) {
631
+ const cached = variantKeyCache.get(v);
632
+ if (cached !== void 0) return cached;
576
633
  const modifierKey = v.modifierConditions.map(getModifierKey).sort().join("|");
577
634
  const pseudoKey = v.pseudoConditions.map(getPseudoKey).sort().join("|");
578
635
  const ownKey = v.ownConditions.map(getSelectorConditionKey).sort().join("|");
579
636
  const containerKey = v.containerConditions.map((c) => `${c.name ?? ""}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|");
580
- return [
637
+ const key = [
581
638
  modifierKey,
582
639
  pseudoKey,
583
640
  ownKey,
@@ -585,9 +642,11 @@ function getVariantKey(v) {
585
642
  containerKey,
586
643
  v.supportsConditions.map((c) => `${c.subtype}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|"),
587
644
  v.rootConditions.map(getSelectorConditionKey).sort().join("|"),
588
- v.parentConditions.map(getSelectorConditionKey).sort().join("|"),
645
+ v.parentGroups.map(getParentGroupKey).sort().join("|"),
589
646
  v.startingStyle ? "1" : "0"
590
647
  ].join("###");
648
+ variantKeyCache.set(v, key);
649
+ return key;
591
650
  }
592
651
  /**
593
652
  * Check if variant A is a superset of variant B (A is more restrictive)
@@ -609,66 +668,45 @@ function isVariantSuperset(a, b) {
609
668
  if (!isModifierConditionsSuperset(a.modifierConditions, b.modifierConditions)) return false;
610
669
  if (!isPseudoConditionsSuperset(a.pseudoConditions, b.pseudoConditions)) return false;
611
670
  if (!isSelectorConditionsSuperset(a.ownConditions, b.ownConditions)) return false;
612
- if (!isSelectorConditionsSuperset(a.parentConditions, b.parentConditions)) return false;
613
- return a.mediaConditions.length + a.containerConditions.length + a.supportsConditions.length + a.modifierConditions.length + a.pseudoConditions.length + a.rootConditions.length + a.parentConditions.length + a.ownConditions.length > b.mediaConditions.length + b.containerConditions.length + b.supportsConditions.length + b.modifierConditions.length + b.pseudoConditions.length + b.rootConditions.length + b.parentConditions.length + b.ownConditions.length;
671
+ if (!isParentGroupsSuperset(a.parentGroups, b.parentGroups)) return false;
672
+ const parentConditionCount = (groups) => groups.reduce((sum, g) => sum + g.conditions.length, 0);
673
+ 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;
614
674
  }
615
675
  /**
616
- * Check if media conditions A is a superset of B
676
+ * Generic superset check: true if every item in B has a matching key in A.
617
677
  */
678
+ function isConditionsSuperset(a, b, getKey) {
679
+ const aKeys = new Set(a.map(getKey));
680
+ return b.every((c) => aKeys.has(getKey(c)));
681
+ }
618
682
  function isMediaConditionsSuperset(a, b) {
619
- const aKeys = new Set(a.map((c) => `${c.subtype}|${c.condition}|${c.negated}`));
620
- for (const c of b) {
621
- const key = `${c.subtype}|${c.condition}|${c.negated}`;
622
- if (!aKeys.has(key)) return false;
623
- }
624
- return true;
683
+ return isConditionsSuperset(a, b, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
625
684
  }
626
- /**
627
- * Check if container conditions A is a superset of B
628
- */
629
685
  function isContainerConditionsSuperset(a, b) {
630
- const aKeys = new Set(a.map((c) => `${c.name ?? ""}|${c.condition}|${c.negated}`));
631
- for (const c of b) {
632
- const key = `${c.name ?? ""}|${c.condition}|${c.negated}`;
633
- if (!aKeys.has(key)) return false;
634
- }
635
- return true;
686
+ return isConditionsSuperset(a, b, (c) => `${c.name ?? ""}|${c.condition}|${c.negated}`);
636
687
  }
637
- /**
638
- * Check if supports conditions A is a superset of B
639
- */
640
688
  function isSupportsConditionsSuperset(a, b) {
641
- const aKeys = new Set(a.map((c) => `${c.subtype}|${c.condition}|${c.negated}`));
642
- for (const c of b) {
643
- const key = `${c.subtype}|${c.condition}|${c.negated}`;
644
- if (!aKeys.has(key)) return false;
645
- }
646
- return true;
689
+ return isConditionsSuperset(a, b, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
647
690
  }
648
- /**
649
- * Check if modifier conditions A is a superset of B
650
- */
651
691
  function isModifierConditionsSuperset(a, b) {
652
- const aKeys = new Set(a.map(getModifierKey));
653
- for (const c of b) if (!aKeys.has(getModifierKey(c))) return false;
654
- return true;
692
+ return isConditionsSuperset(a, b, getModifierKey);
655
693
  }
656
- /**
657
- * Check if pseudo conditions A is a superset of B
658
- */
659
694
  function isPseudoConditionsSuperset(a, b) {
660
- const aKeys = new Set(a.map(getPseudoKey));
661
- for (const c of b) if (!aKeys.has(getPseudoKey(c))) return false;
662
- return true;
695
+ return isConditionsSuperset(a, b, getPseudoKey);
696
+ }
697
+ function isSelectorConditionsSuperset(a, b) {
698
+ return isConditionsSuperset(a, b, getSelectorConditionKey);
663
699
  }
664
700
  /**
665
- * Check if selector conditions A is a superset of B.
666
- * Shared by root, parent, and own conditions.
701
+ * Check if parent groups A is a superset of B.
702
+ * Each group in B must have a matching group in A.
667
703
  */
668
- function isSelectorConditionsSuperset(a, b) {
669
- const aKeys = new Set(a.map(getSelectorConditionKey));
670
- for (const c of b) if (!aKeys.has(getSelectorConditionKey(c))) return false;
671
- return true;
704
+ function isParentGroupsSuperset(a, b) {
705
+ if (a.length < b.length) return false;
706
+ return isConditionsSuperset(a, b, getParentGroupKey);
707
+ }
708
+ function getParentGroupKey(g) {
709
+ return `${g.negated ? "!" : ""}${g.direct ? ">" : ""}(${g.conditions.map(getSelectorConditionKey).sort().join(",")})`;
672
710
  }
673
711
  /**
674
712
  * Deduplicate variants
@@ -687,9 +725,8 @@ function dedupeVariants(variants) {
687
725
  result.push(v);
688
726
  }
689
727
  }
690
- result.sort((a, b) => {
691
- return a.modifierConditions.length + a.pseudoConditions.length + a.ownConditions.length + a.mediaConditions.length + a.containerConditions.length + a.supportsConditions.length + a.rootConditions.length + a.parentConditions.length - (b.modifierConditions.length + b.pseudoConditions.length + b.ownConditions.length + b.mediaConditions.length + b.containerConditions.length + b.supportsConditions.length + b.rootConditions.length + b.parentConditions.length);
692
- });
728
+ const variantConditionCount = (v) => v.modifierConditions.length + v.pseudoConditions.length + v.ownConditions.length + v.mediaConditions.length + v.containerConditions.length + v.supportsConditions.length + v.rootConditions.length + v.parentGroups.reduce((sum, g) => sum + g.conditions.length, 0);
729
+ result.sort((a, b) => variantConditionCount(a) - variantConditionCount(b));
693
730
  const filtered = [];
694
731
  for (const candidate of result) {
695
732
  let isRedundant = false;
@@ -762,19 +799,6 @@ function orToCSS(children) {
762
799
  };
763
800
  }
764
801
  /**
765
- * Get a cache key for a condition
766
- */
767
- function getConditionKey(node) {
768
- if (node.kind === "true") return "TRUE";
769
- if (node.kind === "false") return "FALSE";
770
- if (node.kind === "state") return node.uniqueId;
771
- if (node.kind === "compound") {
772
- const childKeys = node.children.map(getConditionKey).sort();
773
- return `${node.operator}(${childKeys.join(",")})`;
774
- }
775
- return "UNKNOWN";
776
- }
777
- /**
778
802
  * Build at-rules array from a variant
779
803
  */
780
804
  function buildAtRulesFromVariant(variant) {
@@ -816,5 +840,5 @@ function buildAtRulesFromVariant(variant) {
816
840
  }
817
841
 
818
842
  //#endregion
819
- export { buildAtRulesFromVariant, conditionToCSS, modifierToCSS, parentConditionsToCSS, pseudoToCSS, rootConditionsToCSS, selectorConditionToCSS };
843
+ export { buildAtRulesFromVariant, conditionToCSS, modifierToCSS, parentGroupsToCSS, pseudoToCSS, rootConditionsToCSS, selectorConditionToCSS };
820
844
  //# sourceMappingURL=materialize.js.map