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