@tenphi/tasty 2.0.2 → 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 (321) 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/docs/pipeline.md +204 -50
  51. package/package.json +3 -3
  52. package/dist/_virtual/_rolldown/runtime.js +0 -7
  53. package/dist/chunks/cacheKey.d.ts +0 -1
  54. package/dist/chunks/cacheKey.js +0 -77
  55. package/dist/chunks/cacheKey.js.map +0 -1
  56. package/dist/chunks/definitions.d.ts +0 -37
  57. package/dist/chunks/definitions.js +0 -258
  58. package/dist/chunks/definitions.js.map +0 -1
  59. package/dist/chunks/index.d.ts +0 -1
  60. package/dist/chunks/renderChunk.d.ts +0 -1
  61. package/dist/chunks/renderChunk.js +0 -59
  62. package/dist/chunks/renderChunk.js.map +0 -1
  63. package/dist/compute-styles.d.ts +0 -31
  64. package/dist/compute-styles.js +0 -322
  65. package/dist/compute-styles.js.map +0 -1
  66. package/dist/config.d.ts +0 -407
  67. package/dist/config.js +0 -591
  68. package/dist/config.js.map +0 -1
  69. package/dist/counter-style/index.js +0 -51
  70. package/dist/counter-style/index.js.map +0 -1
  71. package/dist/debug.d.ts +0 -89
  72. package/dist/debug.js +0 -453
  73. package/dist/debug.js.map +0 -1
  74. package/dist/font-face/index.js +0 -63
  75. package/dist/font-face/index.js.map +0 -1
  76. package/dist/hooks/index.d.ts +0 -7
  77. package/dist/hooks/useCounterStyle.d.ts +0 -36
  78. package/dist/hooks/useCounterStyle.js +0 -65
  79. package/dist/hooks/useCounterStyle.js.map +0 -1
  80. package/dist/hooks/useFontFace.d.ts +0 -45
  81. package/dist/hooks/useFontFace.js +0 -66
  82. package/dist/hooks/useFontFace.js.map +0 -1
  83. package/dist/hooks/useGlobalStyles.d.ts +0 -46
  84. package/dist/hooks/useGlobalStyles.js +0 -88
  85. package/dist/hooks/useGlobalStyles.js.map +0 -1
  86. package/dist/hooks/useKeyframes.d.ts +0 -58
  87. package/dist/hooks/useKeyframes.js +0 -55
  88. package/dist/hooks/useKeyframes.js.map +0 -1
  89. package/dist/hooks/useProperty.d.ts +0 -81
  90. package/dist/hooks/useProperty.js +0 -96
  91. package/dist/hooks/useProperty.js.map +0 -1
  92. package/dist/hooks/useRawCSS.d.ts +0 -22
  93. package/dist/hooks/useRawCSS.js +0 -103
  94. package/dist/hooks/useRawCSS.js.map +0 -1
  95. package/dist/hooks/useStyles.d.ts +0 -40
  96. package/dist/hooks/useStyles.js +0 -31
  97. package/dist/hooks/useStyles.js.map +0 -1
  98. package/dist/injector/index.d.ts +0 -182
  99. package/dist/injector/index.js +0 -185
  100. package/dist/injector/index.js.map +0 -1
  101. package/dist/injector/injector.d.ts +0 -198
  102. package/dist/injector/injector.js +0 -651
  103. package/dist/injector/injector.js.map +0 -1
  104. package/dist/injector/sheet-manager.d.ts +0 -132
  105. package/dist/injector/sheet-manager.js +0 -699
  106. package/dist/injector/sheet-manager.js.map +0 -1
  107. package/dist/injector/types.d.ts +0 -235
  108. package/dist/keyframes/index.js +0 -206
  109. package/dist/keyframes/index.js.map +0 -1
  110. package/dist/parser/classify.js +0 -319
  111. package/dist/parser/classify.js.map +0 -1
  112. package/dist/parser/const.js +0 -60
  113. package/dist/parser/const.js.map +0 -1
  114. package/dist/parser/lru.js +0 -109
  115. package/dist/parser/lru.js.map +0 -1
  116. package/dist/parser/parser.d.ts +0 -25
  117. package/dist/parser/parser.js +0 -115
  118. package/dist/parser/parser.js.map +0 -1
  119. package/dist/parser/tokenizer.js +0 -69
  120. package/dist/parser/tokenizer.js.map +0 -1
  121. package/dist/parser/types.d.ts +0 -51
  122. package/dist/parser/types.js +0 -46
  123. package/dist/parser/types.js.map +0 -1
  124. package/dist/pipeline/conditions.d.ts +0 -134
  125. package/dist/pipeline/conditions.js +0 -406
  126. package/dist/pipeline/conditions.js.map +0 -1
  127. package/dist/pipeline/exclusive.js +0 -382
  128. package/dist/pipeline/exclusive.js.map +0 -1
  129. package/dist/pipeline/index.d.ts +0 -55
  130. package/dist/pipeline/index.js +0 -708
  131. package/dist/pipeline/index.js.map +0 -1
  132. package/dist/pipeline/materialize.js +0 -1157
  133. package/dist/pipeline/materialize.js.map +0 -1
  134. package/dist/pipeline/parseStateKey.d.ts +0 -15
  135. package/dist/pipeline/parseStateKey.js +0 -446
  136. package/dist/pipeline/parseStateKey.js.map +0 -1
  137. package/dist/pipeline/simplify.js +0 -690
  138. package/dist/pipeline/simplify.js.map +0 -1
  139. package/dist/pipeline/warnings.js +0 -18
  140. package/dist/pipeline/warnings.js.map +0 -1
  141. package/dist/plugins/index.d.ts +0 -2
  142. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  143. package/dist/plugins/okhsl-plugin.js +0 -97
  144. package/dist/plugins/okhsl-plugin.js.map +0 -1
  145. package/dist/plugins/types.d.ts +0 -87
  146. package/dist/properties/index.js +0 -222
  147. package/dist/properties/index.js.map +0 -1
  148. package/dist/properties/property-type-resolver.d.ts +0 -24
  149. package/dist/properties/property-type-resolver.js +0 -90
  150. package/dist/properties/property-type-resolver.js.map +0 -1
  151. package/dist/rsc-cache.js +0 -79
  152. package/dist/rsc-cache.js.map +0 -1
  153. package/dist/ssr/async-storage.d.ts +0 -17
  154. package/dist/ssr/async-storage.js.map +0 -1
  155. package/dist/ssr/collect-auto-properties.js +0 -58
  156. package/dist/ssr/collect-auto-properties.js.map +0 -1
  157. package/dist/ssr/collector.js.map +0 -1
  158. package/dist/ssr/context.js.map +0 -1
  159. package/dist/ssr/format-global-rules.js.map +0 -1
  160. package/dist/ssr/format-keyframes.js +0 -69
  161. package/dist/ssr/format-keyframes.js.map +0 -1
  162. package/dist/ssr/format-property.js +0 -49
  163. package/dist/ssr/format-property.js.map +0 -1
  164. package/dist/ssr/format-rules.js +0 -73
  165. package/dist/ssr/format-rules.js.map +0 -1
  166. package/dist/ssr/hydrate.d.ts +0 -29
  167. package/dist/ssr/hydrate.js.map +0 -1
  168. package/dist/ssr/ssr-collector-ref.js +0 -29
  169. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  170. package/dist/states/index.d.ts +0 -49
  171. package/dist/states/index.js +0 -170
  172. package/dist/states/index.js.map +0 -1
  173. package/dist/static/tastyStatic.d.ts +0 -46
  174. package/dist/static/tastyStatic.js +0 -30
  175. package/dist/static/tastyStatic.js.map +0 -1
  176. package/dist/static/types.d.ts +0 -49
  177. package/dist/static/types.js +0 -24
  178. package/dist/static/types.js.map +0 -1
  179. package/dist/styles/border.d.ts +0 -25
  180. package/dist/styles/border.js +0 -120
  181. package/dist/styles/border.js.map +0 -1
  182. package/dist/styles/color.d.ts +0 -14
  183. package/dist/styles/color.js +0 -26
  184. package/dist/styles/color.js.map +0 -1
  185. package/dist/styles/const.js +0 -17
  186. package/dist/styles/const.js.map +0 -1
  187. package/dist/styles/createStyle.js +0 -79
  188. package/dist/styles/createStyle.js.map +0 -1
  189. package/dist/styles/dimension.js +0 -109
  190. package/dist/styles/dimension.js.map +0 -1
  191. package/dist/styles/directional.js +0 -133
  192. package/dist/styles/directional.js.map +0 -1
  193. package/dist/styles/display.d.ts +0 -30
  194. package/dist/styles/display.js +0 -73
  195. package/dist/styles/display.js.map +0 -1
  196. package/dist/styles/fade.d.ts +0 -15
  197. package/dist/styles/fade.js +0 -62
  198. package/dist/styles/fade.js.map +0 -1
  199. package/dist/styles/fill.d.ts +0 -42
  200. package/dist/styles/fill.js +0 -51
  201. package/dist/styles/fill.js.map +0 -1
  202. package/dist/styles/flow.d.ts +0 -16
  203. package/dist/styles/flow.js +0 -12
  204. package/dist/styles/flow.js.map +0 -1
  205. package/dist/styles/gap.d.ts +0 -31
  206. package/dist/styles/gap.js +0 -38
  207. package/dist/styles/gap.js.map +0 -1
  208. package/dist/styles/height.d.ts +0 -17
  209. package/dist/styles/height.js +0 -19
  210. package/dist/styles/height.js.map +0 -1
  211. package/dist/styles/index.d.ts +0 -1
  212. package/dist/styles/index.js +0 -8
  213. package/dist/styles/index.js.map +0 -1
  214. package/dist/styles/inset.d.ts +0 -24
  215. package/dist/styles/inset.js +0 -34
  216. package/dist/styles/inset.js.map +0 -1
  217. package/dist/styles/list.d.ts +0 -16
  218. package/dist/styles/list.js +0 -100
  219. package/dist/styles/list.js.map +0 -1
  220. package/dist/styles/margin.d.ts +0 -24
  221. package/dist/styles/margin.js +0 -32
  222. package/dist/styles/margin.js.map +0 -1
  223. package/dist/styles/outline.d.ts +0 -29
  224. package/dist/styles/outline.js +0 -55
  225. package/dist/styles/outline.js.map +0 -1
  226. package/dist/styles/padding.d.ts +0 -24
  227. package/dist/styles/padding.js +0 -32
  228. package/dist/styles/padding.js.map +0 -1
  229. package/dist/styles/placement.d.ts +0 -37
  230. package/dist/styles/placement.js +0 -74
  231. package/dist/styles/placement.js.map +0 -1
  232. package/dist/styles/predefined.d.ts +0 -71
  233. package/dist/styles/predefined.js +0 -237
  234. package/dist/styles/predefined.js.map +0 -1
  235. package/dist/styles/preset.d.ts +0 -52
  236. package/dist/styles/preset.js +0 -127
  237. package/dist/styles/preset.js.map +0 -1
  238. package/dist/styles/radius.d.ts +0 -12
  239. package/dist/styles/radius.js +0 -83
  240. package/dist/styles/radius.js.map +0 -1
  241. package/dist/styles/scrollMargin.d.ts +0 -24
  242. package/dist/styles/scrollMargin.js +0 -32
  243. package/dist/styles/scrollMargin.js.map +0 -1
  244. package/dist/styles/scrollbar.d.ts +0 -25
  245. package/dist/styles/scrollbar.js +0 -51
  246. package/dist/styles/scrollbar.js.map +0 -1
  247. package/dist/styles/shadow.d.ts +0 -14
  248. package/dist/styles/shadow.js +0 -25
  249. package/dist/styles/shadow.js.map +0 -1
  250. package/dist/styles/shared.js +0 -17
  251. package/dist/styles/shared.js.map +0 -1
  252. package/dist/styles/transition.d.ts +0 -14
  253. package/dist/styles/transition.js +0 -159
  254. package/dist/styles/transition.js.map +0 -1
  255. package/dist/styles/width.d.ts +0 -17
  256. package/dist/styles/width.js +0 -19
  257. package/dist/styles/width.js.map +0 -1
  258. package/dist/tasty.d.ts +0 -134
  259. package/dist/tasty.js +0 -248
  260. package/dist/tasty.js.map +0 -1
  261. package/dist/types.d.ts +0 -184
  262. package/dist/utils/cache-wrapper.js +0 -21
  263. package/dist/utils/cache-wrapper.js.map +0 -1
  264. package/dist/utils/case-converter.js +0 -8
  265. package/dist/utils/case-converter.js.map +0 -1
  266. package/dist/utils/color-math.d.ts +0 -46
  267. package/dist/utils/color-math.js +0 -749
  268. package/dist/utils/color-math.js.map +0 -1
  269. package/dist/utils/color-space.d.ts +0 -5
  270. package/dist/utils/color-space.js +0 -228
  271. package/dist/utils/color-space.js.map +0 -1
  272. package/dist/utils/colors.d.ts +0 -5
  273. package/dist/utils/colors.js +0 -10
  274. package/dist/utils/colors.js.map +0 -1
  275. package/dist/utils/css-types.d.ts +0 -7
  276. package/dist/utils/deps-equal.js +0 -15
  277. package/dist/utils/deps-equal.js.map +0 -1
  278. package/dist/utils/dotize.d.ts +0 -26
  279. package/dist/utils/dotize.js +0 -122
  280. package/dist/utils/dotize.js.map +0 -1
  281. package/dist/utils/filter-base-props.d.ts +0 -15
  282. package/dist/utils/filter-base-props.js +0 -45
  283. package/dist/utils/filter-base-props.js.map +0 -1
  284. package/dist/utils/get-display-name.d.ts +0 -7
  285. package/dist/utils/get-display-name.js +0 -10
  286. package/dist/utils/get-display-name.js.map +0 -1
  287. package/dist/utils/has-keys.js +0 -13
  288. package/dist/utils/has-keys.js.map +0 -1
  289. package/dist/utils/hash.js +0 -14
  290. package/dist/utils/hash.js.map +0 -1
  291. package/dist/utils/is-dev-env.js +0 -19
  292. package/dist/utils/is-dev-env.js.map +0 -1
  293. package/dist/utils/is-valid-element-type.js +0 -15
  294. package/dist/utils/is-valid-element-type.js.map +0 -1
  295. package/dist/utils/merge-styles.js.map +0 -1
  296. package/dist/utils/mod-attrs.d.ts +0 -6
  297. package/dist/utils/mod-attrs.js +0 -20
  298. package/dist/utils/mod-attrs.js.map +0 -1
  299. package/dist/utils/process-tokens.d.ts +0 -17
  300. package/dist/utils/process-tokens.js +0 -83
  301. package/dist/utils/process-tokens.js.map +0 -1
  302. package/dist/utils/resolve-recipes.d.ts +0 -17
  303. package/dist/utils/resolve-recipes.js.map +0 -1
  304. package/dist/utils/selector-transform.js +0 -32
  305. package/dist/utils/selector-transform.js.map +0 -1
  306. package/dist/utils/string.js +0 -8
  307. package/dist/utils/string.js.map +0 -1
  308. package/dist/utils/styles.d.ts +0 -99
  309. package/dist/utils/styles.js +0 -220
  310. package/dist/utils/styles.js.map +0 -1
  311. package/dist/utils/typography.d.ts +0 -58
  312. package/dist/utils/typography.js +0 -51
  313. package/dist/utils/typography.js.map +0 -1
  314. package/dist/utils/warnings.d.ts +0 -16
  315. package/dist/utils/warnings.js +0 -16
  316. package/dist/utils/warnings.js.map +0 -1
  317. package/dist/zero/css-writer.d.ts +0 -45
  318. package/dist/zero/css-writer.js +0 -73
  319. package/dist/zero/css-writer.js.map +0 -1
  320. package/dist/zero/extractor.d.ts +0 -24
  321. package/dist/zero/extractor.js.map +0 -1
