@tenphi/tasty 0.0.0-snapshot.fa1f6d0 → 0.0.0-snapshot.fa7ba65

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 (135) hide show
  1. package/README.md +449 -393
  2. package/dist/babel-types-Dc5zghyE.d.ts +18 -0
  3. package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
  4. package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
  5. package/dist/chunks/build-config--0qoqt_P.js +60 -0
  6. package/dist/chunks/build-config--0qoqt_P.js.map +1 -0
  7. package/dist/{collector-Denl8-Fv.js → chunks/collector-zp5BrLF0.js} +25 -119
  8. package/dist/chunks/collector-zp5BrLF0.js.map +1 -0
  9. package/dist/chunks/config-engine-BaLq8HrX.js +272 -0
  10. package/dist/chunks/config-engine-BaLq8HrX.js.map +1 -0
  11. package/dist/chunks/config-file-DlZXJMj8.js +25 -0
  12. package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
  13. package/dist/chunks/css-definitions-CfXZ3tU9.js +910 -0
  14. package/dist/chunks/css-definitions-CfXZ3tU9.js.map +1 -0
  15. package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
  16. package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
  17. package/dist/chunks/debug--OC-WA-Q.js +502 -0
  18. package/dist/chunks/debug--OC-WA-Q.js.map +1 -0
  19. package/dist/chunks/dsl-CsFl9LGn.js +1458 -0
  20. package/dist/chunks/dsl-CsFl9LGn.js.map +1 -0
  21. package/dist/chunks/hydration-TRcz5vnk.js +41 -0
  22. package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
  23. package/dist/chunks/react-runtime-DnZ6M1Iv.js +691 -0
  24. package/dist/chunks/react-runtime-DnZ6M1Iv.js.map +1 -0
  25. package/dist/chunks/runtime-engine-J9X_h-Pw.js +2435 -0
  26. package/dist/chunks/runtime-engine-J9X_h-Pw.js.map +1 -0
  27. package/dist/chunks/runtime-state-o_v3Bj7b.js +152 -0
  28. package/dist/chunks/runtime-state-o_v3Bj7b.js.map +1 -0
  29. package/dist/{merge-styles-BKZ5wV9K.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
  30. package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
  31. package/dist/chunks/style-engine-D6lC3O3G.js +5626 -0
  32. package/dist/chunks/style-engine-D6lC3O3G.js.map +1 -0
  33. package/dist/{css-writer-B9cXRm0c.js → chunks/zero-engine-BnjoV04F.js} +65 -145
  34. package/dist/chunks/zero-engine-BnjoV04F.js.map +1 -0
  35. package/dist/{collector-D1ehBofM.d.ts → collector-D2OT6I2G.d.ts} +23 -4
  36. package/dist/{config-CTSH3nyM.d.ts → config-C4ftFxgI.d.ts} +273 -78
  37. package/dist/core/index.d.ts +5 -5
  38. package/dist/core/index.js +9 -6
  39. package/dist/hydrate-CRyjjAyl.d.ts +22 -0
  40. package/dist/{index-DRrDzqto.d.ts → index-DxQNRj50.d.ts} +369 -258
  41. package/dist/index.d.ts +5 -5
  42. package/dist/index.js +11 -867
  43. package/dist/{merge-styles-BqPaLs2C.d.ts → merge-styles-D39qBtox.d.ts} +2 -3
  44. package/dist/ssr/astro-client.d.ts +1 -1
  45. package/dist/ssr/astro-client.js +1 -14
  46. package/dist/ssr/astro-client.js.map +1 -1
  47. package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
  48. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  49. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  50. package/dist/ssr/astro-middleware-extract.d.ts +10 -0
  51. package/dist/ssr/astro-middleware-extract.js +9 -0
  52. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  53. package/dist/ssr/astro-middleware-static.d.ts +3 -2
  54. package/dist/ssr/astro-middleware-static.js +0 -11
  55. package/dist/ssr/astro-middleware-static.js.map +1 -1
  56. package/dist/ssr/astro-middleware.d.ts +3 -2
  57. package/dist/ssr/astro-middleware.js +0 -12
  58. package/dist/ssr/astro-middleware.js.map +1 -1
  59. package/dist/ssr/astro.d.ts +40 -6
  60. package/dist/ssr/astro.js +157 -93
  61. package/dist/ssr/astro.js.map +1 -1
  62. package/dist/ssr/client.d.ts +2 -0
  63. package/dist/ssr/client.js +2 -0
  64. package/dist/ssr/index.d.ts +5 -25
  65. package/dist/ssr/index.js +5 -5
  66. package/dist/ssr/index.js.map +1 -1
  67. package/dist/ssr/next-config.d.ts +64 -0
  68. package/dist/ssr/next-config.js +123 -0
  69. package/dist/ssr/next-config.js.map +1 -0
  70. package/dist/ssr/next.d.ts +9 -8
  71. package/dist/ssr/next.js +29 -43
  72. package/dist/ssr/next.js.map +1 -1
  73. package/dist/static/index.d.ts +8 -9
  74. package/dist/static/index.js +4 -22
  75. package/dist/static/index.js.map +1 -1
  76. package/dist/static/inject.d.ts +1 -2
  77. package/dist/{index-B4UyMNQG.d.ts → types-CYQIhUg1.d.ts} +751 -598
  78. package/dist/zero/babel.d.ts +73 -2
  79. package/dist/zero/babel.js +81 -144
  80. package/dist/zero/babel.js.map +1 -1
  81. package/dist/zero/index.d.ts +63 -8
  82. package/dist/zero/index.js +25 -2
  83. package/dist/zero/index.js.map +1 -0
  84. package/dist/zero/next.d.ts +4 -5
  85. package/dist/zero/next.js +3 -38
  86. package/dist/zero/next.js.map +1 -1
  87. package/docs/README.md +16 -8
  88. package/docs/adoption.md +69 -36
  89. package/docs/ai-agents.md +125 -86
  90. package/docs/comparison.md +77 -47
  91. package/docs/configuration.md +437 -108
  92. package/docs/debug.md +21 -8
  93. package/docs/design-system.md +164 -31
  94. package/docs/dsl.md +583 -211
  95. package/docs/getting-started.md +130 -50
  96. package/docs/injector.md +117 -68
  97. package/docs/llms.txt +31 -0
  98. package/docs/methodology.md +81 -50
  99. package/docs/migration-v3.md +52 -52
  100. package/docs/pipeline.md +56 -32
  101. package/docs/plugins.md +59 -75
  102. package/docs/react-api.md +141 -55
  103. package/docs/runtime-benchmarks.md +388 -0
  104. package/docs/ssr.md +285 -101
  105. package/docs/styles.md +180 -35
  106. package/docs/tasty-static.md +286 -135
  107. package/harness/dev.harnesspm/rules/usage.md +12 -0
  108. package/harness/dev.harnesspm/scripts/render.mjs +441 -0
  109. package/harness/dev.harnesspm/scripts/styles.mjs +412 -0
  110. package/harness/plugin.json +20 -0
  111. package/package.json +132 -50
  112. package/tasty.config.ts +1 -0
  113. package/dist/async-storage-DKK-wTD4.js +0 -44
  114. package/dist/async-storage-DKK-wTD4.js.map +0 -1
  115. package/dist/babel-CO3cZu5y.d.ts +0 -83
  116. package/dist/collector-Denl8-Fv.js.map +0 -1
  117. package/dist/config-C1QNRigT.js +0 -12220
  118. package/dist/config-C1QNRigT.js.map +0 -1
  119. package/dist/context-CA8YKeMn.js +0 -24
  120. package/dist/context-CA8YKeMn.js.map +0 -1
  121. package/dist/core-CKaEqU_5.js +0 -1550
  122. package/dist/core-CKaEqU_5.js.map +0 -1
  123. package/dist/css-writer-B9cXRm0c.js.map +0 -1
  124. package/dist/format-global-rules-DklyaXv-.js +0 -22
  125. package/dist/format-global-rules-DklyaXv-.js.map +0 -1
  126. package/dist/format-rules-DXOmfxq7.js +0 -143
  127. package/dist/format-rules-DXOmfxq7.js.map +0 -1
  128. package/dist/hydrate-DeD-FNtn.js +0 -37
  129. package/dist/hydrate-DeD-FNtn.js.map +0 -1
  130. package/dist/index.js.map +0 -1
  131. package/dist/keyframes-BLmUYaB5.js +0 -424
  132. package/dist/keyframes-BLmUYaB5.js.map +0 -1
  133. package/dist/merge-styles-BKZ5wV9K.js.map +0 -1
  134. package/dist/resolve-recipes-DrHuwEhg.js +0 -144
  135. package/dist/resolve-recipes-DrHuwEhg.js.map +0 -1
package/docs/injector.md CHANGED
@@ -9,11 +9,11 @@ A high-performance CSS-in-JS solution that powers the Tasty design system with e
9
9
  The Style Injector is the core engine behind Tasty's styling system, providing:
10
10
 
11
11
  - **Hash-based deduplication** - Identical CSS gets the same className
12
- - **Reference counting** - Automatic cleanup when components unmount (refCount = 0)
13
- - **CSS nesting flattening** - Handles `&`, `.Class`, `SubElement` patterns
12
+ - **DOM-driven lifetime** - Styles are collected once nothing renders them
13
+ - **Selector assembly** - Prepends the doubled `.tX.tX` class and root prefix to the pipeline's selector fragments (sub-element and `&` nesting is flattened earlier, by the pipeline)
14
14
  - **At-rule injection** - First-class `@keyframes`, `@property`, `@font-face`, `@counter-style`, and `@function` support
15
15
  - **Smart cleanup** - CSS rules batched cleanup, keyframes disposed immediately
16
- - **SSR support** - Deterministic class names and CSS extraction
16
+ - **SSR support** - Deterministic class names shared with `ServerStyleCollector`, and hydration of server-rendered classes
17
17
  - **Multiple roots** - Works with Document and ShadowRoot
18
18
  - **Non-stacking cleanups** - Prevents timeout accumulation for better performance
19
19
 
@@ -55,18 +55,26 @@ Injects CSS rules and returns a className with dispose function.
55
55
  ```typescript
56
56
  import { inject } from '@tenphi/tasty';
57
57
 
58
- // Component styling - generates tasty class names
58
+ // Rules flagged needsClassName get the generated class prepended (doubled)
59
59
  const result = inject([{
60
- selector: '.t-abc123',
60
+ selector: '',
61
61
  declarations: 'color: red; padding: 10px;',
62
+ needsClassName: true,
62
63
  }]);
63
64
 
64
- console.log(result.className); // 't-abc123'
65
+ console.log(result.className); // 'th8n0uh' — `t` + base36 hash of the rules
66
+ // Injected: .th8n0uh.th8n0uh { color: red; padding: 10px; }
65
67
 
66
- // Cleanup when component unmounts (refCount decremented)
68
+ // Release the pin; the class becomes collectible once nothing renders it
67
69
  result.dispose();
68
70
  ```
69
71
 
72
+ `inject()` **pins** the class it returns, and `gc()` never evicts a pinned class
73
+ — that is what `dispose()` releases. Pass `{ pin: false }` when the caller keeps
74
+ no handle and the DOM is the only record that the class is in use; `dispose()`
75
+ is then a no-op. The render path (`tasty()` / `computeStyles()`) injects this
76
+ way, because a hook-free render has no unmount signal to dispose on.
77
+
70
78
  ### `injectGlobal(rules, options?): { dispose: () => void }`
71
79
 
72
80
  Injects global styles that don't reserve tasty class names.
@@ -169,7 +177,7 @@ const result = testInjector.inject(rules);
169
177
  Injects CSS keyframes with automatic deduplication.
170
178
 
171
179
  ```typescript
172
- // Generated name (k0, k1, k2...)
180
+ // Generated name (tk0, tk1, … — namePrefix + 'k' + counter)
173
181
  const fadeIn = keyframes({
174
182
  from: { opacity: 0 },
175
183
  to: { opacity: 1 },
@@ -245,8 +253,30 @@ Dispose, ref-counted cleanup and GC therefore behave identically in every mode.
245
253
  - Most options have sensible defaults and auto-detection
246
254
  - `configure()` is optional - the injector works with defaults
247
255
  - **Configuration is locked after styles are generated** - calling `configure()` after first render will emit a warning and be ignored
248
- - `gc.touchInterval`: Number of touch events between GC cycles. Each style render counts as a touch. When the counter reaches this value, GC is scheduled via `requestIdleCallback`.
249
- - `gc.capacity`: Maximum number of unused styles (refCount = 0, not in DOM) to retain. When exceeded, the oldest are evicted first. Actively referenced styles don't count against this limit.
256
+ - `gc.touchInterval`: Number of renders between sweeps. When the counter reaches this value, a sweep is scheduled via `requestIdleCallback`; without idle callbacks nothing is collected automatically.
257
+ - `gc.grace`: How long a class is left alone after collection first notices nothing is carrying it, in milliseconds (default `10000`).
258
+ - Automatic sweeps are opt-in: they run only when `configure({ gc })` is set (`gc: {}` enables them with these defaults). Without it nothing is collected until you call `gc()` or `cleanup()`.
259
+
260
+ **What a sweep does.** Everything the injector holds falls into one of five bands, and only the last is ever deleted:
261
+
262
+ | Band | | Deleted |
263
+ |---|---|---|
264
+ | 1 | **Rendered** — some element carries the class right now | never |
265
+ | 2 | **Not ours** — queued for a batched write, pre-allocated, or server-rendered | never |
266
+ | 3 | **Hot** — nothing carries it, but that was noticed less than `grace` ago | never |
267
+ | 4 | **Cached** — cold, but within `capacity` when ordered by when it went cold | never |
268
+ | 5 | Everything else | on every sweep |
269
+
270
+ `gc({ force: true })` and `cleanup()` take bands 4 and 5 together, ignoring capacity. Band 3 is spared even then: an explicit cleanup is still no reason to take rules from a render that has not committed yet.
271
+
272
+ `tasty()` components cache the class names they computed, so a re-render with the same styles skips the pipeline. Whenever `gc()`, `cleanup()` or `destroy()` deletes rules, those caches are dropped too, so a component whose CSS was collected injects it again on its next render.
273
+
274
+ > **Why band 3 exists.** Rendering is not commit-aware: a render can resolve a class and commit it a little later, and in between nothing on the page carries it. From outside React that is indistinguishable from a class that is finished, so collection does not try to tell them apart — it leaves alone anything only just noticed to be cold. A render would have to stay pending for the whole window to lose its rules, and it gets them back on its next render.
275
+ >
276
+ > The clock starts when a sweep *notices*, not when the element actually left — nothing observes that moment, so starting it at the sighting is what gives every class the same full window however long ago it went.
277
+ >
278
+ > This is also why collection costs nothing to run: the timestamps are written by the sweep's own DOM scan, so rendering tracks nothing per class.
279
+ - `gc.capacity`: Maximum number of unused styles (not in the DOM, not pinned) to retain. When exceeded, the least recently used are evicted first. Rendered and pinned styles don't count against this limit.
250
280
 
251
281
  ---
252
282
 
@@ -264,7 +294,7 @@ Beyond ordinary rules, the injector has a dedicated entry point per at-rule. All
264
294
 
265
295
  Every one of these takes an optional `root` (a `Document` or `ShadowRoot`).
266
296
 
267
- `func()` also accepts `weak: true`, which registers the rule **without** overriding an existing one of the same name. `configure()` uses it for global `@function` definitions so a component-local definition always wins over the global default, regardless of which is injected first.
297
+ `counterStyle()` and `func()` also accept `weak: true`, which registers the rule **without** overriding an existing one of the same name. `configure()` uses it for global `@counter-style` and `@function` definitions so a component-local definition always wins over the global default, regardless of which is injected first.
268
298
 
269
299
  ```ts
270
300
  import { counterStyle, fontFace, func, property } from '@tenphi/tasty';
@@ -281,60 +311,74 @@ func('$$negative', { args: ['$value'], result: '(-1 * $value)' });
281
311
 
282
312
  ### Style Result Format
283
313
 
284
- The injector works with `StyleResult` objects from the tasty parser:
314
+ The injector works with `StyleResult` objects from the pipeline (`renderStyles`):
285
315
 
286
316
  ```typescript
287
317
  interface StyleResult {
288
- selector: string; // CSS selector
289
- declarations: string; // CSS declarations
290
- atRules?: string[]; // @media, @supports, etc.
291
- nestingLevel?: number; // Nesting depth for specificity
318
+ selector: string; // full selector, or a fragment when needsClassName
319
+ declarations: string; // CSS declarations
320
+ atRules?: string[]; // @media, @container, @supports, …
321
+ needsClassName?: boolean; // prepend the generated `.tX.tX` (OR'd fragments joined with '|||')
322
+ rootPrefix?: string; // root-state prefix placed before the class
323
+ startingStyle?: boolean; // wrap declarations in @starting-style
292
324
  }
293
325
 
294
326
  // Example StyleResult
295
327
  const styleRule: StyleResult = {
296
- selector: '.t-button',
328
+ selector: ':where([data-hovered])',
297
329
  declarations: 'padding: 8px 16px; background: blue; color: white;',
298
330
  atRules: ['@media (min-width: 768px)'],
299
- nestingLevel: 0,
331
+ needsClassName: true,
300
332
  };
301
333
  ```
302
334
 
335
+ ### Batched Injection
336
+
337
+ `configure({ batchInjection: true })` queues every sheet write — component
338
+ rules, global rules, raw CSS and at-rules — into one FIFO and applies them
339
+ together, so the document is style-invalidated once per flush instead of once per
340
+ component. `<TastyBatchProvider>` flushes in `useInsertionEffect`, before any
341
+ layout effect, so a queued write can never be observed by a measurement. See
342
+ [Batched injection](configuration.md#batched-injection) for the modes and the
343
+ ordering guarantee. `flushStyles()` applies pending writes on demand; every read
344
+ API here calls it for you.
345
+
303
346
  ### Deduplication & Performance
304
347
 
305
348
  ```typescript
306
- // Identical CSS rules get the same className
307
- const button1 = inject([{
308
- selector: '.t-btn1',
309
- declarations: 'padding: 8px; color: red;'
310
- }]);
349
+ const rule = { selector: '', declarations: 'padding: 8px; color: red;', needsClassName: true };
311
350
 
312
- const button2 = inject([{
313
- selector: '.t-btn2',
314
- declarations: 'padding: 8px; color: red;' // Same declarations
315
- }]);
351
+ const button1 = inject([rule], { cacheKey: 'button' });
352
+ const button2 = inject([rule], { cacheKey: 'button' });
316
353
 
317
- // Both get the same className due to deduplication
354
+ // One class, one copy of the CSS
318
355
  console.log(button1.className === button2.className); // true
319
356
  ```
320
357
 
321
- ### Reference Counting
358
+ Without `cacheKey` the class name is a hash of the rules, so injecting the same rules again reuses the class the same way: the rules are written once, and each call adds a pin that its own `dispose()` releases.
359
+
360
+ ### Pinning
322
361
 
323
362
  ```typescript
324
- // Multiple components using the same styles
325
- const comp1 = inject([commonStyle]);
326
- const comp2 = inject([commonStyle]);
327
- const comp3 = inject([commonStyle]);
328
-
329
- // Style is kept alive while any component uses it
330
- comp1.dispose(); // refCount: 3 → 2
331
- comp2.dispose(); // refCount: 2 → 1
332
- comp3.dispose(); // refCount: 1 → 0, eligible for bulk cleanup
333
-
334
- // Rule exists but refCount = 0 means unused
335
- // Next inject() with same styles will increment refCount and reuse immediately
363
+ // Multiple callers using the same styles
364
+ const comp1 = inject([commonStyle], { cacheKey: 'common' });
365
+ const comp2 = inject([commonStyle], { cacheKey: 'common' });
366
+ const comp3 = inject([commonStyle], { cacheKey: 'common' });
367
+
368
+ // Style is pinned while any caller holds a handle
369
+ comp1.dispose(); // pins: 3 → 2
370
+ comp2.dispose(); // pins: 2 → 1
371
+ comp3.dispose(); // pins: 1 → 0, now up to the DOM and gc()
372
+
373
+ // Unpinned does not mean deleted: the rule stays cached and is reused instantly
374
+ // by the next inject(). gc() decides when it actually goes.
336
375
  ```
337
376
 
377
+ Pinning covers callers that hold a handle. Styles that come from rendering are
378
+ never pinned — see `{ pin: false }` under
379
+ [`inject()`](#injectrules-options-injectresult) — so what keeps them alive is
380
+ being in the DOM, and nothing else.
381
+
338
382
  ### Garbage Collection
339
383
 
340
384
  ```typescript
@@ -342,6 +386,9 @@ import { configure, gc } from '@tenphi/tasty';
342
386
 
343
387
  // Keyframes: Disposed immediately when refCount = 0 (safer for global scope)
344
388
  // CSS rules: Tracked by touch count and cleaned up via gc()
389
+ //
390
+ // A CSS rule is collectible when no element carries its class AND nobody
391
+ // pinned it with inject().
345
392
 
346
393
  configure({
347
394
  gc: {
@@ -356,15 +403,19 @@ gc();
356
403
  // Force-remove ALL unused styles (e.g. on route change or test teardown):
357
404
  gc({ force: true });
358
405
 
359
- // GC is also triggered automatically by touch count during rendering.
360
- // Every `touchInterval` touches, GC is scheduled via requestIdleCallback.
406
+ // cleanup() is the same thing:
407
+ cleanup();
408
+
409
+ // Every `touchInterval` renders, a sweep is scheduled in idle time. It scans
410
+ // the DOM for the classes actually on the page and sorts everything the
411
+ // injector holds into five bands — only the last one is deleted. See below.
361
412
 
362
413
  // Benefits:
363
414
  // - Activity-proportional: busy apps trigger GC more often
364
415
  // - DOM-safe: styles currently in the DOM are never evicted
365
416
  // - Oldest-first: least recently used styles are evicted first
366
417
  // - Keyframes: Immediate cleanup prevents global namespace pollution
367
- // - Unused styles can be instantly reactivated (just increment refCount)
418
+ // - Unused styles stay cached until evicted, so re-rendering them is a cache hit
368
419
  ```
369
420
 
370
421
  ### Shadow DOM Support
@@ -391,15 +442,16 @@ const shadowAnimation = keyframes({
391
442
 
392
443
  ### Server-Side Rendering
393
444
 
445
+ `getCSSText()` reads the injector's stylesheets, so it needs a DOM; on a server it throws. Collect server CSS with `ServerStyleCollector` from `@tenphi/tasty/ssr` (`collector.getCSS()`) — see [SSR](./ssr.md).
446
+
394
447
  ```typescript
395
448
  import { getCSSText, getCSSTextForNode } from '@tenphi/tasty';
449
+ import { render } from '@testing-library/react';
396
450
 
397
- // Extract all CSS for SSR
398
- const cssText = getCSSText();
451
+ const cssText = getCSSText(); // everything the injector holds (browser / test DOM)
399
452
 
400
- // Extract CSS for specific DOM subtree (like jest-styled-components)
401
- const container = render(<MyComponent />);
402
- const componentCSS = getCSSTextForNode(container);
453
+ const { container } = render(<MyComponent />);
454
+ const componentCSS = getCSSTextForNode(container); // only the CSS this subtree uses
403
455
  ```
404
456
 
405
457
  ### Test Environment Detection
@@ -459,11 +511,11 @@ const metrics = injector.instance.getMetrics();
459
511
  console.log({
460
512
  cacheHits: metrics.hits, // Successful cache hits
461
513
  cacheMisses: metrics.misses, // New styles injected
462
- unusedHits: metrics.unusedHits, // Current unused styles (calculated on demand)
514
+ unusedHits: metrics.unusedHits, // Styles currently eligible for eviction (scans the DOM)
463
515
  bulkCleanups: metrics.bulkCleanups, // Number of bulk cleanup operations
464
516
  stylesCleanedUp: metrics.stylesCleanedUp, // Total styles removed in bulk cleanups
465
517
  totalInsertions: metrics.totalInsertions, // Lifetime insertions
466
- totalUnused: metrics.totalUnused, // Total styles marked as unused (refCount = 0)
518
+ totalUnused: metrics.totalUnused, // Times a pinned style lost its last pin
467
519
  startTime: metrics.startTime, // Metrics collection start timestamp
468
520
  cleanupHistory: metrics.cleanupHistory, // Detailed cleanup operation history
469
521
  });
@@ -472,17 +524,14 @@ console.log({
472
524
  ### Debug Information
473
525
 
474
526
  ```typescript
475
- // Get detailed information about injected styles
476
- const debugInfo = injector.instance.getDebugInfo();
527
+ import { tastyDebug } from '@tenphi/tasty';
477
528
 
478
- console.log({
479
- activeStyles: debugInfo.activeStyles, // Currently active styles
480
- unusedStyles: debugInfo.unusedStyles, // Styles marked for cleanup
481
- totalSheets: debugInfo.totalSheets, // Number of stylesheets
482
- totalRules: debugInfo.totalRules, // Total CSS rules
483
- });
529
+ const { activeClasses, unusedClasses, hotClasses, totalRuleCount } =
530
+ tastyDebug.summary({ raw: true });
484
531
  ```
485
532
 
533
+ See [Debug Utilities](./debug.md).
534
+
486
535
  ### Cleanup History
487
536
 
488
537
  ```typescript
@@ -507,10 +556,10 @@ metrics.cleanupHistory.forEach(cleanup => {
507
556
 
508
557
  ```typescript
509
558
  // ✅ Reuse styles - identical CSS gets deduplicated
510
- const buttonBase = { padding: '8px 16px', borderRadius: '4px' };
559
+ const buttonBase = 'padding: 8px 16px; border-radius: 4px;';
511
560
 
512
561
  // ✅ Avoid frequent disposal and re-injection
513
- // Let the reference counting system handle cleanup
562
+ // Let the injector handle cleanup
514
563
 
515
564
  // ✅ Use bulk operations for global styles
516
565
  injectGlobal([
@@ -536,13 +585,13 @@ configure({
536
585
  // The injector automatically manages memory through:
537
586
 
538
587
  // 1. Hash-based deduplication - same CSS = same className
539
- // 2. Reference counting - styles stay alive while in use (refCount > 0)
540
- // 3. Immediate keyframes cleanup - disposed instantly when refCount = 0
541
- // 4. Touch-count GC - unused CSS rules are evicted oldest-first when over capacity
542
- // 5. DOM safety guard - styles visible in the DOM are never evicted
588
+ // 2. DOM-driven lifetime - a rendered class is never evicted
589
+ // 3. Pinning - inject() callers hold their classes until they dispose
590
+ // 4. Immediate keyframes cleanup - disposed instantly when refCount = 0
591
+ // 5. Touch-count GC - unused CSS rules are evicted oldest-first when over capacity
543
592
 
544
593
  // Manual cleanup is rarely needed but available:
545
- cleanup(); // Force immediate cleanup of all unused CSS rules (refCount = 0)
594
+ cleanup(); // Remove every rule that is neither rendered nor pinned
546
595
  destroy(); // Nuclear option: remove all stylesheets and reset
547
596
  ```
548
597
 
@@ -564,9 +613,9 @@ const StyledButton = tasty({
564
613
 
565
614
  // Internally uses the injector:
566
615
  // 1. Styles are parsed into StyleResult objects
567
- // 2. inject() is called with the parsed results
616
+ // 2. inject() is called with the parsed results, unpinned
568
617
  // 3. Component gets the returned className
569
- // 4. dispose() is called when component unmounts
618
+ // 4. gc() reclaims the class once no element carries it
570
619
  ```
571
620
 
572
621
  For most development, you'll use the [React API](./react-api.md) rather than the injector directly. The injector provides the high-performance foundation that makes Tasty's declarative styling possible.
package/docs/llms.txt ADDED
@@ -0,0 +1,31 @@
1
+ # Tasty
2
+
3
+ > Docs for `@tenphi/tasty`, the version installed in this project. Read the style rules for AI agents before you write or review styles.
4
+
5
+ ## Start here
6
+
7
+ - [Tasty Style Rules for AI Agents](ai-agents.md): the rules for correct styles, with a checklist. Read it before you write or review styles.
8
+ - [Getting Started](getting-started.md): installation, a first component, configuration, the ESLint plugin, and choosing a rendering mode.
9
+
10
+ ## Guides
11
+
12
+ - [Methodology](methodology.md): root and sub-elements, `styleProps` as the public API, `tokens`, `styles` vs `style`, wrapping and extending, anti-patterns.
13
+ - [Building a Design System](design-system.md): token vocabularies, state aliases, recipes, layout primitives, compound components, override contracts.
14
+
15
+ ## Reference
16
+
17
+ - [Style DSL Reference](dsl.md): state maps and state keys, color tokens, units, replace tokens, recipes, advanced states (`@media`, `@parent`, `@root`, `:has`), keyframes, `@property`, `@font-face`, `@function`.
18
+ - [Style Properties Reference](styles.md): every Tasty style property (`fill`, `padding`, `border`, `radius`, `flow`, `preset`, …) and its syntax.
19
+ - [React API](react-api.md): `tasty()`, extending, `styleProps`, `modProps`, `tokenProps`, variants, sub-elements, `useStyles` and the other style functions.
20
+ - [Configuration](configuration.md): `configure()`: state aliases, units, tokens, replace tokens, recipes, presets, handlers, plugins.
21
+ - [Plugins & Extension Points](plugins.md): choosing between functions, units, states, handlers, prop handlers, recipes and base style props.
22
+
23
+ ## Rendering modes
24
+
25
+ - [Build-Time Extraction (`tastyStatic`)](tasty-static.md): zero-runtime CSS through the Babel plugin, Next.js setup, config files, limitations.
26
+ - [Server-Side Rendering (SSR)](ssr.md): the style collector, hydration, Next.js App Router and Astro.
27
+
28
+ ## Help
29
+
30
+ - [Tasty Debug Utilities](debug.md): `tastyDebug` in the browser console: the CSS on the page, cache metrics, chunks.
31
+ - [Migration Guide: v2 → v3](migration-v3.md): every breaking change from v2, with a search-and-replace cheat sheet.