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

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 (309) hide show
  1. package/README.md +397 -185
  2. package/dist/async-storage-DKK-wTD4.js +44 -0
  3. package/dist/async-storage-DKK-wTD4.js.map +1 -0
  4. package/dist/babel-CMYf4JZ2.d.ts +83 -0
  5. package/dist/collector-Ctn5s74s.d.ts +145 -0
  6. package/dist/collector-DMSR6ANK.js +304 -0
  7. package/dist/collector-DMSR6ANK.js.map +1 -0
  8. package/dist/config-B23gZrfP.js +12317 -0
  9. package/dist/config-B23gZrfP.js.map +1 -0
  10. package/dist/config-CZx8_DCu.d.ts +1296 -0
  11. package/dist/context-CA8YKeMn.js +24 -0
  12. package/dist/context-CA8YKeMn.js.map +1 -0
  13. package/dist/core/index.d.ts +5 -33
  14. package/dist/core/index.js +6 -26
  15. package/dist/core-B1tyn69d.js +1573 -0
  16. package/dist/core-B1tyn69d.js.map +1 -0
  17. package/dist/css-writer-CvAxkR6S.js +390 -0
  18. package/dist/css-writer-CvAxkR6S.js.map +1 -0
  19. package/dist/format-global-rules-DklyaXv-.js +22 -0
  20. package/dist/format-global-rules-DklyaXv-.js.map +1 -0
  21. package/dist/format-rules-BCTWVvcS.js +130 -0
  22. package/dist/format-rules-BCTWVvcS.js.map +1 -0
  23. package/dist/hydrate-BCPvkJj3.js +37 -0
  24. package/dist/hydrate-BCPvkJj3.js.map +1 -0
  25. package/dist/index-B3o0aCYV.d.ts +1538 -0
  26. package/dist/index-CsvB0EXZ.d.ts +1909 -0
  27. package/dist/index.d.ts +5 -40
  28. package/dist/index.js +921 -32
  29. package/dist/index.js.map +1 -0
  30. package/dist/keyframes-Dxdx3KOo.js +493 -0
  31. package/dist/keyframes-Dxdx3KOo.js.map +1 -0
  32. package/dist/{utils/merge-styles.js → merge-styles-C-uwpoNW.js} +4 -6
  33. package/dist/merge-styles-C-uwpoNW.js.map +1 -0
  34. package/dist/{utils/merge-styles.d.ts → merge-styles-DJTSfz_M.d.ts} +3 -3
  35. package/dist/{utils/resolve-recipes.js → resolve-recipes-BuOvSEa2.js} +5 -8
  36. package/dist/resolve-recipes-BuOvSEa2.js.map +1 -0
  37. package/dist/ssr/astro-client.d.ts +1 -0
  38. package/dist/ssr/astro-client.js +19 -0
  39. package/dist/ssr/astro-client.js.map +1 -0
  40. package/dist/ssr/astro-middleware-static.d.ts +16 -0
  41. package/dist/ssr/astro-middleware-static.js +18 -0
  42. package/dist/ssr/astro-middleware-static.js.map +1 -0
  43. package/dist/ssr/astro-middleware.d.ts +17 -0
  44. package/dist/ssr/astro-middleware.js +19 -0
  45. package/dist/ssr/astro-middleware.js.map +1 -0
  46. package/dist/ssr/astro.d.ts +93 -0
  47. package/dist/ssr/astro.js +157 -0
  48. package/dist/ssr/astro.js.map +1 -0
  49. package/dist/ssr/index.d.ts +37 -0
  50. package/dist/ssr/index.js +10 -0
  51. package/dist/ssr/index.js.map +1 -0
  52. package/dist/ssr/next.d.ts +45 -0
  53. package/dist/ssr/next.js +74 -0
  54. package/dist/ssr/next.js.map +1 -0
  55. package/dist/static/index.d.ts +91 -5
  56. package/dist/static/index.js +49 -4
  57. package/dist/static/index.js.map +1 -0
  58. package/dist/static/inject.d.ts +5 -0
  59. package/dist/static/inject.js +17 -0
  60. package/dist/static/inject.js.map +1 -0
  61. package/dist/zero/babel.d.ts +2 -108
  62. package/dist/zero/babel.js +235 -39
  63. package/dist/zero/babel.js.map +1 -1
  64. package/dist/zero/index.d.ts +81 -3
  65. package/dist/zero/index.js +2 -4
  66. package/dist/zero/next.d.ts +56 -30
  67. package/dist/zero/next.js +106 -41
  68. package/dist/zero/next.js.map +1 -1
  69. package/docs/README.md +39 -0
  70. package/docs/adoption.md +323 -0
  71. package/docs/ai-agents.md +224 -0
  72. package/docs/comparison.md +448 -0
  73. package/docs/configuration.md +823 -0
  74. package/docs/debug.md +322 -0
  75. package/docs/design-system.md +455 -0
  76. package/docs/dsl.md +1021 -0
  77. package/docs/getting-started.md +238 -0
  78. package/docs/injector.md +614 -0
  79. package/docs/methodology.md +648 -0
  80. package/docs/migration-v3.md +285 -0
  81. package/docs/pipeline.md +741 -0
  82. package/docs/plugins.md +353 -0
  83. package/docs/react-api.md +681 -0
  84. package/docs/runtime-benchmarks.md +216 -0
  85. package/docs/ssr.md +451 -0
  86. package/docs/styles.md +645 -0
  87. package/docs/tasty-static.md +582 -0
  88. package/package.json +149 -40
  89. package/tasty.config.ts +6 -0
  90. package/dist/_virtual/_rolldown/runtime.js +0 -8
  91. package/dist/chunks/cacheKey.js +0 -70
  92. package/dist/chunks/cacheKey.js.map +0 -1
  93. package/dist/chunks/definitions.d.ts +0 -37
  94. package/dist/chunks/definitions.js +0 -260
  95. package/dist/chunks/definitions.js.map +0 -1
  96. package/dist/chunks/renderChunk.js +0 -61
  97. package/dist/chunks/renderChunk.js.map +0 -1
  98. package/dist/config.d.ts +0 -280
  99. package/dist/config.js +0 -403
  100. package/dist/config.js.map +0 -1
  101. package/dist/debug.d.ts +0 -204
  102. package/dist/debug.js +0 -733
  103. package/dist/debug.js.map +0 -1
  104. package/dist/hooks/useGlobalStyles.d.ts +0 -27
  105. package/dist/hooks/useGlobalStyles.js +0 -56
  106. package/dist/hooks/useGlobalStyles.js.map +0 -1
  107. package/dist/hooks/useKeyframes.d.ts +0 -56
  108. package/dist/hooks/useKeyframes.js +0 -54
  109. package/dist/hooks/useKeyframes.js.map +0 -1
  110. package/dist/hooks/useProperty.d.ts +0 -79
  111. package/dist/hooks/useProperty.js +0 -91
  112. package/dist/hooks/useProperty.js.map +0 -1
  113. package/dist/hooks/useRawCSS.d.ts +0 -53
  114. package/dist/hooks/useRawCSS.js +0 -28
  115. package/dist/hooks/useRawCSS.js.map +0 -1
  116. package/dist/hooks/useStyles.d.ts +0 -40
  117. package/dist/hooks/useStyles.js +0 -169
  118. package/dist/hooks/useStyles.js.map +0 -1
  119. package/dist/injector/index.d.ts +0 -157
  120. package/dist/injector/index.js +0 -154
  121. package/dist/injector/index.js.map +0 -1
  122. package/dist/injector/injector.d.ts +0 -139
  123. package/dist/injector/injector.js +0 -404
  124. package/dist/injector/injector.js.map +0 -1
  125. package/dist/injector/sheet-manager.d.ts +0 -127
  126. package/dist/injector/sheet-manager.js +0 -714
  127. package/dist/injector/sheet-manager.js.map +0 -1
  128. package/dist/injector/types.d.ts +0 -135
  129. package/dist/keyframes/index.js +0 -206
  130. package/dist/keyframes/index.js.map +0 -1
  131. package/dist/parser/classify.js +0 -319
  132. package/dist/parser/classify.js.map +0 -1
  133. package/dist/parser/const.js +0 -33
  134. package/dist/parser/const.js.map +0 -1
  135. package/dist/parser/lru.js +0 -109
  136. package/dist/parser/lru.js.map +0 -1
  137. package/dist/parser/parser.d.ts +0 -25
  138. package/dist/parser/parser.js +0 -116
  139. package/dist/parser/parser.js.map +0 -1
  140. package/dist/parser/tokenizer.js +0 -69
  141. package/dist/parser/tokenizer.js.map +0 -1
  142. package/dist/parser/types.d.ts +0 -51
  143. package/dist/parser/types.js +0 -46
  144. package/dist/parser/types.js.map +0 -1
  145. package/dist/pipeline/conditions.d.ts +0 -134
  146. package/dist/pipeline/conditions.js +0 -400
  147. package/dist/pipeline/conditions.js.map +0 -1
  148. package/dist/pipeline/exclusive.js +0 -231
  149. package/dist/pipeline/exclusive.js.map +0 -1
  150. package/dist/pipeline/index.d.ts +0 -53
  151. package/dist/pipeline/index.js +0 -641
  152. package/dist/pipeline/index.js.map +0 -1
  153. package/dist/pipeline/materialize.js +0 -908
  154. package/dist/pipeline/materialize.js.map +0 -1
  155. package/dist/pipeline/parseStateKey.d.ts +0 -15
  156. package/dist/pipeline/parseStateKey.js +0 -430
  157. package/dist/pipeline/parseStateKey.js.map +0 -1
  158. package/dist/pipeline/simplify.js +0 -557
  159. package/dist/pipeline/simplify.js.map +0 -1
  160. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  161. package/dist/plugins/okhsl-plugin.js +0 -371
  162. package/dist/plugins/okhsl-plugin.js.map +0 -1
  163. package/dist/plugins/types.d.ts +0 -69
  164. package/dist/properties/index.js +0 -158
  165. package/dist/properties/index.js.map +0 -1
  166. package/dist/states/index.d.ts +0 -49
  167. package/dist/states/index.js +0 -416
  168. package/dist/states/index.js.map +0 -1
  169. package/dist/static/tastyStatic.d.ts +0 -46
  170. package/dist/static/tastyStatic.js +0 -31
  171. package/dist/static/tastyStatic.js.map +0 -1
  172. package/dist/static/types.d.ts +0 -49
  173. package/dist/static/types.js +0 -24
  174. package/dist/static/types.js.map +0 -1
  175. package/dist/styles/align.d.ts +0 -15
  176. package/dist/styles/align.js +0 -14
  177. package/dist/styles/align.js.map +0 -1
  178. package/dist/styles/border.d.ts +0 -25
  179. package/dist/styles/border.js +0 -114
  180. package/dist/styles/border.js.map +0 -1
  181. package/dist/styles/color.d.ts +0 -14
  182. package/dist/styles/color.js +0 -23
  183. package/dist/styles/color.js.map +0 -1
  184. package/dist/styles/createStyle.js +0 -77
  185. package/dist/styles/createStyle.js.map +0 -1
  186. package/dist/styles/dimension.js +0 -97
  187. package/dist/styles/dimension.js.map +0 -1
  188. package/dist/styles/display.d.ts +0 -37
  189. package/dist/styles/display.js +0 -67
  190. package/dist/styles/display.js.map +0 -1
  191. package/dist/styles/fade.d.ts +0 -15
  192. package/dist/styles/fade.js +0 -58
  193. package/dist/styles/fade.js.map +0 -1
  194. package/dist/styles/fill.d.ts +0 -44
  195. package/dist/styles/fill.js +0 -51
  196. package/dist/styles/fill.js.map +0 -1
  197. package/dist/styles/flow.d.ts +0 -16
  198. package/dist/styles/flow.js +0 -12
  199. package/dist/styles/flow.js.map +0 -1
  200. package/dist/styles/gap.d.ts +0 -31
  201. package/dist/styles/gap.js +0 -37
  202. package/dist/styles/gap.js.map +0 -1
  203. package/dist/styles/height.d.ts +0 -17
  204. package/dist/styles/height.js +0 -20
  205. package/dist/styles/height.js.map +0 -1
  206. package/dist/styles/index.d.ts +0 -2
  207. package/dist/styles/index.js +0 -9
  208. package/dist/styles/index.js.map +0 -1
  209. package/dist/styles/inset.d.ts +0 -52
  210. package/dist/styles/inset.js +0 -150
  211. package/dist/styles/inset.js.map +0 -1
  212. package/dist/styles/justify.d.ts +0 -15
  213. package/dist/styles/justify.js +0 -14
  214. package/dist/styles/justify.js.map +0 -1
  215. package/dist/styles/list.d.ts +0 -16
  216. package/dist/styles/list.js +0 -98
  217. package/dist/styles/list.js.map +0 -1
  218. package/dist/styles/margin.d.ts +0 -24
  219. package/dist/styles/margin.js +0 -104
  220. package/dist/styles/margin.js.map +0 -1
  221. package/dist/styles/outline.d.ts +0 -29
  222. package/dist/styles/outline.js +0 -65
  223. package/dist/styles/outline.js.map +0 -1
  224. package/dist/styles/padding.d.ts +0 -24
  225. package/dist/styles/padding.js +0 -104
  226. package/dist/styles/padding.js.map +0 -1
  227. package/dist/styles/predefined.d.ts +0 -73
  228. package/dist/styles/predefined.js +0 -241
  229. package/dist/styles/predefined.js.map +0 -1
  230. package/dist/styles/preset.d.ts +0 -47
  231. package/dist/styles/preset.js +0 -126
  232. package/dist/styles/preset.js.map +0 -1
  233. package/dist/styles/radius.d.ts +0 -14
  234. package/dist/styles/radius.js +0 -51
  235. package/dist/styles/radius.js.map +0 -1
  236. package/dist/styles/scrollbar.d.ts +0 -21
  237. package/dist/styles/scrollbar.js +0 -105
  238. package/dist/styles/scrollbar.js.map +0 -1
  239. package/dist/styles/shadow.d.ts +0 -14
  240. package/dist/styles/shadow.js +0 -24
  241. package/dist/styles/shadow.js.map +0 -1
  242. package/dist/styles/styledScrollbar.d.ts +0 -47
  243. package/dist/styles/styledScrollbar.js +0 -38
  244. package/dist/styles/styledScrollbar.js.map +0 -1
  245. package/dist/styles/transition.d.ts +0 -14
  246. package/dist/styles/transition.js +0 -158
  247. package/dist/styles/transition.js.map +0 -1
  248. package/dist/styles/types.d.ts +0 -498
  249. package/dist/styles/width.d.ts +0 -17
  250. package/dist/styles/width.js +0 -20
  251. package/dist/styles/width.js.map +0 -1
  252. package/dist/tasty.d.ts +0 -982
  253. package/dist/tasty.js +0 -191
  254. package/dist/tasty.js.map +0 -1
  255. package/dist/tokens/typography.d.ts +0 -19
  256. package/dist/tokens/typography.js +0 -237
  257. package/dist/tokens/typography.js.map +0 -1
  258. package/dist/types.d.ts +0 -184
  259. package/dist/utils/cache-wrapper.js +0 -26
  260. package/dist/utils/cache-wrapper.js.map +0 -1
  261. package/dist/utils/case-converter.js +0 -8
  262. package/dist/utils/case-converter.js.map +0 -1
  263. package/dist/utils/colors.d.ts +0 -5
  264. package/dist/utils/colors.js +0 -9
  265. package/dist/utils/colors.js.map +0 -1
  266. package/dist/utils/css-types.d.ts +0 -7
  267. package/dist/utils/dotize.d.ts +0 -26
  268. package/dist/utils/dotize.js +0 -122
  269. package/dist/utils/dotize.js.map +0 -1
  270. package/dist/utils/filter-base-props.d.ts +0 -15
  271. package/dist/utils/filter-base-props.js +0 -45
  272. package/dist/utils/filter-base-props.js.map +0 -1
  273. package/dist/utils/get-display-name.d.ts +0 -7
  274. package/dist/utils/get-display-name.js +0 -10
  275. package/dist/utils/get-display-name.js.map +0 -1
  276. package/dist/utils/hsl-to-rgb.js +0 -38
  277. package/dist/utils/hsl-to-rgb.js.map +0 -1
  278. package/dist/utils/is-dev-env.js +0 -19
  279. package/dist/utils/is-dev-env.js.map +0 -1
  280. package/dist/utils/is-valid-element-type.js +0 -15
  281. package/dist/utils/is-valid-element-type.js.map +0 -1
  282. package/dist/utils/merge-styles.js.map +0 -1
  283. package/dist/utils/mod-attrs.d.ts +0 -8
  284. package/dist/utils/mod-attrs.js +0 -21
  285. package/dist/utils/mod-attrs.js.map +0 -1
  286. package/dist/utils/okhsl-to-rgb.js +0 -296
  287. package/dist/utils/okhsl-to-rgb.js.map +0 -1
  288. package/dist/utils/process-tokens.d.ts +0 -31
  289. package/dist/utils/process-tokens.js +0 -171
  290. package/dist/utils/process-tokens.js.map +0 -1
  291. package/dist/utils/resolve-recipes.d.ts +0 -17
  292. package/dist/utils/resolve-recipes.js.map +0 -1
  293. package/dist/utils/string.js +0 -8
  294. package/dist/utils/string.js.map +0 -1
  295. package/dist/utils/styles.d.ts +0 -183
  296. package/dist/utils/styles.js +0 -585
  297. package/dist/utils/styles.js.map +0 -1
  298. package/dist/utils/typography.d.ts +0 -36
  299. package/dist/utils/typography.js +0 -53
  300. package/dist/utils/typography.js.map +0 -1
  301. package/dist/utils/warnings.d.ts +0 -16
  302. package/dist/utils/warnings.js +0 -16
  303. package/dist/utils/warnings.js.map +0 -1
  304. package/dist/zero/css-writer.d.ts +0 -45
  305. package/dist/zero/css-writer.js +0 -74
  306. package/dist/zero/css-writer.js.map +0 -1
  307. package/dist/zero/extractor.d.ts +0 -24
  308. package/dist/zero/extractor.js +0 -150
  309. package/dist/zero/extractor.js.map +0 -1
