@tenphi/tasty 0.0.0-snapshot.ef967bb → 0.0.0-snapshot.efb24cc

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 (114) hide show
  1. package/README.md +26 -20
  2. package/dist/compute-styles.js +21 -55
  3. package/dist/compute-styles.js.map +1 -1
  4. package/dist/config.d.ts +54 -19
  5. package/dist/config.js +97 -13
  6. package/dist/config.js.map +1 -1
  7. package/dist/core/index.d.ts +4 -4
  8. package/dist/core/index.js +3 -3
  9. package/dist/debug.js +4 -4
  10. package/dist/debug.js.map +1 -1
  11. package/dist/hooks/useCounterStyle.d.ts +3 -17
  12. package/dist/hooks/useCounterStyle.js +55 -36
  13. package/dist/hooks/useCounterStyle.js.map +1 -1
  14. package/dist/hooks/useFontFace.d.ts +3 -1
  15. package/dist/hooks/useFontFace.js +21 -25
  16. package/dist/hooks/useFontFace.js.map +1 -1
  17. package/dist/hooks/useGlobalStyles.d.ts +18 -2
  18. package/dist/hooks/useGlobalStyles.js +52 -42
  19. package/dist/hooks/useGlobalStyles.js.map +1 -1
  20. package/dist/hooks/useKeyframes.d.ts +4 -2
  21. package/dist/hooks/useKeyframes.js +42 -51
  22. package/dist/hooks/useKeyframes.js.map +1 -1
  23. package/dist/hooks/useProperty.d.ts +4 -2
  24. package/dist/hooks/useProperty.js +29 -42
  25. package/dist/hooks/useProperty.js.map +1 -1
  26. package/dist/hooks/useRawCSS.d.ts +13 -44
  27. package/dist/hooks/useRawCSS.js +90 -22
  28. package/dist/hooks/useRawCSS.js.map +1 -1
  29. package/dist/hooks/useStyles.js.map +1 -1
  30. package/dist/index.d.ts +4 -4
  31. package/dist/index.js +3 -3
  32. package/dist/injector/index.d.ts +18 -2
  33. package/dist/injector/index.js +21 -2
  34. package/dist/injector/index.js.map +1 -1
  35. package/dist/injector/injector.d.ts +35 -3
  36. package/dist/injector/injector.js +199 -12
  37. package/dist/injector/injector.js.map +1 -1
  38. package/dist/injector/sheet-manager.d.ts +9 -13
  39. package/dist/injector/sheet-manager.js +33 -67
  40. package/dist/injector/sheet-manager.js.map +1 -1
  41. package/dist/injector/types.d.ts +52 -21
  42. package/dist/pipeline/exclusive.js +57 -2
  43. package/dist/pipeline/exclusive.js.map +1 -1
  44. package/dist/pipeline/index.js +2 -2
  45. package/dist/pipeline/index.js.map +1 -1
  46. package/dist/pipeline/materialize.js +56 -2
  47. package/dist/pipeline/materialize.js.map +1 -1
  48. package/dist/pipeline/parseStateKey.js +4 -4
  49. package/dist/pipeline/parseStateKey.js.map +1 -1
  50. package/dist/pipeline/simplify.js +180 -5
  51. package/dist/pipeline/simplify.js.map +1 -1
  52. package/dist/plugins/types.d.ts +12 -1
  53. package/dist/rsc-cache.js +79 -0
  54. package/dist/rsc-cache.js.map +1 -0
  55. package/dist/ssr/astro-client.d.ts +1 -0
  56. package/dist/ssr/astro-client.js +19 -0
  57. package/dist/ssr/astro-client.js.map +1 -0
  58. package/dist/ssr/astro-middleware.d.ts +15 -0
  59. package/dist/ssr/astro-middleware.js +19 -0
  60. package/dist/ssr/astro-middleware.js.map +1 -0
  61. package/dist/ssr/astro.d.ts +89 -10
  62. package/dist/ssr/astro.js +112 -27
  63. package/dist/ssr/astro.js.map +1 -1
  64. package/dist/ssr/async-storage.js +14 -4
  65. package/dist/ssr/async-storage.js.map +1 -1
  66. package/dist/ssr/collect-auto-properties.js +28 -9
  67. package/dist/ssr/collect-auto-properties.js.map +1 -1
  68. package/dist/ssr/collector.d.ts +9 -13
  69. package/dist/ssr/collector.js +32 -16
  70. package/dist/ssr/collector.js.map +1 -1
  71. package/dist/ssr/context.js +3 -0
  72. package/dist/ssr/context.js.map +1 -1
  73. package/dist/ssr/hydrate.d.ts +20 -13
  74. package/dist/ssr/hydrate.js +24 -28
  75. package/dist/ssr/hydrate.js.map +1 -1
  76. package/dist/ssr/index.d.ts +3 -4
  77. package/dist/ssr/index.js +4 -5
  78. package/dist/ssr/index.js.map +1 -1
  79. package/dist/ssr/next.d.ts +4 -3
  80. package/dist/ssr/next.js +5 -5
  81. package/dist/ssr/next.js.map +1 -1
  82. package/dist/ssr/ssr-collector-ref.js +19 -2
  83. package/dist/ssr/ssr-collector-ref.js.map +1 -1
  84. package/dist/tasty.d.ts +1 -1
  85. package/dist/tasty.js +14 -6
  86. package/dist/tasty.js.map +1 -1
  87. package/dist/utils/deps-equal.js +15 -0
  88. package/dist/utils/deps-equal.js.map +1 -0
  89. package/dist/utils/filter-base-props.d.ts +1 -1
  90. package/dist/utils/filter-base-props.js.map +1 -1
  91. package/dist/utils/hash.js +14 -0
  92. package/dist/utils/hash.js.map +1 -0
  93. package/dist/utils/typography.d.ts +21 -10
  94. package/dist/utils/typography.js +1 -1
  95. package/dist/utils/typography.js.map +1 -1
  96. package/dist/zero/babel.d.ts +7 -108
  97. package/dist/zero/babel.js +36 -12
  98. package/dist/zero/babel.js.map +1 -1
  99. package/docs/README.md +2 -2
  100. package/docs/adoption.md +5 -3
  101. package/docs/comparison.md +24 -25
  102. package/docs/configuration.md +69 -1
  103. package/docs/design-system.md +22 -10
  104. package/docs/dsl.md +23 -8
  105. package/docs/getting-started.md +10 -10
  106. package/docs/injector.md +41 -25
  107. package/docs/methodology.md +2 -2
  108. package/docs/{runtime.md → react-api.md} +17 -32
  109. package/docs/ssr.md +137 -79
  110. package/docs/tasty-static.md +14 -2
  111. package/package.json +12 -6
  112. package/dist/hooks/resolve-ssr-collector.js +0 -14
  113. package/dist/hooks/resolve-ssr-collector.js.map +0 -1
  114. package/dist/ssr/context.d.ts +0 -8
