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

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 (308) hide show
  1. package/README.md +288 -250
  2. package/dist/_virtual/_rolldown/runtime.js +1 -2
  3. package/dist/chunks/cacheKey.d.ts +1 -0
  4. package/dist/chunks/cacheKey.js +17 -10
  5. package/dist/chunks/cacheKey.js.map +1 -1
  6. package/dist/chunks/definitions.d.ts +1 -1
  7. package/dist/chunks/definitions.js +2 -3
  8. package/dist/chunks/definitions.js.map +1 -1
  9. package/dist/chunks/index.d.ts +1 -0
  10. package/dist/chunks/renderChunk.d.ts +1 -0
  11. package/dist/chunks/renderChunk.js +32 -34
  12. package/dist/chunks/renderChunk.js.map +1 -1
  13. package/dist/compute-styles.d.ts +31 -0
  14. package/dist/compute-styles.js +335 -0
  15. package/dist/compute-styles.js.map +1 -0
  16. package/dist/config.d.ts +109 -30
  17. package/dist/config.js +142 -57
  18. package/dist/config.js.map +1 -1
  19. package/dist/core/index.d.ts +12 -11
  20. package/dist/core/index.js +10 -9
  21. package/dist/counter-style/index.js +51 -0
  22. package/dist/counter-style/index.js.map +1 -0
  23. package/dist/debug.d.ts +26 -141
  24. package/dist/debug.js +357 -637
  25. package/dist/debug.js.map +1 -1
  26. package/dist/font-face/index.js +63 -0
  27. package/dist/font-face/index.js.map +1 -0
  28. package/dist/hooks/index.d.ts +7 -0
  29. package/dist/hooks/useCounterStyle.d.ts +52 -0
  30. package/dist/hooks/useCounterStyle.js +43 -0
  31. package/dist/hooks/useCounterStyle.js.map +1 -0
  32. package/dist/hooks/useFontFace.d.ts +45 -0
  33. package/dist/hooks/useFontFace.js +68 -0
  34. package/dist/hooks/useFontFace.js.map +1 -0
  35. package/dist/hooks/useGlobalStyles.d.ts +18 -2
  36. package/dist/hooks/useGlobalStyles.js +50 -46
  37. package/dist/hooks/useGlobalStyles.js.map +1 -1
  38. package/dist/hooks/useKeyframes.d.ts +4 -2
  39. package/dist/hooks/useKeyframes.js +32 -57
  40. package/dist/hooks/useKeyframes.js.map +1 -1
  41. package/dist/hooks/useProperty.d.ts +4 -2
  42. package/dist/hooks/useProperty.js +29 -45
  43. package/dist/hooks/useProperty.js.map +1 -1
  44. package/dist/hooks/useRawCSS.d.ts +8 -44
  45. package/dist/hooks/useRawCSS.js +82 -27
  46. package/dist/hooks/useRawCSS.js.map +1 -1
  47. package/dist/hooks/useStyles.d.ts +4 -9
  48. package/dist/hooks/useStyles.js +7 -226
  49. package/dist/hooks/useStyles.js.map +1 -1
  50. package/dist/index.d.ts +15 -12
  51. package/dist/index.js +13 -10
  52. package/dist/injector/index.d.ts +36 -19
  53. package/dist/injector/index.js +42 -19
  54. package/dist/injector/index.js.map +1 -1
  55. package/dist/injector/injector.d.ts +48 -3
  56. package/dist/injector/injector.js +144 -16
  57. package/dist/injector/injector.js.map +1 -1
  58. package/dist/injector/sheet-manager.d.ts +9 -13
  59. package/dist/injector/sheet-manager.js +39 -70
  60. package/dist/injector/sheet-manager.js.map +1 -1
  61. package/dist/injector/types.d.ts +103 -19
  62. package/dist/keyframes/index.js +1 -1
  63. package/dist/parser/classify.js +6 -6
  64. package/dist/parser/classify.js.map +1 -1
  65. package/dist/parser/const.js +30 -3
  66. package/dist/parser/const.js.map +1 -1
  67. package/dist/parser/lru.js +1 -1
  68. package/dist/parser/lru.js.map +1 -1
  69. package/dist/parser/parser.js +2 -3
  70. package/dist/parser/parser.js.map +1 -1
  71. package/dist/parser/tokenizer.js +1 -1
  72. package/dist/parser/tokenizer.js.map +1 -1
  73. package/dist/parser/types.js +1 -1
  74. package/dist/parser/types.js.map +1 -1
  75. package/dist/pipeline/conditions.js +1 -1
  76. package/dist/pipeline/conditions.js.map +1 -1
  77. package/dist/pipeline/exclusive.js +1 -2
  78. package/dist/pipeline/exclusive.js.map +1 -1
  79. package/dist/pipeline/index.d.ts +3 -1
  80. package/dist/pipeline/index.js +80 -32
  81. package/dist/pipeline/index.js.map +1 -1
  82. package/dist/pipeline/materialize.js +329 -82
  83. package/dist/pipeline/materialize.js.map +1 -1
  84. package/dist/pipeline/parseStateKey.d.ts +1 -1
  85. package/dist/pipeline/parseStateKey.js +3 -8
  86. package/dist/pipeline/parseStateKey.js.map +1 -1
  87. package/dist/pipeline/simplify.js +1 -2
  88. package/dist/pipeline/simplify.js.map +1 -1
  89. package/dist/pipeline/warnings.js +1 -1
  90. package/dist/plugins/index.d.ts +2 -0
  91. package/dist/plugins/okhsl-plugin.js +3 -277
  92. package/dist/plugins/okhsl-plugin.js.map +1 -1
  93. package/dist/plugins/types.d.ts +9 -2
  94. package/dist/properties/index.js +3 -17
  95. package/dist/properties/index.js.map +1 -1
  96. package/dist/properties/property-type-resolver.js +5 -2
  97. package/dist/properties/property-type-resolver.js.map +1 -1
  98. package/dist/rsc-cache.js +70 -0
  99. package/dist/rsc-cache.js.map +1 -0
  100. package/dist/ssr/astro-client.d.ts +1 -0
  101. package/dist/ssr/astro-client.js +24 -0
  102. package/dist/ssr/astro-client.js.map +1 -0
  103. package/dist/ssr/astro-middleware.d.ts +15 -0
  104. package/dist/ssr/astro-middleware.js +19 -0
  105. package/dist/ssr/astro-middleware.js.map +1 -0
  106. package/dist/ssr/astro.d.ts +85 -8
  107. package/dist/ssr/astro.js +111 -22
  108. package/dist/ssr/astro.js.map +1 -1
  109. package/dist/ssr/async-storage.js +1 -2
  110. package/dist/ssr/async-storage.js.map +1 -1
  111. package/dist/ssr/collect-auto-properties.js +29 -11
  112. package/dist/ssr/collect-auto-properties.js.map +1 -1
  113. package/dist/ssr/collector.d.ts +17 -0
  114. package/dist/ssr/collector.js +60 -14
  115. package/dist/ssr/collector.js.map +1 -1
  116. package/dist/ssr/format-global-rules.js +1 -1
  117. package/dist/ssr/format-keyframes.js +1 -2
  118. package/dist/ssr/format-keyframes.js.map +1 -1
  119. package/dist/ssr/format-property.js +10 -9
  120. package/dist/ssr/format-property.js.map +1 -1
  121. package/dist/ssr/format-rules.js +8 -5
  122. package/dist/ssr/format-rules.js.map +1 -1
  123. package/dist/ssr/hydrate.js +1 -2
  124. package/dist/ssr/hydrate.js.map +1 -1
  125. package/dist/ssr/index.d.ts +2 -3
  126. package/dist/ssr/index.js +2 -4
  127. package/dist/ssr/index.js.map +1 -1
  128. package/dist/ssr/next.d.ts +1 -3
  129. package/dist/ssr/next.js +10 -7
  130. package/dist/ssr/next.js.map +1 -1
  131. package/dist/ssr/ssr-collector-ref.js +1 -1
  132. package/dist/states/index.js +13 -259
  133. package/dist/states/index.js.map +1 -1
  134. package/dist/static/index.js +1 -2
  135. package/dist/static/inject.d.ts +5 -0
  136. package/dist/static/inject.js +17 -0
  137. package/dist/static/inject.js.map +1 -0
  138. package/dist/static/tastyStatic.js +1 -2
  139. package/dist/static/tastyStatic.js.map +1 -1
  140. package/dist/static/types.js +1 -1
  141. package/dist/styles/border.d.ts +1 -1
  142. package/dist/styles/border.js +30 -24
  143. package/dist/styles/border.js.map +1 -1
  144. package/dist/styles/color.d.ts +1 -1
  145. package/dist/styles/color.js +11 -8
  146. package/dist/styles/color.js.map +1 -1
  147. package/dist/styles/const.js +17 -0
  148. package/dist/styles/const.js.map +1 -0
  149. package/dist/styles/createStyle.js +28 -26
  150. package/dist/styles/createStyle.js.map +1 -1
  151. package/dist/styles/dimension.js +15 -3
  152. package/dist/styles/dimension.js.map +1 -1
  153. package/dist/styles/directional.js +133 -0
  154. package/dist/styles/directional.js.map +1 -0
  155. package/dist/styles/display.d.ts +3 -10
  156. package/dist/styles/display.js +45 -39
  157. package/dist/styles/display.js.map +1 -1
  158. package/dist/styles/fade.d.ts +1 -1
  159. package/dist/styles/fade.js +9 -5
  160. package/dist/styles/fade.js.map +1 -1
  161. package/dist/styles/fill.d.ts +2 -2
  162. package/dist/styles/fill.js +3 -4
  163. package/dist/styles/fill.js.map +1 -1
  164. package/dist/styles/flow.js +1 -1
  165. package/dist/styles/gap.d.ts +1 -1
  166. package/dist/styles/gap.js +4 -3
  167. package/dist/styles/gap.js.map +1 -1
  168. package/dist/styles/height.d.ts +1 -1
  169. package/dist/styles/height.js +1 -2
  170. package/dist/styles/height.js.map +1 -1
  171. package/dist/styles/index.d.ts +0 -1
  172. package/dist/styles/index.js +3 -4
  173. package/dist/styles/index.js.map +1 -1
  174. package/dist/styles/inset.d.ts +1 -29
  175. package/dist/styles/inset.js +19 -135
  176. package/dist/styles/inset.js.map +1 -1
  177. package/dist/styles/list.d.ts +5 -5
  178. package/dist/styles/list.js +4 -2
  179. package/dist/styles/list.js.map +1 -1
  180. package/dist/styles/margin.d.ts +1 -1
  181. package/dist/styles/margin.js +17 -89
  182. package/dist/styles/margin.js.map +1 -1
  183. package/dist/styles/outline.d.ts +1 -1
  184. package/dist/styles/outline.js +6 -16
  185. package/dist/styles/outline.js.map +1 -1
  186. package/dist/styles/padding.d.ts +1 -1
  187. package/dist/styles/padding.js +17 -89
  188. package/dist/styles/padding.js.map +1 -1
  189. package/dist/styles/placement.d.ts +37 -0
  190. package/dist/styles/placement.js +74 -0
  191. package/dist/styles/placement.js.map +1 -0
  192. package/dist/styles/predefined.d.ts +4 -4
  193. package/dist/styles/predefined.js +9 -10
  194. package/dist/styles/predefined.js.map +1 -1
  195. package/dist/styles/preset.d.ts +6 -1
  196. package/dist/styles/preset.js +54 -53
  197. package/dist/styles/preset.js.map +1 -1
  198. package/dist/styles/radius.d.ts +1 -3
  199. package/dist/styles/radius.js +38 -6
  200. package/dist/styles/radius.js.map +1 -1
  201. package/dist/styles/scrollMargin.d.ts +24 -0
  202. package/dist/styles/scrollMargin.js +32 -0
  203. package/dist/styles/scrollMargin.js.map +1 -0
  204. package/dist/styles/scrollbar.d.ts +1 -1
  205. package/dist/styles/scrollbar.js +8 -5
  206. package/dist/styles/scrollbar.js.map +1 -1
  207. package/dist/styles/shadow.d.ts +1 -1
  208. package/dist/styles/shadow.js +4 -3
  209. package/dist/styles/shadow.js.map +1 -1
  210. package/dist/styles/shared.js +17 -0
  211. package/dist/styles/shared.js.map +1 -0
  212. package/dist/styles/transition.d.ts +1 -1
  213. package/dist/styles/transition.js +5 -4
  214. package/dist/styles/transition.js.map +1 -1
  215. package/dist/styles/types.d.ts +84 -15
  216. package/dist/styles/width.d.ts +1 -1
  217. package/dist/styles/width.js +1 -2
  218. package/dist/styles/width.js.map +1 -1
  219. package/dist/tasty.d.ts +46 -893
  220. package/dist/tasty.js +96 -59
  221. package/dist/tasty.js.map +1 -1
  222. package/dist/types.d.ts +1 -1
  223. package/dist/utils/cache-wrapper.js +4 -9
  224. package/dist/utils/cache-wrapper.js.map +1 -1
  225. package/dist/utils/case-converter.js +1 -1
  226. package/dist/utils/color-math.d.ts +46 -0
  227. package/dist/utils/color-math.js +749 -0
  228. package/dist/utils/color-math.js.map +1 -0
  229. package/dist/utils/color-space.d.ts +5 -0
  230. package/dist/utils/color-space.js +228 -0
  231. package/dist/utils/color-space.js.map +1 -0
  232. package/dist/utils/colors.js +3 -2
  233. package/dist/utils/colors.js.map +1 -1
  234. package/dist/utils/dotize.js +1 -1
  235. package/dist/utils/dotize.js.map +1 -1
  236. package/dist/utils/filter-base-props.d.ts +1 -1
  237. package/dist/utils/filter-base-props.js +1 -1
  238. package/dist/utils/filter-base-props.js.map +1 -1
  239. package/dist/utils/get-display-name.js +1 -1
  240. package/dist/utils/has-keys.js +13 -0
  241. package/dist/utils/has-keys.js.map +1 -0
  242. package/dist/utils/hash.js +14 -0
  243. package/dist/utils/hash.js.map +1 -0
  244. package/dist/utils/is-dev-env.js +1 -1
  245. package/dist/utils/is-dev-env.js.map +1 -1
  246. package/dist/utils/is-valid-element-type.js +1 -1
  247. package/dist/utils/merge-styles.js +1 -2
  248. package/dist/utils/merge-styles.js.map +1 -1
  249. package/dist/utils/mod-attrs.d.ts +0 -2
  250. package/dist/utils/mod-attrs.js +3 -4
  251. package/dist/utils/mod-attrs.js.map +1 -1
  252. package/dist/utils/process-tokens.d.ts +3 -17
  253. package/dist/utils/process-tokens.js +19 -107
  254. package/dist/utils/process-tokens.js.map +1 -1
  255. package/dist/utils/resolve-recipes.js +1 -2
  256. package/dist/utils/resolve-recipes.js.map +1 -1
  257. package/dist/utils/selector-transform.js +1 -1
  258. package/dist/utils/string.js +1 -1
  259. package/dist/utils/styles.d.ts +3 -81
  260. package/dist/utils/styles.js +29 -539
  261. package/dist/utils/styles.js.map +1 -1
  262. package/dist/utils/typography.d.ts +24 -13
  263. package/dist/utils/typography.js +15 -17
  264. package/dist/utils/typography.js.map +1 -1
  265. package/dist/utils/warnings.js +1 -1
  266. package/dist/zero/babel.d.ts +63 -8
  267. package/dist/zero/babel.js +163 -44
  268. package/dist/zero/babel.js.map +1 -1
  269. package/dist/zero/css-writer.js +1 -2
  270. package/dist/zero/css-writer.js.map +1 -1
  271. package/dist/zero/extractor.js +54 -3
  272. package/dist/zero/extractor.js.map +1 -1
  273. package/dist/zero/index.js +1 -2
  274. package/dist/zero/next.d.ts +28 -1
  275. package/dist/zero/next.js +70 -15
  276. package/dist/zero/next.js.map +1 -1
  277. package/docs/PIPELINE.md +519 -0
  278. package/docs/README.md +31 -0
  279. package/docs/adoption.md +296 -0
  280. package/docs/comparison.md +420 -0
  281. package/docs/configuration.md +127 -12
  282. package/docs/debug.md +152 -339
  283. package/docs/design-system.md +424 -0
  284. package/docs/{usage.md → dsl.md} +379 -386
  285. package/docs/getting-started.md +217 -0
  286. package/docs/injector.md +43 -27
  287. package/docs/methodology.md +616 -0
  288. package/docs/runtime.md +575 -0
  289. package/docs/ssr.md +144 -81
  290. package/docs/styles.md +48 -26
  291. package/docs/tasty-static.md +166 -22
  292. package/package.json +27 -12
  293. package/dist/ssr/context.d.ts +0 -8
  294. package/dist/ssr/context.js +0 -14
  295. package/dist/ssr/context.js.map +0 -1
  296. package/dist/styles/align.d.ts +0 -15
  297. package/dist/styles/align.js +0 -14
  298. package/dist/styles/align.js.map +0 -1
  299. package/dist/styles/justify.d.ts +0 -15
  300. package/dist/styles/justify.js +0 -14
  301. package/dist/styles/justify.js.map +0 -1
  302. package/dist/tokens/typography.d.ts +0 -19
  303. package/dist/tokens/typography.js +0 -237
  304. package/dist/tokens/typography.js.map +0 -1
  305. package/dist/utils/hsl-to-rgb.js +0 -38
  306. package/dist/utils/hsl-to-rgb.js.map +0 -1
  307. package/dist/utils/okhsl-to-rgb.js +0 -296
  308. package/dist/utils/okhsl-to-rgb.js.map +0 -1
