@slurp-ui/react 0.0.0-stage → 1.0.0

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 (334) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -2
  3. package/dist/AccentScope/AccentScope.d.ts +15 -0
  4. package/dist/AccentScope/AccentScope.js +31 -0
  5. package/dist/AccentScope/AccentScope.js.map +1 -0
  6. package/dist/AccentScope/index.d.ts +3 -0
  7. package/dist/AccentScope/index.js +2 -0
  8. package/dist/Avatar/Avatar.d.ts +17 -0
  9. package/dist/Avatar/Avatar.js +42 -0
  10. package/dist/Avatar/Avatar.js.map +1 -0
  11. package/dist/Avatar/index.d.ts +3 -0
  12. package/dist/Avatar/index.js +2 -0
  13. package/dist/Bento/Bento.d.ts +14 -0
  14. package/dist/Bento/Bento.js +42 -0
  15. package/dist/Bento/Bento.js.map +1 -0
  16. package/dist/Bento/index.d.ts +3 -0
  17. package/dist/Bento/index.js +2 -0
  18. package/dist/Bloom/Bloom.d.ts +42 -0
  19. package/dist/Bloom/Bloom.js +183 -0
  20. package/dist/Bloom/Bloom.js.map +1 -0
  21. package/dist/Bloom/index.d.ts +3 -0
  22. package/dist/Bloom/index.js +2 -0
  23. package/dist/Bubble/Bubble.d.ts +20 -0
  24. package/dist/Bubble/Bubble.js +30 -0
  25. package/dist/Bubble/Bubble.js.map +1 -0
  26. package/dist/Bubble/index.d.ts +3 -0
  27. package/dist/Bubble/index.js +2 -0
  28. package/dist/Button/Button.d.ts +26 -0
  29. package/dist/Button/Button.js +50 -0
  30. package/dist/Button/Button.js.map +1 -0
  31. package/dist/Button/index.d.ts +3 -0
  32. package/dist/Button/index.js +2 -0
  33. package/dist/Card/Card.d.ts +26 -0
  34. package/dist/Card/Card.js +70 -0
  35. package/dist/Card/Card.js.map +1 -0
  36. package/dist/Card/index.d.ts +3 -0
  37. package/dist/Card/index.js +2 -0
  38. package/dist/Cell/Cell.d.ts +7 -0
  39. package/dist/Cell/Cell.js +20 -0
  40. package/dist/Cell/Cell.js.map +1 -0
  41. package/dist/Cell/index.d.ts +3 -0
  42. package/dist/Cell/index.js +2 -0
  43. package/dist/Checkbox/Checkbox.d.ts +27 -0
  44. package/dist/Checkbox/Checkbox.js +82 -0
  45. package/dist/Checkbox/Checkbox.js.map +1 -0
  46. package/dist/Checkbox/index.d.ts +3 -0
  47. package/dist/Checkbox/index.js +2 -0
  48. package/dist/Chip/Chip.d.ts +15 -0
  49. package/dist/Chip/Chip.js +40 -0
  50. package/dist/Chip/Chip.js.map +1 -0
  51. package/dist/Chip/index.d.ts +3 -0
  52. package/dist/Chip/index.js +2 -0
  53. package/dist/Choice/Choice.d.ts +37 -0
  54. package/dist/Choice/Choice.js +134 -0
  55. package/dist/Choice/Choice.js.map +1 -0
  56. package/dist/Choice/index.d.ts +3 -0
  57. package/dist/Choice/index.js +2 -0
  58. package/dist/Count/Count.d.ts +19 -0
  59. package/dist/Count/Count.js +30 -0
  60. package/dist/Count/Count.js.map +1 -0
  61. package/dist/Count/index.d.ts +3 -0
  62. package/dist/Count/index.js +2 -0
  63. package/dist/Dialog/Dialog.d.ts +26 -0
  64. package/dist/Dialog/Dialog.js +152 -0
  65. package/dist/Dialog/Dialog.js.map +1 -0
  66. package/dist/Dialog/index.d.ts +3 -0
  67. package/dist/Dialog/index.js +2 -0
  68. package/dist/Dock/Dock.d.ts +124 -0
  69. package/dist/Dock/Dock.js +359 -0
  70. package/dist/Dock/Dock.js.map +1 -0
  71. package/dist/Dock/index.d.ts +3 -0
  72. package/dist/Dock/index.js +2 -0
  73. package/dist/Empty/Empty.d.ts +17 -0
  74. package/dist/Empty/Empty.js +40 -0
  75. package/dist/Empty/Empty.js.map +1 -0
  76. package/dist/Empty/index.d.ts +3 -0
  77. package/dist/Empty/index.js +2 -0
  78. package/dist/Fact/Fact.d.ts +11 -0
  79. package/dist/Fact/Fact.js +27 -0
  80. package/dist/Fact/Fact.js.map +1 -0
  81. package/dist/Fact/index.d.ts +3 -0
  82. package/dist/Fact/index.js +2 -0
  83. package/dist/Field/Field.d.ts +44 -0
  84. package/dist/Field/Field.js +105 -0
  85. package/dist/Field/Field.js.map +1 -0
  86. package/dist/Field/index.d.ts +3 -0
  87. package/dist/Field/index.js +2 -0
  88. package/dist/Filters/Filters.d.ts +37 -0
  89. package/dist/Filters/Filters.js +64 -0
  90. package/dist/Filters/Filters.js.map +1 -0
  91. package/dist/Filters/index.d.ts +3 -0
  92. package/dist/Filters/index.js +2 -0
  93. package/dist/Flow/Flow.d.ts +17 -0
  94. package/dist/Flow/Flow.js +26 -0
  95. package/dist/Flow/Flow.js.map +1 -0
  96. package/dist/Flow/index.d.ts +3 -0
  97. package/dist/Flow/index.js +2 -0
  98. package/dist/Fold/Fold.d.ts +17 -0
  99. package/dist/Fold/Fold.js +64 -0
  100. package/dist/Fold/Fold.js.map +1 -0
  101. package/dist/Fold/index.d.ts +3 -0
  102. package/dist/Fold/index.js +2 -0
  103. package/dist/Frame/Frame.d.ts +7 -0
  104. package/dist/Frame/Frame.js +20 -0
  105. package/dist/Frame/Frame.js.map +1 -0
  106. package/dist/Frame/index.d.ts +3 -0
  107. package/dist/Frame/index.js +2 -0
  108. package/dist/Ground/Ground.d.ts +7 -0
  109. package/dist/Ground/Ground.js +19 -0
  110. package/dist/Ground/Ground.js.map +1 -0
  111. package/dist/Ground/index.d.ts +3 -0
  112. package/dist/Ground/index.js +2 -0
  113. package/dist/Hint/Hint.d.ts +21 -0
  114. package/dist/Hint/Hint.js +104 -0
  115. package/dist/Hint/Hint.js.map +1 -0
  116. package/dist/Hint/index.d.ts +3 -0
  117. package/dist/Hint/index.js +2 -0
  118. package/dist/Link/Link.d.ts +7 -0
  119. package/dist/Link/Link.js +20 -0
  120. package/dist/Link/Link.js.map +1 -0
  121. package/dist/Link/index.d.ts +3 -0
  122. package/dist/Link/index.js +2 -0
  123. package/dist/ListRow/ListRow.d.ts +25 -0
  124. package/dist/ListRow/ListRow.js +80 -0
  125. package/dist/ListRow/ListRow.js.map +1 -0
  126. package/dist/ListRow/index.d.ts +3 -0
  127. package/dist/ListRow/index.js +2 -0
  128. package/dist/Mark/Mark.d.ts +14 -0
  129. package/dist/Mark/Mark.js +28 -0
  130. package/dist/Mark/Mark.js.map +1 -0
  131. package/dist/Mark/index.d.ts +3 -0
  132. package/dist/Mark/index.js +2 -0
  133. package/dist/Menu/Menu.d.ts +29 -0
  134. package/dist/Menu/Menu.js +64 -0
  135. package/dist/Menu/Menu.js.map +1 -0
  136. package/dist/Menu/index.d.ts +3 -0
  137. package/dist/Menu/index.js +2 -0
  138. package/dist/Notice/Notice.d.ts +31 -0
  139. package/dist/Notice/Notice.js +82 -0
  140. package/dist/Notice/Notice.js.map +1 -0
  141. package/dist/Notice/index.d.ts +3 -0
  142. package/dist/Notice/index.js +2 -0
  143. package/dist/Placeholder/Placeholder.d.ts +15 -0
  144. package/dist/Placeholder/Placeholder.js +28 -0
  145. package/dist/Placeholder/Placeholder.js.map +1 -0
  146. package/dist/Placeholder/index.d.ts +3 -0
  147. package/dist/Placeholder/index.js +2 -0
  148. package/dist/Portal/Portal.d.ts +10 -0
  149. package/dist/Portal/Portal.js +13 -0
  150. package/dist/Portal/Portal.js.map +1 -0
  151. package/dist/Portal/index.d.ts +3 -0
  152. package/dist/Portal/index.js +2 -0
  153. package/dist/Progress/Progress.d.ts +22 -0
  154. package/dist/Progress/Progress.js +65 -0
  155. package/dist/Progress/Progress.js.map +1 -0
  156. package/dist/Progress/index.d.ts +3 -0
  157. package/dist/Progress/index.js +2 -0
  158. package/dist/Radio/Radio.d.ts +39 -0
  159. package/dist/Radio/Radio.js +118 -0
  160. package/dist/Radio/Radio.js.map +1 -0
  161. package/dist/Radio/index.d.ts +3 -0
  162. package/dist/Radio/index.js +2 -0
  163. package/dist/Range/Range.d.ts +26 -0
  164. package/dist/Range/Range.js +68 -0
  165. package/dist/Range/Range.js.map +1 -0
  166. package/dist/Range/index.d.ts +3 -0
  167. package/dist/Range/index.js +2 -0
  168. package/dist/ResultRow/ResultRow.d.ts +17 -0
  169. package/dist/ResultRow/ResultRow.js +46 -0
  170. package/dist/ResultRow/ResultRow.js.map +1 -0
  171. package/dist/ResultRow/index.d.ts +3 -0
  172. package/dist/ResultRow/index.js +2 -0
  173. package/dist/Score/Score.d.ts +16 -0
  174. package/dist/Score/Score.js +55 -0
  175. package/dist/Score/Score.js.map +1 -0
  176. package/dist/Score/index.d.ts +3 -0
  177. package/dist/Score/index.js +2 -0
  178. package/dist/Search/Search.d.ts +29 -0
  179. package/dist/Search/Search.js +94 -0
  180. package/dist/Search/Search.js.map +1 -0
  181. package/dist/Search/index.d.ts +3 -0
  182. package/dist/Search/index.js +2 -0
  183. package/dist/Segmented/Segmented.d.ts +24 -0
  184. package/dist/Segmented/Segmented.js +69 -0
  185. package/dist/Segmented/Segmented.js.map +1 -0
  186. package/dist/Segmented/index.d.ts +3 -0
  187. package/dist/Segmented/index.js +2 -0
  188. package/dist/Settings/Settings.d.ts +49 -0
  189. package/dist/Settings/Settings.js +93 -0
  190. package/dist/Settings/Settings.js.map +1 -0
  191. package/dist/Settings/index.d.ts +3 -0
  192. package/dist/Settings/index.js +2 -0
  193. package/dist/Sheet/Sheet.d.ts +7 -0
  194. package/dist/Sheet/Sheet.js +11 -0
  195. package/dist/Sheet/Sheet.js.map +1 -0
  196. package/dist/Sheet/index.d.ts +3 -0
  197. package/dist/Sheet/index.js +2 -0
  198. package/dist/Shelf/Shelf.d.ts +7 -0
  199. package/dist/Shelf/Shelf.js +23 -0
  200. package/dist/Shelf/Shelf.js.map +1 -0
  201. package/dist/Shelf/index.d.ts +3 -0
  202. package/dist/Shelf/index.js +2 -0
  203. package/dist/SlurpProvider/ColorSchemeScript.d.ts +15 -0
  204. package/dist/SlurpProvider/ColorSchemeScript.js +18 -0
  205. package/dist/SlurpProvider/ColorSchemeScript.js.map +1 -0
  206. package/dist/SlurpProvider/SlurpProvider.d.ts +18 -0
  207. package/dist/SlurpProvider/SlurpProvider.js +106 -0
  208. package/dist/SlurpProvider/SlurpProvider.js.map +1 -0
  209. package/dist/SlurpProvider/index.d.ts +5 -0
  210. package/dist/SlurpProvider/index.js +5 -0
  211. package/dist/Stage/Stage.d.ts +14 -0
  212. package/dist/Stage/Stage.js +38 -0
  213. package/dist/Stage/Stage.js.map +1 -0
  214. package/dist/Stage/index.d.ts +3 -0
  215. package/dist/Stage/index.js +2 -0
  216. package/dist/Surface/Surface.d.ts +16 -0
  217. package/dist/Surface/Surface.js +25 -0
  218. package/dist/Surface/Surface.js.map +1 -0
  219. package/dist/Surface/index.d.ts +3 -0
  220. package/dist/Surface/index.js +2 -0
  221. package/dist/Swatch/Swatch.d.ts +31 -0
  222. package/dist/Swatch/Swatch.js +72 -0
  223. package/dist/Swatch/Swatch.js.map +1 -0
  224. package/dist/Swatch/index.d.ts +3 -0
  225. package/dist/Swatch/index.js +2 -0
  226. package/dist/Switch/Switch.d.ts +15 -0
  227. package/dist/Switch/Switch.js +62 -0
  228. package/dist/Switch/Switch.js.map +1 -0
  229. package/dist/Switch/index.d.ts +3 -0
  230. package/dist/Switch/index.js +2 -0
  231. package/dist/Tabs/Tabs.d.ts +21 -0
  232. package/dist/Tabs/Tabs.js +105 -0
  233. package/dist/Tabs/Tabs.js.map +1 -0
  234. package/dist/Tabs/index.d.ts +3 -0
  235. package/dist/Tabs/index.js +2 -0
  236. package/dist/Text/Text.d.ts +17 -0
  237. package/dist/Text/Text.js +33 -0
  238. package/dist/Text/Text.js.map +1 -0
  239. package/dist/Text/index.d.ts +3 -0
  240. package/dist/Text/index.js +2 -0
  241. package/dist/Tile/Tile.d.ts +25 -0
  242. package/dist/Tile/Tile.js +67 -0
  243. package/dist/Tile/Tile.js.map +1 -0
  244. package/dist/Tile/index.d.ts +3 -0
  245. package/dist/Tile/index.js +2 -0
  246. package/dist/Toast/Toast.d.ts +43 -0
  247. package/dist/Toast/Toast.js +132 -0
  248. package/dist/Toast/Toast.js.map +1 -0
  249. package/dist/Toast/index.d.ts +3 -0
  250. package/dist/Toast/index.js +2 -0
  251. package/dist/VisuallyHidden/VisuallyHidden.d.ts +7 -0
  252. package/dist/VisuallyHidden/VisuallyHidden.js +15 -0
  253. package/dist/VisuallyHidden/VisuallyHidden.js.map +1 -0
  254. package/dist/VisuallyHidden/index.d.ts +3 -0
  255. package/dist/VisuallyHidden/index.js +2 -0
  256. package/dist/fonts/poppins-latin-400-normal.woff2 +0 -0
  257. package/dist/fonts/poppins-latin-500-normal.woff2 +0 -0
  258. package/dist/fonts/poppins-latin-600-normal.woff2 +0 -0
  259. package/dist/fonts/poppins-latin-700-normal.woff2 +0 -0
  260. package/dist/icons/index.d.ts +2 -0
  261. package/dist/icons/index.js +2 -0
  262. package/dist/index.d.ts +121 -0
  263. package/dist/index.js +69 -0
  264. package/dist/internal/animation.js +26 -0
  265. package/dist/internal/animation.js.map +1 -0
  266. package/dist/internal/context.d.ts +14 -0
  267. package/dist/internal/context.js +21 -0
  268. package/dist/internal/context.js.map +1 -0
  269. package/dist/internal/styled.js +79 -0
  270. package/dist/internal/styled.js.map +1 -0
  271. package/dist/lib/color.d.ts +21 -0
  272. package/dist/lib/color.js +151 -0
  273. package/dist/lib/color.js.map +1 -0
  274. package/dist/lib/crumb.d.ts +9 -0
  275. package/dist/lib/crumb.js +69 -0
  276. package/dist/lib/crumb.js.map +1 -0
  277. package/dist/lib/css.d.ts +53 -0
  278. package/dist/lib/css.js +142 -0
  279. package/dist/lib/css.js.map +1 -0
  280. package/dist/lib/ground.js +15 -0
  281. package/dist/lib/ground.js.map +1 -0
  282. package/dist/lib/layout.d.ts +24 -0
  283. package/dist/lib/layout.js +88 -0
  284. package/dist/lib/layout.js.map +1 -0
  285. package/dist/lib/polymorphic.d.ts +28 -0
  286. package/dist/lib/theme.d.ts +292 -0
  287. package/dist/lib/theme.js +90 -0
  288. package/dist/lib/theme.js.map +1 -0
  289. package/dist/motion/AnimationGroup.d.ts +10 -0
  290. package/dist/motion/AnimationGroup.js +14 -0
  291. package/dist/motion/AnimationGroup.js.map +1 -0
  292. package/dist/motion/context.js +8 -0
  293. package/dist/motion/context.js.map +1 -0
  294. package/dist/motion/index.d.ts +7 -0
  295. package/dist/motion/index.js +7 -0
  296. package/dist/motion/navigation.d.ts +51 -0
  297. package/dist/motion/navigation.js +122 -0
  298. package/dist/motion/navigation.js.map +1 -0
  299. package/dist/motion/useAnimationTarget.d.ts +22 -0
  300. package/dist/motion/useAnimationTarget.js +34 -0
  301. package/dist/motion/useAnimationTarget.js.map +1 -0
  302. package/dist/motion/useSlurp.d.ts +18 -0
  303. package/dist/motion/useSlurp.js +48 -0
  304. package/dist/motion/useSlurp.js.map +1 -0
  305. package/dist/styles.css +3439 -0
  306. package/dist/tokens/index.d.ts +2 -0
  307. package/dist/tokens/index.js +2 -0
  308. package/dist/tokens.css +178 -0
  309. package/dist/utils/focus.d.ts +20 -0
  310. package/dist/utils/focus.js +50 -0
  311. package/dist/utils/focus.js.map +1 -0
  312. package/dist/utils/index.d.ts +10 -0
  313. package/dist/utils/index.js +10 -0
  314. package/dist/utils/src/index.js +9 -0
  315. package/dist/utils/src/index.js.map +1 -0
  316. package/dist/utils/useControlled.d.ts +14 -0
  317. package/dist/utils/useControlled.js +23 -0
  318. package/dist/utils/useControlled.js.map +1 -0
  319. package/dist/utils/useDismiss.d.ts +24 -0
  320. package/dist/utils/useDismiss.js +60 -0
  321. package/dist/utils/useDismiss.js.map +1 -0
  322. package/dist/utils/useFindInPage.d.ts +18 -0
  323. package/dist/utils/useFindInPage.js +51 -0
  324. package/dist/utils/useFindInPage.js.map +1 -0
  325. package/dist/utils/useForkRef.d.ts +5 -0
  326. package/dist/utils/useForkRef.js +33 -0
  327. package/dist/utils/useForkRef.js.map +1 -0
  328. package/dist/utils/useMediaQuery.d.ts +11 -0
  329. package/dist/utils/useMediaQuery.js +21 -0
  330. package/dist/utils/useMediaQuery.js.map +1 -0
  331. package/dist/utils/useRovingFocus.d.ts +17 -0
  332. package/dist/utils/useRovingFocus.js +26 -0
  333. package/dist/utils/useRovingFocus.js.map +1 -0
  334. package/package.json +107 -3