package/docs/ssr.md CHANGED
@@ -18,7 +18,7 @@ The Astro integration (`@tenphi/tasty/ssr/astro`) has no additional dependencies
18
18
 
19
19
  ## How It Works
20
20
 
21
- `tasty()` components are hook-free and use `computeStyles()` internally — a synchronous, framework-agnostic function. On the server, `computeStyles()` detects a `ServerStyleCollector` (via `AsyncLocalStorage` or an explicit option) and collects CSS into it instead of trying to access the DOM. On the client, CSS is injected synchronously into the DOM during render; the injector's content-based cache makes this idempotent. The collector accumulates all styles, serializes them as `<style>` tags and a cache state script in the HTML. On the client, `hydrateTastyCache()` pre-populates the injector cache so that `computeStyles()` skips the rendering pipeline entirely during hydration.
21
+ `tasty()` components are hook-free and use `computeStyles()` internally — a synchronous, framework-agnostic function. On the server, `computeStyles()` discovers a `ServerStyleCollector` via a registered getter (module-level for Next.js, `globalThis` for Astro/generic frameworks using `AsyncLocalStorage`) and collects CSS into it instead of trying to access the DOM. On the client, CSS is injected synchronously into the DOM during render; the injector's content-based cache makes this idempotent. The collector accumulates all styles, serializes them as `<style>` tags and a cache state script in the HTML. On the client, `hydrateTastyCache()` pre-populates the injector cache so that `computeStyles()` skips the rendering pipeline entirely during hydration.
22
22
 
