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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (360) hide show
  1. package/README.md +441 -362
  2. package/dist/babel-types-BKDTT4--.d.ts +18 -0
  3. package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
  4. package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
  5. package/dist/chunks/build-config-5d8WlQbq.js +60 -0
  6. package/dist/chunks/build-config-5d8WlQbq.js.map +1 -0
  7. package/dist/chunks/collector-CjCak4iE.js +210 -0
  8. package/dist/chunks/collector-CjCak4iE.js.map +1 -0
  9. package/dist/chunks/config-engine-uOFYZidB.js +272 -0
  10. package/dist/chunks/config-engine-uOFYZidB.js.map +1 -0
  11. package/dist/chunks/config-file-DlZXJMj8.js +25 -0
  12. package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
  13. package/dist/chunks/css-definitions-ubrHP97m.js +910 -0
  14. package/dist/chunks/css-definitions-ubrHP97m.js.map +1 -0
  15. package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
  16. package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
  17. package/dist/{debug.js → chunks/debug-CJ31U_WE.js} +197 -149
  18. package/dist/chunks/debug-CJ31U_WE.js.map +1 -0
  19. package/dist/chunks/dsl-DYSJc1-T.js +1383 -0
  20. package/dist/chunks/dsl-DYSJc1-T.js.map +1 -0
  21. package/dist/chunks/hydration-TRcz5vnk.js +41 -0
  22. package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
  23. package/dist/chunks/react-runtime-CyyCI02N.js +689 -0
  24. package/dist/chunks/react-runtime-CyyCI02N.js.map +1 -0
  25. package/dist/chunks/runtime-engine-BQmOu5-W.js +2432 -0
  26. package/dist/chunks/runtime-engine-BQmOu5-W.js.map +1 -0
  27. package/dist/chunks/runtime-state-DEsyUMU-.js +152 -0
  28. package/dist/chunks/runtime-state-DEsyUMU-.js.map +1 -0
  29. package/dist/{utils/merge-styles.js → chunks/shared-utils-y-HjvPN4.js} +61 -58
  30. package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
  31. package/dist/chunks/style-engine-BX2LshDZ.js +5466 -0
  32. package/dist/chunks/style-engine-BX2LshDZ.js.map +1 -0
  33. package/dist/chunks/zero-engine-Dw0P4yGM.js +310 -0
  34. package/dist/chunks/zero-engine-Dw0P4yGM.js.map +1 -0
  35. package/dist/collector-CTU-nl0g.d.ts +164 -0
  36. package/dist/config-CcxqSZI2.d.ts +1368 -0
  37. package/dist/core/index.d.ts +5 -34
  38. package/dist/core/index.js +9 -27
  39. package/dist/hydrate-CRyjjAyl.d.ts +22 -0
  40. package/dist/index-xtey-KDu.d.ts +1950 -0
  41. package/dist/index.d.ts +5 -49
  42. package/dist/index.js +11 -34
  43. package/dist/{utils/merge-styles.d.ts → merge-styles-DSkVc6CD.d.ts} +3 -4
  44. package/dist/ssr/astro-client.d.ts +1 -0
  45. package/dist/ssr/astro-client.js +6 -0
  46. package/dist/ssr/astro-client.js.map +1 -0
  47. package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
  48. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  49. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  50. package/dist/ssr/astro-middleware-extract.d.ts +10 -0
  51. package/dist/ssr/astro-middleware-extract.js +9 -0
  52. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  53. package/dist/ssr/astro-middleware-static.d.ts +17 -0
  54. package/dist/ssr/astro-middleware-static.js +7 -0
  55. package/dist/ssr/astro-middleware-static.js.map +1 -0
  56. package/dist/ssr/astro-middleware.d.ts +18 -0
  57. package/dist/ssr/astro-middleware.js +7 -0
  58. package/dist/ssr/astro-middleware.js.map +1 -0
  59. package/dist/ssr/astro.d.ts +110 -12
  60. package/dist/ssr/astro.js +206 -50
  61. package/dist/ssr/astro.js.map +1 -1
  62. package/dist/ssr/client.d.ts +2 -0
  63. package/dist/ssr/client.js +2 -0
  64. package/dist/ssr/index.d.ts +17 -5
  65. package/dist/ssr/index.js +7 -9
  66. package/dist/ssr/index.js.map +1 -1
  67. package/dist/ssr/next-config.d.ts +64 -0
  68. package/dist/ssr/next-config.js +123 -0
  69. package/dist/ssr/next-config.js.map +1 -0
  70. package/dist/ssr/next.d.ts +13 -12
  71. package/dist/ssr/next.js +40 -51
  72. package/dist/ssr/next.js.map +1 -1
  73. package/dist/static/index.d.ts +90 -5
  74. package/dist/static/index.js +31 -4
  75. package/dist/static/index.js.map +1 -0
  76. package/dist/static/inject.d.ts +4 -0
  77. package/dist/static/inject.js +17 -0
  78. package/dist/static/inject.js.map +1 -0
  79. package/dist/types-DJEM_BOJ.d.ts +1567 -0
  80. package/dist/zero/babel.d.ts +20 -108
  81. package/dist/zero/babel.js +211 -142
  82. package/dist/zero/babel.js.map +1 -1
  83. package/dist/zero/index.d.ts +135 -3
  84. package/dist/zero/index.js +23 -3
  85. package/dist/zero/index.js.map +1 -0
  86. package/dist/zero/next.d.ts +16 -5
  87. package/dist/zero/next.js +8 -42
  88. package/dist/zero/next.js.map +1 -1
  89. package/docs/README.md +23 -12
  90. package/docs/adoption.md +72 -37
  91. package/docs/ai-agents.md +255 -0
  92. package/docs/comparison.md +83 -54
  93. package/docs/configuration.md +764 -74
  94. package/docs/debug.md +39 -24
  95. package/docs/design-system.md +187 -37
  96. package/docs/dsl.md +711 -164
  97. package/docs/getting-started.md +132 -52
  98. package/docs/injector.md +197 -90
  99. package/docs/methodology.md +154 -48
  100. package/docs/migration-v3.md +285 -0
  101. package/docs/pipeline.md +768 -0
  102. package/docs/plugins.md +333 -0
  103. package/docs/react-api.md +742 -0
  104. package/docs/runtime-benchmarks.md +388 -0
  105. package/docs/ssr.md +403 -149
  106. package/docs/styles.md +200 -45
  107. package/docs/tasty-static.md +354 -99
  108. package/package.json +153 -35
  109. package/tasty.config.ts +6 -0
  110. package/dist/_virtual/_rolldown/runtime.js +0 -8
  111. package/dist/chunks/cacheKey.js +0 -78
  112. package/dist/chunks/cacheKey.js.map +0 -1
  113. package/dist/chunks/definitions.d.ts +0 -37
  114. package/dist/chunks/definitions.js +0 -259
  115. package/dist/chunks/definitions.js.map +0 -1
  116. package/dist/chunks/renderChunk.js +0 -60
  117. package/dist/chunks/renderChunk.js.map +0 -1
  118. package/dist/config.d.ts +0 -323
  119. package/dist/config.js +0 -465
  120. package/dist/config.js.map +0 -1
  121. package/dist/debug.d.ts +0 -89
  122. package/dist/debug.js.map +0 -1
  123. package/dist/hooks/useGlobalStyles.d.ts +0 -30
  124. package/dist/hooks/useGlobalStyles.js +0 -83
  125. package/dist/hooks/useGlobalStyles.js.map +0 -1
  126. package/dist/hooks/useKeyframes.d.ts +0 -56
  127. package/dist/hooks/useKeyframes.js +0 -69
  128. package/dist/hooks/useKeyframes.js.map +0 -1
  129. package/dist/hooks/useProperty.d.ts +0 -79
  130. package/dist/hooks/useProperty.js +0 -114
  131. package/dist/hooks/useProperty.js.map +0 -1
  132. package/dist/hooks/useRawCSS.d.ts +0 -53
  133. package/dist/hooks/useRawCSS.js +0 -40
  134. package/dist/hooks/useRawCSS.js.map +0 -1
  135. package/dist/hooks/useStyles.d.ts +0 -45
  136. package/dist/hooks/useStyles.js +0 -249
  137. package/dist/hooks/useStyles.js.map +0 -1
  138. package/dist/injector/index.d.ts +0 -165
  139. package/dist/injector/index.js +0 -162
  140. package/dist/injector/index.js.map +0 -1
  141. package/dist/injector/injector.d.ts +0 -148
  142. package/dist/injector/injector.js +0 -430
  143. package/dist/injector/injector.js.map +0 -1
  144. package/dist/injector/sheet-manager.d.ts +0 -136
  145. package/dist/injector/sheet-manager.js +0 -729
  146. package/dist/injector/sheet-manager.js.map +0 -1
  147. package/dist/injector/types.d.ts +0 -144
  148. package/dist/keyframes/index.js +0 -206
  149. package/dist/keyframes/index.js.map +0 -1
  150. package/dist/parser/classify.js +0 -320
  151. package/dist/parser/classify.js.map +0 -1
  152. package/dist/parser/const.js +0 -33
  153. package/dist/parser/const.js.map +0 -1
  154. package/dist/parser/lru.js +0 -109
  155. package/dist/parser/lru.js.map +0 -1
  156. package/dist/parser/parser.d.ts +0 -25
  157. package/dist/parser/parser.js +0 -116
  158. package/dist/parser/parser.js.map +0 -1
  159. package/dist/parser/tokenizer.js +0 -69
  160. package/dist/parser/tokenizer.js.map +0 -1
  161. package/dist/parser/types.d.ts +0 -51
  162. package/dist/parser/types.js +0 -46
  163. package/dist/parser/types.js.map +0 -1
  164. package/dist/pipeline/conditions.d.ts +0 -134
  165. package/dist/pipeline/conditions.js +0 -406
  166. package/dist/pipeline/conditions.js.map +0 -1
  167. package/dist/pipeline/exclusive.js +0 -231
  168. package/dist/pipeline/exclusive.js.map +0 -1
  169. package/dist/pipeline/index.d.ts +0 -53
  170. package/dist/pipeline/index.js +0 -681
  171. package/dist/pipeline/index.js.map +0 -1
  172. package/dist/pipeline/materialize.js +0 -1105
  173. package/dist/pipeline/materialize.js.map +0 -1
  174. package/dist/pipeline/parseStateKey.d.ts +0 -15
  175. package/dist/pipeline/parseStateKey.js +0 -447
  176. package/dist/pipeline/parseStateKey.js.map +0 -1
  177. package/dist/pipeline/simplify.js +0 -516
  178. package/dist/pipeline/simplify.js.map +0 -1
  179. package/dist/pipeline/warnings.js +0 -18
  180. package/dist/pipeline/warnings.js.map +0 -1
  181. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  182. package/dist/plugins/okhsl-plugin.js +0 -98
  183. package/dist/plugins/okhsl-plugin.js.map +0 -1
  184. package/dist/plugins/types.d.ts +0 -76
  185. package/dist/properties/index.js +0 -223
  186. package/dist/properties/index.js.map +0 -1
  187. package/dist/properties/property-type-resolver.d.ts +0 -24
  188. package/dist/properties/property-type-resolver.js +0 -91
  189. package/dist/properties/property-type-resolver.js.map +0 -1
  190. package/dist/ssr/async-storage.d.ts +0 -17
  191. package/dist/ssr/async-storage.js +0 -35
  192. package/dist/ssr/async-storage.js.map +0 -1
  193. package/dist/ssr/collect-auto-properties.js +0 -40
  194. package/dist/ssr/collect-auto-properties.js.map +0 -1
  195. package/dist/ssr/collector.d.ts +0 -85
  196. package/dist/ssr/collector.js +0 -183
  197. package/dist/ssr/collector.js.map +0 -1
  198. package/dist/ssr/context.d.ts +0 -8
  199. package/dist/ssr/context.js +0 -14
  200. package/dist/ssr/context.js.map +0 -1
  201. package/dist/ssr/format-global-rules.js +0 -22
  202. package/dist/ssr/format-global-rules.js.map +0 -1
  203. package/dist/ssr/format-keyframes.js +0 -70
  204. package/dist/ssr/format-keyframes.js.map +0 -1
  205. package/dist/ssr/format-property.js +0 -50
  206. package/dist/ssr/format-property.js.map +0 -1
  207. package/dist/ssr/format-rules.js +0 -70
  208. package/dist/ssr/format-rules.js.map +0 -1
  209. package/dist/ssr/hydrate.d.ts +0 -22
  210. package/dist/ssr/hydrate.js +0 -50
  211. package/dist/ssr/hydrate.js.map +0 -1
  212. package/dist/ssr/ssr-collector-ref.js +0 -12
  213. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  214. package/dist/states/index.d.ts +0 -49
  215. package/dist/states/index.js +0 -169
  216. package/dist/states/index.js.map +0 -1
  217. package/dist/static/tastyStatic.d.ts +0 -46
  218. package/dist/static/tastyStatic.js +0 -31
  219. package/dist/static/tastyStatic.js.map +0 -1
  220. package/dist/static/types.d.ts +0 -49
  221. package/dist/static/types.js +0 -24
  222. package/dist/static/types.js.map +0 -1
  223. package/dist/styles/align.d.ts +0 -15
  224. package/dist/styles/align.js +0 -14
  225. package/dist/styles/align.js.map +0 -1
  226. package/dist/styles/border.d.ts +0 -25
  227. package/dist/styles/border.js +0 -114
  228. package/dist/styles/border.js.map +0 -1
  229. package/dist/styles/color.d.ts +0 -14
  230. package/dist/styles/color.js +0 -27
  231. package/dist/styles/color.js.map +0 -1
  232. package/dist/styles/createStyle.js +0 -80
  233. package/dist/styles/createStyle.js.map +0 -1
  234. package/dist/styles/dimension.js +0 -97
  235. package/dist/styles/dimension.js.map +0 -1
  236. package/dist/styles/display.d.ts +0 -37
  237. package/dist/styles/display.js +0 -67
  238. package/dist/styles/display.js.map +0 -1
  239. package/dist/styles/fade.d.ts +0 -15
  240. package/dist/styles/fade.js +0 -58
  241. package/dist/styles/fade.js.map +0 -1
  242. package/dist/styles/fill.d.ts +0 -42
  243. package/dist/styles/fill.js +0 -52
  244. package/dist/styles/fill.js.map +0 -1
  245. package/dist/styles/flow.d.ts +0 -16
  246. package/dist/styles/flow.js +0 -12
  247. package/dist/styles/flow.js.map +0 -1
  248. package/dist/styles/gap.d.ts +0 -31
  249. package/dist/styles/gap.js +0 -37
  250. package/dist/styles/gap.js.map +0 -1
  251. package/dist/styles/height.d.ts +0 -17
  252. package/dist/styles/height.js +0 -20
  253. package/dist/styles/height.js.map +0 -1
  254. package/dist/styles/index.d.ts +0 -2
  255. package/dist/styles/index.js +0 -9
  256. package/dist/styles/index.js.map +0 -1
  257. package/dist/styles/inset.d.ts +0 -52
  258. package/dist/styles/inset.js +0 -150
  259. package/dist/styles/inset.js.map +0 -1
  260. package/dist/styles/justify.d.ts +0 -15
  261. package/dist/styles/justify.js +0 -14
  262. package/dist/styles/justify.js.map +0 -1
  263. package/dist/styles/list.d.ts +0 -16
  264. package/dist/styles/list.js +0 -98
  265. package/dist/styles/list.js.map +0 -1
  266. package/dist/styles/margin.d.ts +0 -24
  267. package/dist/styles/margin.js +0 -104
  268. package/dist/styles/margin.js.map +0 -1
  269. package/dist/styles/outline.d.ts +0 -29
  270. package/dist/styles/outline.js +0 -65
  271. package/dist/styles/outline.js.map +0 -1
  272. package/dist/styles/padding.d.ts +0 -24
  273. package/dist/styles/padding.js +0 -104
  274. package/dist/styles/padding.js.map +0 -1
  275. package/dist/styles/predefined.d.ts +0 -71
  276. package/dist/styles/predefined.js +0 -238
  277. package/dist/styles/predefined.js.map +0 -1
  278. package/dist/styles/preset.d.ts +0 -47
  279. package/dist/styles/preset.js +0 -126
  280. package/dist/styles/preset.js.map +0 -1
  281. package/dist/styles/radius.d.ts +0 -14
  282. package/dist/styles/radius.js +0 -51
  283. package/dist/styles/radius.js.map +0 -1
  284. package/dist/styles/scrollbar.d.ts +0 -25
  285. package/dist/styles/scrollbar.js +0 -48
  286. package/dist/styles/scrollbar.js.map +0 -1
  287. package/dist/styles/shadow.d.ts +0 -14
  288. package/dist/styles/shadow.js +0 -24
  289. package/dist/styles/shadow.js.map +0 -1
  290. package/dist/styles/transition.d.ts +0 -14
  291. package/dist/styles/transition.js +0 -158
  292. package/dist/styles/transition.js.map +0 -1
  293. package/dist/styles/types.d.ts +0 -523
  294. package/dist/styles/width.d.ts +0 -17
  295. package/dist/styles/width.js +0 -20
  296. package/dist/styles/width.js.map +0 -1
  297. package/dist/tasty.d.ts +0 -114
  298. package/dist/tasty.js +0 -232
  299. package/dist/tasty.js.map +0 -1
  300. package/dist/types.d.ts +0 -184
  301. package/dist/utils/cache-wrapper.js +0 -22
  302. package/dist/utils/cache-wrapper.js.map +0 -1
  303. package/dist/utils/case-converter.js +0 -8
  304. package/dist/utils/case-converter.js.map +0 -1
  305. package/dist/utils/color-math.d.ts +0 -46
  306. package/dist/utils/color-math.js +0 -749
  307. package/dist/utils/color-math.js.map +0 -1
  308. package/dist/utils/color-space.d.ts +0 -5
  309. package/dist/utils/color-space.js +0 -229
  310. package/dist/utils/color-space.js.map +0 -1
  311. package/dist/utils/colors.d.ts +0 -5
  312. package/dist/utils/colors.js +0 -11
  313. package/dist/utils/colors.js.map +0 -1
  314. package/dist/utils/css-types.d.ts +0 -7
  315. package/dist/utils/dotize.d.ts +0 -26
  316. package/dist/utils/dotize.js +0 -122
  317. package/dist/utils/dotize.js.map +0 -1
  318. package/dist/utils/filter-base-props.d.ts +0 -15
  319. package/dist/utils/filter-base-props.js +0 -45
  320. package/dist/utils/filter-base-props.js.map +0 -1
  321. package/dist/utils/get-display-name.d.ts +0 -7
  322. package/dist/utils/get-display-name.js +0 -10
  323. package/dist/utils/get-display-name.js.map +0 -1
  324. package/dist/utils/has-keys.js +0 -13
  325. package/dist/utils/has-keys.js.map +0 -1
  326. package/dist/utils/is-dev-env.js +0 -19
  327. package/dist/utils/is-dev-env.js.map +0 -1
  328. package/dist/utils/is-valid-element-type.js +0 -15
  329. package/dist/utils/is-valid-element-type.js.map +0 -1
  330. package/dist/utils/merge-styles.js.map +0 -1
  331. package/dist/utils/mod-attrs.d.ts +0 -8
  332. package/dist/utils/mod-attrs.js +0 -21
  333. package/dist/utils/mod-attrs.js.map +0 -1
  334. package/dist/utils/process-tokens.d.ts +0 -21
  335. package/dist/utils/process-tokens.js +0 -91
  336. package/dist/utils/process-tokens.js.map +0 -1
  337. package/dist/utils/resolve-recipes.d.ts +0 -17
  338. package/dist/utils/resolve-recipes.js +0 -147
  339. package/dist/utils/resolve-recipes.js.map +0 -1
  340. package/dist/utils/selector-transform.js +0 -32
  341. package/dist/utils/selector-transform.js.map +0 -1
  342. package/dist/utils/string.js +0 -8
  343. package/dist/utils/string.js.map +0 -1
  344. package/dist/utils/styles.d.ts +0 -101
  345. package/dist/utils/styles.js +0 -223
  346. package/dist/utils/styles.js.map +0 -1
  347. package/dist/utils/typography.d.ts +0 -47
  348. package/dist/utils/typography.js +0 -43
  349. package/dist/utils/typography.js.map +0 -1
  350. package/dist/utils/warnings.d.ts +0 -16
  351. package/dist/utils/warnings.js +0 -16
  352. package/dist/utils/warnings.js.map +0 -1
  353. package/dist/zero/css-writer.d.ts +0 -45
  354. package/dist/zero/css-writer.js +0 -74
  355. package/dist/zero/css-writer.js.map +0 -1
  356. package/dist/zero/extractor.d.ts +0 -24
  357. package/dist/zero/extractor.js +0 -215
  358. package/dist/zero/extractor.js.map +0 -1
  359. package/docs/PIPELINE.md +0 -519
  360. package/docs/runtime.md +0 -397
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/injector/index.ts"],"sourcesContent":["import {\n getConfig,\n getGlobalInjector,\n isTestEnvironment,\n markStylesGenerated,\n} from '../config';\nimport type { StyleResult } from '../pipeline';\n\nimport { StyleInjector } from './injector';\nimport type {\n GlobalInjectResult,\n InjectResult,\n KeyframesResult,\n KeyframesSteps,\n StyleInjectorConfig,\n} from './types';\n\n/**\n * Allocate a className for a cacheKey without injecting styles yet\n */\nexport function allocateClassName(\n cacheKey: string,\n options?: { root?: Document | ShadowRoot },\n): { className: string; isNewAllocation: boolean } {\n return getGlobalInjector().allocateClassName(cacheKey, options);\n}\n\n/**\n * Track a reference to an already-injected cacheKey (refCount + dispose).\n * Used on cache hits (SSR hydration or runtime reuse) where the pipeline\n * was skipped. Returns null if the cacheKey is not in the cache.\n */\nexport function trackRef(\n cacheKey: string,\n options?: { root?: Document | ShadowRoot },\n): InjectResult | null {\n return getGlobalInjector().trackRef(cacheKey, options);\n}\n\n/**\n * Inject styles and return className with dispose function\n */\nexport function inject(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot; cacheKey?: string },\n): InjectResult {\n // Mark that styles have been generated (prevents configuration changes)\n markStylesGenerated();\n\n return getGlobalInjector().inject(rules, options);\n}\n\n/**\n * Inject global rules that should not reserve tasty class names\n */\nexport function injectGlobal(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot },\n): GlobalInjectResult {\n return getGlobalInjector().injectGlobal(rules, options);\n}\n\n/**\n * Inject raw CSS text directly without parsing\n * This is a low-overhead method for injecting raw CSS that doesn't need tasty processing.\n * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking.\n *\n * @example\n * ```tsx\n * // Inject raw CSS\n * const { dispose } = injectRawCSS(`\n * body { margin: 0; padding: 0; }\n * .my-class { color: red; }\n * `);\n *\n * // Later, remove the injected CSS\n * dispose();\n * ```\n */\nexport function injectRawCSS(\n css: string,\n options?: { root?: Document | ShadowRoot },\n): { dispose: () => void } {\n return getGlobalInjector().injectRawCSS(css, options);\n}\n\n/**\n * Get raw CSS text for SSR\n */\nexport function getRawCSSText(options?: {\n root?: Document | ShadowRoot;\n}): string {\n return getGlobalInjector().getRawCSSText(options);\n}\n\n/**\n * Inject keyframes and return object with toString() and dispose()\n */\nexport function keyframes(\n steps: KeyframesSteps,\n nameOrOptions?: string | { root?: Document | ShadowRoot; name?: string },\n): KeyframesResult {\n return getGlobalInjector().keyframes(steps, nameOrOptions);\n}\n\nexport interface PropertyOptions {\n /**\n * CSS syntax string for the property (e.g., '<color>', '<length>', '<angle>')\n * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax\n */\n syntax?: string;\n /**\n * Whether the property inherits from parent elements\n * @default true\n */\n inherits?: boolean;\n /**\n * Initial value for the property\n */\n initialValue?: string | number;\n /**\n * Shadow root or document to inject into\n */\n root?: Document | ShadowRoot;\n}\n\n/**\n * Define a CSS @property custom property.\n * This enables advanced features like animating custom properties.\n *\n * Note: @property rules are global and persistent once defined.\n * Re-registering the same property name is a no-op.\n *\n * @param name - The custom property name (must start with --)\n * @param options - Property configuration\n *\n * @example\n * ```ts\n * // Define a color property that can be animated\n * property('--my-color', {\n * syntax: '<color>',\n * initialValue: 'red',\n * });\n *\n * // Define an angle property\n * property('--rotation', {\n * syntax: '<angle>',\n * inherits: false,\n * initialValue: '0deg',\n * });\n * ```\n */\nexport function property(name: string, options?: PropertyOptions): void {\n return getGlobalInjector().property(name, options);\n}\n\n/**\n * Check if a CSS @property has already been defined\n *\n * @param name - The custom property name to check\n * @param options - Options including root\n */\nexport function isPropertyDefined(\n name: string,\n options?: { root?: Document | ShadowRoot },\n): boolean {\n return getGlobalInjector().isPropertyDefined(name, options);\n}\n\n/**\n * Get CSS text from all sheets (for SSR)\n */\nexport function getCssText(options?: { root?: Document | ShadowRoot }): string {\n return getGlobalInjector().getCssText(options);\n}\n\n/**\n * Collect only CSS used by a rendered subtree (like jest-styled-components).\n * Pass the container returned by render(...).\n */\nexport function getCssTextForNode(\n node: ParentNode | Element | DocumentFragment,\n options?: { root?: Document | ShadowRoot },\n): string {\n // Collect tasty-generated class names (t<number>) from the subtree\n const classSet = new Set<string>();\n\n const readClasses = (el: Element) => {\n const cls = el.getAttribute('class');\n if (!cls) return;\n for (const token of cls.split(/\\s+/)) {\n if (/^t\\d+$/.test(token)) classSet.add(token);\n }\n };\n\n // Include node itself if it's an Element\n if ((node as Element).getAttribute) {\n readClasses(node as Element);\n }\n // Walk descendants\n const elements = (node as ParentNode).querySelectorAll\n ? (node as ParentNode).querySelectorAll('[class]')\n : ([] as unknown as NodeListOf<Element>);\n if (elements) elements.forEach(readClasses);\n\n return getGlobalInjector().getCssTextForClasses(classSet, options);\n}\n\n/**\n * Force cleanup of unused rules\n */\nexport function cleanup(root?: Document | ShadowRoot): void {\n return getGlobalInjector().cleanup(root);\n}\n\n/**\n * Check if we're currently running in a test environment\n */\nexport function getIsTestEnvironment(): boolean {\n return isTestEnvironment();\n}\n\n/**\n * Get the global injector instance for debugging\n */\nexport const injector = {\n get instance() {\n return getGlobalInjector();\n },\n};\n\n/**\n * Destroy all resources and clean up\n */\nexport function destroy(root?: Document | ShadowRoot): void {\n return getGlobalInjector().destroy(root);\n}\n\n/**\n * Create a new isolated injector instance\n */\nexport function createInjector(\n config: Partial<StyleInjectorConfig> = {},\n): StyleInjector {\n const defaultConfig = getConfig();\n\n const fullConfig: StyleInjectorConfig = {\n ...defaultConfig,\n // Auto-enable forceTextInjection in test environments\n forceTextInjection: config.forceTextInjection ?? isTestEnvironment(),\n ...config,\n };\n\n return new StyleInjector(fullConfig);\n}\n\n// Re-export types\nexport type {\n StyleInjectorConfig,\n InjectResult,\n DisposeFunction,\n RuleInfo,\n SheetInfo,\n RootRegistry,\n StyleRule,\n KeyframesInfo,\n KeyframesResult,\n KeyframesSteps,\n KeyframesCacheEntry,\n CacheMetrics,\n RawCSSResult,\n PropertyDefinition,\n} from './types';\n\nexport { StyleInjector } from './injector';\nexport { SheetManager } from './sheet-manager';\n"],"mappings":";;;;;;;;AAoBA,SAAgB,kBACd,UACA,SACiD;AACjD,QAAO,mBAAmB,CAAC,kBAAkB,UAAU,QAAQ;;;;;;;AAQjE,SAAgB,SACd,UACA,SACqB;AACrB,QAAO,mBAAm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,KAAK;;;;;AAM1C,SAAgB,uBAAgC;AAC9C,QAAO,mBAAmB;;;;;AAM5B,MAAa,WAAW,EACtB,IAAI,WAAW;AACb,QAAO,mBAAmB;GAE7B;;;;AAKD,SAAgB,QAAQ,MAAoC;AAC1D,QAAO,mBAAmB,CAAC,QAAQ,KAAK;;;;;AAM1C,SAAgB,eACd,SAAuC,EAAE,EAC1B;AAUf,QAAO,IAAI,cAP6B;EACtC,GAHoB,WAAW;EAK/B,oBAAoB,OAAO,sBAAsB,mBAAmB;EACpE,GAAG;EACJ,CAEmC"}
@@ -1,148 +0,0 @@
1
- import { CacheMetrics, GlobalInjectResult, InjectResult, KeyframesResult, KeyframesSteps, PropertyDefinition, RawCSSResult, StyleInjectorConfig } from "./types.js";
2
- import { StyleResult } from "../pipeline/index.js";
3
- import { SheetManager } from "./sheet-manager.js";
4
-
5
- //#region src/injector/injector.d.ts
6
- declare class StyleInjector {
7
- private sheetManager;
8
- private config;
9
- private cleanupScheduled;
10
- private globalRuleCounter;
11
- /** @internal — exposed for debug utilities only */
12
- get _sheetManager(): SheetManager;
13
- constructor(config?: StyleInjectorConfig);
14
- /**
15
- * Allocate a className for a cacheKey without injecting styles yet.
16
- * This allows separating className allocation (render phase) from style injection (insertion phase).
17
- */
18
- allocateClassName(cacheKey: string, options?: {
19
- root?: Document | ShadowRoot;
20
- }): {
21
- className: string;
22
- isNewAllocation: boolean;
23
- };
24
- /**
25
- * Inject styles from StyleResult objects
26
- */
27
- inject(rules: StyleResult[], options?: {
28
- root?: Document | ShadowRoot;
29
- cacheKey?: string;
30
- }): InjectResult;
31
- /**
32
- * Inject global styles (rules without a generated tasty class selector)
33
- * This ensures we don't reserve a tasty class name (t{number}) for global rules,
34
- * which could otherwise collide with element-level styles and break lookups.
35
- */
36
- injectGlobal(rules: StyleResult[], options?: {
37
- root?: Document | ShadowRoot;
38
- }): GlobalInjectResult;
39
- /**
40
- * Inject raw CSS text directly without parsing
41
- * This is a low-overhead alternative to createGlobalStyle for raw CSS
42
- * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking
43
- */
44
- injectRawCSS(css: string, options?: {
45
- root?: Document | ShadowRoot;
46
- }): RawCSSResult;
47
- /**
48
- * Get raw CSS text for SSR
49
- */
50
- getRawCSSText(options?: {
51
- root?: Document | ShadowRoot;
52
- }): string;
53
- /**
54
- * Increment refCount for an already-injected cacheKey and return a dispose.
55
- * Used by useStyles on cache hits (hydration or runtime reuse) where
56
- * the pipeline was skipped but refCount tracking is still needed.
57
- * Returns null if the cacheKey is not found.
58
- */
59
- trackRef(cacheKey: string, options?: {
60
- root?: Document | ShadowRoot;
61
- }): InjectResult | null;
62
- /**
63
- * Dispose of a className
64
- */
65
- private dispose;
66
- /**
67
- * Force bulk cleanup of unused styles
68
- */
69
- cleanup(root?: Document | ShadowRoot): void;
70
- /**
71
- * Get CSS text from all sheets (for SSR)
72
- */
73
- getCssText(options?: {
74
- root?: Document | ShadowRoot;
75
- }): string;
76
- /**
77
- * Get CSS only for the provided tasty classNames (e.g., ["t0","t3"])
78
- */
79
- getCssTextForClasses(classNames: Iterable<string>, options?: {
80
- root?: Document | ShadowRoot;
81
- }): string;
82
- /**
83
- * Get cache performance metrics
84
- */
85
- getMetrics(options?: {
86
- root?: Document | ShadowRoot;
87
- }): CacheMetrics | null;
88
- /**
89
- * Reset cache performance metrics
90
- */
91
- resetMetrics(options?: {
92
- root?: Document | ShadowRoot;
93
- }): void;
94
- /**
95
- * Define a CSS @property custom property.
96
- *
97
- * Accepts tasty token syntax for the property name:
98
- * - `$name` → defines `--name`
99
- * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
100
- * - `--name` → defines `--name` (legacy format)
101
- *
102
- * Example:
103
- * @property --rotation { syntax: "<angle>"; inherits: false; initial-value: 45deg; }
104
- *
105
- * Note: No caching or dispose — this defines a global property.
106
- *
107
- * If the same property is registered with different options, a warning is emitted
108
- * but the original definition is preserved (CSS @property cannot be redefined).
109
- */
110
- property(name: string, options?: PropertyDefinition & {
111
- root?: Document | ShadowRoot;
112
- }): void;
113
- /**
114
- * Check whether a given @property name was already injected by this injector.
115
- *
116
- * Accepts tasty token syntax:
117
- * - `$name` → checks `--name`
118
- * - `#name` → checks `--name-color`
119
- * - `--name` → checks `--name` (legacy format)
120
- */
121
- isPropertyDefined(name: string, options?: {
122
- root?: Document | ShadowRoot;
123
- }): boolean;
124
- /**
125
- * Inject keyframes and return object with toString() and dispose()
126
- *
127
- * Keyframes are cached by content (steps). If the same content is injected
128
- * multiple times with different provided names, the first injected name is reused.
129
- *
130
- * If the same name is provided with different content (collision), a unique
131
- * name is generated to avoid overwriting the existing keyframes.
132
- */
133
- keyframes(steps: KeyframesSteps, nameOrOptions?: string | {
134
- root?: Document | ShadowRoot;
135
- name?: string;
136
- }): KeyframesResult;
137
- /**
138
- * Dispose keyframes
139
- */
140
- private disposeKeyframes;
141
- /**
142
- * Destroy all resources for a root
143
- */
144
- destroy(root?: Document | ShadowRoot): void;
145
- }
146
- //#endregion
147
- export { StyleInjector };
148
- //# sourceMappingURL=injector.d.ts.map
@@ -1,430 +0,0 @@
1
- import { getEffectiveDefinition, normalizePropertyDefinition } from "../properties/index.js";
2
- import { isDevEnv } from "../utils/is-dev-env.js";
3
- import { parseStyle } from "../utils/styles.js";
4
- import { SheetManager } from "./sheet-manager.js";
5
-
6
- //#region src/injector/injector.ts
7
- /**
8
- * Generate sequential class name with format t{number}
9
- */
10
- function generateClassName(counter) {
11
- return `t${counter}`;
12
- }
13
- var StyleInjector = class {
14
- sheetManager;
15
- config;
16
- cleanupScheduled = false;
17
- globalRuleCounter = 0;
18
- /** @internal — exposed for debug utilities only */
19
- get _sheetManager() {
20
- return this.sheetManager;
21
- }
22
- constructor(config = {}) {
23
- this.config = config;
24
- this.sheetManager = new SheetManager(config);
25
- }
26
- /**
27
- * Allocate a className for a cacheKey without injecting styles yet.
28
- * This allows separating className allocation (render phase) from style injection (insertion phase).
29
- */
30
- allocateClassName(cacheKey, options) {
31
- const root = options?.root || document;
32
- const registry = this.sheetManager.getRegistry(root);
33
- if (registry.cacheKeyToClassName.has(cacheKey)) return {
34
- className: registry.cacheKeyToClassName.get(cacheKey),
35
- isNewAllocation: false
36
- };
37
- const className = generateClassName(registry.classCounter++);
38
- const placeholderRuleInfo = {
39
- className,
40
- ruleIndex: -1,
41
- sheetIndex: -1
42
- };
43
- registry.rules.set(className, placeholderRuleInfo);
44
- registry.cacheKeyToClassName.set(cacheKey, className);
45
- return {
46
- className,
47
- isNewAllocation: true
48
- };
49
- }
50
- /**
51
- * Inject styles from StyleResult objects
52
- */
53
- inject(rules, options) {
54
- const root = options?.root || document;
55
- const registry = this.sheetManager.getRegistry(root);
56
- if (rules.length === 0) return {
57
- className: "",
58
- dispose: () => {}
59
- };
60
- const cacheKey = options?.cacheKey;
61
- let className;
62
- let isPreAllocated = false;
63
- if (cacheKey && registry.cacheKeyToClassName.has(cacheKey)) {
64
- className = registry.cacheKeyToClassName.get(cacheKey);
65
- const existingRuleInfo = registry.rules.get(className);
66
- isPreAllocated = existingRuleInfo.ruleIndex === -1 && existingRuleInfo.sheetIndex === -1;
67
- if (!isPreAllocated) {
68
- const currentRefCount = registry.refCounts.get(className) || 0;
69
- registry.refCounts.set(className, currentRefCount + 1);
70
- if (registry.metrics) registry.metrics.hits++;
71
- return {
72
- className,
73
- dispose: () => this.dispose(className, registry)
74
- };
75
- }
76
- } else className = generateClassName(registry.classCounter++);
77
- const rulesToInsert = rules.map((rule) => {
78
- let newSelector = rule.selector;
79
- if (rule.needsClassName) {
80
- const selectorParts = newSelector ? newSelector.split("|||") : [""];
81
- const classPrefix = `.${className}.${className}`;
82
- newSelector = selectorParts.map((part) => {
83
- const classSelector = part ? `${classPrefix}${part}` : classPrefix;
84
- if (rule.rootPrefix) return `${rule.rootPrefix} ${classSelector}`;
85
- return classSelector;
86
- }).join(", ");
87
- }
88
- return {
89
- ...rule,
90
- selector: newSelector,
91
- needsClassName: void 0,
92
- rootPrefix: void 0
93
- };
94
- });
95
- if (this.config.autoPropertyTypes !== false) {
96
- const resolver = registry.propertyTypeResolver;
97
- const defined = registry.injectedProperties;
98
- for (const rule of rulesToInsert) {
99
- if (!rule.declarations) continue;
100
- resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
101
- this.property(name, {
102
- syntax,
103
- inherits: true,
104
- initialValue,
105
- root
106
- });
107
- });
108
- }
109
- }
110
- const ruleInfo = this.sheetManager.insertRule(registry, rulesToInsert, className, root);
111
- if (!ruleInfo) {
112
- if (registry.metrics) registry.metrics.misses++;
113
- return {
114
- className,
115
- dispose: () => {}
116
- };
117
- }
118
- registry.refCounts.set(className, 1);
119
- if (isPreAllocated) registry.rules.set(className, ruleInfo);
120
- else {
121
- registry.rules.set(className, ruleInfo);
122
- if (cacheKey) registry.cacheKeyToClassName.set(cacheKey, className);
123
- }
124
- if (registry.metrics) {
125
- registry.metrics.totalInsertions++;
126
- registry.metrics.misses++;
127
- }
128
- return {
129
- className,
130
- dispose: () => this.dispose(className, registry)
131
- };
132
- }
133
- /**
134
- * Inject global styles (rules without a generated tasty class selector)
135
- * This ensures we don't reserve a tasty class name (t{number}) for global rules,
136
- * which could otherwise collide with element-level styles and break lookups.
137
- */
138
- injectGlobal(rules, options) {
139
- const root = options?.root || document;
140
- const registry = this.sheetManager.getRegistry(root);
141
- if (!rules || rules.length === 0) return { dispose: () => {} };
142
- if (this.config.autoPropertyTypes !== false) {
143
- const resolver = registry.propertyTypeResolver;
144
- const defined = registry.injectedProperties;
145
- for (const rule of rules) {
146
- if (!rule.declarations) continue;
147
- resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
148
- this.property(name, {
149
- syntax,
150
- inherits: true,
151
- initialValue,
152
- root
153
- });
154
- });
155
- }
156
- }
157
- const key = `global:${this.globalRuleCounter++}`;
158
- const info = this.sheetManager.insertGlobalRule(registry, rules, key, root);
159
- if (registry.metrics) registry.metrics.totalInsertions++;
160
- return { dispose: () => {
161
- if (info) this.sheetManager.deleteGlobalRule(registry, key);
162
- } };
163
- }
164
- /**
165
- * Inject raw CSS text directly without parsing
166
- * This is a low-overhead alternative to createGlobalStyle for raw CSS
167
- * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking
168
- */
169
- injectRawCSS(css, options) {
170
- const root = options?.root || document;
171
- return this.sheetManager.injectRawCSS(css, root);
172
- }
173
- /**
174
- * Get raw CSS text for SSR
175
- */
176
- getRawCSSText(options) {
177
- const root = options?.root || document;
178
- return this.sheetManager.getRawCSSText(root);
179
- }
180
- /**
181
- * Increment refCount for an already-injected cacheKey and return a dispose.
182
- * Used by useStyles on cache hits (hydration or runtime reuse) where
183
- * the pipeline was skipped but refCount tracking is still needed.
184
- * Returns null if the cacheKey is not found.
185
- */
186
- trackRef(cacheKey, options) {
187
- const root = options?.root || document;
188
- const registry = this.sheetManager.getRegistry(root);
189
- if (!registry.cacheKeyToClassName.has(cacheKey)) return null;
190
- const className = registry.cacheKeyToClassName.get(cacheKey);
191
- const currentRefCount = registry.refCounts.get(className) || 0;
192
- registry.refCounts.set(className, currentRefCount + 1);
193
- if (registry.metrics) registry.metrics.hits++;
194
- return {
195
- className,
196
- dispose: () => this.dispose(className, registry)
197
- };
198
- }
199
- /**
200
- * Dispose of a className
201
- */
202
- dispose(className, registry) {
203
- const currentRefCount = registry.refCounts.get(className);
204
- if (currentRefCount == null || currentRefCount <= 0) return;
205
- const newRefCount = currentRefCount - 1;
206
- registry.refCounts.set(className, newRefCount);
207
- if (newRefCount === 0) {
208
- if (registry.metrics) registry.metrics.totalUnused++;
209
- this.sheetManager.checkCleanupNeeded(registry);
210
- }
211
- }
212
- /**
213
- * Force bulk cleanup of unused styles
214
- */
215
- cleanup(root) {
216
- const registry = this.sheetManager.getRegistry(root || document);
217
- this.sheetManager.forceCleanup(registry);
218
- }
219
- /**
220
- * Get CSS text from all sheets (for SSR)
221
- */
222
- getCssText(options) {
223
- const root = options?.root || document;
224
- const registry = this.sheetManager.getRegistry(root);
225
- return this.sheetManager.getCssText(registry);
226
- }
227
- /**
228
- * Get CSS only for the provided tasty classNames (e.g., ["t0","t3"])
229
- */
230
- getCssTextForClasses(classNames, options) {
231
- const root = options?.root || document;
232
- const registry = this.sheetManager.getRegistry(root);
233
- const cssChunks = [];
234
- for (const cls of classNames) {
235
- const info = registry.rules.get(cls);
236
- if (info) {
237
- const styleSheet = registry.sheets[info.sheetIndex]?.sheet?.sheet;
238
- if (styleSheet) {
239
- const start = Math.max(0, info.ruleIndex);
240
- const end = Math.min(styleSheet.cssRules.length - 1, info.endRuleIndex ?? info.ruleIndex);
241
- if (start >= 0 && end >= start && start < styleSheet.cssRules.length) for (let i = start; i <= end; i++) {
242
- const rule = styleSheet.cssRules[i];
243
- if (rule) cssChunks.push(rule.cssText);
244
- }
245
- } else if (info.cssText && info.cssText.length) cssChunks.push(...info.cssText);
246
- }
247
- }
248
- return cssChunks.join("\n");
249
- }
250
- /**
251
- * Get cache performance metrics
252
- */
253
- getMetrics(options) {
254
- const root = options?.root || document;
255
- const registry = this.sheetManager.getRegistry(root);
256
- return this.sheetManager.getMetrics(registry);
257
- }
258
- /**
259
- * Reset cache performance metrics
260
- */
261
- resetMetrics(options) {
262
- const root = options?.root || document;
263
- const registry = this.sheetManager.getRegistry(root);
264
- this.sheetManager.resetMetrics(registry);
265
- }
266
- /**
267
- * Define a CSS @property custom property.
268
- *
269
- * Accepts tasty token syntax for the property name:
270
- * - `$name` → defines `--name`
271
- * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
272
- * - `--name` → defines `--name` (legacy format)
273
- *
274
- * Example:
275
- * @property --rotation { syntax: "<angle>"; inherits: false; initial-value: 45deg; }
276
- *
277
- * Note: No caching or dispose — this defines a global property.
278
- *
279
- * If the same property is registered with different options, a warning is emitted
280
- * but the original definition is preserved (CSS @property cannot be redefined).
281
- */
282
- property(name, options) {
283
- const root = options?.root || document;
284
- const registry = this.sheetManager.getRegistry(root);
285
- const effectiveResult = getEffectiveDefinition(name, {
286
- syntax: options?.syntax,
287
- inherits: options?.inherits,
288
- initialValue: options?.initialValue
289
- });
290
- if (!effectiveResult.isValid) {
291
- if (isDevEnv()) console.warn(`[Tasty] property(): ${effectiveResult.error}. Got: "${name}"`);
292
- return;
293
- }
294
- const cssName = effectiveResult.cssName;
295
- const definition = effectiveResult.definition;
296
- const normalizedDef = normalizePropertyDefinition(definition);
297
- if (registry.injectedProperties.get(cssName) !== void 0) return;
298
- const parts = [];
299
- if (definition.syntax != null) {
300
- let syntax = String(definition.syntax).trim();
301
- if (!/^['"]/u.test(syntax)) syntax = `"${syntax}"`;
302
- parts.push(`syntax: ${syntax};`);
303
- }
304
- const inherits = definition.inherits ?? true;
305
- parts.push(`inherits: ${inherits ? "true" : "false"};`);
306
- if (definition.initialValue != null) {
307
- let initialValueStr;
308
- if (typeof definition.initialValue === "number") initialValueStr = String(definition.initialValue);
309
- else initialValueStr = parseStyle(definition.initialValue).output;
310
- parts.push(`initial-value: ${initialValueStr};`);
311
- }
312
- const declarations = parts.join(" ").trim();
313
- const rule = {
314
- selector: `@property ${cssName}`,
315
- declarations
316
- };
317
- if (!this.sheetManager.insertGlobalRule(registry, [rule], `property:${name}`, root)) return;
318
- registry.injectedProperties.set(cssName, normalizedDef);
319
- }
320
- /**
321
- * Check whether a given @property name was already injected by this injector.
322
- *
323
- * Accepts tasty token syntax:
324
- * - `$name` → checks `--name`
325
- * - `#name` → checks `--name-color`
326
- * - `--name` → checks `--name` (legacy format)
327
- */
328
- isPropertyDefined(name, options) {
329
- const root = options?.root || document;
330
- const registry = this.sheetManager.getRegistry(root);
331
- const effectiveResult = getEffectiveDefinition(name, {});
332
- if (!effectiveResult.isValid) return false;
333
- return registry.injectedProperties.has(effectiveResult.cssName);
334
- }
335
- /**
336
- * Inject keyframes and return object with toString() and dispose()
337
- *
338
- * Keyframes are cached by content (steps). If the same content is injected
339
- * multiple times with different provided names, the first injected name is reused.
340
- *
341
- * If the same name is provided with different content (collision), a unique
342
- * name is generated to avoid overwriting the existing keyframes.
343
- */
344
- keyframes(steps, nameOrOptions) {
345
- const isStringName = typeof nameOrOptions === "string";
346
- const providedName = isStringName ? nameOrOptions : nameOrOptions?.name;
347
- const root = isStringName ? document : nameOrOptions?.root || document;
348
- const registry = this.sheetManager.getRegistry(root);
349
- if (Object.keys(steps).length === 0) return {
350
- toString: () => "",
351
- dispose: () => {}
352
- };
353
- const contentHash = JSON.stringify(steps);
354
- const existing = registry.keyframesCache.get(contentHash);
355
- if (existing) {
356
- existing.refCount++;
357
- return {
358
- toString: () => existing.name,
359
- dispose: () => this.disposeKeyframes(contentHash, registry)
360
- };
361
- }
362
- let actualName;
363
- if (providedName) {
364
- const existingContentForName = registry.keyframesNameToContent.get(providedName);
365
- if (existingContentForName && existingContentForName !== contentHash) actualName = `${providedName}-k${registry.keyframesCounter++}`;
366
- else {
367
- actualName = providedName;
368
- registry.keyframesNameToContent.set(providedName, contentHash);
369
- }
370
- } else actualName = `k${registry.keyframesCounter++}`;
371
- const result = this.sheetManager.insertKeyframes(registry, steps, actualName, root);
372
- if (!result) return {
373
- toString: () => "",
374
- dispose: () => {}
375
- };
376
- const { info, declarations } = result;
377
- if (this.config.autoPropertyTypes !== false && declarations) registry.propertyTypeResolver.scanDeclarations(declarations, (name) => registry.injectedProperties.has(name), (name, syntax, initialValue) => {
378
- this.property(name, {
379
- syntax,
380
- inherits: true,
381
- initialValue,
382
- root
383
- });
384
- });
385
- registry.keyframesCache.set(contentHash, {
386
- name: actualName,
387
- refCount: 1,
388
- info
389
- });
390
- if (registry.metrics) {
391
- registry.metrics.totalInsertions++;
392
- registry.metrics.misses++;
393
- }
394
- return {
395
- toString: () => actualName,
396
- dispose: () => this.disposeKeyframes(contentHash, registry)
397
- };
398
- }
399
- /**
400
- * Dispose keyframes
401
- */
402
- disposeKeyframes(contentHash, registry) {
403
- const entry = registry.keyframesCache.get(contentHash);
404
- if (!entry) return;
405
- entry.refCount--;
406
- if (entry.refCount <= 0) {
407
- this.sheetManager.deleteKeyframes(registry, entry.info);
408
- registry.keyframesCache.delete(contentHash);
409
- for (const [name, hash] of registry.keyframesNameToContent.entries()) if (hash === contentHash) {
410
- registry.keyframesNameToContent.delete(name);
411
- break;
412
- }
413
- if (registry.metrics) {
414
- registry.metrics.totalUnused++;
415
- registry.metrics.stylesCleanedUp++;
416
- }
417
- }
418
- }
419
- /**
420
- * Destroy all resources for a root
421
- */
422
- destroy(root) {
423
- const targetRoot = root || document;
424
- this.sheetManager.cleanup(targetRoot);
425
- }
426
- };
427
-
428
- //#endregion
429
- export { StyleInjector };
430
- //# sourceMappingURL=injector.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"injector.js","names":[],"sources":["../../src/injector/injector.ts"],"sourcesContent":["/**\n * Style injector that works with structured style objects\n * Eliminates CSS string parsing for better performance\n */\n\nimport type { StyleResult } from '../pipeline';\nimport {\n getEffectiveDefinition,\n normalizePropertyDefinition,\n} from '../properties';\nimport { isDevEnv } from '../utils/is-dev-env';\nimport type { StyleValue } from '../utils/styles';\nimport { parseStyle } from '../utils/styles';\n\nimport { SheetManager } from './sheet-manager';\nimport type {\n CacheMetrics,\n GlobalInjectResult,\n InjectResult,\n KeyframesResult,\n KeyframesSteps,\n PropertyDefinition,\n RawCSSResult,\n RootRegistry,\n StyleInjectorConfig,\n StyleRule,\n} from './types';\n\n/**\n * Generate sequential class name with format t{number}\n */\nfunction generateClassName(counter: number): string {\n return `t${counter}`;\n}\n\nexport class StyleInjector {\n private sheetManager: SheetManager;\n private config: StyleInjectorConfig;\n private cleanupScheduled = false;\n private globalRuleCounter = 0;\n\n /** @internal — exposed for debug utilities only */\n get _sheetManager(): SheetManager {\n return this.sheetManager;\n }\n\n constructor(config: StyleInjectorConfig = {}) {\n this.config = config;\n this.sheetManager = new SheetManager(config);\n }\n\n /**\n * Allocate a className for a cacheKey without injecting styles yet.\n * This allows separating className allocation (render phase) from style injection (insertion phase).\n */\n allocateClassName(\n cacheKey: string,\n options?: { root?: Document | ShadowRoot },\n ): { className: string; isNewAllocation: boolean } {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n // Check if we can reuse existing className for this cache key\n if (registry.cacheKeyToClassName.has(cacheKey)) {\n const className = registry.cacheKeyToClassName.get(cacheKey)!;\n return {\n className,\n isNewAllocation: false,\n };\n }\n\n // Generate new className and reserve it\n const className = generateClassName(registry.classCounter++);\n\n // Create placeholder RuleInfo to reserve the className\n const placeholderRuleInfo = {\n className,\n ruleIndex: -1, // Placeholder - will be set during actual injection\n sheetIndex: -1, // Placeholder - will be set during actual injection\n };\n\n // Store RuleInfo only once by className, and map cacheKey separately\n registry.rules.set(className, placeholderRuleInfo);\n registry.cacheKeyToClassName.set(cacheKey, className);\n\n return {\n className,\n isNewAllocation: true,\n };\n }\n\n /**\n * Inject styles from StyleResult objects\n */\n inject(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot; cacheKey?: string },\n ): InjectResult {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n if (rules.length === 0) {\n return {\n className: '',\n dispose: () => {\n /* noop */\n },\n };\n }\n\n // Rules are now in StyleRule format directly\n\n // Check if we can reuse based on cache key\n const cacheKey = options?.cacheKey;\n let className: string;\n let isPreAllocated = false;\n\n if (cacheKey && registry.cacheKeyToClassName.has(cacheKey)) {\n // Reuse existing class for this cache key\n className = registry.cacheKeyToClassName.get(cacheKey)!;\n const existingRuleInfo = registry.rules.get(className)!;\n\n // Check if this is a placeholder (pre-allocated but not yet injected)\n isPreAllocated =\n existingRuleInfo.ruleIndex === -1 && existingRuleInfo.sheetIndex === -1;\n\n if (!isPreAllocated) {\n // Already injected - just increment refCount\n const currentRefCount = registry.refCounts.get(className) || 0;\n registry.refCounts.set(className, currentRefCount + 1);\n\n // Update metrics\n if (registry.metrics) {\n registry.metrics.hits++;\n }\n\n return {\n className,\n dispose: () => this.dispose(className, registry),\n };\n }\n } else {\n // Generate new className\n className = generateClassName(registry.classCounter++);\n }\n\n // Process rules: handle needsClassName flag and apply specificity\n const rulesToInsert = rules.map((rule) => {\n let newSelector = rule.selector;\n\n // If rule needs className prepended\n if (rule.needsClassName) {\n // Handle multiple selectors (separated by ||| for OR conditions)\n const selectorParts = newSelector ? newSelector.split('|||') : [''];\n\n const classPrefix = `.${className}.${className}`;\n\n newSelector = selectorParts\n .map((part) => {\n const classSelector = part ? `${classPrefix}${part}` : classPrefix;\n\n // If there's a root prefix, add it before the class selector\n if (rule.rootPrefix) {\n return `${rule.rootPrefix} ${classSelector}`;\n }\n return classSelector;\n })\n .join(', ');\n }\n\n return {\n ...rule,\n selector: newSelector,\n needsClassName: undefined, // Remove the flag after processing\n rootPrefix: undefined, // Remove rootPrefix after processing\n };\n });\n\n // Auto-register @property for custom properties with inferable types.\n // Colors are detected by --*-color name pattern, numeric types by value.\n if (this.config.autoPropertyTypes !== false) {\n const resolver = registry.propertyTypeResolver;\n const defined = registry.injectedProperties;\n for (const rule of rulesToInsert) {\n if (!rule.declarations) continue;\n resolver.scanDeclarations(\n rule.declarations,\n (name) => defined.has(name),\n (name, syntax, initialValue) => {\n this.property(name, {\n syntax,\n inherits: true,\n initialValue,\n root,\n });\n },\n );\n }\n }\n\n // Insert rules using existing sheet manager\n const ruleInfo = this.sheetManager.insertRule(\n registry,\n rulesToInsert,\n className,\n root,\n );\n\n if (!ruleInfo) {\n // Update metrics\n if (registry.metrics) {\n registry.metrics.misses++;\n }\n\n return {\n className,\n dispose: () => {\n /* noop */\n },\n };\n }\n\n // Store in registry\n registry.refCounts.set(className, 1);\n\n if (isPreAllocated) {\n // Update the existing placeholder entry with real rule info\n registry.rules.set(className, ruleInfo);\n // cacheKey mapping already exists from allocation\n } else {\n // Store new entries\n registry.rules.set(className, ruleInfo);\n if (cacheKey) {\n registry.cacheKeyToClassName.set(cacheKey, className);\n }\n }\n\n // Update metrics\n if (registry.metrics) {\n registry.metrics.totalInsertions++;\n registry.metrics.misses++;\n }\n\n return {\n className,\n dispose: () => this.dispose(className, registry),\n };\n }\n\n /**\n * Inject global styles (rules without a generated tasty class selector)\n * This ensures we don't reserve a tasty class name (t{number}) for global rules,\n * which could otherwise collide with element-level styles and break lookups.\n */\n injectGlobal(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot },\n ): GlobalInjectResult {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n if (!rules || rules.length === 0) {\n return {\n dispose: () => {\n /* noop */\n },\n };\n }\n\n // Auto-register @property for custom properties in global rules\n if (this.config.autoPropertyTypes !== false) {\n const resolver = registry.propertyTypeResolver;\n const defined = registry.injectedProperties;\n for (const rule of rules) {\n if (!rule.declarations) continue;\n resolver.scanDeclarations(\n rule.declarations,\n (name) => defined.has(name),\n (name, syntax, initialValue) => {\n this.property(name, {\n syntax,\n inherits: true,\n initialValue,\n root,\n });\n },\n );\n }\n }\n\n // Use a non-tasty identifier to avoid any collisions with .t{number} classes\n const key = `global:${this.globalRuleCounter++}`;\n\n const info = this.sheetManager.insertGlobalRule(\n registry,\n rules as unknown as StyleRule[],\n key,\n root,\n );\n\n if (registry.metrics) {\n registry.metrics.totalInsertions++;\n }\n\n return {\n dispose: () => {\n if (info) this.sheetManager.deleteGlobalRule(registry, key);\n },\n };\n }\n\n /**\n * Inject raw CSS text directly without parsing\n * This is a low-overhead alternative to createGlobalStyle for raw CSS\n * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking\n */\n injectRawCSS(\n css: string,\n options?: { root?: Document | ShadowRoot },\n ): RawCSSResult {\n const root = options?.root || document;\n return this.sheetManager.injectRawCSS(css, root);\n }\n\n /**\n * Get raw CSS text for SSR\n */\n getRawCSSText(options?: { root?: Document | ShadowRoot }): string {\n const root = options?.root || document;\n return this.sheetManager.getRawCSSText(root);\n }\n\n /**\n * Increment refCount for an already-injected cacheKey and return a dispose.\n * Used by useStyles on cache hits (hydration or runtime reuse) where\n * the pipeline was skipped but refCount tracking is still needed.\n * Returns null if the cacheKey is not found.\n */\n trackRef(\n cacheKey: string,\n options?: { root?: Document | ShadowRoot },\n ): InjectResult | null {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n if (!registry.cacheKeyToClassName.has(cacheKey)) return null;\n\n const className = registry.cacheKeyToClassName.get(cacheKey)!;\n const currentRefCount = registry.refCounts.get(className) || 0;\n registry.refCounts.set(className, currentRefCount + 1);\n\n if (registry.metrics) {\n registry.metrics.hits++;\n }\n\n return {\n className,\n dispose: () => this.dispose(className, registry),\n };\n }\n\n /**\n * Dispose of a className\n */\n private dispose(className: string, registry: RootRegistry): void {\n const currentRefCount = registry.refCounts.get(className);\n // Guard against stale double-dispose or mismatched lifecycle\n if (currentRefCount == null || currentRefCount <= 0) {\n return;\n }\n\n const newRefCount = currentRefCount - 1;\n registry.refCounts.set(className, newRefCount);\n\n if (newRefCount === 0) {\n // Update metrics\n if (registry.metrics) {\n registry.metrics.totalUnused++;\n }\n\n // Check if cleanup should be scheduled\n this.sheetManager.checkCleanupNeeded(registry);\n }\n }\n\n /**\n * Force bulk cleanup of unused styles\n */\n cleanup(root?: Document | ShadowRoot): void {\n const registry = this.sheetManager.getRegistry(root || document);\n // Clean up ALL unused rules regardless of batch ratio\n this.sheetManager.forceCleanup(registry);\n }\n\n /**\n * Get CSS text from all sheets (for SSR)\n */\n getCssText(options?: { root?: Document | ShadowRoot }): string {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n return this.sheetManager.getCssText(registry);\n }\n\n /**\n * Get CSS only for the provided tasty classNames (e.g., [\"t0\",\"t3\"])\n */\n getCssTextForClasses(\n classNames: Iterable<string>,\n options?: { root?: Document | ShadowRoot },\n ): string {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n const cssChunks: string[] = [];\n for (const cls of classNames) {\n const info = registry.rules.get(cls);\n if (info) {\n // Always prefer reading from the live stylesheet, since indices can change\n const sheet = registry.sheets[info.sheetIndex];\n const styleSheet = sheet?.sheet?.sheet;\n if (styleSheet) {\n const start = Math.max(0, info.ruleIndex);\n const end = Math.min(\n styleSheet.cssRules.length - 1,\n (info.endRuleIndex as number) ?? info.ruleIndex,\n );\n // Additional validation: ensure indices are valid and in correct order\n if (\n start >= 0 &&\n end >= start &&\n start < styleSheet.cssRules.length\n ) {\n for (let i = start; i <= end; i++) {\n const rule = styleSheet.cssRules[i] as CSSRule | undefined;\n if (rule) cssChunks.push(rule.cssText);\n }\n }\n } else if (info.cssText && info.cssText.length) {\n // Fallback in environments without CSSOM access\n cssChunks.push(...info.cssText);\n }\n }\n }\n return cssChunks.join('\\n');\n }\n\n /**\n * Get cache performance metrics\n */\n getMetrics(options?: { root?: Document | ShadowRoot }): CacheMetrics | null {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n return this.sheetManager.getMetrics(registry);\n }\n\n /**\n * Reset cache performance metrics\n */\n resetMetrics(options?: { root?: Document | ShadowRoot }): void {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n this.sheetManager.resetMetrics(registry);\n }\n\n /**\n * Define a CSS @property custom property.\n *\n * Accepts tasty token syntax for the property name:\n * - `$name` → defines `--name`\n * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')\n * - `--name` → defines `--name` (legacy format)\n *\n * Example:\n * @property --rotation { syntax: \"<angle>\"; inherits: false; initial-value: 45deg; }\n *\n * Note: No caching or dispose — this defines a global property.\n *\n * If the same property is registered with different options, a warning is emitted\n * but the original definition is preserved (CSS @property cannot be redefined).\n */\n property(\n name: string,\n options?: PropertyDefinition & {\n root?: Document | ShadowRoot;\n },\n ): void {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n // Parse the token and get effective definition\n // This handles $name, #name, --name formats and auto-sets syntax for colors\n const userDefinition: PropertyDefinition = {\n syntax: options?.syntax,\n inherits: options?.inherits,\n initialValue: options?.initialValue,\n };\n\n const effectiveResult = getEffectiveDefinition(name, userDefinition);\n\n if (!effectiveResult.isValid) {\n if (isDevEnv()) {\n console.warn(\n `[Tasty] property(): ${effectiveResult.error}. Got: \"${name}\"`,\n );\n }\n return;\n }\n\n const cssName = effectiveResult.cssName;\n const definition = effectiveResult.definition;\n\n // Normalize the definition for comparison\n const normalizedDef = normalizePropertyDefinition(definition);\n\n // Check if already defined\n const existingDef = registry.injectedProperties.get(cssName);\n if (existingDef !== undefined) {\n return;\n }\n\n const parts: string[] = [];\n\n if (definition.syntax != null) {\n let syntax = String(definition.syntax).trim();\n if (!/^['\"]/u.test(syntax)) syntax = `\"${syntax}\"`;\n parts.push(`syntax: ${syntax};`);\n }\n\n // inherits is required by the CSS @property spec - default to true\n const inherits = definition.inherits ?? true;\n parts.push(`inherits: ${inherits ? 'true' : 'false'};`);\n\n if (definition.initialValue != null) {\n let initialValueStr: string;\n if (typeof definition.initialValue === 'number') {\n initialValueStr = String(definition.initialValue);\n } else {\n // Process via tasty parser to resolve custom units/functions\n initialValueStr = parseStyle(\n definition.initialValue as StyleValue,\n ).output;\n }\n parts.push(`initial-value: ${initialValueStr};`);\n }\n\n const declarations = parts.join(' ').trim();\n\n const rule: StyleRule = {\n selector: `@property ${cssName}`,\n declarations,\n } as StyleRule;\n\n // Insert as a global rule; only mark injected when insertion succeeds\n const info = this.sheetManager.insertGlobalRule(\n registry,\n [rule],\n `property:${name}`,\n root,\n );\n\n if (!info) {\n return;\n }\n\n // Track that this property was injected with its normalized definition\n registry.injectedProperties.set(cssName, normalizedDef);\n }\n\n /**\n * Check whether a given @property name was already injected by this injector.\n *\n * Accepts tasty token syntax:\n * - `$name` → checks `--name`\n * - `#name` → checks `--name-color`\n * - `--name` → checks `--name` (legacy format)\n */\n isPropertyDefined(\n name: string,\n options?: { root?: Document | ShadowRoot },\n ): boolean {\n const root = options?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n // Parse the token to get the CSS property name\n const effectiveResult = getEffectiveDefinition(name, {});\n if (!effectiveResult.isValid) {\n return false;\n }\n\n return registry.injectedProperties.has(effectiveResult.cssName);\n }\n\n /**\n * Inject keyframes and return object with toString() and dispose()\n *\n * Keyframes are cached by content (steps). If the same content is injected\n * multiple times with different provided names, the first injected name is reused.\n *\n * If the same name is provided with different content (collision), a unique\n * name is generated to avoid overwriting the existing keyframes.\n */\n keyframes(\n steps: KeyframesSteps,\n nameOrOptions?: string | { root?: Document | ShadowRoot; name?: string },\n ): KeyframesResult {\n // Parse parameters\n const isStringName = typeof nameOrOptions === 'string';\n const providedName = isStringName ? nameOrOptions : nameOrOptions?.name;\n const root = isStringName ? document : nameOrOptions?.root || document;\n const registry = this.sheetManager.getRegistry(root);\n\n if (Object.keys(steps).length === 0) {\n return {\n toString: () => '',\n dispose: () => {\n /* noop */\n },\n };\n }\n\n // Generate content-based cache key (independent of provided name)\n const contentHash = JSON.stringify(steps);\n\n // Check if this exact content is already cached\n const existing = registry.keyframesCache.get(contentHash);\n if (existing) {\n existing.refCount++;\n return {\n toString: () => existing.name,\n dispose: () => this.disposeKeyframes(contentHash, registry),\n };\n }\n\n // Determine the actual name to use\n let actualName: string;\n\n if (providedName) {\n // Check if this name is already used with different content\n const existingContentForName =\n registry.keyframesNameToContent.get(providedName);\n\n if (existingContentForName && existingContentForName !== contentHash) {\n // Name collision: same name, different content\n // Generate a unique name to avoid overwriting\n actualName = `${providedName}-k${registry.keyframesCounter++}`;\n } else {\n // Name is available or used with same content\n actualName = providedName;\n // Track this name -> content mapping\n registry.keyframesNameToContent.set(providedName, contentHash);\n }\n } else {\n // No name provided, generate one\n actualName = `k${registry.keyframesCounter++}`;\n }\n\n // Insert keyframes\n const result = this.sheetManager.insertKeyframes(\n registry,\n steps,\n actualName,\n root,\n );\n if (!result) {\n return {\n toString: () => '',\n dispose: () => {\n /* noop */\n },\n };\n }\n\n const { info, declarations } = result;\n\n // Auto-register @property for custom properties found in keyframe declarations\n if (this.config.autoPropertyTypes !== false && declarations) {\n const resolver = registry.propertyTypeResolver;\n resolver.scanDeclarations(\n declarations,\n (name) => registry.injectedProperties.has(name),\n (name, syntax, initialValue) => {\n this.property(name, {\n syntax,\n inherits: true,\n initialValue,\n root,\n });\n },\n );\n }\n\n // Cache the result by content hash\n registry.keyframesCache.set(contentHash, {\n name: actualName,\n refCount: 1,\n info,\n });\n\n // Update metrics\n if (registry.metrics) {\n registry.metrics.totalInsertions++;\n registry.metrics.misses++;\n }\n\n return {\n toString: () => actualName,\n dispose: () => this.disposeKeyframes(contentHash, registry),\n };\n }\n\n /**\n * Dispose keyframes\n */\n private disposeKeyframes(contentHash: string, registry: RootRegistry): void {\n const entry = registry.keyframesCache.get(contentHash);\n if (!entry) return;\n\n entry.refCount--;\n if (entry.refCount <= 0) {\n // Dispose immediately - keyframes are global and safe to clean up right away\n this.sheetManager.deleteKeyframes(registry, entry.info);\n registry.keyframesCache.delete(contentHash);\n\n // Clean up name-to-content mapping if this name was tracked\n // Find and remove the mapping for this content hash\n for (const [name, hash] of registry.keyframesNameToContent.entries()) {\n if (hash === contentHash) {\n registry.keyframesNameToContent.delete(name);\n break;\n }\n }\n\n // Update metrics\n if (registry.metrics) {\n registry.metrics.totalUnused++;\n registry.metrics.stylesCleanedUp++;\n }\n }\n }\n\n /**\n * Destroy all resources for a root\n */\n destroy(root?: Document | ShadowRoot): void {\n const targetRoot = root || document;\n this.sheetManager.cleanup(targetRoot);\n }\n}\n"],"mappings":";;;;;;;;;AA+BA,SAAS,kBAAkB,SAAyB;AAClD,QAAO,IAAI;;AAGb,IAAa,gBAAb,MAA2B;CACzB,AAAQ;CACR,AAAQ;CACR,AAAQ,mBAAmB;CAC3B,AAAQ,oBAAoB;;CAG5B,IAAI,gBAA8B;AAChC,SAAO,KAAK;;CAGd,YAAY,SAA8B,EAAE,EAAE;AAC5C,OAAK,SAAS;AACd,OAAK,eAAe,IAAI,aAAa,OAAO;;;;;;CAO9C,kBACE,UACA,SACiD;EACjD,MAAM,OAAO,SAAS,QAAQ;EAC9B,MAAM,WAAW,KAAK,aAAa,YAAY,KAAK;AAGpD,MAAI,SAAS,oBAAoB,I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