@tenphi/tasty 0.0.0-snapshot.08a6610

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 (288) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +666 -0
  3. package/dist/_virtual/_rolldown/runtime.js +8 -0
  4. package/dist/chunks/cacheKey.js +70 -0
  5. package/dist/chunks/cacheKey.js.map +1 -0
  6. package/dist/chunks/definitions.d.ts +37 -0
  7. package/dist/chunks/definitions.js +259 -0
  8. package/dist/chunks/definitions.js.map +1 -0
  9. package/dist/chunks/renderChunk.js +61 -0
  10. package/dist/chunks/renderChunk.js.map +1 -0
  11. package/dist/config.d.ts +311 -0
  12. package/dist/config.js +458 -0
  13. package/dist/config.js.map +1 -0
  14. package/dist/core/index.d.ts +32 -0
  15. package/dist/core/index.js +26 -0
  16. package/dist/debug.d.ts +204 -0
  17. package/dist/debug.js +733 -0
  18. package/dist/debug.js.map +1 -0
  19. package/dist/hooks/useGlobalStyles.d.ts +30 -0
  20. package/dist/hooks/useGlobalStyles.js +83 -0
  21. package/dist/hooks/useGlobalStyles.js.map +1 -0
  22. package/dist/hooks/useKeyframes.d.ts +56 -0
  23. package/dist/hooks/useKeyframes.js +69 -0
  24. package/dist/hooks/useKeyframes.js.map +1 -0
  25. package/dist/hooks/useProperty.d.ts +79 -0
  26. package/dist/hooks/useProperty.js +114 -0
  27. package/dist/hooks/useProperty.js.map +1 -0
  28. package/dist/hooks/useRawCSS.d.ts +53 -0
  29. package/dist/hooks/useRawCSS.js +40 -0
  30. package/dist/hooks/useRawCSS.js.map +1 -0
  31. package/dist/hooks/useStyles.d.ts +45 -0
  32. package/dist/hooks/useStyles.js +248 -0
  33. package/dist/hooks/useStyles.js.map +1 -0
  34. package/dist/index.d.ts +47 -0
  35. package/dist/index.js +33 -0
  36. package/dist/injector/index.d.ts +165 -0
  37. package/dist/injector/index.js +162 -0
  38. package/dist/injector/index.js.map +1 -0
  39. package/dist/injector/injector.d.ts +148 -0
  40. package/dist/injector/injector.js +430 -0
  41. package/dist/injector/injector.js.map +1 -0
  42. package/dist/injector/sheet-manager.d.ts +136 -0
  43. package/dist/injector/sheet-manager.js +729 -0
  44. package/dist/injector/sheet-manager.js.map +1 -0
  45. package/dist/injector/types.d.ts +144 -0
  46. package/dist/keyframes/index.js +206 -0
  47. package/dist/keyframes/index.js.map +1 -0
  48. package/dist/parser/classify.js +319 -0
  49. package/dist/parser/classify.js.map +1 -0
  50. package/dist/parser/const.js +33 -0
  51. package/dist/parser/const.js.map +1 -0
  52. package/dist/parser/lru.js +109 -0
  53. package/dist/parser/lru.js.map +1 -0
  54. package/dist/parser/parser.d.ts +25 -0
  55. package/dist/parser/parser.js +116 -0
  56. package/dist/parser/parser.js.map +1 -0
  57. package/dist/parser/tokenizer.js +69 -0
  58. package/dist/parser/tokenizer.js.map +1 -0
  59. package/dist/parser/types.d.ts +51 -0
  60. package/dist/parser/types.js +46 -0
  61. package/dist/parser/types.js.map +1 -0
  62. package/dist/pipeline/conditions.d.ts +134 -0
  63. package/dist/pipeline/conditions.js +406 -0
  64. package/dist/pipeline/conditions.js.map +1 -0
  65. package/dist/pipeline/exclusive.js +231 -0
  66. package/dist/pipeline/exclusive.js.map +1 -0
  67. package/dist/pipeline/index.d.ts +53 -0
  68. package/dist/pipeline/index.js +660 -0
  69. package/dist/pipeline/index.js.map +1 -0
  70. package/dist/pipeline/materialize.js +856 -0
  71. package/dist/pipeline/materialize.js.map +1 -0
  72. package/dist/pipeline/parseStateKey.d.ts +15 -0
  73. package/dist/pipeline/parseStateKey.js +451 -0
  74. package/dist/pipeline/parseStateKey.js.map +1 -0
  75. package/dist/pipeline/simplify.js +516 -0
  76. package/dist/pipeline/simplify.js.map +1 -0
  77. package/dist/pipeline/warnings.js +18 -0
  78. package/dist/pipeline/warnings.js.map +1 -0
  79. package/dist/plugins/okhsl-plugin.d.ts +35 -0
  80. package/dist/plugins/okhsl-plugin.js +371 -0
  81. package/dist/plugins/okhsl-plugin.js.map +1 -0
  82. package/dist/plugins/types.d.ts +76 -0
  83. package/dist/properties/index.js +236 -0
  84. package/dist/properties/index.js.map +1 -0
  85. package/dist/properties/property-type-resolver.d.ts +24 -0
  86. package/dist/properties/property-type-resolver.js +91 -0
  87. package/dist/properties/property-type-resolver.js.map +1 -0
  88. package/dist/ssr/astro.d.ts +29 -0
  89. package/dist/ssr/astro.js +65 -0
  90. package/dist/ssr/astro.js.map +1 -0
  91. package/dist/ssr/async-storage.d.ts +17 -0
  92. package/dist/ssr/async-storage.js +35 -0
  93. package/dist/ssr/async-storage.js.map +1 -0
  94. package/dist/ssr/collect-auto-properties.js +40 -0
  95. package/dist/ssr/collect-auto-properties.js.map +1 -0
  96. package/dist/ssr/collector.d.ts +85 -0
  97. package/dist/ssr/collector.js +183 -0
  98. package/dist/ssr/collector.js.map +1 -0
  99. package/dist/ssr/context.d.ts +8 -0
  100. package/dist/ssr/context.js +14 -0
  101. package/dist/ssr/context.js.map +1 -0
  102. package/dist/ssr/format-global-rules.js +22 -0
  103. package/dist/ssr/format-global-rules.js.map +1 -0
  104. package/dist/ssr/format-keyframes.js +70 -0
  105. package/dist/ssr/format-keyframes.js.map +1 -0
  106. package/dist/ssr/format-property.js +48 -0
  107. package/dist/ssr/format-property.js.map +1 -0
  108. package/dist/ssr/format-rules.js +70 -0
  109. package/dist/ssr/format-rules.js.map +1 -0
  110. package/dist/ssr/hydrate.d.ts +22 -0
  111. package/dist/ssr/hydrate.js +50 -0
  112. package/dist/ssr/hydrate.js.map +1 -0
  113. package/dist/ssr/index.d.ts +5 -0
  114. package/dist/ssr/index.js +12 -0
  115. package/dist/ssr/index.js.map +1 -0
  116. package/dist/ssr/next.d.ts +45 -0
  117. package/dist/ssr/next.js +71 -0
  118. package/dist/ssr/next.js.map +1 -0
  119. package/dist/ssr/ssr-collector-ref.js +12 -0
  120. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  121. package/dist/states/index.d.ts +49 -0
  122. package/dist/states/index.js +416 -0
  123. package/dist/states/index.js.map +1 -0
  124. package/dist/static/index.d.ts +5 -0
  125. package/dist/static/index.js +5 -0
  126. package/dist/static/tastyStatic.d.ts +46 -0
  127. package/dist/static/tastyStatic.js +31 -0
  128. package/dist/static/tastyStatic.js.map +1 -0
  129. package/dist/static/types.d.ts +49 -0
  130. package/dist/static/types.js +24 -0
  131. package/dist/static/types.js.map +1 -0
  132. package/dist/styles/align.d.ts +15 -0
  133. package/dist/styles/align.js +14 -0
  134. package/dist/styles/align.js.map +1 -0
  135. package/dist/styles/border.d.ts +25 -0
  136. package/dist/styles/border.js +114 -0
  137. package/dist/styles/border.js.map +1 -0
  138. package/dist/styles/color.d.ts +14 -0
  139. package/dist/styles/color.js +23 -0
  140. package/dist/styles/color.js.map +1 -0
  141. package/dist/styles/createStyle.js +77 -0
  142. package/dist/styles/createStyle.js.map +1 -0
  143. package/dist/styles/dimension.js +97 -0
  144. package/dist/styles/dimension.js.map +1 -0
  145. package/dist/styles/display.d.ts +37 -0
  146. package/dist/styles/display.js +67 -0
  147. package/dist/styles/display.js.map +1 -0
  148. package/dist/styles/fade.d.ts +15 -0
  149. package/dist/styles/fade.js +58 -0
  150. package/dist/styles/fade.js.map +1 -0
  151. package/dist/styles/fill.d.ts +42 -0
  152. package/dist/styles/fill.js +52 -0
  153. package/dist/styles/fill.js.map +1 -0
  154. package/dist/styles/flow.d.ts +16 -0
  155. package/dist/styles/flow.js +12 -0
  156. package/dist/styles/flow.js.map +1 -0
  157. package/dist/styles/gap.d.ts +31 -0
  158. package/dist/styles/gap.js +37 -0
  159. package/dist/styles/gap.js.map +1 -0
  160. package/dist/styles/height.d.ts +17 -0
  161. package/dist/styles/height.js +20 -0
  162. package/dist/styles/height.js.map +1 -0
  163. package/dist/styles/index.d.ts +2 -0
  164. package/dist/styles/index.js +9 -0
  165. package/dist/styles/index.js.map +1 -0
  166. package/dist/styles/inset.d.ts +52 -0
  167. package/dist/styles/inset.js +150 -0
  168. package/dist/styles/inset.js.map +1 -0
  169. package/dist/styles/justify.d.ts +15 -0
  170. package/dist/styles/justify.js +14 -0
  171. package/dist/styles/justify.js.map +1 -0
  172. package/dist/styles/list.d.ts +16 -0
  173. package/dist/styles/list.js +98 -0
  174. package/dist/styles/list.js.map +1 -0
  175. package/dist/styles/margin.d.ts +24 -0
  176. package/dist/styles/margin.js +104 -0
  177. package/dist/styles/margin.js.map +1 -0
  178. package/dist/styles/outline.d.ts +29 -0
  179. package/dist/styles/outline.js +65 -0
  180. package/dist/styles/outline.js.map +1 -0
  181. package/dist/styles/padding.d.ts +24 -0
  182. package/dist/styles/padding.js +104 -0
  183. package/dist/styles/padding.js.map +1 -0
  184. package/dist/styles/predefined.d.ts +71 -0
  185. package/dist/styles/predefined.js +238 -0
  186. package/dist/styles/predefined.js.map +1 -0
  187. package/dist/styles/preset.d.ts +47 -0
  188. package/dist/styles/preset.js +126 -0
  189. package/dist/styles/preset.js.map +1 -0
  190. package/dist/styles/radius.d.ts +14 -0
  191. package/dist/styles/radius.js +51 -0
  192. package/dist/styles/radius.js.map +1 -0
  193. package/dist/styles/scrollbar.d.ts +25 -0
  194. package/dist/styles/scrollbar.js +48 -0
  195. package/dist/styles/scrollbar.js.map +1 -0
  196. package/dist/styles/shadow.d.ts +14 -0
  197. package/dist/styles/shadow.js +24 -0
  198. package/dist/styles/shadow.js.map +1 -0
  199. package/dist/styles/transition.d.ts +14 -0
  200. package/dist/styles/transition.js +158 -0
  201. package/dist/styles/transition.js.map +1 -0
  202. package/dist/styles/types.d.ts +508 -0
  203. package/dist/styles/width.d.ts +17 -0
  204. package/dist/styles/width.js +20 -0
  205. package/dist/styles/width.js.map +1 -0
  206. package/dist/tasty.d.ts +981 -0
  207. package/dist/tasty.js +206 -0
  208. package/dist/tasty.js.map +1 -0
  209. package/dist/types.d.ts +184 -0
  210. package/dist/utils/cache-wrapper.js +26 -0
  211. package/dist/utils/cache-wrapper.js.map +1 -0
  212. package/dist/utils/case-converter.js +8 -0
  213. package/dist/utils/case-converter.js.map +1 -0
  214. package/dist/utils/colors.d.ts +5 -0
  215. package/dist/utils/colors.js +9 -0
  216. package/dist/utils/colors.js.map +1 -0
  217. package/dist/utils/css-types.d.ts +7 -0
  218. package/dist/utils/dotize.d.ts +26 -0
  219. package/dist/utils/dotize.js +122 -0
  220. package/dist/utils/dotize.js.map +1 -0
  221. package/dist/utils/filter-base-props.d.ts +15 -0
  222. package/dist/utils/filter-base-props.js +45 -0
  223. package/dist/utils/filter-base-props.js.map +1 -0
  224. package/dist/utils/get-display-name.d.ts +7 -0
  225. package/dist/utils/get-display-name.js +10 -0
  226. package/dist/utils/get-display-name.js.map +1 -0
  227. package/dist/utils/hsl-to-rgb.js +38 -0
  228. package/dist/utils/hsl-to-rgb.js.map +1 -0
  229. package/dist/utils/is-dev-env.js +19 -0
  230. package/dist/utils/is-dev-env.js.map +1 -0
  231. package/dist/utils/is-valid-element-type.js +15 -0
  232. package/dist/utils/is-valid-element-type.js.map +1 -0
  233. package/dist/utils/merge-styles.d.ts +7 -0
  234. package/dist/utils/merge-styles.js +146 -0
  235. package/dist/utils/merge-styles.js.map +1 -0
  236. package/dist/utils/mod-attrs.d.ts +8 -0
  237. package/dist/utils/mod-attrs.js +21 -0
  238. package/dist/utils/mod-attrs.js.map +1 -0
  239. package/dist/utils/okhsl-to-rgb.js +296 -0
  240. package/dist/utils/okhsl-to-rgb.js.map +1 -0
  241. package/dist/utils/process-tokens.d.ts +31 -0
  242. package/dist/utils/process-tokens.js +171 -0
  243. package/dist/utils/process-tokens.js.map +1 -0
  244. package/dist/utils/resolve-recipes.d.ts +17 -0
  245. package/dist/utils/resolve-recipes.js +147 -0
  246. package/dist/utils/resolve-recipes.js.map +1 -0
  247. package/dist/utils/selector-transform.js +32 -0
  248. package/dist/utils/selector-transform.js.map +1 -0
  249. package/dist/utils/string.js +8 -0
  250. package/dist/utils/string.js.map +1 -0
  251. package/dist/utils/styles.d.ts +177 -0
  252. package/dist/utils/styles.js +730 -0
  253. package/dist/utils/styles.js.map +1 -0
  254. package/dist/utils/typography.d.ts +47 -0
  255. package/dist/utils/typography.js +43 -0
  256. package/dist/utils/typography.js.map +1 -0
  257. package/dist/utils/warnings.d.ts +16 -0
  258. package/dist/utils/warnings.js +16 -0
  259. package/dist/utils/warnings.js.map +1 -0
  260. package/dist/zero/babel.d.ts +147 -0
  261. package/dist/zero/babel.js +331 -0
  262. package/dist/zero/babel.js.map +1 -0
  263. package/dist/zero/css-writer.d.ts +45 -0
  264. package/dist/zero/css-writer.js +74 -0
  265. package/dist/zero/css-writer.js.map +1 -0
  266. package/dist/zero/extractor.d.ts +24 -0
  267. package/dist/zero/extractor.js +215 -0
  268. package/dist/zero/extractor.js.map +1 -0
  269. package/dist/zero/index.d.ts +3 -0
  270. package/dist/zero/index.js +4 -0
  271. package/dist/zero/next.d.ts +74 -0
  272. package/dist/zero/next.js +129 -0
  273. package/dist/zero/next.js.map +1 -0
  274. package/docs/adoption.md +286 -0
  275. package/docs/comparison.md +413 -0
  276. package/docs/configuration.md +242 -0
  277. package/docs/debug.md +505 -0
  278. package/docs/design-system.md +401 -0
  279. package/docs/dsl.md +540 -0
  280. package/docs/getting-started.md +201 -0
  281. package/docs/injector.md +528 -0
  282. package/docs/methodology.md +501 -0
  283. package/docs/runtime.md +291 -0
  284. package/docs/ssr.md +382 -0
  285. package/docs/styles.md +574 -0
  286. package/docs/tasty-static.md +421 -0
  287. package/package.json +209 -0
  288. package/tasty.config.ts +14 -0
