@tenphi/tasty 0.0.0-snapshot.b3fbcbb → 0.0.0-snapshot.b478bc9

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 (319) hide show
  1. package/README.md +297 -208
  2. package/dist/_virtual/_rolldown/runtime.js +1 -2
  3. package/dist/chunks/cacheKey.d.ts +1 -0
  4. package/dist/chunks/cacheKey.js +17 -10
  5. package/dist/chunks/cacheKey.js.map +1 -1
  6. package/dist/chunks/definitions.d.ts +1 -1
  7. package/dist/chunks/definitions.js +3 -5
  8. package/dist/chunks/definitions.js.map +1 -1
  9. package/dist/chunks/index.d.ts +1 -0
  10. package/dist/chunks/renderChunk.d.ts +1 -0
  11. package/dist/chunks/renderChunk.js +32 -34
  12. package/dist/chunks/renderChunk.js.map +1 -1
  13. package/dist/compute-styles.d.ts +31 -0
  14. package/dist/compute-styles.js +322 -0
  15. package/dist/compute-styles.js.map +1 -0
  16. package/dist/config.d.ts +149 -30
  17. package/dist/config.js +233 -45
  18. package/dist/config.js.map +1 -1
  19. package/dist/core/index.d.ts +12 -11
  20. package/dist/core/index.js +12 -11
  21. package/dist/counter-style/index.js +51 -0
  22. package/dist/counter-style/index.js.map +1 -0
  23. package/dist/debug.d.ts +26 -141
  24. package/dist/debug.js +359 -639
  25. package/dist/debug.js.map +1 -1
  26. package/dist/font-face/index.js +63 -0
  27. package/dist/font-face/index.js.map +1 -0
  28. package/dist/hooks/index.d.ts +7 -0
  29. package/dist/hooks/useCounterStyle.d.ts +36 -0
  30. package/dist/hooks/useCounterStyle.js +65 -0
  31. package/dist/hooks/useCounterStyle.js.map +1 -0
  32. package/dist/hooks/useFontFace.d.ts +45 -0
  33. package/dist/hooks/useFontFace.js +66 -0
  34. package/dist/hooks/useFontFace.js.map +1 -0
  35. package/dist/hooks/useGlobalStyles.d.ts +21 -2
  36. package/dist/hooks/useGlobalStyles.js +60 -28
  37. package/dist/hooks/useGlobalStyles.js.map +1 -1
  38. package/dist/hooks/useKeyframes.d.ts +4 -2
  39. package/dist/hooks/useKeyframes.js +44 -43
  40. package/dist/hooks/useKeyframes.js.map +1 -1
  41. package/dist/hooks/useProperty.d.ts +4 -2
  42. package/dist/hooks/useProperty.js +36 -31
  43. package/dist/hooks/useProperty.js.map +1 -1
  44. package/dist/hooks/useRawCSS.d.ts +13 -44
  45. package/dist/hooks/useRawCSS.js +91 -16
  46. package/dist/hooks/useRawCSS.js.map +1 -1
  47. package/dist/hooks/useStyles.d.ts +3 -3
  48. package/dist/hooks/useStyles.js +8 -146
  49. package/dist/hooks/useStyles.js.map +1 -1
  50. package/dist/index.d.ts +15 -12
  51. package/dist/index.js +15 -12
  52. package/dist/injector/index.d.ts +36 -11
  53. package/dist/injector/index.js +43 -12
  54. package/dist/injector/index.js.map +1 -1
  55. package/dist/injector/injector.d.ts +62 -3
  56. package/dist/injector/injector.js +256 -31
  57. package/dist/injector/injector.js.map +1 -1
  58. package/dist/injector/sheet-manager.d.ts +10 -13
  59. package/dist/injector/sheet-manager.js +42 -71
  60. package/dist/injector/sheet-manager.js.map +1 -1
  61. package/dist/injector/types.d.ts +112 -21
  62. package/dist/keyframes/index.js +1 -1
  63. package/dist/parser/classify.js +6 -6
  64. package/dist/parser/classify.js.map +1 -1
  65. package/dist/parser/const.js +30 -3
  66. package/dist/parser/const.js.map +1 -1
  67. package/dist/parser/lru.js +1 -1
  68. package/dist/parser/lru.js.map +1 -1
  69. package/dist/parser/parser.js +2 -3
  70. package/dist/parser/parser.js.map +1 -1
  71. package/dist/parser/tokenizer.js +1 -1
  72. package/dist/parser/tokenizer.js.map +1 -1
  73. package/dist/parser/types.js +1 -1
  74. package/dist/parser/types.js.map +1 -1
  75. package/dist/pipeline/conditions.js +1 -1
  76. package/dist/pipeline/conditions.js.map +1 -1
  77. package/dist/pipeline/exclusive.js +163 -5
  78. package/dist/pipeline/exclusive.js.map +1 -1
  79. package/dist/pipeline/index.d.ts +3 -1
  80. package/dist/pipeline/index.js +172 -83
  81. package/dist/pipeline/index.js.map +1 -1
  82. package/dist/pipeline/materialize-contradictions.js +125 -0
  83. package/dist/pipeline/materialize-contradictions.js.map +1 -0
  84. package/dist/pipeline/materialize.js +437 -243
  85. package/dist/pipeline/materialize.js.map +1 -1
  86. package/dist/pipeline/parseStateKey.d.ts +1 -1
  87. package/dist/pipeline/parseStateKey.js +21 -13
  88. package/dist/pipeline/parseStateKey.js.map +1 -1
  89. package/dist/pipeline/simplify.js +181 -7
  90. package/dist/pipeline/simplify.js.map +1 -1
  91. package/dist/pipeline/warnings.js +1 -1
  92. package/dist/plugins/index.d.ts +2 -0
  93. package/dist/plugins/okhsl-plugin.js +3 -277
  94. package/dist/plugins/okhsl-plugin.js.map +1 -1
  95. package/dist/plugins/types.d.ts +20 -2
  96. package/dist/properties/index.js +15 -30
  97. package/dist/properties/index.js.map +1 -1
  98. package/dist/properties/property-type-resolver.js +13 -2
  99. package/dist/properties/property-type-resolver.js.map +1 -1
  100. package/dist/rsc-cache.js +79 -0
  101. package/dist/rsc-cache.js.map +1 -0
  102. package/dist/ssr/astro-client.d.ts +1 -0
  103. package/dist/ssr/astro-client.js +19 -0
  104. package/dist/ssr/astro-client.js.map +1 -0
  105. package/dist/ssr/astro-middleware.d.ts +15 -0
  106. package/dist/ssr/astro-middleware.js +19 -0
  107. package/dist/ssr/astro-middleware.js.map +1 -0
  108. package/dist/ssr/astro.d.ts +108 -0
  109. package/dist/ssr/astro.js +149 -0
  110. package/dist/ssr/astro.js.map +1 -0
  111. package/dist/ssr/async-storage.d.ts +17 -0
  112. package/dist/ssr/async-storage.js +44 -0
  113. package/dist/ssr/async-storage.js.map +1 -0
  114. package/dist/ssr/collect-auto-properties.js +58 -0
  115. package/dist/ssr/collect-auto-properties.js.map +1 -0
  116. package/dist/ssr/collector.d.ts +98 -0
  117. package/dist/ssr/collector.js +235 -0
  118. package/dist/ssr/collector.js.map +1 -0
  119. package/dist/ssr/context.js +16 -0
  120. package/dist/ssr/context.js.map +1 -0
  121. package/dist/ssr/format-global-rules.js +22 -0
  122. package/dist/ssr/format-global-rules.js.map +1 -0
  123. package/dist/ssr/format-keyframes.js +69 -0
  124. package/dist/ssr/format-keyframes.js.map +1 -0
  125. package/dist/ssr/format-property.js +49 -0
  126. package/dist/ssr/format-property.js.map +1 -0
  127. package/dist/ssr/format-rules.js +73 -0
  128. package/dist/ssr/format-rules.js.map +1 -0
  129. package/dist/ssr/hydrate.d.ts +29 -0
  130. package/dist/ssr/hydrate.js +45 -0
  131. package/dist/ssr/hydrate.js.map +1 -0
  132. package/dist/ssr/index.d.ts +4 -0
  133. package/dist/ssr/index.js +10 -0
  134. package/dist/ssr/index.js.map +1 -0
  135. package/dist/ssr/next.d.ts +46 -0
  136. package/dist/ssr/next.js +75 -0
  137. package/dist/ssr/next.js.map +1 -0
  138. package/dist/ssr/ssr-collector-ref.js +29 -0
  139. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  140. package/dist/states/index.js +13 -259
  141. package/dist/states/index.js.map +1 -1
  142. package/dist/static/index.js +1 -2
  143. package/dist/static/inject.d.ts +5 -0
  144. package/dist/static/inject.js +17 -0
  145. package/dist/static/inject.js.map +1 -0
  146. package/dist/static/tastyStatic.js +1 -2
  147. package/dist/static/tastyStatic.js.map +1 -1
  148. package/dist/static/types.js +1 -1
  149. package/dist/styles/border.d.ts +1 -1
  150. package/dist/styles/border.js +30 -24
  151. package/dist/styles/border.js.map +1 -1
  152. package/dist/styles/color.d.ts +1 -1
  153. package/dist/styles/color.js +11 -8
  154. package/dist/styles/color.js.map +1 -1
  155. package/dist/styles/const.js +17 -0
  156. package/dist/styles/const.js.map +1 -0
  157. package/dist/styles/createStyle.js +28 -26
  158. package/dist/styles/createStyle.js.map +1 -1
  159. package/dist/styles/dimension.js +15 -3
  160. package/dist/styles/dimension.js.map +1 -1
  161. package/dist/styles/directional.js +133 -0
  162. package/dist/styles/directional.js.map +1 -0
  163. package/dist/styles/display.d.ts +3 -10
  164. package/dist/styles/display.js +45 -39
  165. package/dist/styles/display.js.map +1 -1
  166. package/dist/styles/fade.d.ts +1 -1
  167. package/dist/styles/fade.js +9 -5
  168. package/dist/styles/fade.js.map +1 -1
  169. package/dist/styles/fill.d.ts +2 -2
  170. package/dist/styles/fill.js +3 -4
  171. package/dist/styles/fill.js.map +1 -1
  172. package/dist/styles/flow.js +1 -1
  173. package/dist/styles/gap.d.ts +1 -1
  174. package/dist/styles/gap.js +4 -3
  175. package/dist/styles/gap.js.map +1 -1
  176. package/dist/styles/height.d.ts +1 -1
  177. package/dist/styles/height.js +1 -2
  178. package/dist/styles/height.js.map +1 -1
  179. package/dist/styles/index.d.ts +0 -1
  180. package/dist/styles/index.js +3 -4
  181. package/dist/styles/index.js.map +1 -1
  182. package/dist/styles/inset.d.ts +1 -29
  183. package/dist/styles/inset.js +19 -135
  184. package/dist/styles/inset.js.map +1 -1
  185. package/dist/styles/list.d.ts +5 -5
  186. package/dist/styles/list.js +4 -2
  187. package/dist/styles/list.js.map +1 -1
  188. package/dist/styles/margin.d.ts +1 -1
  189. package/dist/styles/margin.js +17 -89
  190. package/dist/styles/margin.js.map +1 -1
  191. package/dist/styles/outline.d.ts +1 -1
  192. package/dist/styles/outline.js +6 -16
  193. package/dist/styles/outline.js.map +1 -1
  194. package/dist/styles/padding.d.ts +1 -1
  195. package/dist/styles/padding.js +17 -89
  196. package/dist/styles/padding.js.map +1 -1
  197. package/dist/styles/placement.d.ts +37 -0
  198. package/dist/styles/placement.js +74 -0
  199. package/dist/styles/placement.js.map +1 -0
  200. package/dist/styles/predefined.d.ts +4 -6
  201. package/dist/styles/predefined.js +9 -13
  202. package/dist/styles/predefined.js.map +1 -1
  203. package/dist/styles/preset.d.ts +6 -1
  204. package/dist/styles/preset.js +54 -53
  205. package/dist/styles/preset.js.map +1 -1
  206. package/dist/styles/radius.d.ts +1 -3
  207. package/dist/styles/radius.js +38 -6
  208. package/dist/styles/radius.js.map +1 -1
  209. package/dist/styles/scrollMargin.d.ts +24 -0
  210. package/dist/styles/scrollMargin.js +32 -0
  211. package/dist/styles/scrollMargin.js.map +1 -0
  212. package/dist/styles/scrollbar.d.ts +9 -5
  213. package/dist/styles/scrollbar.js +31 -92
  214. package/dist/styles/scrollbar.js.map +1 -1
  215. package/dist/styles/shadow.d.ts +1 -1
  216. package/dist/styles/shadow.js +4 -3
  217. package/dist/styles/shadow.js.map +1 -1
  218. package/dist/styles/shared.js +17 -0
  219. package/dist/styles/shared.js.map +1 -0
  220. package/dist/styles/transition.d.ts +1 -1
  221. package/dist/styles/transition.js +6 -5
  222. package/dist/styles/transition.js.map +1 -1
  223. package/dist/styles/types.d.ts +94 -28
  224. package/dist/styles/width.d.ts +1 -1
  225. package/dist/styles/width.js +1 -2
  226. package/dist/styles/width.js.map +1 -1
  227. package/dist/tasty.d.ts +46 -894
  228. package/dist/tasty.js +101 -59
  229. package/dist/tasty.js.map +1 -1
  230. package/dist/types.d.ts +1 -1
  231. package/dist/utils/cache-wrapper.js +4 -9
  232. package/dist/utils/cache-wrapper.js.map +1 -1
  233. package/dist/utils/case-converter.js +1 -1
  234. package/dist/utils/color-math.d.ts +46 -0
  235. package/dist/utils/color-math.js +749 -0
  236. package/dist/utils/color-math.js.map +1 -0
  237. package/dist/utils/color-space.d.ts +5 -0
  238. package/dist/utils/color-space.js +228 -0
  239. package/dist/utils/color-space.js.map +1 -0
  240. package/dist/utils/colors.js +3 -2
  241. package/dist/utils/colors.js.map +1 -1
  242. package/dist/utils/deps-equal.js +15 -0
  243. package/dist/utils/deps-equal.js.map +1 -0
  244. package/dist/utils/dotize.js +1 -1
  245. package/dist/utils/dotize.js.map +1 -1
  246. package/dist/utils/filter-base-props.d.ts +1 -1
  247. package/dist/utils/filter-base-props.js +1 -1
  248. package/dist/utils/filter-base-props.js.map +1 -1
  249. package/dist/utils/get-display-name.js +1 -1
  250. package/dist/utils/has-keys.js +13 -0
  251. package/dist/utils/has-keys.js.map +1 -0
  252. package/dist/utils/hash.js +14 -0
  253. package/dist/utils/hash.js.map +1 -0
  254. package/dist/utils/is-dev-env.js +1 -1
  255. package/dist/utils/is-dev-env.js.map +1 -1
  256. package/dist/utils/is-valid-element-type.js +1 -1
  257. package/dist/utils/merge-styles.js +1 -2
  258. package/dist/utils/merge-styles.js.map +1 -1
  259. package/dist/utils/mod-attrs.d.ts +0 -2
  260. package/dist/utils/mod-attrs.js +3 -4
  261. package/dist/utils/mod-attrs.js.map +1 -1
  262. package/dist/utils/process-tokens.d.ts +3 -17
  263. package/dist/utils/process-tokens.js +19 -107
  264. package/dist/utils/process-tokens.js.map +1 -1
  265. package/dist/utils/resolve-recipes.js +1 -2
  266. package/dist/utils/resolve-recipes.js.map +1 -1
  267. package/dist/utils/selector-transform.js +32 -0
  268. package/dist/utils/selector-transform.js.map +1 -0
  269. package/dist/utils/string.js +1 -1
  270. package/dist/utils/styles.d.ts +3 -82
  271. package/dist/utils/styles.js +29 -560
  272. package/dist/utils/styles.js.map +1 -1
  273. package/dist/utils/typography.d.ts +35 -13
  274. package/dist/utils/typography.js +16 -18
  275. package/dist/utils/typography.js.map +1 -1
  276. package/dist/utils/warnings.js +1 -1
  277. package/dist/zero/babel.d.ts +57 -89
  278. package/dist/zero/babel.js +214 -40
  279. package/dist/zero/babel.js.map +1 -1
  280. package/dist/zero/css-writer.js +1 -2
  281. package/dist/zero/css-writer.js.map +1 -1
  282. package/dist/zero/extractor.js +54 -3
  283. package/dist/zero/extractor.js.map +1 -1
  284. package/dist/zero/index.js +1 -2
  285. package/dist/zero/next.d.ts +56 -30
  286. package/dist/zero/next.js +105 -40
  287. package/dist/zero/next.js.map +1 -1
  288. package/docs/README.md +31 -0
  289. package/docs/adoption.md +298 -0
  290. package/docs/comparison.md +419 -0
  291. package/docs/configuration.md +394 -0
  292. package/docs/debug.md +320 -0
  293. package/docs/design-system.md +436 -0
  294. package/docs/dsl.md +688 -0
  295. package/docs/getting-started.md +217 -0
  296. package/docs/injector.md +544 -0
  297. package/docs/methodology.md +616 -0
  298. package/docs/pipeline.md +673 -0
  299. package/docs/react-api.md +557 -0
  300. package/docs/ssr.md +442 -0
  301. package/docs/styles.md +596 -0
  302. package/docs/tasty-static.md +532 -0
  303. package/package.json +68 -36
  304. package/dist/styles/align.d.ts +0 -15
  305. package/dist/styles/align.js +0 -14
  306. package/dist/styles/align.js.map +0 -1
  307. package/dist/styles/justify.d.ts +0 -15
  308. package/dist/styles/justify.js +0 -14
  309. package/dist/styles/justify.js.map +0 -1
  310. package/dist/styles/styledScrollbar.d.ts +0 -47
  311. package/dist/styles/styledScrollbar.js +0 -38
  312. package/dist/styles/styledScrollbar.js.map +0 -1
  313. package/dist/tokens/typography.d.ts +0 -19
  314. package/dist/tokens/typography.js +0 -237
  315. package/dist/tokens/typography.js.map +0 -1
  316. package/dist/utils/hsl-to-rgb.js +0 -38
  317. package/dist/utils/hsl-to-rgb.js.map +0 -1
  318. package/dist/utils/okhsl-to-rgb.js +0 -296
  319. package/dist/utils/okhsl-to-rgb.js.map +0 -1
