@tenphi/tasty 0.0.0-snapshot.f8d65c2 → 0.0.0-snapshot.f9b7ecd

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 (97) hide show
  1. package/dist/{babel-CRNENCeS.d.ts → babel-Zs1Q03qt.d.ts} +2 -2
  2. package/dist/chunks/async-storage-DKK-wTD4.js.map +1 -0
  3. package/dist/chunks/build-config-2XKR9LT3.js +45 -0
  4. package/dist/chunks/build-config-2XKR9LT3.js.map +1 -0
  5. package/dist/{collector-C6CzXyp6.js → chunks/collector-CVBoOUW1.js} +29 -15
  6. package/dist/chunks/collector-CVBoOUW1.js.map +1 -0
  7. package/dist/chunks/config-engine-CUudEz7P.js +331 -0
  8. package/dist/chunks/config-engine-CUudEz7P.js.map +1 -0
  9. package/dist/chunks/css-definitions-CEdgOvNe.js +1229 -0
  10. package/dist/chunks/css-definitions-CEdgOvNe.js.map +1 -0
  11. package/dist/chunks/css-resources-Cyl_axbI.js +149 -0
  12. package/dist/chunks/css-resources-Cyl_axbI.js.map +1 -0
  13. package/dist/chunks/debug-CkoARkLY.js +543 -0
  14. package/dist/chunks/debug-CkoARkLY.js.map +1 -0
  15. package/dist/chunks/dsl-Bj2D1QZ5.js +1769 -0
  16. package/dist/chunks/dsl-Bj2D1QZ5.js.map +1 -0
  17. package/dist/chunks/hydration-CLdVKcH2.js +59 -0
  18. package/dist/chunks/hydration-CLdVKcH2.js.map +1 -0
  19. package/dist/chunks/react-runtime-CbMYWtHC.js +877 -0
  20. package/dist/chunks/react-runtime-CbMYWtHC.js.map +1 -0
  21. package/dist/chunks/runtime-engine-BKiN9WNG.js +3439 -0
  22. package/dist/chunks/runtime-engine-BKiN9WNG.js.map +1 -0
  23. package/dist/chunks/runtime-state-BCakwspy.js +138 -0
  24. package/dist/chunks/runtime-state-BCakwspy.js.map +1 -0
  25. package/dist/{merge-styles-DGKWAJ4H.js → chunks/shared-utils-Bgl8FNGJ.js} +64 -24
  26. package/dist/chunks/shared-utils-Bgl8FNGJ.js.map +1 -0
  27. package/dist/chunks/style-engine-MyMMMn-p.js +6892 -0
  28. package/dist/chunks/style-engine-MyMMMn-p.js.map +1 -0
  29. package/dist/{css-writer-WkeVxwW6.js → chunks/zero-engine-D3ub9Y8k.js} +3 -3
  30. package/dist/chunks/zero-engine-D3ub9Y8k.js.map +1 -0
  31. package/dist/{collector-0YO-P1vW.d.ts → collector-hl5KNH7k.d.ts} +23 -3
  32. package/dist/{config-CG9Aa2SQ.d.ts → config-DWL1ZYue.d.ts} +55 -25
  33. package/dist/core/index.d.ts +5 -5
  34. package/dist/core/index.js +9 -6
  35. package/dist/{index-DTIDwdUV.d.ts → index-D9N9GV24.d.ts} +96 -82
  36. package/dist/index.d.ts +5 -5
  37. package/dist/index.js +11 -922
  38. package/dist/{merge-styles-BcLl1u_d.d.ts → merge-styles-C_oMoJVd.d.ts} +2 -2
  39. package/dist/ssr/astro-client.js +1 -1
  40. package/dist/ssr/astro-middleware-extract-static.d.ts +11 -0
  41. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  42. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  43. package/dist/ssr/astro-middleware-extract.d.ts +11 -0
  44. package/dist/ssr/astro-middleware-extract.js +9 -0
  45. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  46. package/dist/ssr/astro-middleware-static.d.ts +3 -1
  47. package/dist/ssr/astro-middleware.d.ts +3 -1
  48. package/dist/ssr/astro.d.ts +45 -3
  49. package/dist/ssr/astro.js +158 -15
  50. package/dist/ssr/astro.js.map +1 -1
  51. package/dist/ssr/index.d.ts +7 -7
  52. package/dist/ssr/index.js +4 -4
  53. package/dist/ssr/index.js.map +1 -1
  54. package/dist/ssr/next-config.d.ts +66 -0
  55. package/dist/ssr/next-config.js +135 -0
  56. package/dist/ssr/next-config.js.map +1 -0
  57. package/dist/ssr/next.d.ts +9 -2
  58. package/dist/ssr/next.js +27 -11
  59. package/dist/ssr/next.js.map +1 -1
  60. package/dist/static/index.d.ts +2 -2
  61. package/dist/static/index.js +1 -1
  62. package/dist/{index-BmogEzTo.d.ts → types-jKZNpias.d.ts} +845 -804
  63. package/dist/zero/babel.d.ts +1 -1
  64. package/dist/zero/babel.js +25 -24
  65. package/dist/zero/babel.js.map +1 -1
  66. package/dist/zero/index.d.ts +1 -1
  67. package/dist/zero/index.js +1 -1
  68. package/dist/zero/next.d.ts +1 -1
  69. package/docs/ai-agents.md +8 -3
  70. package/docs/debug.md +15 -5
  71. package/docs/methodology.md +3 -3
  72. package/docs/runtime-benchmarks.md +185 -12
  73. package/docs/ssr.md +179 -20
  74. package/docs/styles.md +43 -11
  75. package/package.json +74 -9
  76. package/dist/async-storage-DKK-wTD4.js.map +0 -1
  77. package/dist/collector-C6CzXyp6.js.map +0 -1
  78. package/dist/config-CE_Y8Z8_.js +0 -12363
  79. package/dist/config-CE_Y8Z8_.js.map +0 -1
  80. package/dist/context-CA8YKeMn.js +0 -24
  81. package/dist/context-CA8YKeMn.js.map +0 -1
  82. package/dist/core-DGijQRzL.js +0 -1628
  83. package/dist/core-DGijQRzL.js.map +0 -1
  84. package/dist/css-writer-WkeVxwW6.js.map +0 -1
  85. package/dist/format-global-rules-DklyaXv-.js +0 -22
  86. package/dist/format-global-rules-DklyaXv-.js.map +0 -1
  87. package/dist/format-rules-CkM_6e2u.js +0 -130
  88. package/dist/format-rules-CkM_6e2u.js.map +0 -1
  89. package/dist/hydrate-C8NL-JAC.js +0 -37
  90. package/dist/hydrate-C8NL-JAC.js.map +0 -1
  91. package/dist/index.js.map +0 -1
  92. package/dist/keyframes-DFt5ewaz.js +0 -535
  93. package/dist/keyframes-DFt5ewaz.js.map +0 -1
  94. package/dist/merge-styles-DGKWAJ4H.js.map +0 -1
  95. package/dist/resolve-recipes-UQ2um5Au.js +0 -144
  96. package/dist/resolve-recipes-UQ2um5Au.js.map +0 -1
  97. /package/dist/{async-storage-DKK-wTD4.js → chunks/async-storage-DKK-wTD4.js} +0 -0
