@tenphi/cookbook 0.15.0 → 0.17.0

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 (46) hide show
  1. package/README.md +25 -0
  2. package/dist/config.d.ts +2 -2
  3. package/dist/index.d.ts +2 -2
  4. package/docs/ai-agents.md +61 -0
  5. package/docs/architecture.md +91 -0
  6. package/docs/authoring.mdx +86 -0
  7. package/docs/cli.md +88 -0
  8. package/docs/configuration.md +587 -0
  9. package/docs/content-sources.md +178 -0
  10. package/docs/customization-rules.md +154 -0
  11. package/docs/deployment.md +95 -0
  12. package/docs/examples.md +101 -0
  13. package/docs/getting-started.md +134 -0
  14. package/docs/index.md +74 -0
  15. package/docs/migration.md +36 -0
  16. package/docs/starlight-comparison.md +124 -0
  17. package/docs/theme-and-components.md +745 -0
  18. package/docs/upstream/glaze/LICENSE +21 -0
  19. package/docs/upstream/glaze/README.md +156 -0
  20. package/docs/upstream/glaze/docs/api.md +2021 -0
  21. package/docs/upstream/glaze/docs/methodology.md +686 -0
  22. package/docs/upstream/glaze/docs/migration.md +351 -0
  23. package/docs/upstream/glaze/docs/okhst.md +207 -0
  24. package/docs/upstream/manifest.json +18 -0
  25. package/docs/upstream/tasty/LICENSE +21 -0
  26. package/docs/upstream/tasty/README.md +685 -0
  27. package/docs/upstream/tasty/docs/README.md +39 -0
  28. package/docs/upstream/tasty/docs/adoption.md +323 -0
  29. package/docs/upstream/tasty/docs/ai-agents.md +229 -0
  30. package/docs/upstream/tasty/docs/comparison.md +448 -0
  31. package/docs/upstream/tasty/docs/configuration.md +823 -0
  32. package/docs/upstream/tasty/docs/debug.md +335 -0
  33. package/docs/upstream/tasty/docs/design-system.md +455 -0
  34. package/docs/upstream/tasty/docs/dsl.md +1021 -0
  35. package/docs/upstream/tasty/docs/getting-started.md +238 -0
  36. package/docs/upstream/tasty/docs/injector.md +634 -0
  37. package/docs/upstream/tasty/docs/methodology.md +648 -0
  38. package/docs/upstream/tasty/docs/migration-v3.md +285 -0
  39. package/docs/upstream/tasty/docs/pipeline.md +749 -0
  40. package/docs/upstream/tasty/docs/plugins.md +353 -0
  41. package/docs/upstream/tasty/docs/react-api.md +681 -0
  42. package/docs/upstream/tasty/docs/runtime-benchmarks.md +351 -0
  43. package/docs/upstream/tasty/docs/ssr.md +610 -0
  44. package/docs/upstream/tasty/docs/styles.md +677 -0
  45. package/docs/upstream/tasty/docs/tasty-static.md +582 -0
  46. package/package.json +12 -7
