@tenphi/tasty 0.0.0-snapshot.2705ab9 → 0.0.0-snapshot.272039a

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 (372) hide show
  1. package/README.md +441 -362
  2. package/dist/babel-types-Dc5zghyE.d.ts +18 -0
  3. package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
  4. package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
  5. package/dist/chunks/build-config-D9Iq8QQm.js +60 -0
  6. package/dist/chunks/build-config-D9Iq8QQm.js.map +1 -0
  7. package/dist/chunks/collector-Cb8ah2JF.js +210 -0
  8. package/dist/chunks/collector-Cb8ah2JF.js.map +1 -0
  9. package/dist/chunks/config-engine-CMYFZYQh.js +272 -0
  10. package/dist/chunks/config-engine-CMYFZYQh.js.map +1 -0
  11. package/dist/chunks/config-file-DlZXJMj8.js +25 -0
  12. package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
  13. package/dist/chunks/css-definitions-B4aWBkH3.js +910 -0
  14. package/dist/chunks/css-definitions-B4aWBkH3.js.map +1 -0
  15. package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
  16. package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
  17. package/dist/{debug.js → chunks/debug-D2Pu7Xhy.js} +197 -149
  18. package/dist/chunks/debug-D2Pu7Xhy.js.map +1 -0
  19. package/dist/chunks/dsl-CsFl9LGn.js +1458 -0
  20. package/dist/chunks/dsl-CsFl9LGn.js.map +1 -0
  21. package/dist/chunks/hydration-TRcz5vnk.js +41 -0
  22. package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
  23. package/dist/chunks/react-runtime-DHiopXCu.js +691 -0
  24. package/dist/chunks/react-runtime-DHiopXCu.js.map +1 -0
  25. package/dist/chunks/runtime-engine-NGCofNXy.js +2435 -0
  26. package/dist/chunks/runtime-engine-NGCofNXy.js.map +1 -0
  27. package/dist/chunks/runtime-state-lZjMbvwV.js +152 -0
  28. package/dist/chunks/runtime-state-lZjMbvwV.js.map +1 -0
  29. package/dist/{utils/merge-styles.js → chunks/shared-utils-y-HjvPN4.js} +61 -58
  30. package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
  31. package/dist/chunks/style-engine-DnkV_4Jg.js +5602 -0
  32. package/dist/chunks/style-engine-DnkV_4Jg.js.map +1 -0
  33. package/dist/chunks/zero-engine-DcwaCvFs.js +310 -0
  34. package/dist/chunks/zero-engine-DcwaCvFs.js.map +1 -0
  35. package/dist/collector-D2OT6I2G.d.ts +164 -0
  36. package/dist/config-C4ftFxgI.d.ts +1367 -0
  37. package/dist/core/index.d.ts +5 -34
  38. package/dist/core/index.js +9 -27
  39. package/dist/hydrate-CRyjjAyl.d.ts +22 -0
  40. package/dist/index-DxQNRj50.d.ts +1964 -0
  41. package/dist/index.d.ts +5 -51
  42. package/dist/index.js +11 -36
  43. package/dist/{utils/merge-styles.d.ts → merge-styles-D39qBtox.d.ts} +3 -4
  44. package/dist/ssr/astro-client.d.ts +1 -0
  45. package/dist/ssr/astro-client.js +6 -0
  46. package/dist/ssr/astro-client.js.map +1 -0
  47. package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
  48. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  49. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  50. package/dist/ssr/astro-middleware-extract.d.ts +10 -0
  51. package/dist/ssr/astro-middleware-extract.js +9 -0
  52. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  53. package/dist/ssr/astro-middleware-static.d.ts +17 -0
  54. package/dist/ssr/astro-middleware-static.js +7 -0
  55. package/dist/ssr/astro-middleware-static.js.map +1 -0
  56. package/dist/ssr/astro-middleware.d.ts +18 -0
  57. package/dist/ssr/astro-middleware.js +7 -0
  58. package/dist/ssr/astro-middleware.js.map +1 -0
  59. package/dist/ssr/astro.d.ts +110 -12
  60. package/dist/ssr/astro.js +206 -50
  61. package/dist/ssr/astro.js.map +1 -1
  62. package/dist/ssr/client.d.ts +2 -0
  63. package/dist/ssr/client.js +2 -0
  64. package/dist/ssr/index.d.ts +17 -5
  65. package/dist/ssr/index.js +7 -9
  66. package/dist/ssr/index.js.map +1 -1
  67. package/dist/ssr/next-config.d.ts +64 -0
  68. package/dist/ssr/next-config.js +123 -0
  69. package/dist/ssr/next-config.js.map +1 -0
  70. package/dist/ssr/next.d.ts +13 -12
  71. package/dist/ssr/next.js +40 -51
  72. package/dist/ssr/next.js.map +1 -1
  73. package/dist/static/index.d.ts +90 -5
  74. package/dist/static/index.js +31 -4
  75. package/dist/static/index.js.map +1 -0
  76. package/dist/static/inject.d.ts +4 -0
  77. package/dist/static/inject.js +17 -0
  78. package/dist/static/inject.js.map +1 -0
  79. package/dist/types-CYQIhUg1.d.ts +1569 -0
  80. package/dist/zero/babel.d.ts +27 -121
  81. package/dist/zero/babel.js +192 -151
  82. package/dist/zero/babel.js.map +1 -1
  83. package/dist/zero/index.d.ts +136 -3
  84. package/dist/zero/index.js +24 -3
  85. package/dist/zero/index.js.map +1 -0
  86. package/dist/zero/next.d.ts +16 -5
  87. package/dist/zero/next.js +8 -42
  88. package/dist/zero/next.js.map +1 -1
  89. package/docs/README.md +23 -12
  90. package/docs/adoption.md +72 -37
  91. package/docs/ai-agents.md +259 -0
  92. package/docs/comparison.md +83 -54
  93. package/docs/configuration.md +712 -81
  94. package/docs/debug.md +39 -24
  95. package/docs/design-system.md +174 -41
  96. package/docs/dsl.md +733 -195
  97. package/docs/getting-started.md +132 -52
  98. package/docs/injector.md +197 -90
  99. package/docs/methodology.md +154 -48
  100. package/docs/migration-v3.md +285 -0
  101. package/docs/pipeline.md +768 -0
  102. package/docs/plugins.md +333 -0
  103. package/docs/react-api.md +746 -0
  104. package/docs/runtime-benchmarks.md +388 -0
  105. package/docs/ssr.md +403 -151
  106. package/docs/styles.md +251 -49
  107. package/docs/tasty-static.md +368 -101
  108. package/package.json +157 -40
  109. package/tasty.config.ts +7 -0
  110. package/dist/_virtual/_rolldown/runtime.js +0 -8
  111. package/dist/chunks/cacheKey.js +0 -78
  112. package/dist/chunks/cacheKey.js.map +0 -1
  113. package/dist/chunks/definitions.d.ts +0 -37
  114. package/dist/chunks/definitions.js +0 -259
  115. package/dist/chunks/definitions.js.map +0 -1
  116. package/dist/chunks/renderChunk.js +0 -60
  117. package/dist/chunks/renderChunk.js.map +0 -1
  118. package/dist/config.d.ts +0 -366
  119. package/dist/config.js +0 -504
  120. package/dist/config.js.map +0 -1
  121. package/dist/counter-style/index.js +0 -51
  122. package/dist/counter-style/index.js.map +0 -1
  123. package/dist/debug.d.ts +0 -89
  124. package/dist/debug.js.map +0 -1
  125. package/dist/font-face/index.js +0 -63
  126. package/dist/font-face/index.js.map +0 -1
  127. package/dist/hooks/resolve-ssr-collector.js +0 -15
  128. package/dist/hooks/resolve-ssr-collector.js.map +0 -1
  129. package/dist/hooks/useCounterStyle.d.ts +0 -50
  130. package/dist/hooks/useCounterStyle.js +0 -47
  131. package/dist/hooks/useCounterStyle.js.map +0 -1
  132. package/dist/hooks/useFontFace.d.ts +0 -43
  133. package/dist/hooks/useFontFace.js +0 -71
  134. package/dist/hooks/useFontFace.js.map +0 -1
  135. package/dist/hooks/useGlobalStyles.d.ts +0 -30
  136. package/dist/hooks/useGlobalStyles.js +0 -79
  137. package/dist/hooks/useGlobalStyles.js.map +0 -1
  138. package/dist/hooks/useKeyframes.d.ts +0 -56
  139. package/dist/hooks/useKeyframes.js +0 -65
  140. package/dist/hooks/useKeyframes.js.map +0 -1
  141. package/dist/hooks/useProperty.d.ts +0 -79
  142. package/dist/hooks/useProperty.js +0 -110
  143. package/dist/hooks/useProperty.js.map +0 -1
  144. package/dist/hooks/useRawCSS.d.ts +0 -53
  145. package/dist/hooks/useRawCSS.js +0 -36
  146. package/dist/hooks/useRawCSS.js.map +0 -1
  147. package/dist/hooks/useStyles.d.ts +0 -45
  148. package/dist/hooks/useStyles.js +0 -238
  149. package/dist/hooks/useStyles.js.map +0 -1
  150. package/dist/injector/index.d.ts +0 -183
  151. package/dist/injector/index.js +0 -180
  152. package/dist/injector/index.js.map +0 -1
  153. package/dist/injector/injector.d.ts +0 -166
  154. package/dist/injector/injector.js +0 -465
  155. package/dist/injector/injector.js.map +0 -1
  156. package/dist/injector/sheet-manager.d.ts +0 -136
  157. package/dist/injector/sheet-manager.js +0 -734
  158. package/dist/injector/sheet-manager.js.map +0 -1
  159. package/dist/injector/types.d.ts +0 -204
  160. package/dist/keyframes/index.js +0 -206
  161. package/dist/keyframes/index.js.map +0 -1
  162. package/dist/parser/classify.js +0 -320
  163. package/dist/parser/classify.js.map +0 -1
  164. package/dist/parser/const.js +0 -49
  165. package/dist/parser/const.js.map +0 -1
  166. package/dist/parser/lru.js +0 -109
  167. package/dist/parser/lru.js.map +0 -1
  168. package/dist/parser/parser.d.ts +0 -25
  169. package/dist/parser/parser.js +0 -116
  170. package/dist/parser/parser.js.map +0 -1
  171. package/dist/parser/tokenizer.js +0 -69
  172. package/dist/parser/tokenizer.js.map +0 -1
  173. package/dist/parser/types.d.ts +0 -51
  174. package/dist/parser/types.js +0 -46
  175. package/dist/parser/types.js.map +0 -1
  176. package/dist/pipeline/conditions.d.ts +0 -134
  177. package/dist/pipeline/conditions.js +0 -406
  178. package/dist/pipeline/conditions.js.map +0 -1
  179. package/dist/pipeline/exclusive.js +0 -231
  180. package/dist/pipeline/exclusive.js.map +0 -1
  181. package/dist/pipeline/index.d.ts +0 -55
  182. package/dist/pipeline/index.js +0 -709
  183. package/dist/pipeline/index.js.map +0 -1
  184. package/dist/pipeline/materialize.js +0 -1104
  185. package/dist/pipeline/materialize.js.map +0 -1
  186. package/dist/pipeline/parseStateKey.d.ts +0 -15
  187. package/dist/pipeline/parseStateKey.js +0 -447
  188. package/dist/pipeline/parseStateKey.js.map +0 -1
  189. package/dist/pipeline/simplify.js +0 -516
  190. package/dist/pipeline/simplify.js.map +0 -1
  191. package/dist/pipeline/warnings.js +0 -18
  192. package/dist/pipeline/warnings.js.map +0 -1
  193. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  194. package/dist/plugins/okhsl-plugin.js +0 -98
  195. package/dist/plugins/okhsl-plugin.js.map +0 -1
  196. package/dist/plugins/types.d.ts +0 -76
  197. package/dist/properties/index.js +0 -223
  198. package/dist/properties/index.js.map +0 -1
  199. package/dist/properties/property-type-resolver.d.ts +0 -24
  200. package/dist/properties/property-type-resolver.js +0 -91
  201. package/dist/properties/property-type-resolver.js.map +0 -1
  202. package/dist/ssr/async-storage.d.ts +0 -17
  203. package/dist/ssr/async-storage.js +0 -35
  204. package/dist/ssr/async-storage.js.map +0 -1
  205. package/dist/ssr/collect-auto-properties.js +0 -40
  206. package/dist/ssr/collect-auto-properties.js.map +0 -1
  207. package/dist/ssr/collector.d.ts +0 -102
  208. package/dist/ssr/collector.js +0 -227
  209. package/dist/ssr/collector.js.map +0 -1
  210. package/dist/ssr/context.d.ts +0 -8
  211. package/dist/ssr/context.js +0 -14
  212. package/dist/ssr/context.js.map +0 -1
  213. package/dist/ssr/format-global-rules.js +0 -22
  214. package/dist/ssr/format-global-rules.js.map +0 -1
  215. package/dist/ssr/format-keyframes.js +0 -70
  216. package/dist/ssr/format-keyframes.js.map +0 -1
  217. package/dist/ssr/format-property.js +0 -50
  218. package/dist/ssr/format-property.js.map +0 -1
  219. package/dist/ssr/format-rules.js +0 -73
  220. package/dist/ssr/format-rules.js.map +0 -1
  221. package/dist/ssr/hydrate.d.ts +0 -22
  222. package/dist/ssr/hydrate.js +0 -50
  223. package/dist/ssr/hydrate.js.map +0 -1
  224. package/dist/ssr/ssr-collector-ref.js +0 -12
  225. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  226. package/dist/states/index.d.ts +0 -49
  227. package/dist/states/index.js +0 -171
  228. package/dist/states/index.js.map +0 -1
  229. package/dist/static/tastyStatic.d.ts +0 -46
  230. package/dist/static/tastyStatic.js +0 -31
  231. package/dist/static/tastyStatic.js.map +0 -1
  232. package/dist/static/types.d.ts +0 -49
  233. package/dist/static/types.js +0 -24
  234. package/dist/static/types.js.map +0 -1
  235. package/dist/styles/align.d.ts +0 -15
  236. package/dist/styles/align.js +0 -14
  237. package/dist/styles/align.js.map +0 -1
  238. package/dist/styles/border.d.ts +0 -25
  239. package/dist/styles/border.js +0 -114
  240. package/dist/styles/border.js.map +0 -1
  241. package/dist/styles/color.d.ts +0 -14
  242. package/dist/styles/color.js +0 -27
  243. package/dist/styles/color.js.map +0 -1
  244. package/dist/styles/createStyle.js +0 -80
  245. package/dist/styles/createStyle.js.map +0 -1
  246. package/dist/styles/dimension.js +0 -97
  247. package/dist/styles/dimension.js.map +0 -1
  248. package/dist/styles/display.d.ts +0 -37
  249. package/dist/styles/display.js +0 -67
  250. package/dist/styles/display.js.map +0 -1
  251. package/dist/styles/fade.d.ts +0 -15
  252. package/dist/styles/fade.js +0 -58
  253. package/dist/styles/fade.js.map +0 -1
  254. package/dist/styles/fill.d.ts +0 -42
  255. package/dist/styles/fill.js +0 -52
  256. package/dist/styles/fill.js.map +0 -1
  257. package/dist/styles/flow.d.ts +0 -16
  258. package/dist/styles/flow.js +0 -12
  259. package/dist/styles/flow.js.map +0 -1
  260. package/dist/styles/gap.d.ts +0 -31
  261. package/dist/styles/gap.js +0 -37
  262. package/dist/styles/gap.js.map +0 -1
  263. package/dist/styles/height.d.ts +0 -17
  264. package/dist/styles/height.js +0 -20
  265. package/dist/styles/height.js.map +0 -1
  266. package/dist/styles/index.d.ts +0 -2
  267. package/dist/styles/index.js +0 -9
  268. package/dist/styles/index.js.map +0 -1
  269. package/dist/styles/inset.d.ts +0 -52
  270. package/dist/styles/inset.js +0 -150
  271. package/dist/styles/inset.js.map +0 -1
  272. package/dist/styles/justify.d.ts +0 -15
  273. package/dist/styles/justify.js +0 -14
  274. package/dist/styles/justify.js.map +0 -1
  275. package/dist/styles/list.d.ts +0 -16
  276. package/dist/styles/list.js +0 -98
  277. package/dist/styles/list.js.map +0 -1
  278. package/dist/styles/margin.d.ts +0 -24
  279. package/dist/styles/margin.js +0 -104
  280. package/dist/styles/margin.js.map +0 -1
  281. package/dist/styles/outline.d.ts +0 -29
  282. package/dist/styles/outline.js +0 -65
  283. package/dist/styles/outline.js.map +0 -1
  284. package/dist/styles/padding.d.ts +0 -24
  285. package/dist/styles/padding.js +0 -104
  286. package/dist/styles/padding.js.map +0 -1
  287. package/dist/styles/predefined.d.ts +0 -71
  288. package/dist/styles/predefined.js +0 -238
  289. package/dist/styles/predefined.js.map +0 -1
  290. package/dist/styles/preset.d.ts +0 -52
  291. package/dist/styles/preset.js +0 -127
  292. package/dist/styles/preset.js.map +0 -1
  293. package/dist/styles/radius.d.ts +0 -14
  294. package/dist/styles/radius.js +0 -51
  295. package/dist/styles/radius.js.map +0 -1
  296. package/dist/styles/scrollbar.d.ts +0 -25
  297. package/dist/styles/scrollbar.js +0 -48
  298. package/dist/styles/scrollbar.js.map +0 -1
  299. package/dist/styles/shadow.d.ts +0 -14
  300. package/dist/styles/shadow.js +0 -24
  301. package/dist/styles/shadow.js.map +0 -1
  302. package/dist/styles/transition.d.ts +0 -14
  303. package/dist/styles/transition.js +0 -158
  304. package/dist/styles/transition.js.map +0 -1
  305. package/dist/styles/types.d.ts +0 -547
  306. package/dist/styles/width.d.ts +0 -17
  307. package/dist/styles/width.js +0 -20
  308. package/dist/styles/width.js.map +0 -1
  309. package/dist/tasty.d.ts +0 -119
  310. package/dist/tasty.js +0 -232
  311. package/dist/tasty.js.map +0 -1
  312. package/dist/types.d.ts +0 -184
  313. package/dist/utils/cache-wrapper.js +0 -22
  314. package/dist/utils/cache-wrapper.js.map +0 -1
  315. package/dist/utils/case-converter.js +0 -8
  316. package/dist/utils/case-converter.js.map +0 -1
  317. package/dist/utils/color-math.d.ts +0 -46
  318. package/dist/utils/color-math.js +0 -749
  319. package/dist/utils/color-math.js.map +0 -1
  320. package/dist/utils/color-space.d.ts +0 -5
  321. package/dist/utils/color-space.js +0 -229
  322. package/dist/utils/color-space.js.map +0 -1
  323. package/dist/utils/colors.d.ts +0 -5
  324. package/dist/utils/colors.js +0 -11
  325. package/dist/utils/colors.js.map +0 -1
  326. package/dist/utils/css-types.d.ts +0 -7
  327. package/dist/utils/dotize.d.ts +0 -26
  328. package/dist/utils/dotize.js +0 -122
  329. package/dist/utils/dotize.js.map +0 -1
  330. package/dist/utils/filter-base-props.d.ts +0 -15
  331. package/dist/utils/filter-base-props.js +0 -45
  332. package/dist/utils/filter-base-props.js.map +0 -1
  333. package/dist/utils/get-display-name.d.ts +0 -7
  334. package/dist/utils/get-display-name.js +0 -10
  335. package/dist/utils/get-display-name.js.map +0 -1
  336. package/dist/utils/has-keys.js +0 -13
  337. package/dist/utils/has-keys.js.map +0 -1
  338. package/dist/utils/is-dev-env.js +0 -19
  339. package/dist/utils/is-dev-env.js.map +0 -1
  340. package/dist/utils/is-valid-element-type.js +0 -15
  341. package/dist/utils/is-valid-element-type.js.map +0 -1
  342. package/dist/utils/merge-styles.js.map +0 -1
  343. package/dist/utils/mod-attrs.d.ts +0 -8
  344. package/dist/utils/mod-attrs.js +0 -21
  345. package/dist/utils/mod-attrs.js.map +0 -1
  346. package/dist/utils/process-tokens.d.ts +0 -21
  347. package/dist/utils/process-tokens.js +0 -91
  348. package/dist/utils/process-tokens.js.map +0 -1
  349. package/dist/utils/resolve-recipes.d.ts +0 -17
  350. package/dist/utils/resolve-recipes.js +0 -147
  351. package/dist/utils/resolve-recipes.js.map +0 -1
  352. package/dist/utils/selector-transform.js +0 -32
  353. package/dist/utils/selector-transform.js.map +0 -1
  354. package/dist/utils/string.js +0 -8
  355. package/dist/utils/string.js.map +0 -1
  356. package/dist/utils/styles.d.ts +0 -99
  357. package/dist/utils/styles.js +0 -221
  358. package/dist/utils/styles.js.map +0 -1
  359. package/dist/utils/typography.d.ts +0 -47
  360. package/dist/utils/typography.js +0 -51
  361. package/dist/utils/typography.js.map +0 -1
  362. package/dist/utils/warnings.d.ts +0 -16
  363. package/dist/utils/warnings.js +0 -16
  364. package/dist/utils/warnings.js.map +0 -1
  365. package/dist/zero/css-writer.d.ts +0 -45
  366. package/dist/zero/css-writer.js +0 -74
  367. package/dist/zero/css-writer.js.map +0 -1
  368. package/dist/zero/extractor.d.ts +0 -24
  369. package/dist/zero/extractor.js +0 -267
  370. package/dist/zero/extractor.js.map +0 -1
  371. package/docs/PIPELINE.md +0 -519
  372. package/docs/runtime.md +0 -485
