@tenphi/tasty 3.6.0 → 3.8.0

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 (65) hide show
  1. package/dist/{astro-CzY4LCpr.js → astro-w8r-u4qo.js} +6 -142
  2. package/dist/astro-w8r-u4qo.js.map +1 -0
  3. package/dist/{babel-DWCsafYw.d.ts → babel-Cp_dRhuS.d.ts} +2 -2
  4. package/dist/{collector-C6TtL8HJ.js → collector-C7YBiY7D.js} +3 -3
  5. package/dist/{collector-C6TtL8HJ.js.map → collector-C7YBiY7D.js.map} +1 -1
  6. package/dist/{collector-BTVXj2hS.d.ts → collector-CUtAFyIb.d.ts} +2 -2
  7. package/dist/{config-LfIDmVHx.d.ts → config-BY1e5y7V.d.ts} +2 -2
  8. package/dist/{config-B3gPdCqd.js → config-yXpe2jAV.js} +404 -157
  9. package/dist/config-yXpe2jAV.js.map +1 -0
  10. package/dist/core/index.d.ts +4 -4
  11. package/dist/core/index.js +5 -5
  12. package/dist/{core-Bq7w2kti.js → core-DoEZAHJq.js} +79 -33
  13. package/dist/{core-Bq7w2kti.js.map → core-DoEZAHJq.js.map} +1 -1
  14. package/dist/css-resources-Cyl_axbI.js +149 -0
  15. package/dist/css-resources-Cyl_axbI.js.map +1 -0
  16. package/dist/{css-writer-Bgowobbx.js → css-writer-BiumPvq-.js} +3 -3
  17. package/dist/{css-writer-Bgowobbx.js.map → css-writer-BiumPvq-.js.map} +1 -1
  18. package/dist/{format-rules-rCZ37rqY.js → format-rules-DHuG25KU.js} +3 -29
  19. package/dist/format-rules-DHuG25KU.js.map +1 -0
  20. package/dist/{hydrate-CNOmZprz.js → hydrate-BvRP6QEC.js} +2 -2
  21. package/dist/{hydrate-CNOmZprz.js.map → hydrate-BvRP6QEC.js.map} +1 -1
  22. package/dist/{index-BmogEzTo.d.ts → index-DBjd4MAb.d.ts} +46 -5
  23. package/dist/{index-Bm9ltvdH.d.ts → index-uX74k5jG.d.ts} +93 -46
  24. package/dist/index.d.ts +4 -4
  25. package/dist/index.js +6 -6
  26. package/dist/{keyframes-DE-OE76F.js → keyframes-B8uPLZwx.js} +2 -2
  27. package/dist/{keyframes-DE-OE76F.js.map → keyframes-B8uPLZwx.js.map} +1 -1
  28. package/dist/{merge-styles-DuoZEsm9.js → merge-styles-ChW1k-ZM.js} +2 -2
  29. package/dist/{merge-styles-DuoZEsm9.js.map → merge-styles-ChW1k-ZM.js.map} +1 -1
  30. package/dist/{merge-styles-BcLl1u_d.d.ts → merge-styles-pf6iPs82.d.ts} +2 -2
  31. package/dist/{resolve-recipes-H9NqOQuP.js → resolve-recipes-BNmjANzT.js} +3 -3
  32. package/dist/{resolve-recipes-H9NqOQuP.js.map → resolve-recipes-BNmjANzT.js.map} +1 -1
  33. package/dist/ssr/astro-client.js +1 -1
  34. package/dist/ssr/astro-middleware-extract-static.js +1 -1
  35. package/dist/ssr/astro-middleware-extract.js +1 -1
  36. package/dist/ssr/astro-middleware-static.js +1 -1
  37. package/dist/ssr/astro-middleware.js +1 -1
  38. package/dist/ssr/astro.js +1 -1
  39. package/dist/ssr/index.d.ts +1 -1
  40. package/dist/ssr/index.js +3 -3
  41. package/dist/ssr/next-config.d.ts +66 -0
  42. package/dist/ssr/next-config.js +115 -0
  43. package/dist/ssr/next-config.js.map +1 -0
  44. package/dist/ssr/next.d.ts +9 -2
  45. package/dist/ssr/next.js +26 -9
  46. package/dist/ssr/next.js.map +1 -1
  47. package/dist/ssr-collector-ref-COs_ioWl.js +29 -0
  48. package/dist/ssr-collector-ref-COs_ioWl.js.map +1 -0
  49. package/dist/static/index.d.ts +2 -2
  50. package/dist/static/index.js +1 -1
  51. package/dist/zero/babel.d.ts +1 -1
  52. package/dist/zero/babel.js +4 -4
  53. package/dist/zero/index.d.ts +1 -1
  54. package/dist/zero/index.js +1 -1
  55. package/dist/zero/next.d.ts +1 -1
  56. package/docs/ai-agents.md +8 -3
  57. package/docs/debug.md +13 -0
  58. package/docs/methodology.md +3 -3
  59. package/docs/runtime-benchmarks.md +185 -12
  60. package/docs/ssr.md +113 -18
  61. package/docs/styles.md +43 -11
  62. package/package.json +14 -6
  63. package/dist/astro-CzY4LCpr.js.map +0 -1
  64. package/dist/config-B3gPdCqd.js.map +0 -1
  65. package/dist/format-rules-rCZ37rqY.js.map +0 -1
