@pieai/swimmer-ui-kit 2.7.2 → 2.9.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/CHANGELOG.md +18 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2102 -2539
- package/dist/liquid-presence.css +1 -0
- package/dist/liquid-presence.d.ts +44 -0
- package/dist/liquid-presence.js +689 -0
- package/dist/reducedMotion-C7O9ls34.js +450 -0
- package/package.json +6 -1
|
@@ -0,0 +1,689 @@
|
|
|
1
|
+
import { _ as e, d as t, h as n, i as r, m as i, n as a, t as o } from "./reducedMotion-C7O9ls34.js";
|
|
2
|
+
import { useEffect as s, useId as c, useRef as l, useState as u } from "react";
|
|
3
|
+
import { createPortal as d } from "react-dom";
|
|
4
|
+
import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
5
|
+
import { autoUpdate as h, computePosition as g, flip as _, offset as v, shift as y } from "@floating-ui/react";
|
|
6
|
+
function b(e, t, n) {
|
|
7
|
+
return Number.isFinite(e) ? Math.max(t, Math.min(n, e)) : t;
|
|
8
|
+
}
|
|
9
|
+
function x(e) {
|
|
10
|
+
return !!(e && [
|
|
11
|
+
e.x,
|
|
12
|
+
e.y,
|
|
13
|
+
e.width,
|
|
14
|
+
e.height
|
|
15
|
+
].every(Number.isFinite) && e.width > 0 && e.height > 0);
|
|
16
|
+
}
|
|
17
|
+
function S(e, t) {
|
|
18
|
+
return x(e) && e.x + e.width > t.x && e.y + e.height > t.y && e.x < t.x + t.width && e.y < t.y + t.height;
|
|
19
|
+
}
|
|
20
|
+
function C(e) {
|
|
21
|
+
return {
|
|
22
|
+
x: e.x + e.width / 2,
|
|
23
|
+
y: e.y + e.height / 2
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function w(e, t) {
|
|
27
|
+
let n = Math.hypot(t.x - e.x, t.y - e.y) || 1;
|
|
28
|
+
return {
|
|
29
|
+
x: (t.x - e.x) / n,
|
|
30
|
+
y: (t.y - e.y) / n
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function ee(e, t) {
|
|
34
|
+
let n = Math.max(e.x, t.x), r = Math.max(e.y, t.y);
|
|
35
|
+
return {
|
|
36
|
+
x: n,
|
|
37
|
+
y: r,
|
|
38
|
+
width: Math.max(0, Math.min(e.x + e.width, t.x + t.width) - n),
|
|
39
|
+
height: Math.max(0, Math.min(e.y + e.height, t.y + t.height) - r)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function te(e, t) {
|
|
43
|
+
let n = e.y + e.height + 88 < t.y + t.height, r = n ? "bottom" : "top", i = Math.max(t.x + 18, e.x), a = Math.min(t.x + t.width - 18, e.x + e.width), o = b(Math.max(0, a - i) * .58, 36, 84);
|
|
44
|
+
return {
|
|
45
|
+
x: b((i + a) / 2, t.x + o / 2 + 8, t.x + t.width - o / 2 - 8),
|
|
46
|
+
y: b(n ? e.y + e.height + 10 : e.y - 10, t.y + 18, t.y + t.height - 18),
|
|
47
|
+
side: r,
|
|
48
|
+
width: o
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function T(e, t, n, r) {
|
|
52
|
+
let i = b(n, 0, 1), a = w(e, t), o = Math.min(86, Math.hypot(t.x - e.x, t.y - e.y) * .2), s = {
|
|
53
|
+
x: b((e.x + t.x) / 2 + a.y * o, r.x + 16, r.x + r.width - 16),
|
|
54
|
+
y: b((e.y + t.y) / 2 - a.x * o, r.y + 16, r.y + r.height - 16)
|
|
55
|
+
}, c = 2 * (1 - i) * (s.x - e.x) + 2 * i * (t.x - s.x), l = 2 * (1 - i) * (s.y - e.y) + 2 * i * (t.y - s.y);
|
|
56
|
+
return {
|
|
57
|
+
x: (1 - i) ** 2 * e.x + 2 * (1 - i) * i * s.x + i ** 2 * t.x,
|
|
58
|
+
y: (1 - i) ** 2 * e.y + 2 * (1 - i) * i * s.y + i ** 2 * t.y,
|
|
59
|
+
angle: Math.atan2(l, c) * 180 / Math.PI
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function E(e = 0, t = 0, n = 0) {
|
|
63
|
+
let i = 66 * Math.sqrt(1 - .075 * b(n, 0, 1));
|
|
64
|
+
return r(80 - i, 80 - i, i * 2, i * 2, [
|
|
65
|
+
i,
|
|
66
|
+
i,
|
|
67
|
+
i,
|
|
68
|
+
i
|
|
69
|
+
], {
|
|
70
|
+
amplitude: 3.5 + b(t, 0, 1) * 9,
|
|
71
|
+
lobes: 3,
|
|
72
|
+
seed: 17,
|
|
73
|
+
phase: e
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function D(e, t, n = 20) {
|
|
77
|
+
let i = b(t, 0, 1), a = b(n, 6, 48), o = a + (e - a) * i, s = a + (8 - a) * i;
|
|
78
|
+
return r(-o / 2, -s / 2, o, s, [
|
|
79
|
+
s / 2,
|
|
80
|
+
s / 2,
|
|
81
|
+
s / 2,
|
|
82
|
+
s / 2
|
|
83
|
+
], {
|
|
84
|
+
amplitude: 2.2,
|
|
85
|
+
phase: i * Math.PI,
|
|
86
|
+
seed: 17,
|
|
87
|
+
lobes: 3
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/liquidPresenceMotion.ts
|
|
92
|
+
var O = a("cubic-bezier(0.45, 0, 0.2, 1)");
|
|
93
|
+
function ne(e) {
|
|
94
|
+
let { source: t, destination: n, viewport: r, returning: i = !1, from: a, origin: o } = e, s = o?.seat == null ? 0 : 180;
|
|
95
|
+
if (s && e.elapsed < s) return {
|
|
96
|
+
...o,
|
|
97
|
+
phase: "gather",
|
|
98
|
+
seat: o.seat * (1 - O(b(e.elapsed / s, 0, 1)))
|
|
99
|
+
};
|
|
100
|
+
let c = Math.max(0, e.elapsed - s), l = C(t), u = w(l, n), d = Math.atan2(u.y, u.x) * 180 / Math.PI, f = t.width / 160, p = {
|
|
101
|
+
x: l.x + u.x * 112 * f,
|
|
102
|
+
y: l.y + u.y * 112 * f
|
|
103
|
+
}, m = {
|
|
104
|
+
phase: "still",
|
|
105
|
+
point: l,
|
|
106
|
+
angle: d,
|
|
107
|
+
diameter: 16 * f * 2,
|
|
108
|
+
stretch: 1,
|
|
109
|
+
separation: 0,
|
|
110
|
+
bud: null,
|
|
111
|
+
seat: null
|
|
112
|
+
};
|
|
113
|
+
if (i) {
|
|
114
|
+
if (o?.bud) {
|
|
115
|
+
let e = O(b(c / 320, 0, 1)), t = o.bud.x + (80 - o.bud.x) * e, n = o.bud.y + (80 - o.bud.y) * e;
|
|
116
|
+
return {
|
|
117
|
+
...m,
|
|
118
|
+
phase: e < 1 ? "merge" : "still",
|
|
119
|
+
separation: o.separation * (1 - e),
|
|
120
|
+
point: {
|
|
121
|
+
x: l.x + (t - 80) * f,
|
|
122
|
+
y: l.y + (n - 80) * f
|
|
123
|
+
},
|
|
124
|
+
bud: e < 1 ? {
|
|
125
|
+
x: t,
|
|
126
|
+
y: n,
|
|
127
|
+
radius: o.bud.radius * (1 - e)
|
|
128
|
+
} : null
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
let e = b(c / 620, 0, 1);
|
|
132
|
+
if (e < 1) {
|
|
133
|
+
let t = T(a ?? n, p, O(e), r);
|
|
134
|
+
return {
|
|
135
|
+
...m,
|
|
136
|
+
phase: "return",
|
|
137
|
+
separation: 1,
|
|
138
|
+
angle: t.angle,
|
|
139
|
+
point: t,
|
|
140
|
+
stretch: 1 + .3 * Math.sin(e * Math.PI)
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
let t = b((c - 620) / 420, 0, 1), i = 112 - 78 * O(t);
|
|
144
|
+
return {
|
|
145
|
+
...m,
|
|
146
|
+
phase: t < 1 ? "merge" : "still",
|
|
147
|
+
separation: 1 - O(t),
|
|
148
|
+
point: {
|
|
149
|
+
x: l.x + u.x * i * f,
|
|
150
|
+
y: l.y + u.y * i * f
|
|
151
|
+
},
|
|
152
|
+
bud: t < 1 ? {
|
|
153
|
+
x: 80 + u.x * i,
|
|
154
|
+
y: 80 + u.y * i,
|
|
155
|
+
radius: 16 * (1 - .65 * O(t))
|
|
156
|
+
} : null
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
let h = o?.phase === "split" ? o.bud : null, g = h ? o.separation : 0, _ = h ? Math.max(180, 460 * (1 - g)) : a ? 0 : 460;
|
|
160
|
+
if (c < _) {
|
|
161
|
+
let e = O(c / _), t = 42 + 70 * e, n = h ? h.x + (80 + u.x * 112 - h.x) * e : 80 + u.x * t, r = h ? h.y + (80 + u.y * 112 - h.y) * e : 80 + u.y * t, i = h?.radius ?? 16 * .55;
|
|
162
|
+
return {
|
|
163
|
+
...m,
|
|
164
|
+
phase: "split",
|
|
165
|
+
separation: g + (1 - g) * e,
|
|
166
|
+
point: {
|
|
167
|
+
x: l.x + (n - 80) * f,
|
|
168
|
+
y: l.y + (r - 80) * f
|
|
169
|
+
},
|
|
170
|
+
bud: {
|
|
171
|
+
x: n,
|
|
172
|
+
y: r,
|
|
173
|
+
radius: i + (16 - i) * e
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
let v = a ?? p, y = 560 + Math.min(260, Math.hypot(n.x - v.x, n.y - v.y) * .26), x = b((c - _) / y, 0, 1);
|
|
178
|
+
if (x < 1) {
|
|
179
|
+
let e = T(v, n, O(x), r);
|
|
180
|
+
return {
|
|
181
|
+
...m,
|
|
182
|
+
phase: "flight",
|
|
183
|
+
separation: 1,
|
|
184
|
+
point: e,
|
|
185
|
+
angle: e.angle,
|
|
186
|
+
stretch: 1 + .35 * Math.sin(x * Math.PI)
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
let S = b((c - _ - y) / 380, 0, 1);
|
|
190
|
+
return {
|
|
191
|
+
...m,
|
|
192
|
+
phase: S < 1 ? "land" : "dock",
|
|
193
|
+
separation: 1,
|
|
194
|
+
point: n,
|
|
195
|
+
seat: O(S)
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/liquidPresencePaint.ts
|
|
200
|
+
function k(e, t) {
|
|
201
|
+
e.toggleAttribute("hidden", !t);
|
|
202
|
+
let n = e.style, r = t ? "" : "none";
|
|
203
|
+
n.display !== r && (n.display = r);
|
|
204
|
+
}
|
|
205
|
+
var A = (e, t, n) => {
|
|
206
|
+
let r = String(n);
|
|
207
|
+
e.getAttribute(t) !== r && e.setAttribute(t, r);
|
|
208
|
+
};
|
|
209
|
+
function j(e, t, n) {
|
|
210
|
+
let r = e.overlay.getBoundingClientRect(), i = r.width / (e.overlay.clientWidth || r.width || 1) || 1, a = r.height / (e.overlay.clientHeight || r.height || 1) || 1;
|
|
211
|
+
return {
|
|
212
|
+
x: (t - r.x) / i,
|
|
213
|
+
y: (n - r.y) / a
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function re(e, t, n, r, i = 0) {
|
|
217
|
+
A(e.source, "data-liquid-phase", t.phase), A(e.overlay, "data-liquid-phase", t.phase), A(e.body, "d", E(r, i, t.separation));
|
|
218
|
+
let a = t.bud ? Math.sin(t.separation * Math.PI) * .045 : 0;
|
|
219
|
+
A(e.body, "transform", `translate(${((t.bud?.x ?? 80) - 80) * a} ${((t.bud?.y ?? 80) - 80) * a})`), k(e.bud, !!t.bud), t.bud && (A(e.bud, "cx", t.bud.x), A(e.bud, "cy", t.bud.y), A(e.bud, "r", t.bud.radius));
|
|
220
|
+
let o = t.phase === "flight" || t.phase === "return";
|
|
221
|
+
k(e.flight, o);
|
|
222
|
+
let s = j(e, t.point.x, t.point.y);
|
|
223
|
+
if (o) {
|
|
224
|
+
let n = t.diameter / 32;
|
|
225
|
+
e.flight.style.transform = `translate(${s.x - 48}px, ${s.y - 36}px)`, A(e.flightBody, "transform", `rotate(${t.angle}) scale(${n * t.stretch} ${n / Math.sqrt(t.stretch)})`), A(e.trail, "opacity", Math.min(.8, (t.stretch - 1) * 3));
|
|
226
|
+
}
|
|
227
|
+
k(e.seat, t.seat !== null), t.seat !== null && (e.seat.style.transform = `translate(${s.x - 56}px, ${s.y - 28}px)`, A(e.seatBody, "d", D(t.seatWidth ?? n, t.seat, t.diameter))), k(e.label, t.phase !== "gather" && t.seat !== null && t.seat > .45);
|
|
228
|
+
}
|
|
229
|
+
function ie(e, t, n, r) {
|
|
230
|
+
e.satellites.forEach((e, i) => {
|
|
231
|
+
if (k(e, n), !n) return;
|
|
232
|
+
let a = t * .7 + i * Math.PI * 2 / 3, o = 63 + Math.max(0, Math.sin(t * 1.6 + i * 2)) * (16 + r * 12);
|
|
233
|
+
A(e, "cx", 80 + Math.cos(a) * o), A(e, "cy", 80 + Math.sin(a) * o), A(e, "r", 7 + i * 1.5);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
function M() {
|
|
237
|
+
let e = window.visualViewport;
|
|
238
|
+
return {
|
|
239
|
+
x: e?.offsetLeft ?? 0,
|
|
240
|
+
y: e?.offsetTop ?? 0,
|
|
241
|
+
width: e?.width ?? innerWidth,
|
|
242
|
+
height: e?.height ?? innerHeight
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/liquidPresenceTracking.ts
|
|
247
|
+
function N(e) {
|
|
248
|
+
try {
|
|
249
|
+
let t = e.contextElement;
|
|
250
|
+
if (t && t.ownerDocument !== document || t && (!t.isConnected || t.closest("[hidden], [inert]")) || t && getComputedStyle(t).visibility === "hidden") return null;
|
|
251
|
+
let n = document.querySelector("dialog:modal");
|
|
252
|
+
if (n && (!t || !n.contains(t))) return null;
|
|
253
|
+
let r = e.getRect();
|
|
254
|
+
return x(r) && S(r, M()) ? r : null;
|
|
255
|
+
} catch {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function ae(e, t, n, r) {
|
|
260
|
+
let i = t.contextElement, a = {
|
|
261
|
+
...i ? { contextElement: i } : {},
|
|
262
|
+
getBoundingClientRect: () => {
|
|
263
|
+
let e = N(t) ?? {
|
|
264
|
+
x: 0,
|
|
265
|
+
y: 0,
|
|
266
|
+
width: 0,
|
|
267
|
+
height: 0
|
|
268
|
+
};
|
|
269
|
+
return {
|
|
270
|
+
...e,
|
|
271
|
+
top: e.y,
|
|
272
|
+
left: e.x,
|
|
273
|
+
right: e.x + e.width,
|
|
274
|
+
bottom: e.y + e.height
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}, o = /* @__PURE__ */ new Set();
|
|
278
|
+
for (let t of [e, i]) for (let e = t; e; e = e.parentElement) o.add(e);
|
|
279
|
+
let s = new MutationObserver(r);
|
|
280
|
+
for (let e of o) s.observe(e, {
|
|
281
|
+
attributes: !0,
|
|
282
|
+
attributeFilter: [
|
|
283
|
+
"style",
|
|
284
|
+
"class",
|
|
285
|
+
"hidden",
|
|
286
|
+
"inert",
|
|
287
|
+
"open"
|
|
288
|
+
]
|
|
289
|
+
});
|
|
290
|
+
let c = new MutationObserver((t) => {
|
|
291
|
+
(!e.isConnected || i && !i.isConnected || t.some((e) => e.type === "attributes" || [...e.addedNodes, ...e.removedNodes].some((e) => e instanceof Element && (e.matches("dialog") || !!e.querySelector("dialog"))))) && r();
|
|
292
|
+
});
|
|
293
|
+
c.observe(document.body, {
|
|
294
|
+
subtree: !0,
|
|
295
|
+
childList: !0,
|
|
296
|
+
attributes: !0,
|
|
297
|
+
attributeFilter: ["open", "inert"]
|
|
298
|
+
});
|
|
299
|
+
let l = () => {}, u = !1, d = /* @__PURE__ */ new Map(), f = (e) => {
|
|
300
|
+
l(), u = e, l = h(i ?? a, n, r, { animationFrame: !i || e });
|
|
301
|
+
}, p = (e) => {
|
|
302
|
+
if (!(e.target instanceof Element) || !o.has(e.target)) return;
|
|
303
|
+
let t = "propertyName" in e ? String(e.propertyName) : "animationName" in e ? String(e.animationName) : e.type, n = d.get(e.target) ?? /* @__PURE__ */ new Set();
|
|
304
|
+
e.type === "transitionrun" || e.type === "animationstart" ? n.add(t) : n.delete(t), n.size ? d.set(e.target, n) : d.delete(e.target), u !== !!d.size && f(!!d.size), r();
|
|
305
|
+
}, m = [
|
|
306
|
+
"transitionrun",
|
|
307
|
+
"transitionend",
|
|
308
|
+
"transitioncancel",
|
|
309
|
+
"animationstart",
|
|
310
|
+
"animationend",
|
|
311
|
+
"animationcancel"
|
|
312
|
+
];
|
|
313
|
+
for (let e of m) document.addEventListener(e, p, !0);
|
|
314
|
+
return f(!1), () => {
|
|
315
|
+
l(), s.disconnect(), c.disconnect();
|
|
316
|
+
for (let e of m) document.removeEventListener(e, p, !0);
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/useLiquidPresenceMotion.ts
|
|
321
|
+
function P(t, r, a, o) {
|
|
322
|
+
let c = l(a);
|
|
323
|
+
c.current = a;
|
|
324
|
+
let u = l(null), d = l(null), f = l(null), p = l(0), m = l(() => {});
|
|
325
|
+
s(() => {
|
|
326
|
+
let a = t.current, o = r.current;
|
|
327
|
+
if (!a || !o) return;
|
|
328
|
+
let s = {
|
|
329
|
+
source: a,
|
|
330
|
+
overlay: o,
|
|
331
|
+
body: a.querySelector("[data-presence-body]"),
|
|
332
|
+
bud: a.querySelector("[data-presence-bud]"),
|
|
333
|
+
satellites: [...a.querySelectorAll("[data-presence-satellite]")],
|
|
334
|
+
flight: o.querySelector(".game-ui-liquid-presence-flight"),
|
|
335
|
+
flightBody: o.querySelector("[data-presence-flight-body]"),
|
|
336
|
+
trail: o.querySelector("[data-presence-trail]"),
|
|
337
|
+
seat: o.querySelector(".game-ui-liquid-presence-seat"),
|
|
338
|
+
seatBody: o.querySelector("[data-presence-seat-body]"),
|
|
339
|
+
label: o.querySelector(".game-ui-liquid-presence-label")
|
|
340
|
+
}, l = c.current.target ?? null;
|
|
341
|
+
l || (d.current = null), l?.key === d.current && (l = null);
|
|
342
|
+
let h = u.current, x = !l && !!(h && h.phase !== "still"), w = h && [
|
|
343
|
+
"flight",
|
|
344
|
+
"dock",
|
|
345
|
+
"land",
|
|
346
|
+
"gather",
|
|
347
|
+
"return"
|
|
348
|
+
].includes(h.phase) ? h.point : void 0, T = h?.point ?? C(a.getBoundingClientRect()), E = h?.seatWidth ?? 48, D = h ?? void 0, O = a.getBoundingClientRect(), A = performance.now(), j = null, P = !0, F = !1, I = !0, L = 0, R = p.current, z = performance.now(), B = 0, V = 0, H = () => {}, U, W = () => {
|
|
349
|
+
F && n(), F = !1;
|
|
350
|
+
}, G = (e) => {
|
|
351
|
+
if (l) {
|
|
352
|
+
d.current = l.key, l = null, x = !!(u.current && u.current.phase !== "still"), D = u.current ?? void 0, w = u.current?.point, T = w ?? T, A = performance.now(), H(), clearTimeout(U), V++, k(s.label, !1);
|
|
353
|
+
try {
|
|
354
|
+
c.current.onDismiss?.(e);
|
|
355
|
+
} catch {}
|
|
356
|
+
Z();
|
|
357
|
+
}
|
|
358
|
+
}, K = () => l ? N(c.current.target?.key === l.key ? c.current.target : l) : null, q = () => {
|
|
359
|
+
if (!l) return;
|
|
360
|
+
let e = K();
|
|
361
|
+
if (!e) {
|
|
362
|
+
G("unavailable");
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
let t = te(e, M()), n = ee(e, M());
|
|
366
|
+
T = t, E = t.width;
|
|
367
|
+
let r = {
|
|
368
|
+
...l.contextElement ? { contextElement: l.contextElement } : {},
|
|
369
|
+
getBoundingClientRect: () => ({
|
|
370
|
+
...n,
|
|
371
|
+
top: n.y,
|
|
372
|
+
left: n.x,
|
|
373
|
+
bottom: n.y + n.height,
|
|
374
|
+
right: n.x + n.width
|
|
375
|
+
})
|
|
376
|
+
}, i = ++V;
|
|
377
|
+
g(r, s.label, {
|
|
378
|
+
strategy: "absolute",
|
|
379
|
+
placement: t.side,
|
|
380
|
+
middleware: [
|
|
381
|
+
v(26),
|
|
382
|
+
_(),
|
|
383
|
+
y({
|
|
384
|
+
padding: 16,
|
|
385
|
+
crossAxis: !0
|
|
386
|
+
})
|
|
387
|
+
]
|
|
388
|
+
}).then(({ x: e, y: t }) => {
|
|
389
|
+
P && i === V && (s.label.style.transform = `translate(${e}px, ${t}px)`);
|
|
390
|
+
}).catch(() => {});
|
|
391
|
+
}, J = () => [
|
|
392
|
+
"connecting",
|
|
393
|
+
"listening",
|
|
394
|
+
"thinking",
|
|
395
|
+
"speaking",
|
|
396
|
+
"working"
|
|
397
|
+
].includes(c.current.activity ?? "idle"), oe = () => {
|
|
398
|
+
if (c.current.reducedMotion || c.current.activity === "disabled" || document.hidden || !I || !S(a.getBoundingClientRect(), M())) return !1;
|
|
399
|
+
let t = document.querySelector("dialog:modal");
|
|
400
|
+
if (t && !t.contains(a)) return !1;
|
|
401
|
+
let n = l?.contextElement?.closest("dialog") ?? null;
|
|
402
|
+
if (l && a.closest("dialog") !== n) return !1;
|
|
403
|
+
let r = 13184 + (a.getBoundingClientRect().width * 2) ** 2, o = i();
|
|
404
|
+
return o.maxAnimatedGroups === 0 || r > o.maxFilterArea ? (W(), !1) : (F ||= e(r), F);
|
|
405
|
+
};
|
|
406
|
+
function Y(e) {
|
|
407
|
+
if (!P || document.hidden) return;
|
|
408
|
+
let t = s.source.getBoundingClientRect();
|
|
409
|
+
if (!s.source.isConnected || s.source.closest("[hidden], [inert]") || t.width <= 0 || t.height <= 0) {
|
|
410
|
+
x = !1, u.current = null, G("unavailable"), k(s.label, !1), k(s.flight, !1), k(s.seat, !1), W();
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (l && !K()) {
|
|
414
|
+
G("unavailable");
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
let n = oe(), r = ne({
|
|
418
|
+
elapsed: e - A,
|
|
419
|
+
source: x ? t : O,
|
|
420
|
+
destination: T,
|
|
421
|
+
viewport: M(),
|
|
422
|
+
returning: x,
|
|
423
|
+
...w ? { from: w } : {},
|
|
424
|
+
...D ? { origin: D } : {}
|
|
425
|
+
});
|
|
426
|
+
!l && !x && (r = {
|
|
427
|
+
...r,
|
|
428
|
+
phase: "still",
|
|
429
|
+
separation: 0,
|
|
430
|
+
bud: null,
|
|
431
|
+
seat: null
|
|
432
|
+
}), (!n || l && f.current === l.key) && (r = {
|
|
433
|
+
...r,
|
|
434
|
+
phase: l ? "dock" : "still",
|
|
435
|
+
point: T,
|
|
436
|
+
bud: null,
|
|
437
|
+
seat: l ? 1 : null,
|
|
438
|
+
separation: +!!l
|
|
439
|
+
}), x && r.phase === "still" && (x = !1), l && r.phase === "dock" && (f.current = l.key);
|
|
440
|
+
let i = !["still", "dock"].includes(r.phase), a = c.current.levelRef?.current, o = Math.max(0, Math.min(64, e - z));
|
|
441
|
+
z = e;
|
|
442
|
+
let d = typeof a == "number" ? b(a, 0, 1) : 0;
|
|
443
|
+
B += (d - B) * (1 - Math.exp(-o / (d > B ? 65 : 140))), n && (i || J()) && (R += o * .00105), p.current = R;
|
|
444
|
+
let m = n && J() && !i ? .14 + B * .75 : i ? .2 : 0, h = s.label.hasAttribute("hidden");
|
|
445
|
+
re(s, r, E, R, m), ie(s, R, n && c.current.activity === "speaking" && r.phase === "still", B);
|
|
446
|
+
let g = n && (i || J()) ? "animated" : "static";
|
|
447
|
+
s.source.dataset.liquidMotion !== g && (s.source.dataset.liquidMotion = g), u.current = {
|
|
448
|
+
...r,
|
|
449
|
+
seatWidth: r.phase === "gather" ? D?.seatWidth ?? E : E
|
|
450
|
+
}, l && h && !s.label.hasAttribute("hidden") && q(), n && (i || J()) ? j = requestAnimationFrame(X) : W();
|
|
451
|
+
}
|
|
452
|
+
function X(e) {
|
|
453
|
+
if (j = null, !P || document.hidden) {
|
|
454
|
+
W();
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
if ((u.current?.phase === "still" || u.current?.phase === "dock") && e - L < 32) {
|
|
458
|
+
j = requestAnimationFrame(X);
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
L = e, Y(e);
|
|
462
|
+
}
|
|
463
|
+
function Z() {
|
|
464
|
+
!P || j !== null || document.hidden || Y(performance.now());
|
|
465
|
+
}
|
|
466
|
+
m.current = Z;
|
|
467
|
+
let Q = () => {
|
|
468
|
+
if (H(), H = () => {}, !l || document.hidden) return;
|
|
469
|
+
let e = ae(s.source, l, s.label, () => {
|
|
470
|
+
q(), Z();
|
|
471
|
+
});
|
|
472
|
+
H = e, l || e();
|
|
473
|
+
};
|
|
474
|
+
l && (s.label.textContent = l.label.slice(0, 240), q(), l && (Q(), l && (U = setTimeout(() => G("expired"), 12e3))));
|
|
475
|
+
let $ = (e) => {
|
|
476
|
+
e.key === "Escape" && G("dismissed");
|
|
477
|
+
}, se = (e) => {
|
|
478
|
+
l?.contextElement && e.target instanceof Node && l.contextElement.contains(e.target) && G("dismissed");
|
|
479
|
+
}, ce = () => {
|
|
480
|
+
document.hidden ? (j !== null && cancelAnimationFrame(j), j = null, H(), V++, W()) : (z = performance.now(), Q(), Z());
|
|
481
|
+
}, le = typeof IntersectionObserver > "u" ? null : new IntersectionObserver((e) => {
|
|
482
|
+
I = e[0]?.isIntersecting ?? !0, I || (j !== null && cancelAnimationFrame(j), j = null, W()), Z();
|
|
483
|
+
});
|
|
484
|
+
return le?.observe(a), document.addEventListener("keydown", $), document.addEventListener("click", se), document.addEventListener("visibilitychange", ce), Z(), () => {
|
|
485
|
+
P = !1, m.current = () => {}, V++, j !== null && cancelAnimationFrame(j), clearTimeout(U), H(), le?.disconnect(), W(), document.removeEventListener("keydown", $), document.removeEventListener("click", se), document.removeEventListener("visibilitychange", ce);
|
|
486
|
+
};
|
|
487
|
+
}, [
|
|
488
|
+
t,
|
|
489
|
+
r,
|
|
490
|
+
o,
|
|
491
|
+
a.target?.key,
|
|
492
|
+
a.reducedMotion,
|
|
493
|
+
a.size
|
|
494
|
+
]), s(() => m.current(), [a.activity]);
|
|
495
|
+
}
|
|
496
|
+
//#endregion
|
|
497
|
+
//#region src/LiquidPresence.tsx
|
|
498
|
+
function F(e) {
|
|
499
|
+
let n = o() || e.reducedMotion === !0, r = b(e.size ?? 64, 32, 224), i = `presence-${c().replace(/[^a-zA-Z0-9_-]/g, "")}`, a = l(null), h = l(null), [g, _] = u(null);
|
|
500
|
+
s(() => {
|
|
501
|
+
let t = e.target?.contextElement?.closest("dialog");
|
|
502
|
+
_(t ?? a.current?.closest("dialog") ?? document.body);
|
|
503
|
+
}, [e.target?.contextElement]), s(() => {
|
|
504
|
+
let e = a.current, t = h.current;
|
|
505
|
+
if (!e || !t) return;
|
|
506
|
+
let n = [
|
|
507
|
+
"--liquid-presence-from",
|
|
508
|
+
"--liquid-presence-to",
|
|
509
|
+
"--game-ui-secondary",
|
|
510
|
+
"--game-ui-warning",
|
|
511
|
+
"--game-ui-panel-strong",
|
|
512
|
+
"--game-ui-text",
|
|
513
|
+
"--game-ui-font-body",
|
|
514
|
+
"--game-ui-radius-control",
|
|
515
|
+
"--game-ui-shadow-button"
|
|
516
|
+
], r = () => {
|
|
517
|
+
let r = getComputedStyle(e);
|
|
518
|
+
for (let e of n) {
|
|
519
|
+
let n = r.getPropertyValue(e).trim();
|
|
520
|
+
t.style.getPropertyValue(e) !== n && t.style.setProperty(e, n);
|
|
521
|
+
}
|
|
522
|
+
}, i = new MutationObserver(r);
|
|
523
|
+
for (let t = e; t; t = t.parentElement) i.observe(t, {
|
|
524
|
+
attributes: !0,
|
|
525
|
+
attributeFilter: [
|
|
526
|
+
"class",
|
|
527
|
+
"style",
|
|
528
|
+
"data-game-ui-theme",
|
|
529
|
+
"data-activity"
|
|
530
|
+
]
|
|
531
|
+
});
|
|
532
|
+
return r(), window.addEventListener("resize", r, { passive: !0 }), () => {
|
|
533
|
+
i.disconnect(), window.removeEventListener("resize", r);
|
|
534
|
+
};
|
|
535
|
+
}, [g]), P(a, h, {
|
|
536
|
+
...e,
|
|
537
|
+
size: r,
|
|
538
|
+
reducedMotion: n
|
|
539
|
+
}, g);
|
|
540
|
+
let v = {
|
|
541
|
+
width: r,
|
|
542
|
+
height: r,
|
|
543
|
+
...e.colorFrom ? { "--liquid-presence-from": e.colorFrom } : {},
|
|
544
|
+
...e.colorTo ? { "--liquid-presence-to": e.colorTo } : {},
|
|
545
|
+
...["error", "unknown"].includes(e.activity ?? "") ? {
|
|
546
|
+
"--liquid-presence-from": "var(--game-ui-warning)",
|
|
547
|
+
"--liquid-presence-to": "var(--game-ui-warning)"
|
|
548
|
+
} : {}
|
|
549
|
+
}, y = (e, n) => /* @__PURE__ */ m("defs", { children: [/* @__PURE__ */ m("linearGradient", {
|
|
550
|
+
id: `${i}-${e}-fill`,
|
|
551
|
+
gradientUnits: "userSpaceOnUse",
|
|
552
|
+
x1: e === "core" ? 24 : -24,
|
|
553
|
+
y1: e === "core" ? 16 : -18,
|
|
554
|
+
x2: e === "core" ? 136 : 24,
|
|
555
|
+
y2: e === "core" ? 146 : 18,
|
|
556
|
+
children: [/* @__PURE__ */ p("stop", {
|
|
557
|
+
offset: "0",
|
|
558
|
+
stopColor: "var(--liquid-presence-from, var(--game-ui-secondary))"
|
|
559
|
+
}), /* @__PURE__ */ p("stop", {
|
|
560
|
+
offset: "1",
|
|
561
|
+
stopColor: "var(--liquid-presence-to, var(--game-ui-secondary))"
|
|
562
|
+
})]
|
|
563
|
+
}), /* @__PURE__ */ p("filter", {
|
|
564
|
+
id: `${i}-${e}-goo`,
|
|
565
|
+
filterUnits: "userSpaceOnUse",
|
|
566
|
+
...n,
|
|
567
|
+
colorInterpolationFilters: "sRGB",
|
|
568
|
+
children: /* @__PURE__ */ p(t, {
|
|
569
|
+
blur: e === "core" ? 5 : 2,
|
|
570
|
+
contrast: 18,
|
|
571
|
+
gloss: 3.5,
|
|
572
|
+
shadows: [],
|
|
573
|
+
stroke: null,
|
|
574
|
+
waviness: 0
|
|
575
|
+
})
|
|
576
|
+
})] });
|
|
577
|
+
return /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("span", {
|
|
578
|
+
ref: a,
|
|
579
|
+
className: `game-ui-liquid-presence ${e.className ?? ""}`,
|
|
580
|
+
style: v,
|
|
581
|
+
"data-activity": e.activity ?? "idle",
|
|
582
|
+
"aria-hidden": "true",
|
|
583
|
+
children: /* @__PURE__ */ m("svg", {
|
|
584
|
+
viewBox: "0 0 160 160",
|
|
585
|
+
focusable: "false",
|
|
586
|
+
children: [y("core", {
|
|
587
|
+
x: -80,
|
|
588
|
+
y: -80,
|
|
589
|
+
width: 320,
|
|
590
|
+
height: 320
|
|
591
|
+
}), /* @__PURE__ */ m("g", {
|
|
592
|
+
fill: `url(#${i}-core-fill)`,
|
|
593
|
+
filter: `url(#${i}-core-goo)`,
|
|
594
|
+
children: [
|
|
595
|
+
/* @__PURE__ */ p("path", {
|
|
596
|
+
"data-presence-body": "",
|
|
597
|
+
d: E()
|
|
598
|
+
}),
|
|
599
|
+
/* @__PURE__ */ p("circle", {
|
|
600
|
+
"data-presence-bud": "",
|
|
601
|
+
cx: "80",
|
|
602
|
+
cy: "80",
|
|
603
|
+
r: "0",
|
|
604
|
+
style: { display: "none" }
|
|
605
|
+
}),
|
|
606
|
+
[
|
|
607
|
+
0,
|
|
608
|
+
1,
|
|
609
|
+
2
|
|
610
|
+
].map((e) => /* @__PURE__ */ p("circle", {
|
|
611
|
+
"data-presence-satellite": "",
|
|
612
|
+
cx: "80",
|
|
613
|
+
cy: "80",
|
|
614
|
+
r: "0",
|
|
615
|
+
style: { display: "none" }
|
|
616
|
+
}, e))
|
|
617
|
+
]
|
|
618
|
+
})]
|
|
619
|
+
})
|
|
620
|
+
}), g && d(/* @__PURE__ */ m("div", {
|
|
621
|
+
ref: h,
|
|
622
|
+
className: "game-ui-liquid-presence-overlay",
|
|
623
|
+
style: {
|
|
624
|
+
...v,
|
|
625
|
+
width: void 0,
|
|
626
|
+
height: void 0
|
|
627
|
+
},
|
|
628
|
+
"data-presence-overlay": "",
|
|
629
|
+
children: [
|
|
630
|
+
/* @__PURE__ */ m("svg", {
|
|
631
|
+
className: "game-ui-liquid-presence-flight",
|
|
632
|
+
viewBox: "-48 -36 96 72",
|
|
633
|
+
"aria-hidden": "true",
|
|
634
|
+
focusable: "false",
|
|
635
|
+
style: { display: "none" },
|
|
636
|
+
children: [y("flight", {
|
|
637
|
+
x: -48,
|
|
638
|
+
y: -36,
|
|
639
|
+
width: 96,
|
|
640
|
+
height: 72
|
|
641
|
+
}), /* @__PURE__ */ p("g", {
|
|
642
|
+
fill: `url(#${i}-flight-fill)`,
|
|
643
|
+
filter: `url(#${i}-flight-goo)`,
|
|
644
|
+
children: /* @__PURE__ */ m("g", {
|
|
645
|
+
"data-presence-flight-body": "",
|
|
646
|
+
children: [/* @__PURE__ */ p("circle", { r: "16" }), /* @__PURE__ */ m("g", {
|
|
647
|
+
"data-presence-trail": "",
|
|
648
|
+
children: [/* @__PURE__ */ p("circle", {
|
|
649
|
+
cx: "-27",
|
|
650
|
+
cy: "5",
|
|
651
|
+
r: "4.5"
|
|
652
|
+
}), /* @__PURE__ */ p("circle", {
|
|
653
|
+
cx: "-36",
|
|
654
|
+
cy: "8",
|
|
655
|
+
r: "2.5"
|
|
656
|
+
})]
|
|
657
|
+
})]
|
|
658
|
+
})
|
|
659
|
+
})]
|
|
660
|
+
}),
|
|
661
|
+
/* @__PURE__ */ m("svg", {
|
|
662
|
+
className: "game-ui-liquid-presence-seat",
|
|
663
|
+
viewBox: "-56 -28 112 56",
|
|
664
|
+
"aria-hidden": "true",
|
|
665
|
+
focusable: "false",
|
|
666
|
+
style: { display: "none" },
|
|
667
|
+
children: [y("seat", {
|
|
668
|
+
x: -56,
|
|
669
|
+
y: -28,
|
|
670
|
+
width: 112,
|
|
671
|
+
height: 56
|
|
672
|
+
}), /* @__PURE__ */ p("path", {
|
|
673
|
+
"data-presence-seat-body": "",
|
|
674
|
+
d: D(48, 1),
|
|
675
|
+
fill: `url(#${i}-seat-fill)`,
|
|
676
|
+
filter: `url(#${i}-seat-goo)`
|
|
677
|
+
})]
|
|
678
|
+
}),
|
|
679
|
+
/* @__PURE__ */ p("span", {
|
|
680
|
+
className: "game-ui-liquid-presence-label",
|
|
681
|
+
role: "status",
|
|
682
|
+
"aria-atomic": "true",
|
|
683
|
+
hidden: !0
|
|
684
|
+
})
|
|
685
|
+
]
|
|
686
|
+
}), g)] });
|
|
687
|
+
}
|
|
688
|
+
//#endregion
|
|
689
|
+
export { F as LiquidPresence };
|