@tenphi/tasty 0.1.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 (359) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +236 -0
  3. package/dist/_virtual/_rolldown/runtime.mjs +7 -0
  4. package/dist/chunks/cacheKey.d.ts +1 -0
  5. package/dist/chunks/cacheKey.js +70 -0
  6. package/dist/chunks/cacheKey.js.map +1 -0
  7. package/dist/chunks/cacheKey.mjs +70 -0
  8. package/dist/chunks/cacheKey.mjs.map +1 -0
  9. package/dist/chunks/definitions.d.ts +37 -0
  10. package/dist/chunks/definitions.js +260 -0
  11. package/dist/chunks/definitions.js.map +1 -0
  12. package/dist/chunks/definitions.mjs +260 -0
  13. package/dist/chunks/definitions.mjs.map +1 -0
  14. package/dist/chunks/index.d.ts +3 -0
  15. package/dist/chunks/renderChunk.d.ts +2 -0
  16. package/dist/chunks/renderChunk.js +61 -0
  17. package/dist/chunks/renderChunk.js.map +1 -0
  18. package/dist/chunks/renderChunk.mjs +61 -0
  19. package/dist/chunks/renderChunk.mjs.map +1 -0
  20. package/dist/config.d.ts +279 -0
  21. package/dist/config.js +400 -0
  22. package/dist/config.js.map +1 -0
  23. package/dist/config.mjs +231 -0
  24. package/dist/config.mjs.map +1 -0
  25. package/dist/css-writer.d.mts +45 -0
  26. package/dist/css-writer.mjs +74 -0
  27. package/dist/css-writer.mjs.map +1 -0
  28. package/dist/debug.d.ts +204 -0
  29. package/dist/debug.js +733 -0
  30. package/dist/debug.js.map +1 -0
  31. package/dist/extractor.d.mts +24 -0
  32. package/dist/extractor.mjs +150 -0
  33. package/dist/extractor.mjs.map +1 -0
  34. package/dist/hooks/index.d.ts +5 -0
  35. package/dist/hooks/useGlobalStyles.d.ts +27 -0
  36. package/dist/hooks/useGlobalStyles.js +56 -0
  37. package/dist/hooks/useGlobalStyles.js.map +1 -0
  38. package/dist/hooks/useKeyframes.d.ts +56 -0
  39. package/dist/hooks/useKeyframes.js +54 -0
  40. package/dist/hooks/useKeyframes.js.map +1 -0
  41. package/dist/hooks/useProperty.d.ts +79 -0
  42. package/dist/hooks/useProperty.js +91 -0
  43. package/dist/hooks/useProperty.js.map +1 -0
  44. package/dist/hooks/useRawCSS.d.ts +53 -0
  45. package/dist/hooks/useRawCSS.js +28 -0
  46. package/dist/hooks/useRawCSS.js.map +1 -0
  47. package/dist/hooks/useStyles.d.ts +40 -0
  48. package/dist/hooks/useStyles.js +169 -0
  49. package/dist/hooks/useStyles.js.map +1 -0
  50. package/dist/index.d.ts +38 -0
  51. package/dist/index.js +30 -0
  52. package/dist/injector/index.d.ts +157 -0
  53. package/dist/injector/index.js +154 -0
  54. package/dist/injector/index.js.map +1 -0
  55. package/dist/injector/injector.d.ts +139 -0
  56. package/dist/injector/injector.js +404 -0
  57. package/dist/injector/injector.js.map +1 -0
  58. package/dist/injector/injector.mjs +404 -0
  59. package/dist/injector/injector.mjs.map +1 -0
  60. package/dist/injector/sheet-manager.d.ts +127 -0
  61. package/dist/injector/sheet-manager.js +714 -0
  62. package/dist/injector/sheet-manager.js.map +1 -0
  63. package/dist/injector/sheet-manager.mjs +714 -0
  64. package/dist/injector/sheet-manager.mjs.map +1 -0
  65. package/dist/injector/types.d.mts +18 -0
  66. package/dist/injector/types.d.ts +135 -0
  67. package/dist/keyframes/index.js +206 -0
  68. package/dist/keyframes/index.js.map +1 -0
  69. package/dist/keyframes/index.mjs +156 -0
  70. package/dist/keyframes/index.mjs.map +1 -0
  71. package/dist/parser/classify.js +319 -0
  72. package/dist/parser/classify.js.map +1 -0
  73. package/dist/parser/classify.mjs +319 -0
  74. package/dist/parser/classify.mjs.map +1 -0
  75. package/dist/parser/const.js +33 -0
  76. package/dist/parser/const.js.map +1 -0
  77. package/dist/parser/const.mjs +33 -0
  78. package/dist/parser/const.mjs.map +1 -0
  79. package/dist/parser/lru.js +109 -0
  80. package/dist/parser/lru.js.map +1 -0
  81. package/dist/parser/lru.mjs +109 -0
  82. package/dist/parser/lru.mjs.map +1 -0
  83. package/dist/parser/parser.d.ts +25 -0
  84. package/dist/parser/parser.js +116 -0
  85. package/dist/parser/parser.js.map +1 -0
  86. package/dist/parser/parser.mjs +116 -0
  87. package/dist/parser/parser.mjs.map +1 -0
  88. package/dist/parser/tokenizer.js +69 -0
  89. package/dist/parser/tokenizer.js.map +1 -0
  90. package/dist/parser/tokenizer.mjs +69 -0
  91. package/dist/parser/tokenizer.mjs.map +1 -0
  92. package/dist/parser/types.d.mts +37 -0
  93. package/dist/parser/types.d.ts +46 -0
  94. package/dist/parser/types.js +46 -0
  95. package/dist/parser/types.js.map +1 -0
  96. package/dist/parser/types.mjs +46 -0
  97. package/dist/parser/types.mjs.map +1 -0
  98. package/dist/pipeline/conditions.js +377 -0
  99. package/dist/pipeline/conditions.js.map +1 -0
  100. package/dist/pipeline/conditions.mjs +377 -0
  101. package/dist/pipeline/conditions.mjs.map +1 -0
  102. package/dist/pipeline/exclusive.d.ts +1 -0
  103. package/dist/pipeline/exclusive.js +231 -0
  104. package/dist/pipeline/exclusive.js.map +1 -0
  105. package/dist/pipeline/exclusive.mjs +231 -0
  106. package/dist/pipeline/exclusive.mjs.map +1 -0
  107. package/dist/pipeline/index.d.ts +53 -0
  108. package/dist/pipeline/index.js +641 -0
  109. package/dist/pipeline/index.js.map +1 -0
  110. package/dist/pipeline/index.mjs +635 -0
  111. package/dist/pipeline/index.mjs.map +1 -0
  112. package/dist/pipeline/materialize.js +821 -0
  113. package/dist/pipeline/materialize.js.map +1 -0
  114. package/dist/pipeline/materialize.mjs +821 -0
  115. package/dist/pipeline/materialize.mjs.map +1 -0
  116. package/dist/pipeline/parseStateKey.d.ts +1 -0
  117. package/dist/pipeline/parseStateKey.js +418 -0
  118. package/dist/pipeline/parseStateKey.js.map +1 -0
  119. package/dist/pipeline/parseStateKey.mjs +418 -0
  120. package/dist/pipeline/parseStateKey.mjs.map +1 -0
  121. package/dist/pipeline/simplify.js +557 -0
  122. package/dist/pipeline/simplify.js.map +1 -0
  123. package/dist/pipeline/simplify.mjs +557 -0
  124. package/dist/pipeline/simplify.mjs.map +1 -0
  125. package/dist/plugins/index.d.ts +2 -0
  126. package/dist/plugins/okhsl-plugin.d.ts +35 -0
  127. package/dist/plugins/okhsl-plugin.js +371 -0
  128. package/dist/plugins/okhsl-plugin.js.map +1 -0
  129. package/dist/plugins/okhsl-plugin.mjs +345 -0
  130. package/dist/plugins/okhsl-plugin.mjs.map +1 -0
  131. package/dist/plugins/types.d.mts +49 -0
  132. package/dist/plugins/types.d.ts +69 -0
  133. package/dist/properties/index.js +158 -0
  134. package/dist/properties/index.js.map +1 -0
  135. package/dist/properties/index.mjs +141 -0
  136. package/dist/properties/index.mjs.map +1 -0
  137. package/dist/states/index.d.ts +45 -0
  138. package/dist/states/index.js +389 -0
  139. package/dist/states/index.js.map +1 -0
  140. package/dist/states/index.mjs +161 -0
  141. package/dist/states/index.mjs.map +1 -0
  142. package/dist/static/index.d.ts +5 -0
  143. package/dist/static/index.js +5 -0
  144. package/dist/static/tastyStatic.d.ts +46 -0
  145. package/dist/static/tastyStatic.js +31 -0
  146. package/dist/static/tastyStatic.js.map +1 -0
  147. package/dist/static/types.d.ts +49 -0
  148. package/dist/static/types.js +24 -0
  149. package/dist/static/types.js.map +1 -0
  150. package/dist/styles/align.d.ts +15 -0
  151. package/dist/styles/align.js +14 -0
  152. package/dist/styles/align.js.map +1 -0
  153. package/dist/styles/align.mjs +14 -0
  154. package/dist/styles/align.mjs.map +1 -0
  155. package/dist/styles/border.d.ts +25 -0
  156. package/dist/styles/border.js +114 -0
  157. package/dist/styles/border.js.map +1 -0
  158. package/dist/styles/border.mjs +114 -0
  159. package/dist/styles/border.mjs.map +1 -0
  160. package/dist/styles/color.d.ts +14 -0
  161. package/dist/styles/color.js +23 -0
  162. package/dist/styles/color.js.map +1 -0
  163. package/dist/styles/color.mjs +23 -0
  164. package/dist/styles/color.mjs.map +1 -0
  165. package/dist/styles/createStyle.js +77 -0
  166. package/dist/styles/createStyle.js.map +1 -0
  167. package/dist/styles/createStyle.mjs +77 -0
  168. package/dist/styles/createStyle.mjs.map +1 -0
  169. package/dist/styles/dimension.js +97 -0
  170. package/dist/styles/dimension.js.map +1 -0
  171. package/dist/styles/dimension.mjs +97 -0
  172. package/dist/styles/dimension.mjs.map +1 -0
  173. package/dist/styles/display.d.ts +37 -0
  174. package/dist/styles/display.js +67 -0
  175. package/dist/styles/display.js.map +1 -0
  176. package/dist/styles/display.mjs +67 -0
  177. package/dist/styles/display.mjs.map +1 -0
  178. package/dist/styles/fade.d.ts +15 -0
  179. package/dist/styles/fade.js +58 -0
  180. package/dist/styles/fade.js.map +1 -0
  181. package/dist/styles/fade.mjs +58 -0
  182. package/dist/styles/fade.mjs.map +1 -0
  183. package/dist/styles/fill.d.ts +44 -0
  184. package/dist/styles/fill.js +51 -0
  185. package/dist/styles/fill.js.map +1 -0
  186. package/dist/styles/fill.mjs +51 -0
  187. package/dist/styles/fill.mjs.map +1 -0
  188. package/dist/styles/flow.d.ts +16 -0
  189. package/dist/styles/flow.js +12 -0
  190. package/dist/styles/flow.js.map +1 -0
  191. package/dist/styles/flow.mjs +12 -0
  192. package/dist/styles/flow.mjs.map +1 -0
  193. package/dist/styles/gap.d.ts +31 -0
  194. package/dist/styles/gap.js +37 -0
  195. package/dist/styles/gap.js.map +1 -0
  196. package/dist/styles/gap.mjs +37 -0
  197. package/dist/styles/gap.mjs.map +1 -0
  198. package/dist/styles/height.d.ts +17 -0
  199. package/dist/styles/height.js +20 -0
  200. package/dist/styles/height.js.map +1 -0
  201. package/dist/styles/height.mjs +20 -0
  202. package/dist/styles/height.mjs.map +1 -0
  203. package/dist/styles/index.d.ts +2 -0
  204. package/dist/styles/index.js +9 -0
  205. package/dist/styles/index.js.map +1 -0
  206. package/dist/styles/index.mjs +9 -0
  207. package/dist/styles/index.mjs.map +1 -0
  208. package/dist/styles/inset.d.ts +50 -0
  209. package/dist/styles/inset.js +142 -0
  210. package/dist/styles/inset.js.map +1 -0
  211. package/dist/styles/inset.mjs +142 -0
  212. package/dist/styles/inset.mjs.map +1 -0
  213. package/dist/styles/justify.d.ts +15 -0
  214. package/dist/styles/justify.js +14 -0
  215. package/dist/styles/justify.js.map +1 -0
  216. package/dist/styles/justify.mjs +14 -0
  217. package/dist/styles/justify.mjs.map +1 -0
  218. package/dist/styles/list.d.ts +16 -0
  219. package/dist/styles/list.js +98 -0
  220. package/dist/styles/list.js.map +1 -0
  221. package/dist/styles/margin.d.ts +28 -0
  222. package/dist/styles/margin.js +96 -0
  223. package/dist/styles/margin.js.map +1 -0
  224. package/dist/styles/margin.mjs +96 -0
  225. package/dist/styles/margin.mjs.map +1 -0
  226. package/dist/styles/outline.d.ts +29 -0
  227. package/dist/styles/outline.js +65 -0
  228. package/dist/styles/outline.js.map +1 -0
  229. package/dist/styles/outline.mjs +65 -0
  230. package/dist/styles/outline.mjs.map +1 -0
  231. package/dist/styles/padding.d.ts +28 -0
  232. package/dist/styles/padding.js +96 -0
  233. package/dist/styles/padding.js.map +1 -0
  234. package/dist/styles/padding.mjs +96 -0
  235. package/dist/styles/padding.mjs.map +1 -0
  236. package/dist/styles/predefined.d.ts +74 -0
  237. package/dist/styles/predefined.js +241 -0
  238. package/dist/styles/predefined.js.map +1 -0
  239. package/dist/styles/predefined.mjs +232 -0
  240. package/dist/styles/predefined.mjs.map +1 -0
  241. package/dist/styles/preset.d.ts +47 -0
  242. package/dist/styles/preset.js +126 -0
  243. package/dist/styles/preset.js.map +1 -0
  244. package/dist/styles/preset.mjs +126 -0
  245. package/dist/styles/preset.mjs.map +1 -0
  246. package/dist/styles/radius.d.ts +14 -0
  247. package/dist/styles/radius.js +51 -0
  248. package/dist/styles/radius.js.map +1 -0
  249. package/dist/styles/radius.mjs +51 -0
  250. package/dist/styles/radius.mjs.map +1 -0
  251. package/dist/styles/scrollbar.d.ts +21 -0
  252. package/dist/styles/scrollbar.js +105 -0
  253. package/dist/styles/scrollbar.js.map +1 -0
  254. package/dist/styles/scrollbar.mjs +105 -0
  255. package/dist/styles/scrollbar.mjs.map +1 -0
  256. package/dist/styles/shadow.d.ts +14 -0
  257. package/dist/styles/shadow.js +24 -0
  258. package/dist/styles/shadow.js.map +1 -0
  259. package/dist/styles/shadow.mjs +24 -0
  260. package/dist/styles/shadow.mjs.map +1 -0
  261. package/dist/styles/styledScrollbar.d.ts +47 -0
  262. package/dist/styles/styledScrollbar.js +38 -0
  263. package/dist/styles/styledScrollbar.js.map +1 -0
  264. package/dist/styles/styledScrollbar.mjs +38 -0
  265. package/dist/styles/styledScrollbar.mjs.map +1 -0
  266. package/dist/styles/transition.d.ts +14 -0
  267. package/dist/styles/transition.js +138 -0
  268. package/dist/styles/transition.js.map +1 -0
  269. package/dist/styles/transition.mjs +138 -0
  270. package/dist/styles/transition.mjs.map +1 -0
  271. package/dist/styles/types.d.mts +492 -0
  272. package/dist/styles/types.d.ts +496 -0
  273. package/dist/styles/width.d.ts +17 -0
  274. package/dist/styles/width.js +20 -0
  275. package/dist/styles/width.js.map +1 -0
  276. package/dist/styles/width.mjs +20 -0
  277. package/dist/styles/width.mjs.map +1 -0
  278. package/dist/tasty.d.ts +983 -0
  279. package/dist/tasty.js +191 -0
  280. package/dist/tasty.js.map +1 -0
  281. package/dist/tokens/typography.d.ts +19 -0
  282. package/dist/tokens/typography.js +237 -0
  283. package/dist/tokens/typography.js.map +1 -0
  284. package/dist/types.d.ts +182 -0
  285. package/dist/utils/cache-wrapper.js +26 -0
  286. package/dist/utils/cache-wrapper.js.map +1 -0
  287. package/dist/utils/cache-wrapper.mjs +26 -0
  288. package/dist/utils/cache-wrapper.mjs.map +1 -0
  289. package/dist/utils/case-converter.js +8 -0
  290. package/dist/utils/case-converter.js.map +1 -0
  291. package/dist/utils/case-converter.mjs +8 -0
  292. package/dist/utils/case-converter.mjs.map +1 -0
  293. package/dist/utils/colors.d.ts +5 -0
  294. package/dist/utils/colors.js +9 -0
  295. package/dist/utils/colors.js.map +1 -0
  296. package/dist/utils/dotize.d.ts +26 -0
  297. package/dist/utils/dotize.js +122 -0
  298. package/dist/utils/dotize.js.map +1 -0
  299. package/dist/utils/filter-base-props.d.ts +15 -0
  300. package/dist/utils/filter-base-props.js +45 -0
  301. package/dist/utils/filter-base-props.js.map +1 -0
  302. package/dist/utils/get-display-name.d.ts +7 -0
  303. package/dist/utils/get-display-name.js +10 -0
  304. package/dist/utils/get-display-name.js.map +1 -0
  305. package/dist/utils/hsl-to-rgb.js +38 -0
  306. package/dist/utils/hsl-to-rgb.js.map +1 -0
  307. package/dist/utils/hsl-to-rgb.mjs +38 -0
  308. package/dist/utils/hsl-to-rgb.mjs.map +1 -0
  309. package/dist/utils/is-dev-env.js +19 -0
  310. package/dist/utils/is-dev-env.js.map +1 -0
  311. package/dist/utils/is-dev-env.mjs +19 -0
  312. package/dist/utils/is-dev-env.mjs.map +1 -0
  313. package/dist/utils/merge-styles.d.ts +7 -0
  314. package/dist/utils/merge-styles.js +146 -0
  315. package/dist/utils/merge-styles.js.map +1 -0
  316. package/dist/utils/merge-styles.mjs +146 -0
  317. package/dist/utils/merge-styles.mjs.map +1 -0
  318. package/dist/utils/mod-attrs.d.ts +8 -0
  319. package/dist/utils/mod-attrs.js +21 -0
  320. package/dist/utils/mod-attrs.js.map +1 -0
  321. package/dist/utils/okhsl-to-rgb.js +296 -0
  322. package/dist/utils/okhsl-to-rgb.js.map +1 -0
  323. package/dist/utils/okhsl-to-rgb.mjs +296 -0
  324. package/dist/utils/okhsl-to-rgb.mjs.map +1 -0
  325. package/dist/utils/process-tokens.d.ts +31 -0
  326. package/dist/utils/process-tokens.js +171 -0
  327. package/dist/utils/process-tokens.js.map +1 -0
  328. package/dist/utils/process-tokens.mjs +28 -0
  329. package/dist/utils/process-tokens.mjs.map +1 -0
  330. package/dist/utils/resolve-recipes.d.ts +17 -0
  331. package/dist/utils/resolve-recipes.js +143 -0
  332. package/dist/utils/resolve-recipes.js.map +1 -0
  333. package/dist/utils/resolve-recipes.mjs +143 -0
  334. package/dist/utils/resolve-recipes.mjs.map +1 -0
  335. package/dist/utils/string.js +8 -0
  336. package/dist/utils/string.js.map +1 -0
  337. package/dist/utils/string.mjs +8 -0
  338. package/dist/utils/string.mjs.map +1 -0
  339. package/dist/utils/styles.d.mts +18 -0
  340. package/dist/utils/styles.d.ts +183 -0
  341. package/dist/utils/styles.js +585 -0
  342. package/dist/utils/styles.js.map +1 -0
  343. package/dist/utils/styles.mjs +346 -0
  344. package/dist/utils/styles.mjs.map +1 -0
  345. package/dist/utils/typography.d.ts +36 -0
  346. package/dist/utils/typography.js +53 -0
  347. package/dist/utils/typography.js.map +1 -0
  348. package/dist/utils/warnings.d.ts +16 -0
  349. package/dist/utils/warnings.js +16 -0
  350. package/dist/utils/warnings.js.map +1 -0
  351. package/dist/zero/babel.d.mts +108 -0
  352. package/dist/zero/babel.mjs +282 -0
  353. package/dist/zero/babel.mjs.map +1 -0
  354. package/dist/zero/index.d.mts +3 -0
  355. package/dist/zero/index.mjs +4 -0
  356. package/dist/zero/next.d.mts +60 -0
  357. package/dist/zero/next.mjs +78 -0
  358. package/dist/zero/next.mjs.map +1 -0
  359. package/package.json +127 -0
