@limrun/ui 0.21.0 → 0.22.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.
Files changed (45) hide show
  1. package/README.md +36 -8
  2. package/dist/BufferGeometryUtils-Dm5SmmmT.mjs +64 -0
  3. package/dist/BufferGeometryUtils-Dne8i0aT.js +1 -0
  4. package/dist/GLTFLoader-DzSwAt9C.js +1 -0
  5. package/dist/{GLTFLoader-D4AITfgZ.mjs → GLTFLoader-L51A9w-A.mjs} +138 -137
  6. package/dist/components/device-view.d.ts +29 -0
  7. package/dist/components/duo-frame.d.ts +5 -1
  8. package/dist/components/duo-model.d.ts +2 -1
  9. package/dist/components/macbook-frame.d.ts +30 -0
  10. package/dist/components/macbook-geometry.d.ts +77 -0
  11. package/dist/components/model-source.d.ts +8 -0
  12. package/dist/components/remote-control.d.ts +40 -1
  13. package/dist/components/studio-environment.d.ts +6 -0
  14. package/dist/core/mac-pointer.d.ts +56 -0
  15. package/dist/{core-CRIachT9.mjs → core-nbvkIrvp.mjs} +24 -24
  16. package/dist/core.js +12 -12
  17. package/dist/duo-frame-CHI6g7BR.mjs +758 -0
  18. package/dist/duo-frame-Cj-xHHW3.js +11 -0
  19. package/dist/duo-model-BYgtCaCR.mjs +4 -0
  20. package/dist/duo-model-CDWgmLRF.js +1 -0
  21. package/dist/duo-model.d.ts +2 -0
  22. package/dist/{duo-view-BeqYIqfQ.mjs → duo-view-Biy9MAlH.mjs} +84 -86
  23. package/dist/duo-view-D0Ndj2Ee.js +1 -0
  24. package/dist/index.cjs +1 -1
  25. package/dist/index.css +1 -1
  26. package/dist/index.js +32 -25
  27. package/dist/lite.cjs +1 -1
  28. package/dist/lite.js +2 -2
  29. package/dist/macbook-frame-BHQtQNGV.mjs +349 -0
  30. package/dist/macbook-frame-CQyZhRFn.js +3 -0
  31. package/dist/macbook-model-BiMxLpmf.mjs +4 -0
  32. package/dist/macbook-model-BpUdvtlU.js +1 -0
  33. package/dist/macbook-model.d.ts +2 -0
  34. package/dist/meshopt_decoder.module-C4Z_evpr.mjs +217 -0
  35. package/dist/meshopt_decoder.module-DxJdu6ez.js +1 -0
  36. package/dist/{duo-frame-D1JK_cRk.mjs → model-source-BjSq5Any.mjs} +5353 -6125
  37. package/dist/model-source-S12HoOoQ.js +4049 -0
  38. package/dist/remote-control-BGKETUbE.mjs +1746 -0
  39. package/dist/remote-control-OLgfUSR1.js +1 -0
  40. package/package.json +1 -1
  41. package/dist/GLTFLoader-C25N9Y4j.js +0 -1
  42. package/dist/duo-frame-B1NXSk6a.js +0 -4059
  43. package/dist/duo-view-PsR5b045.js +0 -1
  44. package/dist/remote-control-DNr0Pyrx.js +0 -1
  45. package/dist/remote-control-rdm3mDtI.mjs +0 -1299
