@tenphi/tasty 0.0.0-snapshot.b6cc3cd → 0.0.0-snapshot.b7bfdb1

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 (67) hide show
  1. package/README.md +147 -129
  2. package/dist/{babel-D8dm92E_.d.ts → babel-Brsw7Ax_.d.ts} +2 -2
  3. package/dist/{collector-BFuqdF2F.d.ts → collector-0YO-P1vW.d.ts} +2 -2
  4. package/dist/{collector-Di3C8btw.js → collector-DJqx7XO0.js} +3 -3
  5. package/dist/{collector-Di3C8btw.js.map → collector-DJqx7XO0.js.map} +1 -1
  6. package/dist/{config-DH7I0Ggx.d.ts → config-CscQCTAM.d.ts} +133 -40
  7. package/dist/{config-BrDt11hO.js → config-DsqqkmUs.js} +496 -1009
  8. package/dist/config-DsqqkmUs.js.map +1 -0
  9. package/dist/core/index.d.ts +5 -5
  10. package/dist/core/index.js +6 -6
  11. package/dist/{core-YWn1zgh4.js → core-KVEKOhEi.js} +145 -105
  12. package/dist/core-KVEKOhEi.js.map +1 -0
  13. package/dist/{css-writer-CQYbT4g_.js → css-writer-Cdrh5gHj.js} +3 -3
  14. package/dist/{css-writer-CQYbT4g_.js.map → css-writer-Cdrh5gHj.js.map} +1 -1
  15. package/dist/{format-rules-DdmLdntR.js → format-rules-CHNmNGhw.js} +5 -20
  16. package/dist/format-rules-CHNmNGhw.js.map +1 -0
  17. package/dist/{hydrate-D2ivfS-B.js → hydrate-DJhwbWq4.js} +3 -3
  18. package/dist/{hydrate-D2ivfS-B.js.map → hydrate-DJhwbWq4.js.map} +1 -1
  19. package/dist/{index-DljBkZhV.d.ts → index-BR9as3qn.d.ts} +52 -22
  20. package/dist/{index-LC3O3Jj4.d.ts → index-BmogEzTo.d.ts} +75 -16
  21. package/dist/index.d.ts +5 -5
  22. package/dist/index.js +9 -8
  23. package/dist/index.js.map +1 -1
  24. package/dist/{keyframes-CoLLjBcd.js → keyframes-CQY-i8dO.js} +110 -21
  25. package/dist/keyframes-CQY-i8dO.js.map +1 -0
  26. package/dist/{merge-styles-Cx_6ySBv.d.ts → merge-styles-BcLl1u_d.d.ts} +2 -2
  27. package/dist/{merge-styles-bdh7-1uh.js → merge-styles-voA8J__3.js} +2 -2
  28. package/dist/{merge-styles-bdh7-1uh.js.map → merge-styles-voA8J__3.js.map} +1 -1
  29. package/dist/{resolve-recipes-9JYSgubn.js → resolve-recipes-BP2NqOtQ.js} +3 -3
  30. package/dist/{resolve-recipes-9JYSgubn.js.map → resolve-recipes-BP2NqOtQ.js.map} +1 -1
  31. package/dist/ssr/astro-client.js +1 -1
  32. package/dist/ssr/astro.js +3 -3
  33. package/dist/ssr/index.d.ts +1 -1
  34. package/dist/ssr/index.js +3 -3
  35. package/dist/ssr/next.d.ts +1 -1
  36. package/dist/ssr/next.js +4 -4
  37. package/dist/static/index.d.ts +2 -2
  38. package/dist/static/index.js +1 -1
  39. package/dist/zero/babel.d.ts +1 -1
  40. package/dist/zero/babel.js +4 -4
  41. package/dist/zero/index.d.ts +1 -1
  42. package/dist/zero/index.js +1 -1
  43. package/dist/zero/next.d.ts +1 -1
  44. package/docs/README.md +13 -8
  45. package/docs/adoption.md +56 -31
  46. package/docs/ai-agents.md +78 -77
  47. package/docs/comparison.md +69 -40
  48. package/docs/configuration.md +164 -101
  49. package/docs/debug.md +4 -2
  50. package/docs/design-system.md +41 -22
  51. package/docs/dsl.md +263 -198
  52. package/docs/getting-started.md +60 -39
  53. package/docs/injector.md +63 -26
  54. package/docs/methodology.md +43 -37
  55. package/docs/migration-v3.md +49 -49
  56. package/docs/pipeline.md +1 -4
  57. package/docs/plugins.md +37 -33
  58. package/docs/react-api.md +66 -45
  59. package/docs/runtime-benchmarks.md +178 -0
  60. package/docs/ssr.md +56 -57
  61. package/docs/styles.md +9 -2
  62. package/docs/tasty-static.md +137 -104
  63. package/package.json +12 -7
  64. package/dist/config-BrDt11hO.js.map +0 -1
  65. package/dist/core-YWn1zgh4.js.map +0 -1
  66. package/dist/format-rules-DdmLdntR.js.map +0 -1
  67. package/dist/keyframes-CoLLjBcd.js.map +0 -1
