@justanarthur/modo-ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/LICENSE.beui +21 -0
- package/LICENSE.fluid-functionalism +21 -0
- package/LICENSE.motion-primitives +21 -0
- package/LICENSE.sileo +21 -0
- package/README.md +608 -2
- package/dist/base.css +994 -0
- package/dist/blocks/sidebar-app/index.d.ts +34 -0
- package/dist/blocks/sidebar-app/index.js +34 -0
- package/dist/components/badge/index.d.ts +59 -0
- package/dist/components/badge/index.js +18 -0
- package/dist/components/button/index.d.ts +59 -0
- package/dist/components/button/index.js +16 -0
- package/dist/components/card/index.d.ts +141 -0
- package/dist/components/card/index.js +44 -0
- package/dist/components/inputs/checkbox-group/index.d.ts +50 -0
- package/dist/components/inputs/checkbox-group/index.js +23 -0
- package/dist/components/inputs/color-picker/index.d.ts +137 -0
- package/dist/components/inputs/color-picker/index.js +37 -0
- package/dist/components/inputs/combobox/index.d.ts +161 -0
- package/dist/components/inputs/combobox/index.js +41 -0
- package/dist/components/inputs/date-time/calendar/index.d.ts +45 -0
- package/dist/components/inputs/date-time/calendar/index.js +20 -0
- package/dist/components/inputs/date-time/date-picker/index.d.ts +82 -0
- package/dist/components/inputs/date-time/date-picker/index.js +34 -0
- package/dist/components/inputs/date-time/date-range-picker/index.d.ts +64 -0
- package/dist/components/inputs/date-time/date-range-picker/index.js +33 -0
- package/dist/components/inputs/date-time/duration-picker/index.d.ts +57 -0
- package/dist/components/inputs/date-time/duration-picker/index.js +33 -0
- package/dist/components/inputs/date-time/month-picker/index.d.ts +57 -0
- package/dist/components/inputs/date-time/month-picker/index.js +32 -0
- package/dist/components/inputs/date-time/time-picker/index.d.ts +59 -0
- package/dist/components/inputs/date-time/time-picker/index.js +33 -0
- package/dist/components/inputs/input/index.d.ts +84 -0
- package/dist/components/inputs/input/index.js +20 -0
- package/dist/components/inputs/input-copy/index.d.ts +44 -0
- package/dist/components/inputs/input-copy/index.js +18 -0
- package/dist/components/inputs/input-message/index.d.ts +125 -0
- package/dist/components/inputs/input-message/index.js +27 -0
- package/dist/components/inputs/radio-group/index.d.ts +58 -0
- package/dist/components/inputs/radio-group/index.js +22 -0
- package/dist/components/inputs/search/index.d.ts +83 -0
- package/dist/components/inputs/search/index.js +28 -0
- package/dist/components/inputs/select/index.d.ts +105 -0
- package/dist/components/inputs/select/index.js +37 -0
- package/dist/components/inputs/slider/index.d.ts +108 -0
- package/dist/components/inputs/slider/index.js +16 -0
- package/dist/components/inputs/switch/index.d.ts +43 -0
- package/dist/components/inputs/switch/index.js +16 -0
- package/dist/components/navigation/accordion/index.d.ts +117 -0
- package/dist/components/navigation/accordion/index.js +30 -0
- package/dist/components/navigation/sidebar/index.d.ts +388 -0
- package/dist/components/navigation/sidebar/index.js +101 -0
- package/dist/components/navigation/tabs/index.d.ts +70 -0
- package/dist/components/navigation/tabs/index.js +25 -0
- package/dist/components/navigation/tabs-subtle/index.d.ts +73 -0
- package/dist/components/navigation/tabs-subtle/index.js +23 -0
- package/dist/components/overlays/alert-dialog/index.d.ts +67 -0
- package/dist/components/overlays/alert-dialog/index.js +24 -0
- package/dist/components/overlays/command/index.d.ts +121 -0
- package/dist/components/overlays/command/index.js +39 -0
- package/dist/components/overlays/context-menu/index.d.ts +97 -0
- package/dist/components/overlays/context-menu/index.js +32 -0
- package/dist/components/overlays/dialog/index.d.ts +130 -0
- package/dist/components/overlays/dialog/index.js +39 -0
- package/dist/components/overlays/dropdown/index.d.ts +222 -0
- package/dist/components/overlays/dropdown/index.js +47 -0
- package/dist/components/overlays/popover/index.d.ts +87 -0
- package/dist/components/overlays/popover/index.js +28 -0
- package/dist/components/overlays/preview-card/index.d.ts +75 -0
- package/dist/components/overlays/preview-card/index.js +21 -0
- package/dist/components/overlays/sheet/index.d.ts +67 -0
- package/dist/components/overlays/sheet/index.js +26 -0
- package/dist/components/overlays/toast/index.d.ts +107 -0
- package/dist/components/overlays/toast/index.js +23 -0
- package/dist/components/overlays/tooltip/index.d.ts +75 -0
- package/dist/components/overlays/tooltip/index.js +19 -0
- package/dist/components/table/index.d.ts +44 -0
- package/dist/components/table/index.js +28 -0
- package/dist/components/thinking-indicator/index.d.ts +32 -0
- package/dist/components/thinking-indicator/index.js +15 -0
- package/dist/index.d.ts +3926 -0
- package/dist/index.js +513 -0
- package/dist/preset.d.ts +104 -0
- package/dist/preset.js +124 -0
- package/dist/primitives/code/index.d.ts +23 -0
- package/dist/primitives/code/index.js +12 -0
- package/dist/primitives/craft/index.d.ts +31 -0
- package/dist/primitives/craft/index.js +13 -0
- package/dist/primitives/fluid-hover/index.d.ts +233 -0
- package/dist/primitives/fluid-hover/index.js +27 -0
- package/dist/primitives/morph/index.d.ts +127 -0
- package/dist/primitives/morph/index.js +21 -0
- package/dist/primitives/motion/index.d.ts +115 -0
- package/dist/primitives/motion/index.js +20 -0
- package/dist/primitives/scroll-area/index.d.ts +41 -0
- package/dist/primitives/scroll-area/index.js +13 -0
- package/dist/primitives/sizes/index.d.ts +128 -0
- package/dist/primitives/sizes/index.js +22 -0
- package/dist/primitives/surface/index.d.ts +69 -0
- package/dist/primitives/surface/index.js +18 -0
- package/dist/shared/components-0f0as45n.js +17 -0
- package/dist/shared/components-40j34hdb.js +986 -0
- package/dist/shared/components-4hh0gm0v.js +292 -0
- package/dist/shared/components-4xxddc44.js +15 -0
- package/dist/shared/components-4xxtggzp.js +110 -0
- package/dist/shared/components-54nf2x99.js +293 -0
- package/dist/shared/components-5pkcfprd.js +232 -0
- package/dist/shared/components-5vxtcp88.js +9 -0
- package/dist/shared/components-5zry9te1.js +152 -0
- package/dist/shared/components-61ckf42z.js +220 -0
- package/dist/shared/components-6hzwfmfd.js +58 -0
- package/dist/shared/components-6phwsry6.js +361 -0
- package/dist/shared/components-6t6nr33r.js +86 -0
- package/dist/shared/components-6y1th6k4.js +111 -0
- package/dist/shared/components-74c20v2f.js +32 -0
- package/dist/shared/components-7cqq1sqy.js +193 -0
- package/dist/shared/components-7gv95yfy.js +496 -0
- package/dist/shared/components-7nww01w4.js +375 -0
- package/dist/shared/components-7zp99w5d.js +62 -0
- package/dist/shared/components-8hk9ve3r.js +1200 -0
- package/dist/shared/components-8hzbsfbd.js +123 -0
- package/dist/shared/components-9p8s8n5q.js +171 -0
- package/dist/shared/components-aaq3yk4f.js +304 -0
- package/dist/shared/components-bf2d9k02.js +484 -0
- package/dist/shared/components-bkvb6nem.js +63 -0
- package/dist/shared/components-brnzrp2t.js +262 -0
- package/dist/shared/components-csxz9f52.js +42 -0
- package/dist/shared/components-de8xsm9y.js +22 -0
- package/dist/shared/components-dg0w8g5p.js +26 -0
- package/dist/shared/components-dphg9gjr.js +42 -0
- package/dist/shared/components-e46kf6cp.js +298 -0
- package/dist/shared/components-ed7cmssr.js +105 -0
- package/dist/shared/components-ess3ch6w.js +137 -0
- package/dist/shared/components-gjfrycb5.js +984 -0
- package/dist/shared/components-gndm6am4.js +128 -0
- package/dist/shared/components-hjkrv00c.js +191 -0
- package/dist/shared/components-hzfp4tjb.js +270 -0
- package/dist/shared/components-j65qt1mq.js +719 -0
- package/dist/shared/components-jw16snbn.js +19 -0
- package/dist/shared/components-jxgznftn.js +146 -0
- package/dist/shared/components-kf2ehztc.js +216 -0
- package/dist/shared/components-kpbcms10.js +9 -0
- package/dist/shared/components-m5br529r.js +141 -0
- package/dist/shared/components-nn6xezy2.js +1828 -0
- package/dist/shared/components-nnnd2xef.js +9 -0
- package/dist/shared/components-p2vmyfe1.js +345 -0
- package/dist/shared/components-peg09pzs.js +79 -0
- package/dist/shared/components-r22vtgqc.js +45 -0
- package/dist/shared/components-r2gke5p6.js +1759 -0
- package/dist/shared/components-r43mqnd6.js +160 -0
- package/dist/shared/components-r4jt6hgd.js +58 -0
- package/dist/shared/components-rc63qsy6.js +159 -0
- package/dist/shared/components-s3yfvfkr.js +149 -0
- package/dist/shared/components-s5pkbjx1.js +445 -0
- package/dist/shared/components-tad5h7ta.js +346 -0
- package/dist/shared/components-taxmgbnh.js +120 -0
- package/dist/shared/components-tm88ghva.js +215 -0
- package/dist/shared/components-v7es8aan.js +144 -0
- package/dist/shared/components-vb033rns.js +28 -0
- package/dist/shared/components-vc1k7yv2.js +30 -0
- package/dist/shared/components-vktws5r6.js +667 -0
- package/dist/shared/components-x2xyckd5.js +198 -0
- package/dist/shared/components-x3rz4cyn.js +61 -0
- package/dist/shared/components-xszag63d.js +141 -0
- package/dist/shared/components-y3cqdrgy.js +291 -0
- package/dist/shared/components-zvb11ker.js +288 -0
- package/dist/shared/components-zx2hr57f.js +124 -0
- package/dist/styles.css +1949 -0
- package/dist/tailwind.css +219 -0
- package/dist/tokens.css +345 -0
- package/package.json +102 -3
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useReduceMotion
|
|
3
|
+
} from "./components-nnnd2xef.js";
|
|
4
|
+
import {
|
|
5
|
+
exitFallbackMs,
|
|
6
|
+
spring
|
|
7
|
+
} from "./components-vc1k7yv2.js";
|
|
8
|
+
|
|
9
|
+
// lib/use-morph.ts
|
|
10
|
+
import { animate, clamp, useMotionValue } from "motion/react";
|
|
11
|
+
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
12
|
+
var GOO_MATRIX = "1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 22 -10";
|
|
13
|
+
var GOO_BLUR_RATIO = 0.5;
|
|
14
|
+
var GOO_SURFACE_BLUR = 8;
|
|
15
|
+
var GOO_RELEASE = 0.3;
|
|
16
|
+
var GOO_SETTLE = 0.1;
|
|
17
|
+
var lerp = (a, b, t) => a + (b - a) * t;
|
|
18
|
+
var drawsShape = (effect) => effect === "goo" || effect === "morph";
|
|
19
|
+
function lerpRect(a, b, t) {
|
|
20
|
+
return {
|
|
21
|
+
x: lerp(a.x, b.x, t),
|
|
22
|
+
y: lerp(a.y, b.y, t),
|
|
23
|
+
w: lerp(a.w, b.w, t),
|
|
24
|
+
h: lerp(a.h, b.h, t),
|
|
25
|
+
r: lerp(a.r, b.r, t)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function clampRect(rect) {
|
|
29
|
+
const w = Math.max(0, rect.w);
|
|
30
|
+
const h = Math.max(0, rect.h);
|
|
31
|
+
return { x: rect.x, y: rect.y, w, h, r: Math.max(0, Math.min(rect.r, w / 2, h / 2)) };
|
|
32
|
+
}
|
|
33
|
+
function roundedRectPath({ x, y, w, h, r }) {
|
|
34
|
+
const n = (value) => value.toFixed(3);
|
|
35
|
+
const arc = `A${n(r)} ${n(r)} 0 0 1`;
|
|
36
|
+
return `M${n(x + r)} ${n(y)}` + `H${n(x + w - r)}${arc} ${n(x + w)} ${n(y + r)}` + `V${n(y + h - r)}${arc} ${n(x + w - r)} ${n(y + h)}` + `H${n(x + r)}${arc} ${n(x)} ${n(y + h - r)}` + `V${n(y + r)}${arc} ${n(x + r)} ${n(y)}Z`;
|
|
37
|
+
}
|
|
38
|
+
function radiusOf(el, width, height) {
|
|
39
|
+
const value = getComputedStyle(el).borderTopLeftRadius;
|
|
40
|
+
const r = value.endsWith("%") ? Number.parseFloat(value) / 100 * width : Number.parseFloat(value);
|
|
41
|
+
return Math.min(r || 0, width / 2, height / 2);
|
|
42
|
+
}
|
|
43
|
+
function onScreen(rect) {
|
|
44
|
+
return rect.width > 0 && rect.height > 0 && rect.bottom > 0 && rect.right > 0 && rect.top < innerHeight && rect.left < innerWidth;
|
|
45
|
+
}
|
|
46
|
+
function sourceElement(from, origin) {
|
|
47
|
+
if (from === "trigger")
|
|
48
|
+
return origin.trigger;
|
|
49
|
+
if (typeof from === "object")
|
|
50
|
+
return from.current ?? undefined;
|
|
51
|
+
}
|
|
52
|
+
function sourceRect(from, origin, box, target) {
|
|
53
|
+
const local = (x, y, w, h, r) => ({
|
|
54
|
+
x: x - box.left,
|
|
55
|
+
y: y - box.top,
|
|
56
|
+
w,
|
|
57
|
+
h,
|
|
58
|
+
r
|
|
59
|
+
});
|
|
60
|
+
const center = { x: target.w / 2, y: target.h / 2, w: 0, h: 0, r: target.r };
|
|
61
|
+
if (from === "center")
|
|
62
|
+
return center;
|
|
63
|
+
if (from === "top")
|
|
64
|
+
return local(box.left, 0, box.width, 0, 0);
|
|
65
|
+
if (from === "bottom")
|
|
66
|
+
return local(box.left, innerHeight, box.width, 0, 0);
|
|
67
|
+
if (from === "left")
|
|
68
|
+
return local(0, box.top, 0, box.height, 0);
|
|
69
|
+
if (from === "right")
|
|
70
|
+
return local(innerWidth, box.top, 0, box.height, 0);
|
|
71
|
+
if (from === "pointer") {
|
|
72
|
+
const trigger = origin.trigger?.getBoundingClientRect();
|
|
73
|
+
const point = origin.point ?? (trigger && { x: trigger.left + trigger.width / 2, y: trigger.top + trigger.height / 2 });
|
|
74
|
+
const d = target.r;
|
|
75
|
+
return point ? local(point.x - d / 2, point.y - d / 2, d, d, d / 2) : center;
|
|
76
|
+
}
|
|
77
|
+
const el = sourceElement(from, origin);
|
|
78
|
+
if (!el)
|
|
79
|
+
return center;
|
|
80
|
+
const rect = el.getBoundingClientRect();
|
|
81
|
+
if (!onScreen(rect))
|
|
82
|
+
return center;
|
|
83
|
+
return local(rect.left, rect.top, rect.width, rect.height, radiusOf(el, rect.width, rect.height));
|
|
84
|
+
}
|
|
85
|
+
function slideOffset(from, source, target, box) {
|
|
86
|
+
if (from === "left")
|
|
87
|
+
return { x: -box.right, y: 0 };
|
|
88
|
+
if (from === "right")
|
|
89
|
+
return { x: innerWidth - box.left, y: 0 };
|
|
90
|
+
if (from === "top")
|
|
91
|
+
return { x: 0, y: -box.bottom };
|
|
92
|
+
if (from === "bottom")
|
|
93
|
+
return { x: 0, y: innerHeight - box.top };
|
|
94
|
+
return { x: source.x + source.w / 2 - target.w / 2, y: source.y + source.h / 2 - target.h / 2 };
|
|
95
|
+
}
|
|
96
|
+
function layerBox(source, target, pad) {
|
|
97
|
+
const x = Math.min(source.x, target.x) - pad;
|
|
98
|
+
const y = Math.min(source.y, target.y) - pad;
|
|
99
|
+
const w = Math.max(source.x + source.w, target.x + target.w) + pad - x;
|
|
100
|
+
const h = Math.max(source.y + source.h, target.y + target.h) + pad - y;
|
|
101
|
+
return { x, y, w, h, r: 0 };
|
|
102
|
+
}
|
|
103
|
+
function overlaps(a, b) {
|
|
104
|
+
return a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
|
|
105
|
+
}
|
|
106
|
+
function place(el, { x, y, w, h, r }) {
|
|
107
|
+
if (!el)
|
|
108
|
+
return;
|
|
109
|
+
el.style.inset = "auto";
|
|
110
|
+
el.style.left = `${x}px`;
|
|
111
|
+
el.style.top = `${y}px`;
|
|
112
|
+
el.style.width = `${w}px`;
|
|
113
|
+
el.style.height = `${h}px`;
|
|
114
|
+
el.style.borderRadius = `${r}px`;
|
|
115
|
+
}
|
|
116
|
+
function within(rect, layer) {
|
|
117
|
+
return { ...rect, x: rect.x - layer.x, y: rect.y - layer.y };
|
|
118
|
+
}
|
|
119
|
+
function insetClip(rect, box) {
|
|
120
|
+
const right = box.w - rect.x - rect.w;
|
|
121
|
+
const bottom = box.h - rect.y - rect.h;
|
|
122
|
+
return `inset(${rect.y}px ${right}px ${bottom}px ${rect.x}px round ${rect.r}px)`;
|
|
123
|
+
}
|
|
124
|
+
function opensInPlace({ effect, hideSource = false }) {
|
|
125
|
+
return effect === "morph" && hideSource;
|
|
126
|
+
}
|
|
127
|
+
function inPlaceOffset({ side, anchor }) {
|
|
128
|
+
return side === "top" || side === "bottom" ? -anchor.height : -anchor.width;
|
|
129
|
+
}
|
|
130
|
+
function holdExit(el, tier) {
|
|
131
|
+
return el.animate(null, { duration: exitFallbackMs(spring[tier]) });
|
|
132
|
+
}
|
|
133
|
+
function returnFocus(trigger) {
|
|
134
|
+
requestAnimationFrame(() => requestAnimationFrame(() => {
|
|
135
|
+
const active = document.activeElement;
|
|
136
|
+
if (!trigger.isConnected || active === trigger)
|
|
137
|
+
return;
|
|
138
|
+
if (active && active !== document.body && !active.contains(trigger))
|
|
139
|
+
return;
|
|
140
|
+
trigger.focus({ preventScroll: true });
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
function pressPoint(event) {
|
|
144
|
+
if (event && "touches" in event) {
|
|
145
|
+
const { touches, changedTouches } = event;
|
|
146
|
+
const touch = touches[0] ?? changedTouches[0];
|
|
147
|
+
return touch && { x: touch.clientX, y: touch.clientY };
|
|
148
|
+
}
|
|
149
|
+
if (!(event instanceof MouseEvent))
|
|
150
|
+
return;
|
|
151
|
+
if (event.type === "click" && event.detail === 0)
|
|
152
|
+
return;
|
|
153
|
+
return { x: event.clientX, y: event.clientY };
|
|
154
|
+
}
|
|
155
|
+
function useMorphOrigin() {
|
|
156
|
+
const origin = useRef({});
|
|
157
|
+
const capture = useCallback((details) => {
|
|
158
|
+
const { trigger, event } = details;
|
|
159
|
+
origin.current = {
|
|
160
|
+
trigger: trigger instanceof HTMLElement ? trigger : origin.current.trigger,
|
|
161
|
+
point: pressPoint(event)
|
|
162
|
+
};
|
|
163
|
+
}, []);
|
|
164
|
+
return { origin, capture };
|
|
165
|
+
}
|
|
166
|
+
function useMorph(open, origin, { from = "trigger", effect = "goo", hideSource = false, tier = "slow", exit, instant } = {}, onExited) {
|
|
167
|
+
const reduced = useReduceMotion();
|
|
168
|
+
const resolve = (wanted) => reduced ? "fade" : wanted;
|
|
169
|
+
const resolved = resolve(effect);
|
|
170
|
+
const timing = (effect2) => effect2 === "goo" ? "goo" : tier;
|
|
171
|
+
const progress = useMotionValue(0);
|
|
172
|
+
const gooId = `morph-goo-${useId().replace(/:/g, "")}`;
|
|
173
|
+
const geometry = useRef(null);
|
|
174
|
+
const run = useRef({ effect: resolved, from });
|
|
175
|
+
const targetRadius = useRef(0);
|
|
176
|
+
const hidden = useRef(null);
|
|
177
|
+
const exited = useRef(onExited);
|
|
178
|
+
exited.current = onExited;
|
|
179
|
+
const returnTo = useRef(null);
|
|
180
|
+
const [popup, setPopup] = useState(null);
|
|
181
|
+
const refs = {
|
|
182
|
+
popup: useRef(null),
|
|
183
|
+
shapes: useRef(null),
|
|
184
|
+
blur: useRef(null),
|
|
185
|
+
outline: useRef(null),
|
|
186
|
+
copy: useRef(null),
|
|
187
|
+
shape: useRef(null),
|
|
188
|
+
bg: useRef(null),
|
|
189
|
+
shadow: useRef(null),
|
|
190
|
+
content: useRef(null)
|
|
191
|
+
};
|
|
192
|
+
const render = (p) => {
|
|
193
|
+
const g = geometry.current;
|
|
194
|
+
if (!g)
|
|
195
|
+
return;
|
|
196
|
+
const { bg, content, shadow, popup: popup2, shape } = refs;
|
|
197
|
+
const { effect: effect2 } = run.current;
|
|
198
|
+
const shaped = drawsShape(effect2);
|
|
199
|
+
const slide = { ...g.target, x: g.offset.x * (1 - p), y: g.offset.y * (1 - p) };
|
|
200
|
+
const rect = clampRect(shaped ? lerpRect(g.source, g.target, p) : effect2 === "slide" ? slide : g.target);
|
|
201
|
+
place(shaped ? shape.current : bg.current, shaped ? within(rect, g.layer) : rect);
|
|
202
|
+
place(shadow.current, rect);
|
|
203
|
+
const melting = effect2 === "goo" ? clamp(0, 1, (1 - p) / GOO_RELEASE) : 0;
|
|
204
|
+
refs.blur.current?.setAttribute("stdDeviation", String(g.blur * melting));
|
|
205
|
+
refs.outline.current?.setAttribute("flood-opacity", String(melting * clamp(0, 1, p / GOO_SETTLE)));
|
|
206
|
+
if (shadow.current)
|
|
207
|
+
shadow.current.style.opacity = String(effect2 === "goo" ? 1 - melting : clamp(0, 1, p));
|
|
208
|
+
if (content.current) {
|
|
209
|
+
content.current.style.clipPath = shaped ? insetClip(rect, g.target) : "";
|
|
210
|
+
content.current.style.transform = effect2 === "slide" ? `translate(${rect.x}px, ${rect.y}px)` : "";
|
|
211
|
+
}
|
|
212
|
+
if (popup2.current)
|
|
213
|
+
popup2.current.style.opacity = effect2 === "fade" ? String(p) : "";
|
|
214
|
+
};
|
|
215
|
+
const rest = () => {
|
|
216
|
+
refs.bg.current?.removeAttribute("style");
|
|
217
|
+
refs.shadow.current?.removeAttribute("style");
|
|
218
|
+
if (refs.shapes.current)
|
|
219
|
+
refs.shapes.current.style.display = "";
|
|
220
|
+
if (refs.content.current) {
|
|
221
|
+
refs.content.current.style.clipPath = "";
|
|
222
|
+
refs.content.current.style.transform = "";
|
|
223
|
+
}
|
|
224
|
+
if (refs.popup.current)
|
|
225
|
+
refs.popup.current.style.opacity = "";
|
|
226
|
+
};
|
|
227
|
+
const measure = () => {
|
|
228
|
+
const el = refs.popup.current;
|
|
229
|
+
if (!el)
|
|
230
|
+
return;
|
|
231
|
+
const { effect: effect2, from: from2 } = run.current;
|
|
232
|
+
const shaped = drawsShape(effect2);
|
|
233
|
+
const box = el.getBoundingClientRect();
|
|
234
|
+
const target = { x: 0, y: 0, w: box.width, h: box.height, r: targetRadius.current };
|
|
235
|
+
const source = sourceRect(from2, origin.current ?? {}, box, target);
|
|
236
|
+
const blur = effect2 === "goo" ? Math.max(GOO_SURFACE_BLUR, target.r * GOO_BLUR_RATIO) : 0;
|
|
237
|
+
const layer = layerBox(source, target, blur * 3);
|
|
238
|
+
geometry.current = { source, target, layer, offset: slideOffset(from2, source, target, box), blur };
|
|
239
|
+
const { shapes, copy, bg } = refs;
|
|
240
|
+
if (bg.current)
|
|
241
|
+
bg.current.style.opacity = shaped ? "0" : "";
|
|
242
|
+
if (!shapes.current)
|
|
243
|
+
return;
|
|
244
|
+
shapes.current.style.display = shaped ? "block" : "";
|
|
245
|
+
if (!shaped)
|
|
246
|
+
return;
|
|
247
|
+
place(shapes.current, { ...layer, r: 0 });
|
|
248
|
+
if (effect2 === "goo")
|
|
249
|
+
place(copy.current, within(source, layer));
|
|
250
|
+
const cut = source.w > 0 && source.h > 0 && !hideSource && !overlaps(source, target);
|
|
251
|
+
shapes.current.style.clipPath = cut ? `path(evenodd, "${roundedRectPath({ ...layer, x: 0, y: 0 })} ${roundedRectPath(within(source, layer))}")` : "";
|
|
252
|
+
};
|
|
253
|
+
const reveal = () => {
|
|
254
|
+
if (!hidden.current)
|
|
255
|
+
return;
|
|
256
|
+
hidden.current.el.style.opacity = hidden.current.opacity;
|
|
257
|
+
hidden.current = null;
|
|
258
|
+
};
|
|
259
|
+
const hide = (el) => {
|
|
260
|
+
if (!hideSource || !el || hidden.current?.el === el)
|
|
261
|
+
return;
|
|
262
|
+
reveal();
|
|
263
|
+
hidden.current = { el, opacity: el.style.opacity };
|
|
264
|
+
el.style.opacity = "0";
|
|
265
|
+
};
|
|
266
|
+
const skip = (el) => instant?.(el);
|
|
267
|
+
const opening = (popup2) => {
|
|
268
|
+
returnTo.current = null;
|
|
269
|
+
run.current = { effect: resolved, from };
|
|
270
|
+
const first = !geometry.current;
|
|
271
|
+
if (first && refs.bg.current) {
|
|
272
|
+
const box = popup2.getBoundingClientRect();
|
|
273
|
+
targetRadius.current = radiusOf(refs.bg.current, box.width, box.height);
|
|
274
|
+
}
|
|
275
|
+
let controls;
|
|
276
|
+
const begin = () => {
|
|
277
|
+
measure();
|
|
278
|
+
hide(sourceElement(from, origin.current ?? {}));
|
|
279
|
+
if (skip(popup2)) {
|
|
280
|
+
progress.jump(1);
|
|
281
|
+
rest();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
render(progress.get());
|
|
285
|
+
const { exit: _, ...enter } = spring[timing(run.current.effect)];
|
|
286
|
+
controls = animate(progress, 1, {
|
|
287
|
+
...enter,
|
|
288
|
+
onUpdate: (p) => {
|
|
289
|
+
if (skip(popup2))
|
|
290
|
+
controls?.complete();
|
|
291
|
+
render(p);
|
|
292
|
+
},
|
|
293
|
+
onComplete: rest
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
if (!first || skip(popup2) || !refs.bg.current) {
|
|
297
|
+
begin();
|
|
298
|
+
return () => controls?.stop();
|
|
299
|
+
}
|
|
300
|
+
refs.bg.current.style.opacity = "0";
|
|
301
|
+
if (refs.shadow.current)
|
|
302
|
+
refs.shadow.current.style.opacity = "0";
|
|
303
|
+
if (refs.content.current)
|
|
304
|
+
refs.content.current.style.clipPath = "inset(50%)";
|
|
305
|
+
const frame = requestAnimationFrame(begin);
|
|
306
|
+
return () => {
|
|
307
|
+
cancelAnimationFrame(frame);
|
|
308
|
+
controls?.stop();
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
const closing = (popup2) => {
|
|
312
|
+
returnTo.current = popup2.contains(document.activeElement) ? origin.current?.trigger ?? null : null;
|
|
313
|
+
if (!geometry.current) {
|
|
314
|
+
exited.current?.();
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const done = () => {
|
|
318
|
+
reveal();
|
|
319
|
+
geometry.current = null;
|
|
320
|
+
exited.current?.();
|
|
321
|
+
};
|
|
322
|
+
if (skip(popup2)) {
|
|
323
|
+
progress.jump(0);
|
|
324
|
+
popup2.style.opacity = "0";
|
|
325
|
+
done();
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
run.current = { effect: resolve(exit?.effect ?? effect), from: exit?.from ?? from };
|
|
329
|
+
if (exit)
|
|
330
|
+
progress.jump(1);
|
|
331
|
+
const hold = holdExit(popup2, timing(run.current.effect));
|
|
332
|
+
measure();
|
|
333
|
+
render(progress.get());
|
|
334
|
+
let controls;
|
|
335
|
+
controls = animate(progress, 0, {
|
|
336
|
+
...spring[timing(run.current.effect)].exit,
|
|
337
|
+
onUpdate: (p) => {
|
|
338
|
+
if (skip(popup2))
|
|
339
|
+
controls?.complete();
|
|
340
|
+
render(p);
|
|
341
|
+
},
|
|
342
|
+
onComplete: () => {
|
|
343
|
+
hold.finish();
|
|
344
|
+
done();
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
return () => {
|
|
348
|
+
controls?.stop();
|
|
349
|
+
hold.cancel();
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
useLayoutEffect(() => {
|
|
353
|
+
if (!popup) {
|
|
354
|
+
reveal();
|
|
355
|
+
progress.jump(0);
|
|
356
|
+
if (geometry.current && !open)
|
|
357
|
+
exited.current?.();
|
|
358
|
+
geometry.current = null;
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
return open ? opening(popup) : closing(popup);
|
|
362
|
+
}, [open, popup]);
|
|
363
|
+
useEffect(() => reveal, []);
|
|
364
|
+
const popupRef = useCallback((node) => {
|
|
365
|
+
refs.popup.current = node;
|
|
366
|
+
setPopup(node);
|
|
367
|
+
if (node || !returnTo.current)
|
|
368
|
+
return;
|
|
369
|
+
returnFocus(returnTo.current);
|
|
370
|
+
returnTo.current = null;
|
|
371
|
+
}, []);
|
|
372
|
+
return { refs, popupRef, popup, gooId, effect: resolved, progress };
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export { GOO_MATRIX, GOO_BLUR_RATIO, opensInPlace, inPlaceOffset, holdExit, useMorphOrigin, useMorph };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// lib/shape-context.tsx
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
var shapeMap = {
|
|
5
|
+
pill: {
|
|
6
|
+
variant: "pill",
|
|
7
|
+
item: "rounded-[20px]",
|
|
8
|
+
bg: "rounded-[20px]",
|
|
9
|
+
focusRing: "rounded-[22px]",
|
|
10
|
+
mergedBg: "rounded-2xl",
|
|
11
|
+
container: "rounded-3xl",
|
|
12
|
+
button: "rounded-[20px]",
|
|
13
|
+
input: "rounded-[20px]",
|
|
14
|
+
bgRadius: 20,
|
|
15
|
+
mergedRadius: 16
|
|
16
|
+
},
|
|
17
|
+
rounded: {
|
|
18
|
+
variant: "rounded",
|
|
19
|
+
item: "rounded-lg",
|
|
20
|
+
bg: "rounded-lg",
|
|
21
|
+
focusRing: "rounded-[10px]",
|
|
22
|
+
mergedBg: "rounded-lg",
|
|
23
|
+
container: "rounded-xl",
|
|
24
|
+
button: "rounded-lg",
|
|
25
|
+
input: "rounded-lg",
|
|
26
|
+
bgRadius: 8,
|
|
27
|
+
mergedRadius: 8
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var ShapeContext = createContext(null);
|
|
31
|
+
function useShape() {
|
|
32
|
+
const ctx = useContext(ShapeContext);
|
|
33
|
+
if (!ctx)
|
|
34
|
+
return shapeMap.rounded;
|
|
35
|
+
return ctx.classes;
|
|
36
|
+
}
|
|
37
|
+
function ShapeProvider({ children, defaultShape = "rounded" }) {
|
|
38
|
+
const [shape, setShapeState] = useState(defaultShape);
|
|
39
|
+
const transitionTimeoutRef = useRef(null);
|
|
40
|
+
const transitionShape = useCallback((callback) => {
|
|
41
|
+
const root = document.documentElement;
|
|
42
|
+
root.classList.add("transitioning");
|
|
43
|
+
root.offsetHeight;
|
|
44
|
+
callback();
|
|
45
|
+
if (transitionTimeoutRef.current)
|
|
46
|
+
clearTimeout(transitionTimeoutRef.current);
|
|
47
|
+
transitionTimeoutRef.current = setTimeout(() => root.classList.remove("transitioning"), 200);
|
|
48
|
+
}, []);
|
|
49
|
+
const setShape = useCallback((next) => {
|
|
50
|
+
transitionShape(() => setShapeState(next));
|
|
51
|
+
}, [transitionShape]);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
document.documentElement.style.setProperty("--shape-input-radius", `${shapeMap[shape].bgRadius}px`);
|
|
54
|
+
}, [shape]);
|
|
55
|
+
const value = useMemo(() => ({ shape, setShape, classes: shapeMap[shape] }), [shape, setShape]);
|
|
56
|
+
return /* @__PURE__ */ jsx(ShapeContext.Provider, {
|
|
57
|
+
value,
|
|
58
|
+
children
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { shapeMap, useShape, ShapeProvider };
|