@tenphi/tasty 2.0.3 → 2.0.4

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 (322) hide show
  1. package/dist/{ssr/async-storage.js → async-storage-B7_o6FKt.js} +2 -2
  2. package/dist/async-storage-B7_o6FKt.js.map +1 -0
  3. package/dist/{ssr/collector.d.ts → collector-CkZ517g4.d.ts} +3 -3
  4. package/dist/{ssr/collector.js → collector-DXqvGOb1.js} +5 -10
  5. package/dist/collector-DXqvGOb1.js.map +1 -0
  6. package/dist/config-5jzS6k6B.js +10005 -0
  7. package/dist/config-5jzS6k6B.js.map +1 -0
  8. package/dist/config-DknGsfMo.d.ts +857 -0
  9. package/dist/{ssr/context.js → context-CkSg-kDT.js} +11 -3
  10. package/dist/context-CkSg-kDT.js.map +1 -0
  11. package/dist/core/index.d.ts +5 -34
  12. package/dist/core/index.js +5 -26
  13. package/dist/core-CtU6-9OC.js +1507 -0
  14. package/dist/core-CtU6-9OC.js.map +1 -0
  15. package/dist/{zero/extractor.js → css-writer-DHkX0JuE.js} +74 -11
  16. package/dist/css-writer-DHkX0JuE.js.map +1 -0
  17. package/dist/{ssr/format-global-rules.js → format-global-rules-Dbc_1tc3.js} +2 -2
  18. package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
  19. package/dist/format-rules-DH13ewDu.js +143 -0
  20. package/dist/format-rules-DH13ewDu.js.map +1 -0
  21. package/dist/{ssr/hydrate.js → hydrate-C1Gv-DoS.js} +3 -3
  22. package/dist/hydrate-C1Gv-DoS.js.map +1 -0
  23. package/dist/{styles/types.d.ts → index-PzENbpAq.d.ts} +701 -5
  24. package/dist/index-o7zV2yCr.d.ts +1561 -0
  25. package/dist/index.d.ts +5 -51
  26. package/dist/index.js +728 -35
  27. package/dist/index.js.map +1 -0
  28. package/dist/keyframes-b7X3UxDV.js +587 -0
  29. package/dist/keyframes-b7X3UxDV.js.map +1 -0
  30. package/dist/{utils/merge-styles.d.ts → merge-styles-C7KTy7MY.d.ts} +3 -3
  31. package/dist/{utils/merge-styles.js → merge-styles-Tgo3BbL2.js} +3 -4
  32. package/dist/merge-styles-Tgo3BbL2.js.map +1 -0
  33. package/dist/{utils/resolve-recipes.js → resolve-recipes-Ca2-5CxM.js} +4 -6
  34. package/dist/resolve-recipes-Ca2-5CxM.js.map +1 -0
  35. package/dist/ssr/astro-client.js +1 -1
  36. package/dist/ssr/astro.js +4 -4
  37. package/dist/ssr/index.d.ts +44 -4
  38. package/dist/ssr/index.js +4 -4
  39. package/dist/ssr/next.d.ts +1 -1
  40. package/dist/ssr/next.js +6 -6
  41. package/dist/ssr/next.js.map +1 -1
  42. package/dist/static/index.d.ts +91 -5
  43. package/dist/static/index.js +49 -3
  44. package/dist/static/index.js.map +1 -0
  45. package/dist/zero/babel.d.ts +1 -1
  46. package/dist/zero/babel.js +10 -6
  47. package/dist/zero/babel.js.map +1 -1
  48. package/dist/zero/index.d.ts +67 -3
  49. package/dist/zero/index.js +1 -2
  50. package/package.json +3 -3
  51. package/dist/_virtual/_rolldown/runtime.js +0 -7
  52. package/dist/chunks/cacheKey.d.ts +0 -1
  53. package/dist/chunks/cacheKey.js +0 -77
  54. package/dist/chunks/cacheKey.js.map +0 -1
  55. package/dist/chunks/definitions.d.ts +0 -37
  56. package/dist/chunks/definitions.js +0 -258
  57. package/dist/chunks/definitions.js.map +0 -1
  58. package/dist/chunks/index.d.ts +0 -1
  59. package/dist/chunks/renderChunk.d.ts +0 -1
  60. package/dist/chunks/renderChunk.js +0 -59
  61. package/dist/chunks/renderChunk.js.map +0 -1
  62. package/dist/compute-styles.d.ts +0 -31
  63. package/dist/compute-styles.js +0 -322
  64. package/dist/compute-styles.js.map +0 -1
  65. package/dist/config.d.ts +0 -407
  66. package/dist/config.js +0 -591
  67. package/dist/config.js.map +0 -1
  68. package/dist/counter-style/index.js +0 -51
  69. package/dist/counter-style/index.js.map +0 -1
  70. package/dist/debug.d.ts +0 -89
  71. package/dist/debug.js +0 -453
  72. package/dist/debug.js.map +0 -1
  73. package/dist/font-face/index.js +0 -63
  74. package/dist/font-face/index.js.map +0 -1
  75. package/dist/hooks/index.d.ts +0 -7
  76. package/dist/hooks/useCounterStyle.d.ts +0 -36
  77. package/dist/hooks/useCounterStyle.js +0 -65
  78. package/dist/hooks/useCounterStyle.js.map +0 -1
  79. package/dist/hooks/useFontFace.d.ts +0 -45
  80. package/dist/hooks/useFontFace.js +0 -66
  81. package/dist/hooks/useFontFace.js.map +0 -1
  82. package/dist/hooks/useGlobalStyles.d.ts +0 -46
  83. package/dist/hooks/useGlobalStyles.js +0 -88
  84. package/dist/hooks/useGlobalStyles.js.map +0 -1
  85. package/dist/hooks/useKeyframes.d.ts +0 -58
  86. package/dist/hooks/useKeyframes.js +0 -55
  87. package/dist/hooks/useKeyframes.js.map +0 -1
  88. package/dist/hooks/useProperty.d.ts +0 -81
  89. package/dist/hooks/useProperty.js +0 -96
  90. package/dist/hooks/useProperty.js.map +0 -1
  91. package/dist/hooks/useRawCSS.d.ts +0 -22
  92. package/dist/hooks/useRawCSS.js +0 -103
  93. package/dist/hooks/useRawCSS.js.map +0 -1
  94. package/dist/hooks/useStyles.d.ts +0 -40
  95. package/dist/hooks/useStyles.js +0 -31
  96. package/dist/hooks/useStyles.js.map +0 -1
  97. package/dist/injector/index.d.ts +0 -182
  98. package/dist/injector/index.js +0 -185
  99. package/dist/injector/index.js.map +0 -1
  100. package/dist/injector/injector.d.ts +0 -198
  101. package/dist/injector/injector.js +0 -651
  102. package/dist/injector/injector.js.map +0 -1
  103. package/dist/injector/sheet-manager.d.ts +0 -132
  104. package/dist/injector/sheet-manager.js +0 -699
  105. package/dist/injector/sheet-manager.js.map +0 -1
  106. package/dist/injector/types.d.ts +0 -235
  107. package/dist/keyframes/index.js +0 -206
  108. package/dist/keyframes/index.js.map +0 -1
  109. package/dist/parser/classify.js +0 -319
  110. package/dist/parser/classify.js.map +0 -1
  111. package/dist/parser/const.js +0 -60
  112. package/dist/parser/const.js.map +0 -1
  113. package/dist/parser/lru.js +0 -109
  114. package/dist/parser/lru.js.map +0 -1
  115. package/dist/parser/parser.d.ts +0 -25
  116. package/dist/parser/parser.js +0 -115
  117. package/dist/parser/parser.js.map +0 -1
  118. package/dist/parser/tokenizer.js +0 -69
  119. package/dist/parser/tokenizer.js.map +0 -1
  120. package/dist/parser/types.d.ts +0 -51
  121. package/dist/parser/types.js +0 -46
  122. package/dist/parser/types.js.map +0 -1
  123. package/dist/pipeline/conditions.d.ts +0 -134
  124. package/dist/pipeline/conditions.js +0 -406
  125. package/dist/pipeline/conditions.js.map +0 -1
  126. package/dist/pipeline/exclusive.js +0 -389
  127. package/dist/pipeline/exclusive.js.map +0 -1
  128. package/dist/pipeline/index.d.ts +0 -55
  129. package/dist/pipeline/index.js +0 -749
  130. package/dist/pipeline/index.js.map +0 -1
  131. package/dist/pipeline/materialize-contradictions.js +0 -125
  132. package/dist/pipeline/materialize-contradictions.js.map +0 -1
  133. package/dist/pipeline/materialize.js +0 -1038
  134. package/dist/pipeline/materialize.js.map +0 -1
  135. package/dist/pipeline/parseStateKey.d.ts +0 -15
  136. package/dist/pipeline/parseStateKey.js +0 -446
  137. package/dist/pipeline/parseStateKey.js.map +0 -1
  138. package/dist/pipeline/simplify.js +0 -725
  139. package/dist/pipeline/simplify.js.map +0 -1
  140. package/dist/pipeline/warnings.js +0 -18
  141. package/dist/pipeline/warnings.js.map +0 -1
  142. package/dist/plugins/index.d.ts +0 -2
  143. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  144. package/dist/plugins/okhsl-plugin.js +0 -97
  145. package/dist/plugins/okhsl-plugin.js.map +0 -1
  146. package/dist/plugins/types.d.ts +0 -87
  147. package/dist/properties/index.js +0 -222
  148. package/dist/properties/index.js.map +0 -1
  149. package/dist/properties/property-type-resolver.d.ts +0 -24
  150. package/dist/properties/property-type-resolver.js +0 -90
  151. package/dist/properties/property-type-resolver.js.map +0 -1
  152. package/dist/rsc-cache.js +0 -79
  153. package/dist/rsc-cache.js.map +0 -1
  154. package/dist/ssr/async-storage.d.ts +0 -17
  155. package/dist/ssr/async-storage.js.map +0 -1
  156. package/dist/ssr/collect-auto-properties.js +0 -58
  157. package/dist/ssr/collect-auto-properties.js.map +0 -1
  158. package/dist/ssr/collector.js.map +0 -1
  159. package/dist/ssr/context.js.map +0 -1
  160. package/dist/ssr/format-global-rules.js.map +0 -1
  161. package/dist/ssr/format-keyframes.js +0 -69
  162. package/dist/ssr/format-keyframes.js.map +0 -1
  163. package/dist/ssr/format-property.js +0 -49
  164. package/dist/ssr/format-property.js.map +0 -1
  165. package/dist/ssr/format-rules.js +0 -73
  166. package/dist/ssr/format-rules.js.map +0 -1
  167. package/dist/ssr/hydrate.d.ts +0 -29
  168. package/dist/ssr/hydrate.js.map +0 -1
  169. package/dist/ssr/ssr-collector-ref.js +0 -29
  170. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  171. package/dist/states/index.d.ts +0 -49
  172. package/dist/states/index.js +0 -170
  173. package/dist/states/index.js.map +0 -1
  174. package/dist/static/tastyStatic.d.ts +0 -46
  175. package/dist/static/tastyStatic.js +0 -30
  176. package/dist/static/tastyStatic.js.map +0 -1
  177. package/dist/static/types.d.ts +0 -49
  178. package/dist/static/types.js +0 -24
  179. package/dist/static/types.js.map +0 -1
  180. package/dist/styles/border.d.ts +0 -25
  181. package/dist/styles/border.js +0 -120
  182. package/dist/styles/border.js.map +0 -1
  183. package/dist/styles/color.d.ts +0 -14
  184. package/dist/styles/color.js +0 -26
  185. package/dist/styles/color.js.map +0 -1
  186. package/dist/styles/const.js +0 -17
  187. package/dist/styles/const.js.map +0 -1
  188. package/dist/styles/createStyle.js +0 -79
  189. package/dist/styles/createStyle.js.map +0 -1
  190. package/dist/styles/dimension.js +0 -109
  191. package/dist/styles/dimension.js.map +0 -1
  192. package/dist/styles/directional.js +0 -133
  193. package/dist/styles/directional.js.map +0 -1
  194. package/dist/styles/display.d.ts +0 -30
  195. package/dist/styles/display.js +0 -73
  196. package/dist/styles/display.js.map +0 -1
  197. package/dist/styles/fade.d.ts +0 -15
  198. package/dist/styles/fade.js +0 -62
  199. package/dist/styles/fade.js.map +0 -1
  200. package/dist/styles/fill.d.ts +0 -42
  201. package/dist/styles/fill.js +0 -51
  202. package/dist/styles/fill.js.map +0 -1
  203. package/dist/styles/flow.d.ts +0 -16
  204. package/dist/styles/flow.js +0 -12
  205. package/dist/styles/flow.js.map +0 -1
  206. package/dist/styles/gap.d.ts +0 -31
  207. package/dist/styles/gap.js +0 -38
  208. package/dist/styles/gap.js.map +0 -1
  209. package/dist/styles/height.d.ts +0 -17
  210. package/dist/styles/height.js +0 -19
  211. package/dist/styles/height.js.map +0 -1
  212. package/dist/styles/index.d.ts +0 -1
  213. package/dist/styles/index.js +0 -8
  214. package/dist/styles/index.js.map +0 -1
  215. package/dist/styles/inset.d.ts +0 -24
  216. package/dist/styles/inset.js +0 -34
  217. package/dist/styles/inset.js.map +0 -1
  218. package/dist/styles/list.d.ts +0 -16
  219. package/dist/styles/list.js +0 -100
  220. package/dist/styles/list.js.map +0 -1
  221. package/dist/styles/margin.d.ts +0 -24
  222. package/dist/styles/margin.js +0 -32
  223. package/dist/styles/margin.js.map +0 -1
  224. package/dist/styles/outline.d.ts +0 -29
  225. package/dist/styles/outline.js +0 -55
  226. package/dist/styles/outline.js.map +0 -1
  227. package/dist/styles/padding.d.ts +0 -24
  228. package/dist/styles/padding.js +0 -32
  229. package/dist/styles/padding.js.map +0 -1
  230. package/dist/styles/placement.d.ts +0 -37
  231. package/dist/styles/placement.js +0 -74
  232. package/dist/styles/placement.js.map +0 -1
  233. package/dist/styles/predefined.d.ts +0 -71
  234. package/dist/styles/predefined.js +0 -237
  235. package/dist/styles/predefined.js.map +0 -1
  236. package/dist/styles/preset.d.ts +0 -52
  237. package/dist/styles/preset.js +0 -127
  238. package/dist/styles/preset.js.map +0 -1
  239. package/dist/styles/radius.d.ts +0 -12
  240. package/dist/styles/radius.js +0 -83
  241. package/dist/styles/radius.js.map +0 -1
  242. package/dist/styles/scrollMargin.d.ts +0 -24
  243. package/dist/styles/scrollMargin.js +0 -32
  244. package/dist/styles/scrollMargin.js.map +0 -1
  245. package/dist/styles/scrollbar.d.ts +0 -25
  246. package/dist/styles/scrollbar.js +0 -51
  247. package/dist/styles/scrollbar.js.map +0 -1
  248. package/dist/styles/shadow.d.ts +0 -14
  249. package/dist/styles/shadow.js +0 -25
  250. package/dist/styles/shadow.js.map +0 -1
  251. package/dist/styles/shared.js +0 -17
  252. package/dist/styles/shared.js.map +0 -1
  253. package/dist/styles/transition.d.ts +0 -14
  254. package/dist/styles/transition.js +0 -159
  255. package/dist/styles/transition.js.map +0 -1
  256. package/dist/styles/width.d.ts +0 -17
  257. package/dist/styles/width.js +0 -19
  258. package/dist/styles/width.js.map +0 -1
  259. package/dist/tasty.d.ts +0 -134
  260. package/dist/tasty.js +0 -248
  261. package/dist/tasty.js.map +0 -1
  262. package/dist/types.d.ts +0 -184
  263. package/dist/utils/cache-wrapper.js +0 -21
  264. package/dist/utils/cache-wrapper.js.map +0 -1
  265. package/dist/utils/case-converter.js +0 -8
  266. package/dist/utils/case-converter.js.map +0 -1
  267. package/dist/utils/color-math.d.ts +0 -46
  268. package/dist/utils/color-math.js +0 -749
  269. package/dist/utils/color-math.js.map +0 -1
  270. package/dist/utils/color-space.d.ts +0 -5
  271. package/dist/utils/color-space.js +0 -228
  272. package/dist/utils/color-space.js.map +0 -1
  273. package/dist/utils/colors.d.ts +0 -5
  274. package/dist/utils/colors.js +0 -10
  275. package/dist/utils/colors.js.map +0 -1
  276. package/dist/utils/css-types.d.ts +0 -7
  277. package/dist/utils/deps-equal.js +0 -15
  278. package/dist/utils/deps-equal.js.map +0 -1
  279. package/dist/utils/dotize.d.ts +0 -26
  280. package/dist/utils/dotize.js +0 -122
  281. package/dist/utils/dotize.js.map +0 -1
  282. package/dist/utils/filter-base-props.d.ts +0 -15
  283. package/dist/utils/filter-base-props.js +0 -45
  284. package/dist/utils/filter-base-props.js.map +0 -1
  285. package/dist/utils/get-display-name.d.ts +0 -7
  286. package/dist/utils/get-display-name.js +0 -10
  287. package/dist/utils/get-display-name.js.map +0 -1
  288. package/dist/utils/has-keys.js +0 -13
  289. package/dist/utils/has-keys.js.map +0 -1
  290. package/dist/utils/hash.js +0 -14
  291. package/dist/utils/hash.js.map +0 -1
  292. package/dist/utils/is-dev-env.js +0 -19
  293. package/dist/utils/is-dev-env.js.map +0 -1
  294. package/dist/utils/is-valid-element-type.js +0 -15
  295. package/dist/utils/is-valid-element-type.js.map +0 -1
  296. package/dist/utils/merge-styles.js.map +0 -1
  297. package/dist/utils/mod-attrs.d.ts +0 -6
  298. package/dist/utils/mod-attrs.js +0 -20
  299. package/dist/utils/mod-attrs.js.map +0 -1
  300. package/dist/utils/process-tokens.d.ts +0 -17
  301. package/dist/utils/process-tokens.js +0 -83
  302. package/dist/utils/process-tokens.js.map +0 -1
  303. package/dist/utils/resolve-recipes.d.ts +0 -17
  304. package/dist/utils/resolve-recipes.js.map +0 -1
  305. package/dist/utils/selector-transform.js +0 -32
  306. package/dist/utils/selector-transform.js.map +0 -1
  307. package/dist/utils/string.js +0 -8
  308. package/dist/utils/string.js.map +0 -1
  309. package/dist/utils/styles.d.ts +0 -99
  310. package/dist/utils/styles.js +0 -220
  311. package/dist/utils/styles.js.map +0 -1
  312. package/dist/utils/typography.d.ts +0 -58
  313. package/dist/utils/typography.js +0 -51
  314. package/dist/utils/typography.js.map +0 -1
  315. package/dist/utils/warnings.d.ts +0 -16
  316. package/dist/utils/warnings.js +0 -16
  317. package/dist/utils/warnings.js.map +0 -1
  318. package/dist/zero/css-writer.d.ts +0 -45
  319. package/dist/zero/css-writer.js +0 -73
  320. package/dist/zero/css-writer.js.map +0 -1
  321. package/dist/zero/extractor.d.ts +0 -24
  322. package/dist/zero/extractor.js.map +0 -1
