@tenphi/tasty 0.5.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +4 -3
  2. package/dist/debug.js +1 -1
  3. package/dist/debug.js.map +1 -1
  4. package/dist/pipeline/conditions.js +14 -8
  5. package/dist/pipeline/conditions.js.map +1 -1
  6. package/dist/pipeline/index.js +59 -40
  7. package/dist/pipeline/index.js.map +1 -1
  8. package/dist/pipeline/materialize.js +34 -98
  9. package/dist/pipeline/materialize.js.map +1 -1
  10. package/dist/pipeline/parseStateKey.js +17 -9
  11. package/dist/pipeline/parseStateKey.js.map +1 -1
  12. package/dist/pipeline/simplify.js +111 -152
  13. package/dist/pipeline/simplify.js.map +1 -1
  14. package/dist/pipeline/warnings.js +18 -0
  15. package/dist/pipeline/warnings.js.map +1 -0
  16. package/dist/styles/align.d.ts +1 -1
  17. package/dist/styles/align.js.map +1 -1
  18. package/dist/styles/border.d.ts +1 -1
  19. package/dist/styles/border.js.map +1 -1
  20. package/dist/styles/color.d.ts +2 -2
  21. package/dist/styles/color.js.map +1 -1
  22. package/dist/styles/createStyle.js +1 -1
  23. package/dist/styles/createStyle.js.map +1 -1
  24. package/dist/styles/fade.d.ts +1 -1
  25. package/dist/styles/fade.js.map +1 -1
  26. package/dist/styles/fill.d.ts +14 -16
  27. package/dist/styles/fill.js.map +1 -1
  28. package/dist/styles/flow.d.ts +3 -3
  29. package/dist/styles/flow.js.map +1 -1
  30. package/dist/styles/justify.d.ts +1 -1
  31. package/dist/styles/justify.js.map +1 -1
  32. package/dist/styles/predefined.js.map +1 -1
  33. package/dist/styles/radius.d.ts +1 -1
  34. package/dist/styles/radius.js.map +1 -1
  35. package/dist/styles/scrollbar.d.ts +1 -1
  36. package/dist/styles/scrollbar.js +19 -12
  37. package/dist/styles/scrollbar.js.map +1 -1
  38. package/dist/styles/shadow.d.ts +2 -2
  39. package/dist/styles/shadow.js.map +1 -1
  40. package/dist/styles/styledScrollbar.d.ts +1 -1
  41. package/dist/styles/styledScrollbar.js.map +1 -1
  42. package/dist/styles/transition.d.ts +1 -1
  43. package/dist/styles/transition.js.map +1 -1
  44. package/dist/tasty.js +16 -1
  45. package/dist/tasty.js.map +1 -1
  46. package/dist/utils/colors.d.ts +1 -1
  47. package/dist/utils/colors.js.map +1 -1
  48. package/dist/utils/dotize.d.ts +1 -1
  49. package/dist/utils/mod-attrs.js.map +1 -1
  50. package/dist/utils/string.js.map +1 -1
  51. package/dist/utils/styles.d.ts +7 -12
  52. package/dist/utils/styles.js +13 -8
  53. package/dist/utils/styles.js.map +1 -1
  54. package/package.json +47 -1
@@ -1,5 +1,5 @@
1
1
  import { Lru } from "../parser/lru.js";
2
- import { not } from "./conditions.js";
2
+ import { getConditionUniqueId, not } from "./conditions.js";
3
3
 
4
4
  //#region src/pipeline/materialize.ts
5
5
  /**
@@ -13,16 +13,13 @@ const conditionCache = new Lru(3e3);
13
13
  * Convert a condition tree to CSS components
14
14
  */
15
15
  function conditionToCSS(node) {
16
- const key = getConditionKey(node);
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: [],
@@ -505,49 +502,29 @@ function mergeVariants(a, b) {
505
502
  };
506
503
  }
507
504
  /**
508
- * 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.
509
507
  */