@@ -0,0 +1,178 @@
1
+ # Runtime Benchmarks
2
+
3
+ Tasty keeps its performance claims in reproducible benchmarks rather than
4
+ combining unlike measurements into one score. The repository measures three
5
+ different costs:
6
+
7
+ 1. Style parsing and generation in Node.
8
+ 2. The React overhead of an empty `tasty({})` wrapper.
9
+ 3. Cold browser generation and injection compared with equivalent CSS that is
10
+ already on the page.
11
+
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.
15
+
16
+ ## Reproducing the Results
17
+
18
+ ```bash
19
+ pnpm bench
20
+ pnpm bench:overhead
21
+ pnpm bench:injection
22
+ ```
23
+
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.
27
+
28
+ 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
30
+ 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.
33
+
34
+ ## Core Style Pipeline
35
+
36
+ The following numbers are single-call throughput measured on an Apple M1 Max
37
+ with Node 22:
38
+
39
+ | Operation | ops/sec | Latency (mean) |
40
+ | ----------------------------------------------------------- | -------------------: | -------------: |
41
+ | `renderStyles` — 5 flat properties (cold) | ~60,000 | ~17 us |
42
+ | `renderStyles` — state map with media/hover/modifier (cold) | ~18,500 | ~54 us |
43
+ | `renderStyles` — same styles (cached) | ~5,800,000 | ~0.17 us |
44
+ | `parseStateKey` — simple key like `:hover` (cold) | ~790,000 | ~1.3 us |
45
+ | `parseStateKey` — complex OR/AND/NOT key (cold) | ~140,000 | ~7 us |
46
+ | `parseStateKey` — any key (cached) | ~3,400,000–8,300,000 | ~0.1–0.3 us |
47
+ | `parseStyle` — value tokens like `2x 4x` (cold) | ~344,000 | ~2.9 us |
48
+ | `parseStyle` — color tokens (cold) | ~567,000 | ~1.8 us |
49
+ | `parseStyle` — any value (cached) | ~15,250,000 | ~0.07 us |
50
+
51
+ “Cold” cases use unique inputs to bypass the relevant caches. Cached cases
52
+ reuse one input and measure the LRU hot path. Expect roughly ±10% between runs.
53
+ These benchmarks do not include React, DOM work, stylesheet injection, style
54
+ resolution, layout, or paint.
55
+
56
+ The benchmark sources are colocated with the code they exercise:
57
+ [`pipeline.bench.ts`](../src/pipeline/pipeline.bench.ts),
58
+ [`parseStateKey.bench.ts`](../src/pipeline/parseStateKey.bench.ts), and the
59
+ parser benchmark files under [`src/parser`](../src/parser).
60
+
61
+ ## Empty Wrapper Overhead
62
+
63
+ Skipping the style pipeline does not make a `tasty()` component free. Even
64
+ `tasty({})` is a React component between its parent and the host element. React
65
+ tracks another fiber, and Tasty still processes and forwards the element's
66
+ props.
67
+
68
+ [`tasty-overhead.bench.tsx`](../src/tasty-overhead.bench.tsx) compares 10,000
69
+ raw `<div className>` siblings with 10,000 instances of one module-scoped
70
+ `tasty({})` component. Both receive the same props, and the benchmark fails if
71
+ they do not produce equivalent DOM.
72
+
73
+ The benchmark uses production React in headless Chromium. The factory is
74
+ created and its empty class-name cache is warmed before timing, so factory
75
+ creation, style generation, and injection are excluded. A detached container
76
+ excludes layout, paint, and stylesheet matching. Every commit is wrapped in
77
+ `flushSync`, keeping its synchronous reconciliation and commit inside the
78
+ sample. This does not estimate React's concurrent scheduling latency.
79
+
80
+ On an Apple M3 Pro with React 19.2.4 and Chromium 151, three consecutive runs
81
+ produced these ranges:
82
+
83
+ | Work on 10,000 siblings | Raw elements | `tasty({})` | Extra per wrapped element |
84
+ | ----------------------------------- | -----------: | -----------: | ------------------------: |
85
+ | Mount + remove | 4.5–4.9 ms | 14.0–14.9 ms | 0.95–1.00 us |
86
+ | Rerender, same host props | 1.3–1.4 ms | 10.9–11.4 ms | 0.96–1.00 us |
87
+ | Rerender, change one host attribute | 2.8–3.4 ms | 15.0–15.7 ms | 1.21–1.27 us |
88
+
89
+ The useful result is the raw/Tasty time difference divided by 10,000, not the
90
+ ratio between the two times. The ratio becomes large because the raw baseline
91
+ is tiny. In this synthetic workload, an empty wrapper adds roughly 1 us per
92
+ participating element, or 1.2–1.3 us when React also changes a DOM attribute.
93
+
94
+ This is the floor Tasty consumes when it has no styling job. It is not a
95
+ page-level score. Real trees include application components, effects, layout,
96
+ paint, and usually far fewer simultaneous styled-element updates. The benchmark
97
+ also does not measure retained memory; that requires a matched-tree heap
98
+ snapshot experiment with controlled garbage collection.
99
+
100
+ ## Cold Generation and Injection
101
+
102
+ [`tasty-injection.bench.ts`](../src/tasty-injection.bench.ts) measures the extra
103
+ work when Tasty must generate and inject CSS that an otherwise equivalent page
104
+ already has. It does not compare different stylesheet insertion techniques.
105
+
106
+ The benchmark covers two useful workloads:
107
+
108
+ - **One new rule:** add one rule to an existing stylesheet, append its one
109
+ element, and immediately read its computed style. Each timed sample performs
110
+ 50 independent one-rule transactions and reports their total; dividing the
111
+ raw/Tasty difference by 50 produces a stable per-rule result despite
112
+ Chromium's 0.1 ms timer resolution.
113
+ - **1,000 new rules together:** generate and insert all 1,000 rules into one
114
+ stylesheet, append all 1,000 elements, then read every computed color without
115
+ another write in between. This gives the browser one style-resolution
116
+ boundary for the group.
117
+
118
+ For every transaction, the existing-CSS control has the equivalent stylesheet
119
+ parsed, adopted, and attached before timing. The runtime root has a Tasty
120
+ stylesheet pre-created with an unrelated sentinel rule, but not the measured
121
+ rules. Both paths perform the same class assignment, DOM commit, and
122
+ computed-style reads. Only the runtime path calls `computeStyles()` and inserts
123
+ the new rules.
124
+
125
+ Preparation and cleanup happen outside the sample timer. Every runtime style
126
+ value is unique within a cycle, the relevant caches are cleared between cycles,
127
+ and a guard verifies that both paths resolve to the same color. React and the
128
+ `tasty()` wrapper are absent so their independently measured costs do not enter
129
+ the result. Pre-creating both stylesheets also excludes one-time sheet creation
130
+ and adoption from the subtraction.
131
+
132
+ On an Apple M3 Pro with Chromium 151, three consecutive runs produced these
133
+ ranges:
134
+
135
+ | Workload | CSS already present | Tasty runtime | Incremental Tasty cost |
136
+ | ---------------------------------------------------- | ------------------: | -------------: | ---------------------: |
137
+ | One new rule + immediate resolution, per transaction | 2.8–3.3 us | 110.3–113.8 us | 107.3–111.0 us |
138
+ | 1,000 new rules + one resolution | 1.86–2.06 ms | 9.01–9.98 ms | 7.13–7.92 ms |
139
+ | 1,000-rule workload, incremental cost per rule | — | — | 7.1–7.9 us |
140
+
141
+ Directly compared, injecting 1,000 rules before one resolution boundary cost
142
+ about 66–71 times as much in total as injecting one rule and resolving it—not
143
+ 1,000 times as much. Its average incremental cost per rule was about 14–16
144
+ times lower. This is the same Tasty generation and injection path in both cases;
145
+ the group amortizes fixed transaction work and lets the browser resolve all the
146
+ stylesheet writes together.
147
+
148
+ The subtraction is the meaningful result. It includes Tasty's cold style
149
+ generation, cache and injector bookkeeping, rule insertion, and any additional
150
+ style invalidation exposed by that workload's resolution boundary. It does not
151
+ pretend to isolate `insertRule()` from the system that calls it.
152
+
153
+ This is a deliberately cold workload. Reused styles resolve from cache and do
154
+ not inject another rule. Different rule complexity, DOM shape, stylesheet size,
155
+ browser, and hardware will change the number. The single-rule and 1,000-rule
156
+ results are not interchangeable: the first crosses the injection-to-resolution
157
+ boundary once per rule, while the second lets the browser resolve 1,000 writes
158
+ together. Because the same resolution pattern is present in each workload's
159
+ control, the difference answers the narrower delivery question: how much extra
160
+ work did Tasty perform when the same CSS was not already there?
161
+
162
+ ## Reading the Results Together
163
+
164
+ Do not add all three benchmark numbers to estimate an application blindly.
165
+ They describe different paths:
166
+
167
+ - A stable `tasty()` factory can skip the style pipeline on later renders, but
168
+ its React wrapper still participates in reconciliation.
169
+ - A cached style avoids cold parsing and generation and does not insert a new
170
+ rule.
171
+ - A genuinely new style pays generation and injection once, then becomes
172
+ reusable.
173
+ - Browser style resolution, layout, and paint depend on the actual document and
174
+ need application-level profiling.
175
+
176
+ The practical optimization target is therefore repeated work: keep style input
177
+ stable when possible, reuse generated chunks, and generate CSS at build or
178
+ server time when runtime flexibility is unnecessary.
package/docs/ssr.md CHANGED
@@ -1,16 +1,22 @@
1
1
  # Server-Side Rendering (SSR)