package/docs/ai-agents.md CHANGED
@@ -50,6 +50,8 @@ Prefer the Tasty shorthand over its CSS equivalents:
50
50
  | `hide: true` | `display: 'none'` |
51
51
  | `flexGrow` / `flexShrink` / `flexBasis` | `flex` |
52
52
 
53
+ Use logical category styles when layout must follow writing mode or direction: `blockSize`/`inlineSize`, `blockPadding`/`inlinePadding`, `blockMargin`/`inlineMargin`, `blockInset`/`inlineInset`, `blockScrollMargin`/`inlineScrollMargin`, `blockScrollPadding`/`inlineScrollPadding`, and `blockBorder`/`inlineBorder`. Use `start`/`end` value modifiers; do not replace them with physical sides. Native logical CSS properties remain valid as ordinary keys when an individual declaration is needed.
54
+
53
55
  The last row goes the other way — longhands over the shorthand — because `flex` is lossy: it resets the components you omit to non-initial values (`flex: '0'` silently sets `flex-basis: 0%`) and cannot express `flexShrink: 0` at all. The longhands also carry separate state maps.
54
56
 
55
57
  ## 3. Values
@@ -86,7 +88,7 @@ Prefer units over raw pixels: `8px` → `1x` … `64px` → `8x`; `radius: '6px'
86
88
 
87
89
  ### `true`
88
90
 
89
- `true` means "the design-system default" and is accepted **only** by: `border`, `radius`, `outline`, `shadow`, `padding`, `margin`, `gap`, `inset`, `width`, `height`, `fill`, `color`, `fade`, `preset`, `font`, `scrollbar`, `hide`. Anywhere else it is an error.
91
+ `true` means "the design-system default" and is accepted **only** by: `border`, `radius`, `outline`, `shadow`, `padding`, `margin`, `gap`, `inset`, `width`, `height`, `fill`, `color`, `fade`, `preset`, `font`, `scrollbar`, `scrollMargin`, `scrollPadding`, and the enhanced logical category styles listed above, plus `hide`. Anywhere else it is an error.
90
92
 
91
93
  ### `!important`
92
94
 
@@ -100,9 +102,11 @@ A value is `[values…] [modifiers…]`, and several groups can be comma-separat
100
102
  | ------------------------------------ | ---------------------------------------------------------------------------------------------------------- |
101
103
  | `padding`, `margin`, `inset`, `fade` | `top` `right` `bottom` `left` |
102
104
  | `border` | the four directions + `solid` `dashed` `dotted` `double` `groove` `ridge` `inset` `outset` `none` `hidden` |
105
+ | logical axis spacing/inset styles | `start` `end` |
106
+ | `blockBorder`, `inlineBorder` | `start` `end` + the border style keywords above |
103
107
  | `outline` | the style keywords above |
104
108
  | `radius` | `top` `right` `bottom` `left` + shapes `round` `ellipse` `leaf` `backleaf` |
105
- | `width`, `height` | `min` `max` `fixed` |
109
+ | `width`, `height`, `blockSize`, `inlineSize` | `min` `max` `fixed` |
106
110
  | `flow` | `row` `column` `row-reverse` `column-reverse` `wrap` `nowrap` `dense` |
107
111
  | `overflow` | `visible` `hidden` `scroll` `clip` `auto` `overlay` |
108
112
  | `position` | `static` `relative` `absolute` `fixed` `sticky` |
@@ -118,7 +122,7 @@ Directional modifiers beat placeholder zeros:
118
122
  - ❌ `padding: '2x 4x top right'` — a directional group takes one value, so `4x` is dropped → ✅ `padding: '2x top, 4x right'`
119
123
  - ❌ `fade: '3x 1x top bottom'` → ✅ `fade: '3x top, 1x bottom'`
120
124
 
121
- Value-only properties reject both colors and modifiers: `gap`, `columnGap`, `rowGap`, `opacity`, `zIndex`, `order`, `flexGrow`, `flexShrink`, `flexBasis`, `aspectRatio`, `lineClamp`, `tabSize`, `paddingInline`, `paddingBlock`. `fill` and `color` take a color (plus `none` / `transparent`); `caretColor` and `accentColor` take a color only.
125
+ Value-only properties reject both colors and modifiers: `gap`, `columnGap`, `rowGap`, `opacity`, `zIndex`, `order`, `flexGrow`, `flexShrink`, `flexBasis`, `aspectRatio`, `lineClamp`, and `tabSize`. Logical axis category styles accept one or two values in start/end order and the `start`, `end`, and `longhand` modifiers. `fill` and `color` take a color (plus `none` / `transparent`); `caretColor` and `accentColor` take a color only.
122
126
 
123
127
  ### `transition`
124
128
 
@@ -214,6 +218,7 @@ The selector must be a string literal and valid CSS. Values must be static — s
214
218
 
215
219
  - Token, preset, recipe, unit and `@alias` names exist in the project config.
216
220
  - Tasty shorthand chosen over CSS longhands; `flexGrow`/`flexShrink`/`flexBasis` over `flex`; `hide: true` over `display: 'none'`.
221
+ - Logical category styles keep native `block`/`inline` declarations and accept `start`/`end`, never physical direction modifiers.
217
222
  - Colors are `#tokens`, not hex/rgb/oklch/named; `$prop` not `var(--prop)`.
