@tenphi/tasty 0.0.0-snapshot.c8bdaeb → 0.0.0-snapshot.cb232f9

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 (303) hide show
  1. package/README.md +314 -159
  2. package/dist/async-storage-B7_o6FKt.js +44 -0
  3. package/dist/async-storage-B7_o6FKt.js.map +1 -0
  4. package/dist/collector-BQHl-atL.d.ts +108 -0
  5. package/dist/collector-DROCOiaT.js +243 -0
  6. package/dist/collector-DROCOiaT.js.map +1 -0
  7. package/dist/config-CzzTHmtS.d.ts +928 -0
  8. package/dist/config-JokB1Lc8.js +10351 -0
  9. package/dist/config-JokB1Lc8.js.map +1 -0
  10. package/dist/context-CkSg-kDT.js +24 -0
  11. package/dist/context-CkSg-kDT.js.map +1 -0
  12. package/dist/core/index.d.ts +5 -33
  13. package/dist/core/index.js +6 -26
  14. package/dist/core-CW4XEUFk.js +1598 -0
  15. package/dist/core-CW4XEUFk.js.map +1 -0
  16. package/dist/css-writer-Jv468wSl.js +351 -0
  17. package/dist/css-writer-Jv468wSl.js.map +1 -0
  18. package/dist/format-global-rules-Dbc_1tc3.js +22 -0
  19. package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
  20. package/dist/format-rules-B0vbh8Qz.js +143 -0
  21. package/dist/format-rules-B0vbh8Qz.js.map +1 -0
  22. package/dist/hydrate-BO6nlAeD.js +45 -0
  23. package/dist/hydrate-BO6nlAeD.js.map +1 -0
  24. package/dist/index-CgD29XlB.d.ts +1628 -0
  25. package/dist/index-Dy74C11K.d.ts +1273 -0
  26. package/dist/index.d.ts +5 -48
  27. package/dist/index.js +777 -32
  28. package/dist/index.js.map +1 -0
  29. package/dist/keyframes-J_JNrpdh.js +588 -0
  30. package/dist/keyframes-J_JNrpdh.js.map +1 -0
  31. package/dist/{utils/merge-styles.d.ts → merge-styles-BS-mpcci.d.ts} +3 -3
  32. package/dist/{utils/merge-styles.js → merge-styles-Du-eC7zp.js} +4 -6
  33. package/dist/merge-styles-Du-eC7zp.js.map +1 -0
  34. package/dist/{utils/resolve-recipes.js → resolve-recipes-DPRT3FMM.js} +5 -8
  35. package/dist/resolve-recipes-DPRT3FMM.js.map +1 -0
  36. package/dist/ssr/astro-client.d.ts +1 -0
  37. package/dist/ssr/astro-client.js +19 -0
  38. package/dist/ssr/astro-client.js.map +1 -0
  39. package/dist/ssr/astro-middleware.d.ts +15 -0
  40. package/dist/ssr/astro-middleware.js +19 -0
  41. package/dist/ssr/astro-middleware.js.map +1 -0
  42. package/dist/ssr/astro.d.ts +97 -0
  43. package/dist/ssr/astro.js +149 -0
  44. package/dist/ssr/astro.js.map +1 -0
  45. package/dist/ssr/index.d.ts +44 -0
  46. package/dist/ssr/index.js +10 -0
  47. package/dist/ssr/index.js.map +1 -0
  48. package/dist/ssr/next.d.ts +46 -0
  49. package/dist/ssr/next.js +75 -0
  50. package/dist/ssr/next.js.map +1 -0
  51. package/dist/static/index.d.ts +91 -5
  52. package/dist/static/index.js +49 -4
  53. package/dist/static/index.js.map +1 -0
  54. package/dist/static/inject.d.ts +5 -0
  55. package/dist/static/inject.js +17 -0
  56. package/dist/static/inject.js.map +1 -0
  57. package/dist/zero/babel.d.ts +57 -84
  58. package/dist/zero/babel.js +232 -40
  59. package/dist/zero/babel.js.map +1 -1
  60. package/dist/zero/index.d.ts +67 -3
  61. package/dist/zero/index.js +2 -4
  62. package/dist/zero/next.d.ts +56 -30
  63. package/dist/zero/next.js +105 -40
  64. package/dist/zero/next.js.map +1 -1
  65. package/docs/README.md +31 -0
  66. package/docs/adoption.md +298 -0
  67. package/docs/comparison.md +419 -0
  68. package/docs/configuration.md +438 -0
  69. package/docs/debug.md +320 -0
  70. package/docs/design-system.md +436 -0
  71. package/docs/dsl.md +690 -0
  72. package/docs/getting-started.md +217 -0
  73. package/docs/injector.md +544 -0
  74. package/docs/methodology.md +638 -0
  75. package/docs/pipeline.md +673 -0
  76. package/docs/react-api.md +575 -0
  77. package/docs/ssr.md +444 -0
  78. package/docs/styles.md +596 -0
  79. package/docs/tasty-static.md +547 -0
  80. package/package.json +70 -37
  81. package/tasty.config.ts +1 -0
  82. package/dist/_virtual/_rolldown/runtime.js +0 -8
  83. package/dist/chunks/cacheKey.js +0 -70
  84. package/dist/chunks/cacheKey.js.map +0 -1
  85. package/dist/chunks/definitions.d.ts +0 -37
  86. package/dist/chunks/definitions.js +0 -260
  87. package/dist/chunks/definitions.js.map +0 -1
  88. package/dist/chunks/renderChunk.js +0 -61
  89. package/dist/chunks/renderChunk.js.map +0 -1
  90. package/dist/config.d.ts +0 -280
  91. package/dist/config.js +0 -403
  92. package/dist/config.js.map +0 -1
  93. package/dist/debug.d.ts +0 -204
  94. package/dist/debug.js +0 -733
  95. package/dist/debug.js.map +0 -1
  96. package/dist/hooks/useGlobalStyles.d.ts +0 -27
  97. package/dist/hooks/useGlobalStyles.js +0 -56
  98. package/dist/hooks/useGlobalStyles.js.map +0 -1
  99. package/dist/hooks/useKeyframes.d.ts +0 -56
  100. package/dist/hooks/useKeyframes.js +0 -54
  101. package/dist/hooks/useKeyframes.js.map +0 -1
  102. package/dist/hooks/useProperty.d.ts +0 -79
  103. package/dist/hooks/useProperty.js +0 -91
  104. package/dist/hooks/useProperty.js.map +0 -1
  105. package/dist/hooks/useRawCSS.d.ts +0 -53
  106. package/dist/hooks/useRawCSS.js +0 -28
  107. package/dist/hooks/useRawCSS.js.map +0 -1
  108. package/dist/hooks/useStyles.d.ts +0 -40
  109. package/dist/hooks/useStyles.js +0 -169
  110. package/dist/hooks/useStyles.js.map +0 -1
  111. package/dist/injector/index.d.ts +0 -157
  112. package/dist/injector/index.js +0 -154
  113. package/dist/injector/index.js.map +0 -1
  114. package/dist/injector/injector.d.ts +0 -139
  115. package/dist/injector/injector.js +0 -404
  116. package/dist/injector/injector.js.map +0 -1
  117. package/dist/injector/sheet-manager.d.ts +0 -127
  118. package/dist/injector/sheet-manager.js +0 -714
  119. package/dist/injector/sheet-manager.js.map +0 -1
  120. package/dist/injector/types.d.ts +0 -135
  121. package/dist/keyframes/index.js +0 -206
  122. package/dist/keyframes/index.js.map +0 -1
  123. package/dist/parser/classify.js +0 -319
  124. package/dist/parser/classify.js.map +0 -1
  125. package/dist/parser/const.js +0 -33
  126. package/dist/parser/const.js.map +0 -1
  127. package/dist/parser/lru.js +0 -109
  128. package/dist/parser/lru.js.map +0 -1
  129. package/dist/parser/parser.d.ts +0 -25
  130. package/dist/parser/parser.js +0 -116
  131. package/dist/parser/parser.js.map +0 -1
  132. package/dist/parser/tokenizer.js +0 -69
  133. package/dist/parser/tokenizer.js.map +0 -1
  134. package/dist/parser/types.d.ts +0 -51
  135. package/dist/parser/types.js +0 -46
  136. package/dist/parser/types.js.map +0 -1
  137. package/dist/pipeline/conditions.d.ts +0 -134
  138. package/dist/pipeline/conditions.js +0 -406
  139. package/dist/pipeline/conditions.js.map +0 -1
  140. package/dist/pipeline/exclusive.js +0 -231
  141. package/dist/pipeline/exclusive.js.map +0 -1
  142. package/dist/pipeline/index.d.ts +0 -53
  143. package/dist/pipeline/index.js +0 -660
  144. package/dist/pipeline/index.js.map +0 -1
  145. package/dist/pipeline/materialize.js +0 -844
  146. package/dist/pipeline/materialize.js.map +0 -1
  147. package/dist/pipeline/parseStateKey.d.ts +0 -15
  148. package/dist/pipeline/parseStateKey.js +0 -438
  149. package/dist/pipeline/parseStateKey.js.map +0 -1
  150. package/dist/pipeline/simplify.js +0 -516
  151. package/dist/pipeline/simplify.js.map +0 -1
  152. package/dist/pipeline/warnings.js +0 -18
  153. package/dist/pipeline/warnings.js.map +0 -1
  154. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  155. package/dist/plugins/okhsl-plugin.js +0 -371
  156. package/dist/plugins/okhsl-plugin.js.map +0 -1
  157. package/dist/plugins/types.d.ts +0 -69
  158. package/dist/properties/index.js +0 -158
  159. package/dist/properties/index.js.map +0 -1
  160. package/dist/states/index.d.ts +0 -49
  161. package/dist/states/index.js +0 -416
  162. package/dist/states/index.js.map +0 -1
  163. package/dist/static/tastyStatic.d.ts +0 -46
  164. package/dist/static/tastyStatic.js +0 -31
  165. package/dist/static/tastyStatic.js.map +0 -1
  166. package/dist/static/types.d.ts +0 -49
  167. package/dist/static/types.js +0 -24
  168. package/dist/static/types.js.map +0 -1
  169. package/dist/styles/align.d.ts +0 -15
  170. package/dist/styles/align.js +0 -14
  171. package/dist/styles/align.js.map +0 -1
  172. package/dist/styles/border.d.ts +0 -25
  173. package/dist/styles/border.js +0 -114
  174. package/dist/styles/border.js.map +0 -1
  175. package/dist/styles/color.d.ts +0 -14
  176. package/dist/styles/color.js +0 -23
  177. package/dist/styles/color.js.map +0 -1
  178. package/dist/styles/createStyle.js +0 -77
  179. package/dist/styles/createStyle.js.map +0 -1
  180. package/dist/styles/dimension.js +0 -97
  181. package/dist/styles/dimension.js.map +0 -1
  182. package/dist/styles/display.d.ts +0 -37
  183. package/dist/styles/display.js +0 -67
  184. package/dist/styles/display.js.map +0 -1
  185. package/dist/styles/fade.d.ts +0 -15
  186. package/dist/styles/fade.js +0 -58
  187. package/dist/styles/fade.js.map +0 -1
  188. package/dist/styles/fill.d.ts +0 -42
  189. package/dist/styles/fill.js +0 -51
  190. package/dist/styles/fill.js.map +0 -1
  191. package/dist/styles/flow.d.ts +0 -16
  192. package/dist/styles/flow.js +0 -12
  193. package/dist/styles/flow.js.map +0 -1
  194. package/dist/styles/gap.d.ts +0 -31
  195. package/dist/styles/gap.js +0 -37
  196. package/dist/styles/gap.js.map +0 -1
  197. package/dist/styles/height.d.ts +0 -17
  198. package/dist/styles/height.js +0 -20
  199. package/dist/styles/height.js.map +0 -1
  200. package/dist/styles/index.d.ts +0 -2
  201. package/dist/styles/index.js +0 -9
  202. package/dist/styles/index.js.map +0 -1
  203. package/dist/styles/inset.d.ts +0 -52
  204. package/dist/styles/inset.js +0 -150
  205. package/dist/styles/inset.js.map +0 -1
  206. package/dist/styles/justify.d.ts +0 -15
  207. package/dist/styles/justify.js +0 -14
  208. package/dist/styles/justify.js.map +0 -1
  209. package/dist/styles/list.d.ts +0 -16
  210. package/dist/styles/list.js +0 -98
  211. package/dist/styles/list.js.map +0 -1
  212. package/dist/styles/margin.d.ts +0 -24
  213. package/dist/styles/margin.js +0 -104
  214. package/dist/styles/margin.js.map +0 -1
  215. package/dist/styles/outline.d.ts +0 -29
  216. package/dist/styles/outline.js +0 -65
  217. package/dist/styles/outline.js.map +0 -1
  218. package/dist/styles/padding.d.ts +0 -24
  219. package/dist/styles/padding.js +0 -104
  220. package/dist/styles/padding.js.map +0 -1
  221. package/dist/styles/predefined.d.ts +0 -73
  222. package/dist/styles/predefined.js +0 -241
  223. package/dist/styles/predefined.js.map +0 -1
  224. package/dist/styles/preset.d.ts +0 -47
  225. package/dist/styles/preset.js +0 -126
  226. package/dist/styles/preset.js.map +0 -1
  227. package/dist/styles/radius.d.ts +0 -14
  228. package/dist/styles/radius.js +0 -51
  229. package/dist/styles/radius.js.map +0 -1
  230. package/dist/styles/scrollbar.d.ts +0 -21
  231. package/dist/styles/scrollbar.js +0 -112
  232. package/dist/styles/scrollbar.js.map +0 -1
  233. package/dist/styles/shadow.d.ts +0 -14
  234. package/dist/styles/shadow.js +0 -24
  235. package/dist/styles/shadow.js.map +0 -1
  236. package/dist/styles/styledScrollbar.d.ts +0 -47
  237. package/dist/styles/styledScrollbar.js +0 -38
  238. package/dist/styles/styledScrollbar.js.map +0 -1
  239. package/dist/styles/transition.d.ts +0 -14
  240. package/dist/styles/transition.js +0 -158
  241. package/dist/styles/transition.js.map +0 -1
  242. package/dist/styles/types.d.ts +0 -498
  243. package/dist/styles/width.d.ts +0 -17
  244. package/dist/styles/width.js +0 -20
  245. package/dist/styles/width.js.map +0 -1
  246. package/dist/tasty.d.ts +0 -982
  247. package/dist/tasty.js +0 -206
  248. package/dist/tasty.js.map +0 -1
  249. package/dist/tokens/typography.d.ts +0 -19
  250. package/dist/tokens/typography.js +0 -237
  251. package/dist/tokens/typography.js.map +0 -1
  252. package/dist/types.d.ts +0 -184
  253. package/dist/utils/cache-wrapper.js +0 -26
  254. package/dist/utils/cache-wrapper.js.map +0 -1
  255. package/dist/utils/case-converter.js +0 -8
  256. package/dist/utils/case-converter.js.map +0 -1
  257. package/dist/utils/colors.d.ts +0 -5
  258. package/dist/utils/colors.js +0 -9
  259. package/dist/utils/colors.js.map +0 -1
  260. package/dist/utils/css-types.d.ts +0 -7
  261. package/dist/utils/dotize.d.ts +0 -26
  262. package/dist/utils/dotize.js +0 -122
  263. package/dist/utils/dotize.js.map +0 -1
  264. package/dist/utils/filter-base-props.d.ts +0 -15
  265. package/dist/utils/filter-base-props.js +0 -45
  266. package/dist/utils/filter-base-props.js.map +0 -1
  267. package/dist/utils/get-display-name.d.ts +0 -7
  268. package/dist/utils/get-display-name.js +0 -10
  269. package/dist/utils/get-display-name.js.map +0 -1
  270. package/dist/utils/hsl-to-rgb.js +0 -38
  271. package/dist/utils/hsl-to-rgb.js.map +0 -1
  272. package/dist/utils/is-dev-env.js +0 -19
  273. package/dist/utils/is-dev-env.js.map +0 -1
  274. package/dist/utils/is-valid-element-type.js +0 -15
  275. package/dist/utils/is-valid-element-type.js.map +0 -1
  276. package/dist/utils/merge-styles.js.map +0 -1
  277. package/dist/utils/mod-attrs.d.ts +0 -8
  278. package/dist/utils/mod-attrs.js +0 -21
  279. package/dist/utils/mod-attrs.js.map +0 -1
  280. package/dist/utils/okhsl-to-rgb.js +0 -296
  281. package/dist/utils/okhsl-to-rgb.js.map +0 -1
  282. package/dist/utils/process-tokens.d.ts +0 -31
  283. package/dist/utils/process-tokens.js +0 -171
  284. package/dist/utils/process-tokens.js.map +0 -1
  285. package/dist/utils/resolve-recipes.d.ts +0 -17
  286. package/dist/utils/resolve-recipes.js.map +0 -1
  287. package/dist/utils/string.js +0 -8
  288. package/dist/utils/string.js.map +0 -1
  289. package/dist/utils/styles.d.ts +0 -178
  290. package/dist/utils/styles.js +0 -590
  291. package/dist/utils/styles.js.map +0 -1
  292. package/dist/utils/typography.d.ts +0 -36
  293. package/dist/utils/typography.js +0 -53
  294. package/dist/utils/typography.js.map +0 -1
  295. package/dist/utils/warnings.d.ts +0 -16
  296. package/dist/utils/warnings.js +0 -16
  297. package/dist/utils/warnings.js.map +0 -1
  298. package/dist/zero/css-writer.d.ts +0 -45
  299. package/dist/zero/css-writer.js +0 -74
  300. package/dist/zero/css-writer.js.map +0 -1
  301. package/dist/zero/extractor.d.ts +0 -24
  302. package/dist/zero/extractor.js +0 -150
  303. package/dist/zero/extractor.js.map +0 -1
