@tenphi/tasty 0.0.0-snapshot.fafcbfe → 0.0.0-snapshot.fc19da9

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 (330) hide show
  1. package/README.md +497 -266
  2. package/dist/babel-types-DpUCD2L_.d.ts +18 -0
  3. package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
  4. package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
  5. package/dist/chunks/build-config-BDLYGmKn.js +60 -0
  6. package/dist/chunks/build-config-BDLYGmKn.js.map +1 -0
  7. package/dist/chunks/collector-DqcB0UUT.js +210 -0
  8. package/dist/chunks/collector-DqcB0UUT.js.map +1 -0
  9. package/dist/chunks/config-engine-CGIMO2PV.js +272 -0
  10. package/dist/chunks/config-engine-CGIMO2PV.js.map +1 -0
  11. package/dist/chunks/config-file-DlZXJMj8.js +25 -0
  12. package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
  13. package/dist/chunks/css-definitions-BibU6ZnP.js +904 -0
  14. package/dist/chunks/css-definitions-BibU6ZnP.js.map +1 -0
  15. package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
  16. package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
  17. package/dist/chunks/debug-BzYPQ0H2.js +502 -0
  18. package/dist/chunks/debug-BzYPQ0H2.js.map +1 -0
  19. package/dist/chunks/dsl-DRhFWQzo.js +1378 -0
  20. package/dist/chunks/dsl-DRhFWQzo.js.map +1 -0
  21. package/dist/chunks/hydration-TRcz5vnk.js +41 -0
  22. package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
  23. package/dist/chunks/react-runtime-B2e-Wha-.js +689 -0
  24. package/dist/chunks/react-runtime-B2e-Wha-.js.map +1 -0
  25. package/dist/chunks/runtime-engine-yeyCAx2e.js +2431 -0
  26. package/dist/chunks/runtime-engine-yeyCAx2e.js.map +1 -0
  27. package/dist/chunks/runtime-state-C0u1jp-Q.js +141 -0
  28. package/dist/chunks/runtime-state-C0u1jp-Q.js.map +1 -0
  29. package/dist/{utils/merge-styles.js → chunks/shared-utils-y-HjvPN4.js} +61 -58
  30. package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
  31. package/dist/chunks/style-engine-D35rvcdB.js +5420 -0
  32. package/dist/chunks/style-engine-D35rvcdB.js.map +1 -0
  33. package/dist/chunks/zero-engine-DpkieEPZ.js +310 -0
  34. package/dist/chunks/zero-engine-DpkieEPZ.js.map +1 -0
  35. package/dist/collector-D4POJ53X.d.ts +164 -0
  36. package/dist/config-DvPUj4cw.d.ts +1364 -0
  37. package/dist/core/index.d.ts +5 -33
  38. package/dist/core/index.js +9 -26
  39. package/dist/hydrate-CRyjjAyl.d.ts +22 -0
  40. package/dist/index-DC4q-xDq.d.ts +1946 -0
  41. package/dist/index.d.ts +5 -40
  42. package/dist/index.js +11 -33
  43. package/dist/{utils/merge-styles.d.ts → merge-styles-Jb5iZ-Jf.d.ts} +3 -4
  44. package/dist/ssr/astro-client.d.ts +1 -0
  45. package/dist/ssr/astro-client.js +6 -0
  46. package/dist/ssr/astro-client.js.map +1 -0
  47. package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
  48. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  49. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  50. package/dist/ssr/astro-middleware-extract.d.ts +10 -0
  51. package/dist/ssr/astro-middleware-extract.js +9 -0
  52. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  53. package/dist/ssr/astro-middleware-static.d.ts +17 -0
  54. package/dist/ssr/astro-middleware-static.js +7 -0
  55. package/dist/ssr/astro-middleware-static.js.map +1 -0
  56. package/dist/ssr/astro-middleware.d.ts +18 -0
  57. package/dist/ssr/astro-middleware.js +7 -0
  58. package/dist/ssr/astro-middleware.js.map +1 -0
  59. package/dist/ssr/astro.d.ts +127 -0
  60. package/dist/ssr/astro.js +221 -0
  61. package/dist/ssr/astro.js.map +1 -0
  62. package/dist/ssr/client.d.ts +2 -0
  63. package/dist/ssr/client.js +2 -0
  64. package/dist/ssr/index.d.ts +17 -0
  65. package/dist/ssr/index.js +10 -0
  66. package/dist/ssr/index.js.map +1 -0
  67. package/dist/ssr/next-config.d.ts +64 -0
  68. package/dist/ssr/next-config.js +123 -0
  69. package/dist/ssr/next-config.js.map +1 -0
  70. package/dist/ssr/next.d.ts +46 -0
  71. package/dist/ssr/next.js +60 -0
  72. package/dist/ssr/next.js.map +1 -0
  73. package/dist/static/index.d.ts +90 -5
  74. package/dist/static/index.js +31 -4
  75. package/dist/static/index.js.map +1 -0
  76. package/dist/static/inject.d.ts +4 -0
  77. package/dist/static/inject.js +17 -0
  78. package/dist/static/inject.js.map +1 -0
  79. package/dist/types-ZbF2_6LV.d.ts +1567 -0
  80. package/dist/zero/babel.d.ts +49 -90
  81. package/dist/zero/babel.js +252 -119
  82. package/dist/zero/babel.js.map +1 -1
  83. package/dist/zero/index.d.ts +117 -3
  84. package/dist/zero/index.js +23 -3
  85. package/dist/zero/index.js.map +1 -0
  86. package/dist/zero/next.d.ts +58 -33
  87. package/dist/zero/next.js +89 -59
  88. package/dist/zero/next.js.map +1 -1
  89. package/docs/README.md +42 -0
  90. package/docs/adoption.md +331 -0
  91. package/docs/ai-agents.md +252 -0
  92. package/docs/comparison.md +449 -0
  93. package/docs/configuration.md +943 -0
  94. package/docs/debug.md +333 -0
  95. package/docs/design-system.md +557 -0
  96. package/docs/dsl.md +1093 -0
  97. package/docs/getting-started.md +297 -0
  98. package/docs/injector.md +633 -0
  99. package/docs/methodology.md +673 -0
  100. package/docs/migration-v3.md +285 -0
  101. package/docs/pipeline.md +768 -0
  102. package/docs/plugins.md +333 -0
  103. package/docs/react-api.md +703 -0
  104. package/docs/runtime-benchmarks.md +388 -0
  105. package/docs/ssr.md +630 -0
  106. package/docs/styles.md +725 -0
  107. package/docs/tasty-static.md +659 -0
  108. package/package.json +238 -50
  109. package/tasty.config.ts +6 -0
  110. package/dist/_virtual/_rolldown/runtime.js +0 -8
  111. package/dist/chunks/cacheKey.js +0 -70
  112. package/dist/chunks/cacheKey.js.map +0 -1
  113. package/dist/chunks/definitions.d.ts +0 -37
  114. package/dist/chunks/definitions.js +0 -260
  115. package/dist/chunks/definitions.js.map +0 -1
  116. package/dist/chunks/renderChunk.js +0 -61
  117. package/dist/chunks/renderChunk.js.map +0 -1
  118. package/dist/config.d.ts +0 -280
  119. package/dist/config.js +0 -403
  120. package/dist/config.js.map +0 -1
  121. package/dist/debug.d.ts +0 -204
  122. package/dist/debug.js +0 -733
  123. package/dist/debug.js.map +0 -1
  124. package/dist/hooks/useGlobalStyles.d.ts +0 -27
  125. package/dist/hooks/useGlobalStyles.js +0 -56
  126. package/dist/hooks/useGlobalStyles.js.map +0 -1
  127. package/dist/hooks/useKeyframes.d.ts +0 -56
  128. package/dist/hooks/useKeyframes.js +0 -54
  129. package/dist/hooks/useKeyframes.js.map +0 -1
  130. package/dist/hooks/useProperty.d.ts +0 -79
  131. package/dist/hooks/useProperty.js +0 -91
  132. package/dist/hooks/useProperty.js.map +0 -1
  133. package/dist/hooks/useRawCSS.d.ts +0 -53
  134. package/dist/hooks/useRawCSS.js +0 -28
  135. package/dist/hooks/useRawCSS.js.map +0 -1
  136. package/dist/hooks/useStyles.d.ts +0 -40
  137. package/dist/hooks/useStyles.js +0 -169
  138. package/dist/hooks/useStyles.js.map +0 -1
  139. package/dist/injector/index.d.ts +0 -157
  140. package/dist/injector/index.js +0 -154
  141. package/dist/injector/index.js.map +0 -1
  142. package/dist/injector/injector.d.ts +0 -139
  143. package/dist/injector/injector.js +0 -404
  144. package/dist/injector/injector.js.map +0 -1
  145. package/dist/injector/sheet-manager.d.ts +0 -127
  146. package/dist/injector/sheet-manager.js +0 -714
  147. package/dist/injector/sheet-manager.js.map +0 -1
  148. package/dist/injector/types.d.ts +0 -135
  149. package/dist/keyframes/index.js +0 -206
  150. package/dist/keyframes/index.js.map +0 -1
  151. package/dist/parser/classify.js +0 -319
  152. package/dist/parser/classify.js.map +0 -1
  153. package/dist/parser/const.js +0 -33
  154. package/dist/parser/const.js.map +0 -1
  155. package/dist/parser/lru.js +0 -109
  156. package/dist/parser/lru.js.map +0 -1
  157. package/dist/parser/parser.d.ts +0 -25
  158. package/dist/parser/parser.js +0 -116
  159. package/dist/parser/parser.js.map +0 -1
  160. package/dist/parser/tokenizer.js +0 -69
  161. package/dist/parser/tokenizer.js.map +0 -1
  162. package/dist/parser/types.d.ts +0 -51
  163. package/dist/parser/types.js +0 -46
  164. package/dist/parser/types.js.map +0 -1
  165. package/dist/pipeline/conditions.d.ts +0 -134
  166. package/dist/pipeline/conditions.js +0 -400
  167. package/dist/pipeline/conditions.js.map +0 -1
  168. package/dist/pipeline/exclusive.js +0 -231
  169. package/dist/pipeline/exclusive.js.map +0 -1
  170. package/dist/pipeline/index.d.ts +0 -53
  171. package/dist/pipeline/index.js +0 -641
  172. package/dist/pipeline/index.js.map +0 -1
  173. package/dist/pipeline/materialize.js +0 -908
  174. package/dist/pipeline/materialize.js.map +0 -1
  175. package/dist/pipeline/parseStateKey.d.ts +0 -15
  176. package/dist/pipeline/parseStateKey.js +0 -430
  177. package/dist/pipeline/parseStateKey.js.map +0 -1
  178. package/dist/pipeline/simplify.js +0 -557
  179. package/dist/pipeline/simplify.js.map +0 -1
  180. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  181. package/dist/plugins/okhsl-plugin.js +0 -371
  182. package/dist/plugins/okhsl-plugin.js.map +0 -1
  183. package/dist/plugins/types.d.ts +0 -69
  184. package/dist/properties/index.js +0 -158
  185. package/dist/properties/index.js.map +0 -1
  186. package/dist/states/index.d.ts +0 -49
  187. package/dist/states/index.js +0 -416
  188. package/dist/states/index.js.map +0 -1
  189. package/dist/static/tastyStatic.d.ts +0 -46
  190. package/dist/static/tastyStatic.js +0 -31
  191. package/dist/static/tastyStatic.js.map +0 -1
  192. package/dist/static/types.d.ts +0 -49
  193. package/dist/static/types.js +0 -24
  194. package/dist/static/types.js.map +0 -1
  195. package/dist/styles/align.d.ts +0 -15
  196. package/dist/styles/align.js +0 -14
  197. package/dist/styles/align.js.map +0 -1
  198. package/dist/styles/border.d.ts +0 -25
  199. package/dist/styles/border.js +0 -114
  200. package/dist/styles/border.js.map +0 -1
  201. package/dist/styles/color.d.ts +0 -14
  202. package/dist/styles/color.js +0 -23
  203. package/dist/styles/color.js.map +0 -1
  204. package/dist/styles/createStyle.js +0 -77
  205. package/dist/styles/createStyle.js.map +0 -1
  206. package/dist/styles/dimension.js +0 -97
  207. package/dist/styles/dimension.js.map +0 -1
  208. package/dist/styles/display.d.ts +0 -37
  209. package/dist/styles/display.js +0 -67
  210. package/dist/styles/display.js.map +0 -1
  211. package/dist/styles/fade.d.ts +0 -15
  212. package/dist/styles/fade.js +0 -58
  213. package/dist/styles/fade.js.map +0 -1
  214. package/dist/styles/fill.d.ts +0 -44
  215. package/dist/styles/fill.js +0 -51
  216. package/dist/styles/fill.js.map +0 -1
  217. package/dist/styles/flow.d.ts +0 -16
  218. package/dist/styles/flow.js +0 -12
  219. package/dist/styles/flow.js.map +0 -1
  220. package/dist/styles/gap.d.ts +0 -31
  221. package/dist/styles/gap.js +0 -37
  222. package/dist/styles/gap.js.map +0 -1
  223. package/dist/styles/height.d.ts +0 -17
  224. package/dist/styles/height.js +0 -20
  225. package/dist/styles/height.js.map +0 -1
  226. package/dist/styles/index.d.ts +0 -2
  227. package/dist/styles/index.js +0 -9
  228. package/dist/styles/index.js.map +0 -1
  229. package/dist/styles/inset.d.ts +0 -52
  230. package/dist/styles/inset.js +0 -150
  231. package/dist/styles/inset.js.map +0 -1
  232. package/dist/styles/justify.d.ts +0 -15
  233. package/dist/styles/justify.js +0 -14
  234. package/dist/styles/justify.js.map +0 -1
  235. package/dist/styles/list.d.ts +0 -16
  236. package/dist/styles/list.js +0 -98
  237. package/dist/styles/list.js.map +0 -1
  238. package/dist/styles/margin.d.ts +0 -24
  239. package/dist/styles/margin.js +0 -104
  240. package/dist/styles/margin.js.map +0 -1
  241. package/dist/styles/outline.d.ts +0 -29
  242. package/dist/styles/outline.js +0 -65
  243. package/dist/styles/outline.js.map +0 -1
  244. package/dist/styles/padding.d.ts +0 -24
  245. package/dist/styles/padding.js +0 -104
  246. package/dist/styles/padding.js.map +0 -1
  247. package/dist/styles/predefined.d.ts +0 -73
  248. package/dist/styles/predefined.js +0 -241
  249. package/dist/styles/predefined.js.map +0 -1
  250. package/dist/styles/preset.d.ts +0 -47
  251. package/dist/styles/preset.js +0 -126
  252. package/dist/styles/preset.js.map +0 -1
  253. package/dist/styles/radius.d.ts +0 -14
  254. package/dist/styles/radius.js +0 -51
  255. package/dist/styles/radius.js.map +0 -1
  256. package/dist/styles/scrollbar.d.ts +0 -21
  257. package/dist/styles/scrollbar.js +0 -105
  258. package/dist/styles/scrollbar.js.map +0 -1
  259. package/dist/styles/shadow.d.ts +0 -14
  260. package/dist/styles/shadow.js +0 -24
  261. package/dist/styles/shadow.js.map +0 -1
  262. package/dist/styles/styledScrollbar.d.ts +0 -47
  263. package/dist/styles/styledScrollbar.js +0 -38
  264. package/dist/styles/styledScrollbar.js.map +0 -1
  265. package/dist/styles/transition.d.ts +0 -14
  266. package/dist/styles/transition.js +0 -158
  267. package/dist/styles/transition.js.map +0 -1
  268. package/dist/styles/types.d.ts +0 -498
  269. package/dist/styles/width.d.ts +0 -17
  270. package/dist/styles/width.js +0 -20
  271. package/dist/styles/width.js.map +0 -1
  272. package/dist/tasty.d.ts +0 -982
  273. package/dist/tasty.js +0 -191
  274. package/dist/tasty.js.map +0 -1
  275. package/dist/tokens/typography.d.ts +0 -19
  276. package/dist/tokens/typography.js +0 -237
  277. package/dist/tokens/typography.js.map +0 -1
  278. package/dist/types.d.ts +0 -184
  279. package/dist/utils/cache-wrapper.js +0 -26
  280. package/dist/utils/cache-wrapper.js.map +0 -1
  281. package/dist/utils/case-converter.js +0 -8
  282. package/dist/utils/case-converter.js.map +0 -1
  283. package/dist/utils/colors.d.ts +0 -5
  284. package/dist/utils/colors.js +0 -9
  285. package/dist/utils/colors.js.map +0 -1
  286. package/dist/utils/css-types.d.ts +0 -7
  287. package/dist/utils/dotize.d.ts +0 -26
  288. package/dist/utils/dotize.js +0 -122
  289. package/dist/utils/dotize.js.map +0 -1
  290. package/dist/utils/filter-base-props.d.ts +0 -15
  291. package/dist/utils/filter-base-props.js +0 -45
  292. package/dist/utils/filter-base-props.js.map +0 -1
  293. package/dist/utils/get-display-name.d.ts +0 -7
  294. package/dist/utils/get-display-name.js +0 -10
  295. package/dist/utils/get-display-name.js.map +0 -1
  296. package/dist/utils/hsl-to-rgb.js +0 -38
  297. package/dist/utils/hsl-to-rgb.js.map +0 -1
  298. package/dist/utils/is-dev-env.js +0 -19
  299. package/dist/utils/is-dev-env.js.map +0 -1
  300. package/dist/utils/is-valid-element-type.js +0 -15
  301. package/dist/utils/is-valid-element-type.js.map +0 -1
  302. package/dist/utils/merge-styles.js.map +0 -1
  303. package/dist/utils/mod-attrs.d.ts +0 -8
  304. package/dist/utils/mod-attrs.js +0 -21
  305. package/dist/utils/mod-attrs.js.map +0 -1
  306. package/dist/utils/okhsl-to-rgb.js +0 -296
  307. package/dist/utils/okhsl-to-rgb.js.map +0 -1
  308. package/dist/utils/process-tokens.d.ts +0 -31
  309. package/dist/utils/process-tokens.js +0 -171
  310. package/dist/utils/process-tokens.js.map +0 -1
  311. package/dist/utils/resolve-recipes.d.ts +0 -17
  312. package/dist/utils/resolve-recipes.js +0 -147
  313. package/dist/utils/resolve-recipes.js.map +0 -1
  314. package/dist/utils/string.js +0 -8
  315. package/dist/utils/string.js.map +0 -1
  316. package/dist/utils/styles.d.ts +0 -183
  317. package/dist/utils/styles.js +0 -585
  318. package/dist/utils/styles.js.map +0 -1
  319. package/dist/utils/typography.d.ts +0 -36
  320. package/dist/utils/typography.js +0 -53
  321. package/dist/utils/typography.js.map +0 -1
  322. package/dist/utils/warnings.d.ts +0 -16
  323. package/dist/utils/warnings.js +0 -16
  324. package/dist/utils/warnings.js.map +0 -1
  325. package/dist/zero/css-writer.d.ts +0 -45
  326. package/dist/zero/css-writer.js +0 -74
  327. package/dist/zero/css-writer.js.map +0 -1
  328. package/dist/zero/extractor.d.ts +0 -24
  329. package/dist/zero/extractor.js +0 -150
  330. package/dist/zero/extractor.js.map +0 -1
