@kumix/ui 0.4.3 → 0.5.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 (296) hide show
  1. package/README.md +15 -13
  2. package/dist/components/agents/agent-activity/index.js +1 -1
  3. package/dist/components/agents/approval-card/index.js +2 -3
  4. package/dist/components/agents/approval-card/index.js.map +1 -1
  5. package/dist/components/agents/prompt-input.js +1 -2
  6. package/dist/components/agents/prompt-input.js.map +1 -1
  7. package/dist/components/agents/todo-list.js +1 -1
  8. package/dist/components/agents/tool-result.js +1 -1
  9. package/dist/components/charts/bar-chart/context.d.ts +114 -0
  10. package/dist/components/charts/bar-chart/context.d.ts.map +1 -0
  11. package/dist/components/charts/bar-chart/context.js +60 -0
  12. package/dist/components/charts/bar-chart/context.js.map +1 -0
  13. package/dist/components/charts/bar-chart/legend.d.ts +6 -0
  14. package/dist/components/charts/bar-chart/legend.d.ts.map +1 -0
  15. package/dist/components/charts/bar-chart/legend.js +21 -0
  16. package/dist/components/charts/bar-chart/legend.js.map +1 -0
  17. package/dist/components/charts/bar-chart/plot.d.ts +10 -0
  18. package/dist/components/charts/bar-chart/plot.d.ts.map +1 -0
  19. package/dist/components/charts/bar-chart/plot.js +290 -0
  20. package/dist/components/charts/bar-chart/plot.js.map +1 -0
  21. package/dist/components/charts/bar-chart/tooltip.d.ts +20 -0
  22. package/dist/components/charts/bar-chart/tooltip.d.ts.map +1 -0
  23. package/dist/components/charts/bar-chart/tooltip.js +57 -0
  24. package/dist/components/charts/bar-chart/tooltip.js.map +1 -0
  25. package/dist/components/charts/bar-chart.d.ts +9 -0
  26. package/dist/components/charts/bar-chart.d.ts.map +1 -0
  27. package/dist/components/charts/bar-chart.js +51 -0
  28. package/dist/components/charts/bar-chart.js.map +1 -0
  29. package/dist/components/charts/bump-chart/plot.js +1 -1
  30. package/dist/components/charts/bump-chart/point.js +1 -1
  31. package/dist/components/charts/bump-chart.js +1 -1
  32. package/dist/components/charts/composition-chart/plot.js +5 -1
  33. package/dist/components/charts/composition-chart/plot.js.map +1 -1
  34. package/dist/components/charts/composition-chart/tooltip-content.js +1 -1
  35. package/dist/components/charts/donut-chart.d.ts +1 -1
  36. package/dist/components/charts/donut-chart.js +1 -1
  37. package/dist/components/charts/funnel-chart.js +1 -1
  38. package/dist/components/charts/heat-calendar/tooltip.js +1 -1
  39. package/dist/components/charts/line-chart/context.d.ts +154 -0
  40. package/dist/components/charts/line-chart/context.d.ts.map +1 -0
  41. package/dist/components/charts/line-chart/context.js +67 -0
  42. package/dist/components/charts/line-chart/context.js.map +1 -0
  43. package/dist/components/charts/line-chart/legend.d.ts +6 -0
  44. package/dist/components/charts/line-chart/legend.d.ts.map +1 -0
  45. package/dist/components/charts/line-chart/legend.js +21 -0
  46. package/dist/components/charts/line-chart/legend.js.map +1 -0
  47. package/dist/components/charts/line-chart/plot.d.ts +12 -0
  48. package/dist/components/charts/line-chart/plot.d.ts.map +1 -0
  49. package/dist/components/charts/line-chart/plot.js +604 -0
  50. package/dist/components/charts/line-chart/plot.js.map +1 -0
  51. package/dist/components/charts/line-chart/tooltip.d.ts +22 -0
  52. package/dist/components/charts/line-chart/tooltip.d.ts.map +1 -0
  53. package/dist/components/charts/line-chart/tooltip.js +108 -0
  54. package/dist/components/charts/line-chart/tooltip.js.map +1 -0
  55. package/dist/components/charts/line-chart.d.ts +10 -0
  56. package/dist/components/charts/line-chart.d.ts.map +1 -0
  57. package/dist/components/charts/line-chart.js +53 -0
  58. package/dist/components/charts/line-chart.js.map +1 -0
  59. package/dist/components/charts/liquidity-heatmap.js +1 -1
  60. package/dist/components/charts/price-target-fan.js +1 -1
  61. package/dist/components/charts/returns-calendar/tooltip.js +1 -1
  62. package/dist/components/charts/returns-calendar.d.ts.map +1 -1
  63. package/dist/components/charts/sankey-chart/context.d.ts +2 -0
  64. package/dist/components/charts/sankey-chart/context.js +2 -0
  65. package/dist/components/charts/sankey-chart/plot.d.ts +8 -0
  66. package/dist/components/charts/sankey-chart/plot.d.ts.map +1 -0
  67. package/dist/components/charts/sankey-chart/plot.js +342 -0
  68. package/dist/components/charts/sankey-chart/plot.js.map +1 -0
  69. package/dist/components/charts/sankey-chart/tooltip.d.ts +10 -0
  70. package/dist/components/charts/sankey-chart/tooltip.d.ts.map +1 -0
  71. package/dist/components/charts/sankey-chart/tooltip.js +147 -0
  72. package/dist/components/charts/sankey-chart/tooltip.js.map +1 -0
  73. package/dist/components/charts/sankey-chart.d.ts +17 -0
  74. package/dist/components/charts/sankey-chart.d.ts.map +1 -0
  75. package/dist/components/charts/sankey-chart.js +76 -0
  76. package/dist/components/charts/sankey-chart.js.map +1 -0
  77. package/dist/components/charts/sparkline.d.ts +26 -0
  78. package/dist/components/charts/sparkline.d.ts.map +1 -0
  79. package/dist/components/charts/sparkline.js +197 -0
  80. package/dist/components/charts/sparkline.js.map +1 -0
  81. package/dist/components/charts/treemap/tooltip.js +1 -1
  82. package/dist/components/charts/treemap.d.ts.map +1 -1
  83. package/dist/components/charts/volume-profile/tooltip.js +1 -1
  84. package/dist/components/charts/xy/axis.d.ts +24 -0
  85. package/dist/components/charts/xy/axis.d.ts.map +1 -0
  86. package/dist/components/charts/xy/axis.js +90 -0
  87. package/dist/components/charts/xy/axis.js.map +1 -0
  88. package/dist/components/charts/xy/data-table.d.ts +9 -0
  89. package/dist/components/charts/xy/data-table.d.ts.map +1 -0
  90. package/dist/components/charts/xy/data-table.js +29 -0
  91. package/dist/components/charts/xy/data-table.js.map +1 -0
  92. package/dist/components/charts/xy/inspector.d.ts +27 -0
  93. package/dist/components/charts/xy/inspector.d.ts.map +1 -0
  94. package/dist/components/charts/xy/inspector.js +110 -0
  95. package/dist/components/charts/xy/inspector.js.map +1 -0
  96. package/dist/components/charts/xy/legend.d.ts +13 -0
  97. package/dist/components/charts/xy/legend.d.ts.map +1 -0
  98. package/dist/components/charts/xy/legend.js +42 -0
  99. package/dist/components/charts/xy/legend.js.map +1 -0
  100. package/dist/components/charts/xy/tooltip-content.d.ts +2 -0
  101. package/dist/components/charts/xy/tooltip-content.js +66 -0
  102. package/dist/components/charts/xy/tooltip-content.js.map +1 -0
  103. package/dist/components/motion/attachment-upload.js +1 -1
  104. package/dist/components/motion/availability-scheduler/copy-menu.js +1 -1
  105. package/dist/components/motion/availability-scheduler/day-row.js +2 -2
  106. package/dist/components/motion/availability-scheduler/index.js +1 -1
  107. package/dist/components/motion/avatar-group.d.ts +48 -0
  108. package/dist/components/motion/avatar-group.d.ts.map +1 -0
  109. package/dist/components/motion/avatar-group.js +196 -0
  110. package/dist/components/motion/avatar-group.js.map +1 -0
  111. package/dist/components/motion/bottom-sheet.js +1 -1
  112. package/dist/components/motion/bouncy-accordion.d.ts.map +1 -1
  113. package/dist/components/motion/bouncy-accordion.js +20 -34
  114. package/dist/components/motion/bouncy-accordion.js.map +1 -1
  115. package/dist/components/motion/breadcrumb.js +0 -3
  116. package/dist/components/motion/breadcrumb.js.map +1 -1
  117. package/dist/components/motion/button/magnetic.js +1 -1
  118. package/dist/components/motion/card-dealer.d.ts +36 -0
  119. package/dist/components/motion/card-dealer.d.ts.map +1 -0
  120. package/dist/components/motion/card-dealer.js +232 -0
  121. package/dist/components/motion/card-dealer.js.map +1 -0
  122. package/dist/components/motion/color-picker.js +1 -1
  123. package/dist/components/motion/combobox.js +1 -1
  124. package/dist/components/motion/context-menu.js +1 -1
  125. package/dist/components/motion/crash/crash-balloon.d.ts +9 -0
  126. package/dist/components/motion/crash/crash-balloon.d.ts.map +1 -0
  127. package/dist/components/motion/crash/crash-balloon.js +829 -0
  128. package/dist/components/motion/crash/crash-balloon.js.map +1 -0
  129. package/dist/components/motion/crash/crash-parts.d.ts +59 -0
  130. package/dist/components/motion/crash/crash-parts.d.ts.map +1 -0
  131. package/dist/components/motion/crash/crash-parts.js +2 -0
  132. package/dist/components/motion/crash/crash-tower.d.ts +9 -0
  133. package/dist/components/motion/crash/crash-tower.d.ts.map +1 -0
  134. package/dist/components/motion/crash/crash-tower.js +370 -0
  135. package/dist/components/motion/crash/crash-tower.js.map +1 -0
  136. package/dist/components/motion/crash.d.ts +9 -0
  137. package/dist/components/motion/crash.d.ts.map +1 -0
  138. package/dist/components/motion/crash.js +590 -0
  139. package/dist/components/motion/crash.js.map +1 -0
  140. package/dist/components/motion/date-range-picker.js +1 -1
  141. package/dist/components/motion/feedback-widget.js +0 -1
  142. package/dist/components/motion/feedback-widget.js.map +1 -1
  143. package/dist/components/motion/hold-action-button.js +1 -1
  144. package/dist/components/motion/liquid.js +2 -2
  145. package/dist/components/motion/liquid.js.map +1 -1
  146. package/dist/components/motion/loader.js +5 -4
  147. package/dist/components/motion/loader.js.map +1 -1
  148. package/dist/components/motion/mines.d.ts +41 -0
  149. package/dist/components/motion/mines.d.ts.map +1 -0
  150. package/dist/components/motion/mines.js +762 -0
  151. package/dist/components/motion/mines.js.map +1 -0
  152. package/dist/components/motion/morphing-modal.js +6 -4
  153. package/dist/components/motion/morphing-modal.js.map +1 -1
  154. package/dist/components/motion/morphing-tabs.js +1 -1
  155. package/dist/components/motion/multi-select/index.js +1 -1
  156. package/dist/components/motion/pagination.d.ts +31 -0
  157. package/dist/components/motion/pagination.d.ts.map +1 -0
  158. package/dist/components/motion/pagination.js +193 -0
  159. package/dist/components/motion/pagination.js.map +1 -0
  160. package/dist/components/motion/plinko.d.ts +59 -0
  161. package/dist/components/motion/plinko.d.ts.map +1 -0
  162. package/dist/components/motion/plinko.js +385 -0
  163. package/dist/components/motion/plinko.js.map +1 -0
  164. package/dist/components/motion/popover-morph.d.ts +11 -2
  165. package/dist/components/motion/popover-morph.d.ts.map +1 -1
  166. package/dist/components/motion/popover-morph.js +98 -4
  167. package/dist/components/motion/popover-morph.js.map +1 -1
  168. package/dist/components/motion/pull-to-refresh.js +1 -1
  169. package/dist/components/motion/range-slider-bubble.js +1 -1
  170. package/dist/components/motion/range-slider-fluid.js +1 -1
  171. package/dist/components/motion/range-slider-inline.js +1 -1
  172. package/dist/components/motion/range-slider-ruler.js +1 -1
  173. package/dist/components/motion/range-slider-wave.js +1 -1
  174. package/dist/components/motion/range-slider.js +1 -1
  175. package/dist/components/motion/signup-form.js +0 -1
  176. package/dist/components/motion/signup-form.js.map +1 -1
  177. package/dist/components/motion/slide-action-button.js +1 -1
  178. package/dist/components/motion/swap/field.js +1 -1
  179. package/dist/components/motion/swap/token-picker.js +1 -1
  180. package/dist/components/motion/swap.d.ts +1 -1
  181. package/dist/components/motion/swap.js +2 -2
  182. package/dist/components/motion/table/index.js +2 -2
  183. package/dist/components/motion/table/table-header.js +1 -1
  184. package/dist/components/motion/tooltip.d.ts +2 -2
  185. package/dist/components/motion/tooltip.d.ts.map +1 -1
  186. package/dist/components/motion/wallet-card/index.js +1 -2
  187. package/dist/components/motion/wallet-card/index.js.map +1 -1
  188. package/dist/components/motion/wheel-picker.js +1 -1
  189. package/dist/components/reui/badge.d.ts +1 -1
  190. package/dist/components/reui/cascader/cascader-columns.js +1 -1
  191. package/dist/components/reui/cascader/cascader-footer.js +1 -1
  192. package/dist/components/reui/cascader/cascader-nav.js +1 -1
  193. package/dist/components/reui/cascader/cascader-virtual.js +1 -1
  194. package/dist/components/reui/cascader/cascader.d.ts +1 -1
  195. package/dist/components/reui/cascader/cascader.js +2 -2
  196. package/dist/components/reui/code-block/code-block.d.ts +2 -1
  197. package/dist/components/reui/code-block/code-block.d.ts.map +1 -1
  198. package/dist/components/reui/data-grid/data-grid-column-filter.js +1 -1
  199. package/dist/components/reui/data-grid/data-grid-pagination.js +1 -1
  200. package/dist/components/reui/data-grid/data-grid-table.d.ts +1 -1
  201. package/dist/components/reui/data-grid/data-grid-table.d.ts.map +1 -1
  202. package/dist/components/reui/data-grid/data-grid-table.js +1 -1
  203. package/dist/components/reui/date-selector.js +2 -2
  204. package/dist/components/reui/emoji-picker.js +2 -2
  205. package/dist/components/reui/event-calendar/event-calendar-agenda-view.js +1 -1
  206. package/dist/components/reui/event-calendar/event-calendar-content.js +1 -1
  207. package/dist/components/reui/event-calendar/event-calendar-dnd.js +1 -1
  208. package/dist/components/reui/event-calendar/event-calendar-event.js +1 -1
  209. package/dist/components/reui/event-calendar/event-calendar-month-view.js +2 -2
  210. package/dist/components/reui/event-calendar/event-calendar-nav.js +2 -2
  211. package/dist/components/reui/event-calendar/event-calendar-resource-view.js +1 -1
  212. package/dist/components/reui/event-calendar/event-calendar-time-grid.js +1 -1
  213. package/dist/components/reui/event-calendar/event-calendar.d.ts +1 -1
  214. package/dist/components/reui/filters/filters-advanced.js +4 -4
  215. package/dist/components/reui/filters/filters-builder.js +1 -1
  216. package/dist/components/reui/filters/filters-chip.js +2 -2
  217. package/dist/components/reui/filters/filters-context.d.ts +1 -1
  218. package/dist/components/reui/filters/filters-editors.js +3 -3
  219. package/dist/components/reui/filters/filters.d.ts +3 -3
  220. package/dist/components/reui/filters/filters.js +6 -6
  221. package/dist/components/reui/gantt/gantt-bar.js +1 -1
  222. package/dist/components/reui/gantt/gantt-dnd.js +1 -1
  223. package/dist/components/reui/gantt/gantt-nav.js +2 -2
  224. package/dist/components/reui/gantt/gantt-view.js +3 -3
  225. package/dist/components/reui/gantt/gantt.d.ts +1 -1
  226. package/dist/components/reui/icon-tile.d.ts +1 -1
  227. package/dist/components/reui/phone-input.js +2 -2
  228. package/dist/components/reui/tree.d.ts +1 -0
  229. package/dist/components/reui/tree.d.ts.map +1 -1
  230. package/dist/components/ui/attachment.d.ts +1 -1
  231. package/dist/components/ui/badge.d.ts +1 -1
  232. package/dist/components/ui/bubble.d.ts +1 -1
  233. package/dist/components/ui/button-group.d.ts +1 -1
  234. package/dist/components/ui/button.d.ts +2 -2
  235. package/dist/components/ui/command.js +1 -1
  236. package/dist/components/ui/field.d.ts +1 -1
  237. package/dist/components/ui/field.js +1 -1
  238. package/dist/components/ui/item.d.ts +1 -1
  239. package/dist/components/ui/marker.d.ts +1 -1
  240. package/dist/components/ui/sidebar.d.ts +1 -1
  241. package/dist/components/ui/sidebar.js +1 -1
  242. package/dist/components/ui/tabs.d.ts +1 -1
  243. package/dist/context-CQbvWVnM.js +393 -0
  244. package/dist/context-CQbvWVnM.js.map +1 -0
  245. package/dist/context-tv-kneJV.d.ts +204 -0
  246. package/dist/context-tv-kneJV.d.ts.map +1 -0
  247. package/dist/{copy-menu-CKW3jM1J.js → copy-menu-LU54Aruj.js} +2 -2
  248. package/dist/{copy-menu-CKW3jM1J.js.map → copy-menu-LU54Aruj.js.map} +1 -1
  249. package/dist/crash-parts-CUv5gFYQ.js +1053 -0
  250. package/dist/crash-parts-CUv5gFYQ.js.map +1 -0
  251. package/dist/{ease-CHhXKlG3.d.ts → ease-DjhlGGZO.d.ts} +4 -2
  252. package/dist/ease-DjhlGGZO.d.ts.map +1 -0
  253. package/dist/hooks/use-highlighted-code.d.ts +1 -1
  254. package/dist/hooks/use-highlighted-code.d.ts.map +1 -1
  255. package/dist/hooks/use-modal-scope.js +2 -2
  256. package/dist/hooks/use-modal-scope.js.map +1 -1
  257. package/dist/lib/audio-context.d.ts +11 -0
  258. package/dist/lib/audio-context.d.ts.map +1 -0
  259. package/dist/lib/audio-context.js +37 -0
  260. package/dist/lib/audio-context.js.map +1 -0
  261. package/dist/lib/ease.d.ts +2 -2
  262. package/dist/lib/ease.js +8 -1
  263. package/dist/lib/ease.js.map +1 -1
  264. package/dist/lib/focusable.d.ts +2 -0
  265. package/dist/lib/focusable.d.ts.map +1 -0
  266. package/dist/lib/focusable.js +12 -0
  267. package/dist/lib/focusable.js.map +1 -0
  268. package/dist/lib/game-sounds.d.ts +18 -0
  269. package/dist/lib/game-sounds.d.ts.map +1 -0
  270. package/dist/lib/game-sounds.js +142 -0
  271. package/dist/lib/game-sounds.js.map +1 -0
  272. package/dist/lib/tick-sound.d.ts +4 -3
  273. package/dist/lib/tick-sound.d.ts.map +1 -1
  274. package/dist/lib/tick-sound.js +30 -37
  275. package/dist/lib/tick-sound.js.map +1 -1
  276. package/dist/model-CvWolJdo.d.ts +14 -0
  277. package/dist/model-CvWolJdo.d.ts.map +1 -0
  278. package/dist/path-VEfFUowr.d.ts +3 -0
  279. package/dist/path-VEfFUowr.d.ts.map +1 -0
  280. package/dist/{plot-DAKl-Lu1.js → plot-CTQFrQKi.js} +2 -2
  281. package/dist/{plot-DAKl-Lu1.js.map → plot-CTQFrQKi.js.map} +1 -1
  282. package/dist/scale-DSsaupNc.d.ts +7 -0
  283. package/dist/scale-DSsaupNc.d.ts.map +1 -0
  284. package/dist/tooltip-CNEYdIX3.d.ts.map +1 -1
  285. package/dist/tooltip-content-K0vPsEtI.d.ts +17 -0
  286. package/dist/tooltip-content-K0vPsEtI.d.ts.map +1 -0
  287. package/dist/use-crash-game-B3RHxFkm.d.ts +108 -0
  288. package/dist/use-crash-game-B3RHxFkm.d.ts.map +1 -0
  289. package/dist/use-inspection-CZhdpH8J.js +127 -0
  290. package/dist/use-inspection-CZhdpH8J.js.map +1 -0
  291. package/dist/use-points-C2jpElHh.js +118 -0
  292. package/dist/use-points-C2jpElHh.js.map +1 -0
  293. package/dist/use-width-CkKCh1b3.js +23 -0
  294. package/dist/use-width-CkKCh1b3.js.map +1 -0
  295. package/package.json +7 -7
  296. package/dist/ease-CHhXKlG3.d.ts.map +0 -1
