@kumix/ui 0.4.0 → 0.4.1
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.
- package/README.md +15 -15
- package/dist/components/agents/approval-card/index.d.ts +2 -0
- package/dist/components/agents/approval-card/index.d.ts.map +1 -1
- package/dist/components/agents/approval-card/index.js +2 -0
- package/dist/components/agents/approval-card/index.js.map +1 -1
- package/dist/components/agents/citations.d.ts +14 -2
- package/dist/components/agents/citations.d.ts.map +1 -1
- package/dist/components/agents/citations.js +11 -7
- package/dist/components/agents/citations.js.map +1 -1
- package/dist/components/agents/loading-states/reasoning-text.d.ts.map +1 -1
- package/dist/components/agents/loading-states/reasoning-text.js +3 -0
- package/dist/components/agents/loading-states/reasoning-text.js.map +1 -1
- package/dist/components/charts/bump-chart/context.js +1 -2
- package/dist/components/charts/bump-chart/plot.js +1 -2
- package/dist/components/charts/bump-chart/point.js +1 -1
- package/dist/components/charts/bump-chart/series.d.ts +1 -0
- package/dist/components/charts/candlestick-chart/context.d.ts +79 -0
- package/dist/components/charts/candlestick-chart/context.d.ts.map +1 -0
- package/dist/components/charts/candlestick-chart/context.js +69 -0
- package/dist/components/charts/candlestick-chart/context.js.map +1 -0
- package/dist/components/charts/candlestick-chart/legend.d.ts +12 -0
- package/dist/components/charts/candlestick-chart/legend.d.ts.map +1 -0
- package/dist/components/charts/candlestick-chart/legend.js +56 -0
- package/dist/components/charts/candlestick-chart/legend.js.map +1 -0
- package/dist/components/charts/candlestick-chart/plot.d.ts +9 -0
- package/dist/components/charts/candlestick-chart/plot.d.ts.map +1 -0
- package/dist/components/charts/candlestick-chart/plot.js +218 -0
- package/dist/components/charts/candlestick-chart/plot.js.map +1 -0
- package/dist/components/charts/candlestick-chart.d.ts +18 -0
- package/dist/components/charts/candlestick-chart.d.ts.map +1 -0
- package/dist/components/charts/candlestick-chart.js +34 -0
- package/dist/components/charts/candlestick-chart.js.map +1 -0
- package/dist/components/charts/composition-chart/context.js +1 -2
- package/dist/components/charts/composition-chart/plot.js +1 -1
- package/dist/components/charts/donut-chart/center.d.ts +16 -0
- package/dist/components/charts/donut-chart/center.d.ts.map +1 -0
- package/dist/components/charts/donut-chart/center.js +78 -0
- package/dist/components/charts/donut-chart/center.js.map +1 -0
- package/dist/components/charts/donut-chart/context.d.ts +68 -0
- package/dist/components/charts/donut-chart/context.d.ts.map +1 -0
- package/dist/components/charts/donut-chart/context.js +2 -0
- package/dist/components/charts/donut-chart/legend.d.ts +17 -0
- package/dist/components/charts/donut-chart/legend.d.ts.map +1 -0
- package/dist/components/charts/donut-chart/legend.js +85 -0
- package/dist/components/charts/donut-chart/legend.js.map +1 -0
- package/dist/components/charts/donut-chart/plot.d.ts +10 -0
- package/dist/components/charts/donut-chart/plot.d.ts.map +1 -0
- package/dist/components/charts/donut-chart/plot.js +108 -0
- package/dist/components/charts/donut-chart/plot.js.map +1 -0
- package/dist/components/charts/donut-chart.d.ts +22 -0
- package/dist/components/charts/donut-chart.d.ts.map +1 -0
- package/dist/components/charts/donut-chart.js +37 -0
- package/dist/components/charts/donut-chart.js.map +1 -0
- package/dist/components/charts/funnel-chart.d.ts.map +1 -1
- package/dist/components/charts/funnel-chart.js +1 -2
- package/dist/components/charts/funnel-chart.js.map +1 -1
- package/dist/components/charts/heat-calendar/tooltip.js +1 -1
- package/dist/components/charts/liquidity-heatmap.js +1 -1
- package/dist/components/charts/order-book/depth-row.d.ts +8 -2
- package/dist/components/charts/order-book/depth-row.d.ts.map +1 -1
- package/dist/components/charts/order-book/depth-row.js +11 -3
- package/dist/components/charts/order-book/depth-row.js.map +1 -1
- package/dist/components/charts/order-book.d.ts +33 -1
- package/dist/components/charts/order-book.d.ts.map +1 -1
- package/dist/components/charts/order-book.js +92 -17
- package/dist/components/charts/order-book.js.map +1 -1
- package/dist/components/charts/price-target-fan/tooltip.js +1 -1
- package/dist/components/charts/returns-calendar/tooltip.js +1 -1
- package/dist/components/charts/status-bar/tooltip.js +1 -1
- package/dist/components/charts/treemap/tooltip.js +1 -1
- package/dist/components/charts/volume-profile/tooltip.js +1 -1
- package/dist/components/custom/confirm-dialog.d.ts +1 -0
- package/dist/components/custom/toast.d.ts +1 -0
- package/dist/components/motion/action-swap.d.ts.map +1 -1
- package/dist/components/motion/action-swap.js +3 -0
- package/dist/components/motion/action-swap.js.map +1 -1
- package/dist/components/motion/animated-sidebar.d.ts +1 -0
- package/dist/components/motion/attachment-upload.d.ts.map +1 -1
- package/dist/components/motion/attachment-upload.js +1 -2
- package/dist/components/motion/attachment-upload.js.map +1 -1
- package/dist/components/motion/availability-scheduler/copy-menu.js +1 -2
- package/dist/components/motion/availability-scheduler/day-row.js +2 -2
- package/dist/components/motion/availability-scheduler/index.js +1 -1
- package/dist/components/motion/bloom-menu.d.ts +1 -0
- package/dist/components/motion/bounce-sidebar.d.ts.map +1 -1
- package/dist/components/motion/bounce-sidebar.js +34 -42
- package/dist/components/motion/bounce-sidebar.js.map +1 -1
- package/dist/components/motion/button/stateful.d.ts.map +1 -1
- package/dist/components/motion/button/stateful.js +3 -0
- package/dist/components/motion/button/stateful.js.map +1 -1
- package/dist/components/motion/card.d.ts +44 -0
- package/dist/components/motion/card.d.ts.map +1 -0
- package/dist/components/motion/card.js +122 -0
- package/dist/components/motion/card.js.map +1 -0
- package/dist/components/motion/checkbox.d.ts +3 -1
- package/dist/components/motion/checkbox.d.ts.map +1 -1
- package/dist/components/motion/checkbox.js +18 -6
- package/dist/components/motion/checkbox.js.map +1 -1
- package/dist/components/motion/color-picker.d.ts +110 -0
- package/dist/components/motion/color-picker.d.ts.map +1 -0
- package/dist/components/motion/color-picker.js +1053 -0
- package/dist/components/motion/color-picker.js.map +1 -0
- package/dist/components/motion/color-selector.d.ts.map +1 -1
- package/dist/components/motion/color-selector.js +9 -2
- package/dist/components/motion/color-selector.js.map +1 -1
- package/dist/components/motion/combobox/content.d.ts +1 -0
- package/dist/components/motion/command-palette.js +2 -2
- package/dist/components/motion/command-palette.js.map +1 -1
- package/dist/components/motion/context-menu.d.ts +1 -0
- package/dist/components/motion/digit-swap.d.ts +9 -1
- package/dist/components/motion/digit-swap.d.ts.map +1 -1
- package/dist/components/motion/digit-swap.js +18 -7
- package/dist/components/motion/digit-swap.js.map +1 -1
- package/dist/components/motion/expandable-control.d.ts +1 -0
- package/dist/components/motion/knockout-wheel.d.ts.map +1 -1
- package/dist/components/motion/knockout-wheel.js +1 -2
- package/dist/components/motion/knockout-wheel.js.map +1 -1
- package/dist/components/motion/morphing-search-chips.d.ts +54 -0
- package/dist/components/motion/morphing-search-chips.d.ts.map +1 -0
- package/dist/components/motion/morphing-search-chips.js +599 -0
- package/dist/components/motion/morphing-search-chips.js.map +1 -0
- package/dist/components/motion/multi-select/content.d.ts +1 -0
- package/dist/components/motion/not-found/shared.d.ts +1 -0
- package/dist/components/motion/number-ticker.d.ts +6 -1
- package/dist/components/motion/number-ticker.d.ts.map +1 -1
- package/dist/components/motion/number-ticker.js +19 -9
- package/dist/components/motion/number-ticker.js.map +1 -1
- package/dist/components/motion/parallax.js.map +1 -1
- package/dist/components/motion/popover-morph.d.ts +1 -0
- package/dist/components/motion/popover-morph.js +3 -0
- package/dist/components/motion/popover-morph.js.map +1 -1
- package/dist/components/motion/popover.d.ts +1 -0
- package/dist/components/motion/prediction-market-card.js +2 -3
- package/dist/components/motion/prediction-market-card.js.map +1 -1
- package/dist/components/motion/radio.d.ts +3 -1
- package/dist/components/motion/radio.d.ts.map +1 -1
- package/dist/components/motion/radio.js +17 -5
- package/dist/components/motion/radio.js.map +1 -1
- package/dist/components/motion/scroll-progress.d.ts +1 -0
- package/dist/components/motion/shader-background.d.ts +1 -0
- package/dist/components/motion/sortable-list.d.ts +1 -0
- package/dist/components/motion/sortable-stack.js +1 -2
- package/dist/components/motion/tabs.d.ts +1 -0
- package/dist/components/motion/text-reveal.d.ts +1 -0
- package/dist/components/motion/tooltip/positioner.d.ts +8 -26
- package/dist/components/motion/tooltip/positioner.d.ts.map +1 -1
- package/dist/components/motion/tooltip/positioner.js +1 -2
- package/dist/components/motion/tooltip.d.ts +62 -20
- package/dist/components/motion/tooltip.d.ts.map +1 -1
- package/dist/components/motion/tooltip.js +1 -135
- package/dist/components/motion/wallet-card/account-avatar.js +1 -2
- package/dist/components/reui/alert.d.ts +1 -1
- package/dist/components/reui/autocomplete.d.ts +1 -1
- package/dist/components/reui/autocomplete.d.ts.map +1 -1
- package/dist/components/reui/autocomplete.js.map +1 -1
- package/dist/components/reui/badge.d.ts +2 -2
- package/dist/components/reui/color-picker.d.ts +280 -0
- package/dist/components/reui/color-picker.d.ts.map +1 -0
- package/dist/components/reui/color-picker.js +2013 -0
- package/dist/components/reui/color-picker.js.map +1 -0
- package/dist/components/reui/data-grid/data-grid-cell-selection.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-header.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-header.js +43 -21
- package/dist/components/reui/data-grid/data-grid-column-header.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-pagination.js +1 -1
- package/dist/components/reui/data-grid/data-grid-scroll-area.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-scroll-area.js +9 -3
- package/dist/components/reui/data-grid/data-grid-scroll-area.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js +12 -8
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd.d.ts +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd.js +52 -13
- package/dist/components/reui/data-grid/data-grid-table-dnd.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.js +35 -41
- package/dist/components/reui/data-grid/data-grid-table-virtual.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table.d.ts +168 -5
- package/dist/components/reui/data-grid/data-grid-table.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table.js +203 -69
- package/dist/components/reui/data-grid/data-grid-table.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid.d.ts +39 -0
- package/dist/components/reui/data-grid/data-grid.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid.js +33 -1
- package/dist/components/reui/data-grid/data-grid.js.map +1 -1
- package/dist/components/reui/date-selector.d.ts +1 -0
- package/dist/components/reui/date-selector.js +1 -1
- package/dist/components/reui/emoji-picker.d.ts +367 -0
- package/dist/components/reui/emoji-picker.d.ts.map +1 -0
- package/dist/components/reui/emoji-picker.js +1768 -0
- package/dist/components/reui/emoji-picker.js.map +1 -0
- package/dist/components/reui/event-calendar/event-calendar-i18n.d.ts.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-nav.js +2 -2
- package/dist/components/reui/file-type.d.ts +496 -0
- package/dist/components/reui/file-type.d.ts.map +1 -0
- package/dist/components/reui/file-type.js +964 -0
- package/dist/components/reui/file-type.js.map +1 -0
- package/dist/components/reui/filters/filters-advanced.d.ts +1 -0
- package/dist/components/reui/filters/filters-advanced.js +1 -1
- package/dist/components/reui/filters/filters-advanced.js.map +1 -1
- package/dist/components/reui/filters/filters-chip.d.ts +5 -1
- package/dist/components/reui/filters/filters-chip.d.ts.map +1 -1
- package/dist/components/reui/filters/filters-chip.js +1 -1
- package/dist/components/reui/filters/filters-lib.d.ts.map +1 -1
- package/dist/components/reui/frame.d.ts +1 -1
- package/dist/components/reui/frame.d.ts.map +1 -1
- package/dist/components/reui/frame.js.map +1 -1
- package/dist/components/reui/gantt/gantt-nav.js +2 -2
- package/dist/components/reui/icon-tile.d.ts +2 -2
- package/dist/components/reui/icon-tile.js +8 -7
- package/dist/components/reui/icon-tile.js.map +1 -1
- package/dist/components/reui/kanban.d.ts.map +1 -1
- package/dist/components/reui/kanban.js +1 -1
- package/dist/components/reui/kanban.js.map +1 -1
- package/dist/components/reui/number-field.d.ts +3 -3
- package/dist/components/reui/number-field.d.ts.map +1 -1
- package/dist/components/reui/number-field.js.map +1 -1
- package/dist/components/reui/rating.d.ts +1 -1
- package/dist/components/reui/scrollspy.d.ts +1 -0
- package/dist/components/reui/time-picker.js.map +1 -1
- package/dist/components/ui/attachment.d.ts +3 -3
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/bubble.d.ts +1 -1
- package/dist/components/ui/button-group.d.ts +1 -1
- package/dist/components/ui/button.d.ts +2 -2
- package/dist/components/ui/command.d.ts.map +1 -1
- package/dist/components/ui/direction.js +1 -2
- package/dist/components/ui/empty.d.ts +1 -1
- package/dist/components/ui/field.d.ts +1 -1
- package/dist/components/ui/field.js +1 -1
- package/dist/components/ui/input-group.d.ts +1 -1
- package/dist/components/ui/item.d.ts +2 -2
- package/dist/components/ui/marker.d.ts +1 -1
- package/dist/components/ui/message-scroller.d.ts.map +1 -1
- package/dist/components/ui/questionnaire.d.ts.map +1 -1
- package/dist/components/ui/sidebar.d.ts +1 -1
- package/dist/components/ui/sidebar.js +1 -1
- package/dist/components/ui/toggle.d.ts +1 -1
- package/dist/context-tTdLKYNf.js +99 -0
- package/dist/context-tTdLKYNf.js.map +1 -0
- package/dist/{copy-menu-C5GaT4Z-.js → copy-menu-BXUh52bu.js} +2 -2
- package/dist/{copy-menu-C5GaT4Z-.js.map → copy-menu-BXUh52bu.js.map} +1 -1
- package/dist/hooks/use-copy-to-clipboard.d.ts +1 -0
- package/dist/hooks/use-hover-gesture.d.ts +1 -0
- package/dist/hooks/use-intersection-observer.d.ts +1 -0
- package/dist/hooks/use-scroll-position.d.ts +1 -0
- package/dist/hooks/use-slider-input.d.ts +1 -0
- package/dist/hooks/use-viewport.d.ts +1 -0
- package/dist/lib/tick-sound.d.ts +1 -0
- package/dist/model-NSIg2p7a.d.ts +20 -0
- package/dist/model-NSIg2p7a.d.ts.map +1 -0
- package/dist/model-_mRyI6V9.d.ts +18 -0
- package/dist/model-_mRyI6V9.d.ts.map +1 -0
- package/dist/{positioner-3mCqiebN.js → positioner-3r3cfkqT.js} +97 -33
- package/dist/positioner-3r3cfkqT.js.map +1 -0
- package/dist/tooltip-Bam5KeYe.js +535 -0
- package/dist/tooltip-Bam5KeYe.js.map +1 -0
- package/dist/use-position-DOi1gVL0.d.ts +32 -0
- package/dist/use-position-DOi1gVL0.d.ts.map +1 -0
- package/package.json +8 -8
- package/dist/components/motion/tooltip.js.map +0 -1
- package/dist/model-DfeFradZ.d.ts +0 -9
- package/dist/model-DfeFradZ.d.ts.map +0 -1
- package/dist/positioner-3mCqiebN.js.map +0 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useCallback, useContext, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { useReducedMotion } from "motion/react";
|
|
4
|
+
//#region src/components/charts/candlestick-chart/context.tsx
|
|
5
|
+
const defaultPrice = (value) => value.toLocaleString("en-US", { maximumFractionDigits: 2 });
|
|
6
|
+
const defaultVolume = (value) => new Intl.NumberFormat("en-US", {
|
|
7
|
+
notation: "compact",
|
|
8
|
+
maximumFractionDigits: 1
|
|
9
|
+
}).format(value);
|
|
10
|
+
function useCandlestickModel({ candles, lastPrice, activeId, defaultActiveId = null, onActiveIdChange, formatPrice = defaultPrice, formatVolume = defaultVolume, label = "Candlestick chart" }) {
|
|
11
|
+
const reduce = useReducedMotion() ?? false;
|
|
12
|
+
const [internalActive, setInternalActive] = useState(defaultActiveId);
|
|
13
|
+
const rawActive = activeId === void 0 ? internalActive : activeId;
|
|
14
|
+
const index = rawActive === null ? -1 : candles.findIndex((candle) => candle.id === rawActive);
|
|
15
|
+
const active = index >= 0 ? index : null;
|
|
16
|
+
const latest = useRef({
|
|
17
|
+
candles,
|
|
18
|
+
controlled: activeId !== void 0,
|
|
19
|
+
onActiveIdChange
|
|
20
|
+
});
|
|
21
|
+
useLayoutEffect(() => {
|
|
22
|
+
latest.current = {
|
|
23
|
+
candles,
|
|
24
|
+
controlled: activeId !== void 0,
|
|
25
|
+
onActiveIdChange
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
candles,
|
|
30
|
+
lastPrice,
|
|
31
|
+
active,
|
|
32
|
+
setActive: useCallback((next) => {
|
|
33
|
+
const id = next === null ? null : latest.current.candles[next]?.id ?? null;
|
|
34
|
+
if (!latest.current.controlled) setInternalActive(id);
|
|
35
|
+
latest.current.onActiveIdChange?.(id);
|
|
36
|
+
}, []),
|
|
37
|
+
scale: useMemo(() => {
|
|
38
|
+
const lows = candles.map((candle) => candle.low);
|
|
39
|
+
const highs = candles.map((candle) => candle.high);
|
|
40
|
+
if (lastPrice !== void 0) {
|
|
41
|
+
lows.push(lastPrice);
|
|
42
|
+
highs.push(lastPrice);
|
|
43
|
+
}
|
|
44
|
+
const min = lows.length ? Math.min(...lows) : 0;
|
|
45
|
+
const max = highs.length ? Math.max(...highs) : 1;
|
|
46
|
+
const pad = Math.max((max - min) * .08, max * 5e-4, 1e-4);
|
|
47
|
+
const volumeMax = Math.max(1, ...candles.map((candle) => candle.volume));
|
|
48
|
+
return {
|
|
49
|
+
min: min - pad,
|
|
50
|
+
max: max + pad,
|
|
51
|
+
volumeMax
|
|
52
|
+
};
|
|
53
|
+
}, [candles, lastPrice]),
|
|
54
|
+
formatPrice,
|
|
55
|
+
formatVolume,
|
|
56
|
+
label,
|
|
57
|
+
reduce
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const CandlestickContext = createContext(null);
|
|
61
|
+
function useCandlestickChart() {
|
|
62
|
+
const model = useContext(CandlestickContext);
|
|
63
|
+
if (!model) throw new Error("CandlestickChart parts must be used inside <CandlestickChart>");
|
|
64
|
+
return model;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { CandlestickContext, useCandlestickChart, useCandlestickModel };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"sources":["../../../../src/components/charts/candlestick-chart/context.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useReducedMotion } from \"motion/react\";\n\nexport type Candle = {\n /** Stable id, such as the open timestamp. */\n id: string;\n /** Axis and readout label, such as \"14:05\". */\n label: string;\n open: number;\n high: number;\n low: number;\n close: number;\n volume: number;\n};\n\nexport interface CandlestickChartProps {\n candles: readonly Candle[];\n /** Draws a dashed line and tag at this price, usually the last trade. */\n lastPrice?: number;\n /**\n * Controlled crosshair candle, by `id`, so it stays on the same candle as\n * new ones arrive. Pair with `onActiveIdChange`.\n */\n activeId?: string | null;\n defaultActiveId?: string | null;\n onActiveIdChange?: (id: string | null) => void;\n formatPrice?: (value: number) => string;\n formatVolume?: (value: number) => string;\n /** Accessible name for the chart. */\n label?: string;\n className?: string;\n children?: ReactNode;\n}\n\nconst defaultPrice = (value: number) => value.toLocaleString(\"en-US\", { maximumFractionDigits: 2 });\nconst defaultVolume = (value: number) =>\n new Intl.NumberFormat(\"en-US\", {\n notation: \"compact\",\n maximumFractionDigits: 1,\n }).format(value);\n\nexport function useCandlestickModel({\n candles,\n lastPrice,\n activeId,\n defaultActiveId = null,\n onActiveIdChange,\n formatPrice = defaultPrice,\n formatVolume = defaultVolume,\n label = \"Candlestick chart\",\n}: CandlestickChartProps) {\n const reduce = useReducedMotion() ?? false;\n const [internalActive, setInternalActive] = useState(defaultActiveId);\n const rawActive = activeId === undefined ? internalActive : activeId;\n // Resolve the crosshair during render by id; a candle that scrolled out of\n // the window clears it rather than landing on a neighbour.\n const index = rawActive === null ? -1 : candles.findIndex((candle) => candle.id === rawActive);\n const active = index >= 0 ? index : null;\n\n // Stable setter that reads the latest candles and callback from a ref.\n const latest = useRef({ candles, controlled: activeId !== undefined, onActiveIdChange });\n useLayoutEffect(() => {\n latest.current = { candles, controlled: activeId !== undefined, onActiveIdChange };\n });\n const setActive = useCallback((next: number | null) => {\n const id = next === null ? null : (latest.current.candles[next]?.id ?? null);\n if (!latest.current.controlled) setInternalActive(id);\n latest.current.onActiveIdChange?.(id);\n }, []);\n\n const scale = useMemo(() => {\n const lows = candles.map((candle) => candle.low);\n const highs = candles.map((candle) => candle.high);\n if (lastPrice !== undefined) {\n lows.push(lastPrice);\n highs.push(lastPrice);\n }\n const min = lows.length ? Math.min(...lows) : 0;\n const max = highs.length ? Math.max(...highs) : 1;\n const pad = Math.max((max - min) * 0.08, max * 0.0005, 0.0001);\n const volumeMax = Math.max(1, ...candles.map((candle) => candle.volume));\n return { min: min - pad, max: max + pad, volumeMax };\n }, [candles, lastPrice]);\n\n return {\n candles,\n lastPrice,\n active,\n setActive,\n scale,\n formatPrice,\n formatVolume,\n label,\n reduce,\n };\n}\n\nexport type CandlestickModel = ReturnType<typeof useCandlestickModel>;\n\nexport const CandlestickContext = createContext<CandlestickModel | null>(null);\n\nexport function useCandlestickChart() {\n const model = useContext(CandlestickContext);\n if (!model) throw new Error(\"CandlestickChart parts must be used inside <CandlestickChart>\");\n return model;\n}\n"],"mappings":";;;;AA6CA,MAAM,gBAAgB,UAAkB,MAAM,eAAe,SAAS,EAAE,uBAAuB,EAAE,CAAC;AAClG,MAAM,iBAAiB,UACrB,IAAI,KAAK,aAAa,SAAS;CAC7B,UAAU;CACV,uBAAuB;AACzB,CAAC,CAAC,CAAC,OAAO,KAAK;AAEjB,SAAgB,oBAAoB,EAClC,SACA,WACA,UACA,kBAAkB,MAClB,kBACA,cAAc,cACd,eAAe,eACf,QAAQ,uBACgB;CACxB,MAAM,SAAS,iBAAiB,KAAK;CACrC,MAAM,CAAC,gBAAgB,qBAAqB,SAAS,eAAe;CACpE,MAAM,YAAY,aAAa,KAAA,IAAY,iBAAiB;CAG5D,MAAM,QAAQ,cAAc,OAAO,KAAK,QAAQ,WAAW,WAAW,OAAO,OAAO,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@@
|
|
|
1
|
+
import { Candle } from "./context.js";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
//#region src/components/charts/candlestick-chart/legend.d.ts
|
|
4
|
+
export type CandlestickChartLegendProps = {
|
|
5
|
+
/** Custom readout. Receives the crosshair candle, or the latest one. */
|
|
6
|
+
children?: (candle: Candle, change: number) => ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
};
|
|
9
|
+
/** OHLC and volume readout that follows the crosshair. */
|
|
10
|
+
export declare function CandlestickChartLegend({ children, className }: CandlestickChartLegendProps): import("react").JSX.Element | null;
|
|
11
|
+
//#endregion
|
|
12
|
+
//# sourceMappingURL=legend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legend.d.ts","names":[],"sources":["../../../../src/components/charts/candlestick-chart/legend.tsx"],"mappings":";;;YAOY;;EAEV,YAAY,QAAQ,QAAQ,mBAAmB;EAC/C;;;wBAIc,yBAAyB,UAAU,aAAa,8CAA2B,IAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCandlestickChart } from "./context.js";
|
|
3
|
+
import { cn } from "@kumix/utils";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
//#region src/components/charts/candlestick-chart/legend.tsx
|
|
6
|
+
/** OHLC and volume readout that follows the crosshair. */
|
|
7
|
+
function CandlestickChartLegend({ children, className }) {
|
|
8
|
+
const { candles, active, formatPrice, formatVolume } = useCandlestickChart();
|
|
9
|
+
const candle = active !== null ? candles[active] : candles.at(-1);
|
|
10
|
+
if (!candle) return null;
|
|
11
|
+
const change = candle.open ? (candle.close - candle.open) / candle.open * 100 : 0;
|
|
12
|
+
if (children) return /* @__PURE__ */ jsx(Fragment, { children: children(candle, change) });
|
|
13
|
+
const tone = change >= 0 ? "text-emerald-600 dark:text-emerald-400" : "text-rose-600 dark:text-rose-400";
|
|
14
|
+
const items = [
|
|
15
|
+
["O", formatPrice(candle.open)],
|
|
16
|
+
["H", formatPrice(candle.high)],
|
|
17
|
+
["L", formatPrice(candle.low)],
|
|
18
|
+
["C", formatPrice(candle.close)],
|
|
19
|
+
["Vol", formatVolume(candle.volume)]
|
|
20
|
+
];
|
|
21
|
+
return /* @__PURE__ */ jsxs("dl", {
|
|
22
|
+
className: cn("flex flex-wrap items-center gap-x-3 gap-y-1 font-mono text-xs tabular-nums", className),
|
|
23
|
+
children: [
|
|
24
|
+
/* @__PURE__ */ jsx("dt", {
|
|
25
|
+
className: "sr-only",
|
|
26
|
+
children: "Candle"
|
|
27
|
+
}),
|
|
28
|
+
/* @__PURE__ */ jsx("dd", {
|
|
29
|
+
className: "text-muted-foreground",
|
|
30
|
+
children: candle.label
|
|
31
|
+
}),
|
|
32
|
+
items.map(([term, value]) => /* @__PURE__ */ jsxs("div", {
|
|
33
|
+
className: "flex gap-1",
|
|
34
|
+
children: [/* @__PURE__ */ jsx("dt", {
|
|
35
|
+
className: "text-muted-foreground",
|
|
36
|
+
children: term
|
|
37
|
+
}), /* @__PURE__ */ jsx("dd", {
|
|
38
|
+
className: term === "Vol" ? void 0 : tone,
|
|
39
|
+
children: value
|
|
40
|
+
})]
|
|
41
|
+
}, term)),
|
|
42
|
+
/* @__PURE__ */ jsxs("dd", {
|
|
43
|
+
className: tone,
|
|
44
|
+
children: [
|
|
45
|
+
change >= 0 ? "+" : "−",
|
|
46
|
+
Math.abs(change).toFixed(2),
|
|
47
|
+
"%"
|
|
48
|
+
]
|
|
49
|
+
})
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { CandlestickChartLegend };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=legend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legend.js","names":[],"sources":["../../../../src/components/charts/candlestick-chart/legend.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ReactNode } from \"react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { type Candle, useCandlestickChart } from \"./context\";\n\nexport type CandlestickChartLegendProps = {\n /** Custom readout. Receives the crosshair candle, or the latest one. */\n children?: (candle: Candle, change: number) => ReactNode;\n className?: string;\n};\n\n/** OHLC and volume readout that follows the crosshair. */\nexport function CandlestickChartLegend({ children, className }: CandlestickChartLegendProps) {\n const { candles, active, formatPrice, formatVolume } = useCandlestickChart();\n const candle = active !== null ? candles[active] : candles.at(-1);\n if (!candle) return null;\n const change = candle.open ? ((candle.close - candle.open) / candle.open) * 100 : 0;\n if (children) return <>{children(candle, change)}</>;\n const tone =\n change >= 0 ? \"text-emerald-600 dark:text-emerald-400\" : \"text-rose-600 dark:text-rose-400\";\n const items: [string, string][] = [\n [\"O\", formatPrice(candle.open)],\n [\"H\", formatPrice(candle.high)],\n [\"L\", formatPrice(candle.low)],\n [\"C\", formatPrice(candle.close)],\n [\"Vol\", formatVolume(candle.volume)],\n ];\n return (\n <dl\n className={cn(\n \"flex flex-wrap items-center gap-x-3 gap-y-1 font-mono text-xs tabular-nums\",\n className,\n )}\n >\n <dt className=\"sr-only\">Candle</dt>\n <dd className=\"text-muted-foreground\">{candle.label}</dd>\n {items.map(([term, value]) => (\n <div key={term} className=\"flex gap-1\">\n <dt className=\"text-muted-foreground\">{term}</dt>\n <dd className={term === \"Vol\" ? undefined : tone}>{value}</dd>\n </div>\n ))}\n <dd className={tone}>\n {change >= 0 ? \"+\" : \"−\"}\n {Math.abs(change).toFixed(2)}%\n </dd>\n </dl>\n );\n}\n"],"mappings":";;;;;;AAcA,SAAgB,uBAAuB,EAAE,UAAU,aAA0C;CAC3F,MAAM,EAAE,SAAS,QAAQ,aAAa,iBAAiB,oBAAoB;CAC3E,MAAM,SAAS,WAAW,OAAO,QAAQ,UAAU,QAAQ,GAAG,EAAE;CAChE,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,SAAS,OAAO,QAAS,OAAO,QAAQ,OAAO,QAAQ,OAAO,OAAQ,MAAM;CAClF,IAAI,UAAU,OAAO,oBAAA,UAAA,EAAA,UAAG,SAAS,QAAQ,MAAM,EAAI,CAAA;CACnD,MAAM,OACJ,UAAU,IAAI,2CAA2C;CAC3D,MAAM,QAA4B;EAChC,CAAC,KAAK,YAAY,OAAO,IAAI,CAAC;EAC9B,CAAC,KAAK,YAAY,OAAO,IAAI,CAAC;EAC9B,CAAC,KAAK,YAAY,OAAO,GAAG,CAAC;EAC7B,CAAC,KAAK,YAAY,OAAO,KAAK,CAAC;EAC/B,CAAC,OAAO,aAAa,OAAO,MAAM,CAAC;CACrC;CACA,OACE,qBAAC,MAAD;EACE,WAAW,GACT,8EACA,SACF;EAJF,UAAA;GAME,oBAAC,MAAD;IAAI,WAAU;IAAU,UAAA;GAAU,CAAA;GAClC,oBAAC,MAAD;IAAI,WAAU;IAAyB,UAAA,OAAO;GAAU,CAAA;GACvD,MAAM,KAAK,CAAC,MAAM,WACjB,qBAAC,OAAD;IAAgB,WAAU;IAA1B,UAAA,CACE,oBAAC,MAAD;KAAI,WAAU;KAAyB,UAAA;IAAS,CAAA,GAChD,oBAAC,MAAD;KAAI,WAAW,SAAS,QAAQ,KAAA,IAAY;KAAO,UAAA;IAAU,CAAA,CAC1D;GAHK,GAAA,IAGL,CACN;GACD,qBAAC,MAAD;IAAI,WAAW;IAAf,UAAA;KACG,UAAU,IAAI,MAAM;KACpB,KAAK,IAAI,MAAM,CAAC,CAAC,QAAQ,CAAC;KAAE;IAC3B;;EACF;;AAER"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/components/charts/candlestick-chart/plot.d.ts
|
|
2
|
+
export type CandlestickChartPlotProps = {
|
|
3
|
+
/** Plot height in px. */
|
|
4
|
+
height?: number;
|
|
5
|
+
className?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function CandlestickChartPlot({ height, className }: CandlestickChartPlotProps): import("react").JSX.Element;
|
|
8
|
+
//#endregion
|
|
9
|
+
//# sourceMappingURL=plot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plot.d.ts","names":[],"sources":["../../../../src/components/charts/candlestick-chart/plot.tsx"],"mappings":";YAuBY;;EAEV;EACA;;wBAGc,uBAAuB,QAAc,aAAa,4CAAyB,IAAA"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { EASE_OUT, SPRING_LAYOUT } from "../../../lib/ease.js";
|
|
3
|
+
import { useCandlestickChart } from "./context.js";
|
|
4
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
5
|
+
import { cn } from "@kumix/utils";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { motion } from "motion/react";
|
|
8
|
+
//#region src/components/charts/candlestick-chart/plot.tsx
|
|
9
|
+
/** Right gutter reserved for price labels, in px. */
|
|
10
|
+
const AXIS = 64;
|
|
11
|
+
const VOLUME_SHARE = .18;
|
|
12
|
+
const GAP = 8;
|
|
13
|
+
/** Scale from the shape's own top edge rather than its centre. */
|
|
14
|
+
const TOP_ORIGIN = {
|
|
15
|
+
originX: 0,
|
|
16
|
+
originY: 0
|
|
17
|
+
};
|
|
18
|
+
function CandlestickChartPlot({ height = 320, className }) {
|
|
19
|
+
const { candles, lastPrice, active, setActive, scale, formatPrice, label, reduce } = useCandlestickChart();
|
|
20
|
+
const ref = useRef(null);
|
|
21
|
+
const [width, setWidth] = useState(0);
|
|
22
|
+
const [pointerY, setPointerY] = useState(null);
|
|
23
|
+
useLayoutEffect(() => {
|
|
24
|
+
const node = ref.current;
|
|
25
|
+
if (!node) return;
|
|
26
|
+
const update = () => setWidth(node.clientWidth);
|
|
27
|
+
update();
|
|
28
|
+
const observer = new ResizeObserver(update);
|
|
29
|
+
observer.observe(node);
|
|
30
|
+
return () => observer.disconnect();
|
|
31
|
+
}, []);
|
|
32
|
+
const plotWidth = Math.max(0, width - AXIS);
|
|
33
|
+
const priceHeight = height * .8200000000000001 - GAP;
|
|
34
|
+
const slot = candles.length ? plotWidth / candles.length : 0;
|
|
35
|
+
const body = Math.max(1, slot * .62);
|
|
36
|
+
const y = (price) => (scale.max - price) / (scale.max - scale.min || 1) * priceHeight;
|
|
37
|
+
const priceAt = (py) => scale.max - py / priceHeight * (scale.max - scale.min);
|
|
38
|
+
const ticks = Array.from({ length: 5 }, (_, i) => scale.max - (scale.max - scale.min) * (i + .5) / 5);
|
|
39
|
+
const spring = reduce ? { duration: 0 } : SPRING_LAYOUT;
|
|
40
|
+
const onPointerMove = (event) => {
|
|
41
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
42
|
+
const x = event.clientX - rect.left;
|
|
43
|
+
const py = event.clientY - rect.top;
|
|
44
|
+
if (x > plotWidth || !slot) return;
|
|
45
|
+
setActive(Math.min(candles.length - 1, Math.max(0, Math.floor(x / slot))));
|
|
46
|
+
setPointerY(py <= priceHeight ? py : null);
|
|
47
|
+
};
|
|
48
|
+
const onKeyDown = (event) => {
|
|
49
|
+
const current = active ?? candles.length - 1;
|
|
50
|
+
let next = current;
|
|
51
|
+
if (event.key === "ArrowLeft") next = Math.max(0, current - 1);
|
|
52
|
+
else if (event.key === "ArrowRight") next = Math.min(candles.length - 1, current + 1);
|
|
53
|
+
else if (event.key === "Home") next = 0;
|
|
54
|
+
else if (event.key === "End") next = candles.length - 1;
|
|
55
|
+
else if (event.key === "Escape") next = null;
|
|
56
|
+
else return;
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
setPointerY(null);
|
|
59
|
+
setActive(next);
|
|
60
|
+
};
|
|
61
|
+
const focus = active !== null ? candles[active] : candles.at(-1);
|
|
62
|
+
const crossX = active !== null ? active * slot + slot / 2 : null;
|
|
63
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
64
|
+
ref,
|
|
65
|
+
role: "slider",
|
|
66
|
+
tabIndex: 0,
|
|
67
|
+
"aria-label": label,
|
|
68
|
+
"aria-valuemin": 0,
|
|
69
|
+
"aria-valuemax": Math.max(0, candles.length - 1),
|
|
70
|
+
"aria-valuenow": active ?? Math.max(0, candles.length - 1),
|
|
71
|
+
"aria-valuetext": focus ? `${focus.label}: open ${formatPrice(focus.open)}, high ${formatPrice(focus.high)}, low ${formatPrice(focus.low)}, close ${formatPrice(focus.close)}` : void 0,
|
|
72
|
+
onPointerMove,
|
|
73
|
+
onPointerLeave: () => {
|
|
74
|
+
setActive(null);
|
|
75
|
+
setPointerY(null);
|
|
76
|
+
},
|
|
77
|
+
onKeyDown,
|
|
78
|
+
onBlur: () => setActive(null),
|
|
79
|
+
className: cn("relative w-full cursor-crosshair touch-pan-y select-none rounded-xl outline-none focus-visible:ring-2 focus-visible:ring-ring", className),
|
|
80
|
+
style: { height },
|
|
81
|
+
children: [
|
|
82
|
+
width > 0 ? /* @__PURE__ */ jsxs("svg", {
|
|
83
|
+
width,
|
|
84
|
+
height,
|
|
85
|
+
className: "absolute inset-0 overflow-visible",
|
|
86
|
+
"aria-hidden": "true",
|
|
87
|
+
children: [
|
|
88
|
+
ticks.map((tick) => /* @__PURE__ */ jsx("line", {
|
|
89
|
+
x1: 0,
|
|
90
|
+
x2: plotWidth,
|
|
91
|
+
y1: y(tick),
|
|
92
|
+
y2: y(tick),
|
|
93
|
+
stroke: "var(--border)",
|
|
94
|
+
strokeDasharray: "2 6"
|
|
95
|
+
}, tick)),
|
|
96
|
+
candles.map((candle, index) => {
|
|
97
|
+
const up = candle.close >= candle.open;
|
|
98
|
+
const cx = index * slot + slot / 2;
|
|
99
|
+
const top = y(Math.max(candle.open, candle.close));
|
|
100
|
+
const bodyHeight = Math.max(1, Math.abs(y(candle.open) - y(candle.close)));
|
|
101
|
+
const wickTop = y(candle.high);
|
|
102
|
+
const wickHeight = Math.max(1, y(candle.low) - wickTop);
|
|
103
|
+
const volumeHeight = Math.max(.5, candle.volume / scale.volumeMax * height * VOLUME_SHARE);
|
|
104
|
+
const dimmed = active !== null && active !== index;
|
|
105
|
+
return /* @__PURE__ */ jsxs(motion.g, {
|
|
106
|
+
className: up ? "fill-emerald-500 stroke-emerald-500" : "fill-rose-500 stroke-rose-500",
|
|
107
|
+
initial: reduce ? false : { opacity: 0 },
|
|
108
|
+
animate: { opacity: dimmed ? .45 : 1 },
|
|
109
|
+
transition: {
|
|
110
|
+
duration: .3,
|
|
111
|
+
ease: EASE_OUT,
|
|
112
|
+
delay: reduce ? 0 : Math.min(index * .012, .6)
|
|
113
|
+
},
|
|
114
|
+
children: [
|
|
115
|
+
/* @__PURE__ */ jsx(motion.line, {
|
|
116
|
+
x1: cx,
|
|
117
|
+
x2: cx,
|
|
118
|
+
y1: 0,
|
|
119
|
+
y2: 1,
|
|
120
|
+
vectorEffect: "non-scaling-stroke",
|
|
121
|
+
strokeWidth: 1,
|
|
122
|
+
style: TOP_ORIGIN,
|
|
123
|
+
initial: false,
|
|
124
|
+
animate: {
|
|
125
|
+
y: wickTop,
|
|
126
|
+
scaleY: wickHeight
|
|
127
|
+
},
|
|
128
|
+
transition: spring
|
|
129
|
+
}),
|
|
130
|
+
/* @__PURE__ */ jsx(motion.rect, {
|
|
131
|
+
x: cx - body / 2,
|
|
132
|
+
y: 0,
|
|
133
|
+
width: body,
|
|
134
|
+
height: 1,
|
|
135
|
+
strokeWidth: 0,
|
|
136
|
+
style: TOP_ORIGIN,
|
|
137
|
+
initial: false,
|
|
138
|
+
animate: {
|
|
139
|
+
y: top,
|
|
140
|
+
scaleY: bodyHeight
|
|
141
|
+
},
|
|
142
|
+
transition: spring
|
|
143
|
+
}),
|
|
144
|
+
/* @__PURE__ */ jsx(motion.rect, {
|
|
145
|
+
x: cx - body / 2,
|
|
146
|
+
y: 0,
|
|
147
|
+
width: body,
|
|
148
|
+
height: 1,
|
|
149
|
+
strokeWidth: 0,
|
|
150
|
+
opacity: .28,
|
|
151
|
+
style: TOP_ORIGIN,
|
|
152
|
+
initial: false,
|
|
153
|
+
animate: {
|
|
154
|
+
y: height - volumeHeight,
|
|
155
|
+
scaleY: volumeHeight
|
|
156
|
+
},
|
|
157
|
+
transition: spring
|
|
158
|
+
})
|
|
159
|
+
]
|
|
160
|
+
}, candle.id);
|
|
161
|
+
}),
|
|
162
|
+
lastPrice !== void 0 ? /* @__PURE__ */ jsx(motion.line, {
|
|
163
|
+
x1: 0,
|
|
164
|
+
x2: plotWidth,
|
|
165
|
+
y1: 0,
|
|
166
|
+
y2: 0,
|
|
167
|
+
initial: false,
|
|
168
|
+
animate: { y: y(lastPrice) },
|
|
169
|
+
transition: spring,
|
|
170
|
+
stroke: "var(--foreground)",
|
|
171
|
+
strokeOpacity: .45,
|
|
172
|
+
strokeDasharray: "3 4"
|
|
173
|
+
}) : null,
|
|
174
|
+
crossX !== null ? /* @__PURE__ */ jsx("line", {
|
|
175
|
+
x1: crossX,
|
|
176
|
+
x2: crossX,
|
|
177
|
+
y1: 0,
|
|
178
|
+
y2: height,
|
|
179
|
+
stroke: "var(--foreground)",
|
|
180
|
+
strokeOpacity: .3
|
|
181
|
+
}) : null,
|
|
182
|
+
pointerY !== null ? /* @__PURE__ */ jsx("line", {
|
|
183
|
+
x1: 0,
|
|
184
|
+
x2: plotWidth,
|
|
185
|
+
y1: pointerY,
|
|
186
|
+
y2: pointerY,
|
|
187
|
+
stroke: "var(--foreground)",
|
|
188
|
+
strokeOpacity: .3
|
|
189
|
+
}) : null
|
|
190
|
+
]
|
|
191
|
+
}) : null,
|
|
192
|
+
width > 0 ? ticks.map((tick) => /* @__PURE__ */ jsx("span", {
|
|
193
|
+
className: "pointer-events-none absolute right-0 -translate-y-1/2 pr-1 font-mono text-muted-foreground text-xs tabular-nums",
|
|
194
|
+
style: { top: y(tick) },
|
|
195
|
+
children: formatPrice(tick)
|
|
196
|
+
}, tick)) : null,
|
|
197
|
+
width > 0 && lastPrice !== void 0 ? /* @__PURE__ */ jsx(motion.div, {
|
|
198
|
+
className: "pointer-events-none absolute top-0 right-0",
|
|
199
|
+
initial: false,
|
|
200
|
+
animate: { y: y(lastPrice) },
|
|
201
|
+
transition: spring,
|
|
202
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
203
|
+
className: "block -translate-y-1/2 rounded-md bg-foreground px-1.5 py-0.5 font-mono text-background text-xs tabular-nums",
|
|
204
|
+
children: formatPrice(lastPrice)
|
|
205
|
+
})
|
|
206
|
+
}) : null,
|
|
207
|
+
width > 0 && pointerY !== null ? /* @__PURE__ */ jsx("span", {
|
|
208
|
+
className: "pointer-events-none absolute right-0 -translate-y-1/2 rounded-md bg-muted px-1.5 py-0.5 font-mono text-foreground text-xs tabular-nums",
|
|
209
|
+
style: { top: pointerY },
|
|
210
|
+
children: formatPrice(priceAt(pointerY))
|
|
211
|
+
}) : null
|
|
212
|
+
]
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
216
|
+
export { CandlestickChartPlot };
|
|
217
|
+
|
|
218
|
+
//# sourceMappingURL=plot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plot.js","names":[],"sources":["../../../../src/components/charts/candlestick-chart/plot.tsx"],"sourcesContent":["\"use client\";\n\n/* Candles fade up 12ms apart on first draw. The live candle's body, wick, and\n * volume bar spring to new values as trades print, and the last-price line\n * follows. Pointer or arrow keys move a crosshair with a price tag on the\n * axis. Every moving shape is drawn at unit height and placed with\n * translateY and scaleY, so updates animate transforms only. Reduced motion:\n * no fade or spring; values update in place. */\n\nimport { type KeyboardEvent, type PointerEvent, useLayoutEffect, useRef, useState } from \"react\";\nimport { motion, type Transition } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_LAYOUT } from \"../../../lib/ease\";\nimport { useCandlestickChart } from \"./context\";\n\n/** Right gutter reserved for price labels, in px. */\nconst AXIS = 64;\nconst VOLUME_SHARE = 0.18;\nconst GAP = 8;\n/** Scale from the shape's own top edge rather than its centre. */\nconst TOP_ORIGIN = { originX: 0, originY: 0 } as const;\n\nexport type CandlestickChartPlotProps = {\n /** Plot height in px. */\n height?: number;\n className?: string;\n};\n\nexport function CandlestickChartPlot({ height = 320, className }: CandlestickChartPlotProps) {\n const { candles, lastPrice, active, setActive, scale, formatPrice, label, reduce } =\n useCandlestickChart();\n const ref = useRef<HTMLDivElement>(null);\n const [width, setWidth] = useState(0);\n const [pointerY, setPointerY] = useState<number | null>(null);\n\n useLayoutEffect(() => {\n const node = ref.current;\n if (!node) return;\n const update = () => setWidth(node.clientWidth);\n update();\n const observer = new ResizeObserver(update);\n observer.observe(node);\n return () => observer.disconnect();\n }, []);\n\n const plotWidth = Math.max(0, width - AXIS);\n const priceHeight = height * (1 - VOLUME_SHARE) - GAP;\n const slot = candles.length ? plotWidth / candles.length : 0;\n const body = Math.max(1, slot * 0.62);\n const y = (price: number) => ((scale.max - price) / (scale.max - scale.min || 1)) * priceHeight;\n const priceAt = (py: number) => scale.max - (py / priceHeight) * (scale.max - scale.min);\n const ticks = Array.from(\n { length: 5 },\n (_, i) => scale.max - ((scale.max - scale.min) * (i + 0.5)) / 5,\n );\n const spring: Transition = reduce ? { duration: 0 } : SPRING_LAYOUT;\n\n const onPointerMove = (event: PointerEvent<HTMLDivElement>) => {\n const rect = event.currentTarget.getBoundingClientRect();\n const x = event.clientX - rect.left;\n const py = event.clientY - rect.top;\n if (x > plotWidth || !slot) return;\n setActive(Math.min(candles.length - 1, Math.max(0, Math.floor(x / slot))));\n setPointerY(py <= priceHeight ? py : null);\n };\n\n const onKeyDown = (event: KeyboardEvent) => {\n const current = active ?? candles.length - 1;\n let next: number | null = current;\n if (event.key === \"ArrowLeft\") next = Math.max(0, current - 1);\n else if (event.key === \"ArrowRight\") next = Math.min(candles.length - 1, current + 1);\n else if (event.key === \"Home\") next = 0;\n else if (event.key === \"End\") next = candles.length - 1;\n else if (event.key === \"Escape\") next = null;\n else return;\n event.preventDefault();\n setPointerY(null);\n setActive(next);\n };\n\n const focus = active !== null ? candles[active] : candles.at(-1);\n const crossX = active !== null ? active * slot + slot / 2 : null;\n\n return (\n <div\n ref={ref}\n role=\"slider\"\n tabIndex={0}\n aria-label={label}\n aria-valuemin={0}\n aria-valuemax={Math.max(0, candles.length - 1)}\n aria-valuenow={active ?? Math.max(0, candles.length - 1)}\n aria-valuetext={\n focus\n ? `${focus.label}: open ${formatPrice(focus.open)}, high ${formatPrice(focus.high)}, low ${formatPrice(focus.low)}, close ${formatPrice(focus.close)}`\n : undefined\n }\n onPointerMove={onPointerMove}\n onPointerLeave={() => {\n setActive(null);\n setPointerY(null);\n }}\n onKeyDown={onKeyDown}\n onBlur={() => setActive(null)}\n className={cn(\n \"relative w-full cursor-crosshair touch-pan-y select-none rounded-xl outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n className,\n )}\n style={{ height }}\n >\n {width > 0 ? (\n <svg\n width={width}\n height={height}\n className=\"absolute inset-0 overflow-visible\"\n aria-hidden=\"true\"\n >\n {ticks.map((tick) => (\n <line\n key={tick}\n x1={0}\n x2={plotWidth}\n y1={y(tick)}\n y2={y(tick)}\n stroke=\"var(--border)\"\n strokeDasharray=\"2 6\"\n />\n ))}\n {candles.map((candle, index) => {\n const up = candle.close >= candle.open;\n const cx = index * slot + slot / 2;\n const top = y(Math.max(candle.open, candle.close));\n const bodyHeight = Math.max(1, Math.abs(y(candle.open) - y(candle.close)));\n const wickTop = y(candle.high);\n const wickHeight = Math.max(1, y(candle.low) - wickTop);\n const volumeHeight = Math.max(\n 0.5,\n (candle.volume / scale.volumeMax) * height * VOLUME_SHARE,\n );\n const dimmed = active !== null && active !== index;\n return (\n <motion.g\n key={candle.id}\n className={\n up ? \"fill-emerald-500 stroke-emerald-500\" : \"fill-rose-500 stroke-rose-500\"\n }\n initial={reduce ? false : { opacity: 0 }}\n animate={{ opacity: dimmed ? 0.45 : 1 }}\n transition={{\n duration: 0.3,\n ease: EASE_OUT,\n delay: reduce ? 0 : Math.min(index * 0.012, 0.6),\n }}\n >\n <motion.line\n x1={cx}\n x2={cx}\n y1={0}\n y2={1}\n vectorEffect=\"non-scaling-stroke\"\n strokeWidth={1}\n style={TOP_ORIGIN}\n initial={false}\n animate={{ y: wickTop, scaleY: wickHeight }}\n transition={spring}\n />\n <motion.rect\n x={cx - body / 2}\n y={0}\n width={body}\n height={1}\n strokeWidth={0}\n style={TOP_ORIGIN}\n initial={false}\n animate={{ y: top, scaleY: bodyHeight }}\n transition={spring}\n />\n <motion.rect\n x={cx - body / 2}\n y={0}\n width={body}\n height={1}\n strokeWidth={0}\n opacity={0.28}\n style={TOP_ORIGIN}\n initial={false}\n animate={{ y: height - volumeHeight, scaleY: volumeHeight }}\n transition={spring}\n />\n </motion.g>\n );\n })}\n {lastPrice !== undefined ? (\n <motion.line\n x1={0}\n x2={plotWidth}\n y1={0}\n y2={0}\n initial={false}\n animate={{ y: y(lastPrice) }}\n transition={spring}\n stroke=\"var(--foreground)\"\n strokeOpacity={0.45}\n strokeDasharray=\"3 4\"\n />\n ) : null}\n {crossX !== null ? (\n <line\n x1={crossX}\n x2={crossX}\n y1={0}\n y2={height}\n stroke=\"var(--foreground)\"\n strokeOpacity={0.3}\n />\n ) : null}\n {pointerY !== null ? (\n <line\n x1={0}\n x2={plotWidth}\n y1={pointerY}\n y2={pointerY}\n stroke=\"var(--foreground)\"\n strokeOpacity={0.3}\n />\n ) : null}\n </svg>\n ) : null}\n\n {width > 0\n ? ticks.map((tick) => (\n <span\n key={tick}\n className=\"pointer-events-none absolute right-0 -translate-y-1/2 pr-1 font-mono text-muted-foreground text-xs tabular-nums\"\n style={{ top: y(tick) }}\n >\n {formatPrice(tick)}\n </span>\n ))\n : null}\n {width > 0 && lastPrice !== undefined ? (\n <motion.div\n className=\"pointer-events-none absolute top-0 right-0\"\n initial={false}\n animate={{ y: y(lastPrice) }}\n transition={spring}\n >\n <span className=\"block -translate-y-1/2 rounded-md bg-foreground px-1.5 py-0.5 font-mono text-background text-xs tabular-nums\">\n {formatPrice(lastPrice)}\n </span>\n </motion.div>\n ) : null}\n {width > 0 && pointerY !== null ? (\n <span\n className=\"pointer-events-none absolute right-0 -translate-y-1/2 rounded-md bg-muted px-1.5 py-0.5 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ClB,CAAA;GACI,CAAA,IACV;GACH,QAAQ,KAAK,aAAa,OACzB,oBAAC,QAAD;IACE,WAAU;IACV,OAAO,EAAE,KAAK,SAAS;IAEtB,UAAA,YAAY,QAAQ,QAAQ,CAAC;GAC1B,CAAA,IACJ;EACD;;AAET"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Candle, CandlestickChartProps, useCandlestickChart } from "./candlestick-chart/context.js";
|
|
2
|
+
import { CandlestickChartLegend, CandlestickChartLegendProps } from "./candlestick-chart/legend.js";
|
|
3
|
+
import { CandlestickChartPlot, CandlestickChartPlotProps } from "./candlestick-chart/plot.js";
|
|
4
|
+
//#region src/components/charts/candlestick-chart.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* OHLC candles with volume, a last-price line, and a crosshair readout.
|
|
7
|
+
*
|
|
8
|
+
* ```tsx
|
|
9
|
+
* <CandlestickChart candles={candles} lastPrice={last} formatPrice={usd}>
|
|
10
|
+
* <CandlestickChartLegend />
|
|
11
|
+
* <CandlestickChartPlot height={360} />
|
|
12
|
+
* </CandlestickChart>
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function CandlestickChart({ className, children, ...props }: CandlestickChartProps): import("react").JSX.Element;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { type Candle, CandlestickChartLegend, type CandlestickChartLegendProps, CandlestickChartPlot, type CandlestickChartPlotProps, type CandlestickChartProps, useCandlestickChart };
|
|
18
|
+
//# sourceMappingURL=candlestick-chart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"candlestick-chart.d.ts","names":[],"sources":["../../../src/components/charts/candlestick-chart.tsx"],"mappings":";;;;;;;;;;;;;;wBAqBgB,mBAAmB,WAAW,aAAa,SAAS,wCAAqB,IAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { CandlestickContext, useCandlestickChart, useCandlestickModel } from "./candlestick-chart/context.js";
|
|
3
|
+
import { CandlestickChartLegend } from "./candlestick-chart/legend.js";
|
|
4
|
+
import { CandlestickChartPlot } from "./candlestick-chart/plot.js";
|
|
5
|
+
import { cn } from "@kumix/utils";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
//#region src/components/charts/candlestick-chart.tsx
|
|
8
|
+
/**
|
|
9
|
+
* OHLC candles with volume, a last-price line, and a crosshair readout.
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <CandlestickChart candles={candles} lastPrice={last} formatPrice={usd}>
|
|
13
|
+
* <CandlestickChartLegend />
|
|
14
|
+
* <CandlestickChartPlot height={360} />
|
|
15
|
+
* </CandlestickChart>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
function CandlestickChart({ className, children, ...props }) {
|
|
19
|
+
const model = useCandlestickModel(props);
|
|
20
|
+
return /* @__PURE__ */ jsx(CandlestickContext.Provider, {
|
|
21
|
+
value: model,
|
|
22
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
23
|
+
className: cn("w-full", className),
|
|
24
|
+
children: children ?? /* @__PURE__ */ jsxs("div", {
|
|
25
|
+
className: "grid gap-3",
|
|
26
|
+
children: [/* @__PURE__ */ jsx(CandlestickChartLegend, {}), /* @__PURE__ */ jsx(CandlestickChartPlot, {})]
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { CandlestickChart, CandlestickChartLegend, CandlestickChartPlot, useCandlestickChart };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=candlestick-chart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"candlestick-chart.js","names":[],"sources":["../../../src/components/charts/candlestick-chart.tsx"],"sourcesContent":["\"use client\";\n\nimport { cn } from \"@kumix/utils\";\nimport {\n type CandlestickChartProps,\n CandlestickContext,\n useCandlestickModel,\n} from \"./candlestick-chart/context\";\nimport { CandlestickChartLegend } from \"./candlestick-chart/legend\";\nimport { CandlestickChartPlot } from \"./candlestick-chart/plot\";\n\n/**\n * OHLC candles with volume, a last-price line, and a crosshair readout.\n *\n * ```tsx\n * <CandlestickChart candles={candles} lastPrice={last} formatPrice={usd}>\n * <CandlestickChartLegend />\n * <CandlestickChartPlot height={360} />\n * </CandlestickChart>\n * ```\n */\nexport function CandlestickChart({ className, children, ...props }: CandlestickChartProps) {\n const model = useCandlestickModel(props);\n return (\n <CandlestickContext.Provider value={model}>\n <div className={cn(\"w-full\", className)}>\n {children ?? (\n <div className=\"grid gap-3\">\n <CandlestickChartLegend />\n <CandlestickChartPlot />\n </div>\n )}\n </div>\n </CandlestickContext.Provider>\n );\n}\n\nexport {\n type Candle,\n type CandlestickChartProps,\n useCandlestickChart,\n} from \"./candlestick-chart/context\";\nexport {\n CandlestickChartLegend,\n type CandlestickChartLegendProps,\n} from \"./candlestick-chart/legend\";\nexport {\n CandlestickChartPlot,\n type CandlestickChartPlotProps,\n} from \"./candlestick-chart/plot\";\n"],"mappings":";;;;;;;;;;;;;;;;;AAqBA,SAAgB,iBAAiB,EAAE,WAAW,UAAU,GAAG,SAAgC;CACzF,MAAM,QAAQ,oBAAoB,KAAK;CACvC,OACE,oBAAC,mBAAmB,UAApB;EAA6B,OAAO;EAClC,UAAA,oBAAC,OAAD;GAAK,WAAW,GAAG,UAAU,SAAS;GACnC,UAAA,YACC,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACE,oBAAC,wBAAD,CAAyB,CAAA,GACzB,oBAAC,sBAAD,CAAuB,CAAA,CACpB;;EAEJ,CAAA;CACsB,CAAA;AAEjC"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
export { CompositionContext, useCompositionChart, useCompositionModel };
|
|
2
|
+
export { t as CompositionContext, n as useCompositionChart, r as useCompositionModel } from "../../../context-sD8DQga-.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { SPRING_LAYOUT } from "../../../lib/ease.js";
|
|
3
|
-
import { Tooltip } from "
|
|
3
|
+
import { t as Tooltip } from "../../../tooltip-Bam5KeYe.js";
|
|
4
4
|
import { i as compositionArea, n as useCompositionChart } from "../../../context-sD8DQga-.js";
|
|
5
5
|
import { CompositionTooltipContent } from "./tooltip-content.js";
|
|
6
6
|
import { useId, useRef, useState } from "react";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { n as PlacedSegment } from "../../../model-_mRyI6V9.js";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
//#region src/components/charts/donut-chart/center.d.ts
|
|
4
|
+
export type DonutChartCenterProps = {
|
|
5
|
+
/**
|
|
6
|
+
* Custom content for the hole. Receives the focused segment, or null when
|
|
7
|
+
* nothing is focused, and the total. Defaults to a rolling value and caption.
|
|
8
|
+
*/
|
|
9
|
+
children?: (segment: PlacedSegment | null, total: number) => ReactNode;
|
|
10
|
+
/** Caption under the total when nothing is focused. */
|
|
11
|
+
totalLabel?: ReactNode;
|
|
12
|
+
className?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function DonutChartCenter({ children, totalLabel, className }: DonutChartCenterProps): import("react").JSX.Element;
|
|
15
|
+
//#endregion
|
|
16
|
+
//# sourceMappingURL=center.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"center.d.ts","names":[],"sources":["../../../../src/components/charts/donut-chart/center.tsx"],"mappings":";;;YAgBY;;;;;EAKV,YAAY,SAAS,sBAAsB,kBAAkB;;EAE7D,aAAa;EACb;;wBAGc,mBACd,UACA,YACA,aACC,wCAAqB,IAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { EASE_OUT } from "../../../lib/ease.js";
|
|
3
|
+
import { DigitSwap } from "../../motion/digit-swap.js";
|
|
4
|
+
import { n as useDonutChart } from "../../../context-tTdLKYNf.js";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { cn } from "@kumix/utils";
|
|
7
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { AnimatePresence, motion } from "motion/react";
|
|
9
|
+
//#region src/components/charts/donut-chart/center.tsx
|
|
10
|
+
function DonutChartCenter({ children, totalLabel = "Total", className }) {
|
|
11
|
+
const { placed, active, total, formatValue, reduce } = useDonutChart();
|
|
12
|
+
const segment = placed.find((item) => item.id === active) ?? null;
|
|
13
|
+
const value = segment?.value ?? total;
|
|
14
|
+
const [previous, setPrevious] = useState(value);
|
|
15
|
+
const [direction, setDirection] = useState("up");
|
|
16
|
+
if (value !== previous) {
|
|
17
|
+
setPrevious(value);
|
|
18
|
+
setDirection(value > previous ? "up" : "down");
|
|
19
|
+
}
|
|
20
|
+
if (children) return /* @__PURE__ */ jsx("div", {
|
|
21
|
+
"aria-live": "polite",
|
|
22
|
+
className: cn("relative max-w-[56%]", className),
|
|
23
|
+
children: children(segment, total)
|
|
24
|
+
});
|
|
25
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
26
|
+
"aria-live": "polite",
|
|
27
|
+
className: cn("relative max-w-[56%]", className),
|
|
28
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
29
|
+
className: "font-medium text-2xl tabular-nums tracking-tight",
|
|
30
|
+
children: /* @__PURE__ */ jsx(DigitSwap, {
|
|
31
|
+
value: formatValue(value),
|
|
32
|
+
direction
|
|
33
|
+
})
|
|
34
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
35
|
+
className: "relative mt-1 h-4 overflow-hidden",
|
|
36
|
+
children: /* @__PURE__ */ jsx(AnimatePresence, {
|
|
37
|
+
initial: false,
|
|
38
|
+
mode: "popLayout",
|
|
39
|
+
children: /* @__PURE__ */ jsx(motion.p, {
|
|
40
|
+
initial: reduce ? { opacity: 0 } : {
|
|
41
|
+
opacity: 0,
|
|
42
|
+
y: "100%"
|
|
43
|
+
},
|
|
44
|
+
animate: {
|
|
45
|
+
opacity: 1,
|
|
46
|
+
y: "0%"
|
|
47
|
+
},
|
|
48
|
+
exit: reduce ? { opacity: 0 } : {
|
|
49
|
+
opacity: 0,
|
|
50
|
+
y: "-100%"
|
|
51
|
+
},
|
|
52
|
+
transition: {
|
|
53
|
+
duration: reduce ? .12 : .22,
|
|
54
|
+
ease: EASE_OUT
|
|
55
|
+
},
|
|
56
|
+
className: "flex items-center justify-center gap-1.5 whitespace-nowrap text-muted-foreground text-xs leading-4",
|
|
57
|
+
children: segment ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
|
|
58
|
+
"aria-hidden": "true",
|
|
59
|
+
className: "size-2 shrink-0 rounded-full",
|
|
60
|
+
style: { backgroundColor: segment.color }
|
|
61
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
62
|
+
className: "truncate",
|
|
63
|
+
children: [
|
|
64
|
+
segment.name,
|
|
65
|
+
" · ",
|
|
66
|
+
(segment.share * 100).toFixed(1),
|
|
67
|
+
"%"
|
|
68
|
+
]
|
|
69
|
+
})] }) : totalLabel
|
|
70
|
+
}, segment?.id ?? "total")
|
|
71
|
+
})
|
|
72
|
+
})]
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
export { DonutChartCenter };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=center.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"center.js","names":[],"sources":["../../../../src/components/charts/donut-chart/center.tsx"],"sourcesContent":["\"use client\";\n\n/* The value rolls digit by digit (up when it grows, down when it shrinks) in\n * a stable container, and the caption slides through a clipped line, so\n * moving between segments reads as one readout updating rather than a\n * replaced block. Reduced motion: both swap with a short fade. */\n\nimport { type ReactNode, useState } from \"react\";\nimport { AnimatePresence, motion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT } from \"../../../lib/ease\";\nimport { DigitSwap } from \"../../motion/digit-swap\";\nimport { useDonutChart } from \"./context\";\nimport type { PlacedSegment } from \"./model\";\n\nexport type DonutChartCenterProps = {\n /**\n * Custom content for the hole. Receives the focused segment, or null when\n * nothing is focused, and the total. Defaults to a rolling value and caption.\n */\n children?: (segment: PlacedSegment | null, total: number) => ReactNode;\n /** Caption under the total when nothing is focused. */\n totalLabel?: ReactNode;\n className?: string;\n};\n\nexport function DonutChartCenter({\n children,\n totalLabel = \"Total\",\n className,\n}: DonutChartCenterProps) {\n const { placed, active, total, formatValue, reduce } = useDonutChart();\n const segment = placed.find((item) => item.id === active) ?? null;\n const value = segment?.value ?? total;\n // Roll digits in the direction the value moved, adjusted during render so\n // the first frame of a change already rolls the right way.\n const [previous, setPrevious] = useState(value);\n const [direction, setDirection] = useState<\"up\" | \"down\">(\"up\");\n if (value !== previous) {\n setPrevious(value);\n setDirection(value > previous ? \"up\" : \"down\");\n }\n\n if (children) {\n return (\n <div aria-live=\"polite\" className={cn(\"relative max-w-[56%]\", className)}>\n {children(segment, total)}\n </div>\n );\n }\n\n return (\n <div aria-live=\"polite\" className={cn(\"relative max-w-[56%]\", className)}>\n <p className=\"font-medium text-2xl tabular-nums tracking-tight\">\n <DigitSwap value={formatValue(value)} direction={direction} />\n </p>\n <div className=\"relative mt-1 h-4 overflow-hidden\">\n <AnimatePresence initial={false} mode=\"popLayout\">\n <motion.p\n key={segment?.id ?? \"total\"}\n initial={reduce ? { opacity: 0 } : { opacity: 0, y: \"100%\" }}\n animate={{ opacity: 1, y: \"0%\" }}\n exit={reduce ? { opacity: 0 } : { opacity: 0, y: \"-100%\" }}\n transition={{ duration: reduce ? 0.12 : 0.22, ease: EASE_OUT }}\n className=\"flex items-center justify-center gap-1.5 whitespace-nowrap text-muted-foreground text-xs leading-4\"\n >\n {segment ? (\n <>\n <span\n aria-hidden=\"true\"\n className=\"size-2 shrink-0 rounded-full\"\n style={{ backgroundColor: segment.color }}\n />\n <span className=\"truncate\">\n {segment.name} · {(segment.share * 100).toFixed(1)}%\n </span>\n </>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