@tenphi/tasty 2.0.3 → 2.0.4

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 (322) hide show
  1. package/dist/{ssr/async-storage.js → async-storage-B7_o6FKt.js} +2 -2
  2. package/dist/async-storage-B7_o6FKt.js.map +1 -0
  3. package/dist/{ssr/collector.d.ts → collector-CkZ517g4.d.ts} +3 -3
  4. package/dist/{ssr/collector.js → collector-DXqvGOb1.js} +5 -10
  5. package/dist/collector-DXqvGOb1.js.map +1 -0
  6. package/dist/config-5jzS6k6B.js +10005 -0
  7. package/dist/config-5jzS6k6B.js.map +1 -0
  8. package/dist/config-DknGsfMo.d.ts +857 -0
  9. package/dist/{ssr/context.js → context-CkSg-kDT.js} +11 -3
  10. package/dist/context-CkSg-kDT.js.map +1 -0
  11. package/dist/core/index.d.ts +5 -34
  12. package/dist/core/index.js +5 -26
  13. package/dist/core-CtU6-9OC.js +1507 -0
  14. package/dist/core-CtU6-9OC.js.map +1 -0
  15. package/dist/{zero/extractor.js → css-writer-DHkX0JuE.js} +74 -11
  16. package/dist/css-writer-DHkX0JuE.js.map +1 -0
  17. package/dist/{ssr/format-global-rules.js → format-global-rules-Dbc_1tc3.js} +2 -2
  18. package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
  19. package/dist/format-rules-DH13ewDu.js +143 -0
  20. package/dist/format-rules-DH13ewDu.js.map +1 -0
  21. package/dist/{ssr/hydrate.js → hydrate-C1Gv-DoS.js} +3 -3
  22. package/dist/hydrate-C1Gv-DoS.js.map +1 -0
  23. package/dist/{styles/types.d.ts → index-PzENbpAq.d.ts} +701 -5
  24. package/dist/index-o7zV2yCr.d.ts +1561 -0
  25. package/dist/index.d.ts +5 -51
  26. package/dist/index.js +728 -35
  27. package/dist/index.js.map +1 -0
  28. package/dist/keyframes-b7X3UxDV.js +587 -0
  29. package/dist/keyframes-b7X3UxDV.js.map +1 -0
  30. package/dist/{utils/merge-styles.d.ts → merge-styles-C7KTy7MY.d.ts} +3 -3
  31. package/dist/{utils/merge-styles.js → merge-styles-Tgo3BbL2.js} +3 -4
  32. package/dist/merge-styles-Tgo3BbL2.js.map +1 -0
  33. package/dist/{utils/resolve-recipes.js → resolve-recipes-Ca2-5CxM.js} +4 -6
  34. package/dist/resolve-recipes-Ca2-5CxM.js.map +1 -0
  35. package/dist/ssr/astro-client.js +1 -1
  36. package/dist/ssr/astro.js +4 -4
  37. package/dist/ssr/index.d.ts +44 -4
  38. package/dist/ssr/index.js +4 -4
  39. package/dist/ssr/next.d.ts +1 -1
  40. package/dist/ssr/next.js +6 -6
  41. package/dist/ssr/next.js.map +1 -1
  42. package/dist/static/index.d.ts +91 -5
  43. package/dist/static/index.js +49 -3
  44. package/dist/static/index.js.map +1 -0
  45. package/dist/zero/babel.d.ts +1 -1
  46. package/dist/zero/babel.js +10 -6
  47. package/dist/zero/babel.js.map +1 -1
  48. package/dist/zero/index.d.ts +67 -3
  49. package/dist/zero/index.js +1 -2
  50. package/package.json +3 -3
  51. package/dist/_virtual/_rolldown/runtime.js +0 -7
  52. package/dist/chunks/cacheKey.d.ts +0 -1
  53. package/dist/chunks/cacheKey.js +0 -77
  54. package/dist/chunks/cacheKey.js.map +0 -1
  55. package/dist/chunks/definitions.d.ts +0 -37
  56. package/dist/chunks/definitions.js +0 -258
  57. package/dist/chunks/definitions.js.map +0 -1
  58. package/dist/chunks/index.d.ts +0 -1
  59. package/dist/chunks/renderChunk.d.ts +0 -1
  60. package/dist/chunks/renderChunk.js +0 -59
  61. package/dist/chunks/renderChunk.js.map +0 -1
  62. package/dist/compute-styles.d.ts +0 -31
  63. package/dist/compute-styles.js +0 -322
  64. package/dist/compute-styles.js.map +0 -1
  65. package/dist/config.d.ts +0 -407
  66. package/dist/config.js +0 -591
  67. package/dist/config.js.map +0 -1
  68. package/dist/counter-style/index.js +0 -51
  69. package/dist/counter-style/index.js.map +0 -1
  70. package/dist/debug.d.ts +0 -89
  71. package/dist/debug.js +0 -453
  72. package/dist/debug.js.map +0 -1
  73. package/dist/font-face/index.js +0 -63
  74. package/dist/font-face/index.js.map +0 -1
  75. package/dist/hooks/index.d.ts +0 -7
  76. package/dist/hooks/useCounterStyle.d.ts +0 -36
  77. package/dist/hooks/useCounterStyle.js +0 -65
  78. package/dist/hooks/useCounterStyle.js.map +0 -1
  79. package/dist/hooks/useFontFace.d.ts +0 -45
  80. package/dist/hooks/useFontFace.js +0 -66
  81. package/dist/hooks/useFontFace.js.map +0 -1
  82. package/dist/hooks/useGlobalStyles.d.ts +0 -46
  83. package/dist/hooks/useGlobalStyles.js +0 -88
  84. package/dist/hooks/useGlobalStyles.js.map +0 -1
  85. package/dist/hooks/useKeyframes.d.ts +0 -58
  86. package/dist/hooks/useKeyframes.js +0 -55
  87. package/dist/hooks/useKeyframes.js.map +0 -1
  88. package/dist/hooks/useProperty.d.ts +0 -81
  89. package/dist/hooks/useProperty.js +0 -96
  90. package/dist/hooks/useProperty.js.map +0 -1
  91. package/dist/hooks/useRawCSS.d.ts +0 -22
  92. package/dist/hooks/useRawCSS.js +0 -103
  93. package/dist/hooks/useRawCSS.js.map +0 -1
  94. package/dist/hooks/useStyles.d.ts +0 -40
  95. package/dist/hooks/useStyles.js +0 -31
  96. package/dist/hooks/useStyles.js.map +0 -1
  97. package/dist/injector/index.d.ts +0 -182
  98. package/dist/injector/index.js +0 -185
  99. package/dist/injector/index.js.map +0 -1
  100. package/dist/injector/injector.d.ts +0 -198
  101. package/dist/injector/injector.js +0 -651
  102. package/dist/injector/injector.js.map +0 -1
  103. package/dist/injector/sheet-manager.d.ts +0 -132
  104. package/dist/injector/sheet-manager.js +0 -699
  105. package/dist/injector/sheet-manager.js.map +0 -1
  106. package/dist/injector/types.d.ts +0 -235
  107. package/dist/keyframes/index.js +0 -206
  108. package/dist/keyframes/index.js.map +0 -1
  109. package/dist/parser/classify.js +0 -319
  110. package/dist/parser/classify.js.map +0 -1
  111. package/dist/parser/const.js +0 -60
  112. package/dist/parser/const.js.map +0 -1
  113. package/dist/parser/lru.js +0 -109
  114. package/dist/parser/lru.js.map +0 -1
  115. package/dist/parser/parser.d.ts +0 -25
  116. package/dist/parser/parser.js +0 -115
  117. package/dist/parser/parser.js.map +0 -1
  118. package/dist/parser/tokenizer.js +0 -69
  119. package/dist/parser/tokenizer.js.map +0 -1
  120. package/dist/parser/types.d.ts +0 -51
  121. package/dist/parser/types.js +0 -46
  122. package/dist/parser/types.js.map +0 -1
  123. package/dist/pipeline/conditions.d.ts +0 -134
  124. package/dist/pipeline/conditions.js +0 -406
  125. package/dist/pipeline/conditions.js.map +0 -1
  126. package/dist/pipeline/exclusive.js +0 -389
  127. package/dist/pipeline/exclusive.js.map +0 -1
  128. package/dist/pipeline/index.d.ts +0 -55
  129. package/dist/pipeline/index.js +0 -749
  130. package/dist/pipeline/index.js.map +0 -1
  131. package/dist/pipeline/materialize-contradictions.js +0 -125
  132. package/dist/pipeline/materialize-contradictions.js.map +0 -1
  133. package/dist/pipeline/materialize.js +0 -1038
  134. package/dist/pipeline/materialize.js.map +0 -1
  135. package/dist/pipeline/parseStateKey.d.ts +0 -15
  136. package/dist/pipeline/parseStateKey.js +0 -446
  137. package/dist/pipeline/parseStateKey.js.map +0 -1
  138. package/dist/pipeline/simplify.js +0 -725
  139. package/dist/pipeline/simplify.js.map +0 -1
  140. package/dist/pipeline/warnings.js +0 -18
  141. package/dist/pipeline/warnings.js.map +0 -1
  142. package/dist/plugins/index.d.ts +0 -2
  143. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  144. package/dist/plugins/okhsl-plugin.js +0 -97
  145. package/dist/plugins/okhsl-plugin.js.map +0 -1
  146. package/dist/plugins/types.d.ts +0 -87
  147. package/dist/properties/index.js +0 -222
  148. package/dist/properties/index.js.map +0 -1
  149. package/dist/properties/property-type-resolver.d.ts +0 -24
  150. package/dist/properties/property-type-resolver.js +0 -90
  151. package/dist/properties/property-type-resolver.js.map +0 -1
  152. package/dist/rsc-cache.js +0 -79
  153. package/dist/rsc-cache.js.map +0 -1
  154. package/dist/ssr/async-storage.d.ts +0 -17
  155. package/dist/ssr/async-storage.js.map +0 -1
  156. package/dist/ssr/collect-auto-properties.js +0 -58
  157. package/dist/ssr/collect-auto-properties.js.map +0 -1
  158. package/dist/ssr/collector.js.map +0 -1
  159. package/dist/ssr/context.js.map +0 -1
  160. package/dist/ssr/format-global-rules.js.map +0 -1
  161. package/dist/ssr/format-keyframes.js +0 -69
  162. package/dist/ssr/format-keyframes.js.map +0 -1
  163. package/dist/ssr/format-property.js +0 -49
  164. package/dist/ssr/format-property.js.map +0 -1
  165. package/dist/ssr/format-rules.js +0 -73
  166. package/dist/ssr/format-rules.js.map +0 -1
  167. package/dist/ssr/hydrate.d.ts +0 -29
  168. package/dist/ssr/hydrate.js.map +0 -1
  169. package/dist/ssr/ssr-collector-ref.js +0 -29
  170. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  171. package/dist/states/index.d.ts +0 -49
  172. package/dist/states/index.js +0 -170
  173. package/dist/states/index.js.map +0 -1
  174. package/dist/static/tastyStatic.d.ts +0 -46
  175. package/dist/static/tastyStatic.js +0 -30
  176. package/dist/static/tastyStatic.js.map +0 -1
  177. package/dist/static/types.d.ts +0 -49
  178. package/dist/static/types.js +0 -24
  179. package/dist/static/types.js.map +0 -1
  180. package/dist/styles/border.d.ts +0 -25
  181. package/dist/styles/border.js +0 -120
  182. package/dist/styles/border.js.map +0 -1
  183. package/dist/styles/color.d.ts +0 -14
  184. package/dist/styles/color.js +0 -26
  185. package/dist/styles/color.js.map +0 -1
  186. package/dist/styles/const.js +0 -17
  187. package/dist/styles/const.js.map +0 -1
  188. package/dist/styles/createStyle.js +0 -79
  189. package/dist/styles/createStyle.js.map +0 -1
  190. package/dist/styles/dimension.js +0 -109
  191. package/dist/styles/dimension.js.map +0 -1
  192. package/dist/styles/directional.js +0 -133
  193. package/dist/styles/directional.js.map +0 -1
  194. package/dist/styles/display.d.ts +0 -30
  195. package/dist/styles/display.js +0 -73
  196. package/dist/styles/display.js.map +0 -1
  197. package/dist/styles/fade.d.ts +0 -15
  198. package/dist/styles/fade.js +0 -62
  199. package/dist/styles/fade.js.map +0 -1
  200. package/dist/styles/fill.d.ts +0 -42
  201. package/dist/styles/fill.js +0 -51
  202. package/dist/styles/fill.js.map +0 -1
  203. package/dist/styles/flow.d.ts +0 -16
  204. package/dist/styles/flow.js +0 -12
  205. package/dist/styles/flow.js.map +0 -1
  206. package/dist/styles/gap.d.ts +0 -31
  207. package/dist/styles/gap.js +0 -38
  208. package/dist/styles/gap.js.map +0 -1
  209. package/dist/styles/height.d.ts +0 -17
  210. package/dist/styles/height.js +0 -19
  211. package/dist/styles/height.js.map +0 -1
  212. package/dist/styles/index.d.ts +0 -1
  213. package/dist/styles/index.js +0 -8
  214. package/dist/styles/index.js.map +0 -1
  215. package/dist/styles/inset.d.ts +0 -24
  216. package/dist/styles/inset.js +0 -34
  217. package/dist/styles/inset.js.map +0 -1
  218. package/dist/styles/list.d.ts +0 -16
  219. package/dist/styles/list.js +0 -100
  220. package/dist/styles/list.js.map +0 -1
  221. package/dist/styles/margin.d.ts +0 -24
  222. package/dist/styles/margin.js +0 -32
  223. package/dist/styles/margin.js.map +0 -1
  224. package/dist/styles/outline.d.ts +0 -29
  225. package/dist/styles/outline.js +0 -55
  226. package/dist/styles/outline.js.map +0 -1
  227. package/dist/styles/padding.d.ts +0 -24
  228. package/dist/styles/padding.js +0 -32
  229. package/dist/styles/padding.js.map +0 -1
  230. package/dist/styles/placement.d.ts +0 -37
  231. package/dist/styles/placement.js +0 -74
  232. package/dist/styles/placement.js.map +0 -1
  233. package/dist/styles/predefined.d.ts +0 -71
  234. package/dist/styles/predefined.js +0 -237
  235. package/dist/styles/predefined.js.map +0 -1
  236. package/dist/styles/preset.d.ts +0 -52
  237. package/dist/styles/preset.js +0 -127
  238. package/dist/styles/preset.js.map +0 -1
  239. package/dist/styles/radius.d.ts +0 -12
  240. package/dist/styles/radius.js +0 -83
  241. package/dist/styles/radius.js.map +0 -1
  242. package/dist/styles/scrollMargin.d.ts +0 -24
  243. package/dist/styles/scrollMargin.js +0 -32
  244. package/dist/styles/scrollMargin.js.map +0 -1
  245. package/dist/styles/scrollbar.d.ts +0 -25
  246. package/dist/styles/scrollbar.js +0 -51
  247. package/dist/styles/scrollbar.js.map +0 -1
  248. package/dist/styles/shadow.d.ts +0 -14
  249. package/dist/styles/shadow.js +0 -25
  250. package/dist/styles/shadow.js.map +0 -1
  251. package/dist/styles/shared.js +0 -17
  252. package/dist/styles/shared.js.map +0 -1
  253. package/dist/styles/transition.d.ts +0 -14
  254. package/dist/styles/transition.js +0 -159
  255. package/dist/styles/transition.js.map +0 -1
  256. package/dist/styles/width.d.ts +0 -17
  257. package/dist/styles/width.js +0 -19
  258. package/dist/styles/width.js.map +0 -1
  259. package/dist/tasty.d.ts +0 -134
  260. package/dist/tasty.js +0 -248
  261. package/dist/tasty.js.map +0 -1
  262. package/dist/types.d.ts +0 -184
  263. package/dist/utils/cache-wrapper.js +0 -21
  264. package/dist/utils/cache-wrapper.js.map +0 -1
  265. package/dist/utils/case-converter.js +0 -8
  266. package/dist/utils/case-converter.js.map +0 -1
  267. package/dist/utils/color-math.d.ts +0 -46
  268. package/dist/utils/color-math.js +0 -749
  269. package/dist/utils/color-math.js.map +0 -1
  270. package/dist/utils/color-space.d.ts +0 -5
  271. package/dist/utils/color-space.js +0 -228
  272. package/dist/utils/color-space.js.map +0 -1
  273. package/dist/utils/colors.d.ts +0 -5
  274. package/dist/utils/colors.js +0 -10
  275. package/dist/utils/colors.js.map +0 -1
  276. package/dist/utils/css-types.d.ts +0 -7
  277. package/dist/utils/deps-equal.js +0 -15
  278. package/dist/utils/deps-equal.js.map +0 -1
  279. package/dist/utils/dotize.d.ts +0 -26
  280. package/dist/utils/dotize.js +0 -122
  281. package/dist/utils/dotize.js.map +0 -1
  282. package/dist/utils/filter-base-props.d.ts +0 -15
  283. package/dist/utils/filter-base-props.js +0 -45
  284. package/dist/utils/filter-base-props.js.map +0 -1
  285. package/dist/utils/get-display-name.d.ts +0 -7
  286. package/dist/utils/get-display-name.js +0 -10
  287. package/dist/utils/get-display-name.js.map +0 -1
  288. package/dist/utils/has-keys.js +0 -13
  289. package/dist/utils/has-keys.js.map +0 -1
  290. package/dist/utils/hash.js +0 -14
  291. package/dist/utils/hash.js.map +0 -1
  292. package/dist/utils/is-dev-env.js +0 -19
  293. package/dist/utils/is-dev-env.js.map +0 -1
  294. package/dist/utils/is-valid-element-type.js +0 -15
  295. package/dist/utils/is-valid-element-type.js.map +0 -1
  296. package/dist/utils/merge-styles.js.map +0 -1
  297. package/dist/utils/mod-attrs.d.ts +0 -6
  298. package/dist/utils/mod-attrs.js +0 -20
  299. package/dist/utils/mod-attrs.js.map +0 -1
  300. package/dist/utils/process-tokens.d.ts +0 -17
  301. package/dist/utils/process-tokens.js +0 -83
  302. package/dist/utils/process-tokens.js.map +0 -1
  303. package/dist/utils/resolve-recipes.d.ts +0 -17
  304. package/dist/utils/resolve-recipes.js.map +0 -1
  305. package/dist/utils/selector-transform.js +0 -32
  306. package/dist/utils/selector-transform.js.map +0 -1
  307. package/dist/utils/string.js +0 -8
  308. package/dist/utils/string.js.map +0 -1
  309. package/dist/utils/styles.d.ts +0 -99
  310. package/dist/utils/styles.js +0 -220
  311. package/dist/utils/styles.js.map +0 -1
  312. package/dist/utils/typography.d.ts +0 -58
  313. package/dist/utils/typography.js +0 -51
  314. package/dist/utils/typography.js.map +0 -1
  315. package/dist/utils/warnings.d.ts +0 -16
  316. package/dist/utils/warnings.js +0 -16
  317. package/dist/utils/warnings.js.map +0 -1
  318. package/dist/zero/css-writer.d.ts +0 -45
  319. package/dist/zero/css-writer.js +0 -73
  320. package/dist/zero/css-writer.js.map +0 -1
  321. package/dist/zero/extractor.d.ts +0 -24
  322. package/dist/zero/extractor.js.map +0 -1
