@limrun/ui 0.22.0 → 0.22.1
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/dist/{BufferGeometryUtils-Dne8i0aT.js → BufferGeometryUtils-B2-bJqFj.js} +1 -1
- package/dist/{BufferGeometryUtils-Dm5SmmmT.mjs → BufferGeometryUtils-BcXIkYhS.mjs} +12 -12
- package/dist/{GLTFLoader-L51A9w-A.mjs → GLTFLoader-BQvr_TBF.mjs} +2 -2
- package/dist/{GLTFLoader-DzSwAt9C.js → GLTFLoader-CsxjkQ8a.js} +1 -1
- package/dist/components/device-stage.d.ts +61 -0
- package/dist/duo-frame-B04_gIge.js +11 -0
- package/dist/duo-frame-CyoWZakh.mjs +748 -0
- package/dist/{duo-view-D0Ndj2Ee.js → duo-view-BHwnQmx_.js} +1 -1
- package/dist/{duo-view-Biy9MAlH.mjs → duo-view-DJEQ3Q74.mjs} +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/lite.cjs +1 -1
- package/dist/lite.js +1 -1
- package/dist/macbook-frame-Be0dCliH.js +3 -0
- package/dist/macbook-frame-DzwIHHCA.mjs +344 -0
- package/dist/{model-source-BjSq5Any.mjs → model-source-BAZAKTcr.mjs} +4750 -4688
- package/dist/model-source-DbYJQWkh.js +4049 -0
- package/dist/{remote-control-OLgfUSR1.js → remote-control-Db6ssV0S.js} +1 -1
- package/dist/{remote-control-BGKETUbE.mjs → remote-control-PGtDEDgm.mjs} +1 -1
- package/package.json +1 -1
- package/dist/duo-frame-CHI6g7BR.mjs +0 -758
- package/dist/duo-frame-Cj-xHHW3.js +0 -11
- package/dist/macbook-frame-BHQtQNGV.mjs +0 -349
- package/dist/macbook-frame-CQyZhRFn.js +0 -3
- package/dist/model-source-S12HoOoQ.js +0 -4049
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const se=require("react/jsx-runtime"),N=require("react"),e=require("./model-source-S12HoOoQ.js"),et=require("./BufferGeometryUtils-Dne8i0aT.js"),fe=require("./core-BCBQrYsk.js"),ze=require("./duo-view-D0Ndj2Ee.js"),Te=new e.Vector3;function oe(h,x,m,l,M,r){const g=2*Math.PI*M/4,A=Math.max(r-2*M,0),k=Math.PI/4;Te.copy(x),Te[l]=0,Te.normalize();const a=.5*g/(g+A),z=1-Te.angleTo(h)/k;return Math.sign(Te[m])===1?z*a:A/(g+A)+a+a*(1-z)}class Ge extends e.BoxGeometry{constructor(x=1,m=1,l=1,M=2,r=.1){const g=M*2+1;if(r=Math.min(x/2,m/2,l/2,r),super(1,1,1,g,g,g),this.type="RoundedBoxGeometry",this.parameters={width:x,height:m,depth:l,segments:M,radius:r},g===1)return;const A=this.toNonIndexed();this.index=null,this.attributes.position=A.attributes.position,this.attributes.normal=A.attributes.normal,this.attributes.uv=A.attributes.uv;const k=new e.Vector3,a=new e.Vector3,z=new e.Vector3(x,m,l).divideScalar(2).subScalar(r),P=this.attributes.position.array,Y=this.attributes.normal.array,B=this.attributes.uv.array,V=P.length/6,w=new e.Vector3,W=.5/g;for(let R=0,D=0;R<P.length;R+=3,D+=2)switch(k.fromArray(P,R),a.copy(k),a.x-=Math.sign(a.x)*W,a.y-=Math.sign(a.y)*W,a.z-=Math.sign(a.z)*W,a.normalize(),P[R+0]=z.x*Math.sign(k.x)+a.x*r,P[R+1]=z.y*Math.sign(k.y)+a.y*r,P[R+2]=z.z*Math.sign(k.z)+a.z*r,Y[R+0]=a.x,Y[R+1]=a.y,Y[R+2]=a.z,Math.floor(R/V)){case 0:w.set(1,0,0),B[D+0]=oe(w,a,"z","y",r,l),B[D+1]=1-oe(w,a,"y","z",r,m);break;case 1:w.set(-1,0,0),B[D+0]=1-oe(w,a,"z","y",r,l),B[D+1]=1-oe(w,a,"y","z",r,m);break;case 2:w.set(0,1,0),B[D+0]=1-oe(w,a,"x","z",r,x),B[D+1]=oe(w,a,"z","x",r,l);break;case 3:w.set(0,-1,0),B[D+0]=1-oe(w,a,"x","z",r,x),B[D+1]=1-oe(w,a,"z","x",r,l);break;case 4:w.set(0,0,1),B[D+0]=1-oe(w,a,"x","y",r,x),B[D+1]=1-oe(w,a,"y","x",r,m);break;case 5:w.set(0,0,-1),B[D+0]=oe(w,a,"x","y",r,x),B[D+1]=1-oe(w,a,"y","x",r,m);break}}static fromJSON(x){return new Ge(x.width,x.height,x.depth,x.segments,x.radius)}}const{width:tt,height:J,depth:T}=fe.DUO_DIMENSIONS,X=tt/2,we=(11.3-T*2)/2,Se=157.5,je=110.8,me=1.1,Xe=.14;function Ye(h,x){h.envMap=x??null,h.envMapIntensity=1,h.onBeforeCompile=m=>{m.vertexShader=`varying vec3 vDuoStudioPosition;
|
|
2
|
-
${m.vertexShader}`.replace("#include <worldpos_vertex>",`#include <worldpos_vertex>
|
|
3
|
-
vDuoStudioPosition = (modelMatrix * vec4(transformed, 1.0)).xyz;`),m.fragmentShader=`
|
|
4
|
-
varying vec3 vDuoStudioPosition;
|
|
5
|
-
vec3 duoStudioReflection(vec3 direction) {
|
|
6
|
-
float radius = 240.0;
|
|
7
|
-
float along = dot(vDuoStudioPosition, direction);
|
|
8
|
-
float distance = -along + sqrt(max(0.0, along * along + radius * radius - dot(vDuoStudioPosition, vDuoStudioPosition)));
|
|
9
|
-
return normalize(vDuoStudioPosition + direction * distance);
|
|
10
|
-
}
|
|
11
|
-
${m.fragmentShader}`.replace("#include <envmap_physical_pars_fragment>",e.ShaderChunk.envmap_physical_pars_fragment.replace("envMapRotation * reflectVec","envMapRotation * duoStudioReflection(reflectVec)"))},h.customProgramCacheKey=()=>"duo-polished-silver-v1"}function Ne(h,x,m,l){const M=new e.Shape,r=-h/2,g=-x/2;return M.moveTo(r+m,g),M.lineTo(r+h-l,g),l&&M.absarc(r+h-l,g+l,l,-Math.PI/2,0,!1),M.lineTo(r+h,g+x-l),l&&M.absarc(r+h-l,g+x-l,l,0,Math.PI/2,!1),M.lineTo(r+m,g+x),m&&M.absarc(r+m,g+x-m,m,Math.PI/2,Math.PI,!1),M.lineTo(r,g+m),m&&M.absarc(r+m,g+m,m,Math.PI,Math.PI*1.5,!1),M}function nt(h,x,m){const l=new e.Group,M=new e.Group,r=new e.Group;l.add(M,r);const g=[],A=new Map,k=new Map,a=new Map;let z,P=!1,Y=!1;const B=[],V=[],w=new e.MeshPhysicalMaterial({color:15264750,metalness:1,roughness:.055,clearcoat:1,clearcoatRoughness:.055,envMapIntensity:1.15}),W=new e.MeshPhysicalMaterial({color:15987179,metalness:.04,roughness:.2,clearcoat:1,clearcoatRoughness:.08}),R=w.clone();R.roughness=.085,Ye(w,m),Ye(R,m);const D=new e.MeshBasicMaterial({color:526860}),ie=new e.MeshStandardMaterial({color:10790304,roughness:.55}),pe=new e.MeshPhysicalMaterial({color:198157,envMap:m??null,envMapIntensity:.05,metalness:1,roughness:.22}),ue=new e.MeshPhysicalMaterial({color:1057079,envMap:m??null,envMapIntensity:.04,metalness:1,roughness:.3}),u=new e.MeshStandardMaterial({color:15723220,roughness:.35}),C=new e.MeshStandardMaterial({color:12632252,metalness:.6,roughness:.25,side:e.DoubleSide}),ae=new e.MeshBasicMaterial({map:h,toneMapped:!1}),j=new e.MeshBasicMaterial({map:x,toneMapped:!1});V.push(w,W,R,D,ie,pe,ue,u,C,ae,j);const _=(s,o)=>{V.push(s);const n=new e.Mesh(s,o);return g.push(n),n},Q=(s,o,n,i,b,p,I=.12)=>_(et.toCreasedNormals(new e.ExtrudeGeometry(Ne(s,o,i,b),{depth:n,bevelEnabled:I>0,bevelSize:I,bevelThickness:I,bevelSegments:3,steps:1,curveSegments:20}),Math.PI/3),p),ce=(s,o,n,i,b)=>_(new Ge(s,o,n,3,i),b);for(const[s,o]of[[M,-1],[r,1]]){const n=o===-1?8.6:.55,i=o===1?8.6:.55,b=Q(X-.3,J-.3,T-.8,n,i,w,.35);b.position.set(o*X/2,0,-T+.4),s.add(b);const p=Q(X-1.25,J-1.25,.2,n-.3,i-.3,W);p.position.set(o*X/2,0,-T-.02),s.add(p);const I=Q(X-.8,J-.8,.1,n-.2,i-.2,D,.05);I.position.set(o*X/2,0,-.06),s.add(I);for(const S of[-J/2+13,J/2-13]){const c=ce(.22,.65,T-.8,.08,ie);c.position.set(o*(X+.04),S,-T/2),s.add(c)}}const ye=(s,o,n,i,b,p=0)=>{const I=b==="outer"?Ne(n,i,.8,6.6):Ne(n,i,p===0?5.3:0,p===1?5.3:0),S=new e.ShapeGeometry(I,24),c=S.getAttribute("position"),y=S.getAttribute("uv");for(let v=0;v<c.count;v++){const U=(c.getX(v)+n/2)/n,F=(c.getY(v)+i/2)/i;if(b==="inner"){const ne=c.getX(v)+o;y.setXY(v,1-F,(ne+Se/2)/Se)}else y.setXY(v,U,F)}const d=_(S,b==="inner"?j:ae);d.name=b==="outer"?"cover-display":`inner-display-${p}`,d.position.set(o,0,b==="inner"?Xe:-T-.25),b==="outer"&&(d.rotation.y=Math.PI),d.userData.display=b,s.add(d)},Be=Se/2-me;ye(M,-79.85/2,Be,je,"inner",0),ye(r,(Se/2+me)/2,Be,je,"inner",1);const be=Q(X-.85,J-.9,.08,8.1,.3,D,.04);be.position.set(-X/2,0,-T-.15),M.add(be),ye(M,-X/2,77.1,112.2,"outer");const q=J/2-15,le=Q(57,20,1.6,10,10,W,.28);le.position.set(X/2+2,q,-T-1.8),r.add(le);const L=(s,o,n,i,b)=>{const p=_(new e.CircleGeometry(s,48),o);return p.rotation.y=Math.PI,p.position.set(n,i,b),r.add(p),p};for(const s of[X/2+19,X/2-1]){const o=_(new e.CylinderGeometry(8.05,8.05,1.7,64),w);o.rotation.x=Math.PI/2,o.position.set(s,q,-T-2.55),r.add(o),L(7.35,D,s,q,-T-3.43),L(6.65,pe,s,q,-T-3.46),L(2.5,ue,s,q,-T-3.48),L(1.9,pe,s,q,-T-3.5);const n=L(.7,ue,s-1.1,q+1.15,-T-3.52);n.scale.y=.55}L(2.2,w,X/2-18,q-3,-T-2.11),L(1.8,u,X/2-18,q-3,-T-2.15),L(.65,D,X/2-18,q+3.2,-T-2.15);const ee=new e.Shape;ee.moveTo(0,3.2),ee.bezierCurveTo(-1.5,4.2,-3.5,4.3,-4.8,2.6),ee.bezierCurveTo(-6.4,.3,-4.4,-4.6,-2.5,-5.4),ee.bezierCurveTo(-1.4,-5.9,-.8,-5,0,-5),ee.bezierCurveTo(1,-5,1.7,-5.9,2.8,-5.3),ee.bezierCurveTo(3.8,-4.5,4.6,-3.1,4.9,-2.1),ee.bezierCurveTo(2.3,-1.2,2.1,1.5,4.1,2.8),ee.bezierCurveTo(3,4.3,1.5,4,0,3.2);const te=new e.Shape;te.moveTo(-.2,4),te.bezierCurveTo(-.3,5.7,1,6.9,2.5,7.1),te.bezierCurveTo(2.6,5.6,1.2,4,-.2,4);const ve=_(new e.ShapeGeometry([ee,te],20),C);ve.rotation.y=Math.PI,ve.position.set(X/2,-3,-T-.16),r.add(ve);const xe=(s,o,n,i,b)=>{const p=w.clone();V.push(p);const I=ce(o,n,2.5,.27,p);I.name=`button-${s}`,I.userData.button=s,I.position.set(i,b,-T/2),r.add(I),A.set(s,I),k.set(s,I.position.clone());const S=ce(o<n?4.5:o,o<n?n:4.5,T,.1,p);g.splice(g.indexOf(S),1),S.position.set(i+(o<n?2:0),b+(o<n?0:2),-T/2),S.userData.button=s,S.visible=!1,S.updateMatrix(),B.push(S)};xe("side",.7,13,X+.15,21),xe("volumeUp",9.5,.65,X-25,J/2+.12),xe("volumeDown",9.5,.65,X-37,J/2+.12);const O=ce(.35,12,2.5,.15,ie);O.position.set(X-.08,-12,-T/2),r.add(O);const H=32,de=(s,o=!1)=>{const n=new e.BufferGeometry,i=new Float32Array((H+1)*2*3),b=new Float32Array((H+1)*2*2),p=[];for(let S=0;S<=H;S++){const c=(Se/2-me+2*me*S/H)/Se;if(b.set([1,c,0,c],S*4),S<H){const y=S*2;p.push(y,y+2,y+1,y+2,y+3,y+1)}}n.setAttribute("position",new e.BufferAttribute(i,3).setUsage(e.DynamicDrawUsage)),n.setAttribute("uv",new e.BufferAttribute(b,2)),n.setIndex(p);const I=_(n,s);return o&&(I.userData.display="inner"),l.add(I),n},De=de(D),Z=de(j,!0),he=de(R),ge=[-1,1].map(s=>{const o=new e.BufferGeometry;o.setAttribute("position",new e.BufferAttribute(new Float32Array((H+1)*2*3),3).setUsage(e.DynamicDrawUsage));const n=[];for(let b=0;b<H;b++){const p=b*2;n.push(...s===1?[p,p+1,p+2,p+1,p+3,p+2]:[p,p+2,p+1,p+1,p+2,p+3])}o.setIndex(n);const i=_(o,R);return i.name=`hinge-cap-${s}`,l.add(i),{geometry:o,edge:s}});he.setIndex(Array.from(he.getIndex().array).reverse());let ke;const Ie=s=>{if(ke===s)return;ke=s;const o=e.MathUtils.degToRad((180-s)/2),n=Math.sin(o),i=Math.cos(o);for(const[d,v]of[[M,1],[r,-1]])d.rotation.y=v*o,d.position.set(-v*we*n,0,we*(1-i));const b=me*i+(we-Xe)*n,p=me*n+Xe*i+we*(1-i),I=2*me/3,S=.45*i+(T+we)*n,c=.45*n-T*i+we*(1-i),y=-T*(1-n)-.8*n;for(let d=0;d<=H;d++){const v=d/H,U=1-v,F=U*U*U*-b+3*U*U*v*(-b+i*I)+3*U*v*v*(b-i*I)+v*v*v*b,ne=p-3*U*v*n*I,re=Math.PI*v;for(let $=0;$<2;$++)Z.getAttribute("position").setXYZ(d*2+$,F,($-.5)*je,ne),De.getAttribute("position").setXYZ(d*2+$,F,($-.5)*(J-.9),ne-.07),he.getAttribute("position").setXYZ(d*2+$,-S*Math.cos(re),($-.5)*(J-.9),c+(y-c)*Math.sin(re));for(const{geometry:$,edge:Me}of ge){const Ae=$.getAttribute("position");Ae.setXYZ(d*2,F,Me*(J/2-.45),ne-.07),Ae.setXYZ(d*2+1,-S*Math.cos(re),Me*(J/2-.45),c+(y-c)*Math.sin(re))}}for(const d of[De,Z,he,...ge.map(v=>v.geometry)])d.getAttribute("position").needsUpdate=!0,d.computeVertexNormals(),d.computeBoundingSphere(),d.computeBoundingBox();l.updateMatrixWorld(!0)};return Ie(180),{device:l,hitObjects:g,setAngle:Ie,buttonAnchors:()=>[...k].map(([s,o])=>({button:s,point:o.clone().applyMatrix4(r.matrixWorld),outward:o.clone().add(s==="side"?new e.Vector3(10,0,0):new e.Vector3(0,10,0)).applyMatrix4(r.matrixWorld)})),getBounds:s=>{s.makeEmpty();const o=new e.Box3;for(const n of g)!(n instanceof e.Mesh)||n.userData.button||(n.geometry.boundingBox||n.geometry.computeBoundingBox(),o.copy(n.geometry.boundingBox).applyMatrix4(n.matrixWorld),s.union(o));return s},pick:s=>{const o=s.intersectObjects(g,!1)[0];if(o?.object.userData.display||o?.object.userData.button)return o;for(const i of B)i.matrixWorld.multiplyMatrices(r.matrixWorld,i.matrix);const n=s.intersectObjects(B,!1)[0];return n&&(!o||n.distance<=o.distance)?n:o},loadAppearance:async s=>{const{GLTFLoader:o}=await Promise.resolve().then(()=>require("./GLTFLoader-DzSwAt9C.js")),{scene:n}=await e.loadModel(new o,s),i=new Set;if(n.traverse(c=>{if(c instanceof e.Mesh){i.add(c.geometry);for(const y of Array.isArray(c.material)?c.material:[c.material]){i.add(y),y instanceof e.MeshStandardMaterial&&y.userData.finish==="polished-silver"&&Ye(y,m);for(const d of Object.values(y))d instanceof e.Texture&&d!==m&&i.add(d)}}}),Y){i.forEach(c=>c.dispose());return}const b=n.getObjectByName("folding-half"),p=n.getObjectByName("stationary-half"),I=new Set;if(p?.traverse(c=>{c instanceof e.Mesh&&c.userData.button&&I.add(c.userData.button)}),!b||!p||!["side","volumeUp","volumeDown"].every(c=>I.has(c)))throw i.forEach(c=>c.dispose()),new Error("Duo appearance requires both body halves and side, volumeUp, and volumeDown button meshes.");V.push(...i);const S=b.children.find(c=>c instanceof e.Mesh&&(c.userData.sourceDisplay==="outer"||c.material.name==="cover-screen"));if(S){const c=l.getObjectByName("cover-display"),y=S.geometry.clone().scale(10,10,10);y.computeBoundingBox();const d=y.boundingBox,v=y.getAttribute("position"),U=new e.BufferAttribute(new Float32Array(v.count*2),2);for(let F=0;F<v.count;F++)U.setXY(F,(d.max.x-v.getX(F))/(d.max.x-d.min.x),(v.getY(F)-d.min.y)/(d.max.y-d.min.y));y.setAttribute("uv",U),c.geometry=y,c.position.copy(S.position).multiplyScalar(10),c.rotation.copy(S.rotation),c.scale.copy(S.scale),V.push(y)}for(const c of[M,r])for(const y of[...c.children]){if(y.userData.display)continue;c.remove(y);const d=g.indexOf(y);d!==-1&&g.splice(d,1)}A.clear(),B.length=0,k.clear(),a.clear();for(const c of["side","volumeUp","volumeDown"]){const y=new e.Group;y.name=`button-${c}`,A.set(c,y),r.add(y)}for(const[c,y]of[[b,M],[p,r]])for(const d of[...c.children]){if(!(d instanceof e.Mesh)||d.userData.sourceDisplay||["inner-screen","cover-screen"].includes(d.material.name))continue;d.geometry.scale(10,10,10),d.position.multiplyScalar(10),d.geometry.computeBoundingBox();const v=d.userData.button;v&&A.has(v)?A.get(v).add(d):y.add(d),g.push(d)}for(const[c,y]of A){const d=new e.Box3;for(const ne of y.children){const re=ne;re.updateMatrix(),d.union(re.geometry.boundingBox.clone().applyMatrix4(re.matrix))}const v=d.getCenter(new e.Vector3);for(const ne of y.children)ne.position.sub(v);y.position.copy(v),k.set(c,v);const U=d.getSize(new e.Vector3),F=ce(c==="side"?5:U.x,c==="side"?U.y:5,T,.1,w);g.splice(g.indexOf(F),1),F.position.copy(v).add(new e.Vector3(c==="side"?2:0,c==="side"?0:2,0)),F.userData.button=c,F.visible=!1,F.updateMatrix(),B.push(F)}l.updateMatrixWorld(!0)},highlightButton:(s,o=!1)=>{z=s,P=o},animateButtons:s=>{let o=!1;for(const[n,i]of A){const b=k.get(n),p=n===z?P?0:.5:.16;let I=e.MathUtils.damp(a.get(n)??.16,p,22,s);Math.abs(I-p)<.001?I=p:o=!0,a.set(n,I),i.position.copy(b),i.position[n==="side"?"x":"y"]+=I}return o},dispose:()=>{Y=!0,V.forEach(s=>s.dispose())}}}function Ue(h,x,m){const l=Math.min(2.5,Math.max(0,m)),M=l<=.625?l*.8:l<=1.875?.5+(l-.625)*.2:.75+(l-1.875)*.4;return h+(x-h)*M}function ot(h,x,m,l,M){const r=a=>{const z=a.clone().project(m);return new e.Vector2((z.x+1)*l/2,(1-z.y)*M/2)},g=new e.Box2;for(const a of[x.min.x,x.max.x])for(const z of[x.min.y,x.max.y])for(const P of[x.min.z,x.max.z])g.expandByPoint(r(new e.Vector3(a,z,P)));const A=h.map(({button:a,point:z,outward:P})=>{const Y=r(z),B=r(P).sub(Y),V=Math.abs(B.y)>=Math.abs(B.x),w=V?B.y<0?"top":"bottom":B.x<0?"left":"right";return{button:a,edge:w,x:V?Y.x:w==="left"?g.min.x-28:g.max.x+28,y:V?w==="top"?g.min.y-28:g.max.y+28:Y.y}}),k=A.filter(a=>a.button!=="side");if(k.length===2&&k[0].edge===k[1].edge){const a=k[0].edge==="top"||k[0].edge==="bottom"?"x":"y";if(k.sort((z,P)=>z[a]-P[a]),k[1][a]-k[0][a]<48){const z=(k[0][a]+k[1][a])/2;k[0][a]=z-24,k[1][a]=z+24}}return{guides:A,rect:g,iconSize:ze.hardwareIconSize(g)}}function rt(h,x,m){const l=N.useRef(void 0),M=N.useRef(0),[r,g]=N.useState(),A=ze.useDuoHinge(h,x,P=>{P!==void 0&&a(),m(P)}),k=N.useRef(A);k.current=A;const a=()=>{l.current&&(cancelAnimationFrame(M.current),l.current=void 0,A.interacting.current=!1,g(void 0))},z=()=>{const P=performance.now(),Y=l.current,B=Y?Ue(Y.from,Y.target,(P-Y.startedAt)/1e3):A.angle,V=(Y?.target??A.angle)<90?180:0;a();const w={from:B,target:V,startedAt:P};l.current=w,A.interacting.current=!0,g(V);let W=-1/0;const R=D=>{if(l.current!==w)return;const ie=Ue(B,V,(D-P)/1e3);(D-W>=1e3/30||ie===V)&&(W=D,k.current.changeAngle(ie)),ie===V?a():M.current=requestAnimationFrame(R)};M.current=requestAnimationFrame(R)};return N.useEffect(()=>()=>{cancelAnimationFrame(M.current),l.current=void 0,k.current.interacting.current=!1},[]),{...A,motion:l,target:r,fold:z,cancelFold:a,changeAngle:P=>{a(),A.changeAngle(P)}}}function st(h){const x=N.useRef(null),m=N.useRef(new Map),l=N.useRef(h);l.current=h;const[M,r]=N.useState(),{angle:g,changeAngle:A,interacting:k,motion:a,target:z,fold:P,cancelFold:Y}=rt(h.state.angleDegrees,h.setAngle,r),B=N.useRef(g);B.current=g;const[V,w]=N.useState("front"),W=N.useRef(0),R=N.useRef(V);R.current=V;const[D,ie]=N.useState(!1),pe=N.useRef(D);pe.current=D;const ue=N.useRef(()=>{});return N.useEffect(()=>{ue.current()},[g,z,V,D,h.state.orientation]),N.useEffect(()=>{const u=x.current;if(!u||!h.outer||!h.inner)return;let C;try{C=new e.WebGLRenderer({antialias:!0,alpha:!0})}catch{r("3D rendering is unavailable in this browser. Enable WebGL to use the folding frame."),l.current.onReady?.();return}C.setPixelRatio(Math.min(window.devicePixelRatio,1.5)),C.outputColorSpace=e.SRGBColorSpace,C.toneMapping=e.ACESFilmicToneMapping,C.toneMappingExposure=1,C.setClearColor(0,0),u.appendChild(C.domElement);const ae=new e.Scene,j=new e.OrthographicCamera(-150,150,150,-150,1,2e3);let _=1;j.position.set(0,0,340);const Q=new e.Group,ce=e.createStudioEnvironment(C);ae.environment=ce.texture,ae.environmentIntensity=.4,ae.add(new e.HemisphereLight(16777215,12699857,1.1));const ye=new e.DirectionalLight(16777215,2.4);ye.position.set(-100,180,260),ae.add(ye);const Be=new e.DirectionalLight(15003135,.8);Be.position.set(200,-40,-200),ae.add(Be);const be=new e.VideoTexture(h.outer),q=new e.VideoTexture(h.inner);for(const t of[be,q])t.colorSpace=e.SRGBColorSpace,t.minFilter=e.LinearFilter,t.magFilter=e.LinearFilter;let le=!1;const L=nt(be,q,ce.texture),{device:ee}=L;h.model?L.loadAppearance(h.model).then(()=>i()).catch(t=>{le||r(String(t))}).finally(()=>{le||l.current.onReady?.()}):l.current.onReady?.();const te=new fe.DuoButtonSender((t,f)=>l.current.button(t,f),t=>r(String(t)));Q.add(ee),ae.add(Q);const ve=new e.Raycaster,xe=new e.Vector2;let O,H=0,de=0,De=W.current,Z=B.current,he=Z,ge=Z,ke=0,Ie=!1,s=0,o=0,n=!0;const i=()=>{!o&&n&&!document.hidden&&!le&&(o=requestAnimationFrame(Ze))};ue.current=i;let b=0,p,I;const S=t=>t instanceof Element?t.closest("[data-duo-button]"):null,c=t=>{I=t;for(const f of p?.guides??[]){const E=m.current.get(f.button);E&&(E.dataset.visible=String(f.edge===t))}},y=t=>{if(l.current.watchOnly)return;const f=S(t.target);if(f)return{button:f.dataset.duoButton};const E=C.domElement.getBoundingClientRect();xe.set((t.clientX-E.left)/E.width*2-1,1-(t.clientY-E.top)/E.height*2),ve.setFromCamera(xe,j);const K=L.pick(ve),G=K?.object.userData.button;if(G)return{button:G};if(!K?.object.userData.display||!K.uv)return;const Ee=l.current.state.displays.find(Le=>Le.id===K.object.userData.display);if(Ee)return{screenId:Ee.screenId,...fe.panelTouch(K.uv.x,K.uv.y)}},d=t=>{if(i(),O||t.button!==0)return;S(t.target)||u.focus({preventScroll:!0});const f=y(t),E=f&&"button"in f?f.button:void 0,K=fe.duoPointerMode(pe.current,!!f&&!E,t.altKey);if(K==="ignore"&&!E)return;const G=K==="touch"&&f&&"screenId"in f?f:void 0;O={pointer:t.pointerId,button:E,...G,x:G?.x??0,y:G?.y??0,clientX:t.clientX,clientY:t.clientY},u.setPointerCapture(t.pointerId),E?(r(void 0),te.press(E),L.highlightButton(E,!0)):G&&l.current.touch(0,G.screenId,G.x,G.y)},v=t=>{if(i(),!O){const f=y(t),E=f&&"button"in f?f.button:void 0,K=u.getBoundingClientRect();c(E?p?.guides.find(G=>G.button===E)?.edge:p&&ze.flatHoverEdge(t.clientX-K.left,t.clientY-K.top,p.rect)),C.domElement.style.cursor=E?"pointer":"",C.domElement.title=E?fe.DUO_BUTTONS[E]:"",L.highlightButton(E);return}if(!(O.pointer!==t.pointerId||O.button)){if(O.screenId){const f=y(t);f&&"screenId"in f&&f.screenId===O.screenId&&(O.x=f.x,O.y=f.y,l.current.touch(2,f.screenId,f.x,f.y))}else pe.current||(H+=(t.clientX-O.clientX)*.008,de=e.MathUtils.clamp(de+(t.clientY-O.clientY)*.008,-1.4,1.4));O.clientX=t.clientX,O.clientY=t.clientY}},U=t=>{i(),!(!O||t&&O.pointer!==t.pointerId)&&(O.button?(te.release(),L.highlightButton()):O.screenId&&l.current.touch(1,O.screenId,O.x,O.y),O=void 0,t&&v(t))},F=()=>{i(),O||(L.highlightButton(),c(void 0))},ne=t=>{i();const f=S(t.target);if(!f||l.current.watchOnly||(t.stopPropagation(),t.code!=="Space"&&t.code!=="Enter")||(t.preventDefault(),t.repeat))return;const E=f.dataset.duoButton;te.press(E),L.highlightButton(E,!0),f.dataset.pressed="true"},re=t=>{i();const f=S(t.target);!f||l.current.watchOnly||(t.stopPropagation(),!(t.code!=="Space"&&t.code!=="Enter")&&(t.preventDefault(),te.release(),L.highlightButton(f.dataset.duoButton),f.dataset.pressed="false"))},$=t=>{const f=S(t.target);f&&c(p?.guides.find(E=>E.button===f.dataset.duoButton)?.edge)},Me=()=>{i(),U(),te.release(),L.highlightButton(),c(void 0),m.current.forEach(t=>{t.dataset.pressed="false"})},Ae=t=>{u.contains(t.relatedTarget)?S(t.target)&&(te.release(),L.highlightButton()):Me()};u.addEventListener("pointerleave",F),u.addEventListener("pointerdown",d),u.addEventListener("pointermove",v),u.addEventListener("pointerup",U),u.addEventListener("pointercancel",U),u.addEventListener("lostpointercapture",U),u.addEventListener("keydown",ne),u.addEventListener("keyup",re),u.addEventListener("focusin",$),u.addEventListener("focusout",Ae),window.addEventListener("blur",Me);const We=()=>{const t=u.clientWidth,f=u.clientHeight;!t||!f||(_=t/f,j.updateProjectionMatrix(),C.setSize(t,f,!1),i())},qe=new ResizeObserver(We);qe.observe(u);const Ce=new e.Box3,_e=new e.Vector3,Ve=new e.Vector3,Ze=t=>{if(o=0,le||!n||document.hidden)return;const f=Math.min((t-b)/1e3,.05);b=t,W.current!==De&&(H=0,de=0,De=W.current),ge!==B.current&&(he=Z,ge=B.current,ke=t,Ie=k.current);const E=a.current;Z=E?Ue(E.from,E.target,(t-E.startedAt)/1e3):Ie?e.MathUtils.damp(Z,ge,18,f):Ue(he,ge,(t-ke)/1e3),Math.abs(Z-B.current)<.001&&(Z=B.current),L.setAngle(Z);const G=(1-e.MathUtils.smoothstep(Z,15,110))*Math.PI/2+(R.current==="back"?Math.PI:0);s=e.MathUtils.damp(s,G,12,f),Math.abs(s-G)<.001&&(s=G),Q.rotation.set(de+(R.current==="table"?-.35:R.current==="book"?.2:0),H+(R.current==="book"?-.2:0),0),ee.rotation.set(0,s,{portrait:0,pud:Math.PI,"landscape-left":Math.PI/2,"landscape-right":-Math.PI/2}[l.current.state.orientation]??0,"ZYX"),Q.position.set(0,0,0),Q.updateMatrixWorld(!0),L.getBounds(Ce).getCenter(_e),Ce.getSize(Ve),Q.position.copy(_e).negate();const Ee=u.clientWidth,Le=u.clientHeight,Ke=Math.max(.4,1-108/Ee),Je=Math.min(.8,Math.max(.35,1-108/Le)),Re=Math.max(Ve.y/(2*Je),Ve.x/(2*_*Ke));j.top=e.MathUtils.damp(j.top,Re,14,f),Math.abs(j.top-Re)<.001&&(j.top=Re),j.bottom=-j.top,j.left=-j.top*_,j.right=j.top*_,j.updateProjectionMatrix();const Qe=L.animateButtons(f);C.render(ae,j),L.getBounds(Ce),p=ot(L.buttonAnchors(),Ce,j,Ee,Le);for(const Oe of p.guides){const Pe=m.current.get(Oe.button);Pe&&(Pe.style.left=`${Oe.x}px`,Pe.style.top=`${Oe.y}px`,Pe.style.setProperty("--duo-hardware-icon-size",`${p.iconSize}px`),Pe.dataset.visible=String(Oe.edge===I))}(a.current||Z!==B.current||s!==G||j.top!==Re||Qe)&&i()},Fe=new Map;for(const t of[h.outer,h.inner]){const f=()=>{le||(i(),Fe.set(t,t.requestVideoFrameCallback(f)))};"requestVideoFrameCallback"in t&&Fe.set(t,t.requestVideoFrameCallback(f))}const $e="requestVideoFrameCallback"in h.outer?void 0:window.setInterval(i,1e3/30),He=new IntersectionObserver(([t])=>{n=!!t?.isIntersecting,i()});return He.observe(u),document.addEventListener("visibilitychange",i),We(),()=>{le=!0,ue.current=()=>{},He.disconnect(),document.removeEventListener("visibilitychange",i);for(const[t,f]of Fe)t.cancelVideoFrameCallback(f);clearInterval($e),U(),te.release(),cancelAnimationFrame(o),qe.disconnect(),window.removeEventListener("blur",Me),u.removeEventListener("pointerleave",F),u.removeEventListener("pointerdown",d),u.removeEventListener("pointermove",v),u.removeEventListener("pointerup",U),u.removeEventListener("pointercancel",U),u.removeEventListener("lostpointercapture",U),u.removeEventListener("keydown",ne),u.removeEventListener("keyup",re),u.removeEventListener("focusin",$),u.removeEventListener("focusout",Ae),C.dispose(),C.forceContextLoss(),L.dispose(),be.dispose(),q.dispose(),ce.dispose(),C.domElement.remove()}},[h.outer,h.inner,h.model]),se.jsxs("div",{className:"rc-duo",children:[se.jsx("div",{ref:x,className:"rc-duo-stage","data-position-locked":D,tabIndex:0,role:"application","aria-label":"iPhone Duo simulator. Touch the screen to control iOS. Drag the frame or background to rotate when position is unlocked.",onKeyDown:h.onKeyDown,onKeyUp:h.onKeyUp,children:Object.keys(fe.DUO_BUTTONS).map(u=>se.jsx("button",{disabled:h.watchOnly,ref:C=>{C?m.current.set(u,C):m.current.delete(u)},type:"button",className:"rc-duo-hardware","data-duo-button":u,"data-visible":"false","aria-label":fe.DUO_BUTTONS[u],title:fe.DUO_BUTTONS[u],children:se.jsx(ze.DuoHardwareIcon,{button:u})},u))}),se.jsxs(ze.DuoControls,{watchOnly:h.watchOnly,angle:g,onFold:P,foldTarget:z,onHingeDrag:Y,changeAngle:A,interacting:k,rotate:()=>{h.setOrientation(h.state.orientation==="portrait"?"landscape-left":"portrait").catch(u=>r(String(u)))},children:[["front","book","table","back"].map(u=>se.jsx("button",{disabled:h.watchOnly&&(u==="book"||u==="table"),"aria-pressed":V===u,onClick:()=>{W.current++,w(u),ue.current(),u==="book"&&h.setOrientation("portrait").then(()=>A(110)).catch(C=>r(String(C))),u==="table"&&h.setOrientation("landscape-left").then(()=>A(110)).catch(C=>r(String(C)))},children:u==="table"?"Laptop view":u[0].toUpperCase()+u.slice(1)},u)),se.jsxs("button",{className:"rc-duo-lock","aria-label":"Lock position","aria-pressed":D,title:D?"Position is locked. Screen touches still control iOS.":"Drag the frame or background to rotate. Alt-drag rotates from the screen.",onClick:()=>ie(!D),children:[se.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"none","aria-hidden":"true",children:[se.jsx("rect",{x:"4",y:"9",width:"12",height:"9",rx:"2",stroke:"currentColor",strokeWidth:"1.6"}),se.jsx("path",{d:D?"M6 9V6a4 4 0 0 1 8 0v3":"M6 9V6a4 4 0 0 1 8 0",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})]}),D?"Position locked":"Lock position"]})]}),M&&se.jsx("div",{role:"alert",className:"rc-duo-error",children:M})]})}exports.default=st;
|
|
@@ -1,349 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,3 +0,0 @@
|
|
|
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;
|