@tenphi/tasty 0.0.0-snapshot.2dc73be → 0.0.0-snapshot.2ea241d

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 (326) hide show
  1. package/README.md +298 -250
  2. package/dist/{ssr/async-storage.js → async-storage-B7_o6FKt.js} +17 -8
  3. package/dist/async-storage-B7_o6FKt.js.map +1 -0
  4. package/dist/collector-Crs9kGJW.js +243 -0
  5. package/dist/collector-Crs9kGJW.js.map +1 -0
  6. package/dist/{ssr/collector.d.ts → collector-osfWTeRd.d.ts} +38 -15
  7. package/dist/config-BaxtQMS3.js +10464 -0
  8. package/dist/config-BaxtQMS3.js.map +1 -0
  9. package/dist/config-BoZDUHW5.d.ts +945 -0
  10. package/dist/context-CkSg-kDT.js +24 -0
  11. package/dist/context-CkSg-kDT.js.map +1 -0
  12. package/dist/core/index.d.ts +5 -33
  13. package/dist/core/index.js +6 -26
  14. package/dist/core-CmxaoZ-N.js +1598 -0
  15. package/dist/core-CmxaoZ-N.js.map +1 -0
  16. package/dist/{zero/extractor.js → css-writer-CPy_cbFJ.js} +149 -13
  17. package/dist/css-writer-CPy_cbFJ.js.map +1 -0
  18. package/dist/{ssr/format-global-rules.js → format-global-rules-Dbc_1tc3.js} +3 -3
  19. package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
  20. package/dist/format-rules-CPirO_Mj.js +143 -0
  21. package/dist/format-rules-CPirO_Mj.js.map +1 -0
  22. package/dist/hydrate-CVn-A_3y.js +45 -0
  23. package/dist/hydrate-CVn-A_3y.js.map +1 -0
  24. package/dist/index-B_k47mc_.d.ts +1655 -0
  25. package/dist/index-tcHuMPFt.d.ts +1286 -0
  26. package/dist/index.d.ts +5 -48
  27. package/dist/index.js +731 -32
  28. package/dist/index.js.map +1 -0
  29. package/dist/keyframes-vpzoVdUR.js +588 -0
  30. package/dist/keyframes-vpzoVdUR.js.map +1 -0
  31. package/dist/{utils/merge-styles.d.ts → merge-styles-BMWcH6MF.d.ts} +3 -3
  32. package/dist/{utils/merge-styles.js → merge-styles-BzQutdAK.js} +4 -6
  33. package/dist/merge-styles-BzQutdAK.js.map +1 -0
  34. package/dist/{utils/resolve-recipes.js → resolve-recipes-DgH8A3Nn.js} +5 -8
  35. package/dist/resolve-recipes-DgH8A3Nn.js.map +1 -0
  36. package/dist/ssr/astro-client.d.ts +1 -0
  37. package/dist/ssr/astro-client.js +19 -0
  38. package/dist/ssr/astro-client.js.map +1 -0
  39. package/dist/ssr/astro-middleware.d.ts +15 -0
  40. package/dist/ssr/astro-middleware.js +19 -0
  41. package/dist/ssr/astro-middleware.js.map +1 -0
  42. package/dist/ssr/astro.d.ts +78 -10
  43. package/dist/ssr/astro.js +116 -32
  44. package/dist/ssr/astro.js.map +1 -1
  45. package/dist/ssr/index.d.ts +44 -5
  46. package/dist/ssr/index.js +7 -9
  47. package/dist/ssr/index.js.map +1 -1
  48. package/dist/ssr/next.d.ts +7 -6
  49. package/dist/ssr/next.js +18 -14
  50. package/dist/ssr/next.js.map +1 -1
  51. package/dist/static/index.d.ts +91 -5
  52. package/dist/static/index.js +49 -4
  53. package/dist/static/index.js.map +1 -0
  54. package/dist/static/inject.d.ts +5 -0
  55. package/dist/static/inject.js +17 -0
  56. package/dist/static/inject.js.map +1 -0
  57. package/dist/zero/babel.d.ts +49 -95
  58. package/dist/zero/babel.js +203 -48
  59. package/dist/zero/babel.js.map +1 -1
  60. package/dist/zero/index.d.ts +67 -3
  61. package/dist/zero/index.js +2 -4
  62. package/dist/zero/next.d.ts +28 -1
  63. package/dist/zero/next.js +70 -15
  64. package/dist/zero/next.js.map +1 -1
  65. package/docs/README.md +31 -0
  66. package/docs/adoption.md +298 -0
  67. package/docs/comparison.md +419 -0
  68. package/docs/configuration.md +239 -12
  69. package/docs/debug.md +155 -340
  70. package/docs/design-system.md +436 -0
  71. package/docs/dsl.md +690 -0
  72. package/docs/getting-started.md +217 -0
  73. package/docs/injector.md +45 -29
  74. package/docs/methodology.md +642 -0
  75. package/docs/pipeline.md +699 -0
  76. package/docs/react-api.md +581 -0
  77. package/docs/ssr.md +156 -84
  78. package/docs/styles.md +50 -26
  79. package/docs/tasty-static.md +194 -23
  80. package/package.json +30 -14
  81. package/tasty.config.ts +1 -0
  82. package/dist/_virtual/_rolldown/runtime.js +0 -8
  83. package/dist/chunks/cacheKey.js +0 -70
  84. package/dist/chunks/cacheKey.js.map +0 -1
  85. package/dist/chunks/definitions.d.ts +0 -37
  86. package/dist/chunks/definitions.js +0 -259
  87. package/dist/chunks/definitions.js.map +0 -1
  88. package/dist/chunks/renderChunk.js +0 -61
  89. package/dist/chunks/renderChunk.js.map +0 -1
  90. package/dist/config.d.ts +0 -288
  91. package/dist/config.js +0 -417
  92. package/dist/config.js.map +0 -1
  93. package/dist/debug.d.ts +0 -204
  94. package/dist/debug.js +0 -733
  95. package/dist/debug.js.map +0 -1
  96. package/dist/hooks/useGlobalStyles.d.ts +0 -30
  97. package/dist/hooks/useGlobalStyles.js +0 -83
  98. package/dist/hooks/useGlobalStyles.js.map +0 -1
  99. package/dist/hooks/useKeyframes.d.ts +0 -56
  100. package/dist/hooks/useKeyframes.js +0 -69
  101. package/dist/hooks/useKeyframes.js.map +0 -1
  102. package/dist/hooks/useProperty.d.ts +0 -79
  103. package/dist/hooks/useProperty.js +0 -114
  104. package/dist/hooks/useProperty.js.map +0 -1
  105. package/dist/hooks/useRawCSS.d.ts +0 -53
  106. package/dist/hooks/useRawCSS.js +0 -40
  107. package/dist/hooks/useRawCSS.js.map +0 -1
  108. package/dist/hooks/useStyles.d.ts +0 -45
  109. package/dist/hooks/useStyles.js +0 -248
  110. package/dist/hooks/useStyles.js.map +0 -1
  111. package/dist/injector/index.d.ts +0 -165
  112. package/dist/injector/index.js +0 -162
  113. package/dist/injector/index.js.map +0 -1
  114. package/dist/injector/injector.d.ts +0 -148
  115. package/dist/injector/injector.js +0 -436
  116. package/dist/injector/injector.js.map +0 -1
  117. package/dist/injector/sheet-manager.d.ts +0 -136
  118. package/dist/injector/sheet-manager.js +0 -729
  119. package/dist/injector/sheet-manager.js.map +0 -1
  120. package/dist/injector/types.d.ts +0 -144
  121. package/dist/keyframes/index.js +0 -206
  122. package/dist/keyframes/index.js.map +0 -1
  123. package/dist/parser/classify.js +0 -319
  124. package/dist/parser/classify.js.map +0 -1
  125. package/dist/parser/const.js +0 -33
  126. package/dist/parser/const.js.map +0 -1
  127. package/dist/parser/lru.js +0 -109
  128. package/dist/parser/lru.js.map +0 -1
  129. package/dist/parser/parser.d.ts +0 -25
  130. package/dist/parser/parser.js +0 -116
  131. package/dist/parser/parser.js.map +0 -1
  132. package/dist/parser/tokenizer.js +0 -69
  133. package/dist/parser/tokenizer.js.map +0 -1
  134. package/dist/parser/types.d.ts +0 -51
  135. package/dist/parser/types.js +0 -46
  136. package/dist/parser/types.js.map +0 -1
  137. package/dist/pipeline/conditions.d.ts +0 -134
  138. package/dist/pipeline/conditions.js +0 -406
  139. package/dist/pipeline/conditions.js.map +0 -1
  140. package/dist/pipeline/exclusive.js +0 -231
  141. package/dist/pipeline/exclusive.js.map +0 -1
  142. package/dist/pipeline/index.d.ts +0 -53
  143. package/dist/pipeline/index.js +0 -660
  144. package/dist/pipeline/index.js.map +0 -1
  145. package/dist/pipeline/materialize.js +0 -856
  146. package/dist/pipeline/materialize.js.map +0 -1
  147. package/dist/pipeline/parseStateKey.d.ts +0 -15
  148. package/dist/pipeline/parseStateKey.js +0 -451
  149. package/dist/pipeline/parseStateKey.js.map +0 -1
  150. package/dist/pipeline/simplify.js +0 -516
  151. package/dist/pipeline/simplify.js.map +0 -1
  152. package/dist/pipeline/warnings.js +0 -18
  153. package/dist/pipeline/warnings.js.map +0 -1
  154. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  155. package/dist/plugins/okhsl-plugin.js +0 -371
  156. package/dist/plugins/okhsl-plugin.js.map +0 -1
  157. package/dist/plugins/types.d.ts +0 -69
  158. package/dist/properties/index.js +0 -236
  159. package/dist/properties/index.js.map +0 -1
  160. package/dist/properties/property-type-resolver.d.ts +0 -24
  161. package/dist/properties/property-type-resolver.js +0 -87
  162. package/dist/properties/property-type-resolver.js.map +0 -1
  163. package/dist/ssr/async-storage.d.ts +0 -17
  164. package/dist/ssr/async-storage.js.map +0 -1
  165. package/dist/ssr/collect-auto-properties.js +0 -40
  166. package/dist/ssr/collect-auto-properties.js.map +0 -1
  167. package/dist/ssr/collector.js +0 -173
  168. package/dist/ssr/collector.js.map +0 -1
  169. package/dist/ssr/context.d.ts +0 -8
  170. package/dist/ssr/context.js +0 -14
  171. package/dist/ssr/context.js.map +0 -1
  172. package/dist/ssr/format-global-rules.js.map +0 -1
  173. package/dist/ssr/format-keyframes.js +0 -70
  174. package/dist/ssr/format-keyframes.js.map +0 -1
  175. package/dist/ssr/format-property.js +0 -48
  176. package/dist/ssr/format-property.js.map +0 -1
  177. package/dist/ssr/format-rules.js +0 -70
  178. package/dist/ssr/format-rules.js.map +0 -1
  179. package/dist/ssr/hydrate.d.ts +0 -22
  180. package/dist/ssr/hydrate.js +0 -50
  181. package/dist/ssr/hydrate.js.map +0 -1
  182. package/dist/ssr/ssr-collector-ref.js +0 -12
  183. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  184. package/dist/states/index.d.ts +0 -49
  185. package/dist/states/index.js +0 -416
  186. package/dist/states/index.js.map +0 -1
  187. package/dist/static/tastyStatic.d.ts +0 -46
  188. package/dist/static/tastyStatic.js +0 -31
  189. package/dist/static/tastyStatic.js.map +0 -1
  190. package/dist/static/types.d.ts +0 -49
  191. package/dist/static/types.js +0 -24
  192. package/dist/static/types.js.map +0 -1
  193. package/dist/styles/align.d.ts +0 -15
  194. package/dist/styles/align.js +0 -14
  195. package/dist/styles/align.js.map +0 -1
  196. package/dist/styles/border.d.ts +0 -25
  197. package/dist/styles/border.js +0 -114
  198. package/dist/styles/border.js.map +0 -1
  199. package/dist/styles/color.d.ts +0 -14
  200. package/dist/styles/color.js +0 -23
  201. package/dist/styles/color.js.map +0 -1
  202. package/dist/styles/createStyle.js +0 -77
  203. package/dist/styles/createStyle.js.map +0 -1
  204. package/dist/styles/dimension.js +0 -97
  205. package/dist/styles/dimension.js.map +0 -1
  206. package/dist/styles/display.d.ts +0 -37
  207. package/dist/styles/display.js +0 -67
  208. package/dist/styles/display.js.map +0 -1
  209. package/dist/styles/fade.d.ts +0 -15
  210. package/dist/styles/fade.js +0 -58
  211. package/dist/styles/fade.js.map +0 -1
  212. package/dist/styles/fill.d.ts +0 -42
  213. package/dist/styles/fill.js +0 -52
  214. package/dist/styles/fill.js.map +0 -1
  215. package/dist/styles/flow.d.ts +0 -16
  216. package/dist/styles/flow.js +0 -12
  217. package/dist/styles/flow.js.map +0 -1
  218. package/dist/styles/gap.d.ts +0 -31
  219. package/dist/styles/gap.js +0 -37
  220. package/dist/styles/gap.js.map +0 -1
  221. package/dist/styles/height.d.ts +0 -17
  222. package/dist/styles/height.js +0 -20
  223. package/dist/styles/height.js.map +0 -1
  224. package/dist/styles/index.d.ts +0 -2
  225. package/dist/styles/index.js +0 -9
  226. package/dist/styles/index.js.map +0 -1
  227. package/dist/styles/inset.d.ts +0 -52
  228. package/dist/styles/inset.js +0 -150
  229. package/dist/styles/inset.js.map +0 -1
  230. package/dist/styles/justify.d.ts +0 -15
  231. package/dist/styles/justify.js +0 -14
  232. package/dist/styles/justify.js.map +0 -1
  233. package/dist/styles/list.d.ts +0 -16
  234. package/dist/styles/list.js +0 -98
  235. package/dist/styles/list.js.map +0 -1
  236. package/dist/styles/margin.d.ts +0 -24
  237. package/dist/styles/margin.js +0 -104
  238. package/dist/styles/margin.js.map +0 -1
  239. package/dist/styles/outline.d.ts +0 -29
  240. package/dist/styles/outline.js +0 -65
  241. package/dist/styles/outline.js.map +0 -1
  242. package/dist/styles/padding.d.ts +0 -24
  243. package/dist/styles/padding.js +0 -104
  244. package/dist/styles/padding.js.map +0 -1
  245. package/dist/styles/predefined.d.ts +0 -71
  246. package/dist/styles/predefined.js +0 -238
  247. package/dist/styles/predefined.js.map +0 -1
  248. package/dist/styles/preset.d.ts +0 -47
  249. package/dist/styles/preset.js +0 -126
  250. package/dist/styles/preset.js.map +0 -1
  251. package/dist/styles/radius.d.ts +0 -14
  252. package/dist/styles/radius.js +0 -51
  253. package/dist/styles/radius.js.map +0 -1
  254. package/dist/styles/scrollbar.d.ts +0 -25
  255. package/dist/styles/scrollbar.js +0 -48
  256. package/dist/styles/scrollbar.js.map +0 -1
  257. package/dist/styles/shadow.d.ts +0 -14
  258. package/dist/styles/shadow.js +0 -24
  259. package/dist/styles/shadow.js.map +0 -1
  260. package/dist/styles/transition.d.ts +0 -14
  261. package/dist/styles/transition.js +0 -158
  262. package/dist/styles/transition.js.map +0 -1
  263. package/dist/styles/types.d.ts +0 -495
  264. package/dist/styles/width.d.ts +0 -17
  265. package/dist/styles/width.js +0 -20
  266. package/dist/styles/width.js.map +0 -1
  267. package/dist/tasty.d.ts +0 -981
  268. package/dist/tasty.js +0 -206
  269. package/dist/tasty.js.map +0 -1
  270. package/dist/tokens/typography.d.ts +0 -19
  271. package/dist/tokens/typography.js +0 -237
  272. package/dist/tokens/typography.js.map +0 -1
  273. package/dist/types.d.ts +0 -184
  274. package/dist/utils/cache-wrapper.js +0 -26
  275. package/dist/utils/cache-wrapper.js.map +0 -1
  276. package/dist/utils/case-converter.js +0 -8
  277. package/dist/utils/case-converter.js.map +0 -1
  278. package/dist/utils/colors.d.ts +0 -5
  279. package/dist/utils/colors.js +0 -9
  280. package/dist/utils/colors.js.map +0 -1
  281. package/dist/utils/css-types.d.ts +0 -7
  282. package/dist/utils/dotize.d.ts +0 -26
  283. package/dist/utils/dotize.js +0 -122
  284. package/dist/utils/dotize.js.map +0 -1
  285. package/dist/utils/filter-base-props.d.ts +0 -15
  286. package/dist/utils/filter-base-props.js +0 -45
  287. package/dist/utils/filter-base-props.js.map +0 -1
  288. package/dist/utils/get-display-name.d.ts +0 -7
  289. package/dist/utils/get-display-name.js +0 -10
  290. package/dist/utils/get-display-name.js.map +0 -1
  291. package/dist/utils/hsl-to-rgb.js +0 -38
  292. package/dist/utils/hsl-to-rgb.js.map +0 -1
  293. package/dist/utils/is-dev-env.js +0 -19
  294. package/dist/utils/is-dev-env.js.map +0 -1
  295. package/dist/utils/is-valid-element-type.js +0 -15
  296. package/dist/utils/is-valid-element-type.js.map +0 -1
  297. package/dist/utils/merge-styles.js.map +0 -1
  298. package/dist/utils/mod-attrs.d.ts +0 -8
  299. package/dist/utils/mod-attrs.js +0 -21
  300. package/dist/utils/mod-attrs.js.map +0 -1
  301. package/dist/utils/okhsl-to-rgb.js +0 -296
  302. package/dist/utils/okhsl-to-rgb.js.map +0 -1
  303. package/dist/utils/process-tokens.d.ts +0 -31
  304. package/dist/utils/process-tokens.js +0 -171
  305. package/dist/utils/process-tokens.js.map +0 -1
  306. package/dist/utils/resolve-recipes.d.ts +0 -17
  307. package/dist/utils/resolve-recipes.js.map +0 -1
  308. package/dist/utils/selector-transform.js +0 -32
  309. package/dist/utils/selector-transform.js.map +0 -1
  310. package/dist/utils/string.js +0 -8
  311. package/dist/utils/string.js.map +0 -1
  312. package/dist/utils/styles.d.ts +0 -177
  313. package/dist/utils/styles.js +0 -730
  314. package/dist/utils/styles.js.map +0 -1
  315. package/dist/utils/typography.d.ts +0 -36
  316. package/dist/utils/typography.js +0 -53
  317. package/dist/utils/typography.js.map +0 -1
  318. package/dist/utils/warnings.d.ts +0 -16
  319. package/dist/utils/warnings.js +0 -16
  320. package/dist/utils/warnings.js.map +0 -1
  321. package/dist/zero/css-writer.d.ts +0 -45
  322. package/dist/zero/css-writer.js +0 -74
  323. package/dist/zero/css-writer.js.map +0 -1
  324. package/dist/zero/extractor.d.ts +0 -24
  325. package/dist/zero/extractor.js.map +0 -1
  326. package/docs/usage.md +0 -695
@@ -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