@tenphi/tasty 0.0.0-snapshot.a7fb1f5 → 0.0.0-snapshot.a8a2a5d

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