@kumix/ui 0.3.5 → 0.3.7
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/dist/components/agents/ai-sidebar.d.ts +17 -1
- package/dist/components/agents/ai-sidebar.d.ts.map +1 -1
- package/dist/components/agents/ai-sidebar.js +90 -14
- package/dist/components/agents/ai-sidebar.js.map +1 -1
- package/dist/components/agents/chat-app.d.ts +10 -5
- package/dist/components/agents/chat-app.d.ts.map +1 -1
- package/dist/components/agents/chat-app.js +54 -5
- package/dist/components/agents/chat-app.js.map +1 -1
- package/dist/components/agents/citations.d.ts.map +1 -1
- package/dist/components/agents/citations.js +5 -6
- package/dist/components/agents/citations.js.map +1 -1
- package/dist/components/agents/tool-approval.d.ts.map +1 -1
- package/dist/components/agents/tool-approval.js +1 -1
- package/dist/components/agents/tool-approval.js.map +1 -1
- package/dist/components/motion/action-swap.d.ts.map +1 -1
- package/dist/components/motion/action-swap.js +11 -16
- package/dist/components/motion/action-swap.js.map +1 -1
- package/dist/components/motion/animated-sidebar.js +1 -0
- package/dist/components/motion/animated-sidebar.js.map +1 -1
- package/dist/components/motion/availability-scheduler/copy-menu.js +1 -1
- package/dist/components/motion/availability-scheduler/day-row.d.ts +5 -2
- package/dist/components/motion/availability-scheduler/day-row.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/day-row.js +18 -8
- package/dist/components/motion/availability-scheduler/day-row.js.map +1 -1
- package/dist/components/motion/availability-scheduler/index.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/index.js +27 -5
- package/dist/components/motion/availability-scheduler/index.js.map +1 -1
- package/dist/components/motion/availability-scheduler/time-select.d.ts +3 -1
- package/dist/components/motion/availability-scheduler/time-select.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/time-select.js +3 -1
- package/dist/components/motion/availability-scheduler/time-select.js.map +1 -1
- package/dist/components/motion/bottom-sheet.d.ts.map +1 -1
- package/dist/components/motion/bottom-sheet.js +26 -7
- package/dist/components/motion/bottom-sheet.js.map +1 -1
- package/dist/components/motion/combobox/list.js +2 -2
- package/dist/components/motion/combobox/list.js.map +1 -1
- package/dist/components/motion/command-palette.d.ts.map +1 -1
- package/dist/components/motion/command-palette.js +3 -1
- package/dist/components/motion/command-palette.js.map +1 -1
- package/dist/components/motion/context-menu.d.ts.map +1 -1
- package/dist/components/motion/context-menu.js +16 -6
- package/dist/components/motion/context-menu.js.map +1 -1
- package/dist/components/motion/cylinder-carousel.d.ts.map +1 -1
- package/dist/components/motion/cylinder-carousel.js +4 -3
- package/dist/components/motion/cylinder-carousel.js.map +1 -1
- package/dist/components/motion/expandable-action-bar.d.ts +6 -0
- package/dist/components/motion/expandable-action-bar.d.ts.map +1 -1
- package/dist/components/motion/expandable-action-bar.js +38 -9
- package/dist/components/motion/expandable-action-bar.js.map +1 -1
- package/dist/components/motion/hold-action-button.d.ts +1 -1
- package/dist/components/motion/hold-action-button.d.ts.map +1 -1
- package/dist/components/motion/hold-action-button.js +64 -50
- package/dist/components/motion/hold-action-button.js.map +1 -1
- package/dist/components/motion/morphing-tabs.d.ts.map +1 -1
- package/dist/components/motion/morphing-tabs.js +59 -18
- package/dist/components/motion/morphing-tabs.js.map +1 -1
- package/dist/components/motion/notification-stack.d.ts.map +1 -1
- package/dist/components/motion/notification-stack.js +28 -11
- package/dist/components/motion/notification-stack.js.map +1 -1
- package/dist/components/motion/popover-morph.d.ts.map +1 -1
- package/dist/components/motion/popover-morph.js +26 -11
- package/dist/components/motion/popover-morph.js.map +1 -1
- package/dist/components/motion/popover.d.ts.map +1 -1
- package/dist/components/motion/popover.js +39 -28
- package/dist/components/motion/popover.js.map +1 -1
- package/dist/components/motion/preview-rail.d.ts.map +1 -1
- package/dist/components/motion/preview-rail.js +42 -13
- package/dist/components/motion/preview-rail.js.map +1 -1
- package/dist/components/motion/project-folder.d.ts +27 -0
- package/dist/components/motion/project-folder.d.ts.map +1 -0
- package/dist/components/motion/project-folder.js +310 -0
- package/dist/components/motion/project-folder.js.map +1 -0
- package/dist/components/motion/pull-to-refresh.d.ts.map +1 -1
- package/dist/components/motion/pull-to-refresh.js +8 -7
- package/dist/components/motion/pull-to-refresh.js.map +1 -1
- package/dist/components/motion/range-slider-bubble.d.ts.map +1 -1
- package/dist/components/motion/range-slider-bubble.js +2 -1
- package/dist/components/motion/range-slider-bubble.js.map +1 -1
- package/dist/components/motion/range-slider-fluid.d.ts.map +1 -1
- package/dist/components/motion/range-slider-fluid.js +2 -1
- package/dist/components/motion/range-slider-fluid.js.map +1 -1
- package/dist/components/motion/range-slider-ruler.d.ts.map +1 -1
- package/dist/components/motion/range-slider-ruler.js +2 -1
- package/dist/components/motion/range-slider-ruler.js.map +1 -1
- package/dist/components/motion/range-slider-wave.d.ts.map +1 -1
- package/dist/components/motion/range-slider-wave.js +2 -1
- package/dist/components/motion/range-slider-wave.js.map +1 -1
- package/dist/components/motion/range-slider.d.ts.map +1 -1
- package/dist/components/motion/range-slider.js +2 -1
- package/dist/components/motion/range-slider.js.map +1 -1
- package/dist/components/motion/select.d.ts +15 -1
- package/dist/components/motion/select.d.ts.map +1 -1
- package/dist/components/motion/select.js +15 -4
- package/dist/components/motion/select.js.map +1 -1
- package/dist/components/motion/slide-action-button.d.ts.map +1 -1
- package/dist/components/motion/slide-action-button.js +3 -2
- package/dist/components/motion/slide-action-button.js.map +1 -1
- package/dist/components/motion/swipeable-list.d.ts.map +1 -1
- package/dist/components/motion/swipeable-list.js +2 -1
- package/dist/components/motion/swipeable-list.js.map +1 -1
- package/dist/components/motion/table/index.d.ts.map +1 -1
- package/dist/components/motion/table/index.js +64 -6
- package/dist/components/motion/table/index.js.map +1 -1
- package/dist/components/motion/table/table-header.d.ts.map +1 -1
- package/dist/components/motion/table/table-header.js +3 -2
- package/dist/components/motion/table/table-header.js.map +1 -1
- package/dist/components/motion/tabs.d.ts.map +1 -1
- package/dist/components/motion/tabs.js +2 -0
- package/dist/components/motion/tabs.js.map +1 -1
- package/dist/components/motion/text-reveal.d.ts.map +1 -1
- package/dist/components/motion/text-reveal.js +72 -48
- package/dist/components/motion/text-reveal.js.map +1 -1
- package/dist/components/motion/tooltip.d.ts.map +1 -1
- package/dist/components/motion/tooltip.js +35 -15
- package/dist/components/motion/tooltip.js.map +1 -1
- package/dist/components/motion/wheel-picker.d.ts.map +1 -1
- package/dist/components/motion/wheel-picker.js +4 -3
- package/dist/components/motion/wheel-picker.js.map +1 -1
- package/dist/components/reui/alert.d.ts +1 -1
- package/dist/components/reui/badge.d.ts +2 -2
- package/dist/components/reui/frame.d.ts +2 -2
- package/dist/components/reui/icon-tile.d.ts +2 -2
- package/dist/components/ui/attachment.d.ts +1 -1
- 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/field.d.ts +1 -1
- package/dist/components/ui/item.d.ts +1 -1
- package/dist/components/ui/sidebar.d.ts +1 -1
- package/dist/components/ui/toggle.d.ts +1 -1
- package/dist/{copy-menu-Bk5GP9Gp.js → copy-menu-1FKoMc9o.js} +9 -2
- package/dist/copy-menu-1FKoMc9o.js.map +1 -0
- package/dist/hooks/use-dismiss.d.ts +34 -0
- package/dist/hooks/use-dismiss.d.ts.map +1 -0
- package/dist/hooks/use-dismiss.js +78 -0
- package/dist/hooks/use-dismiss.js.map +1 -0
- package/dist/hooks/use-favicon.d.ts +17 -0
- package/dist/hooks/use-favicon.d.ts.map +1 -0
- package/dist/hooks/use-favicon.js +35 -0
- package/dist/hooks/use-favicon.js.map +1 -0
- package/dist/hooks/use-hover-gesture.d.ts +38 -0
- package/dist/hooks/use-hover-gesture.d.ts.map +1 -0
- package/dist/hooks/use-hover-gesture.js +46 -0
- package/dist/hooks/use-hover-gesture.js.map +1 -0
- package/dist/hooks/use-slider.d.ts.map +1 -1
- package/dist/hooks/use-slider.js +3 -2
- package/dist/hooks/use-slider.js.map +1 -1
- package/dist/hooks/use-tap-gesture.d.ts +47 -0
- package/dist/hooks/use-tap-gesture.d.ts.map +1 -0
- package/dist/hooks/use-tap-gesture.js +51 -0
- package/dist/hooks/use-tap-gesture.js.map +1 -0
- package/dist/hooks/use-touch-capable.d.ts +15 -0
- package/dist/hooks/use-touch-capable.d.ts.map +1 -0
- package/dist/hooks/use-touch-capable.js +29 -0
- package/dist/hooks/use-touch-capable.js.map +1 -0
- package/dist/lib/touch.d.ts +66 -0
- package/dist/lib/touch.d.ts.map +1 -0
- package/dist/lib/touch.js +79 -0
- package/dist/lib/touch.js.map +1 -0
- package/dist/types-smkWN_7x.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/copy-menu-Bk5GP9Gp.js.map +0 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { useDismiss } from "../../hooks/use-dismiss.js";
|
|
3
|
+
import { useHoverGesture } from "../../hooks/use-hover-gesture.js";
|
|
4
|
+
import { useTapGesture } from "../../hooks/use-tap-gesture.js";
|
|
3
5
|
import { EASE_OUT, SPRING_LAYOUT } from "../../lib/ease.js";
|
|
4
6
|
import { ActionSwapText } from "./action-swap.js";
|
|
5
7
|
import { useCallback, useRef, useState } from "react";
|
|
@@ -38,13 +40,21 @@ function NotificationCardContent({ item, classNames }) {
|
|
|
38
40
|
}
|
|
39
41
|
function NotificationStack({ items, expanded, defaultExpanded = false, onExpandedChange, onViewAll, maxVisible = 3, collapsedLabel = "Notifications", expandedLabel = "View all", emptyLabel = "All caught up", className, classNames }) {
|
|
40
42
|
const reduce = useReducedMotion();
|
|
41
|
-
const canHover = useHoverCapable();
|
|
42
43
|
const hasFocus = useRef(false);
|
|
44
|
+
const rootRef = useRef(null);
|
|
45
|
+
const hover = useHoverGesture();
|
|
46
|
+
const tap = useTapGesture();
|
|
43
47
|
const [isExpanded, setIsExpanded] = useControllableExpanded({
|
|
44
48
|
expanded,
|
|
45
49
|
defaultExpanded,
|
|
46
50
|
onExpandedChange
|
|
47
51
|
});
|
|
52
|
+
const [tapExpanded, setTapExpanded] = useState(false);
|
|
53
|
+
const collapse = useCallback(() => {
|
|
54
|
+
setTapExpanded(false);
|
|
55
|
+
setIsExpanded(false);
|
|
56
|
+
}, [setIsExpanded]);
|
|
57
|
+
useDismiss(tapExpanded && isExpanded, collapse, rootRef, { behavior: "consume" });
|
|
48
58
|
const visibleItems = items.slice(0, Math.max(1, maxVisible));
|
|
49
59
|
const primaryItem = visibleItems[0];
|
|
50
60
|
const transition = reduce ? { duration: 0 } : SPRING_LAYOUT;
|
|
@@ -66,36 +76,43 @@ function NotificationStack({ items, expanded, defaultExpanded = false, onExpande
|
|
|
66
76
|
const handleBlur = (event) => {
|
|
67
77
|
if (event.currentTarget.contains(event.relatedTarget)) return;
|
|
68
78
|
hasFocus.current = false;
|
|
69
|
-
|
|
79
|
+
collapse();
|
|
70
80
|
};
|
|
71
81
|
const handleKeyDown = (event) => {
|
|
82
|
+
tap.drop();
|
|
72
83
|
if (event.key !== "Escape") return;
|
|
73
84
|
event.preventDefault();
|
|
74
|
-
|
|
75
|
-
event.currentTarget.blur();
|
|
85
|
+
collapse();
|
|
76
86
|
};
|
|
77
87
|
const handleClick = () => {
|
|
78
|
-
|
|
88
|
+
const gesture = tap.take();
|
|
89
|
+
if (!(gesture ? gesture.state : isExpanded)) {
|
|
79
90
|
setIsExpanded(true);
|
|
91
|
+
if (gesture && gesture.pointerType !== "mouse") setTapExpanded(true);
|
|
80
92
|
return;
|
|
81
93
|
}
|
|
82
94
|
if (onViewAll) {
|
|
83
95
|
onViewAll();
|
|
84
96
|
return;
|
|
85
97
|
}
|
|
86
|
-
|
|
98
|
+
collapse();
|
|
87
99
|
};
|
|
88
100
|
return /* @__PURE__ */ jsxs(motion.button, {
|
|
101
|
+
ref: rootRef,
|
|
89
102
|
type: "button",
|
|
90
103
|
initial: false,
|
|
91
104
|
"aria-expanded": isExpanded,
|
|
92
105
|
"aria-label": isExpanded ? `${items.length} notifications. ${expandedLabel}.` : `${items.length} notifications. Expand notifications.`,
|
|
93
|
-
onPointerEnter: () => {
|
|
94
|
-
if (
|
|
106
|
+
onPointerEnter: (event) => {
|
|
107
|
+
if (hover.enter(event)) setIsExpanded(true);
|
|
108
|
+
},
|
|
109
|
+
onPointerLeave: (event) => {
|
|
110
|
+
if (hover.leave(event) && !hasFocus.current) collapse();
|
|
95
111
|
},
|
|
96
|
-
|
|
97
|
-
|
|
112
|
+
onPointerDown: (event) => {
|
|
113
|
+
tap.start(event, isExpanded);
|
|
98
114
|
},
|
|
115
|
+
onPointerCancel: tap.drop,
|
|
99
116
|
onFocus: () => {
|
|
100
117
|
hasFocus.current = true;
|
|
101
118
|
setIsExpanded(true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-stack.js","names":[],"sources":["../../../src/components/motion/notification-stack.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type FocusEvent,\n type KeyboardEvent,\n type ReactNode,\n useCallback,\n useRef,\n useState,\n} from \"react\";\nimport { ArrowUpRight, BellOff } from \"lucide-react\";\nimport { motion, type Transition, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useHoverCapable } from \"../../hooks/use-hover-capable\";\nimport { EASE_OUT, SPRING_LAYOUT } from \"../../lib/ease\";\nimport { ActionSwapText } from \"./action-swap\";\n\nexport type NotificationStackItem = {\n id: string;\n title: ReactNode;\n description?: ReactNode;\n trailing?: ReactNode;\n};\n\nexport type NotificationStackClassNames = {\n stack?: string;\n card?: string;\n content?: string;\n title?: string;\n description?: string;\n trailing?: string;\n footer?: string;\n count?: string;\n};\n\nexport interface NotificationStackProps {\n items: NotificationStackItem[];\n expanded?: boolean;\n defaultExpanded?: boolean;\n onExpandedChange?: (expanded: boolean) => void;\n onViewAll?: () => void;\n maxVisible?: number;\n collapsedLabel?: string;\n expandedLabel?: string;\n emptyLabel?: string;\n className?: string;\n classNames?: NotificationStackClassNames;\n}\n\nconst STACK_PEEK = 8;\nconst STACK_INSET = 12;\n\nfunction useControllableExpanded({\n expanded,\n defaultExpanded,\n onExpandedChange,\n}: {\n expanded?: boolean;\n defaultExpanded: boolean;\n onExpandedChange?: (expanded: boolean) => void;\n}) {\n const [internalExpanded, setInternalExpanded] = useState(defaultExpanded);\n const isControlled = expanded !== undefined;\n const value = expanded ?? internalExpanded;\n\n const setValue = useCallback(\n (next: boolean) => {\n if (!isControlled) setInternalExpanded(next);\n onExpandedChange?.(next);\n },\n [isControlled, onExpandedChange],\n );\n\n return [value, setValue] as const;\n}\n\nfunction NotificationCardContent({\n item,\n classNames,\n}: {\n item: NotificationStackItem;\n classNames?: NotificationStackClassNames;\n}) {\n return (\n <span className={cn(\"flex min-w-0 flex-col gap-1.5 py-4\", classNames?.content)}>\n <span className=\"flex min-w-0 items-start justify-between gap-3\">\n <span className={cn(\"min-w-0 font-medium text-sm leading-snug\", classNames?.title)}>\n {item.title}\n </span>\n {item.trailing ? (\n <span className={cn(\"shrink-0 text-xs\", classNames?.trailing)}>{item.trailing}</span>\n ) : null}\n </span>\n {item.description ? (\n <span\n className={cn(\"text-muted-foreground text-xs leading-relaxed\", classNames?.description)}\n >\n {item.description}\n </span>\n ) : null}\n </span>\n );\n}\n\nexport function NotificationStack({\n items,\n expanded,\n defaultExpanded = false,\n onExpandedChange,\n onViewAll,\n maxVisible = 3,\n collapsedLabel = \"Notifications\",\n expandedLabel = \"View all\",\n emptyLabel = \"All caught up\",\n className,\n classNames,\n}: NotificationStackProps) {\n const reduce = useReducedMotion();\n const canHover = useHoverCapable();\n const hasFocus = useRef(false);\n const [isExpanded, setIsExpanded] = useControllableExpanded({\n expanded,\n defaultExpanded,\n onExpandedChange,\n });\n\n const visibleItems = items.slice(0, Math.max(1, maxVisible));\n const primaryItem = visibleItems[0];\n const transition: Transition = reduce ? { duration: 0 } : SPRING_LAYOUT;\n const cardTransition: Transition = reduce ? { duration: 0 } : { duration: 0.32, ease: EASE_OUT };\n const backgroundTransition: Transition = reduce\n ? { duration: 0 }\n : { duration: 0.26, ease: EASE_OUT };\n\n if (!primaryItem) {\n return (\n <div\n className={cn(\n \"flex w-full max-w-[22rem] items-center justify-center gap-2 rounded-3xl bg-muted/70 px-5 py-8 font-medium text-muted-foreground text-sm\",\n className,\n )}\n >\n <BellOff className=\"h-4 w-4\" aria-hidden=\"true\" />\n {emptyLabel}\n </div>\n );\n }\n\n const handleBlur = (event: FocusEvent<HTMLButtonElement>) => {\n if (event.currentTarget.contains(event.relatedTarget)) return;\n hasFocus.current = false;\n setIsExpanded(false);\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.key !== \"Escape\") return;\n event.preventDefault();\n setIsExpanded(false);\n event.currentTarget.blur();\n };\n\n const handleClick = () => {\n if (!isExpanded) {\n setIsExpanded(true);\n return;\n }\n\n if (onViewAll) {\n onViewAll();\n return;\n }\n\n setIsExpanded(false);\n };\n\n return (\n <motion.button\n type=\"button\"\n initial={false}\n aria-expanded={isExpanded}\n aria-label={\n isExpanded\n ? `${items.length} notifications. ${expandedLabel}.`\n : `${items.length} notifications. Expand notifications.`\n }\n onPointerEnter={() => {\n if (canHover) setIsExpanded(true);\n }}\n onPointerLeave={() => {\n if (canHover && !hasFocus.current) setIsExpanded(false);\n }}\n onFocus={() => {\n hasFocus.current = true;\n setIsExpanded(true);\n }}\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n onClick={handleClick}\n className={cn(\n \"relative z-10 block w-full max-w-[22rem] cursor-pointer rounded-3xl text-left text-foreground outline-none\",\n \"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n className,\n )}\n >\n {/* This invisible first card gives the button its compact intrinsic footprint. */}\n <span aria-hidden=\"true\" className=\"invisible block p-3\">\n <span className=\"block\">\n <span\n className={cn(\"block rounded-2xl border border-transparent px-4\", classNames?.card)}\n >\n <NotificationCardContent item={primaryItem} classNames={classNames} />\n </span>\n </span>\n <span className=\"mt-2 block h-9\" />\n </span>\n\n <span className=\"absolute inset-x-0 bottom-0 block p-3\">\n <motion.span\n aria-hidden=\"true\"\n layout\n initial={false}\n transition={backgroundTransition}\n className=\"absolute inset-0 rounded-3xl bg-muted\"\n />\n <span className={cn(\"relative z-10 grid gap-1\", !isExpanded && \"pb-2\", classNames?.stack)}>\n {visibleItems.map((item, index) => {\n const isPrimary = index === 0;\n\n return (\n <motion.span\n key={item.id}\n layout=\"position\"\n initial={false}\n animate={{\n y: isExpanded ? 0 : index * STACK_PEEK,\n clipPath: isExpanded\n ? \"inset(0px 0px round 16px)\"\n : `inset(0px ${index * STACK_INSET}px round 16px)`,\n }}\n transition={cardTransition}\n className={cn(\n \"block rounded-2xl border border-border/60 bg-background px-4\",\n classNames?.card,\n )}\n style={{\n zIndex: visibleItems.length - index,\n gridColumn: 1,\n gridRow: isExpanded ? index + 1 : 1,\n }}\n >\n <span className={cn(\"block\", !isPrimary && !isExpanded && \"invisible\")}>\n <NotificationCardContent item={item} classNames={classNames} />\n </span>\n </motion.span>\n );\n })}\n </span>\n\n <motion.span\n layout=\"position\"\n transition={transition}\n className={cn(\n \"relative z-10 mt-2 flex min-h-9 items-center gap-2 px-1\",\n classNames?.footer,\n )}\n >\n <span\n className={cn(\n \"grid size-7 shrink-0 place-items-center rounded-full bg-orange-600 font-medium text-white text-xs shadow-[inset_0_1px_2px_rgb(0_0_0/0.2),inset_0_-1px_0_rgb(255_255_255/0.16)] dark:bg-orange-500\",\n classNames?.count,\n )}\n >\n {items.length}\n </span>\n <span className=\"flex items-center font-medium text-sm\">\n <ActionSwapText value={isExpanded ? \"expanded\" : \"collapsed\"} animation=\"roll\">\n {isExpanded ? (\n <span className=\"inline-flex items-center gap-1\">\n {expandedLabel}\n <ArrowUpRight className=\"size-4\" aria-hidden=\"true\" />\n </span>\n ) : (\n collapsedLabel\n )}\n </ActionSwapText>\n </span>\n </motion.span>\n </span>\n </motion.button>\n );\n}\n"],"mappings":";;;;;;;;;;AAkDA,MAAM,a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A,IAAA;MAEY,CAAA;KACZ,CAAA,CACK;;GACT;EACO,CAAA,CAAA;;AAEnB"}
|
|
1
|
+
{"version":3,"file":"notification-stack.js","names":[],"sources":["../../../src/components/motion/notification-stack.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type FocusEvent,\n type KeyboardEvent,\n type PointerEvent,\n type ReactNode,\n useCallback,\n useRef,\n useState,\n} from \"react\";\nimport { ArrowUpRight, BellOff } from \"lucide-react\";\nimport { motion, type Transition, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useDismiss } from \"../../hooks/use-dismiss\";\nimport { useHoverGesture } from \"../../hooks/use-hover-gesture\";\nimport { useTapGesture } from \"../../hooks/use-tap-gesture\";\nimport { EASE_OUT, SPRING_LAYOUT } from \"../../lib/ease\";\nimport { ActionSwapText } from \"./action-swap\";\n\nexport type NotificationStackItem = {\n id: string;\n title: ReactNode;\n description?: ReactNode;\n trailing?: ReactNode;\n};\n\nexport type NotificationStackClassNames = {\n stack?: string;\n card?: string;\n content?: string;\n title?: string;\n description?: string;\n trailing?: string;\n footer?: string;\n count?: string;\n};\n\nexport interface NotificationStackProps {\n items: NotificationStackItem[];\n expanded?: boolean;\n defaultExpanded?: boolean;\n onExpandedChange?: (expanded: boolean) => void;\n onViewAll?: () => void;\n maxVisible?: number;\n collapsedLabel?: string;\n expandedLabel?: string;\n emptyLabel?: string;\n className?: string;\n classNames?: NotificationStackClassNames;\n}\n\nconst STACK_PEEK = 8;\nconst STACK_INSET = 12;\n\nfunction useControllableExpanded({\n expanded,\n defaultExpanded,\n onExpandedChange,\n}: {\n expanded?: boolean;\n defaultExpanded: boolean;\n onExpandedChange?: (expanded: boolean) => void;\n}) {\n const [internalExpanded, setInternalExpanded] = useState(defaultExpanded);\n const isControlled = expanded !== undefined;\n const value = expanded ?? internalExpanded;\n\n const setValue = useCallback(\n (next: boolean) => {\n if (!isControlled) setInternalExpanded(next);\n onExpandedChange?.(next);\n },\n [isControlled, onExpandedChange],\n );\n\n return [value, setValue] as const;\n}\n\nfunction NotificationCardContent({\n item,\n classNames,\n}: {\n item: NotificationStackItem;\n classNames?: NotificationStackClassNames;\n}) {\n return (\n <span className={cn(\"flex min-w-0 flex-col gap-1.5 py-4\", classNames?.content)}>\n <span className=\"flex min-w-0 items-start justify-between gap-3\">\n <span className={cn(\"min-w-0 font-medium text-sm leading-snug\", classNames?.title)}>\n {item.title}\n </span>\n {item.trailing ? (\n <span className={cn(\"shrink-0 text-xs\", classNames?.trailing)}>{item.trailing}</span>\n ) : null}\n </span>\n {item.description ? (\n <span\n className={cn(\"text-muted-foreground text-xs leading-relaxed\", classNames?.description)}\n >\n {item.description}\n </span>\n ) : null}\n </span>\n );\n}\n\nexport function NotificationStack({\n items,\n expanded,\n defaultExpanded = false,\n onExpandedChange,\n onViewAll,\n maxVisible = 3,\n collapsedLabel = \"Notifications\",\n expandedLabel = \"View all\",\n emptyLabel = \"All caught up\",\n className,\n classNames,\n}: NotificationStackProps) {\n const reduce = useReducedMotion();\n const hasFocus = useRef(false);\n const rootRef = useRef<HTMLButtonElement>(null);\n const hover = useHoverGesture();\n // What the last gesture on the stack was, and whether it was already\n // expanded when that gesture started. A click reports neither.\n const tap = useTapGesture<boolean>();\n const [isExpanded, setIsExpanded] = useControllableExpanded({\n expanded,\n defaultExpanded,\n onExpandedChange,\n });\n // Set by the tap that expands the stack, and the reason the outside-tap\n // dismisser exists at all — a hovering pointer has its own way out.\n const [tapExpanded, setTapExpanded] = useState(false);\n\n const collapse = useCallback(() => {\n setTapExpanded(false);\n setIsExpanded(false);\n }, [setIsExpanded]);\n\n // A pointer leaving the stack is what collapses it, and a finger never\n // leaves: without this the stack stays open for good once tapped, and when\n // `onViewAll` is set the next tap follows the link instead of closing. The\n // tap that lands somewhere else stands in for the pointer leaving, and it is\n // consumed rather than passed through — the expanded stack covers the page,\n // so the tap that dismisses it is aimed at nothing else.\n useDismiss(tapExpanded && isExpanded, collapse, rootRef, {\n behavior: \"consume\",\n });\n\n const visibleItems = items.slice(0, Math.max(1, maxVisible));\n const primaryItem = visibleItems[0];\n const transition: Transition = reduce ? { duration: 0 } : SPRING_LAYOUT;\n const cardTransition: Transition = reduce ? { duration: 0 } : { duration: 0.32, ease: EASE_OUT };\n const backgroundTransition: Transition = reduce\n ? { duration: 0 }\n : { duration: 0.26, ease: EASE_OUT };\n\n if (!primaryItem) {\n return (\n <div\n className={cn(\n \"flex w-full max-w-[22rem] items-center justify-center gap-2 rounded-3xl bg-muted/70 px-5 py-8 font-medium text-muted-foreground text-sm\",\n className,\n )}\n >\n <BellOff className=\"h-4 w-4\" aria-hidden=\"true\" />\n {emptyLabel}\n </div>\n );\n }\n\n const handleBlur = (event: FocusEvent<HTMLButtonElement>) => {\n if (event.currentTarget.contains(event.relatedTarget)) return;\n hasFocus.current = false;\n collapse();\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n // A key press is the start of a keyboard activation, never part of a tap:\n // whatever a taken-away gesture left behind must not be read as one.\n tap.drop();\n if (event.key !== \"Escape\") return;\n event.preventDefault();\n collapse();\n // Focus stays where the keyboard put it. Blurring here collapsed the stack\n // *and* threw the user back to the top of the document.\n };\n\n const handleClick = () => {\n const gesture = tap.take();\n // Read from where the gesture started, not from now: a browser that\n // focuses the stack on contact expands it mid-tap, and the first tap would\n // then follow `onViewAll` instead of opening the list it was meant to.\n const wasExpanded = gesture ? gesture.state : isExpanded;\n\n if (!wasExpanded) {\n setIsExpanded(true);\n if (gesture && gesture.pointerType !== \"mouse\") setTapExpanded(true);\n return;\n }\n\n if (onViewAll) {\n onViewAll();\n return;\n }\n\n collapse();\n };\n\n return (\n <motion.button\n ref={rootRef}\n type=\"button\"\n initial={false}\n aria-expanded={isExpanded}\n aria-label={\n isExpanded\n ? `${items.length} notifications. ${expandedLabel}.`\n : `${items.length} notifications. Expand notifications.`\n }\n // A tap reports as a hover on its way past — enter, leave, then click —\n // so an unfiltered hover path expands, collapses and expands again in\n // the space of one tap, springs and all. The tap has its own route\n // through `handleClick`.\n onPointerEnter={(event: PointerEvent<HTMLButtonElement>) => {\n if (hover.enter(event)) setIsExpanded(true);\n }}\n onPointerLeave={(event: PointerEvent<HTMLButtonElement>) => {\n if (hover.leave(event) && !hasFocus.current) collapse();\n }}\n onPointerDown={(event: PointerEvent<HTMLButtonElement>) => {\n tap.start(event, isExpanded);\n }}\n // The platform can take the gesture away mid-press — a scroll, a system\n // swipe — and no click follows it.\n onPointerCancel={tap.drop}\n onFocus={() => {\n hasFocus.current = true;\n setIsExpanded(true);\n }}\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n onClick={handleClick}\n className={cn(\n \"relative z-10 block w-full max-w-[22rem] cursor-pointer rounded-3xl text-left text-foreground outline-none\",\n \"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n className,\n )}\n >\n {/* This invisible first card gives the button its compact intrinsic footprint. */}\n <span aria-hidden=\"true\" className=\"invisible block p-3\">\n <span className=\"block\">\n <span\n className={cn(\"block rounded-2xl border border-transparent px-4\", classNames?.card)}\n >\n <NotificationCardContent item={primaryItem} classNames={classNames} />\n </span>\n </span>\n <span className=\"mt-2 block h-9\" />\n </span>\n\n <span className=\"absolute inset-x-0 bottom-0 block p-3\">\n <motion.span\n aria-hidden=\"true\"\n layout\n initial={false}\n transition={backgroundTransition}\n className=\"absolute inset-0 rounded-3xl bg-muted\"\n />\n <span className={cn(\"relative z-10 grid gap-1\", !isExpanded && \"pb-2\", classNames?.stack)}>\n {visibleItems.map((item, index) => {\n const isPrimary = index === 0;\n\n return (\n <motion.span\n key={item.id}\n layout=\"position\"\n initial={false}\n animate={{\n y: isExpanded ? 0 : index * STACK_PEEK,\n clipPath: isExpanded\n ? \"inset(0px 0px round 16px)\"\n : `inset(0px ${index * STACK_INSET}px round 16px)`,\n }}\n transition={cardTransition}\n className={cn(\n \"block rounded-2xl border border-border/60 bg-background px-4\",\n classNames?.card,\n )}\n style={{\n zIndex: visibleItems.length - index,\n gridColumn: 1,\n gridRow: isExpanded ? index + 1 : 1,\n }}\n >\n <span className={cn(\"block\", !isPrimary && !isExpanded && \"invisible\")}>\n <NotificationCardContent item={item} classNames={classNames} />\n </span>\n </motion.span>\n );\n })}\n </span>\n\n <motion.span\n layout=\"position\"\n transition={transition}\n className={cn(\n \"relative z-10 mt-2 flex min-h-9 items-center gap-2 px-1\",\n classNames?.footer,\n )}\n >\n <span\n className={cn(\n \"grid size-7 shrink-0 place-items-center rounded-full bg-orange-600 font-medium text-white text-xs shadow-[inset_0_1px_2px_rgb(0_0_0/0.2),inset_0_-1px_0_rgb(255_255_255/0.16)] dark:bg-orange-500\",\n classNames?.count,\n )}\n >\n {items.length}\n </span>\n <span className=\"flex items-center font-medium text-sm\">\n <ActionSwapText value={isExpanded ? \"expanded\" : \"collapsed\"} animation=\"roll\">\n {isExpanded ? (\n <span className=\"inline-flex items-center gap-1\">\n {expandedLabel}\n <ArrowUpRight className=\"size-4\" aria-hidden=\"true\" />\n </span>\n ) : (\n collapsedLabel\n )}\n </ActionSwapText>\n </span>\n </motion.span>\n </span>\n </motion.button>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAqDA,MAAM,aAAa;AACnB,MAAM,cAAc;AAEpB,SAAS,wBAAwB,EAC/B,UACA,iBACA,oBAKC;CACD,MAAM,CAAC,kBAAkB,uBAAuB,SAAS,eAAe;CACxE,MAAM,eAAe,aAAa,KAAA;CAWlC,OAAO,CAVO,YAAY,kBAET,aACd,SAAkB;EACjB,IAAI,CAAC,cAAc,oBAAoB,IAAI;EAC3C,mBAAmB,IAAI;CACzB,GACA,CAAC,cAAc,gBAAgB,CAGX,CAAC;AACzB;AAEA,SAAS,wBAAwB,EAC/B,MACA,cAIC;CACD,OACE,qBAAC,QAAD;EAAM,WAAW,GAAG,sCAAsC,YAAY,OAAO;EAA7E,UAAA,CACE,qBAAC,QAAD;GAAM,WAAU;GAAhB,UAAA,CACE,oBAAC,QAAD;IAAM,WAA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A;MAEY,CAAA;KACZ,CAAA,CACK;;GACT;EACO,CAAA,CAAA;;AAEnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover-morph.d.ts","names":[],"sources":["../../../src/components/motion/popover-morph.tsx"],"mappings":";;KAwBK;KACA;
|
|
1
|
+
{"version":3,"file":"popover-morph.d.ts","names":[],"sources":["../../../src/components/motion/popover-morph.tsx"],"mappings":";;KAwBK;KACA;UAsBY;EACf,UAAU;;EAEV;;EAEA;EACA,gBAAgB;EAChB;;;;;;;iBAQc,eACd,UACA,MAAM,gBACN,aACA,cACA,aACC,oCAAiB,IAAA;UAoFH;EACf,UAAU;;;iBAcI,sBAAsB,YAAY,2BAAwB,aAAA,kDAAA;UAuCzD;EACf,UAAU;EACV,OAAO;EACP,QAAQ;;EAER;;EAEA;EACA;;iBAGc,sBACd,UACA,MACA,OACA,YACA,QACA,aACC,2CAAwB"}
|
|
@@ -20,8 +20,8 @@ function useMorphContext(component) {
|
|
|
20
20
|
*/
|
|
21
21
|
function MorphPopover({ children, open: controlledOpen, defaultOpen = false, onOpenChange, className }) {
|
|
22
22
|
const baseId = useId();
|
|
23
|
-
const
|
|
24
|
-
const
|
|
23
|
+
const [root, setRoot] = useState(null);
|
|
24
|
+
const [trigger, setTrigger] = useState(null);
|
|
25
25
|
const contentRef = useRef(null);
|
|
26
26
|
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
27
27
|
const controlled = controlledOpen !== void 0;
|
|
@@ -31,12 +31,23 @@ function MorphPopover({ children, open: controlledOpen, defaultOpen = false, onO
|
|
|
31
31
|
onOpenChange?.(next);
|
|
32
32
|
}, [controlled, onOpenChange]);
|
|
33
33
|
const toggle = useCallback(() => setOpen(!open), [setOpen, open]);
|
|
34
|
+
const anchorRef = useMemo(() => ({ current: trigger ?? root }), [root, trigger]);
|
|
35
|
+
const close = useCallback(() => {
|
|
36
|
+
setOpen(false);
|
|
37
|
+
const focused = document.activeElement;
|
|
38
|
+
if (!(focused instanceof HTMLElement && contentRef.current?.contains(focused))) return;
|
|
39
|
+
(trigger ?? (root && root.tabIndex >= 0 ? root : null))?.focus();
|
|
40
|
+
}, [
|
|
41
|
+
root,
|
|
42
|
+
setOpen,
|
|
43
|
+
trigger
|
|
44
|
+
]);
|
|
34
45
|
useEffect(() => {
|
|
35
46
|
if (!open) return;
|
|
36
|
-
const onKey = (e) => e.key === "Escape" &&
|
|
47
|
+
const onKey = (e) => e.key === "Escape" && close();
|
|
37
48
|
const onPointer = (e) => {
|
|
38
49
|
const target = e.target;
|
|
39
|
-
if (
|
|
50
|
+
if (root && !root.contains(target) && !contentRef.current?.contains(target)) close();
|
|
40
51
|
};
|
|
41
52
|
window.addEventListener("keydown", onKey);
|
|
42
53
|
window.addEventListener("pointerdown", onPointer);
|
|
@@ -44,25 +55,31 @@ function MorphPopover({ children, open: controlledOpen, defaultOpen = false, onO
|
|
|
44
55
|
window.removeEventListener("keydown", onKey);
|
|
45
56
|
window.removeEventListener("pointerdown", onPointer);
|
|
46
57
|
};
|
|
47
|
-
}, [
|
|
58
|
+
}, [
|
|
59
|
+
open,
|
|
60
|
+
root,
|
|
61
|
+
close
|
|
62
|
+
]);
|
|
48
63
|
const ctx = useMemo(() => ({
|
|
49
64
|
open,
|
|
50
65
|
setOpen,
|
|
51
66
|
toggle,
|
|
52
67
|
triggerId: `${baseId}-trigger`,
|
|
53
68
|
contentId: `${baseId}-content`,
|
|
54
|
-
triggerRef,
|
|
69
|
+
triggerRef: anchorRef,
|
|
70
|
+
registerTrigger: setTrigger,
|
|
55
71
|
contentRef
|
|
56
72
|
}), [
|
|
57
73
|
open,
|
|
58
74
|
setOpen,
|
|
59
75
|
toggle,
|
|
60
|
-
baseId
|
|
76
|
+
baseId,
|
|
77
|
+
anchorRef
|
|
61
78
|
]);
|
|
62
79
|
return /* @__PURE__ */ jsx(MorphContext.Provider, {
|
|
63
80
|
value: ctx,
|
|
64
81
|
children: /* @__PURE__ */ jsx("div", {
|
|
65
|
-
ref:
|
|
82
|
+
ref: setRoot,
|
|
66
83
|
className: cn("relative inline-flex", className),
|
|
67
84
|
children
|
|
68
85
|
})
|
|
@@ -83,9 +100,7 @@ function MorphPopoverTrigger({ children }) {
|
|
|
83
100
|
const childRef = child.props.ref;
|
|
84
101
|
return cloneElement(child, {
|
|
85
102
|
id: ctx.triggerId,
|
|
86
|
-
ref: mergeRefs(childRef,
|
|
87
|
-
ctx.triggerRef.current = node;
|
|
88
|
-
}),
|
|
103
|
+
ref: mergeRefs(childRef, ctx.registerTrigger),
|
|
89
104
|
onClick: (e) => {
|
|
90
105
|
childOnClick?.(e);
|
|
91
106
|
ctx.toggle();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover-morph.js","names":[],"sources":["../../../src/components/motion/popover-morph.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n cloneElement,\n createContext,\n isValidElement,\n type ReactElement,\n type ReactNode,\n type Ref,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_PANEL } from \"../../lib/ease\";\nimport { usePopoverPortalPosition } from \"./popover-position\";\n\ntype Side = \"top\" | \"bottom\";\ntype Align = \"start\" | \"end\";\n\ntype MorphContextValue = {\n open: boolean;\n setOpen: (open: boolean) => void;\n toggle: () => void;\n triggerId: string;\n contentId: string;\n triggerRef: React.MutableRefObject<HTMLElement | null>;\n contentRef: React.MutableRefObject<HTMLDivElement | null>;\n};\n\nconst MorphContext = createContext<MorphContextValue | null>(null);\n\nfunction useMorphContext(component: string) {\n const ctx = useContext(MorphContext);\n if (!ctx) throw new Error(`${component} must be used within <MorphPopover>`);\n return ctx;\n}\n\nexport interface MorphPopoverProps {\n children: ReactNode;\n /** Controlled open state. */\n open?: boolean;\n /** Uncontrolled initial open state. */\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n className?: string;\n}\n\n/**\n * A popover whose panel morphs open from the trigger corner: it's laid out at\n * full size but clipped to the corner nearest the trigger, then unclips as one\n * piece. Closes on outside pointer / Escape. Controlled or uncontrolled.\n */\nexport function MorphPopover({\n children,\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n className,\n}: MorphPopoverProps) {\n const baseId = useId();\n const rootRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLElement | null>(null);\n const contentRef = useRef<HTMLDivElement | null>(null);\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const controlled = controlledOpen !== undefined;\n const open = controlled ? controlledOpen : internalOpen;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (!controlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [controlled, onOpenChange],\n );\n const toggle = useCallback(() => setOpen(!open), [setOpen, open]);\n\n useEffect(() => {\n if (!open) return;\n const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && setOpen(false);\n const onPointer = (e: PointerEvent) => {\n const target = e.target as Node;\n if (\n rootRef.current &&\n !rootRef.current.contains(target) &&\n !contentRef.current?.contains(target)\n )\n setOpen(false);\n };\n window.addEventListener(\"keydown\", onKey);\n window.addEventListener(\"pointerdown\", onPointer);\n return () => {\n window.removeEventListener(\"keydown\", onKey);\n window.removeEventListener(\"pointerdown\", onPointer);\n };\n }, [open, setOpen]);\n\n const ctx = useMemo<MorphContextValue>(\n () => ({\n open,\n setOpen,\n toggle,\n triggerId: `${baseId}-trigger`,\n contentId: `${baseId}-content`,\n triggerRef,\n contentRef,\n }),\n [open, setOpen, toggle, baseId],\n );\n\n return (\n <MorphContext.Provider value={ctx}>\n <div ref={rootRef} className={cn(\"relative inline-flex\", className)}>\n {children}\n </div>\n </MorphContext.Provider>\n );\n}\n\nexport interface MorphPopoverTriggerProps {\n children: ReactElement;\n}\n\nfunction mergeRefs<T>(...refs: Array<Ref<T> | undefined>) {\n return (node: T | null) => {\n for (const ref of refs) {\n if (typeof ref === \"function\") ref(node);\n else if (ref && typeof ref === \"object\")\n (ref as React.MutableRefObject<T | null>).current = node;\n }\n };\n}\n\n/** Wraps a single element, toggling the popover on click. */\nexport function MorphPopoverTrigger({ children }: MorphPopoverTriggerProps) {\n const ctx = useMorphContext(\"MorphPopoverTrigger\");\n if (!isValidElement(children)) return children;\n\n const child = children as ReactElement<Record<string, unknown>>;\n const childOnClick = child.props.onClick as ((e: unknown) => void) | undefined;\n const childRef = (child.props as { ref?: Ref<HTMLElement> }).ref;\n\n return cloneElement(child, {\n id: ctx.triggerId,\n ref: mergeRefs(childRef, (node: HTMLElement | null) => {\n ctx.triggerRef.current = node;\n }),\n onClick: (e: unknown) => {\n childOnClick?.(e);\n ctx.toggle();\n },\n \"aria-haspopup\": \"dialog\",\n \"aria-expanded\": ctx.open,\n \"aria-controls\": ctx.open ? ctx.contentId : undefined,\n });\n}\n\nconst originFor = (side: Side, align: Align) =>\n `${side === \"bottom\" ? \"top\" : \"bottom\"} ${align === \"end\" ? \"right\" : \"left\"}`;\n\n// A clip that hides everything but the corner nearest the trigger, so the\n// panel appears to grow out of it. inset(top right bottom left).\nfunction clipHidden(side: Side, align: Align, radius: number) {\n const top = side === \"bottom\" ? \"0%\" : \"92%\";\n const bottom = side === \"bottom\" ? \"92%\" : \"0%\";\n const right = align === \"end\" ? \"0%\" : \"92%\";\n const left = align === \"end\" ? \"92%\" : \"0%\";\n return `inset(${top} ${right} ${bottom} ${left} round ${radius}px)`;\n}\nconst clipShown = (radius: number) => `inset(0% 0% 0% 0% round ${radius}px)`;\n\n// Preserve the original spring character on the wrapper, but tween the complex\n// clip-path so it cannot snap when the spring resolves its final distance.\nconst MORPH_CLIP_TRANSITION = { duration: 0.32, ease: EASE_OUT } as const;\n\nexport interface MorphPopoverContentProps {\n children: ReactNode;\n side?: Side;\n align?: Align;\n /** Gap between trigger and panel, in px. Default 8. */\n sideOffset?: number;\n /** Panel corner radius, in px. Default 16. */\n radius?: number;\n className?: string;\n}\n\nexport function MorphPopoverContent({\n children,\n side = \"bottom\",\n align = \"end\",\n sideOffset = 8,\n radius = 16,\n className,\n}: MorphPopoverContentProps) {\n const ctx = useMorphContext(\"MorphPopoverContent\");\n const reduce = useReducedMotion() ?? false;\n const [portalReady, setPortalReady] = useState(false);\n const layout = usePopoverPortalPosition(ctx.triggerRef, ctx.contentRef, portalReady && ctx.open);\n\n useEffect(() => setPortalReady(true), []);\n const left = layout\n ? align === \"end\"\n ? layout.trigger.left + layout.trigger.width - layout.content.width\n : layout.trigger.left\n : 0;\n const top = layout\n ? side === \"bottom\"\n ? layout.trigger.top + layout.trigger.height + sideOffset\n : layout.trigger.top - layout.content.height - sideOffset\n : 0;\n\n // Both directions travel between the exact same hidden/show states. Exit\n // targets \"hidden\" directly instead of introducing separate choreography.\n const wrap = reduce\n ? undefined\n : {\n hidden: { opacity: 0, scale: 0.96, transition: SPRING_PANEL },\n show: { opacity: 1, scale: 1, transition: SPRING_PANEL },\n };\n const clip = reduce\n ? undefined\n : {\n hidden: {\n clipPath: clipHidden(side, align, radius),\n transition: MORPH_CLIP_TRANSITION,\n },\n show: {\n clipPath: clipShown(radius),\n transition: MORPH_CLIP_TRANSITION,\n },\n };\n\n // Keep the server and first client render identical, then mount the portal.\n if (!portalReady) return null;\n\n return createPortal(\n <AnimatePresence>\n {ctx.open ? (\n <motion.div\n data-morph-popover-portal=\"\"\n // Wrapper carries the shadow as a drop-shadow filter, which hugs the\n // clipped shape below (box-shadow would just get clipped away).\n variants={wrap}\n initial={reduce ? { opacity: 0 } : \"hidden\"}\n animate={reduce ? { opacity: 1 } : \"show\"}\n exit={reduce ? { opacity: 0 } : \"hidden\"}\n transition={reduce ? { duration: 0.12 } : undefined}\n style={{\n left,\n top,\n visibility: layout ? \"visible\" : \"hidden\",\n transformOrigin: originFor(side, align),\n }}\n className=\"filter-[drop-shadow(0_10px_18px_rgba(0,0,0,0.14))] fixed z-9999\"\n >\n <motion.div\n ref={ctx.contentRef}\n id={ctx.contentId}\n role=\"dialog\"\n aria-labelledby={ctx.triggerId}\n variants={clip}\n style={{ borderRadius: radius }}\n className={cn(\"overflow-hidden border border-border bg-background\", className)}\n >\n {children}\n </motion.div>\n </motion.div>\n ) : null}\n </AnimatePresence>,\n document.body,\n );\n}\n"],"mappings":";;;;;;;;;AAqCA,MAAM,eAAe,cAAwC,IAAI;AAEjE,SAAS,gBAAgB,WAAmB;CAC1C,MAAM,MAAM,WAAW,YAAY;CACnC,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,GAAG,UAAU,oCAAoC;CAC3E,OAAO;AACT;;;;;;AAiBA,SAAgB,aAAa,EAC3B,UACA,MAAM,gBACN,cAAc,OACd,cACA,aACoB;CACpB,MAAM,SAAS,MAAM;CACrB,MAAM,UAAU,OAAuB,IAAI;CAC3C,MAAM,aAAa,OAA2B,IAAI;CAClD,MAAM,aAAa,OAA8B,IAAI;CACrD,MAAM,CAAC,cAAc,mBAAmB,SAAS,WAAW;CAC5D,MAAM,aAAa,mBAAmB,KAAA;CACtC,MAAM,OAAO,aAAa,iBAAiB;CAE3C,MAAM,UAAU,aACb,SAAkB;EACjB,IAAI,CAAC,YAAY,gBAAgB,IAAI;EACrC,eAAe,IAAI;CACrB,GACA,CAAC,YAAY,YAAY,CAC3B;CACA,MAAM,SAAS,kBAAkB,QAAQ,CAAC,IAAI,GAAG,CAAC,SAAS,IAAI,CAAC;CAEhE,gBAAgB;EACd,IAAI,CAAC,MAAM;EACX,MAAM,SAAS,MAAqB,EAAE,QAAQ,YAAY,QAAQ,KAAK;EACvE,MAAM,aAAa,MAAoB;GACrC,MAAM,SAAS,EAAE;GACjB,IACE,QAAQ,WACR,CAAC,QAAQ,QAAQ,SAAS,MAAM,KAChC,CAAC,WAAW,SAAS,SAAS,MAAM,GAEpC,QAAQ,KAAK;EACjB;EACA,OAAO,iBAAiB,WAAW,KAAK;EACxC,OAAO,iBAAiB,eAAe,SAAS;EAChD,aAAa;GACX,OAAO,oBAAo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E,IAAI;EACnC,MAAM,SAAS,EAAE,SAAS,EAAE,IAAI;EAChC,YAAY,SAAS,EAAE,UAAU,IAAK,IAAI,KAAA;EAC1C,OAAO;GACL;GACA;GACA,YAAY,SAAS,YAAY;GACjC,iBAAiB,UAAU,MAAM,KAAK;EACxC;EACA,WAAU;EAEV,UAAA,oBAAC,OAAO,KAAR;GACE,KAAK,IAAI;GACT,IAAI,IAAI;GACR,MAAK;GACL,mBAAiB,IAAI;GACrB,UAAU;GACV,OAAO,EAAE,cAAc,OAAO;GAC9B,WAAW,GAAG,sDAAsD,SAAS;GAE5E;EACS,CAAA;CACF,CAAA,IACV,KACW,CAAA,GACjB,SAAS,IACX;AACF"}
|
|
1
|
+
{"version":3,"file":"popover-morph.js","names":[],"sources":["../../../src/components/motion/popover-morph.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n cloneElement,\n createContext,\n isValidElement,\n type ReactElement,\n type ReactNode,\n type Ref,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_PANEL } from \"../../lib/ease\";\nimport { usePopoverPortalPosition } from \"./popover-position\";\n\ntype Side = \"top\" | \"bottom\";\ntype Align = \"start\" | \"end\";\n\ntype MorphContextValue = {\n open: boolean;\n setOpen: (open: boolean) => void;\n toggle: () => void;\n triggerId: string;\n contentId: string;\n /** The element the panel measures against — see `registerTrigger`. */\n triggerRef: React.MutableRefObject<HTMLElement | null>;\n registerTrigger: (node: HTMLElement | null) => void;\n contentRef: React.MutableRefObject<HTMLDivElement | null>;\n};\n\nconst MorphContext = createContext<MorphContextValue | null>(null);\n\nfunction useMorphContext(component: string) {\n const ctx = useContext(MorphContext);\n if (!ctx) throw new Error(`${component} must be used within <MorphPopover>`);\n return ctx;\n}\n\nexport interface MorphPopoverProps {\n children: ReactNode;\n /** Controlled open state. */\n open?: boolean;\n /** Uncontrolled initial open state. */\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n className?: string;\n}\n\n/**\n * A popover whose panel morphs open from the trigger corner: it's laid out at\n * full size but clipped to the corner nearest the trigger, then unclips as one\n * piece. Closes on outside pointer / Escape. Controlled or uncontrolled.\n */\nexport function MorphPopover({\n children,\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n className,\n}: MorphPopoverProps) {\n const baseId = useId();\n const [root, setRoot] = useState<HTMLDivElement | null>(null);\n const [trigger, setTrigger] = useState<HTMLElement | null>(null);\n const contentRef = useRef<HTMLDivElement | null>(null);\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const controlled = controlledOpen !== undefined;\n const open = controlled ? controlledOpen : internalOpen;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (!controlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [controlled, onOpenChange],\n );\n const toggle = useCallback(() => setOpen(!open), [setOpen, open]);\n\n // A trigger normally registers itself through MorphPopoverTrigger. It can't\n // when something else already clones the element — a Tooltip wrapping the\n // button, say — and an unregistered trigger leaves the panel with nothing to\n // measure against, so it renders permanently invisible. The root boxes the\n // trigger exactly (the content portals out of it), so it stands in until a\n // real trigger registers, and stands in again if that one unmounts. Both are\n // state, so a trigger arriving while the panel is open re-anchors it.\n const anchorRef = useMemo<React.MutableRefObject<HTMLElement | null>>(\n () => ({ current: trigger ?? root }),\n [root, trigger],\n );\n\n // The panel is a `role=\"dialog\"` and goes inert the moment it closes, so\n // focus cannot be left sitting inside it: a dismissal hands it back to the\n // trigger, the way the ARIA dialog pattern asks. A pointer dismissal takes\n // the focus onward itself when it lands on something focusable — this only\n // catches the case where it would otherwise be stranded. When no trigger has\n // registered, the root anchor stands in only if it can actually hold focus;\n // there is nowhere better than where the keyboard already is, so leave it.\n const close = useCallback(() => {\n setOpen(false);\n const focused = document.activeElement;\n const inPanel = focused instanceof HTMLElement && contentRef.current?.contains(focused);\n if (!inPanel) return;\n const restore = trigger ?? (root && root.tabIndex >= 0 ? root : null);\n restore?.focus();\n }, [root, setOpen, trigger]);\n\n useEffect(() => {\n if (!open) return;\n const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && close();\n const onPointer = (e: PointerEvent) => {\n const target = e.target as Node;\n if (root && !root.contains(target) && !contentRef.current?.contains(target)) close();\n };\n window.addEventListener(\"keydown\", onKey);\n window.addEventListener(\"pointerdown\", onPointer);\n return () => {\n window.removeEventListener(\"keydown\", onKey);\n window.removeEventListener(\"pointerdown\", onPointer);\n };\n }, [open, root, close]);\n\n const ctx = useMemo<MorphContextValue>(\n () => ({\n open,\n setOpen,\n toggle,\n triggerId: `${baseId}-trigger`,\n contentId: `${baseId}-content`,\n triggerRef: anchorRef,\n registerTrigger: setTrigger,\n contentRef,\n }),\n [open, setOpen, toggle, baseId, anchorRef],\n );\n\n return (\n <MorphContext.Provider value={ctx}>\n <div ref={setRoot} className={cn(\"relative inline-flex\", className)}>\n {children}\n </div>\n </MorphContext.Provider>\n );\n}\n\nexport interface MorphPopoverTriggerProps {\n children: ReactElement;\n}\n\nfunction mergeRefs<T>(...refs: Array<Ref<T> | undefined>) {\n return (node: T | null) => {\n for (const ref of refs) {\n if (typeof ref === \"function\") ref(node);\n else if (ref && typeof ref === \"object\")\n (ref as React.MutableRefObject<T | null>).current = node;\n }\n };\n}\n\n/** Wraps a single element, toggling the popover on click. */\nexport function MorphPopoverTrigger({ children }: MorphPopoverTriggerProps) {\n const ctx = useMorphContext(\"MorphPopoverTrigger\");\n if (!isValidElement(children)) return children;\n\n const child = children as ReactElement<Record<string, unknown>>;\n const childOnClick = child.props.onClick as ((e: unknown) => void) | undefined;\n const childRef = (child.props as { ref?: Ref<HTMLElement> }).ref;\n\n return cloneElement(child, {\n id: ctx.triggerId,\n ref: mergeRefs(childRef, ctx.registerTrigger),\n onClick: (e: unknown) => {\n childOnClick?.(e);\n ctx.toggle();\n },\n \"aria-haspopup\": \"dialog\",\n \"aria-expanded\": ctx.open,\n \"aria-controls\": ctx.open ? ctx.contentId : undefined,\n });\n}\n\nconst originFor = (side: Side, align: Align) =>\n `${side === \"bottom\" ? \"top\" : \"bottom\"} ${align === \"end\" ? \"right\" : \"left\"}`;\n\n// A clip that hides everything but the corner nearest the trigger, so the\n// panel appears to grow out of it. inset(top right bottom left).\nfunction clipHidden(side: Side, align: Align, radius: number) {\n const top = side === \"bottom\" ? \"0%\" : \"92%\";\n const bottom = side === \"bottom\" ? \"92%\" : \"0%\";\n const right = align === \"end\" ? \"0%\" : \"92%\";\n const left = align === \"end\" ? \"92%\" : \"0%\";\n return `inset(${top} ${right} ${bottom} ${left} round ${radius}px)`;\n}\nconst clipShown = (radius: number) => `inset(0% 0% 0% 0% round ${radius}px)`;\n\n// Preserve the original spring character on the wrapper, but tween the complex\n// clip-path so it cannot snap when the spring resolves its final distance.\nconst MORPH_CLIP_TRANSITION = { duration: 0.32, ease: EASE_OUT } as const;\n\nexport interface MorphPopoverContentProps {\n children: ReactNode;\n side?: Side;\n align?: Align;\n /** Gap between trigger and panel, in px. Default 8. */\n sideOffset?: number;\n /** Panel corner radius, in px. Default 16. */\n radius?: number;\n className?: string;\n}\n\nexport function MorphPopoverContent({\n children,\n side = \"bottom\",\n align = \"end\",\n sideOffset = 8,\n radius = 16,\n className,\n}: MorphPopoverContentProps) {\n const ctx = useMorphContext(\"MorphPopoverContent\");\n const reduce = useReducedMotion() ?? false;\n const [portalReady, setPortalReady] = useState(false);\n const layout = usePopoverPortalPosition(ctx.triggerRef, ctx.contentRef, portalReady && ctx.open);\n\n useEffect(() => setPortalReady(true), []);\n const left = layout\n ? align === \"end\"\n ? layout.trigger.left + layout.trigger.width - layout.content.width\n : layout.trigger.left\n : 0;\n const top = layout\n ? side === \"bottom\"\n ? layout.trigger.top + layout.trigger.height + sideOffset\n : layout.trigger.top - layout.content.height - sideOffset\n : 0;\n\n // Both directions travel between the exact same hidden/show states. Exit\n // targets \"hidden\" directly instead of introducing separate choreography.\n const wrap = reduce\n ? undefined\n : {\n hidden: { opacity: 0, scale: 0.96, transition: SPRING_PANEL },\n show: { opacity: 1, scale: 1, transition: SPRING_PANEL },\n };\n const clip = reduce\n ? undefined\n : {\n hidden: {\n clipPath: clipHidden(side, align, radius),\n transition: MORPH_CLIP_TRANSITION,\n },\n show: {\n clipPath: clipShown(radius),\n transition: MORPH_CLIP_TRANSITION,\n },\n };\n\n // Keep the server and first client render identical, then mount the portal.\n if (!portalReady) return null;\n\n return createPortal(\n <AnimatePresence>\n {ctx.open ? (\n <motion.div\n data-morph-popover-portal=\"\"\n // Wrapper carries the shadow as a drop-shadow filter, which hugs the\n // clipped shape below (box-shadow would just get clipped away).\n variants={wrap}\n initial={reduce ? { opacity: 0 } : \"hidden\"}\n animate={reduce ? { opacity: 1 } : \"show\"}\n exit={reduce ? { opacity: 0 } : \"hidden\"}\n transition={reduce ? { duration: 0.12 } : undefined}\n style={{\n left,\n top,\n visibility: layout ? \"visible\" : \"hidden\",\n transformOrigin: originFor(side, align),\n }}\n className=\"filter-[drop-shadow(0_10px_18px_rgba(0,0,0,0.14))] fixed z-9999\"\n >\n <motion.div\n ref={ctx.contentRef}\n id={ctx.contentId}\n role=\"dialog\"\n aria-labelledby={ctx.triggerId}\n variants={clip}\n style={{ borderRadius: radius }}\n className={cn(\"overflow-hidden border border-border bg-background\", className)}\n >\n {children}\n </motion.div>\n </motion.div>\n ) : null}\n </AnimatePresence>,\n document.body,\n );\n}\n"],"mappings":";;;;;;;;;AAuCA,MAAM,eAAe,cAAwC,IAAI;AAEjE,SAAS,gBAAgB,WAAmB;CAC1C,MAAM,MAAM,WAAW,YAAY;CACnC,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,GAAG,UAAU,oCAAoC;CAC3E,OAAO;AACT;;;;;;AAiBA,SAAgB,aAAa,EAC3B,UACA,MAAM,gBACN,cAAc,OACd,cACA,aACoB;CACpB,MAAM,SAAS,MAAM;CACrB,MAAM,CAAC,MAAM,W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K;EACxC;EACA,WAAU;EAEV,UAAA,oBAAC,OAAO,KAAR;GACE,KAAK,IAAI;GACT,IAAI,IAAI;GACR,MAAK;GACL,mBAAiB,IAAI;GACrB,UAAU;GACV,OAAO,EAAE,cAAc,OAAO;GAC9B,WAAW,GAAG,sDAAsD,SAAS;GAE5E;EACS,CAAA;CACF,CAAA,IACV,KACW,CAAA,GACjB,SAAS,IACX;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover.d.ts","names":[],"sources":["../../../src/components/motion/popover.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"popover.d.ts","names":[],"sources":["../../../src/components/motion/popover.tsx"],"mappings":";;KAiCK;KACA;KACA;UA8LY;EACf,UAAU;;EAEV;;EAEA;EACA,gBAAgB;;EAEhB,UAAU;;EAEV,OAAO;;EAEP,QAAQ;;EAER;;EAEA;;EAEA;EACA;;iBAGc,UACd,UACA,MAAM,gBACN,aACA,cACA,SACA,MACA,OACA,YACA,aACA,aACA,aACC,+BAAY,IAAA;UA4IE;;EAEf,UAAU;;iBAGI,iBAAiB,YAAY,sBAAmB,aAAA,kDAAA;UA6E/C;EACf,UAAU;EACV;;iBAGc,iBAAiB,UAAU,aAAa,sCAAmB"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useDismiss } from "../../hooks/use-dismiss.js";
|
|
3
|
+
import { useHoverGesture } from "../../hooks/use-hover-gesture.js";
|
|
4
|
+
import { useTapGesture } from "../../hooks/use-tap-gesture.js";
|
|
2
5
|
import { t as usePopoverPortalPosition } from "../../popover-position-BUqYCq8X.js";
|
|
3
6
|
import { cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
7
|
import { cn } from "@kumix/utils";
|
|
@@ -18,6 +21,16 @@ const GOO_CLOSE_SPRING = {
|
|
|
18
21
|
};
|
|
19
22
|
const HOVER_CLOSE_DELAY = 120;
|
|
20
23
|
const CIRCLE_KAPPA = .5523;
|
|
24
|
+
function makeHoverHandlers(hover, enter, leave) {
|
|
25
|
+
return {
|
|
26
|
+
onPointerEnter: (event) => {
|
|
27
|
+
if (hover.enter(event)) enter();
|
|
28
|
+
},
|
|
29
|
+
onPointerLeave: (event) => {
|
|
30
|
+
if (hover.leave(event)) leave();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
21
34
|
const lerp = (a, b, t) => a + (b - a) * t;
|
|
22
35
|
function buildGeo(tW, tH, cW, cH, side, align, gap, panelRadius) {
|
|
23
36
|
const py = side === "bottom" ? tH + gap : -(gap + cH);
|
|
@@ -109,6 +122,7 @@ function Popover({ children, open: controlledOpen, defaultOpen = false, onOpenCh
|
|
|
109
122
|
const triggerRef = useRef(null);
|
|
110
123
|
const contentRef = useRef(null);
|
|
111
124
|
const closeTimer = useRef(null);
|
|
125
|
+
const rootHover = useHoverGesture();
|
|
112
126
|
const progress = useMotionValue(defaultOpen ? 1 : 0);
|
|
113
127
|
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
114
128
|
const controlled = controlledOpen !== void 0;
|
|
@@ -141,24 +155,13 @@ function Popover({ children, open: controlledOpen, defaultOpen = false, onOpenCh
|
|
|
141
155
|
progress,
|
|
142
156
|
reduce
|
|
143
157
|
]);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
window.addEventListener("keydown", onKey);
|
|
152
|
-
if (trigger === "click") window.addEventListener("pointerdown", onPointer);
|
|
153
|
-
return () => {
|
|
154
|
-
window.removeEventListener("keydown", onKey);
|
|
155
|
-
window.removeEventListener("pointerdown", onPointer);
|
|
156
|
-
};
|
|
157
|
-
}, [
|
|
158
|
-
open,
|
|
159
|
-
setOpen,
|
|
160
|
-
trigger
|
|
161
|
-
]);
|
|
158
|
+
const close = useCallback(() => {
|
|
159
|
+
setOpen(false);
|
|
160
|
+
const focused = document.activeElement;
|
|
161
|
+
if (focused instanceof HTMLElement && contentRef.current?.contains(focused)) triggerRef.current?.focus();
|
|
162
|
+
}, [setOpen]);
|
|
163
|
+
const ignoreContent = useCallback((target) => Boolean(contentRef.current?.contains(target)), []);
|
|
164
|
+
useDismiss(open, close, rootRef, { ignore: ignoreContent });
|
|
162
165
|
const ctx = useMemo(() => ({
|
|
163
166
|
open,
|
|
164
167
|
setOpen,
|
|
@@ -194,10 +197,7 @@ function Popover({ children, open: controlledOpen, defaultOpen = false, onOpenCh
|
|
|
194
197
|
contentId,
|
|
195
198
|
progress
|
|
196
199
|
]);
|
|
197
|
-
const hoverHandlers = trigger === "hover" ? {
|
|
198
|
-
onMouseEnter: openHover,
|
|
199
|
-
onMouseLeave: scheduleClose
|
|
200
|
-
} : {};
|
|
200
|
+
const hoverHandlers = trigger === "hover" ? makeHoverHandlers(rootHover, openHover, scheduleClose) : {};
|
|
201
201
|
return /* @__PURE__ */ jsx(PopoverContext.Provider, {
|
|
202
202
|
value: ctx,
|
|
203
203
|
children: /* @__PURE__ */ jsx("div", {
|
|
@@ -216,17 +216,30 @@ function mergeRefs(...refs) {
|
|
|
216
216
|
}
|
|
217
217
|
function PopoverTrigger({ children }) {
|
|
218
218
|
const ctx = usePopoverContext("PopoverTrigger");
|
|
219
|
+
const tap = useTapGesture();
|
|
219
220
|
if (!isValidElement(children)) return children;
|
|
220
221
|
const child = children;
|
|
221
222
|
const childProps = child.props;
|
|
222
223
|
const childRef = childProps.ref;
|
|
223
224
|
const compose = (name, handler) => (event) => {
|
|
224
225
|
childProps[name]?.(event);
|
|
225
|
-
if (!event.defaultPrevented) handler();
|
|
226
|
+
if (!event.defaultPrevented) handler(event);
|
|
227
|
+
};
|
|
228
|
+
const observe = (name, handler) => (event) => {
|
|
229
|
+
childProps[name]?.(event);
|
|
230
|
+
handler(event);
|
|
226
231
|
};
|
|
227
232
|
const handlers = ctx.triggerMode === "hover" ? {
|
|
228
233
|
onFocus: compose("onFocus", ctx.openHover),
|
|
229
|
-
onBlur: compose("onBlur", ctx.scheduleClose)
|
|
234
|
+
onBlur: compose("onBlur", ctx.scheduleClose),
|
|
235
|
+
onPointerDown: observe("onPointerDown", (event) => tap.start(event, ctx.open)),
|
|
236
|
+
onPointerCancel: observe("onPointerCancel", tap.drop),
|
|
237
|
+
onKeyDown: observe("onKeyDown", tap.drop),
|
|
238
|
+
onClick: compose("onClick", () => {
|
|
239
|
+
const gesture = tap.take();
|
|
240
|
+
if (!gesture || gesture.pointerType === "mouse") return;
|
|
241
|
+
ctx.setOpen(!gesture.state);
|
|
242
|
+
})
|
|
230
243
|
} : { onClick: compose("onClick", ctx.toggle) };
|
|
231
244
|
return cloneElement(child, {
|
|
232
245
|
...handlers,
|
|
@@ -250,6 +263,7 @@ function PopoverContent({ children, className }) {
|
|
|
250
263
|
const [portalReady, setPortalReady] = useState(false);
|
|
251
264
|
const { side, align, gap, panelRadius, gooStrength, reduce, gooId, contentId, progress, triggerRef, contentRef, open, triggerMode, openHover, scheduleClose } = ctx;
|
|
252
265
|
const measureRef = contentRef;
|
|
266
|
+
const panelHover = useHoverGesture();
|
|
253
267
|
const blobRef = useRef(null);
|
|
254
268
|
const clipRef = useRef(null);
|
|
255
269
|
const geoRef = useRef(null);
|
|
@@ -279,10 +293,7 @@ function PopoverContent({ children, className }) {
|
|
|
279
293
|
render
|
|
280
294
|
]);
|
|
281
295
|
useMotionValueEvent(progress, "change", (p) => render(geoRef.current, p));
|
|
282
|
-
const hoverHandlers = triggerMode === "hover" ? {
|
|
283
|
-
onMouseEnter: openHover,
|
|
284
|
-
onMouseLeave: scheduleClose
|
|
285
|
-
} : {};
|
|
296
|
+
const hoverHandlers = triggerMode === "hover" ? makeHoverHandlers(panelHover, openHover, scheduleClose) : {};
|
|
286
297
|
if (!portalReady) return null;
|
|
287
298
|
return createPortal(/* @__PURE__ */ jsxs("div", {
|
|
288
299
|
"data-popover-portal": "",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover.js","names":[],"sources":["../../../src/components/motion/popover.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n cloneElement,\n createContext,\n isValidElement,\n type ReactElement,\n type ReactNode,\n type Ref,\n useCallback,\n useContext,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n animate,\n type MotionValue,\n useMotionValue,\n useMotionValueEvent,\n useReducedMotion,\n} from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { usePopoverPortalPosition } from \"./popover-position\";\n\ntype Side = \"top\" | \"bottom\";\ntype Align = \"start\" | \"center\" | \"end\";\ntype TriggerMode = \"click\" | \"hover\";\n\n// This morph needs less bounce than layout motion: too much overshoot makes\n// the liquid neck balloon past the final panel edges.\nconst GOO_OPEN_SPRING = {\n type: \"spring\",\n visualDuration: 0.3,\n bounce: 0.15,\n} as const;\nconst GOO_CLOSE_SPRING = {\n type: \"spring\",\n visualDuration: 0.21,\n bounce: 0.15,\n} as const;\nconst HOVER_CLOSE_DELAY = 120;\nconst CIRCLE_KAPPA = 0.5523;\n\nconst lerp = (a: number, b: number, t: number) => a + (b - a) * t;\n\ninterface Rect {\n x: number;\n y: number;\n w: number;\n h: number;\n r: number;\n}\ninterface Geo {\n layerW: number;\n layerH: number;\n left: number;\n top: number;\n trigger: Rect;\n panel: Rect;\n}\n\n// Trigger rect and panel rect in a shared local coordinate box.\nfunction buildGeo(\n tW: number,\n tH: number,\n cW: number,\n cH: number,\n side: Side,\n align: Align,\n gap: number,\n panelRadius: number,\n): Geo {\n const py = side === \"bottom\" ? tH + gap : -(gap + cH);\n const px = align === \"start\" ? 0 : align === \"end\" ? tW - cW : (tW - cW) / 2;\n\n const left = Math.min(0, px);\n const top = Math.min(0, py);\n const layerW = Math.max(tW, px + cW) - left;\n const layerH = Math.max(tH, py + cH) - top;\n\n const triggerRadius = Math.min(tH / 2, panelRadius);\n\n return {\n layerW,\n layerH,\n left,\n top,\n trigger: { x: -left, y: -top, w: tW, h: tH, r: triggerRadius },\n panel: { x: px - left, y: py - top, w: cW, h: cH, r: panelRadius },\n };\n}\n\nfunction rectAtProgress(geo: Geo, progress: number): Rect {\n const trigger = geo.trigger;\n const panel = geo.panel;\n\n return {\n x: lerp(trigger.x, panel.x, progress),\n y: lerp(trigger.y, panel.y, progress),\n w: lerp(trigger.w, panel.w, progress),\n h: lerp(trigger.h, panel.h, progress),\n r: lerp(trigger.r, panel.r, progress),\n };\n}\n\nfunction insetFor(rect: Rect, layerW: number, layerH: number) {\n const top = rect.y;\n const right = layerW - (rect.x + rect.w);\n const bottom = layerH - (rect.y + rect.h);\n const left = rect.x;\n return `inset(${top}px ${right}px ${bottom}px ${left}px round ${rect.r}px)`;\n}\n\nfunction roundedRectShape(rect: Rect) {\n const radius = Math.max(0, Math.min(rect.r, rect.w / 2, rect.h / 2));\n const control = radius * CIRCLE_KAPPA;\n const x1 = rect.x;\n const y1 = rect.y;\n const x2 = rect.x + rect.w;\n const y2 = rect.y + rect.h;\n const px = (value: number) => `${value.toFixed(3)}px`;\n\n return (\n `shape(from ${px(x1 + radius)} ${px(y1)}, ` +\n `line to ${px(x2 - radius)} ${px(y1)}, ` +\n `curve to ${px(x2)} ${px(y1 + radius)} with ${px(x2 - radius + control)} ${px(y1)} / ${px(x2)} ${px(y1 + radius - control)}, ` +\n `line to ${px(x2)} ${px(y2 - radius)}, ` +\n `curve to ${px(x2 - radius)} ${px(y2)} with ${px(x2)} ${px(y2 - radius + control)} / ${px(x2 - radius + control)} ${px(y2)}, ` +\n `line to ${px(x1 + radius)} ${px(y2)}, ` +\n `curve to ${px(x1)} ${px(y2 - radius)} with ${px(x1 + radius - control)} ${px(y2)} / ${px(x1)} ${px(y2 - radius + control)}, ` +\n `line to ${px(x1)} ${px(y1 + radius)}, ` +\n `curve to ${px(x1 + radius)} ${px(y1)} with ${px(x1)} ${px(y1 + radius - control)} / ${px(x1 + radius - control)} ${px(y1)}, ` +\n \"close)\"\n );\n}\n\nfunction clipForProgress(geo: Geo, progress: number, supportsShape: boolean) {\n const rect = rectAtProgress(geo, progress);\n return supportsShape ? roundedRectShape(rect) : insetFor(rect, geo.layerW, geo.layerH);\n}\n\nfunction roundedRectPath(rect: Rect) {\n const radius = Math.max(0, Math.min(rect.r, rect.w / 2, rect.h / 2));\n const n = (value: number) => value.toFixed(3);\n const x1 = rect.x;\n const y1 = rect.y;\n const x2 = rect.x + rect.w;\n const y2 = rect.y + rect.h;\n const arc = `A${n(radius)} ${n(radius)} 0 0 1`;\n\n // A zero radius makes every arc degenerate to a line, so this also draws\n // plain rectangles.\n return (\n `M${n(x1 + radius)} ${n(y1)}` +\n `H${n(x2 - radius)}${arc} ${n(x2)} ${n(y1 + radius)}` +\n `V${n(y2 - radius)}${arc} ${n(x2 - radius)} ${n(y2)}` +\n `H${n(x1 + radius)}${arc} ${n(x1)} ${n(y2 - radius)}` +\n `V${n(y1 + radius)}${arc} ${n(x1 + radius)} ${n(y1)}Z`\n );\n}\n\n// The goo layer is portalled above the page, so its copy of the trigger pill\n// would cover the real trigger's label and focus ring. Punching the trigger\n// back out keeps the real one visible and clips the blur to the layer box.\n// This is a clip path rather than a CSS mask on purpose: WebKit silently\n// ignores `mask: url(#id)` pointing at an SVG <mask> element, which left the\n// label hidden behind the goo in Safari.\nfunction triggerCutout(geo: Geo) {\n const layer = { x: 0, y: 0, w: geo.layerW, h: geo.layerH, r: 0 };\n return `path(evenodd, \"${roundedRectPath(layer)} ${roundedRectPath(geo.trigger)}\")`;\n}\n\ninterface PopoverContextValue {\n open: boolean;\n setOpen: (open: boolean) => void;\n toggle: () => void;\n openHover: () => void;\n scheduleClose: () => void;\n triggerMode: TriggerMode;\n side: Side;\n align: Align;\n gap: number;\n panelRadius: number;\n gooStrength: number;\n reduce: boolean;\n gooId: string;\n contentId: string;\n progress: MotionValue<number>;\n triggerRef: React.MutableRefObject<HTMLElement | null>;\n contentRef: React.MutableRefObject<HTMLDivElement | null>;\n}\n\nconst PopoverContext = createContext<PopoverContextValue | null>(null);\n\nfunction usePopoverContext(component: string) {\n const ctx = useContext(PopoverContext);\n if (!ctx) throw new Error(`${component} must be used within <Popover>`);\n return ctx;\n}\n\nexport interface PopoverProps {\n children: ReactNode;\n /** Controlled open state. */\n open?: boolean;\n /** Uncontrolled initial open state. */\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n /** How the popover is summoned. Default \"click\". */\n trigger?: TriggerMode;\n /** Which side of the trigger the panel oozes out of. Default \"bottom\". */\n side?: Side;\n /** Alignment along the trigger's edge. Default \"center\". */\n align?: Align;\n /** Gap between trigger and panel, in px — the length of the gooey neck. Default 14. */\n sideOffset?: number;\n /** Corner radius of the open panel, in px. Default 16. */\n panelRadius?: number;\n /** Blur radius feeding the goo filter — higher melts more. Default 8. */\n gooStrength?: number;\n className?: string;\n}\n\nexport function Popover({\n children,\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n trigger = \"click\",\n side = \"bottom\",\n align = \"center\",\n sideOffset = 14,\n panelRadius = 16,\n gooStrength = 8,\n className,\n}: PopoverProps) {\n const reduce = useReducedMotion() ?? false;\n const gooId = useId().replace(/:/g, \"\");\n const contentId = useId();\n const rootRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLElement | null>(null);\n const contentRef = useRef<HTMLDivElement | null>(null);\n const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n const progress = useMotionValue(defaultOpen ? 1 : 0);\n\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const controlled = controlledOpen !== undefined;\n const open = controlled ? controlledOpen : internalOpen;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (!controlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [controlled, onOpenChange],\n );\n\n const cancelClose = useCallback(() => {\n if (closeTimer.current) {\n clearTimeout(closeTimer.current);\n closeTimer.current = null;\n }\n }, []);\n\n const openHover = useCallback(() => {\n cancelClose();\n setOpen(true);\n }, [cancelClose, setOpen]);\n\n const scheduleClose = useCallback(() => {\n cancelClose();\n closeTimer.current = setTimeout(() => setOpen(false), HOVER_CLOSE_DELAY);\n }, [cancelClose, setOpen]);\n\n const toggle = useCallback(() => setOpen(!open), [setOpen, open]);\n\n useEffect(() => () => cancelClose(), [cancelClose]);\n\n useEffect(() => {\n const animation = animate(\n progress,\n open ? 1 : 0,\n reduce ? { duration: 0 } : open ? GOO_OPEN_SPRING : GOO_CLOSE_SPRING,\n );\n return () => animation.stop();\n }, [open, progress, reduce]);\n\n useEffect(() => {\n if (!open) return;\n const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && setOpen(false);\n // The panel is portalled, so both trees participate in outside detection.\n const onPointer = (e: PointerEvent) => {\n const target = e.target as Node;\n if (\n rootRef.current &&\n !rootRef.current.contains(target) &&\n !contentRef.current?.contains(target)\n )\n setOpen(false);\n };\n window.addEventListener(\"keydown\", onKey);\n if (trigger === \"click\") window.addEventListener(\"pointerdown\", onPointer);\n return () => {\n window.removeEventListener(\"keydown\", onKey);\n window.removeEventListener(\"pointerdown\", onPointer);\n };\n }, [open, setOpen, trigger]);\n\n const ctx = useMemo<PopoverContextValue>(\n () => ({\n open,\n setOpen,\n toggle,\n openHover,\n scheduleClose,\n triggerMode: trigger,\n side,\n align,\n gap: sideOffset,\n panelRadius,\n gooStrength,\n reduce,\n gooId,\n contentId,\n progress,\n triggerRef,\n contentRef,\n }),\n [\n open,\n setOpen,\n toggle,\n openHover,\n scheduleClose,\n trigger,\n side,\n align,\n sideOffset,\n panelRadius,\n gooStrength,\n reduce,\n gooId,\n contentId,\n progress,\n ],\n );\n\n const hoverHandlers =\n trigger === \"hover\" ? { onMouseEnter: openHover, onMouseLeave: scheduleClose } : {};\n\n return (\n <PopoverContext.Provider value={ctx}>\n <div\n ref={rootRef}\n className={cn(\"relative isolate inline-flex\", className)}\n {...hoverHandlers}\n >\n {children}\n </div>\n </PopoverContext.Provider>\n );\n}\n\nfunction mergeRefs<T>(...refs: Array<Ref<T> | undefined>) {\n return (node: T | null) => {\n for (const ref of refs) {\n if (typeof ref === \"function\") ref(node);\n else if (ref && typeof ref === \"object\")\n (ref as React.MutableRefObject<T | null>).current = node;\n }\n };\n}\n\nexport interface PopoverTriggerProps {\n /** A single focusable element (e.g. a Button) that opens the popover. */\n children: ReactElement;\n}\n\nexport function PopoverTrigger({ children }: PopoverTriggerProps) {\n const ctx = usePopoverContext(\"PopoverTrigger\");\n\n if (!isValidElement(children)) return children;\n\n const child = children as ReactElement<Record<string, unknown>>;\n const childProps = child.props;\n const childRef = (childProps as { ref?: Ref<HTMLElement> }).ref;\n\n const compose =\n (name: string, handler: () => void) => (event: { defaultPrevented?: boolean }) => {\n (childProps[name] as ((e: unknown) => void) | undefined)?.(event);\n if (!event.defaultPrevented) handler();\n };\n\n const handlers: Record<string, unknown> =\n ctx.triggerMode === \"hover\"\n ? {\n onFocus: compose(\"onFocus\", ctx.openHover),\n onBlur: compose(\"onBlur\", ctx.scheduleClose),\n }\n : { onClick: compose(\"onClick\", ctx.toggle) };\n\n return cloneElement(child, {\n ...handlers,\n ref: mergeRefs(childRef, (node: HTMLElement | null) => {\n ctx.triggerRef.current = node;\n }),\n // Above the goo layer (z-[-1]) so the neck reads behind it.\n className: cn(\"relative z-0\", childProps.className as string | undefined),\n \"aria-haspopup\": \"dialog\",\n \"aria-expanded\": ctx.open,\n \"aria-controls\": ctx.open ? ctx.contentId : undefined,\n \"data-state\": ctx.open ? \"open\" : \"closed\",\n });\n}\n\nconst ALIGN_ORIGIN: Record<Align, string> = {\n start: \"left\",\n center: \"center\",\n end: \"right\",\n};\n\nexport interface PopoverContentProps {\n children: ReactNode;\n className?: string;\n}\n\nexport function PopoverContent({ children, className }: PopoverContentProps) {\n const ctx = usePopoverContext(\"PopoverContent\");\n const [portalReady, setPortalReady] = useState(false);\n const {\n side,\n align,\n gap,\n panelRadius,\n gooStrength,\n reduce,\n gooId,\n contentId,\n progress,\n triggerRef,\n contentRef,\n open,\n triggerMode,\n openHover,\n scheduleClose,\n } = ctx;\n\n const measureRef = contentRef;\n const blobRef = useRef<HTMLDivElement>(null);\n const clipRef = useRef<HTMLDivElement>(null);\n const geoRef = useRef<Geo | null>(null);\n const supportsShapeRef = useRef(false);\n const layout = usePopoverPortalPosition(triggerRef, measureRef, portalReady);\n\n useEffect(() => setPortalReady(true), []);\n\n const geo = useMemo(\n () =>\n buildGeo(\n layout?.trigger.width ?? 0,\n layout?.trigger.height ?? 0,\n layout?.content.width ?? 0,\n layout?.content.height ?? 0,\n side,\n align,\n gap,\n panelRadius,\n ),\n [layout, side, align, gap, panelRadius],\n );\n\n // Morph the same clip on the goo body and the content, so the whole popover\n // oozes as one and the text reveals with it.\n const render = useCallback((g: Geo | null, p: number) => {\n if (!g || g.layerW === 0) return;\n const clip = clipForProgress(g, p, supportsShapeRef.current);\n if (blobRef.current) blobRef.current.style.clipPath = clip;\n if (clipRef.current) clipRef.current.style.clipPath = clip;\n }, []);\n\n useLayoutEffect(() => {\n supportsShapeRef.current =\n typeof CSS !== \"undefined\" &&\n typeof CSS.supports === \"function\" &&\n CSS.supports(\"clip-path\", \"shape(from 0px 0px, line to 1px 1px, close)\");\n geoRef.current = geo;\n render(geo, progress.get());\n }, [geo, progress, render]);\n\n useMotionValueEvent(progress, \"change\", (p) => render(geoRef.current, p));\n\n const hoverHandlers =\n triggerMode === \"hover\" ? { onMouseEnter: openHover, onMouseLeave: scheduleClose } : {};\n\n // Match the server and first client render, then attach the portal after\n // hydration. This preserves SSR without regenerating the page on the client.\n if (!portalReady) return null;\n\n return createPortal(\n <div\n data-popover-portal=\"\"\n className=\"pointer-events-none fixed top-0 left-0 isolate z-9999 size-0\"\n style={{\n visibility: layout ? \"visible\" : \"hidden\",\n transform: `translate3d(${layout?.trigger.left ?? 0}px, ${layout?.trigger.top ?? 0}px, 0)`,\n }}\n >\n {/* Goo filter: blur, sharpen the alpha back into solid shapes, then lay\n the crisp original on top so blobs merge with liquid edges. */}\n <svg aria-hidden width=\"0\" height=\"0\" className=\"absolute\">\n <title>Popover visual effects</title>\n <defs>\n <filter id={gooId} x=\"-50%\" y=\"-50%\" width=\"200%\" height=\"200%\">\n <feGaussianBlur in=\"SourceGraphic\" stdDeviation={gooStrength} result=\"blur\" />\n <feColorMatrix\n in=\"blur\"\n mode=\"matrix\"\n values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 22 -10\"\n result=\"goo\"\n />\n <feComposite in=\"SourceGraphic\" in2=\"goo\" operator=\"atop\" />\n </filter>\n </defs>\n </svg>\n\n {/* Goo body: static trigger pill + morphing blob. */}\n <div\n aria-hidden\n className=\"pointer-events-none absolute z-[-1]\"\n style={{\n left: geo.left,\n top: geo.top,\n width: geo.layerW,\n height: geo.layerH,\n filter: reduce ? undefined : `url(#${gooId})`,\n clipPath: triggerCutout(geo),\n }}\n >\n <div\n className=\"absolute bg-popover\"\n style={{\n left: geo.trigger.x,\n top: geo.trigger.y,\n width: geo.trigger.w,\n height: geo.trigger.h,\n borderRadius: geo.trigger.r,\n }}\n />\n <div\n ref={blobRef}\n className=\"absolute inset-0 bg-popover\"\n style={{\n clipPath: clipForProgress(geo, progress.get(), false),\n }}\n />\n </div>\n\n {/* Content is clipped by the same morph. The portal wrapper stays\n pointer-transparent; only the fully open panel accepts interaction. */}\n <div\n className=\"pointer-events-none absolute z-10\"\n style={{\n left: geo.left,\n top: geo.top,\n width: geo.layerW,\n height: geo.layerH,\n }}\n >\n <div\n ref={clipRef}\n inert={!open}\n className=\"absolute inset-0\"\n style={{\n clipPath: clipForProgress(geo, progress.get(), false),\n pointerEvents: open ? \"auto\" : \"none\",\n }}\n >\n <div\n ref={measureRef}\n id={contentId}\n role=\"dialog\"\n {...hoverHandlers}\n style={{\n position: \"absolute\",\n left: geo.panel.x,\n top: geo.panel.y,\n transformOrigin: `${ALIGN_ORIGIN[align]} ${side === \"bottom\" ? \"top\" : \"bottom\"}`,\n }}\n className={cn(\n \"w-max max-w-[min(92vw,20rem)] p-4 text-popover-foreground outline-none\",\n className,\n )}\n >\n {children}\n </div>\n </div>\n </div>\n </div>,\n document.body,\n );\n}\n"],"mappings":";;;;;;;;AAoCA,MAAM,kBAAkB;CACtB,MAAM;CACN,gBAAgB;CAChB,QAAQ;AACV;AACA,MAAM,mBAAmB;CACvB,MAAM;CACN,gBAAgB;CAChB,QAAQ;AACV;AACA,MAAM,oBAAoB;AAC1B,MAAM,eAAe;AAErB,MAAM,QAAQ,GAAW,GAAW,MAAc,KAAK,IAAI,KAAK;AAmBhE,SAAS,SACP,IACA,IACA,IACA,IACA,MACA,OACA,KACA,aACK;CACL,MAAM,KAAK,SAAS,WAAW,KAAK,MAAM,EAAE,MAAM;CAClD,MAAM,KAAK,UAAU,UAAU,IAAI,UAAU,QAAQ,KAAK,MAAM,KAAK,MAAM;CAE3E,MAAM,OAAO,KAAK,IAAI,GAAG,EAAE;CAC3B,MAAM,MAAM,KAAK,IAAI,GAAG,EAAE;CAC1B,MAAM,SAAS,KAAK,IAAI,IAAI,KAAK,EAAE,IAAI;CACvC,MAAM,SAAS,KAAK,IAAI,IAAI,KAAK,EAAE,IAAI;CAEvC,MAAM,gBAAgB,KAAK,IAAI,KAAK,GAAG,WAAW;CAElD,OAAO;EACL;EACA;EACA;EACA;EACA,SAAS;GAAE,GAAG,CAAC;GAAM,GAAG,CAAC;GAAK,GAAG;GAAI,GAAG;GAAI,GAAG;EAAc;EAC7D,OAAO;GAAE,GAAG,KAAK;GAAM,GAAG,KAAK;GAAK,GAAG;GAAI,GAAG;GAAI,GAAG;EAAY;CACnE;AACF;AAEA,SAAS,eAAe,KAAU,UAAwB;CACxD,MAAM,UAAU,IAAI;CACpB,MAAM,QAAQ,IAAI;CAElB,OAAO;EACL,GAAG,KAAK,QAAQ,GAAG,MAAM,GAAG,QAAQ;EACpC,GAAG,KAAK,QAAQ,GAAG,MAAM,GAAG,QAAQ;EACpC,GAAG,KAAK,QAAQ,GAAG,MAAM,GAAG,QAAQ;EACpC,GAA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WAAU;IACV,OAAO;KACL,MAAM,IAAI;KACV,KAAK,IAAI;KACT,OAAO,IAAI;KACX,QAAQ,IAAI;IACd;IAEA,UAAA,oBAAC,OAAD;KACE,KAAK;KACL,OAAO,CAAC;KACR,WAAU;KACV,OAAO;MACL,UAAU,gBAAgB,KAAK,SAAS,IAAI,GAAG,KAAK;MACpD,eAAe,OAAO,SAAS;KACjC;KAEA,UAAA,oBAAC,OAAD;MACE,KAAK;MACL,IAAI;MACJ,MAAK;MACL,GAAI;MACJ,OAAO;OACL,UAAU;OACV,MAAM,IAAI,MAAM;OAChB,KAAK,IAAI,MAAM;OACf,iBAAiB,GAAG,aAAa,OAAO,GAAG,SAAS,WAAW,QAAQ;MACzE;MACA,WAAW,GACT,0EACA,SACF;MAEC;KACE,CAAA;IACF,CAAA;GACF,CAAA;EACF;CACL,CAAA,GAAA,SAAS,IACX;AACF"}
|
|
1
|
+
{"version":3,"file":"popover.js","names":[],"sources":["../../../src/components/motion/popover.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n cloneElement,\n createContext,\n isValidElement,\n type ReactElement,\n type ReactNode,\n type Ref,\n useCallback,\n useContext,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n animate,\n type MotionValue,\n useMotionValue,\n useMotionValueEvent,\n useReducedMotion,\n} from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useDismiss } from \"../../hooks/use-dismiss\";\nimport { type HoverGesture, useHoverGesture } from \"../../hooks/use-hover-gesture\";\nimport { useTapGesture } from \"../../hooks/use-tap-gesture\";\nimport { usePopoverPortalPosition } from \"./popover-position\";\n\ntype Side = \"top\" | \"bottom\";\ntype Align = \"start\" | \"center\" | \"end\";\ntype TriggerMode = \"click\" | \"hover\";\n\n// This morph needs less bounce than layout motion: too much overshoot makes\n// the liquid neck balloon past the final panel edges.\nconst GOO_OPEN_SPRING = {\n type: \"spring\",\n visualDuration: 0.3,\n bounce: 0.15,\n} as const;\nconst GOO_CLOSE_SPRING = {\n type: \"spring\",\n visualDuration: 0.21,\n bounce: 0.15,\n} as const;\nconst HOVER_CLOSE_DELAY = 120;\nconst CIRCLE_KAPPA = 0.5523;\n\n// `onPointerEnter`/`onPointerLeave` rather than the mouse pair: a tap fires\n// compatibility mouseenter/mouseleave that carry no pointerType at all, and\n// they are what made the panel flicker open and shut under a finger. The\n// gesture pairs the two, so the panel a pen tap opened is not closed again by\n// the boundary event that ends the same tap.\nfunction makeHoverHandlers(hover: HoverGesture, enter: () => void, leave: () => void) {\n return {\n onPointerEnter: (event: React.PointerEvent) => {\n if (hover.enter(event)) enter();\n },\n onPointerLeave: (event: React.PointerEvent) => {\n if (hover.leave(event)) leave();\n },\n };\n}\n\nconst lerp = (a: number, b: number, t: number) => a + (b - a) * t;\n\ninterface Rect {\n x: number;\n y: number;\n w: number;\n h: number;\n r: number;\n}\ninterface Geo {\n layerW: number;\n layerH: number;\n left: number;\n top: number;\n trigger: Rect;\n panel: Rect;\n}\n\n// Trigger rect and panel rect in a shared local coordinate box.\nfunction buildGeo(\n tW: number,\n tH: number,\n cW: number,\n cH: number,\n side: Side,\n align: Align,\n gap: number,\n panelRadius: number,\n): Geo {\n const py = side === \"bottom\" ? tH + gap : -(gap + cH);\n const px = align === \"start\" ? 0 : align === \"end\" ? tW - cW : (tW - cW) / 2;\n\n const left = Math.min(0, px);\n const top = Math.min(0, py);\n const layerW = Math.max(tW, px + cW) - left;\n const layerH = Math.max(tH, py + cH) - top;\n\n const triggerRadius = Math.min(tH / 2, panelRadius);\n\n return {\n layerW,\n layerH,\n left,\n top,\n trigger: { x: -left, y: -top, w: tW, h: tH, r: triggerRadius },\n panel: { x: px - left, y: py - top, w: cW, h: cH, r: panelRadius },\n };\n}\n\nfunction rectAtProgress(geo: Geo, progress: number): Rect {\n const trigger = geo.trigger;\n const panel = geo.panel;\n\n return {\n x: lerp(trigger.x, panel.x, progress),\n y: lerp(trigger.y, panel.y, progress),\n w: lerp(trigger.w, panel.w, progress),\n h: lerp(trigger.h, panel.h, progress),\n r: lerp(trigger.r, panel.r, progress),\n };\n}\n\nfunction insetFor(rect: Rect, layerW: number, layerH: number) {\n const top = rect.y;\n const right = layerW - (rect.x + rect.w);\n const bottom = layerH - (rect.y + rect.h);\n const left = rect.x;\n return `inset(${top}px ${right}px ${bottom}px ${left}px round ${rect.r}px)`;\n}\n\nfunction roundedRectShape(rect: Rect) {\n const radius = Math.max(0, Math.min(rect.r, rect.w / 2, rect.h / 2));\n const control = radius * CIRCLE_KAPPA;\n const x1 = rect.x;\n const y1 = rect.y;\n const x2 = rect.x + rect.w;\n const y2 = rect.y + rect.h;\n const px = (value: number) => `${value.toFixed(3)}px`;\n\n return (\n `shape(from ${px(x1 + radius)} ${px(y1)}, ` +\n `line to ${px(x2 - radius)} ${px(y1)}, ` +\n `curve to ${px(x2)} ${px(y1 + radius)} with ${px(x2 - radius + control)} ${px(y1)} / ${px(x2)} ${px(y1 + radius - control)}, ` +\n `line to ${px(x2)} ${px(y2 - radius)}, ` +\n `curve to ${px(x2 - radius)} ${px(y2)} with ${px(x2)} ${px(y2 - radius + control)} / ${px(x2 - radius + control)} ${px(y2)}, ` +\n `line to ${px(x1 + radius)} ${px(y2)}, ` +\n `curve to ${px(x1)} ${px(y2 - radius)} with ${px(x1 + radius - control)} ${px(y2)} / ${px(x1)} ${px(y2 - radius + control)}, ` +\n `line to ${px(x1)} ${px(y1 + radius)}, ` +\n `curve to ${px(x1 + radius)} ${px(y1)} with ${px(x1)} ${px(y1 + radius - control)} / ${px(x1 + radius - control)} ${px(y1)}, ` +\n \"close)\"\n );\n}\n\nfunction clipForProgress(geo: Geo, progress: number, supportsShape: boolean) {\n const rect = rectAtProgress(geo, progress);\n return supportsShape ? roundedRectShape(rect) : insetFor(rect, geo.layerW, geo.layerH);\n}\n\nfunction roundedRectPath(rect: Rect) {\n const radius = Math.max(0, Math.min(rect.r, rect.w / 2, rect.h / 2));\n const n = (value: number) => value.toFixed(3);\n const x1 = rect.x;\n const y1 = rect.y;\n const x2 = rect.x + rect.w;\n const y2 = rect.y + rect.h;\n const arc = `A${n(radius)} ${n(radius)} 0 0 1`;\n\n // A zero radius makes every arc degenerate to a line, so this also draws\n // plain rectangles.\n return (\n `M${n(x1 + radius)} ${n(y1)}` +\n `H${n(x2 - radius)}${arc} ${n(x2)} ${n(y1 + radius)}` +\n `V${n(y2 - radius)}${arc} ${n(x2 - radius)} ${n(y2)}` +\n `H${n(x1 + radius)}${arc} ${n(x1)} ${n(y2 - radius)}` +\n `V${n(y1 + radius)}${arc} ${n(x1 + radius)} ${n(y1)}Z`\n );\n}\n\n// The goo layer is portalled above the page, so its copy of the trigger pill\n// would cover the real trigger's label and focus ring. Punching the trigger\n// back out keeps the real one visible and clips the blur to the layer box.\n// This is a clip path rather than a CSS mask on purpose: WebKit silently\n// ignores `mask: url(#id)` pointing at an SVG <mask> element, which left the\n// label hidden behind the goo in Safari.\nfunction triggerCutout(geo: Geo) {\n const layer = { x: 0, y: 0, w: geo.layerW, h: geo.layerH, r: 0 };\n return `path(evenodd, \"${roundedRectPath(layer)} ${roundedRectPath(geo.trigger)}\")`;\n}\n\ninterface PopoverContextValue {\n open: boolean;\n setOpen: (open: boolean) => void;\n toggle: () => void;\n openHover: () => void;\n scheduleClose: () => void;\n triggerMode: TriggerMode;\n side: Side;\n align: Align;\n gap: number;\n panelRadius: number;\n gooStrength: number;\n reduce: boolean;\n gooId: string;\n contentId: string;\n progress: MotionValue<number>;\n triggerRef: React.MutableRefObject<HTMLElement | null>;\n contentRef: React.MutableRefObject<HTMLDivElement | null>;\n}\n\nconst PopoverContext = createContext<PopoverContextValue | null>(null);\n\nfunction usePopoverContext(component: string) {\n const ctx = useContext(PopoverContext);\n if (!ctx) throw new Error(`${component} must be used within <Popover>`);\n return ctx;\n}\n\nexport interface PopoverProps {\n children: ReactNode;\n /** Controlled open state. */\n open?: boolean;\n /** Uncontrolled initial open state. */\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n /** How the popover is summoned. Default \"click\". */\n trigger?: TriggerMode;\n /** Which side of the trigger the panel oozes out of. Default \"bottom\". */\n side?: Side;\n /** Alignment along the trigger's edge. Default \"center\". */\n align?: Align;\n /** Gap between trigger and panel, in px — the length of the gooey neck. Default 14. */\n sideOffset?: number;\n /** Corner radius of the open panel, in px. Default 16. */\n panelRadius?: number;\n /** Blur radius feeding the goo filter — higher melts more. Default 8. */\n gooStrength?: number;\n className?: string;\n}\n\nexport function Popover({\n children,\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n trigger = \"click\",\n side = \"bottom\",\n align = \"center\",\n sideOffset = 14,\n panelRadius = 16,\n gooStrength = 8,\n className,\n}: PopoverProps) {\n const reduce = useReducedMotion() ?? false;\n const gooId = useId().replace(/:/g, \"\");\n const contentId = useId();\n const rootRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLElement | null>(null);\n const contentRef = useRef<HTMLDivElement | null>(null);\n const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n const rootHover = useHoverGesture();\n const progress = useMotionValue(defaultOpen ? 1 : 0);\n\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const controlled = controlledOpen !== undefined;\n const open = controlled ? controlledOpen : internalOpen;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (!controlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [controlled, onOpenChange],\n );\n\n const cancelClose = useCallback(() => {\n if (closeTimer.current) {\n clearTimeout(closeTimer.current);\n closeTimer.current = null;\n }\n }, []);\n\n const openHover = useCallback(() => {\n cancelClose();\n setOpen(true);\n }, [cancelClose, setOpen]);\n\n const scheduleClose = useCallback(() => {\n cancelClose();\n closeTimer.current = setTimeout(() => setOpen(false), HOVER_CLOSE_DELAY);\n }, [cancelClose, setOpen]);\n\n const toggle = useCallback(() => setOpen(!open), [setOpen, open]);\n\n useEffect(() => () => cancelClose(), [cancelClose]);\n\n useEffect(() => {\n const animation = animate(\n progress,\n open ? 1 : 0,\n reduce ? { duration: 0 } : open ? GOO_OPEN_SPRING : GOO_CLOSE_SPRING,\n );\n return () => animation.stop();\n }, [open, progress, reduce]);\n\n // The panel is a `role=\"dialog\"` and goes inert the moment it closes, so\n // focus cannot be left sitting inside it: Escape hands it back to the\n // trigger, the way the ARIA dialog pattern asks. A pointer dismissal takes\n // the focus onward itself when it lands on something focusable — this only\n // catches the case where it would otherwise be stranded.\n const close = useCallback(() => {\n setOpen(false);\n const focused = document.activeElement;\n const inPanel = focused instanceof HTMLElement && contentRef.current?.contains(focused);\n if (inPanel) triggerRef.current?.focus();\n }, [setOpen]);\n // The panel is portalled, so both trees participate in outside detection.\n const ignoreContent = useCallback(\n (target: Element) => Boolean(contentRef.current?.contains(target)),\n [],\n );\n // A hover trigger opens on tap as well now, so it needs the same outside\n // dismissal the click trigger always had. The gesture passes through to\n // whatever it landed on, which is the light-dismiss bargain the platform's\n // own popovers strike.\n useDismiss(open, close, rootRef, { ignore: ignoreContent });\n\n const ctx = useMemo<PopoverContextValue>(\n () => ({\n open,\n setOpen,\n toggle,\n openHover,\n scheduleClose,\n triggerMode: trigger,\n side,\n align,\n gap: sideOffset,\n panelRadius,\n gooStrength,\n reduce,\n gooId,\n contentId,\n progress,\n triggerRef,\n contentRef,\n }),\n [\n open,\n setOpen,\n toggle,\n openHover,\n scheduleClose,\n trigger,\n side,\n align,\n sideOffset,\n panelRadius,\n gooStrength,\n reduce,\n gooId,\n contentId,\n progress,\n ],\n );\n\n const hoverHandlers =\n trigger === \"hover\" ? makeHoverHandlers(rootHover, openHover, scheduleClose) : {};\n\n return (\n <PopoverContext.Provider value={ctx}>\n <div\n ref={rootRef}\n className={cn(\"relative isolate inline-flex\", className)}\n {...hoverHandlers}\n >\n {children}\n </div>\n </PopoverContext.Provider>\n );\n}\n\nfunction mergeRefs<T>(...refs: Array<Ref<T> | undefined>) {\n return (node: T | null) => {\n for (const ref of refs) {\n if (typeof ref === \"function\") ref(node);\n else if (ref && typeof ref === \"object\")\n (ref as React.MutableRefObject<T | null>).current = node;\n }\n };\n}\n\nexport interface PopoverTriggerProps {\n /** A single focusable element (e.g. a Button) that opens the popover. */\n children: ReactElement;\n}\n\nexport function PopoverTrigger({ children }: PopoverTriggerProps) {\n const ctx = usePopoverContext(\"PopoverTrigger\");\n // What the last gesture on the trigger was, and whether the panel was\n // already open when it started. A click reports neither.\n const tap = useTapGesture<boolean>();\n\n if (!isValidElement(children)) return children;\n\n const child = children as ReactElement<Record<string, unknown>>;\n const childProps = child.props;\n const childRef = (childProps as { ref?: Ref<HTMLElement> }).ref;\n\n const compose =\n <E extends { defaultPrevented?: boolean }>(name: string, handler: (event: E) => void) =>\n (event: E) => {\n (childProps[name] as ((e: unknown) => void) | undefined)?.(event);\n if (!event.defaultPrevented) handler(event);\n };\n\n // Observation, not action. `compose` steps aside for a child that handled\n // the event itself, which is right for anything that *does* something — but\n // a child preventing the pointerdown default (to hold focus, say) has not\n // said the gesture didn't happen. Skipping the record there left the panel\n // reading whatever the gesture before it had put in.\n const observe =\n <E,>(name: string, handler: (event: E) => void) =>\n (event: E) => {\n (childProps[name] as ((e: unknown) => void) | undefined)?.(event);\n handler(event);\n };\n\n // The hover trigger keeps its hover path and *adds* a tap one, rather than\n // swapping mode on a device that reports a touchscreen: a touchscreen laptop\n // has both inputs and the mouse must keep working. A hovering pointer has\n // already opened the panel on its way in, and a keyboard press arrives with\n // no pointerdown behind it, so only a tap toggles here. Which panel state\n // the tap acts on is read from the gesture's start, because a browser that\n // focuses the trigger on contact would otherwise open it mid-gesture and let\n // the click close it again.\n const handlers: Record<string, unknown> =\n ctx.triggerMode === \"hover\"\n ? {\n onFocus: compose(\"onFocus\", ctx.openHover),\n onBlur: compose(\"onBlur\", ctx.scheduleClose),\n onPointerDown: observe<React.PointerEvent>(\"onPointerDown\", (event) =>\n tap.start(event, ctx.open),\n ),\n onPointerCancel: observe(\"onPointerCancel\", tap.drop),\n onKeyDown: observe(\"onKeyDown\", tap.drop),\n onClick: compose(\"onClick\", () => {\n const gesture = tap.take();\n if (!gesture || gesture.pointerType === \"mouse\") return;\n ctx.setOpen(!gesture.state);\n }),\n }\n : { onClick: compose(\"onClick\", ctx.toggle) };\n\n return cloneElement(child, {\n ...handlers,\n ref: mergeRefs(childRef, (node: HTMLElement | null) => {\n ctx.triggerRef.current = node;\n }),\n // Above the goo layer (z-[-1]) so the neck reads behind it.\n className: cn(\"relative z-0\", childProps.className as string | undefined),\n \"aria-haspopup\": \"dialog\",\n \"aria-expanded\": ctx.open,\n \"aria-controls\": ctx.open ? ctx.contentId : undefined,\n \"data-state\": ctx.open ? \"open\" : \"closed\",\n });\n}\n\nconst ALIGN_ORIGIN: Record<Align, string> = {\n start: \"left\",\n center: \"center\",\n end: \"right\",\n};\n\nexport interface PopoverContentProps {\n children: ReactNode;\n className?: string;\n}\n\nexport function PopoverContent({ children, className }: PopoverContentProps) {\n const ctx = usePopoverContext(\"PopoverContent\");\n const [portalReady, setPortalReady] = useState(false);\n const {\n side,\n align,\n gap,\n panelRadius,\n gooStrength,\n reduce,\n gooId,\n contentId,\n progress,\n triggerRef,\n contentRef,\n open,\n triggerMode,\n openHover,\n scheduleClose,\n } = ctx;\n\n const measureRef = contentRef;\n const panelHover = useHoverGesture();\n const blobRef = useRef<HTMLDivElement>(null);\n const clipRef = useRef<HTMLDivElement>(null);\n const geoRef = useRef<Geo | null>(null);\n const supportsShapeRef = useRef(false);\n const layout = usePopoverPortalPosition(triggerRef, measureRef, portalReady);\n\n useEffect(() => setPortalReady(true), []);\n\n const geo = useMemo(\n () =>\n buildGeo(\n layout?.trigger.width ?? 0,\n layout?.trigger.height ?? 0,\n layout?.content.width ?? 0,\n layout?.content.height ?? 0,\n side,\n align,\n gap,\n panelRadius,\n ),\n [layout, side, align, gap, panelRadius],\n );\n\n // Morph the same clip on the goo body and the content, so the whole popover\n // oozes as one and the text reveals with it.\n const render = useCallback((g: Geo | null, p: number) => {\n if (!g || g.layerW === 0) return;\n const clip = clipForProgress(g, p, supportsShapeRef.current);\n if (blobRef.current) blobRef.current.style.clipPath = clip;\n if (clipRef.current) clipRef.current.style.clipPath = clip;\n }, []);\n\n useLayoutEffect(() => {\n supportsShapeRef.current =\n typeof CSS !== \"undefined\" &&\n typeof CSS.supports === \"function\" &&\n CSS.supports(\"clip-path\", \"shape(from 0px 0px, line to 1px 1px, close)\");\n geoRef.current = geo;\n render(geo, progress.get());\n }, [geo, progress, render]);\n\n useMotionValueEvent(progress, \"change\", (p) => render(geoRef.current, p));\n\n const hoverHandlers =\n triggerMode === \"hover\" ? makeHoverHandlers(panelHover, openHover, scheduleClose) : {};\n\n // Match the server and first client render, then attach the portal after\n // hydration. This preserves SSR without regenerating the page on the client.\n if (!portalReady) return null;\n\n return createPortal(\n <div\n data-popover-portal=\"\"\n className=\"pointer-events-none fixed top-0 left-0 isolate z-9999 size-0\"\n style={{\n visibility: layout ? \"visible\" : \"hidden\",\n transform: `translate3d(${layout?.trigger.left ?? 0}px, ${layout?.trigger.top ?? 0}px, 0)`,\n }}\n >\n {/* Goo filter: blur, sharpen the alpha back into solid shapes, then lay\n the crisp original on top so blobs merge with liquid edges. */}\n <svg aria-hidden width=\"0\" height=\"0\" className=\"absolute\">\n <title>Popover visual effects</title>\n <defs>\n <filter id={gooId} x=\"-50%\" y=\"-50%\" width=\"200%\" height=\"200%\">\n <feGaussianBlur in=\"SourceGraphic\" stdDeviation={gooStrength} result=\"blur\" />\n <feColorMatrix\n in=\"blur\"\n mode=\"matrix\"\n values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 22 -10\"\n result=\"goo\"\n />\n <feComposite in=\"SourceGraphic\" in2=\"goo\" operator=\"atop\" />\n </filter>\n </defs>\n </svg>\n\n {/* Goo body: static trigger pill + morphing blob. */}\n <div\n aria-hidden\n className=\"pointer-events-none absolute z-[-1]\"\n style={{\n left: geo.left,\n top: geo.top,\n width: geo.layerW,\n height: geo.layerH,\n filter: reduce ? undefined : `url(#${gooId})`,\n clipPath: triggerCutout(geo),\n }}\n >\n <div\n className=\"absolute bg-popover\"\n style={{\n left: geo.trigger.x,\n top: geo.trigger.y,\n width: geo.trigger.w,\n height: geo.trigger.h,\n borderRadius: geo.trigger.r,\n }}\n />\n <div\n ref={blobRef}\n className=\"absolute inset-0 bg-popover\"\n style={{\n clipPath: clipForProgress(geo, progress.get(), false),\n }}\n />\n </div>\n\n {/* Content is clipped by the same morph. The portal wrapper stays\n pointer-transparent; only the fully open panel accepts interaction. */}\n <div\n className=\"pointer-events-none absolute z-10\"\n style={{\n left: geo.left,\n top: geo.top,\n width: geo.layerW,\n height: geo.layerH,\n }}\n >\n <div\n ref={clipRef}\n inert={!open}\n className=\"absolute inset-0\"\n style={{\n clipPath: clipForProgress(geo, progress.get(), false),\n pointerEvents: open ? \"auto\" : \"none\",\n }}\n >\n <div\n ref={measureRef}\n id={contentId}\n role=\"dialog\"\n {...hoverHandlers}\n style={{\n position: \"absolute\",\n left: geo.panel.x,\n top: geo.panel.y,\n transformOrigin: `${ALIGN_ORIGIN[align]} ${side === \"bottom\" ? \"top\" : \"bottom\"}`,\n }}\n className={cn(\n \"w-max max-w-[min(92vw,20rem)] p-4 text-popover-foreground outline-none\",\n className,\n )}\n >\n {children}\n </div>\n </div>\n </div>\n </div>,\n document.body,\n );\n}\n"],"mappings":";;;;;;;;;;;AAuCA,MAAM,kBAAkB;CACtB,MAAM;CACN,gBAAgB;CAChB,QAAQ;AACV;AACA,MAAM,mBAAmB;CACvB,MAAM;CACN,gBAAgB;CAChB,QAAQ;AACV;AACA,MAAM,oBAAoB;AAC1B,MAAM,eAAe;AAOrB,SAAS,kBAAkB,OAAqB,OAAmB,OAAmB;CACpF,OAAO;EACL,iBAAiB,UAA8B;GAC7C,IAAI,MAAM,MAAM,KAAK,GAAG,MAAM;EAChC;EACA,iBAAiB,UAA8B;GAC7C,IAAI,MAAM,MAAM,KAAK,GAAG,MAAM;EAChC;CACF;AACF;AAEA,MA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EACtD;IACD,CAAA,CACE;;GAIL,oBAAC,OAAD;IACE,WAAU;IACV,OAAO;KACL,MAAM,IAAI;KACV,KAAK,IAAI;KACT,OAAO,IAAI;KACX,QAAQ,IAAI;IACd;IAEA,UAAA,oBAAC,OAAD;KACE,KAAK;KACL,OAAO,CAAC;KACR,WAAU;KACV,OAAO;MACL,UAAU,gBAAgB,KAAK,SAAS,IAAI,GAAG,KAAK;MACpD,eAAe,OAAO,SAAS;KACjC;KAEA,UAAA,oBAAC,OAAD;MACE,KAAK;MACL,IAAI;MACJ,MAAK;MACL,GAAI;MACJ,OAAO;OACL,UAAU;OACV,MAAM,IAAI,MAAM;OAChB,KAAK,IAAI,MAAM;OACf,iBAAiB,GAAG,aAAa,OAAO,GAAG,SAAS,WAAW,QAAQ;MACzE;MACA,WAAW,GACT,0EACA,SACF;MAEC;KACE,CAAA;IACF,CAAA;GACF,CAAA;EACF;CACL,CAAA,GAAA,SAAS,IACX;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-rail.d.ts","names":[],"sources":["../../../src/components/motion/preview-rail.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"preview-rail.d.ts","names":[],"sources":["../../../src/components/motion/preview-rail.tsx"],"mappings":";;UAmBiB;EACf;EACA;EACA;EACA,cAAc;EACd;EACA;EACA;;UAGe;EACf,OAAO;EACP;EACA;EACA;EACA;EACA,kBAAkB;EAClB,gBAAgB,MAAM;EACtB,iBAAiB,MAAM,oBAAoB;EAC3C;EACA;EACA;EACA;EACA,WAAW;EACX;EACA;EACA;EACA;;iBAwBc,cACd,OACA,OACA,aACA,UACA,iBACA,gBACA,cACA,eACA,aACA,aACA,iBACA,UACA,UACA,WACA,eACA,2BACA,oBACC,mCAAgB,IAAA"}
|