510
- function dedupeMediaConditions(conditions) {
508
+ function dedupeByKey(items, getKey) {
511
509
  const seen = /* @__PURE__ */ new Set();
512
510
  const result = [];
513
- for (const c of conditions) {
514
- const key = `${c.subtype}|${c.condition}|${c.negated}`;
511
+ for (const item of items) {
512
+ const key = getKey(item);
515
513
  if (!seen.has(key)) {
516
514
  seen.add(key);
517
- result.push(c);
515
+ result.push(item);
518
516
  }
519
517
  }
520
518
  return result;
521
519
  }
522
- /**
523
- * Deduplicate container conditions by their key (name + condition + negated)
524
- */
520
+ function dedupeMediaConditions(conditions) {
521
+ return dedupeByKey(conditions, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
522
+ }
525
523
  function dedupeContainerConditions(conditions) {
526
- const seen = /* @__PURE__ */ new Set();
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;
524
+ return dedupeByKey(conditions, (c) => `${c.name ?? ""}|${c.condition}|${c.negated}`);
536
525
  }
537
- /**
538
- * Deduplicate supports conditions by their key (subtype + condition + negated)
539
- */
540
526
  function dedupeSupportsConditions(conditions) {
541
- const seen = /* @__PURE__ */ new Set();
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;
527
+ return dedupeByKey(conditions, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
551
528
  }
552
529
  /**
553
530
  * Check if supports conditions contain contradictions
@@ -644,15 +621,20 @@ function hasContainerStyleContradiction(conditions) {
644
621
  }
645
622
  return false;
646
623
  }
624
+ const variantKeyCache = /* @__PURE__ */ new WeakMap();
647
625
  /**
648
- * 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.
649
629
  */
650
630
  function getVariantKey(v) {
631
+ const cached = variantKeyCache.get(v);
632
+ if (cached !== void 0) return cached;
651
633
  const modifierKey = v.modifierConditions.map(getModifierKey).sort().join("|");
652
634
  const pseudoKey = v.pseudoConditions.map(getPseudoKey).sort().join("|");
653
635
  const ownKey = v.ownConditions.map(getSelectorConditionKey).sort().join("|");
654
636
  const containerKey = v.containerConditions.map((c) => `${c.name ?? ""}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|");
655
- return [
637
+ const key = [
656
638
  modifierKey,
657
639
  pseudoKey,
658
640
  ownKey,
@@ -663,6 +645,8 @@ function getVariantKey(v) {
663
645
  v.parentGroups.map(getParentGroupKey).sort().join("|"),
664
646
  v.startingStyle ? "1" : "0"
665
647
  ].join("###");
648
+ variantKeyCache.set(v, key);
649
+ return key;
666
650
  }
667
651
  /**
668
652
  * Check if variant A is a superset of variant B (A is more restrictive)
@@ -689,62 +673,29 @@ function isVariantSuperset(a, b) {
689
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;
690
674
  }
691
675
  /**
692
- * 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.
693
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
+ }
694
682
  function isMediaConditionsSuperset(a, b) {
695
- const aKeys = new Set(a.map((c) => `${c.subtype}|${c.condition}|${c.negated}`));
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;
683
+ return isConditionsSuperset(a, b, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
701
684
  }
702
- /**
703
- * Check if container conditions A is a superset of B
704
- */
705
685
  function isContainerConditionsSuperset(a, b) {
706
- const aKeys = new Set(a.map((c) => `${c.name ?? ""}|${c.condition}|${c.negated}`));
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;
686
+ return isConditionsSuperset(a, b, (c) => `${c.name ?? ""}|${c.condition}|${c.negated}`);
712
687
  }
713
- /**
714
- * Check if supports conditions A is a superset of B
715
- */
716
688
  function isSupportsConditionsSuperset(a, b) {
717
- const aKeys = new Set(a.map((c) => `${c.subtype}|${c.condition}|${c.negated}`));
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;
689
+ return isConditionsSuperset(a, b, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
723
690
  }
724
- /**
725
- * Check if modifier conditions A is a superset of B
726
- */
727
691
  function isModifierConditionsSuperset(a, b) {
728
- const aKeys = new Set(a.map(getModifierKey));
729
- for (const c of b) if (!aKeys.has(getModifierKey(c))) return false;
730
- return true;
692
+ return isConditionsSuperset(a, b, getModifierKey);
731
693
  }
732
- /**
733
- * Check if pseudo conditions A is a superset of B
734
- */
735
694
  function isPseudoConditionsSuperset(a, b) {
736
- const aKeys = new Set(a.map(getPseudoKey));
737
- for (const c of b) if (!aKeys.has(getPseudoKey(c))) return false;
738
- return true;
695
+ return isConditionsSuperset(a, b, getPseudoKey);
739
696
  }
740
- /**
741
- * Check if selector conditions A is a superset of B.
742
- * Shared by root and own conditions.
743
- */
744
697
  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;
698
+ return isConditionsSuperset(a, b, getSelectorConditionKey);
748
699
  }
749
700
  /**
750
701
  * Check if parent groups A is a superset of B.
@@ -752,9 +703,7 @@ function isSelectorConditionsSuperset(a, b) {
752
703
  */
753
704
  function isParentGroupsSuperset(a, b) {
754
705
  if (a.length < b.length) return false;
755
- const aKeys = new Set(a.map(getParentGroupKey));
756
- for (const g of b) if (!aKeys.has(getParentGroupKey(g))) return false;
757
- return true;
706
+ return isConditionsSuperset(a, b, getParentGroupKey);
758
707
  }
759
708
  function getParentGroupKey(g) {
760
709
  return `${g.negated ? "!" : ""}${g.direct ? ">" : ""}(${g.conditions.map(getSelectorConditionKey).sort().join(",")})`;
@@ -850,19 +799,6 @@ function orToCSS(children) {
850
799
  };
851
800
  }
852
801
  /**
853
- * Get a cache key for a condition
854
- */
855
- function getConditionKey(node) {
856
- if (node.kind === "true") return "TRUE";
857
- if (node.kind === "false") return "FALSE";
858
- if (node.kind === "state") return node.uniqueId;
859
- if (node.kind === "compound") {
860
- const childKeys = node.children.map(getConditionKey).sort();
861
- return `${node.operator}(${childKeys.join(",")})`;
862
- }
863
- return "UNKNOWN";
864
- }
865
- /**
866
802
  * Build at-rules array from a variant
867
803
  */
868
804
  function buildAtRulesFromVariant(variant) {
@@ -1 +1 @@
1
- {"version":3,"file":"materialize.js","names":[],"sources":["../../src/pipeline/materialize.ts"],"sourcesContent":["/**\n * CSS Materialization\n *\n * Converts condition trees into CSS selectors and at-rules.\n * This is the final stage that produces actual CSS output.\n */\n\nimport { Lru } from '../parser/lru';\n\nimport type {\n ConditionNode,\n ContainerCondition,\n MediaCondition,\n ModifierCondition,\n PseudoCondition,\n StateCondition,\n SupportsCondition,\n} from './conditions';\nimport { not } from './conditions';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Parsed media condition for structured analysis and combination\n */\nexport interface ParsedMediaCondition {\n /** Subtype for structured analysis */\n subtype: 'dimension' | 'feature' | 'type';\n /** Whether this is a negated condition */\n negated: boolean;\n /** The condition part for CSS output (e.g., \"(width < 600px)\", \"print\") */\n condition: string;\n /** For dimension queries: dimension name */\n dimension?: 'width' | 'height' | 'inline-size' | 'block-size';\n /** For dimension queries: lower bound value */\n lowerBound?: {\n value: string;\n valueNumeric: number | null;\n inclusive: boolean;\n };\n /** For dimension queries: upper bound value */\n upperBound?: {\n value: string;\n valueNumeric: number | null;\n inclusive: boolean;\n };\n /** For feature queries: feature name */\n feature?: string;\n /** For feature queries: feature value */\n featureValue?: string;\n /** For type queries: media type */\n mediaType?: 'print' | 'screen' | 'all' | 'speech';\n}\n\n/**\n * Parsed container condition for structured analysis and combination\n */\nexport interface ParsedContainerCondition {\n /** Container name (undefined = unnamed/nearest container) */\n name?: string;\n /** The condition part (e.g., \"(width < 600px)\" or \"style(--variant: danger)\") */\n condition: string;\n /** Whether this is a negated condition */\n negated: boolean;\n /** Subtype for structured analysis */\n subtype: 'dimension' | 'style' | 'raw';\n /** For style queries: property name (without --) */\n property?: string;\n /** For style queries: property value (undefined = existence check) */\n propertyValue?: string;\n}\n\n/**\n * Parsed supports condition for structured analysis and combination\n */\nexport interface ParsedSupportsCondition {\n /** Subtype: 'feature' for property support, 'selector' for selector() support */\n subtype: 'feature' | 'selector';\n /** The condition string (e.g., \"display: grid\" or \":has(*)\") */\n condition: string;\n /** Whether this is a negated condition */\n negated: boolean;\n}\n\n/**\n * Parsed modifier condition for structured analysis\n */\nexport interface ParsedModifierCondition {\n /** Attribute name (e.g., 'data-hovered', 'data-size') */\n attribute: string;\n /** Value if present (e.g., 'large', 'danger') */\n value?: string;\n /** Operator for value matching (default '=') */\n operator?: '=' | '^=' | '$=' | '*=';\n /** Whether this is negated (:not(...)) */\n negated: boolean;\n}\n\n/**\n * Parsed pseudo-class condition for structured analysis\n */\nexport interface ParsedPseudoCondition {\n /** The pseudo-class (e.g., ':hover', ':focus-visible', ':has(> Icon)') */\n pseudo: string;\n /** Whether this is negated (:not(...)) */\n negated: boolean;\n}\n\n/** Modifier or pseudo condition (shared across own/root/parent) */\ntype ParsedSelectorCondition = ParsedModifierCondition | ParsedPseudoCondition;\n\n/**\n * A group of parent conditions originating from a single @parent() call.\n * Each group produces its own :is() wrapper in the final CSS.\n * Separate @parent() calls = separate groups = can match different ancestors.\n * @parent(a & b) = one group with two conditions = same ancestor must match both.\n */\nexport interface ParentGroup {\n conditions: ParsedSelectorCondition[];\n direct: boolean;\n negated: boolean;\n}\n\n/**\n * A single selector variant (one term in a DNF expression)\n */\nexport interface SelectorVariant {\n /** Structured modifier conditions */\n modifierConditions: ParsedModifierCondition[];\n\n /** Structured pseudo conditions */\n pseudoConditions: ParsedPseudoCondition[];\n\n /** Structured own conditions (for sub-element states) */\n ownConditions: ParsedSelectorCondition[];\n\n /** Parsed media conditions for structured combination */\n mediaConditions: ParsedMediaCondition[];\n\n /** Parsed container conditions for structured combination */\n containerConditions: ParsedContainerCondition[];\n\n /** Parsed supports conditions for @supports at-rules */\n supportsConditions: ParsedSupportsCondition[];\n\n /** Root conditions (modifier/pseudo applied to :root) */\n rootConditions: ParsedSelectorCondition[];\n\n /** Parent condition groups — each @parent() call is a separate group */\n parentGroups: ParentGroup[];\n\n /** Whether to wrap in @starting-style */\n startingStyle: boolean;\n}\n\n/**\n * CSS output components extracted from a condition\n * Supports multiple variants for OR conditions (DNF form)\n */\nexport interface CSSComponents {\n /** Selector variants - OR means multiple variants, AND means single variant with combined selectors */\n variants: SelectorVariant[];\n\n /** Whether condition is impossible (should skip) */\n isImpossible: boolean;\n}\n\n/**\n * Final CSS rule output\n */\nexport interface CSSRule {\n /** Single selector or array of selector fragments (for OR conditions) */\n selector: string | string[];\n declarations: string;\n atRules?: string[];\n rootPrefix?: string;\n}\n\n// ============================================================================\n// Caching\n// ============================================================================\n\nconst conditionCache = new Lru<string, CSSComponents>(3000);\n\n// ============================================================================\n// Main Functions\n// ============================================================================\n\n/**\n * Convert a condition tree to CSS components\n */\nexport function conditionToCSS(node: ConditionNode): CSSComponents {\n // Check cache\n const key = getConditionKey(node);\n const cached = conditionCache.get(key);\n if (cached) {\n return cached;\n }\n\n const result = conditionToCSSInner(node);\n\n // Cache result\n conditionCache.set(key, result);\n\n return result;\n}\n\n/**\n * Clear the condition cache (for testing)\n */\nexport function clearConditionCache(): void {\n conditionCache.clear();\n}\n\n// ============================================================================\n// Inner Implementation\n// ============================================================================\n\n/**\n * Create an empty selector variant\n */\nfunction emptyVariant(): SelectorVariant {\n return {\n modifierConditions: [],\n pseudoConditions: [],\n ownConditions: [],\n mediaConditions: [],\n containerConditions: [],\n supportsConditions: [],\n rootConditions: [],\n parentGroups: [],\n startingStyle: false,\n };\n}\n\nfunction conditionToCSSInner(node: ConditionNode): CSSComponents {\n // Base case: TRUE condition - single empty variant (matches everything)\n if (node.kind === 'true') {\n return {\n variants: [emptyVariant()],\n isImpossible: false,\n };\n }\n\n // Base case: FALSE condition - no variants (matches nothing)\n if (node.kind === 'false') {\n return {\n variants: [],\n isImpossible: true,\n };\n }\n\n // State condition\n if (node.kind === 'state') {\n return stateToCSS(node);\n }\n\n // Compound condition\n if (node.kind === 'compound') {\n if (node.operator === 'AND') {\n return andToCSS(node.children);\n } else {\n return orToCSS(node.children);\n }\n }\n\n // Fallback - single empty variant\n return {\n variants: [emptyVariant()],\n isImpossible: false,\n };\n}\n\n/**\n * Convert a state condition to CSS\n */\nfunction stateToCSS(state: StateCondition): CSSComponents {\n switch (state.type) {\n case 'media': {\n const mediaResults = mediaToParsed(state);\n const variants = mediaResults.map((mediaCond) => {\n const v = emptyVariant();\n v.mediaConditions.push(mediaCond);\n return v;\n });\n return { variants, isImpossible: false };\n }\n\n case 'root':\n return innerConditionToVariants(\n state.innerCondition,\n state.negated ?? false,\n 'rootConditions',\n );\n\n case 'parent':\n return parentConditionToVariants(\n state.innerCondition,\n state.negated ?? false,\n state.direct,\n );\n\n case 'own':\n return innerConditionToVariants(\n state.innerCondition,\n state.negated ?? false,\n 'ownConditions',\n );\n\n case 'modifier': {\n const v = emptyVariant();\n v.modifierConditions.push(modifierToParsed(state));\n return { variants: [v], isImpossible: false };\n }\n\n case 'pseudo': {\n const v = emptyVariant();\n v.pseudoConditions.push(pseudoToParsed(state));\n return { variants: [v], isImpossible: false };\n }\n\n case 'container': {\n const v = emptyVariant();\n v.containerConditions.push(containerToParsed(state));\n return { variants: [v], isImpossible: false };\n }\n\n case 'supports': {\n const v = emptyVariant();\n v.supportsConditions.push(supportsToParsed(state));\n return { variants: [v], isImpossible: false };\n }\n\n case 'starting': {\n const v = emptyVariant();\n v.startingStyle = !state.negated;\n return { variants: [v], isImpossible: false };\n }\n }\n}\n\n/**\n * Convert modifier condition to parsed structure\n */\nfunction modifierToParsed(state: ModifierCondition): ParsedModifierCondition {\n return {\n attribute: state.attribute,\n value: state.value,\n operator: state.operator,\n negated: state.negated ?? false,\n };\n}\n\n/**\n * Convert parsed modifier to CSS selector string (for final output)\n */\nexport function modifierToCSS(mod: ParsedModifierCondition): string {\n let selector: string;\n\n if (mod.value !== undefined) {\n // Value attribute: [data-attr=\"value\"]\n const op = mod.operator || '=';\n selector = `[${mod.attribute}${op}\"${mod.value}\"]`;\n } else {\n // Boolean attribute: [data-attr]\n selector = `[${mod.attribute}]`;\n }\n\n if (mod.negated) {\n return `:not(${selector})`;\n }\n return selector;\n}\n\n/**\n * Convert pseudo condition to parsed structure\n */\nfunction pseudoToParsed(state: PseudoCondition): ParsedPseudoCondition {\n return {\n pseudo: state.pseudo,\n negated: state.negated ?? false,\n };\n}\n\n/**\n * Convert parsed pseudo to CSS selector string (for final output)\n */\nexport function pseudoToCSS(pseudo: ParsedPseudoCondition): string {\n if (pseudo.negated) {\n // Wrap in :not() if not already\n if (pseudo.pseudo.startsWith(':not(')) {\n // Double negation - remove :not()\n return pseudo.pseudo.slice(5, -1);\n }\n return `:not(${pseudo.pseudo})`;\n }\n return pseudo.pseudo;\n}\n\n/**\n * Convert media condition to parsed structure(s)\n * Returns an array because negated ranges produce OR branches (two separate conditions)\n */\nfunction mediaToParsed(state: MediaCondition): ParsedMediaCondition[] {\n if (state.subtype === 'type') {\n // @media:print → @media print (or @media not print)\n const mediaType = state.mediaType || 'all';\n return [\n {\n subtype: 'type',\n negated: state.negated ?? false,\n condition: mediaType,\n mediaType: state.mediaType,\n },\n ];\n } else if (state.subtype === 'feature') {\n // @media(prefers-contrast: high) → @media (prefers-contrast: high)\n let condition: string;\n if (state.featureValue) {\n condition = `(${state.feature}: ${state.featureValue})`;\n } else {\n condition = `(${state.feature})`;\n }\n return [\n {\n subtype: 'feature',\n negated: state.negated ?? false,\n condition,\n feature: state.feature,\n featureValue: state.featureValue,\n },\n ];\n } else {\n // Dimension query - negation is handled by inverting the condition\n // because \"not (width < x)\" doesn't work reliably in browsers\n return dimensionToMediaParsed(\n state.dimension || 'width',\n state.lowerBound,\n state.upperBound,\n state.negated ?? false,\n );\n }\n}\n\n/**\n * Convert dimension bounds to parsed media condition(s)\n * Uses CSS Media Queries Level 4 `not (condition)` syntax for negation.\n */\nfunction dimensionToMediaParsed(\n dimension: 'width' | 'height' | 'inline-size' | 'block-size',\n lowerBound?: {\n value: string;\n valueNumeric: number | null;\n inclusive: boolean;\n },\n upperBound?: {\n value: string;\n valueNumeric: number | null;\n inclusive: boolean;\n },\n negated?: boolean,\n): ParsedMediaCondition[] {\n // Build the condition string\n let condition: string;\n if (lowerBound && upperBound) {\n const lowerOp = lowerBound.inclusive ? '<=' : '<';\n const upperOp = upperBound.inclusive ? '<=' : '<';\n condition = `(${lowerBound.value} ${lowerOp} ${dimension} ${upperOp} ${upperBound.value})`;\n } else if (upperBound) {\n const op = upperBound.inclusive ? '<=' : '<';\n condition = `(${dimension} ${op} ${upperBound.value})`;\n } else if (lowerBound) {\n const op = lowerBound.inclusive ? '>=' : '>';\n condition = `(${dimension} ${op} ${lowerBound.value})`;\n } else {\n condition = `(${dimension})`;\n }\n\n // For negation, we use CSS `not (condition)` syntax in buildAtRulesFromVariant\n return [\n {\n subtype: 'dimension',\n negated: negated ?? false,\n condition,\n dimension,\n lowerBound,\n upperBound,\n },\n ];\n}\n\n/**\n * Convert container condition to parsed structure\n * This enables structured analysis for contradiction detection and condition combining\n */\nfunction containerToParsed(\n state: ContainerCondition,\n): ParsedContainerCondition {\n let condition: string;\n\n if (state.subtype === 'style') {\n // Style query: style(--prop: value)\n if (state.propertyValue) {\n condition = `style(--${state.property}: ${state.propertyValue})`;\n } else {\n condition = `style(--${state.property})`;\n }\n } else if (state.subtype === 'raw') {\n // Raw function query: passed through verbatim (e.g., scroll-state(stuck: top))\n condition = state.rawCondition!;\n } else {\n // Dimension query\n condition = dimensionToContainerCondition(\n state.dimension || 'width',\n state.lowerBound,\n state.upperBound,\n );\n }\n\n return {\n name: state.containerName,\n condition,\n negated: state.negated ?? false,\n subtype: state.subtype,\n property: state.property,\n propertyValue: state.propertyValue,\n };\n}\n\n/**\n * Convert dimension bounds to container query condition (single string)\n * Container queries support \"not (condition)\", so no need to invert manually\n */\nfunction dimensionToContainerCondition(\n dimension: string,\n lowerBound?: { value: string; inclusive: boolean },\n upperBound?: { value: string; inclusive: boolean },\n): string {\n if (lowerBound && upperBound) {\n const lowerOp = lowerBound.inclusive ? '<=' : '<';\n const upperOp = upperBound.inclusive ? '<=' : '<';\n return `(${lowerBound.value} ${lowerOp} ${dimension} ${upperOp} ${upperBound.value})`;\n } else if (upperBound) {\n const op = upperBound.inclusive ? '<=' : '<';\n return `(${dimension} ${op} ${upperBound.value})`;\n } else if (lowerBound) {\n const op = lowerBound.inclusive ? '>=' : '>';\n return `(${dimension} ${op} ${lowerBound.value})`;\n }\n return '(width)'; // Fallback\n}\n\n/**\n * Convert supports condition to parsed structure\n */\nfunction supportsToParsed(state: SupportsCondition): ParsedSupportsCondition {\n return {\n subtype: state.subtype,\n condition: state.condition,\n negated: state.negated ?? false,\n };\n}\n\n/**\n * Collect all modifier and pseudo conditions from a variant as a flat array.\n */\nfunction collectSelectorConditions(\n variant: SelectorVariant,\n): ParsedSelectorCondition[] {\n return [...variant.modifierConditions, ...variant.pseudoConditions];\n}\n\n/**\n * Convert an inner condition tree into SelectorVariants.\n * Each inner OR branch becomes a separate variant, preserving disjunction.\n * Shared by @root() and @own().\n */\nfunction innerConditionToVariants(\n innerCondition: ConditionNode,\n negated: boolean,\n target: 'rootConditions' | 'ownConditions',\n): CSSComponents {\n // For @root/@own, negation is applied upfront via De Morgan: !(A | B) = !A & !B.\n // This is safe because the negated conditions are appended directly to the same\n // selector (e.g. :root:not([a]):not([b])), so collapsing OR branches is correct.\n //\n // @parent uses a different strategy (parentConditionToVariants) because each OR\n // branch must become its own :not(... *) wrapper — the * combinator scopes to a\n // specific ancestor, so branches cannot be merged into one selector.\n const effectiveCondition = negated ? not(innerCondition) : innerCondition;\n const innerCSS = conditionToCSS(effectiveCondition);\n\n if (innerCSS.isImpossible || innerCSS.variants.length === 0) {\n return { variants: [], isImpossible: true };\n }\n\n const variants: SelectorVariant[] = [];\n\n for (const innerVariant of innerCSS.variants) {\n const conditions = collectSelectorConditions(innerVariant);\n\n if (conditions.length > 0) {\n const v = emptyVariant();\n v[target].push(...conditions);\n variants.push(v);\n }\n }\n\n if (variants.length === 0) {\n return { variants: [emptyVariant()], isImpossible: false };\n }\n\n return { variants, isImpossible: false };\n}\n\n/**\n * Convert a @parent() inner condition into SelectorVariants with ParentGroups.\n *\n * Positive: each inner OR branch becomes a separate variant with one :is() group.\n * Negated: !(A | B) = !A & !B — all branches become :not() groups collected\n * into a single variant so they produce :not([a] *):not([b] *) on one element.\n */\nfunction parentConditionToVariants(\n innerCondition: ConditionNode,\n negated: boolean,\n direct: boolean,\n): CSSComponents {\n const innerCSS = conditionToCSS(innerCondition);\n\n if (innerCSS.isImpossible || innerCSS.variants.length === 0) {\n return { variants: [], isImpossible: true };\n }\n\n if (negated) {\n // Collect all OR branches into one variant as separate :not() groups.\n const v = emptyVariant();\n\n for (const innerVariant of innerCSS.variants) {\n const conditions = collectSelectorConditions(innerVariant);\n\n if (conditions.length > 0) {\n v.parentGroups.push({ conditions, direct, negated: true });\n }\n }\n\n if (v.parentGroups.length === 0) {\n return { variants: [emptyVariant()], isImpossible: false };\n }\n\n return { variants: [v], isImpossible: false };\n }\n\n // Positive: each OR branch is a separate variant\n const variants: SelectorVariant[] = [];\n\n for (const innerVariant of innerCSS.variants) {\n const conditions = collectSelectorConditions(innerVariant);\n\n if (conditions.length > 0) {\n const v = emptyVariant();\n v.parentGroups.push({ conditions, direct, negated: false });\n variants.push(v);\n }\n }\n\n if (variants.length === 0) {\n return { variants: [emptyVariant()], isImpossible: false };\n }\n\n return { variants, isImpossible: false };\n}\n\n/**\n * Convert parsed root conditions to CSS selector prefix (for final output)\n */\nexport function rootConditionsToCSS(\n roots: ParsedSelectorCondition[],\n): string | undefined {\n if (roots.length === 0) return undefined;\n\n let prefix = ':root';\n for (const cond of roots) {\n prefix += selectorConditionToCSS(cond);\n }\n return prefix;\n}\n\n/**\n * Convert parent groups to CSS selector fragments (for final output).\n * Each group produces its own :is() wrapper.\n */\nexport function parentGroupsToCSS(groups: ParentGroup[]): string {\n let result = '';\n for (const group of groups) {\n const combinator = group.direct ? ' > *' : ' *';\n let parts = '';\n for (const cond of group.conditions) {\n parts += selectorConditionToCSS(cond);\n }\n const wrapper = group.negated ? ':not' : ':is';\n result += `${wrapper}(${parts}${combinator})`;\n }\n return result;\n}\n\n/**\n * Convert a modifier or pseudo condition to a CSS selector fragment\n */\nexport function selectorConditionToCSS(cond: ParsedSelectorCondition): string {\n if ('attribute' in cond) {\n return modifierToCSS(cond);\n }\n return pseudoToCSS(cond);\n}\n\n/**\n * Get unique key for a modifier condition\n */\nfunction getModifierKey(mod: ParsedModifierCondition): string {\n const base = mod.value\n ? `${mod.attribute}${mod.operator || '='}${mod.value}`\n : mod.attribute;\n return mod.negated ? `!${base}` : base;\n}\n\n/**\n * Get unique key for a pseudo condition\n */\nfunction getPseudoKey(pseudo: ParsedPseudoCondition): string {\n return pseudo.negated ? `!${pseudo.pseudo}` : pseudo.pseudo;\n}\n\n/**\n * Get unique key for any selector condition (modifier or pseudo)\n */\nfunction getSelectorConditionKey(cond: ParsedSelectorCondition): string {\n return 'attribute' in cond\n ? `mod:${getModifierKey(cond)}`\n : `pseudo:${getPseudoKey(cond)}`;\n}\n\n/**\n * Deduplicate selector conditions (modifiers or pseudos).\n * Shared by root, parent, and own conditions.\n */\nfunction dedupeSelectorConditions(\n conditions: ParsedSelectorCondition[],\n): ParsedSelectorCondition[] {\n // Pass 1: exact-key dedup\n const seen = new Set<string>();\n let result: ParsedSelectorCondition[] = [];\n for (const c of conditions) {\n const key = getSelectorConditionKey(c);\n if (!seen.has(key)) {\n seen.add(key);\n result.push(c);\n }\n }\n\n // Pass 2: remove negated value modifiers subsumed by other modifiers.\n // :not([data-attr]) subsumes :not([data-attr=\"value\"])\n // [data-attr=\"X\"] implies :not([data-attr=\"Y\"]) is redundant\n // This implication only holds for exact-match (=) operators; substring\n // operators (^=, $=, *=) don't imply exclusivity between values.\n const negatedBooleanAttrs = new Set<string>();\n const positiveExactValuesByAttr = new Map<string, Set<string>>();\n\n for (const c of result) {\n if (!('attribute' in c)) continue;\n if (c.negated && c.value === undefined) {\n negatedBooleanAttrs.add(c.attribute);\n }\n const op = c.operator ?? '=';\n if (!c.negated && c.value !== undefined && op === '=') {\n let values = positiveExactValuesByAttr.get(c.attribute);\n if (!values) {\n values = new Set();\n positiveExactValuesByAttr.set(c.attribute, values);\n }\n values.add(c.value);\n }\n }\n\n result = result.filter((c) => {\n if (!('attribute' in c) || !c.negated || c.value === undefined) {\n return true;\n }\n if (negatedBooleanAttrs.has(c.attribute)) {\n return false;\n }\n const op = c.operator ?? '=';\n if (op !== '=') return true;\n const positiveValues = positiveExactValuesByAttr.get(c.attribute);\n if (\n positiveValues !== undefined &&\n positiveValues.size === 1 &&\n !positiveValues.has(c.value)\n ) {\n return false;\n }\n return true;\n });\n\n return result;\n}\n\n/**\n * Check for modifier contradiction: same attribute with opposite negation\n */\nfunction hasModifierContradiction(\n conditions: ParsedModifierCondition[],\n): boolean {\n const byKey = new Map<string, boolean>(); // base key -> isPositive\n\n for (const mod of conditions) {\n const baseKey = mod.value\n ? `${mod.attribute}${mod.operator || '='}${mod.value}`\n : mod.attribute;\n const existing = byKey.get(baseKey);\n if (existing !== undefined && existing !== !mod.negated) {\n return true; // Same attribute with opposite negation\n }\n byKey.set(baseKey, !mod.negated);\n }\n return false;\n}\n\n/**\n * Check for pseudo contradiction: same pseudo with opposite negation\n */\nfunction hasPseudoContradiction(conditions: ParsedPseudoCondition[]): boolean {\n const byKey = new Map<string, boolean>(); // pseudo -> isPositive\n\n for (const pseudo of conditions) {\n const existing = byKey.get(pseudo.pseudo);\n if (existing !== undefined && existing !== !pseudo.negated) {\n return true; // Same pseudo with opposite negation\n }\n byKey.set(pseudo.pseudo, !pseudo.negated);\n }\n return false;\n}\n\n/**\n * Check for selector condition contradiction (modifier or pseudo with opposite negation).\n * Shared by root, parent, and own conditions.\n */\nfunction hasSelectorConditionContradiction(\n conditions: ParsedSelectorCondition[],\n): boolean {\n const modifiers: ParsedModifierCondition[] = [];\n const pseudos: ParsedPseudoCondition[] = [];\n\n for (const c of conditions) {\n if ('attribute' in c) {\n modifiers.push(c);\n } else {\n pseudos.push(c);\n }\n }\n\n return hasModifierContradiction(modifiers) || hasPseudoContradiction(pseudos);\n}\n\n/**\n * Check for parent group contradiction: same target (direct + conditions)\n * with opposite negation. E.g. :not([data-hovered] *) and :is([data-hovered] *)\n * in the same variant is impossible.\n */\nfunction hasParentGroupContradiction(groups: ParentGroup[]): boolean {\n const byBaseKey = new Map<string, boolean>();\n\n for (const g of groups) {\n const baseKey = `${g.direct ? '>' : ''}(${g.conditions.map(getSelectorConditionKey).sort().join(',')})`;\n const existing = byBaseKey.get(baseKey);\n if (existing !== undefined && existing !== !g.negated) {\n return true;\n }\n byBaseKey.set(baseKey, !g.negated);\n }\n return false;\n}\n\n/**\n * Merge two selector variants (AND operation)\n * Deduplicates conditions and checks for contradictions\n */\nfunction mergeVariants(\n a: SelectorVariant,\n b: SelectorVariant,\n): SelectorVariant | null {\n // Merge media conditions and check for contradictions\n const mergedMedia = dedupeMediaConditions([\n ...a.mediaConditions,\n ...b.mediaConditions,\n ]);\n if (hasMediaContradiction(mergedMedia)) {\n return null; // Impossible variant\n }\n\n // Merge root conditions and check for contradictions\n const mergedRoots = dedupeSelectorConditions([\n ...a.rootConditions,\n ...b.rootConditions,\n ]);\n if (hasSelectorConditionContradiction(mergedRoots)) {\n return null; // Impossible variant\n }\n\n // Merge modifier and pseudo conditions separately, then cross-check\n const mergedModifiers = dedupeSelectorConditions([\n ...a.modifierConditions,\n ...b.modifierConditions,\n ]) as ParsedModifierCondition[];\n const mergedPseudos = dedupeSelectorConditions([\n ...a.pseudoConditions,\n ...b.pseudoConditions,\n ]) as ParsedPseudoCondition[];\n if (\n hasSelectorConditionContradiction([...mergedModifiers, ...mergedPseudos])\n ) {\n return null; // Impossible variant\n }\n\n // Concatenate parent groups (each group is an independent :is() wrapper)\n const mergedParentGroups = [...a.parentGroups, ...b.parentGroups];\n if (hasParentGroupContradiction(mergedParentGroups)) {\n return null; // Impossible variant\n }\n\n // Merge own conditions and check for contradictions\n const mergedOwn = dedupeSelectorConditions([\n ...a.ownConditions,\n ...b.ownConditions,\n ]);\n if (hasSelectorConditionContradiction(mergedOwn)) {\n return null; // Impossible variant\n }\n\n // Merge container conditions and check for contradictions\n const mergedContainers = dedupeContainerConditions([\n ...a.containerConditions,\n ...b.containerConditions,\n ]);\n if (hasContainerStyleContradiction(mergedContainers)) {\n return null; // Impossible variant\n }\n\n // Merge supports conditions and check for contradictions\n const mergedSupports = dedupeSupportsConditions([\n ...a.supportsConditions,\n ...b.supportsConditions,\n ]);\n if (hasSupportsContradiction(mergedSupports)) {\n return null; // Impossible variant\n }\n\n return {\n modifierConditions: mergedModifiers,\n pseudoConditions: mergedPseudos,\n ownConditions: mergedOwn,\n mediaConditions: mergedMedia,\n containerConditions: mergedContainers,\n supportsConditions: mergedSupports,\n rootConditions: mergedRoots,\n parentGroups: mergedParentGroups,\n startingStyle: a.startingStyle || b.startingStyle,\n };\n}\n\n/**\n * Deduplicate media conditions by their key (subtype + condition + negated)\n */\nfunction dedupeMediaConditions(\n conditions: ParsedMediaCondition[],\n): ParsedMediaCondition[] {\n const seen = new Set<string>();\n const result: ParsedMediaCondition[] = [];\n for (const c of conditions) {\n const key = `${c.subtype}|${c.condition}|${c.negated}`;\n if (!seen.has(key)) {\n seen.add(key);\n result.push(c);\n }\n }\n return result;\n}\n\n/**\n * Deduplicate container conditions by their key (name + condition + negated)\n */\nfunction dedupeContainerConditions(\n conditions: ParsedContainerCondition[],\n): ParsedContainerCondition[] {\n const seen = new Set<string>();\n const result: ParsedContainerCondition[] = [];\n for (const c of conditions) {\n const key = `${c.name ?? ''}|${c.condition}|${c.negated}`;\n if (!seen.has(key)) {\n seen.add(key);\n result.push(c);\n }\n }\n return result;\n}\n\n/**\n * Deduplicate supports conditions by their key (subtype + condition + negated)\n */\nfunction dedupeSupportsConditions(\n conditions: ParsedSupportsCondition[],\n): ParsedSupportsCondition[] {\n const seen = new Set<string>();\n const result: ParsedSupportsCondition[] = [];\n for (const c of conditions) {\n const key = `${c.subtype}|${c.condition}|${c.negated}`;\n if (!seen.has(key)) {\n seen.add(key);\n result.push(c);\n }\n }\n return result;\n}\n\n/**\n * Check if supports conditions contain contradictions\n * e.g., @supports(display: grid) AND NOT @supports(display: grid)\n */\nfunction hasSupportsContradiction(\n conditions: ParsedSupportsCondition[],\n): boolean {\n const conditionMap = new Map<string, boolean>(); // key -> isPositive\n\n for (const cond of conditions) {\n const key = `${cond.subtype}|${cond.condition}`;\n const existing = conditionMap.get(key);\n if (existing !== undefined && existing !== !cond.negated) {\n return true; // Contradiction: positive AND negated\n }\n conditionMap.set(key, !cond.negated);\n }\n\n return false;\n}\n\n/**\n * Check if a set of media conditions contains contradictions\n * e.g., (prefers-color-scheme: light) AND NOT (prefers-color-scheme: light)\n * or (width >= 900px) AND (width < 600px)\n *\n * Uses parsed media conditions for efficient analysis without regex parsing.\n */\nfunction hasMediaContradiction(conditions: ParsedMediaCondition[]): boolean {\n // Track conditions by their key (condition string) to detect A and NOT A\n const featureConditions = new Map<string, boolean>(); // key -> isPositive\n const typeConditions = new Map<string, boolean>(); // mediaType -> isPositive\n const dimensionConditions = new Map<string, boolean>(); // condition -> isPositive\n\n // Track dimension conditions for range contradiction detection (non-negated only)\n const dimensionsByDim = new Map<\n string,\n { lowerBound: number | null; upperBound: number | null }\n >();\n\n for (const cond of conditions) {\n if (cond.subtype === 'type') {\n // Type query: check for direct contradiction (print AND NOT print)\n const key = cond.mediaType || 'all';\n const existing = typeConditions.get(key);\n if (existing !== undefined && existing !== !cond.negated) {\n return true; // Contradiction: positive AND negated\n }\n typeConditions.set(key, !cond.negated);\n } else if (cond.subtype === 'feature') {\n // Feature query: check for direct contradiction\n const key = cond.condition;\n const existing = featureConditions.get(key);\n if (existing !== undefined && existing !== !cond.negated) {\n return true; // Contradiction: positive AND negated\n }\n featureConditions.set(key, !cond.negated);\n } else if (cond.subtype === 'dimension') {\n // First, check for direct contradiction: (width < 600px) AND NOT (width < 600px)\n const condKey = cond.condition;\n const existing = dimensionConditions.get(condKey);\n if (existing !== undefined && existing !== !cond.negated) {\n return true; // Contradiction: positive AND negated\n }\n dimensionConditions.set(condKey, !cond.negated);\n\n // For range analysis, only consider non-negated conditions\n // Negated conditions are handled via the direct contradiction check above\n if (!cond.negated) {\n const dim = cond.dimension || 'width';\n let bounds = dimensionsByDim.get(dim);\n if (!bounds) {\n bounds = { lowerBound: null, upperBound: null };\n dimensionsByDim.set(dim, bounds);\n }\n\n // Track the effective bounds\n if (cond.lowerBound?.valueNumeric != null) {\n const value = cond.lowerBound.valueNumeric;\n if (bounds.lowerBound === null || value > bounds.lowerBound) {\n bounds.lowerBound = value;\n }\n }\n if (cond.upperBound?.valueNumeric != null) {\n const value = cond.upperBound.valueNumeric;\n if (bounds.upperBound === null || value < bounds.upperBound) {\n bounds.upperBound = value;\n }\n }\n\n // Check for impossible range\n if (\n bounds.lowerBound !== null &&\n bounds.upperBound !== null &&\n bounds.lowerBound >= bounds.upperBound\n ) {\n return true;\n }\n }\n }\n }\n\n return false;\n}\n\n/**\n * Check if container conditions contain contradictions in style queries\n * e.g., style(--variant: danger) and style(--variant: success) together\n * Same property with different values = always false\n *\n * Uses parsed container conditions for efficient analysis without regex parsing.\n */\nfunction hasContainerStyleContradiction(\n conditions: ParsedContainerCondition[],\n): boolean {\n // Track style queries by property name\n // key: property name, value: { hasExistence: boolean, values: Set<string>, hasNegatedExistence: boolean }\n const styleQueries = new Map<\n string,\n { hasExistence: boolean; values: Set<string>; hasNegatedExistence: boolean }\n >();\n\n for (const cond of conditions) {\n // Only analyze style queries\n if (cond.subtype !== 'style' || !cond.property) {\n continue;\n }\n\n const property = cond.property;\n const value = cond.propertyValue;\n\n if (!styleQueries.has(property)) {\n styleQueries.set(property, {\n hasExistence: false,\n values: new Set(),\n hasNegatedExistence: false,\n });\n }\n\n const entry = styleQueries.get(property)!;\n\n if (cond.negated) {\n if (value === undefined) {\n // not style(--prop) - negated existence check\n entry.hasNegatedExistence = true;\n }\n // Negated value checks don't contradict positive value checks directly\n // They just mean \"not this value\"\n } else {\n if (value === undefined) {\n // style(--prop) - existence check\n entry.hasExistence = true;\n } else {\n // style(--prop: value) - value check\n entry.values.add(value);\n }\n }\n }\n\n // Check for contradictions\n for (const [, entry] of styleQueries) {\n // Contradiction: existence check + negated existence check\n if (entry.hasExistence && entry.hasNegatedExistence) {\n return true;\n }\n\n // Contradiction: multiple different values for same property\n // style(--variant: danger) AND style(--variant: success) is impossible\n if (entry.values.size > 1) {\n return true;\n }\n\n // Contradiction: negated existence + value check\n // not style(--variant) AND style(--variant: danger) is impossible\n if (entry.hasNegatedExistence && entry.values.size > 0) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Get a unique key for a variant (for deduplication)\n */\nfunction getVariantKey(v: SelectorVariant): string {\n const modifierKey = v.modifierConditions.map(getModifierKey).sort().join('|');\n const pseudoKey = v.pseudoConditions.map(getPseudoKey).sort().join('|');\n const ownKey = v.ownConditions.map(getSelectorConditionKey).sort().join('|');\n const containerKey = v.containerConditions\n .map((c) => `${c.name ?? ''}:${c.negated ? '!' : ''}${c.condition}`)\n .sort()\n .join('|');\n const mediaKey = v.mediaConditions\n .map((c) => `${c.subtype}:${c.negated ? '!' : ''}${c.condition}`)\n .sort()\n .join('|');\n const supportsKey = v.supportsConditions\n .map((c) => `${c.subtype}:${c.negated ? '!' : ''}${c.condition}`)\n .sort()\n .join('|');\n const rootKey = v.rootConditions\n .map(getSelectorConditionKey)\n .sort()\n .join('|');\n const parentKey = v.parentGroups.map(getParentGroupKey).sort().join('|');\n return [\n modifierKey,\n pseudoKey,\n ownKey,\n mediaKey,\n containerKey,\n supportsKey,\n rootKey,\n parentKey,\n v.startingStyle ? '1' : '0',\n ].join('###');\n}\n\n/**\n * Check if variant A is a superset of variant B (A is more restrictive)\n *\n * If A has all of B's conditions plus more, then A is redundant\n * because B already covers the same cases (and more).\n *\n * Example:\n * A: :not([size=large]):not([size=medium]):not([size=small])\n * B: :not([size=large])\n * A is a superset of B, so A is redundant when B exists.\n */\nfunction isVariantSuperset(a: SelectorVariant, b: SelectorVariant): boolean {\n // Must have same context\n if (a.startingStyle !== b.startingStyle) return false;\n\n // Check if a.rootConditions is superset of b.rootConditions\n if (!isSelectorConditionsSuperset(a.rootConditions, b.rootConditions))\n return false;\n\n // Check if a.mediaConditions is superset of b.mediaConditions\n if (!isMediaConditionsSuperset(a.mediaConditions, b.mediaConditions))\n return false;\n\n // Check if a.containerConditions is superset of b.containerConditions\n if (\n !isContainerConditionsSuperset(a.containerConditions, b.containerConditions)\n )\n return false;\n\n // Check if a.supportsConditions is superset of b.supportsConditions\n if (!isSupportsConditionsSuperset(a.supportsConditions, b.supportsConditions))\n return false;\n\n // Check if a.modifierConditions is superset of b.modifierConditions\n if (!isModifierConditionsSuperset(a.modifierConditions, b.modifierConditions))\n return false;\n\n // Check if a.pseudoConditions is superset of b.pseudoConditions\n if (!isPseudoConditionsSuperset(a.pseudoConditions, b.pseudoConditions))\n return false;\n\n // Check if a.ownConditions is superset of b.ownConditions\n if (!isSelectorConditionsSuperset(a.ownConditions, b.ownConditions))\n return false;\n\n // Check if a.parentGroups is superset of b.parentGroups\n if (!isParentGroupsSuperset(a.parentGroups, b.parentGroups)) return false;\n\n // A is a superset if it has all of B's items (possibly more)\n // and at least one category has strictly more items\n const parentConditionCount = (groups: ParentGroup[]) =>\n groups.reduce((sum, g) => sum + g.conditions.length, 0);\n const aTotal =\n a.mediaConditions.length +\n a.containerConditions.length +\n a.supportsConditions.length +\n a.modifierConditions.length +\n a.pseudoConditions.length +\n a.rootConditions.length +\n parentConditionCount(a.parentGroups) +\n a.ownConditions.length;\n const bTotal =\n b.mediaConditions.length +\n b.containerConditions.length +\n b.supportsConditions.length +\n b.modifierConditions.length +\n b.pseudoConditions.length +\n b.rootConditions.length +\n parentConditionCount(b.parentGroups) +\n b.ownConditions.length;\n\n return aTotal > bTotal;\n}\n\n/**\n * Check if media conditions A is a superset of B\n */\nfunction isMediaConditionsSuperset(\n a: ParsedMediaCondition[],\n b: ParsedMediaCondition[],\n): boolean {\n const aKeys = new Set(\n a.map((c) => `${c.subtype}|${c.condition}|${c.negated}`),\n );\n for (const c of b) {\n const key = `${c.subtype}|${c.condition}|${c.negated}`;\n if (!aKeys.has(key)) return false;\n }\n return true;\n}\n\n/**\n * Check if container conditions A is a superset of B\n */\nfunction isContainerConditionsSuperset(\n a: ParsedContainerCondition[],\n b: ParsedContainerCondition[],\n): boolean {\n const aKeys = new Set(\n a.map((c) => `${c.name ?? ''}|${c.condition}|${c.negated}`),\n );\n for (const c of b) {\n const key = `${c.name ?? ''}|${c.condition}|${c.negated}`;\n if (!aKeys.has(key)) return false;\n }\n return true;\n}\n\n/**\n * Check if supports conditions A is a superset of B\n */\nfunction isSupportsConditionsSuperset(\n a: ParsedSupportsCondition[],\n b: ParsedSupportsCondition[],\n): boolean {\n const aKeys = new Set(\n a.map((c) => `${c.subtype}|${c.condition}|${c.negated}`),\n );\n for (const c of b) {\n const key = `${c.subtype}|${c.condition}|${c.negated}`;\n if (!aKeys.has(key)) return false;\n }\n return true;\n}\n\n/**\n * Check if modifier conditions A is a superset of B\n */\nfunction isModifierConditionsSuperset(\n a: ParsedModifierCondition[],\n b: ParsedModifierCondition[],\n): boolean {\n const aKeys = new Set(a.map(getModifierKey));\n for (const c of b) {\n if (!aKeys.has(getModifierKey(c))) return false;\n }\n return true;\n}\n\n/**\n * Check if pseudo conditions A is a superset of B\n */\nfunction isPseudoConditionsSuperset(\n a: ParsedPseudoCondition[],\n b: ParsedPseudoCondition[],\n): boolean {\n const aKeys = new Set(a.map(getPseudoKey));\n for (const c of b) {\n if (!aKeys.has(getPseudoKey(c))) return false;\n }\n return true;\n}\n\n/**\n * Check if selector conditions A is a superset of B.\n * Shared by root and own conditions.\n */\nfunction isSelectorConditionsSuperset(\n a: ParsedSelectorCondition[],\n b: ParsedSelectorCondition[],\n): boolean {\n const aKeys = new Set(a.map(getSelectorConditionKey));\n for (const c of b) {\n if (!aKeys.has(getSelectorConditionKey(c))) return false;\n }\n return true;\n}\n\n/**\n * Check if parent groups A is a superset of B.\n * Each group in B must have a matching group in A.\n */\nfunction isParentGroupsSuperset(a: ParentGroup[], b: ParentGroup[]): boolean {\n if (a.length < b.length) return false;\n const aKeys = new Set(a.map(getParentGroupKey));\n for (const g of b) {\n if (!aKeys.has(getParentGroupKey(g))) return false;\n }\n return true;\n}\n\nfunction getParentGroupKey(g: ParentGroup): string {\n return `${g.negated ? '!' : ''}${g.direct ? '>' : ''}(${g.conditions.map(getSelectorConditionKey).sort().join(',')})`;\n}\n\n/**\n * Deduplicate variants\n *\n * Removes:\n * 1. Exact duplicates (same key)\n * 2. Superset variants (more restrictive selectors that are redundant)\n */\nfunction dedupeVariants(variants: SelectorVariant[]): SelectorVariant[] {\n // First pass: exact deduplication\n const seen = new Set<string>();\n const result: SelectorVariant[] = [];\n\n for (const v of variants) {\n const key = getVariantKey(v);\n if (!seen.has(key)) {\n seen.add(key);\n result.push(v);\n }\n }\n\n // Second pass: remove supersets (more restrictive variants)\n // Sort by total condition count (fewer conditions = less restrictive = keep)\n const variantConditionCount = (v: SelectorVariant) =>\n v.modifierConditions.length +\n v.pseudoConditions.length +\n v.ownConditions.length +\n v.mediaConditions.length +\n v.containerConditions.length +\n v.supportsConditions.length +\n v.rootConditions.length +\n v.parentGroups.reduce((sum, g) => sum + g.conditions.length, 0);\n result.sort((a, b) => variantConditionCount(a) - variantConditionCount(b));\n\n // Remove variants that are supersets of earlier (less restrictive) variants\n const filtered: SelectorVariant[] = [];\n for (const candidate of result) {\n let isRedundant = false;\n for (const kept of filtered) {\n if (isVariantSuperset(candidate, kept)) {\n isRedundant = true;\n break;\n }\n }\n if (!isRedundant) {\n filtered.push(candidate);\n }\n }\n\n return filtered;\n}\n\n/**\n * Combine AND conditions into CSS\n *\n * AND of conditions means cartesian product of variants:\n * (A1 | A2) & (B1 | B2) = A1&B1 | A1&B2 | A2&B1 | A2&B2\n *\n * Variants that result in contradictions (e.g., conflicting media rules)\n * are filtered out.\n */\nfunction andToCSS(children: ConditionNode[]): CSSComponents {\n // Start with a single empty variant\n let currentVariants: SelectorVariant[] = [emptyVariant()];\n\n for (const child of children) {\n const childCSS = conditionToCSSInner(child);\n\n if (childCSS.isImpossible || childCSS.variants.length === 0) {\n return { variants: [], isImpossible: true };\n }\n\n // Cartesian product: each current variant × each child variant\n const newVariants: SelectorVariant[] = [];\n for (const current of currentVariants) {\n for (const childVariant of childCSS.variants) {\n const merged = mergeVariants(current, childVariant);\n // Skip impossible variants (contradictions detected during merge)\n if (merged !== null) {\n newVariants.push(merged);\n }\n }\n }\n\n if (newVariants.length === 0) {\n return { variants: [], isImpossible: true };\n }\n\n // Deduplicate after each step to prevent exponential blowup\n currentVariants = dedupeVariants(newVariants);\n }\n\n return {\n variants: currentVariants,\n isImpossible: false,\n };\n}\n\n/**\n * Combine OR conditions into CSS\n *\n * OR in CSS means multiple selector variants (DNF).\n * Each variant becomes a separate selector in the comma-separated list,\n * or multiple CSS rules if they have different at-rules.\n *\n * Note: OR exclusivity is handled at the pipeline level (expandOrConditions),\n * so here we just collect all variants. Any remaining ORs in the condition\n * tree (e.g., from De Morgan expansion) are handled as simple alternatives.\n */\nfunction orToCSS(children: ConditionNode[]): CSSComponents {\n const allVariants: SelectorVariant[] = [];\n\n for (const child of children) {\n const childCSS = conditionToCSSInner(child);\n if (childCSS.isImpossible) continue;\n\n allVariants.push(...childCSS.variants);\n }\n\n if (allVariants.length === 0) {\n return { variants: [], isImpossible: true };\n }\n\n // Deduplicate variants\n return {\n variants: dedupeVariants(allVariants),\n isImpossible: false,\n };\n}\n\n// ============================================================================\n// Utility Functions\n// ============================================================================\n\n/**\n * Get a cache key for a condition\n */\nfunction getConditionKey(node: ConditionNode): string {\n if (node.kind === 'true') return 'TRUE';\n if (node.kind === 'false') return 'FALSE';\n if (node.kind === 'state') return node.uniqueId;\n if (node.kind === 'compound') {\n const childKeys = node.children.map(getConditionKey).sort();\n return `${node.operator}(${childKeys.join(',')})`;\n }\n return 'UNKNOWN';\n}\n\n/**\n * Build at-rules array from a variant\n */\nexport function buildAtRulesFromVariant(variant: SelectorVariant): string[] {\n const atRules: string[] = [];\n\n // Add media rules - combine all conditions with \"and\"\n if (variant.mediaConditions.length > 0) {\n const conditionParts = variant.mediaConditions.map((c) => {\n if (c.subtype === 'type') {\n // Media type: print, screen, etc.\n return c.negated ? `not ${c.condition}` : c.condition;\n } else {\n // Feature or dimension: use not (condition) syntax for negation\n // MQ Level 4 requires parentheses around the condition for negation\n return c.negated ? `(not ${c.condition})` : c.condition;\n }\n });\n atRules.push(`@media ${conditionParts.join(' and ')}`);\n }\n\n // Add container rules - group by container name and combine with \"and\"\n if (variant.containerConditions.length > 0) {\n // Group conditions by container name (undefined = unnamed/nearest)\n const byName = new Map<string | undefined, ParsedContainerCondition[]>();\n for (const cond of variant.containerConditions) {\n const group = byName.get(cond.name) || [];\n group.push(cond);\n byName.set(cond.name, group);\n }\n\n // Build one @container rule per container name\n for (const [name, conditions] of byName) {\n // CSS Container Query syntax requires parentheses around negated conditions:\n // @container (not style(--x)) and style(--y) - NOT @container not style(--x) and style(--y)\n const conditionParts = conditions.map((c) =>\n c.negated ? `(not ${c.condition})` : c.condition,\n );\n const namePrefix = name ? `${name} ` : '';\n atRules.push(`@container ${namePrefix}${conditionParts.join(' and ')}`);\n }\n }\n\n // Add supports rules - combine all conditions with \"and\"\n if (variant.supportsConditions.length > 0) {\n const conditionParts = variant.supportsConditions.map((c) => {\n // Build the condition based on subtype\n // feature: (display: grid) or (not (display: grid))\n // selector: selector(:has(*)) or (not selector(:has(*)))\n if (c.subtype === 'selector') {\n const selectorCond = `selector(${c.condition})`;\n return c.negated ? `(not ${selectorCond})` : selectorCond;\n } else {\n const featureCond = `(${c.condition})`;\n return c.negated ? `(not ${featureCond})` : featureCond;\n }\n });\n atRules.push(`@supports ${conditionParts.join(' and ')}`);\n }\n\n // Add starting-style\n if (variant.startingStyle) {\n atRules.push('@starting-style');\n }\n\n return atRules;\n}\n"],"mappings":";;;;;;;;;;AAwLA,MAAM,iBAAiB,IAAI,IAA2B,IAAK;;;;AAS3D,SAAgB,eAAe,MAAoC;CAEjE,MAAM,MAAM,gBAAgB,KAAK;CACjC,MAAM,SAAS,eAAe,IAAI,IAAI;AACtC,KAAI,OACF,QAAO;CAGT,MAAM,SAAS,oBAAoB,KAAK;AAGxC,gBAAe,IAAI,KAAK,OAAO;AAE/B,QAAO;;;;;AAiBT,SAAS,eAAgC;AACvC,QAAO;EACL,oBAAoB,EAAE;EACtB,kBAAkB,EAAE;EACpB,eAAe,EAAE;EACjB,iBAAiB,EAAE;EACnB,qBAAqB,EAAE;EACvB,oBAAoB,EAAE;EACtB,gBAAgB,EAAE;EAClB,cAAc,EAAE;EAChB,eAAe;EAChB;;AAGH,SAAS,oBAAoB,MAAoC;AAE/D,KAAI,KAAK,SAAS,OAChB,QAAO;EACL,UAAU,CAAC,cAAc,CAAC;EAC1B,cAAc;EACf;AAIH,KAAI,KAAK,SAAS,QAChB,QAAO;EACL,UAAU,EAAE;EACZ,cAAc;EACf;AAIH,KAAI,KAAK,SAAS,QAChB,QAAO,WAAW,KAAK;AAIzB,KAAI,KAAK,SAAS,WAChB,KAAI,KAAK,aAAa,MACpB,QAAO,SAAS,KAAK,SAAS;KAE9B,QAAO,QA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,MAAM,iBAAiB,QAAQ,gBAAgB,KAAK,MAAM;AACxD,OAAI,EAAE,YAAY,OAEhB,QAAO,EAAE,UAAU,OAAO,EAAE,cAAc,EAAE;OAI5C,QAAO,EAAE,UAAU,QAAQ,EAAE,UAAU,KAAK,EAAE;IAEhD;AACF,UAAQ,KAAK,UAAU,eAAe,KAAK,QAAQ,GAAG;;AAIxD,KAAI,QAAQ,oBAAoB,SAAS,GAAG;EAE1C,MAAM,yBAAS,IAAI,KAAqD;AACxE,OAAK,MAAM,QAAQ,QAAQ,qBAAqB;GAC9C,MAAM,QAAQ,OAAO,IAAI,KAAK,KAAK,IAAI,EAAE;AACzC,SAAM,KAAK,KAAK;AAChB,UAAO,IAAI,KAAK,MAAM,MAAM;;AAI9B,OAAK,MAAM,CAAC,MAAM,eAAe,QAAQ;GAGvC,MAAM,iBAAiB,WAAW,KAAK,MACrC,EAAE,UAAU,QAAQ,EAAE,UAAU,KAAK,EAAE,UACxC;GACD,MAAM,aAAa,OAAO,GAAG,KAAK,KAAK;AACvC,WAAQ,KAAK,cAAc,aAAa,eAAe,KAAK,QAAQ,GAAG;;;AAK3E,KAAI,QAAQ,mBAAmB,SAAS,GAAG;EACzC,MAAM,iBAAiB,QAAQ,mBAAmB,KAAK,MAAM;AAI3D,OAAI,EAAE,YAAY,YAAY;IAC5B,MAAM,eAAe,YAAY,EAAE,UAAU;AAC7C,WAAO,EAAE,UAAU,QAAQ,aAAa,KAAK;UACxC;IACL,MAAM,cAAc,IAAI,EAAE,UAAU;AACpC,WAAO,EAAE,UAAU,QAAQ,YAAY,KAAK;;IAE9C;AACF,UAAQ,KAAK,aAAa,eAAe,KAAK,QAAQ,GAAG;;AAI3D,KAAI,QAAQ,cACV,SAAQ,KAAK,kBAAkB;AAGjC,QAAO"}
1
+ {"version":3,"file":"materialize.js","names":[],"sources":["../../src/pipeline/materialize.ts"],"sourcesContent":["/**\n * CSS Materialization\n *\n * Converts condition trees into CSS selectors and at-rules.\n * This is the final stage that produces actual CSS output.\n */\n\nimport { Lru } from '../parser/lru';\n\nimport type {\n ConditionNode,\n ContainerCondition,\n MediaCondition,\n ModifierCondition,\n PseudoCondition,\n StateCondition,\n SupportsCondition,\n} from './conditions';\nimport { getConditionUniqueId, not } from './conditions';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Parsed media condition for structured analysis and combination\n */\nexport interface ParsedMediaCondition {\n /** Subtype for structured analysis */\n subtype: 'dimension' | 'feature' | 'type';\n /** Whether this is a negated condition */\n negated: boolean;\n /** The condition part for CSS output (e.g., \"(width < 600px)\", \"print\") */\n condition: string;\n /** For dimension queries: dimension name */\n dimension?: 'width' | 'height' | 'inline-size' | 'block-size';\n /** For dimension queries: lower bound value */\n lowerBound?: {\n value: string;\n valueNumeric: number | null;\n inclusive: boolean;\n };\n /** For dimension queries: upper bound value */\n upperBound?: {\n value: string;\n valueNumeric: number | null;\n inclusive: boolean;\n };\n /** For feature queries: feature name */\n feature?: string;\n /** For feature queries: feature value */\n featureValue?: string;\n /** For type queries: media type */\n mediaType?: 'print' | 'screen' | 'all' | 'speech';\n}\n\n/**\n * Parsed container condition for structured analysis and combination\n */\nexport interface ParsedContainerCondition {\n /** Container name (undefined = unnamed/nearest container) */\n name?: string;\n /** The condition part (e.g., \"(width < 600px)\" or \"style(--variant: danger)\") */\n condition: string;\n /** Whether this is a negated condition */\n negated: boolean;\n /** Subtype for structured analysis */\n subtype: 'dimension' | 'style' | 'raw';\n /** For style queries: property name (without --) */\n property?: string;\n /** For style queries: property value (undefined = existence check) */\n propertyValue?: string;\n}\n\n/**\n * Parsed supports condition for structured analysis and combination\n */\nexport interface ParsedSupportsCondition {\n /** Subtype: 'feature' for property support, 'selector' for selector() support */\n subtype: 'feature' | 'selector';\n /** The condition string (e.g., \"display: grid\" or \":has(*)\") */\n condition: string;\n /** Whether this is a negated condition */\n negated: boolean;\n}\n\n/**\n * Parsed modifier condition for structured analysis\n */\nexport interface ParsedModifierCondition {\n /** Attribute name (e.g., 'data-hovered', 'data-size') */\n attribute: string;\n /** Value if present (e.g., 'large', 'danger') */\n value?: string;\n /** Operator for value matching (default '=') */\n operator?: '=' | '^=' | '$=' | '*=';\n /** Whether this is negated (:not(...)) */\n negated: boolean;\n}\n\n/**\n * Parsed pseudo-class condition for structured analysis\n */\nexport interface ParsedPseudoCondition {\n /** The pseudo-class (e.g., ':hover', ':focus-visible', ':has(> Icon)') */\n pseudo: string;\n /** Whether this is negated (:not(...)) */\n negated: boolean;\n}\n\n/** Modifier or pseudo condition (shared across own/root/parent) */\ntype ParsedSelectorCondition = ParsedModifierCondition | ParsedPseudoCondition;\n\n/**\n * A group of parent conditions originating from a single @parent() call.\n * Each group produces its own :is() wrapper in the final CSS.\n * Separate @parent() calls = separate groups = can match different ancestors.\n * @parent(a & b) = one group with two conditions = same ancestor must match both.\n */\nexport interface ParentGroup {\n conditions: ParsedSelectorCondition[];\n direct: boolean;\n negated: boolean;\n}\n\n/**\n * A single selector variant (one term in a DNF expression)\n */\nexport interface SelectorVariant {\n /** Structured modifier conditions */\n modifierConditions: ParsedModifierCondition[];\n\n /** Structured pseudo conditions */\n pseudoConditions: ParsedPseudoCondition[];\n\n /** Structured own conditions (for sub-element states) */\n ownConditions: ParsedSelectorCondition[];\n\n /** Parsed media conditions for structured combination */\n mediaConditions: ParsedMediaCondition[];\n\n /** Parsed container conditions for structured combination */\n containerConditions: ParsedContainerCondition[];\n\n /** Parsed supports conditions for @supports at-rules */\n supportsConditions: ParsedSupportsCondition[];\n\n /** Root conditions (modifier/pseudo applied to :root) */\n rootConditions: ParsedSelectorCondition[];\n\n /** Parent condition groups — each @parent() call is a separate group */\n parentGroups: ParentGroup[];\n\n /** Whether to wrap in @starting-style */\n startingStyle: boolean;\n}\n\n/**\n * CSS output components extracted from a condition\n * Supports multiple variants for OR conditions (DNF form)\n */\nexport interface CSSComponents {\n /** Selector variants - OR means multiple variants, AND means single variant with combined selectors */\n variants: SelectorVariant[];\n\n /** Whether condition is impossible (should skip) */\n isImpossible: boolean;\n}\n\n/**\n * Final CSS rule output\n */\nexport interface CSSRule {\n /** Single selector or array of selector fragments (for OR conditions) */\n selector: string | string[];\n declarations: string;\n atRules?: string[];\n rootPrefix?: string;\n}\n\n// ============================================================================\n// Caching\n// ============================================================================\n\nconst conditionCache = new Lru<string, CSSComponents>(3000);\n\n// ============================================================================\n// Main Functions\n// ============================================================================\n\n/**\n * Convert a condition tree to CSS components\n */\nexport function conditionToCSS(node: ConditionNode): CSSComponents {\n // Check cache\n const key = getConditionUniqueId(node);\n const cached = conditionCache.get(key);\n if (cached) {\n return cached;\n }\n\n const result = conditionToCSSInner(node);\n\n // Cache result\n conditionCache.set(key, result);\n\n return result;\n}\n\n/**\n * Clear the condition cache (for testing)\n */\nexport function clearConditionCache(): void {\n conditionCache.clear();\n}\n\n// ============================================================================\n// Inner Implementation\n// ============================================================================\n\nfunction emptyVariant(): SelectorVariant {\n return {\n modifierConditions: [],\n pseudoConditions: [],\n ownConditions: [],\n mediaConditions: [],\n containerConditions: [],\n supportsConditions: [],\n rootConditions: [],\n parentGroups: [],\n startingStyle: false,\n };\n}\n\nfunction conditionToCSSInner(node: ConditionNode): CSSComponents {\n // Base case: TRUE condition - single empty variant (matches everything)\n if (node.kind === 'true') {\n return {\n variants: [emptyVariant()],\n isImpossible: false,\n };\n }\n\n // Base case: FALSE condition - no variants (matches nothing)\n if (node.kind === 'false') {\n return {\n variants: [],\n isImpossible: true,\n };\n }\n\n // State condition\n if (node.kind === 'state') {\n return stateToCSS(node);\n }\n\n // Compound condition\n if (node.kind === 'compound') {\n if (node.operator === 'AND') {\n return andToCSS(node.children);\n } else {\n return orToCSS(node.children);\n }\n }\n\n // Fallback - single empty variant\n return {\n variants: [emptyVariant()],\n isImpossible: false,\n };\n}\n\n/**\n * Convert a state condition to CSS\n */\nfunction stateToCSS(state: StateCondition): CSSComponents {\n switch (state.type) {\n case 'media': {\n const mediaResults = mediaToParsed(state);\n const variants = mediaResults.map((mediaCond) => {\n const v = emptyVariant();\n v.mediaConditions.push(mediaCond);\n return v;\n });\n return { variants, isImpossible: false };\n }\n\n case 'root':\n return innerConditionToVariants(\n state.innerCondition,\n state.negated ?? false,\n 'rootConditions',\n );\n\n case 'parent':\n return parentConditionToVariants(\n state.innerCondition,\n state.negated ?? false,\n state.direct,\n );\n\n case 'own':\n return innerConditionToVariants(\n state.innerCondition,\n state.negated ?? false,\n 'ownConditions',\n );\n\n case 'modifier': {\n const v = emptyVariant();\n v.modifierConditions.push(modifierToParsed(state));\n return { variants: [v], isImpossible: false };\n }\n\n case 'pseudo': {\n const v = emptyVariant();\n v.pseudoConditions.push(pseudoToParsed(state));\n return { variants: [v], isImpossible: false };\n }\n\n case 'container': {\n const v = emptyVariant();\n v.containerConditions.push(containerToParsed(state));\n return { variants: [v], isImpossible: false };\n }\n\n case 'supports': {\n const v = emptyVariant();\n v.supportsConditions.push(supportsToParsed(state));\n return { variants: [v], isImpossible: false };\n }\n\n case 'starting': {\n const v = emptyVariant();\n v.startingStyle = !state.negated;\n return { variants: [v], isImpossible: false };\n }\n }\n}\n\n/**\n * Convert modifier condition to parsed structure\n */\nfunction modifierToParsed(state: ModifierCondition): ParsedModifierCondition {\n return {\n attribute: state.attribute,\n value: state.value,\n operator: state.operator,\n negated: state.negated ?? false,\n };\n}\n\n/**\n * Convert parsed modifier to CSS selector string (for final output)\n */\nexport function modifierToCSS(mod: ParsedModifierCondition): string {\n let selector: string;\n\n if (mod.value !== undefined) {\n // Value attribute: [data-attr=\"value\"]\n const op = mod.operator || '=';\n selector = `[${mod.attribute}${op}\"${mod.value}\"]`;\n } else {\n // Boolean attribute: [data-attr]\n selector = `[${mod.attribute}]`;\n }\n\n if (mod.negated) {\n return `:not(${selector})`;\n }\n return selector;\n}\n\n/**\n * Convert pseudo condition to parsed structure\n */\nfunction pseudoToParsed(state: PseudoCondition): ParsedPseudoCondition {\n return {\n pseudo: state.pseudo,\n negated: state.negated ?? false,\n };\n}\n\n/**\n * Convert parsed pseudo to CSS selector string (for final output)\n */\nexport function pseudoToCSS(pseudo: ParsedPseudoCondition): string {\n if (pseudo.negated) {\n // Wrap in :not() if not already\n if (pseudo.pseudo.startsWith(':not(')) {\n // Double negation - remove :not()\n return pseudo.pseudo.slice(5, -1);\n }\n return `:not(${pseudo.pseudo})`;\n }\n return pseudo.pseudo;\n}\n\n/**\n * Convert media condition to parsed structure(s)\n * Returns an array because negated ranges produce OR branches (two separate conditions)\n */\nfunction mediaToParsed(state: MediaCondition): ParsedMediaCondition[] {\n if (state.subtype === 'type') {\n // @media:print → @media print (or @media not print)\n const mediaType = state.mediaType || 'all';\n return [\n {\n subtype: 'type',\n negated: state.negated ?? false,\n condition: mediaType,\n mediaType: state.mediaType,\n },\n ];\n } else if (state.subtype === 'feature') {\n // @media(prefers-contrast: high) → @media (prefers-contrast: high)\n let condition: string;\n if (state.featureValue) {\n condition = `(${state.feature}: ${state.featureValue})`;\n } else {\n condition = `(${state.feature})`;\n }\n return [\n {\n subtype: 'feature',\n negated: state.negated ?? false,\n condition,\n feature: state.feature,\n featureValue: state.featureValue,\n },\n ];\n } else {\n // Dimension query - negation is handled by inverting the condition\n // because \"not (width < x)\" doesn't work reliably in browsers\n return dimensionToMediaParsed(\n state.dimension || 'width',\n state.lowerBound,\n state.upperBound,\n state.negated ?? false,\n );\n }\n}\n\n/**\n * Convert dimension bounds to parsed media condition(s)\n * Uses CSS Media Queries Level 4 `not (condition)` syntax for negation.\n */\nfunction dimensionToMediaParsed(\n dimension: 'width' | 'height' | 'inline-size' | 'block-size',\n lowerBound?: {\n value: string;\n valueNumeric: number | null;\n inclusive: boolean;\n },\n upperBound?: {\n value: string;\n valueNumeric: number | null;\n inclusive: boolean;\n },\n negated?: boolean,\n): ParsedMediaCondition[] {\n // Build the condition string\n let condition: string;\n if (lowerBound && upperBound) {\n const lowerOp = lowerBound.inclusive ? '<=' : '<';\n const upperOp = upperBound.inclusive ? '<=' : '<';\n condition = `(${lowerBound.value} ${lowerOp} ${dimension} ${upperOp} ${upperBound.value})`;\n } else if (upperBound) {\n const op = upperBound.inclusive ? '<=' : '<';\n condition = `(${dimension} ${op} ${upperBound.value})`;\n } else if (lowerBound) {\n const op = lowerBound.inclusive ? '>=' : '>';\n condition = `(${dimension} ${op} ${lowerBound.value})`;\n } else {\n condition = `(${dimension})`;\n }\n\n // For negation, we use CSS `not (condition)` syntax in buildAtRulesFromVariant\n return [\n {\n subtype: 'dimension',\n negated: negated ?? false,\n condition,\n dimension,\n lowerBound,\n upperBound,\n },\n ];\n}\n\n/**\n * Convert container condition to parsed structure\n * This enables structured analysis for contradiction detection and condition combining\n */\nfunction containerToParsed(\n state: ContainerCondition,\n): ParsedContainerCondition {\n let condition: string;\n\n if (state.subtype === 'style') {\n // Style query: style(--prop: value)\n if (state.propertyValue) {\n condition = `style(--${state.property}: ${state.propertyValue})`;\n } else {\n condition = `style(--${state.property})`;\n }\n } else if (state.subtype === 'raw') {\n // Raw function query: passed through verbatim (e.g., scroll-state(stuck: top))\n condition = state.rawCondition!;\n } else {\n // Dimension query\n condition = dimensionToContainerCondition(\n state.dimension || 'width',\n state.lowerBound,\n state.upperBound,\n );\n }\n\n return {\n name: state.containerName,\n condition,\n negated: state.negated ?? false,\n subtype: state.subtype,\n property: state.property,\n propertyValue: state.propertyValue,\n };\n}\n\n/**\n * Convert dimension bounds to container query condition (single string)\n * Container queries support \"not (condition)\", so no need to invert manually\n */\nfunction dimensionToContainerCondition(\n dimension: string,\n lowerBound?: { value: string; inclusive: boolean },\n upperBound?: { value: string; inclusive: boolean },\n): string {\n if (lowerBound && upperBound) {\n const lowerOp = lowerBound.inclusive ? '<=' : '<';\n const upperOp = upperBound.inclusive ? '<=' : '<';\n return `(${lowerBound.value} ${lowerOp} ${dimension} ${upperOp} ${upperBound.value})`;\n } else if (upperBound) {\n const op = upperBound.inclusive ? '<=' : '<';\n return `(${dimension} ${op} ${upperBound.value})`;\n } else if (lowerBound) {\n const op = lowerBound.inclusive ? '>=' : '>';\n return `(${dimension} ${op} ${lowerBound.value})`;\n }\n return '(width)'; // Fallback\n}\n\n/**\n * Convert supports condition to parsed structure\n */\nfunction supportsToParsed(state: SupportsCondition): ParsedSupportsCondition {\n return {\n subtype: state.subtype,\n condition: state.condition,\n negated: state.negated ?? false,\n };\n}\n\n/**\n * Collect all modifier and pseudo conditions from a variant as a flat array.\n */\nfunction collectSelectorConditions(\n variant: SelectorVariant,\n): ParsedSelectorCondition[] {\n return [...variant.modifierConditions, ...variant.pseudoConditions];\n}\n\n/**\n * Convert an inner condition tree into SelectorVariants.\n * Each inner OR branch becomes a separate variant, preserving disjunction.\n * Shared by @root() and @own().\n */\nfunction innerConditionToVariants(\n innerCondition: ConditionNode,\n negated: boolean,\n target: 'rootConditions' | 'ownConditions',\n): CSSComponents {\n // For @root/@own, negation is applied upfront via De Morgan: !(A | B) = !A & !B.\n // This is safe because the negated conditions are appended directly to the same\n // selector (e.g. :root:not([a]):not([b])), so collapsing OR branches is correct.\n //\n // @parent uses a different strategy (parentConditionToVariants) because each OR\n // branch must become its own :not(... *) wrapper — the * combinator scopes to a\n // specific ancestor, so branches cannot be merged into one selector.\n const effectiveCondition = negated ? not(innerCondition) : innerCondition;\n const innerCSS = conditionToCSS(effectiveCondition);\n\n if (innerCSS.isImpossible || innerCSS.variants.length === 0) {\n return { variants: [], isImpossible: true };\n }\n\n const variants: SelectorVariant[] = [];\n\n for (const innerVariant of innerCSS.variants) {\n const conditions = collectSelectorConditions(innerVariant);\n\n if (conditions.length > 0) {\n const v = emptyVariant();\n v[target].push(...conditions);\n variants.push(v);\n }\n }\n\n if (variants.length === 0) {\n return { variants: [emptyVariant()], isImpossible: false };\n }\n\n return { variants, isImpossible: false };\n}\n\n/**\n * Convert a @parent() inner condition into SelectorVariants with ParentGroups.\n *\n * Positive: each inner OR branch becomes a separate variant with one :is() group.\n * Negated: !(A | B) = !A & !B — all branches become :not() groups collected\n * into a single variant so they produce :not([a] *):not([b] *) on one element.\n */\nfunction parentConditionToVariants(\n innerCondition: ConditionNode,\n negated: boolean,\n direct: boolean,\n): CSSComponents {\n const innerCSS = conditionToCSS(innerCondition);\n\n if (innerCSS.isImpossible || innerCSS.variants.length === 0) {\n return { variants: [], isImpossible: true };\n }\n\n if (negated) {\n // Collect all OR branches into one variant as separate :not() groups.\n const v = emptyVariant();\n\n for (const innerVariant of innerCSS.variants) {\n const conditions = collectSelectorConditions(innerVariant);\n\n if (conditions.length > 0) {\n v.parentGroups.push({ conditions, direct, negated: true });\n }\n }\n\n if (v.parentGroups.length === 0) {\n return { variants: [emptyVariant()], isImpossible: false };\n }\n\n return { variants: [v], isImpossible: false };\n }\n\n // Positive: each OR branch is a separate variant\n const variants: SelectorVariant[] = [];\n\n for (const innerVariant of innerCSS.variants) {\n const conditions = collectSelectorConditions(innerVariant);\n\n if (conditions.length > 0) {\n const v = emptyVariant();\n v.parentGroups.push({ conditions, direct, negated: false });\n variants.push(v);\n }\n }\n\n if (variants.length === 0) {\n return { variants: [emptyVariant()], isImpossible: false };\n }\n\n return { variants, isImpossible: false };\n}\n\n/**\n * Convert parsed root conditions to CSS selector prefix (for final output)\n */\nexport function rootConditionsToCSS(\n roots: ParsedSelectorCondition[],\n): string | undefined {\n if (roots.length === 0) return undefined;\n\n let prefix = ':root';\n for (const cond of roots) {\n prefix += selectorConditionToCSS(cond);\n }\n return prefix;\n}\n\n/**\n * Convert parent groups to CSS selector fragments (for final output).\n * Each group produces its own :is() wrapper.\n */\nexport function parentGroupsToCSS(groups: ParentGroup[]): string {\n let result = '';\n for (const group of groups) {\n const combinator = group.direct ? ' > *' : ' *';\n let parts = '';\n for (const cond of group.conditions) {\n parts += selectorConditionToCSS(cond);\n }\n const wrapper = group.negated ? ':not' : ':is';\n result += `${wrapper}(${parts}${combinator})`;\n }\n return result;\n}\n\n/**\n * Convert a modifier or pseudo condition to a CSS selector fragment\n */\nexport function selectorConditionToCSS(cond: ParsedSelectorCondition): string {\n if ('attribute' in cond) {\n return modifierToCSS(cond);\n }\n return pseudoToCSS(cond);\n}\n\n/**\n * Get unique key for a modifier condition\n */\nfunction getModifierKey(mod: ParsedModifierCondition): string {\n const base = mod.value\n ? `${mod.attribute}${mod.operator || '='}${mod.value}`\n : mod.attribute;\n return mod.negated ? `!${base}` : base;\n}\n\n/**\n * Get unique key for a pseudo condition\n */\nfunction getPseudoKey(pseudo: ParsedPseudoCondition): string {\n return pseudo.negated ? `!${pseudo.pseudo}` : pseudo.pseudo;\n}\n\n/**\n * Get unique key for any selector condition (modifier or pseudo)\n */\nfunction getSelectorConditionKey(cond: ParsedSelectorCondition): string {\n return 'attribute' in cond\n ? `mod:${getModifierKey(cond)}`\n : `pseudo:${getPseudoKey(cond)}`;\n}\n\n/**\n * Deduplicate selector conditions (modifiers or pseudos).\n * Shared by root, parent, and own conditions.\n */\nfunction dedupeSelectorConditions(\n conditions: ParsedSelectorCondition[],\n): ParsedSelectorCondition[] {\n // Pass 1: exact-key dedup\n const seen = new Set<string>();\n let result: ParsedSelectorCondition[] = [];\n for (const c of conditions) {\n const key = getSelectorConditionKey(c);\n if (!seen.has(key)) {\n seen.add(key);\n result.push(c);\n }\n }\n\n // Pass 2: remove negated value modifiers subsumed by other modifiers.\n // :not([data-attr]) subsumes :not([data-attr=\"value\"])\n // [data-attr=\"X\"] implies :not([data-attr=\"Y\"]) is redundant\n // This implication only holds for exact-match (=) operators; substring\n // operators (^=, $=, *=) don't imply exclusivity between values.\n const negatedBooleanAttrs = new Set<string>();\n const positiveExactValuesByAttr = new Map<string, Set<string>>();\n\n for (const c of result) {\n if (!('attribute' in c)) continue;\n if (c.negated && c.value === undefined) {\n negatedBooleanAttrs.add(c.attribute);\n }\n const op = c.operator ?? '=';\n if (!c.negated && c.value !== undefined && op === '=') {\n let values = positiveExactValuesByAttr.get(c.attribute);\n if (!values) {\n values = new Set();\n positiveExactValuesByAttr.set(c.attribute, values);\n }\n values.add(c.value);\n }\n }\n\n result = result.filter((c) => {\n if (!('attribute' in c) || !c.negated || c.value === undefined) {\n return true;\n }\n if (negatedBooleanAttrs.has(c.attribute)) {\n return false;\n }\n const op = c.operator ?? '=';\n if (op !== '=') return true;\n const positiveValues = positiveExactValuesByAttr.get(c.attribute);\n if (\n positiveValues !== undefined &&\n positiveValues.size === 1 &&\n !positiveValues.has(c.value)\n ) {\n return false;\n }\n return true;\n });\n\n return result;\n}\n\n/**\n * Check for modifier contradiction: same attribute with opposite negation\n */\nfunction hasModifierContradiction(\n conditions: ParsedModifierCondition[],\n): boolean {\n const byKey = new Map<string, boolean>(); // base key -> isPositive\n\n for (const mod of conditions) {\n const baseKey = mod.value\n ? `${mod.attribute}${mod.operator || '='}${mod.value}`\n : mod.attribute;\n const existing = byKey.get(baseKey);\n if (existing !== undefined && existing !== !mod.negated) {\n return true; // Same attribute with opposite negation\n }\n byKey.set(baseKey, !mod.negated);\n }\n return false;\n}\n\n/**\n * Check for pseudo contradiction: same pseudo with opposite negation\n */\nfunction hasPseudoContradiction(conditions: ParsedPseudoCondition[]): boolean {\n const byKey = new Map<string, boolean>(); // pseudo -> isPositive\n\n for (const pseudo of conditions) {\n const existing = byKey.get(pseudo.pseudo);\n if (existing !== undefined && existing !== !pseudo.negated) {\n return true; // Same pseudo with opposite negation\n }\n byKey.set(pseudo.pseudo, !pseudo.negated);\n }\n return false;\n}\n\n/**\n * Check for selector condition contradiction (modifier or pseudo with opposite negation).\n * Shared by root, parent, and own conditions.\n */\nfunction hasSelectorConditionContradiction(\n conditions: ParsedSelectorCondition[],\n): boolean {\n const modifiers: ParsedModifierCondition[] = [];\n const pseudos: ParsedPseudoCondition[] = [];\n\n for (const c of conditions) {\n if ('attribute' in c) {\n modifiers.push(c);\n } else {\n pseudos.push(c);\n }\n }\n\n return hasModifierContradiction(modifiers) || hasPseudoContradiction(pseudos);\n}\n\n/**\n * Check for parent group contradiction: same target (direct + conditions)\n * with opposite negation. E.g. :not([data-hovered] *) and :is([data-hovered] *)\n * in the same variant is impossible.\n */\nfunction hasParentGroupContradiction(groups: ParentGroup[]): boolean {\n const byBaseKey = new Map<string, boolean>();\n\n for (const g of groups) {\n const baseKey = `${g.direct ? '>' : ''}(${g.conditions.map(getSelectorConditionKey).sort().join(',')})`;\n const existing = byBaseKey.get(baseKey);\n if (existing !== undefined && existing !== !g.negated) {\n return true;\n }\n byBaseKey.set(baseKey, !g.negated);\n }\n return false;\n}\n\n/**\n * Merge two selector variants (AND operation)\n * Deduplicates conditions and checks for contradictions\n */\nfunction mergeVariants(\n a: SelectorVariant,\n b: SelectorVariant,\n): SelectorVariant | null {\n // Merge media conditions and check for contradictions\n const mergedMedia = dedupeMediaConditions([\n ...a.mediaConditions,\n ...b.mediaConditions,\n ]);\n if (hasMediaContradiction(mergedMedia)) {\n return null; // Impossible variant\n }\n\n // Merge root conditions and check for contradictions\n const mergedRoots = dedupeSelectorConditions([\n ...a.rootConditions,\n ...b.rootConditions,\n ]);\n if (hasSelectorConditionContradiction(mergedRoots)) {\n return null; // Impossible variant\n }\n\n // Merge modifier and pseudo conditions separately, then cross-check\n const mergedModifiers = dedupeSelectorConditions([\n ...a.modifierConditions,\n ...b.modifierConditions,\n ]) as ParsedModifierCondition[];\n const mergedPseudos = dedupeSelectorConditions([\n ...a.pseudoConditions,\n ...b.pseudoConditions,\n ]) as ParsedPseudoCondition[];\n if (\n hasSelectorConditionContradiction([...mergedModifiers, ...mergedPseudos])\n ) {\n return null; // Impossible variant\n }\n\n // Concatenate parent groups (each group is an independent :is() wrapper)\n const mergedParentGroups = [...a.parentGroups, ...b.parentGroups];\n if (hasParentGroupContradiction(mergedParentGroups)) {\n return null; // Impossible variant\n }\n\n // Merge own conditions and check for contradictions\n const mergedOwn = dedupeSelectorConditions([\n ...a.ownConditions,\n ...b.ownConditions,\n ]);\n if (hasSelectorConditionContradiction(mergedOwn)) {\n return null; // Impossible variant\n }\n\n // Merge container conditions and check for contradictions\n const mergedContainers = dedupeContainerConditions([\n ...a.containerConditions,\n ...b.containerConditions,\n ]);\n if (hasContainerStyleContradiction(mergedContainers)) {\n return null; // Impossible variant\n }\n\n // Merge supports conditions and check for contradictions\n const mergedSupports = dedupeSupportsConditions([\n ...a.supportsConditions,\n ...b.supportsConditions,\n ]);\n if (hasSupportsContradiction(mergedSupports)) {\n return null; // Impossible variant\n }\n\n return {\n modifierConditions: mergedModifiers,\n pseudoConditions: mergedPseudos,\n ownConditions: mergedOwn,\n mediaConditions: mergedMedia,\n containerConditions: mergedContainers,\n supportsConditions: mergedSupports,\n rootConditions: mergedRoots,\n parentGroups: mergedParentGroups,\n startingStyle: a.startingStyle || b.startingStyle,\n };\n}\n\n/**\n * Generic deduplication by a key extraction function.\n * Preserves insertion order, keeping the first occurrence of each key.\n */\nfunction dedupeByKey<T>(items: T[], getKey: (item: T) => string): T[] {\n const seen = new Set<string>();\n const result: T[] = [];\n for (const item of items) {\n const key = getKey(item);\n if (!seen.has(key)) {\n seen.add(key);\n result.push(item);\n }\n }\n return result;\n}\n\nfunction dedupeMediaConditions(\n conditions: ParsedMediaCondition[],\n): ParsedMediaCondition[] {\n return dedupeByKey(\n conditions,\n (c) => `${c.subtype}|${c.condition}|${c.negated}`,\n );\n}\n\nfunction dedupeContainerConditions(\n conditions: ParsedContainerCondition[],\n): ParsedContainerCondition[] {\n return dedupeByKey(\n conditions,\n (c) => `${c.name ?? ''}|${c.condition}|${c.negated}`,\n );\n}\n\nfunction dedupeSupportsConditions(\n conditions: ParsedSupportsCondition[],\n): ParsedSupportsCondition[] {\n return dedupeByKey(\n conditions,\n (c) => `${c.subtype}|${c.condition}|${c.negated}`,\n );\n}\n\n/**\n * Check if supports conditions contain contradictions\n * e.g., @supports(display: grid) AND NOT @supports(display: grid)\n */\nfunction hasSupportsContradiction(\n conditions: ParsedSupportsCondition[],\n): boolean {\n const conditionMap = new Map<string, boolean>(); // key -> isPositive\n\n for (const cond of conditions) {\n const key = `${cond.subtype}|${cond.condition}`;\n const existing = conditionMap.get(key);\n if (existing !== undefined && existing !== !cond.negated) {\n return true; // Contradiction: positive AND negated\n }\n conditionMap.set(key, !cond.negated);\n }\n\n return false;\n}\n\n/**\n * Check if a set of media conditions contains contradictions\n * e.g., (prefers-color-scheme: light) AND NOT (prefers-color-scheme: light)\n * or (width >= 900px) AND (width < 600px)\n *\n * Uses parsed media conditions for efficient analysis without regex parsing.\n */\nfunction hasMediaContradiction(conditions: ParsedMediaCondition[]): boolean {\n // Track conditions by their key (condition string) to detect A and NOT A\n const featureConditions = new Map<string, boolean>(); // key -> isPositive\n const typeConditions = new Map<string, boolean>(); // mediaType -> isPositive\n const dimensionConditions = new Map<string, boolean>(); // condition -> isPositive\n\n // Track dimension conditions for range contradiction detection (non-negated only)\n const dimensionsByDim = new Map<\n string,\n { lowerBound: number | null; upperBound: number | null }\n >();\n\n for (const cond of conditions) {\n if (cond.subtype === 'type') {\n // Type query: check for direct contradiction (print AND NOT print)\n const key = cond.mediaType || 'all';\n const existing = typeConditions.get(key);\n if (existing !== undefined && existing !== !cond.negated) {\n return true; // Contradiction: positive AND negated\n }\n typeConditions.set(key, !cond.negated);\n } else if (cond.subtype === 'feature') {\n // Feature query: check for direct contradiction\n const key = cond.condition;\n const existing = featureConditions.get(key);\n if (existing !== undefined && existing !== !cond.negated) {\n return true; // Contradiction: positive AND negated\n }\n featureConditions.set(key, !cond.negated);\n } else if (cond.subtype === 'dimension') {\n // First, check for direct contradiction: (width < 600px) AND NOT (width < 600px)\n const condKey = cond.condition;\n const existing = dimensionConditions.get(condKey);\n if (existing !== undefined && existing !== !cond.negated) {\n return true; // Contradiction: positive AND negated\n }\n dimensionConditions.set(condKey, !cond.negated);\n\n // For range analysis, only consider non-negated conditions\n // Negated conditions are handled via the direct contradiction check above\n if (!cond.negated) {\n const dim = cond.dimension || 'width';\n let bounds = dimensionsByDim.get(dim);\n if (!bounds) {\n bounds = { lowerBound: null, upperBound: null };\n dimensionsByDim.set(dim, bounds);\n }\n\n // Track the effective bounds\n if (cond.lowerBound?.valueNumeric != null) {\n const value = cond.lowerBound.valueNumeric;\n if (bounds.lowerBound === null || value > bounds.lowerBound) {\n bounds.lowerBound = value;\n }\n }\n if (cond.upperBound?.valueNumeric != null) {\n const value = cond.upperBound.valueNumeric;\n if (bounds.upperBound === null || value < bounds.upperBound) {\n bounds.upperBound = value;\n }\n }\n\n // Check for impossible range\n if (\n bounds.lowerBound !== null &&\n bounds.upperBound !== null &&\n bounds.lowerBound >= bounds.upperBound\n ) {\n return true;\n }\n }\n }\n }\n\n return false;\n}\n\n/**\n * Check if container conditions contain contradictions in style queries\n * e.g., style(--variant: danger) and style(--variant: success) together\n * Same property with different values = always false\n *\n * Uses parsed container conditions for efficient analysis without regex parsing.\n */\nfunction hasContainerStyleContradiction(\n conditions: ParsedContainerCondition[],\n): boolean {\n // Track style queries by property name\n // key: property name, value: { hasExistence: boolean, values: Set<string>, hasNegatedExistence: boolean }\n const styleQueries = new Map<\n string,\n { hasExistence: boolean; values: Set<string>; hasNegatedExistence: boolean }\n >();\n\n for (const cond of conditions) {\n // Only analyze style queries\n if (cond.subtype !== 'style' || !cond.property) {\n continue;\n }\n\n const property = cond.property;\n const value = cond.propertyValue;\n\n if (!styleQueries.has(property)) {\n styleQueries.set(property, {\n hasExistence: false,\n values: new Set(),\n hasNegatedExistence: false,\n });\n }\n\n const entry = styleQueries.get(property)!;\n\n if (cond.negated) {\n if (value === undefined) {\n // not style(--prop) - negated existence check\n entry.hasNegatedExistence = true;\n }\n // Negated value checks don't contradict positive value checks directly\n // They just mean \"not this value\"\n } else {\n if (value === undefined) {\n // style(--prop) - existence check\n entry.hasExistence = true;\n } else {\n // style(--prop: value) - value check\n entry.values.add(value);\n }\n }\n }\n\n // Check for contradictions\n for (const [, entry] of styleQueries) {\n // Contradiction: existence check + negated existence check\n if (entry.hasExistence && entry.hasNegatedExistence) {\n return true;\n }\n\n // Contradiction: multiple different values for same property\n // style(--variant: danger) AND style(--variant: success) is impossible\n if (entry.values.size > 1) {\n return true;\n }\n\n // Contradiction: negated existence + value check\n // not style(--variant) AND style(--variant: danger) is impossible\n if (entry.hasNegatedExistence && entry.values.size > 0) {\n return true;\n }\n }\n\n return false;\n}\n\nconst variantKeyCache = new WeakMap<SelectorVariant, string>();\n\n/**\n * Get a unique key for a variant (for deduplication).\n * Cached via WeakMap since variants are compared multiple times during\n * deduplication and sorting.\n */\nfunction getVariantKey(v: SelectorVariant): string {\n const cached = variantKeyCache.get(v);\n if (cached !== undefined) return cached;\n const modifierKey = v.modifierConditions.map(getModifierKey).sort().join('|');\n const pseudoKey = v.pseudoConditions.map(getPseudoKey).sort().join('|');\n const ownKey = v.ownConditions.map(getSelectorConditionKey).sort().join('|');\n const containerKey = v.containerConditions\n .map((c) => `${c.name ?? ''}:${c.negated ? '!' : ''}${c.condition}`)\n .sort()\n .join('|');\n const mediaKey = v.mediaConditions\n .map((c) => `${c.subtype}:${c.negated ? '!' : ''}${c.condition}`)\n .sort()\n .join('|');\n const supportsKey = v.supportsConditions\n .map((c) => `${c.subtype}:${c.negated ? '!' : ''}${c.condition}`)\n .sort()\n .join('|');\n const rootKey = v.rootConditions\n .map(getSelectorConditionKey)\n .sort()\n .join('|');\n const parentKey = v.parentGroups.map(getParentGroupKey).sort().join('|');\n const key = [\n modifierKey,\n pseudoKey,\n ownKey,\n mediaKey,\n containerKey,\n supportsKey,\n rootKey,\n parentKey,\n v.startingStyle ? '1' : '0',\n ].join('###');\n variantKeyCache.set(v, key);\n return key;\n}\n\n/**\n * Check if variant A is a superset of variant B (A is more restrictive)\n *\n * If A has all of B's conditions plus more, then A is redundant\n * because B already covers the same cases (and more).\n *\n * Example:\n * A: :not([size=large]):not([size=medium]):not([size=small])\n * B: :not([size=large])\n * A is a superset of B, so A is redundant when B exists.\n */\nfunction isVariantSuperset(a: SelectorVariant, b: SelectorVariant): boolean {\n // Must have same context\n if (a.startingStyle !== b.startingStyle) return false;\n\n // Check if a.rootConditions is superset of b.rootConditions\n if (!isSelectorConditionsSuperset(a.rootConditions, b.rootConditions))\n return false;\n\n // Check if a.mediaConditions is superset of b.mediaConditions\n if (!isMediaConditionsSuperset(a.mediaConditions, b.mediaConditions))\n return false;\n\n // Check if a.containerConditions is superset of b.containerConditions\n if (\n !isContainerConditionsSuperset(a.containerConditions, b.containerConditions)\n )\n return false;\n\n // Check if a.supportsConditions is superset of b.supportsConditions\n if (!isSupportsConditionsSuperset(a.supportsConditions, b.supportsConditions))\n return false;\n\n // Check if a.modifierConditions is superset of b.modifierConditions\n if (!isModifierConditionsSuperset(a.modifierConditions, b.modifierConditions))\n return false;\n\n // Check if a.pseudoConditions is superset of b.pseudoConditions\n if (!isPseudoConditionsSuperset(a.pseudoConditions, b.pseudoConditions))\n return false;\n\n // Check if a.ownConditions is superset of b.ownConditions\n if (!isSelectorConditionsSuperset(a.ownConditions, b.ownConditions))\n return false;\n\n // Check if a.parentGroups is superset of b.parentGroups\n if (!isParentGroupsSuperset(a.parentGroups, b.parentGroups)) return false;\n\n // A is a superset if it has all of B's items (possibly more)\n // and at least one category has strictly more items\n const parentConditionCount = (groups: ParentGroup[]) =>\n groups.reduce((sum, g) => sum + g.conditions.length, 0);\n const aTotal =\n a.mediaConditions.length +\n a.containerConditions.length +\n a.supportsConditions.length +\n a.modifierConditions.length +\n a.pseudoConditions.length +\n a.rootConditions.length +\n parentConditionCount(a.parentGroups) +\n a.ownConditions.length;\n const bTotal =\n b.mediaConditions.length +\n b.containerConditions.length +\n b.supportsConditions.length +\n b.modifierConditions.length +\n b.pseudoConditions.length +\n b.rootConditions.length +\n parentConditionCount(b.parentGroups) +\n b.ownConditions.length;\n\n return aTotal > bTotal;\n}\n\n/**\n * Generic superset check: true if every item in B has a matching key in A.\n */\nfunction isConditionsSuperset<T>(\n a: T[],\n b: T[],\n getKey: (item: T) => string,\n): boolean {\n const aKeys = new Set(a.map(getKey));\n return b.every((c) => aKeys.has(getKey(c)));\n}\n\nfunction isMediaConditionsSuperset(\n a: ParsedMediaCondition[],\n b: ParsedMediaCondition[],\n): boolean {\n return isConditionsSuperset(\n a,\n b,\n (c) => `${c.subtype}|${c.condition}|${c.negated}`,\n );\n}\n\nfunction isContainerConditionsSuperset(\n a: ParsedContainerCondition[],\n b: ParsedContainerCondition[],\n): boolean {\n return isConditionsSuperset(\n a,\n b,\n (c) => `${c.name ?? ''}|${c.condition}|${c.negated}`,\n );\n}\n\nfunction isSupportsConditionsSuperset(\n a: ParsedSupportsCondition[],\n b: ParsedSupportsCondition[],\n): boolean {\n return isConditionsSuperset(\n a,\n b,\n (c) => `${c.subtype}|${c.condition}|${c.negated}`,\n );\n}\n\nfunction isModifierConditionsSuperset(\n a: ParsedModifierCondition[],\n b: ParsedModifierCondition[],\n): boolean {\n return isConditionsSuperset(a, b, getModifierKey);\n}\n\nfunction isPseudoConditionsSuperset(\n a: ParsedPseudoCondition[],\n b: ParsedPseudoCondition[],\n): boolean {\n return isConditionsSuperset(a, b, getPseudoKey);\n}\n\nfunction isSelectorConditionsSuperset(\n a: ParsedSelectorCondition[],\n b: ParsedSelectorCondition[],\n): boolean {\n return isConditionsSuperset(a, b, getSelectorConditionKey);\n}\n\n/**\n * Check if parent groups A is a superset of B.\n * Each group in B must have a matching group in A.\n */\nfunction isParentGroupsSuperset(a: ParentGroup[], b: ParentGroup[]): boolean {\n if (a.length < b.length) return false;\n return isConditionsSuperset(a, b, getParentGroupKey);\n}\n\nfunction getParentGroupKey(g: ParentGroup): string {\n return `${g.negated ? '!' : ''}${g.direct ? '>' : ''}(${g.conditions.map(getSelectorConditionKey).sort().join(',')})`;\n}\n\n/**\n * Deduplicate variants\n *\n * Removes:\n * 1. Exact duplicates (same key)\n * 2. Superset variants (more restrictive selectors that are redundant)\n */\nfunction dedupeVariants(variants: SelectorVariant[]): SelectorVariant[] {\n // First pass: exact deduplication\n const seen = new Set<string>();\n const result: SelectorVariant[] = [];\n\n for (const v of variants) {\n const key = getVariantKey(v);\n if (!seen.has(key)) {\n seen.add(key);\n result.push(v);\n }\n }\n\n // Second pass: remove supersets (more restrictive variants)\n // Sort by total condition count (fewer conditions = less restrictive = keep)\n const variantConditionCount = (v: SelectorVariant) =>\n v.modifierConditions.length +\n v.pseudoConditions.length +\n v.ownConditions.length +\n v.mediaConditions.length +\n v.containerConditions.length +\n v.supportsConditions.length +\n v.rootConditions.length +\n v.parentGroups.reduce((sum, g) => sum + g.conditions.length, 0);\n result.sort((a, b) => variantConditionCount(a) - variantConditionCount(b));\n\n // Remove variants that are supersets of earlier (less restrictive) variants\n const filtered: SelectorVariant[] = [];\n for (const candidate of result) {\n let isRedundant = false;\n for (const kept of filtered) {\n if (isVariantSuperset(candidate, kept)) {\n isRedundant = true;\n break;\n }\n }\n if (!isRedundant) {\n filtered.push(candidate);\n }\n }\n\n return filtered;\n}\n\n/**\n * Combine AND conditions into CSS\n *\n * AND of conditions means cartesian product of variants:\n * (A1 | A2) & (B1 | B2) = A1&B1 | A1&B2 | A2&B1 | A2&B2\n *\n * Variants that result in contradictions (e.g., conflicting media rules)\n * are filtered out.\n */\nfunction andToCSS(children: ConditionNode[]): CSSComponents {\n // Start with a single empty variant\n let currentVariants: SelectorVariant[] = [emptyVariant()];\n\n for (const child of children) {\n const childCSS = conditionToCSSInner(child);\n\n if (childCSS.isImpossible || childCSS.variants.length === 0) {\n return { variants: [], isImpossible: true };\n }\n\n // Cartesian product: each current variant × each child variant\n const newVariants: SelectorVariant[] = [];\n for (const current of currentVariants) {\n for (const childVariant of childCSS.variants) {\n const merged = mergeVariants(current, childVariant);\n // Skip impossible variants (contradictions detected during merge)\n if (merged !== null) {\n newVariants.push(merged);\n }\n }\n }\n\n if (newVariants.length === 0) {\n return { variants: [], isImpossible: true };\n }\n\n // Deduplicate after each step to prevent exponential blowup\n currentVariants = dedupeVariants(newVariants);\n }\n\n return {\n variants: currentVariants,\n isImpossible: false,\n };\n}\n\n/**\n * Combine OR conditions into CSS\n *\n * OR in CSS means multiple selector variants (DNF).\n * Each variant becomes a separate selector in the comma-separated list,\n * or multiple CSS rules if they have different at-rules.\n *\n * Note: OR exclusivity is handled at the pipeline level (expandOrConditions),\n * so here we just collect all variants. Any remaining ORs in the condition\n * tree (e.g., from De Morgan expansion) are handled as simple alternatives.\n */\nfunction orToCSS(children: ConditionNode[]): CSSComponents {\n const allVariants: SelectorVariant[] = [];\n\n for (const child of children) {\n const childCSS = conditionToCSSInner(child);\n if (childCSS.isImpossible) continue;\n\n allVariants.push(...childCSS.variants);\n }\n\n if (allVariants.length === 0) {\n return { variants: [], isImpossible: true };\n }\n\n // Deduplicate variants\n return {\n variants: dedupeVariants(allVariants),\n isImpossible: false,\n };\n}\n\n// ============================================================================\n// Utility Functions\n// ============================================================================\n\n/**\n * Build at-rules array from a variant\n */\nexport function buildAtRulesFromVariant(variant: SelectorVariant): string[] {\n const atRules: string[] = [];\n\n // Add media rules - combine all conditions with \"and\"\n if (variant.mediaConditions.length > 0) {\n const conditionParts = variant.mediaConditions.map((c) => {\n if (c.subtype === 'type') {\n // Media type: print, screen, etc.\n return c.negated ? `not ${c.condition}` : c.condition;\n } else {\n // Feature or dimension: use not (condition) syntax for negation\n // MQ Level 4 requires parentheses around the condition for negation\n return c.negated ? `(not ${c.condition})` : c.condition;\n }\n });\n atRules.push(`@media ${conditionParts.join(' and ')}`);\n }\n\n // Add container rules - group by container name and combine with \"and\"\n if (variant.containerConditions.length > 0) {\n // Group conditions by container name (undefined = unnamed/nearest)\n const byName = new Map<string | undefined, ParsedContainerCondition[]>();\n for (const cond of variant.containerConditions) {\n const group = byName.get(cond.name) || [];\n group.push(cond);\n byName.set(cond.name, group);\n }\n\n // Build one @container rule per container name\n for (const [name, conditions] of byName) {\n // CSS Container Query syntax requires parentheses around negated conditions:\n // @container (not style(--x)) and style(--y) - NOT @container not style(--x) and style(--y)\n const conditionParts = conditions.map((c) =>\n c.negated ? `(not ${c.condition})` : c.condition,\n );\n const namePrefix = name ? `${name} ` : '';\n atRules.push(`@container ${namePrefix}${conditionParts.join(' and ')}`);\n }\n }\n\n // Add supports rules - combine all conditions with \"and\"\n if (variant.supportsConditions.length > 0) {\n const conditionParts = variant.supportsConditions.map((c) => {\n // Build the condition based on subtype\n // feature: (display: grid) or (not (display: grid))\n // selector: selector(:has(*)) or (not selector(:has(*)))\n if (c.subtype === 'selector') {\n const selectorCond = `selector(${c.condition})`;\n return c.negated ? `(not ${selectorCond})` : selectorCond;\n } else {\n const featureCond = `(${c.condition})`;\n return c.negated ? `(not ${featureCond})` : featureCond;\n }\n });\n atRules.push(`@supports ${conditionParts.join(' and ')}`);\n }\n\n // Add starting-style\n if (variant.startingStyle) {\n atRules.push('@starting-style');\n }\n\n return atRules;\n}\n"],"mappings":";;;;;;;;;;AAwLA,MAAM,iBAAiB,IAAI,IAA2B,IAAK;;;;AAS3D,SAAgB,eAAe,MAAoC;CAEjE,MAAM,MAAM,qBAAqB,KAAK;CACtC,MAAM,SAAS,eAAe,IAAI,IAAI;AACtC,KAAI,OACF,QAAO;CAGT,MAAM,SAAS,oBAAoB,KAAK;AAGxC,gBAAe,IAAI,KAAK,OAAO;AAE/B,QAAO;;AAcT,SAAS,eAAgC;AACvC,QAAO;EACL,oBAAoB,EAAE;EACtB,kBAAkB,EAAE;EACpB,eAAe,EAAE;EACjB,iBAAiB,EAAE;EACnB,qBAAqB,EAAE;EACvB,oBAAoB,EAAE;EACtB,gBAAgB,EAAE;EAClB,cAAc,EAAE;EAChB,eAAe;EAChB;;AAGH,SAAS,oBAAoB,MAAoC;AAE/D,KAAI,KAAK,SAAS,OAChB,QAAO;EACL,UAAU,CAAC,cAAc,CAAC;EAC1B,cAAc;EACf;AAIH,KAAI,KAAK,SAAS,QAChB,QAAO;EACL,UAAU,EAAE;EACZ,cAAc;EACf;AAIH,KAAI,KAAK,SAAS,QAChB,QAAO,WAAW,KAAK;AAIzB,KAAI,KAAK,SAAS,WAChB,KAAI,KAAK,aAAa,MACpB,QAAO,SAAS,KAAK,SAAS;KAE9B,QAAO,QAAQ,KAAK,SAAS;AAKjC,QAAO;EACL,UAAU,CAAC,cAAc,CAAC;EAC1B,cAAc;EACf;;;;;AAMH,SAAS,WAAW,OAAsC;AACxD,S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AK,UAAU,eAAe,KAAK,QAAQ,GAAG;;AAIxD,KAAI,QAAQ,oBAAoB,SAAS,GAAG;EAE1C,MAAM,yBAAS,IAAI,KAAqD;AACxE,OAAK,MAAM,QAAQ,QAAQ,qBAAqB;GAC9C,MAAM,QAAQ,OAAO,IAAI,KAAK,KAAK,IAAI,EAAE;AACzC,SAAM,KAAK,KAAK;AAChB,UAAO,IAAI,KAAK,MAAM,MAAM;;AAI9B,OAAK,MAAM,CAAC,MAAM,eAAe,QAAQ;GAGvC,MAAM,iBAAiB,WAAW,KAAK,MACrC,EAAE,UAAU,QAAQ,EAAE,UAAU,KAAK,EAAE,UACxC;GACD,MAAM,aAAa,OAAO,GAAG,KAAK,KAAK;AACvC,WAAQ,KAAK,cAAc,aAAa,eAAe,KAAK,QAAQ,GAAG;;;AAK3E,KAAI,QAAQ,mBAAmB,SAAS,GAAG;EACzC,MAAM,iBAAiB,QAAQ,mBAAmB,KAAK,MAAM;AAI3D,OAAI,EAAE,YAAY,YAAY;IAC5B,MAAM,eAAe,YAAY,EAAE,UAAU;AAC7C,WAAO,EAAE,UAAU,QAAQ,aAAa,KAAK;UACxC;IACL,MAAM,cAAc,IAAI,EAAE,UAAU;AACpC,WAAO,EAAE,UAAU,QAAQ,YAAY,KAAK;;IAE9C;AACF,UAAQ,KAAK,aAAa,eAAe,KAAK,QAAQ,GAAG;;AAI3D,KAAI,QAAQ,cACV,SAAQ,KAAK,kBAAkB;AAGjC,QAAO"}
@@ -2,6 +2,7 @@ import { Lru } from "../parser/lru.js";
2
2
  import { expandDimensionShorthands, expandTastyUnits, findTopLevelComma, resolvePredefinedState } from "../states/index.js";
3
3
  import { camelToKebab } from "../utils/case-converter.js";
4
4
  import { and, createContainerDimensionCondition, createContainerRawCondition, createContainerStyleCondition, createMediaDimensionCondition, createMediaFeatureCondition, createMediaTypeCondition, createModifierCondition, createOwnCondition, createParentCondition, createPseudoCondition, createRootCondition, createStartingCondition, createSupportsCondition, not, or, trueCondition } from "./conditions.js";
5
+ import { emitWarning } from "./warnings.js";
5
6
 
6
7
  //#region src/pipeline/parseStateKey.ts
7
8
  /**
@@ -10,6 +11,12 @@ import { and, createContainerDimensionCondition, createContainerRawCondition, cr
10
11
  * Parses state notation strings (like 'hovered & !disabled', '@media(w < 768px)')
11
12
  * into ConditionNode trees for processing in the pipeline.
12
13
  */
14
+ /**
15
+ * Maximum XOR operands before emitting a performance warning.
16
+ * A ^ B ^ C ^ D = 8 OR branches (2^(n-1)), so chains above 4
17
+ * risk exponential blowup in downstream processing.
18
+ */
19
+ const MAX_XOR_CHAIN_LENGTH = 4;
13
20
  const parseCache = new Lru(5e3);
14
21
  /**
15
22
  * Pattern for tokenizing state notation.
@@ -150,9 +157,12 @@ var Parser = class {
150
157
  }
151
158
  parseXor() {
152
159
  let left = this.parseUnary();
160
+ let operandCount = 1;
153
161
  while (this.current()?.type === "XOR") {
154
162
  this.advance();
155
163
  const right = this.parseUnary();
164
+ operandCount++;
165
+ if (operandCount > MAX_XOR_CHAIN_LENGTH) emitWarning("XOR_CHAIN_TOO_LONG", `XOR chain with ${operandCount} operands produces ${Math.pow(2, operandCount - 1)} OR branches. Consider breaking into smaller expressions to avoid exponential growth.`);
156
166
  left = or(and(left, not(right)), and(not(left), right));
157
167
  }
158
168
  return left;
@@ -291,10 +301,13 @@ var Parser = class {
291
301
  /**
292
302
  * Parse @root(...) state
293
303
  */
294
- parseRootState(raw) {
295
- const content = raw.slice(6, -1);
304
+ parseInnerCondition(raw, prefixLen, wrap) {
305
+ const content = raw.slice(prefixLen, -1);
296
306
  if (!content.trim()) return trueCondition();
297
- return createRootCondition(parseStateKey(content, this.options), false, raw);
307
+ return wrap(parseStateKey(content, this.options));
308
+ }
309
+ parseRootState(raw) {
310
+ return this.parseInnerCondition(raw, 6, (inner) => createRootCondition(inner, false, raw));
298
311
  }
299
312
  /**
300
313
  * Parse @parent(...) state
@@ -332,13 +345,8 @@ var Parser = class {
332
345
  if (content.startsWith("$,")) return createSupportsCondition("selector", content.slice(2).trim(), false, raw);
333
346
  return createSupportsCondition("feature", content, false, raw);
334
347
  }
335
- /**
336
- * Parse @own(...) state
337
- */
338
348
  parseOwnState(raw) {
339
- const content = raw.slice(5, -1);
340
- if (!content.trim()) return trueCondition();
341
- return createOwnCondition(parseStateKey(content, this.options), false, raw);
349
+ return this.parseInnerCondition(raw, 5, (inner) => createOwnCondition(inner, false, raw));
342
350
  }
343
351
  /**
344
352
  * Parse @(...) container query