@tenphi/tasty 0.0.0-snapshot.fafcbfe → 0.0.0-snapshot.fc19da9

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