2
2
 
3
- Tasty supports server-side rendering with zero-cost client hydration. This does **not** introduce a separate styling engine: SSR uses the same runtime `tasty()` pipeline you already use on the client, then adds server-side CSS collection and client-side cache hydration. Your existing `tasty()` components work unchanged, and SSR remains opt-in with no per-component modifications. For the broader docs map, see the [Docs Hub](README.md).
3
+ Tasty supports server-side rendering with zero-cost client hydration. This does **not** introduce a separate styling engine: `tasty()` uses the same rendering pipeline on the server and in the browser, while the SSR integrations add server-side CSS collection and client-side cache hydration. Your existing `tasty()` components work unchanged, and SSR remains opt-in with no per-component modifications. For the broader docs map, see the [Docs Hub](README.md).
4
+
5
+ ## Zero-runtime terminology
6
+
7
+ Zero-runtime delivery is an outcome, not an alias for `tastyStatic()`. When `tasty()` components render only on the server, their CSS is delivered with the HTML and no Tasty styling runtime is shipped to the browser. Astro's `tastyIntegration({ islands: false })` is the explicit integration for this setup. Server-only Next.js React Server Components follow the same architecture, although you should verify the generated output for your deployment.
8
+
9
+ `tastyStatic()` reaches the same client-side outcome by extracting CSS during the build instead of during React rendering. Use it when extraction must happen before rendering or when the consumer is not React; see [Build-Time Extraction](tasty-static.md).
4
10
 