@@ -0,0 +1,90 @@
1
+
2
+ import { accentVars, resolveAccent } from "./color.js";
3
+ import { LAYER_ORDER, hash } from "./css.js";
4
+ import { MOTION_DEFAULTS } from "@slurp-ui/motion";
5
+ // src/lib/theme.ts
6
+ const { duration, stagger, curve, swell, drop, reducedMotion, interrupt } = MOTION_DEFAULTS;
7
+ const DEFAULT_MOTION = {
8
+ duration,
9
+ stagger,
10
+ curve,
11
+ swell,
12
+ drop,
13
+ reducedMotion,
14
+ interrupt,
15
+ goo: "auto",
16
+ ghost: "shape",
17
+ order: "distance"
18
+ };
19
+ const DEFAULT_ACCENT = "hue-violet";
20
+ /** localStorage key of the chosen colour scheme (same as the design system's setTheme()). */
21
+ const DEFAULT_STORAGE_KEY = "slurp-theme";
22
+ function createTheme(options = {}) {
23
+ const accent = options.accent ?? DEFAULT_ACCENT;
24
+ return {
25
+ colorScheme: options.colorScheme ?? "system",
26
+ accent,
27
+ accentColor: resolveAccent(accent),
28
+ locale: options.locale ?? "it-IT",
29
+ tokens: options.tokens ?? {},
30
+ motion: {
31
+ ...DEFAULT_MOTION,
32
+ ...options.motion
33
+ },
34
+ components: options.components ?? {}
35
+ };
36
+ }
37
+ const defaultTheme = createTheme();
38
+ const px = (v) => typeof v === "number" ? `${v}px` : v;
39
+ /** Light / dark declarations of the token overrides of a theme. */
40
+ function overrideDeclarations(tokens) {
41
+ const light = [];
42
+ const dark = [];
43
+ const add = (name, v) => {
44
+ if (typeof v === "object") {
45
+ light.push(`--slurp-${name}:${v.light}`);
46
+ dark.push(`--slurp-${name}:${v.dark}`);
47
+ } else light.push(`--slurp-${name}:${px(v)}`);
48
+ };
49
+ for (const [k, v] of Object.entries(tokens.color ?? {})) if (v !== void 0) add(k, v);
50
+ for (const [k, v] of Object.entries(tokens.space ?? {})) if (v !== void 0) add(`space-${k}`, v);
51
+ for (const [k, v] of Object.entries(tokens.radius ?? {})) if (v !== void 0) add(`radius-${k}`, v);
52
+ for (const [k, v] of Object.entries(tokens.shadow ?? {})) if (v !== void 0) add(`shadow-${k}`, v);
53
+ for (const [k, v] of Object.entries(tokens.blur ?? {})) if (v !== void 0) add(`blur-${k}`, v);
54
+ return {
55
+ light,
56
+ dark
57
+ };
58
+ }
59
+ function selectors(scope) {
60
+ if (!scope) return {
61
+ base: ":root,[data-theme]",
62
+ dark: "[data-theme='dark']",
63
+ systemDark: ":root:not([data-theme='light'])"
64
+ };
65
+ const s = `[data-slurp-theme="${scope}"]`;
66
+ return {
67
+ base: `${s},${s} [data-theme]`,
68
+ dark: `:root[data-theme='dark'] ${s},${s} [data-theme='dark']`,
69
+ systemDark: `:root:not([data-theme='light']) ${s}`
70
+ };
71
+ }
72
+ /**
73
+ * The stylesheet of a theme: accent variables and token overrides, on the root (or on a nested provider's `scope`)
74
+ * and on every `data-theme` subtree, so derived values re-resolve per theme. Empty for the default theme.
75
+ * tokens.css uses `:where()`, so these plain selectors win whatever the stylesheet order.
76
+ */
77
+ function themeCss(theme, scope) {
78
+ const { light, dark } = overrideDeclarations(theme.tokens);
79
+ const base = [...theme.accent === DEFAULT_ACCENT ? [] : Object.entries(accentVars(theme.accentColor)).map(([k, v]) => `${k}:${v}`), ...light];
80
+ if (!base.length && !dark.length) return "";
81
+ const sel = selectors(scope);
82
+ const rules = [`${sel.base}{${base.join(";")}}`];
83
+ if (dark.length) rules.push(`${sel.dark}{${dark.join(";")}}`, `@media (prefers-color-scheme: dark){${sel.systemDark}{${dark.join(";")}}}`);
84
+ return `${LAYER_ORDER}@layer slurp.base{${rules.join("")}}`;
85
+ }
86
+ /** Stable id of a stylesheet, for React's <style href> de-duplication. */
87
+ const styleId = (prefix, css) => `slurp-${prefix}-${hash(css)}`;
88
+ export { DEFAULT_STORAGE_KEY, createTheme, defaultTheme, styleId, themeCss };
89
+
90
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.js","names":[],"sources":["../../src/lib/theme.ts"],"sourcesContent":["// createTheme() and the stylesheet that applies a theme. Server-safe: a theme is plain, serialisable data,\n// so it can be created in a server component and passed to <SlurpProvider>.\nimport { MOTION_DEFAULTS, type GhostKind, type SlurpDefaults } from '@slurp-ui/motion';\nimport type { blur, ColorToken, HueToken, RadiusToken, shadow, SpaceToken } from '@slurp-ui/tokens';\n\nimport type { AccentScopeProps } from '../AccentScope/AccentScope';\nimport type { BentoProps } from '../Bento/Bento';\nimport type { CardProps } from '../Card/Card';\nimport type { DockProps } from '../Dock/Dock';\nimport type { EmptyProps } from '../Empty/Empty';\nimport type { FactProps } from '../Fact/Fact';\nimport type { FiltersProps } from '../Filters/Filters';\nimport type { LinkProps } from '../Link/Link';\nimport type { ListProps, ListRowProps } from '../ListRow/ListRow';\nimport type { ResultRowProps } from '../ResultRow/ResultRow';\nimport type { ScoreProps } from '../Score/Score';\nimport type { SettingsProps } from '../Settings/Settings';\nimport type { ShelfProps } from '../Shelf/Shelf';\nimport type { StageProps } from '../Stage/Stage';\nimport type { TileProps } from '../Tile/Tile';\nimport type { AvatarProps } from '../Avatar/Avatar';\nimport type { BloomProps } from '../Bloom/Bloom';\nimport type { BubbleProps } from '../Bubble/Bubble';\nimport type { ButtonProps } from '../Button/Button';\nimport type { CellProps } from '../Cell/Cell';\nimport type { CheckboxProps } from '../Checkbox/Checkbox';\nimport type { ChipProps } from '../Chip/Chip';\nimport type { ChoiceProps } from '../Choice/Choice';\nimport type { CountProps } from '../Count/Count';\nimport type { DialogProps } from '../Dialog/Dialog';\nimport type { FieldProps } from '../Field/Field';\nimport type { FlowProps } from '../Flow/Flow';\nimport type { FoldProps } from '../Fold/Fold';\nimport type { FrameProps } from '../Frame/Frame';\nimport type { HintProps } from '../Hint/Hint';\nimport type { MenuProps } from '../Menu/Menu';\nimport type { NoticeProps } from '../Notice/Notice';\nimport type { PlaceholderProps } from '../Placeholder/Placeholder';\nimport type { ProgressProps } from '../Progress/Progress';\nimport type { RadioGroupProps, RadioProps } from '../Radio/Radio';\nimport type { RangeProps } from '../Range/Range';\nimport type { SearchProps } from '../Search/Search';\nimport type { SegmentedProps } from '../Segmented/Segmented';\nimport type { SheetProps } from '../Sheet/Sheet';\nimport type { SurfaceProps } from '../Surface/Surface';\nimport type { SwatchGroupProps, SwatchProps } from '../Swatch/Swatch';\nimport type { SwitchProps } from '../Switch/Switch';\nimport type { TabsProps } from '../Tabs/Tabs';\nimport type { TextProps } from '../Text/Text';\nimport { accentVars, resolveAccent } from './color';\nimport { hash, LAYER_ORDER, type SlurpCss } from './css';\n\nexport type ColorSchemeMode = 'light' | 'dark' | 'system';\nexport type ResolvedColorScheme = 'light' | 'dark';\n/** A `hue-*` preset (used as is) or any hex colour (turned into an accent with `vivid()`). */\nexport type AccentInput = `hue-${HueToken}` | `#${string}`;\n\ntype Themed = string | { light: string; dark: string };\ntype Length = string | number;\n\nexport interface TokenOverrides {\n color?: Partial<Record<ColorToken | `hue-${HueToken}`, Themed>>;\n space?: Partial<Record<SpaceToken, Length>>;\n radius?: Partial<Record<RadiusToken, Length>>;\n shadow?: Partial<Record<keyof typeof shadow, Themed>>;\n blur?: Partial<Record<keyof typeof blur, Length>>;\n}\n\n/** Defaults of the collapse / expand transitions started with useSlurp() (serialisable values only). */\nexport interface MotionOptions extends Pick<\n SlurpDefaults,\n 'duration' | 'stagger' | 'curve' | 'swell' | 'drop' | 'reducedMotion' | 'interrupt'\n> {\n goo: boolean | 'auto';\n ghost: GhostKind;\n order: 'distance' | 'dom';\n}\n\nconst { duration, stagger, curve, swell, drop, reducedMotion, interrupt } = MOTION_DEFAULTS;\nconst DEFAULT_MOTION: MotionOptions = {\n duration,\n stagger,\n curve,\n swell,\n drop,\n reducedMotion,\n interrupt,\n goo: 'auto',\n ghost: 'shape',\n order: 'distance',\n};\n\n/** Components that read defaults and `css` overrides from the theme, with their parts. */\nexport interface ThemeComponents {\n AccentScope: { props: AccentScopeProps; parts: 'root' };\n Bento: { props: BentoProps; parts: 'root' };\n Card: { props: CardProps; parts: 'root' | 'media' | 'badge' | 'title' | 'description' };\n Dock: { props: DockProps; parts: 'root' };\n Empty: { props: EmptyProps; parts: 'root' };\n Fact: { props: FactProps; parts: 'root' };\n Filters: { props: FiltersProps; parts: 'root' };\n Link: { props: LinkProps; parts: 'root' };\n List: { props: ListProps; parts: 'root' };\n ListRow: {\n props: ListRowProps;\n parts: 'root' | 'mark' | 'title' | 'tag' | 'meta' | 'value' | 'action';\n };\n ResultRow: { props: ResultRowProps; parts: 'root' };\n Score: { props: ScoreProps; parts: 'root' };\n Settings: { props: SettingsProps; parts: 'root' };\n Shelf: { props: ShelfProps; parts: 'root' };\n Stage: { props: StageProps; parts: 'root' };\n Tile: {\n props: TileProps;\n parts: 'root' | 'blob' | 'text' | 'title' | 'subtitle' | 'badge' | 'media';\n };\n Avatar: { props: AvatarProps; parts: 'root' };\n Bloom: { props: BloomProps; parts: 'root' | 'surface' | 'trigger' | 'panel' };\n Bubble: { props: BubbleProps; parts: 'root' };\n Button: { props: ButtonProps; parts: 'root' | 'icon' | 'label' | 'endIcon' };\n Cell: { props: CellProps; parts: 'root' };\n Checkbox: { props: CheckboxProps; parts: 'root' | 'input' | 'box' | 'label' };\n Chip: { props: ChipProps; parts: 'root' };\n Choice: { props: ChoiceProps; parts: 'root' };\n Count: { props: CountProps; parts: 'root' };\n Dialog: {\n props: DialogProps;\n parts: 'root' | 'header' | 'title' | 'description' | 'body' | 'footer' | 'close';\n };\n Field: { props: FieldProps; parts: 'root' | 'label' | 'control' | 'hint' | 'error' };\n Flow: { props: FlowProps; parts: 'root' };\n Fold: { props: FoldProps; parts: 'root' | 'heading' | 'trigger' | 'region' };\n Frame: { props: FrameProps; parts: 'root' };\n Hint: { props: HintProps; parts: 'root' };\n Menu: { props: MenuProps; parts: 'root' };\n Notice: { props: NoticeProps; parts: 'root' | 'icon' | 'title' | 'body' | 'dismiss' };\n Placeholder: { props: PlaceholderProps; parts: 'root' };\n Progress: { props: ProgressProps; parts: 'root' };\n Radio: { props: RadioProps; parts: 'root' | 'input' | 'dot' | 'label' };\n RadioGroup: { props: RadioGroupProps; parts: 'root' | 'legend' };\n Range: { props: RangeProps; parts: 'root' | 'label' | 'value' | 'control' };\n Search: { props: SearchProps; parts: 'root' | 'icon' | 'control' | 'clear' | 'status' };\n Segmented: { props: SegmentedProps; parts: 'root' | 'item' };\n Sheet: {\n props: SheetProps;\n parts: 'root' | 'header' | 'title' | 'description' | 'body' | 'footer' | 'close';\n };\n Surface: { props: SurfaceProps; parts: 'root' };\n Swatch: { props: SwatchProps; parts: 'root' };\n SwatchGroup: { props: SwatchGroupProps; parts: 'root' };\n Switch: { props: SwitchProps; parts: 'root' | 'input' | 'track' | 'thumb' | 'label' };\n Tabs: { props: TabsProps; parts: 'root' | 'list' | 'tab' | 'indicator' | 'panel' };\n Text: { props: TextProps; parts: 'root' };\n}\nexport type ComponentName = keyof ThemeComponents;\n\nexport type ComponentsConfig = {\n [K in ComponentName]?: {\n defaults?: Partial<Omit<ThemeComponents[K]['props'], 'ref' | 'children' | 'css'>>;\n css?: Partial<Record<ThemeComponents[K]['parts'], SlurpCss>>;\n };\n};\n\nexport interface ThemeOptions {\n /** Initial colour scheme, until the person chooses one (default `system`). */\n colorScheme?: ColorSchemeMode;\n /** Default `hue-violet`. */\n accent?: AccentInput;\n /** Used only by Intl (numbers, prices). Not an i18n system. Default `it-IT`. */\n locale?: string;\n tokens?: TokenOverrides;\n motion?: Partial<MotionOptions>;\n components?: ComponentsConfig;\n}\n\nexport interface Theme {\n colorScheme: ColorSchemeMode;\n accent: AccentInput;\n /** The accent actually painted (hex). */\n accentColor: string;\n locale: string;\n tokens: TokenOverrides;\n motion: MotionOptions;\n components: ComponentsConfig;\n}\n\nconst DEFAULT_ACCENT: AccentInput = 'hue-violet';\n\n/** localStorage key of the chosen colour scheme (same as the design system's setTheme()). */\nexport const DEFAULT_STORAGE_KEY = 'slurp-theme';\n\nexport function createTheme(options: ThemeOptions = {}): Theme {\n const accent = options.accent ?? DEFAULT_ACCENT;\n return {\n colorScheme: options.colorScheme ?? 'system',\n accent,\n accentColor: resolveAccent(accent),\n locale: options.locale ?? 'it-IT',\n tokens: options.tokens ?? {},\n motion: { ...DEFAULT_MOTION, ...options.motion },\n components: options.components ?? {},\n };\n}\n\nexport const defaultTheme: Theme = createTheme();\n\nconst px = (v: Length) => (typeof v === 'number' ? `${v}px` : v);\n\n/** Light / dark declarations of the token overrides of a theme. */\nfunction overrideDeclarations(tokens: TokenOverrides) {\n const light: string[] = [];\n const dark: string[] = [];\n const add = (name: string, v: Themed | number) => {\n if (typeof v === 'object') {\n light.push(`--slurp-${name}:${v.light}`);\n dark.push(`--slurp-${name}:${v.dark}`);\n } else light.push(`--slurp-${name}:${px(v)}`);\n };\n for (const [k, v] of Object.entries(tokens.color ?? {})) if (v !== undefined) add(k, v);\n for (const [k, v] of Object.entries(tokens.space ?? {}))\n if (v !== undefined) add(`space-${k}`, v);\n for (const [k, v] of Object.entries(tokens.radius ?? {}))\n if (v !== undefined) add(`radius-${k}`, v);\n for (const [k, v] of Object.entries(tokens.shadow ?? {}))\n if (v !== undefined) add(`shadow-${k}`, v);\n for (const [k, v] of Object.entries(tokens.blur ?? {})) if (v !== undefined) add(`blur-${k}`, v);\n return { light, dark };\n}\n\nfunction selectors(scope: string | undefined) {\n if (!scope) {\n return {\n base: ':root,[data-theme]',\n dark: \"[data-theme='dark']\",\n systemDark: \":root:not([data-theme='light'])\",\n };\n }\n const s = `[data-slurp-theme=\"${scope}\"]`;\n return {\n base: `${s},${s} [data-theme]`,\n dark: `:root[data-theme='dark'] ${s},${s} [data-theme='dark']`,\n systemDark: `:root:not([data-theme='light']) ${s}`,\n };\n}\n\n/**\n * The stylesheet of a theme: accent variables and token overrides, on the root (or on a nested provider's `scope`)\n * and on every `data-theme` subtree, so derived values re-resolve per theme. Empty for the default theme.\n * tokens.css uses `:where()`, so these plain selectors win whatever the stylesheet order.\n */\nexport function themeCss(theme: Theme, scope?: string): string {\n const { light, dark } = overrideDeclarations(theme.tokens);\n const accent =\n theme.accent === DEFAULT_ACCENT\n ? []\n : Object.entries(accentVars(theme.accentColor)).map(([k, v]) => `${k}:${v}`);\n const base = [...accent, ...light];\n if (!base.length && !dark.length) return '';\n const sel = selectors(scope);\n const rules = [`${sel.base}{${base.join(';')}}`];\n if (dark.length) {\n rules.push(\n `${sel.dark}{${dark.join(';')}}`,\n `@media (prefers-color-scheme: dark){${sel.systemDark}{${dark.join(';')}}}`,\n );\n }\n return `${LAYER_ORDER}@layer slurp.base{${rules.join('')}}`;\n}\n\n/** Stable id of a stylesheet, for React's <style href> de-duplication. */\nexport const styleId = (prefix: string, css: string) => `slurp-${prefix}-${hash(css)}`;\n"],"mappings":"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"}
@@ -0,0 +1,10 @@
1
+
2
+ import { ReactNode } from "react";
3
+ export interface AnimationGroupProps {
4
+ /** Group id: `{ group: id }` resolves every element inside that has an animationId. */
5
+ id: string;
6
+ children?: ReactNode;
7
+ }
8
+ /** Declarative group: descendants with an `animationId` join it. Renders no element. */
9
+ export declare function AnimationGroup({ id, children }: AnimationGroupProps): import("react").JSX.Element;
10
+ //# sourceMappingURL=AnimationGroup.d.ts.map
@@ -0,0 +1,14 @@
1
+ "use client";
2
+ import { AnimationGroupContext } from "./context.js";
3
+ import { jsx } from "react/jsx-runtime";
4
+ // src/motion/AnimationGroup.tsx
5
+ /** Declarative group: descendants with an `animationId` join it. Renders no element. */
6
+ function AnimationGroup({ id, children }) {
7
+ return /* @__PURE__ */ jsx(AnimationGroupContext, {
8
+ value: id,
9
+ children
10
+ });
11
+ }
12
+ export { AnimationGroup };
13
+
14
+ //# sourceMappingURL=AnimationGroup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnimationGroup.js","names":[],"sources":["../../src/motion/AnimationGroup.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport { AnimationGroupContext } from './context';\n\nexport interface AnimationGroupProps {\n /** Group id: `{ group: id }` resolves every element inside that has an animationId. */\n id: string;\n children?: ReactNode;\n}\n\n/** Declarative group: descendants with an `animationId` join it. Renders no element. */\nexport function AnimationGroup({ id, children }: AnimationGroupProps) {\n return <AnimationGroupContext value={id}>{children}</AnimationGroupContext>;\n}\n"],"mappings":";;;;;AAWA,SAAgB,eAAe,EAAE,IAAI,YAAiC;CACpE,OAAO,oBAAC,uBAAD;EAAuB,OAAO;EAAK;CAAgC,CAAA;AAC5E"}
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ import { createContext } from "react";
3
+ // src/motion/context.ts
4
+ /** Group id given by the nearest `<AnimationGroup>`. */
5
+ const AnimationGroupContext = createContext(null);
6
+ export { AnimationGroupContext };
7
+
8
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","names":[],"sources":["../../src/motion/context.ts"],"sourcesContent":["import { createContext } from 'react';\n\n/** Group id given by the nearest `<AnimationGroup>`. */\nexport const AnimationGroupContext = createContext<string | null>(null);\n"],"mappings":";;;;AAGA,MAAa,wBAAwB,cAA6B,IAAI"}
@@ -0,0 +1,7 @@
1
+
2
+ import { AnimationProps, useAnimationTarget } from "./useAnimationTarget.js";
3
+ import { AnimationGroup, AnimationGroupProps } from "./AnimationGroup.js";
4
+ import { SlurpControls, useSlurp } from "./useSlurp.js";
5
+ import { ContentRef, SlurpEnterOptions, SlurpNavigate, SlurpNavigateOptions, useSlurpEnter, useSlurpNavigate } from "./navigation.js";
6
+ export * from "@slurp-ui/motion";
7
+ export { AnimationGroup, type AnimationGroupProps, type AnimationProps, type ContentRef, type SlurpControls, type SlurpEnterOptions, type SlurpNavigate, type SlurpNavigateOptions, useAnimationTarget, useSlurp, useSlurpEnter, useSlurpNavigate };
@@ -0,0 +1,7 @@
1
+
2
+ import { AnimationGroup } from "./AnimationGroup.js";
3
+ import { useAnimationTarget } from "./useAnimationTarget.js";
4
+ import { useSlurp } from "./useSlurp.js";
5
+ import { useSlurpEnter, useSlurpNavigate } from "./navigation.js";
6
+ export * from "@slurp-ui/motion";
7
+ export { AnimationGroup, useAnimationTarget, useSlurp, useSlurpEnter, useSlurpNavigate };
@@ -0,0 +1,51 @@
1
+
2
+ import { SlurpAnimation, SlurpDefaults, SlurpRef } from "@slurp-ui/motion";
3
+ export interface SlurpNavigateOptions extends Partial<SlurpDefaults> {
4
+ /** What leaves: measured now, before the navigation unmounts it. */
5
+ from: SlurpRef | SlurpRef[];
6
+ /** Where it lands in the next route; when omitted, `useSlurpEnter(to)` there says it. */
7
+ to?: SlurpRef | SlurpRef[];
8
+ /** The element the action is about: it merges last (collapse) or comes out first (expand, where it is in the next route). */
9
+ lead?: SlurpRef;
10
+ }
11
+ type Go<A> = A extends [infer T, ...infer R] ? (to: T, options?: SlurpNavigateOptions | null, ...rest: R) => void : never;
12
+ /**
13
+ * The navigate function of a router with slurp options as second argument; its other arguments pass through.
14
+ * Overloads are kept (React Router's `navigate(to, options)` and `navigate(-1)`).
15
+ */
16
+ export type SlurpNavigate<F> = F extends {
17
+ (...args: infer A1): unknown;
18
+ (...args: infer A2): unknown;
19
+ } ? Go<A1> & Go<A2> : never;
20
+ /**
21
+ * Wraps a router's navigate function (`router.push`, React Router's `navigate`, `history.pushState`…):
22
+ * with slurp options it measures `from` first and leaves a handoff that the next route plays with
23
+ * `useSlurpEnter`. Without options it just navigates. No router is imported.
24
+ */
25
+ export declare function useSlurpNavigate<F extends (...args: never[]) => unknown>(navigate: F): SlurpNavigate<F>;
26
+ export interface SlurpEnterOptions {
27
+ /** A handoff older than this (ms) only fades in. Default 1000. */
28
+ maxAge?: number;
29
+ /** How long to wait for the targets to mount (ms). Default 800. */
30
+ timeout?: number;
31
+ /** Plays again when it changes: for a route component reused with other params (e.g. the pathname). */
32
+ key?: unknown;
33
+ /** Called with the transition when it starts (for example to follow it or reverse it). */
34
+ onStart?: (animation: SlurpAnimation) => void;
35
+ /**
36
+ * The rest of the route (title, text…): hidden before the first paint, it fades in while the droplets land
37
+ * (the last 40% of the transition). Leave out what holds the targets: an element containing one is skipped.
38
+ */
39
+ content?: ContentRef | ContentRef[];
40
+ }
41
+ export type ContentRef = HTMLElement | {
42
+ current: HTMLElement | null;
43
+ } | null | undefined;
44
+ /**
45
+ * In the route that mounts after `useSlurpNavigate`: waits for `to` (or the handoff's own target) to be
46
+ * mounted and plays the transition from the nodes measured before the navigation. A stale handoff or
47
+ * missing targets fade instead; without a handoff (a direct visit, the browser's back) nothing runs.
48
+ */
49
+ export declare function useSlurpEnter(to?: SlurpRef | SlurpRef[], options?: SlurpEnterOptions): void;
50
+ export {};
51
+ //# sourceMappingURL=navigation.d.ts.map
@@ -0,0 +1,122 @@
1
+ "use client";
2
+ import { useTheme } from "../internal/context.js";
3
+ import { useSlurp } from "./useSlurp.js";
4
+ import { useCallback, useEffectEvent, useLayoutEffect, useRef } from "react";
5
+ import { REDUCED_DURATION, registry } from "@slurp-ui/motion";
6
+ // src/motion/navigation.ts
7
+ /** Measures without keeping the element: the snapshot outlives the route that rendered it. */
8
+ function snapshot(node, lead) {
9
+ const copy = {
10
+ ...node,
11
+ lead: lead || node.lead
12
+ };
13
+ delete copy.el;
14
+ return copy;
15
+ }
16
+ /**
17
+ * Wraps a router's navigate function (`router.push`, React Router's `navigate`, `history.pushState`…):
18
+ * with slurp options it measures `from` first and leaves a handoff that the next route plays with
19
+ * `useSlurpEnter`. Without options it just navigates. No router is imported.
20
+ */
21
+ function useSlurpNavigate(navigate) {
22
+ return useCallback((to, options, ...rest) => {
23
+ if (options) {
24
+ const { from, to: target, lead, ...motion } = options;
25
+ const leads = new Set(lead ? registry.resolve(lead).map((n) => n.key) : []);
26
+ const nodes = registry.resolve(from).map((n) => snapshot(n, leads.has(n.key)));
27
+ const arriving = lead !== void 0 && !nodes.some((n) => n.lead);
28
+ if (nodes.length) registry.handoff.set({
29
+ kind: "run",
30
+ from: nodes,
31
+ ...target === void 0 ? null : { to: target },
32
+ options: arriving ? {
33
+ ...motion,
34
+ lead
35
+ } : motion
36
+ });
37
+ }
38
+ navigate(to, ...rest);
39
+ }, [navigate]);
40
+ }
41
+ /** Share of the transition before the content starts fading in. */
42
+ const CONTENT_DELAY = .6;
43
+ const prefersReduced = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
44
+ function contentOf(content) {
45
+ return (Array.isArray(content) ? content : [content]).flatMap((r) => {
46
+ const el = r && "current" in r ? r.current : r;
47
+ return el && typeof el.animate === "function" ? [el] : [];
48
+ });
49
+ }
50
+ /**
51
+ * In the route that mounts after `useSlurpNavigate`: waits for `to` (or the handoff's own target) to be
52
+ * mounted and plays the transition from the nodes measured before the navigation. A stale handoff or
53
+ * missing targets fade instead; without a handoff (a direct visit, the browser's back) nothing runs.
54
+ */
55
+ function useSlurpEnter(to, options = {}) {
56
+ const { run } = useSlurp();
57
+ const motion = useTheme().motion;
58
+ const { maxAge = 1e3, timeout, key, onStart, content } = options;
59
+ const taken = useRef(null);
60
+ const play = useEffectEvent((handoff, live) => {
61
+ const target = handoff.to ?? to;
62
+ if (!target) return () => {};
63
+ const stale = Date.now() - handoff.at > maxAge;
64
+ const o = {
65
+ ...motion,
66
+ ...handoff.options
67
+ };
68
+ const els = contentOf(content);
69
+ const fades = els.map((el) => el.animate([{ opacity: 0 }, { opacity: 0 }], { fill: "forwards" }));
70
+ let animation = null;
71
+ registry.whenMounted(target, timeout === void 0 ? {} : { timeout }).then((nodes) => {
72
+ if (!live()) return;
73
+ animation = run({
74
+ ...handoff.options,
75
+ ...stale ? { reducedMotion: "always" } : null,
76
+ from: handoff.from,
77
+ to: nodes
78
+ });
79
+ const reduced = stale || !nodes.length || o.reducedMotion === "always" || o.reducedMotion === "user" && prefersReduced();
80
+ const duration = reduced ? REDUCED_DURATION : o.duration;
81
+ els.forEach((el, i) => {
82
+ const fade = nodes.some((n) => n.el && el.contains(n.el)) ? null : el.animate([
83
+ { opacity: 0 },
84
+ {
85
+ opacity: 0,
86
+ offset: reduced ? 0 : CONTENT_DELAY,
87
+ easing: "ease-out"
88
+ },
89
+ { opacity: 1 }
90
+ ], {
91
+ duration,
92
+ fill: "both"
93
+ });
94
+ fades[i]?.cancel();
95
+ if (fade) fades[i] = fade;
96
+ });
97
+ animation.finished.then(() => fades.forEach((f) => f.cancel()));
98
+ onStart?.(animation);
99
+ });
100
+ return () => {
101
+ animation?.cancel();
102
+ fades.forEach((f) => f.cancel());
103
+ };
104
+ });
105
+ useLayoutEffect(() => {
106
+ if (!taken.current || taken.current.key !== key) taken.current = {
107
+ key,
108
+ handoff: registry.handoff.take(Number.POSITIVE_INFINITY)
109
+ };
110
+ const { handoff } = taken.current;
111
+ if (!handoff) return;
112
+ let live = true;
113
+ const stop = play(handoff, () => live);
114
+ return () => {
115
+ live = false;
116
+ stop();
117
+ };
118
+ }, [key]);
119
+ }
120
+ export { useSlurpEnter, useSlurpNavigate };
121
+
122
+ //# sourceMappingURL=navigation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigation.js","names":[],"sources":["../../src/motion/navigation.ts"],"sourcesContent":["import {\n REDUCED_DURATION,\n registry,\n type Handoff,\n type SlurpAnimation,\n type SlurpDefaults,\n type SlurpNode,\n type SlurpRef,\n} from '@slurp-ui/motion';\nimport { useCallback, useEffectEvent, useLayoutEffect, useRef } from 'react';\n\nimport { useTheme } from '../internal/context';\nimport { useSlurp } from './useSlurp';\n\nexport interface SlurpNavigateOptions extends Partial<SlurpDefaults> {\n /** What leaves: measured now, before the navigation unmounts it. */\n from: SlurpRef | SlurpRef[];\n /** Where it lands in the next route; when omitted, `useSlurpEnter(to)` there says it. */\n to?: SlurpRef | SlurpRef[];\n /** The element the action is about: it merges last (collapse) or comes out first (expand, where it is in the next route). */\n lead?: SlurpRef;\n}\n\ntype Go<A> = A extends [infer T, ...infer R]\n ? (to: T, options?: SlurpNavigateOptions | null, ...rest: R) => void\n : never;\n\n/**\n * The navigate function of a router with slurp options as second argument; its other arguments pass through.\n * Overloads are kept (React Router's `navigate(to, options)` and `navigate(-1)`).\n */\nexport type SlurpNavigate<F> = F extends {\n (...args: infer A1): unknown;\n (...args: infer A2): unknown;\n}\n ? Go<A1> & Go<A2>\n : never;\n\n/** Measures without keeping the element: the snapshot outlives the route that rendered it. */\nfunction snapshot(node: SlurpNode, lead: boolean): SlurpNode {\n const copy: SlurpNode = { ...node, lead: lead || node.lead };\n delete copy.el;\n return copy;\n}\n\n/**\n * Wraps a router's navigate function (`router.push`, React Router's `navigate`, `history.pushState`…):\n * with slurp options it measures `from` first and leaves a handoff that the next route plays with\n * `useSlurpEnter`. Without options it just navigates. No router is imported.\n */\nexport function useSlurpNavigate<F extends (...args: never[]) => unknown>(\n navigate: F,\n): SlurpNavigate<F> {\n return useCallback(\n (to: unknown, options?: SlurpNavigateOptions | null, ...rest: unknown[]) => {\n if (options) {\n const { from, to: target, lead, ...motion } = options;\n const leads = new Set(lead ? registry.resolve(lead).map((n) => n.key) : []);\n const nodes = registry.resolve(from).map((n) => snapshot(n, leads.has(n.key)));\n // A lead that is not leaving (expand: it arrives with the next route) is resolved there.\n const arriving = lead !== undefined && !nodes.some((n) => n.lead);\n if (nodes.length) {\n registry.handoff.set({\n kind: 'run',\n from: nodes,\n ...(target === undefined ? null : { to: target }),\n options: arriving ? { ...motion, lead } : motion,\n });\n }\n }\n (navigate as unknown as (...args: unknown[]) => unknown)(to, ...rest);\n },\n [navigate],\n ) as SlurpNavigate<F>;\n}\n\nexport interface SlurpEnterOptions {\n /** A handoff older than this (ms) only fades in. Default 1000. */\n maxAge?: number;\n /** How long to wait for the targets to mount (ms). Default 800. */\n timeout?: number;\n /** Plays again when it changes: for a route component reused with other params (e.g. the pathname). */\n key?: unknown;\n /** Called with the transition when it starts (for example to follow it or reverse it). */\n onStart?: (animation: SlurpAnimation) => void;\n /**\n * The rest of the route (title, text…): hidden before the first paint, it fades in while the droplets land\n * (the last 40% of the transition). Leave out what holds the targets: an element containing one is skipped.\n */\n content?: ContentRef | ContentRef[];\n}\n\nexport type ContentRef = HTMLElement | { current: HTMLElement | null } | null | undefined;\n\n/** Share of the transition before the content starts fading in. */\nconst CONTENT_DELAY = 0.6;\n\nconst prefersReduced = () =>\n typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n\nfunction contentOf(content: ContentRef | ContentRef[] | undefined): HTMLElement[] {\n const refs = Array.isArray(content) ? content : [content];\n return refs.flatMap((r) => {\n const el = r && 'current' in r ? r.current : r;\n return el && typeof el.animate === 'function' ? [el] : [];\n });\n}\n\n/**\n * In the route that mounts after `useSlurpNavigate`: waits for `to` (or the handoff's own target) to be\n * mounted and plays the transition from the nodes measured before the navigation. A stale handoff or\n * missing targets fade instead; without a handoff (a direct visit, the browser's back) nothing runs.\n */\nexport function useSlurpEnter(to?: SlurpRef | SlurpRef[], options: SlurpEnterOptions = {}): void {\n const { run } = useSlurp();\n const motion = useTheme().motion;\n const { maxAge = 1000, timeout, key, onStart, content } = options;\n // Taken once per key: StrictMode's second mount replays the same handoff instead of losing it.\n const taken = useRef<{ key: unknown; handoff: Handoff | null } | null>(null);\n\n const play = useEffectEvent((handoff: Handoff, live: () => boolean) => {\n const target = handoff.to ?? to;\n if (!target) return () => {};\n const stale = Date.now() - handoff.at > maxAge;\n const o = { ...motion, ...handoff.options };\n // Hidden now (before the first paint), until the transition starts and fades it in.\n const els = contentOf(content);\n const fades = els.map((el) =>\n el.animate([{ opacity: 0 }, { opacity: 0 }], { fill: 'forwards' }),\n );\n let animation: SlurpAnimation | null = null;\n void registry.whenMounted(target, timeout === undefined ? {} : { timeout }).then((nodes) => {\n if (!live()) return;\n animation = run({\n ...handoff.options,\n ...(stale ? { reducedMotion: 'always' } : null),\n from: handoff.from,\n to: nodes,\n });\n const reduced =\n stale ||\n !nodes.length ||\n o.reducedMotion === 'always' ||\n (o.reducedMotion === 'user' && prefersReduced());\n const duration = reduced ? REDUCED_DURATION : o.duration;\n els.forEach((el, i) => {\n // Content holding a target would hide it while the droplets land on it.\n const holds = nodes.some((n) => n.el && el.contains(n.el));\n const fade = holds\n ? null\n : el.animate(\n [\n { opacity: 0 },\n { opacity: 0, offset: reduced ? 0 : CONTENT_DELAY, easing: 'ease-out' },\n { opacity: 1 },\n ],\n { duration, fill: 'both' },\n );\n fades[i]?.cancel();\n if (fade) fades[i] = fade;\n });\n void animation.finished.then(() => fades.forEach((f) => f.cancel()));\n onStart?.(animation);\n });\n return () => {\n animation?.cancel();\n fades.forEach((f) => f.cancel());\n };\n });\n\n // Layout effect + whenMounted's microtask: the targets are hidden before the first paint.\n useLayoutEffect(() => {\n if (!taken.current || taken.current.key !== key) {\n taken.current = { key, handoff: registry.handoff.take(Number.POSITIVE_INFINITY) };\n }\n const { handoff } = taken.current;\n if (!handoff) return;\n let live = true;\n const stop = play(handoff, () => live);\n return () => {\n live = false;\n stop();\n };\n }, [key]);\n}\n"],"mappings":"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"}
@@ -0,0 +1,22 @@
1
+
2
+ import { RefCallback } from "react";
3
+ import { GhostKind } from "@slurp-ui/motion";
4
+ /** Accepted by every component: it only registers its root element. Transitions are started by useSlurp(). */
5
+ export interface AnimationProps {
6
+ /** Registers the element under this id (a `from` / `to` / `lead` of useSlurp). */
7
+ animationId?: string;
8
+ /** Joins a group (`{ group }` refs). Inside `<AnimationGroup>`, elements with an animationId join it by themselves. */
9
+ animationGroup?: string;
10
+ /** The element the action is about: it merges last in a collapse and comes out first in an expand. */
11
+ animationLead?: boolean;
12
+ /** Left out of the transition: it is neither hidden nor animated, it only fades. */
13
+ animationDisabled?: boolean;
14
+ /** Ghost override for this element. */
15
+ animationGhost?: GhostKind;
16
+ }
17
+ /**
18
+ * Ref that registers an element with the motion registry while it is mounted. Undefined when the element has neither
19
+ * an animationId nor an animationGroup: then nothing is registered and nothing is allocated.
20
+ */
21
+ export declare function useAnimationTarget<T extends HTMLElement = HTMLElement>({ animationId, animationGroup, animationLead, animationDisabled, animationGhost }?: AnimationProps): RefCallback<T> | undefined;
22
+ //# sourceMappingURL=useAnimationTarget.d.ts.map
@@ -0,0 +1,34 @@
1
+ "use client";
2
+ import { AnimationGroupContext } from "./context.js";
3
+ import { useContext, useId, useMemo } from "react";
4
+ import { registry } from "@slurp-ui/motion";
5
+ // src/motion/useAnimationTarget.ts
6
+ /**
7
+ * Ref that registers an element with the motion registry while it is mounted. Undefined when the element has neither
8
+ * an animationId nor an animationGroup: then nothing is registered and nothing is allocated.
9
+ */
10
+ function useAnimationTarget({ animationId, animationGroup, animationLead, animationDisabled, animationGhost } = {}) {
11
+ const inherited = useContext(AnimationGroupContext);
12
+ const auto = useId();
13
+ const id = animationId ?? (animationGroup ? `${animationGroup}:${auto}` : void 0);
14
+ const group = animationGroup ?? (animationId ? inherited ?? void 0 : void 0);
15
+ return useMemo(() => {
16
+ if (!id) return void 0;
17
+ const meta = {
18
+ group,
19
+ lead: animationLead,
20
+ disabled: animationDisabled,
21
+ ghost: animationGhost
22
+ };
23
+ return (el) => el ? registry.register(id, el, meta) : void 0;
24
+ }, [
25
+ id,
26
+ group,
27
+ animationLead,
28
+ animationDisabled,
29
+ animationGhost
30
+ ]);
31
+ }
32
+ export { useAnimationTarget };
33
+
34
+ //# sourceMappingURL=useAnimationTarget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAnimationTarget.js","names":[],"sources":["../../src/motion/useAnimationTarget.ts"],"sourcesContent":["import { registry, type GhostKind } from '@slurp-ui/motion';\nimport { useContext, useId, useMemo, type RefCallback } from 'react';\n\nimport { AnimationGroupContext } from './context';\n\n/** Accepted by every component: it only registers its root element. Transitions are started by useSlurp(). */\nexport interface AnimationProps {\n /** Registers the element under this id (a `from` / `to` / `lead` of useSlurp). */\n animationId?: string;\n /** Joins a group (`{ group }` refs). Inside `<AnimationGroup>`, elements with an animationId join it by themselves. */\n animationGroup?: string;\n /** The element the action is about: it merges last in a collapse and comes out first in an expand. */\n animationLead?: boolean;\n /** Left out of the transition: it is neither hidden nor animated, it only fades. */\n animationDisabled?: boolean;\n /** Ghost override for this element. */\n animationGhost?: GhostKind;\n}\n\n/**\n * Ref that registers an element with the motion registry while it is mounted. Undefined when the element has neither\n * an animationId nor an animationGroup: then nothing is registered and nothing is allocated.\n */\nexport function useAnimationTarget<T extends HTMLElement = HTMLElement>({\n animationId,\n animationGroup,\n animationLead,\n animationDisabled,\n animationGhost,\n}: AnimationProps = {}): RefCallback<T> | undefined {\n const inherited = useContext(AnimationGroupContext);\n const auto = useId();\n const id = animationId ?? (animationGroup ? `${animationGroup}:${auto}` : undefined);\n // An inherited group applies only to elements that opted in with an id (not to every Cell in the subtree).\n const group = animationGroup ?? (animationId ? (inherited ?? undefined) : undefined);\n return useMemo(() => {\n if (!id) return undefined;\n const meta = {\n group,\n lead: animationLead,\n disabled: animationDisabled,\n ghost: animationGhost,\n };\n return (el: T | null) => (el ? registry.register(id, el, meta) : undefined);\n }, [id, group, animationLead, animationDisabled, animationGhost]);\n}\n"],"mappings":";;;;;;;;;AAuBA,SAAgB,mBAAwD,EACtE,aACA,gBACA,eACA,mBACA,mBACkB,CAAC,GAA+B;CAClD,MAAM,YAAY,WAAW,qBAAqB;CAClD,MAAM,OAAO,MAAM;CACnB,MAAM,KAAK,gBAAgB,iBAAiB,GAAG,eAAe,GAAG,SAAS,KAAA;CAE1E,MAAM,QAAQ,mBAAmB,cAAe,aAAa,KAAA,IAAa,KAAA;CAC1E,OAAO,cAAc;EACnB,IAAI,CAAC,IAAI,OAAO,KAAA;EAChB,MAAM,OAAO;GACX;GACA,MAAM;GACN,UAAU;GACV,OAAO;EACT;EACA,QAAQ,OAAkB,KAAK,SAAS,SAAS,IAAI,IAAI,IAAI,IAAI,KAAA;CACnE,GAAG;EAAC;EAAI;EAAO;EAAe;EAAmB;CAAc,CAAC;AAClE"}
@@ -0,0 +1,18 @@
1
+
2
+ import { CollapseOptions, ExpandOptions, SlurpAnimation, SlurpOptions } from "@slurp-ui/motion";
3
+ export interface SlurpControls {
4
+ /** Generic: from → to (n → 1 collapses, 1 → n expands, 1 → 1 morphs). */
5
+ run(options: SlurpOptions): SlurpAnimation;
6
+ /** n → 1, to go forward: the items collapse into the target. */
7
+ collapse(options: CollapseOptions): SlurpAnimation;
8
+ /** 1 → n, to go back: the source bursts into the items. */
9
+ expand(options: ExpandOptions): SlurpAnimation;
10
+ /** 1 → 1. */
11
+ morph(options: SlurpOptions): SlurpAnimation;
12
+ }
13
+ /**
14
+ * Starts collapse / expand transitions with the theme's motion defaults (`createTheme({ motion })`).
15
+ * Transitions still running when the component unmounts are cancelled.
16
+ */
17
+ export declare function useSlurp(): SlurpControls;
18
+ //# sourceMappingURL=useSlurp.d.ts.map
@@ -0,0 +1,48 @@
1
+ "use client";
2
+ import { useTheme } from "../internal/context.js";
3
+ import { useEffect, useMemo, useRef } from "react";
4
+ import { collapse, expand, morph, slurp } from "@slurp-ui/motion";
5
+ // src/motion/useSlurp.ts
6
+ /**
7
+ * Starts collapse / expand transitions with the theme's motion defaults (`createTheme({ motion })`).
8
+ * Transitions still running when the component unmounts are cancelled.
9
+ */
10
+ function useSlurp() {
11
+ const motion = useTheme().motion;
12
+ const running = useRef(/* @__PURE__ */ new Set());
13
+ useEffect(() => {
14
+ const set = running.current;
15
+ return () => {
16
+ for (const a of set) a.cancel();
17
+ set.clear();
18
+ };
19
+ }, []);
20
+ return useMemo(() => {
21
+ const track = (a) => {
22
+ running.current.add(a);
23
+ a.finished.then(() => running.current.delete(a));
24
+ return a;
25
+ };
26
+ return {
27
+ run: (o) => track(slurp({
28
+ ...motion,
29
+ ...o
30
+ })),
31
+ collapse: (o) => track(collapse({
32
+ ...motion,
33
+ ...o
34
+ })),
35
+ expand: (o) => track(expand({
36
+ ...motion,
37
+ ...o
38
+ })),
39
+ morph: (o) => track(morph({
40
+ ...motion,
41
+ ...o
42
+ }))
43
+ };
44
+ }, [motion]);
45
+ }
46
+ export { useSlurp };
47
+
48
+ //# sourceMappingURL=useSlurp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSlurp.js","names":[],"sources":["../../src/motion/useSlurp.ts"],"sourcesContent":["import {\n collapse,\n expand,\n morph,\n slurp,\n type CollapseOptions,\n type ExpandOptions,\n type SlurpAnimation,\n type SlurpOptions,\n} from '@slurp-ui/motion';\nimport { useEffect, useMemo, useRef } from 'react';\n\nimport { useTheme } from '../internal/context';\n\nexport interface SlurpControls {\n /** Generic: from → to (n → 1 collapses, 1 → n expands, 1 → 1 morphs). */\n run(options: SlurpOptions): SlurpAnimation;\n /** n → 1, to go forward: the items collapse into the target. */\n collapse(options: CollapseOptions): SlurpAnimation;\n /** 1 → n, to go back: the source bursts into the items. */\n expand(options: ExpandOptions): SlurpAnimation;\n /** 1 → 1. */\n morph(options: SlurpOptions): SlurpAnimation;\n}\n\n/**\n * Starts collapse / expand transitions with the theme's motion defaults (`createTheme({ motion })`).\n * Transitions still running when the component unmounts are cancelled.\n */\nexport function useSlurp(): SlurpControls {\n const motion = useTheme().motion;\n const running = useRef(new Set<SlurpAnimation>());\n\n useEffect(() => {\n const set = running.current;\n return () => {\n for (const a of set) a.cancel();\n set.clear();\n };\n }, []);\n\n return useMemo(() => {\n const track = (a: SlurpAnimation) => {\n running.current.add(a);\n void a.finished.then(() => running.current.delete(a));\n return a;\n };\n return {\n run: (o) => track(slurp({ ...motion, ...o })),\n collapse: (o) => track(collapse({ ...motion, ...o })),\n expand: (o) => track(expand({ ...motion, ...o })),\n morph: (o) => track(morph({ ...motion, ...o })),\n };\n }, [motion]);\n}\n"],"mappings":";;;;;;;;;AA6BA,SAAgB,WAA0B;CACxC,MAAM,SAAS,SAAS,CAAC,CAAC;CAC1B,MAAM,UAAU,uBAAO,IAAI,IAAoB,CAAC;CAEhD,gBAAgB;EACd,MAAM,MAAM,QAAQ;EACpB,aAAa;GACX,KAAK,MAAM,KAAK,KAAK,EAAE,OAAO;GAC9B,IAAI,MAAM;EACZ;CACF,GAAG,CAAC,CAAC;CAEL,OAAO,cAAc;EACnB,MAAM,SAAS,MAAsB;GACnC,QAAQ,QAAQ,IAAI,CAAC;GACrB,EAAO,SAAS,WAAW,QAAQ,QAAQ,OAAO,CAAC,CAAC;GACpD,OAAO;EACT;EACA,OAAO;GACL,MAAM,MAAM,MAAM,MAAM;IAAE,GAAG;IAAQ,GAAG;GAAE,CAAC,CAAC;GAC5C,WAAW,MAAM,MAAM,SAAS;IAAE,GAAG;IAAQ,GAAG;GAAE,CAAC,CAAC;GACpD,SAAS,MAAM,MAAM,OAAO;IAAE,GAAG;IAAQ,GAAG;GAAE,CAAC,CAAC;GAChD,QAAQ,MAAM,MAAM,MAAM;IAAE,GAAG;IAAQ,GAAG;GAAE,CAAC,CAAC;EAChD;CACF,GAAG,CAAC,MAAM,CAAC;AACb"}