@tenphi/tasty 0.0.0-snapshot.fa94a5a → 0.0.0-snapshot.fdb16ea

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