@@ -0,0 +1,404 @@
1
+ import { parseStyle } from "../utils/styles.mjs";
2
+ import { colorInitialValueToRgb, getEffectiveDefinition, normalizePropertyDefinition } from "../properties/index.mjs";
3
+ import { isDevEnv } from "../utils/is-dev-env.mjs";
4
+ import { SheetManager } from "./sheet-manager.mjs";
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
+ const colorPropRegex = /^\s*(--[a-z0-9-]+-color)\s*:/i;
96
+ for (const rule of rulesToInsert) {
97
+ if (!rule.declarations) continue;
98
+ const parts = rule.declarations.split(/;+\s*/);
99
+ for (const part of parts) {
100
+ if (!part) continue;
101
+ const match = colorPropRegex.exec(part);
102
+ if (match) {
103
+ const propName = match[1];
104
+ if (!this.isPropertyDefined(propName, { root })) this.property(propName, {
105
+ syntax: "<color>",
106
+ initialValue: "transparent",
107
+ root
108
+ });
109
+ }
110
+ }
111
+ }
112
+ const ruleInfo = this.sheetManager.insertRule(registry, rulesToInsert, className, root);
113
+ if (!ruleInfo) {
114
+ if (registry.metrics) registry.metrics.misses++;
115
+ return {
116
+ className,
117
+ dispose: () => {}
118
+ };
119
+ }
120
+ registry.refCounts.set(className, 1);
121
+ if (isPreAllocated) registry.rules.set(className, ruleInfo);
122
+ else {
123
+ registry.rules.set(className, ruleInfo);
124
+ if (cacheKey) registry.cacheKeyToClassName.set(cacheKey, className);
125
+ }
126
+ if (registry.metrics) {
127
+ registry.metrics.totalInsertions++;
128
+ registry.metrics.misses++;
129
+ }
130
+ return {
131
+ className,
132
+ dispose: () => this.dispose(className, registry)
133
+ };
134
+ }
135
+ /**
136
+ * Inject global styles (rules without a generated tasty class selector)
137
+ * This ensures we don't reserve a tasty class name (t{number}) for global rules,
138
+ * which could otherwise collide with element-level styles and break lookups.
139
+ */
140
+ injectGlobal(rules, options) {
141
+ const root = options?.root || document;
142
+ const registry = this.sheetManager.getRegistry(root);
143
+ if (!rules || rules.length === 0) return { dispose: () => {} };
144
+ const key = `global:${this.globalRuleCounter++}`;
145
+ const info = this.sheetManager.insertGlobalRule(registry, rules, key, root);
146
+ if (registry.metrics) registry.metrics.totalInsertions++;
147
+ return { dispose: () => {
148
+ if (info) this.sheetManager.deleteGlobalRule(registry, key);
149
+ } };
150
+ }
151
+ /**
152
+ * Inject raw CSS text directly without parsing
153
+ * This is a low-overhead alternative to createGlobalStyle for raw CSS
154
+ * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking
155
+ */
156
+ injectRawCSS(css, options) {
157
+ const root = options?.root || document;
158
+ return this.sheetManager.injectRawCSS(css, root);
159
+ }
160
+ /**
161
+ * Get raw CSS text for SSR
162
+ */
163
+ getRawCSSText(options) {
164
+ const root = options?.root || document;
165
+ return this.sheetManager.getRawCSSText(root);
166
+ }
167
+ /**
168
+ * Dispose of a className
169
+ */
170
+ dispose(className, registry) {
171
+ const currentRefCount = registry.refCounts.get(className);
172
+ if (currentRefCount == null || currentRefCount <= 0) return;
173
+ const newRefCount = currentRefCount - 1;
174
+ registry.refCounts.set(className, newRefCount);
175
+ if (newRefCount === 0) {
176
+ if (registry.metrics) registry.metrics.totalUnused++;
177
+ this.sheetManager.checkCleanupNeeded(registry);
178
+ }
179
+ }
180
+ /**
181
+ * Force bulk cleanup of unused styles
182
+ */
183
+ cleanup(root) {
184
+ const registry = this.sheetManager.getRegistry(root || document);
185
+ this.sheetManager.forceCleanup(registry);
186
+ }
187
+ /**
188
+ * Get CSS text from all sheets (for SSR)
189
+ */
190
+ getCssText(options) {
191
+ const root = options?.root || document;
192
+ const registry = this.sheetManager.getRegistry(root);
193
+ return this.sheetManager.getCssText(registry);
194
+ }
195
+ /**
196
+ * Get CSS only for the provided tasty classNames (e.g., ["t0","t3"])
197
+ */
198
+ getCssTextForClasses(classNames, options) {
199
+ const root = options?.root || document;
200
+ const registry = this.sheetManager.getRegistry(root);
201
+ const cssChunks = [];
202
+ for (const cls of classNames) {
203
+ const info = registry.rules.get(cls);
204
+ if (info) {
205
+ const styleSheet = registry.sheets[info.sheetIndex]?.sheet?.sheet;
206
+ if (styleSheet) {
207
+ const start = Math.max(0, info.ruleIndex);
208
+ const end = Math.min(styleSheet.cssRules.length - 1, info.endRuleIndex ?? info.ruleIndex);
209
+ if (start >= 0 && end >= start && start < styleSheet.cssRules.length) for (let i = start; i <= end; i++) {
210
+ const rule = styleSheet.cssRules[i];
211
+ if (rule) cssChunks.push(rule.cssText);
212
+ }
213
+ } else if (info.cssText && info.cssText.length) cssChunks.push(...info.cssText);
214
+ }
215
+ }
216
+ return cssChunks.join("\n");
217
+ }
218
+ /**
219
+ * Get cache performance metrics
220
+ */
221
+ getMetrics(options) {
222
+ const root = options?.root || document;
223
+ const registry = this.sheetManager.getRegistry(root);
224
+ return this.sheetManager.getMetrics(registry);
225
+ }
226
+ /**
227
+ * Reset cache performance metrics
228
+ */
229
+ resetMetrics(options) {
230
+ const root = options?.root || document;
231
+ const registry = this.sheetManager.getRegistry(root);
232
+ this.sheetManager.resetMetrics(registry);
233
+ }
234
+ /**
235
+ * Define a CSS @property custom property.
236
+ *
237
+ * Accepts tasty token syntax for the property name:
238
+ * - `$name` → defines `--name`
239
+ * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
240
+ * - `--name` → defines `--name` (legacy format)
241
+ *
242
+ * Example:
243
+ * @property --rotation { syntax: "<angle>"; inherits: false; initial-value: 45deg; }
244
+ *
245
+ * Note: No caching or dispose — this defines a global property.
246
+ *
247
+ * If the same property is registered with different options, a warning is emitted
248
+ * but the original definition is preserved (CSS @property cannot be redefined).
249
+ */
250
+ property(name, options) {
251
+ const root = options?.root || document;
252
+ const registry = this.sheetManager.getRegistry(root);
253
+ const effectiveResult = getEffectiveDefinition(name, {
254
+ syntax: options?.syntax,
255
+ inherits: options?.inherits,
256
+ initialValue: options?.initialValue
257
+ });
258
+ if (!effectiveResult.isValid) {
259
+ if (isDevEnv()) console.warn(`[Tasty] property(): ${effectiveResult.error}. Got: "${name}"`);
260
+ return;
261
+ }
262
+ const cssName = effectiveResult.cssName;
263
+ const definition = effectiveResult.definition;
264
+ const normalizedDef = normalizePropertyDefinition(definition);
265
+ const existingDef = registry.injectedProperties.get(cssName);
266
+ if (existingDef !== void 0) {
267
+ if (existingDef !== normalizedDef) {
268
+ if (isDevEnv()) console.warn(`[Tasty] @property ${cssName} was already defined with a different declaration. The new declaration will be ignored. Original: ${existingDef}, New: ${normalizedDef}`);
269
+ }
270
+ return;
271
+ }
272
+ const parts = [];
273
+ if (definition.syntax != null) {
274
+ let syntax = String(definition.syntax).trim();
275
+ if (!/^['"]/u.test(syntax)) syntax = `"${syntax}"`;
276
+ parts.push(`syntax: ${syntax};`);
277
+ }
278
+ const inherits = definition.inherits ?? true;
279
+ parts.push(`inherits: ${inherits ? "true" : "false"};`);
280
+ if (definition.initialValue != null) {
281
+ let initialValueStr;
282
+ if (typeof definition.initialValue === "number") initialValueStr = String(definition.initialValue);
283
+ else initialValueStr = parseStyle(definition.initialValue).output;
284
+ parts.push(`initial-value: ${initialValueStr};`);
285
+ }
286
+ const declarations = parts.join(" ").trim();
287
+ const rule = {
288
+ selector: `@property ${cssName}`,
289
+ declarations
290
+ };
291
+ if (!this.sheetManager.insertGlobalRule(registry, [rule], `property:${name}`, root)) return;
292
+ registry.injectedProperties.set(cssName, normalizedDef);
293
+ if (effectiveResult.isColor) {
294
+ const rgbCssName = `${cssName}-rgb`;
295
+ if (!this.isPropertyDefined(rgbCssName, { root })) this.property(rgbCssName, {
296
+ syntax: "<number>+",
297
+ inherits: definition.inherits,
298
+ initialValue: colorInitialValueToRgb(definition.initialValue),
299
+ root
300
+ });
301
+ }
302
+ }
303
+ /**
304
+ * Check whether a given @property name was already injected by this injector.
305
+ *
306
+ * Accepts tasty token syntax:
307
+ * - `$name` → checks `--name`
308
+ * - `#name` → checks `--name-color`
309
+ * - `--name` → checks `--name` (legacy format)
310
+ */
311
+ isPropertyDefined(name, options) {
312
+ const root = options?.root || document;
313
+ const registry = this.sheetManager.getRegistry(root);
314
+ const effectiveResult = getEffectiveDefinition(name, {});
315
+ if (!effectiveResult.isValid) return false;
316
+ return registry.injectedProperties.has(effectiveResult.cssName);
317
+ }
318
+ /**
319
+ * Inject keyframes and return object with toString() and dispose()
320
+ *
321
+ * Keyframes are cached by content (steps). If the same content is injected
322
+ * multiple times with different provided names, the first injected name is reused.
323
+ *
324
+ * If the same name is provided with different content (collision), a unique
325
+ * name is generated to avoid overwriting the existing keyframes.
326
+ */
327
+ keyframes(steps, nameOrOptions) {
328
+ const isStringName = typeof nameOrOptions === "string";
329
+ const providedName = isStringName ? nameOrOptions : nameOrOptions?.name;
330
+ const root = isStringName ? document : nameOrOptions?.root || document;
331
+ const registry = this.sheetManager.getRegistry(root);
332
+ if (Object.keys(steps).length === 0) return {
333
+ toString: () => "",
334
+ dispose: () => {}
335
+ };
336
+ const contentHash = JSON.stringify(steps);
337
+ const existing = registry.keyframesCache.get(contentHash);
338
+ if (existing) {
339
+ existing.refCount++;
340
+ return {
341
+ toString: () => existing.name,
342
+ dispose: () => this.disposeKeyframes(contentHash, registry)
343
+ };
344
+ }
345
+ let actualName;
346
+ if (providedName) {
347
+ const existingContentForName = registry.keyframesNameToContent.get(providedName);
348
+ if (existingContentForName && existingContentForName !== contentHash) actualName = `${providedName}-k${registry.keyframesCounter++}`;
349
+ else {
350
+ actualName = providedName;
351
+ registry.keyframesNameToContent.set(providedName, contentHash);
352
+ }
353
+ } else actualName = `k${registry.keyframesCounter++}`;
354
+ const info = this.sheetManager.insertKeyframes(registry, steps, actualName, root);
355
+ if (!info) return {
356
+ toString: () => "",
357
+ dispose: () => {}
358
+ };
359
+ registry.keyframesCache.set(contentHash, {
360
+ name: actualName,
361
+ refCount: 1,
362
+ info
363
+ });
364
+ if (registry.metrics) {
365
+ registry.metrics.totalInsertions++;
366
+ registry.metrics.misses++;
367
+ }
368
+ return {
369
+ toString: () => actualName,
370
+ dispose: () => this.disposeKeyframes(contentHash, registry)
371
+ };
372
+ }
373
+ /**
374
+ * Dispose keyframes
375
+ */
376
+ disposeKeyframes(contentHash, registry) {
377
+ const entry = registry.keyframesCache.get(contentHash);
378
+ if (!entry) return;
379
+ entry.refCount--;
380
+ if (entry.refCount <= 0) {
381
+ this.sheetManager.deleteKeyframes(registry, entry.info);
382
+ registry.keyframesCache.delete(contentHash);
383
+ for (const [name, hash] of registry.keyframesNameToContent.entries()) if (hash === contentHash) {
384
+ registry.keyframesNameToContent.delete(name);
385
+ break;
386
+ }
387
+ if (registry.metrics) {
388
+ registry.metrics.totalUnused++;
389
+ registry.metrics.stylesCleanedUp++;
390
+ }
391
+ }
392
+ }
393
+ /**
394
+ * Destroy all resources for a root
395
+ */
396
+ destroy(root) {
397
+ const targetRoot = root || document;
398
+ this.sheetManager.cleanup(targetRoot);
399
+ }
400
+ };
401
+
402
+ //#endregion
403
+ export { StyleInjector };
404
+ //# sourceMappingURL=injector.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injector.mjs","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 colorInitialValueToRgb,\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: () => { /* noop */ },\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 // Before inserting, auto-register @property for any color custom properties being defined.\n // Fast parse: split declarations by ';' and match \"--*-color:\"\n // Do this only when we actually insert (i.e., no cache hit above)\n const colorPropRegex = /^\\s*(--[a-z0-9-]+-color)\\s*:/i;\n for (const rule of rulesToInsert) {\n // Skip if no declarations\n if (!rule.declarations) continue;\n const parts = rule.declarations.split(/;+\\s*/);\n for (const part of parts) {\n if (!part) continue;\n const match = colorPropRegex.exec(part);\n if (match) {\n const propName = match[1];\n // Register @property only if not already defined for this root\n if (!this.isPropertyDefined(propName, { root })) {\n this.property(propName, {\n syntax: '<color>',\n initialValue: 'transparent',\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: () => { /* noop */ },\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 { dispose: () => { /* noop */ } };\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 * 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 // Property already exists - check if definitions match\n if (existingDef !== normalizedDef) {\n // Different definition - warn but don't replace (CSS @property can't be redefined)\n if (isDevEnv()) {\n console.warn(\n `[Tasty] @property ${cssName} was already defined with a different declaration. ` +\n `The new declaration will be ignored. ` +\n `Original: ${existingDef}, New: ${normalizedDef}`,\n );\n }\n }\n // Either exact match or warned - skip injection\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(definition.initialValue as StyleValue).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 // Auto-register companion -rgb property for color properties.\n // E.g. --white-color gets a companion --white-color-rgb with syntax: '<number>+'\n if (effectiveResult.isColor) {\n const rgbCssName = `${cssName}-rgb`;\n if (!this.isPropertyDefined(rgbCssName, { root })) {\n this.property(rgbCssName, {\n syntax: '<number>+',\n inherits: definition.inherits,\n initialValue: colorInitialValueToRgb(definition.initialValue),\n root,\n });\n }\n }\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: () => { /* noop */ },\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 info = this.sheetManager.insertKeyframes(\n registry,\n steps,\n actualName,\n root,\n );\n if (!info) {\n return {\n toString: () => '',\n dispose: () => { /* noop */ },\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":";;;;;;;;;AAgCA,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,SAA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SResult, 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
+ */
85
+ private stepsToCSS;
86
+ /**
87
+ * Insert keyframes rule
88
+ */
89
+ insertKeyframes(registry: RootRegistry, steps: KeyframesSteps, name: string, root: Document | ShadowRoot): KeyframesInfo | null;
90
+ /**
91
+ * Delete keyframes rule
92
+ */
93
+ deleteKeyframes(registry: RootRegistry, info: KeyframesInfo): void;
94
+ /**
95
+ * Schedule async cleanup check (non-stacking)
96
+ */
97
+ checkCleanupNeeded(registry: RootRegistry): void;
98
+ /**
99
+ * Perform the actual cleanup check (called asynchronously)
100
+ */
101
+ private performCleanupCheck;
102
+ /**
103
+ * Clean up resources for a root
104
+ */
105
+ cleanup(root: Document | ShadowRoot): void;
106
+ /**
107
+ * Get or create a dedicated style element for raw CSS
108
+ * Raw CSS is kept separate from tasty-managed sheets to avoid index conflicts
109
+ */
110
+ private getOrCreateRawStyleElement;
111
+ /**
112
+ * Inject raw CSS text directly without parsing
113
+ * Returns a dispose function to remove the injected CSS
114
+ */
115
+ injectRawCSS(css: string, root: Document | ShadowRoot): RawCSSResult;
116
+ /**
117
+ * Remove a raw CSS block by ID
118
+ */
119
+ private disposeRawCSS;
120
+ /**
121
+ * Get the raw CSS content for SSR
122
+ */
123
+ getRawCSSText(root: Document | ShadowRoot): string;
124
+ }
125
+ //#endregion
126
+ export { SheetManager };
127
+ //# sourceMappingURL=sheet-manager.d.ts.map