@tenphi/tasty 0.0.0-snapshot.da430e1 → 0.0.0-snapshot.dc62ea3

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 (68) hide show
  1. package/dist/{astro-C_by9qPq.js → astro-CeYENy2x.js} +62 -68
  2. package/dist/astro-CeYENy2x.js.map +1 -0
  3. package/dist/{babel-BUQGeOXA.d.ts → babel-DWCsafYw.d.ts} +2 -2
  4. package/dist/{collector-BevHh16N.js → collector-B3OsM252.js} +3 -3
  5. package/dist/{collector-BevHh16N.js.map → collector-B3OsM252.js.map} +1 -1
  6. package/dist/{collector-CLVr5_p3.d.ts → collector-BTVXj2hS.d.ts} +2 -2
  7. package/dist/{config-NcdqU9PC.js → config-B3gPdCqd.js} +304 -152
  8. package/dist/config-B3gPdCqd.js.map +1 -0
  9. package/dist/{config-YsxGv4tq.d.ts → config-LfIDmVHx.d.ts} +132 -32
  10. package/dist/core/index.d.ts +5 -5
  11. package/dist/core/index.js +6 -6
  12. package/dist/{core-D7s7u-k1.js → core-DGm0CFHP.js} +284 -118
  13. package/dist/core-DGm0CFHP.js.map +1 -0
  14. package/dist/css-resources-Cyl_axbI.js +149 -0
  15. package/dist/css-resources-Cyl_axbI.js.map +1 -0
  16. package/dist/{css-writer-BDPmetHV.js → css-writer-Bgowobbx.js} +3 -3
  17. package/dist/{css-writer-BDPmetHV.js.map → css-writer-Bgowobbx.js.map} +1 -1
  18. package/dist/{format-rules-BQCn7JZH.js → format-rules-XRw9u7d4.js} +3 -29
  19. package/dist/format-rules-XRw9u7d4.js.map +1 -0
  20. package/dist/{hydrate-C3cfqlaQ.js → hydrate-CNOmZprz.js} +3 -3
  21. package/dist/{hydrate-C3cfqlaQ.js.map → hydrate-CNOmZprz.js.map} +1 -1
  22. package/dist/{index-CBK778ne.d.ts → index-Bm9ltvdH.d.ts} +38 -16
  23. package/dist/{index-Cd45t5NM.d.ts → index-BmogEzTo.d.ts} +69 -15
  24. package/dist/index.d.ts +5 -5
  25. package/dist/index.js +7 -7
  26. package/dist/index.js.map +1 -1
  27. package/dist/{keyframes-ByhOtsXB.js → keyframes-DE-OE76F.js} +45 -3
  28. package/dist/keyframes-DE-OE76F.js.map +1 -0
  29. package/dist/{merge-styles-CU7JbEwg.d.ts → merge-styles-BcLl1u_d.d.ts} +2 -2
  30. package/dist/{merge-styles-BKfagXfV.js → merge-styles-DuoZEsm9.js} +2 -2
  31. package/dist/{merge-styles-BKfagXfV.js.map → merge-styles-DuoZEsm9.js.map} +1 -1
  32. package/dist/{resolve-recipes-vvygrWLw.js → resolve-recipes-H9NqOQuP.js} +3 -3
  33. package/dist/{resolve-recipes-vvygrWLw.js.map → resolve-recipes-H9NqOQuP.js.map} +1 -1
  34. package/dist/ssr/astro-client.js +1 -1
  35. package/dist/ssr/astro-middleware-extract-static.js +1 -1
  36. package/dist/ssr/astro-middleware-extract.js +1 -1
  37. package/dist/ssr/astro-middleware-static.js +1 -1
  38. package/dist/ssr/astro-middleware.js +1 -1
  39. package/dist/ssr/astro.d.ts +9 -1
  40. package/dist/ssr/astro.js +1 -1
  41. package/dist/ssr/index.d.ts +1 -1
  42. package/dist/ssr/index.js +3 -3
  43. package/dist/ssr/next-config.d.ts +66 -0
  44. package/dist/ssr/next-config.js +115 -0
  45. package/dist/ssr/next-config.js.map +1 -0
  46. package/dist/ssr/next.d.ts +9 -2
  47. package/dist/ssr/next.js +26 -9
  48. package/dist/ssr/next.js.map +1 -1
  49. package/dist/ssr-collector-ref-COs_ioWl.js +29 -0
  50. package/dist/ssr-collector-ref-COs_ioWl.js.map +1 -0
  51. package/dist/static/index.d.ts +2 -2
  52. package/dist/static/index.js +1 -1
  53. package/dist/zero/babel.d.ts +1 -1
  54. package/dist/zero/babel.js +4 -4
  55. package/dist/zero/babel.js.map +1 -1
  56. package/dist/zero/index.d.ts +1 -1
  57. package/dist/zero/index.js +1 -1
  58. package/dist/zero/next.d.ts +1 -1
  59. package/docs/debug.md +17 -2
  60. package/docs/injector.md +62 -25
  61. package/docs/runtime-benchmarks.md +213 -78
  62. package/docs/ssr.md +151 -31
  63. package/package.json +16 -9
  64. package/dist/astro-C_by9qPq.js.map +0 -1
  65. package/dist/config-NcdqU9PC.js.map +0 -1
  66. package/dist/core-D7s7u-k1.js.map +0 -1
  67. package/dist/format-rules-BQCn7JZH.js.map +0 -1
  68. package/dist/keyframes-ByhOtsXB.js.map +0 -1