5
11
  ---
6
12
 
7
13
  ## Requirements
8
14
 
9
- | Dependency | Version | Required for |
10
- |---|---|---|
11
- | `react` | >= 18 | All SSR entry points (matches the current peer dependency of `@tenphi/tasty`) |
12
- | `next` | >= 13 | Next.js integration (`@tenphi/tasty/ssr/next`) — App Router with `useServerInsertedHTML` |
13
- | Node.js | >= 20 | Generic / streaming SSR (`@tenphi/tasty/ssr`) — uses `node:async_hooks` for `AsyncLocalStorage` |
15
+ | Dependency | Version | Required for |
16
+ | ---------- | ------- | ----------------------------------------------------------------------------------------------- |
17
+ | `react` | >= 18 | All SSR entry points (matches the current peer dependency of `@tenphi/tasty`) |
18
+ | `next` | >= 13 | Next.js integration (`@tenphi/tasty/ssr/next`) — App Router with `useServerInsertedHTML` |
19
+ | Node.js | >= 20 | Generic / streaming SSR (`@tenphi/tasty/ssr`) — uses `node:async_hooks` for `AsyncLocalStorage` |
14
20
 
15
21
  The Astro integration (`@tenphi/tasty/ssr/astro`) has no additional dependencies beyond `react`.
