@tenphi/tasty 0.0.0-snapshot.05c1c22

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 (314) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +629 -0
  3. package/dist/_virtual/_rolldown/runtime.js +7 -0
  4. package/dist/chunks/cacheKey.d.ts +1 -0
  5. package/dist/chunks/cacheKey.js +77 -0
  6. package/dist/chunks/cacheKey.js.map +1 -0
  7. package/dist/chunks/definitions.d.ts +37 -0
  8. package/dist/chunks/definitions.js +258 -0
  9. package/dist/chunks/definitions.js.map +1 -0
  10. package/dist/chunks/index.d.ts +1 -0
  11. package/dist/chunks/renderChunk.d.ts +1 -0
  12. package/dist/chunks/renderChunk.js +59 -0
  13. package/dist/chunks/renderChunk.js.map +1 -0
  14. package/dist/config.d.ts +366 -0
  15. package/dist/config.js +503 -0
  16. package/dist/config.js.map +1 -0
  17. package/dist/core/index.d.ts +33 -0
  18. package/dist/core/index.js +26 -0
  19. package/dist/counter-style/index.js +51 -0
  20. package/dist/counter-style/index.js.map +1 -0
  21. package/dist/debug.d.ts +89 -0
  22. package/dist/debug.js +453 -0
  23. package/dist/debug.js.map +1 -0
  24. package/dist/font-face/index.js +63 -0
  25. package/dist/font-face/index.js.map +1 -0
  26. package/dist/hooks/index.d.ts +7 -0
  27. package/dist/hooks/resolve-ssr-collector.js +14 -0
  28. package/dist/hooks/resolve-ssr-collector.js.map +1 -0
  29. package/dist/hooks/useCounterStyle.d.ts +50 -0
  30. package/dist/hooks/useCounterStyle.js +46 -0
  31. package/dist/hooks/useCounterStyle.js.map +1 -0
  32. package/dist/hooks/useFontFace.d.ts +43 -0
  33. package/dist/hooks/useFontFace.js +70 -0
  34. package/dist/hooks/useFontFace.js.map +1 -0
  35. package/dist/hooks/useGlobalStyles.d.ts +30 -0
  36. package/dist/hooks/useGlobalStyles.js +78 -0
  37. package/dist/hooks/useGlobalStyles.js.map +1 -0
  38. package/dist/hooks/useKeyframes.d.ts +56 -0
  39. package/dist/hooks/useKeyframes.js +64 -0
  40. package/dist/hooks/useKeyframes.js.map +1 -0
  41. package/dist/hooks/useProperty.d.ts +79 -0
  42. package/dist/hooks/useProperty.js +109 -0
  43. package/dist/hooks/useProperty.js.map +1 -0
  44. package/dist/hooks/useRawCSS.d.ts +53 -0
  45. package/dist/hooks/useRawCSS.js +35 -0
  46. package/dist/hooks/useRawCSS.js.map +1 -0
  47. package/dist/hooks/useStyles.d.ts +45 -0
  48. package/dist/hooks/useStyles.js +237 -0
  49. package/dist/hooks/useStyles.js.map +1 -0
  50. package/dist/index.d.ts +50 -0
  51. package/dist/index.js +35 -0
  52. package/dist/injector/index.d.ts +183 -0
  53. package/dist/injector/index.js +179 -0
  54. package/dist/injector/index.js.map +1 -0
  55. package/dist/injector/injector.d.ts +166 -0
  56. package/dist/injector/injector.js +464 -0
  57. package/dist/injector/injector.js.map +1 -0
  58. package/dist/injector/sheet-manager.d.ts +136 -0
  59. package/dist/injector/sheet-manager.js +733 -0
  60. package/dist/injector/sheet-manager.js.map +1 -0
  61. package/dist/injector/types.d.ts +204 -0
  62. package/dist/keyframes/index.js +206 -0
  63. package/dist/keyframes/index.js.map +1 -0
  64. package/dist/parser/classify.js +319 -0
  65. package/dist/parser/classify.js.map +1 -0
  66. package/dist/parser/const.js +49 -0
  67. package/dist/parser/const.js.map +1 -0
  68. package/dist/parser/lru.js +109 -0
  69. package/dist/parser/lru.js.map +1 -0
  70. package/dist/parser/parser.d.ts +25 -0
  71. package/dist/parser/parser.js +115 -0
  72. package/dist/parser/parser.js.map +1 -0
  73. package/dist/parser/tokenizer.js +69 -0
  74. package/dist/parser/tokenizer.js.map +1 -0
  75. package/dist/parser/types.d.ts +51 -0
  76. package/dist/parser/types.js +46 -0
  77. package/dist/parser/types.js.map +1 -0
  78. package/dist/pipeline/conditions.d.ts +134 -0
  79. package/dist/pipeline/conditions.js +406 -0
  80. package/dist/pipeline/conditions.js.map +1 -0
  81. package/dist/pipeline/exclusive.js +230 -0
  82. package/dist/pipeline/exclusive.js.map +1 -0
  83. package/dist/pipeline/index.d.ts +55 -0
  84. package/dist/pipeline/index.js +708 -0
  85. package/dist/pipeline/index.js.map +1 -0
  86. package/dist/pipeline/materialize.js +1103 -0
  87. package/dist/pipeline/materialize.js.map +1 -0
  88. package/dist/pipeline/parseStateKey.d.ts +15 -0
  89. package/dist/pipeline/parseStateKey.js +446 -0
  90. package/dist/pipeline/parseStateKey.js.map +1 -0
  91. package/dist/pipeline/simplify.js +515 -0
  92. package/dist/pipeline/simplify.js.map +1 -0
  93. package/dist/pipeline/warnings.js +18 -0
  94. package/dist/pipeline/warnings.js.map +1 -0
  95. package/dist/plugins/index.d.ts +2 -0
  96. package/dist/plugins/okhsl-plugin.d.ts +35 -0
  97. package/dist/plugins/okhsl-plugin.js +97 -0
  98. package/dist/plugins/okhsl-plugin.js.map +1 -0
  99. package/dist/plugins/types.d.ts +76 -0
  100. package/dist/properties/index.js +222 -0
  101. package/dist/properties/index.js.map +1 -0
  102. package/dist/properties/property-type-resolver.d.ts +24 -0
  103. package/dist/properties/property-type-resolver.js +90 -0
  104. package/dist/properties/property-type-resolver.js.map +1 -0
  105. package/dist/ssr/astro.d.ts +29 -0
  106. package/dist/ssr/astro.js +64 -0
  107. package/dist/ssr/astro.js.map +1 -0
  108. package/dist/ssr/async-storage.d.ts +17 -0
  109. package/dist/ssr/async-storage.js +34 -0
  110. package/dist/ssr/async-storage.js.map +1 -0
  111. package/dist/ssr/collect-auto-properties.js +39 -0
  112. package/dist/ssr/collect-auto-properties.js.map +1 -0
  113. package/dist/ssr/collector.d.ts +102 -0
  114. package/dist/ssr/collector.js +226 -0
  115. package/dist/ssr/collector.js.map +1 -0
  116. package/dist/ssr/context.d.ts +8 -0
  117. package/dist/ssr/context.js +13 -0
  118. package/dist/ssr/context.js.map +1 -0
  119. package/dist/ssr/format-global-rules.js +22 -0
  120. package/dist/ssr/format-global-rules.js.map +1 -0
  121. package/dist/ssr/format-keyframes.js +69 -0
  122. package/dist/ssr/format-keyframes.js.map +1 -0
  123. package/dist/ssr/format-property.js +49 -0
  124. package/dist/ssr/format-property.js.map +1 -0
  125. package/dist/ssr/format-rules.js +73 -0
  126. package/dist/ssr/format-rules.js.map +1 -0
  127. package/dist/ssr/hydrate.d.ts +22 -0
  128. package/dist/ssr/hydrate.js +49 -0
  129. package/dist/ssr/hydrate.js.map +1 -0
  130. package/dist/ssr/index.d.ts +5 -0
  131. package/dist/ssr/index.js +11 -0
  132. package/dist/ssr/index.js.map +1 -0
  133. package/dist/ssr/next.d.ts +45 -0
  134. package/dist/ssr/next.js +69 -0
  135. package/dist/ssr/next.js.map +1 -0
  136. package/dist/ssr/ssr-collector-ref.js +12 -0
  137. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  138. package/dist/states/index.d.ts +49 -0
  139. package/dist/states/index.js +170 -0
  140. package/dist/states/index.js.map +1 -0
  141. package/dist/static/index.d.ts +5 -0
  142. package/dist/static/index.js +4 -0
  143. package/dist/static/inject.d.ts +5 -0
  144. package/dist/static/inject.js +17 -0
  145. package/dist/static/inject.js.map +1 -0
  146. package/dist/static/tastyStatic.d.ts +46 -0
  147. package/dist/static/tastyStatic.js +30 -0
  148. package/dist/static/tastyStatic.js.map +1 -0
  149. package/dist/static/types.d.ts +49 -0
  150. package/dist/static/types.js +24 -0
  151. package/dist/static/types.js.map +1 -0
  152. package/dist/styles/align.d.ts +15 -0
  153. package/dist/styles/align.js +14 -0
  154. package/dist/styles/align.js.map +1 -0
  155. package/dist/styles/border.d.ts +25 -0
  156. package/dist/styles/border.js +113 -0
  157. package/dist/styles/border.js.map +1 -0
  158. package/dist/styles/color.d.ts +14 -0
  159. package/dist/styles/color.js +26 -0
  160. package/dist/styles/color.js.map +1 -0
  161. package/dist/styles/createStyle.js +79 -0
  162. package/dist/styles/createStyle.js.map +1 -0
  163. package/dist/styles/dimension.js +96 -0
  164. package/dist/styles/dimension.js.map +1 -0
  165. package/dist/styles/display.d.ts +37 -0
  166. package/dist/styles/display.js +66 -0
  167. package/dist/styles/display.js.map +1 -0
  168. package/dist/styles/fade.d.ts +15 -0
  169. package/dist/styles/fade.js +57 -0
  170. package/dist/styles/fade.js.map +1 -0
  171. package/dist/styles/fill.d.ts +42 -0
  172. package/dist/styles/fill.js +51 -0
  173. package/dist/styles/fill.js.map +1 -0
  174. package/dist/styles/flow.d.ts +16 -0
  175. package/dist/styles/flow.js +12 -0
  176. package/dist/styles/flow.js.map +1 -0
  177. package/dist/styles/gap.d.ts +31 -0
  178. package/dist/styles/gap.js +36 -0
  179. package/dist/styles/gap.js.map +1 -0
  180. package/dist/styles/height.d.ts +17 -0
  181. package/dist/styles/height.js +19 -0
  182. package/dist/styles/height.js.map +1 -0
  183. package/dist/styles/index.d.ts +1 -0
  184. package/dist/styles/index.js +8 -0
  185. package/dist/styles/index.js.map +1 -0
  186. package/dist/styles/inset.d.ts +52 -0
  187. package/dist/styles/inset.js +149 -0
  188. package/dist/styles/inset.js.map +1 -0
  189. package/dist/styles/justify.d.ts +15 -0
  190. package/dist/styles/justify.js +14 -0
  191. package/dist/styles/justify.js.map +1 -0
  192. package/dist/styles/list.d.ts +16 -0
  193. package/dist/styles/list.js +98 -0
  194. package/dist/styles/list.js.map +1 -0
  195. package/dist/styles/margin.d.ts +24 -0
  196. package/dist/styles/margin.js +103 -0
  197. package/dist/styles/margin.js.map +1 -0
  198. package/dist/styles/outline.d.ts +29 -0
  199. package/dist/styles/outline.js +64 -0
  200. package/dist/styles/outline.js.map +1 -0
  201. package/dist/styles/padding.d.ts +24 -0
  202. package/dist/styles/padding.js +103 -0
  203. package/dist/styles/padding.js.map +1 -0
  204. package/dist/styles/predefined.d.ts +71 -0
  205. package/dist/styles/predefined.js +237 -0
  206. package/dist/styles/predefined.js.map +1 -0
  207. package/dist/styles/preset.d.ts +52 -0
  208. package/dist/styles/preset.js +126 -0
  209. package/dist/styles/preset.js.map +1 -0
  210. package/dist/styles/radius.d.ts +12 -0
  211. package/dist/styles/radius.js +71 -0
  212. package/dist/styles/radius.js.map +1 -0
  213. package/dist/styles/scrollbar.d.ts +25 -0
  214. package/dist/styles/scrollbar.js +46 -0
  215. package/dist/styles/scrollbar.js.map +1 -0
  216. package/dist/styles/shadow.d.ts +14 -0
  217. package/dist/styles/shadow.js +23 -0
  218. package/dist/styles/shadow.js.map +1 -0
  219. package/dist/styles/transition.d.ts +14 -0
  220. package/dist/styles/transition.js +157 -0
  221. package/dist/styles/transition.js.map +1 -0
  222. package/dist/styles/types.d.ts +549 -0
  223. package/dist/styles/width.d.ts +17 -0
  224. package/dist/styles/width.js +19 -0
  225. package/dist/styles/width.js.map +1 -0
  226. package/dist/tasty.d.ts +119 -0
  227. package/dist/tasty.js +231 -0
  228. package/dist/tasty.js.map +1 -0
  229. package/dist/types.d.ts +184 -0
  230. package/dist/utils/cache-wrapper.js +21 -0
  231. package/dist/utils/cache-wrapper.js.map +1 -0
  232. package/dist/utils/case-converter.js +8 -0
  233. package/dist/utils/case-converter.js.map +1 -0
  234. package/dist/utils/color-math.d.ts +46 -0
  235. package/dist/utils/color-math.js +749 -0
  236. package/dist/utils/color-math.js.map +1 -0
  237. package/dist/utils/color-space.d.ts +5 -0
  238. package/dist/utils/color-space.js +228 -0
  239. package/dist/utils/color-space.js.map +1 -0
  240. package/dist/utils/colors.d.ts +5 -0
  241. package/dist/utils/colors.js +10 -0
  242. package/dist/utils/colors.js.map +1 -0
  243. package/dist/utils/css-types.d.ts +7 -0
  244. package/dist/utils/dotize.d.ts +26 -0
  245. package/dist/utils/dotize.js +122 -0
  246. package/dist/utils/dotize.js.map +1 -0
  247. package/dist/utils/filter-base-props.d.ts +15 -0
  248. package/dist/utils/filter-base-props.js +45 -0
  249. package/dist/utils/filter-base-props.js.map +1 -0
  250. package/dist/utils/get-display-name.d.ts +7 -0
  251. package/dist/utils/get-display-name.js +10 -0
  252. package/dist/utils/get-display-name.js.map +1 -0
  253. package/dist/utils/has-keys.js +13 -0
  254. package/dist/utils/has-keys.js.map +1 -0
  255. package/dist/utils/is-dev-env.js +19 -0
  256. package/dist/utils/is-dev-env.js.map +1 -0
  257. package/dist/utils/is-valid-element-type.js +15 -0
  258. package/dist/utils/is-valid-element-type.js.map +1 -0
  259. package/dist/utils/merge-styles.d.ts +7 -0
  260. package/dist/utils/merge-styles.js +145 -0
  261. package/dist/utils/merge-styles.js.map +1 -0
  262. package/dist/utils/mod-attrs.d.ts +6 -0
  263. package/dist/utils/mod-attrs.js +20 -0
  264. package/dist/utils/mod-attrs.js.map +1 -0
  265. package/dist/utils/process-tokens.d.ts +21 -0
  266. package/dist/utils/process-tokens.js +90 -0
  267. package/dist/utils/process-tokens.js.map +1 -0
  268. package/dist/utils/resolve-recipes.d.ts +17 -0
  269. package/dist/utils/resolve-recipes.js +146 -0
  270. package/dist/utils/resolve-recipes.js.map +1 -0
  271. package/dist/utils/selector-transform.js +32 -0
  272. package/dist/utils/selector-transform.js.map +1 -0
  273. package/dist/utils/string.js +8 -0
  274. package/dist/utils/string.js.map +1 -0
  275. package/dist/utils/styles.d.ts +99 -0
  276. package/dist/utils/styles.js +220 -0
  277. package/dist/utils/styles.js.map +1 -0
  278. package/dist/utils/typography.d.ts +47 -0
  279. package/dist/utils/typography.js +51 -0
  280. package/dist/utils/typography.js.map +1 -0
  281. package/dist/utils/warnings.d.ts +16 -0
  282. package/dist/utils/warnings.js +16 -0
  283. package/dist/utils/warnings.js.map +1 -0
  284. package/dist/zero/babel.d.ts +182 -0
  285. package/dist/zero/babel.js +438 -0
  286. package/dist/zero/babel.js.map +1 -0
  287. package/dist/zero/css-writer.d.ts +45 -0
  288. package/dist/zero/css-writer.js +73 -0
  289. package/dist/zero/css-writer.js.map +1 -0
  290. package/dist/zero/extractor.d.ts +24 -0
  291. package/dist/zero/extractor.js +266 -0
  292. package/dist/zero/extractor.js.map +1 -0
  293. package/dist/zero/index.d.ts +3 -0
  294. package/dist/zero/index.js +3 -0
  295. package/dist/zero/next.d.ts +86 -0
  296. package/dist/zero/next.js +143 -0
  297. package/dist/zero/next.js.map +1 -0
  298. package/docs/PIPELINE.md +519 -0
  299. package/docs/README.md +31 -0
  300. package/docs/adoption.md +296 -0
  301. package/docs/comparison.md +420 -0
  302. package/docs/configuration.md +326 -0
  303. package/docs/debug.md +318 -0
  304. package/docs/design-system.md +424 -0
  305. package/docs/dsl.md +673 -0
  306. package/docs/getting-started.md +217 -0
  307. package/docs/injector.md +528 -0
  308. package/docs/methodology.md +567 -0
  309. package/docs/runtime.md +485 -0
  310. package/docs/ssr.md +384 -0
  311. package/docs/styles.md +582 -0
  312. package/docs/tasty-static.md +520 -0
  313. package/package.json +215 -0
  314. package/tasty.config.ts +14 -0
