@tenphi/tasty 0.0.0-snapshot.2dc73be → 0.0.0-snapshot.2f5d166

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 (308) hide show
  1. package/README.md +288 -250
  2. package/dist/_virtual/_rolldown/runtime.js +1 -2
  3. package/dist/chunks/cacheKey.d.ts +1 -0
  4. package/dist/chunks/cacheKey.js +17 -10
  5. package/dist/chunks/cacheKey.js.map +1 -1
  6. package/dist/chunks/definitions.d.ts +1 -1
  7. package/dist/chunks/definitions.js +2 -3
  8. package/dist/chunks/definitions.js.map +1 -1
  9. package/dist/chunks/index.d.ts +1 -0
  10. package/dist/chunks/renderChunk.d.ts +1 -0
  11. package/dist/chunks/renderChunk.js +32 -34
  12. package/dist/chunks/renderChunk.js.map +1 -1
  13. package/dist/compute-styles.d.ts +31 -0
  14. package/dist/compute-styles.js +335 -0
  15. package/dist/compute-styles.js.map +1 -0
  16. package/dist/config.d.ts +109 -30
  17. package/dist/config.js +142 -57
  18. package/dist/config.js.map +1 -1
  19. package/dist/core/index.d.ts +12 -11
  20. package/dist/core/index.js +10 -9
  21. package/dist/counter-style/index.js +51 -0
  22. package/dist/counter-style/index.js.map +1 -0
  23. package/dist/debug.d.ts +26 -141
  24. package/dist/debug.js +357 -637
  25. package/dist/debug.js.map +1 -1
  26. package/dist/font-face/index.js +63 -0
  27. package/dist/font-face/index.js.map +1 -0
  28. package/dist/hooks/index.d.ts +7 -0
  29. package/dist/hooks/useCounterStyle.d.ts +52 -0
  30. package/dist/hooks/useCounterStyle.js +43 -0
  31. package/dist/hooks/useCounterStyle.js.map +1 -0
  32. package/dist/hooks/useFontFace.d.ts +45 -0
  33. package/dist/hooks/useFontFace.js +68 -0
  34. package/dist/hooks/useFontFace.js.map +1 -0
  35. package/dist/hooks/useGlobalStyles.d.ts +18 -2
  36. package/dist/hooks/useGlobalStyles.js +50 -46
  37. package/dist/hooks/useGlobalStyles.js.map +1 -1
  38. package/dist/hooks/useKeyframes.d.ts +4 -2
  39. package/dist/hooks/useKeyframes.js +32 -57
  40. package/dist/hooks/useKeyframes.js.map +1 -1
  41. package/dist/hooks/useProperty.d.ts +4 -2
  42. package/dist/hooks/useProperty.js +29 -45
  43. package/dist/hooks/useProperty.js.map +1 -1
  44. package/dist/hooks/useRawCSS.d.ts +8 -44
  45. package/dist/hooks/useRawCSS.js +82 -27
  46. package/dist/hooks/useRawCSS.js.map +1 -1
  47. package/dist/hooks/useStyles.d.ts +4 -9
  48. package/dist/hooks/useStyles.js +7 -226
  49. package/dist/hooks/useStyles.js.map +1 -1
  50. package/dist/index.d.ts +15 -12
  51. package/dist/index.js +13 -10
  52. package/dist/injector/index.d.ts +36 -19
  53. package/dist/injector/index.js +42 -19
  54. package/dist/injector/index.js.map +1 -1
  55. package/dist/injector/injector.d.ts +48 -3
  56. package/dist/injector/injector.js +144 -16
  57. package/dist/injector/injector.js.map +1 -1
  58. package/dist/injector/sheet-manager.d.ts +9 -13
  59. package/dist/injector/sheet-manager.js +39 -70
  60. package/dist/injector/sheet-manager.js.map +1 -1
  61. package/dist/injector/types.d.ts +103 -19
  62. package/dist/keyframes/index.js +1 -1
  63. package/dist/parser/classify.js +6 -6
  64. package/dist/parser/classify.js.map +1 -1
  65. package/dist/parser/const.js +30 -3
  66. package/dist/parser/const.js.map +1 -1
  67. package/dist/parser/lru.js +1 -1
  68. package/dist/parser/lru.js.map +1 -1
  69. package/dist/parser/parser.js +2 -3
  70. package/dist/parser/parser.js.map +1 -1
  71. package/dist/parser/tokenizer.js +1 -1
  72. package/dist/parser/tokenizer.js.map +1 -1
  73. package/dist/parser/types.js +1 -1
  74. package/dist/parser/types.js.map +1 -1
  75. package/dist/pipeline/conditions.js +1 -1
  76. package/dist/pipeline/conditions.js.map +1 -1
  77. package/dist/pipeline/exclusive.js +1 -2
  78. package/dist/pipeline/exclusive.js.map +1 -1
  79. package/dist/pipeline/index.d.ts +3 -1
  80. package/dist/pipeline/index.js +80 -32
  81. package/dist/pipeline/index.js.map +1 -1
  82. package/dist/pipeline/materialize.js +329 -82
  83. package/dist/pipeline/materialize.js.map +1 -1
  84. package/dist/pipeline/parseStateKey.d.ts +1 -1
  85. package/dist/pipeline/parseStateKey.js +3 -8
  86. package/dist/pipeline/parseStateKey.js.map +1 -1
  87. package/dist/pipeline/simplify.js +1 -2
  88. package/dist/pipeline/simplify.js.map +1 -1
  89. package/dist/pipeline/warnings.js +1 -1
  90. package/dist/plugins/index.d.ts +2 -0
  91. package/dist/plugins/okhsl-plugin.js +3 -277
  92. package/dist/plugins/okhsl-plugin.js.map +1 -1
  93. package/dist/plugins/types.d.ts +9 -2
  94. package/dist/properties/index.js +3 -17
  95. package/dist/properties/index.js.map +1 -1
  96. package/dist/properties/property-type-resolver.js +5 -2
  97. package/dist/properties/property-type-resolver.js.map +1 -1
  98. package/dist/rsc-cache.js +70 -0
  99. package/dist/rsc-cache.js.map +1 -0
  100. package/dist/ssr/astro-client.d.ts +1 -0
  101. package/dist/ssr/astro-client.js +24 -0
  102. package/dist/ssr/astro-client.js.map +1 -0
  103. package/dist/ssr/astro-middleware.d.ts +15 -0
  104. package/dist/ssr/astro-middleware.js +19 -0
  105. package/dist/ssr/astro-middleware.js.map +1 -0
  106. package/dist/ssr/astro.d.ts +85 -8
  107. package/dist/ssr/astro.js +111 -22
  108. package/dist/ssr/astro.js.map +1 -1
  109. package/dist/ssr/async-storage.js +1 -2
  110. package/dist/ssr/async-storage.js.map +1 -1
  111. package/dist/ssr/collect-auto-properties.js +29 -11
  112. package/dist/ssr/collect-auto-properties.js.map +1 -1
  113. package/dist/ssr/collector.d.ts +17 -0
  114. package/dist/ssr/collector.js +60 -14
  115. package/dist/ssr/collector.js.map +1 -1
  116. package/dist/ssr/format-global-rules.js +1 -1
  117. package/dist/ssr/format-keyframes.js +1 -2
  118. package/dist/ssr/format-keyframes.js.map +1 -1
  119. package/dist/ssr/format-property.js +10 -9
  120. package/dist/ssr/format-property.js.map +1 -1
  121. package/dist/ssr/format-rules.js +8 -5
  122. package/dist/ssr/format-rules.js.map +1 -1
  123. package/dist/ssr/hydrate.js +1 -2
  124. package/dist/ssr/hydrate.js.map +1 -1
  125. package/dist/ssr/index.d.ts +2 -3
  126. package/dist/ssr/index.js +2 -4
  127. package/dist/ssr/index.js.map +1 -1
  128. package/dist/ssr/next.d.ts +1 -3
  129. package/dist/ssr/next.js +10 -7
  130. package/dist/ssr/next.js.map +1 -1
  131. package/dist/ssr/ssr-collector-ref.js +1 -1
  132. package/dist/states/index.js +13 -259
  133. package/dist/states/index.js.map +1 -1
  134. package/dist/static/index.js +1 -2
  135. package/dist/static/inject.d.ts +5 -0
  136. package/dist/static/inject.js +17 -0
  137. package/dist/static/inject.js.map +1 -0
  138. package/dist/static/tastyStatic.js +1 -2
  139. package/dist/static/tastyStatic.js.map +1 -1
  140. package/dist/static/types.js +1 -1
  141. package/dist/styles/border.d.ts +1 -1
  142. package/dist/styles/border.js +30 -24
  143. package/dist/styles/border.js.map +1 -1
  144. package/dist/styles/color.d.ts +1 -1
  145. package/dist/styles/color.js +11 -8
  146. package/dist/styles/color.js.map +1 -1
  147. package/dist/styles/const.js +17 -0
  148. package/dist/styles/const.js.map +1 -0
  149. package/dist/styles/createStyle.js +28 -26
  150. package/dist/styles/createStyle.js.map +1 -1
  151. package/dist/styles/dimension.js +15 -3
  152. package/dist/styles/dimension.js.map +1 -1
  153. package/dist/styles/directional.js +133 -0
  154. package/dist/styles/directional.js.map +1 -0
  155. package/dist/styles/display.d.ts +3 -10
  156. package/dist/styles/display.js +45 -39
  157. package/dist/styles/display.js.map +1 -1
  158. package/dist/styles/fade.d.ts +1 -1
  159. package/dist/styles/fade.js +9 -5
  160. package/dist/styles/fade.js.map +1 -1
  161. package/dist/styles/fill.d.ts +2 -2
  162. package/dist/styles/fill.js +3 -4
  163. package/dist/styles/fill.js.map +1 -1
  164. package/dist/styles/flow.js +1 -1
  165. package/dist/styles/gap.d.ts +1 -1
  166. package/dist/styles/gap.js +4 -3
  167. package/dist/styles/gap.js.map +1 -1
  168. package/dist/styles/height.d.ts +1 -1
  169. package/dist/styles/height.js +1 -2
  170. package/dist/styles/height.js.map +1 -1
  171. package/dist/styles/index.d.ts +0 -1
  172. package/dist/styles/index.js +3 -4
  173. package/dist/styles/index.js.map +1 -1
  174. package/dist/styles/inset.d.ts +1 -29
  175. package/dist/styles/inset.js +19 -135
  176. package/dist/styles/inset.js.map +1 -1
  177. package/dist/styles/list.d.ts +5 -5
  178. package/dist/styles/list.js +4 -2
  179. package/dist/styles/list.js.map +1 -1
  180. package/dist/styles/margin.d.ts +1 -1
  181. package/dist/styles/margin.js +17 -89
  182. package/dist/styles/margin.js.map +1 -1
  183. package/dist/styles/outline.d.ts +1 -1
  184. package/dist/styles/outline.js +6 -16
  185. package/dist/styles/outline.js.map +1 -1
  186. package/dist/styles/padding.d.ts +1 -1
  187. package/dist/styles/padding.js +17 -89
  188. package/dist/styles/padding.js.map +1 -1
  189. package/dist/styles/placement.d.ts +37 -0
  190. package/dist/styles/placement.js +74 -0
  191. package/dist/styles/placement.js.map +1 -0
  192. package/dist/styles/predefined.d.ts +4 -4
  193. package/dist/styles/predefined.js +9 -10
  194. package/dist/styles/predefined.js.map +1 -1
  195. package/dist/styles/preset.d.ts +6 -1
  196. package/dist/styles/preset.js +54 -53
  197. package/dist/styles/preset.js.map +1 -1
  198. package/dist/styles/radius.d.ts +1 -3
  199. package/dist/styles/radius.js +38 -6
  200. package/dist/styles/radius.js.map +1 -1
  201. package/dist/styles/scrollMargin.d.ts +24 -0
  202. package/dist/styles/scrollMargin.js +32 -0
  203. package/dist/styles/scrollMargin.js.map +1 -0
  204. package/dist/styles/scrollbar.d.ts +1 -1
  205. package/dist/styles/scrollbar.js +8 -5
  206. package/dist/styles/scrollbar.js.map +1 -1
  207. package/dist/styles/shadow.d.ts +1 -1
  208. package/dist/styles/shadow.js +4 -3
  209. package/dist/styles/shadow.js.map +1 -1
  210. package/dist/styles/shared.js +17 -0
  211. package/dist/styles/shared.js.map +1 -0
  212. package/dist/styles/transition.d.ts +1 -1
  213. package/dist/styles/transition.js +5 -4
  214. package/dist/styles/transition.js.map +1 -1
  215. package/dist/styles/types.d.ts +84 -15
  216. package/dist/styles/width.d.ts +1 -1
  217. package/dist/styles/width.js +1 -2
  218. package/dist/styles/width.js.map +1 -1
  219. package/dist/tasty.d.ts +46 -893
  220. package/dist/tasty.js +96 -59
  221. package/dist/tasty.js.map +1 -1
  222. package/dist/types.d.ts +1 -1
  223. package/dist/utils/cache-wrapper.js +4 -9
  224. package/dist/utils/cache-wrapper.js.map +1 -1
  225. package/dist/utils/case-converter.js +1 -1
  226. package/dist/utils/color-math.d.ts +46 -0
  227. package/dist/utils/color-math.js +749 -0
  228. package/dist/utils/color-math.js.map +1 -0
  229. package/dist/utils/color-space.d.ts +5 -0
  230. package/dist/utils/color-space.js +228 -0
  231. package/dist/utils/color-space.js.map +1 -0
  232. package/dist/utils/colors.js +3 -2
  233. package/dist/utils/colors.js.map +1 -1
  234. package/dist/utils/dotize.js +1 -1
  235. package/dist/utils/dotize.js.map +1 -1
  236. package/dist/utils/filter-base-props.d.ts +1 -1
  237. package/dist/utils/filter-base-props.js +1 -1
  238. package/dist/utils/filter-base-props.js.map +1 -1
  239. package/dist/utils/get-display-name.js +1 -1
  240. package/dist/utils/has-keys.js +13 -0
  241. package/dist/utils/has-keys.js.map +1 -0
  242. package/dist/utils/hash.js +14 -0
  243. package/dist/utils/hash.js.map +1 -0
  244. package/dist/utils/is-dev-env.js +1 -1
  245. package/dist/utils/is-dev-env.js.map +1 -1
  246. package/dist/utils/is-valid-element-type.js +1 -1
  247. package/dist/utils/merge-styles.js +1 -2
  248. package/dist/utils/merge-styles.js.map +1 -1
  249. package/dist/utils/mod-attrs.d.ts +0 -2
  250. package/dist/utils/mod-attrs.js +3 -4
  251. package/dist/utils/mod-attrs.js.map +1 -1
  252. package/dist/utils/process-tokens.d.ts +3 -17
  253. package/dist/utils/process-tokens.js +19 -107
  254. package/dist/utils/process-tokens.js.map +1 -1
  255. package/dist/utils/resolve-recipes.js +1 -2
  256. package/dist/utils/resolve-recipes.js.map +1 -1
  257. package/dist/utils/selector-transform.js +1 -1
  258. package/dist/utils/string.js +1 -1
  259. package/dist/utils/styles.d.ts +3 -81
  260. package/dist/utils/styles.js +29 -539
  261. package/dist/utils/styles.js.map +1 -1
  262. package/dist/utils/typography.d.ts +24 -13
  263. package/dist/utils/typography.js +15 -17
  264. package/dist/utils/typography.js.map +1 -1
  265. package/dist/utils/warnings.js +1 -1
  266. package/dist/zero/babel.d.ts +63 -8
  267. package/dist/zero/babel.js +163 -44
  268. package/dist/zero/babel.js.map +1 -1
  269. package/dist/zero/css-writer.js +1 -2
  270. package/dist/zero/css-writer.js.map +1 -1
  271. package/dist/zero/extractor.js +54 -3
  272. package/dist/zero/extractor.js.map +1 -1
  273. package/dist/zero/index.js +1 -2
  274. package/dist/zero/next.d.ts +28 -1
  275. package/dist/zero/next.js +70 -15
  276. package/dist/zero/next.js.map +1 -1
  277. package/docs/PIPELINE.md +519 -0
  278. package/docs/README.md +31 -0
  279. package/docs/adoption.md +296 -0
  280. package/docs/comparison.md +420 -0
  281. package/docs/configuration.md +127 -12
  282. package/docs/debug.md +152 -339
  283. package/docs/design-system.md +424 -0
  284. package/docs/{usage.md → dsl.md} +379 -386
  285. package/docs/getting-started.md +217 -0
  286. package/docs/injector.md +43 -27
  287. package/docs/methodology.md +616 -0
  288. package/docs/runtime.md +575 -0
  289. package/docs/ssr.md +144 -81
  290. package/docs/styles.md +48 -26
  291. package/docs/tasty-static.md +166 -22
  292. package/package.json +27 -12
  293. package/dist/ssr/context.d.ts +0 -8
  294. package/dist/ssr/context.js +0 -14
  295. package/dist/ssr/context.js.map +0 -1
  296. package/dist/styles/align.d.ts +0 -15
  297. package/dist/styles/align.js +0 -14
  298. package/dist/styles/align.js.map +0 -1
  299. package/dist/styles/justify.d.ts +0 -15
  300. package/dist/styles/justify.js +0 -14
  301. package/dist/styles/justify.js.map +0 -1
  302. package/dist/tokens/typography.d.ts +0 -19
  303. package/dist/tokens/typography.js +0 -237
  304. package/dist/tokens/typography.js.map +0 -1
  305. package/dist/utils/hsl-to-rgb.js +0 -38
  306. package/dist/utils/hsl-to-rgb.js.map +0 -1
  307. package/dist/utils/okhsl-to-rgb.js +0 -296
  308. package/dist/utils/okhsl-to-rgb.js.map +0 -1