@@ -1,1038 +0,0 @@
1
- import { Lru } from "../parser/lru.js";
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";
5
- //#region src/pipeline/materialize.ts
6
- /**
7
- * CSS Materialization
8
- *
9
- * Converts condition trees into CSS selectors and at-rules.
10
- * This is the final stage that produces actual CSS output.
11
- */
12
- const conditionCache = new Lru(3e3);
13
- /**
14
- * Convert a condition tree to CSS components
15
- */
16
- function conditionToCSS(node) {
17
- const key = getConditionUniqueId(node);
18
- const cached = conditionCache.get(key);
19
- if (cached) return cached;
20
- const result = conditionToCSSInner(node);
21
- conditionCache.set(key, result);
22
- return result;
23
- }
24
- function emptyVariant() {
25
- return {
26
- modifierConditions: [],
27
- pseudoConditions: [],
28
- selectorGroups: [],
29
- ownGroups: [],
30
- mediaConditions: [],
31
- containerConditions: [],
32
- supportsConditions: [],
33
- rootGroups: [],
34
- parentGroups: [],
35
- startingStyle: false
36
- };
37
- }
38
- function conditionToCSSInner(node) {
39
- if (node.kind === "true") return {
40
- variants: [emptyVariant()],
41
- isImpossible: false
42
- };
43
- if (node.kind === "false") return {
44
- variants: [],
45
- isImpossible: true
46
- };
47
- if (node.kind === "state") return stateToCSS(node);
48
- if (node.kind === "compound") if (node.operator === "AND") return andToCSS(node.children);
49
- else return orToCSS(node.children);
50
- return {
51
- variants: [emptyVariant()],
52
- isImpossible: false
53
- };
54
- }
55
- /**
56
- * Convert a state condition to CSS
57
- */
58
- function stateToCSS(state) {
59
- switch (state.type) {
60
- case "media": return {
61
- variants: mediaToParsed(state).map((mediaCond) => {
62
- const v = emptyVariant();
63
- v.mediaConditions.push(mediaCond);
64
- return v;
65
- }),
66
- isImpossible: false
67
- };
68
- case "root": return innerConditionToVariants(state.innerCondition, state.negated ?? false, "rootGroups");
69
- case "parent": return parentConditionToVariants(state.innerCondition, state.negated ?? false, state.direct);
70
- case "own": return innerConditionToVariants(state.innerCondition, state.negated ?? false, "ownGroups");
71
- case "modifier": {
72
- const v = emptyVariant();
73
- v.modifierConditions.push(modifierToParsed(state));
74
- return {
75
- variants: [v],
76
- isImpossible: false
77
- };
78
- }
79
- case "pseudo": {
80
- const v = emptyVariant();
81
- v.pseudoConditions.push(pseudoToParsed(state));
82
- return {
83
- variants: [v],
84
- isImpossible: false
85
- };
86
- }
87
- case "container": {
88
- const v = emptyVariant();
89
- v.containerConditions.push(containerToParsed(state));
90
- return {
91
- variants: [v],
92
- isImpossible: false
93
- };
94
- }
95
- case "supports": {
96
- const v = emptyVariant();
97
- v.supportsConditions.push(supportsToParsed(state));
98
- return {
99
- variants: [v],
100
- isImpossible: false
101
- };
102
- }
103
- case "starting": {
104
- const v = emptyVariant();
105
- v.startingStyle = !state.negated;
106
- return {
107
- variants: [v],
108
- isImpossible: false
109
- };
110
- }
111
- }
112
- }
113
- /**
114
- * Convert modifier condition to parsed structure
115
- */
116
- function modifierToParsed(state) {
117
- return {
118
- attribute: state.attribute,
119
- value: state.value,
120
- operator: state.operator,
121
- negated: state.negated ?? false
122
- };
123
- }
124
- /**
125
- * Convert parsed modifier to CSS selector string (for final output)
126
- */
127
- function modifierToCSS(mod) {
128
- let selector;
129
- if (mod.value !== void 0) {
130
- const op = mod.operator || "=";
131
- selector = `[${mod.attribute}${op}"${mod.value}"]`;
132
- } else selector = `[${mod.attribute}]`;
133
- if (mod.negated) return `:not(${selector})`;
134
- return selector;
135
- }
136
- /**
137
- * Convert pseudo condition to parsed structure
138
- */
139
- function pseudoToParsed(state) {
140
- return {
141
- pseudo: state.pseudo,
142
- negated: state.negated ?? false
143
- };
144
- }
145
- /**
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()).
158
- */
159
- function pseudoToCSS(pseudo) {
160
- const p = pseudo.pseudo;
161
- if (pseudo.negated) {
162
- if (p.startsWith(":is(") || p.startsWith(":where(")) return `:not(${p.slice(p.indexOf("(") + 1, -1)})`;
163
- return `:not(${p})`;
164
- }
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;
171
- }
172
- /**
173
- * Convert media condition to parsed structure(s)
174
- * Returns an array because negated ranges produce OR branches (two separate conditions)
175
- */
176
- function mediaToParsed(state) {
177
- if (state.subtype === "type") {
178
- const mediaType = state.mediaType || "all";
179
- return [{
180
- subtype: "type",
181
- negated: state.negated ?? false,
182
- condition: mediaType,
183
- mediaType: state.mediaType
184
- }];
185
- } else if (state.subtype === "feature") {
186
- let condition;
187
- if (state.featureValue) condition = `(${state.feature}: ${state.featureValue})`;
188
- else condition = `(${state.feature})`;
189
- return [{
190
- subtype: "feature",
191
- negated: state.negated ?? false,
192
- condition,
193
- feature: state.feature,
194
- featureValue: state.featureValue
195
- }];
196
- } else return dimensionToMediaParsed(state.dimension || "width", state.lowerBound, state.upperBound, state.negated ?? false);
197
- }
198
- /**
199
- * Convert dimension bounds to parsed media condition(s)
200
- * Uses CSS Media Queries Level 4 `not (condition)` syntax for negation.
201
- */
202
- function dimensionToMediaParsed(dimension, lowerBound, upperBound, negated) {
203
- let condition;
204
- if (lowerBound && upperBound) {
205
- const lowerOp = lowerBound.inclusive ? "<=" : "<";
206
- const upperOp = upperBound.inclusive ? "<=" : "<";
207
- condition = `(${lowerBound.value} ${lowerOp} ${dimension} ${upperOp} ${upperBound.value})`;
208
- } else if (upperBound) condition = `(${dimension} ${upperBound.inclusive ? "<=" : "<"} ${upperBound.value})`;
209
- else if (lowerBound) condition = `(${dimension} ${lowerBound.inclusive ? ">=" : ">"} ${lowerBound.value})`;
210
- else condition = `(${dimension})`;
211
- return [{
212
- subtype: "dimension",
213
- negated: negated ?? false,
214
- condition,
215
- dimension,
216
- lowerBound,
217
- upperBound
218
- }];
219
- }
220
- /**
221
- * Convert container condition to parsed structure
222
- * This enables structured analysis for contradiction detection and condition combining
223
- */
224
- function containerToParsed(state) {
225
- let condition;
226
- if (state.subtype === "style") if (state.propertyValue) condition = `style(--${state.property}: ${state.propertyValue})`;
227
- else condition = `style(--${state.property})`;
228
- else if (state.subtype === "raw") condition = state.rawCondition;
229
- else condition = dimensionToContainerCondition(state.dimension || "width", state.lowerBound, state.upperBound);
230
- return {
231
- name: state.containerName,
232
- condition,
233
- negated: state.negated ?? false,
234
- subtype: state.subtype,
235
- property: state.property,
236
- propertyValue: state.propertyValue
237
- };
238
- }
239
- /**
240
- * Convert dimension bounds to container query condition (single string)
241
- * Container queries support "not (condition)", so no need to invert manually
242
- */
243
- function dimensionToContainerCondition(dimension, lowerBound, upperBound) {
244
- if (lowerBound && upperBound) {
245
- const lowerOp = lowerBound.inclusive ? "<=" : "<";
246
- const upperOp = upperBound.inclusive ? "<=" : "<";
247
- return `(${lowerBound.value} ${lowerOp} ${dimension} ${upperOp} ${upperBound.value})`;
248
- } else if (upperBound) return `(${dimension} ${upperBound.inclusive ? "<=" : "<"} ${upperBound.value})`;
249
- else if (lowerBound) return `(${dimension} ${lowerBound.inclusive ? ">=" : ">"} ${lowerBound.value})`;
250
- return "(width)";
251
- }
252
- /**
253
- * Convert supports condition to parsed structure
254
- */
255
- function supportsToParsed(state) {
256
- return {
257
- subtype: state.subtype,
258
- condition: state.condition,
259
- negated: state.negated ?? false
260
- };
261
- }
262
- /**
263
- * Collect all modifier and pseudo conditions from a variant as a flat array.
264
- */
265
- function collectSelectorConditions(variant) {
266
- return [...variant.modifierConditions, ...variant.pseudoConditions];
267
- }
268
- /**
269
- * Convert an inner condition tree into a single SelectorVariant with
270
- * one SelectorGroup whose branches represent the inner OR alternatives.
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]).
280
- */
281
- function innerConditionToVariants(innerCondition, negated, target) {
282
- const innerCSS = conditionToCSS(innerCondition);
283
- if (innerCSS.isImpossible || innerCSS.variants.length === 0) return {
284
- variants: [],
285
- isImpossible: true
286
- };
287
- const branches = [];
288
- for (const innerVariant of innerCSS.variants) {
289
- const conditions = collectSelectorConditions(innerVariant);
290
- if (conditions.length > 0) branches.push(conditions);
291
- }
292
- if (branches.length === 0) return {
293
- variants: [emptyVariant()],
294
- isImpossible: false
295
- };
296
- const v = emptyVariant();
297
- v[target].push({
298
- branches,
299
- negated
300
- });
301
- return {
302
- variants: [v],
303
- isImpossible: false
304
- };
305
- }
306
- /**
307
- * Convert a @parent() inner condition into a single SelectorVariant with
308
- * one ParentGroup whose branches represent the inner OR alternatives.
309
- *
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.
313
- */
314
- function parentConditionToVariants(innerCondition, negated, direct) {
315
- const innerCSS = conditionToCSS(innerCondition);
316
- if (innerCSS.isImpossible || innerCSS.variants.length === 0) return {
317
- variants: [],
318
- isImpossible: true
319
- };
320
- const branches = [];
321
- for (const innerVariant of innerCSS.variants) {
322
- const conditions = collectSelectorConditions(innerVariant);
323
- if (conditions.length > 0) branches.push(conditions);
324
- }
325
- if (branches.length === 0) return {
326
- variants: [emptyVariant()],
327
- isImpossible: false
328
- };
329
- const v = emptyVariant();
330
- v.parentGroups.push({
331
- branches,
332
- direct,
333
- negated
334
- });
335
- return {
336
- variants: [v],
337
- isImpossible: false
338
- };
339
- }
340
- /**
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.
435
- */
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;
477
- let prefix = ":root";
478
- for (const group of optimized) prefix += selectorGroupToCSS(group);
479
- return prefix;
480
- }
481
- /**
482
- * Convert parent groups to CSS selector fragments (for final output).
483
- * Each group produces its own :is()/:not() wrapper with a combinator
484
- * suffix (` *` or ` > *`) appended to each branch.
485
- */
486
- function parentGroupsToCSS(groups) {
487
- let result = "";
488
- for (const group of groups) {
489
- const combinator = group.direct ? " > *" : " *";
490
- const args = group.branches.map((branch) => branchToCSS(branch) + combinator);
491
- result += wrapInIsOrNot(args, group.negated);
492
- }
493
- return result;
494
- }
495
- /**
496
- * Convert a modifier or pseudo condition to a CSS selector fragment
497
- */
498
- function selectorConditionToCSS(cond) {
499
- if ("attribute" in cond) return modifierToCSS(cond);
500
- return pseudoToCSS(cond);
501
- }
502
- /**
503
- * Get unique key for a modifier condition
504
- */
505
- function getModifierKey(mod) {
506
- const base = mod.value ? `${mod.attribute}${mod.operator || "="}${mod.value}` : mod.attribute;
507
- return mod.negated ? `!${base}` : base;
508
- }
509
- /**
510
- * Get unique key for a pseudo condition
511
- */
512
- function getPseudoKey(pseudo) {
513
- return pseudo.negated ? `!${pseudo.pseudo}` : pseudo.pseudo;
514
- }
515
- /**
516
- * Get unique key for any selector condition (modifier or pseudo)
517
- */
518
- function getSelectorConditionKey(cond) {
519
- return "attribute" in cond ? `mod:${getModifierKey(cond)}` : `pseudo:${getPseudoKey(cond)}`;
520
- }
521
- /**
522
- * Deduplicate selector conditions (modifiers or pseudos).
523
- * Shared by root, parent, and own conditions.
524
- */
525
- function dedupeSelectorConditions(conditions) {
526
- const seen = /* @__PURE__ */ new Set();
527
- const result = [];
528
- for (const c of conditions) {
529
- const key = getSelectorConditionKey(c);
530
- if (!seen.has(key)) {
531
- seen.add(key);
532
- result.push(c);
533
- }
534
- }
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);
540
- });
541
- }
542
- /**
543
- * Check for modifier contradiction: same attribute with opposite negation
544
- */
545
- function hasModifierContradiction(conditions) {
546
- const byKey = /* @__PURE__ */ new Map();
547
- for (const mod of conditions) {
548
- const baseKey = mod.value ? `${mod.attribute}${mod.operator || "="}${mod.value}` : mod.attribute;
549
- const existing = byKey.get(baseKey);
550
- if (existing !== void 0 && existing !== !mod.negated) return true;
551
- byKey.set(baseKey, !mod.negated);
552
- }
553
- return false;
554
- }
555
- /**
556
- * Check for pseudo contradiction: same pseudo with opposite negation
557
- */
558
- function hasPseudoContradiction(conditions) {
559
- const byKey = /* @__PURE__ */ new Map();
560
- for (const pseudo of conditions) {
561
- const existing = byKey.get(pseudo.pseudo);
562
- if (existing !== void 0 && existing !== !pseudo.negated) return true;
563
- byKey.set(pseudo.pseudo, !pseudo.negated);
564
- }
565
- return false;
566
- }
567
- /**
568
- * Check for selector condition contradiction (modifier or pseudo with opposite negation).
569
- * Shared by root, parent, and own conditions.
570
- */
571
- function hasSelectorConditionContradiction(conditions) {
572
- const modifiers = [];
573
- const pseudos = [];
574
- for (const c of conditions) if ("attribute" in c) modifiers.push(c);
575
- else pseudos.push(c);
576
- return hasModifierContradiction(modifiers) || hasPseudoContradiction(pseudos);
577
- }
578
- /**
579
- * Check for parent group contradiction: same target (direct + conditions)
580
- * with opposite negation. E.g. :not([data-hovered] *) and :is([data-hovered] *)
581
- * in the same variant is impossible.
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
- }
591
- function hasParentGroupContradiction(groups) {
592
- const byBaseKey = /* @__PURE__ */ new Map();
593
- for (const g of groups) {
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);
609
- const existing = byBaseKey.get(baseKey);
610
- if (existing !== void 0 && existing !== !g.negated) return true;
611
- byBaseKey.set(baseKey, !g.negated);
612
- }
613
- return false;
614
- }
615
- /**
616
- * Merge two selector variants (AND operation)
617
- * Deduplicates conditions and checks for contradictions
618
- */
619
- function mergeVariants(a, b) {
620
- const mergedMedia = dedupeMediaConditions([...a.mediaConditions, ...b.mediaConditions]);
621
- if (hasMediaContradiction(mergedMedia)) return null;
622
- const mergedRootGroups = optimizeGroups([...a.rootGroups, ...b.rootGroups]);
623
- if (hasSelectorGroupContradiction(mergedRootGroups)) return null;
624
- const mergedModifiers = dedupeSelectorConditions([...a.modifierConditions, ...b.modifierConditions]);
625
- const mergedPseudos = dedupeSelectorConditions([...a.pseudoConditions, ...b.pseudoConditions]);
626
- if (hasSelectorConditionContradiction([...mergedModifiers, ...mergedPseudos])) return null;
627
- const mergedSelectorGroups = optimizeGroups([...a.selectorGroups, ...b.selectorGroups]);
628
- if (hasSelectorGroupContradiction(mergedSelectorGroups)) return null;
629
- const mergedParentGroups = [...a.parentGroups, ...b.parentGroups];
630
- if (hasParentGroupContradiction(mergedParentGroups)) return null;
631
- const mergedOwnGroups = optimizeGroups([...a.ownGroups, ...b.ownGroups]);
632
- if (hasSelectorGroupContradiction(mergedOwnGroups)) return null;
633
- const mergedContainers = dedupeContainerConditions([...a.containerConditions, ...b.containerConditions]);
634
- if (hasContainerStyleContradiction(mergedContainers)) return null;
635
- const mergedSupports = dedupeSupportsConditions([...a.supportsConditions, ...b.supportsConditions]);
636
- if (hasSupportsContradiction(mergedSupports)) return null;
637
- return {
638
- modifierConditions: mergedModifiers,
639
- pseudoConditions: mergedPseudos,
640
- selectorGroups: mergedSelectorGroups,
641
- ownGroups: mergedOwnGroups,
642
- mediaConditions: mergedMedia,
643
- containerConditions: mergedContainers,
644
- supportsConditions: mergedSupports,
645
- rootGroups: mergedRootGroups,
646
- parentGroups: mergedParentGroups,
647
- startingStyle: a.startingStyle || b.startingStyle
648
- };
649
- }
650
- const variantKeyCache = /* @__PURE__ */ new WeakMap();
651
- /**
652
- * Get a unique key for a variant (for deduplication).
653
- * Cached via WeakMap since variants are compared multiple times during
654
- * deduplication and sorting.
655
- */
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 [
666
- v.mediaConditions.map((c) => `${c.subtype}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|"),
667
- v.containerConditions.map((c) => `${c.name ?? ""}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|"),
668
- v.supportsConditions.map((c) => `${c.subtype}:${c.negated ? "!" : ""}${c.condition}`).sort().join("|"),
669
- v.rootGroups.map(getSelectorGroupKey).sort().join("|"),
670
- v.parentGroups.map(getParentGroupKey).sort().join("|"),
671
- v.ownGroups.map(getSelectorGroupKey).sort().join("|"),
672
- v.selectorGroups.map(getSelectorGroupKey).sort().join("|"),
673
- v.startingStyle ? "1" : "0"
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);
682
- variantKeyCache.set(v, key);
683
- return key;
684
- }
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
- /**
695
- * Check if variant A is a superset of variant B (A is more restrictive)
696
- *
697
- * If A has all of B's conditions plus more, then A is redundant
698
- * because B already covers the same cases (and more).
699
- *
700
- * Example:
701
- * A: :not([size=large]):not([size=medium]):not([size=small])
702
- * B: :not([size=large])
703
- * A is a superset of B, so A is redundant when B exists.
704
- */
705
- function isVariantSuperset(a, b) {
706
- if (a.startingStyle !== b.startingStyle) return false;
707
- if (!isSelectorGroupsSuperset(a.rootGroups, b.rootGroups)) return false;
708
- if (!isMediaConditionsSuperset(a.mediaConditions, b.mediaConditions)) return false;
709
- if (!isContainerConditionsSuperset(a.containerConditions, b.containerConditions)) return false;
710
- if (!isSupportsConditionsSuperset(a.supportsConditions, b.supportsConditions)) return false;
711
- if (!isModifierConditionsSuperset(a.modifierConditions, b.modifierConditions)) return false;
712
- if (!isPseudoConditionsSuperset(a.pseudoConditions, b.pseudoConditions)) return false;
713
- if (!isSelectorGroupsSuperset(a.selectorGroups, b.selectorGroups)) return false;
714
- if (!isSelectorGroupsSuperset(a.ownGroups, b.ownGroups)) return false;
715
- if (!isParentGroupsSuperset(a.parentGroups, b.parentGroups)) return false;
716
- return variantConditionCount(a) > variantConditionCount(b);
717
- }
718
- /**
719
- * Generic superset check: true if every item in B has a matching key in A.
720
- */
721
- function isConditionsSuperset(a, b, getKey) {
722
- const aKeys = new Set(a.map(getKey));
723
- return b.every((c) => aKeys.has(getKey(c)));
724
- }
725
- function isMediaConditionsSuperset(a, b) {
726
- return isConditionsSuperset(a, b, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
727
- }
728
- function isContainerConditionsSuperset(a, b) {
729
- return isConditionsSuperset(a, b, (c) => `${c.name ?? ""}|${c.condition}|${c.negated}`);
730
- }
731
- function isSupportsConditionsSuperset(a, b) {
732
- return isConditionsSuperset(a, b, (c) => `${c.subtype}|${c.condition}|${c.negated}`);
733
- }
734
- function isModifierConditionsSuperset(a, b) {
735
- return isConditionsSuperset(a, b, getModifierKey);
736
- }
737
- function isPseudoConditionsSuperset(a, b) {
738
- return isConditionsSuperset(a, b, getPseudoKey);
739
- }
740
- function isSelectorGroupsSuperset(a, b) {
741
- if (a.length < b.length) return false;
742
- return isConditionsSuperset(a, b, getSelectorGroupKey);
743
- }
744
- /**
745
- * Check if parent groups A is a superset of B.
746
- * Each group in B must have a matching group in A.
747
- */
748
- function isParentGroupsSuperset(a, b) {
749
- if (a.length < b.length) return false;
750
- return isConditionsSuperset(a, b, getParentGroupKey);
751
- }
752
- function getParentGroupKey(g) {
753
- return `${g.negated ? "!" : ""}${g.direct ? ">" : ""}(${getBranchesKey(g.branches)})`;
754
- }
755
- /**
756
- * Deduplicate variants
757
- *
758
- * Removes:
759
- * 1. Exact duplicates (same key)
760
- * 2. Superset variants (more restrictive selectors that are redundant)
761
- */
762
- function dedupeVariants(variants) {
763
- if (variants.length <= 1) return variants;
764
- const seen = /* @__PURE__ */ new Set();
765
- const result = [];
766
- for (const v of variants) {
767
- const key = getVariantKey(v);
768
- if (!seen.has(key)) {
769
- seen.add(key);
770
- result.push(v);
771
- }
772
- }
773
- if (result.length <= 1) return result;
774
- result.sort((a, b) => variantConditionCount(a) - variantConditionCount(b));
775
- const filtered = [];
776
- for (const candidate of result) {
777
- let isRedundant = false;
778
- for (const kept of filtered) if (isVariantSuperset(candidate, kept)) {
779
- isRedundant = true;
780
- break;
781
- }
782
- if (!isRedundant) filtered.push(candidate);
783
- }
784
- return filtered;
785
- }
786
- /**
787
- * Combine AND conditions into CSS
788
- *
789
- * AND of conditions means cartesian product of variants:
790
- * (A1 | A2) & (B1 | B2) = A1&B1 | A1&B2 | A2&B1 | A2&B2
791
- *
792
- * Variants that result in contradictions (e.g., conflicting media rules)
793
- * are filtered out.
794
- */
795
- function andToCSS(children) {
796
- const exclusiveChildren = makeOrBranchesExclusive(children);
797
- let currentVariants = [emptyVariant()];
798
- for (const child of exclusiveChildren) {
799
- const childCSS = conditionToCSSInner(child);
800
- if (childCSS.isImpossible || childCSS.variants.length === 0) return {
801
- variants: [],
802
- isImpossible: true
803
- };
804
- const newVariants = [];
805
- for (const current of currentVariants) for (const childVariant of childCSS.variants) {
806
- const merged = mergeVariants(current, childVariant);
807
- if (merged !== null) newVariants.push(merged);
808
- }
809
- if (newVariants.length === 0) return {
810
- variants: [],
811
- isImpossible: true
812
- };
813
- currentVariants = dedupeVariants(newVariants);
814
- }
815
- return {
816
- variants: currentVariants,
817
- isImpossible: false
818
- };
819
- }
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
- /**
873
- * Combine OR conditions into CSS
874
- *
875
- * OR in CSS means multiple selector variants (DNF).
876
- * After deduplication, variants that differ only in their base
877
- * modifier/pseudo conditions are merged into :is() groups.
878
- *
879
- * Note: OR exclusivity is handled at the pipeline level (expandOrConditions),
880
- * so here we just collect all variants. Any remaining ORs in the condition
881
- * tree (e.g., from De Morgan expansion) are handled as simple alternatives.
882
- */
883
- function orToCSS(children) {
884
- const allVariants = [];
885
- for (const child of children) {
886
- const childCSS = conditionToCSSInner(child);
887
- if (childCSS.isImpossible) continue;
888
- allVariants.push(...childCSS.variants);
889
- }
890
- if (allVariants.length === 0) return {
891
- variants: [],
892
- isImpossible: true
893
- };
894
- return {
895
- variants: dedupeVariants(allVariants),
896
- isImpossible: false
897
- };
898
- }
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
- /**
997
- * Build at-rules array from a variant
998
- */
999
- function buildAtRulesFromVariant(variant) {
1000
- const atRules = [];
1001
- if (variant.mediaConditions.length > 0) {
1002
- const conditionParts = variant.mediaConditions.map((c) => {
1003
- if (c.subtype === "type") return c.negated ? `not ${c.condition}` : c.condition;
1004
- else return c.negated ? `(not ${c.condition})` : c.condition;
1005
- });
1006
- atRules.push(`@media ${conditionParts.join(" and ")}`);
1007
- }
1008
- if (variant.containerConditions.length > 0) {
1009
- const byName = /* @__PURE__ */ new Map();
1010
- for (const cond of variant.containerConditions) {
1011
- const group = byName.get(cond.name) || [];
1012
- group.push(cond);
1013
- byName.set(cond.name, group);
1014
- }
1015
- for (const [name, conditions] of byName) {
1016
- const conditionParts = conditions.map((c) => c.negated ? `(not ${c.condition})` : c.condition);
1017
- const namePrefix = name ? `${name} ` : "";
1018
- atRules.push(`@container ${namePrefix}${conditionParts.join(" and ")}`);
1019
- }
1020
- }
1021
- if (variant.supportsConditions.length > 0) {
1022
- const conditionParts = variant.supportsConditions.map((c) => {
1023
- if (c.subtype === "selector") {
1024
- const selectorCond = `selector(${c.condition})`;
1025
- return c.negated ? `(not ${selectorCond})` : selectorCond;
1026
- } else {
1027
- const featureCond = `(${c.condition})`;
1028
- return c.negated ? `(not ${featureCond})` : featureCond;
1029
- }
1030
- });
1031
- atRules.push(`@supports ${conditionParts.join(" and ")}`);
1032
- }
1033
- return atRules;
1034
- }
1035
- //#endregion
1036
- export { branchToCSS, buildAtRulesFromVariant, conditionToCSS, mergeVariantsIntoSelectorGroups, optimizeGroups, parentGroupsToCSS, rootGroupsToCSS, selectorGroupToCSS };
1037
-
1038
- //# sourceMappingURL=materialize.js.map