@tenphi/tasty 0.0.0-snapshot.d2dcdeb → 0.0.0-snapshot.d4ccea8

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 (357) hide show
  1. package/README.md +181 -131
  2. package/dist/{ssr/async-storage.js → async-storage-DKK-wTD4.js} +2 -2
  3. package/dist/async-storage-DKK-wTD4.js.map +1 -0
  4. package/dist/babel-eMs_zZjM.d.ts +83 -0
  5. package/dist/{ssr/collector.js → collector-BjkQEtbh.js} +111 -38
  6. package/dist/collector-BjkQEtbh.js.map +1 -0
  7. package/dist/{ssr/collector.d.ts → collector-DzeNxHOq.d.ts} +58 -7
  8. package/dist/config-DMslHK_e.d.ts +1298 -0
  9. package/dist/config-DX126v_w.js +12318 -0
  10. package/dist/config-DX126v_w.js.map +1 -0
  11. package/dist/{ssr/context.js → context-CA8YKeMn.js} +11 -3
  12. package/dist/context-CA8YKeMn.js.map +1 -0
  13. package/dist/core/index.d.ts +5 -34
  14. package/dist/core/index.js +6 -27
  15. package/dist/core-CMn-Tj2X.js +1573 -0
  16. package/dist/core-CMn-Tj2X.js.map +1 -0
  17. package/dist/{zero/extractor.js → css-writer-C8ShXK5R.js} +148 -24
  18. package/dist/css-writer-C8ShXK5R.js.map +1 -0
  19. package/dist/{ssr/format-global-rules.js → format-global-rules-DklyaXv-.js} +2 -2
  20. package/dist/format-global-rules-DklyaXv-.js.map +1 -0
  21. package/dist/{ssr/format-rules.js → format-rules-BkstDvlN.js} +59 -2
  22. package/dist/format-rules-BkstDvlN.js.map +1 -0
  23. package/dist/{ssr/hydrate.js → hydrate-DXXWZgm0.js} +4 -12
  24. package/dist/hydrate-DXXWZgm0.js.map +1 -0
  25. package/dist/index-BcsaHo8x.d.ts +1568 -0
  26. package/dist/index-CC0wykKn.d.ts +1909 -0
  27. package/dist/index.d.ts +5 -51
  28. package/dist/index.js +922 -36
  29. package/dist/index.js.map +1 -0
  30. package/dist/keyframes-Z0YLVOWq.js +493 -0
  31. package/dist/keyframes-Z0YLVOWq.js.map +1 -0
  32. package/dist/{utils/merge-styles.d.ts → merge-styles-BTFAkYSD.d.ts} +3 -3
  33. package/dist/{utils/merge-styles.js → merge-styles-Dpueyn82.js} +3 -4
  34. package/dist/merge-styles-Dpueyn82.js.map +1 -0
  35. package/dist/{utils/resolve-recipes.js → resolve-recipes-B2Vjr7ET.js} +4 -6
  36. package/dist/resolve-recipes-B2Vjr7ET.js.map +1 -0
  37. package/dist/ssr/astro-client.js +1 -1
  38. package/dist/ssr/astro-client.js.map +1 -1
  39. package/dist/ssr/astro-middleware-static.d.ts +16 -0
  40. package/dist/ssr/astro-middleware-static.js +18 -0
  41. package/dist/ssr/astro-middleware-static.js.map +1 -0
  42. package/dist/ssr/astro-middleware.d.ts +8 -6
  43. package/dist/ssr/astro-middleware.js +10 -10
  44. package/dist/ssr/astro-middleware.js.map +1 -1
  45. package/dist/ssr/astro.d.ts +2 -17
  46. package/dist/ssr/astro.js +29 -21
  47. package/dist/ssr/astro.js.map +1 -1
  48. package/dist/ssr/index.d.ts +37 -4
  49. package/dist/ssr/index.js +5 -5
  50. package/dist/ssr/index.js.map +1 -1
  51. package/dist/ssr/next.d.ts +2 -3
  52. package/dist/ssr/next.js +7 -8
  53. package/dist/ssr/next.js.map +1 -1
  54. package/dist/static/index.d.ts +91 -5
  55. package/dist/static/index.js +49 -3
  56. package/dist/static/index.js.map +1 -0
  57. package/dist/static/inject.js.map +1 -1
  58. package/dist/zero/babel.d.ts +2 -81
  59. package/dist/zero/babel.js +45 -29
  60. package/dist/zero/babel.js.map +1 -1
  61. package/dist/zero/index.d.ts +81 -3
  62. package/dist/zero/index.js +2 -3
  63. package/dist/zero/next.d.ts +1 -1
  64. package/dist/zero/next.js +1 -1
  65. package/dist/zero/next.js.map +1 -1
  66. package/docs/README.md +18 -10
  67. package/docs/adoption.md +56 -31
  68. package/docs/ai-agents.md +224 -0
  69. package/docs/comparison.md +69 -40
  70. package/docs/configuration.md +501 -72
  71. package/docs/debug.md +22 -18
  72. package/docs/design-system.md +43 -24
  73. package/docs/dsl.md +512 -179
  74. package/docs/getting-started.md +60 -39
  75. package/docs/injector.md +110 -32
  76. package/docs/methodology.md +68 -36
  77. package/docs/migration-v3.md +285 -0
  78. package/docs/pipeline.md +741 -0
  79. package/docs/plugins.md +353 -0
  80. package/docs/react-api.md +164 -40
  81. package/docs/runtime-benchmarks.md +216 -0
  82. package/docs/ssr.md +92 -81
  83. package/docs/styles.md +65 -16
  84. package/docs/tasty-static.md +149 -99
  85. package/package.json +49 -21
  86. package/tasty.config.ts +6 -0
  87. package/dist/_virtual/_rolldown/runtime.js +0 -7
  88. package/dist/chunks/cacheKey.d.ts +0 -1
  89. package/dist/chunks/cacheKey.js +0 -77
  90. package/dist/chunks/cacheKey.js.map +0 -1
  91. package/dist/chunks/definitions.d.ts +0 -37
  92. package/dist/chunks/definitions.js +0 -258
  93. package/dist/chunks/definitions.js.map +0 -1
  94. package/dist/chunks/index.d.ts +0 -1
  95. package/dist/chunks/renderChunk.d.ts +0 -1
  96. package/dist/chunks/renderChunk.js +0 -59
  97. package/dist/chunks/renderChunk.js.map +0 -1
  98. package/dist/compute-styles.d.ts +0 -31
  99. package/dist/compute-styles.js +0 -335
  100. package/dist/compute-styles.js.map +0 -1
  101. package/dist/config.d.ts +0 -407
  102. package/dist/config.js +0 -587
  103. package/dist/config.js.map +0 -1
  104. package/dist/counter-style/index.js +0 -51
  105. package/dist/counter-style/index.js.map +0 -1
  106. package/dist/debug.d.ts +0 -89
  107. package/dist/debug.js +0 -453
  108. package/dist/debug.js.map +0 -1
  109. package/dist/font-face/index.js +0 -63
  110. package/dist/font-face/index.js.map +0 -1
  111. package/dist/hooks/index.d.ts +0 -7
  112. package/dist/hooks/useCounterStyle.d.ts +0 -36
  113. package/dist/hooks/useCounterStyle.js +0 -65
  114. package/dist/hooks/useCounterStyle.js.map +0 -1
  115. package/dist/hooks/useFontFace.d.ts +0 -45
  116. package/dist/hooks/useFontFace.js +0 -66
  117. package/dist/hooks/useFontFace.js.map +0 -1
  118. package/dist/hooks/useGlobalStyles.d.ts +0 -46
  119. package/dist/hooks/useGlobalStyles.js +0 -88
  120. package/dist/hooks/useGlobalStyles.js.map +0 -1
  121. package/dist/hooks/useKeyframes.d.ts +0 -58
  122. package/dist/hooks/useKeyframes.js +0 -55
  123. package/dist/hooks/useKeyframes.js.map +0 -1
  124. package/dist/hooks/useProperty.d.ts +0 -81
  125. package/dist/hooks/useProperty.js +0 -96
  126. package/dist/hooks/useProperty.js.map +0 -1
  127. package/dist/hooks/useRawCSS.d.ts +0 -22
  128. package/dist/hooks/useRawCSS.js +0 -103
  129. package/dist/hooks/useRawCSS.js.map +0 -1
  130. package/dist/hooks/useStyles.d.ts +0 -40
  131. package/dist/hooks/useStyles.js +0 -31
  132. package/dist/hooks/useStyles.js.map +0 -1
  133. package/dist/injector/index.d.ts +0 -182
  134. package/dist/injector/index.js +0 -185
  135. package/dist/injector/index.js.map +0 -1
  136. package/dist/injector/injector.d.ts +0 -198
  137. package/dist/injector/injector.js +0 -651
  138. package/dist/injector/injector.js.map +0 -1
  139. package/dist/injector/sheet-manager.d.ts +0 -132
  140. package/dist/injector/sheet-manager.js +0 -699
  141. package/dist/injector/sheet-manager.js.map +0 -1
  142. package/dist/injector/types.d.ts +0 -235
  143. package/dist/keyframes/index.js +0 -206
  144. package/dist/keyframes/index.js.map +0 -1
  145. package/dist/parser/classify.js +0 -319
  146. package/dist/parser/classify.js.map +0 -1
  147. package/dist/parser/const.js +0 -60
  148. package/dist/parser/const.js.map +0 -1
  149. package/dist/parser/lru.js +0 -109
  150. package/dist/parser/lru.js.map +0 -1
  151. package/dist/parser/parser.d.ts +0 -25
  152. package/dist/parser/parser.js +0 -115
  153. package/dist/parser/parser.js.map +0 -1
  154. package/dist/parser/tokenizer.js +0 -69
  155. package/dist/parser/tokenizer.js.map +0 -1
  156. package/dist/parser/types.d.ts +0 -51
  157. package/dist/parser/types.js +0 -46
  158. package/dist/parser/types.js.map +0 -1
  159. package/dist/pipeline/conditions.d.ts +0 -134
  160. package/dist/pipeline/conditions.js +0 -406
  161. package/dist/pipeline/conditions.js.map +0 -1
  162. package/dist/pipeline/exclusive.js +0 -230
  163. package/dist/pipeline/exclusive.js.map +0 -1
  164. package/dist/pipeline/index.d.ts +0 -55
  165. package/dist/pipeline/index.js +0 -708
  166. package/dist/pipeline/index.js.map +0 -1
  167. package/dist/pipeline/materialize.js +0 -1103
  168. package/dist/pipeline/materialize.js.map +0 -1
  169. package/dist/pipeline/parseStateKey.d.ts +0 -15
  170. package/dist/pipeline/parseStateKey.js +0 -446
  171. package/dist/pipeline/parseStateKey.js.map +0 -1
  172. package/dist/pipeline/simplify.js +0 -515
  173. package/dist/pipeline/simplify.js.map +0 -1
  174. package/dist/pipeline/warnings.js +0 -18
  175. package/dist/pipeline/warnings.js.map +0 -1
  176. package/dist/plugins/index.d.ts +0 -2
  177. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  178. package/dist/plugins/okhsl-plugin.js +0 -97
  179. package/dist/plugins/okhsl-plugin.js.map +0 -1
  180. package/dist/plugins/types.d.ts +0 -87
  181. package/dist/properties/index.js +0 -222
  182. package/dist/properties/index.js.map +0 -1
  183. package/dist/properties/property-type-resolver.d.ts +0 -24
  184. package/dist/properties/property-type-resolver.js +0 -90
  185. package/dist/properties/property-type-resolver.js.map +0 -1
  186. package/dist/rsc-cache.js +0 -79
  187. package/dist/rsc-cache.js.map +0 -1
  188. package/dist/ssr/async-storage.d.ts +0 -17
  189. package/dist/ssr/async-storage.js.map +0 -1
  190. package/dist/ssr/collect-auto-properties.js +0 -58
  191. package/dist/ssr/collect-auto-properties.js.map +0 -1
  192. package/dist/ssr/collector.js.map +0 -1
  193. package/dist/ssr/context.js.map +0 -1
  194. package/dist/ssr/format-global-rules.js.map +0 -1
  195. package/dist/ssr/format-keyframes.js +0 -69
  196. package/dist/ssr/format-keyframes.js.map +0 -1
  197. package/dist/ssr/format-property.js +0 -49
  198. package/dist/ssr/format-property.js.map +0 -1
  199. package/dist/ssr/format-rules.js.map +0 -1
  200. package/dist/ssr/hydrate.d.ts +0 -29
  201. package/dist/ssr/hydrate.js.map +0 -1
  202. package/dist/ssr/ssr-collector-ref.js +0 -29
  203. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  204. package/dist/states/index.d.ts +0 -49
  205. package/dist/states/index.js +0 -170
  206. package/dist/states/index.js.map +0 -1
  207. package/dist/static/tastyStatic.d.ts +0 -46
  208. package/dist/static/tastyStatic.js +0 -30
  209. package/dist/static/tastyStatic.js.map +0 -1
  210. package/dist/static/types.d.ts +0 -49
  211. package/dist/static/types.js +0 -24
  212. package/dist/static/types.js.map +0 -1
  213. package/dist/styles/border.d.ts +0 -25
  214. package/dist/styles/border.js +0 -120
  215. package/dist/styles/border.js.map +0 -1
  216. package/dist/styles/color.d.ts +0 -14
  217. package/dist/styles/color.js +0 -26
  218. package/dist/styles/color.js.map +0 -1
  219. package/dist/styles/const.js +0 -17
  220. package/dist/styles/const.js.map +0 -1
  221. package/dist/styles/createStyle.js +0 -79
  222. package/dist/styles/createStyle.js.map +0 -1
  223. package/dist/styles/dimension.js +0 -109
  224. package/dist/styles/dimension.js.map +0 -1
  225. package/dist/styles/directional.js +0 -133
  226. package/dist/styles/directional.js.map +0 -1
  227. package/dist/styles/display.d.ts +0 -30
  228. package/dist/styles/display.js +0 -73
  229. package/dist/styles/display.js.map +0 -1
  230. package/dist/styles/fade.d.ts +0 -15
  231. package/dist/styles/fade.js +0 -62
  232. package/dist/styles/fade.js.map +0 -1
  233. package/dist/styles/fill.d.ts +0 -42
  234. package/dist/styles/fill.js +0 -51
  235. package/dist/styles/fill.js.map +0 -1
  236. package/dist/styles/flow.d.ts +0 -16
  237. package/dist/styles/flow.js +0 -12
  238. package/dist/styles/flow.js.map +0 -1
  239. package/dist/styles/gap.d.ts +0 -31
  240. package/dist/styles/gap.js +0 -38
  241. package/dist/styles/gap.js.map +0 -1
  242. package/dist/styles/height.d.ts +0 -17
  243. package/dist/styles/height.js +0 -19
  244. package/dist/styles/height.js.map +0 -1
  245. package/dist/styles/index.d.ts +0 -1
  246. package/dist/styles/index.js +0 -8
  247. package/dist/styles/index.js.map +0 -1
  248. package/dist/styles/inset.d.ts +0 -24
  249. package/dist/styles/inset.js +0 -34
  250. package/dist/styles/inset.js.map +0 -1
  251. package/dist/styles/list.d.ts +0 -16
  252. package/dist/styles/list.js +0 -100
  253. package/dist/styles/list.js.map +0 -1
  254. package/dist/styles/margin.d.ts +0 -24
  255. package/dist/styles/margin.js +0 -32
  256. package/dist/styles/margin.js.map +0 -1
  257. package/dist/styles/outline.d.ts +0 -29
  258. package/dist/styles/outline.js +0 -55
  259. package/dist/styles/outline.js.map +0 -1
  260. package/dist/styles/padding.d.ts +0 -24
  261. package/dist/styles/padding.js +0 -32
  262. package/dist/styles/padding.js.map +0 -1
  263. package/dist/styles/placement.d.ts +0 -37
  264. package/dist/styles/placement.js +0 -74
  265. package/dist/styles/placement.js.map +0 -1
  266. package/dist/styles/predefined.d.ts +0 -71
  267. package/dist/styles/predefined.js +0 -237
  268. package/dist/styles/predefined.js.map +0 -1
  269. package/dist/styles/preset.d.ts +0 -52
  270. package/dist/styles/preset.js +0 -127
  271. package/dist/styles/preset.js.map +0 -1
  272. package/dist/styles/radius.d.ts +0 -12
  273. package/dist/styles/radius.js +0 -83
  274. package/dist/styles/radius.js.map +0 -1
  275. package/dist/styles/scrollMargin.d.ts +0 -24
  276. package/dist/styles/scrollMargin.js +0 -32
  277. package/dist/styles/scrollMargin.js.map +0 -1
  278. package/dist/styles/scrollbar.d.ts +0 -25
  279. package/dist/styles/scrollbar.js +0 -51
  280. package/dist/styles/scrollbar.js.map +0 -1
  281. package/dist/styles/shadow.d.ts +0 -14
  282. package/dist/styles/shadow.js +0 -25
  283. package/dist/styles/shadow.js.map +0 -1
  284. package/dist/styles/shared.js +0 -17
  285. package/dist/styles/shared.js.map +0 -1
  286. package/dist/styles/transition.d.ts +0 -14
  287. package/dist/styles/transition.js +0 -159
  288. package/dist/styles/transition.js.map +0 -1
  289. package/dist/styles/types.d.ts +0 -564
  290. package/dist/styles/width.d.ts +0 -17
  291. package/dist/styles/width.js +0 -19
  292. package/dist/styles/width.js.map +0 -1
  293. package/dist/tasty.d.ts +0 -134
  294. package/dist/tasty.js +0 -248
  295. package/dist/tasty.js.map +0 -1
  296. package/dist/types.d.ts +0 -184
  297. package/dist/utils/cache-wrapper.js +0 -21
  298. package/dist/utils/cache-wrapper.js.map +0 -1
  299. package/dist/utils/case-converter.js +0 -8
  300. package/dist/utils/case-converter.js.map +0 -1
  301. package/dist/utils/color-math.d.ts +0 -46
  302. package/dist/utils/color-math.js +0 -749
  303. package/dist/utils/color-math.js.map +0 -1
  304. package/dist/utils/color-space.d.ts +0 -5
  305. package/dist/utils/color-space.js +0 -228
  306. package/dist/utils/color-space.js.map +0 -1
  307. package/dist/utils/colors.d.ts +0 -5
  308. package/dist/utils/colors.js +0 -10
  309. package/dist/utils/colors.js.map +0 -1
  310. package/dist/utils/css-types.d.ts +0 -7
  311. package/dist/utils/deps-equal.js +0 -15
  312. package/dist/utils/deps-equal.js.map +0 -1
  313. package/dist/utils/dotize.d.ts +0 -26
  314. package/dist/utils/dotize.js +0 -122
  315. package/dist/utils/dotize.js.map +0 -1
  316. package/dist/utils/filter-base-props.d.ts +0 -15
  317. package/dist/utils/filter-base-props.js +0 -45
  318. package/dist/utils/filter-base-props.js.map +0 -1
  319. package/dist/utils/get-display-name.d.ts +0 -7
  320. package/dist/utils/get-display-name.js +0 -10
  321. package/dist/utils/get-display-name.js.map +0 -1
  322. package/dist/utils/has-keys.js +0 -13
  323. package/dist/utils/has-keys.js.map +0 -1
  324. package/dist/utils/hash.js +0 -14
  325. package/dist/utils/hash.js.map +0 -1
  326. package/dist/utils/is-dev-env.js +0 -19
  327. package/dist/utils/is-dev-env.js.map +0 -1
  328. package/dist/utils/is-valid-element-type.js +0 -15
  329. package/dist/utils/is-valid-element-type.js.map +0 -1
  330. package/dist/utils/merge-styles.js.map +0 -1
  331. package/dist/utils/mod-attrs.d.ts +0 -6
  332. package/dist/utils/mod-attrs.js +0 -20
  333. package/dist/utils/mod-attrs.js.map +0 -1
  334. package/dist/utils/process-tokens.d.ts +0 -17
  335. package/dist/utils/process-tokens.js +0 -83
  336. package/dist/utils/process-tokens.js.map +0 -1
  337. package/dist/utils/resolve-recipes.d.ts +0 -17
  338. package/dist/utils/resolve-recipes.js.map +0 -1
  339. package/dist/utils/selector-transform.js +0 -32
  340. package/dist/utils/selector-transform.js.map +0 -1
  341. package/dist/utils/string.js +0 -8
  342. package/dist/utils/string.js.map +0 -1
  343. package/dist/utils/styles.d.ts +0 -99
  344. package/dist/utils/styles.js +0 -220
  345. package/dist/utils/styles.js.map +0 -1
  346. package/dist/utils/typography.d.ts +0 -58
  347. package/dist/utils/typography.js +0 -51
  348. package/dist/utils/typography.js.map +0 -1
  349. package/dist/utils/warnings.d.ts +0 -16
  350. package/dist/utils/warnings.js +0 -16
  351. package/dist/utils/warnings.js.map +0 -1
  352. package/dist/zero/css-writer.d.ts +0 -45
  353. package/dist/zero/css-writer.js +0 -73
  354. package/dist/zero/css-writer.js.map +0 -1
  355. package/dist/zero/extractor.d.ts +0 -24
  356. package/dist/zero/extractor.js.map +0 -1
  357. package/docs/PIPELINE.md +0 -519
