@limrun/ui 0.20.1 → 0.20.3

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.
@@ -0,0 +1,679 @@
1
+ import { jsx as o, jsxs as x, Fragment as z } from "react/jsx-runtime";
2
+ import ot, { useId as J, useState as W, useRef as M, useEffect as T, useCallback as at, useLayoutEffect as it, Suspense as st, lazy as ct } from "react";
3
+ import { H as dt, D as A, v as ut, w as lt, x as ht, y as ft, z as j } from "./core-CeAISahM.mjs";
4
+ function mt(t, n, r) {
5
+ const [s, i] = W(t), a = M({ nativeAngle: t, send: n, failed: r });
6
+ a.current = { nativeAngle: t, send: n, failed: r };
7
+ const u = M(void 0), m = M(!1), d = M(null);
8
+ return T(() => (d.current = new dt(
9
+ async (h) => {
10
+ await a.current.send(h), u.current === h && (u.current = void 0);
11
+ },
12
+ (h) => {
13
+ u.current = void 0, a.current.failed(String(h)), i(a.current.nativeAngle);
14
+ }
15
+ ), () => d.current?.stop()), []), T(() => {
16
+ !m.current && u.current === void 0 && i(t);
17
+ }, [t]), { angle: s, changeAngle: (h) => {
18
+ a.current.failed(void 0), u.current = h, i(h), d.current?.set(h);
19
+ }, interacting: m };
20
+ }
21
+ function pt({
22
+ angle: t,
23
+ watchOnly: n = !1,
24
+ changeAngle: r,
25
+ interacting: s,
26
+ rotate: i,
27
+ onFold: a,
28
+ foldTarget: u,
29
+ onHingeDrag: m,
30
+ children: d
31
+ }) {
32
+ const l = J();
33
+ return /* @__PURE__ */ x("div", { className: "rc-duo-controls", onPointerDown: (h) => h.stopPropagation(), children: [
34
+ /* @__PURE__ */ x("div", { className: "rc-duo-hinge", children: [
35
+ /* @__PURE__ */ o(
36
+ "button",
37
+ {
38
+ disabled: n,
39
+ className: "rc-duo-fold",
40
+ onClick: a ?? (() => r(t < 90 ? 180 : 0)),
41
+ children: (u ?? t) < 90 ? "Unfold" : "Fold"
42
+ }
43
+ ),
44
+ /* @__PURE__ */ o("label", { htmlFor: l, children: "Hinge" }),
45
+ /* @__PURE__ */ o(
46
+ "input",
47
+ {
48
+ id: l,
49
+ type: "range",
50
+ disabled: n,
51
+ min: 0,
52
+ max: 180,
53
+ step: 1,
54
+ value: t,
55
+ onPointerDown: (h) => {
56
+ m?.(), s.current = !0, h.currentTarget.setPointerCapture(h.pointerId);
57
+ },
58
+ onPointerUp: () => {
59
+ s.current = !1;
60
+ },
61
+ onPointerCancel: () => {
62
+ s.current = !1;
63
+ },
64
+ onLostPointerCapture: () => {
65
+ s.current = !1;
66
+ },
67
+ onChange: (h) => r(Number(h.target.value))
68
+ }
69
+ ),
70
+ /* @__PURE__ */ x("output", { children: [
71
+ Math.round(t),
72
+ "°"
73
+ ] }),
74
+ /* @__PURE__ */ o(
75
+ "button",
76
+ {
77
+ disabled: n,
78
+ className: "rc-duo-rotate",
79
+ "aria-label": "Rotate device",
80
+ title: "Rotate device",
81
+ onClick: i,
82
+ children: /* @__PURE__ */ x(
83
+ "svg",
84
+ {
85
+ viewBox: "0 0 24 24",
86
+ width: "18",
87
+ height: "18",
88
+ fill: "none",
89
+ stroke: "currentColor",
90
+ strokeWidth: "1.6",
91
+ "aria-hidden": "true",
92
+ children: [
93
+ /* @__PURE__ */ o("rect", { x: "7", y: "3", width: "10", height: "18", rx: "2" }),
94
+ /* @__PURE__ */ o("path", { d: "M3 9a9 9 0 0 1 3-5M3 4v5h5M21 15a9 9 0 0 1-3 5m3 0v-5h-5" })
95
+ ]
96
+ }
97
+ )
98
+ }
99
+ )
100
+ ] }),
101
+ d && /* @__PURE__ */ o("div", { className: "rc-duo-views", "aria-label": "Device view", children: d })
102
+ ] });
103
+ }
104
+ function gt({ button: t }) {
105
+ return /* @__PURE__ */ o(
106
+ "svg",
107
+ {
108
+ viewBox: "0 0 24 24",
109
+ width: "24",
110
+ height: "24",
111
+ fill: "none",
112
+ stroke: "currentColor",
113
+ strokeWidth: "1.7",
114
+ strokeLinecap: "round",
115
+ strokeLinejoin: "round",
116
+ "aria-hidden": "true",
117
+ children: t === "side" ? /* @__PURE__ */ x(z, { children: [
118
+ /* @__PURE__ */ o("rect", { x: "6", y: "10", width: "12", height: "11", rx: "2" }),
119
+ /* @__PURE__ */ o("path", { d: "M8 10V7a4 4 0 0 1 8 0v3" })
120
+ ] }) : /* @__PURE__ */ x(z, { children: [
121
+ /* @__PURE__ */ o("path", { d: "M3 9h4l5-5v16l-5-5H3zM17 12h5" }),
122
+ t === "volumeUp" && /* @__PURE__ */ o("path", { d: "M19.5 9.5v5" })
123
+ ] })
124
+ }
125
+ );
126
+ }
127
+ function Y(t, n, r, s, i, a) {
128
+ return "M" + (t + i) + "," + n + "H" + (t + r - a) + "a" + a + "," + a + " 0 0 1 " + a + "," + a + "V" + (n + s - a) + "a" + a + "," + a + " 0 0 1 " + -a + "," + a + "H" + (t + i) + "a" + i + "," + i + " 0 0 1 " + -i + "," + -i + "V" + (n + i) + "a" + i + "," + i + " 0 0 1 " + i + "," + -i + "Z";
129
+ }
130
+ function Q({ inner: t, width: n, height: r }) {
131
+ const s = J().replace(/:/g, ""), i = t ? 8.4 : 1.25, a = 8.4;
132
+ return /* @__PURE__ */ x("svg", { className: "rc-duo-flat-frame", viewBox: "0 0 " + n + " " + r, "aria-hidden": "true", children: [
133
+ /* @__PURE__ */ x("defs", { children: [
134
+ /* @__PURE__ */ x("linearGradient", { id: s + "-silver", x1: "0", y1: "0", x2: "1", y2: "1", children: [
135
+ /* @__PURE__ */ o("stop", { offset: "0", stopColor: "#62676b" }),
136
+ /* @__PURE__ */ o("stop", { offset: "0.035", stopColor: "#f9faf9" }),
137
+ /* @__PURE__ */ o("stop", { offset: "0.11", stopColor: "#b0b4b6" }),
138
+ /* @__PURE__ */ o("stop", { offset: "0.31", stopColor: "#fdfefd" }),
139
+ /* @__PURE__ */ o("stop", { offset: "0.43", stopColor: "#797f84" }),
140
+ /* @__PURE__ */ o("stop", { offset: "0.51", stopColor: "#e8eaea" }),
141
+ /* @__PURE__ */ o("stop", { offset: "0.7", stopColor: "#979da1" }),
142
+ /* @__PURE__ */ o("stop", { offset: "0.87", stopColor: "#fafbf9" }),
143
+ /* @__PURE__ */ o("stop", { offset: "1", stopColor: "#5f676c" })
144
+ ] }),
145
+ /* @__PURE__ */ x("linearGradient", { id: s + "-spine", children: [
146
+ /* @__PURE__ */ o("stop", { stopColor: "#4a5154" }),
147
+ /* @__PURE__ */ o("stop", { offset: "0.16", stopColor: "#d6d9d9" }),
148
+ /* @__PURE__ */ o("stop", { offset: "0.4", stopColor: "#f8f9f7" }),
149
+ /* @__PURE__ */ o("stop", { offset: "0.62", stopColor: "#a2a8ab" }),
150
+ /* @__PURE__ */ o("stop", { offset: "0.83", stopColor: "#e4e7e5" }),
151
+ /* @__PURE__ */ o("stop", { offset: "1", stopColor: "#666e72" })
152
+ ] })
153
+ ] }),
154
+ !t && /* @__PURE__ */ x(z, { children: [
155
+ /* @__PURE__ */ o(
156
+ "rect",
157
+ {
158
+ x: "-2.3",
159
+ y: "0.7",
160
+ width: "3.3",
161
+ height: r - 1.4,
162
+ rx: "0.85",
163
+ fill: "url(#" + s + "-spine)",
164
+ stroke: "#8b9296",
165
+ strokeWidth: "0.15"
166
+ }
167
+ ),
168
+ /* @__PURE__ */ o("path", { d: "M-.6 2V" + (r - 2), stroke: "#f5f6f4", strokeWidth: "0.22" })
169
+ ] }),
170
+ /* @__PURE__ */ o(
171
+ "path",
172
+ {
173
+ d: Y(0, 0, n, r, i, a),
174
+ fill: "url(#" + s + "-silver)",
175
+ stroke: "#696f72",
176
+ strokeWidth: "0.24"
177
+ }
178
+ ),
179
+ /* @__PURE__ */ o(
180
+ "path",
181
+ {
182
+ d: Y(0.48, 0.48, n - 0.96, r - 0.96, Math.max(0.5, i - 0.48), a - 0.48),
183
+ fill: "none",
184
+ stroke: "#ffffff",
185
+ strokeOpacity: "0.85",
186
+ strokeWidth: "0.2"
187
+ }
188
+ ),
189
+ /* @__PURE__ */ o(
190
+ "path",
191
+ {
192
+ d: Y(1.12, 1.12, n - 2.24, r - 2.24, t ? 7.15 : 0.65, 7.15),
193
+ fill: "#090b0d",
194
+ stroke: "#34393c",
195
+ strokeWidth: "0.2"
196
+ }
197
+ ),
198
+ [n - 16, t ? 19 : 16].map((u) => /* @__PURE__ */ o(ot.Fragment, { children: /* @__PURE__ */ o(
199
+ "path",
200
+ {
201
+ d: "M" + u + ",0.17v0.82M" + u + "," + (r - 1) + "v0.82",
202
+ stroke: "#b1b2ac",
203
+ strokeWidth: "1.1"
204
+ }
205
+ ) }, u)),
206
+ t && [0, r - 0.6].map((u) => /* @__PURE__ */ o(
207
+ "rect",
208
+ {
209
+ x: n / 2 - 2.2,
210
+ y: u,
211
+ width: "4.4",
212
+ height: "0.6",
213
+ rx: "0.18",
214
+ fill: "url(#" + s + "-spine)",
215
+ stroke: "#697074",
216
+ strokeWidth: "0.14"
217
+ },
218
+ u
219
+ )),
220
+ /* @__PURE__ */ o(
221
+ "path",
222
+ {
223
+ d: "M" + (n - 0.1) + ",20h-.9m.9," + (r - 40) + "h-.9",
224
+ stroke: "#b1b2ac",
225
+ strokeWidth: "1.05"
226
+ }
227
+ )
228
+ ] });
229
+ }
230
+ function yt(t, n, r, s) {
231
+ const i = A.width / (t ? 1 : 2), a = A.height, u = t ? 157.5 : 77.1, m = t ? 110.8 : 112.2, d = (n + (t ? 3 : 0)) % 4, l = Math.max(
232
+ 0,
233
+ Math.min(
234
+ (r - 120) / (d % 2 ? a : i),
235
+ (s - 120) / (d % 2 ? i : a)
236
+ )
237
+ ), h = (y, f) => {
238
+ y = (y - i / 2) * l, f = (f - a / 2) * l;
239
+ const P = d === 1 ? { x: -f, y } : d === 2 ? { x: -y, y: -f } : d === 3 ? { x: f, y: -y } : { x: y, y: f };
240
+ return { x: P.x + r / 2, y: P.y + s / 2 };
241
+ }, H = (d % 2 ? a : i) * l, D = (d % 2 ? i : a) * l, N = {
242
+ min: { x: (r - H) / 2, y: (s - D) / 2 },
243
+ max: { x: (r + H) / 2, y: (s + D) / 2 }
244
+ }, g = [
245
+ { button: "volumeDown", x: i - 37, y: -0.32, width: 9.5, height: 0.65, edge: "top" },
246
+ { button: "volumeUp", x: i - 25, y: -0.32, width: 9.5, height: 0.65, edge: "top" },
247
+ { button: "side", x: i + 0.35, y: a / 2 - 21, width: 0.7, height: 13, edge: "right" }
248
+ ], b = ["top", "right", "bottom", "left"], v = g.map((y) => {
249
+ const f = b[(b.indexOf(y.edge) + d) % 4], P = h(y.x, y.y);
250
+ return f === "top" && (P.y = N.min.y - 28), f === "bottom" && (P.y = N.max.y + 28), f === "left" && (P.x = N.min.x - 28), f === "right" && (P.x = N.max.x + 28), { button: y.button, edge: f, ...P, targetX: P.x, targetY: P.y };
251
+ }), w = v.filter((y) => y.button !== "side"), p = d % 2 ? "y" : "x";
252
+ w.sort((y, f) => y[p] - f[p]);
253
+ const F = d % 2 ? "targetY" : "targetX";
254
+ if (w[1][p] - w[0][p] < 44) {
255
+ const y = (w[0][p] + w[1][p]) / 2;
256
+ w[0][F] = y - 22, w[1][F] = y + 22;
257
+ }
258
+ return {
259
+ bodyWidth: i,
260
+ bodyHeight: a,
261
+ screenWidth: u,
262
+ screenHeight: m,
263
+ scale: l,
264
+ turns: d,
265
+ buttons: g,
266
+ guides: v,
267
+ rect: N,
268
+ iconSize: Math.min(bt(N), 12 * l)
269
+ };
270
+ }
271
+ function bt(t) {
272
+ return Math.max(12, Math.min(24, Math.max(t.max.x - t.min.x, t.max.y - t.min.y) / 24));
273
+ }
274
+ function vt(t, n, r) {
275
+ return [
276
+ ["top", r.min.y - n, t, r.min.x, r.max.x],
277
+ ["bottom", n - r.max.y, t, r.min.x, r.max.x],
278
+ ["left", r.min.x - t, n, r.min.y, r.max.y],
279
+ ["right", t - r.max.x, n, r.min.y, r.max.y]
280
+ ].filter(
281
+ ([, i, a, u, m]) => i >= -7 && i <= 52 && a >= u - 12 && a <= m + 12
282
+ ).sort((i, a) => Math.abs(i[1]) - Math.abs(a[1]))[0]?.[0];
283
+ }
284
+ function _(t) {
285
+ if (!t || t.readyState < 2 || !t.videoWidth || !t.videoHeight) return;
286
+ const n = Math.min(1, 1024 / Math.max(t.videoWidth, t.videoHeight)), r = document.createElement("canvas");
287
+ try {
288
+ const s = r.getContext("2d");
289
+ return s ? (r.width = Math.round(t.videoWidth * n), r.height = Math.round(t.videoHeight * n), s.drawImage(t, 0, 0, r.width, r.height), r) : void 0;
290
+ } catch {
291
+ return;
292
+ }
293
+ }
294
+ function wt(t, n) {
295
+ let r = !1, s;
296
+ const i = (l) => {
297
+ r || (d(), n(l));
298
+ }, a = () => {
299
+ if (r) return;
300
+ const l = _(t);
301
+ l && i(l);
302
+ }, u = () => {
303
+ s = void 0, a(), r || (s = t?.requestVideoFrameCallback?.(u));
304
+ }, m = setTimeout(() => i(void 0), 2500);
305
+ s = t?.requestVideoFrameCallback?.(u), t?.addEventListener("loadeddata", a), !t?.requestVideoFrameCallback && t && t.readyState >= 2 && a();
306
+ function d() {
307
+ r = !0, clearTimeout(m), s !== void 0 && t?.cancelVideoFrameCallback(s), t?.removeEventListener("loadeddata", a);
308
+ }
309
+ return d;
310
+ }
311
+ function xt(t, n, r, s, i = !0) {
312
+ const a = M(void 0), u = M(s), m = M({ inner: n, frame: r });
313
+ m.current = { inner: n, frame: r };
314
+ const [d, l] = W(), h = M(void 0), H = M(void 0), D = at(() => {
315
+ clearTimeout(H.current), h.current = void 0, l(void 0);
316
+ }, []), N = (g) => {
317
+ if (!i || g === n) {
318
+ D();
319
+ return;
320
+ }
321
+ if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches || h.current) return;
322
+ const b = _(t.current);
323
+ if (!b) return;
324
+ const v = m.current;
325
+ h.current = { from: v, to: v, before: b, ready: !1 }, l(h.current), H.current = setTimeout(D, 5e3);
326
+ };
327
+ return T(() => () => clearTimeout(H.current), []), it(() => {
328
+ const g = a.current, b = { inner: n, frame: r };
329
+ a.current = b;
330
+ const v = u.current !== s;
331
+ if (u.current = s, !g) return;
332
+ const w = Math.abs(g.frame.rect.min.x + g.frame.rect.max.x - r.rect.min.x - r.rect.max.x) > 0.5 || Math.abs(g.frame.rect.min.y + g.frame.rect.max.y - r.rect.min.y - r.rect.max.y) > 0.5;
333
+ if (!i || w || v) {
334
+ D();
335
+ return;
336
+ }
337
+ if (g.inner === n || (l(void 0), !g.frame.scale || !r.scale) || window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) return;
338
+ const p = h.current?.before ?? _(t.current), F = h.current?.from ?? g;
339
+ clearTimeout(H.current), h.current = void 0, p && l({ from: F, to: b, before: p, ready: !1 });
340
+ }, [n, r.scale, r.turns, r.rect.min.x, r.rect.min.y, s, i]), T(() => {
341
+ if (!d || d.from.inner === n) return;
342
+ const g = wt(t.current, (w) => {
343
+ w ? l((p) => p && { ...p, to: m.current, after: w, ready: !0 }) : D();
344
+ }), b = window.matchMedia?.("(prefers-reduced-motion: reduce)"), v = () => {
345
+ b?.matches && l(void 0);
346
+ };
347
+ return b?.addEventListener("change", v), () => {
348
+ g(), b?.removeEventListener("change", v);
349
+ };
350
+ }, [d?.from, n]), { motion: d, finish: D, prepare: N };
351
+ }
352
+ function Mt({ pose: t, image: n, scale: r }) {
353
+ const { bodyWidth: s, bodyHeight: i, screenWidth: a, screenHeight: u } = t.frame, m = a * r, d = u * r;
354
+ return /* @__PURE__ */ x("div", { className: "rc-duo-fold-still", style: { width: s * r, height: i * r }, children: [
355
+ /* @__PURE__ */ o(Q, { inner: t.inner, width: s, height: i }),
356
+ /* @__PURE__ */ o(
357
+ "div",
358
+ {
359
+ className: "rc-duo-flat-screen",
360
+ style: {
361
+ width: m,
362
+ height: d,
363
+ left: (s - a) * r / 2,
364
+ top: (i - u) * r / 2,
365
+ borderRadius: t.inner ? 5.3 * r : [0.8, 6.6, 6.6, 0.8].map((l) => l * r + "px").join(" ")
366
+ },
367
+ children: n && /* @__PURE__ */ o(
368
+ "canvas",
369
+ {
370
+ ref: (l) => {
371
+ l && (l.width = n.width, l.height = n.height, l.getContext("2d")?.drawImage(n, 0, 0));
372
+ },
373
+ style: {
374
+ width: t.inner ? d : m,
375
+ height: t.inner ? m : d,
376
+ transform: `translate(-50%, -50%) rotate(${t.inner ? 90 : 0}deg)`
377
+ }
378
+ }
379
+ )
380
+ }
381
+ )
382
+ ] });
383
+ }
384
+ function Ct({ motion: t, onFinish: n }) {
385
+ const r = M(null), [s, i] = W(!1);
386
+ return T(() => {
387
+ if (i(!1), !t.ready) return;
388
+ let a = !1, u;
389
+ return import("./duo-fold-renderer-BXejNHcY.mjs").then(({ renderFold: m }) => {
390
+ a || !r.current || (u = m(r.current, t, n), i(!0));
391
+ }).catch(() => {
392
+ a || n();
393
+ }), () => {
394
+ a = !0, u?.();
395
+ };
396
+ }, [t.ready, t.from, n]), /* @__PURE__ */ x(z, { children: [
397
+ !s && /* @__PURE__ */ o(
398
+ "div",
399
+ {
400
+ className: "rc-duo-fold-hold",
401
+ "aria-hidden": "true",
402
+ style: {
403
+ width: t.from.frame.bodyWidth * t.from.frame.scale,
404
+ height: t.from.frame.bodyHeight * t.from.frame.scale,
405
+ transform: `translate(-50%, -50%) rotate(${t.from.frame.turns * 90}deg)`
406
+ },
407
+ children: /* @__PURE__ */ o(Mt, { pose: t.from, image: t.before, scale: t.from.frame.scale })
408
+ }
409
+ ),
410
+ /* @__PURE__ */ o(
411
+ "canvas",
412
+ {
413
+ ref: r,
414
+ className: "rc-duo-fold-canvas",
415
+ "aria-hidden": "true",
416
+ style: { visibility: s ? "visible" : "hidden" }
417
+ }
418
+ )
419
+ ] });
420
+ }
421
+ const kt = ct(() => import("./duo-frame-DGBuQved.mjs").then((t) => t.ac));
422
+ function Dt(t) {
423
+ const [n, r] = W("2d");
424
+ return /* @__PURE__ */ x("div", { className: "rc-duo-view", children: [
425
+ t.showFrame !== !1 && n === "3d" ? /* @__PURE__ */ o(st, { fallback: /* @__PURE__ */ o(Z, { ...t }), children: /* @__PURE__ */ o(kt, { ...t }) }) : /* @__PURE__ */ o(Z, { ...t }),
426
+ t.showFrame !== !1 && /* @__PURE__ */ x("div", { className: "rc-duo-mode", role: "group", "aria-label": "Device rendering", children: [
427
+ /* @__PURE__ */ o("button", { type: "button", "aria-pressed": n === "2d", onClick: () => r("2d"), children: "2D" }),
428
+ /* @__PURE__ */ o("button", { type: "button", "aria-pressed": n === "3d", onClick: () => r("3d"), children: "3D" })
429
+ ] })
430
+ ] });
431
+ }
432
+ function Z(t) {
433
+ const n = t.showFrame !== !1, r = M(null), s = M(null), i = M(t);
434
+ i.current = t;
435
+ const [a, u] = W({ width: 0, height: 0 }), [m, d] = W(), [l, h] = W(), [H, D] = W(), [N, g] = W(), b = M(void 0), v = M(null);
436
+ v.current || (v.current = new ut((...e) => i.current.touch(...e)));
437
+ const w = M(null), p = lt(t.state), F = p?.id === "inner" ? t.inner : t.outer, y = ht(p?.orientation), f = p?.id === "inner", P = { portrait: 0, pud: 2, "landscape-left": 3, "landscape-right": 1 }[t.state.orientation], R = n ? (P + (f ? 1 : 0)) % 4 : y, C = yt(f, R, a.width, a.height), U = n ? C.screenWidth : (f ? p?.height : p?.width) ?? 1, V = n ? C.screenHeight : (f ? p?.width : p?.height) ?? 1, E = n ? C.bodyWidth : U, O = n ? C.bodyHeight : V, k = n ? C.scale : Math.max(
438
+ 0,
439
+ Math.min(
440
+ a.width / (C.turns % 2 ? O : E),
441
+ a.height / (C.turns % 2 ? E : O)
442
+ )
443
+ ), B = U * k, K = V * k;
444
+ T(() => {
445
+ const e = new ResizeObserver(([c]) => {
446
+ c && u({ width: c.contentRect.width, height: c.contentRect.height });
447
+ });
448
+ return r.current && e.observe(r.current), () => e.disconnect();
449
+ }, []), T(() => {
450
+ const e = s.current;
451
+ if (!e || !F) return;
452
+ const c = () => {
453
+ e.srcObject !== F.srcObject && (e.srcObject = F.srcObject), e.play().catch(() => {
454
+ }), t.outer?.pause(), t.inner?.pause();
455
+ };
456
+ return c(), F.addEventListener("loadedmetadata", c), () => {
457
+ F.removeEventListener("loadedmetadata", c), e.pause(), e.srcObject = null;
458
+ for (const X of [t.outer, t.inner]) X?.play().catch(() => {
459
+ });
460
+ };
461
+ }, [F, t.outer, t.inner]);
462
+ const {
463
+ motion: S,
464
+ finish: $,
465
+ prepare: tt
466
+ } = xt(s, f, C, t.state.orientation, n), { angle: et, changeAngle: rt, interacting: nt } = mt(
467
+ t.state.angleDegrees,
468
+ async (e) => {
469
+ tt(e >= 90);
470
+ try {
471
+ await t.setAngle(e);
472
+ } catch (c) {
473
+ throw $(), c;
474
+ }
475
+ },
476
+ d
477
+ ), I = () => {
478
+ v.current?.release(), b.current = void 0;
479
+ };
480
+ T(() => {
481
+ w.current = new ft(
482
+ (c, X) => i.current.button(c, X),
483
+ (c) => d(String(c))
484
+ );
485
+ const e = () => {
486
+ I(), w.current?.release(), g(void 0);
487
+ };
488
+ return window.addEventListener("blur", e), () => {
489
+ e(), window.removeEventListener("blur", e);
490
+ };
491
+ }, []), T(() => {
492
+ v.current?.setDisplay(p, R), v.current?.active || (b.current = void 0);
493
+ }, [p, R]);
494
+ const L = () => {
495
+ w.current?.release(), g(void 0);
496
+ }, q = (e) => ({
497
+ disabled: t.watchOnly,
498
+ onPointerDown: (c) => {
499
+ t.watchOnly || S || c.button !== 0 || (c.currentTarget.setPointerCapture(c.pointerId), w.current?.press(e), g(e));
500
+ },
501
+ onPointerUp: L,
502
+ onPointerCancel: L,
503
+ onLostPointerCapture: L,
504
+ onBlur: L,
505
+ onPointerEnter: () => D(e),
506
+ onPointerLeave: () => D(void 0),
507
+ onFocus: () => h(C.guides.find((c) => c.button === e)?.edge),
508
+ onKeyDown: (c) => {
509
+ S || (c.key === "Enter" || c.key === " ") && (c.preventDefault(), c.repeat || (w.current?.press(e), g(e)));
510
+ },
511
+ onKeyUp: (c) => {
512
+ (c.key === "Enter" || c.key === " ") && (c.preventDefault(), L());
513
+ }
514
+ }), G = (e) => {
515
+ const c = e.currentTarget.getBoundingClientRect();
516
+ return { x: (e.clientX - c.left) / c.width, y: (e.clientY - c.top) / c.height };
517
+ };
518
+ return /* @__PURE__ */ x("div", { className: n ? "rc-duo" : "rc-duo rc-duo-frameless", children: [
519
+ /* @__PURE__ */ x(
520
+ "div",
521
+ {
522
+ ref: r,
523
+ className: "rc-duo-flat-stage",
524
+ "data-folding": !!S,
525
+ "aria-busy": !!S,
526
+ onPointerMove: (e) => {
527
+ if (!n) return;
528
+ const c = e.currentTarget.getBoundingClientRect();
529
+ h(vt(e.clientX - c.left, e.clientY - c.top, C.rect));
530
+ },
531
+ onPointerLeave: () => {
532
+ h(void 0), D(void 0);
533
+ },
534
+ children: [
535
+ /* @__PURE__ */ x(
536
+ "div",
537
+ {
538
+ className: "rc-duo-flat-device",
539
+ "data-display": f ? "inner" : "outer",
540
+ style: {
541
+ width: E * k,
542
+ height: O * k,
543
+ transform: "translate(-50%, -50%) rotate(" + C.turns * 90 + "deg)"
544
+ },
545
+ children: [
546
+ n && /* @__PURE__ */ o(Q, { inner: f, width: E, height: O }),
547
+ /* @__PURE__ */ o(
548
+ "div",
549
+ {
550
+ className: "rc-duo-flat-screen",
551
+ role: "application",
552
+ "aria-label": "iPhone Duo 2D simulator",
553
+ tabIndex: 0,
554
+ style: {
555
+ width: B,
556
+ height: K,
557
+ left: (E - U) / 2 * k,
558
+ top: (O - V) / 2 * k,
559
+ borderRadius: n ? f ? 5.3 * k : [0.8, 6.6, 6.6, 0.8].map((e) => e * k + "px").join(" ") : 0
560
+ },
561
+ onKeyDown: S ? void 0 : t.onKeyDown,
562
+ onKeyUp: t.onKeyUp,
563
+ onPointerDown: (e) => {
564
+ if (t.watchOnly || S || b.current !== void 0 || e.button !== 0 || !p)
565
+ return;
566
+ e.currentTarget.focus({ preventScroll: !0 }), e.currentTarget.setPointerCapture(e.pointerId);
567
+ const c = G(e);
568
+ b.current = e.pointerId, v.current?.touch("begin", c.x, c.y);
569
+ },
570
+ onPointerMove: (e) => {
571
+ if (b.current !== e.pointerId) return;
572
+ const c = G(e);
573
+ v.current?.touch("move", c.x, c.y);
574
+ },
575
+ onPointerUp: (e) => {
576
+ b.current === e.pointerId && I();
577
+ },
578
+ onPointerCancel: I,
579
+ onLostPointerCapture: I,
580
+ children: /* @__PURE__ */ o(
581
+ "video",
582
+ {
583
+ ref: s,
584
+ autoPlay: !0,
585
+ muted: !0,
586
+ playsInline: !0,
587
+ style: {
588
+ width: f ? K : B,
589
+ height: f ? B : K,
590
+ transform: "translate(-50%, -50%) rotate(" + (f ? 90 : 0) + "deg)"
591
+ }
592
+ }
593
+ )
594
+ }
595
+ ),
596
+ n && C.buttons.map((e) => /* @__PURE__ */ o(
597
+ "button",
598
+ {
599
+ type: "button",
600
+ className: "rc-duo-physical",
601
+ "data-duo-button": e.button,
602
+ "data-edge": e.edge,
603
+ "data-highlighted": H === e.button,
604
+ "data-pressed": N === e.button,
605
+ "aria-label": j[e.button] + " physical button",
606
+ title: j[e.button],
607
+ style: {
608
+ left: e.x * k,
609
+ top: e.y * k,
610
+ width: e.edge === "top" ? Math.max(28, e.width * k) : 28,
611
+ height: e.edge === "top" ? 28 : Math.max(28, e.height * k)
612
+ },
613
+ ...q(e.button),
614
+ children: /* @__PURE__ */ o(
615
+ "span",
616
+ {
617
+ style: { width: Math.max(2, e.width * k), height: Math.max(2, e.height * k) }
618
+ }
619
+ )
620
+ },
621
+ e.button
622
+ ))
623
+ ]
624
+ }
625
+ ),
626
+ n && C.guides.map((e) => /* @__PURE__ */ o(
627
+ "button",
628
+ {
629
+ type: "button",
630
+ className: "rc-duo-hardware",
631
+ "data-duo-button": e.button,
632
+ "data-visible": l === e.edge,
633
+ "data-pressed": N === e.button,
634
+ "aria-label": j[e.button],
635
+ title: j[e.button],
636
+ style: {
637
+ left: e.targetX,
638
+ top: e.targetY,
639
+ "--duo-hardware-icon-size": `${C.iconSize}px`,
640
+ "--duo-hardware-icon-x": `${e.x - e.targetX}px`,
641
+ "--duo-hardware-icon-y": `${e.y - e.targetY}px`
642
+ },
643
+ ...q(e.button),
644
+ children: /* @__PURE__ */ o(gt, { button: e.button })
645
+ },
646
+ e.button
647
+ )),
648
+ S && /* @__PURE__ */ o(Ct, { motion: S, onFinish: $ })
649
+ ]
650
+ }
651
+ ),
652
+ n && /* @__PURE__ */ o(
653
+ pt,
654
+ {
655
+ watchOnly: t.watchOnly,
656
+ angle: et,
657
+ changeAngle: rt,
658
+ interacting: nt,
659
+ rotate: () => {
660
+ t.setOrientation(t.state.orientation === "portrait" ? "landscape-left" : "portrait").catch((e) => d(String(e)));
661
+ },
662
+ children: /* @__PURE__ */ o("span", { className: "rc-duo-view-label", children: "Front view" })
663
+ }
664
+ ),
665
+ m && /* @__PURE__ */ o("div", { role: "alert", className: "rc-duo-error", children: m })
666
+ ] });
667
+ }
668
+ const Ht = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
669
+ __proto__: null,
670
+ default: Dt
671
+ }, Symbol.toStringTag, { value: "Module" }));
672
+ export {
673
+ gt as D,
674
+ pt as a,
675
+ Ht as d,
676
+ vt as f,
677
+ bt as h,
678
+ mt as u
679
+ };