@@ -1,6 +1,7 @@
1
1
  import { Lru } from "../parser/lru.js";
2
- import { getConditionUniqueId, not } from "./conditions.js";
3
-
2
+ import { and, getConditionUniqueId, isCompoundCondition, not } from "./conditions.js";
3
+ import { simplifyCondition } from "./simplify.js";
4
+ import { dedupeContainerConditions, dedupeMediaConditions, dedupeSupportsConditions, hasContainerStyleContradiction, hasMediaContradiction, hasSupportsContradiction } from "./materialize-contradictions.js";
4
5
  //#region src/pipeline/materialize.ts
5
6
  /**
6
7
  * CSS Materialization
@@ -24,11 +25,12 @@ function emptyVariant() {
24
25
  return {
25
26
  modifierConditions: [],
26
27
  pseudoConditions: [],
27
- ownConditions: [],
28
+ selectorGroups: [],
29
+ ownGroups: [],
28
30
  mediaConditions: [],
29
31
  containerConditions: [],
30
32
  supportsConditions: [],
31
- rootConditions: [],
33
+ rootGroups: [],
32
34
  parentGroups: [],
33
35
  startingStyle: false
34
36
  };
@@ -63,9 +65,9 @@ function stateToCSS(state) {
63
65
  }),
64
66
  isImpossible: false
65
67
  };
66
- case "root": return innerConditionToVariants(state.innerCondition, state.negated ?? false, "rootConditions");
68
+ case "root": return innerConditionToVariants(state.innerCondition, state.negated ?? false, "rootGroups");
67
69
  case "parent": return parentConditionToVariants(state.innerCondition, state.negated ?? false, state.direct);
68
- case "own": return innerConditionToVariants(state.innerCondition, state.negated ?? false, "ownConditions");
70
+ case "own": return innerConditionToVariants(state.innerCondition, state.negated ?? false, "ownGroups");
69
71
  case "modifier": {
70
72
  const v = emptyVariant();
71
73
  v.modifierConditions.push(modifierToParsed(state));
@@ -141,14 +143,31 @@ function pseudoToParsed(state) {
141
143
  };
142
144
  }
143
145
  /**
144
- * Convert parsed pseudo to CSS selector string (for final output)
146
+ * Convert parsed pseudo to CSS selector string (for final output).
147
+ *
148
+ * :not() is normalized to negated :is() at parse time, so pseudo.pseudo
149
+ * never starts with ':not(' here. When negated:
150
+ * - :is(X) → :not(X) (unwrap :is)
151
+ * - :where(X) → :not(X) (unwrap :where)
152
+ * - :has(X) → :not(:has(X))
153
+ * - other → :not(other)
154
+ *
155
+ * When not negated, single-argument :is()/:where() is unwrapped when the
156
+ * inner content is a simple compound selector that can safely append to
157
+ * the base selector (this happens after double-negation of :not()).
145
158
  */