@@ -1,734 +0,0 @@
1
- import { PropertyTypeResolver } from "../properties/property-type-resolver.js";
2
- import { createStyle } from "../styles/createStyle.js";
3
- import { STYLE_HANDLER_MAP } from "../styles/index.js";
4
-
5
- //#region src/injector/sheet-manager.ts
6
- var SheetManager = class {
7
- rootRegistries = /* @__PURE__ */ new WeakMap();
8
- config;
9
- /** Dedicated style elements for raw CSS per root */
10
- rawStyleElements = /* @__PURE__ */ new WeakMap();
11
- /** Tracking for raw CSS blocks per root */
12
- rawCSSBlocks = /* @__PURE__ */ new WeakMap();
13
- /** Counter for generating unique raw CSS IDs */
14
- rawCSSCounter = 0;
15
- constructor(config) {
16
- this.config = config;
17
- }
18
- /**
19
- * Get or create registry for a root (Document or ShadowRoot)
20
- */
21
- getRegistry(root) {
22
- let registry = this.rootRegistries.get(root);
23
- if (!registry) {
24
- const metrics = this.config.devMode ? {
25
- hits: 0,
26
- misses: 0,
27
- bulkCleanups: 0,
28
- totalInsertions: 0,
29
- totalUnused: 0,
30
- stylesCleanedUp: 0,
31
- cleanupHistory: [],
32
- startTime: Date.now()
33
- } : void 0;
34
- registry = {
35
- sheets: [],
36
- refCounts: /* @__PURE__ */ new Map(),
37
- rules: /* @__PURE__ */ new Map(),
38
- cacheKeyToClassName: /* @__PURE__ */ new Map(),
39
- ruleTextSet: /* @__PURE__ */ new Set(),
40
- bulkCleanupTimeout: null,
41
- cleanupCheckTimeout: null,
42
- metrics,
43
- classCounter: 0,
44
- keyframesCache: /* @__PURE__ */ new Map(),
45
- keyframesNameToContent: /* @__PURE__ */ new Map(),
46
- keyframesCounter: 0,
47
- injectedProperties: /* @__PURE__ */ new Map(),
48
- injectedFontFaces: /* @__PURE__ */ new Set(),
49
- injectedCounterStyles: /* @__PURE__ */ new Set(),
50
- globalRules: /* @__PURE__ */ new Map(),
51
- propertyTypeResolver: new PropertyTypeResolver()
52
- };
53
- this.rootRegistries.set(root, registry);
54
- }
55
- return registry;
56
- }
57
- /**
58
- * Create a new stylesheet for the registry
59
- */
60
- createSheet(registry, root) {
61
- const sheetInfo = {
62
- sheet: this.createStyleElement(root),
63
- ruleCount: 0,
64
- holes: []
65
- };
66
- registry.sheets.push(sheetInfo);
67
- return sheetInfo;
68
- }
69
- /**
70
- * Create a style element and append to document
71
- */
72
- createStyleElement(root) {
73
- const style = root.createElement?.("style") || document.createElement("style");
74
- if (this.config.nonce) style.nonce = this.config.nonce;
75
- style.setAttribute("data-tasty", "");
76
- if ("head" in root && root.head) root.head.appendChild(style);
77
- else if ("appendChild" in root) root.appendChild(style);
78
- else document.head.appendChild(style);
79
- if (!style.isConnected && !this.config.forceTextInjection) console.error("SheetManager: Style element failed to connect to DOM!", {
80
- parentNode: style.parentNode?.nodeName,
81
- isConnected: style.isConnected
82
- });
83
- return style;
84
- }
85
- /**
86
- * Insert CSS rules as a single block
87
- */
88
- insertRule(registry, flattenedRules, className, root) {
89
- let targetSheet = this.findAvailableSheet(registry, root);
90
- if (!targetSheet) targetSheet = this.createSheet(registry, root);
91
- const sheetIndex = registry.sheets.indexOf(targetSheet);
92
- try {
93
- const groupedRules = [];
94
- const groupMap = /* @__PURE__ */ new Map();
95
- const atKey = (at) => at && at.length ? at.join("|") : "";
96
- flattenedRules.forEach((r) => {
97
- const key = `${atKey(r.atRules)}||${r.selector}||${r.startingStyle ? "1" : "0"}`;
98
- const existing = groupMap.get(key);
99
- if (existing) existing.declarations = existing.declarations ? `${existing.declarations} ${r.declarations}` : r.declarations;
100
- else {
101
- groupMap.set(key, {
102
- idx: groupedRules.length,
103
- selector: r.selector,
104
- atRules: r.atRules,
105
- startingStyle: r.startingStyle,
106
- declarations: r.declarations
107
- });
108
- groupedRules.push({ ...r });
109
- }
110
- });
111
- groupMap.forEach((val) => {
112
- groupedRules[val.idx] = {
113
- selector: val.selector,
114
- atRules: val.atRules,
115
- startingStyle: val.startingStyle,
116
- declarations: val.declarations
117
- };
118
- });
119
- const insertedRuleTexts = [];
120
- const insertedIndices = [];
121
- let currentRuleIndex = this.findAvailableRuleIndex(targetSheet);
122
- let firstInsertedIndex = null;
123
- let lastInsertedIndex = null;
124
- for (const rule of groupedRules) {
125
- const declarations = rule.declarations;
126
- const innerContent = rule.startingStyle ? `@starting-style { ${declarations} }` : declarations;
127
- const baseRule = `${rule.selector} { ${innerContent} }`;
128
- let fullRule = baseRule;
129
- if (rule.atRules && rule.atRules.length > 0) fullRule = rule.atRules.reduce((css, atRule) => `${atRule} { ${css} }`, baseRule);
130
- const styleElement = targetSheet.sheet;
131
- const styleSheet = styleElement.sheet;
132
- if (styleSheet && !this.config.forceTextInjection) {
133
- const maxIndex = styleSheet.cssRules.length;
134
- const atomicRuleIndex = this.findAvailableRuleIndex(targetSheet);
135
- const safeIndex = Math.min(Math.max(0, atomicRuleIndex), maxIndex);
136
- const splitSelectorsSafely = (selectorList) => {
137
- const parts = [];
138
- let buf = "";
139
- let depthSq = 0;
140
- let depthPar = 0;
141
- let inStr = "";
142
- for (let i = 0; i < selectorList.length; i++) {
143
- const ch = selectorList[i];
144
- if (inStr) {
145
- if (ch === inStr && selectorList[i - 1] !== "\\") inStr = "";
146
- buf += ch;
147
- continue;
148
- }
149
- if (ch === "\"" || ch === "'") {
150
- inStr = ch;
151
- buf += ch;
152
- continue;
153
- }
154
- if (ch === "[") depthSq++;
155
- else if (ch === "]") depthSq = Math.max(0, depthSq - 1);
156
- else if (ch === "(") depthPar++;
157
- else if (ch === ")") depthPar = Math.max(0, depthPar - 1);
158
- if (ch === "," && depthSq === 0 && depthPar === 0) {
159
- const part = buf.trim();
160
- if (part) parts.push(part);
161
- buf = "";
162
- } else buf += ch;
163
- }
164
- const tail = buf.trim();
165
- if (tail) parts.push(tail);
166
- return parts;
167
- };
168
- try {
169
- styleSheet.insertRule(fullRule, safeIndex);
170
- targetSheet.ruleCount++;
171
- insertedIndices.push(safeIndex);
172
- if (firstInsertedIndex == null) firstInsertedIndex = safeIndex;
173
- lastInsertedIndex = safeIndex;
174
- currentRuleIndex = safeIndex + 1;
175
- } catch (e) {
176
- const selectors = splitSelectorsSafely(rule.selector);
177
- if (selectors.length > 1) {
178
- let anyInserted = false;
179
- for (const sel of selectors) {
180
- const singleBase = `${sel} { ${declarations} }`;
181
- let singleRule = singleBase;
182
- if (rule.atRules && rule.atRules.length > 0) singleRule = rule.atRules.reduce((css, atRule) => `${atRule} { ${css} }`, singleBase);
183
- try {
184
- const maxIdx = styleSheet.cssRules.length;
185
- const atomicIdx = this.findAvailableRuleIndex(targetSheet);
186
- const idx = Math.min(Math.max(0, atomicIdx), maxIdx);
187
- styleSheet.insertRule(singleRule, idx);
188
- targetSheet.ruleCount++;
189
- insertedIndices.push(idx);
190
- if (firstInsertedIndex == null) firstInsertedIndex = idx;
191
- lastInsertedIndex = idx;
192
- currentRuleIndex = idx + 1;
193
- anyInserted = true;
194
- } catch (singleErr) {
195
- console.warn("[tasty] Browser rejected CSS rule:", singleRule, singleErr);
196
- }
197
- }
198
- if (!anyInserted) {}
199
- } else console.warn("[tasty] Browser rejected CSS rule:", fullRule, e);
200
- }
201
- } else {
202
- const atomicRuleIndex = this.findAvailableRuleIndex(targetSheet);
203
- styleElement.textContent = (styleElement.textContent || "") + "\n" + fullRule;
204
- targetSheet.ruleCount++;
205
- insertedIndices.push(atomicRuleIndex);
206
- if (firstInsertedIndex == null) firstInsertedIndex = atomicRuleIndex;
207
- lastInsertedIndex = atomicRuleIndex;
208
- currentRuleIndex = atomicRuleIndex + 1;
209
- }
210
- if (!styleElement.parentNode && !this.config.forceTextInjection) console.error("SheetManager: Style element is NOT in DOM! This is the problem!", {
211
- className,
212
- ruleIndex: currentRuleIndex
213
- });
214
- if (this.config.devMode) {
215
- insertedRuleTexts.push(fullRule);
216
- try {
217
- registry.ruleTextSet.add(fullRule);
218
- } catch {}
219
- }
220
- }
221
- if (insertedIndices.length === 0) return null;
222
- return {
223
- className,
224
- ruleIndex: firstInsertedIndex ?? 0,
225
- sheetIndex,
226
- cssText: this.config.devMode ? insertedRuleTexts : void 0,
227
- endRuleIndex: lastInsertedIndex ?? firstInsertedIndex ?? 0,
228
- indices: insertedIndices
229
- };
230
- } catch (error) {
231
- console.warn("Failed to insert CSS rules:", error, {
232
- flattenedRules,
233
- className
234
- });
235
- return null;
236
- }
237
- }
238
- /**
239
- * Insert global CSS rules
240
- */
241
- insertGlobalRule(registry, flattenedRules, globalKey, root) {
242
- const ruleInfo = this.insertRule(registry, flattenedRules, globalKey, root);
243
- if (ruleInfo) registry.globalRules.set(globalKey, ruleInfo);
244
- return ruleInfo;
245
- }
246
- /**
247
- * Delete a global CSS rule by key
248
- */
249
- deleteGlobalRule(registry, globalKey) {
250
- const ruleInfo = registry.globalRules.get(globalKey);
251
- if (!ruleInfo) return;
252
- this.deleteRule(registry, ruleInfo);
253
- registry.globalRules.delete(globalKey);
254
- }
255
- /**
256
- * Adjust rule indices after deletion to account for shifting
257
- */
258
- adjustIndicesAfterDeletion(registry, sheetIndex, startIdx, endIdx, deleteCount, deletedRuleInfo, deletedIndices) {
259
- try {
260
- const sortedDeleted = deletedIndices && deletedIndices.length > 0 ? [...deletedIndices].sort((a, b) => a - b) : null;
261
- const countDeletedBefore = (sorted, idx) => {
262
- let shift = 0;
263
- for (const delIdx of sorted) if (delIdx < idx) shift++;
264
- else break;
265
- return shift;
266
- };
267
- const adjustRuleInfo = (info) => {
268
- if (info === deletedRuleInfo) return;
269
- if (info.sheetIndex !== sheetIndex) return;
270
- if (!info.indices || info.indices.length === 0) return;
271
- if (sortedDeleted) info.indices = info.indices.map((idx) => {
272
- return idx - countDeletedBefore(sortedDeleted, idx);
273
- });
274
- else info.indices = info.indices.map((idx) => idx > endIdx ? Math.max(0, idx - deleteCount) : idx);
275
- if (info.indices.length > 0) {
276
- info.ruleIndex = Math.min(...info.indices);
277
- info.endRuleIndex = Math.max(...info.indices);
278
- }
279
- };
280
- for (const info of registry.rules.values()) adjustRuleInfo(info);
281
- for (const info of registry.globalRules.values()) adjustRuleInfo(info);
282
- for (const entry of registry.keyframesCache.values()) {
283
- const ki = entry.info;
284
- if (ki.sheetIndex !== sheetIndex) continue;
285
- if (sortedDeleted) {
286
- const shift = countDeletedBefore(sortedDeleted, ki.ruleIndex);
287
- if (shift > 0) ki.ruleIndex = Math.max(0, ki.ruleIndex - shift);
288
- } else if (ki.ruleIndex > endIdx) ki.ruleIndex = Math.max(0, ki.ruleIndex - deleteCount);
289
- }
290
- } catch {}
291
- }
292
- /**
293
- * Delete a CSS rule from the sheet
294
- */
295
- deleteRule(registry, ruleInfo) {
296
- const sheet = registry.sheets[ruleInfo.sheetIndex];
297
- if (!sheet) return;
298
- try {
299
- const texts = this.config.devMode && Array.isArray(ruleInfo.cssText) ? ruleInfo.cssText.slice() : [];
300
- const styleSheet = sheet.sheet.sheet;
301
- if (styleSheet) {
302
- const rules = styleSheet.cssRules;
303
- if (ruleInfo.indices && ruleInfo.indices.length > 0) {
304
- const sortedIndices = [...ruleInfo.indices].sort((a, b) => b - a);
305
- const deletedIndices = [];
306
- for (const idx of sortedIndices) if (idx >= 0 && idx < styleSheet.cssRules.length) try {
307
- styleSheet.deleteRule(idx);
308
- deletedIndices.push(idx);
309
- } catch (e) {
310
- console.warn(`Failed to delete rule at index ${idx}:`, e);
311
- }
312
- sheet.ruleCount = Math.max(0, sheet.ruleCount - deletedIndices.length);
313
- if (deletedIndices.length > 0) this.adjustIndicesAfterDeletion(registry, ruleInfo.sheetIndex, Math.min(...deletedIndices), Math.max(...deletedIndices), deletedIndices.length, ruleInfo, deletedIndices);
314
- } else {
315
- const startIdx = Math.max(0, ruleInfo.ruleIndex);
316
- const endIdx = Math.min(rules.length - 1, Number.isFinite(ruleInfo.endRuleIndex) ? ruleInfo.endRuleIndex : startIdx);
317
- if (Number.isFinite(startIdx) && endIdx >= startIdx) {
318
- const deleteCount = endIdx - startIdx + 1;
319
- for (let idx = endIdx; idx >= startIdx; idx--) {
320
- if (idx < 0 || idx >= styleSheet.cssRules.length) continue;
321
- styleSheet.deleteRule(idx);
322
- }
323
- sheet.ruleCount = Math.max(0, sheet.ruleCount - deleteCount);
324
- this.adjustIndicesAfterDeletion(registry, ruleInfo.sheetIndex, startIdx, endIdx, deleteCount, ruleInfo);
325
- }
326
- }
327
- }
328
- if (this.config.devMode && texts.length) try {
329
- for (const text of texts) registry.ruleTextSet.delete(text);
330
- } catch {}
331
- } catch (error) {
332
- console.warn("Failed to delete CSS rule:", error);
333
- }
334
- }
335
- /**
336
- * Find a sheet with available space or return null
337
- */
338
- findAvailableSheet(registry, _root) {
339
- const maxRules = this.config.maxRulesPerSheet;
340
- if (!maxRules) return registry.sheets[registry.sheets.length - 1] || null;
341
- for (const sheet of registry.sheets) if (sheet.ruleCount < maxRules) return sheet;
342
- return null;
343
- }
344
- /**
345
- * Find an available rule index in the sheet
346
- */
347
- findAvailableRuleIndex(sheet) {
348
- return sheet.ruleCount;
349
- }
350
- /**
351
- * Schedule bulk cleanup of all unused styles (non-stacking)
352
- */
353
- scheduleBulkCleanup(registry) {
354
- if (registry.bulkCleanupTimeout) {
355
- if (this.config.idleCleanup && typeof cancelIdleCallback !== "undefined") cancelIdleCallback(registry.bulkCleanupTimeout);
356
- else clearTimeout(registry.bulkCleanupTimeout);
357
- registry.bulkCleanupTimeout = null;
358
- }
359
- const performCleanup = () => {
360
- this.performBulkCleanup(registry);
361
- registry.bulkCleanupTimeout = null;
362
- };
363
- if (this.config.idleCleanup && typeof requestIdleCallback !== "undefined") registry.bulkCleanupTimeout = requestIdleCallback(performCleanup);
364
- else {
365
- const delay = this.config.bulkCleanupDelay || 5e3;
366
- registry.bulkCleanupTimeout = setTimeout(performCleanup, delay);
367
- }
368
- }
369
- /**
370
- * Force cleanup of unused styles
371
- */
372
- forceCleanup(registry) {
373
- this.performBulkCleanup(registry, true);
374
- }
375
- /**
376
- * Perform bulk cleanup of all unused styles
377
- */
378
- performBulkCleanup(registry, cleanupAll = false) {
379
- const cleanupStartTime = Date.now();
380
- const unusedClassNames = Array.from(registry.refCounts.entries()).filter(([, refCount]) => refCount === 0).map(([className]) => className);
381
- if (unusedClassNames.length === 0) return;
382
- const candidates = unusedClassNames.map((className) => {
383
- return {
384
- className,
385
- ruleInfo: registry.rules.get(className)
386
- };
387
- });
388
- if (candidates.length === 0) return;
389
- let selected = candidates;
390
- if (!cleanupAll) {
391
- const ratio = this.config.bulkCleanupBatchRatio ?? .5;
392
- const limit = Math.max(1, Math.floor(candidates.length * Math.min(1, Math.max(0, ratio))));
393
- selected = candidates.slice(0, limit);
394
- }
395
- let cleanedUpCount = 0;
396
- let totalCssSize = 0;
397
- let totalRulesDeleted = 0;
398
- const rulesBySheet = /* @__PURE__ */ new Map();
399
- for (const { className, ruleInfo } of selected) {
400
- const sheetIndex = ruleInfo.sheetIndex;
401
- if (this.config.devMode && Array.isArray(ruleInfo.cssText)) {
402
- const cssSize = ruleInfo.cssText.reduce((total, css) => total + css.length, 0);
403
- totalCssSize += cssSize;
404
- totalRulesDeleted += ruleInfo.cssText.length;
405
- }
406
- if (!rulesBySheet.has(sheetIndex)) rulesBySheet.set(sheetIndex, []);
407
- rulesBySheet.get(sheetIndex).push({
408
- className,
409
- ruleInfo
410
- });
411
- }
412
- for (const [_sheetIndex, rulesInSheet] of rulesBySheet) {
413
- rulesInSheet.sort((a, b) => b.ruleInfo.ruleIndex - a.ruleInfo.ruleIndex);
414
- for (const { className, ruleInfo } of rulesInSheet) {
415
- if ((registry.refCounts.get(className) || 0) > 0) continue;
416
- if (registry.rules.get(className) !== ruleInfo) continue;
417
- const sheetInfo = registry.sheets[ruleInfo.sheetIndex];
418
- if (!sheetInfo || !sheetInfo.sheet) continue;
419
- const styleSheet = sheetInfo.sheet.sheet;
420
- if (!styleSheet) continue;
421
- const maxRuleIndex = styleSheet.cssRules.length - 1;
422
- const startIdx = ruleInfo.ruleIndex;
423
- const endIdx = ruleInfo.endRuleIndex ?? ruleInfo.ruleIndex;
424
- if (startIdx < 0 || endIdx > maxRuleIndex || startIdx > endIdx) continue;
425
- this.deleteRule(registry, ruleInfo);
426
- registry.rules.delete(className);
427
- registry.refCounts.delete(className);
428
- const keysToDelete = [];
429
- for (const [key, mappedClassName] of registry.cacheKeyToClassName.entries()) if (mappedClassName === className) keysToDelete.push(key);
430
- for (const key of keysToDelete) registry.cacheKeyToClassName.delete(key);
431
- cleanedUpCount++;
432
- }
433
- }
434
- if (registry.metrics) {
435
- registry.metrics.bulkCleanups++;
436
- registry.metrics.stylesCleanedUp += cleanedUpCount;
437
- registry.metrics.cleanupHistory.push({
438
- timestamp: cleanupStartTime,
439
- classesDeleted: cleanedUpCount,
440
- cssSize: totalCssSize,
441
- rulesDeleted: totalRulesDeleted
442
- });
443
- }
444
- }
445
- /**
446
- * Get total number of rules across all sheets
447
- */
448
- getTotalRuleCount(registry) {
449
- return registry.sheets.reduce((total, sheet) => total + sheet.ruleCount - sheet.holes.length, 0);
450
- }
451
- /**
452
- * Get CSS text from all sheets (for SSR)
453
- */
454
- getCssText(registry) {
455
- const cssChunks = [];
456
- for (const sheet of registry.sheets) try {
457
- const styleElement = sheet.sheet;
458
- if (styleElement.textContent) cssChunks.push(styleElement.textContent);
459
- else if (styleElement.sheet) {
460
- const rules = Array.from(styleElement.sheet.cssRules);
461
- cssChunks.push(rules.map((rule) => rule.cssText).join("\n"));
462
- }
463
- } catch (error) {
464
- console.warn("Failed to read CSS from sheet:", error);
465
- }
466
- return cssChunks.join("\n");
467
- }
468
- /**
469
- * Get cache performance metrics
470
- */
471
- getMetrics(registry) {
472
- if (!registry.metrics) return null;
473
- const unusedRulesCount = Array.from(registry.refCounts.values()).filter((count) => count === 0).length;
474
- return {
475
- ...registry.metrics,
476
- unusedHits: unusedRulesCount
477
- };
478
- }
479
- /**
480
- * Reset cache performance metrics
481
- */
482
- resetMetrics(registry) {
483
- if (registry.metrics) registry.metrics = {
484
- hits: 0,
485
- misses: 0,
486
- bulkCleanups: 0,
487
- totalInsertions: 0,
488
- totalUnused: 0,
489
- stylesCleanedUp: 0,
490
- cleanupHistory: [],
491
- startTime: Date.now()
492
- };
493
- }
494
- /**
495
- * Convert keyframes steps to CSS string.
496
- * Public so the SSR collector can format keyframes without DOM access.
497
- * Returns both the CSS text and a combined declarations string for property type scanning.
498
- */
499
- stepsToCSS(steps) {
500
- const rules = [];
501
- const allDeclarations = [];
502
- for (const [key, value] of Object.entries(steps)) {
503
- if (typeof value === "string") {
504
- rules.push(`${key} { ${value.trim()} }`);
505
- allDeclarations.push(value.trim());
506
- continue;
507
- }
508
- const styleMap = value || {};
509
- const styleNames = Object.keys(styleMap).sort();
510
- const handlerQueue = [];
511
- const seenHandlers = /* @__PURE__ */ new Set();
512
- styleNames.forEach((styleName) => {
513
- let handlers = STYLE_HANDLER_MAP[styleName];
514
- if (!handlers) handlers = STYLE_HANDLER_MAP[styleName] = [createStyle(styleName)];
515
- handlers.forEach((handler) => {
516
- if (!seenHandlers.has(handler)) {
517
- seenHandlers.add(handler);
518
- handlerQueue.push(handler);
519
- }
520
- });
521
- });
522
- const declarationPairs = [];
523
- handlerQueue.forEach((handler) => {
524
- const result = handler(handler.__lookupStyles.reduce((acc, name) => {
525
- const v = styleMap[name];
526
- if (v !== void 0) acc[name] = v;
527
- return acc;
528
- }, {}));
529
- if (!result) return;
530
- (Array.isArray(result) ? result : [result]).forEach((cssMap) => {
531
- if (!cssMap || typeof cssMap !== "object") return;
532
- const { $: _$, ...props } = cssMap;
533
- Object.entries(props).forEach(([prop, val]) => {
534
- if (val == null || val === "") return;
535
- if (Array.isArray(val)) val.forEach((v) => {
536
- if (v != null && v !== "") declarationPairs.push({
537
- prop,
538
- value: String(v)
539
- });
540
- });
541
- else declarationPairs.push({
542
- prop,
543
- value: String(val)
544
- });
545
- });
546
- });
547
- });
548
- const declarations = declarationPairs.map((d) => `${d.prop}: ${d.value}`).join("; ");
549
- rules.push(`${key} { ${declarations.trim()} }`);
550
- allDeclarations.push(declarations);
551
- }
552
- return {
553
- css: rules.join(" "),
554
- declarations: allDeclarations.join("; ")
555
- };
556
- }
557
- /**
558
- * Insert keyframes rule.
559
- * Returns the KeyframesInfo and the raw declarations string for property type scanning.
560
- */
561
- insertKeyframes(registry, steps, name, root) {
562
- let targetSheet = this.findAvailableSheet(registry, root);
563
- if (!targetSheet) targetSheet = this.createSheet(registry, root);
564
- const ruleIndex = this.findAvailableRuleIndex(targetSheet);
565
- const sheetIndex = registry.sheets.indexOf(targetSheet);
566
- try {
567
- const { css: cssSteps, declarations } = this.stepsToCSS(steps);
568
- const fullRule = `@keyframes ${name} { ${cssSteps} }`;
569
- const styleElement = targetSheet.sheet;
570
- const styleSheet = styleElement.sheet;
571
- if (styleSheet && !this.config.forceTextInjection) {
572
- const safeIndex = Math.min(Math.max(0, ruleIndex), styleSheet.cssRules.length);
573
- styleSheet.insertRule(fullRule, safeIndex);
574
- } else styleElement.textContent = (styleElement.textContent || "") + "\n" + fullRule;
575
- targetSheet.ruleCount++;
576
- return {
577
- info: {
578
- name,
579
- ruleIndex,
580
- sheetIndex,
581
- cssText: this.config.devMode ? fullRule : void 0
582
- },
583
- declarations
584
- };
585
- } catch (error) {
586
- console.warn("Failed to insert keyframes:", error);
587
- return null;
588
- }
589
- }
590
- /**
591
- * Delete keyframes rule
592
- */
593
- deleteKeyframes(registry, info) {
594
- const sheet = registry.sheets[info.sheetIndex];
595
- if (!sheet) return;
596
- try {
597
- const styleSheet = sheet.sheet.sheet;
598
- if (styleSheet) {
599
- if (info.ruleIndex >= 0 && info.ruleIndex < styleSheet.cssRules.length) {
600
- styleSheet.deleteRule(info.ruleIndex);
601
- sheet.ruleCount = Math.max(0, sheet.ruleCount - 1);
602
- this.adjustIndicesAfterDeletion(registry, info.sheetIndex, info.ruleIndex, info.ruleIndex, 1, {
603
- className: "",
604
- ruleIndex: info.ruleIndex,
605
- sheetIndex: info.sheetIndex
606
- }, [info.ruleIndex]);
607
- }
608
- }
609
- } catch (error) {
610
- console.warn("Failed to delete keyframes:", error);
611
- }
612
- }
613
- /**
614
- * Schedule async cleanup check (non-stacking)
615
- */
616
- checkCleanupNeeded(registry) {
617
- if (registry.cleanupCheckTimeout) {
618
- clearTimeout(registry.cleanupCheckTimeout);
619
- registry.cleanupCheckTimeout = null;
620
- }
621
- registry.cleanupCheckTimeout = setTimeout(() => {
622
- this.performCleanupCheck(registry);
623
- registry.cleanupCheckTimeout = null;
624
- }, 0);
625
- }
626
- /**
627
- * Perform the actual cleanup check (called asynchronously)
628
- */
629
- performCleanupCheck(registry) {
630
- if (Array.from(registry.refCounts.values()).filter((count) => count === 0).length >= (this.config.unusedStylesThreshold || 500)) this.scheduleBulkCleanup(registry);
631
- }
632
- /**
633
- * Clean up resources for a root
634
- */
635
- cleanup(root) {
636
- const registry = this.rootRegistries.get(root);
637
- if (!registry) return;
638
- if (registry.bulkCleanupTimeout) {
639
- if (this.config.idleCleanup && typeof cancelIdleCallback !== "undefined") cancelIdleCallback(registry.bulkCleanupTimeout);
640
- else clearTimeout(registry.bulkCleanupTimeout);
641
- registry.bulkCleanupTimeout = null;
642
- }
643
- if (registry.cleanupCheckTimeout) {
644
- clearTimeout(registry.cleanupCheckTimeout);
645
- registry.cleanupCheckTimeout = null;
646
- }
647
- for (const sheet of registry.sheets) try {
648
- const styleElement = sheet.sheet;
649
- if (styleElement.parentNode) styleElement.parentNode.removeChild(styleElement);
650
- } catch (error) {
651
- console.warn("Failed to cleanup sheet:", error);
652
- }
653
- this.rootRegistries.delete(root);
654
- const rawStyleElement = this.rawStyleElements.get(root);
655
- if (rawStyleElement?.parentNode) rawStyleElement.parentNode.removeChild(rawStyleElement);
656
- this.rawStyleElements.delete(root);
657
- this.rawCSSBlocks.delete(root);
658
- }
659
- /**
660
- * Get or create a dedicated style element for raw CSS
661
- * Raw CSS is kept separate from tasty-managed sheets to avoid index conflicts
662
- */
663
- getOrCreateRawStyleElement(root) {
664
- let styleElement = this.rawStyleElements.get(root);
665
- if (!styleElement) {
666
- styleElement = root.createElement?.("style") || document.createElement("style");
667
- if (this.config.nonce) styleElement.nonce = this.config.nonce;
668
- styleElement.setAttribute("data-tasty-raw", "");
669
- if ("head" in root && root.head) root.head.appendChild(styleElement);
670
- else if ("appendChild" in root) root.appendChild(styleElement);
671
- else document.head.appendChild(styleElement);
672
- this.rawStyleElements.set(root, styleElement);
673
- this.rawCSSBlocks.set(root, /* @__PURE__ */ new Map());
674
- }
675
- return styleElement;
676
- }
677
- /**
678
- * Inject raw CSS text directly without parsing
679
- * Returns a dispose function to remove the injected CSS
680
- */
681
- injectRawCSS(css, root) {
682
- if (!css.trim()) return { dispose: () => {} };
683
- const styleElement = this.getOrCreateRawStyleElement(root);
684
- const blocksMap = this.rawCSSBlocks.get(root);
685
- const id = `raw_${this.rawCSSCounter++}`;
686
- const currentContent = styleElement.textContent || "";
687
- const startOffset = currentContent.length;
688
- const cssWithNewline = (currentContent ? "\n" : "") + css;
689
- const endOffset = startOffset + cssWithNewline.length;
690
- styleElement.textContent = currentContent + cssWithNewline;
691
- const info = {
692
- id,
693
- css,
694
- startOffset,
695
- endOffset
696
- };
697
- blocksMap.set(id, info);
698
- return { dispose: () => {
699
- this.disposeRawCSS(id, root);
700
- } };
701
- }
702
- /**
703
- * Remove a raw CSS block by ID
704
- */
705
- disposeRawCSS(id, root) {
706
- const styleElement = this.rawStyleElements.get(root);
707
- const blocksMap = this.rawCSSBlocks.get(root);
708
- if (!styleElement || !blocksMap) return;
709
- if (!blocksMap.get(id)) return;
710
- blocksMap.delete(id);
711
- const remainingBlocks = Array.from(blocksMap.values());
712
- if (remainingBlocks.length === 0) styleElement.textContent = "";
713
- else {
714
- remainingBlocks.sort((a, b) => a.startOffset - b.startOffset);
715
- styleElement.textContent = remainingBlocks.map((block) => block.css).join("\n");
716
- let offset = 0;
717
- for (const block of remainingBlocks) {
718
- block.startOffset = offset;
719
- block.endOffset = offset + block.css.length;
720
- offset = block.endOffset + 1;
721
- }
722
- }
723
- }
724
- /**
725
- * Get the raw CSS content for SSR
726
- */
727
- getRawCSSText(root) {
728
- return this.rawStyleElements.get(root)?.textContent || "";
729
- }
730
- };
731
-
732
- //#endregion
733
- export { SheetManager };
734
- //# sourceMappingURL=sheet-manager.js.map