package/docs/dsl.md ADDED
@@ -0,0 +1,1093 @@
1
+ # Style DSL Reference
2
+
3
+ This is the language behind Tasty’s predictable state resolution. Every property can use a state map; later branches declare higher priority, and Tasty compiles them so only one generated selector can match.
4
+
5
+ The same value syntax, state maps, tokens, units, extension semantics, and special declarations apply to React `tasty()`—whether rendered on the client or server—and build-time `tastyStatic()`.
6
+
7
+ For the React API (`tasty()`, style functions, component props), see [React API](react-api.md). For all enhanced style properties, see [Style Properties](styles.md). For global configuration, see [Configuration](configuration.md).
8
+
9
+ To autocomplete your own token and preset names, see [TypeScript autocomplete](getting-started.md#typescript-autocomplete); to check state keys, tokens, units, and values at lint time, see [ESLint plugin](getting-started.md#eslint-plugin).
10
+
11
+ ---
12
+
13
+ ## Dictionary
14
+
15
+ ### Style Mapping
16
+
17
+ Object where keys represent states and values are the styles to apply:
18
+
19
+ ```jsx
20
+ fill: { '': '#white', hovered: '#gray.05', 'theme=danger': '#red' }
21
+ ```
22
+
23
+ Define an alias for one component by adding an `'@name': '<state expression>'` key to its styles. It works like a global alias from [`configure({ states })`](configuration.md#options), scoped to that component:
24
+
25
+ ```jsx
26
+ styles: {
27
+ '@narrow': '@media(w < 600px)',
28
+ fill: { '': '#surface', '@narrow': '#surface-mobile' },
29
+ }
30
+ ```
31
+
32
+ #### State Key Types
33
+
34
+ | Syntax | Example | Generated CSS |
35
+ | ------------------ | ------------------------ | ------------------------------------------------------------------------ |
36
+ | Boolean modifier | `hovered` | `[data-hovered]` |
37
+ | Value modifier | `theme=danger` | `[data-theme="danger"]` |
38
+ | Pseudo-class | `:hover` | `:hover` |
39
+ | Class selector | `.active` | `.active` |
40
+ | Attribute selector | `[aria-expanded="true"]` | `[aria-expanded="true"]` |
41
+ | Combined (AND) | `hovered & .active` | `[data-hovered].active` |
42
+ | Combined (OR) | `hovered \| focused` | `[data-hovered], [data-focused]` |
43
+ | Negated (NOT) | `!disabled` | `:not([data-disabled])` |
44
+ | Exclusive (XOR) | `hovered ^ focused` | `[data-hovered]:not([data-focused]), :not([data-hovered])[data-focused]` |
45
+
46
+ #### Automatic Native States
47
+
48
+ `disabled`, `checked`, and `hidden` are built-in automatic states. A Tasty component sets `data-disabled`, `data-checked`, and `data-hidden` from the native `disabled`, `checked`, and `hidden` props (or `isDisabled`, `isChecked`, `isHidden`), so each pair below expresses the same component state:
49
+
50
+ | Concise Tasty state | Compiles to | Explicit attribute selector |
51
+ | ------------------- | ----------------- | --------------------------- |
52
+ | `disabled` | `[data-disabled]` | `[disabled]` |
53
+ | `checked` | `[data-checked]` | `[checked]` |
54
+ | `hidden` | `[data-hidden]` | `[hidden]` |
55
+
56
+ Prefer the concise form when authoring Tasty component styles. Explicit attribute selectors remain valid and can be useful when targeting arbitrary attributes or when CSS-shaped syntax makes an introductory example easier to recognize.
57
+
58
+ Operator precedence (highest to lowest): `!` (NOT) > `^` (XOR) > `|` (OR) > `&` (AND). Use parentheses to override: `hovered & (pressed ^ focused)`.
59
+
60
+ A top-level comma is the same as `|`: `'hovered, focused'` is `'hovered | focused'`.
61
+
62
+ `^` (XOR) means "exactly one of" — `A ^ B` expands to `(A & !B) | (!A & B)`. This is useful for mutually exclusive states where exactly one should be active:
63
+
64
+ ```jsx
65
+ fill: {
66
+ '': '#surface',
67
+ 'hovered ^ focused': '#accent', // active when hovered OR focused, but not both
68
+ }
69
+ ```
70
+
71
+ Modifier and class names start with a letter and may be a single letter (`x` → `[data-x]`, `.x`). Tasty emits an `INVALID_STATE_KEY` warning for a key it cannot fully read and skips the unreadable parts. That covers characters outside the notation (`1st`, or `@media (w < 600px)` with a space before the parenthesis), an operator missing a state (`hovered &`), and two states with no operator between them (`hovered focused`). A partly read key can apply in states you did not mean, so fix the key rather than rely on what it produces.
72
+
73
+ #### Default State Ordering
74
+
75
+ Key order sets priority — later keys win and turn off earlier ones via negation. The bare default (`''`) is the lowest-priority state, so it **must be the first key**. If it appears after other states, Tasty moves it to the front and emits a dev warning (`MISPLACED_DEFAULT_STATE`); otherwise it would override every state above it.
76
+
77
+ ```jsx
78
+ // Correct — default first
79
+ color: { '': '#text', hovered: '#accent' }
80
+
81
+ // Auto-corrected with a warning — '' moved to the front
82
+ color: { hovered: '#accent', '': '#text' }
83
+ ```
84
+
85
+ The bare `''` default still **receives negation** (it is turned off when a higher-priority state matches). For a value that must always apply as a guaranteed floor — even where a query is _unknown_ — use the [`_` fallback floor](#_--fallback-floor) instead. The two can coexist: `''` is the negated default, `_` is the always-on floor. If a map contains only `_` and `''` (no other states), the `''` default is redundant — Tasty keeps the `_` value and drops `''` with a `REDUNDANT_DEFAULT_STATE` warning.
86
+
87
+ ### Sub-element
88
+
89
+ Element styled using a capitalized key. Identified by `data-element` attribute:
90
+
91
+ ```jsx
92
+ styles: {
93
+ Title: { preset: 'h3' },
94
+ }
95
+ // Targets: <div data-element="Title">
96
+ ```
97
+
98
+ #### Selector Affix (`$`)
99
+
100
+ Control how a sub-element selector attaches to the root selector using the `$` property inside the sub-element's styles.
101
+
102
+ Examples below assume the sub-element key is **Cell** (i.e. `[data-element="Cell"]` in CSS):
103
+
104
+ | Pattern | Result | Description |
105
+ | ----------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
106
+ | _(none)_ | `[data-element="Cell"]` | Descendant (default) |
107
+ | `>` | `> [data-element="Cell"]` | Direct child |
108
+ | `>Body>` | `> [data-element="Body"] > [data-element="Cell"]` | Chained elements |
109
+ | `> Cell` | `> [data-element="Cell"]` | Self-name shorthand — when the trailing element name matches the sub-element's own key, it acts as the placeholder (same as `@`); no duplication |
110
+ | `h1` | `h1` | Tag selector (no key injection) |
111
+ | `h1 >` | `h1 > [data-element="Cell"]` | Key is direct child of tag |
112
+ | `h1 *` | `h1 *` | Any descendant of tag |
113
+ | `*` | `*` | All descendants |
114
+ | `&::before` | `::before` | Root pseudo (no key); `&` is required |
115
+ | `@::before` | `[data-element="Cell"]::before` | Pseudo on the sub-element |
116
+ | `>@.active` | `> [data-element="Cell"].active` | Class on the sub-element |
117
+
118
+ Rules for key injection (`[data-element="..."]`):
119
+
120
+ - **Trailing combinator** (`>`, `+`, `~`) — key is injected after it
121
+ - **Uppercase element name** (`Body`, `Row`) — key is injected as descendant
122
+ - **HTML tag** (`h1`, `a`, `span`) — no key injection; the tag IS the selector
123
+ - **Universal selector** (`*`) — no key injection
124
+ - **Pseudo / class / attribute** — no key injection
125
+
126
+ The `@` placeholder marks exactly where `[data-element="..."]` is injected, allowing you to attach pseudo-classes, pseudo-elements, or class selectors directly to the sub-element instead of the root:
127
+
128
+ ```jsx
129
+ const List = tasty({
130
+ styles: {
131
+ Item: {
132
+ $: '>@::after',
133
+ content: '""',
134
+ },
135
+ },
136
+ });
137
+ // → .t0.t0 > [data-element="Item"]::after { content: "" }
138
+ ```
139
+
140
+ Keep conditions such as `:last-child` out of `$` and write them as `@own(:last-child)` in a state map; `tasty/no-state-in-selector` warns otherwise.
141
+
142
+ ### Color Token
143
+
144
+ Named color prefixed with `#` that maps to CSS custom properties. Supports opacity with `.N` suffix:
145
+
146
+ ```jsx
147
+ fill: '#purple.5'; // → oklch(from var(--purple-color) l c h / .5)
148
+ ```
149
+
150
+ ### Modifier
151
+
152
+ State value via `mods` prop that generates `data-*` attributes:
153
+
154
+ ```jsx
155
+ mods={{ hovered: true, theme: 'danger' }}
156
+ // → data-hovered="" data-theme="danger"
157
+ ```
158
+
159
+ Modifiers can also be exposed as top-level component props via `modProps` — see [React API — Mod Props](react-api.md#mod-props).
160
+
161
+ ---
162
+
163
+ ## Color Tokens & Opacity
164
+
165
+ ```jsx
166
+ color: '#purple', // Full opacity
167
+ color: '#purple.5', // 50% opacity
168
+ color: '#purple.05', // 5% opacity
169
+ color: '#purple.$fade', // Opacity from a custom property
170
+ fill: '#current', // → currentcolor
171
+ color: '(#primary, #secondary)', // Fallback syntax
172
+ ```
173
+
174
+ `#white`, `#black`, `#clear` (transparent), and `#border` are registered by default, so they work before you define any tokens.
175
+
176
+ The suffix sets the alpha on the token's color with CSS relative color syntax:
177
+
178
+ ```jsx
179
+ fill: '#purple.5';
180
+ // → oklch(from var(--purple-color) l c h / .5)
181
+ ```
182
+
183
+ The channels are copied over and the alpha slot is written, which asks nothing of
184
+ the color beyond _being_ a color. That means the suffix works on every one of
185
+ these:
186
+
187
+ - a token holding a `color-mix()`, a `light-dark()`, or a `color()` in a space
188
+ Tasty cannot convert — none of which have channels to decompose
189
+ - `#current`, which resolves to the color the element inherits
190
+ - a `--name-color` variable declared in your own CSS, with no Tasty token
191
+ definition behind it
192
+
193
+ Two properties follow from writing the alpha slot rather than compositing:
194
+
195
+ - **Alpha is replaced, not multiplied.** A token holding `rgb(255 0 0 / .8)`
196
+ faded to `.5` is alpha `.5`, not `.4`.
197
+ - **The alpha may be a number or a percentage.** `#purple.$fade` emits
198
+ `/ var(--fade)` unchanged, so it works whether `$fade` holds `.5` or `50%` —
199
+ which is what `--*-opacity` properties are registered to accept.
200
+
201
+ ### `#current` is the keyword
202
+
203
+ `#current` emits the `currentcolor` keyword, so it resolves against the element
204
+ that reads it. That is what lets it follow a color an ancestor faded — a ramp
205
+ that expresses its disabled state once, in `color`, fades everything painted from
206
+ `#current` below it with no further declarations.
207
+
208
+ The `color` style also publishes `--current-color` beside every color it sets,
209
+ for anything that needs the inherited color _as a color_ rather than as the
210
+ keyword — hand-authored CSS, or a place the keyword will not do. Read it as
211
+ `$current-color`. It is registered with `initial-value: currentcolor`, so where
212
+ nothing published it, it still resolves against each element's own color:
213
+
214
+ ```jsx
215
+ fill: '$current-color'; // → var(--current-color)
216
+ ```
217
+
218
+ A color that already reads the color it inherits — `#current`, a `#current` fade
219
+ — is not published into it: resolving such a value a second time at a descendant
220
+ would fade it twice.
221
+
222
+ One case needs the wider floor to be considered. A token _defined_ as `#current`
223
+ and then faded gives relative color syntax a `currentcolor` origin, which Safari
224
+ supports only from 18:
225
+
226
+ ```jsx
227
+ { '#ink': '#current', fill: '#ink.5' }
228
+ // --ink-color: currentcolor
229
+ // fill: oklch(from currentcolor l c h / .5) → Chrome, Firefox, Safari 18+
230
+ ```
231
+
232
+ Put the fade in the token instead — `{ '#ink': '#current.5' }` — and it goes
233
+ through `color-mix()`, which works from Safari 16.2 and composes like every other
234
+ `#current` fade.
235
+
236
+ ### `#current` composes instead
237
+
238
+ `#current` is the one exception, and the difference is deliberate. A token _names_
239
+ a color, so fading it sets its alpha. `currentcolor` is the color an element
240
+ **inherits**, which an ancestor may already have faded — `#current.4` means "40%
241
+ of what reaches me":
242
+
243
+ ```jsx
244
+ fill: '#current.4';
245
+ // → color-mix(in oklab, currentcolor 40%, transparent)
246
+ ```
247
+
248
+ So a `#current` fade nested inside another one composes: a label at `#current.4`
249
+ with a fill of `#current.18` under it lands at `.072`. Color ramps built on
250
+ `#current` depend on that — replacing would double the opacity of every nested
251
+ step. Because a `color-mix()` percentage cannot be a `<number>`, an opacity
252
+ custom property used as `#current.$fade` must hold a unitless number; a token
253
+ accepts either form.
254
+
255
+ Token fades always use `oklch(from …)`: it is unbounded, so a wide-gamut color
256
+ survives a round trip that a gamut-limited space would clamp. `#current` fades
257
+ mix `in oklab`. Nothing configures either — see
258
+ [Color space](configuration.md#color-space).
259
+
260
+ ---
261
+
262
+ ## CSS Color Functions
263
+
264
+ Every CSS color function is recognized as a color, so it lands in the color slot
265
+ of whichever style property you use it in — and tokens inside it are expanded:
266
+
267
+ ```jsx
268
+ fill: 'color-mix(in oklab, #primary 50%, #surface)',
269
+ color: 'light-dark(#dark, #light)',
270
+ color: 'contrast-color(#primary)',
271
+ fill: 'color(display-p3 1 .5 0)',
272
+ border: '1bw solid oklch(from #primary l c h / 50%)', // relative color syntax
273
+ shadow: '0 0 1x color-mix(in oklab, #dark 20%, transparent)',
274
+ ```
275
+
276
+ Tasty also ships `okhsl()` and `okhst()`, which compile to `rgb()` at parse
277
+ time: `fill: 'okhsl(280 80% 50%)'` → `rgb(40% 38.5% 88.2%)`.
278
+
279
+ `light-dark()` is the one exception to "always a color": CSS lets it pick between
280
+ values of any type, so it is treated as a color only when its arguments are
281
+ colors. `padding: 'light-dark(1x, 2x)'` still reaches the padding slot.
282
+
283
+ A color token defined as one of these functions takes the
284
+ [opacity suffix](#color-tokens--opacity) like any other:
285
+
286
+ ```jsx
287
+ const Card = tasty({
288
+ styles: {
289
+ '#brand': 'color-mix(in oklab, #primary 50%, #surface)',
290
+ fill: '#brand.5',
291
+ },
292
+ });
293
+ ```
294
+
295
+ A [replace token](configuration.md#replace-tokens-parse-time-substitution) is
296
+ substituted while parsing, so its color is right there to fade in place. A
297
+ channel function takes the alpha after a slash; a derived function has no alpha
298
+ channel, so it gets wrapped:
299
+
300
+ ```jsx
301
+ configure({
302
+ replaceTokens: {
303
+ '#solid': 'hsl(220 90% 50%)',
304
+ '#adaptive': 'light-dark(#dark, #light)',
305
+ },
306
+ });
307
+
308
+ fill: '#solid.5'; // → hsl(220 90% 50% / .5)
309
+ fill: '#adaptive.5'; // → oklch(from light-dark(…) l c h / .5)
310
+ ```
311
+
312
+ ---
313
+
314
+ ## Built-in Units
315
+
316
+ | Unit | Description | Default | Example | CSS output |
317
+ | ---- | ------------------ | ---------------- | ------- | ---------------- |
318
+ | `x` | Spacing step | `8px` | `2x` | `16px` |
319
+ | `r` | Border radius | `6px` | `1r` | `6px` |
320
+ | `cr` | Card border radius | `10px` | `1cr` | `10px` |
321
+ | `bw` | Border width | `1px` | `2bw` | `2px` |
322
+ | `ow` | Outline width | `3px` | `1ow` | `3px` |
323
+ | `sf` | Stable fraction | `minmax(0, Nfr)` | `1sf` | `minmax(0, 1fr)` |
324
+
325
+ Units compile to plain values. Change the scale with `configure({ units: { x: '4px' } })`, or point a unit at a custom property when it must change at runtime: with `units: { x: 'var(--gap)' }`, `2x` compiles to `calc(2 * var(--gap))`. Setting a `$gap` or `$radius` token does not change the units. Register additional units the same way via [`configure()`](configuration.md#options).
326
+
327
+ ---
328
+
329
+ ## Replace Tokens
330
+
331
+ Tokens defined via [`configure({ replaceTokens })`](configuration.md#replace-tokens-parse-time-substitution) are replaced at parse time and baked into the generated CSS:
332
+
333
+ ```jsx
334
+ const Card = tasty({
335
+ styles: {
336
+ padding: '$card-padding',
337
+ fill: '#surface',
338
+ border: '1bw solid #accent',
339
+ },
340
+ });
341
+ ```
342
+
343
+ ---
344
+
345
+ ## Recipes
346
+
347
+ Apply predefined style bundles (defined via [`configure({ recipes })`](configuration.md#recipes)) using the `recipe` style property:
348
+
349
+ ```jsx
350
+ const Card = tasty({
351
+ styles: {
352
+ recipe: 'card',
353
+ color: '#text',
354
+ },
355
+ });
356
+
357
+ // Compose multiple recipes
358
+ const ElevatedCard = tasty({
359
+ styles: {
360
+ recipe: 'card elevated',
361
+ color: '#text',
362
+ },
363
+ });
364
+ ```
365
+
366
+ **Where recipes resolve:**
367
+
368
+ The `recipe` property is resolved on the component root and independently inside each sub-element's styles:
369
+
370
+ ```jsx
371
+ const CardWithPanel = tasty({
372
+ styles: {
373
+ recipe: 'card',
374
+ Panel: {
375
+ recipe: 'card elevated',
376
+ padding: '2x', // Overrides the panel's base recipe padding
377
+ },
378
+ },
379
+ });
380
+ ```
381
+
382
+ At each level, base recipes are collected in the order listed (later recipes replace earlier values for the same property), then local styles are merged, then post recipes are merged. The merges with local styles and post recipes follow the [state-map extension and replacement rules](#extending-vs-replacing-state-maps).
383
+
384
+ Recipe definitions themselves cannot contain a `recipe` reference to another recipe: there is no recursive expansion or recipe inheritance. Compose names in the root or sub-element `recipe` property instead. See [Configuration — Recipes](configuration.md#recipes) for an unsupported nesting example.
385
+
386
+ **Post-merge recipes (`/` separator):**
387
+
388
+ Recipes listed after `/` are applied _after_ component styles using `mergeStyles`:
389
+
390
+ ```jsx
391
+ const Input = tasty({
392
+ styles: {
393
+ recipe: 'reset input / input-autofill',
394
+ preset: 't3',
395
+ },
396
+ });
397
+ ```
398
+
399
+ Use `none` to skip base recipes and apply only post recipes:
400
+
401
+ ```jsx
402
+ const Custom = tasty({
403
+ styles: {
404
+ recipe: 'none / disabled',
405
+ padding: '2x',
406
+ },
407
+ });
408
+ ```
409
+
410
+ ---
411
+
412
+ ## Extending vs. Replacing State Maps
413
+
414
+ When a style property uses a state map, the merge behavior depends on whether the child provides a `''` (default) key:
415
+
416
+ - **No `''` key** — extend mode: parent states are preserved, child adds/overrides
417
+ - **Has `''` key** — replace mode: child defines everything from scratch
418
+
419
+ ```jsx
420
+ // Parent has: fill: { '': '#white', hovered: '#blue', disabled: '#gray' }
421
+
422
+ // Extend — no '' key, parent states preserved
423
+ const MyButton = tasty(Button, {
424
+ styles: {
425
+ fill: {
426
+ loading: '#yellow', // append new state
427
+ disabled: '#gray.20', // override existing state in place
428
+ },
429
+ },
430
+ });
431
+
432
+ // Replace — has '' key, parent states dropped
433
+ const MyButton = tasty(Button, {
434
+ styles: {
435
+ fill: {
436
+ '': '#red',
437
+ hovered: '#blue',
438
+ },
439
+ },
440
+ });
441
+ ```
442
+
443
+ Use `'@inherit'` to pull a parent state value. In extend mode it repositions the state; in replace mode it cherry-picks it:
444
+
445
+ ```jsx
446
+ // Extend mode: reposition disabled to end (highest CSS priority)
447
+ fill: {
448
+ 'loading': '#yellow',
449
+ disabled: '@inherit',
450
+ }
451
+
452
+ // Replace mode: cherry-pick disabled from parent
453
+ fill: {
454
+ '': '#red',
455
+ disabled: '@inherit',
456
+ }
457
+ ```
458
+
459
+ Use `null` inside a state map to remove a state, or `false` to block it entirely (tombstone):
460
+
461
+ ```jsx
462
+ const MyButton = tasty(Button, {
463
+ styles: {
464
+ fill: {
465
+ hovered: null, // removes the parent's hovered state
466
+ disabled: false, // tombstone — no CSS for disabled, blocks recipe too
467
+ },
468
+ },
469
+ });
470
+ ```
471
+
472
+ ### Resetting Properties with `null` and `false`
473
+
474
+ ```jsx
475
+ const SimpleButton = tasty(Button, {
476
+ styles: {
477
+ fill: null, // discard parent's fill, let recipe fill in
478
+ border: false, // no border at all (tombstone — blocks recipe too)
479
+ },
480
+ });
481
+ ```
482
+
483
+ | Value | Meaning | Recipe fills in? |
484
+ | ----------- | ------------------------------------ | ---------------- |
485
+ | `undefined` | Not provided — parent preserved | N/A |
486
+ | `null` | Intentional unset — parent discarded | Yes |
487
+ | `false` | Tombstone — blocks everything | No |
488
+
489
+ ---
490
+
491
+ ## Advanced States (`@` prefix)
492
+
493
+ | Prefix | Purpose | Example |
494
+ | ----------- | ----------------------------------------- | -------------------------- |
495
+ | `@media` | Media queries | `@media(w < 768px)` |
496
+ | `@(...)` | Container queries | `@(panel, w >= 300px)` |
497
+ | `@supports` | Feature/selector support | `@supports(display: grid)` |
498
+ | `@root` | Root element states | `@root(schema=dark)` |
499
+ | `@parent` | Parent/ancestor element states | `@parent(hovered)` |
500
+ | `@own` | Sub-element's own state | `@own(hovered)` |
501
+ | `@starting` | Entry animation | `@starting` |
502
+ | `_` | Fallback floor (always-on, never negated) | `_` |
503
+ | `:is()` | CSS `:is()` structural pseudo-class | `:is(fieldset > label)` |
504
+ | `:has()` | CSS `:has()` relational pseudo-class | `:has(> Icon)` |
505
+ | `:not()` | CSS `:not()` negation (prefer `!:is()`) | `:not(:first-child)` |
506
+ | `:where()` | CSS `:where()` (zero specificity) | `:where(Section)` |
507
+
508
+ > **Specificity.** All state selectors Tasty generates (modifiers, pseudo-classes,
509
+ > `:is()`/`:not()` groups, and `@root` / `@parent` context) are wrapped in
510
+ > `:where(...)` so they carry **zero specificity**. The only specificity anchors
511
+ > are the doubled component class (`.t0.t0`) and sub-element `[data-element]`
512
+ > attributes. This means overlapping rules (e.g. a `_` fallback floor and the
513
+ > states layered over it) resolve purely by **source order** — Tasty emits
514
+ > lower-priority states first and higher-priority states last so the cascade
515
+ > produces the intended winner.
516
+
517
+ ### `@media(...)` — Media Queries
518
+
519
+ Media queries support dimension shorthands:
520
+
521
+ | Shorthand | Expands to |
522
+ | --------- | ---------- |
523
+ | `w` | `width` |
524
+ | `h` | `height` |
525
+
526
+ ```jsx
527
+ fill: {
528
+ '': '#surface',
529
+ '@media(w < 768px)': '#surface-mobile',
530
+ '@media(600px <= w < 1200px)': '#surface-tablet',
531
+ '@media(prefers-color-scheme: dark)': '#surface-dark',
532
+ }
533
+ ```
534
+
535
+ | Tasty syntax | CSS output |
536
+ | ------------------------------------ | ------------------------------------- |
537
+ | `@media(w < 768px)` | `@media (width < 768px)` |
538
+ | `@media(600px <= w < 1200px)` | `@media (600px <= width < 1200px)` |
539
+ | `@media:print` | `@media print` |
540
+ | `@media:screen` | `@media screen` |
541
+ | `@media:all` | `@media all` |
542
+ | `@media:speech` | `@media speech` |
543
+ | `@media(prefers-color-scheme: dark)` | `@media (prefers-color-scheme: dark)` |
544
+ | `@media(prefers-reduced-motion)` | `@media (prefers-reduced-motion)` |
545
+
546
+ Tasty units are not resolved inside query conditions: `@media(w < 40x)` currently emits `calc(var(--gap) * 40)`, which browsers reject in `@media` and `@container`, so neither branch applies. Write query lengths in `px`, `em`, or `rem`.
547
+
548
+ Units are only converted in features that take a length: `width`, `height`, `inline-size`, and `block-size`, with or without `min-`/`max-` (`@media(min-width: 40x)` converts too). Every other feature keeps its value as written, so `@media(min-resolution: 2x)` and `@media(resolution >= 2x)` reach the browser unchanged: there `x` is CSS's own resolution unit, an alias of `dppx`.
549
+
550
+ In practice, define state aliases via `configure({ states })` and use `@mobile` instead of writing the full query in every component.
551
+
552
+ ### `@(...)` — Container Queries
553
+
554
+ Container queries use the syntax `@(name, condition)` for named containers or `@(condition)` for the nearest ancestor container. Dimension shorthands (`w`, `h`, `is`, `bs`) are expanded the same way as `@media`.
555
+
556
+ | Shorthand | Expands to |
557
+ | --------- | ------------- |
558
+ | `w` | `width` |
559
+ | `h` | `height` |
560
+ | `is` | `inline-size` |
561
+ | `bs` | `block-size` |
562
+
563
+ ```jsx
564
+ const Panel = tasty({
565
+ styles: {
566
+ flow: {
567
+ '': 'column',
568
+ '@(layout, w >= 600px)': 'row',
569
+ },
570
+ },
571
+ });
572
+ ```
573
+
574
+ | Tasty syntax | CSS output |
575
+ | ---------------------------------- | -------------------------------------------- |
576
+ | `@(layout, w < 600px)` | `@container layout (width < 600px)` |
577
+ | `@(w < 600px)` | `@container (width < 600px)` |
578
+ | `@(layout, $variant=danger)` | `@container layout style(--variant: danger)` |
579
+ | `@(layout, $compact)` | `@container layout style(--compact)` |
580
+ | `@(scroll-state(stuck: top))` | `@container scroll-state(stuck: top)` |
581
+ | `@(nav, scroll-state(stuck: top))` | `@container nav scroll-state(stuck: top)` |
582
+
583
+ Container style queries use `$prop` (boolean) or `$prop=value` syntax, which maps to CSS `style(--prop)` or `style(--prop: value)`. The value is emitted unquoted, so it matches a custom property set to the identifier `danger`, not the string `"danger"`.
584
+
585
+ ### `@supports(...)` — Feature Queries
586
+
587
+ Feature queries test CSS property support and accept CSS support functions such
588
+ as `at-rule()`. Use `$` as the first argument to test selector support:
589
+
590
+ | Tasty syntax | CSS output |
591
+ | ----------------------------- | ----------------------------------- |
592
+ | `@supports(display: grid)` | `@supports (display: grid)` |
593
+ | `@supports($, :has(*))` | `@supports selector(:has(*))` |
594
+ | `@supports(at-rule(@scope))` | `@supports (at-rule(@scope))` |
595
+ | `!@supports(display: grid)` | `@supports (not (display: grid))` |
596
+ | `!@supports(at-rule(@scope))` | `@supports (not (at-rule(@scope)))` |
597
+
598
+ ```jsx
599
+ display: {
600
+ '': 'flex',
601
+ '@supports(display: grid)': 'grid',
602
+ }
603
+ ```
604
+
605
+ `at-rule()` tests whether the browser supports the named at-rule. Its surrounding
606
+ parentheses in Tasty's CSS output are valid CSS. Negation and combinations with
607
+ other states use the same syntax as property queries:
608
+
609
+ ```jsx
610
+ color: {
611
+ _: 'red',
612
+ '@supports(at-rule(@scope)) & @supports(display: grid)': 'blue',
613
+ }
614
+ ```
615
+
616
+ Use `_` to keep a base value when a browser cannot evaluate a query. A support
617
+ query only detects a browser feature; it does not add an API for authoring the
618
+ queried at-rule in a Tasty style object. For conditional stylesheet imports such
619
+ as `@import url("scoped.css") supports(at-rule(@scope));`, use an ordinary CSS
620
+ stylesheet or document-level `useRawCSS()`. Put imports before other rules in
621
+ that stylesheet. Imports cannot be used in constructable stylesheets, including
622
+ Tasty's adopted-sheet mode for Shadow DOM.
623
+
624
+ ### `_` — Fallback Floor
625
+
626
+ By default Tasty makes states **mutually exclusive**: a higher-priority state
627
+ turns the lower-priority ones off via negation, so exactly one branch applies.
628
+ This relies on `A | !A` always being true. CSS feature/container queries break
629
+ that assumption: `@supports(...)` and `@(...)` queries can be **unknown** (not
630
+ just true/false), and `not(unknown)` is also unknown — so a negated default
631
+ branch silently never applies. The classic case is `scroll-state`: a browser can
632
+ support `container-type: scroll-state` while a specific `scroll-state(...)` query
633
+ is unknown, leaving _no_ branch active.
634
+
635
+ The `_` fallback floor solves this. Use `_` as a **standalone key** and its value
636
+ **always applies** as a guaranteed floor: it never receives negation, and
637
+ higher-priority states simply layer over it via the cascade.
638
+
639
+ ```jsx
640
+ inset: {
641
+ _: '0 top',
642
+ '@supports(container-type: scroll-state) & @(scroll-state(scrolled: block-end))':
643
+ '-80x top',
644
+ }
645
+ ```
646
+
647
+ ```css
648
+ .t0.t0 {
649
+ inset: 0 auto auto auto;
650
+ }
651
+ @supports (container-type: scroll-state) {
652
+ @container scroll-state(scrolled: block-end) {
653
+ .t0.t0 {
654
+ inset: -640px auto auto auto;
655
+ }
656
+ }
657
+ }
658
+ ```
659
+
660
+ The floor is emitted as a bare rule (no negated `@supports` / container branches),
661
+ so it always applies. When the override matches it wins because it is emitted
662
+ later and all state selectors share the same specificity (see the note on
663
+ `:where()` above).
664
+
665
+ Notes:
666
+
667
+ - `_` is a **standalone key only** — it defines a single map-wide floor and
668
+ cannot be combined with state logic. Keys like `_ & hovered` or `_ | focused`
669
+ are ignored with an `INVALID_FALLBACK_KEY` dev warning.
670
+ - `_` can coexist with the bare `''` default when other states exist: `''` is the
671
+ negated default, `_` is the always-on floor. With only `_` and `''` (no other
672
+ states) the `''` default is redundant — Tasty keeps the `_` value and drops
673
+ `''` with a `REDUNDANT_DEFAULT_STATE` warning.
674
+ - `_` is position-independent: it is always placed at the lowest priority
675
+ regardless of where it appears in the map.
676
+
677
+ #### `_` vs the `''` default
678
+
679
+ In simple maps where every other state is a plain modifier (always cleanly
680
+ on/off), `_` and `''` produce the **same visible result** — the base value shows
681
+ whenever no other state wins. They diverge in three situations, and the root
682
+ cause is always the same: **`''` is mutually exclusive (turned off by negation),
683
+ while `_` is always on (layered underneath).**
684
+
685
+ - **Unknown / invalid branches.** If a higher-priority branch sits behind a query
686
+ that can be _unknown_ (`@supports`, container, `scroll-state`) or uses a
687
+ selector the browser drops, the negated `''` default disappears along with it
688
+ (`not(unknown) = unknown`), leaving the property with no rule. The `_` floor
689
+ survives because it is an unconditional bare rule. This is the case `_` exists
690
+ for.
691
+
692
+ - **Empty / "unset" states.** A state can intentionally produce _no_ output (an
693
+ empty value) to leave a property unset while that state is active. With `''`
694
+ this works — the default is negated away and nothing replaces it, so the
695
+ property unsets. With `_` the floor can never be turned off, so its value keeps
696
+ applying and the "unset on this state" intent is lost.
697
+
698
+ ```jsx
699
+ // '' : color unsets while loading. '_' : color stays #text while loading.
700
+ color: { '': '#text', loading: '' }
701
+ ```
702
+
703
+ - **States with different output shapes.** Because `_` layers additively, when
704
+ different states emit _different sets_ of declarations, the floor's
705
+ declarations bleed through wherever the winning state does not override the
706
+ same property — which can produce inconsistent combinations. A `''` default is
707
+ swapped out cleanly by its mutually-exclusive condition.
708
+
709
+ Rule of thumb: **use `''` for the normal default** (clean mutual exclusivity,
710
+ supports unsetting), and reach for `_` only when a value must survive an
711
+ _unknown_ higher-priority branch.
712
+
713
+ ### `@root(...)` — Root Element States
714
+
715
+ Root states generate selectors on the `:root` element. They are useful for theme modes, feature flags, and other page-level conditions:
716
+
717
+ These docs use `data-schema` in examples. If your app standardizes on a different root attribute, keep the same pattern and swap the attribute name consistently in your aliases and selectors.
718
+
719
+ ```jsx
720
+ color: {
721
+ '': '#text',
722
+ '@root(schema=dark)': '#text-on-dark',
723
+ '@root(.premium-user)': '#gold',
724
+ }
725
+ ```
726
+
727
+ | Tasty syntax | CSS selector |
728
+ | ---------------------- | --------------------------------- |
729
+ | `@root(schema=dark)` | `:root[data-schema="dark"]` |
730
+ | `@root(hovered)` | `:root[data-hovered]` |
731
+ | `@root(.premium-user)` | `:root.premium-user` |
732
+ | `@root([lang="en"])` | `:root[lang="en"]` |
733
+ | `!@root(schema=dark)` | `:root:not([data-schema="dark"])` |
734
+
735
+ Root conditions are prepended to the component selector inside `:where()`: `:where(:root[data-schema="dark"]) .t0.t0 { ... }`.
736
+
737
+ ### `@own(...)` — Sub-element's Own State
738
+
739
+ By default, state keys in sub-element styles refer to the root component's state context. Use `@own(...)` when the sub-element should react to its own state:
740
+
741
+ ```jsx
742
+ const Nav = tasty({
743
+ styles: {
744
+ NavItem: {
745
+ color: {
746
+ '': '#text',
747
+ '@own(:hover)': '#primary',
748
+ '@own(:focus-visible)': '#primary',
749
+ selected: '#primary', // root-level modifier
750
+ },
751
+ },
752
+ },
753
+ elements: { NavItem: 'a' },
754
+ });
755
+ ```
756
+
757
+ | Tasty syntax (inside sub-element) | CSS output |
758
+ | --------------------------------- | ------------------------------------------------- |
759
+ | `@own(:hover)` | `:hover` on the sub-element selector |
760
+ | `@own(hovered)` | `[data-hovered]` on the sub-element selector |
761
+ | `@own(theme=dark)` | `[data-theme="dark"]` on the sub-element selector |
762
+
763
+ `@own()` is only valid inside sub-element styles. Using it on root styles emits a warning and is treated as a regular modifier.
764
+
765
+ ### `@starting` — Entry Animation
766
+
767
+ Wraps the rule in `@starting-style`, enabling CSS entry animations for elements as they appear in the DOM:
768
+
769
+ ```jsx
770
+ const FadeIn = tasty({
771
+ styles: {
772
+ opacity: { '': '1', '@starting': '0' },
773
+ transform: { '': 'scale(1)', '@starting': 'scale(0.95)' },
774
+ transition: 'opacity, translate',
775
+ },
776
+ });
777
+ ```
778
+
779
+ | Tasty syntax | CSS output |
780
+ | ------------ | ------------------------------------ |
781
+ | `@starting` | `.t0.t0 { @starting-style { ... } }` |
782
+
783
+ ### `@parent(...)` — Parent Element States
784
+
785
+ Style based on ancestor element attributes. Uses `:where([selector] *)` / `:where(:not([selector] *))` for symmetric, composable parent checks. Boolean logic (`&`, `|`, `!`, `^`) is supported inside `@parent()`.
786
+
787
+ ```jsx
788
+ const Highlight = tasty({
789
+ styles: {
790
+ fill: {
791
+ '': '#white',
792
+ '@parent(hovered)': '#gray.05', // Any ancestor has [data-hovered]
793
+ '@parent(theme=dark, >)': '#dark-02', // Direct parent has [data-theme="dark"]
794
+ },
795
+ },
796
+ });
797
+ ```
798
+
799
+ | Syntax | CSS Output |
800
+ | ------------------------------------- | -------------------------------------------------------------------------- |
801
+ | `@parent(hovered)` | `:where([data-hovered] *)` |
802
+ | `!@parent(hovered)` | `:where(:not([data-hovered] *))` |
803
+ | `@parent(hovered, >)` | `:where([data-hovered] > *)` (direct parent) |
804
+ | `@parent(.active)` | `:where(.active *)` |
805
+ | `@parent(hovered & focused)` | `:where([data-hovered][data-focused] *)` (same ancestor) |
806
+ | `@parent(hovered) & @parent(focused)` | `:where([data-hovered] *):where([data-focused] *)` (independent ancestors) |
807
+ | `@parent(hovered \| focused)` | `:where([data-hovered] *, [data-focused] *)` (OR inside single wrapper) |
808
+
809
+ For sub-elements, the parent check applies to the root element's ancestors:
810
+
811
+ ```jsx
812
+ const Card = tasty({
813
+ styles: {
814
+ Label: {
815
+ color: {
816
+ '': '#text',
817
+ '@parent(hovered)': '#primary',
818
+ },
819
+ },
820
+ },
821
+ });
822
+ // → .t0.t0:where([data-hovered] *) [data-element="Label"]
823
+ ```
824
+
825
+ ### `:is()`, `:has()` — CSS Structural Pseudo-classes
826
+
827
+ Use CSS structural pseudo-classes directly in state keys. Capitalized words become `[data-element="..."]` selectors; lowercase words are HTML tags. A trailing combinator (`>`, `+`, `~`) is auto-completed with `*`. Leading combinators (`> Icon`, `+ Icon`) are relative selectors and are valid only inside `:has()`.
828
+
829
+ `:where()` and `:not()` are also supported but rarely needed — use `:is()` and `!` negation instead.
830
+
831
+ > **Performance warning:** CSS structural pseudo-classes — especially `:has()` — can be costly for the browser to evaluate because they require inspecting the DOM tree beyond the matched element. Tasty already provides a rich, purpose-built state system (`@parent()`, `@own()`, modifiers, boolean logic) that covers the vast majority of use cases without the performance trade-off. **Prefer Tasty's built-in mechanisms and treat `:has()` / `:is()` as a last resort** for conditions that cannot be expressed any other way.
832
+
833
+ ```jsx
834
+ const Card = tasty({
835
+ styles: {
836
+ display: {
837
+ '': 'block',
838
+ ':has(> Icon)': 'grid', // has Icon as direct child
839
+ ':has(+ Icon)': 'grid', // immediately followed by an Icon sibling
840
+ ':has(~ Icon)': 'grid', // has an Icon sibling somewhere after
841
+ ':has(Icon +)': 'grid', // immediately preceded by an Icon sibling (auto-completes to `Icon + *`)
842
+ ':has(Icon ~)': 'grid', // has an Icon sibling somewhere before (auto-completes to `Icon ~ *`)
843
+ ':is(fieldset > label)': 'inline', // is a label inside a fieldset (HTML tags)
844
+ '!:has(> Icon)': 'flex', // negation: no Icon child
845
+ },
846
+ },
847
+ });
848
+ ```
849
+
850
+ | Syntax | CSS Output | Meaning |
851
+ | -------------------- | ------------------------------------- | --------------------------------------- |
852
+ | `:has(> Icon)` | `:has(> [data-element="Icon"])` | Has Icon as direct child |
853
+ | `:has(+ Icon)` | `:has(+ [data-element="Icon"])` | Immediately followed by an Icon sibling |
854
+ | `:has(~ Icon)` | `:has(~ [data-element="Icon"])` | Has an Icon sibling somewhere after |
855
+ | `:has(Icon +)` | `:has([data-element="Icon"] + *)` | Immediately preceded by an Icon sibling |
856
+ | `:has(Icon ~)` | `:has([data-element="Icon"] ~ *)` | Has an Icon sibling somewhere before |
857
+ | `:has(>)` | `:has(> *)` | Has any direct child |
858
+ | `:is(Field + input)` | `:is([data-element="Field"] + input)` | Is an input right after a Field sibling |
859
+ | `:has(button)` | `:has(button)` | HTML tag (lowercase, unchanged) |
860
+ | `!:has(> Icon)` | `:not(:has(> [data-element="Icon"]))` | Negation (use `!`) |
861
+ | `!:is(Panel)` | `:not([data-element="Panel"])` | Negation (use `!:is`) |
862
+
863
+ Combine with other states using boolean logic (`&`, `|`, `!`, `^`):
864
+
865
+ ```jsx
866
+ ':has(> Icon) & hovered'; // AND: structural + data attribute
867
+ '@parent(hovered) & :has(> Icon)'; // AND: parent check + structural
868
+ ':has(> Icon) | :has(> Button)'; // OR: either sub-element present
869
+ ':has(> Icon) ^ :has(> Button)'; // XOR: exactly one present
870
+ ```
871
+
872
+ > **Nesting limit:** The state key parser supports up to 2 levels of nested parentheses inside `:is()`, `:has()`, `:not()`, and `:where()` — e.g. `:has(Input:not(:disabled))` works, but 3+ levels like `:has(:is(:not(:hover)))` will not be tokenized correctly. This covers virtually all practical use cases.
873
+
874
+ ---
875
+
876
+ ## Keyframes
877
+
878
+ Define animations inline using the `@keyframes` key in styles:
879
+
880
+ ```jsx
881
+ const Pulse = tasty({
882
+ styles: {
883
+ animation: 'pulse 2s infinite',
884
+ '@keyframes': {
885
+ pulse: {
886
+ '0%, 100%': { transform: 'scale(1)' },
887
+ '50%': { transform: 'scale(1.05)' },
888
+ },
889
+ },
890
+ },
891
+ });
892
+ ```
893
+
894
+ Keyframes names are case-sensitive and keep their authored case in `animation` and `animationName` (`fadeIn`, not `fadein`), so they match `@keyframes` defined here, in `configure({ keyframes })`, or in plain CSS. Everything else in the value — durations, timing functions, keywords — is parsed as usual.
895
+
896
+ ---
897
+
898
+ ## Properties (`@property`)
899
+
900
+ CSS cannot transition or animate custom properties unless the browser knows their type. Tasty solves this automatically — when you assign a concrete value to a custom property, the type is inferred and a CSS `@property` rule is registered behind the scenes:
901
+
902
+ ```jsx
903
+ const AnimatedGradient = tasty({
904
+ styles: {
905
+ '$gradient-angle': '0deg',
906
+ '#theme': 'okhst(280 80% 50%)',
907
+ image: 'linear-gradient($gradient-angle, #theme, #clear)',
908
+ transition: '$$gradient-angle, ##theme',
909
+ },
910
+ });
911
+ ```
912
+
913
+ Here `$gradient-angle: '0deg'` is detected as `<angle>` and `#theme` as `<color>` (via the `#name` naming convention), so both transitions work without any manual `@property` declarations. Numeric types (`<number>`, `<length>`, `<percentage>`, `<angle>`, `<time>`) are inferred from values; `<color>` is inferred from `#name` tokens.
914
+
915
+ Use explicit `@property` when you need non-default settings like `inherits: false`:
916
+
917
+ ```jsx
918
+ '@property': {
919
+ '$gradient-angle': { syntax: '<angle>', inherits: false, initialValue: '0deg' },
920
+ },
921
+ ```
922
+
923
+ ---
924
+
925
+ ## Font Face (`@font-face`)
926
+
927
+ Register custom fonts directly inside a `styles` object. Keys are font-family names, values are descriptor objects (or arrays of them for multiple weights/styles).
928
+
929
+ ```ts
930
+ const Heading = tasty({
931
+ styles: {
932
+ '@font-face': {
933
+ 'Brand Sans': {
934
+ src: 'url("/fonts/brand-sans.woff2") format("woff2")',
935
+ fontDisplay: 'swap',
936
+ },
937
+ },
938
+ font: '"Brand Sans", sans-serif',
939
+ },
940
+ });
941
+ ```
942
+
943
+ ### Multiple weights
944
+
945
+ Supply an array to register several variants of the same family:
946
+
947
+ ```ts
948
+ '@font-face': {
949
+ 'Brand Sans': [
950
+ { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
951
+ { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
952
+ ],
953
+ }
954
+ ```
955
+
956
+ ### Supported descriptors
957
+
958
+ | Descriptor | CSS property | Type |
959
+ | ----------------------- | ------------------------- | --------------------------------------------------------- |
960
+ | `src` (required) | `src` | `string` |
961
+ | `fontWeight` | `font-weight` | `string \| number` |
962
+ | `fontStyle` | `font-style` | `string` |
963
+ | `fontStretch` | `font-stretch` | `string` |
964
+ | `fontDisplay` | `font-display` | `'auto' \| 'block' \| 'swap' \| 'fallback' \| 'optional'` |
965
+ | `unicodeRange` | `unicode-range` | `string` |
966
+ | `ascentOverride` | `ascent-override` | `string` |
967
+ | `descentOverride` | `descent-override` | `string` |
968
+ | `lineGapOverride` | `line-gap-override` | `string` |
969
+ | `sizeAdjust` | `size-adjust` | `string` |
970
+ | `fontFeatureSettings` | `font-feature-settings` | `string` |
971
+ | `fontVariationSettings` | `font-variation-settings` | `string` |
972
+
973
+ > Font-face rules are permanent — they are injected once and never cleaned up, matching how browsers handle `@font-face`.
974
+
975
+ ---
976
+
977
+ ## Counter Style (`@counter-style`)
978
+
979
+ Define custom list markers via the CSS `@counter-style` at-rule. Keys are counter-style names, values are descriptor objects.
980
+
981
+ ```ts
982
+ const EmojiList = tasty({
983
+ as: 'ol',
984
+ styles: {
985
+ '@counter-style': {
986
+ thumbs: {
987
+ system: 'cyclic',
988
+ symbols: '"👍"',
989
+ suffix: '" "',
990
+ },
991
+ },
992
+ listStyleType: 'thumbs',
993
+ },
994
+ });
995
+ ```
996
+
997
+ ### Supported descriptors
998
+
999
+ | Descriptor | CSS property | Type |
1000
+ | ------------------- | ------------------ | ---------------------------------------------------------------------------------------- |
1001
+ | `system` (required) | `system` | `'cyclic' \| 'numeric' \| 'alphabetic' \| 'symbolic' \| 'additive' \| 'fixed' \| string` |
1002
+ | `symbols` | `symbols` | `string` |
1003
+ | `additiveSymbols` | `additive-symbols` | `string` |
1004
+ | `prefix` | `prefix` | `string` |
1005
+ | `suffix` | `suffix` | `string` |
1006
+ | `negative` | `negative` | `string` |
1007
+ | `range` | `range` | `string` |
1008
+ | `pad` | `pad` | `string` |
1009
+ | `fallback` | `fallback` | `string` |
1010
+ | `speakAs` | `speak-as` | `string` |
1011
+
1012
+ > Counter-style rules are permanent — they are injected once and never cleaned up, matching how browsers handle `@counter-style`.
1013
+
1014
+ ---
1015
+
1016
+ ## Functions (`@function`)
1017
+
1018
+ Define reusable, parameterized CSS [custom functions](https://developer.mozilla.org/en-US/docs/Web/CSS/@function) via the CSS `@function` at-rule. A custom function takes parameters and returns a single value — like a dynamic custom property.
1019
+
1020
+ The token convention follows Tasty's `$` vs `$$` distinction:
1021
+
1022
+ - **`$$name`** — the literal callable name (`--name`). Used for the **definition key** and for **invocation** `$$name(...)`, mirroring the existing `$$gradient-angle` → `--gradient-angle` sugar. The definition key matches the call site.
1023
+ - **`$name`** — a custom-property declaration/reference (`var(--name)`). Used for **parameters** and **local variables**, exactly like declaring custom props in a styles object.
1024
+ - **Local variables** are declared directly as `$name` keys on the descriptor — the body reads like a mini styles object.
1025
+ - `result`, local-variable values, and parameter `default` values flow through the full Tasty DSL, so units (`2x`), color tokens (`#theme`), auto-calc (`(-1 * $value)` → `calc(-1 * var(--value))`), and fallbacks (`($shadow-color, black)` → `var(--shadow-color, black)`) all work.
1026
+
1027
+ ```ts
1028
+ const Box = tasty({
1029
+ styles: {
1030
+ '@function': {
1031
+ // simplest: one bare param + result (auto-calc, no explicit calc())
1032
+ $$negative: { args: ['$value'], result: '(-1 * $value)' },
1033
+
1034
+ // typed param + default + return type + local variable
1035
+ $$shadow: {
1036
+ args: { '$shadow-color': { syntax: '<color>', default: 'inherit' } },
1037
+ returns: '<color>',
1038
+ $offset: '2px', // local variable
1039
+ result: '$offset $offset ($shadow-color, black)',
1040
+ },
1041
+ },
1042
+ margin: '$$negative(10px) top', // → margin: --negative(10px) 0 0 0
1043
+ shadow: '$$shadow(#accent)', // → box-shadow: --shadow(var(--accent-color))
1044
+ },
1045
+ });
1046
+ ```
1047
+
1048
+ Generated CSS:
1049
+
1050
+ ```css
1051
+ @function --negative(--value) {
1052
+ result: calc(-1 * var(--value));
1053
+ }
1054
+ @function --shadow(--shadow-color <color>: inherit) returns <color> {
1055
+ --offset: 2px;
1056
+ result: var(--offset) var(--offset) var(--shadow-color, black);
1057
+ }
1058
+ .t0 {
1059
+ margin: --negative(10px) 0 0 0;
1060
+ box-shadow: --shadow(var(--accent-color));
1061
+ }
1062
+ ```
1063
+
1064
+ ### Descriptor shape
1065
+
1066
+ | Field | Type | Notes |
1067
+ | ------------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------- |
1068
+ | `result` (required) | `string` | The `result:` value, parsed through the Tasty DSL. |
1069
+ | `args` | `string[]` \| `Record<string, FunctionParameter>` | Ordered parameters. Array form lists bare names; object form maps names to type/default. |
1070
+ | `returns` | `string` | Optional return type, e.g. `'<color>'`. |
1071
+ | `$name` keys | `string \| number` | Any `$name` key declares a local variable `--name` (value parsed). |
1072
+
1073
+ A `FunctionParameter` is one of: `true` (bare param), a string CSS type shorthand (`'<length>'`), or `{ syntax?: string; default?: string | number }`.
1074
+
1075
+ Functions can also be registered with the [`useFunction`](react-api.md#usefunction) style function or globally via [`configure({ functions })`](configuration.md#functions) (the same map also accepts bare-key parse functions).
1076
+
1077
+ > `@function` is permanent — injected once and never cleaned up, like `@counter-style`. It is an experimental CSS feature ([Chrome 139+](https://developer.mozilla.org/en-US/docs/Web/CSS/@function)); unsupported browsers safely ignore the native rule, so use it as progressive enhancement — or enable the [`configure({ polyfills: { functions: true } })`](configuration.md#polyfills) inline polyfill to expand `$$name(...)` calls into plain CSS for full cross-browser support.
1078
+
1079
+ ---
1080
+
1081
+ ## Style Properties
1082
+
1083
+ For a complete reference of all enhanced style properties — syntax, values, modifiers, and recommendations — see **[Style Properties Reference](styles.md)**.
1084
+
1085
+ ---
1086
+
1087
+ ## Learn more
1088
+
1089
+ - **[React API](react-api.md)** — `tasty()` factory, component props, variants, sub-elements, style functions
1090
+ - **[Methodology](methodology.md)** — Recommended patterns: root + sub-elements, styleProps, tokens, wrapping
1091
+ - **[Configuration](configuration.md)** — Tokens, recipes, custom units, style handlers, TypeScript extensions
1092
+ - **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
1093
+ - **[Build-Time Extraction (`tastyStatic`)](tasty-static.md)** — Static styling with the Babel plugin