@@ -1,17 +1,22 @@
1
1
  # Runtime Benchmarks
2
2
 
3
3
  Tasty keeps its performance claims in reproducible benchmarks rather than
4
- combining unlike measurements into one score. The repository measures three
4
+ combining unlike measurements into one score. The repository measures five
5
5
  different costs:
6
6
 
7
7
  1. Style parsing and generation in Node.
8
8
  2. The React overhead of an empty `tasty({})` wrapper.
9
9
  3. Cold browser generation and injection compared with equivalent CSS that is
10
10
  already on the page.
11
+ 4. The steady-state interaction path — mod flips and styled subtrees opening
12
+ and closing after the page has loaded.
13
+ 5. Page-load cold start: network, module compilation, execution and first
14
+ paint, end to end in a throttled browser.
11
15
 
12
- These are focused microbenchmarks, not page-load or interaction scores. Run
13
- them several times on an otherwise idle machine and use a production profile
14
- to decide whether any cost matters in an application.
16
+ The first four are focused microbenchmarks, not page-level scores. The fifth is
17
+ a page-level measurement and is the only one that answers "what does a visitor
18
+ wait for". Run them several times on an otherwise idle machine and use a
19
+ production profile to decide whether any cost matters in an application.
15
20
 
16
21
  ## Reproducing the Results
17
22
 
@@ -19,17 +24,21 @@ to decide whether any cost matters in an application.
19
24
  pnpm bench
20
25
  pnpm bench:overhead
21
26
  pnpm bench:injection
