@tenphi/tasty 0.0.0-snapshot.a8b4749 → 0.0.0-snapshot.a8da86e
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 +181 -136
- package/dist/babel-types-C_7kRP38.d.ts +18 -0
- package/dist/chunks/async-storage-CG5HnUT5.js +20 -0
- package/dist/chunks/async-storage-CG5HnUT5.js.map +1 -0
- package/dist/chunks/build-config-Betc6IB6.js +60 -0
- package/dist/chunks/build-config-Betc6IB6.js.map +1 -0
- package/dist/{collector-C-keQH9m.js → chunks/collector-DqqisglQ.js} +68 -101
- package/dist/chunks/collector-DqqisglQ.js.map +1 -0
- package/dist/chunks/config-engine-BPeROwq2.js +272 -0
- package/dist/chunks/config-engine-BPeROwq2.js.map +1 -0
- package/dist/chunks/css-definitions-IeuyJTGk.js +899 -0
- package/dist/chunks/css-definitions-IeuyJTGk.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-P1E2jkj7.js +502 -0
- package/dist/chunks/debug-P1E2jkj7.js.map +1 -0
- package/dist/chunks/dsl-DRhFWQzo.js +1378 -0
- package/dist/chunks/dsl-DRhFWQzo.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-XMBbGRes.js +582 -0
- package/dist/chunks/react-runtime-XMBbGRes.js.map +1 -0
- package/dist/chunks/runtime-engine-CsIMtulO.js +2415 -0
- package/dist/chunks/runtime-engine-CsIMtulO.js.map +1 -0
- package/dist/chunks/runtime-state-CyKzDioI.js +141 -0
- package/dist/chunks/runtime-state-CyKzDioI.js.map +1 -0
- package/dist/{merge-styles-Cd2vBl9b.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-RbokDN6A.js +5427 -0
- package/dist/chunks/style-engine-RbokDN6A.js.map +1 -0
- package/dist/{css-writer-BWvwQzz0.js → chunks/zero-engine-DbtjMsfo.js} +81 -137
- package/dist/chunks/zero-engine-DbtjMsfo.js.map +1 -0
- package/dist/{collector-osfWTeRd.d.ts → collector-w4mBj5gd.d.ts} +64 -8
- package/dist/{config-BoZDUHW5.d.ts → config-CrZOfNJ5.d.ts} +489 -85
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/{index-B_k47mc_.d.ts → index-CYJtAI9a.d.ts} +664 -399
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -732
- package/dist/{merge-styles-BMWcH6MF.d.ts → merge-styles-VXwJ0Frr.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 +17 -0
- package/dist/ssr/astro-middleware-static.js +7 -0
- package/dist/ssr/astro-middleware-static.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +11 -8
- package/dist/ssr/astro-middleware.js +2 -14
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +40 -10
- package/dist/ssr/astro.js +163 -91
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/index.d.ts +10 -18
- 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 +134 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +9 -9
- package/dist/ssr/next.js +29 -44
- 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/static/inject.js.map +1 -1
- package/dist/{index-tcHuMPFt.d.ts → types-JEY8PVYP.d.ts} +874 -593
- package/dist/zero/babel.d.ts +5 -19
- package/dist/zero/babel.js +74 -144
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +57 -7
- 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 +0 -31
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +17 -9
- package/docs/adoption.md +56 -31
- package/docs/ai-agents.md +250 -0
- package/docs/comparison.md +69 -40
- package/docs/configuration.md +487 -86
- package/docs/debug.md +26 -14
- package/docs/design-system.md +43 -24
- package/docs/dsl.md +558 -181
- package/docs/getting-started.md +64 -41
- package/docs/injector.md +120 -30
- package/docs/methodology.md +46 -40
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +87 -21
- package/docs/plugins.md +353 -0
- package/docs/react-api.md +151 -42
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +252 -86
- package/docs/styles.md +142 -25
- package/docs/tasty-static.md +174 -106
- package/package.json +127 -35
- package/tasty.config.ts +5 -0
- package/dist/async-storage-B7_o6FKt.js +0 -44
- package/dist/async-storage-B7_o6FKt.js.map +0 -1
- package/dist/collector-C-keQH9m.js.map +0 -1
- package/dist/config-BBiyxMCe.js +0 -10559
- package/dist/config-BBiyxMCe.js.map +0 -1
- package/dist/context-CkSg-kDT.js +0 -24
- package/dist/context-CkSg-kDT.js.map +0 -1
- package/dist/core-BO4319td.js +0 -1598
- package/dist/core-BO4319td.js.map +0 -1
- package/dist/css-writer-BWvwQzz0.js.map +0 -1
- package/dist/format-global-rules-Dbc_1tc3.js +0 -22
- package/dist/format-global-rules-Dbc_1tc3.js.map +0 -1
- package/dist/format-rules-BSjeH4Z7.js +0 -143
- package/dist/format-rules-BSjeH4Z7.js.map +0 -1
- package/dist/hydrate-CcvrP4qJ.js +0 -45
- package/dist/hydrate-CcvrP4qJ.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-BUQhdOSJ.js +0 -588
- package/dist/keyframes-BUQhdOSJ.js.map +0 -1
- package/dist/merge-styles-Cd2vBl9b.js.map +0 -1
- package/dist/resolve-recipes-C1nrvnYh.js +0 -144
- package/dist/resolve-recipes-C1nrvnYh.js.map +0 -1
package/docs/tasty-static.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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
|
|
|
@@ -8,19 +10,19 @@
|
|
|
8
10
|
|
|
9
11
|
- **Static site generation (SSG)** — Pre-render all styles at build time
|
|
10
12
|
- **No-JavaScript websites** — CSS works without any JS runtime
|
|
11
|
-
- **Performance-critical pages** —
|
|
13
|
+
- **Performance-critical pages** — CSS extracted before the application renders
|
|
12
14
|
- **Landing pages** — Minimal bundle size with pre-generated CSS
|
|
13
15
|
|
|
14
16
|
## Requirements
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
Build-time extraction is part of the main `@tenphi/tasty` package but requires additional peer dependencies depending on your setup:
|
|
17
19
|
|
|
18
|
-
| Dependency
|
|
19
|
-
|
|
20
|
-
| `@babel/core`
|
|
21
|
-
| `@babel/helper-plugin-utils` | >= 7.24 | Babel plugin
|
|
22
|
-
| `@babel/types`
|
|
23
|
-
| `jiti`
|
|
20
|
+
| Dependency | Version | Required for |
|
|
21
|
+
| ---------------------------- | ------- | -------------------------------------------------------------------------- |
|
|
22
|
+
| `@babel/core` | >= 7.24 | Babel plugin (`@tenphi/tasty/babel-plugin`) |
|
|
23
|
+
| `@babel/helper-plugin-utils` | >= 7.24 | Babel plugin |
|
|
24
|
+
| `@babel/types` | >= 7.24 | Babel plugin |
|
|
25
|
+
| `jiti` | >= 2.6 | Next.js wrapper (`@tenphi/tasty/zero/next`) when using `configFile` option |
|
|
24
26
|
|
|
25
27
|
All of these are declared as optional peer dependencies of `@tenphi/tasty`. Install only what your setup requires:
|
|
26
28
|
|
|
@@ -103,15 +105,17 @@ tastyStatic('body', {
|
|
|
103
105
|
});
|
|
104
106
|
```
|
|
105
107
|
|
|
108
|
+
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)`.
|
|
109
|
+
|
|
106
110
|
---
|
|
107
111
|
|
|
108
112
|
## StaticStyle Object
|
|
109
113
|
|
|
110
|
-
| Property
|
|
111
|
-
|
|
112
|
-
| `className`
|
|
113
|
-
| `styles`
|
|
114
|
-
| `toString()` | `() => string` | Returns `className` for string coercion
|
|
114
|
+
| Property | Type | Description |
|
|
115
|
+
| ------------ | -------------- | ------------------------------------------ |
|
|
116
|
+
| `className` | `string` | Space-separated class names for use in JSX |
|
|
117
|
+
| `styles` | `Styles` | The original (or merged) styles object |
|
|
118
|
+
| `toString()` | `() => string` | Returns `className` for string coercion |
|
|
115
119
|
|
|
116
120
|
---
|
|
117
121
|
|
|
@@ -123,66 +127,73 @@ tastyStatic('body', {
|
|
|
123
127
|
// babel.config.js
|
|
124
128
|
module.exports = {
|
|
125
129
|
plugins: [
|
|
126
|
-
[
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
[
|
|
131
|
+
'@tenphi/tasty/babel-plugin',
|
|
132
|
+
{
|
|
133
|
+
output: 'public/tasty.css',
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
],
|
|
130
137
|
};
|
|
131
138
|
```
|
|
132
139
|
|
|
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
|
|
140
|
+
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
141
|
|
|
135
142
|
### With Configuration
|
|
136
143
|
|
|
137
144
|
```javascript
|
|
138
145
|
module.exports = {
|
|
139
146
|
plugins: [
|
|
140
|
-
[
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
+
[
|
|
148
|
+
'@tenphi/tasty/babel-plugin',
|
|
149
|
+
{
|
|
150
|
+
output: 'public/tasty.css',
|
|
151
|
+
config: {
|
|
152
|
+
states: {
|
|
153
|
+
'@mobile': '@media(w < 768px)',
|
|
154
|
+
'@tablet': '@media(w < 1024px)',
|
|
155
|
+
'@dark': '@root(schema=dark)',
|
|
156
|
+
},
|
|
157
|
+
devMode: true,
|
|
147
158
|
},
|
|
148
|
-
devMode: true,
|
|
149
159
|
},
|
|
150
|
-
|
|
151
|
-
]
|
|
160
|
+
],
|
|
161
|
+
],
|
|
152
162
|
};
|
|
153
163
|
```
|
|
154
164
|
|
|
155
165
|
### Plugin Options
|
|
156
166
|
|
|
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.
|
|
172
|
-
| `config.
|
|
173
|
-
| `config.units`
|
|
174
|
-
| `config.
|
|
175
|
-
| `config.
|
|
176
|
-
| `config.
|
|
177
|
-
| `config.
|
|
178
|
-
| `config.
|
|
179
|
-
| `config.
|
|
180
|
-
| `config.
|
|
181
|
-
| `config.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
167
|
+
| Option | Type | Default | Description |
|
|
168
|
+
| -------------------------- | ------------------------------------------------ | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
169
|
+
| `output` | `string` | `'tasty.css'` | Path for generated CSS file |
|
|
170
|
+
| `mode` | `'file' \| 'inject'` | `'file'` | `'file'` writes CSS to disk; `'inject'` embeds CSS inline in JS (see [Inject Mode](#inject-mode)) |
|
|
171
|
+
| `configFile` | `string` | — | Absolute path to a TS/JS module that default-exports a `TastyZeroConfig` object. JSON-serializable alternative to `config` — required for Turbopack. |
|
|
172
|
+
| `config` | `TastyZeroConfig \| () => TastyZeroConfig` | `{}` | Inline config object or factory function. Takes precedence over `configFile`. |
|
|
173
|
+
| `configDeps` | `string[]` | `[]` | Absolute file paths that affect config (for cache invalidation) |
|
|
174
|
+
| `injectImport` | `boolean` | `true` | Replace `@tenphi/tasty/static` imports with an import of the generated CSS file. Set to `false` to manage CSS imports manually. |
|
|
175
|
+
| `config.states` | `Record<string, string>` | `{}` | Predefined state aliases (e.g. `{ '@mobile': '@media(w < 768px)' }`) |
|
|
176
|
+
| `config.devMode` | `boolean` | `false` | Add source comments to CSS |
|
|
177
|
+
| `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. |
|
|
178
|
+
| `config.replaceTokens` | `Record<string, string \| number>` | — | Parse-time token substitution. Keys use `$name` for custom properties and `#name` for color tokens. |
|
|
179
|
+
| `config.recipes` | `Record<string, RecipeStyles>` | `{}` | Predefined style recipes |
|
|
180
|
+
| `config.keyframes` | `Record<string, KeyframesSteps>` | — | Global `@keyframes` definitions available to all `tastyStatic` calls |
|
|
181
|
+
| `config.fontFaces` | `Record<string, FontFaceInput>` | — | Global `@font-face` definitions |
|
|
182
|
+
| `config.counterStyles` | `Record<string, CounterStyleDescriptors>` | — | Global `@counter-style` definitions |
|
|
183
|
+
| `config.units` | `Record<string, string \| UnitHandler>` | — | Custom units for the style parser (merged with built-ins). E.g. `{ em: 'em', vw: 'vw' }` |
|
|
184
|
+
| `config.functions` | `Record<string, FunctionDefinition \| Function>` | — | Custom functions (merged). Bare keys → parse functions; `$$name` keys → declarative CSS `@function` definitions |
|
|
185
|
+
| `config.polyfills` | `{ functions?: boolean }` | `{}` | Opt-in polyfills. `functions: true` inlines `@function` calls into plain CSS at build time |
|
|
186
|
+
| `config.plugins` | `TastyPlugin[]` | — | Plugins that extend tasty with custom functions, units, states, and handlers |
|
|
187
|
+
| `config.handlers` | `Record<string, StyleHandlerDefinition>` | — | Custom style handlers that transform style properties into CSS declarations |
|
|
188
|
+
| `config.presets` | `Record<string, TypographyPreset>` | — | Typography presets — shorthand for `generateTypographyTokens()`. Generated tokens merge under explicit `tokens`. |
|
|
189
|
+
| `config.globalStyles` | `Record<string, Styles>` | — | Global Tasty styles keyed by CSS selector. Supports the full style syntax. |
|
|
190
|
+
| `config.autoPropertyTypes` | `boolean` | `true` | Automatically infer and register CSS `@property` declarations from values |
|
|
191
|
+
| `config.parserCacheSize` | `number` | `1000` | Parser LRU cache size. Larger values improve performance for builds with many unique style values |
|
|
192
|
+
| `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). |
|
|
193
|
+
|
|
194
|
+
### Coexisting with `tasty()`
|
|
195
|
+
|
|
196
|
+
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:
|
|
186
197
|
|
|
187
198
|
```ts
|
|
188
199
|
// tasty-zero.config.ts (Babel plugin)
|
|
@@ -190,7 +201,7 @@ export default { namePrefix: 'mbs' };
|
|
|
190
201
|
```
|
|
191
202
|
|
|
192
203
|
```ts
|
|
193
|
-
// app entry (
|
|
204
|
+
// app entry (`tasty()` configure)
|
|
194
205
|
configure({ namePrefix: 'mb' });
|
|
195
206
|
```
|
|
196
207
|
|
|
@@ -204,16 +215,24 @@ Recipes work with `tastyStatic` the same way as with runtime `tasty`:
|
|
|
204
215
|
// babel.config.js
|
|
205
216
|
module.exports = {
|
|
206
217
|
plugins: [
|
|
207
|
-
[
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
218
|
+
[
|
|
219
|
+
'@tenphi/tasty/babel-plugin',
|
|
220
|
+
{
|
|
221
|
+
output: 'public/tasty.css',
|
|
222
|
+
config: {
|
|
223
|
+
recipes: {
|
|
224
|
+
card: {
|
|
225
|
+
padding: '4x',
|
|
226
|
+
fill: '#surface',
|
|
227
|
+
radius: '1r',
|
|
228
|
+
border: true,
|
|
229
|
+
},
|
|
230
|
+
elevated: { shadow: '2x 2x 4x #shadow' },
|
|
231
|
+
},
|
|
213
232
|
},
|
|
214
233
|
},
|
|
215
|
-
|
|
216
|
-
]
|
|
234
|
+
],
|
|
235
|
+
],
|
|
217
236
|
};
|
|
218
237
|
```
|
|
219
238
|
|
|
@@ -225,7 +244,7 @@ const card = tastyStatic({
|
|
|
225
244
|
color: '#text',
|
|
226
245
|
});
|
|
227
246
|
|
|
228
|
-
<div className={card}>Styled card</div
|
|
247
|
+
<div className={card}>Styled card</div>;
|
|
229
248
|
```
|
|
230
249
|
|
|
231
250
|
---
|
|
@@ -236,7 +255,7 @@ The `withTastyZero` wrapper configures both **webpack** and **Turbopack** automa
|
|
|
236
255
|
|
|
237
256
|
```typescript
|
|
238
257
|
// next.config.ts
|
|
239
|
-
import { withTastyZero } from '@tenphi/tasty/next';
|
|
258
|
+
import { withTastyZero } from '@tenphi/tasty/zero/next';
|
|
240
259
|
|
|
241
260
|
export default withTastyZero({
|
|
242
261
|
output: 'public/tasty.css',
|
|
@@ -249,14 +268,14 @@ export default withTastyZero({
|
|
|
249
268
|
|
|
250
269
|
### `withTastyZero` Options
|
|
251
270
|
|
|
252
|
-
| Option
|
|
253
|
-
|
|
254
|
-
| `output`
|
|
255
|
-
| `mode`
|
|
256
|
-
| `enabled`
|
|
257
|
-
| `configFile` | `string`
|
|
258
|
-
| `config`
|
|
259
|
-
| `configDeps` | `string[]`
|
|
271
|
+
| Option | Type | Default | Description |
|
|
272
|
+
| ------------ | -------------------- | -------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
273
|
+
| `output` | `string` | `'public/tasty.css'` | Output path for CSS relative to project root |
|
|
274
|
+
| `mode` | `'file' \| 'inject'` | `'file'` | `'file'` writes CSS to disk; `'inject'` embeds CSS inline in JS |
|
|
275
|
+
| `enabled` | `boolean` | `true` | Enable/disable the plugin |
|
|
276
|
+
| `configFile` | `string` | — | Path to a TS/JS module that default-exports `TastyZeroConfig`. Recommended for Turbopack compatibility. |
|
|
277
|
+
| `config` | `TastyZeroConfig` | — | Inline config object. For static configs that don't change during dev. |
|
|
278
|
+
| `configDeps` | `string[]` | `[]` | Extra files the config depends on (for cache invalidation) |
|
|
260
279
|
|
|
261
280
|
### Turbopack Support
|
|
262
281
|
|
|
@@ -282,6 +301,37 @@ public/tasty.css
|
|
|
282
301
|
|
|
283
302
|
---
|
|
284
303
|
|
|
304
|
+
## Programmatic API
|
|
305
|
+
|
|
306
|
+
`@tenphi/tasty/zero` turns styles into CSS in Node without Babel or React — for build scripts, or CSS shipped to other frameworks:
|
|
307
|
+
|
|
308
|
+
```ts
|
|
309
|
+
import {
|
|
310
|
+
configure,
|
|
311
|
+
extractStylesForSelector,
|
|
312
|
+
extractStylesWithChunks,
|
|
313
|
+
} from '@tenphi/tasty/zero';
|
|
314
|
+
|
|
315
|
+
configure({
|
|
316
|
+
units: { u: 'var(--unit)' },
|
|
317
|
+
states: { '@dark': '@root(schema=dark)' },
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
extractStylesForSelector('.card', { padding: '2u', fill: '#surface' }).css;
|
|
321
|
+
// → '.card { padding: calc(2 * var(--unit)); background-color: … }'
|
|
322
|
+
|
|
323
|
+
extractStylesWithChunks({ display: 'flex', gap: '1u' });
|
|
324
|
+
// → [{ className: 'ts…', css: '.ts….ts… { … }' }]
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
`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: `tokens`, `globalStyles`, `fontFaces`, `counterStyles`, `properties` and `$$` `@function` definitions. Render tokens and global styles with `extractStylesForSelector(':root', tokens)` and `extractStylesForSelector(selector, styles)`.
|
|
328
|
+
|
|
329
|
+
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.
|
|
330
|
+
|
|
331
|
+
`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.
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
285
335
|
## Vite Integration
|
|
286
336
|
|
|
287
337
|
```typescript
|
|
@@ -294,12 +344,15 @@ export default defineConfig({
|
|
|
294
344
|
react({
|
|
295
345
|
babel: {
|
|
296
346
|
plugins: [
|
|
297
|
-
[
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
347
|
+
[
|
|
348
|
+
'@tenphi/tasty/babel-plugin',
|
|
349
|
+
{
|
|
350
|
+
output: 'public/tasty.css',
|
|
351
|
+
config: {
|
|
352
|
+
states: { '@mobile': '@media(w < 768px)' },
|
|
353
|
+
},
|
|
301
354
|
},
|
|
302
|
-
|
|
355
|
+
],
|
|
303
356
|
],
|
|
304
357
|
},
|
|
305
358
|
}),
|
|
@@ -333,7 +386,9 @@ export const Button = () => <button className={button}>Click</button>;
|
|
|
333
386
|
const button = {
|
|
334
387
|
className: 'ts3f2a1b ts8c4d2e',
|
|
335
388
|
styles: { padding: '2x 4x', fill: '#purple', color: '#white' },
|
|
336
|
-
toString() {
|
|
389
|
+
toString() {
|
|
390
|
+
return this.className;
|
|
391
|
+
},
|
|
337
392
|
};
|
|
338
393
|
|
|
339
394
|
export const Button = () => <button className={button}>Click</button>;
|
|
@@ -381,13 +436,16 @@ This is ideal for **reusable components**, **extensions**, and **libraries** whe
|
|
|
381
436
|
// babel.config.js
|
|
382
437
|
module.exports = {
|
|
383
438
|
plugins: [
|
|
384
|
-
[
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
439
|
+
[
|
|
440
|
+
'@tenphi/tasty/babel-plugin',
|
|
441
|
+
{
|
|
442
|
+
mode: 'inject',
|
|
443
|
+
config: {
|
|
444
|
+
states: { '@mobile': '@media(w < 768px)' },
|
|
445
|
+
},
|
|
388
446
|
},
|
|
389
|
-
|
|
390
|
-
]
|
|
447
|
+
],
|
|
448
|
+
],
|
|
391
449
|
};
|
|
392
450
|
```
|
|
393
451
|
|
|
@@ -395,7 +453,7 @@ With Next.js:
|
|
|
395
453
|
|
|
396
454
|
```typescript
|
|
397
455
|
// next.config.ts
|
|
398
|
-
import { withTastyZero } from '@tenphi/tasty/next';
|
|
456
|
+
import { withTastyZero } from '@tenphi/tasty/zero/next';
|
|
399
457
|
|
|
400
458
|
export default withTastyZero({
|
|
401
459
|
mode: 'inject',
|
|
@@ -427,13 +485,20 @@ tastyStatic('.heading', { preset: 'h1' });
|
|
|
427
485
|
```tsx
|
|
428
486
|
import { injectCSS as _$i } from '@tenphi/tasty/static/inject';
|
|
429
487
|
|
|
430
|
-
const button =
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
488
|
+
const button =
|
|
489
|
+
(_$i(
|
|
490
|
+
'ts3f2a1b ts8c4d2e',
|
|
491
|
+
'.ts3f2a1b.ts3f2a1b{padding:16px 32px}\n.ts8c4d2e.ts8c4d2e{background:#9370db}',
|
|
492
|
+
),
|
|
493
|
+
{
|
|
494
|
+
className: 'ts3f2a1b ts8c4d2e',
|
|
495
|
+
styles: { padding: '2x 4x', fill: '#purple' },
|
|
496
|
+
toString() {
|
|
497
|
+
return this.className;
|
|
498
|
+
},
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
_$i('.heading', '.heading{font-size:2.5rem;font-weight:700;line-height:1.2}');
|
|
437
502
|
```
|
|
438
503
|
|
|
439
504
|
### Dev Mode / HMR
|
|
@@ -442,7 +507,7 @@ Class names are content-hashed (`ts` + MD5). When styles change, a new hash prod
|
|
|
442
507
|
|
|
443
508
|
### Limitations (inject mode)
|
|
444
509
|
|
|
445
|
-
- **Client-side only** — Styles are injected via the DOM, so they are not available during SSR. For server-rendered apps, use `mode: 'file'` or
|
|
510
|
+
- **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()`.
|
|
446
511
|
- **Larger JS bundle** — CSS is embedded in JavaScript, increasing bundle size. Best suited for components and extensions, not full-app styling.
|
|
447
512
|
|
|
448
513
|
---
|
|
@@ -457,7 +522,7 @@ const button = tastyStatic({
|
|
|
457
522
|
radius: '1r',
|
|
458
523
|
fill: '#gray.20',
|
|
459
524
|
color: '#text',
|
|
460
|
-
transition: 'fill
|
|
525
|
+
transition: 'fill',
|
|
461
526
|
});
|
|
462
527
|
|
|
463
528
|
// Variants
|
|
@@ -511,13 +576,15 @@ For dynamic styling needs, combine with regular CSS or CSS variables:
|
|
|
511
576
|
```tsx
|
|
512
577
|
const card = tastyStatic({
|
|
513
578
|
padding: '4x',
|
|
514
|
-
fill: '
|
|
579
|
+
fill: '($card-bg, #white)',
|
|
515
580
|
});
|
|
516
581
|
|
|
517
582
|
<div
|
|
518
583
|
className={card}
|
|
519
|
-
style={{
|
|
520
|
-
|
|
584
|
+
style={{
|
|
585
|
+
'--card-bg': isActive ? 'var(--purple-color)' : 'var(--white-color)',
|
|
586
|
+
}}
|
|
587
|
+
/>;
|
|
521
588
|
```
|
|
522
589
|
|
|
523
590
|
---
|
|
@@ -534,14 +601,15 @@ const card = tastyStatic({
|
|
|
534
601
|
## Common Issues
|
|
535
602
|
|
|
536
603
|
- 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.
|
|
537
|
-
- Styles stay dynamic by mistake: `tastyStatic()` only supports build-time-known values. Move
|
|
604
|
+
- 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()`.
|
|
538
605
|
- Turbopack config behaves inconsistently: prefer `configFile` over inline functions so the setup stays JSON-serializable.
|
|
539
606
|
|
|
540
607
|
---
|
|
541
608
|
|
|
542
609
|
## Related
|
|
543
610
|
|
|
544
|
-
- [Docs Hub](README.md) — Choose the right guide by task or
|
|
611
|
+
- [Docs Hub](README.md) — Choose the right guide by task or CSS delivery model
|
|
545
612
|
- [Style DSL](dsl.md) — State maps, tokens, units, extending semantics (shared by runtime and static)
|
|
546
|
-
- [React API](react-api.md) —
|
|
613
|
+
- [React API](react-api.md) — Client or server rendering with `tasty()`: component props, variants, sub-elements, and style functions
|
|
547
614
|
- [Configuration](configuration.md) — Global configuration: tokens, recipes, custom units, and style handlers
|
|
615
|
+
- [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)
|