@@ -0,0 +1,393 @@
1
+ import { useHoverCapable } from "./hooks/use-hover-capable.js";
2
+ import { useRowCursor } from "./hooks/use-row-cursor.js";
3
+ import { createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
4
+ import { useReducedMotion } from "motion/react";
5
+ // src/components/charts/sankey-chart/model.ts
6
+ const SANKEY_COLORS = [
7
+ "#1d4ed8",
8
+ "#7c3aed",
9
+ "#0f766e",
10
+ "#b45309",
11
+ "#be123c",
12
+ "#475569"
13
+ ];
14
+ /** Relaxation passes; more settles crossings further at a small cost. */
15
+ const ITERATIONS = 6;
16
+ const linkId = (link) => link.id ?? `${link.source}:${link.target}`;
17
+ /**
18
+ * Cleans consumer data once per change, not per resize:
19
+ * - repeated node ids keep the first node;
20
+ * - links to unknown nodes, self links and non-positive or non-finite values
21
+ * are dropped;
22
+ * - unnamed links between the same pair are summed into one band, while a
23
+ * repeated explicit id keeps the first link;
24
+ * - a link closing a cycle is dropped: one whose target is still on the
25
+ * depth-first path that reached its source, so the first-listed direction
26
+ * of a loop survives.
27
+ */
28
+ function cleanSankey(nodes, links) {
29
+ const byId = /* @__PURE__ */ new Map();
30
+ for (const node of nodes) if (!byId.has(node.id)) byId.set(node.id, node);
31
+ const unique = [...byId.values()];
32
+ const invalid = [];
33
+ const merged = /* @__PURE__ */ new Map();
34
+ for (const link of links) {
35
+ if (!(byId.has(link.source) && byId.has(link.target) && link.source !== link.target && Number.isFinite(link.value) && link.value > 0)) {
36
+ invalid.push(link);
37
+ continue;
38
+ }
39
+ const id = linkId(link);
40
+ const existing = merged.get(id);
41
+ if (!existing) merged.set(id, {
42
+ ...link,
43
+ id
44
+ });
45
+ else if (link.id === void 0 && existing.source === link.source && existing.target === link.target) existing.value += link.value;
46
+ else invalid.push(link);
47
+ }
48
+ const valid = [...merged.values()];
49
+ const outgoing = /* @__PURE__ */ new Map();
50
+ for (const link of valid) outgoing.set(link.source, [...outgoing.get(link.source) ?? [], link]);
51
+ const state = /* @__PURE__ */ new Map();
52
+ const back = /* @__PURE__ */ new Set();
53
+ for (const root of unique) {
54
+ if (state.has(root.id)) continue;
55
+ const stack = [{
56
+ id: root.id,
57
+ next: 0
58
+ }];
59
+ state.set(root.id, "open");
60
+ while (stack.length) {
61
+ const frame = stack[stack.length - 1];
62
+ const edges = outgoing.get(frame.id) ?? [];
63
+ if (frame.next >= edges.length) {
64
+ state.set(frame.id, "done");
65
+ stack.pop();
66
+ continue;
67
+ }
68
+ const link = edges[frame.next++];
69
+ const seen = state.get(link.target);
70
+ if (seen === "open") back.add(link);
71
+ else if (seen === void 0) {
72
+ state.set(link.target, "open");
73
+ stack.push({
74
+ id: link.target,
75
+ next: 0
76
+ });
77
+ }
78
+ }
79
+ }
80
+ return {
81
+ nodes: unique,
82
+ links: valid.filter((link) => !back.has(link)),
83
+ dropped: {
84
+ invalid,
85
+ cycle: valid.filter((link) => back.has(link))
86
+ }
87
+ };
88
+ }
89
+ /**
90
+ * Lays nodes out in columns by their longest path from a source, with sinks
91
+ * pushed to the last column, then sizes them to their value and relaxes each
92
+ * column toward its neighbours to shorten the links. Each column keeps the
93
+ * order the nodes were given in, so order them to avoid crossings.
94
+ */
95
+ function layoutSankey({ nodes, links: kept }, { width, height, nodeWidth, nodePadding, colors }) {
96
+ const inValue = /* @__PURE__ */ new Map();
97
+ const outValue = /* @__PURE__ */ new Map();
98
+ for (const link of kept) {
99
+ outValue.set(link.source, (outValue.get(link.source) ?? 0) + link.value);
100
+ inValue.set(link.target, (inValue.get(link.target) ?? 0) + link.value);
101
+ }
102
+ const indegree = /* @__PURE__ */ new Map();
103
+ for (const link of kept) indegree.set(link.target, (indegree.get(link.target) ?? 0) + 1);
104
+ const depth = /* @__PURE__ */ new Map();
105
+ const queue = nodes.filter((node) => !indegree.get(node.id)).map((node) => node.id);
106
+ for (const id of queue) depth.set(id, 0);
107
+ for (let i = 0; i < queue.length; i++) {
108
+ const id = queue[i];
109
+ for (const link of kept) {
110
+ if (link.source !== id) continue;
111
+ depth.set(link.target, Math.max(depth.get(link.target) ?? 0, (depth.get(id) ?? 0) + 1));
112
+ const left = (indegree.get(link.target) ?? 0) - 1;
113
+ indegree.set(link.target, left);
114
+ if (left === 0) queue.push(link.target);
115
+ }
116
+ }
117
+ const linked = nodes.filter((node) => inValue.has(node.id) || outValue.has(node.id));
118
+ if (!linked.length || width <= 0 || height <= 0) return {
119
+ nodes: [],
120
+ links: [],
121
+ columns: 0,
122
+ step: 0
123
+ };
124
+ const maxDepth = Math.max(0, ...linked.map((node) => depth.get(node.id) ?? 0));
125
+ const columns = maxDepth + 1;
126
+ const step = columns > 1 ? (width - nodeWidth) / (columns - 1) : 0;
127
+ const placed = linked.map((node) => {
128
+ const index = nodes.indexOf(node);
129
+ const value = Math.max(inValue.get(node.id) ?? 0, outValue.get(node.id) ?? 0);
130
+ const d = outValue.has(node.id) ? depth.get(node.id) ?? 0 : maxDepth;
131
+ return {
132
+ id: node.id,
133
+ label: node.label,
134
+ description: node.description,
135
+ color: node.color ?? colors[index % colors.length],
136
+ value,
137
+ inValue: inValue.get(node.id) ?? 0,
138
+ outValue: outValue.get(node.id) ?? 0,
139
+ depth: d,
140
+ x0: d * step,
141
+ x1: d * step + nodeWidth,
142
+ y0: 0,
143
+ y1: 0
144
+ };
145
+ });
146
+ const byId = new Map(placed.map((node) => [node.id, node]));
147
+ const byColumn = Array.from({ length: columns }, (_, d) => placed.filter((node) => node.depth === d));
148
+ const padding = Math.min(nodePadding, ...byColumn.map((column) => column.length > 1 ? height * .5 / (column.length - 1) : nodePadding));
149
+ const ky = Math.min(...byColumn.filter((column) => column.length).map((column) => (height - (column.length - 1) * padding) / column.reduce((sum, node) => sum + node.value, 0)));
150
+ for (const column of byColumn) {
151
+ let y = 0;
152
+ for (const node of column) {
153
+ node.y0 = y;
154
+ node.y1 = y + node.value * ky;
155
+ y = node.y1 + padding;
156
+ }
157
+ const offset = (height - (y - padding)) / 2;
158
+ for (const node of column) {
159
+ node.y0 += offset;
160
+ node.y1 += offset;
161
+ }
162
+ }
163
+ const resolve = (column) => {
164
+ let y = 0;
165
+ for (const node of column) {
166
+ const dy = y - node.y0;
167
+ if (dy > 0) {
168
+ node.y0 += dy;
169
+ node.y1 += dy;
170
+ }
171
+ y = node.y1 + padding;
172
+ }
173
+ y = height;
174
+ for (let i = column.length - 1; i >= 0; i--) {
175
+ const node = column[i];
176
+ const dy = node.y1 - y;
177
+ if (dy > 0) {
178
+ node.y0 -= dy;
179
+ node.y1 -= dy;
180
+ }
181
+ y = node.y0 - padding;
182
+ }
183
+ };
184
+ const center = (node) => (node.y0 + node.y1) / 2;
185
+ const relax = (column, alpha, side) => {
186
+ for (const node of column) {
187
+ let weighted = 0;
188
+ let total = 0;
189
+ for (const link of kept) {
190
+ if ((side === "source" ? link.target : link.source) !== node.id) continue;
191
+ const other = byId.get(side === "source" ? link.source : link.target);
192
+ if (!other) continue;
193
+ weighted += center(other) * link.value;
194
+ total += link.value;
195
+ }
196
+ if (!total) continue;
197
+ const dy = (weighted / total - center(node)) * alpha;
198
+ node.y0 += dy;
199
+ node.y1 += dy;
200
+ }
201
+ resolve(column);
202
+ };
203
+ for (let i = 0; i < ITERATIONS; i++) {
204
+ const alpha = .99 ** i;
205
+ for (let d = 1; d < columns; d++) relax(byColumn[d], alpha, "source");
206
+ for (let d = columns - 2; d >= 0; d--) relax(byColumn[d], alpha, "target");
207
+ }
208
+ const placedLinks = kept.map((link) => ({
209
+ link,
210
+ source: byId.get(link.source),
211
+ target: byId.get(link.target),
212
+ sy: 0,
213
+ ty: 0
214
+ }));
215
+ for (const node of placed) {
216
+ let sy = node.y0;
217
+ for (const entry of placedLinks.filter((entry) => entry.source === node).sort((a, b) => a.target.y0 - b.target.y0)) {
218
+ entry.sy = sy;
219
+ sy += entry.link.value * ky;
220
+ }
221
+ let ty = node.y0;
222
+ for (const entry of placedLinks.filter((entry) => entry.target === node).sort((a, b) => a.source.y0 - b.source.y0)) {
223
+ entry.ty = ty;
224
+ ty += entry.link.value * ky;
225
+ }
226
+ }
227
+ const result = placedLinks.map(({ link, source, target, sy, ty }) => {
228
+ const w = link.value * ky;
229
+ const x0 = source.x1;
230
+ const x1 = target.x0;
231
+ const y0 = sy + w / 2;
232
+ const y1 = ty + w / 2;
233
+ const xm = (x0 + x1) / 2;
234
+ return {
235
+ id: linkId(link),
236
+ source,
237
+ target,
238
+ value: link.value,
239
+ share: source.value ? link.value / source.value : 0,
240
+ width: w,
241
+ x0,
242
+ y0,
243
+ x1,
244
+ y1,
245
+ path: `M ${x0} ${y0} C ${xm} ${y0} ${xm} ${y1} ${x1} ${y1}`
246
+ };
247
+ });
248
+ return {
249
+ nodes: byColumn.flat(),
250
+ links: result,
251
+ columns,
252
+ step
253
+ };
254
+ }
255
+ // src/components/charts/sankey-chart/context.tsx
256
+ const defaultFormat = (value) => value.toLocaleString("en-US", { maximumFractionDigits: 2 });
257
+ function useSankeyModel({ nodes, links, label = "Sankey chart", formatValue = defaultFormat, colors = SANKEY_COLORS, nodeWidth = 12, nodePadding = 16, activeId, defaultActiveId = null, onActiveChange }) {
258
+ const data = useMemo(() => cleanSankey(nodes, links), [nodes, links]);
259
+ useEffect(() => {
260
+ if (process.env.NODE_ENV === "production") return;
261
+ const { invalid, cycle } = data.dropped;
262
+ if (invalid.length || cycle.length) console.warn(`SankeyChart left out ${invalid.length} invalid and ${cycle.length} loop-closing link(s).`, {
263
+ invalid,
264
+ cycle
265
+ });
266
+ }, [data]);
267
+ const [size, setSize] = useState({
268
+ width: 640,
269
+ height: 320
270
+ });
271
+ const sizeKey = `${size.width}x${size.height}`;
272
+ const [settledSize, setSettledSize] = useState(sizeKey);
273
+ const resized = settledSize !== sizeKey;
274
+ useLayoutEffect(() => {
275
+ if (resized) setSettledSize(sizeKey);
276
+ }, [resized, sizeKey]);
277
+ const layout = useMemo(() => layoutSankey(data, {
278
+ width: size.width,
279
+ height: size.height,
280
+ nodeWidth,
281
+ nodePadding,
282
+ colors
283
+ }), [
284
+ data,
285
+ size,
286
+ nodeWidth,
287
+ nodePadding,
288
+ colors
289
+ ]);
290
+ const cursor = useRowCursor(layout.nodes, "");
291
+ const [internalId, setInternalId] = useState(defaultActiveId);
292
+ const requestedId = activeId === void 0 ? internalId : activeId;
293
+ const node = layout.nodes.find((n) => n.id === requestedId);
294
+ const link = node ? void 0 : layout.links.find((l) => l.id === requestedId);
295
+ const active = node ? {
296
+ type: "node",
297
+ node
298
+ } : link ? {
299
+ type: "link",
300
+ link
301
+ } : null;
302
+ if (activeId === void 0 && internalId !== null && !active) setInternalId(null);
303
+ const latest = useRef({
304
+ activeId,
305
+ requestedId,
306
+ onActiveChange
307
+ });
308
+ useLayoutEffect(() => {
309
+ latest.current = {
310
+ activeId,
311
+ requestedId,
312
+ onActiveChange
313
+ };
314
+ });
315
+ const setActive = useCallback((id) => {
316
+ const current = latest.current;
317
+ if (current.activeId === void 0) setInternalId(id);
318
+ if (current.requestedId !== id) current.onActiveChange?.(id);
319
+ }, []);
320
+ const [tooltipOpen, setTooltipOpen] = useState(false);
321
+ const plotRef = useRef(null);
322
+ const buttons = useRef(/* @__PURE__ */ new Map());
323
+ const registerButton = useCallback((id, element) => {
324
+ if (element) buttons.current.set(id, element);
325
+ else buttons.current.delete(id);
326
+ }, []);
327
+ const totals = /* @__PURE__ */ new Map();
328
+ for (const l of data.links) totals.set(l.source, (totals.get(l.source) ?? 0) + l.value);
329
+ const incoming = /* @__PURE__ */ new Map();
330
+ for (const l of data.links) incoming.set(l.target, (incoming.get(l.target) ?? 0) + l.value);
331
+ const labels = new Map(data.nodes.map((n) => [n.id, n.label]));
332
+ const flows = data.links.map((l) => {
333
+ const sourceValue = Math.max(totals.get(l.source) ?? 0, incoming.get(l.source) ?? 0);
334
+ return {
335
+ id: l.id ?? `${l.source}:${l.target}`,
336
+ source: labels.get(l.source) ?? l.source,
337
+ target: labels.get(l.target) ?? l.target,
338
+ value: l.value,
339
+ share: sourceValue ? l.value / sourceValue : 0
340
+ };
341
+ });
342
+ const empty = !data.links.length ? nodes.length ? "No flows to show" : "No sankey data" : null;
343
+ return {
344
+ ...layout,
345
+ flows,
346
+ empty,
347
+ resized,
348
+ size,
349
+ setSize,
350
+ nodeWidth,
351
+ label,
352
+ formatValue,
353
+ active,
354
+ setActive,
355
+ cursor,
356
+ tooltipOpen,
357
+ setTooltipOpen,
358
+ tooltipId: useId(),
359
+ gradientId: useId(),
360
+ plotRef,
361
+ buttons,
362
+ registerButton,
363
+ reduce: useReducedMotion() ?? false,
364
+ canHover: useHoverCapable()
365
+ };
366
+ }
367
+ const SankeyContext = createContext(null);
368
+ function useSankeyChart() {
369
+ const model = useContext(SankeyContext);
370
+ if (!model) throw new Error("Sankey chart parts must be rendered inside SankeyChart.");
371
+ return model;
372
+ }
373
+ /** Whether a node or link is part of what is highlighted. */
374
+ function emphasis(active) {
375
+ const node = (n) => {
376
+ if (!active) return true;
377
+ if (active.type === "link") return active.link.source === n || active.link.target === n;
378
+ if (active.node === n) return true;
379
+ return false;
380
+ };
381
+ const link = (l) => {
382
+ if (!active) return true;
383
+ if (active.type === "link") return active.link === l;
384
+ return l.source === active.node || l.target === active.node;
385
+ };
386
+ return {
387
+ node,
388
+ link
389
+ };
390
+ }
391
+ export { useSankeyModel as i, emphasis as n, useSankeyChart as r, SankeyContext as t };
392
+
393
+ //# sourceMappingURL=context-CQbvWVnM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-CQbvWVnM.js","names":[],"sources":["../src/components/charts/sankey-chart/model.ts","../src/components/charts/sankey-chart/context.tsx"],"sourcesContent":["export interface SankeyNode {\n id: string;\n label: string;\n /** Any CSS color. Defaults to the palette, in node order. */\n color?: string;\n description?: string;\n}\n\nexport interface SankeyLink {\n /** Defaults to `${source}:${target}`. */\n id?: string;\n source: string;\n target: string;\n /** Positive value. Zero, negative and invalid values are left out. */\n value: number;\n}\n\nexport type PlacedNode = Required<Pick<SankeyNode, \"id\" | \"label\" | \"color\">> & {\n description?: string;\n /** Larger of the node's incoming and outgoing totals. */\n value: number;\n inValue: number;\n outValue: number;\n /** Column, counted from the sources. */\n depth: number;\n x0: number;\n x1: number;\n y0: number;\n y1: number;\n};\n\nexport type PlacedLink = {\n id: string;\n source: PlacedNode;\n target: PlacedNode;\n value: number;\n /** Share of the source node's value, from 0 to 1. */\n share: number;\n /** Band thickness. */\n width: number;\n /** Centerline ends: leaving the source and arriving at the target. */\n x0: number;\n y0: number;\n x1: number;\n y1: number;\n /** Centerline cubic path; stroke it at `width`. */\n path: string;\n};\n\nexport const SANKEY_COLORS = [\n \"#1d4ed8\",\n \"#7c3aed\",\n \"#0f766e\",\n \"#b45309\",\n \"#be123c\",\n \"#475569\",\n] as const;\n\n/** Relaxation passes; more settles crossings further at a small cost. */\nconst ITERATIONS = 6;\n\nexport const linkId = (link: SankeyLink) => link.id ?? `${link.source}:${link.target}`;\n\nexport type SankeyData = {\n nodes: SankeyNode[];\n links: SankeyLink[];\n /** Links left out, by reason, for the development warning. */\n dropped: { invalid: SankeyLink[]; cycle: SankeyLink[] };\n};\n\n/**\n * Cleans consumer data once per change, not per resize:\n * - repeated node ids keep the first node;\n * - links to unknown nodes, self links and non-positive or non-finite values\n * are dropped;\n * - unnamed links between the same pair are summed into one band, while a\n * repeated explicit id keeps the first link;\n * - a link closing a cycle is dropped: one whose target is still on the\n * depth-first path that reached its source, so the first-listed direction\n * of a loop survives.\n */\nexport function cleanSankey(\n nodes: readonly SankeyNode[],\n links: readonly SankeyLink[],\n): SankeyData {\n const byId = new Map<string, SankeyNode>();\n for (const node of nodes) if (!byId.has(node.id)) byId.set(node.id, node);\n const unique = [...byId.values()];\n\n const invalid: SankeyLink[] = [];\n const merged = new Map<string, SankeyLink>();\n for (const link of links) {\n const ok =\n byId.has(link.source) &&\n byId.has(link.target) &&\n link.source !== link.target &&\n Number.isFinite(link.value) &&\n link.value > 0;\n if (!ok) {\n invalid.push(link);\n continue;\n }\n const id = linkId(link);\n const existing = merged.get(id);\n if (!existing) merged.set(id, { ...link, id });\n else if (\n link.id === undefined &&\n existing.source === link.source &&\n existing.target === link.target\n )\n existing.value += link.value;\n else invalid.push(link);\n }\n const valid = [...merged.values()];\n\n const outgoing = new Map<string, SankeyLink[]>();\n for (const link of valid) {\n outgoing.set(link.source, [...(outgoing.get(link.source) ?? []), link]);\n }\n const state = new Map<string, \"open\" | \"done\">();\n const back = new Set<SankeyLink>();\n // Iterative depth-first search, so a very long chain cannot overflow the stack.\n for (const root of unique) {\n if (state.has(root.id)) continue;\n const stack: { id: string; next: number }[] = [{ id: root.id, next: 0 }];\n state.set(root.id, \"open\");\n while (stack.length) {\n const frame = stack[stack.length - 1];\n const edges = outgoing.get(frame.id) ?? [];\n if (frame.next >= edges.length) {\n state.set(frame.id, \"done\");\n stack.pop();\n continue;\n }\n const link = edges[frame.next++];\n const seen = state.get(link.target);\n if (seen === \"open\") back.add(link);\n else if (seen === undefined) {\n state.set(link.target, \"open\");\n stack.push({ id: link.target, next: 0 });\n }\n }\n }\n return {\n nodes: unique,\n links: valid.filter((link) => !back.has(link)),\n dropped: { invalid, cycle: valid.filter((link) => back.has(link)) },\n };\n}\n\n/**\n * Lays nodes out in columns by their longest path from a source, with sinks\n * pushed to the last column, then sizes them to their value and relaxes each\n * column toward its neighbours to shorten the links. Each column keeps the\n * order the nodes were given in, so order them to avoid crossings.\n */\nexport function layoutSankey(\n { nodes, links: kept }: SankeyData,\n {\n width,\n height,\n nodeWidth,\n nodePadding,\n colors,\n }: {\n width: number;\n height: number;\n nodeWidth: number;\n nodePadding: number;\n colors: readonly string[];\n },\n) {\n const inValue = new Map<string, number>();\n const outValue = new Map<string, number>();\n for (const link of kept) {\n outValue.set(link.source, (outValue.get(link.source) ?? 0) + link.value);\n inValue.set(link.target, (inValue.get(link.target) ?? 0) + link.value);\n }\n\n // Longest-path depth over the acyclic links, in topological order.\n const indegree = new Map<string, number>();\n for (const link of kept) indegree.set(link.target, (indegree.get(link.target) ?? 0) + 1);\n const depth = new Map<string, number>();\n const queue = nodes.filter((node) => !indegree.get(node.id)).map((node) => node.id);\n for (const id of queue) depth.set(id, 0);\n for (let i = 0; i < queue.length; i++) {\n const id = queue[i];\n for (const link of kept) {\n if (link.source !== id) continue;\n depth.set(link.target, Math.max(depth.get(link.target) ?? 0, (depth.get(id) ?? 0) + 1));\n const left = (indegree.get(link.target) ?? 0) - 1;\n indegree.set(link.target, left);\n if (left === 0) queue.push(link.target);\n }\n }\n\n const linked = nodes.filter((node) => inValue.has(node.id) || outValue.has(node.id));\n if (!linked.length || width <= 0 || height <= 0) {\n return { nodes: [] as PlacedNode[], links: [] as PlacedLink[], columns: 0, step: 0 };\n }\n const maxDepth = Math.max(0, ...linked.map((node) => depth.get(node.id) ?? 0));\n const columns = maxDepth + 1;\n const step = columns > 1 ? (width - nodeWidth) / (columns - 1) : 0;\n\n const placed: PlacedNode[] = linked.map((node) => {\n const index = nodes.indexOf(node);\n const value = Math.max(inValue.get(node.id) ?? 0, outValue.get(node.id) ?? 0);\n // Sinks sit in the last column, so every outcome lines up on the right.\n const d = outValue.has(node.id) ? (depth.get(node.id) ?? 0) : maxDepth;\n return {\n id: node.id,\n label: node.label,\n description: node.description,\n color: node.color ?? colors[index % colors.length],\n value,\n inValue: inValue.get(node.id) ?? 0,\n outValue: outValue.get(node.id) ?? 0,\n depth: d,\n x0: d * step,\n x1: d * step + nodeWidth,\n y0: 0,\n y1: 0,\n };\n });\n const byId = new Map(placed.map((node) => [node.id, node]));\n const byColumn = Array.from({ length: columns }, (_, d) =>\n placed.filter((node) => node.depth === d),\n );\n\n // One scale for every column: the fullest column fills the height.\n const padding = Math.min(\n nodePadding,\n ...byColumn.map((column) =>\n column.length > 1 ? (height * 0.5) / (column.length - 1) : nodePadding,\n ),\n );\n const ky = Math.min(\n ...byColumn\n .filter((column) => column.length)\n .map(\n (column) =>\n (height - (column.length - 1) * padding) /\n column.reduce((sum, node) => sum + node.value, 0),\n ),\n );\n for (const column of byColumn) {\n let y = 0;\n for (const node of column) {\n node.y0 = y;\n node.y1 = y + node.value * ky;\n y = node.y1 + padding;\n }\n // Center columns shorter than the fullest one.\n const offset = (height - (y - padding)) / 2;\n for (const node of column) {\n node.y0 += offset;\n node.y1 += offset;\n }\n }\n\n // Columns keep the order nodes were given in, so the same data in a new\n // period morphs in place instead of swapping nodes past each other.\n // Relaxation only moves a node within the room its neighbours leave.\n const resolve = (column: PlacedNode[]) => {\n let y = 0;\n for (const node of column) {\n const dy = y - node.y0;\n if (dy > 0) {\n node.y0 += dy;\n node.y1 += dy;\n }\n y = node.y1 + padding;\n }\n y = height;\n for (let i = column.length - 1; i >= 0; i--) {\n const node = column[i];\n const dy = node.y1 - y;\n if (dy > 0) {\n node.y0 -= dy;\n node.y1 -= dy;\n }\n y = node.y0 - padding;\n }\n };\n const center = (node: PlacedNode) => (node.y0 + node.y1) / 2;\n const relax = (column: PlacedNode[], alpha: number, side: \"source\" | \"target\") => {\n for (const node of column) {\n let weighted = 0;\n let total = 0;\n for (const link of kept) {\n const self = side === \"source\" ? link.target : link.source;\n if (self !== node.id) continue;\n const other = byId.get(side === \"source\" ? link.source : link.target);\n if (!other) continue;\n weighted += center(other) * link.value;\n total += link.value;\n }\n if (!total) continue;\n const dy = (weighted / total - center(node)) * alpha;\n node.y0 += dy;\n node.y1 += dy;\n }\n resolve(column);\n };\n for (let i = 0; i < ITERATIONS; i++) {\n const alpha = 0.99 ** i;\n for (let d = 1; d < columns; d++) relax(byColumn[d], alpha, \"source\");\n for (let d = columns - 2; d >= 0; d--) relax(byColumn[d], alpha, \"target\");\n }\n\n // Stack each node's links in the order of the nodes they reach, so bands\n // leave and arrive without crossing at the node.\n const placedLinks = kept.map((link) => ({\n link,\n source: byId.get(link.source) as PlacedNode,\n target: byId.get(link.target) as PlacedNode,\n sy: 0,\n ty: 0,\n }));\n for (const node of placed) {\n let sy = node.y0;\n for (const entry of placedLinks\n .filter((entry) => entry.source === node)\n .sort((a, b) => a.target.y0 - b.target.y0)) {\n entry.sy = sy;\n sy += entry.link.value * ky;\n }\n let ty = node.y0;\n for (const entry of placedLinks\n .filter((entry) => entry.target === node)\n .sort((a, b) => a.source.y0 - b.source.y0)) {\n entry.ty = ty;\n ty += entry.link.value * ky;\n }\n }\n\n const result: PlacedLink[] = placedLinks.map(({ link, source, target, sy, ty }) => {\n const w = link.value * ky;\n const x0 = source.x1;\n const x1 = target.x0;\n const y0 = sy + w / 2;\n const y1 = ty + w / 2;\n const xm = (x0 + x1) / 2;\n return {\n id: linkId(link),\n source,\n target,\n value: link.value,\n share: source.value ? link.value / source.value : 0,\n width: w,\n x0,\n y0,\n x1,\n y1,\n path: `M ${x0} ${y0} C ${xm} ${y0} ${xm} ${y1} ${x1} ${y1}`,\n };\n });\n\n // Reading order for keyboard focus: column by column, top to bottom.\n const ordered = byColumn.flat();\n return { nodes: ordered, links: result, columns, step };\n}\n","\"use client\";\n\nimport {\n type ComponentProps,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useReducedMotion } from \"motion/react\";\n\nimport { useHoverCapable } from \"../../../hooks/use-hover-capable\";\nimport { useRowCursor } from \"../../../hooks/use-row-cursor\";\nimport {\n cleanSankey,\n layoutSankey,\n type PlacedLink,\n type PlacedNode,\n SANKEY_COLORS,\n type SankeyLink,\n type SankeyNode,\n} from \"./model\";\n\nexport interface SankeyChartProps extends ComponentProps<\"section\"> {\n nodes: readonly SankeyNode[];\n /** Weighted flows between node ids. Links that would close a loop are left out. */\n links: readonly SankeyLink[];\n label?: string;\n formatValue?: (value: number) => string;\n /** Palette for nodes without their own color, in node order. */\n colors?: readonly string[];\n /** Node bar width in px. */\n nodeWidth?: number;\n /** Space between nodes in a column, in px. */\n nodePadding?: number;\n /** Highlighted node or link id. Controlled. Link ids default to `source:target`. */\n activeId?: string | null;\n defaultActiveId?: string | null;\n onActiveChange?: (id: string | null) => void;\n}\n\nexport type SankeyActive = { type: \"node\"; node: PlacedNode } | { type: \"link\"; link: PlacedLink };\n\nconst defaultFormat = (value: number) =>\n value.toLocaleString(\"en-US\", { maximumFractionDigits: 2 });\n\nexport function useSankeyModel({\n nodes,\n links,\n label = \"Sankey chart\",\n formatValue = defaultFormat,\n colors = SANKEY_COLORS,\n nodeWidth = 12,\n nodePadding = 16,\n activeId,\n defaultActiveId = null,\n onActiveChange,\n}: SankeyChartProps) {\n const data = useMemo(() => cleanSankey(nodes, links), [nodes, links]);\n useEffect(() => {\n if (process.env.NODE_ENV === \"production\") return;\n const { invalid, cycle } = data.dropped;\n if (invalid.length || cycle.length)\n console.warn(\n `SankeyChart left out ${invalid.length} invalid and ${cycle.length} loop-closing link(s).`,\n { invalid, cycle },\n );\n }, [data]);\n\n const [size, setSize] = useState({ width: 640, height: 320 });\n // A resize re-lays the chart at once; only a data change springs. The\n // render that commits a new size carries `resized`, so its transitions are\n // instant; the follow-up render has the same targets and starts nothing.\n const sizeKey = `${size.width}x${size.height}`;\n const [settledSize, setSettledSize] = useState(sizeKey);\n const resized = settledSize !== sizeKey;\n useLayoutEffect(() => {\n if (resized) setSettledSize(sizeKey);\n }, [resized, sizeKey]);\n\n const layout = useMemo(\n () =>\n layoutSankey(data, {\n width: size.width,\n height: size.height,\n nodeWidth,\n nodePadding,\n colors,\n }),\n [data, size, nodeWidth, nodePadding, colors],\n );\n const cursor = useRowCursor(layout.nodes, \"\");\n\n const [internalId, setInternalId] = useState(defaultActiveId);\n const requestedId = activeId === undefined ? internalId : activeId;\n // Resolved during render by id: a node or link that left the data clears.\n const node = layout.nodes.find((n) => n.id === requestedId);\n const link = node ? undefined : layout.links.find((l) => l.id === requestedId);\n const active: SankeyActive | null = node\n ? { type: \"node\", node }\n : link\n ? { type: \"link\", link }\n : null;\n if (activeId === undefined && internalId !== null && !active) setInternalId(null);\n\n const latest = useRef({ activeId, requestedId, onActiveChange });\n useLayoutEffect(() => {\n latest.current = { activeId, requestedId, onActiveChange };\n });\n const setActive = useCallback((id: string | null) => {\n const current = latest.current;\n if (current.activeId === undefined) setInternalId(id);\n if (current.requestedId !== id) current.onActiveChange?.(id);\n }, []);\n\n const [tooltipOpen, setTooltipOpen] = useState(false);\n const plotRef = useRef<HTMLDivElement>(null);\n const buttons = useRef(new Map<string, HTMLButtonElement>());\n const registerButton = useCallback((id: string, element: HTMLButtonElement | null) => {\n if (element) buttons.current.set(id, element);\n else buttons.current.delete(id);\n }, []);\n\n // Every drawable flow for the exact-data table, with shares from the\n // cleaned data so the table does not wait on a measured size.\n const totals = new Map<string, number>();\n for (const l of data.links) {\n totals.set(l.source, (totals.get(l.source) ?? 0) + l.value);\n }\n const incoming = new Map<string, number>();\n for (const l of data.links) incoming.set(l.target, (incoming.get(l.target) ?? 0) + l.value);\n const labels = new Map(data.nodes.map((n) => [n.id, n.label]));\n const flows = data.links.map((l) => {\n const sourceValue = Math.max(totals.get(l.source) ?? 0, incoming.get(l.source) ?? 0);\n return {\n id: l.id ?? `${l.source}:${l.target}`,\n source: labels.get(l.source) ?? l.source,\n target: labels.get(l.target) ?? l.target,\n value: l.value,\n share: sourceValue ? l.value / sourceValue : 0,\n };\n });\n const empty = !data.links.length ? (nodes.length ? \"No flows to show\" : \"No sankey data\") : null;\n\n return {\n ...layout,\n flows,\n empty,\n resized,\n size,\n setSize,\n nodeWidth,\n label,\n formatValue,\n active,\n setActive,\n cursor,\n tooltipOpen,\n setTooltipOpen,\n tooltipId: useId(),\n gradientId: useId(),\n plotRef,\n buttons,\n registerButton,\n reduce: useReducedMotion() ?? false,\n canHover: useHoverCapable(),\n };\n}\n\nexport type SankeyModel = ReturnType<typeof useSankeyModel>;\nexport const SankeyContext = createContext<SankeyModel | null>(null);\n\nexport function useSankeyChart() {\n const model = useContext(SankeyContext);\n if (!model) throw new Error(\"Sankey chart parts must be rendered inside SankeyChart.\");\n return model;\n}\n\n/** Whether a node or link is part of what is highlighted. */\nexport function emphasis(active: SankeyActive | null) {\n const node = (n: PlacedNode) => {\n if (!active) return true;\n if (active.type === \"link\") return active.link.source === n || active.link.target === n;\n if (active.node === n) return true;\n return false;\n };\n const link = (l: PlacedLink) => {\n if (!active) return true;\n if (active.type === \"link\") return active.link === l;\n return l.source === active.node || l.target === active.node;\n };\n return { node, link };\n}\n"],"mappings":";;;;;AAiDA,MAAa,gBAAgB;CAC3B;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,aAAa;AAEnB,MAAa,UAAU,SAAqB,KAAK,MAAM,GAAG,KAAK,OAAO,GAAG,KAAK;;;;;;;;;;;;AAoB9E,SAAgB,YACd,OACA,OACY;CACZ,MAAM,uBAAO,IAAI,IAAwB;CACzC,KAAK,MAAM,QAAQ,OAAO,IAAI,CAAC,KAAK,IAAI,KAAK,EAAE,GAAG,KAAK,IAAI,KAAK,IAAI,IAAI;CACxE,MAAM,SAAS,CAAC,GAAG,KAAK,OAAO,CAAC;CAEhC,M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AAkC,IAAI;AAEnE,SAAgB,iBAAiB;CAC/B,MAAM,QAAQ,WAAW,aAAa;CACtC,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,yDAAyD;CACrF,OAAO;AACT;;AAGA,SAAgB,SAAS,QAA6B;CACpD,MAAM,QAAQ,MAAkB;EAC9B,IAAI,CAAC,QAAQ,OAAO;EACpB,IAAI,OAAO,SAAS,QAAQ,OAAO,OAAO,KAAK,WAAW,KAAK,OAAO,KAAK,WAAW;EACtF,IAAI,OAAO,SAAS,GAAG,OAAO;EAC9B,OAAO;CACT;CACA,MAAM,QAAQ,MAAkB;EAC9B,IAAI,CAAC,QAAQ,OAAO;EACpB,IAAI,OAAO,SAAS,QAAQ,OAAO,OAAO,SAAS;EACnD,OAAO,EAAE,WAAW,OAAO,QAAQ,EAAE,WAAW,OAAO;CACzD;CACA,OAAO;EAAE;EAAM;CAAK;AACtB"}
@@ -0,0 +1,204 @@
1
+ import { ComponentProps } from "react";
2
+ interface SankeyNode {
3
+ id: string;
4
+ label: string;
5
+ /** Any CSS color. Defaults to the palette, in node order. */
6
+ color?: string;
7
+ description?: string;
8
+ }
9
+ interface SankeyLink {
10
+ /** Defaults to `${source}:${target}`. */
11
+ id?: string;
12
+ source: string;
13
+ target: string;
14
+ /** Positive value. Zero, negative and invalid values are left out. */
15
+ value: number;
16
+ }
17
+ type PlacedNode = Required<Pick<SankeyNode, "id" | "label" | "color">> & {
18
+ description?: string;
19
+ /** Larger of the node's incoming and outgoing totals. */
20
+ value: number;
21
+ inValue: number;
22
+ outValue: number;
23
+ /** Column, counted from the sources. */
24
+ depth: number;
25
+ x0: number;
26
+ x1: number;
27
+ y0: number;
28
+ y1: number;
29
+ };
30
+ type PlacedLink = {
31
+ id: string;
32
+ source: PlacedNode;
33
+ target: PlacedNode;
34
+ value: number;
35
+ /** Share of the source node's value, from 0 to 1. */
36
+ share: number;
37
+ /** Band thickness. */
38
+ width: number;
39
+ /** Centerline ends: leaving the source and arriving at the target. */
40
+ x0: number;
41
+ y0: number;
42
+ x1: number;
43
+ y1: number;
44
+ /** Centerline cubic path; stroke it at `width`. */
45
+ path: string;
46
+ };
47
+ interface SankeyChartProps extends ComponentProps<"section"> {
48
+ nodes: readonly SankeyNode[];
49
+ /** Weighted flows between node ids. Links that would close a loop are left out. */
50
+ links: readonly SankeyLink[];
51
+ label?: string;
52
+ formatValue?: (value: number) => string;
53
+ /** Palette for nodes without their own color, in node order. */
54
+ colors?: readonly string[];
55
+ /** Node bar width in px. */
56
+ nodeWidth?: number;
57
+ /** Space between nodes in a column, in px. */
58
+ nodePadding?: number;
59
+ /** Highlighted node or link id. Controlled. Link ids default to `source:target`. */
60
+ activeId?: string | null;
61
+ defaultActiveId?: string | null;
62
+ onActiveChange?: (id: string | null) => void;
63
+ }
64
+ type SankeyActive = {
65
+ type: "node";
66
+ node: PlacedNode;
67
+ } | {
68
+ type: "link";
69
+ link: PlacedLink;
70
+ };
71
+ declare function useSankeyModel({ nodes, links, label, formatValue, colors, nodeWidth, nodePadding, activeId, defaultActiveId, onActiveChange }: SankeyChartProps): {
72
+ flows: {
73
+ id: string;
74
+ source: string;
75
+ target: string;
76
+ value: number;
77
+ share: number;
78
+ }[];
79
+ empty: string | null;
80
+ resized: boolean;
81
+ size: {
82
+ width: number;
83
+ height: number;
84
+ };
85
+ setSize: import("react").Dispatch<import("react").SetStateAction<{
86
+ width: number;
87
+ height: number;
88
+ }>>;
89
+ nodeWidth: number;
90
+ label: string;
91
+ formatValue: (value: number) => string;
92
+ active: SankeyActive | null;
93
+ setActive: (id: string | null) => void;
94
+ cursor: {
95
+ activeIndex: number;
96
+ moveTo: (id: string | null) => void;
97
+ moveActive: (direction: 1 | -1) => void;
98
+ };
99
+ tooltipOpen: boolean;
100
+ setTooltipOpen: import("react").Dispatch<import("react").SetStateAction<boolean>>;
101
+ tooltipId: string;
102
+ gradientId: string;
103
+ plotRef: import("react").RefObject<HTMLDivElement | null>;
104
+ buttons: import("react").RefObject<Map<string, HTMLButtonElement>>;
105
+ registerButton: (id: string, element: HTMLButtonElement | null) => void;
106
+ reduce: boolean;
107
+ canHover: boolean;
108
+ nodes: PlacedNode[];
109
+ links: PlacedLink[];
110
+ columns: number;
111
+ step: number;
112
+ };
113
+ type SankeyModel = ReturnType<typeof useSankeyModel>;
114
+ declare const SankeyContext: import("react").Context<{
115
+ flows: {
116
+ id: string;
117
+ source: string;
118
+ target: string;
119
+ value: number;
120
+ share: number;
121
+ }[];
122
+ empty: string | null;
123
+ resized: boolean;
124
+ size: {
125
+ width: number;
126
+ height: number;
127
+ };
128
+ setSize: import("react").Dispatch<import("react").SetStateAction<{
129
+ width: number;
130
+ height: number;
131
+ }>>;
132
+ nodeWidth: number;
133
+ label: string;
134
+ formatValue: (value: number) => string;
135
+ active: SankeyActive | null;
136
+ setActive: (id: string | null) => void;
137
+ cursor: {
138
+ activeIndex: number;
139
+ moveTo: (id: string | null) => void;
140
+ moveActive: (direction: 1 | -1) => void;
141
+ };
142
+ tooltipOpen: boolean;
143
+ setTooltipOpen: import("react").Dispatch<import("react").SetStateAction<boolean>>;
144
+ tooltipId: string;
145
+ gradientId: string;
146
+ plotRef: import("react").RefObject<HTMLDivElement | null>;
147
+ buttons: import("react").RefObject<Map<string, HTMLButtonElement>>;
148
+ registerButton: (id: string, element: HTMLButtonElement | null) => void;
149
+ reduce: boolean;
150
+ canHover: boolean;
151
+ nodes: PlacedNode[];
152
+ links: PlacedLink[];
153
+ columns: number;
154
+ step: number;
155
+ } | null>;
156
+ declare function useSankeyChart(): {
157
+ flows: {
158
+ id: string;
159
+ source: string;
160
+ target: string;
161
+ value: number;
162
+ share: number;
163
+ }[];
164
+ empty: string | null;
165
+ resized: boolean;
166
+ size: {
167
+ width: number;
168
+ height: number;
169
+ };
170
+ setSize: import("react").Dispatch<import("react").SetStateAction<{
171
+ width: number;
172
+ height: number;
173
+ }>>;
174
+ nodeWidth: number;
175
+ label: string;
176
+ formatValue: (value: number) => string;
177
+ active: SankeyActive | null;
178
+ setActive: (id: string | null) => void;
179
+ cursor: {
180
+ activeIndex: number;
181
+ moveTo: (id: string | null) => void;
182
+ moveActive: (direction: 1 | -1) => void;
183
+ };
184
+ tooltipOpen: boolean;
185
+ setTooltipOpen: import("react").Dispatch<import("react").SetStateAction<boolean>>;
186
+ tooltipId: string;
187
+ gradientId: string;
188
+ plotRef: import("react").RefObject<HTMLDivElement | null>;
189
+ buttons: import("react").RefObject<Map<string, HTMLButtonElement>>;
190
+ registerButton: (id: string, element: HTMLButtonElement | null) => void;
191
+ reduce: boolean;
192
+ canHover: boolean;
193
+ nodes: PlacedNode[];
194
+ links: PlacedLink[];
195
+ columns: number;
196
+ step: number;
197
+ };
198
+ /** Whether a node or link is part of what is highlighted. */
199
+ declare function emphasis(active: SankeyActive | null): {
200
+ node: (n: PlacedNode) => boolean;
201
+ link: (l: PlacedLink) => boolean;
202
+ };
203
+ export { emphasis as a, PlacedLink as c, SankeyNode as d, SankeyModel as i, PlacedNode as l, SankeyChartProps as n, useSankeyChart as o, SankeyContext as r, useSankeyModel as s, SankeyActive as t, SankeyLink as u };
204
+ //# sourceMappingURL=context-tv-kneJV.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-tv-kneJV.d.ts","names":[],"sources":["../src/components/charts/sankey-chart/model.ts","../src/components/charts/sankey-chart/context.tsx"],"mappings":";UAAiB;EACf;EACA;;EAEA;EACA;;UAGe;;EAEf;EACA;EACA;;EAEA;;KAGU,aAAa,SAAS,KAAK;EACrC;;EAEA;EACA;EACA;;EAEA;EACA;EACA;EACA;EACA;;KAGU;EACV;EACA,QAAQ;EACR,QAAQ;EACR;;EAEA;;EAEA;;EAEA;EACA;EACA;EACA;;EAEA;;UClBe,yBAAyB;EACxC,gBAAgB;;EAEhB,gBAAgB;EAChB;EACA,eAAe;;EAEf;;EAEA;;EAEA;;EAEA;EACA;EACA,kBAAkB;;KAGR;EAAiB;EAAc,MAAM;;EAAiB;EAAc,MAAM;;iBAKtE,iBACd,OACA,OACA,OACA,aACA,QACA,WACA,aACA,UACA,iBACA,kBACC;;;;;;;;;;;;;;;;;;;;EA7BqB,cAAA;;EAiFa,YAAA;;;;;;;;;;;;EASK,iBAAA,YAAM,SAAW;;;;;;;;KAmD/C,cAAc,kBAAkB;cAC/B,+BAAa;;;;;;;;;;;;;;;;;;;;EA9IF,cAAA;;EAiFa,YAAA;;;;;;;;;;;;EASK,iBAAA,YAAM,SAAW;;;;;;;;iBAsD3C;;;;;;;;;;;;;;;;;;;;EAhJQ,cAAA;;EAiFa,YAAA;;;;;;;;;;;;EASK,iBAAA,YAAM,SAAW;;;;;;;;;iBA6D3C,SAAS,QAAQ;EACd,OAAA,GAAA;EAMA,OAAA,GAAA"}
@@ -1,7 +1,7 @@
1
1
  import { SPRING_PRESS } from "./lib/ease.js";
2
+ import { Checkbox } from "./components/motion/checkbox.js";
2
3
  import { MorphPopover, MorphPopoverContent } from "./components/motion/popover-morph.js";
3
4
  import { t as Tooltip } from "./tooltip-CuHpilPN.js";
4
- import { Checkbox } from "./components/motion/checkbox.js";
5
5
  import { IconButton } from "./components/motion/availability-scheduler/icon-button.js";
6
6
  import { useState } from "react";
7
7
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -268,4 +268,4 @@ function CopyMenu({ fromLabel, reduce, onApply }) {
268
268
  }
269
269
  export { defaultWeek as a, startOptions as c, clampRange as i, toMinutes as l, WEEKDAYS as n, endOptions as o, buildOptions as r, panelKey as s, CopyMenu as t, toValue as u };
270
270
 
271
- //# sourceMappingURL=copy-menu-CKW3jM1J.js.map
271
+ //# sourceMappingURL=copy-menu-LU54Aruj.js.map