218
223
  - Spacing uses `x`/`r`/`bw`/`ow` units; math uses `(…)`, not `calc(…)`.
219
224
  - `true` only on the properties that accept it; no `!important`.
package/docs/debug.md CHANGED
@@ -54,6 +54,19 @@ interface DebugOptions {
54
54
 
55
55
  When `raw` is `false` (the default), results are logged to the console **and** returned. When `raw` is `true`, results are returned silently.
56
56
 
57
+ ### Environments Without a DOM
58
+
59
+ `tastyDebug` reads the document, so on a server — SSR, a Node REPL, a test
60
+ runner in the `node` environment — there is nothing for it to read. Every
61
+ method returns its empty result (`''`, an empty `InspectResult`, a summary of
62
+ zeroes, `metrics: null`) instead of throwing, and explains itself once with a
63
+ console warning. `{ raw: true }` suppresses that warning along with the rest of
64
+ the logging.
65
+
66
+ To see the styles a server render produced, read the `ServerStyleCollector`
67
+ instead — `collector.getCSS()` and `collector.getRenderedClassNames()`. See
68
+ [SSR](./ssr.md).
69
+
57
70
  ---
58
71
 
59
72
  ## API Reference
@@ -122,10 +122,10 @@ Tasty exports predefined style prop lists that group properties by role. Use the
122
122
  | Preset | Properties | Typical use |
123
123
  | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------- |
124
124
  | `FLOW_STYLES` | flow, gap, columnGap, rowGap, align, justify, placeItems, placeContent, alignItems, alignContent, justifyItems, justifyContent, gridColumns, gridRows, gridTemplate, gridAreas | Layout containers (`Space`, `Grid`) |
125
- | `POSITION_STYLES` | gridArea, gridColumn, gridRow, order, placeSelf, alignSelf, justifySelf, zIndex, margin, inset, position | Positioned elements (`Button`, `Badge`) |
126
- | `DIMENSION_STYLES` | width, height, flexBasis, flexGrow, flexShrink, flex | Sized elements |
125
+ | `POSITION_STYLES` | gridArea, gridColumn, gridRow, order, placeSelf, alignSelf, justifySelf, zIndex, physical/logical margin, inset, scroll margin/padding, position | Positioned elements (`Button`, `Badge`) |
126
+ | `DIMENSION_STYLES` | width, height, blockSize, inlineSize, flexBasis, flexGrow, flexShrink, flex | Sized elements |
127
127
  | `COLOR_STYLES` | color, fill, fade, image | Color-customizable elements |
128
- | `BLOCK_STYLES` | padding, paddingInline, paddingBlock, overflow, scrollbar, textAlign, border, radius, shadow, outline | Block-level containers |
128
+ | `BLOCK_STYLES` | padding, blockPadding, inlinePadding, overflow, scrollbar, textAlign, border, blockBorder, inlineBorder, radius, shadow, outline | Block-level containers |
129
129
  | `CONTAINER_STYLES` | All of the above combined (+ BASE_STYLES) | Fully flexible containers |
130
130
  | `OUTER_STYLES` | POSITION_STYLES + DIMENSION_STYLES + block outer (border, radius, shadow, outline) | Components whose outer shell is customizable |
131
131
  | `INNER_STYLES` | BASE_STYLES + COLOR_STYLES + block inner (padding, overflow, scrollbar) + FLOW_STYLES | Components whose inner layout is customizable |
@@ -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.
@@ -130,13 +216,13 @@ The nonce is automatically applied to all `<style>` and `<script>` tags injected
130
216
 
131
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 |
138
- | `tastyIntegration({ css: { mode: 'extract' } })` | One line | Cross-tree and cross-page | Yes | Auto-hydration |
139
- | `tastyIntegration({ islands: false, css: { mode: 'extract' } })` | One line | Cross-tree and cross-page | Yes | None |
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 |
140
226
 
141
227
  ### Zero setup (static pages)
142
228
 
@@ -413,12 +499,13 @@ const stream = await runWithCollector(collector, () =>
413
499
 
414
500
  ### Entry points
415
501
 
416
- | Import path | Description |
417
- | ----------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
418
- | `@tenphi/tasty/ssr` | Core SSR API: `ServerStyleCollector`, `createServerStyleCollector`, `runWithCollector`, `hydrateTastyClasses` |
419
- | `@tenphi/tasty/ssr/next` | Next.js App Router: `TastyRegistry` component |
420
- | `@tenphi/tasty/ssr/astro` | Astro: `tastyIntegration`, `tastyMiddleware` |
421
- | `@tenphi/tasty/ssr/astro-client` | Astro: client-side cache hydration (auto-injected by integration, or import manually) |
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) |
422
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()`. |
423
510
 
424
511
  ### `ServerStyleCollector`
@@ -439,7 +526,7 @@ Constructor: `new ServerStyleCollector(namePrefix?)`, or use the `createServerSt
439
526
  | `allocateCounterStyleName(providedName?)` | Allocate a counter-style name. Returns `providedName` if given, otherwise generates one using `${namePrefix}c${counter}` (e.g. `tc0`, `tc1`, ...). |
440
527
  | `collectGlobalStyles(key, css)` | Record global styles (from `useGlobalStyles`). Deduplicated by key. |
441
528
  | `collectRawCSS(key, css)` | Record raw CSS text (from `useRawCSS`). Deduplicated by key. |
442
- | `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. |
443
530
  | `getCSS()` | Get all collected CSS as a single string. For non-streaming SSR. |
444
531
  | `flushCSS()` | Get only CSS collected since the last flush. For streaming SSR. |
445
532
  | `getRenderedClassNames()` | Get the list of class names rendered so far. Serialized to `window.__TASTY__` for client hydration via `hydrateTastyClasses()`. |
@@ -448,10 +535,18 @@ Constructor: `new ServerStyleCollector(namePrefix?)`, or use the `createServerSt
448
535
 
449
536
  Next.js App Router component. Props:
450
537
 
451
- | Prop | Type | Default | Description |
452
- | --------------- | ----------- | -------- | ------------------------------------------------ |
453
- | `children` | `ReactNode` | required | Application tree |
454
- | `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`.
455
550
 
456
551
  ### `tastyIntegration(options?)`
457
552
 
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