146
159
  function pseudoToCSS(pseudo) {
160
+ const p = pseudo.pseudo;
147
161
  if (pseudo.negated) {
148
- if (pseudo.pseudo.startsWith(":not(")) return pseudo.pseudo.slice(5, -1);
149
- return `:not(${pseudo.pseudo})`;
162
+ if (p.startsWith(":is(") || p.startsWith(":where(")) return `:not(${p.slice(p.indexOf("(") + 1, -1)})`;
163
+ return `:not(${p})`;
150
164
  }
151
- return pseudo.pseudo;
165
+ if ((p.startsWith(":is(") || p.startsWith(":where(")) && !p.includes(",")) {
166
+ const inner = p.slice(p.indexOf("(") + 1, -1);
167
+ const ch = inner[0];
168
+ if ((ch === ":" || ch === "." || ch === "[" || ch === "#") && !/\s/.test(inner)) return inner;
169
+ }
170
+ return p;
152
171
  }
153
172
  /**
154
173
  * Convert media condition to parsed structure(s)
@@ -247,40 +266,50 @@ function collectSelectorConditions(variant) {
247
266
  return [...variant.modifierConditions, ...variant.pseudoConditions];
248
267
  }
249
268
  /**
250
- * Convert an inner condition tree into SelectorVariants.
251
- * Each inner OR branch becomes a separate variant, preserving disjunction.
269
+ * Convert an inner condition tree into a single SelectorVariant with
270
+ * one SelectorGroup whose branches represent the inner OR alternatives.
252
271
  * Shared by @root() and @own().
272
+ *
273
+ * Both positive and negated cases produce one variant with one group.
274
+ * Negation simply sets the `negated` flag, which swaps :is() for :not()
275
+ * in the final CSS output — no De Morgan transformation is needed.
276
+ *
277
+ * This mirrors parentConditionToVariants: OR branches are kept inside
278
+ * a single group and rendered as comma-separated arguments in
279
+ * :is()/:not(), e.g. :root:is([a], [b]) or [el]:not([a], [b]).
253
280
  */
