@tenphi/tasty 0.0.0-snapshot.002b1b3

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 (82) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +637 -0
  3. package/dist/async-storage-B7_o6FKt.js +44 -0
  4. package/dist/async-storage-B7_o6FKt.js.map +1 -0
  5. package/dist/collector-LuU1vZ68.d.ts +98 -0
  6. package/dist/collector-MOYY2SOr.js +230 -0
  7. package/dist/collector-MOYY2SOr.js.map +1 -0
  8. package/dist/config-A237aY9H.js +10235 -0
  9. package/dist/config-A237aY9H.js.map +1 -0
  10. package/dist/config-vuCRkBWX.d.ts +884 -0
  11. package/dist/context-CkSg-kDT.js +24 -0
  12. package/dist/context-CkSg-kDT.js.map +1 -0
  13. package/dist/core/index.d.ts +5 -0
  14. package/dist/core/index.js +6 -0
  15. package/dist/core-BkKav78f.js +1592 -0
  16. package/dist/core-BkKav78f.js.map +1 -0
  17. package/dist/css-writer-Cos9tQRM.js +329 -0
  18. package/dist/css-writer-Cos9tQRM.js.map +1 -0
  19. package/dist/format-global-rules-Dbc_1tc3.js +22 -0
  20. package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
  21. package/dist/format-rules-C2oiTsEO.js +143 -0
  22. package/dist/format-rules-C2oiTsEO.js.map +1 -0
  23. package/dist/hydrate-miFzWIKR.js +45 -0
  24. package/dist/hydrate-miFzWIKR.js.map +1 -0
  25. package/dist/index-CJMXAAO5.d.ts +1602 -0
  26. package/dist/index-dUtwpOux.d.ts +1266 -0
  27. package/dist/index.d.ts +5 -0
  28. package/dist/index.js +732 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/keyframes-DDtNo_hl.js +587 -0
  31. package/dist/keyframes-DDtNo_hl.js.map +1 -0
  32. package/dist/merge-styles-CtDJMhpJ.d.ts +7 -0
  33. package/dist/merge-styles-D_HbBOlq.js +144 -0
  34. package/dist/merge-styles-D_HbBOlq.js.map +1 -0
  35. package/dist/resolve-recipes-B7-823LL.js +144 -0
  36. package/dist/resolve-recipes-B7-823LL.js.map +1 -0
  37. package/dist/ssr/astro-client.d.ts +1 -0
  38. package/dist/ssr/astro-client.js +19 -0
  39. package/dist/ssr/astro-client.js.map +1 -0
  40. package/dist/ssr/astro-middleware.d.ts +15 -0
  41. package/dist/ssr/astro-middleware.js +19 -0
  42. package/dist/ssr/astro-middleware.js.map +1 -0
  43. package/dist/ssr/astro.d.ts +97 -0
  44. package/dist/ssr/astro.js +149 -0
  45. package/dist/ssr/astro.js.map +1 -0
  46. package/dist/ssr/index.d.ts +44 -0
  47. package/dist/ssr/index.js +10 -0
  48. package/dist/ssr/index.js.map +1 -0
  49. package/dist/ssr/next.d.ts +46 -0
  50. package/dist/ssr/next.js +75 -0
  51. package/dist/ssr/next.js.map +1 -0
  52. package/dist/static/index.d.ts +91 -0
  53. package/dist/static/index.js +50 -0
  54. package/dist/static/index.js.map +1 -0
  55. package/dist/static/inject.d.ts +5 -0
  56. package/dist/static/inject.js +17 -0
  57. package/dist/static/inject.js.map +1 -0
  58. package/dist/zero/babel.d.ts +81 -0
  59. package/dist/zero/babel.js +466 -0
  60. package/dist/zero/babel.js.map +1 -0
  61. package/dist/zero/index.d.ts +67 -0
  62. package/dist/zero/index.js +2 -0
  63. package/dist/zero/next.d.ts +86 -0
  64. package/dist/zero/next.js +143 -0
  65. package/dist/zero/next.js.map +1 -0
  66. package/docs/README.md +31 -0
  67. package/docs/adoption.md +298 -0
  68. package/docs/comparison.md +419 -0
  69. package/docs/configuration.md +394 -0
  70. package/docs/debug.md +320 -0
  71. package/docs/design-system.md +436 -0
  72. package/docs/dsl.md +688 -0
  73. package/docs/getting-started.md +217 -0
  74. package/docs/injector.md +544 -0
  75. package/docs/methodology.md +616 -0
  76. package/docs/pipeline.md +673 -0
  77. package/docs/react-api.md +557 -0
  78. package/docs/ssr.md +442 -0
  79. package/docs/styles.md +596 -0
  80. package/docs/tasty-static.md +532 -0
  81. package/package.json +222 -0
  82. package/tasty.config.ts +15 -0