@@ -1,65 +0,0 @@
1
- import { hashString } from "../utils/hash.js";
2
- import { formatCounterStyleRule } from "../counter-style/index.js";
3
- import { getGlobalInjector } from "../config.js";
4
- import { getStyleTarget, pushRSCCSS } from "../rsc-cache.js";
5
- //#region src/hooks/useCounterStyle.ts
6
- let clientCounterStyleCounter = 0;
7
- const clientContentToName = /* @__PURE__ */ new Map();
8
- /**
9
- * Inject a CSS @counter-style rule and return the generated name.
10
- * Permanent — no cleanup on unmount. Deduplicates by name.
11
- *
12
- * Works in all environments: client, SSR with collector, and React Server Components.
13
- *
14
- * @example Basic usage
15
- * ```tsx
16
- * function EmojiList() {
17
- * const styleName = useCounterStyle({
18
- * system: 'cyclic',
19
- * symbols: '"👍"',
20
- * suffix: '" "',
21
- * }, { name: 'thumbs' });
22
- *
23
- * return (
24
- * <ol style={{ listStyleType: styleName }}>
25
- * <li>First</li>
26
- * <li>Second</li>
27
- * </ol>
28
- * );
29
- * }
30
- * ```
31
- *
32
- */
33
- function useCounterStyle(descriptors, options) {
34
- if (!descriptors || !descriptors.system) return "";
35
- const target = getStyleTarget();
36
- if (target.mode === "ssr") {
37
- const actualName = target.collector.allocateCounterStyleName(options?.name);
38
- const css = formatCounterStyleRule(actualName, descriptors);
39
- target.collector.collectCounterStyle(actualName, css);
40
- return actualName;
41
- }
42
- if (target.mode === "rsc") {
43
- const serializedContent = JSON.stringify(descriptors);
44
- const key = `__cs:${options?.name ?? ""}:${serializedContent}`;
45
- const existingName = target.cache.generatedNames.get(key);
46
- if (existingName) return existingName;
47
- const actualName = options?.name ?? `cs${hashString(serializedContent)}`;
48
- const css = formatCounterStyleRule(actualName, descriptors);
49
- pushRSCCSS(target.cache, key, css);
50
- target.cache.generatedNames.set(key, actualName);
51
- return actualName;
52
- }
53
- const serializedContent = JSON.stringify(descriptors);
54
- const cacheKey = `${options?.name ?? ""}:${serializedContent}`;
55
- const existingName = clientContentToName.get(cacheKey);
56
- if (existingName) return existingName;
57
- const name = options?.name ?? `cs${clientCounterStyleCounter++}`;
58
- clientContentToName.set(cacheKey, name);
59
- getGlobalInjector().counterStyle(name, descriptors, { root: options?.root });
60
- return name;
61
- }
62
- //#endregion
63
- export { useCounterStyle };
64
-
65
- //# sourceMappingURL=useCounterStyle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useCounterStyle.js","names":[],"sources":["../../src/hooks/useCounterStyle.ts"],"sourcesContent":["import { getGlobalInjector } from '../config';\nimport { formatCounterStyleRule } from '../counter-style';\nimport type { CounterStyleDescriptors } from '../injector/types';\nimport { getStyleTarget, pushRSCCSS } from '../rsc-cache';\nimport { hashString } from '../utils/hash';\n\ninterface UseCounterStyleOptions {\n name?: string;\n root?: Document | ShadowRoot;\n}\n\nlet clientCounterStyleCounter = 0;\n\nconst clientContentToName = new Map<string, string>();\n\n/* @internal — used only for tests */\nexport function _resetCounterStyleCache(): void {\n clientContentToName.clear();\n clientCounterStyleCounter = 0;\n}\n\n/**\n * Inject a CSS @counter-style rule and return the generated name.\n * Permanent — no cleanup on unmount. Deduplicates by name.\n *\n * Works in all environments: client, SSR with collector, and React Server Components.\n *\n * @example Basic usage\n * ```tsx\n * function EmojiList() {\n * const styleName = useCounterStyle({\n * system: 'cyclic',\n * symbols: '\"👍\"',\n * suffix: '\" \"',\n * }, { name: 'thumbs' });\n *\n * return (\n * <ol style={{ listStyleType: styleName }}>\n * <li>First</li>\n * <li>Second</li>\n * </ol>\n * );\n * }\n * ```\n *\n */\nexport function useCounterStyle(\n descriptors: CounterStyleDescriptors,\n options?: UseCounterStyleOptions,\n): string {\n if (!descriptors || !descriptors.system) {\n return '';\n }\n\n const target = getStyleTarget();\n\n if (target.mode === 'ssr') {\n const actualName = target.collector.allocateCounterStyleName(options?.name);\n const css = formatCounterStyleRule(actualName, descriptors);\n target.collector.collectCounterStyle(actualName, css);\n return actualName;\n }\n\n if (target.mode === 'rsc') {\n const serializedContent = JSON.stringify(descriptors);\n const key = `__cs:${options?.name ?? ''}:${serializedContent}`;\n\n const existingName = target.cache.generatedNames.get(key);\n if (existingName) return existingName;\n\n const actualName = options?.name ?? `cs${hashString(serializedContent)}`;\n const css = formatCounterStyleRule(actualName, descriptors);\n pushRSCCSS(target.cache, key, css);\n target.cache.generatedNames.set(key, actualName);\n return actualName;\n }\n\n // Client path: stable name via content-based dedup\n const serializedContent = JSON.stringify(descriptors);\n const cacheKey = `${options?.name ?? ''}:${serializedContent}`;\n\n const existingName = clientContentToName.get(cacheKey);\n if (existingName) {\n return existingName;\n }\n\n const name = options?.name ?? `cs${clientCounterStyleCounter++}`;\n clientContentToName.set(cacheKey, name);\n\n const injector = getGlobalInjector();\n injector.counterStyle(name, descriptors, { root: options?.root });\n\n return name;\n}\n"],"mappings":";;;;;AAWA,IAAI,4BAA4B;AAEhC,MAAM,sCAAsB,IAAI,KAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCrD,SAAgB,gBACd,aACA,SACQ;AACR,KAAI,CAAC,eAAe,CAAC,YAAY,OAC/B,QAAO;CAGT,MAAM,SAAS,gBAAgB;AAE/B,KAAI,OAAO,SAAS,OAAO;EACzB,MAAM,aAAa,OAAO,UAAU,yBAAyB,SAAS,KAAK;EAC3E,MAAM,MAAM,uBAAuB,YAAY,YAAY;AAC3D,SAAO,UAAU,oBAAoB,YAAY,IAAI;AACrD,SAAO;;AAGT,KAAI,OAAO,SAAS,OAAO;EACzB,MAAM,oBAAoB,KAAK,UAAU,YAAY;EACrD,MAAM,MAAM,QAAQ,SAAS,QAAQ,GAAG,GAAG;EAE3C,MAAM,eAAe,OAAO,MAAM,eAAe,IAAI,IAAI;AACzD,MAAI,aAAc,QAAO;EAEzB,MAAM,aAAa,SAAS,QAAQ,KAAK,WAAW,kBAAkB;EACtE,MAAM,MAAM,uBAAuB,YAAY,YAAY;AAC3D,aAAW,OAAO,OAAO,KAAK,IAAI;AAClC,SAAO,MAAM,eAAe,IAAI,KAAK,WAAW;AAChD,SAAO;;CAIT,MAAM,oBAAoB,KAAK,UAAU,YAAY;CACrD,MAAM,WAAW,GAAG,SAAS,QAAQ,GAAG,GAAG;CAE3C,MAAM,eAAe,oBAAoB,IAAI,SAAS;AACtD,KAAI,aACF,QAAO;CAGT,MAAM,OAAO,SAAS,QAAQ,KAAK;AACnC,qBAAoB,IAAI,UAAU,KAAK;AAEtB,oBAAmB,CAC3B,aAAa,MAAM,aAAa,EAAE,MAAM,SAAS,MAAM,CAAC;AAEjE,QAAO"}
@@ -1,45 +0,0 @@
1
- import { FontFaceInput } from "../injector/types.js";
2
-
3
- //#region src/hooks/useFontFace.d.ts
4
- interface UseFontFaceOptions {
5
- root?: Document | ShadowRoot;
6
- }
7
- /**
8
- * Inject CSS @font-face rules.
9
- * Permanent — no cleanup on unmount. Deduplicates by content hash.
10
- *
11
- * Works in all environments: client, SSR with collector, and React Server Components.
12
- *
13
- * @param family - The font-family name
14
- * @param input - Single descriptor object or array of descriptors (for multiple weights/styles)
15
- * @param options - Optional settings (e.g. Shadow DOM root)
16
- *
17
- * @example Single weight
18
- * ```tsx
19
- * function App() {
20
- * useFontFace('Brand Sans', {
21
- * src: 'url("/fonts/brand-sans.woff2") format("woff2")',
22
- * fontWeight: '400 700',
23
- * fontDisplay: 'swap',
24
- * });
25
- *
26
- * return <div style={{ fontFamily: '"Brand Sans", sans-serif' }}>Hello</div>;
27
- * }
28
- * ```
29
- *
30
- * @example Multiple weights
31
- * ```tsx
32
- * function App() {
33
- * useFontFace('Brand Sans', [
34
- * { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
35
- * { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
36
- * ]);
37
- *
38
- * return <div style={{ fontFamily: '"Brand Sans", sans-serif' }}>Hello</div>;
39
- * }
40
- * ```
41
- */
42
- declare function useFontFace(family: string, input: FontFaceInput, options?: UseFontFaceOptions): void;
43
- //#endregion
44
- export { useFontFace };
45
- //# sourceMappingURL=useFontFace.d.ts.map
@@ -1,66 +0,0 @@
1
- import { fontFaceContentHash, formatFontFaceRule } from "../font-face/index.js";
2
- import { getGlobalInjector } from "../config.js";
3
- import { getStyleTarget, pushRSCCSS } from "../rsc-cache.js";
4
- //#region src/hooks/useFontFace.ts
5
- /**
6
- * Inject CSS @font-face rules.
7
- * Permanent — no cleanup on unmount. Deduplicates by content hash.
8
- *
9
- * Works in all environments: client, SSR with collector, and React Server Components.
10
- *
11
- * @param family - The font-family name
12
- * @param input - Single descriptor object or array of descriptors (for multiple weights/styles)
13
- * @param options - Optional settings (e.g. Shadow DOM root)
14
- *
15
- * @example Single weight
16
- * ```tsx
17
- * function App() {
18
- * useFontFace('Brand Sans', {
19
- * src: 'url("/fonts/brand-sans.woff2") format("woff2")',
20
- * fontWeight: '400 700',
21
- * fontDisplay: 'swap',
22
- * });
23
- *
24
- * return <div style={{ fontFamily: '"Brand Sans", sans-serif' }}>Hello</div>;
25
- * }
26
- * ```
27
- *
28
- * @example Multiple weights
29
- * ```tsx
30
- * function App() {
31
- * useFontFace('Brand Sans', [
32
- * { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
33
- * { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
34
- * ]);
35
- *
36
- * return <div style={{ fontFamily: '"Brand Sans", sans-serif' }}>Hello</div>;
37
- * }
38
- * ```
39
- */
40
- function useFontFace(family, input, options) {
41
- if (!family) return;
42
- const descriptors = Array.isArray(input) ? input : [input];
43
- const target = getStyleTarget();
44
- if (target.mode === "ssr") {
45
- for (const desc of descriptors) {
46
- const hash = fontFaceContentHash(family, desc);
47
- const css = formatFontFaceRule(family, desc);
48
- target.collector.collectFontFace(hash, css);
49
- }
50
- return;
51
- }
52
- if (target.mode === "rsc") {
53
- for (const desc of descriptors) {
54
- const hash = fontFaceContentHash(family, desc);
55
- const css = formatFontFaceRule(family, desc);
56
- pushRSCCSS(target.cache, `__ff:${hash}`, css);
57
- }
58
- return;
59
- }
60
- const injector = getGlobalInjector();
61
- for (const desc of descriptors) injector.fontFace(family, desc, { root: options?.root });
62
- }
63
- //#endregion
64
- export { useFontFace };
65
-
66
- //# sourceMappingURL=useFontFace.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useFontFace.js","names":[],"sources":["../../src/hooks/useFontFace.ts"],"sourcesContent":["import { getGlobalInjector } from '../config';\nimport { fontFaceContentHash, formatFontFaceRule } from '../font-face';\nimport type { FontFaceDescriptors, FontFaceInput } from '../injector/types';\nimport { getStyleTarget, pushRSCCSS } from '../rsc-cache';\n\ninterface UseFontFaceOptions {\n root?: Document | ShadowRoot;\n}\n\n/**\n * Inject CSS @font-face rules.\n * Permanent — no cleanup on unmount. Deduplicates by content hash.\n *\n * Works in all environments: client, SSR with collector, and React Server Components.\n *\n * @param family - The font-family name\n * @param input - Single descriptor object or array of descriptors (for multiple weights/styles)\n * @param options - Optional settings (e.g. Shadow DOM root)\n *\n * @example Single weight\n * ```tsx\n * function App() {\n * useFontFace('Brand Sans', {\n * src: 'url(\"/fonts/brand-sans.woff2\") format(\"woff2\")',\n * fontWeight: '400 700',\n * fontDisplay: 'swap',\n * });\n *\n * return <div style={{ fontFamily: '\"Brand Sans\", sans-serif' }}>Hello</div>;\n * }\n * ```\n *\n * @example Multiple weights\n * ```tsx\n * function App() {\n * useFontFace('Brand Sans', [\n * { src: 'url(\"/fonts/brand-regular.woff2\") format(\"woff2\")', fontWeight: 400, fontDisplay: 'swap' },\n * { src: 'url(\"/fonts/brand-bold.woff2\") format(\"woff2\")', fontWeight: 700, fontDisplay: 'swap' },\n * ]);\n *\n * return <div style={{ fontFamily: '\"Brand Sans\", sans-serif' }}>Hello</div>;\n * }\n * ```\n */\nexport function useFontFace(\n family: string,\n input: FontFaceInput,\n options?: UseFontFaceOptions,\n): void {\n if (!family) return;\n\n const descriptors: FontFaceDescriptors[] = Array.isArray(input)\n ? input\n : [input];\n\n const target = getStyleTarget();\n\n if (target.mode === 'ssr') {\n for (const desc of descriptors) {\n const hash = fontFaceContentHash(family, desc);\n const css = formatFontFaceRule(family, desc);\n target.collector.collectFontFace(hash, css);\n }\n return;\n }\n\n if (target.mode === 'rsc') {\n for (const desc of descriptors) {\n const hash = fontFaceContentHash(family, desc);\n const css = formatFontFaceRule(family, desc);\n pushRSCCSS(target.cache, `__ff:${hash}`, css);\n }\n return;\n }\n\n const injector = getGlobalInjector();\n for (const desc of descriptors) {\n injector.fontFace(family, desc, { root: options?.root });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,YACd,QACA,OACA,SACM;AACN,KAAI,CAAC,OAAQ;CAEb,MAAM,cAAqC,MAAM,QAAQ,MAAM,GAC3D,QACA,CAAC,MAAM;CAEX,MAAM,SAAS,gBAAgB;AAE/B,KAAI,OAAO,SAAS,OAAO;AACzB,OAAK,MAAM,QAAQ,aAAa;GAC9B,MAAM,OAAO,oBAAoB,QAAQ,KAAK;GAC9C,MAAM,MAAM,mBAAmB,QAAQ,KAAK;AAC5C,UAAO,UAAU,gBAAgB,MAAM,IAAI;;AAE7C;;AAGF,KAAI,OAAO,SAAS,OAAO;AACzB,OAAK,MAAM,QAAQ,aAAa;GAC9B,MAAM,OAAO,oBAAoB,QAAQ,KAAK;GAC9C,MAAM,MAAM,mBAAmB,QAAQ,KAAK;AAC5C,cAAW,OAAO,OAAO,QAAQ,QAAQ,IAAI;;AAE/C;;CAGF,MAAM,WAAW,mBAAmB;AACpC,MAAK,MAAM,QAAQ,YACjB,UAAS,SAAS,QAAQ,MAAM,EAAE,MAAM,SAAS,MAAM,CAAC"}
@@ -1,46 +0,0 @@
1
- import { Styles } from "../styles/types.js";
2
-
3
- //#region src/hooks/useGlobalStyles.d.ts
4
- interface UseGlobalStylesOptions {
5
- /**
6
- * Stable identifier for update tracking (client-only). When provided,
7
- * changing the styles will dispose the previous injection and inject the
8
- * new one. Without an id, the selector is used as the slot key.
9
- * In RSC mode, renders are single-pass so update tracking does not apply.
10
- */
11
- id?: string;
12
- }
13
- /**
14
- * Inject global styles for a given selector.
15
- * Useful for styling elements by selector without generating classNames.
16
- *
17
- * SSR-aware: when a ServerStyleCollector is available, CSS is collected
18
- * during the render phase instead of being injected into the DOM.
19
- *
20
- * Works in all environments: client, SSR with collector, and React Server Components.
21
- *
22
- * Injected styles are permanent — they are not cleaned up on component unmount.
23
- * Use the `id` option for update tracking when styles change over the
24
- * component lifecycle.
25
- *
26
- * @param selector - CSS selector to apply styles to (e.g., '.my-class', ':root', 'body')
27
- * @param styles - Tasty styles object
28
- * @param options - Optional settings including `id` for update tracking
29
- *
30
- * @example
31
- * ```tsx
32
- * function MyComponent() {
33
- * useGlobalStyles('.card', {
34
- * padding: '2x',
35
- * radius: '1r',
36
- * fill: '#white',
37
- * });
38
- *
39
- * return <div className="card">Content</div>;
40
- * }
41
- * ```
42
- */
43
- declare function useGlobalStyles(selector: string, styles?: Styles, options?: UseGlobalStylesOptions): void;
44
- //#endregion
45
- export { useGlobalStyles };
46
- //# sourceMappingURL=useGlobalStyles.d.ts.map
@@ -1,88 +0,0 @@
1
- import { hashString } from "../utils/hash.js";
2
- import { renderStyles } from "../pipeline/index.js";
3
- import { getConfig } from "../config.js";
4
- import { injectGlobal } from "../injector/index.js";
5
- import { getStyleTarget, pushRSCCSS } from "../rsc-cache.js";
6
- import { collectAutoInferredProperties, collectAutoInferredPropertiesRSC } from "../ssr/collect-auto-properties.js";
7
- import { resolveRecipes } from "../utils/resolve-recipes.js";
8
- import { formatGlobalRules } from "../ssr/format-global-rules.js";
9
- //#region src/hooks/useGlobalStyles.ts
10
- const clientGlobalEntries = /* @__PURE__ */ new Map();
11
- /**
12
- * Inject global styles for a given selector.
13
- * Useful for styling elements by selector without generating classNames.
14
- *
15
- * SSR-aware: when a ServerStyleCollector is available, CSS is collected
16
- * during the render phase instead of being injected into the DOM.
17
- *
18
- * Works in all environments: client, SSR with collector, and React Server Components.
19
- *
20
- * Injected styles are permanent — they are not cleaned up on component unmount.
21
- * Use the `id` option for update tracking when styles change over the
22
- * component lifecycle.
23
- *
24
- * @param selector - CSS selector to apply styles to (e.g., '.my-class', ':root', 'body')
25
- * @param styles - Tasty styles object
26
- * @param options - Optional settings including `id` for update tracking
27
- *
28
- * @example
29
- * ```tsx
30
- * function MyComponent() {
31
- * useGlobalStyles('.card', {
32
- * padding: '2x',
33
- * radius: '1r',
34
- * fill: '#white',
35
- * });
36
- *
37
- * return <div className="card">Content</div>;
38
- * }
39
- * ```
40
- */
41
- function useGlobalStyles(selector, styles, options) {
42
- if (!styles) return;
43
- if (!selector) {
44
- console.warn("[Tasty] useGlobalStyles: selector is required and cannot be empty. Styles will not be injected.");
45
- return;
46
- }
47
- const target = getStyleTarget();
48
- if (target.mode === "client") {
49
- const slotKey = options?.id ?? selector;
50
- const stylesKey = JSON.stringify(styles);
51
- const existing = clientGlobalEntries.get(slotKey);
52
- if (existing && existing.stylesKey === stylesKey) return;
53
- }
54
- const resolvedStyles = resolveRecipes(styles);
55
- const styleResults = renderStyles(resolvedStyles, selector);
56
- if (styleResults.length === 0) return;
57
- if (target.mode === "ssr") {
58
- target.collector.collectInternals();
59
- const css = formatGlobalRules(styleResults);
60
- if (css) {
61
- const key = options?.id ? `global:${options.id}` : `global:${selector}:${hashString(css)}`;
62
- target.collector.collectGlobalStyles(key, css);
63
- }
64
- if (getConfig().autoPropertyTypes !== false) collectAutoInferredProperties(styleResults, target.collector, resolvedStyles);
65
- return;
66
- }
67
- if (target.mode === "rsc") {
68
- const css = formatGlobalRules(styleResults);
69
- if (css) {
70
- const key = options?.id ? `__global:${options.id}` : `__global:${selector}:${hashString(css)}`;
71
- pushRSCCSS(target.cache, key, css);
72
- }
73
- if (getConfig().autoPropertyTypes !== false) collectAutoInferredPropertiesRSC(styleResults, target.cache, resolvedStyles);
74
- return;
75
- }
76
- const slotKey = options?.id ?? selector;
77
- const existing = clientGlobalEntries.get(slotKey);
78
- if (existing) existing.dispose();
79
- const { dispose } = injectGlobal(styleResults);
80
- clientGlobalEntries.set(slotKey, {
81
- stylesKey: JSON.stringify(styles),
82
- dispose
83
- });
84
- }
85
- //#endregion
86
- export { useGlobalStyles };
87
-
88
- //# sourceMappingURL=useGlobalStyles.js.map
@@ -1 +0,0 @@
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 { getStyleTarget, pushRSCCSS } from '../rsc-cache';\nimport {\n collectAutoInferredProperties,\n collectAutoInferredPropertiesRSC,\n} from '../ssr/collect-auto-properties';\nimport { formatGlobalRules } from '../ssr/format-global-rules';\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 target = getStyleTarget();\n\n // Client fast path: skip resolveRecipes/renderStyles if styles haven't changed\n if (target.mode === 'client') {\n const slotKey = options?.id ?? selector;\n const stylesKey = JSON.stringify(styles);\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 (target.mode === 'ssr') {\n target.collector.collectInternals();\n\n const css = formatGlobalRules(styleResults);\n if (css) {\n const key = options?.id\n ? `global:${options.id}`\n : `global:${selector}:${hashString(css)}`;\n target.collector.collectGlobalStyles(key, css);\n }\n\n if (getConfig().autoPropertyTypes !== false) {\n collectAutoInferredProperties(\n styleResults,\n target.collector,\n resolvedStyles,\n );\n }\n return;\n }\n\n if (target.mode === 'rsc') {\n const css = formatGlobalRules(styleResults);\n if (css) {\n const key = options?.id\n ? `__global:${options.id}`\n : `__global:${selector}:${hashString(css)}`;\n pushRSCCSS(target.cache, key, css);\n }\n\n if (getConfig().autoPropertyTypes !== false) {\n collectAutoInferredPropertiesRSC(\n styleResults,\n target.cache,\n resolvedStyles,\n );\n }\n return;\n }\n\n // Client path\n const slotKey = options?.id ?? selector;\n\n const existing = clientGlobalEntries.get(slotKey);\n if (existing) {\n existing.dispose();\n }\n\n const { dispose } = injectGlobal(styleResults);\n clientGlobalEntries.set(slotKey, {\n stylesKey: JSON.stringify(styles),\n dispose,\n });\n}\n"],"mappings":";;;;;;;;;AA6BA,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,SAAS,gBAAgB;AAG/B,KAAI,OAAO,SAAS,UAAU;EAC5B,MAAM,UAAU,SAAS,MAAM;EAC/B,MAAM,YAAY,KAAK,UAAU,OAAO;EACxC,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,OAAO,SAAS,OAAO;AACzB,SAAO,UAAU,kBAAkB;EAEnC,MAAM,MAAM,kBAAkB,aAAa;AAC3C,MAAI,KAAK;GACP,MAAM,MAAM,SAAS,KACjB,UAAU,QAAQ,OAClB,UAAU,SAAS,GAAG,WAAW,IAAI;AACzC,UAAO,UAAU,oBAAoB,KAAK,IAAI;;AAGhD,MAAI,WAAW,CAAC,sBAAsB,MACpC,+BACE,cACA,OAAO,WACP,eACD;AAEH;;AAGF,KAAI,OAAO,SAAS,OAAO;EACzB,MAAM,MAAM,kBAAkB,aAAa;AAC3C,MAAI,KAAK;GACP,MAAM,MAAM,SAAS,KACjB,YAAY,QAAQ,OACpB,YAAY,SAAS,GAAG,WAAW,IAAI;AAC3C,cAAW,OAAO,OAAO,KAAK,IAAI;;AAGpC,MAAI,WAAW,CAAC,sBAAsB,MACpC,kCACE,cACA,OAAO,OACP,eACD;AAEH;;CAIF,MAAM,UAAU,SAAS,MAAM;CAE/B,MAAM,WAAW,oBAAoB,IAAI,QAAQ;AACjD,KAAI,SACF,UAAS,SAAS;CAGpB,MAAM,EAAE,YAAY,aAAa,aAAa;AAC9C,qBAAoB,IAAI,SAAS;EAC/B,WAAW,KAAK,UAAU,OAAO;EACjC;EACD,CAAC"}
@@ -1,58 +0,0 @@
1
- import { KeyframesSteps } from "../injector/types.js";
2
-
3
- //#region src/hooks/useKeyframes.d.ts
4
- interface UseKeyframesOptions {
5
- name?: string;
6
- root?: Document | ShadowRoot;
7
- }
8
- /**
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.
13
- *
14
- * @example Basic usage - steps object is the dependency
15
- * ```tsx
16
- * function MyComponent() {
17
- * const bounce = useKeyframes({
18
- * '0%': { transform: 'scale(1)' },
19
- * '50%': { transform: 'scale(1.1)' },
20
- * '100%': { transform: 'scale(1)' },
21
- * });
22
- *
23
- * return <div style={{ animation: `${bounce} 1s infinite` }}>Bouncing</div>;
24
- * }
25
- * ```
26
- *
27
- * @example With custom name
28
- * ```tsx
29
- * function MyComponent() {
30
- * const fadeIn = useKeyframes(
31
- * { from: { opacity: 0 }, to: { opacity: 1 } },
32
- * { name: 'fadeIn' }
33
- * );
34
- *
35
- * return <div style={{ animation: `${fadeIn} 0.3s ease-out` }}>Fading in</div>;
36
- * }
37
- * ```
38
- *
39
- * @example Factory function with dependencies
40
- * ```tsx
41
- * function MyComponent({ scale }: { scale: number }) {
42
- * const pulse = useKeyframes(
43
- * () => ({
44
- * '0%': { transform: 'scale(1)' },
45
- * '100%': { transform: `scale(${scale})` },
46
- * }),
47
- * [scale]
48
- * );
49
- *
50
- * return <div style={{ animation: `${pulse} 1s infinite` }}>Pulsing</div>;
51
- * }
52
- * ```
53
- */
54
- declare function useKeyframes(steps: KeyframesSteps, options?: UseKeyframesOptions): string;
55
- declare function useKeyframes(factory: () => KeyframesSteps, deps: readonly unknown[], options?: UseKeyframesOptions): string;
56
- //#endregion
57
- export { useKeyframes };
58
- //# sourceMappingURL=useKeyframes.d.ts.map
@@ -1,55 +0,0 @@
1
- import { hashString } from "../utils/hash.js";
2
- import { keyframes } from "../injector/index.js";
3
- import { getStyleTarget, pushRSCCSS } from "../rsc-cache.js";
4
- import { formatKeyframesCSS } from "../ssr/format-keyframes.js";
5
- import { depsEqual } from "../utils/deps-equal.js";
6
- //#region src/hooks/useKeyframes.ts
7
- const clientContentToName = /* @__PURE__ */ new Map();
8
- const factoryDepsCache = /* @__PURE__ */ new Map();
9
- function useKeyframes(stepsOrFactory, depsOrOptions, options) {
10
- const isFactory = typeof stepsOrFactory === "function";
11
- const deps = isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : void 0;
12
- const opts = isFactory ? options : depsOrOptions;
13
- const target = getStyleTarget();
14
- if (isFactory && deps && opts?.name && target.mode === "client") {
15
- const cached = factoryDepsCache.get(opts.name);
16
- if (cached && depsEqual(cached.deps, deps)) return cached.name;
17
- }
18
- const steps = isFactory ? stepsOrFactory() : stepsOrFactory;
19
- if (!steps || Object.keys(steps).length === 0) return "";
20
- if (target.mode === "ssr") {
21
- const actualName = target.collector.allocateKeyframeName(opts?.name);
22
- const css = formatKeyframesCSS(actualName, steps);
23
- target.collector.collectKeyframes(actualName, css);
24
- return actualName;
25
- }
26
- if (target.mode === "rsc") {
27
- const serializedContent = JSON.stringify(steps);
28
- const key = `__kf:${opts?.name ?? ""}:${serializedContent}`;
29
- const existingName = target.cache.generatedNames.get(key);
30
- if (existingName) return existingName;
31
- const actualName = opts?.name ?? `k${hashString(serializedContent)}`;
32
- const css = formatKeyframesCSS(actualName, steps);
33
- pushRSCCSS(target.cache, key, css);
34
- target.cache.generatedNames.set(key, actualName);
35
- return actualName;
36
- }
37
- const serializedContent = JSON.stringify(steps);
38
- const cacheKey = `${opts?.name ?? ""}:${serializedContent}`;
39
- const cachedName = clientContentToName.get(cacheKey);
40
- if (cachedName) return cachedName;
41
- const name = keyframes(steps, {
42
- name: opts?.name,
43
- root: opts?.root
44
- }).toString();
45
- clientContentToName.set(cacheKey, name);
46
- if (deps && opts?.name) factoryDepsCache.set(opts.name, {
47
- deps,
48
- name
49
- });
50
- return name;
51
- }
52
- //#endregion
53
- export { useKeyframes };
54
-
55
- //# sourceMappingURL=useKeyframes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useKeyframes.js","names":[],"sources":["../../src/hooks/useKeyframes.ts"],"sourcesContent":["import { keyframes } from '../injector';\nimport type { KeyframesSteps } from '../injector/types';\nimport { getStyleTarget, pushRSCCSS } from '../rsc-cache';\nimport { formatKeyframesCSS } from '../ssr/format-keyframes';\nimport { depsEqual } from '../utils/deps-equal';\nimport { hashString } from '../utils/hash';\n\ninterface UseKeyframesOptions {\n name?: string;\n root?: Document | ShadowRoot;\n}\n\nconst clientContentToName = new Map<string, string>();\n\ninterface FactoryDepsEntry {\n deps: readonly unknown[];\n name: string;\n}\n\nconst factoryDepsCache = new Map<string, FactoryDepsEntry>();\n\n/* @internal — used only for tests */\nexport function _resetKeyframesCache(): void {\n clientContentToName.clear();\n factoryDepsCache.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 deps =\n isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : undefined;\n const opts = isFactory\n ? options\n : (depsOrOptions as UseKeyframesOptions | undefined);\n\n const target = getStyleTarget();\n\n // Client deps cache: skip factory re-evaluation when deps haven't changed\n if (isFactory && deps && opts?.name && target.mode === 'client') {\n const cached = factoryDepsCache.get(opts.name);\n if (cached && depsEqual(cached.deps, deps)) {\n return cached.name;\n }\n }\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 if (target.mode === 'ssr') {\n const actualName = target.collector.allocateKeyframeName(opts?.name);\n const css = formatKeyframesCSS(actualName, steps);\n target.collector.collectKeyframes(actualName, css);\n return actualName;\n }\n\n if (target.mode === 'rsc') {\n const serializedContent = JSON.stringify(steps);\n const key = `__kf:${opts?.name ?? ''}:${serializedContent}`;\n\n const existingName = target.cache.generatedNames.get(key);\n if (existingName) return existingName;\n\n const actualName = opts?.name ?? `k${hashString(serializedContent)}`;\n const css = formatKeyframesCSS(actualName, steps);\n pushRSCCSS(target.cache, key, css);\n target.cache.generatedNames.set(key, actualName);\n return actualName;\n }\n\n // Client path: stable name via content-based dedup\n const serializedContent = JSON.stringify(steps);\n const cacheKey = `${opts?.name ?? ''}:${serializedContent}`;\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 if (deps && opts?.name) {\n factoryDepsCache.set(opts.name, { deps, name });\n }\n\n return name;\n}\n"],"mappings":";;;;;;AAYA,MAAM,sCAAsB,IAAI,KAAqB;AAOrD,MAAM,mCAAmB,IAAI,KAA+B;AAqE5D,SAAgB,aACd,gBACA,eACA,SACQ;CACR,MAAM,YAAY,OAAO,mBAAmB;CAE5C,MAAM,OACJ,aAAa,MAAM,QAAQ,cAAc,GAAG,gBAAgB,KAAA;CAC9D,MAAM,OAAO,YACT,UACC;CAEL,MAAM,SAAS,gBAAgB;AAG/B,KAAI,aAAa,QAAQ,MAAM,QAAQ,OAAO,SAAS,UAAU;EAC/D,MAAM,SAAS,iBAAiB,IAAI,KAAK,KAAK;AAC9C,MAAI,UAAU,UAAU,OAAO,MAAM,KAAK,CACxC,QAAO,OAAO;;CAIlB,MAAM,QAAQ,YACT,gBAAyC,GACzC;AAEL,KAAI,CAAC,SAAS,OAAO,KAAK,MAAM,CAAC,WAAW,EAC1C,QAAO;AAGT,KAAI,OAAO,SAAS,OAAO;EACzB,MAAM,aAAa,OAAO,UAAU,qBAAqB,MAAM,KAAK;EACpE,MAAM,MAAM,mBAAmB,YAAY,MAAM;AACjD,SAAO,UAAU,iBAAiB,YAAY,IAAI;AAClD,SAAO;;AAGT,KAAI,OAAO,SAAS,OAAO;EACzB,MAAM,oBAAoB,KAAK,UAAU,MAAM;EAC/C,MAAM,MAAM,QAAQ,MAAM,QAAQ,GAAG,GAAG;EAExC,MAAM,eAAe,OAAO,MAAM,eAAe,IAAI,IAAI;AACzD,MAAI,aAAc,QAAO;EAEzB,MAAM,aAAa,MAAM,QAAQ,IAAI,WAAW,kBAAkB;EAClE,MAAM,MAAM,mBAAmB,YAAY,MAAM;AACjD,aAAW,OAAO,OAAO,KAAK,IAAI;AAClC,SAAO,MAAM,eAAe,IAAI,KAAK,WAAW;AAChD,SAAO;;CAIT,MAAM,oBAAoB,KAAK,UAAU,MAAM;CAC/C,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,KAAI,QAAQ,MAAM,KAChB,kBAAiB,IAAI,KAAK,MAAM;EAAE;EAAM;EAAM,CAAC;AAGjD,QAAO"}
@@ -1,81 +0,0 @@
1
- //#region src/hooks/useProperty.d.ts
2
- interface UsePropertyOptions {
3
- /**
4
- * CSS syntax string for the property (e.g., '<color>', '<length>', '<angle>').
5
- * For color tokens (#name), this is auto-set to '<color>' and cannot be overridden.
6
- * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax
7
- */
8
- syntax?: string;
9
- /**
10
- * Whether the property inherits from parent elements
11
- * @default true
12
- */
13
- inherits?: boolean;
14
- /**
15
- * Initial value for the property.
16
- * For color tokens (#name), this defaults to 'transparent' if not specified.
17
- */
18
- initialValue?: string | number;
19
- /**
20
- * Shadow root or document to inject into
21
- */
22
- root?: Document | ShadowRoot;
23
- }
24
- /**
25
- * Register a CSS @property custom property.
26
- * This enables advanced features like animating custom properties.
27
- *
28
- * Note: @property rules are global and persistent once defined.
29
- * The function ensures the property is only registered once per root.
30
- *
31
- * Accepts tasty token syntax for the property name:
32
- * - `$name` → defines `--name`
33
- * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
34
- * - `--name` → defines `--name` (legacy format)
35
- *
36
- * Works in all environments: client, SSR with collector, and React Server Components.
37
- *
38
- * @param name - The property token ($name, #name) or CSS property name (--name)
39
- * @param options - Property configuration
40
- *
41
- * @example Basic property with token syntax
42
- * ```tsx
43
- * function Spinner() {
44
- * useProperty('$rotation', {
45
- * syntax: '<angle>',
46
- * inherits: false,
47
- * initialValue: '0deg',
48
- * });
49
- *
50
- * return <div className="spinner" />;
51
- * }
52
- * ```
53
- *
54
- * @example Color property with token syntax (auto-sets syntax)
55
- * ```tsx
56
- * function MyComponent() {
57
- * useProperty('#theme', {
58
- * initialValue: 'red', // syntax: '<color>' is auto-set
59
- * });
60
- *
61
- * // Now --theme-color can be animated with CSS transitions
62
- * return <div style={{ '--theme-color': 'blue' } as React.CSSProperties}>Colored</div>;
63
- * }
64
- * ```
65
- *
66
- * @example Legacy format (still supported)
67
- * ```tsx
68
- * function ResizableBox() {
69
- * useProperty('--box-size', {
70
- * syntax: '<length>',
71
- * initialValue: '100px',
72
- * });
73
- *
74
- * return <div style={{ width: 'var(--box-size)' }} />;
75
- * }
76
- * ```
77
- */
78
- declare function useProperty(name: string, options?: UsePropertyOptions): void;
79
- //#endregion
80
- export { UsePropertyOptions, useProperty };
81
- //# sourceMappingURL=useProperty.d.ts.map
@@ -1,96 +0,0 @@
1
- import { getGlobalInjector } from "../config.js";
2
- import { getStyleTarget, pushRSCCSS } from "../rsc-cache.js";
3
- import { formatPropertyCSS } from "../ssr/format-property.js";
4
- //#region src/hooks/useProperty.ts
5
- /**
6
- * Register a CSS @property custom property.
7
- * This enables advanced features like animating custom properties.
8
- *
9
- * Note: @property rules are global and persistent once defined.
10
- * The function ensures the property is only registered once per root.
11
- *
12
- * Accepts tasty token syntax for the property name:
13
- * - `$name` → defines `--name`
14
- * - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
15
- * - `--name` → defines `--name` (legacy format)
16
- *
17
- * Works in all environments: client, SSR with collector, and React Server Components.
18
- *
19
- * @param name - The property token ($name, #name) or CSS property name (--name)
20
- * @param options - Property configuration
21
- *
22
- * @example Basic property with token syntax
23
- * ```tsx
24
- * function Spinner() {
25
- * useProperty('$rotation', {
26
- * syntax: '<angle>',
27
- * inherits: false,
28
- * initialValue: '0deg',
29
- * });
30
- *
31
- * return <div className="spinner" />;
32
- * }
33
- * ```
34
- *
35
- * @example Color property with token syntax (auto-sets syntax)
36
- * ```tsx
37
- * function MyComponent() {
38
- * useProperty('#theme', {
39
- * initialValue: 'red', // syntax: '<color>' is auto-set
40
- * });
41
- *
42
- * // Now --theme-color can be animated with CSS transitions
43
- * return <div style={{ '--theme-color': 'blue' } as React.CSSProperties}>Colored</div>;
44
- * }
45
- * ```
46
- *
47
- * @example Legacy format (still supported)
48
- * ```tsx
49
- * function ResizableBox() {
50
- * useProperty('--box-size', {
51
- * syntax: '<length>',
52
- * initialValue: '100px',
53
- * });
54
- *
55
- * return <div style={{ width: 'var(--box-size)' }} />;
56
- * }
57
- * ```
58
- */
59
- function useProperty(name, options) {
60
- if (!name) {
61
- console.warn(`[Tasty] useProperty: property name is required`);
62
- return;
63
- }
64
- const target = getStyleTarget();
65
- if (target.mode === "ssr") {
66
- target.collector.collectInternals();
67
- const css = formatPropertyCSS(name, {
68
- syntax: options?.syntax,
69
- inherits: options?.inherits,
70
- initialValue: options?.initialValue
71
- });
72
- if (css) target.collector.collectProperty(name, css);
73
- return;
74
- }
75
- if (target.mode === "rsc") {
76
- const css = formatPropertyCSS(name, {
77
- syntax: options?.syntax,
78
- inherits: options?.inherits,
79
- initialValue: options?.initialValue
80
- });
81
- if (css) pushRSCCSS(target.cache, `__prop:${name}`, css);
82
- return;
83
- }
84
- const injector = getGlobalInjector();
85
- if (injector.isPropertyDefined(name, { root: options?.root })) return;
86
- injector.property(name, {
87
- syntax: options?.syntax,
88
- inherits: options?.inherits,
89
- initialValue: options?.initialValue,
90
- root: options?.root
91
- });
92
- }
93
- //#endregion
94
- export { useProperty };
95
-
96
- //# sourceMappingURL=useProperty.js.map