@tenphi/tasty 0.0.0-snapshot.db103fd → 0.0.0-snapshot.db2ef70

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