@tenphi/tasty 0.0.0-snapshot.b49e579 → 0.0.0-snapshot.b4e384c
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.
- package/README.md +436 -394
- package/dist/babel-types-Dc5zghyE.d.ts +18 -0
- package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
- package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
- package/dist/chunks/build-config-D9Iq8QQm.js +60 -0
- package/dist/chunks/build-config-D9Iq8QQm.js.map +1 -0
- package/dist/{collector-D6fpuCdp.js → chunks/collector-Cb8ah2JF.js} +25 -119
- package/dist/chunks/collector-Cb8ah2JF.js.map +1 -0
- package/dist/chunks/config-engine-CMYFZYQh.js +272 -0
- package/dist/chunks/config-engine-CMYFZYQh.js.map +1 -0
- package/dist/chunks/config-file-DlZXJMj8.js +25 -0
- package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
- package/dist/chunks/css-definitions-B4aWBkH3.js +910 -0
- package/dist/chunks/css-definitions-B4aWBkH3.js.map +1 -0
- package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
- package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
- package/dist/chunks/debug-D2Pu7Xhy.js +502 -0
- package/dist/chunks/debug-D2Pu7Xhy.js.map +1 -0
- package/dist/chunks/dsl-CsFl9LGn.js +1458 -0
- package/dist/chunks/dsl-CsFl9LGn.js.map +1 -0
- package/dist/chunks/hydration-TRcz5vnk.js +41 -0
- package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
- package/dist/chunks/react-runtime-DHiopXCu.js +691 -0
- package/dist/chunks/react-runtime-DHiopXCu.js.map +1 -0
- package/dist/chunks/runtime-engine-NGCofNXy.js +2435 -0
- package/dist/chunks/runtime-engine-NGCofNXy.js.map +1 -0
- package/dist/chunks/runtime-state-lZjMbvwV.js +152 -0
- package/dist/chunks/runtime-state-lZjMbvwV.js.map +1 -0
- package/dist/{merge-styles-biRwSixM.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
- package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
- package/dist/chunks/style-engine-DnkV_4Jg.js +5602 -0
- package/dist/chunks/style-engine-DnkV_4Jg.js.map +1 -0
- package/dist/{css-writer-DB4ZVUYy.js → chunks/zero-engine-DcwaCvFs.js} +65 -145
- package/dist/chunks/zero-engine-DcwaCvFs.js.map +1 -0
- package/dist/{collector-D8o4Wdq-.d.ts → collector-D2OT6I2G.d.ts} +23 -4
- package/dist/{config-De8L9NWM.d.ts → config-C4ftFxgI.d.ts} +273 -78
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/hydrate-CRyjjAyl.d.ts +22 -0
- package/dist/{index-DzGxoeyN.d.ts → index-DxQNRj50.d.ts} +369 -258
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -867
- package/dist/{merge-styles-DLm4wdnb.d.ts → merge-styles-D39qBtox.d.ts} +2 -3
- package/dist/ssr/astro-client.d.ts +1 -1
- package/dist/ssr/astro-client.js +1 -14
- package/dist/ssr/astro-client.js.map +1 -1
- package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract-static.js +9 -0
- package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
- package/dist/ssr/astro-middleware-extract.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract.js +9 -0
- package/dist/ssr/astro-middleware-extract.js.map +1 -0
- package/dist/ssr/astro-middleware-static.d.ts +3 -2
- package/dist/ssr/astro-middleware-static.js +0 -11
- package/dist/ssr/astro-middleware-static.js.map +1 -1
- package/dist/ssr/astro-middleware.d.ts +3 -2
- package/dist/ssr/astro-middleware.js +0 -12
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +40 -6
- package/dist/ssr/astro.js +157 -93
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +2 -0
- package/dist/ssr/index.d.ts +5 -25
- package/dist/ssr/index.js +5 -5
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +64 -0
- package/dist/ssr/next-config.js +123 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +9 -8
- package/dist/ssr/next.js +29 -43
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +8 -9
- package/dist/static/index.js +4 -22
- package/dist/static/index.js.map +1 -1
- package/dist/static/inject.d.ts +1 -2
- package/dist/{index-KUYya3x7.d.ts → types-CYQIhUg1.d.ts} +745 -592
- package/dist/zero/babel.d.ts +73 -2
- package/dist/zero/babel.js +81 -144
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +63 -8
- package/dist/zero/index.js +25 -2
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +4 -5
- package/dist/zero/next.js +3 -38
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +16 -8
- package/docs/adoption.md +69 -36
- package/docs/ai-agents.md +122 -86
- package/docs/comparison.md +77 -47
- package/docs/configuration.md +434 -110
- package/docs/debug.md +21 -8
- package/docs/design-system.md +152 -31
- package/docs/dsl.md +503 -222
- package/docs/getting-started.md +130 -50
- package/docs/injector.md +117 -68
- package/docs/methodology.md +81 -50
- package/docs/migration-v3.md +52 -52
- package/docs/pipeline.md +55 -31
- package/docs/plugins.md +59 -75
- package/docs/react-api.md +141 -55
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +285 -101
- package/docs/styles.md +178 -35
- package/docs/tasty-static.md +286 -135
- package/package.json +125 -41
- package/dist/async-storage-DKK-wTD4.js +0 -44
- package/dist/async-storage-DKK-wTD4.js.map +0 -1
- package/dist/babel-R2qT7yLN.d.ts +0 -83
- package/dist/collector-D6fpuCdp.js.map +0 -1
- package/dist/config-Bxme0Moq.js +0 -12442
- package/dist/config-Bxme0Moq.js.map +0 -1
- package/dist/context-CA8YKeMn.js +0 -24
- package/dist/context-CA8YKeMn.js.map +0 -1
- package/dist/core-BR4waa0Q.js +0 -1552
- package/dist/core-BR4waa0Q.js.map +0 -1
- package/dist/css-writer-DB4ZVUYy.js.map +0 -1
- package/dist/format-global-rules-DklyaXv-.js +0 -22
- package/dist/format-global-rules-DklyaXv-.js.map +0 -1
- package/dist/format-rules-BXSRL8KZ.js +0 -145
- package/dist/format-rules-BXSRL8KZ.js.map +0 -1
- package/dist/hydrate-D_EWjD6z.js +0 -37
- package/dist/hydrate-D_EWjD6z.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-DrUITLCz.js +0 -424
- package/dist/keyframes-DrUITLCz.js.map +0 -1
- package/dist/merge-styles-biRwSixM.js.map +0 -1
- package/dist/resolve-recipes-CBVdPz67.js +0 -144
- package/dist/resolve-recipes-CBVdPz67.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
|
-
- **
|
|
13
|
-
- **
|
|
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
|
|
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
|
-
//
|
|
58
|
+
// Rules flagged needsClassName get the generated class prepended (doubled)
|
|
59
59
|
const result = inject([{
|
|
60
|
-
selector: '
|
|
60
|
+
selector: '',
|
|
61
61
|
declarations: 'color: red; padding: 10px;',
|
|
62
|
+
needsClassName: true,
|
|
62
63
|
}]);
|
|
63
64
|
|
|
64
|
-
console.log(result.className); // 't
|
|
65
|
+
console.log(result.className); // 'th8n0uh' — `t` + base36 hash of the rules
|
|
66
|
+
// Injected: .th8n0uh.th8n0uh { color: red; padding: 10px; }
|
|
65
67
|
|
|
66
|
-
//
|
|
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 (
|
|
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
|
|
249
|
-
- `gc.
|
|
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
|
|
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
|
|
314
|
+
The injector works with `StyleResult` objects from the pipeline (`renderStyles`):
|
|
285
315
|
|
|
286
316
|
```typescript
|
|
287
317
|
interface StyleResult {
|
|
288
|
-
selector: string;
|
|
289
|
-
declarations: string;
|
|
290
|
-
atRules?: string[];
|
|
291
|
-
|
|
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: '
|
|
328
|
+
selector: ':where([data-hovered])',
|
|
297
329
|
declarations: 'padding: 8px 16px; background: blue; color: white;',
|
|
298
330
|
atRules: ['@media (min-width: 768px)'],
|
|
299
|
-
|
|
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
|
-
|
|
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
|
|
313
|
-
|
|
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
|
-
//
|
|
354
|
+
// One class, one copy of the CSS
|
|
318
355
|
console.log(button1.className === button2.className); // true
|
|
319
356
|
```
|
|
320
357
|
|
|
321
|
-
|
|
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
|
|
325
|
-
const comp1 = inject([commonStyle]);
|
|
326
|
-
const comp2 = inject([commonStyle]);
|
|
327
|
-
const comp3 = inject([commonStyle]);
|
|
328
|
-
|
|
329
|
-
// Style is
|
|
330
|
-
comp1.dispose(); //
|
|
331
|
-
comp2.dispose(); //
|
|
332
|
-
comp3.dispose(); //
|
|
333
|
-
|
|
334
|
-
//
|
|
335
|
-
//
|
|
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
|
-
//
|
|
360
|
-
|
|
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
|
|
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
|
-
//
|
|
398
|
-
const cssText = getCSSText();
|
|
451
|
+
const cssText = getCSSText(); // everything the injector holds (browser / test DOM)
|
|
399
452
|
|
|
400
|
-
|
|
401
|
-
const
|
|
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, //
|
|
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, //
|
|
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
|
-
|
|
476
|
-
const debugInfo = injector.instance.getDebugInfo();
|
|
527
|
+
import { tastyDebug } from '@tenphi/tasty';
|
|
477
528
|
|
|
478
|
-
|
|
479
|
-
|
|
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 =
|
|
559
|
+
const buttonBase = 'padding: 8px 16px; border-radius: 4px;';
|
|
511
560
|
|
|
512
561
|
// ✅ Avoid frequent disposal and re-injection
|
|
513
|
-
// Let the
|
|
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.
|
|
540
|
-
// 3.
|
|
541
|
-
// 4.
|
|
542
|
-
// 5.
|
|
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(); //
|
|
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.
|
|
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.
|