@tenphi/tasty 1.4.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +8 -7
  2. package/dist/compute-styles.js +6 -28
  3. package/dist/compute-styles.js.map +1 -1
  4. package/dist/config.d.ts +3 -2
  5. package/dist/config.js.map +1 -1
  6. package/dist/core/index.d.ts +2 -2
  7. package/dist/core/index.js +2 -2
  8. package/dist/hooks/useCounterStyle.d.ts +3 -17
  9. package/dist/hooks/useCounterStyle.js +54 -35
  10. package/dist/hooks/useCounterStyle.js.map +1 -1
  11. package/dist/hooks/useFontFace.d.ts +3 -1
  12. package/dist/hooks/useFontFace.js +21 -24
  13. package/dist/hooks/useFontFace.js.map +1 -1
  14. package/dist/hooks/useGlobalStyles.d.ts +18 -2
  15. package/dist/hooks/useGlobalStyles.js +51 -40
  16. package/dist/hooks/useGlobalStyles.js.map +1 -1
  17. package/dist/hooks/useKeyframes.d.ts +4 -2
  18. package/dist/hooks/useKeyframes.js +41 -50
  19. package/dist/hooks/useKeyframes.js.map +1 -1
  20. package/dist/hooks/useProperty.d.ts +4 -2
  21. package/dist/hooks/useProperty.js +29 -41
  22. package/dist/hooks/useProperty.js.map +1 -1
  23. package/dist/hooks/useRawCSS.d.ts +13 -44
  24. package/dist/hooks/useRawCSS.js +90 -21
  25. package/dist/hooks/useRawCSS.js.map +1 -1
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.js +2 -2
  28. package/dist/injector/index.d.ts +5 -10
  29. package/dist/injector/index.js +5 -12
  30. package/dist/injector/index.js.map +1 -1
  31. package/dist/injector/injector.d.ts +11 -13
  32. package/dist/injector/injector.js +50 -73
  33. package/dist/injector/injector.js.map +1 -1
  34. package/dist/injector/sheet-manager.js +2 -1
  35. package/dist/injector/sheet-manager.js.map +1 -1
  36. package/dist/injector/types.d.ts +21 -28
  37. package/dist/rsc-cache.js +81 -0
  38. package/dist/rsc-cache.js.map +1 -0
  39. package/dist/ssr/astro-client.d.ts +1 -0
  40. package/dist/ssr/astro-client.js +24 -0
  41. package/dist/ssr/astro-client.js.map +1 -0
  42. package/dist/ssr/astro-middleware.d.ts +15 -0
  43. package/dist/ssr/astro-middleware.js +19 -0
  44. package/dist/ssr/astro-middleware.js.map +1 -0
  45. package/dist/ssr/astro.d.ts +85 -8
  46. package/dist/ssr/astro.js +110 -20
  47. package/dist/ssr/astro.js.map +1 -1
  48. package/dist/ssr/collect-auto-properties.js +28 -9
  49. package/dist/ssr/collect-auto-properties.js.map +1 -1
  50. package/dist/ssr/index.d.ts +1 -1
  51. package/dist/tasty.d.ts +1 -1
  52. package/dist/utils/deps-equal.js +15 -0
  53. package/dist/utils/deps-equal.js.map +1 -0
  54. package/dist/utils/hash.js +14 -0
  55. package/dist/utils/hash.js.map +1 -0
  56. package/docs/adoption.md +1 -1
  57. package/docs/comparison.md +1 -1
  58. package/docs/configuration.md +1 -1
  59. package/docs/design-system.md +1 -1
  60. package/docs/dsl.md +21 -6
  61. package/docs/getting-started.md +1 -1
  62. package/docs/injector.md +25 -24
  63. package/docs/methodology.md +1 -1
  64. package/docs/runtime.md +12 -31
  65. package/docs/ssr.md +117 -36
  66. package/docs/tasty-static.md +1 -1
  67. package/package.json +8 -2