@@ -1,7 +1,8 @@
1
- import { Bt as getGlobalParseFunctions, G as StyleInjector, Gt as parseStyle, It as registerLocalFunctionPolyfills, J as hasLocalCounterStyle, K as extractLocalCounterStyle, Mt as formatFunctionRule, Nt as hasLocalFunctions, Pt as parseFunctionName, Q as hasLocalFontFace, Qt as isDevEnv, Ut as normalizeColorTokenValue, Vt as getGlobalParser, X as fontFaceContentHash, Y as extractLocalFontFace, Z as formatFontFaceRule, _ as isFunctionsPolyfillEnabled, _t as hashString, bt as hasLocalProperties, c as getGlobalInjector, en as Lru, 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 overrideColorAlpha, v as isTestEnvironment, vt as extractLocalProperties, wt as CHUNK_NAMES, xt as parsePropertyToken, y as markStylesGenerated, z as camelToKebab } from "./config-NcdqU9PC.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-ByhOtsXB.js";
3
- import { n as formatPropertyCSS, r as getRegisteredSSRCollector, t as formatRules } from "./format-rules-BQCn7JZH.js";
4
- import { t as resolveRecipes } from "./resolve-recipes-vvygrWLw.js";
1
+ import { Bt as getGlobalParseFunctions, G as StyleInjector, Gt as parseStyle, It as registerLocalFunctionPolyfills, J as hasLocalCounterStyle, K as extractLocalCounterStyle, Mt as formatFunctionRule, Nt as hasLocalFunctions, Pt as parseFunctionName, Q as hasLocalFontFace, Qt as isDevEnv, Ut as normalizeColorTokenValue, Vt as getGlobalParser, X as fontFaceContentHash, Y as extractLocalFontFace, Z as formatFontFaceRule, _ as isFunctionsPolyfillEnabled, _t as hashString, bt as hasLocalProperties, c as getGlobalInjector, en as Lru, 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, ot as flushStyles, p as hasGlobalKeyframes, q as formatCounterStyleRule, rt as createStyle, sn as normalizeDslName, tn as overrideColorAlpha, v as isTestEnvironment, vt as extractLocalProperties, wt as CHUNK_NAMES, xt as parsePropertyToken, y as markStylesGenerated, z as camelToKebab } from "./config-B3gPdCqd.js";
2
+ import { a as mergeKeyframes, c as resolveKeyframesNames, d as categorizeStyleKeys, i as hasLocalKeyframes, l as renderStylesForChunk, n as extractLocalKeyframes, o as referencesAnimation, r as filterUsedKeyframes, s as replaceAnimationNames, t as extractAnimationNamesFromStyles, u as generateChunkCacheKey } from "./keyframes-DE-OE76F.js";
3
+ import { t as getRegisteredSSRCollector } from "./ssr-collector-ref-COs_ioWl.js";
4
+ import { n as formatPropertyCSS, t as formatRules } from "./format-rules-XRw9u7d4.js";
5
+ import { t as resolveRecipes } from "./resolve-recipes-H9NqOQuP.js";
5
6
  import { cache } from "react";
6
7
  //#region src/utils/function-color.ts
