@vite-hub/ui 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -81
- package/dist/announce-Cy_Tn9wW.js +32 -0
- package/dist/{code-view-D0bqhogi.js → code-view-DsU-xzic.js} +4 -4
- package/dist/comment-attachments-C4yNbcx5.js +20 -0
- package/dist/{comment-composer-jYv2ULNP.js → comment-composer-D7ZytyER.js} +257 -10
- package/dist/{comment-composer-Cc8Jvu6u.d.ts → comment-composer-DvKMTrAi.d.ts} +1 -1
- package/dist/{comment-layer-ClH4MLj4.d.ts → comment-layer-GTsLdABl.d.ts} +17 -6
- package/dist/{comment-list-B8hphLfS.d.ts → comment-list-BI96empx.d.ts} +2 -2
- package/dist/comment-marks.css +18 -22
- package/dist/{comment-panel-fcKSKwLC.d.ts → comment-panel-CsKWTms_.d.ts} +15 -4
- package/dist/{comment-row-Bbm9WwuF.js → comment-row-JmTC0uXr.js} +2 -2
- package/dist/comment-selection-bar-CyVBNYl9.d.ts +42 -0
- package/dist/comment-send-7bg4NEEM.js +277 -0
- package/dist/comment-send-C45dHC22.d.ts +25 -0
- package/dist/comment-send.css +267 -0
- package/dist/comment-thread-B_Sc2QX6.js +797 -0
- package/dist/{comment-thread-CoTLrdal.d.ts → comment-thread-C6U-bsK_.d.ts} +23 -6
- package/dist/{comments-CkWc2Khc.js → comments-B88zg9gC.js} +66 -10
- package/dist/{comments-Bx2WRsYy.d.ts → comments-D8hulVPy.d.ts} +34 -6
- package/dist/{comments-context-C2lOZyQ5.js → comments-context-DhbIdYQ1.js} +2 -1
- package/dist/{config-Dk67emQt.js → config-B1u7zqMB.js} +8 -1
- package/dist/{config-DgxBW013.d.ts → config-pHazYdq6.d.ts} +11 -0
- package/dist/drop-field-3CDRFFRm.js +163 -0
- package/dist/{editor-C_wt4RRV.js → editor-BHYGLgty.js} +42 -3
- package/dist/effects-Ql6VzCRa.js +2971 -0
- package/dist/format-orwcdZL_.js +39 -0
- package/dist/headless.d.ts +2 -2
- package/dist/headless.js +1 -1
- package/dist/hold-to-delete-DjWzRDyY.d.ts +51 -0
- package/dist/hold-to-delete-ROLQRZg_.js +434 -0
- package/dist/icon-c5Jb_Tl7.d.ts +31 -0
- package/dist/{image-preview-C9tdkmEj.js → image-preview-BigoAvb3.js} +2 -2
- package/dist/{index-BD1e8vx5.d.ts → index-YUvL2nV8.d.ts} +10 -6
- package/dist/index.d.ts +18 -12
- package/dist/index.js +47 -45
- package/dist/install-D5f6msEU.js +17 -0
- package/dist/list-RCbNZ14q.js +271 -0
- package/dist/{markdown-editor-CMbNZOdN.js → markdown-editor-Dfl2DgPS.js} +1 -1
- package/dist/{markdown-editor-DqdZfIEn.d.ts → markdown-editor-wQF0yD5o.d.ts} +1 -1
- package/dist/markdown-editor.d.ts +1 -1
- package/dist/markdown-editor.js +1 -1
- package/dist/motion/core.d.ts +4 -0
- package/dist/motion/core.js +11 -0
- package/dist/motion-core-lHRF8PZz.d.ts +456 -0
- package/dist/motion.d.ts +16 -0
- package/dist/motion.js +13 -0
- package/dist/{nuxt-ui-DSQFzq3s.js → nuxt-ui-CgvMzO5v.js} +20 -14
- package/dist/nuxt.d.ts +2 -2
- package/dist/nuxt.js +20 -5
- package/dist/opt-out-b6bnUjIT.js +208 -0
- package/dist/parts/components/agent-session.js +1 -1
- package/dist/parts/components/attachment.js +1 -1
- package/dist/parts/components/avatar-stack.js +3 -2
- package/dist/parts/components/chat-session.d.ts +1 -1
- package/dist/parts/components/chat.js +2 -2
- package/dist/parts/components/code-block.js +1 -1
- package/dist/parts/components/code-view.js +1 -1
- package/dist/parts/components/comment-composer.d.ts +1 -1
- package/dist/parts/components/comment-composer.js +1 -1
- package/dist/parts/components/comment-layer.d.ts +1 -1
- package/dist/parts/components/comment-layer.js +54 -23
- package/dist/parts/components/comment-list.d.ts +1 -1
- package/dist/parts/components/comment-list.js +13 -7
- package/dist/parts/components/comment-panel.d.ts +1 -1
- package/dist/parts/components/comment-panel.js +46 -20
- package/dist/parts/components/comment-pin.js +1 -1
- package/dist/parts/components/comment-selection-bar.d.ts +2 -0
- package/dist/parts/components/comment-selection-bar.js +117 -0
- package/dist/parts/components/comment-send.d.ts +2 -0
- package/dist/parts/components/comment-send.js +2 -0
- package/dist/parts/components/comment-thread.d.ts +2 -2
- package/dist/parts/components/comment-thread.js +2 -570
- package/dist/parts/components/comments.d.ts +8 -6
- package/dist/parts/components/comments.js +6 -4
- package/dist/parts/components/copy-button.d.ts +12 -2
- package/dist/parts/components/copy-button.js +226 -1
- package/dist/parts/components/drop-field.d.ts +69 -0
- package/dist/parts/components/drop-field.js +77 -0
- package/dist/parts/components/filter-search.js +1 -1
- package/dist/parts/components/hold-to-delete.d.ts +82 -0
- package/dist/parts/components/hold-to-delete.js +76 -0
- package/dist/parts/components/markdown-editor.d.ts +1 -1
- package/dist/parts/components/markdown-editor.js +1 -1
- package/dist/parts/components/markdown-renderer.js +1 -1
- package/dist/parts/components/markdown.js +1 -1
- package/dist/parts/components/message-parts.js +13 -5
- package/dist/parts/components/motion-list.d.ts +42 -0
- package/dist/parts/components/motion-list.js +42 -0
- package/dist/parts/components/motion.d.ts +124 -0
- package/dist/parts/components/motion.js +172 -0
- package/dist/parts/components/progress.d.ts +41 -0
- package/dist/parts/components/progress.js +54 -0
- package/dist/parts/components/prompt-input.d.ts +3 -3
- package/dist/parts/components/prompt-input.js +3 -3
- package/dist/parts/components/relative-time.js +1 -1
- package/dist/parts/components/sync-status.js +2 -1
- package/dist/parts/components/tool-list.d.ts +1 -1
- package/dist/parts/components/trace-run.d.ts +1 -1
- package/dist/parts/components/trace-run.js +2 -2
- package/dist/parts/headless/comments.d.ts +2 -2
- package/dist/parts/headless/comments.js +1 -1
- package/dist/parts/playground/share.d.ts +36 -2
- package/dist/parts/workspace/browser-support-notice.js +12 -4
- package/dist/parts/workspace/codemirror.d.ts +9 -0
- package/dist/parts/workspace/codemirror.js +37 -4
- package/dist/parts/workspace/connect-panel.js +1 -1
- package/dist/parts/workspace/file-icons.d.ts +16 -0
- package/dist/parts/workspace/file-icons.js +82 -0
- package/dist/parts/workspace/icons.d.ts +1 -0
- package/dist/parts/workspace/icons.js +1 -0
- package/dist/parts/workspace/runners/render.d.ts +26 -0
- package/dist/parts/workspace/runners/render.js +124 -0
- package/dist/parts/workspace/runners/web-container.d.ts +29 -0
- package/dist/parts/workspace/runners/web-container.js +186 -0
- package/dist/parts/workspace/workspace-bar.d.ts +51 -0
- package/dist/parts/workspace/workspace-bar.js +51 -0
- package/dist/parts/workspace/workspace-boot-status.js +1 -1
- package/dist/parts/workspace/workspace-editor-head.d.ts +47 -0
- package/dist/parts/workspace/workspace-editor-head.js +66 -0
- package/dist/parts/workspace/workspace-editor.d.ts +17 -0
- package/dist/parts/workspace/workspace-editor.js +29 -3
- package/dist/parts/workspace/workspace-examples.d.ts +74 -0
- package/dist/parts/workspace/workspace-examples.js +72 -0
- package/dist/parts/workspace/workspace-file-link.d.ts +35 -0
- package/dist/parts/workspace/workspace-file-link.js +39 -0
- package/dist/parts/workspace/workspace-file-tree.d.ts +8 -8
- package/dist/parts/workspace/workspace-file-tree.js +26 -19
- package/dist/parts/workspace/workspace-guide.d.ts +52 -0
- package/dist/parts/workspace/workspace-guide.js +91 -0
- package/dist/parts/workspace/workspace-issues.d.ts +46 -0
- package/dist/parts/workspace/workspace-issues.js +49 -0
- package/dist/parts/workspace/workspace-preview.js +1 -1
- package/dist/parts/workspace/workspace-shell.d.ts +2 -88
- package/dist/parts/workspace/workspace-shell.js +131 -78
- package/dist/parts/workspace/workspace-sidebar.d.ts +75 -0
- package/dist/parts/workspace/workspace-sidebar.js +132 -0
- package/dist/parts/workspace/workspace-start.d.ts +47 -0
- package/dist/parts/workspace/workspace-start.js +60 -0
- package/dist/parts/workspace/workspace-status.d.ts +69 -0
- package/dist/parts/workspace/workspace-status.js +74 -0
- package/dist/parts/workspace/workspace-steps.d.ts +2 -0
- package/dist/parts/workspace/workspace-steps.js +128 -0
- package/dist/parts/workspace/workspace-task.d.ts +20 -0
- package/dist/parts/workspace/workspace-task.js +20 -0
- package/dist/parts/workspace/workspace.d.ts +251 -0
- package/dist/parts/workspace/workspace.js +665 -0
- package/dist/{pierre-code-view-xgBL6DO7.js → pierre-code-view-NE35tkmR.js} +37 -17
- package/dist/playground.d.ts +1 -1
- package/dist/progress-C7afI5vq.js +266 -0
- package/dist/registry-D3-ysX7l.js +78 -0
- package/dist/{relative-time-BVmjOsYG.js → relative-time-DgSS3zKN.js} +1 -1
- package/dist/ring-B7Qxu7zd.js +175 -0
- package/dist/runtime/nuxt-plugin.js +2 -2
- package/dist/styles.css +657 -526
- package/dist/text-BCJflBJf.js +826 -0
- package/dist/theme.d.ts +43 -0
- package/dist/theme.js +22 -7
- package/dist/travel-C87xd5Wh.js +182 -0
- package/dist/tween-CO24nMpf.js +62 -0
- package/dist/{types-Dyr6CfBW.d.ts → types-BX64qHlV.d.ts} +1 -1
- package/dist/visual-copy-CrVc3z4n.js +15 -0
- package/dist/workspace-shell-BJGnoF3p.d.ts +112 -0
- package/dist/workspace-steps-Bgph2rpr.d.ts +72 -0
- package/dist/workspace.d.ts +17 -4
- package/dist/workspace.js +16 -3
- package/package.json +22 -11
- package/dist/copy-button-CRN3kmSD.js +0 -253
- package/dist/format-Du58PlsG.js +0 -18
- package/dist/icon-swap.css +0 -69
- package/dist/parts/playground/highlight.d.ts +0 -5
- package/dist/parts/playground/highlight.js +0 -23
- package/dist/parts/playground/playground-render.d.ts +0 -126
- package/dist/parts/playground/playground-render.js +0 -356
- package/dist/parts/workspace/playground-container.d.ts +0 -192
- package/dist/parts/workspace/playground-container.js +0 -603
- package/dist/share-DM4eNy4q.d.ts +0 -37
|
@@ -0,0 +1,2971 @@
|
|
|
1
|
+
import { c as offsetIn, d as iconShape, n as morph, o as enterIcon, r as morphTarget, s as leaveIcon, t as discardMorph, u as findIcons } from "./text-BCJflBJf.js";
|
|
2
|
+
import { i as getMotionSlowFactor, l as onReducedMotionChange, r as createSpring, s as springs, t as isMotionOff, u as prefersReducedMotion } from "./opt-out-b6bnUjIT.js";
|
|
3
|
+
import { a as listMotionEffects, c as onMotionEffectsChange, i as handOffMotionEffects, l as otherMotionLayer, o as motionEffectRegistrations, r as defineOwnEffect, s as motionStateAttributes, t as claimMotionLayer, u as writeMotionStyle } from "./registry-D3-ysX7l.js";
|
|
4
|
+
import { a as isOwnNode, c as own } from "./ring-B7Qxu7zd.js";
|
|
5
|
+
//#region src/motion/effects/divider.ts
|
|
6
|
+
const springBack = {
|
|
7
|
+
stiffness: 500,
|
|
8
|
+
damping: 14
|
|
9
|
+
};
|
|
10
|
+
const reach = 60;
|
|
11
|
+
const inset = 40;
|
|
12
|
+
const svgNamespace$1 = "http://www.w3.org/2000/svg";
|
|
13
|
+
const rekaDragAttribute = "data-resize-handle-active";
|
|
14
|
+
const bends = /* @__PURE__ */ new WeakMap();
|
|
15
|
+
function axisOf$1(handle, rect) {
|
|
16
|
+
const orientation = handle.getAttribute("aria-orientation");
|
|
17
|
+
if (orientation === "vertical") return "x";
|
|
18
|
+
if (orientation === "horizontal") return "y";
|
|
19
|
+
return rect.height >= rect.width ? "x" : "y";
|
|
20
|
+
}
|
|
21
|
+
function shows(color) {
|
|
22
|
+
return !/^transparent$|rgba\([^)]*,\s*0\)$|\/\s*0\)$/.test(color.trim());
|
|
23
|
+
}
|
|
24
|
+
function lineOf(handle, axis) {
|
|
25
|
+
const across = (style) => Number.parseFloat(axis === "x" ? style.width : style.height);
|
|
26
|
+
const styles = [
|
|
27
|
+
[getComputedStyle(handle), handle],
|
|
28
|
+
[getComputedStyle(handle, "::before"), handle],
|
|
29
|
+
[getComputedStyle(handle, "::after"), handle]
|
|
30
|
+
];
|
|
31
|
+
for (const child of handle.children) if (child instanceof HTMLElement) styles.push([getComputedStyle(child), child]);
|
|
32
|
+
for (const [style, element] of styles) {
|
|
33
|
+
const width = across(style);
|
|
34
|
+
if (style.display !== "none" && shows(style.backgroundColor) && width > 0 && width <= 4) return {
|
|
35
|
+
color: style.backgroundColor,
|
|
36
|
+
width,
|
|
37
|
+
element
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
color: "var(--ui-border, var(--vh-border, currentColor))",
|
|
42
|
+
width: 1
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function draw$4(bend, amount) {
|
|
46
|
+
const { handle, axis, line } = bend;
|
|
47
|
+
if (Math.abs(amount) < .5 && !bend.spring.active) {
|
|
48
|
+
bend.lane?.svg.remove();
|
|
49
|
+
if (line.element && bend.opacity) line.element.style.setProperty("opacity", bend.opacity.value, bend.opacity.priority);
|
|
50
|
+
if (bends.get(handle) === bend) bends.delete(handle);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!bend.lane) {
|
|
54
|
+
const svg = document.createElementNS(svgNamespace$1, "svg");
|
|
55
|
+
svg.setAttribute("aria-hidden", "true");
|
|
56
|
+
svg.dataset.motion = "bend";
|
|
57
|
+
svg.style.cssText = "position:absolute;left:0;top:0;width:1px;height:1px;overflow:visible;pointer-events:none;z-index:1";
|
|
58
|
+
const path = document.createElementNS(svgNamespace$1, "path");
|
|
59
|
+
path.setAttribute("fill", "none");
|
|
60
|
+
path.style.stroke = line.color;
|
|
61
|
+
path.style.strokeWidth = `${line.width}px`;
|
|
62
|
+
svg.append(path);
|
|
63
|
+
bend.lane = {
|
|
64
|
+
svg,
|
|
65
|
+
path
|
|
66
|
+
};
|
|
67
|
+
if (line.element) {
|
|
68
|
+
const { style } = line.element;
|
|
69
|
+
bend.opacity = {
|
|
70
|
+
value: style.opacity,
|
|
71
|
+
priority: style.getPropertyPriority("opacity")
|
|
72
|
+
};
|
|
73
|
+
style.setProperty("opacity", "0");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const { svg, path } = bend.lane;
|
|
77
|
+
if (!svg.isConnected) handle.after(svg);
|
|
78
|
+
const zoom = handle.offsetHeight ? handle.getBoundingClientRect().height / handle.offsetHeight || 1 : 1;
|
|
79
|
+
const scaled = (box) => ({
|
|
80
|
+
left: box.left / zoom,
|
|
81
|
+
top: box.top / zoom,
|
|
82
|
+
width: box.width / zoom,
|
|
83
|
+
height: box.height / zoom
|
|
84
|
+
});
|
|
85
|
+
const origin = scaled(svg.getBoundingClientRect());
|
|
86
|
+
const rect = scaled(handle.getBoundingClientRect());
|
|
87
|
+
const u = axis === "x" ? rect.left + rect.width / 2 - origin.left : rect.top + rect.height / 2 - origin.top;
|
|
88
|
+
const from = axis === "x" ? rect.top - origin.top : rect.left - origin.left;
|
|
89
|
+
const to = from + (axis === "x" ? rect.height : rect.width);
|
|
90
|
+
const middle = (from + to) / 2;
|
|
91
|
+
const at = to - from > 80 ? Math.max(from + inset, Math.min(to - inset, bend.at / zoom - (axis === "x" ? origin.top : origin.left))) : middle;
|
|
92
|
+
const point = (along, across) => axis === "x" ? `${across.toFixed(2)},${along.toFixed(2)}` : `${along.toFixed(2)},${across.toFixed(2)}`;
|
|
93
|
+
const tip = u + amount;
|
|
94
|
+
path.setAttribute("d", `M${point(from, u)} C${point(at - 70, u)} ${point(at - 40, tip)} ${point(at, tip)} C${point(at + 40, tip)} ${point(at + 70, u)} ${point(to, u)}`);
|
|
95
|
+
}
|
|
96
|
+
function draggable(handle) {
|
|
97
|
+
if (handle.matches("[aria-disabled=true], [data-disabled]:not([data-disabled=false]), [data-panel-resize-handle-enabled=false]")) return false;
|
|
98
|
+
return /resize/.test(getComputedStyle(handle).cursor) || handle.tabIndex >= 0 || handle.hasAttribute("aria-valuenow");
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Drag a value (docs/design/motion.md): a divider, `[role=separator]` that a person can drag, from Nuxt UI `USplitter`,
|
|
102
|
+
* `UDashboardPanel`, Reka, ui-sdk and kit `Resizable`, or a plain handle. Past the limit of its panel, the divider
|
|
103
|
+
* stays where its component keeps it and its line bends toward the pointer. On release it springs back straight.
|
|
104
|
+
*/
|
|
105
|
+
const divider = {
|
|
106
|
+
name: "divider",
|
|
107
|
+
selector: "[role=separator]",
|
|
108
|
+
press(handle, event) {
|
|
109
|
+
if (!(event instanceof PointerEvent) || !draggable(handle)) return;
|
|
110
|
+
if (handle.matches("[role=separator][data-panel-resize-handle-id]") && handle.getAttribute("data-resize-handle-active") !== "pointer") return;
|
|
111
|
+
const rect = handle.getBoundingClientRect();
|
|
112
|
+
const axis = axisOf$1(handle, rect);
|
|
113
|
+
const along = (pointer) => axis === "x" ? pointer.clientX : pointer.clientY;
|
|
114
|
+
const across = (pointer) => axis === "x" ? pointer.clientY : pointer.clientX;
|
|
115
|
+
const center = (box) => axis === "x" ? box.left + box.width / 2 : box.top + box.height / 2;
|
|
116
|
+
const grab = along(event) - center(rect);
|
|
117
|
+
let bend = bends.get(handle);
|
|
118
|
+
if (!bend) {
|
|
119
|
+
const current = {
|
|
120
|
+
handle,
|
|
121
|
+
axis,
|
|
122
|
+
line: lineOf(handle, axis),
|
|
123
|
+
at: across(event),
|
|
124
|
+
spring: createSpring(0, (value) => draw$4(current, value), springBack)
|
|
125
|
+
};
|
|
126
|
+
bend = current;
|
|
127
|
+
bends.set(handle, bend);
|
|
128
|
+
}
|
|
129
|
+
const active = bend;
|
|
130
|
+
active.at = across(event);
|
|
131
|
+
let pointer = event;
|
|
132
|
+
let frame = 0;
|
|
133
|
+
const measure = () => {
|
|
134
|
+
frame = 0;
|
|
135
|
+
const box = handle.getBoundingClientRect();
|
|
136
|
+
const zoom = handle.offsetHeight ? box.height / handle.offsetHeight || 1 : 1;
|
|
137
|
+
const over = (along(pointer) - grab - center(box)) / zoom;
|
|
138
|
+
active.at = across(pointer);
|
|
139
|
+
active.spring.set(Math.abs(over) < 1 ? 0 : over / (1 + Math.abs(over) / reach));
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
move(next) {
|
|
143
|
+
pointer = next;
|
|
144
|
+
if (!frame) frame = requestAnimationFrame(measure);
|
|
145
|
+
},
|
|
146
|
+
release() {
|
|
147
|
+
cancelAnimationFrame(frame);
|
|
148
|
+
active.spring.to(0, { preset: springBack });
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/motion/layer.ts
|
|
155
|
+
const roots = /* @__PURE__ */ new Map();
|
|
156
|
+
let observer;
|
|
157
|
+
const presses = /* @__PURE__ */ new Map();
|
|
158
|
+
let splitterPointer;
|
|
159
|
+
let stopWatching = [];
|
|
160
|
+
const pressedBy = Symbol.for("vite-hub.motion.effect-presses");
|
|
161
|
+
const eventPresses = (event) => {
|
|
162
|
+
const claimed = Reflect.get(event, pressedBy);
|
|
163
|
+
if (claimed) return claimed;
|
|
164
|
+
const effects = /* @__PURE__ */ new Map();
|
|
165
|
+
Reflect.set(event, pressedBy, effects);
|
|
166
|
+
return effects;
|
|
167
|
+
};
|
|
168
|
+
const unreadable = /* @__PURE__ */ new Set();
|
|
169
|
+
/** `element.matches(selector)`, false for a selector that this browser cannot read. */
|
|
170
|
+
function matches(element, selector) {
|
|
171
|
+
if (unreadable.has(selector)) return false;
|
|
172
|
+
try {
|
|
173
|
+
return element.matches(selector);
|
|
174
|
+
} catch {
|
|
175
|
+
unreadable.add(selector);
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* True when an install covers the element: an installed element contains it, or its root is installed, also through the
|
|
181
|
+
* shadow hosts around it. An app that installs the document covers the shadow roots in it, and the page pill, which
|
|
182
|
+
* installs only its own host and shadow roots, does not move the buttons of the page that it is on.
|
|
183
|
+
*/
|
|
184
|
+
function covered(element) {
|
|
185
|
+
let node = element;
|
|
186
|
+
for (;;) {
|
|
187
|
+
for (const root of roots.keys()) if (root instanceof Element && root.contains(node)) return true;
|
|
188
|
+
const root = node.getRootNode();
|
|
189
|
+
if ((root instanceof Document || root instanceof ShadowRoot) && roots.has(root)) return true;
|
|
190
|
+
if (!(root instanceof ShadowRoot)) return false;
|
|
191
|
+
node = root.host;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/** The innermost element on the event path that matches `selector`, that an install covers, and that is not inside `[data-motion="none"]`. */
|
|
195
|
+
function find(path, selector) {
|
|
196
|
+
let lastOff = -1;
|
|
197
|
+
path.forEach((node, index) => {
|
|
198
|
+
if (node instanceof Element && node.matches("[data-motion=\"none\"]")) lastOff = index;
|
|
199
|
+
});
|
|
200
|
+
const index = path.findIndex((node) => node instanceof HTMLElement && matches(node, selector));
|
|
201
|
+
return index === -1 || index <= lastOff || !covered(path[index]) ? void 0 : path[index];
|
|
202
|
+
}
|
|
203
|
+
function begin(id, event, path) {
|
|
204
|
+
end(id, true);
|
|
205
|
+
const claimed = eventPresses(event);
|
|
206
|
+
const started = [];
|
|
207
|
+
for (const { effect, isReduced } of motionEffectRegistrations()) {
|
|
208
|
+
if (!effect.press || isReduced()) continue;
|
|
209
|
+
const element = find(path, effect.selector);
|
|
210
|
+
if (!element || id === "key" && element !== path[0]) continue;
|
|
211
|
+
const previous = claimed.get(element);
|
|
212
|
+
if (previous?.has(effect.name)) continue;
|
|
213
|
+
const press = effect.press(element, event);
|
|
214
|
+
if (!press) continue;
|
|
215
|
+
if (previous) previous.add(effect.name);
|
|
216
|
+
else claimed.set(element, /* @__PURE__ */ new Set([effect.name]));
|
|
217
|
+
const item = {
|
|
218
|
+
element,
|
|
219
|
+
press
|
|
220
|
+
};
|
|
221
|
+
if (id !== "key" && !press.move) {
|
|
222
|
+
item.leave = () => endItem(id, item, true);
|
|
223
|
+
element.addEventListener("pointerleave", item.leave, { once: true });
|
|
224
|
+
}
|
|
225
|
+
started.push(item);
|
|
226
|
+
}
|
|
227
|
+
if (!started.length) return;
|
|
228
|
+
presses.set(id, started);
|
|
229
|
+
if (started.some((item) => item.press.move)) document.addEventListener("pointermove", onPointerMove, {
|
|
230
|
+
capture: true,
|
|
231
|
+
passive: true
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
function end(id, cancelled = false) {
|
|
235
|
+
const items = presses.get(id);
|
|
236
|
+
if (!items) return;
|
|
237
|
+
presses.delete(id);
|
|
238
|
+
for (const { element, press, leave } of items) {
|
|
239
|
+
if (leave) element.removeEventListener("pointerleave", leave);
|
|
240
|
+
if (cancelled && press.cancel) press.cancel();
|
|
241
|
+
else press.release();
|
|
242
|
+
}
|
|
243
|
+
stopPointerMoveIfIdle();
|
|
244
|
+
}
|
|
245
|
+
function endItem(id, item, cancelled = false) {
|
|
246
|
+
const items = presses.get(id);
|
|
247
|
+
const index = items?.indexOf(item) ?? -1;
|
|
248
|
+
if (!items || index === -1) return;
|
|
249
|
+
if (item.leave) item.element.removeEventListener("pointerleave", item.leave);
|
|
250
|
+
items.splice(index, 1);
|
|
251
|
+
if (!items.length) presses.delete(id);
|
|
252
|
+
if (cancelled && item.press.cancel) item.press.cancel();
|
|
253
|
+
else item.press.release();
|
|
254
|
+
stopPointerMoveIfIdle();
|
|
255
|
+
}
|
|
256
|
+
function stopPointerMoveIfIdle() {
|
|
257
|
+
if (![...presses.values()].some((list) => list.some((item) => item.press.move))) document.removeEventListener("pointermove", onPointerMove, { capture: true });
|
|
258
|
+
}
|
|
259
|
+
function onPointerDown(event) {
|
|
260
|
+
if (event.button !== 0) return;
|
|
261
|
+
const path = event.composedPath();
|
|
262
|
+
if (event.isPrimary) splitterPointer = {
|
|
263
|
+
event,
|
|
264
|
+
path
|
|
265
|
+
};
|
|
266
|
+
begin(event.pointerId, event, path);
|
|
267
|
+
}
|
|
268
|
+
function onPointerUp(event) {
|
|
269
|
+
if (splitterPointer?.event.pointerId === event.pointerId) splitterPointer = void 0;
|
|
270
|
+
end(event.pointerId, event.type === "pointercancel");
|
|
271
|
+
}
|
|
272
|
+
function onPointerMove(event) {
|
|
273
|
+
for (const { press } of presses.get(event.pointerId) ?? []) press.move?.(event);
|
|
274
|
+
}
|
|
275
|
+
function onKeyDown(event) {
|
|
276
|
+
if (event.repeat || event.key !== " " && event.key !== "Enter") return;
|
|
277
|
+
const path = event.composedPath();
|
|
278
|
+
if (event.key === " " && path[0] instanceof Element && path[0].matches("a[href], [role=link]")) return;
|
|
279
|
+
begin("key", event, path);
|
|
280
|
+
}
|
|
281
|
+
function onKeyUp(event) {
|
|
282
|
+
if (event.key === " " || event.key === "Enter") end("key");
|
|
283
|
+
}
|
|
284
|
+
function collectContent(records, effects) {
|
|
285
|
+
const watching = effects.filter((effect) => effect.content);
|
|
286
|
+
if (!watching.length) return;
|
|
287
|
+
const changes = /* @__PURE__ */ new Map();
|
|
288
|
+
for (const record of records) {
|
|
289
|
+
if (record.type === "attributes") continue;
|
|
290
|
+
const element = record.type === "characterData" ? record.target.parentElement : record.target;
|
|
291
|
+
if (!(element instanceof HTMLElement || element instanceof SVGElement)) continue;
|
|
292
|
+
let change = changes.get(element);
|
|
293
|
+
if (!change) {
|
|
294
|
+
change = {
|
|
295
|
+
added: [],
|
|
296
|
+
removed: [],
|
|
297
|
+
oldText: void 0,
|
|
298
|
+
texts: /* @__PURE__ */ new Map()
|
|
299
|
+
};
|
|
300
|
+
changes.set(element, change);
|
|
301
|
+
}
|
|
302
|
+
if (record.type === "characterData") {
|
|
303
|
+
if (!change.texts.has(record.target)) change.texts.set(record.target, record.oldValue);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
change.added.push(...record.addedNodes);
|
|
307
|
+
change.removed.push(...record.removedNodes);
|
|
308
|
+
}
|
|
309
|
+
for (const [element, change] of changes) {
|
|
310
|
+
if (!element.isConnected) continue;
|
|
311
|
+
const added = change.added.filter((node) => !change.removed.includes(node));
|
|
312
|
+
const removed = change.removed.filter((node) => !change.added.includes(node));
|
|
313
|
+
const texts = change.texts;
|
|
314
|
+
let oldText;
|
|
315
|
+
const children = [...element.childNodes];
|
|
316
|
+
if (removed.length && children.every((node) => added.includes(node))) oldText = removed.map((node) => node.textContent ?? "").join("");
|
|
317
|
+
else if (texts.size === 1 && children.length === 1 && texts.has(children[0])) oldText = texts.get(children[0]) ?? "";
|
|
318
|
+
for (const effect of watching) if (matches(element, effect.selector) && !isMotionOff(element)) effect.content(element, {
|
|
319
|
+
added,
|
|
320
|
+
removed,
|
|
321
|
+
oldText
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function onSplitterDrag(handle) {
|
|
326
|
+
if (!splitterPointer || !handle.matches("[role=separator][data-panel-resize-handle-id]")) return;
|
|
327
|
+
const registration = motionEffectRegistrations().find(({ effect }) => effect.name === "divider");
|
|
328
|
+
if (!registration || registration.isReduced()) return;
|
|
329
|
+
const { event, path } = splitterPointer;
|
|
330
|
+
const items = presses.get(event.pointerId) ?? [];
|
|
331
|
+
const current = items.find((item) => item.splitter && item.element === handle);
|
|
332
|
+
if (handle.getAttribute("data-resize-handle-active") !== "pointer") {
|
|
333
|
+
if (current) endItem(event.pointerId, current);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (current || !path.includes(handle.getRootNode()) || !covered(handle) || isMotionOff(handle)) return;
|
|
337
|
+
const press = registration.effect.press?.(handle, event);
|
|
338
|
+
if (!press) return;
|
|
339
|
+
items.push({
|
|
340
|
+
element: handle,
|
|
341
|
+
press,
|
|
342
|
+
splitter: true
|
|
343
|
+
});
|
|
344
|
+
presses.set(event.pointerId, items);
|
|
345
|
+
document.addEventListener("pointermove", onPointerMove, {
|
|
346
|
+
capture: true,
|
|
347
|
+
passive: true
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
function onMutations(batch) {
|
|
351
|
+
const records = [...new Set(batch)];
|
|
352
|
+
const effects = listMotionEffects();
|
|
353
|
+
const dispatched = /* @__PURE__ */ new Map();
|
|
354
|
+
collectContent(records, effects);
|
|
355
|
+
for (const record of records) {
|
|
356
|
+
if (record.type === "characterData") continue;
|
|
357
|
+
if (record.type === "attributes") {
|
|
358
|
+
const element = record.target;
|
|
359
|
+
if (!(element instanceof HTMLElement)) continue;
|
|
360
|
+
if (record.attributeName === "data-resize-handle-active") {
|
|
361
|
+
onSplitterDrag(element);
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
const attribute = record.attributeName;
|
|
365
|
+
const value = element.getAttribute(attribute);
|
|
366
|
+
if (value === record.oldValue) continue;
|
|
367
|
+
let attributes = dispatched.get(element);
|
|
368
|
+
if (!attributes) dispatched.set(element, attributes = /* @__PURE__ */ new Map());
|
|
369
|
+
let oldValues = attributes.get(attribute);
|
|
370
|
+
if (!oldValues) attributes.set(attribute, oldValues = /* @__PURE__ */ new Set());
|
|
371
|
+
if (oldValues.has(record.oldValue)) continue;
|
|
372
|
+
oldValues.add(record.oldValue);
|
|
373
|
+
for (const effect of effects) if (effect.state && matches(element, effect.selector) && !isMotionOff(element)) effect.state(element, {
|
|
374
|
+
attribute,
|
|
375
|
+
oldValue: record.oldValue,
|
|
376
|
+
value
|
|
377
|
+
});
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
for (const node of record.addedNodes) {
|
|
381
|
+
if (!(node instanceof HTMLElement) || !node.isConnected) continue;
|
|
382
|
+
for (const effect of effects) {
|
|
383
|
+
if (!effect.enter) continue;
|
|
384
|
+
const self = matches(node, effect.selector);
|
|
385
|
+
if (unreadable.has(effect.selector)) continue;
|
|
386
|
+
const found = [...self ? [node] : [], ...node.querySelectorAll(effect.selector)];
|
|
387
|
+
for (const element of found) if (!isMotionOff(element)) effect.enter(element);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
function observe(root, observer) {
|
|
393
|
+
const content = listMotionEffects().some((effect) => effect.content);
|
|
394
|
+
observer.observe(root, {
|
|
395
|
+
attributes: true,
|
|
396
|
+
attributeFilter: [...motionStateAttributes, ...listMotionEffects().some((effect) => effect.name === "divider") ? [rekaDragAttribute] : []],
|
|
397
|
+
attributeOldValue: true,
|
|
398
|
+
childList: content || listMotionEffects().some((effect) => effect.enter),
|
|
399
|
+
characterData: content,
|
|
400
|
+
characterDataOldValue: content,
|
|
401
|
+
subtree: true
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
function syncWatchers(root, watchers) {
|
|
405
|
+
const effects = listMotionEffects();
|
|
406
|
+
for (const [effect, stop] of watchers) {
|
|
407
|
+
if (effects.includes(effect)) continue;
|
|
408
|
+
stop();
|
|
409
|
+
watchers.delete(effect);
|
|
410
|
+
}
|
|
411
|
+
for (const effect of effects) if (effect.watch && !watchers.has(effect)) watchers.set(effect, effect.watch(root));
|
|
412
|
+
}
|
|
413
|
+
function startDocument() {
|
|
414
|
+
const options = {
|
|
415
|
+
capture: true,
|
|
416
|
+
passive: true
|
|
417
|
+
};
|
|
418
|
+
document.addEventListener("pointerdown", onPointerDown, options);
|
|
419
|
+
document.addEventListener("pointerup", onPointerUp, options);
|
|
420
|
+
document.addEventListener("pointercancel", onPointerUp, options);
|
|
421
|
+
document.addEventListener("keydown", onKeyDown, options);
|
|
422
|
+
document.addEventListener("keyup", onKeyUp, options);
|
|
423
|
+
stopWatching = [() => {
|
|
424
|
+
document.removeEventListener("pointerdown", onPointerDown, options);
|
|
425
|
+
document.removeEventListener("pointerup", onPointerUp, options);
|
|
426
|
+
document.removeEventListener("pointercancel", onPointerUp, options);
|
|
427
|
+
document.removeEventListener("keydown", onKeyDown, options);
|
|
428
|
+
document.removeEventListener("keyup", onKeyUp, options);
|
|
429
|
+
splitterPointer = void 0;
|
|
430
|
+
for (const id of presses.keys()) end(id, true);
|
|
431
|
+
}, onReducedMotionChange((reduced) => {
|
|
432
|
+
if (!reduced) return;
|
|
433
|
+
splitterPointer = void 0;
|
|
434
|
+
for (const id of presses.keys()) end(id, true);
|
|
435
|
+
})];
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Starts the motion layer in `root`, the document, a shadow root, or an element and everything in it, with the effects
|
|
439
|
+
* in `options.effects`. The other built-in effects stay out of the bundle. It listens once on the document and reads the composed path, so a press also reaches
|
|
440
|
+
* the shadow roots inside an installed root. Pass a shadow root to also watch the state attributes inside it: an
|
|
441
|
+
* observer does not see into a shadow root. A surface that installs only its own host and shadow roots, such as the
|
|
442
|
+
* page pill, does not move the elements of the page around it.
|
|
443
|
+
*
|
|
444
|
+
* It is safe to call more than once. Returns a function that stops this install. The layer stops when every install
|
|
445
|
+
* has stopped. On the server it does nothing. `installMotion(root?)` of `@vite-hub/ui/motion` is this function with
|
|
446
|
+
* every built-in effect.
|
|
447
|
+
*
|
|
448
|
+
* When another copy of the module installed first, this install and these effects go to that copy, the shared layer,
|
|
449
|
+
* so an element that both copies cover moves once.
|
|
450
|
+
*/
|
|
451
|
+
function installMotion(root, options) {
|
|
452
|
+
if (typeof document === "undefined") return () => {};
|
|
453
|
+
const shared = otherMotionLayer();
|
|
454
|
+
if (shared) {
|
|
455
|
+
handOffMotionEffects(shared);
|
|
456
|
+
return shared.install(root, options.effects, prefersReducedMotion);
|
|
457
|
+
}
|
|
458
|
+
claimMotionLayer(sharedLayer);
|
|
459
|
+
return installOwn(root, options.effects);
|
|
460
|
+
}
|
|
461
|
+
const sharedLayer = {
|
|
462
|
+
define: defineOwnEffect,
|
|
463
|
+
install: installOwn
|
|
464
|
+
};
|
|
465
|
+
function installOwn(root, effects, isReduced = prefersReducedMotion) {
|
|
466
|
+
const defined = new Set(listMotionEffects().map((effect) => effect.name));
|
|
467
|
+
for (const effect of effects) if (!defined.has(effect.name)) defineOwnEffect(effect, isReduced);
|
|
468
|
+
if (!observer) {
|
|
469
|
+
startDocument();
|
|
470
|
+
const active = new MutationObserver((records, source) => onMutations(records.concat(source.takeRecords())));
|
|
471
|
+
observer = active;
|
|
472
|
+
stopWatching.push(onMotionEffectsChange(() => {
|
|
473
|
+
for (const [root, { watchers }] of roots) {
|
|
474
|
+
observe(root, active);
|
|
475
|
+
syncWatchers(root, watchers);
|
|
476
|
+
}
|
|
477
|
+
}));
|
|
478
|
+
}
|
|
479
|
+
const entry = roots.get(root);
|
|
480
|
+
if (entry) entry.installs++;
|
|
481
|
+
else {
|
|
482
|
+
const watchers = /* @__PURE__ */ new Map();
|
|
483
|
+
observe(root, observer);
|
|
484
|
+
roots.set(root, {
|
|
485
|
+
installs: 1,
|
|
486
|
+
watchers
|
|
487
|
+
});
|
|
488
|
+
syncWatchers(root, watchers);
|
|
489
|
+
}
|
|
490
|
+
let stopped = false;
|
|
491
|
+
return () => {
|
|
492
|
+
if (stopped) return;
|
|
493
|
+
stopped = true;
|
|
494
|
+
const current = roots.get(root);
|
|
495
|
+
if (!current || --current.installs > 0) return;
|
|
496
|
+
roots.delete(root);
|
|
497
|
+
const active = observer;
|
|
498
|
+
const pending = active.takeRecords();
|
|
499
|
+
active.disconnect();
|
|
500
|
+
for (const stop of current.watchers.values()) stop();
|
|
501
|
+
if (roots.size) {
|
|
502
|
+
for (const root of roots.keys()) observe(root, active);
|
|
503
|
+
if (pending.length) queueMicrotask(() => {
|
|
504
|
+
if (observer !== active) return;
|
|
505
|
+
const remaining = [...roots.keys()];
|
|
506
|
+
onMutations(pending.filter((record) => remaining.some((root) => root.contains(record.target))));
|
|
507
|
+
});
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
observer = void 0;
|
|
511
|
+
for (const stop of stopWatching) stop();
|
|
512
|
+
stopWatching = [];
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
//#endregion
|
|
516
|
+
//#region src/motion/effects/ghost.ts
|
|
517
|
+
/**
|
|
518
|
+
* A copy of an element that leaves the page, so its exit can play after the component removed or hid it. Reka and
|
|
519
|
+
* ui-sdk remove a closed tooltip or toast at once when it has no CSS animation, and Nuxt UI removes the mark of a
|
|
520
|
+
* checkbox with the check. The motion layer does not use CSS animations, so the effect plays the exit on this copy.
|
|
521
|
+
*
|
|
522
|
+
* The copy is inert, hidden from assistive technology, and inside `data-motion="none"`, so the layer does not take it
|
|
523
|
+
* for a new tooltip, toast, or checkbox. It has no `id` and no `role`.
|
|
524
|
+
*/
|
|
525
|
+
function createGhost(source, parent, before) {
|
|
526
|
+
const ghost = source.cloneNode(true);
|
|
527
|
+
for (const element of [ghost, ...ghost.querySelectorAll("*")]) for (const name of [
|
|
528
|
+
"id",
|
|
529
|
+
"role",
|
|
530
|
+
"tabindex",
|
|
531
|
+
"hidden",
|
|
532
|
+
"inert",
|
|
533
|
+
"popover",
|
|
534
|
+
"data-ending-style",
|
|
535
|
+
"data-starting-style",
|
|
536
|
+
"aria-live"
|
|
537
|
+
]) element.removeAttribute(name);
|
|
538
|
+
ghost.setAttribute("aria-hidden", "true");
|
|
539
|
+
ghost.setAttribute("data-motion", "none");
|
|
540
|
+
if (ghost instanceof HTMLElement) ghost.inert = true;
|
|
541
|
+
ghost.style.pointerEvents = "none";
|
|
542
|
+
parent.insertBefore(ghost, before?.parentNode === parent ? before : null);
|
|
543
|
+
return ghost;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Puts a ghost at a place on the screen with `position: fixed`, outside the layout of the list it came from. A parent
|
|
547
|
+
* with a transform moves fixed elements, so the ghost measures where it landed and corrects for it.
|
|
548
|
+
*/
|
|
549
|
+
function pinGhost(ghost, rect) {
|
|
550
|
+
Object.assign(ghost.style, {
|
|
551
|
+
position: "fixed",
|
|
552
|
+
inset: "auto",
|
|
553
|
+
left: `${rect.left}px`,
|
|
554
|
+
top: `${rect.top}px`,
|
|
555
|
+
width: `${rect.width}px`,
|
|
556
|
+
height: `${rect.height}px`,
|
|
557
|
+
margin: "0",
|
|
558
|
+
boxSizing: "border-box",
|
|
559
|
+
transform: "none",
|
|
560
|
+
translate: "none",
|
|
561
|
+
zIndex: "2147483647"
|
|
562
|
+
});
|
|
563
|
+
const landed = ghost.getBoundingClientRect();
|
|
564
|
+
if (Math.abs(landed.left - rect.left) > .5) ghost.style.left = `${2 * rect.left - landed.left}px`;
|
|
565
|
+
if (Math.abs(landed.top - rect.top) > .5) ghost.style.top = `${2 * rect.top - landed.top}px`;
|
|
566
|
+
}
|
|
567
|
+
/** Calls `callback` after `ms` of motion time, so ¼× also slows the waits between the steps of an effect. */
|
|
568
|
+
function after(ms, callback) {
|
|
569
|
+
return window.setTimeout(callback, ms * getMotionSlowFactor());
|
|
570
|
+
}
|
|
571
|
+
//#endregion
|
|
572
|
+
//#region src/motion/effects/check.ts
|
|
573
|
+
const checks = /* @__PURE__ */ new WeakMap();
|
|
574
|
+
function isOn$1(value) {
|
|
575
|
+
return value === "true" || value === "mixed";
|
|
576
|
+
}
|
|
577
|
+
function styleable(node) {
|
|
578
|
+
return node instanceof HTMLElement || node instanceof SVGElement ? node : void 0;
|
|
579
|
+
}
|
|
580
|
+
/** The child of `element` that holds `node`. */
|
|
581
|
+
function childOf(element, node) {
|
|
582
|
+
let child = node;
|
|
583
|
+
while (child.parentElement && child.parentElement !== element) child = child.parentElement;
|
|
584
|
+
return child;
|
|
585
|
+
}
|
|
586
|
+
function keepGhost(check) {
|
|
587
|
+
const { indicator } = check;
|
|
588
|
+
if (check.drawn.target || check.ghost || !indicator || indicator.isConnected) return;
|
|
589
|
+
const source = styleable(indicator);
|
|
590
|
+
if (!source) return;
|
|
591
|
+
const ghost = createGhost(source, check.element, null);
|
|
592
|
+
check.ghost = ghost;
|
|
593
|
+
bind(check, findIcons(ghost)[0], ghost);
|
|
594
|
+
}
|
|
595
|
+
function draw$3(check, value) {
|
|
596
|
+
keepGhost(check);
|
|
597
|
+
const drawn = Math.min(1, Math.max(0, value));
|
|
598
|
+
if (check.icon && !check.reduced) {
|
|
599
|
+
const { icon, lengths } = check;
|
|
600
|
+
icon.shapes.forEach((shape, index) => {
|
|
601
|
+
const length = lengths[index];
|
|
602
|
+
icon.set(shape, "stroke-dasharray", `${length} ${length}`);
|
|
603
|
+
icon.set(shape, "stroke-dashoffset", String(length * (1 - drawn)));
|
|
604
|
+
});
|
|
605
|
+
icon.commit();
|
|
606
|
+
}
|
|
607
|
+
if (check.fade) writeMotionStyle(check.fade, { opacity: String(drawn) });
|
|
608
|
+
}
|
|
609
|
+
function finish$1(check) {
|
|
610
|
+
check.icon?.restore();
|
|
611
|
+
check.icon = void 0;
|
|
612
|
+
if (check.fade) writeMotionStyle(check.fade, { opacity: null });
|
|
613
|
+
check.fade = void 0;
|
|
614
|
+
check.ghost?.remove();
|
|
615
|
+
check.ghost = void 0;
|
|
616
|
+
}
|
|
617
|
+
function checkOf(element, wasOn) {
|
|
618
|
+
const existing = checks.get(element);
|
|
619
|
+
if (existing) return existing;
|
|
620
|
+
const check = {
|
|
621
|
+
element,
|
|
622
|
+
drawn: createSpring(wasOn ? 1 : 0, (value) => {
|
|
623
|
+
if (check.drawn.active) draw$3(check, value);
|
|
624
|
+
else finish$1(check);
|
|
625
|
+
}),
|
|
626
|
+
icon: void 0,
|
|
627
|
+
lengths: [],
|
|
628
|
+
fade: void 0,
|
|
629
|
+
indicator: void 0,
|
|
630
|
+
ghost: void 0,
|
|
631
|
+
reduced: false
|
|
632
|
+
};
|
|
633
|
+
checks.set(element, check);
|
|
634
|
+
return check;
|
|
635
|
+
}
|
|
636
|
+
/** Points the spring at the mark of `icon`, and puts back the mark that it drew before. */
|
|
637
|
+
function bind(check, icon, fade) {
|
|
638
|
+
check.icon?.restore();
|
|
639
|
+
if (check.fade && check.fade !== fade) writeMotionStyle(check.fade, { opacity: null });
|
|
640
|
+
check.icon = icon && !check.reduced ? iconShape(icon) : void 0;
|
|
641
|
+
check.lengths = check.icon?.measure((shapes) => shapes.map((shape) => shape.getTotalLength())) ?? [];
|
|
642
|
+
check.fade = fade;
|
|
643
|
+
return !!check.icon || !!fade;
|
|
644
|
+
}
|
|
645
|
+
const check = {
|
|
646
|
+
name: "check",
|
|
647
|
+
selector: "[role=checkbox]",
|
|
648
|
+
state(element, { attribute, oldValue, value }) {
|
|
649
|
+
if (attribute !== "aria-checked") return;
|
|
650
|
+
const check = checkOf(element, isOn$1(oldValue));
|
|
651
|
+
check.ghost?.remove();
|
|
652
|
+
check.ghost = void 0;
|
|
653
|
+
check.reduced = prefersReducedMotion();
|
|
654
|
+
const options = check.reduced ? { tween: .15 } : void 0;
|
|
655
|
+
if (isOn$1(value)) {
|
|
656
|
+
const icon = findIcons(element)[0];
|
|
657
|
+
check.indicator = icon && childOf(element, icon);
|
|
658
|
+
if (isOn$1(oldValue)) check.drawn.set(0);
|
|
659
|
+
if (!bind(check, icon, check.reduced ? styleable(check.indicator) : void 0)) return;
|
|
660
|
+
draw$3(check, check.drawn.value);
|
|
661
|
+
check.drawn.to(1, options);
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
if (oldValue !== "true") {
|
|
665
|
+
check.drawn.set(0);
|
|
666
|
+
check.indicator = void 0;
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
const icon = findIcons(element)[0];
|
|
670
|
+
if (icon) check.indicator = childOf(element, icon);
|
|
671
|
+
if (!bind(check, icon, check.reduced ? styleable(check.indicator) : void 0) && !check.indicator) return;
|
|
672
|
+
check.drawn.to(0, options);
|
|
673
|
+
draw$3(check, check.drawn.value);
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
//#endregion
|
|
677
|
+
//#region src/motion/effects/disclosure.ts
|
|
678
|
+
const iconSelector$1 = "[data-motion-chevron], svg, img, .iconify, [data-slot=icon], [data-slot$=Icon]";
|
|
679
|
+
const quarter = 90;
|
|
680
|
+
const turns = /* @__PURE__ */ new WeakMap();
|
|
681
|
+
const pending$1 = /* @__PURE__ */ new WeakMap();
|
|
682
|
+
/** The element that holds the chevron: the `<summary>` of a `<details>`, or the trigger itself. */
|
|
683
|
+
function triggerOf(element) {
|
|
684
|
+
return element instanceof HTMLDetailsElement ? element.querySelector(":scope > summary") : element;
|
|
685
|
+
}
|
|
686
|
+
function degrees(value) {
|
|
687
|
+
if (!value || value === "none") return 0;
|
|
688
|
+
const axis = value.trim().split(/\s+/);
|
|
689
|
+
const angle = axis.pop();
|
|
690
|
+
if (axis.length === 1 && axis[0] !== "z") return 0;
|
|
691
|
+
if (axis.length === 3 && (Number(axis[0]) !== 0 || Number(axis[1]) !== 0)) return 0;
|
|
692
|
+
const number = Number.parseFloat(angle);
|
|
693
|
+
if (angle.endsWith("turn")) return number * 360;
|
|
694
|
+
if (angle.endsWith("grad")) return number * .9;
|
|
695
|
+
if (angle.endsWith("rad")) return number * 180 / Math.PI;
|
|
696
|
+
return Number.isFinite(number) ? number : 0;
|
|
697
|
+
}
|
|
698
|
+
/** The Z angle of a computed transform matrix. */
|
|
699
|
+
function matrixDegrees(value) {
|
|
700
|
+
const match = /^matrix(?:3d)?\(([^)]+)\)$/.exec(value);
|
|
701
|
+
if (!match) return 0;
|
|
702
|
+
const [a = 1, b = 0] = match[1].split(",").map(Number);
|
|
703
|
+
return Math.atan2(b, a) * 180 / Math.PI;
|
|
704
|
+
}
|
|
705
|
+
/** The angle that the stylesheet draws the icon at now, without what the effect wrote, split into its two sources. */
|
|
706
|
+
function measure$2(icon) {
|
|
707
|
+
const written = icon.style.getPropertyValue("rotate");
|
|
708
|
+
if (written) icon.style.removeProperty("rotate");
|
|
709
|
+
const style = getComputedStyle(icon);
|
|
710
|
+
const base = matrixDegrees(style.transform);
|
|
711
|
+
const total = base + degrees(style.rotate);
|
|
712
|
+
if (written) icon.style.setProperty("rotate", written);
|
|
713
|
+
return {
|
|
714
|
+
total,
|
|
715
|
+
base
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* True when the icon still turns with a CSS transition of its own, as Nuxt UI's accordion chevron does. The transition
|
|
720
|
+
* would smear each frame of the spring, so that icon keeps its own motion.
|
|
721
|
+
*/
|
|
722
|
+
function transitionsTurn(icon) {
|
|
723
|
+
const style = getComputedStyle(icon);
|
|
724
|
+
const durations = style.transitionDuration.split(",");
|
|
725
|
+
return style.transitionProperty.split(",").some((property, index) => /^\s*(?:transform|rotate|all)\s*$/.test(property) && Number.parseFloat(durations[index % durations.length]) > 0);
|
|
726
|
+
}
|
|
727
|
+
function icons(trigger) {
|
|
728
|
+
return [...trigger.querySelectorAll(iconSelector$1)].filter((icon) => !icon.parentElement?.closest(iconSelector$1) || icon.matches("[data-motion-chevron]"));
|
|
729
|
+
}
|
|
730
|
+
function turnOf(icon) {
|
|
731
|
+
const turn = turns.get(icon);
|
|
732
|
+
if (turn) return turn;
|
|
733
|
+
const current = {
|
|
734
|
+
base: 0,
|
|
735
|
+
spring: createSpring(0, (value, velocity) => {
|
|
736
|
+
if (isMotionOff(icon)) {
|
|
737
|
+
current.spring.stop();
|
|
738
|
+
writeMotionStyle(icon, { rotate: null });
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
const settled = velocity === 0 && value === current.spring.target;
|
|
742
|
+
writeMotionStyle(icon, { rotate: settled ? null : `${(value * quarter - current.base).toFixed(2)}deg` });
|
|
743
|
+
}, springs.snappy)
|
|
744
|
+
};
|
|
745
|
+
turns.set(icon, current);
|
|
746
|
+
return current;
|
|
747
|
+
}
|
|
748
|
+
const disclosure = {
|
|
749
|
+
name: "disclosure",
|
|
750
|
+
selector: "details, summary, [aria-expanded]",
|
|
751
|
+
press(element) {
|
|
752
|
+
const owner = element.tagName === "SUMMARY" ? element.parentElement : element.matches("[aria-expanded]") ? element : null;
|
|
753
|
+
if (!owner || !(owner instanceof HTMLDetailsElement || owner.matches("[aria-expanded]"))) return;
|
|
754
|
+
const trigger = triggerOf(owner);
|
|
755
|
+
if (!trigger) return;
|
|
756
|
+
const angles = /* @__PURE__ */ new Map();
|
|
757
|
+
for (const icon of icons(trigger)) {
|
|
758
|
+
if (isMotionOff(icon) || transitionsTurn(icon)) continue;
|
|
759
|
+
const spring = turns.get(icon)?.spring;
|
|
760
|
+
angles.set(icon, spring?.active ? spring.target * quarter : measure$2(icon).total);
|
|
761
|
+
}
|
|
762
|
+
if (!angles.size) return;
|
|
763
|
+
pending$1.set(owner, angles);
|
|
764
|
+
return { release() {
|
|
765
|
+
setTimeout(() => {
|
|
766
|
+
if (pending$1.get(owner) === angles) pending$1.delete(owner);
|
|
767
|
+
});
|
|
768
|
+
} };
|
|
769
|
+
},
|
|
770
|
+
state(element, { attribute }) {
|
|
771
|
+
if (attribute !== (element instanceof HTMLDetailsElement ? "open" : "aria-expanded")) return;
|
|
772
|
+
const angles = pending$1.get(element);
|
|
773
|
+
pending$1.delete(element);
|
|
774
|
+
const trigger = triggerOf(element);
|
|
775
|
+
if (!trigger) return;
|
|
776
|
+
for (const icon of icons(trigger)) {
|
|
777
|
+
const previous = turns.get(icon);
|
|
778
|
+
const sampled = angles?.get(icon);
|
|
779
|
+
if (isMotionOff(icon) || sampled === void 0 || prefersReducedMotion() || transitionsTurn(icon)) {
|
|
780
|
+
if (previous?.spring.active) {
|
|
781
|
+
previous.spring.stop();
|
|
782
|
+
writeMotionStyle(icon, { rotate: null });
|
|
783
|
+
}
|
|
784
|
+
continue;
|
|
785
|
+
}
|
|
786
|
+
const turn = turnOf(icon);
|
|
787
|
+
const from = turn.spring.active ? turn.spring.value * quarter : sampled;
|
|
788
|
+
const { total, base } = measure$2(icon);
|
|
789
|
+
turn.base = base;
|
|
790
|
+
if (Math.abs(total - from) < .5) {
|
|
791
|
+
if (turn.spring.active) turn.spring.set(total / quarter);
|
|
792
|
+
continue;
|
|
793
|
+
}
|
|
794
|
+
if (!turn.spring.active) turn.spring.set(from / quarter);
|
|
795
|
+
turn.spring.to(total / quarter);
|
|
796
|
+
if (turn.spring.active) writeMotionStyle(icon, { rotate: `${(turn.spring.value * quarter - base).toFixed(2)}deg` });
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
//#endregion
|
|
801
|
+
//#region src/motion/effects/jelly.ts
|
|
802
|
+
const waveEnd = 1.5;
|
|
803
|
+
const waveSeconds = .56 * waveEnd;
|
|
804
|
+
const points = 120;
|
|
805
|
+
const waves = /* @__PURE__ */ new WeakMap();
|
|
806
|
+
/** The outline of the path at `wave`, as a closed polyline. The formula is the prototype's, for any path size. */
|
|
807
|
+
function deform({ outline, box }, wave) {
|
|
808
|
+
const amount = wave <= 1 ? .5 * Math.sin(Math.PI * wave) : -.12 * Math.sin(Math.PI * (wave - 1) / .5);
|
|
809
|
+
const crest = -.15 + 1.35 * Math.min(1, Math.max(0, wave));
|
|
810
|
+
const lift = 4 * box.height / 18;
|
|
811
|
+
return `M${outline.map(([x, y]) => {
|
|
812
|
+
const along = (y - box.top) / box.height;
|
|
813
|
+
const bulge = Math.exp(-(((along - crest) / .3) ** 2));
|
|
814
|
+
const swell = amount * bulge * (.12 + 1.1 * Math.max(0, along) ** 1.6);
|
|
815
|
+
const nextX = box.center + (x - box.center) * (1 + swell);
|
|
816
|
+
const nextY = along > .8 ? y - amount * bulge * lift * (along - .8) : y;
|
|
817
|
+
return `${nextX.toFixed(2)} ${nextY.toFixed(2)}`;
|
|
818
|
+
}).join("L")}Z`;
|
|
819
|
+
}
|
|
820
|
+
function singleOutline(shape) {
|
|
821
|
+
const [path, ...rest] = shape.shapes;
|
|
822
|
+
if (rest.length || !(path instanceof SVGPathElement)) return;
|
|
823
|
+
const data = path.getAttribute("d") ?? "";
|
|
824
|
+
return /^[Mm][^MmZz]+[Zz]\s*$/.test(data.trim()) ? path : void 0;
|
|
825
|
+
}
|
|
826
|
+
function start$2(icon) {
|
|
827
|
+
const running = waves.get(icon);
|
|
828
|
+
if (running) {
|
|
829
|
+
running.clock.set(0);
|
|
830
|
+
running.clock.to(1, { tween: waveSeconds });
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
const shape = iconShape(icon);
|
|
834
|
+
const path = shape && singleOutline(shape);
|
|
835
|
+
if (!shape || !path) return;
|
|
836
|
+
const sampled = shape.measure(([geometry]) => {
|
|
837
|
+
const length = geometry.getTotalLength();
|
|
838
|
+
const bounds = geometry.getBBox();
|
|
839
|
+
return {
|
|
840
|
+
outline: Array.from({ length: points }, (_, index) => {
|
|
841
|
+
const point = geometry.getPointAtLength(length * index / points);
|
|
842
|
+
return [point.x, point.y];
|
|
843
|
+
}),
|
|
844
|
+
box: {
|
|
845
|
+
top: bounds.y,
|
|
846
|
+
height: bounds.height,
|
|
847
|
+
center: bounds.x + bounds.width / 2
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
});
|
|
851
|
+
if (!sampled.box.height) return;
|
|
852
|
+
const wave = {
|
|
853
|
+
shape,
|
|
854
|
+
path,
|
|
855
|
+
...sampled,
|
|
856
|
+
clock: createSpring(0, (eased) => {
|
|
857
|
+
const time = 1 - Math.cbrt(1 - Math.min(1, eased));
|
|
858
|
+
if (time >= 1 || !icon.isConnected) {
|
|
859
|
+
waves.delete(icon);
|
|
860
|
+
wave.clock.stop();
|
|
861
|
+
shape.restore();
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
shape.set(path, "d", deform(wave, time * waveEnd));
|
|
865
|
+
shape.commit();
|
|
866
|
+
})
|
|
867
|
+
};
|
|
868
|
+
waves.set(icon, wave);
|
|
869
|
+
wave.clock.to(1, { tween: waveSeconds });
|
|
870
|
+
}
|
|
871
|
+
let batch;
|
|
872
|
+
function flush$1() {
|
|
873
|
+
const changes = batch;
|
|
874
|
+
batch = void 0;
|
|
875
|
+
for (const elements of changes.values()) {
|
|
876
|
+
if (new Set(elements.map((element) => element.getAttribute("aria-pressed") === "true")).size > 1) continue;
|
|
877
|
+
for (const element of elements) {
|
|
878
|
+
const icons = findIcons(element);
|
|
879
|
+
if (icons.length === 1) start$2(icons[0]);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
const jelly = {
|
|
884
|
+
name: "jelly",
|
|
885
|
+
selector: "[aria-pressed]",
|
|
886
|
+
state(element, { attribute }) {
|
|
887
|
+
if (attribute !== "aria-pressed" || prefersReducedMotion()) return;
|
|
888
|
+
if (!batch) {
|
|
889
|
+
batch = /* @__PURE__ */ new Map();
|
|
890
|
+
queueMicrotask(flush$1);
|
|
891
|
+
}
|
|
892
|
+
const siblings = batch.get(element.parentElement) ?? [];
|
|
893
|
+
siblings.push(element);
|
|
894
|
+
batch.set(element.parentElement, siblings);
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
//#endregion
|
|
898
|
+
//#region src/motion/effects/label.ts
|
|
899
|
+
const controls = ":is(button, a, [role=button])";
|
|
900
|
+
/**
|
|
901
|
+
* Rule 4 for every button: when the text-only label of a Nuxt UI button, or of a control with a `[data-slot=label]` child,
|
|
902
|
+
* changes, its letters morph and the button's width follows. The app only changes the label, such as
|
|
903
|
+
* `:label="loading ? 'Publishing' : 'Publish'"`.
|
|
904
|
+
*/
|
|
905
|
+
const label = {
|
|
906
|
+
name: "label",
|
|
907
|
+
selector: `${controls} > [data-slot=label]`,
|
|
908
|
+
content(element, { added, removed, oldText }) {
|
|
909
|
+
if (!(element instanceof HTMLElement)) return;
|
|
910
|
+
if ([...element.childNodes].some((node) => node.nodeType !== Node.TEXT_NODE && !isOwnNode(node))) {
|
|
911
|
+
discardMorph(element);
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
if (added.length ? added.every(isOwnNode) : removed.length > 0) return;
|
|
915
|
+
const before = morphTarget(element) ?? oldText;
|
|
916
|
+
if (before === void 0) return;
|
|
917
|
+
morph(element, element.textContent ?? "", before);
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
/**
|
|
921
|
+
* Rule 5 for every button: when Vue draws another icon into the leading or trailing SVG of a button, such as the
|
|
922
|
+
* spinner of `loading`, a copy of the old icon blurs out where it was and the new one comes in. A spinner draws its
|
|
923
|
+
* stroke. An icon of `@nuxt/icon` in CSS mode changes a class, which the layer does not watch, so it changes at once.
|
|
924
|
+
*/
|
|
925
|
+
const buttonIcon = {
|
|
926
|
+
name: "button-icon",
|
|
927
|
+
selector: `${controls}, ${controls} > svg:is([data-slot=leadingIcon], [data-slot=trailingIcon])`,
|
|
928
|
+
content(svg, { added, removed }) {
|
|
929
|
+
if (svg instanceof HTMLElement) {
|
|
930
|
+
for (const slot of ["leadingIcon", "trailingIcon"]) {
|
|
931
|
+
const isIcon = (node) => node instanceof SVGSVGElement && node.getAttribute("data-slot") === slot && !isOwnNode(node);
|
|
932
|
+
const next = added.find((node) => isIcon(node) && node.parentNode === svg);
|
|
933
|
+
const previous = removed.find(isIcon);
|
|
934
|
+
if (previous) {
|
|
935
|
+
const ghost = own(previous.cloneNode(true));
|
|
936
|
+
ghost.classList.remove("animate-spin");
|
|
937
|
+
ghost.removeAttribute("data-slot");
|
|
938
|
+
if (next) next.after(ghost);
|
|
939
|
+
else if (slot === "leadingIcon") svg.prepend(ghost);
|
|
940
|
+
else svg.append(ghost);
|
|
941
|
+
leaveIcon(svg, ghost, offsetIn(svg, next ?? ghost), "blur", (old) => old.remove());
|
|
942
|
+
}
|
|
943
|
+
if (next) enterIcon(next, void 0, 0);
|
|
944
|
+
}
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
const container = svg.parentElement;
|
|
948
|
+
if (!(svg instanceof SVGSVGElement) || !container || !removed.length || added.every(isOwnNode)) return;
|
|
949
|
+
if (!removed.some((node) => node instanceof SVGElement)) return;
|
|
950
|
+
const at = offsetIn(container, svg);
|
|
951
|
+
const ghost = own(svg.cloneNode(false));
|
|
952
|
+
ghost.classList.remove("animate-spin");
|
|
953
|
+
ghost.removeAttribute("data-slot");
|
|
954
|
+
ghost.append(...removed);
|
|
955
|
+
svg.after(ghost);
|
|
956
|
+
leaveIcon(container, ghost, at, "blur", (old) => old.remove());
|
|
957
|
+
enterIcon(svg, void 0, 0);
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
//#endregion
|
|
961
|
+
//#region src/motion/effects/leave.ts
|
|
962
|
+
const fold = {
|
|
963
|
+
stiffness: 260,
|
|
964
|
+
damping: 28
|
|
965
|
+
};
|
|
966
|
+
const slotScale = .9;
|
|
967
|
+
const crossfade$2 = .15;
|
|
968
|
+
const leaving = /* @__PURE__ */ new WeakMap();
|
|
969
|
+
function stop(element) {
|
|
970
|
+
const entry = leaving.get(element);
|
|
971
|
+
if (!entry) return;
|
|
972
|
+
leaving.delete(element);
|
|
973
|
+
entry.spring.stop();
|
|
974
|
+
entry.ghost.remove();
|
|
975
|
+
element.removeAttribute("data-motion-leave-managed");
|
|
976
|
+
writeMotionStyle(element, { opacity: null });
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* A mark that leaves while its page keeps it a moment longer, such as a comment pin when one comment shows on its own:
|
|
980
|
+
* the page sets `data-leaving="true"` on it and removes it later. A copy of it folds away in its place, as a removed item
|
|
981
|
+
* of a list does, and the mark itself hides at once, so the time the page keeps it does not matter. When the page shows
|
|
982
|
+
* it again, the copy goes. Under reduced motion the copy fades out in 150ms.
|
|
983
|
+
*/
|
|
984
|
+
const leave$2 = {
|
|
985
|
+
name: "leave",
|
|
986
|
+
selector: "*",
|
|
987
|
+
state(element, { attribute, value }) {
|
|
988
|
+
if (attribute !== "data-leaving") return;
|
|
989
|
+
stop(element);
|
|
990
|
+
if (value !== "true" || !element.parentNode) return;
|
|
991
|
+
element.setAttribute("data-motion-leave-managed", "");
|
|
992
|
+
const rect = element.getBoundingClientRect();
|
|
993
|
+
const ghost = createGhost(element, element.parentNode, element.nextSibling);
|
|
994
|
+
const position = getComputedStyle(element).position;
|
|
995
|
+
if (position !== "absolute" && position !== "fixed") pinGhost(ghost, rect);
|
|
996
|
+
writeMotionStyle(element, { opacity: "0" });
|
|
997
|
+
const reduced = prefersReducedMotion();
|
|
998
|
+
const spring = createSpring(1, (progress) => {
|
|
999
|
+
writeMotionStyle(ghost, {
|
|
1000
|
+
scale: reduced ? null : (slotScale + .09999999999999998 * progress).toFixed(4),
|
|
1001
|
+
opacity: Math.max(0, progress).toFixed(3)
|
|
1002
|
+
});
|
|
1003
|
+
if (progress < .02) {
|
|
1004
|
+
spring.stop();
|
|
1005
|
+
ghost.remove();
|
|
1006
|
+
}
|
|
1007
|
+
}, fold);
|
|
1008
|
+
leaving.set(element, {
|
|
1009
|
+
ghost,
|
|
1010
|
+
spring
|
|
1011
|
+
});
|
|
1012
|
+
spring.to(0, reduced ? { tween: crossfade$2 } : { preset: fold });
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
1015
|
+
//#endregion
|
|
1016
|
+
//#region src/motion/effects/panel.ts
|
|
1017
|
+
const resizeSpring = {
|
|
1018
|
+
stiffness: 420,
|
|
1019
|
+
damping: 30
|
|
1020
|
+
};
|
|
1021
|
+
const panelSelector = "[data-motion-panel]";
|
|
1022
|
+
const resizes = /* @__PURE__ */ new WeakMap();
|
|
1023
|
+
const widths = /* @__PURE__ */ new WeakMap();
|
|
1024
|
+
const tracking = /* @__PURE__ */ new WeakMap();
|
|
1025
|
+
const unit = 100;
|
|
1026
|
+
function stopResize(element) {
|
|
1027
|
+
const spring = resizes.get(element)?.spring;
|
|
1028
|
+
if (!spring?.active) return;
|
|
1029
|
+
spring.stop();
|
|
1030
|
+
writeMotionStyle(element, { width: null });
|
|
1031
|
+
}
|
|
1032
|
+
function watchPanels(root) {
|
|
1033
|
+
const panels = /* @__PURE__ */ new Set();
|
|
1034
|
+
const resize = new ResizeObserver((entries) => {
|
|
1035
|
+
for (const { target } of entries) if (target instanceof HTMLElement && panels.has(target) && !resizes.get(target)?.spring.active) widths.set(target, target.getBoundingClientRect().width);
|
|
1036
|
+
});
|
|
1037
|
+
function track(element) {
|
|
1038
|
+
if (panels.has(element) || !root.contains(element) || !element.matches(panelSelector)) return;
|
|
1039
|
+
panels.add(element);
|
|
1040
|
+
const count = tracking.get(element) ?? 0;
|
|
1041
|
+
if (count === 0) widths.set(element, element.getBoundingClientRect().width);
|
|
1042
|
+
tracking.set(element, count + 1);
|
|
1043
|
+
resize.observe(element, { box: "border-box" });
|
|
1044
|
+
}
|
|
1045
|
+
function untrack(element) {
|
|
1046
|
+
panels.delete(element);
|
|
1047
|
+
resize.unobserve(element);
|
|
1048
|
+
const count = tracking.get(element) ?? 1;
|
|
1049
|
+
if (count > 1) {
|
|
1050
|
+
tracking.set(element, count - 1);
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
tracking.delete(element);
|
|
1054
|
+
stopResize(element);
|
|
1055
|
+
widths.delete(element);
|
|
1056
|
+
}
|
|
1057
|
+
const observer = new MutationObserver((records) => {
|
|
1058
|
+
for (const element of panels) if (!root.contains(element) || !element.matches(panelSelector)) untrack(element);
|
|
1059
|
+
for (const record of records) {
|
|
1060
|
+
if (record.type === "attributes" && record.target instanceof HTMLElement) track(record.target);
|
|
1061
|
+
for (const node of record.addedNodes) {
|
|
1062
|
+
if (!(node instanceof HTMLElement)) continue;
|
|
1063
|
+
track(node);
|
|
1064
|
+
for (const element of node.querySelectorAll(panelSelector)) track(element);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
if (root instanceof HTMLElement) track(root);
|
|
1069
|
+
for (const element of root.querySelectorAll(panelSelector)) track(element);
|
|
1070
|
+
observer.observe(root, {
|
|
1071
|
+
subtree: true,
|
|
1072
|
+
childList: true,
|
|
1073
|
+
attributeFilter: ["data-motion-panel"]
|
|
1074
|
+
});
|
|
1075
|
+
return () => {
|
|
1076
|
+
observer.disconnect();
|
|
1077
|
+
for (const element of panels) untrack(element);
|
|
1078
|
+
resize.disconnect();
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
function frameOf$1(element) {
|
|
1082
|
+
const style = getComputedStyle(element);
|
|
1083
|
+
if (style.boxSizing === "border-box") return 0;
|
|
1084
|
+
return [
|
|
1085
|
+
style.paddingLeft,
|
|
1086
|
+
style.paddingRight,
|
|
1087
|
+
style.borderLeftWidth,
|
|
1088
|
+
style.borderRightWidth
|
|
1089
|
+
].reduce((sum, value) => sum + Number.parseFloat(value), 0);
|
|
1090
|
+
}
|
|
1091
|
+
function write$1(element, resize) {
|
|
1092
|
+
writeMotionStyle(element, { width: `${resize.spring.value * unit - resize.frame}px` });
|
|
1093
|
+
}
|
|
1094
|
+
const panel = {
|
|
1095
|
+
name: "panel",
|
|
1096
|
+
selector: panelSelector,
|
|
1097
|
+
watch: watchPanels,
|
|
1098
|
+
state(element) {
|
|
1099
|
+
let resize = resizes.get(element);
|
|
1100
|
+
const from = resize?.spring.active ? resize.spring.value * unit : widths.get(element);
|
|
1101
|
+
if (resize?.spring.active) writeMotionStyle(element, { width: null });
|
|
1102
|
+
const to = element.getBoundingClientRect().width;
|
|
1103
|
+
widths.set(element, to);
|
|
1104
|
+
if (from === void 0 || prefersReducedMotion() || Math.abs(to - from) < .5) {
|
|
1105
|
+
stopResize(element);
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
if (!resize) {
|
|
1109
|
+
const current = {
|
|
1110
|
+
frame: 0,
|
|
1111
|
+
spring: createSpring(from / unit, (width, velocity) => {
|
|
1112
|
+
if (velocity === 0 && width === current.spring.target) writeMotionStyle(element, { width: null });
|
|
1113
|
+
else write$1(element, current);
|
|
1114
|
+
}, resizeSpring)
|
|
1115
|
+
};
|
|
1116
|
+
resize = current;
|
|
1117
|
+
resizes.set(element, resize);
|
|
1118
|
+
}
|
|
1119
|
+
resize.frame = frameOf$1(element);
|
|
1120
|
+
if (!resize.spring.active) resize.spring.set(from / unit);
|
|
1121
|
+
resize.spring.to(to / unit);
|
|
1122
|
+
if (resize.spring.active) write$1(element, resize);
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
1125
|
+
//#endregion
|
|
1126
|
+
//#region src/motion/effects/press.ts
|
|
1127
|
+
const down = {
|
|
1128
|
+
stiffness: 900,
|
|
1129
|
+
damping: 40
|
|
1130
|
+
};
|
|
1131
|
+
const up = {
|
|
1132
|
+
stiffness: 380,
|
|
1133
|
+
damping: 14
|
|
1134
|
+
};
|
|
1135
|
+
/**
|
|
1136
|
+
* Everything a person presses: native controls and the roles of docs/design/motion.md, when they are enabled. A switch
|
|
1137
|
+
* is not squashed: the switch effect grows its knob instead.
|
|
1138
|
+
*/
|
|
1139
|
+
const pressSelector = `:is(button, a[href], summary, input:is([type=button], [type=submit], [type=reset], [type=checkbox], [type=radio]), ${[
|
|
1140
|
+
"button",
|
|
1141
|
+
"link",
|
|
1142
|
+
"tab",
|
|
1143
|
+
"radio",
|
|
1144
|
+
"menuitem",
|
|
1145
|
+
"menuitemradio",
|
|
1146
|
+
"menuitemcheckbox",
|
|
1147
|
+
"option",
|
|
1148
|
+
"checkbox"
|
|
1149
|
+
].map((role) => `[role=${role}]`).join(", ")}):not(:disabled, [aria-disabled="true"], [role=switch])`;
|
|
1150
|
+
const iconSelector = "svg, img, .iconify, [data-slot=icon], [data-slot$=Icon], [data-slot=swap-icon]";
|
|
1151
|
+
const pressed = /* @__PURE__ */ new WeakMap();
|
|
1152
|
+
/** How much a control of this height squashes: 3% from 40px high, 4% from 32px, and 5% below. */
|
|
1153
|
+
const amountFor = (height) => height >= 40 ? .03 : height >= 32 ? .04 : .05;
|
|
1154
|
+
/**
|
|
1155
|
+
* How much a press squashes, from the prototype: an icon-only control squashes its icon by 15%, and a control squashes
|
|
1156
|
+
* by its height. A control that another element draws, such as the mark of the folded page pill, names that element
|
|
1157
|
+
* with `data-motion-press-target`, a selector that `closest()` finds from the control. Then that element squashes.
|
|
1158
|
+
*/
|
|
1159
|
+
function squash(element) {
|
|
1160
|
+
const drawnBy = element.dataset.motionPressTarget ? element.closest(element.dataset.motionPressTarget) : null;
|
|
1161
|
+
if (drawnBy instanceof HTMLElement) return {
|
|
1162
|
+
target: drawnBy,
|
|
1163
|
+
amount: amountFor(drawnBy.offsetHeight)
|
|
1164
|
+
};
|
|
1165
|
+
const icon = element.firstElementChild;
|
|
1166
|
+
if (element.childElementCount === 1 && !element.textContent?.trim() && (icon instanceof HTMLElement || icon instanceof SVGElement) && icon.matches(iconSelector)) return {
|
|
1167
|
+
target: icon,
|
|
1168
|
+
amount: .15
|
|
1169
|
+
};
|
|
1170
|
+
return {
|
|
1171
|
+
target: element,
|
|
1172
|
+
amount: amountFor(element.offsetHeight)
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* True when the element still animates `scale` with a CSS transition of its own, as a hand-written press on the
|
|
1177
|
+
* allowlist of `test/design-rules.test.ts` does. The transition would smear each frame of the spring, so that element
|
|
1178
|
+
* keeps its own press until its wave moves it onto the layer. Tailwind's plain `transition` class also animates `scale`.
|
|
1179
|
+
*/
|
|
1180
|
+
function transitionsScale(style) {
|
|
1181
|
+
const durations = style.transitionDuration.split(",");
|
|
1182
|
+
return style.transitionProperty.split(",").some((property, index) => /^\s*(?:scale|all)\s*$/.test(property) && Number.parseFloat(durations[index % durations.length]) > 0);
|
|
1183
|
+
}
|
|
1184
|
+
function nearEdge(bounds, event, amount) {
|
|
1185
|
+
const { left, right, top, bottom, width, height } = bounds;
|
|
1186
|
+
return Math.min(event.clientX - left, right - event.clientX) <= width * amount || Math.min(event.clientY - top, bottom - event.clientY) <= height * amount;
|
|
1187
|
+
}
|
|
1188
|
+
const press = {
|
|
1189
|
+
name: "press",
|
|
1190
|
+
selector: pressSelector,
|
|
1191
|
+
press(element, event) {
|
|
1192
|
+
const { target, amount } = squash(element);
|
|
1193
|
+
const style = getComputedStyle(target);
|
|
1194
|
+
if (transitionsScale(style) || style.display === "contents") return;
|
|
1195
|
+
if (style.display === "inline" && target === element && !(element instanceof HTMLInputElement)) return;
|
|
1196
|
+
let bounds;
|
|
1197
|
+
if (target === element && "pointerId" in event) {
|
|
1198
|
+
bounds = element.getBoundingClientRect();
|
|
1199
|
+
if (nearEdge(bounds, event, amount)) return;
|
|
1200
|
+
}
|
|
1201
|
+
let state = pressed.get(target);
|
|
1202
|
+
if (!state) {
|
|
1203
|
+
const current = {
|
|
1204
|
+
amount,
|
|
1205
|
+
spring: createSpring(0, (value) => {
|
|
1206
|
+
writeMotionStyle(target, { scale: value ? String(1 - current.amount * value) : null });
|
|
1207
|
+
}, down)
|
|
1208
|
+
};
|
|
1209
|
+
state = current;
|
|
1210
|
+
pressed.set(target, state);
|
|
1211
|
+
}
|
|
1212
|
+
state.amount = amount;
|
|
1213
|
+
const { spring } = state;
|
|
1214
|
+
spring.to(1, { preset: down });
|
|
1215
|
+
let cancelled = false;
|
|
1216
|
+
const cancel = () => {
|
|
1217
|
+
if (cancelled) return;
|
|
1218
|
+
cancelled = true;
|
|
1219
|
+
spring.set(0);
|
|
1220
|
+
};
|
|
1221
|
+
return {
|
|
1222
|
+
move: bounds ? (pointer) => {
|
|
1223
|
+
if (nearEdge(bounds, pointer, amount)) cancel();
|
|
1224
|
+
} : void 0,
|
|
1225
|
+
release: () => {
|
|
1226
|
+
if (!cancelled) spring.to(0, { preset: up });
|
|
1227
|
+
},
|
|
1228
|
+
cancel
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
//#endregion
|
|
1233
|
+
//#region src/motion/effects/select.ts
|
|
1234
|
+
const groups = {
|
|
1235
|
+
tab: "[role=tablist]",
|
|
1236
|
+
radio: "[role=radiogroup]",
|
|
1237
|
+
option: "[role=listbox]",
|
|
1238
|
+
menuitemradio: "[role=group], [role=menu]"
|
|
1239
|
+
};
|
|
1240
|
+
const optIn = "[data-motion-select]";
|
|
1241
|
+
const anyGroup = `[role=tablist], [role=radiogroup], [role=listbox], [role=group], [role=menu], ${optIn}`;
|
|
1242
|
+
const byRole = Object.keys(groups).map((role) => `[role=${role}]`).join(", ");
|
|
1243
|
+
const itemSelector = `${byRole}, ${optIn} *`;
|
|
1244
|
+
const selectionState = [
|
|
1245
|
+
"aria-selected",
|
|
1246
|
+
"aria-checked",
|
|
1247
|
+
"data-state",
|
|
1248
|
+
"data-checked"
|
|
1249
|
+
];
|
|
1250
|
+
const indicatorItem = `${byRole}, [aria-selected], [aria-checked], [data-checked], ${[
|
|
1251
|
+
"active",
|
|
1252
|
+
"inactive",
|
|
1253
|
+
"checked",
|
|
1254
|
+
"unchecked",
|
|
1255
|
+
"on",
|
|
1256
|
+
"off"
|
|
1257
|
+
].map((value) => `[data-state=${value}]`).join(", ")}`;
|
|
1258
|
+
const ownIndicator = "[data-motion-indicator], [data-slot=indicator]";
|
|
1259
|
+
const groupIndicator = `${ownIndicator}, [data-slot$="-indicator"]`;
|
|
1260
|
+
const stretchPerSpeed$1 = .09;
|
|
1261
|
+
const stretchMax$1 = .55;
|
|
1262
|
+
const thinning = .25;
|
|
1263
|
+
const flights = /* @__PURE__ */ new WeakMap();
|
|
1264
|
+
const pending = /* @__PURE__ */ new Map();
|
|
1265
|
+
const observedItems = /* @__PURE__ */ new WeakSet();
|
|
1266
|
+
let frameId = 0;
|
|
1267
|
+
function isSelected(attribute, value) {
|
|
1268
|
+
if (attribute === "aria-selected" || attribute === "aria-checked") return value === "true";
|
|
1269
|
+
if (attribute === "data-state") return value === "active" || value === "checked" || value === "on";
|
|
1270
|
+
if (attribute === "data-checked") return value !== null && value !== "false";
|
|
1271
|
+
return false;
|
|
1272
|
+
}
|
|
1273
|
+
function groupOf(item) {
|
|
1274
|
+
const group = item.parentElement?.closest(anyGroup);
|
|
1275
|
+
if (!group || group.matches("[role=listbox][aria-multiselectable=true]")) return null;
|
|
1276
|
+
const role = item.getAttribute("role");
|
|
1277
|
+
const selector = role ? groups[role] : void 0;
|
|
1278
|
+
return group.matches(optIn) || selector && group.matches(selector) ? group : null;
|
|
1279
|
+
}
|
|
1280
|
+
function selected(item) {
|
|
1281
|
+
return selectionState.some((attribute) => isSelected(attribute, item.getAttribute(attribute)));
|
|
1282
|
+
}
|
|
1283
|
+
function indicatorOwner(group, indicator) {
|
|
1284
|
+
for (let node = indicator; node && node !== group; node = node.parentElement) if (observedItems.has(node) || node.matches(indicatorItem)) return node;
|
|
1285
|
+
}
|
|
1286
|
+
function frameOf(group) {
|
|
1287
|
+
const rect = group.getBoundingClientRect();
|
|
1288
|
+
return {
|
|
1289
|
+
left: rect.left,
|
|
1290
|
+
top: rect.top,
|
|
1291
|
+
k: group.offsetWidth ? rect.width / group.offsetWidth : 1
|
|
1292
|
+
};
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* The layout box of an element relative to the group, in CSS pixels. The size comes from layout and the center from the
|
|
1296
|
+
* screen, so a press that scales an item around its center does not change it.
|
|
1297
|
+
*/
|
|
1298
|
+
function boxOf(element, frame) {
|
|
1299
|
+
const rect = element.getBoundingClientRect();
|
|
1300
|
+
const width = element.offsetWidth || rect.width / frame.k;
|
|
1301
|
+
const height = element.offsetHeight || rect.height / frame.k;
|
|
1302
|
+
return {
|
|
1303
|
+
x: (rect.left + rect.width / 2 - frame.left) / frame.k - width / 2,
|
|
1304
|
+
y: (rect.top + rect.height / 2 - frame.top) / frame.k - height / 2,
|
|
1305
|
+
width,
|
|
1306
|
+
height
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
/** The indicator of `item`: its own one, or the one of the group that is in no item. */
|
|
1310
|
+
function indicatorOf(group, item) {
|
|
1311
|
+
for (const candidate of item.querySelectorAll(ownIndicator)) if (candidate.closest(anyGroup) === group && indicatorOwner(group, candidate) === item) return candidate;
|
|
1312
|
+
for (const candidate of group.querySelectorAll(groupIndicator)) if (candidate.closest(anyGroup) === group && !indicatorOwner(group, candidate)) return candidate;
|
|
1313
|
+
}
|
|
1314
|
+
function innerBounds(group) {
|
|
1315
|
+
const style = getComputedStyle(group);
|
|
1316
|
+
const left = group.clientLeft + Number.parseFloat(style.paddingLeft);
|
|
1317
|
+
const top = group.clientTop + Number.parseFloat(style.paddingTop);
|
|
1318
|
+
const right = group.clientLeft + group.clientWidth - Number.parseFloat(style.paddingRight);
|
|
1319
|
+
const bottom = group.clientTop + group.clientHeight - Number.parseFloat(style.paddingBottom);
|
|
1320
|
+
return [[left, right], [top, bottom]];
|
|
1321
|
+
}
|
|
1322
|
+
function pixels(value, size) {
|
|
1323
|
+
return value.endsWith("%") ? Number.parseFloat(value) / 100 * size : Number.parseFloat(value) || 0;
|
|
1324
|
+
}
|
|
1325
|
+
function measureRest$1(flight) {
|
|
1326
|
+
writeMotionStyle(flight.element, {
|
|
1327
|
+
translate: null,
|
|
1328
|
+
scale: null
|
|
1329
|
+
});
|
|
1330
|
+
const style = getComputedStyle(flight.element);
|
|
1331
|
+
flight.rest = boxOf(flight.element, frameOf(flight.group));
|
|
1332
|
+
const [tx = "0", ty = "0"] = style.translate === "none" ? [] : style.translate.split(" ");
|
|
1333
|
+
const [ox = "50%", oy = "50%"] = style.transformOrigin.split(" ");
|
|
1334
|
+
flight.translate = [pixels(tx, flight.rest.width), pixels(ty, flight.rest.height)];
|
|
1335
|
+
flight.origin = [pixels(ox, flight.rest.width), pixels(oy, flight.rest.height)];
|
|
1336
|
+
}
|
|
1337
|
+
/** The box of the indicator at rest in `to`, moved and resized to sit the same way in `from`. */
|
|
1338
|
+
function mapBox(rest, to, from) {
|
|
1339
|
+
const sx = to.width ? from.width / to.width : 1;
|
|
1340
|
+
const sy = to.height ? from.height / to.height : 1;
|
|
1341
|
+
return {
|
|
1342
|
+
x: from.x + (rest.x - to.x) * sx,
|
|
1343
|
+
y: from.y + (rest.y - to.y) * sy,
|
|
1344
|
+
width: rest.width * sx,
|
|
1345
|
+
height: rest.height * sy
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
function moving(flight) {
|
|
1349
|
+
return !!flight && (flight.x.active || flight.y.active || flight.width.active || flight.height.active);
|
|
1350
|
+
}
|
|
1351
|
+
function queue(flight) {
|
|
1352
|
+
if (flight.queued) return;
|
|
1353
|
+
flight.queued = true;
|
|
1354
|
+
queueMicrotask(() => {
|
|
1355
|
+
flight.queued = false;
|
|
1356
|
+
render(flight);
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* One axis of the box in flight: its start and size, longer by `along` of its size toward where it moves, thinner by a
|
|
1361
|
+
* quarter of `across`, and kept inside `bounds` or the place at rest.
|
|
1362
|
+
*/
|
|
1363
|
+
function stretch(start, size, velocity, along, across, bounds, restStart, restSize) {
|
|
1364
|
+
const extra = along * size;
|
|
1365
|
+
const low = Math.min(bounds[0], restStart, start);
|
|
1366
|
+
const high = Math.max(bounds[1], restStart + restSize, start + size);
|
|
1367
|
+
let from = velocity < 0 ? Math.max(low, start - extra) : start;
|
|
1368
|
+
let to = velocity < 0 ? start + size : Math.min(high, start + size + extra);
|
|
1369
|
+
const thin = (to - from) * across * thinning / 2;
|
|
1370
|
+
from += thin;
|
|
1371
|
+
to -= thin;
|
|
1372
|
+
return [from, to - from];
|
|
1373
|
+
}
|
|
1374
|
+
function render(flight) {
|
|
1375
|
+
if (!flight.ready) return;
|
|
1376
|
+
const { element, rest, translate, origin, x, y, width, height, span } = flight;
|
|
1377
|
+
if (!moving(flight)) {
|
|
1378
|
+
writeMotionStyle(element, {
|
|
1379
|
+
translate: null,
|
|
1380
|
+
scale: null
|
|
1381
|
+
});
|
|
1382
|
+
land(flight);
|
|
1383
|
+
return;
|
|
1384
|
+
}
|
|
1385
|
+
const fx = Math.min(stretchMax$1, Math.abs(x.velocity) / span[0] * stretchPerSpeed$1);
|
|
1386
|
+
const fy = Math.min(stretchMax$1, Math.abs(y.velocity) / span[1] * stretchPerSpeed$1);
|
|
1387
|
+
const [left, boxWidth] = stretch(x.value, width.value, x.velocity, fx, fy, flight.bounds[0], rest.x, rest.width);
|
|
1388
|
+
const [top, boxHeight] = stretch(y.value, height.value, y.velocity, fy, fx, flight.bounds[1], rest.y, rest.height);
|
|
1389
|
+
const scaleX = rest.width ? boxWidth / rest.width : 1;
|
|
1390
|
+
const scaleY = rest.height ? boxHeight / rest.height : 1;
|
|
1391
|
+
const tx = left - (rest.x - translate[0]) - origin[0] * (1 - scaleX);
|
|
1392
|
+
const ty = top - (rest.y - translate[1]) - origin[1] * (1 - scaleY);
|
|
1393
|
+
writeMotionStyle(element, {
|
|
1394
|
+
translate: `${tx}px ${ty}px`,
|
|
1395
|
+
scale: `${scaleX} ${scaleY}`
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
function fly(group, element, from, to, copyOf) {
|
|
1399
|
+
const previous = flights.get(group);
|
|
1400
|
+
const wasMoving = moving(previous);
|
|
1401
|
+
if (previous && previous.element !== element) {
|
|
1402
|
+
writeMotionStyle(previous.element, {
|
|
1403
|
+
translate: null,
|
|
1404
|
+
scale: null
|
|
1405
|
+
});
|
|
1406
|
+
land(previous);
|
|
1407
|
+
}
|
|
1408
|
+
const flight = previous ?? {
|
|
1409
|
+
element,
|
|
1410
|
+
group,
|
|
1411
|
+
ready: false,
|
|
1412
|
+
rest: {
|
|
1413
|
+
x: 0,
|
|
1414
|
+
y: 0,
|
|
1415
|
+
width: 0,
|
|
1416
|
+
height: 0
|
|
1417
|
+
},
|
|
1418
|
+
translate: [0, 0],
|
|
1419
|
+
origin: [0, 0],
|
|
1420
|
+
span: [1, 1],
|
|
1421
|
+
bounds: [[0, 0], [0, 0]],
|
|
1422
|
+
queued: false,
|
|
1423
|
+
x: createSpring(0, () => queue(flight), springs.snappy),
|
|
1424
|
+
y: createSpring(0, () => queue(flight), springs.snappy),
|
|
1425
|
+
width: createSpring(0, () => queue(flight), springs.snappy),
|
|
1426
|
+
height: createSpring(0, () => queue(flight), springs.snappy)
|
|
1427
|
+
};
|
|
1428
|
+
flights.set(group, flight);
|
|
1429
|
+
flight.ready = false;
|
|
1430
|
+
flight.element = element;
|
|
1431
|
+
flight.copyOf = copyOf;
|
|
1432
|
+
measureRest$1(flight);
|
|
1433
|
+
flight.bounds = innerBounds(group);
|
|
1434
|
+
const { rest } = flight;
|
|
1435
|
+
if (!rest.width || !rest.height || !wasMoving && !from) {
|
|
1436
|
+
flight.ready = true;
|
|
1437
|
+
return land(flight);
|
|
1438
|
+
}
|
|
1439
|
+
if (!wasMoving && from) {
|
|
1440
|
+
const frame = frameOf(group);
|
|
1441
|
+
const start = mapBox(rest, boxOf(to, frame), boxOf(from, frame));
|
|
1442
|
+
flight.x.set(start.x);
|
|
1443
|
+
flight.y.set(start.y);
|
|
1444
|
+
flight.width.set(start.width);
|
|
1445
|
+
flight.height.set(start.height);
|
|
1446
|
+
}
|
|
1447
|
+
flight.span = [Math.max(Math.abs(rest.x - flight.x.value), rest.width, 1), Math.max(Math.abs(rest.y - flight.y.value), rest.height, 1)];
|
|
1448
|
+
flight.x.to(rest.x);
|
|
1449
|
+
flight.y.to(rest.y);
|
|
1450
|
+
flight.width.to(rest.width);
|
|
1451
|
+
flight.height.to(rest.height);
|
|
1452
|
+
flight.ready = true;
|
|
1453
|
+
render(flight);
|
|
1454
|
+
}
|
|
1455
|
+
const sides = [
|
|
1456
|
+
"top",
|
|
1457
|
+
"right",
|
|
1458
|
+
"bottom",
|
|
1459
|
+
"left"
|
|
1460
|
+
];
|
|
1461
|
+
const borderParts = [
|
|
1462
|
+
"width",
|
|
1463
|
+
"style",
|
|
1464
|
+
"color"
|
|
1465
|
+
];
|
|
1466
|
+
const lookProperties = [
|
|
1467
|
+
"background-color",
|
|
1468
|
+
"box-shadow",
|
|
1469
|
+
...sides.flatMap((side) => borderParts.map((part) => `border-${side}-${part}`))
|
|
1470
|
+
];
|
|
1471
|
+
function finishLook(element) {
|
|
1472
|
+
getComputedStyle(element).backgroundColor;
|
|
1473
|
+
for (const animation of element.getAnimations()) if (animation instanceof CSSTransition && lookProperties.includes(animation.transitionProperty)) animation.finish();
|
|
1474
|
+
}
|
|
1475
|
+
const hiddenLook = [
|
|
1476
|
+
"[data-motion-select-moving] { isolation: isolate; }",
|
|
1477
|
+
"[data-motion-select-hidden~=\"background\"] { background-color: transparent !important; }",
|
|
1478
|
+
"[data-motion-select-hidden~=\"shadow\"] { box-shadow: none !important; }",
|
|
1479
|
+
...sides.map((side) => `[data-motion-select-hidden~="border-${side}"] { border-${side}-color: transparent !important; }`)
|
|
1480
|
+
].join("\n");
|
|
1481
|
+
let sheet;
|
|
1482
|
+
function adoptSheet(node) {
|
|
1483
|
+
const root = node.getRootNode();
|
|
1484
|
+
if (!(root instanceof Document || root instanceof ShadowRoot)) return;
|
|
1485
|
+
if (!sheet) {
|
|
1486
|
+
sheet = new CSSStyleSheet();
|
|
1487
|
+
sheet.replaceSync(hiddenLook);
|
|
1488
|
+
}
|
|
1489
|
+
if (!root.adoptedStyleSheets.includes(sheet)) root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];
|
|
1490
|
+
}
|
|
1491
|
+
const clear = /^transparent$|^rgba\((?:[^,]+,){3}\s*0(?:\.0+)?\)$|\/\s*0(?:\.0+)?%?\s*\)$/;
|
|
1492
|
+
/** A copy of the look that `to` has and `from` does not, behind the items, or nothing when they look the same. */
|
|
1493
|
+
function copyLook(group, from, to) {
|
|
1494
|
+
finishLook(from);
|
|
1495
|
+
finishLook(to);
|
|
1496
|
+
const was = getComputedStyle(from);
|
|
1497
|
+
const now = getComputedStyle(to);
|
|
1498
|
+
const hidden = [];
|
|
1499
|
+
const style = {
|
|
1500
|
+
"position": "absolute",
|
|
1501
|
+
"z-index": "-1",
|
|
1502
|
+
"box-sizing": "border-box",
|
|
1503
|
+
"margin": "0",
|
|
1504
|
+
"pointer-events": "none",
|
|
1505
|
+
"border-radius": now.borderRadius,
|
|
1506
|
+
"background-color": "transparent",
|
|
1507
|
+
"box-shadow": "none"
|
|
1508
|
+
};
|
|
1509
|
+
if (now.backgroundColor !== was.backgroundColor && !clear.test(now.backgroundColor)) {
|
|
1510
|
+
style["background-color"] = now.backgroundColor;
|
|
1511
|
+
hidden.push("background");
|
|
1512
|
+
}
|
|
1513
|
+
if (now.boxShadow !== was.boxShadow && now.boxShadow !== "none") {
|
|
1514
|
+
style["box-shadow"] = now.boxShadow;
|
|
1515
|
+
hidden.push("shadow");
|
|
1516
|
+
}
|
|
1517
|
+
for (const side of sides) {
|
|
1518
|
+
const border = `border-${side}`;
|
|
1519
|
+
const width = now.getPropertyValue(`${border}-width`);
|
|
1520
|
+
const color = now.getPropertyValue(`${border}-color`);
|
|
1521
|
+
style[`${border}-width`] = width;
|
|
1522
|
+
style[`${border}-style`] = now.getPropertyValue(`${border}-style`);
|
|
1523
|
+
style[`${border}-color`] = "transparent";
|
|
1524
|
+
if (Number.parseFloat(width) > 0 && !clear.test(color) && borderParts.some((part) => {
|
|
1525
|
+
const property = `${border}-${part}`;
|
|
1526
|
+
return now.getPropertyValue(property) !== was.getPropertyValue(property);
|
|
1527
|
+
})) {
|
|
1528
|
+
style[`${border}-color`] = color;
|
|
1529
|
+
hidden.push(border);
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
if (!hidden.length) return void 0;
|
|
1533
|
+
const element = document.createElement("span");
|
|
1534
|
+
element.setAttribute("aria-hidden", "true");
|
|
1535
|
+
element.setAttribute("data-motion-copy", "");
|
|
1536
|
+
for (const [property, value] of Object.entries(style)) element.style.setProperty(property, value);
|
|
1537
|
+
adoptSheet(group);
|
|
1538
|
+
group.append(element);
|
|
1539
|
+
const parent = element.offsetParent instanceof HTMLElement ? element.offsetParent : null;
|
|
1540
|
+
const block = parent && !(parent === document.body && getComputedStyle(parent).position === "static") ? parent : null;
|
|
1541
|
+
const box = boxOf(to, frameOf(block ?? document.documentElement));
|
|
1542
|
+
element.style.left = `${box.x - (block ? block.clientLeft - block.scrollLeft : 0)}px`;
|
|
1543
|
+
element.style.top = `${box.y - (block ? block.clientTop - block.scrollTop : 0)}px`;
|
|
1544
|
+
element.style.width = `${box.width}px`;
|
|
1545
|
+
element.style.height = `${box.height}px`;
|
|
1546
|
+
return {
|
|
1547
|
+
element,
|
|
1548
|
+
hidden
|
|
1549
|
+
};
|
|
1550
|
+
}
|
|
1551
|
+
function land(flight) {
|
|
1552
|
+
const item = flight.copyOf;
|
|
1553
|
+
if (!item) return;
|
|
1554
|
+
flight.copyOf = void 0;
|
|
1555
|
+
item.removeAttribute("data-motion-select-hidden");
|
|
1556
|
+
finishLook(item);
|
|
1557
|
+
flight.element.remove();
|
|
1558
|
+
flight.group.removeAttribute("data-motion-select-moving");
|
|
1559
|
+
}
|
|
1560
|
+
function cancelFlight(group) {
|
|
1561
|
+
const flight = flights.get(group);
|
|
1562
|
+
if (!flight) return;
|
|
1563
|
+
flights.delete(group);
|
|
1564
|
+
flight.ready = false;
|
|
1565
|
+
for (const spring of [
|
|
1566
|
+
flight.x,
|
|
1567
|
+
flight.y,
|
|
1568
|
+
flight.width,
|
|
1569
|
+
flight.height
|
|
1570
|
+
]) spring.stop();
|
|
1571
|
+
writeMotionStyle(flight.element, {
|
|
1572
|
+
translate: null,
|
|
1573
|
+
scale: null
|
|
1574
|
+
});
|
|
1575
|
+
land(flight);
|
|
1576
|
+
}
|
|
1577
|
+
function move(group, from, to) {
|
|
1578
|
+
if (prefersReducedMotion() || isMotionOff(to)) return cancelFlight(group);
|
|
1579
|
+
const indicator = indicatorOf(group, to);
|
|
1580
|
+
if (indicator) return isMotionOff(indicator) ? cancelFlight(group) : fly(group, indicator, from, to);
|
|
1581
|
+
const previous = flights.get(group);
|
|
1582
|
+
const source = from ?? (moving(previous) ? previous?.copyOf : void 0);
|
|
1583
|
+
if (!source) return;
|
|
1584
|
+
const look = copyLook(group, source, to);
|
|
1585
|
+
if (!look) return;
|
|
1586
|
+
to.setAttribute("data-motion-select-hidden", look.hidden.join(" "));
|
|
1587
|
+
finishLook(to);
|
|
1588
|
+
fly(group, look.element, from, to, to);
|
|
1589
|
+
if (look.element.isConnected) group.setAttribute("data-motion-select-moving", "");
|
|
1590
|
+
}
|
|
1591
|
+
function flush() {
|
|
1592
|
+
frameId = 0;
|
|
1593
|
+
const batch = [...pending];
|
|
1594
|
+
pending.clear();
|
|
1595
|
+
for (const [group, { from, to }] of batch) if (to?.isConnected && groupOf(to) === group && selected(to)) move(group, from?.isConnected && groupOf(from) === group ? from : void 0, to);
|
|
1596
|
+
else if (!group.isConnected || flights.has(group) && ![...group.querySelectorAll(itemSelector)].some((item) => selected(item) && groupOf(item) === group)) cancelFlight(group);
|
|
1597
|
+
}
|
|
1598
|
+
const select = {
|
|
1599
|
+
name: "select",
|
|
1600
|
+
selector: itemSelector,
|
|
1601
|
+
state(element, { attribute, oldValue, value }) {
|
|
1602
|
+
const was = isSelected(attribute, oldValue);
|
|
1603
|
+
const now = isSelected(attribute, value);
|
|
1604
|
+
if (was === now) return;
|
|
1605
|
+
const group = groupOf(element);
|
|
1606
|
+
if (!group) return;
|
|
1607
|
+
observedItems.add(element);
|
|
1608
|
+
const entry = pending.get(group) ?? {};
|
|
1609
|
+
if (now) entry.to = element;
|
|
1610
|
+
else entry.from = element;
|
|
1611
|
+
pending.set(group, entry);
|
|
1612
|
+
frameId ||= requestAnimationFrame(flush);
|
|
1613
|
+
}
|
|
1614
|
+
};
|
|
1615
|
+
//#endregion
|
|
1616
|
+
//#region src/motion/effects/slider.ts
|
|
1617
|
+
const followSpring = {
|
|
1618
|
+
stiffness: 520,
|
|
1619
|
+
damping: 38
|
|
1620
|
+
};
|
|
1621
|
+
const trail = {
|
|
1622
|
+
stiffness: 260,
|
|
1623
|
+
damping: 30
|
|
1624
|
+
};
|
|
1625
|
+
const heldScale = 1.12;
|
|
1626
|
+
const tailMax = 150;
|
|
1627
|
+
const tailPerSpeed = .13;
|
|
1628
|
+
const turnSpeed = .05;
|
|
1629
|
+
const tailPoints = 28;
|
|
1630
|
+
const stretchPerSpeed = .09;
|
|
1631
|
+
const stretchMax = .55;
|
|
1632
|
+
const svgNamespace = "http://www.w3.org/2000/svg";
|
|
1633
|
+
const valueSelector = "[role=slider], input[type=range]";
|
|
1634
|
+
const nativeThumb = "[data-slot=slider-thumb]";
|
|
1635
|
+
const rangeSelector = "[data-slot=range], [data-slot=slider-indicator]";
|
|
1636
|
+
const trackSelector = "[data-slot=track], [data-slot=slider-track], :has(> [data-slot=range])";
|
|
1637
|
+
const motions = /* @__PURE__ */ new WeakMap();
|
|
1638
|
+
const fills = /* @__PURE__ */ new WeakMap();
|
|
1639
|
+
function thumbOf(element) {
|
|
1640
|
+
if (!(element instanceof HTMLInputElement)) return element;
|
|
1641
|
+
const parent = element.parentElement;
|
|
1642
|
+
return parent?.matches(nativeThumb) ? parent : void 0;
|
|
1643
|
+
}
|
|
1644
|
+
function trackValues(track) {
|
|
1645
|
+
return track.querySelectorAll(`:scope > [role=slider], :scope > ${nativeThumb} > input[type=range]`);
|
|
1646
|
+
}
|
|
1647
|
+
function axisOf(value) {
|
|
1648
|
+
return value.getAttribute("aria-orientation") === "vertical" || value.closest("[data-orientation=vertical]") ? "y" : "x";
|
|
1649
|
+
}
|
|
1650
|
+
function rectOf(element, motion) {
|
|
1651
|
+
const { left, top, width, height } = element.getBoundingClientRect();
|
|
1652
|
+
return {
|
|
1653
|
+
left: left / motion.zoom,
|
|
1654
|
+
top: top / motion.zoom,
|
|
1655
|
+
width: width / motion.zoom,
|
|
1656
|
+
height: height / motion.zoom
|
|
1657
|
+
};
|
|
1658
|
+
}
|
|
1659
|
+
function zoomOf(track) {
|
|
1660
|
+
return track.offsetWidth ? track.getBoundingClientRect().width / track.offsetWidth || 1 : 1;
|
|
1661
|
+
}
|
|
1662
|
+
function along$1(rect, axis) {
|
|
1663
|
+
return axis === "x" ? {
|
|
1664
|
+
start: rect.left,
|
|
1665
|
+
size: rect.width
|
|
1666
|
+
} : {
|
|
1667
|
+
start: rect.top,
|
|
1668
|
+
size: rect.height
|
|
1669
|
+
};
|
|
1670
|
+
}
|
|
1671
|
+
function measure$1(motion) {
|
|
1672
|
+
const { thumb, track, axis } = motion;
|
|
1673
|
+
motion.zoom = zoomOf(track);
|
|
1674
|
+
const shown = along$1(rectOf(thumb, motion), axis);
|
|
1675
|
+
const trackBox = along$1(rectOf(track, motion), axis);
|
|
1676
|
+
motion.length = trackBox.size;
|
|
1677
|
+
return shown.start + shown.size / 2 - trackBox.start - (motions.get(thumb) === motion ? motion.position.value - motion.layout : 0);
|
|
1678
|
+
}
|
|
1679
|
+
function number(value) {
|
|
1680
|
+
return Number.parseFloat(value ?? "");
|
|
1681
|
+
}
|
|
1682
|
+
function directionOf({ thumb, axis }) {
|
|
1683
|
+
const { style } = thumb;
|
|
1684
|
+
const forward = axis === "x" ? style.left : style.top;
|
|
1685
|
+
const backward = axis === "x" ? style.right : style.bottom;
|
|
1686
|
+
if (forward && !backward) return 1;
|
|
1687
|
+
if (backward && !forward) return -1;
|
|
1688
|
+
return axis === "y" || getComputedStyle(thumb).direction === "rtl" ? -1 : 1;
|
|
1689
|
+
}
|
|
1690
|
+
function previousCenter(motion, value, from, to) {
|
|
1691
|
+
const min = number(value.getAttribute("aria-valuemin") ?? value.getAttribute("min"));
|
|
1692
|
+
const max = number(value.getAttribute("aria-valuemax") ?? value.getAttribute("max"));
|
|
1693
|
+
const minimum = Number.isFinite(min) ? min : 0;
|
|
1694
|
+
const maximum = Number.isFinite(max) ? max : 100;
|
|
1695
|
+
if (!(maximum > minimum) || !Number.isFinite(from) || !Number.isFinite(to)) return void 0;
|
|
1696
|
+
const size = along$1(rectOf(motion.thumb, motion), motion.axis).size;
|
|
1697
|
+
const fraction = (to - minimum) / (maximum - minimum);
|
|
1698
|
+
const signAtMidpoint = directionOf(motion);
|
|
1699
|
+
let best;
|
|
1700
|
+
for (const travel of [motion.length - size, motion.length]) for (const sign of [signAtMidpoint, -signAtMidpoint]) {
|
|
1701
|
+
const predicted = motion.length / 2 + sign * (fraction - .5) * travel;
|
|
1702
|
+
const error = Math.abs(predicted - motion.layout);
|
|
1703
|
+
if (!best || error < best.error) best = {
|
|
1704
|
+
error,
|
|
1705
|
+
travel,
|
|
1706
|
+
sign
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
if (!best || best.error > 3) return void 0;
|
|
1710
|
+
return motion.layout - best.sign * ((to - from) / (maximum - minimum)) * best.travel;
|
|
1711
|
+
}
|
|
1712
|
+
function split(translate) {
|
|
1713
|
+
const [x = "0px", y = "0px"] = translate.split(" ").filter(Boolean);
|
|
1714
|
+
return {
|
|
1715
|
+
raw: translate,
|
|
1716
|
+
x,
|
|
1717
|
+
y
|
|
1718
|
+
};
|
|
1719
|
+
}
|
|
1720
|
+
function start$1(thumb, value) {
|
|
1721
|
+
const track = thumb.parentElement;
|
|
1722
|
+
if (!track) return void 0;
|
|
1723
|
+
const axis = axisOf(value);
|
|
1724
|
+
const motion = {
|
|
1725
|
+
thumb,
|
|
1726
|
+
track,
|
|
1727
|
+
range: track.querySelector(":scope > [data-slot=range], :scope > [data-slot=slider-indicator]"),
|
|
1728
|
+
axis,
|
|
1729
|
+
layout: 0,
|
|
1730
|
+
length: 0,
|
|
1731
|
+
zoom: 1,
|
|
1732
|
+
direction: 1,
|
|
1733
|
+
held: false,
|
|
1734
|
+
position: createSpring(0, (_value, velocity) => {
|
|
1735
|
+
if (Math.abs(velocity) > turnSpeed * motion.length) motion.direction = velocity > 0 ? 1 : -1;
|
|
1736
|
+
motion.tail.to(Math.min(tailMax, Math.abs(velocity) * tailPerSpeed));
|
|
1737
|
+
draw$2(motion);
|
|
1738
|
+
}, followSpring),
|
|
1739
|
+
tail: createSpring(0, () => draw$2(motion), trail),
|
|
1740
|
+
ownTranslate: split(thumb.style.translate)
|
|
1741
|
+
};
|
|
1742
|
+
motion.layout = measure$1(motion);
|
|
1743
|
+
motion.position.set(motion.layout);
|
|
1744
|
+
motions.set(thumb, motion);
|
|
1745
|
+
return motion;
|
|
1746
|
+
}
|
|
1747
|
+
function finish(motion) {
|
|
1748
|
+
motions.delete(motion.thumb);
|
|
1749
|
+
motion.position.stop();
|
|
1750
|
+
motion.tail.stop();
|
|
1751
|
+
writeMotionStyle(motion.thumb, {
|
|
1752
|
+
translate: motion.ownTranslate.raw || null,
|
|
1753
|
+
scale: null
|
|
1754
|
+
});
|
|
1755
|
+
drawRange(motion);
|
|
1756
|
+
motion.lane?.ownerSVGElement?.remove();
|
|
1757
|
+
}
|
|
1758
|
+
function drawRange(motion) {
|
|
1759
|
+
const { range, axis, track } = motion;
|
|
1760
|
+
if (!range) return;
|
|
1761
|
+
const endpoints = [...trackValues(track)].flatMap((value) => {
|
|
1762
|
+
const thumb = thumbOf(value);
|
|
1763
|
+
if (!thumb) return [];
|
|
1764
|
+
const current = motions.get(thumb);
|
|
1765
|
+
const box = along$1(rectOf(thumb, motion), axis);
|
|
1766
|
+
return [{
|
|
1767
|
+
center: box.start + box.size / 2,
|
|
1768
|
+
moving: !!current && Math.abs(current.position.value - current.layout) >= .01
|
|
1769
|
+
}];
|
|
1770
|
+
});
|
|
1771
|
+
const minSize = axis === "x" ? "minWidth" : "minHeight";
|
|
1772
|
+
let fill = fills.get(range);
|
|
1773
|
+
if (!endpoints.some((endpoint) => endpoint.moving)) {
|
|
1774
|
+
if (fill) {
|
|
1775
|
+
range.style[minSize] = fill.minSize;
|
|
1776
|
+
writeMotionStyle(range, {
|
|
1777
|
+
translate: fill.translate,
|
|
1778
|
+
scale: fill.scale
|
|
1779
|
+
});
|
|
1780
|
+
fills.delete(range);
|
|
1781
|
+
}
|
|
1782
|
+
return;
|
|
1783
|
+
}
|
|
1784
|
+
if (!fill) {
|
|
1785
|
+
fill = {
|
|
1786
|
+
minSize: range.style[minSize],
|
|
1787
|
+
scale: range.style.scale,
|
|
1788
|
+
translate: range.style.translate,
|
|
1789
|
+
shift: 0
|
|
1790
|
+
};
|
|
1791
|
+
fills.set(range, fill);
|
|
1792
|
+
range.style[minSize] = "1px";
|
|
1793
|
+
}
|
|
1794
|
+
const size = Number.parseFloat(getComputedStyle(range)[axis === "x" ? "width" : "height"]);
|
|
1795
|
+
if (!(size > 0)) return;
|
|
1796
|
+
const box = along$1(rectOf(range, motion), axis);
|
|
1797
|
+
const start = box.start + box.size / 2 - fill.shift - size / 2;
|
|
1798
|
+
const end = start + size;
|
|
1799
|
+
const centers = endpoints.map((endpoint) => endpoint.center);
|
|
1800
|
+
let from = Math.min(...centers);
|
|
1801
|
+
let to = Math.max(...centers);
|
|
1802
|
+
if (endpoints.length === 1) {
|
|
1803
|
+
if (directionOf(motion) > 0) from = start;
|
|
1804
|
+
else to = end;
|
|
1805
|
+
}
|
|
1806
|
+
const scale = Math.max(0, to - from) / size;
|
|
1807
|
+
const move = fill.shift = (from + to) / 2 - (start + end) / 2;
|
|
1808
|
+
writeMotionStyle(range, {
|
|
1809
|
+
translate: axis === "x" ? `${move}px 0px` : `0px ${move}px`,
|
|
1810
|
+
scale: axis === "x" ? `${scale} 1` : `1 ${scale}`
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
function drawTail(motion) {
|
|
1814
|
+
const { thumb, track, axis, direction, length, range } = motion;
|
|
1815
|
+
const tail = Math.min(tailMax, motion.tail.value);
|
|
1816
|
+
if (tail <= 2) {
|
|
1817
|
+
motion.lane?.setAttribute("d", "");
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1820
|
+
if (!motion.lane) {
|
|
1821
|
+
const svg = document.createElementNS(svgNamespace, "svg");
|
|
1822
|
+
svg.setAttribute("aria-hidden", "true");
|
|
1823
|
+
svg.dataset.motion = "tail";
|
|
1824
|
+
svg.style.cssText = "position:absolute;left:0;top:0;width:1px;height:1px;overflow:visible;pointer-events:none;margin:0";
|
|
1825
|
+
const path = document.createElementNS(svgNamespace, "path");
|
|
1826
|
+
path.style.fill = getComputedStyle(range ?? thumb).backgroundColor;
|
|
1827
|
+
svg.append(path);
|
|
1828
|
+
motion.lane = path;
|
|
1829
|
+
}
|
|
1830
|
+
const svg = motion.lane.ownerSVGElement;
|
|
1831
|
+
if (!svg.isConnected) thumb.before(svg);
|
|
1832
|
+
const origin = rectOf(svg, motion);
|
|
1833
|
+
const trackRect = rectOf(track, motion);
|
|
1834
|
+
const thumbRect = rectOf(thumb, motion);
|
|
1835
|
+
const radius = (axis === "x" ? thumbRect.height : thumbRect.width) / 2 / (motion.held ? heldScale : 1);
|
|
1836
|
+
const cross = axis === "x" ? thumbRect.top + thumbRect.height / 2 - origin.top : thumbRect.left + thumbRect.width / 2 - origin.left;
|
|
1837
|
+
const trackStart = axis === "x" ? trackRect.left - origin.left : trackRect.top - origin.top;
|
|
1838
|
+
const at = Math.max(0, Math.min(length, motion.position.value));
|
|
1839
|
+
const reach = Math.min(tail, direction > 0 ? at : length - at);
|
|
1840
|
+
const thinnest = direction > 0 && range ? (axis === "x" ? range.offsetHeight : range.offsetWidth) / 2 : 0;
|
|
1841
|
+
const one = [];
|
|
1842
|
+
const other = [];
|
|
1843
|
+
for (let index = 0; index <= tailPoints; index++) {
|
|
1844
|
+
const progress = index / tailPoints;
|
|
1845
|
+
const point = (trackStart + at - direction * reach * progress).toFixed(1);
|
|
1846
|
+
const half = Math.max(thinnest, radius * .95 * (1 - progress) ** 1.3);
|
|
1847
|
+
const near = (cross - half).toFixed(2);
|
|
1848
|
+
const far = (cross + half).toFixed(2);
|
|
1849
|
+
one.push(axis === "x" ? `${point} ${near}` : `${near} ${point}`);
|
|
1850
|
+
other.push(axis === "x" ? `${point} ${far}` : `${far} ${point}`);
|
|
1851
|
+
}
|
|
1852
|
+
motion.lane.setAttribute("d", `M${one.join("L")}L${other.reverse().join("L")}Z`);
|
|
1853
|
+
}
|
|
1854
|
+
function draw$2(motion) {
|
|
1855
|
+
if (motions.get(motion.thumb) !== motion) return;
|
|
1856
|
+
if (!motion.held && !motion.position.active && !motion.tail.active) {
|
|
1857
|
+
finish(motion);
|
|
1858
|
+
return;
|
|
1859
|
+
}
|
|
1860
|
+
const { thumb, axis } = motion;
|
|
1861
|
+
const shift = motion.position.value - motion.layout;
|
|
1862
|
+
const { x, y } = motion.ownTranslate;
|
|
1863
|
+
const translate = axis === "x" ? `calc(${x} + ${shift.toFixed(2)}px) ${y}` : `${x} calc(${y} + ${shift.toFixed(2)}px)`;
|
|
1864
|
+
const speed = Math.abs(motion.position.velocity) / Math.max(1, motion.length);
|
|
1865
|
+
const stretch = Math.min(stretchMax, speed * stretchPerSpeed);
|
|
1866
|
+
const base = motion.held ? heldScale : 1;
|
|
1867
|
+
const travel = (base * (1 + stretch)).toFixed(4);
|
|
1868
|
+
const cross = (base * (1 - stretch * .25)).toFixed(4);
|
|
1869
|
+
writeMotionStyle(thumb, {
|
|
1870
|
+
translate,
|
|
1871
|
+
scale: axis === "x" ? `${travel} ${cross}` : `${cross} ${travel}`
|
|
1872
|
+
});
|
|
1873
|
+
drawRange(motion);
|
|
1874
|
+
drawTail(motion);
|
|
1875
|
+
}
|
|
1876
|
+
function follow(thumb, value, from, to) {
|
|
1877
|
+
if (prefersReducedMotion()) {
|
|
1878
|
+
const existing = motions.get(thumb);
|
|
1879
|
+
if (existing) finish(existing);
|
|
1880
|
+
return;
|
|
1881
|
+
}
|
|
1882
|
+
const existing = motions.get(thumb);
|
|
1883
|
+
const motion = existing ?? start$1(thumb, value);
|
|
1884
|
+
if (!motion) return;
|
|
1885
|
+
const next = measure$1(motion);
|
|
1886
|
+
if (!existing) {
|
|
1887
|
+
const was = from === void 0 || to === void 0 ? void 0 : previousCenter(motion, value, from, to);
|
|
1888
|
+
motion.position.set(was ?? next);
|
|
1889
|
+
}
|
|
1890
|
+
if (Math.abs(next - motion.layout) < .01 && existing) return;
|
|
1891
|
+
motion.layout = next;
|
|
1892
|
+
motion.position.to(next);
|
|
1893
|
+
draw$2(motion);
|
|
1894
|
+
}
|
|
1895
|
+
function disabled$1(value) {
|
|
1896
|
+
return value.matches(":disabled, [aria-disabled=true], [data-disabled]:not([data-disabled=false])");
|
|
1897
|
+
}
|
|
1898
|
+
/**
|
|
1899
|
+
* Drag a value (docs/design/motion.md): a slider thumb from Nuxt UI `USlider`, Reka, ui-sdk and kit, or a plain
|
|
1900
|
+
* `[role=slider]`. Its component puts the thumb at the value. The effect keeps the thumb that people see where it was
|
|
1901
|
+
* and springs it there, so a tail trails it with its speed and it stretches along the track. A press on the thumb or
|
|
1902
|
+
* on its track holds the thumb, and it grows while it is held.
|
|
1903
|
+
*/
|
|
1904
|
+
const slider = {
|
|
1905
|
+
name: "slider",
|
|
1906
|
+
selector: `${valueSelector}, ${trackSelector}, [data-slot=slider-control]`,
|
|
1907
|
+
press(element, event) {
|
|
1908
|
+
if (!(event instanceof PointerEvent)) return;
|
|
1909
|
+
const target = event.composedPath()[0];
|
|
1910
|
+
if (!(target instanceof Element)) return;
|
|
1911
|
+
const track = element.matches("[data-slot=slider-control]") ? element.querySelector("[data-slot=slider-track]") : element;
|
|
1912
|
+
const values = element.matches(valueSelector) ? [element] : track && (target === element || target === track || target.closest(rangeSelector)?.parentElement === track) ? trackValues(track) : [];
|
|
1913
|
+
let held;
|
|
1914
|
+
let nearest = Number.POSITIVE_INFINITY;
|
|
1915
|
+
for (const value of values) {
|
|
1916
|
+
const thumb = thumbOf(value);
|
|
1917
|
+
if (!thumb || disabled$1(value) || isMotionOff(value)) continue;
|
|
1918
|
+
const rect = thumb.getBoundingClientRect();
|
|
1919
|
+
const distance = Math.hypot(rect.left + rect.width / 2 - event.clientX, rect.top + rect.height / 2 - event.clientY);
|
|
1920
|
+
if (distance < nearest) {
|
|
1921
|
+
nearest = distance;
|
|
1922
|
+
held = {
|
|
1923
|
+
thumb,
|
|
1924
|
+
value
|
|
1925
|
+
};
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
if (!held) return;
|
|
1929
|
+
const { thumb, value } = held;
|
|
1930
|
+
const motion = motions.get(thumb) ?? start$1(thumb, value);
|
|
1931
|
+
if (!motion) return;
|
|
1932
|
+
motion.held = true;
|
|
1933
|
+
draw$2(motion);
|
|
1934
|
+
let frame = 0;
|
|
1935
|
+
return {
|
|
1936
|
+
move() {
|
|
1937
|
+
if (!frame) frame = requestAnimationFrame(() => {
|
|
1938
|
+
frame = 0;
|
|
1939
|
+
follow(thumb, value);
|
|
1940
|
+
});
|
|
1941
|
+
},
|
|
1942
|
+
release() {
|
|
1943
|
+
cancelAnimationFrame(frame);
|
|
1944
|
+
const current = motions.get(thumb);
|
|
1945
|
+
if (!current) return;
|
|
1946
|
+
current.held = false;
|
|
1947
|
+
follow(thumb, value);
|
|
1948
|
+
draw$2(current);
|
|
1949
|
+
}
|
|
1950
|
+
};
|
|
1951
|
+
},
|
|
1952
|
+
state(element, { attribute, oldValue, value }) {
|
|
1953
|
+
if (attribute !== "aria-valuenow" && attribute !== "aria-valuetext") return;
|
|
1954
|
+
if (!element.matches(valueSelector)) return;
|
|
1955
|
+
const thumb = thumbOf(element);
|
|
1956
|
+
if (!thumb) return;
|
|
1957
|
+
follow(thumb, element, number(oldValue), number(value));
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
1960
|
+
//#endregion
|
|
1961
|
+
//#region src/motion/effects/switch.ts
|
|
1962
|
+
const travel = {
|
|
1963
|
+
stiffness: 300,
|
|
1964
|
+
damping: 24
|
|
1965
|
+
};
|
|
1966
|
+
const size = {
|
|
1967
|
+
stiffness: 320,
|
|
1968
|
+
damping: 16
|
|
1969
|
+
};
|
|
1970
|
+
const pressSpring = {
|
|
1971
|
+
stiffness: 700,
|
|
1972
|
+
damping: 32
|
|
1973
|
+
};
|
|
1974
|
+
const wobble = {
|
|
1975
|
+
stiffness: 520,
|
|
1976
|
+
damping: 9
|
|
1977
|
+
};
|
|
1978
|
+
const wobbleDelay = 170;
|
|
1979
|
+
const wobbleKick = -5;
|
|
1980
|
+
const knobSelector = "[data-slot=thumb], [data-slot=switch-thumb]";
|
|
1981
|
+
const knobs = /* @__PURE__ */ new WeakMap();
|
|
1982
|
+
function findKnob(element) {
|
|
1983
|
+
const knob = element.querySelector(knobSelector) ?? element.firstElementChild;
|
|
1984
|
+
return knob instanceof HTMLElement ? knob : void 0;
|
|
1985
|
+
}
|
|
1986
|
+
function isOn(value) {
|
|
1987
|
+
return value === "true";
|
|
1988
|
+
}
|
|
1989
|
+
/** Reads where the stylesheet puts the knob in the current state, without what the effect wrote. */
|
|
1990
|
+
function measure(element, knob) {
|
|
1991
|
+
writeMotionStyle(knob, {
|
|
1992
|
+
translate: null,
|
|
1993
|
+
scale: null
|
|
1994
|
+
});
|
|
1995
|
+
const track = element.getBoundingClientRect();
|
|
1996
|
+
const box = knob.getBoundingClientRect();
|
|
1997
|
+
const [x = "0px", y = "0px"] = getComputedStyle(knob).translate.split(" ");
|
|
1998
|
+
const zoom = element.offsetWidth ? track.width / element.offsetWidth : 1;
|
|
1999
|
+
return {
|
|
2000
|
+
rest: {
|
|
2001
|
+
center: (box.left + box.width / 2 - track.left) / zoom,
|
|
2002
|
+
width: box.width / zoom,
|
|
2003
|
+
height: box.height / zoom
|
|
2004
|
+
},
|
|
2005
|
+
translate: x === "none" ? ["0px", "0px"] : [x, y],
|
|
2006
|
+
width: knob.offsetWidth,
|
|
2007
|
+
height: knob.offsetHeight
|
|
2008
|
+
};
|
|
2009
|
+
}
|
|
2010
|
+
function restOf(state, on, trackWidth) {
|
|
2011
|
+
const own = state.rest[on ? 1 : 0];
|
|
2012
|
+
if (own) return own;
|
|
2013
|
+
const other = state.rest[on ? 0 : 1];
|
|
2014
|
+
return {
|
|
2015
|
+
...other,
|
|
2016
|
+
center: trackWidth - other.center
|
|
2017
|
+
};
|
|
2018
|
+
}
|
|
2019
|
+
function draw$1(element, state) {
|
|
2020
|
+
const { knob, now } = state;
|
|
2021
|
+
if (!state.position.active && !state.size.active && !state.press.active && !state.press.target && !state.wobble.active && state.wobbleTimer === void 0) {
|
|
2022
|
+
writeMotionStyle(knob, {
|
|
2023
|
+
translate: null,
|
|
2024
|
+
scale: null
|
|
2025
|
+
});
|
|
2026
|
+
return;
|
|
2027
|
+
}
|
|
2028
|
+
const trackWidth = element.offsetWidth;
|
|
2029
|
+
const off = restOf(state, false, trackWidth);
|
|
2030
|
+
const on = restOf(state, true, trackWidth);
|
|
2031
|
+
const p = state.position.value;
|
|
2032
|
+
const grown = state.size.value;
|
|
2033
|
+
const stretch = Math.min(.55, Math.abs(state.velocity) * .09) + state.press.value * .4;
|
|
2034
|
+
const sx = 1 + stretch + state.wobble.value * .14;
|
|
2035
|
+
const sy = 1 - stretch * .25 - state.wobble.value * .14;
|
|
2036
|
+
const width = (off.width + (on.width - off.width) * grown) * sx;
|
|
2037
|
+
const height = (off.height + (on.height - off.height) * grown) * sy;
|
|
2038
|
+
const start = Math.min(off.center - off.width / 2, on.center - on.width / 2);
|
|
2039
|
+
const end = Math.max(off.center + off.width / 2, on.center + on.width / 2);
|
|
2040
|
+
const center = off.center + (on.center - off.center) * p;
|
|
2041
|
+
const half = width / 2;
|
|
2042
|
+
const shift = (start + half > end - half ? (start + end) / 2 : Math.max(start + half, Math.min(end - half, center))) - (now.on ? on : off).center;
|
|
2043
|
+
writeMotionStyle(knob, {
|
|
2044
|
+
translate: `calc(${now.translate[0]} + ${shift.toFixed(2)}px) ${now.translate[1]}`,
|
|
2045
|
+
scale: `${(width / now.width).toFixed(4)} ${(height / now.height).toFixed(4)}`
|
|
2046
|
+
});
|
|
2047
|
+
}
|
|
2048
|
+
/**
|
|
2049
|
+
* True when the knob still moves with a CSS transition of its own, as Nuxt UI's thumb does without the ViteHub theme.
|
|
2050
|
+
* The transition would smear each frame of the springs, so that knob keeps its own motion.
|
|
2051
|
+
*/
|
|
2052
|
+
function transitionsKnob(knob) {
|
|
2053
|
+
const style = getComputedStyle(knob);
|
|
2054
|
+
const durations = style.transitionDuration.split(",");
|
|
2055
|
+
return style.transitionProperty.split(",").some((property, index) => /^\s*(?:transform|translate|scale|all)\s*$/.test(property) && Number.parseFloat(durations[index % durations.length]) > 0);
|
|
2056
|
+
}
|
|
2057
|
+
function knobOf(element, wasOn) {
|
|
2058
|
+
const existing = knobs.get(element);
|
|
2059
|
+
if (existing && existing.knob.isConnected && element.contains(existing.knob)) return existing;
|
|
2060
|
+
const knob = findKnob(element);
|
|
2061
|
+
if (!knob || transitionsKnob(knob)) return;
|
|
2062
|
+
const value = wasOn ? 1 : 0;
|
|
2063
|
+
const redraw = () => draw$1(element, state);
|
|
2064
|
+
const state = {
|
|
2065
|
+
knob,
|
|
2066
|
+
rest: [void 0, void 0],
|
|
2067
|
+
now: {
|
|
2068
|
+
on: wasOn,
|
|
2069
|
+
translate: ["0px", "0px"],
|
|
2070
|
+
width: 1,
|
|
2071
|
+
height: 1
|
|
2072
|
+
},
|
|
2073
|
+
position: createSpring(value, (position, velocity) => {
|
|
2074
|
+
state.velocity = velocity;
|
|
2075
|
+
redraw();
|
|
2076
|
+
}, travel),
|
|
2077
|
+
velocity: 0,
|
|
2078
|
+
size: createSpring(value, redraw, size),
|
|
2079
|
+
press: createSpring(0, redraw, pressSpring),
|
|
2080
|
+
wobble: createSpring(0, redraw, wobble),
|
|
2081
|
+
wobbleTimer: void 0
|
|
2082
|
+
};
|
|
2083
|
+
knobs.set(element, state);
|
|
2084
|
+
return state;
|
|
2085
|
+
}
|
|
2086
|
+
/** Measures the state that the stylesheet draws now and keeps it as the rest of that state. */
|
|
2087
|
+
function remeasure(element, state, on) {
|
|
2088
|
+
const { rest, translate, width, height } = measure(element, state.knob);
|
|
2089
|
+
state.rest[on ? 1 : 0] = rest;
|
|
2090
|
+
state.now = {
|
|
2091
|
+
on,
|
|
2092
|
+
translate,
|
|
2093
|
+
width,
|
|
2094
|
+
height
|
|
2095
|
+
};
|
|
2096
|
+
}
|
|
2097
|
+
function disabled(element) {
|
|
2098
|
+
return element.matches(":disabled, [aria-disabled=\"true\"]");
|
|
2099
|
+
}
|
|
2100
|
+
const switchKnob = {
|
|
2101
|
+
name: "switch",
|
|
2102
|
+
selector: "[role=switch]",
|
|
2103
|
+
press(element) {
|
|
2104
|
+
if (disabled(element)) return;
|
|
2105
|
+
const on = isOn(element.getAttribute("aria-checked"));
|
|
2106
|
+
const state = knobOf(element, on);
|
|
2107
|
+
if (!state) return;
|
|
2108
|
+
if (!state.position.active) remeasure(element, state, on);
|
|
2109
|
+
state.press.to(1);
|
|
2110
|
+
return { release: () => state.press.to(0) };
|
|
2111
|
+
},
|
|
2112
|
+
state(element, { attribute, oldValue, value }) {
|
|
2113
|
+
if (attribute !== "aria-checked") return;
|
|
2114
|
+
const on = isOn(value);
|
|
2115
|
+
const state = knobOf(element, isOn(oldValue));
|
|
2116
|
+
if (!state) return;
|
|
2117
|
+
remeasure(element, state, on);
|
|
2118
|
+
state.position.to(on ? 1 : 0);
|
|
2119
|
+
state.size.to(on ? 1 : 0);
|
|
2120
|
+
clearTimeout(state.wobbleTimer);
|
|
2121
|
+
state.wobbleTimer = void 0;
|
|
2122
|
+
if (!prefersReducedMotion()) state.wobbleTimer = setTimeout(() => {
|
|
2123
|
+
state.wobbleTimer = void 0;
|
|
2124
|
+
state.wobble.to(0, { velocity: wobbleKick });
|
|
2125
|
+
}, wobbleDelay * getMotionSlowFactor());
|
|
2126
|
+
draw$1(element, state);
|
|
2127
|
+
}
|
|
2128
|
+
};
|
|
2129
|
+
//#endregion
|
|
2130
|
+
//#region src/motion/effects/toast.ts
|
|
2131
|
+
const crossfade$1 = .15;
|
|
2132
|
+
const lists = /* @__PURE__ */ new WeakMap();
|
|
2133
|
+
const fixed = (element) => !!element && getComputedStyle(element).position === "fixed";
|
|
2134
|
+
function isToast(element) {
|
|
2135
|
+
const list = element.parentElement;
|
|
2136
|
+
if (!list || list.tagName !== "OL" && list.tagName !== "UL") return false;
|
|
2137
|
+
const region = list.closest("[role=region], [data-slot=toast-region]");
|
|
2138
|
+
return !!region && (fixed(list) || fixed(list.parentElement) || fixed(region));
|
|
2139
|
+
}
|
|
2140
|
+
function edgeOf$1(rect) {
|
|
2141
|
+
return rect.top + rect.height / 2 > innerHeight / 2 ? "bottom" : "top";
|
|
2142
|
+
}
|
|
2143
|
+
function pastEdge(rect) {
|
|
2144
|
+
return edgeOf$1(rect) === "bottom" ? innerHeight - rect.top : -(rect.top + rect.height);
|
|
2145
|
+
}
|
|
2146
|
+
function exitOf(rect, direction) {
|
|
2147
|
+
if (direction === "left") return {
|
|
2148
|
+
axis: "x",
|
|
2149
|
+
distance: -rect.right
|
|
2150
|
+
};
|
|
2151
|
+
if (direction === "right") return {
|
|
2152
|
+
axis: "x",
|
|
2153
|
+
distance: innerWidth - rect.left
|
|
2154
|
+
};
|
|
2155
|
+
if (direction === "up") return {
|
|
2156
|
+
axis: "y",
|
|
2157
|
+
distance: -rect.bottom
|
|
2158
|
+
};
|
|
2159
|
+
if (direction === "down") return {
|
|
2160
|
+
axis: "y",
|
|
2161
|
+
distance: innerHeight - rect.top
|
|
2162
|
+
};
|
|
2163
|
+
const center = rect.left + rect.width / 2;
|
|
2164
|
+
if (Math.abs(center - innerWidth / 2) < innerWidth / 8) return {
|
|
2165
|
+
axis: "y",
|
|
2166
|
+
distance: pastEdge(rect)
|
|
2167
|
+
};
|
|
2168
|
+
return {
|
|
2169
|
+
axis: "x",
|
|
2170
|
+
distance: center > innerWidth / 2 ? innerWidth - rect.left : -rect.right
|
|
2171
|
+
};
|
|
2172
|
+
}
|
|
2173
|
+
function exitDirection(list, element) {
|
|
2174
|
+
const align = list.region.getAttribute("data-align");
|
|
2175
|
+
if (align === "center") return list.region.getAttribute("data-side") === "top" ? "up" : "down";
|
|
2176
|
+
if (align === "start" || align === "end") return align === "start" !== (getComputedStyle(list.region).direction === "rtl") ? "left" : "right";
|
|
2177
|
+
return element.getAttribute("data-swipe-direction");
|
|
2178
|
+
}
|
|
2179
|
+
function swipeOffset(element, axis, released = false) {
|
|
2180
|
+
const reka = `--reka-toast-swipe-${released ? "end" : "move"}-${axis}`;
|
|
2181
|
+
return Number.parseFloat(element.style.getPropertyValue(reka) || element.style.getPropertyValue(`--toast-swipe-${axis}`)) || 0;
|
|
2182
|
+
}
|
|
2183
|
+
function write(element, x, y, fade) {
|
|
2184
|
+
const still = Math.abs(x.value) < .01 && Math.abs(y.value) < .01;
|
|
2185
|
+
const offset = (value, axis) => {
|
|
2186
|
+
return `calc(${`${Math.round(value * 100) / 100}px`} + var(--reka-toast-swipe-move-${axis}, var(--toast-swipe-${axis}, 0px)))`;
|
|
2187
|
+
};
|
|
2188
|
+
writeMotionStyle(element, {
|
|
2189
|
+
translate: still && !x.active && !y.active ? null : `${offset(x.value, "x")} ${offset(y.value, "y")}`,
|
|
2190
|
+
opacity: fade && (fade.active || fade.value < 1) ? String(fade.value) : null
|
|
2191
|
+
});
|
|
2192
|
+
}
|
|
2193
|
+
function createItem(element, rest) {
|
|
2194
|
+
const item = {
|
|
2195
|
+
element,
|
|
2196
|
+
rest
|
|
2197
|
+
};
|
|
2198
|
+
const frame = () => write(element, item.x, item.y, item.fade);
|
|
2199
|
+
item.x = createSpring(0, frame, springs.snappy);
|
|
2200
|
+
item.y = createSpring(0, frame, springs.snappy);
|
|
2201
|
+
return item;
|
|
2202
|
+
}
|
|
2203
|
+
function shift(spring, distance) {
|
|
2204
|
+
const velocity = spring.velocity;
|
|
2205
|
+
spring.set(spring.value + distance);
|
|
2206
|
+
spring.to(0, { velocity });
|
|
2207
|
+
}
|
|
2208
|
+
function relayout(list) {
|
|
2209
|
+
for (const item of list.items.values()) {
|
|
2210
|
+
if (!item.element.isConnected) continue;
|
|
2211
|
+
const rect = item.element.getBoundingClientRect();
|
|
2212
|
+
const rest = {
|
|
2213
|
+
left: rect.left - item.x.value - swipeOffset(item.element, "x"),
|
|
2214
|
+
top: rect.top - item.y.value - swipeOffset(item.element, "y"),
|
|
2215
|
+
width: rect.width,
|
|
2216
|
+
height: rect.height
|
|
2217
|
+
};
|
|
2218
|
+
const dx = item.rest.left - rest.left;
|
|
2219
|
+
const dy = item.rest.top - rest.top;
|
|
2220
|
+
item.rest = rest;
|
|
2221
|
+
if (Math.abs(dx) > .5) shift(item.x, dx);
|
|
2222
|
+
if (Math.abs(dy) > .5) shift(item.y, dy);
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
function watchLayout(list) {
|
|
2226
|
+
list.watchFrames = 12;
|
|
2227
|
+
if (list.frame) return;
|
|
2228
|
+
const step = () => {
|
|
2229
|
+
relayout(list);
|
|
2230
|
+
list.watchFrames = [...list.items.values()].some((item) => item.x.active || item.y.active) ? Math.max(list.watchFrames, 2) : list.watchFrames - 1;
|
|
2231
|
+
list.frame = list.watchFrames > 0 ? requestAnimationFrame(step) : 0;
|
|
2232
|
+
};
|
|
2233
|
+
list.frame = requestAnimationFrame(step);
|
|
2234
|
+
}
|
|
2235
|
+
function leave$1(list, element) {
|
|
2236
|
+
const item = list.items.get(element);
|
|
2237
|
+
if (!item) return;
|
|
2238
|
+
list.items.delete(element);
|
|
2239
|
+
item.x.stop();
|
|
2240
|
+
item.y.stop();
|
|
2241
|
+
const direction = exitDirection(list, element);
|
|
2242
|
+
const swipe = element.getAttribute("data-swipe") === "end" || element.matches("[data-slot=toast]") && element.hasAttribute("data-swipe-direction");
|
|
2243
|
+
const swipeDirection = swipe ? element.getAttribute("data-swipe-direction") : null;
|
|
2244
|
+
const parent = list.region.parentNode;
|
|
2245
|
+
if (parent) {
|
|
2246
|
+
const rect = new DOMRect(item.rest.left + item.x.value + (swipe ? swipeOffset(element, "x", true) : 0), item.rest.top + item.y.value + (swipe ? swipeOffset(element, "y", true) : 0), item.rest.width, item.rest.height);
|
|
2247
|
+
const ghost = createGhost(element, parent, list.region.nextSibling);
|
|
2248
|
+
writeMotionStyle(ghost, {
|
|
2249
|
+
translate: null,
|
|
2250
|
+
opacity: null
|
|
2251
|
+
});
|
|
2252
|
+
pinGhost(ghost, rect);
|
|
2253
|
+
if (prefersReducedMotion()) {
|
|
2254
|
+
const fade = createSpring(1, (value) => {
|
|
2255
|
+
writeMotionStyle(ghost, { opacity: String(value) });
|
|
2256
|
+
if (!fade.active && value === 0) ghost.remove();
|
|
2257
|
+
});
|
|
2258
|
+
fade.to(0, { tween: crossfade$1 });
|
|
2259
|
+
} else {
|
|
2260
|
+
const { axis, distance: target } = exitOf(rect, swipeDirection ?? direction);
|
|
2261
|
+
const spring = createSpring(0, (value) => {
|
|
2262
|
+
const offset = `${Math.round(value * 100) / 100}px`;
|
|
2263
|
+
writeMotionStyle(ghost, { translate: axis === "x" ? `${offset} 0px` : `0px ${offset}` });
|
|
2264
|
+
if ((target > 0 ? value >= target : value <= target) || !spring.active) {
|
|
2265
|
+
spring.stop();
|
|
2266
|
+
ghost.remove();
|
|
2267
|
+
}
|
|
2268
|
+
}, springs.snappy);
|
|
2269
|
+
spring.to(target);
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
relayout(list);
|
|
2273
|
+
watchLayout(list);
|
|
2274
|
+
if (!list.items.size) {
|
|
2275
|
+
list.observer.disconnect();
|
|
2276
|
+
lists.delete(list.element);
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
function listOf(element) {
|
|
2280
|
+
const parent = element.parentElement;
|
|
2281
|
+
let list = lists.get(parent);
|
|
2282
|
+
if (list) return list;
|
|
2283
|
+
const current = {
|
|
2284
|
+
element: parent,
|
|
2285
|
+
items: /* @__PURE__ */ new Map(),
|
|
2286
|
+
observer: new MutationObserver((records) => {
|
|
2287
|
+
for (const record of records) for (const node of record.removedNodes) if (node instanceof HTMLElement && !node.isConnected) leave$1(current, node);
|
|
2288
|
+
}),
|
|
2289
|
+
region: parent.closest("[role=region], [data-slot=toast-region]") ?? parent,
|
|
2290
|
+
watchFrames: 0,
|
|
2291
|
+
frame: 0
|
|
2292
|
+
};
|
|
2293
|
+
current.observer.observe(parent, { childList: true });
|
|
2294
|
+
lists.set(parent, current);
|
|
2295
|
+
list = current;
|
|
2296
|
+
return list;
|
|
2297
|
+
}
|
|
2298
|
+
/**
|
|
2299
|
+
* Something arrives on its own: a toast comes in from its edge of the screen, and the toasts that the list moves make
|
|
2300
|
+
* room with a spring. A toast that closes leaves past the side of the screen that the toaster sits at, and the others
|
|
2301
|
+
* close the gap. A toast that a person
|
|
2302
|
+
* swiped away leaves from where they let go. Under reduced motion a toast crossfades in and out in 150ms, and the others
|
|
2303
|
+
* take their new places at once.
|
|
2304
|
+
*
|
|
2305
|
+
* It is a role effect on the items of a notifications region, so Nuxt UI's `UToast` and ui-sdk's `Toast` both get it.
|
|
2306
|
+
*/
|
|
2307
|
+
const toast = {
|
|
2308
|
+
name: "toast",
|
|
2309
|
+
selector: "[role=region] li, [data-slot=toast]",
|
|
2310
|
+
enter(element) {
|
|
2311
|
+
if (!isToast(element)) return;
|
|
2312
|
+
const list = listOf(element);
|
|
2313
|
+
if (list.items.has(element)) return;
|
|
2314
|
+
relayout(list);
|
|
2315
|
+
const rect = element.getBoundingClientRect();
|
|
2316
|
+
const item = createItem(element, {
|
|
2317
|
+
left: rect.left,
|
|
2318
|
+
top: rect.top,
|
|
2319
|
+
width: rect.width,
|
|
2320
|
+
height: rect.height
|
|
2321
|
+
});
|
|
2322
|
+
list.items.set(element, item);
|
|
2323
|
+
if (prefersReducedMotion()) {
|
|
2324
|
+
const fade = createSpring(0, () => write(element, item.x, item.y, fade));
|
|
2325
|
+
item.fade = fade;
|
|
2326
|
+
fade.set(0);
|
|
2327
|
+
fade.to(1, { tween: crossfade$1 });
|
|
2328
|
+
} else {
|
|
2329
|
+
item.y.set(pastEdge(rect));
|
|
2330
|
+
item.y.to(0);
|
|
2331
|
+
}
|
|
2332
|
+
watchLayout(list);
|
|
2333
|
+
}
|
|
2334
|
+
};
|
|
2335
|
+
//#endregion
|
|
2336
|
+
//#region src/motion/effects/tooltip.ts
|
|
2337
|
+
const slide = {
|
|
2338
|
+
stiffness: 480,
|
|
2339
|
+
damping: 36
|
|
2340
|
+
};
|
|
2341
|
+
const rise = {
|
|
2342
|
+
stiffness: 380,
|
|
2343
|
+
damping: 26
|
|
2344
|
+
};
|
|
2345
|
+
const widen = {
|
|
2346
|
+
stiffness: 440,
|
|
2347
|
+
damping: 32
|
|
2348
|
+
};
|
|
2349
|
+
const narrow = 30;
|
|
2350
|
+
const widenAfter = 120;
|
|
2351
|
+
const labelAfterRise = 70;
|
|
2352
|
+
const labelAfterSlide = 40;
|
|
2353
|
+
const sinkAfter = 90;
|
|
2354
|
+
const goneAfter = 520;
|
|
2355
|
+
const labelIn = .24;
|
|
2356
|
+
const labelOutOnSlide = .15;
|
|
2357
|
+
const labelOutOnLeave = .14;
|
|
2358
|
+
const crossfade = .15;
|
|
2359
|
+
const tips = /* @__PURE__ */ new WeakMap();
|
|
2360
|
+
const openTips = /* @__PURE__ */ new Set();
|
|
2361
|
+
const exitBoxes = /* @__PURE__ */ new Set();
|
|
2362
|
+
let handoff;
|
|
2363
|
+
function visuallyHidden(element) {
|
|
2364
|
+
const style = getComputedStyle(element);
|
|
2365
|
+
return style.clipPath === "inset(50%)" || style.clip === "rect(0px, 0px, 0px, 0px)";
|
|
2366
|
+
}
|
|
2367
|
+
function roleElement(box) {
|
|
2368
|
+
return box.matches("[role=tooltip]") ? box : box.querySelector(":scope > [role=tooltip]");
|
|
2369
|
+
}
|
|
2370
|
+
/** An element that is not a tooltip but appears next to its trigger in the same way, such as a comment's draft bubble. */
|
|
2371
|
+
const appearSelector = "[data-motion-appear]";
|
|
2372
|
+
function visualBox(element) {
|
|
2373
|
+
if (element.matches(appearSelector)) return element;
|
|
2374
|
+
if (element.matches("[role=tooltip]")) return visuallyHidden(element) ? element.parentElement : element;
|
|
2375
|
+
const inner = element.querySelector(":scope > [role=tooltip]");
|
|
2376
|
+
return inner && visuallyHidden(inner) ? element : null;
|
|
2377
|
+
}
|
|
2378
|
+
function isOpen(box) {
|
|
2379
|
+
const state = box.getAttribute("data-state");
|
|
2380
|
+
if (state !== null) return state !== "closed";
|
|
2381
|
+
return !box.hidden && !box.hasAttribute("data-closed");
|
|
2382
|
+
}
|
|
2383
|
+
/**
|
|
2384
|
+
* The trigger of a tooltip: the element that `aria-describedby` points at it. The trigger of a `data-motion-appear`
|
|
2385
|
+
* element is the nearest element around it that its value selects, else a sibling that it selects, or none for an
|
|
2386
|
+
* empty value.
|
|
2387
|
+
*/
|
|
2388
|
+
function findTrigger(box) {
|
|
2389
|
+
const anchor = box.getAttribute("data-motion-appear");
|
|
2390
|
+
if (anchor !== null) {
|
|
2391
|
+
const parent = box.parentElement;
|
|
2392
|
+
if (!anchor || !parent) return null;
|
|
2393
|
+
return parent.closest(anchor) ?? [...parent.children].find((sibling) => sibling !== box && sibling.matches(anchor)) ?? null;
|
|
2394
|
+
}
|
|
2395
|
+
const id = roleElement(box)?.id;
|
|
2396
|
+
if (!id) return null;
|
|
2397
|
+
return box.getRootNode().querySelector(`[aria-describedby~="${CSS.escape(id)}"]`) ?? document.querySelector(`[aria-describedby~="${CSS.escape(id)}"]`);
|
|
2398
|
+
}
|
|
2399
|
+
function measureRest(element) {
|
|
2400
|
+
const saved = [
|
|
2401
|
+
"translate",
|
|
2402
|
+
"scale",
|
|
2403
|
+
"clip-path",
|
|
2404
|
+
"opacity"
|
|
2405
|
+
].map((name) => [name, element.style.getPropertyValue(name)]);
|
|
2406
|
+
writeMotionStyle(element, {
|
|
2407
|
+
translate: null,
|
|
2408
|
+
scale: null,
|
|
2409
|
+
"clip-path": null
|
|
2410
|
+
});
|
|
2411
|
+
const rect = element.getBoundingClientRect();
|
|
2412
|
+
for (const [name, value] of saved) if (value) element.style.setProperty(name, value);
|
|
2413
|
+
return rect;
|
|
2414
|
+
}
|
|
2415
|
+
function sideOf(box, rest, trigger) {
|
|
2416
|
+
const side = box.getAttribute("data-side");
|
|
2417
|
+
if (side === "top" || side === "bottom" || side === "left" || side === "right") return side;
|
|
2418
|
+
if (!trigger) return "top";
|
|
2419
|
+
const dx = trigger.left + trigger.width / 2 - (rest.left + rest.width / 2);
|
|
2420
|
+
const dy = trigger.top + trigger.height / 2 - (rest.top + rest.height / 2);
|
|
2421
|
+
if (Math.abs(dy) >= Math.abs(dx)) return dy > 0 ? "top" : "bottom";
|
|
2422
|
+
return dx > 0 ? "left" : "right";
|
|
2423
|
+
}
|
|
2424
|
+
function edgeOf(side, rest, trigger) {
|
|
2425
|
+
if (side === "top") return trigger?.top ?? rest.bottom + 8;
|
|
2426
|
+
if (side === "bottom") return trigger?.bottom ?? rest.top - 8;
|
|
2427
|
+
if (side === "left") return trigger?.left ?? rest.right + 8;
|
|
2428
|
+
return trigger?.right ?? rest.left - 8;
|
|
2429
|
+
}
|
|
2430
|
+
const vertical = (side) => side === "top" || side === "bottom";
|
|
2431
|
+
function hiddenCenter(box) {
|
|
2432
|
+
const { rest, side, edge } = box;
|
|
2433
|
+
if (side === "top") return edge + rest.height / 2;
|
|
2434
|
+
if (side === "bottom") return edge - rest.height / 2;
|
|
2435
|
+
if (side === "left") return edge + rest.width / 2;
|
|
2436
|
+
return edge - rest.width / 2;
|
|
2437
|
+
}
|
|
2438
|
+
function labelElements(box) {
|
|
2439
|
+
return [...box.element.children].filter((child) => child instanceof HTMLElement && child !== box.old?.element && !child.matches("[role=tooltip]") && !visuallyHidden(child));
|
|
2440
|
+
}
|
|
2441
|
+
function labelText(box) {
|
|
2442
|
+
return [...box.element.childNodes].filter((node) => node.nodeType === Node.TEXT_NODE || node instanceof Element && node !== box.old?.element && !node.matches("[role=tooltip]") && !visuallyHidden(node)).map((node) => node.textContent ?? "").join("");
|
|
2443
|
+
}
|
|
2444
|
+
function hasTextOfItsOwn(element) {
|
|
2445
|
+
return [...element.childNodes].some((node) => node.nodeType === Node.TEXT_NODE && node.textContent?.trim());
|
|
2446
|
+
}
|
|
2447
|
+
const px = (value) => `${Math.round(value * 100) / 100}px`;
|
|
2448
|
+
function draw(box) {
|
|
2449
|
+
const { element, rest, side, edge, origin } = box;
|
|
2450
|
+
const width = Math.max(1, box.width.value);
|
|
2451
|
+
const reveal = box.mode === "clip" && width < rest.width;
|
|
2452
|
+
const scale = reveal ? 1 : width / rest.width;
|
|
2453
|
+
const left = box.x.value - width / 2;
|
|
2454
|
+
const tx = reveal ? box.x.value - (rest.left + rest.width / 2) : left - rest.left - origin * (1 - scale);
|
|
2455
|
+
const ty = box.y.value - (rest.top + rest.height / 2);
|
|
2456
|
+
const insets = [
|
|
2457
|
+
-40,
|
|
2458
|
+
-40,
|
|
2459
|
+
-40,
|
|
2460
|
+
-40
|
|
2461
|
+
];
|
|
2462
|
+
if (side === "top") insets[2] = box.y.value + rest.height / 2 - edge;
|
|
2463
|
+
if (side === "bottom") insets[0] = edge - (box.y.value - rest.height / 2);
|
|
2464
|
+
if (side === "left") insets[1] = (box.x.value + width / 2 - edge) / scale;
|
|
2465
|
+
if (side === "right") insets[3] = (edge - (box.x.value - width / 2)) / scale;
|
|
2466
|
+
const behind = insets.some((inset) => inset > 0);
|
|
2467
|
+
let clip = null;
|
|
2468
|
+
if (reveal) {
|
|
2469
|
+
const hidden = (rest.width - width) / 2;
|
|
2470
|
+
clip = `inset(${[
|
|
2471
|
+
Math.max(0, insets[0]),
|
|
2472
|
+
hidden + Math.max(0, insets[1]),
|
|
2473
|
+
Math.max(0, insets[2]),
|
|
2474
|
+
hidden + Math.max(0, insets[3])
|
|
2475
|
+
].map(px).join(" ")} round ${box.radius})`;
|
|
2476
|
+
} else if (behind) clip = `inset(${insets.map(px).join(" ")})`;
|
|
2477
|
+
writeMotionStyle(element, {
|
|
2478
|
+
"translate": Math.abs(tx) > .01 || Math.abs(ty) > .01 || box.old ? `${px(tx)} ${px(ty)}` : null,
|
|
2479
|
+
"scale": Math.abs(scale - 1) > .001 ? `${scale} 1` : null,
|
|
2480
|
+
"clip-path": clip,
|
|
2481
|
+
"opacity": box.fade.active || box.fade.value < 1 ? String(box.fade.value) : null
|
|
2482
|
+
});
|
|
2483
|
+
const inverse = Math.abs(scale - 1) > .001 ? `${1 / scale} 1` : null;
|
|
2484
|
+
const label = box.label.value;
|
|
2485
|
+
for (const child of labelElements(box)) writeMotionStyle(child, {
|
|
2486
|
+
scale: inverse,
|
|
2487
|
+
opacity: label < 1 ? String(label) : null,
|
|
2488
|
+
filter: label < 1 ? `blur(${px((1 - label) * 6)})` : null
|
|
2489
|
+
});
|
|
2490
|
+
if (box.old) {
|
|
2491
|
+
const value = box.old.spring.value;
|
|
2492
|
+
writeMotionStyle(box.old.element, {
|
|
2493
|
+
scale: inverse,
|
|
2494
|
+
opacity: String(value),
|
|
2495
|
+
filter: `blur(${px((1 - value) * 5)})`
|
|
2496
|
+
});
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
function settle(box) {
|
|
2500
|
+
if (box.holding || box.timers.size || [
|
|
2501
|
+
box.x,
|
|
2502
|
+
box.y,
|
|
2503
|
+
box.width,
|
|
2504
|
+
box.label,
|
|
2505
|
+
box.fade,
|
|
2506
|
+
box.old?.spring
|
|
2507
|
+
].some((spring) => spring?.active)) return;
|
|
2508
|
+
box.old?.element.remove();
|
|
2509
|
+
box.old = void 0;
|
|
2510
|
+
writeMotionStyle(box.element, {
|
|
2511
|
+
"translate": null,
|
|
2512
|
+
"scale": null,
|
|
2513
|
+
"clip-path": null,
|
|
2514
|
+
"opacity": null
|
|
2515
|
+
});
|
|
2516
|
+
for (const child of labelElements(box)) writeMotionStyle(child, {
|
|
2517
|
+
scale: null,
|
|
2518
|
+
opacity: null,
|
|
2519
|
+
filter: null
|
|
2520
|
+
});
|
|
2521
|
+
box.done?.();
|
|
2522
|
+
}
|
|
2523
|
+
function createBox(element, rest, trigger) {
|
|
2524
|
+
const style = getComputedStyle(element);
|
|
2525
|
+
const side = sideOf(element, rest, trigger);
|
|
2526
|
+
const box = {
|
|
2527
|
+
element,
|
|
2528
|
+
rest,
|
|
2529
|
+
origin: Number.parseFloat(style.transformOrigin) || rest.width / 2,
|
|
2530
|
+
side,
|
|
2531
|
+
edge: edgeOf(side, rest, trigger),
|
|
2532
|
+
trigger,
|
|
2533
|
+
mode: hasTextOfItsOwn(element) || element.matches(appearSelector) ? "clip" : "scale",
|
|
2534
|
+
handoff: !element.matches(appearSelector),
|
|
2535
|
+
radius: style.borderRadius || "0px",
|
|
2536
|
+
timers: /* @__PURE__ */ new Set(),
|
|
2537
|
+
holding: true
|
|
2538
|
+
};
|
|
2539
|
+
const frame = () => {
|
|
2540
|
+
draw(box);
|
|
2541
|
+
settle(box);
|
|
2542
|
+
};
|
|
2543
|
+
box.x = createSpring(rest.left + rest.width / 2, frame, slide);
|
|
2544
|
+
box.y = createSpring(rest.top + rest.height / 2, frame, slide);
|
|
2545
|
+
box.width = createSpring(rest.width, frame, widen);
|
|
2546
|
+
box.label = createSpring(1, frame);
|
|
2547
|
+
box.fade = createSpring(1, frame);
|
|
2548
|
+
return box;
|
|
2549
|
+
}
|
|
2550
|
+
function later(box, ms, step) {
|
|
2551
|
+
const timer = after(ms, () => {
|
|
2552
|
+
box.timers.delete(timer);
|
|
2553
|
+
step();
|
|
2554
|
+
settle(box);
|
|
2555
|
+
});
|
|
2556
|
+
box.timers.add(timer);
|
|
2557
|
+
}
|
|
2558
|
+
function stopBox(box) {
|
|
2559
|
+
for (const timer of box.timers) clearTimeout(timer);
|
|
2560
|
+
box.timers.clear();
|
|
2561
|
+
for (const spring of [
|
|
2562
|
+
box.x,
|
|
2563
|
+
box.y,
|
|
2564
|
+
box.width,
|
|
2565
|
+
box.label,
|
|
2566
|
+
box.fade,
|
|
2567
|
+
box.old?.spring
|
|
2568
|
+
]) spring?.stop();
|
|
2569
|
+
}
|
|
2570
|
+
function removeGhost(box) {
|
|
2571
|
+
stopBox(box);
|
|
2572
|
+
exitBoxes.delete(box);
|
|
2573
|
+
if (handoff === box) handoff = void 0;
|
|
2574
|
+
box.element.closest("[data-motion=none]")?.remove();
|
|
2575
|
+
}
|
|
2576
|
+
function reduceTooltips(reduced) {
|
|
2577
|
+
if (!reduced) return;
|
|
2578
|
+
for (const ghost of exitBoxes) removeGhost(ghost);
|
|
2579
|
+
for (const element of openTips) {
|
|
2580
|
+
const box = tips.get(element)?.box;
|
|
2581
|
+
if (!box) continue;
|
|
2582
|
+
stopBox(box);
|
|
2583
|
+
box.holding = true;
|
|
2584
|
+
box.x.set(box.rest.left + box.rest.width / 2);
|
|
2585
|
+
box.y.set(box.rest.top + box.rest.height / 2);
|
|
2586
|
+
box.width.set(box.rest.width);
|
|
2587
|
+
box.label.set(1);
|
|
2588
|
+
box.fade.set(1);
|
|
2589
|
+
box.holding = false;
|
|
2590
|
+
settle(box);
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
function nextTo(from, to) {
|
|
2594
|
+
const a = from.trigger;
|
|
2595
|
+
const b = to.trigger;
|
|
2596
|
+
if (!a || !b || from.side !== to.side) return false;
|
|
2597
|
+
return vertical(to.side) ? a.top < b.bottom && b.top < a.bottom : a.left < b.right && b.left < a.right;
|
|
2598
|
+
}
|
|
2599
|
+
function along(box) {
|
|
2600
|
+
return vertical(box.side) ? box.y : box.x;
|
|
2601
|
+
}
|
|
2602
|
+
function blurOutOld(box, nodes, from) {
|
|
2603
|
+
if (!nodes.length) return;
|
|
2604
|
+
const element = document.createElement("span");
|
|
2605
|
+
element.setAttribute("aria-hidden", "true");
|
|
2606
|
+
Object.assign(element.style, {
|
|
2607
|
+
position: "absolute",
|
|
2608
|
+
inset: "0",
|
|
2609
|
+
display: "flex",
|
|
2610
|
+
alignItems: "center",
|
|
2611
|
+
justifyContent: "center",
|
|
2612
|
+
gap: "inherit",
|
|
2613
|
+
pointerEvents: "none",
|
|
2614
|
+
whiteSpace: "nowrap"
|
|
2615
|
+
});
|
|
2616
|
+
element.append(...nodes);
|
|
2617
|
+
box.element.append(element);
|
|
2618
|
+
const spring = createSpring(from, () => {
|
|
2619
|
+
draw(box);
|
|
2620
|
+
settle(box);
|
|
2621
|
+
});
|
|
2622
|
+
box.old = {
|
|
2623
|
+
element,
|
|
2624
|
+
spring
|
|
2625
|
+
};
|
|
2626
|
+
spring.to(0, { tween: labelOutOnSlide });
|
|
2627
|
+
}
|
|
2628
|
+
function copyLabel(box) {
|
|
2629
|
+
if (box.mode === "clip") return [...box.element.childNodes].filter((node) => node.nodeType === Node.TEXT_NODE).map((node) => node.cloneNode());
|
|
2630
|
+
return labelElements(box).map((child) => {
|
|
2631
|
+
const copy = child.cloneNode(true);
|
|
2632
|
+
copy.style.removeProperty("scale");
|
|
2633
|
+
copy.style.removeProperty("opacity");
|
|
2634
|
+
copy.style.removeProperty("filter");
|
|
2635
|
+
return copy;
|
|
2636
|
+
});
|
|
2637
|
+
}
|
|
2638
|
+
function start(element, tip) {
|
|
2639
|
+
const triggerRect = tip.trigger?.getBoundingClientRect();
|
|
2640
|
+
const rest = measureRest(element);
|
|
2641
|
+
const box = createBox(element, rest, triggerRect);
|
|
2642
|
+
tip.box = box;
|
|
2643
|
+
tip.text = labelText(box);
|
|
2644
|
+
tip.label = copyLabel(box);
|
|
2645
|
+
writeMotionStyle(element, { opacity: null });
|
|
2646
|
+
const from = box.handoff && handoff && nextTo(handoff, box) ? handoff : void 0;
|
|
2647
|
+
if (from) handoff = void 0;
|
|
2648
|
+
if (prefersReducedMotion()) {
|
|
2649
|
+
if (from) leaveGhost(from, true);
|
|
2650
|
+
box.fade.set(0);
|
|
2651
|
+
box.holding = false;
|
|
2652
|
+
box.fade.to(1, { tween: crossfade });
|
|
2653
|
+
return;
|
|
2654
|
+
}
|
|
2655
|
+
if (from) {
|
|
2656
|
+
const old = copyLabel(from);
|
|
2657
|
+
const values = {
|
|
2658
|
+
x: [from.x.value, from.x.velocity],
|
|
2659
|
+
y: [from.y.value, from.y.velocity],
|
|
2660
|
+
width: [from.width.value, from.width.velocity]
|
|
2661
|
+
};
|
|
2662
|
+
const label = from.old ? 0 : from.label.value;
|
|
2663
|
+
removeGhost(from);
|
|
2664
|
+
box.x.set(values.x[0]);
|
|
2665
|
+
box.y.set(values.y[0]);
|
|
2666
|
+
box.width.set(values.width[0]);
|
|
2667
|
+
box.label.set(0);
|
|
2668
|
+
blurOutOld(box, old, label);
|
|
2669
|
+
box.x.to(rest.left + rest.width / 2, {
|
|
2670
|
+
preset: slide,
|
|
2671
|
+
velocity: values.x[1]
|
|
2672
|
+
});
|
|
2673
|
+
box.y.to(rest.top + rest.height / 2, {
|
|
2674
|
+
preset: slide,
|
|
2675
|
+
velocity: values.y[1]
|
|
2676
|
+
});
|
|
2677
|
+
box.width.to(rest.width, {
|
|
2678
|
+
preset: widen,
|
|
2679
|
+
velocity: values.width[1]
|
|
2680
|
+
});
|
|
2681
|
+
later(box, labelAfterSlide, () => box.label.to(1, { tween: labelIn }));
|
|
2682
|
+
box.holding = false;
|
|
2683
|
+
draw(box);
|
|
2684
|
+
return;
|
|
2685
|
+
}
|
|
2686
|
+
along(box).set(hiddenCenter(box));
|
|
2687
|
+
box.width.set(Math.min(narrow, rest.width));
|
|
2688
|
+
box.label.set(0);
|
|
2689
|
+
draw(box);
|
|
2690
|
+
along(box).to(vertical(box.side) ? rest.top + rest.height / 2 : rest.left + rest.width / 2, { preset: rise });
|
|
2691
|
+
later(box, widenAfter, () => {
|
|
2692
|
+
box.width.to(rest.width, { preset: widen });
|
|
2693
|
+
later(box, labelAfterRise, () => box.label.to(1, { tween: labelIn }));
|
|
2694
|
+
});
|
|
2695
|
+
box.holding = false;
|
|
2696
|
+
}
|
|
2697
|
+
function leaveGhost(box, reduced) {
|
|
2698
|
+
exitBoxes.add(box);
|
|
2699
|
+
box.holding = false;
|
|
2700
|
+
if (reduced) {
|
|
2701
|
+
box.done = () => removeGhost(box);
|
|
2702
|
+
box.fade.to(0, { tween: crossfade });
|
|
2703
|
+
return;
|
|
2704
|
+
}
|
|
2705
|
+
if (box.handoff) handoff = box;
|
|
2706
|
+
if (box.old) box.old.spring.to(0, { tween: labelOutOnLeave });
|
|
2707
|
+
box.label.to(0, { tween: labelOutOnLeave });
|
|
2708
|
+
box.width.to(Math.min(narrow, box.rest.width), { preset: widen });
|
|
2709
|
+
later(box, sinkAfter, () => {
|
|
2710
|
+
if (handoff === box) handoff = void 0;
|
|
2711
|
+
along(box).to(hiddenCenter(box), { preset: rise });
|
|
2712
|
+
});
|
|
2713
|
+
later(box, goneAfter, () => removeGhost(box));
|
|
2714
|
+
}
|
|
2715
|
+
function leave(element, tip) {
|
|
2716
|
+
if (!tip.open) return;
|
|
2717
|
+
tip.open = false;
|
|
2718
|
+
openTips.delete(element);
|
|
2719
|
+
tip.stopWatch?.();
|
|
2720
|
+
tip.stopWatch = void 0;
|
|
2721
|
+
if (!openTips.size) stopWatchingMoves();
|
|
2722
|
+
const box = tip.box;
|
|
2723
|
+
tip.box = void 0;
|
|
2724
|
+
writeMotionStyle(element, { opacity: null });
|
|
2725
|
+
if (!box) return;
|
|
2726
|
+
const parent = tip.root.parentNode ?? tip.parent;
|
|
2727
|
+
const ghostRoot = parent?.isConnected ? createGhost(tip.root, parent, tip.root.isConnected ? tip.root.nextSibling : tip.next) : void 0;
|
|
2728
|
+
const now = {
|
|
2729
|
+
x: box.x,
|
|
2730
|
+
y: box.y,
|
|
2731
|
+
width: box.width,
|
|
2732
|
+
label: box.label,
|
|
2733
|
+
fade: box.fade
|
|
2734
|
+
};
|
|
2735
|
+
const values = Object.fromEntries(Object.entries(now).map(([name, spring]) => [name, [spring.value, spring.velocity]]));
|
|
2736
|
+
const oldLabel = box.old?.spring.value;
|
|
2737
|
+
stopBox(box);
|
|
2738
|
+
box.old?.element.remove();
|
|
2739
|
+
writeMotionStyle(element, {
|
|
2740
|
+
"translate": null,
|
|
2741
|
+
"scale": null,
|
|
2742
|
+
"clip-path": null,
|
|
2743
|
+
"opacity": null
|
|
2744
|
+
});
|
|
2745
|
+
for (const child of labelElements(box)) writeMotionStyle(child, {
|
|
2746
|
+
scale: null,
|
|
2747
|
+
opacity: null,
|
|
2748
|
+
filter: null
|
|
2749
|
+
});
|
|
2750
|
+
if (!ghostRoot) return;
|
|
2751
|
+
const ghostElement = pathTo(tip.root, element).reduce((node, index) => node?.children[index], ghostRoot);
|
|
2752
|
+
if (!(ghostElement instanceof HTMLElement)) {
|
|
2753
|
+
ghostRoot.remove();
|
|
2754
|
+
return;
|
|
2755
|
+
}
|
|
2756
|
+
if (element.hasAttribute("popover")) {
|
|
2757
|
+
writeMotionStyle(ghostElement, { scale: null });
|
|
2758
|
+
pinGhost(ghostElement, box.rest);
|
|
2759
|
+
}
|
|
2760
|
+
const ghost = createBox(ghostElement, box.rest, void 0);
|
|
2761
|
+
Object.assign(ghost, {
|
|
2762
|
+
side: box.side,
|
|
2763
|
+
edge: box.edge,
|
|
2764
|
+
trigger: box.trigger,
|
|
2765
|
+
mode: box.mode,
|
|
2766
|
+
origin: box.origin,
|
|
2767
|
+
radius: box.radius,
|
|
2768
|
+
handoff: box.handoff
|
|
2769
|
+
});
|
|
2770
|
+
const old = ghostElement.querySelector(":scope > [aria-hidden=true][style*=absolute]");
|
|
2771
|
+
if (oldLabel !== void 0 && old) ghost.old = {
|
|
2772
|
+
element: old,
|
|
2773
|
+
spring: createSpring(oldLabel, () => draw(ghost))
|
|
2774
|
+
};
|
|
2775
|
+
for (const name of [
|
|
2776
|
+
"x",
|
|
2777
|
+
"y",
|
|
2778
|
+
"width",
|
|
2779
|
+
"label",
|
|
2780
|
+
"fade"
|
|
2781
|
+
]) ghost[name].set(values[name][0]);
|
|
2782
|
+
draw(ghost);
|
|
2783
|
+
for (const name of [
|
|
2784
|
+
"x",
|
|
2785
|
+
"y",
|
|
2786
|
+
"width"
|
|
2787
|
+
]) if (values[name][1]) ghost[name].to(values[name][0], { velocity: values[name][1] });
|
|
2788
|
+
leaveGhost(ghost, prefersReducedMotion());
|
|
2789
|
+
}
|
|
2790
|
+
function pathTo(root, element) {
|
|
2791
|
+
const path = [];
|
|
2792
|
+
for (let node = element; node !== root && node.parentElement; node = node.parentElement) path.unshift([...node.parentElement.children].indexOf(node));
|
|
2793
|
+
return path;
|
|
2794
|
+
}
|
|
2795
|
+
function whenPlaced(element, tip, callback, frames = 20) {
|
|
2796
|
+
requestAnimationFrame(() => {
|
|
2797
|
+
if (!tip.open || !element.isConnected) return;
|
|
2798
|
+
const wrapper = element.closest("[data-reka-popper-content-wrapper]");
|
|
2799
|
+
if (frames > 0 && wrapper?.style.transform.includes("-200%")) return whenPlaced(element, tip, callback, frames - 1);
|
|
2800
|
+
callback();
|
|
2801
|
+
});
|
|
2802
|
+
}
|
|
2803
|
+
function watchRemoval(element, tip) {
|
|
2804
|
+
const observe = () => {
|
|
2805
|
+
observer.disconnect();
|
|
2806
|
+
let node = element;
|
|
2807
|
+
while (node) {
|
|
2808
|
+
const parent = node.parentNode;
|
|
2809
|
+
if (parent) observer.observe(parent, { childList: true });
|
|
2810
|
+
node = parent ?? (node instanceof ShadowRoot ? node.host : null);
|
|
2811
|
+
}
|
|
2812
|
+
};
|
|
2813
|
+
const observer = new MutationObserver(() => {
|
|
2814
|
+
if (!element.isConnected) leave(element, tip);
|
|
2815
|
+
else {
|
|
2816
|
+
tip.parent = tip.root.parentNode;
|
|
2817
|
+
tip.next = tip.root.nextSibling;
|
|
2818
|
+
observe();
|
|
2819
|
+
}
|
|
2820
|
+
});
|
|
2821
|
+
observe();
|
|
2822
|
+
return () => observer.disconnect();
|
|
2823
|
+
}
|
|
2824
|
+
function open(element) {
|
|
2825
|
+
let tip = tips.get(element);
|
|
2826
|
+
if (tip?.open) return;
|
|
2827
|
+
const trigger = findTrigger(element);
|
|
2828
|
+
if (trigger && isMotionOff(trigger)) return;
|
|
2829
|
+
const root = element.closest("[data-reka-popper-content-wrapper]") ?? element;
|
|
2830
|
+
tip = {
|
|
2831
|
+
open: true,
|
|
2832
|
+
root,
|
|
2833
|
+
parent: root.parentNode,
|
|
2834
|
+
next: root.nextSibling,
|
|
2835
|
+
text: "",
|
|
2836
|
+
label: [],
|
|
2837
|
+
trigger
|
|
2838
|
+
};
|
|
2839
|
+
tips.set(element, tip);
|
|
2840
|
+
openTips.add(element);
|
|
2841
|
+
watchMoves();
|
|
2842
|
+
writeMotionStyle(element, { opacity: "0" });
|
|
2843
|
+
tip.stopWatch = watchRemoval(element, tip);
|
|
2844
|
+
const current = tip;
|
|
2845
|
+
whenPlaced(element, tip, () => start(element, current));
|
|
2846
|
+
}
|
|
2847
|
+
let checking = 0;
|
|
2848
|
+
function checkMoves() {
|
|
2849
|
+
checking = 0;
|
|
2850
|
+
for (const element of openTips) {
|
|
2851
|
+
const tip = tips.get(element);
|
|
2852
|
+
const box = tip?.box;
|
|
2853
|
+
if (!tip || !box) continue;
|
|
2854
|
+
const rest = measureRest(element);
|
|
2855
|
+
const text = labelText(box);
|
|
2856
|
+
if (!(Math.abs(rest.left - box.rest.left) > 1 || Math.abs(rest.top - box.rest.top) > 1 || Math.abs(rest.width - box.rest.width) > 1) && text === tip.text) continue;
|
|
2857
|
+
const old = text === tip.text ? [] : tip.label;
|
|
2858
|
+
tip.trigger = findTrigger(element) ?? tip.trigger;
|
|
2859
|
+
const triggerRect = tip.trigger?.getBoundingClientRect();
|
|
2860
|
+
tip.text = text;
|
|
2861
|
+
tip.label = copyLabel(box);
|
|
2862
|
+
box.rest = rest;
|
|
2863
|
+
box.side = sideOf(element, rest, triggerRect);
|
|
2864
|
+
box.edge = edgeOf(box.side, rest, triggerRect);
|
|
2865
|
+
if (prefersReducedMotion()) {
|
|
2866
|
+
box.x.set(rest.left + rest.width / 2);
|
|
2867
|
+
box.y.set(rest.top + rest.height / 2);
|
|
2868
|
+
box.width.set(rest.width);
|
|
2869
|
+
continue;
|
|
2870
|
+
}
|
|
2871
|
+
box.x.to(rest.left + rest.width / 2, { preset: slide });
|
|
2872
|
+
box.y.to(rest.top + rest.height / 2, { preset: slide });
|
|
2873
|
+
box.width.to(rest.width, { preset: widen });
|
|
2874
|
+
if (old.length) {
|
|
2875
|
+
box.old?.spring.stop();
|
|
2876
|
+
box.old?.element.remove();
|
|
2877
|
+
blurOutOld(box, old, box.label.value);
|
|
2878
|
+
box.label.set(0);
|
|
2879
|
+
later(box, labelAfterSlide, () => box.label.to(1, { tween: labelIn }));
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
function onMove() {
|
|
2884
|
+
if (!checking) checking = requestAnimationFrame(checkMoves);
|
|
2885
|
+
}
|
|
2886
|
+
let watching = false;
|
|
2887
|
+
let stopWatchingReduction;
|
|
2888
|
+
function watchMoves() {
|
|
2889
|
+
stopWatchingReduction ??= onReducedMotionChange(reduceTooltips);
|
|
2890
|
+
if (watching) return;
|
|
2891
|
+
watching = true;
|
|
2892
|
+
document.addEventListener("pointerover", onMove, {
|
|
2893
|
+
capture: true,
|
|
2894
|
+
passive: true
|
|
2895
|
+
});
|
|
2896
|
+
document.addEventListener("focusin", onMove, {
|
|
2897
|
+
capture: true,
|
|
2898
|
+
passive: true
|
|
2899
|
+
});
|
|
2900
|
+
}
|
|
2901
|
+
function stopWatchingMoves() {
|
|
2902
|
+
watching = false;
|
|
2903
|
+
cancelAnimationFrame(checking);
|
|
2904
|
+
checking = 0;
|
|
2905
|
+
document.removeEventListener("pointerover", onMove, { capture: true });
|
|
2906
|
+
document.removeEventListener("focusin", onMove, { capture: true });
|
|
2907
|
+
}
|
|
2908
|
+
/** The hooks of a tooltip and of an element with `data-motion-appear`: both appear the same way. */
|
|
2909
|
+
const appearHooks = {
|
|
2910
|
+
enter(element) {
|
|
2911
|
+
if (visualBox(element) !== element || !isOpen(element)) return;
|
|
2912
|
+
open(element);
|
|
2913
|
+
},
|
|
2914
|
+
state(element) {
|
|
2915
|
+
if (visualBox(element) !== element) return;
|
|
2916
|
+
const tip = tips.get(element);
|
|
2917
|
+
if (isOpen(element)) open(element);
|
|
2918
|
+
else if (tip) leave(element, tip);
|
|
2919
|
+
}
|
|
2920
|
+
};
|
|
2921
|
+
/**
|
|
2922
|
+
* A tooltip appears next to its trigger: it rises from behind its trigger, narrow and without its label, widens to
|
|
2923
|
+
* fit, and blurs its label in. When the next trigger opens its tooltip while this one leaves, the new one takes the
|
|
2924
|
+
* place, size, and speed of the old one and slides over. A tooltip that closes narrows and sinks back behind its
|
|
2925
|
+
* trigger. Under reduced motion it crossfades in 150ms.
|
|
2926
|
+
*
|
|
2927
|
+
* Floating UI or Reka still places the tooltip. The effect only adds `translate`, `scale`, `clip-path`, `opacity`, and
|
|
2928
|
+
* `filter` to that.
|
|
2929
|
+
*/
|
|
2930
|
+
const tooltip = {
|
|
2931
|
+
name: "tooltip",
|
|
2932
|
+
selector: "[role=tooltip], :has(> [role=tooltip])",
|
|
2933
|
+
...appearHooks
|
|
2934
|
+
};
|
|
2935
|
+
/**
|
|
2936
|
+
* An element with `data-motion-appear` that is not a tooltip, such as a comment's draft bubble or a tab that comes out
|
|
2937
|
+
* of a bar, appears as a tooltip does when it is added to the page, but never takes the place of another one. Its
|
|
2938
|
+
* trigger is the nearest element around it, or a sibling, that the attribute's value selects; with an empty value it
|
|
2939
|
+
* rises from 8px past its own edge, on the side that `data-side` names. Its parts are revealed, not squeezed, while it
|
|
2940
|
+
* widens.
|
|
2941
|
+
*/
|
|
2942
|
+
const appear = {
|
|
2943
|
+
name: "appear",
|
|
2944
|
+
selector: appearSelector,
|
|
2945
|
+
...appearHooks
|
|
2946
|
+
};
|
|
2947
|
+
//#endregion
|
|
2948
|
+
//#region src/motion/effects/index.ts
|
|
2949
|
+
/**
|
|
2950
|
+
* Every built-in effect: what `installMotion()` of `@vite-hub/ui/motion` runs. Add a role effect here, in a file of its
|
|
2951
|
+
* own, and export it from `src/motion-core.ts`.
|
|
2952
|
+
*/
|
|
2953
|
+
const motionEffects = [
|
|
2954
|
+
press,
|
|
2955
|
+
select,
|
|
2956
|
+
switchKnob,
|
|
2957
|
+
check,
|
|
2958
|
+
jelly,
|
|
2959
|
+
tooltip,
|
|
2960
|
+
appear,
|
|
2961
|
+
toast,
|
|
2962
|
+
slider,
|
|
2963
|
+
divider,
|
|
2964
|
+
label,
|
|
2965
|
+
buttonIcon,
|
|
2966
|
+
disclosure,
|
|
2967
|
+
leave$2,
|
|
2968
|
+
panel
|
|
2969
|
+
];
|
|
2970
|
+
//#endregion
|
|
2971
|
+
export { divider as _, switchKnob as a, press as c, buttonIcon as d, label as f, installMotion as g, check as h, toast as i, panel as l, disclosure as m, appear as n, slider as o, jelly as p, tooltip as r, select as s, motionEffects as t, leave$2 as u };
|