@@ -0,0 +1,335 @@
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
+ ### Environments Without a DOM
58
+
59
+ `tastyDebug` reads the document, so on a server — SSR, a Node REPL, a test
60
+ runner in the `node` environment — there is nothing for it to read. Every
61
+ method returns its empty result (`''`, an empty `InspectResult`, a summary of
62
+ zeroes, `metrics: null`) instead of throwing, and explains itself once with a
63
+ console warning. `{ raw: true }` suppresses that warning along with the rest of
64
+ the logging.
65
+
66
+ To see the styles a server render produced, read the `ServerStyleCollector`
67
+ instead — `collector.getCSS()` and `collector.getRenderedClassNames()`. See
68
+ [SSR](./ssr.md).
69
+
70
+ ---
71
+
72
+ ## API Reference
73
+
74
+ ### `css(target, opts?): string`
75
+
76
+ Retrieves CSS text for a given target. Logs the result with rule count and size.
77
+
78
+ **Targets:**
79
+
80
+ | Target | Description |
81
+ |---|---|
82
+ | `'all'` | All tasty CSS (component + global + raw) |
83
+ | `'active'` | CSS for classes currently in the DOM |
84
+ | `'unused'` | CSS for injected classes no element carries (cached but not rendered) |
85
+ | `'global'` | Only global CSS (from `injectGlobal`) |
86
+ | `'page'` | All CSS on the page (including non-tasty) |
87
+ | `'t3a5f'` | CSS for a specific tasty class (class names are `t` + base36 hash) |
88
+ | `['t3a5f', 't9k2']` | CSS for multiple tasty classes |
89
+ | `'.my-button'` | CSS affecting a DOM element (by selector) |
90
+ | `element` | CSS affecting a DOM element (by reference) |
91
+
92
+ **Extra options:**
93
+
94
+ ```typescript
95
+ interface CSSOptions extends DebugOptions {
96
+ prettify?: boolean; // Format output (default: true)
97
+ source?: boolean; // Read original CSS instead of live CSSOM (default: false, dev-mode only)
98
+ }
99
+ ```
100
+
101
+ ```typescript
102
+ // Active CSS with stats
103
+ tastyDebug.css('active');
104
+
105
+ // Specific class, silent
106
+ const css = tastyDebug.css('t3a5f', { raw: true });
107
+
108
+ // Compare original vs browser-parsed CSS (dev mode only)
109
+ tastyDebug.css('t3a5f'); // live CSSOM
110
+ tastyDebug.css('t3a5f', { source: true }); // original output
111
+
112
+ // Shadow DOM
113
+ tastyDebug.css('all', { root: shadowRoot });
114
+ ```
115
+
116
+ 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.
117
+
118
+ ---
119
+
120
+ ### `inspect(target, opts?): InspectResult`
121
+
122
+ Inspects a DOM element and returns detailed information about its tasty styles, including chunk assignments.
123
+
124
+ ```typescript
125
+ interface InspectResult {
126
+ element?: Element | null;
127
+ classes: string[]; // Tasty classes on the element
128
+ chunks: DebugChunkInfo[]; // Chunk assignment per class
129
+ css: string; // Prettified CSS
130
+ size: number; // CSS size in characters
131
+ rules: number; // Number of CSS rule blocks
132
+ }
133
+
134
+ interface DebugChunkInfo {
135
+ className: string;
136
+ chunkName: string | null; // e.g., 'appearance', 'font', 'dimension'
137
+ }
138
+ ```
139
+
140
+ ```typescript
141
+ tastyDebug.inspect('.my-card');
142
+ // Logs: inspect div — 3 classes, 5 rules, 1.2KB
143
+ // Chunks: t3a5f→appearance, t9k2→font, tb71→dimension
144
+
145
+ // Silent
146
+ const result = tastyDebug.inspect('.my-card', { raw: true });
147
+ console.log(result.classes); // ['t3a5f', 't9k2', 'tb71']
148
+ console.log(result.rules); // 5
149
+ ```
150
+
151
+ ---
152
+
153
+ ### `summary(opts?): Summary`
154
+
155
+ One-shot overview of the entire Tasty CSS state. Logs a compact report.
156
+
157
+ ```typescript
158
+ interface Summary {
159
+ activeClasses: string[];
160
+ unusedClasses: string[];
161
+ totalStyledClasses: string[];
162
+
163
+ activeCSSSize: number;
164
+ unusedCSSSize: number;
165
+ globalCSSSize: number;
166
+ rawCSSSize: number;
167
+ keyframesCSSSize: number;
168
+ propertyCSSSize: number;
169
+ totalCSSSize: number;
170
+
171
+ activeRuleCount: number;
172
+ unusedRuleCount: number;
173
+ globalRuleCount: number;
174
+ rawRuleCount: number;
175
+ keyframesRuleCount: number;
176
+ propertyRuleCount: number;
177
+ totalRuleCount: number;
178
+
179
+ metrics: CacheMetrics | null;
180
+ definedProperties: string[];
181
+ definedKeyframes: { name: string; refCount: number }[];
182
+ chunkBreakdown: ChunkBreakdown;
183
+ }
184
+ ```
185
+
186
+ ```typescript
187
+ // Logged automatically
188
+ tastyDebug.summary();
189
+ // Output:
190
+ // Active: 42 classes, 186 rules, 12.4KB
191
+ // Unused: 3 classes, 8 rules, 0.5KB
192
+ // Global: 12 rules, 1.1KB
193
+ // Total: 45 classes, 206 rules, 14.0KB
194
+ // Cache: 94.2% hit rate (312 lookups)
195
+
196
+ // Silent
197
+ const s = tastyDebug.summary({ raw: true });
198
+ console.log(s.totalRuleCount); // 206
199
+ ```
200
+
201
+ ---
202
+
203
+ ### `chunks(opts?): ChunkBreakdown`
204
+
205
+ Breakdown of styles by chunk type.
206
+
207
+ ```typescript
208
+ interface ChunkBreakdown {
209
+ byChunk: Record<string, {
210
+ classes: string[];
211
+ cssSize: number;
212
+ ruleCount: number;
213
+ }>;
214
+ totalChunkTypes: number;
215
+ totalClasses: number;
216
+ }
217
+ ```
218
+
219
+ ```typescript
220
+ tastyDebug.chunks();
221
+ // Output:
222
+ // appearance: 24 cls, 48 rules, 3.2KB
223
+ // font: 18 cls, 18 rules, 1.1KB
224
+ // dimension: 31 cls, 45 rules, 2.4KB
225
+ ```
226
+
227
+ Chunk types: `combined`, `appearance`, `font`, `dimension`, `display`, `layout`, `position`, `misc`, `subcomponents`.
228
+
229
+ ---
230
+
231
+ ### `cache(opts?): CacheStatus`
232
+
233
+ Cache state and performance metrics.
234
+
235
+ ```typescript
236
+ interface CacheStatus {
237
+ classes: {
238
+ active: string[];
239
+ unused: string[];
240
+ all: string[];
241
+ };
242
+ metrics: CacheMetrics | null;
243
+ }
244
+ ```
245
+
246
+ ```typescript
247
+ tastyDebug.cache();
248
+ // Output:
249
+ // Active: 42, Unused: 3
250
+ // Hits: 294, Misses: 18, Rate: 94.2%
251
+ ```
252
+
253
+ ---
254
+
255
+ ### `cleanup(opts?): void`
256
+
257
+ Removes every injected style that is neither carried by an element nor pinned by
258
+ an outstanding `inject()` handle — the same set `summary()` reports as unused.
259
+ Equivalent to `gc({ force: true })`.
260
+
261
+ ```typescript
262
+ tastyDebug.cleanup();
263
+ tastyDebug.cleanup({ root: shadowRoot });
264
+ ```
265
+
266
+ ---
267
+
268
+ ### `help(): void`
269
+
270
+ Prints a quick-start guide to the console.
271
+
272
+ ```typescript
273
+ tastyDebug.help();
274
+ ```
275
+
276
+ ---
277
+
278
+ ### `install(): void`
279
+
280
+ Attaches `tastyDebug` to `window.tastyDebug`. Called automatically in development mode.
281
+
282
+ ```typescript
283
+ import { tastyDebug } from '@tenphi/tasty';
284
+ tastyDebug.install();
285
+ ```
286
+
287
+ ---
288
+
289
+ ## Shadow DOM Support
290
+
291
+ All methods accept a `root` option to target a Shadow DOM:
292
+
293
+ ```typescript
294
+ const shadowRoot = host.shadowRoot;
295
+ tastyDebug.css('all', { root: shadowRoot });
296
+ tastyDebug.inspect('.shadow-component', { root: shadowRoot });
297
+ tastyDebug.summary({ root: shadowRoot });
298
+ ```
299
+
300
+ ---
301
+
302
+ ## Common Workflows
303
+
304
+ ### Debugging a component's styles
305
+
306
+ ```typescript
307
+ // 1. Inspect the element
308
+ tastyDebug.inspect('.my-button');
309
+
310
+ // 2. See CSS for a specific class
311
+ tastyDebug.css('t3a5f');
312
+
313
+ // 3. Compare original vs browser-parsed (dev mode)
314
+ tastyDebug.css('t3a5f', { source: true });
315
+ ```
316
+
317
+ ### Checking cache efficiency
318
+
319
+ ```typescript
320
+ const { metrics } = tastyDebug.cache({ raw: true });
321
+ if (metrics) {
322
+ const total = metrics.hits + metrics.misses;
323
+ const rate = total > 0 ? ((metrics.hits / total) * 100).toFixed(1) : 0;
324
+ console.log(`Cache hit rate: ${rate}%`);
325
+ }
326
+ ```
327
+
328
+ ### Monitoring CSS growth
329
+
330
+ ```typescript
331
+ const s = tastyDebug.summary({ raw: true });
332
+ console.log(`Total: ${s.totalRuleCount} rules, ${(s.totalCSSSize / 1024).toFixed(1)}KB`);
333
+ console.log(`Active: ${s.activeRuleCount} rules`);
334
+ console.log(`Unused: ${s.unusedRuleCount} rules`);
335
+ ```