23
23
  ```
24
24
  Server Client
@@ -82,15 +82,21 @@ That's it. All `tasty()` components inside the tree automatically get SSR suppor
82
82
 
83
83
  ### How it works
84
84
 
85
- - `TastyRegistry` is a `'use client'` component, but Next.js still server-renders it on initial page load.
86
- - During SSR, `computeStyles()` finds the collector (registered globally by `TastyRegistry`) and collects CSS rules into it.
87
- - `TastyRegistry` uses `useServerInsertedHTML` to flush collected CSS into the HTML stream as `<style data-tasty-ssr>` tags. This is fully streaming-compatible -- styles are injected alongside each Suspense boundary as it resolves.
88
- - A companion `<script>` tag transfers the `cacheKey → className` mapping to the client.
89
- - When the module loads on the client, `hydrateTastyCache()` runs automatically and pre-populates the injector cache. During hydration, `computeStyles()` hits the cache and skips the entire pipeline.
85
+ - `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.
86
+ - During SSR, `TastyRegistry` creates a `ServerStyleCollector` and registers it via a module-level getter (not `globalThis` — this avoids leaking between Next.js's separate RSC and SSR module graphs). It also wraps children in a React context provider so that hooks inside the SSR tree can discover the collector. All style functions — `tasty()` components, `computeStyles()`, `useStyles()`, `useGlobalStyles()`, `useRawCSS()`, `useKeyframes()`, `useProperty()`, `useFontFace()`, and `useCounterStyle()` — discover the collector through the module-level getter or context provider.
87
+ - `TastyRegistry` uses `useServerInsertedHTML` to flush collected CSS into the HTML stream as `<style data-tasty-ssr>` tags. This is fully streaming-compatible — styles are injected alongside each Suspense boundary as it resolves.
88
+ - A companion inline `<script>` tag merges the `cacheKey → className` mapping into `window.__TASTY_SSR_CACHE__` for each flush. This streaming-friendly approach accumulates cache entries incrementally as Suspense boundaries resolve.
89
+ - When the `@tenphi/tasty/ssr/next` module loads on the client, `hydrateTastyCache()` runs automatically from `window.__TASTY_SSR_CACHE__` and pre-populates the injector cache. During hydration, `computeStyles()` hits the cache and skips the entire pipeline.
90
90
 
91
- ### Using tasty() in Server Components
91
+ ### Using Tasty in Server Components
92
92
 
93
- `tasty()` components are hook-free and do not require `'use client'`. They can be used directly in React Server Components. Dynamic `styleProps` like `<Grid flow="column">` work normally in server components. During SSR, the `TastyRegistry` registers its collector globally so that `computeStyles()` can discover it without React context.
93
+ All Tasty style functions are hook-free and do not require `'use client'`. They can be used directly in React Server Components:
94
+
95
+ - `tasty()` components — dynamic `styleProps` like `<Grid flow="column">` work normally
96
+ - `useStyles()`, `useGlobalStyles()`, `useRawCSS()` — inject styles by class or selector
97
+ - `useKeyframes()`, `useProperty()`, `useFontFace()`, `useCounterStyle()` — inject ancillary CSS rules
98
+
99
+ During SSR, all functions discover the collector via the same global getter registered by `TastyRegistry` — no React context or client boundary needed. In RSC mode without a collector (e.g., Astro zero-setup), CSS is accumulated in a per-request cache and flushed into an inline `<style>` tag by the next `tasty()` component in the tree. Ensure at least one `tasty()` component is present in every RSC render tree — standalone style functions alone cannot emit their CSS without a `tasty()` component to trigger the flush.
94
100
 
95
101
  ### Options
96
102
 
@@ -116,18 +122,17 @@ The nonce is automatically applied to all `<style>` and `<script>` tags injected
116
122
 
117
123
  ## Astro
118
124
 
119
- ### 1. Add the middleware
120
-
121
- Create or update your Astro middleware:
125
+ Tasty offers three levels of Astro integration. Choose the one that matches your needs:
122
126
 
123
- ```ts
124
- // src/middleware.ts
125
- import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
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 |
126
132
 
127
- export const onRequest = tastyMiddleware();
128
- ```
133
+ ### Zero setup (static pages)
129
134
 
130
- ### 2. Use tasty() components as normal
135
+ `tasty()` components work in Astro with **no configuration**. Each component emits its own inline `<style>` tag during server rendering via the RSC inline path. Just import and use:
131
136
 
132
137
  ```tsx
133
138
  // src/components/Card.tsx
@@ -153,56 +158,123 @@ import Card from '../components/Card.tsx';
153
158
 
154
159
  <html>
155
160
  <body>
156
- <Card>Static card — styles collected by middleware</Card>
157
- <Card client:load>Island card — styles hydrated on client</Card>
161
+ <Card>Styled with zero setup</Card>
158
162
  </body>
159
163
  </html>
160
164
  ```
161
165
 
162
- ### How it works
166
+ **Trade-offs**: Styles are deduplicated within each React render tree, but Astro renders separate component trees independently, so shared CSS (tokens, `@property` rules) may appear more than once. All style functions (`useGlobalStyles`, `useRawCSS`, `useKeyframes`, `useProperty`, `useFontFace`, `useCounterStyle`) work in zero-setup mode — their CSS is accumulated in the RSC cache and flushed by the next `tasty()` component in the tree.
163
167
 
164
- Astro's `@astrojs/react` renderer calls `renderToString()` for each React component without wrapping the tree in a provider. The middleware uses `AsyncLocalStorage` to make the collector available to all `computeStyles()` calls within the request.
168
+ Best for quick prototyping, small static sites, or trying Tasty out in Astro.
165
169
 
166
- - **Static components** (no `client:*`): Styles are collected during `renderToString` and injected into `</head>`. No JavaScript is shipped for these components.
167
- - **Islands** (`client:load`, `client:visible`, etc.): Styles are collected during SSR the same way. On the client, importing `@tenphi/tasty/ssr/astro` auto-hydrates the cache from `<script data-tasty-cache>`. The island's `computeStyles()` calls hit the cache during hydration.
170
+ ### Astro Integration (recommended)
168
171
 
169
- ### Client-side hydration for islands
172
+ For production use, add `tastyIntegration()` to your Astro config. This registers middleware automatically and, by default, injects client-side hydration for islands.
170
173
 
171
- The `@tenphi/tasty/ssr/astro` module auto-hydrates when imported on the client. To ensure the cache is warm before any island renders, import it in a shared entry point or in each island component:
174
+ #### With islands (default)
172
175
 
173
- ```tsx
174
- // src/components/MyIsland.tsx
175
- import '@tenphi/tasty/ssr/astro'; // auto-hydrates cache on import
176
- import { tasty } from '@tenphi/tasty';
176
+ ```ts
177
+ // astro.config.mjs
178
+ import { defineConfig } from 'astro/config';
179
+ import react from '@astrojs/react';
180
+ import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
177
181
 
178
- const MyIsland = tasty({
179
- styles: { padding: '2x', fill: '#blue' },
182
+ export default defineConfig({
183
+ integrations: [react(), tastyIntegration()],
180
184
  });
185
+ ```
186
+
187
+ This gives you:
188
+
189
+ - A `ServerStyleCollector` per request via `AsyncLocalStorage`, deduplicating CSS across all React trees on the page
190
+ - A single consolidated `<style data-tasty-ssr>` injected into `</head>`
191
+ - A `<script data-tasty-cache>` tag with the `cacheKey -> className` map for client hydration
192
+ - Auto-injected client hydration script (via `injectScript('before-hydration')`) so islands skip the style pipeline during hydration -- no need to import anything manually in each island component
193
+
194
+ All style functions (`useGlobalStyles`, `useRawCSS`, `useKeyframes`, `useProperty`, `useFontFace`, `useCounterStyle`) work on the server.
195
+
196
+ ```astro
197
+ ---
198
+ // src/pages/index.astro
199
+ import Card from '../components/Card.tsx';
200
+ import Interactive from '../components/Interactive.tsx';
201
+ ---
181
202
 
182
- export default MyIsland;
203
+ <html>
204
+ <body>
205
+ <Card>Static -- styles in <style data-tasty-ssr></Card>
206
+ <Interactive client:load>Island -- cache hydrated automatically</Interactive>
207
+ </body>
208
+ </html>
183
209
  ```
184
210
 
185
- ### Options
211
+ #### Static only (no client JS)
212
+
213
+ If your site has no `client:*` islands, skip the hydration script and cache transfer:
214
+
215
+ ```ts
216
+ // astro.config.mjs
217
+ import { defineConfig } from 'astro/config';
218
+ import react from '@astrojs/react';
219
+ import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
220
+
221
+ export default defineConfig({
222
+ integrations: [react(), tastyIntegration({ islands: false })],
223
+ });
224
+ ```
225
+
226
+ This gives the same middleware deduplication and hook support, but ships zero client-side JavaScript. No `<script data-tasty-cache>` is emitted.
227
+
228
+ ### Manual middleware (advanced)
229
+
230
+ If you need to compose Tasty's middleware with other middleware (e.g., via `sequence()`), use `tastyMiddleware()` directly:
231
+
232
+ ```ts
233
+ // src/middleware.ts
234
+ import { sequence } from 'astro:middleware';
235
+ import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
236
+
237
+ export const onRequest = sequence(
238
+ tastyMiddleware(),
239
+ myOtherMiddleware,
240
+ );
241
+ ```
242
+
243
+ For island hydration with manual middleware, import the client module in a shared entry point or in each island:
244
+
245
+ ```tsx
246
+ import '@tenphi/tasty/ssr/astro-client';
247
+ ```
248
+
249
+ #### Options
186
250
 
187
251
  ```ts
188
- // Skip cache state transfer
252
+ // Skip cache state transfer (static-only, no islands)
189
253
  export const onRequest = tastyMiddleware({ transferCache: false });
190
254
  ```
191
255
 
256
+ ### How it works
257
+
258
+ Astro's `@astrojs/react` renderer calls `renderToString()` for each React component without wrapping the tree in a provider. The middleware creates a `ServerStyleCollector` and binds it via `AsyncLocalStorage`. All `computeStyles()` calls within the request discover this collector automatically.
259
+
260
+ - **Static components** (no `client:*`): Styles are collected during `renderToString` and injected into `</head>` as a single `<style>` tag. No JavaScript is shipped.
261
+ - **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 cache state from `<script data-tasty-cache>` and pre-populates the injector. The island's `computeStyles()` calls hit the cache during hydration.
262
+ - The middleware reads the full response body, then injects the collected CSS into `</head>` before sending the final HTML.
263
+
192
264
  ### CSP nonce
193
265
 
194
- Same as Next.js -- call `configure({ nonce: '...' })` before any rendering happens. The middleware reads the nonce and applies it to injected tags.
266
+ Call `configure({ nonce: '...' })` before any rendering happens. The middleware reads the nonce and applies it to injected `<style>` and `<script>` tags.
195
267
 
196
268
  ---
197
269
 
198
270
  ## Generic Framework Integration
199
271
 
200
- Any React-based framework can integrate using the core SSR API:
272
+ Any React-based framework can integrate using `runWithCollector`, which binds a `ServerStyleCollector` to the current async context via `AsyncLocalStorage`. All style function calls within the render automatically discover the collector.
201
273
 
202
274
  ```tsx
203
275
  import {
204
276
  ServerStyleCollector,
205
- TastySSRContext,
277
+ runWithCollector,
206
278
  hydrateTastyCache,
207
279
  } from '@tenphi/tasty/ssr';
208
280
  import { renderToString } from 'react-dom/server';
@@ -212,10 +284,8 @@ import { hydrateRoot } from 'react-dom/client';
212
284
 
213
285
  const collector = new ServerStyleCollector();
214
286
 
215
- const html = renderToString(
216
- <TastySSRContext.Provider value={collector}>
217
- <App />
218
- </TastySSRContext.Provider>
287
+ const html = await runWithCollector(collector, () =>
288
+ renderToString(<App />)
219
289
  );
220
290
 
221
291
  const css = collector.getCSS();
@@ -251,11 +321,8 @@ For streaming with `renderToPipeableStream`, use `flushCSS()` instead of `getCSS
251
321
  ```tsx
252
322
  const collector = new ServerStyleCollector();
253
323
 
254
- const stream = renderToPipeableStream(
255
- <TastySSRContext.Provider value={collector}>
256
- <App />
257
- </TastySSRContext.Provider>,
258
- {
324
+ const stream = await runWithCollector(collector, () =>
325
+ renderToPipeableStream(<App />, {
259
326
  onShellReady() {
260
327
  // Flush styles collected so far
261
328
  const css = collector.flushCSS();
@@ -270,29 +337,8 @@ const stream = renderToPipeableStream(
270
337
  const state = collector.getCacheState();
271
338
  res.write(`<script data-tasty-cache type="application/json">${JSON.stringify(state)}</script>`);
272
339
  },
273
- }
274
- );
275
- ```
276
-
277
- ### AsyncLocalStorage (no React context)
278
-
279
- If your framework doesn't support wrapping the React tree with a provider, use `runWithCollector`:
280
-
281
- ```tsx
282
- import {
283
- ServerStyleCollector,
284
- runWithCollector,
285
- hydrateTastyCache,
286
- } from '@tenphi/tasty/ssr';
287
-
288
- const collector = new ServerStyleCollector();
289
-
290
- const html = await runWithCollector(collector, () =>
291
- renderToString(<App />)
340
+ })
292
341
  );
293
-
294
- const css = collector.getCSS();
295
- // ... inject into HTML as above
296
342
  ```
297
343
 
298
344
  ---
@@ -303,9 +349,10 @@ const css = collector.getCSS();
303
349
 
304
350
  | Import path | Description |
305
351
  |---|---|
306
- | `@tenphi/tasty/ssr` | Core SSR API: `ServerStyleCollector`, `TastySSRContext`, `runWithCollector`, `hydrateTastyCache` |
352
+ | `@tenphi/tasty/ssr` | Core SSR API: `ServerStyleCollector`, `runWithCollector`, `hydrateTastyCache` |
307
353
  | `@tenphi/tasty/ssr/next` | Next.js App Router: `TastyRegistry` component |
308
- | `@tenphi/tasty/ssr/astro` | Astro: `tastyMiddleware`, auto-hydration on import |
354
+ | `@tenphi/tasty/ssr/astro` | Astro: `tastyIntegration`, `tastyMiddleware` |
355
+ | `@tenphi/tasty/ssr/astro-client` | Astro: client-side cache hydration (auto-injected by integration, or import manually) |
309
356
 
310
357
  ### `ServerStyleCollector`
311
358
 
@@ -316,17 +363,18 @@ Server-safe style collector. One instance per request.
316
363
  | `allocateClassName(cacheKey)` | Allocate a sequential class name (`t0`, `t1`, ...) for a cache key. Returns `{ className, isNewAllocation }`. |
317
364
  | `collectChunk(cacheKey, className, rules)` | Record CSS rules for a chunk. Deduplicated by `cacheKey`. |
318
365
  | `collectKeyframes(name, css)` | Record a `@keyframes` rule. Deduplicated by name. |
366
+ | `allocateKeyframeName(providedName?)` | Allocate a keyframe name. Returns `providedName` if given, otherwise generates one (`k0`, `k1`, ...). |
319
367
  | `collectProperty(name, css)` | Record a `@property` rule. Deduplicated by name. |
320
368
  | `collectFontFace(key, css)` | Record a `@font-face` rule. Deduplicated by content hash. |
321
369
  | `collectCounterStyle(name, css)` | Record a `@counter-style` rule. Deduplicated by name. |
370
+ | `allocateCounterStyleName(providedName?)` | Allocate a counter-style name. Returns `providedName` if given, otherwise generates one (`cs0`, `cs1`, ...). |
371
+ | `collectGlobalStyles(key, css)` | Record global styles (from `useGlobalStyles`). Deduplicated by key. |
372
+ | `collectRawCSS(key, css)` | Record raw CSS text (from `useRawCSS`). Deduplicated by key. |
373
+ | `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. |
322
374
  | `getCSS()` | Get all collected CSS as a single string. For non-streaming SSR. |
323
375
  | `flushCSS()` | Get only CSS collected since the last flush. For streaming SSR. |
324
376
  | `getCacheState()` | Serialize `{ entries: Record<cacheKey, className>, classCounter }` for client hydration. |
325
377
 
326
- ### `TastySSRContext`
327
-
328
- React context (`createContext<ServerStyleCollector | null>(null)`). Used by the `useStyles()` hook to find the collector during SSR. Not needed when using `computeStyles()` directly (which discovers the collector via `AsyncLocalStorage` or the global getter registered by `TastyRegistry`).
329
-
330
378
  ### `TastyRegistry`
331
379
 
332
380
  Next.js App Router component. Props:
@@ -336,9 +384,17 @@ Next.js App Router component. Props:
336
384
  | `children` | `ReactNode` | required | Application tree |
337
385
  | `transferCache` | `boolean` | `true` | Embed cache state script for zero-cost hydration |
338
386
 
387
+ ### `tastyIntegration(options?)`
388
+
389
+ Astro integration factory. Registers middleware and optionally injects client hydration.
390
+
391
+ | Option | Type | Default | Description |
392
+ |---|---|---|---|
393
+ | `islands` | `boolean` | `true` | When `true`, injects client hydration script and enables `transferCache`. When `false`, no client JS is shipped. |
394
+
339
395
  ### `tastyMiddleware(options?)`
340
396
 
341
- Astro middleware factory. Options:
397
+ Astro middleware factory. Use for manual middleware composition.
342
398
 
343
399
  | Option | Type | Default | Description |
344
400
  |---|---|---|---|
@@ -350,7 +406,7 @@ Pre-populate the client injector cache. When called without arguments, reads fro
350
406
 
351
407
  ### `runWithCollector(collector, fn)`
352
408
 
353
- Run a function with a `ServerStyleCollector` bound to the current async context via `AsyncLocalStorage`. All `computeStyles()` and `useStyles()` calls within `fn` (and async continuations) will find this collector.
409
+ Run a function with a `ServerStyleCollector` bound to the current async context via `AsyncLocalStorage`. All style function calls within `fn` (and async continuations) — including `computeStyles()`, `useStyles()`, `useGlobalStyles()`, `useRawCSS()`, `useKeyframes()`, `useProperty()`, `useFontFace()`, and `useCounterStyle()` — will find this collector.
354
410
 
355
411
  ---
356
412
 
@@ -358,15 +414,17 @@ Run a function with a `ServerStyleCollector` bound to the current async context
358
414
 
359
415
  ### Styles flash on page load (FOUC)
360
416
 
361
- The `TastyRegistry` or `tastyMiddleware` is missing. Ensure your layout wraps the app with `TastyRegistry` (Next.js) or the middleware is registered (Astro).
417
+ The `TastyRegistry` or `tastyIntegration` is missing. Ensure your layout wraps the app with `TastyRegistry` (Next.js) or that `tastyIntegration()` is in your Astro config (or `tastyMiddleware()` is registered manually).
362
418
 
363
419
  ### Hydration mismatch warnings
364
420
 
365
- Class names are deterministic for the same render order. If you see mismatches, ensure `hydrateTastyCache()` runs before React hydration. For Next.js, this is automatic. For Astro, import `@tenphi/tasty/ssr/astro` in your island components. For custom setups, call `hydrateTastyCache()` before `hydrateRoot()`.
421
+ Class names are deterministic for the same render order. If you see mismatches, ensure `hydrateTastyCache()` 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 `hydrateTastyCache()` before `hydrateRoot()`.
366
422
 
367
423
  ### Styles duplicated after hydration
368
424
 
369
- This is expected and harmless. 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, call `cleanupSSRStyles()` after hydration:
425
+ **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.
426
+
427
+ **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, call `cleanupSSRStyles()` after hydration:
370
428
 
371
429
  ```tsx
372
430
  import { hydrateTastyCache } from '@tenphi/tasty/ssr';
@@ -161,11 +161,23 @@ module.exports = {
161
161
  | `configFile` | `string` | — | Absolute path to a TS/JS module that default-exports a `TastyZeroConfig` object. JSON-serializable alternative to `config` — required for Turbopack. |
162
162
  | `config` | `TastyZeroConfig \| () => TastyZeroConfig` | `{}` | Inline config object or factory function. Takes precedence over `configFile`. |
163
163
  | `configDeps` | `string[]` | `[]` | Absolute file paths that affect config (for cache invalidation) |
164
- | `config.states` | `Record<string, string>` | `{}` | Predefined state aliases |
164
+ | `injectImport` | `boolean` | `true` | Replace `@tenphi/tasty/static` imports with an import of the generated CSS file. Set to `false` to manage CSS imports manually. |
165
+ | `config.states` | `Record<string, string>` | `{}` | Predefined state aliases (e.g. `{ '@mobile': '@media(w < 768px)' }`) |
165
166
  | `config.devMode` | `boolean` | `false` | Add source comments to CSS |
167
+ | `config.tokens` | `ConfigTokens` | — | Design tokens injected as CSS custom properties on `:root`. Values are parsed through the Tasty DSL. Supports state maps for responsive/themed tokens. |
168
+ | `config.replaceTokens` | `Record<string, string \| number>` | — | Parse-time token substitution. Keys use `$name` for custom properties and `#name` for color tokens. |
166
169
  | `config.recipes` | `Record<string, RecipeStyles>` | `{}` | Predefined style recipes |
170
+ | `config.keyframes` | `Record<string, KeyframesSteps>` | — | Global `@keyframes` definitions available to all `tastyStatic` calls |
167
171
  | `config.fontFace` | `Record<string, FontFaceInput>` | — | Global `@font-face` definitions |
168
172
  | `config.counterStyle` | `Record<string, CounterStyleDescriptors>` | — | Global `@counter-style` definitions |
173
+ | `config.units` | `Record<string, string \| UnitHandler>` | — | Custom units for the style parser (merged with built-ins). E.g. `{ em: 'em', vw: 'vw' }` |
174
+ | `config.funcs` | `Record<string, Function>` | — | Custom functions for the style parser (merged with existing) |
175
+ | `config.plugins` | `TastyPlugin[]` | — | Plugins that extend tasty with custom functions, units, states, and handlers |
176
+ | `config.handlers` | `Record<string, StyleHandlerDefinition>` | — | Custom style handlers that transform style properties into CSS declarations |
177
+ | `config.presets` | `Record<string, TypographyPreset>` | — | Typography presets — shorthand for `generateTypographyTokens()`. Generated tokens merge under explicit `tokens`. |
178
+ | `config.globalStyles` | `Record<string, Styles>` | — | Global Tasty styles keyed by CSS selector. Supports the full style syntax. |
179
+ | `config.autoPropertyTypes` | `boolean` | `true` | Automatically infer and register CSS `@property` declarations from values |
180
+ | `config.parserCacheSize` | `number` | `1000` | Parser LRU cache size. Larger values improve performance for builds with many unique style values |
169
181
 
170
182
  ---
171
183
 
@@ -516,5 +528,5 @@ const card = tastyStatic({
516
528
 
517
529
  - [Docs Hub](README.md) — Choose the right guide by task or rendering mode
518
530
  - [Style DSL](dsl.md) — State maps, tokens, units, extending semantics (shared by runtime and static)
519
- - [Runtime API](runtime.md) — Runtime styling: `tasty()` factory, component props, variants, sub-elements, hooks
531
+ - [React API](react-api.md) — Runtime styling: `tasty()` factory, component props, variants, sub-elements, style functions
520
532
  - [Configuration](configuration.md) — Global configuration: tokens, recipes, custom units, and style handlers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenphi/tasty",
3
- "version": "0.0.0-snapshot.ef967bb",
3
+ "version": "0.0.0-snapshot.efb24cc",
4
4
  "description": "A design-system-integrated styling system and DSL for concise, state-aware UI styling",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -57,6 +57,11 @@
57
57
  "import": "./dist/ssr/astro.js",
58
58
  "default": "./dist/ssr/astro.js"
59
59
  },
60
+ "./ssr/astro-client": {
61
+ "types": "./dist/ssr/astro-client.d.ts",
62
+ "import": "./dist/ssr/astro-client.js",
63
+ "default": "./dist/ssr/astro-client.js"
64
+ },
60
65
  "./tasty.config": "./tasty.config.ts"
61
66
  },
62
67
  "files": [
@@ -67,7 +72,8 @@
67
72
  "sideEffects": [
68
73
  "./dist/ssr/index.js",
69
74
  "./dist/ssr/next.js",
70
- "./dist/ssr/astro.js"
75
+ "./dist/ssr/astro.js",
76
+ "./dist/ssr/astro-client.js"
71
77
  ],
72
78
  "engines": {
73
79
  "node": ">=20"
@@ -175,13 +181,13 @@
175
181
  "name": "main (import *)",
176
182
  "path": "dist/index.js",
177
183
  "import": "*",
178
- "limit": "48 kB"
184
+ "limit": "50 kB"
179
185
  },
180
186
  {
181
187
  "name": "core (import *)",
182
188
  "path": "dist/core/index.js",
183
189
  "import": "*",
184
- "limit": "45 kB"
190
+ "limit": "47.5 kB"
185
191
  },
186
192
  {
187
193
  "name": "static",
@@ -198,7 +204,7 @@
198
204
  "path",
199
205
  "crypto"
200
206
  ],
201
- "limit": "28.5 kB"
207
+ "limit": "29.5 kB"
202
208
  },
203
209
  {
204
210
  "name": "babel-plugin",
@@ -209,7 +215,7 @@
209
215
  "path",
210
216
  "crypto"
211
217
  ],
212
- "limit": "41 kB"
218
+ "limit": "43.5 kB"
213
219
  }
214
220
  ]
215
221
  }
@@ -1,14 +0,0 @@
1
- import { getRegisteredSSRCollector } from "../ssr/ssr-collector-ref.js";
2
- //#region src/hooks/resolve-ssr-collector.ts
3
- /**
4
- * Resolve the SSR collector from React context or AsyncLocalStorage.
5
- * Returns null on the client (no collector available).
6
- */
7
- function resolveSSRCollector(reactContext) {
8
- if (reactContext) return reactContext;
9
- return getRegisteredSSRCollector();
10
- }
11
- //#endregion
12
- export { resolveSSRCollector };
13
-
14
- //# sourceMappingURL=resolve-ssr-collector.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolve-ssr-collector.js","names":[],"sources":["../../src/hooks/resolve-ssr-collector.ts"],"sourcesContent":["import type { ServerStyleCollector } from '../ssr/collector';\nimport { getRegisteredSSRCollector } from '../ssr/ssr-collector-ref';\n\n/**\n * Resolve the SSR collector from React context or AsyncLocalStorage.\n * Returns null on the client (no collector available).\n */\nexport function resolveSSRCollector(\n reactContext: ServerStyleCollector | null,\n): ServerStyleCollector | null {\n if (reactContext) return reactContext;\n return getRegisteredSSRCollector();\n}\n"],"mappings":";;;;;;AAOA,SAAgB,oBACd,cAC6B;AAC7B,KAAI,aAAc,QAAO;AACzB,QAAO,2BAA2B"}
@@ -1,8 +0,0 @@
1
- import { ServerStyleCollector } from "./collector.js";
2
- import * as _$react from "react";
3
-
4
- //#region src/ssr/context.d.ts
5
- declare const TastySSRContext: _$react.Context<ServerStyleCollector | null>;
6
- //#endregion
7
- export { TastySSRContext };
8
- //# sourceMappingURL=context.d.ts.map