@@ -0,0 +1,823 @@
1
+ # Configuration
2
+
3
+ Tasty works without upfront configuration. Use `configure()` when your app or design system is ready to define shared tokens, state aliases, units, recipes, presets, or extension points.
4
+
5
+ Call it **before any styles are generated** (before first render). For a guided setup, see [Getting Started](getting-started.md). For the higher-level docs map, see the [Docs Hub](README.md).
6
+
7
+ ```jsx
8
+ import { configure } from '@tenphi/tasty';
9
+
10
+ configure({
11
+ // CSP nonce for style elements
12
+ nonce: 'abc123',
13
+
14
+ // Global state aliases
15
+ states: {
16
+ '@mobile': '@media(w < 768px)',
17
+ '@tablet': '@media(768px <= w < 1024px)',
18
+ '@dark': '@root(schema=dark)',
19
+ },
20
+
21
+ // Parser configuration
22
+ parserCacheSize: 2000, // LRU cache size (default: 1000)
23
+
24
+ // Custom units (merged with built-in units)
25
+ units: {
26
+ vh: 'vh',
27
+ vw: 'vw',
28
+ custom: (n) => `${n * 10}px`, // Function-based unit
29
+ },
30
+
31
+ // Custom functions — a single map for both flavors, discriminated by value type:
32
+ functions: {
33
+ // Bare key + function value → parse-time function, called as `double(...)`
34
+ double: (groups) => {
35
+ const value = parseFloat(groups[0]?.output || '0');
36
+ return `${value * 2}px`;
37
+ },
38
+ // `$$name` key + object value → declarative CSS @function, called as `$$negative(...)`
39
+ $$negative: { args: ['$value'], result: '(-1 * $value)' },
40
+ },
41
+ });
42
+ ```
43
+
44
+ These docs use `data-schema="dark"` in examples. If your app already standardizes on a different attribute such as `data-theme`, keep the same pattern and swap the attribute name consistently everywhere you define root-state aliases.
45
+
46
+ ---
47
+
48
+ ## Options
49
+
50
+ | Option | Type | Default | Description |
51
+ | -------------------- | ------------------------------------------------ | ------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
52
+ | `nonce` | `string` | - | CSP nonce for style elements |
53
+ | `maxRulesPerSheet` | `number` | `8192` | Maximum rules per injected stylesheet |
54
+ | `forceTextInjection` | `boolean` | auto (`true` in test envs) | Force text-node CSS injection instead of constructable stylesheets |
55
+ | `devMode` | `boolean` | auto | Enable development-mode features: performance metrics and debug info |
56
+ | `states` | `Record<string, string>` | - | Global state aliases for advanced state mapping |
57
+ | `parserCacheSize` | `number` | `1000` | Parser LRU cache size |
58
+ | `units` | `Record<string, string \| UnitHandler>` | Built-in | Custom units (merged with built-in). See [built-in units](dsl.md#built-in-units) |
59
+ | `functions` | `Record<string, FunctionDefinition \| Function>` | - | Custom functions (merged). Bare keys → parse functions; `$$name` keys → declarative CSS `@function` definitions |
60
+ | `handlers` | `Record<string, StyleHandlerDefinition>` | Built-in | Custom style handlers (replace built-in). See [Custom Style Handlers](#custom-style-handlers) |
61
+ | `propHandlers` | `Record<string, PropHandlerDefinition>` | - | Props middleware for every component — props in, props out. See [Props Middleware](#props-middleware) |
62
+ | `baseStyleProps` | `readonly string[]` | - | Style names exposed as props on **every** component. See [Base Style Props](#base-style-props) |
63
+ | `tokens` | `Record<string, value \| stateMap>` | - | Design tokens injected as `:root` CSS custom properties |
64
+ | `replaceTokens` | `Record<string, string \| number \| boolean>` | - | Parse-time token substitution (inline replacement). `boolean` is allowed for `#` color tokens |
65
+ | `keyframes` | `Record<string, KeyframesSteps>` | - | Global keyframes for animations |
66
+ | `properties` | `Record<string, PropertyDefinition>` | - | Global CSS @property definitions |
67
+ | `fontFaces` | `Record<string, FontFaceInput>` | - | Global @font-face definitions |
68
+ | `counterStyles` | `Record<string, CounterStyleDescriptors>` | - | Global @counter-style definitions |
69
+ | `polyfills` | `{ functions?: boolean }` | `{}` | Opt-in polyfills for not-yet-baseline features. `functions: true` inlines `@function` calls into plain CSS at parse time |
70
+ | `autoPropertyTypes` | `boolean` | `true` | Auto-infer and register `@property` types from values |
71
+ | `recipes` | `Record<string, RecipeStyles>` | - | Predefined style recipes (named style bundles) |
72
+ | `presets` | `Record<string, TypographyPreset>` | - | Typography presets — shorthand for `generateTypographyTokens()` |
73
+ | `globalStyles` | `Record<string, Styles>` | - | Global Tasty styles keyed by CSS selector |
74
+ | `plugins` | `TastyPlugin[]` | - | Plugins that bundle any of the above (processed in order; later override earlier, and direct config wins over all). See [Plugins](plugins.md) |
75
+ | `gc` | `GCConfig` | - | Garbage-collection tuning for unused styles (`{ touchInterval, capacity }`) |
76
+ | `batchInjection` | `boolean \| 'always'` | `false` | Defer stylesheet writes and apply them in one batch. See [Batched injection](#batched-injection) |
77
+ | `colorSpace` | `'rgb' \| 'hsl' \| 'oklch'` | - | **Deprecated** — no longer has any effect. See [Color space](#color-space) |
78
+ | `namePrefix` | `string` | `'t'` (`tasty`) / `'ts'` (build-time) | Prefix prepended to every generated identifier (class, keyframe, counter-style names). Must match `^[a-zA-Z_][a-zA-Z0-9_-]{0,31}$`. See [Name prefix](#name-prefix). |
79
+
80
+ ---
81
+
82
+ ## Batched Injection
83
+
84
+ Every `insertRule()` on a live stylesheet invalidates style for that sheet's
85
+ scope. Components inject during React's render phase, and if anything else reads
86
+ layout in the same pass, the two interleave:
87
+
88
+ ```
89
+ inject -> read (forced style recalc) -> inject -> read (forced recalc) -> ...
90
+ ```
91
+
92
+ A UI kit that measures during render — popovers, autosizing inputs, virtualized
93
+ lists — can turn one mount into a dozen full-tree recalculations. `batchInjection`
94
+ queues the writes instead and applies them together, so the tree is invalidated
95
+ once per flush.
96
+
97
+ ```tsx
98
+ import { configure, TastyBatchProvider } from '@tenphi/tasty';
99
+
100
+ configure({ batchInjection: true });
101
+
102
+ createRoot(el).render(
103
+ <TastyBatchProvider>
104
+ <App />
105
+ </TastyBatchProvider>,
106
+ );
107
+ ```
108
+
109
+ ### Why the provider is required
110
+
111
+ Deferring a write past React's layout phase would let a `useLayoutEffect`
112
+ measure an element whose rules are not in the sheet yet and read its _unstyled_
113
+ box — a wrong number, not a stale one, so it never self-corrects.
114
+
115
+ `TastyBatchProvider` closes that hole. It opens a _batch window_ during its
116
+ render and closes it — flushing — in `useInsertionEffect`, which React runs in
117
+ the mutation phase, before any layout effect:
118
+
119
+ ```
120
+ provider renders -> window OPEN
121
+ children render -> injections queued
122
+ provider insertionEffect -> FLUSH, window CLOSED
123
+ layout effects run -> rules are in the sheet
124
+ ```
125
+
126
+ With `batchInjection: true` a write is only ever queued inside such a window, so
127
+ turning the flag on can make injection cheaper but can never make a measurement
128
+ wrong. Injections outside a window are written straight through, exactly as with
129
+ batching off:
130
+
131
+ - a deep update that did not re-render the provider
132
+ - an injection from a layout effect, an event handler or an async callback
133
+ - SSR and RSC, where there is no live sheet at all
134
+
135
+ Mount the provider as high in the tree as you can: batching applies to the
136
+ commits it takes part in.
137
+
138
+ ### Modes
139
+
140
+ | Value | Behaviour |
141
+ | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
142
+ | `false` (default) | One `insertRule()` per component, synchronously. |
143
+ | `true` | Batch inside a provider window only. Cannot affect measurement. Without the provider nothing is batched, and dev mode says so once. |
144
+ | `'always'` | Batch every injection, flushing on a microtask when no window is open. Covers more commits; a `useLayoutEffect` measuring a freshly mounted element can read its unstyled box. Paint is unaffected — microtasks always drain before the browser paints. |
145
+
146
+ ### Ordering
147
+
148
+ All writes share one FIFO queue — component rules, global rules, raw CSS,
149
+ `@property`, `@keyframes`, `@font-face`, `@counter-style` and `@function`.
150
+ Draining it in insertion order keeps the sheet byte-identical to unbatched
151
+ output, which matters because equal-specificity rules resolve by document order.
152
+
153
+ ### Client rendering, server rendering, and build-time extraction
154
+
155
+ **Server render — nothing to batch, safe to leave enabled.** SSR and RSC collect
156
+ CSS as text through `ServerStyleCollector`; the runtime injector never runs
157
+ there, so `batchInjection` changes nothing either way. `<TastyBatchProvider>`
158
+ renders its children and does nothing else: the window it opens is a no-op
159
+ without a `document`, and the `useInsertionEffect` that would close it never
160
+ fires on the server. Configure the flag once in shared code — no environment
161
+ branching needed.
162
+
163
+ **Hydration — the better your SSR coverage, the less there is to batch.**
164
+ `hydrateTastyClasses()` (wired up for you by `@tenphi/tasty/ssr/next` and the
165
+ Astro integration) pre-populates the injector from `window.__TASTY__`, so
166
+ hydrating a server-rendered class is a cache hit that produces no sheet write at
167
+ all. Batching pays off on what SSR could not cover: client-only routes, styles
168
+ that first appear after hydration (a `styles` prop that changes on interaction, a
169
+ modal or popover mounting), and dynamic tokens.
170
+
171
+ **Astro islands — one provider per island, or `'always'`.** Every island is its
172
+ own React root, so a provider inside one island does not open a window for
173
+ another. With `batchInjection: true`, wrap each island root that renders enough
174
+ tasty components to be worth it. `'always'` needs no provider and covers every
175
+ island, at the cost of the measurement hazard above. Either way, an island that
176
+ only re-hydrates server-rendered classes has nothing to batch.
177
+
178
+ **Build-time extraction (`tastyStatic`) — unaffected.** The Babel plugin never
179
+ touches the injector: the babel plugin emits either a CSS file import or an
180
+ `injectCSS()` call from `@tenphi/tasty/static/inject`, which appends text to a
181
+ single `<style data-tasty-static>` element. `batchInjection` only defers CSSOM
182
+ writes made by the browser injector, so extracted styles are unchanged. In an app
183
+ that mixes both, it still applies to the `tasty()` half.
184
+
185
+ ### `flushStyles()`
186
+
187
+ Applies every pending write immediately. Every injector read API calls it for
188
+ you — `getCSSText`, `getCSSTextForClasses`, `getCSSTextForNode`,
189
+ `getRawCSSText`, `isPropertyDefined`, `getMetrics`, `cleanup`, `gc` and
190
+ `destroy` — so a read never observes a partial sheet.
191
+ Call it directly before measuring in code that runs outside a batch window under
192
+ `'always'`:
193
+
194
+ ```tsx
195
+ import { flushStyles } from '@tenphi/tasty';
196
+
197
+ useLayoutEffect(() => {
198
+ flushStyles();
199
+ const { width } = ref.current.getBoundingClientRect();
200
+ }, []);
201
+ ```
202
+
203
+ `hasPendingStyleWrites()` reports whether anything is queued, and
204
+ `resetStyleBatch()` drops the queue without applying it (tests only).
205
+
206
+ ---
207
+
208
+ ## Color Space
209
+
210
+ > **Deprecated.** `configure({ colorSpace })` no longer has any effect and will
211
+ > be removed in the next major. Setting it warns in development.
212
+
213
+ A `#name` token's value used to be rewritten into a configured color space, so
214
+ `#brand: '#ff8800'` declared `--brand-color: oklch(0.75 0.16 55)`. That existed
215
+ to serve the opacity suffix, which needed numeric channels to write an alpha
216
+ into. Opacity now uses CSS relative color syntax —
217
+ `oklch(from var(--brand-color) l c h / .5)` — which has the browser read the
218
+ channels, so there is nothing left for the setting to decide.
219
+
220
+ A color is emitted exactly as authored:
221
+
222
+ ```jsx
223
+ configure({ tokens: { '#brand': '#ff8800' } });
224
+ // → --brand-color: #ff8800
225
+ ```
226
+
227
+ That holds for every form: a hex literal, a native color function, a bare CSS
228
+ color name, a `color-mix()`, a `light-dark()`, a fallback chain. A `#token`
229
+ reference still resolves to its `var()` chain, and a plugin color function such
230
+ as `okhsl()` is still resolved by the parser to the color it denotes.
231
+
232
+ To address a token's channels, use relative color syntax against the token:
233
+
234
+ ```css
235
+ background: oklch(from var(--brand-color) calc(l * 1.2) c h);
236
+ ```
237
+
238
+ This works on any `<color>`, including the ones no build-time conversion could
239
+ have evaluated — and it is what the [opacity suffix](dsl.md#color-tokens--opacity)
240
+ itself uses. Its space is always `oklch`, which is unbounded, so a wide-gamut
241
+ color survives a round trip a narrower space would clamp.
242
+
243
+ ### Migrating off `colorSpace`
244
+
245
+ Drop the option. If you relied on the uniform output format, nothing in Tasty
246
+ needs it — author your tokens in the space you want them emitted in, since the
247
+ value now passes through untouched:
248
+
249
+ ```jsx
250
+ // before: any input, normalized to the configured space on the way out
251
+ configure({ colorSpace: 'oklch', tokens: { '#brand': '#ff8800' } });
252
+
253
+ // after: author it in the space you want
254
+ configure({ tokens: { '#brand': 'oklch(0.75 0.16 55)' } });
255
+ ```
256
+
257
+ ### Migrating off the channel companions
258
+
259
+ A `#name` token used to declare a second variable beside `--name-color` holding
260
+ its channels decomposed, suffixed with the configured space —
261
+ `--brand-color-oklch: 0.75 0.16 55` — and a `color` style emitted
262
+ `--current-color-{space}` beside `--current-color`. Both are gone, for the same
263
+ reason: they existed so an opacity suffix had channels to write an alpha into.
264
+
265
+ These were never part of the public API, but they were visible in the emitted
266
+ CSS, so hand-authored CSS may reference one. Address the token itself instead:
267
+
268
+ ```css
269
+ /* before */
270
+ color: oklch(var(--brand-color-oklch) / 0.5);
271
+ background: oklch(var(--brand-color-oklch));
272
+
273
+ /* after */
274
+ color: oklch(from var(--brand-color) l c h / 0.5);
275
+ background: var(--brand-color);
276
+ ```
277
+
278
+ The replacement is strictly more capable — the companion could only be
279
+ decomposed for a color the engine could evaluate at build time, while relative
280
+ color syntax works on every `<color>`, including a `color-mix()`, a
281
+ `light-dark()`, and a variable Tasty never defined.
282
+
283
+ ---
284
+
285
+ ## Name Prefix
286
+
287
+ Every identifier Tasty generates — class names, keyframe names, counter-style names — starts with a configurable prefix. The `tasty()` client, SSR, and RSC paths default to `'t'`; the build-time extraction path (`tastyStatic` via the Babel plugin) defaults to `'ts'` so extracted classes can never collide with `tasty()` classes when both are loaded on the same page.
288
+
289
+ ```jsx
290
+ configure({
291
+ namePrefix: 'mb',
292
+ });
293
+ ```
294
+
295
+ The prefix is prepended verbatim to the hash, so include any separator inside the prefix string itself:
296
+
297
+ | Setting | Class | Keyframe | Counter-style |
298
+ | --------------------------- | ------------- | -------------- | -------------- |
299
+ | `'t'` (`tasty` default) | `t1a2b3` | `tk1a2b3` | `tc1a2b3` |
300
+ | `'ts'` (build-time default) | `ts1a2b3` | `tsk1a2b3` | `tsc1a2b3` |
301
+ | `'mb'` | `mb1a2b3` | `mbk1a2b3` | `mbc1a2b3` |
302
+ | `'myapp-'` | `myapp-1a2b3` | `myapp-k1a2b3` | `myapp-c1a2b3` |
303
+
304
+ The single-letter discriminators (`k` for keyframes, `c` for counter-styles) keep the three kinds visually distinct in devtools — they are not required for correctness because CSS keeps these in separate namespaces.
305
+
306
+ ### Rules
307
+
308
+ - Must match `^[a-zA-Z_][a-zA-Z0-9_-]{0,31}$`. Examples that pass: `'t'`, `'ts'`, `'app'`, `'myapp-'`, `'_foo'`. Examples that fail: `''`, `'1foo'`, `'my app'`.
309
+ - Validated at `configure()` time; an invalid prefix throws synchronously rather than silently producing broken hydration.
310
+ - Locked once styles have been generated, like all other config.
311
+
312
+ ### Coexistence with build-time extraction
313
+
314
+ The `tasty()` and `tastyStatic()` paths **must use different prefixes** when both are loaded on the same page. Defaults already guarantee this; if you customize one, customize the other accordingly:
315
+
316
+ ```jsx
317
+ // app config (client / SSR / RSC)
318
+ configure({ namePrefix: 'mb' });
319
+
320
+ // tasty-zero.config.ts (Babel plugin)
321
+ export default { namePrefix: 'mbs' };
322
+ ```
323
+
324
+ If you only use one of the two builds, you only need to set `namePrefix` on that path.
325
+
326
+ ---
327
+
328
+ ## Design Tokens
329
+
330
+ Design tokens define CSS custom properties on `:root`. They are injected automatically when the first style is rendered. Values are parsed through the Tasty DSL, so you can use units, color syntax, and other DSL features.
331
+
332
+ Tokens support state maps for responsive or theme-aware values:
333
+
334
+ ```jsx
335
+ configure({
336
+ tokens: {
337
+ $gap: '4px',
338
+ $radius: '6px',
339
+ '#primary': {
340
+ '': '#purple',
341
+ '@dark': '#light-purple',
342
+ },
343
+ '$font-size': {
344
+ '': '14px',
345
+ '@mobile': '12px',
346
+ },
347
+ },
348
+ });
349
+ ```
350
+
351
+ - `$name` keys become `--name` CSS custom properties
352
+ - `#name` keys become `--name-color` custom properties
353
+ - Names keep their case, since CSS custom properties are case-sensitive: `$myVar` is `--myVar` and is referenced as `$myVar`. A leading capital is not supported and folds — `$Foo` and `#Purple` become `--foo` and `--purple-color` — so start names lowercase. Kebab-case (`$my-var`) remains the convention.
354
+
355
+ Tokens are automatically emitted in all delivery modes: client rendering, server rendering, and build-time extraction with the Babel plugin.
356
+
357
+ ---
358
+
359
+ ## Replace Tokens (Parse-Time Substitution)
360
+
361
+ Replace tokens are **substituted inline at parse time** — they are baked into the generated CSS, not resolved via CSS custom properties at runtime. This makes them ideal for value aliases and shorthand references.
362
+
363
+ Use `$name` for value tokens and `#name` for color token aliases:
364
+
365
+ ```jsx
366
+ configure({
367
+ replaceTokens: {
368
+ $spacing: '2x',
369
+ '$card-padding': '4x',
370
+ '#accent': '#purple',
371
+ '#surface-hover': '#gray.05',
372
+ },
373
+ });
374
+ ```
375
+
376
+ When a component uses `padding: '$card-padding'`, the parser replaces it with `'4x'` before generating CSS. When a component uses `fill: '#accent'`, it is replaced with `'#purple'`, which in turn resolves to `var(--purple-color)`.
377
+
378
+ See [Replace Tokens](dsl.md#replace-tokens) in the Style DSL reference.
379
+
380
+ ---
381
+
382
+ ## Font Face
383
+
384
+ Register custom fonts globally so every component can reference them by family name. Values are descriptor objects or arrays (for multiple weights/styles). Rules are injected eagerly when styles are first generated.
385
+
386
+ ```ts
387
+ configure({
388
+ fontFaces: {
389
+ 'Brand Sans': [
390
+ {
391
+ src: 'url("/fonts/brand-regular.woff2") format("woff2")',
392
+ fontWeight: 400,
393
+ fontDisplay: 'swap',
394
+ },
395
+ {
396
+ src: 'url("/fonts/brand-bold.woff2") format("woff2")',
397
+ fontWeight: 700,
398
+ fontDisplay: 'swap',
399
+ },
400
+ ],
401
+ Icons: {
402
+ src: 'url("/fonts/icons.woff2") format("woff2")',
403
+ fontDisplay: 'block',
404
+ },
405
+ },
406
+ });
407
+ ```
408
+
409
+ Now any component can use `font: '"Brand Sans", sans-serif'` and the browser will already have the `@font-face` rules in the stylesheet.
410
+
411
+ See [Font Face (`@font-face`)](dsl.md#font-face-font-face) for inline usage inside component styles and the full list of supported descriptors.
412
+
413
+ ---
414
+
415
+ ## Counter Style
416
+
417
+ Define custom list-marker algorithms globally. Rules are injected eagerly when styles are first generated.
418
+
419
+ ```ts
420
+ configure({
421
+ counterStyles: {
422
+ thumbs: {
423
+ system: 'cyclic',
424
+ symbols: '"👍"',
425
+ suffix: '" "',
426
+ },
427
+ 'lower-roman-parens': {
428
+ system: 'extends lower-roman',
429
+ suffix: '") "',
430
+ },
431
+ },
432
+ });
433
+ ```
434
+
435
+ Components can then reference `listStyleType: 'thumbs'` directly.
436
+
437
+ See [Counter Style (`@counter-style`)](dsl.md#counter-style-counter-style) for inline usage inside component styles and the full list of supported descriptors.
438
+
439
+ ---
440
+
441
+ ## Functions
442
+
443
+ The single `functions` map holds both kinds of custom functions, discriminated by the value type:
444
+
445
+ - **Parse functions** — a **bare key** with a **function value** `(groups) => string`. Runs at parse time and is called as `name(...)`. Use these for computed/derived CSS that JavaScript produces (e.g. color-space conversions).
446
+ - **CSS `@function` definitions** — a **`$$name` key** with an **object value** (a [`FunctionDefinition`](https://developer.mozilla.org/en-US/docs/Web/CSS/@function)). Injected eagerly as a native `@function` rule and called as `$$name(...)` (→ `--name(...)`).
447
+
448
+ ```ts
449
+ configure({
450
+ functions: {
451
+ // Parse function — bare key, function value
452
+ double: (groups) => `calc(2 * ${groups[0]?.output ?? '0'})`,
453
+
454
+ // CSS @function — `$$` key, object value
455
+ $$negative: { args: ['$value'], result: '(-1 * $value)' },
456
+ $$shadow: {
457
+ args: { '$shadow-color': { syntax: '<color>', default: 'inherit' } },
458
+ returns: '<color>',
459
+ $offset: '2px',
460
+ result: '$offset $offset ($shadow-color, black)',
461
+ },
462
+ },
463
+ });
464
+ ```
465
+
466
+ Components then invoke parse functions as `double(...)` and CSS functions with the `$$name(...)` sugar, e.g. `margin: '$$negative(10px) top'`.
467
+
468
+ > A key whose prefix doesn't match its value type (an object under a bare key, or a function under a `$$` key) is **ignored with a dev-mode warning**.
469
+
470
+ See [Functions (`@function`)](dsl.md#functions-function) for inline usage inside component styles, the full descriptor shape, and token conventions. `@function` is an experimental CSS feature — unsupported browsers safely ignore the native rule (see the polyfill below).
471
+
472
+ ### Custom color functions
473
+
474
+ A parse function whose output is an already-supported color (`rgb`, `hsl`, `#…`, `oklch`, …) is treated as a **color function**: it works everywhere a color is accepted — style values, `#token.alpha` opacity injection, and `parseColor` — with no extra registration. This is the same mechanism the built-in `okhsl`/`okhst` plugins use; they are ordinary plugins registered by default.
475
+
476
+ ```ts
477
+ import { configure, createColorFunc } from '@tenphi/tasty';
478
+
479
+ // A custom color space is just a `functions` entry.
480
+ const myColorPlugin = () => ({
481
+ name: 'mycolor',
482
+ functions: {
483
+ // Hand-written parse function:
484
+ mycolor: (groups) => {
485
+ const [r, g, b] = groups[0].all;
486
+ return `rgb(${r} ${g} ${b})`;
487
+ },
488
+ },
489
+ });
490
+
491
+ configure({ plugins: [myColorPlugin()] });
492
+
493
+ // Now `mycolor(...)` is a color in every context:
494
+ // fill: 'mycolor(255 0 0)'
495
+ // fill: '#brand.5' (with replaceTokens: { '#brand': 'mycolor(255 0 0)' })
496
+ ```
497
+
498
+ For HSL-style color spaces (a hue angle plus two percentages), the exported `createColorFunc(name, convert, label?)` helper handles angle/percentage parsing, clamping, alpha, and caching. `convert` returns sRGB `[r, g, b]` in 0-1; `label` is an optional string used only in dev warnings (e.g. `'H S L'`) and has no effect on output. This is exactly how `okhslPlugin`/`okhstPlugin` are implemented.
499
+
500
+ ---
501
+
502
+ ## Polyfills
503
+
504
+ `@function` only ships natively in Chromium 139+. To use CSS functions in browsers that don't support the at-rule yet (Firefox, Safari), enable the **functions polyfill**, which expands every `$$name(...)` call into plain CSS (`calc()`/`var()`/`color-mix()`) at parse time instead of emitting the native `@function` rule:
505
+
506
+ ```ts
507
+ configure({
508
+ polyfills: {
509
+ functions: true, // default: false
510
+ },
511
+ functions: {
512
+ $$negative: { args: ['$value'], result: '(-1 * $value)' },
513
+ },
514
+ });
515
+
516
+ // Now `margin: '$$negative(10px) top'` renders `margin: calc(-1 * 10px) 0 0 0`
517
+ // — no native @function rule is emitted.
518
+ ```
519
+
520
+ This works across all rendering modes (client, SSR/RSC, and `tastyStatic`) because expansion happens in the parser. Note `polyfills.functions` (the feature toggle) is distinct from the top-level `functions` (the definitions map).
521
+
522
+ **Decided limitations when the polyfill is on:**
523
+
524
+ - **No native fallback** — functions are always inlined; we do exactly what is configured.
525
+ - **Conditional results** (`@media`/`@supports`/`if()` inside `result`) are inlined verbatim; the conditional nuance is not resolved per-element.
526
+ - **Typed params / `returns`** are dropped (inlining is purely lexical substitution).
527
+ - **Param name collisions** are avoided by fully inlining argument values (no function-internal custom properties are emitted) and by namespacing the function's own variables.
528
+ - **Recursion** — self/mutually-recursive functions are not expanded; the cycle guard bails and leaves the call untouched.
529
+
530
+ ---
531
+
532
+ ## Recipes
533
+
534
+ Recipes are predefined, named style bundles. Define them globally via `configure()`:
535
+
536
+ ```jsx
537
+ configure({
538
+ recipes: {
539
+ card: {
540
+ padding: '4x',
541
+ fill: '#surface',
542
+ radius: '1r',
543
+ border: true,
544
+ },
545
+ elevated: {
546
+ shadow: '2x 2x 4x #shadow',
547
+ },
548
+ },
549
+ });
550
+ ```
551
+
552
+ Recipe values are flat tasty styles (no sub-element keys). They may contain base styles, tokens, local states, `@keyframes`, and `@property`. Recipes cannot reference other recipes.
553
+
554
+ For how to apply, compose, and override recipes in components, see [Recipes](dsl.md#recipes) in the Style DSL reference.
555
+
556
+ ---
557
+
558
+ ## Typography Presets
559
+
560
+ Typography presets are a shorthand for `generateTypographyTokens()`. Instead of calling the function manually and spreading the result into `tokens`, pass the presets directly:
561
+
562
+ ```jsx
563
+ configure({
564
+ presets: {
565
+ h1: { fontSize: '32px', lineHeight: '1.2', fontWeight: '700' },
566
+ t2: { fontSize: '16px', lineHeight: '1.5', fontWeight: '400' },
567
+ tag: {
568
+ fontSize: '10px',
569
+ lineHeight: '1.4',
570
+ letterSpacing: '0.04em',
571
+ fontWeight: '600',
572
+ },
573
+ },
574
+ });
575
+ ```
576
+
577
+ Each preset generates `$name-font-size`, `$name-line-height`, `$name-letter-spacing`, `$name-font-weight`, and optional `$name-bold-font-weight`, `$name-icon-size`, `$name-text-transform`, `$name-font-family`, `$name-font-style` tokens.
578
+
579
+ Preset values support state maps for responsive or theme-aware typography:
580
+
581
+ ```jsx
582
+ configure({
583
+ presets: {
584
+ t2: {
585
+ fontSize: '16px',
586
+ lineHeight: '1.5',
587
+ fontWeight: { '': '400', '@dark': '300' },
588
+ },
589
+ },
590
+ });
591
+ ```
592
+
593
+ The generated tokens are merged **under** explicit `tokens` — if both `presets` and `tokens` define `$t2-font-weight`, the `tokens` value wins. Plugins can also provide `presets`; plugin presets are merged first, then config presets, then explicit tokens on top.
594
+
595
+ ---
596
+
597
+ ## Global Styles
598
+
599
+ Apply Tasty styles to any selector via configuration, without needing `useGlobalStyles(selector, ...)` at runtime:
600
+
601
+ ```jsx
602
+ configure({
603
+ globalStyles: {
604
+ body: {
605
+ fill: '#surface',
606
+ color: '#text',
607
+ preset: 't2',
608
+ margin: 0,
609
+ font: 'system-ui, sans-serif',
610
+ },
611
+ html: {
612
+ overflow: 'hidden',
613
+ },
614
+ },
615
+ });
616
+ ```
617
+
618
+ Each key is a CSS selector, and each value is a Tasty `Styles` object supporting the full style syntax including style properties, tokens, state maps, and selector-based sub-styling (e.g. `$: '> .app'` for elements outside React scope). Global styles are injected alongside `:root` tokens when the first style is rendered.
619
+
620
+ Global styles are automatically emitted in all delivery modes: client rendering, server rendering, and build-time extraction with the Babel plugin. Plugins can also provide `globalStyles`; they are merged per selector with config global styles (config wins on conflict).
621
+
622
+ ---
623
+
624
+ ## Auto Property Types
625
+
626
+ CSS cannot transition or animate custom properties unless their type is declared via [`@property`](https://developer.mozilla.org/en-US/docs/Web/CSS/@property). Tasty handles this automatically — when a custom property is assigned a concrete value (e.g. `'$scale': 1`, `'$gap': '10px'`, `'#accent': 'purple'`), the type is inferred and a `@property` rule is registered.
627
+
628
+ This works across all declaration contexts: component styles, `@keyframes`, global config, and build-time extraction with the Babel plugin. It also resolves `var()` chains — if `$a` references `var(--b)`, the type propagates once `--b` is resolved.
629
+
630
+ Supported types:
631
+
632
+ | Detection | Inferred syntax |
633
+ | -------------------------------------- | --------------- |
634
+ | `1`, `0.5`, `-3` (bare numbers) | `<number>` |
635
+ | `10px`, `2rem`, `100vw` (length units) | `<length>` |
636
+ | `50%` | `<percentage>` |
637
+ | `45deg`, `0.5turn` (angle units) | `<angle>` |
638
+ | `300ms`, `1s` (time units) | `<time>` |
639
+ | `#name` tokens (by naming convention) | `<color>` |
640
+
641
+ Auto-inferred properties use `inherits: true` (the CSS default). Use explicit `@property` when you need different settings:
642
+
643
+ ```jsx
644
+ // In component styles
645
+ styles: {
646
+ '@property': {
647
+ '$scale': { syntax: '<number>', inherits: false, initialValue: 1 },
648
+ },
649
+ }
650
+
651
+ // Or globally
652
+ configure({
653
+ properties: {
654
+ '$scale': { syntax: '<number>', inherits: false, initialValue: 1 },
655
+ },
656
+ });
657
+ ```
658
+
659
+ To disable auto-inference entirely (only explicit `@property` will be used):
660
+
661
+ ```jsx
662
+ configure({ autoPropertyTypes: false });
663
+ ```
664
+
665
+ ---
666
+
667
+ ## Custom Style Handlers
668
+
669
+ Override or extend the built-in style property handlers. A handler definition can take three forms:
670
+
671
+ | Form | Syntax | Description |
672
+ | ------------- | ---------------------------------- | --------------------------------------------------------------- |
673
+ | Function only | `handler` | Triggered by its key name; receives only that property |
674
+ | Single dep | `['styleName', handler]` | Triggered by the specified style property |
675
+ | Multi dep | `[['dep1', 'dep2', ...], handler]` | Triggered by any of the listed properties; receives all of them |
676
+
677
+ The multi-dep form is useful when output depends on several style properties together (e.g., `gap` needs to know `display` and `flow` to decide the CSS strategy). Use `defineHandler` for it and the dependency types are inferred from the dependency list, so a typo in the destructure is a type error instead of a silent `undefined`.
678
+
679
+ ```jsx
680
+ import { configure, defineHandler, styleHandlers } from '@tenphi/tasty';
681
+
682
+ configure({
683
+ handlers: {
684
+ // Function only — new single-prop handler
685
+ elevation: ({ elevation }) => {
686
+ const level = parseInt(elevation) || 1;
687
+ return {
688
+ 'box-shadow': `0 ${level * 2}px ${level * 4}px rgba(0,0,0,0.1)`,
689
+ 'z-index': String(level * 100),
690
+ };
691
+ },
692
+
693
+ // Overriding a built-in: declare every style the built-in handled and pass
694
+ // them all through, or the ones you leave out stop working (see below).
695
+ fill: defineHandler(
696
+ [
697
+ 'fill',
698
+ 'backgroundColor',
699
+ 'image',
700
+ 'backgroundImage',
701
+ 'backgroundPosition',
702
+ 'backgroundSize',
703
+ 'backgroundRepeat',
704
+ ],
705
+ (props) => {
706
+ if (
707
+ typeof props.fill === 'string' &&
708
+ props.fill.startsWith('gradient:')
709
+ ) {
710
+ return { background: props.fill.slice(9) };
711
+ }
712
+ return styleHandlers.fill(props);
713
+ },
714
+ ),
715
+
716
+ // Multi dep — handler reads multiple style properties
717
+ gap: defineHandler(['display', 'flow', 'gap'], ({ display, flow, gap }) => {
718
+ if (!gap) return;
719
+ const isGrid = String(display ?? '').includes('grid');
720
+ return { gap: isGrid ? gap : `/* custom logic for ${flow} */` };
721
+ }),
722
+ },
723
+ });
724
+ ```
725
+
726
+ ### Return shape
727
+
728
+ A handler returns a `CSSMap`, an array of them, or nothing:
729
+
730
+ - Keys are **kebab-case** CSS property names (`'background-color'`, not `backgroundColor`) or `--custom-property` names. A camelCase key warns in development and is emitted verbatim, which the browser ignores.
731
+ - Values are stringified, so numbers are fine (`{ '-webkit-line-clamp': 3 }`).
732
+ - The reserved `$` key is a **selector suffix**: `{ $: '& > *:not(:last-child)', 'margin-right': gap }` applies the declarations to a nested selector. It accepts an array to fan out over several.
733
+ - Return an array of maps to emit several declaration sets, each with its own `$`.
734
+
735
+ Values arrive **state-resolved but unparsed** — the raw authored DSL string (`'2x'`, `'#purple.5'`, `true`, `4`). Call the exported `parseStyle()` / `parseColor()` yourself; nothing parses them for you.
736
+
737
+ ### Replacing a built-in handler
738
+
739
+ Built-in handlers are shared across several style names. Registering a handler for one of those names unregisters the built-in from **all** of them, and the displaced names then fall back to auto-generated CSS aliases — so `hide: true` starts emitting a literal `hide: true` declaration. A development-mode warning lists exactly what was displaced.
740
+
741
+ The shared groups worth knowing:
742
+
743
+ | Registering a handler for | Also takes over |
744
+ | ------------------------------ | --------------------------------------------------------------------------------------------------------- |
745
+ | `fill` | `backgroundColor`, `image`, `backgroundImage`, `backgroundPosition`, `backgroundSize`, `backgroundRepeat` |
746
+ | `display` | `hide`, `overflow`, `whiteSpace`, `textOverflow`, `flow`, `gap` |
747
+ | `preset` | `font`, `fontSize`, `fontWeight`, `fontStyle`, `lineHeight`, `letterSpacing`, `textTransform` |
748
+ | `padding` / `margin` / `inset` | their `*Top`/`*Right`/`*Bottom`/`*Left`/`*Block`/`*Inline` longhands |
749
+
750
+ Either declare the whole group and delegate the rest to `styleHandlers.*`, or pick a name that isn't shared.
751
+
752
+ ### Chunk membership
753
+
754
+ Tasty renders and caches CSS in independent chunks, and a chunk's cache key covers only its own style values. All of a handler's dependencies must therefore live in one chunk. Custom style names are pulled into their handler's chunk automatically at registration; a handler whose dependencies span two _built-in_ chunks (say `fill` and `padding`) warns, because it would be invoked once per chunk with a subset of its inputs.
755
+
756
+ `configure({ handlers })` must run before the first render, like every other config option.
757
+
758
+ ---
759
+
760
+ ## Props Middleware
761
+
762
+ `propHandlers` are middleware over a component's props — props in, props out. Where a style _handler_ turns a style property into CSS declarations, a prop handler turns a **component prop** into other props, including `styles`. It is the extension point for props whose value isn't a style value.
763
+
764
+ ```jsx
765
+ import { configure, mergeStyles } from '@tenphi/tasty';
766
+
767
+ configure({
768
+ propHandlers: {
769
+ glaze: (props) => {
770
+ const { glaze, ...rest } = props;
771
+ if (!glaze) return rest;
772
+
773
+ return { ...rest, styles: mergeStyles(glazeStyles(glaze), rest.styles) };
774
+ },
775
+ },
776
+ });
777
+
778
+ <Element glaze="purple" />;
779
+ ```
780
+
781
+ The map key is the handler's name and, by default, the prop that triggers it, so an absent prop costs one property check rather than a call. A tuple overrides that: `['glaze', fn]`, `[['glaze', 'tint'], fn]`, or `['*', fn]` for unconditional.
782
+
783
+ Handlers run at the very top of every component's render, before any prop is destructured, so one can rewrite `styles`, `mods`, `tokens`, `variant`, `as`, `element`, and `qa`. They run in registration order — plugins first, then direct config — each receiving the previous one's output.
784
+
785
+ Handlers must be **pure** and must not mutate their input, and should memoize the styles they build per input value: style values are cached by object identity, so mutating one in place yields stale CSS, and a reference-stable object avoids re-serializing on every render.
786
+
787
+ Injected styles occupy the `styles` slot, so they beat a component's own default styles and lose to a style prop at the call site. Prop handlers do not apply to sub-elements or to build-time `tastyStatic()`, which has no props.
788
+
789
+ See [Plugins → Props middleware](plugins.md#props-middleware) for the full contract and a worked example.
790
+
791
+ ---
792
+
793
+ ## Base Style Props
794
+
795
+ `baseStyleProps` exposes style properties as props on **every** `tasty()` component, on top of the built-in base styles (`display`, `font`, `preset`, `hide`, `whiteSpace`, `opacity`, `transition`):
796
+
797
+ ```jsx
798
+ configure({ baseStyleProps: ['radius', 'shadow'] });
799
+
800
+ <Card radius="1r" shadow />;
801
+ ```
802
+
803
+ `configure()` may run after your components are defined — each factory resolves its prop list lazily.
804
+
805
+ Each name costs one property check per render of every component, and the effect is app-global, so keep the list short and use a factory's own `styleProps` for anything narrower. Avoid names that collide with real DOM or component props (`width`, `size`, `color`), since every component will then swallow them as styles.
806
+
807
+ ---
808
+
809
+ ## Extending Style Types (TypeScript)
810
+
811
+ Use module augmentation to extend the `StylesInterface`:
812
+
813
+ ```tsx
814
+ // tasty.d.ts
815
+ declare module '@tenphi/tasty' {
816
+ interface StylesInterface {
817
+ elevation?: string;
818
+ gradient?: string;
819
+ }
820
+ }
821
+ ```
822
+
823
+ See [Style DSL](dsl.md) for state maps, tokens, units, and extending semantics, and [React API](react-api.md) for `tasty()`, style functions, and component props.