254
281
  function innerConditionToVariants(innerCondition, negated, target) {
255
- const innerCSS = conditionToCSS(negated ? not(innerCondition) : innerCondition);
282
+ const innerCSS = conditionToCSS(innerCondition);
256
283
  if (innerCSS.isImpossible || innerCSS.variants.length === 0) return {
257
284
  variants: [],
258
285
  isImpossible: true
259
286
  };
260
- const variants = [];
287
+ const branches = [];
261
288
  for (const innerVariant of innerCSS.variants) {
262
289
  const conditions = collectSelectorConditions(innerVariant);
263
- if (conditions.length > 0) {
264
- const v = emptyVariant();
265
- v[target].push(...conditions);
266
- variants.push(v);
267
- }
290
+ if (conditions.length > 0) branches.push(conditions);
268
291
  }
269
- if (variants.length === 0) return {
292
+ if (branches.length === 0) return {
270
293
  variants: [emptyVariant()],
271
294
  isImpossible: false
272
295
  };
296
+ const v = emptyVariant();
297
+ v[target].push({
298
+ branches,
299
+ negated
300
+ });
273
301
  return {
274
- variants,
302
+ variants: [v],
275
303
  isImpossible: false
276
304
  };
277
305
  }
278
306
  /**
279
- * Convert a @parent() inner condition into SelectorVariants with ParentGroups.
307
+ * Convert a @parent() inner condition into a single SelectorVariant with
308
+ * one ParentGroup whose branches represent the inner OR alternatives.
280
309
  *
281
- * Positive: each inner OR branch becomes a separate variant with one :is() group.
282
- * Negated: !(A | B) = !A & !B — all branches become :not() groups collected
283
- * into a single variant so they produce :not([a] *):not([b] *) on one element.
310
+ * Both positive and negated cases produce one variant with one group.
311
+ * Negation simply sets the `negated` flag, which swaps :is() for :not()
312
+ * in the final CSS output — no structural transformation is needed.
284
313
  */
285
314
  function parentConditionToVariants(innerCondition, negated, direct) {
286
315
  const innerCSS = conditionToCSS(innerCondition);
@@ -288,68 +317,178 @@ function parentConditionToVariants(innerCondition, negated, direct) {
288
317
  variants: [],
289
318
  isImpossible: true
290
319
  };
291
- if (negated) {
292
- const v = emptyVariant();
293
- for (const innerVariant of innerCSS.variants) {
294
- const conditions = collectSelectorConditions(innerVariant);
295
- if (conditions.length > 0) v.parentGroups.push({
296
- conditions,
297
- direct,
298
- negated: true
299
- });
300
- }
301
- if (v.parentGroups.length === 0) return {
302
- variants: [emptyVariant()],
303
- isImpossible: false
304
- };
305
- return {
306
- variants: [v],
307
- isImpossible: false
308
- };
309
- }
310
- const variants = [];
320
+ const branches = [];
311
321
  for (const innerVariant of innerCSS.variants) {
312
322
  const conditions = collectSelectorConditions(innerVariant);
313
- if (conditions.length > 0) {
314
- const v = emptyVariant();
315
- v.parentGroups.push({
316
- conditions,
317
- direct,
318
- negated: false
319
- });
320
- variants.push(v);
321
- }
323
+ if (conditions.length > 0) branches.push(conditions);
322
324
  }
323
- if (variants.length === 0) return {
325
+ if (branches.length === 0) return {
324
326
  variants: [emptyVariant()],
325
327
  isImpossible: false
326
328
  };
329
+ const v = emptyVariant();
330
+ v.parentGroups.push({
331
+ branches,
332
+ direct,
333
+ negated
334
+ });
327
335
  return {
328
- variants,
336
+ variants: [v],
329
337
  isImpossible: false
330
338
  };
331
339
  }
332
340
  /**
333
- * Convert parsed root conditions to CSS selector prefix (for final output)
341
+ * Sort key for canonical condition output within selectors.
342
+ *
343
+ * Priority order:
344
+ * 0: Boolean attribute selectors ([data-hovered])
345
+ * 1: Value attribute selectors ([data-size="small"])
346
+ * 2: Negated boolean attributes (:not([data-disabled]))
347
+ * 3: Negated value attributes (:not([data-size="small"]))
348
+ * 4: Pseudo-classes (:hover, :focus)
349
+ * 5: Negated pseudo-classes (:not(:disabled))
350
+ *
351
+ * Secondary sort: alphabetical by attribute name / pseudo string.
352
+ */
353
+ function conditionSortKey(cond) {
354
+ if ("attribute" in cond) {
355
+ const hasValue = cond.value !== void 0 ? 1 : 0;
356
+ return `${(cond.negated ? 2 : 0) + hasValue}|${cond.attribute}|${cond.value ?? ""}`;
357
+ }
358
+ return `${cond.negated ? 5 : 4}|${cond.pseudo}`;
359
+ }
360
+ function sortConditions(conditions) {
361
+ return conditions.toSorted((a, b) => conditionSortKey(a).localeCompare(conditionSortKey(b)));
362
+ }
363
+ function branchToCSS(branch) {
364
+ let parts = "";
365
+ for (const cond of sortConditions(branch)) parts += selectorConditionToCSS(cond);
366
+ return parts;
367
+ }
368
+ /**
369
+ * Wrap serialized selector arguments in :is() or :not().
370
+ * Arguments are sorted for canonical output.
371
+ */
372
+ function wrapInIsOrNot(args, negated) {
373
+ return `${negated ? ":not" : ":is"}(${args.sort().join(", ")})`;
374
+ }
375
+ /**
376
+ * Convert a selector group to a CSS selector fragment.
377
+ *
378
+ * Single-branch groups are unwrapped (no :is() wrapper).
379
+ * Multi-branch groups use :is() or :not().
380
+ * Negation swaps :is() for :not().
381
+ */
382
+ function selectorGroupToCSS(group) {
383
+ if (group.branches.length === 0) return "";
384
+ if (group.branches.length === 1) {
385
+ const parts = branchToCSS(group.branches[0]);
386
+ if (group.negated) return `:not(${parts})`;
387
+ return parts;
388
+ }
389
+ return wrapInIsOrNot(group.branches.map(branchToCSS), group.negated);
390
+ }
391
+ /**
392
+ * Collect facts about modifier conditions for subsumption analysis.
393
+ * Tracks negated boolean attrs (:not([attr])) and positive exact values ([attr="X"]).
394
+ */
395
+ function collectSubsumptionFacts(modifiers) {
396
+ const negatedBooleanAttrs = /* @__PURE__ */ new Set();
397
+ const positiveExactValuesByAttr = /* @__PURE__ */ new Map();
398
+ for (const mod of modifiers) {
399
+ if (mod.negated && mod.value === void 0) negatedBooleanAttrs.add(mod.attribute);
400
+ if (!mod.negated && mod.value !== void 0 && (mod.operator ?? "=") === "=") {
401
+ let vals = positiveExactValuesByAttr.get(mod.attribute);
402
+ if (!vals) {
403
+ vals = /* @__PURE__ */ new Set();
404
+ positiveExactValuesByAttr.set(mod.attribute, vals);
405
+ }
406
+ vals.add(mod.value);
407
+ }
408
+ }
409
+ return {
410
+ negatedBooleanAttrs,
411
+ positiveExactValuesByAttr
412
+ };
413
+ }
414
+ /**
415
+ * Check if a negated-value modifier is subsumed by stronger facts:
416
+ * - :not([attr]) subsumes :not([attr="val"])
417
+ * - [attr="X"] implies :not([attr="Y"]) is redundant (single exact value)
418
+ *
419
+ * Only applies to exact-match (=) operators; substring operators don't
420
+ * imply exclusivity between values.
421
+ */
422
+ function isSubsumedNegatedModifier(mod, facts) {
423
+ if (!mod.negated || mod.value === void 0) return false;
424
+ if (facts.negatedBooleanAttrs.has(mod.attribute)) return true;
425
+ if ((mod.operator ?? "=") === "=") {
426
+ const posVals = facts.positiveExactValuesByAttr.get(mod.attribute);
427
+ if (posVals && posVals.size === 1 && !posVals.has(mod.value)) return true;
428
+ }
429
+ return false;
430
+ }
431
+ /**
432
+ * Remove redundant single-condition groups that are subsumed by stronger
433
+ * groups on the same attribute. O(n) — only inspects single-branch,
434
+ * single-condition groups.
334
435
  */
335
- function rootConditionsToCSS(roots) {
336
- if (roots.length === 0) return void 0;
436
+ function optimizeGroups(groups) {
437
+ if (groups.length <= 1) return groups;
438
+ const seen = /* @__PURE__ */ new Set();
439
+ const result = [];
440
+ for (const g of groups) {
441
+ const key = getSelectorGroupKey(g);
442
+ if (!seen.has(key)) {
443
+ seen.add(key);
444
+ result.push(g);
445
+ }
446
+ }
447
+ if (result.length <= 1) return result;
448
+ const effectiveModifiers = [];
449
+ for (const g of result) {
450
+ if (g.branches.length !== 1 || g.branches[0].length !== 1) continue;
451
+ const cond = g.branches[0][0];
452
+ if (!("attribute" in cond)) continue;
453
+ effectiveModifiers.push({
454
+ ...cond,
455
+ negated: g.negated !== cond.negated
456
+ });
457
+ }
458
+ const facts = collectSubsumptionFacts(effectiveModifiers);
459
+ if (facts.negatedBooleanAttrs.size === 0 && facts.positiveExactValuesByAttr.size === 0) return result;
460
+ return result.filter((g) => {
461
+ if (g.branches.length !== 1 || g.branches[0].length !== 1) return true;
462
+ const cond = g.branches[0][0];
463
+ if (!("attribute" in cond) || !g.negated || cond.negated || cond.value === void 0) return true;
464
+ return !isSubsumedNegatedModifier({
465
+ ...cond,
466
+ negated: true
467
+ }, facts);
468
+ });
469
+ }
470
+ /**
471
+ * Convert root groups to CSS selector prefix (for final output)
472
+ */
473
+ function rootGroupsToCSS(groups) {
474
+ if (groups.length === 0) return void 0;
475
+ const optimized = optimizeGroups(groups);
476
+ if (optimized.length === 0) return void 0;
337
477
  let prefix = ":root";
338
- for (const cond of roots) prefix += selectorConditionToCSS(cond);
478
+ for (const group of optimized) prefix += selectorGroupToCSS(group);
339
479
  return prefix;
340
480
  }
341
481
  /**
342
482
  * Convert parent groups to CSS selector fragments (for final output).
343
- * Each group produces its own :is() wrapper.
483
+ * Each group produces its own :is()/:not() wrapper with a combinator
484
+ * suffix (` *` or ` > *`) appended to each branch.
344
485
  */
345
486
  function parentGroupsToCSS(groups) {
346
487
  let result = "";
347
488
  for (const group of groups) {
348
489
  const combinator = group.direct ? " > *" : " *";
349
- let parts = "";
350
- for (const cond of group.conditions) parts += selectorConditionToCSS(cond);
351
- const wrapper = group.negated ? ":not" : ":is";
352
- result += `${wrapper}(${parts}${combinator})`;
490
+ const args = group.branches.map((branch) => branchToCSS(branch) + combinator);
491
+ result += wrapInIsOrNot(args, group.negated);
353
492
  }
354
493
  return result;
355
494
  }
@@ -385,7 +524,7 @@ function getSelectorConditionKey(cond) {
385
524
  */
386
525
  function dedupeSelectorConditions(conditions) {
387
526
  const seen = /* @__PURE__ */ new Set();
388
- let result = [];
527
+ const result = [];
389
528
  for (const c of conditions) {
390
529
  const key = getSelectorConditionKey(c);
391
530
  if (!seen.has(key)) {
@@ -393,30 +532,12 @@ function dedupeSelectorConditions(conditions) {
393
532
  result.push(c);
394
533
  }
395
534
  }
396
- const negatedBooleanAttrs = /* @__PURE__ */ new Set();
397
- const positiveExactValuesByAttr = /* @__PURE__ */ new Map();
398
- for (const c of result) {
399
- if (!("attribute" in c)) continue;
400
- if (c.negated && c.value === void 0) negatedBooleanAttrs.add(c.attribute);
401
- const op = c.operator ?? "=";
402
- if (!c.negated && c.value !== void 0 && op === "=") {
403
- let values = positiveExactValuesByAttr.get(c.attribute);
404
- if (!values) {
405
- values = /* @__PURE__ */ new Set();
406
- positiveExactValuesByAttr.set(c.attribute, values);
407
- }
408
- values.add(c.value);
409
- }
410
- }
411
- result = result.filter((c) => {
412
- if (!("attribute" in c) || !c.negated || c.value === void 0) return true;
413
- if (negatedBooleanAttrs.has(c.attribute)) return false;
414
- if ((c.operator ?? "=") !== "=") return true;
415
- const positiveValues = positiveExactValuesByAttr.get(c.attribute);
416
- if (positiveValues !== void 0 && positiveValues.size === 1 && !positiveValues.has(c.value)) return false;
417
- return true;
535
+ const facts = collectSubsumptionFacts(result.filter((c) => "attribute" in c));
536
+ if (facts.negatedBooleanAttrs.size === 0 && facts.positiveExactValuesByAttr.size === 0) return result;
537
+ return result.filter((c) => {
538
+ if (!("attribute" in c)) return true;
539
+ return !isSubsumedNegatedModifier(c, facts);
418
540
  });
419
- return result;
420
541
  }
421
542
  /**
422
543
  * Check for modifier contradiction: same attribute with opposite negation
@@ -459,10 +580,32 @@ function hasSelectorConditionContradiction(conditions) {
459
580
  * with opposite negation. E.g. :not([data-hovered] *) and :is([data-hovered] *)
460
581
  * in the same variant is impossible.
461
582
  */
583
+ function getBranchesKey(branches) {
584
+ if (branches.length === 1) {
585
+ const b = branches[0];
586
+ if (b.length === 1) return getSelectorConditionKey(b[0]);
587
+ return b.map(getSelectorConditionKey).sort().join("+");
588
+ }
589
+ return branches.map((b) => b.map(getSelectorConditionKey).sort().join("+")).sort().join(",");
590
+ }
462
591
  function hasParentGroupContradiction(groups) {
463
592
  const byBaseKey = /* @__PURE__ */ new Map();
464
593
  for (const g of groups) {
465
- const baseKey = `${g.direct ? ">" : ""}(${g.conditions.map(getSelectorConditionKey).sort().join(",")})`;
594
+ const baseKey = `${g.direct ? ">" : ""}(${getBranchesKey(g.branches)})`;
595
+ const existing = byBaseKey.get(baseKey);
596
+ if (existing !== void 0 && existing !== !g.negated) return true;
597
+ byBaseKey.set(baseKey, !g.negated);
598
+ }
599
+ return false;
600
+ }
601
+ /**
602
+ * Check for selector group contradiction: same branches with opposite negation.
603
+ * E.g. :is([data-a]) and :not([data-a]) in the same variant is impossible.
604
+ */
605
+ function hasSelectorGroupContradiction(groups) {
606
+ const byBaseKey = /* @__PURE__ */ new Map();
607
+ for (const g of groups) {
608
+ const baseKey = getBranchesKey(g.branches);
466
609
  const existing = byBaseKey.get(baseKey);
467
610
  if (existing !== void 0 && existing !== !g.negated) return true;
468
611
  byBaseKey.set(baseKey, !g.negated);
@@ -476,15 +619,17 @@ function hasParentGroupContradiction(groups) {
476
619
  function mergeVariants(a, b) {
477
620
  const mergedMedia = dedupeMediaConditions([...a.mediaConditions, ...b.mediaConditions]);
478
621
  if (hasMediaContradiction(mergedMedia)) return null;
479
- const mergedRoots = dedupeSelectorConditions([...a.rootConditions, ...b.rootConditions]);
480
- if (hasSelectorConditionContradiction(mergedRoots)) return null;
622
+ const mergedRootGroups = optimizeGroups([...a.rootGroups, ...b.rootGroups]);
623
+ if (hasSelectorGroupContradiction(mergedRootGroups)) return null;
481
624
  const mergedModifiers = dedupeSelectorConditions([...a.modifierConditions, ...b.modifierConditions]);
482
625
  const mergedPseudos = dedupeSelectorConditions([...a.pseudoConditions, ...b.pseudoConditions]);
483
626
  if (hasSelectorConditionContradiction([...mergedModifiers, ...mergedPseudos])) return null;
627
+ const mergedSelectorGroups = optimizeGroups([...a.selectorGroups, ...b.selectorGroups]);
628
+ if (hasSelectorGroupContradiction(mergedSelectorGroups)) return null;
484
629
  const mergedParentGroups = [...a.parentGroups, ...b.parentGroups];
485
630
  if (hasParentGroupContradiction(mergedParentGroups)) return null;
486
- const mergedOwn = dedupeSelectorConditions([...a.ownConditions, ...b.ownConditions]);
487
- if (hasSelectorConditionContradiction(mergedOwn)) return null;
631
+ const mergedOwnGroups = optimizeGroups([...a.ownGroups, ...b.ownGroups]);
632
+ if (hasSelectorGroupContradiction(mergedOwnGroups)) return null;
488
633
  const mergedContainers = dedupeContainerConditions([...a.containerConditions, ...b.containerConditions]);
489
634
  if (hasContainerStyleContradiction(mergedContainers)) return null;
490
635
  const mergedSupports = dedupeSupportsConditions([...a.supportsConditions, ...b.supportsConditions]);
@@ -492,163 +637,61 @@ function mergeVariants(a, b) {
492
637
  return {
493
638
  modifierConditions: mergedModifiers,
494
639
  pseudoConditions: mergedPseudos,
495
- ownConditions: mergedOwn,
640
+ selectorGroups: mergedSelectorGroups,
641
+ ownGroups: mergedOwnGroups,
496
642
  mediaConditions: mergedMedia,
497
643
  containerConditions: mergedContainers,
498
644
  supportsConditions: mergedSupports,
499
- rootConditions: mergedRoots,
645
+ rootGroups: mergedRootGroups,
500
646
  parentGroups: mergedParentGroups,
501
647
  startingStyle: a.startingStyle || b.startingStyle
502
648
  };
503
649
  }
504
- /**
505
- * Generic deduplication by a key extraction function.
506
- * Preserves insertion order, keeping the first occurrence of each key.
507
- */
508
- function dedupeByKey(items, getKey) {
509
- const seen = /* @__PURE__ */ new Set();
510
- const result = [];
511
- for (const item of items) {
512
- const key = getKey(item);
513
- if (!seen.has(key)) {
514
- seen.add(key);
515
- result.push(item);
516
- }
517
- }
518
- return result;
519
- }
520
- function dedupeMediaConditions(conditions) {
521
- return dedupeByKey(conditions, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
522
- }
523
- function dedupeContainerConditions(conditions) {
524
- return dedupeByKey(conditions, (c) => `${c.name ?? ""}|${c.condition}|${c.negated}`);
525
- }
526
- function dedupeSupportsConditions(conditions) {
527
- return dedupeByKey(conditions, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
528
- }
529
- /**
530
- * Check if supports conditions contain contradictions
531
- * e.g., @supports(display: grid) AND NOT @supports(display: grid)
532
- */
533
- function hasSupportsContradiction(conditions) {
534
- const conditionMap = /* @__PURE__ */ new Map();
535
- for (const cond of conditions) {
536
- const key = `${cond.subtype}|${cond.condition}`;
537
- const existing = conditionMap.get(key);
538
- if (existing !== void 0 && existing !== !cond.negated) return true;
539
- conditionMap.set(key, !cond.negated);
540
- }
541
- return false;
542
- }
543
- /**
544
- * Check if a set of media conditions contains contradictions
545
- * e.g., (prefers-color-scheme: light) AND NOT (prefers-color-scheme: light)
546
- * or (width >= 900px) AND (width < 600px)
547
- *
548
- * Uses parsed media conditions for efficient analysis without regex parsing.
549
- */
550
- function hasMediaContradiction(conditions) {
551
- const featureConditions = /* @__PURE__ */ new Map();
552
- const typeConditions = /* @__PURE__ */ new Map();
553
- const dimensionConditions = /* @__PURE__ */ new Map();
554
- const dimensionsByDim = /* @__PURE__ */ new Map();
555
- for (const cond of conditions) if (cond.subtype === "type") {
556
- const key = cond.mediaType || "all";
557
- const existing = typeConditions.get(key);
558
- if (existing !== void 0 && existing !== !cond.negated) return true;
559
- typeConditions.set(key, !cond.negated);
560
- } else if (cond.subtype === "feature") {
561
- const key = cond.condition;
562
- const existing = featureConditions.get(key);
563
- if (existing !== void 0 && existing !== !cond.negated) return true;
564
- featureConditions.set(key, !cond.negated);
565
- } else if (cond.subtype === "dimension") {
566
- const condKey = cond.condition;
567
- const existing = dimensionConditions.get(condKey);
568
- if (existing !== void 0 && existing !== !cond.negated) return true;
569
- dimensionConditions.set(condKey, !cond.negated);
570
- if (!cond.negated) {
571
- const dim = cond.dimension || "width";
572
- let bounds = dimensionsByDim.get(dim);
573
- if (!bounds) {
574
- bounds = {
575
- lowerBound: null,
576
- upperBound: null
577
- };
578
- dimensionsByDim.set(dim, bounds);
579
- }
580
- if (cond.lowerBound?.valueNumeric != null) {
581
- const value = cond.lowerBound.valueNumeric;
582
- if (bounds.lowerBound === null || value > bounds.lowerBound) bounds.lowerBound = value;
583
- }
584
- if (cond.upperBound?.valueNumeric != null) {
585
- const value = cond.upperBound.valueNumeric;
586
- if (bounds.upperBound === null || value < bounds.upperBound) bounds.upperBound = value;
587
- }
588
- if (bounds.lowerBound !== null && bounds.upperBound !== null && bounds.lowerBound >= bounds.upperBound) return true;
589
- }
590
- }
591
- return false;
592
- }
593
- /**
594
- * Check if container conditions contain contradictions in style queries
595
- * e.g., style(--variant: danger) and style(--variant: success) together
596
- * Same property with different values = always false
597
- *
598
- * Uses parsed container conditions for efficient analysis without regex parsing.
599
- */
600
- function hasContainerStyleContradiction(conditions) {
601
- const styleQueries = /* @__PURE__ */ new Map();
602
- for (const cond of conditions) {
603
- if (cond.subtype !== "style" || !cond.property) continue;
604
- const property = cond.property;
605
- const value = cond.propertyValue;
606
- if (!styleQueries.has(property)) styleQueries.set(property, {
607
- hasExistence: false,
608
- values: /* @__PURE__ */ new Set(),
609
- hasNegatedExistence: false
610
- });
611
- const entry = styleQueries.get(property);
612
- if (cond.negated) {
613
- if (value === void 0) entry.hasNegatedExistence = true;
614
- } else if (value === void 0) entry.hasExistence = true;
615
- else entry.values.add(value);
616
- }
617
- for (const [, entry] of styleQueries) {
618
- if (entry.hasExistence && entry.hasNegatedExistence) return true;
619
- if (entry.values.size > 1) return true;
620
- if (entry.hasNegatedExistence && entry.values.size > 0) return true;
621
- }
622
- return false;
623
- }
624
650
  const variantKeyCache = /* @__PURE__ */ new WeakMap();
625
651
  /**
626
652
  * Get a unique key for a variant (for deduplication).
627
653
  * Cached via WeakMap since variants are compared multiple times during
628
654
  * deduplication and sorting.
629
655
  */
630
- function getVariantKey(v) {
631
- const cached = variantKeyCache.get(v);
632
- if (cached !== void 0) return cached;
633
- const modifierKey = v.modifierConditions.map(getModifierKey).sort().join("|");
634
- const pseudoKey = v.pseudoConditions.map(getPseudoKey).sort().join("|");
635
- const ownKey = v.ownConditions.map(getSelectorConditionKey).sort().join("|");
636
- const containerKey = v.containerConditions.map((c) => `${c.name ?? ""}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|");
637
- const key = [
638
- modifierKey,
639
- pseudoKey,
640
- ownKey,
656
+ function getSelectorGroupKey(g) {
657
+ return `${g.negated ? "!" : ""}(${getBranchesKey(g.branches)})`;
658
+ }
659
+ /**
660
+ * Get a context key for a variant — everything except flat modifier/pseudo
661
+ * conditions. Variants with the same context key can be merged into an
662
+ * :is() group. Also used by getVariantKey as the shared non-selector portion.
663
+ */
664
+ function getVariantContextKey(v) {
665
+ return [
641
666
  v.mediaConditions.map((c) => `${c.subtype}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|"),
642
- containerKey,
667
+ v.containerConditions.map((c) => `${c.name ?? ""}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|"),
643
668
  v.supportsConditions.map((c) => `${c.subtype}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|"),
644
- v.rootConditions.map(getSelectorConditionKey).sort().join("|"),
669
+ v.rootGroups.map(getSelectorGroupKey).sort().join("|"),
645
670
  v.parentGroups.map(getParentGroupKey).sort().join("|"),
671
+ v.ownGroups.map(getSelectorGroupKey).sort().join("|"),
672
+ v.selectorGroups.map(getSelectorGroupKey).sort().join("|"),
646
673
  v.startingStyle ? "1" : "0"
647
674
  ].join("###");
675
+ }
676
+ function getVariantKey(v) {
677
+ const cached = variantKeyCache.get(v);
678
+ if (cached !== void 0) return cached;
679
+ const modifierKey = v.modifierConditions.map(getModifierKey).sort().join("|");
680
+ const pseudoKey = v.pseudoConditions.map(getPseudoKey).sort().join("|");
681
+ const key = modifierKey + "###" + pseudoKey + "###" + getVariantContextKey(v);
648
682
  variantKeyCache.set(v, key);
649
683
  return key;
650
684
  }
651
685
  /**
686
+ * Total number of leaf conditions in a variant (for superset / dedup comparisons).
687
+ */
688
+ function groupConditionCount(groups) {
689
+ return groups.reduce((sum, g) => sum + g.branches.reduce((s, b) => s + b.length, 0), 0);
690
+ }
691
+ function variantConditionCount(v) {
692
+ return v.modifierConditions.length + v.pseudoConditions.length + groupConditionCount(v.selectorGroups) + groupConditionCount(v.ownGroups) + v.mediaConditions.length + v.containerConditions.length + v.supportsConditions.length + groupConditionCount(v.rootGroups) + groupConditionCount(v.parentGroups);
693
+ }
694
+ /**
652
695
  * Check if variant A is a superset of variant B (A is more restrictive)
653
696
  *
654
697
  * If A has all of B's conditions plus more, then A is redundant
@@ -661,16 +704,16 @@ function getVariantKey(v) {
661
704
  */
662
705
  function isVariantSuperset(a, b) {
663
706
  if (a.startingStyle !== b.startingStyle) return false;
664
- if (!isSelectorConditionsSuperset(a.rootConditions, b.rootConditions)) return false;
707
+ if (!isSelectorGroupsSuperset(a.rootGroups, b.rootGroups)) return false;
665
708
  if (!isMediaConditionsSuperset(a.mediaConditions, b.mediaConditions)) return false;
666
709
  if (!isContainerConditionsSuperset(a.containerConditions, b.containerConditions)) return false;
667
710
  if (!isSupportsConditionsSuperset(a.supportsConditions, b.supportsConditions)) return false;
668
711
  if (!isModifierConditionsSuperset(a.modifierConditions, b.modifierConditions)) return false;
669
712
  if (!isPseudoConditionsSuperset(a.pseudoConditions, b.pseudoConditions)) return false;
670
- if (!isSelectorConditionsSuperset(a.ownConditions, b.ownConditions)) return false;
713
+ if (!isSelectorGroupsSuperset(a.selectorGroups, b.selectorGroups)) return false;
714
+ if (!isSelectorGroupsSuperset(a.ownGroups, b.ownGroups)) return false;
671
715
  if (!isParentGroupsSuperset(a.parentGroups, b.parentGroups)) return false;
672
- const parentConditionCount = (groups) => groups.reduce((sum, g) => sum + g.conditions.length, 0);
673
- return a.mediaConditions.length + a.containerConditions.length + a.supportsConditions.length + a.modifierConditions.length + a.pseudoConditions.length + a.rootConditions.length + parentConditionCount(a.parentGroups) + a.ownConditions.length > b.mediaConditions.length + b.containerConditions.length + b.supportsConditions.length + b.modifierConditions.length + b.pseudoConditions.length + b.rootConditions.length + parentConditionCount(b.parentGroups) + b.ownConditions.length;
716
+ return variantConditionCount(a) > variantConditionCount(b);
674
717
  }
675
718
  /**
676
719
  * Generic superset check: true if every item in B has a matching key in A.
@@ -694,8 +737,9 @@ function isModifierConditionsSuperset(a, b) {
694
737
  function isPseudoConditionsSuperset(a, b) {
695
738
  return isConditionsSuperset(a, b, getPseudoKey);
696
739
  }
697
- function isSelectorConditionsSuperset(a, b) {
698
- return isConditionsSuperset(a, b, getSelectorConditionKey);
740
+ function isSelectorGroupsSuperset(a, b) {
741
+ if (a.length < b.length) return false;
742
+ return isConditionsSuperset(a, b, getSelectorGroupKey);
699
743
  }
700
744
  /**
701
745
  * Check if parent groups A is a superset of B.
@@ -706,7 +750,7 @@ function isParentGroupsSuperset(a, b) {
706
750
  return isConditionsSuperset(a, b, getParentGroupKey);
707
751
  }
708
752
  function getParentGroupKey(g) {
709
- return `${g.negated ? "!" : ""}${g.direct ? ">" : ""}(${g.conditions.map(getSelectorConditionKey).sort().join(",")})`;
753
+ return `${g.negated ? "!" : ""}${g.direct ? ">" : ""}(${getBranchesKey(g.branches)})`;
710
754
  }
711
755
  /**
712
756
  * Deduplicate variants
@@ -716,6 +760,7 @@ function getParentGroupKey(g) {
716
760
  * 2. Superset variants (more restrictive selectors that are redundant)
717
761
  */
718
762
  function dedupeVariants(variants) {
763
+ if (variants.length <= 1) return variants;
719
764
  const seen = /* @__PURE__ */ new Set();
720
765
  const result = [];
721
766
  for (const v of variants) {
@@ -725,7 +770,7 @@ function dedupeVariants(variants) {
725
770
  result.push(v);
726
771
  }
727
772
  }
728
- const variantConditionCount = (v) => v.modifierConditions.length + v.pseudoConditions.length + v.ownConditions.length + v.mediaConditions.length + v.containerConditions.length + v.supportsConditions.length + v.rootConditions.length + v.parentGroups.reduce((sum, g) => sum + g.conditions.length, 0);
773
+ if (result.length <= 1) return result;
729
774
  result.sort((a, b) => variantConditionCount(a) - variantConditionCount(b));
730
775
  const filtered = [];
731
776
  for (const candidate of result) {
@@ -748,8 +793,9 @@ function dedupeVariants(variants) {
748
793
  * are filtered out.
749
794
  */
750
795
  function andToCSS(children) {
796
+ const exclusiveChildren = makeOrBranchesExclusive(children);
751
797
  let currentVariants = [emptyVariant()];
752
- for (const child of children) {
798
+ for (const child of exclusiveChildren) {
753
799
  const childCSS = conditionToCSSInner(child);
754
800
  if (childCSS.isImpossible || childCSS.variants.length === 0) return {
755
801
  variants: [],
@@ -772,11 +818,63 @@ function andToCSS(children) {
772
818
  };
773
819
  }
774
820
  /**
821
+ * Make OR branches within AND children mutually exclusive.
822
+ *
823
+ * For an AND child that is OR(A, B), transforms it to OR(A, B & !A)
824
+ * so that when andToCSS does a Cartesian product, the resulting
825
+ * CSS variants don't overlap.
826
+ *
827
+ * Only transforms OR children whose branches actually produce
828
+ * different at-rule contexts when materialized. This avoids
829
+ * breaking cases where contradiction detection in the Cartesian
830
+ * product naturally handles deduplication.
831
+ */
832
+ function makeOrBranchesExclusive(children) {
833
+ return children.map((child) => {
834
+ if (!isCompoundCondition(child) || child.operator !== "OR") return child;
835
+ if (child.children.length <= 1) return child;
836
+ if (!branchesProduceDifferentContexts(child.children)) return child;
837
+ const exclusiveBranches = [];
838
+ const priorBranches = [];
839
+ for (const branch of child.children) {
840
+ if (priorBranches.length === 0) exclusiveBranches.push(branch);
841
+ else {
842
+ let exclusive = branch;
843
+ for (const prior of priorBranches) exclusive = and(exclusive, not(prior));
844
+ const simplified = simplifyCondition(exclusive);
845
+ if (simplified.kind !== "false") exclusiveBranches.push(simplified);
846
+ }
847
+ priorBranches.push(branch);
848
+ }
849
+ if (exclusiveBranches.length === 0) return child;
850
+ if (exclusiveBranches.length === 1) return exclusiveBranches[0];
851
+ return {
852
+ kind: "compound",
853
+ operator: "OR",
854
+ children: exclusiveBranches
855
+ };
856
+ });
857
+ }
858
+ /**
859
+ * Check if OR branches produce different at-rule contexts when
860
+ * materialized. If so, the Cartesian product in andToCSS will
861
+ * create overlapping CSS variants that need exclusive expansion.
862
+ */
863
+ function branchesProduceDifferentContexts(branches) {
864
+ const contextKeys = /* @__PURE__ */ new Set();
865
+ for (const branch of branches) {
866
+ const css = conditionToCSSInner(branch);
867
+ if (css.isImpossible) continue;
868
+ for (const v of css.variants) contextKeys.add(getVariantContextKey(v));
869
+ }
870
+ return contextKeys.size > 1;
871
+ }
872
+ /**
775
873
  * Combine OR conditions into CSS
776
874
  *
777
875
  * OR in CSS means multiple selector variants (DNF).
778
- * Each variant becomes a separate selector in the comma-separated list,
779
- * or multiple CSS rules if they have different at-rules.
876
+ * After deduplication, variants that differ only in their base
877
+ * modifier/pseudo conditions are merged into :is() groups.
780
878
  *
781
879
  * Note: OR exclusivity is handled at the pipeline level (expandOrConditions),
782
880
  * so here we just collect all variants. Any remaining ORs in the condition
@@ -799,6 +897,103 @@ function orToCSS(children) {
799
897
  };
800
898
  }
801
899
  /**
900
+ * Find keys present in ALL condition arrays.
901
+ */
902
+ function findCommonKeys(conditionSets, getKey) {
903
+ if (conditionSets.length === 0) return /* @__PURE__ */ new Set();
904
+ const common = new Set(conditionSets[0].map(getKey));
905
+ for (let i = 1; i < conditionSets.length; i++) {
906
+ const keys = new Set(conditionSets[i].map(getKey));
907
+ for (const key of common) if (!keys.has(key)) common.delete(key);
908
+ }
909
+ return common;
910
+ }
911
+ /**
912
+ * Merge OR variants that share the same "context" (at-rules, root, parent,
913
+ * own, starting) into a single variant with a SelectorGroup.
914
+ *
915
+ * Variants with no modifier/pseudo conditions are kept separate (they match
916
+ * unconditionally and can't be expressed inside :is()).
917
+ */
918
+ function mergeVariantsIntoSelectorGroups(variants) {
919
+ if (variants.length <= 1) return variants;
920
+ const groups = /* @__PURE__ */ new Map();
921
+ for (const v of variants) {
922
+ const key = getVariantContextKey(v);
923
+ const group = groups.get(key);
924
+ if (group) group.push(v);
925
+ else groups.set(key, [v]);
926
+ }
927
+ const result = [];
928
+ for (const group of groups.values()) {
929
+ if (group.length === 1) {
930
+ result.push(group[0]);
931
+ continue;
932
+ }
933
+ const withSelectors = [];
934
+ const withoutSelectors = [];
935
+ for (const v of group) if (v.modifierConditions.length === 0 && v.pseudoConditions.length === 0) withoutSelectors.push(v);
936
+ else withSelectors.push(v);
937
+ result.push(...withoutSelectors);
938
+ if (withSelectors.length <= 1) {
939
+ result.push(...withSelectors);
940
+ continue;
941
+ }
942
+ result.push(factorAndGroup(withSelectors));
943
+ }
944
+ return result;
945
+ }
946
+ /**
947
+ * Factor common modifier/pseudo conditions out of variants and create
948
+ * a single variant with a SelectorGroup for the remaining (differing)
949
+ * conditions.
950
+ *
951
+ * Precondition: all variants must share the same context key (identical
952
+ * at-rules, root/parent/own/selector groups, startingStyle).
953
+ */
954
+ function factorAndGroup(variants) {
955
+ {
956
+ const key0 = getVariantContextKey(variants[0]);
957
+ for (let i = 1; i < variants.length; i++) {
958
+ const keyI = getVariantContextKey(variants[i]);
959
+ if (keyI !== key0) throw new Error(`factorAndGroup: context key mismatch at index ${i}.\n expected: ${key0}\n got: ${keyI}`);
960
+ }
961
+ }
962
+ const commonModKeys = findCommonKeys(variants.map((v) => v.modifierConditions), getModifierKey);
963
+ const commonPseudoKeys = findCommonKeys(variants.map((v) => v.pseudoConditions), getPseudoKey);
964
+ const commonModifiers = variants[0].modifierConditions.filter((m) => commonModKeys.has(getModifierKey(m)));
965
+ const commonPseudos = variants[0].pseudoConditions.filter((p) => commonPseudoKeys.has(getPseudoKey(p)));
966
+ const branches = [];
967
+ let hasEmptyBranch = false;
968
+ for (const v of variants) {
969
+ const branch = [];
970
+ for (const mod of v.modifierConditions) if (!commonModKeys.has(getModifierKey(mod))) branch.push(mod);
971
+ for (const pseudo of v.pseudoConditions) if (!commonPseudoKeys.has(getPseudoKey(pseudo))) branch.push(pseudo);
972
+ if (branch.length > 0) branches.push(branch);
973
+ else hasEmptyBranch = true;
974
+ }
975
+ if (hasEmptyBranch) return {
976
+ ...variants[0],
977
+ modifierConditions: commonModifiers,
978
+ pseudoConditions: commonPseudos
979
+ };
980
+ return {
981
+ modifierConditions: commonModifiers,
982
+ pseudoConditions: commonPseudos,
983
+ selectorGroups: [...variants[0].selectorGroups, {
984
+ branches,
985
+ negated: false
986
+ }],
987
+ ownGroups: [...variants[0].ownGroups],
988
+ mediaConditions: [...variants[0].mediaConditions],
989
+ containerConditions: [...variants[0].containerConditions],
990
+ supportsConditions: [...variants[0].supportsConditions],
991
+ rootGroups: [...variants[0].rootGroups],
992
+ parentGroups: [...variants[0].parentGroups],
993
+ startingStyle: variants[0].startingStyle
994
+ };
995
+ }
996
+ /**
802
997
  * Build at-rules array from a variant
803
998
  */
804
999
  function buildAtRulesFromVariant(variant) {
@@ -835,10 +1030,9 @@ function buildAtRulesFromVariant(variant) {
835
1030
  });
836
1031
  atRules.push(`@supports ${conditionParts.join(" and ")}`);
837
1032
  }
838
- if (variant.startingStyle) atRules.push("@starting-style");
839
1033
  return atRules;
840
1034
  }
841
-
842
1035
  //#endregion
843
- export { buildAtRulesFromVariant, conditionToCSS, modifierToCSS, parentGroupsToCSS, pseudoToCSS, rootConditionsToCSS, selectorConditionToCSS };
1036
+ export { branchToCSS, buildAtRulesFromVariant, conditionToCSS, mergeVariantsIntoSelectorGroups, optimizeGroups, parentGroupsToCSS, rootGroupsToCSS, selectorGroupToCSS };
1037
+
844
1038
  //# sourceMappingURL=materialize.js.map