@vite-hub/ui 0.4.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 +102 -76
- package/dist/announce-Cy_Tn9wW.js +32 -0
- package/dist/{avatar-stack-DPRFuezh.d.ts → avatar-stack-DXmCQhxd.d.ts} +1 -1
- package/dist/{comment-composer-jYv2ULNP.js → comment-composer-D7ZytyER.js} +257 -10
- package/dist/{comment-composer-fINL5bxo.d.ts → comment-composer-DvKMTrAi.d.ts} +4 -4
- package/dist/{comment-layer-C_sbPIR5.d.ts → comment-layer-GTsLdABl.d.ts} +4 -4
- package/dist/{comment-list-BcSaLngS.d.ts → comment-list-BI96empx.d.ts} +2 -2
- package/dist/comment-marks.css +18 -22
- package/dist/{comment-panel-CfvdRUMX.d.ts → comment-panel-CsKWTms_.d.ts} +2 -2
- package/dist/{comment-pin-DHOdRvUw.d.ts → comment-pin-CvwgRSDR.d.ts} +1 -1
- package/dist/{comment-row-Bn3nr8l5.js → comment-row-JmTC0uXr.js} +1 -1
- 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-DKJjmWN0.d.ts → comment-thread-C6U-bsK_.d.ts} +4 -4
- package/dist/{comments-D0d26ghV.js → comments-B88zg9gC.js} +1 -1
- 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/headless.d.ts +1 -1
- 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-BYRFQfCd.d.ts → index-YUvL2nV8.d.ts} +8 -10
- package/dist/index.d.ts +19 -14
- package/dist/index.js +45 -44
- 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.js +1 -1
- package/dist/{message-scroller-jrYN9dG9.d.ts → message-scroller-Bm1YWTeY.d.ts} +2 -2
- 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 +1 -1
- package/dist/nuxt.js +12 -3
- package/dist/opt-out-b6bnUjIT.js +208 -0
- package/dist/parts/components/agent-session.js +1 -1
- package/dist/parts/components/attachment.d.ts +1 -1
- package/dist/parts/components/attachment.js +1 -1
- package/dist/parts/components/avatar-stack.d.ts +1 -1
- package/dist/parts/components/avatar-stack.js +2 -1
- package/dist/parts/components/bubble.d.ts +1 -1
- package/dist/parts/components/chat-session.d.ts +1 -1
- package/dist/parts/components/chat.js +2 -2
- package/dist/parts/components/code-block.d.ts +1 -1
- package/dist/parts/components/code-block.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 +24 -6
- package/dist/parts/components/comment-list.d.ts +1 -1
- package/dist/parts/components/comment-list.js +12 -7
- package/dist/parts/components/comment-panel.d.ts +1 -1
- package/dist/parts/components/comment-panel.js +24 -10
- package/dist/parts/components/comment-pin.d.ts +1 -1
- package/dist/parts/components/comment-selection-bar.js +3 -2
- 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 +1 -1
- package/dist/parts/components/comment-thread.js +2 -597
- package/dist/parts/components/comments.d.ts +8 -7
- package/dist/parts/components/comments.js +5 -4
- package/dist/parts/components/copy-button.d.ts +13 -3
- package/dist/parts/components/copy-button.js +226 -1
- package/dist/parts/components/device-frame.d.ts +2 -2
- 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.js +1 -1
- package/dist/parts/components/markdown-renderer.js +1 -1
- package/dist/parts/components/markdown.js +1 -1
- package/dist/parts/components/marker.d.ts +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 +5 -5
- 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 +1 -1
- package/dist/parts/components/trace.d.ts +1 -1
- package/dist/parts/headless/comments.js +1 -1
- package/dist/parts/headless/message-scroller.d.ts +1 -1
- package/dist/parts/playground/share.d.ts +36 -2
- package/dist/parts/workspace/browser-support-notice.d.ts +1 -1
- 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.d.ts +1 -1
- 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-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/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 +586 -573
- 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-Dj7vp0lZ.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 +16 -3
- package/dist/workspace.js +15 -2
- package/package.json +21 -10
- package/dist/copy-button-CRN3kmSD.js +0 -253
- 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,826 @@
|
|
|
1
|
+
import { i as getMotionSlowFactor } from "./opt-out-b6bnUjIT.js";
|
|
2
|
+
import { u as writeMotionStyle } from "./registry-D3-ysX7l.js";
|
|
3
|
+
import { c as own, i as glyphNode, l as reduced, n as frameOf, o as motionSkipped, r as glyphMotionSkipped, s as openFrame, u as setText } from "./ring-B7Qxu7zd.js";
|
|
4
|
+
import { a as tween, n as easeIn, r as easeOut, t as cubicBezier } from "./tween-CO24nMpf.js";
|
|
5
|
+
//#region src/motion/effects/icon-shape.ts
|
|
6
|
+
const svgNamespace = "http://www.w3.org/2000/svg";
|
|
7
|
+
const geometry = /* @__PURE__ */ new Map([
|
|
8
|
+
["path", ["d"]],
|
|
9
|
+
["line", [
|
|
10
|
+
"x1",
|
|
11
|
+
"y1",
|
|
12
|
+
"x2",
|
|
13
|
+
"y2"
|
|
14
|
+
]],
|
|
15
|
+
["polyline", ["points"]],
|
|
16
|
+
["polygon", ["points"]],
|
|
17
|
+
["circle", [
|
|
18
|
+
"cx",
|
|
19
|
+
"cy",
|
|
20
|
+
"r"
|
|
21
|
+
]],
|
|
22
|
+
["ellipse", [
|
|
23
|
+
"cx",
|
|
24
|
+
"cy",
|
|
25
|
+
"rx",
|
|
26
|
+
"ry"
|
|
27
|
+
]],
|
|
28
|
+
["rect", [
|
|
29
|
+
"x",
|
|
30
|
+
"y",
|
|
31
|
+
"width",
|
|
32
|
+
"height",
|
|
33
|
+
"rx",
|
|
34
|
+
"ry"
|
|
35
|
+
]]
|
|
36
|
+
]);
|
|
37
|
+
const shapeSelector = [...geometry.keys()].join(", ");
|
|
38
|
+
/** The icons inside an element: inline `<svg>` elements, and Iconify CSS icons. */
|
|
39
|
+
function findIcons(element) {
|
|
40
|
+
const icons = [];
|
|
41
|
+
for (const node of element.querySelectorAll("svg, .iconify")) {
|
|
42
|
+
if (node instanceof SVGSVGElement && node.parentElement?.closest("svg")) continue;
|
|
43
|
+
if (node instanceof SVGSVGElement || cssIconSource(node)) icons.push(node);
|
|
44
|
+
}
|
|
45
|
+
return icons;
|
|
46
|
+
}
|
|
47
|
+
function cssIconSource(element) {
|
|
48
|
+
const value = getComputedStyle(element).getPropertyValue("--svg").trim();
|
|
49
|
+
const url = /^url\(\s*(["']?)(.*)\1\s*\)$/s.exec(value)?.[2];
|
|
50
|
+
if (!url?.startsWith("data:image/svg+xml")) return;
|
|
51
|
+
const comma = url.indexOf(",");
|
|
52
|
+
const data = url.slice(comma + 1);
|
|
53
|
+
try {
|
|
54
|
+
return url.slice(0, comma).endsWith(";base64") ? atob(data) : decodeURIComponent(data);
|
|
55
|
+
} catch {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function editor(shapes) {
|
|
60
|
+
const originals = /* @__PURE__ */ new Map();
|
|
61
|
+
return {
|
|
62
|
+
set(shape, name, value) {
|
|
63
|
+
let kept = originals.get(shape);
|
|
64
|
+
if (!kept) originals.set(shape, kept = /* @__PURE__ */ new Map());
|
|
65
|
+
if (!kept.has(name)) kept.set(name, shape.getAttribute(name));
|
|
66
|
+
shape.setAttribute(name, value);
|
|
67
|
+
},
|
|
68
|
+
putBack() {
|
|
69
|
+
for (const [shape, kept] of originals) for (const [name, value] of kept) if (value === null) shape.removeAttribute(name);
|
|
70
|
+
else shape.setAttribute(name, value);
|
|
71
|
+
originals.clear();
|
|
72
|
+
},
|
|
73
|
+
shapes
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** The shapes of an icon from `findIcons`, or undefined when it has none. */
|
|
77
|
+
function iconShape(icon) {
|
|
78
|
+
if (icon instanceof SVGSVGElement) {
|
|
79
|
+
const { set, putBack, shapes } = editor([...icon.querySelectorAll(shapeSelector)]);
|
|
80
|
+
if (!shapes.length) return;
|
|
81
|
+
return {
|
|
82
|
+
shapes,
|
|
83
|
+
set,
|
|
84
|
+
commit() {},
|
|
85
|
+
restore: putBack,
|
|
86
|
+
measure: (read) => read(shapes)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const source = cssIconSource(icon);
|
|
90
|
+
if (!source) return;
|
|
91
|
+
const svg = new DOMParser().parseFromString(source, "image/svg+xml").documentElement;
|
|
92
|
+
if (!(svg instanceof SVGSVGElement)) return;
|
|
93
|
+
if (svg.matches("[style], [class], [transform]")) return;
|
|
94
|
+
const copies = [];
|
|
95
|
+
const originals = [];
|
|
96
|
+
for (const child of svg.children) {
|
|
97
|
+
const attributes = geometry.get(child.localName);
|
|
98
|
+
if (!attributes || !(child instanceof SVGGeometryElement) || child.childElementCount || child.matches("[style], [class], [transform]")) return;
|
|
99
|
+
const copy = document.createElementNS(svgNamespace, child.localName);
|
|
100
|
+
if (!(copy instanceof SVGGeometryElement)) return;
|
|
101
|
+
for (const name of attributes) {
|
|
102
|
+
const value = child.getAttribute(name);
|
|
103
|
+
if (value !== null) copy.setAttribute(name, value);
|
|
104
|
+
}
|
|
105
|
+
copies.push(copy);
|
|
106
|
+
originals.push(child);
|
|
107
|
+
}
|
|
108
|
+
if (!copies.length) return;
|
|
109
|
+
const { set, putBack, shapes } = editor(originals);
|
|
110
|
+
const readMask = () => ({
|
|
111
|
+
value: icon.style.getPropertyValue("--svg"),
|
|
112
|
+
priority: icon.style.getPropertyPriority("--svg")
|
|
113
|
+
});
|
|
114
|
+
const original = readMask();
|
|
115
|
+
let written;
|
|
116
|
+
const matchesMask = (expected) => {
|
|
117
|
+
const current = readMask();
|
|
118
|
+
return expected.value === current.value && expected.priority === current.priority;
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
shapes,
|
|
122
|
+
set,
|
|
123
|
+
commit() {
|
|
124
|
+
if (!matchesMask(written ?? original)) return;
|
|
125
|
+
icon.style.setProperty("--svg", `url("data:image/svg+xml,${encodeURIComponent(new XMLSerializer().serializeToString(svg))}")`, original.priority);
|
|
126
|
+
written = readMask();
|
|
127
|
+
},
|
|
128
|
+
restore() {
|
|
129
|
+
putBack();
|
|
130
|
+
if (written && matchesMask(written)) {
|
|
131
|
+
const { value, priority } = original;
|
|
132
|
+
if (value) icon.style.setProperty("--svg", value, priority);
|
|
133
|
+
else icon.style.removeProperty("--svg");
|
|
134
|
+
}
|
|
135
|
+
written = void 0;
|
|
136
|
+
},
|
|
137
|
+
measure(read) {
|
|
138
|
+
const host = document.createElementNS(svgNamespace, "svg");
|
|
139
|
+
host.setAttribute("aria-hidden", "true");
|
|
140
|
+
host.style.cssText = "position:absolute;width:0;height:0;overflow:hidden;visibility:hidden";
|
|
141
|
+
host.append(...copies);
|
|
142
|
+
document.body.append(host);
|
|
143
|
+
try {
|
|
144
|
+
return read(copies);
|
|
145
|
+
} finally {
|
|
146
|
+
host.remove();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/motion/helpers/icon.ts
|
|
153
|
+
const exit = {
|
|
154
|
+
duration: 200,
|
|
155
|
+
travel: 12,
|
|
156
|
+
scale: .6,
|
|
157
|
+
blur: 2
|
|
158
|
+
};
|
|
159
|
+
const enterBlur = {
|
|
160
|
+
duration: 260,
|
|
161
|
+
delay: 40,
|
|
162
|
+
scale: .5,
|
|
163
|
+
blur: 3,
|
|
164
|
+
ease: cubicBezier(.3, 1.5, .5, 1)
|
|
165
|
+
};
|
|
166
|
+
const enterSlide = {
|
|
167
|
+
duration: 260,
|
|
168
|
+
delay: 80,
|
|
169
|
+
travel: 10,
|
|
170
|
+
ease: cubicBezier(.2, .8, .2, 1)
|
|
171
|
+
};
|
|
172
|
+
const draw = {
|
|
173
|
+
duration: 340,
|
|
174
|
+
spinner: 420,
|
|
175
|
+
delay: 120,
|
|
176
|
+
ease: cubicBezier(.6, 0, .2, 1)
|
|
177
|
+
};
|
|
178
|
+
const crossfade$2 = 150;
|
|
179
|
+
const directions = {
|
|
180
|
+
left: [-1, 0],
|
|
181
|
+
right: [1, 0],
|
|
182
|
+
up: [0, -1],
|
|
183
|
+
down: [0, 1]
|
|
184
|
+
};
|
|
185
|
+
const states = /* @__PURE__ */ new WeakMap();
|
|
186
|
+
const positioned = /* @__PURE__ */ new WeakMap();
|
|
187
|
+
function stateOf(icon) {
|
|
188
|
+
let state = states.get(icon);
|
|
189
|
+
if (!state) {
|
|
190
|
+
state = {
|
|
191
|
+
shown: 1,
|
|
192
|
+
leaving: false
|
|
193
|
+
};
|
|
194
|
+
states.set(icon, state);
|
|
195
|
+
}
|
|
196
|
+
return state;
|
|
197
|
+
}
|
|
198
|
+
function styled(icon) {
|
|
199
|
+
return icon instanceof HTMLElement || icon instanceof SVGElement;
|
|
200
|
+
}
|
|
201
|
+
function strokes(icon) {
|
|
202
|
+
const svg = icon instanceof SVGSVGElement ? icon : icon.querySelector("svg");
|
|
203
|
+
const shape = svg ? iconShape(svg) : void 0;
|
|
204
|
+
const parts = shape?.shapes.filter((part) => getComputedStyle(part).stroke !== "none") ?? [];
|
|
205
|
+
return shape && parts.length ? {
|
|
206
|
+
shape,
|
|
207
|
+
parts
|
|
208
|
+
} : void 0;
|
|
209
|
+
}
|
|
210
|
+
function saveStyle(style, property) {
|
|
211
|
+
const value = style.getPropertyValue(property);
|
|
212
|
+
const priority = style.getPropertyPriority(property);
|
|
213
|
+
return () => {
|
|
214
|
+
if (value) style.setProperty(property, value, priority);
|
|
215
|
+
else style.removeProperty(property);
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function paintIcon(icon, state, values) {
|
|
219
|
+
if (!styled(icon)) return;
|
|
220
|
+
const styles = state.styles ??= /* @__PURE__ */ new Map();
|
|
221
|
+
for (const [property, value] of Object.entries(values)) {
|
|
222
|
+
if (!styles.has(property)) styles.set(property, saveStyle(icon.style, property));
|
|
223
|
+
icon.style.setProperty(property, value);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function clear(state) {
|
|
227
|
+
state.stroke?.restore();
|
|
228
|
+
state.stroke = void 0;
|
|
229
|
+
for (const restore of state.styles?.values() ?? []) restore();
|
|
230
|
+
state.styles = void 0;
|
|
231
|
+
}
|
|
232
|
+
function stopIcon(icon) {
|
|
233
|
+
const state = states.get(icon);
|
|
234
|
+
if (!state) return;
|
|
235
|
+
state.fade?.stop();
|
|
236
|
+
clear(state);
|
|
237
|
+
state.restorePlacement?.();
|
|
238
|
+
states.delete(icon);
|
|
239
|
+
}
|
|
240
|
+
function leave$1(icon, kind, reducedMotion, done) {
|
|
241
|
+
const state = stateOf(icon);
|
|
242
|
+
state.fade?.stop();
|
|
243
|
+
clear(state);
|
|
244
|
+
state.leaving = true;
|
|
245
|
+
const [x, y] = kind === "blur" ? [0, 0] : directions[kind];
|
|
246
|
+
state.fade = tween(state.shown, 0, {
|
|
247
|
+
duration: reducedMotion ? crossfade$2 : exit.duration,
|
|
248
|
+
ease: reducedMotion ? easeOut : easeIn
|
|
249
|
+
}, (value) => {
|
|
250
|
+
state.shown = value;
|
|
251
|
+
const gone = 1 - value;
|
|
252
|
+
paintIcon(icon, state, {
|
|
253
|
+
opacity: String(value),
|
|
254
|
+
...reducedMotion ? {} : kind === "blur" ? {
|
|
255
|
+
filter: `blur(${(exit.blur * gone).toFixed(2)}px)`,
|
|
256
|
+
scale: String(1 - (1 - exit.scale) * gone)
|
|
257
|
+
} : { translate: `${x * exit.travel * gone}px ${y * exit.travel * gone}px` }
|
|
258
|
+
});
|
|
259
|
+
}, () => {
|
|
260
|
+
state.fade = void 0;
|
|
261
|
+
done();
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
function come(icon, kind, reducedMotion, from) {
|
|
265
|
+
const state = stateOf(icon);
|
|
266
|
+
state.fade?.stop();
|
|
267
|
+
state.restorePlacement?.();
|
|
268
|
+
state.restorePlacement = void 0;
|
|
269
|
+
state.leaving = false;
|
|
270
|
+
clear(state);
|
|
271
|
+
const stroke = kind === "draw" && !reducedMotion ? strokes(icon) : void 0;
|
|
272
|
+
state.stroke = stroke?.shape;
|
|
273
|
+
const finish = () => {
|
|
274
|
+
state.fade = void 0;
|
|
275
|
+
state.shown = 1;
|
|
276
|
+
clear(state);
|
|
277
|
+
};
|
|
278
|
+
if (reducedMotion) {
|
|
279
|
+
state.fade = tween(from, 1, {
|
|
280
|
+
duration: crossfade$2,
|
|
281
|
+
ease: easeOut
|
|
282
|
+
}, (value) => {
|
|
283
|
+
state.shown = value;
|
|
284
|
+
paintIcon(icon, state, { opacity: String(value) });
|
|
285
|
+
}, finish);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (stroke) {
|
|
289
|
+
const { shape, parts } = stroke;
|
|
290
|
+
for (const part of parts) {
|
|
291
|
+
shape.set(part, "pathLength", "1");
|
|
292
|
+
shape.set(part, "stroke-dasharray", "1");
|
|
293
|
+
shape.set(part, "stroke-dashoffset", "1");
|
|
294
|
+
}
|
|
295
|
+
shape.commit();
|
|
296
|
+
const spins = icon.matches(".animate-spin") || !!icon.querySelector(".animate-spin");
|
|
297
|
+
state.shown = 1;
|
|
298
|
+
state.fade = tween(1, 0, {
|
|
299
|
+
duration: spins ? draw.spinner : draw.duration,
|
|
300
|
+
delay: draw.delay,
|
|
301
|
+
ease: draw.ease
|
|
302
|
+
}, (value) => {
|
|
303
|
+
for (const part of parts) shape.set(part, "stroke-dashoffset", String(value));
|
|
304
|
+
shape.commit();
|
|
305
|
+
}, finish);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const effective = kind === "draw" ? "blur" : kind;
|
|
309
|
+
if (effective === "blur") {
|
|
310
|
+
state.fade = tween(from, 1, {
|
|
311
|
+
duration: enterBlur.duration,
|
|
312
|
+
delay: from ? 0 : enterBlur.delay,
|
|
313
|
+
ease: enterBlur.ease
|
|
314
|
+
}, (value) => {
|
|
315
|
+
state.shown = Math.min(1, value);
|
|
316
|
+
const gone = 1 - value;
|
|
317
|
+
paintIcon(icon, state, {
|
|
318
|
+
opacity: String(Math.min(1, Math.max(0, value))),
|
|
319
|
+
filter: `blur(${Math.max(0, enterBlur.blur * gone).toFixed(2)}px)`,
|
|
320
|
+
scale: String(1 - (1 - enterBlur.scale) * gone)
|
|
321
|
+
});
|
|
322
|
+
}, finish);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const [x, y] = directions[effective];
|
|
326
|
+
state.fade = tween(from, 1, {
|
|
327
|
+
duration: enterSlide.duration,
|
|
328
|
+
delay: from ? 0 : enterSlide.delay,
|
|
329
|
+
ease: enterSlide.ease
|
|
330
|
+
}, (value) => {
|
|
331
|
+
state.shown = value;
|
|
332
|
+
const gone = 1 - value;
|
|
333
|
+
paintIcon(icon, state, {
|
|
334
|
+
opacity: String(Math.min(1, value)),
|
|
335
|
+
translate: `${-x * enterSlide.travel * gone}px ${-y * enterSlide.travel * gone}px`
|
|
336
|
+
});
|
|
337
|
+
}, finish);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Swaps the icon in `container` for `icon`, as rule 5 of docs/design/motion.md asks: the old icon blurs out, or leaves in
|
|
341
|
+
* the direction it points, while the new one comes in, and a spinner or a check draws its stroke. `icon` may already be
|
|
342
|
+
* a child of `container`, as when a framework renders it; else the helper appends it. Every other icon in the container
|
|
343
|
+
* leaves, and is removed when it is gone.
|
|
344
|
+
*
|
|
345
|
+
* Call it again at any time: an icon that is still coming in leaves from where it is. Under reduced motion the icons
|
|
346
|
+
* crossfade in 150ms. Inside `data-motion="none"` the old icons go at once.
|
|
347
|
+
*/
|
|
348
|
+
function swapIcon(container, icon, options = {}) {
|
|
349
|
+
const remove = options.onRemove ?? ((old) => old.remove());
|
|
350
|
+
if (icon.parentNode !== container) container.append(icon);
|
|
351
|
+
const known = states.get(icon);
|
|
352
|
+
const others = [...container.children].filter((child) => child !== icon && !states.get(child)?.leaving);
|
|
353
|
+
const leavingNow = [...container.children].filter((child) => child !== icon && states.get(child)?.leaving);
|
|
354
|
+
if (motionSkipped(container)) {
|
|
355
|
+
for (const old of [...others, ...leavingNow]) {
|
|
356
|
+
stopIcon(old);
|
|
357
|
+
remove(old);
|
|
358
|
+
}
|
|
359
|
+
stopIcon(icon);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (!others.length && (known ? !known.leaving : !leavingNow.length)) {
|
|
363
|
+
stateOf(icon);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const placed = others.map((old) => ({
|
|
367
|
+
old,
|
|
368
|
+
at: offsetIn(container, old)
|
|
369
|
+
}));
|
|
370
|
+
for (const { old, at } of placed) leaveIcon(container, old, at, options.exit ?? "blur", remove);
|
|
371
|
+
enterIcon(icon, options.enter, known ? known.shown : 0);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Takes `old` out of the flow at `at`, a place in the padding box of `container`, and plays its exit. `remove` runs when
|
|
375
|
+
* it is gone. The label effect of the layer uses it for a copy of the icon that Vue already replaced.
|
|
376
|
+
*/
|
|
377
|
+
function leaveIcon(container, old, at, exit, remove) {
|
|
378
|
+
const reducedMotion = reduced();
|
|
379
|
+
let position = positioned.get(container);
|
|
380
|
+
if (!position && getComputedStyle(container).position === "static") {
|
|
381
|
+
position = {
|
|
382
|
+
exits: 0,
|
|
383
|
+
restore: saveStyle(container.style, "position")
|
|
384
|
+
};
|
|
385
|
+
positioned.set(container, position);
|
|
386
|
+
container.style.position = "relative";
|
|
387
|
+
}
|
|
388
|
+
if (position) position.exits++;
|
|
389
|
+
const restores = [];
|
|
390
|
+
if (styled(old)) {
|
|
391
|
+
const placement = {
|
|
392
|
+
position: "absolute",
|
|
393
|
+
left: `${at.left}px`,
|
|
394
|
+
top: `${at.top}px`,
|
|
395
|
+
"pointer-events": "none",
|
|
396
|
+
"margin-top": "0",
|
|
397
|
+
"margin-right": "0",
|
|
398
|
+
"margin-bottom": "0",
|
|
399
|
+
"margin-left": "0"
|
|
400
|
+
};
|
|
401
|
+
for (const [property, value] of Object.entries(placement)) {
|
|
402
|
+
restores.push(saveStyle(old.style, property));
|
|
403
|
+
old.style.setProperty(property, value);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
const hidden = old.getAttribute("aria-hidden");
|
|
407
|
+
old.setAttribute("aria-hidden", "true");
|
|
408
|
+
stateOf(old).restorePlacement = () => {
|
|
409
|
+
for (const restore of restores) restore();
|
|
410
|
+
if (hidden === null) old.removeAttribute("aria-hidden");
|
|
411
|
+
else old.setAttribute("aria-hidden", hidden);
|
|
412
|
+
if (position && --position.exits === 0) {
|
|
413
|
+
position.restore();
|
|
414
|
+
positioned.delete(container);
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
leave$1(old, exit, reducedMotion, () => {
|
|
418
|
+
stopIcon(old);
|
|
419
|
+
remove(old);
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
/** Plays the entrance of `icon` from `from` (0 for a new icon). The default draws a spinning icon and blurs in others. */
|
|
423
|
+
function enterIcon(icon, enter, from) {
|
|
424
|
+
const spins = icon.matches(".animate-spin") || !!icon.querySelector(".animate-spin");
|
|
425
|
+
come(icon, enter ?? (spins ? "draw" : "blur"), reduced(), from);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Where `child` sits in the padding box of `container`, in layout pixels. An SVG has no `offsetLeft`, and a press may
|
|
429
|
+
* scale the button around both, so it divides the distance on screen by that scale.
|
|
430
|
+
*/
|
|
431
|
+
function offsetIn(container, child) {
|
|
432
|
+
const outer = container.getBoundingClientRect();
|
|
433
|
+
const inner = child.getBoundingClientRect();
|
|
434
|
+
const scale = container.offsetWidth ? outer.width / container.offsetWidth : 1;
|
|
435
|
+
return {
|
|
436
|
+
left: (inner.left - outer.left) / (scale || 1) - container.clientLeft,
|
|
437
|
+
top: (inner.top - outer.top) / (scale || 1) - container.clientTop
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
//#endregion
|
|
441
|
+
//#region src/motion/helpers/number.ts
|
|
442
|
+
const travel = 1;
|
|
443
|
+
const blur$1 = 2;
|
|
444
|
+
const out = {
|
|
445
|
+
duration: 240,
|
|
446
|
+
ease: easeIn
|
|
447
|
+
};
|
|
448
|
+
const into = {
|
|
449
|
+
duration: 380,
|
|
450
|
+
delay: 60,
|
|
451
|
+
ease: cubicBezier(.3, 1.4, .5, 1)
|
|
452
|
+
};
|
|
453
|
+
const crossfade$1 = 150;
|
|
454
|
+
const rolls = /* @__PURE__ */ new WeakMap();
|
|
455
|
+
const values = /* @__PURE__ */ new WeakMap();
|
|
456
|
+
function glyph(char) {
|
|
457
|
+
const node = glyphNode(char);
|
|
458
|
+
node.style.gridArea = "1 / 1";
|
|
459
|
+
return {
|
|
460
|
+
node,
|
|
461
|
+
shown: 1
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
function column(char) {
|
|
465
|
+
const node = own(document.createElement("span"));
|
|
466
|
+
node.style.cssText = "display:inline-grid;overflow:hidden;justify-items:center";
|
|
467
|
+
const current = char ? glyph(char) : void 0;
|
|
468
|
+
if (current) node.append(current.node);
|
|
469
|
+
return {
|
|
470
|
+
node,
|
|
471
|
+
char,
|
|
472
|
+
current,
|
|
473
|
+
leaving: /* @__PURE__ */ new Set()
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function paint$1(item, value, direction, reducedMotion) {
|
|
477
|
+
item.shown = value;
|
|
478
|
+
const gone = 1 - value;
|
|
479
|
+
writeMotionStyle(item.node, {
|
|
480
|
+
opacity: value >= 1 ? null : String(Math.max(0, value)),
|
|
481
|
+
filter: reducedMotion || value >= 1 ? null : `blur(${Math.max(0, blur$1 * gone).toFixed(2)}px)`,
|
|
482
|
+
scale: reducedMotion || value === 1 ? null : String(1 - .44999999999999996 * gone),
|
|
483
|
+
translate: reducedMotion || value === 1 ? null : `0 ${(direction * travel * gone).toFixed(3)}em`
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
function idle(roll) {
|
|
487
|
+
return !roll.frame.width.active && roll.columns.every((item) => !item.leaving.size && !item.current?.fade);
|
|
488
|
+
}
|
|
489
|
+
function finishIfIdle$1(element, roll) {
|
|
490
|
+
if (rolls.get(element) !== roll || !idle(roll)) return;
|
|
491
|
+
rolls.delete(element);
|
|
492
|
+
roll.frame.collapse(roll.text);
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Rolls the number in `element` to `value`, as rule 6 of docs/design/motion.md asks: only the digits that change roll,
|
|
496
|
+
* up when the number grows and down when it shrinks. The width of the element follows with a spring. `format` turns the
|
|
497
|
+
* number into its text, such as `n => n.toLocaleString()`. The default is `String`.
|
|
498
|
+
*
|
|
499
|
+
* Call it again at any time: a digit that is still rolling in rolls out from where it is. The element keeps the final
|
|
500
|
+
* text for screen readers, and holds plain text again when the roll ends. Under reduced motion the changed digits
|
|
501
|
+
* crossfade in 150ms. Inside `data-motion="none"`, or before the element is on the page, it sets the text at once.
|
|
502
|
+
*/
|
|
503
|
+
function rollNumber(element, value, format = String) {
|
|
504
|
+
const text = format(value);
|
|
505
|
+
let roll = rolls.get(element);
|
|
506
|
+
const before = roll?.text ?? element.textContent ?? "";
|
|
507
|
+
const previous = roll?.value ?? values.get(element) ?? parseCount(before);
|
|
508
|
+
values.set(element, value);
|
|
509
|
+
if (previous === void 0 || !roll && before === text || glyphMotionSkipped(element)) {
|
|
510
|
+
if (roll) {
|
|
511
|
+
for (const item of roll.columns) for (const g of [item.current, ...item.leaving]) g?.fade?.stop();
|
|
512
|
+
rolls.delete(element);
|
|
513
|
+
}
|
|
514
|
+
setText(element, text);
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
const direction = value > previous ? 1 : value < previous ? -1 : 0;
|
|
518
|
+
const reducedMotion = reduced();
|
|
519
|
+
if (!roll) {
|
|
520
|
+
const frame = frameOf(element) ?? openFrame(element, "end", () => {
|
|
521
|
+
const running = rolls.get(element);
|
|
522
|
+
if (running) finishIfIdle$1(element, running);
|
|
523
|
+
});
|
|
524
|
+
const columns = [...before].map(column);
|
|
525
|
+
frame.holder.append(...columns.map((item) => item.node));
|
|
526
|
+
frame.width.set(frame.natural());
|
|
527
|
+
roll = {
|
|
528
|
+
frame,
|
|
529
|
+
text: before,
|
|
530
|
+
value: previous,
|
|
531
|
+
columns
|
|
532
|
+
};
|
|
533
|
+
rolls.set(element, roll);
|
|
534
|
+
}
|
|
535
|
+
const state = roll;
|
|
536
|
+
state.frame.restore();
|
|
537
|
+
state.text = text;
|
|
538
|
+
state.value = value;
|
|
539
|
+
state.frame.name(text);
|
|
540
|
+
const chars = [...text];
|
|
541
|
+
const count = Math.max(chars.length, state.columns.length);
|
|
542
|
+
while (state.columns.length < count) {
|
|
543
|
+
const added = column("");
|
|
544
|
+
state.frame.holder.prepend(added.node);
|
|
545
|
+
state.columns.unshift(added);
|
|
546
|
+
}
|
|
547
|
+
const offset = count - chars.length;
|
|
548
|
+
state.columns.forEach((item, index) => {
|
|
549
|
+
const next = chars[index - offset] ?? "";
|
|
550
|
+
if (next === item.char) return;
|
|
551
|
+
item.char = next;
|
|
552
|
+
const old = item.current;
|
|
553
|
+
if (old) {
|
|
554
|
+
old.fade?.stop();
|
|
555
|
+
item.leaving.add(old);
|
|
556
|
+
old.fade = tween(old.shown, 0, reducedMotion ? {
|
|
557
|
+
duration: crossfade$1,
|
|
558
|
+
ease: easeOut
|
|
559
|
+
} : out, (v) => paint$1(old, v, -direction, reducedMotion), () => {
|
|
560
|
+
old.fade = void 0;
|
|
561
|
+
old.node.remove();
|
|
562
|
+
item.leaving.delete(old);
|
|
563
|
+
settleColumns(element, state);
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
item.current = void 0;
|
|
567
|
+
if (!next) return;
|
|
568
|
+
const incoming = glyph(next);
|
|
569
|
+
item.current = incoming;
|
|
570
|
+
item.node.append(incoming.node);
|
|
571
|
+
paint$1(incoming, 0, direction, reducedMotion);
|
|
572
|
+
incoming.fade = tween(0, 1, reducedMotion ? {
|
|
573
|
+
duration: crossfade$1,
|
|
574
|
+
ease: easeOut
|
|
575
|
+
} : into, (v) => paint$1(incoming, v, direction, reducedMotion), () => {
|
|
576
|
+
incoming.fade = void 0;
|
|
577
|
+
paint$1(incoming, 1, direction, reducedMotion);
|
|
578
|
+
settleColumns(element, state);
|
|
579
|
+
});
|
|
580
|
+
});
|
|
581
|
+
const width = state.frame.width;
|
|
582
|
+
const leavingColumns = state.columns.filter((item) => !item.char);
|
|
583
|
+
for (const item of leavingColumns) item.node.style.display = "none";
|
|
584
|
+
const end = state.frame.natural();
|
|
585
|
+
for (const item of leavingColumns) item.node.style.display = "inline-grid";
|
|
586
|
+
if (reducedMotion) width.set(end);
|
|
587
|
+
else width.to(end);
|
|
588
|
+
}
|
|
589
|
+
function parseCount(text) {
|
|
590
|
+
const digits = text.replace(/[^\d.-]/g, "");
|
|
591
|
+
const value = digits ? Number(digits) : NaN;
|
|
592
|
+
return Number.isFinite(value) ? value : void 0;
|
|
593
|
+
}
|
|
594
|
+
function settleColumns(element, roll) {
|
|
595
|
+
if (rolls.get(element) !== roll) return;
|
|
596
|
+
roll.columns = roll.columns.filter((item) => {
|
|
597
|
+
if (item.char || item.leaving.size) return true;
|
|
598
|
+
item.node.remove();
|
|
599
|
+
return false;
|
|
600
|
+
});
|
|
601
|
+
finishIfIdle$1(element, roll);
|
|
602
|
+
}
|
|
603
|
+
//#endregion
|
|
604
|
+
//#region src/motion/helpers/text.ts
|
|
605
|
+
/** Splits a change of label into the shared start, the old letters after it, and the new letters after it. */
|
|
606
|
+
function diffText(from, to) {
|
|
607
|
+
const a = [...from];
|
|
608
|
+
const b = [...to];
|
|
609
|
+
let index = 0;
|
|
610
|
+
while (index < a.length && index < b.length && a[index] === b[index]) index++;
|
|
611
|
+
return {
|
|
612
|
+
kept: a.slice(0, index).join(""),
|
|
613
|
+
gone: a.slice(index).join(""),
|
|
614
|
+
typed: b.slice(index).join("")
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
const blur = 6;
|
|
618
|
+
const leave = {
|
|
619
|
+
duration: 200,
|
|
620
|
+
stagger: 30
|
|
621
|
+
};
|
|
622
|
+
const type = {
|
|
623
|
+
duration: 240,
|
|
624
|
+
lead: 30,
|
|
625
|
+
stagger: 55
|
|
626
|
+
};
|
|
627
|
+
const crossfade = 150;
|
|
628
|
+
const morphs = /* @__PURE__ */ new WeakMap();
|
|
629
|
+
/** The text that the element shows or moves to, when a morph runs on it. */
|
|
630
|
+
function morphTarget(element) {
|
|
631
|
+
return morphs.get(element)?.text;
|
|
632
|
+
}
|
|
633
|
+
function paint(letter, value, reducedMotion) {
|
|
634
|
+
letter.shown = value;
|
|
635
|
+
writeMotionStyle(letter.node, {
|
|
636
|
+
opacity: value >= 1 ? null : String(value),
|
|
637
|
+
filter: reducedMotion || value >= 1 ? null : `blur(${(blur * (1 - value)).toFixed(2)}px)`
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
function letterNode(char) {
|
|
641
|
+
return glyphNode(char);
|
|
642
|
+
}
|
|
643
|
+
function finishIfIdle(element, morph) {
|
|
644
|
+
if (morphs.get(element) !== morph) return;
|
|
645
|
+
if (morph.leaving.size || morph.timers.size || morph.frame.width.active || morph.letters.some((letter) => letter.fade || letter.waiting)) return;
|
|
646
|
+
morphs.delete(element);
|
|
647
|
+
morph.frame.collapse(morph.text);
|
|
648
|
+
}
|
|
649
|
+
function stopAll(morph) {
|
|
650
|
+
for (const timer of morph.timers) clearTimeout(timer);
|
|
651
|
+
morph.timers.clear();
|
|
652
|
+
for (const letter of [...morph.letters, ...morph.leaving]) letter.fade?.stop();
|
|
653
|
+
}
|
|
654
|
+
function discardMorph(element) {
|
|
655
|
+
const current = morphs.get(element);
|
|
656
|
+
if (!current) return;
|
|
657
|
+
stopAll(current);
|
|
658
|
+
morphs.delete(element);
|
|
659
|
+
current.frame.discard();
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Changes the text of `element` letter by letter, as rule 4 of docs/design/motion.md asks: the letters that the old and
|
|
663
|
+
* new text share at the start stay, the other old letters blur out where they are, and the new letters type in one at
|
|
664
|
+
* a time with a short blur. The width of the element follows the letters with a spring and never jumps.
|
|
665
|
+
*
|
|
666
|
+
* Call it again at any time: a new text continues from the letters on screen. The element keeps the final text for
|
|
667
|
+
* screen readers during the morph, and holds plain text again when it ends. Under reduced motion the two texts
|
|
668
|
+
* crossfade in 150ms. Inside `data-motion="none"`, or when the element has no layout, it sets the text at once.
|
|
669
|
+
*
|
|
670
|
+
* Give it an element of its own with no padding, such as the label `<span>` of a button.
|
|
671
|
+
*/
|
|
672
|
+
function morphText(element, text) {
|
|
673
|
+
morph(element, text, void 0);
|
|
674
|
+
}
|
|
675
|
+
function hasLayout(element) {
|
|
676
|
+
let node = element;
|
|
677
|
+
while (node) {
|
|
678
|
+
if (node.getClientRects().length) return true;
|
|
679
|
+
if (getComputedStyle(node).display !== "contents") return false;
|
|
680
|
+
const root = node.getRootNode();
|
|
681
|
+
node = node.parentElement ?? (root instanceof ShadowRoot ? root.host : null);
|
|
682
|
+
}
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* The morph of `morphText`. `from` is the text that the element showed before, when the app already wrote the new text
|
|
687
|
+
* into the element, as Vue does with the label of a button.
|
|
688
|
+
*/
|
|
689
|
+
function morph(element, text, from) {
|
|
690
|
+
let current = morphs.get(element);
|
|
691
|
+
const before = current?.text ?? from ?? element.textContent ?? "";
|
|
692
|
+
if (!current && before === text || glyphMotionSkipped(element) || !hasLayout(element)) {
|
|
693
|
+
if (current) {
|
|
694
|
+
stopAll(current);
|
|
695
|
+
morphs.delete(element);
|
|
696
|
+
}
|
|
697
|
+
setText(element, text);
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
const reducedMotion = reduced();
|
|
701
|
+
if (!current) {
|
|
702
|
+
const frame = frameOf(element) ?? openFrame(element, "inline", () => {
|
|
703
|
+
const running = morphs.get(element);
|
|
704
|
+
if (running) finishIfIdle(element, running);
|
|
705
|
+
});
|
|
706
|
+
const letters = [...before].map((char) => ({
|
|
707
|
+
node: letterNode(char),
|
|
708
|
+
char,
|
|
709
|
+
shown: 1,
|
|
710
|
+
waiting: false
|
|
711
|
+
}));
|
|
712
|
+
frame.holder.append(...letters.map((letter) => letter.node));
|
|
713
|
+
frame.width.set(frame.natural());
|
|
714
|
+
current = {
|
|
715
|
+
frame,
|
|
716
|
+
text: before,
|
|
717
|
+
letters,
|
|
718
|
+
leaving: /* @__PURE__ */ new Set(),
|
|
719
|
+
timers: /* @__PURE__ */ new Set()
|
|
720
|
+
};
|
|
721
|
+
morphs.set(element, current);
|
|
722
|
+
}
|
|
723
|
+
const state = current;
|
|
724
|
+
const width = state.frame.width;
|
|
725
|
+
state.frame.restore();
|
|
726
|
+
for (const timer of state.timers) clearTimeout(timer);
|
|
727
|
+
state.timers.clear();
|
|
728
|
+
state.text = text;
|
|
729
|
+
state.frame.name(text);
|
|
730
|
+
if (reducedMotion) {
|
|
731
|
+
leaveLetters(state, state.letters, true);
|
|
732
|
+
state.letters = [...text].map((char) => {
|
|
733
|
+
const letter = {
|
|
734
|
+
node: letterNode(char),
|
|
735
|
+
char,
|
|
736
|
+
shown: 0,
|
|
737
|
+
waiting: false
|
|
738
|
+
};
|
|
739
|
+
paint(letter, 0, true);
|
|
740
|
+
state.frame.holder.append(letter.node);
|
|
741
|
+
return letter;
|
|
742
|
+
});
|
|
743
|
+
width.set(state.frame.natural());
|
|
744
|
+
for (const letter of state.letters) fadeIn(element, state, letter, 0, crossfade, true);
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
const diff = diffText(state.letters.map((letter) => letter.char).join(""), text);
|
|
748
|
+
const keptCount = [...diff.kept].length;
|
|
749
|
+
const kept = state.letters.slice(0, keptCount);
|
|
750
|
+
leaveLetters(state, state.letters.slice(keptCount), false);
|
|
751
|
+
const typing = [...kept.filter((letter) => letter.waiting), ...[...diff.typed].map((char) => {
|
|
752
|
+
const letter = {
|
|
753
|
+
node: letterNode(char),
|
|
754
|
+
char,
|
|
755
|
+
shown: 0,
|
|
756
|
+
waiting: true
|
|
757
|
+
};
|
|
758
|
+
paint(letter, 0, false);
|
|
759
|
+
state.frame.holder.append(letter.node);
|
|
760
|
+
return letter;
|
|
761
|
+
})];
|
|
762
|
+
state.letters = [...kept, ...typing.filter((letter) => !kept.includes(letter))];
|
|
763
|
+
const end = state.frame.natural();
|
|
764
|
+
if (!typing.length) {
|
|
765
|
+
width.to(end);
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
const start = width.value;
|
|
769
|
+
let step = end - typing.reduce((sum, letter) => sum + letter.node.offsetWidth, 0);
|
|
770
|
+
const slow = getMotionSlowFactor();
|
|
771
|
+
typing.forEach((letter, index) => {
|
|
772
|
+
step += letter.node.offsetWidth;
|
|
773
|
+
const target = index === typing.length - 1 ? end : Math.max(step, index === 0 ? Math.min(start, end) : 0);
|
|
774
|
+
const timer = setTimeout(() => {
|
|
775
|
+
state.timers.delete(timer);
|
|
776
|
+
letter.waiting = false;
|
|
777
|
+
width.to(target);
|
|
778
|
+
fadeIn(element, state, letter, letter.shown, type.duration, false);
|
|
779
|
+
}, (type.lead + index * type.stagger) * slow);
|
|
780
|
+
state.timers.add(timer);
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
function fadeIn(element, state, letter, from, duration, reducedMotion) {
|
|
784
|
+
letter.fade?.stop();
|
|
785
|
+
letter.fade = tween(from, 1, {
|
|
786
|
+
duration,
|
|
787
|
+
ease: easeOut
|
|
788
|
+
}, (value) => paint(letter, value, reducedMotion), () => {
|
|
789
|
+
letter.fade = void 0;
|
|
790
|
+
paint(letter, 1, reducedMotion);
|
|
791
|
+
finishIfIdle(element, state);
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
function leaveLetters(state, letters, reducedMotion) {
|
|
795
|
+
const element = state.frame.element;
|
|
796
|
+
const placed = letters.map((letter) => ({
|
|
797
|
+
letter,
|
|
798
|
+
left: letter.node.offsetLeft,
|
|
799
|
+
top: letter.node.offsetTop
|
|
800
|
+
}));
|
|
801
|
+
let order = 0;
|
|
802
|
+
for (const { letter, left, top } of placed) {
|
|
803
|
+
letter.fade?.stop();
|
|
804
|
+
letter.fade = void 0;
|
|
805
|
+
if (letter.waiting || letter.shown <= 0) {
|
|
806
|
+
letter.node.remove();
|
|
807
|
+
continue;
|
|
808
|
+
}
|
|
809
|
+
letter.node.style.position = "absolute";
|
|
810
|
+
letter.node.style.left = `${left}px`;
|
|
811
|
+
letter.node.style.top = `${top}px`;
|
|
812
|
+
state.leaving.add(letter);
|
|
813
|
+
letter.fade = tween(letter.shown, 0, {
|
|
814
|
+
duration: reducedMotion ? crossfade : leave.duration,
|
|
815
|
+
delay: reducedMotion ? 0 : order++ * leave.stagger,
|
|
816
|
+
ease: reducedMotion ? easeOut : easeIn
|
|
817
|
+
}, (value) => paint(letter, value, reducedMotion), () => {
|
|
818
|
+
letter.fade = void 0;
|
|
819
|
+
letter.node.remove();
|
|
820
|
+
state.leaving.delete(letter);
|
|
821
|
+
finishIfIdle(element, state);
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
//#endregion
|
|
826
|
+
export { rollNumber as a, offsetIn as c, iconShape as d, morphText as i, swapIcon as l, morph as n, enterIcon as o, morphTarget as r, leaveIcon as s, discardMorph as t, findIcons as u };
|