@@ -0,0 +1,575 @@
1
+ # React 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
+ > **Note:** This file was previously named `runtime.md`. All functionality documented here works in both server and client contexts — "runtime" referred to style computation during React rendering, not to client-side JavaScript.
6
+
7
+ ---
8
+
9
+ ## Component Creation
10
+
11
+ ### Create a new component
12
+
13
+ ```jsx
14
+ import { tasty } from '@tenphi/tasty';
15
+
16
+ const Card = tasty({
17
+ as: 'div',
18
+ styles: {
19
+ padding: '4x',
20
+ fill: '#white',
21
+ border: true,
22
+ radius: true,
23
+ },
24
+ styleProps: ['padding', 'fill'],
25
+ });
26
+
27
+ <Card>Hello World</Card>
28
+ <Card padding="6x" fill="#gray.05">Custom Card</Card>
29
+ ```
30
+
31
+ ### Extend an existing component
32
+
33
+ ```jsx
34
+ const PrimaryButton = tasty(Button, {
35
+ styles: {
36
+ fill: '#purple',
37
+ color: '#white',
38
+ padding: '2x 4x',
39
+ },
40
+ });
41
+ ```
42
+
43
+ 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.
44
+
45
+ `tasty(Component, ...)` also works for components that are **not** produced by `tasty()` — Next.js `Link`, `react-router`'s `Link`, Radix primitives, MUI, or any `forwardRef`/`memo` that forwards `className`. Tasty-produced components are internally branded; non-branded components get styled through their `className` prop, which keeps `styles`, `mods`, `qa`, etc. from leaking to the DOM:
46
+
47
+ ```jsx
48
+ import NextLink from 'next/link';
49
+
50
+ const Link = tasty(NextLink, {
51
+ styles: {
52
+ color: { '': '#accent-text', ':hover': '#text' },
53
+ textDecoration: 'underline',
54
+ },
55
+ styleProps: ['padding'],
56
+ });
57
+
58
+ <Link href="/blog" padding="1x">Blog</Link>;
59
+ ```
60
+
61
+ The only requirement on the wrapped component is that it forwards `className` (and ideally `style`/`ref`). See [Methodology — Wrapping non-Tasty components](methodology.md#wrapping-non-tasty-components) for the full picture.
62
+
63
+ ---
64
+
65
+ ## Style Props
66
+
67
+ Use `styleProps` to expose style properties as direct component props:
68
+
69
+ ```jsx
70
+ const FlexibleBox = tasty({
71
+ as: 'div',
72
+ styles: {
73
+ display: 'flex',
74
+ padding: '2x',
75
+ },
76
+ styleProps: ['gap', 'align', 'placeContent', 'fill'],
77
+ });
78
+
79
+ <FlexibleBox gap="2x" align="center" fill="#surface">
80
+ Content
81
+ </FlexibleBox>
82
+ ```
83
+
84
+ Style props accept state maps, so responsive values work through the same API:
85
+
86
+ ```jsx
87
+ <FlexibleBox
88
+ gap={{ '': '2x', '@tablet': '4x' }}
89
+ fill={{ '': '#surface', '@dark': '#surface-dark' }}
90
+ >
91
+ ```
92
+
93
+ 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).
94
+
95
+ ---
96
+
97
+ ## Mod Props
98
+
99
+ Use `modProps` to expose modifier keys as direct component props instead of requiring the `mods` object:
100
+
101
+ ```jsx
102
+ // Before: mods object
103
+ <Button mods={{ isLoading: true, size: 'large' }}>Submit</Button>
104
+
105
+ // After: mod props
106
+ <Button isLoading size="large">Submit</Button>
107
+ ```
108
+
109
+ ### Array form
110
+
111
+ List modifier key names. Types default to `ModValue` (`boolean | string | number | undefined | null`):
112
+
113
+ ```jsx
114
+ const Button = tasty({
115
+ modProps: ['isLoading', 'isSelected'] as const,
116
+ styles: {
117
+ fill: { '': '#surface', isLoading: '#surface.5' },
118
+ border: { '': '1bw solid #outline', isSelected: '2bw solid #primary' },
119
+ },
120
+ });
121
+
122
+ <Button isLoading isSelected>Submit</Button>
123
+ // Renders: <button data-is-loading="" data-is-selected="">Submit</button>
124
+ ```
125
+
126
+ ### Object form (typed)
127
+
128
+ Map modifier names to type descriptors for precise TypeScript types:
129
+
130
+ ```tsx
131
+ const Button = tasty({
132
+ modProps: {
133
+ isLoading: Boolean, // isLoading?: boolean
134
+ isSelected: Boolean, // isSelected?: boolean
135
+ size: ['small', 'medium', 'large'] as const, // size?: 'small' | 'medium' | 'large'
136
+ },
137
+ styles: {
138
+ padding: { '': '2x 4x', 'size=small': '1x 2x', 'size=large': '3x 6x' },
139
+ fill: { '': '#surface', isLoading: '#surface.5' },
140
+ },
141
+ });
142
+
143
+ <Button isLoading size="large">Submit</Button>
144
+ // Renders: <button data-is-loading="" data-size="large">Submit</button>
145
+ ```
146
+
147
+ Available type descriptors:
148
+
149
+ | Descriptor | TypeScript type | Example |
150
+ |---|---|---|
151
+ | `Boolean` | `boolean` | `isLoading: Boolean` |
152
+ | `String` | `string` | `label: String` |
153
+ | `Number` | `number` | `count: Number` |
154
+ | `['a', 'b'] as const` | `'a' \| 'b'` | `size: ['sm', 'md', 'lg'] as const` |
155
+
156
+ ### Merge with `mods`
157
+
158
+ Mod props and the `mods` object can be used together. Mod props take precedence:
159
+
160
+ ```jsx
161
+ <Button mods={{ isLoading: false, extra: true }} isLoading>
162
+ // isLoading=true wins (from mod prop), extra=true preserved from mods
163
+ ```
164
+
165
+ ### When to use `modProps` vs `mods`
166
+
167
+ | Use case | Recommendation |
168
+ |---|---|
169
+ | Component has a fixed set of known modifiers | `modProps` — cleaner API, better TypeScript autocomplete |
170
+ | Component needs arbitrary/dynamic modifiers | `mods` — open-ended `Record<string, ModValue>` |
171
+ | Both fixed and dynamic | Combine: `modProps` for known keys, `mods` for ad-hoc |
172
+
173
+ For architecture guidance on when to use modifiers vs `styleProps`, see [Methodology — modProps and mods](methodology.md#modprops-and-mods).
174
+
175
+ ---
176
+
177
+ ## Token Props
178
+
179
+ Use `tokenProps` to expose token keys as direct component props instead of requiring the `tokens` object:
180
+
181
+ ```jsx
182
+ // Before: tokens object
183
+ <ProgressBar tokens={{ $progress: '75%', '#accent': '#purple' }} />
184
+
185
+ // After: token props
186
+ <ProgressBar progress="75%" accentColor="#purple" />
187
+ ```
188
+
189
+ ### Array form
190
+
191
+ List prop names. Names ending in `Color` map to `#` color tokens; everything else maps to `$` custom property tokens:
192
+
193
+ ```jsx
194
+ const ProgressBar = tasty({
195
+ tokenProps: ['progress', 'accentColor'] as const,
196
+ styles: { width: '$progress', fill: '#accent' },
197
+ });
198
+
199
+ <ProgressBar progress="75%" accentColor="#purple" />
200
+ // 'progress' → $progress → --progress
201
+ // 'accentColor' → #accent → --accent-color + --accent-color-oklch
202
+ ```
203
+
204
+ ### Object form
205
+
206
+ Map prop names to explicit `$`/`#`-prefixed token keys:
207
+
208
+ ```tsx
209
+ const Card = tasty({
210
+ tokenProps: {
211
+ size: '$card-size',
212
+ color: '#card-accent',
213
+ },
214
+ styles: { padding: '$card-size', fill: '#card-accent' },
215
+ });
216
+
217
+ <Card size="4x" color="#purple" />
218
+ ```
219
+
220
+ ### Merge with `tokens`
221
+
222
+ Token props and the `tokens` prop can be used together. Token props take precedence over `tokens`, which takes precedence over default `tokens` in `tasty({...})`:
223
+
224
+ ```jsx
225
+ const Bar = tasty({
226
+ tokenProps: ['progress'] as const,
227
+ tokens: { $progress: '0%' }, // default
228
+ });
229
+
230
+ <Bar tokens={{ $progress: '50%' }} progress="90%" />
231
+ // progress="90%" wins (from token prop)
232
+ ```
233
+
234
+ ### When to use `tokenProps` vs `tokens`
235
+
236
+ | Use case | Recommendation |
237
+ |---|---|
238
+ | Component has a fixed set of known token keys | `tokenProps` — cleaner API, better TypeScript autocomplete |
239
+ | Component needs arbitrary/dynamic token values | `tokens` — open-ended `Record<string, TokenValue>` |
240
+ | Both fixed and dynamic | Combine: `tokenProps` for known keys, `tokens` for ad-hoc |
241
+
242
+ For architecture guidance, see [Methodology — tokenProps](methodology.md#tokenprops).
243
+
244
+ ---
245
+
246
+ ## Variants
247
+
248
+ Define named style variations. Only CSS for variants actually used at runtime is injected:
249
+
250
+ ```jsx
251
+ const Button = tasty({
252
+ styles: {
253
+ padding: '2x 4x',
254
+ border: true,
255
+ },
256
+ variants: {
257
+ default: { fill: '#blue', color: '#white' },
258
+ danger: { fill: '#red', color: '#white' },
259
+ outline: { fill: 'transparent', color: '#blue', border: '1bw solid #blue' },
260
+ },
261
+ });
262
+
263
+ <Button variant="danger">Delete</Button>
264
+ ```
265
+
266
+ ### Extending Variants with Base State Maps
267
+
268
+ 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:
269
+
270
+ ```jsx
271
+ const Badge = tasty({
272
+ styles: {
273
+ padding: '1x 2x',
274
+ border: {
275
+ 'type=primary': '#clear',
276
+ },
277
+ },
278
+ variants: {
279
+ primary: {
280
+ border: { '': '#white.2', pressed: '#primary-text', disabled: '#clear' },
281
+ fill: { '': '#white #primary', hovered: '#white #primary-text' },
282
+ },
283
+ secondary: {
284
+ border: { '': '#primary.15', pressed: '#primary.3' },
285
+ fill: '#primary.10',
286
+ },
287
+ },
288
+ });
289
+
290
+ // Both variants get 'type=primary': '#clear' appended to their border map
291
+ ```
292
+
293
+ 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.
294
+
295
+ ---
296
+
297
+ ## Sub-element Styling
298
+
299
+ Sub-elements are inner parts of a compound component, styled via capitalized keys in `styles` and identified by `data-element` attributes in the DOM.
300
+
301
+ > 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.
302
+
303
+ ```jsx
304
+ const Card = tasty({
305
+ styles: {
306
+ padding: '4x',
307
+ Title: { preset: 'h3', color: '#primary' },
308
+ Content: { color: '#text' },
309
+ },
310
+ elements: {
311
+ Title: 'h3',
312
+ Content: 'div',
313
+ },
314
+ });
315
+
316
+ <Card>
317
+ <Card.Title>Card Title</Card.Title>
318
+ <Card.Content>Card content</Card.Content>
319
+ </Card>
320
+ ```
321
+
322
+ Each entry in `elements` can be a tag name string or a config object:
323
+
324
+ ```jsx
325
+ elements: {
326
+ Title: 'h3', // shorthand: tag name only
327
+ Icon: { as: 'span', qa: 'card-icon' }, // full form: tag + QA attribute
328
+ }
329
+ ```
330
+
331
+ The sub-components produced by `elements` support `mods`, `tokens`, `isDisabled`, `isHidden`, and `isChecked` props — the same modifier interface as the root component.
332
+
333
+ 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:
334
+
335
+ ```jsx
336
+ const Card = tasty({
337
+ styles: {
338
+ padding: '4x',
339
+ Title: { preset: 'h3', color: '#primary' },
340
+ },
341
+ });
342
+
343
+ <Card>
344
+ <div data-element="Title">Card Title</div>
345
+ </Card>
346
+ ```
347
+
348
+ ### Selector Affix (`$`)
349
+
350
+ 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-).
351
+
352
+ 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).
353
+
354
+ ---
355
+
356
+ ## computeStyles
357
+
358
+ Hook-free, synchronous style computation. Can be used anywhere — including React Server Components, plain functions, and non-React code:
359
+
360
+ ```tsx
361
+ import { computeStyles } from '@tenphi/tasty';
362
+
363
+ const { className } = computeStyles({
364
+ padding: '2x',
365
+ fill: '#surface',
366
+ radius: '1r',
367
+ });
368
+ ```
369
+
370
+ 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.
371
+
372
+ ---
373
+
374
+ ## Style Functions
375
+
376
+ 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.
377
+
378
+ In server-only contexts (Next.js RSC without `'use client'`, Astro without `client:*` directives, SSG), components that use only Tasty style functions produce zero client JavaScript. Tasty never forces the `'use client'` boundary — that decision belongs to your component when it needs React interactivity (state, effects, event handlers).
379
+
380
+ ### useStyles
381
+
382
+ Generate a className from a style object. Thin wrapper around `computeStyles()`:
383
+
384
+ ```tsx
385
+ import { useStyles } from '@tenphi/tasty';
386
+
387
+ function MyComponent() {
388
+ const { className } = useStyles({
389
+ padding: '2x',
390
+ fill: '#surface',
391
+ radius: '1r',
392
+ });
393
+
394
+ return <div className={className}>Styled content</div>;
395
+ }
396
+ ```
397
+
398
+ ### useGlobalStyles
399
+
400
+ 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:
401
+
402
+ ```tsx
403
+ import { useGlobalStyles } from '@tenphi/tasty';
404
+
405
+ function ThemeStyles() {
406
+ useGlobalStyles('.card', {
407
+ padding: '4x',
408
+ fill: '#surface',
409
+ radius: '1r',
410
+ });
411
+
412
+ return null;
413
+ }
414
+ ```
415
+
416
+ ### useRawCSS
417
+
418
+ 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:
419
+
420
+ ```tsx
421
+ import { useRawCSS } from '@tenphi/tasty';
422
+
423
+ function GlobalReset() {
424
+ useRawCSS(`
425
+ body { margin: 0; padding: 0; }
426
+ `);
427
+
428
+ return null;
429
+ }
430
+ ```
431
+
432
+ ### useKeyframes
433
+
434
+ Inject `@keyframes` rules and return the generated animation name:
435
+
436
+ ```tsx
437
+ import { useKeyframes } from '@tenphi/tasty';
438
+
439
+ function Spinner() {
440
+ const spin = useKeyframes(
441
+ {
442
+ from: { transform: 'rotate(0deg)' },
443
+ to: { transform: 'rotate(360deg)' },
444
+ },
445
+ { name: 'spin' }
446
+ );
447
+
448
+ return <div style={{ animation: `${spin} 1s linear infinite` }} />;
449
+ }
450
+ ```
451
+
452
+ `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:
453
+
454
+ ```tsx
455
+ function Pulse({ scale }: { scale: number }) {
456
+ const pulse = useKeyframes(
457
+ () => ({
458
+ '0%': { transform: 'scale(1)' },
459
+ '100%': { transform: `scale(${scale})` },
460
+ }),
461
+ [scale]
462
+ );
463
+
464
+ return <div style={{ animation: `${pulse} 500ms ease-in-out alternate infinite` }} />;
465
+ }
466
+ ```
467
+
468
+ ### useProperty
469
+
470
+ Register a CSS `@property` rule so a custom property can animate smoothly:
471
+
472
+ ```tsx
473
+ import { useProperty } from '@tenphi/tasty';
474
+
475
+ function Spinner() {
476
+ useProperty('$rotation', {
477
+ syntax: '<angle>',
478
+ inherits: false,
479
+ initialValue: '0deg',
480
+ });
481
+
482
+ return <div style={{ transform: 'rotate(var(--rotation))' }} />;
483
+ }
484
+ ```
485
+
486
+ `useProperty()` accepts Tasty token syntax for the property name:
487
+
488
+ - `$name` defines `--name`
489
+ - `#name` defines `--name-color` and auto-infers `<color>`
490
+ - `--name` is also supported for existing CSS variables
491
+
492
+ ### useFontFace
493
+
494
+ Inject `@font-face` rules for custom fonts. Permanent — no cleanup on unmount. Deduplicates by content.
495
+
496
+ ```tsx
497
+ import { useFontFace } from '@tenphi/tasty';
498
+
499
+ function App() {
500
+ useFontFace('Brand Sans', {
501
+ src: 'url("/fonts/brand-sans.woff2") format("woff2")',
502
+ fontWeight: '400 700',
503
+ fontDisplay: 'swap',
504
+ });
505
+
506
+ return <div style={{ fontFamily: '"Brand Sans", sans-serif' }}>Hello</div>;
507
+ }
508
+ ```
509
+
510
+ For multiple weights/styles, pass an array:
511
+
512
+ ```tsx
513
+ useFontFace('Brand Sans', [
514
+ { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
515
+ { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
516
+ ]);
517
+ ```
518
+
519
+ Signature:
520
+
521
+ ```ts
522
+ function useFontFace(family: string, input: FontFaceInput): void;
523
+ ```
524
+
525
+ ### useCounterStyle
526
+
527
+ Inject a `@counter-style` rule and get back the counter style name. Permanent — no cleanup on unmount. Deduplicates by name.
528
+
529
+ ```tsx
530
+ import { useCounterStyle } from '@tenphi/tasty';
531
+
532
+ function EmojiList() {
533
+ const styleName = useCounterStyle({
534
+ system: 'cyclic',
535
+ symbols: '"👍"',
536
+ suffix: '" "',
537
+ }, { name: 'thumbs' });
538
+
539
+ return (
540
+ <ol style={{ listStyleType: styleName }}>
541
+ <li>First</li>
542
+ <li>Second</li>
543
+ </ol>
544
+ );
545
+ }
546
+ ```
547
+
548
+ Signature:
549
+
550
+ ```ts
551
+ function useCounterStyle(
552
+ descriptors: CounterStyleDescriptors,
553
+ options?: { name?: string; root?: Document | ShadowRoot },
554
+ ): string;
555
+ ```
556
+
557
+ ### Troubleshooting
558
+
559
+ - 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).
560
+ - 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`.
561
+ - Animation/custom property issues: prefer `useKeyframes()` and `useProperty()` over raw CSS when you want Tasty to manage injection and SSR collection for you.
562
+ - For dynamic styles that change over the component lifecycle, use the `id` option in `useGlobalStyles()` and `useRawCSS()` to enable update tracking.
563
+ - RSC inline mode: CSS accumulated by standalone style functions (`useGlobalStyles`, `useRawCSS`, etc.) is flushed into inline `<style>` tags by the next `tasty()` component in the render tree. If your page uses only standalone style functions without any `tasty()` component, the CSS will not be emitted. Ensure at least one `tasty()` component is present in each RSC render tree.
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