@@ -1,382 +0,0 @@
1
- import { and, isCompoundCondition, not, or, trueCondition } from "./conditions.js";
2
- import { simplifyCondition } from "./simplify.js";
3
- //#region src/pipeline/exclusive.ts
4
- /**
5
- * Build exclusive conditions for a list of parsed style entries.
6
- *
7
- * The entries should be ordered by priority (highest priority first).
8
- *
9
- * For each entry, we compute:
10
- * exclusiveCondition = condition & !prior[0] & !prior[1] & ...
11
- *
12
- * This ensures exactly one condition matches at any time.
13
- *
14
- * Example:
15
- * Input (ordered highest to lowest priority):
16
- * A: value1 (priority 2)
17
- * B: value2 (priority 1)
18
- * C: value3 (priority 0)
19
- *
20
- * Output:
21
- * A: A
22
- * B: B & !A
23
- * C: C & !A & !B
24
- *
25
- * @param entries Parsed style entries ordered by priority (highest first)
26
- * @returns Entries with exclusive conditions, filtered to remove impossible ones
27
- */
28
- function buildExclusiveConditions(entries) {
29
- const result = [];
30
- const priorConditions = [];
31
- for (const entry of entries) {
32
- let exclusive = entry.condition;
33
- for (const prior of priorConditions) if (prior.kind !== "true") exclusive = and(exclusive, not(prior));
34
- const simplified = simplifyCondition(exclusive);
35
- if (simplified.kind === "false") continue;
36
- result.push({
37
- ...entry,
38
- exclusiveCondition: simplified
39
- });
40
- if (entry.condition.kind !== "true") priorConditions.push(entry.condition);
41
- }
42
- return result;
43
- }
44
- /**
45
- * Parse style entries from a value mapping object.
46
- *
47
- * @param styleKey The style key (e.g., 'padding')
48
- * @param valueMap The value mapping { '': '2x', 'compact': '1x', '@media(w < 768px)': '0.5x' }
49
- * @param parseCondition Function to parse state keys into conditions
50
- * @returns Parsed entries ordered by priority (highest first)
51
- */
52
- function parseStyleEntries(styleKey, valueMap, parseCondition) {
53
- const entries = [];
54
- Object.keys(valueMap).forEach((stateKey, index) => {
55
- const value = valueMap[stateKey];
56
- const condition = stateKey === "" ? trueCondition() : parseCondition(stateKey);
57
- entries.push({
58
- styleKey,
59
- stateKey,
60
- value,
61
- condition,
62
- priority: index
63
- });
64
- });
65
- entries.reverse();
66
- return entries;
67
- }
68
- /**
69
- * Merge parsed entries that share the same value.
70
- *
71
- * When multiple **non-default** state keys map to the same value, their
72
- * conditions can be combined with OR and treated as a single entry.
73
- * This must happen **before** exclusive expansion and OR branch splitting
74
- * to avoid combinatorial explosion and duplicate CSS output.
75
- *
76
- * Default (TRUE) entries are **never** merged with non-default entries.
77
- * Merging `TRUE | X` collapses to `TRUE`, destroying the non-default
78
- * condition's participation in exclusive building. That causes
79
- * intermediate-priority states to lose their `:not(X)` negation,
80
- * breaking mutual exclusivity when X and an intermediate state are
81
- * both active. Stage 6 `mergeByValue` handles combining rules with
82
- * identical CSS output after exclusive conditions are correctly built.
83
- *
84
- * Example: `{ '@dark': 'red', '@dark & @hc': 'red' }` merges into a
85
- * single entry with condition `@dark | (@dark & @hc)` = `@dark`.
86
- *
87
- * Entries are ordered highest-priority-first. The merged entry keeps the
88
- * highest priority of the group.
89
- */
90
- function mergeEntriesByValue(entries) {
91
- if (entries.length <= 1) return entries;
92
- const groups = /* @__PURE__ */ new Map();
93
- for (const entry of entries) {
94
- const valueKey = serializeValue(entry.value);
95
- const group = groups.get(valueKey);
96
- if (group) {
97
- group.entries.push(entry);
98
- group.maxPriority = Math.max(group.maxPriority, entry.priority);
99
- } else groups.set(valueKey, {
100
- entries: [entry],
101
- maxPriority: entry.priority
102
- });
103
- }
104
- if (groups.size === entries.length) return entries;
105
- const merged = [];
106
- for (const [, group] of groups) {
107
- if (group.entries.length === 1) {
108
- merged.push(group.entries[0]);
109
- continue;
110
- }
111
- const defaultEntries = group.entries.filter((e) => e.condition.kind === "true");
112
- const nonDefaultEntries = group.entries.filter((e) => e.condition.kind !== "true");
113
- for (const entry of defaultEntries) merged.push(entry);
114
- if (nonDefaultEntries.length === 1) merged.push(nonDefaultEntries[0]);
115
- else if (nonDefaultEntries.length >= 2) {
116
- const combinedCondition = simplifyCondition(or(...nonDefaultEntries.map((e) => e.condition)));
117
- const combinedStateKey = nonDefaultEntries.map((e) => e.stateKey).join(" | ");
118
- merged.push({
119
- styleKey: nonDefaultEntries[0].styleKey,
120
- stateKey: combinedStateKey,
121
- value: nonDefaultEntries[0].value,
122
- condition: combinedCondition,
123
- priority: group.maxPriority
124
- });
125
- }
126
- }
127
- merged.sort((a, b) => b.priority - a.priority);
128
- return merged;
129
- }
130
- function serializeValue(value) {
131
- if (value === null || value === void 0) return "null";
132
- if (typeof value === "string" || typeof value === "number") return String(value);
133
- return JSON.stringify(value);
134
- }
135
- /**
136
- * Eliminate redundant state dimensions from a value map.
137
- *
138
- * When a value map contains compound AND state keys (e.g. `@dark & @hc`),
139
- * checks whether any state atom is a "don't-care" variable — i.e. the
140
- * value is the same whether that atom is present or absent. Redundant
141
- * atoms are removed from all keys and duplicate entries are collapsed.
142
- *
143
- * This runs **before** condition parsing so that downstream stages
144
- * (`mergeEntriesByValue`, `buildExclusiveConditions`, materialization)
145
- * never see the irrelevant dimension, producing simpler, smaller CSS.
146
- *
147
- * Only pure top-level AND combinations are eligible. Keys that contain
148
- * `|`, `^`, or `,` at the top level are treated as opaque single atoms.
149
- *
150
- * @example
151
- * { '': A, '@dark': B, '@hc': A, '@dark & @hc': B }
152
- * // @hc is redundant → { '': A, '@dark': B }
153
- */
154
- function extractCompoundStates(valueMap) {
155
- const keys = Object.keys(valueMap);
156
- if (keys.length < 3 || !keys.some((k) => k.includes("&"))) return valueMap;
157
- const entries = keys.map((key) => {
158
- return {
159
- atoms: splitTopLevelAnd(key) ?? [key],
160
- value: valueMap[key]
161
- };
162
- });
163
- const allAtoms = /* @__PURE__ */ new Set();
164
- for (const e of entries) for (const a of e.atoms) allAtoms.add(a);
165
- const redundant = /* @__PURE__ */ new Set();
166
- for (const atom of allAtoms) if (isAtomRedundant(entries, atom)) redundant.add(atom);
167
- if (redundant.size === 0) return valueMap;
168
- const newMap = {};
169
- for (const e of entries) {
170
- const newKey = e.atoms.filter((a) => !redundant.has(a)).join(" & ");
171
- if (!(newKey in newMap)) newMap[newKey] = e.value;
172
- }
173
- return newMap;
174
- }
175
- /**
176
- * Split a state key by top-level `&` operators.
177
- *
178
- * Returns `null` if the key contains `|`, `^`, or `,` at the top level
179
- * (making it ineligible for atom-level extraction).
180
- * Returns `[]` for the empty string (default key).
181
- */
182
- function splitTopLevelAnd(key) {
183
- if (key === "") return [];
184
- const parts = [];
185
- let depth = 0;
186
- let current = "";
187
- for (const ch of key) {
188
- if (ch === "(" || ch === "[") depth++;
189
- else if (ch === ")" || ch === "]") depth--;
190
- if (depth === 0) {
191
- if (ch === "&") {
192
- const trimmed = current.trim();
193
- if (trimmed) parts.push(trimmed);
194
- current = "";
195
- continue;
196
- }
197
- if (ch === "|" || ch === "^" || ch === ",") return null;
198
- }
199
- current += ch;
200
- }
201
- const trimmed = current.trim();
202
- if (trimmed) parts.push(trimmed);
203
- return parts;
204
- }
205
- /**
206
- * An atom is redundant when every entry that contains it has a matching
207
- * partner (same remaining atoms, atom absent) with the same value.
208
- */
209
- function isAtomRedundant(entries, atom) {
210
- const withAtom = entries.filter((e) => e.atoms.includes(atom));
211
- if (withAtom.length === 0) return false;
212
- for (const wa of withAtom) {
213
- const remaining = wa.atoms.filter((a) => a !== atom);
214
- const pair = entries.find((e) => !e.atoms.includes(atom) && e.atoms.length === remaining.length && remaining.every((r) => e.atoms.includes(r)));
215
- if (!pair) return false;
216
- if (serializeValue(wa.value) !== serializeValue(pair.value)) return false;
217
- }
218
- return true;
219
- }
220
- /**
221
- * Check if a value is a style value mapping (object with state keys)
222
- */
223
- function isValueMapping(value) {
224
- return value !== null && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
225
- }
226
- /**
227
- * Expand OR conditions in parsed entries into multiple exclusive entries.
228
- *
229
- * For an entry with condition `A | B | C`, this creates 3 entries:
230
- * - condition: A
231
- * - condition: B & !A
232
- * - condition: C & !A & !B
233
- *
234
- * This ensures OR branches are mutually exclusive BEFORE the main
235
- * exclusive condition building pass.
236
- *
237
- * @param entries Parsed entries (may contain OR conditions)
238
- * @returns Expanded entries with OR branches made exclusive
239
- */
240
- function expandOrConditions(entries) {
241
- const result = [];
242
- for (const entry of entries) {
243
- const expanded = expandSingleEntry(entry);
244
- result.push(...expanded);
245
- }
246
- return result;
247
- }
248
- /**
249
- * Expand a single entry's OR condition into multiple exclusive entries
250
- */
251
- function expandSingleEntry(entry) {
252
- const orBranches = collectOrBranches(entry.condition);
253
- if (orBranches.length <= 1) return [entry];
254
- const result = [];
255
- const priorBranches = [];
256
- for (let i = 0; i < orBranches.length; i++) {
257
- const branch = orBranches[i];
258
- let exclusiveBranch = branch;
259
- for (const prior of priorBranches) exclusiveBranch = and(exclusiveBranch, not(prior));
260
- const simplified = simplifyCondition(exclusiveBranch);
261
- if (simplified.kind === "false") {
262
- priorBranches.push(branch);
263
- continue;
264
- }
265
- result.push({
266
- ...entry,
267
- stateKey: `${entry.stateKey}[${i}]`,
268
- condition: simplified
269
- });
270
- priorBranches.push(branch);
271
- }
272
- return result;
273
- }
274
- /**
275
- * Collect top-level OR branches from a condition.
276
- *
277
- * For `A | B | C`, returns [A, B, C]
278
- * For `A & B`, returns [A & B] (single branch)
279
- * For `A | (B & C)`, returns [A, B & C]
280
- */
281
- function collectOrBranches(condition) {
282
- if (condition.kind === "true" || condition.kind === "false") return [condition];
283
- if (isCompoundCondition(condition) && condition.operator === "OR") {
284
- const branches = [];
285
- for (const child of condition.children) branches.push(...collectOrBranches(child));
286
- return branches;
287
- }
288
- return [condition];
289
- }
290
- /**
291
- * Expand OR conditions in exclusive entries AFTER buildExclusiveConditions.
292
- *
293
- * This handles ORs that arise from De Morgan expansion during negation:
294
- * !(A & B) = !A | !B
295
- *
296
- * These ORs need to be made exclusive to avoid overlapping CSS rules:
297
- * !A | !B → !A | (A & !B)
298
- *
299
- * This is logically equivalent but ensures each branch has proper context.
300
- *
301
- * Example:
302
- * Input: { "": V1, "@supports(...) & :has()": V2 }
303
- * V2's exclusive = @supports & :has
304
- * V1's exclusive = !(@supports & :has) = !@supports | !:has
305
- *
306
- * Without this fix: V1 gets two rules:
307
- * - @supports (not ...) → V1 ✓
308
- * - :not(:has()) → V1 ✗ (missing @supports context!)
309
- *
310
- * With this fix: V1 gets two exclusive rules:
311
- * - @supports (not ...) → V1 ✓
312
- * - @supports (...) { :not(:has()) } → V1 ✓ (proper context!)
313
- */
314
- function expandExclusiveOrs(entries) {
315
- const result = [];
316
- for (const entry of entries) {
317
- const expanded = expandExclusiveConditionOrs(entry);
318
- result.push(...expanded);
319
- }
320
- return result;
321
- }
322
- /**
323
- * Check if a condition involves at-rules (media, container, supports, starting)
324
- */
325
- function hasAtRuleContext(node) {
326
- if (node.kind === "true" || node.kind === "false") return false;
327
- if (node.kind === "state") return node.type === "media" || node.type === "container" || node.type === "supports" || node.type === "starting";
328
- if (node.kind === "compound") return node.children.some(hasAtRuleContext);
329
- return false;
330
- }
331
- /**
332
- * Sort OR branches to prioritize at-rule conditions first.
333
- *
334
- * This is critical for correct CSS generation. For `!A | !B` where A is at-rule
335
- * and B is modifier, we want:
336
- * - Branch 0: !A (at-rule negation - covers "no @supports/media" case)
337
- * - Branch 1: A & !B (modifier negation with at-rule context)
338
- *
339
- * If we process in wrong order (!B first), we'd get:
340
- * - Branch 0: !B (modifier negation WITHOUT at-rule context - WRONG!)
341
- * - Branch 1: B & !A (at-rule negation with modifier - incomplete coverage)
342
- */
343
- function sortOrBranchesForExpansion(branches) {
344
- return [...branches].sort((a, b) => {
345
- const aHasAtRule = hasAtRuleContext(a);
346
- const bHasAtRule = hasAtRuleContext(b);
347
- if (aHasAtRule && !bHasAtRule) return -1;
348
- if (!aHasAtRule && bHasAtRule) return 1;
349
- return 0;
350
- });
351
- }
352
- /**
353
- * Expand ORs in a single entry's exclusive condition
354
- */
355
- function expandExclusiveConditionOrs(entry) {
356
- let orBranches = collectOrBranches(entry.exclusiveCondition);
357
- if (orBranches.length <= 1) return [entry];
358
- orBranches = sortOrBranchesForExpansion(orBranches);
359
- const result = [];
360
- const priorBranches = [];
361
- for (let i = 0; i < orBranches.length; i++) {
362
- const branch = orBranches[i];
363
- let exclusiveBranch = branch;
364
- for (const prior of priorBranches) exclusiveBranch = and(exclusiveBranch, not(prior));
365
- const simplified = simplifyCondition(exclusiveBranch);
366
- if (simplified.kind === "false") {
367
- priorBranches.push(branch);
368
- continue;
369
- }
370
- result.push({
371
- ...entry,
372
- stateKey: `${entry.stateKey}[or:${i}]`,
373
- exclusiveCondition: simplified
374
- });
375
- priorBranches.push(branch);
376
- }
377
- return result;
378
- }
379
- //#endregion
380
- export { buildExclusiveConditions, expandExclusiveOrs, expandOrConditions, extractCompoundStates, isValueMapping, mergeEntriesByValue, parseStyleEntries };
381
-
382
- //# sourceMappingURL=exclusive.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exclusive.js","names":[],"sources":["../../src/pipeline/exclusive.ts"],"sourcesContent":["/**\n * Exclusive Condition Builder\n *\n * Transforms parsed style entries into exclusive conditions.\n * Each entry's condition is ANDed with the negation of all higher-priority conditions,\n * ensuring exactly one condition matches at any given time.\n */\n\nimport type { StyleValue } from '../utils/styles';\n\nimport type { ConditionNode } from './conditions';\nimport { and, isCompoundCondition, not, or, trueCondition } from './conditions';\nimport { simplifyCondition } from './simplify';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Parsed style entry with condition\n */\nexport interface ParsedStyleEntry {\n styleKey: string; // e.g., 'padding', 'fill'\n stateKey: string; // Original key: '', 'compact', '@media(w < 768px)'\n value: StyleValue; // The style value (before handler processing)\n condition: ConditionNode; // Parsed condition tree\n priority: number; // Order in original object (higher = higher priority)\n}\n\n/**\n * Style entry with exclusive condition\n */\nexport interface ExclusiveStyleEntry extends ParsedStyleEntry {\n exclusiveCondition: ConditionNode; // condition & !higherPriorityConditions\n}\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\n/**\n * Build exclusive conditions for a list of parsed style entries.\n *\n * The entries should be ordered by priority (highest priority first).\n *\n * For each entry, we compute:\n * exclusiveCondition = condition & !prior[0] & !prior[1] & ...\n *\n * This ensures exactly one condition matches at any time.\n *\n * Example:\n * Input (ordered highest to lowest priority):\n * A: value1 (priority 2)\n * B: value2 (priority 1)\n * C: value3 (priority 0)\n *\n * Output:\n * A: A\n * B: B & !A\n * C: C & !A & !B\n *\n * @param entries Parsed style entries ordered by priority (highest first)\n * @returns Entries with exclusive conditions, filtered to remove impossible ones\n */\nexport function buildExclusiveConditions(\n entries: ParsedStyleEntry[],\n): ExclusiveStyleEntry[] {\n const result: ExclusiveStyleEntry[] = [];\n const priorConditions: ConditionNode[] = [];\n\n for (const entry of entries) {\n // Build: condition & !prior[0] & !prior[1] & ...\n let exclusive: ConditionNode = entry.condition;\n\n for (const prior of priorConditions) {\n // Skip negating \"always true\" (default state) - it would become \"always false\"\n if (prior.kind !== 'true') {\n exclusive = and(exclusive, not(prior));\n }\n }\n\n // Simplify the exclusive condition\n const simplified = simplifyCondition(exclusive);\n\n // Skip impossible conditions (simplified to FALSE)\n if (simplified.kind === 'false') {\n continue;\n }\n\n result.push({\n ...entry,\n exclusiveCondition: simplified,\n });\n\n // Add non-default conditions to prior list for subsequent entries\n if (entry.condition.kind !== 'true') {\n priorConditions.push(entry.condition);\n }\n }\n\n return result;\n}\n\n/**\n * Parse style entries from a value mapping object.\n *\n * @param styleKey The style key (e.g., 'padding')\n * @param valueMap The value mapping { '': '2x', 'compact': '1x', '@media(w < 768px)': '0.5x' }\n * @param parseCondition Function to parse state keys into conditions\n * @returns Parsed entries ordered by priority (highest first)\n */\nexport function parseStyleEntries(\n styleKey: string,\n valueMap: Record<string, StyleValue>,\n parseCondition: (stateKey: string) => ConditionNode,\n): ParsedStyleEntry[] {\n const entries: ParsedStyleEntry[] = [];\n const keys = Object.keys(valueMap);\n\n keys.forEach((stateKey, index) => {\n const value = valueMap[stateKey];\n const condition =\n stateKey === '' ? trueCondition() : parseCondition(stateKey);\n\n entries.push({\n styleKey,\n stateKey,\n value,\n condition,\n priority: index,\n });\n });\n\n // Reverse so highest priority (last in object) comes first for exclusive building\n // buildExclusiveConditions expects highest priority first\n entries.reverse();\n\n return entries;\n}\n\n/**\n * Merge parsed entries that share the same value.\n *\n * When multiple **non-default** state keys map to the same value, their\n * conditions can be combined with OR and treated as a single entry.\n * This must happen **before** exclusive expansion and OR branch splitting\n * to avoid combinatorial explosion and duplicate CSS output.\n *\n * Default (TRUE) entries are **never** merged with non-default entries.\n * Merging `TRUE | X` collapses to `TRUE`, destroying the non-default\n * condition's participation in exclusive building. That causes\n * intermediate-priority states to lose their `:not(X)` negation,\n * breaking mutual exclusivity when X and an intermediate state are\n * both active. Stage 6 `mergeByValue` handles combining rules with\n * identical CSS output after exclusive conditions are correctly built.\n *\n * Example: `{ '@dark': 'red', '@dark & @hc': 'red' }` merges into a\n * single entry with condition `@dark | (@dark & @hc)` = `@dark`.\n *\n * Entries are ordered highest-priority-first. The merged entry keeps the\n * highest priority of the group.\n */\nexport function mergeEntriesByValue(\n entries: ParsedStyleEntry[],\n): ParsedStyleEntry[] {\n if (entries.length <= 1) return entries;\n\n const groups = new Map<\n string,\n { entries: ParsedStyleEntry[]; maxPriority: number }\n >();\n\n for (const entry of entries) {\n const valueKey = serializeValue(entry.value);\n const group = groups.get(valueKey);\n if (group) {\n group.entries.push(entry);\n group.maxPriority = Math.max(group.maxPriority, entry.priority);\n } else {\n groups.set(valueKey, { entries: [entry], maxPriority: entry.priority });\n }\n }\n\n // If no merges possible, return as-is\n if (groups.size === entries.length) return entries;\n\n const merged: ParsedStyleEntry[] = [];\n for (const [, group] of groups) {\n if (group.entries.length === 1) {\n merged.push(group.entries[0]);\n continue;\n }\n\n // Separate default (TRUE) entries from non-default entries.\n // Default entries must stay separate so that non-default conditions\n // participate in exclusive building and block intermediate states.\n const defaultEntries = group.entries.filter(\n (e) => e.condition.kind === 'true',\n );\n const nonDefaultEntries = group.entries.filter(\n (e) => e.condition.kind !== 'true',\n );\n\n // Keep default entries as-is\n for (const entry of defaultEntries) {\n merged.push(entry);\n }\n\n // Merge only non-default entries\n if (nonDefaultEntries.length === 1) {\n merged.push(nonDefaultEntries[0]);\n } else if (nonDefaultEntries.length >= 2) {\n const combinedCondition = simplifyCondition(\n or(...nonDefaultEntries.map((e) => e.condition)),\n );\n\n const combinedStateKey = nonDefaultEntries\n .map((e) => e.stateKey)\n .join(' | ');\n\n merged.push({\n styleKey: nonDefaultEntries[0].styleKey,\n stateKey: combinedStateKey,\n value: nonDefaultEntries[0].value,\n condition: combinedCondition,\n priority: group.maxPriority,\n });\n }\n }\n\n // Re-sort by priority (highest first)\n merged.sort((a, b) => b.priority - a.priority);\n\n return merged;\n}\n\nfunction serializeValue(value: StyleValue): string {\n if (value === null || value === undefined) return 'null';\n if (typeof value === 'string' || typeof value === 'number') {\n return String(value);\n }\n return JSON.stringify(value);\n}\n\n// ============================================================================\n// Compound State Extraction\n// ============================================================================\n\n/**\n * Eliminate redundant state dimensions from a value map.\n *\n * When a value map contains compound AND state keys (e.g. `@dark & @hc`),\n * checks whether any state atom is a \"don't-care\" variable — i.e. the\n * value is the same whether that atom is present or absent. Redundant\n * atoms are removed from all keys and duplicate entries are collapsed.\n *\n * This runs **before** condition parsing so that downstream stages\n * (`mergeEntriesByValue`, `buildExclusiveConditions`, materialization)\n * never see the irrelevant dimension, producing simpler, smaller CSS.\n *\n * Only pure top-level AND combinations are eligible. Keys that contain\n * `|`, `^`, or `,` at the top level are treated as opaque single atoms.\n *\n * @example\n * { '': A, '@dark': B, '@hc': A, '@dark & @hc': B }\n * // @hc is redundant → { '': A, '@dark': B }\n */\nexport function extractCompoundStates(\n valueMap: Record<string, StyleValue>,\n): Record<string, StyleValue> {\n const keys = Object.keys(valueMap);\n\n if (keys.length < 3 || !keys.some((k) => k.includes('&'))) {\n return valueMap;\n }\n\n const entries = keys.map((key) => {\n const atoms = splitTopLevelAnd(key);\n return {\n // null means the key has non-AND operators; treat the whole key\n // as a single opaque atom so it never matches partial pairs.\n atoms: atoms ?? [key],\n value: valueMap[key],\n };\n });\n\n const allAtoms = new Set<string>();\n for (const e of entries) {\n for (const a of e.atoms) allAtoms.add(a);\n }\n\n const redundant = new Set<string>();\n for (const atom of allAtoms) {\n if (isAtomRedundant(entries, atom)) {\n redundant.add(atom);\n }\n }\n\n if (redundant.size === 0) return valueMap;\n\n const newMap: Record<string, StyleValue> = {};\n for (const e of entries) {\n const filtered = e.atoms.filter((a) => !redundant.has(a));\n const newKey = filtered.join(' & ');\n if (!(newKey in newMap)) {\n newMap[newKey] = e.value;\n }\n }\n\n return newMap;\n}\n\n/**\n * Split a state key by top-level `&` operators.\n *\n * Returns `null` if the key contains `|`, `^`, or `,` at the top level\n * (making it ineligible for atom-level extraction).\n * Returns `[]` for the empty string (default key).\n */\nfunction splitTopLevelAnd(key: string): string[] | null {\n if (key === '') return [];\n\n const parts: string[] = [];\n let depth = 0;\n let current = '';\n\n for (const ch of key) {\n if (ch === '(' || ch === '[') depth++;\n else if (ch === ')' || ch === ']') depth--;\n\n if (depth === 0) {\n if (ch === '&') {\n const trimmed = current.trim();\n if (trimmed) parts.push(trimmed);\n current = '';\n continue;\n }\n if (ch === '|' || ch === '^' || ch === ',') {\n return null;\n }\n }\n\n current += ch;\n }\n\n const trimmed = current.trim();\n if (trimmed) parts.push(trimmed);\n\n return parts;\n}\n\n/**\n * An atom is redundant when every entry that contains it has a matching\n * partner (same remaining atoms, atom absent) with the same value.\n */\nfunction isAtomRedundant(\n entries: { atoms: string[]; value: StyleValue }[],\n atom: string,\n): boolean {\n const withAtom = entries.filter((e) => e.atoms.includes(atom));\n if (withAtom.length === 0) return false;\n\n for (const wa of withAtom) {\n const remaining = wa.atoms.filter((a) => a !== atom);\n\n const pair = entries.find(\n (e) =>\n !e.atoms.includes(atom) &&\n e.atoms.length === remaining.length &&\n remaining.every((r) => e.atoms.includes(r)),\n );\n\n if (!pair) return false;\n if (serializeValue(wa.value) !== serializeValue(pair.value)) return false;\n }\n\n return true;\n}\n\n/**\n * Check if a value is a style value mapping (object with state keys)\n */\nexport function isValueMapping(\n value: StyleValue | Record<string, StyleValue>,\n): value is Record<string, StyleValue> {\n return (\n value !== null &&\n typeof value === 'object' &&\n !Array.isArray(value) &&\n !(value instanceof Date)\n );\n}\n\n// ============================================================================\n// OR Expansion\n// ============================================================================\n\n/**\n * Expand OR conditions in parsed entries into multiple exclusive entries.\n *\n * For an entry with condition `A | B | C`, this creates 3 entries:\n * - condition: A\n * - condition: B & !A\n * - condition: C & !A & !B\n *\n * This ensures OR branches are mutually exclusive BEFORE the main\n * exclusive condition building pass.\n *\n * @param entries Parsed entries (may contain OR conditions)\n * @returns Expanded entries with OR branches made exclusive\n */\nexport function expandOrConditions(\n entries: ParsedStyleEntry[],\n): ParsedStyleEntry[] {\n const result: ParsedStyleEntry[] = [];\n\n for (const entry of entries) {\n const expanded = expandSingleEntry(entry);\n result.push(...expanded);\n }\n\n return result;\n}\n\n/**\n * Expand a single entry's OR condition into multiple exclusive entries\n */\nfunction expandSingleEntry(entry: ParsedStyleEntry): ParsedStyleEntry[] {\n const orBranches = collectOrBranches(entry.condition);\n\n // If no OR (single branch), return as-is\n if (orBranches.length <= 1) {\n return [entry];\n }\n\n // Make each OR branch exclusive from prior branches\n const result: ParsedStyleEntry[] = [];\n const priorBranches: ConditionNode[] = [];\n\n for (let i = 0; i < orBranches.length; i++) {\n const branch = orBranches[i];\n\n // Build: branch & !prior[0] & !prior[1] & ...\n let exclusiveBranch: ConditionNode = branch;\n for (const prior of priorBranches) {\n exclusiveBranch = and(exclusiveBranch, not(prior));\n }\n\n // Simplify to detect impossible combinations\n const simplified = simplifyCondition(exclusiveBranch);\n\n // Skip impossible branches\n if (simplified.kind === 'false') {\n priorBranches.push(branch);\n continue;\n }\n\n result.push({\n ...entry,\n stateKey: `${entry.stateKey}[${i}]`, // Mark as expanded branch\n condition: simplified,\n // Keep same priority - all branches from same entry have same priority\n });\n\n priorBranches.push(branch);\n }\n\n return result;\n}\n\n/**\n * Collect top-level OR branches from a condition.\n *\n * For `A | B | C`, returns [A, B, C]\n * For `A & B`, returns [A & B] (single branch)\n * For `A | (B & C)`, returns [A, B & C]\n */\nfunction collectOrBranches(condition: ConditionNode): ConditionNode[] {\n if (condition.kind === 'true' || condition.kind === 'false') {\n return [condition];\n }\n\n if (isCompoundCondition(condition) && condition.operator === 'OR') {\n // Flatten nested ORs\n const branches: ConditionNode[] = [];\n for (const child of condition.children) {\n branches.push(...collectOrBranches(child));\n }\n return branches;\n }\n\n // Not an OR - return as single branch\n return [condition];\n}\n\n// ============================================================================\n// Post-Build OR Expansion (for De Morgan ORs)\n// ============================================================================\n\n/**\n * Expand OR conditions in exclusive entries AFTER buildExclusiveConditions.\n *\n * This handles ORs that arise from De Morgan expansion during negation:\n * !(A & B) = !A | !B\n *\n * These ORs need to be made exclusive to avoid overlapping CSS rules:\n * !A | !B → !A | (A & !B)\n *\n * This is logically equivalent but ensures each branch has proper context.\n *\n * Example:\n * Input: { \"\": V1, \"@supports(...) & :has()\": V2 }\n * V2's exclusive = @supports & :has\n * V1's exclusive = !(@supports & :has) = !@supports | !:has\n *\n * Without this fix: V1 gets two rules:\n * - @supports (not ...) → V1 ✓\n * - :not(:has()) → V1 ✗ (missing @supports context!)\n *\n * With this fix: V1 gets two exclusive rules:\n * - @supports (not ...) → V1 ✓\n * - @supports (...) { :not(:has()) } → V1 ✓ (proper context!)\n */\nexport function expandExclusiveOrs(\n entries: ExclusiveStyleEntry[],\n): ExclusiveStyleEntry[] {\n const result: ExclusiveStyleEntry[] = [];\n\n for (const entry of entries) {\n const expanded = expandExclusiveConditionOrs(entry);\n result.push(...expanded);\n }\n\n return result;\n}\n\n/**\n * Check if a condition involves at-rules (media, container, supports, starting)\n */\nfunction hasAtRuleContext(node: ConditionNode): boolean {\n if (node.kind === 'true' || node.kind === 'false') {\n return false;\n }\n\n if (node.kind === 'state') {\n // These condition types generate at-rules\n return (\n node.type === 'media' ||\n node.type === 'container' ||\n node.type === 'supports' ||\n node.type === 'starting'\n );\n }\n\n if (node.kind === 'compound') {\n return node.children.some(hasAtRuleContext);\n }\n\n return false;\n}\n\n/**\n * Sort OR branches to prioritize at-rule conditions first.\n *\n * This is critical for correct CSS generation. For `!A | !B` where A is at-rule\n * and B is modifier, we want:\n * - Branch 0: !A (at-rule negation - covers \"no @supports/media\" case)\n * - Branch 1: A & !B (modifier negation with at-rule context)\n *\n * If we process in wrong order (!B first), we'd get:\n * - Branch 0: !B (modifier negation WITHOUT at-rule context - WRONG!)\n * - Branch 1: B & !A (at-rule negation with modifier - incomplete coverage)\n */\nfunction sortOrBranchesForExpansion(\n branches: ConditionNode[],\n): ConditionNode[] {\n return [...branches].sort((a, b) => {\n const aHasAtRule = hasAtRuleContext(a);\n const bHasAtRule = hasAtRuleContext(b);\n\n // At-rule conditions come first\n if (aHasAtRule && !bHasAtRule) return -1;\n if (!aHasAtRule && bHasAtRule) return 1;\n\n // Same type - keep original order (stable sort)\n return 0;\n });\n}\n\n/**\n * Expand ORs in a single entry's exclusive condition\n */\nfunction expandExclusiveConditionOrs(\n entry: ExclusiveStyleEntry,\n): ExclusiveStyleEntry[] {\n let orBranches = collectOrBranches(entry.exclusiveCondition);\n\n // If no OR (single branch), return as-is\n if (orBranches.length <= 1) {\n return [entry];\n }\n\n // Sort branches so at-rule conditions come first\n // This ensures proper context inheritance during expansion\n orBranches = sortOrBranchesForExpansion(orBranches);\n\n // Make each OR branch exclusive from prior branches\n const result: ExclusiveStyleEntry[] = [];\n const priorBranches: ConditionNode[] = [];\n\n for (let i = 0; i < orBranches.length; i++) {\n const branch = orBranches[i];\n\n // Build: branch & !prior[0] & !prior[1] & ...\n // This transforms: !A | !B → !A, !B & !!A = !A, (A & !B)\n let exclusiveBranch: ConditionNode = branch;\n for (const prior of priorBranches) {\n exclusiveBranch = and(exclusiveBranch, not(prior));\n }\n\n // Simplify to detect impossible combinations and clean up double negations\n const simplified = simplifyCondition(exclusiveBranch);\n\n // Skip impossible branches\n if (simplified.kind === 'false') {\n priorBranches.push(branch);\n continue;\n }\n\n result.push({\n ...entry,\n stateKey: `${entry.stateKey}[or:${i}]`, // Mark as expanded OR branch\n exclusiveCondition: simplified,\n });\n\n priorBranches.push(branch);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,yBACd,SACuB;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,aAAa,kBAAkB,gBAAgB;AAGrD,MAAI,WAAW,SAAS,SAAS;AAC/B,iBAAc,KAAK,OAAO;AAC1B;;AAGF,SAAO,KAAK;GACV,GAAG;GACH,UAAU,GAAG,MAAM,SAAS,MAAM,EAAE;GACpC,oBAAoB;GACrB,CAAC;AAEF,gBAAc,KAAK,OAAO;;AAG5B,QAAO"}
@@ -1,55 +0,0 @@
1
- import { Styles } from "../styles/types.js";
2
- import { ConditionNode } from "./conditions.js";
3
- import { parseStateKey } from "./parseStateKey.js";
4
-
5
- //#region src/pipeline/index.d.ts
6
- /**
7
- * Matches the old StyleResult interface for backward compatibility
8
- */
9
- interface StyleResult {
10
- selector: string;
11
- declarations: string;
12
- atRules?: string[];
13
- needsClassName?: boolean;
14
- rootPrefix?: string;
15
- /** When true, declarations are wrapped in @starting-style { ... } inside the selector rule */
16
- startingStyle?: boolean;
17
- }
18
- /**
19
- * Matches the old RenderResult interface for backward compatibility
20
- */
21
- interface RenderResult {
22
- rules: StyleResult[];
23
- className?: string;
24
- }
25
- /**
26
- * Check if a key is a CSS selector
27
- */
28
- declare function isSelector(key: string): boolean;
29
- /**
30
- * Options for renderStyles when using direct selector mode.
31
- */
32
- interface RenderStylesOptions {
33
- /**
34
- * Whether to double the class selector for increased specificity.
35
- * When true, `.myClass` becomes `.myClass.myClass` for higher specificity.
36
- *
37
- * @default false - User-provided selectors are not doubled.
38
- *
39
- * Note: This only applies when a classNameOrSelector is provided.
40
- * When renderStyles returns RenderResult with needsClassName=true,
41
- * the injector handles doubling automatically.
42
- */
43
- doubleSelector?: boolean;
44
- }
45
- /**
46
- * Render styles to CSS rules.
47
- *
48
- * When called without classNameOrSelector, returns RenderResult with needsClassName=true.
49
- * When called with a selector/className string, returns StyleResult[] for direct injection.
50
- */
51
- declare function renderStyles(styles?: Styles, classNameOrSelector?: undefined, options?: undefined, pipelineCacheKey?: string): RenderResult;
52
- declare function renderStyles(styles: Styles | undefined, classNameOrSelector: string, options?: RenderStylesOptions): StyleResult[];
53
- //#endregion
54
- export { RenderResult, StyleResult, isSelector, renderStyles };
55
- //# sourceMappingURL=index.d.ts.map