16
22
 
@@ -124,11 +130,11 @@ The nonce is automatically applied to all `<style>` and `<script>` tags injected
124
130
 
125
131
  Tasty offers three levels of Astro integration. Choose the one that matches your needs:
126
132
 
127
- | Setup | Config needed | Deduplication | Hooks work | Client JS |
128
- |---|---|---|---|---|
129
- | Zero setup | None | Per render tree | Yes (within each tree) | None |
130
- | `tastyIntegration({ islands: false })` | One line | Cross-tree | Yes | None |
131
- | `tastyIntegration()` | One line | Cross-tree | Yes | Auto-hydration |
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 |
132
138
 
133
139
  ### Zero setup (static pages)
134
140
 
@@ -234,10 +240,7 @@ If you need to compose Tasty's middleware with other middleware (e.g., via `sequ
234
240
  import { sequence } from 'astro:middleware';
235
241
  import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
236
242
 
237
- export const onRequest = sequence(
238
- tastyMiddleware(),
239
- myOtherMiddleware,
240
- );
243
+ export const onRequest = sequence(tastyMiddleware(), myOtherMiddleware);
241
244
  ```
242
245
 
243
246
  For island hydration with manual middleware, import the client module in a shared entry point or in each island:
@@ -285,9 +288,7 @@ import { hydrateRoot } from 'react-dom/client';
285
288
 
286
289
  const collector = createServerStyleCollector();
287
290
 
288
- const html = await runWithCollector(collector, () =>
289
- renderToString(<App />)
290
- );
291
+ const html = await runWithCollector(collector, () => renderToString(<App />));
291
292
 
292
293
  const css = collector.getCSS();
293
294
  const classNames = collector.getRenderedClassNames();
@@ -338,7 +339,7 @@ const stream = await runWithCollector(collector, () =>
338
339
  `<script>(window.__TASTY__=window.__TASTY__||[]).push(${JSON.stringify(classNames)})</script>`,
339
340
  );
340
341
  },
341
- })
342
+ }),
342
343
  );
343
344
  ```
344
345
 