27
+ pnpm bench:interaction
28
+ pnpm bench:cold-start
22
29
  ```
23
30
 
24
- `pnpm bench` runs the core pipeline benchmarks in Node. The other two commands
25
- use production code paths in headless Chromium. The first checkout may require
26
- `pnpm test:setup` to download Chromium.
31
+ `pnpm bench` runs the core pipeline benchmarks in Node. The rest use production
32
+ code paths in headless Chromium. The first checkout may require
33
+ `pnpm test:setup` to download Chromium, and `pnpm bench:cold-start` needs a
34
+ current `dist/` — run `pnpm build` first.
27
35
 
28
36
  Run the Node and browser suites separately so they do not compete for CPU. The
29
- browser timer has 0.1 ms resolution, so both browser benchmarks perform many
37
+ browser timer has 0.1 ms resolution, so the browser benchmarks perform many
30
38
  matched operations per sample and divide the absolute difference by the number
31
- of elements or rules. Machine load, browser versions, and CPU power will move
32
- the results.
39
+ of elements, rules or interactions. Machine load, browser versions, and CPU
40
+ power will move the results — on a loaded machine the absolute columns drift
41
+ several percent while the raw/Tasty delta holds, so read the delta.
33
42
 
34
43
  ## Core Style Pipeline
35
44
 
@@ -159,10 +168,165 @@ together. Because the same resolution pattern is present in each workload's
159
168
  control, the difference answers the narrower delivery question: how much extra
160
169
  work did Tasty perform when the same CSS was not already there?
161
170
 
171
+ ## Steady-State Interaction
172
+
173
+ The benchmarks above measure mounting and whole-tree updates. A running
174
+ application spends most of its time on neither. It flips mods — hovered,
175
+ pressed, selected, expanded — on elements whose styles never change, one
176
+ element at a time, and it mounts and unmounts small styled subtrees as menus
177
+ and dialogs open. Both paths go through the state-map and ref-counting
178
+ machinery rather than the parser, so a regression in them is invisible to every
179
+ other benchmark here.
180
+
181
+ [`tasty-interaction.bench.tsx`](../src/tasty-interaction.bench.tsx) pairs each
182
+ case with a raw-DOM equivalent driven by a hand-written stylesheet that
183
+ produces the same computed color and background in both states. The benchmark
184
+ fails if either arm resolves to anything else, so an arm that quietly rendered
185
+ unstyled elements cannot report a flattering number.
186
+
187
+ Each leaf owns its own `useState`, which is what keeps a single-element
188
+ interaction single: re-rendering the root to flip one row would time the whole
189
+ tree. One toggle is far below Chromium's 0.1 ms timer resolution, so a sample
190
+ flips a 100-element tree three times over — 300 commits — and the churn case
191
+ performs 20 open/close cycles. Divide the raw/Tasty difference by those counts.
192
+
193
+ Two things had to be sized deliberately, and both are the difference between a
194
+ readable number and noise:
195
+
196
+ - **The tree is small (100 elements), not large.** React locates a leaf's
197
+ pending update by walking the sibling list, so in a 1,000-element tree a
198
+ single-element update costs ~68 us of traversal — identical in both arms and
199
+ an order of magnitude above anything the styling layer contributes.
200
+ - **The sample resolves style once, not once per flip.** Forcing a recalc
201
+ between flips costs ~70 us in both arms, which buries the delta the same way.
202
+ The browser's side of an interaction is real, but it is the browser's;
203
+ resolution boundaries are what the injection benchmark above measures.
204
+
205
+ The contract check also reads the injected CSS **before** any toggle and fails
206
+ if the hovered rule is not already there. That a style map's states all ship in
207
+ one chunk on first render is the premise of this case; if the hovered rule
208
+ arrived lazily, the first sample would be timing injection.
209
+
210
+ On an Apple M1 Max with React 19.2.8 and Chromium 151, across several runs:
211
+
212
+ | Workload | Raw elements | Tasty mods | Extra per unit |
213
+ | ---------------------------------------------------- | -----------: | -----------: | -----------------------: |
214
+ | 300 single-element mod toggles in a 100-element tree | 2.1–2.5 ms | 2.7–3.1 ms | 1.6–2.1 us / interaction |
215
+ | 20 mount + unmount cycles of a 200-element subtree | 7.6–8.0 ms | 12.6–12.7 ms | 1.22–1.27 us / element |
216
+
217
+ The absolute columns move several percent with machine load; the delta between
218
+ the arms is the stable quantity, so read that rather than either column.
219
+
220
+ Two things are worth reading out of this.
221
+
222
+ A mod flip on an already-mounted element costs about 2 us. The CSS for both
223
+ states already exists — Tasty emits every state of a style map in one chunk on
224
+ first render — so both arms perform the same commit, and what is left is
225
+ Tasty's props and mod handling. That is the same order as the ~1 us empty
226
+ wrapper measured above, which is most of where it comes from.
227
+
228
+ Subtree churn is not about styling at all. Its ~1.25 us per element sits right
229
+ on the empty-wrapper mount cost, because the styles are already cached:
230
+ reopening a menu re-pays the React wrapper, not the style pipeline.
231
+
232
+ ## Page-Load Cold Start
233
+
234
+ Every benchmark above deliberately excludes the network, module compilation and
235
+ the first render. [`scripts/cold-start`](../scripts/cold-start) measures exactly
236
+ those: what a visitor waits for between requesting a page and seeing styled
237
+ content, in a real Chromium under CDP network and CPU throttling.
238
+
239
+ Three pages render the same 50 styled components and are verified, before any
240
+ timing, to produce the same 50 elements at the same computed color:
241
+
242
+ - **baseline** — the components server-rendered: identical markup, identical
243
+ class names, a linked stylesheet, and no Tasty on the page. Every other
244
+ column is a delta against this one.
245
+ - **runtime** — Tasty generates the CSS in the browser, as a client-rendered
246
+ application does. The run asserts it really did (69 rules generated).
247
+ - **prewarm** — the same, after one throwaway `computeStyles()` against a
248
+ detached root before the first component renders.
249
+
250
+ Each cell is the median of 5 uncached loads in a fresh browser context. The run
251
+ ends at the first contentful paint, observed through a `PerformanceObserver`
252
+ rather than counted in animation frames — `requestAnimationFrame` fires before
253
+ paint, so a page that commits fast can reach its second frame with nothing
254
+ painted yet.
255
+
256
+ Two things about the payload decide whether this measures a deployment or a
257
+ straw man, so both are enforced rather than assumed:
258
+
259
+ - **Assets are served brotli-compressed**, the way a static host serves them.
260
+ The bundle is 52.0 KB on the wire and 186 KB decoded; putting the decoded
261
+ bytes on a 1.6 Mbps link would add ~700 ms and charge it to Tasty. The run
262
+ reads `encodedBodySize` back out of resource timing and fails if what
263
+ crossed the wire is not the compressed size the table reports.
264
+ - **The bundle is built from what the page imports** (`tasty`, `configure`,
265
+ `computeStyles`, `tastyDebug`), so it is tree-shaken as an application's
266
+ would be. Re-exporting the whole library adds ~4 KB brotli of code no page
267
+ here calls.
268
+
269
+ On an Apple M1 Max with React 19.2.8 and Chromium 151, first contentful paint:
270
+
271
+ | Link / CPU | baseline | runtime | prewarm | Tasty's cost |
272
+ | --------------------- | -------: | ------: | ------: | -----------: |
273
+ | No throttling, 1x | 40 ms | 52 ms | 52 ms | +12 ms |
274
+ | Fast 4G, 1x | 624 ms | 680 ms | 676 ms | +56 ms |
275
+ | Slow 4G, 1x | 2028 ms | 2304 ms | 2304 ms | +276 ms |
276
+ | No throttling, 4x CPU | 148 ms | 196 ms | 196 ms | +48 ms |
277
+ | Fast 4G, 4x CPU | 684 ms | 784 ms | 788 ms | +100 ms |
278
+ | Slow 4G, 4x CPU | 2096 ms | 2416 ms | 2408 ms | +320 ms |
279
+
280
+ That is one full run of the matrix; a second moved every cell by a few percent.
281
+
282
+ **The cost is the bundle, not the work.** On Slow 4G the extra transfer alone
283
+ accounts for 262 ms of the 276 ms FCP delta — nearly all of it. Everything
284
+ Tasty then *does* is small by comparison:
285
+
286
+ | Phase (Slow 4G, 1x) | baseline | runtime | prewarm |
287
+ | ----------------------- | -------: | ------: | ------: |
288
+ | js+css transfer | 1420 ms | 1682 ms | 1681 ms |
289
+ | module compile (shared) | 1.2 ms | 1.5 ms | 2.0 ms |
290
+ | tasty top-level execute | — | 1.2 ms | 0.9 ms |
291
+ | `configure()` | — | 0.6 ms | 0.5 ms |
292
+ | prewarm | — | — | 5.3 ms |
293
+ | render 1st component | 2.0 ms | 8.2 ms | 2.7 ms |
294
+ | render 49 more | 1.0 ms | 7.1 ms | 6.0 ms |
295
+
296
+ Importing Tasty costs about 1 ms of top-level execution; `configure()` costs
297
+ half of one. The rest of the CPU delta — about 13 ms for 50 components — is
298
+ generation and injection, which is the cost the injection benchmark isolates.
299
+
300
+ One asymmetry is worth naming: the control links a render-blocking stylesheet
301
+ and the runtime modes have none, so the control's first paint waits for CSS the
302
+ runtime modes never request. That is the real difference between the two
303
+ delivery models, not a thumb on the scale, but it means the FCP delta is not
304
+ purely "what Tasty costs to execute".
305
+
306
+ **Prewarming moves the wake-up, it does not remove it.** The first styled render
307
+ is ~5 ms more expensive than the ones after it, because that is when the
308
+ engine's deferred payload is actually compiled. A throwaway `computeStyles()`
309
+ against a detached root pays it early: `render 1st` drops from 8.2 ms to
310
+ 2.7 ms. The prewarm itself costs 5.3 ms, so FCP does not move. It is worth
311
+ doing only when something else can overlap it, or when the first render is on a
312
+ latency-critical path and the page has idle time before it.
313
+
314
+ **Retained heap.** After a forced collection, the runtime page holds about
315
+ 1,013 KB more than the control (2,632 KB vs 1,619 KB) for 50 components — the
316
+ parser caches, the chunk cache, the injector's registry and the generated CSS.
317
+ The control is not zero either; most of its 1.6 MB is React and the DOM.
318
+
319
+ CPU throttling changes which line moves. At 4x, module compilation of the
320
+ larger graph becomes visible (5.9 ms → 25 ms) where at 1x it is free: V8
321
+ pre-parses at import and compiles lazily, so a slower CPU pays for code the
322
+ faster one never fully compiled. Transfer numbers from the unthrottled cells
323
+ are not worth reading — with no emulated link, resource timings are scheduling
324
+ jitter.
325
+
162
326
  ## Reading the Results Together
163
327
 
164
- Do not add all three benchmark numbers to estimate an application blindly.
165
- They describe different paths:
328
+ Do not add the microbenchmark numbers together to estimate an application
329
+ blindly. They describe different paths:
166
330
 
167
331
  - A stable `tasty()` factory can skip the style pipeline on later renders, but
168
332
  its React wrapper still participates in reconciliation.
@@ -170,9 +334,18 @@ They describe different paths:
170
334
  rule.
171
335
  - A genuinely new style pays generation and injection once, then becomes
172
336
  reusable.
337
+ - A mod flip on an already-styled element pays neither; it is a class-name
338
+ change.
173
339
  - Browser style resolution, layout, and paint depend on the actual document and
174
340
  need application-level profiling.
175
341
 
342
+ The cold-start measurement is the one that puts the rest in proportion. On a
343
+ slow connection, nearly all of Tasty's page-load cost is transferring the
344
+ library — 262 ms of a 276 ms delta — while the generation and injection the
345
+ microbenchmarks obsess over is ~13 ms for 50 components. Bundle size is
346
+ therefore the lever with the largest effect on first paint, and the runtime
347
+ levers matter for what happens after it.
348
+
176
349
  The practical optimization target is therefore repeated work: keep style input
177
350
  stable when possible, reuse generated chunks, and generate CSS at build or
178
351
  server time when runtime flexibility is unnecessary.
package/docs/ssr.md CHANGED
@@ -86,6 +86,92 @@ export default function RootLayout({
86
86
 
87
87
  That's it. All `tasty()` components inside the tree automatically get SSR support. No per-component changes needed.
88
88
 
89
+ ### Optional shared globals stylesheet
90
+
91
+ By default, configured global CSS is included in the streamed Tasty style tag
92
+ for every route. `withTastyNext()` can move that stable CSS into one
93
+ content-hashed stylesheet shared by all routes while leaving component and hook
94
+ styles in the normal streaming path.
95
+
96
+ Keep the Tasty config in a side-effect-free module:
97
+
98
+ ```ts
99
+ // app/tasty.config.ts
100
+ import type { TastyConfig } from '@tenphi/tasty';
101
+
102
+ const config: TastyConfig = {
103
+ tokens: { $gap: '8px', '#brand': 'rebeccapurple' },
104
+ globalStyles: { body: { margin: '0', color: '#brand' } },
105
+ fontFaces: {
106
+ Brand: { src: 'url("/fonts/brand.woff2") format("woff2")' },
107
+ },
108
+ };
109
+
110
+ export default config;
111
+ ```
112
+
113
+ Use it from the Next config:
114
+
115
+ ```ts
116
+ // next.config.ts
117
+ import { withTastyNext } from '@tenphi/tasty/ssr/next-config';
118
+ import config from './app/tasty.config';
119
+
120
+ export default withTastyNext({
121
+ config,
122
+ })({
123
+ // your Next.js config
124
+ });
125
+ ```
126
+
127
+ The runtime must receive the same config. Import and configure it before the
128
+ registry renders:
129
+
130
+ ```tsx
131
+ // app/tasty-registry.tsx
132
+ 'use client';
133
+
134
+ import { configure } from '@tenphi/tasty';
135
+ import { TastyRegistry } from '@tenphi/tasty/ssr/next';
136
+ import config from './tasty.config';
137
+
138
+ configure(config);
139
+
140
+ export default function TastyStyleRegistry({ children }) {
141
+ return <TastyRegistry>{children}</TastyRegistry>;
142
+ }
143
+ ```
144
+
145
+ The generated file contains eager configuration artifacts: built-in and custom
146
+ `@property` rules, tokens and presets, `@font-face`, `@counter-style`, native
147
+ CSS `@function` definitions, and `globalStyles`. Route-dependent component
148
+ rules and calls to `useGlobalStyles`, `useRawCSS`, `useKeyframes`,
149
+ `useProperty`, `useFontFace`, `useCounterStyle`, and `useFunction` remain
150
+ route-specific. Configured keyframes also remain lazy and are streamed only
151
+ when a route references them.
152
+
153
+ The default output directory is `public/_tasty`. The wrapper adds the generated
154
+ URL to `TastyRegistry`, respects `basePath`, preserves existing `env` and
155
+ `headers` config, and serves the content-hashed file with an immutable one-year
156
+ cache header on Next server deployments. Static exports keep the content-hashed
157
+ URL and leave cache headers to the hosting provider. Older hashes are not
158
+ deleted automatically, so rolling deployments cannot break pages from the
159
+ previous build; clean the generated directory as part of a clean deployment if
160
+ needed. Page-relative CSS resources such as
161
+ `url(../fonts/brand.woff2)` are rejected because moving them would change their
162
+ meaning; use root-relative, absolute, or data URLs.
163
+
164
+ `withTastyNext()` options:
165
+
166
+ | Option | Type | Default | Description |
167
+ | ------------ | ------------- | ------------------------- | ---------------------------------------------------------------------- |
168
+ | `config` | `TastyConfig` | — | Config object; takes precedence over `configFile` |
169
+ | `configFile` | `string` | — | Project-relative config module path; requires the optional `jiti` peer |
170
+ | `rootDir` | `string` | current directory | Next app root when the build runs from a monorepo root |
171
+ | `outputDir` | `string` | `public/_tasty` | Filesystem output directory |
172
+ | `publicPath` | `string` | inferred from `outputDir` | Root-relative URL; required when output is outside `public` |
173
+ | `enabled` | `boolean` | `true` | Disable generation without changing wrapper composition |
174
+
89
175
  ### How it works
90
176
 
91
177
  - `TastyRegistry` is a `'use client'` component, but Next.js still server-renders it on initial page load. The `'use client'` boundary is required solely to access `useServerInsertedHTML` — **not** because `tasty()` components need the client.
@@ -128,13 +214,15 @@ The nonce is automatically applied to all `<style>` and `<script>` tags injected
128
214
 
129
215
  ## Astro
130
216
 
131
- Tasty offers three levels of Astro integration. Choose the one that matches your needs:
217
+ Tasty offers several levels of Astro integration. Choose the one that matches your needs:
132
218
 
133
- | Setup | Config needed | Deduplication | Hooks work | Client JS |
134
- | -------------------------------------- | ------------- | --------------- | ---------------------- | -------------- |
135
- | Zero setup | None | Per render tree | Yes (within each tree) | None |
136
- | `tastyIntegration({ islands: false })` | One line | Cross-tree | Yes | None |
137
- | `tastyIntegration()` | One line | Cross-tree | Yes | Auto-hydration |
219
+ | Setup | Config needed | Deduplication | Hooks work | Client JS |
220
+ | ---------------------------------------------------------------- | ------------- | ------------------------- | ---------------------- | -------------- |
221
+ | Zero setup | None | Per render tree | Yes (within each tree) | None |
222
+ | `tastyIntegration({ islands: false })` | One line | Cross-tree | Yes | None |
223
+ | `tastyIntegration()` | One line | Cross-tree | Yes | Auto-hydration |
224
+ | `tastyIntegration({ css: { mode: 'extract' } })` | One line | Cross-tree and cross-page | Yes | Auto-hydration |
225
+ | `tastyIntegration({ islands: false, css: { mode: 'extract' } })` | One line | Cross-tree and cross-page | Yes | None |
138
226
 
139
227
  ### Zero setup (static pages)
140
228
 
@@ -231,6 +319,63 @@ export default defineConfig({
231
319
 
232
320
  This gives the same middleware deduplication and hook support, but ships zero client-side JavaScript. No class-list `<script>` is emitted.
233
321
 
322
+ #### Build-wide CSS extraction
323
+
324
+ Static Astro builds can move Tasty CSS into content-hashed, browser-cacheable
325
+ shared and page assets:
326
+
327
+ ```ts
328
+ export default defineConfig({
329
+ integrations: [
330
+ react(),
331
+ tastyIntegration({
332
+ islands: false,
333
+ css: {
334
+ mode: 'extract',
335
+ },
336
+ }),
337
+ ],
338
+ });
339
+ ```
340
+
341
+ `css.mode` defaults to `'inline'`, so existing projects keep their current
342
+ output. Extraction requires Astro 5 or newer and only applies to prerendered
343
+ production pages. Development, preview-time SSR, and on-demand routes continue
344
+ to receive the normal inline `<style data-tasty-ssr>` output.
345
+
346
+ Extraction writes every artifact emitted by all styled pages to a shared
347
+ stylesheet. Each page's strict set difference is written to a separate page
348
+ stylesheet. The shared link comes first and the page link follows, so shared
349
+ styles form the base cascade and page-only styles can override them. A fully
350
+ shared page omits the empty page stylesheet. If generated pages have no common
351
+ artifacts, each page receives only its page stylesheet.
352
+
353
+ The shared-base/page-override order is the extraction-mode cascade contract.
354
+ It does not preserve an inline artifact order where a page-only rule originally
355
+ appeared before a shared rule. Use shared styles for defaults and page-only
356
+ styles for overrides.
357
+
358
+ Extracted CSS preserves resource URLs verbatim. Relative URLs in an inline
359
+ style resolve from the page, but in an extracted stylesheet they resolve from
360
+ the asset directory. Use absolute URLs or data URLs when extraction is enabled.
361
+ Root-relative URLs such as `url(/fonts/brand.woff2)` are also safe while the
362
+ stylesheet stays on the page's origin. The build fails with a clear error if an
363
+ artifact contains a page-relative or fragment-only URL, including URL strings
364
+ in `image-set()`, `image()`, `src()`, and `@import`.
365
+
366
+ Assets are written under Astro's configured `build.assets` directory (for
367
+ example, `/_astro/tasty.shared.a1b2c3.css` and
368
+ `/_astro/tasty.page.d4e5f6.css`). Links include the configured Astro `base`, so
369
+ nested routes do not need relative-path handling. Content hashes and output are
370
+ deterministic for identical builds. If `build.assetsPrefix` is configured,
371
+ Tasty uses its CSS-specific prefix (or `fallback`) just like Astro-generated
372
+ stylesheets. When that prefix points to a different origin, root-relative
373
+ resources would resolve against the asset origin rather than the page's origin,
374
+ so the build rejects them as well. Tasty compares the prefix with Astro's `site`
375
+ when it is configured; without `site`, an absolute or protocol-relative prefix
376
+ is treated conservatively as cross-origin. Use a fully absolute resource URL in
377
+ that configuration.
378
+
234
379
  ### Manual middleware (advanced)
235
380
 
236
381
  If you need to compose Tasty's middleware with other middleware (e.g., via `sequence()`), use `tastyMiddleware()` directly:
@@ -263,10 +408,15 @@ Astro's `@astrojs/react` renderer calls `renderToString()` for each React compon
263
408
  - **Static components** (no `client:*`): Styles are collected during `renderToString` and injected into `</head>` as a single `<style>` tag. No JavaScript is shipped.
264
409
  - **Islands** (`client:load`, `client:visible`, etc.): Styles are collected during SSR the same way. On the client, the hydration script (auto-injected by `tastyIntegration()` or manually via `@tenphi/tasty/ssr/astro-client`) reads the class list from `window.__TASTY__` and pre-populates the injector's rules map. The island's `computeStyles()` calls see the class names as already registered and skip the pipeline during hydration.
265
410
  - The middleware reads the full response body, then injects the collected CSS into `</head>` before sending the final HTML.
411
+ - In extraction mode, prerendered responses also carry temporary structured
412
+ artifact metadata. `astro:build:done` uses those collector-provided
413
+ boundaries to write shared and page assets and rewrite generated HTML, then
414
+ removes the metadata. Artifact boundaries are never inferred by splitting or
415
+ reparsing the generated CSS.
266
416
 
267
417
  ### CSP nonce
268
418
 
269
- Call `configure({ nonce: '...' })` before any rendering happens. The middleware reads the nonce and applies it to injected `<style>` and `<script>` tags.
419
+ Call `configure({ nonce: '...' })` before any rendering happens. The middleware reads the nonce and applies it to injected `<style>` and `<script>` tags. In extraction mode, the external stylesheet links retain the nonce.
270
420
 
271
421
  ---
272
422
 
@@ -349,13 +499,14 @@ const stream = await runWithCollector(collector, () =>
349
499
 
350
500
  ### Entry points
351
501
 
352
- | Import path | Description |
353
- | ----------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
354
- | `@tenphi/tasty/ssr` | Core SSR API: `ServerStyleCollector`, `createServerStyleCollector`, `runWithCollector`, `hydrateTastyClasses` |
355
- | `@tenphi/tasty/ssr/next` | Next.js App Router: `TastyRegistry` component |
356
- | `@tenphi/tasty/ssr/astro` | Astro: `tastyIntegration`, `tastyMiddleware` |
357
- | `@tenphi/tasty/ssr/astro-client` | Astro: client-side cache hydration (auto-injected by integration, or import manually) |
358
- | `@tenphi/tasty/ssr/astro-middleware`<br>`@tenphi/tasty/ssr/astro-middleware-static` | Astro: the middleware entrypoints `tastyIntegration()` registers via `addMiddleware()`. Exported so Astro can resolve them by specifier; you should not import them. For manual setups use `tastyMiddleware()`. |
502
+ | Import path | Description |
503
+ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
504
+ | `@tenphi/tasty/ssr` | Core SSR API: `ServerStyleCollector`, `createServerStyleCollector`, `runWithCollector`, `hydrateTastyClasses` |
505
+ | `@tenphi/tasty/ssr/next` | Next.js App Router: `TastyRegistry` component |
506
+ | `@tenphi/tasty/ssr/next-config` | Next.js config wrapper: shared, content-hashed global stylesheet |
507
+ | `@tenphi/tasty/ssr/astro` | Astro: `tastyIntegration`, `tastyMiddleware` |
508
+ | `@tenphi/tasty/ssr/astro-client` | Astro: client-side cache hydration (auto-injected by integration, or import manually) |
509
+ | `@tenphi/tasty/ssr/astro-middleware`<br>`@tenphi/tasty/ssr/astro-middleware-static`<br>`@tenphi/tasty/ssr/astro-middleware-extract`<br>`@tenphi/tasty/ssr/astro-middleware-extract-static` | Astro: the middleware entrypoints `tastyIntegration()` registers via `addMiddleware()`. Exported so Astro can resolve them by specifier; you should not import them. For manual setups use `tastyMiddleware()`. |
359
510
 
360
511
  ### `ServerStyleCollector`
361
512
 
@@ -375,7 +526,7 @@ Constructor: `new ServerStyleCollector(namePrefix?)`, or use the `createServerSt
375
526
  | `allocateCounterStyleName(providedName?)` | Allocate a counter-style name. Returns `providedName` if given, otherwise generates one using `${namePrefix}c${counter}` (e.g. `tc0`, `tc1`, ...). |