@@ -1,27 +1,30 @@
1
1
  import { renderStyles } from "../pipeline/index.js";
2
2
  import { getConfig } from "../config.js";
3
3
  import { injectGlobal } from "../injector/index.js";
4
- import { resolveRecipes } from "../utils/resolve-recipes.js";
5
- import { collectAutoInferredProperties } from "../ssr/collect-auto-properties.js";
6
- import { TastySSRContext } from "../ssr/context.js";
7
- import { getRegisteredSSRCollector } from "../ssr/ssr-collector-ref.js";
4
+ import { getRSCCache, isServerEnvironment, pushRSCCSS } from "../rsc-cache.js";
5
+ import { collectAutoInferredProperties, collectAutoInferredPropertiesRSC } from "../ssr/collect-auto-properties.js";
8
6
  import { formatGlobalRules } from "../ssr/format-global-rules.js";
9
- import { useContext, useInsertionEffect, useMemo, useRef } from "react";
10
-
7
+ import { getRegisteredSSRCollector } from "../ssr/ssr-collector-ref.js";
8
+ import { resolveRecipes } from "../utils/resolve-recipes.js";
9
+ import { hashString } from "../utils/hash.js";
11
10
  //#region src/hooks/useGlobalStyles.ts
12
- function resolveSSRCollector(reactContext) {
13
- if (reactContext) return reactContext;
14
- return getRegisteredSSRCollector();
15
- }
11
+ const clientGlobalEntries = /* @__PURE__ */ new Map();
16
12
  /**
17
- * Hook to inject global styles for a given selector.
13
+ * Inject global styles for a given selector.
18
14
  * Useful for styling elements by selector without generating classNames.
19
15
  *
20
16
  * SSR-aware: when a ServerStyleCollector is available, CSS is collected
21
17
  * during the render phase instead of being injected into the DOM.
22
18
  *
19
+ * Works in all environments: client, SSR with collector, and React Server Components.
20
+ *
21
+ * Injected styles are permanent — they are not cleaned up on component unmount.
22
+ * Use the `id` option for update tracking when styles change over the
23
+ * component lifecycle.
24
+ *
23
25
  * @param selector - CSS selector to apply styles to (e.g., '.my-class', ':root', 'body')
24
26
  * @param styles - Tasty styles object
27
+ * @param options - Optional settings including `id` for update tracking
25
28
  *
26
29
  * @example
27
30
  * ```tsx
@@ -36,48 +39,49 @@ function resolveSSRCollector(reactContext) {
36
39
  * }
37
40
  * ```
38
41
  */
