@tenphi/tasty 0.0.0-snapshot.bae20d4 → 0.0.0-snapshot.bbd36bd

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 (351) hide show
  1. package/README.md +309 -293
  2. package/dist/astro-CeYENy2x.js +301 -0
  3. package/dist/astro-CeYENy2x.js.map +1 -0
  4. package/dist/{ssr/async-storage.js → async-storage-DKK-wTD4.js} +17 -8
  5. package/dist/async-storage-DKK-wTD4.js.map +1 -0
  6. package/dist/babel-DWCsafYw.d.ts +83 -0
  7. package/dist/collector-B3OsM252.js +327 -0
  8. package/dist/collector-B3OsM252.js.map +1 -0
  9. package/dist/collector-BTVXj2hS.d.ts +163 -0
  10. package/dist/config-B3gPdCqd.js +12421 -0
  11. package/dist/config-B3gPdCqd.js.map +1 -0
  12. package/dist/config-LfIDmVHx.d.ts +1363 -0
  13. package/dist/context-CA8YKeMn.js +24 -0
  14. package/dist/context-CA8YKeMn.js.map +1 -0
  15. package/dist/core/index.d.ts +5 -34
  16. package/dist/core/index.js +6 -27
  17. package/dist/core-DGm0CFHP.js +1732 -0
  18. package/dist/core-DGm0CFHP.js.map +1 -0
  19. package/dist/css-resources-Cyl_axbI.js +149 -0
  20. package/dist/css-resources-Cyl_axbI.js.map +1 -0
  21. package/dist/{zero/extractor.js → css-writer-Bgowobbx.js} +188 -13
  22. package/dist/css-writer-Bgowobbx.js.map +1 -0
  23. package/dist/{ssr/format-global-rules.js → format-global-rules-DklyaXv-.js} +3 -3
  24. package/dist/format-global-rules-DklyaXv-.js.map +1 -0
  25. package/dist/{ssr/format-rules.js → format-rules-XRw9u7d4.js} +41 -7
  26. package/dist/format-rules-XRw9u7d4.js.map +1 -0
  27. package/dist/hydrate-CNOmZprz.js +37 -0
  28. package/dist/hydrate-CNOmZprz.js.map +1 -0
  29. package/dist/index-Bm9ltvdH.d.ts +1933 -0
  30. package/dist/index-BmogEzTo.d.ts +1575 -0
  31. package/dist/index.d.ts +5 -49
  32. package/dist/index.js +921 -33
  33. package/dist/index.js.map +1 -0
  34. package/dist/keyframes-DE-OE76F.js +535 -0
  35. package/dist/keyframes-DE-OE76F.js.map +1 -0
  36. package/dist/{utils/merge-styles.d.ts → merge-styles-BcLl1u_d.d.ts} +3 -3
  37. package/dist/{utils/merge-styles.js → merge-styles-DuoZEsm9.js} +4 -6
  38. package/dist/merge-styles-DuoZEsm9.js.map +1 -0
  39. package/dist/{utils/resolve-recipes.js → resolve-recipes-H9NqOQuP.js} +5 -8
  40. package/dist/resolve-recipes-H9NqOQuP.js.map +1 -0
  41. package/dist/ssr/astro-client.d.ts +1 -0
  42. package/dist/ssr/astro-client.js +19 -0
  43. package/dist/ssr/astro-client.js.map +1 -0
  44. package/dist/ssr/astro-middleware-extract-static.d.ts +11 -0
  45. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  46. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  47. package/dist/ssr/astro-middleware-extract.d.ts +11 -0
  48. package/dist/ssr/astro-middleware-extract.js +9 -0
  49. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  50. package/dist/ssr/astro-middleware-static.d.ts +18 -0
  51. package/dist/ssr/astro-middleware-static.js +18 -0
  52. package/dist/ssr/astro-middleware-static.js.map +1 -0
  53. package/dist/ssr/astro-middleware.d.ts +19 -0
  54. package/dist/ssr/astro-middleware.js +19 -0
  55. package/dist/ssr/astro-middleware.js.map +1 -0
  56. package/dist/ssr/astro.d.ts +117 -11
  57. package/dist/ssr/astro.js +2 -65
  58. package/dist/ssr/index.d.ts +37 -5
  59. package/dist/ssr/index.js +7 -9
  60. package/dist/ssr/index.js.map +1 -1
  61. package/dist/ssr/next-config.d.ts +66 -0
  62. package/dist/ssr/next-config.js +115 -0
  63. package/dist/ssr/next-config.js.map +1 -0
  64. package/dist/ssr/next.d.ts +14 -7
  65. package/dist/ssr/next.js +40 -20
  66. package/dist/ssr/next.js.map +1 -1
  67. package/dist/ssr-collector-ref-COs_ioWl.js +29 -0
  68. package/dist/ssr-collector-ref-COs_ioWl.js.map +1 -0
  69. package/dist/static/index.d.ts +91 -5
  70. package/dist/static/index.js +49 -4
  71. package/dist/static/index.js.map +1 -0
  72. package/dist/static/inject.d.ts +5 -0
  73. package/dist/static/inject.js +17 -0
  74. package/dist/static/inject.js.map +1 -0
  75. package/dist/zero/babel.d.ts +2 -155
  76. package/dist/zero/babel.js +183 -51
  77. package/dist/zero/babel.js.map +1 -1
  78. package/dist/zero/index.d.ts +81 -3
  79. package/dist/zero/index.js +2 -4
  80. package/dist/zero/next.d.ts +13 -1
  81. package/dist/zero/next.js +6 -5
  82. package/dist/zero/next.js.map +1 -1
  83. package/docs/README.md +39 -0
  84. package/docs/adoption.md +72 -35
  85. package/docs/ai-agents.md +224 -0
  86. package/docs/comparison.md +88 -53
  87. package/docs/configuration.md +623 -63
  88. package/docs/debug.md +172 -342
  89. package/docs/design-system.md +83 -29
  90. package/docs/dsl.md +614 -133
  91. package/docs/getting-started.md +80 -43
  92. package/docs/injector.md +159 -53
  93. package/docs/methodology.md +178 -31
  94. package/docs/migration-v3.md +285 -0
  95. package/docs/pipeline.md +741 -0
  96. package/docs/plugins.md +353 -0
  97. package/docs/react-api.md +681 -0
  98. package/docs/runtime-benchmarks.md +351 -0
  99. package/docs/ssr.md +356 -128
  100. package/docs/styles.md +103 -32
  101. package/docs/tasty-static.md +227 -65
  102. package/package.json +83 -22
  103. package/tasty.config.ts +6 -0
  104. package/dist/_virtual/_rolldown/runtime.js +0 -8
  105. package/dist/chunks/cacheKey.js +0 -78
  106. package/dist/chunks/cacheKey.js.map +0 -1
  107. package/dist/chunks/definitions.d.ts +0 -37
  108. package/dist/chunks/definitions.js +0 -259
  109. package/dist/chunks/definitions.js.map +0 -1
  110. package/dist/chunks/renderChunk.js +0 -60
  111. package/dist/chunks/renderChunk.js.map +0 -1
  112. package/dist/config.d.ts +0 -323
  113. package/dist/config.js +0 -465
  114. package/dist/config.js.map +0 -1
  115. package/dist/debug.d.ts +0 -204
  116. package/dist/debug.js +0 -733
  117. package/dist/debug.js.map +0 -1
  118. package/dist/hooks/useGlobalStyles.d.ts +0 -30
  119. package/dist/hooks/useGlobalStyles.js +0 -83
  120. package/dist/hooks/useGlobalStyles.js.map +0 -1
  121. package/dist/hooks/useKeyframes.d.ts +0 -56
  122. package/dist/hooks/useKeyframes.js +0 -69
  123. package/dist/hooks/useKeyframes.js.map +0 -1
  124. package/dist/hooks/useProperty.d.ts +0 -79
  125. package/dist/hooks/useProperty.js +0 -114
  126. package/dist/hooks/useProperty.js.map +0 -1
  127. package/dist/hooks/useRawCSS.d.ts +0 -53
  128. package/dist/hooks/useRawCSS.js +0 -40
  129. package/dist/hooks/useRawCSS.js.map +0 -1
  130. package/dist/hooks/useStyles.d.ts +0 -45
  131. package/dist/hooks/useStyles.js +0 -249
  132. package/dist/hooks/useStyles.js.map +0 -1
  133. package/dist/injector/index.d.ts +0 -165
  134. package/dist/injector/index.js +0 -162
  135. package/dist/injector/index.js.map +0 -1
  136. package/dist/injector/injector.d.ts +0 -148
  137. package/dist/injector/injector.js +0 -430
  138. package/dist/injector/injector.js.map +0 -1
  139. package/dist/injector/sheet-manager.d.ts +0 -136
  140. package/dist/injector/sheet-manager.js +0 -729
  141. package/dist/injector/sheet-manager.js.map +0 -1
  142. package/dist/injector/types.d.ts +0 -144
  143. package/dist/keyframes/index.js +0 -206
  144. package/dist/keyframes/index.js.map +0 -1
  145. package/dist/parser/classify.js +0 -320
  146. package/dist/parser/classify.js.map +0 -1
  147. package/dist/parser/const.js +0 -33
  148. package/dist/parser/const.js.map +0 -1
  149. package/dist/parser/lru.js +0 -109
  150. package/dist/parser/lru.js.map +0 -1
  151. package/dist/parser/parser.d.ts +0 -25
  152. package/dist/parser/parser.js +0 -116
  153. package/dist/parser/parser.js.map +0 -1
  154. package/dist/parser/tokenizer.js +0 -69
  155. package/dist/parser/tokenizer.js.map +0 -1
  156. package/dist/parser/types.d.ts +0 -51
  157. package/dist/parser/types.js +0 -46
  158. package/dist/parser/types.js.map +0 -1
  159. package/dist/pipeline/conditions.d.ts +0 -134
  160. package/dist/pipeline/conditions.js +0 -406
  161. package/dist/pipeline/conditions.js.map +0 -1
  162. package/dist/pipeline/exclusive.js +0 -231
  163. package/dist/pipeline/exclusive.js.map +0 -1
  164. package/dist/pipeline/index.d.ts +0 -53
  165. package/dist/pipeline/index.js +0 -670
  166. package/dist/pipeline/index.js.map +0 -1
  167. package/dist/pipeline/materialize.js +0 -1105
  168. package/dist/pipeline/materialize.js.map +0 -1
  169. package/dist/pipeline/parseStateKey.d.ts +0 -15
  170. package/dist/pipeline/parseStateKey.js +0 -447
  171. package/dist/pipeline/parseStateKey.js.map +0 -1
  172. package/dist/pipeline/simplify.js +0 -516
  173. package/dist/pipeline/simplify.js.map +0 -1
  174. package/dist/pipeline/warnings.js +0 -18
  175. package/dist/pipeline/warnings.js.map +0 -1
  176. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  177. package/dist/plugins/okhsl-plugin.js +0 -98
  178. package/dist/plugins/okhsl-plugin.js.map +0 -1
  179. package/dist/plugins/types.d.ts +0 -76
  180. package/dist/properties/index.js +0 -223
  181. package/dist/properties/index.js.map +0 -1
  182. package/dist/properties/property-type-resolver.d.ts +0 -24
  183. package/dist/properties/property-type-resolver.js +0 -91
  184. package/dist/properties/property-type-resolver.js.map +0 -1
  185. package/dist/ssr/astro.js.map +0 -1
  186. package/dist/ssr/async-storage.d.ts +0 -17
  187. package/dist/ssr/async-storage.js.map +0 -1
  188. package/dist/ssr/collect-auto-properties.js +0 -40
  189. package/dist/ssr/collect-auto-properties.js.map +0 -1
  190. package/dist/ssr/collector.d.ts +0 -85
  191. package/dist/ssr/collector.js +0 -183
  192. package/dist/ssr/collector.js.map +0 -1
  193. package/dist/ssr/context.d.ts +0 -8
  194. package/dist/ssr/context.js +0 -14
  195. package/dist/ssr/context.js.map +0 -1
  196. package/dist/ssr/format-global-rules.js.map +0 -1
  197. package/dist/ssr/format-keyframes.js +0 -70
  198. package/dist/ssr/format-keyframes.js.map +0 -1
  199. package/dist/ssr/format-property.js +0 -50
  200. package/dist/ssr/format-property.js.map +0 -1
  201. package/dist/ssr/format-rules.js.map +0 -1
  202. package/dist/ssr/hydrate.d.ts +0 -22
  203. package/dist/ssr/hydrate.js +0 -50
  204. package/dist/ssr/hydrate.js.map +0 -1
  205. package/dist/ssr/ssr-collector-ref.js +0 -12
  206. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  207. package/dist/states/index.d.ts +0 -49
  208. package/dist/states/index.js +0 -169
  209. package/dist/states/index.js.map +0 -1
  210. package/dist/static/tastyStatic.d.ts +0 -46
  211. package/dist/static/tastyStatic.js +0 -31
  212. package/dist/static/tastyStatic.js.map +0 -1
  213. package/dist/static/types.d.ts +0 -49
  214. package/dist/static/types.js +0 -24
  215. package/dist/static/types.js.map +0 -1
  216. package/dist/styles/align.d.ts +0 -15
  217. package/dist/styles/align.js +0 -14
  218. package/dist/styles/align.js.map +0 -1
  219. package/dist/styles/border.d.ts +0 -25
  220. package/dist/styles/border.js +0 -114
  221. package/dist/styles/border.js.map +0 -1
  222. package/dist/styles/color.d.ts +0 -14
  223. package/dist/styles/color.js +0 -27
  224. package/dist/styles/color.js.map +0 -1
  225. package/dist/styles/createStyle.js +0 -80
  226. package/dist/styles/createStyle.js.map +0 -1
  227. package/dist/styles/dimension.js +0 -97
  228. package/dist/styles/dimension.js.map +0 -1
  229. package/dist/styles/display.d.ts +0 -37
  230. package/dist/styles/display.js +0 -67
  231. package/dist/styles/display.js.map +0 -1
  232. package/dist/styles/fade.d.ts +0 -15
  233. package/dist/styles/fade.js +0 -58
  234. package/dist/styles/fade.js.map +0 -1
  235. package/dist/styles/fill.d.ts +0 -42
  236. package/dist/styles/fill.js +0 -52
  237. package/dist/styles/fill.js.map +0 -1
  238. package/dist/styles/flow.d.ts +0 -16
  239. package/dist/styles/flow.js +0 -12
  240. package/dist/styles/flow.js.map +0 -1
  241. package/dist/styles/gap.d.ts +0 -31
  242. package/dist/styles/gap.js +0 -37
  243. package/dist/styles/gap.js.map +0 -1
  244. package/dist/styles/height.d.ts +0 -17
  245. package/dist/styles/height.js +0 -20
  246. package/dist/styles/height.js.map +0 -1
  247. package/dist/styles/index.d.ts +0 -2
  248. package/dist/styles/index.js +0 -9
  249. package/dist/styles/index.js.map +0 -1
  250. package/dist/styles/inset.d.ts +0 -52
  251. package/dist/styles/inset.js +0 -150
  252. package/dist/styles/inset.js.map +0 -1
  253. package/dist/styles/justify.d.ts +0 -15
  254. package/dist/styles/justify.js +0 -14
  255. package/dist/styles/justify.js.map +0 -1
  256. package/dist/styles/list.d.ts +0 -16
  257. package/dist/styles/list.js +0 -98
  258. package/dist/styles/list.js.map +0 -1
  259. package/dist/styles/margin.d.ts +0 -24
  260. package/dist/styles/margin.js +0 -104
  261. package/dist/styles/margin.js.map +0 -1
  262. package/dist/styles/outline.d.ts +0 -29
  263. package/dist/styles/outline.js +0 -65
  264. package/dist/styles/outline.js.map +0 -1
  265. package/dist/styles/padding.d.ts +0 -24
  266. package/dist/styles/padding.js +0 -104
  267. package/dist/styles/padding.js.map +0 -1
  268. package/dist/styles/predefined.d.ts +0 -71
  269. package/dist/styles/predefined.js +0 -238
  270. package/dist/styles/predefined.js.map +0 -1
  271. package/dist/styles/preset.d.ts +0 -47
  272. package/dist/styles/preset.js +0 -126
  273. package/dist/styles/preset.js.map +0 -1
  274. package/dist/styles/radius.d.ts +0 -14
  275. package/dist/styles/radius.js +0 -51
  276. package/dist/styles/radius.js.map +0 -1
  277. package/dist/styles/scrollbar.d.ts +0 -25
  278. package/dist/styles/scrollbar.js +0 -48
  279. package/dist/styles/scrollbar.js.map +0 -1
  280. package/dist/styles/shadow.d.ts +0 -14
  281. package/dist/styles/shadow.js +0 -24
  282. package/dist/styles/shadow.js.map +0 -1
  283. package/dist/styles/transition.d.ts +0 -14
  284. package/dist/styles/transition.js +0 -158
  285. package/dist/styles/transition.js.map +0 -1
  286. package/dist/styles/types.d.ts +0 -508
  287. package/dist/styles/width.d.ts +0 -17
  288. package/dist/styles/width.js +0 -20
  289. package/dist/styles/width.js.map +0 -1
  290. package/dist/tasty.d.ts +0 -981
  291. package/dist/tasty.js +0 -219
  292. package/dist/tasty.js.map +0 -1
  293. package/dist/types.d.ts +0 -184
  294. package/dist/utils/cache-wrapper.js +0 -22
  295. package/dist/utils/cache-wrapper.js.map +0 -1
  296. package/dist/utils/case-converter.js +0 -8
  297. package/dist/utils/case-converter.js.map +0 -1
  298. package/dist/utils/color-math.d.ts +0 -45
  299. package/dist/utils/color-math.js +0 -749
  300. package/dist/utils/color-math.js.map +0 -1
  301. package/dist/utils/color-space.d.ts +0 -5
  302. package/dist/utils/color-space.js +0 -228
  303. package/dist/utils/color-space.js.map +0 -1
  304. package/dist/utils/colors.d.ts +0 -5
  305. package/dist/utils/colors.js +0 -11
  306. package/dist/utils/colors.js.map +0 -1
  307. package/dist/utils/css-types.d.ts +0 -7
  308. package/dist/utils/dotize.d.ts +0 -26
  309. package/dist/utils/dotize.js +0 -122
  310. package/dist/utils/dotize.js.map +0 -1
  311. package/dist/utils/filter-base-props.d.ts +0 -15
  312. package/dist/utils/filter-base-props.js +0 -45
  313. package/dist/utils/filter-base-props.js.map +0 -1
  314. package/dist/utils/get-display-name.d.ts +0 -7
  315. package/dist/utils/get-display-name.js +0 -10
  316. package/dist/utils/get-display-name.js.map +0 -1
  317. package/dist/utils/has-keys.js +0 -13
  318. package/dist/utils/has-keys.js.map +0 -1
  319. package/dist/utils/is-dev-env.js +0 -19
  320. package/dist/utils/is-dev-env.js.map +0 -1
  321. package/dist/utils/is-valid-element-type.js +0 -15
  322. package/dist/utils/is-valid-element-type.js.map +0 -1
  323. package/dist/utils/merge-styles.js.map +0 -1
  324. package/dist/utils/mod-attrs.d.ts +0 -8
  325. package/dist/utils/mod-attrs.js +0 -21
  326. package/dist/utils/mod-attrs.js.map +0 -1
  327. package/dist/utils/process-tokens.d.ts +0 -21
  328. package/dist/utils/process-tokens.js +0 -91
  329. package/dist/utils/process-tokens.js.map +0 -1
  330. package/dist/utils/resolve-recipes.d.ts +0 -17
  331. package/dist/utils/resolve-recipes.js.map +0 -1
  332. package/dist/utils/selector-transform.js +0 -32
  333. package/dist/utils/selector-transform.js.map +0 -1
  334. package/dist/utils/string.js +0 -8
  335. package/dist/utils/string.js.map +0 -1
  336. package/dist/utils/styles.d.ts +0 -101
  337. package/dist/utils/styles.js +0 -223
  338. package/dist/utils/styles.js.map +0 -1
  339. package/dist/utils/typography.d.ts +0 -47
  340. package/dist/utils/typography.js +0 -43
  341. package/dist/utils/typography.js.map +0 -1
  342. package/dist/utils/warnings.d.ts +0 -16
  343. package/dist/utils/warnings.js +0 -16
  344. package/dist/utils/warnings.js.map +0 -1
  345. package/dist/zero/css-writer.d.ts +0 -45
  346. package/dist/zero/css-writer.js +0 -74
  347. package/dist/zero/css-writer.js.map +0 -1
  348. package/dist/zero/extractor.d.ts +0 -24
  349. package/dist/zero/extractor.js.map +0 -1
  350. package/docs/PIPELINE.md +0 -519
  351. package/docs/runtime.md +0 -291