@@ -0,0 +1,430 @@
1
+ import { getEffectiveDefinition, normalizePropertyDefinition } from "../properties/index.js";
2
+ import { isDevEnv } from "../utils/is-dev-env.js";
3
+ import { parseStyle } from "../utils/styles.js";
4
+ import { SheetManager } from "./sheet-manager.js";
5
+
6
+ //#region src/injector/injector.ts
7
+ /**
8
+ * Generate sequential class name with format t{number}
9
+ */
10
+ function generateClassName(counter) {
11
+ return `t${counter}`;
12
+ }
13
+ var StyleInjector = class {
14
+ sheetManager;
15
+ config;
16
+ cleanupScheduled = false;
17
+ globalRuleCounter = 0;
18
+ /** @internal — exposed for debug utilities only */
19
+ get _sheetManager() {
20
+ return this.sheetManager;
21
+ }
22
+ constructor(config = {}) {
23
+ this.config = config;
24
+ this.sheetManager = new SheetManager(config);
25
+ }
26
+ /**
27
+ * Allocate a className for a cacheKey without injecting styles yet.
28
+ * This allows separating className allocation (render phase) from style injection (insertion phase).
29
+ */
30
+ allocateClassName(cacheKey, options) {
31
+ const root = options?.root || document;
32
+ const registry = this.sheetManager.getRegistry(root);
33
+ if (registry.cacheKeyToClassName.has(cacheKey)) return {
34
+ className: registry.cacheKeyToClassName.get(cacheKey),
35
+ isNewAllocation: false
36
+ };
37
+ const className = generateClassName(registry.classCounter++);
38
+ const placeholderRuleInfo = {
39
+ className,
40
+ ruleIndex: -1,
41
+ sheetIndex: -1
42
+ };
43
+ registry.rules.set(className, placeholderRuleInfo);
44
+ registry.cacheKeyToClassName.set(cacheKey, className);
45
+ return {
46
+ className,
47
+ isNewAllocation: true
48
+ };
49
+ }
50
+ /**
51
+ * Inject styles from StyleResult objects
52
+ */
53
+ inject(rules, options) {
54
+ const root = options?.root || document;
55
+ const registry = this.sheetManager.getRegistry(root);
56
+ if (rules.length === 0) return {
57
+ className: "",
58
+ dispose: () => {}
59
+ };
60
+ const cacheKey = options?.cacheKey;
61
+ let className;
62
+ let isPreAllocated = false;
63
+ if (cacheKey && registry.cacheKeyToClassName.has(cacheKey)) {
64
+ className = registry.cacheKeyToClassName.get(cacheKey);
65
+ const existingRuleInfo = registry.rules.get(className);
66
+ isPreAllocated = existingRuleInfo.ruleIndex === -1 && existingRuleInfo.sheetIndex === -1;
67
+ if (!isPreAllocated) {
68
+ const currentRefCount = registry.refCounts.get(className) || 0;
69
+ registry.refCounts.set(className, currentRefCount + 1);
70
+ if (registry.metrics) registry.metrics.hits++;
71
+ return {
72
+ className,
73
+ dispose: () => this.dispose(className, registry)
74
+ };
75
+ }
76
+ } else className = generateClassName(registry.classCounter++);
77
+ const rulesToInsert = rules.map((rule) => {
78
+ let newSelector = rule.selector;
79
+ if (rule.needsClassName) {
80
+ const selectorParts = newSelector ? newSelector.split("|||") : [""];
81
+ const classPrefix = `.${className}.${className}`;
82
+ newSelector = selectorParts.map((part) => {
83
+ const classSelector = part ? `${classPrefix}${part}` : classPrefix;
84
+ if (rule.rootPrefix) return `${rule.rootPrefix} ${classSelector}`;
85
+ return classSelector;
86
+ }).join(", ");
87
+ }
88
+ return {
89
+ ...rule,
90
+ selector: newSelector,
91
+ needsClassName: void 0,
92
+ rootPrefix: void 0
93
+ };
94
+ });
95
+ if (this.config.autoPropertyTypes !== false) {
96
+ const resolver = registry.propertyTypeResolver;
97
+ const defined = registry.injectedProperties;
98
+ for (const rule of rulesToInsert) {
99
+ if (!rule.declarations) continue;
100
+ resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
101
+ this.property(name, {
102
+ syntax,
103
+ inherits: true,
104
+ initialValue,
105
+ root
106
+ });
107
+ });
108
+ }
109
+ }
110
+ const ruleInfo = this.sheetManager.insertRule(registry, rulesToInsert, className, root);
111
+ if (!ruleInfo) {
112
+ if (registry.metrics) registry.metrics.misses++;
113
+ return {
114
+ className,
115
+ dispose: () => {}
116
+ };
117
+ }
118
+ registry.refCounts.set(className, 1);
119
+ if (isPreAllocated) registry.rules.set(className, ruleInfo);
120
+ else {
121
+ registry.rules.set(className, ruleInfo);
122
+ if (cacheKey) registry.cacheKeyToClassName.set(cacheKey, className);
123
+ }
124
+ if (registry.metrics) {
125
+ registry.metrics.totalInsertions++;
126
+ registry.metrics.misses++;
127
+ }
128
+ return {
129
+ className,
130
+ dispose: () => this.dispose(className, registry)
131
+ };
132
+ }
133
+ /**
134
+ * Inject global styles (rules without a generated tasty class selector)
135
+ * This ensures we don't reserve a tasty class name (t{number}) for global rules,
136
+ * which could otherwise collide with element-level styles and break lookups.
137
+ */
138
+ injectGlobal(rules, options) {
139
+ const root = options?.root || document;
140
+ const registry = this.sheetManager.getRegistry(root);
141
+ if (!rules || rules.length === 0) return { dispose: () => {} };
142
+ if (this.config.autoPropertyTypes !== false) {
143
+ const resolver = registry.propertyTypeResolver;
144
+ const defined = registry.injectedProperties;
145
+ for (const rule of rules) {
146
+ if (!rule.declarations) continue;
147
+ resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
148
+ this.property(name, {
149
+ syntax,
150
+ inherits: true,
151
+ initialValue,
152
+ root
153
+ });
154
+ });
155
+ }
156
+ }
157
+ const key = `global:${this.globalRuleCounter++}`;
158
+ const info = this.sheetManager.insertGlobalRule(registry, rules, key, root);
159
+ if (registry.metrics) registry.metrics.totalInsertions++;
160
+ return { dispose: () => {
161
+ if (info) this.sheetManager.deleteGlobalRule(registry, key);
162
+ } };
163
+ }
164
+ /**
165
+ * Inject raw CSS text directly without parsing
166
+ * This is a low-overhead alternative to createGlobalStyle for raw CSS
167
+ * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking
168
+ */
169
+ injectRawCSS(css, options) {
170
+ const root = options?.root || document;
171
+ return this.sheetManager.injectRawCSS(css, root);
172
+ }
173
+ /**
174
+ * Get raw CSS text for SSR
175
+ */
176
+ getRawCSSText(options) {
177
+ const root = options?.root || document;
178
+ return this.sheetManager.getRawCSSText(root);
179
+ }
180
+ /**
181
+ * Increment refCount for an already-injected cacheKey and return a dispose.
182
+ * Used by useStyles on cache hits (hydration or runtime reuse) where
183
+ * the pipeline was skipped but refCount tracking is still needed.
184
+ * Returns null if the cacheKey is not found.
185
+ */
186
+ trackRef(cacheKey, options) {
187
+ const root = options?.root || document;
188
+ const registry = this.sheetManager.getRegistry(root);
189
+ if (!registry.cacheKeyToClassName.has(cacheKey)) return null;
190
+ const className = registry.cacheKeyToClassName.get(cacheKey);
191
+ const currentRefCount = registry.refCounts.get(className) || 0;
192
+ registry.refCounts.set(className, currentRefCount + 1);
193
+ if (registry.metrics) registry.metrics.hits++;
194
+ return {
195
+ className,
196
+ dispose: () => this.dispose(className, registry)
197
+ };
198
+ }
199
+ /**
200
+ * Dispose of a className
201
+ */
202
+ dispose(className, registry) {
203
+ const currentRefCount = registry.refCounts.get(className);
204
+ if (currentRefCount == null || currentRefCount <= 0) return;
205
+ const newRefCount = currentRefCount - 1;
206
+ registry.refCounts.set(className, newRefCount);
207
+ if (newRefCount === 0) {
208
+ if (registry.metrics) registry.metrics.totalUnused++;
209
+ this.sheetManager.checkCleanupNeeded(registry);
210
+ }
211
+ }
212
+ /**
213
+ * Force bulk cleanup of unused styles
214
+ */
215
+ cleanup(root) {
216
+ const registry = this.sheetManager.getRegistry(root || document);
217
+ this.sheetManager.forceCleanup(registry);
218
+ }
219
+ /**
220
+ * Get CSS text from all sheets (for SSR)
221
+ */
222
+ getCssText(options) {
223
+ const root = options?.root || document;
224
+ const registry = this.sheetManager.getRegistry(root);
225
+ return this.sheetManager.getCssText(registry);
226
+ }
227
+ /**
228
+ * Get CSS only for the provided tasty classNames (e.g., ["t0","t3"])
229
+ */
230
+ getCssTextForClasses(classNames, options) {
231
+ const root = options?.root || document;
232
+ const registry = this.sheetManager.getRegistry(root);
233
+ const cssChunks = [];
234
+ for (const cls of classNames) {
235
+ const info = registry.rules.get(cls);
236
+ if (info) {
237
+ const styleSheet = registry.sheets[info.sheetIndex]?.sheet?.sheet;
238
+ if (styleSheet) {
239
+ const start = Math.max(0, info.ruleIndex);
240
+ const end = Math.min(styleSheet.cssRules.length - 1, info.endRuleIndex ?? info.ruleIndex);
241
+ if (start >= 0 && end >= start && start < styleSheet.cssRules.length) for (let i = start; i <= end; i++) {
242
+ const rule = styleSheet.cssRules[i];
243
+ if (rule) cssChunks.push(rule.cssText);
244
+ }
245
+ } else if (info.cssText && info.cssText.length) cssChunks.push(...info.cssText);
246
+ }
247
+ }
248
+ return cssChunks.join("\n");
249
+ }
250
+ /**
251
+ * Get cache performance metrics
252
+ */
253
+ getMetrics(options) {
254
+ const root = options?.root || document;
255
+ const registry = this.sheetManager.getRegistry(root);
256
+ return this.sheetManager.getMetrics(registry);
257
+ }
258
+ /**
259
+ * Reset cache performance metrics
260
+ */
261
+ resetMetrics(options) {
262
+ const root = options?.root || document;
263
+ const registry = this.sheetManager.getRegistry(root);
264
+ this.sheetManager.resetMetrics(registry);
265
+ }
266
+ /**
267
+ * Define a CSS @property custom property.
268
+ *
269
+ * Accepts tasty token syntax for the property name:
270
+ * - `$name` → defines `--name`
271
+ * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
272
+ * - `--name` → defines `--name` (legacy format)
273
+ *
274
+ * Example:
275
+ * @property --rotation { syntax: "<angle>"; inherits: false; initial-value: 45deg; }
276
+ *
277
+ * Note: No caching or dispose — this defines a global property.
278
+ *
279
+ * If the same property is registered with different options, a warning is emitted
280
+ * but the original definition is preserved (CSS @property cannot be redefined).
281
+ */
282
+ property(name, options) {
283
+ const root = options?.root || document;
284
+ const registry = this.sheetManager.getRegistry(root);
285
+ const effectiveResult = getEffectiveDefinition(name, {
286
+ syntax: options?.syntax,
287
+ inherits: options?.inherits,
288
+ initialValue: options?.initialValue
289
+ });
290
+ if (!effectiveResult.isValid) {
291
+ if (isDevEnv()) console.warn(`[Tasty] property(): ${effectiveResult.error}. Got: "${name}"`);
292
+ return;
293
+ }
294
+ const cssName = effectiveResult.cssName;
295
+ const definition = effectiveResult.definition;
296
+ const normalizedDef = normalizePropertyDefinition(definition);
297
+ if (registry.injectedProperties.get(cssName) !== void 0) return;
298
+ const parts = [];
299
+ if (definition.syntax != null) {
300
+ let syntax = String(definition.syntax).trim();
301
+ if (!/^['"]/u.test(syntax)) syntax = `"${syntax}"`;
302
+ parts.push(`syntax: ${syntax};`);
303
+ }
304
+ const inherits = definition.inherits ?? true;
305
+ parts.push(`inherits: ${inherits ? "true" : "false"};`);
306
+ if (definition.initialValue != null) {
307
+ let initialValueStr;
308
+ if (typeof definition.initialValue === "number") initialValueStr = String(definition.initialValue);
309
+ else initialValueStr = parseStyle(definition.initialValue).output;
310
+ parts.push(`initial-value: ${initialValueStr};`);
311
+ }
312
+ const declarations = parts.join(" ").trim();
313
+ const rule = {
314
+ selector: `@property ${cssName}`,
315
+ declarations
316
+ };
317
+ if (!this.sheetManager.insertGlobalRule(registry, [rule], `property:${name}`, root)) return;
318
+ registry.injectedProperties.set(cssName, normalizedDef);
319
+ }
320
+ /**
321
+ * Check whether a given @property name was already injected by this injector.
322
+ *
323
+ * Accepts tasty token syntax:
324
+ * - `$name` → checks `--name`
325
+ * - `#name` → checks `--name-color`
326
+ * - `--name` → checks `--name` (legacy format)
327
+ */
328
+ isPropertyDefined(name, options) {
329
+ const root = options?.root || document;
330
+ const registry = this.sheetManager.getRegistry(root);
331
+ const effectiveResult = getEffectiveDefinition(name, {});
332
+ if (!effectiveResult.isValid) return false;
333
+ return registry.injectedProperties.has(effectiveResult.cssName);
334
+ }
335
+ /**
336
+ * Inject keyframes and return object with toString() and dispose()
337
+ *
338
+ * Keyframes are cached by content (steps). If the same content is injected
339
+ * multiple times with different provided names, the first injected name is reused.
340
+ *
341
+ * If the same name is provided with different content (collision), a unique
342
+ * name is generated to avoid overwriting the existing keyframes.
343
+ */
344
+ keyframes(steps, nameOrOptions) {
345
+ const isStringName = typeof nameOrOptions === "string";
346
+ const providedName = isStringName ? nameOrOptions : nameOrOptions?.name;
347
+ const root = isStringName ? document : nameOrOptions?.root || document;
348
+ const registry = this.sheetManager.getRegistry(root);
349
+ if (Object.keys(steps).length === 0) return {
350
+ toString: () => "",
351
+ dispose: () => {}
352
+ };
353
+ const contentHash = JSON.stringify(steps);
354
+ const existing = registry.keyframesCache.get(contentHash);
355
+ if (existing) {
356
+ existing.refCount++;
357
+ return {
358
+ toString: () => existing.name,
359
+ dispose: () => this.disposeKeyframes(contentHash, registry)
360
+ };
361
+ }
362
+ let actualName;
363
+ if (providedName) {
364
+ const existingContentForName = registry.keyframesNameToContent.get(providedName);
365
+ if (existingContentForName && existingContentForName !== contentHash) actualName = `${providedName}-k${registry.keyframesCounter++}`;
366
+ else {
367
+ actualName = providedName;
368
+ registry.keyframesNameToContent.set(providedName, contentHash);
369
+ }
370
+ } else actualName = `k${registry.keyframesCounter++}`;
371
+ const result = this.sheetManager.insertKeyframes(registry, steps, actualName, root);
372
+ if (!result) return {
373
+ toString: () => "",
374
+ dispose: () => {}
375
+ };
376
+ const { info, declarations } = result;
377
+ if (this.config.autoPropertyTypes !== false && declarations) registry.propertyTypeResolver.scanDeclarations(declarations, (name) => registry.injectedProperties.has(name), (name, syntax, initialValue) => {
378
+ this.property(name, {
379
+ syntax,
380
+ inherits: true,
381
+ initialValue,
382
+ root
383
+ });
384
+ });
385
+ registry.keyframesCache.set(contentHash, {
386
+ name: actualName,
387
+ refCount: 1,
388
+ info
389
+ });
390
+ if (registry.metrics) {
391
+ registry.metrics.totalInsertions++;
392
+ registry.metrics.misses++;
393
+ }
394
+ return {
395
+ toString: () => actualName,
396
+ dispose: () => this.disposeKeyframes(contentHash, registry)
397
+ };
398
+ }
399
+ /**
400
+ * Dispose keyframes
401
+ */
402
+ disposeKeyframes(contentHash, registry) {
403
+ const entry = registry.keyframesCache.get(contentHash);
404
+ if (!entry) return;
405
+ entry.refCount--;
406
+ if (entry.refCount <= 0) {
407
+ this.sheetManager.deleteKeyframes(registry, entry.info);
408
+ registry.keyframesCache.delete(contentHash);
409
+ for (const [name, hash] of registry.keyframesNameToContent.entries()) if (hash === contentHash) {
410
+ registry.keyframesNameToContent.delete(name);
411
+ break;
412
+ }
413
+ if (registry.metrics) {
414
+ registry.metrics.totalUnused++;
415
+ registry.metrics.stylesCleanedUp++;
416
+ }
417
+ }
418
+ }
419
+ /**
420
+ * Destroy all resources for a root
421
+ */
422
+ destroy(root) {
423
+ const targetRoot = root || document;
424
+ this.sheetManager.cleanup(targetRoot);
425
+ }
426
+ };
427
+
428
+ //#endregion
429
+ export { StyleInjector };
430
+ //# sourceMappingURL=injector.js.map
@@ -0,0 +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 type {\n CacheMetrics,\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 cleanupScheduled = false;\n private globalRuleCounter = 0;\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\n */\n private dispose(className: string, registry: RootRegistry): void {\n const currentRefCount = registry.refCounts.get(className);\n // Guard against stale double-dispose or mismatched lifecycle\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) {\n // Update metrics\n if (registry.metrics) {\n registry.metrics.totalUnused++;\n }\n\n // Check if cleanup should be scheduled\n this.sheetManager.checkCleanupNeeded(registry);\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 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 * 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}\n"],"mappings":";;;;;;;;;AA+BA,SAAS,kBAAkB,SAAyB;AAClD,QAAO,IAAI;;AAGb,IAAa,gBAAb,MAA2B;CACzB,AAAQ;CACR,AAAQ;CACR,AAAQ,mBAAmB;CAC3B,AAAQ,oBAAoB;;CAG5B,IAAI,gBAA8B;AAChC,SAAO,KAAK;;CAGd,YAAY,SAA8B,EAAE,EAAE;AAC5C,OAAK,SAAS;AACd,OAAK,eAAe,IAAI,aAAa,OAAO;;;;;;CAO9C,kBACE,UACA,SACiD;EACjD,MAAM,OAAO,SAAS,QAAQ;EAC9B,MAAM,WAAW,KAAK,aAAa,YAAY,KAAK;AAGpD,MAAI,SAAS,oBAAoB,IAAI,SAAS,CAE5C,QAAO;GACL,WAFgB,SAAS,oBAAoB,IAAI,SAAS;GAG1D,iBAAiB;GAClB;EAIH,MAAM,YAAY,kBAAkB,SAAS,eAAe;EAG5D,MAAM,sBAAsB;GAC1B;GACA,WAAW;GACX,YAAY;GACb;AAGD,WAAS,MAAM,IAAI,WAAW,oBAAoB;AAClD,WAAS,oBAAoB,IAAI,UAAU,UAAU;AAErD,SAAO;GACL;GACA,iBAAiB;GAClB;;;;;CAMH,OACE,OACA,SACc;EACd,MAAM,OAAO,SAAS,QAAQ;EAC9B,MAAM,WAAW,KAAK,aAAa,YAAY,KAAK;AAEpD,MAAI,MAAM,WAAW,EACnB,QAAO;GACL,WAAW;GACX,eAAe;GAGhB;EAMH,MAAM,WAAW,SAAS;EA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BAAuB,SAAS,CAClE,KAAI,SAAS,aAAa;AACxB,aAAS,uBAAuB,OAAO,KAAK;AAC5C;;AAKJ,OAAI,SAAS,SAAS;AACpB,aAAS,QAAQ;AACjB,aAAS,QAAQ;;;;;;;CAQvB,QAAQ,MAAoC;EAC1C,MAAM,aAAa,QAAQ;AAC3B,OAAK,aAAa,QAAQ,WAAW"}
@@ -0,0 +1,136 @@
1
+ import { CacheMetrics, KeyframesInfo, KeyframesSteps, RawCSSResult, RootRegistry, RuleInfo, SheetInfo, StyleInjectorConfig, StyleRule } from "./types.js";
2
+
3
+ //#region src/injector/sheet-manager.d.ts
4
+ declare class SheetManager {
5
+ private rootRegistries;
6
+ private config;
7
+ /** Dedicated style elements for raw CSS per root */
8
+ private rawStyleElements;
9
+ /** Tracking for raw CSS blocks per root */
10
+ private rawCSSBlocks;
11
+ /** Counter for generating unique raw CSS IDs */
12
+ private rawCSSCounter;
13
+ constructor(config: StyleInjectorConfig);
14
+ /**
15
+ * Get or create registry for a root (Document or ShadowRoot)
16
+ */
17
+ getRegistry(root: Document | ShadowRoot): RootRegistry;
18
+ /**
19
+ * Create a new stylesheet for the registry
20
+ */
21
+ createSheet(registry: RootRegistry, root: Document | ShadowRoot): SheetInfo;
22
+ /**
23
+ * Create a style element and append to document
24
+ */
25
+ private createStyleElement;
26
+ /**
27
+ * Insert CSS rules as a single block
28
+ */
29
+ insertRule(registry: RootRegistry, flattenedRules: StyleRule[], className: string, root: Document | ShadowRoot): RuleInfo | null;
30
+ /**
31
+ * Insert global CSS rules
32
+ */
33
+ insertGlobalRule(registry: RootRegistry, flattenedRules: StyleRule[], globalKey: string, root: Document | ShadowRoot): RuleInfo | null;
34
+ /**
35
+ * Delete a global CSS rule by key
36
+ */
37
+ deleteGlobalRule(registry: RootRegistry, globalKey: string): void;
38
+ /**
39
+ * Adjust rule indices after deletion to account for shifting
40
+ */
41
+ private adjustIndicesAfterDeletion;
42
+ /**
43
+ * Delete a CSS rule from the sheet
44
+ */
45
+ deleteRule(registry: RootRegistry, ruleInfo: RuleInfo): void;
46
+ /**
47
+ * Find a sheet with available space or return null
48
+ */
49
+ private findAvailableSheet;
50
+ /**
51
+ * Find an available rule index in the sheet
52
+ */
53
+ findAvailableRuleIndex(sheet: SheetInfo): number;
54
+ /**
55
+ * Schedule bulk cleanup of all unused styles (non-stacking)
56
+ */
57
+ private scheduleBulkCleanup;
58
+ /**
59
+ * Force cleanup of unused styles
60
+ */
61
+ forceCleanup(registry: RootRegistry): void;
62
+ /**
63
+ * Perform bulk cleanup of all unused styles
64
+ */
65
+ private performBulkCleanup;
66
+ /**
67
+ * Get total number of rules across all sheets
68
+ */
69
+ getTotalRuleCount(registry: RootRegistry): number;
70
+ /**
71
+ * Get CSS text from all sheets (for SSR)
72
+ */
73
+ getCssText(registry: RootRegistry): string;
74
+ /**
75
+ * Get cache performance metrics
76
+ */
77
+ getMetrics(registry: RootRegistry): CacheMetrics | null;
78
+ /**
79
+ * Reset cache performance metrics
80
+ */
81
+ resetMetrics(registry: RootRegistry): void;
82
+ /**
83
+ * Convert keyframes steps to CSS string.
84
+ * Public so the SSR collector can format keyframes without DOM access.
85
+ * Returns both the CSS text and a combined declarations string for property type scanning.
86
+ */
87
+ stepsToCSS(steps: KeyframesSteps): {
88
+ css: string;
89
+ declarations: string;
90
+ };
91
+ /**
92
+ * Insert keyframes rule.
93
+ * Returns the KeyframesInfo and the raw declarations string for property type scanning.
94
+ */
95
+ insertKeyframes(registry: RootRegistry, steps: KeyframesSteps, name: string, root: Document | ShadowRoot): {
96
+ info: KeyframesInfo;
97
+ declarations: string;
98
+ } | null;
99
+ /**
100
+ * Delete keyframes rule
101
+ */
102
+ deleteKeyframes(registry: RootRegistry, info: KeyframesInfo): void;
103
+ /**
104
+ * Schedule async cleanup check (non-stacking)
105
+ */
106
+ checkCleanupNeeded(registry: RootRegistry): void;
107
+ /**
108
+ * Perform the actual cleanup check (called asynchronously)
109
+ */
110
+ private performCleanupCheck;
111
+ /**
112
+ * Clean up resources for a root
113
+ */
114
+ cleanup(root: Document | ShadowRoot): void;
115
+ /**
116
+ * Get or create a dedicated style element for raw CSS
117
+ * Raw CSS is kept separate from tasty-managed sheets to avoid index conflicts
118
+ */
119
+ private getOrCreateRawStyleElement;
120
+ /**
121
+ * Inject raw CSS text directly without parsing
122
+ * Returns a dispose function to remove the injected CSS
123
+ */
124
+ injectRawCSS(css: string, root: Document | ShadowRoot): RawCSSResult;
125
+ /**
126
+ * Remove a raw CSS block by ID
127
+ */
128
+ private disposeRawCSS;
129
+ /**
130
+ * Get the raw CSS content for SSR
131
+ */
132
+ getRawCSSText(root: Document | ShadowRoot): string;
133
+ }
134
+ //#endregion
135
+ export { SheetManager };
136
+ //# sourceMappingURL=sheet-manager.d.ts.map