39
- function useGlobalStyles(selector, styles) {
40
- const ssrCollector = resolveSSRCollector(useContext(TastySSRContext));
41
- const disposeRef = useRef(null);
42
- const resolvedStyles = useMemo(() => {
43
- if (!styles) return styles;
44
- return resolveRecipes(styles);
45
- }, [styles]);
46
- const styleResults = useMemo(() => {
47
- if (!resolvedStyles) return [];
48
- if (!selector) {
49
- console.warn("[Tasty] useGlobalStyles: selector is required and cannot be empty. Styles will not be injected.");
50
- return [];
51
- }
52
- return renderStyles(resolvedStyles, selector);
53
- }, [resolvedStyles, selector]);
54
- useMemo(() => {
55
- if (!ssrCollector || styleResults.length === 0) return;
42
+ function useGlobalStyles(selector, styles, options) {
43
+ if (!styles) return;
44
+ if (!selector) {
45
+ console.warn("[Tasty] useGlobalStyles: selector is required and cannot be empty. Styles will not be injected.");
46
+ return;
47
+ }
48
+ const ssrCollector = getRegisteredSSRCollector();
49
+ const isServer = !ssrCollector && isServerEnvironment();
50
+ const slotKey = options?.id ?? selector;
51
+ const stylesKey = JSON.stringify(styles);
52
+ if (!ssrCollector && !isServer) {
53
+ const existing = clientGlobalEntries.get(slotKey);
54
+ if (existing && existing.stylesKey === stylesKey) return;
55
+ }
56
+ const resolvedStyles = resolveRecipes(styles);
57
+ const styleResults = renderStyles(resolvedStyles, selector);
58
+ if (styleResults.length === 0) return;
59
+ if (ssrCollector) {
56
60
  ssrCollector.collectInternals();
57
61
  const css = formatGlobalRules(styleResults);
58
62
  if (css) {
59
- const key = `global:${selector}:${css.length}:${css.slice(0, 64)}`;
63
+ const key = `global:${selector}:${hashString(css)}`;
60
64
  ssrCollector.collectGlobalStyles(key, css);
61
65
  }
62
66
  if (getConfig().autoPropertyTypes !== false) collectAutoInferredProperties(styleResults, ssrCollector, resolvedStyles);
63
- }, [
64
- ssrCollector,
65
- styleResults,
66
- selector
67
- ]);
68
- useInsertionEffect(() => {
69
- disposeRef.current?.();
70
- if (styleResults.length > 0) {
71
- const { dispose } = injectGlobal(styleResults);
72
- disposeRef.current = dispose;
73
- } else disposeRef.current = null;
74
- return () => {
75
- disposeRef.current?.();
76
- disposeRef.current = null;
77
- };
78
- }, [styleResults]);
67
+ return;
68
+ }
69
+ if (isServer) {
70
+ const rscCache = getRSCCache();
71
+ const css = formatGlobalRules(styleResults);
72
+ if (css) pushRSCCSS(rscCache, options?.id ? `__global:${options.id}` : `__global:${selector}:${hashString(css)}`, css);
73
+ if (getConfig().autoPropertyTypes !== false) collectAutoInferredPropertiesRSC(styleResults, rscCache, resolvedStyles);
74
+ return;
75
+ }
76
+ const existing = clientGlobalEntries.get(slotKey);
77
+ if (existing) existing.dispose();
78
+ const { dispose } = injectGlobal(styleResults);
79
+ clientGlobalEntries.set(slotKey, {
80
+ stylesKey,
81
+ dispose
82
+ });
79
83
  }
80
-
81
84
  //#endregion
82
85
  export { useGlobalStyles };
86
+
83
87
  //# sourceMappingURL=useGlobalStyles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useGlobalStyles.js","names":[],"sources":["../../src/hooks/useGlobalStyles.ts"],"sourcesContent":["import { useContext, useInsertionEffect, useMemo, useRef } from 'react';\n\nimport { getConfig } from '../config';\nimport { injectGlobal } from '../injector';\nimport type { StyleResult } from '../pipeline';\nimport { renderStyles } from '../pipeline';\nimport { collectAutoInferredProperties } from '../ssr/collect-auto-properties';\nimport type { ServerStyleCollector } from '../ssr/collector';\nimport { TastySSRContext } from '../ssr/context';\nimport { formatGlobalRules } from '../ssr/format-global-rules';\nimport { getRegisteredSSRCollector } from '../ssr/ssr-collector-ref';\nimport type { Styles } from '../styles/types';\nimport { resolveRecipes } from '../utils/resolve-recipes';\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 global styles for a given selector.\n * Useful for styling elements by selector without generating classNames.\n *\n * SSR-aware: when a ServerStyleCollector is available, CSS is collected\n * during the render phase instead of being injected into the DOM.\n *\n * @param selector - CSS selector to apply styles to (e.g., '.my-class', ':root', 'body')\n * @param styles - Tasty styles object\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * useGlobalStyles('.card', {\n * padding: '2x',\n * radius: '1r',\n * fill: '#white',\n * });\n *\n * return <div className=\"card\">Content</div>;\n * }\n * ```\n */\nexport function useGlobalStyles(selector: string, styles?: Styles): void {\n const ssrContextValue = useContext(TastySSRContext);\n const ssrCollector = resolveSSRCollector(ssrContextValue);\n\n const disposeRef = useRef<(() => void) | null>(null);\n\n // Resolve recipes before rendering (zero overhead if no recipes configured)\n const resolvedStyles = useMemo(() => {\n if (!styles) return styles;\n return resolveRecipes(styles);\n }, [styles]);\n\n // Render styles with the provided selector\n // Note: renderStyles overload with selector string returns StyleResult[] directly\n const styleResults = useMemo((): StyleResult[] => {\n if (!resolvedStyles) return [];\n\n if (!selector) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n '[Tasty] useGlobalStyles: selector is required and cannot be empty. ' +\n 'Styles will not be injected.',\n );\n }\n return [];\n }\n\n const result = renderStyles(resolvedStyles, selector);\n return result as StyleResult[];\n }, [resolvedStyles, selector]);\n\n // SSR path: collect CSS during render\n useMemo(() => {\n if (!ssrCollector || styleResults.length === 0) return;\n\n ssrCollector.collectInternals();\n\n const css = formatGlobalRules(styleResults);\n if (css) {\n const key = `global:${selector}:${css.length}:${css.slice(0, 64)}`;\n ssrCollector.collectGlobalStyles(key, css);\n }\n\n if (getConfig().autoPropertyTypes !== false) {\n collectAutoInferredProperties(styleResults, ssrCollector, resolvedStyles);\n }\n }, [ssrCollector, styleResults, selector]);\n\n // Client path: inject via DOM\n useInsertionEffect(() => {\n disposeRef.current?.();\n\n if (styleResults.length > 0) {\n const { dispose } = injectGlobal(styleResults);\n disposeRef.current = dispose;\n } else {\n disposeRef.current = null;\n }\n\n return () => {\n disposeRef.current?.();\n disposeRef.current = null;\n };\n }, [styleResults]);\n}\n"],"mappings":";;;;;;;;;;;AAcA,SAAS,oBACP,cAC6B;AAC7B,KAAI,aAAc,QAAO;AACzB,QAAO,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;AA0BpC,SAAgB,gBAAgB,UAAkB,QAAuB;CAEvE,MAAM,eAAe,oBADG,WAAW,gBAAgB,CACM;CAEzD,MAAM,aAAa,OAA4B,KAAK;CAGpD,MAAM,iBAAiB,cAAc;AACnC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,eAAe,OAAO;IAC5B,CAAC,OAAO,CAAC;CAIZ,MAAM,eAAe,cAA6B;AAChD,MAAI,CAAC,eAAgB,QAAO,EAAE;AAE9B,MAAI,CAAC,UAAU;AAEX,WAAQ,KACN,kGAED;AAEH,UAAO,EAAE;;AAIX,SADe,aAAa,gBAAgB,SAAS;IAEpD,CAAC,gBAAgB,SAAS,CAAC;AAG9B,eAAc;AACZ,MAAI,CAAC,gBAAgB,aAAa,WAAW,EAAG;AAEhD,eAAa,kBAAkB;EAE/B,MAAM,MAAM,kBAAkB,aAAa;AAC3C,MAAI,KAAK;GACP,MAAM,MAAM,UAAU,SAAS,GAAG,IAAI,OAAO,GAAG,IAAI,MAAM,GAAG,GAAG;AAChE,gBAAa,oBAAoB,KAAK,IAAI;;AAG5C,MAAI,WAAW,CAAC,sBAAsB,MACpC,+BAA8B,cAAc,cAAc,eAAe;IAE1E;EAAC;EAAc;EAAc;EAAS,CAAC;AAG1C,0BAAyB;AACvB,aAAW,WAAW;AAEtB,MAAI,aAAa,SAAS,GAAG;GAC3B,MAAM,EAAE,YAAY,aAAa,aAAa;AAC9C,cAAW,UAAU;QAErB,YAAW,UAAU;AAGvB,eAAa;AACX,cAAW,WAAW;AACtB,cAAW,UAAU;;IAEtB,CAAC,aAAa,CAAC"}
1
+ {"version":3,"file":"useGlobalStyles.js","names":[],"sources":["../../src/hooks/useGlobalStyles.ts"],"sourcesContent":["import { getConfig } from '../config';\nimport { injectGlobal } from '../injector';\nimport type { StyleResult } from '../pipeline';\nimport { renderStyles } from '../pipeline';\nimport { getRSCCache, isServerEnvironment, pushRSCCSS } from '../rsc-cache';\nimport {\n collectAutoInferredProperties,\n collectAutoInferredPropertiesRSC,\n} from '../ssr/collect-auto-properties';\nimport { formatGlobalRules } from '../ssr/format-global-rules';\nimport { getRegisteredSSRCollector } from '../ssr/ssr-collector-ref';\nimport type { Styles } from '../styles/types';\nimport { hashString } from '../utils/hash';\nimport { resolveRecipes } from '../utils/resolve-recipes';\n\ninterface UseGlobalStylesOptions {\n /**\n * Stable identifier for update tracking (client-only). When provided,\n * changing the styles will dispose the previous injection and inject the\n * new one. Without an id, the selector is used as the slot key.\n * In RSC mode, renders are single-pass so update tracking does not apply.\n */\n id?: string;\n}\n\ninterface ClientGlobalEntry {\n stylesKey: string;\n dispose: () => void;\n}\n\nconst clientGlobalEntries = new Map<string, ClientGlobalEntry>();\n\n/* @internal — used only for tests */\nexport function _resetGlobalStylesCache(): void {\n clientGlobalEntries.clear();\n}\n\n/**\n * Inject global styles for a given selector.\n * Useful for styling elements by selector without generating classNames.\n *\n * SSR-aware: when a ServerStyleCollector is available, CSS is collected\n * during the render phase instead of being injected into the DOM.\n *\n * Works in all environments: client, SSR with collector, and React Server Components.\n *\n * Injected styles are permanent — they are not cleaned up on component unmount.\n * Use the `id` option for update tracking when styles change over the\n * component lifecycle.\n *\n * @param selector - CSS selector to apply styles to (e.g., '.my-class', ':root', 'body')\n * @param styles - Tasty styles object\n * @param options - Optional settings including `id` for update tracking\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * useGlobalStyles('.card', {\n * padding: '2x',\n * radius: '1r',\n * fill: '#white',\n * });\n *\n * return <div className=\"card\">Content</div>;\n * }\n * ```\n */\nexport function useGlobalStyles(\n selector: string,\n styles?: Styles,\n options?: UseGlobalStylesOptions,\n): void {\n if (!styles) return;\n\n if (!selector) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n '[Tasty] useGlobalStyles: selector is required and cannot be empty. ' +\n 'Styles will not be injected.',\n );\n }\n return;\n }\n\n const ssrCollector = getRegisteredSSRCollector();\n const isServer = !ssrCollector && isServerEnvironment();\n\n const slotKey = options?.id ?? selector;\n const stylesKey = JSON.stringify(styles);\n\n // Client fast path: skip resolveRecipes/renderStyles if styles haven't changed\n if (!ssrCollector && !isServer) {\n const existing = clientGlobalEntries.get(slotKey);\n if (existing && existing.stylesKey === stylesKey) return;\n }\n\n const resolvedStyles = resolveRecipes(styles);\n\n const styleResults = renderStyles(resolvedStyles, selector) as StyleResult[];\n\n if (styleResults.length === 0) return;\n\n if (ssrCollector) {\n ssrCollector.collectInternals();\n\n const css = formatGlobalRules(styleResults);\n if (css) {\n const key = `global:${selector}:${hashString(css)}`;\n ssrCollector.collectGlobalStyles(key, css);\n }\n\n if (getConfig().autoPropertyTypes !== false) {\n collectAutoInferredProperties(styleResults, ssrCollector, resolvedStyles);\n }\n return;\n }\n\n if (isServer) {\n const rscCache = getRSCCache();\n const css = formatGlobalRules(styleResults);\n if (css) {\n const key = options?.id\n ? `__global:${options.id}`\n : `__global:${selector}:${hashString(css)}`;\n pushRSCCSS(rscCache, key, css);\n }\n\n if (getConfig().autoPropertyTypes !== false) {\n collectAutoInferredPropertiesRSC(styleResults, rscCache, resolvedStyles);\n }\n return;\n }\n\n // Client path\n const existing = clientGlobalEntries.get(slotKey);\n if (existing) {\n existing.dispose();\n }\n\n const { dispose } = injectGlobal(styleResults);\n clientGlobalEntries.set(slotKey, { stylesKey, dispose });\n}\n"],"mappings":";;;;;;;;;;AA8BA,MAAM,sCAAsB,IAAI,KAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqChE,SAAgB,gBACd,UACA,QACA,SACM;AACN,KAAI,CAAC,OAAQ;AAEb,KAAI,CAAC,UAAU;AAEX,UAAQ,KACN,kGAED;AAEH;;CAGF,MAAM,eAAe,2BAA2B;CAChD,MAAM,WAAW,CAAC,gBAAgB,qBAAqB;CAEvD,MAAM,UAAU,SAAS,MAAM;CAC/B,MAAM,YAAY,KAAK,UAAU,OAAO;AAGxC,KAAI,CAAC,gBAAgB,CAAC,UAAU;EAC9B,MAAM,WAAW,oBAAoB,IAAI,QAAQ;AACjD,MAAI,YAAY,SAAS,cAAc,UAAW;;CAGpD,MAAM,iBAAiB,eAAe,OAAO;CAE7C,MAAM,eAAe,aAAa,gBAAgB,SAAS;AAE3D,KAAI,aAAa,WAAW,EAAG;AAE/B,KAAI,cAAc;AAChB,eAAa,kBAAkB;EAE/B,MAAM,MAAM,kBAAkB,aAAa;AAC3C,MAAI,KAAK;GACP,MAAM,MAAM,UAAU,SAAS,GAAG,WAAW,IAAI;AACjD,gBAAa,oBAAoB,KAAK,IAAI;;AAG5C,MAAI,WAAW,CAAC,sBAAsB,MACpC,+BAA8B,cAAc,cAAc,eAAe;AAE3E;;AAGF,KAAI,UAAU;EACZ,MAAM,WAAW,aAAa;EAC9B,MAAM,MAAM,kBAAkB,aAAa;AAC3C,MAAI,IAIF,YAAW,UAHC,SAAS,KACjB,YAAY,QAAQ,OACpB,YAAY,SAAS,GAAG,WAAW,IAAI,IACjB,IAAI;AAGhC,MAAI,WAAW,CAAC,sBAAsB,MACpC,kCAAiC,cAAc,UAAU,eAAe;AAE1E;;CAIF,MAAM,WAAW,oBAAoB,IAAI,QAAQ;AACjD,KAAI,SACF,UAAS,SAAS;CAGpB,MAAM,EAAE,YAAY,aAAa,aAAa;AAC9C,qBAAoB,IAAI,SAAS;EAAE;EAAW;EAAS,CAAC"}
@@ -6,8 +6,10 @@ interface UseKeyframesOptions {
6
6
  root?: Document | ShadowRoot;
7
7
  }
8
8
  /**
9
- * Hook to inject CSS @keyframes and return the generated animation name.
10
- * Handles keyframes injection with proper cleanup on unmount or dependency changes.
9
+ * Inject CSS @keyframes and return the generated animation name.
10
+ * Deduplicates by content — identical steps always return the same name.
11
+ *
12
+ * Works in all environments: client, SSR with collector, and React Server Components.
11
13
  *
12
14
  * @example Basic usage - steps object is the dependency
13
15
  * ```tsx
@@ -1,69 +1,44 @@
1
1
  import { keyframes } from "../injector/index.js";
2
- import { TastySSRContext } from "../ssr/context.js";
2
+ import { getRSCCache, isServerEnvironment, pushRSCCSS } from "../rsc-cache.js";
3
3
  import { formatKeyframesCSS } from "../ssr/format-keyframes.js";
4
4
  import { getRegisteredSSRCollector } from "../ssr/ssr-collector-ref.js";
5
- import { useContext, useInsertionEffect, useMemo, useRef } from "react";
6
-
7
5
  //#region src/hooks/useKeyframes.ts
8
- function resolveSSRCollector(reactContext) {
9
- if (reactContext) return reactContext;
10
- return getRegisteredSSRCollector();
11
- }
6
+ const clientContentToName = /* @__PURE__ */ new Map();
12
7
  function useKeyframes(stepsOrFactory, depsOrOptions, options) {
13
- const ssrCollector = resolveSSRCollector(useContext(TastySSRContext));
14
8
  const isFactory = typeof stepsOrFactory === "function";
15
- const deps = isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : void 0;
16
9
  const opts = isFactory ? options : depsOrOptions;
17
- const stepsData = useMemo(() => {
18
- const steps = isFactory ? stepsOrFactory() : stepsOrFactory;
19
- if (!steps || Object.keys(steps).length === 0) return null;
20
- return steps;
21
- }, isFactory ? deps ?? [] : [stepsOrFactory]);
22
- const renderResultRef = useRef(null);
23
- const effectResultRef = useRef(null);
24
- const name = useMemo(() => {
25
- if (!stepsData) return "";
26
- if (ssrCollector) {
27
- const actualName = ssrCollector.allocateKeyframeName(opts?.name);
28
- const css = formatKeyframesCSS(actualName, stepsData);
29
- ssrCollector.collectKeyframes(actualName, css);
30
- return actualName;
31
- }
32
- renderResultRef.current?.dispose();
33
- renderResultRef.current = null;
34
- const result = keyframes(stepsData, {
35
- name: opts?.name,
36
- root: opts?.root
37
- });
38
- renderResultRef.current = result;
39
- return result.toString();
40
- }, [
41
- stepsData,
42
- opts?.name,
43
- opts?.root,
44
- ssrCollector
45
- ]);
46
- useInsertionEffect(() => {
47
- effectResultRef.current?.dispose();
48
- effectResultRef.current = null;
49
- if (stepsData) effectResultRef.current = keyframes(stepsData, {
50
- name: opts?.name,
51
- root: opts?.root
52
- });
53
- return () => {
54
- effectResultRef.current?.dispose();
55
- effectResultRef.current = null;
56
- renderResultRef.current?.dispose();
57
- renderResultRef.current = null;
58
- };
59
- }, [
60
- stepsData,
61
- opts?.name,
62
- opts?.root
63
- ]);
10
+ const steps = isFactory ? stepsOrFactory() : stepsOrFactory;
11
+ if (!steps || Object.keys(steps).length === 0) return "";
12
+ const ssrCollector = getRegisteredSSRCollector();
13
+ if (ssrCollector) {
14
+ const actualName = ssrCollector.allocateKeyframeName(opts?.name);
15
+ const css = formatKeyframesCSS(actualName, steps);
16
+ ssrCollector.collectKeyframes(actualName, css);
17
+ return actualName;
18
+ }
19
+ if (isServerEnvironment()) {
20
+ const rscCache = getRSCCache();
21
+ const contentHash = JSON.stringify(steps);
22
+ const key = `__kf:${opts?.name ?? ""}:${contentHash}`;
23
+ const existingName = rscCache.generatedNames.get(key);
24
+ if (existingName) return existingName;
25
+ const actualName = opts?.name ?? `k${rscCache.keyframesCounter++}`;
26
+ pushRSCCSS(rscCache, key, formatKeyframesCSS(actualName, steps));
27
+ rscCache.generatedNames.set(key, actualName);
28
+ return actualName;
29
+ }
30
+ const contentHash = JSON.stringify(steps);
31
+ const cacheKey = `${opts?.name ?? ""}:${contentHash}`;
32
+ const cachedName = clientContentToName.get(cacheKey);
33
+ if (cachedName) return cachedName;
34
+ const name = keyframes(steps, {
35
+ name: opts?.name,
36
+ root: opts?.root
37
+ }).toString();
38
+ clientContentToName.set(cacheKey, name);
64
39
  return name;
65
40
  }
66
-
67
41
  //#endregion
68
42
  export { useKeyframes };
43
+
69
44
  //# sourceMappingURL=useKeyframes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useKeyframes.js","names":[],"sources":["../../src/hooks/useKeyframes.ts"],"sourcesContent":["import { useContext, useInsertionEffect, useMemo, useRef } from 'react';\n\nimport { keyframes } from '../injector';\nimport type { KeyframesResult, KeyframesSteps } from '../injector/types';\nimport type { ServerStyleCollector } from '../ssr/collector';\nimport { TastySSRContext } from '../ssr/context';\nimport { formatKeyframesCSS } from '../ssr/format-keyframes';\nimport { getRegisteredSSRCollector } from '../ssr/ssr-collector-ref';\n\ninterface UseKeyframesOptions {\n name?: string;\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 CSS @keyframes and return the generated animation name.\n * Handles keyframes injection with proper cleanup on unmount or dependency changes.\n *\n * @example Basic usage - steps object is the dependency\n * ```tsx\n * function MyComponent() {\n * const bounce = useKeyframes({\n * '0%': { transform: 'scale(1)' },\n * '50%': { transform: 'scale(1.1)' },\n * '100%': { transform: 'scale(1)' },\n * });\n *\n * return <div style={{ animation: `${bounce} 1s infinite` }}>Bouncing</div>;\n * }\n * ```\n *\n * @example With custom name\n * ```tsx\n * function MyComponent() {\n * const fadeIn = useKeyframes(\n * { from: { opacity: 0 }, to: { opacity: 1 } },\n * { name: 'fadeIn' }\n * );\n *\n * return <div style={{ animation: `${fadeIn} 0.3s ease-out` }}>Fading in</div>;\n * }\n * ```\n *\n * @example Factory function with dependencies\n * ```tsx\n * function MyComponent({ scale }: { scale: number }) {\n * const pulse = useKeyframes(\n * () => ({\n * '0%': { transform: 'scale(1)' },\n * '100%': { transform: `scale(${scale})` },\n * }),\n * [scale]\n * );\n *\n * return <div style={{ animation: `${pulse} 1s infinite` }}>Pulsing</div>;\n * }\n * ```\n */\n\n// Overload 1: Static steps object\nexport function useKeyframes(\n steps: KeyframesSteps,\n options?: UseKeyframesOptions,\n): string;\n\n// Overload 2: Factory function with dependencies\nexport function useKeyframes(\n factory: () => KeyframesSteps,\n deps: readonly unknown[],\n options?: UseKeyframesOptions,\n): string;\n\n// Implementation\nexport function useKeyframes(\n stepsOrFactory: KeyframesSteps | (() => KeyframesSteps),\n depsOrOptions?: readonly unknown[] | UseKeyframesOptions,\n options?: UseKeyframesOptions,\n): string {\n const ssrContextValue = useContext(TastySSRContext);\n const ssrCollector = resolveSSRCollector(ssrContextValue);\n\n // Detect which overload is being used\n const isFactory = typeof stepsOrFactory === '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 UseKeyframesOptions | undefined);\n\n // Memoize the keyframes steps to get a stable reference\n const stepsData = useMemo(\n () => {\n const steps = isFactory\n ? (stepsOrFactory as () => KeyframesSteps)()\n : (stepsOrFactory as KeyframesSteps);\n\n if (!steps || Object.keys(steps).length === 0) {\n return null;\n }\n\n return steps;\n },\n\n isFactory ? (deps ?? []) : [stepsOrFactory],\n );\n\n // Store keyframes results for cleanup (client only)\n const renderResultRef = useRef<KeyframesResult | null>(null);\n const effectResultRef = useRef<KeyframesResult | null>(null);\n\n const name = useMemo(() => {\n if (!stepsData) {\n return '';\n }\n\n // SSR path: format and collect, return name without DOM injection\n if (ssrCollector) {\n const actualName = ssrCollector.allocateKeyframeName(opts?.name);\n const css = formatKeyframesCSS(actualName, stepsData);\n ssrCollector.collectKeyframes(actualName, css);\n return actualName;\n }\n\n // Client path: inject keyframes synchronously for immediate name availability\n renderResultRef.current?.dispose();\n renderResultRef.current = null;\n\n const result = keyframes(stepsData, {\n name: opts?.name,\n root: opts?.root,\n });\n\n renderResultRef.current = result;\n\n return result.toString();\n }, [stepsData, opts?.name, opts?.root, ssrCollector]);\n\n // Client path: handle Strict Mode double-invocation and cleanup\n useInsertionEffect(() => {\n effectResultRef.current?.dispose();\n effectResultRef.current = null;\n\n if (stepsData) {\n const result = keyframes(stepsData, {\n name: opts?.name,\n root: opts?.root,\n });\n effectResultRef.current = result;\n }\n\n return () => {\n effectResultRef.current?.dispose();\n effectResultRef.current = null;\n renderResultRef.current?.dispose();\n renderResultRef.current = null;\n };\n }, [stepsData, opts?.name, opts?.root]);\n\n return name;\n}\n"],"mappings":";;;;;;;AAcA,SAAS,oBACP,cAC6B;AAC7B,KAAI,aAAc,QAAO;AACzB,QAAO,2BAA2B;;AA8DpC,SAAgB,aACd,gBACA,eACA,SACQ;CAER,MAAM,eAAe,oBADG,WAAW,gBAAgB,CACM;CAGzD,MAAM,YAAY,OAAO,mBAAmB;CAG5C,MAAM,OACJ,aAAa,MAAM,QAAQ,cAAc,GAAG,gBAAgB;CAC9D,MAAM,OAAO,YACT,UACC;CAGL,MAAM,YAAY,cACV;EACJ,MAAM,QAAQ,YACT,gBAAyC,GACzC;AAEL,MAAI,CAAC,SAAS,OAAO,KAAK,MAAM,CAAC,WAAW,EAC1C,QAAO;AAGT,SAAO;IAGT,YAAa,QAAQ,EAAE,GAAI,CAAC,eAAe,CAC5C;CAGD,MAAM,kBAAkB,OAA+B,KAAK;CAC5D,MAAM,kBAAkB,OAA+B,KAAK;CAE5D,MAAM,OAAO,cAAc;AACzB,MAAI,CAAC,UACH,QAAO;AAIT,MAAI,cAAc;GAChB,MAAM,aAAa,aAAa,qBAAqB,MAAM,KAAK;GAChE,MAAM,MAAM,mBAAmB,YAAY,UAAU;AACrD,gBAAa,iBAAiB,YAAY,IAAI;AAC9C,UAAO;;AAIT,kBAAgB,SAAS,SAAS;AAClC,kBAAgB,UAAU;EAE1B,MAAM,SAAS,UAAU,WAAW;GAClC,MAAM,MAAM;GACZ,MAAM,MAAM;GACb,CAAC;AAEF,kBAAgB,UAAU;AAE1B,SAAO,OAAO,UAAU;IACvB;EAAC;EAAW,MAAM;EAAM,MAAM;EAAM;EAAa,CAAC;AAGrD,0BAAyB;AACvB,kBAAgB,SAAS,SAAS;AAClC,kBAAgB,UAAU;AAE1B,MAAI,UAKF,iBAAgB,UAJD,UAAU,WAAW;GAClC,MAAM,MAAM;GACZ,MAAM,MAAM;GACb,CAAC;AAIJ,eAAa;AACX,mBAAgB,SAAS,SAAS;AAClC,mBAAgB,UAAU;AAC1B,mBAAgB,SAAS,SAAS;AAClC,mBAAgB,UAAU;;IAE3B;EAAC;EAAW,MAAM;EAAM,MAAM;EAAK,CAAC;AAEvC,QAAO"}
1
+ {"version":3,"file":"useKeyframes.js","names":[],"sources":["../../src/hooks/useKeyframes.ts"],"sourcesContent":["import { keyframes } from '../injector';\nimport type { KeyframesSteps } from '../injector/types';\nimport { getRSCCache, isServerEnvironment, pushRSCCSS } from '../rsc-cache';\nimport { formatKeyframesCSS } from '../ssr/format-keyframes';\nimport { getRegisteredSSRCollector } from '../ssr/ssr-collector-ref';\n\ninterface UseKeyframesOptions {\n name?: string;\n root?: Document | ShadowRoot;\n}\n\nconst clientContentToName = new Map<string, string>();\n\n/* @internal — used only for tests */\nexport function _resetKeyframesCache(): void {\n clientContentToName.clear();\n}\n\n/**\n * Inject CSS @keyframes and return the generated animation name.\n * Deduplicates by content — identical steps always return the same name.\n *\n * Works in all environments: client, SSR with collector, and React Server Components.\n *\n * @example Basic usage - steps object is the dependency\n * ```tsx\n * function MyComponent() {\n * const bounce = useKeyframes({\n * '0%': { transform: 'scale(1)' },\n * '50%': { transform: 'scale(1.1)' },\n * '100%': { transform: 'scale(1)' },\n * });\n *\n * return <div style={{ animation: `${bounce} 1s infinite` }}>Bouncing</div>;\n * }\n * ```\n *\n * @example With custom name\n * ```tsx\n * function MyComponent() {\n * const fadeIn = useKeyframes(\n * { from: { opacity: 0 }, to: { opacity: 1 } },\n * { name: 'fadeIn' }\n * );\n *\n * return <div style={{ animation: `${fadeIn} 0.3s ease-out` }}>Fading in</div>;\n * }\n * ```\n *\n * @example Factory function with dependencies\n * ```tsx\n * function MyComponent({ scale }: { scale: number }) {\n * const pulse = useKeyframes(\n * () => ({\n * '0%': { transform: 'scale(1)' },\n * '100%': { transform: `scale(${scale})` },\n * }),\n * [scale]\n * );\n *\n * return <div style={{ animation: `${pulse} 1s infinite` }}>Pulsing</div>;\n * }\n * ```\n */\n\n// Overload 1: Static steps object\nexport function useKeyframes(\n steps: KeyframesSteps,\n options?: UseKeyframesOptions,\n): string;\n\n// Overload 2: Factory function with dependencies\nexport function useKeyframes(\n factory: () => KeyframesSteps,\n deps: readonly unknown[],\n options?: UseKeyframesOptions,\n): string;\n\n// Implementation\nexport function useKeyframes(\n stepsOrFactory: KeyframesSteps | (() => KeyframesSteps),\n depsOrOptions?: readonly unknown[] | UseKeyframesOptions,\n options?: UseKeyframesOptions,\n): string {\n const isFactory = typeof stepsOrFactory === 'function';\n\n const opts = isFactory\n ? options\n : (depsOrOptions as UseKeyframesOptions | undefined);\n\n const steps = isFactory\n ? (stepsOrFactory as () => KeyframesSteps)()\n : (stepsOrFactory as KeyframesSteps);\n\n if (!steps || Object.keys(steps).length === 0) {\n return '';\n }\n\n const ssrCollector = getRegisteredSSRCollector();\n\n if (ssrCollector) {\n const actualName = ssrCollector.allocateKeyframeName(opts?.name);\n const css = formatKeyframesCSS(actualName, steps);\n ssrCollector.collectKeyframes(actualName, css);\n return actualName;\n }\n\n if (isServerEnvironment()) {\n const rscCache = getRSCCache();\n const contentHash = JSON.stringify(steps);\n const key = `__kf:${opts?.name ?? ''}:${contentHash}`;\n\n const existingName = rscCache.generatedNames.get(key);\n if (existingName) return existingName;\n\n const actualName = opts?.name ?? `k${rscCache.keyframesCounter++}`;\n const css = formatKeyframesCSS(actualName, steps);\n pushRSCCSS(rscCache, key, css);\n rscCache.generatedNames.set(key, actualName);\n return actualName;\n }\n\n // Client path: stable name via content-based dedup\n const contentHash = JSON.stringify(steps);\n const cacheKey = `${opts?.name ?? ''}:${contentHash}`;\n\n const cachedName = clientContentToName.get(cacheKey);\n if (cachedName) {\n return cachedName;\n }\n\n const result = keyframes(steps, {\n name: opts?.name,\n root: opts?.root,\n });\n\n const name = result.toString();\n clientContentToName.set(cacheKey, name);\n\n return name;\n}\n"],"mappings":";;;;;AAWA,MAAM,sCAAsB,IAAI,KAAqB;AAoErD,SAAgB,aACd,gBACA,eACA,SACQ;CACR,MAAM,YAAY,OAAO,mBAAmB;CAE5C,MAAM,OAAO,YACT,UACC;CAEL,MAAM,QAAQ,YACT,gBAAyC,GACzC;AAEL,KAAI,CAAC,SAAS,OAAO,KAAK,MAAM,CAAC,WAAW,EAC1C,QAAO;CAGT,MAAM,eAAe,2BAA2B;AAEhD,KAAI,cAAc;EAChB,MAAM,aAAa,aAAa,qBAAqB,MAAM,KAAK;EAChE,MAAM,MAAM,mBAAmB,YAAY,MAAM;AACjD,eAAa,iBAAiB,YAAY,IAAI;AAC9C,SAAO;;AAGT,KAAI,qBAAqB,EAAE;EACzB,MAAM,WAAW,aAAa;EAC9B,MAAM,cAAc,KAAK,UAAU,MAAM;EACzC,MAAM,MAAM,QAAQ,MAAM,QAAQ,GAAG,GAAG;EAExC,MAAM,eAAe,SAAS,eAAe,IAAI,IAAI;AACrD,MAAI,aAAc,QAAO;EAEzB,MAAM,aAAa,MAAM,QAAQ,IAAI,SAAS;AAE9C,aAAW,UAAU,KADT,mBAAmB,YAAY,MAAM,CACnB;AAC9B,WAAS,eAAe,IAAI,KAAK,WAAW;AAC5C,SAAO;;CAIT,MAAM,cAAc,KAAK,UAAU,MAAM;CACzC,MAAM,WAAW,GAAG,MAAM,QAAQ,GAAG,GAAG;CAExC,MAAM,aAAa,oBAAoB,IAAI,SAAS;AACpD,KAAI,WACF,QAAO;CAQT,MAAM,OALS,UAAU,OAAO;EAC9B,MAAM,MAAM;EACZ,MAAM,MAAM;EACb,CAAC,CAEkB,UAAU;AAC9B,qBAAoB,IAAI,UAAU,KAAK;AAEvC,QAAO"}
@@ -22,17 +22,19 @@ interface UsePropertyOptions {
22
22
  root?: Document | ShadowRoot;
23
23
  }
24
24
  /**
25
- * Hook to register a CSS @property custom property.
25
+ * Register a CSS @property custom property.
26
26
  * This enables advanced features like animating custom properties.
27
27
  *
28
28
  * Note: @property rules are global and persistent once defined.
29
- * The hook ensures the property is only registered once per root.
29
+ * The function ensures the property is only registered once per root.
30
30
  *
31
31
  * Accepts tasty token syntax for the property name:
32
32
  * - `$name` → defines `--name`
33
33
  * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
34
34
  * - `--name` → defines `--name` (legacy format)
35
35
  *
36
+ * Works in all environments: client, SSR with collector, and React Server Components.
37
+ *
36
38
  * @param name - The property token ($name, #name) or CSS property name (--name)
37
39
  * @param options - Property configuration
38
40
  *
@@ -1,26 +1,22 @@
1
1
  import { getGlobalInjector } from "../config.js";
2
+ import { getRSCCache, isServerEnvironment, pushRSCCSS } from "../rsc-cache.js";
2
3
  import { formatPropertyCSS } from "../ssr/format-property.js";
3
- import { TastySSRContext } from "../ssr/context.js";
4
4
  import { getRegisteredSSRCollector } from "../ssr/ssr-collector-ref.js";
5
- import { useContext, useInsertionEffect, useMemo } from "react";
6
-
7
5
  //#region src/hooks/useProperty.ts
8
- function resolveSSRCollector(reactContext) {
9
- if (reactContext) return reactContext;
10
- return getRegisteredSSRCollector();
11
- }
12
6
  /**
13
- * Hook to register a CSS @property custom property.
7
+ * Register a CSS @property custom property.
14
8
  * This enables advanced features like animating custom properties.
15
9
  *
16
10
  * Note: @property rules are global and persistent once defined.
17
- * The hook ensures the property is only registered once per root.
11
+ * The function ensures the property is only registered once per root.
18
12
  *
19
13
  * Accepts tasty token syntax for the property name:
20
14
  * - `$name` → defines `--name`
21
15
  * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
22
16
  * - `--name` → defines `--name` (legacy format)
23
17
  *
18
+ * Works in all environments: client, SSR with collector, and React Server Components.
19
+ *
24
20
  * @param name - The property token ($name, #name) or CSS property name (--name)
25
21
  * @param options - Property configuration
26
22
  *
@@ -62,21 +58,12 @@ function resolveSSRCollector(reactContext) {
62
58
  * ```
63
59
  */
64
60
  function useProperty(name, options) {
65
- const ssrCollector = resolveSSRCollector(useContext(TastySSRContext));
66
- const optionsKey = useMemo(() => {
67
- if (!options) return "";
68
- return JSON.stringify({
69
- syntax: options.syntax,
70
- inherits: options.inherits,
71
- initialValue: options.initialValue
72
- });
73
- }, [
74
- options?.syntax,
75
- options?.inherits,
76
- options?.initialValue
77
- ]);
78
- useMemo(() => {
79
- if (!ssrCollector || !name) return;
61
+ if (!name) {
62
+ console.warn(`[Tasty] useProperty: property name is required`);
63
+ return;
64
+ }
65
+ const ssrCollector = getRegisteredSSRCollector();
66
+ if (ssrCollector) {
80
67
  ssrCollector.collectInternals();
81
68
  const css = formatPropertyCSS(name, {
82
69
  syntax: options?.syntax,
@@ -84,31 +71,28 @@ function useProperty(name, options) {
84
71
  initialValue: options?.initialValue
85
72
  });
86
73
  if (css) ssrCollector.collectProperty(name, css);
87
- }, [
88
- ssrCollector,
89
- name,
90
- optionsKey
91
- ]);
92
- useInsertionEffect(() => {
93
- if (!name) {
94
- console.warn(`[Tasty] useProperty: property name is required`);
95
- return;
96
- }
97
- const injector = getGlobalInjector();
98
- if (injector.isPropertyDefined(name, { root: options?.root })) return;
99
- injector.property(name, {
74
+ return;
75
+ }
76
+ if (isServerEnvironment()) {
77
+ const rscCache = getRSCCache();
78
+ const css = formatPropertyCSS(name, {
100
79
  syntax: options?.syntax,
101
80
  inherits: options?.inherits,
102
- initialValue: options?.initialValue,
103
- root: options?.root
81
+ initialValue: options?.initialValue
104
82
  });
105
- }, [
106
- name,
107
- optionsKey,
108
- options?.root
109
- ]);
83
+ if (css) pushRSCCSS(rscCache, `__prop:${name}`, css);
84
+ return;
85
+ }
86
+ const injector = getGlobalInjector();
87
+ if (injector.isPropertyDefined(name, { root: options?.root })) return;
88
+ injector.property(name, {
89
+ syntax: options?.syntax,
90
+ inherits: options?.inherits,
91
+ initialValue: options?.initialValue,
92
+ root: options?.root
93
+ });
110
94
  }
111
-
112
95
  //#endregion
113
96
  export { useProperty };
97
+
114
98
  //# sourceMappingURL=useProperty.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useProperty.js","names":[],"sources":["../../src/hooks/useProperty.ts"],"sourcesContent":["import { useContext, useInsertionEffect, useMemo } from 'react';\n\nimport { getGlobalInjector } from '../config';\nimport type { ServerStyleCollector } from '../ssr/collector';\nimport { TastySSRContext } from '../ssr/context';\nimport { formatPropertyCSS } from '../ssr/format-property';\nimport { getRegisteredSSRCollector } from '../ssr/ssr-collector-ref';\n\nfunction resolveSSRCollector(\n reactContext: ServerStyleCollector | null,\n): ServerStyleCollector | null {\n if (reactContext) return reactContext;\n return getRegisteredSSRCollector();\n}\n\nexport interface UsePropertyOptions {\n /**\n * CSS syntax string for the property (e.g., '<color>', '<length>', '<angle>').\n * For color tokens (#name), this is auto-set to '<color>' and cannot be overridden.\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 * For color tokens (#name), this defaults to 'transparent' if not specified.\n */\n initialValue?: string | number;\n /**\n * Shadow root or document to inject into\n */\n root?: Document | ShadowRoot;\n}\n\n/**\n * Hook to register 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 * The hook ensures the property is only registered once per root.\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 * @param name - The property token ($name, #name) or CSS property name (--name)\n * @param options - Property configuration\n *\n * @example Basic property with token syntax\n * ```tsx\n * function Spinner() {\n * useProperty('$rotation', {\n * syntax: '<angle>',\n * inherits: false,\n * initialValue: '0deg',\n * });\n *\n * return <div className=\"spinner\" />;\n * }\n * ```\n *\n * @example Color property with token syntax (auto-sets syntax)\n * ```tsx\n * function MyComponent() {\n * useProperty('#theme', {\n * initialValue: 'red', // syntax: '<color>' is auto-set\n * });\n *\n * // Now --theme-color can be animated with CSS transitions\n * return <div style={{ '--theme-color': 'blue' } as React.CSSProperties}>Colored</div>;\n * }\n * ```\n *\n * @example Legacy format (still supported)\n * ```tsx\n * function ResizableBox() {\n * useProperty('--box-size', {\n * syntax: '<length>',\n * initialValue: '100px',\n * });\n *\n * return <div style={{ width: 'var(--box-size)' }} />;\n * }\n * ```\n */\nexport function useProperty(name: string, options?: UsePropertyOptions): void {\n const ssrContextValue = useContext(TastySSRContext);\n const ssrCollector = resolveSSRCollector(ssrContextValue);\n\n // Memoize the options to create a stable dependency\n const optionsKey = useMemo(() => {\n if (!options) return '';\n return JSON.stringify({\n syntax: options.syntax,\n inherits: options.inherits,\n initialValue: options.initialValue,\n });\n }, [options?.syntax, options?.inherits, options?.initialValue]);\n\n // SSR path: collect @property CSS during render\n useMemo(() => {\n if (!ssrCollector || !name) return;\n\n ssrCollector.collectInternals();\n\n const css = formatPropertyCSS(name, {\n syntax: options?.syntax,\n inherits: options?.inherits,\n initialValue: options?.initialValue,\n });\n if (css) {\n ssrCollector.collectProperty(name, css);\n }\n }, [ssrCollector, name, optionsKey]);\n\n // Client path: inject via DOM\n useInsertionEffect(() => {\n if (!name) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`[Tasty] useProperty: property name is required`);\n }\n return;\n }\n\n const injector = getGlobalInjector();\n\n if (injector.isPropertyDefined(name, { root: options?.root })) {\n return;\n }\n\n injector.property(name, {\n syntax: options?.syntax,\n inherits: options?.inherits,\n initialValue: options?.initialValue,\n root: options?.root,\n });\n }, [name, optionsKey, options?.root]);\n}\n"],"mappings":";;;;;;;AAQA,SAAS,oBACP,cAC6B;AAC7B,KAAI,aAAc,QAAO;AACzB,QAAO,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8EpC,SAAgB,YAAY,MAAc,SAAoC;CAE5E,MAAM,eAAe,oBADG,WAAW,gBAAgB,CACM;CAGzD,MAAM,aAAa,cAAc;AAC/B,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,KAAK,UAAU;GACpB,QAAQ,QAAQ;GAChB,UAAU,QAAQ;GAClB,cAAc,QAAQ;GACvB,CAAC;IACD;EAAC,SAAS;EAAQ,SAAS;EAAU,SAAS;EAAa,CAAC;AAG/D,eAAc;AACZ,MAAI,CAAC,gBAAgB,CAAC,KAAM;AAE5B,eAAa,kBAAkB;EAE/B,MAAM,MAAM,kBAAkB,MAAM;GAClC,QAAQ,SAAS;GACjB,UAAU,SAAS;GACnB,cAAc,SAAS;GACxB,CAAC;AACF,MAAI,IACF,cAAa,gBAAgB,MAAM,IAAI;IAExC;EAAC;EAAc;EAAM;EAAW,CAAC;AAGpC,0BAAyB;AACvB,MAAI,CAAC,MAAM;AAEP,WAAQ,KAAK,iDAAiD;AAEhE;;EAGF,MAAM,WAAW,mBAAmB;AAEpC,MAAI,SAAS,kBAAkB,MAAM,EAAE,MAAM,SAAS,MAAM,CAAC,CAC3D;AAGF,WAAS,SAAS,MAAM;GACtB,QAAQ,SAAS;GACjB,UAAU,SAAS;GACnB,cAAc,SAAS;GACvB,MAAM,SAAS;GAChB,CAAC;IACD;EAAC;EAAM;EAAY,SAAS;EAAK,CAAC"}
1
+ {"version":3,"file":"useProperty.js","names":[],"sources":["../../src/hooks/useProperty.ts"],"sourcesContent":["import { getGlobalInjector } from '../config';\nimport { pushRSCCSS, getRSCCache, isServerEnvironment } from '../rsc-cache';\nimport { formatPropertyCSS } from '../ssr/format-property';\nimport { getRegisteredSSRCollector } from '../ssr/ssr-collector-ref';\n\nexport interface UsePropertyOptions {\n /**\n * CSS syntax string for the property (e.g., '<color>', '<length>', '<angle>').\n * For color tokens (#name), this is auto-set to '<color>' and cannot be overridden.\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 * For color tokens (#name), this defaults to 'transparent' if not specified.\n */\n initialValue?: string | number;\n /**\n * Shadow root or document to inject into\n */\n root?: Document | ShadowRoot;\n}\n\n/**\n * Register 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 * The function ensures the property is only registered once per root.\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 * Works in all environments: client, SSR with collector, and React Server Components.\n *\n * @param name - The property token ($name, #name) or CSS property name (--name)\n * @param options - Property configuration\n *\n * @example Basic property with token syntax\n * ```tsx\n * function Spinner() {\n * useProperty('$rotation', {\n * syntax: '<angle>',\n * inherits: false,\n * initialValue: '0deg',\n * });\n *\n * return <div className=\"spinner\" />;\n * }\n * ```\n *\n * @example Color property with token syntax (auto-sets syntax)\n * ```tsx\n * function MyComponent() {\n * useProperty('#theme', {\n * initialValue: 'red', // syntax: '<color>' is auto-set\n * });\n *\n * // Now --theme-color can be animated with CSS transitions\n * return <div style={{ '--theme-color': 'blue' } as React.CSSProperties}>Colored</div>;\n * }\n * ```\n *\n * @example Legacy format (still supported)\n * ```tsx\n * function ResizableBox() {\n * useProperty('--box-size', {\n * syntax: '<length>',\n * initialValue: '100px',\n * });\n *\n * return <div style={{ width: 'var(--box-size)' }} />;\n * }\n * ```\n */\nexport function useProperty(name: string, options?: UsePropertyOptions): void {\n if (!name) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`[Tasty] useProperty: property name is required`);\n }\n return;\n }\n\n const ssrCollector = getRegisteredSSRCollector();\n\n if (ssrCollector) {\n ssrCollector.collectInternals();\n\n const css = formatPropertyCSS(name, {\n syntax: options?.syntax,\n inherits: options?.inherits,\n initialValue: options?.initialValue,\n });\n if (css) {\n ssrCollector.collectProperty(name, css);\n }\n return;\n }\n\n if (isServerEnvironment()) {\n const rscCache = getRSCCache();\n const css = formatPropertyCSS(name, {\n syntax: options?.syntax,\n inherits: options?.inherits,\n initialValue: options?.initialValue,\n });\n if (css) {\n pushRSCCSS(rscCache, `__prop:${name}`, css);\n }\n return;\n }\n\n const injector = getGlobalInjector();\n\n if (injector.isPropertyDefined(name, { root: options?.root })) {\n return;\n }\n\n injector.property(name, {\n syntax: options?.syntax,\n inherits: options?.inherits,\n initialValue: options?.initialValue,\n root: options?.root,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,YAAY,MAAc,SAAoC;AAC5E,KAAI,CAAC,MAAM;AAEP,UAAQ,KAAK,iDAAiD;AAEhE;;CAGF,MAAM,eAAe,2BAA2B;AAEhD,KAAI,cAAc;AAChB,eAAa,kBAAkB;EAE/B,MAAM,MAAM,kBAAkB,MAAM;GAClC,QAAQ,SAAS;GACjB,UAAU,SAAS;GACnB,cAAc,SAAS;GACxB,CAAC;AACF,MAAI,IACF,cAAa,gBAAgB,MAAM,IAAI;AAEzC;;AAGF,KAAI,qBAAqB,EAAE;EACzB,MAAM,WAAW,aAAa;EAC9B,MAAM,MAAM,kBAAkB,MAAM;GAClC,QAAQ,SAAS;GACjB,UAAU,SAAS;GACnB,cAAc,SAAS;GACxB,CAAC;AACF,MAAI,IACF,YAAW,UAAU,UAAU,QAAQ,IAAI;AAE7C;;CAGF,MAAM,WAAW,mBAAmB;AAEpC,KAAI,SAAS,kBAAkB,MAAM,EAAE,MAAM,SAAS,MAAM,CAAC,CAC3D;AAGF,UAAS,SAAS,MAAM;EACtB,QAAQ,SAAS;EACjB,UAAU,SAAS;EACnB,cAAc,SAAS;EACvB,MAAM,SAAS;EAChB,CAAC"}
@@ -1,51 +1,15 @@
1
1
  //#region src/hooks/useRawCSS.d.ts
2
2
  interface UseRawCSSOptions {
3
3
  root?: Document | ShadowRoot;
4
+ /**
5
+ * Stable identifier for update tracking (client-only). When provided,
6
+ * changing the CSS content will dispose the previous injection and inject
7
+ * the new one. Without an id, deduplication is purely content-based (same
8
+ * CSS is injected only once). In RSC mode, renders are single-pass so
9
+ * update tracking does not apply.
10
+ */
11
+ id?: string;
4
12
  }
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
13
  declare function useRawCSS(css: string, options?: UseRawCSSOptions): void;
50
14
  declare function useRawCSS(factory: () => string, deps: readonly unknown[], options?: UseRawCSSOptions): void;
51
15
  //#endregion