7
8
  const RE_FUNC_NAME = /^([a-z][a-z0-9-]*)\s*\(/i;
@@ -245,24 +246,43 @@ function getCSSTextForNode(node, options) {
245
246
  return getGlobalInjector().getCSSTextForClasses(classSet, options);
246
247
  }
247
248
  /**
248
- * Force cleanup of unused rules
249
+ * Take a reference on local `@keyframes` under the deterministic names the
250
+ * caller resolved, and report which entry holds each. Pair with
251
+ * `ownKeyframes()` once the rules exist to inspect.
252
+ */
253
+ function holdKeyframes(steps, names, options) {
254
+ return getGlobalInjector().holdKeyframes(steps, names, options);
255
+ }
256
+ /**
257
+ * Record that a class animates these keyframes, so the reference is released
258
+ * when the last such class is collected.
259
+ */
260
+ function ownKeyframes(key, className, options) {
261
+ getGlobalInjector().ownKeyframes(key, className, options);
262
+ }
263
+ /**
264
+ * Remove every injected rule that is neither in the DOM nor held by an
265
+ * outstanding `inject()` handle. Equivalent to `gc({ force: true })`.
249
266
  */
250
267
  function cleanup(root) {
251
268
  return getGlobalInjector().cleanup(root);
252
269
  }
253
270
  /**
254
- * Record a render-time usage hit for one or more classNames.
255
- * Used internally by computeStyles and tasty() to track usage for GC.
256
- * When the global touch counter reaches `touchInterval`, schedules GC.
271
+ * Count a render, so that a collection pass is scheduled every
272
+ * `gc.touchInterval` of them. Used internally by computeStyles and tasty().
273
+ *
274
+ * @deprecated The class name is ignored — collection asks the DOM what is
275
+ * rendered rather than recording usage per class. The argument is kept so
276
+ * existing calls still compile.
257
277
  */
258
278
  function touch(className, options) {
259
279
  if (!getConfig().gc) return;
260
280
  getGlobalInjector().touch(className, options);
261
281
  }
262
282
  /**
263
- * Synchronous garbage collection of unused styles.
264
- * Evicts the oldest unused styles when usageMap exceeds capacity.
265
- * With `{ force: true }`, removes ALL unused styles regardless of capacity.
283
+ * Synchronous garbage collection of unused styles — those no element carries
284
+ * and no `inject()` handle references. Evicts the oldest ones once they exceed
285
+ * capacity. With `{ force: true }`, removes all of them regardless of capacity.
266
286
  *
267
287
  * @returns Number of styles evicted.
268
288
  */
@@ -543,8 +563,10 @@ function collectInternalsRSC(rscCache) {
543
563
  function collectAncillaryRSC(rscCache, styles) {
544
564
  const parts = [];
545
565
  const usedKf = getUsedKeyframes(styles);
546
- if (usedKf) for (const [name, steps] of Object.entries(usedKf)) {
547
- const key = `__kf:${name}:${JSON.stringify(steps)}`;
566
+ const rscKeyframeNames = usedKf ? resolveKeyframesNames(usedKf) : null;
567
+ if (usedKf && rscKeyframeNames) for (const [authored, steps] of Object.entries(usedKf)) {
568
+ const name = rscKeyframeNames.get(authored);
569
+ const key = `__kf:${name}`;
548
570
  if (!rscCache.emittedKeys.has(key)) {
549
571
  rscCache.emittedKeys.add(key);
550
572
  parts.push(formatKeyframesCSS(name, steps));
@@ -604,20 +626,23 @@ function computeStylesRSC(styles, chunkMap, stableStyles) {
604
626
  const rscCache = getRSCCache();
605
627
  const cssParts = [];
606
628
  const classNames = [];
629
+ const rscUsedKf = getUsedKeyframes(styles);
630
+ const rscKeyframeNames = rscUsedKf ? resolveKeyframesNames(rscUsedKf) : null;
607
631
  const pendingCSS = flushPendingCSS(rscCache);
608
632
  if (pendingCSS) cssParts.push(pendingCSS);
609
633
  const internalsCSS = collectInternalsRSC(rscCache);
610
634
  if (internalsCSS) cssParts.push(internalsCSS);
611
635
  for (const [chunkName, chunkStyleKeys] of chunkMap) {
612
636
  if (chunkStyleKeys.length === 0) continue;
613
- const { className, isNew } = rscAllocateClassName(rscCache, generateChunkCacheKey(styles, chunkName, chunkStyleKeys, stableStyles));
637
+ const baseKey = generateChunkCacheKey(styles, chunkName, chunkStyleKeys, stableStyles);
638
+ const renderResult = renderStylesForChunk(styles, chunkName, chunkStyleKeys);
639
+ if (renderResult.rules.length === 0) continue;
640
+ const { rules, cacheKey } = applyKeyframeNames(renderResult.rules, baseKey, rscKeyframeNames);
641
+ const { className, isNew } = rscAllocateClassName(rscCache, cacheKey);
614
642
  classNames.push(className);
615
643
  if (isNew) {
616
- const renderResult = renderStylesForChunk(styles, chunkName, chunkStyleKeys);
617
- if (renderResult.rules.length > 0) {
618
- const css = formatRules(renderResult.rules, className);
619
- if (css) cssParts.push(css);
620
- }
644
+ const css = formatRules(rules, className);
645
+ if (css) cssParts.push(css);
621
646
  }
622
647
  }
623
648
  const ancillaryCSS = collectAncillaryRSC(rscCache, styles);
@@ -644,23 +669,26 @@ function getUsedKeyframes(styles) {
644
669
  /**
645
670
  * Process a chunk on the SSR path: allocate via collector, render, collect CSS.
646
671
  */
647
- function processChunkSSR(collector, styles, chunkName, styleKeys, stableStyles) {
672
+ function processChunkSSR(collector, styles, chunkName, styleKeys, stableStyles, keyframeNames) {
648
673
  if (styleKeys.length === 0) return null;
649
- const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys, stableStyles);
674
+ const baseKey = generateChunkCacheKey(styles, chunkName, styleKeys, stableStyles);
675
+ const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);
676
+ if (renderResult.rules.length === 0) return null;
677
+ const { animations, rules, cacheKey } = applyKeyframeNames(renderResult.rules, baseKey, keyframeNames);
650
678
  const { className, isNewAllocation } = collector.allocateClassName(cacheKey);
651
679
  if (isNewAllocation) {
652
- const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);
653
- if (renderResult.rules.length > 0) {
654
- collector.collectChunk(cacheKey, className, renderResult.rules);
655
- return {
656
- name: chunkName,
657
- styleKeys,
658
- cacheKey,
659
- renderResult,
660
- className
661
- };
662
- }
663
- return null;
680
+ collector.collectChunk(cacheKey, className, rules);
681
+ return {
682
+ name: chunkName,
683
+ styleKeys,
684
+ cacheKey,
685
+ renderResult: {
686
+ ...renderResult,
687
+ rules
688
+ },
689
+ className,
690
+ animations
691
+ };
664
692
  }
665
693
  return {
666
694
  name: chunkName,
@@ -671,57 +699,64 @@ function processChunkSSR(collector, styles, chunkName, styleKeys, stableStyles)
671
699
  };
672
700
  }
673
701
  /**
702
+ * Point a chunk's rules at the resolved keyframe names, and fold those names
703
+ * into its cache key.
704
+ *
705
+ * Both halves matter, and both have to happen before the rules are written
706
+ * anywhere: the declarations have to name the animation that will exist, and
707
+ * the key has to distinguish two components that authored the same shorthand
708
+ * over different definitions. Shared by the client and the server so they
709
+ * cannot disagree about either.
710
+ */
711
+ function applyKeyframeNames(ruleset, baseKey, keyframeNames) {
712
+ if (!keyframeNames || keyframeNames.size === 0) return {
713
+ animations: [],
714
+ rules: ruleset,
715
+ cacheKey: baseKey
716
+ };
717
+ const animations = [...keyframeNames.keys()].filter((authored) => ruleset.some((rule) => referencesAnimation(rule.declarations, authored)));
718
+ if (animations.length === 0) return {
719
+ animations,
720
+ rules: ruleset,
721
+ cacheKey: baseKey
722
+ };
723
+ return {
724
+ animations,
725
+ rules: ruleset.map((rule) => ({
726
+ ...rule,
727
+ declarations: replaceAnimationNames(rule.declarations, keyframeNames)
728
+ })),
729
+ cacheKey: `${baseKey}\u0000kf:${animations.map((authored) => `${authored}=${keyframeNames.get(authored)}`).sort().join(",")}`
730
+ };
731
+ }
732
+ /**
674
733
  * Process a chunk on the client: render, allocate className, and inject
675
734
  * CSS synchronously. The injector's cache makes this idempotent.
676
735
  */
677
- function processChunkSync(styles, chunkName, styleKeys, stableStyles, root) {
736
+ function processChunkSync(styles, chunkName, styleKeys, stableStyles, root, keyframeNames) {
678
737
  if (styleKeys.length === 0) return null;
679
738
  const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys, stableStyles);
680
739
  const renderResult = renderStylesForChunk(styles, chunkName, styleKeys, cacheKey);
681
740
  if (renderResult.rules.length === 0) return null;
682
- const { className } = inject(renderResult.rules, {
683
- cacheKey,
684
- root
741
+ const { animations, rules, cacheKey: injectKey } = applyKeyframeNames(renderResult.rules, cacheKey, keyframeNames);
742
+ const { className } = inject(rules, {
743
+ cacheKey: injectKey,
744
+ root,
745
+ pin: false
685
746
  });
686
747
  return {
687
748
  name: chunkName,
688
749
  styleKeys,
689
- cacheKey,
690
- renderResult,
691
- className
750
+ cacheKey: injectKey,
751
+ renderResult: {
752
+ ...renderResult,
753
+ rules
754
+ },
755
+ className,
756
+ animations
692
757
  };
693
758
  }
694
759
  /**
695
- * Inject keyframes synchronously and return a name replacement map.
696
- * On the client, keyframes are injected into the DOM.
697
- */
698
- function injectKeyframesSync(usedKeyframes, root) {
699
- let nameMap = null;
700
- for (const [name, steps] of Object.entries(usedKeyframes)) {
701
- const injectedName = keyframes(steps, {
702
- name,
703
- root
704
- }).toString();
705
- if (injectedName !== name) {
706
- if (!nameMap) nameMap = /* @__PURE__ */ new Map();
707
- nameMap.set(name, injectedName);
708
- }
709
- }
710
- return nameMap;
711
- }
712
- /**
713
- * Inject chunk rules synchronously, replacing animation names if needed.
714
- */
715
- function injectChunkRulesSync(chunks, nameMap, root) {
716
- for (const chunk of chunks) if (chunk.renderResult.rules.length > 0) inject(nameMap ? chunk.renderResult.rules.map((rule) => ({
717
- ...rule,
718
- declarations: replaceAnimationNames(rule.declarations, nameMap)
719
- })) : chunk.renderResult.rules, {
720
- cacheKey: chunk.cacheKey,
721
- root
722
- });
723
- }
724
- /**
725
760
  * Inject all ancillary rules (properties, font-faces, counter-styles) synchronously.
726
761
  */
727
762
  function injectAncillarySync(styles, root) {
@@ -753,9 +788,12 @@ function injectAncillarySync(styles, root) {
753
788
  */
754
789
  function collectAncillarySSR(collector, styles, chunks) {
755
790
  const usedKf = getUsedKeyframes(styles);
756
- if (usedKf) for (const [name, steps] of Object.entries(usedKf)) {
757
- const css = formatKeyframesCSS(name, steps);
758
- collector.collectKeyframes(name, css);
791
+ if (usedKf) {
792
+ const names = resolveKeyframesNames(usedKf);
793
+ for (const [authored, steps] of Object.entries(usedKf)) {
794
+ const name = names.get(authored);
795
+ collector.collectKeyframes(name, formatKeyframesCSS(name, steps));
796
+ }
759
797
  }
760
798
  if (hasLocalProperties(styles)) {
761
799
  const localProperties = extractLocalProperties(styles);
@@ -819,8 +857,10 @@ function computeStyles(styles, options) {
819
857
  const chunks = [];
820
858
  if (collector) {
821
859
  collector.collectInternals();
860
+ const ssrKf = getUsedKeyframes(resolved);
861
+ const ssrKeyframeNames = ssrKf ? resolveKeyframesNames(ssrKf) : null;
822
862
  for (const [chunkName, chunkStyleKeys] of chunkMap) {
823
- const chunk = processChunkSSR(collector, resolved, chunkName, chunkStyleKeys, stableStyles);
863
+ const chunk = processChunkSSR(collector, resolved, chunkName, chunkStyleKeys, stableStyles, ssrKeyframeNames);
824
864
  if (chunk) chunks.push(chunk);
825
865
  }
826
866
  collectAncillarySSR(collector, resolved, chunks);
@@ -829,12 +869,16 @@ function computeStyles(styles, options) {
829
869
  const root = options?.root;
830
870
  injectAncillarySync(resolved, root);
831
871
  const usedKf = getUsedKeyframes(resolved);
832
- const nameMap = usedKf ? injectKeyframesSync(usedKf, root) : null;
872
+ const keyframeNames = usedKf ? resolveKeyframesNames(usedKf) : null;
873
+ const keyframeKeys = usedKf && keyframeNames ? holdKeyframes(usedKf, keyframeNames, { root }) : null;
833
874
  for (const [chunkName, chunkStyleKeys] of chunkMap) {
834
- const chunk = processChunkSync(resolved, chunkName, chunkStyleKeys, stableStyles, root);
875
+ const chunk = processChunkSync(resolved, chunkName, chunkStyleKeys, stableStyles, root, keyframeNames);
835
876
  if (chunk) chunks.push(chunk);
836
877
  }
837
- if (nameMap) injectChunkRulesSync(chunks, nameMap, root);
878
+ if (keyframeKeys) for (const chunk of chunks) for (const authored of chunk.animations ?? []) {
879
+ const key = keyframeKeys.get(authored);
880
+ if (key) ownKeyframes(key, chunk.className, { root });
881
+ }
838
882
  for (const chunk of chunks) touch(chunk.className, { root });
839
883
  }
840
884
  if (chunks.length === 0) return EMPTY_RESULT;
@@ -1115,17 +1159,41 @@ function countRules(css) {
1115
1159
  function sortTastyClasses(classes) {
1116
1160
  return Array.from(classes).sort((a, b) => a.localeCompare(b));
1117
1161
  }
1118
- function getRegistry(root = document) {
1119
- return injector.instance._sheetManager?.getRegistry(root);
1162
+ /**
1163
+ * The root these helpers read, or `null` where there is no DOM.
1164
+ *
1165
+ * `document` used to be a default parameter value, and a default is evaluated
1166
+ * at the call site — so every read below threw a bare `ReferenceError` under
1167
+ * Node, taking out five of the eight public methods. A debug utility must not
1168
+ * be able to fail an SSR render because a call was left in, so the DOM-less
1169
+ * case reports an empty result and says why.
1170
+ */
1171
+ function defaultRoot() {
1172
+ return typeof document === "undefined" ? null : document;
1120
1173
  }
1121
- function getUnusedClasses(root = document) {
1122
- const registry = getRegistry(root);
1123
- if (!registry) return [];
1124
- const result = [];
1125
- for (const [cls, rc] of registry.refCounts) if (rc === 0) result.push(cls);
1126
- return sortTastyClasses(result);
1174
+ let warnedNoDom = false;
1175
+ /** Say once why the numbers are empty. Silent under `{ raw: true }`. */
1176
+ function warnNoDom(raw) {
1177
+ if (raw || warnedNoDom) return;
1178
+ warnedNoDom = true;
1179
+ console.warn("[Tasty] tastyDebug reads the DOM and this environment has none, so the result is empty. During SSR, read the ServerStyleCollector instead.");
1127
1180
  }
1128
- function findDomTastyClasses(root = document) {
1181
+ /**
1182
+ * The registry for `root`, with every queued write landed first.
1183
+ *
1184
+ * Every injector read API is a flush point, and the reads below reach past
1185
+ * those APIs straight into the registry and the sheet manager. Without this
1186
+ * they would report a batch window's contents as absent — a rule that is
1187
+ * enqueued but not yet in a sheet is missing from `globalRules`, from the
1188
+ * sheets, and from anything counting either.
1189
+ */
1190
+ function getRegistry(root = defaultRoot()) {
1191
+ if (!root) return void 0;
1192
+ flushStyles();
1193
+ return injector.instance._sheetManager?.getRegistry(root);
1194
+ }
1195
+ function findDomTastyClasses(root = defaultRoot()) {
1196
+ if (!root) return [];
1129
1197
  const classes = /* @__PURE__ */ new Set();
1130
1198
  const elements = root.querySelectorAll?.("[class]") || [];
1131
1199
  const classRegex = tastyClassRegex(getNamePrefix());
@@ -1137,6 +1205,49 @@ function findDomTastyClasses(root = document) {
1137
1205
  });
1138
1206
  return sortTastyClasses(classes);
1139
1207
  }
1208
+ /**
1209
+ * Everything this injector holds in `root`, in the order the engine applies it,
1210
+ * with the sources kept byte-for-byte — trimming would report a total smaller
1211
+ * than one of its own parts whenever raw CSS has edge whitespace.
1212
+ */
1213
+ function getAllCSS(root = defaultRoot()) {
1214
+ const registry = getRegistry(root);
1215
+ const sheetManager = injector.instance._sheetManager;
1216
+ if (!root || !registry || !sheetManager) return "";
1217
+ return sheetManager.getOwnedCSSInOrder(registry, root).join("\n");
1218
+ }
1219
+ /**
1220
+ * The injector's own readers fall back to `document` when `root` is omitted, so
1221
+ * they have to be reached with a real root or not at all.
1222
+ */
1223
+ function cssTextForClasses(classNames, root) {
1224
+ if (!root) return "";
1225
+ return injector.instance.getCSSTextForClasses(classNames, { root });
1226
+ }
1227
+ function getInjectorMetrics(root) {
1228
+ if (!root) return null;
1229
+ return injector.instance.getMetrics({ root });
1230
+ }
1231
+ /**
1232
+ * Injected classes that no element carries and nobody pinned — the exact set
1233
+ * `gc({ force: true })` would delete.
1234
+ *
1235
+ * Deliberately borrowed from the injector rather than recomputed here: the two
1236
+ * drifted apart once before, when this file still read "unused" off the pin
1237
+ * counts the render path had stopped maintaining.
1238
+ */
1239
+ function getUnusedClasses(root = defaultRoot()) {
1240
+ if (!root) return [];
1241
+ return sortTastyClasses(injector.instance.getUnusedClasses({ root }));
1242
+ }
1243
+ /** Every class this injector holds CSS for in `root`. */
1244
+ function getOwnedClasses(root = defaultRoot()) {
1245
+ const registry = getRegistry(root);
1246
+ if (!registry) return [];
1247
+ const owned = [];
1248
+ for (const [className, info] of registry.rules) if (info.sheetIndex >= 0) owned.push(className);
1249
+ return sortTastyClasses(owned);
1250
+ }
1140
1251
  function prettifyCSS(css) {
1141
1252
  if (!css || !css.trim()) return "";
1142
1253
  const out = [];
@@ -1197,15 +1308,15 @@ function extractChunkName(cacheKey) {
1197
1308
  }
1198
1309
  return null;
1199
1310
  }
1200
- function getChunkForClass(className, root = document) {
1311
+ function getChunkForClass(className, root = defaultRoot()) {
1201
1312
  const registry = getRegistry(root);
1202
1313
  if (!registry) return null;
1203
1314
  for (const [key, cn] of registry.cacheKeyToClassName) if (cn === className) return extractChunkName(key);
1204
1315
  return null;
1205
1316
  }
1206
- function buildChunkBreakdown(root = document) {
1317
+ function buildChunkBreakdown(root = defaultRoot()) {
1207
1318
  const registry = getRegistry(root);
1208
- if (!registry) return {
1319
+ if (!root || !registry) return {
1209
1320
  byChunk: {},
1210
1321
  totalChunkTypes: 0,
1211
1322
  totalClasses: 0
@@ -1231,15 +1342,36 @@ function buildChunkBreakdown(root = document) {
1231
1342
  totalClasses
1232
1343
  };
1233
1344
  }
1234
- function getGlobalTypeCSS(type, root = document) {
1345
+ /**
1346
+ * Every prefix `registry.globalRules` is keyed by. Anything missing here is a
1347
+ * rule the summary would hold but never count, which is how the totals stopped
1348
+ * adding up the first time.
1349
+ */
1350
+ const GLOBAL_RULE_PREFIXES = {
1351
+ global: "global:",
1352
+ property: "property:",
1353
+ fontFace: "fontface:",
1354
+ counterStyle: "counterstyle:",
1355
+ function: "function:"
1356
+ };
1357
+ function getGlobalTypeCSS(type, root = defaultRoot()) {
1235
1358
  const registry = getRegistry(root);
1236
- if (!registry) return {
1359
+ if (!root || !registry) return {
1237
1360
  css: "",
1238
1361
  ruleCount: 0,
1239
1362
  size: 0
1240
1363
  };
1241
1364
  const chunks = [];
1242
1365
  let rc = 0;
1366
+ if (type === "raw") {
1367
+ const css = injector.instance.getRawCSSText({ root });
1368
+ const sheetManager = injector.instance._sheetManager;
1369
+ return {
1370
+ css: prettifyCSS(css),
1371
+ ruleCount: sheetManager?.getRawRuleCount(root) ?? 0,
1372
+ size: css.length
1373
+ };
1374
+ }
1243
1375
  if (type === "keyframes") for (const [, entry] of registry.keyframesCache) {
1244
1376
  const info = entry.info;
1245
1377
  const sheetInfo = registry.sheets[info.sheetIndex];
@@ -1257,7 +1389,7 @@ function getGlobalTypeCSS(type, root = document) {
1257
1389
  }
1258
1390
  }
1259
1391
  else {
1260
- const prefix = type === "global" ? "global:" : type === "raw" ? "raw:" : "property:";
1392
+ const prefix = GLOBAL_RULE_PREFIXES[type];
1261
1393
  for (const [key, ri] of registry.globalRules) {
1262
1394
  if (!key.startsWith(prefix)) continue;
1263
1395
  const sheetInfo = registry.sheets[ri.sheetIndex];
@@ -1286,7 +1418,7 @@ function getGlobalTypeCSS(type, root = document) {
1286
1418
  size: raw.length
1287
1419
  };
1288
1420
  }
1289
- function getSourceCssForClasses(classNames, root = document) {
1421
+ function getSourceCssForClasses(classNames, root = defaultRoot()) {
1290
1422
  const registry = getRegistry(root);
1291
1423
  if (!registry) return null;
1292
1424
  const chunks = [];
@@ -1300,7 +1432,7 @@ function getSourceCssForClasses(classNames, root = document) {
1300
1432
  }
1301
1433
  return found ? chunks.join("\n") : null;
1302
1434
  }
1303
- function getDefs(root = document) {
1435
+ function getDefs(root = defaultRoot()) {
1304
1436
  const registry = getRegistry(root);
1305
1437
  let properties = [];
1306
1438
  if (registry?.injectedProperties) properties = Array.from(registry.injectedProperties.keys()).sort();
@@ -1330,7 +1462,11 @@ const CHUNK_ORDER = [
1330
1462
  ];
1331
1463
  const tastyDebug = {
1332
1464
  css(target, opts) {
1333
- const { root = document, prettify = true, raw = false, source = false } = opts || {};
1465
+ const { root = defaultRoot(), prettify = true, raw = false, source = false } = opts || {};
1466
+ if (!root) {
1467
+ warnNoDom(raw);
1468
+ return "";
1469
+ }
1334
1470
  let css = "";
1335
1471
  const classRegex = tastyClassRegex(getNamePrefix());
1336
1472
  if (source && typeof target === "string" && classRegex.test(target)) {
@@ -1347,7 +1483,7 @@ const tastyDebug = {
1347
1483
  if (!raw) console.warn("[Tasty] source CSS not available. Falling back to live CSSOM.");
1348
1484
  css = injector.instance.getCSSTextForClasses(target, { root });
1349
1485
  }
1350
- } else if (typeof target === "string") if (target === "all") css = injector.instance.getCSSText({ root });
1486
+ } else if (typeof target === "string") if (target === "all") css = getAllCSS(root);
1351
1487
  else if (target === "global") {
1352
1488
  css = getGlobalTypeCSS("global", root).css;
1353
1489
  return css;
@@ -1376,8 +1512,9 @@ const tastyDebug = {
1376
1512
  return result;
1377
1513
  },
1378
1514
  inspect(target, opts) {
1379
- const { root = document, raw = false } = opts || {};
1380
- const element = typeof target === "string" ? root.querySelector?.(target) : target;
1515
+ const { root = defaultRoot(), raw = false } = opts || {};
1516
+ const element = !root ? null : typeof target === "string" ? root.querySelector?.(target) : target;
1517
+ if (!root) warnNoDom(raw);
1381
1518
  if (!element) {
1382
1519
  const empty = {
1383
1520
  element: null,
@@ -1387,7 +1524,7 @@ const tastyDebug = {
1387
1524
  size: 0,
1388
1525
  rules: 0
1389
1526
  };
1390
- if (!raw) console.warn("[Tasty] debug.inspect: element not found");
1527
+ if (!raw && root) console.warn("[Tasty] debug.inspect: element not found");
1391
1528
  return empty;
1392
1529
  }
1393
1530
  const classList = element.getAttribute("class") || "";
@@ -1397,7 +1534,7 @@ const tastyDebug = {
1397
1534
  className,
1398
1535
  chunkName: getChunkForClass(className, root)
1399
1536
  }));
1400
- const css = getCSSTextForNode(element, { root });
1537
+ const css = getCSSTextForNode(element, { root: root ?? void 0 });
1401
1538
  const rules = countRules(css);
1402
1539
  const result = {
1403
1540
  element,
@@ -1420,37 +1557,60 @@ const tastyDebug = {
1420
1557
  return result;
1421
1558
  },
1422
1559
  summary(opts) {
1423
- const { root = document, raw = false } = opts || {};
1560
+ const { root = defaultRoot(), raw = false } = opts || {};
1561
+ if (!root) warnNoDom(raw);
1424
1562
  const activeClasses = findDomTastyClasses(root);
1425
1563
  const unusedClasses = getUnusedClasses(root);
1426
- const totalStyledClasses = [...activeClasses, ...unusedClasses];
1427
- const activeCSS = injector.instance.getCSSTextForClasses(activeClasses, { root });
1428
- const unusedCSS = injector.instance.getCSSTextForClasses(unusedClasses, { root });
1429
- const allCSS = injector.instance.getCSSText({ root });
1564
+ const ownedClasses = getOwnedClasses(root);
1565
+ const totalStyledClasses = sortTastyClasses(new Set([...activeClasses, ...ownedClasses]));
1566
+ const unusedSet = new Set(unusedClasses);
1567
+ const activeSet = new Set(activeClasses);
1568
+ const hotClasses = ownedClasses.filter((className) => !activeSet.has(className) && !unusedSet.has(className));
1569
+ const hotCSS = cssTextForClasses(hotClasses, root);
1570
+ const activeCSS = cssTextForClasses(activeClasses, root);
1571
+ const unusedCSS = cssTextForClasses(unusedClasses, root);
1572
+ const allCSS = getAllCSS(root);
1430
1573
  const activeRuleCount = countRules(activeCSS);
1431
1574
  const unusedRuleCount = countRules(unusedCSS);
1432
1575
  const globalData = getGlobalTypeCSS("global", root);
1433
1576
  const rawData = getGlobalTypeCSS("raw", root);
1434
1577
  const kfData = getGlobalTypeCSS("keyframes", root);
1435
1578
  const propData = getGlobalTypeCSS("property", root);
1436
- const totalRuleCount = activeRuleCount + unusedRuleCount + globalData.ruleCount + rawData.ruleCount + kfData.ruleCount + propData.ruleCount;
1437
- const metrics = injector.instance.getMetrics({ root });
1579
+ const atRuleData = [
1580
+ "fontFace",
1581
+ "counterStyle",
1582
+ "function"
1583
+ ].reduce((all, type) => {
1584
+ const data = getGlobalTypeCSS(type, root);
1585
+ return {
1586
+ css: data.css ? `${all.css}\n${data.css}`.trim() : all.css,
1587
+ ruleCount: all.ruleCount + data.ruleCount,
1588
+ size: all.size + data.size
1589
+ };
1590
+ }, {
1591
+ css: "",
1592
+ ruleCount: 0,
1593
+ size: 0
1594
+ });
1595
+ const totalRuleCount = activeRuleCount + unusedRuleCount + countRules(hotCSS) + globalData.ruleCount + atRuleData.ruleCount + rawData.ruleCount + kfData.ruleCount + propData.ruleCount;
1596
+ const metrics = getInjectorMetrics(root);
1438
1597
  const defs = getDefs(root);
1439
1598
  const chunkBreakdown = buildChunkBreakdown(root);
1440
1599
  const summary = {
1441
1600
  activeClasses,
1442
1601
  unusedClasses,
1602
+ hotClasses,
1443
1603
  totalStyledClasses,
1444
1604
  activeCSSSize: activeCSS.length,
1445
1605
  unusedCSSSize: unusedCSS.length,
1446
- globalCSSSize: globalData.size,
1606
+ globalCSSSize: globalData.size + atRuleData.size,
1447
1607
  rawCSSSize: rawData.size,
1448
1608
  keyframesCSSSize: kfData.size,
1449
1609
  propertyCSSSize: propData.size,
1450
1610
  totalCSSSize: allCSS.length,
1451
1611
  activeRuleCount,
1452
1612
  unusedRuleCount,
1453
- globalRuleCount: globalData.ruleCount,
1613
+ globalRuleCount: globalData.ruleCount + atRuleData.ruleCount,
1454
1614
  rawRuleCount: rawData.ruleCount,
1455
1615
  keyframesRuleCount: kfData.ruleCount,
1456
1616
  propertyRuleCount: propData.ruleCount,
@@ -1464,7 +1624,8 @@ const tastyDebug = {
1464
1624
  console.group("Tasty Summary");
1465
1625
  console.log(`Active: ${activeClasses.length} classes, ${activeRuleCount} rules, ${fmtSize(activeCSS.length)}`);
1466
1626
  console.log(`Unused: ${unusedClasses.length} classes, ${unusedRuleCount} rules, ${fmtSize(unusedCSS.length)}`);
1467
- console.log(`Global: ${globalData.ruleCount} rules, ${fmtSize(globalData.size)}`);
1627
+ if (hotClasses.length) console.log(`Held: ${hotClasses.length} classes, ${countRules(hotCSS)} rules, ${fmtSize(hotCSS.length)} (not rendered, not yet collectable)`);
1628
+ console.log(`Global: ${globalData.ruleCount + atRuleData.ruleCount} rules, ${fmtSize(globalData.size + atRuleData.size)}`);
1468
1629
  if (rawData.ruleCount) console.log(`Raw: ${rawData.ruleCount} rules, ${fmtSize(rawData.size)}`);
1469
1630
  if (kfData.ruleCount) console.log(`Keyframes: ${kfData.ruleCount} rules, ${fmtSize(kfData.size)}`);
1470
1631
  if (propData.ruleCount) console.log(`@property: ${propData.ruleCount} rules, ${fmtSize(propData.size)}`);
@@ -1489,7 +1650,8 @@ const tastyDebug = {
1489
1650
  return summary;
1490
1651
  },
1491
1652
  chunks(opts) {
1492
- const { root = document, raw = false } = opts || {};
1653
+ const { root = defaultRoot(), raw = false } = opts || {};
1654
+ if (!root) warnNoDom(raw);
1493
1655
  const breakdown = buildChunkBreakdown(root);
1494
1656
  if (!raw) {
1495
1657
  console.group(`Chunks (${breakdown.totalChunkTypes} types, ${breakdown.totalClasses} classes)`);
@@ -1503,15 +1665,16 @@ const tastyDebug = {
1503
1665
  return breakdown;
1504
1666
  },
1505
1667
  cache(opts) {
1506
- const { root = document, raw = false } = opts || {};
1668
+ const { root = defaultRoot(), raw = false } = opts || {};
1669
+ if (!root) warnNoDom(raw);
1507
1670
  const active = findDomTastyClasses(root);
1508
1671
  const unused = getUnusedClasses(root);
1509
- const metrics = injector.instance.getMetrics({ root });
1672
+ const metrics = getInjectorMetrics(root);
1510
1673
  const status = {
1511
1674
  classes: {
1512
1675
  active,
1513
1676
  unused,
1514
- all: [...active, ...unused]
1677
+ all: sortTastyClasses(new Set([...active, ...getOwnedClasses(root)]))
1515
1678
  },
1516
1679
  metrics
1517
1680
  };
@@ -1528,7 +1691,9 @@ const tastyDebug = {
1528
1691
  return status;
1529
1692
  },
1530
1693
  cleanup(opts) {
1531
- injector.instance.cleanup(opts?.root);
1694
+ const root = opts?.root ?? defaultRoot();
1695
+ if (!root) return;
1696
+ injector.instance.cleanup(root);
1532
1697
  },
1533
1698
  help() {
1534
1699
  console.log(`tastyDebug API:
@@ -1550,7 +1715,8 @@ Options: { raw: true } suppresses logging, { root: shadowRoot } targets Shadow D
1550
1715
  }
1551
1716
  }
1552
1717
  };
1553
- function getPageCSS(root = document) {
1718
+ function getPageCSS(root = defaultRoot()) {
1719
+ if (!root) return "";
1554
1720
  const chunks = [];
1555
1721
  try {
1556
1722
  if ("styleSheets" in root) for (const sheet of Array.from(root.styleSheets)) try {
@@ -1561,6 +1727,6 @@ function getPageCSS(root = document) {
1561
1727
  }
1562
1728
  if (typeof window !== "undefined" && isDevEnv()) tastyDebug.install();
1563
1729
  //#endregion
1564
- export { property as A, getRawCSSText as C, injector as D, injectRawCSS as E, ChunkSheetRegistry as M, chunkSheetRegistry as N, isPropertyDefined as O, resolveFunctionColor as P, 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 };
1730
+ export { keyframes as A, getRawCSSText as C, injectRawCSS as D, injectGlobal as E, chunkSheetRegistry as F, resolveFunctionColor as I, property as M, touch as N, injector as O, ChunkSheetRegistry as P, getCSSTextForNode as S, inject 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, ownKeyframes as j, isPropertyDefined 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, holdKeyframes as w, getCSSText as x, func as y };
1565
1731
 
1566
- //# sourceMappingURL=core-D7s7u-k1.js.map
1732
+ //# sourceMappingURL=core-DGm0CFHP.js.map