@@ -15,8 +15,6 @@ var StyleInjector = class StyleInjector {
15
15
  sheetManager;
16
16
  config;
17
17
  globalRuleCounter = 0;
18
- lastGCTime = 0;
19
- backgroundSweepTimeout = null;
20
18
  pendingGCHandle = null;
21
19
  /** @internal — exposed for debug utilities only */
22
20
  get _sheetManager() {
@@ -25,21 +23,6 @@ var StyleInjector = class StyleInjector {
25
23
  constructor(config = {}) {
26
24
  this.config = config;
27
25
  this.sheetManager = new SheetManager(config);
28
- if (config.gc?.auto && typeof document !== "undefined") {
29
- const interval = config.gc.autoInterval ?? 3e5;
30
- const scheduleNext = () => {
31
- this.backgroundSweepTimeout = setTimeout(() => {
32
- const doSweep = () => {
33
- this.sheetManager.pruneDisconnectedRoots();
34
- for (const root of this.sheetManager.getActiveRoots()) this.gc({ root });
35
- scheduleNext();
36
- };
37
- if (typeof requestIdleCallback !== "undefined") requestIdleCallback(() => doSweep());
38
- else doSweep();
39
- }, interval);
40
- };
41
- scheduleNext();
42
- }
43
26
  }
44
27
  /**
45
28
  * Allocate a className for a cacheKey without injecting styles yet.
@@ -464,11 +447,12 @@ var StyleInjector = class StyleInjector {
464
447
  }
465
448
  }
466
449
  }
467
- static TOUCH_THROTTLE_MS = 5e3;
468
450
  static TASTY_CLASS_RE = /^t\d+$/;
469
451
  /**
470
452
  * Record a render-time usage hit for one or more classNames.
471
453
  * Handles space-separated multi-chunk classNames.
454
+ * When the global touch counter reaches `touchInterval`, schedules a GC
455
+ * via `requestIdleCallback`.
472
456
  * No-op on the server.
473
457
  */
474
458
  touch(className, options) {
@@ -482,22 +466,37 @@ var StyleInjector = class StyleInjector {
482
466
  if (!StyleInjector.TASTY_CLASS_RE.test(cls)) continue;
483
467
  if (!registry.rules.has(cls)) continue;
484
468
  const entry = registry.usageMap.get(cls);
485
- if (entry) {
486
- entry.hitCount++;
487
- if (now - entry.lastUsedAt > StyleInjector.TOUCH_THROTTLE_MS) entry.lastUsedAt = now;
488
- } else registry.usageMap.set(cls, {
489
- hitCount: 1,
490
- lastUsedAt: now
491
- });
469
+ if (entry) entry.lastTouchedAt = now;
470
+ else registry.usageMap.set(cls, { lastTouchedAt: now });
471
+ registry.touchCount++;
492
472
  }
473
+ const touchInterval = this.config.gc.touchInterval ?? 1e3;
474
+ if (registry.touchCount >= touchInterval) {
475
+ registry.touchCount = 0;
476
+ this.scheduleGC();
477
+ }
478
+ }
479
+ /**
480
+ * Schedule a GC via `requestIdleCallback` (or synchronously as fallback).
481
+ * Runs GC on all active roots. Avoids double-scheduling via `pendingGCHandle`.
482
+ */
483
+ scheduleGC() {
484
+ if (this.pendingGCHandle != null) return;
485
+ const runGC = () => {
486
+ this.pendingGCHandle = null;
487
+ this.sheetManager.pruneDisconnectedRoots();
488
+ for (const root of this.sheetManager.getActiveRoots()) this.gc({ root });
489
+ };
490
+ if (typeof requestIdleCallback !== "undefined") this.pendingGCHandle = requestIdleCallback(() => runGC());
491
+ else runGC();
493
492
  }
494
493
  /**
495
494
  * Synchronous garbage collection.
496
495
  *
497
- * 1. Scans the DOM for live tasty classNames (safety guard).
498
- * 2. Scores each non-live className via popularity-weighted TTL.
499
- * 3. Marks evictable styles with refCount = 0 and deletes them.
500
- * 4. Optionally enforces a hard `cacheCapacity` cap.
496
+ * 1. Quick upper-bound check: skip if unused count can't exceed capacity.
497
+ * 2. Scans the DOM for live tasty classNames (safety guard).
498
+ * 3. With `force: true`: deletes all unused entries inline.
499
+ * Without `force`: collects unused, sorts oldest-first, evicts over capacity.
501
500
  *
502
501
  * @returns Number of styles evicted.
503
502
  */
@@ -508,76 +507,54 @@ var StyleInjector = class StyleInjector {
508
507
  this.pendingGCHandle = null;
509
508
  }
510
509
  const root = options?.root || document;
510
+ const force = options?.force ?? false;
511
511
  const registry = this.sheetManager.getRegistry(root);
512
- const baseMaxAge = options?.baseMaxAge ?? this.config.gc?.baseMaxAge ?? 6e4;
513
- const cacheCapacity = options?.cacheCapacity ?? this.config.gc?.cacheCapacity;
514
- const now = Date.now();
512
+ const capacity = this.config.gc?.capacity ?? 1e3;
513
+ if (!force) {
514
+ let activeCount = 0;
515
+ for (const refCount of registry.refCounts.values()) if (refCount > 0) activeCount++;
516
+ if (registry.usageMap.size - activeCount <= capacity) return 0;
517
+ }
515
518
  const liveClasses = /* @__PURE__ */ new Set();
516
519
  for (const el of root.querySelectorAll("[class]")) for (const token of el.classList) if (StyleInjector.TASTY_CLASS_RE.test(token)) liveClasses.add(token);
517
520
  let swept = 0;
518
- for (const [className, usage] of registry.usageMap) {
521
+ if (force) for (const [className] of registry.usageMap) {
519
522
  if (liveClasses.has(className)) continue;
520
523
  if ((registry.refCounts.get(className) ?? 0) > 0) continue;
521
- if (now - usage.lastUsedAt > baseMaxAge * Math.log2(usage.hitCount + 1)) {
522
- registry.usageMap.delete(className);
523
- swept++;
524
- }
524
+ registry.usageMap.delete(className);
525
+ swept++;
525
526
  }
526
- if (cacheCapacity && registry.usageMap.size > cacheCapacity) {
527
- const scored = [];
527
+ else {
528
+ const unused = [];
528
529
  for (const [className, usage] of registry.usageMap) {
529
530
  if (liveClasses.has(className)) continue;
530
531
  if ((registry.refCounts.get(className) ?? 0) > 0) continue;
531
- const age = now - usage.lastUsedAt;
532
- scored.push({
532
+ unused.push({
533
533
  className,
534
- score: usage.hitCount * Math.exp(-age / baseMaxAge)
534
+ lastTouchedAt: usage.lastTouchedAt
535
535
  });
536
536
  }
537
- if (scored.length > 0) {
538
- scored.sort((a, b) => a.score - b.score);
539
- const toEvict = registry.usageMap.size - cacheCapacity;
540
- for (let i = 0; i < Math.min(toEvict, scored.length); i++) {
541
- const { className } = scored[i];
542
- registry.usageMap.delete(className);
537
+ if (unused.length > capacity) {
538
+ unused.sort((a, b) => a.lastTouchedAt - b.lastTouchedAt);
539
+ const toEvict = unused.length - capacity;
540
+ for (let i = 0; i < toEvict; i++) {
541
+ registry.usageMap.delete(unused[i].className);
543
542
  swept++;
544
543
  }
545
544
  }
546
545
  }
547
546
  if (swept > 0) this.sheetManager.forceCleanup(registry);
548
- this.lastGCTime = Date.now();
549
547
  return swept;
550
548
  }
551
549
  /**
552
- * Event-driven GC with cooldown.
553
- * Skips if called within `cooldown` ms of the last run.
554
- * Schedules the actual GC via `requestIdleCallback` when available.
555
- */
556
- maybeGC(options) {
557
- if (typeof document === "undefined") return;
558
- const cooldown = this.config.gc?.cooldown ?? 3e4;
559
- const now = Date.now();
560
- if (now - this.lastGCTime < cooldown) return;
561
- this.lastGCTime = now;
562
- if (typeof requestIdleCallback !== "undefined") this.pendingGCHandle = requestIdleCallback(() => {
563
- this.pendingGCHandle = null;
564
- this.gc(options);
565
- });
566
- else this.gc(options);
567
- }
568
- /**
569
550
  * Destroy all resources for a root
570
551
  */
571
552
  destroy(root) {
572
553
  const targetRoot = root || document;
573
554
  this.sheetManager.cleanup(targetRoot);
574
- if (this.backgroundSweepTimeout && !this.sheetManager.hasActiveRoots()) {
575
- clearTimeout(this.backgroundSweepTimeout);
576
- this.backgroundSweepTimeout = null;
577
- if (this.pendingGCHandle != null) {
578
- if (typeof cancelIdleCallback !== "undefined") cancelIdleCallback(this.pendingGCHandle);
579
- this.pendingGCHandle = null;
580
- }
555
+ if (this.pendingGCHandle != null && !this.sheetManager.hasActiveRoots()) {
556
+ if (typeof cancelIdleCallback !== "undefined") cancelIdleCallback(this.pendingGCHandle);
557
+ this.pendingGCHandle = null;
581
558
  }
582
559
  }
583
560
  };
@@ -1 +1 @@
1
- {"version":3,"file":"injector.js","names":[],"sources":["../../src/injector/injector.ts"],"sourcesContent":["/**\n * Style injector that works with structured style objects\n * Eliminates CSS string parsing for better performance\n */\n\nimport type { StyleResult } from '../pipeline';\nimport {\n getEffectiveDefinition,\n normalizePropertyDefinition,\n} from '../properties';\nimport { isDevEnv } from '../utils/is-dev-env';\nimport type { StyleValue } from '../utils/styles';\nimport { parseStyle } from '../utils/styles';\n\nimport { SheetManager } from './sheet-manager';\nimport { fontFaceContentHash, formatFontFaceDeclarations } from '../font-face';\nimport { formatCounterStyleDeclarations } from '../counter-style';\nimport type {\n CacheMetrics,\n CounterStyleDescriptors,\n FontFaceDescriptors,\n GCOptions,\n GlobalInjectResult,\n InjectResult,\n KeyframesResult,\n KeyframesSteps,\n PropertyDefinition,\n RawCSSResult,\n RootRegistry,\n StyleInjectorConfig,\n StyleRule,\n} from './types';\n\n/**\n * Generate sequential class name with format t{number}\n */\nfunction generateClassName(counter: number): string {\n return `t${counter}`;\n}\n\nexport class StyleInjector {\n private sheetManager: SheetManager;\n private config: StyleInjectorConfig;\n private globalRuleCounter = 0;\n private lastGCTime = 0;\n private backgroundSweepTimeout: ReturnType<typeof setTimeout> | null = null;\n private pendingGCHandle: ReturnType<typeof requestIdleCallback> | null = null;\n\n /** @internal — exposed for debug utilities only */\n get _sheetManager(): SheetManager {\n return this.sheetManager;\n }\n\n constructor(config: StyleInjectorConfig = {}) {\n this.config = config;\n this.sheetManager = new SheetManager(config);\n\n if (config.gc?.auto && typeof document !== 'undefined') {\n const interval = config.gc.autoInterval ?? 300_000;\n const scheduleNext = () => {\n this.backgroundSweepTimeout = setTimeout(() => {\n const doSweep = () => {\n this.sheetManager.pruneDisconnectedRoots();\n for (const root of this.sheetManager.getActiveRoots()) {\n this.gc({ root });\n }\n scheduleNext();\n };\n if (typeof requestIdleCallback !== 'undefined') {\n requestIdleCallback(() => doSweep());\n } else {\n doSweep();\n }\n }, interval);\n };\n scheduleNext();\n }\n }\n\n /**\n * Allocate a className for a cacheKey without injecting styles yet.\n * This allows separating className allocation (render phase) from style injection (insertion phase).\n */\n allocateClassName(\n cacheKey: string,\n options?: { root?: Document | ShadowRoot },\n ): { className: string; isNewAllocation: boolean } {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n // Check if we can reuse existing className for this cache key\n if (registry.cacheKeyToClassName.has(cacheKey)) {\n const className = registry.cacheKeyToClassName.get(cacheKey)!;\n return {\n className,\n isNewAllocation: false,\n };\n }\n\n // Generate new className and reserve it\n const className = generateClassName(registry.classCounter++);\n\n // Create placeholder RuleInfo to reserve the className\n const placeholderRuleInfo = {\n className,\n ruleIndex: -1, // Placeholder - will be set during actual injection\n sheetIndex: -1, // Placeholder - will be set during actual injection\n };\n\n // Store RuleInfo only once by className, and map cacheKey separately\n registry.rules.set(className, placeholderRuleInfo);\n registry.cacheKeyToClassName.set(cacheKey, className);\n\n return {\n className,\n isNewAllocation: true,\n };\n }\n\n /**\n * Inject styles from StyleResult objects\n */\n inject(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot; cacheKey?: string },\n ): InjectResult {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n if (rules.length === 0) {\n return {\n className: '',\n dispose: () => {\n /* noop */\n },\n };\n }\n\n // Rules are now in StyleRule format directly\n\n // Check if we can reuse based on cache key\n const cacheKey = options?.cacheKey;\n let className: string;\n let isPreAllocated = false;\n\n if (cacheKey && registry.cacheKeyToClassName.has(cacheKey)) {\n // Reuse existing class for this cache key\n className = registry.cacheKeyToClassName.get(cacheKey)!;\n const existingRuleInfo = registry.rules.get(className)!;\n\n // Check if this is a placeholder (pre-allocated but not yet injected)\n isPreAllocated =\n existingRuleInfo.ruleIndex === -1 && existingRuleInfo.sheetIndex === -1;\n\n if (!isPreAllocated) {\n // Already injected - just increment refCount\n const currentRefCount = registry.refCounts.get(className) || 0;\n registry.refCounts.set(className, currentRefCount + 1);\n\n // Update metrics\n if (registry.metrics) {\n registry.metrics.hits++;\n }\n\n return {\n className,\n dispose: () => this.dispose(className, registry),\n };\n }\n } else {\n // Generate new className\n className = generateClassName(registry.classCounter++);\n }\n\n // Process rules: handle needsClassName flag and apply specificity\n const rulesToInsert = rules.map((rule) => {\n let newSelector = rule.selector;\n\n // If rule needs className prepended\n if (rule.needsClassName) {\n // Handle multiple selectors (separated by ||| for OR conditions)\n const selectorParts = newSelector ? newSelector.split('|||') : [''];\n\n const classPrefix = `.${className}.${className}`;\n\n newSelector = selectorParts\n .map((part) => {\n const classSelector = part ? `${classPrefix}${part}` : classPrefix;\n\n // If there's a root prefix, add it before the class selector\n if (rule.rootPrefix) {\n return `${rule.rootPrefix} ${classSelector}`;\n }\n return classSelector;\n })\n .join(', ');\n }\n\n return {\n ...rule,\n selector: newSelector,\n needsClassName: undefined, // Remove the flag after processing\n rootPrefix: undefined, // Remove rootPrefix after processing\n };\n });\n\n // Auto-register @property for custom properties with inferable types.\n // Colors are detected by --*-color name pattern, numeric types by value.\n if (this.config.autoPropertyTypes !== false) {\n const resolver = registry.propertyTypeResolver;\n const defined = registry.injectedProperties;\n for (const rule of rulesToInsert) {\n if (!rule.declarations) continue;\n resolver.scanDeclarations(\n rule.declarations,\n (name) => defined.has(name),\n (name, syntax, initialValue) => {\n this.property(name, {\n syntax,\n inherits: true,\n initialValue,\n root,\n });\n },\n );\n }\n }\n\n // Insert rules using existing sheet manager\n const ruleInfo = this.sheetManager.insertRule(\n registry,\n rulesToInsert,\n className,\n root,\n );\n\n if (!ruleInfo) {\n // Update metrics\n if (registry.metrics) {\n registry.metrics.misses++;\n }\n\n return {\n className,\n dispose: () => {\n /* noop */\n },\n };\n }\n\n // Store in registry\n registry.refCounts.set(className, 1);\n\n if (isPreAllocated) {\n // Update the existing placeholder entry with real rule info\n registry.rules.set(className, ruleInfo);\n // cacheKey mapping already exists from allocation\n } else {\n // Store new entries\n registry.rules.set(className, ruleInfo);\n if (cacheKey) {\n registry.cacheKeyToClassName.set(cacheKey, className);\n }\n }\n\n // Update metrics\n if (registry.metrics) {\n registry.metrics.totalInsertions++;\n registry.metrics.misses++;\n }\n\n return {\n className,\n dispose: () => this.dispose(className, registry),\n };\n }\n\n /**\n * Inject global styles (rules without a generated tasty class selector)\n * This ensures we don't reserve a tasty class name (t{number}) for global rules,\n * which could otherwise collide with element-level styles and break lookups.\n */\n injectGlobal(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot },\n ): GlobalInjectResult {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n if (!rules || rules.length === 0) {\n return {\n dispose: () => {\n /* noop */\n },\n };\n }\n\n // Auto-register @property for custom properties in global rules\n if (this.config.autoPropertyTypes !== false) {\n const resolver = registry.propertyTypeResolver;\n const defined = registry.injectedProperties;\n for (const rule of rules) {\n if (!rule.declarations) continue;\n resolver.scanDeclarations(\n rule.declarations,\n (name) => defined.has(name),\n (name, syntax, initialValue) => {\n this.property(name, {\n syntax,\n inherits: true,\n initialValue,\n root,\n });\n },\n );\n }\n }\n\n // Use a non-tasty identifier to avoid any collisions with .t{number} classes\n const key = `global:${this.globalRuleCounter++}`;\n\n const info = this.sheetManager.insertGlobalRule(\n registry,\n rules as unknown as StyleRule[],\n key,\n root,\n );\n\n if (registry.metrics) {\n registry.metrics.totalInsertions++;\n }\n\n return {\n dispose: () => {\n if (info) this.sheetManager.deleteGlobalRule(registry, key);\n },\n };\n }\n\n /**\n * Inject raw CSS text directly without parsing\n * This is a low-overhead alternative to createGlobalStyle for raw CSS\n * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking\n */\n injectRawCSS(\n css: string,\n options?: { root?: Document | ShadowRoot },\n ): RawCSSResult {\n const root = options?.root || document;\n return this.sheetManager.injectRawCSS(css, root);\n }\n\n /**\n * Get raw CSS text for SSR\n */\n getRawCSSText(options?: { root?: Document | ShadowRoot }): string {\n const root = options?.root || document;\n return this.sheetManager.getRawCSSText(root);\n }\n\n /**\n * Increment refCount for an already-injected cacheKey and return a dispose.\n * Used by useStyles on cache hits (hydration or runtime reuse) where\n * the pipeline was skipped but refCount tracking is still needed.\n * Returns null if the cacheKey is not found.\n */\n trackRef(\n cacheKey: string,\n options?: { root?: Document | ShadowRoot },\n ): InjectResult | null {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n if (!registry.cacheKeyToClassName.has(cacheKey)) return null;\n\n const className = registry.cacheKeyToClassName.get(cacheKey)!;\n const currentRefCount = registry.refCounts.get(className) || 0;\n registry.refCounts.set(className, currentRefCount + 1);\n\n if (registry.metrics) {\n registry.metrics.hits++;\n }\n\n return {\n className,\n dispose: () => this.dispose(className, registry),\n };\n }\n\n /**\n * Dispose of a className (decrements refCount only).\n */\n private dispose(className: string, registry: RootRegistry): void {\n const currentRefCount = registry.refCounts.get(className);\n if (currentRefCount == null || currentRefCount <= 0) {\n return;\n }\n\n const newRefCount = currentRefCount - 1;\n registry.refCounts.set(className, newRefCount);\n\n if (newRefCount === 0 && registry.metrics) {\n registry.metrics.totalUnused++;\n }\n }\n\n /**\n * Force bulk cleanup of unused styles\n */\n cleanup(root?: Document | ShadowRoot): void {\n const registry = this.sheetManager.getRegistry(root || document);\n // Clean up ALL unused rules regardless of batch ratio\n this.sheetManager.forceCleanup(registry);\n }\n\n /**\n * Get CSS text from all sheets (for SSR)\n */\n getCssText(options?: { root?: Document | ShadowRoot }): string {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n return this.sheetManager.getCssText(registry);\n }\n\n /**\n * Get CSS only for the provided tasty classNames (e.g., [\"t0\",\"t3\"])\n */\n getCssTextForClasses(\n classNames: Iterable<string>,\n options?: { root?: Document | ShadowRoot },\n ): string {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n const cssChunks: string[] = [];\n for (const cls of classNames) {\n const info = registry.rules.get(cls);\n if (info) {\n // Always prefer reading from the live stylesheet, since indices can change\n const sheet = registry.sheets[info.sheetIndex];\n const styleSheet = sheet?.sheet?.sheet;\n if (styleSheet) {\n const start = Math.max(0, info.ruleIndex);\n const end = Math.min(\n styleSheet.cssRules.length - 1,\n (info.endRuleIndex as number) ?? info.ruleIndex,\n );\n // Additional validation: ensure indices are valid and in correct order\n if (\n start >= 0 &&\n end >= start &&\n start < styleSheet.cssRules.length\n ) {\n for (let i = start; i <= end; i++) {\n const rule = styleSheet.cssRules[i] as CSSRule | undefined;\n if (rule) cssChunks.push(rule.cssText);\n }\n }\n } else if (info.cssText && info.cssText.length) {\n // Fallback in environments without CSSOM access\n cssChunks.push(...info.cssText);\n }\n }\n }\n return cssChunks.join('\\n');\n }\n\n /**\n * Get cache performance metrics\n */\n getMetrics(options?: { root?: Document | ShadowRoot }): CacheMetrics | null {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n return this.sheetManager.getMetrics(registry);\n }\n\n /**\n * Reset cache performance metrics\n */\n resetMetrics(options?: { root?: Document | ShadowRoot }): void {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n this.sheetManager.resetMetrics(registry);\n }\n\n /**\n * Define a CSS @property custom property.\n *\n * Accepts tasty token syntax for the property name:\n * - `$name` → defines `--name`\n * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')\n * - `--name` → defines `--name` (legacy format)\n *\n * Example:\n * @property --rotation { syntax: \"<angle>\"; inherits: false; initial-value: 45deg; }\n *\n * Note: No caching or dispose — this defines a global property.\n *\n * If the same property is registered with different options, a warning is emitted\n * but the original definition is preserved (CSS @property cannot be redefined).\n */\n property(\n name: string,\n options?: PropertyDefinition & {\n root?: Document | ShadowRoot;\n },\n ): void {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n // Parse the token and get effective definition\n // This handles $name, #name, --name formats and auto-sets syntax for colors\n const userDefinition: PropertyDefinition = {\n syntax: options?.syntax,\n inherits: options?.inherits,\n initialValue: options?.initialValue,\n };\n\n const effectiveResult = getEffectiveDefinition(name, userDefinition);\n\n if (!effectiveResult.isValid) {\n if (isDevEnv()) {\n console.warn(\n `[Tasty] property(): ${effectiveResult.error}. Got: \"${name}\"`,\n );\n }\n return;\n }\n\n const cssName = effectiveResult.cssName;\n const definition = effectiveResult.definition;\n\n // Normalize the definition for comparison\n const normalizedDef = normalizePropertyDefinition(definition);\n\n // Check if already defined\n const existingDef = registry.injectedProperties.get(cssName);\n if (existingDef !== undefined) {\n return;\n }\n\n const parts: string[] = [];\n\n if (definition.syntax != null) {\n let syntax = String(definition.syntax).trim();\n if (!/^['\"]/u.test(syntax)) syntax = `\"${syntax}\"`;\n parts.push(`syntax: ${syntax};`);\n }\n\n // inherits is required by the CSS @property spec - default to true\n const inherits = definition.inherits ?? true;\n parts.push(`inherits: ${inherits ? 'true' : 'false'};`);\n\n if (definition.initialValue != null) {\n let initialValueStr: string;\n if (typeof definition.initialValue === 'number') {\n initialValueStr = String(definition.initialValue);\n } else {\n // Process via tasty parser to resolve custom units/functions\n initialValueStr = parseStyle(\n definition.initialValue as StyleValue,\n ).output;\n }\n parts.push(`initial-value: ${initialValueStr};`);\n }\n\n const declarations = parts.join(' ').trim();\n\n const rule: StyleRule = {\n selector: `@property ${cssName}`,\n declarations,\n } as StyleRule;\n\n // Insert as a global rule; only mark injected when insertion succeeds\n const info = this.sheetManager.insertGlobalRule(\n registry,\n [rule],\n `property:${name}`,\n root,\n );\n\n if (!info) {\n return;\n }\n\n // Track that this property was injected with its normalized definition\n registry.injectedProperties.set(cssName, normalizedDef);\n }\n\n /**\n * Check whether a given @property name was already injected by this injector.\n *\n * Accepts tasty token syntax:\n * - `$name` → checks `--name`\n * - `#name` → checks `--name-color`\n * - `--name` → checks `--name` (legacy format)\n */\n isPropertyDefined(\n name: string,\n options?: { root?: Document | ShadowRoot },\n ): boolean {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n // Parse the token to get the CSS property name\n const effectiveResult = getEffectiveDefinition(name, {});\n if (!effectiveResult.isValid) {\n return false;\n }\n\n return registry.injectedProperties.has(effectiveResult.cssName);\n }\n\n /**\n * Inject a CSS @font-face rule.\n *\n * Permanent and global — no dispose or ref-counting.\n * Deduplicates by content hash (family + descriptors).\n */\n fontFace(\n family: string,\n descriptors: FontFaceDescriptors,\n options?: { root?: Document | ShadowRoot },\n ): void {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n const hash = fontFaceContentHash(family, descriptors);\n\n if (registry.injectedFontFaces.has(hash)) {\n return;\n }\n\n const rule: StyleRule = {\n selector: '@font-face',\n declarations: formatFontFaceDeclarations(family, descriptors),\n } as StyleRule;\n\n const info = this.sheetManager.insertGlobalRule(\n registry,\n [rule],\n `fontface:${hash}`,\n root,\n );\n\n if (info) {\n registry.injectedFontFaces.add(hash);\n }\n }\n\n /**\n * Inject a CSS @counter-style rule.\n *\n * Permanent and global — no dispose or ref-counting.\n * Deduplicates by name (first definition wins).\n */\n counterStyle(\n name: string,\n descriptors: CounterStyleDescriptors,\n options?: { root?: Document | ShadowRoot },\n ): void {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n if (registry.injectedCounterStyles.has(name)) {\n return;\n }\n\n const rule: StyleRule = {\n selector: `@counter-style ${name}`,\n declarations: formatCounterStyleDeclarations(descriptors),\n } as StyleRule;\n\n const info = this.sheetManager.insertGlobalRule(\n registry,\n [rule],\n `counterstyle:${name}`,\n root,\n );\n\n if (info) {\n registry.injectedCounterStyles.add(name);\n }\n }\n\n /**\n * Inject keyframes and return object with toString() and dispose()\n *\n * Keyframes are cached by content (steps). If the same content is injected\n * multiple times with different provided names, the first injected name is reused.\n *\n * If the same name is provided with different content (collision), a unique\n * name is generated to avoid overwriting the existing keyframes.\n */\n keyframes(\n steps: KeyframesSteps,\n nameOrOptions?: string | { root?: Document | ShadowRoot; name?: string },\n ): KeyframesResult {\n // Parse parameters\n const isStringName = typeof nameOrOptions === 'string';\n const providedName = isStringName ? nameOrOptions : nameOrOptions?.name;\n const root = isStringName ? document : nameOrOptions?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n if (Object.keys(steps).length === 0) {\n return {\n toString: () => '',\n dispose: () => {\n /* noop */\n },\n };\n }\n\n // Generate content-based cache key (independent of provided name)\n const contentHash = JSON.stringify(steps);\n\n // Check if this exact content is already cached\n const existing = registry.keyframesCache.get(contentHash);\n if (existing) {\n existing.refCount++;\n return {\n toString: () => existing.name,\n dispose: () => this.disposeKeyframes(contentHash, registry),\n };\n }\n\n // Determine the actual name to use\n let actualName: string;\n\n if (providedName) {\n // Check if this name is already used with different content\n const existingContentForName =\n registry.keyframesNameToContent.get(providedName);\n\n if (existingContentForName && existingContentForName !== contentHash) {\n // Name collision: same name, different content\n // Generate a unique name to avoid overwriting\n actualName = `${providedName}-k${registry.keyframesCounter++}`;\n } else {\n // Name is available or used with same content\n actualName = providedName;\n // Track this name -> content mapping\n registry.keyframesNameToContent.set(providedName, contentHash);\n }\n } else {\n // No name provided, generate one\n actualName = `k${registry.keyframesCounter++}`;\n }\n\n // Insert keyframes\n const result = this.sheetManager.insertKeyframes(\n registry,\n steps,\n actualName,\n root,\n );\n if (!result) {\n return {\n toString: () => '',\n dispose: () => {\n /* noop */\n },\n };\n }\n\n const { info, declarations } = result;\n\n // Auto-register @property for custom properties found in keyframe declarations\n if (this.config.autoPropertyTypes !== false && declarations) {\n const resolver = registry.propertyTypeResolver;\n resolver.scanDeclarations(\n declarations,\n (name) => registry.injectedProperties.has(name),\n (name, syntax, initialValue) => {\n this.property(name, {\n syntax,\n inherits: true,\n initialValue,\n root,\n });\n },\n );\n }\n\n // Cache the result by content hash\n registry.keyframesCache.set(contentHash, {\n name: actualName,\n refCount: 1,\n info,\n });\n\n // Update metrics\n if (registry.metrics) {\n registry.metrics.totalInsertions++;\n registry.metrics.misses++;\n }\n\n return {\n toString: () => actualName,\n dispose: () => this.disposeKeyframes(contentHash, registry),\n };\n }\n\n /**\n * Dispose keyframes\n */\n private disposeKeyframes(contentHash: string, registry: RootRegistry): void {\n const entry = registry.keyframesCache.get(contentHash);\n if (!entry) return;\n\n entry.refCount--;\n if (entry.refCount <= 0) {\n // Dispose immediately - keyframes are global and safe to clean up right away\n this.sheetManager.deleteKeyframes(registry, entry.info);\n registry.keyframesCache.delete(contentHash);\n\n // Clean up name-to-content mapping if this name was tracked\n // Find and remove the mapping for this content hash\n for (const [name, hash] of registry.keyframesNameToContent.entries()) {\n if (hash === contentHash) {\n registry.keyframesNameToContent.delete(name);\n break;\n }\n }\n\n // Update metrics\n if (registry.metrics) {\n registry.metrics.totalUnused++;\n registry.metrics.stylesCleanedUp++;\n }\n }\n }\n\n // =========================================================================\n // GC: popularity-aware garbage collection with DOM safety guard\n // =========================================================================\n\n private static readonly TOUCH_THROTTLE_MS = 5_000;\n private static readonly TASTY_CLASS_RE = /^t\\d+$/;\n\n /**\n * Record a render-time usage hit for one or more classNames.\n * Handles space-separated multi-chunk classNames.\n * No-op on the server.\n */\n touch(className: string, options?: { root?: Document | ShadowRoot }): void {\n if (typeof document === 'undefined') return;\n if (!this.config.gc) return;\n\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n const now = Date.now();\n\n const parts =\n className.indexOf(' ') === -1 ? [className] : className.split(' ');\n\n for (const cls of parts) {\n if (!StyleInjector.TASTY_CLASS_RE.test(cls)) continue;\n if (!registry.rules.has(cls)) continue;\n\n const entry = registry.usageMap.get(cls);\n if (entry) {\n entry.hitCount++;\n if (now - entry.lastUsedAt > StyleInjector.TOUCH_THROTTLE_MS) {\n entry.lastUsedAt = now;\n }\n } else {\n registry.usageMap.set(cls, { hitCount: 1, lastUsedAt: now });\n }\n }\n }\n\n /**\n * Synchronous garbage collection.\n *\n * 1. Scans the DOM for live tasty classNames (safety guard).\n * 2. Scores each non-live className via popularity-weighted TTL.\n * 3. Marks evictable styles with refCount = 0 and deletes them.\n * 4. Optionally enforces a hard `cacheCapacity` cap.\n *\n * @returns Number of styles evicted.\n */\n gc(options?: GCOptions): number {\n if (typeof document === 'undefined') return 0;\n\n // Cancel any pending idle-scheduled GC to prevent double runs\n if (this.pendingGCHandle != null) {\n if (typeof cancelIdleCallback !== 'undefined') {\n cancelIdleCallback(this.pendingGCHandle);\n }\n this.pendingGCHandle = null;\n }\n\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n const baseMaxAge =\n options?.baseMaxAge ?? this.config.gc?.baseMaxAge ?? 60_000;\n const cacheCapacity =\n options?.cacheCapacity ?? this.config.gc?.cacheCapacity;\n const now = Date.now();\n\n // Phase 0: scan DOM for live classes (classList handles SVG elements too)\n const liveClasses = new Set<string>();\n for (const el of root.querySelectorAll('[class]')) {\n for (const token of el.classList) {\n if (StyleInjector.TASTY_CLASS_RE.test(token)) {\n liveClasses.add(token);\n }\n }\n }\n\n let swept = 0;\n\n // Phase 1: score-based eviction (skip live and actively-referenced classes)\n for (const [className, usage] of registry.usageMap) {\n if (liveClasses.has(className)) continue;\n if ((registry.refCounts.get(className) ?? 0) > 0) continue;\n\n const age = now - usage.lastUsedAt;\n const effectiveTTL = baseMaxAge * Math.log2(usage.hitCount + 1);\n\n if (age > effectiveTTL) {\n registry.usageMap.delete(className);\n swept++;\n }\n }\n\n // Phase 2: capacity cap (evict lowest-scored non-live, non-referenced styles)\n if (cacheCapacity && registry.usageMap.size > cacheCapacity) {\n const scored: { className: string; score: number }[] = [];\n for (const [className, usage] of registry.usageMap) {\n if (liveClasses.has(className)) continue;\n if ((registry.refCounts.get(className) ?? 0) > 0) continue;\n const age = now - usage.lastUsedAt;\n scored.push({\n className,\n score: usage.hitCount * Math.exp(-age / baseMaxAge),\n });\n }\n\n if (scored.length > 0) {\n scored.sort((a, b) => a.score - b.score);\n\n const toEvict = registry.usageMap.size - cacheCapacity;\n for (let i = 0; i < Math.min(toEvict, scored.length); i++) {\n const { className } = scored[i];\n registry.usageMap.delete(className);\n swept++;\n }\n }\n }\n\n if (swept > 0) {\n this.sheetManager.forceCleanup(registry);\n }\n\n this.lastGCTime = Date.now();\n\n return swept;\n }\n\n /**\n * Event-driven GC with cooldown.\n * Skips if called within `cooldown` ms of the last run.\n * Schedules the actual GC via `requestIdleCallback` when available.\n */\n maybeGC(options?: GCOptions): void {\n if (typeof document === 'undefined') return;\n\n const cooldown = this.config.gc?.cooldown ?? 30_000;\n const now = Date.now();\n\n if (now - this.lastGCTime < cooldown) return;\n\n // Set before scheduling to prevent multiple idle callbacks from stacking\n // when maybeGC is called rapidly (e.g. on every route change).\n this.lastGCTime = now;\n\n if (typeof requestIdleCallback !== 'undefined') {\n this.pendingGCHandle = requestIdleCallback(() => {\n this.pendingGCHandle = null;\n this.gc(options);\n });\n } else {\n this.gc(options);\n }\n }\n\n /**\n * Destroy all resources for a root\n */\n destroy(root?: Document | ShadowRoot): void {\n const targetRoot = root || document;\n this.sheetManager.cleanup(targetRoot);\n\n // Clear sweep timer and pending GC only when no active roots remain\n if (this.backgroundSweepTimeout && !this.sheetManager.hasActiveRoots()) {\n clearTimeout(this.backgroundSweepTimeout);\n this.backgroundSweepTimeout = null;\n\n if (this.pendingGCHandle != null) {\n if (typeof cancelIdleCallback !== 'undefined') {\n cancelIdleCallback(this.pendingGCHandle);\n }\n this.pendingGCHandle = null;\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAoCA,SAAS,kBAAkB,SAAyB;AAClD,QAAO,IAAI;;AAGb,IAAa,gBAAb,MAAa,cAAc;CACzB;CACA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AM,MAAM,MAAM,MAAM;AACxB,WAAO,KAAK;KACV;KACA,OAAO,MAAM,WAAW,KAAK,IAAI,CAAC,MAAM,WAAW;KACpD,CAAC;;AAGJ,OAAI,OAAO,SAAS,GAAG;AACrB,WAAO,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM;IAExC,MAAM,UAAU,SAAS,SAAS,OAAO;AACzC,SAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IAAI,SAAS,OAAO,OAAO,EAAE,KAAK;KACzD,MAAM,EAAE,cAAc,OAAO;AAC7B,cAAS,SAAS,OAAO,UAAU;AACnC;;;;AAKN,MAAI,QAAQ,EACV,MAAK,aAAa,aAAa,SAAS;AAG1C,OAAK,aAAa,KAAK,KAAK;AAE5B,SAAO;;;;;;;CAQT,QAAQ,SAA2B;AACjC,MAAI,OAAO,aAAa,YAAa;EAErC,MAAM,WAAW,KAAK,OAAO,IAAI,YAAY;EAC7C,MAAM,MAAM,KAAK,KAAK;AAEtB,MAAI,MAAM,KAAK,aAAa,SAAU;AAItC,OAAK,aAAa;AAElB,MAAI,OAAO,wBAAwB,YACjC,MAAK,kBAAkB,0BAA0B;AAC/C,QAAK,kBAAkB;AACvB,QAAK,GAAG,QAAQ;IAChB;MAEF,MAAK,GAAG,QAAQ;;;;;CAOpB,QAAQ,MAAoC;EAC1C,MAAM,aAAa,QAAQ;AAC3B,OAAK,aAAa,QAAQ,WAAW;AAGrC,MAAI,KAAK,0BAA0B,CAAC,KAAK,aAAa,gBAAgB,EAAE;AACtE,gBAAa,KAAK,uBAAuB;AACzC,QAAK,yBAAyB;AAE9B,OAAI,KAAK,mBAAmB,MAAM;AAChC,QAAI,OAAO,uBAAuB,YAChC,oBAAmB,KAAK,gBAAgB;AAE1C,SAAK,kBAAkB"}
1
+ {"version":3,"file":"injector.js","names":[],"sources":["../../src/injector/injector.ts"],"sourcesContent":["/**\n * Style injector that works with structured style objects\n * Eliminates CSS string parsing for better performance\n */\n\nimport type { StyleResult } from '../pipeline';\nimport {\n getEffectiveDefinition,\n normalizePropertyDefinition,\n} from '../properties';\nimport { isDevEnv } from '../utils/is-dev-env';\nimport type { StyleValue } from '../utils/styles';\nimport { parseStyle } from '../utils/styles';\n\nimport { SheetManager } from './sheet-manager';\nimport { fontFaceContentHash, formatFontFaceDeclarations } from '../font-face';\nimport { formatCounterStyleDeclarations } from '../counter-style';\nimport type {\n CacheMetrics,\n CounterStyleDescriptors,\n FontFaceDescriptors,\n GCOptions,\n GlobalInjectResult,\n InjectResult,\n KeyframesResult,\n KeyframesSteps,\n PropertyDefinition,\n RawCSSResult,\n RootRegistry,\n StyleInjectorConfig,\n StyleRule,\n} from './types';\n\n/**\n * Generate sequential class name with format t{number}\n */\nfunction generateClassName(counter: number): string {\n return `t${counter}`;\n}\n\nexport class StyleInjector {\n private sheetManager: SheetManager;\n private config: StyleInjectorConfig;\n private globalRuleCounter = 0;\n private pendingGCHandle: ReturnType<typeof requestIdleCallback> | null = null;\n\n /** @internal — exposed for debug utilities only */\n get _sheetManager(): SheetManager {\n return this.sheetManager;\n }\n\n constructor(config: StyleInjectorConfig = {}) {\n this.config = config;\n this.sheetManager = new SheetManager(config);\n }\n\n /**\n * Allocate a className for a cacheKey without injecting styles yet.\n * This allows separating className allocation (render phase) from style injection (insertion phase).\n */\n allocateClassName(\n cacheKey: string,\n options?: { root?: Document | ShadowRoot },\n ): { className: string; isNewAllocation: boolean } {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n // Check if we can reuse existing className for this cache key\n if (registry.cacheKeyToClassName.has(cacheKey)) {\n const className = registry.cacheKeyToClassName.get(cacheKey)!;\n return {\n className,\n isNewAllocation: false,\n };\n }\n\n // Generate new className and reserve it\n const className = generateClassName(registry.classCounter++);\n\n // Create placeholder RuleInfo to reserve the className\n const placeholderRuleInfo = {\n className,\n ruleIndex: -1, // Placeholder - will be set during actual injection\n sheetIndex: -1, // Placeholder - will be set during actual injection\n };\n\n // Store RuleInfo only once by className, and map cacheKey separately\n registry.rules.set(className, placeholderRuleInfo);\n registry.cacheKeyToClassName.set(cacheKey, className);\n\n return {\n className,\n isNewAllocation: true,\n };\n }\n\n /**\n * Inject styles from StyleResult objects\n */\n inject(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot; cacheKey?: string },\n ): InjectResult {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n if (rules.length === 0) {\n return {\n className: '',\n dispose: () => {\n /* noop */\n },\n };\n }\n\n // Rules are now in StyleRule format directly\n\n // Check if we can reuse based on cache key\n const cacheKey = options?.cacheKey;\n let className: string;\n let isPreAllocated = false;\n\n if (cacheKey && registry.cacheKeyToClassName.has(cacheKey)) {\n // Reuse existing class for this cache key\n className = registry.cacheKeyToClassName.get(cacheKey)!;\n const existingRuleInfo = registry.rules.get(className)!;\n\n // Check if this is a placeholder (pre-allocated but not yet injected)\n isPreAllocated =\n existingRuleInfo.ruleIndex === -1 && existingRuleInfo.sheetIndex === -1;\n\n if (!isPreAllocated) {\n // Already injected - just increment refCount\n const currentRefCount = registry.refCounts.get(className) || 0;\n registry.refCounts.set(className, currentRefCount + 1);\n\n // Update metrics\n if (registry.metrics) {\n registry.metrics.hits++;\n }\n\n return {\n className,\n dispose: () => this.dispose(className, registry),\n };\n }\n } else {\n // Generate new className\n className = generateClassName(registry.classCounter++);\n }\n\n // Process rules: handle needsClassName flag and apply specificity\n const rulesToInsert = rules.map((rule) => {\n let newSelector = rule.selector;\n\n // If rule needs className prepended\n if (rule.needsClassName) {\n // Handle multiple selectors (separated by ||| for OR conditions)\n const selectorParts = newSelector ? newSelector.split('|||') : [''];\n\n const classPrefix = `.${className}.${className}`;\n\n newSelector = selectorParts\n .map((part) => {\n const classSelector = part ? `${classPrefix}${part}` : classPrefix;\n\n // If there's a root prefix, add it before the class selector\n if (rule.rootPrefix) {\n return `${rule.rootPrefix} ${classSelector}`;\n }\n return classSelector;\n })\n .join(', ');\n }\n\n return {\n ...rule,\n selector: newSelector,\n needsClassName: undefined, // Remove the flag after processing\n rootPrefix: undefined, // Remove rootPrefix after processing\n };\n });\n\n // Auto-register @property for custom properties with inferable types.\n // Colors are detected by --*-color name pattern, numeric types by value.\n if (this.config.autoPropertyTypes !== false) {\n const resolver = registry.propertyTypeResolver;\n const defined = registry.injectedProperties;\n for (const rule of rulesToInsert) {\n if (!rule.declarations) continue;\n resolver.scanDeclarations(\n rule.declarations,\n (name) => defined.has(name),\n (name, syntax, initialValue) => {\n this.property(name, {\n syntax,\n inherits: true,\n initialValue,\n root,\n });\n },\n );\n }\n }\n\n // Insert rules using existing sheet manager\n const ruleInfo = this.sheetManager.insertRule(\n registry,\n rulesToInsert,\n className,\n root,\n );\n\n if (!ruleInfo) {\n // Update metrics\n if (registry.metrics) {\n registry.metrics.misses++;\n }\n\n return {\n className,\n dispose: () => {\n /* noop */\n },\n };\n }\n\n // Store in registry\n registry.refCounts.set(className, 1);\n\n if (isPreAllocated) {\n // Update the existing placeholder entry with real rule info\n registry.rules.set(className, ruleInfo);\n // cacheKey mapping already exists from allocation\n } else {\n // Store new entries\n registry.rules.set(className, ruleInfo);\n if (cacheKey) {\n registry.cacheKeyToClassName.set(cacheKey, className);\n }\n }\n\n // Update metrics\n if (registry.metrics) {\n registry.metrics.totalInsertions++;\n registry.metrics.misses++;\n }\n\n return {\n className,\n dispose: () => this.dispose(className, registry),\n };\n }\n\n /**\n * Inject global styles (rules without a generated tasty class selector)\n * This ensures we don't reserve a tasty class name (t{number}) for global rules,\n * which could otherwise collide with element-level styles and break lookups.\n */\n injectGlobal(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot },\n ): GlobalInjectResult {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n if (!rules || rules.length === 0) {\n return {\n dispose: () => {\n /* noop */\n },\n };\n }\n\n // Auto-register @property for custom properties in global rules\n if (this.config.autoPropertyTypes !== false) {\n const resolver = registry.propertyTypeResolver;\n const defined = registry.injectedProperties;\n for (const rule of rules) {\n if (!rule.declarations) continue;\n resolver.scanDeclarations(\n rule.declarations,\n (name) => defined.has(name),\n (name, syntax, initialValue) => {\n this.property(name, {\n syntax,\n inherits: true,\n initialValue,\n root,\n });\n },\n );\n }\n }\n\n // Use a non-tasty identifier to avoid any collisions with .t{number} classes\n const key = `global:${this.globalRuleCounter++}`;\n\n const info = this.sheetManager.insertGlobalRule(\n registry,\n rules as unknown as StyleRule[],\n key,\n root,\n );\n\n if (registry.metrics) {\n registry.metrics.totalInsertions++;\n }\n\n return {\n dispose: () => {\n if (info) this.sheetManager.deleteGlobalRule(registry, key);\n },\n };\n }\n\n /**\n * Inject raw CSS text directly without parsing\n * This is a low-overhead alternative to createGlobalStyle for raw CSS\n * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking\n */\n injectRawCSS(\n css: string,\n options?: { root?: Document | ShadowRoot },\n ): RawCSSResult {\n const root = options?.root || document;\n return this.sheetManager.injectRawCSS(css, root);\n }\n\n /**\n * Get raw CSS text for SSR\n */\n getRawCSSText(options?: { root?: Document | ShadowRoot }): string {\n const root = options?.root || document;\n return this.sheetManager.getRawCSSText(root);\n }\n\n /**\n * Increment refCount for an already-injected cacheKey and return a dispose.\n * Used by useStyles on cache hits (hydration or runtime reuse) where\n * the pipeline was skipped but refCount tracking is still needed.\n * Returns null if the cacheKey is not found.\n */\n trackRef(\n cacheKey: string,\n options?: { root?: Document | ShadowRoot },\n ): InjectResult | null {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n if (!registry.cacheKeyToClassName.has(cacheKey)) return null;\n\n const className = registry.cacheKeyToClassName.get(cacheKey)!;\n const currentRefCount = registry.refCounts.get(className) || 0;\n registry.refCounts.set(className, currentRefCount + 1);\n\n if (registry.metrics) {\n registry.metrics.hits++;\n }\n\n return {\n className,\n dispose: () => this.dispose(className, registry),\n };\n }\n\n /**\n * Dispose of a className (decrements refCount only).\n */\n private dispose(className: string, registry: RootRegistry): void {\n const currentRefCount = registry.refCounts.get(className);\n if (currentRefCount == null || currentRefCount <= 0) {\n return;\n }\n\n const newRefCount = currentRefCount - 1;\n registry.refCounts.set(className, newRefCount);\n\n if (newRefCount === 0 && registry.metrics) {\n registry.metrics.totalUnused++;\n }\n }\n\n /**\n * Force bulk cleanup of unused styles\n */\n cleanup(root?: Document | ShadowRoot): void {\n const registry = this.sheetManager.getRegistry(root || document);\n // Clean up ALL unused rules regardless of batch ratio\n this.sheetManager.forceCleanup(registry);\n }\n\n /**\n * Get CSS text from all sheets (for SSR)\n */\n getCssText(options?: { root?: Document | ShadowRoot }): string {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n return this.sheetManager.getCssText(registry);\n }\n\n /**\n * Get CSS only for the provided tasty classNames (e.g., [\"t0\",\"t3\"])\n */\n getCssTextForClasses(\n classNames: Iterable<string>,\n options?: { root?: Document | ShadowRoot },\n ): string {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n const cssChunks: string[] = [];\n for (const cls of classNames) {\n const info = registry.rules.get(cls);\n if (info) {\n // Always prefer reading from the live stylesheet, since indices can change\n const sheet = registry.sheets[info.sheetIndex];\n const styleSheet = sheet?.sheet?.sheet;\n if (styleSheet) {\n const start = Math.max(0, info.ruleIndex);\n const end = Math.min(\n styleSheet.cssRules.length - 1,\n (info.endRuleIndex as number) ?? info.ruleIndex,\n );\n // Additional validation: ensure indices are valid and in correct order\n if (\n start >= 0 &&\n end >= start &&\n start < styleSheet.cssRules.length\n ) {\n for (let i = start; i <= end; i++) {\n const rule = styleSheet.cssRules[i] as CSSRule | undefined;\n if (rule) cssChunks.push(rule.cssText);\n }\n }\n } else if (info.cssText && info.cssText.length) {\n // Fallback in environments without CSSOM access\n cssChunks.push(...info.cssText);\n }\n }\n }\n return cssChunks.join('\\n');\n }\n\n /**\n * Get cache performance metrics\n */\n getMetrics(options?: { root?: Document | ShadowRoot }): CacheMetrics | null {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n return this.sheetManager.getMetrics(registry);\n }\n\n /**\n * Reset cache performance metrics\n */\n resetMetrics(options?: { root?: Document | ShadowRoot }): void {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n this.sheetManager.resetMetrics(registry);\n }\n\n /**\n * Define a CSS @property custom property.\n *\n * Accepts tasty token syntax for the property name:\n * - `$name` → defines `--name`\n * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')\n * - `--name` → defines `--name` (legacy format)\n *\n * Example:\n * @property --rotation { syntax: \"<angle>\"; inherits: false; initial-value: 45deg; }\n *\n * Note: No caching or dispose — this defines a global property.\n *\n * If the same property is registered with different options, a warning is emitted\n * but the original definition is preserved (CSS @property cannot be redefined).\n */\n property(\n name: string,\n options?: PropertyDefinition & {\n root?: Document | ShadowRoot;\n },\n ): void {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n // Parse the token and get effective definition\n // This handles $name, #name, --name formats and auto-sets syntax for colors\n const userDefinition: PropertyDefinition = {\n syntax: options?.syntax,\n inherits: options?.inherits,\n initialValue: options?.initialValue,\n };\n\n const effectiveResult = getEffectiveDefinition(name, userDefinition);\n\n if (!effectiveResult.isValid) {\n if (isDevEnv()) {\n console.warn(\n `[Tasty] property(): ${effectiveResult.error}. Got: \"${name}\"`,\n );\n }\n return;\n }\n\n const cssName = effectiveResult.cssName;\n const definition = effectiveResult.definition;\n\n // Normalize the definition for comparison\n const normalizedDef = normalizePropertyDefinition(definition);\n\n // Check if already defined\n const existingDef = registry.injectedProperties.get(cssName);\n if (existingDef !== undefined) {\n return;\n }\n\n const parts: string[] = [];\n\n if (definition.syntax != null) {\n let syntax = String(definition.syntax).trim();\n if (!/^['\"]/u.test(syntax)) syntax = `\"${syntax}\"`;\n parts.push(`syntax: ${syntax};`);\n }\n\n // inherits is required by the CSS @property spec - default to true\n const inherits = definition.inherits ?? true;\n parts.push(`inherits: ${inherits ? 'true' : 'false'};`);\n\n if (definition.initialValue != null) {\n let initialValueStr: string;\n if (typeof definition.initialValue === 'number') {\n initialValueStr = String(definition.initialValue);\n } else {\n // Process via tasty parser to resolve custom units/functions\n initialValueStr = parseStyle(\n definition.initialValue as StyleValue,\n ).output;\n }\n parts.push(`initial-value: ${initialValueStr};`);\n }\n\n const declarations = parts.join(' ').trim();\n\n const rule: StyleRule = {\n selector: `@property ${cssName}`,\n declarations,\n } as StyleRule;\n\n // Insert as a global rule; only mark injected when insertion succeeds\n const info = this.sheetManager.insertGlobalRule(\n registry,\n [rule],\n `property:${name}`,\n root,\n );\n\n if (!info) {\n return;\n }\n\n // Track that this property was injected with its normalized definition\n registry.injectedProperties.set(cssName, normalizedDef);\n }\n\n /**\n * Check whether a given @property name was already injected by this injector.\n *\n * Accepts tasty token syntax:\n * - `$name` → checks `--name`\n * - `#name` → checks `--name-color`\n * - `--name` → checks `--name` (legacy format)\n */\n isPropertyDefined(\n name: string,\n options?: { root?: Document | ShadowRoot },\n ): boolean {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n // Parse the token to get the CSS property name\n const effectiveResult = getEffectiveDefinition(name, {});\n if (!effectiveResult.isValid) {\n return false;\n }\n\n return registry.injectedProperties.has(effectiveResult.cssName);\n }\n\n /**\n * Inject a CSS @font-face rule.\n *\n * Permanent and global — no dispose or ref-counting.\n * Deduplicates by content hash (family + descriptors).\n */\n fontFace(\n family: string,\n descriptors: FontFaceDescriptors,\n options?: { root?: Document | ShadowRoot },\n ): void {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n const hash = fontFaceContentHash(family, descriptors);\n\n if (registry.injectedFontFaces.has(hash)) {\n return;\n }\n\n const rule: StyleRule = {\n selector: '@font-face',\n declarations: formatFontFaceDeclarations(family, descriptors),\n } as StyleRule;\n\n const info = this.sheetManager.insertGlobalRule(\n registry,\n [rule],\n `fontface:${hash}`,\n root,\n );\n\n if (info) {\n registry.injectedFontFaces.add(hash);\n }\n }\n\n /**\n * Inject a CSS @counter-style rule.\n *\n * Permanent and global — no dispose or ref-counting.\n * Deduplicates by name (first definition wins).\n */\n counterStyle(\n name: string,\n descriptors: CounterStyleDescriptors,\n options?: { root?: Document | ShadowRoot },\n ): void {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n if (registry.injectedCounterStyles.has(name)) {\n return;\n }\n\n const rule: StyleRule = {\n selector: `@counter-style ${name}`,\n declarations: formatCounterStyleDeclarations(descriptors),\n } as StyleRule;\n\n const info = this.sheetManager.insertGlobalRule(\n registry,\n [rule],\n `counterstyle:${name}`,\n root,\n );\n\n if (info) {\n registry.injectedCounterStyles.add(name);\n }\n }\n\n /**\n * Inject keyframes and return object with toString() and dispose()\n *\n * Keyframes are cached by content (steps). If the same content is injected\n * multiple times with different provided names, the first injected name is reused.\n *\n * If the same name is provided with different content (collision), a unique\n * name is generated to avoid overwriting the existing keyframes.\n */\n keyframes(\n steps: KeyframesSteps,\n nameOrOptions?: string | { root?: Document | ShadowRoot; name?: string },\n ): KeyframesResult {\n // Parse parameters\n const isStringName = typeof nameOrOptions === 'string';\n const providedName = isStringName ? nameOrOptions : nameOrOptions?.name;\n const root = isStringName ? document : nameOrOptions?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n if (Object.keys(steps).length === 0) {\n return {\n toString: () => '',\n dispose: () => {\n /* noop */\n },\n };\n }\n\n // Generate content-based cache key (independent of provided name)\n const contentHash = JSON.stringify(steps);\n\n // Check if this exact content is already cached\n const existing = registry.keyframesCache.get(contentHash);\n if (existing) {\n existing.refCount++;\n return {\n toString: () => existing.name,\n dispose: () => this.disposeKeyframes(contentHash, registry),\n };\n }\n\n // Determine the actual name to use\n let actualName: string;\n\n if (providedName) {\n // Check if this name is already used with different content\n const existingContentForName =\n registry.keyframesNameToContent.get(providedName);\n\n if (existingContentForName && existingContentForName !== contentHash) {\n // Name collision: same name, different content\n // Generate a unique name to avoid overwriting\n actualName = `${providedName}-k${registry.keyframesCounter++}`;\n } else {\n // Name is available or used with same content\n actualName = providedName;\n // Track this name -> content mapping\n registry.keyframesNameToContent.set(providedName, contentHash);\n }\n } else {\n // No name provided, generate one\n actualName = `k${registry.keyframesCounter++}`;\n }\n\n // Insert keyframes\n const result = this.sheetManager.insertKeyframes(\n registry,\n steps,\n actualName,\n root,\n );\n if (!result) {\n return {\n toString: () => '',\n dispose: () => {\n /* noop */\n },\n };\n }\n\n const { info, declarations } = result;\n\n // Auto-register @property for custom properties found in keyframe declarations\n if (this.config.autoPropertyTypes !== false && declarations) {\n const resolver = registry.propertyTypeResolver;\n resolver.scanDeclarations(\n declarations,\n (name) => registry.injectedProperties.has(name),\n (name, syntax, initialValue) => {\n this.property(name, {\n syntax,\n inherits: true,\n initialValue,\n root,\n });\n },\n );\n }\n\n // Cache the result by content hash\n registry.keyframesCache.set(contentHash, {\n name: actualName,\n refCount: 1,\n info,\n });\n\n // Update metrics\n if (registry.metrics) {\n registry.metrics.totalInsertions++;\n registry.metrics.misses++;\n }\n\n return {\n toString: () => actualName,\n dispose: () => this.disposeKeyframes(contentHash, registry),\n };\n }\n\n /**\n * Dispose keyframes\n */\n private disposeKeyframes(contentHash: string, registry: RootRegistry): void {\n const entry = registry.keyframesCache.get(contentHash);\n if (!entry) return;\n\n entry.refCount--;\n if (entry.refCount <= 0) {\n // Dispose immediately - keyframes are global and safe to clean up right away\n this.sheetManager.deleteKeyframes(registry, entry.info);\n registry.keyframesCache.delete(contentHash);\n\n // Clean up name-to-content mapping if this name was tracked\n // Find and remove the mapping for this content hash\n for (const [name, hash] of registry.keyframesNameToContent.entries()) {\n if (hash === contentHash) {\n registry.keyframesNameToContent.delete(name);\n break;\n }\n }\n\n // Update metrics\n if (registry.metrics) {\n registry.metrics.totalUnused++;\n registry.metrics.stylesCleanedUp++;\n }\n }\n }\n\n // =========================================================================\n // GC: touch-count-driven garbage collection with DOM safety guard\n // =========================================================================\n\n private static readonly TASTY_CLASS_RE = /^t\\d+$/;\n\n /**\n * Record a render-time usage hit for one or more classNames.\n * Handles space-separated multi-chunk classNames.\n * When the global touch counter reaches `touchInterval`, schedules a GC\n * via `requestIdleCallback`.\n * No-op on the server.\n */\n touch(className: string, options?: { root?: Document | ShadowRoot }): void {\n if (typeof document === 'undefined') return;\n if (!this.config.gc) return;\n\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n const now = Date.now();\n\n const parts =\n className.indexOf(' ') === -1 ? [className] : className.split(' ');\n\n for (const cls of parts) {\n if (!StyleInjector.TASTY_CLASS_RE.test(cls)) continue;\n if (!registry.rules.has(cls)) continue;\n\n const entry = registry.usageMap.get(cls);\n if (entry) {\n entry.lastTouchedAt = now;\n } else {\n registry.usageMap.set(cls, { lastTouchedAt: now });\n }\n registry.touchCount++;\n }\n\n const touchInterval = this.config.gc.touchInterval ?? 1000;\n if (registry.touchCount >= touchInterval) {\n registry.touchCount = 0;\n this.scheduleGC();\n }\n }\n\n /**\n * Schedule a GC via `requestIdleCallback` (or synchronously as fallback).\n * Runs GC on all active roots. Avoids double-scheduling via `pendingGCHandle`.\n */\n private scheduleGC(): void {\n if (this.pendingGCHandle != null) return;\n\n const runGC = () => {\n this.pendingGCHandle = null;\n this.sheetManager.pruneDisconnectedRoots();\n for (const root of this.sheetManager.getActiveRoots()) {\n this.gc({ root });\n }\n };\n\n if (typeof requestIdleCallback !== 'undefined') {\n this.pendingGCHandle = requestIdleCallback(() => runGC());\n } else {\n runGC();\n }\n }\n\n /**\n * Synchronous garbage collection.\n *\n * 1. Quick upper-bound check: skip if unused count can't exceed capacity.\n * 2. Scans the DOM for live tasty classNames (safety guard).\n * 3. With `force: true`: deletes all unused entries inline.\n * Without `force`: collects unused, sorts oldest-first, evicts over capacity.\n *\n * @returns Number of styles evicted.\n */\n gc(options?: GCOptions): number {\n if (typeof document === 'undefined') return 0;\n\n // Cancel any pending idle-scheduled GC to prevent double runs\n if (this.pendingGCHandle != null) {\n if (typeof cancelIdleCallback !== 'undefined') {\n cancelIdleCallback(this.pendingGCHandle);\n }\n this.pendingGCHandle = null;\n }\n\n const root = options?.root || document;\n const force = options?.force ?? false;\n const registry = this.sheetManager.getRegistry(root);\n const capacity = this.config.gc?.capacity ?? 1000;\n\n // Quick upper-bound check: count active refs to see if there could\n // possibly be enough unused entries to exceed capacity.\n // This avoids the expensive DOM scan when most styles are active.\n if (!force) {\n let activeCount = 0;\n for (const refCount of registry.refCounts.values()) {\n if (refCount > 0) activeCount++;\n }\n if (registry.usageMap.size - activeCount <= capacity) {\n return 0;\n }\n }\n\n // Scan DOM for live classes (classList handles SVG elements too)\n const liveClasses = new Set<string>();\n for (const el of root.querySelectorAll('[class]')) {\n for (const token of el.classList) {\n if (StyleInjector.TASTY_CLASS_RE.test(token)) {\n liveClasses.add(token);\n }\n }\n }\n\n let swept = 0;\n\n if (force) {\n for (const [className] of registry.usageMap) {\n if (liveClasses.has(className)) continue;\n if ((registry.refCounts.get(className) ?? 0) > 0) continue;\n registry.usageMap.delete(className);\n swept++;\n }\n } else {\n const unused: { className: string; lastTouchedAt: number }[] = [];\n for (const [className, usage] of registry.usageMap) {\n if (liveClasses.has(className)) continue;\n if ((registry.refCounts.get(className) ?? 0) > 0) continue;\n unused.push({ className, lastTouchedAt: usage.lastTouchedAt });\n }\n\n if (unused.length > capacity) {\n unused.sort((a, b) => a.lastTouchedAt - b.lastTouchedAt);\n const toEvict = unused.length - capacity;\n for (let i = 0; i < toEvict; i++) {\n registry.usageMap.delete(unused[i].className);\n swept++;\n }\n }\n }\n\n if (swept > 0) {\n this.sheetManager.forceCleanup(registry);\n }\n\n return swept;\n }\n\n /**\n * Destroy all resources for a root\n */\n destroy(root?: Document | ShadowRoot): void {\n const targetRoot = root || document;\n this.sheetManager.cleanup(targetRoot);\n\n // Clear pending GC when no active roots remain\n if (this.pendingGCHandle != null && !this.sheetManager.hasActiveRoots()) {\n if (typeof cancelIdleCallback !== 'undefined') {\n cancelIdleCallback(this.pendingGCHandle);\n }\n this.pendingGCHandle = null;\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAoCA,SAAS,kBAAkB,SAAyB;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e,CAAC;;AAGhE,OAAI,OAAO,SAAS,UAAU;AAC5B,WAAO,MAAM,GAAG,MAAM,EAAE,gBAAgB,EAAE,cAAc;IACxD,MAAM,UAAU,OAAO,SAAS;AAChC,SAAK,IAAI,IAAI,GAAG,IAAI,SAAS,KAAK;AAChC,cAAS,SAAS,OAAO,OAAO,GAAG,UAAU;AAC7C;;;;AAKN,MAAI,QAAQ,EACV,MAAK,aAAa,aAAa,SAAS;AAG1C,SAAO;;;;;CAMT,QAAQ,MAAoC;EAC1C,MAAM,aAAa,QAAQ;AAC3B,OAAK,aAAa,QAAQ,WAAW;AAGrC,MAAI,KAAK,mBAAmB,QAAQ,CAAC,KAAK,aAAa,gBAAgB,EAAE;AACvE,OAAI,OAAO,uBAAuB,YAChC,oBAAmB,KAAK,gBAAgB;AAE1C,QAAK,kBAAkB"}
@@ -48,7 +48,8 @@ var SheetManager = class {
48
48
  injectedCounterStyles: /* @__PURE__ */ new Set(),
49
49
  globalRules: /* @__PURE__ */ new Map(),
50
50
  propertyTypeResolver: new PropertyTypeResolver(),
51
- usageMap: /* @__PURE__ */ new Map()
51
+ usageMap: /* @__PURE__ */ new Map(),
52
+ touchCount: 0
52
53
  };
53
54
  this.rootRegistries.set(root, registry);
54
55
  this.activeRoots.add(root);