@@ -0,0 +1,741 @@
1
+ # Tasty Style Rendering Pipeline
2
+
3
+ This document describes the style rendering pipeline that transforms style objects into CSS rules. The pipeline ensures that each style value is applied to exactly one condition through exclusive condition building, boolean simplification, and intelligent CSS generation.
4
+
5
+ **Implementation:** [`src/pipeline/`](../src/pipeline/) — TypeScript file names below are relative to that directory.
6
+
7
+ ## Overview
8
+
9
+ The pipeline takes a `Styles` object and produces an array of `CSSRule` objects ready for injection into the DOM. The entry point is `renderStyles`, which has two overloads: called with a selector or class (`renderStyles(styles, '.t1')`) it returns the rules directly; called without one (`renderStyles(styles)`) it returns `{ rules }` for a caller that will allocate the class name itself. The per-handler flow is:
10
+
11
+ ```
12
+ Input: Styles Object
13
+ ↓
14
+ ┌──────────────────────────────────────────┐
15
+ │ 0. PRE-PARSE NORMALIZATION │
16
+ │ extractCompoundStates │
17
+ │ (drop don't-care AND atoms) │
18
+ └──────────────────────────────────────────┘
19
+ ↓
20
+ ┌──────────────────────────────────────────┐
21
+ │ 1. PARSE CONDITIONS │
22
+ │ parseStyleEntries + parseStateKey │
23
+ └──────────────────────────────────────────┘
24
+ ↓
25
+ ┌──────────────────────────────────────────┐
26
+ │ 1b. MERGE ENTRIES BY VALUE │
27
+ │ mergeEntriesByValue │
28
+ │ (collapse same-value non-defaults) │
29
+ └──────────────────────────────────────────┘
30
+ ↓
31
+ ┌──────────────────────────────────────────┐
32
+ │ 2a. EXPAND USER OR BRANCHES │
33
+ │ expandOrConditions │
34
+ │ (A | B | C → A, B&!A, C&!A&!B) │
35
+ └──────────────────────────────────────────┘
36
+ ↓
37
+ ┌──────────────────────────────────────────┐
38
+ │ 2b. BUILD EXCLUSIVE CONDITIONS │
39
+ │ Negate higher-priority entries │
40
+ └──────────────────────────────────────────┘
41
+ ↓
42
+ ┌──────────────────────────────────────────┐
43
+ │ 3. EXPAND DE MORGAN OR BRANCHES │
44
+ │ expandExclusiveOrs │
45
+ │ (only for at-rule ORs from negation) │
46
+ └──────────────────────────────────────────┘
47
+ ↓
48
+ ┌──────────────────────────────────────────┐
49
+ │ 4. COMPUTE STATE COMBINATIONS │
50
+ │ Cartesian product across styles │
51
+ └──────────────────────────────────────────┘
52
+ ↓
53
+ ┌──────────────────────────────────────────┐
54
+ │ 5. CALL HANDLERS │
55
+ │ Compute CSS declarations │
56
+ └──────────────────────────────────────────┘
57
+ ↓
58
+ ┌──────────────────────────────────────────┐
59
+ │ 6. MERGE BY VALUE │
60
+ │ Combine rules with same output │
61
+ └──────────────────────────────────────────┘
62
+ ↓
63
+ ┌──────────────────────────────────────────┐
64
+ │ 7. MATERIALIZE CSS │
65
+ │ Condition → selectors + at-rules │
66
+ └──────────────────────────────────────────┘
67
+ ↓
68
+ ┌──────────────────────────────────────────┐
69
+ │ runPipeline post-pass: │
70
+ │ - dedupe identical rules │
71
+ │ - emit @starting-style rules last │
72
+ └──────────────────────────────────────────┘
73
+ ↓
74
+ Output: CSSRule[]
75
+ ```
76
+
77
+ **Simplification** (`simplifyCondition` in `simplify.ts`) is not a separate numbered stage. It runs inside OR expansion, exclusive building, `expandExclusiveOrs` branch cleanup, combination ANDs, merge-by-value ORs, and materialization. Every call is cached by condition unique-id, so the repetition is cheap.
78
+
79
+ **Post-pass:** After `processStyles` collects rules from every handler, `runPipeline` (`index.ts`) filters duplicates using a key of `selector|declarations|atRules|rootPrefix|startingStyle`, then **stable-sorts rules by their cascade `order` hint (ascending source priority)** so lower-priority rules come first and higher-priority rules win, and finally emits every `@starting-style` rule **after** all normal rules. The `order` hint is the highest source priority among the entries that produced each rule (threaded `ComputedRule → CSSRule`). This ordering is cascade-critical because Stage 7 equalizes specificity with `:where()`: once every state selector carries zero specificity, source order alone decides which of two overlapping rules wins — most importantly the `_` fallback floor (low order, emitted first) versus the states layered over it, and `@starting-style` versus its normal counterpart. Mutually-exclusive rules are unaffected by ordering (they never both match), so reordering them is safe.
80
+
81
+ ---
82
+
83
+ ## Stage 0: Pre-parse Normalization
84
+
85
+ **File:** `exclusive.ts` (`extractCompoundStates`)
86
+
87
+ ### What It Does
88
+
89
+ Runs on each style's value map **before** any parsing. If a compound AND state key shares a value with the "atom absent" variant, the atom is a don't-care and every key is simplified by dropping it. Duplicate keys collapse.
90
+
91
+ ### How It Works
92
+
93
+ 1. Gather the unique set of top-level AND atoms across all keys.
94
+ 2. An atom is **redundant** when every entry that contains it has a same-value partner with the atom absent and the rest of the atoms identical.
95
+ 3. Keys containing `|`, `^`, or `,` at top level are treated as opaque single atoms (they don't participate in atom-level extraction).
96
+ 4. Drop redundant atoms from every key; collapse duplicates.
97
+
98
+ ### Why
99
+
100
+ Removing don't-care dimensions before parsing prevents combinatorial blowup in later stages. `mergeEntriesByValue`, `buildExclusiveConditions`, and materialization all see fewer entries and fewer spurious conditions. Implemented as part of the Apr 2026 fix for overlapping CSS rules (commit 7cd9dbe).
101
+
102
+ ### Example
103
+
104
+ ```typescript
105
+ // Input (value map)
106
+ { '': 'A', '@dark': 'B', '@hc': 'A', '@dark & @hc': 'B' }
107
+ // @hc is a don't-care: its presence never changes the value.
108
+
109
+ // Output
110
+ { '': 'A', '@dark': 'B' }
111
+ ```
112
+
113
+ ---
114
+
115
+ ## Stage 1: Parse Conditions
116
+
117
+ **Files:** `exclusive.ts` (`parseStyleEntries`), `parseStateKey.ts` (`parseStateKey`)
118
+
119
+ ### What It Does
120
+
121
+ Converts each state key in a style value map (like `'hovered & !disabled'`, `'@media(w < 768px)'`) into `ConditionNode` trees. `parseStyleEntries` walks the object keys in source order and assigns priorities; `parseStateKey` parses a single key string.
122
+
123
+ `parseStyleEntries` also handles the bare `''` default and the standalone `_` fallback floor before the priority order is finalized. The bare `''` default only behaves correctly as the lowest-priority state, so a misplaced one is moved to the front (`MISPLACED_DEFAULT_STATE` warning). The `_` key is pulled out as a separate floor entry (`floor: true`, `TrueCondition`) and always assigned the lowest priority. If a map defines only `_` and a bare `''` (no other states), the `''` default is redundant — it is dropped in favor of the `_` value (`REDUNDANT_DEFAULT_STATE` warning). A `_` combined with state logic (`_ & hovered`, `_ | x`) is ignored (`INVALID_FALLBACK_KEY` warning).
124
+
125
+ ### How It Works
126
+
127
+ 1. **Tokenization**: The state key is split into tokens using a regex pattern that recognizes:
128
+ - Operators: `&` (AND), `|` (OR), `!` (NOT), `^` (XOR)
129
+ - Parentheses for grouping
130
+ - State tokens: `@media(...)`, `@root(...)`, `@parent(...)`, `@own(...)`, `@supports(...)`, `@(...)`, `@starting`, predefined states, modifiers, pseudo-classes
131
+
132
+ 2. **Recursive Descent Parsing**: Tokens are parsed with operator precedence:
133
+ ```
134
+ ! (NOT) > ^ (XOR) > | (OR) > & (AND)
135
+ ```
136
+
137
+ 3. **State Token Interpretation**: Each state token is converted to a specific condition type:
138
+ - `hovered` → `ModifierCondition` with `attribute: 'data-hovered'`
139
+ - `theme=dark` → `ModifierCondition` with `attribute: 'data-theme', value: 'dark'`
140
+ - `:hover` → `PseudoCondition`
141
+ - `@media(w < 768px)` → `MediaCondition` (`subtype: 'dimension'`) with bounds
142
+ - `@media(prefers-color-scheme: dark)` → `MediaCondition` (`subtype: 'feature'`, `feature` + `featureValue`)
143
+ - `@root(schema=dark)` → `RootCondition` wrapping the inner condition
144
+ - `@parent(hovered)` → `ParentCondition` (optional `direct` for immediate parent)
145
+ - `@own(hovered)` → `OwnCondition` wrapping the parsed inner condition
146
+ - `@supports(display: grid)` → `SupportsCondition`
147
+ - `@(w < 600px)` → `ContainerCondition` (dimension, style, or raw subtypes)
148
+ - `@mobile` → Resolved via predefined states, then parsed recursively
149
+
150
+ Pipeline warnings for invalid inputs (e.g. bad `$` selector affix) are emitted from `warnings.ts`.
151
+
152
+ ### Why
153
+
154
+ The condition tree representation enables:
155
+ - Boolean algebra operations (simplification, negation)
156
+ - Semantic analysis (detect contradictions)
157
+ - Flexible CSS generation (different output for media vs. selectors)
158
+
159
+ ### Example
160
+
161
+ ```typescript
162
+ // Input
163
+ 'hovered & @media(w < 768px)'
164
+
165
+ // Output ConditionNode
166
+ {
167
+ kind: 'compound',
168
+ operator: 'AND',
169
+ children: [
170
+ { kind: 'state', type: 'modifier', attribute: 'data-hovered', ... },
171
+ { kind: 'state', type: 'media', subtype: 'dimension', upperBound: { value: '768px', ... }, ... }
172
+ ]
173
+ }
174
+ ```
175
+
176
+ ---
177
+
178
+ ## Stage 1b: Merge Entries By Value
179
+
180
+ **File:** `exclusive.ts` (`mergeEntriesByValue`)
181
+
182
+ ### What It Does
183
+
184
+ Collapses parsed entries that share the same value when doing so provably preserves the authored cascade. Only **non-default** entries are merged — an entry with the default state (`''` → `TrueCondition`) is never merged with a non-default entry.
185
+
186
+ ### How It Works
187
+
188
+ Entries arrive sorted highest-priority-first. For each entry the pass walks already-emitted entries from most-recent backward, looking for the nearest same-value entry where merging is safe. If found, the two entries collapse into one (priority becomes the maximum of the pair, condition becomes the simplified `OR`). Default entries are emitted as singletons and never participate in a merge.
189
+
190
+ ### The Safety Condition
191
+
192
+ Merging two same-value entries with conditions `C_h` (higher priority) and `C_l` (lower priority) lifts the lower one up to `p_h` and changes the higher-priority "blocker" for every intermediate-priority entry from `!C_h` to `!(C_h | C_l) = !C_h & !C_l`. The added `!C_l` constraint can incorrectly block an intermediate entry that should have won.
193
+
194
+ The merge is safe iff for every entry `e_m` strictly between them in priority with a different value,
195
+
196
+ simplify(C_m & C_l & !C_h) = FALSE
197
+
198
+ i.e. there is no scenario where the intermediate state could have matched, the lower same-value entry would also have matched, and the higher one would not. This is the only way the merge could leak through and shadow the intermediate state.
199
+
200
+ ### Why
201
+
202
+ Without this pass a value map like `{ '@dark': 'red', '@dark & @hc': 'red' }` would create two separate entries that later produce two CSS rules with identical output. Merging before exclusive building keeps the exclusive condition algebra small and avoids duplicate CSS. The safety check ensures we never break the cascade in service of this optimization.
203
+
204
+ **Why defaults are kept separate:** merging `TRUE | X` collapses to `TRUE`, destroying X's participation in the exclusive cascade. Intermediate-priority states would then lose their `:not(X)` negation, producing overlapping CSS rules.
205
+
206
+ ### Example — Safe merge (still collapses)
207
+
208
+ ```typescript
209
+ // { '@dark & @hc': 'red', '@dark': 'red' }
210
+ // Input entries (highest priority first), no intermediate different-value entry
211
+ [
212
+ { stateKey: '@dark & @hc', value: 'red', condition: dark & hc, priority: 1 },
213
+ { stateKey: '@dark', value: 'red', condition: dark, priority: 0 },
214
+ ]
215
+
216
+ // Safe: no intermediates. Output: one merged entry
217
+ [
218
+ { stateKey: '@dark & @hc | @dark', value: 'red',
219
+ condition: simplify((dark & hc) | dark) = dark, priority: 1 }
220
+ ]
221
+ ```
222
+
223
+ The compound dark/HC dedup pattern `{ '': light, '@dark': dark, '@hc': hc, '@dark & @hc': dark }` also collapses cleanly because `@hc & @dark & !(@dark & @hc)` simplifies to FALSE — the intermediate `@hc` is structurally blocked by the contradiction.
224
+
225
+ ### Example — Unsafe merge (must NOT collapse)
226
+
227
+ ```typescript
228
+ // { hovered: 'red', pressed: 'blue', disabled: 'red' }
229
+ // Authored cascade: disabled > pressed > hovered.
230
+ // Merging hovered (priority 0) with disabled (priority 2) would lift
231
+ // hovered to priority 2 and rewrite `pressed`'s exclusive from
232
+ // `pressed & !disabled` to `pressed & !disabled & !hovered`, making
233
+ // `pressed + hovered` resolve to red instead of blue.
234
+
235
+ // `simplify(pressed & hovered & !disabled)` is not FALSE — three
236
+ // independent modifiers can all be active — so the entries are kept
237
+ // separate. Stage 6 `mergeByValue` will later combine the two red
238
+ // CSS rules into one selector group, but only after the cascade is
239
+ // correctly resolved.
240
+ ```
241
+
242
+ ---
243
+
244
+ ## Stage 2a: Expand User OR Branches
245
+
246
+ **File:** `exclusive.ts` (`expandOrConditions`)
247
+
248
+ ### What It Does
249
+
250
+ Runs **before** `buildExclusiveConditions`. Splits any user-authored OR in a parsed entry's condition into multiple sibling entries, each made exclusive against the OR branches that come before it.
251
+
252
+ ### How It Works
253
+
254
+ For an entry with condition `A | B | C`:
255
+
256
+ ```
257
+ A (first branch, no prior)
258
+ B & !A (second branch exclusive from first)
259
+ C & !A & !B (third branch exclusive from first two)
260
+ ```
261
+
262
+ Each expanded branch gets a `stateKey` suffix like `[0]`, `[1]`, `[2]`. Branches that simplify to `FALSE` are dropped. Branches inherit the original entry's priority.
263
+
264
+ This pass does **not** sort branches — user ORs are authored in the natural order they appear and aren't the product of De Morgan negation, so at-rule-aware sorting isn't required here (that's Stage 3's job).
265
+
266
+ ### Why
267
+
268
+ Running this before exclusive building means the Stage 2b negation cascade sees one branch per entry and never has to reason about nested ORs while computing `!prior`. It also avoids emitting overlapping CSS rules: `{ 'compact | @media(dark)': 'red' }` becomes two mutually exclusive entries rather than one rule whose two branches could both match simultaneously.
269
+
270
+ ---
271
+
272
+ ## Stage 2b: Build Exclusive Conditions
273
+
274
+ **File:** `exclusive.ts` (`buildExclusiveConditions`)
275
+
276
+ ### What It Does
277
+
278
+ Ensures each style entry applies in exactly one scenario by ANDing each condition with the negation of all higher-priority conditions.
279
+
280
+ ### How It Works
281
+
282
+ Given entries ordered by priority (highest first):
283
+ ```
284
+ A: value1 (priority 2)
285
+ B: value2 (priority 1)
286
+ C: value3 (priority 0)
287
+ ```
288
+
289
+ Produces:
290
+ ```
291
+ A: A (highest priority, no negation needed)
292
+ B: B & !A (applies only when A doesn't)
293
+ C: C & !A & !B (applies only when neither A nor B)
294
+ ```
295
+
296
+ Each exclusive condition is passed through `simplifyCondition`. Entries that simplify to `FALSE` (impossible) are filtered out. The default state (`''` → `TrueCondition`) is not added to the “prior” list for negation (see `buildExclusiveConditions`).
297
+
298
+ ### `_` fallback floor
299
+
300
+ An entry flagged `floor: true` (from the standalone `_` key) is the one
301
+ exception to the negation cascade above. `buildExclusiveConditions` **pulls the
302
+ floor entries out** before the negation pass, builds the remaining entries with a
303
+ plain unconditional negation loop, then re-appends each floor with its own
304
+ (`TRUE`) condition as the exclusive condition. So the floor **always applies**,
305
+ never receives `!prior`, and never negates lower-priority entries. Because its
306
+ condition is `TRUE`, Stage 1 `mergeEntriesByValue` already leaves it untouched
307
+ (same guard as the bare `''` default), so no floor-specific merge handling is
308
+ needed.
309
+
310
+ This exists to fix the *unknown-query hole*: CSS three-valued logic makes
311
+ `not(unknown) = unknown`, so a negated `@supports(...)` / container-query default
312
+ branch silently never applies. A `_` floor sidesteps negation entirely and lets
313
+ the positive override layer on top via the cascade (see Stage 7's `:where()`
314
+ equalization and the ascending-priority post-pass).
315
+
316
+ Because the floor is **additive** (always emitted, never negated) rather than
317
+ mutually exclusive, it differs observably from the `''` default in two ways
318
+ beyond the unknown-query fix: an "empty" higher-priority state (one that emits no
319
+ declarations) cannot unset the property — the floor still applies — and when
320
+ states emit different declaration sets, the floor's declarations bleed through
321
+ wherever a winning state does not override the same property. The `''` default,
322
+ being negated, swaps out cleanly. See the DSL guide's "`_` vs the `''` default".
323
+
324
+ ### Why
325
+
326
+ This eliminates CSS specificity wars. Instead of relying on cascade order, each CSS rule matches in exactly one scenario. Benefits:
327
+ - Predictable styling regardless of rule order
328
+ - No conflicts from overlapping conditions
329
+ - Easier debugging (each rule is mutually exclusive)
330
+
331
+ ### Example
332
+
333
+ ```typescript
334
+ // Style value mapping
335
+ { padding: { '': '2x', 'compact': '1x', '@media(w < 768px)': '0.5x' } }
336
+
337
+ // After exclusive building (highest priority first):
338
+ // @media(w < 768px): applies when media matches
339
+ // compact & !@media(w < 768px): applies when compact but NOT media
340
+ // !compact & !@media(w < 768px): default, applies when neither
341
+ ```
342
+
343
+ ---
344
+
345
+ ## Stage 3: Expand De Morgan OR Branches
346
+
347
+ **File:** `exclusive.ts` (`expandExclusiveOrs`, `sortOrBranchesForExpansion`)
348
+
349
+ ### What It Does
350
+
351
+ Runs **after** `buildExclusiveConditions`. Handles ORs that arise **during** exclusive building from De Morgan negation — e.g. when a higher-priority condition `A & B` gets negated into the next entry's exclusive as `!(A & B) = !A | !B`. When such an OR mixes **at-rule** context (`media`, `container`, `supports`, `starting`) with other branches, each branch needs to keep its own at-rule wrapping.
352
+
353
+ This is the companion to **Stage 2a** (user-OR expansion). The split exists because the two passes have different data and different correctness needs:
354
+
355
+ | Stage | Runs on | Sees ORs from | Sorts branches? |
356
+ |---|---|---|---|
357
+ | 2a `expandOrConditions` | `ParsedStyleEntry.condition` | User-authored `|` in state keys | No — user order is stable |
358
+ | 3 `expandExclusiveOrs` | `ExclusiveStyleEntry.exclusiveCondition` | De Morgan negation inside `buildExclusiveConditions` | Yes — at-rule branches first |
359
+
360
+ ### How It Works
361
+
362
+ 1. Collect top-level OR branches of `exclusiveCondition`.
363
+ 2. If there is no OR (single branch), the entry is unchanged. Pure selector ORs with no at-rule context are also left alone (materialization handles them via `:is()` / variant merging).
364
+ 3. Otherwise `sortOrBranchesForExpansion` reorders branches by a three-tier rank — `@supports` branches first, then other at-rule branches (media / container / starting), then pure-selector branches. This is load-bearing for correctness (see below).
365
+ 4. Each branch is made exclusive against prior branches: `branch & !prior[0] & !prior[1] & ...`, then simplified.
366
+ 5. Impossible branches are dropped; expanded entries get a synthetic `stateKey` suffix like `[or:0]`.
367
+
368
+ ### Why the sort matters
369
+
370
+ **At-rules before selectors.** Consider `!A | !B` where A is an at-rule (e.g. `@supports(grid)`) and B is a modifier (e.g. `:has(foo)`):
371
+
372
+ - **With at-rule-first sort** (`!A`, then `!B & A`): the first branch emits "outside `@supports`", the second emits "inside `@supports` with `:not(:has(foo))`". Full coverage.
373
+ - **Without the sort** (`!B`, then `!A & B`): the first branch emits `:not(:has(foo))` as a bare selector with no at-rule context — leaking the rule outside `@supports`. The second is incomplete.
374
+
375
+ **`@supports` before other at-rules (Kleene logic).** A `@supports` feature query is special: anything ANDed with it can become *unknown* — not simply false — when the feature is unsupported. The canonical case is a feature guard over a dependent query, e.g. `@supports(container-type: scroll-state) & @(scroll-state(scrolled: block-end))` (`S & C`). The default's exclusive is `!(S & C) = !S | !C`, which `simplify` sorts alphabetically into `[!C, !S]`.
376
+
377
+ - **Expanding `!C` first** emits a bare `@container (not scroll-state(...))` rule. In a browser without `scroll-state` support that query is unknown (not false), so it matches nothing and the default `inset` is never applied — a coverage hole.
378
+ - **Expanding `!S` first** yields `!S | (S & !C)`: a bare `@supports (not (container-type: scroll-state))` fallback carrying the default, plus the dependent negation nested inside the supported scope. Full coverage, and the unsupported path never references the guarded query.
379
+
380
+ Because `!S | (S & !R) ≡ !S | !R` in two-valued logic, this reordering is a no-op for cases without an `@supports` guard. The same supports-first ordering is also applied in `makeOrBranchesExclusive` (`materialize.ts`) for ORs that survive nested inside an AND (e.g. `compact & (!S | !C)`).
381
+
382
+ The pre-build Stage 2a pass doesn't need this because user-authored ORs aren't produced by negation and their branches are expected to apply in each branch's own scope.
383
+
384
+ ### Example (conceptual)
385
+
386
+ See the comment block in `exclusive.ts:500-523`: a default value whose higher-priority sibling is `@supports(...) & :has(...)` gets an exclusive of `!@supports | !:has`. Expansion yields one branch under `@supports (not ...)` and another under `@supports (...) { :not(:has()) }` instead of a bare `:not(:has())` rule.
387
+
388
+ ---
389
+
390
+ ## Stage 4: Compute State Combinations
391
+
392
+ **File:** `index.ts` (`computeStateCombinations`)
393
+
394
+ ### What It Does
395
+
396
+ Computes the Cartesian product of all style entries for a handler, creating snapshots of which value each style has for each possible state combination.
397
+
398
+ ### How It Works
399
+
400
+ 1. Collect exclusive entries for each style the handler uses
401
+ 2. Compute Cartesian product: every combination of entries
402
+ 3. For each combination:
403
+ - AND all `exclusiveCondition` values together
404
+ - `simplifyCondition` the result
405
+ - Skip if simplified to `FALSE`
406
+ - Record the values for each style
407
+
408
+ ### Why
409
+
410
+ Style handlers often depend on multiple style properties (e.g., `padding` might look at both `padding` and `gap`). By computing all valid combinations, we can call the handler once per unique state and get the correct CSS output.
411
+
412
+ ### Example
413
+
414
+ ```typescript
415
+ // Handler looks up: ['padding', 'size']
416
+ // padding has entries: [{ value: '2x', condition: A }, { value: '1x', condition: B }]
417
+ // size has entries: [{ value: 'large', condition: C }, { value: 'small', condition: D }]
418
+
419
+ // Combinations:
420
+ // { padding: '2x', size: 'large', condition: A & C }
421
+ // { padding: '2x', size: 'small', condition: A & D }
422
+ // { padding: '1x', size: 'large', condition: B & C }
423
+ // { padding: '1x', size: 'small', condition: B & D }
424
+ ```
425
+
426
+ ---
427
+
428
+ ## Stage 5: Call Handlers
429
+
430
+ **File:** `index.ts` (within `processStyles`)
431
+
432
+ ### What It Does
433
+
434
+ Invokes style handlers with computed value snapshots to produce CSS declarations.
435
+
436
+ ### How It Works
437
+
438
+ 1. For each state snapshot (condition + values):
439
+ - Call the handler with the values
440
+ - Handler returns CSS properties (e.g., `{ 'padding-top': '16px', 'padding-bottom': '16px' }`)
441
+ - Handler may also return `$` (selector suffix) for pseudo-elements
442
+ 2. Create computed rules with the condition, declarations, and selector suffix
443
+
444
+ ### Why
445
+
446
+ Style handlers encapsulate the logic for translating design tokens (like `'2x'`) to actual CSS values (like `'16px'`). They can also handle complex multi-property styles (e.g., `padding` → `padding-top`, `padding-right`, etc.).
447
+
448
+ ---
449
+
450
+ ## Stage 6: Merge By Value
451
+
452
+ **File:** `index.ts` (`mergeByValue`)
453
+
454
+ ### What It Does
455
+
456
+ Combines rules that have identical CSS output into a single rule with an OR condition.
457
+
458
+ ### How It Works
459
+
460
+ 1. Group rules by `selectorSuffix` plus a stable string for declarations (JSON via an internal `declStringCache` `WeakMap` on declaration objects)
461
+ 2. For rules in the same group:
462
+ - Merge their conditions with OR
463
+ - `simplifyCondition` the resulting condition
464
+ 3. Output one rule per group
465
+
466
+ ### Why
467
+
468
+ Different state combinations might produce the same CSS output. Rather than emitting duplicate CSS, we combine them into a single rule. This reduces CSS size and improves performance.
469
+
470
+ ### Example
471
+
472
+ ```typescript
473
+ // Before merging:
474
+ // condition: A → { color: 'red' }
475
+ // condition: B → { color: 'red' }
476
+
477
+ // After merging:
478
+ // condition: A | B → { color: 'red' }
479
+ ```
480
+
481
+ ---
482
+
483
+ ## Stage 7: Materialize CSS
484
+
485
+ **File:** `materialize.ts` (`conditionToCSS`, `materializeComputedRule` in `index.ts`)
486
+
487
+ ### What It Does
488
+
489
+ Converts condition trees into actual CSS selectors and at-rules.
490
+
491
+ ### How It Works
492
+
493
+ 1. **Condition to CSS components** (`conditionToCSS`): Walk the condition tree and build `SelectorVariant` data:
494
+ - `ModifierCondition` → attribute selectors (e.g. `[data-hovered]`); optional `operator` (`=`, `^=`, `$=`, `*=`)
495
+ - `PseudoCondition` → pseudo-class (e.g. `:hover`)
496
+ - `MediaCondition` → `@media` (dimension, feature, or type)
497
+ - `ContainerCondition` → `@container` (dimension, style query, or raw)
498
+ - `RootCondition` → `rootGroups` / root prefix fragments
499
+ - `ParentCondition` → `parentGroups` / ancestor selectors (`direct` → child combinator path)
500
+ - `OwnCondition` → `ownGroups` on the **styled** element (sub-element / `&` scope), optimized with `optimizeGroups`
501
+ - `SupportsCondition` → `@supports` at-rules
502
+ - `StartingCondition` → `@starting-style` wrapper
503
+
504
+ 2. **AND / OR on variants**: AND merges variant dimensions; OR yields multiple variants (later merged into `:is()` / `:not()` groups where appropriate).
505
+
506
+ 3. **Contradiction detection**: During variant merging, impossible combinations are dropped (e.g. conflicting media, root, or modifier negations).
507
+
508
+ 4. **`materializeComputedRule`**: Groups variants by sorted at-rules plus root-prefix key; within each group, `mergeVariantsIntoSelectorGroups` merges variants that differ only in flat modifier/pseudo parts; builds selector strings and emits one or more `CSSRule` objects. The rule's `order` hint (cascade priority) is propagated here for the post-pass sort.
509
+
510
+ 5. **`:where()` specificity equalization**: Every stateful part of the selector is wrapped in `:where(...)` so it contributes **zero specificity**:
511
+ - the flat root modifiers + pseudos and the root element's `:is()`/`:not()` groups are combined into one `:where(...)` (`buildSelectorFromVariant`);
512
+ - the sub-element (`@own`) groups are wrapped in a **separate** `:where(...)` so the sub-element's structural `[data-element="X"]` specificity is preserved while its states are zeroed;
513
+ - `@parent` ancestors (`parentGroupsToCSS`) become `:where(... *)` / `:where(:not(... *))`;
514
+ - the `@root` context prefix (`rootGroupsToCSS`) becomes `:where(:root...)` (zeroing the `:root` pseudo too).
515
+
516
+ The only specificity anchors that remain are the doubled component class (`.tXX.tXX`, added by the injector) and sub-element `[data-element]` attributes. Because Stage 2b already makes ordinary rules mutually exclusive, zeroing specificity never changes *which* rule matches — it only makes additive layering (`_` fallback floor, `@starting-style`) resolve deterministically by source order (see the post-pass). Canonical sorting/dedup/subsumption still run first; `:where()` is only the final wrapper, and both output paths (injector and direct-selector / SSR) consume the same wrapped fragments.
517
+
518
+ ### Why
519
+
520
+ CSS has different mechanisms for different condition types:
521
+ - Modifiers → attribute selectors
522
+ - Media queries → `@media` blocks
523
+ - Container queries → `@container` blocks
524
+ - Root state → `:root` / root groups
525
+ - Supports → `@supports` blocks
526
+
527
+ The materialization layer handles these differences while maintaining the logical semantics of the condition tree.
528
+
529
+ ### Output Structure
530
+
531
+ ```typescript
532
+ interface CSSRule {
533
+ selector: string | string[]; // Selector fragment(s); array when OR’d selector branches
534
+ declarations: string; // CSS declarations (e.g. 'color: red;')
535
+ atRules?: string[]; // Wrapping at-rules
536
+ rootPrefix?: string; // Root state prefix
537
+ startingStyle?: boolean; // Wrap declarations in @starting-style
538
+ order?: number; // Internal cascade order hint (ascending source priority); stripped before injection
539
+ }
540
+ ```
541
+
542
+ When `renderStyles` runs **without** a selector, returned rules include `needsClassName: true` (compatibility field for the injector); that flag is not part of `CSSRule` inside `materialize.ts`.
543
+
544
+ ---
545
+
546
+ ## Condition Types
547
+
548
+ **File:** `conditions.ts`
549
+
550
+ ### ConditionNode Hierarchy
551
+
552
+ ```
553
+ ConditionNode
554
+ ├── TrueCondition (matches everything)
555
+ ├── FalseCondition (matches nothing)
556
+ ├── CompoundCondition (AND/OR of children)
557
+ └── StateCondition
558
+ ├── ModifierCondition (data attributes; optional value + match operator)
559
+ ├── PseudoCondition (CSS pseudo-classes: :hover)
560
+ ├── MediaCondition (subtype: dimension | feature | type)
561
+ ├── ContainerCondition (subtype: dimension | style | raw)
562
+ ├── RootCondition (inner condition under :root)
563
+ ├── ParentCondition (@parent(...); optional direct parent)
564
+ ├── OwnCondition (@own(...); scoped to styled / sub-element)
565
+ ├── SupportsCondition (@supports(...))
566
+ └── StartingCondition (@starting-style wrapper)
567
+ ```
568
+
569
+ ### Key Operations
570
+
571
+ - `and(...conditions)`: Create AND with short-circuit and flattening
572
+ - `or(...conditions)`: Create OR with short-circuit and flattening
573
+ - `not(condition)`: Negate with De Morgan's law support
574
+ - `getConditionUniqueId(condition)`: Get canonical ID for comparison
575
+
576
+ ---
577
+
578
+ ## Simplification
579
+
580
+ **File:** `simplify.ts`
581
+
582
+ ### What It Does
583
+
584
+ Applies boolean algebra rules to reduce condition complexity and detect impossible combinations.
585
+
586
+ ### Rules Applied
587
+
588
+ 1. **Identity Laws**:
589
+ - `A & TRUE = A`
590
+ - `A | FALSE = A`
591
+
592
+ 2. **Annihilator Laws**:
593
+ - `A & FALSE = FALSE`
594
+ - `A | TRUE = TRUE`
595
+
596
+ 3. **Contradiction Detection**:
597
+ - `A & !A = FALSE`
598
+
599
+ 4. **Tautology Detection**:
600
+ - `A | !A = TRUE`
601
+
602
+ 5. **Idempotent Laws** (via deduplication):
603
+ - `A & A = A`
604
+ - `A | A = A`
605
+
606
+ 6. **Absorption Laws**:
607
+ - `A & (A | B) = A`
608
+ - `A | (A & B) = A`
609
+
610
+ 7. **Range intersection**: For **media and container** dimension queries, impossible ranges simplify to `FALSE` (e.g. `@media(w > 400px) & @media(w < 300px)`). Ranges with compatible bounds are also merged in place (`w >= 400 & w <= 800` → a single bounded range).
611
+
612
+ 8. **Container style queries**: Conflicting or redundant `@container` style conditions on the same property can be reduced (see `simplify.ts` around the container-style conflict pass).
613
+
614
+ 9. **Attribute conflict detection**:
615
+ - `[data-theme="dark"] & [data-theme="light"] = FALSE`
616
+
617
+ 10. **Complementary factoring** (OR context): `(A & B) | (A & !B) = A`. Also works on **compound complements** — if two AND-clauses differ only by a child that is a compound negation of the other (e.g. `X` vs `!X` where X is itself `(P & Q)`), the clauses factor correctly.
618
+
619
+ 11. **Consensus / resolution** (AND context, dual of #10): `(A | B) & (A | !B) = A`. Added in commit f9038bd to eliminate overlapping CSS selectors from compound-state OR branches.
620
+
621
+ ### Why
622
+
623
+ Simplification reduces CSS output size and catches impossible combinations early, preventing invalid CSS rules from being generated. Every `simplifyCondition` call is memoized by the condition's unique id, so the cost of running it many times across stages is negligible after the first hit.
624
+
625
+ ---
626
+
627
+ ## Caching Strategy
628
+
629
+ LRU and small auxiliary caches:
630
+
631
+ | Cache | Size | Key | Purpose |
632
+ |-------|------|-----|---------|
633
+ | `pipelineCache` | 5000 | `pipelineCacheKey \|\| stringifyStyles(styles)` | Skip full pipeline for identical styles |
634
+ | `parseCache` | 5000 | `trimmedStateKey + '\\0' + isSubElement + '\\0' + JSON.stringify(localPredefinedStates)` | Skip re-parsing identical state keys in context |
635
+ | `simplifyCache` | 5000 | `getConditionUniqueId(node)` | Skip re-simplifying identical conditions |
636
+ | `conditionCache` | 3000 | `getConditionUniqueId(node)` in `conditionToCSS` | Skip re-materializing identical conditions |
637
+ | `variantKeyCache` | — | `WeakMap<SelectorVariant, string>` | Stable string keys for variants during materialization |
638
+ | `declStringCache` | — | `WeakMap<Record<string,string>, string>` | Stable JSON keys for declaration objects in `mergeByValue` |
639
+
640
+ ---
641
+
642
+ ## Example Walkthrough
643
+
644
+ ### Input
645
+
646
+ ```typescript
647
+ const styles = {
648
+ color: {
649
+ '': '#white',
650
+ '@media(prefers-color-scheme: dark)': '#dark',
651
+ hovered: '#highlight',
652
+ },
653
+ };
654
+ ```
655
+
656
+ ### Stage 1: Parse Conditions
657
+
658
+ ```
659
+ '' → TrueCondition
660
+ '@media(prefers-color-scheme: dark)' → MediaCondition(subtype: 'feature', feature: 'prefers-color-scheme', featureValue: 'dark')
661
+ 'hovered' → ModifierCondition(attribute: 'data-hovered')
662
+ ```
663
+
664
+ ### Stage 0 + 1b: Normalization
665
+
666
+ No compound AND keys, no same-value duplicates — the value map is unchanged.
667
+
668
+ ### Stage 1 + 2a: Parse and expand user ORs
669
+
670
+ No user ORs — three entries pass through unchanged.
671
+
672
+ ### Stage 2b + 3: Exclusive conditions + De Morgan expansion
673
+
674
+ Processing order (highest priority first): `hovered`, `@media(dark)`, default.
675
+
676
+ ```
677
+ hovered: [data-hovered]
678
+ @media(dark) & !hovered: @media(dark) & :not([data-hovered])
679
+ !hovered & !@media(dark): :not([data-hovered]) & not @media(dark)
680
+ ```
681
+
682
+ The default entry's exclusive is `!hovered & !@media(dark)` — no top-level OR, so Stage 3 expansion does nothing. If a higher-priority entry had been `@media(dark) & :has(foo)`, the default's exclusive would have expanded via De Morgan into two at-rule-aware branches (see Stage 3 for that scenario).
683
+
684
+ ### Stages 4–5: Compute combinations and call handler
685
+
686
+ Single style, three snapshots; the `color` handler emits `color` plus a `--current-color` variable.
687
+
688
+ ### Stage 6: Merge by value
689
+
690
+ Each snapshot yields distinct declarations; no merge.
691
+
692
+ ### Stage 7: Materialize CSS
693
+
694
+ Using `renderStyles(styles, '.t1')` (the class is doubled — `.t1.t1` — so Tasty owns specificity without `!important`):
695
+
696
+ ```css
697
+ .t1[data-hovered] {
698
+ color: var(--highlight-color);
699
+ --current-color: var(--highlight-color);
700
+ }
701
+ @media (prefers-color-scheme: dark) {
702
+ .t1:not([data-hovered]) {
703
+ color: var(--dark-color);
704
+ --current-color: var(--dark-color);
705
+ }
706
+ }
707
+ @media (not (prefers-color-scheme: dark)) {
708
+ .t1:not([data-hovered]) {
709
+ color: var(--white-color);
710
+ --current-color: var(--white-color);
711
+ }
712
+ }
713
+ ```
714
+
715
+ ---
716
+
717
+ ## Key Design Decisions
718
+
719
+ ### 1. Exclusive Conditions Over CSS Specificity
720
+
721
+ Rather than relying on CSS cascade rules, we generate mutually exclusive selectors. This makes styling predictable and debuggable.
722
+
723
+ ### 2. OR Handling in Three Layers
724
+
725
+ Boolean OR appears in three different shapes during the pipeline, and each is handled where it's cheapest to get right:
726
+
727
+ 1. **User-authored ORs in state keys** (Stage 2a, `expandOrConditions`): A user-authored condition like `'compact | @media(w < 768px)'` is split into multiple exclusive entries **before** exclusive building so the negation cascade doesn't have to reason about nested ORs.
728
+
729
+ 2. **De Morgan ORs from negation** (Stage 3, `expandExclusiveOrs`): When `buildExclusiveConditions` negates a higher-priority compound like `A & B`, the result is `!A | !B`. If branches involve at-rules, they're split with `sortOrBranchesForExpansion` so at-rule context is preserved per branch.
730
+
731
+ 3. **Pure selector ORs** (materialization): ORs that only mention modifiers/pseudos are kept intact until the `conditionToCSS` layer, where they're merged into `:is()` / `:not()` groups or emitted as comma-separated selectors. There's no gain from expanding these earlier — CSS already has compact syntax for selector-only disjunction.
732
+
733
+ Ultimately every emitted CSS rule corresponds to one conjunctive clause (DNF), produced by whichever of the three paths handled the OR.
734
+
735
+ ### 3. Early Contradiction Detection
736
+
737
+ Impossible combinations are detected at multiple levels (simplification, variant merging) to avoid generating invalid CSS.
738
+
739
+ ### 4. Aggressive Caching
740
+
741
+ Parse, simplify, condition-to-CSS, and full-pipeline results are cached independently, enabling fast re-rendering when only parts of the style object change.