@@ -348,12 +349,12 @@ const stream = await runWithCollector(collector, () =>
348
349
 
349
350
  ### Entry points
350
351
 
351
- | Import path | Description |
352
- |---|---|
353
- | `@tenphi/tasty/ssr` | Core SSR API: `ServerStyleCollector`, `createServerStyleCollector`, `runWithCollector`, `hydrateTastyClasses` |
354
- | `@tenphi/tasty/ssr/next` | Next.js App Router: `TastyRegistry` component |
355
- | `@tenphi/tasty/ssr/astro` | Astro: `tastyIntegration`, `tastyMiddleware` |
356
- | `@tenphi/tasty/ssr/astro-client` | Astro: client-side cache hydration (auto-injected by integration, or import manually) |
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) |
357
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()`. |
358
359
 
359
360
  ### `ServerStyleCollector`
@@ -362,47 +363,47 @@ Server-safe style collector. One instance per request.
362
363
 
363
364
  Constructor: `new ServerStyleCollector(namePrefix?)`, or use the `createServerStyleCollector(namePrefix?)` factory. The optional `namePrefix` overrides the value from `configure({ namePrefix })`; in normal usage you pass nothing and let the global config drive it. See [Configuration: Name prefix](configuration.md#name-prefix).
364
365
 
365
- | Method | Description |
366
- |---|---|
367
- | `allocateClassName(cacheKey)` | Allocate a deterministic, content-hashed class name for a cache key (e.g. `t1a2b3` with the default prefix). The same `cacheKey` always produces the same class name on server and client when both share the same `namePrefix`. Returns `{ className, isNewAllocation }`. |
368
- | `collectChunk(cacheKey, className, rules)` | Record CSS rules for a chunk. Deduplicated by `cacheKey`. |
369
- | `collectKeyframes(name, css)` | Record a `@keyframes` rule. Deduplicated by name. |
370
- | `allocateKeyframeName(providedName?)` | Allocate a keyframe name. Returns `providedName` if given, otherwise generates one using `${namePrefix}k${counter}` (e.g. `tk0`, `tk1`, ...). |
371
- | `collectProperty(name, css)` | Record a `@property` rule. Deduplicated by name. |
372
- | `collectFontFace(key, css)` | Record a `@font-face` rule. Deduplicated by content hash. |
373
- | `collectCounterStyle(name, css)` | Record a `@counter-style` rule. Deduplicated by name. |
374
- | `allocateCounterStyleName(providedName?)` | Allocate a counter-style name. Returns `providedName` if given, otherwise generates one using `${namePrefix}c${counter}` (e.g. `tc0`, `tc1`, ...). |
375
- | `collectGlobalStyles(key, css)` | Record global styles (from `useGlobalStyles`). Deduplicated by key. |
376
- | `collectRawCSS(key, css)` | Record raw CSS text (from `useRawCSS`). Deduplicated by key. |
377
- | `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. |
378
- | `getCSS()` | Get all collected CSS as a single string. For non-streaming SSR. |
379
- | `flushCSS()` | Get only CSS collected since the last flush. For streaming SSR. |
380
- | `getRenderedClassNames()` | Get the list of class names rendered so far. Serialized to `window.__TASTY__` for client hydration via `hydrateTastyClasses()`. |
366
+ | Method | Description |
367
+ | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
368
+ | `allocateClassName(cacheKey)` | Allocate a deterministic, content-hashed class name for a cache key (e.g. `t1a2b3` with the default prefix). The same `cacheKey` always produces the same class name on server and client when both share the same `namePrefix`. Returns `{ className, isNewAllocation }`. |
369
+ | `collectChunk(cacheKey, className, rules)` | Record CSS rules for a chunk. Deduplicated by `cacheKey`. |
370
+ | `collectKeyframes(name, css)` | Record a `@keyframes` rule. Deduplicated by name. |
371
+ | `allocateKeyframeName(providedName?)` | Allocate a keyframe name. Returns `providedName` if given, otherwise generates one using `${namePrefix}k${counter}` (e.g. `tk0`, `tk1`, ...). |
372
+ | `collectProperty(name, css)` | Record a `@property` rule. Deduplicated by name. |
373
+ | `collectFontFace(key, css)` | Record a `@font-face` rule. Deduplicated by content hash. |
374
+ | `collectCounterStyle(name, css)` | Record a `@counter-style` rule. Deduplicated by name. |
375
+ | `allocateCounterStyleName(providedName?)` | Allocate a counter-style name. Returns `providedName` if given, otherwise generates one using `${namePrefix}c${counter}` (e.g. `tc0`, `tc1`, ...). |
376
+ | `collectGlobalStyles(key, css)` | Record global styles (from `useGlobalStyles`). Deduplicated by key. |
377
+ | `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. |
379
+ | `getCSS()` | Get all collected CSS as a single string. For non-streaming SSR. |
380
+ | `flushCSS()` | Get only CSS collected since the last flush. For streaming SSR. |
381
+ | `getRenderedClassNames()` | Get the list of class names rendered so far. Serialized to `window.__TASTY__` for client hydration via `hydrateTastyClasses()`. |
381
382
 
382
383
  ### `TastyRegistry`
383
384
 
384
385
  Next.js App Router component. Props:
385
386
 
386
- | Prop | Type | Default | Description |
387
- |---|---|---|---|
388
- | `children` | `ReactNode` | required | Application tree |
389
- | `transferCache` | `boolean` | `true` | Embed cache state script for zero-cost hydration |
387
+ | Prop | Type | Default | Description |
388
+ | --------------- | ----------- | -------- | ------------------------------------------------ |
389
+ | `children` | `ReactNode` | required | Application tree |
390
+ | `transferCache` | `boolean` | `true` | Embed cache state script for zero-cost hydration |
390
391
 
391
392
  ### `tastyIntegration(options?)`
392
393
 
393
394
  Astro integration factory. Registers middleware and optionally injects client hydration.
394
395
 
395
- | Option | Type | Default | Description |
396
- |---|---|---|---|
397
- | `islands` | `boolean` | `true` | When `true`, injects client hydration script and enables `transferCache`. When `false`, no client JS is shipped. |
396
+ | Option | Type | Default | Description |
397
+ | --------- | --------- | ------- | ---------------------------------------------------------------------------------------------------------------- |
398
+ | `islands` | `boolean` | `true` | When `true`, injects client hydration script and enables `transferCache`. When `false`, no client JS is shipped. |
398
399
 
399
400
  ### `tastyMiddleware(options?)`
400
401
 
401
402
  Astro middleware factory. Use for manual middleware composition.
402
403
 
403
- | Option | Type | Default | Description |
404
- |---|---|---|---|
405
- | `transferCache` | `boolean` | `true` | Embed cache state script for island hydration |
404
+ | Option | Type | Default | Description |
405
+ | --------------- | --------- | ------- | --------------------------------------------- |
406
+ | `transferCache` | `boolean` | `true` | Embed cache state script for island hydration |
406
407
 
407
408
  ### `hydrateTastyClasses(classes?)`
408
409
 
@@ -424,7 +425,7 @@ The `TastyRegistry` or `tastyIntegration` is missing. Ensure your layout wraps t
424
425
 
425
426
  Class names are deterministic for the same render order. If you see mismatches, ensure `hydrateTastyClasses()` runs before React hydration. For Next.js, this is automatic. For Astro with `tastyIntegration()`, this is also automatic. For manual Astro middleware setups, import `@tenphi/tasty/ssr/astro-client` in your island components. For custom setups, call `hydrateTastyClasses()` before `hydrateRoot()`.
426
427
 
427
- Class names are also derived from the *resolved* styles, so the server and the client must configure Tasty identically. Anything that changes what a component's styles resolve to will produce a mismatch if it is registered on only one side — `namePrefix`, `recipes`, `handlers`, and the `propHandlers` / `baseStyleProps` extension points described in [Plugins](plugins.md). Call the same `configure()` on both; global CSS is deduplicated automatically, so no `typeof window` guard is needed.
428
+ Class names are also derived from the _resolved_ styles, so the server and the client must configure Tasty identically. Anything that changes what a component's styles resolve to will produce a mismatch if it is registered on only one side — `namePrefix`, `recipes`, `handlers`, and the `propHandlers` / `baseStyleProps` extension points described in [Plugins](plugins.md). Call the same `configure()` on both; global CSS is deduplicated automatically, so no `typeof window` guard is needed.
428
429
 
429
430
  ### Styles duplicated after hydration
430
431
 
@@ -440,11 +441,9 @@ hydrateRoot(root, <App />);
440
441
 
441
442
  // Optional: remove SSR style tags and class-list scripts after hydration
442
443
  document.querySelectorAll('style[data-tasty-ssr]').forEach((el) => el.remove());
443
- document
444
- .querySelectorAll('script')
445
- .forEach((el) => {
446
- if (el.textContent?.includes('__TASTY__')) el.remove();
447
- });
444
+ document.querySelectorAll('script').forEach((el) => {
445
+ if (el.textContent?.includes('__TASTY__')) el.remove();
446
+ });
448
447
  ```
