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