@@ -0,0 +1,520 @@
1
+ # Zero Runtime Mode (tastyStatic)
2
+
3
+ `tastyStatic` is a build-time utility for generating CSS with zero runtime overhead. It's designed for static sites, no-JS websites, and performance-critical applications where you want to eliminate all runtime styling code. For the broader docs map, see the [Docs Hub](README.md).
4
+
5
+ ---
6
+
7
+ ## When to Use
8
+
9
+ - **Static site generation (SSG)** — Pre-render all styles at build time
10
+ - **No-JavaScript websites** — CSS works without any JS runtime
11
+ - **Performance-critical pages** — Zero runtime overhead for styling
12
+ - **Landing pages** — Minimal bundle size with pre-generated CSS
13
+
14
+ ## Requirements
15
+
16
+ The zero-runtime mode is part of the main `@tenphi/tasty` package but requires additional peer dependencies depending on your setup:
17
+
18
+ | Dependency | Version | Required for |
19
+ |---|---|---|
20
+ | `@babel/core` | >= 7.24 | Babel plugin (`@tenphi/tasty/babel-plugin`) |
21
+ | `@babel/helper-plugin-utils` | >= 7.24 | Babel plugin |
22
+ | `@babel/types` | >= 7.24 | Babel plugin |
23
+ | `jiti` | >= 2.6 | Next.js wrapper (`@tenphi/tasty/next`) when using `configFile` option |
24
+
25
+ All of these are declared as optional peer dependencies of `@tenphi/tasty`. Install only what your setup requires:
26
+
27
+ ```bash
28
+ # For any Babel-based setup (Vite, custom Babel config, etc.)
29
+ pnpm add -D @babel/core @babel/helper-plugin-utils @babel/types
30
+
31
+ # For Next.js with TypeScript config file
32
+ pnpm add -D @babel/core @babel/helper-plugin-utils @babel/types jiti
33
+ ```
34
+
35
+ ---
36
+
37
+ ## Quick Start
38
+
39
+ ### Basic Usage
40
+
41
+ ```tsx
42
+ import { tastyStatic } from '@tenphi/tasty/static';
43
+
44
+ // Define styles - returns StaticStyle object
45
+ const button = tastyStatic({
46
+ display: 'inline-flex',
47
+ padding: '2x 4x',
48
+ fill: '#purple',
49
+ color: '#white',
50
+ radius: '1r',
51
+ });
52
+
53
+ // Use in JSX - works via toString() coercion
54
+ <button className={button}>Click me</button>
55
+
56
+ // Or access className explicitly
57
+ <button className={button.className}>Click me</button>
58
+ ```
59
+
60
+ ---
61
+
62
+ ## API Reference
63
+
64
+ ### tastyStatic(styles)
65
+
66
+ Creates a `StaticStyle` object from a styles definition.
67
+
68
+ ```tsx
69
+ const card = tastyStatic({
70
+ padding: '4x',
71
+ fill: '#white',
72
+ border: true,
73
+ radius: true,
74
+ });
75
+ ```
76
+
77
+ ### tastyStatic(base, styles)
78
+
79
+ Extends an existing `StaticStyle` with additional styles. Uses `mergeStyles` internally for proper nested selector handling.
80
+
81
+ ```tsx
82
+ const button = tastyStatic({
83
+ padding: '2x 4x',
84
+ fill: '#blue',
85
+ Icon: { color: '#white' },
86
+ });
87
+
88
+ const primaryButton = tastyStatic(button, {
89
+ fill: '#purple',
90
+ Icon: { opacity: 0.8 },
91
+ });
92
+ ```
93
+
94
+ ### tastyStatic(selector, styles)
95
+
96
+ Generates global styles for a CSS selector. The call is removed from the bundle after transformation.
97
+
98
+ ```tsx
99
+ tastyStatic('body', {
100
+ fill: '#surface',
101
+ color: '#text',
102
+ preset: 't3',
103
+ });
104
+ ```
105
+
106
+ ---
107
+
108
+ ## StaticStyle Object
109
+
110
+ | Property | Type | Description |
111
+ |----------|------|-------------|
112
+ | `className` | `string` | Space-separated class names for use in JSX |
113
+ | `styles` | `Styles` | The original (or merged) styles object |
114
+ | `toString()` | `() => string` | Returns `className` for string coercion |
115
+
116
+ ---
117
+
118
+ ## Babel Plugin Configuration
119
+
120
+ ### Basic Configuration
121
+
122
+ ```javascript
123
+ // babel.config.js
124
+ module.exports = {
125
+ plugins: [
126
+ ['@tenphi/tasty/babel-plugin', {
127
+ output: 'public/tasty.css',
128
+ }]
129
+ ]
130
+ };
131
+ ```
132
+
133
+ These examples use `data-schema="dark"` as the root-state convention. If your app already uses a different root attribute such as `data-theme`, keep the same alias pattern and swap the attribute name consistently in your zero-runtime config.
134
+
135
+ ### With Configuration
136
+
137
+ ```javascript
138
+ module.exports = {
139
+ plugins: [
140
+ ['@tenphi/tasty/babel-plugin', {
141
+ output: 'public/tasty.css',
142
+ config: {
143
+ states: {
144
+ '@mobile': '@media(w < 768px)',
145
+ '@tablet': '@media(w < 1024px)',
146
+ '@dark': '@root(schema=dark)',
147
+ },
148
+ devMode: true,
149
+ },
150
+ }]
151
+ ]
152
+ };
153
+ ```
154
+
155
+ ### Plugin Options
156
+
157
+ | Option | Type | Default | Description |
158
+ |--------|------|---------|-------------|
159
+ | `output` | `string` | `'tasty.css'` | Path for generated CSS file |
160
+ | `mode` | `'file' \| 'inject'` | `'file'` | `'file'` writes CSS to disk; `'inject'` embeds CSS inline in JS (see [Inject Mode](#inject-mode)) |
161
+ | `configFile` | `string` | — | Absolute path to a TS/JS module that default-exports a `TastyZeroConfig` object. JSON-serializable alternative to `config` — required for Turbopack. |
162
+ | `config` | `TastyZeroConfig \| () => TastyZeroConfig` | `{}` | Inline config object or factory function. Takes precedence over `configFile`. |
163
+ | `configDeps` | `string[]` | `[]` | Absolute file paths that affect config (for cache invalidation) |
164
+ | `config.states` | `Record<string, string>` | `{}` | Predefined state aliases |
165
+ | `config.devMode` | `boolean` | `false` | Add source comments to CSS |
166
+ | `config.recipes` | `Record<string, RecipeStyles>` | `{}` | Predefined style recipes |
167
+ | `config.fontFace` | `Record<string, FontFaceInput>` | — | Global `@font-face` definitions |
168
+ | `config.counterStyle` | `Record<string, CounterStyleDescriptors>` | — | Global `@counter-style` definitions |
169
+
170
+ ---
171
+
172
+ ## Recipes
173
+
174
+ Recipes work with `tastyStatic` the same way as with runtime `tasty`:
175
+
176
+ ```javascript
177
+ // babel.config.js
178
+ module.exports = {
179
+ plugins: [
180
+ ['@tenphi/tasty/babel-plugin', {
181
+ output: 'public/tasty.css',
182
+ config: {
183
+ recipes: {
184
+ card: { padding: '4x', fill: '#surface', radius: '1r', border: true },
185
+ elevated: { shadow: '2x 2x 4x #shadow' },
186
+ },
187
+ },
188
+ }]
189
+ ]
190
+ };
191
+ ```
192
+
193
+ ```tsx
194
+ import { tastyStatic } from '@tenphi/tasty/static';
195
+
196
+ const card = tastyStatic({
197
+ recipe: 'card elevated',
198
+ color: '#text',
199
+ });
200
+
201
+ <div className={card}>Styled card</div>
202
+ ```
203
+
204
+ ---
205
+
206
+ ## Next.js Integration
207
+
208
+ The `withTastyZero` wrapper configures both **webpack** and **Turbopack** automatically. No `--webpack` flag is needed — it works with whichever bundler Next.js uses.
209
+
210
+ ```typescript
211
+ // next.config.ts
212
+ import { withTastyZero } from '@tenphi/tasty/next';
213
+
214
+ export default withTastyZero({
215
+ output: 'public/tasty.css',
216
+ configFile: './app/tasty-zero.config.ts',
217
+ configDeps: ['./app/theme.ts'],
218
+ })({
219
+ reactStrictMode: true,
220
+ });
221
+ ```
222
+
223
+ ### `withTastyZero` Options
224
+
225
+ | Option | Type | Default | Description |
226
+ |--------|------|---------|-------------|
227
+ | `output` | `string` | `'public/tasty.css'` | Output path for CSS relative to project root |
228
+ | `mode` | `'file' \| 'inject'` | `'file'` | `'file'` writes CSS to disk; `'inject'` embeds CSS inline in JS |
229
+ | `enabled` | `boolean` | `true` | Enable/disable the plugin |
230
+ | `configFile` | `string` | — | Path to a TS/JS module that default-exports `TastyZeroConfig`. Recommended for Turbopack compatibility. |
231
+ | `config` | `TastyZeroConfig` | — | Inline config object. For static configs that don't change during dev. |
232
+ | `configDeps` | `string[]` | `[]` | Extra files the config depends on (for cache invalidation) |
233
+
234
+ ### Turbopack Support
235
+
236
+ Starting with Next.js 16, Turbopack is the default bundler. `withTastyZero` supports it out of the box by injecting `turbopack.rules` with `babel-loader` and JSON-serializable options.
237
+
238
+ The `configFile` option is key for Turbopack — it passes a file path (JSON-serializable) instead of a function, and the Babel plugin loads the config internally via jiti.
239
+
240
+ **Requirements**: `babel-loader` must be installed in your project:
241
+
242
+ ```bash
243
+ pnpm add babel-loader
244
+ ```
245
+
246
+ ### CSS Injection
247
+
248
+ `withTastyZero` automatically injects the generated CSS into your app. Every file that imports from `@tenphi/tasty/static` gets its import replaced with an import of the output CSS file at build time. No manual CSS import is needed.
249
+
250
+ The generated CSS file (e.g. `public/tasty.css`) is created as an empty stub before the first build if it doesn't exist, so there's no chicken-and-egg problem with fresh clones or CI builds. Add it to `.gitignore`:
251
+
252
+ ```gitignore
253
+ public/tasty.css
254
+ ```
255
+
256
+ ---
257
+
258
+ ## Vite Integration
259
+
260
+ ```typescript
261
+ // vite.config.ts
262
+ import { defineConfig } from 'vite';
263
+ import react from '@vitejs/plugin-react';
264
+
265
+ export default defineConfig({
266
+ plugins: [
267
+ react({
268
+ babel: {
269
+ plugins: [
270
+ ['@tenphi/tasty/babel-plugin', {
271
+ output: 'public/tasty.css',
272
+ config: {
273
+ states: { '@mobile': '@media(w < 768px)' },
274
+ },
275
+ }],
276
+ ],
277
+ },
278
+ }),
279
+ ],
280
+ });
281
+ ```
282
+
283
+ ---
284
+
285
+ ## Build Transformation
286
+
287
+ ### Before (Source Code)
288
+
289
+ ```tsx
290
+ import { tastyStatic } from '@tenphi/tasty/static';
291
+
292
+ const button = tastyStatic({
293
+ padding: '2x 4x',
294
+ fill: '#purple',
295
+ color: '#white',
296
+ });
297
+
298
+ tastyStatic('.heading', { preset: 'h1' });
299
+
300
+ export const Button = () => <button className={button}>Click</button>;
301
+ ```
302
+
303
+ ### After (Production Build)
304
+
305
+ ```tsx
306
+ const button = {
307
+ className: 'ts3f2a1b ts8c4d2e',
308
+ styles: { padding: '2x 4x', fill: '#purple', color: '#white' },
309
+ toString() { return this.className; }
310
+ };
311
+
312
+ export const Button = () => <button className={button}>Click</button>;
313
+ ```
314
+
315
+ ### Generated CSS (tasty.css)
316
+
317
+ ```css
318
+ /* Generated by @tenphi/tasty/zero - DO NOT EDIT */
319
+
320
+ .ts3f2a1b.ts3f2a1b {
321
+ padding: 16px 32px;
322
+ }
323
+
324
+ .ts8c4d2e.ts8c4d2e {
325
+ background: #9370db;
326
+ color: #fff;
327
+ }
328
+
329
+ .heading.heading {
330
+ font-size: 2.5rem;
331
+ font-weight: 700;
332
+ line-height: 1.2;
333
+ }
334
+ ```
335
+
336
+ ---
337
+
338
+ ## Inject Mode
339
+
340
+ By default the Babel plugin writes CSS to a file (`mode: 'file'`). **Inject mode** (`mode: 'inject'`) embeds CSS inline in your JavaScript and injects it at runtime via a tiny injector. No CSS file is produced.
341
+
342
+ This is ideal for **reusable components**, **extensions**, and **libraries** where consumers shouldn't need to manage an external CSS file.
343
+
344
+ ### How It Works
345
+
346
+ 1. The Babel plugin extracts CSS at build time (same pipeline as file mode).
347
+ 2. Instead of writing to a `.css` file, the CSS is embedded as string literals in the JS output.
348
+ 3. The `@tenphi/tasty/static` import is rewritten to `@tenphi/tasty/static/inject`.
349
+ 4. Each `tastyStatic` call becomes a self-contained expression that injects its CSS and evaluates to a `StaticStyle` object.
350
+
351
+ ### Configuration
352
+
353
+ ```javascript
354
+ // babel.config.js
355
+ module.exports = {
356
+ plugins: [
357
+ ['@tenphi/tasty/babel-plugin', {
358
+ mode: 'inject',
359
+ config: {
360
+ states: { '@mobile': '@media(w < 768px)' },
361
+ },
362
+ }]
363
+ ]
364
+ };
365
+ ```
366
+
367
+ With Next.js:
368
+
369
+ ```typescript
370
+ // next.config.ts
371
+ import { withTastyZero } from '@tenphi/tasty/next';
372
+
373
+ export default withTastyZero({
374
+ mode: 'inject',
375
+ configFile: './app/tasty-zero.config.ts',
376
+ })({
377
+ reactStrictMode: true,
378
+ });
379
+ ```
380
+
381
+ When `mode` is `'inject'`, the `output` and `injectImport` options are ignored.
382
+
383
+ ### Build Transformation (inject mode)
384
+
385
+ **Before:**
386
+
387
+ ```tsx
388
+ import { tastyStatic } from '@tenphi/tasty/static';
389
+
390
+ const button = tastyStatic({
391
+ padding: '2x 4x',
392
+ fill: '#purple',
393
+ });
394
+
395
+ tastyStatic('.heading', { preset: 'h1' });
396
+ ```
397
+
398
+ **After:**
399
+
400
+ ```tsx
401
+ import { injectCSS as _$i } from '@tenphi/tasty/static/inject';
402
+
403
+ const button = (_$i("ts3f2a1b ts8c4d2e", ".ts3f2a1b.ts3f2a1b{padding:16px 32px}\n.ts8c4d2e.ts8c4d2e{background:#9370db}"), {
404
+ className: 'ts3f2a1b ts8c4d2e',
405
+ styles: { padding: '2x 4x', fill: '#purple' },
406
+ toString() { return this.className; }
407
+ });
408
+
409
+ _$i(".heading", ".heading{font-size:2.5rem;font-weight:700;line-height:1.2}");
410
+ ```
411
+
412
+ ### Dev Mode / HMR
413
+
414
+ Class names are content-hashed (`ts` + MD5). When styles change, a new hash produces a new `_$i` call that injects fresh CSS. The injector deduplicates by id, so unchanged styles are skipped. Old CSS stays in the DOM but is harmless since no elements reference those class names.
415
+
416
+ ### Limitations (inject mode)
417
+
418
+ - **Client-side only** — Styles are injected via the DOM, so they are not available during SSR. For server-rendered apps, use `mode: 'file'` or the runtime `tasty()`.
419
+ - **Larger JS bundle** — CSS is embedded in JavaScript, increasing bundle size. Best suited for components and extensions, not full-app styling.
420
+
421
+ ---
422
+
423
+ ## Style Extension
424
+
425
+ ```tsx
426
+ // Base button
427
+ const button = tastyStatic({
428
+ display: 'inline-flex',
429
+ padding: '2x 4x',
430
+ radius: '1r',
431
+ fill: '#gray.20',
432
+ color: '#text',
433
+ transition: 'fill 0.15s',
434
+ });
435
+
436
+ // Variants
437
+ const primaryButton = tastyStatic(button, {
438
+ fill: '#purple',
439
+ color: '#white',
440
+ });
441
+
442
+ const dangerButton = tastyStatic(button, {
443
+ fill: '#danger',
444
+ color: '#white',
445
+ });
446
+ ```
447
+
448
+ ---
449
+
450
+ ## State-based Styling
451
+
452
+ ```tsx
453
+ const card = tastyStatic({
454
+ padding: {
455
+ '': '4x',
456
+ '@mobile': '2x',
457
+ },
458
+ display: {
459
+ '': 'flex',
460
+ '@mobile': 'block',
461
+ },
462
+ });
463
+ ```
464
+
465
+ ---
466
+
467
+ ## Extending Style Types (TypeScript)
468
+
469
+ If you add custom style properties, use module augmentation so `tastyStatic` recognizes them too. See [Extending Style Types](configuration.md#extending-style-types-typescript) in the configuration docs.
470
+
471
+ ---
472
+
473
+ ## Limitations
474
+
475
+ 1. **Static values only** — All style values must be known at build time
476
+ 2. **No runtime props** — Cannot use `styleProps` or dynamic `styles` prop
477
+ 3. **No mods at runtime** — Modifiers must be defined statically
478
+ 4. **Build-time transformation required** — Babel plugin must process files
479
+
480
+ ### Workarounds
481
+
482
+ For dynamic styling needs, combine with regular CSS or CSS variables:
483
+
484
+ ```tsx
485
+ const card = tastyStatic({
486
+ padding: '4x',
487
+ fill: 'var(--card-bg, #white)',
488
+ });
489
+
490
+ <div
491
+ className={card}
492
+ style={{ '--card-bg': isActive ? '#purple' : '#white' }}
493
+ />
494
+ ```
495
+
496
+ ---
497
+
498
+ ## Best Practices
499
+
500
+ 1. **Define base styles** for common patterns, then extend for variants
501
+ 2. **Use selector mode** for global/body styles
502
+ 3. **Enable devMode** in development for easier debugging
503
+ 4. **Configure states** for consistent responsive breakpoints
504
+
505
+ ---
506
+
507
+ ## Common Issues
508
+
509
+ - No CSS file is generated: make sure the Babel plugin actually runs for files importing `@tenphi/tasty/static`, and verify the `output` path is writable.
510
+ - Styles stay dynamic by mistake: `tastyStatic()` only supports build-time-known values. Move runtime values to CSS variables or switch that component to runtime `tasty()`.
511
+ - Turbopack config behaves inconsistently: prefer `configFile` over inline functions so the setup stays JSON-serializable.
512
+
513
+ ---
514
+
515
+ ## Related
516
+
517
+ - [Docs Hub](README.md) — Choose the right guide by task or rendering mode
518
+ - [Style DSL](dsl.md) — State maps, tokens, units, extending semantics (shared by runtime and static)
519
+ - [Runtime API](runtime.md) — Runtime styling: `tasty()` factory, component props, variants, sub-elements, hooks
520
+ - [Configuration](configuration.md) — Global configuration: tokens, recipes, custom units, and style handlers