@tenphi/tasty 0.0.0-snapshot.1d29633 → 0.0.0-snapshot.1f1c00a

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 (122) hide show
  1. package/README.md +152 -134
  2. package/dist/{babel-Cg-mJV_t.d.ts → babel-rZcEwPLM.d.ts} +2 -3
  3. package/dist/chunks/async-storage-CG5HnUT5.js +20 -0
  4. package/dist/chunks/async-storage-CG5HnUT5.js.map +1 -0
  5. package/dist/chunks/build-config-CL4eRu2z.js +42 -0
  6. package/dist/chunks/build-config-CL4eRu2z.js.map +1 -0
  7. package/dist/{collector-BMT05AmU.js → chunks/collector-D2ARGT2L.js} +21 -117
  8. package/dist/chunks/collector-D2ARGT2L.js.map +1 -0
  9. package/dist/chunks/config-engine-DEmmPPdp.js +272 -0
  10. package/dist/chunks/config-engine-DEmmPPdp.js.map +1 -0
  11. package/dist/chunks/css-definitions-DotDkIXt.js +876 -0
  12. package/dist/chunks/css-definitions-DotDkIXt.js.map +1 -0
  13. package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
  14. package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
  15. package/dist/chunks/debug-D8pg9RGI.js +502 -0
  16. package/dist/chunks/debug-D8pg9RGI.js.map +1 -0
  17. package/dist/chunks/dsl-DRhFWQzo.js +1378 -0
  18. package/dist/chunks/dsl-DRhFWQzo.js.map +1 -0
  19. package/dist/chunks/hydration-TRcz5vnk.js +41 -0
  20. package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
  21. package/dist/chunks/react-runtime-BpxlOTbO.js +562 -0
  22. package/dist/chunks/react-runtime-BpxlOTbO.js.map +1 -0
  23. package/dist/chunks/runtime-engine-CKFXUH-A.js +2416 -0
  24. package/dist/chunks/runtime-engine-CKFXUH-A.js.map +1 -0
  25. package/dist/chunks/runtime-state-BxaLhVdP.js +127 -0
  26. package/dist/chunks/runtime-state-BxaLhVdP.js.map +1 -0
  27. package/dist/{merge-styles-CkAcnd0Z.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
  28. package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
  29. package/dist/chunks/style-engine-BBbBuSkT.js +5260 -0
  30. package/dist/chunks/style-engine-BBbBuSkT.js.map +1 -0
  31. package/dist/{css-writer-b02uBqNF.js → chunks/zero-engine-gJrKBRiw.js} +6 -121
  32. package/dist/chunks/zero-engine-gJrKBRiw.js.map +1 -0
  33. package/dist/{collector-BFuqdF2F.d.ts → collector-w4mBj5gd.d.ts} +23 -4
  34. package/dist/{config-DmFxnBxg.d.ts → config-CZWCzBr6.d.ts} +171 -72
  35. package/dist/core/index.d.ts +5 -5
  36. package/dist/core/index.js +9 -6
  37. package/dist/{index-D1nMkpUe.d.ts → index-G9JuwM9p.d.ts} +263 -247
  38. package/dist/index.d.ts +5 -5
  39. package/dist/index.js +11 -921
  40. package/dist/{merge-styles-Cx_6ySBv.d.ts → merge-styles-VXwJ0Frr.d.ts} +2 -3
  41. package/dist/ssr/astro-client.d.ts +1 -1
  42. package/dist/ssr/astro-client.js +1 -14
  43. package/dist/ssr/astro-client.js.map +1 -1
  44. package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
  45. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  46. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  47. package/dist/ssr/astro-middleware-extract.d.ts +10 -0
  48. package/dist/ssr/astro-middleware-extract.js +9 -0
  49. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  50. package/dist/ssr/astro-middleware-static.d.ts +3 -2
  51. package/dist/ssr/astro-middleware-static.js +0 -11
  52. package/dist/ssr/astro-middleware-static.js.map +1 -1
  53. package/dist/ssr/astro-middleware.d.ts +3 -2
  54. package/dist/ssr/astro-middleware.js +0 -12
  55. package/dist/ssr/astro-middleware.js.map +1 -1
  56. package/dist/ssr/astro.d.ts +40 -6
  57. package/dist/ssr/astro.js +157 -93
  58. package/dist/ssr/astro.js.map +1 -1
  59. package/dist/ssr/index.d.ts +10 -11
  60. package/dist/ssr/index.js +4 -4
  61. package/dist/ssr/index.js.map +1 -1
  62. package/dist/ssr/next-config.d.ts +64 -0
  63. package/dist/ssr/next-config.js +128 -0
  64. package/dist/ssr/next-config.js.map +1 -0
  65. package/dist/ssr/next.d.ts +9 -8
  66. package/dist/ssr/next.js +29 -43
  67. package/dist/ssr/next.js.map +1 -1
  68. package/dist/static/index.d.ts +8 -9
  69. package/dist/static/index.js +4 -22
  70. package/dist/static/index.js.map +1 -1
  71. package/dist/static/inject.d.ts +1 -2
  72. package/dist/{index-LC3O3Jj4.d.ts → types-JEY8PVYP.d.ts} +862 -811
  73. package/dist/zero/babel.d.ts +1 -1
  74. package/dist/zero/babel.js +41 -107
  75. package/dist/zero/babel.js.map +1 -1
  76. package/dist/zero/index.d.ts +6 -7
  77. package/dist/zero/index.js +1 -1
  78. package/dist/zero/next.d.ts +3 -5
  79. package/dist/zero/next.js +0 -31
  80. package/dist/zero/next.js.map +1 -1
  81. package/docs/README.md +13 -8
  82. package/docs/adoption.md +56 -31
  83. package/docs/ai-agents.md +107 -80
  84. package/docs/comparison.md +69 -40
  85. package/docs/configuration.md +179 -114
  86. package/docs/debug.md +19 -7
  87. package/docs/design-system.md +41 -22
  88. package/docs/dsl.md +310 -201
  89. package/docs/getting-started.md +64 -41
  90. package/docs/injector.md +63 -26
  91. package/docs/methodology.md +44 -38
  92. package/docs/migration-v3.md +49 -49
  93. package/docs/pipeline.md +32 -8
  94. package/docs/plugins.md +38 -34
  95. package/docs/react-api.md +67 -44
  96. package/docs/runtime-benchmarks.md +388 -0
  97. package/docs/ssr.md +219 -61
  98. package/docs/styles.md +95 -18
  99. package/docs/tasty-static.md +138 -105
  100. package/package.json +104 -33
  101. package/dist/async-storage-DKK-wTD4.js +0 -44
  102. package/dist/async-storage-DKK-wTD4.js.map +0 -1
  103. package/dist/collector-BMT05AmU.js.map +0 -1
  104. package/dist/config-DF93rL3u.js +0 -12661
  105. package/dist/config-DF93rL3u.js.map +0 -1
  106. package/dist/context-CA8YKeMn.js +0 -24
  107. package/dist/context-CA8YKeMn.js.map +0 -1
  108. package/dist/core-B5ybnMP1.js +0 -1529
  109. package/dist/core-B5ybnMP1.js.map +0 -1
  110. package/dist/css-writer-b02uBqNF.js.map +0 -1
  111. package/dist/format-global-rules-DklyaXv-.js +0 -22
  112. package/dist/format-global-rules-DklyaXv-.js.map +0 -1
  113. package/dist/format-rules-Cs4e3M9m.js +0 -130
  114. package/dist/format-rules-Cs4e3M9m.js.map +0 -1
  115. package/dist/hydrate-aaUSNJZJ.js +0 -37
  116. package/dist/hydrate-aaUSNJZJ.js.map +0 -1
  117. package/dist/index.js.map +0 -1
  118. package/dist/keyframes-BedEzEXk.js +0 -424
  119. package/dist/keyframes-BedEzEXk.js.map +0 -1
  120. package/dist/merge-styles-CkAcnd0Z.js.map +0 -1
  121. package/dist/resolve-recipes-CiyLtJG9.js +0 -144
  122. package/dist/resolve-recipes-CiyLtJG9.js.map +0 -1
@@ -1,1529 +0,0 @@
1
- import { $t as overrideColorAlpha, G as StyleInjector, Ht as normalizeColorTokenValue, It as registerLocalFunctionPolyfills, J as hasLocalCounterStyle, K as extractLocalCounterStyle, Mt as formatFunctionRule, Nt as hasLocalFunctions, Pt as parseFunctionName, Q as hasLocalFontFace, Wt as parseStyle, X as fontFaceContentHash, Y as extractLocalFontFace, Z as formatFontFaceRule, Zt as isDevEnv, _ as isFunctionsPolyfillEnabled, _t as hashString, bt as hasLocalProperties, c as getGlobalInjector, et as STYLE_HANDLER_MAP, f as getNamePrefix, ft as makeClassName, ht as tastyClassRegex, it as PropertyTypeResolver, jt as extractLocalFunctions, l as getGlobalKeyframes, n as getConfig, p as hasGlobalKeyframes, q as formatCounterStyleRule, rt as createStyle, sn as normalizeDslName, tn as Lru, v as isTestEnvironment, vt as extractLocalProperties, wt as CHUNK_NAMES, xt as parsePropertyToken, y as markStylesGenerated, z as camelToKebab } from "./config-DF93rL3u.js";
2
- import { a as mergeKeyframes, c as generateChunkCacheKey, i as hasLocalKeyframes, l as categorizeStyleKeys, n as extractLocalKeyframes, o as replaceAnimationNames, r as filterUsedKeyframes, s as renderStylesForChunk, t as extractAnimationNamesFromStyles } from "./keyframes-BedEzEXk.js";
3
- import { n as formatPropertyCSS, r as getRegisteredSSRCollector, t as formatRules } from "./format-rules-Cs4e3M9m.js";
4
- import { t as resolveRecipes } from "./resolve-recipes-CiyLtJG9.js";
5
- import { cache } from "react";
6
- //#region src/injector/chunk-sheet-registry.ts
7
- /**
8
- * Global registry mapping CSS content hashes to shared constructable
9
- * CSSStyleSheet objects with reference counting.
10
- *
11
- * Multiple shadow roots adopting the same chunk share a single underlying
12
- * stylesheet object — parse once, adopt everywhere.
13
- */
14
- var ChunkSheetRegistry = class {
15
- sheets = /* @__PURE__ */ new Map();
16
- sheetToHash = /* @__PURE__ */ new WeakMap();
17
- /**
18
- * Get or create a CSSStyleSheet for the given CSS text.
19
- * Increments refCount. Uses content hash as the dedup key.
20
- */
21
- acquire(cssText) {
22
- const hash = hashString(cssText);
23
- const existing = this.sheets.get(hash);
24
- if (existing) {
25
- existing.refCount++;
26
- return existing.sheet;
27
- }
28
- const sheet = new CSSStyleSheet();
29
- sheet.replaceSync(cssText);
30
- const entry = {
31
- sheet,
32
- cssText,
33
- refCount: 1
34
- };
35
- this.sheets.set(hash, entry);
36
- this.sheetToHash.set(sheet, hash);
37
- return sheet;
38
- }
39
- /**
40
- * Decrement refCount for a sheet. When refCount reaches 0,
41
- * the sheet is removed from the registry.
42
- */
43
- release(sheet) {
44
- const hash = this.sheetToHash.get(sheet);
45
- if (!hash) return;
46
- const entry = this.sheets.get(hash);
47
- if (!entry) return;
48
- entry.refCount--;
49
- if (entry.refCount <= 0) {
50
- this.sheets.delete(hash);
51
- this.sheetToHash.delete(sheet);
52
- }
53
- }
54
- /**
55
- * Bulk acquire — returns an array of CSSStyleSheet in the same order.
56
- */
57
- acquireAll(cssTexts) {
58
- return cssTexts.map((text) => this.acquire(text));
59
- }
60
- /**
61
- * Bulk release — decrements refCount for each sheet.
62
- */
63
- releaseAll(sheets) {
64
- for (const sheet of sheets) this.release(sheet);
65
- }
66
- /** Number of unique sheets currently held. */
67
- get size() {
68
- return this.sheets.size;
69
- }
70
- };
71
- /** Module-level singleton shared across the entire application. */
72
- const chunkSheetRegistry = new ChunkSheetRegistry();
73
- //#endregion
74
- //#region src/injector/index.ts
75
- /**
76
- * Inject styles and return className with dispose function
77
- */
78
- function inject(rules, options) {
79
- const injector = getGlobalInjector();
80
- markStylesGenerated();
81
- return injector.inject(rules, options);
82
- }
83
- /**
84
- * Inject global rules that should not reserve tasty class names
85
- */
86
- function injectGlobal(rules, options) {
87
- return getGlobalInjector().injectGlobal(rules, options);
88
- }
89
- /**
90
- * Inject raw CSS text directly without parsing
91
- * This is a low-overhead method for injecting raw CSS that doesn't need tasty processing.
92
- * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking.
93
- *
94
- * @example
95
- * ```tsx
96
- * // Inject raw CSS
97
- * const { dispose } = injectRawCSS(`
98
- * body { margin: 0; padding: 0; }
99
- * .my-class { color: red; }
100
- * `);
101
- *
102
- * // Later, remove the injected CSS
103
- * dispose();
104
- * ```
105
- */
106
- function injectRawCSS(css, options) {
107
- return getGlobalInjector().injectRawCSS(css, options);
108
- }
109
- /**
110
- * Get raw CSS text for SSR
111
- */
112
- function getRawCSSText(options) {
113
- return getGlobalInjector().getRawCSSText(options);
114
- }
115
- /**
116
- * Inject keyframes and return object with toString() and dispose()
117
- */
118
- function keyframes(steps, nameOrOptions) {
119
- return getGlobalInjector().keyframes(steps, nameOrOptions);
120
- }
121
- /**
122
- * Define a CSS @property custom property.
123
- * This enables advanced features like animating custom properties.
124
- *
125
- * Note: @property rules are global and persistent once defined.
126
- * Re-registering the same property name is a no-op.
127
- *
128
- * @param name - The custom property name (must start with --)
129
- * @param options - Property configuration
130
- *
131
- * @example
132
- * ```ts
133
- * // Define a color property that can be animated
134
- * property('--my-color', {
135
- * syntax: '<color>',
136
- * initialValue: 'red',
137
- * });
138
- *
139
- * // Define an angle property
140
- * property('--rotation', {
141
- * syntax: '<angle>',
142
- * inherits: false,
143
- * initialValue: '0deg',
144
- * });
145
- * ```
146
- */
147
- function property(name, options) {
148
- return getGlobalInjector().property(name, options);
149
- }
150
- /**
151
- * Check if a CSS @property has already been defined
152
- *
153
- * @param name - The custom property name to check
154
- * @param options - Options including root
155
- */
156
- function isPropertyDefined(name, options) {
157
- return getGlobalInjector().isPropertyDefined(name, options);
158
- }
159
- /**
160
- * Inject a CSS @font-face rule.
161
- *
162
- * Permanent and global — no dispose or ref-counting.
163
- * Deduplicates by content hash (family + descriptors).
164
- */
165
- function fontFace(family, descriptors, options) {
166
- return getGlobalInjector().fontFace(family, descriptors, options);
167
- }
168
- /**
169
- * Inject a CSS @counter-style rule.
170
- *
171
- * Permanent and global — no dispose or ref-counting. Deduplicates by name and
172
- * overrides an existing rule by default. Pass `weak: true` for global
173
- * `configure()` definitions, which never clobber an existing rule.
174
- */
175
- function counterStyle(name, descriptors, options) {
176
- return getGlobalInjector().counterStyle(name, descriptors, options);
177
- }
178
- /**
179
- * Inject a CSS @function rule (custom function).
180
- *
181
- * Permanent and global — no dispose or ref-counting. Deduplicates by function
182
- * name and overrides an existing rule by default. Pass `weak: true` for global
183
- * `configure()` definitions, which never clobber an existing rule.
184
- *
185
- * @param name - The function name (`$$name`, `$name`, or `--name`)
186
- * @param definition - Function definition (args, returns, result, local vars)
187
- *
188
- * @example
189
- * ```ts
190
- * func('$$negative', { args: ['$value'], result: '(-1 * $value)' });
191
- * ```
192
- */
193
- function func(name, definition, options) {
194
- return getGlobalInjector().func(name, definition, options);
195
- }
196
- /**
197
- * Get CSS text from all sheets (for SSR)
198
- */
199
- function getCSSText(options) {
200
- return getGlobalInjector().getCSSText(options);
201
- }
202
- /**
203
- * Collect only CSS used by a rendered subtree (like jest-styled-components).
204
- * Pass the container returned by render(...).
205
- */
206
- function getCSSTextForNode(node, options) {
207
- const classRegex = tastyClassRegex(getNamePrefix());
208
- const classSet = /* @__PURE__ */ new Set();
209
- const readClasses = (el) => {
210
- const cls = el.getAttribute("class");
211
- if (!cls) return;
212
- for (const token of cls.split(/\s+/)) if (classRegex.test(token)) classSet.add(token);
213
- };
214
- if (node.getAttribute) readClasses(node);
215
- const elements = node.querySelectorAll ? node.querySelectorAll("[class]") : [];
216
- if (elements) elements.forEach(readClasses);
217
- return getGlobalInjector().getCSSTextForClasses(classSet, options);
218
- }
219
- /**
220
- * Force cleanup of unused rules
221
- */
222
- function cleanup(root) {
223
- return getGlobalInjector().cleanup(root);
224
- }
225
- /**
226
- * Record a render-time usage hit for one or more classNames.
227
- * Used internally by computeStyles and tasty() to track usage for GC.
228
- * When the global touch counter reaches `touchInterval`, schedules GC.
229
- */
230
- function touch(className, options) {
231
- if (!getConfig().gc) return;
232
- getGlobalInjector().touch(className, options);
233
- }
234
- /**
235
- * Synchronous garbage collection of unused styles.
236
- * Evicts the oldest unused styles when usageMap exceeds capacity.
237
- * With `{ force: true }`, removes ALL unused styles regardless of capacity.
238
- *
239
- * @returns Number of styles evicted.
240
- */
241
- function gc(options) {
242
- return getGlobalInjector().gc(options);
243
- }
244
- /**
245
- * Get the global injector instance for debugging
246
- */
247
- const injector = { get instance() {
248
- return getGlobalInjector();
249
- } };
250
- /**
251
- * Destroy all resources and clean up
252
- */
253
- function destroy(root) {
254
- return getGlobalInjector().destroy(root);
255
- }
256
- /**
257
- * Create a new isolated injector instance
258
- */
259
- function createInjector(config = {}) {
260
- return new StyleInjector({
261
- ...getConfig(),
262
- forceTextInjection: config.forceTextInjection ?? isTestEnvironment(),
263
- ...config
264
- });
265
- }
266
- //#endregion
267
- //#region src/rsc-cache.ts
268
- /**
269
- * Shared RSC (React Server Components) inline style cache.
270
- *
271
- * Uses React.cache for per-request memoization in Server Components.
272
- * Both computeStyles() and standalone style functions (useGlobalStyles,
273
- * useRawCSS, useKeyframes, useProperty, useFontFace, useCounterStyle)
274
- * share this cache so that CSS accumulated by standalone functions is
275
- * flushed into inline <style> tags by the next tasty() component.
276
- */
277
- /**
278
- * Per-request RSC style cache using React.cache.
279
- * React.cache provides per-request memoization in Server Components,
280
- * so each request gets its own isolated cache.
281
- */
282
- const getRSCCache = cache(() => ({
283
- cacheKeyToClassName: /* @__PURE__ */ new Map(),
284
- emittedKeys: /* @__PURE__ */ new Set(),
285
- internalsEmitted: false,
286
- pendingCSS: [],
287
- keyToIndex: /* @__PURE__ */ new Map(),
288
- generatedNames: /* @__PURE__ */ new Map()
289
- }));
290
- function rscAllocateClassName(rscCache, cacheKey) {
291
- const existing = rscCache.cacheKeyToClassName.get(cacheKey);
292
- if (existing) return {
293
- className: existing,
294
- isNew: false
295
- };
296
- const className = makeClassName(getNamePrefix(), hashString(cacheKey));
297
- rscCache.cacheKeyToClassName.set(cacheKey, className);
298
- return {
299
- className,
300
- isNew: true
301
- };
302
- }
303
- /**
304
- * Flush any pending CSS accumulated by standalone functions.
305
- * Returns the CSS string and clears the buffer.
306
- */
307
- function flushPendingCSS(rscCache) {
308
- if (rscCache.pendingCSS.length === 0) return "";
309
- const css = rscCache.pendingCSS.join("\n");
310
- rscCache.pendingCSS.length = 0;
311
- rscCache.keyToIndex.clear();
312
- return css;
313
- }
314
- /**
315
- * Push CSS into the RSC pending buffer with dedup via emittedKeys.
316
- * Returns true if the CSS was added, false if it was already emitted.
317
- *
318
- * Pass `replace` for slot-keyed entries (an explicit `id`), where the last write
319
- * must win to match the client's update-tracking behavior. If the slot has
320
- * already been flushed into a `<style>` tag the new CSS is appended instead,
321
- * which still wins by cascade order.
322
- */
323
- function pushRSCCSS(rscCache, key, css, replace) {
324
- if (replace) {
325
- const pendingIndex = rscCache.keyToIndex.get(key);
326
- if (pendingIndex !== void 0) {
327
- rscCache.pendingCSS[pendingIndex] = css;
328
- return true;
329
- }
330
- } else if (rscCache.emittedKeys.has(key)) return false;
331
- rscCache.emittedKeys.add(key);
332
- rscCache.keyToIndex.set(key, rscCache.pendingCSS.length);
333
- rscCache.pendingCSS.push(css);
334
- return true;
335
- }
336
- /**
337
- * Determine the current style injection target.
338
- * Centralizes the three-way detection (SSR collector / RSC cache / client DOM)
339
- * used by all style functions.
340
- */
341
- function getStyleTarget() {
342
- const collector = getRegisteredSSRCollector();
343
- if (collector) return {
344
- mode: "ssr",
345
- collector
346
- };
347
- if (typeof document === "undefined") return {
348
- mode: "rsc",
349
- cache: getRSCCache()
350
- };
351
- return { mode: "client" };
352
- }
353
- //#endregion
354
- //#region src/ssr/collect-auto-properties.ts
355
- /**
356
- * Scan rendered rules for auto-inferable custom properties and emit
357
- * @property CSS via the provided callback.
358
- */
359
- function scanAndEmitAutoProperties(rules, styles, emit) {
360
- const registered = /* @__PURE__ */ new Set();
361
- if (styles) {
362
- const localProps = styles["@property"];
363
- if (localProps && typeof localProps === "object") for (const token of Object.keys(localProps)) {
364
- const parsed = parsePropertyToken(token);
365
- if (parsed.isValid) registered.add(parsed.cssName);
366
- }
367
- }
368
- const resolver = new PropertyTypeResolver();
369
- for (const rule of rules) {
370
- if (!rule.declarations) continue;
371
- resolver.scanDeclarations(rule.declarations, (name) => registered.has(name), (name, syntax, initialValue) => {
372
- registered.add(name);
373
- const css = formatPropertyCSS(name, {
374
- syntax,
375
- inherits: true,
376
- initialValue
377
- });
378
- if (css) emit(name, css);
379
- });
380
- }
381
- }
382
- /**
383
- * Scan rendered rules for custom property declarations and collect
384
- * auto-inferred @property rules via the SSR collector.
385
- *
386
- * @param rules - Rendered style rules containing CSS declarations
387
- * @param collector - SSR collector to emit @property CSS into
388
- * @param styles - Original styles object (used to skip explicit @property)
389
- */
390
- function collectAutoInferredProperties(rules, collector, styles) {
391
- scanAndEmitAutoProperties(rules, styles, (name, css) => {
392
- collector.collectProperty(`__auto:${name}`, css);
393
- });
394
- }
395
- /**
396
- * RSC variant: scan rendered rules and push auto-inferred @property CSS
397
- * into the RSC pending buffer.
398
- */
399
- function collectAutoInferredPropertiesRSC(rules, rscCache, styles) {
400
- scanAndEmitAutoProperties(rules, styles, (name, css) => {
401
- pushRSCCSS(rscCache, `__auto:${name}`, css);
402
- });
403
- }
404
- //#endregion
405
- //#region src/ssr/format-keyframes.ts
406
- /**
407
- * Convert keyframes steps to a CSS string.
408
- * Replicates SheetManager.stepsToCSS() without the class instance.
409
- */
410
- function stepsToCSS(steps) {
411
- const rules = [];
412
- for (const [key, value] of Object.entries(steps)) {
413
- if (typeof value === "string") {
414
- rules.push(`${key} { ${value.trim()} }`);
415
- continue;
416
- }
417
- const styleMap = value || {};
418
- const styleNames = Object.keys(styleMap).sort();
419
- const handlerQueue = [];
420
- const seenHandlers = /* @__PURE__ */ new Set();
421
- styleNames.forEach((styleName) => {
422
- let handlers = STYLE_HANDLER_MAP[styleName];
423
- if (!handlers) handlers = STYLE_HANDLER_MAP[styleName] = [createStyle(styleName)];
424
- handlers.forEach((handler) => {
425
- if (!seenHandlers.has(handler)) {
426
- seenHandlers.add(handler);
427
- handlerQueue.push(handler);
428
- }
429
- });
430
- });
431
- const declarationPairs = [];
432
- handlerQueue.forEach((handler) => {
433
- const result = handler(handler.__lookupStyles.reduce((acc, name) => {
434
- const v = styleMap[name];
435
- if (v !== void 0) acc[name] = v;
436
- return acc;
437
- }, {}));
438
- if (!result) return;
439
- (Array.isArray(result) ? result : [result]).forEach((cssMap) => {
440
- if (!cssMap || typeof cssMap !== "object") return;
441
- const { $: _$, ...props } = cssMap;
442
- Object.entries(props).forEach(([prop, val]) => {
443
- if (val == null || val === "") return;
444
- if (Array.isArray(val)) val.forEach((v) => {
445
- if (v != null && v !== "") declarationPairs.push({
446
- prop,
447
- value: String(v)
448
- });
449
- });
450
- else declarationPairs.push({
451
- prop,
452
- value: String(val)
453
- });
454
- });
455
- });
456
- });
457
- const declarations = declarationPairs.map((d) => `${d.prop}: ${d.value}`).join("; ");
458
- rules.push(`${key} { ${declarations.trim()} }`);
459
- }
460
- return rules.join(" ");
461
- }
462
- /**
463
- * Format a @keyframes rule as a CSS string.
464
- */
465
- function formatKeyframesCSS(name, steps) {
466
- return `@keyframes ${name} { ${stepsToCSS(steps)} }`;
467
- }
468
- //#endregion
469
- //#region src/utils/has-keys.ts
470
- /**
471
- * Check if an object has any own enumerable keys.
472
- * Avoids the array allocation of Object.keys(obj).length > 0.
473
- */
474
- function hasKeys(obj) {
475
- for (const _ in obj) return true;
476
- return false;
477
- }
478
- //#endregion
479
- //#region src/compute-styles.ts
480
- /**
481
- * Hook-free, synchronous style computation.
482
- *
483
- * Extracts the core logic from useStyles() into a plain function that can
484
- * be called during React render without any hooks. Three code paths:
485
- *
486
- * 1. SSR collector — styles collected via ServerStyleCollector
487
- * 2. Client inject — styles injected synchronously into the DOM
488
- * 3. RSC inline — styles returned as CSS strings for inline <style> emission
489
- *
490
- * This enables tasty() components to work as React Server Components.
491
- */
492
- const EMPTY_RESULT = { className: "" };
493
- /**
494
- * Mark internals as emitted for this RSC request.
495
- *
496
- * Internals (tokens, @property, @font-face, @counter-style) are emitted
497
- * exclusively by the SSR collector via ServerStyleCollector.collectInternals().
498
- * The SSR path is reliable because TastyRegistry is always present as a
499
- * client component in the root layout, guaranteeing SSR runs for every page.
500
- *
501
- * Previously this function also emitted internals and coordinated with SSR
502
- * via a globalThis flag, but that flag leaked across requests in the same
503
- * Node.js process, causing pages without RSC-rendered tasty components
504
- * (e.g. the playground route) to lose all token CSS.
505
- */
506
- function collectInternalsRSC(rscCache) {
507
- if (rscCache.internalsEmitted) return "";
508
- rscCache.internalsEmitted = true;
509
- return "";
510
- }
511
- /**
512
- * Collect per-component ancillary CSS (keyframes, @property, font-face,
513
- * counter-style) for RSC mode.
514
- */
515
- function collectAncillaryRSC(rscCache, styles) {
516
- const parts = [];
517
- const usedKf = getUsedKeyframes(styles);
518
- if (usedKf) for (const [name, steps] of Object.entries(usedKf)) {
519
- const key = `__kf:${name}:${JSON.stringify(steps)}`;
520
- if (!rscCache.emittedKeys.has(key)) {
521
- rscCache.emittedKeys.add(key);
522
- parts.push(formatKeyframesCSS(name, steps));
523
- }
524
- }
525
- if (hasLocalProperties(styles)) {
526
- const localProperties = extractLocalProperties(styles);
527
- if (localProperties) for (const [token, definition] of Object.entries(localProperties)) {
528
- const key = `__prop:${token}`;
529
- if (!rscCache.emittedKeys.has(key)) {
530
- rscCache.emittedKeys.add(key);
531
- const css = formatPropertyCSS(token, definition);
532
- if (css) parts.push(css);
533
- }
534
- }
535
- }
536
- if (hasLocalFontFace(styles)) {
537
- const localFontFace = extractLocalFontFace(styles);
538
- if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
539
- const descriptors = Array.isArray(input) ? input : [input];
540
- for (const desc of descriptors) {
541
- const key = `__ff:${fontFaceContentHash(family, desc)}`;
542
- if (!rscCache.emittedKeys.has(key)) {
543
- rscCache.emittedKeys.add(key);
544
- parts.push(formatFontFaceRule(family, desc));
545
- }
546
- }
547
- }
548
- }
549
- if (hasLocalCounterStyle(styles)) {
550
- const localCounterStyle = extractLocalCounterStyle(styles);
551
- if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) {
552
- const key = `__cs:${name}:${JSON.stringify(descriptors)}`;
553
- if (!rscCache.emittedKeys.has(key)) {
554
- rscCache.emittedKeys.add(key);
555
- parts.push(formatCounterStyleRule(name, descriptors));
556
- }
557
- }
558
- }
559
- if (!isFunctionsPolyfillEnabled() && hasLocalFunctions(styles)) {
560
- const localFunctions = extractLocalFunctions(styles);
561
- if (localFunctions) for (const [name, definition] of Object.entries(localFunctions)) {
562
- const key = `__func:${parseFunctionName(name)}`;
563
- if (!rscCache.emittedKeys.has(key)) {
564
- rscCache.emittedKeys.add(key);
565
- parts.push(formatFunctionRule(name, definition));
566
- }
567
- }
568
- }
569
- return parts.join("\n");
570
- }
571
- /**
572
- * Process all chunks in RSC mode: render CSS to strings, allocate classNames,
573
- * and return combined { className, css }.
574
- */
575
- function computeStylesRSC(styles, chunkMap) {
576
- const rscCache = getRSCCache();
577
- const cssParts = [];
578
- const classNames = [];
579
- const pendingCSS = flushPendingCSS(rscCache);
580
- if (pendingCSS) cssParts.push(pendingCSS);
581
- const internalsCSS = collectInternalsRSC(rscCache);
582
- if (internalsCSS) cssParts.push(internalsCSS);
583
- for (const [chunkName, chunkStyleKeys] of chunkMap) {
584
- if (chunkStyleKeys.length === 0) continue;
585
- const { className, isNew } = rscAllocateClassName(rscCache, generateChunkCacheKey(styles, chunkName, chunkStyleKeys));
586
- classNames.push(className);
587
- if (isNew) {
588
- const renderResult = renderStylesForChunk(styles, chunkName, chunkStyleKeys);
589
- if (renderResult.rules.length > 0) {
590
- const css = formatRules(renderResult.rules, className);
591
- if (css) cssParts.push(css);
592
- }
593
- }
594
- }
595
- const ancillaryCSS = collectAncillaryRSC(rscCache, styles);
596
- if (ancillaryCSS) cssParts.push(ancillaryCSS);
597
- if (classNames.length === 0) return EMPTY_RESULT;
598
- const css = cssParts.join("\n");
599
- return {
600
- className: classNames.join(" "),
601
- css: css || void 0
602
- };
603
- }
604
- /**
605
- * Get keyframes that are actually used in styles.
606
- * Returns null if no keyframes are used (fast path for zero overhead).
607
- */
608
- function getUsedKeyframes(styles) {
609
- const hasLocal = hasLocalKeyframes(styles);
610
- const hasGlobal = hasGlobalKeyframes();
611
- if (!hasLocal && !hasGlobal) return null;
612
- const usedNames = extractAnimationNamesFromStyles(styles);
613
- if (usedNames.size === 0) return null;
614
- return filterUsedKeyframes(mergeKeyframes(hasLocal ? extractLocalKeyframes(styles) : null, hasGlobal ? getGlobalKeyframes() : null), usedNames);
615
- }
616
- /**
617
- * Process a chunk on the SSR path: allocate via collector, render, collect CSS.
618
- */
619
- function processChunkSSR(collector, styles, chunkName, styleKeys) {
620
- if (styleKeys.length === 0) return null;
621
- const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
622
- const { className, isNewAllocation } = collector.allocateClassName(cacheKey);
623
- if (isNewAllocation) {
624
- const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);
625
- if (renderResult.rules.length > 0) {
626
- collector.collectChunk(cacheKey, className, renderResult.rules);
627
- return {
628
- name: chunkName,
629
- styleKeys,
630
- cacheKey,
631
- renderResult,
632
- className
633
- };
634
- }
635
- return null;
636
- }
637
- return {
638
- name: chunkName,
639
- styleKeys,
640
- cacheKey,
641
- renderResult: { rules: [] },
642
- className
643
- };
644
- }
645
- /**
646
- * Process a chunk on the client: render, allocate className, and inject
647
- * CSS synchronously. The injector's cache makes this idempotent.
648
- */
649
- function processChunkSync(styles, chunkName, styleKeys, root) {
650
- if (styleKeys.length === 0) return null;
651
- const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
652
- const renderResult = renderStylesForChunk(styles, chunkName, styleKeys, cacheKey);
653
- if (renderResult.rules.length === 0) return null;
654
- const { className } = inject(renderResult.rules, {
655
- cacheKey,
656
- root
657
- });
658
- return {
659
- name: chunkName,
660
- styleKeys,
661
- cacheKey,
662
- renderResult,
663
- className
664
- };
665
- }
666
- /**
667
- * Inject keyframes synchronously and return a name replacement map.
668
- * On the client, keyframes are injected into the DOM.
669
- */
670
- function injectKeyframesSync(usedKeyframes, root) {
671
- let nameMap = null;
672
- for (const [name, steps] of Object.entries(usedKeyframes)) {
673
- const injectedName = keyframes(steps, {
674
- name,
675
- root
676
- }).toString();
677
- if (injectedName !== name) {
678
- if (!nameMap) nameMap = /* @__PURE__ */ new Map();
679
- nameMap.set(name, injectedName);
680
- }
681
- }
682
- return nameMap;
683
- }
684
- /**
685
- * Inject chunk rules synchronously, replacing animation names if needed.
686
- */
687
- function injectChunkRulesSync(chunks, nameMap, root) {
688
- for (const chunk of chunks) if (chunk.renderResult.rules.length > 0) inject(nameMap ? chunk.renderResult.rules.map((rule) => ({
689
- ...rule,
690
- declarations: replaceAnimationNames(rule.declarations, nameMap)
691
- })) : chunk.renderResult.rules, {
692
- cacheKey: chunk.cacheKey,
693
- root
694
- });
695
- }
696
- /**
697
- * Inject all ancillary rules (properties, font-faces, counter-styles) synchronously.
698
- */
699
- function injectAncillarySync(styles, root) {
700
- if (hasLocalProperties(styles)) {
701
- const localProperties = extractLocalProperties(styles);
702
- if (localProperties) for (const [token, definition] of Object.entries(localProperties)) property(token, {
703
- ...definition,
704
- root
705
- });
706
- }
707
- if (hasLocalFontFace(styles)) {
708
- const localFontFace = extractLocalFontFace(styles);
709
- if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
710
- const descriptors = Array.isArray(input) ? input : [input];
711
- for (const desc of descriptors) fontFace(family, desc, { root });
712
- }
713
- }
714
- if (hasLocalCounterStyle(styles)) {
715
- const localCounterStyle = extractLocalCounterStyle(styles);
716
- if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) counterStyle(name, descriptors, { root });
717
- }
718
- if (!isFunctionsPolyfillEnabled() && hasLocalFunctions(styles)) {
719
- const localFunctions = extractLocalFunctions(styles);
720
- if (localFunctions) for (const [name, definition] of Object.entries(localFunctions)) func(name, definition, { root });
721
- }
722
- }
723
- /**
724
- * Collect all ancillary rules into the SSR collector.
725
- */
726
- function collectAncillarySSR(collector, styles, chunks) {
727
- const usedKf = getUsedKeyframes(styles);
728
- if (usedKf) for (const [name, steps] of Object.entries(usedKf)) {
729
- const css = formatKeyframesCSS(name, steps);
730
- collector.collectKeyframes(name, css);
731
- }
732
- if (hasLocalProperties(styles)) {
733
- const localProperties = extractLocalProperties(styles);
734
- if (localProperties) for (const [token, definition] of Object.entries(localProperties)) {
735
- const css = formatPropertyCSS(token, definition);
736
- if (css) collector.collectProperty(token, css);
737
- }
738
- }
739
- if (hasLocalFontFace(styles)) {
740
- const localFontFace = extractLocalFontFace(styles);
741
- if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
742
- const descriptors = Array.isArray(input) ? input : [input];
743
- for (const desc of descriptors) {
744
- const hash = fontFaceContentHash(family, desc);
745
- const css = formatFontFaceRule(family, desc);
746
- collector.collectFontFace(hash, css);
747
- }
748
- }
749
- }
750
- if (hasLocalCounterStyle(styles)) {
751
- const localCounterStyle = extractLocalCounterStyle(styles);
752
- if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) {
753
- const css = formatCounterStyleRule(name, descriptors);
754
- collector.collectCounterStyle(name, css);
755
- }
756
- }
757
- if (!isFunctionsPolyfillEnabled() && hasLocalFunctions(styles)) {
758
- const localFunctions = extractLocalFunctions(styles);
759
- if (localFunctions) for (const [name, definition] of Object.entries(localFunctions)) {
760
- const css = formatFunctionRule(name, definition);
761
- collector.collectFunction(parseFunctionName(name), css);
762
- }
763
- }
764
- if (getConfig().autoPropertyTypes !== false) {
765
- const allRules = chunks.flatMap((c) => c.renderResult.rules);
766
- if (allRules.length > 0) collectAutoInferredProperties(allRules, collector, styles);
767
- }
768
- }
769
- /**
770
- * Synchronous, hook-free style computation.
771
- *
772
- * Resolves recipes, categorizes style keys into chunks, renders CSS rules,
773
- * allocates class names, and injects / collects / returns the CSS.
774
- *
775
- * Three code paths:
776
- * 1. SSR collector — discovered via ALS or passed explicitly; CSS collected
777
- * 2. RSC inline — no collector and no `document`; CSS returned as `result.css`
778
- * for the caller to emit as an inline `<style>` tag
779
- * 3. Client inject — CSS injected synchronously into the DOM (idempotent)
780
- *
781
- * @param styles - Tasty styles object (or undefined for no styles)
782
- * @param options - Optional SSR collector override
783
- */
784
- function computeStyles(styles, options) {
785
- if (!styles || !hasKeys(styles)) return EMPTY_RESULT;
786
- const resolved = resolveRecipes(styles);
787
- if (isFunctionsPolyfillEnabled() && hasLocalFunctions(resolved)) registerLocalFunctionPolyfills(resolved);
788
- const chunkMap = categorizeStyleKeys(resolved);
789
- const collector = options?.ssrCollector !== void 0 ? options.ssrCollector : getRegisteredSSRCollector();
790
- const chunks = [];
791
- if (collector) {
792
- collector.collectInternals();
793
- for (const [chunkName, chunkStyleKeys] of chunkMap) {
794
- const chunk = processChunkSSR(collector, resolved, chunkName, chunkStyleKeys);
795
- if (chunk) chunks.push(chunk);
796
- }
797
- collectAncillarySSR(collector, resolved, chunks);
798
- } else if (typeof document === "undefined") return computeStylesRSC(resolved, chunkMap);
799
- else {
800
- const root = options?.root;
801
- injectAncillarySync(resolved, root);
802
- const usedKf = getUsedKeyframes(resolved);
803
- const nameMap = usedKf ? injectKeyframesSync(usedKf, root) : null;
804
- for (const [chunkName, chunkStyleKeys] of chunkMap) {
805
- const chunk = processChunkSync(resolved, chunkName, chunkStyleKeys, root);
806
- if (chunk) chunks.push(chunk);
807
- }
808
- if (nameMap) injectChunkRulesSync(chunks, nameMap, root);
809
- for (const chunk of chunks) touch(chunk.className, { root });
810
- }
811
- if (chunks.length === 0) return EMPTY_RESULT;
812
- if (chunks.length === 1) return { className: chunks[0].className };
813
- return { className: chunks.map((c) => c.className).join(" ") };
814
- }
815
- //#endregion
816
- //#region src/utils/filter-base-props.ts
817
- const DOMPropNames = new Set(["id"]);
818
- const BasePropNames = new Set([
819
- "role",
820
- "as",
821
- "element",
822
- "css",
823
- "qa",
824
- "mods",
825
- "qaVal",
826
- "hidden",
827
- "isHidden",
828
- "disabled",
829
- "isDisabled",
830
- "children",
831
- "style",
832
- "className",
833
- "href",
834
- "target",
835
- "tabIndex"
836
- ]);
837
- const ignoreEventPropsNames = new Set([
838
- "onPress",
839
- "onHoverStart",
840
- "onHoverEnd",
841
- "onPressStart",
842
- "onPressEnd"
843
- ]);
844
- const propRe = /^((data-).*)$/;
845
- const eventRe = /^on[A-Z].+$/;
846
- /**
847
- * Filters out all props that aren't valid DOM props or defined via override prop obj.
848
- * @param props - The component props to be filtered.
849
- * @param opts - Props to override.
850
- */
851
- function filterBaseProps(props, opts = {}) {
852
- const { propNames, eventProps } = opts;
853
- const filteredProps = {};
854
- for (const prop in props) if (Object.prototype.hasOwnProperty.call(props, prop) && (DOMPropNames.has(prop) || BasePropNames.has(prop) || prop.startsWith("aria-") || eventProps && eventRe.test(prop) && !ignoreEventPropsNames.has(prop) || propNames?.has(prop) || propRe.test(prop))) filteredProps[prop] = props[prop];
855
- return filteredProps;
856
- }
857
- //#endregion
858
- //#region src/utils/colors.ts
859
- function color(name, opacity = 1) {
860
- if (opacity !== 1) return overrideColorAlpha(`var(--${name}-color)`, String(opacity));
861
- return `var(--${name}-color)`;
862
- }
863
- //#endregion
864
- //#region src/utils/cache-wrapper.ts
865
- /**
866
- * Create a function that caches the result with LRU eviction.
867
- */
868
- function cacheWrapper(handler, limit = 1e3) {
869
- const cache = new Lru(limit);
870
- return (firstArg, secondArg) => {
871
- const key = typeof firstArg === "string" && secondArg == null ? firstArg : JSON.stringify([firstArg, secondArg]);
872
- let result = cache.get(key);
873
- if (result === void 0) {
874
- result = secondArg == null ? handler(firstArg) : handler(firstArg, secondArg);
875
- cache.set(key, result);
876
- }
877
- return result;
878
- };
879
- }
880
- //#endregion
881
- //#region src/utils/mod-attrs.ts
882
- function modAttrs(map) {
883
- return map ? Object.keys(map).reduce((attrs, key) => {
884
- const value = map[key];
885
- if (value == null || value === false) return attrs;
886
- const attrName = `data-${camelToKebab(key)}`;
887
- if (value === true) attrs[attrName] = "";
888
- else if (typeof value === "string") attrs[attrName] = value;
889
- else if (typeof value === "number") attrs[attrName] = String(value);
890
- else console.warn(`[Tasty] Invalid mod value for "${key}". Expected boolean, string, or number, got ${typeof value}`);
891
- return attrs;
892
- }, {}) : null;
893
- }
894
- const _modAttrs = cacheWrapper(modAttrs);
895
- //#endregion
896
- //#region src/utils/dotize.ts
897
- const dotize = {
898
- valTypes: {
899
- none: "NONE",
900
- primitive: "PRIM",
901
- object: "OBJECT",
902
- array: "ARRAY"
903
- },
904
- getValType: function(val) {
905
- if (!val || typeof val != "object" || Array.isArray(val)) return dotize.valTypes.primitive;
906
- if (typeof val == "object") return dotize.valTypes.object;
907
- },
908
- getPathType: function(arrPath) {
909
- const arrPathTypes = [];
910
- for (const path in arrPath) {
911
- const pathVal = arrPath[path];
912
- if (!pathVal) arrPathTypes.push(dotize.valTypes.none);
913
- else if (dotize.isNumber(pathVal)) arrPathTypes.push(dotize.valTypes.array);
914
- else arrPathTypes.push(dotize.valTypes.object);
915
- }
916
- return arrPathTypes;
917
- },
918
- isUndefined: function(obj) {
919
- return typeof obj == "undefined";
920
- },
921
- isNumber: function(f) {
922
- return !isNaN(parseInt(f));
923
- },
924
- isEmptyObj: function(obj) {
925
- for (const prop in obj) if (Object.hasOwnProperty.call(obj, prop)) return false;
926
- return JSON.stringify(obj) === JSON.stringify({});
927
- },
928
- isPlainObject: function(obj) {
929
- if (typeof obj !== "object" || obj === null) return false;
930
- return Object.getPrototypeOf(obj) === Object.prototype;
931
- },
932
- isNotObject: function(obj) {
933
- return !obj || !this.isPlainObject(obj);
934
- },
935
- isEmptyArray: function(arr) {
936
- return Array.isArray(arr) && arr.length == 0;
937
- },
938
- isNotArray: function(arr) {
939
- return Array.isArray(arr) == false;
940
- },
941
- removeEmptyArrayItem: function(arr) {
942
- return arr.filter(function(el) {
943
- return el != null && el != "";
944
- });
945
- },
946
- getFieldName: function(field, prefix, isRoot, isArrayItem, isArray) {
947
- if (isArray) return (prefix ? prefix : "") + (dotize.isNumber(field) ? "[" + field + "]" : (isRoot && !prefix ? "" : ".") + field);
948
- else if (isArrayItem) return (prefix ? prefix : "") + "[" + field + "]";
949
- else return (prefix ? prefix + "." : "") + field;
950
- },
951
- startsWith: function(val, valToSearch) {
952
- return val.indexOf(valToSearch) == 0;
953
- },
954
- convert: function(obj, prefix = "") {
955
- let newObj = {};
956
- if (dotize.isNotObject(obj)) if (prefix) {
957
- newObj[prefix] = obj;
958
- return newObj;
959
- } else return obj;
960
- return (function recurse(o, p, isRoot) {
961
- const isArrayItem = Array.isArray(o);
962
- for (const f in o) {
963
- const currentProp = o[f];
964
- if (currentProp && typeof currentProp === "object" && !Array.isArray(currentProp) && dotize.isPlainObject(currentProp)) {
965
- if (isArrayItem && dotize.isEmptyObj(currentProp) == false) newObj = recurse(currentProp, dotize.getFieldName(f, p, isRoot, true));
966
- else if (dotize.isEmptyObj(currentProp) == false) newObj = recurse(currentProp, dotize.getFieldName(f, p, isRoot));
967
- else if (dotize.isEmptyObj(currentProp)) newObj[dotize.getFieldName(f, p, isRoot, isArrayItem)] = currentProp;
968
- } else if (isArrayItem || dotize.isNumber(f)) newObj[dotize.getFieldName(f, p, isRoot, true)] = currentProp;
969
- else newObj[dotize.getFieldName(f, p, isRoot)] = currentProp;
970
- }
971
- return newObj;
972
- })(obj, prefix, true);
973
- },
974
- backward: function(obj, prefix) {
975
- let newObj = {};
976
- const arStartRegex = /\[(\d+)\]/g;
977
- if (dotize.isNotObject(obj) && dotize.isNotArray(obj)) if (prefix) return obj[prefix];
978
- else return obj;
979
- for (let tProp in obj) {
980
- const tPropVal = obj[tProp];
981
- if (prefix) {
982
- const prefixRegex = new RegExp("^" + prefix);
983
- tProp = tProp.replace(prefixRegex, "");
984
- }
985
- tProp = tProp.replace(arStartRegex, ".$1");
986
- if (dotize.startsWith(tProp, ".")) tProp = tProp.replace(/^\./, "");
987
- const arrPath = tProp.split(".");
988
- const arrPathTypes = dotize.getPathType(arrPath);
989
- if (!dotize.isUndefined(arrPathTypes) && arrPathTypes[0] == dotize.valTypes.array && Array.isArray(newObj) == false) newObj = [];
990
- (function recurse(rPropVal, rObj, rPropValPrev, rObjPrev) {
991
- let currentPath = arrPath.shift();
992
- const currentPathType = arrPathTypes.shift();
993
- if (typeof currentPath == "undefined" || currentPath == "") {
994
- newObj = rPropVal;
995
- return;
996
- }
997
- const isArray = currentPathType == dotize.valTypes.array;
998
- if (dotize.isNumber(currentPath)) currentPath = parseInt(currentPath);
999
- if (arrPath.length > 0) {
1000
- if (typeof rObj[currentPath] == "undefined") if (isArray) rObj[currentPath] = [];
1001
- else rObj[currentPath] = {};
1002
- recurse(rPropVal, rObj[currentPath], currentPath, rObj);
1003
- return;
1004
- }
1005
- if (currentPathType == dotize.valTypes.array && rPropValPrev && rObjPrev) {
1006
- if (Array.isArray(rObjPrev[rPropValPrev]) == false) rObjPrev[rPropValPrev] = [];
1007
- rObjPrev[rPropValPrev].push(rPropVal);
1008
- } else rObj[currentPath] = rPropVal;
1009
- })(tPropVal, newObj);
1010
- }
1011
- return newObj;
1012
- }
1013
- };
1014
- //#endregion
1015
- //#region src/utils/process-tokens.ts
1016
- /**
1017
- * Check if a value is a valid token value (string, number, or boolean - not object).
1018
- * Returns false for `false` values (they mean "skip this token").
1019
- */
1020
- function isValidTokenValue(value) {
1021
- if (value === void 0 || value === null || value === false) return false;
1022
- if (typeof value === "object") {
1023
- console.warn("[Tasty] Object values are not allowed in tokens prop. Tokens do not support state-based styling. Use a primitive value instead.");
1024
- return false;
1025
- }
1026
- return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
1027
- }
1028
- /**
1029
- * Process a single token value through the tasty parser.
1030
- * Numbers are converted to strings; 0 stays as "0".
1031
- */
1032
- function processTokenValue(value) {
1033
- if (typeof value === "number") {
1034
- if (value === 0) return "0";
1035
- return parseStyle(String(value)).output;
1036
- }
1037
- return parseStyle(value).output;
1038
- }
1039
- /**
1040
- * Process tokens object into inline style properties.
1041
- * - $name -> --name with parsed value
1042
- * - #name -> --name-color with parsed value
1043
- *
1044
- * @param tokens - The tokens object to process
1045
- * @returns CSSProperties object or undefined if no tokens to process
1046
- */
1047
- function processTokens(tokens) {
1048
- if (!tokens) return;
1049
- const keys = Object.keys(tokens);
1050
- if (keys.length === 0) return;
1051
- let result;
1052
- for (const key of keys) {
1053
- const value = tokens[key];
1054
- if (!isValidTokenValue(value)) continue;
1055
- if (key.startsWith("$")) {
1056
- const propName = `--${normalizeDslName(key.slice(1))}`;
1057
- const processedValue = processTokenValue(value === true ? "" : value);
1058
- if (!result) result = {};
1059
- result[propName] = processedValue;
1060
- } else if (key.startsWith("#")) {
1061
- const colorName = normalizeDslName(key.slice(1));
1062
- const effectiveValue = normalizeColorTokenValue(value);
1063
- if (effectiveValue === null) continue;
1064
- if (!result) result = {};
1065
- result[`--${colorName}-color`] = processTokenValue(effectiveValue);
1066
- }
1067
- }
1068
- return result;
1069
- }
1070
- //#endregion
1071
- //#region src/debug.ts
1072
- function fmtSize(bytes) {
1073
- return bytes > 1024 ? `${(bytes / 1024).toFixed(1)}KB` : `${bytes}B`;
1074
- }
1075
- function countRules(css) {
1076
- return (css.match(/\{[^}]*\}/g) || []).length;
1077
- }
1078
- function sortTastyClasses(classes) {
1079
- return Array.from(classes).sort((a, b) => a.localeCompare(b));
1080
- }
1081
- function getRegistry(root = document) {
1082
- return injector.instance._sheetManager?.getRegistry(root);
1083
- }
1084
- function getUnusedClasses(root = document) {
1085
- const registry = getRegistry(root);
1086
- if (!registry) return [];
1087
- const result = [];
1088
- for (const [cls, rc] of registry.refCounts) if (rc === 0) result.push(cls);
1089
- return sortTastyClasses(result);
1090
- }
1091
- function findDomTastyClasses(root = document) {
1092
- const classes = /* @__PURE__ */ new Set();
1093
- const elements = root.querySelectorAll?.("[class]") || [];
1094
- const classRegex = tastyClassRegex(getNamePrefix());
1095
- elements.forEach((el) => {
1096
- const attr = el.getAttribute("class");
1097
- if (attr) {
1098
- for (const cls of attr.split(/\s+/)) if (classRegex.test(cls)) classes.add(cls);
1099
- }
1100
- });
1101
- return sortTastyClasses(classes);
1102
- }
1103
- function prettifyCSS(css) {
1104
- if (!css || !css.trim()) return "";
1105
- const out = [];
1106
- let depth = 0;
1107
- const indent = () => " ".repeat(depth);
1108
- let normalized = css.replace(/\s+/g, " ").trim();
1109
- normalized = normalized.replace(/\s*\{\s*/g, " { ");
1110
- normalized = normalized.replace(/\s*\}\s*/g, " } ");
1111
- normalized = normalized.replace(/;\s*/g, "; ");
1112
- const tokens = normalized.split(/\s+/);
1113
- let buf = "";
1114
- for (const t of tokens) if (t === "{") {
1115
- const header = buf.trim();
1116
- if (header) {
1117
- const parts = splitOutsideParens(header, ",");
1118
- if (parts.length > 1) out.push(parts.map((p, idx) => idx === 0 ? `${indent()}${p.trim()},` : `${indent()}${p.trim()}${idx < parts.length - 1 ? "," : ""}`).join("\n") + " {");
1119
- else out.push(`${indent()}${header} {`);
1120
- } else out.push(`${indent()}{`);
1121
- depth++;
1122
- buf = "";
1123
- } else if (t === "}") {
1124
- if (buf.trim()) {
1125
- for (const decl of buf.split(";").filter((s) => s.trim())) out.push(`${indent()}${decl.trim()};`);
1126
- buf = "";
1127
- }
1128
- depth = Math.max(0, depth - 1);
1129
- out.push(`${indent()}}`);
1130
- } else if (t.endsWith(";")) {
1131
- buf += ` ${t}`;
1132
- const full = buf.trim();
1133
- if (full) out.push(`${indent()}${full}`);
1134
- buf = "";
1135
- } else buf += ` ${t}`;
1136
- if (buf.trim()) out.push(buf.trim());
1137
- return out.filter((l) => l.trim()).join("\n").replace(/\n{3,}/g, "\n\n").trim();
1138
- }
1139
- /** Split `str` by `sep` only when not inside parentheses */
1140
- function splitOutsideParens(str, sep) {
1141
- const parts = [];
1142
- let depth = 0;
1143
- let start = 0;
1144
- for (let i = 0; i < str.length; i++) {
1145
- const ch = str[i];
1146
- if (ch === "(") depth++;
1147
- else if (ch === ")") depth--;
1148
- else if (depth === 0 && str.startsWith(sep, i)) {
1149
- parts.push(str.slice(start, i));
1150
- start = i + sep.length;
1151
- }
1152
- }
1153
- parts.push(str.slice(start));
1154
- return parts;
1155
- }
1156
- function extractChunkName(cacheKey) {
1157
- for (const part of cacheKey.split("\0")) {
1158
- if (part.startsWith("[states:")) continue;
1159
- if (!part.includes(":") && part.length > 0) return part;
1160
- }
1161
- return null;
1162
- }
1163
- function getChunkForClass(className, root = document) {
1164
- const registry = getRegistry(root);
1165
- if (!registry) return null;
1166
- for (const [key, cn] of registry.cacheKeyToClassName) if (cn === className) return extractChunkName(key);
1167
- return null;
1168
- }
1169
- function buildChunkBreakdown(root = document) {
1170
- const registry = getRegistry(root);
1171
- if (!registry) return {
1172
- byChunk: {},
1173
- totalChunkTypes: 0,
1174
- totalClasses: 0
1175
- };
1176
- const byChunk = {};
1177
- for (const [cacheKey, className] of registry.cacheKeyToClassName) {
1178
- const chunk = extractChunkName(cacheKey) || "unknown";
1179
- if (!byChunk[chunk]) byChunk[chunk] = {
1180
- classes: [],
1181
- cssSize: 0,
1182
- ruleCount: 0
1183
- };
1184
- byChunk[chunk].classes.push(className);
1185
- const css = injector.instance.getCSSTextForClasses([className], { root });
1186
- byChunk[chunk].cssSize += css.length;
1187
- byChunk[chunk].ruleCount += countRules(css);
1188
- }
1189
- for (const entry of Object.values(byChunk)) entry.classes = sortTastyClasses(entry.classes);
1190
- const totalClasses = Object.values(byChunk).reduce((s, e) => s + e.classes.length, 0);
1191
- return {
1192
- byChunk,
1193
- totalChunkTypes: Object.keys(byChunk).length,
1194
- totalClasses
1195
- };
1196
- }
1197
- function getGlobalTypeCSS(type, root = document) {
1198
- const registry = getRegistry(root);
1199
- if (!registry) return {
1200
- css: "",
1201
- ruleCount: 0,
1202
- size: 0
1203
- };
1204
- const chunks = [];
1205
- let rc = 0;
1206
- if (type === "keyframes") for (const [, entry] of registry.keyframesCache) {
1207
- const info = entry.info;
1208
- const sheetInfo = registry.sheets[info.sheetIndex];
1209
- const sm = injector.instance._sheetManager;
1210
- const ss = sheetInfo && sm ? sm.getCSSSheet(sheetInfo) : null;
1211
- if (ss && info.ruleIndex < ss.cssRules.length) {
1212
- const rule = ss.cssRules[info.ruleIndex];
1213
- if (rule) {
1214
- chunks.push(rule.cssText);
1215
- rc++;
1216
- }
1217
- } else if (info.cssText) {
1218
- chunks.push(info.cssText);
1219
- rc++;
1220
- }
1221
- }
1222
- else {
1223
- const prefix = type === "global" ? "global:" : type === "raw" ? "raw:" : "property:";
1224
- for (const [key, ri] of registry.globalRules) {
1225
- if (!key.startsWith(prefix)) continue;
1226
- const sheetInfo = registry.sheets[ri.sheetIndex];
1227
- const sm = injector.instance._sheetManager;
1228
- const ss = sheetInfo && sm ? sm.getCSSSheet(sheetInfo) : null;
1229
- if (ss) {
1230
- const start = Math.max(0, ri.ruleIndex);
1231
- const end = Math.min(ss.cssRules.length - 1, ri.endRuleIndex ?? ri.ruleIndex);
1232
- if (start >= 0 && end >= start && start < ss.cssRules.length) for (let i = start; i <= end; i++) {
1233
- const rule = ss.cssRules[i];
1234
- if (rule) {
1235
- chunks.push(rule.cssText);
1236
- rc++;
1237
- }
1238
- }
1239
- } else if (ri.cssText?.length) {
1240
- chunks.push(...ri.cssText);
1241
- rc += ri.cssText.length;
1242
- }
1243
- }
1244
- }
1245
- const raw = chunks.join("\n");
1246
- return {
1247
- css: prettifyCSS(raw),
1248
- ruleCount: rc,
1249
- size: raw.length
1250
- };
1251
- }
1252
- function getSourceCssForClasses(classNames, root = document) {
1253
- const registry = getRegistry(root);
1254
- if (!registry) return null;
1255
- const chunks = [];
1256
- let found = false;
1257
- for (const cls of classNames) {
1258
- const info = registry.rules.get(cls);
1259
- if (info?.cssText?.length) {
1260
- chunks.push(...info.cssText);
1261
- found = true;
1262
- }
1263
- }
1264
- return found ? chunks.join("\n") : null;
1265
- }
1266
- function getDefs(root = document) {
1267
- const registry = getRegistry(root);
1268
- let properties = [];
1269
- if (registry?.injectedProperties) properties = Array.from(registry.injectedProperties.keys()).sort();
1270
- const keyframes = [];
1271
- if (registry) {
1272
- for (const entry of registry.keyframesCache.values()) keyframes.push({
1273
- name: entry.name,
1274
- refCount: entry.refCount
1275
- });
1276
- keyframes.sort((a, b) => a.name.localeCompare(b.name));
1277
- }
1278
- return {
1279
- properties,
1280
- keyframes
1281
- };
1282
- }
1283
- const CHUNK_ORDER = [
1284
- CHUNK_NAMES.COMBINED,
1285
- CHUNK_NAMES.APPEARANCE,
1286
- CHUNK_NAMES.FONT,
1287
- CHUNK_NAMES.DIMENSION,
1288
- CHUNK_NAMES.DISPLAY,
1289
- CHUNK_NAMES.LAYOUT,
1290
- CHUNK_NAMES.POSITION,
1291
- CHUNK_NAMES.MISC,
1292
- CHUNK_NAMES.SUBCOMPONENTS
1293
- ];
1294
- const tastyDebug = {
1295
- css(target, opts) {
1296
- const { root = document, prettify = true, raw = false, source = false } = opts || {};
1297
- let css = "";
1298
- const classRegex = tastyClassRegex(getNamePrefix());
1299
- if (source && typeof target === "string" && classRegex.test(target)) {
1300
- const src = getSourceCssForClasses([target], root);
1301
- if (src) css = src;
1302
- else {
1303
- if (!raw) console.warn("[Tasty] source CSS not available (requires dev mode or TASTY_DEBUG=true). Falling back to live CSSOM.");
1304
- css = injector.instance.getCSSTextForClasses([target], { root });
1305
- }
1306
- } else if (source && Array.isArray(target)) {
1307
- const src = getSourceCssForClasses(target, root);
1308
- if (src) css = src;
1309
- else {
1310
- if (!raw) console.warn("[Tasty] source CSS not available. Falling back to live CSSOM.");
1311
- css = injector.instance.getCSSTextForClasses(target, { root });
1312
- }
1313
- } else if (typeof target === "string") if (target === "all") css = injector.instance.getCSSText({ root });
1314
- else if (target === "global") {
1315
- css = getGlobalTypeCSS("global", root).css;
1316
- return css;
1317
- } else if (target === "active") {
1318
- const active = findDomTastyClasses(root);
1319
- css = injector.instance.getCSSTextForClasses(active, { root });
1320
- } else if (target === "unused") {
1321
- const unused = getUnusedClasses(root);
1322
- css = injector.instance.getCSSTextForClasses(unused, { root });
1323
- } else if (target === "page") css = getPageCSS(root);
1324
- else if (classRegex.test(target)) css = injector.instance.getCSSTextForClasses([target], { root });
1325
- else {
1326
- const el = root.querySelector?.(target);
1327
- if (el) css = getCSSTextForNode(el, { root });
1328
- }
1329
- else if (Array.isArray(target)) css = injector.instance.getCSSTextForClasses(target, { root });
1330
- else if (target instanceof Element) css = getCSSTextForNode(target, { root });
1331
- const result = prettify ? prettifyCSS(css) : css;
1332
- if (!raw) {
1333
- const label = Array.isArray(target) ? `[${target.join(", ")}]` : target;
1334
- const rc = countRules(css);
1335
- console.group(`CSS for ${label} (${rc} rules, ${fmtSize(css.length)})`);
1336
- console.log(result || "(empty)");
1337
- console.groupEnd();
1338
- }
1339
- return result;
1340
- },
1341
- inspect(target, opts) {
1342
- const { root = document, raw = false } = opts || {};
1343
- const element = typeof target === "string" ? root.querySelector?.(target) : target;
1344
- if (!element) {
1345
- const empty = {
1346
- element: null,
1347
- classes: [],
1348
- chunks: [],
1349
- css: "",
1350
- size: 0,
1351
- rules: 0
1352
- };
1353
- if (!raw) console.warn("[Tasty] debug.inspect: element not found");
1354
- return empty;
1355
- }
1356
- const classList = element.getAttribute("class") || "";
1357
- const classRegex = tastyClassRegex(getNamePrefix());
1358
- const tastyClasses = classList.split(/\s+/).filter((cls) => classRegex.test(cls));
1359
- const chunks = tastyClasses.map((className) => ({
1360
- className,
1361
- chunkName: getChunkForClass(className, root)
1362
- }));
1363
- const css = getCSSTextForNode(element, { root });
1364
- const rules = countRules(css);
1365
- const result = {
1366
- element,
1367
- classes: tastyClasses,
1368
- chunks,
1369
- css: prettifyCSS(css),
1370
- size: css.length,
1371
- rules
1372
- };
1373
- if (!raw) {
1374
- const tag = element.tagName.toLowerCase();
1375
- const id = element.id ? `#${element.id}` : "";
1376
- console.group(`inspect ${tag}${id} — ${tastyClasses.length} classes, ${rules} rules, ${fmtSize(css.length)}`);
1377
- if (chunks.length) console.log("Chunks:", chunks.map((c) => `${c.className}→${c.chunkName || "?"}`).join(", "));
1378
- console.groupCollapsed("CSS");
1379
- console.log(result.css || "(empty)");
1380
- console.groupEnd();
1381
- console.groupEnd();
1382
- }
1383
- return result;
1384
- },
1385
- summary(opts) {
1386
- const { root = document, raw = false } = opts || {};
1387
- const activeClasses = findDomTastyClasses(root);
1388
- const unusedClasses = getUnusedClasses(root);
1389
- const totalStyledClasses = [...activeClasses, ...unusedClasses];
1390
- const activeCSS = injector.instance.getCSSTextForClasses(activeClasses, { root });
1391
- const unusedCSS = injector.instance.getCSSTextForClasses(unusedClasses, { root });
1392
- const allCSS = injector.instance.getCSSText({ root });
1393
- const activeRuleCount = countRules(activeCSS);
1394
- const unusedRuleCount = countRules(unusedCSS);
1395
- const globalData = getGlobalTypeCSS("global", root);
1396
- const rawData = getGlobalTypeCSS("raw", root);
1397
- const kfData = getGlobalTypeCSS("keyframes", root);
1398
- const propData = getGlobalTypeCSS("property", root);
1399
- const totalRuleCount = activeRuleCount + unusedRuleCount + globalData.ruleCount + rawData.ruleCount + kfData.ruleCount + propData.ruleCount;
1400
- const metrics = injector.instance.getMetrics({ root });
1401
- const defs = getDefs(root);
1402
- const chunkBreakdown = buildChunkBreakdown(root);
1403
- const summary = {
1404
- activeClasses,
1405
- unusedClasses,
1406
- totalStyledClasses,
1407
- activeCSSSize: activeCSS.length,
1408
- unusedCSSSize: unusedCSS.length,
1409
- globalCSSSize: globalData.size,
1410
- rawCSSSize: rawData.size,
1411
- keyframesCSSSize: kfData.size,
1412
- propertyCSSSize: propData.size,
1413
- totalCSSSize: allCSS.length,
1414
- activeRuleCount,
1415
- unusedRuleCount,
1416
- globalRuleCount: globalData.ruleCount,
1417
- rawRuleCount: rawData.ruleCount,
1418
- keyframesRuleCount: kfData.ruleCount,
1419
- propertyRuleCount: propData.ruleCount,
1420
- totalRuleCount,
1421
- metrics,
1422
- definedProperties: defs.properties,
1423
- definedKeyframes: defs.keyframes,
1424
- chunkBreakdown
1425
- };
1426
- if (!raw) {
1427
- console.group("Tasty Summary");
1428
- console.log(`Active: ${activeClasses.length} classes, ${activeRuleCount} rules, ${fmtSize(activeCSS.length)}`);
1429
- console.log(`Unused: ${unusedClasses.length} classes, ${unusedRuleCount} rules, ${fmtSize(unusedCSS.length)}`);
1430
- console.log(`Global: ${globalData.ruleCount} rules, ${fmtSize(globalData.size)}`);
1431
- if (rawData.ruleCount) console.log(`Raw: ${rawData.ruleCount} rules, ${fmtSize(rawData.size)}`);
1432
- if (kfData.ruleCount) console.log(`Keyframes: ${kfData.ruleCount} rules, ${fmtSize(kfData.size)}`);
1433
- if (propData.ruleCount) console.log(`@property: ${propData.ruleCount} rules, ${fmtSize(propData.size)}`);
1434
- console.log(`Total: ${totalStyledClasses.length} classes, ${totalRuleCount} rules, ${fmtSize(allCSS.length)}`);
1435
- if (metrics) {
1436
- const total = metrics.hits + metrics.misses;
1437
- const rate = total > 0 ? (metrics.hits / total * 100).toFixed(1) : 0;
1438
- console.log(`Cache: ${rate}% hit rate (${total} lookups)`);
1439
- }
1440
- if (chunkBreakdown.totalChunkTypes > 0) {
1441
- console.groupCollapsed(`Chunks (${chunkBreakdown.totalChunkTypes} types, ${chunkBreakdown.totalClasses} classes)`);
1442
- for (const name of CHUNK_ORDER) {
1443
- const d = chunkBreakdown.byChunk[name];
1444
- if (d) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
1445
- }
1446
- for (const [name, d] of Object.entries(chunkBreakdown.byChunk)) if (!CHUNK_ORDER.includes(name)) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
1447
- console.groupEnd();
1448
- }
1449
- if (defs.properties.length || defs.keyframes.length) console.log(`Defs: ${defs.properties.length} @property, ${defs.keyframes.length} @keyframes`);
1450
- console.groupEnd();
1451
- }
1452
- return summary;
1453
- },
1454
- chunks(opts) {
1455
- const { root = document, raw = false } = opts || {};
1456
- const breakdown = buildChunkBreakdown(root);
1457
- if (!raw) {
1458
- console.group(`Chunks (${breakdown.totalChunkTypes} types, ${breakdown.totalClasses} classes)`);
1459
- for (const name of CHUNK_ORDER) {
1460
- const d = breakdown.byChunk[name];
1461
- if (d) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
1462
- }
1463
- for (const [name, d] of Object.entries(breakdown.byChunk)) if (!CHUNK_ORDER.includes(name)) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
1464
- console.groupEnd();
1465
- }
1466
- return breakdown;
1467
- },
1468
- cache(opts) {
1469
- const { root = document, raw = false } = opts || {};
1470
- const active = findDomTastyClasses(root);
1471
- const unused = getUnusedClasses(root);
1472
- const metrics = injector.instance.getMetrics({ root });
1473
- const status = {
1474
- classes: {
1475
- active,
1476
- unused,
1477
- all: [...active, ...unused]
1478
- },
1479
- metrics
1480
- };
1481
- if (!raw) {
1482
- console.group("Cache");
1483
- console.log(`Active: ${active.length}, Unused: ${unused.length}`);
1484
- if (metrics) {
1485
- const total = metrics.hits + metrics.misses;
1486
- const rate = total > 0 ? (metrics.hits / total * 100).toFixed(1) : 0;
1487
- console.log(`Hits: ${metrics.hits}, Misses: ${metrics.misses}, Rate: ${rate}%`);
1488
- }
1489
- console.groupEnd();
1490
- }
1491
- return status;
1492
- },
1493
- cleanup(opts) {
1494
- injector.instance.cleanup(opts?.root);
1495
- },
1496
- help() {
1497
- console.log(`tastyDebug API:
1498
- .summary() — overview (classes, rules, sizes)
1499
- .css("active") — CSS for classes in DOM
1500
- .css("t42") — CSS for a specific class
1501
- .css("t42",{source:1})— original CSS before browser parsing (dev only)
1502
- .css(".selector") — CSS for a DOM element
1503
- .inspect(".selector") — element details (classes, chunks, rules)
1504
- .chunks() — style chunk breakdown
1505
- .cache() — cache status and metrics
1506
- .cleanup() — force unused style cleanup
1507
- Options: { raw: true } suppresses logging, { root: shadowRoot } targets Shadow DOM`);
1508
- },
1509
- install() {
1510
- if (typeof window !== "undefined" && window.tastyDebug !== tastyDebug) {
1511
- window.tastyDebug = tastyDebug;
1512
- console.log("tastyDebug installed. Run tastyDebug.help() for commands.");
1513
- }
1514
- }
1515
- };
1516
- function getPageCSS(root = document) {
1517
- const chunks = [];
1518
- try {
1519
- if ("styleSheets" in root) for (const sheet of Array.from(root.styleSheets)) try {
1520
- if (sheet.cssRules) chunks.push(Array.from(sheet.cssRules).map((r) => r.cssText).join("\n"));
1521
- } catch {}
1522
- } catch {}
1523
- return chunks.join("\n");
1524
- }
1525
- if (typeof window !== "undefined" && isDevEnv()) tastyDebug.install();
1526
- //#endregion
1527
- export { property as A, getRawCSSText as C, injector as D, injectRawCSS as E, ChunkSheetRegistry as M, chunkSheetRegistry as N, isPropertyDefined as O, getCSSTextForNode as S, injectGlobal as T, destroy as _, color as a, gc as b, hasKeys as c, collectAutoInferredPropertiesRSC as d, getStyleTarget as f, createInjector as g, counterStyle as h, _modAttrs as i, touch as j, keyframes as k, formatKeyframesCSS as l, cleanup as m, processTokens as n, filterBaseProps as o, pushRSCCSS as p, dotize as r, computeStyles as s, tastyDebug as t, collectAutoInferredProperties as u, fontFace as v, inject as w, getCSSText as x, func as y };
1528
-
1529
- //# sourceMappingURL=core-B5ybnMP1.js.map