@@ -0,0 +1,575 @@
1
+ # Runtime API
2
+
3
+ The React-specific `tasty()` component factory, component props, and style functions. All Tasty style functions — `tasty()` components, `useStyles()`, `useGlobalStyles()`, `useRawCSS()`, `useKeyframes()`, `useProperty()`, `useFontFace()`, and `useCounterStyle()` — are hook-free and compatible with React Server Components. No `'use client'` directive needed. For the shared style language (state maps, tokens, units, extending semantics), see [Style DSL](dsl.md). For global configuration, see [Configuration](configuration.md). For the broader docs map, see the [Docs Hub](README.md).
4
+
5
+ ---
6
+
7
+ ## Component Creation
8
+
9
+ ### Create a new component
10
+
11
+ ```jsx
12
+ import { tasty } from '@tenphi/tasty';
13
+
14
+ const Card = tasty({
15
+ as: 'div',
16
+ styles: {
17
+ padding: '4x',
18
+ fill: '#white',
19
+ border: true,
20
+ radius: true,
21
+ },
22
+ styleProps: ['padding', 'fill'],
23
+ });
24
+
25
+ <Card>Hello World</Card>
26
+ <Card padding="6x" fill="#gray.05">Custom Card</Card>
27
+ ```
28
+
29
+ ### Extend an existing component
30
+
31
+ ```jsx
32
+ const PrimaryButton = tasty(Button, {
33
+ styles: {
34
+ fill: '#purple',
35
+ color: '#white',
36
+ padding: '2x 4x',
37
+ },
38
+ });
39
+ ```
40
+
41
+ Style maps merge intelligently — see [Style DSL — Extending vs. Replacing State Maps](dsl.md#extending-vs-replacing-state-maps) for extend mode, replace mode, `@inherit`, `null`, and `false` tombstones.
42
+
43
+ ---
44
+
45
+ ## Style Props
46
+
47
+ Use `styleProps` to expose style properties as direct component props:
48
+
49
+ ```jsx
50
+ const FlexibleBox = tasty({
51
+ as: 'div',
52
+ styles: {
53
+ display: 'flex',
54
+ padding: '2x',
55
+ },
56
+ styleProps: ['gap', 'align', 'placeContent', 'fill'],
57
+ });
58
+
59
+ <FlexibleBox gap="2x" align="center" fill="#surface">
60
+ Content
61
+ </FlexibleBox>
62
+ ```
63
+
64
+ Style props accept state maps, so responsive values work through the same API:
65
+
66
+ ```jsx
67
+ <FlexibleBox
68
+ gap={{ '': '2x', '@tablet': '4x' }}
69
+ fill={{ '': '#surface', '@dark': '#surface-dark' }}
70
+ >
71
+ ```
72
+
73
+ For predefined style prop lists (`FLOW_STYLES`, `POSITION_STYLES`, `DIMENSION_STYLES`, etc.) and guidance on which props to expose per component category, see [Methodology — styleProps as the public API](methodology.md#styleprops-as-the-public-api).
74
+
75
+ ---
76
+
77
+ ## Mod Props
78
+
79
+ Use `modProps` to expose modifier keys as direct component props instead of requiring the `mods` object:
80
+
81
+ ```jsx
82
+ // Before: mods object
83
+ <Button mods={{ isLoading: true, size: 'large' }}>Submit</Button>
84
+
85
+ // After: mod props
86
+ <Button isLoading size="large">Submit</Button>
87
+ ```
88
+
89
+ ### Array form
90
+
91
+ List modifier key names. Types default to `ModValue` (`boolean | string | number | undefined | null`):
92
+
93
+ ```jsx
94
+ const Button = tasty({
95
+ modProps: ['isLoading', 'isSelected'] as const,
96
+ styles: {
97
+ fill: { '': '#surface', isLoading: '#surface.5' },
98
+ border: { '': '1bw solid #outline', isSelected: '2bw solid #primary' },
99
+ },
100
+ });
101
+
102
+ <Button isLoading isSelected>Submit</Button>
103
+ // Renders: <button data-is-loading="" data-is-selected="">Submit</button>
104
+ ```
105
+
106
+ ### Object form (typed)
107
+
108
+ Map modifier names to type descriptors for precise TypeScript types:
109
+
110
+ ```tsx
111
+ const Button = tasty({
112
+ modProps: {
113
+ isLoading: Boolean, // isLoading?: boolean
114
+ isSelected: Boolean, // isSelected?: boolean
115
+ size: ['small', 'medium', 'large'] as const, // size?: 'small' | 'medium' | 'large'
116
+ },
117
+ styles: {
118
+ padding: { '': '2x 4x', 'size=small': '1x 2x', 'size=large': '3x 6x' },
119
+ fill: { '': '#surface', isLoading: '#surface.5' },
120
+ },
121
+ });
122
+
123
+ <Button isLoading size="large">Submit</Button>
124
+ // Renders: <button data-is-loading="" data-size="large">Submit</button>
125
+ ```
126
+
127
+ Available type descriptors:
128
+
129
+ | Descriptor | TypeScript type | Example |
130
+ |---|---|---|
131
+ | `Boolean` | `boolean` | `isLoading: Boolean` |
132
+ | `String` | `string` | `label: String` |
133
+ | `Number` | `number` | `count: Number` |
134
+ | `['a', 'b'] as const` | `'a' \| 'b'` | `size: ['sm', 'md', 'lg'] as const` |
135
+
136
+ ### Merge with `mods`
137
+
138
+ Mod props and the `mods` object can be used together. Mod props take precedence:
139
+
140
+ ```jsx
141
+ <Button mods={{ isLoading: false, extra: true }} isLoading>
142
+ // isLoading=true wins (from mod prop), extra=true preserved from mods
143
+ ```
144
+
145
+ ### When to use `modProps` vs `mods`
146
+
147
+ | Use case | Recommendation |
148
+ |---|---|
149
+ | Component has a fixed set of known modifiers | `modProps` — cleaner API, better TypeScript autocomplete |
150
+ | Component needs arbitrary/dynamic modifiers | `mods` — open-ended `Record<string, ModValue>` |
151
+ | Both fixed and dynamic | Combine: `modProps` for known keys, `mods` for ad-hoc |
152
+
153
+ For architecture guidance on when to use modifiers vs `styleProps`, see [Methodology — modProps and mods](methodology.md#modprops-and-mods).
154
+
155
+ ---
156
+
157
+ ## Token Props
158
+
159
+ Use `tokenProps` to expose token keys as direct component props instead of requiring the `tokens` object:
160
+
161
+ ```jsx
162
+ // Before: tokens object
163
+ <ProgressBar tokens={{ $progress: '75%', '#accent': '#purple' }} />
164
+
165
+ // After: token props
166
+ <ProgressBar progress="75%" accentColor="#purple" />
167
+ ```
168
+
169
+ ### Array form
170
+
171
+ List prop names. Names ending in `Color` map to `#` color tokens; everything else maps to `$` custom property tokens:
172
+
173
+ ```jsx
174
+ const ProgressBar = tasty({
175
+ tokenProps: ['progress', 'accentColor'] as const,
176
+ styles: { width: '$progress', fill: '#accent' },
177
+ });
178
+
179
+ <ProgressBar progress="75%" accentColor="#purple" />
180
+ // 'progress' → $progress → --progress
181
+ // 'accentColor' → #accent → --accent-color + --accent-color-oklch
182
+ ```
183
+
184
+ ### Object form
185
+
186
+ Map prop names to explicit `$`/`#`-prefixed token keys:
187
+
188
+ ```tsx
189
+ const Card = tasty({
190
+ tokenProps: {
191
+ size: '$card-size',
192
+ color: '#card-accent',
193
+ },
194
+ styles: { padding: '$card-size', fill: '#card-accent' },
195
+ });
196
+
197
+ <Card size="4x" color="#purple" />
198
+ ```
199
+
200
+ ### Merge with `tokens`
201
+
202
+ Token props and the `tokens` prop can be used together. Token props take precedence over `tokens`, which takes precedence over default `tokens` in `tasty({...})`:
203
+
204
+ ```jsx
205
+ const Bar = tasty({
206
+ tokenProps: ['progress'] as const,
207
+ tokens: { $progress: '0%' }, // default
208
+ });
209
+
210
+ <Bar tokens={{ $progress: '50%' }} progress="90%" />
211
+ // progress="90%" wins (from token prop)
212
+ ```
213
+
214
+ ### When to use `tokenProps` vs `tokens`
215
+
216
+ | Use case | Recommendation |
217
+ |---|---|
218
+ | Component has a fixed set of known token keys | `tokenProps` — cleaner API, better TypeScript autocomplete |
219
+ | Component needs arbitrary/dynamic token values | `tokens` — open-ended `Record<string, TokenValue>` |
220
+ | Both fixed and dynamic | Combine: `tokenProps` for known keys, `tokens` for ad-hoc |
221
+
222
+ For architecture guidance, see [Methodology — tokenProps](methodology.md#tokenprops).
223
+
224
+ ---
225
+
226
+ ## Variants
227
+
228
+ Define named style variations. Only CSS for variants actually used at runtime is injected:
229
+
230
+ ```jsx
231
+ const Button = tasty({
232
+ styles: {
233
+ padding: '2x 4x',
234
+ border: true,
235
+ },
236
+ variants: {
237
+ default: { fill: '#blue', color: '#white' },
238
+ danger: { fill: '#red', color: '#white' },
239
+ outline: { fill: 'transparent', color: '#blue', border: '1bw solid #blue' },
240
+ },
241
+ });
242
+
243
+ <Button variant="danger">Delete</Button>
244
+ ```
245
+
246
+ ### Extending Variants with Base State Maps
247
+
248
+ When base `styles` contain an extend-mode state map (an object **without** a `''` key), it is applied **after** the variant merge. This lets you add or override states across all variants without repeating yourself:
249
+
250
+ ```jsx
251
+ const Badge = tasty({
252
+ styles: {
253
+ padding: '1x 2x',
254
+ border: {
255
+ 'type=primary': '#clear',
256
+ },
257
+ },
258
+ variants: {
259
+ primary: {
260
+ border: { '': '#white.2', pressed: '#primary-text', disabled: '#clear' },
261
+ fill: { '': '#white #primary', hovered: '#white #primary-text' },
262
+ },
263
+ secondary: {
264
+ border: { '': '#primary.15', pressed: '#primary.3' },
265
+ fill: '#primary.10',
266
+ },
267
+ },
268
+ });
269
+
270
+ // Both variants get 'type=primary': '#clear' appended to their border map
271
+ ```
272
+
273
+ Properties that are **not** extend-mode (simple values, state maps with `''`, `null`, `false`, selectors, sub-elements) merge with variants as before — the variant can fully replace them.
274
+
275
+ ---
276
+
277
+ ## Sub-element Styling
278
+
279
+ Sub-elements are inner parts of a compound component, styled via capitalized keys in `styles` and identified by `data-element` attributes in the DOM.
280
+
281
+ > Use the `elements` prop to declare sub-element components. This gives you typed, reusable sub-components (`Card.Title`, `Card.Content`) instead of manually writing `data-element` attributes.
282
+
283
+ ```jsx
284
+ const Card = tasty({
285
+ styles: {
286
+ padding: '4x',
287
+ Title: { preset: 'h3', color: '#primary' },
288
+ Content: { color: '#text' },
289
+ },
290
+ elements: {
291
+ Title: 'h3',
292
+ Content: 'div',
293
+ },
294
+ });
295
+
296
+ <Card>
297
+ <Card.Title>Card Title</Card.Title>
298
+ <Card.Content>Card content</Card.Content>
299
+ </Card>
300
+ ```
301
+
302
+ Each entry in `elements` can be a tag name string or a config object:
303
+
304
+ ```jsx
305
+ elements: {
306
+ Title: 'h3', // shorthand: tag name only
307
+ Icon: { as: 'span', qa: 'card-icon' }, // full form: tag + QA attribute
308
+ }
309
+ ```
310
+
311
+ The sub-components produced by `elements` support `mods`, `tokens`, `isDisabled`, `isHidden`, and `isChecked` props — the same modifier interface as the root component.
312
+
313
+ If you don't need sub-components (e.g., the inner elements are already rendered by a third-party library), you can still style them by key alone — just omit `elements` and apply `data-element` manually:
314
+
315
+ ```jsx
316
+ const Card = tasty({
317
+ styles: {
318
+ padding: '4x',
319
+ Title: { preset: 'h3', color: '#primary' },
320
+ },
321
+ });
322
+
323
+ <Card>
324
+ <div data-element="Title">Card Title</div>
325
+ </Card>
326
+ ```
327
+
328
+ ### Selector Affix (`$`)
329
+
330
+ The `$` property inside a sub-element's styles controls how its selector attaches to the root selector — combinators, HTML tags, pseudo-elements, the `@` placeholder, and more. For the full reference table and injection rules, see [DSL — Selector Affix](dsl.md#selector-affix-).
331
+
332
+ For the mental model behind sub-elements — how they share root state context and how this differs from BEM — see [Methodology — Component architecture](methodology.md#component-architecture-root--sub-elements).
333
+
334
+ ---
335
+
336
+ ## computeStyles
337
+
338
+ Hook-free, synchronous style computation. Can be used anywhere — including React Server Components, plain functions, and non-React code:
339
+
340
+ ```tsx
341
+ import { computeStyles } from '@tenphi/tasty';
342
+
343
+ const { className } = computeStyles({
344
+ padding: '2x',
345
+ fill: '#surface',
346
+ radius: '1r',
347
+ });
348
+ ```
349
+
350
+ On the client, CSS is injected synchronously into the DOM (idempotent via the injector cache). On the server, CSS is collected via the SSR collector if one is available. This is the same function that `tasty()` components use internally.
351
+
352
+ ---
353
+
354
+ ## Style Functions
355
+
356
+ All style functions below are plain functions (not React hooks) and can be used in any environment: client components, SSR with a `ServerStyleCollector`, and React Server Components. They retain their `use` prefix for backward compatibility, but do not use any React hooks internally.
357
+
358
+ ### useStyles
359
+
360
+ Generate a className from a style object. Thin wrapper around `computeStyles()`:
361
+
362
+ ```tsx
363
+ import { useStyles } from '@tenphi/tasty';
364
+
365
+ function MyComponent() {
366
+ const { className } = useStyles({
367
+ padding: '2x',
368
+ fill: '#surface',
369
+ radius: '1r',
370
+ });
371
+
372
+ return <div className={className}>Styled content</div>;
373
+ }
374
+ ```
375
+
376
+ ### useGlobalStyles
377
+
378
+ Inject global styles for a CSS selector. Accepts an optional third argument with an `id` for update tracking — when the styles change, the previous injection is disposed and the new one is injected:
379
+
380
+ ```tsx
381
+ import { useGlobalStyles } from '@tenphi/tasty';
382
+
383
+ function ThemeStyles() {
384
+ useGlobalStyles('.card', {
385
+ padding: '4x',
386
+ fill: '#surface',
387
+ radius: '1r',
388
+ });
389
+
390
+ return null;
391
+ }
392
+ ```
393
+
394
+ ### useRawCSS
395
+
396
+ Inject raw CSS strings. Accepts an optional `id` in the options for update tracking — when the CSS changes for the same id, the previous injection is replaced:
397
+
398
+ ```tsx
399
+ import { useRawCSS } from '@tenphi/tasty';
400
+
401
+ function GlobalReset() {
402
+ useRawCSS(`
403
+ body { margin: 0; padding: 0; }
404
+ `);
405
+
406
+ return null;
407
+ }
408
+ ```
409
+
410
+ ### useKeyframes
411
+
412
+ Inject `@keyframes` rules and return the generated animation name:
413
+
414
+ ```tsx
415
+ import { useKeyframes } from '@tenphi/tasty';
416
+
417
+ function Spinner() {
418
+ const spin = useKeyframes(
419
+ {
420
+ from: { transform: 'rotate(0deg)' },
421
+ to: { transform: 'rotate(360deg)' },
422
+ },
423
+ { name: 'spin' }
424
+ );
425
+
426
+ return <div style={{ animation: `${spin} 1s linear infinite` }} />;
427
+ }
428
+ ```
429
+
430
+ `useKeyframes()` also supports a factory function. The deps array is accepted for backward compatibility but the factory is called on every invocation — deduplication is handled internally by content hash:
431
+
432
+ ```tsx
433
+ function Pulse({ scale }: { scale: number }) {
434
+ const pulse = useKeyframes(
435
+ () => ({
436
+ '0%': { transform: 'scale(1)' },
437
+ '100%': { transform: `scale(${scale})` },
438
+ }),
439
+ [scale]
440
+ );
441
+
442
+ return <div style={{ animation: `${pulse} 500ms ease-in-out alternate infinite` }} />;
443
+ }
444
+ ```
445
+
446
+ ### useProperty
447
+
448
+ Register a CSS `@property` rule so a custom property can animate smoothly:
449
+
450
+ ```tsx
451
+ import { useProperty } from '@tenphi/tasty';
452
+
453
+ function Spinner() {
454
+ useProperty('$rotation', {
455
+ syntax: '<angle>',
456
+ inherits: false,
457
+ initialValue: '0deg',
458
+ });
459
+
460
+ return <div style={{ transform: 'rotate(var(--rotation))' }} />;
461
+ }
462
+ ```
463
+
464
+ `useProperty()` accepts Tasty token syntax for the property name:
465
+
466
+ - `$name` defines `--name`
467
+ - `#name` defines `--name-color` and auto-infers `<color>`
468
+ - `--name` is also supported for existing CSS variables
469
+
470
+ ### useFontFace
471
+
472
+ Inject `@font-face` rules for custom fonts. Permanent — no cleanup on unmount. Deduplicates by content.
473
+
474
+ ```tsx
475
+ import { useFontFace } from '@tenphi/tasty';
476
+
477
+ function App() {
478
+ useFontFace('Brand Sans', {
479
+ src: 'url("/fonts/brand-sans.woff2") format("woff2")',
480
+ fontWeight: '400 700',
481
+ fontDisplay: 'swap',
482
+ });
483
+
484
+ return <div style={{ fontFamily: '"Brand Sans", sans-serif' }}>Hello</div>;
485
+ }
486
+ ```
487
+
488
+ For multiple weights/styles, pass an array:
489
+
490
+ ```tsx
491
+ useFontFace('Brand Sans', [
492
+ { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
493
+ { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
494
+ ]);
495
+ ```
496
+
497
+ Signature:
498
+
499
+ ```ts
500
+ function useFontFace(family: string, input: FontFaceInput): void;
501
+ ```
502
+
503
+ ### useCounterStyle
504
+
505
+ Inject a `@counter-style` rule and get back the counter style name. Permanent — no cleanup on unmount. Deduplicates by name.
506
+
507
+ ```tsx
508
+ import { useCounterStyle } from '@tenphi/tasty';
509
+
510
+ function EmojiList() {
511
+ const styleName = useCounterStyle({
512
+ system: 'cyclic',
513
+ symbols: '"👍"',
514
+ suffix: '" "',
515
+ }, { name: 'thumbs' });
516
+
517
+ return (
518
+ <ol style={{ listStyleType: styleName }}>
519
+ <li>First</li>
520
+ <li>Second</li>
521
+ </ol>
522
+ );
523
+ }
524
+ ```
525
+
526
+ Factory form with dependencies:
527
+
528
+ ```tsx
529
+ function DynamicList({ marker }: { marker: string }) {
530
+ const styleName = useCounterStyle(
531
+ () => ({
532
+ system: 'cyclic',
533
+ symbols: `"${marker}"`,
534
+ suffix: '" "',
535
+ }),
536
+ [marker],
537
+ );
538
+
539
+ return <ol style={{ listStyleType: styleName }}>...</ol>;
540
+ }
541
+ ```
542
+
543
+ Signatures:
544
+
545
+ ```ts
546
+ function useCounterStyle(
547
+ descriptors: CounterStyleDescriptors,
548
+ options?: { name?: string; root?: Document | ShadowRoot },
549
+ ): string;
550
+
551
+ function useCounterStyle(
552
+ factory: () => CounterStyleDescriptors,
553
+ deps: readonly unknown[],
554
+ options?: { name?: string; root?: Document | ShadowRoot },
555
+ ): string;
556
+ ```
557
+
558
+ ### Troubleshooting
559
+
560
+ - Styles are not updating: make sure `configure()` runs before first render, and verify the generated class name or global rule with [Debug Utilities](debug.md).
561
+ - SSR output looks wrong: check the [SSR guide](ssr.md) for collector setup. All style functions discover the SSR collector via `AsyncLocalStorage` or the global getter registered by `TastyRegistry`.
562
+ - Animation/custom property issues: prefer `useKeyframes()` and `useProperty()` over raw CSS when you want Tasty to manage injection and SSR collection for you.
563
+ - For dynamic styles that change over the component lifecycle, use the `id` option in `useGlobalStyles()` and `useRawCSS()` to enable update tracking.
564
+
565
+ ---
566
+
567
+ ## Learn more
568
+
569
+ - **[Style DSL](dsl.md)** — State maps, tokens, units, extending semantics, keyframes, @property
570
+ - **[Methodology](methodology.md)** — Recommended patterns: root + sub-elements, styleProps, tokens, wrapping
571
+ - **[Configuration](configuration.md)** — Tokens, recipes, custom units, style handlers, TypeScript extensions
572
+ - **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
573
+ - **[Zero Runtime (tastyStatic)](tasty-static.md)** — Build-time static styling with Babel plugin
574
+ - **[Server-Side Rendering](ssr.md)** — SSR setup for Next.js, Astro, and generic frameworks
575
+ - **[Debug Utilities](debug.md)** — Inspect injected CSS, cache state, and active styles at runtime