@@ -1,53 +0,0 @@
1
- //#region src/hooks/useRawCSS.d.ts
2
- interface UseRawCSSOptions {
3
- root?: Document | ShadowRoot;
4
- }
5
- /**
6
- * Hook to inject raw CSS text directly without parsing.
7
- * This is a low-overhead alternative for injecting global CSS that doesn't need tasty processing.
8
- *
9
- * The CSS is inserted into a separate style element (data-tasty-raw) to avoid conflicts
10
- * with tasty's chunked style sheets.
11
- *
12
- * @example Static CSS string
13
- * ```tsx
14
- * function GlobalStyles() {
15
- * useRawCSS(`
16
- * body {
17
- * margin: 0;
18
- * padding: 0;
19
- * font-family: sans-serif;
20
- * }
21
- * `);
22
- *
23
- * return null;
24
- * }
25
- * ```
26
- *
27
- * @example Factory function with dependencies (like useMemo)
28
- * ```tsx
29
- * function ThemeStyles({ theme }: { theme: 'light' | 'dark' }) {
30
- * useRawCSS(() => `
31
- * :root {
32
- * --bg-color: ${theme === 'dark' ? '#1a1a1a' : '#ffffff'};
33
- * --text-color: ${theme === 'dark' ? '#ffffff' : '#1a1a1a'};
34
- * }
35
- * `, [theme]);
36
- *
37
- * return null;
38
- * }
39
- * ```
40
- *
41
- * @example With options
42
- * ```tsx
43
- * function ShadowStyles({ shadowRoot }) {
44
- * useRawCSS(() => `.scoped { color: red; }`, [], { root: shadowRoot });
45
- * return null;
46
- * }
47
- * ```
48
- */
49
- declare function useRawCSS(css: string, options?: UseRawCSSOptions): void;
50
- declare function useRawCSS(factory: () => string, deps: readonly unknown[], options?: UseRawCSSOptions): void;
51
- //#endregion
52
- export { useRawCSS };
53
- //# sourceMappingURL=useRawCSS.d.ts.map
@@ -1,40 +0,0 @@
1
- import { injectRawCSS } from "../injector/index.js";
2
- import { TastySSRContext } from "../ssr/context.js";
3
- import { getRegisteredSSRCollector } from "../ssr/ssr-collector-ref.js";
4
- import { useContext, useInsertionEffect, useMemo, useRef } from "react";
5
-
6
- //#region src/hooks/useRawCSS.ts
7
- function resolveSSRCollector(reactContext) {
8
- if (reactContext) return reactContext;
9
- return getRegisteredSSRCollector();
10
- }
11
- function useRawCSS(cssOrFactory, depsOrOptions, options) {
12
- const ssrCollector = resolveSSRCollector(useContext(TastySSRContext));
13
- const isFactory = typeof cssOrFactory === "function";
14
- const deps = isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : void 0;
15
- const opts = isFactory ? options : depsOrOptions;
16
- const css = useMemo(() => isFactory ? cssOrFactory() : cssOrFactory, isFactory ? deps ?? [] : [cssOrFactory]);
17
- useMemo(() => {
18
- if (!ssrCollector || !css.trim()) return;
19
- const key = `raw:${css.length}:${css.slice(0, 64)}`;
20
- ssrCollector.collectRawCSS(key, css);
21
- }, [ssrCollector, css]);
22
- const disposeRef = useRef(null);
23
- useInsertionEffect(() => {
24
- disposeRef.current?.();
25
- if (!css.trim()) {
26
- disposeRef.current = null;
27
- return;
28
- }
29
- const { dispose } = injectRawCSS(css, opts);
30
- disposeRef.current = dispose;
31
- return () => {
32
- disposeRef.current?.();
33
- disposeRef.current = null;
34
- };
35
- }, [css, opts?.root]);
36
- }
37
-
38
- //#endregion
39
- export { useRawCSS };
40
- //# sourceMappingURL=useRawCSS.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useRawCSS.js","names":[],"sources":["../../src/hooks/useRawCSS.ts"],"sourcesContent":["import { useContext, useInsertionEffect, useMemo, useRef } from 'react';\n\nimport { injectRawCSS } from '../injector';\nimport type { ServerStyleCollector } from '../ssr/collector';\nimport { TastySSRContext } from '../ssr/context';\nimport { getRegisteredSSRCollector } from '../ssr/ssr-collector-ref';\n\ninterface UseRawCSSOptions {\n root?: Document | ShadowRoot;\n}\n\nfunction resolveSSRCollector(\n reactContext: ServerStyleCollector | null,\n): ServerStyleCollector | null {\n if (reactContext) return reactContext;\n return getRegisteredSSRCollector();\n}\n\n/**\n * Hook to inject raw CSS text directly without parsing.\n * This is a low-overhead alternative for injecting global CSS that doesn't need tasty processing.\n *\n * The CSS is inserted into a separate style element (data-tasty-raw) to avoid conflicts\n * with tasty's chunked style sheets.\n *\n * @example Static CSS string\n * ```tsx\n * function GlobalStyles() {\n * useRawCSS(`\n * body {\n * margin: 0;\n * padding: 0;\n * font-family: sans-serif;\n * }\n * `);\n *\n * return null;\n * }\n * ```\n *\n * @example Factory function with dependencies (like useMemo)\n * ```tsx\n * function ThemeStyles({ theme }: { theme: 'light' | 'dark' }) {\n * useRawCSS(() => `\n * :root {\n * --bg-color: ${theme === 'dark' ? '#1a1a1a' : '#ffffff'};\n * --text-color: ${theme === 'dark' ? '#ffffff' : '#1a1a1a'};\n * }\n * `, [theme]);\n *\n * return null;\n * }\n * ```\n *\n * @example With options\n * ```tsx\n * function ShadowStyles({ shadowRoot }) {\n * useRawCSS(() => `.scoped { color: red; }`, [], { root: shadowRoot });\n * return null;\n * }\n * ```\n */\n\n// Overload 1: Static CSS string\nexport function useRawCSS(css: string, options?: UseRawCSSOptions): void;\n\n// Overload 2: Factory function with dependencies\nexport function useRawCSS(\n factory: () => string,\n deps: readonly unknown[],\n options?: UseRawCSSOptions,\n): void;\n\n// Implementation\nexport function useRawCSS(\n cssOrFactory: string | (() => string),\n depsOrOptions?: readonly unknown[] | UseRawCSSOptions,\n options?: UseRawCSSOptions,\n): void {\n const ssrContextValue = useContext(TastySSRContext);\n const ssrCollector = resolveSSRCollector(ssrContextValue);\n\n // Detect which overload is being used\n const isFactory = typeof cssOrFactory === 'function';\n\n // Parse arguments based on overload\n const deps =\n isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : undefined;\n const opts = isFactory\n ? options\n : (depsOrOptions as UseRawCSSOptions | undefined);\n\n // Memoize CSS - for factory functions, use provided deps; for strings, use the string itself\n const css = useMemo(\n () =>\n isFactory ? (cssOrFactory as () => string)() : (cssOrFactory as string),\n\n isFactory ? (deps ?? []) : [cssOrFactory],\n );\n\n // SSR path: collect raw CSS during render\n useMemo(() => {\n if (!ssrCollector || !css.trim()) return;\n\n const key = `raw:${css.length}:${css.slice(0, 64)}`;\n ssrCollector.collectRawCSS(key, css);\n }, [ssrCollector, css]);\n\n const disposeRef = useRef<(() => void) | null>(null);\n\n // Client path: inject via DOM\n useInsertionEffect(() => {\n disposeRef.current?.();\n\n if (!css.trim()) {\n disposeRef.current = null;\n return;\n }\n\n const { dispose } = injectRawCSS(css, opts);\n disposeRef.current = dispose;\n\n return () => {\n disposeRef.current?.();\n disposeRef.current = null;\n };\n }, [css, opts?.root]);\n}\n"],"mappings":";;;;;;AAWA,SAAS,oBACP,cAC6B;AAC7B,KAAI,aAAc,QAAO;AACzB,QAAO,2BAA2B;;AA2DpC,SAAgB,UACd,cACA,eACA,SACM;CAEN,MAAM,eAAe,oBADG,WAAW,gBAAgB,CACM;CAGzD,MAAM,YAAY,OAAO,iBAAiB;CAG1C,MAAM,OACJ,aAAa,MAAM,QAAQ,cAAc,GAAG,gBAAgB;CAC9D,MAAM,OAAO,YACT,UACC;CAGL,MAAM,MAAM,cAER,YAAa,cAA+B,GAAI,cAElD,YAAa,QAAQ,EAAE,GAAI,CAAC,aAAa,CAC1C;AAGD,eAAc;AACZ,MAAI,CAAC,gBAAgB,CAAC,IAAI,MAAM,CAAE;EAElC,MAAM,MAAM,OAAO,IAAI,OAAO,GAAG,IAAI,MAAM,GAAG,GAAG;AACjD,eAAa,cAAc,KAAK,IAAI;IACnC,CAAC,cAAc,IAAI,CAAC;CAEvB,MAAM,aAAa,OAA4B,KAAK;AAGpD,0BAAyB;AACvB,aAAW,WAAW;AAEtB,MAAI,CAAC,IAAI,MAAM,EAAE;AACf,cAAW,UAAU;AACrB;;EAGF,MAAM,EAAE,YAAY,aAAa,KAAK,KAAK;AAC3C,aAAW,UAAU;AAErB,eAAa;AACX,cAAW,WAAW;AACtB,cAAW,UAAU;;IAEtB,CAAC,KAAK,MAAM,KAAK,CAAC"}
@@ -1,45 +0,0 @@
1
- import { Styles } from "../styles/types.js";
2
-
3
- //#region src/hooks/useStyles.d.ts
4
- /**
5
- * Tasty styles object to generate CSS classes for.
6
- * Can be undefined or empty object for no styles.
7
- */
8
- type UseStylesOptions = Styles | undefined;
9
- interface UseStylesResult {
10
- /**
11
- * Generated className(s) to apply to the element.
12
- * Can be empty string if no styles are provided.
13
- * With chunking enabled, may contain multiple space-separated class names.
14
- */
15
- className: string;
16
- }
17
- /**
18
- * Hook to generate CSS classes from Tasty styles.
19
- * Handles style rendering, className allocation, and CSS injection.
20
- *
21
- * SSR-aware: when a ServerStyleCollector is available (via React context
22
- * or AsyncLocalStorage), CSS is collected during the render phase instead
23
- * of being injected into the DOM. useInsertionEffect does not run on the
24
- * server, so the collector path is the only active path during SSR.
25
- *
26
- * Uses chunking to split styles into logical groups for better caching
27
- * and CSS reuse across components.
28
- *
29
- * @example
30
- * ```tsx
31
- * function MyComponent() {
32
- * const { className } = useStyles({
33
- * padding: '2x',
34
- * fill: '#purple',
35
- * radius: '1r',
36
- * });
37
- *
38
- * return <div className={className}>Styled content</div>;
39
- * }
40
- * ```
41
- */
42
- declare function useStyles(styles: UseStylesOptions): UseStylesResult;
43
- //#endregion
44
- export { UseStylesOptions, UseStylesResult, useStyles };
45
- //# sourceMappingURL=useStyles.d.ts.map
@@ -1,249 +0,0 @@
1
- import { extractLocalProperties, hasLocalProperties } from "../properties/index.js";
2
- import { stringifyStyles } from "../utils/styles.js";
3
- import { getConfig, getGlobalKeyframes, hasGlobalKeyframes } from "../config.js";
4
- import { CHUNK_NAMES, categorizeStyleKeys } from "../chunks/definitions.js";
5
- import { generateChunkCacheKey } from "../chunks/cacheKey.js";
6
- import { renderStylesForChunk } from "../chunks/renderChunk.js";
7
- import { allocateClassName, inject, keyframes, property } from "../injector/index.js";
8
- import { resolveRecipes } from "../utils/resolve-recipes.js";
9
- import { extractAnimationNamesFromStyles, extractLocalKeyframes, filterUsedKeyframes, hasLocalKeyframes, mergeKeyframes, replaceAnimationNames } from "../keyframes/index.js";
10
- import { formatPropertyCSS } from "../ssr/format-property.js";
11
- import { collectAutoInferredProperties } from "../ssr/collect-auto-properties.js";
12
- import { TastySSRContext } from "../ssr/context.js";
13
- import { formatKeyframesCSS } from "../ssr/format-keyframes.js";
14
- import { getRegisteredSSRCollector } from "../ssr/ssr-collector-ref.js";
15
- import { hasKeys } from "../utils/has-keys.js";
16
- import { useContext, useInsertionEffect, useMemo, useRef } from "react";
17
-
18
- //#region src/hooks/useStyles.ts
19
- /**
20
- * Check if styles contain @starting-style rules.
21
- *
22
- * @starting-style CSS cannot be applied via multiple class names because
23
- * of cascade - later rules override earlier ones. When @starting is detected,
24
- * we combine top-level styles into a single chunk but keep sub-element styles
25
- * in their own chunk for better caching.
26
- */
27
- function containsStartingStyle(styleKey) {
28
- return styleKey.includes("@starting");
29
- }
30
- /**
31
- * Render, cache-key, and allocate a className for a single chunk.
32
- * Returns a ProcessedChunk, or null if the chunk produces no CSS rules.
33
- *
34
- * Always runs the pipeline and calls allocateClassName. The inject()
35
- * call in useInsertionEffect handles all edge cases: placeholders from
36
- * abandoned concurrent renders, hydration hits (ruleIndex -2), and
37
- * runtime cache hits (already injected). The pipeline's own LRU cache
38
- * makes repeated calls for identical styles cheap.
39
- */
40
- function processChunk(styles, chunkName, styleKeys) {
41
- if (styleKeys.length === 0) return null;
42
- const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
43
- const renderResult = renderStylesForChunk(styles, chunkName, styleKeys, cacheKey);
44
- if (renderResult.rules.length === 0) return null;
45
- const { className } = allocateClassName(cacheKey);
46
- return {
47
- name: chunkName,
48
- styleKeys,
49
- cacheKey,
50
- renderResult,
51
- className
52
- };
53
- }
54
- /**
55
- * Merge chunk map entries for @starting-style partial chunking.
56
- *
57
- * All non-subcomponent chunks are merged into a single COMBINED entry,
58
- * while SUBCOMPONENTS stays separate. This preserves CSS cascade for
59
- * @starting-style while still allowing sub-element styles to cache independently.
60
- */
61
- function mergeChunksForStartingStyle(chunkMap) {
62
- const merged = /* @__PURE__ */ new Map();
63
- const combinedKeys = [];
64
- for (const [chunkName, keys] of chunkMap) if (chunkName === CHUNK_NAMES.SUBCOMPONENTS) merged.set(CHUNK_NAMES.SUBCOMPONENTS, keys);
65
- else combinedKeys.push(...keys);
66
- if (combinedKeys.length > 0) {
67
- const result = /* @__PURE__ */ new Map();
68
- result.set(CHUNK_NAMES.COMBINED, combinedKeys);
69
- for (const [k, v] of merged) result.set(k, v);
70
- return result;
71
- }
72
- return merged;
73
- }
74
- /**
75
- * Get keyframes that are actually used in styles.
76
- * Returns null if no keyframes are used (fast path for zero overhead).
77
- *
78
- * Optimization order:
79
- * 1. Check if any keyframes are defined (local or global) - if not, return null
80
- * 2. Extract animation names from styles - if none, return null
81
- * 3. Merge and filter keyframes to only used ones
82
- */
83
- function getUsedKeyframes(styles) {
84
- const hasLocal = hasLocalKeyframes(styles);
85
- const hasGlobal = hasGlobalKeyframes();
86
- if (!hasLocal && !hasGlobal) return null;
87
- const usedNames = extractAnimationNamesFromStyles(styles);
88
- if (usedNames.size === 0) return null;
89
- return filterUsedKeyframes(mergeKeyframes(hasLocal ? extractLocalKeyframes(styles) : null, hasGlobal ? getGlobalKeyframes() : null), usedNames);
90
- }
91
- /**
92
- * Resolve the SSR collector from React context or AsyncLocalStorage.
93
- * Returns null on the client (no collector available).
94
- */
95
- function resolveSSRCollector(reactContext) {
96
- if (reactContext) return reactContext;
97
- const alsCollector = getRegisteredSSRCollector();
98
- if (alsCollector) return alsCollector;
99
- return null;
100
- }
101
- /**
102
- * Process a chunk on the SSR path: allocate via collector, render, collect CSS.
103
- * Returns null if the chunk produces no CSS rules.
104
- */
105
- function processChunkSSR(collector, styles, chunkName, styleKeys) {
106
- if (styleKeys.length === 0) return null;
107
- const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
108
- const { className, isNewAllocation } = collector.allocateClassName(cacheKey);
109
- if (isNewAllocation) {
110
- const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);
111
- if (renderResult.rules.length > 0) {
112
- collector.collectChunk(cacheKey, className, renderResult.rules);
113
- return {
114
- name: chunkName,
115
- styleKeys,
116
- cacheKey,
117
- renderResult,
118
- className
119
- };
120
- }
121
- return null;
122
- }
123
- return {
124
- name: chunkName,
125
- styleKeys,
126
- cacheKey,
127
- renderResult: { rules: [] },
128
- className
129
- };
130
- }
131
- /**
132
- * Hook to generate CSS classes from Tasty styles.
133
- * Handles style rendering, className allocation, and CSS injection.
134
- *
135
- * SSR-aware: when a ServerStyleCollector is available (via React context
136
- * or AsyncLocalStorage), CSS is collected during the render phase instead
137
- * of being injected into the DOM. useInsertionEffect does not run on the
138
- * server, so the collector path is the only active path during SSR.
139
- *
140
- * Uses chunking to split styles into logical groups for better caching
141
- * and CSS reuse across components.
142
- *
143
- * @example
144
- * ```tsx
145
- * function MyComponent() {
146
- * const { className } = useStyles({
147
- * padding: '2x',
148
- * fill: '#purple',
149
- * radius: '1r',
150
- * });
151
- *
152
- * return <div className={className}>Styled content</div>;
153
- * }
154
- * ```
155
- */
156
- function useStyles(styles) {
157
- const ssrCollector = resolveSSRCollector(useContext(TastySSRContext));
158
- const disposeRef = useRef([]);
159
- const stylesRef = useRef({
160
- key: "",
161
- styles: void 0
162
- });
163
- const resolvedStyles = useMemo(() => {
164
- if (!styles) return styles;
165
- return resolveRecipes(styles);
166
- }, [styles]);
167
- const styleKey = useMemo(() => {
168
- if (!resolvedStyles || !hasKeys(resolvedStyles)) return "";
169
- return stringifyStyles(resolvedStyles);
170
- }, [resolvedStyles]);
171
- if (stylesRef.current.key !== styleKey) stylesRef.current = {
172
- key: styleKey,
173
- styles: resolvedStyles
174
- };
175
- const processedChunks = useMemo(() => {
176
- const currentStyles = stylesRef.current.styles;
177
- if (!styleKey || !currentStyles) return [];
178
- let chunkMap = categorizeStyleKeys(currentStyles);
179
- if (containsStartingStyle(styleKey)) chunkMap = mergeChunksForStartingStyle(chunkMap);
180
- const chunks = [];
181
- if (ssrCollector) {
182
- ssrCollector.collectInternals();
183
- for (const [chunkName, chunkStyleKeys] of chunkMap) {
184
- const chunk = processChunkSSR(ssrCollector, currentStyles, chunkName, chunkStyleKeys);
185
- if (chunk) chunks.push(chunk);
186
- }
187
- const usedKeyframes = getUsedKeyframes(currentStyles);
188
- if (usedKeyframes) for (const [name, steps] of Object.entries(usedKeyframes)) {
189
- const css = formatKeyframesCSS(name, steps);
190
- ssrCollector.collectKeyframes(name, css);
191
- }
192
- if (hasLocalProperties(currentStyles)) {
193
- const localProperties = extractLocalProperties(currentStyles);
194
- if (localProperties) for (const [token, definition] of Object.entries(localProperties)) {
195
- const css = formatPropertyCSS(token, definition);
196
- if (css) ssrCollector.collectProperty(token, css);
197
- }
198
- }
199
- if (getConfig().autoPropertyTypes !== false) {
200
- const allRules = chunks.flatMap((c) => c.renderResult.rules);
201
- if (allRules.length > 0) collectAutoInferredProperties(allRules, ssrCollector, currentStyles);
202
- }
203
- } else for (const [chunkName, chunkStyleKeys] of chunkMap) {
204
- const chunk = processChunk(currentStyles, chunkName, chunkStyleKeys);
205
- if (chunk) chunks.push(chunk);
206
- }
207
- return chunks;
208
- }, [styleKey]);
209
- useInsertionEffect(() => {
210
- disposeRef.current.forEach((dispose) => dispose?.());
211
- disposeRef.current = [];
212
- if (processedChunks.length === 0) return;
213
- const currentStyles = stylesRef.current.styles;
214
- if (currentStyles && hasLocalProperties(currentStyles)) {
215
- const localProperties = extractLocalProperties(currentStyles);
216
- if (localProperties) for (const [token, definition] of Object.entries(localProperties)) property(token, definition);
217
- }
218
- const usedKeyframes = currentStyles ? getUsedKeyframes(currentStyles) : null;
219
- let nameMap = null;
220
- if (usedKeyframes) {
221
- nameMap = /* @__PURE__ */ new Map();
222
- for (const [name, steps] of Object.entries(usedKeyframes)) {
223
- const result = keyframes(steps, { name });
224
- const injectedName = result.toString();
225
- if (injectedName !== name) nameMap.set(name, injectedName);
226
- disposeRef.current.push(result.dispose);
227
- }
228
- if (nameMap.size === 0) nameMap = null;
229
- }
230
- for (const chunk of processedChunks) if (chunk.renderResult.rules.length > 0) {
231
- const { dispose } = inject(nameMap ? chunk.renderResult.rules.map((rule) => ({
232
- ...rule,
233
- declarations: replaceAnimationNames(rule.declarations, nameMap)
234
- })) : chunk.renderResult.rules, { cacheKey: chunk.cacheKey });
235
- disposeRef.current.push(dispose);
236
- }
237
- return () => {
238
- disposeRef.current.forEach((dispose) => dispose?.());
239
- disposeRef.current = [];
240
- };
241
- }, [processedChunks]);
242
- return { className: useMemo(() => {
243
- return processedChunks.map((chunk) => chunk.className).join(" ");
244
- }, [processedChunks]) };
245
- }
246
-
247
- //#endregion
248
- export { useStyles };
249
- //# sourceMappingURL=useStyles.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStyles.js","names":[],"sources":["../../src/hooks/useStyles.ts"],"sourcesContent":["import { useContext, useInsertionEffect, useMemo, useRef } from 'react';\n\nimport {\n categorizeStyleKeys,\n CHUNK_NAMES,\n generateChunkCacheKey,\n renderStylesForChunk,\n} from '../chunks';\nimport { getConfig, getGlobalKeyframes, hasGlobalKeyframes } from '../config';\nimport { allocateClassName, inject, keyframes, property } from '../injector';\nimport type { KeyframesSteps } from '../injector/types';\nimport {\n extractAnimationNamesFromStyles,\n extractLocalKeyframes,\n filterUsedKeyframes,\n hasLocalKeyframes,\n mergeKeyframes,\n replaceAnimationNames,\n} from '../keyframes';\nimport type { RenderResult } from '../pipeline';\nimport { extractLocalProperties, hasLocalProperties } from '../properties';\nimport { collectAutoInferredProperties } from '../ssr/collect-auto-properties';\nimport type { ServerStyleCollector } from '../ssr/collector';\nimport { TastySSRContext } from '../ssr/context';\nimport { formatKeyframesCSS } from '../ssr/format-keyframes';\nimport { formatPropertyCSS } from '../ssr/format-property';\nimport { getRegisteredSSRCollector } from '../ssr/ssr-collector-ref';\nimport type { Styles } from '../styles/types';\nimport { hasKeys } from '../utils/has-keys';\nimport { resolveRecipes } from '../utils/resolve-recipes';\nimport { stringifyStyles } from '../utils/styles';\n\n/**\n * Check if styles contain @starting-style rules.\n *\n * @starting-style CSS cannot be applied via multiple class names because\n * of cascade - later rules override earlier ones. When @starting is detected,\n * we combine top-level styles into a single chunk but keep sub-element styles\n * in their own chunk for better caching.\n */\nfunction containsStartingStyle(styleKey: string): boolean {\n return styleKey.includes('@starting');\n}\n\n/**\n * Tasty styles object to generate CSS classes for.\n * Can be undefined or empty object for no styles.\n */\nexport type UseStylesOptions = Styles | undefined;\n\nexport interface UseStylesResult {\n /**\n * Generated className(s) to apply to the element.\n * Can be empty string if no styles are provided.\n * With chunking enabled, may contain multiple space-separated class names.\n */\n className: string;\n}\n\n/**\n * Information about a processed chunk\n */\ninterface ProcessedChunk {\n name: string;\n styleKeys: string[];\n cacheKey: string;\n renderResult: RenderResult;\n className: string;\n}\n\n/**\n * Render, cache-key, and allocate a className for a single chunk.\n * Returns a ProcessedChunk, or null if the chunk produces no CSS rules.\n *\n * Always runs the pipeline and calls allocateClassName. The inject()\n * call in useInsertionEffect handles all edge cases: placeholders from\n * abandoned concurrent renders, hydration hits (ruleIndex -2), and\n * runtime cache hits (already injected). The pipeline's own LRU cache\n * makes repeated calls for identical styles cheap.\n */\nfunction processChunk(\n styles: Styles,\n chunkName: string,\n styleKeys: string[],\n): ProcessedChunk | null {\n if (styleKeys.length === 0) return null;\n\n const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);\n const renderResult = renderStylesForChunk(\n styles,\n chunkName,\n styleKeys,\n cacheKey,\n );\n if (renderResult.rules.length === 0) return null;\n\n const { className } = allocateClassName(cacheKey);\n\n return { name: chunkName, styleKeys, cacheKey, renderResult, className };\n}\n\n/**\n * Merge chunk map entries for @starting-style partial chunking.\n *\n * All non-subcomponent chunks are merged into a single COMBINED entry,\n * while SUBCOMPONENTS stays separate. This preserves CSS cascade for\n * @starting-style while still allowing sub-element styles to cache independently.\n */\nfunction mergeChunksForStartingStyle(\n chunkMap: Map<string, string[]>,\n): Map<string, string[]> {\n const merged = new Map<string, string[]>();\n const combinedKeys: string[] = [];\n\n for (const [chunkName, keys] of chunkMap) {\n if (chunkName === CHUNK_NAMES.SUBCOMPONENTS) {\n merged.set(CHUNK_NAMES.SUBCOMPONENTS, keys);\n } else {\n combinedKeys.push(...keys);\n }\n }\n\n if (combinedKeys.length > 0) {\n // Insert COMBINED first so it appears before SUBCOMPONENTS\n const result = new Map<string, string[]>();\n result.set(CHUNK_NAMES.COMBINED, combinedKeys);\n for (const [k, v] of merged) {\n result.set(k, v);\n }\n return result;\n }\n\n return merged;\n}\n\n/**\n * Get keyframes that are actually used in styles.\n * Returns null if no keyframes are used (fast path for zero overhead).\n *\n * Optimization order:\n * 1. Check if any keyframes are defined (local or global) - if not, return null\n * 2. Extract animation names from styles - if none, return null\n * 3. Merge and filter keyframes to only used ones\n */\nfunction getUsedKeyframes(\n styles: Styles,\n): Record<string, KeyframesSteps> | null {\n // Fast path: no keyframes defined anywhere\n const hasLocal = hasLocalKeyframes(styles);\n const hasGlobal = hasGlobalKeyframes();\n if (!hasLocal && !hasGlobal) return null;\n\n // Extract animation names from styles (not from rendered CSS - faster)\n const usedNames = extractAnimationNamesFromStyles(styles);\n if (usedNames.size === 0) return null;\n\n // Merge local and global keyframes\n const local = hasLocal ? extractLocalKeyframes(styles) : null;\n const global = hasGlobal ? getGlobalKeyframes() : null;\n const allKeyframes = mergeKeyframes(local, global);\n\n // Filter to only used keyframes\n return filterUsedKeyframes(allKeyframes, usedNames);\n}\n\n/**\n * Resolve the SSR collector from React context or AsyncLocalStorage.\n * Returns null on the client (no collector available).\n */\nfunction resolveSSRCollector(\n reactContext: ServerStyleCollector | null,\n): ServerStyleCollector | null {\n if (reactContext) return reactContext;\n\n const alsCollector = getRegisteredSSRCollector();\n if (alsCollector) return alsCollector;\n\n return null;\n}\n\n/**\n * Process a chunk on the SSR path: allocate via collector, render, collect CSS.\n * Returns null if the chunk produces no CSS rules.\n */\nfunction processChunkSSR(\n collector: ServerStyleCollector,\n styles: Styles,\n chunkName: string,\n styleKeys: string[],\n): ProcessedChunk | null {\n if (styleKeys.length === 0) return null;\n\n const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);\n const { className, isNewAllocation } = collector.allocateClassName(cacheKey);\n\n if (isNewAllocation) {\n const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);\n if (renderResult.rules.length > 0) {\n collector.collectChunk(cacheKey, className, renderResult.rules);\n return {\n name: chunkName,\n styleKeys,\n cacheKey,\n renderResult,\n className,\n };\n }\n return null;\n }\n\n return {\n name: chunkName,\n styleKeys,\n cacheKey,\n renderResult: { rules: [] },\n className,\n };\n}\n\n/**\n * Hook to generate CSS classes from Tasty styles.\n * Handles style rendering, className allocation, and CSS injection.\n *\n * SSR-aware: when a ServerStyleCollector is available (via React context\n * or AsyncLocalStorage), CSS is collected during the render phase instead\n * of being injected into the DOM. useInsertionEffect does not run on the\n * server, so the collector path is the only active path during SSR.\n *\n * Uses chunking to split styles into logical groups for better caching\n * and CSS reuse across components.\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { className } = useStyles({\n * padding: '2x',\n * fill: '#purple',\n * radius: '1r',\n * });\n *\n * return <div className={className}>Styled content</div>;\n * }\n * ```\n */\nexport function useStyles(styles: UseStylesOptions): UseStylesResult {\n const ssrContextValue = useContext(TastySSRContext);\n const ssrCollector = resolveSSRCollector(ssrContextValue);\n\n // Array of dispose functions for each chunk\n const disposeRef = useRef<(() => void)[]>([]);\n\n // Store styles by their stringified key to avoid recomputing when only reference changes\n const stylesRef = useRef<{ key: string; styles: Styles | undefined }>({\n key: '',\n styles: undefined,\n });\n\n // Resolve recipes before any processing (zero overhead if no recipes configured)\n const resolvedStyles = useMemo(() => {\n if (!styles) return styles;\n return resolveRecipes(styles);\n }, [styles]);\n\n // Compute style key - this is a primitive string that captures style content\n const styleKey = useMemo(() => {\n if (!resolvedStyles || !hasKeys(resolvedStyles)) {\n return '';\n }\n return stringifyStyles(resolvedStyles);\n }, [resolvedStyles]);\n\n // Update ref when styleKey changes (content actually changed)\n if (stylesRef.current.key !== styleKey) {\n stylesRef.current = { key: styleKey, styles: resolvedStyles };\n }\n\n // Process chunks: categorize, generate cache keys, render, and allocate classNames\n // Only depends on styleKey (primitive), not styles object reference\n const processedChunks: ProcessedChunk[] = useMemo(() => {\n const currentStyles = stylesRef.current.styles;\n if (!styleKey || !currentStyles) {\n return [];\n }\n\n // Categorize style keys into chunks\n let chunkMap = categorizeStyleKeys(\n currentStyles as Record<string, unknown>,\n );\n\n // Partial chunking for styles containing @starting-style rules.\n // @starting-style CSS cannot work with multiple class names due to cascade,\n // so we merge all top-level chunks into one but keep sub-element styles separate.\n if (containsStartingStyle(styleKey)) {\n chunkMap = mergeChunksForStartingStyle(chunkMap);\n }\n\n const chunks: ProcessedChunk[] = [];\n\n if (ssrCollector) {\n // Ensure internal @property and :root token CSS is included\n ssrCollector.collectInternals();\n\n // SERVER PATH: allocate via collector, collect CSS\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n const chunk = processChunkSSR(\n ssrCollector,\n currentStyles,\n chunkName,\n chunkStyleKeys,\n );\n if (chunk) chunks.push(chunk);\n }\n\n // Collect keyframes on the server\n const usedKeyframes = getUsedKeyframes(currentStyles);\n if (usedKeyframes) {\n for (const [name, steps] of Object.entries(usedKeyframes)) {\n const css = formatKeyframesCSS(name, steps);\n ssrCollector.collectKeyframes(name, css);\n }\n }\n\n // Collect explicit @property rules on the server\n if (hasLocalProperties(currentStyles)) {\n const localProperties = extractLocalProperties(currentStyles);\n if (localProperties) {\n for (const [token, definition] of Object.entries(localProperties)) {\n const css = formatPropertyCSS(token, definition);\n if (css) {\n ssrCollector.collectProperty(token, css);\n }\n }\n }\n }\n\n // Auto-infer @property types from rendered declarations (SSR).\n // On the client this happens inside StyleInjector.inject(), which\n // runs in useInsertionEffect and therefore never executes on the server.\n if (getConfig().autoPropertyTypes !== false) {\n const allRules = chunks.flatMap((c) => c.renderResult.rules);\n if (allRules.length > 0) {\n collectAutoInferredProperties(allRules, ssrCollector, currentStyles);\n }\n }\n } else {\n // CLIENT PATH: unchanged behavior\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n const chunk = processChunk(currentStyles, chunkName, chunkStyleKeys);\n if (chunk) chunks.push(chunk);\n }\n }\n\n return chunks;\n }, [styleKey]);\n\n // Inject styles in insertion effect (avoids render phase side effects).\n // Does NOT run on the server — the SSR path above handles collection.\n useInsertionEffect(() => {\n // Cleanup all previous disposals\n disposeRef.current.forEach((dispose) => dispose?.());\n disposeRef.current = [];\n\n // Fast path: no chunks to inject\n if (processedChunks.length === 0) {\n return;\n }\n\n const currentStyles = stylesRef.current.styles;\n\n // Register explicit @properties first so they take precedence over auto-inference\n // that happens during keyframe and style chunk injection.\n // Token formats: $name → --name, #name → --name-color (with auto syntax: '<color>')\n // Note: Global properties are injected once when styles are first generated (see markStylesGenerated)\n if (currentStyles && hasLocalProperties(currentStyles)) {\n const localProperties = extractLocalProperties(currentStyles);\n if (localProperties) {\n for (const [token, definition] of Object.entries(localProperties)) {\n property(token, definition);\n }\n }\n }\n\n // Get keyframes that are actually used (returns null if none - zero overhead)\n const usedKeyframes = currentStyles\n ? getUsedKeyframes(currentStyles)\n : null;\n\n // Inject keyframes and build name map (only if we have keyframes)\n let nameMap: Map<string, string> | null = null;\n\n if (usedKeyframes) {\n nameMap = new Map();\n for (const [name, steps] of Object.entries(usedKeyframes)) {\n const result = keyframes(steps, { name });\n const injectedName = result.toString();\n // Only add to map if name differs (optimization for replacement check)\n if (injectedName !== name) {\n nameMap.set(name, injectedName);\n }\n disposeRef.current.push(result.dispose);\n }\n // Clear map if no replacements needed\n if (nameMap.size === 0) {\n nameMap = null;\n }\n }\n\n // Inject each chunk\n for (const chunk of processedChunks) {\n if (chunk.renderResult.rules.length > 0) {\n // Replace animation names only if needed\n const rulesToInject = nameMap\n ? chunk.renderResult.rules.map((rule) => ({\n ...rule,\n declarations: replaceAnimationNames(rule.declarations, nameMap!),\n }))\n : chunk.renderResult.rules;\n\n const { dispose } = inject(rulesToInject, {\n cacheKey: chunk.cacheKey,\n });\n disposeRef.current.push(dispose);\n }\n }\n\n return () => {\n disposeRef.current.forEach((dispose) => dispose?.());\n disposeRef.current = [];\n };\n }, [processedChunks]);\n\n // Combine all chunk classNames\n const className = useMemo(() => {\n return processedChunks.map((chunk) => chunk.className).join(' ');\n }, [processedChunks]);\n\n return {\n className,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAS,sBAAsB,UAA2B;AACxD,QAAO,SAAS,SAAS,YAAY;;;;;;;;;;;;AAuCvC,SAAS,aACP,QACA,WACA,WACuB;AACvB,KAAI,UAAU,WAAW,EAAG,QAAO;CAEnC,MAAM,WAAW,sBAAsB,QAAQ,WAAW,UAAU;CACpE,MAAM,eAAe,qBACnB,QACA,WACA,WACA,SACD;AACD,KAAI,aAAa,MAAM,WAAW,EAAG,QAAO;CAE5C,MAAM,EAAE,cAAc,kBAAkB,SAAS;AAEjD,QAAO;EAAE,MAAM;EAAW;EAAW;EAAU;EAAc;EAAW;;;;;;;;;AAU1E,SAAS,4BACP,UACuB;CACvB,MAAM,yBAAS,IAAI,KAAuB;CAC1C,M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E,UAClB,MAAM,aAAa,MAAM,KAAK,UAAU;IACtC,GAAG;IACH,cAAc,sBAAsB,KAAK,cAAc,QAAS;IACjE,EAAE,GACH,MAAM,aAAa,OAEmB,EACxC,UAAU,MAAM,UACjB,CAAC;AACF,cAAW,QAAQ,KAAK,QAAQ;;AAIpC,eAAa;AACX,cAAW,QAAQ,SAAS,YAAY,WAAW,CAAC;AACpD,cAAW,UAAU,EAAE;;IAExB,CAAC,gBAAgB,CAAC;AAOrB,QAAO,EACL,WALgB,cAAc;AAC9B,SAAO,gBAAgB,KAAK,UAAU,MAAM,UAAU,CAAC,KAAK,IAAI;IAC/D,CAAC,gBAAgB,CAAC,EAIpB"}
@@ -1,165 +0,0 @@
1
- import { CacheMetrics, DisposeFunction, GlobalInjectResult, InjectResult, KeyframesCacheEntry, KeyframesInfo, KeyframesResult, KeyframesSteps, PropertyDefinition, RawCSSResult, RootRegistry, RuleInfo, SheetInfo, StyleInjectorConfig, StyleRule } from "./types.js";
2
- import { StyleResult } from "../pipeline/index.js";
3
- import { SheetManager } from "./sheet-manager.js";
4
- import { StyleInjector } from "./injector.js";
5
-
6
- //#region src/injector/index.d.ts
7
- /**
8
- * Allocate a className for a cacheKey without injecting styles yet
9
- */
10
- declare function allocateClassName(cacheKey: string, options?: {
11
- root?: Document | ShadowRoot;
12
- }): {
13
- className: string;
14
- isNewAllocation: boolean;
15
- };
16
- /**
17
- * Track a reference to an already-injected cacheKey (refCount + dispose).
18
- * Used on cache hits (SSR hydration or runtime reuse) where the pipeline
19
- * was skipped. Returns null if the cacheKey is not in the cache.
20
- */
21
- declare function trackRef(cacheKey: string, options?: {
22
- root?: Document | ShadowRoot;
23
- }): InjectResult | null;
24
- /**
25
- * Inject styles and return className with dispose function
26
- */
27
- declare function inject(rules: StyleResult[], options?: {
28
- root?: Document | ShadowRoot;
29
- cacheKey?: string;
30
- }): InjectResult;
31
- /**
32
- * Inject global rules that should not reserve tasty class names
33
- */
34
- declare function injectGlobal(rules: StyleResult[], options?: {
35
- root?: Document | ShadowRoot;
36
- }): GlobalInjectResult;
37
- /**
38
- * Inject raw CSS text directly without parsing
39
- * This is a low-overhead method for injecting raw CSS that doesn't need tasty processing.
40
- * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking.
41
- *
42
- * @example
43
- * ```tsx
44
- * // Inject raw CSS
45
- * const { dispose } = injectRawCSS(`
46
- * body { margin: 0; padding: 0; }
47
- * .my-class { color: red; }
48
- * `);
49
- *
50
- * // Later, remove the injected CSS
51
- * dispose();
52
- * ```
53
- */
54
- declare function injectRawCSS(css: string, options?: {
55
- root?: Document | ShadowRoot;
56
- }): {
57
- dispose: () => void;
58
- };
59
- /**
60
- * Get raw CSS text for SSR
61
- */
62
- declare function getRawCSSText(options?: {
63
- root?: Document | ShadowRoot;
64
- }): string;
65
- /**
66
- * Inject keyframes and return object with toString() and dispose()
67
- */
68
- declare function keyframes(steps: KeyframesSteps, nameOrOptions?: string | {
69
- root?: Document | ShadowRoot;
70
- name?: string;
71
- }): KeyframesResult;
72
- interface PropertyOptions {
73
- /**
74
- * CSS syntax string for the property (e.g., '<color>', '<length>', '<angle>')
75
- * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax
76
- */
77
- syntax?: string;
78
- /**
79
- * Whether the property inherits from parent elements
80
- * @default true
81
- */
82
- inherits?: boolean;
83
- /**
84
- * Initial value for the property
85
- */
86
- initialValue?: string | number;
87
- /**
88
- * Shadow root or document to inject into
89
- */
90
- root?: Document | ShadowRoot;
91
- }
92
- /**
93
- * Define a CSS @property custom property.
94
- * This enables advanced features like animating custom properties.
95
- *
96
- * Note: @property rules are global and persistent once defined.
97
- * Re-registering the same property name is a no-op.
98
- *
99
- * @param name - The custom property name (must start with --)
100
- * @param options - Property configuration
101
- *
102
- * @example
103
- * ```ts
104
- * // Define a color property that can be animated
105
- * property('--my-color', {
106
- * syntax: '<color>',
107
- * initialValue: 'red',
108
- * });
109
- *
110
- * // Define an angle property
111
- * property('--rotation', {
112
- * syntax: '<angle>',
113
- * inherits: false,
114
- * initialValue: '0deg',
115
- * });
116
- * ```
117
- */
118
- declare function property(name: string, options?: PropertyOptions): void;
119
- /**
120
- * Check if a CSS @property has already been defined
121
- *
122
- * @param name - The custom property name to check
123
- * @param options - Options including root
124
- */
125
- declare function isPropertyDefined(name: string, options?: {
126
- root?: Document | ShadowRoot;
127
- }): boolean;
128
- /**
129
- * Get CSS text from all sheets (for SSR)
130
- */
131
- declare function getCssText(options?: {
132
- root?: Document | ShadowRoot;
133
- }): string;
134
- /**
135
- * Collect only CSS used by a rendered subtree (like jest-styled-components).
136
- * Pass the container returned by render(...).
137
- */
138
- declare function getCssTextForNode(node: ParentNode | Element | DocumentFragment, options?: {
139
- root?: Document | ShadowRoot;
140
- }): string;
141
- /**
142
- * Force cleanup of unused rules
143
- */
144
- declare function cleanup(root?: Document | ShadowRoot): void;
145
- /**
146
- * Check if we're currently running in a test environment
147
- */
148
- declare function getIsTestEnvironment(): boolean;
149
- /**
150
- * Get the global injector instance for debugging
151
- */
152
- declare const injector: {
153
- readonly instance: StyleInjector;
154
- };
155
- /**
156
- * Destroy all resources and clean up
157
- */
158
- declare function destroy(root?: Document | ShadowRoot): void;
159
- /**
160
- * Create a new isolated injector instance
161
- */
162
- declare function createInjector(config?: Partial<StyleInjectorConfig>): StyleInjector;
163
- //#endregion
164
- export { PropertyOptions, allocateClassName, cleanup, createInjector, destroy, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, trackRef };
165
- //# sourceMappingURL=index.d.ts.map