@tenphi/tasty 0.0.0-snapshot.dffd134 → 0.0.0-snapshot.e01a0ee
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.
- package/README.md +436 -394
- package/dist/babel-types-BKDTT4--.d.ts +18 -0
- package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
- package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
- package/dist/chunks/build-config-DlxpZKk_.js +60 -0
- package/dist/chunks/build-config-DlxpZKk_.js.map +1 -0
- package/dist/{collector-UWhVKseF.js → chunks/collector-B4-yqFEs.js} +25 -119
- package/dist/chunks/collector-B4-yqFEs.js.map +1 -0
- package/dist/chunks/config-engine-DJsb5WYu.js +272 -0
- package/dist/chunks/config-engine-DJsb5WYu.js.map +1 -0
- package/dist/chunks/config-file-DlZXJMj8.js +25 -0
- package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
- package/dist/chunks/css-definitions-DW1TGGiy.js +910 -0
- package/dist/chunks/css-definitions-DW1TGGiy.js.map +1 -0
- package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
- package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
- package/dist/chunks/debug-DMMwe1rY.js +502 -0
- package/dist/chunks/debug-DMMwe1rY.js.map +1 -0
- package/dist/chunks/dsl-DYSJc1-T.js +1383 -0
- package/dist/chunks/dsl-DYSJc1-T.js.map +1 -0
- package/dist/chunks/hydration-TRcz5vnk.js +41 -0
- package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
- package/dist/chunks/react-runtime-DhPtFlZs.js +689 -0
- package/dist/chunks/react-runtime-DhPtFlZs.js.map +1 -0
- package/dist/chunks/runtime-engine-BlrVXv8l.js +2432 -0
- package/dist/chunks/runtime-engine-BlrVXv8l.js.map +1 -0
- package/dist/chunks/runtime-state-BLyMRYFF.js +152 -0
- package/dist/chunks/runtime-state-BLyMRYFF.js.map +1 -0
- package/dist/{merge-styles-CVCZ4hgD.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
- package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
- package/dist/chunks/style-engine-of5Xbc27.js +5571 -0
- package/dist/chunks/style-engine-of5Xbc27.js.map +1 -0
- package/dist/{css-writer-DEkJuPH6.js → chunks/zero-engine-D2jPSpWA.js} +65 -145
- package/dist/chunks/zero-engine-D2jPSpWA.js.map +1 -0
- package/dist/{collector-BPzZezAG.d.ts → collector-CTU-nl0g.d.ts} +23 -4
- package/dist/{config-D2INrjr_.d.ts → config-CcxqSZI2.d.ts} +274 -78
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/hydrate-CRyjjAyl.d.ts +22 -0
- package/dist/{index-BAAbdfRs.d.ts → index--GdqCPlp.d.ts} +366 -257
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -867
- package/dist/{merge-styles-NEvqayL_.d.ts → merge-styles-DSkVc6CD.d.ts} +2 -3
- package/dist/ssr/astro-client.d.ts +1 -1
- package/dist/ssr/astro-client.js +1 -14
- package/dist/ssr/astro-client.js.map +1 -1
- package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract-static.js +9 -0
- package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
- package/dist/ssr/astro-middleware-extract.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract.js +9 -0
- package/dist/ssr/astro-middleware-extract.js.map +1 -0
- package/dist/ssr/astro-middleware-static.d.ts +3 -2
- package/dist/ssr/astro-middleware-static.js +0 -11
- package/dist/ssr/astro-middleware-static.js.map +1 -1
- package/dist/ssr/astro-middleware.d.ts +3 -2
- package/dist/ssr/astro-middleware.js +0 -12
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +40 -6
- package/dist/ssr/astro.js +157 -93
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +2 -0
- package/dist/ssr/index.d.ts +5 -25
- package/dist/ssr/index.js +5 -5
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +64 -0
- package/dist/ssr/next-config.js +123 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +9 -8
- package/dist/ssr/next.js +29 -43
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +8 -9
- package/dist/static/index.js +4 -22
- package/dist/static/index.js.map +1 -1
- package/dist/static/inject.d.ts +1 -2
- package/dist/{index-l_NdJSUS.d.ts → types-DJEM_BOJ.d.ts} +751 -590
- package/dist/zero/babel.d.ts +67 -2
- package/dist/zero/babel.js +77 -140
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +62 -8
- package/dist/zero/index.js +24 -2
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +4 -5
- package/dist/zero/next.js +3 -38
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +16 -8
- package/docs/adoption.md +69 -36
- package/docs/ai-agents.md +122 -85
- package/docs/comparison.md +77 -47
- package/docs/configuration.md +435 -108
- package/docs/debug.md +21 -8
- package/docs/design-system.md +152 -31
- package/docs/dsl.md +497 -211
- package/docs/getting-started.md +130 -50
- package/docs/injector.md +117 -68
- package/docs/methodology.md +81 -50
- package/docs/migration-v3.md +52 -52
- package/docs/pipeline.md +55 -31
- package/docs/plugins.md +59 -75
- package/docs/react-api.md +139 -53
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +285 -101
- package/docs/styles.md +128 -33
- package/docs/tasty-static.md +272 -135
- package/package.json +119 -39
- package/dist/async-storage-DKK-wTD4.js +0 -44
- package/dist/async-storage-DKK-wTD4.js.map +0 -1
- package/dist/babel-HlEpSZrj.d.ts +0 -83
- package/dist/collector-UWhVKseF.js.map +0 -1
- package/dist/config-BCuFlC1I.js +0 -12180
- package/dist/config-BCuFlC1I.js.map +0 -1
- package/dist/context-CA8YKeMn.js +0 -24
- package/dist/context-CA8YKeMn.js.map +0 -1
- package/dist/core-CbMYIizf.js +0 -1550
- package/dist/core-CbMYIizf.js.map +0 -1
- package/dist/css-writer-DEkJuPH6.js.map +0 -1
- package/dist/format-global-rules-DklyaXv-.js +0 -22
- package/dist/format-global-rules-DklyaXv-.js.map +0 -1
- package/dist/format-rules-D2J4PbR5.js +0 -143
- package/dist/format-rules-D2J4PbR5.js.map +0 -1
- package/dist/hydrate-lZeNoz_w.js +0 -37
- package/dist/hydrate-lZeNoz_w.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-BUMyAa-Q.js +0 -424
- package/dist/keyframes-BUMyAa-Q.js.map +0 -1
- package/dist/merge-styles-CVCZ4hgD.js.map +0 -1
- package/dist/resolve-recipes-BnMC1WW1.js +0 -144
- package/dist/resolve-recipes-BnMC1WW1.js.map +0 -1
package/docs/tasty-static.md
CHANGED
|
@@ -1,35 +1,43 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Build-Time Extraction (`tastyStatic`)
|
|
2
2
|
|
|
3
|
-
`tastyStatic` is
|
|
3
|
+
`tastyStatic` is Tasty's framework-agnostic build-time utility for extracting CSS before rendering. It produces no client styling runtime in file mode, but it is not the only way to achieve zero-runtime delivery: server-only `tasty()` also ships no Tasty runtime to the browser while retaining the full React component API. Astro's `tastyIntegration({ islands: false })` is the clearest example; the same architecture applies to server-only Next.js RSC.
|
|
4
|
+
|
|
5
|
+
Choose `tastyStatic` specifically when styles must be generated during the build, when the consumer is not React, or when you want static class-name objects instead of components. For the broader docs map, see the [Docs Hub](README.md).
|
|
4
6
|
|
|
5
7
|
---
|
|
6
8
|
|
|
7
9
|
## When to Use
|
|
8
10
|
|
|
9
|
-
- **
|
|
10
|
-
- **No
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
11
|
+
- **CSS that must exist before anything renders** — static sites, landing pages, and HTML served from a CDN get one stylesheet generated at build time
|
|
12
|
+
- **No React at runtime** — `tastyStatic` returns class names, so plain DOM code or any templating that sets `class` can use them; the [Programmatic API](#programmatic-api) covers frameworks Babel does not process
|
|
13
|
+
- **Class-name objects instead of components** — extend them with `tastyStatic(base, styles)` and pass them wherever a `className` goes
|
|
14
|
+
- **Self-contained packages** — [inject mode](#inject-mode) embeds the CSS in the JavaScript, so consumers have no stylesheet to wire up
|
|
15
|
+
|
|
16
|
+
If the styles depend on props, keep `tasty()`: rendered only on the server, it also ships no styling runtime (see [Server-Side Rendering](ssr.md)).
|
|
13
17
|
|
|
14
18
|
## Requirements
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
Build-time extraction is part of the main `@tenphi/tasty` package but requires additional peer dependencies depending on your setup:
|
|
17
21
|
|
|
18
|
-
| Dependency
|
|
19
|
-
|
|
20
|
-
| `@babel/core`
|
|
21
|
-
| `@babel/helper-plugin-utils` | >= 7.24 | Babel plugin
|
|
22
|
-
| `@babel/types`
|
|
23
|
-
| `jiti`
|
|
22
|
+
| Dependency | Version | Required for |
|
|
23
|
+
| ---------------------------- | ------- | ---------------------------------------------------- |
|
|
24
|
+
| `@babel/core` | >= 7.24 | Babel plugin (`@tenphi/tasty/babel-plugin`) |
|
|
25
|
+
| `@babel/helper-plugin-utils` | >= 7.24 | Babel plugin |
|
|
26
|
+
| `@babel/types` | >= 7.24 | Babel plugin |
|
|
27
|
+
| `jiti` | >= 2.6 | `configFile` only (Babel plugin and Next.js wrapper) |
|
|
28
|
+
| `babel-loader` | any | Next.js wrapper (`@tenphi/tasty/zero/next`) |
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
The Babel packages and `jiti` are optional peer dependencies of `@tenphi/tasty`; `babel-loader` is resolved from your project. `jiti` is loaded only to read a `configFile`, so a setup that passes `config` directly does not need it; without it, `configFile` fails with an error that says to install it. Install what your setup requires:
|
|
26
31
|
|
|
27
32
|
```bash
|
|
28
|
-
#
|
|
33
|
+
# Any Babel-based setup (Vite, custom Babel config, etc.)
|
|
29
34
|
pnpm add -D @babel/core @babel/helper-plugin-utils @babel/types
|
|
30
35
|
|
|
31
|
-
#
|
|
32
|
-
pnpm add -D @babel/core @babel/helper-plugin-utils @babel/types
|
|
36
|
+
# Next.js
|
|
37
|
+
pnpm add -D @babel/core @babel/helper-plugin-utils @babel/types babel-loader
|
|
38
|
+
|
|
39
|
+
# Either, with configFile
|
|
40
|
+
pnpm add -D jiti
|
|
33
41
|
```
|
|
34
42
|
|
|
35
43
|
---
|
|
@@ -50,13 +58,15 @@ const button = tastyStatic({
|
|
|
50
58
|
radius: '1r',
|
|
51
59
|
});
|
|
52
60
|
|
|
53
|
-
// Use in JSX
|
|
54
|
-
<button className={button}>Click me</button
|
|
61
|
+
// Use in JSX
|
|
62
|
+
<button className={button.className}>Click me</button>;
|
|
55
63
|
|
|
56
|
-
//
|
|
57
|
-
|
|
64
|
+
// toString() returns the class name, for template strings and plain JS
|
|
65
|
+
element.className = `${button} is-active`;
|
|
58
66
|
```
|
|
59
67
|
|
|
68
|
+
In TSX, pass `button.className`: React types `className` as `string`, so passing the `StaticStyle` object fails type-checking even though it works at runtime.
|
|
69
|
+
|
|
60
70
|
---
|
|
61
71
|
|
|
62
72
|
## API Reference
|
|
@@ -103,15 +113,17 @@ tastyStatic('body', {
|
|
|
103
113
|
});
|
|
104
114
|
```
|
|
105
115
|
|
|
116
|
+
The selector can be a list (`'.uni-checkbox, uni-checkbox'`): every item gets the states and sub-elements. Local `@keyframes` and `@starting` states work as in `tastyStatic(styles)`.
|
|
117
|
+
|
|
106
118
|
---
|
|
107
119
|
|
|
108
120
|
## StaticStyle Object
|
|
109
121
|
|
|
110
|
-
| Property
|
|
111
|
-
|
|
112
|
-
| `className`
|
|
113
|
-
| `styles`
|
|
114
|
-
| `toString()` | `() => string` | Returns `className` for string coercion
|
|
122
|
+
| Property | Type | Description |
|
|
123
|
+
| ------------ | -------------- | ------------------------------------------ |
|
|
124
|
+
| `className` | `string` | Space-separated class names for use in JSX |
|
|
125
|
+
| `styles` | `Styles` | The original (or merged) styles object |
|
|
126
|
+
| `toString()` | `() => string` | Returns `className` for string coercion |
|
|
115
127
|
|
|
116
128
|
---
|
|
117
129
|
|
|
@@ -123,67 +135,74 @@ tastyStatic('body', {
|
|
|
123
135
|
// babel.config.js
|
|
124
136
|
module.exports = {
|
|
125
137
|
plugins: [
|
|
126
|
-
[
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
[
|
|
139
|
+
'@tenphi/tasty/babel-plugin',
|
|
140
|
+
{
|
|
141
|
+
output: 'public/tasty.css',
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
],
|
|
130
145
|
};
|
|
131
146
|
```
|
|
132
147
|
|
|
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
|
|
148
|
+
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 build-time config.
|
|
134
149
|
|
|
135
150
|
### With Configuration
|
|
136
151
|
|
|
137
152
|
```javascript
|
|
138
153
|
module.exports = {
|
|
139
154
|
plugins: [
|
|
140
|
-
[
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
155
|
+
[
|
|
156
|
+
'@tenphi/tasty/babel-plugin',
|
|
157
|
+
{
|
|
158
|
+
output: 'public/tasty.css',
|
|
159
|
+
config: {
|
|
160
|
+
states: {
|
|
161
|
+
'@mobile': '@media(w < 768px)',
|
|
162
|
+
'@tablet': '@media(w < 1024px)',
|
|
163
|
+
'@dark': '@root(schema=dark)',
|
|
164
|
+
},
|
|
165
|
+
devMode: true,
|
|
147
166
|
},
|
|
148
|
-
devMode: true,
|
|
149
167
|
},
|
|
150
|
-
|
|
151
|
-
]
|
|
168
|
+
],
|
|
169
|
+
],
|
|
152
170
|
};
|
|
153
171
|
```
|
|
154
172
|
|
|
155
173
|
### Plugin Options
|
|
156
174
|
|
|
157
|
-
| Option
|
|
158
|
-
|
|
159
|
-
| `output`
|
|
160
|
-
| `mode`
|
|
161
|
-
| `configFile`
|
|
162
|
-
| `config`
|
|
163
|
-
| `configDeps`
|
|
164
|
-
| `injectImport`
|
|
165
|
-
| `config.states`
|
|
166
|
-
| `config.devMode`
|
|
167
|
-
| `config.tokens`
|
|
168
|
-
| `config.replaceTokens`
|
|
169
|
-
| `config.recipes`
|
|
170
|
-
| `config.keyframes`
|
|
171
|
-
| `config.fontFaces`
|
|
172
|
-
| `config.counterStyles`
|
|
173
|
-
| `config.
|
|
174
|
-
| `config.
|
|
175
|
-
| `config.
|
|
176
|
-
| `config.
|
|
177
|
-
| `config.
|
|
178
|
-
| `config.
|
|
179
|
-
| `config.
|
|
180
|
-
| `config.
|
|
181
|
-
| `config.
|
|
182
|
-
| `config.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
175
|
+
| Option | Type | Default | Description |
|
|
176
|
+
| -------------------------- | ------------------------------------------------ | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
177
|
+
| `output` | `string` | `'tasty.css'` | Path for generated CSS file |
|
|
178
|
+
| `mode` | `'file' \| 'inject'` | `'file'` | `'file'` writes CSS to disk; `'inject'` embeds CSS inline in JS (see [Inject Mode](#inject-mode)) |
|
|
179
|
+
| `configFile` | `string` | — | Absolute path to a TS/JS module that default-exports a `TastyZeroConfig` object. JSON-serializable alternative to `config` — required for Turbopack. Loaded with the optional `jiti` peer. |
|
|
180
|
+
| `config` | `TastyZeroConfig \| () => TastyZeroConfig` | `{}` | Inline config object or factory function. Takes precedence over `configFile`. |
|
|
181
|
+
| `configDeps` | `string[]` | `[]` | Absolute file paths that affect config (for cache invalidation) |
|
|
182
|
+
| `injectImport` | `boolean` | `true` | Replace `@tenphi/tasty/static` imports with an import of the generated CSS file. Set to `false` to manage CSS imports manually. |
|
|
183
|
+
| `config.states` | `Record<string, string>` | `{}` | Predefined state aliases (e.g. `{ '@mobile': '@media(w < 768px)' }`) |
|
|
184
|
+
| `config.devMode` | `boolean` | `false` | Add source comments to CSS |
|
|
185
|
+
| `config.tokens` | `ConfigTokens` | — | Design tokens injected as CSS custom properties on `:root`. Values are parsed through the Tasty DSL. Supports state maps for responsive/themed tokens. |
|
|
186
|
+
| `config.replaceTokens` | `Record<string, string \| number>` | — | Parse-time token substitution. Keys use `$name` for custom properties and `#name` for color tokens. |
|
|
187
|
+
| `config.recipes` | `Record<string, RecipeStyles>` | `{}` | Predefined style recipes |
|
|
188
|
+
| `config.keyframes` | `Record<string, KeyframesSteps>` | — | Global `@keyframes` definitions available to all `tastyStatic` calls |
|
|
189
|
+
| `config.fontFaces` | `Record<string, FontFaceInput>` | — | Global `@font-face` definitions |
|
|
190
|
+
| `config.counterStyles` | `Record<string, CounterStyleDescriptors>` | — | Global `@counter-style` definitions |
|
|
191
|
+
| `config.properties` | `Record<string, PropertyDefinition>` | — | Global `@property` definitions, written with Tasty's [default properties](dsl.md#default-properties) |
|
|
192
|
+
| `config.units` | `Record<string, string \| UnitHandler>` | — | Custom units for the style parser (merged with built-ins). E.g. `{ u: 'var(--u)' }` makes `2u` compile to `calc(2 * var(--u))`. Native CSS units need no entry |
|
|
193
|
+
| `config.functions` | `Record<string, FunctionDefinition \| Function>` | — | Custom functions (merged). Bare keys → parse functions; `$$name` keys → declarative CSS `@function` definitions |
|
|
194
|
+
| `config.polyfills` | `{ functions?: boolean }` | `{}` | Opt-in polyfills. `functions: true` inlines `@function` calls into plain CSS at build time |
|
|
195
|
+
| `config.plugins` | `TastyPlugin[]` | — | Plugins that extend tasty with custom functions, units, states, and handlers |
|
|
196
|
+
| `config.handlers` | `Record<string, StyleHandlerDefinition>` | — | Custom style handlers that transform style properties into CSS declarations |
|
|
197
|
+
| `config.presets` | `Record<string, TypographyPreset>` | — | Typography presets — shorthand for `generateTypographyTokens()`. Generated tokens merge under explicit `tokens`. |
|
|
198
|
+
| `config.globalStyles` | `Record<string, Styles>` | — | Global Tasty styles keyed by CSS selector. Supports the full style syntax. |
|
|
199
|
+
| `config.autoPropertyTypes` | `boolean` | `true` | Automatically infer and register CSS `@property` declarations from values |
|
|
200
|
+
| `config.parserCacheSize` | `number` | `1000` | Parser LRU cache size. Larger values improve performance for builds with many unique style values |
|
|
201
|
+
| `config.namePrefix` | `string` | `'ts'` | Prefix prepended to every generated identifier. Defaults to `'ts'` so static classes never collide with runtime (`'t'`) classes. See [Configuration: Name prefix](configuration.md#name-prefix). |
|
|
202
|
+
|
|
203
|
+
### Coexisting with `tasty()`
|
|
204
|
+
|
|
205
|
+
When a page mixes `tastyStatic` with `tasty`, both must use **different** `namePrefix` values. The defaults handle this automatically (`'t'` for React rendering, `'ts'` for build-time extraction). If you customize one, customize the other:
|
|
187
206
|
|
|
188
207
|
```ts
|
|
189
208
|
// tasty-zero.config.ts (Babel plugin)
|
|
@@ -191,7 +210,7 @@ export default { namePrefix: 'mbs' };
|
|
|
191
210
|
```
|
|
192
211
|
|
|
193
212
|
```ts
|
|
194
|
-
// app entry (
|
|
213
|
+
// app entry (`tasty()` configure)
|
|
195
214
|
configure({ namePrefix: 'mb' });
|
|
196
215
|
```
|
|
197
216
|
|
|
@@ -205,16 +224,24 @@ Recipes work with `tastyStatic` the same way as with runtime `tasty`:
|
|
|
205
224
|
// babel.config.js
|
|
206
225
|
module.exports = {
|
|
207
226
|
plugins: [
|
|
208
|
-
[
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
227
|
+
[
|
|
228
|
+
'@tenphi/tasty/babel-plugin',
|
|
229
|
+
{
|
|
230
|
+
output: 'public/tasty.css',
|
|
231
|
+
config: {
|
|
232
|
+
recipes: {
|
|
233
|
+
card: {
|
|
234
|
+
padding: '4x',
|
|
235
|
+
fill: '#surface',
|
|
236
|
+
radius: '1r',
|
|
237
|
+
border: true,
|
|
238
|
+
},
|
|
239
|
+
elevated: { shadow: '2x 2x 4x #shadow' },
|
|
240
|
+
},
|
|
214
241
|
},
|
|
215
242
|
},
|
|
216
|
-
|
|
217
|
-
]
|
|
243
|
+
],
|
|
244
|
+
],
|
|
218
245
|
};
|
|
219
246
|
```
|
|
220
247
|
|
|
@@ -226,7 +253,7 @@ const card = tastyStatic({
|
|
|
226
253
|
color: '#text',
|
|
227
254
|
});
|
|
228
255
|
|
|
229
|
-
<div className={card}>Styled card</div
|
|
256
|
+
<div className={card.className}>Styled card</div>;
|
|
230
257
|
```
|
|
231
258
|
|
|
232
259
|
---
|
|
@@ -250,25 +277,25 @@ export default withTastyZero({
|
|
|
250
277
|
|
|
251
278
|
### `withTastyZero` Options
|
|
252
279
|
|
|
253
|
-
| Option
|
|
254
|
-
|
|
255
|
-
| `output`
|
|
256
|
-
| `mode`
|
|
257
|
-
| `enabled`
|
|
258
|
-
| `configFile` | `string`
|
|
259
|
-
| `config`
|
|
260
|
-
| `configDeps` | `string[]`
|
|
280
|
+
| Option | Type | Default | Description |
|
|
281
|
+
| ------------ | -------------------- | -------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
282
|
+
| `output` | `string` | `'public/tasty.css'` | Output path for CSS relative to project root |
|
|
283
|
+
| `mode` | `'file' \| 'inject'` | `'file'` | `'file'` writes CSS to disk; `'inject'` embeds CSS inline in JS |
|
|
284
|
+
| `enabled` | `boolean` | `true` | Enable/disable the plugin |
|
|
285
|
+
| `configFile` | `string` | — | Path to a TS/JS module that default-exports `TastyZeroConfig`. Recommended for Turbopack compatibility. |
|
|
286
|
+
| `config` | `TastyZeroConfig` | — | Inline config object. For static configs that don't change during dev. |
|
|
287
|
+
| `configDeps` | `string[]` | `[]` | Extra files the config depends on (for cache invalidation) |
|
|
261
288
|
|
|
262
289
|
### Turbopack Support
|
|
263
290
|
|
|
264
291
|
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.
|
|
265
292
|
|
|
266
|
-
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.
|
|
293
|
+
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`, which must be installed.
|
|
267
294
|
|
|
268
|
-
**Requirements**: `babel-loader` must be installed in your project:
|
|
295
|
+
**Requirements**: `babel-loader` must be installed in your project (see [Requirements](#requirements)):
|
|
269
296
|
|
|
270
297
|
```bash
|
|
271
|
-
pnpm add babel-loader
|
|
298
|
+
pnpm add -D babel-loader
|
|
272
299
|
```
|
|
273
300
|
|
|
274
301
|
### CSS Injection
|
|
@@ -283,31 +310,95 @@ public/tasty.css
|
|
|
283
310
|
|
|
284
311
|
---
|
|
285
312
|
|
|
313
|
+
## Programmatic API
|
|
314
|
+
|
|
315
|
+
`@tenphi/tasty/zero` turns styles into CSS in Node without Babel or React — for build scripts, or CSS shipped to other frameworks:
|
|
316
|
+
|
|
317
|
+
```ts
|
|
318
|
+
import {
|
|
319
|
+
configure,
|
|
320
|
+
extractStylesForSelector,
|
|
321
|
+
extractStylesWithChunks,
|
|
322
|
+
} from '@tenphi/tasty/zero';
|
|
323
|
+
|
|
324
|
+
configure({
|
|
325
|
+
units: { u: 'var(--unit)' },
|
|
326
|
+
states: { '@dark': '@root(schema=dark)' },
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
extractStylesForSelector('.card', { padding: '2u', fill: '#surface' }).css;
|
|
330
|
+
// → '.card { padding: calc(2 * var(--unit)); background-color: … }'
|
|
331
|
+
|
|
332
|
+
extractStylesWithChunks({ display: 'flex', gap: '1u' });
|
|
333
|
+
// → [{ className: 'ts…', css: '.ts….ts… { … }' }]
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
`configure()` takes the same options as the Babel plugin's `config` (see [Plugin Options](#plugin-options)) and replaces the previous configuration on each call; `resetConfig()` returns to the defaults. Options that shape the extracted rules apply — `states`, `units`, parse `functions`, `handlers`, `replaceTokens`, `recipes`, `plugins`, `namePrefix`. Definitions that become at-rules or global CSS of their own are not emitted with the rules: `tokens`, `globalStyles`, `fontFaces`, `counterStyles`, `properties` and `$$` `@function` definitions. Render tokens and global styles with `extractStylesForSelector(':root', tokens)` and `extractStylesForSelector(selector, styles)`.
|
|
337
|
+
|
|
338
|
+
`extractConfigProperties()` returns the `@property` rules the Babel plugin writes at the top of its output: Tasty's [default set](dsl.md#default-properties) (`#border`, `#outline`, `$gap`, `$radius`, `$transition`, …) overlaid with the configured `properties`, or with the `properties` map you pass it. Emit them once per stylesheet. Style handlers read several of these tokens with no fallback of their own (`border: true` reads `#border`, `transition` reads `$transition`), so without them those declarations resolve to nothing.
|
|
339
|
+
|
|
340
|
+
The configuration is process-wide and shared with the Babel plugin and the runtime `configure()` from `@tenphi/tasty`. The extractors re-apply their own configuration when the Babel plugin replaced it, but not after a runtime `configure()` — don't mix the runtime and build-time configuration in one process.
|
|
341
|
+
|
|
342
|
+
`extractStylesForSelector()` output starts with the `@keyframes` its rules animate — local `@keyframes` and configured `keyframes` — under hashed names the `animation` declarations are rewritten to. `extractStylesWithChunks()` returns class rules only.
|
|
343
|
+
|
|
344
|
+
To write the results to a file the way the Babel plugin does, use `createCSSWriter()`. It deduplicates blocks by key and prepends the generated-file header:
|
|
345
|
+
|
|
346
|
+
```ts
|
|
347
|
+
import {
|
|
348
|
+
createCSSWriter,
|
|
349
|
+
extractConfigProperties,
|
|
350
|
+
extractStylesWithChunks,
|
|
351
|
+
} from '@tenphi/tasty/zero';
|
|
352
|
+
|
|
353
|
+
const writer = createCSSWriter('dist/tasty.css', { devMode: true });
|
|
354
|
+
|
|
355
|
+
for (const prop of extractConfigProperties()) {
|
|
356
|
+
writer.add(`@property:${prop.name}`, prop.css);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
for (const chunk of extractStylesWithChunks({ display: 'flex', gap: '1u' })) {
|
|
360
|
+
writer.add(chunk.className, chunk.css, 'src/card.ts'); // source is a devMode comment
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
writer.write(); // also: has(key), getCSS(), clear(), getOutputPath()
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
286
368
|
## Vite Integration
|
|
287
369
|
|
|
370
|
+
`@vitejs/plugin-react` 6 no longer runs Babel; add it with `@rolldown/plugin-babel` (`pnpm add -D @rolldown/plugin-babel`):
|
|
371
|
+
|
|
288
372
|
```typescript
|
|
289
373
|
// vite.config.ts
|
|
290
374
|
import { defineConfig } from 'vite';
|
|
291
375
|
import react from '@vitejs/plugin-react';
|
|
376
|
+
import babel from '@rolldown/plugin-babel';
|
|
292
377
|
|
|
293
378
|
export default defineConfig({
|
|
294
379
|
plugins: [
|
|
295
|
-
react(
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
380
|
+
react(),
|
|
381
|
+
babel({
|
|
382
|
+
plugins: [
|
|
383
|
+
[
|
|
384
|
+
'@tenphi/tasty/babel-plugin',
|
|
385
|
+
{
|
|
386
|
+
output: 'src/tasty.css',
|
|
300
387
|
config: {
|
|
301
388
|
states: { '@mobile': '@media(w < 768px)' },
|
|
302
389
|
},
|
|
303
|
-
}
|
|
390
|
+
},
|
|
304
391
|
],
|
|
305
|
-
|
|
392
|
+
],
|
|
306
393
|
}),
|
|
307
394
|
],
|
|
308
395
|
});
|
|
309
396
|
```
|
|
310
397
|
|
|
398
|
+
With `@vitejs/plugin-react` 5 or older, pass the same `plugins` array to `react({ babel: { plugins } })` instead.
|
|
399
|
+
|
|
400
|
+
Keep `output` outside `public/`: the plugin replaces each `@tenphi/tasty/static` import with an import of the generated file, and Vite does not let JavaScript import files from `public/`. Vite then bundles the CSS like any other stylesheet.
|
|
401
|
+
|
|
311
402
|
---
|
|
312
403
|
|
|
313
404
|
## Build Transformation
|
|
@@ -325,42 +416,67 @@ const button = tastyStatic({
|
|
|
325
416
|
|
|
326
417
|
tastyStatic('.heading', { preset: 'h1' });
|
|
327
418
|
|
|
328
|
-
export const Button = () => <button className={button}>Click</button>;
|
|
419
|
+
export const Button = () => <button className={button.className}>Click</button>;
|
|
329
420
|
```
|
|
330
421
|
|
|
331
422
|
### After (Production Build)
|
|
332
423
|
|
|
333
424
|
```tsx
|
|
425
|
+
import './tasty.css';
|
|
426
|
+
|
|
334
427
|
const button = {
|
|
335
|
-
className: '
|
|
428
|
+
className: 'ts3f783b ts070801',
|
|
336
429
|
styles: { padding: '2x 4x', fill: '#purple', color: '#white' },
|
|
337
|
-
toString() {
|
|
430
|
+
toString() {
|
|
431
|
+
return this.className;
|
|
432
|
+
},
|
|
338
433
|
};
|
|
339
434
|
|
|
340
|
-
export const Button = () => <button className={button}>Click</button>;
|
|
435
|
+
export const Button = () => <button className={button.className}>Click</button>;
|
|
341
436
|
```
|
|
342
437
|
|
|
438
|
+
The `@tenphi/tasty/static` import becomes an import of the generated file (relative to the source file), and the selector-mode call is removed.
|
|
439
|
+
|
|
343
440
|
### Generated CSS (tasty.css)
|
|
344
441
|
|
|
345
442
|
```css
|
|
346
443
|
/* Generated by @tenphi/tasty/zero - DO NOT EDIT */
|
|
347
444
|
|
|
348
|
-
|
|
349
|
-
|
|
445
|
+
@property --tasty-second-fill-color {
|
|
446
|
+
syntax: '<color>';
|
|
447
|
+
inherits: false;
|
|
448
|
+
initial-value: transparent;
|
|
350
449
|
}
|
|
351
450
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
451
|
+
@property --current-color {
|
|
452
|
+
syntax: '<color>';
|
|
453
|
+
inherits: true;
|
|
454
|
+
initial-value: currentcolor;
|
|
355
455
|
}
|
|
356
456
|
|
|
357
|
-
.
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
457
|
+
/* …the rest of Tasty's default @property rules (--white-color, --border-color, --gap, --transition, …), then config.properties */
|
|
458
|
+
|
|
459
|
+
.ts3f783b.ts3f783b {
|
|
460
|
+
color: var(--white-color);
|
|
461
|
+
--current-color: var(--white-color);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
.ts3f783b.ts3f783b {
|
|
465
|
+
background-color: var(--purple-color);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
.ts070801.ts070801 {
|
|
469
|
+
padding: 16px 32px;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
.heading {
|
|
473
|
+
font-size: var(--h1-font-size, var(--default-font-size));
|
|
474
|
+
/* …line-height, letter-spacing, font-weight, and the rest of the h1 preset */
|
|
361
475
|
}
|
|
362
476
|
```
|
|
363
477
|
|
|
478
|
+
The file starts with Tasty's [default `@property` rules](dsl.md#default-properties) and your `config.properties`, written once. Styles are split into chunks (here appearance and spacing), each with its own class. Color tokens compile to custom properties: `#purple` becomes `var(--purple-color)`. Define it in `config.tokens` and the plugin writes it to `:root` at the top of the same file. Units are literal (`2x` is `16px`). Selector-mode rules use the selector as written, without the doubled specificity of class rules.
|
|
479
|
+
|
|
364
480
|
---
|
|
365
481
|
|
|
366
482
|
## Inject Mode
|
|
@@ -382,13 +498,16 @@ This is ideal for **reusable components**, **extensions**, and **libraries** whe
|
|
|
382
498
|
// babel.config.js
|
|
383
499
|
module.exports = {
|
|
384
500
|
plugins: [
|
|
385
|
-
[
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
501
|
+
[
|
|
502
|
+
'@tenphi/tasty/babel-plugin',
|
|
503
|
+
{
|
|
504
|
+
mode: 'inject',
|
|
505
|
+
config: {
|
|
506
|
+
states: { '@mobile': '@media(w < 768px)' },
|
|
507
|
+
},
|
|
389
508
|
},
|
|
390
|
-
|
|
391
|
-
]
|
|
509
|
+
],
|
|
510
|
+
],
|
|
392
511
|
};
|
|
393
512
|
```
|
|
394
513
|
|
|
@@ -428,22 +547,36 @@ tastyStatic('.heading', { preset: 'h1' });
|
|
|
428
547
|
```tsx
|
|
429
548
|
import { injectCSS as _$i } from '@tenphi/tasty/static/inject';
|
|
430
549
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
_$i(
|
|
550
|
+
_$i(
|
|
551
|
+
'@property',
|
|
552
|
+
'@property --tasty-second-fill-color { … }\n@property --current-color { … }\n…',
|
|
553
|
+
);
|
|
554
|
+
|
|
555
|
+
const button =
|
|
556
|
+
(_$i(
|
|
557
|
+
'tsa903d6 ts070801',
|
|
558
|
+
'.tsa903d6.tsa903d6 { background-color: var(--purple-color); }\n.ts070801.ts070801 { padding: 16px 32px; }',
|
|
559
|
+
),
|
|
560
|
+
{
|
|
561
|
+
className: 'tsa903d6 ts070801',
|
|
562
|
+
styles: { padding: '2x 4x', fill: '#purple' },
|
|
563
|
+
toString() {
|
|
564
|
+
return this.className;
|
|
565
|
+
},
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
_$i('.heading', '.heading { font-size: var(--h1-font-size, …); … }');
|
|
438
569
|
```
|
|
439
570
|
|
|
571
|
+
Each file that calls `tastyStatic()` starts by injecting Tasty's default `@property` rules and your `config.properties` under the `@property` id. `injectCSS()` skips an id it has already injected, so the page gets them once.
|
|
572
|
+
|
|
440
573
|
### Dev Mode / HMR
|
|
441
574
|
|
|
442
575
|
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.
|
|
443
576
|
|
|
444
577
|
### Limitations (inject mode)
|
|
445
578
|
|
|
446
|
-
- **Client-side only** — Styles are injected via the DOM, so they are not available during SSR. For server-rendered apps, use `mode: 'file'` or
|
|
579
|
+
- **Client-side only** — Styles are injected via the DOM, so they are not available during SSR. For server-rendered apps, use `mode: 'file'` or React `tasty()`.
|
|
447
580
|
- **Larger JS bundle** — CSS is embedded in JavaScript, increasing bundle size. Best suited for components and extensions, not full-app styling.
|
|
448
581
|
|
|
449
582
|
---
|
|
@@ -458,7 +591,7 @@ const button = tastyStatic({
|
|
|
458
591
|
radius: '1r',
|
|
459
592
|
fill: '#gray.20',
|
|
460
593
|
color: '#text',
|
|
461
|
-
transition: 'fill
|
|
594
|
+
transition: 'fill',
|
|
462
595
|
});
|
|
463
596
|
|
|
464
597
|
// Variants
|
|
@@ -494,7 +627,7 @@ const card = tastyStatic({
|
|
|
494
627
|
|
|
495
628
|
## Extending Style Types (TypeScript)
|
|
496
629
|
|
|
497
|
-
If you add custom style properties, use module augmentation so `tastyStatic` recognizes them too. See [
|
|
630
|
+
If you add custom style properties, use module augmentation so `tastyStatic` recognizes them too. See [TypeScript](configuration.md#typescript) in the configuration docs.
|
|
498
631
|
|
|
499
632
|
---
|
|
500
633
|
|
|
@@ -512,13 +645,17 @@ For dynamic styling needs, combine with regular CSS or CSS variables:
|
|
|
512
645
|
```tsx
|
|
513
646
|
const card = tastyStatic({
|
|
514
647
|
padding: '4x',
|
|
515
|
-
fill: '
|
|
648
|
+
fill: '($card-bg, #white)',
|
|
516
649
|
});
|
|
517
650
|
|
|
518
651
|
<div
|
|
519
|
-
className={card}
|
|
520
|
-
style={
|
|
521
|
-
|
|
652
|
+
className={card.className}
|
|
653
|
+
style={
|
|
654
|
+
{
|
|
655
|
+
'--card-bg': isActive ? 'var(--purple-color)' : 'var(--white-color)',
|
|
656
|
+
} as React.CSSProperties
|
|
657
|
+
}
|
|
658
|
+
/>;
|
|
522
659
|
```
|
|
523
660
|
|
|
524
661
|
---
|
|
@@ -535,15 +672,15 @@ const card = tastyStatic({
|
|
|
535
672
|
## Common Issues
|
|
536
673
|
|
|
537
674
|
- 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.
|
|
538
|
-
- Styles stay dynamic by mistake: `tastyStatic()` only supports build-time-known values. Move
|
|
675
|
+
- Styles stay dynamic by mistake: `tastyStatic()` only supports build-time-known values. Move dynamic values to CSS variables or switch that component to React `tasty()`.
|
|
539
676
|
- Turbopack config behaves inconsistently: prefer `configFile` over inline functions so the setup stays JSON-serializable.
|
|
540
677
|
|
|
541
678
|
---
|
|
542
679
|
|
|
543
680
|
## Related
|
|
544
681
|
|
|
545
|
-
- [Docs Hub](README.md) — Choose the right guide by task or
|
|
682
|
+
- [Docs Hub](README.md) — Choose the right guide by task or CSS delivery model
|
|
546
683
|
- [Style DSL](dsl.md) — State maps, tokens, units, extending semantics (shared by runtime and static)
|
|
547
|
-
- [React API](react-api.md) —
|
|
684
|
+
- [React API](react-api.md) — Client or server rendering with `tasty()`: component props, variants, sub-elements, and style functions
|
|
548
685
|
- [Configuration](configuration.md) — Global configuration: tokens, recipes, custom units, and style handlers
|
|
549
686
|
- [Plugins & Extension Points](plugins.md) — Which extension points work at build time (`functions`, `units`, `states`, `handlers`, `recipes`) and which do not (`propHandlers` — `tastyStatic()` takes styles objects, not props)
|