376
527
  | `collectGlobalStyles(key, css)` | Record global styles (from `useGlobalStyles`). Deduplicated by key. |
377
528
  | `collectRawCSS(key, css)` | Record raw CSS text (from `useRawCSS`). Deduplicated by key. |
378
- | `collectInternals()` | Collect internal `@property` rules, `:root` token defaults, `@font-face`, and `@counter-style` rules from the global config. Called automatically on first chunk collection; idempotent. |
529
+ | `collectInternals()` | Collect eager configured globals: `@property`, `:root` tokens and presets, `@font-face`, `@counter-style`, `@function`, and `globalStyles`. Called automatically on first chunk collection; idempotent. |
379
530
  | `getCSS()` | Get all collected CSS as a single string. For non-streaming SSR. |
380
531
  | `flushCSS()` | Get only CSS collected since the last flush. For streaming SSR. |
381
532
  | `getRenderedClassNames()` | Get the list of class names rendered so far. Serialized to `window.__TASTY__` for client hydration via `hydrateTastyClasses()`. |
@@ -384,10 +535,18 @@ Constructor: `new ServerStyleCollector(namePrefix?)`, or use the `createServerSt
384
535
 
385
536
  Next.js App Router component. Props:
386
537
 
387
- | Prop | Type | Default | Description |
388
- | --------------- | ----------- | -------- | ------------------------------------------------ |
389
- | `children` | `ReactNode` | required | Application tree |
390
- | `transferCache` | `boolean` | `true` | Embed cache state script for zero-cost hydration |
538
+ | Prop | Type | Default | Description |
539
+ | ------------------ | ----------------- | --------- | ------------------------------------------------------------------------- |
540
+ | `children` | `ReactNode` | required | Application tree |
541
+ | `transferCache` | `boolean` | `true` | Embed cache state script for zero-cost hydration |
542
+ | `sharedStylesheet` | `string \| false` | generated | Override the shared URL, or disable generated shared CSS for the registry |
543
+
544
+ ### `withTastyNext(options)`
545
+
546
+ Next.js configuration wrapper exported from
547
+ `@tenphi/tasty/ssr/next-config`. It generates a shared stylesheet from eager
548
+ Tasty configuration artifacts and wires its URL and immutable cache header
549
+ into the Next config. Route-specific CSS continues through `TastyRegistry`.
391
550
 
392
551
  ### `tastyIntegration(options?)`
393
552
 
@@ -429,7 +588,7 @@ Class names are also derived from the _resolved_ styles, so the server and the c
429
588
 
430
589
  ### Styles duplicated after hydration
431
590
 
432
- **Global CSS** (`:root` tokens, `@property`, `globalStyles`, `@font-face`, `@counter-style`) configured via `configure()` is automatically deduplicated. When Tasty detects `<style data-tasty-ssr>` in the document, it skips client-side injection of globals that were already rendered by the SSR collector. This means `configure()` can be called with the full config on both server and client — no `typeof window === 'undefined'` guard is needed.
591
+ **Global CSS** (`:root` tokens, `@property`, `globalStyles`, `@font-face`, `@counter-style`, `@function`) configured via `configure()` is automatically deduplicated. When Tasty detects an inline or extracted `[data-tasty-ssr]` stylesheet in the document, it skips client-side injection of globals that were already rendered by the SSR collector. This means `configure()` can be called with the full config on both server and client — no `typeof window === 'undefined'` guard is needed.
433
592
 
434
593
  **Component CSS**: SSR `<style data-tasty-ssr>` tags remain in the DOM. The client injector creates separate `<style>` elements for any new styles. SSR styles are never modified or removed by the client. If this is a concern for very large apps, you can remove the SSR style tags and hydration scripts manually after hydration:
435
594
 
package/docs/styles.md CHANGED
@@ -20,9 +20,10 @@ Use these instead of their raw CSS counterparts:
20
20
  |-----|------------|
21
21
  | `fill` | `backgroundColor`, `background` |
22
22
  | `image` | `backgroundImage` |
23
- | `padding` (with direction modifiers) | `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft` |
24
- | `margin` (with direction modifiers) | `marginTop`, `marginRight`, `marginBottom`, `marginLeft` |
25
- | `width` (with `min`/`max` modifiers) | `minWidth`, `maxWidth` |
23
+ | `padding` (with physical direction modifiers) | `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft` |
24
+ | `margin` (with physical direction modifiers) | `marginTop`, `marginRight`, `marginBottom`, `marginLeft` |
25
+ | Logical block/inline category styles (with `start`/`end` modifiers) | Native logical axis/edge declarations |
26
+ | `width` / `blockSize` / `inlineSize` (with `min`/`max` modifiers) | Their separate min/max declarations when one state map is sufficient |
26
27
  | `height` (with `min`/`max` modifiers) | `minHeight`, `maxHeight` |
27
28
  | `border` | `borderColor`, `borderWidth`, `borderStyle` |
28
29
  | `radius` | `borderRadius` |
@@ -125,9 +126,7 @@ A group that names *no* direction keeps plain CSS shorthand order, which is unam
125
126
 
126
127
  Later comma-separated groups override earlier groups for conflicting directions.
127
128
 
128
- Individual props `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft`, `paddingBlock`, `paddingInline` are supported but `padding` with modifiers is recommended.
129
-
130
- **Priority:** `padding` < `paddingBlock`/`paddingInline` < `paddingTop`/`paddingRight`/`paddingBottom`/`paddingLeft`
129
+ Individual physical props `paddingTop`, `paddingRight`, `paddingBottom`, and `paddingLeft` are supported, but `padding` with modifiers is recommended. Use `blockPadding` or `inlinePadding` for an enhanced logical-axis shorthand; native declarations such as `paddingInlineStart` remain ordinary CSS properties. See [Logical properties](#logical-properties).
131
130
 
132
131
  ### `margin`
133
132
 
@@ -153,9 +152,7 @@ The [one-value-per-directional-group rule](#padding) from `padding` applies here
153
152
 
154
153
  Later comma-separated groups override earlier groups for conflicting directions.
155
154
 
156
- Individual props `marginTop`, `marginRight`, `marginBottom`, `marginLeft`, `marginBlock`, `marginInline` are supported but `margin` with modifiers is recommended.
157
-
158
- **Priority:** `margin` < `marginBlock`/`marginInline` < `marginTop`/`marginRight`/`marginBottom`/`marginLeft`
155
+ Individual physical props `marginTop`, `marginRight`, `marginBottom`, and `marginLeft` are supported, but `margin` with modifiers is recommended. Use `blockMargin` or `inlineMargin` for an enhanced logical-axis shorthand; native declarations such as `marginInlineStart` remain ordinary CSS properties. See [Logical properties](#logical-properties).
159
156
 
160
157
  ### `width`
161
158
 
@@ -234,9 +231,44 @@ second to every side they span.
234
231
 
235
232
  Later comma-separated groups override earlier groups for conflicting directions.
236
233
 
237
- Individual props `top`, `right`, `bottom`, `left`, `insetBlock`, `insetInline` are supported. When only individual direction props are used (without `inset`), individual CSS properties are output for correct cascade behavior with state overrides.
234
+ Individual physical props `top`, `right`, `bottom`, and `left` are supported. When only those props are used (without `inset`), individual CSS properties are output for correct cascade behavior with state overrides. Use `blockInset` or `inlineInset` for logical axes; native declarations such as `insetInlineStart` remain ordinary CSS properties.
235
+
236
+ ### Logical properties
237
+
238
+ Tasty provides one enhanced handler for each logical axis/category pair. Each handler emits native logical CSS instead of converting values to `top`, `right`, `bottom`, `left`, `width`, or `height`. The browser therefore resolves `block`, `inline`, `start`, and `end` from the element's `writingMode` and `direction`.
239
+
240
+ ```jsx
241
+ styles: {
242
+ direction: 'rtl',
243
+ inlinePadding: '1x start, 2x end',
244
+ inlineBorder: '1bw solid #accent start',
245
+ blockInset: '0 end',
246
+ }
247
+ ```
248
+
249
+ An axis handler accepts one value for both edges or two values in logical **start/end** order. Use `start` and `end` modifiers, with comma-separated groups for different edge values. Unspecified padding, margin, and scroll edges reset to `0`; unspecified inset edges reset to `auto`. The `longhand` modifier emits the two native start/end declarations.
250
+
251
+ | Category | Block axis | Inline axis |
252
+ |----------|------------|-------------|
253
+ | Size | `blockSize` | `inlineSize` |
254
+ | Padding | `blockPadding` | `inlinePadding` |
255
+ | Margin | `blockMargin` | `inlineMargin` |
256
+ | Inset | `blockInset` | `inlineInset` |
257
+ | Scroll margin | `blockScrollMargin` | `inlineScrollMargin` |
258
+ | Scroll padding | `blockScrollPadding` | `inlineScrollPadding` |
259
+ | Border | `blockBorder` | `inlineBorder` |
260
+
261
+ `blockSize` and `inlineSize` use the same enhanced one/two/three-value and `min`/`max`/`fixed` syntax as `width`. Separate `minBlockSize`, `maxBlockSize`, `minInlineSize`, and `maxInlineSize` declarations override constraints produced by that shorthand.
262
+
263
+ `blockBorder` and `inlineBorder` use the same width/style/color parsing and defaults as `border`, including `1bw`, color tokens, and `true`. Logical padding, margin, scroll margin, and scroll padding default to `1x` for `true`; logical inset defaults to `0`.
264
+
265
+ Native logical CSS names—such as `paddingInlineStart`, `borderBlockColor`, and `borderStartStartRadius`—remain available as ordinary CSS properties. They support Tasty tokens and units through the normal value parser, but do not get category defaults or directional shorthand behavior.
266
+
267
+ The physical `scrollMargin` and `scrollPadding` shorthands support the same values and physical direction modifiers as `padding`. Their logical counterparts stay in separate axis handlers.
268
+
269
+ `writingMode`, `direction`, and `textOrientation` are standard CSS control properties. They use Tasty's normal value parser and need no special handler.
238
270
 
239
- **Priority:** `inset` < `insetBlock`/`insetInline` < `top`/`right`/`bottom`/`left`
271
+ Avoid setting physical and logical declarations that resolve to the same edge in one style block. Tasty keeps them separate and lets the native CSS cascade resolve the overlap, whose result also depends on writing mode and direction.
240
272
 
241
273
  ---
242
274