@limrun/ui 0.22.2 → 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.
- package/README.md +4 -1
- package/dist/components/macbook-geometry.d.ts +5 -5
- package/dist/components/remote-control.d.ts +3 -2
- package/dist/{duo-frame-DTcuOvpd.mjs → duo-frame-BCmB9_5p.mjs} +1 -1
- package/dist/{duo-frame-CiREcpNs.js → duo-frame-Bm0hprn9.js} +1 -1
- package/dist/{duo-view-LwhLVwKV.mjs → duo-view-C07GD_5E.mjs} +2 -2
- package/dist/{duo-view-B60dcPNt.js → duo-view-tUJbbWoS.js} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +1 -1
- package/dist/lite.cjs +1 -1
- package/dist/lite.js +1 -1
- package/dist/macbook-frame-BxJfxUcU.js +2 -0
- package/dist/{macbook-frame-CNPk98_q.mjs → macbook-frame-Dm6ko0j9.mjs} +112 -113
- package/dist/{remote-control-CPDca8px.mjs → remote-control-BX6dzHtt.mjs} +686 -720
- package/dist/remote-control-CEVcOPQZ.js +1 -0
- package/package.json +1 -1
- package/dist/macbook-frame-CaCXZbOa.js +0 -3
- package/dist/remote-control-DfhrxDXL.js +0 -1
package/README.md
CHANGED
|
@@ -20,7 +20,10 @@ logo is omitted. Pass your own images through the `assets` prop if you want fram
|
|
|
20
20
|
|
|
21
21
|
A macOS guest streams inside a MacBook Pro. The default entry draws it with an image rendered from a
|
|
22
22
|
3D model, with the stream in the screen's opening; `@limrun/ui/lite` draws a plainer one in CSS.
|
|
23
|
-
Neither draws it when `showFrame` is false.
|
|
23
|
+
Neither draws it when `showFrame` is false. The stream starts at the top of the screen, so the notch
|
|
24
|
+
covers the top of the guest's menu bar as it does on a MacBook. A guest with the 16-inch panel's
|
|
25
|
+
shape, such as the 1728 × 1116 that Limrun's macOS instances draw, fills the screen; a guest of
|
|
26
|
+
another shape keeps its own, with black glass where it falls short.
|
|
24
27
|
|
|
25
28
|
A 2D and 3D switch above the MacBook turns it into a 3D model, like the iPhone Duo's, with the
|
|
26
29
|
stream on its screen. The 3D MacBook opens its lid when it appears; set `animateLid={false}` to show
|
|
@@ -54,11 +54,11 @@ export declare function lidEase(progress: number): number;
|
|
|
54
54
|
*/
|
|
55
55
|
export declare function macbookMeshes(aspect: number): MacbookMesh[];
|
|
56
56
|
/**
|
|
57
|
-
* How a stream fills a display of another shape: the texture transform that keeps its shape,
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
57
|
+
* How a stream fills a display of another shape: the texture transform that keeps its shape, with
|
|
58
|
+
* black bars on the sides it does not reach. Texture coordinates outside 0 to 1 after it are the
|
|
59
|
+
* bars. The stream is centered, except on a display with a notch, the share of its height `notch`
|
|
60
|
+
* gives: there it starts at the top, so the notch covers the top of the guest's menu bar as it
|
|
61
|
+
* does on a MacBook, and any bar is at the bottom.
|
|
62
62
|
*/
|
|
63
63
|
export declare function streamFit(videoAspect: number, screenAspect: number, notch?: number): {
|
|
64
64
|
readonly repeat: readonly [number, number];
|
|
@@ -255,8 +255,9 @@ export type RemoteControlPlatformAssets = {
|
|
|
255
255
|
/**
|
|
256
256
|
* Where a macOS frame image's screen opening sits, as fractions of the image's width and height
|
|
257
257
|
* from its top left. A macOS `frame` needs it; without both, the MacBook is drawn in CSS. `notch`
|
|
258
|
-
* is the share of the opening's height a notch takes at its top: the stream
|
|
259
|
-
*
|
|
258
|
+
* is the share of the opening's height a notch takes at its top: the stream then starts at the
|
|
259
|
+
* top of the opening, so the notch the image draws covers the top of its menu bar, as on a
|
|
260
|
+
* MacBook.
|
|
260
261
|
*/
|
|
261
262
|
screen?: {
|
|
262
263
|
left: number;
|
|
@@ -3,7 +3,7 @@ import { useRef as ut, useState as oe, useEffect as Zt } from "react";
|
|
|
3
3
|
import { ah as ae, d as K, G as Pt, f as Xt, M as jt, e as Yt, D as ce, ai as le, aj as _t, ak as qt, B as Jt, j as Ft, al as Qt, i as wt, l as ue, b as bt, T as de, g as $t, am as fe, an as pe, ao as ge, ap as he, h as ne, u as me, a4 as ye, c as be, V as te, S as ve, L as ee, R as xe } from "./model-source-CN_i4mVy.mjs";
|
|
4
4
|
import { a as we } from "./BufferGeometryUtils-DEy5W2hb.mjs";
|
|
5
5
|
import { D as Me, k as Se, l as Ut, m as De, p as Be } from "./core-nbvkIrvp.mjs";
|
|
6
|
-
import { h as ke, u as Ie, D as Ae, a as Ee, f as ze } from "./duo-view-
|
|
6
|
+
import { h as ke, u as Ie, D as Ae, a as Ee, f as ze } from "./duo-view-C07GD_5E.mjs";
|
|
7
7
|
const zt = new K();
|
|
8
8
|
function et(h, b, g, i, w, n) {
|
|
9
9
|
const f = 2 * Math.PI * w / 4, k = Math.max(n - 2 * w, 0), B = Math.PI / 4;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ie=require("react/jsx-runtime"),K=require("react"),e=require("./model-source-D3_k9qRK.js"),Ge=require("./BufferGeometryUtils-CMbyl1DL.js"),fe=require("./core-BCBQrYsk.js"),Pe=require("./duo-view-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ie=require("react/jsx-runtime"),K=require("react"),e=require("./model-source-D3_k9qRK.js"),Ge=require("./BufferGeometryUtils-CMbyl1DL.js"),fe=require("./core-BCBQrYsk.js"),Pe=require("./duo-view-tUJbbWoS.js"),Ee=new e.Vector3;function oe(m,v,g,a,w,r){const p=2*Math.PI*w/4,I=Math.max(r-2*w,0),k=Math.PI/4;Ee.copy(v),Ee[a]=0,Ee.normalize();const i=.5*p/(p+I),L=1-Ee.angleTo(m)/k;return Math.sign(Ee[g])===1?L*i:I/(p+I)+i+i*(1-L)}class Xe extends e.BoxGeometry{constructor(v=1,g=1,a=1,w=2,r=.1){const p=w*2+1;if(r=Math.min(v/2,g/2,a/2,r),super(1,1,1,p,p,p),this.type="RoundedBoxGeometry",this.parameters={width:v,height:g,depth:a,segments:w,radius:r},p===1)return;const I=this.toNonIndexed();this.index=null,this.attributes.position=I.attributes.position,this.attributes.normal=I.attributes.normal,this.attributes.uv=I.attributes.uv;const k=new e.Vector3,i=new e.Vector3,L=new e.Vector3(v,g,a).divideScalar(2).subScalar(r),E=this.attributes.position.array,F=this.attributes.normal.array,B=this.attributes.uv.array,j=E.length/6,x=new e.Vector3,J=.5/p;for(let P=0,T=0;P<E.length;P+=3,T+=2)switch(k.fromArray(E,P),i.copy(k),i.x-=Math.sign(i.x)*J,i.y-=Math.sign(i.y)*J,i.z-=Math.sign(i.z)*J,i.normalize(),E[P+0]=L.x*Math.sign(k.x)+i.x*r,E[P+1]=L.y*Math.sign(k.y)+i.y*r,E[P+2]=L.z*Math.sign(k.z)+i.z*r,F[P+0]=i.x,F[P+1]=i.y,F[P+2]=i.z,Math.floor(P/j)){case 0:x.set(1,0,0),B[T+0]=oe(x,i,"z","y",r,a),B[T+1]=1-oe(x,i,"y","z",r,g);break;case 1:x.set(-1,0,0),B[T+0]=1-oe(x,i,"z","y",r,a),B[T+1]=1-oe(x,i,"y","z",r,g);break;case 2:x.set(0,1,0),B[T+0]=1-oe(x,i,"x","z",r,v),B[T+1]=oe(x,i,"z","x",r,a);break;case 3:x.set(0,-1,0),B[T+0]=1-oe(x,i,"x","z",r,v),B[T+1]=1-oe(x,i,"z","x",r,a);break;case 4:x.set(0,0,1),B[T+0]=1-oe(x,i,"x","y",r,v),B[T+1]=1-oe(x,i,"y","x",r,g);break;case 5:x.set(0,0,-1),B[T+0]=oe(x,i,"x","y",r,v),B[T+1]=1-oe(x,i,"y","x",r,g);break}}static fromJSON(v){return new Xe(v.width,v.height,v.depth,v.segments,v.radius)}}const{width:We,height:$,depth:z}=fe.DUO_DIMENSIONS,V=We/2,ve=(11.3-z*2)/2,xe=157.5,Re=110.8,ge=1.1,Ce=.14;function je(m,v){m.envMap=v??null,m.envMapIntensity=1,m.onBeforeCompile=g=>{g.vertexShader=`varying vec3 vDuoStudioPosition;
|
|
2
2
|
${g.vertexShader}`.replace("#include <worldpos_vertex>",`#include <worldpos_vertex>
|
|
3
3
|
vDuoStudioPosition = (modelMatrix * vec4(transformed, 1.0)).xyz;`),g.fragmentShader=`
|
|
4
4
|
varying vec3 vDuoStudioPosition;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as o, jsxs as x, Fragment as R } from "react/jsx-runtime";
|
|
2
2
|
import ot, { useId as J, useState as S, useRef as M, useEffect as T, useCallback as at, useLayoutEffect as it, Suspense as st, lazy as ct } from "react";
|
|
3
|
-
import { u as dt, D as ut } from "./remote-control-
|
|
3
|
+
import { u as dt, D as ut } from "./remote-control-BX6dzHtt.mjs";
|
|
4
4
|
import { H as lt, D as A, h as ht, i as ft, j as mt, k as pt, l as j } from "./core-nbvkIrvp.mjs";
|
|
5
5
|
function gt(t, n, r) {
|
|
6
6
|
const [s, i] = S(t), a = M({ nativeAngle: t, send: n, failed: r });
|
|
@@ -419,7 +419,7 @@ function kt({ motion: t, onFinish: n }) {
|
|
|
419
419
|
)
|
|
420
420
|
] });
|
|
421
421
|
}
|
|
422
|
-
const Pt = ct(() => import("./duo-frame-
|
|
422
|
+
const Pt = ct(() => import("./duo-frame-BCmB9_5p.mjs"));
|
|
423
423
|
function Ft(t) {
|
|
424
424
|
const n = dt();
|
|
425
425
|
return /* @__PURE__ */ x("div", { className: "rc-duo-view", children: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const r=require("react/jsx-runtime"),u=require("react"),X=require("./remote-control-DfhrxDXL.js"),R=require("./core-BCBQrYsk.js");function $(e,o,n){const[a,i]=u.useState(e),s=u.useRef({nativeAngle:e,send:o,failed:n});s.current={nativeAngle:e,send:o,failed:n};const l=u.useRef(void 0),x=u.useRef(!1),d=u.useRef(null);return u.useEffect(()=>(d.current=new R.HingeSender(async h=>{await s.current.send(h),l.current===h&&(l.current=void 0)},h=>{l.current=void 0,s.current.failed(String(h)),i(s.current.nativeAngle)}),()=>d.current?.stop()),[]),u.useEffect(()=>{!x.current&&l.current===void 0&&i(e)},[e]),{angle:a,changeAngle:h=>{s.current.failed(void 0),l.current=h,i(h),d.current?.set(h)},interacting:x}}function G({angle:e,watchOnly:o=!1,changeAngle:n,interacting:a,rotate:i,onFold:s,foldTarget:l,onHingeDrag:x,children:d}){const f=u.useId();return r.jsxs("div",{className:"rc-duo-controls",onPointerDown:h=>h.stopPropagation(),children:[r.jsxs("div",{className:"rc-duo-hinge",children:[r.jsx("button",{disabled:o,className:"rc-duo-fold",onClick:s??(()=>n(e<90?180:0)),children:(l??e)<90?"Unfold":"Fold"}),r.jsx("label",{htmlFor:f,children:"Hinge"}),r.jsx("input",{id:f,type:"range",disabled:o,min:0,max:180,step:1,value:e,onPointerDown:h=>{x?.(),a.current=!0,h.currentTarget.setPointerCapture(h.pointerId)},onPointerUp:()=>{a.current=!1},onPointerCancel:()=>{a.current=!1},onLostPointerCapture:()=>{a.current=!1},onChange:h=>n(Number(h.target.value))}),r.jsxs("output",{children:[Math.round(e),"°"]}),r.jsx("button",{disabled:o,className:"rc-duo-rotate","aria-label":"Rotate device",title:"Rotate device",onClick:i,children:r.jsxs("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:[r.jsx("rect",{x:"7",y:"3",width:"10",height:"18",rx:"2"}),r.jsx("path",{d:"M3 9a9 9 0 0 1 3-5M3 4v5h5M21 15a9 9 0 0 1-3 5m3 0v-5h-5"})]})})]}),d&&r.jsx("div",{className:"rc-duo-views","aria-label":"Device view",children:d})]})}function A({button:e}){return r.jsx("svg",{viewBox:"0 0 24 24",width:"24",height:"24",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e==="side"?r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"6",y:"10",width:"12",height:"11",rx:"2"}),r.jsx("path",{d:"M8 10V7a4 4 0 0 1 8 0v3"})]}):r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M3 9h4l5-5v16l-5-5H3zM17 12h5"}),e==="volumeUp"&&r.jsx("path",{d:"M19.5 9.5v5"})]})})}function B(e,o,n,a,i,s){return"M"+(e+i)+","+o+"H"+(e+n-s)+"a"+s+","+s+" 0 0 1 "+s+","+s+"V"+(o+a-s)+"a"+s+","+s+" 0 0 1 "+-s+","+s+"H"+(e+i)+"a"+i+","+i+" 0 0 1 "+-i+","+-i+"V"+(o+i)+"a"+i+","+i+" 0 0 1 "+i+","+-i+"Z"}function Z({inner:e,width:o,height:n}){const a=u.useId().replace(/:/g,""),i=e?8.4:1.25,s=8.4;return r.jsxs("svg",{className:"rc-duo-flat-frame",viewBox:"0 0 "+o+" "+n,"aria-hidden":"true",children:[r.jsxs("defs",{children:[r.jsxs("linearGradient",{id:a+"-silver",x1:"0",y1:"0",x2:"1",y2:"1",children:[r.jsx("stop",{offset:"0",stopColor:"#62676b"}),r.jsx("stop",{offset:"0.035",stopColor:"#f9faf9"}),r.jsx("stop",{offset:"0.11",stopColor:"#b0b4b6"}),r.jsx("stop",{offset:"0.31",stopColor:"#fdfefd"}),r.jsx("stop",{offset:"0.43",stopColor:"#797f84"}),r.jsx("stop",{offset:"0.51",stopColor:"#e8eaea"}),r.jsx("stop",{offset:"0.7",stopColor:"#979da1"}),r.jsx("stop",{offset:"0.87",stopColor:"#fafbf9"}),r.jsx("stop",{offset:"1",stopColor:"#5f676c"})]}),r.jsxs("linearGradient",{id:a+"-spine",children:[r.jsx("stop",{stopColor:"#4a5154"}),r.jsx("stop",{offset:"0.16",stopColor:"#d6d9d9"}),r.jsx("stop",{offset:"0.4",stopColor:"#f8f9f7"}),r.jsx("stop",{offset:"0.62",stopColor:"#a2a8ab"}),r.jsx("stop",{offset:"0.83",stopColor:"#e4e7e5"}),r.jsx("stop",{offset:"1",stopColor:"#666e72"})]})]}),!e&&r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"-2.3",y:"0.7",width:"3.3",height:n-1.4,rx:"0.85",fill:"url(#"+a+"-spine)",stroke:"#8b9296",strokeWidth:"0.15"}),r.jsx("path",{d:"M-.6 2V"+(n-2),stroke:"#f5f6f4",strokeWidth:"0.22"})]}),r.jsx("path",{d:B(0,0,o,n,i,s),fill:"url(#"+a+"-silver)",stroke:"#696f72",strokeWidth:"0.24"}),r.jsx("path",{d:B(.48,.48,o-.96,n-.96,Math.max(.5,i-.48),s-.48),fill:"none",stroke:"#ffffff",strokeOpacity:"0.85",strokeWidth:"0.2"}),r.jsx("path",{d:B(1.12,1.12,o-2.24,n-2.24,e?7.15:.65,7.15),fill:"#090b0d",stroke:"#34393c",strokeWidth:"0.2"}),[o-16,e?19:16].map(l=>r.jsx(u.Fragment,{children:r.jsx("path",{d:"M"+l+",0.17v0.82M"+l+","+(n-1)+"v0.82",stroke:"#b1b2ac",strokeWidth:"1.1"})},l)),e&&[0,n-.6].map(l=>r.jsx("rect",{x:o/2-2.2,y:l,width:"4.4",height:"0.6",rx:"0.18",fill:"url(#"+a+"-spine)",stroke:"#697074",strokeWidth:"0.14"},l)),r.jsx("path",{d:"M"+(o-.1)+",20h-.9m.9,"+(n-40)+"h-.9",stroke:"#b1b2ac",strokeWidth:"1.05"})]})}function oe(e,o,n,a){const i=R.DUO_DIMENSIONS.width/(e?1:2),s=R.DUO_DIMENSIONS.height,l=e?157.5:77.1,x=e?110.8:112.2,d=(o+(e?3:0))%4,f=Math.max(0,Math.min((n-120)/(d%2?s:i),(a-120)/(d%2?i:s))),h=(y,m)=>{y=(y-i/2)*f,m=(m-s/2)*f;const C=d===1?{x:-m,y}:d===2?{x:-y,y:-m}:d===3?{x:m,y:-y}:{x:y,y:m};return{x:C.x+n/2,y:C.y+a/2}},E=(d%2?s:i)*f,D=(d%2?i:s)*f,k={min:{x:(n-E)/2,y:(a-D)/2},max:{x:(n+E)/2,y:(a+D)/2}},p=[{button:"volumeDown",x:i-37,y:-.32,width:9.5,height:.65,edge:"top"},{button:"volumeUp",x:i-25,y:-.32,width:9.5,height:.65,edge:"top"},{button:"side",x:i+.35,y:s/2-21,width:.7,height:13,edge:"right"}],v=["top","right","bottom","left"],b=p.map(y=>{const m=v[(v.indexOf(y.edge)+d)%4],C=h(y.x,y.y);return m==="top"&&(C.y=k.min.y-28),m==="bottom"&&(C.y=k.max.y+28),m==="left"&&(C.x=k.min.x-28),m==="right"&&(C.x=k.max.x+28),{button:y.button,edge:m,...C,targetX:C.x,targetY:C.y}}),j=b.filter(y=>y.button!=="side"),g=d%2?"y":"x";j.sort((y,m)=>y[g]-m[g]);const S=d%2?"targetY":"targetX";if(j[1][g]-j[0][g]<44){const y=(j[0][g]+j[1][g])/2;j[0][S]=y-22,j[1][S]=y+22}return{bodyWidth:i,bodyHeight:s,screenWidth:l,screenHeight:x,scale:f,turns:d,buttons:p,guides:b,rect:k,iconSize:Math.min(J(k),12*f)}}function J(e){return Math.max(12,Math.min(24,Math.max(e.max.x-e.min.x,e.max.y-e.min.y)/24))}function Q(e,o,n){return[["top",n.min.y-o,e,n.min.x,n.max.x],["bottom",o-n.max.y,e,n.min.x,n.max.x],["left",n.min.x-e,o,n.min.y,n.max.y],["right",e-n.max.x,o,n.min.y,n.max.y]].filter(([,i,s,l,x])=>i>=-7&&i<=52&&s>=l-12&&s<=x+12).sort((i,s)=>Math.abs(i[1])-Math.abs(s[1]))[0]?.[0]}function V(e){if(!e||e.readyState<2||!e.videoWidth||!e.videoHeight)return;const o=Math.min(1,1024/Math.max(e.videoWidth,e.videoHeight)),n=document.createElement("canvas");try{const a=n.getContext("2d");return a?(n.width=Math.round(e.videoWidth*o),n.height=Math.round(e.videoHeight*o),a.drawImage(e,0,0,n.width,n.height),n):void 0}catch{return}}function se(e,o){let n=!1,a;const i=f=>{n||(d(),o(f))},s=()=>{if(n)return;const f=V(e);f&&i(f)},l=()=>{a=void 0,s(),n||(a=e?.requestVideoFrameCallback?.(l))},x=setTimeout(()=>i(void 0),2500);a=e?.requestVideoFrameCallback?.(l),e?.addEventListener("loadeddata",s),!e?.requestVideoFrameCallback&&e&&e.readyState>=2&&s();function d(){n=!0,clearTimeout(x),a!==void 0&&e?.cancelVideoFrameCallback(a),e?.removeEventListener("loadeddata",s)}return d}function ie(e,o,n,a,i=!0){const s=u.useRef(void 0),l=u.useRef(a),x=u.useRef({inner:o,frame:n});x.current={inner:o,frame:n};const[d,f]=u.useState(),h=u.useRef(void 0),E=u.useRef(void 0),D=u.useCallback(()=>{clearTimeout(E.current),h.current=void 0,f(void 0)},[]),k=p=>{if(!i||p===o){D();return}if(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches||h.current)return;const v=V(e.current);if(!v)return;const b=x.current;h.current={from:b,to:b,before:v,ready:!1},f(h.current),E.current=setTimeout(D,5e3)};return u.useEffect(()=>()=>clearTimeout(E.current),[]),u.useLayoutEffect(()=>{const p=s.current,v={inner:o,frame:n};s.current=v;const b=l.current!==a;if(l.current=a,!p)return;const j=Math.abs(p.frame.rect.min.x+p.frame.rect.max.x-n.rect.min.x-n.rect.max.x)>.5||Math.abs(p.frame.rect.min.y+p.frame.rect.max.y-n.rect.min.y-n.rect.max.y)>.5;if(!i||j||b){D();return}if(p.inner===o||(f(void 0),!p.frame.scale||!n.scale)||window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)return;const g=h.current?.before??V(e.current),S=h.current?.from??p;clearTimeout(E.current),h.current=void 0,g&&f({from:S,to:v,before:g,ready:!1})},[o,n.scale,n.turns,n.rect.min.x,n.rect.min.y,a,i]),u.useEffect(()=>{if(!d||d.from.inner===o)return;const p=se(e.current,j=>{j?f(g=>g&&{...g,to:x.current,after:j,ready:!0}):D()}),v=window.matchMedia?.("(prefers-reduced-motion: reduce)"),b=()=>{v?.matches&&f(void 0)};return v?.addEventListener("change",b),()=>{p(),v?.removeEventListener("change",b)}},[d?.from,o]),{motion:d,finish:D,prepare:k}}function ae({pose:e,image:o,scale:n}){const{bodyWidth:a,bodyHeight:i,screenWidth:s,screenHeight:l}=e.frame,x=s*n,d=l*n;return r.jsxs("div",{className:"rc-duo-fold-still",style:{width:a*n,height:i*n},children:[r.jsx(Z,{inner:e.inner,width:a,height:i}),r.jsx("div",{className:"rc-duo-flat-screen",style:{width:x,height:d,left:(a-s)*n/2,top:(i-l)*n/2,borderRadius:e.inner?5.3*n:[.8,6.6,6.6,.8].map(f=>f*n+"px").join(" ")},children:o&&r.jsx("canvas",{ref:f=>{f&&(f.width=o.width,f.height=o.height,f.getContext("2d")?.drawImage(o,0,0))},style:{width:e.inner?d:x,height:e.inner?x:d,transform:`translate(-50%, -50%) rotate(${e.inner?90:0}deg)`}})})]})}function ce({motion:e,onFinish:o}){const n=u.useRef(null),[a,i]=u.useState(!1);return u.useEffect(()=>{if(i(!1),!e.ready)return;let s=!1,l;return Promise.resolve().then(()=>require("./duo-fold-renderer-DdltAnF7.js")).then(({renderFold:x})=>{s||!n.current||(l=x(n.current,e,o),i(!0))}).catch(()=>{s||o()}),()=>{s=!0,l?.()}},[e.ready,e.from,o]),r.jsxs(r.Fragment,{children:[!a&&r.jsx("div",{className:"rc-duo-fold-hold","aria-hidden":"true",style:{width:e.from.frame.bodyWidth*e.from.frame.scale,height:e.from.frame.bodyHeight*e.from.frame.scale,transform:`translate(-50%, -50%) rotate(${e.from.frame.turns*90}deg)`},children:r.jsx(ae,{pose:e.from,image:e.before,scale:e.from.frame.scale})}),r.jsx("canvas",{ref:n,className:"rc-duo-fold-canvas","aria-hidden":"true",style:{visibility:a?"visible":"hidden"}})]})}const ue=u.lazy(()=>Promise.resolve().then(()=>require("./duo-frame-CiREcpNs.js")));function de(e){const o=X.useDeviceView();return r.jsxs("div",{className:"rc-duo-view",children:[e.showFrame!==!1&&o.mode==="3d"?r.jsx(u.Suspense,{fallback:r.jsx(Y,{...e}),children:r.jsx(ue,{...e,onReady:o.onReady})}):r.jsx(Y,{...e}),e.showFrame!==!1&&r.jsx(X.DeviceModeToggle,{view:o,label:"Device rendering"})]})}function Y(e){const o=e.showFrame!==!1,n=u.useRef(null),a=u.useRef(null),i=u.useRef(e);i.current=e;const[s,l]=u.useState({width:0,height:0}),[x,d]=u.useState(),[f,h]=u.useState(),[E,D]=u.useState(),[k,p]=u.useState(),v=u.useRef(void 0),b=u.useRef(null);b.current||(b.current=new R.DuoTouchController((...t)=>i.current.touch(...t)));const j=u.useRef(null),g=R.getDuoDisplay(e.state),S=g?.id==="inner"?e.inner:e.outer,y=R.duoDisplayTurns(g?.orientation),m=g?.id==="inner",C={portrait:0,pud:2,"landscape-left":3,"landscape-right":1}[e.state.orientation],H=o?(C+(m?1:0))%4:y,w=oe(m,H,s.width,s.height),W=o?w.screenWidth:(m?g?.height:g?.width)??1,I=o?w.screenHeight:(m?g?.width:g?.height)??1,P=o?w.bodyWidth:W,T=o?w.bodyHeight:I,M=o?w.scale:Math.max(0,Math.min(s.width/(w.turns%2?T:P),s.height/(w.turns%2?P:T))),U=W*M,L=I*M;u.useEffect(()=>{const t=new ResizeObserver(([c])=>{c&&l({width:c.contentRect.width,height:c.contentRect.height})});return n.current&&t.observe(n.current),()=>t.disconnect()},[]),u.useEffect(()=>{const t=a.current;if(!t||!S)return;const c=()=>{t.srcObject!==S.srcObject&&(t.srcObject=S.srcObject),t.play().catch(()=>{}),e.outer?.pause(),e.inner?.pause()};return c(),S.addEventListener("loadedmetadata",c),()=>{S.removeEventListener("loadedmetadata",c),t.pause(),t.srcObject=null;for(const z of[e.outer,e.inner])z?.play().catch(()=>{})}},[S,e.outer,e.inner]);const{motion:N,finish:_,prepare:ee}=ie(a,m,w,e.state.orientation,o),{angle:te,changeAngle:re,interacting:ne}=$(e.state.angleDegrees,async t=>{ee(t>=90);try{await e.setAngle(t)}catch(c){throw _(),c}},d),F=()=>{b.current?.release(),v.current=void 0};u.useEffect(()=>{j.current=new R.DuoButtonSender((c,z)=>i.current.button(c,z),c=>d(String(c)));const t=()=>{F(),j.current?.release(),p(void 0)};return window.addEventListener("blur",t),()=>{t(),window.removeEventListener("blur",t)}},[]),u.useEffect(()=>{b.current?.setDisplay(g,H),b.current?.active||(v.current=void 0)},[g,H]);const O=()=>{j.current?.release(),p(void 0)},q=t=>({disabled:e.watchOnly,onPointerDown:c=>{e.watchOnly||N||c.button!==0||(c.currentTarget.setPointerCapture(c.pointerId),j.current?.press(t),p(t))},onPointerUp:O,onPointerCancel:O,onLostPointerCapture:O,onBlur:O,onPointerEnter:()=>D(t),onPointerLeave:()=>D(void 0),onFocus:()=>h(w.guides.find(c=>c.button===t)?.edge),onKeyDown:c=>{N||(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),c.repeat||(j.current?.press(t),p(t)))},onKeyUp:c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),O())}}),K=t=>{const c=t.currentTarget.getBoundingClientRect();return{x:(t.clientX-c.left)/c.width,y:(t.clientY-c.top)/c.height}};return r.jsxs("div",{className:o?"rc-duo":"rc-duo rc-duo-frameless",children:[r.jsxs("div",{ref:n,className:"rc-duo-flat-stage","data-folding":!!N,"aria-busy":!!N,onPointerMove:t=>{if(!o)return;const c=t.currentTarget.getBoundingClientRect();h(Q(t.clientX-c.left,t.clientY-c.top,w.rect))},onPointerLeave:()=>{h(void 0),D(void 0)},children:[r.jsxs("div",{className:"rc-duo-flat-device","data-display":m?"inner":"outer",style:{width:P*M,height:T*M,transform:"translate(-50%, -50%) rotate("+w.turns*90+"deg)"},children:[o&&r.jsx(Z,{inner:m,width:P,height:T}),r.jsx("div",{className:"rc-duo-flat-screen",role:"application","aria-label":"iPhone Duo 2D simulator",tabIndex:0,style:{width:U,height:L,left:(P-W)/2*M,top:(T-I)/2*M,borderRadius:o?m?5.3*M:[.8,6.6,6.6,.8].map(t=>t*M+"px").join(" "):0},onKeyDown:N?void 0:e.onKeyDown,onKeyUp:e.onKeyUp,onPointerDown:t=>{if(e.watchOnly||N||v.current!==void 0||t.button!==0||!g)return;t.currentTarget.focus({preventScroll:!0}),t.currentTarget.setPointerCapture(t.pointerId);const c=K(t);v.current=t.pointerId,b.current?.touch("begin",c.x,c.y)},onPointerMove:t=>{if(v.current!==t.pointerId)return;const c=K(t);b.current?.touch("move",c.x,c.y)},onPointerUp:t=>{v.current===t.pointerId&&F()},onPointerCancel:F,onLostPointerCapture:F,children:r.jsx("video",{ref:a,autoPlay:!0,muted:!0,playsInline:!0,style:{width:m?L:U,height:m?U:L,transform:"translate(-50%, -50%) rotate("+(m?90:0)+"deg)"}})}),o&&w.buttons.map(t=>r.jsx("button",{type:"button",className:"rc-duo-physical","data-duo-button":t.button,"data-edge":t.edge,"data-highlighted":E===t.button,"data-pressed":k===t.button,"aria-label":R.DUO_BUTTONS[t.button]+" physical button",title:R.DUO_BUTTONS[t.button],style:{left:t.x*M,top:t.y*M,width:t.edge==="top"?Math.max(28,t.width*M):28,height:t.edge==="top"?28:Math.max(28,t.height*M)},...q(t.button),children:r.jsx("span",{style:{width:Math.max(2,t.width*M),height:Math.max(2,t.height*M)}})},t.button))]}),o&&w.guides.map(t=>r.jsx("button",{type:"button",className:"rc-duo-hardware","data-duo-button":t.button,"data-visible":f===t.edge,"data-pressed":k===t.button,"aria-label":R.DUO_BUTTONS[t.button],title:R.DUO_BUTTONS[t.button],style:{left:t.targetX,top:t.targetY,"--duo-hardware-icon-size":`${w.iconSize}px`,"--duo-hardware-icon-x":`${t.x-t.targetX}px`,"--duo-hardware-icon-y":`${t.y-t.targetY}px`},...q(t.button),children:r.jsx(A,{button:t.button})},t.button)),N&&r.jsx(ce,{motion:N,onFinish:_})]}),o&&r.jsx(G,{watchOnly:e.watchOnly,angle:te,changeAngle:re,interacting:ne,rotate:()=>{e.setOrientation(e.state.orientation==="portrait"?"landscape-left":"portrait").catch(t=>d(String(t)))},children:r.jsx("span",{className:"rc-duo-view-label",children:"Front view"})}),x&&r.jsx("div",{role:"alert",className:"rc-duo-error",children:x})]})}const le=Object.freeze(Object.defineProperty({__proto__:null,default:de},Symbol.toStringTag,{value:"Module"}));exports.DuoControls=G;exports.DuoHardwareIcon=A;exports.duoView=le;exports.flatHoverEdge=Q;exports.hardwareIconSize=J;exports.useDuoHinge=$;
|
|
1
|
+
"use strict";const r=require("react/jsx-runtime"),u=require("react"),X=require("./remote-control-CEVcOPQZ.js"),R=require("./core-BCBQrYsk.js");function $(e,o,n){const[a,i]=u.useState(e),s=u.useRef({nativeAngle:e,send:o,failed:n});s.current={nativeAngle:e,send:o,failed:n};const l=u.useRef(void 0),x=u.useRef(!1),d=u.useRef(null);return u.useEffect(()=>(d.current=new R.HingeSender(async h=>{await s.current.send(h),l.current===h&&(l.current=void 0)},h=>{l.current=void 0,s.current.failed(String(h)),i(s.current.nativeAngle)}),()=>d.current?.stop()),[]),u.useEffect(()=>{!x.current&&l.current===void 0&&i(e)},[e]),{angle:a,changeAngle:h=>{s.current.failed(void 0),l.current=h,i(h),d.current?.set(h)},interacting:x}}function G({angle:e,watchOnly:o=!1,changeAngle:n,interacting:a,rotate:i,onFold:s,foldTarget:l,onHingeDrag:x,children:d}){const f=u.useId();return r.jsxs("div",{className:"rc-duo-controls",onPointerDown:h=>h.stopPropagation(),children:[r.jsxs("div",{className:"rc-duo-hinge",children:[r.jsx("button",{disabled:o,className:"rc-duo-fold",onClick:s??(()=>n(e<90?180:0)),children:(l??e)<90?"Unfold":"Fold"}),r.jsx("label",{htmlFor:f,children:"Hinge"}),r.jsx("input",{id:f,type:"range",disabled:o,min:0,max:180,step:1,value:e,onPointerDown:h=>{x?.(),a.current=!0,h.currentTarget.setPointerCapture(h.pointerId)},onPointerUp:()=>{a.current=!1},onPointerCancel:()=>{a.current=!1},onLostPointerCapture:()=>{a.current=!1},onChange:h=>n(Number(h.target.value))}),r.jsxs("output",{children:[Math.round(e),"°"]}),r.jsx("button",{disabled:o,className:"rc-duo-rotate","aria-label":"Rotate device",title:"Rotate device",onClick:i,children:r.jsxs("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:[r.jsx("rect",{x:"7",y:"3",width:"10",height:"18",rx:"2"}),r.jsx("path",{d:"M3 9a9 9 0 0 1 3-5M3 4v5h5M21 15a9 9 0 0 1-3 5m3 0v-5h-5"})]})})]}),d&&r.jsx("div",{className:"rc-duo-views","aria-label":"Device view",children:d})]})}function A({button:e}){return r.jsx("svg",{viewBox:"0 0 24 24",width:"24",height:"24",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e==="side"?r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"6",y:"10",width:"12",height:"11",rx:"2"}),r.jsx("path",{d:"M8 10V7a4 4 0 0 1 8 0v3"})]}):r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M3 9h4l5-5v16l-5-5H3zM17 12h5"}),e==="volumeUp"&&r.jsx("path",{d:"M19.5 9.5v5"})]})})}function B(e,o,n,a,i,s){return"M"+(e+i)+","+o+"H"+(e+n-s)+"a"+s+","+s+" 0 0 1 "+s+","+s+"V"+(o+a-s)+"a"+s+","+s+" 0 0 1 "+-s+","+s+"H"+(e+i)+"a"+i+","+i+" 0 0 1 "+-i+","+-i+"V"+(o+i)+"a"+i+","+i+" 0 0 1 "+i+","+-i+"Z"}function Z({inner:e,width:o,height:n}){const a=u.useId().replace(/:/g,""),i=e?8.4:1.25,s=8.4;return r.jsxs("svg",{className:"rc-duo-flat-frame",viewBox:"0 0 "+o+" "+n,"aria-hidden":"true",children:[r.jsxs("defs",{children:[r.jsxs("linearGradient",{id:a+"-silver",x1:"0",y1:"0",x2:"1",y2:"1",children:[r.jsx("stop",{offset:"0",stopColor:"#62676b"}),r.jsx("stop",{offset:"0.035",stopColor:"#f9faf9"}),r.jsx("stop",{offset:"0.11",stopColor:"#b0b4b6"}),r.jsx("stop",{offset:"0.31",stopColor:"#fdfefd"}),r.jsx("stop",{offset:"0.43",stopColor:"#797f84"}),r.jsx("stop",{offset:"0.51",stopColor:"#e8eaea"}),r.jsx("stop",{offset:"0.7",stopColor:"#979da1"}),r.jsx("stop",{offset:"0.87",stopColor:"#fafbf9"}),r.jsx("stop",{offset:"1",stopColor:"#5f676c"})]}),r.jsxs("linearGradient",{id:a+"-spine",children:[r.jsx("stop",{stopColor:"#4a5154"}),r.jsx("stop",{offset:"0.16",stopColor:"#d6d9d9"}),r.jsx("stop",{offset:"0.4",stopColor:"#f8f9f7"}),r.jsx("stop",{offset:"0.62",stopColor:"#a2a8ab"}),r.jsx("stop",{offset:"0.83",stopColor:"#e4e7e5"}),r.jsx("stop",{offset:"1",stopColor:"#666e72"})]})]}),!e&&r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"-2.3",y:"0.7",width:"3.3",height:n-1.4,rx:"0.85",fill:"url(#"+a+"-spine)",stroke:"#8b9296",strokeWidth:"0.15"}),r.jsx("path",{d:"M-.6 2V"+(n-2),stroke:"#f5f6f4",strokeWidth:"0.22"})]}),r.jsx("path",{d:B(0,0,o,n,i,s),fill:"url(#"+a+"-silver)",stroke:"#696f72",strokeWidth:"0.24"}),r.jsx("path",{d:B(.48,.48,o-.96,n-.96,Math.max(.5,i-.48),s-.48),fill:"none",stroke:"#ffffff",strokeOpacity:"0.85",strokeWidth:"0.2"}),r.jsx("path",{d:B(1.12,1.12,o-2.24,n-2.24,e?7.15:.65,7.15),fill:"#090b0d",stroke:"#34393c",strokeWidth:"0.2"}),[o-16,e?19:16].map(l=>r.jsx(u.Fragment,{children:r.jsx("path",{d:"M"+l+",0.17v0.82M"+l+","+(n-1)+"v0.82",stroke:"#b1b2ac",strokeWidth:"1.1"})},l)),e&&[0,n-.6].map(l=>r.jsx("rect",{x:o/2-2.2,y:l,width:"4.4",height:"0.6",rx:"0.18",fill:"url(#"+a+"-spine)",stroke:"#697074",strokeWidth:"0.14"},l)),r.jsx("path",{d:"M"+(o-.1)+",20h-.9m.9,"+(n-40)+"h-.9",stroke:"#b1b2ac",strokeWidth:"1.05"})]})}function oe(e,o,n,a){const i=R.DUO_DIMENSIONS.width/(e?1:2),s=R.DUO_DIMENSIONS.height,l=e?157.5:77.1,x=e?110.8:112.2,d=(o+(e?3:0))%4,f=Math.max(0,Math.min((n-120)/(d%2?s:i),(a-120)/(d%2?i:s))),h=(y,m)=>{y=(y-i/2)*f,m=(m-s/2)*f;const C=d===1?{x:-m,y}:d===2?{x:-y,y:-m}:d===3?{x:m,y:-y}:{x:y,y:m};return{x:C.x+n/2,y:C.y+a/2}},E=(d%2?s:i)*f,D=(d%2?i:s)*f,k={min:{x:(n-E)/2,y:(a-D)/2},max:{x:(n+E)/2,y:(a+D)/2}},p=[{button:"volumeDown",x:i-37,y:-.32,width:9.5,height:.65,edge:"top"},{button:"volumeUp",x:i-25,y:-.32,width:9.5,height:.65,edge:"top"},{button:"side",x:i+.35,y:s/2-21,width:.7,height:13,edge:"right"}],v=["top","right","bottom","left"],b=p.map(y=>{const m=v[(v.indexOf(y.edge)+d)%4],C=h(y.x,y.y);return m==="top"&&(C.y=k.min.y-28),m==="bottom"&&(C.y=k.max.y+28),m==="left"&&(C.x=k.min.x-28),m==="right"&&(C.x=k.max.x+28),{button:y.button,edge:m,...C,targetX:C.x,targetY:C.y}}),j=b.filter(y=>y.button!=="side"),g=d%2?"y":"x";j.sort((y,m)=>y[g]-m[g]);const S=d%2?"targetY":"targetX";if(j[1][g]-j[0][g]<44){const y=(j[0][g]+j[1][g])/2;j[0][S]=y-22,j[1][S]=y+22}return{bodyWidth:i,bodyHeight:s,screenWidth:l,screenHeight:x,scale:f,turns:d,buttons:p,guides:b,rect:k,iconSize:Math.min(J(k),12*f)}}function J(e){return Math.max(12,Math.min(24,Math.max(e.max.x-e.min.x,e.max.y-e.min.y)/24))}function Q(e,o,n){return[["top",n.min.y-o,e,n.min.x,n.max.x],["bottom",o-n.max.y,e,n.min.x,n.max.x],["left",n.min.x-e,o,n.min.y,n.max.y],["right",e-n.max.x,o,n.min.y,n.max.y]].filter(([,i,s,l,x])=>i>=-7&&i<=52&&s>=l-12&&s<=x+12).sort((i,s)=>Math.abs(i[1])-Math.abs(s[1]))[0]?.[0]}function V(e){if(!e||e.readyState<2||!e.videoWidth||!e.videoHeight)return;const o=Math.min(1,1024/Math.max(e.videoWidth,e.videoHeight)),n=document.createElement("canvas");try{const a=n.getContext("2d");return a?(n.width=Math.round(e.videoWidth*o),n.height=Math.round(e.videoHeight*o),a.drawImage(e,0,0,n.width,n.height),n):void 0}catch{return}}function se(e,o){let n=!1,a;const i=f=>{n||(d(),o(f))},s=()=>{if(n)return;const f=V(e);f&&i(f)},l=()=>{a=void 0,s(),n||(a=e?.requestVideoFrameCallback?.(l))},x=setTimeout(()=>i(void 0),2500);a=e?.requestVideoFrameCallback?.(l),e?.addEventListener("loadeddata",s),!e?.requestVideoFrameCallback&&e&&e.readyState>=2&&s();function d(){n=!0,clearTimeout(x),a!==void 0&&e?.cancelVideoFrameCallback(a),e?.removeEventListener("loadeddata",s)}return d}function ie(e,o,n,a,i=!0){const s=u.useRef(void 0),l=u.useRef(a),x=u.useRef({inner:o,frame:n});x.current={inner:o,frame:n};const[d,f]=u.useState(),h=u.useRef(void 0),E=u.useRef(void 0),D=u.useCallback(()=>{clearTimeout(E.current),h.current=void 0,f(void 0)},[]),k=p=>{if(!i||p===o){D();return}if(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches||h.current)return;const v=V(e.current);if(!v)return;const b=x.current;h.current={from:b,to:b,before:v,ready:!1},f(h.current),E.current=setTimeout(D,5e3)};return u.useEffect(()=>()=>clearTimeout(E.current),[]),u.useLayoutEffect(()=>{const p=s.current,v={inner:o,frame:n};s.current=v;const b=l.current!==a;if(l.current=a,!p)return;const j=Math.abs(p.frame.rect.min.x+p.frame.rect.max.x-n.rect.min.x-n.rect.max.x)>.5||Math.abs(p.frame.rect.min.y+p.frame.rect.max.y-n.rect.min.y-n.rect.max.y)>.5;if(!i||j||b){D();return}if(p.inner===o||(f(void 0),!p.frame.scale||!n.scale)||window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)return;const g=h.current?.before??V(e.current),S=h.current?.from??p;clearTimeout(E.current),h.current=void 0,g&&f({from:S,to:v,before:g,ready:!1})},[o,n.scale,n.turns,n.rect.min.x,n.rect.min.y,a,i]),u.useEffect(()=>{if(!d||d.from.inner===o)return;const p=se(e.current,j=>{j?f(g=>g&&{...g,to:x.current,after:j,ready:!0}):D()}),v=window.matchMedia?.("(prefers-reduced-motion: reduce)"),b=()=>{v?.matches&&f(void 0)};return v?.addEventListener("change",b),()=>{p(),v?.removeEventListener("change",b)}},[d?.from,o]),{motion:d,finish:D,prepare:k}}function ae({pose:e,image:o,scale:n}){const{bodyWidth:a,bodyHeight:i,screenWidth:s,screenHeight:l}=e.frame,x=s*n,d=l*n;return r.jsxs("div",{className:"rc-duo-fold-still",style:{width:a*n,height:i*n},children:[r.jsx(Z,{inner:e.inner,width:a,height:i}),r.jsx("div",{className:"rc-duo-flat-screen",style:{width:x,height:d,left:(a-s)*n/2,top:(i-l)*n/2,borderRadius:e.inner?5.3*n:[.8,6.6,6.6,.8].map(f=>f*n+"px").join(" ")},children:o&&r.jsx("canvas",{ref:f=>{f&&(f.width=o.width,f.height=o.height,f.getContext("2d")?.drawImage(o,0,0))},style:{width:e.inner?d:x,height:e.inner?x:d,transform:`translate(-50%, -50%) rotate(${e.inner?90:0}deg)`}})})]})}function ce({motion:e,onFinish:o}){const n=u.useRef(null),[a,i]=u.useState(!1);return u.useEffect(()=>{if(i(!1),!e.ready)return;let s=!1,l;return Promise.resolve().then(()=>require("./duo-fold-renderer-DdltAnF7.js")).then(({renderFold:x})=>{s||!n.current||(l=x(n.current,e,o),i(!0))}).catch(()=>{s||o()}),()=>{s=!0,l?.()}},[e.ready,e.from,o]),r.jsxs(r.Fragment,{children:[!a&&r.jsx("div",{className:"rc-duo-fold-hold","aria-hidden":"true",style:{width:e.from.frame.bodyWidth*e.from.frame.scale,height:e.from.frame.bodyHeight*e.from.frame.scale,transform:`translate(-50%, -50%) rotate(${e.from.frame.turns*90}deg)`},children:r.jsx(ae,{pose:e.from,image:e.before,scale:e.from.frame.scale})}),r.jsx("canvas",{ref:n,className:"rc-duo-fold-canvas","aria-hidden":"true",style:{visibility:a?"visible":"hidden"}})]})}const ue=u.lazy(()=>Promise.resolve().then(()=>require("./duo-frame-Bm0hprn9.js")));function de(e){const o=X.useDeviceView();return r.jsxs("div",{className:"rc-duo-view",children:[e.showFrame!==!1&&o.mode==="3d"?r.jsx(u.Suspense,{fallback:r.jsx(Y,{...e}),children:r.jsx(ue,{...e,onReady:o.onReady})}):r.jsx(Y,{...e}),e.showFrame!==!1&&r.jsx(X.DeviceModeToggle,{view:o,label:"Device rendering"})]})}function Y(e){const o=e.showFrame!==!1,n=u.useRef(null),a=u.useRef(null),i=u.useRef(e);i.current=e;const[s,l]=u.useState({width:0,height:0}),[x,d]=u.useState(),[f,h]=u.useState(),[E,D]=u.useState(),[k,p]=u.useState(),v=u.useRef(void 0),b=u.useRef(null);b.current||(b.current=new R.DuoTouchController((...t)=>i.current.touch(...t)));const j=u.useRef(null),g=R.getDuoDisplay(e.state),S=g?.id==="inner"?e.inner:e.outer,y=R.duoDisplayTurns(g?.orientation),m=g?.id==="inner",C={portrait:0,pud:2,"landscape-left":3,"landscape-right":1}[e.state.orientation],H=o?(C+(m?1:0))%4:y,w=oe(m,H,s.width,s.height),W=o?w.screenWidth:(m?g?.height:g?.width)??1,I=o?w.screenHeight:(m?g?.width:g?.height)??1,P=o?w.bodyWidth:W,T=o?w.bodyHeight:I,M=o?w.scale:Math.max(0,Math.min(s.width/(w.turns%2?T:P),s.height/(w.turns%2?P:T))),U=W*M,L=I*M;u.useEffect(()=>{const t=new ResizeObserver(([c])=>{c&&l({width:c.contentRect.width,height:c.contentRect.height})});return n.current&&t.observe(n.current),()=>t.disconnect()},[]),u.useEffect(()=>{const t=a.current;if(!t||!S)return;const c=()=>{t.srcObject!==S.srcObject&&(t.srcObject=S.srcObject),t.play().catch(()=>{}),e.outer?.pause(),e.inner?.pause()};return c(),S.addEventListener("loadedmetadata",c),()=>{S.removeEventListener("loadedmetadata",c),t.pause(),t.srcObject=null;for(const z of[e.outer,e.inner])z?.play().catch(()=>{})}},[S,e.outer,e.inner]);const{motion:N,finish:_,prepare:ee}=ie(a,m,w,e.state.orientation,o),{angle:te,changeAngle:re,interacting:ne}=$(e.state.angleDegrees,async t=>{ee(t>=90);try{await e.setAngle(t)}catch(c){throw _(),c}},d),F=()=>{b.current?.release(),v.current=void 0};u.useEffect(()=>{j.current=new R.DuoButtonSender((c,z)=>i.current.button(c,z),c=>d(String(c)));const t=()=>{F(),j.current?.release(),p(void 0)};return window.addEventListener("blur",t),()=>{t(),window.removeEventListener("blur",t)}},[]),u.useEffect(()=>{b.current?.setDisplay(g,H),b.current?.active||(v.current=void 0)},[g,H]);const O=()=>{j.current?.release(),p(void 0)},q=t=>({disabled:e.watchOnly,onPointerDown:c=>{e.watchOnly||N||c.button!==0||(c.currentTarget.setPointerCapture(c.pointerId),j.current?.press(t),p(t))},onPointerUp:O,onPointerCancel:O,onLostPointerCapture:O,onBlur:O,onPointerEnter:()=>D(t),onPointerLeave:()=>D(void 0),onFocus:()=>h(w.guides.find(c=>c.button===t)?.edge),onKeyDown:c=>{N||(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),c.repeat||(j.current?.press(t),p(t)))},onKeyUp:c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),O())}}),K=t=>{const c=t.currentTarget.getBoundingClientRect();return{x:(t.clientX-c.left)/c.width,y:(t.clientY-c.top)/c.height}};return r.jsxs("div",{className:o?"rc-duo":"rc-duo rc-duo-frameless",children:[r.jsxs("div",{ref:n,className:"rc-duo-flat-stage","data-folding":!!N,"aria-busy":!!N,onPointerMove:t=>{if(!o)return;const c=t.currentTarget.getBoundingClientRect();h(Q(t.clientX-c.left,t.clientY-c.top,w.rect))},onPointerLeave:()=>{h(void 0),D(void 0)},children:[r.jsxs("div",{className:"rc-duo-flat-device","data-display":m?"inner":"outer",style:{width:P*M,height:T*M,transform:"translate(-50%, -50%) rotate("+w.turns*90+"deg)"},children:[o&&r.jsx(Z,{inner:m,width:P,height:T}),r.jsx("div",{className:"rc-duo-flat-screen",role:"application","aria-label":"iPhone Duo 2D simulator",tabIndex:0,style:{width:U,height:L,left:(P-W)/2*M,top:(T-I)/2*M,borderRadius:o?m?5.3*M:[.8,6.6,6.6,.8].map(t=>t*M+"px").join(" "):0},onKeyDown:N?void 0:e.onKeyDown,onKeyUp:e.onKeyUp,onPointerDown:t=>{if(e.watchOnly||N||v.current!==void 0||t.button!==0||!g)return;t.currentTarget.focus({preventScroll:!0}),t.currentTarget.setPointerCapture(t.pointerId);const c=K(t);v.current=t.pointerId,b.current?.touch("begin",c.x,c.y)},onPointerMove:t=>{if(v.current!==t.pointerId)return;const c=K(t);b.current?.touch("move",c.x,c.y)},onPointerUp:t=>{v.current===t.pointerId&&F()},onPointerCancel:F,onLostPointerCapture:F,children:r.jsx("video",{ref:a,autoPlay:!0,muted:!0,playsInline:!0,style:{width:m?L:U,height:m?U:L,transform:"translate(-50%, -50%) rotate("+(m?90:0)+"deg)"}})}),o&&w.buttons.map(t=>r.jsx("button",{type:"button",className:"rc-duo-physical","data-duo-button":t.button,"data-edge":t.edge,"data-highlighted":E===t.button,"data-pressed":k===t.button,"aria-label":R.DUO_BUTTONS[t.button]+" physical button",title:R.DUO_BUTTONS[t.button],style:{left:t.x*M,top:t.y*M,width:t.edge==="top"?Math.max(28,t.width*M):28,height:t.edge==="top"?28:Math.max(28,t.height*M)},...q(t.button),children:r.jsx("span",{style:{width:Math.max(2,t.width*M),height:Math.max(2,t.height*M)}})},t.button))]}),o&&w.guides.map(t=>r.jsx("button",{type:"button",className:"rc-duo-hardware","data-duo-button":t.button,"data-visible":f===t.edge,"data-pressed":k===t.button,"aria-label":R.DUO_BUTTONS[t.button],title:R.DUO_BUTTONS[t.button],style:{left:t.targetX,top:t.targetY,"--duo-hardware-icon-size":`${w.iconSize}px`,"--duo-hardware-icon-x":`${t.x-t.targetX}px`,"--duo-hardware-icon-y":`${t.y-t.targetY}px`},...q(t.button),children:r.jsx(A,{button:t.button})},t.button)),N&&r.jsx(ce,{motion:N,onFinish:_})]}),o&&r.jsx(G,{watchOnly:e.watchOnly,angle:te,changeAngle:re,interacting:ne,rotate:()=>{e.setOrientation(e.state.orientation==="portrait"?"landscape-left":"portrait").catch(t=>d(String(t)))},children:r.jsx("span",{className:"rc-duo-view-label",children:"Front view"})}),x&&r.jsx("div",{role:"alert",className:"rc-duo-error",children:x})]})}const le=Object.freeze(Object.defineProperty({__proto__:null,default:de},Symbol.toStringTag,{value:"Module"}));exports.DuoControls=G;exports.DuoHardwareIcon=A;exports.duoView=le;exports.flatHoverEdge=Q;exports.hardwareIconSize=J;exports.useDuoHinge=$;
|