@@ -0,0 +1,394 @@
1
+ # Configuration
2
+
3
+ Configure the Tasty style system before your app renders using the `configure()` function. Configuration must be done **before any styles are generated** (before first render). For a higher-level docs map, see the [Docs Hub](README.md).
4
+
5
+ ```jsx
6
+ import { configure } from '@tenphi/tasty';
7
+
8
+ configure({
9
+ // CSP nonce for style elements
10
+ nonce: 'abc123',
11
+
12
+ // Global state aliases
13
+ states: {
14
+ '@mobile': '@media(w < 768px)',
15
+ '@tablet': '@media(768px <= w < 1024px)',
16
+ '@dark': '@root(schema=dark)',
17
+ },
18
+
19
+ // Parser configuration
20
+ parserCacheSize: 2000, // LRU cache size (default: 1000)
21
+
22
+ // Custom units (merged with built-in units)
23
+ units: {
24
+ vh: 'vh',
25
+ vw: 'vw',
26
+ custom: (n) => `${n * 10}px`, // Function-based unit
27
+ },
28
+
29
+ // Custom functions for the parser
30
+ funcs: {
31
+ double: (groups) => {
32
+ const value = parseFloat(groups[0]?.output || '0');
33
+ return `${value * 2}px`;
34
+ },
35
+ },
36
+ });
37
+ ```
38
+
39
+ These docs use `data-schema="dark"` in examples. If your app already standardizes on a different attribute such as `data-theme`, keep the same pattern and swap the attribute name consistently everywhere you define root-state aliases.
40
+
41
+ ---
42
+
43
+ ## Options
44
+
45
+ | Option | Type | Default | Description |
46
+ |--------|------|---------|-------------|
47
+ | `nonce` | `string` | - | CSP nonce for style elements |
48
+ | `states` | `Record<string, string>` | - | Global state aliases for advanced state mapping |
49
+ | `parserCacheSize` | `number` | `1000` | Parser LRU cache size |
50
+ | `units` | `Record<string, string \| Function>` | Built-in | Custom units (merged with built-in). See [built-in units](dsl.md#built-in-units) |
51
+ | `funcs` | `Record<string, Function>` | - | Custom parser functions (merged with existing) |
52
+ | `handlers` | `Record<string, StyleHandlerDefinition>` | Built-in | Custom style handlers (replace built-in) |
53
+ | `tokens` | `Record<string, value \| stateMap>` | - | Design tokens injected as `:root` CSS custom properties |
54
+ | `replaceTokens` | `Record<string, string \| number>` | - | Parse-time token substitution (inline replacement) |
55
+ | `keyframes` | `Record<string, KeyframesSteps>` | - | Global keyframes for animations |
56
+ | `properties` | `Record<string, PropertyDefinition>` | - | Global CSS @property definitions |
57
+ | `fontFace` | `Record<string, FontFaceInput>` | - | Global @font-face definitions |
58
+ | `counterStyle` | `Record<string, CounterStyleDescriptors>` | - | Global @counter-style definitions |
59
+ | `autoPropertyTypes` | `boolean` | `true` | Auto-infer and register `@property` types from values |
60
+ | `recipes` | `Record<string, RecipeStyles>` | - | Predefined style recipes (named style bundles) |
61
+ | `presets` | `Record<string, TypographyPreset>` | - | Typography presets — shorthand for `generateTypographyTokens()` |
62
+ | `globalStyles` | `Record<string, Styles>` | - | Global Tasty styles keyed by CSS selector |
63
+ | `colorSpace` | `'rgb' \| 'hsl' \| 'oklch'` | `'oklch'` | Color space for decomposed color token companion variables |
64
+
65
+ ---
66
+
67
+ ## Color Space
68
+
69
+ Controls the CSS color space used for decomposed color token companion variables. When you define `#name` color tokens, tasty generates both `--name-color` (full color) and `--name-color-{suffix}` (decomposed components for alpha composition).
70
+
71
+ ```jsx
72
+ configure({
73
+ colorSpace: 'oklch', // default
74
+ });
75
+ ```
76
+
77
+ | Color Space | Suffix | Components Format | Alpha Syntax |
78
+ |---|---|---|---|
79
+ | `rgb` | `-rgb` | `255 128 0` | `rgb(var(--name-color-rgb) / .5)` |
80
+ | `hsl` | `-hsl` | `300 100% 25%` | `hsl(var(--name-color-hsl) / .5)` |
81
+ | `oklch` | `-oklch` | `0.42 0.16 328` | `oklch(var(--name-color-oklch) / .5)` |
82
+
83
+ The `oklch` color space is the default because it provides perceptually uniform color manipulation — alpha fading and color mixing produce more natural-looking results.
84
+
85
+ ---
86
+
87
+ ## Design Tokens
88
+
89
+ Design tokens define CSS custom properties on `:root`. They are injected automatically when the first style is rendered. Values are parsed through the Tasty DSL, so you can use units, color syntax, and other DSL features.
90
+
91
+ Tokens support state maps for responsive or theme-aware values:
92
+
93
+ ```jsx
94
+ configure({
95
+ tokens: {
96
+ '$gap': '4px',
97
+ '$radius': '6px',
98
+ '#primary': {
99
+ '': '#purple',
100
+ '@dark': '#light-purple',
101
+ },
102
+ '$font-size': {
103
+ '': '14px',
104
+ '@mobile': '12px',
105
+ },
106
+ },
107
+ });
108
+ ```
109
+
110
+ - `$name` keys become `--name` CSS custom properties
111
+ - `#name` keys become `--name-color` and `--name-color-{colorSpace}` properties (suffix depends on `colorSpace`, default `oklch`)
112
+
113
+ Tokens are automatically emitted in all rendering modes: runtime (client), SSR, and zero-runtime (Babel plugin).
114
+
115
+ ---
116
+
117
+ ## Replace Tokens (Parse-Time Substitution)
118
+
119
+ Replace tokens are **substituted inline at parse time** — they are baked into the generated CSS, not resolved via CSS custom properties at runtime. This makes them ideal for value aliases and shorthand references.
120
+
121
+ Use `$name` for value tokens and `#name` for color token aliases:
122
+
123
+ ```jsx
124
+ configure({
125
+ replaceTokens: {
126
+ $spacing: '2x',
127
+ '$card-padding': '4x',
128
+ '#accent': '#purple',
129
+ '#surface-hover': '#gray.05',
130
+ },
131
+ });
132
+ ```
133
+
134
+ When a component uses `padding: '$card-padding'`, the parser replaces it with `'4x'` before generating CSS. When a component uses `fill: '#accent'`, it is replaced with `'#purple'`, which in turn resolves to `var(--purple-color)`.
135
+
136
+ See [Replace Tokens](dsl.md#replace-tokens) in the Style DSL reference.
137
+
138
+ ---
139
+
140
+ ## Font Face
141
+
142
+ Register custom fonts globally so every component can reference them by family name. Values are descriptor objects or arrays (for multiple weights/styles). Rules are injected eagerly when styles are first generated.
143
+
144
+ ```ts
145
+ configure({
146
+ fontFace: {
147
+ 'Brand Sans': [
148
+ {
149
+ src: 'url("/fonts/brand-regular.woff2") format("woff2")',
150
+ fontWeight: 400,
151
+ fontDisplay: 'swap',
152
+ },
153
+ {
154
+ src: 'url("/fonts/brand-bold.woff2") format("woff2")',
155
+ fontWeight: 700,
156
+ fontDisplay: 'swap',
157
+ },
158
+ ],
159
+ Icons: {
160
+ src: 'url("/fonts/icons.woff2") format("woff2")',
161
+ fontDisplay: 'block',
162
+ },
163
+ },
164
+ });
165
+ ```
166
+
167
+ Now any component can use `fontFamily: '"Brand Sans", sans-serif'` and the browser will already have the `@font-face` rules in the stylesheet.
168
+
169
+ See [Font Face (`@fontFace`)](dsl.md#font-face-fontface) for inline usage inside component styles and the full list of supported descriptors.
170
+
171
+ ---
172
+
173
+ ## Counter Style
174
+
175
+ Define custom list-marker algorithms globally. Rules are injected eagerly when styles are first generated.
176
+
177
+ ```ts
178
+ configure({
179
+ counterStyle: {
180
+ thumbs: {
181
+ system: 'cyclic',
182
+ symbols: '"👍"',
183
+ suffix: '" "',
184
+ },
185
+ 'lower-roman-parens': {
186
+ system: 'extends lower-roman',
187
+ suffix: '") "',
188
+ },
189
+ },
190
+ });
191
+ ```
192
+
193
+ Components can then reference `listStyleType: 'thumbs'` directly.
194
+
195
+ See [Counter Style (`@counterStyle`)](dsl.md#counter-style-counterstyle) for inline usage inside component styles and the full list of supported descriptors.
196
+
197
+ ---
198
+
199
+ ## Recipes
200
+
201
+ Recipes are predefined, named style bundles. Define them globally via `configure()`:
202
+
203
+ ```jsx
204
+ configure({
205
+ recipes: {
206
+ card: {
207
+ padding: '4x',
208
+ fill: '#surface',
209
+ radius: '1r',
210
+ border: true,
211
+ },
212
+ elevated: {
213
+ shadow: '2x 2x 4x #shadow',
214
+ },
215
+ },
216
+ });
217
+ ```
218
+
219
+ Recipe values are flat tasty styles (no sub-element keys). They may contain base styles, tokens, local states, `@keyframes`, and `@properties`. Recipes cannot reference other recipes.
220
+
221
+ For how to apply, compose, and override recipes in components, see [Recipes](dsl.md#recipes) in the Style DSL reference.
222
+
223
+ ---
224
+
225
+ ## Typography Presets
226
+
227
+ Typography presets are a shorthand for `generateTypographyTokens()`. Instead of calling the function manually and spreading the result into `tokens`, pass the presets directly:
228
+
229
+ ```jsx
230
+ configure({
231
+ presets: {
232
+ h1: { fontSize: '32px', lineHeight: '1.2', fontWeight: '700' },
233
+ t2: { fontSize: '16px', lineHeight: '1.5', fontWeight: '400' },
234
+ tag: {
235
+ fontSize: '10px',
236
+ lineHeight: '1.4',
237
+ letterSpacing: '0.04em',
238
+ fontWeight: '600',
239
+ },
240
+ },
241
+ });
242
+ ```
243
+
244
+ Each preset generates `$name-font-size`, `$name-line-height`, `$name-letter-spacing`, `$name-font-weight`, and optional `$name-bold-font-weight`, `$name-icon-size`, `$name-text-transform`, `$name-font-family`, `$name-font-style` tokens.
245
+
246
+ Preset values support state maps for responsive or theme-aware typography:
247
+
248
+ ```jsx
249
+ configure({
250
+ presets: {
251
+ t2: {
252
+ fontSize: '16px',
253
+ lineHeight: '1.5',
254
+ fontWeight: { '': '400', '@dark': '300' },
255
+ },
256
+ },
257
+ });
258
+ ```
259
+
260
+ The generated tokens are merged **under** explicit `tokens` — if both `presets` and `tokens` define `$t2-font-weight`, the `tokens` value wins. Plugins can also provide `presets`; plugin presets are merged first, then config presets, then explicit tokens on top.
261
+
262
+ ---
263
+
264
+ ## Global Styles
265
+
266
+ Apply Tasty styles to any selector via configuration, without needing `useGlobalStyles(selector, ...)` at runtime:
267
+
268
+ ```jsx
269
+ configure({
270
+ globalStyles: {
271
+ body: {
272
+ fill: '#surface',
273
+ color: '#text',
274
+ preset: 't2',
275
+ margin: 0,
276
+ fontFamily: 'system-ui, sans-serif',
277
+ },
278
+ html: {
279
+ overflow: 'hidden',
280
+ },
281
+ },
282
+ });
283
+ ```
284
+
285
+ Each key is a CSS selector, and each value is a Tasty `Styles` object supporting the full style syntax including style properties, tokens, state maps, and selector-based sub-styling (e.g. `$: '> .app'` for elements outside React scope). Global styles are injected alongside `:root` tokens when the first style is rendered.
286
+
287
+ Global styles are automatically emitted in all rendering modes: runtime (client), SSR, and zero-runtime (Babel plugin). Plugins can also provide `globalStyles`; they are merged per selector with config global styles (config wins on conflict).
288
+
289
+ ---
290
+
291
+ ## Auto Property Types
292
+
293
+ CSS cannot transition or animate custom properties unless their type is declared via [`@property`](https://developer.mozilla.org/en-US/docs/Web/CSS/@property). Tasty handles this automatically — when a custom property is assigned a concrete value (e.g. `'$scale': 1`, `'$gap': '10px'`, `'#accent': 'purple'`), the type is inferred and a `@property` rule is registered.
294
+
295
+ This works across all declaration contexts: component styles, `@keyframes`, global config, and the zero-runtime Babel plugin. It also resolves `var()` chains — if `$a` references `var(--b)`, the type propagates once `--b` is resolved.
296
+
297
+ Supported types:
298
+
299
+ | Detection | Inferred syntax |
300
+ |-----------|-----------------|
301
+ | `1`, `0.5`, `-3` (bare numbers) | `<number>` |
302
+ | `10px`, `2rem`, `100vw` (length units) | `<length>` |
303
+ | `50%` | `<percentage>` |
304
+ | `45deg`, `0.5turn` (angle units) | `<angle>` |
305
+ | `300ms`, `1s` (time units) | `<time>` |
306
+ | `#name` tokens (by naming convention) | `<color>` |
307
+
308
+ Auto-inferred properties use `inherits: true` (the CSS default). Use explicit `@properties` when you need different settings:
309
+
310
+ ```jsx
311
+ // In component styles
312
+ styles: {
313
+ '@properties': {
314
+ '$scale': { syntax: '<number>', inherits: false, initialValue: 1 },
315
+ },
316
+ }
317
+
318
+ // Or globally
319
+ configure({
320
+ properties: {
321
+ '$scale': { syntax: '<number>', inherits: false, initialValue: 1 },
322
+ },
323
+ });
324
+ ```
325
+
326
+ To disable auto-inference entirely (only explicit `@properties` will be used):
327
+
328
+ ```jsx
329
+ configure({ autoPropertyTypes: false });
330
+ ```
331
+
332
+ ---
333
+
334
+ ## Custom Style Handlers
335
+
336
+ Override or extend the built-in style property handlers. A handler definition can take three forms:
337
+
338
+ | Form | Syntax | Description |
339
+ |------|--------|-------------|
340
+ | Function only | `handler` | Triggered by its key name; receives only that property |
341
+ | Single dep | `['styleName', handler]` | Triggered by the specified style property |
342
+ | Multi dep | `[['dep1', 'dep2', ...], handler]` | Triggered by any of the listed properties; receives all of them |
343
+
344
+ The multi-dep form is useful when output depends on several style properties together (e.g., `gap` needs to know `display` and `flow` to decide the CSS strategy).
345
+
346
+ ```jsx
347
+ import { configure, styleHandlers } from '@tenphi/tasty';
348
+
349
+ configure({
350
+ handlers: {
351
+ // Function only — overrides built-in fill handler
352
+ fill: ({ fill }) => {
353
+ if (fill?.startsWith('gradient:')) {
354
+ return { background: fill.slice(9) };
355
+ }
356
+ return styleHandlers.fill({ fill });
357
+ },
358
+
359
+ // Function only — new single-prop handler
360
+ elevation: ({ elevation }) => {
361
+ const level = parseInt(elevation) || 1;
362
+ return {
363
+ 'box-shadow': `0 ${level * 2}px ${level * 4}px rgba(0,0,0,0.1)`,
364
+ 'z-index': String(level * 100),
365
+ };
366
+ },
367
+
368
+ // Multi dep — handler reads multiple style properties
369
+ gap: [['display', 'flow', 'gap'], ({ display, flow, gap }) => {
370
+ if (!gap) return;
371
+ const isGrid = display?.includes('grid');
372
+ return { gap: isGrid ? gap : `/* custom logic for ${flow} */` };
373
+ }],
374
+ },
375
+ });
376
+ ```
377
+
378
+ ---
379
+
380
+ ## Extending Style Types (TypeScript)
381
+
382
+ Use module augmentation to extend the `StylesInterface`:
383
+
384
+ ```tsx
385
+ // tasty.d.ts
386
+ declare module '@tenphi/tasty' {
387
+ interface StylesInterface {
388
+ elevation?: string;
389
+ gradient?: string;
390
+ }
391
+ }
392
+ ```
393
+
394
+ See [Style DSL](dsl.md) for state maps, tokens, units, and extending semantics, and [React API](react-api.md) for `tasty()`, style functions, and component props.
package/docs/debug.md ADDED
@@ -0,0 +1,320 @@
1
+ # Tasty Debug Utilities
2
+
3
+ Runtime CSS inspection and diagnostics for the Tasty styling system. Inspect injected styles, measure cache performance, analyze style chunks, and troubleshoot CSS issues — all from the browser console.
4
+
5
+ ---
6
+
7
+ ## Overview
8
+
9
+ `tastyDebug` is a diagnostic object that exposes Tasty's runtime CSS state. It is designed for development use but can be manually installed in production for debugging.
10
+
11
+ In development mode (`isDevEnv()` returns `true`), `tastyDebug` is automatically installed on `window.tastyDebug`. In production, install it manually when needed.
12
+
13
+ All methods **log to the console by default**. Pass `{ raw: true }` to suppress logging and only return data.
14
+
15
+ > **Note (2.0.0+):** Class names use a content-addressed base36 hash format (e.g. `t3a5f`) instead of the previous sequential `t{number}` format. Cross-environment hydration reads the rendered class list from `window.__TASTY__` (the legacy `window.__TASTY_SSR_CACHE__` global was removed in 2.0.0).
16
+
17
+ ---
18
+
19
+ ## Quick Start
20
+
21
+ ```typescript
22
+ // Auto-installed in dev mode. Otherwise:
23
+ import { tastyDebug } from '@tenphi/tasty';
24
+ tastyDebug.install();
25
+
26
+ // Print a quick-start guide
27
+ tastyDebug.help();
28
+
29
+ // Get a comprehensive overview (logged automatically)
30
+ tastyDebug.summary();
31
+
32
+ // See all active CSS
33
+ tastyDebug.css('active');
34
+
35
+ // Inspect a specific element
36
+ tastyDebug.inspect('.my-button');
37
+
38
+ // Silent mode — return data only, no console output
39
+ const data = tastyDebug.summary({ raw: true });
40
+ ```
41
+
42
+ ---
43
+
44
+ ## Options
45
+
46
+ All methods accept a shared options object:
47
+
48
+ ```typescript
49
+ interface DebugOptions {
50
+ root?: Document | ShadowRoot; // Target root (default: document)
51
+ raw?: boolean; // Suppress console logging (default: false)
52
+ }
53
+ ```
54
+
55
+ When `raw` is `false` (the default), results are logged to the console **and** returned. When `raw` is `true`, results are returned silently.
56
+
57
+ ---
58
+
59
+ ## API Reference
60
+
61
+ ### `css(target, opts?): string`
62
+
63
+ Retrieves CSS text for a given target. Logs the result with rule count and size.
64
+
65
+ **Targets:**
66
+
67
+ | Target | Description |
68
+ |---|---|
69
+ | `'all'` | All tasty CSS (component + global + raw) |
70
+ | `'active'` | CSS for classes currently in the DOM |
71
+ | `'unused'` | CSS with refCount = 0 (cached but not used) |
72
+ | `'global'` | Only global CSS (from `injectGlobal`) |
73
+ | `'page'` | All CSS on the page (including non-tasty) |
74
+ | `'t3a5f'` | CSS for a specific tasty class (class names are `t` + base36 hash) |
75
+ | `['t3a5f', 't9k2']` | CSS for multiple tasty classes |
76
+ | `'.my-button'` | CSS affecting a DOM element (by selector) |
77
+ | `element` | CSS affecting a DOM element (by reference) |
78
+
79
+ **Extra options:**
80
+
81
+ ```typescript
82
+ interface CssOptions extends DebugOptions {
83
+ prettify?: boolean; // Format output (default: true)
84
+ source?: boolean; // Read original CSS instead of live CSSOM (default: false, dev-mode only)
85
+ }
86
+ ```
87
+
88
+ ```typescript
89
+ // Active CSS with stats
90
+ tastyDebug.css('active');
91
+
92
+ // Specific class, silent
93
+ const css = tastyDebug.css('t3a5f', { raw: true });
94
+
95
+ // Compare original vs browser-parsed CSS (dev mode only)
96
+ tastyDebug.css('t3a5f'); // live CSSOM
97
+ tastyDebug.css('t3a5f', { source: true }); // original output
98
+
99
+ // Shadow DOM
100
+ tastyDebug.css('all', { root: shadowRoot });
101
+ ```
102
+
103
+ The `source` option reads from `RuleInfo.cssText`, which is only populated when `devMode` is active (development environment or `localStorage.TASTY_DEBUG = 'true'`). In production without debug mode, it falls back to the live CSSOM with a warning.
104
+
105
+ ---
106
+
107
+ ### `inspect(target, opts?): InspectResult`
108
+
109
+ Inspects a DOM element and returns detailed information about its tasty styles, including chunk assignments.
110
+
111
+ ```typescript
112
+ interface InspectResult {
113
+ element?: Element | null;
114
+ classes: string[]; // Tasty classes on the element
115
+ chunks: ChunkInfo[]; // Chunk assignment per class
116
+ css: string; // Prettified CSS
117
+ size: number; // CSS size in characters
118
+ rules: number; // Number of CSS rule blocks
119
+ }
120
+
121
+ interface ChunkInfo {
122
+ className: string;
123
+ chunkName: string | null; // e.g., 'appearance', 'font', 'dimension'
124
+ }
125
+ ```
126
+
127
+ ```typescript
128
+ tastyDebug.inspect('.my-card');
129
+ // Logs: inspect div — 3 classes, 5 rules, 1.2KB
130
+ // Chunks: t3a5f→appearance, t9k2→font, tb71→dimension
131
+
132
+ // Silent
133
+ const result = tastyDebug.inspect('.my-card', { raw: true });
134
+ console.log(result.classes); // ['t3a5f', 't9k2', 'tb71']
135
+ console.log(result.rules); // 5
136
+ ```
137
+
138
+ ---
139
+
140
+ ### `summary(opts?): Summary`
141
+
142
+ One-shot overview of the entire Tasty CSS state. Logs a compact report.
143
+
144
+ ```typescript
145
+ interface Summary {
146
+ activeClasses: string[];
147
+ unusedClasses: string[];
148
+ totalStyledClasses: string[];
149
+
150
+ activeCSSSize: number;
151
+ unusedCSSSize: number;
152
+ globalCSSSize: number;
153
+ rawCSSSize: number;
154
+ keyframesCSSSize: number;
155
+ propertyCSSSize: number;
156
+ totalCSSSize: number;
157
+
158
+ activeRuleCount: number;
159
+ unusedRuleCount: number;
160
+ globalRuleCount: number;
161
+ rawRuleCount: number;
162
+ keyframesRuleCount: number;
163
+ propertyRuleCount: number;
164
+ totalRuleCount: number;
165
+
166
+ metrics: CacheMetrics | null;
167
+ definedProperties: string[];
168
+ definedKeyframes: { name: string; refCount: number }[];
169
+ chunkBreakdown: ChunkBreakdown;
170
+ }
171
+ ```
172
+
173
+ ```typescript
174
+ // Logged automatically
175
+ tastyDebug.summary();
176
+ // Output:
177
+ // Active: 42 classes, 186 rules, 12.4KB
178
+ // Unused: 3 classes, 8 rules, 0.5KB
179
+ // Global: 12 rules, 1.1KB
180
+ // Total: 45 classes, 206 rules, 14.0KB
181
+ // Cache: 94.2% hit rate (312 lookups)
182
+
183
+ // Silent
184
+ const s = tastyDebug.summary({ raw: true });
185
+ console.log(s.totalRuleCount); // 206
186
+ ```
187
+
188
+ ---
189
+
190
+ ### `chunks(opts?): ChunkBreakdown`
191
+
192
+ Breakdown of styles by chunk type.
193
+
194
+ ```typescript
195
+ interface ChunkBreakdown {
196
+ byChunk: Record<string, {
197
+ classes: string[];
198
+ cssSize: number;
199
+ ruleCount: number;
200
+ }>;
201
+ totalChunkTypes: number;
202
+ totalClasses: number;
203
+ }
204
+ ```
205
+
206
+ ```typescript
207
+ tastyDebug.chunks();
208
+ // Output:
209
+ // appearance: 24 cls, 48 rules, 3.2KB
210
+ // font: 18 cls, 18 rules, 1.1KB
211
+ // dimension: 31 cls, 45 rules, 2.4KB
212
+ ```
213
+
214
+ Chunk types: `combined`, `appearance`, `font`, `dimension`, `display`, `layout`, `position`, `misc`, `subcomponents`.
215
+
216
+ ---
217
+
218
+ ### `cache(opts?): CacheStatus`
219
+
220
+ Cache state and performance metrics.
221
+
222
+ ```typescript
223
+ interface CacheStatus {
224
+ classes: {
225
+ active: string[];
226
+ unused: string[];
227
+ all: string[];
228
+ };
229
+ metrics: CacheMetrics | null;
230
+ }
231
+ ```
232
+
233
+ ```typescript
234
+ tastyDebug.cache();
235
+ // Output:
236
+ // Active: 42, Unused: 3
237
+ // Hits: 294, Misses: 18, Rate: 94.2%
238
+ ```
239
+
240
+ ---
241
+
242
+ ### `cleanup(opts?): void`
243
+
244
+ Forces immediate cleanup of all unused styles (those with `refCount = 0`).
245
+
246
+ ```typescript
247
+ tastyDebug.cleanup();
248
+ tastyDebug.cleanup({ root: shadowRoot });
249
+ ```
250
+
251
+ ---
252
+
253
+ ### `help(): void`
254
+
255
+ Prints a quick-start guide to the console.
256
+
257
+ ```typescript
258
+ tastyDebug.help();
259
+ ```
260
+
261
+ ---
262
+
263
+ ### `install(): void`
264
+
265
+ Attaches `tastyDebug` to `window.tastyDebug`. Called automatically in development mode.
266
+
267
+ ```typescript
268
+ import { tastyDebug } from '@tenphi/tasty';
269
+ tastyDebug.install();
270
+ ```
271
+
272
+ ---
273
+
274
+ ## Shadow DOM Support
275
+
276
+ All methods accept a `root` option to target a Shadow DOM:
277
+
278
+ ```typescript
279
+ const shadowRoot = host.shadowRoot;
280
+ tastyDebug.css('all', { root: shadowRoot });
281
+ tastyDebug.inspect('.shadow-component', { root: shadowRoot });
282
+ tastyDebug.summary({ root: shadowRoot });
283
+ ```
284
+
285
+ ---
286
+
287
+ ## Common Workflows
288
+
289
+ ### Debugging a component's styles
290
+
291
+ ```typescript
292
+ // 1. Inspect the element
293
+ tastyDebug.inspect('.my-button');
294
+
295
+ // 2. See CSS for a specific class
296
+ tastyDebug.css('t3a5f');
297
+
298
+ // 3. Compare original vs browser-parsed (dev mode)
299
+ tastyDebug.css('t3a5f', { source: true });
300
+ ```
301
+
302
+ ### Checking cache efficiency
303
+
304
+ ```typescript
305
+ const { metrics } = tastyDebug.cache({ raw: true });
306
+ if (metrics) {
307
+ const total = metrics.hits + metrics.misses;
308
+ const rate = total > 0 ? ((metrics.hits / total) * 100).toFixed(1) : 0;
309
+ console.log(`Cache hit rate: ${rate}%`);
310
+ }
311
+ ```
312
+
313
+ ### Monitoring CSS growth
314
+
315
+ ```typescript
316
+ const s = tastyDebug.summary({ raw: true });
317
+ console.log(`Total: ${s.totalRuleCount} rules, ${(s.totalCSSSize / 1024).toFixed(1)}KB`);
318
+ console.log(`Active: ${s.activeRuleCount} rules`);
319
+ console.log(`Unused: ${s.unusedRuleCount} rules`);
320
+ ```