package/dist/lite.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./remote-control-DNr0Pyrx.js"),e=require("./core-BCBQrYsk.js");exports.RemoteControl=r.RemoteControl;exports.AX_UNAVAILABLE_ERROR=e.AX_UNAVAILABLE_ERROR;exports.axElementAtPoint=e.axElementAtPoint;exports.axElementSelectorExpression=e.axElementSelectorExpression;exports.axElementSummary=e.axElementSummary;exports.axElementsEqual=e.axElementsEqual;exports.axSnapshotsEqual=e.axSnapshotsEqual;exports.clampAxFrameForScreen=e.clampAxFrameForScreen;exports.normalizeAndroidTree=e.normalizeAndroidTree;exports.normalizeIosTree=e.normalizeIosTree;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./remote-control-OLgfUSR1.js"),e=require("./core-BCBQrYsk.js");exports.RemoteControl=r.RemoteControl;exports.AX_UNAVAILABLE_ERROR=e.AX_UNAVAILABLE_ERROR;exports.axElementAtPoint=e.axElementAtPoint;exports.axElementSelectorExpression=e.axElementSelectorExpression;exports.axElementSummary=e.axElementSummary;exports.axElementsEqual=e.axElementsEqual;exports.axSnapshotsEqual=e.axSnapshotsEqual;exports.clampAxFrameForScreen=e.clampAxFrameForScreen;exports.normalizeAndroidTree=e.normalizeAndroidTree;exports.normalizeIosTree=e.normalizeIosTree;
package/dist/lite.js CHANGED
@@ -1,5 +1,5 @@
1
- import { R as o } from "./remote-control-rdm3mDtI.mjs";
2
- import { A as s, a as m, b as n, c as t, d as l, e as x, f as E, n as A, g as i } from "./core-CRIachT9.mjs";
1
+ import { R as o } from "./remote-control-BGKETUbE.mjs";
2
+ import { A as s, a as m, b as n, c as t, d as l, e as x, f as E, n as A, g as i } from "./core-nbvkIrvp.mjs";
3
3
  export {
4
4
  s as AX_UNAVAILABLE_ERROR,
5
5
  o as RemoteControl,
@@ -0,0 +1,349 @@
1
+ import { jsxs as Y, jsx as A } from "react/jsx-runtime";
2
+ import { useRef as v, useState as G, useId as ut, useEffect as He } from "react";
3
+ import { W as mt, S as qe, A as ft, a as pt, c as ht, H as vt, D as ze, P as wt, V as bt, L as $e, M as yt, b as tt, G as pe, B as gt, I as Mt, d as he, e as ve, f as Et, g as Ze, l as kt, T as Lt, R as xt, h as N, i as K, j as Je, k as Ot } from "./model-source-BjSq5Any.mjs";
4
+ import { M as D, l as se, m as Ct, a as St, b as At, c as Dt, d as Bt, s as Ft, e as Qe } from "./remote-control-BGKETUbE.mjs";
5
+ const X = {
6
+ front: { yaw: 0, pitch: 0.1, label: "Front" },
7
+ desk: { yaw: -0.5, pitch: 0.42, label: "Desk" },
8
+ side: { yaw: -1.15, pitch: 0.16, label: "Side" }
9
+ }, et = 28;
10
+ function Pt(p, W) {
11
+ const o = tt;
12
+ switch (p) {
13
+ case "screen":
14
+ return W;
15
+ case "shell":
16
+ return new K({ color: 3421498, metalness: 0.9, roughness: 0.34, side: o });
17
+ case "glass":
18
+ return new Je({ color: 328966, roughness: 0.06, clearcoat: 1, side: o });
19
+ case "camera":
20
+ return new K({ color: 790549, roughness: 0.2, side: o });
21
+ case "well":
22
+ return new K({ color: 1052690, roughness: 0.9, side: o });
23
+ case "keys":
24
+ return new K({ color: 723725, roughness: 0.7, side: o });
25
+ case "trackpad":
26
+ return new Je({
27
+ color: 2895153,
28
+ metalness: 0.4,
29
+ roughness: 0.3,
30
+ clearcoat: 0.6,
31
+ side: o
32
+ });
33
+ case "scoop":
34
+ return new K({ color: 1579035, metalness: 0.6, roughness: 0.5, side: o });
35
+ }
36
+ }
37
+ const It = {
38
+ glass: 1,
39
+ camera: 2,
40
+ screen: 2,
41
+ well: 1,
42
+ keys: 2,
43
+ trackpad: 1,
44
+ scoop: 1
45
+ };
46
+ function Vt(p) {
47
+ const W = v(null), o = v(p);
48
+ o.current = p;
49
+ const [we, ie] = G(), [nt, ot] = G(!1), be = v(!1), [U, rt] = G("front"), j = v(U);
50
+ j.current = U;
51
+ const H = v(0), [y, st] = G(!1), ye = v(y);
52
+ ye.current = y;
53
+ const T = v(() => {
54
+ }), B = v(D), m = v(D), [q, ce] = G(D), z = v(
55
+ void 0
56
+ ), ge = ut(), Me = (n) => {
57
+ const i = m.current;
58
+ B.current = n, z.current = {
59
+ from: i,
60
+ to: n,
61
+ start: performance.now(),
62
+ duration: Dt * Math.abs(n - i) / D
63
+ }, T.current();
64
+ };
65
+ return He(() => T.current(), [U, y]), He(() => {
66
+ const n = W.current, i = p.video;
67
+ if (!n || !i) return;
68
+ const Ee = () => {
69
+ ot(!0), o.current.onReady?.();
70
+ };
71
+ ie(void 0);
72
+ let a;
73
+ try {
74
+ a = new mt({ antialias: !0, alpha: !0 });
75
+ } catch {
76
+ ie("3D rendering is unavailable in this browser. Enable WebGL to use the 3D MacBook."), Ee();
77
+ return;
78
+ }
79
+ a.setPixelRatio(Math.min(window.devicePixelRatio, 2)), a.outputColorSpace = qe, a.toneMapping = ft, a.setClearColor(0, 0), n.appendChild(a.domElement);
80
+ const L = new pt(), ke = ht(a);
81
+ L.environment = ke.texture, L.environmentIntensity = 0.45, L.add(new vt(16777215, 12699857, 1));
82
+ const Le = new ze(16777215, 2.2);
83
+ Le.position.set(-120, 220, 260), L.add(Le);
84
+ const xe = new ze(15003135, 0.7);
85
+ xe.position.set(220, 40, -220), L.add(xe);
86
+ const F = new wt(et, 1, 10, 4e3), g = new bt(i);
87
+ g.colorSpace = qe, g.minFilter = $e, g.magFilter = $e, g.anisotropy = a.capabilities.getMaxAnisotropy();
88
+ const P = new yt({
89
+ map: g,
90
+ toneMapped: !1,
91
+ side: tt
92
+ }), Oe = { value: !1 };
93
+ P.onBeforeCompile = (e) => {
94
+ e.uniforms.fillAbove = Oe, e.fragmentShader = `uniform bool fillAbove;
95
+ ${e.fragmentShader}`.replace(
96
+ "#include <map_fragment>",
97
+ `#include <map_fragment>
98
+ if (vMapUv.x < 0.0 || vMapUv.x > 1.0 || vMapUv.y < 0.0 || (vMapUv.y > 1.0 && !fillAbove)) diffuseColor.rgb = vec3(0.0);`
99
+ );
100
+ }, P.customProgramCacheKey = () => "macbook-fitted-screen";
101
+ let V = o.current.aspect, ae = 0, I = Qe(V, V);
102
+ const it = () => {
103
+ const e = i.videoWidth && i.videoHeight ? i.videoWidth / i.videoHeight : V;
104
+ I = Qe(e, V, ae), g.repeat.set(I.repeat[0], I.repeat[1]), g.offset.set(I.offset[0], I.offset[1]);
105
+ }, M = new pe(), w = new pe(), f = new pe();
106
+ f.rotation.x = se(m.current), w.add(f), M.add(w), L.add(M);
107
+ const Ce = [P], $ = [];
108
+ let Z;
109
+ for (const e of Ct(o.current.aspect)) {
110
+ const t = new gt(), l = new Mt(e.vertices, St);
111
+ t.setAttribute("position", new he(l, 3, 0)), t.setAttribute("normal", new he(l, 3, 3)), t.setAttribute("uv", new he(l, 2, 6));
112
+ const s = Pt(e.kind, P), c = It[e.kind];
113
+ c && (s.polygonOffset = !0, s.polygonOffsetFactor = -c, s.polygonOffsetUnits = -c);
114
+ const h = new ve(t, s);
115
+ e.kind === "screen" && (Z = h), (e.part === "lid" ? f : w).add(h), $.push(t), s !== P && $.push(s);
116
+ }
117
+ const Se = new Et(), Ae = (e) => {
118
+ const t = f.rotation.x;
119
+ return f.rotation.x = se(D), e.updateMatrixWorld(!0), Se.setFromObject(e), f.rotation.x = t, Se;
120
+ }, De = () => {
121
+ M.rotation.set(0, 0, 0), w.position.set(0, 0, 0), w.position.copy(Ae(M).getCenter(new Ze())).negate();
122
+ };
123
+ De();
124
+ const ct = !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
125
+ let le = !1;
126
+ const Be = () => {
127
+ M.visible = !0, !be.current && o.current.animateLid !== !1 && !ct && (m.current = 0, f.rotation.x = se(0), ce(0), Me(D)), be.current = !0, le = !0, u();
128
+ }, at = async (e) => {
129
+ const [{ GLTFLoader: t }, { MeshoptDecoder: l }] = await Promise.all([
130
+ import("./GLTFLoader-L51A9w-A.mjs"),
131
+ import("./meshopt_decoder.module-C4Z_evpr.mjs")
132
+ ]), { scene: s } = await kt(new t().setMeshoptDecoder(l), e), c = [];
133
+ if (s.traverse((d) => {
134
+ if (d instanceof ve) {
135
+ c.push(d.geometry);
136
+ for (const Ue of Array.isArray(d.material) ? d.material : [d.material]) {
137
+ c.push(Ue);
138
+ for (const je of Object.values(Ue)) je instanceof Lt && c.push(je);
139
+ }
140
+ }
141
+ }), O) {
142
+ for (const d of c) d.dispose();
143
+ return;
144
+ }
145
+ Ce.push(...c);
146
+ const h = s.getObjectByName("macbook-base"), C = s.getObjectByName("macbook-lid"), k = s.getObjectByName("macbook-screen");
147
+ if (!h || !C || !(k instanceof ve))
148
+ throw new Error("it has no macbook-base, macbook-lid or macbook-screen");
149
+ for (const d of [...w.children]) d !== f && w.remove(d);
150
+ f.clear(), w.add(h);
151
+ for (const d of [...C.children]) f.add(d);
152
+ k.material = P, Z = k;
153
+ const b = k.userData.aspect;
154
+ typeof b == "number" && b > 0 && (V = b);
155
+ const S = k.userData.notch;
156
+ typeof S == "number" && S >= 0 && S < 0.5 && (ae = S), Oe.value = ae > 0;
157
+ for (const d of $.splice(0)) d.dispose();
158
+ De();
159
+ }, de = o.current.model;
160
+ de && (M.visible = !1, at(de).catch((e) => {
161
+ O || ie(
162
+ `The MacBook model could not load: ${e instanceof Error ? e.message : e}`
163
+ );
164
+ }).finally(() => {
165
+ O || Be();
166
+ }));
167
+ const J = new Ze();
168
+ let x = 0;
169
+ const Fe = new xt(), Pe = new Ot();
170
+ let r, ue = 0, Q = 0, R = X[j.current].yaw, _ = X[j.current].pitch, Ie = H.current, me = 1, ee = 0, Re = 0, O = !1, fe = !0;
171
+ const u = () => {
172
+ !ee && fe && !document.hidden && !O && (ee = requestAnimationFrame(lt));
173
+ };
174
+ T.current = u;
175
+ const te = (e) => {
176
+ if (!Z) return;
177
+ const t = a.domElement.getBoundingClientRect();
178
+ Pe.set(
179
+ (e.clientX - t.left) / t.width * 2 - 1,
180
+ 1 - (e.clientY - t.top) / t.height * 2
181
+ ), Fe.setFromCamera(Pe, F);
182
+ const l = Fe.intersectObject(w, !0)[0], s = l?.object === Z ? l.uv : void 0;
183
+ return s && Ft(s.x, s.y, I);
184
+ }, _e = (e) => {
185
+ if (u(), r) return;
186
+ const t = o.current.watchOnly || e.altKey ? void 0 : te(e);
187
+ !t && (ye.current || e.button !== 0) || (n.focus({ preventScroll: !0 }), n.setPointerCapture(e.pointerId), r = {
188
+ pointer: e.pointerId,
189
+ kind: t ? "screen" : "orbit",
190
+ clientX: e.clientX,
191
+ clientY: e.clientY,
192
+ x: t?.x ?? 0,
193
+ y: t?.y ?? 0
194
+ }, t && o.current.pointer("down", t.x, t.y, e.buttons));
195
+ }, Ne = (e) => {
196
+ if (u(), !r) {
197
+ const t = o.current.watchOnly ? void 0 : te(e);
198
+ a.domElement.style.cursor = t ? "none" : "", t && o.current.pointer("move", t.x, t.y, 0);
199
+ return;
200
+ }
201
+ if (r.pointer === e.pointerId) {
202
+ if (r.kind === "screen") {
203
+ const t = te(e);
204
+ t && (r.x = t.x, r.y = t.y), o.current.pointer("move", r.x, r.y, e.buttons);
205
+ } else
206
+ ue += (e.clientX - r.clientX) * 8e-3, Q = N.clamp(Q + (e.clientY - r.clientY) * 8e-3, -1.2, 1.2);
207
+ r.clientX = e.clientX, r.clientY = e.clientY;
208
+ }
209
+ }, E = (e) => {
210
+ u(), !(!r || e && r.pointer !== e.pointerId) && (r.kind === "screen" && o.current.pointer("up", r.x, r.y, e?.buttons ?? 0), r = void 0);
211
+ }, Te = (e) => {
212
+ if (o.current.watchOnly || e.ctrlKey) return;
213
+ const t = te(e);
214
+ if (!t) return;
215
+ e.preventDefault();
216
+ const l = e.deltaMode === WheelEvent.DOM_DELTA_LINE ? 16 : e.deltaMode === WheelEvent.DOM_DELTA_PAGE ? n.clientHeight : 1;
217
+ o.current.scroll(t.x, t.y, e.deltaX * l, e.deltaY * l);
218
+ }, ne = (e) => e.stopPropagation(), Ve = [
219
+ "mousedown",
220
+ "mousemove",
221
+ "mouseup",
222
+ "touchstart",
223
+ "touchmove",
224
+ "touchend",
225
+ "touchcancel"
226
+ ];
227
+ for (const e of Ve) n.addEventListener(e, ne);
228
+ const Ye = (e) => e.preventDefault(), oe = () => {
229
+ E(), o.current.onBlur();
230
+ };
231
+ n.addEventListener("pointerdown", _e), n.addEventListener("pointermove", Ne), n.addEventListener("pointerup", E), n.addEventListener("pointercancel", E), n.addEventListener("lostpointercapture", E), n.addEventListener("wheel", Te, { passive: !1 }), n.addEventListener("wheel", ne), n.addEventListener("contextmenu", Ye), n.addEventListener("focusout", oe), window.addEventListener("blur", oe);
232
+ const Ge = () => {
233
+ const e = n.clientWidth, t = n.clientHeight;
234
+ !e || !t || (me = e / t, F.aspect = me, F.updateProjectionMatrix(), a.setSize(e, t, !1), u());
235
+ }, Ke = new ResizeObserver(Ge);
236
+ Ke.observe(n);
237
+ const lt = (e) => {
238
+ if (ee = 0, O || !fe || document.hidden) return;
239
+ const t = Math.min((e - Re) / 1e3, 0.05);
240
+ Re = e, H.current !== Ie && (ue = 0, Q = 0, Ie = H.current);
241
+ const l = X[j.current];
242
+ let s = !1;
243
+ const c = z.current;
244
+ if (c) {
245
+ const S = c.duration > 0 ? (e - c.start) / c.duration : 1;
246
+ m.current = c.from + (c.to - c.from) * Bt(S), S >= 1 ? z.current = void 0 : s = !0, ce(m.current);
247
+ } else m.current !== B.current && (m.current = N.damp(m.current, B.current, 14, t), Math.abs(m.current - B.current) < 0.05 ? m.current = B.current : s = !0);
248
+ f.rotation.x = se(m.current);
249
+ const h = l.yaw + ue, C = l.pitch + Q;
250
+ R = N.damp(R, h, 10, t), _ = N.damp(_, C, 10, t), Math.abs(R - h) < 5e-4 && (R = h), Math.abs(_ - C) < 5e-4 && (_ = C), it(), M.rotation.set(_, R, 0, "XYZ"), Ae(M).getSize(J);
251
+ const k = Math.tan(N.degToRad(et / 2)), b = Math.max(J.y / 2 / k, J.x / 2 / (k * me)) * 1.12 + J.z / 2;
252
+ x = x ? N.damp(x, b, 10, t) : b, Math.abs(x - b) < 0.01 && (x = b), F.position.set(0, 0, x), F.lookAt(0, 0, 0), a.render(L, F), le && (le = !1, Ee()), (s || R !== h || _ !== C || x !== b) && u();
253
+ };
254
+ let re;
255
+ const Xe = () => {
256
+ O || (u(), re = i.requestVideoFrameCallback(Xe));
257
+ };
258
+ "requestVideoFrameCallback" in i && (re = i.requestVideoFrameCallback(Xe));
259
+ const dt = "requestVideoFrameCallback" in i ? void 0 : window.setInterval(u, 1e3 / 30), We = new IntersectionObserver(([e]) => {
260
+ fe = !!e?.isIntersecting, u();
261
+ });
262
+ return We.observe(n), document.addEventListener("visibilitychange", u), Ge(), de || Be(), () => {
263
+ O = !0, T.current = () => {
264
+ }, E(), cancelAnimationFrame(ee), re !== void 0 && i.cancelVideoFrameCallback(re), clearInterval(dt), We.disconnect(), Ke.disconnect(), document.removeEventListener("visibilitychange", u);
265
+ for (const e of Ve) n.removeEventListener(e, ne);
266
+ n.removeEventListener("pointerdown", _e), n.removeEventListener("pointermove", Ne), n.removeEventListener("pointerup", E), n.removeEventListener("pointercancel", E), n.removeEventListener("lostpointercapture", E), n.removeEventListener("wheel", Te), n.removeEventListener("wheel", ne), n.removeEventListener("contextmenu", Ye), n.removeEventListener("focusout", oe), window.removeEventListener("blur", oe);
267
+ for (const e of [...Ce, ...$]) e.dispose();
268
+ g.dispose(), ke.dispose(), a.dispose(), a.forceContextLoss(), a.domElement.remove();
269
+ };
270
+ }, [p.video, p.aspect, p.model]), // The Duo's 3D styles serve every 3D device frame.
271
+ // Unseen until its first frame, so the host's 2D MacBook shows while the model loads.
272
+ /* @__PURE__ */ Y("div", { className: "rc-duo rc-macbook-3d", style: nt ? void 0 : { visibility: "hidden" }, children: [
273
+ /* @__PURE__ */ A(
274
+ "div",
275
+ {
276
+ ref: W,
277
+ className: "rc-duo-stage",
278
+ "data-position-locked": y,
279
+ tabIndex: 0,
280
+ role: "application",
281
+ "aria-label": "MacBook running macOS. Use the screen to control the guest. Drag around the MacBook to turn it when position is unlocked.",
282
+ onKeyDown: p.onKeyDown,
283
+ onKeyUp: p.onKeyUp
284
+ }
285
+ ),
286
+ /* @__PURE__ */ Y("div", { className: "rc-duo-controls", onPointerDown: (n) => n.stopPropagation(), children: [
287
+ /* @__PURE__ */ Y("div", { className: "rc-duo-hinge", children: [
288
+ /* @__PURE__ */ A(
289
+ "button",
290
+ {
291
+ type: "button",
292
+ className: "rc-duo-fold",
293
+ onClick: () => Me(q < 45 ? D : 0),
294
+ children: q < 45 ? "Open" : "Close"
295
+ }
296
+ ),
297
+ /* @__PURE__ */ A("label", { htmlFor: ge, children: "Lid" }),
298
+ /* @__PURE__ */ A(
299
+ "input",
300
+ {
301
+ id: ge,
302
+ type: "range",
303
+ min: 0,
304
+ max: At,
305
+ step: 1,
306
+ value: Math.round(q),
307
+ onChange: (n) => {
308
+ const i = Number(n.target.value);
309
+ z.current = void 0, B.current = i, ce(i), T.current();
310
+ }
311
+ }
312
+ ),
313
+ /* @__PURE__ */ Y("output", { children: [
314
+ Math.round(q),
315
+ "°"
316
+ ] })
317
+ ] }),
318
+ /* @__PURE__ */ Y("div", { className: "rc-duo-views", children: [
319
+ Object.keys(X).map((n) => /* @__PURE__ */ A(
320
+ "button",
321
+ {
322
+ type: "button",
323
+ "aria-pressed": U === n,
324
+ onClick: () => {
325
+ H.current++, rt(n);
326
+ },
327
+ children: X[n].label
328
+ },
329
+ n
330
+ )),
331
+ /* @__PURE__ */ A(
332
+ "button",
333
+ {
334
+ type: "button",
335
+ className: "rc-duo-lock",
336
+ "aria-pressed": y,
337
+ title: y ? "Position is locked. The screen still controls macOS." : "Drag around the MacBook to turn it. Alt-drag turns it from the screen.",
338
+ onClick: () => st(!y),
339
+ children: y ? "Position locked" : "Lock position"
340
+ }
341
+ )
342
+ ] })
343
+ ] }),
344
+ we && /* @__PURE__ */ A("div", { role: "alert", className: "rc-duo-error", children: we })
345
+ ] });
346
+ }
347
+ export {
348
+ Vt as default
349
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),a=require("react"),t=require("./model-source-S12HoOoQ.js"),c=require("./remote-control-OLgfUSR1.js"),K={front:{yaw:0,pitch:.1,label:"Front"},desk:{yaw:-.5,pitch:.42,label:"Desk"},side:{yaw:-1.15,pitch:.16,label:"Side"}},Ke=28;function $e(w,T){const o=t.DoubleSide;switch(w){case"screen":return T;case"shell":return new t.MeshStandardMaterial({color:3421498,metalness:.9,roughness:.34,side:o});case"glass":return new t.MeshPhysicalMaterial({color:328966,roughness:.06,clearcoat:1,side:o});case"camera":return new t.MeshStandardMaterial({color:790549,roughness:.2,side:o});case"well":return new t.MeshStandardMaterial({color:1052690,roughness:.9,side:o});case"keys":return new t.MeshStandardMaterial({color:723725,roughness:.7,side:o});case"trackpad":return new t.MeshPhysicalMaterial({color:2895153,metalness:.4,roughness:.3,clearcoat:.6,side:o});case"scoop":return new t.MeshStandardMaterial({color:1579035,metalness:.6,roughness:.5,side:o})}}const Ze={glass:1,camera:2,screen:2,well:1,keys:2,trackpad:1,scoop:1};function Je(w){const T=a.useRef(null),o=a.useRef(w);o.current=w;const[de,ne]=a.useState(),[Te,Ue]=a.useState(!1),ue=a.useRef(!1),[U,Ve]=a.useState("front"),V=a.useRef(U);V.current=U;const Y=a.useRef(0),[g,Ye]=a.useState(!1),fe=a.useRef(g);fe.current=g;const j=a.useRef(()=>{}),_=a.useRef(c.MACBOOK_LID_OPEN_DEGREES),v=a.useRef(c.MACBOOK_LID_OPEN_DEGREES),[q,re]=a.useState(c.MACBOOK_LID_OPEN_DEGREES),X=a.useRef(void 0),me=a.useId(),pe=r=>{const l=v.current;_.current=r,X.current={from:l,to:r,start:performance.now(),duration:c.MACBOOK_LID_OPENING_MS*Math.abs(r-l)/c.MACBOOK_LID_OPEN_DEGREES},j.current()};return a.useEffect(()=>j.current(),[U,g]),a.useEffect(()=>{const r=T.current,l=w.video;if(!r||!l)return;const he=()=>{Ue(!0),o.current.onReady?.()};ne(void 0);let u;try{u=new t.WebGLRenderer({antialias:!0,alpha:!0})}catch{ne("3D rendering is unavailable in this browser. Enable WebGL to use the 3D MacBook."),he();return}u.setPixelRatio(Math.min(window.devicePixelRatio,2)),u.outputColorSpace=t.SRGBColorSpace,u.toneMapping=t.ACESFilmicToneMapping,u.setClearColor(0,0),r.appendChild(u.domElement);const S=new t.Scene,ve=t.createStudioEnvironment(u);S.environment=ve.texture,S.environmentIntensity=.45,S.add(new t.HemisphereLight(16777215,12699857,1));const be=new t.DirectionalLight(16777215,2.2);be.position.set(-120,220,260),S.add(be);const we=new t.DirectionalLight(15003135,.7);we.position.set(220,40,-220),S.add(we);const B=new t.PerspectiveCamera(Ke,1,10,4e3),L=new t.VideoTexture(l);L.colorSpace=t.SRGBColorSpace,L.minFilter=t.LinearFilter,L.magFilter=t.LinearFilter,L.anisotropy=u.capabilities.getMaxAnisotropy();const P=new t.MeshBasicMaterial({map:L,toneMapped:!1,side:t.DoubleSide}),Me={value:!1};P.onBeforeCompile=e=>{e.uniforms.fillAbove=Me,e.fragmentShader=`uniform bool fillAbove;
2
+ ${e.fragmentShader}`.replace("#include <map_fragment>",`#include <map_fragment>
3
+ if (vMapUv.x < 0.0 || vMapUv.x > 1.0 || vMapUv.y < 0.0 || (vMapUv.y > 1.0 && !fillAbove)) diffuseColor.rgb = vec3(0.0);`)},P.customProgramCacheKey=()=>"macbook-fitted-screen";let G=o.current.aspect,oe=0,I=c.streamFit(G,G);const qe=()=>{const e=l.videoWidth&&l.videoHeight?l.videoWidth/l.videoHeight:G;I=c.streamFit(e,G,oe),L.repeat.set(I.repeat[0],I.repeat[1]),L.offset.set(I.offset[0],I.offset[1])},O=new t.Group,E=new t.Group,b=new t.Group;b.rotation.x=c.lidRotation(v.current),E.add(b),O.add(E),S.add(O);const Ee=[P],W=[];let z;for(const e of c.macbookMeshes(o.current.aspect)){const n=new t.BufferGeometry,f=new t.InterleavedBuffer(e.vertices,c.MACBOOK_VERTEX_FLOATS);n.setAttribute("position",new t.InterleavedBufferAttribute(f,3,0)),n.setAttribute("normal",new t.InterleavedBufferAttribute(f,3,3)),n.setAttribute("uv",new t.InterleavedBufferAttribute(f,2,6));const i=$e(e.kind,P),d=Ze[e.kind];d&&(i.polygonOffset=!0,i.polygonOffsetFactor=-d,i.polygonOffsetUnits=-d);const M=new t.Mesh(n,i);e.kind==="screen"&&(z=M),(e.part==="lid"?b:E).add(M),W.push(n),i!==P&&W.push(i)}const ye=new t.Box3,ge=e=>{const n=b.rotation.x;return b.rotation.x=c.lidRotation(c.MACBOOK_LID_OPEN_DEGREES),e.updateMatrixWorld(!0),ye.setFromObject(e),b.rotation.x=n,ye},Le=()=>{O.rotation.set(0,0,0),E.position.set(0,0,0),E.position.copy(ge(O).getCenter(new t.Vector3)).negate()};Le();const Xe=!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;let se=!1;const Oe=()=>{O.visible=!0,!ue.current&&o.current.animateLid!==!1&&!Xe&&(v.current=0,b.rotation.x=c.lidRotation(0),re(0),pe(c.MACBOOK_LID_OPEN_DEGREES)),ue.current=!0,se=!0,p()},We=async e=>{const[{GLTFLoader:n},{MeshoptDecoder:f}]=await Promise.all([Promise.resolve().then(()=>require("./GLTFLoader-DzSwAt9C.js")),Promise.resolve().then(()=>require("./meshopt_decoder.module-DxJdu6ez.js"))]),{scene:i}=await t.loadModel(new n().setMeshoptDecoder(f),e),d=[];if(i.traverse(m=>{if(m instanceof t.Mesh){d.push(m.geometry);for(const je of Array.isArray(m.material)?m.material:[m.material]){d.push(je);for(const Ge of Object.values(je))Ge instanceof t.Texture&&d.push(Ge)}}}),R){for(const m of d)m.dispose();return}Ee.push(...d);const M=i.getObjectByName("macbook-base"),C=i.getObjectByName("macbook-lid"),k=i.getObjectByName("macbook-screen");if(!M||!C||!(k instanceof t.Mesh))throw new Error("it has no macbook-base, macbook-lid or macbook-screen");for(const m of[...E.children])m!==b&&E.remove(m);b.clear(),E.add(M);for(const m of[...C.children])b.add(m);k.material=P,z=k;const y=k.userData.aspect;typeof y=="number"&&y>0&&(G=y);const A=k.userData.notch;typeof A=="number"&&A>=0&&A<.5&&(oe=A),Me.value=oe>0;for(const m of W.splice(0))m.dispose();Le()},ie=o.current.model;ie&&(O.visible=!1,We(ie).catch(e=>{R||ne(`The MacBook model could not load: ${e instanceof Error?e.message:e}`)}).finally(()=>{R||Oe()}));const H=new t.Vector3;let D=0;const xe=new t.Raycaster,ke=new t.Vector2;let s,ce=0,$=0,F=K[V.current].yaw,N=K[V.current].pitch,Se=Y.current,ae=1,Z=0,De=0,R=!1,le=!0;const p=()=>{!Z&&le&&!document.hidden&&!R&&(Z=requestAnimationFrame(ze))};j.current=p;const J=e=>{if(!z)return;const n=u.domElement.getBoundingClientRect();ke.set((e.clientX-n.left)/n.width*2-1,1-(e.clientY-n.top)/n.height*2),xe.setFromCamera(ke,B);const f=xe.intersectObject(E,!0)[0],i=f?.object===z?f.uv:void 0;return i&&c.streamPoint(i.x,i.y,I)},Re=e=>{if(p(),s)return;const n=o.current.watchOnly||e.altKey?void 0:J(e);!n&&(fe.current||e.button!==0)||(r.focus({preventScroll:!0}),r.setPointerCapture(e.pointerId),s={pointer:e.pointerId,kind:n?"screen":"orbit",clientX:e.clientX,clientY:e.clientY,x:n?.x??0,y:n?.y??0},n&&o.current.pointer("down",n.x,n.y,e.buttons))},Ce=e=>{if(p(),!s){const n=o.current.watchOnly?void 0:J(e);u.domElement.style.cursor=n?"none":"",n&&o.current.pointer("move",n.x,n.y,0);return}if(s.pointer===e.pointerId){if(s.kind==="screen"){const n=J(e);n&&(s.x=n.x,s.y=n.y),o.current.pointer("move",s.x,s.y,e.buttons)}else ce+=(e.clientX-s.clientX)*.008,$=t.MathUtils.clamp($+(e.clientY-s.clientY)*.008,-1.2,1.2);s.clientX=e.clientX,s.clientY=e.clientY}},x=e=>{p(),!(!s||e&&s.pointer!==e.pointerId)&&(s.kind==="screen"&&o.current.pointer("up",s.x,s.y,e?.buttons??0),s=void 0)},Ae=e=>{if(o.current.watchOnly||e.ctrlKey)return;const n=J(e);if(!n)return;e.preventDefault();const f=e.deltaMode===WheelEvent.DOM_DELTA_LINE?16:e.deltaMode===WheelEvent.DOM_DELTA_PAGE?r.clientHeight:1;o.current.scroll(n.x,n.y,e.deltaX*f,e.deltaY*f)},Q=e=>e.stopPropagation(),_e=["mousedown","mousemove","mouseup","touchstart","touchmove","touchend","touchcancel"];for(const e of _e)r.addEventListener(e,Q);const Be=e=>e.preventDefault(),ee=()=>{x(),o.current.onBlur()};r.addEventListener("pointerdown",Re),r.addEventListener("pointermove",Ce),r.addEventListener("pointerup",x),r.addEventListener("pointercancel",x),r.addEventListener("lostpointercapture",x),r.addEventListener("wheel",Ae,{passive:!1}),r.addEventListener("wheel",Q),r.addEventListener("contextmenu",Be),r.addEventListener("focusout",ee),window.addEventListener("blur",ee);const Pe=()=>{const e=r.clientWidth,n=r.clientHeight;!e||!n||(ae=e/n,B.aspect=ae,B.updateProjectionMatrix(),u.setSize(e,n,!1),p())},Ie=new ResizeObserver(Pe);Ie.observe(r);const ze=e=>{if(Z=0,R||!le||document.hidden)return;const n=Math.min((e-De)/1e3,.05);De=e,Y.current!==Se&&(ce=0,$=0,Se=Y.current);const f=K[V.current];let i=!1;const d=X.current;if(d){const A=d.duration>0?(e-d.start)/d.duration:1;v.current=d.from+(d.to-d.from)*c.lidEase(A),A>=1?X.current=void 0:i=!0,re(v.current)}else v.current!==_.current&&(v.current=t.MathUtils.damp(v.current,_.current,14,n),Math.abs(v.current-_.current)<.05?v.current=_.current:i=!0);b.rotation.x=c.lidRotation(v.current);const M=f.yaw+ce,C=f.pitch+$;F=t.MathUtils.damp(F,M,10,n),N=t.MathUtils.damp(N,C,10,n),Math.abs(F-M)<5e-4&&(F=M),Math.abs(N-C)<5e-4&&(N=C),qe(),O.rotation.set(N,F,0,"XYZ"),ge(O).getSize(H);const k=Math.tan(t.MathUtils.degToRad(Ke/2)),y=Math.max(H.y/2/k,H.x/2/(k*ae))*1.12+H.z/2;D=D?t.MathUtils.damp(D,y,10,n):y,Math.abs(D-y)<.01&&(D=y),B.position.set(0,0,D),B.lookAt(0,0,0),u.render(S,B),se&&(se=!1,he()),(i||F!==M||N!==C||D!==y)&&p()};let te;const Fe=()=>{R||(p(),te=l.requestVideoFrameCallback(Fe))};"requestVideoFrameCallback"in l&&(te=l.requestVideoFrameCallback(Fe));const He="requestVideoFrameCallback"in l?void 0:window.setInterval(p,1e3/30),Ne=new IntersectionObserver(([e])=>{le=!!e?.isIntersecting,p()});return Ne.observe(r),document.addEventListener("visibilitychange",p),Pe(),ie||Oe(),()=>{R=!0,j.current=()=>{},x(),cancelAnimationFrame(Z),te!==void 0&&l.cancelVideoFrameCallback(te),clearInterval(He),Ne.disconnect(),Ie.disconnect(),document.removeEventListener("visibilitychange",p);for(const e of _e)r.removeEventListener(e,Q);r.removeEventListener("pointerdown",Re),r.removeEventListener("pointermove",Ce),r.removeEventListener("pointerup",x),r.removeEventListener("pointercancel",x),r.removeEventListener("lostpointercapture",x),r.removeEventListener("wheel",Ae),r.removeEventListener("wheel",Q),r.removeEventListener("contextmenu",Be),r.removeEventListener("focusout",ee),window.removeEventListener("blur",ee);for(const e of[...Ee,...W])e.dispose();L.dispose(),ve.dispose(),u.dispose(),u.forceContextLoss(),u.domElement.remove()}},[w.video,w.aspect,w.model]),h.jsxs("div",{className:"rc-duo rc-macbook-3d",style:Te?void 0:{visibility:"hidden"},children:[h.jsx("div",{ref:T,className:"rc-duo-stage","data-position-locked":g,tabIndex:0,role:"application","aria-label":"MacBook running macOS. Use the screen to control the guest. Drag around the MacBook to turn it when position is unlocked.",onKeyDown:w.onKeyDown,onKeyUp:w.onKeyUp}),h.jsxs("div",{className:"rc-duo-controls",onPointerDown:r=>r.stopPropagation(),children:[h.jsxs("div",{className:"rc-duo-hinge",children:[h.jsx("button",{type:"button",className:"rc-duo-fold",onClick:()=>pe(q<45?c.MACBOOK_LID_OPEN_DEGREES:0),children:q<45?"Open":"Close"}),h.jsx("label",{htmlFor:me,children:"Lid"}),h.jsx("input",{id:me,type:"range",min:0,max:c.MACBOOK_LID_MAX_DEGREES,step:1,value:Math.round(q),onChange:r=>{const l=Number(r.target.value);X.current=void 0,_.current=l,re(l),j.current()}}),h.jsxs("output",{children:[Math.round(q),"°"]})]}),h.jsxs("div",{className:"rc-duo-views",children:[Object.keys(K).map(r=>h.jsx("button",{type:"button","aria-pressed":U===r,onClick:()=>{Y.current++,Ve(r)},children:K[r].label},r)),h.jsx("button",{type:"button",className:"rc-duo-lock","aria-pressed":g,title:g?"Position is locked. The screen still controls macOS.":"Drag around the MacBook to turn it. Alt-drag turns it from the screen.",onClick:()=>Ye(!g),children:g?"Position locked":"Lock position"})]})]}),de&&h.jsx("div",{role:"alert",className:"rc-duo-error",children:de})]})}exports.default=Je;