449
448
 
450
449
  ### `AsyncLocalStorage` not available
package/docs/styles.md CHANGED
@@ -290,7 +290,14 @@ Text color with design token support.
290
290
  | `"light-dark(#dark, #light)"` | CSS color function — see [CSS Color Functions](dsl.md#css-color-functions) |
291
291
  | `true` | `currentColor` |
292
292
 
293
- When set to a named color token, also sets `$current-color` and `$current-color-{colorSpace}` custom properties for downstream use (suffix depends on the configured `colorSpace`, default `oklch`). An opacity suffix does not move the companion: `color="#purple.5"` still reports `#purple`'s channels, since components carry no alpha.
293
+ Also sets `$current-color` to the same color, for anything that needs the
294
+ inherited color as a color rather than as the `currentcolor` keyword. Every color
295
+ publishes it, not just a named token, so a reader below always takes the nearest
296
+ `color` rather than the nearest *token* color. A value that already reads the
297
+ inherited color — `#current` itself, a `#current` fade, a bare `currentColor` —
298
+ is not republished: resolving it a second time one level down would fade it
299
+ twice, and the variable into itself is a self-reference. `#current` does not go
300
+ through it; it is the keyword.
294
301
 
295
302
  ### `svgFill`
296
303
 
@@ -298,7 +305,7 @@ SVG fill color. Same color token syntax as `fill` and `color`. Outputs the nativ
298
305
 
299
306
  ```jsx
300
307
  svgFill="#purple.10"
301
- svgFill="currentColor"
308
+ svgFill="#current"
302
309
  ```
303
310
 
304
311
  ---