@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
|
@@ -42,7 +42,7 @@ declare function SidebarMenu({ className, ...props }: React$1.ComponentProps<"ul
|
|
|
42
42
|
declare function SidebarMenuItem({ className, ...props }: React$1.ComponentProps<"li">): React$1.JSX.Element;
|
|
43
43
|
declare const sidebarMenuButtonVariants: (props?: ({
|
|
44
44
|
variant?: "outline" | "default" | null | undefined;
|
|
45
|
-
size?: "
|
|
45
|
+
size?: "sm" | "lg" | "default" | null | undefined;
|
|
46
46
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
47
47
|
declare function SidebarMenuButton({ render, isActive, variant, size, tooltip, className, ...props }: useRender.ComponentProps<"button"> & React$1.ComponentProps<"button"> & {
|
|
48
48
|
isActive?: boolean;
|
|
@@ -3,8 +3,8 @@ import { useIsMobile } from "../../hooks/use-mobile.js";
|
|
|
3
3
|
import { Button } from "./button.js";
|
|
4
4
|
import { Input } from "./input.js";
|
|
5
5
|
import { Separator } from "./separator.js";
|
|
6
|
-
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "./sheet.js";
|
|
7
6
|
import { Skeleton } from "./skeleton.js";
|
|
7
|
+
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "./sheet.js";
|
|
8
8
|
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
|
|
9
9
|
import * as React$1 from "react";
|
|
10
10
|
import { cn } from "@kumix/utils";
|
|
@@ -3,7 +3,7 @@ import { Toggle as Toggle$1 } from "@base-ui/react/toggle";
|
|
|
3
3
|
//#region src/components/ui/toggle.d.ts
|
|
4
4
|
declare const toggleVariants: (props?: ({
|
|
5
5
|
variant?: "outline" | "default" | null | undefined;
|
|
6
|
-
size?: "
|
|
6
|
+
size?: "sm" | "lg" | "default" | null | undefined;
|
|
7
7
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
8
8
|
declare function Toggle({ className, variant, size, ...props }: Toggle$1.Props & VariantProps<typeof toggleVariants>): import("react").JSX.Element;
|
|
9
9
|
//#endregion
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useHoverCapable } from "./hooks/use-hover-capable.js";
|
|
2
|
+
import { createContext, useCallback, useContext, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
import { useReducedMotion } from "motion/react";
|
|
4
|
+
const CENTER = 100;
|
|
5
|
+
const point = (radius, degrees) => {
|
|
6
|
+
const radians = degrees * Math.PI / 180;
|
|
7
|
+
return [CENTER + radius * Math.sin(radians), CENTER - radius * Math.cos(radians)];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Lays segments clockwise from 12 o'clock as round-capped arcs. Each arc is
|
|
11
|
+
* shortened by the gap plus its own cap, so neighbouring pills keep an even
|
|
12
|
+
* gap. Arcs too small for their caps collapse to a dot.
|
|
13
|
+
*/
|
|
14
|
+
function buildDonut(segments, { radius, thickness, gap }) {
|
|
15
|
+
const valid = segments.filter((segment) => Number.isFinite(segment.value) && segment.value > 0);
|
|
16
|
+
const total = valid.reduce((sum, segment) => sum + segment.value, 0);
|
|
17
|
+
const capDegrees = thickness / 2 / radius * (180 / Math.PI);
|
|
18
|
+
const single = valid.length === 1;
|
|
19
|
+
let cursor = 0;
|
|
20
|
+
return {
|
|
21
|
+
placed: valid.map((segment) => {
|
|
22
|
+
const share = total ? segment.value / total : 0;
|
|
23
|
+
const sweep = share * 360;
|
|
24
|
+
const inset = single ? 0 : gap / 2 + capDegrees;
|
|
25
|
+
const start = cursor + inset;
|
|
26
|
+
const end = Math.max(start + .01, cursor + sweep - inset);
|
|
27
|
+
cursor += sweep;
|
|
28
|
+
let path;
|
|
29
|
+
if (single) {
|
|
30
|
+
const [x1, y1] = point(radius, 0);
|
|
31
|
+
const [x2, y2] = point(radius, 180);
|
|
32
|
+
path = `M ${x1} ${y1} A ${radius} ${radius} 0 1 1 ${x2} ${y2} A ${radius} ${radius} 0 1 1 ${x1} ${y1}`;
|
|
33
|
+
} else {
|
|
34
|
+
const [x1, y1] = point(radius, start);
|
|
35
|
+
const [x2, y2] = point(radius, end);
|
|
36
|
+
path = `M ${x1} ${y1} A ${radius} ${radius} 0 ${end - start > 180 ? 1 : 0} 1 ${x2} ${y2}`;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
...segment,
|
|
40
|
+
share,
|
|
41
|
+
path
|
|
42
|
+
};
|
|
43
|
+
}),
|
|
44
|
+
total
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/components/charts/donut-chart/context.tsx
|
|
49
|
+
const defaultFormat = (value) => value.toLocaleString("en-US");
|
|
50
|
+
function useDonutModel({ segments, thickness = 22, gap = 3, activeId, defaultActiveId = null, onActiveChange, onSelect, selectedId = null, formatValue = defaultFormat, label = "Donut chart" }) {
|
|
51
|
+
const reduce = useReducedMotion() ?? false;
|
|
52
|
+
const canHover = useHoverCapable();
|
|
53
|
+
const radius = 100 - thickness / 2 - 8;
|
|
54
|
+
const { placed, total } = buildDonut(segments, {
|
|
55
|
+
radius,
|
|
56
|
+
thickness,
|
|
57
|
+
gap
|
|
58
|
+
});
|
|
59
|
+
const [internal, setInternal] = useState(defaultActiveId);
|
|
60
|
+
const raw = activeId === void 0 ? internal : activeId;
|
|
61
|
+
const active = raw !== null && placed.some((segment) => segment.id === raw) ? raw : null;
|
|
62
|
+
const latest = useRef({
|
|
63
|
+
controlled: activeId !== void 0,
|
|
64
|
+
onActiveChange
|
|
65
|
+
});
|
|
66
|
+
useLayoutEffect(() => {
|
|
67
|
+
latest.current = {
|
|
68
|
+
controlled: activeId !== void 0,
|
|
69
|
+
onActiveChange
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
placed,
|
|
74
|
+
total,
|
|
75
|
+
radius,
|
|
76
|
+
thickness,
|
|
77
|
+
active,
|
|
78
|
+
setActive: useCallback((id) => {
|
|
79
|
+
if (!latest.current.controlled) setInternal(id);
|
|
80
|
+
latest.current.onActiveChange?.(id);
|
|
81
|
+
}, []),
|
|
82
|
+
onSelect,
|
|
83
|
+
selectedId,
|
|
84
|
+
formatValue,
|
|
85
|
+
label,
|
|
86
|
+
reduce,
|
|
87
|
+
canHover
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const DonutContext = createContext(null);
|
|
91
|
+
function useDonutChart() {
|
|
92
|
+
const model = useContext(DonutContext);
|
|
93
|
+
if (!model) throw new Error("Donut chart parts must be rendered inside DonutChart.");
|
|
94
|
+
return model;
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
export { useDonutChart as n, useDonutModel as r, DonutContext as t };
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=context-tTdLKYNf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-tTdLKYNf.js","names":[],"sources":["../src/components/charts/donut-chart/model.ts","../src/components/charts/donut-chart/context.tsx"],"sourcesContent":["export interface DonutSegment {\n id: string;\n name: string;\n /** Any CSS color, such as \"#2563eb\" or \"var(--chart-1)\". */\n color: string;\n /** Nonnegative value. Zero and invalid values are left out of the ring. */\n value: number;\n}\n\nexport type PlacedSegment = DonutSegment & {\n /** Share of the total, from 0 to 1. */\n share: number;\n /** Centerline arc path in the 200 × 200 viewBox. */\n path: string;\n};\n\nexport const DONUT_SIZE = 200;\nconst CENTER = DONUT_SIZE / 2;\n\nconst point = (radius: number, degrees: number) => {\n const radians = (degrees * Math.PI) / 180;\n return [CENTER + radius * Math.sin(radians), CENTER - radius * Math.cos(radians)];\n};\n\n/**\n * Lays segments clockwise from 12 o'clock as round-capped arcs. Each arc is\n * shortened by the gap plus its own cap, so neighbouring pills keep an even\n * gap. Arcs too small for their caps collapse to a dot.\n */\nexport function buildDonut(\n segments: readonly DonutSegment[],\n { radius, thickness, gap }: { radius: number; thickness: number; gap: number },\n) {\n const valid = segments.filter((segment) => Number.isFinite(segment.value) && segment.value > 0);\n const total = valid.reduce((sum, segment) => sum + segment.value, 0);\n const capDegrees = (thickness / 2 / radius) * (180 / Math.PI);\n const single = valid.length === 1;\n let cursor = 0;\n const placed: PlacedSegment[] = valid.map((segment) => {\n const share = total ? segment.value / total : 0;\n const sweep = share * 360;\n const inset = single ? 0 : gap / 2 + capDegrees;\n const start = cursor + inset;\n const end = Math.max(start + 0.01, cursor + sweep - inset);\n cursor += sweep;\n let path: string;\n if (single) {\n // A full ring needs two half arcs; one arc cannot start and end together.\n const [x1, y1] = point(radius, 0);\n const [x2, y2] = point(radius, 180);\n path = `M ${x1} ${y1} A ${radius} ${radius} 0 1 1 ${x2} ${y2} A ${radius} ${radius} 0 1 1 ${x1} ${y1}`;\n } else {\n const [x1, y1] = point(radius, start);\n const [x2, y2] = point(radius, end);\n path = `M ${x1} ${y1} A ${radius} ${radius} 0 ${end - start > 180 ? 1 : 0} 1 ${x2} ${y2}`;\n }\n return { ...segment, share, path };\n });\n return { placed, total };\n}\n","\"use client\";\n\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { useReducedMotion } from \"motion/react\";\n\nimport { useHoverCapable } from \"../../../hooks/use-hover-capable\";\nimport { buildDonut, type DonutSegment } from \"./model\";\n\nexport interface DonutChartProps {\n segments: readonly DonutSegment[];\n /** Ring thickness in viewBox units; the chart is 200 wide. */\n thickness?: number;\n /** Degrees of empty space between neighbouring segments. */\n gap?: number;\n /** Focused segment, shared by the ring, center, and legend. Controlled. */\n activeId?: string | null;\n defaultActiveId?: string | null;\n onActiveChange?: (id: string | null) => void;\n /** Called when a legend item is clicked. */\n onSelect?: (id: string) => void;\n /** Marks a legend item as pressed. */\n selectedId?: string | null;\n formatValue?: (value: number) => string;\n /** Accessible name for the chart. */\n label?: string;\n className?: string;\n children?: ReactNode;\n}\n\nconst defaultFormat = (value: number) => value.toLocaleString(\"en-US\");\n\nexport function useDonutModel({\n segments,\n thickness = 22,\n gap = 3,\n activeId,\n defaultActiveId = null,\n onActiveChange,\n onSelect,\n selectedId = null,\n formatValue = defaultFormat,\n label = \"Donut chart\",\n}: DonutChartProps) {\n const reduce = useReducedMotion() ?? false;\n const canHover = useHoverCapable();\n const radius = 100 - thickness / 2 - 8;\n const { placed, total } = buildDonut(segments, { radius, thickness, gap });\n\n const [internal, setInternal] = useState(defaultActiveId);\n const raw = activeId === undefined ? internal : activeId;\n // Resolve during render by id; a segment that left the data clears focus.\n const active = raw !== null && placed.some((segment) => segment.id === raw) ? raw : null;\n\n const latest = useRef({ controlled: activeId !== undefined, onActiveChange });\n useLayoutEffect(() => {\n latest.current = { controlled: activeId !== undefined, onActiveChange };\n });\n const setActive = useCallback((id: string | null) => {\n if (!latest.current.controlled) setInternal(id);\n latest.current.onActiveChange?.(id);\n }, []);\n\n return {\n placed,\n total,\n radius,\n thickness,\n active,\n setActive,\n onSelect,\n selectedId,\n formatValue,\n label,\n reduce,\n canHover,\n };\n}\n\nexport type DonutModel = ReturnType<typeof useDonutModel>;\nexport const DonutContext = createContext<DonutModel | null>(null);\n\nexport function useDonutChart() {\n const model = useContext(DonutContext);\n if (!model) throw new Error(\"Donut chart parts must be rendered inside DonutChart.\");\n return model;\n}\n"],"mappings":";;;AAiBA,MAAM,SAAA;AAEN,MAAM,SAAS,QAAgB,YAAoB;CACjD,MAAM,UAAW,UAAU,KAAK,KAAM;CACtC,OAAO,CAAC,SAAS,SAAS,KAAK,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e,OAAO;AAErE,SAAgB,cAAc,EAC5B,UACA,YAAY,IACZ,MAAM,GACN,UACA,kBAAkB,MAClB,gBACA,UACA,aAAa,MACb,cAAc,eACd,QAAQ,iBACU;CAClB,MAAM,SAAS,iBAAiB,KAAK;CACrC,MAAM,WAAW,gBAAgB;CACjC,MAAM,SAAS,MAAM,YAAY,IAAI;CACrC,MAAM,EAAE,QAAQ,UAAU,WAAW,UAAU;EAAE;EAAQ;EAAW;CAAI,CAAC;CAEzE,MAAM,CAAC,UAAU,eAAe,SAAS,eAAe;CACxD,MAAM,MAAM,aAAa,KAAA,IAAY,WAAW;CAEhD,MAAM,SAAS,QAAQ,QAAQ,OAAO,MAAM,YAAY,QAAQ,OAAO,GAAG,IAAI,MAAM;CAEpF,MAAM,SAAS,OAAO;EAAE,YAAY,aAAa,KAAA;EAAW;CAAe,CAAC;CAC5E,sBAAsB;EACpB,OAAO,UAAU;GAAE,YAAY,aAAa,KAAA;GAAW;EAAe;CACxE,CAAC;CAMD,OAAO;EACL;EACA;EACA;EACA;EACA;EACA,WAXgB,aAAa,OAAsB;GACnD,IAAI,CAAC,OAAO,QAAQ,YAAY,YAAY,EAAE;GAC9C,OAAO,QAAQ,iBAAiB,EAAE;EACpC,GAAG,CAAC,CAQM;EACR;EACA;EACA;EACA;EACA;EACA;CACF;AACF;AAGA,MAAa,eAAe,cAAiC,IAAI;AAEjE,SAAgB,gBAAgB;CAC9B,MAAM,QAAQ,WAAW,YAAY;CACrC,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,uDAAuD;CACnF,OAAO;AACT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SPRING_PRESS } from "./lib/ease.js";
|
|
2
2
|
import { MorphPopover, MorphPopoverContent } from "./components/motion/popover-morph.js";
|
|
3
|
-
import { Tooltip } from "./
|
|
3
|
+
import { t as Tooltip } from "./tooltip-Bam5KeYe.js";
|
|
4
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";
|
|
@@ -270,4 +270,4 @@ function CopyMenu({ fromLabel, reduce, onApply }) {
|
|
|
270
270
|
//#endregion
|
|
271
271
|
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 };
|
|
272
272
|
|
|
273
|
-
//# sourceMappingURL=copy-menu-
|
|
273
|
+
//# sourceMappingURL=copy-menu-BXUh52bu.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy-menu-C5GaT4Z-.js","names":[],"sources":["../src/components/motion/availability-scheduler/types.ts","../src/components/motion/availability-scheduler/copy-menu.tsx"],"sourcesContent":["export type DayKey = \"mon\" | \"tue\" | \"wed\" | \"thu\" | \"fri\" | \"sat\" | \"sun\";\n\nexport type TimeRange = { id: string; start: string; end: string };\nexport type DayAvailability = { enabled: boolean; ranges: TimeRange[] };\nexport type WeekAvailability = Record<DayKey, DayAvailability>;\nexport type TimeOption = { value: string; label: string };\n\nexport const WEEKDAYS: { key: DayKey; label: string }[] = [\n { key: \"mon\", label: \"Monday\" },\n { key: \"tue\", label: \"Tuesday\" },\n { key: \"wed\", label: \"Wednesday\" },\n { key: \"thu\", label: \"Thursday\" },\n { key: \"fri\", label: \"Friday\" },\n { key: \"sat\", label: \"Saturday\" },\n { key: \"sun\", label: \"Sunday\" },\n];\n\n// ─── panels ──────────────────────────────────────────────────────────────────\n\n/**\n * Names one time field week-wide, because the scheduler holds a single open\n * panel for the whole week. Range ids belong to the value and are only unique\n * within a day, so the day is part of the name — and the scheduler builds the\n * same keys to ask whether the panel it is holding is still on screen.\n */\nexport const panelKey = (day: DayKey, rangeId: string, edge: \"start\" | \"end\") =>\n `${day}:${rangeId}:${edge}`;\n\n// ─── time helpers ────────────────────────────────────────────────────────────\n\nexport const toMinutes = (v: string) => {\n const [h, m] = v.split(\":\").map(Number);\n return h * 60 + m;\n};\n\nexport const toValue = (mins: number) => {\n const clamped = Math.max(0, Math.min(24 * 60 - 1, mins));\n const h = Math.floor(clamped / 60);\n const m = clamped % 60;\n return `${String(h).padStart(2, \"0\")}:${String(m).padStart(2, \"0\")}`;\n};\n\nexport const label12 = (v: string) => {\n const [h, m] = v.split(\":\").map(Number);\n const ap = h < 12 ? \"AM\" : \"PM\";\n const h12 = h % 12 === 0 ? 12 : h % 12;\n return `${h12}:${String(m).padStart(2, \"0\")} ${ap}`;\n};\n\nexport function buildOptions(step: number): TimeOption[] {\n const out: TimeOption[] = [];\n for (let m = 0; m < 24 * 60; m += step) {\n const value = toValue(m);\n out.push({ value, label: label12(value) });\n }\n return out;\n}\n\nfunction snapToOption(mins: number, slots: number[]) {\n let best = slots[0];\n for (const slot of slots) {\n if (Math.abs(slot - mins) < Math.abs(best - mins)) best = slot;\n }\n return best;\n}\n\nfunction withCurrentOption(filtered: TimeOption[], all: TimeOption[], current?: string) {\n if (!current || filtered.some((o) => o.value === current)) return filtered;\n const extra =\n all.find((o) => o.value === current) ??\n ({ value: current, label: label12(current) } satisfies TimeOption);\n return [...filtered, extra].sort((a, b) => toMinutes(a.value) - toMinutes(b.value));\n}\n\n/**\n * Same-day ranges only. A valid pair is left alone so an off-grid persisted\n * end (17:00 with `step={720}`) is not rewritten. When the invariant fails,\n * the just-selected endpoint stays and only the opposite side moves onto a\n * neighboring generated option.\n */\nexport function clampRange(\n start: string,\n end: string,\n options: TimeOption[],\n changed: \"start\" | \"end\" = \"start\",\n): { start: string; end: string } {\n const slots = options.map((o) => toMinutes(o.value));\n if (slots.length === 0) return { start, end };\n\n const startM = toMinutes(start);\n const endM = toMinutes(end);\n if (endM > startM) return { start, end };\n\n const keepOrSnap = (value: string) => {\n const mins = toMinutes(value);\n return slots.includes(mins) ? mins : snapToOption(mins, slots);\n };\n\n if (changed === \"end\") {\n const e = keepOrSnap(end);\n const earlier = [...slots].reverse().find((slot) => slot < e);\n if (earlier === undefined && slots.length > 1) {\n // Midnight cannot end a positive same-day range, so use the first pair.\n return { start: toValue(slots[0]), end: toValue(slots[1]) };\n }\n return {\n start: toValue(earlier ?? keepOrSnap(start)),\n end: toValue(e),\n };\n }\n\n const s = keepOrSnap(start);\n const later = slots.find((slot) => slot > s);\n if (later === undefined && slots.length > 1) {\n // The last slot cannot start a positive range, so use the final pair.\n return {\n start: toValue(slots[slots.length - 2]),\n end: toValue(slots[slots.length - 1]),\n };\n }\n return {\n start: toValue(s),\n end: toValue(later ?? keepOrSnap(end)),\n };\n}\n\nexport function startOptions(options: TimeOption[], end: string, current?: string) {\n const filtered = options.filter((o) => toMinutes(o.value) < toMinutes(end));\n // An invalid midnight end has no earlier option; expose midnight so choosing\n // it can move the end forward through clampRange instead of trapping the row.\n const recovery = filtered.length === 0 ? options.slice(0, 1) : filtered;\n return withCurrentOption(recovery, options, current);\n}\n\nexport function endOptions(options: TimeOption[], start: string, current?: string) {\n const filtered = options.filter((o) => toMinutes(o.value) > toMinutes(start));\n // An invalid last-slot start has no later option; expose the last slot so\n // choosing it can move the start backward through clampRange.\n const recovery = filtered.length === 0 ? options.slice(-1) : filtered;\n return withCurrentOption(recovery, options, current);\n}\n\n// Default: Mon–Fri 9–5, weekend off. Fixed ids so SSR and first client render\n// agree (new ranges get counter ids afterwards).\nexport function defaultWeek(): WeekAvailability {\n const workday = (day: DayKey): DayAvailability => ({\n enabled: true,\n ranges: [{ id: `${day}-0`, start: \"09:00\", end: \"17:00\" }],\n });\n const off = (day: DayKey): DayAvailability => ({\n enabled: false,\n ranges: [{ id: `${day}-0`, start: \"09:00\", end: \"17:00\" }],\n });\n return {\n mon: workday(\"mon\"),\n tue: workday(\"tue\"),\n wed: workday(\"wed\"),\n thu: workday(\"thu\"),\n fri: workday(\"fri\"),\n sat: off(\"sat\"),\n sun: off(\"sun\"),\n };\n}\n","\"use client\";\n\nimport { useState } from \"react\";\nimport { Check, Copy } from \"lucide-react\";\nimport { AnimatePresence, motion } from \"motion/react\";\n\nimport { SPRING_PRESS } from \"../../../lib/ease\";\nimport { Checkbox } from \"../checkbox\";\nimport { MorphPopover, MorphPopoverContent } from \"../popover-morph\";\nimport { Tooltip } from \"../tooltip\";\nimport { IconButton } from \"./icon-button\";\nimport { type DayKey, WEEKDAYS } from \"./types\";\n\n// Copy this day's hours to other days: a morph popover with a day picker.\nexport function CopyMenu({\n fromLabel,\n reduce,\n onApply,\n}: {\n fromLabel: string;\n reduce: boolean;\n onApply: (targets: DayKey[]) => void;\n}) {\n const [open, setOpen] = useState(false);\n const [copied, setCopied] = useState(false);\n const [picked, setPicked] = useState<Set<DayKey>>(new Set());\n const others = WEEKDAYS.filter((d) => d.label !== fromLabel);\n\n const toggle = (k: DayKey) =>\n setPicked((prev) => {\n const next = new Set(prev);\n if (next.has(k)) next.delete(k);\n else next.add(k);\n return next;\n });\n\n const apply = (targets: DayKey[]) => {\n if (!targets.length) return;\n onApply(targets);\n setOpen(false);\n setPicked(new Set());\n setCopied(true);\n window.setTimeout(() => setCopied(false), 1200);\n };\n\n return (\n <MorphPopover open={open} onOpenChange={setOpen}>\n <Tooltip content=\"Copy times\">\n <IconButton\n label={`Copy ${fromLabel} hours to other days`}\n reduce={reduce}\n expanded={open}\n onClick={() => setOpen(!open)}\n >\n <AnimatePresence mode=\"popLayout\" initial={false}>\n {copied ? (\n <motion.span\n key=\"done\"\n initial={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.5 }}\n animate={{ opacity: 1, scale: 1 }}\n exit={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.5 }}\n transition={SPRING_PRESS}\n className=\"text-foreground\"\n >\n <Check className=\"h-4 w-4\" />\n </motion.span>\n ) : (\n <motion.span\n key=\"copy\"\n initial={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.5 }}\n animate={{ opacity: 1, scale: 1 }}\n exit={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.5 }}\n transition={SPRING_PRESS}\n >\n <Copy className=\"h-4 w-4\" />\n </motion.span>\n )}\n </AnimatePresence>\n </IconButton>\n </Tooltip>\n\n <MorphPopoverContent align=\"end\" className=\"w-52 p-2\">\n <p className=\"px-2 py-1.5 font-medium text-muted-foreground text-xs\">Copy times to</p>\n <div className=\"flex flex-col\">\n {others.map((d) => (\n <Checkbox\n key={d.key}\n checked={picked.has(d.key)}\n onCheckedChange={() => toggle(d.key)}\n label={d.label}\n className=\"w-full flex-row-reverse justify-between rounded-lg px-2 py-1.5 transition-colors hover:bg-muted [&_button[data-state=unchecked]]:border-border-strong [&_button]:size-4 [&_button]:rounded-[5px] [&_button]:border\"\n />\n ))}\n </div>\n <div className=\"mt-1 flex items-center gap-2 border-border border-t px-1 pt-2\">\n <button\n type=\"button\"\n onClick={() => apply(others.map((d) => d.key))}\n className=\"flex-1 rounded-lg px-2 py-1.5 font-medium text-muted-foreground text-xs outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:bg-muted\"\n >\n Every day\n </button>\n <button\n type=\"button\"\n onClick={() => apply([...picked])}\n disabled={picked.size === 0}\n className=\"flex-1 rounded-lg bg-primary px-2 py-1.5 font-semibold text-primary-foreground text-xs outline-none transition-opacity hover:opacity-90 focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-40\"\n >\n Apply\n </button>\n </div>\n </MorphPopoverContent>\n </MorphPopover>\n );\n}\n"],"mappings":";;;;;;;;;;AAOA,MAAa,WAA6C;CACxD;EAAE,KAAK;EAAO,OAAO;CAAS;CAC9B;EAAE,KAAK;EAAO,OAAO;CAAU;CAC/B;EAAE,KAAK;EAAO,OAAO;CAAY;CACjC;EAAE,KAAK;EAAO,OAAO;CAAW;CAChC;EAAE,KAAK;EAAO,OAAO;CAAS;CAC9B;EAAE,KAAK;EAAO,OAAO;CAAW;CAChC;EAAE,KAAK;EAAO,OAAO;CAAS;AAChC;;;;;;;AAUA,MAAa,YAAY,KAAa,SAAiB,SACrD,GAAG,IAAI,GAAG,QAAQ,GAAG;AAIvB,MAAa,aAAa,MAAc;CACtC,MAAM,C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AD;KAAK,WAAU;KACZ,UAAA,OAAO,KAAK,MACX,oBAAC,UAAD;MAEE,SAAS,OAAO,IAAI,EAAE,GAAG;MACzB,uBAAuB,OAAO,EAAE,GAAG;MACnC,OAAO,EAAE;MACT,WAAU;KACX,GALM,EAAE,GAKR,CACF;IACE,CAAA;IACL,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA,CACE,oBAAC,UAAD;MACE,MAAK;MACL,eAAe,MAAM,OAAO,KAAK,MAAM,EAAE,GAAG,CAAC;MAC7C,WAAU;MACX,UAAA;KAEO,CAAA,GACR,oBAAC,UAAD;MACE,MAAK;MACL,eAAe,MAAM,CAAC,GAAG,MAAM,CAAC;MAChC,UAAU,OAAO,SAAS;MAC1B,WAAU;MACX,UAAA;KAEO,CAAA,CACL;;GACc;EACT,CAAA,CAAA;;AAElB"}
|
|
1
|
+
{"version":3,"file":"copy-menu-BXUh52bu.js","names":[],"sources":["../src/components/motion/availability-scheduler/types.ts","../src/components/motion/availability-scheduler/copy-menu.tsx"],"sourcesContent":["export type DayKey = \"mon\" | \"tue\" | \"wed\" | \"thu\" | \"fri\" | \"sat\" | \"sun\";\n\nexport type TimeRange = { id: string; start: string; end: string };\nexport type DayAvailability = { enabled: boolean; ranges: TimeRange[] };\nexport type WeekAvailability = Record<DayKey, DayAvailability>;\nexport type TimeOption = { value: string; label: string };\n\nexport const WEEKDAYS: { key: DayKey; label: string }[] = [\n { key: \"mon\", label: \"Monday\" },\n { key: \"tue\", label: \"Tuesday\" },\n { key: \"wed\", label: \"Wednesday\" },\n { key: \"thu\", label: \"Thursday\" },\n { key: \"fri\", label: \"Friday\" },\n { key: \"sat\", label: \"Saturday\" },\n { key: \"sun\", label: \"Sunday\" },\n];\n\n// ─── panels ──────────────────────────────────────────────────────────────────\n\n/**\n * Names one time field week-wide, because the scheduler holds a single open\n * panel for the whole week. Range ids belong to the value and are only unique\n * within a day, so the day is part of the name — and the scheduler builds the\n * same keys to ask whether the panel it is holding is still on screen.\n */\nexport const panelKey = (day: DayKey, rangeId: string, edge: \"start\" | \"end\") =>\n `${day}:${rangeId}:${edge}`;\n\n// ─── time helpers ────────────────────────────────────────────────────────────\n\nexport const toMinutes = (v: string) => {\n const [h, m] = v.split(\":\").map(Number);\n return h * 60 + m;\n};\n\nexport const toValue = (mins: number) => {\n const clamped = Math.max(0, Math.min(24 * 60 - 1, mins));\n const h = Math.floor(clamped / 60);\n const m = clamped % 60;\n return `${String(h).padStart(2, \"0\")}:${String(m).padStart(2, \"0\")}`;\n};\n\nexport const label12 = (v: string) => {\n const [h, m] = v.split(\":\").map(Number);\n const ap = h < 12 ? \"AM\" : \"PM\";\n const h12 = h % 12 === 0 ? 12 : h % 12;\n return `${h12}:${String(m).padStart(2, \"0\")} ${ap}`;\n};\n\nexport function buildOptions(step: number): TimeOption[] {\n const out: TimeOption[] = [];\n for (let m = 0; m < 24 * 60; m += step) {\n const value = toValue(m);\n out.push({ value, label: label12(value) });\n }\n return out;\n}\n\nfunction snapToOption(mins: number, slots: number[]) {\n let best = slots[0];\n for (const slot of slots) {\n if (Math.abs(slot - mins) < Math.abs(best - mins)) best = slot;\n }\n return best;\n}\n\nfunction withCurrentOption(filtered: TimeOption[], all: TimeOption[], current?: string) {\n if (!current || filtered.some((o) => o.value === current)) return filtered;\n const extra =\n all.find((o) => o.value === current) ??\n ({ value: current, label: label12(current) } satisfies TimeOption);\n return [...filtered, extra].sort((a, b) => toMinutes(a.value) - toMinutes(b.value));\n}\n\n/**\n * Same-day ranges only. A valid pair is left alone so an off-grid persisted\n * end (17:00 with `step={720}`) is not rewritten. When the invariant fails,\n * the just-selected endpoint stays and only the opposite side moves onto a\n * neighboring generated option.\n */\nexport function clampRange(\n start: string,\n end: string,\n options: TimeOption[],\n changed: \"start\" | \"end\" = \"start\",\n): { start: string; end: string } {\n const slots = options.map((o) => toMinutes(o.value));\n if (slots.length === 0) return { start, end };\n\n const startM = toMinutes(start);\n const endM = toMinutes(end);\n if (endM > startM) return { start, end };\n\n const keepOrSnap = (value: string) => {\n const mins = toMinutes(value);\n return slots.includes(mins) ? mins : snapToOption(mins, slots);\n };\n\n if (changed === \"end\") {\n const e = keepOrSnap(end);\n const earlier = [...slots].reverse().find((slot) => slot < e);\n if (earlier === undefined && slots.length > 1) {\n // Midnight cannot end a positive same-day range, so use the first pair.\n return { start: toValue(slots[0]), end: toValue(slots[1]) };\n }\n return {\n start: toValue(earlier ?? keepOrSnap(start)),\n end: toValue(e),\n };\n }\n\n const s = keepOrSnap(start);\n const later = slots.find((slot) => slot > s);\n if (later === undefined && slots.length > 1) {\n // The last slot cannot start a positive range, so use the final pair.\n return {\n start: toValue(slots[slots.length - 2]),\n end: toValue(slots[slots.length - 1]),\n };\n }\n return {\n start: toValue(s),\n end: toValue(later ?? keepOrSnap(end)),\n };\n}\n\nexport function startOptions(options: TimeOption[], end: string, current?: string) {\n const filtered = options.filter((o) => toMinutes(o.value) < toMinutes(end));\n // An invalid midnight end has no earlier option; expose midnight so choosing\n // it can move the end forward through clampRange instead of trapping the row.\n const recovery = filtered.length === 0 ? options.slice(0, 1) : filtered;\n return withCurrentOption(recovery, options, current);\n}\n\nexport function endOptions(options: TimeOption[], start: string, current?: string) {\n const filtered = options.filter((o) => toMinutes(o.value) > toMinutes(start));\n // An invalid last-slot start has no later option; expose the last slot so\n // choosing it can move the start backward through clampRange.\n const recovery = filtered.length === 0 ? options.slice(-1) : filtered;\n return withCurrentOption(recovery, options, current);\n}\n\n// Default: Mon–Fri 9–5, weekend off. Fixed ids so SSR and first client render\n// agree (new ranges get counter ids afterwards).\nexport function defaultWeek(): WeekAvailability {\n const workday = (day: DayKey): DayAvailability => ({\n enabled: true,\n ranges: [{ id: `${day}-0`, start: \"09:00\", end: \"17:00\" }],\n });\n const off = (day: DayKey): DayAvailability => ({\n enabled: false,\n ranges: [{ id: `${day}-0`, start: \"09:00\", end: \"17:00\" }],\n });\n return {\n mon: workday(\"mon\"),\n tue: workday(\"tue\"),\n wed: workday(\"wed\"),\n thu: workday(\"thu\"),\n fri: workday(\"fri\"),\n sat: off(\"sat\"),\n sun: off(\"sun\"),\n };\n}\n","\"use client\";\n\nimport { useState } from \"react\";\nimport { Check, Copy } from \"lucide-react\";\nimport { AnimatePresence, motion } from \"motion/react\";\n\nimport { SPRING_PRESS } from \"../../../lib/ease\";\nimport { Checkbox } from \"../checkbox\";\nimport { MorphPopover, MorphPopoverContent } from \"../popover-morph\";\nimport { Tooltip } from \"../tooltip\";\nimport { IconButton } from \"./icon-button\";\nimport { type DayKey, WEEKDAYS } from \"./types\";\n\n// Copy this day's hours to other days: a morph popover with a day picker.\nexport function CopyMenu({\n fromLabel,\n reduce,\n onApply,\n}: {\n fromLabel: string;\n reduce: boolean;\n onApply: (targets: DayKey[]) => void;\n}) {\n const [open, setOpen] = useState(false);\n const [copied, setCopied] = useState(false);\n const [picked, setPicked] = useState<Set<DayKey>>(new Set());\n const others = WEEKDAYS.filter((d) => d.label !== fromLabel);\n\n const toggle = (k: DayKey) =>\n setPicked((prev) => {\n const next = new Set(prev);\n if (next.has(k)) next.delete(k);\n else next.add(k);\n return next;\n });\n\n const apply = (targets: DayKey[]) => {\n if (!targets.length) return;\n onApply(targets);\n setOpen(false);\n setPicked(new Set());\n setCopied(true);\n window.setTimeout(() => setCopied(false), 1200);\n };\n\n return (\n <MorphPopover open={open} onOpenChange={setOpen}>\n <Tooltip content=\"Copy times\">\n <IconButton\n label={`Copy ${fromLabel} hours to other days`}\n reduce={reduce}\n expanded={open}\n onClick={() => setOpen(!open)}\n >\n <AnimatePresence mode=\"popLayout\" initial={false}>\n {copied ? (\n <motion.span\n key=\"done\"\n initial={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.5 }}\n animate={{ opacity: 1, scale: 1 }}\n exit={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.5 }}\n transition={SPRING_PRESS}\n className=\"text-foreground\"\n >\n <Check className=\"h-4 w-4\" />\n </motion.span>\n ) : (\n <motion.span\n key=\"copy\"\n initial={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.5 }}\n animate={{ opacity: 1, scale: 1 }}\n exit={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.5 }}\n transition={SPRING_PRESS}\n >\n <Copy className=\"h-4 w-4\" />\n </motion.span>\n )}\n </AnimatePresence>\n </IconButton>\n </Tooltip>\n\n <MorphPopoverContent align=\"end\" className=\"w-52 p-2\">\n <p className=\"px-2 py-1.5 font-medium text-muted-foreground text-xs\">Copy times to</p>\n <div className=\"flex flex-col\">\n {others.map((d) => (\n <Checkbox\n key={d.key}\n checked={picked.has(d.key)}\n onCheckedChange={() => toggle(d.key)}\n label={d.label}\n className=\"w-full flex-row-reverse justify-between rounded-lg px-2 py-1.5 transition-colors hover:bg-muted [&_button[data-state=unchecked]]:border-border-strong [&_button]:size-4 [&_button]:rounded-[5px] [&_button]:border\"\n />\n ))}\n </div>\n <div className=\"mt-1 flex items-center gap-2 border-border border-t px-1 pt-2\">\n <button\n type=\"button\"\n onClick={() => apply(others.map((d) => d.key))}\n className=\"flex-1 rounded-lg px-2 py-1.5 font-medium text-muted-foreground text-xs outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:bg-muted\"\n >\n Every day\n </button>\n <button\n type=\"button\"\n onClick={() => apply([...picked])}\n disabled={picked.size === 0}\n className=\"flex-1 rounded-lg bg-primary px-2 py-1.5 font-semibold text-primary-foreground text-xs outline-none transition-opacity hover:opacity-90 focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-40\"\n >\n Apply\n </button>\n </div>\n </MorphPopoverContent>\n </MorphPopover>\n );\n}\n"],"mappings":";;;;;;;;;;AAOA,MAAa,WAA6C;CACxD;EAAE,KAAK;EAAO,OAAO;CAAS;CAC9B;EAAE,KAAK;EAAO,OAAO;CAAU;CAC/B;EAAE,KAAK;EAAO,OAAO;CAAY;CACjC;EAAE,KAAK;EAAO,OAAO;CAAW;CAChC;EAAE,KAAK;EAAO,OAAO;CAAS;CAC9B;EAAE,KAAK;EAAO,OAAO;CAAW;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AAA;GACP,CAAA;EACL,CAAA,GAET,qBAAC,qBAAD;GAAqB,OAAM;GAAM,WAAU;GAA3C,UAAA;IACE,oBAAC,KAAD;KAAG,WAAU;KAAwD,UAAA;IAAgB,CAAA;IACrF,oBAAC,OAAD;KAAK,WAAU;KACZ,UAAA,OAAO,KAAK,MACX,oBAAC,UAAD;MAEE,SAAS,OAAO,IAAI,EAAE,GAAG;MACzB,uBAAuB,OAAO,EAAE,GAAG;MACnC,OAAO,EAAE;MACT,WAAU;KACX,GALM,EAAE,GAKR,CACF;IACE,CAAA;IACL,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA,CACE,oBAAC,UAAD;MACE,MAAK;MACL,eAAe,MAAM,OAAO,KAAK,MAAM,EAAE,GAAG,CAAC;MAC7C,WAAU;MACX,UAAA;KAEO,CAAA,GACR,oBAAC,UAAD;MACE,MAAK;MACL,eAAe,MAAM,CAAC,GAAG,MAAM,CAAC;MAChC,UAAU,OAAO,SAAS;MAC1B,WAAU;MACX,UAAA;KAEO,CAAA,CACL;;GACc;EACT,CAAA,CAAA;;AAElB"}
|
|
@@ -51,4 +51,5 @@ interface IntersectionObserverOptions extends IntersectionObserverInit {
|
|
|
51
51
|
*/
|
|
52
52
|
export declare function useIntersectionObserver(elementRef: React$1.RefObject<Element | null>, { threshold, root, rootMargin, freezeOnceVisible }?: IntersectionObserverOptions): boolean;
|
|
53
53
|
//#endregion
|
|
54
|
+
export {};
|
|
54
55
|
//# sourceMappingURL=use-intersection-observer.d.ts.map
|
package/dist/lib/tick-sound.d.ts
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/components/charts/order-book/model.d.ts
|
|
2
|
+
type DepthLevel = {
|
|
3
|
+
price: number;
|
|
4
|
+
size: number;
|
|
5
|
+
total: number;
|
|
6
|
+
};
|
|
7
|
+
type DepthSummary = {
|
|
8
|
+
side: "bid" | "ask";
|
|
9
|
+
/** Number of levels from the best price out to the inspected one. */
|
|
10
|
+
levels: number;
|
|
11
|
+
/** Total base size across those levels. */
|
|
12
|
+
size: number;
|
|
13
|
+
/** Total quote value across those levels. */
|
|
14
|
+
quote: number;
|
|
15
|
+
/** Size-weighted average fill price. */
|
|
16
|
+
averagePrice: number;
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { DepthSummary as n, DepthLevel as t };
|
|
20
|
+
//# sourceMappingURL=model-NSIg2p7a.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-NSIg2p7a.d.ts","names":[],"sources":["../src/components/charts/order-book/model.ts"],"mappings":";KAAY;EAAe;EAAe;EAAc;;KAmB5C;EACV;;EAEA;;EAEA;;EAEA;;EAEA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/components/charts/donut-chart/model.d.ts
|
|
2
|
+
interface DonutSegment {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
/** Any CSS color, such as "#2563eb" or "var(--chart-1)". */
|
|
6
|
+
color: string;
|
|
7
|
+
/** Nonnegative value. Zero and invalid values are left out of the ring. */
|
|
8
|
+
value: number;
|
|
9
|
+
}
|
|
10
|
+
type PlacedSegment = DonutSegment & {
|
|
11
|
+
/** Share of the total, from 0 to 1. */
|
|
12
|
+
share: number;
|
|
13
|
+
/** Centerline arc path in the 200 × 200 viewBox. */
|
|
14
|
+
path: string;
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { PlacedSegment as n, DonutSegment as t };
|
|
18
|
+
//# sourceMappingURL=model-_mRyI6V9.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-_mRyI6V9.d.ts","names":[],"sources":["../src/components/charts/donut-chart/model.ts"],"mappings":";UAAiB;EACf;EACA;;EAEA;;EAEA;;KAGU,gBAAgB;;EAE1B;;EAEA"}
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { useCallback, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useIsPresent } from "motion/react";
|
|
4
|
-
import { autoUpdate, computePosition, flip, offset, shift } from "@floating-ui/dom";
|
|
4
|
+
import { arrow, autoUpdate, computePosition, flip, hide, offset, shift } from "@floating-ui/dom";
|
|
5
5
|
//#region src/components/motion/tooltip/use-position.ts
|
|
6
|
+
const ORIGIN = {
|
|
7
|
+
top: "center bottom",
|
|
8
|
+
bottom: "center top",
|
|
9
|
+
left: "right center",
|
|
10
|
+
right: "left center"
|
|
11
|
+
};
|
|
6
12
|
/** Position is geometry, not animation. One write per frame, never a spring chasing a pointer. */
|
|
7
|
-
function useTooltipPosition({ open,
|
|
13
|
+
function useTooltipPosition({ open, anchor, floatingRef, arrowRef, anchorPoint, followCursor, side, align, sideOffset, onDismiss, onPosition, pointer }) {
|
|
8
14
|
const { cursor, onMove } = pointer;
|
|
15
|
+
const preferred = align === "center" ? side : `${side}-${align}`;
|
|
9
16
|
const cursorSide = useRef(null);
|
|
10
17
|
useLayoutEffect(() => {
|
|
11
|
-
cursorSide.current = open ?
|
|
12
|
-
}, [open,
|
|
18
|
+
cursorSide.current = open ? preferred : null;
|
|
19
|
+
}, [open, preferred]);
|
|
13
20
|
const frame = useRef(null);
|
|
14
21
|
const version = useRef(0);
|
|
15
22
|
const update = useRef(() => {});
|
|
@@ -31,12 +38,12 @@ function useTooltipPosition({ open, anchorRef, floatingRef, anchorPoint, followC
|
|
|
31
38
|
const pointY = anchorPoint?.y;
|
|
32
39
|
useLayoutEffect(() => {
|
|
33
40
|
update.current = () => {
|
|
34
|
-
const anchor = anchorRef.current;
|
|
35
41
|
const floating = floatingRef.current;
|
|
36
42
|
if (!open || !anchor || !floating) return;
|
|
37
43
|
const revision = ++version.current;
|
|
38
44
|
const currentCursor = followCursor ? cursor.current : null;
|
|
39
|
-
|
|
45
|
+
const virtual = Boolean(currentCursor) || pointX !== void 0 || pointY !== void 0;
|
|
46
|
+
const reference = virtual ? {
|
|
40
47
|
contextElement: anchor,
|
|
41
48
|
getBoundingClientRect: () => {
|
|
42
49
|
const rect = anchor.getBoundingClientRect();
|
|
@@ -53,46 +60,61 @@ function useTooltipPosition({ open, anchorRef, floatingRef, anchorPoint, followC
|
|
|
53
60
|
height: 0
|
|
54
61
|
};
|
|
55
62
|
}
|
|
56
|
-
} : anchor
|
|
63
|
+
} : anchor;
|
|
64
|
+
const arrowElement = arrowRef?.current ?? null;
|
|
65
|
+
computePosition(reference, floating, {
|
|
57
66
|
strategy: "fixed",
|
|
58
|
-
placement: currentCursor ? cursorSide.current ??
|
|
67
|
+
placement: currentCursor ? cursorSide.current ?? preferred : preferred,
|
|
59
68
|
middleware: [
|
|
60
|
-
offset(currentCursor ? 12 : 8),
|
|
69
|
+
offset(sideOffset ?? (currentCursor ? 12 : 8)),
|
|
61
70
|
flip({ padding: 8 }),
|
|
62
|
-
shift({ padding: 8 })
|
|
71
|
+
shift({ padding: 8 }),
|
|
72
|
+
...arrowElement ? [arrow({
|
|
73
|
+
element: arrowElement,
|
|
74
|
+
padding: 10
|
|
75
|
+
})] : [],
|
|
76
|
+
...virtual ? [] : [hide({ strategy: "referenceHidden" })]
|
|
63
77
|
]
|
|
64
|
-
}).then(({ x, y, placement }) => {
|
|
78
|
+
}).then(({ x, y, placement, middlewareData }) => {
|
|
65
79
|
if (version.current !== revision || !floating.isConnected) return;
|
|
66
80
|
if (currentCursor) cursorSide.current = placement;
|
|
67
81
|
else cursorSide.current = null;
|
|
82
|
+
const placedSide = placement.split("-")[0];
|
|
68
83
|
const dpr = window.devicePixelRatio || 1;
|
|
69
84
|
floating.style.transform = `translate3d(${Math.round(x * dpr) / dpr}px, ${Math.round(y * dpr) / dpr}px, 0)`;
|
|
70
|
-
floating.style.setProperty("--tooltip-origin",
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
right: "left center"
|
|
75
|
-
}[placement.split("-")[0]]);
|
|
76
|
-
floating.style.visibility = "visible";
|
|
85
|
+
floating.style.setProperty("--tooltip-origin", ORIGIN[placedSide]);
|
|
86
|
+
const box = anchor.getBoundingClientRect();
|
|
87
|
+
const clipped = Boolean(middlewareData.hide?.referenceHidden) && (box.width > 0 || box.height > 0);
|
|
88
|
+
floating.style.visibility = clipped ? "hidden" : "visible";
|
|
77
89
|
floating.dataset.placement = placement;
|
|
78
|
-
|
|
90
|
+
const surface = arrowElement?.parentElement;
|
|
91
|
+
if (arrowElement && surface) {
|
|
92
|
+
const { x: ax, y: ay } = middlewareData.arrow ?? {};
|
|
93
|
+
if (ax != null) arrowElement.style.left = `${ax - surface.clientLeft}px`;
|
|
94
|
+
if (ay != null) arrowElement.style.top = `${ay - surface.clientTop}px`;
|
|
95
|
+
const style = getComputedStyle(surface);
|
|
96
|
+
arrowElement.style.setProperty("--tooltip-arrow-fill", style.backgroundColor);
|
|
97
|
+
arrowElement.style.setProperty("--tooltip-arrow-stroke", style.borderTopColor);
|
|
98
|
+
}
|
|
99
|
+
onPosition(placedSide);
|
|
79
100
|
});
|
|
80
101
|
};
|
|
81
102
|
if (open) schedule();
|
|
82
103
|
}, [
|
|
83
104
|
open,
|
|
84
|
-
|
|
105
|
+
anchor,
|
|
85
106
|
floatingRef,
|
|
107
|
+
arrowRef,
|
|
86
108
|
followCursor,
|
|
87
109
|
pointX,
|
|
88
110
|
pointY,
|
|
89
|
-
|
|
111
|
+
preferred,
|
|
112
|
+
sideOffset,
|
|
90
113
|
schedule,
|
|
91
114
|
onPosition,
|
|
92
115
|
cursor
|
|
93
116
|
]);
|
|
94
117
|
useLayoutEffect(() => {
|
|
95
|
-
const anchor = anchorRef.current;
|
|
96
118
|
const floating = floatingRef.current;
|
|
97
119
|
if (!open || !anchor || !floating) return;
|
|
98
120
|
const stop = autoUpdate(anchor, floating, schedule);
|
|
@@ -109,7 +131,7 @@ function useTooltipPosition({ open, anchorRef, floatingRef, anchorPoint, followC
|
|
|
109
131
|
};
|
|
110
132
|
}, [
|
|
111
133
|
open,
|
|
112
|
-
|
|
134
|
+
anchor,
|
|
113
135
|
floatingRef,
|
|
114
136
|
followCursor,
|
|
115
137
|
onDismiss,
|
|
@@ -121,13 +143,12 @@ function useTooltipPosition({ open, anchorRef, floatingRef, anchorPoint, followC
|
|
|
121
143
|
if (frame.current !== null) cancelAnimationFrame(frame.current);
|
|
122
144
|
}, []);
|
|
123
145
|
}
|
|
124
|
-
/** Pointer lifetime belongs to the
|
|
125
|
-
function useTooltipPointer(
|
|
146
|
+
/** Pointer lifetime belongs to the anchor, including the opening delay. */
|
|
147
|
+
function useTooltipPointer(anchor, followCursor) {
|
|
126
148
|
const cursor = useRef(null);
|
|
127
149
|
const onMove = useRef(null);
|
|
128
150
|
const pointerFocus = useRef(false);
|
|
129
151
|
useLayoutEffect(() => {
|
|
130
|
-
const anchor = anchorRef.current;
|
|
131
152
|
if (!anchor || !followCursor) return;
|
|
132
153
|
const point = (event) => {
|
|
133
154
|
if (event.type === "pointermove" && event.pointerType === "touch" && !event.buttons) return;
|
|
@@ -168,7 +189,7 @@ function useTooltipPointer(anchorRef, followCursor) {
|
|
|
168
189
|
anchor.removeEventListener("keydown", keyboard);
|
|
169
190
|
anchor.removeEventListener("focusin", focus);
|
|
170
191
|
};
|
|
171
|
-
}, [
|
|
192
|
+
}, [anchor, followCursor]);
|
|
172
193
|
return {
|
|
173
194
|
cursor,
|
|
174
195
|
onMove
|
|
@@ -180,7 +201,11 @@ function useTooltipPointer(anchorRef, followCursor) {
|
|
|
180
201
|
function TooltipPositioner({ children, ...position }) {
|
|
181
202
|
const present = useIsPresent();
|
|
182
203
|
const [ready, setReady] = useState(false);
|
|
183
|
-
const
|
|
204
|
+
const [side, setSide] = useState(position.side);
|
|
205
|
+
const onPosition = useCallback((placed) => {
|
|
206
|
+
setReady(true);
|
|
207
|
+
setSide(placed);
|
|
208
|
+
}, []);
|
|
184
209
|
useTooltipPosition({
|
|
185
210
|
...position,
|
|
186
211
|
open: present,
|
|
@@ -190,15 +215,54 @@ function TooltipPositioner({ children, ...position }) {
|
|
|
190
215
|
ref: position.floatingRef,
|
|
191
216
|
inert: !present,
|
|
192
217
|
"aria-hidden": !present || void 0,
|
|
193
|
-
className: "pointer-events-none fixed top-0 left-0 z-9999 w-max",
|
|
218
|
+
className: "pointer-events-none fixed top-0 left-0 z-[9999] w-max",
|
|
194
219
|
style: {
|
|
195
220
|
visibility: "hidden",
|
|
196
221
|
maxWidth: "calc(100vw - 16px)"
|
|
197
222
|
},
|
|
198
|
-
children: children(ready, present)
|
|
223
|
+
children: children(ready, present, side)
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
const ARROW = {
|
|
227
|
+
top: {
|
|
228
|
+
path: "M0 6L6 12L12 6",
|
|
229
|
+
style: { top: "calc(100% - 6px)" }
|
|
230
|
+
},
|
|
231
|
+
bottom: {
|
|
232
|
+
path: "M0 6L6 0L12 6",
|
|
233
|
+
style: { bottom: "calc(100% - 6px)" }
|
|
234
|
+
},
|
|
235
|
+
left: {
|
|
236
|
+
path: "M6 0L12 6L6 12",
|
|
237
|
+
style: { left: "calc(100% - 6px)" }
|
|
238
|
+
},
|
|
239
|
+
right: {
|
|
240
|
+
path: "M6 0L0 6L6 12",
|
|
241
|
+
style: { right: "calc(100% - 6px)" }
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
function TooltipArrow({ side, ref }) {
|
|
245
|
+
const { path, style } = ARROW[side];
|
|
246
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
247
|
+
ref,
|
|
248
|
+
"aria-hidden": "true",
|
|
249
|
+
width: "12",
|
|
250
|
+
height: "12",
|
|
251
|
+
viewBox: "0 0 12 12",
|
|
252
|
+
className: "pointer-events-none absolute overflow-visible",
|
|
253
|
+
style,
|
|
254
|
+
children: [/* @__PURE__ */ jsx("path", {
|
|
255
|
+
d: `${path}Z`,
|
|
256
|
+
style: { fill: "var(--tooltip-arrow-fill, transparent)" }
|
|
257
|
+
}), /* @__PURE__ */ jsx("path", {
|
|
258
|
+
d: path,
|
|
259
|
+
fill: "none",
|
|
260
|
+
strokeWidth: "1",
|
|
261
|
+
style: { stroke: "var(--tooltip-arrow-stroke, transparent)" }
|
|
262
|
+
})]
|
|
199
263
|
});
|
|
200
264
|
}
|
|
201
265
|
//#endregion
|
|
202
|
-
export {
|
|
266
|
+
export { TooltipPositioner as n, useTooltipPointer as r, TooltipArrow as t };
|
|
203
267
|
|
|
204
|
-
//# sourceMappingURL=positioner-
|
|
268
|
+
//# sourceMappingURL=positioner-3r3cfkqT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positioner-3r3cfkqT.js","names":["arrowMiddleware"],"sources":["../src/components/motion/tooltip/use-position.ts","../src/components/motion/tooltip/positioner.tsx"],"sourcesContent":["\"use client\";\n\nimport { type RefObject, useCallback, useLayoutEffect, useRef } from \"react\";\nimport {\n arrow as arrowMiddleware,\n autoUpdate,\n computePosition,\n flip,\n hide,\n offset,\n type Placement,\n shift,\n type VirtualElement,\n} from \"@floating-ui/dom\";\n\nexport type TooltipSide = \"top\" | \"right\" | \"bottom\" | \"left\";\nexport type TooltipAlign = \"start\" | \"center\" | \"end\";\nexport type TooltipPoint = { x: number; y: number };\nexport type TooltipAnchor = HTMLElement | SVGElement;\n\nconst ORIGIN: Record<TooltipSide, string> = {\n top: \"center bottom\",\n bottom: \"center top\",\n left: \"right center\",\n right: \"left center\",\n};\n\n/** Position is geometry, not animation. One write per frame, never a spring chasing a pointer. */\nexport function useTooltipPosition({\n open,\n anchor,\n floatingRef,\n arrowRef,\n anchorPoint,\n followCursor,\n side,\n align,\n sideOffset,\n onDismiss,\n onPosition,\n pointer,\n}: {\n open: boolean;\n anchor: TooltipAnchor | null;\n floatingRef: RefObject<HTMLSpanElement | null>;\n arrowRef?: RefObject<SVGSVGElement | null>;\n anchorPoint?: TooltipPoint;\n followCursor: boolean;\n side: TooltipSide;\n align: TooltipAlign;\n sideOffset?: number;\n onDismiss: () => void;\n onPosition: (side: TooltipSide) => void;\n pointer: ReturnType<typeof useTooltipPointer>;\n}) {\n const { cursor, onMove } = pointer;\n const preferred: Placement = align === \"center\" ? side : `${side}-${align}`;\n const cursorSide = useRef<Placement | null>(null);\n useLayoutEffect(() => {\n cursorSide.current = open ? preferred : null;\n }, [open, preferred]);\n const frame = useRef<number | null>(null);\n const version = useRef(0);\n const update = useRef<() => void>(() => {});\n const schedule = useCallback(() => {\n // Invalidate older async calculations as soon as new geometry is requested.\n version.current++;\n if (frame.current !== null) return;\n frame.current = requestAnimationFrame(() => {\n frame.current = null;\n update.current();\n });\n }, []);\n useLayoutEffect(() => {\n onMove.current = schedule;\n return () => {\n onMove.current = null;\n };\n }, [onMove, schedule]);\n const pointX = anchorPoint?.x;\n const pointY = anchorPoint?.y;\n\n // Latest committed inputs are read without recreating observers for every period/content update.\n useLayoutEffect(() => {\n update.current = () => {\n const floating = floatingRef.current;\n if (!open || !anchor || !floating) return;\n const revision = ++version.current;\n const currentCursor = followCursor ? cursor.current : null;\n const virtual = Boolean(currentCursor) || pointX !== undefined || pointY !== undefined;\n const reference: Element | VirtualElement = virtual\n ? {\n contextElement: anchor,\n getBoundingClientRect: () => {\n const rect = anchor.getBoundingClientRect();\n const x = currentCursor?.x ?? rect.left + rect.width * (pointX ?? 0.5);\n const y = currentCursor?.y ?? rect.top + rect.height * (pointY ?? 0.5);\n return { x, y, left: x, right: x, top: y, bottom: y, width: 0, height: 0 };\n },\n }\n : anchor;\n const arrowElement = arrowRef?.current ?? null;\n void computePosition(reference, floating, {\n strategy: \"fixed\",\n placement: currentCursor ? (cursorSide.current ?? preferred) : preferred,\n middleware: [\n offset(sideOffset ?? (currentCursor ? 12 : 8)),\n flip({ padding: 8 }),\n shift({ padding: 8 }),\n ...(arrowElement ? [arrowMiddleware({ element: arrowElement, padding: 10 })] : []),\n // A label left floating over whatever scrolled into its trigger's place\n // describes nothing there. Points inside a chart move with the chart.\n ...(virtual ? [] : [hide({ strategy: \"referenceHidden\" })]),\n ],\n }).then(({ x, y, placement, middlewareData }) => {\n if (version.current !== revision || !floating.isConnected) return;\n // Hold the chosen side for this hover session. Crossing a flip threshold\n // repeatedly must not bounce the surface above and below the pointer.\n if (currentCursor) cursorSide.current = placement;\n else cursorSide.current = null;\n const placedSide = placement.split(\"-\")[0] as TooltipSide;\n const dpr = window.devicePixelRatio || 1;\n floating.style.transform = `translate3d(${Math.round(x * dpr) / dpr}px, ${Math.round(y * dpr) / dpr}px, 0)`;\n floating.style.setProperty(\"--tooltip-origin\", ORIGIN[placedSide]);\n // A box with no size has no clipped state to report, only a missing layout.\n const box = anchor.getBoundingClientRect();\n const clipped =\n Boolean(middlewareData.hide?.referenceHidden) && (box.width > 0 || box.height > 0);\n floating.style.visibility = clipped ? \"hidden\" : \"visible\";\n floating.dataset.placement = placement;\n const surface = arrowElement?.parentElement;\n if (arrowElement && surface) {\n // Measured against the positioner, drawn inside the surface's border.\n const { x: ax, y: ay } = middlewareData.arrow ?? {};\n if (ax != null) arrowElement.style.left = `${ax - surface.clientLeft}px`;\n if (ay != null) arrowElement.style.top = `${ay - surface.clientTop}px`;\n // Paint with whatever the surface resolved to, so a restyled tooltip\n // keeps a matching arrow without a second set of classes.\n const style = getComputedStyle(surface);\n arrowElement.style.setProperty(\"--tooltip-arrow-fill\", style.backgroundColor);\n arrowElement.style.setProperty(\"--tooltip-arrow-stroke\", style.borderTopColor);\n }\n onPosition(placedSide);\n });\n };\n if (open) schedule();\n }, [\n open,\n anchor,\n floatingRef,\n arrowRef,\n followCursor,\n pointX,\n pointY,\n preferred,\n sideOffset,\n schedule,\n onPosition,\n cursor,\n ]);\n\n useLayoutEffect(() => {\n const floating = floatingRef.current;\n if (!open || !anchor || !floating) return;\n const stop = autoUpdate(anchor, floating, schedule);\n const onScroll = () => {\n // A stationary pointer no longer describes the same chart point after scrolling.\n if (followCursor && cursor.current) onDismiss();\n };\n window.addEventListener(\"scroll\", onScroll, true);\n return () => {\n stop();\n window.removeEventListener(\"scroll\", onScroll, true);\n version.current++;\n if (frame.current !== null) cancelAnimationFrame(frame.current);\n frame.current = null;\n };\n }, [open, anchor, floatingRef, followCursor, onDismiss, schedule, cursor]);\n\n useLayoutEffect(\n () => () => {\n version.current++;\n if (frame.current !== null) cancelAnimationFrame(frame.current);\n },\n [],\n );\n}\n\n/** Pointer lifetime belongs to the anchor, including the opening delay. */\nexport function useTooltipPointer(anchor: TooltipAnchor | null, followCursor: boolean) {\n const cursor = useRef<TooltipPoint | null>(null);\n const onMove = useRef<(() => void) | null>(null);\n const pointerFocus = useRef(false);\n useLayoutEffect(() => {\n if (!anchor || !followCursor) return;\n const point = (event: PointerEvent) => {\n if (event.type === \"pointermove\" && event.pointerType === \"touch\" && !event.buttons) return;\n cursor.current = { x: event.clientX, y: event.clientY };\n if (event.type === \"pointerdown\") pointerFocus.current = true;\n onMove.current?.();\n };\n const keyboard = () => {\n cursor.current = null;\n pointerFocus.current = false;\n onMove.current?.();\n };\n const focus = () => {\n if (!pointerFocus.current) cursor.current = null;\n pointerFocus.current = false;\n onMove.current?.();\n };\n const leave = () => {\n cursor.current = null;\n };\n anchor.addEventListener(\"pointerenter\", point as EventListener, { passive: true });\n anchor.addEventListener(\"pointermove\", point as EventListener, { passive: true });\n anchor.addEventListener(\"pointerdown\", point as EventListener, { passive: true });\n anchor.addEventListener(\"pointerleave\", leave);\n anchor.addEventListener(\"pointercancel\", leave);\n anchor.addEventListener(\"keydown\", keyboard);\n anchor.addEventListener(\"focusin\", focus);\n return () => {\n cursor.current = null;\n anchor.removeEventListener(\"pointerenter\", point as EventListener);\n anchor.removeEventListener(\"pointermove\", point as EventListener);\n anchor.removeEventListener(\"pointerdown\", point as EventListener);\n anchor.removeEventListener(\"pointerleave\", leave);\n anchor.removeEventListener(\"pointercancel\", leave);\n anchor.removeEventListener(\"keydown\", keyboard);\n anchor.removeEventListener(\"focusin\", focus);\n };\n }, [anchor, followCursor]);\n\n return { cursor, onMove };\n}\n","\"use client\";\n\nimport { type CSSProperties, type ReactNode, type Ref, useCallback, useState } from \"react\";\nimport { useIsPresent } from \"motion/react\";\n\nimport { type TooltipSide, useTooltipPosition } from \"./use-position\";\n\ntype PositionProps = Parameters<typeof useTooltipPosition>[0];\n\n/** Readiness lives with the mounted overlay, not a trigger ref's attach/detach cycle. */\nexport function TooltipPositioner({\n children,\n ...position\n}: Omit<PositionProps, \"open\" | \"onPosition\"> & {\n children: (ready: boolean, present: boolean, side: TooltipSide) => ReactNode;\n}) {\n const present = useIsPresent();\n const [ready, setReady] = useState(false);\n const [side, setSide] = useState<TooltipSide>(position.side);\n const onPosition = useCallback((placed: TooltipSide) => {\n setReady(true);\n setSide(placed);\n }, []);\n useTooltipPosition({ ...position, open: present, onPosition });\n return (\n <span\n ref={position.floatingRef}\n inert={!present}\n aria-hidden={!present || undefined}\n className=\"pointer-events-none fixed top-0 left-0 z-[9999] w-max\"\n style={{ visibility: \"hidden\", maxWidth: \"calc(100vw - 16px)\" }}\n >\n {children(ready, present, side)}\n </span>\n );\n}\n\n// Each arrow is a 12px box whose base sits on the surface's inner border edge,\n// so its fill covers the border beneath it and only the two outer edges stroke.\nconst ARROW: Record<TooltipSide, { path: string; style: CSSProperties }> = {\n top: { path: \"M0 6L6 12L12 6\", style: { top: \"calc(100% - 6px)\" } },\n bottom: { path: \"M0 6L6 0L12 6\", style: { bottom: \"calc(100% - 6px)\" } },\n left: { path: \"M6 0L12 6L6 12\", style: { left: \"calc(100% - 6px)\" } },\n right: { path: \"M6 0L0 6L6 12\", style: { right: \"calc(100% - 6px)\" } },\n};\n\nexport function TooltipArrow({ side, ref }: { side: TooltipSide; ref: Ref<SVGSVGElement> }) {\n const { path, style } = ARROW[side];\n return (\n <svg\n ref={ref}\n aria-hidden=\"true\"\n width=\"12\"\n height=\"12\"\n viewBox=\"0 0 12 12\"\n className=\"pointer-events-none absolute overflow-visible\"\n style={style}\n >\n <path d={`${path}Z`} style={{ fill: \"var(--tooltip-arrow-fill, transparent)\" }} />\n <path\n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