@tenphi/tasty 0.0.0-snapshot.e4aff73 → 0.0.0-snapshot.e4e4347

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