@displayxr/inline3d 1.47.4 → 1.47.5
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/CHANGELOG.md +13 -0
- package/dist/call.js +5 -5
- package/js/camera/capture.js +31 -13
- package/package.json +1 -1
package/dist/call.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/* @displayxr/inline3d 1.47.
|
|
2
|
-
var Ds=Object.defineProperty;var le=(r,e)=>()=>(r&&(e=r(r=0)),e);var Ps=(r,e)=>{for(var t in e)Ds(r,t,{get:e[t],enumerable:!0})};function yr(r,e,t=1){let i=Ke,n=!!r&&r.displayWidthMeters>0&&r.displayHeightMeters>0&&r.displayPixelWidth>0&&r.displayPixelHeight>0,s=n?[r.displayWidthMeters,r.displayHeightMeters]:[...i.displaySizeM],o=n?[r.displayPixelWidth,r.displayPixelHeight]:[...i.displayPixels],a=(s[0]/o[0]+s[1]/o[1])/2,l=t>0?t:1,c=n?a*l:a*(o[1]/Math.max(1,globalThis.innerHeight||o[1])),u=r?.nominalViewerPosition?.z,f=Number.isFinite(u)&&u>.1;return{canvasSizeM:[(e?.width||0)*c,(e?.height||0)*c],metersPerCssPx:c,displaySizeM:s,nominalViewerM:f?u:i.nominalViewerM,eyeSeparationM:i.eyeSeparationM,source:{size:n?"display":"default",viewer:f?"display":"default",eyeSeparation:"default"}}}var Ke,Vt=le(()=>{"use strict";Ke=Object.freeze({displaySizeM:Object.freeze([.3456,.1944]),displayPixels:Object.freeze([1920,1080]),nominalViewerM:.65,eyeSeparationM:.063})});function ht(r,e,t,i,n,s,o,a,l,c,u){if(s<0||s+a>t||o<0)return-1;let f=0,h=0,d=0,p=a*l;for(let m=0;m<l;m++){let _=(n+m)*e+i,S=(o+m)*e+t+s;for(let x=0;x<a;x++){let C=r[S+x];f+=C,h+=C*C,d+=r[_+x]*C}}let g=f/p,w=h/p-g*g;return w<1?-1:(d/p-c*g)/(u*Math.sqrt(w))}function Oo(r,e,t,i,n,s){let o=0,a=0;for(let u=0;u<s;u++){let f=(i+u)*e+t;for(let h=0;h<n;h++){let d=r[f+h];o+=d,a+=d*d}}let l=n*s,c=o/l;return{mean:c,std:Math.sqrt(Math.max(0,a/l-c*c))}}function ge(r,e,t,i,n,s,o,{dMin:a,dMax:l,dyMax:c=2,uniq:u}={}){let f=e/2,{mean:h,std:d}=Oo(r,e,i,n,s,o);if(d<6)return null;let p=-2,g=0,w=0,m=new Map,_=(T,v,b,y,E)=>{for(let I=y;I<=E;I++){let O=n+I;if(!(O<0||O+o>t))for(let N=T;N<=v;N+=b){let $=ht(r,e,f,i,n,i-N,O,s,o,h,d);$>(m.get(N)??-2)&&m.set(N,$),$>p&&(p=$,g=N,w=I)}}},S=l-a>8;if(_(a,l,S?2:1,-c,c),S&&p>-1){let T=g,v=w;_(Math.max(a,T-2),Math.min(l,T+2),1,Math.max(-c,v-1),Math.min(c,v+1))}if(p<-1)return null;let x=-2,C=T=>{let v=-2;for(let b=-c;b<=c;b++){let y=n+b;if(!(y<0||y+o>t))for(let E=T-1;E<=T+1;E++)v=Math.max(v,ht(r,e,f,i,n,i-E,y,s,o,h,d))}return v};for(let[T,v]of m){if(Math.abs(T-g)<3||v<=x)continue;let y=v>=(m.get(T-2)??-2)&&v>=(m.get(T+2)??-2)&&v>0?C(T):v;y>x&&(x=y)}if(l-a>12&&x>-2&&p-x<(u??.08))return null;let M=ht(r,e,f,i,n,i-(g-1),n+w,s,o,h,d),k=ht(r,e,f,i,n,i-(g+1),n+w,s,o,h,d),P=0,D=M-2*p+k;return M>-1&&k>-1&&D<0&&(P=Math.max(-.5,Math.min(.5,.5*(M-k)/D))),{d:g+P,dy:w,c:p}}function Do(r,e,t,i={}){let n=e/2,s=i.block||Math.max(8,Math.round(n/20)),o=i.step||s,a=i.dMax??Math.round(n*.3),l=i.dMin??-Math.round(n*.05),c=Math.round(n*(i.roiX0??.15)),u=Math.round(n*(i.roiX1??.85))-s,f=Math.round(t*(i.roiY0??.05)),h=Math.round(t*(i.roiY1??.85))-s,d=[];for(let p=f;p<=h;p+=o)for(let g=c;g<=u;g+=o){let w=ge(r,e,t,g,p,s,s,{dMin:l,dMax:a,dyMax:i.dyMax??2,uniq:i.uniq});w&&w.c>=(i.minNcc??.8)&&d.push({x:g,y:p,...w})}return d}function Po(r,{tol:e=2,relTol:t=.1,minFrac:i=.12,minBlocks:n=3}={}){if(!r.length)return null;let s=Math.max(n,Math.ceil(r.length*i)),o=r.map(a=>a.d).sort((a,l)=>l-a);for(let a of o){let l=Math.max(e,t*Math.abs(a)),c=r.filter(u=>Math.abs(u.d-a)<=l);if(c.length>=s){let u=c.map(f=>f.d).sort((f,h)=>f-h);return{d:u[u.length>>1],members:c}}}return null}function Ao(r,e){let t=Math.min(...r.map(l=>l.y)),n=r.filter(l=>l.y<=t+2*e).map(l=>l.x),s=Math.min(...n),o=Math.max(...n)+e,a=o-s;return{x:(s+o)/2,y:t+.4*1.3*a}}function Mi(r,e,t,i={}){let n=e/2,s=i.block||Math.max(8,Math.round(n/20)),o=i.dMax??Math.round(n*.3),a=i.dMin??-Math.round(n*.05),l=i.focus||null,c="focus",u=0,f=null;if(!l){let S=Do(r,e,t,{...i,block:s,dMax:o,dMin:a});u=S.length;let x=Po(S,i);if(!x)return null;l=Ao(x.members,s),f=x.d,c="mode"}let h=Math.round(s*(i.refineW??3)),d=Math.round(s*(i.refineH??1.5)),p=Math.round(Math.max(0,Math.min(n-h,l.x-h/2))),g=Math.round(Math.max(0,Math.min(t-d,l.y-d/2))),w=f===null?a:Math.max(a,Math.floor(f)-4),m=f===null?o:Math.min(o,Math.ceil(f)+4),_=ge(r,e,t,p,g,h,d,{dMin:w,dMax:m,dyMax:i.dyMax??2});return _&&_.c>=(i.minNcc??.8)?{d:_.d,x:l.x,y:l.y,c:_.c,method:c,blocks:u}:f!==null?{d:f,x:l.x,y:l.y,c:0,method:c,blocks:u}:null}function ut(r,e){let t=new Uint8Array(e);for(let i=0,n=0;i<e;i++,n+=4)t[i]=r[n]*77+r[n+1]*150+r[n+2]*29>>8;return t}function dt({n:r=3}={}){let e=[],t={value:null,push(i){if(i===null||!Number.isFinite(i))return t.value;e.push(i),e.length>r&&e.shift();let n=[...e].sort((s,o)=>s-o);return t.value=n[n.length>>1],t.value},reset(){e.length=0,t.value=null}};return t}function rn(r,e,t,i,n,s){let o=new Float32Array(n*s);for(let a=0;a<s;a++)for(let l=0;l<n;l++)o[a*n+l]=r[(i+a)*e+t+l];return o}function Lo(r,e,t,i,n,s,o,a,l,c){let u=e/2,f=n*s,h=0,d=0;for(let _=0;_<f;_++)h+=i[_],d+=i[_]*i[_];h/=f;let p=Math.sqrt(Math.max(1e-6,d/f-h*h)),g=-2,w=o,m=a;for(let _=Math.max(0,a-c);_<=Math.min(t-s,a+c);_++)for(let S=Math.max(0,o-l);S<=Math.min(u-n,o+l);S++){let x=0,C=0,M=0;for(let T=0;T<s;T++){let v=(_+T)*e+S;for(let b=0;b<n;b++){let y=r[v+b];x+=y,C+=y*y,M+=y*i[T*n+b]}}let k=x/f,P=C/f-k*k;if(P<1)continue;let D=(M/f-k*h)/(Math.sqrt(P)*p);D>g&&(g=D,w=S,m=_)}return{x:w,y:m,c:g}}function $e({fullEveryMs:r=2e3,dWin:e=4,rx:t=12,ry:i=8,minTrackNcc:n=.75,jump:s=8}={}){let o=null,a=null;return{measure(c,u,f,h,d={}){let p=u/2,g=d.block||Math.max(8,Math.round(p/20)),w=Math.round(g*3),m=Math.round(g*1.5),_=null;if(o&&o.w===w&&o.h===m){let k=Lo(c,u,f,o.tpl,w,m,o.x,o.y,t,i);if(k.c>=n){let P=ge(c,u,f,k.x,k.y,w,m,{dMin:Math.floor(o.d)-e,dMax:Math.ceil(o.d)+e,dyMax:2});P&&P.c>=.8&&(_={m:P,f:k})}}let S=({m:k,f:P})=>(o={...o,x:P.x,y:P.y,d:k.d,tpl:rn(c,u,P.x,P.y,w,m)},{d:k.d,x:P.x+w/2,y:P.y+m/2,c:k.c,method:"track",blocks:0});if(_&&h-o.at<r)return S(_);let x=Mi(c,u,f,d);if(_&&(!x||Math.abs(x.d-_.m.d)>s)){let k=x&&a&&Math.abs(a.d-x.d)<=3;if(a=x&&!k?{d:x.d}:null,!k)return o.at=h,S(_)}else a=null;if(!x)return o=null,null;let C=Math.round(Math.max(0,Math.min(p-w,x.x-w/2))),M=Math.round(Math.max(0,Math.min(f-m,x.y-m/2)));return o={x:C,y:M,d:x.d,tpl:rn(c,u,C,M,w,m),w,h:m,at:h},x},reset(){o=null,a=null}}}function nn(r,e,t,i,n,s){let o=Math.max(1,s|0),a=Math.floor(i/o);a-=a&1;let l=Math.floor(n/o),c=new Uint8Array(a*l);if(o<=2){let h=o*o;for(let d=0;d<l;d++)for(let p=0;p<a;p++){let g=0;for(let w=0;w<o;w++){let m=e+(d*o+w)*t+p*o;for(let _=0;_<o;_++)g+=r[m+_]}c[d*a+p]=g/h|0}return{img:c,w:a,h:l}}let u=o>>2,f=3*o>>2;for(let h=0;h<l;h++){let d=e+(h*o+u)*t,p=e+(h*o+f)*t;for(let g=0;g<a;g++){let w=g*o+u,m=g*o+f;c[h*a+g]=r[d+w]+r[d+m]+r[p+w]+r[p+m]>>2}}return{img:c,w:a,h:l}}var Ei=le(()=>{"use strict"});function _t(r,e="@displayxr/inline3d"){if(r==null||r===!0)return{..._e};r===!1&&(r="off");let t=()=>new Error(`${e}: cursor.soften ${JSON.stringify(r)} \u2014 expected ${pt.map(s=>`'${s}'`).join(" | ")} or { ${mt.join(", ")} }.`);if(typeof r=="string"){if(!pt.includes(r))throw t();return{..._e,...sn(r)}}if(typeof r!="object"||Array.isArray(r))throw t();let i=Object.keys(r).filter(s=>!mt.includes(s));if(i.length)throw new Error(`${e}: cursor.soften \u2014 unknown option(s) ${i.join(", ")}; expected ${mt.join(", ")}.`);if(r.mode!==void 0&&!pt.includes(r.mode))throw t();let n={..._e,...sn(r.mode??"both")};for(let s of Object.keys(gt)){if(r[s]===void 0)continue;let[o,a,l]=gt[s];if(!Io(s,r[s]))throw new Error(`${e}: cursor.soften.${s} must be a number in ${l?"(":"["}${o}, ${a}].`);n[s]=r[s]}return n}function an(r,e="@displayxr/inline3d"){if(r==null||r===!1)return null;if(r==="depth"||r===!0)return{};if(typeof r!="object")throw new Error(`${e}: cursor ${JSON.stringify(r)} \u2014 expected 'depth' or { ${ft.join(", ")} }.`);let t=Object.keys(r).filter(i=>!ft.includes(i));if(t.length)throw new Error(`${e}: cursor \u2014 unknown option(s) ${t.join(", ")}; expected ${ft.join(", ")}.`);if(r.anchor!==void 0&&!Ri.includes(r.anchor))throw new Error(`${e}: cursor.anchor "${r.anchor}" \u2014 expected ${Ri.join(", ")}.`);if(r.pointerScope!==void 0&&r.pointerScope!=="canvas"&&r.pointerScope!=="window")throw new Error(`${e}: cursor.pointerScope "${r.pointerScope}" \u2014 expected 'canvas' or 'window'.`);if(r.debug!==void 0&&typeof r.debug!="boolean"&&r.debug!=="both")throw new Error(`${e}: cursor.debug ${JSON.stringify(r.debug)} \u2014 expected true, false or 'both'.`);for(let i of["height","margin"])if(r[i]!==void 0&&!(typeof r[i]=="number"&&r[i]>0&&Number.isFinite(r[i])))throw new Error(`${e}: cursor.${i} must be a positive number.`);if(r.soften!==void 0&&_t(r.soften,e),r.shape!==void 0&&!ve.includes(r.shape))throw new Error(`${e}: cursor.shape ${JSON.stringify(r.shape)} \u2014 expected ${ve.map(i=>`'${i}'`).join(" | ")}.`);if(r.shapeFor!==void 0&&r.shapeFor!==null&&typeof r.shapeFor!="function")throw new Error(`${e}: cursor.shapeFor must be a function (hit) => shape.`);return{...r}}function vt(r,e="@displayxr/inline3d"){let t=an(r,e);if(!t)return null;let i=Object.keys(t).filter(n=>!on.includes(n));if(i.length)throw new Error(`${e}: cursor \u2014 ${i.join(", ")} not supported on a stereo pair; expected ${on.join(", ")}.`);return t}var Ri,ft,ye,ve,pt,_e,gt,mt,Io,sn,on,we=le(()=>{"use strict";Ri=Object.freeze(["hybrid","screen","world"]),ft=Object.freeze(["height","margin","anchor","pointerScope","debug","soften","shape","shapeFor"]),ye=Object.freeze(["arrow","pointer","grab","grabbing","move","text","vertical-text","crosshair","not-allowed","help","wait","progress","copy","alias","context-menu","cell","ns-resize","ew-resize","nesw-resize","nwse-resize","col-resize","row-resize","zoom-in","zoom-out"]),ve=Object.freeze(["auto","none",...ye]),pt=Object.freeze(["both","off","alpha","blur"]),_e=Object.freeze({blur:!0,alpha:!0,blurK:.1,blurMaxPx:8,blurMaxFrac:.06,alphaMin:.5,fullD:.03}),gt=Object.freeze({blurK:[0,1e3,!1],blurMaxPx:[0,8,!1],blurMaxFrac:[0,.5,!1],alphaMin:[0,1,!1],fullD:[0,1e3,!0]}),mt=Object.freeze(["mode",...Object.keys(gt)]),Io=(r,e)=>{let[t,i,n]=gt[r];return typeof e=="number"&&Number.isFinite(e)&&e>=t&&e<=i&&!(n&&e<=t)},sn=r=>({blur:r==="both"||r==="blur",alpha:r==="both"||r==="alpha"});on=Object.freeze(["height","pointerScope","soften","shape","shapeFor"])});function Ai(r){return typeof r=="string"&&kn[r.trim().toLowerCase()]||"arrow"}function Uo(r){let e=[],t=0,i="",n="";for(let s=0;s<r.length;s++){let o=r[s];if(i){if(o==="\\"&&s+1<r.length){n+=o+r[++s];continue}o===i&&(i="")}else if(o==='"'||o==="'")i=o;else if(o==="(")t++;else if(o===")")t=Math.max(0,t-1);else if(o===","&&t===0){e.push(n.trim()),n="";continue}n+=o}return n.trim()&&e.push(n.trim()),e}function Li(r){if(typeof r!="string")return{images:[],keyword:"auto"};let e=xt.get(r);if(e)return e;let t=[],i="auto";for(let n of Uo(r)){let s=/^url\(\s*(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|([^)\s]*))\s*\)\s*(.*)$/is.exec(n);if(s){let o=(s[1]??s[2]??s[3]??"").replace(/\\(.)/g,"$1"),a=(s[4]||"").trim().split(/\s+/).filter(Boolean).map(Number),l=a.length===2&&a.every(Number.isFinite)?[a[0],a[1]]:null;o&&t.push({url:o,hotspot:l});continue}/^(-webkit-)?image-set\(/i.test(n)||(i=n.trim().toLowerCase())}return e=Object.freeze({images:Object.freeze(t),keyword:i}),xt.size>64&&xt.clear(),xt.set(r,e),e}function Tn(r){return Ai(Li(r).keyword)}function On(r,e=0){if(!r||r.byteLength<22)return null;let t=new DataView(r);if(t.getUint16(0,!0)!==0||t.getUint16(2,!0)!==2)return null;let i=t.getUint16(4,!0),n=-1;for(let o=0;o<i&&6+16*o+16<=r.byteLength;o++){let a=t.getUint8(6+16*o)||256;if((n<0||a===e)&&(n=o),a===e)break}if(n<0)return null;let s=6+16*n;return[t.getUint16(s+4,!0),t.getUint16(s+6,!0)]}function Dn(r,e=Ii){let t=Li(r);for(let i of t.images){let n=e.get(i.url);if(n.state==="failed")continue;if(n.state!=="ready")break;let s=Math.min(1,Cn/Math.max(n.width,n.height)),o=i.hotspot||n.curHotspot||[0,0],a=n.width*s,l=n.height*s,c=[Math.min(a,Math.max(0,o[0]*s)),Math.min(l,Math.max(0,o[1]*s))];return{kind:"image",key:i.url,entry:n,width:a,height:l,hotspot:c}}return Se(Ai(t.keyword))}function Se(r){if(r==="none")return{kind:"none"};let e=ye.includes(r)?r:"arrow";return{kind:"shape",name:e,key:`shape:${e}`}}function R(r,e,t,i,[n=0,s=0,o=0,a=0]=[]){let l=[],c=(u,f)=>{let h=l[l.length-1];(!h||Math.abs(h[0]-u)>1e-9||Math.abs(h[1]-f)>1e-9)&&l.push([u,f])};return c(r+n,e),c(t-s,e),c(t,e+s),c(t,i-o),c(t-o,i),c(r+a,i),c(r,i-a),c(r,e+n),l.length>1&&Math.abs(l[0][0]-l[l.length-1][0])<1e-9&&Math.abs(l[0][1]-l[l.length-1][1])<1e-9&&l.pop(),l}function Mt(r,e,t,i,n,s=n/3.5){let o=t-r,a=i-e,l=Math.hypot(o,a),c=o/l,u=a/l,f=-u*(n/2),h=c*(n/2),d=t-c*s,p=i-u*s,g=1-2*s/n;return Me([[r+f,e+h],[d+f,p+h],[t+f*g,i+h*g],[t-f*g,i-h*g],[d-f,p-h],[r-f,e-h]])}function xn(r,e,t,i,n){let s=t-r,o=i-e,a=Math.hypot(s,o),l=-o/a*(n/2),c=s/a*(n/2);return Me([[r+l,e+c],[t+l,i+c],[t-l,i-c],[r-l,e-c]])}function Pn(r,e,t,i=20){return Me(Array.from({length:i},(n,s)=>[r+t*Math.cos(2*Math.PI*s/i),e+t*Math.sin(2*Math.PI*s/i)]))}function Bo(r,e,t,i,n=24){let s=[],o=(a,l)=>[r+a*Math.cos(l),e+a*Math.sin(l)];for(let a=0;a<n;a++){let l=[0,1,2,3].map(c=>2*Math.PI*(a+c)/n);s.push(Me([...l.map(c=>o(i,c)),...l.reverse().map(c=>o(t,c))]))}return s}function qo(){return{pointer:{hot:[6.8,0],parts:[R(5,0,8.6,14,[1.2,1.2,0,0]),R(7.6,5.4,10.9,14,[1.1,1.1,0,0]),R(9.9,6.4,13.2,14,[1.1,1.1,0,0]),R(12.2,7.6,15.2,14,[.9,.9,0,0]),R(4.2,10.8,15.2,19,[0,0,3,2.2]),Mt(7.4,15,1,9,3.6)]},grab:{hot:[8.6,12.5],parts:[R(3,2.6,6.6,12.4,[1.2,1.2,0,0]),R(5.6,.6,9.2,12.4,[1.2,1.2,0,0]),R(8.2,1.4,11.8,12.4,[1.2,1.2,0,0]),R(10.8,3.6,14.2,12.4,[1.1,1.1,0,0]),R(3,9.4,14.2,18,[0,0,2.6,2.6]),Mt(6.2,14.4,.4,7,3.6)]},grabbing:{hot:[8.6,13],parts:[R(3,5.6,6.6,12.4,[1.2,1.2,0,0]),R(5.6,5,9.2,12.4,[1.2,1.2,0,0]),R(8.2,5.2,11.8,12.4,[1.2,1.2,0,0]),R(10.8,6,14.2,12.4,[1.1,1.1,0,0]),R(3,9.4,14.2,18,[0,0,2.6,2.6]),Mt(6,14.2,1.2,9,3.6)]},move:{hot:[9.5,9.5],parts:[R(3,7.8,16,11.2),R(7.8,3,11.2,16),V([9.5,0],[14,4.6],[5,4.6]),V([9.5,19],[5,14.4],[14,14.4]),V([0,9.5],[4.6,5],[4.6,14]),V([19,9.5],[14.4,14],[14.4,5])]},text:{hot:[9.5,9.5],parts:[R(8,.5,11,18.5),R(4.5,0,14.5,3),R(4.5,16,14.5,19)]},"vertical-text":{hot:[9.5,9.5],parts:Ve([R(8,.5,11,18.5),R(4.5,0,14.5,3),R(4.5,16,14.5,19)],90,9.5,9.5)},crosshair:{hot:[9.5,9.5],parts:[R(0,8,19,11),R(8,0,11,19)]},cell:{hot:[9.5,9.5],parts:[R(1.5,6.3,17.5,12.7),R(6.3,1.5,12.7,17.5)]},"not-allowed":{hot:[9.5,9.5],parts:[...Bo(9.5,9.5,5.4,8.8),xn(4.6,4.6,14.4,14.4,3.4)]},help:{hot:[0,0],parts:[...se(Be(),.8),Pn(13.6,12.4,5.4)],detail:[R(11.6,9,15.4,10.2),R(14.4,9,15.6,12.6),R(12.9,11.6,15.6,12.8),R(12.9,11.6,14.1,13.8),R(12.9,14.8,14.1,16)]},wait:{hot:[9.5,9.5],parts:Xo()},progress:{hot:[0,0],parts:[...se(Be(),.8),R(10.6,9,18.8,11.6),R(10.6,16.4,18.8,19),V([11.4,10.2],[18,10.2],[14.7,14.4]),V([14.7,13.6],[18,17.8],[11.4,17.8])]},copy:{hot:[0,0],parts:[...se(Be(),.8),R(9.6,9.8,18.8,19,[1.2,1.2,1.2,1.2])],detail:[R(13.6,11.8,14.8,17),R(11.6,13.8,16.8,15)]},alias:{hot:[0,0],parts:[...se(Be(),.8),R(9.6,9.8,18.8,19,[1.2,1.2,1.2,1.2])],detail:[xn(11.8,16.8,15.6,13,1.3),V([16.8,11.8],[16.8,15.4],[13.2,11.8])]},"context-menu":{hot:[0,0],parts:[...se(Be(),.8),R(9.2,8.6,18.8,19)],detail:[R(11,10.8,17,11.8),R(11,13.3,17,14.3),R(11,15.8,17,16.8)]},"ns-resize":{hot:[9.5,9.5],parts:St()},"ew-resize":{hot:[9.5,9.5],parts:Ve(St(),90,9.5,9.5)},"nesw-resize":{hot:[9.5,9.5],parts:se(Ve(St(),45,9.5,9.5),1.2,-1.9,-1.9)},"nwse-resize":{hot:[9.5,9.5],parts:se(Ve(St(),-45,9.5,9.5),1.2,-1.9,-1.9)},"col-resize":{hot:[9.5,9.5],parts:Sn()},"row-resize":{hot:[9.5,9.5],parts:Ve(Sn(),90,9.5,9.5)},"zoom-in":{hot:[7.5,7.5],parts:Mn(),detail:[R(4.4,6.9,10.6,8.1),R(6.9,4.4,8.1,10.6)]},"zoom-out":{hot:[7.5,7.5],parts:Mn(),detail:[R(4.4,6.9,10.6,8.1)]}}}function Fi(r){let e=ye.includes(r)?r:"arrow",t=En.get(e);if(t)return t;let i=c=>Object.freeze(c.map(u=>Object.freeze(u.map(f=>Object.freeze(f))))),n,s,o;if(e==="arrow")n=[ee],s=[Nn],o=[];else{let c=(Go||=qo())[e],u=f=>f.map(h=>h.map(([d,p])=>[(d-c.hot[0])/19,(p-c.hot[1])/19]));n=i(u(c.parts)),s=i(n.map(f=>kt(1/19,f))),o=i(u(c.detail||[]))}let a=n.flat().map(c=>c[0]),l=n.flat().map(c=>c[1]);return t=Object.freeze({name:e,parts:Object.freeze(n),fill:Object.freeze(s),detail:Object.freeze(o),box:Object.freeze([Math.min(...a),Math.min(...l),Math.max(...a),Math.max(...l)])}),En.set(e,t),t}function Ee(r,e=1/19){let t=Fi(r);return Math.abs(e-1/19)<1e-12?{outline:t.parts,fill:t.fill,detail:t.detail}:{outline:t.parts,fill:t.parts.map(i=>kt(e,i)),detail:t.detail}}function An(r,e,t=0){let i=Fi(r).box,n=(e>0&&Number.isFinite(e)?e:0)+(t>0&&Number.isFinite(t)?t:0);return[i[0]-n,i[1]-n,i[2]+n,i[3]+n]}function Ln(r,e,t,i,n,s=Hi,o=$i,a=Ee(r)){let l=0,c=0,u=0,f=0,h=0,d=i>0?qe:qe.slice(0,1),p=a.detail&&a.detail.length?a.detail:null;for(let[g,w,m]of d){let _=e+g*i,S=t+w*i,x=Pi(Di(a.outline,_,S),n),C=x>0?Pi(Di(a.fill,_,S),n):0;p&&C>0&&(C*=1-Pi(Di(p,_,S),n)),l+=m*(o[0]*x+(s[0]-o[0])*C),c+=m*(o[1]*x+(s[1]-o[1])*C),u+=m*(o[2]*x+(s[2]-o[2])*C),f+=m*x,h+=m}return f/=h,f>1e-5?[l/h/f,c/h/f,u/h/f,f]:[0,0,0,0]}function Ni(r,e,t,i,n,s,o=Hi,a=$i,l=Ee(r)){let c=i>0&&Number.isFinite(i)?i:1,u=1/c,[f,h,d,p]=An(r,n,u),g=Math.floor(e+f*c),w=Math.floor(t+h*c),m=Math.max(1,Math.ceil(e+d*c)-g),_=Math.max(1,Math.ceil(t+p*c)-w),S=new Uint8ClampedArray(m*_*4),x=s>=0&&s<=1?s:1;for(let C=0;C<_;C++){let M=(w+C+.5-t)/c;for(let k=0;k<m;k++){let P=Ln(r,(g+k+.5-e)/c,M,n,u,o,a,l);if(!(P[3]>0))continue;let D=(C*m+k)*4;S[D]=Math.round(P[0]*255),S[D+1]=Math.round(P[1]*255),S[D+2]=Math.round(P[2]*255),S[D+3]=Math.round(P[3]*x*255)}}return{x0:g,y0:w,width:m,height:_,data:S}}function ji(r,e,t,i,n,s=Ee(e),o="#fff",a="#000"){for(let[l,c]of[[s.outline,a],[s.fill,o],[s.detail||[],a]]){r.fillStyle=c;for(let u of l)r.beginPath(),u.forEach(([f,h],d)=>(d?r.lineTo:r.moveTo).call(r,t+f*n,i+h*n)),r.closePath(),r.fill()}}function zi(r,e,t,i,n){let s=i>0&&Number.isFinite(i)?Math.ceil(i)+1:0,o=e+2*s,a=t+2*s,l=new Uint8ClampedArray(o*a*4),c=n>=0&&n<=1?n:1,u=s?qe:qe.slice(0,1);for(let f=0;f<a;f++)for(let h=0;h<o;h++){let d=0,p=0,g=0,w=0,m=0;for(let[S,x,C]of u){m+=C;let M=Math.round(h-s+S*i),k=Math.round(f-s+x*i);if(M<0||k<0||M>=e||k>=t)continue;let P=(k*e+M)*4,D=r[P+3]/255*C;d+=r[P]*D,p+=r[P+1]*D,g+=r[P+2]*D,w+=D}if(!(w>1e-5))continue;let _=(f*o+h)*4;l[_]=d/w,l[_+1]=p/w,l[_+2]=g/w,l[_+3]=w/m*c*255}return{pad:s,width:o,height:a,data:l}}function Ct(r=globalThis.document){if(!r||!r.createElement)return!1;let e="inline3d-cursor-style";if(r.getElementById&&r.getElementById(e))return!0;let t=r.createElement("style");return t.id=e,t.textContent=Rn,(r.head||r.documentElement)?.appendChild(t),!0}function Fn(r,e){let t=globalThis.getComputedStyle;if(!r||typeof t!="function")return null;let i=[];for(let n of e)n&&n.hasAttribute&&n.hasAttribute(B)&&(i.push([n,n.getAttribute(B)]),n.removeAttribute(B));try{let n=t(r).cursor;return typeof n=="string"?n:null}catch{return null}finally{for(let[n,s]of i)n.setAttribute(B,s??"")}}var B,Rn,Cn,kn,$o,xt,Vo,Et,Ii,Me,V,Ve,se,Be,St,Sn,Xo,Mn,Go,En,Di,Pi,In,Rt,Xe,Wi=le(()=>{"use strict";Ui();we();B="data-inline3d-cursor-hidden",Rn=`[${B}],[${B}] *{cursor:none!important}`,Cn=128,kn=Object.freeze({auto:"arrow",default:"arrow",none:"none",pointer:"pointer",grab:"grab","-webkit-grab":"grab",grabbing:"grabbing","-webkit-grabbing":"grabbing",move:"move","all-scroll":"move",text:"text","vertical-text":"vertical-text",crosshair:"crosshair","not-allowed":"not-allowed","no-drop":"not-allowed",help:"help",wait:"wait",progress:"progress",copy:"copy",alias:"alias","context-menu":"context-menu",cell:"cell","n-resize":"ns-resize","s-resize":"ns-resize","ns-resize":"ns-resize","e-resize":"ew-resize","w-resize":"ew-resize","ew-resize":"ew-resize","ne-resize":"nesw-resize","sw-resize":"nesw-resize","nesw-resize":"nesw-resize","nw-resize":"nwse-resize","se-resize":"nwse-resize","nwse-resize":"nwse-resize","col-resize":"col-resize","row-resize":"row-resize","zoom-in":"zoom-in","-webkit-zoom-in":"zoom-in","zoom-out":"zoom-out","-webkit-zoom-out":"zoom-out"}),$o=Object.freeze(Object.keys(kn));xt=new Map;Vo=r=>/\.cur(?:[?#]|$)/i.test(r)||/^data:image\/(?:x-win-bitmap|x-icon|vnd\.microsoft\.icon)/i.test(r),Et=class{constructor({ImageCtor:e=globalThis.Image,fetchFn:t=globalThis.fetch}={}){this._Image=e,this._fetch=t,this._m=new Map}get(e){let t=this._m.get(e);if(t)return t;if(t={url:e,state:"loading",image:null,width:0,height:0,curHotspot:null},this._m.set(e,t),typeof this._Image!="function")return t.state="failed",t;let i=new this._Image;i.crossOrigin="anonymous";let n=1,s=()=>{--n>0||t.state==="failed"||(t.state="ready")};return i.onload=()=>{let o=i.naturalWidth||i.width,a=i.naturalHeight||i.height;if(!(o>0&&a>0))return void(t.state="failed");t.image=i,t.width=o,t.height=a,s()},i.onerror=()=>{t.state="failed"},Vo(e)&&typeof this._fetch=="function"&&(n++,Promise.resolve().then(()=>this._fetch(e,e.startsWith("data:")?void 0:{mode:"cors"})).then(o=>o&&o.ok!==!1?o.arrayBuffer():null).then(o=>{t.curHotspot=o?On(o,t.width):null}).catch(()=>{}).finally(s)),i.src=e,t}},Ii=new Et;Me=r=>{let e=0;for(let t=0;t<r.length;t++){let[i,n]=r[t],[s,o]=r[(t+1)%r.length];e+=i*o-s*n}return e>0?r:r.reverse()};V=(r,e,t)=>Me([r,e,t]),Ve=(r,e,t,i)=>{let n=e*Math.PI/180,s=Math.cos(n),o=Math.sin(n);return r.map(a=>Me(a.map(([l,c])=>[t+(l-t)*s-(c-i)*o,i+(l-t)*o+(c-i)*s])))},se=(r,e,t=0,i=0)=>r.map(n=>n.map(([s,o])=>[s*e+t,o*e+i])),Be=()=>[ee.map(([r,e])=>[r*19,e*19])],St=()=>[R(8,3,11,16),V([9.5,0],[14.2,5],[4.8,5]),V([9.5,19],[4.8,14],[14.2,14])],Sn=()=>[R(8,1,11,18),R(3.4,8,7.4,11),V([0,9.5],[4.4,5],[4.4,14]),R(11.6,8,15.6,11),V([19,9.5],[14.6,14],[14.6,5])],Xo=()=>[R(3,0,16,3),R(3,16,16,19),V([4.2,.5],[14.8,.5],[9.5,10]),V([9.5,9],[14.8,18.5],[4.2,18.5])],Mn=()=>[Pn(7.5,7.5,7),Mt(11.6,11.6,18.4,18.4,3.8,1)];Go=null,En=new Map;Di=(r,e,t)=>{let i=1/0;for(let n of r)i=Math.min(i,jn(n,e,t));return i},Pi=(r,e)=>e>0?Math.min(1,Math.max(0,.5-r/e)):r<0?1:0;In=100;Rt=class{constructor(e,{throttleMs:t=In}={}){this.pointer=e,this.throttleMs=t,this.css=null,this.reads=0,this._el=null,this._stale=!0,this._urgent=!0,this._lastRead=-1/0;let i=n=>s=>{let o=typeof s.composedPath=="function"?s.composedPath():null,a=o&&o.length?o[0]:s.target;a&&a.nodeType===1&&(this._el=a),this._stale=!0,n&&(this._urgent=!0)};this._onMove=i(!1),this._onPress=i(!0),this._target=e.scope==="window"?globalThis:e.canvas,this._target&&this._target.addEventListener&&(this._target.addEventListener("pointermove",this._onMove),this._target.addEventListener("pointerdown",this._onPress),this._target.addEventListener("pointerup",this._onPress),this._target.addEventListener("pointercancel",this._onPress))}value(e=globalThis.performance?globalThis.performance.now():Date.now()){return this._stale&&(this._urgent||this.css===null||e-this._lastRead>=this.throttleMs)&&this.read(e),this.css??"auto"}shape(e){return Tn(this.value(e))}read(e=globalThis.performance?globalThis.performance.now():Date.now()){let t=globalThis.document,i=this.pointer.canvas,n=this._el;n&&n.isConnected===!1&&(n=null);let s=Fn(n||i,[i,t&&t.documentElement]);return this.reads++,this._lastRead=e,this._stale=!1,this._urgent=!1,s!==null&&(this.css=s),this.css??"auto"}dispose(){this._target&&this._target.removeEventListener&&(this._target.removeEventListener("pointermove",this._onMove),this._target.removeEventListener("pointerdown",this._onPress),this._target.removeEventListener("pointerup",this._onPress),this._target.removeEventListener("pointercancel",this._onPress))}},Xe=class{constructor(e,{shape:t="auto",shapeFor:i=null,images:n=Ii}={}){if(!ve.includes(t))throw new Error(`@displayxr/inline3d: cursor.shape "${t}" \u2014 expected ${ve.join(", ")}.`);this.option=t,this.shapeFor=typeof i=="function"?i:null,this.images=n,this.reader=t==="auto"?new Rt(e):null,this.sprite=Se(t==="auto"?"arrow":t)}get current(){return this.sprite.kind==="shape"?this.sprite.name:this.sprite.kind}pick(e,t){let i=this.reader?this.reader.value(t):null,n=i===null?null:Dn(i,this.images),s=n?n.kind==="shape"?n.name:n.kind:null,o;if(this.shapeFor)try{o=this.shapeFor({...e,css:s,cssValue:i})}catch(l){this._warned||(this._warned=!0,console.warn("[inline3d] cursor.shapeFor threw; using the page cursor.",l))}let a=l=>l==="none"||ye.includes(l);return a(o)?this.sprite=Se(o):a(this.option)?this.sprite=Se(this.option):this.sprite=n||Se("arrow"),this.sprite}dispose(){this.reader?.dispose()}}});function $n(r){return r>0&&Number.isFinite(r)?Math.min(.5,Xi/r):Yo}function Un(r,e){return r<=Ko?!(e>0&&Number.isFinite(e))||-r*e>=Jo:!1}function qi(r,e,t){if(!e||!Number.isFinite(t)||!(t<0))return 0;let i=Math.min(0,Number.isFinite(r.maxDisparity)?r.maxDisparity:0);return Math.min(i,Math.max(r.minDisparity,t-r.margin))}function Vn(r,e,t,i){if(!r.primed||i<r.last||i-r.last>e.stale)return r.primed=!0,r.disparity=t,r.last=i,t;if(i===r.last)return r.disparity;let n=i-r.last,s=t<r.disparity?e.riseTau:e.sinkTau,o=s>0?1-Math.exp(-n/s):1;return r.disparity+=o*(t-r.disparity),r.last=i,r.disparity}function zn(r){let e=r&&r.pointerType;return!e||e==="mouse"?!0:e==="pen"?!(r.buttons>0):!1}function Zo(r){return!!r&&"onpointerrawupdate"in r&&globalThis.isSecureContext!==!1}function Qo(r){let e=globalThis.document;if(!e||!e.documentElement)return;r&&Ct(e),Vi=Math.max(0,Vi+(r?1:-1));let t=e.documentElement;Vi>0?t.setAttribute?.(B,""):t.removeAttribute?.(B)}function Wn(r){return!!r&&typeof r.setCursorDepth=="function"&&typeof r.getCursorDepthSupport=="function"}function ra(r,e,t,i){let n=.75*t,s=[[r,e]];for(let o=0;o<8;o++){let a=o*Math.PI/4;s.push([r+n*Math.cos(a)/i,e+n*Math.sin(a)])}return s}function Bn(r,e,t,i){return[[r,e],...ra(r+.3*t/i,e+.5*t,t,i)]}function kt(r,e=ee){let t=0;for(let s=0;s<e.length;s++){let[o,a]=e[s],[l,c]=e[(s+1)%e.length];t+=o*c-l*a}let i=t>0?1:-1,n=e.map((s,o)=>{let a=e[(o+1)%e.length],l=a[0]-s[0],c=a[1]-s[1],u=Math.hypot(l,c)||1;return[-c/u*i,l/u*i]});return e.map((s,o)=>{let a=n[(o+e.length-1)%e.length],l=n[o],c=r/(1+a[0]*l[0]+a[1]*l[1]);return[s[0]+(a[0]+l[0])*c,s[1]+(a[1]+l[1])*c]})}function Xn(r,e,t,i=_e){let n={blurPx:0,alpha:1},s=i;if(!s)return n;if(s.blur&&Number.isFinite(e)&&s.blurK>0&&s.blurMaxPx>0){let o=s.blurMaxPx;if(s.blurMaxFrac>0&&Number.isFinite(t)&&t>0){let l=s.blurMaxFrac*t;o=l<o?l:o}let a=s.blurK*Math.abs(e);n.blurPx=a<o?a:o}if(s.alpha&&Number.isFinite(r)&&s.fullD>0){let o=Math.abs(r)/s.fullD;o=o<1?o:1;let a=o*o*(3-2*o),l=s.alphaMin<0?0:s.alphaMin>1?1:s.alphaMin;n.alpha=1-(1-l)*a}return n}function jn(r,e,t){let i=(e-r[0][0])**2+(t-r[0][1])**2,n=1;for(let s=0,o=r.length-1;s<r.length;o=s,s++){let a=r[s],l=r[o],c=l[0]-a[0],u=l[1]-a[1],f=e-a[0],h=t-a[1],d=Math.min(1,Math.max(0,(f*c+h*u)/(c*c+u*u))),p=f-c*d,g=h-u*d;i=Math.min(i,p*p+g*g);let w=t>=a[1],m=t<l[1],_=c*h>u*f;(w&&m&&_||!w&&!m&&!_)&&(n=-n)}return n*Math.sqrt(i)}var Yo,Xi,Ko,Jo,Dt,Tt,Vi,ea,ta,ia,Bi,Ot,Hn,ee,Tl,Nn,Hi,$i,qe,Ol,Dl,Pl,Ui=le(()=>{"use strict";we();we();Wi();Wi();Yo=.03,Xi=19;Ko=-.005,Jo=.5;Dt=Object.freeze({margin:.015,minDisparity:-.6,maxDisparity:0,riseTau:.03,sinkTau:.25,stale:.5});Tt=class{constructor(e,{scope:t="canvas",keepCss:i=!1}={}){if(t!=="canvas"&&t!=="window")throw new Error(`@displayxr/inline3d: cursor pointerScope "${t}" \u2014 expected 'canvas' or 'window'.`);this.canvas=e,this.scope=t,this.keepCss=!!i,this._uv=null,this.sampleTime=0,this.samples=0,this._hidden=!1,this._cx=0,this._cy=0,this._pending=!1,this._onMove=n=>this._sample(n),this._onLeave=()=>{this.uv=null},this._onDown=n=>{zn(n)||(this.uv=null)},this._target=t==="window"?globalThis:e,this.source=Zo(this._target)?"pointerrawupdate":"pointermove",this._target.addEventListener("pointermove",this._onMove),this.source==="pointerrawupdate"&&this._target.addEventListener("pointerrawupdate",this._onMove),this._target.addEventListener("pointerdown",this._onDown),t==="window"?(this._onOut=n=>{n.relatedTarget||(this.uv=null)},globalThis.addEventListener("pointerout",this._onOut),globalThis.addEventListener("blur",this._onLeave)):e.addEventListener("pointerleave",this._onLeave)}get uv(){if(this._pending){this._pending=!1;let e=this.canvas.getBoundingClientRect();if(!(e.width>0&&e.height>0))this._uv=null;else{let t=(this._cx-e.left)/e.width,i=(this._cy-e.top)/e.height;this._uv=t>=0&&t<=1&&i>=0&&i<=1?[t,i]:null}}return this._uv}set uv(e){this._pending=!1,this._uv=e}_sample(e){if(!zn(e)){this.uv=null;return}let t=typeof e.getCoalescedEvents=="function"?e.getCoalescedEvents():null,i=t&&t.length?t[t.length-1]:e,n=i.timeStamp>0?i.timeStamp:e.timeStamp>0?e.timeStamp:globalThis.performance?globalThis.performance.now():Date.now();n<this.sampleTime||(this.samples++,this.sampleTime=n,this._cx=i.clientX,this._cy=i.clientY,this._pending=!0)}set(e,t){this.uv=e==null?null:[e,t]}aspect(){let e=this.canvas.getBoundingClientRect();return e.height>0?e.width/e.height:1}cssHeight(){let e=this.canvas.getBoundingClientRect();return e.height>0?e.height:0}panelPx(){return this.cssHeight()*(globalThis.devicePixelRatio>0?globalThis.devicePixelRatio:1)}panelSize(){let e=this.canvas.getBoundingClientRect(),t=globalThis.devicePixelRatio>0?globalThis.devicePixelRatio:1;return e.width>0&&e.height>0?[e.width*t,e.height*t]:[0,0]}hideCss(e){this.keepCss&&(e=!1),e!==this._hidden&&(this.scope==="window"?Qo(e):this.canvas.setAttribute&&(e?(Ct(),this.canvas.setAttribute(B,"")):this.canvas.removeAttribute(B)),this._hidden=e)}dispose(){this._target.removeEventListener("pointermove",this._onMove),this.source==="pointerrawupdate"&&this._target.removeEventListener("pointerrawupdate",this._onMove),this._target.removeEventListener("pointerdown",this._onDown),this.scope==="window"?(globalThis.removeEventListener("pointerout",this._onOut),globalThis.removeEventListener("blur",this._onLeave)):this.canvas.removeEventListener("pointerleave",this._onLeave),this.hideCss(!1)}};Vi=0;ea=2e3,ta=6,ia=1e4;Bi=new WeakMap,Ot=class{constructor(){this.target=null,this._sent=!1,this.last=null}get support(){let e=this.target;if(!Wn(e))return"none";let t=Bi.get(e);return t?t.state:"pending"}get drawing(){return this.support==="runtime"}bind(e){let t=e||null;if(t!==this.target&&(this.withdraw(),this.target=t),!Wn(t))return!1;let i=Bi.get(t);if(i||Bi.set(t,i={state:"pending",probes:0,inFlight:!1,at:0}),i.state==="runtime"||i.inFlight)return i.state==="runtime";let n=globalThis.performance?globalThis.performance.now():Date.now(),s=i.probes<ta?ea:ia;if(i.probes===0||n-i.at>=s){i.probes++,i.at=n,i.inFlight=!0;let o;try{o=Promise.resolve(t.getCursorDepthSupport())}catch(a){o=Promise.reject(a)}o.then(a=>{i.inFlight=!1,i.state=a==="runtime"?"runtime":"none"},()=>{i.inFlight=!1,i.state="none"})}return i.state==="runtime"}report(e,t,i){if(!this.drawing)return!1;let n={u:Hn(e),v:Hn(t)};i!=null&&Number.isFinite(i)&&(n.disparityPx=i);try{this.target.setCursorDepth(n)}catch{return!1}return this._sent=!0,this.last={u:n.u,v:n.v,disparityPx:n.disparityPx??null},!0}withdraw(){if(this.last=null,!!this._sent){this._sent=!1;try{this.target?.setCursorDepth()}catch{}}}dispose(){this.withdraw(),this.target=null}},Hn=r=>r>0?r<1?r:1:0;ee=Object.freeze([[0,0],[0,16],[4.2,12.4],[6.9,18.6],[9.5,17.5],[6.8,11.5],[11.7,11.5]].map(([r,e])=>Object.freeze([r/19,e/19]))),Tl=Object.freeze([[0,1,2],[0,2,5],[0,5,6],[2,3,4],[2,4,5]]);Nn=Object.freeze(kt(1/19).map(r=>Object.freeze(r))),Hi=Object.freeze([1,1,1,1]),$i=Object.freeze([.02,.02,.03,1]);qe=Object.freeze([Object.freeze([0,0,1]),...[[.5,0],[-.5,0],[0,.5],[0,-.5]].map(([r,e])=>Object.freeze([r,e,.7066])),...Array.from({length:8},(r,e)=>{let t=.3927+.7854*e;return Object.freeze([Math.cos(t),Math.sin(t),.2494])})]),Ol=Object.freeze([Math.max(...ee.map(r=>r[0])),Math.max(...ee.map(r=>r[1]))]);Dl=Object.freeze({declarations:`#ifdef PICK_PASS
|
|
1
|
+
/* @displayxr/inline3d 1.47.5 — dist/call.js — Apache-2.0 — https://github.com/DisplayXR/displayxr-web */
|
|
2
|
+
var Ds=Object.defineProperty;var le=(r,e)=>()=>(r&&(e=r(r=0)),e);var Ps=(r,e)=>{for(var t in e)Ds(r,t,{get:e[t],enumerable:!0})};function yr(r,e,t=1){let i=Ke,n=!!r&&r.displayWidthMeters>0&&r.displayHeightMeters>0&&r.displayPixelWidth>0&&r.displayPixelHeight>0,s=n?[r.displayWidthMeters,r.displayHeightMeters]:[...i.displaySizeM],o=n?[r.displayPixelWidth,r.displayPixelHeight]:[...i.displayPixels],a=(s[0]/o[0]+s[1]/o[1])/2,l=t>0?t:1,c=n?a*l:a*(o[1]/Math.max(1,globalThis.innerHeight||o[1])),d=r?.nominalViewerPosition?.z,f=Number.isFinite(d)&&d>.1;return{canvasSizeM:[(e?.width||0)*c,(e?.height||0)*c],metersPerCssPx:c,displaySizeM:s,nominalViewerM:f?d:i.nominalViewerM,eyeSeparationM:i.eyeSeparationM,source:{size:n?"display":"default",viewer:f?"display":"default",eyeSeparation:"default"}}}var Ke,Bt=le(()=>{"use strict";Ke=Object.freeze({displaySizeM:Object.freeze([.3456,.1944]),displayPixels:Object.freeze([1920,1080]),nominalViewerM:.65,eyeSeparationM:.063})});function ut(r,e,t,i,n,s,o,a,l,c,d){if(s<0||s+a>t||o<0)return-1;let f=0,h=0,u=0,m=a*l;for(let w=0;w<l;w++){let g=(n+w)*e+i,x=(o+w)*e+t+s;for(let _=0;_<a;_++){let M=r[x+_];f+=M,h+=M*M,u+=r[g+_]*M}}let p=f/m,b=h/m-p*p;return b<1?-1:(u/m-c*p)/(d*Math.sqrt(b))}function Oo(r,e,t,i,n,s){let o=0,a=0;for(let d=0;d<s;d++){let f=(i+d)*e+t;for(let h=0;h<n;h++){let u=r[f+h];o+=u,a+=u*u}}let l=n*s,c=o/l;return{mean:c,std:Math.sqrt(Math.max(0,a/l-c*c))}}function ge(r,e,t,i,n,s,o,{dMin:a,dMax:l,dyMax:c=2,uniq:d}={}){let f=e/2,{mean:h,std:u}=Oo(r,e,i,n,s,o);if(u<6)return null;let m=-2,p=0,b=0,w=new Map,g=(T,v,S,y,R)=>{for(let I=y;I<=R;I++){let O=n+I;if(!(O<0||O+o>t))for(let N=T;N<=v;N+=S){let $=ut(r,e,f,i,n,i-N,O,s,o,h,u);$>(w.get(N)??-2)&&w.set(N,$),$>m&&(m=$,p=N,b=I)}}},x=l-a>8;if(g(a,l,x?2:1,-c,c),x&&m>-1){let T=p,v=b;g(Math.max(a,T-2),Math.min(l,T+2),1,Math.max(-c,v-1),Math.min(c,v+1))}if(m<-1)return null;let _=-2,M=T=>{let v=-2;for(let S=-c;S<=c;S++){let y=n+S;if(!(y<0||y+o>t))for(let R=T-1;R<=T+1;R++)v=Math.max(v,ut(r,e,f,i,n,i-R,y,s,o,h,u))}return v};for(let[T,v]of w){if(Math.abs(T-p)<3||v<=_)continue;let y=v>=(w.get(T-2)??-2)&&v>=(w.get(T+2)??-2)&&v>0?M(T):v;y>_&&(_=y)}if(l-a>12&&_>-2&&m-_<(d??.08))return null;let E=ut(r,e,f,i,n,i-(p-1),n+b,s,o,h,u),C=ut(r,e,f,i,n,i-(p+1),n+b,s,o,h,u),P=0,D=E-2*m+C;return E>-1&&C>-1&&D<0&&(P=Math.max(-.5,Math.min(.5,.5*(E-C)/D))),{d:p+P,dy:b,c:m}}function Do(r,e,t,i={}){let n=e/2,s=i.block||Math.max(8,Math.round(n/20)),o=i.step||s,a=i.dMax??Math.round(n*.3),l=i.dMin??-Math.round(n*.05),c=Math.round(n*(i.roiX0??.15)),d=Math.round(n*(i.roiX1??.85))-s,f=Math.round(t*(i.roiY0??.05)),h=Math.round(t*(i.roiY1??.85))-s,u=[];for(let m=f;m<=h;m+=o)for(let p=c;p<=d;p+=o){let b=ge(r,e,t,p,m,s,s,{dMin:l,dMax:a,dyMax:i.dyMax??2,uniq:i.uniq});b&&b.c>=(i.minNcc??.8)&&u.push({x:p,y:m,...b})}return u}function Po(r,{tol:e=2,relTol:t=.1,minFrac:i=.12,minBlocks:n=3}={}){if(!r.length)return null;let s=Math.max(n,Math.ceil(r.length*i)),o=r.map(a=>a.d).sort((a,l)=>l-a);for(let a of o){let l=Math.max(e,t*Math.abs(a)),c=r.filter(d=>Math.abs(d.d-a)<=l);if(c.length>=s){let d=c.map(f=>f.d).sort((f,h)=>f-h);return{d:d[d.length>>1],members:c}}}return null}function Ao(r,e){let t=Math.min(...r.map(l=>l.y)),n=r.filter(l=>l.y<=t+2*e).map(l=>l.x),s=Math.min(...n),o=Math.max(...n)+e,a=o-s;return{x:(s+o)/2,y:t+.4*1.3*a}}function Mi(r,e,t,i={}){let n=e/2,s=i.block||Math.max(8,Math.round(n/20)),o=i.dMax??Math.round(n*.3),a=i.dMin??-Math.round(n*.05),l=i.focus||null,c="focus",d=0,f=null;if(!l){let x=Do(r,e,t,{...i,block:s,dMax:o,dMin:a});d=x.length;let _=Po(x,i);if(!_)return null;l=Ao(_.members,s),f=_.d,c="mode"}let h=Math.round(s*(i.refineW??3)),u=Math.round(s*(i.refineH??1.5)),m=Math.round(Math.max(0,Math.min(n-h,l.x-h/2))),p=Math.round(Math.max(0,Math.min(t-u,l.y-u/2))),b=f===null?a:Math.max(a,Math.floor(f)-4),w=f===null?o:Math.min(o,Math.ceil(f)+4),g=ge(r,e,t,m,p,h,u,{dMin:b,dMax:w,dyMax:i.dyMax??2});return g&&g.c>=(i.minNcc??.8)?{d:g.d,x:l.x,y:l.y,c:g.c,method:c,blocks:d}:f!==null?{d:f,x:l.x,y:l.y,c:0,method:c,blocks:d}:null}function dt(r,e){let t=new Uint8Array(e);for(let i=0,n=0;i<e;i++,n+=4)t[i]=r[n]*77+r[n+1]*150+r[n+2]*29>>8;return t}function ft({n:r=3}={}){let e=[],t={value:null,push(i){if(i===null||!Number.isFinite(i))return t.value;e.push(i),e.length>r&&e.shift();let n=[...e].sort((s,o)=>s-o);return t.value=n[n.length>>1],t.value},reset(){e.length=0,t.value=null}};return t}function rn(r,e,t,i,n,s){let o=new Float32Array(n*s);for(let a=0;a<s;a++)for(let l=0;l<n;l++)o[a*n+l]=r[(i+a)*e+t+l];return o}function Lo(r,e,t,i,n,s,o,a,l,c){let d=e/2,f=n*s,h=0,u=0;for(let g=0;g<f;g++)h+=i[g],u+=i[g]*i[g];h/=f;let m=Math.sqrt(Math.max(1e-6,u/f-h*h)),p=-2,b=o,w=a;for(let g=Math.max(0,a-c);g<=Math.min(t-s,a+c);g++)for(let x=Math.max(0,o-l);x<=Math.min(d-n,o+l);x++){let _=0,M=0,E=0;for(let T=0;T<s;T++){let v=(g+T)*e+x;for(let S=0;S<n;S++){let y=r[v+S];_+=y,M+=y*y,E+=y*i[T*n+S]}}let C=_/f,P=M/f-C*C;if(P<1)continue;let D=(E/f-C*h)/(Math.sqrt(P)*m);D>p&&(p=D,b=x,w=g)}return{x:b,y:w,c:p}}function $e({fullEveryMs:r=2e3,dWin:e=4,rx:t=12,ry:i=8,minTrackNcc:n=.75,jump:s=8}={}){let o=null,a=null;return{measure(c,d,f,h,u={}){let m=d/2,p=u.block||Math.max(8,Math.round(m/20)),b=Math.round(p*3),w=Math.round(p*1.5),g=null;if(o&&o.w===b&&o.h===w){let C=Lo(c,d,f,o.tpl,b,w,o.x,o.y,t,i);if(C.c>=n){let P=ge(c,d,f,C.x,C.y,b,w,{dMin:Math.floor(o.d)-e,dMax:Math.ceil(o.d)+e,dyMax:2});P&&P.c>=.8&&(g={m:P,f:C})}}let x=({m:C,f:P})=>(o={...o,x:P.x,y:P.y,d:C.d,tpl:rn(c,d,P.x,P.y,b,w)},{d:C.d,x:P.x+b/2,y:P.y+w/2,c:C.c,method:"track",blocks:0});if(g&&h-o.at<r)return x(g);let _=Mi(c,d,f,u);if(g&&(!_||Math.abs(_.d-g.m.d)>s)){let C=_&&a&&Math.abs(a.d-_.d)<=3;if(a=_&&!C?{d:_.d}:null,!C)return o.at=h,x(g)}else a=null;if(!_)return o=null,null;let M=Math.round(Math.max(0,Math.min(m-b,_.x-b/2))),E=Math.round(Math.max(0,Math.min(f-w,_.y-w/2)));return o={x:M,y:E,d:_.d,tpl:rn(c,d,M,E,b,w),w:b,h:w,at:h},_},reset(){o=null,a=null}}}function nn(r,e,t,i,n,s){let o=Math.max(1,s|0),a=Math.floor(i/o);a-=a&1;let l=Math.floor(n/o),c=new Uint8Array(a*l);if(o<=2){let h=o*o;for(let u=0;u<l;u++)for(let m=0;m<a;m++){let p=0;for(let b=0;b<o;b++){let w=e+(u*o+b)*t+m*o;for(let g=0;g<o;g++)p+=r[w+g]}c[u*a+m]=p/h|0}return{img:c,w:a,h:l}}let d=o>>2,f=3*o>>2;for(let h=0;h<l;h++){let u=e+(h*o+d)*t,m=e+(h*o+f)*t;for(let p=0;p<a;p++){let b=p*o+d,w=p*o+f;c[h*a+p]=r[u+b]+r[u+w]+r[m+b]+r[m+w]>>2}}return{img:c,w:a,h:l}}var Ei=le(()=>{"use strict"});function vt(r,e="@displayxr/inline3d"){if(r==null||r===!0)return{..._e};r===!1&&(r="off");let t=()=>new Error(`${e}: cursor.soften ${JSON.stringify(r)} \u2014 expected ${mt.map(s=>`'${s}'`).join(" | ")} or { ${gt.join(", ")} }.`);if(typeof r=="string"){if(!mt.includes(r))throw t();return{..._e,...sn(r)}}if(typeof r!="object"||Array.isArray(r))throw t();let i=Object.keys(r).filter(s=>!gt.includes(s));if(i.length)throw new Error(`${e}: cursor.soften \u2014 unknown option(s) ${i.join(", ")}; expected ${gt.join(", ")}.`);if(r.mode!==void 0&&!mt.includes(r.mode))throw t();let n={..._e,...sn(r.mode??"both")};for(let s of Object.keys(_t)){if(r[s]===void 0)continue;let[o,a,l]=_t[s];if(!Io(s,r[s]))throw new Error(`${e}: cursor.soften.${s} must be a number in ${l?"(":"["}${o}, ${a}].`);n[s]=r[s]}return n}function an(r,e="@displayxr/inline3d"){if(r==null||r===!1)return null;if(r==="depth"||r===!0)return{};if(typeof r!="object")throw new Error(`${e}: cursor ${JSON.stringify(r)} \u2014 expected 'depth' or { ${pt.join(", ")} }.`);let t=Object.keys(r).filter(i=>!pt.includes(i));if(t.length)throw new Error(`${e}: cursor \u2014 unknown option(s) ${t.join(", ")}; expected ${pt.join(", ")}.`);if(r.anchor!==void 0&&!Ri.includes(r.anchor))throw new Error(`${e}: cursor.anchor "${r.anchor}" \u2014 expected ${Ri.join(", ")}.`);if(r.pointerScope!==void 0&&r.pointerScope!=="canvas"&&r.pointerScope!=="window")throw new Error(`${e}: cursor.pointerScope "${r.pointerScope}" \u2014 expected 'canvas' or 'window'.`);if(r.debug!==void 0&&typeof r.debug!="boolean"&&r.debug!=="both")throw new Error(`${e}: cursor.debug ${JSON.stringify(r.debug)} \u2014 expected true, false or 'both'.`);for(let i of["height","margin"])if(r[i]!==void 0&&!(typeof r[i]=="number"&&r[i]>0&&Number.isFinite(r[i])))throw new Error(`${e}: cursor.${i} must be a positive number.`);if(r.soften!==void 0&&vt(r.soften,e),r.shape!==void 0&&!ve.includes(r.shape))throw new Error(`${e}: cursor.shape ${JSON.stringify(r.shape)} \u2014 expected ${ve.map(i=>`'${i}'`).join(" | ")}.`);if(r.shapeFor!==void 0&&r.shapeFor!==null&&typeof r.shapeFor!="function")throw new Error(`${e}: cursor.shapeFor must be a function (hit) => shape.`);return{...r}}function yt(r,e="@displayxr/inline3d"){let t=an(r,e);if(!t)return null;let i=Object.keys(t).filter(n=>!on.includes(n));if(i.length)throw new Error(`${e}: cursor \u2014 ${i.join(", ")} not supported on a stereo pair; expected ${on.join(", ")}.`);return t}var Ri,pt,ye,ve,mt,_e,_t,gt,Io,sn,on,we=le(()=>{"use strict";Ri=Object.freeze(["hybrid","screen","world"]),pt=Object.freeze(["height","margin","anchor","pointerScope","debug","soften","shape","shapeFor"]),ye=Object.freeze(["arrow","pointer","grab","grabbing","move","text","vertical-text","crosshair","not-allowed","help","wait","progress","copy","alias","context-menu","cell","ns-resize","ew-resize","nesw-resize","nwse-resize","col-resize","row-resize","zoom-in","zoom-out"]),ve=Object.freeze(["auto","none",...ye]),mt=Object.freeze(["both","off","alpha","blur"]),_e=Object.freeze({blur:!0,alpha:!0,blurK:.1,blurMaxPx:8,blurMaxFrac:.06,alphaMin:.5,fullD:.03}),_t=Object.freeze({blurK:[0,1e3,!1],blurMaxPx:[0,8,!1],blurMaxFrac:[0,.5,!1],alphaMin:[0,1,!1],fullD:[0,1e3,!0]}),gt=Object.freeze(["mode",...Object.keys(_t)]),Io=(r,e)=>{let[t,i,n]=_t[r];return typeof e=="number"&&Number.isFinite(e)&&e>=t&&e<=i&&!(n&&e<=t)},sn=r=>({blur:r==="both"||r==="blur",alpha:r==="both"||r==="alpha"});on=Object.freeze(["height","pointerScope","soften","shape","shapeFor"])});function Ai(r){return typeof r=="string"&&kn[r.trim().toLowerCase()]||"arrow"}function Uo(r){let e=[],t=0,i="",n="";for(let s=0;s<r.length;s++){let o=r[s];if(i){if(o==="\\"&&s+1<r.length){n+=o+r[++s];continue}o===i&&(i="")}else if(o==='"'||o==="'")i=o;else if(o==="(")t++;else if(o===")")t=Math.max(0,t-1);else if(o===","&&t===0){e.push(n.trim()),n="";continue}n+=o}return n.trim()&&e.push(n.trim()),e}function Li(r){if(typeof r!="string")return{images:[],keyword:"auto"};let e=St.get(r);if(e)return e;let t=[],i="auto";for(let n of Uo(r)){let s=/^url\(\s*(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|([^)\s]*))\s*\)\s*(.*)$/is.exec(n);if(s){let o=(s[1]??s[2]??s[3]??"").replace(/\\(.)/g,"$1"),a=(s[4]||"").trim().split(/\s+/).filter(Boolean).map(Number),l=a.length===2&&a.every(Number.isFinite)?[a[0],a[1]]:null;o&&t.push({url:o,hotspot:l});continue}/^(-webkit-)?image-set\(/i.test(n)||(i=n.trim().toLowerCase())}return e=Object.freeze({images:Object.freeze(t),keyword:i}),St.size>64&&St.clear(),St.set(r,e),e}function Tn(r){return Ai(Li(r).keyword)}function On(r,e=0){if(!r||r.byteLength<22)return null;let t=new DataView(r);if(t.getUint16(0,!0)!==0||t.getUint16(2,!0)!==2)return null;let i=t.getUint16(4,!0),n=-1;for(let o=0;o<i&&6+16*o+16<=r.byteLength;o++){let a=t.getUint8(6+16*o)||256;if((n<0||a===e)&&(n=o),a===e)break}if(n<0)return null;let s=6+16*n;return[t.getUint16(s+4,!0),t.getUint16(s+6,!0)]}function Dn(r,e=Ii){let t=Li(r);for(let i of t.images){let n=e.get(i.url);if(n.state==="failed")continue;if(n.state!=="ready")break;let s=Math.min(1,Cn/Math.max(n.width,n.height)),o=i.hotspot||n.curHotspot||[0,0],a=n.width*s,l=n.height*s,c=[Math.min(a,Math.max(0,o[0]*s)),Math.min(l,Math.max(0,o[1]*s))];return{kind:"image",key:i.url,entry:n,width:a,height:l,hotspot:c}}return Se(Ai(t.keyword))}function Se(r){if(r==="none")return{kind:"none"};let e=ye.includes(r)?r:"arrow";return{kind:"shape",name:e,key:`shape:${e}`}}function k(r,e,t,i,[n=0,s=0,o=0,a=0]=[]){let l=[],c=(d,f)=>{let h=l[l.length-1];(!h||Math.abs(h[0]-d)>1e-9||Math.abs(h[1]-f)>1e-9)&&l.push([d,f])};return c(r+n,e),c(t-s,e),c(t,e+s),c(t,i-o),c(t-o,i),c(r+a,i),c(r,i-a),c(r,e+n),l.length>1&&Math.abs(l[0][0]-l[l.length-1][0])<1e-9&&Math.abs(l[0][1]-l[l.length-1][1])<1e-9&&l.pop(),l}function Et(r,e,t,i,n,s=n/3.5){let o=t-r,a=i-e,l=Math.hypot(o,a),c=o/l,d=a/l,f=-d*(n/2),h=c*(n/2),u=t-c*s,m=i-d*s,p=1-2*s/n;return Me([[r+f,e+h],[u+f,m+h],[t+f*p,i+h*p],[t-f*p,i-h*p],[u-f,m-h],[r-f,e-h]])}function xn(r,e,t,i,n){let s=t-r,o=i-e,a=Math.hypot(s,o),l=-o/a*(n/2),c=s/a*(n/2);return Me([[r+l,e+c],[t+l,i+c],[t-l,i-c],[r-l,e-c]])}function Pn(r,e,t,i=20){return Me(Array.from({length:i},(n,s)=>[r+t*Math.cos(2*Math.PI*s/i),e+t*Math.sin(2*Math.PI*s/i)]))}function Bo(r,e,t,i,n=24){let s=[],o=(a,l)=>[r+a*Math.cos(l),e+a*Math.sin(l)];for(let a=0;a<n;a++){let l=[0,1,2,3].map(c=>2*Math.PI*(a+c)/n);s.push(Me([...l.map(c=>o(i,c)),...l.reverse().map(c=>o(t,c))]))}return s}function qo(){return{pointer:{hot:[6.8,0],parts:[k(5,0,8.6,14,[1.2,1.2,0,0]),k(7.6,5.4,10.9,14,[1.1,1.1,0,0]),k(9.9,6.4,13.2,14,[1.1,1.1,0,0]),k(12.2,7.6,15.2,14,[.9,.9,0,0]),k(4.2,10.8,15.2,19,[0,0,3,2.2]),Et(7.4,15,1,9,3.6)]},grab:{hot:[8.6,12.5],parts:[k(3,2.6,6.6,12.4,[1.2,1.2,0,0]),k(5.6,.6,9.2,12.4,[1.2,1.2,0,0]),k(8.2,1.4,11.8,12.4,[1.2,1.2,0,0]),k(10.8,3.6,14.2,12.4,[1.1,1.1,0,0]),k(3,9.4,14.2,18,[0,0,2.6,2.6]),Et(6.2,14.4,.4,7,3.6)]},grabbing:{hot:[8.6,13],parts:[k(3,5.6,6.6,12.4,[1.2,1.2,0,0]),k(5.6,5,9.2,12.4,[1.2,1.2,0,0]),k(8.2,5.2,11.8,12.4,[1.2,1.2,0,0]),k(10.8,6,14.2,12.4,[1.1,1.1,0,0]),k(3,9.4,14.2,18,[0,0,2.6,2.6]),Et(6,14.2,1.2,9,3.6)]},move:{hot:[9.5,9.5],parts:[k(3,7.8,16,11.2),k(7.8,3,11.2,16),V([9.5,0],[14,4.6],[5,4.6]),V([9.5,19],[5,14.4],[14,14.4]),V([0,9.5],[4.6,5],[4.6,14]),V([19,9.5],[14.4,14],[14.4,5])]},text:{hot:[9.5,9.5],parts:[k(8,.5,11,18.5),k(4.5,0,14.5,3),k(4.5,16,14.5,19)]},"vertical-text":{hot:[9.5,9.5],parts:Ve([k(8,.5,11,18.5),k(4.5,0,14.5,3),k(4.5,16,14.5,19)],90,9.5,9.5)},crosshair:{hot:[9.5,9.5],parts:[k(0,8,19,11),k(8,0,11,19)]},cell:{hot:[9.5,9.5],parts:[k(1.5,6.3,17.5,12.7),k(6.3,1.5,12.7,17.5)]},"not-allowed":{hot:[9.5,9.5],parts:[...Bo(9.5,9.5,5.4,8.8),xn(4.6,4.6,14.4,14.4,3.4)]},help:{hot:[0,0],parts:[...se(Be(),.8),Pn(13.6,12.4,5.4)],detail:[k(11.6,9,15.4,10.2),k(14.4,9,15.6,12.6),k(12.9,11.6,15.6,12.8),k(12.9,11.6,14.1,13.8),k(12.9,14.8,14.1,16)]},wait:{hot:[9.5,9.5],parts:Xo()},progress:{hot:[0,0],parts:[...se(Be(),.8),k(10.6,9,18.8,11.6),k(10.6,16.4,18.8,19),V([11.4,10.2],[18,10.2],[14.7,14.4]),V([14.7,13.6],[18,17.8],[11.4,17.8])]},copy:{hot:[0,0],parts:[...se(Be(),.8),k(9.6,9.8,18.8,19,[1.2,1.2,1.2,1.2])],detail:[k(13.6,11.8,14.8,17),k(11.6,13.8,16.8,15)]},alias:{hot:[0,0],parts:[...se(Be(),.8),k(9.6,9.8,18.8,19,[1.2,1.2,1.2,1.2])],detail:[xn(11.8,16.8,15.6,13,1.3),V([16.8,11.8],[16.8,15.4],[13.2,11.8])]},"context-menu":{hot:[0,0],parts:[...se(Be(),.8),k(9.2,8.6,18.8,19)],detail:[k(11,10.8,17,11.8),k(11,13.3,17,14.3),k(11,15.8,17,16.8)]},"ns-resize":{hot:[9.5,9.5],parts:Mt()},"ew-resize":{hot:[9.5,9.5],parts:Ve(Mt(),90,9.5,9.5)},"nesw-resize":{hot:[9.5,9.5],parts:se(Ve(Mt(),45,9.5,9.5),1.2,-1.9,-1.9)},"nwse-resize":{hot:[9.5,9.5],parts:se(Ve(Mt(),-45,9.5,9.5),1.2,-1.9,-1.9)},"col-resize":{hot:[9.5,9.5],parts:Sn()},"row-resize":{hot:[9.5,9.5],parts:Ve(Sn(),90,9.5,9.5)},"zoom-in":{hot:[7.5,7.5],parts:Mn(),detail:[k(4.4,6.9,10.6,8.1),k(6.9,4.4,8.1,10.6)]},"zoom-out":{hot:[7.5,7.5],parts:Mn(),detail:[k(4.4,6.9,10.6,8.1)]}}}function Fi(r){let e=ye.includes(r)?r:"arrow",t=En.get(e);if(t)return t;let i=c=>Object.freeze(c.map(d=>Object.freeze(d.map(f=>Object.freeze(f))))),n,s,o;if(e==="arrow")n=[ee],s=[Nn],o=[];else{let c=(Go||=qo())[e],d=f=>f.map(h=>h.map(([u,m])=>[(u-c.hot[0])/19,(m-c.hot[1])/19]));n=i(d(c.parts)),s=i(n.map(f=>Tt(1/19,f))),o=i(d(c.detail||[]))}let a=n.flat().map(c=>c[0]),l=n.flat().map(c=>c[1]);return t=Object.freeze({name:e,parts:Object.freeze(n),fill:Object.freeze(s),detail:Object.freeze(o),box:Object.freeze([Math.min(...a),Math.min(...l),Math.max(...a),Math.max(...l)])}),En.set(e,t),t}function Ee(r,e=1/19){let t=Fi(r);return Math.abs(e-1/19)<1e-12?{outline:t.parts,fill:t.fill,detail:t.detail}:{outline:t.parts,fill:t.parts.map(i=>Tt(e,i)),detail:t.detail}}function An(r,e,t=0){let i=Fi(r).box,n=(e>0&&Number.isFinite(e)?e:0)+(t>0&&Number.isFinite(t)?t:0);return[i[0]-n,i[1]-n,i[2]+n,i[3]+n]}function Ln(r,e,t,i,n,s=Hi,o=$i,a=Ee(r)){let l=0,c=0,d=0,f=0,h=0,u=i>0?qe:qe.slice(0,1),m=a.detail&&a.detail.length?a.detail:null;for(let[p,b,w]of u){let g=e+p*i,x=t+b*i,_=Pi(Di(a.outline,g,x),n),M=_>0?Pi(Di(a.fill,g,x),n):0;m&&M>0&&(M*=1-Pi(Di(m,g,x),n)),l+=w*(o[0]*_+(s[0]-o[0])*M),c+=w*(o[1]*_+(s[1]-o[1])*M),d+=w*(o[2]*_+(s[2]-o[2])*M),f+=w*_,h+=w}return f/=h,f>1e-5?[l/h/f,c/h/f,d/h/f,f]:[0,0,0,0]}function Ni(r,e,t,i,n,s,o=Hi,a=$i,l=Ee(r)){let c=i>0&&Number.isFinite(i)?i:1,d=1/c,[f,h,u,m]=An(r,n,d),p=Math.floor(e+f*c),b=Math.floor(t+h*c),w=Math.max(1,Math.ceil(e+u*c)-p),g=Math.max(1,Math.ceil(t+m*c)-b),x=new Uint8ClampedArray(w*g*4),_=s>=0&&s<=1?s:1;for(let M=0;M<g;M++){let E=(b+M+.5-t)/c;for(let C=0;C<w;C++){let P=Ln(r,(p+C+.5-e)/c,E,n,d,o,a,l);if(!(P[3]>0))continue;let D=(M*w+C)*4;x[D]=Math.round(P[0]*255),x[D+1]=Math.round(P[1]*255),x[D+2]=Math.round(P[2]*255),x[D+3]=Math.round(P[3]*_*255)}}return{x0:p,y0:b,width:w,height:g,data:x}}function ji(r,e,t,i,n,s=Ee(e),o="#fff",a="#000"){for(let[l,c]of[[s.outline,a],[s.fill,o],[s.detail||[],a]]){r.fillStyle=c;for(let d of l)r.beginPath(),d.forEach(([f,h],u)=>(u?r.lineTo:r.moveTo).call(r,t+f*n,i+h*n)),r.closePath(),r.fill()}}function zi(r,e,t,i,n){let s=i>0&&Number.isFinite(i)?Math.ceil(i)+1:0,o=e+2*s,a=t+2*s,l=new Uint8ClampedArray(o*a*4),c=n>=0&&n<=1?n:1,d=s?qe:qe.slice(0,1);for(let f=0;f<a;f++)for(let h=0;h<o;h++){let u=0,m=0,p=0,b=0,w=0;for(let[x,_,M]of d){w+=M;let E=Math.round(h-s+x*i),C=Math.round(f-s+_*i);if(E<0||C<0||E>=e||C>=t)continue;let P=(C*e+E)*4,D=r[P+3]/255*M;u+=r[P]*D,m+=r[P+1]*D,p+=r[P+2]*D,b+=D}if(!(b>1e-5))continue;let g=(f*o+h)*4;l[g]=u/b,l[g+1]=m/b,l[g+2]=p/b,l[g+3]=b/w*c*255}return{pad:s,width:o,height:a,data:l}}function kt(r=globalThis.document){if(!r||!r.createElement)return!1;let e="inline3d-cursor-style";if(r.getElementById&&r.getElementById(e))return!0;let t=r.createElement("style");return t.id=e,t.textContent=Rn,(r.head||r.documentElement)?.appendChild(t),!0}function Fn(r,e){let t=globalThis.getComputedStyle;if(!r||typeof t!="function")return null;let i=[];for(let n of e)n&&n.hasAttribute&&n.hasAttribute(B)&&(i.push([n,n.getAttribute(B)]),n.removeAttribute(B));try{let n=t(r).cursor;return typeof n=="string"?n:null}catch{return null}finally{for(let[n,s]of i)n.setAttribute(B,s??"")}}var B,Rn,Cn,kn,$o,St,Vo,Rt,Ii,Me,V,Ve,se,Be,Mt,Sn,Xo,Mn,Go,En,Di,Pi,In,Ct,Xe,Wi=le(()=>{"use strict";Ui();we();B="data-inline3d-cursor-hidden",Rn=`[${B}],[${B}] *{cursor:none!important}`,Cn=128,kn=Object.freeze({auto:"arrow",default:"arrow",none:"none",pointer:"pointer",grab:"grab","-webkit-grab":"grab",grabbing:"grabbing","-webkit-grabbing":"grabbing",move:"move","all-scroll":"move",text:"text","vertical-text":"vertical-text",crosshair:"crosshair","not-allowed":"not-allowed","no-drop":"not-allowed",help:"help",wait:"wait",progress:"progress",copy:"copy",alias:"alias","context-menu":"context-menu",cell:"cell","n-resize":"ns-resize","s-resize":"ns-resize","ns-resize":"ns-resize","e-resize":"ew-resize","w-resize":"ew-resize","ew-resize":"ew-resize","ne-resize":"nesw-resize","sw-resize":"nesw-resize","nesw-resize":"nesw-resize","nw-resize":"nwse-resize","se-resize":"nwse-resize","nwse-resize":"nwse-resize","col-resize":"col-resize","row-resize":"row-resize","zoom-in":"zoom-in","-webkit-zoom-in":"zoom-in","zoom-out":"zoom-out","-webkit-zoom-out":"zoom-out"}),$o=Object.freeze(Object.keys(kn));St=new Map;Vo=r=>/\.cur(?:[?#]|$)/i.test(r)||/^data:image\/(?:x-win-bitmap|x-icon|vnd\.microsoft\.icon)/i.test(r),Rt=class{constructor({ImageCtor:e=globalThis.Image,fetchFn:t=globalThis.fetch}={}){this._Image=e,this._fetch=t,this._m=new Map}get(e){let t=this._m.get(e);if(t)return t;if(t={url:e,state:"loading",image:null,width:0,height:0,curHotspot:null},this._m.set(e,t),typeof this._Image!="function")return t.state="failed",t;let i=new this._Image;i.crossOrigin="anonymous";let n=1,s=()=>{--n>0||t.state==="failed"||(t.state="ready")};return i.onload=()=>{let o=i.naturalWidth||i.width,a=i.naturalHeight||i.height;if(!(o>0&&a>0))return void(t.state="failed");t.image=i,t.width=o,t.height=a,s()},i.onerror=()=>{t.state="failed"},Vo(e)&&typeof this._fetch=="function"&&(n++,Promise.resolve().then(()=>this._fetch(e,e.startsWith("data:")?void 0:{mode:"cors"})).then(o=>o&&o.ok!==!1?o.arrayBuffer():null).then(o=>{t.curHotspot=o?On(o,t.width):null}).catch(()=>{}).finally(s)),i.src=e,t}},Ii=new Rt;Me=r=>{let e=0;for(let t=0;t<r.length;t++){let[i,n]=r[t],[s,o]=r[(t+1)%r.length];e+=i*o-s*n}return e>0?r:r.reverse()};V=(r,e,t)=>Me([r,e,t]),Ve=(r,e,t,i)=>{let n=e*Math.PI/180,s=Math.cos(n),o=Math.sin(n);return r.map(a=>Me(a.map(([l,c])=>[t+(l-t)*s-(c-i)*o,i+(l-t)*o+(c-i)*s])))},se=(r,e,t=0,i=0)=>r.map(n=>n.map(([s,o])=>[s*e+t,o*e+i])),Be=()=>[ee.map(([r,e])=>[r*19,e*19])],Mt=()=>[k(8,3,11,16),V([9.5,0],[14.2,5],[4.8,5]),V([9.5,19],[4.8,14],[14.2,14])],Sn=()=>[k(8,1,11,18),k(3.4,8,7.4,11),V([0,9.5],[4.4,5],[4.4,14]),k(11.6,8,15.6,11),V([19,9.5],[14.6,14],[14.6,5])],Xo=()=>[k(3,0,16,3),k(3,16,16,19),V([4.2,.5],[14.8,.5],[9.5,10]),V([9.5,9],[14.8,18.5],[4.2,18.5])],Mn=()=>[Pn(7.5,7.5,7),Et(11.6,11.6,18.4,18.4,3.8,1)];Go=null,En=new Map;Di=(r,e,t)=>{let i=1/0;for(let n of r)i=Math.min(i,jn(n,e,t));return i},Pi=(r,e)=>e>0?Math.min(1,Math.max(0,.5-r/e)):r<0?1:0;In=100;Ct=class{constructor(e,{throttleMs:t=In}={}){this.pointer=e,this.throttleMs=t,this.css=null,this.reads=0,this._el=null,this._stale=!0,this._urgent=!0,this._lastRead=-1/0;let i=n=>s=>{let o=typeof s.composedPath=="function"?s.composedPath():null,a=o&&o.length?o[0]:s.target;a&&a.nodeType===1&&(this._el=a),this._stale=!0,n&&(this._urgent=!0)};this._onMove=i(!1),this._onPress=i(!0),this._target=e.scope==="window"?globalThis:e.canvas,this._target&&this._target.addEventListener&&(this._target.addEventListener("pointermove",this._onMove),this._target.addEventListener("pointerdown",this._onPress),this._target.addEventListener("pointerup",this._onPress),this._target.addEventListener("pointercancel",this._onPress))}value(e=globalThis.performance?globalThis.performance.now():Date.now()){return this._stale&&(this._urgent||this.css===null||e-this._lastRead>=this.throttleMs)&&this.read(e),this.css??"auto"}shape(e){return Tn(this.value(e))}read(e=globalThis.performance?globalThis.performance.now():Date.now()){let t=globalThis.document,i=this.pointer.canvas,n=this._el;n&&n.isConnected===!1&&(n=null);let s=Fn(n||i,[i,t&&t.documentElement]);return this.reads++,this._lastRead=e,this._stale=!1,this._urgent=!1,s!==null&&(this.css=s),this.css??"auto"}dispose(){this._target&&this._target.removeEventListener&&(this._target.removeEventListener("pointermove",this._onMove),this._target.removeEventListener("pointerdown",this._onPress),this._target.removeEventListener("pointerup",this._onPress),this._target.removeEventListener("pointercancel",this._onPress))}},Xe=class{constructor(e,{shape:t="auto",shapeFor:i=null,images:n=Ii}={}){if(!ve.includes(t))throw new Error(`@displayxr/inline3d: cursor.shape "${t}" \u2014 expected ${ve.join(", ")}.`);this.option=t,this.shapeFor=typeof i=="function"?i:null,this.images=n,this.reader=t==="auto"?new Ct(e):null,this.sprite=Se(t==="auto"?"arrow":t)}get current(){return this.sprite.kind==="shape"?this.sprite.name:this.sprite.kind}pick(e,t){let i=this.reader?this.reader.value(t):null,n=i===null?null:Dn(i,this.images),s=n?n.kind==="shape"?n.name:n.kind:null,o;if(this.shapeFor)try{o=this.shapeFor({...e,css:s,cssValue:i})}catch(l){this._warned||(this._warned=!0,console.warn("[inline3d] cursor.shapeFor threw; using the page cursor.",l))}let a=l=>l==="none"||ye.includes(l);return a(o)?this.sprite=Se(o):a(this.option)?this.sprite=Se(this.option):this.sprite=n||Se("arrow"),this.sprite}dispose(){this.reader?.dispose()}}});function $n(r){return r>0&&Number.isFinite(r)?Math.min(.5,Xi/r):Yo}function Un(r,e){return r<=Ko?!(e>0&&Number.isFinite(e))||-r*e>=Jo:!1}function qi(r,e,t){if(!e||!Number.isFinite(t)||!(t<0))return 0;let i=Math.min(0,Number.isFinite(r.maxDisparity)?r.maxDisparity:0);return Math.min(i,Math.max(r.minDisparity,t-r.margin))}function Vn(r,e,t,i){if(!r.primed||i<r.last||i-r.last>e.stale)return r.primed=!0,r.disparity=t,r.last=i,t;if(i===r.last)return r.disparity;let n=i-r.last,s=t<r.disparity?e.riseTau:e.sinkTau,o=s>0?1-Math.exp(-n/s):1;return r.disparity+=o*(t-r.disparity),r.last=i,r.disparity}function zn(r){let e=r&&r.pointerType;return!e||e==="mouse"?!0:e==="pen"?!(r.buttons>0):!1}function Zo(r){return!!r&&"onpointerrawupdate"in r&&globalThis.isSecureContext!==!1}function Qo(r){let e=globalThis.document;if(!e||!e.documentElement)return;r&&kt(e),Vi=Math.max(0,Vi+(r?1:-1));let t=e.documentElement;Vi>0?t.setAttribute?.(B,""):t.removeAttribute?.(B)}function Wn(r){return!!r&&typeof r.setCursorDepth=="function"&&typeof r.getCursorDepthSupport=="function"}function ra(r,e,t,i){let n=.75*t,s=[[r,e]];for(let o=0;o<8;o++){let a=o*Math.PI/4;s.push([r+n*Math.cos(a)/i,e+n*Math.sin(a)])}return s}function Bn(r,e,t,i){return[[r,e],...ra(r+.3*t/i,e+.5*t,t,i)]}function Tt(r,e=ee){let t=0;for(let s=0;s<e.length;s++){let[o,a]=e[s],[l,c]=e[(s+1)%e.length];t+=o*c-l*a}let i=t>0?1:-1,n=e.map((s,o)=>{let a=e[(o+1)%e.length],l=a[0]-s[0],c=a[1]-s[1],d=Math.hypot(l,c)||1;return[-c/d*i,l/d*i]});return e.map((s,o)=>{let a=n[(o+e.length-1)%e.length],l=n[o],c=r/(1+a[0]*l[0]+a[1]*l[1]);return[s[0]+(a[0]+l[0])*c,s[1]+(a[1]+l[1])*c]})}function Xn(r,e,t,i=_e){let n={blurPx:0,alpha:1},s=i;if(!s)return n;if(s.blur&&Number.isFinite(e)&&s.blurK>0&&s.blurMaxPx>0){let o=s.blurMaxPx;if(s.blurMaxFrac>0&&Number.isFinite(t)&&t>0){let l=s.blurMaxFrac*t;o=l<o?l:o}let a=s.blurK*Math.abs(e);n.blurPx=a<o?a:o}if(s.alpha&&Number.isFinite(r)&&s.fullD>0){let o=Math.abs(r)/s.fullD;o=o<1?o:1;let a=o*o*(3-2*o),l=s.alphaMin<0?0:s.alphaMin>1?1:s.alphaMin;n.alpha=1-(1-l)*a}return n}function jn(r,e,t){let i=(e-r[0][0])**2+(t-r[0][1])**2,n=1;for(let s=0,o=r.length-1;s<r.length;o=s,s++){let a=r[s],l=r[o],c=l[0]-a[0],d=l[1]-a[1],f=e-a[0],h=t-a[1],u=Math.min(1,Math.max(0,(f*c+h*d)/(c*c+d*d))),m=f-c*u,p=h-d*u;i=Math.min(i,m*m+p*p);let b=t>=a[1],w=t<l[1],g=c*h>d*f;(b&&w&&g||!b&&!w&&!g)&&(n=-n)}return n*Math.sqrt(i)}var Yo,Xi,Ko,Jo,Pt,Ot,Vi,ea,ta,ia,Bi,Dt,Hn,ee,Tl,Nn,Hi,$i,qe,Ol,Dl,Pl,Ui=le(()=>{"use strict";we();we();Wi();Wi();Yo=.03,Xi=19;Ko=-.005,Jo=.5;Pt=Object.freeze({margin:.015,minDisparity:-.6,maxDisparity:0,riseTau:.03,sinkTau:.25,stale:.5});Ot=class{constructor(e,{scope:t="canvas",keepCss:i=!1}={}){if(t!=="canvas"&&t!=="window")throw new Error(`@displayxr/inline3d: cursor pointerScope "${t}" \u2014 expected 'canvas' or 'window'.`);this.canvas=e,this.scope=t,this.keepCss=!!i,this._uv=null,this.sampleTime=0,this.samples=0,this._hidden=!1,this._cx=0,this._cy=0,this._pending=!1,this._onMove=n=>this._sample(n),this._onLeave=()=>{this.uv=null},this._onDown=n=>{zn(n)||(this.uv=null)},this._target=t==="window"?globalThis:e,this.source=Zo(this._target)?"pointerrawupdate":"pointermove",this._target.addEventListener("pointermove",this._onMove),this.source==="pointerrawupdate"&&this._target.addEventListener("pointerrawupdate",this._onMove),this._target.addEventListener("pointerdown",this._onDown),t==="window"?(this._onOut=n=>{n.relatedTarget||(this.uv=null)},globalThis.addEventListener("pointerout",this._onOut),globalThis.addEventListener("blur",this._onLeave)):e.addEventListener("pointerleave",this._onLeave)}get uv(){if(this._pending){this._pending=!1;let e=this.canvas.getBoundingClientRect();if(!(e.width>0&&e.height>0))this._uv=null;else{let t=(this._cx-e.left)/e.width,i=(this._cy-e.top)/e.height;this._uv=t>=0&&t<=1&&i>=0&&i<=1?[t,i]:null}}return this._uv}set uv(e){this._pending=!1,this._uv=e}_sample(e){if(!zn(e)){this.uv=null;return}let t=typeof e.getCoalescedEvents=="function"?e.getCoalescedEvents():null,i=t&&t.length?t[t.length-1]:e,n=i.timeStamp>0?i.timeStamp:e.timeStamp>0?e.timeStamp:globalThis.performance?globalThis.performance.now():Date.now();n<this.sampleTime||(this.samples++,this.sampleTime=n,this._cx=i.clientX,this._cy=i.clientY,this._pending=!0)}set(e,t){this.uv=e==null?null:[e,t]}aspect(){let e=this.canvas.getBoundingClientRect();return e.height>0?e.width/e.height:1}cssHeight(){let e=this.canvas.getBoundingClientRect();return e.height>0?e.height:0}panelPx(){return this.cssHeight()*(globalThis.devicePixelRatio>0?globalThis.devicePixelRatio:1)}panelSize(){let e=this.canvas.getBoundingClientRect(),t=globalThis.devicePixelRatio>0?globalThis.devicePixelRatio:1;return e.width>0&&e.height>0?[e.width*t,e.height*t]:[0,0]}hideCss(e){this.keepCss&&(e=!1),e!==this._hidden&&(this.scope==="window"?Qo(e):this.canvas.setAttribute&&(e?(kt(),this.canvas.setAttribute(B,"")):this.canvas.removeAttribute(B)),this._hidden=e)}dispose(){this._target.removeEventListener("pointermove",this._onMove),this.source==="pointerrawupdate"&&this._target.removeEventListener("pointerrawupdate",this._onMove),this._target.removeEventListener("pointerdown",this._onDown),this.scope==="window"?(globalThis.removeEventListener("pointerout",this._onOut),globalThis.removeEventListener("blur",this._onLeave)):this.canvas.removeEventListener("pointerleave",this._onLeave),this.hideCss(!1)}};Vi=0;ea=2e3,ta=6,ia=1e4;Bi=new WeakMap,Dt=class{constructor(){this.target=null,this._sent=!1,this.last=null}get support(){let e=this.target;if(!Wn(e))return"none";let t=Bi.get(e);return t?t.state:"pending"}get drawing(){return this.support==="runtime"}bind(e){let t=e||null;if(t!==this.target&&(this.withdraw(),this.target=t),!Wn(t))return!1;let i=Bi.get(t);if(i||Bi.set(t,i={state:"pending",probes:0,inFlight:!1,at:0}),i.state==="runtime"||i.inFlight)return i.state==="runtime";let n=globalThis.performance?globalThis.performance.now():Date.now(),s=i.probes<ta?ea:ia;if(i.probes===0||n-i.at>=s){i.probes++,i.at=n,i.inFlight=!0;let o;try{o=Promise.resolve(t.getCursorDepthSupport())}catch(a){o=Promise.reject(a)}o.then(a=>{i.inFlight=!1,i.state=a==="runtime"?"runtime":"none"},()=>{i.inFlight=!1,i.state="none"})}return i.state==="runtime"}report(e,t,i){if(!this.drawing)return!1;let n={u:Hn(e),v:Hn(t)};i!=null&&Number.isFinite(i)&&(n.disparityPx=i);try{this.target.setCursorDepth(n)}catch{return!1}return this._sent=!0,this.last={u:n.u,v:n.v,disparityPx:n.disparityPx??null},!0}withdraw(){if(this.last=null,!!this._sent){this._sent=!1;try{this.target?.setCursorDepth()}catch{}}}dispose(){this.withdraw(),this.target=null}},Hn=r=>r>0?r<1?r:1:0;ee=Object.freeze([[0,0],[0,16],[4.2,12.4],[6.9,18.6],[9.5,17.5],[6.8,11.5],[11.7,11.5]].map(([r,e])=>Object.freeze([r/19,e/19]))),Tl=Object.freeze([[0,1,2],[0,2,5],[0,5,6],[2,3,4],[2,4,5]]);Nn=Object.freeze(Tt(1/19).map(r=>Object.freeze(r))),Hi=Object.freeze([1,1,1,1]),$i=Object.freeze([.02,.02,.03,1]);qe=Object.freeze([Object.freeze([0,0,1]),...[[.5,0],[-.5,0],[0,.5],[0,-.5]].map(([r,e])=>Object.freeze([r,e,.7066])),...Array.from({length:8},(r,e)=>{let t=.3927+.7854*e;return Object.freeze([Math.cos(t),Math.sin(t),.2494])})]),Ol=Object.freeze([Math.max(...ee.map(r=>r[0])),Math.max(...ee.map(r=>r[1]))]);Dl=Object.freeze({declarations:`#ifdef PICK_PASS
|
|
3
3
|
#include "pickPS"
|
|
4
4
|
#endif
|
|
5
5
|
`,output:`pcFragColor0 = getPickOutput();
|
|
@@ -13,10 +13,10 @@ pcFragColor1 = getPickDepth();
|
|
|
13
13
|
#ifdef DEPTH_PICK_PASS
|
|
14
14
|
output.color1 = getPickDepth();
|
|
15
15
|
#endif
|
|
16
|
-
`})});var Ki={};Ps(Ki,{PAIR_CURSOR_ARROW:()=>sa,PAIR_CURSOR_CSS_PX:()=>na,PAIR_CURSOR_CSS_PX_M:()=>Kn,PAIR_CURSOR_HEIGHT:()=>Yn,PAIR_SUPPORT_COPY_PX:()=>Zn,PairCursor:()=>Yi,consistentMatch:()=>Gi,drawPairArrow:()=>rs,drawPairArrowSoft:()=>ss,drawPairImage:()=>os,pairCursorScale:()=>es,pairCursorTarget:()=>aa,pairFootprintDisparity:()=>Jn,pairNearestSupported:()=>Qn,pairPxPerBaseline:()=>ts});function Jn(r,e,t,i,n,s){if(!r||!r.img||!e||!e.rL||!e.rR||!(e.outW>0))return null;let{img:o,w:a,h:l,scale:c}=r,u=a/2,f=Math.max(8,Math.round(u/20)),h=Math.round(u*.3),d=-Math.round(u*.05),{rL:p,rR:g}=e,w=e.outW/p.sw,m=oa(r),_=[],S=new Set,x=(T,v)=>{let b=Math.round((p.sy+v*p.sh)*c-f/2);if(b<0||b+f>l)return;let y=Math.round((p.sx+T*p.sw)*c-f/2),E=Math.round((g.sx+T*g.sw)*c-f/2);if(!S.has(`L${y},${b}`)){S.add(`L${y},${b}`);let I=Gi(o,m,a,l,y,b,f,d,h);I!==null&&_.push({d:I,x:y,y:b,eye:0})}if(!S.has(`R${E},${b}`)){S.add(`R${E},${b}`);let I=Gi(m,o,a,l,E,b,f,-h,-d);I!==null&&_.push({d:-I,x:E,y:b,eye:1})}},C=0,M=0,k=0;for(let[T,v]of Bn(t,i,n,s))T>=0&&T<=1&&v>=0&&v<=1&&(x(e.mirror?1-T:T,v),C+=T,M+=v,k++);if(!k)return null;let P=f/2/c/p.sw,D=f/2/c/p.sh;for(let[T,v]of[[-P,0],[P,0],[0,-D],[0,D]]){let b=C/k+T,y=M/k+v;b>=0&&b<=1&&y>=0&&y<=1&&x(e.mirror?1-b:b,y)}for(let T of _)T.d=(T.d/c-(p.sx-g.sx))*w;return Qn(_,Zn/c*w,f/2)}function oa(r){let e=Gn.get(r);if(e)return e;let{img:t,w:i,h:n}=r,s=i/2;e=new Uint8Array(i*n);for(let o=0;o<n;o++){let a=o*i;for(let l=0;l<s;l++)e[a+l]=t[a+s+l],e[a+s+l]=t[a+l]}return Gn.set(r,e),e}function Gi(r,e,t,i,n,s,o,a,l){let c=t/2;if(n<0||n+o>c)return null;let u=ge(r,t,i,n,s,o,o,{dMin:a,dMax:l,dyMax:2});if(!u||u.c<.8)return null;let f=Math.round(n-u.d),h=s+u.dy;if(f<0||f+o>c||h<0||h+o>i)return null;let d=ge(e,t,i,f,h,o,o,{dMin:-Math.ceil(u.d)-2,dMax:-Math.floor(u.d)+2,dyMax:1});return!d||d.c<.8||Math.abs(-d.d-u.d)>1?null:u.d}function Qn(r,e,t=0){let i=r.map(o=>typeof o=="number"?{d:o,x:0,y:0,eye:-1}:o);if(i.length<2)return null;let n=[...i].sort((o,a)=>a.d-o.d),s=(o,a)=>o.eye===-1||o.eye!==a.eye||Math.abs(o.x-a.x)+Math.abs(o.y-a.y)>=t;for(let o of n)for(let a of n)if(a!==o&&Math.abs(o.d-a.d)<=e&&s(o,a))return o.d;return null}function es(r,e,t){let i=t>0&&Number.isFinite(t)?t:Kn;return e>0?r/e/i:r/(1e3*i)}function ts(r,e,t,i=Ke.eyeSeparationM){return es(r,e,t)*i}function aa(r,e,t=Dt){return r===null||!Number.isFinite(r)||!(e>0)?0:-qi(t,!0,-r/e)*e||0}function is(r,e){let t=e>0?Math.max(.05263157894736842,1/e):.05263157894736842,i=`${r}:${Math.round(t*1e4)}`,n=Pt.get(i);return n||(Pt.size>64&&Pt.clear(),Pt.set(i,n=Ee(r,t))),n}function rs(r,e,t,i,n,s,o,a="arrow"){let l=n*t,c=is(a,o);for(let u of[0,1]){let f=u*e+i*e+(u===0?s/2:-s/2);r.save(),r.beginPath(),r.rect(u*e,0,e,t),r.clip(),ji(r,a,f,l,o,c),r.restore()}}function ns(r,e){if(!X||typeof OffscreenCanvas=="function"&&!(X instanceof OffscreenCanvas))try{typeof OffscreenCanvas=="function"?X=new OffscreenCanvas(1,1):globalThis.document&&document.createElement&&(X=document.createElement("canvas"))}catch{X=null}return!X||typeof X.getContext!="function"?null:(X.width<r&&(X.width=r),X.height<e&&(X.height=e),X.getContext("2d"))}function ss(r,e,t,i,n,s,o,a,l,c="arrow"){let u=n*t,f=is(c,o),h=[0,1].map(p=>{let g=p*e+i*e+(p===0?s/2:-s/2);return Ni(c,g,u,o,a,l,[1,1,1,1],[0,0,0,1],f)}),d=ns(Math.max(h[0].width,h[1].width),Math.max(h[0].height,h[1].height));if(!d||typeof d.putImageData!="function"||typeof ImageData!="function")return!1;for(let p of[0,1]){let g=h[p];d.putImageData(new ImageData(g.data,g.width,g.height),0,0),r.save(),r.beginPath(),r.rect(p*e,0,e,t),r.clip(),r.drawImage(d.canvas,0,0,g.width,g.height,g.x0,g.y0,g.width,g.height),r.restore()}return!0}function os(r,e,t,i,n,s,o,a,l,c){let u=o/19,f=Math.max(1,Math.round(a.width*u)),h=Math.max(1,Math.round(a.height*u)),d=ns(f+2*(Math.ceil(l)+2),h+2*(Math.ceil(l)+2));if(!d||typeof d.getImageData!="function"||typeof ImageData!="function")return!1;d.clearRect(0,0,d.canvas.width,d.canvas.height),d.drawImage(a.entry.image,0,0,f,h);let p=zi(d.getImageData(0,0,f,h).data,f,h,l,c);d.clearRect(0,0,d.canvas.width,d.canvas.height),d.putImageData(new ImageData(p.data,p.width,p.height),0,0);let g=n*t-a.hotspot[1]*u-p.pad;for(let w of[0,1]){let m=w*e+i*e+(w===0?s/2:-s/2)-a.hotspot[0]*u-p.pad;r.save(),r.beginPath(),r.rect(w*e,0,e,t),r.clip(),r.drawImage(d.canvas,0,0,p.width,p.height,Math.round(m),Math.round(g),p.width,p.height),r.restore()}return!0}var na,Yn,sa,Kn,Zn,Gn,Pt,X,Yi,Ji=le(()=>{"use strict";Ui();Vt();Ei();na=Xi,Yn=.06,sa=ee,Kn=.0254/96;Zn=1.5,Gn=new WeakMap;Pt=new Map;X=null;Yi=class{constructor(e,{height:t,pointerScope:i="window",soften:n,shape:s="auto",shapeFor:o=null}={}){this.pointer=new Tt(e,{scope:i}),this.shapes=new Xe(this.pointer,{shape:s,shapeFor:o}),this.soften=_t(n,"@displayxr/inline3d pair cursor"),this.height=t>0?t:null,this.filter={},this._luma=null,this._uv=null,this._content=null,this._metricsFor=null,this.metersPerCssPx=null,this.eyeSeparationM=Ke.eyeSeparationM,this.last=null,this.runtime=new Ot}get hovering(){return!!this.pointer.uv}draw(e,t,i,n){let s=this.runtime.bind(i&&i.handle),o=this.pointer.uv;if(!o)return this.idle();let[a,l]=o,c=this.height??this._osArrowFraction();(t!==this._luma||!this._uv||this._uv[0]!==a||this._uv[1]!==l)&&(this._content=Jn(t,i,a,l,c,i.outW/i.outH),this._luma=t,this._uv=o);let u=this.pointer.canvas.getBoundingClientRect?.();if(s)return this._drawRuntime(a,l,u,i);this._askMetrics(i.handle);let f=ts(i.outW,u&&u.width,this.metersPerCssPx,this.eyeSeparationM),h=this._content===null?null:-this._content/f,d=qi(Dt,h!==null,h),p=Vn(this.filter,Dt,d,n),g=Un(p,f),w=-p*f,m=null,_=null;if(g){let S=c*i.outH,x=globalThis.devicePixelRatio>0?globalThis.devicePixelRatio:1,C=u&&u.width>0?u.width*x/i.outW:1,M=u&&u.height>0?c*u.height*x:S,k=Xn(p,w*C,M,this.soften),P=this.shapes.pick({u:a,v:l,point:null},n*1e3);_=this.shapes.current,m={blurPx:k.blurPx,alpha:k.alpha,ghostPx:Math.abs(w*C),spritePx:M,radius:M>0?k.blurPx/M:0,soft:k.blurPx>0||k.alpha<1},P.kind==="image"?os(e,i.outW,i.outH,a,l,w,S,P,m.soft?m.radius*S:0,m.soft?k.alpha:1):P.kind==="shape"&&(!m.soft||!ss(e,i.outW,i.outH,a,l,w,S,m.radius,k.alpha,_))&&rs(e,i.outW,i.outH,a,l,w,S,_)}return this.pointer.hideCss(g),this.last={contentPx:this._content,targetPx:-d*f||0,disparityPx:g?w:0,filteredPx:w||0,drawn:g,pxPerBaseline:f,soften:m,shape:_},this.last}_drawRuntime(e,t,i,n){this.pointer.hideCss(!1),this.filter={};let s=globalThis.devicePixelRatio>0?globalThis.devicePixelRatio:1,o=i&&i.width>0&&n.outW>0?i.width*s/n.outW:null,a=this._content===null||o===null?null:-this._content*o;return this.runtime.report(e,t,a),this.last={contentPx:this._content,targetPx:0,disparityPx:0,filteredPx:0,drawn:!1,runtime:!0,runtimeDisparityPx:a,pxPerBaseline:null,soften:null,shape:null},this.last}_askMetrics(e){!e||e===this._metricsFor||typeof e.displayMetrics!="function"||(this._metricsFor=e,Promise.resolve().then(()=>e.displayMetrics()).then(t=>{this._metricsFor!==e||!t||(t.metersPerCssPx>0&&(this.metersPerCssPx=t.metersPerCssPx),t.eyeSeparationM>0&&(this.eyeSeparationM=t.eyeSeparationM))}).catch(()=>{}))}_osArrowFraction(){let e=this.pointer.canvas.getBoundingClientRect?.();return e&&e.height>0?$n(e.height):Yn}idle(){return this.runtime.withdraw(),this.pointer.hideCss(!1),this.filter={},this._uv=null,this.last=null,null}dispose(){this.runtime.dispose(),this.pointer.dispose(),this.shapes.dispose()}}});var De=Object.freeze({speaker:"high",other:"normal",hidden:"paused"}),As=["high","normal","low","paused"],Ls=.02,Is=1e3/20,Fs=3e3,Ns=1e3/28;function Ae(r){return typeof r=="function"?r:r===!1||r==="off"?"off":"auto"}function zt(r=import.meta.url){return Oe?typeof Oe=="function"?Oe():Oe:new URL("../lift/index.js",r).href}var Oe=null;function gr(r){Oe=r||null}function js(){return import(zt())}async function Wt(r,{importer:e=js,nav:t=globalThis.navigator,log:i=null,capsOpts:n={webFallback:!0}}={}){let s=(h,d)=>i&&i(h,d),o=(h,d={})=>(s("lift-unavailable",{reason:h,...d}),{lift:null,capabilities:null,caps:null,source:"none",reason:h}),a=Ae(r);if(a==="off")return{lift:null,capabilities:null,caps:null,source:"none",reason:"off"};if(typeof a=="function"){let h=typeof a.liftCapabilities=="function"?a.liftCapabilities:null;return{lift:a,capabilities:h,caps:null,source:"injected",reason:null}}let l;try{l=await e()}catch(h){return o("import-failed",{message:String(h&&h.message||h).slice(0,200)})}let c=l&&typeof l.lift=="function"?l.lift:null;if(!c)return o("no-lift-export");let u=typeof l.liftCapabilities=="function"?l.liftCapabilities:null,f=null;if(u){try{f=await u(n)}catch{f=null}let h=!!(f&&f.webFallback&&f.webFallback.webgpu);if(f&&!f.native&&!h)return o("no-provider",{native:!1,webgpu:!1})}else if(!(t&&t.gpu))return o("no-webgpu");return s("lift-ready",{native:!!(f&&f.native),provider:f&&f.provider||null}),{lift:c,capabilities:u,caps:f,source:"module",reason:null}}function Pe(r){let e=Number.isFinite(+r)&&r!==null?Math.max(-1,Math.min(1,+r)):0;return Math.abs(e)<Ls?"auto":Math.round((.5+.5*e)*1e3)/1e3}function Ye({id:r,speakerId:e,visible:t=!0}){return t?r!=null&&r===e?De.speaker:De.other:De.hidden}function Ht(r,e){if(!r||!As.includes(e)||typeof r.setPriority!="function")return!1;try{return r.setPriority(e)!==!1}catch{return!1}}function $t({degradedMs:r=Is,recoveredMs:e=Ns,holdMs:t=Fs,alpha:i=.1}={}){let n=null,s=0,o=!1;return{feed(a){if(!(a>0)||a>1e3)return null;if(n=n===null?a:n+i*(a-n),o){if(n<e)return o=!1,s=0,"recovered"}else if(s=n>r?s+a:0,s>=t)return o=!0,"degraded";return null},reset(){n=null,s=0,o=!1},get frameMs(){return n},get degraded(){return o}}}function Ut({lift:r,max:e=4,log:t=null,options:i=null}={}){let n=i&&typeof i=="object"?i:{},s=new Map,o=null,a=0,l=0,c=(h,d)=>t&&t(h,d),u=(h,d)=>{if(!d.handle)return;let p=Ye({id:h,speakerId:o,visible:d.visible});if(p===d.priority)return;d.priority=p;let g=Ht(d.handle,p);c("lift-priority",{peer:h,priority:p,applied:g})},f={get size(){return s.size},get max(){return e},set max(h){e=Math.max(0,h|0)},has:h=>s.has(h),handle:h=>s.get(h)&&s.get(h).handle||null,priority:h=>s.get(h)&&s.get(h).priority||null,canAcquire:h=>s.has(h)||s.size<e,acquire(h,d,{wall:p,visible:g=!0,onError:w}={}){let m=s.get(h);if(m)return m.pending||Promise.resolve(m.handle);if(s.size>=e)return Promise.resolve(null);let _=++l,S=Ye({id:h,speakerId:o,visible:g}),x={gen:_,handle:null,visible:g,priority:S,pending:null};s.set(h,x);let C={quality:"auto",...n,mode:"live",wall:p,ui:"none",convergence:Pe(a),priority:S};return c("lift-acquire",{peer:h,priority:S,convergence:C.convergence}),x.pending=Promise.resolve().then(()=>r(d,C)).then(M=>{if(s.get(h)!==x||x.gen!==_){try{M&&M.remove&&M.remove()}catch{}return null}return x.pending=null,x.handle=M||null,x.priority=null,u(h,x),M&&typeof M.setConvergence=="function"&&M.setConvergence(Pe(a)),x.handle},M=>(s.get(h)===x&&s.delete(h),c("lift-failed",{peer:h,message:String(M&&M.message||M).slice(0,200)}),w&&w(M),null)),x.pending},release(h){let d=s.get(h);if(d){if(s.delete(h),d.handle)try{d.handle.remove()}catch{}c("lift-release",{peer:h})}},releaseAll(){for(let h of[...s.keys()])f.release(h)},setSpeaker(h){o=h===void 0?null:h;for(let[d,p]of s)u(d,p)},setVisible(h,d){let p=s.get(h);!p||p.visible===!!d||(p.visible=!!d,u(h,p))},setDepth(h){a=h;let d=Pe(h);for(let p of s.values())p.handle&&typeof p.handle.setConvergence=="function"&&p.handle.setConvergence(d);return d},get anyWeb(){for(let h of s.values())if(h.handle&&!h.handle.native)return!0;return!1},list(){return[...s].map(([h,d])=>({id:h,priority:d.priority,pending:!!d.pending,native:!!(d.handle&&d.handle.native)}))}};return f}var Ws=null;function _r(r){Ws=typeof r=="function"?r:null}var Hs=new WeakMap;function vr(r,e){r&&(typeof r=="object"||typeof r=="function")&&Hs.set(r,e)}Vt();var Ua=Object.freeze(["shibata","percival"]);var $s="[inline3d] camera rig with convergenceDiopters 0: convergence at infinity puts the whole scene in front of the glass; set convergence to the subject's distance.",Us=new WeakSet;function Vs(r){let e=[];return!r||typeof r!="object"||(r.type==="camera"?(r.convergenceDiopters>0||e.push(["convergence",$s]),r.verticalFov>Math.PI&&e.push(["fov",`[inline3d] camera rig verticalFov ${r.verticalFov} is more than \u03C0: it looks like DEGREES \u2014 the descriptor takes RADIANS (cameraRigFromCamera / cameraRigFromPose convert three's degrees for you).`])):(r.ipdFactor>1||r.parallaxFactor>1)&&e.push(["factor",`[inline3d] display rig ipdFactor ${r.ipdFactor??1} / parallaxFactor ${r.parallaxFactor??1}: above 1 exaggerates depth past what the display shows by construction (1 = correct; below 1 = a comfort dial). Sent as given.`])),e}function Bt(r,e){if(!(!e||typeof e!="object")&&!(e.type==="camera"?e.convergenceDiopters>0&&!(e.verticalFov>Math.PI):!(e.ipdFactor>1||e.parallaxFactor>1)))for(let[t,i]of Vs(e))r.has(t)||(r.add(t),!(t==="convergence"&&Us.has(e))&&console.warn(i))}function wr(r){let e=String(r||"");return e.startsWith("cross-pass")?"the canvas is inside its own render surface: a CSS effect on it or an ancestor (filter, opacity < 1, mask, clip-path, mix-blend-mode, backdrop-filter). Remove it (woven-canvas rule 7)":e==="no-quad"?"the canvas drew nothing the compositor can see: it is not drawing, is occluded, or a CSS effect on it or an ancestor (filter, opacity < 1, mask, clip-path, mix-blend-mode, backdrop-filter) hides it (woven-canvas rule 7)":e==="no-identity"?"the canvas reached the browser without its identity: register it once, keep it mounted, cover it until firstWoven (woven-canvas rules 3-5)":e==="no-join"?"nothing joined this rect; harmless off screen, otherwise check the canvas is drawing and on screen":e==="resolve-dropped"?"the browser could not resolve the canvas's GPU resource (a browser-side issue)":"see docs/woven-canvas-rules.md \xA73"}var br=new WeakMap,Q;function xr(r){let e=null;for(let[t,i]of r)i>0&&(!e||i<e[1])&&(e=[t,i]);return e}function Bs(r){if(!r||typeof r.getParameter!="function")return null;let e=br.get(r);if(e)return e;let t,i,n;try{t=r.getParameter(r.MAX_TEXTURE_SIZE??3379),i=r.getParameter(r.MAX_RENDERBUFFER_SIZE??34024),n=r.getParameter(r.MAX_VIEWPORT_DIMS??3386)}catch{return null}let s=n&&n.length>=2?n[0]:0,o=n&&n.length>=2?n[1]:0,a=xr([["MAX_TEXTURE_SIZE",t],["MAX_RENDERBUFFER_SIZE",i],["MAX_VIEWPORT_DIMS",s]]),l=xr([["MAX_TEXTURE_SIZE",t],["MAX_RENDERBUFFER_SIZE",i],["MAX_VIEWPORT_DIMS",o]]);if(!a||!l)return null;let c={maxW:a[1],maxH:l[1],nameW:a[0],nameH:l[0],valueW:a[1],valueH:l[1]};return br.set(r,c),c}function Sr(){if(Q!==void 0)return Q;Q=null;try{if(typeof document>"u"||!document||typeof document.createElement!="function")return Q;let r=document.createElement("canvas"),e=r.getContext("webgl2")||r.getContext("webgl");if(!e)return Q;Q=Bs(e),e.getExtension?.("WEBGL_lose_context")?.loseContext?.()}catch{Q=null}return Q}function Mr(r,e,t,{cols:i=2,rows:n=1}={}){let s=r*i,o=e*n,a={eyeW:r,eyeH:e,cols:i,scale:1,clamped:!1,reqW:s,reqH:o,bufW:s,bufH:o,limitName:"",limitValue:0};if(!t||!(r>0)||!(e>0))return a;let l=t.maxW/s,c=t.maxH/o,u=Math.min(l,c);if(!(u<1))return a;let f=l<=c,h=Math.max(1,Math.min(Math.floor(r*u+1e-9),Math.floor(t.maxW/i))),d=Math.max(1,Math.min(Math.floor(e*u+1e-9),Math.floor(t.maxH/n)));return{eyeW:h,eyeH:d,cols:i,scale:u,clamped:!0,reqW:s,reqH:o,bufW:h*i,bufH:d*n,limitName:f?t.nameW:t.nameH,limitValue:f?t.valueW:t.valueH}}function Xt(r){return Math.round(r*1e3)/1e3}function Er(r,e,t){let i=typeof t=="number"?` (renderScale ${Xt(t)} \u2192 ${Xt(t*e.scale)})`:` (scale ${Xt(e.scale)})`;return`${r} ${e.cols===1?"buffer":"SBS buffer"} ${e.reqW}\xD7${e.reqH} exceeds ${e.limitName} ${e.limitValue} on this device; rendering at ${e.bufW}\xD7${e.bufH}${i}.`}function Rr(r,e){let t=r?.width||0,i=r?.height||0,n=e&&e.drawingBufferWidth>0?e.drawingBufferWidth:t,s=e&&e.drawingBufferHeight>0?e.drawingBufferHeight:i,o=t>0?n/t:1,a=i>0?s/i:1;return{sx:o,sy:a,w:n,h:s,mismatch:o!==1||a!==1}}function Cr(r,e,t,i="laying the eyes out from the drawing buffer. Lower renderScale to stay inside the device limit."){return`${r} the browser clamped this canvas's drawing buffer to ${t.w}\xD7${t.h} (canvas.width/height say ${e.width}\xD7${e.height}); ${i}`}var he="smoothstep",Gt=["linear","smoothstep","easeoutcubic"];function Yt(r){if(typeof r!="string")return null;let e=r.toLowerCase().replace(/[-_\s]/g,"");return Gt.includes(e)?e:null}function Xs(r,e){if(e<=0)return 0;if(e>=1)return 1;if(r==="linear")return e;if(r==="easeoutcubic"){let t=1-e;return 1-t*t*t}return e*e*(3-2*e)}var ce="idle",kr="rampDownThenFire",qt="fireThenRampUp",Je=class{constructor(e,t){this._phase=ce,this._targetMode=null,this._firePending=!1,this._fireAtEnd=!1,this._from=0,this._to=0,this._cur=0,this._t=1,this._dur=180/1e3,this._easing=he,(e!==void 0||t!==void 0)&&this.configure(e,t)}configure(e,t){if(e!==void 0){let i=Number(e);this._dur=Number.isFinite(i)&&i>0?i:0}return t!==void 0&&(this._easing=Yt(t)||he),this}get durationS(){return this._dur}get easing(){return this._easing}request({targetMode:e=null,targetViewCount:t,currentMode:i=null,currentViewCount:n,current:s,steady:o=1}={}){let a=!(t>1),l=!(n>1),c=Number.isFinite(o)?o:1,u=Number.isFinite(s)?s:c;return this._targetMode=e,this._from=u,a&&!l?(this._phase=kr,this._to=0,this._fireAtEnd=!0,this._firePending=!1):!a&&l?(this._phase=qt,this._from=0,this._to=c,this._firePending=!0,this._fireAtEnd=!1):(this._phase=qt,this._to=a?u:c,this._firePending=!(e!==null&&e===i),this._fireAtEnd=!1),this._t=this._dur>0?0:1,this._cur=this._from,this}update(e){let t=!1;if(this._phase!==ce){let i=Number.isFinite(e)&&e>0?e:0;this._t<1&&this._dur>0?(this._t+=i/this._dur,this._t>1&&(this._t=1)):this._t=1,this._cur=this._from+(this._to-this._from)*Xs(this._easing,this._t),this._phase===qt?(this._firePending&&(this._firePending=!1,t=!0),this._t>=1&&(this._phase=ce)):this._t>=1&&(this._fireAtEnd&&(this._fireAtEnd=!1,t=!0),this._phase=ce)}return{factor:this._cur,fire:t,mode:this._targetMode}}active(){return this._phase!==ce}value(){return this._cur}firePending(){return this._phase===kr?this._fireAtEnd:this._firePending}cancel(){return this._phase=ce,this._firePending=!1,this._fireAtEnd=!1,this._t=1,this}};var Y=null;_r(r=>{let e=Y;if(!e||!e._running||!r)return null;let t=i=>({layer:i.layer,session:e.session});for(let i of e._windows.values())if(i.canvas===r&&i.layer)return t(i);for(let i of e._windows.values())if(i.layer&&typeof r.contains=="function"&&r.contains(i.canvas))return t(i);for(let i of e._windows.values()){let n=i.canvas.parentElement;if(i.layer&&n&&typeof n.contains=="function"&&n.contains(r))return t(i)}return null});var qs=()=>typeof navigator<"u"&&!!navigator.xr,ne=()=>typeof window<"u"&&typeof window.XRDisplayLayer=="function",Ze=()=>ne()&&"excludeElement"in window.XRDisplayLayer.prototype,Kt=()=>{if(!ne())return!1;try{return"setViewRig"in window.XRDisplayLayer.prototype}catch{return!1}},Gs=["getDisplayInfo","getRenderingModes","requestRenderingMode"],zr=["renderingmodechange","hardwaredisplaystatechange"],si="trackingstatechange",Wr=["unknown","tracking","searching"],Or=[...zr,si];function Qe(r){try{let e=r?r.trackingState:void 0;return Wr.includes(e)?e:null}catch{return null}}var Jt=()=>{if(!ne())return!1;try{let r=window.XRDisplayLayer.prototype;return Gs.every(e=>typeof r[e]=="function")}catch{return!1}},Zt=()=>{if(!ne())return!1;try{return typeof window.XRDisplayLayer.prototype.undock=="function"}catch{return!1}},de=null;function ue(){if(de!==null)return de;if(!ne())return!1;try{let r=window.XRDisplayLayer.occlusionByDrawOrder;if(typeof r=="boolean")return de=r}catch{}return!1}function Ys(r){if(de!==null)return de;if(!r||!ne()||!("occlusionByDrawOrder"in window.XRDisplayLayer.prototype))return null;try{return de=!!r.occlusionByDrawOrder}catch{return null}}var Dr=!1;function Qt(){Dr||(Dr=!0,console.info("[inline3d] This browser composites 2D over woven 3D automatically, per-pixel by draw order \u2014 overlay exclusion is obsolete here, so exclude()/addGlobalOverlay()/data-inline3d-overlay/autoChrome are accepted and ignored. Your 2D chrome already occludes the tiles correctly. The calls are harmless (keep them if you also ship to older DisplayXR Browsers); gate on inline3dOcclusionByDrawOrder() to drop them."))}function Hr(){return qs()&&ne()}function ei(r){return{type:"display",position:{x:0,y:0,z:0},orientation:{x:0,y:0,z:0,w:1},virtualDisplayHeight:r.virtualDisplayHeight>0?r.virtualDisplayHeight:.24,ipdFactor:1,parallaxFactor:1,perspectiveFactor:1}}function Ks(r,e){let t=Number.isFinite(r.ipdFactor)?r.ipdFactor:1,i=Number.isFinite(r.parallaxFactor)?r.parallaxFactor:1;return{...r,ipdFactor:t*e,parallaxFactor:i*e}}var Js=16;function W(){return typeof performance<"u"&&performance&&typeof performance.now=="function"?performance.now():Date.now()}var oi=1200,Zs=new Set(["pending","woven","withheld"]),Pr=3,Qs=new Set(["getDisplayInfo","getRenderingModes","requestRenderingMode"]),eo=new Set(["getDisplayInfo","getRenderingModes"]);function to(r){return r==null||Array.isArray(r)&&r.length===0}function ti(){try{let r=typeof XRDisplayLayer=="function"?XRDisplayLayer:null;return!!(r&&r.prototype&&"wovenState"in r.prototype)}catch{return!1}}function et(r){try{let e=r?r.wovenState:null;return Zs.has(e)?e:null}catch{return null}}function ii(r){try{let e=r?r.withheldReason:null;return typeof e=="string"&&e?e:null}catch{return null}}var Ar=!1;function io(r){if(r==null)return he;let e=Yt(r);return e||(Ar||(Ar=!0,console.warn(`[inline3d] createInline3D({ modeSwitch: { easing: ${JSON.stringify(r)} } }) is not a curve this SDK knows (${Gt.join(" / ")}); using '${he}'.`)),he)}var Lr=!1;function ro(){Lr||(Lr=!0,console.info("[inline3d] The active rendering mode is 1-view, so this SDK has zeroed every window rig (ipdFactor/parallaxFactor -> 0) \u2014 both eyes now render from one place. The runtime keeps weaving the same two-view atlas whatever the page submits, so leaving stereo in it would put two slightly different images on a flat panel, i.e. a blurry double image instead of 2D. Your rendering is unchanged; the flattening is a copy applied on the way to the layer and it is undone the moment a 2-view mode goes active again."))}function ai(r){return r&&r.detail!==void 0&&r.detail!==null?r.detail:void 0}function $r(r){let e=ai(r);return e!==void 0?[e,r]:[r]}function no(r){for(let e of $r(r)){if(typeof e=="number"&&Number.isFinite(e))return e;if(e&&typeof e=="object"){let t=e.modeIndex!==void 0?e.modeIndex:e.mode;if(typeof t=="number"&&Number.isFinite(t))return t}}return-1}function so(r){for(let e of $r(r)){if(e==="2d"||e==="3d")return e;if(e&&typeof e=="object"){let t=e.state!==void 0?e.state:e.hardwareDisplayState;if(t==="2d"||t==="3d")return t}}return null}var Ir=!1;function oo(){Ir||(Ir=!0,console.warn("[inline3d] This browser has no XRDisplayLayer.setViewRig, so the view rig was ignored (the window still weaves \u2014 the runtime keeps the default display rig, scaled by virtualDisplayHeight). Gate on inline3dViewRigSupported() if your page's framing depends on the rig; further calls are silent."))}var Fr=!1;function ao(){Fr||(Fr=!0,console.warn("[inline3d] addScene got BOTH viewRig and virtualDisplayHeight; on a browser with rig support the rig wins and the height is dropped. They describe the same slot \u2014 virtualDisplayHeight is shorthand for exactly one rig (display, identity pose, all factors 1) \u2014 so there is no merge. This is only worth passing as a PAIR deliberately: the height is what a browser without setViewRig will use, so a camera-rig scene can name its own fallback framing. Otherwise say it once, inside the rig."))}async function Ur(r={}){let{referenceSpace:e="viewer",lazy:t=!0,rootMargin:i="50% 0px",autoChrome:n=!0,modeSwitch:s=null,untrackedFallback:o="none",viewerEase:a}=r;if(!Hr())return{supported:!1,trackingState:"unknown"};let l;try{l=await navigator.xr.requestSession("inline-3d")}catch(u){return{supported:!1,trackingState:"unknown",error:u}}a!==void 0&&vr(l,a);let c=null;try{c=await l.requestReferenceSpace(e)}catch{}return new li(l,c,{lazy:t,rootMargin:i,autoChrome:n,modeSwitch:s,untrackedFallback:o})}var Le=null;function it(r={}){return Y&&Y._running?Promise.resolve(Y):Le||(Le=Ur(r).finally(()=>{Le=null}),Le)}var Nr=.7,lo=new Set(["IMG","SVG","VIDEO","CANVAS","BUTTON","INPUT","SELECT","TEXTAREA"]);function co(r){let e=[],t=document.createTreeWalker(r,NodeFilter.SHOW_ELEMENT);for(let i=t.nextNode();i;i=t.nextNode())if(!i.closest("[data-inline3d-no-overlay]")){if(lo.has(i.tagName.toUpperCase())){e.push(i);continue}for(let n of i.childNodes)if(n.nodeType===Node.TEXT_NODE&&n.nodeValue.trim()){e.push(i);break}}return e}var ri=4;function ni(r){let e=typeof window<"u"&&window.devicePixelRatio||1,t="";if(typeof r.getBoundingClientRect=="function"){let i=r.getBoundingClientRect()||{},n=typeof window<"u"&&window.scrollX||0,s=typeof window<"u"&&window.scrollY||0;t=`+${Math.round((i.left??i.x??0)+n)},${Math.round((i.top??i.y??0)+s)}`}return`${r.clientWidth}x${r.clientHeight}@${e}${t}`}function jr(r){let e=typeof window<"u"&&window.devicePixelRatio||1;return{width:r.clientWidth||0,height:r.clientHeight||0,dpr:e}}function ho(r){if(r==null||r===!1||r==="off")return null;if(r==="auto"||r===!0)return{color:"#000",snapshot:!0};if(typeof r=="object"){if(r.color!==void 0&&typeof r.color!="string")throw new TypeError("[inline3d] rectCover.color must be a CSS color string.");return{color:r.color||"#000",snapshot:r.snapshot!==!1}}throw new TypeError(`[inline3d] rectCover: expected 'auto', 'off' or { color?, snapshot? }; got ${JSON.stringify(r)}.`)}var li=class{constructor(e,t,{lazy:i,rootMargin:n,autoChrome:s=!0,modeSwitch:o=null,untrackedFallback:a="none"}){this.supported=!0,this.session=e,this.refSpace=t,this._windows=new Map,this._claims=new Map,this._doubleWarned=new WeakSet,this._globalOverlays=new Set,this._isolatedBy=new WeakMap,this._autoChrome=s,this._autoChromeEls=new Set,this._lastChromeScan=0,this._fullTileWarned=new WeakSet,this._stoodDown=!1,this._activeModeIndex=-1,this._activeViewCount=0,this._hardwareDisplayState=null,this._modes=null,this._stereoCollapsed=!1,this._displayListeners=new Map,this._primedDisplayState=!1;let l=o&&typeof o=="object"?o:{};this._msEnabled=l.enabled!==!1,this._modeSwitch=new Je((Number.isFinite(l.durationMs)?Math.max(0,l.durationMs):180)/1e3,io(l.easing)),this._stereoFactor=1,this._msFire=null,this._msArmedUp=!1,this._msLastMs=null,this._msTick=null,this._trackingSupported=Qe(e)!==null,this._trackingState=this._trackingSupported?Qe(e):"unknown",this._untrackedFallback=a==="mono"?"mono":"none",this._bakedStereo=1,this._bakedTarget=1,this._bakedAt=null,this._bakedEaseS=(Number.isFinite(l.durationMs)?Math.max(0,l.durationMs):180)/1e3,this._applyUntrackedTarget(),this.undock=Zt()?{model:!1,splat:!1}:null,this._undockRead=!1,this._running=!0,this._lazy=i,this._observer=i&&typeof IntersectionObserver=="function"?new IntersectionObserver(c=>this._onIntersect(c),{rootMargin:n}):null,this._loopId=0,this._framePending=!1,this._frameCount=0,this._frameWatchdog=null,this._suspended=null,Y&&Y._running&&Y!==this&&console.warn("[inline3d] A second inline-3D session is live in this document. The browser's element-rect channel is a whole-widget setter, so both managers clobber each other's rect list every frame \u2014 tiles may flicker, ghost, or weave at a stale rect. Use ONE createInline3D() per document and add every window to it; if you are switching views, close() the previous manager first."),Y=this,e.addEventListener("end",()=>this._teardown()),this._bindDisplayEvents(),this._bindTrackingEvents(),this._scanChrome(),this._bindLifecycle(),this._armDprWatch(),this._requestFrame()}get liveCount(){let e=0;for(let t of this._windows.values())t.layer&&e++;return e}addGlobalOverlay(e){if(!(!e||this._globalOverlays.has(e))){ue()&&Qt(),this._globalOverlays.add(e);for(let t of this._windows.values())t.layer&&this._applyExclusion(t,e)}}removeGlobalOverlay(e){if(!(!e||!this._globalOverlays.delete(e)))for(let t of this._windows.values())t.layer&&this._dropExclusion(t,e)}_scanChrome(){if(ue()||!this._autoChrome||!Ze()||typeof document>"u")return;let e=Date.now();if(e-this._lastChromeScan<1e3)return;this._lastChromeScan=e;let t=document.body;if(!t)return;let i=new Set,n=t.querySelectorAll(":scope > *, :scope > * > *, :scope > * > * > *");for(let s of n){if(s.closest("[data-inline3d-no-overlay]"))continue;let o=getComputedStyle(s).position;if(o!=="fixed"&&o!=="sticky")continue;let a=!1;for(let l of this._windows.keys())if(s===l||s.contains(l)){a=!0;break}if(!a){i.add(s);for(let l of co(s))i.add(l)}}for(let s of this._autoChromeEls){let o=!1;if(s.isConnected){for(let a of this._windows.keys())if(s===a||s.contains(a)){o=!0;break}}(!s.isConnected||o)&&(this._autoChromeEls.delete(s),this.removeGlobalOverlay(s))}for(let s of i)this._globalOverlays.has(s)||(this._autoChromeEls.add(s),this.addGlobalOverlay(s))}addImage(e,t,i={}){this._warnDoubleAttach(e,"addImage",i._dxrClaim);let n=this._register(e,"image",i);return n.method="addImage",n.ready=fo(t).then(s=>{n.img=s,n.repaint()}),this._handle(e,n)}addVideo(e,t,i={}){this._warnDoubleAttach(e,"addVideo",i._dxrClaim);let n=this._register(e,"video",i);return n.method="addVideo",n.video=t,this._handle(e,n)}addScene(e,t,i={}){this._warnDoubleAttach(e,"addScene",i._dxrClaim),i.viewRig&&i.virtualDisplayHeight!==void 0&&ao();let n=this._register(e,"scene",{virtualDisplayHeight:.24,...i});return n.method="addScene",n.onFrame=t,n.ownsBuffer=!1,i.bufferClamped===!0&&(n.warnedBufMismatch=!0),this._handle(e,n)}_liveRegistration(e,t){let i=this._claims.get(e);if(i&&i.token!==t)return i.method;let n=this._windows.get(e);return n?n.method||"add*":null}_warnDoubleAttach(e,t,i){let n=this._liveRegistration(e,i);!n||this._doubleWarned.has(e)||(this._doubleWarned.add(e),console.warn(`[inline3d] ${t}() on a canvas that is already registered on this inline-3D session (by ${n}(), not yet removed). This call is rebuilding the canvas's layer (a fresh 0.4-1.2 s identity gap) or putting a second renderer on its context. Change what is IN the canvas instead (setSource, your onFrame, a redrawn source canvas), or call handle.remove() on the first registration first. (Warned once per canvas.)`,e))}_attachGuard(e,t,i={}){let n=this._claims.get(e);if(i&&i._dxrClaim&&n&&n.token===i._dxrClaim)return{opts:i,own:()=>{}};this._warnDoubleAttach(e,t,null);let s={};return{opts:{...i,_dxrClaim:s},own:o=>this._claim(e,t,o,s)}}_claim(e,t,i,n){if(!this._running||!i||typeof i!="object")return;let s={token:n,method:t};this._claims.set(e,s);let o=i.remove,a=(...l)=>(this._claims.get(e)===s&&this._claims.delete(e),typeof o=="function"?o.apply(i,l):void 0);Object.defineProperty(i,"remove",{configurable:!0,enumerable:!0,get:()=>a,set:l=>{o=l}})}_handle(e,t){let i=this;return{remove:()=>this._remove(e),exclude:n=>{n&&(ue()&&Qt(),t.excluded.add(n),this._applyExclusion(t,n))},unexclude:n=>{!n||!t.excluded.delete(n)||this._dropExclusion(t,n)},get trackingState(){return i._trackingState},setViewRig:n=>(t.viewRig=n||null,n&&Bt(t.rigWarned,n),this._pushViewRig(t)),setCursorDepth:n=>{let s=t.layer;if(!s||typeof s.setCursorDepth!="function")return!1;try{return n?s.setCursorDepth(n):s.setCursorDepth(),!0}catch{return!1}},getCursorDepthSupport:()=>{let n=t.layer;if(!n||typeof n.getCursorDepthSupport!="function")return Promise.resolve("none");try{return Promise.resolve(n.getCursorDepthSupport()).then(s=>s==="runtime"?"runtime":"none",()=>"none")}catch{return Promise.resolve("none")}},getDisplayInfo:()=>this._layerCall(t,"getDisplayInfo","getDisplayInfo()"),displayMetrics:async()=>{let n=null;try{n=await this._layerCall(t,"getDisplayInfo","getDisplayInfo()")}catch{}return yr(n,e.getBoundingClientRect(),globalThis.devicePixelRatio||1)},getRenderingModes:()=>this._getRenderingModes(t),requestRenderingMode:n=>this._requestRenderingModeEased(n,t),setStereoEnabled:n=>this._setStereoEnabled(n,t),on:(n,s)=>this.on(n,s),off:(n,s)=>this.off(n,s),onDisplayModeChange:n=>this._onDisplayModeChange(n),stats:()=>({frames:t.frames,monoFrames:t.monoFrames}),get wovenState(){return ti()?t.layer?et(t.layer):"pending":null},get withheldReason(){return!ti()||!t.layer?null:et(t.layer)==="withheld"?ii(t.layer):null},get firstWoven(){return t.fwPromise},onFirstWoven:n=>{if(typeof n!="function")throw new TypeError("[inline3d] onFirstWoven() takes a function.");let s=!0;return t.fwPromise.then(o=>{if(s)try{n(o)}catch(a){console.error("[inline3d] onFirstWoven callback threw",a)}}),()=>{s=!1}},rewoven:()=>this._rewoven(t)}}getDisplayInfo(){return this._layerCall(this._liveWindow(null),"getDisplayInfo","getDisplayInfo()")}getRenderingModes(){return this._getRenderingModes(null)}requestRenderingMode(e){return this._requestRenderingModeEased(e,null)}setStereoEnabled(e){return this._setStereoEnabled(e,null)}get trackingState(){return this._trackingState}get hardwareDisplayState(){return this._hardwareDisplayState}get activeMode(){return{modeIndex:this._activeModeIndex,viewCount:this._activeViewCount}}get stereoCollapsed(){return this._stereoCollapsed}get modeSwitch(){return{active:this._msTransitionActive(),factor:this._stereoFactor}}close(){try{this.session.end()}catch{}this._teardown()}_effectiveViewRig(e){return this._stereoFactor>=1?e.viewRig||(e.stereoSynthRig?ei(e):null):(e.viewRig||(e.stereoSynthRig=!0),Ks(e.viewRig||ei(e),this._stereoFactor))}_setStereoCollapsed(e){let t=!!e;if(this._stereoCollapsed!==t){this._stereoCollapsed=t,t&&ro(),!t&&this._msArmedUp?(this._msArmedUp=!1,this._startUpRamp()):this._modeSwitch.active()||(this._stereoFactor=t?0:1);for(let i of this._windows.values()){if(t){let n=i.viewRig||ei(i);i.stereoSaved={ipdFactor:n.ipdFactor,parallaxFactor:n.parallaxFactor}}else i.stereoSaved=null;this._pushViewRig(i)}}}_pushViewRig(e){if(!Kt())return oo(),!1;if(!e.layer)return!1;let t=this._effectiveViewRig(e);try{return e.layer.setViewRig(t),!0}catch{return!1}}_layerCall(e,t,i,n=[]){if(!Jt())return Promise.reject(new Error(`[inline3d] ${i} needs a DisplayXR Browser with the display-mode API (XRDisplayLayer.getDisplayInfo/getRenderingModes/requestRenderingMode). Gate on inline3dDisplayModesSupported().`));if(!e||!e.layer)return Promise.reject(new Error(`[inline3d] ${i} needs a live weave layer, and this window has none right now (lazy mode closes the layer while the tile is off screen). Call it once the tile is visible, or create the manager with { lazy: false }.`));if(Qs.has(t)&&!e.layerFramed&&this._layerReadPending(e))return this._whenLayerFramed(e).then(()=>this._layerCall(e,t,i,n));let o;try{o=Promise.resolve(e.layer[t](...n))}catch(l){return Promise.reject(l)}if(!eo.has(t)||!this._layerReadPending(e))return o;let a=e.layer;return o.then(l=>e.layer!==a?l:to(l)?this._layerReadPending(e)?this._whenLayerFramed(e).then(()=>this._layerCall(e,t,i,n)):l:(e.lfAnswered=!0,l))}_layerFramedCap(e){return ri*Math.max(e.fwHoldMs,oi)}_layerReadPending(e){return!e.layer||e.lfAnswered||e.lfCapped?!1:W()-e.lfAt>=this._layerFramedCap(e)?(e.lfCapped=!0,!1):!0}_whenLayerFramed(e){return new Promise(t=>{let i=e.layer,n={resolve:t,timer:null},s=Math.max(0,this._layerFramedCap(e)-(W()-e.lfAt));n.timer=setTimeout(()=>{let o=e.framedWaiters.indexOf(n);o>=0&&e.framedWaiters.splice(o,1),e.layer===i&&(e.lfCapped=!0),t()},s),n.timer&&typeof n.timer.unref=="function"&&n.timer.unref(),e.framedWaiters.push(n)})}_tickLayerFramed(e){let t=e.wsLive?et(e.layer):null;(t?t==="woven":e.lfStereo)?this._noteLayerFramed(e,!0):e.framedWaiters.length&&!this._layerReadPending(e)&&this._noteLayerFramed(e,!1)}_noteLayerFramed(e,t=!0){t&&(e.layerFramed=!0);let i=e.framedWaiters.splice(0);for(let n of i)clearTimeout(n.timer),n.resolve()}_liveWindow(e){if(e&&e.layer)return e;for(let t of this._windows.values())if(t.layer)return t;return e||null}async _getRenderingModes(e){let t=await this._layerCall(this._liveWindow(e),"getRenderingModes","getRenderingModes()"),i=Array.isArray(t)?t:[];this._modes=i;let n=i.find(s=>s.isActive);return n&&(this._activeModeIndex=n.modeIndex,this._activeViewCount=n.viewCount,(n.viewCount===1||n.viewCount===2)&&this._setStereoCollapsed(n.viewCount===1)),this._primedDisplayState=!0,t}_requestRenderingMode(e,t){return this._layerCall(this._liveWindow(t),"requestRenderingMode","requestRenderingMode()",[e])}_msTransitionActive(){return this._modeSwitch.active()||this._msArmedUp||this._msFire!==null}async _requestRenderingModeEased(e,t){if(!this._msEnabled||!Kt())return this._requestRenderingMode(e,t);let i=this._modes;if(!Array.isArray(i)||i.length===0)try{i=await this._getRenderingModes(t)}catch{i=null}let n=(Array.isArray(i)?i:[]).find(a=>a&&a.modeIndex===e),s=n&&Number.isFinite(n.viewCount)?n.viewCount:0,o=this._activeViewCount;return s<1||s>2||o<1?this._requestRenderingMode(e,t):s===1?o===1?this._requestRenderingMode(e,t):this._rampDownThenRequest(e,t):this._requestThenRampUp(e,t)}_rampDownThenRequest(e,t){if(this._msFire&&this._msFire.modeIndex===e)return this._msFire.promise;this._settlePendingDown("superseded",`a request for mode ${e} replaced it`);let i={modeIndex:e,win:t,resolve:null,reject:null,promise:null};return i.promise=new Promise((n,s)=>{i.resolve=n,i.reject=s}),this._msFire=i,this._modeSwitch.request({targetMode:e,targetViewCount:1,currentMode:this._activeModeIndex,currentViewCount:this._activeViewCount,current:this._stereoFactor,steady:1}),this._msLastMs=W(),this._armModeSwitchTick(),i.promise}_requestThenRampUp(e,t){let n=this._msFire!==null&&e===this._activeModeIndex;this._settlePendingDown("superseded",`a request for mode ${e} reversed it`);let s=n?Promise.resolve(void 0):this._requestRenderingMode(e,t);return this._stereoFactor<1&&(this._stereoCollapsed?(this._msArmedUp=!0,this._modeSwitch.cancel(),this._stereoFactor=0):this._startUpRamp()),s.catch(o=>{throw this._msArmedUp&&(this._msArmedUp=!1,this._modeSwitch.active()||(this._stereoFactor=this._stereoCollapsed?0:1)),o})}_startUpRamp(){this._settlePendingDown("superseded","the display returned to 3D"),this._modeSwitch.request({targetMode:this._activeModeIndex,targetViewCount:2,currentMode:this._activeModeIndex,currentViewCount:2,current:this._stereoFactor,steady:1}),this._msLastMs=W(),this._armModeSwitchTick()}_settlePendingDown(e,t){let i=this._msFire;if(!i)return;this._msFire=null;let n=new Error(`[inline3d] the request for rendering mode ${i.modeIndex} was never forwarded: ${t}. A ->2D switch is held until the disparity has ramped out, so a request that is reversed or replaced in that window is dropped rather than fired late.`);n.name=e,i.reject(n)}_advanceModeSwitch(){if(!this._modeSwitch.active()){this._msLastMs=null,this._disarmModeSwitchTick();return}let e=W(),t=typeof this._msLastMs=="number"?Math.max(0,(e-this._msLastMs)/1e3):0;this._msLastMs=e;let i=this._modeSwitch.update(t);if(i.factor!==this._stereoFactor){this._stereoFactor=i.factor;for(let n of this._windows.values())this._pushViewRig(n)}if(i.fire&&this._msFire){let n=this._msFire;this._msFire=null,this._requestRenderingMode(n.modeIndex,n.win).then(s=>n.resolve(s),s=>{this._startUpRamp(),n.reject(s)})}this._modeSwitch.active()||(this._msLastMs=null,this._disarmModeSwitchTick())}_armModeSwitchTick(){this._msTick!==null||typeof setTimeout!="function"||(this._msTick=setTimeout(()=>{this._msTick=null,this._running&&(this._advanceModeSwitch(),this._modeSwitch.active()&&this._armModeSwitchTick())},Js))}_disarmModeSwitchTick(){this._msTick!==null&&(typeof clearTimeout=="function"&&clearTimeout(this._msTick),this._msTick=null)}async _setStereoEnabled(e,t){let i=e?2:1,n=await this._getRenderingModes(t),s=Array.isArray(n)?n:[],o=s.find(a=>a.viewCount===i&&a.isRequestable);if(!o)throw new Error(`[inline3d] setStereoEnabled(${!!e}) found no requestable ${i}-view mode on this display (${s.length} mode(s) listed). It is sugar over requestRenderingMode() and cannot invent one \u2014 read getRenderingModes() and drive the list yourself.`);return o.isActive&&!this._msTransitionActive()||await this._requestRenderingModeEased(o.modeIndex,t),!!e}_bindDisplayEvents(){let e=this.session;!e||typeof e.addEventListener!="function"||Jt()&&(e.addEventListener("renderingmodechange",t=>{this._onRenderingModeChange(t).catch(()=>{})}),e.addEventListener("hardwaredisplaystatechange",t=>{this._onHardwareDisplayStateChange(t).catch(()=>{})}))}_onHardwareDisplayStateChange(e){let t=so(e),i=ai(e),n=a=>{a&&(this._hardwareDisplayState=a),this._emitDisplay({type:"hardwaredisplaystatechange",state:a||this._hardwareDisplayState,detail:i})};t&&n(t);let s=this._activeModeIndex,o=this._activeViewCount;return this._getRenderingModes(null).then(a=>{let l=(Array.isArray(a)?a:[]).find(c=>c.isActive)||null;if(l&&(l.modeIndex!==s||l.viewCount!==o)&&this._emitDisplay({type:"renderingmodechange",modeIndex:this._activeModeIndex,viewCount:this._activeViewCount||null,mode:l,detail:null}),!t){let c=l&&typeof l.hardwareDisplay3D=="boolean"?l.hardwareDisplay3D?"3d":"2d":null;n(c)}}).catch(()=>{t||n(null)})}async _onRenderingModeChange(e){let t=ai(e),i=no(e),n=null;try{let s=await this._getRenderingModes(null),o=Array.isArray(s)?s:[];n=(i>=0?o.find(a=>a.modeIndex===i):null)||o.find(a=>a.isActive)||null}catch{}n?(this._activeModeIndex=n.modeIndex,this._activeViewCount=n.viewCount):i>=0&&(this._activeModeIndex=i),(this._activeViewCount===1||this._activeViewCount===2)&&this._setStereoCollapsed(this._activeViewCount===1),this._emitDisplay({type:"renderingmodechange",modeIndex:this._activeModeIndex,viewCount:this._activeViewCount||null,mode:n,detail:t})}_emitDisplay(e,t){let i=this._displayListeners.get(e.type);if(!i)return;let n=t||[e];for(let s of[...i])try{s(...n)}catch(o){console.error(`[inline3d] ${e.type} listener threw`,o)}}on(e,t){if(typeof t!="function")throw new TypeError("[inline3d] on() takes (type, function).");if(!Or.includes(e))throw new TypeError(`[inline3d] on() knows ${Or.join(" / ")}, got ${JSON.stringify(e)}.`);let i=this._displayListeners.get(e);return i||this._displayListeners.set(e,i=new Set),i.add(t),()=>this.off(e,t)}off(e,t){let i=this._displayListeners.get(e);i&&i.delete(t)}_onDisplayModeChange(e){if(typeof e!="function")throw new TypeError("[inline3d] onDisplayModeChange() takes a function.");let t=zr.map(i=>this.on(i,e));return()=>{for(let i of t)i()}}async refreshUndock(){if(!Zt())return this.undock=null;let e=this._liveWindow(null);if(!e||!e.layer||typeof e.layer.getUndockCapabilities!="function")return this.undock;try{let t=await e.layer.getUndockCapabilities();this.undock={model:!!(t&&t.model),splat:!!(t&&t.splat)}}catch{}return this.undock}_register(e,t,i){this._windows.has(e)&&this._remove(e),e.style.willChange="transform",e.style.transform="translateZ(0)";let n={canvas:e,kind:t,layer:null,img:null,video:null,onFrame:null,onLayerLost:typeof i.onLayerLost=="function"?i.onLayerLost:null,layerLostSent:!1,onResize:t==="scene"&&typeof i.onResize=="function"?i.onResize:null,resizeBox:null,inResize:!1,ready:null,ownsBuffer:t!=="scene",cornerRadius:i.cornerRadius||0,feather:i.feather||0,reqW:i.width||0,reqH:i.height||0,virtualDisplayHeight:i.virtualDisplayHeight||0,viewRig:i.viewRig||null,rigWarned:new Set,warnedWithheld:!1,stereoSaved:null,stereoSynthRig:!1,observeEl:i.observe||e,ctx:t==="scene"?null:e.getContext("2d"),repaint:()=>this._paint(n,null),excluded:new Set,autoExcluded:new Set,overlayObserver:null,sizeObserver:null,resizePending:!1,frames:0,monoFrames:0,fwResult:null,fwResolve:null,fwPromise:null,fwHoldMs:uo(i.firstWovenHoldMs),fwRegAt:W(),fwLayerAt:null,fwStereo:!1,rw:null,rwGone:null,wsLive:!1,rc:null,layerFramed:!1,lfAnswered:!1,lfStereo:!1,lfAt:0,lfCapped:!1,framedWaiters:[]},s=ho(i.rectCover);return s&&(n.rc={cfg:s,box:null,el:null,up:!1,snapped:!1,snapWanted:!1,waiting:null,w:0,h:0}),n.fwPromise=new Promise(o=>{n.fwResolve=o}),n.viewRig&&Bt(n.rigWarned,n.viewRig),this._windows.set(e,n),this._lazy&&this._observer?this._observer.observe(n.observeEl):this._activate(n),n}_remove(e){let t=this._windows.get(e);t&&(this._observer&&this._observer.unobserve(t.observeEl),this._deactivate(t),this._windows.delete(e),this._settleFirstWoven(t,!1,"removed"),this._dropCover(t))}_onIntersect(e){for(let t of e){let i=null;for(let n of this._windows.values())if(n.observeEl===t.target){i=n;break}i&&(t.isIntersecting?this._activate(i):this._deactivate(i))}}_activate(e){if(!e.layer){this._scanChrome();try{let t=Kt()?this._effectiveViewRig(e):null,i=t?{viewRig:t}:e.virtualDisplayHeight>0?{virtualDisplayHeight:e.virtualDisplayHeight}:{};e.layer=new XRDisplayLayer(this.session,e.canvas,i)}catch(t){e.layer=null,e.layerFailWarned||(e.layerFailWarned=!0,console.warn("[inline3d] new XRDisplayLayer() failed for this window \u2014 it will show FLAT 2D instead of woven 3D, and the SDK will not retry. The canvas has been repainted mono so it cannot be left holding a raw side-by-side pair.",t)),this._paintMono(e),this._notifyLayerLost(e),this._settleFirstWoven(e,!1,"layer-failed");return}e.fwResult||(e.fwLayerAt=W(),e.fwStereo=!1),e.wsLive=ti(),e.layerFramed=!1,e.lfAnswered=!1,e.lfStereo=!1,e.lfCapped=!1,e.lfAt=W(),this._restartRewoven(e),e.layerLostSent=!1,!this._primedDisplayState&&Jt()&&(this._primedDisplayState=!0,this._getRenderingModes(e).catch(()=>{this._primedDisplayState=!1})),Zt()&&this.undock&&!this._undockRead&&(this._undockRead=!0,this.refreshUndock().catch(()=>{})),Ys(e.layer)===!0&&this._standDownLegacyOcclusion();for(let t of e.excluded)this._applyExclusion(e,t);for(let t of this._globalOverlays)this._applyExclusion(e,t);this._startOverlayScan(e),e.ownsBuffer&&(this._sizeBuffer(e,!0),this._paint(e,null)),this._startSizeWatch(e)}}_deactivate(e){if(this._noteLayerFramed(e,!1),this._stopOverlayScan(e),this._stopSizeWatch(e),e.layer){try{e.layer.close()}catch{}e.layer=null}this._paintMono(e)}_paintMono(e){!e.ownsBuffer||e.kind==="scene"||(this._sizeBuffer(e,!1),this._paint(e,null))}_notifyLayerLost(e){if(!(e.kind!=="scene"||typeof e.onLayerLost!="function"||e.layerLostSent)){e.layerLostSent=!0;try{e.onLayerLost()}catch(t){console.warn("[inline3d] a scene window's onLayerLost callback threw",t)}}}_isFullTileOverlay(e,t){if(!t||typeof t.getBoundingClientRect!="function")return!1;let i=t.getBoundingClientRect(),n=e.canvas.getBoundingClientRect(),s=i.width*i.height,o=n.width*n.height;if(s<=0||o<=0)return!1;let a=Math.min(i.right,n.right)-Math.max(i.left,n.left),l=Math.min(i.bottom,n.bottom)-Math.max(i.top,n.top);if(a<=0||l<=0)return!1;let c=a*l;return c/s<Nr||c/o<Nr?!1:(this._fullTileWarned.has(t)||(this._fullTileWarned.add(t),console.warn("[inline3d] Refusing a full-tile overlay: this element covers its own woven canvas, and the browser's geometric matcher cannot tell the two apart \u2014 it would stage the CANVAS as the overlay and the tile would show its raw side-by-side buffer instead of 3D. Make the overlay a PARTIAL region of the tile (a caption band, a badge, a corner plate), or move it outside the tile and register it with addGlobalOverlay().",t)),!0)}_applyExclusion(e,t){if(ue()||!e.layer||!Ze()||this._isFullTileOverlay(e,t))return;let i=this._isolatedBy.get(t);if(i||(i=new Set,this._isolatedBy.set(t,i)),i.add(e),!t.dataset.inline3dIsolated){t.dataset.inline3dPriorWillChange=t.style.willChange||"";let n=t.style.willChange&&t.style.willChange!=="auto"?t.style.willChange+", transform":"transform";t.style.willChange=n,t.dataset.inline3dIsolated="1"}try{e.layer.excludeElement(t)}catch{}}_dropExclusion(e,t){if(ue())return;let i=this._isolatedBy.get(t);if(i&&i.delete(e),(!i||i.size===0)&&this._unpromote(t),!(!e.layer||!Ze()))try{e.layer.unexcludeElement(t)}catch{}}_unpromote(e){return!e||!e.dataset||!e.dataset.inline3dIsolated?!1:(e.style.willChange=e.dataset.inline3dPriorWillChange||"",delete e.dataset.inline3dPriorWillChange,delete e.dataset.inline3dIsolated,!0)}_standDownLegacyOcclusion(){if(this._stoodDown)return;this._stoodDown=!0;let e=!1;for(let t of this._windows.values()){t.overlayObserver&&(this._stopOverlayScan(t),e=!0);for(let i of t.excluded)this._unpromote(i)&&(e=!0)}for(let t of this._autoChromeEls)this._globalOverlays.delete(t),this._unpromote(t),e=!0;this._autoChromeEls.clear();for(let t of this._globalOverlays)this._unpromote(t)&&(e=!0);this._isolatedBy=new WeakMap,e&&Qt()}_startOverlayScan(e){if(ue()||!Ze()||typeof MutationObserver!="function")return;let t=e.canvas.parentElement;if(!t)return;let i=()=>{let n=new Set(t.querySelectorAll("[data-inline3d-overlay]"));for(let s of e.autoExcluded)n.has(s)||(e.autoExcluded.delete(s),this._dropExclusion(e,s));for(let s of n)e.autoExcluded.has(s)||(e.autoExcluded.add(s),this._applyExclusion(e,s))};i(),e.overlayObserver=new MutationObserver(i),e.overlayObserver.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-inline3d-overlay"]})}_stopOverlayScan(e){e.overlayObserver&&(e.overlayObserver.disconnect(),e.overlayObserver=null),e.autoExcluded.clear()}_eyeSize(e,t=!0){let i=Math.min(window.devicePixelRatio||1,2),n=e.reqW||Math.round((e.canvas.clientWidth||256)*i),s=e.reqH||Math.round((e.canvas.clientHeight||256)*i),o=1,a=!e.reqW&&!e.reqH&&this._sourceEyeSize(e);if(a){let c=Math.max(a.w/n,a.h/s);c<1&&(o=c,n=Math.max(1,Math.round(n*c)),s=Math.max(1,Math.round(s*c)))}let l=Mr(n,s,Sr(),{cols:t?2:1});return l.clamped&&(o*=l.scale,n=l.eyeW,s=l.eyeH,e.warnedBufClamp||(e.warnedBufClamp=!0,console.warn(Er("[inline3d]",l)))),e.bufScale=o,{w:n,h:s}}_sourceEyeSize(e){if(e.kind!=="video"&&e.kind!=="image")return null;let t=e.kind==="video"?e.video:e.img;if(!t)return null;let i=t.videoWidth||t.naturalWidth||t.width,n=t.videoHeight||t.naturalHeight||t.height;return!(i>1)||!(n>0)?null:{w:i/2,h:n}}_checkSceneBuffer(e){let t=e.canvas;if(!t||typeof t.getContext!="function")return;if(e.sceneGl===void 0){let n=null;try{n=t.getContext("webgl2")||t.getContext("webgl")}catch{n=null}e.sceneGl=n&&typeof n.drawingBufferWidth=="number"?n:null}if(!e.sceneGl)return;let i=Rr(t,e.sceneGl);i.mismatch&&(e.warnedBufMismatch=!0,console.warn(Cr("[inline3d]",t,i,"getViewport() splits canvas.width, so the eyes are off-centre in the woven buffer. This scene canvas is sized by the page: keep 2 \xD7 eye width and the height within MAX_TEXTURE_SIZE / MAX_RENDERBUFFER_SIZE / MAX_VIEWPORT_DIMS, or map getViewport() onto gl.drawingBufferWidth/Height.")))}_sizeBuffer(e,t){let{w:i,h:n}=this._eyeSize(e,t);e.eyeW=i,e.eyeH=n,e.canvas.width=t?i*2:i,e.canvas.height=n,e.sbs=t}_startSizeWatch(e){if(typeof ResizeObserver=="function"&&!e.sizeObserver){if(e.kind==="scene"){if(!e.onResize)return;e.resizeBox=jr(e.canvas),e.sizeObserver=new ResizeObserver(()=>this._onSceneResize(e)),e.sizeObserver.observe(e.canvas);return}!e.ownsBuffer||e.reqW&&e.reqH||(e.sizeObserver=new ResizeObserver(()=>this._onBoxChange(e)),e.sizeObserver.observe(e.canvas))}}_onSceneResize(e){if(!e.layer||!e.onResize||e.inResize)return;let t=jr(e.canvas),i=e.resizeBox;if(!(i&&i.width===t.width&&i.height===t.height&&i.dpr===t.dpr)){e.resizeBox=t,e.inResize=!0;try{e.onResize(t)}catch(n){e.resizeThrewWarned||(e.resizeThrewWarned=!0,console.warn("[inline3d] a scene window's onResize threw; further throws from it are silent.",n))}finally{e.inResize=!1}}}_stopSizeWatch(e){e.sizeObserver&&(e.sizeObserver.disconnect(),e.sizeObserver=null),e.resizePending=!1}_onBoxChange(e){if(!e.layer||!e.ownsBuffer||e.resizePending)return;e.resizePending=!0;let t=()=>{if(!e.resizePending||(e.resizePending=!1,!e.layer||!e.ownsBuffer))return;this._noteRewovenBox(e);let{w:i,h:n}=this._eyeSize(e);i===e.eyeW&&n===e.eyeH||(this._sizeBuffer(e,!0),this._paint(e,null))};typeof requestAnimationFrame=="function"?requestAnimationFrame(t):t()}_armDprWatch(){if(typeof window>"u"||typeof window.matchMedia!="function")return;this._disarmDprWatch();let e;try{e=window.matchMedia(`(resolution: ${window.devicePixelRatio||1}dppx)`)}catch{return}let t=()=>{if(this._running){this._armDprWatch();for(let i of this._windows.values())i.layer&&this._onBoxChange(i)}};try{e.addEventListener("change",t)}catch{return}this._dprWatch={q:e,onChange:t}}_disarmDprWatch(){if(this._dprWatch){try{this._dprWatch.q.removeEventListener("change",this._dprWatch.onChange)}catch{}this._dprWatch=null}}_paint(e,t){if(e.kind==="scene"||!e.ctx)return;let i=this._running&&!!e.layer;!i&&e.sbs&&this._sizeBuffer(e,!1);let n=e.kind==="video"?e.video:e.img;if(!n)return;if(e.kind==="video"&&(n.readyState||0)<2){i&&this._recommitLastFrame(e);return}let s=e.canvas,o=e.ctx,a=n.videoWidth||n.naturalWidth||n.width,l=n.videoHeight||n.naturalHeight||n.height;if(!a||!l)return;let c=a+"x"+l;if(e.srcKey!==c&&(e.srcKey=c,e.ownsBuffer&&!(e.reqW&&e.reqH))){let{w:g,h:w}=this._eyeSize(e,e.sbs);(g!==e.eyeW||w!==e.eyeH)&&this._sizeBuffer(e,e.sbs)}let u=e.bufScale||1,f=e.cornerRadius*u,h=e.feather*u;if(o.clearRect(0,0,s.width,s.height),!e.sbs){tt(o,n,0,0,a/2,l,0,0,s.width,s.height,f,h);return}let d=s.width/2,p=Math.min(this._stereoFactor,this._bakedStereo);if(p<1){tt(o,n,0,0,a/2,l,0,0,d,s.height,f,h),po(o,n,a/2,l,d,s.height,p,f,h);return}f>0||h>0?(tt(o,n,0,0,a/2,l,0,0,d,s.height,f,h),tt(o,n,a/2,0,a/2,l,d,0,d,s.height,f,h)):o.drawImage(n,0,0,a,l,0,0,s.width,s.height)}_bindTrackingEvents(){let e=this.session;!e||typeof e.addEventListener!="function"||this._trackingSupported&&e.addEventListener(si,()=>{this._setTrackingState(Qe(e)||"unknown")})}_setTrackingState(e){let t=Wr.includes(e)?e:"unknown";if(t===this._trackingState)return;this._trackingState=t,this._applyUntrackedTarget();let i={type:si,state:t};this._emitDisplay(i,[t,i])}_applyUntrackedTarget(){if(this._untrackedFallback!=="mono"){this._bakedTarget=1;return}this._trackingState==="searching"?this._bakedTarget=0:this._trackingState==="tracking"&&(this._bakedTarget=1)}_trackBakedStereo(e){this._trackingSupported&&this._setTrackingState(Qe(this.session)||"unknown");let t=this._bakedAt===null||!Number.isFinite(e)?0:Math.max(0,(e-this._bakedAt)/1e3);this._bakedAt=Number.isFinite(e)?e:this._bakedAt;let i=this._bakedStereo,n=this._bakedTarget;if(i===n)return;let s=this._bakedEaseS>0?t/this._bakedEaseS:1;this._bakedStereo=n>i?Math.min(n,i+s):Math.max(n,i-s)}_recommitLastFrame(e){let t=e.canvas;if(!t.width||!t.height)return;let i=e.ctx;try{i.save(),i.globalCompositeOperation="copy",i.drawImage(t,0,0),i.restore()}catch{}}_requestFrame(e){if(!this._running||this._framePending&&!e)return;let t=e?++this._loopId:this._loopId;this._framePending=!0;try{this.session.requestAnimationFrame((i,n)=>{t===this._loopId&&(this._framePending=!1,this._frameCount++,this._frame(i,n))})}catch{this._framePending=!1}}_frame(e,t){if(!this._running)return;this._requestFrame(),this._advanceModeSwitch();let i=this.refSpace?t.getViewerPose(this.refSpace):null,n=i?i.views:null;this._trackBakedStereo(e);for(let s of this._windows.values())if(s.layer){if(s.rc&&this._rectCoverCheck(s),s.kind==="scene"){if(n&&s.onFrame){if(s.frames++,n.length<2&&(s.monoFrames++,s.monoFrames%300===1&&typeof console<"u"&&console.debug)){let o=(100*s.monoFrames/Math.max(1,s.frames)).toFixed(1);console.debug(`[inline3d] scene window: ${s.monoFrames} non-stereo view lists in ${s.frames} frames (${o}%). The viewer replays its last good stereo frame for these; a rising rate means the session is falling back under load.`)}try{s.onFrame(n,s.layer,t),n.length>=2&&(s.fwStereo=!0,s.lfStereo=!0,s.warnedBufMismatch||this._checkSceneBuffer(s),s.rw&&(s.rw.stereo=!0))}catch(o){s.frameThrewWarned||(s.frameThrewWarned=!0,console.warn("[inline3d] a scene window's onFrame threw; this window will keep whatever it last drew, and the other windows carry on. Further throws from it are silent.",o))}}}else this._paint(s,n),s.sbs&&(s.kind==="video"?(s.video&&s.video.readyState||0)>=2:s.img)&&(s.fwStereo=!0,s.lfStereo=!0,s.rw&&(s.rw.stereo=!0));s.rc&&s.rc.snapWanted&&this._rectCoverSnap(s),(!s.layerFramed||s.framedWaiters.length)&&this._tickLayerFramed(s),this._tickFirstWoven(s)}}_tickFirstWoven(e){let t=e.wsLive&&e.layer?et(e.layer):null;if(t){this._tickWovenState(e,t);return}if(e.rw){this._noteRewovenBox(e);let i=e.rw,n=W();i.stereo&&n-i.at>=e.fwHoldMs?this._settleRewoven(e,!0,"hold-elapsed"):i.at>i.calledAt&&n-i.calledAt>=ri*e.fwHoldMs&&this._settleRewoven(e,!0,"hold-capped")}e.fwResult||!e.fwStereo||e.fwLayerAt===null||W()-e.fwLayerAt<e.fwHoldMs||this._settleFirstWoven(e,!0,"hold-elapsed")}_tickWovenState(e,t){let i=W(),n=ri*Math.max(e.fwHoldMs,oi);if(e.rw){this._noteRewovenBox(e);let s=e.rw;t!=="woven"?s.gap=!0:s.stereo&&(s.gap||s.boxFrame!==null&&this._frameCount-s.boxFrame>=Pr||s.boxFrame===null&&this._frameCount-s.callFrame>=Pr)&&this._settleRewoven(e,!0,"woven",!0),e.rw&&i-s.calledAt>=n&&(t==="woven"?this._settleRewoven(e,!0,"hold-capped",!0):this._settleRewoven(e,!1,ii(e.layer)||t,!0))}e.fwResult||e.fwLayerAt===null||(e.fwStereo&&t==="woven"?this._settleFirstWoven(e,!0,"woven",!0):i-e.fwLayerAt>=n&&(t==="woven"?this._settleFirstWoven(e,!0,"hold-capped",!0):this._settleFirstWoven(e,!1,ii(e.layer)||t,!0)))}_noteWithheld(e,t,i,n){t||!n||e.warnedWithheld||!i||i==="pending"||i==="hold-capped"||(e.warnedWithheld=!0,console.warn(`[inline3d] the browser withheld this canvas from the weave (${i}): ${wr(i)}.`,e.canvas))}_settleFirstWoven(e,t,i,n=!1){this._noteWithheld(e,t,i,n),!t&&!n&&(e.rwGone||(e.rwGone=i),this._settleRewoven(e,!1,i)),!e.fwResult&&(e.fwResult=Object.freeze({woven:t,confirmed:n,reason:i,ms:Math.round(W()-e.fwRegAt)}),e.fwResolve(e.fwResult),e.fwResolve=null)}_rewoven(e){if(!e.fwResult)return e.fwPromise;if(!e.fwResult.woven&&!e.fwResult.confirmed)return Promise.resolve(e.fwResult);if(e.rwGone)return Promise.resolve(Object.freeze({woven:!1,confirmed:!1,reason:e.rwGone,ms:0}));if(e.rw)return this._restartRewoven(e),e.rw.promise;let t,i=new Promise(s=>{t=s}),n=W();return e.rw={promise:i,resolve:t,calledAt:n,at:n,stereo:!1,box:ni(e.canvas),gap:!1,boxFrame:null,callFrame:this._frameCount},i}_noteRewovenBox(e){let t=e.rw;if(!t)return;let i=ni(e.canvas);i!==t.box&&(t.box=i,this._restartRewoven(e))}_restartRewoven(e){e.rw&&(e.rw.at=W(),e.rw.stereo=!1,e.rw.gap=!1,e.rw.boxFrame=this._frameCount)}_settleRewoven(e,t,i,n=!1){let s=e.rw;s&&(this._noteWithheld(e,t,i,n),e.rw=null,s.resolve(Object.freeze({woven:t,confirmed:n,reason:i,ms:Math.round(W()-s.calledAt)})))}_rectCoverCheck(e){let t=e.rc,i=ni(e.canvas);if(i===t.box)return;let n=t.box===null,s=t.w,o=t.h;if(t.box=i,t.w=e.canvas.clientWidth||0,t.h=e.canvas.clientHeight||0,n)return;t.up&&this._placeCover(e);let a=e.fwResult;if(!a||e.rwGone||!(a.woven||a.confirmed))return;t.up||(t.snapped||(t.aspect=o>0?s/o:0),this._raiseCover(e)),t.cfg.snapshot&&!t.snapped&&t.w>0&&t.h>0&&(t.snapWanted=!0);let l;e.rw?(this._noteRewovenBox(e),l=e.rw.promise):(l=this._rewoven(e),e.rw&&(e.rw.boxFrame=this._frameCount)),t.waiting!==l&&(t.waiting=l,l.then(()=>{t.waiting===l&&(t.waiting=null,this._lowerCover(e))}))}_raiseCover(e){let t=e.rc;if(!t.el){if(typeof document>"u"||!document||typeof document.createElement!="function"||!e.canvas.parentElement)return;let i=document.createElement("canvas");i.setAttribute?.("aria-hidden","true"),i.dataset&&(i.dataset.inline3dCover="");let n=i.style;n.position="absolute",n.pointerEvents="none",n.margin="0",n.border="0",n.padding="0",n.background=t.cfg.color,n.display="none";try{let s=typeof getComputedStyle=="function"?getComputedStyle(e.canvas).zIndex:"auto";s&&s!=="auto"&&(n.zIndex=s)}catch{}t.el=i}this._placeCover(e),t.el.style.display="block",t.up=!0,this._fullTileWarned.add(t.el),this._applyExclusion(e,t.el)}_placeCover(e){let i=e.rc.el,n=e.canvas;if(!i)return;let s=n.parentElement;s&&(i.parentElement!==s||i.previousSibling!==n)&&s.insertBefore(i,n.nextSibling);let o=i.style;if(n.offsetParent)o.position="absolute",o.left=`${n.offsetLeft}px`,o.top=`${n.offsetTop}px`,o.width=`${n.offsetWidth}px`,o.height=`${n.offsetHeight}px`;else{let a=n.getBoundingClientRect();o.position="fixed",o.left=`${a.left??a.x??0}px`,o.top=`${a.top??a.y??0}px`,o.width=`${a.width}px`,o.height=`${a.height}px`}}_rectCoverSnap(e){let t=e.rc;t.snapWanted=!1;let i=t.el,n=e.canvas;if(!i||!t.up||!(n.width>1)||!(n.height>0))return;let s=Math.max(1,Math.round(t.w)),o=Math.max(1,Math.round(t.h)),a=s/o,l=t.aspect>0?t.aspect:n.width/2/n.height,c=1,u=1;a>l?u=l/a:c=a/l;let f=n.width/2*c,h=n.height*u,d=(n.width/2-f)/2,p=(n.height-h)/2;try{i.width=s,i.height=o;let g=i.getContext("2d");if(!g)return;g.drawImage(n,d,p,f,h,0,0,s,o),t.snapped=!0}catch{}}_lowerCover(e){let t=e.rc;t&&(t.up=!1,t.snapped=!1,t.snapWanted=!1,t.el&&(t.el.style.display="none",this._dropExclusion(e,t.el)))}_dropCover(e){let t=e.rc;t&&(t.waiting=null,this._lowerCover(e),t.el&&t.el.parentElement&&t.el.parentElement.removeChild(t.el),t.el=null)}_bindLifecycle(){typeof window>"u"||(this._onPageHide=()=>this._suspend(),this._onPageShow=e=>this._resume(!!(e&&e.persisted)),window.addEventListener("pagehide",this._onPageHide),window.addEventListener("pageshow",this._onPageShow),typeof document<"u"&&"onfreeze"in document&&(this._onFreeze=()=>this._suspend(),this._onResume=()=>this._resume(!0),document.addEventListener("freeze",this._onFreeze),document.addEventListener("resume",this._onResume)))}_unbindLifecycle(){typeof window>"u"||(this._onPageHide&&window.removeEventListener("pagehide",this._onPageHide),this._onPageShow&&window.removeEventListener("pageshow",this._onPageShow),this._onFreeze&&typeof document<"u"&&(document.removeEventListener("freeze",this._onFreeze),document.removeEventListener("resume",this._onResume)),this._onPageHide=this._onPageShow=this._onFreeze=this._onResume=null,this._frameWatchdog&&(clearTimeout(this._frameWatchdog),this._frameWatchdog=null))}_suspend(){if(!this._running||this._suspended)return;let e=[];for(let t of this._windows.values())t.layer&&(e.push(t),this._deactivate(t));this._suspended=e}_resume(e){if(!this._running)return;let t=this._suspended;if(this._suspended=null,t)for(let i of t)this._windows.has(i.canvas)&&(this._lazy&&this._observer?(this._observer.unobserve(i.observeEl),this._observer.observe(i.observeEl)):this._activate(i));this._lastChromeScan=0,this._scanChrome(),this._armDprWatch(),e&&this._watchForStalledFrames()}_watchForStalledFrames(){if(this._frameWatchdog||typeof setTimeout!="function")return;let e=this._frameCount;this._frameWatchdog=setTimeout(()=>{this._frameWatchdog=null,!(!this._running||this._frameCount!==e)&&this._requestFrame(!0)},1e3)}_teardown(){if(this._running){this._running=!1,Y===this&&(Y=null),this._unbindLifecycle(),this._disarmDprWatch(),this._disarmModeSwitchTick(),this._modeSwitch.cancel(),this._msArmedUp=!1,this._settlePendingDown("closed","the inline-3D session closed first"),this._observer&&this._observer.disconnect();for(let e of this._windows.values()){if(this._stopOverlayScan(e),this._stopSizeWatch(e),e.layer){try{e.layer.close()}catch{}e.layer=null}this._paintMono(e),this._notifyLayerLost(e),this._settleFirstWoven(e,!1,"session-ended"),this._dropCover(e),this._noteLayerFramed(e,!1)}this._windows.clear(),this._claims.clear(),this._setTrackingState("unknown"),this._displayListeners.clear()}}};function uo(r){return typeof r=="number"&&Number.isFinite(r)&&r>=0?r:oi}function fo(r){return typeof r!="string"?Promise.resolve(r):new Promise((e,t)=>{let i=new Image;i.decoding="async",i.onload=()=>e(i),i.onerror=t,i.src=r})}function tt(r,e,t,i,n,s,o,a,l,c,u,f){u>0&&r.roundRect?(r.save(),r.beginPath(),r.roundRect(o,a,l,c,u),r.clip(),r.drawImage(e,t,i,n,s,o,a,l,c),r.restore()):r.drawImage(e,t,i,n,s,o,a,l,c),f>0&&Vr(r,o,a,l,c,f)}function po(r,e,t,i,n,s,o,a,l){r.save(),a>0&&r.roundRect&&(r.beginPath(),r.roundRect(n,0,n,s,a),r.clip()),r.drawImage(e,0,0,t,i,n,0,n,s),o>0&&(r.globalAlpha=o,r.drawImage(e,t,0,t,i,n,0,n,s)),r.restore(),l>0&&Vr(r,n,0,n,s,l)}function Vr(r,e,t,i,n,s){let o=Math.min(s,Math.floor(Math.min(i,n)/2));if(o<=0)return;r.save(),r.globalCompositeOperation="destination-out";let a=[[e,t,i,o,[e,t],[e,t+o]],[e,t+n-o,i,o,[e,t+n],[e,t+n-o]],[e,t,o,n,[e,t],[e+o,t]],[e+i-o,t,o,n,[e+i,t],[e+i-o,t]]];for(let[l,c,u,f,h,d]of a){let p=r.createLinearGradient(h[0],h[1],d[0],d[1]);p.addColorStop(0,"rgba(0,0,0,1)"),p.addColorStop(1,"rgba(0,0,0,0)"),r.fillStyle=p,r.fillRect(l,c,u,f)}r.restore()}function ci(r,e){return r>0&&e>0&&r/e>2.5}function q(r,e,t,i,n){let s=Math.abs(i||0),o=Math.min(r-2*s,e*t);o=Math.max(1,o);let a=Math.min(e,o/t);o=a*t;let l=(r-o)/2+(n===0?i:-i);return{sx:Math.max(0,Math.min(r-o,l)),sy:(e-a)/2,sw:o,sh:a}}function Ie(r,e,t){let i=Math.min(r,e*t),n=i/t;return{w:Math.max(2,Math.round(i/2)*2),h:Math.max(2,Math.round(n/2)*2)}}function fe(r,e){let t=r/2;return[{src:"R",sx:t,sw:t,sy:0,sh:e,dx:0,dw:t,mirror:!0},{src:"L",sx:0,sw:t,sy:0,sh:e,dx:t,dw:t,mirror:!0}]}function hi(r,e,t){let i=new r.constructor(r.length);for(let n of fe(e,t))for(let s=0;s<t;s++)for(let o=0;o<n.dw;o++){let a=n.sx+(n.sw-1-o);i[s*e+n.dx+o]=r[s*e+a]}return i}function Br(r,e){return!(r>0)||!(e>0)||e>=180?null:r/2/Math.tan(e/2*Math.PI/180)}function rt({eyeWidthPx:r,hfovDeg:e,baselineMm:t,subjectZmm:i}){let n=Br(r,e);return n===null||!(t>0)||!(i>0)?0:n*t/(2*i)}function nt(r,e,t=.2){let i=Math.max(0,e*t);return Math.max(-i,Math.min(i,r||0))}function st(r,e,t=.2){let i=r+t*(e-r);return Math.abs(e-i)<.05?e:i}function Fe(){let r={hello:null,subjectZmm:null,measuredPx:null,depth:0,current:0,target(e){let t=r.measuredPx!==null?r.measuredPx/2:r.hello&&r.subjectZmm?rt({eyeWidthPx:e,hfovDeg:r.hello.hfovDeg,baselineMm:r.hello.baselineMm,subjectZmm:r.subjectZmm}):0;return nt(t+r.depth*.05*e,e)},step(e){return r.current=st(r.current,r.target(e)),r.current}};return r}var ot=1,ui="inline3d-call/1",Xr=Object.freeze(["sbs","mono"]),pe=4,qr=4,di=5,mo=150,go=5e3,_o=/^[A-Za-z0-9_-]{16,64}$/,vo=16;function fi(r){let e=new Uint8Array(vo);return(r||(i=>globalThis.crypto.getRandomValues(i)))(e),Yr(e)}function Gr(r){let e=new Uint8Array(8);return(r||(i=>globalThis.crypto.getRandomValues(i)))(e),Yr(e)}function Yr(r){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",t="",i=0;for(;i+2<r.length;i+=3){let s=r[i]<<16|r[i+1]<<8|r[i+2];t+=e[s>>18&63]+e[s>>12&63]+e[s>>6&63]+e[s&63]}let n=r.length-i;if(n===1){let s=r[i]<<16;t+=e[s>>18&63]+e[s>>12&63]}else if(n===2){let s=r[i]<<16|r[i+1]<<8;t+=e[s>>18&63]+e[s>>12&63]+e[s>>6&63]}return t}function me(r){return typeof r=="string"&&_o.test(r)}function Ne(r){if(!r)return null;let e="";if(typeof r=="object")e=r.hash||r.href&&String(r.href).split("#")[1]||"";else{let t=String(r),i=t.indexOf("#");e=i>=0?t.slice(i+1):t.includes("=")&&!t.includes("://")?t:""}e=e.replace(/^#/,"");for(let t of e.split("&")){let i=t.indexOf("=");if(i<0||decodeURIComponent(t.slice(0,i))!=="room")continue;let n=decodeURIComponent(t.slice(i+1));return me(n)?n:null}return null}function at(r,e){if(!me(e))throw new Error(`@displayxr/inline3d/call: invalid room id "${e}"`);return`${String(r||"").split("#")[0]}#room=${e}`}function pi(r){if(!r||typeof r!="object"||r.type!=="hello")return null;let e=(t,i,n)=>typeof t=="number"&&Number.isFinite(t)&&t>=i&&t<=n?t:null;return{type:"hello",v:typeof r.v=="number"?r.v:ot,format:Xr.includes(r.format)?r.format:"mono",width:e(r.width,1,16384),height:e(r.height,1,16384),baselineMm:e(r.baselineMm,1,1e3),hfovDeg:e(r.hfovDeg,5,170),rectified:r.rectified===!0,sdk:typeof r.sdk=="string"?r.sdk.slice(0,64):null}}function mi({format:r,width:e,height:t,baselineMm:i,hfovDeg:n,rectified:s}={}){let o={type:"hello",v:ot,format:Xr.includes(r)?r:"mono",width:e||0,height:t||0,rectified:!!s,sdk:ui};return Number.isFinite(i)&&(o.baselineMm=i),Number.isFinite(n)&&(o.hfovDeg=n),o}function gi(r){if(!r||r.type!=="hint")return null;let e=r.subjectZmm;return typeof e=="number"&&Number.isFinite(e)&&e>=mo&&e<=go?{type:"hint",subjectZmm:e}:null}function Kr(r){return!r||r.type!=="state"?null:{type:"state",muted:r.muted===!0,cameraOff:r.cameraOff===!0,speaking:r.speaking===!0}}function _i(r){let e=1e3/r,t=-1/0;return i=>i-t<e?!1:(t=i,!0)}function vi({format:r,woven:e,mono3D:t="auto",lift:i=!1,overBudget:n=!1,failed:s=!1}){return(r==="sbs"?"sbs":"mono")==="sbs"?{route:e?"woven-sbs":"flat-left"}:e?t==="off"||t===!1?{route:"flat",mono3d:"off"}:i?s?{route:"flat",mono3d:"failed"}:n?{route:"flat",mono3d:"budget"}:{route:"lifted",mono3d:"lifted"}:{route:"flat",mono3d:"unavailable"}:{route:"flat"}}function yi(r){return r==="woven-sbs"?"3D":r==="lifted"?"2D\u21923D":"2D"}function wi({need:r=10,needNoPose:e=30}={}){let t=0,i=0,n=!1;return{feed(s){return n?!0:(i++,s===null?n=i>=e:(t=s>=1?t+1:0,n=t>=r),n)},get live(){return n}}}function lt(r,e){let t=Math.max(1,e|0),n=r==="sbs"?[6e3,4e3,3e3]:[2500,1800,1400];return n[Math.min(t,n.length)-1]}function K(r,{baseMs:e=1e3,maxMs:t=3e4,rand:i=Math.random}={}){let n=Math.min(t,e*Math.pow(2,Math.max(0,r)));return Math.round(n*(.8+.4*i()))}var je=Object.freeze(["VP9","VP8","AV1"]);function wo(r,e=je){let t=e.indexOf(String(r||"").toUpperCase());return t<0?e.length:t}function ct(r,e=je){let t=i=>wo(String(i.mimeType||"").split("/")[1],e);return r.map((i,n)=>({c:i,i:n,r:t(i)})).sort((i,n)=>i.r-n.r||i.i-n.i).map(i=>i.c)}function ze(r,e=je){if(!r)return r;let t=r.includes(`\r
|
|
16
|
+
`})});var Ki={};Ps(Ki,{PAIR_CURSOR_ARROW:()=>sa,PAIR_CURSOR_CSS_PX:()=>na,PAIR_CURSOR_CSS_PX_M:()=>Kn,PAIR_CURSOR_HEIGHT:()=>Yn,PAIR_SUPPORT_COPY_PX:()=>Zn,PairCursor:()=>Yi,consistentMatch:()=>Gi,drawPairArrow:()=>rs,drawPairArrowSoft:()=>ss,drawPairImage:()=>os,pairCursorScale:()=>es,pairCursorTarget:()=>aa,pairFootprintDisparity:()=>Jn,pairNearestSupported:()=>Qn,pairPxPerBaseline:()=>ts});function Jn(r,e,t,i,n,s){if(!r||!r.img||!e||!e.rL||!e.rR||!(e.outW>0))return null;let{img:o,w:a,h:l,scale:c}=r,d=a/2,f=Math.max(8,Math.round(d/20)),h=Math.round(d*.3),u=-Math.round(d*.05),{rL:m,rR:p}=e,b=e.outW/m.sw,w=oa(r),g=[],x=new Set,_=(T,v)=>{let S=Math.round((m.sy+v*m.sh)*c-f/2);if(S<0||S+f>l)return;let y=Math.round((m.sx+T*m.sw)*c-f/2),R=Math.round((p.sx+T*p.sw)*c-f/2);if(!x.has(`L${y},${S}`)){x.add(`L${y},${S}`);let I=Gi(o,w,a,l,y,S,f,u,h);I!==null&&g.push({d:I,x:y,y:S,eye:0})}if(!x.has(`R${R},${S}`)){x.add(`R${R},${S}`);let I=Gi(w,o,a,l,R,S,f,-h,-u);I!==null&&g.push({d:-I,x:R,y:S,eye:1})}},M=0,E=0,C=0;for(let[T,v]of Bn(t,i,n,s))T>=0&&T<=1&&v>=0&&v<=1&&(_(e.mirror?1-T:T,v),M+=T,E+=v,C++);if(!C)return null;let P=f/2/c/m.sw,D=f/2/c/m.sh;for(let[T,v]of[[-P,0],[P,0],[0,-D],[0,D]]){let S=M/C+T,y=E/C+v;S>=0&&S<=1&&y>=0&&y<=1&&_(e.mirror?1-S:S,y)}for(let T of g)T.d=(T.d/c-(m.sx-p.sx))*b;return Qn(g,Zn/c*b,f/2)}function oa(r){let e=Gn.get(r);if(e)return e;let{img:t,w:i,h:n}=r,s=i/2;e=new Uint8Array(i*n);for(let o=0;o<n;o++){let a=o*i;for(let l=0;l<s;l++)e[a+l]=t[a+s+l],e[a+s+l]=t[a+l]}return Gn.set(r,e),e}function Gi(r,e,t,i,n,s,o,a,l){let c=t/2;if(n<0||n+o>c)return null;let d=ge(r,t,i,n,s,o,o,{dMin:a,dMax:l,dyMax:2});if(!d||d.c<.8)return null;let f=Math.round(n-d.d),h=s+d.dy;if(f<0||f+o>c||h<0||h+o>i)return null;let u=ge(e,t,i,f,h,o,o,{dMin:-Math.ceil(d.d)-2,dMax:-Math.floor(d.d)+2,dyMax:1});return!u||u.c<.8||Math.abs(-u.d-d.d)>1?null:d.d}function Qn(r,e,t=0){let i=r.map(o=>typeof o=="number"?{d:o,x:0,y:0,eye:-1}:o);if(i.length<2)return null;let n=[...i].sort((o,a)=>a.d-o.d),s=(o,a)=>o.eye===-1||o.eye!==a.eye||Math.abs(o.x-a.x)+Math.abs(o.y-a.y)>=t;for(let o of n)for(let a of n)if(a!==o&&Math.abs(o.d-a.d)<=e&&s(o,a))return o.d;return null}function es(r,e,t){let i=t>0&&Number.isFinite(t)?t:Kn;return e>0?r/e/i:r/(1e3*i)}function ts(r,e,t,i=Ke.eyeSeparationM){return es(r,e,t)*i}function aa(r,e,t=Pt){return r===null||!Number.isFinite(r)||!(e>0)?0:-qi(t,!0,-r/e)*e||0}function is(r,e){let t=e>0?Math.max(.05263157894736842,1/e):.05263157894736842,i=`${r}:${Math.round(t*1e4)}`,n=At.get(i);return n||(At.size>64&&At.clear(),At.set(i,n=Ee(r,t))),n}function rs(r,e,t,i,n,s,o,a="arrow"){let l=n*t,c=is(a,o);for(let d of[0,1]){let f=d*e+i*e+(d===0?s/2:-s/2);r.save(),r.beginPath(),r.rect(d*e,0,e,t),r.clip(),ji(r,a,f,l,o,c),r.restore()}}function ns(r,e){if(!X||typeof OffscreenCanvas=="function"&&!(X instanceof OffscreenCanvas))try{typeof OffscreenCanvas=="function"?X=new OffscreenCanvas(1,1):globalThis.document&&document.createElement&&(X=document.createElement("canvas"))}catch{X=null}return!X||typeof X.getContext!="function"?null:(X.width<r&&(X.width=r),X.height<e&&(X.height=e),X.getContext("2d"))}function ss(r,e,t,i,n,s,o,a,l,c="arrow"){let d=n*t,f=is(c,o),h=[0,1].map(m=>{let p=m*e+i*e+(m===0?s/2:-s/2);return Ni(c,p,d,o,a,l,[1,1,1,1],[0,0,0,1],f)}),u=ns(Math.max(h[0].width,h[1].width),Math.max(h[0].height,h[1].height));if(!u||typeof u.putImageData!="function"||typeof ImageData!="function")return!1;for(let m of[0,1]){let p=h[m];u.putImageData(new ImageData(p.data,p.width,p.height),0,0),r.save(),r.beginPath(),r.rect(m*e,0,e,t),r.clip(),r.drawImage(u.canvas,0,0,p.width,p.height,p.x0,p.y0,p.width,p.height),r.restore()}return!0}function os(r,e,t,i,n,s,o,a,l,c){let d=o/19,f=Math.max(1,Math.round(a.width*d)),h=Math.max(1,Math.round(a.height*d)),u=ns(f+2*(Math.ceil(l)+2),h+2*(Math.ceil(l)+2));if(!u||typeof u.getImageData!="function"||typeof ImageData!="function")return!1;u.clearRect(0,0,u.canvas.width,u.canvas.height),u.drawImage(a.entry.image,0,0,f,h);let m=zi(u.getImageData(0,0,f,h).data,f,h,l,c);u.clearRect(0,0,u.canvas.width,u.canvas.height),u.putImageData(new ImageData(m.data,m.width,m.height),0,0);let p=n*t-a.hotspot[1]*d-m.pad;for(let b of[0,1]){let w=b*e+i*e+(b===0?s/2:-s/2)-a.hotspot[0]*d-m.pad;r.save(),r.beginPath(),r.rect(b*e,0,e,t),r.clip(),r.drawImage(u.canvas,0,0,m.width,m.height,Math.round(w),Math.round(p),m.width,m.height),r.restore()}return!0}var na,Yn,sa,Kn,Zn,Gn,At,X,Yi,Ji=le(()=>{"use strict";Ui();Bt();Ei();na=Xi,Yn=.06,sa=ee,Kn=.0254/96;Zn=1.5,Gn=new WeakMap;At=new Map;X=null;Yi=class{constructor(e,{height:t,pointerScope:i="window",soften:n,shape:s="auto",shapeFor:o=null}={}){this.pointer=new Ot(e,{scope:i}),this.shapes=new Xe(this.pointer,{shape:s,shapeFor:o}),this.soften=vt(n,"@displayxr/inline3d pair cursor"),this.height=t>0?t:null,this.filter={},this._luma=null,this._uv=null,this._content=null,this._metricsFor=null,this.metersPerCssPx=null,this.eyeSeparationM=Ke.eyeSeparationM,this.last=null,this.runtime=new Dt}get hovering(){return!!this.pointer.uv}draw(e,t,i,n){let s=this.runtime.bind(i&&i.handle),o=this.pointer.uv;if(!o)return this.idle();let[a,l]=o,c=this.height??this._osArrowFraction();(t!==this._luma||!this._uv||this._uv[0]!==a||this._uv[1]!==l)&&(this._content=Jn(t,i,a,l,c,i.outW/i.outH),this._luma=t,this._uv=o);let d=this.pointer.canvas.getBoundingClientRect?.();if(s)return this._drawRuntime(a,l,d,i);this._askMetrics(i.handle);let f=ts(i.outW,d&&d.width,this.metersPerCssPx,this.eyeSeparationM),h=this._content===null?null:-this._content/f,u=qi(Pt,h!==null,h),m=Vn(this.filter,Pt,u,n),p=Un(m,f),b=-m*f,w=null,g=null;if(p){let x=c*i.outH,_=globalThis.devicePixelRatio>0?globalThis.devicePixelRatio:1,M=d&&d.width>0?d.width*_/i.outW:1,E=d&&d.height>0?c*d.height*_:x,C=Xn(m,b*M,E,this.soften),P=this.shapes.pick({u:a,v:l,point:null},n*1e3);g=this.shapes.current,w={blurPx:C.blurPx,alpha:C.alpha,ghostPx:Math.abs(b*M),spritePx:E,radius:E>0?C.blurPx/E:0,soft:C.blurPx>0||C.alpha<1},P.kind==="image"?os(e,i.outW,i.outH,a,l,b,x,P,w.soft?w.radius*x:0,w.soft?C.alpha:1):P.kind==="shape"&&(!w.soft||!ss(e,i.outW,i.outH,a,l,b,x,w.radius,C.alpha,g))&&rs(e,i.outW,i.outH,a,l,b,x,g)}return this.pointer.hideCss(p),this.last={contentPx:this._content,targetPx:-u*f||0,disparityPx:p?b:0,filteredPx:b||0,drawn:p,pxPerBaseline:f,soften:w,shape:g},this.last}_drawRuntime(e,t,i,n){this.pointer.hideCss(!1),this.filter={};let s=globalThis.devicePixelRatio>0?globalThis.devicePixelRatio:1,o=i&&i.width>0&&n.outW>0?i.width*s/n.outW:null,a=this._content===null||o===null?null:-this._content*o;return this.runtime.report(e,t,a),this.last={contentPx:this._content,targetPx:0,disparityPx:0,filteredPx:0,drawn:!1,runtime:!0,runtimeDisparityPx:a,pxPerBaseline:null,soften:null,shape:null},this.last}_askMetrics(e){!e||e===this._metricsFor||typeof e.displayMetrics!="function"||(this._metricsFor=e,Promise.resolve().then(()=>e.displayMetrics()).then(t=>{this._metricsFor!==e||!t||(t.metersPerCssPx>0&&(this.metersPerCssPx=t.metersPerCssPx),t.eyeSeparationM>0&&(this.eyeSeparationM=t.eyeSeparationM))}).catch(()=>{}))}_osArrowFraction(){let e=this.pointer.canvas.getBoundingClientRect?.();return e&&e.height>0?$n(e.height):Yn}idle(){return this.runtime.withdraw(),this.pointer.hideCss(!1),this.filter={},this._uv=null,this.last=null,null}dispose(){this.runtime.dispose(),this.pointer.dispose(),this.shapes.dispose()}}});var De=Object.freeze({speaker:"high",other:"normal",hidden:"paused"}),As=["high","normal","low","paused"],Ls=.02,Is=1e3/20,Fs=3e3,Ns=1e3/28;function Ae(r){return typeof r=="function"?r:r===!1||r==="off"?"off":"auto"}function Wt(r=import.meta.url){return Oe?typeof Oe=="function"?Oe():Oe:new URL("../lift/index.js",r).href}var Oe=null;function gr(r){Oe=r||null}function js(){return import(Wt())}async function Ht(r,{importer:e=js,nav:t=globalThis.navigator,log:i=null,capsOpts:n={webFallback:!0}}={}){let s=(h,u)=>i&&i(h,u),o=(h,u={})=>(s("lift-unavailable",{reason:h,...u}),{lift:null,capabilities:null,caps:null,source:"none",reason:h}),a=Ae(r);if(a==="off")return{lift:null,capabilities:null,caps:null,source:"none",reason:"off"};if(typeof a=="function"){let h=typeof a.liftCapabilities=="function"?a.liftCapabilities:null;return{lift:a,capabilities:h,caps:null,source:"injected",reason:null}}let l;try{l=await e()}catch(h){return o("import-failed",{message:String(h&&h.message||h).slice(0,200)})}let c=l&&typeof l.lift=="function"?l.lift:null;if(!c)return o("no-lift-export");let d=typeof l.liftCapabilities=="function"?l.liftCapabilities:null,f=null;if(d){try{f=await d(n)}catch{f=null}let h=!!(f&&f.webFallback&&f.webFallback.webgpu);if(f&&!f.native&&!h)return o("no-provider",{native:!1,webgpu:!1})}else if(!(t&&t.gpu))return o("no-webgpu");return s("lift-ready",{native:!!(f&&f.native),provider:f&&f.provider||null}),{lift:c,capabilities:d,caps:f,source:"module",reason:null}}function Pe(r){let e=Number.isFinite(+r)&&r!==null?Math.max(-1,Math.min(1,+r)):0;return Math.abs(e)<Ls?"auto":Math.round((.5+.5*e)*1e3)/1e3}function Ye({id:r,speakerId:e,visible:t=!0}){return t?r!=null&&r===e?De.speaker:De.other:De.hidden}function $t(r,e){if(!r||!As.includes(e)||typeof r.setPriority!="function")return!1;try{return r.setPriority(e)!==!1}catch{return!1}}function Ut({degradedMs:r=Is,recoveredMs:e=Ns,holdMs:t=Fs,alpha:i=.1}={}){let n=null,s=0,o=!1;return{feed(a){if(!(a>0)||a>1e3)return null;if(n=n===null?a:n+i*(a-n),o){if(n<e)return o=!1,s=0,"recovered"}else if(s=n>r?s+a:0,s>=t)return o=!0,"degraded";return null},reset(){n=null,s=0,o=!1},get frameMs(){return n},get degraded(){return o}}}function Vt({lift:r,max:e=4,log:t=null,options:i=null}={}){let n=i&&typeof i=="object"?i:{},s=new Map,o=null,a=0,l=0,c=(h,u)=>t&&t(h,u),d=(h,u)=>{if(!u.handle)return;let m=Ye({id:h,speakerId:o,visible:u.visible});if(m===u.priority)return;u.priority=m;let p=$t(u.handle,m);c("lift-priority",{peer:h,priority:m,applied:p})},f={get size(){return s.size},get max(){return e},set max(h){e=Math.max(0,h|0)},has:h=>s.has(h),handle:h=>s.get(h)&&s.get(h).handle||null,priority:h=>s.get(h)&&s.get(h).priority||null,canAcquire:h=>s.has(h)||s.size<e,acquire(h,u,{wall:m,visible:p=!0,onError:b}={}){let w=s.get(h);if(w)return w.pending||Promise.resolve(w.handle);if(s.size>=e)return Promise.resolve(null);let g=++l,x=Ye({id:h,speakerId:o,visible:p}),_={gen:g,handle:null,visible:p,priority:x,pending:null};s.set(h,_);let M={quality:"auto",...n,mode:"live",wall:m,ui:"none",convergence:Pe(a),priority:x};return c("lift-acquire",{peer:h,priority:x,convergence:M.convergence}),_.pending=Promise.resolve().then(()=>r(u,M)).then(E=>{if(s.get(h)!==_||_.gen!==g){try{E&&E.remove&&E.remove()}catch{}return null}return _.pending=null,_.handle=E||null,_.priority=null,d(h,_),E&&typeof E.setConvergence=="function"&&E.setConvergence(Pe(a)),_.handle},E=>(s.get(h)===_&&s.delete(h),c("lift-failed",{peer:h,message:String(E&&E.message||E).slice(0,200)}),b&&b(E),null)),_.pending},release(h){let u=s.get(h);if(u){if(s.delete(h),u.handle)try{u.handle.remove()}catch{}c("lift-release",{peer:h})}},releaseAll(){for(let h of[...s.keys()])f.release(h)},setSpeaker(h){o=h===void 0?null:h;for(let[u,m]of s)d(u,m)},setVisible(h,u){let m=s.get(h);!m||m.visible===!!u||(m.visible=!!u,d(h,m))},setDepth(h){a=h;let u=Pe(h);for(let m of s.values())m.handle&&typeof m.handle.setConvergence=="function"&&m.handle.setConvergence(u);return u},get anyWeb(){for(let h of s.values())if(h.handle&&!h.handle.native)return!0;return!1},list(){return[...s].map(([h,u])=>({id:h,priority:u.priority,pending:!!u.pending,native:!!(u.handle&&u.handle.native)}))}};return f}var Ws=null;function _r(r){Ws=typeof r=="function"?r:null}var Hs=new WeakMap;function vr(r,e){r&&(typeof r=="object"||typeof r=="function")&&Hs.set(r,e)}Bt();var Ua=Object.freeze(["shibata","percival"]);var $s="[inline3d] camera rig with convergenceDiopters 0: convergence at infinity puts the whole scene in front of the glass; set convergence to the subject's distance.",Us=new WeakSet;function Vs(r){let e=[];return!r||typeof r!="object"||(r.type==="camera"?(r.convergenceDiopters>0||e.push(["convergence",$s]),r.verticalFov>Math.PI&&e.push(["fov",`[inline3d] camera rig verticalFov ${r.verticalFov} is more than \u03C0: it looks like DEGREES \u2014 the descriptor takes RADIANS (cameraRigFromCamera / cameraRigFromPose convert three's degrees for you).`])):(r.ipdFactor>1||r.parallaxFactor>1)&&e.push(["factor",`[inline3d] display rig ipdFactor ${r.ipdFactor??1} / parallaxFactor ${r.parallaxFactor??1}: above 1 exaggerates depth past what the display shows by construction (1 = correct; below 1 = a comfort dial). Sent as given.`])),e}function Xt(r,e){if(!(!e||typeof e!="object")&&!(e.type==="camera"?e.convergenceDiopters>0&&!(e.verticalFov>Math.PI):!(e.ipdFactor>1||e.parallaxFactor>1)))for(let[t,i]of Vs(e))r.has(t)||(r.add(t),!(t==="convergence"&&Us.has(e))&&console.warn(i))}function wr(r){let e=String(r||"");return e.startsWith("cross-pass")?"the canvas is inside its own render surface: a CSS effect on it or an ancestor (filter, opacity < 1, mask, clip-path, mix-blend-mode, backdrop-filter). Remove it (woven-canvas rule 7)":e==="no-quad"?"the canvas drew nothing the compositor can see: it is not drawing, is occluded, or a CSS effect on it or an ancestor (filter, opacity < 1, mask, clip-path, mix-blend-mode, backdrop-filter) hides it (woven-canvas rule 7)":e==="no-identity"?"the canvas reached the browser without its identity: register it once, keep it mounted, cover it until firstWoven (woven-canvas rules 3-5)":e==="no-join"?"nothing joined this rect; harmless off screen, otherwise check the canvas is drawing and on screen":e==="resolve-dropped"?"the browser could not resolve the canvas's GPU resource (a browser-side issue)":"see docs/woven-canvas-rules.md \xA73"}var br=new WeakMap,Q;function xr(r){let e=null;for(let[t,i]of r)i>0&&(!e||i<e[1])&&(e=[t,i]);return e}function Bs(r){if(!r||typeof r.getParameter!="function")return null;let e=br.get(r);if(e)return e;let t,i,n;try{t=r.getParameter(r.MAX_TEXTURE_SIZE??3379),i=r.getParameter(r.MAX_RENDERBUFFER_SIZE??34024),n=r.getParameter(r.MAX_VIEWPORT_DIMS??3386)}catch{return null}let s=n&&n.length>=2?n[0]:0,o=n&&n.length>=2?n[1]:0,a=xr([["MAX_TEXTURE_SIZE",t],["MAX_RENDERBUFFER_SIZE",i],["MAX_VIEWPORT_DIMS",s]]),l=xr([["MAX_TEXTURE_SIZE",t],["MAX_RENDERBUFFER_SIZE",i],["MAX_VIEWPORT_DIMS",o]]);if(!a||!l)return null;let c={maxW:a[1],maxH:l[1],nameW:a[0],nameH:l[0],valueW:a[1],valueH:l[1]};return br.set(r,c),c}function Sr(){if(Q!==void 0)return Q;Q=null;try{if(typeof document>"u"||!document||typeof document.createElement!="function")return Q;let r=document.createElement("canvas"),e=r.getContext("webgl2")||r.getContext("webgl");if(!e)return Q;Q=Bs(e),e.getExtension?.("WEBGL_lose_context")?.loseContext?.()}catch{Q=null}return Q}function Mr(r,e,t,{cols:i=2,rows:n=1}={}){let s=r*i,o=e*n,a={eyeW:r,eyeH:e,cols:i,scale:1,clamped:!1,reqW:s,reqH:o,bufW:s,bufH:o,limitName:"",limitValue:0};if(!t||!(r>0)||!(e>0))return a;let l=t.maxW/s,c=t.maxH/o,d=Math.min(l,c);if(!(d<1))return a;let f=l<=c,h=Math.max(1,Math.min(Math.floor(r*d+1e-9),Math.floor(t.maxW/i))),u=Math.max(1,Math.min(Math.floor(e*d+1e-9),Math.floor(t.maxH/n)));return{eyeW:h,eyeH:u,cols:i,scale:d,clamped:!0,reqW:s,reqH:o,bufW:h*i,bufH:u*n,limitName:f?t.nameW:t.nameH,limitValue:f?t.valueW:t.valueH}}function qt(r){return Math.round(r*1e3)/1e3}function Er(r,e,t){let i=typeof t=="number"?` (renderScale ${qt(t)} \u2192 ${qt(t*e.scale)})`:` (scale ${qt(e.scale)})`;return`${r} ${e.cols===1?"buffer":"SBS buffer"} ${e.reqW}\xD7${e.reqH} exceeds ${e.limitName} ${e.limitValue} on this device; rendering at ${e.bufW}\xD7${e.bufH}${i}.`}function Rr(r,e){let t=r?.width||0,i=r?.height||0,n=e&&e.drawingBufferWidth>0?e.drawingBufferWidth:t,s=e&&e.drawingBufferHeight>0?e.drawingBufferHeight:i,o=t>0?n/t:1,a=i>0?s/i:1;return{sx:o,sy:a,w:n,h:s,mismatch:o!==1||a!==1}}function Cr(r,e,t,i="laying the eyes out from the drawing buffer. Lower renderScale to stay inside the device limit."){return`${r} the browser clamped this canvas's drawing buffer to ${t.w}\xD7${t.h} (canvas.width/height say ${e.width}\xD7${e.height}); ${i}`}var he="smoothstep",Yt=["linear","smoothstep","easeoutcubic"];function Kt(r){if(typeof r!="string")return null;let e=r.toLowerCase().replace(/[-_\s]/g,"");return Yt.includes(e)?e:null}function Xs(r,e){if(e<=0)return 0;if(e>=1)return 1;if(r==="linear")return e;if(r==="easeoutcubic"){let t=1-e;return 1-t*t*t}return e*e*(3-2*e)}var ce="idle",kr="rampDownThenFire",Gt="fireThenRampUp",Je=class{constructor(e,t){this._phase=ce,this._targetMode=null,this._firePending=!1,this._fireAtEnd=!1,this._from=0,this._to=0,this._cur=0,this._t=1,this._dur=180/1e3,this._easing=he,(e!==void 0||t!==void 0)&&this.configure(e,t)}configure(e,t){if(e!==void 0){let i=Number(e);this._dur=Number.isFinite(i)&&i>0?i:0}return t!==void 0&&(this._easing=Kt(t)||he),this}get durationS(){return this._dur}get easing(){return this._easing}request({targetMode:e=null,targetViewCount:t,currentMode:i=null,currentViewCount:n,current:s,steady:o=1}={}){let a=!(t>1),l=!(n>1),c=Number.isFinite(o)?o:1,d=Number.isFinite(s)?s:c;return this._targetMode=e,this._from=d,a&&!l?(this._phase=kr,this._to=0,this._fireAtEnd=!0,this._firePending=!1):!a&&l?(this._phase=Gt,this._from=0,this._to=c,this._firePending=!0,this._fireAtEnd=!1):(this._phase=Gt,this._to=a?d:c,this._firePending=!(e!==null&&e===i),this._fireAtEnd=!1),this._t=this._dur>0?0:1,this._cur=this._from,this}update(e){let t=!1;if(this._phase!==ce){let i=Number.isFinite(e)&&e>0?e:0;this._t<1&&this._dur>0?(this._t+=i/this._dur,this._t>1&&(this._t=1)):this._t=1,this._cur=this._from+(this._to-this._from)*Xs(this._easing,this._t),this._phase===Gt?(this._firePending&&(this._firePending=!1,t=!0),this._t>=1&&(this._phase=ce)):this._t>=1&&(this._fireAtEnd&&(this._fireAtEnd=!1,t=!0),this._phase=ce)}return{factor:this._cur,fire:t,mode:this._targetMode}}active(){return this._phase!==ce}value(){return this._cur}firePending(){return this._phase===kr?this._fireAtEnd:this._firePending}cancel(){return this._phase=ce,this._firePending=!1,this._fireAtEnd=!1,this._t=1,this}};var Y=null;_r(r=>{let e=Y;if(!e||!e._running||!r)return null;let t=i=>({layer:i.layer,session:e.session});for(let i of e._windows.values())if(i.canvas===r&&i.layer)return t(i);for(let i of e._windows.values())if(i.layer&&typeof r.contains=="function"&&r.contains(i.canvas))return t(i);for(let i of e._windows.values()){let n=i.canvas.parentElement;if(i.layer&&n&&typeof n.contains=="function"&&n.contains(r))return t(i)}return null});var qs=()=>typeof navigator<"u"&&!!navigator.xr,ne=()=>typeof window<"u"&&typeof window.XRDisplayLayer=="function",Ze=()=>ne()&&"excludeElement"in window.XRDisplayLayer.prototype,Jt=()=>{if(!ne())return!1;try{return"setViewRig"in window.XRDisplayLayer.prototype}catch{return!1}},Gs=["getDisplayInfo","getRenderingModes","requestRenderingMode"],zr=["renderingmodechange","hardwaredisplaystatechange"],oi="trackingstatechange",Wr=["unknown","tracking","searching"],Or=[...zr,oi];function Qe(r){try{let e=r?r.trackingState:void 0;return Wr.includes(e)?e:null}catch{return null}}var Zt=()=>{if(!ne())return!1;try{let r=window.XRDisplayLayer.prototype;return Gs.every(e=>typeof r[e]=="function")}catch{return!1}},Qt=()=>{if(!ne())return!1;try{return typeof window.XRDisplayLayer.prototype.undock=="function"}catch{return!1}},de=null;function ue(){if(de!==null)return de;if(!ne())return!1;try{let r=window.XRDisplayLayer.occlusionByDrawOrder;if(typeof r=="boolean")return de=r}catch{}return!1}function Ys(r){if(de!==null)return de;if(!r||!ne()||!("occlusionByDrawOrder"in window.XRDisplayLayer.prototype))return null;try{return de=!!r.occlusionByDrawOrder}catch{return null}}var Dr=!1;function ei(){Dr||(Dr=!0,console.info("[inline3d] This browser composites 2D over woven 3D automatically, per-pixel by draw order \u2014 overlay exclusion is obsolete here, so exclude()/addGlobalOverlay()/data-inline3d-overlay/autoChrome are accepted and ignored. Your 2D chrome already occludes the tiles correctly. The calls are harmless (keep them if you also ship to older DisplayXR Browsers); gate on inline3dOcclusionByDrawOrder() to drop them."))}function Hr(){return qs()&&ne()}function ti(r){return{type:"display",position:{x:0,y:0,z:0},orientation:{x:0,y:0,z:0,w:1},virtualDisplayHeight:r.virtualDisplayHeight>0?r.virtualDisplayHeight:.24,ipdFactor:1,parallaxFactor:1,perspectiveFactor:1}}function Ks(r,e){let t=Number.isFinite(r.ipdFactor)?r.ipdFactor:1,i=Number.isFinite(r.parallaxFactor)?r.parallaxFactor:1;return{...r,ipdFactor:t*e,parallaxFactor:i*e}}var Js=16;function W(){return typeof performance<"u"&&performance&&typeof performance.now=="function"?performance.now():Date.now()}var ai=1200,Zs=new Set(["pending","woven","withheld"]),Pr=3,Qs=new Set(["getDisplayInfo","getRenderingModes","requestRenderingMode"]),eo=new Set(["getDisplayInfo","getRenderingModes"]);function to(r){return r==null||Array.isArray(r)&&r.length===0}function ii(){try{let r=typeof XRDisplayLayer=="function"?XRDisplayLayer:null;return!!(r&&r.prototype&&"wovenState"in r.prototype)}catch{return!1}}function et(r){try{let e=r?r.wovenState:null;return Zs.has(e)?e:null}catch{return null}}function ri(r){try{let e=r?r.withheldReason:null;return typeof e=="string"&&e?e:null}catch{return null}}var Ar=!1;function io(r){if(r==null)return he;let e=Kt(r);return e||(Ar||(Ar=!0,console.warn(`[inline3d] createInline3D({ modeSwitch: { easing: ${JSON.stringify(r)} } }) is not a curve this SDK knows (${Yt.join(" / ")}); using '${he}'.`)),he)}var Lr=!1;function ro(){Lr||(Lr=!0,console.info("[inline3d] The active rendering mode is 1-view, so this SDK has zeroed every window rig (ipdFactor/parallaxFactor -> 0) \u2014 both eyes now render from one place. The runtime keeps weaving the same two-view atlas whatever the page submits, so leaving stereo in it would put two slightly different images on a flat panel, i.e. a blurry double image instead of 2D. Your rendering is unchanged; the flattening is a copy applied on the way to the layer and it is undone the moment a 2-view mode goes active again."))}function li(r){return r&&r.detail!==void 0&&r.detail!==null?r.detail:void 0}function $r(r){let e=li(r);return e!==void 0?[e,r]:[r]}function no(r){for(let e of $r(r)){if(typeof e=="number"&&Number.isFinite(e))return e;if(e&&typeof e=="object"){let t=e.modeIndex!==void 0?e.modeIndex:e.mode;if(typeof t=="number"&&Number.isFinite(t))return t}}return-1}function so(r){for(let e of $r(r)){if(e==="2d"||e==="3d")return e;if(e&&typeof e=="object"){let t=e.state!==void 0?e.state:e.hardwareDisplayState;if(t==="2d"||t==="3d")return t}}return null}var Ir=!1;function oo(){Ir||(Ir=!0,console.warn("[inline3d] This browser has no XRDisplayLayer.setViewRig, so the view rig was ignored (the window still weaves \u2014 the runtime keeps the default display rig, scaled by virtualDisplayHeight). Gate on inline3dViewRigSupported() if your page's framing depends on the rig; further calls are silent."))}var Fr=!1;function ao(){Fr||(Fr=!0,console.warn("[inline3d] addScene got BOTH viewRig and virtualDisplayHeight; on a browser with rig support the rig wins and the height is dropped. They describe the same slot \u2014 virtualDisplayHeight is shorthand for exactly one rig (display, identity pose, all factors 1) \u2014 so there is no merge. This is only worth passing as a PAIR deliberately: the height is what a browser without setViewRig will use, so a camera-rig scene can name its own fallback framing. Otherwise say it once, inside the rig."))}async function Ur(r={}){let{referenceSpace:e="viewer",lazy:t=!0,rootMargin:i="50% 0px",autoChrome:n=!0,modeSwitch:s=null,untrackedFallback:o="none",viewerEase:a}=r;if(!Hr())return{supported:!1,trackingState:"unknown"};let l;try{l=await navigator.xr.requestSession("inline-3d")}catch(d){return{supported:!1,trackingState:"unknown",error:d}}a!==void 0&&vr(l,a);let c=null;try{c=await l.requestReferenceSpace(e)}catch{}return new ci(l,c,{lazy:t,rootMargin:i,autoChrome:n,modeSwitch:s,untrackedFallback:o})}var Le=null;function it(r={}){return Y&&Y._running?Promise.resolve(Y):Le||(Le=Ur(r).finally(()=>{Le=null}),Le)}var Nr=.7,lo=new Set(["IMG","SVG","VIDEO","CANVAS","BUTTON","INPUT","SELECT","TEXTAREA"]);function co(r){let e=[],t=document.createTreeWalker(r,NodeFilter.SHOW_ELEMENT);for(let i=t.nextNode();i;i=t.nextNode())if(!i.closest("[data-inline3d-no-overlay]")){if(lo.has(i.tagName.toUpperCase())){e.push(i);continue}for(let n of i.childNodes)if(n.nodeType===Node.TEXT_NODE&&n.nodeValue.trim()){e.push(i);break}}return e}var ni=4;function si(r){let e=typeof window<"u"&&window.devicePixelRatio||1,t="";if(typeof r.getBoundingClientRect=="function"){let i=r.getBoundingClientRect()||{},n=typeof window<"u"&&window.scrollX||0,s=typeof window<"u"&&window.scrollY||0;t=`+${Math.round((i.left??i.x??0)+n)},${Math.round((i.top??i.y??0)+s)}`}return`${r.clientWidth}x${r.clientHeight}@${e}${t}`}function jr(r){let e=typeof window<"u"&&window.devicePixelRatio||1;return{width:r.clientWidth||0,height:r.clientHeight||0,dpr:e}}function ho(r){if(r==null||r===!1||r==="off")return null;if(r==="auto"||r===!0)return{color:"#000",snapshot:!0};if(typeof r=="object"){if(r.color!==void 0&&typeof r.color!="string")throw new TypeError("[inline3d] rectCover.color must be a CSS color string.");return{color:r.color||"#000",snapshot:r.snapshot!==!1}}throw new TypeError(`[inline3d] rectCover: expected 'auto', 'off' or { color?, snapshot? }; got ${JSON.stringify(r)}.`)}var ci=class{constructor(e,t,{lazy:i,rootMargin:n,autoChrome:s=!0,modeSwitch:o=null,untrackedFallback:a="none"}){this.supported=!0,this.session=e,this.refSpace=t,this._windows=new Map,this._claims=new Map,this._doubleWarned=new WeakSet,this._globalOverlays=new Set,this._isolatedBy=new WeakMap,this._autoChrome=s,this._autoChromeEls=new Set,this._lastChromeScan=0,this._fullTileWarned=new WeakSet,this._stoodDown=!1,this._activeModeIndex=-1,this._activeViewCount=0,this._hardwareDisplayState=null,this._modes=null,this._stereoCollapsed=!1,this._displayListeners=new Map,this._primedDisplayState=!1;let l=o&&typeof o=="object"?o:{};this._msEnabled=l.enabled!==!1,this._modeSwitch=new Je((Number.isFinite(l.durationMs)?Math.max(0,l.durationMs):180)/1e3,io(l.easing)),this._stereoFactor=1,this._msFire=null,this._msArmedUp=!1,this._msLastMs=null,this._msTick=null,this._trackingSupported=Qe(e)!==null,this._trackingState=this._trackingSupported?Qe(e):"unknown",this._untrackedFallback=a==="mono"?"mono":"none",this._bakedStereo=1,this._bakedTarget=1,this._bakedAt=null,this._bakedEaseS=(Number.isFinite(l.durationMs)?Math.max(0,l.durationMs):180)/1e3,this._applyUntrackedTarget(),this.undock=Qt()?{model:!1,splat:!1}:null,this._undockRead=!1,this._running=!0,this._lazy=i,this._observer=i&&typeof IntersectionObserver=="function"?new IntersectionObserver(c=>this._onIntersect(c),{rootMargin:n}):null,this._loopId=0,this._framePending=!1,this._frameCount=0,this._frameWatchdog=null,this._suspended=null,Y&&Y._running&&Y!==this&&console.warn("[inline3d] A second inline-3D session is live in this document. The browser's element-rect channel is a whole-widget setter, so both managers clobber each other's rect list every frame \u2014 tiles may flicker, ghost, or weave at a stale rect. Use ONE createInline3D() per document and add every window to it; if you are switching views, close() the previous manager first."),Y=this,e.addEventListener("end",()=>this._teardown()),this._bindDisplayEvents(),this._bindTrackingEvents(),this._scanChrome(),this._bindLifecycle(),this._armDprWatch(),this._requestFrame()}get liveCount(){let e=0;for(let t of this._windows.values())t.layer&&e++;return e}addGlobalOverlay(e){if(!(!e||this._globalOverlays.has(e))){ue()&&ei(),this._globalOverlays.add(e);for(let t of this._windows.values())t.layer&&this._applyExclusion(t,e)}}removeGlobalOverlay(e){if(!(!e||!this._globalOverlays.delete(e)))for(let t of this._windows.values())t.layer&&this._dropExclusion(t,e)}_scanChrome(){if(ue()||!this._autoChrome||!Ze()||typeof document>"u")return;let e=Date.now();if(e-this._lastChromeScan<1e3)return;this._lastChromeScan=e;let t=document.body;if(!t)return;let i=new Set,n=t.querySelectorAll(":scope > *, :scope > * > *, :scope > * > * > *");for(let s of n){if(s.closest("[data-inline3d-no-overlay]"))continue;let o=getComputedStyle(s).position;if(o!=="fixed"&&o!=="sticky")continue;let a=!1;for(let l of this._windows.keys())if(s===l||s.contains(l)){a=!0;break}if(!a){i.add(s);for(let l of co(s))i.add(l)}}for(let s of this._autoChromeEls){let o=!1;if(s.isConnected){for(let a of this._windows.keys())if(s===a||s.contains(a)){o=!0;break}}(!s.isConnected||o)&&(this._autoChromeEls.delete(s),this.removeGlobalOverlay(s))}for(let s of i)this._globalOverlays.has(s)||(this._autoChromeEls.add(s),this.addGlobalOverlay(s))}addImage(e,t,i={}){this._warnDoubleAttach(e,"addImage",i._dxrClaim);let n=this._register(e,"image",i);return n.method="addImage",n.ready=fo(t).then(s=>{n.img=s,n.repaint()}),this._handle(e,n)}addVideo(e,t,i={}){this._warnDoubleAttach(e,"addVideo",i._dxrClaim);let n=this._register(e,"video",i);return n.method="addVideo",n.video=t,this._handle(e,n)}addScene(e,t,i={}){this._warnDoubleAttach(e,"addScene",i._dxrClaim),i.viewRig&&i.virtualDisplayHeight!==void 0&&ao();let n=this._register(e,"scene",{virtualDisplayHeight:.24,...i});return n.method="addScene",n.onFrame=t,n.ownsBuffer=!1,i.bufferClamped===!0&&(n.warnedBufMismatch=!0),this._handle(e,n)}_liveRegistration(e,t){let i=this._claims.get(e);if(i&&i.token!==t)return i.method;let n=this._windows.get(e);return n?n.method||"add*":null}_warnDoubleAttach(e,t,i){let n=this._liveRegistration(e,i);!n||this._doubleWarned.has(e)||(this._doubleWarned.add(e),console.warn(`[inline3d] ${t}() on a canvas that is already registered on this inline-3D session (by ${n}(), not yet removed). This call is rebuilding the canvas's layer (a fresh 0.4-1.2 s identity gap) or putting a second renderer on its context. Change what is IN the canvas instead (setSource, your onFrame, a redrawn source canvas), or call handle.remove() on the first registration first. (Warned once per canvas.)`,e))}_attachGuard(e,t,i={}){let n=this._claims.get(e);if(i&&i._dxrClaim&&n&&n.token===i._dxrClaim)return{opts:i,own:()=>{}};this._warnDoubleAttach(e,t,null);let s={};return{opts:{...i,_dxrClaim:s},own:o=>this._claim(e,t,o,s)}}_claim(e,t,i,n){if(!this._running||!i||typeof i!="object")return;let s={token:n,method:t};this._claims.set(e,s);let o=i.remove,a=(...l)=>(this._claims.get(e)===s&&this._claims.delete(e),typeof o=="function"?o.apply(i,l):void 0);Object.defineProperty(i,"remove",{configurable:!0,enumerable:!0,get:()=>a,set:l=>{o=l}})}_handle(e,t){let i=this;return{remove:()=>this._remove(e),exclude:n=>{n&&(ue()&&ei(),t.excluded.add(n),this._applyExclusion(t,n))},unexclude:n=>{!n||!t.excluded.delete(n)||this._dropExclusion(t,n)},get trackingState(){return i._trackingState},setViewRig:n=>(t.viewRig=n||null,n&&Xt(t.rigWarned,n),this._pushViewRig(t)),setCursorDepth:n=>{let s=t.layer;if(!s||typeof s.setCursorDepth!="function")return!1;try{return n?s.setCursorDepth(n):s.setCursorDepth(),!0}catch{return!1}},getCursorDepthSupport:()=>{let n=t.layer;if(!n||typeof n.getCursorDepthSupport!="function")return Promise.resolve("none");try{return Promise.resolve(n.getCursorDepthSupport()).then(s=>s==="runtime"?"runtime":"none",()=>"none")}catch{return Promise.resolve("none")}},getDisplayInfo:()=>this._layerCall(t,"getDisplayInfo","getDisplayInfo()"),displayMetrics:async()=>{let n=null;try{n=await this._layerCall(t,"getDisplayInfo","getDisplayInfo()")}catch{}return yr(n,e.getBoundingClientRect(),globalThis.devicePixelRatio||1)},getRenderingModes:()=>this._getRenderingModes(t),requestRenderingMode:n=>this._requestRenderingModeEased(n,t),setStereoEnabled:n=>this._setStereoEnabled(n,t),on:(n,s)=>this.on(n,s),off:(n,s)=>this.off(n,s),onDisplayModeChange:n=>this._onDisplayModeChange(n),stats:()=>({frames:t.frames,monoFrames:t.monoFrames}),get wovenState(){return ii()?t.layer?et(t.layer):"pending":null},get withheldReason(){return!ii()||!t.layer?null:et(t.layer)==="withheld"?ri(t.layer):null},get firstWoven(){return t.fwPromise},onFirstWoven:n=>{if(typeof n!="function")throw new TypeError("[inline3d] onFirstWoven() takes a function.");let s=!0;return t.fwPromise.then(o=>{if(s)try{n(o)}catch(a){console.error("[inline3d] onFirstWoven callback threw",a)}}),()=>{s=!1}},rewoven:()=>this._rewoven(t)}}getDisplayInfo(){return this._layerCall(this._liveWindow(null),"getDisplayInfo","getDisplayInfo()")}getRenderingModes(){return this._getRenderingModes(null)}requestRenderingMode(e){return this._requestRenderingModeEased(e,null)}setStereoEnabled(e){return this._setStereoEnabled(e,null)}get trackingState(){return this._trackingState}get hardwareDisplayState(){return this._hardwareDisplayState}get activeMode(){return{modeIndex:this._activeModeIndex,viewCount:this._activeViewCount}}get stereoCollapsed(){return this._stereoCollapsed}get modeSwitch(){return{active:this._msTransitionActive(),factor:this._stereoFactor}}close(){try{this.session.end()}catch{}this._teardown()}_effectiveViewRig(e){return this._stereoFactor>=1?e.viewRig||(e.stereoSynthRig?ti(e):null):(e.viewRig||(e.stereoSynthRig=!0),Ks(e.viewRig||ti(e),this._stereoFactor))}_setStereoCollapsed(e){let t=!!e;if(this._stereoCollapsed!==t){this._stereoCollapsed=t,t&&ro(),!t&&this._msArmedUp?(this._msArmedUp=!1,this._startUpRamp()):this._modeSwitch.active()||(this._stereoFactor=t?0:1);for(let i of this._windows.values()){if(t){let n=i.viewRig||ti(i);i.stereoSaved={ipdFactor:n.ipdFactor,parallaxFactor:n.parallaxFactor}}else i.stereoSaved=null;this._pushViewRig(i)}}}_pushViewRig(e){if(!Jt())return oo(),!1;if(!e.layer)return!1;let t=this._effectiveViewRig(e);try{return e.layer.setViewRig(t),!0}catch{return!1}}_layerCall(e,t,i,n=[]){if(!Zt())return Promise.reject(new Error(`[inline3d] ${i} needs a DisplayXR Browser with the display-mode API (XRDisplayLayer.getDisplayInfo/getRenderingModes/requestRenderingMode). Gate on inline3dDisplayModesSupported().`));if(!e||!e.layer)return Promise.reject(new Error(`[inline3d] ${i} needs a live weave layer, and this window has none right now (lazy mode closes the layer while the tile is off screen). Call it once the tile is visible, or create the manager with { lazy: false }.`));if(Qs.has(t)&&!e.layerFramed&&this._layerReadPending(e))return this._whenLayerFramed(e).then(()=>this._layerCall(e,t,i,n));let o;try{o=Promise.resolve(e.layer[t](...n))}catch(l){return Promise.reject(l)}if(!eo.has(t)||!this._layerReadPending(e))return o;let a=e.layer;return o.then(l=>e.layer!==a?l:to(l)?this._layerReadPending(e)?this._whenLayerFramed(e).then(()=>this._layerCall(e,t,i,n)):l:(e.lfAnswered=!0,l))}_layerFramedCap(e){return ni*Math.max(e.fwHoldMs,ai)}_layerReadPending(e){return!e.layer||e.lfAnswered||e.lfCapped?!1:W()-e.lfAt>=this._layerFramedCap(e)?(e.lfCapped=!0,!1):!0}_whenLayerFramed(e){return new Promise(t=>{let i=e.layer,n={resolve:t,timer:null},s=Math.max(0,this._layerFramedCap(e)-(W()-e.lfAt));n.timer=setTimeout(()=>{let o=e.framedWaiters.indexOf(n);o>=0&&e.framedWaiters.splice(o,1),e.layer===i&&(e.lfCapped=!0),t()},s),n.timer&&typeof n.timer.unref=="function"&&n.timer.unref(),e.framedWaiters.push(n)})}_tickLayerFramed(e){let t=e.wsLive?et(e.layer):null;(t?t==="woven":e.lfStereo)?this._noteLayerFramed(e,!0):e.framedWaiters.length&&!this._layerReadPending(e)&&this._noteLayerFramed(e,!1)}_noteLayerFramed(e,t=!0){t&&(e.layerFramed=!0);let i=e.framedWaiters.splice(0);for(let n of i)clearTimeout(n.timer),n.resolve()}_liveWindow(e){if(e&&e.layer)return e;for(let t of this._windows.values())if(t.layer)return t;return e||null}async _getRenderingModes(e){let t=await this._layerCall(this._liveWindow(e),"getRenderingModes","getRenderingModes()"),i=Array.isArray(t)?t:[];this._modes=i;let n=i.find(s=>s.isActive);return n&&(this._activeModeIndex=n.modeIndex,this._activeViewCount=n.viewCount,(n.viewCount===1||n.viewCount===2)&&this._setStereoCollapsed(n.viewCount===1)),this._primedDisplayState=!0,t}_requestRenderingMode(e,t){return this._layerCall(this._liveWindow(t),"requestRenderingMode","requestRenderingMode()",[e])}_msTransitionActive(){return this._modeSwitch.active()||this._msArmedUp||this._msFire!==null}async _requestRenderingModeEased(e,t){if(!this._msEnabled||!Jt())return this._requestRenderingMode(e,t);let i=this._modes;if(!Array.isArray(i)||i.length===0)try{i=await this._getRenderingModes(t)}catch{i=null}let n=(Array.isArray(i)?i:[]).find(a=>a&&a.modeIndex===e),s=n&&Number.isFinite(n.viewCount)?n.viewCount:0,o=this._activeViewCount;return s<1||s>2||o<1?this._requestRenderingMode(e,t):s===1?o===1?this._requestRenderingMode(e,t):this._rampDownThenRequest(e,t):this._requestThenRampUp(e,t)}_rampDownThenRequest(e,t){if(this._msFire&&this._msFire.modeIndex===e)return this._msFire.promise;this._settlePendingDown("superseded",`a request for mode ${e} replaced it`);let i={modeIndex:e,win:t,resolve:null,reject:null,promise:null};return i.promise=new Promise((n,s)=>{i.resolve=n,i.reject=s}),this._msFire=i,this._modeSwitch.request({targetMode:e,targetViewCount:1,currentMode:this._activeModeIndex,currentViewCount:this._activeViewCount,current:this._stereoFactor,steady:1}),this._msLastMs=W(),this._armModeSwitchTick(),i.promise}_requestThenRampUp(e,t){let n=this._msFire!==null&&e===this._activeModeIndex;this._settlePendingDown("superseded",`a request for mode ${e} reversed it`);let s=n?Promise.resolve(void 0):this._requestRenderingMode(e,t);return this._stereoFactor<1&&(this._stereoCollapsed?(this._msArmedUp=!0,this._modeSwitch.cancel(),this._stereoFactor=0):this._startUpRamp()),s.catch(o=>{throw this._msArmedUp&&(this._msArmedUp=!1,this._modeSwitch.active()||(this._stereoFactor=this._stereoCollapsed?0:1)),o})}_startUpRamp(){this._settlePendingDown("superseded","the display returned to 3D"),this._modeSwitch.request({targetMode:this._activeModeIndex,targetViewCount:2,currentMode:this._activeModeIndex,currentViewCount:2,current:this._stereoFactor,steady:1}),this._msLastMs=W(),this._armModeSwitchTick()}_settlePendingDown(e,t){let i=this._msFire;if(!i)return;this._msFire=null;let n=new Error(`[inline3d] the request for rendering mode ${i.modeIndex} was never forwarded: ${t}. A ->2D switch is held until the disparity has ramped out, so a request that is reversed or replaced in that window is dropped rather than fired late.`);n.name=e,i.reject(n)}_advanceModeSwitch(){if(!this._modeSwitch.active()){this._msLastMs=null,this._disarmModeSwitchTick();return}let e=W(),t=typeof this._msLastMs=="number"?Math.max(0,(e-this._msLastMs)/1e3):0;this._msLastMs=e;let i=this._modeSwitch.update(t);if(i.factor!==this._stereoFactor){this._stereoFactor=i.factor;for(let n of this._windows.values())this._pushViewRig(n)}if(i.fire&&this._msFire){let n=this._msFire;this._msFire=null,this._requestRenderingMode(n.modeIndex,n.win).then(s=>n.resolve(s),s=>{this._startUpRamp(),n.reject(s)})}this._modeSwitch.active()||(this._msLastMs=null,this._disarmModeSwitchTick())}_armModeSwitchTick(){this._msTick!==null||typeof setTimeout!="function"||(this._msTick=setTimeout(()=>{this._msTick=null,this._running&&(this._advanceModeSwitch(),this._modeSwitch.active()&&this._armModeSwitchTick())},Js))}_disarmModeSwitchTick(){this._msTick!==null&&(typeof clearTimeout=="function"&&clearTimeout(this._msTick),this._msTick=null)}async _setStereoEnabled(e,t){let i=e?2:1,n=await this._getRenderingModes(t),s=Array.isArray(n)?n:[],o=s.find(a=>a.viewCount===i&&a.isRequestable);if(!o)throw new Error(`[inline3d] setStereoEnabled(${!!e}) found no requestable ${i}-view mode on this display (${s.length} mode(s) listed). It is sugar over requestRenderingMode() and cannot invent one \u2014 read getRenderingModes() and drive the list yourself.`);return o.isActive&&!this._msTransitionActive()||await this._requestRenderingModeEased(o.modeIndex,t),!!e}_bindDisplayEvents(){let e=this.session;!e||typeof e.addEventListener!="function"||Zt()&&(e.addEventListener("renderingmodechange",t=>{this._onRenderingModeChange(t).catch(()=>{})}),e.addEventListener("hardwaredisplaystatechange",t=>{this._onHardwareDisplayStateChange(t).catch(()=>{})}))}_onHardwareDisplayStateChange(e){let t=so(e),i=li(e),n=a=>{a&&(this._hardwareDisplayState=a),this._emitDisplay({type:"hardwaredisplaystatechange",state:a||this._hardwareDisplayState,detail:i})};t&&n(t);let s=this._activeModeIndex,o=this._activeViewCount;return this._getRenderingModes(null).then(a=>{let l=(Array.isArray(a)?a:[]).find(c=>c.isActive)||null;if(l&&(l.modeIndex!==s||l.viewCount!==o)&&this._emitDisplay({type:"renderingmodechange",modeIndex:this._activeModeIndex,viewCount:this._activeViewCount||null,mode:l,detail:null}),!t){let c=l&&typeof l.hardwareDisplay3D=="boolean"?l.hardwareDisplay3D?"3d":"2d":null;n(c)}}).catch(()=>{t||n(null)})}async _onRenderingModeChange(e){let t=li(e),i=no(e),n=null;try{let s=await this._getRenderingModes(null),o=Array.isArray(s)?s:[];n=(i>=0?o.find(a=>a.modeIndex===i):null)||o.find(a=>a.isActive)||null}catch{}n?(this._activeModeIndex=n.modeIndex,this._activeViewCount=n.viewCount):i>=0&&(this._activeModeIndex=i),(this._activeViewCount===1||this._activeViewCount===2)&&this._setStereoCollapsed(this._activeViewCount===1),this._emitDisplay({type:"renderingmodechange",modeIndex:this._activeModeIndex,viewCount:this._activeViewCount||null,mode:n,detail:t})}_emitDisplay(e,t){let i=this._displayListeners.get(e.type);if(!i)return;let n=t||[e];for(let s of[...i])try{s(...n)}catch(o){console.error(`[inline3d] ${e.type} listener threw`,o)}}on(e,t){if(typeof t!="function")throw new TypeError("[inline3d] on() takes (type, function).");if(!Or.includes(e))throw new TypeError(`[inline3d] on() knows ${Or.join(" / ")}, got ${JSON.stringify(e)}.`);let i=this._displayListeners.get(e);return i||this._displayListeners.set(e,i=new Set),i.add(t),()=>this.off(e,t)}off(e,t){let i=this._displayListeners.get(e);i&&i.delete(t)}_onDisplayModeChange(e){if(typeof e!="function")throw new TypeError("[inline3d] onDisplayModeChange() takes a function.");let t=zr.map(i=>this.on(i,e));return()=>{for(let i of t)i()}}async refreshUndock(){if(!Qt())return this.undock=null;let e=this._liveWindow(null);if(!e||!e.layer||typeof e.layer.getUndockCapabilities!="function")return this.undock;try{let t=await e.layer.getUndockCapabilities();this.undock={model:!!(t&&t.model),splat:!!(t&&t.splat)}}catch{}return this.undock}_register(e,t,i){this._windows.has(e)&&this._remove(e),e.style.willChange="transform",e.style.transform="translateZ(0)";let n={canvas:e,kind:t,layer:null,img:null,video:null,onFrame:null,onLayerLost:typeof i.onLayerLost=="function"?i.onLayerLost:null,layerLostSent:!1,onResize:t==="scene"&&typeof i.onResize=="function"?i.onResize:null,resizeBox:null,inResize:!1,ready:null,ownsBuffer:t!=="scene",cornerRadius:i.cornerRadius||0,feather:i.feather||0,reqW:i.width||0,reqH:i.height||0,virtualDisplayHeight:i.virtualDisplayHeight||0,viewRig:i.viewRig||null,rigWarned:new Set,warnedWithheld:!1,stereoSaved:null,stereoSynthRig:!1,observeEl:i.observe||e,ctx:t==="scene"?null:e.getContext("2d"),repaint:()=>this._paint(n,null),excluded:new Set,autoExcluded:new Set,overlayObserver:null,sizeObserver:null,resizePending:!1,frames:0,monoFrames:0,fwResult:null,fwResolve:null,fwPromise:null,fwHoldMs:uo(i.firstWovenHoldMs),fwRegAt:W(),fwLayerAt:null,fwStereo:!1,rw:null,rwGone:null,wsLive:!1,rc:null,layerFramed:!1,lfAnswered:!1,lfStereo:!1,lfAt:0,lfCapped:!1,framedWaiters:[]},s=ho(i.rectCover);return s&&(n.rc={cfg:s,box:null,el:null,up:!1,snapped:!1,snapWanted:!1,waiting:null,w:0,h:0}),n.fwPromise=new Promise(o=>{n.fwResolve=o}),n.viewRig&&Xt(n.rigWarned,n.viewRig),this._windows.set(e,n),this._lazy&&this._observer?this._observer.observe(n.observeEl):this._activate(n),n}_remove(e){let t=this._windows.get(e);t&&(this._observer&&this._observer.unobserve(t.observeEl),this._deactivate(t),this._windows.delete(e),this._settleFirstWoven(t,!1,"removed"),this._dropCover(t))}_onIntersect(e){for(let t of e){let i=null;for(let n of this._windows.values())if(n.observeEl===t.target){i=n;break}i&&(t.isIntersecting?this._activate(i):this._deactivate(i))}}_activate(e){if(!e.layer){this._scanChrome();try{let t=Jt()?this._effectiveViewRig(e):null,i=t?{viewRig:t}:e.virtualDisplayHeight>0?{virtualDisplayHeight:e.virtualDisplayHeight}:{};e.layer=new XRDisplayLayer(this.session,e.canvas,i)}catch(t){e.layer=null,e.layerFailWarned||(e.layerFailWarned=!0,console.warn("[inline3d] new XRDisplayLayer() failed for this window \u2014 it will show FLAT 2D instead of woven 3D, and the SDK will not retry. The canvas has been repainted mono so it cannot be left holding a raw side-by-side pair.",t)),this._paintMono(e),this._notifyLayerLost(e),this._settleFirstWoven(e,!1,"layer-failed");return}e.fwResult||(e.fwLayerAt=W(),e.fwStereo=!1),e.wsLive=ii(),e.layerFramed=!1,e.lfAnswered=!1,e.lfStereo=!1,e.lfCapped=!1,e.lfAt=W(),this._restartRewoven(e),e.layerLostSent=!1,!this._primedDisplayState&&Zt()&&(this._primedDisplayState=!0,this._getRenderingModes(e).catch(()=>{this._primedDisplayState=!1})),Qt()&&this.undock&&!this._undockRead&&(this._undockRead=!0,this.refreshUndock().catch(()=>{})),Ys(e.layer)===!0&&this._standDownLegacyOcclusion();for(let t of e.excluded)this._applyExclusion(e,t);for(let t of this._globalOverlays)this._applyExclusion(e,t);this._startOverlayScan(e),e.ownsBuffer&&(this._sizeBuffer(e,!0),this._paint(e,null)),this._startSizeWatch(e)}}_deactivate(e){if(this._noteLayerFramed(e,!1),this._stopOverlayScan(e),this._stopSizeWatch(e),e.layer){try{e.layer.close()}catch{}e.layer=null}this._paintMono(e)}_paintMono(e){!e.ownsBuffer||e.kind==="scene"||(this._sizeBuffer(e,!1),this._paint(e,null))}_notifyLayerLost(e){if(!(e.kind!=="scene"||typeof e.onLayerLost!="function"||e.layerLostSent)){e.layerLostSent=!0;try{e.onLayerLost()}catch(t){console.warn("[inline3d] a scene window's onLayerLost callback threw",t)}}}_isFullTileOverlay(e,t){if(!t||typeof t.getBoundingClientRect!="function")return!1;let i=t.getBoundingClientRect(),n=e.canvas.getBoundingClientRect(),s=i.width*i.height,o=n.width*n.height;if(s<=0||o<=0)return!1;let a=Math.min(i.right,n.right)-Math.max(i.left,n.left),l=Math.min(i.bottom,n.bottom)-Math.max(i.top,n.top);if(a<=0||l<=0)return!1;let c=a*l;return c/s<Nr||c/o<Nr?!1:(this._fullTileWarned.has(t)||(this._fullTileWarned.add(t),console.warn("[inline3d] Refusing a full-tile overlay: this element covers its own woven canvas, and the browser's geometric matcher cannot tell the two apart \u2014 it would stage the CANVAS as the overlay and the tile would show its raw side-by-side buffer instead of 3D. Make the overlay a PARTIAL region of the tile (a caption band, a badge, a corner plate), or move it outside the tile and register it with addGlobalOverlay().",t)),!0)}_applyExclusion(e,t){if(ue()||!e.layer||!Ze()||this._isFullTileOverlay(e,t))return;let i=this._isolatedBy.get(t);if(i||(i=new Set,this._isolatedBy.set(t,i)),i.add(e),!t.dataset.inline3dIsolated){t.dataset.inline3dPriorWillChange=t.style.willChange||"";let n=t.style.willChange&&t.style.willChange!=="auto"?t.style.willChange+", transform":"transform";t.style.willChange=n,t.dataset.inline3dIsolated="1"}try{e.layer.excludeElement(t)}catch{}}_dropExclusion(e,t){if(ue())return;let i=this._isolatedBy.get(t);if(i&&i.delete(e),(!i||i.size===0)&&this._unpromote(t),!(!e.layer||!Ze()))try{e.layer.unexcludeElement(t)}catch{}}_unpromote(e){return!e||!e.dataset||!e.dataset.inline3dIsolated?!1:(e.style.willChange=e.dataset.inline3dPriorWillChange||"",delete e.dataset.inline3dPriorWillChange,delete e.dataset.inline3dIsolated,!0)}_standDownLegacyOcclusion(){if(this._stoodDown)return;this._stoodDown=!0;let e=!1;for(let t of this._windows.values()){t.overlayObserver&&(this._stopOverlayScan(t),e=!0);for(let i of t.excluded)this._unpromote(i)&&(e=!0)}for(let t of this._autoChromeEls)this._globalOverlays.delete(t),this._unpromote(t),e=!0;this._autoChromeEls.clear();for(let t of this._globalOverlays)this._unpromote(t)&&(e=!0);this._isolatedBy=new WeakMap,e&&ei()}_startOverlayScan(e){if(ue()||!Ze()||typeof MutationObserver!="function")return;let t=e.canvas.parentElement;if(!t)return;let i=()=>{let n=new Set(t.querySelectorAll("[data-inline3d-overlay]"));for(let s of e.autoExcluded)n.has(s)||(e.autoExcluded.delete(s),this._dropExclusion(e,s));for(let s of n)e.autoExcluded.has(s)||(e.autoExcluded.add(s),this._applyExclusion(e,s))};i(),e.overlayObserver=new MutationObserver(i),e.overlayObserver.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-inline3d-overlay"]})}_stopOverlayScan(e){e.overlayObserver&&(e.overlayObserver.disconnect(),e.overlayObserver=null),e.autoExcluded.clear()}_eyeSize(e,t=!0){let i=Math.min(window.devicePixelRatio||1,2),n=e.reqW||Math.round((e.canvas.clientWidth||256)*i),s=e.reqH||Math.round((e.canvas.clientHeight||256)*i),o=1,a=!e.reqW&&!e.reqH&&this._sourceEyeSize(e);if(a){let c=Math.max(a.w/n,a.h/s);c<1&&(o=c,n=Math.max(1,Math.round(n*c)),s=Math.max(1,Math.round(s*c)))}let l=Mr(n,s,Sr(),{cols:t?2:1});return l.clamped&&(o*=l.scale,n=l.eyeW,s=l.eyeH,e.warnedBufClamp||(e.warnedBufClamp=!0,console.warn(Er("[inline3d]",l)))),e.bufScale=o,{w:n,h:s}}_sourceEyeSize(e){if(e.kind!=="video"&&e.kind!=="image")return null;let t=e.kind==="video"?e.video:e.img;if(!t)return null;let i=t.videoWidth||t.naturalWidth||t.width,n=t.videoHeight||t.naturalHeight||t.height;return!(i>1)||!(n>0)?null:{w:i/2,h:n}}_checkSceneBuffer(e){let t=e.canvas;if(!t||typeof t.getContext!="function")return;if(e.sceneGl===void 0){let n=null;try{n=t.getContext("webgl2")||t.getContext("webgl")}catch{n=null}e.sceneGl=n&&typeof n.drawingBufferWidth=="number"?n:null}if(!e.sceneGl)return;let i=Rr(t,e.sceneGl);i.mismatch&&(e.warnedBufMismatch=!0,console.warn(Cr("[inline3d]",t,i,"getViewport() splits canvas.width, so the eyes are off-centre in the woven buffer. This scene canvas is sized by the page: keep 2 \xD7 eye width and the height within MAX_TEXTURE_SIZE / MAX_RENDERBUFFER_SIZE / MAX_VIEWPORT_DIMS, or map getViewport() onto gl.drawingBufferWidth/Height.")))}_sizeBuffer(e,t){let{w:i,h:n}=this._eyeSize(e,t);e.eyeW=i,e.eyeH=n,e.canvas.width=t?i*2:i,e.canvas.height=n,e.sbs=t}_startSizeWatch(e){if(typeof ResizeObserver=="function"&&!e.sizeObserver){if(e.kind==="scene"){if(!e.onResize)return;e.resizeBox=jr(e.canvas),e.sizeObserver=new ResizeObserver(()=>this._onSceneResize(e)),e.sizeObserver.observe(e.canvas);return}!e.ownsBuffer||e.reqW&&e.reqH||(e.sizeObserver=new ResizeObserver(()=>this._onBoxChange(e)),e.sizeObserver.observe(e.canvas))}}_onSceneResize(e){if(!e.layer||!e.onResize||e.inResize)return;let t=jr(e.canvas),i=e.resizeBox;if(!(i&&i.width===t.width&&i.height===t.height&&i.dpr===t.dpr)){e.resizeBox=t,e.inResize=!0;try{e.onResize(t)}catch(n){e.resizeThrewWarned||(e.resizeThrewWarned=!0,console.warn("[inline3d] a scene window's onResize threw; further throws from it are silent.",n))}finally{e.inResize=!1}}}_stopSizeWatch(e){e.sizeObserver&&(e.sizeObserver.disconnect(),e.sizeObserver=null),e.resizePending=!1}_onBoxChange(e){if(!e.layer||!e.ownsBuffer||e.resizePending)return;e.resizePending=!0;let t=()=>{if(!e.resizePending||(e.resizePending=!1,!e.layer||!e.ownsBuffer))return;this._noteRewovenBox(e);let{w:i,h:n}=this._eyeSize(e);i===e.eyeW&&n===e.eyeH||(this._sizeBuffer(e,!0),this._paint(e,null))};typeof requestAnimationFrame=="function"?requestAnimationFrame(t):t()}_armDprWatch(){if(typeof window>"u"||typeof window.matchMedia!="function")return;this._disarmDprWatch();let e;try{e=window.matchMedia(`(resolution: ${window.devicePixelRatio||1}dppx)`)}catch{return}let t=()=>{if(this._running){this._armDprWatch();for(let i of this._windows.values())i.layer&&this._onBoxChange(i)}};try{e.addEventListener("change",t)}catch{return}this._dprWatch={q:e,onChange:t}}_disarmDprWatch(){if(this._dprWatch){try{this._dprWatch.q.removeEventListener("change",this._dprWatch.onChange)}catch{}this._dprWatch=null}}_paint(e,t){if(e.kind==="scene"||!e.ctx)return;let i=this._running&&!!e.layer;!i&&e.sbs&&this._sizeBuffer(e,!1);let n=e.kind==="video"?e.video:e.img;if(!n)return;if(e.kind==="video"&&(n.readyState||0)<2){i&&this._recommitLastFrame(e);return}let s=e.canvas,o=e.ctx,a=n.videoWidth||n.naturalWidth||n.width,l=n.videoHeight||n.naturalHeight||n.height;if(!a||!l)return;let c=a+"x"+l;if(e.srcKey!==c&&(e.srcKey=c,e.ownsBuffer&&!(e.reqW&&e.reqH))){let{w:p,h:b}=this._eyeSize(e,e.sbs);(p!==e.eyeW||b!==e.eyeH)&&this._sizeBuffer(e,e.sbs)}let d=e.bufScale||1,f=e.cornerRadius*d,h=e.feather*d;if(o.clearRect(0,0,s.width,s.height),!e.sbs){tt(o,n,0,0,a/2,l,0,0,s.width,s.height,f,h);return}let u=s.width/2,m=Math.min(this._stereoFactor,this._bakedStereo);if(m<1){tt(o,n,0,0,a/2,l,0,0,u,s.height,f,h),po(o,n,a/2,l,u,s.height,m,f,h);return}f>0||h>0?(tt(o,n,0,0,a/2,l,0,0,u,s.height,f,h),tt(o,n,a/2,0,a/2,l,u,0,u,s.height,f,h)):o.drawImage(n,0,0,a,l,0,0,s.width,s.height)}_bindTrackingEvents(){let e=this.session;!e||typeof e.addEventListener!="function"||this._trackingSupported&&e.addEventListener(oi,()=>{this._setTrackingState(Qe(e)||"unknown")})}_setTrackingState(e){let t=Wr.includes(e)?e:"unknown";if(t===this._trackingState)return;this._trackingState=t,this._applyUntrackedTarget();let i={type:oi,state:t};this._emitDisplay(i,[t,i])}_applyUntrackedTarget(){if(this._untrackedFallback!=="mono"){this._bakedTarget=1;return}this._trackingState==="searching"?this._bakedTarget=0:this._trackingState==="tracking"&&(this._bakedTarget=1)}_trackBakedStereo(e){this._trackingSupported&&this._setTrackingState(Qe(this.session)||"unknown");let t=this._bakedAt===null||!Number.isFinite(e)?0:Math.max(0,(e-this._bakedAt)/1e3);this._bakedAt=Number.isFinite(e)?e:this._bakedAt;let i=this._bakedStereo,n=this._bakedTarget;if(i===n)return;let s=this._bakedEaseS>0?t/this._bakedEaseS:1;this._bakedStereo=n>i?Math.min(n,i+s):Math.max(n,i-s)}_recommitLastFrame(e){let t=e.canvas;if(!t.width||!t.height)return;let i=e.ctx;try{i.save(),i.globalCompositeOperation="copy",i.drawImage(t,0,0),i.restore()}catch{}}_requestFrame(e){if(!this._running||this._framePending&&!e)return;let t=e?++this._loopId:this._loopId;this._framePending=!0;try{this.session.requestAnimationFrame((i,n)=>{t===this._loopId&&(this._framePending=!1,this._frameCount++,this._frame(i,n))})}catch{this._framePending=!1}}_frame(e,t){if(!this._running)return;this._requestFrame(),this._advanceModeSwitch();let i=this.refSpace?t.getViewerPose(this.refSpace):null,n=i?i.views:null;this._trackBakedStereo(e);for(let s of this._windows.values())if(s.layer){if(s.rc&&this._rectCoverCheck(s),s.kind==="scene"){if(n&&s.onFrame){if(s.frames++,n.length<2&&(s.monoFrames++,s.monoFrames%300===1&&typeof console<"u"&&console.debug)){let o=(100*s.monoFrames/Math.max(1,s.frames)).toFixed(1);console.debug(`[inline3d] scene window: ${s.monoFrames} non-stereo view lists in ${s.frames} frames (${o}%). The viewer replays its last good stereo frame for these; a rising rate means the session is falling back under load.`)}try{s.onFrame(n,s.layer,t),n.length>=2&&(s.fwStereo=!0,s.lfStereo=!0,s.warnedBufMismatch||this._checkSceneBuffer(s),s.rw&&(s.rw.stereo=!0))}catch(o){s.frameThrewWarned||(s.frameThrewWarned=!0,console.warn("[inline3d] a scene window's onFrame threw; this window will keep whatever it last drew, and the other windows carry on. Further throws from it are silent.",o))}}}else this._paint(s,n),s.sbs&&(s.kind==="video"?(s.video&&s.video.readyState||0)>=2:s.img)&&(s.fwStereo=!0,s.lfStereo=!0,s.rw&&(s.rw.stereo=!0));s.rc&&s.rc.snapWanted&&this._rectCoverSnap(s),(!s.layerFramed||s.framedWaiters.length)&&this._tickLayerFramed(s),this._tickFirstWoven(s)}}_tickFirstWoven(e){let t=e.wsLive&&e.layer?et(e.layer):null;if(t){this._tickWovenState(e,t);return}if(e.rw){this._noteRewovenBox(e);let i=e.rw,n=W();i.stereo&&n-i.at>=e.fwHoldMs?this._settleRewoven(e,!0,"hold-elapsed"):i.at>i.calledAt&&n-i.calledAt>=ni*e.fwHoldMs&&this._settleRewoven(e,!0,"hold-capped")}e.fwResult||!e.fwStereo||e.fwLayerAt===null||W()-e.fwLayerAt<e.fwHoldMs||this._settleFirstWoven(e,!0,"hold-elapsed")}_tickWovenState(e,t){let i=W(),n=ni*Math.max(e.fwHoldMs,ai);if(e.rw){this._noteRewovenBox(e);let s=e.rw;t!=="woven"?s.gap=!0:s.stereo&&(s.gap||s.boxFrame!==null&&this._frameCount-s.boxFrame>=Pr||s.boxFrame===null&&this._frameCount-s.callFrame>=Pr)&&this._settleRewoven(e,!0,"woven",!0),e.rw&&i-s.calledAt>=n&&(t==="woven"?this._settleRewoven(e,!0,"hold-capped",!0):this._settleRewoven(e,!1,ri(e.layer)||t,!0))}e.fwResult||e.fwLayerAt===null||(e.fwStereo&&t==="woven"?this._settleFirstWoven(e,!0,"woven",!0):i-e.fwLayerAt>=n&&(t==="woven"?this._settleFirstWoven(e,!0,"hold-capped",!0):this._settleFirstWoven(e,!1,ri(e.layer)||t,!0)))}_noteWithheld(e,t,i,n){t||!n||e.warnedWithheld||!i||i==="pending"||i==="hold-capped"||(e.warnedWithheld=!0,console.warn(`[inline3d] the browser withheld this canvas from the weave (${i}): ${wr(i)}.`,e.canvas))}_settleFirstWoven(e,t,i,n=!1){this._noteWithheld(e,t,i,n),!t&&!n&&(e.rwGone||(e.rwGone=i),this._settleRewoven(e,!1,i)),!e.fwResult&&(e.fwResult=Object.freeze({woven:t,confirmed:n,reason:i,ms:Math.round(W()-e.fwRegAt)}),e.fwResolve(e.fwResult),e.fwResolve=null)}_rewoven(e){if(!e.fwResult)return e.fwPromise;if(!e.fwResult.woven&&!e.fwResult.confirmed)return Promise.resolve(e.fwResult);if(e.rwGone)return Promise.resolve(Object.freeze({woven:!1,confirmed:!1,reason:e.rwGone,ms:0}));if(e.rw)return this._restartRewoven(e),e.rw.promise;let t,i=new Promise(s=>{t=s}),n=W();return e.rw={promise:i,resolve:t,calledAt:n,at:n,stereo:!1,box:si(e.canvas),gap:!1,boxFrame:null,callFrame:this._frameCount},i}_noteRewovenBox(e){let t=e.rw;if(!t)return;let i=si(e.canvas);i!==t.box&&(t.box=i,this._restartRewoven(e))}_restartRewoven(e){e.rw&&(e.rw.at=W(),e.rw.stereo=!1,e.rw.gap=!1,e.rw.boxFrame=this._frameCount)}_settleRewoven(e,t,i,n=!1){let s=e.rw;s&&(this._noteWithheld(e,t,i,n),e.rw=null,s.resolve(Object.freeze({woven:t,confirmed:n,reason:i,ms:Math.round(W()-s.calledAt)})))}_rectCoverCheck(e){let t=e.rc,i=si(e.canvas);if(i===t.box)return;let n=t.box===null,s=t.w,o=t.h;if(t.box=i,t.w=e.canvas.clientWidth||0,t.h=e.canvas.clientHeight||0,n)return;t.up&&this._placeCover(e);let a=e.fwResult;if(!a||e.rwGone||!(a.woven||a.confirmed))return;t.up||(t.snapped||(t.aspect=o>0?s/o:0),this._raiseCover(e)),t.cfg.snapshot&&!t.snapped&&t.w>0&&t.h>0&&(t.snapWanted=!0);let l;e.rw?(this._noteRewovenBox(e),l=e.rw.promise):(l=this._rewoven(e),e.rw&&(e.rw.boxFrame=this._frameCount)),t.waiting!==l&&(t.waiting=l,l.then(()=>{t.waiting===l&&(t.waiting=null,this._lowerCover(e))}))}_raiseCover(e){let t=e.rc;if(!t.el){if(typeof document>"u"||!document||typeof document.createElement!="function"||!e.canvas.parentElement)return;let i=document.createElement("canvas");i.setAttribute?.("aria-hidden","true"),i.dataset&&(i.dataset.inline3dCover="");let n=i.style;n.position="absolute",n.pointerEvents="none",n.margin="0",n.border="0",n.padding="0",n.background=t.cfg.color,n.display="none";try{let s=typeof getComputedStyle=="function"?getComputedStyle(e.canvas).zIndex:"auto";s&&s!=="auto"&&(n.zIndex=s)}catch{}t.el=i}this._placeCover(e),t.el.style.display="block",t.up=!0,this._fullTileWarned.add(t.el),this._applyExclusion(e,t.el)}_placeCover(e){let i=e.rc.el,n=e.canvas;if(!i)return;let s=n.parentElement;s&&(i.parentElement!==s||i.previousSibling!==n)&&s.insertBefore(i,n.nextSibling);let o=i.style;if(n.offsetParent)o.position="absolute",o.left=`${n.offsetLeft}px`,o.top=`${n.offsetTop}px`,o.width=`${n.offsetWidth}px`,o.height=`${n.offsetHeight}px`;else{let a=n.getBoundingClientRect();o.position="fixed",o.left=`${a.left??a.x??0}px`,o.top=`${a.top??a.y??0}px`,o.width=`${a.width}px`,o.height=`${a.height}px`}}_rectCoverSnap(e){let t=e.rc;t.snapWanted=!1;let i=t.el,n=e.canvas;if(!i||!t.up||!(n.width>1)||!(n.height>0))return;let s=Math.max(1,Math.round(t.w)),o=Math.max(1,Math.round(t.h)),a=s/o,l=t.aspect>0?t.aspect:n.width/2/n.height,c=1,d=1;a>l?d=l/a:c=a/l;let f=n.width/2*c,h=n.height*d,u=(n.width/2-f)/2,m=(n.height-h)/2;try{i.width=s,i.height=o;let p=i.getContext("2d");if(!p)return;p.drawImage(n,u,m,f,h,0,0,s,o),t.snapped=!0}catch{}}_lowerCover(e){let t=e.rc;t&&(t.up=!1,t.snapped=!1,t.snapWanted=!1,t.el&&(t.el.style.display="none",this._dropExclusion(e,t.el)))}_dropCover(e){let t=e.rc;t&&(t.waiting=null,this._lowerCover(e),t.el&&t.el.parentElement&&t.el.parentElement.removeChild(t.el),t.el=null)}_bindLifecycle(){typeof window>"u"||(this._onPageHide=()=>this._suspend(),this._onPageShow=e=>this._resume(!!(e&&e.persisted)),window.addEventListener("pagehide",this._onPageHide),window.addEventListener("pageshow",this._onPageShow),typeof document<"u"&&"onfreeze"in document&&(this._onFreeze=()=>this._suspend(),this._onResume=()=>this._resume(!0),document.addEventListener("freeze",this._onFreeze),document.addEventListener("resume",this._onResume)))}_unbindLifecycle(){typeof window>"u"||(this._onPageHide&&window.removeEventListener("pagehide",this._onPageHide),this._onPageShow&&window.removeEventListener("pageshow",this._onPageShow),this._onFreeze&&typeof document<"u"&&(document.removeEventListener("freeze",this._onFreeze),document.removeEventListener("resume",this._onResume)),this._onPageHide=this._onPageShow=this._onFreeze=this._onResume=null,this._frameWatchdog&&(clearTimeout(this._frameWatchdog),this._frameWatchdog=null))}_suspend(){if(!this._running||this._suspended)return;let e=[];for(let t of this._windows.values())t.layer&&(e.push(t),this._deactivate(t));this._suspended=e}_resume(e){if(!this._running)return;let t=this._suspended;if(this._suspended=null,t)for(let i of t)this._windows.has(i.canvas)&&(this._lazy&&this._observer?(this._observer.unobserve(i.observeEl),this._observer.observe(i.observeEl)):this._activate(i));this._lastChromeScan=0,this._scanChrome(),this._armDprWatch(),e&&this._watchForStalledFrames()}_watchForStalledFrames(){if(this._frameWatchdog||typeof setTimeout!="function")return;let e=this._frameCount;this._frameWatchdog=setTimeout(()=>{this._frameWatchdog=null,!(!this._running||this._frameCount!==e)&&this._requestFrame(!0)},1e3)}_teardown(){if(this._running){this._running=!1,Y===this&&(Y=null),this._unbindLifecycle(),this._disarmDprWatch(),this._disarmModeSwitchTick(),this._modeSwitch.cancel(),this._msArmedUp=!1,this._settlePendingDown("closed","the inline-3D session closed first"),this._observer&&this._observer.disconnect();for(let e of this._windows.values()){if(this._stopOverlayScan(e),this._stopSizeWatch(e),e.layer){try{e.layer.close()}catch{}e.layer=null}this._paintMono(e),this._notifyLayerLost(e),this._settleFirstWoven(e,!1,"session-ended"),this._dropCover(e),this._noteLayerFramed(e,!1)}this._windows.clear(),this._claims.clear(),this._setTrackingState("unknown"),this._displayListeners.clear()}}};function uo(r){return typeof r=="number"&&Number.isFinite(r)&&r>=0?r:ai}function fo(r){return typeof r!="string"?Promise.resolve(r):new Promise((e,t)=>{let i=new Image;i.decoding="async",i.onload=()=>e(i),i.onerror=t,i.src=r})}function tt(r,e,t,i,n,s,o,a,l,c,d,f){d>0&&r.roundRect?(r.save(),r.beginPath(),r.roundRect(o,a,l,c,d),r.clip(),r.drawImage(e,t,i,n,s,o,a,l,c),r.restore()):r.drawImage(e,t,i,n,s,o,a,l,c),f>0&&Vr(r,o,a,l,c,f)}function po(r,e,t,i,n,s,o,a,l){r.save(),a>0&&r.roundRect&&(r.beginPath(),r.roundRect(n,0,n,s,a),r.clip()),r.drawImage(e,0,0,t,i,n,0,n,s),o>0&&(r.globalAlpha=o,r.drawImage(e,t,0,t,i,n,0,n,s)),r.restore(),l>0&&Vr(r,n,0,n,s,l)}function Vr(r,e,t,i,n,s){let o=Math.min(s,Math.floor(Math.min(i,n)/2));if(o<=0)return;r.save(),r.globalCompositeOperation="destination-out";let a=[[e,t,i,o,[e,t],[e,t+o]],[e,t+n-o,i,o,[e,t+n],[e,t+n-o]],[e,t,o,n,[e,t],[e+o,t]],[e+i-o,t,o,n,[e+i,t],[e+i-o,t]]];for(let[l,c,d,f,h,u]of a){let m=r.createLinearGradient(h[0],h[1],u[0],u[1]);m.addColorStop(0,"rgba(0,0,0,1)"),m.addColorStop(1,"rgba(0,0,0,0)"),r.fillStyle=m,r.fillRect(l,c,d,f)}r.restore()}function hi(r,e){return r>0&&e>0&&r/e>2.5}function q(r,e,t,i,n){let s=Math.abs(i||0),o=Math.min(r-2*s,e*t);o=Math.max(1,o);let a=Math.min(e,o/t);o=a*t;let l=(r-o)/2+(n===0?i:-i);return{sx:Math.max(0,Math.min(r-o,l)),sy:(e-a)/2,sw:o,sh:a}}function Ie(r,e,t){let i=Math.min(r,e*t),n=i/t;return{w:Math.max(2,Math.round(i/2)*2),h:Math.max(2,Math.round(n/2)*2)}}function fe(r,e){let t=r/2;return[{src:"R",sx:t,sw:t,sy:0,sh:e,dx:0,dw:t,mirror:!0},{src:"L",sx:0,sw:t,sy:0,sh:e,dx:t,dw:t,mirror:!0}]}function ui(r,e,t){let i=new r.constructor(r.length);for(let n of fe(e,t))for(let s=0;s<t;s++)for(let o=0;o<n.dw;o++){let a=n.sx+(n.sw-1-o);i[s*e+n.dx+o]=r[s*e+a]}return i}function Br(r,e){return!(r>0)||!(e>0)||e>=180?null:r/2/Math.tan(e/2*Math.PI/180)}function rt({eyeWidthPx:r,hfovDeg:e,baselineMm:t,subjectZmm:i}){let n=Br(r,e);return n===null||!(t>0)||!(i>0)?0:n*t/(2*i)}function nt(r,e,t=.2){let i=Math.max(0,e*t);return Math.max(-i,Math.min(i,r||0))}function st(r,e,t=.2){let i=r+t*(e-r);return Math.abs(e-i)<.05?e:i}function Fe(){let r={hello:null,subjectZmm:null,measuredPx:null,depth:0,current:0,target(e){let t=r.measuredPx!==null?r.measuredPx/2:r.hello&&r.subjectZmm?rt({eyeWidthPx:e,hfovDeg:r.hello.hfovDeg,baselineMm:r.hello.baselineMm,subjectZmm:r.subjectZmm}):0;return nt(t+r.depth*.05*e,e)},step(e){return r.current=st(r.current,r.target(e)),r.current}};return r}var ot=1,di="inline3d-call/1",Xr=Object.freeze(["sbs","mono"]),pe=4,qr=4,fi=5,mo=150,go=5e3,_o=/^[A-Za-z0-9_-]{16,64}$/,vo=16;function pi(r){let e=new Uint8Array(vo);return(r||(i=>globalThis.crypto.getRandomValues(i)))(e),Yr(e)}function Gr(r){let e=new Uint8Array(8);return(r||(i=>globalThis.crypto.getRandomValues(i)))(e),Yr(e)}function Yr(r){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",t="",i=0;for(;i+2<r.length;i+=3){let s=r[i]<<16|r[i+1]<<8|r[i+2];t+=e[s>>18&63]+e[s>>12&63]+e[s>>6&63]+e[s&63]}let n=r.length-i;if(n===1){let s=r[i]<<16;t+=e[s>>18&63]+e[s>>12&63]}else if(n===2){let s=r[i]<<16|r[i+1]<<8;t+=e[s>>18&63]+e[s>>12&63]+e[s>>6&63]}return t}function me(r){return typeof r=="string"&&_o.test(r)}function Ne(r){if(!r)return null;let e="";if(typeof r=="object")e=r.hash||r.href&&String(r.href).split("#")[1]||"";else{let t=String(r),i=t.indexOf("#");e=i>=0?t.slice(i+1):t.includes("=")&&!t.includes("://")?t:""}e=e.replace(/^#/,"");for(let t of e.split("&")){let i=t.indexOf("=");if(i<0||decodeURIComponent(t.slice(0,i))!=="room")continue;let n=decodeURIComponent(t.slice(i+1));return me(n)?n:null}return null}function at(r,e){if(!me(e))throw new Error(`@displayxr/inline3d/call: invalid room id "${e}"`);return`${String(r||"").split("#")[0]}#room=${e}`}function mi(r){if(!r||typeof r!="object"||r.type!=="hello")return null;let e=(t,i,n)=>typeof t=="number"&&Number.isFinite(t)&&t>=i&&t<=n?t:null;return{type:"hello",v:typeof r.v=="number"?r.v:ot,format:Xr.includes(r.format)?r.format:"mono",width:e(r.width,1,16384),height:e(r.height,1,16384),baselineMm:e(r.baselineMm,1,1e3),hfovDeg:e(r.hfovDeg,5,170),rectified:r.rectified===!0,sdk:typeof r.sdk=="string"?r.sdk.slice(0,64):null}}function gi({format:r,width:e,height:t,baselineMm:i,hfovDeg:n,rectified:s}={}){let o={type:"hello",v:ot,format:Xr.includes(r)?r:"mono",width:e||0,height:t||0,rectified:!!s,sdk:di};return Number.isFinite(i)&&(o.baselineMm=i),Number.isFinite(n)&&(o.hfovDeg=n),o}function _i(r){if(!r||r.type!=="hint")return null;let e=r.subjectZmm;return typeof e=="number"&&Number.isFinite(e)&&e>=mo&&e<=go?{type:"hint",subjectZmm:e}:null}function Kr(r){return!r||r.type!=="state"?null:{type:"state",muted:r.muted===!0,cameraOff:r.cameraOff===!0,speaking:r.speaking===!0}}function vi(r){let e=1e3/r,t=-1/0;return i=>i-t<e?!1:(t=i,!0)}function yi({format:r,woven:e,mono3D:t="auto",lift:i=!1,overBudget:n=!1,failed:s=!1}){return(r==="sbs"?"sbs":"mono")==="sbs"?{route:e?"woven-sbs":"flat-left"}:e?t==="off"||t===!1?{route:"flat",mono3d:"off"}:i?s?{route:"flat",mono3d:"failed"}:n?{route:"flat",mono3d:"budget"}:{route:"lifted",mono3d:"lifted"}:{route:"flat",mono3d:"unavailable"}:{route:"flat"}}function wi(r){return r==="woven-sbs"?"3D":r==="lifted"?"2D\u21923D":"2D"}function bi({need:r=10,needNoPose:e=30}={}){let t=0,i=0,n=!1;return{feed(s){return n?!0:(i++,s===null?n=i>=e:(t=s>=1?t+1:0,n=t>=r),n)},get live(){return n}}}function lt(r,e){let t=Math.max(1,e|0),n=r==="sbs"?[6e3,4e3,3e3]:[2500,1800,1400];return n[Math.min(t,n.length)-1]}function K(r,{baseMs:e=1e3,maxMs:t=3e4,rand:i=Math.random}={}){let n=Math.min(t,e*Math.pow(2,Math.max(0,r)));return Math.round(n*(.8+.4*i()))}var je=Object.freeze(["VP9","VP8","AV1"]);function wo(r,e=je){let t=e.indexOf(String(r||"").toUpperCase());return t<0?e.length:t}function ct(r,e=je){let t=i=>wo(String(i.mimeType||"").split("/")[1],e);return r.map((i,n)=>({c:i,i:n,r:t(i)})).sort((i,n)=>i.r-n.r||i.i-n.i).map(i=>i.c)}function ze(r,e=je){if(!r)return r;let t=r.includes(`\r
|
|
17
17
|
`)?`\r
|
|
18
18
|
`:`
|
|
19
|
-
`,i=r.split(t),n=i.findIndex(d=>d.startsWith("m=video"));if(n<0)return r;let s=i.findIndex((d,p)=>p>n&&d.startsWith("m="));s<0&&(s=i.length);let o=i.slice(n,s),a=new Map,l=new Map;for(let d of o){let p=d.match(/^a=rtpmap:(\d+) ([\w-]+)\//);p&&a.set(p[1],p[2].toUpperCase());let g=d.match(/^a=fmtp:(\d+) apt=(\d+)/);g&&(l.has(g[2])||l.set(g[2],[]),l.get(g[2]).push(g[1]))}let c=i[n].split(" "),u=c.slice(3),f=[];for(let d of e)for(let p of u)if(a.get(p)===d&&!f.includes(p)){f.push(p);for(let g of l.get(p)||[])u.includes(g)&&!f.includes(g)&&f.push(g)}if(!f.length)return r;let h=u.filter(d=>!f.includes(d));return i[n]=[...c.slice(0,3),...f,...h].join(" "),i.join(t)}var Jr=Object.freeze([{urls:"stun:stun.l.google.com:19302"}]),xo=4e3,So=1e4,Mo=2e4,Eo=8e3,Ro=1e4;function He(r){let e=Number.isInteger(r)?r:pe;return Math.max(2,Math.min(qr,e))}function Zr(r,e){return r<e}var We=class{constructor({signaling:e,id:t,maxPeers:i,iceServers:n,RTCPeerConnection:s,log:o,unreachableMs:a}={}){this.unreachableMs=a>0?a:Ro,this.signaling=e,this.id=t,this.maxPeers=He(i),this.pageIce=n||null,this.iceServers=n||Jr,this.PC=s||globalThis.RTCPeerConnection,this.log=o||(()=>{}),this.peers=new Map,this.session=null,this.ready=!1,this._pending=[],this.stopped=!1,this.sendFormat="mono",this.localStream=null}get size(){return this.peers.size}async start({room:e,localStream:t,sendFormat:i,onPeer:n,onPeerLeft:s,onStream:o,onMessage:a,onPeerState:l,onRefused:c,onSignalingState:u,onGhost:f}){this.localStream=t,this.sendFormat=i||"mono",this.cb={onPeer:n,onPeerLeft:s,onStream:o,onMessage:a,onPeerState:l,onRefused:c,onSignalingState:u,onGhost:f};let h=g=>(...w)=>this.ready?g(...w):this._pending.push(()=>g(...w));this.session=await this.signaling.join(e,{id:this.id,maxPeers:this.maxPeers,onPeerJoined:h(g=>this._onPeerJoined(g)),onPeerLeft:h(g=>this._onPeerLeftSignaling(g)),onSignal:h((g,w)=>this._onSignal(g,w)),onDisconnect:g=>u?.(g?"closed":"reconnecting",g),onPeerUnreachable:h(g=>f?.(g,!0)),onPeerReachable:h(g=>f?.(g,!1)),onReconnect:h(g=>{u?.("connected");for(let w of g)this._onPeerJoined(w)})}),!this.pageIce&&this.session.iceServers&&this.session.iceServers.length&&(this.iceServers=[...Jr,...this.session.iceServers]);let d=this.session.peers||[];if(d.length>=this.maxPeers){this.session.leave();let g=new Error(`@displayxr/inline3d/call: this call is full (${this.maxPeers} participants)`);throw g.code="room-full",g}this.ready=!0;for(let g of d)this._onPeerJoined(g);let p=this._pending;this._pending=[];for(let g of p)g();return this.session}_onPeerJoined(e){if(this.stopped||e===this.id)return;let t=this.peers.get(e);if(t){t.absent=!1,t.state!=="connected"&&Zr(this.id,e)&&this._rebuild(t,"rejoined");return}if(this.peers.size>=this.maxPeers-1){this.log("refused",{peer:e,reason:"maxPeers",maxPeers:this.maxPeers}),this.cb.onRefused?.(e);return}let i=this._newRecord(e);this.cb.onPeer?.(e),i.offerer?this._build(i,1):i.waitTimer=setTimeout(()=>this._askRestart(i),Eo)}_onPeerLeftSignaling(e){let t=this.peers.get(e);t&&(t.absent=!0,t.state!=="connected"&&this._drop(t,"left"))}_newRecord(e){let t={id:e,offerer:Zr(this.id,e),pc:null,builtAt:0,offerAt:0,dc:null,gen:0,state:"new",stream:null,attempts:0,iceRestarted:!1,absent:!1,pendingCandidates:[],timers:new Set,waitTimer:null,unreachable:!1,unreachTimer:null};return this.peers.set(e,t),this._armUnreachable(t),t}_build(e,t){this._closePc(e),e.gen=t,e.builtAt=Date.now(),e.iceRestarted=!1,e.pendingCandidates=[],e.stream=null;let i=new this.PC({iceServers:this.iceServers});e.pc=i;let n=i.createDataChannel("dxr-call",{negotiated:!0,id:0,ordered:!0});if(this._wireDc(e,n),e.offerer){let s=this.localStream?this.localStream.getTracks():[],o=s.find(u=>u.kind==="audio"),a=s.find(u=>u.kind==="video"),l=this.localStream?[this.localStream]:[];i.addTransceiver(o||"audio",{direction:"sendrecv",streams:l});let c=i.addTransceiver(a||"video",{direction:"sendrecv",streams:l});this._preferCodecs(c)}return i.onicecandidate=s=>{s.candidate&&this._signal(e,{kind:"candidate",candidate:s.candidate.toJSON?s.candidate.toJSON():s.candidate})},i.ontrack=s=>{if(e.stream||(e.stream=new MediaStream),!e.stream.getTracks().includes(s.track)){for(let o of e.stream.getTracks())o.kind===s.track.kind&&e.stream.removeTrack(o);e.stream.addTrack(s.track)}this.cb.onStream?.(e.id,e.stream)},i.onconnectionstatechange=()=>this._onConnState(e,i),this._arm(e,Mo,()=>{e.pc===i&&i.connectionState!=="connected"&&this._fail(e,"connect-timeout")}),e.offerer&&this._offer(e).catch(s=>this.log("offer-error",{peer:e.id,err:String(s)})),this._setState(e,e.attempts>0?"reconnecting":"connecting"),i}async _offer(e,{iceRestart:t=!1}={}){let i=e.pc,n=await i.createOffer(t?{iceRestart:!0}:void 0);this._canPreferCodecs||(n.sdp=ze(n.sdp)),await i.setLocalDescription(n),this._signal(e,{kind:"offer",sdp:i.localDescription.sdp})}async _onSignal(e,t){if(this.stopped||!t||typeof t!="object")return;let i=this.peers.get(e);if(!i&&(t.kind!=="offer"||(this._onPeerJoined(e),i=this.peers.get(e),!i)))return;let n=t.gen|0;try{switch(t.kind){case"offer":{if(i.offerer||(clearTimeout(i.waitTimer),n<i.gen))return;i.offerAt=Date.now(),(n>i.gen||!i.pc)&&this._build(i,n);let s=i.pc;await s.setRemoteDescription({type:"offer",sdp:t.sdp}),this._attachAnswererTracks(i);let o=await s.createAnswer();this._canPreferCodecs||(o.sdp=ze(o.sdp)),await s.setLocalDescription(o),this._signal(i,{kind:"answer",sdp:s.localDescription.sdp}),this._flushCandidates(i);break}case"answer":if(!i.offerer||n!==i.gen||!i.pc||i.pc.signalingState!=="have-local-offer")return;await i.pc.setRemoteDescription({type:"answer",sdp:t.sdp}),this._flushCandidates(i);break;case"candidate":if(n!==i.gen||!i.pc)return;i.pc.remoteDescription?await i.pc.addIceCandidate(t.candidate).catch(()=>{}):i.pendingCandidates.push(t.candidate);break;case"restart":if(!i.offerer||i.pc&&i.state!=="connected"&&Date.now()-i.builtAt<5e3)return;this._rebuild(i,"peer-asked");break;case"bye":this._drop(i,"left");break}}catch(s){this.log("signal-error",{peer:e,kind:t.kind,err:String(s)})}}_flushCandidates(e){let t=e.pendingCandidates;e.pendingCandidates=[];for(let i of t)e.pc.addIceCandidate(i).catch(()=>{})}_attachAnswererTracks(e){let t=e.pc,i=this.localStream?this.localStream.getTracks():[];for(let n of t.getTransceivers()){let s=n.receiver&&n.receiver.track?n.receiver.track.kind:null;if(!s||n.sender.track)continue;let o=i.find(a=>a.kind===s);o&&(n.sender.replaceTrack(o).catch(()=>{}),this.localStream&&n.sender.setStreams&&n.sender.setStreams(this.localStream)),n.direction="sendrecv",s==="video"&&this._preferCodecs(n)}}_preferCodecs(e){let t=globalThis.RTCRtpReceiver&&RTCRtpReceiver.getCapabilities&&RTCRtpReceiver.getCapabilities("video");if(this._canPreferCodecs=!!(e&&e.setCodecPreferences&&t),!!this._canPreferCodecs)try{e.setCodecPreferences(ct(t.codecs))}catch{this._canPreferCodecs=!1}}_onConnState(e,t){if(e.pc!==t)return;let i=t.connectionState;this.log("pc-state",{peer:e.id,state:i,gen:e.gen}),i==="connected"?(this._clearTimers(e),e.attempts=0,e.iceRestarted=!1,this._setState(e,"connected"),this.tuneSenders()):i==="disconnected"?(this._setState(e,"reconnecting"),this._arm(e,xo,()=>{e.pc===t&&t.connectionState!=="connected"&&this._fail(e,"disconnected")})):i==="failed"?this._fail(e,"failed"):i==="closed"&&!this.stopped&&this.peers.get(e.id)===e&&this._fail(e,"closed")}_fail(e,t){if(this.stopped||this.peers.get(e.id)!==e)return;if(e.absent)return this._drop(e,"left");if(this._setState(e,"reconnecting"),!e.offerer)return this._askRestart(e);let i=e.pc;if(i&&!e.iceRestarted&&i.connectionState!=="closed"&&i.signalingState!=="closed"){e.iceRestarted=!0,this.log("ice-restart",{peer:e.id,why:t,gen:e.gen}),this._offer(e,{iceRestart:!0}).catch(()=>this._rebuild(e,"ice-restart-failed")),this._arm(e,So,()=>{e.pc===i&&i.connectionState!=="connected"&&this._rebuild(e,"ice-restart-timeout")});return}this._rebuild(e,t)}_rebuild(e,t){if(this.stopped||this.peers.get(e.id)!==e)return;this._clearTimers(e),this._closePc(e),this._setState(e,"reconnecting");let i=K(e.attempts++);this.log("redial",{peer:e.id,why:t,attempt:e.attempts,inMs:i}),this._arm(e,i,()=>this._build(e,e.gen+1))}_askRestart(e){if(this.stopped||this.peers.get(e.id)!==e||e.offerer)return;let t=Date.now();this._signal(e,{kind:"restart"}),this._arm(e,Math.max(3e3,K(e.attempts++)),()=>{e.state!=="connected"&&!(e.offerAt>=t)&&this._askRestart(e)})}_drop(e,t){this.peers.get(e.id)===e&&(this._clearTimers(e),clearTimeout(e.unreachTimer),clearTimeout(e.waitTimer),this._closePc(e),this.peers.delete(e.id),this._setState(e,"left"),this.cb.onPeerLeft?.(e.id,t),this.tuneSenders())}_closePc(e){if(e.dc){try{e.dc.close()}catch{}e.dc=null}if(e.pc){let t=e.pc;e.pc=null;try{t.close()}catch{}}}_arm(e,t,i){let n=setTimeout(()=>{e.timers.delete(n),i()},t);e.timers.add(n)}_clearTimers(e){for(let t of e.timers)clearTimeout(t);e.timers.clear()}_armUnreachable(e){e.unreachTimer||e.unreachable||(e.unreachTimer=setTimeout(()=>{e.unreachTimer=null,!(this.stopped||this.peers.get(e.id)!==e||e.state==="connected")&&(e.unreachable=!0,this.log("unreachable",{peer:e.id,afterMs:this.unreachableMs,pc:e.pc?e.pc.iceConnectionState:null}),this._setState(e,"unreachable"))},this.unreachableMs))}_setState(e,t){t==="connected"?(clearTimeout(e.unreachTimer),e.unreachTimer=null,e.unreachable=!1):(t==="connecting"||t==="reconnecting")&&(e.unreachable?t="unreachable":this._armUnreachable(e)),e.state!==t&&(e.state=t,this.cb.onPeerState?.(e.id,t))}_signal(e,t){this.session?.send(e.id,{...t,gen:e.gen})}_wireDc(e,t){e.dc=t,t.onopen=()=>this.cb.onMessage?.(e.id,{type:"__open"}),t.onmessage=i=>{let n;try{n=JSON.parse(i.data)}catch{return}if(n&&n.type==="bye")return this._drop(e,"left");this.cb.onMessage?.(e.id,n)}}send(e,t){let i=this.peers.get(e);return i&&i.dc&&i.dc.readyState==="open"?(i.dc.send(JSON.stringify(t)),!0):!1}broadcast(e){for(let t of this.peers.keys())this.send(t,e)}peerConnection(e){let t=this.peers.get(e);return t?t.pc:null}peerState(e){let t=this.peers.get(e);return t?t.state:null}async replaceTrack(e,t,i){i&&(this.localStream=i);for(let n of this.peers.values())if(n.pc)for(let s of n.pc.getTransceivers())(s.receiver&&s.receiver.track?s.receiver.track.kind:null)===e&&await s.sender.replaceTrack(t).catch(()=>{});await this.tuneSenders()}setSendFormat(e){return this.sendFormat=e,this.tuneSenders()}async tuneSenders(){let e=this.peers.size,t=lt(this.sendFormat,e);for(let i of this.peers.values())if(i.pc){for(let n of i.pc.getSenders())if(!(!n.track||n.track.kind!=="video"))try{let s=n.getParameters();s.degradationPreference="maintain-resolution",(!s.encodings||!s.encodings.length)&&(s.encodings=[{}]),s.encodings[0].maxBitrate=t*1e3,await n.setParameters(s)}catch(s){this.log("setParameters-error",{peer:i.id,err:String(s)})}}return t}stop(){if(!this.stopped){this.broadcast({type:"bye"}),this.stopped=!0;for(let e of this.peers.values())this._clearTimers(e),clearTimeout(e.waitTimer),clearTimeout(e.unreachTimer),this._signal(e,{kind:"bye"}),this._closePc(e);this.peers.clear();try{this.session?.leave()}catch{}}}_debugKill(e){let t=this.peers.get(e);return!t||!t.pc?!1:(this._closePc(t),this._fail(t,"debug-kill"),!0)}};var bi={width:{ideal:1280},height:{ideal:720},frameRate:{ideal:30}},xi={width:{ideal:3840},height:{ideal:1080},frameRate:{ideal:30}},Co=Object.freeze({echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0});function ko(r){return!!r&&(r.name==="NotReadableError"||r.name==="TrackStartError"||/in use|busy/i.test(r.message||""))}function To(r){return!!r&&(r.name==="NotAllowedError"||r.name==="PermissionDeniedError"||r.name==="SecurityError")}function Qr(r){return r.length&&r.every(e=>e.busy)?"camera-busy":r.some(e=>e.denied)?"permission-denied":"no-camera"}function Si(r){return/stereo|\b3d\b|\bsbs\b|dual/i.test(r||"")}async function en(r="auto",e={}){let t=e.mediaDevices||globalThis.navigator&&navigator.mediaDevices,i=e.log||(()=>{}),n=[],s=e.calibration||{};if(r&&typeof r=="object"&&typeof r.getVideoTracks=="function"){let m=r.getVideoTracks()[0],_=m?m.getSettings():{},S=e.format==="sbs"?"sbs":"mono";return{stream:r,format:S,width:_.width||0,height:_.height||0,deviceId:_.deviceId||null,label:m?m.label:"",owned:!1,skipped:n,calibration:s}}if(!t||!t.getUserMedia)throw Object.assign(new Error("getUserMedia is not available (insecure context?)"),{code:"no-camera"});let o=async m=>{let _=await t.getUserMedia({video:m,audio:!1}),S=_.getVideoTracks()[0],x=S?S.getSettings():{};if(!S||S.readyState==="ended"||!(x.width>0)||!(x.height>0))throw _.getTracks().forEach(M=>M.stop()),Object.assign(new Error("the camera opened but delivers no picture (0x0)"),{name:"NotReadableError"});let C=x.displayxrStereo&&x.displayxrStereo.layout==="side-by-side"?x.displayxrStereo:null;return{stream:_,track:S,width:x.width,height:x.height,deviceId:x.deviceId||null,label:S.label||"",stereo:C}},a=(m,_)=>{n.push({label:m,error:`${_.name}: ${_.message}`,busy:ko(_),denied:To(_)}),i("camera-skip",{label:m,error:_.name})},l=m=>m&&m.stream.getTracks().forEach(_=>_.stop()),c=m=>!!m&&(!!m.stereo||ci(m.width,m.height)),u=(m,_)=>({stream:m.stream,format:_,width:m.width,height:m.height,deviceId:m.deviceId,label:m.label,owned:!0,skipped:n,calibration:{rectified:!1,..._==="sbs"&&m.stereo?{rectified:!!m.stereo.rectified,...m.stereo.baselineMm>0?{baselineMm:m.stereo.baselineMm}:{},...m.stereo.horizontalFovDeg>0?{hfovDeg:m.stereo.horizontalFovDeg}:{}}:{},...s}});if(typeof r=="string"&&!["auto","stereo","mono"].includes(r)){let m;try{m=await o({deviceId:{exact:r},...xi})}catch(_){throw a(r,_),Object.assign(new Error(`camera unavailable: ${_.message}`),{code:Qr(n),skipped:n})}return c(m)?u(m,"sbs"):(l(m),u(await o({deviceId:{exact:r},...bi}),"mono"))}let f=new Set,h=async()=>{try{return(await t.enumerateDevices()).filter(m=>m.kind==="videoinput")}catch{return[]}},d=async m=>{for(let _ of m){if(!_.deviceId||!Si(_.label)||f.has(_.deviceId))continue;f.add(_.deviceId);let S=null;try{S=await o({deviceId:{exact:_.deviceId},...xi})}catch(x){a(_.label,x);continue}if(c(S))return i("camera-sbs",{label:S.label,width:S.width,height:S.height,direct:!0}),S;l(S)}return null},p=null;if(r!=="mono"){let m=await h(),_=await d(m);if(_)return u(_,"sbs");if(m.length&&m.every(S=>!S.label)){let S=null;try{S=await o({...bi,facingMode:{ideal:"environment"}})}catch(C){a("default",C)}if(S&&c(S))return u(S,"sbs");let x=await d(await h());if(x)return l(S),u(x,"sbs");S&&S.track?.getSettings?.().facingMode!=="environment"?p=S:l(S)}}if(!p)try{p=await o(bi)}catch(m){a("default",m)}if(r==="mono"&&p)return u(p,"mono");if(p&&c(p))return u(p,"sbs");let g=[];try{g=(await t.enumerateDevices()).filter(m=>m.kind==="videoinput")}catch{}g.sort((m,_)=>Number(Si(_.label))-Number(Si(m.label)));for(let m of g){if(!m.deviceId||p&&m.deviceId===p.deviceId||f.has(m.deviceId))continue;let _=null;try{_=await o({deviceId:{exact:m.deviceId},...xi})}catch(S){a(m.label,S);continue}if(c(_))return l(p),i("camera-sbs",{label:_.label,width:_.width,height:_.height}),u(_,"sbs");l(_)}if(p)return r==="stereo"&&i("camera-no-stereo",{fallback:p.label}),u(p,"mono");let w=Qr(n);throw Object.assign(new Error(w==="camera-busy"?"camera unavailable: in use by another app (e.g. eye tracking) or unable to deliver a picture":w==="permission-denied"?"camera access was denied":"no camera could be opened"),{code:w,skipped:n})}async function tn(r={}){let e=r.mediaDevices||globalThis.navigator&&navigator.mediaDevices;try{return(await e.getUserMedia({audio:{...Co},video:!1})).getAudioTracks()[0]||null}catch(t){return(r.log||(()=>{}))("mic-skip",{error:t&&t.name}),null}}Ei();we();var ln="http://displayxr.org/ns/stereo/1.0/",yt="http://ns.adobe.com/xap/1.0/\0";function bt(r={}){let e=i=>typeof i=="number"&&Number.isFinite(i)?i:null,t=r.layout==="sbs"||r.layout==="side-by-side"?"sbs":"mono";return{layout:t,columns:t==="sbs"?2:1,rows:1,convergencePx:e(r.convergencePx),baselineMm:e(r.baselineMm),horizontalFovDeg:e(r.horizontalFovDeg),rectified:r.rectified===!0?!0:r.rectified===!1?!1:null,eyeWidth:e(r.eyeWidth),eyeHeight:e(r.eyeHeight),software:typeof r.software=="string"&&r.software?r.software:null}}var Fo=r=>String(r).replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<"),xe=r=>Math.round(r*1e3)/1e3;function cn(r){let e=bt(r),t=[["Layout",e.layout==="sbs"?"side-by-side":"mono"],["Columns",e.columns],["Rows",e.rows],["ConvergencePx",e.convergencePx===null?null:xe(e.convergencePx)],["BaselineMm",e.baselineMm===null?null:xe(e.baselineMm)],["HorizontalFovDeg",e.horizontalFovDeg===null?null:xe(e.horizontalFovDeg)],["Rectified",e.rectified===null?null:e.rectified?"True":"False"],["EyeWidth",e.eyeWidth],["EyeHeight",e.eyeHeight],["Software",e.software]].filter(([,i])=>i!=null).map(([i,n])=>` dxr:${i}="${Fo(n)}"`).join("");return`<?xpacket begin="\uFEFF" id="W5M0MpCehiHzreSzNTczkc9d"?><x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:dxr="${ln}"${t}/></rdf:RDF></x:xmpmeta><?xpacket end="w"?>`}function ki(r){if(typeof r!="string"||!r.includes(ln))return null;let e=o=>{let a=new RegExp(`\\bdxr:${o}="([^"]*)"`).exec(r);if(a)return a[1];let l=new RegExp(`<dxr:${o}>([^<]*)</dxr:${o}>`).exec(r);return l?l[1]:null},t=o=>{let a=e(o);return a===null||a===""||!Number.isFinite(+a)?null:+a},i=e("Rectified"),n=e("Layout"),s=e("Software");return bt({layout:n==="side-by-side"||n==="sbs"?"sbs":"mono",convergencePx:t("ConvergencePx"),baselineMm:t("BaselineMm"),horizontalFovDeg:t("HorizontalFovDeg"),rectified:i===null?null:/^true$/i.test(i),eyeWidth:t("EyeWidth"),eyeHeight:t("EyeHeight"),software:s===null?null:s.replace(/"/g,'"').replace(/</g,"<").replace(/&/g,"&")})}var wt=r=>new TextEncoder().encode(r),Ci=r=>new TextDecoder().decode(r),hn=r=>r.length>4&&r[0]===255&&r[1]===216;function*un(r){let e=2;for(;e+4<=r.length;){if(r[e]!==255)return;let t=r[e+1];if(t===216||t>=208&&t<=215||t===1||t===255){e+=t===255?1:2;continue}if(t===218||t===217)return;let i=r[e+2]<<8|r[e+3];if(i<2||e+2+i>r.length)return;yield{marker:t,start:e,end:e+2+i,data:r.subarray(e+4,e+2+i)},e+=2+i}}function dn(r,e){if(r.length<e.length)return!1;for(let t=0;t<e.length;t++)if(r[t]!==e.charCodeAt(t))return!1;return!0}function fn(r,e){if(!hn(r))throw new TypeError("jpegWithXmp: not a JPEG");let t=new Uint8Array([...wt(yt),...wt(e)]),i=t.length+2;if(i>65535)throw new RangeError("jpegWithXmp: XMP packet too large for one APP1 segment");let n=new Uint8Array(4+t.length);n[0]=255,n[1]=225,n[2]=i>>8,n[3]=i&255,n.set(t,4);let s=2,o=null;for(let u of un(r)){if(u.marker===225&&dn(u.data,yt)){o=u;break}if(u.marker===224||u.marker===225)s=u.end;else break}let[a,l]=o?[o.start,o.end]:[s,s],c=new Uint8Array(r.length-(l-a)+n.length);return c.set(r.subarray(0,a),0),c.set(n,a),c.set(r.subarray(l),a+n.length),c}function Ti(r){if(!hn(r))return null;for(let e of un(r))if(e.marker===225&&dn(e.data,yt))return Ci(e.data.subarray(yt.length));return null}var pn=r=>ki(Ti(r)),U={EBML:440786851,Segment:408125543,Tags:307544935,Tag:29555,Targets:25536,SimpleTag:26568,TagName:17827,TagString:17543},No=r=>r.length>4&&r[0]===26&&r[1]===69&&r[2]===223&&r[3]===163;function mn(r){let e=[];for(let t=r;t>0;t=Math.floor(t/256))e.unshift(t%256);return e}function gn(r,e=0){let t=e;if(!t)for(t=1;t<8&&r>2**(7*t)-2;t++);let i=new Array(t).fill(0),n=r;for(let s=t-1;s>=1;s--)i[s]=n%256,n=Math.floor(n/256);return i[0]=128>>t-1|n,i}function Oi(r,e){let t=r[e],i=t>=128?1:t>=64?2:t>=32?3:t>=16?4:0;if(!i||e+i>r.length)return null;let n=0;for(let s=0;s<i;s++)n=n*256+r[e+s];return{id:n,width:i}}function Ue(r,e){let t=r[e],i=1;for(;i<=8&&!(t&128>>i-1);)i++;if(i>8||e+i>r.length)return null;let n=t&255>>i,s=n===127>>i-1;for(let o=1;o<i;o++)n=n*256+r[e+o],r[e+o]!==255&&(s=!1);return{size:n,width:i,unknown:s}}function be(r,e){return[...mn(r),...gn(e.length),...e]}function jo(r){let e=[];for(let[i,n]of Object.entries(r))n!=null&&e.push(...be(U.SimpleTag,[...be(U.TagName,[...wt(String(i))]),...be(U.TagString,[...wt(String(n))])]));let t=be(U.Tag,[...be(U.Targets,[]),...e]);return new Uint8Array(be(U.Tags,t))}function _n(r){let e=bt(r);return{DXR_LAYOUT:e.layout==="sbs"?"side-by-side":"mono",DXR_COLUMNS:String(e.columns),DXR_ROWS:String(e.rows),DXR_CONVERGENCE_PX:e.convergencePx===null?null:String(xe(e.convergencePx)),DXR_BASELINE_MM:e.baselineMm===null?null:String(xe(e.baselineMm)),DXR_HFOV_DEG:e.horizontalFovDeg===null?null:String(xe(e.horizontalFovDeg)),DXR_RECTIFIED:e.rectified===null?null:e.rectified?"true":"false",DXR_EYE_WIDTH:e.eyeWidth===null?null:String(e.eyeWidth),DXR_EYE_HEIGHT:e.eyeHeight===null?null:String(e.eyeHeight),DXR_SOFTWARE:e.software}}function zo(r){if(!r||!("DXR_LAYOUT"in r))return null;let e=t=>r[t]===void 0||r[t]===""||!Number.isFinite(+r[t])?null:+r[t];return bt({layout:r.DXR_LAYOUT==="side-by-side"?"sbs":"mono",convergencePx:e("DXR_CONVERGENCE_PX"),baselineMm:e("DXR_BASELINE_MM"),horizontalFovDeg:e("DXR_HFOV_DEG"),rectified:r.DXR_RECTIFIED===void 0?null:r.DXR_RECTIFIED==="true",eyeWidth:e("DXR_EYE_WIDTH"),eyeHeight:e("DXR_EYE_HEIGHT"),software:r.DXR_SOFTWARE??null})}function vn(r){if(!No(r))return null;let e=Ue(r,4);if(!e)return null;let t=4+e.width+e.size;for(;t<r.length;){let i=Oi(r,t);if(!i)return null;let n=Ue(r,t+i.width);if(!n)return null;let s=t+i.width+n.width;if(i.id===U.Segment)return{sizeAt:t+i.width,sizeWidth:n.width,unknown:n.unknown,dataStart:s,size:n.size};if(n.unknown)return null;t=s+n.size}return null}function yn(r,e){let t=vn(r);if(!t)throw new TypeError("webmWithTags: not a WebM/Matroska file (no Segment)");let i=jo(e);if(t.unknown){let u=new Uint8Array(r.length+i.length);return u.set(r,0),u.set(i,r.length),u}let n=Math.min(r.length,t.dataStart+t.size),s=n-t.dataStart+i.length,o=s<=2**(7*t.sizeWidth)-2,a=gn(s,o?t.sizeWidth:8),l=new Uint8Array(t.sizeAt+a.length+(n-t.dataStart)+i.length+(r.length-n));l.set(r.subarray(0,t.sizeAt),0),l.set(a,t.sizeAt);let c=t.sizeAt+a.length;return l.set(r.subarray(t.dataStart,n),c),c+=n-t.dataStart,l.set(i,c),c+=i.length,l.set(r.subarray(n),c),l}function wn(r,e,t){let i={},n=(s,o,a)=>{let l=s;for(;l<o;){let c=Oi(r,l);if(!c)return;let u=Ue(r,l+c.width);if(!u||u.unknown)return;let f=l+c.width+u.width;a(c.id,f,Math.min(o,f+u.size)),l=f+u.size}};return n(e,t,(s,o,a)=>{s===U.Tag&&n(o,a,(l,c,u)=>{if(l!==U.SimpleTag)return;let f=null,h=null;n(c,u,(d,p,g)=>{d===U.TagName?f=Ci(r.subarray(p,g)):d===U.TagString&&(h=Ci(r.subarray(p,g)))}),f!==null&&(i[f]=h??"")})}),i}function Wo(r){let e=vn(r);if(!e)return null;let t=e.unknown?r.length:Math.min(r.length,e.dataStart+e.size),i=null,n=e.dataStart;for(;n<t;){let s=Oi(r,n);if(!s)break;let o=Ue(r,n+s.width);if(!o)break;let a=n+s.width+o.width;if(s.id===U.Tags&&!o.unknown&&(i={...i||{},...wn(r,a,Math.min(t,a+o.size))}),o.unknown){i=i||Ho(r,t);break}n=a+o.size}return i}function Ho(r,e){let t=mn(U.Tags);for(let i=e-t.length-1;i>=0;i--){if(r[i]!==t[0]||r[i+1]!==t[1]||r[i+2]!==t[2]||r[i+3]!==t[3])continue;let n=Ue(r,i+4);if(n&&!n.unknown&&i+4+n.width+n.size===e)return wn(r,i+4+n.width,e)}return null}var bn=r=>zo(Wo(r));var oe="[inline3d/camera]",cs="inline3d-camera/1",la=200,ca=240,ha=66,ua=4e3,da=4,fa=1500,pa=2e4,ma=["video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm","video/mp4"],At=()=>typeof document<"u"&&document&&typeof document.createElement=="function",as=()=>{let r=new Date,e=t=>String(t).padStart(2,"0");return`${r.getFullYear()}${e(r.getMonth()+1)}${e(r.getDate())}-${e(r.getHours())}${e(r.getMinutes())}${e(r.getSeconds())}`},ga=r=>/jpe?g/.test(r)?"jpg":/png/.test(r)?"png":/webp/.test(r)?"webp":/mp4/.test(r)?"mp4":/webm/.test(r)?"webm":"bin";function Lt(r,e,t){return`${String(r||"capture").replace(/[^\w.-]+/g,"-").replace(/^-+|-+$/g,"")||"capture"}${e==="sbs"?"_2x1":""}.${ga(t)}`}var te=(r,e,t={})=>Object.assign(new Error(`${oe} ${r}`),{code:e,...t});function ls(r,e=ua){return r?(r.readyState||0)>=2&&r.videoWidth?Promise.resolve():new Promise((t,i)=>{let n=!1,s=()=>{n||(r.readyState||0)<2||!r.videoWidth||(n=!0,clearTimeout(o),r.removeEventListener("loadeddata",s),r.removeEventListener("playing",s),r.removeEventListener("resize",s),t())},o=setTimeout(()=>{n||(n=!0,i(te("the camera delivered no frame in time","no-frame")))},e);r.addEventListener("loadeddata",s),r.addEventListener("playing",s),r.addEventListener("resize",s),r.play?.().catch(()=>{})}):Promise.reject(te("no video element (no document?)","no-frame"))}function hs(r,e,t=ca){let i=r.videoWidth,n=r.videoHeight;if(!i||!n||(r.readyState||0)<2)return null;let s=Math.min(1,t/(i/2)),o=Math.max(2,Math.round(i*s/2)*2),a=Math.max(2,Math.round(n*s));(e.width!==o||e.height!==a)&&(e.width=o,e.height=a);let l=e.getContext("2d",{willReadFrequently:!0});try{return l.drawImage(r,0,0,o,a),{img:ut(l.getImageData(0,0,o,a).data,o*a),w:o,h:a,scale:o/i}}catch{return null}}var Zi=class{constructor(e,{log:t=null}={}){this.format=e.format,this.stream=e.stream,this.width=e.width||0,this.height=e.height||0,this.deviceId=e.deviceId||null,this.label=e.label||"",this.owned=!!e.owned,this.skipped=Object.freeze([...e.skipped||[]]),this.calibration=Object.freeze({...e.calibration||{}});let i=this.calibration;this.stereo=this.format==="sbs"?Object.freeze({rectified:!!i.rectified,baselineMm:i.baselineMm>0?i.baselineMm:null,horizontalFovDeg:i.hfovDeg>0?i.hfovDeg:null}):null,this.state="live",this._log=t,this._listeners=new Map,this._scratch=null,this._views=new Set,this.video=null,At()&&(this.video=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,autoplay:!0}),this.video.srcObject=this.stream,this.video.play?.().catch(()=>{})),this._onEnded=()=>this._ended("ended");for(let n of this.stream.getVideoTracks())n.addEventListener?.("ended",this._onEnded)}get facing(){try{let e=this.stream.getVideoTracks()[0]?.getSettings?.().facingMode;return typeof e=="string"&&e?e:null}catch{return null}}get eyeWidth(){return this.format==="sbs"?this.width/2:this.width}log(e,t={}){this._log&&this._log(e,t)}on(e,t){if(typeof t!="function")throw new TypeError(`${oe} on() takes a function`);return this._listeners.has(e)||this._listeners.set(e,new Set),this._listeners.get(e).add(t),()=>this._listeners.get(e)?.delete(t)}off(e,t){this._listeners.get(e)?.delete(t)}_emit(e,t){for(let i of[...this._listeners.get(e)||[]])try{i(t)}catch(n){console.error(`${oe} '${e}' listener threw`,n)}}_ended(e){this.state==="live"&&(this.state="ended",this.log("ended",{reason:e}),this._emit("ended",{reason:e}))}async measureConvergence(){if(this.format!=="sbs"||!this.video||!At())return null;try{await ls(this.video)}catch{return null}this._scratch=this._scratch||document.createElement("canvas");let e=hs(this.video,this._scratch);if(!e)return null;let t=$e().measure(e.img,e.w,e.h,0);return t?t.d/e.scale:null}_meta(e,t=this.width,i=this.height){let n=this.stereo;return{layout:this.format,convergencePx:e,baselineMm:n?n.baselineMm:null,horizontalFovDeg:n?n.horizontalFovDeg:null,rectified:n?n.rectified:null,eyeWidth:this.format==="sbs"?t/2:t,eyeHeight:i,software:cs}}async capturePhoto({type:e="image/jpeg",quality:t=.92,name:i,convergencePx:n}={}){if(this.state==="closed")throw te("the camera is closed","closed");if(!this.video||!At())throw te("capturePhoto needs a document","no-frame");await ls(this.video);let s=this.video.videoWidth,o=this.video.videoHeight,a=typeof n=="number"&&Number.isFinite(n)?n:await this.measureConvergence(),l=document.createElement("canvas");l.width=s,l.height=o,l.getContext("2d").drawImage(this.video,0,0,s,o);let c=await new Promise((d,p)=>l.toBlob(g=>g?d(g):p(te("toBlob produced nothing","encode-failed")),e,t)),u=this._meta(a,s,o),f=null;(c.type==="image/jpeg"||/jpe?g/.test(e))&&(f=cn(u),c=new Blob([fn(new Uint8Array(await c.arrayBuffer()),f)],{type:"image/jpeg"}));let h={blob:c,type:c.type||e,width:s,height:o,layout:this.format,convergencePx:a,stereo:this.stereo,suggestedName:Lt(i||`photo-${as()}`,this.format,c.type||e),xmp:f};return this.log("photo",{width:s,height:o,layout:this.format,convergencePx:a,bytes:c.size,name:h.suggestedName}),h}record({mimeType:e,mono:t=!1,audio:i=null,videoBitsPerSecond:n,timesliceMs:s=1e3,name:o,fps:a=30}={}){if(this.state==="closed")throw te("the camera is closed","closed");if(typeof MediaRecorder!="function")throw te("MediaRecorder is not available here","unsupported");let l=e||ma.find(v=>typeof MediaRecorder.isTypeSupported!="function"||MediaRecorder.isTypeSupported(v))||"";if(l&&typeof MediaRecorder.isTypeSupported=="function"&&!MediaRecorder.isTypeSupported(l))throw te(`${l} is not a supported recording type here`,"unsupported");let c=[...this.stream.getVideoTracks()],u=i&&typeof i.getAudioTracks=="function"?i.getAudioTracks():i&&i.kind==="audio"?[i]:[];c.push(...u);let f=new MediaStream(c),h={...l?{mimeType:l}:{},...n?{videoBitsPerSecond:n}:{}},d=new MediaRecorder(f,h),p=[];d.ondataavailable=v=>v.data&&v.data.size&&p.push(v.data);let g=null,w=[],m=null,_=0,S=!!t&&this.format==="sbs"&&At()&&this.video;if(S){m=document.createElement("canvas");let v=()=>{_=requestAnimationFrame(v);let y=this.video,E=y.videoWidth,I=y.videoHeight;!E||!I||(y.readyState||0)<2||((m.width!==E/2||m.height!==I)&&(m.width=E/2,m.height=I),m.getContext("2d").drawImage(y,0,0,E/2,I,0,0,E/2,I))};v();let b=m.captureStream(a);for(let y of u)b.addTrack(y);g=new MediaRecorder(b,h),g.ondataavailable=y=>y.data&&y.data.size&&w.push(y.data)}let x=performance.now(),C=[],M=this.format==="sbs"?setInterval(()=>this.measureConvergence().then(v=>v!==null&&C.push(v)),1500):0;this.measureConvergence().then(v=>v!==null&&C.push(v)),d.start(s),g?.start(s),this.log("record-start",{mimeType:l,mono:S,audio:u.length});let k=(v,b)=>new Promise(y=>{if(!v||v.state==="inactive")return y(b);v.onstop=()=>y(b),v.stop()}),P=o||`clip-${as()}`,D=this;return{get state(){return d.state},get mimeType(){return d.mimeType||l},pause(){d.state==="recording"&&d.pause(),g&&g.state==="recording"&&g.pause()},resume(){d.state==="paused"&&d.resume(),g&&g.state==="paused"&&g.resume()},async stop(){clearInterval(M),_&&cancelAnimationFrame(_);let[v,b]=await Promise.all([k(d,p),k(g,w)]),y=d.mimeType||l||v[0]&&v[0].type||"video/webm",E=[...C].sort((Te,G)=>Te-G),I=E.length?E[Math.floor(E.length/2)]:null,O=D._meta(I),N=/webm|matroska/.test(y),$=async(Te,G)=>{let re=new Blob(Te,{type:y});if(N&&re.size)try{re=new Blob([yn(new Uint8Array(await re.arrayBuffer()),_n({...O,layout:G}))],{type:y})}catch(mr){D.log("record-tag-failed",{message:String(mr&&mr.message)})}return re},L=await $(v,D.format),j={blob:L,type:y,layout:D.format,durationMs:Math.round(performance.now()-x),convergencePx:I,stereo:D.stereo,suggestedName:Lt(P,D.format,y),tagged:N&&L.size>0};return g&&(j.mono=await $(b,"mono"),j.monoSuggestedName=Lt(P,"mono",y)),D.log("record-stop",{bytes:L.size,mono:j.mono?j.mono.size:null,ms:j.durationMs,convergencePx:I,name:j.suggestedName}),j}}}close(){if(this.state!=="closed"){this.state="closed";for(let e of this.stream.getVideoTracks())e.removeEventListener?.("ended",this._onEnded);for(let e of[...this._views])e.remove();this.owned&&this.stream.getTracks().forEach(e=>e.stop()),this.video&&(this.video.srcObject=null),this.log("closed",{})}}};async function er(r={}){let e=typeof r=="string"||r&&typeof r.getVideoTracks=="function"?{prefer:r}:r||{},t=e.prefer===void 0||e.prefer===null?"auto":e.prefer,i=typeof e.log=="function"?e.log:e.debug?(a,l)=>console.log(`${oe} ${a} ${JSON.stringify(l)}`):null,n=e.calibration&&typeof e.calibration=="object"?{...e.calibration}:{};n.horizontalFovDeg>0&&!(n.hfovDeg>0)&&(n.hfovDeg=n.horizontalFovDeg),delete n.horizontalFovDeg;let s=await en(t,{format:e.format,calibration:n,mediaDevices:e.mediaDevices,log:i||void 0});if(s.format==="sbs"&&typeof e.rectify=="function")try{let a=await e.rectify(s.stream,{width:s.width,height:s.height,deviceId:s.deviceId,label:s.label});a&&typeof a.getVideoTracks=="function"&&(s.stream=a,s.calibration={...s.calibration,rectified:!0})}catch(a){i?.("rectify-failed",{message:String(a&&a.message)}),s.rectifyError=a}let o=new Zi(s,{log:i});return s.rectifyError&&(o.rectifyError=s.rectifyError),o.log("open",{format:o.format,width:o.width,height:o.height,label:o.label,stereo:o.stereo,skipped:o.skipped.length}),o}var It=r=>!!r&&typeof r=="object"&&typeof r.capturePhoto=="function"&&typeof r.record=="function"&&r.stream&&typeof r.stream.getVideoTracks=="function";function _a(r){let e=Math.min(globalThis.devicePixelRatio||1,2),t=Math.round((r.clientWidth||0)*e),i=Math.round((r.clientHeight||0)*e);return!t||!i?!1:((r.width!==t||r.height!==i)&&(r.width=t,r.height=i),!0)}function tr(r,e,t,i={}){if(!e||typeof e.getContext!="function")throw new TypeError(`${oe} addCameraView(wall, canvas, cam, opts) needs a canvas`);if(!It(t))throw new TypeError(`${oe} addCameraView: cam must be a StereoCamera from openCamera()`);let n=new Qi(r,e,t,i);return t._views?.add(n),n}var Qi=class{constructor(e,t,i,n){this.wall=e||null,this.canvas=t,this.cam=i,this.mirror=n.mirror===void 0?i.facing!=="environment":!!n.mirror,this.aspect=typeof n.aspect=="number"&&n.aspect>.3&&n.aspect<4?n.aspect:16/9,this.autoConverge=!!n.autoConverge,this.conv=Fe(),this.conv.depth=0,this.setDepth(n.depth),this.route=null,this.handle=null,this.fallbackReason=null,this._fw=null,this._onRouteChange=typeof n.onRouteChange=="function"?n.onRouteChange:null,this._layerFails=0,this._layerTimer=0,this.buffer=null,this.removed=!1,this._raf=0,this._loop=n._loop!==!1,this._autoAt=0,this._track=dt(),this._focus=$e(),this._scratch=null,this._luma=null,this.disparityPx=null,this._cursorOpt=vt(n.cursor,"@displayxr/inline3d/camera"),this.cursor=null,this._cursorOpt&&Promise.resolve().then(()=>(Ji(),Ki)).then(s=>{this.removed||(this.cursor=new s.PairCursor(this.canvas,this._cursorOpt))}),this._reroute(!1),this._loop&&this._start()}get woven(){return this.route==="woven-sbs"}weaveState(){return{route:this.route,woven:this.woven,reason:this.fallbackReason,firstWoven:this.route==="woven-sbs"?this._fw?{...this._fw}:"pending":null,layerRetries:this._layerFails}}get convergencePx(){return this.conv.current}get depth(){return this.conv.depth}setDepth(e){let t=e==null||!Number.isFinite(+e)?0:Math.max(-1,Math.min(1,+e));return this.conv.depth=t,t}setMirror(e){return this.mirror=e===void 0?!this.mirror:!!e,this.mirror}setAutoConverge(e){return this.autoConverge=e===void 0?!this.autoConverge:!!e,this.autoConverge||(this._track.reset(),this._focus.reset(),this.conv.measuredPx=null,this.disparityPx=null),this.autoConverge}_reroute(e,t){if(t!==void 0&&(this.wall=t),this.removed)return;e&&this.fallbackReason&&(this.fallbackReason=null,clearTimeout(this._layerTimer),this._layerTimer=0);let i=this.cam,n=i.state==="live"&&i.video,o=i.format==="sbs"&&n&&this.wall&&this.wall.supported&&!this.fallbackReason?"woven-sbs":i.format==="sbs"?"flat-left":"flat";if(!e&&o===this.route)return;let a=this.route;this._unregister(),this.route=o,o==="woven-sbs"&&this._registerWoven(),o!==a&&this._routeChanged()}_registerWoven(){this.buffer||(this.buffer=document.createElement("canvas")),this._paintWoven();let e=this.wall.addImage(this.canvas,this.buffer);this.handle=e,this._fw=null;let t=e&&e.firstWoven;!t||typeof t.then!="function"||t.then(i=>{this.handle!==e||this.removed||!i||(this._fw={woven:!!i.woven,confirmed:!!i.confirmed,reason:i.reason||null,ms:i.ms},this.cam.log?.("view-first-woven",{woven:!!i.woven,reason:i.reason||null}),i.woven?(this._layerFails=0,this._routeChanged()):i.reason!=="removed"&&this._layerLost(i.reason||"layer-failed"))})}_layerLost(e){if(this.fallbackReason=e,this._reroute(!1),e!=="layer-failed"||this._layerFails>=da)return;let t=Math.min(pa,fa*Math.pow(2,this._layerFails++));this.cam.log?.("view-layer-retry",{attempt:this._layerFails,inMs:t}),clearTimeout(this._layerTimer),this._layerTimer=setTimeout(()=>{this._layerTimer=0,!(this.removed||this.fallbackReason!==e)&&this._reroute(!0)},t)}_routeChanged(){if(this._onRouteChange)try{this._onRouteChange(this.route,this.weaveState())}catch(e){console.error(`${oe} onRouteChange threw`,e)}}_onWallLost(){this._reroute(!0,{supported:!1})}_unregister(){if(this.handle){try{this.handle.remove()}catch{}this.handle=null}}_start(){let e=()=>{this._raf=requestAnimationFrame(e),this.paint()};this._raf=requestAnimationFrame(e)}paint(){if(this.removed)return;let e=this.cam.video;!e||this.cam.state==="closed"||(this.route==="woven-sbs"?this._paintWoven():this._paintFlat(e))}_paintFlat(e){if(this.cursor?.idle(),!_a(this.canvas))return;let t=e.videoWidth,i=e.videoHeight;if(!t||!i||(e.readyState||0)<2)return;let n=this.canvas.getContext("2d"),s=this.route==="flat-left"?t/2:t,o=q(s,i,this.canvas.width/this.canvas.height,0,0);n.save(),this.mirror&&(n.translate(this.canvas.width,0),n.scale(-1,1)),n.drawImage(e,o.sx,o.sy,o.sw,o.sh,0,0,this.canvas.width,this.canvas.height),n.restore()}_paintWoven(){let e=this.cam.video,t=e.videoWidth,i=e.videoHeight;if(!t||!i||(e.readyState||0)<2||!this.buffer)return;let n=t/2,s=this.aspect,{w:o,h:a}=Ie(n,i,s),l=this.buffer;(l.width!==2*o||l.height!==a)&&(l.width=2*o,l.height=a);let c=!!(this.cursor&&this.cursor.hovering);(this.autoConverge||c)&&this._sample(e,c);let u=this.conv.step(n),f=l.getContext("2d");if(this.mirror)for(let h of fe(t,i)){let d=h.src==="L"?0:1,p=q(n,i,s,u,d),g=h.dx===0?0:o;f.save(),f.translate(g+o,0),f.scale(-1,1),f.drawImage(e,h.sx+p.sx,p.sy,p.sw,p.sh,0,0,o,a),f.restore()}else for(let h of[0,1]){let d=q(n,i,s,u,h);f.drawImage(e,h*n+d.sx,d.sy,d.sw,d.sh,h*o,0,o,a)}if(this.cursor){let h={rL:q(n,i,s,u,0),rR:q(n,i,s,u,1),outW:o,outH:a,mirror:this.mirror,handle:this.handle};this.cursor.draw(f,this._luma,h,performance.now()/1e3)}}_sample(e,t=!1){let i=performance.now();if(i-this._autoAt<(t?ha:la))return;this._autoAt=i,this._scratch=this._scratch||document.createElement("canvas");let n=hs(e,this._scratch);if(n&&(this._luma=n),!this.autoConverge)return;let s=n?this._focus.measure(n.img,n.w,n.h,i):null,o=this._track.push(s?s.d/n.scale:null);this.conv.measuredPx=o,this.disparityPx=o}remove(){this.removed||(this.removed=!0,this._raf&&cancelAnimationFrame(this._raf),this._raf=0,clearTimeout(this._layerTimer),this._layerTimer=0,this._unregister(),this.cursor?.dispose(),this.cursor=null,this.cam._views?.delete(this))}};var ds=[[-1,7,10,15,20,26,18,20,24,30,18],[-1,10,16,26,18,24,16,18,22,22,26]],fs=[[-1,1,1,1,1,1,2,2,2,2,4],[-1,1,1,1,2,2,4,4,4,5,5]],va=[1,0],ir=10;function ps(r){let e=(16*r+128)*r+64;if(r>=2){let t=Math.floor(r/7)+2;e-=(25*t-10)*t-55,r>=7&&(e-=36)}return e}var us=(r,e)=>Math.floor(ps(r)/8)-ds[e][r]*fs[e][r];function rr(r,e){let t=0;for(let i=7;i>=0;i--)t=t<<1^(t>>>7)*285,t^=(e>>>i&1)*r;return t}function ya(r){let e=new Array(r-1).fill(0);e.push(1);let t=1;for(let i=0;i<r;i++){for(let n=0;n<e.length;n++)e[n]=rr(e[n],t),n+1<e.length&&(e[n]^=e[n+1]);t=rr(t,2)}return e}function wa(r,e){let t=e.map(()=>0);for(let i of r){let n=i^t.shift();t.push(0),e.forEach((s,o)=>t[o]^=rr(s,n))}return t}function nr(r,e={}){let t=e.ecl==="L"?0:1,i=[...new TextEncoder().encode(String(r))],n=1;for(;n<=ir&&!(4+(n<=9?8:16)+i.length*8<=us(n,t)*8);n++);if(n>ir)throw new Error(`qrEncode: ${i.length} bytes is too long for a version-${ir} code`);let s=[],o=(v,b)=>{for(let y=b-1;y>=0;y--)s.push(v>>>y&1)};o(4,4),o(i.length,n<=9?8:16);for(let v of i)o(v,8);let a=us(n,t)*8;o(0,Math.min(4,a-s.length)),o(0,(8-s.length%8)%8);for(let v=236;s.length<a;v^=253)o(v,8);let l=[];for(let v=0;v<s.length;v+=8)l.push(s.slice(v,v+8).reduce((b,y)=>b<<1|y,0));let c=fs[t][n],u=ds[t][n],f=Math.floor(ps(n)/8),h=c-f%c,d=Math.floor(f/c),p=ya(u),g=[];for(let v=0,b=0;v<c;v++){let y=l.slice(b,b+d-u+(v<h?0:1));b+=y.length;let E=wa(y,p);v<h&&y.push(0),g.push(y.concat(E))}let w=[];for(let v=0;v<g[0].length;v++)for(let b=0;b<g.length;b++)(v!==d-u||b>=h)&&w.push(g[b][v]);let m=n*4+17,_=Array.from({length:m},()=>new Array(m).fill(!1)),S=Array.from({length:m},()=>new Array(m).fill(!1)),x=(v,b,y)=>{_[b][v]=y,S[b][v]=!0};for(let v=0;v<m;v++)x(6,v,v%2===0),x(v,6,v%2===0);let C=(v,b)=>{for(let y=-4;y<=4;y++)for(let E=-4;E<=4;E++){let I=Math.max(Math.abs(E),Math.abs(y)),O=v+E,N=b+y;O>=0&&O<m&&N>=0&&N<m&&x(O,N,I!==2&&I!==4)}};C(3,3),C(m-4,3),C(3,m-4);let M=[];if(n>1){let v=Math.floor(n/7)+2,b=Math.ceil((n*4+4)/(v*2-2))*2;M.push(6);for(let y=m-7;M.length<v;y-=b)M.splice(1,0,y)}for(let v=0;v<M.length;v++)for(let b=0;b<M.length;b++)if(!(v===0&&b===0||v===0&&b===M.length-1||v===M.length-1&&b===0))for(let y=-2;y<=2;y++)for(let E=-2;E<=2;E++)x(M[v]+E,M[b]+y,Math.max(Math.abs(E),Math.abs(y))!==1);let k=v=>{let b=va[t]<<3|v,y=b;for(let O=0;O<10;O++)y=y<<1^(y>>>9)*1335;let E=(b<<10|y)^21522,I=O=>(E>>>O&1)!==0;for(let O=0;O<=5;O++)x(8,O,I(O));x(8,7,I(6)),x(8,8,I(7)),x(7,8,I(8));for(let O=9;O<15;O++)x(14-O,8,I(O));for(let O=0;O<8;O++)x(m-1-O,8,I(O));for(let O=8;O<15;O++)x(8,m-15+O,I(O));x(8,m-8,!0)};if(k(0),n>=7){let v=n;for(let y=0;y<12;y++)v=v<<1^(v>>>11)*7973;let b=n<<12|v;for(let y=0;y<18;y++){let E=(b>>>y&1)!==0,I=m-11+y%3,O=Math.floor(y/3);x(I,O,E),x(O,I,E)}}let P=0;for(let v=m-1;v>=1;v-=2){v===6&&(v=5);for(let b=0;b<m;b++)for(let y=0;y<2;y++){let E=v-y,O=(v+1&2)===0?m-1-b:b;!S[O][E]&&P<w.length*8&&(_[O][E]=(w[P>>>3]>>>7-(P&7)&1)!==0,P++)}}let D=v=>{for(let b=0;b<m;b++)for(let y=0;y<m;y++){if(S[b][y])continue;let E;switch(v){case 0:E=(y+b)%2===0;break;case 1:E=b%2===0;break;case 2:E=y%3===0;break;case 3:E=(y+b)%3===0;break;case 4:E=(Math.floor(y/3)+Math.floor(b/2))%2===0;break;case 5:E=y*b%2+y*b%3===0;break;case 6:E=(y*b%2+y*b%3)%2===0;break;default:E=((y+b)%2+y*b%3)%2===0}E&&(_[b][y]=!_[b][y])}},T=Number.isInteger(e.mask)?e.mask:-1;if(T<0){let v=1/0;for(let b=0;b<8;b++){D(b),k(b);let y=ba(_,m);y<v&&(v=y,T=b),D(b)}}return D(T),k(T),{version:n,size:m,mask:T,modules:_}}function ba(r,e){let t=0,i=[];for(let o=0;o<e;o++)i.push(r[o]);for(let o=0;o<e;o++)i.push(r.map(a=>a[o]));for(let o of i){let a=1;for(let c=1;c<=e;c++)c<e&&o[c]===o[c-1]?a++:(a>=5&&(t+=a-2),a=1);let l=o.map(c=>c?"1":"0").join("");for(let c of["10111010000","00001011101"])for(let u=l.indexOf(c);u>=0;u=l.indexOf(c,u+1))t+=40}let n=0;for(let o=0;o<e;o++)for(let a=0;a<e;a++)if(r[o][a]&&n++,a<e-1&&o<e-1){let l=r[o][a];l===r[o][a+1]&&l===r[o+1][a]&&l===r[o+1][a+1]&&(t+=3)}let s=e*e;return t+=Math.floor(Math.abs(n*20-s*10)/s)*10,t}function ms(r,e,{px:t=4,dark:i="#000",light:n="#fff",ecl:s="M"}={}){let o=nr(e,{ecl:s}),a=o.size+8;r.width=r.height=a*t;let l=r.getContext("2d");l.fillStyle=n,l.fillRect(0,0,a*t,a*t),l.fillStyle=i;for(let c=0;c<o.size;c++)for(let u=0;u<o.size;u++)o.modules[c][u]&&l.fillRect((u+4)*t,(c+4)*t,t,t);return o}function ie(r,e){let t=new Error(`@displayxr/inline3d/call: ${e}`);return t.code=r,t}async function sr(r){let e=await globalThis.crypto.subtle.digest("SHA-256",new TextEncoder().encode(String(r)));return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}var Ft="wss://signal.displayxr.org",gs=Object.freeze([Ft,"wss://dxr-signal.displayxr.workers.dev"]),_s=["bad-room","bad-id","bad-version","bad-key","origin-not-allowed","blocked"];function Re(r=Ft,e={}){if(!r||typeof r!="string")throw ie("no-signaling-url","dxrSignaling(url): url must be a ws:// or wss:// string (omit it for the hosted DisplayXR server)");let t=c=>String(c).replace(/\/+$/,""),i=t(r),n=e.WebSocket||globalThis.WebSocket,s=e.pingMs||2e4,o=Array.isArray(e.aliases)?e.aliases.filter(c=>typeof c=="string"&&c).map(t):gs.includes(i)?[...gs]:[],a=[i,...o.filter(c=>c!==i)],l=0;return{name:"dxr",url:i,async join(c,u){let h=`k=${await sr(c)}${typeof e.key=="string"&&e.key?`&key=${encodeURIComponent(e.key)}`:""}`,d=D=>`${a[D]}/v1/connect?${h}`,p=null,g=!1,w=0,m=null,_=new Set,S=[],x=D=>C(D,a.length),C=(D,T)=>new Promise((v,b)=>{let y=!1,E=!1,I=!1,O=new n(d(l));p=O;let N=$=>{if(!y){y=!0;try{O.close()}catch{}b($)}};O.onopen=()=>{I=!0,O.send(JSON.stringify({t:"join",v:1,room:c,id:u.id,max:u.maxPeers}))},O.onmessage=$=>{let L;try{L=JSON.parse(typeof $.data=="string"?$.data:String($.data))}catch{return}switch(L.t){case"welcome":{w=0;let j=Array.isArray(L.peers)?L.peers.filter(G=>typeof G=="string"):[];clearInterval(m),m=setInterval(()=>M({t:"ping"}),s);let Te=S;S=[];for(let G of Te)M(G);if(D){let G=new Set(j);for(let re of _)G.has(re)||u.onPeerLeft?.(re);_=G,u.onReconnect?.(j)}else _=new Set(j);y=!0,E=!0,v({id:L.id,peers:j,iceServers:Array.isArray(L.iceServers)?L.iceServers:void 0,max:L.max,tier:L.tier==="key"?"key":"anon",key:typeof L.key=="string"?L.key:void 0,turn:L.turn&&typeof L.turn=="object"?L.turn:void 0});break}case"full":g=!0,N(ie("room-full",`this call is full (${L.max} participants)`));break;case"expired":{g=!0,clearInterval(m);let j=ie("expired","this room has reached its lifetime on the signalling server");y?u.onDisconnect?.(j):N(j);break}case"error":if(!y&&_s.includes(L.code))g=!0,N(ie(L.code,L.message||L.code));else if(!y&&(L.code==="rate-limited"||L.code==="quota")){let j=ie(L.code,L.message||L.code);j.retryMs=L.retryMs>0?L.retryMs:0,N(j)}else!y&&L.code==="id-taken"&&N(ie("id-taken","peer id still held; retrying"));break;case"peer-joined":typeof L.id=="string"&&!_.has(L.id)&&(_.add(L.id),u.onPeerJoined?.(L.id));break;case"peer-left":typeof L.id=="string"&&(_.delete(L.id),u.onPeerLeft?.(L.id));break;case"signal":typeof L.from=="string"&&u.onSignal?.(L.from,L.data);break}},O.onerror=()=>{if(!I&&!y&&T>1){y=!0,l=(l+1)%a.length,C(D,T-1).then(v,b);return}N(ie("signaling-unreachable",`cannot reach ${a[l]}`))},O.onclose=()=>{clearInterval(m),N(ie("signaling-closed","signalling closed before joining")),E&&!g&&p===O&&k()}}),M=D=>{p&&p.readyState===1?p.send(JSON.stringify(D)):g||S.push(D)},k=()=>{u.onDisconnect?.();let D=()=>{g||x(!0).catch(T=>{if(g||T&&(T.code==="room-full"||_s.includes(T.code))){u.onDisconnect?.(T);return}setTimeout(D,Math.max(K(w++,{baseMs:500,maxMs:15e3}),T&&T.retryMs||0))})};setTimeout(D,K(w++,{baseMs:300,maxMs:15e3}))};return{...await x(!1),send:(D,T)=>M({t:"signal",to:D,data:T}),leave:()=>{if(!g){g=!0,clearInterval(m);try{p&&p.readyState===1&&p.send(JSON.stringify({t:"leave"})),p&&p.close(1e3,"leave")}catch{}}}}}}}var or=Object.freeze({azure:"#4da3ff",violet:"#9b7bff",magenta:"#ff4fa3",sunset:"#ff7a45",amber:"#ffc23d",lime:"#9be15d",mint:"#35e0b0",ice:"#8fe3ff"}),ys=r=>typeof r=="string"&&or[r.toLowerCase()]||r,ws=Object.freeze({accent:"--dxr-accent",ink:"--dxr-ink",shell:"--dxr-shell",danger:"--dxr-danger",radius:"--dxr-radius",font:"--dxr-font"}),Ge=Object.freeze({lobbyStartTitle:"Start a 3D call",lobbyJoinTitle:"Join the 3D call",lobbyFullTitle:"This call is full",lobbyLeftTitle:"You left the call",lobbyFullText:"It already has {maxPeers} participants.",lobbyText:"Check your framing below. Camera: {camera} \u2014 {kind}.",cameraDefault:"default",kindBusy:"busy (joining audio-only)",kindNone:"none (joining audio-only)",kindSbs:"sending 3D (side-by-side, {width}\xD7{height})",kindMono:"sending 2D ({width}\xD7{height})",liftOff:"Mono cameras: 2D (2D\u21923D is off).",liftChecking:"Mono cameras: checking 2D\u21923D\u2026",liftMissing:"Mono cameras: 2D\u21923D unavailable in this build.",liftNoProvider:"Mono cameras: 2D (no 2D\u21923D provider here).",liftNative:"Mono cameras: 2D\u21923D (native{provider}).",liftWeb:"Mono cameras: 2D\u21923D (in this page, WebGPU).",liftProven:"Mono cameras: 2D\u21923D.",liftUnproven:"Mono cameras: 2D\u21923D (confirmed on the first mono participant).",start:"Start 3D call",join:"Join call",rejoin:"Rejoin",retryCamera:"Retry camera",cameraSelect:"Camera",joining:"Joining\u2026",waitingTitle:"Waiting for others",waitingText:"Share this link (or scan the code). Anyone who opens it joins \u2014 keep it private.",inviteTitle:"Invite",inviteText:"Anyone with this link can join.",inviteLink:"Invite link",copyLink:"Copy link",copied:"Copied",pressCopy:"Press Ctrl/Cmd+C",qrLabel:"QR code of the invite link",banner2D:"You are seeing this call in 2D.",bannerLink:"View in 3D with DisplayXR Browser",mute:"Mute microphone",unmute:"Unmute microphone",cameraOn:"Turn camera on",cameraOff:"Turn camera off",cameraRetry:"No camera \u2014 click to retry",cameraBusyRetry:"{cameraBusy} \u2014 click to retry",depth:"Depth",invite:"Invite",leave:"Leave call",connecting:"Connecting\u2026",reconnecting:"Reconnecting\u2026",leftCall:"Left the call",cameraOffPlate:"Camera off",noCamera:"No camera",unreachable:"Can't reach this participant \u2014 the network needs a relay (TURN)",cameraBusy:"Camera busy \u2014 in use by another app (e.g. eye tracking)",you:"You",badge3D:"3D",badge2D3D:"2D\u21923D",badge2D:"2D",badgePending:"\u2026"});function bs(r){let e={...Ge,...r&&typeof r=="object"?r:{}};return(t,i)=>{let n=typeof e[t]=="string"?e[t]:Ge[t]||t;if(i)for(let[s,o]of Object.entries(i))n=n.split(`{${s}}`).join(String(o));return n}}var vs="dxr-call-style",Ma=`
|
|
19
|
+
`,i=r.split(t),n=i.findIndex(u=>u.startsWith("m=video"));if(n<0)return r;let s=i.findIndex((u,m)=>m>n&&u.startsWith("m="));s<0&&(s=i.length);let o=i.slice(n,s),a=new Map,l=new Map;for(let u of o){let m=u.match(/^a=rtpmap:(\d+) ([\w-]+)\//);m&&a.set(m[1],m[2].toUpperCase());let p=u.match(/^a=fmtp:(\d+) apt=(\d+)/);p&&(l.has(p[2])||l.set(p[2],[]),l.get(p[2]).push(p[1]))}let c=i[n].split(" "),d=c.slice(3),f=[];for(let u of e)for(let m of d)if(a.get(m)===u&&!f.includes(m)){f.push(m);for(let p of l.get(m)||[])d.includes(p)&&!f.includes(p)&&f.push(p)}if(!f.length)return r;let h=d.filter(u=>!f.includes(u));return i[n]=[...c.slice(0,3),...f,...h].join(" "),i.join(t)}var Jr=Object.freeze([{urls:"stun:stun.l.google.com:19302"}]),xo=4e3,So=1e4,Mo=2e4,Eo=8e3,Ro=1e4;function He(r){let e=Number.isInteger(r)?r:pe;return Math.max(2,Math.min(qr,e))}function Zr(r,e){return r<e}var We=class{constructor({signaling:e,id:t,maxPeers:i,iceServers:n,RTCPeerConnection:s,log:o,unreachableMs:a}={}){this.unreachableMs=a>0?a:Ro,this.signaling=e,this.id=t,this.maxPeers=He(i),this.pageIce=n||null,this.iceServers=n||Jr,this.PC=s||globalThis.RTCPeerConnection,this.log=o||(()=>{}),this.peers=new Map,this.session=null,this.ready=!1,this._pending=[],this.stopped=!1,this.sendFormat="mono",this.localStream=null}get size(){return this.peers.size}async start({room:e,localStream:t,sendFormat:i,onPeer:n,onPeerLeft:s,onStream:o,onMessage:a,onPeerState:l,onRefused:c,onSignalingState:d,onGhost:f}){this.localStream=t,this.sendFormat=i||"mono",this.cb={onPeer:n,onPeerLeft:s,onStream:o,onMessage:a,onPeerState:l,onRefused:c,onSignalingState:d,onGhost:f};let h=p=>(...b)=>this.ready?p(...b):this._pending.push(()=>p(...b));this.session=await this.signaling.join(e,{id:this.id,maxPeers:this.maxPeers,onPeerJoined:h(p=>this._onPeerJoined(p)),onPeerLeft:h(p=>this._onPeerLeftSignaling(p)),onSignal:h((p,b)=>this._onSignal(p,b)),onDisconnect:p=>d?.(p?"closed":"reconnecting",p),onPeerUnreachable:h(p=>f?.(p,!0)),onPeerReachable:h(p=>f?.(p,!1)),onReconnect:h(p=>{d?.("connected");for(let b of p)this._onPeerJoined(b)})}),!this.pageIce&&this.session.iceServers&&this.session.iceServers.length&&(this.iceServers=[...Jr,...this.session.iceServers]);let u=this.session.peers||[];if(u.length>=this.maxPeers){this.session.leave();let p=new Error(`@displayxr/inline3d/call: this call is full (${this.maxPeers} participants)`);throw p.code="room-full",p}this.ready=!0;for(let p of u)this._onPeerJoined(p);let m=this._pending;this._pending=[];for(let p of m)p();return this.session}_onPeerJoined(e){if(this.stopped||e===this.id)return;let t=this.peers.get(e);if(t){t.absent=!1,t.state!=="connected"&&Zr(this.id,e)&&this._rebuild(t,"rejoined");return}if(this.peers.size>=this.maxPeers-1){this.log("refused",{peer:e,reason:"maxPeers",maxPeers:this.maxPeers}),this.cb.onRefused?.(e);return}let i=this._newRecord(e);this.cb.onPeer?.(e),i.offerer?this._build(i,1):i.waitTimer=setTimeout(()=>this._askRestart(i),Eo)}_onPeerLeftSignaling(e){let t=this.peers.get(e);t&&(t.absent=!0,t.state!=="connected"&&this._drop(t,"left"))}_newRecord(e){let t={id:e,offerer:Zr(this.id,e),pc:null,builtAt:0,offerAt:0,dc:null,gen:0,state:"new",stream:null,attempts:0,iceRestarted:!1,absent:!1,pendingCandidates:[],timers:new Set,waitTimer:null,unreachable:!1,unreachTimer:null};return this.peers.set(e,t),this._armUnreachable(t),t}_build(e,t){this._closePc(e),e.gen=t,e.builtAt=Date.now(),e.iceRestarted=!1,e.pendingCandidates=[],e.stream=null;let i=new this.PC({iceServers:this.iceServers});e.pc=i;let n=i.createDataChannel("dxr-call",{negotiated:!0,id:0,ordered:!0});if(this._wireDc(e,n),e.offerer){let s=this.localStream?this.localStream.getTracks():[],o=s.find(d=>d.kind==="audio"),a=s.find(d=>d.kind==="video"),l=this.localStream?[this.localStream]:[];i.addTransceiver(o||"audio",{direction:"sendrecv",streams:l});let c=i.addTransceiver(a||"video",{direction:"sendrecv",streams:l});this._preferCodecs(c)}return i.onicecandidate=s=>{s.candidate&&this._signal(e,{kind:"candidate",candidate:s.candidate.toJSON?s.candidate.toJSON():s.candidate})},i.ontrack=s=>{if(e.stream||(e.stream=new MediaStream),!e.stream.getTracks().includes(s.track)){for(let o of e.stream.getTracks())o.kind===s.track.kind&&e.stream.removeTrack(o);e.stream.addTrack(s.track)}this.cb.onStream?.(e.id,e.stream)},i.onconnectionstatechange=()=>this._onConnState(e,i),this._arm(e,Mo,()=>{e.pc===i&&i.connectionState!=="connected"&&this._fail(e,"connect-timeout")}),e.offerer&&this._offer(e).catch(s=>this.log("offer-error",{peer:e.id,err:String(s)})),this._setState(e,e.attempts>0?"reconnecting":"connecting"),i}async _offer(e,{iceRestart:t=!1}={}){let i=e.pc,n=await i.createOffer(t?{iceRestart:!0}:void 0);this._canPreferCodecs||(n.sdp=ze(n.sdp)),await i.setLocalDescription(n),this._signal(e,{kind:"offer",sdp:i.localDescription.sdp})}async _onSignal(e,t){if(this.stopped||!t||typeof t!="object")return;let i=this.peers.get(e);if(!i&&(t.kind!=="offer"||(this._onPeerJoined(e),i=this.peers.get(e),!i)))return;let n=t.gen|0;try{switch(t.kind){case"offer":{if(i.offerer||(clearTimeout(i.waitTimer),n<i.gen))return;i.offerAt=Date.now(),(n>i.gen||!i.pc)&&this._build(i,n);let s=i.pc;await s.setRemoteDescription({type:"offer",sdp:t.sdp}),this._attachAnswererTracks(i);let o=await s.createAnswer();this._canPreferCodecs||(o.sdp=ze(o.sdp)),await s.setLocalDescription(o),this._signal(i,{kind:"answer",sdp:s.localDescription.sdp}),this._flushCandidates(i);break}case"answer":if(!i.offerer||n!==i.gen||!i.pc||i.pc.signalingState!=="have-local-offer")return;await i.pc.setRemoteDescription({type:"answer",sdp:t.sdp}),this._flushCandidates(i);break;case"candidate":if(n!==i.gen||!i.pc)return;i.pc.remoteDescription?await i.pc.addIceCandidate(t.candidate).catch(()=>{}):i.pendingCandidates.push(t.candidate);break;case"restart":if(!i.offerer||i.pc&&i.state!=="connected"&&Date.now()-i.builtAt<5e3)return;this._rebuild(i,"peer-asked");break;case"bye":this._drop(i,"left");break}}catch(s){this.log("signal-error",{peer:e,kind:t.kind,err:String(s)})}}_flushCandidates(e){let t=e.pendingCandidates;e.pendingCandidates=[];for(let i of t)e.pc.addIceCandidate(i).catch(()=>{})}_attachAnswererTracks(e){let t=e.pc,i=this.localStream?this.localStream.getTracks():[];for(let n of t.getTransceivers()){let s=n.receiver&&n.receiver.track?n.receiver.track.kind:null;if(!s||n.sender.track)continue;let o=i.find(a=>a.kind===s);o&&(n.sender.replaceTrack(o).catch(()=>{}),this.localStream&&n.sender.setStreams&&n.sender.setStreams(this.localStream)),n.direction="sendrecv",s==="video"&&this._preferCodecs(n)}}_preferCodecs(e){let t=globalThis.RTCRtpReceiver&&RTCRtpReceiver.getCapabilities&&RTCRtpReceiver.getCapabilities("video");if(this._canPreferCodecs=!!(e&&e.setCodecPreferences&&t),!!this._canPreferCodecs)try{e.setCodecPreferences(ct(t.codecs))}catch{this._canPreferCodecs=!1}}_onConnState(e,t){if(e.pc!==t)return;let i=t.connectionState;this.log("pc-state",{peer:e.id,state:i,gen:e.gen}),i==="connected"?(this._clearTimers(e),e.attempts=0,e.iceRestarted=!1,this._setState(e,"connected"),this.tuneSenders()):i==="disconnected"?(this._setState(e,"reconnecting"),this._arm(e,xo,()=>{e.pc===t&&t.connectionState!=="connected"&&this._fail(e,"disconnected")})):i==="failed"?this._fail(e,"failed"):i==="closed"&&!this.stopped&&this.peers.get(e.id)===e&&this._fail(e,"closed")}_fail(e,t){if(this.stopped||this.peers.get(e.id)!==e)return;if(e.absent)return this._drop(e,"left");if(this._setState(e,"reconnecting"),!e.offerer)return this._askRestart(e);let i=e.pc;if(i&&!e.iceRestarted&&i.connectionState!=="closed"&&i.signalingState!=="closed"){e.iceRestarted=!0,this.log("ice-restart",{peer:e.id,why:t,gen:e.gen}),this._offer(e,{iceRestart:!0}).catch(()=>this._rebuild(e,"ice-restart-failed")),this._arm(e,So,()=>{e.pc===i&&i.connectionState!=="connected"&&this._rebuild(e,"ice-restart-timeout")});return}this._rebuild(e,t)}_rebuild(e,t){if(this.stopped||this.peers.get(e.id)!==e)return;this._clearTimers(e),this._closePc(e),this._setState(e,"reconnecting");let i=K(e.attempts++);this.log("redial",{peer:e.id,why:t,attempt:e.attempts,inMs:i}),this._arm(e,i,()=>this._build(e,e.gen+1))}_askRestart(e){if(this.stopped||this.peers.get(e.id)!==e||e.offerer)return;let t=Date.now();this._signal(e,{kind:"restart"}),this._arm(e,Math.max(3e3,K(e.attempts++)),()=>{e.state!=="connected"&&!(e.offerAt>=t)&&this._askRestart(e)})}_drop(e,t){this.peers.get(e.id)===e&&(this._clearTimers(e),clearTimeout(e.unreachTimer),clearTimeout(e.waitTimer),this._closePc(e),this.peers.delete(e.id),this._setState(e,"left"),this.cb.onPeerLeft?.(e.id,t),this.tuneSenders())}_closePc(e){if(e.dc){try{e.dc.close()}catch{}e.dc=null}if(e.pc){let t=e.pc;e.pc=null;try{t.close()}catch{}}}_arm(e,t,i){let n=setTimeout(()=>{e.timers.delete(n),i()},t);e.timers.add(n)}_clearTimers(e){for(let t of e.timers)clearTimeout(t);e.timers.clear()}_armUnreachable(e){e.unreachTimer||e.unreachable||(e.unreachTimer=setTimeout(()=>{e.unreachTimer=null,!(this.stopped||this.peers.get(e.id)!==e||e.state==="connected")&&(e.unreachable=!0,this.log("unreachable",{peer:e.id,afterMs:this.unreachableMs,pc:e.pc?e.pc.iceConnectionState:null}),this._setState(e,"unreachable"))},this.unreachableMs))}_setState(e,t){t==="connected"?(clearTimeout(e.unreachTimer),e.unreachTimer=null,e.unreachable=!1):(t==="connecting"||t==="reconnecting")&&(e.unreachable?t="unreachable":this._armUnreachable(e)),e.state!==t&&(e.state=t,this.cb.onPeerState?.(e.id,t))}_signal(e,t){this.session?.send(e.id,{...t,gen:e.gen})}_wireDc(e,t){e.dc=t,t.onopen=()=>this.cb.onMessage?.(e.id,{type:"__open"}),t.onmessage=i=>{let n;try{n=JSON.parse(i.data)}catch{return}if(n&&n.type==="bye")return this._drop(e,"left");this.cb.onMessage?.(e.id,n)}}send(e,t){let i=this.peers.get(e);return i&&i.dc&&i.dc.readyState==="open"?(i.dc.send(JSON.stringify(t)),!0):!1}broadcast(e){for(let t of this.peers.keys())this.send(t,e)}peerConnection(e){let t=this.peers.get(e);return t?t.pc:null}peerState(e){let t=this.peers.get(e);return t?t.state:null}async replaceTrack(e,t,i){i&&(this.localStream=i);for(let n of this.peers.values())if(n.pc)for(let s of n.pc.getTransceivers())(s.receiver&&s.receiver.track?s.receiver.track.kind:null)===e&&await s.sender.replaceTrack(t).catch(()=>{});await this.tuneSenders()}setSendFormat(e){return this.sendFormat=e,this.tuneSenders()}async tuneSenders(){let e=this.peers.size,t=lt(this.sendFormat,e);for(let i of this.peers.values())if(i.pc){for(let n of i.pc.getSenders())if(!(!n.track||n.track.kind!=="video"))try{let s=n.getParameters();s.degradationPreference="maintain-resolution",(!s.encodings||!s.encodings.length)&&(s.encodings=[{}]),s.encodings[0].maxBitrate=t*1e3,await n.setParameters(s)}catch(s){this.log("setParameters-error",{peer:i.id,err:String(s)})}}return t}stop(){if(!this.stopped){this.broadcast({type:"bye"}),this.stopped=!0;for(let e of this.peers.values())this._clearTimers(e),clearTimeout(e.waitTimer),clearTimeout(e.unreachTimer),this._signal(e,{kind:"bye"}),this._closePc(e);this.peers.clear();try{this.session?.leave()}catch{}}}_debugKill(e){let t=this.peers.get(e);return!t||!t.pc?!1:(this._closePc(t),this._fail(t,"debug-kill"),!0)}};var xi={width:{ideal:1280},height:{ideal:720},frameRate:{ideal:30}},Si={width:{ideal:3840},height:{ideal:1080},frameRate:{ideal:30}},Co=Object.freeze({echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0});function ko(r){return!!r&&(r.name==="NotReadableError"||r.name==="TrackStartError"||/in use|busy/i.test(r.message||""))}function To(r){return!!r&&(r.name==="NotAllowedError"||r.name==="PermissionDeniedError"||r.name==="SecurityError")}function Qr(r){return r.length&&r.every(e=>e.busy)?"camera-busy":r.some(e=>e.denied)?"permission-denied":"no-camera"}function ht(r){return/stereo|\b3d\b|\bsbs\b|dual/i.test(r||"")}async function en(r="auto",e={}){let t=e.mediaDevices||globalThis.navigator&&navigator.mediaDevices,i=e.log||(()=>{}),n=[],s=e.calibration||{};if(r&&typeof r=="object"&&typeof r.getVideoTracks=="function"){let g=r.getVideoTracks()[0],x=g?g.getSettings():{},_=e.format==="sbs"?"sbs":"mono";return{stream:r,format:_,width:x.width||0,height:x.height||0,deviceId:x.deviceId||null,label:g?g.label:"",owned:!1,skipped:n,calibration:s}}if(!t||!t.getUserMedia)throw Object.assign(new Error("getUserMedia is not available (insecure context?)"),{code:"no-camera"});let o=async g=>{let x=await t.getUserMedia({video:g,audio:!1}),_=x.getVideoTracks()[0],M=_?_.getSettings():{};if(!_||_.readyState==="ended"||!(M.width>0)||!(M.height>0))throw x.getTracks().forEach(C=>C.stop()),Object.assign(new Error("the camera opened but delivers no picture (0x0)"),{name:"NotReadableError"});let E=M.displayxrStereo&&M.displayxrStereo.layout==="side-by-side"?M.displayxrStereo:null;return{stream:x,track:_,width:M.width,height:M.height,deviceId:M.deviceId||null,label:_.label||"",stereo:E}},a=(g,x)=>{n.push({label:g,error:`${x.name}: ${x.message}`,busy:ko(x),denied:To(x)}),i("camera-skip",{label:g,error:x.name})},l=g=>g&&g.stream.getTracks().forEach(x=>x.stop()),c=async(g,x)=>{try{await g.track.applyConstraints(x);let _=g.track.getSettings();if(_.width>0&&_.height>0)return{...g,width:_.width,height:_.height}}catch{}return g},d=g=>!!g&&(!!g.stereo||hi(g.width,g.height)),f=(g,x)=>({stream:g.stream,format:x,width:g.width,height:g.height,deviceId:g.deviceId,label:g.label,owned:!0,skipped:n,calibration:{rectified:!1,...x==="sbs"&&g.stereo?{rectified:!!g.stereo.rectified,...g.stereo.baselineMm>0?{baselineMm:g.stereo.baselineMm}:{},...g.stereo.horizontalFovDeg>0?{hfovDeg:g.stereo.horizontalFovDeg}:{}}:{},...s}});if(typeof r=="string"&&!["auto","stereo","mono"].includes(r)){let g;try{g=await o({deviceId:{exact:r},...Si})}catch(x){throw a(r,x),Object.assign(new Error(`camera unavailable: ${x.message}`),{code:Qr(n),skipped:n})}return d(g)?f(g,"sbs"):(l(g),f(await o({deviceId:{exact:r},...xi}),"mono"))}let h=new Set,u=async()=>{try{return(await t.enumerateDevices()).filter(g=>g.kind==="videoinput")}catch{return[]}},m=async g=>{for(let x of g){if(!x.deviceId||!ht(x.label)||h.has(x.deviceId))continue;h.add(x.deviceId);let _=null;try{_=await o({deviceId:{exact:x.deviceId},...Si})}catch(M){a(x.label,M);continue}if(d(_))return i("camera-sbs",{label:_.label,width:_.width,height:_.height,direct:!0}),_;l(_)}return null},p=null;if(r!=="mono"){let g=await u(),x=await m(g);if(x||g.some(_=>_.label)&&!g.some(_=>ht(_.label))&&(g=await u(),x=await m(g),x))return f(x,"sbs");if(g.length&&g.every(_=>!_.label)){let _=null;try{_=await o(!0)}catch(E){a("default",E)}if(_&&d(_))return f(_,"sbs");let M=await m(await u());if(M)return l(_),f(M,"sbs");_&&(p=await c(_,xi))}}if(!p)try{p=await o(xi)}catch(g){a("default",g)}if(r==="mono"&&p)return f(p,"mono");if(p&&d(p))return f(p,"sbs");let b=[];try{b=(await t.enumerateDevices()).filter(g=>g.kind==="videoinput")}catch{}b.sort((g,x)=>Number(ht(x.label))-Number(ht(g.label)));for(let g of b){if(!g.deviceId||p&&g.deviceId===p.deviceId||h.has(g.deviceId))continue;let x=null;try{x=await o({deviceId:{exact:g.deviceId},...Si})}catch(_){a(g.label,_);continue}if(d(x))return l(p),i("camera-sbs",{label:x.label,width:x.width,height:x.height}),f(x,"sbs");l(x)}if(p)return r==="stereo"&&i("camera-no-stereo",{fallback:p.label}),f(p,"mono");let w=Qr(n);throw Object.assign(new Error(w==="camera-busy"?"camera unavailable: in use by another app (e.g. eye tracking) or unable to deliver a picture":w==="permission-denied"?"camera access was denied":"no camera could be opened"),{code:w,skipped:n})}async function tn(r={}){let e=r.mediaDevices||globalThis.navigator&&navigator.mediaDevices;try{return(await e.getUserMedia({audio:{...Co},video:!1})).getAudioTracks()[0]||null}catch(t){return(r.log||(()=>{}))("mic-skip",{error:t&&t.name}),null}}Ei();we();var ln="http://displayxr.org/ns/stereo/1.0/",wt="http://ns.adobe.com/xap/1.0/\0";function xt(r={}){let e=i=>typeof i=="number"&&Number.isFinite(i)?i:null,t=r.layout==="sbs"||r.layout==="side-by-side"?"sbs":"mono";return{layout:t,columns:t==="sbs"?2:1,rows:1,convergencePx:e(r.convergencePx),baselineMm:e(r.baselineMm),horizontalFovDeg:e(r.horizontalFovDeg),rectified:r.rectified===!0?!0:r.rectified===!1?!1:null,eyeWidth:e(r.eyeWidth),eyeHeight:e(r.eyeHeight),software:typeof r.software=="string"&&r.software?r.software:null}}var Fo=r=>String(r).replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<"),xe=r=>Math.round(r*1e3)/1e3;function cn(r){let e=xt(r),t=[["Layout",e.layout==="sbs"?"side-by-side":"mono"],["Columns",e.columns],["Rows",e.rows],["ConvergencePx",e.convergencePx===null?null:xe(e.convergencePx)],["BaselineMm",e.baselineMm===null?null:xe(e.baselineMm)],["HorizontalFovDeg",e.horizontalFovDeg===null?null:xe(e.horizontalFovDeg)],["Rectified",e.rectified===null?null:e.rectified?"True":"False"],["EyeWidth",e.eyeWidth],["EyeHeight",e.eyeHeight],["Software",e.software]].filter(([,i])=>i!=null).map(([i,n])=>` dxr:${i}="${Fo(n)}"`).join("");return`<?xpacket begin="\uFEFF" id="W5M0MpCehiHzreSzNTczkc9d"?><x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:dxr="${ln}"${t}/></rdf:RDF></x:xmpmeta><?xpacket end="w"?>`}function ki(r){if(typeof r!="string"||!r.includes(ln))return null;let e=o=>{let a=new RegExp(`\\bdxr:${o}="([^"]*)"`).exec(r);if(a)return a[1];let l=new RegExp(`<dxr:${o}>([^<]*)</dxr:${o}>`).exec(r);return l?l[1]:null},t=o=>{let a=e(o);return a===null||a===""||!Number.isFinite(+a)?null:+a},i=e("Rectified"),n=e("Layout"),s=e("Software");return xt({layout:n==="side-by-side"||n==="sbs"?"sbs":"mono",convergencePx:t("ConvergencePx"),baselineMm:t("BaselineMm"),horizontalFovDeg:t("HorizontalFovDeg"),rectified:i===null?null:/^true$/i.test(i),eyeWidth:t("EyeWidth"),eyeHeight:t("EyeHeight"),software:s===null?null:s.replace(/"/g,'"').replace(/</g,"<").replace(/&/g,"&")})}var bt=r=>new TextEncoder().encode(r),Ci=r=>new TextDecoder().decode(r),hn=r=>r.length>4&&r[0]===255&&r[1]===216;function*un(r){let e=2;for(;e+4<=r.length;){if(r[e]!==255)return;let t=r[e+1];if(t===216||t>=208&&t<=215||t===1||t===255){e+=t===255?1:2;continue}if(t===218||t===217)return;let i=r[e+2]<<8|r[e+3];if(i<2||e+2+i>r.length)return;yield{marker:t,start:e,end:e+2+i,data:r.subarray(e+4,e+2+i)},e+=2+i}}function dn(r,e){if(r.length<e.length)return!1;for(let t=0;t<e.length;t++)if(r[t]!==e.charCodeAt(t))return!1;return!0}function fn(r,e){if(!hn(r))throw new TypeError("jpegWithXmp: not a JPEG");let t=new Uint8Array([...bt(wt),...bt(e)]),i=t.length+2;if(i>65535)throw new RangeError("jpegWithXmp: XMP packet too large for one APP1 segment");let n=new Uint8Array(4+t.length);n[0]=255,n[1]=225,n[2]=i>>8,n[3]=i&255,n.set(t,4);let s=2,o=null;for(let d of un(r)){if(d.marker===225&&dn(d.data,wt)){o=d;break}if(d.marker===224||d.marker===225)s=d.end;else break}let[a,l]=o?[o.start,o.end]:[s,s],c=new Uint8Array(r.length-(l-a)+n.length);return c.set(r.subarray(0,a),0),c.set(n,a),c.set(r.subarray(l),a+n.length),c}function Ti(r){if(!hn(r))return null;for(let e of un(r))if(e.marker===225&&dn(e.data,wt))return Ci(e.data.subarray(wt.length));return null}var pn=r=>ki(Ti(r)),U={EBML:440786851,Segment:408125543,Tags:307544935,Tag:29555,Targets:25536,SimpleTag:26568,TagName:17827,TagString:17543},No=r=>r.length>4&&r[0]===26&&r[1]===69&&r[2]===223&&r[3]===163;function mn(r){let e=[];for(let t=r;t>0;t=Math.floor(t/256))e.unshift(t%256);return e}function gn(r,e=0){let t=e;if(!t)for(t=1;t<8&&r>2**(7*t)-2;t++);let i=new Array(t).fill(0),n=r;for(let s=t-1;s>=1;s--)i[s]=n%256,n=Math.floor(n/256);return i[0]=128>>t-1|n,i}function Oi(r,e){let t=r[e],i=t>=128?1:t>=64?2:t>=32?3:t>=16?4:0;if(!i||e+i>r.length)return null;let n=0;for(let s=0;s<i;s++)n=n*256+r[e+s];return{id:n,width:i}}function Ue(r,e){let t=r[e],i=1;for(;i<=8&&!(t&128>>i-1);)i++;if(i>8||e+i>r.length)return null;let n=t&255>>i,s=n===127>>i-1;for(let o=1;o<i;o++)n=n*256+r[e+o],r[e+o]!==255&&(s=!1);return{size:n,width:i,unknown:s}}function be(r,e){return[...mn(r),...gn(e.length),...e]}function jo(r){let e=[];for(let[i,n]of Object.entries(r))n!=null&&e.push(...be(U.SimpleTag,[...be(U.TagName,[...bt(String(i))]),...be(U.TagString,[...bt(String(n))])]));let t=be(U.Tag,[...be(U.Targets,[]),...e]);return new Uint8Array(be(U.Tags,t))}function _n(r){let e=xt(r);return{DXR_LAYOUT:e.layout==="sbs"?"side-by-side":"mono",DXR_COLUMNS:String(e.columns),DXR_ROWS:String(e.rows),DXR_CONVERGENCE_PX:e.convergencePx===null?null:String(xe(e.convergencePx)),DXR_BASELINE_MM:e.baselineMm===null?null:String(xe(e.baselineMm)),DXR_HFOV_DEG:e.horizontalFovDeg===null?null:String(xe(e.horizontalFovDeg)),DXR_RECTIFIED:e.rectified===null?null:e.rectified?"true":"false",DXR_EYE_WIDTH:e.eyeWidth===null?null:String(e.eyeWidth),DXR_EYE_HEIGHT:e.eyeHeight===null?null:String(e.eyeHeight),DXR_SOFTWARE:e.software}}function zo(r){if(!r||!("DXR_LAYOUT"in r))return null;let e=t=>r[t]===void 0||r[t]===""||!Number.isFinite(+r[t])?null:+r[t];return xt({layout:r.DXR_LAYOUT==="side-by-side"?"sbs":"mono",convergencePx:e("DXR_CONVERGENCE_PX"),baselineMm:e("DXR_BASELINE_MM"),horizontalFovDeg:e("DXR_HFOV_DEG"),rectified:r.DXR_RECTIFIED===void 0?null:r.DXR_RECTIFIED==="true",eyeWidth:e("DXR_EYE_WIDTH"),eyeHeight:e("DXR_EYE_HEIGHT"),software:r.DXR_SOFTWARE??null})}function vn(r){if(!No(r))return null;let e=Ue(r,4);if(!e)return null;let t=4+e.width+e.size;for(;t<r.length;){let i=Oi(r,t);if(!i)return null;let n=Ue(r,t+i.width);if(!n)return null;let s=t+i.width+n.width;if(i.id===U.Segment)return{sizeAt:t+i.width,sizeWidth:n.width,unknown:n.unknown,dataStart:s,size:n.size};if(n.unknown)return null;t=s+n.size}return null}function yn(r,e){let t=vn(r);if(!t)throw new TypeError("webmWithTags: not a WebM/Matroska file (no Segment)");let i=jo(e);if(t.unknown){let d=new Uint8Array(r.length+i.length);return d.set(r,0),d.set(i,r.length),d}let n=Math.min(r.length,t.dataStart+t.size),s=n-t.dataStart+i.length,o=s<=2**(7*t.sizeWidth)-2,a=gn(s,o?t.sizeWidth:8),l=new Uint8Array(t.sizeAt+a.length+(n-t.dataStart)+i.length+(r.length-n));l.set(r.subarray(0,t.sizeAt),0),l.set(a,t.sizeAt);let c=t.sizeAt+a.length;return l.set(r.subarray(t.dataStart,n),c),c+=n-t.dataStart,l.set(i,c),c+=i.length,l.set(r.subarray(n),c),l}function wn(r,e,t){let i={},n=(s,o,a)=>{let l=s;for(;l<o;){let c=Oi(r,l);if(!c)return;let d=Ue(r,l+c.width);if(!d||d.unknown)return;let f=l+c.width+d.width;a(c.id,f,Math.min(o,f+d.size)),l=f+d.size}};return n(e,t,(s,o,a)=>{s===U.Tag&&n(o,a,(l,c,d)=>{if(l!==U.SimpleTag)return;let f=null,h=null;n(c,d,(u,m,p)=>{u===U.TagName?f=Ci(r.subarray(m,p)):u===U.TagString&&(h=Ci(r.subarray(m,p)))}),f!==null&&(i[f]=h??"")})}),i}function Wo(r){let e=vn(r);if(!e)return null;let t=e.unknown?r.length:Math.min(r.length,e.dataStart+e.size),i=null,n=e.dataStart;for(;n<t;){let s=Oi(r,n);if(!s)break;let o=Ue(r,n+s.width);if(!o)break;let a=n+s.width+o.width;if(s.id===U.Tags&&!o.unknown&&(i={...i||{},...wn(r,a,Math.min(t,a+o.size))}),o.unknown){i=i||Ho(r,t);break}n=a+o.size}return i}function Ho(r,e){let t=mn(U.Tags);for(let i=e-t.length-1;i>=0;i--){if(r[i]!==t[0]||r[i+1]!==t[1]||r[i+2]!==t[2]||r[i+3]!==t[3])continue;let n=Ue(r,i+4);if(n&&!n.unknown&&i+4+n.width+n.size===e)return wn(r,i+4+n.width,e)}return null}var bn=r=>zo(Wo(r));var oe="[inline3d/camera]",cs="inline3d-camera/1",la=200,ca=240,ha=66,ua=4e3,da=4,fa=1500,pa=2e4,ma=["video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm","video/mp4"],Lt=()=>typeof document<"u"&&document&&typeof document.createElement=="function",as=()=>{let r=new Date,e=t=>String(t).padStart(2,"0");return`${r.getFullYear()}${e(r.getMonth()+1)}${e(r.getDate())}-${e(r.getHours())}${e(r.getMinutes())}${e(r.getSeconds())}`},ga=r=>/jpe?g/.test(r)?"jpg":/png/.test(r)?"png":/webp/.test(r)?"webp":/mp4/.test(r)?"mp4":/webm/.test(r)?"webm":"bin";function It(r,e,t){return`${String(r||"capture").replace(/[^\w.-]+/g,"-").replace(/^-+|-+$/g,"")||"capture"}${e==="sbs"?"_2x1":""}.${ga(t)}`}var te=(r,e,t={})=>Object.assign(new Error(`${oe} ${r}`),{code:e,...t});function ls(r,e=ua){return r?(r.readyState||0)>=2&&r.videoWidth?Promise.resolve():new Promise((t,i)=>{let n=!1,s=()=>{n||(r.readyState||0)<2||!r.videoWidth||(n=!0,clearTimeout(o),r.removeEventListener("loadeddata",s),r.removeEventListener("playing",s),r.removeEventListener("resize",s),t())},o=setTimeout(()=>{n||(n=!0,i(te("the camera delivered no frame in time","no-frame")))},e);r.addEventListener("loadeddata",s),r.addEventListener("playing",s),r.addEventListener("resize",s),r.play?.().catch(()=>{})}):Promise.reject(te("no video element (no document?)","no-frame"))}function hs(r,e,t=ca){let i=r.videoWidth,n=r.videoHeight;if(!i||!n||(r.readyState||0)<2)return null;let s=Math.min(1,t/(i/2)),o=Math.max(2,Math.round(i*s/2)*2),a=Math.max(2,Math.round(n*s));(e.width!==o||e.height!==a)&&(e.width=o,e.height=a);let l=e.getContext("2d",{willReadFrequently:!0});try{return l.drawImage(r,0,0,o,a),{img:dt(l.getImageData(0,0,o,a).data,o*a),w:o,h:a,scale:o/i}}catch{return null}}var Zi=class{constructor(e,{log:t=null}={}){this.format=e.format,this.stream=e.stream,this.width=e.width||0,this.height=e.height||0,this.deviceId=e.deviceId||null,this.label=e.label||"",this.owned=!!e.owned,this.skipped=Object.freeze([...e.skipped||[]]),this.calibration=Object.freeze({...e.calibration||{}});let i=this.calibration;this.stereo=this.format==="sbs"?Object.freeze({rectified:!!i.rectified,baselineMm:i.baselineMm>0?i.baselineMm:null,horizontalFovDeg:i.hfovDeg>0?i.hfovDeg:null}):null,this.state="live",this._log=t,this._listeners=new Map,this._scratch=null,this._views=new Set,this.video=null,Lt()&&(this.video=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,autoplay:!0}),this.video.srcObject=this.stream,this.video.play?.().catch(()=>{})),this._onEnded=()=>this._ended("ended");for(let n of this.stream.getVideoTracks())n.addEventListener?.("ended",this._onEnded)}get facing(){try{let e=this.stream.getVideoTracks()[0]?.getSettings?.().facingMode;return typeof e=="string"&&e?e:null}catch{return null}}get eyeWidth(){return this.format==="sbs"?this.width/2:this.width}log(e,t={}){this._log&&this._log(e,t)}on(e,t){if(typeof t!="function")throw new TypeError(`${oe} on() takes a function`);return this._listeners.has(e)||this._listeners.set(e,new Set),this._listeners.get(e).add(t),()=>this._listeners.get(e)?.delete(t)}off(e,t){this._listeners.get(e)?.delete(t)}_emit(e,t){for(let i of[...this._listeners.get(e)||[]])try{i(t)}catch(n){console.error(`${oe} '${e}' listener threw`,n)}}_ended(e){this.state==="live"&&(this.state="ended",this.log("ended",{reason:e}),this._emit("ended",{reason:e}))}async measureConvergence(){if(this.format!=="sbs"||!this.video||!Lt())return null;try{await ls(this.video)}catch{return null}this._scratch=this._scratch||document.createElement("canvas");let e=hs(this.video,this._scratch);if(!e)return null;let t=$e().measure(e.img,e.w,e.h,0);return t?t.d/e.scale:null}_meta(e,t=this.width,i=this.height){let n=this.stereo;return{layout:this.format,convergencePx:e,baselineMm:n?n.baselineMm:null,horizontalFovDeg:n?n.horizontalFovDeg:null,rectified:n?n.rectified:null,eyeWidth:this.format==="sbs"?t/2:t,eyeHeight:i,software:cs}}async capturePhoto({type:e="image/jpeg",quality:t=.92,name:i,convergencePx:n}={}){if(this.state==="closed")throw te("the camera is closed","closed");if(!this.video||!Lt())throw te("capturePhoto needs a document","no-frame");await ls(this.video);let s=this.video.videoWidth,o=this.video.videoHeight,a=typeof n=="number"&&Number.isFinite(n)?n:await this.measureConvergence(),l=document.createElement("canvas");l.width=s,l.height=o,l.getContext("2d").drawImage(this.video,0,0,s,o);let c=await new Promise((u,m)=>l.toBlob(p=>p?u(p):m(te("toBlob produced nothing","encode-failed")),e,t)),d=this._meta(a,s,o),f=null;(c.type==="image/jpeg"||/jpe?g/.test(e))&&(f=cn(d),c=new Blob([fn(new Uint8Array(await c.arrayBuffer()),f)],{type:"image/jpeg"}));let h={blob:c,type:c.type||e,width:s,height:o,layout:this.format,convergencePx:a,stereo:this.stereo,suggestedName:It(i||`photo-${as()}`,this.format,c.type||e),xmp:f};return this.log("photo",{width:s,height:o,layout:this.format,convergencePx:a,bytes:c.size,name:h.suggestedName}),h}record({mimeType:e,mono:t=!1,audio:i=null,videoBitsPerSecond:n,timesliceMs:s=1e3,name:o,fps:a=30}={}){if(this.state==="closed")throw te("the camera is closed","closed");if(typeof MediaRecorder!="function")throw te("MediaRecorder is not available here","unsupported");let l=e||ma.find(v=>typeof MediaRecorder.isTypeSupported!="function"||MediaRecorder.isTypeSupported(v))||"";if(l&&typeof MediaRecorder.isTypeSupported=="function"&&!MediaRecorder.isTypeSupported(l))throw te(`${l} is not a supported recording type here`,"unsupported");let c=[...this.stream.getVideoTracks()],d=i&&typeof i.getAudioTracks=="function"?i.getAudioTracks():i&&i.kind==="audio"?[i]:[];c.push(...d);let f=new MediaStream(c),h={...l?{mimeType:l}:{},...n?{videoBitsPerSecond:n}:{}},u=new MediaRecorder(f,h),m=[];u.ondataavailable=v=>v.data&&v.data.size&&m.push(v.data);let p=null,b=[],w=null,g=0,x=!!t&&this.format==="sbs"&&Lt()&&this.video;if(x){w=document.createElement("canvas");let v=()=>{g=requestAnimationFrame(v);let y=this.video,R=y.videoWidth,I=y.videoHeight;!R||!I||(y.readyState||0)<2||((w.width!==R/2||w.height!==I)&&(w.width=R/2,w.height=I),w.getContext("2d").drawImage(y,0,0,R/2,I,0,0,R/2,I))};v();let S=w.captureStream(a);for(let y of d)S.addTrack(y);p=new MediaRecorder(S,h),p.ondataavailable=y=>y.data&&y.data.size&&b.push(y.data)}let _=performance.now(),M=[],E=this.format==="sbs"?setInterval(()=>this.measureConvergence().then(v=>v!==null&&M.push(v)),1500):0;this.measureConvergence().then(v=>v!==null&&M.push(v)),u.start(s),p?.start(s),this.log("record-start",{mimeType:l,mono:x,audio:d.length});let C=(v,S)=>new Promise(y=>{if(!v||v.state==="inactive")return y(S);v.onstop=()=>y(S),v.stop()}),P=o||`clip-${as()}`,D=this;return{get state(){return u.state},get mimeType(){return u.mimeType||l},pause(){u.state==="recording"&&u.pause(),p&&p.state==="recording"&&p.pause()},resume(){u.state==="paused"&&u.resume(),p&&p.state==="paused"&&p.resume()},async stop(){clearInterval(E),g&&cancelAnimationFrame(g);let[v,S]=await Promise.all([C(u,m),C(p,b)]),y=u.mimeType||l||v[0]&&v[0].type||"video/webm",R=[...M].sort((Te,G)=>Te-G),I=R.length?R[Math.floor(R.length/2)]:null,O=D._meta(I),N=/webm|matroska/.test(y),$=async(Te,G)=>{let re=new Blob(Te,{type:y});if(N&&re.size)try{re=new Blob([yn(new Uint8Array(await re.arrayBuffer()),_n({...O,layout:G}))],{type:y})}catch(mr){D.log("record-tag-failed",{message:String(mr&&mr.message)})}return re},L=await $(v,D.format),j={blob:L,type:y,layout:D.format,durationMs:Math.round(performance.now()-_),convergencePx:I,stereo:D.stereo,suggestedName:It(P,D.format,y),tagged:N&&L.size>0};return p&&(j.mono=await $(S,"mono"),j.monoSuggestedName=It(P,"mono",y)),D.log("record-stop",{bytes:L.size,mono:j.mono?j.mono.size:null,ms:j.durationMs,convergencePx:I,name:j.suggestedName}),j}}}close(){if(this.state!=="closed"){this.state="closed";for(let e of this.stream.getVideoTracks())e.removeEventListener?.("ended",this._onEnded);for(let e of[...this._views])e.remove();this.owned&&this.stream.getTracks().forEach(e=>e.stop()),this.video&&(this.video.srcObject=null),this.log("closed",{})}}};async function er(r={}){let e=typeof r=="string"||r&&typeof r.getVideoTracks=="function"?{prefer:r}:r||{},t=e.prefer===void 0||e.prefer===null?"auto":e.prefer,i=typeof e.log=="function"?e.log:e.debug?(a,l)=>console.log(`${oe} ${a} ${JSON.stringify(l)}`):null,n=e.calibration&&typeof e.calibration=="object"?{...e.calibration}:{};n.horizontalFovDeg>0&&!(n.hfovDeg>0)&&(n.hfovDeg=n.horizontalFovDeg),delete n.horizontalFovDeg;let s=await en(t,{format:e.format,calibration:n,mediaDevices:e.mediaDevices,log:i||void 0});if(s.format==="sbs"&&typeof e.rectify=="function")try{let a=await e.rectify(s.stream,{width:s.width,height:s.height,deviceId:s.deviceId,label:s.label});a&&typeof a.getVideoTracks=="function"&&(s.stream=a,s.calibration={...s.calibration,rectified:!0})}catch(a){i?.("rectify-failed",{message:String(a&&a.message)}),s.rectifyError=a}let o=new Zi(s,{log:i});return s.rectifyError&&(o.rectifyError=s.rectifyError),o.log("open",{format:o.format,width:o.width,height:o.height,label:o.label,stereo:o.stereo,skipped:o.skipped.length}),o}var Ft=r=>!!r&&typeof r=="object"&&typeof r.capturePhoto=="function"&&typeof r.record=="function"&&r.stream&&typeof r.stream.getVideoTracks=="function";function _a(r){let e=Math.min(globalThis.devicePixelRatio||1,2),t=Math.round((r.clientWidth||0)*e),i=Math.round((r.clientHeight||0)*e);return!t||!i?!1:((r.width!==t||r.height!==i)&&(r.width=t,r.height=i),!0)}function tr(r,e,t,i={}){if(!e||typeof e.getContext!="function")throw new TypeError(`${oe} addCameraView(wall, canvas, cam, opts) needs a canvas`);if(!Ft(t))throw new TypeError(`${oe} addCameraView: cam must be a StereoCamera from openCamera()`);let n=new Qi(r,e,t,i);return t._views?.add(n),n}var Qi=class{constructor(e,t,i,n){this.wall=e||null,this.canvas=t,this.cam=i,this.mirror=n.mirror===void 0?i.facing!=="environment":!!n.mirror,this.aspect=typeof n.aspect=="number"&&n.aspect>.3&&n.aspect<4?n.aspect:16/9,this.autoConverge=!!n.autoConverge,this.conv=Fe(),this.conv.depth=0,this.setDepth(n.depth),this.route=null,this.handle=null,this.fallbackReason=null,this._fw=null,this._onRouteChange=typeof n.onRouteChange=="function"?n.onRouteChange:null,this._layerFails=0,this._layerTimer=0,this.buffer=null,this.removed=!1,this._raf=0,this._loop=n._loop!==!1,this._autoAt=0,this._track=ft(),this._focus=$e(),this._scratch=null,this._luma=null,this.disparityPx=null,this._cursorOpt=yt(n.cursor,"@displayxr/inline3d/camera"),this.cursor=null,this._cursorOpt&&Promise.resolve().then(()=>(Ji(),Ki)).then(s=>{this.removed||(this.cursor=new s.PairCursor(this.canvas,this._cursorOpt))}),this._reroute(!1),this._loop&&this._start()}get woven(){return this.route==="woven-sbs"}weaveState(){return{route:this.route,woven:this.woven,reason:this.fallbackReason,firstWoven:this.route==="woven-sbs"?this._fw?{...this._fw}:"pending":null,layerRetries:this._layerFails}}get convergencePx(){return this.conv.current}get depth(){return this.conv.depth}setDepth(e){let t=e==null||!Number.isFinite(+e)?0:Math.max(-1,Math.min(1,+e));return this.conv.depth=t,t}setMirror(e){return this.mirror=e===void 0?!this.mirror:!!e,this.mirror}setAutoConverge(e){return this.autoConverge=e===void 0?!this.autoConverge:!!e,this.autoConverge||(this._track.reset(),this._focus.reset(),this.conv.measuredPx=null,this.disparityPx=null),this.autoConverge}_reroute(e,t){if(t!==void 0&&(this.wall=t),this.removed)return;e&&this.fallbackReason&&(this.fallbackReason=null,clearTimeout(this._layerTimer),this._layerTimer=0);let i=this.cam,n=i.state==="live"&&i.video,o=i.format==="sbs"&&n&&this.wall&&this.wall.supported&&!this.fallbackReason?"woven-sbs":i.format==="sbs"?"flat-left":"flat";if(!e&&o===this.route)return;let a=this.route;this._unregister(),this.route=o,o==="woven-sbs"&&this._registerWoven(),o!==a&&this._routeChanged()}_registerWoven(){this.buffer||(this.buffer=document.createElement("canvas")),this._paintWoven();let e=this.wall.addImage(this.canvas,this.buffer);this.handle=e,this._fw=null;let t=e&&e.firstWoven;!t||typeof t.then!="function"||t.then(i=>{this.handle!==e||this.removed||!i||(this._fw={woven:!!i.woven,confirmed:!!i.confirmed,reason:i.reason||null,ms:i.ms},this.cam.log?.("view-first-woven",{woven:!!i.woven,reason:i.reason||null}),i.woven?(this._layerFails=0,this._routeChanged()):i.reason!=="removed"&&this._layerLost(i.reason||"layer-failed"))})}_layerLost(e){if(this.fallbackReason=e,this._reroute(!1),e!=="layer-failed"||this._layerFails>=da)return;let t=Math.min(pa,fa*Math.pow(2,this._layerFails++));this.cam.log?.("view-layer-retry",{attempt:this._layerFails,inMs:t}),clearTimeout(this._layerTimer),this._layerTimer=setTimeout(()=>{this._layerTimer=0,!(this.removed||this.fallbackReason!==e)&&this._reroute(!0)},t)}_routeChanged(){if(this._onRouteChange)try{this._onRouteChange(this.route,this.weaveState())}catch(e){console.error(`${oe} onRouteChange threw`,e)}}_onWallLost(){this._reroute(!0,{supported:!1})}_unregister(){if(this.handle){try{this.handle.remove()}catch{}this.handle=null}}_start(){let e=()=>{this._raf=requestAnimationFrame(e),this.paint()};this._raf=requestAnimationFrame(e)}paint(){if(this.removed)return;let e=this.cam.video;!e||this.cam.state==="closed"||(this.route==="woven-sbs"?this._paintWoven():this._paintFlat(e))}_paintFlat(e){if(this.cursor?.idle(),!_a(this.canvas))return;let t=e.videoWidth,i=e.videoHeight;if(!t||!i||(e.readyState||0)<2)return;let n=this.canvas.getContext("2d"),s=this.route==="flat-left"?t/2:t,o=q(s,i,this.canvas.width/this.canvas.height,0,0);n.save(),this.mirror&&(n.translate(this.canvas.width,0),n.scale(-1,1)),n.drawImage(e,o.sx,o.sy,o.sw,o.sh,0,0,this.canvas.width,this.canvas.height),n.restore()}_paintWoven(){let e=this.cam.video,t=e.videoWidth,i=e.videoHeight;if(!t||!i||(e.readyState||0)<2||!this.buffer)return;let n=t/2,s=this.aspect,{w:o,h:a}=Ie(n,i,s),l=this.buffer;(l.width!==2*o||l.height!==a)&&(l.width=2*o,l.height=a);let c=!!(this.cursor&&this.cursor.hovering);(this.autoConverge||c)&&this._sample(e,c);let d=this.conv.step(n),f=l.getContext("2d");if(this.mirror)for(let h of fe(t,i)){let u=h.src==="L"?0:1,m=q(n,i,s,d,u),p=h.dx===0?0:o;f.save(),f.translate(p+o,0),f.scale(-1,1),f.drawImage(e,h.sx+m.sx,m.sy,m.sw,m.sh,0,0,o,a),f.restore()}else for(let h of[0,1]){let u=q(n,i,s,d,h);f.drawImage(e,h*n+u.sx,u.sy,u.sw,u.sh,h*o,0,o,a)}if(this.cursor){let h={rL:q(n,i,s,d,0),rR:q(n,i,s,d,1),outW:o,outH:a,mirror:this.mirror,handle:this.handle};this.cursor.draw(f,this._luma,h,performance.now()/1e3)}}_sample(e,t=!1){let i=performance.now();if(i-this._autoAt<(t?ha:la))return;this._autoAt=i,this._scratch=this._scratch||document.createElement("canvas");let n=hs(e,this._scratch);if(n&&(this._luma=n),!this.autoConverge)return;let s=n?this._focus.measure(n.img,n.w,n.h,i):null,o=this._track.push(s?s.d/n.scale:null);this.conv.measuredPx=o,this.disparityPx=o}remove(){this.removed||(this.removed=!0,this._raf&&cancelAnimationFrame(this._raf),this._raf=0,clearTimeout(this._layerTimer),this._layerTimer=0,this._unregister(),this.cursor?.dispose(),this.cursor=null,this.cam._views?.delete(this))}};var ds=[[-1,7,10,15,20,26,18,20,24,30,18],[-1,10,16,26,18,24,16,18,22,22,26]],fs=[[-1,1,1,1,1,1,2,2,2,2,4],[-1,1,1,1,2,2,4,4,4,5,5]],va=[1,0],ir=10;function ps(r){let e=(16*r+128)*r+64;if(r>=2){let t=Math.floor(r/7)+2;e-=(25*t-10)*t-55,r>=7&&(e-=36)}return e}var us=(r,e)=>Math.floor(ps(r)/8)-ds[e][r]*fs[e][r];function rr(r,e){let t=0;for(let i=7;i>=0;i--)t=t<<1^(t>>>7)*285,t^=(e>>>i&1)*r;return t}function ya(r){let e=new Array(r-1).fill(0);e.push(1);let t=1;for(let i=0;i<r;i++){for(let n=0;n<e.length;n++)e[n]=rr(e[n],t),n+1<e.length&&(e[n]^=e[n+1]);t=rr(t,2)}return e}function wa(r,e){let t=e.map(()=>0);for(let i of r){let n=i^t.shift();t.push(0),e.forEach((s,o)=>t[o]^=rr(s,n))}return t}function nr(r,e={}){let t=e.ecl==="L"?0:1,i=[...new TextEncoder().encode(String(r))],n=1;for(;n<=ir&&!(4+(n<=9?8:16)+i.length*8<=us(n,t)*8);n++);if(n>ir)throw new Error(`qrEncode: ${i.length} bytes is too long for a version-${ir} code`);let s=[],o=(v,S)=>{for(let y=S-1;y>=0;y--)s.push(v>>>y&1)};o(4,4),o(i.length,n<=9?8:16);for(let v of i)o(v,8);let a=us(n,t)*8;o(0,Math.min(4,a-s.length)),o(0,(8-s.length%8)%8);for(let v=236;s.length<a;v^=253)o(v,8);let l=[];for(let v=0;v<s.length;v+=8)l.push(s.slice(v,v+8).reduce((S,y)=>S<<1|y,0));let c=fs[t][n],d=ds[t][n],f=Math.floor(ps(n)/8),h=c-f%c,u=Math.floor(f/c),m=ya(d),p=[];for(let v=0,S=0;v<c;v++){let y=l.slice(S,S+u-d+(v<h?0:1));S+=y.length;let R=wa(y,m);v<h&&y.push(0),p.push(y.concat(R))}let b=[];for(let v=0;v<p[0].length;v++)for(let S=0;S<p.length;S++)(v!==u-d||S>=h)&&b.push(p[S][v]);let w=n*4+17,g=Array.from({length:w},()=>new Array(w).fill(!1)),x=Array.from({length:w},()=>new Array(w).fill(!1)),_=(v,S,y)=>{g[S][v]=y,x[S][v]=!0};for(let v=0;v<w;v++)_(6,v,v%2===0),_(v,6,v%2===0);let M=(v,S)=>{for(let y=-4;y<=4;y++)for(let R=-4;R<=4;R++){let I=Math.max(Math.abs(R),Math.abs(y)),O=v+R,N=S+y;O>=0&&O<w&&N>=0&&N<w&&_(O,N,I!==2&&I!==4)}};M(3,3),M(w-4,3),M(3,w-4);let E=[];if(n>1){let v=Math.floor(n/7)+2,S=Math.ceil((n*4+4)/(v*2-2))*2;E.push(6);for(let y=w-7;E.length<v;y-=S)E.splice(1,0,y)}for(let v=0;v<E.length;v++)for(let S=0;S<E.length;S++)if(!(v===0&&S===0||v===0&&S===E.length-1||v===E.length-1&&S===0))for(let y=-2;y<=2;y++)for(let R=-2;R<=2;R++)_(E[v]+R,E[S]+y,Math.max(Math.abs(R),Math.abs(y))!==1);let C=v=>{let S=va[t]<<3|v,y=S;for(let O=0;O<10;O++)y=y<<1^(y>>>9)*1335;let R=(S<<10|y)^21522,I=O=>(R>>>O&1)!==0;for(let O=0;O<=5;O++)_(8,O,I(O));_(8,7,I(6)),_(8,8,I(7)),_(7,8,I(8));for(let O=9;O<15;O++)_(14-O,8,I(O));for(let O=0;O<8;O++)_(w-1-O,8,I(O));for(let O=8;O<15;O++)_(8,w-15+O,I(O));_(8,w-8,!0)};if(C(0),n>=7){let v=n;for(let y=0;y<12;y++)v=v<<1^(v>>>11)*7973;let S=n<<12|v;for(let y=0;y<18;y++){let R=(S>>>y&1)!==0,I=w-11+y%3,O=Math.floor(y/3);_(I,O,R),_(O,I,R)}}let P=0;for(let v=w-1;v>=1;v-=2){v===6&&(v=5);for(let S=0;S<w;S++)for(let y=0;y<2;y++){let R=v-y,O=(v+1&2)===0?w-1-S:S;!x[O][R]&&P<b.length*8&&(g[O][R]=(b[P>>>3]>>>7-(P&7)&1)!==0,P++)}}let D=v=>{for(let S=0;S<w;S++)for(let y=0;y<w;y++){if(x[S][y])continue;let R;switch(v){case 0:R=(y+S)%2===0;break;case 1:R=S%2===0;break;case 2:R=y%3===0;break;case 3:R=(y+S)%3===0;break;case 4:R=(Math.floor(y/3)+Math.floor(S/2))%2===0;break;case 5:R=y*S%2+y*S%3===0;break;case 6:R=(y*S%2+y*S%3)%2===0;break;default:R=((y+S)%2+y*S%3)%2===0}R&&(g[S][y]=!g[S][y])}},T=Number.isInteger(e.mask)?e.mask:-1;if(T<0){let v=1/0;for(let S=0;S<8;S++){D(S),C(S);let y=ba(g,w);y<v&&(v=y,T=S),D(S)}}return D(T),C(T),{version:n,size:w,mask:T,modules:g}}function ba(r,e){let t=0,i=[];for(let o=0;o<e;o++)i.push(r[o]);for(let o=0;o<e;o++)i.push(r.map(a=>a[o]));for(let o of i){let a=1;for(let c=1;c<=e;c++)c<e&&o[c]===o[c-1]?a++:(a>=5&&(t+=a-2),a=1);let l=o.map(c=>c?"1":"0").join("");for(let c of["10111010000","00001011101"])for(let d=l.indexOf(c);d>=0;d=l.indexOf(c,d+1))t+=40}let n=0;for(let o=0;o<e;o++)for(let a=0;a<e;a++)if(r[o][a]&&n++,a<e-1&&o<e-1){let l=r[o][a];l===r[o][a+1]&&l===r[o+1][a]&&l===r[o+1][a+1]&&(t+=3)}let s=e*e;return t+=Math.floor(Math.abs(n*20-s*10)/s)*10,t}function ms(r,e,{px:t=4,dark:i="#000",light:n="#fff",ecl:s="M"}={}){let o=nr(e,{ecl:s}),a=o.size+8;r.width=r.height=a*t;let l=r.getContext("2d");l.fillStyle=n,l.fillRect(0,0,a*t,a*t),l.fillStyle=i;for(let c=0;c<o.size;c++)for(let d=0;d<o.size;d++)o.modules[c][d]&&l.fillRect((d+4)*t,(c+4)*t,t,t);return o}function ie(r,e){let t=new Error(`@displayxr/inline3d/call: ${e}`);return t.code=r,t}async function sr(r){let e=await globalThis.crypto.subtle.digest("SHA-256",new TextEncoder().encode(String(r)));return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}var Nt="wss://signal.displayxr.org",gs=Object.freeze([Nt,"wss://dxr-signal.displayxr.workers.dev"]),_s=["bad-room","bad-id","bad-version","bad-key","origin-not-allowed","blocked"];function Re(r=Nt,e={}){if(!r||typeof r!="string")throw ie("no-signaling-url","dxrSignaling(url): url must be a ws:// or wss:// string (omit it for the hosted DisplayXR server)");let t=c=>String(c).replace(/\/+$/,""),i=t(r),n=e.WebSocket||globalThis.WebSocket,s=e.pingMs||2e4,o=Array.isArray(e.aliases)?e.aliases.filter(c=>typeof c=="string"&&c).map(t):gs.includes(i)?[...gs]:[],a=[i,...o.filter(c=>c!==i)],l=0;return{name:"dxr",url:i,async join(c,d){let h=`k=${await sr(c)}${typeof e.key=="string"&&e.key?`&key=${encodeURIComponent(e.key)}`:""}`,u=D=>`${a[D]}/v1/connect?${h}`,m=null,p=!1,b=0,w=null,g=new Set,x=[],_=D=>M(D,a.length),M=(D,T)=>new Promise((v,S)=>{let y=!1,R=!1,I=!1,O=new n(u(l));m=O;let N=$=>{if(!y){y=!0;try{O.close()}catch{}S($)}};O.onopen=()=>{I=!0,O.send(JSON.stringify({t:"join",v:1,room:c,id:d.id,max:d.maxPeers}))},O.onmessage=$=>{let L;try{L=JSON.parse(typeof $.data=="string"?$.data:String($.data))}catch{return}switch(L.t){case"welcome":{b=0;let j=Array.isArray(L.peers)?L.peers.filter(G=>typeof G=="string"):[];clearInterval(w),w=setInterval(()=>E({t:"ping"}),s);let Te=x;x=[];for(let G of Te)E(G);if(D){let G=new Set(j);for(let re of g)G.has(re)||d.onPeerLeft?.(re);g=G,d.onReconnect?.(j)}else g=new Set(j);y=!0,R=!0,v({id:L.id,peers:j,iceServers:Array.isArray(L.iceServers)?L.iceServers:void 0,max:L.max,tier:L.tier==="key"?"key":"anon",key:typeof L.key=="string"?L.key:void 0,turn:L.turn&&typeof L.turn=="object"?L.turn:void 0});break}case"full":p=!0,N(ie("room-full",`this call is full (${L.max} participants)`));break;case"expired":{p=!0,clearInterval(w);let j=ie("expired","this room has reached its lifetime on the signalling server");y?d.onDisconnect?.(j):N(j);break}case"error":if(!y&&_s.includes(L.code))p=!0,N(ie(L.code,L.message||L.code));else if(!y&&(L.code==="rate-limited"||L.code==="quota")){let j=ie(L.code,L.message||L.code);j.retryMs=L.retryMs>0?L.retryMs:0,N(j)}else!y&&L.code==="id-taken"&&N(ie("id-taken","peer id still held; retrying"));break;case"peer-joined":typeof L.id=="string"&&!g.has(L.id)&&(g.add(L.id),d.onPeerJoined?.(L.id));break;case"peer-left":typeof L.id=="string"&&(g.delete(L.id),d.onPeerLeft?.(L.id));break;case"signal":typeof L.from=="string"&&d.onSignal?.(L.from,L.data);break}},O.onerror=()=>{if(!I&&!y&&T>1){y=!0,l=(l+1)%a.length,M(D,T-1).then(v,S);return}N(ie("signaling-unreachable",`cannot reach ${a[l]}`))},O.onclose=()=>{clearInterval(w),N(ie("signaling-closed","signalling closed before joining")),R&&!p&&m===O&&C()}}),E=D=>{m&&m.readyState===1?m.send(JSON.stringify(D)):p||x.push(D)},C=()=>{d.onDisconnect?.();let D=()=>{p||_(!0).catch(T=>{if(p||T&&(T.code==="room-full"||_s.includes(T.code))){d.onDisconnect?.(T);return}setTimeout(D,Math.max(K(b++,{baseMs:500,maxMs:15e3}),T&&T.retryMs||0))})};setTimeout(D,K(b++,{baseMs:300,maxMs:15e3}))};return{...await _(!1),send:(D,T)=>E({t:"signal",to:D,data:T}),leave:()=>{if(!p){p=!0,clearInterval(w);try{m&&m.readyState===1&&m.send(JSON.stringify({t:"leave"})),m&&m.close(1e3,"leave")}catch{}}}}}}}var or=Object.freeze({azure:"#4da3ff",violet:"#9b7bff",magenta:"#ff4fa3",sunset:"#ff7a45",amber:"#ffc23d",lime:"#9be15d",mint:"#35e0b0",ice:"#8fe3ff"}),ys=r=>typeof r=="string"&&or[r.toLowerCase()]||r,ws=Object.freeze({accent:"--dxr-accent",ink:"--dxr-ink",shell:"--dxr-shell",danger:"--dxr-danger",radius:"--dxr-radius",font:"--dxr-font"}),Ge=Object.freeze({lobbyStartTitle:"Start a 3D call",lobbyJoinTitle:"Join the 3D call",lobbyFullTitle:"This call is full",lobbyLeftTitle:"You left the call",lobbyFullText:"It already has {maxPeers} participants.",lobbyText:"Check your framing below. Camera: {camera} \u2014 {kind}.",cameraDefault:"default",kindBusy:"busy (joining audio-only)",kindNone:"none (joining audio-only)",kindSbs:"sending 3D (side-by-side, {width}\xD7{height})",kindMono:"sending 2D ({width}\xD7{height})",liftOff:"Mono cameras: 2D (2D\u21923D is off).",liftChecking:"Mono cameras: checking 2D\u21923D\u2026",liftMissing:"Mono cameras: 2D\u21923D unavailable in this build.",liftNoProvider:"Mono cameras: 2D (no 2D\u21923D provider here).",liftNative:"Mono cameras: 2D\u21923D (native{provider}).",liftWeb:"Mono cameras: 2D\u21923D (in this page, WebGPU).",liftProven:"Mono cameras: 2D\u21923D.",liftUnproven:"Mono cameras: 2D\u21923D (confirmed on the first mono participant).",start:"Start 3D call",join:"Join call",rejoin:"Rejoin",retryCamera:"Retry camera",cameraSelect:"Camera",joining:"Joining\u2026",waitingTitle:"Waiting for others",waitingText:"Share this link (or scan the code). Anyone who opens it joins \u2014 keep it private.",inviteTitle:"Invite",inviteText:"Anyone with this link can join.",inviteLink:"Invite link",copyLink:"Copy link",copied:"Copied",pressCopy:"Press Ctrl/Cmd+C",qrLabel:"QR code of the invite link",banner2D:"You are seeing this call in 2D.",bannerLink:"View in 3D with DisplayXR Browser",mute:"Mute microphone",unmute:"Unmute microphone",cameraOn:"Turn camera on",cameraOff:"Turn camera off",cameraRetry:"No camera \u2014 click to retry",cameraBusyRetry:"{cameraBusy} \u2014 click to retry",depth:"Depth",invite:"Invite",leave:"Leave call",connecting:"Connecting\u2026",reconnecting:"Reconnecting\u2026",leftCall:"Left the call",cameraOffPlate:"Camera off",noCamera:"No camera",unreachable:"Can't reach this participant \u2014 the network needs a relay (TURN)",cameraBusy:"Camera busy \u2014 in use by another app (e.g. eye tracking)",you:"You",badge3D:"3D",badge2D3D:"2D\u21923D",badge2D:"2D",badgePending:"\u2026"});function bs(r){let e={...Ge,...r&&typeof r=="object"?r:{}};return(t,i)=>{let n=typeof e[t]=="string"?e[t]:Ge[t]||t;if(i)for(let[s,o]of Object.entries(i))n=n.split(`{${s}}`).join(String(o));return n}}var vs="dxr-call-style",Ma=`
|
|
20
20
|
.dxr-call-host{--dxr-accent:#4da3ff;--dxr-ink:#fff;--dxr-shell:rgba(16,17,22,.92);--dxr-danger:#ff5a5f;--dxr-radius:12px;
|
|
21
21
|
--dxr-font:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
|
|
22
22
|
display:flex;flex-direction:column;gap:12px;color:var(--dxr-ink);
|
|
@@ -97,4 +97,4 @@ output.color1 = getPickDepth();
|
|
|
97
97
|
.dxr-call-depth{display:flex;align-items:center;gap:6px;padding:0 8px;font-size:12px;opacity:.9;}
|
|
98
98
|
.dxr-call-depth input{width:110px;accent-color:var(--dxr-accent);}
|
|
99
99
|
.dxr-call-note{font-size:12px;opacity:.65;}
|
|
100
|
-
`;function xs(r=document){if(r.getElementById(vs))return;let e=r.createElement("style");e.id=vs,e.textContent=Ma,(r.head||r.documentElement).appendChild(e)}var ae=r=>`<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${r}"/></svg>`,J={mic:ae("M12 14a3 3 0 0 0 3-3V5a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21h2v-3.08A7 7 0 0 0 19 11z"),micOff:ae("M19 11h-2a5 5 0 0 1-.4 1.97l1.47 1.47A6.96 6.96 0 0 0 19 11zM15 11V5a3 3 0 0 0-5.94-.6L15 10.34zM4.27 3 3 4.27l6 6V11a3 3 0 0 0 4.52 2.59l1.46 1.46A5 5 0 0 1 7 11H5a7 7 0 0 0 6 6.92V21h2v-3.08a6.9 6.9 0 0 0 3.02-1.14L19.73 21 21 19.73z"),cam:ae("M17 10.5V7a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-3.5l4 4v-11z"),camOff:ae("M21 6.5l-4 4V7a1 1 0 0 0-1-1H9.82L21 17.18zM3.27 2 2 3.27 4.73 6H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h12c.21 0 .39-.08.54-.18L19.73 21 21 19.73z"),link:ae("M3.9 12a3.1 3.1 0 0 1 3.1-3.1h4V7H7a5 5 0 0 0 0 10h4v-1.9H7A3.1 3.1 0 0 1 3.9 12zM8 13h8v-2H8zm9-6h-4v1.9h4a3.1 3.1 0 0 1 0 6.2h-4V17h4a5 5 0 0 0 0-10z"),leave:ae("M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85a1 1 0 0 1-1.41-.02L.29 13.08a1 1 0 0 1 0-1.41C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67a1 1 0 0 1 0 1.41l-2.48 2.48a1 1 0 0 1-1.41.02 11.3 11.3 0 0 0-2.66-1.85 1 1 0 0 1-.56-.9v-3.1A15.3 15.3 0 0 0 12 9z"),mutedSmall:ae("M19 11h-2a5 5 0 0 1-.4 1.97l1.47 1.47A6.96 6.96 0 0 0 19 11zM15 11V5a3 3 0 0 0-5.94-.6L15 10.34zM4.27 3 3 4.27l6 6V11a3 3 0 0 0 4.52 2.59l1.46 1.46A5 5 0 0 1 7 11H5a7 7 0 0 0 6 6.92V21h2v-3.08a6.9 6.9 0 0 0 3.02-1.14L19.73 21 21 19.73z")};function A(r,e={},t=[]){let i=document.createElement(r);for(let[n,s]of Object.entries(e))s!=null&&(n==="class"?i.className=s:n==="html"?i.innerHTML=s:n==="text"?i.textContent=s:n.startsWith("on")&&typeof s=="function"?i.addEventListener(n.slice(2),s):n in i&&typeof s!="string"?i[n]=s:i.setAttribute(n,s));for(let n of[].concat(t))n&&i.appendChild(typeof n=="string"?document.createTextNode(n):n);return i}var z=(r,e)=>r&&r.classList.toggle("dxr-call-hidden",!e);we();var Ms="[inline3d/call]",Ea="https://github.com/DisplayXR/displayxr-browser",Es=Object.freeze({accent:"theme.accent",tileAspect:"theme.tileAspect",inviteBase:"invite.base",updateUrl:"invite.updateUrl",browserUrl:"landing.browserUrl",maxLifted:"liftOptions.max",calibration:"openCamera({ calibration }) of '@displayxr/inline3d/camera' (pass the camera as `camera`)",rectify:"openCamera({ rectify }) of '@displayxr/inline3d/camera'",log:"debug: true (and diagnostics())",recoverSession:"nothing \u2014 a call always recovers the document's session (sharedInline3D())",wallOptions:"sharedInline3D(opts) \u2014 the document's wall is configured by the page",scrollIntoView:"nothing \u2014 always on with ui: true"}),Ss=new Set;function Ra(r){Ss.has(r)||(Ss.add(r),console.warn(`${Ms} option \`${r}\` is deprecated (removed in 1.31) \u2014 use ${Es[r]}`))}function ar(r={}){for(let w of Object.keys(Es))r[w]!==void 0&&Ra(w);let e=r.theme&&typeof r.theme=="object"?r.theme:{},t=r.invite&&typeof r.invite=="object"?r.invite:{},i=r.landing&&typeof r.landing=="object"?r.landing:{},n=r.ui===void 0?!0:r.ui==="tiles"?"tiles":!!r.ui,s=n===!0,o=e.tileAspect!==void 0?e.tileAspect:r.tileAspect,a=typeof o=="number"&&o>.3&&o<4?o:16/9,l=r.room===void 0||r.room===null?"auto":r.room;if(l!=="auto"&&!me(l)){let w=Ne(l);if(!w)throw new Error(`@displayxr/inline3d/call: room "${l}" is not a valid room id (16-64 base64url chars) or invite link`);l=w}let c=r.liftOptions&&typeof r.liftOptions=="object"?{...r.liftOptions}:null,u=c&&c.max!==void 0?c.max:r.maxLifted;c&&delete c.max;let f=e.accent!==void 0?e.accent:r.accent,h={};for(let[w,m]of Object.entries(ws)){let _=w==="accent"?f:e[w];typeof _=="string"&&_?h[m]=w==="accent"?ys(_):_:typeof _=="number"&&w==="radius"&&(h[m]=`${_}px`)}let d=t.base!==void 0?t.base:r.inviteBase,p=t.updateUrl!==void 0?t.updateUrl:r.updateUrl,g=i.browserUrl!==void 0?i.browserUrl:r.browserUrl;return{room:l,signaling:r.signaling||Re(void 0,typeof r.key=="string"&&r.key?{key:r.key}:{}),iceServers:Array.isArray(r.iceServers)?r.iceServers:void 0,camera:r.camera===void 0?"auto":r.camera,format:r.format==="sbs"?"sbs":r.format==="mono"?"mono":void 0,calibration:r.calibration&&typeof r.calibration=="object"?{...r.calibration}:{},rectify:typeof r.rectify=="function"?r.rectify:null,audio:r.audio===void 0?!0:!!r.audio,autoConverge:r.autoConverge===void 0?!0:!!r.autoConverge,cursor:vt(r.cursor,"@displayxr/inline3d/call"),mono3D:Ae(r.mono3D),maxPeers:He(r.maxPeers===void 0?pe:r.maxPeers),liftOptions:c&&Object.keys(c).length?c:null,maxLifted:Number.isFinite(+u)&&u!==null&&u!==void 0?Math.max(0,Math.min(pe,Math.floor(+u))):pe,layout:r.layout==="speaker"?"speaker":r.layout==="none"?"none":"grid",ui:n,chrome:s,autoJoin:r.autoJoin===void 0?!s:!!r.autoJoin,selfView:r.selfView===void 0?!0:!!r.selfView,tileAspect:a,cssVars:h,strings:e.strings&&typeof e.strings=="object"?{...e.strings}:null,invite:{base:typeof d=="string"?d:null,updateUrl:p===void 0?s:!!p},landing:{browserUrl:typeof g=="string"?g:Ea,allow2D:i.allow2D===void 0?!0:!!i.allow2D},debug:!!r.debug,log:typeof r.log=="function"?r.log:r.debug?(w,m)=>console.log(`${Ms} ${w} ${JSON.stringify(m)}`):null,_liftImporter:typeof r._liftImporter=="function"?r._liftImporter:void 0}}var ec=Object.freeze(["normalizeCallOptions","newRoomId","isValidRoomId","buildInviteLink","normalizeHello","makeHello","routeFor","badgeFor","createLiveGate","convergenceShiftPx","lowPass","clampShift","eyeCropRect","mirrorSwapOps","mirrorSwapPixels","maxBitrateKbps","measureFocusDisparity","preferVideoCodecs","sortCodecCapabilities","VIDEO_CODEC_ORDER","MeshTransport","clampMaxPeers","qrEncode","roomKey","SIGNAL_PROTOCOL","WIRE_VERSION","CALL_SDK","PLATE_TEXT","CALL_ACCENTS","normalizeMono3D","resolveLift","createLiftPool","createFrameWatch","liftConvergenceFor","liftPriorityFor","setLiftPriority","defaultLiftSpecifier","LIFT_PRIORITY"]);var cr="dxr-call:",Ca=["joined","left","peer","peerleft","state","display","speaker","quality","error","warning"],lr="[inline3d/call] <dxr-call>",Ce=r=>r!=null&&!/^(false|0|off|no)$/i.test(String(r).trim()),Rs=r=>{if(r==null||String(r).trim()==="")return;let e=/^\s*([0-9.]+)\s*\/\s*([0-9.]+)\s*$/.exec(String(r)),t=e?+e[1]/+e[2]:+r;return Number.isFinite(t)?t:void 0},H=r=>r==null||String(r).trim()===""?void 0:String(r).trim();function hr(r){let e=typeof r=="function"?r:l=>r&&typeof r.getAttribute=="function"?r.getAttribute(l):null,t={},i=(l,c)=>{c!==void 0&&(t[l]=c)};i("room",H(e("room")));let n=H(e("signaling"));n&&(t.signaling=Re(n,H(e("key"))?{key:H(e("key"))}:{})),i("key",H(e("key"))),i("camera",H(e("camera"))),i("layout",H(e("layout"))),i("maxPeers",Rs(e("max-peers")));let s=H(e("ui"));Ce(e("no-ui"))?t.ui=!1:s==="tiles"&&(t.ui="tiles"),Ce(e("auto-join"))&&(t.autoJoin=!0);let o=H(e("mono3d"));o&&/^(off|false|0|no)$/i.test(o)&&(t.mono3D="off"),Ce(e("no-audio"))&&(t.audio=!1),Ce(e("no-self-view"))&&(t.selfView=!1),Ce(e("no-auto-converge"))&&(t.autoConverge=!1),H(e("cursor"))==="depth"&&(t.cursor="depth");let a={accent:H(e("accent")),tileAspect:Rs(e("tile-aspect"))};return(a.accent!==void 0||a.tileAspect!==void 0)&&(t.theme=Object.fromEntries(Object.entries(a).filter(([,l])=>l!==void 0))),H(e("invite-base"))&&(t.invite={base:H(e("invite-base"))}),H(e("browser-url"))&&(t.landing={browserUrl:H(e("browser-url"))}),Ce(e("debug"))&&(t.debug=!0),t}var ka=typeof HTMLElement=="function"?HTMLElement:class{},ke=class r extends ka{static mount=null;constructor(){super(),this.options=null,this.call=null,this.ready=null,this._gen=0,this._off=[],this._pending=null}connectedCallback(){if(this.call||this._pending)return;let e=++this._gen,t={...hr(this),...this.options&&typeof this.options=="object"?this.options:{}},i=this.constructor.mount||r.mount||ur;this._pending=new Promise(n=>n(i(this,t))).then(n=>{if(this._pending=null,e!==this._gen)return n.leave(),null;if(this.call=n,this._off=Ca.map(s=>n.on(s,o=>this._dispatch(s,o))),this._off.push(n.on("error",s=>console.warn(`${lr} ${s.code}: ${s.message}`))),this._dispatch("ready",{call:n}),n.state==="in-call"){this._dispatch("joined",{room:n.room,id:n.id});for(let s of n.peers)this._dispatch("peer",{id:s.id})}return n},n=>{throw this._pending=null,this._dispatch("error",{code:"mount-failed",message:String(n&&n.message||n),error:n||null}),console.warn(`${lr} mount failed: ${String(n&&n.message||n)}`),n}),this.ready=this._pending,this.ready.catch(()=>{})}disconnectedCallback(){this._gen++;let e=this.call;this.call=null,e&&e.leave();for(let t of this._off)try{t()}catch{}this._off=[]}_dispatch(e,t){typeof CustomEvent!="function"||typeof this.dispatchEvent!="function"||this.dispatchEvent(new CustomEvent(cr+e,{detail:t,bubbles:!0,composed:!0}))}};function Nt(r="dxr-call",e=globalThis.customElements){if(!e||typeof e.define!="function")return!1;let t=e.get(r);return t?(t!==ke&&console.warn(`${lr} <${r}> is already defined by another class; leaving it`),!1):(e.define(r,ke),!0)}var Z="[inline3d/call]",Ta=2e3,Oa=2500,Da=500,dr=.02,Pa=4,Aa=2,La=200,Cs=240,Ia=66,Fa=new Set(["I420","I420A","I422","I444","NV12"]);async function Os(r,e,t={}){if(!e||typeof e.appendChild!="function")throw new TypeError("@displayxr/inline3d/call: addCall(wall, container, opts) needs a container element");let i=ar(t);if(!i.signaling||typeof i.signaling.join!="function")throw new TypeError("@displayxr/inline3d/call: opts.signaling must be a SignalingAdapter \u2014 dxrSignaling([url]) or your own");let n=new fr(r,e,i);return await n._init(),n.handle}async function ur(r,e={}){if(!r||typeof r.appendChild!="function")throw new TypeError("@displayxr/inline3d/call: mountCall(el, opts) needs a container element");let{wall:t,...i}=e,n=t||await it(i.wallOptions);return Os(n,r,i)}var fr=class{constructor(e,t,i){this.o=i,this.t=bs(i.strings),this.container=t,this.wall=e||null,this.wallLive=!!(e&&e.supported),this.weaveLive=!1,this.camStatus="pending",this.id=Gr(),this.room=i.room==="auto"?Ne(globalThis.location):i.room,this.state="idle",this.tiles=new Map,this.listeners=new Map,this.local=null,this.muted=!1,this.camOff=!1,this.depth=0,this.speakerId=null,this.transport=null,this._raf=0,this._statsTimer=0,this._hintGate=_i(di),this.mono3D=i.mono3D,this.mono3DOn=i.mono3D!=="off",this.liftApi=null,this.liftPool=null,this._liftP=null,this.liftProven=!1,this.liftMissing=!1,this._liftWarned=!1,this._frameWatch=$t(),this.handle=this._makeHandle(),this.wallLive&&this._hookWall(this.wall)}get woven(){return!!(this.wall&&this.wall.supported&&this.wallLive)}log(e,t={}){this.o.log&&this.o.log(e,t)}emit(e,t){let i=this.listeners.get(e);if(i)for(let n of[...i])try{n(t)}catch(s){console.error(`${Z} '${e}' listener threw`,s)}}error(e,t,i){this.log("error",{code:e,message:t}),this.listeners.get("error")?.size||console.warn(`${Z} ${e}: ${t}`),this.emit("error",{code:e,message:t,error:i||null})}warning(e,t){this.log("warning",{code:e,message:t}),console.warn(`${Z} ${e}: ${t}`),this.emit("warning",{code:e,message:t})}async _init(){this._buildDom(),this.wallLive&&this._ensureLift(),await this._openMedia(this.o.camera),this._startLoop(),this.o.autoJoin?await this.join():this._setState("lobby")}async _openMedia(e,t,{keepOnFail:i=!1}={}){let n=(h,d)=>this.log(h,d),s=null,o=null,a=It(e)?e:null;try{if(s=a||await er({prefer:e,format:t||this.o.format,calibration:this.o.calibration,rectify:this.o.rectify||void 0,log:n}),a&&a.state!=="live")throw Object.assign(new Error("the camera given is not live"),{code:"no-camera",skipped:[]})}catch(h){o=h;let d=h.code==="camera-busy";if(this.error(d?"camera-busy":h.code||"no-camera",d?`${this.t("cameraBusy")}. Joining audio-only.`:`no camera: ${h.message}. Joining audio-only.`,h),i&&this.local&&this.local.videoTrack)return this.local;this.camStatus=d?"busy":"none"}s&&(this.camStatus="ok"),s&&s.rectifyError&&this.error("rectify-failed",`rectify() threw \u2014 sending the raw pair: ${s.rectifyError.message}`,s.rectifyError);let l=this.local?this.local.audioTrack:null;this.o.audio&&!l&&(l=await tn({log:n})),l&&(l.enabled=!this.muted);let c=s&&s.stream.getVideoTracks()[0]||null;if(c){try{c.contentHint="detail"}catch{}c.enabled=!this.camOff}let u=new MediaStream([c,l].filter(Boolean)),f=this.local;return this.local={stream:u,cam:s,camStream:s?s.stream:null,video:s?s.video:null,videoTrack:c,audioTrack:l,format:s?s.format:"mono",width:s?s.width:0,height:s?s.height:0,calibration:s?s.calibration:{},owned:s?s.owned&&s!==a:!1,label:s?s.label:"",skipped:s?s.skipped:o?.skipped||[]},s&&s!==f?.cam&&(this._camEndedOff?.(),this._camEndedOff=s.on("ended",()=>{this.local?.cam===s&&(this.local.videoTrack=null,this.camStatus="none",this.error("no-camera",'the camera ended (revoked, unplugged, or taken by another app). Audio-only until "Retry camera".'),this.transport?.broadcast(this.stateMsg()),this._refreshSelf(),this._refreshBar())})),this.log("camera",{format:this.local.format,width:this.local.width,height:this.local.height,label:this.local.label,skipped:this.local.skipped.length}),f&&f.owned&&f.cam&&f.cam!==s&&f.cam.close(),this._refreshSelf(),this._refreshLobby(),this.local}hello(){let e=this.local||{};return mi({format:e.format,width:e.width,height:e.height,baselineMm:e.calibration?.baselineMm,hfovDeg:e.calibration?.hfovDeg,rectified:!!e.calibration?.rectified})}stateMsg(){return{type:"state",muted:this.muted,cameraOff:this.camOff||!this.local?.videoTrack,speaking:!!this._selfSpeaking}}async join(){if(this.state==="joining"||this.state==="in-call")return this.handle;if(this.state==="left"&&!this.local?.videoTrack&&await this._openMedia(this.o.camera),this.room||(this.room=fi(),this.log("room-created",{})),this.o.invite.updateUrl&&globalThis.history&&globalThis.location)try{history.replaceState(history.state,"",at(location.href,this.room))}catch{}this._setState("joining");let e=new We({signaling:this.o.signaling,id:this.id,maxPeers:this.o.maxPeers,iceServers:this.o.iceServers,log:(i,n)=>this.log(i,n)});this.transport=e;let t=null;try{t=await e.start({room:this.room,localStream:this.local.stream,sendFormat:this.local.format,onPeer:i=>this._onPeer(i),onPeerLeft:(i,n)=>this._onPeerLeft(i,n),onStream:(i,n)=>this.tiles.get(i)?.setStream(n),onMessage:(i,n)=>this._onMessage(i,n),onPeerState:(i,n)=>{this.tiles.get(i)?.setConn(n),this.emit("state",{id:i,state:n})},onRefused:i=>this.log("refused-peer",{id:i}),onGhost:(i,n)=>this._onGhost(i,n),onSignalingState:(i,n)=>{this.log("signaling",{state:i}),i==="closed"&&n&&this.error(n.code||"signaling-closed",n.message,n)}})}catch(i){throw this.transport=null,i&&i.code==="room-full"?(this._setState("full"),this.error("room-full",i.message,i)):(this._setState("lobby"),this.error(i.code||"join-failed",`could not join: ${i.message}`,i)),i}if(this._setState("in-call"),this.o.chrome)try{this.container.scrollIntoView?.({block:"start",behavior:"instant"}),this._fitGrid()}catch{}return this._startStats(),this._pagehide=()=>this.leave("pagehide"),globalThis.addEventListener?.("pagehide",this._pagehide),this.log("joined",{id:this.id,peers:this.tiles.size}),this.emit("joined",{room:this.room,id:this.id}),setTimeout(()=>{this.transport===e&&this._reportTurn(t)},0),this.handle}_reportTurn(e){let t=e&&e.turn;!t||typeof t!="object"||(t.status==="off"&&t.reason==="cap"?this.error("turn-cap","relay (TURN) capacity for this month is used up; direct connections still work, but a participant behind a strict NAT may be unreachable",null):(t.reason==="budget"||t.reason==="rate")&&this.warning("turn-shed",t.reason==="rate"?"no relay (TURN) for this session: too many credential requests from this address this hour":"no relay (TURN) for this anonymous session: the hosted service is near its monthly relay budget (a publishable key keeps TURN)"))}_onPeer(e){if(this.tiles.has(e))return;let t=new jt(this,e);this.tiles.set(e,t),this._layout(),this.emit("peer",{id:e})}_onGhost(e,t){let i=this.tiles.get(e);if(t&&!i){let n=new jt(this,e);n.ghost=!0,this.tiles.set(e,n),n.setConn("unreachable"),this._layout()}else!t&&i&&i.ghost&&(i.destroy(),this.tiles.delete(e),this._layout())}_onPeerLeft(e,t){let i=this.tiles.get(e);i&&(i.setConn("left"),this.emit("peerleft",{id:e,reason:t}),i.leaveTimer=setTimeout(()=>{i.destroy(),this.tiles.get(e)===i&&this.tiles.delete(e),this.speakerId===e&&this._setSpeaker(null),this._layout()},Oa))}_onMessage(e,t){let i=this.tiles.get(e);if(!i||!t)return;if(t.type==="__open"){this.transport.send(e,this.hello()),this.transport.send(e,this.stateMsg()),i.onChannelOpen();return}let n=pi(t);if(n)return i.setHello(n);let s=gi(t);if(s)return i.setHint(s);let o=Kr(t);if(o)return i.setRemoteState(o)}inviteLink(){if(!this.room)return null;let e=this.o.invite.base||(globalThis.location?location.href:"");return at(e,this.room)}mute(e){return this.muted=e===void 0?!this.muted:!!e,this.local?.audioTrack&&(this.local.audioTrack.enabled=!this.muted),this.transport?.broadcast(this.stateMsg()),this._refreshBar(),this.log("mute",{muted:this.muted}),this.muted}setCameraOff(e){return this.camOff=e===void 0?!this.camOff:!!e,this.local?.videoTrack&&(this.local.videoTrack.enabled=!this.camOff),this.transport?.broadcast(this.stateMsg()),this._refreshBar(),this._refreshSelf(),this.camOff}setDepth(e){let t=e==null||!Number.isFinite(+e)?0:Math.max(-1,Math.min(1,+e));this.depth=t;for(let i of this.tiles.values())i.conv.depth=t;return this.liftPool?.setDepth(t),this.ui?.depth&&+this.ui.depth.value!==t&&(this.ui.depth.value=String(t)),t}async setCamera(e,{format:t}={}){let i=this.local?.format,n=await this._openMedia(e,t,{keepOnFail:!0});return this.transport&&(await this.transport.replaceTrack("video",n.videoTrack,n.stream),await this.transport.setSendFormat(n.format),this.transport.broadcast(this.hello()),this.transport.broadcast(this.stateMsg())),i!==n.format&&this.log("send-format",{format:n.format}),{format:n.format,width:n.width,height:n.height,label:n.label}}retryCamera(){return this.setCamera(this.o.camera,{format:this.o.format})}sendHint(e){if(!this._hintGate(performance.now()))return!1;let t=gi({type:"hint",subjectZmm:e});return t?(this.transport?.broadcast(t),!0):!1}leave(e="left"){if(this.state!=="left"){globalThis.removeEventListener?.("pagehide",this._pagehide),this.transport?.stop(),this.transport=null;for(let t of this.tiles.values())t.destroy();this.tiles.clear(),this.liftPool?.releaseAll(),clearInterval(this._statsTimer),this._setSpeaker(null),this.local&&(this._camEndedOff?.(),this._camEndedOff=null,this.local.stream.getTracks().forEach(t=>t.stop()),this.local.owned&&this.local.cam?this.local.cam.close():this.local.cam&&this.self?.detach(),this.local.videoTrack=null,this.local.audioTrack=null),this.self?.detach(),this._unhookWall(),this._setState("left"),this._layout(),this.emit("left",{room:this.room,reason:e})}}_hookWall(e){if(!e||!e.session||typeof e.session.addEventListener!="function")return;let t=e.close;this._wallHook={w:e,orig:t,pageClosed:!1};let i=this._wallHook;e.close=(...n)=>(i.pageClosed=!0,t.apply(e,n)),i.onEnd=()=>this._sessionEnded(i),e.session.addEventListener("end",i.onEnd),this._watchLive(e)}_watchLive(e){this.weaveLive=!1;let t=e.session;if(!t||typeof t.requestAnimationFrame!="function"){this.weaveLive=!0;return}let i=wi(),n=performance.now(),s=(o,a)=>{if(e!==this.wall||!this.wallLive||this.state==="left")return;let l=null;if(e.refSpace)try{let c=a.getViewerPose(e.refSpace);l=c&&c.views?c.views.length:0}catch{l=0}if(!i.feed(l)){try{t.requestAnimationFrame(s)}catch{}return}this.weaveLive=!0,this.log("weave-live",{ms:Math.round(performance.now()-n)});for(let c of this.tiles.values())(c.route==="woven-sbs"||c.route==="lifted")&&c.reroute(!0);this.self&&this.self.route==="woven-sbs"&&this.self.reroute(!0),this._layout()};try{t.requestAnimationFrame(s)}catch{this.weaveLive=!0}}_unhookWall(){let e=this._wallHook;if(e){this._wallHook=null,e.w.close!==e.orig&&(e.w.close=e.orig);try{e.w.session.removeEventListener("end",e.onEnd)}catch{}}}_sessionEnded(e){if(this._wallHook===e){this.wallLive=!1,this.weaveLive=!1,this.log("session-ended",{byPage:e.pageClosed});for(let t of this.tiles.values())t.onWallLost();if(this.self?.onWallLost(),e.pageClosed||this.state==="left"){this._unhookWall();return}this.error("session-ended","the inline-3D session ended; tiles are flat while it is re-opened"),this._unhookWall(),this._recoverWall(0)}}_recoverWall(e){this.state==="left"||e>10||setTimeout(async()=>{if(this.state==="left")return;let t=null;try{t=await it()}catch{t=null}if(!t||!t.supported)return this._recoverWall(e+1);this.wall=t,this.wallLive=!0,this._hookWall(t),this.log("session-recovered",{attempt:e});for(let i of this.tiles.values())i.reroute(!0);this.self?.reroute(!0)},K(e,{baseMs:1e3,maxMs:15e3}))}_startLoop(){let e=0,t=i=>{this._raf=requestAnimationFrame(t);for(let n of this.tiles.values())n.paint();e&&this.liftPool&&this.liftPool.anyWeb&&this._watchFrames(i-e),e=i};this._raf=requestAnimationFrame(t)}_watchFrames(e){let t=this._frameWatch.feed(e);if(!t)return;let i={degraded:t==="degraded",frameMs:Math.round(this._frameWatch.frameMs*10)/10,tiles:this.liftPool.size};this.log("lift-frame-time",i),t==="degraded"&&console.warn(`${Z} lifted tiles are slowing the page (~${Math.round(1e3/i.frameMs)} fps with ${i.tiles} lifted) \u2014 setMono3D(false) shows mono peers flat`),this.emit("quality",{id:null,in:null,out:null,lift:i})}_ensureLift(){if(!this.mono3DOn)return Promise.resolve(null);if(!this._liftP){let e=(n,s)=>this.log(n,s),t=this.o.liftOptions,i={webFallback:!0,...t&&t.models?{models:t.models}:{}};this._liftP=Wt(this.mono3D,{log:e,capsOpts:i,...this.o._liftImporter?{importer:this.o._liftImporter}:{}}).then(n=>(this.liftApi=n,n.lift?(this.liftPool=Ut({lift:n.lift,max:this.o.maxLifted,log:e,options:this.o.liftOptions}),this.liftPool.setDepth(this.depth),this.liftPool.setSpeaker(this.speakerId),!n.caps&&n.capabilities&&Promise.resolve().then(()=>n.capabilities(i)).then(s=>{n.caps=s||null,this._refreshLobby()}).catch(()=>{})):n.reason==="import-failed"||n.reason==="no-lift-export"?this.liftMissing=!0:n.reason!=="off"&&console.info(`${Z} mono\u21923D unavailable (${n.reason}) \u2014 mono participants are shown flat`),this._rerouteMono(),this._refreshLobby(),n))}return this._liftP}_warnLiftMissing(){this._liftWarned||!this.liftMissing||!this.mono3DOn||(this._liftWarned=!0,this.warning("lift-not-bundled","a 2D participant is on a 3D display but the 2D\u21923D module could not be imported from this build, so they stay flat. Import it explicitly \u2014 `import { lift } from '@displayxr/inline3d/lift'; mountCall(el, { mono3D: lift })` \u2014 or use `@displayxr/inline3d/call/full`, which bundles it."))}_rerouteMono(){for(let e of this.tiles.values())e.format&&e.format!=="sbs"&&e.reroute(!1)}setMono3D(e){let t=e===void 0?!this.mono3DOn:!!e;return t===this.mono3DOn||(this.mono3DOn=t,t&&this.mono3D==="off"&&(this.mono3D="auto"),this._frameWatch.reset(),this.log("mono3d",{on:t}),this._rerouteMono(),t&&this.wallLive&&this._ensureLift(),this._refreshLobby()),t}_liftHint(){if(!this.wallLive)return"";let e=this.t;if(!this.mono3DOn)return e("liftOff");let t=this.liftApi;if(!t)return e("liftChecking");if(!t.lift)return this.liftMissing?e("liftMissing"):e("liftNoProvider");let i=t.caps;return i&&i.native?e("liftNative",{provider:i.provider?`, ${i.provider}`:""}):i&&i.webFallback&&i.webFallback.webgpu?e("liftWeb"):this.liftProven?e("liftProven"):e("liftUnproven")}_mono3DInfo(){let e=this.liftApi,t=e&&e.caps;return Object.freeze({on:this.mono3DOn,state:this.mono3DOn?e?e.lift?"ready":"unavailable":this._liftP?"loading":"idle":"off",reason:e?e.reason:null,native:t?!!t.native:null,provider:t&&t.provider||null,lifted:this.liftPool?this.liftPool.size:0,max:this.o.maxLifted,proven:this.liftProven})}_startStats(){clearInterval(this._statsTimer);let e=0;this._statsTimer=setInterval(()=>this._stats(++e%4===0),Da)}async _stats(e){if(!this.transport)return;let t=null,i=0;for(let[o,a]of this.tiles){let l=this.transport.peerConnection(o);if(!l)continue;let c;try{c=await l.getStats()}catch{continue}let u={};c.forEach(d=>{d.type==="codec"&&(u[d.id]=d.mimeType)});let f={in:null,out:null};c.forEach(d=>{if(d.type==="inbound-rtp"&&d.kind==="audio"&&typeof d.audioLevel=="number"&&(a.level=Math.max(d.audioLevel,(a.level||0)*.6)),d.type==="media-source"&&d.kind==="audio"&&typeof d.audioLevel=="number"&&(i=Math.max(i,d.audioLevel)),!!e){if(d.type==="inbound-rtp"&&d.kind==="video"){let p=a._prevIn;f.in={width:d.frameWidth||0,height:d.frameHeight||0,fps:d.framesPerSecond||0,codec:u[d.codecId]||null,kbps:p?Math.round((d.bytesReceived-p.bytes)*8/(d.timestamp-p.t)):null,dropped:d.framesDropped||0,decoder:d.decoderImplementation||null},a._prevIn={bytes:d.bytesReceived,t:d.timestamp}}else if(d.type==="outbound-rtp"&&d.kind==="video"){let p=a._prevOut;f.out={width:d.frameWidth||0,height:d.frameHeight||0,fps:d.framesPerSecond||0,codec:u[d.codecId]||null,kbps:p?Math.round((d.bytesSent-p.bytes)*8/(d.timestamp-p.t)):null,limitation:d.qualityLimitationReason||null,encoder:d.encoderImplementation||null},a._prevOut={bytes:d.bytesSent,t:d.timestamp}}}}),e&&(f.in||f.out)&&(a.quality=f,this.emit("quality",{id:o,...f}));let h=a.remote.muted?0:a.level||0;a.setSpeaking(h>dr||a.remote.speaking),h>dr&&(!t||h>t.lvl)&&(t={id:o,lvl:h})}let n=t?t.id:null;n&&n!==this.speakerId?(this._challengeTicks=this._challenger===n?(this._challengeTicks||0)+1:1,this._challenger=n,this._challengeTicks>=2&&this._setSpeaker(n)):(this._challenger=null,this._challengeTicks=0);let s=!this.muted&&i>dr;s!==!!this._selfSpeaking&&(this._selfSpeaking=s,this.transport?.broadcast(this.stateMsg()),this.self?.setSpeaking(s))}_setSpeaker(e){e!==this.speakerId&&(this.speakerId=e,this._challengeTicks=0,this.liftPool?.setSpeaker(e),this.emit("speaker",{id:e}),this.o.layout==="speaker"&&this._layout())}_fitGrid(){let e=this.ui;if(!e||!this.o.chrome||typeof globalThis.innerHeight!="number")return;let t=this.container.getBoundingClientRect?.(),i=e.grid.getBoundingClientRect?.();if(!t||!i||!i.height)return;let n=Math.max(160,Math.floor(globalThis.innerHeight-Math.max(0,t.top)-(t.height-i.height)-8)),s=parseFloat(this.container.style.getPropertyValue("--dxr-call-fit"))||0;Math.abs(n-s)>2&&this.container.style.setProperty("--dxr-call-fit",`${n}px`),this._fitHooked||(this._fitHooked=!0,globalThis.addEventListener?.("resize",()=>this._fitGrid()))}_setState(e){this.state=e,this.log("state",{state:e}),this._layout()}_buildDom(){let e=this.container,t=this.t;xs(e.ownerDocument||document),e.classList.add("dxr-call-host");for(let[n,s]of Object.entries(this.o.cssVars))e.style.setProperty(n,s);let i=this.ui={};i.banner=A("div",{class:"dxr-call-banner dxr-call-hidden",part:"banner"},[A("span",{text:t("banner2D")}),A("a",{href:this.o.landing.browserUrl,target:"_blank",rel:"noopener",text:t("bannerLink")})]),i.grid=A("div",{class:"dxr-call-grid",part:"grid","data-layout":this.o.layout,"data-n":"0"}),i.panel=A("div",{class:"dxr-call-panel dxr-call-hidden",part:"lobby"}),i.selfSlot=A("div",{class:"dxr-call-self",part:"self"}),i.bar=A("div",{class:"dxr-call-bar",part:"bar"}),i.foot=A("div",{class:"dxr-call-foot"},[i.selfSlot,i.bar]),i.invite=A("div",{class:"dxr-call-panel dxr-call-hidden",part:"invite"}),this.o.chrome||z(i.bar,!1),e.append(i.banner,i.panel,i.grid,i.invite,i.foot),this.o.selfView?this.self=new pr(this,i.selfSlot):z(i.selfSlot,!1),this.o.chrome&&this._buildBar()}_buildBar(){let e=this.ui,t=this.t,i=(n,s,o,a="")=>A("button",{class:`dxr-call-ib ${a}`,type:"button","aria-label":n,title:n,html:s,onclick:o});e.mic=i(t("mute"),J.mic,()=>this.mute()),e.cam=i(t("cameraOff"),J.cam,()=>this.local?.videoTrack?this.setCameraOff():this.retryCamera().catch(()=>{})),e.depth=A("input",{type:"range",min:"-1",max:"1",step:"0.05",value:"0","aria-label":t("depth")}),e.depth.addEventListener("input",()=>this.setDepth(+e.depth.value)),e.depth.addEventListener("dblclick",()=>this.setDepth(0)),e.inviteBtn=i(t("invite"),J.link,()=>{this._showInvite=!this._showInvite,this._layout()}),e.leave=i(t("leave"),J.leave,()=>this.leave(),"dxr-call-ib--leave"),e.bar.append(e.mic,e.cam,A("label",{class:"dxr-call-depth"},[t("depth"),e.depth]),e.inviteBtn,e.leave)}_refreshBar(){let e=this.ui;if(!e||!e.mic)return;let t=this.t;e.mic.innerHTML=this.muted?J.micOff:J.mic,e.mic.setAttribute("aria-pressed",String(this.muted)),e.mic.title=this.muted?t("unmute"):t("mute");let i=!this.local?.videoTrack;e.cam.innerHTML=this.camOff||i?J.camOff:J.cam,e.cam.setAttribute("aria-pressed",String(this.camOff||i)),e.cam.title=i?this.camStatus==="busy"?t("cameraBusyRetry",{cameraBusy:t("cameraBusy")}):t("cameraRetry"):this.camOff?t("cameraOn"):t("cameraOff")}_refreshSelf(){this.self?.update()}_refreshLobby(){(this.state==="lobby"||this.state==="idle")&&this._layout()}_renderInvite(e,t,i){e.replaceChildren();let n=this.inviteLink();if(!n)return;let s=this.t,o=A("input",{type:"text",readOnly:!0,value:n,"aria-label":s("inviteLink")});o.addEventListener("focus",()=>o.select());let a=A("button",{class:"dxr-call-btn dxr-call-btn--primary",type:"button",text:s("copyLink")});a.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(n),a.textContent=s("copied")}catch{o.select(),a.textContent=s("pressCopy")}setTimeout(()=>a.textContent=s("copyLink"),1800)});let l=A("canvas",{"aria-label":s("qrLabel"),role:"img"});try{ms(l,n,{px:4})}catch{l.style.display="none"}e.append(A("h3",{text:t}),A("p",{text:i}),A("div",{class:"dxr-call-invite"},[A("div",{class:"dxr-call-row",style:"flex:1 1 280px"},[o,a]),l]))}_layout(){let e=this.ui;if(!e)return;let t=this.container,i=this.t,n=this.o.chrome&&(this.state==="lobby"||this.state==="idle"||this.state==="full"||this.state==="left");t.classList.toggle("dxr-call-host--lobby",n),z(e.banner,this.o.chrome&&!this.woven);let s=this.tiles.size;e.grid.dataset.n=String(Math.min(s,4)),z(e.grid,s>0&&this.state!=="left");let o=this.o.layout==="speaker"?this.speakerId||[...this.tiles.keys()][0]:null;for(let[c,u]of this.tiles)u.el.classList.toggle("dxr-call-tile--main",c===o);if(!this.o.chrome)return;this._refreshBar(),queueMicrotask(()=>this._fitGrid());let a=e.panel;if(n){z(a,!0),a.replaceChildren();let c=this.local,u=!!this.room,f=this.state==="full"?i("lobbyFullTitle"):this.state==="left"?i("lobbyLeftTitle"):i(u?"lobbyJoinTitle":"lobbyStartTitle"),h={width:c?.width||0,height:c?.height||0},d=this.camStatus==="busy"?i("kindBusy"):!c||!c.videoTrack?i("kindNone"):c.format==="sbs"?i("kindSbs",h):i("kindMono",h),p=this.state==="full"?i("lobbyFullText",{maxPeers:this.o.maxPeers}):`${i("lobbyText",{camera:c?.label||i("cameraDefault"),kind:d})}${this._liftHint()?` ${this._liftHint()}`:""}`,g=A("button",{class:"dxr-call-btn dxr-call-btn--primary",type:"button",text:this.state==="left"?i("rejoin"):i(u?"join":"start")});g.addEventListener("click",()=>this.join().catch(()=>{}));let w=A("select",{class:"dxr-call-select","aria-label":i("cameraSelect")});this._fillCameras(w),w.addEventListener("change",()=>this.setCamera(w.value).catch(_=>this.error("camera-failed",_.message,_)));let m=!c||!c.videoTrack?A("button",{class:"dxr-call-btn",type:"button",text:i("retryCamera")}):null;m?.addEventListener("click",()=>this.retryCamera().catch(()=>{})),a.append(A("h3",{text:f}),A("p",{text:p}),A("div",{class:"dxr-call-row"},[this.state==="full"?null:g,m,w]))}else this.state==="in-call"&&s===0?(z(a,!0),this._renderInvite(a,i("waitingTitle"),i("waitingText"))):this.state==="joining"?(z(a,!0),a.replaceChildren(A("p",{text:i("joining")}))):z(a,!1);let l=this.state==="in-call"&&s>0&&this._showInvite;l&&!e.invite.childElementCount&&this._renderInvite(e.invite,i("inviteTitle"),i("inviteText")),z(e.invite,l),l||e.invite.replaceChildren(),e.inviteBtn?.setAttribute("aria-pressed",String(!!l))}diagnostics(){let e=this.local;return{sdk:ui,wire:ot,state:this.state,wall:this.wall,wallLive:this.wallLive,weaveLive:this.weaveLive,woven:this.woven,local:e?{format:e.format,width:e.width,height:e.height,label:e.label,calibration:e.calibration,owned:e.owned,skipped:e.skipped,camera:e.cam||null,stream:e.stream}:null,hello:this.hello(),transport:this.transport,peers:[...this.tiles.values()].map(t=>t.diag()),self:this.self?this.self.diag():null,mono3D:{...this._mono3DInfo(),lift:this.liftApi,pool:this.liftPool?this.liftPool.list():[]},speaker:this.speakerId,depth:this.depth,options:this.o,kill:t=>this.transport?._debugKill(t)}}async _fillCameras(e){let t=[];try{t=(await navigator.mediaDevices.enumerateDevices()).filter(n=>n.kind==="videoinput")}catch{}let i=this.local?.videoTrack?.getSettings?.().deviceId;e.replaceChildren(...t.map((n,s)=>A("option",{value:n.deviceId,text:n.label||`Camera ${s+1}`}))),i&&(e.value=i),z(e,t.length>1)}_makeHandle(){let e=this,t={format:"display",session:null},i={get room(){return e.room},get id(){return e.id},get state(){return e.state},get localFormat(){return e.local?e.local.format:null},get muted(){return e.muted},get cameraOff(){return e.camOff},get depth(){return e.depth},get speaker(){return e.speakerId},get camera(){return e.camStatus},get mono3D(){return e._mono3DInfo()},get peers(){return Object.freeze([...e.tiles.values()].map(s=>s.info()))},join:()=>e.join().then(()=>{}),inviteLink:()=>e.inviteLink(),mute:s=>e.mute(s),setCameraOff:s=>e.setCameraOff(s),setCamera:(s,o)=>e.setCamera(s,o),setDepth:s=>e.setDepth(s),retryCamera:()=>e.retryCamera(),setMono3D:s=>e.setMono3D(s),leave:()=>e.leave("left"),tile:s=>e.tiles.get(s)?.el||null,diagnostics:()=>e.diagnostics(),on(s,o){if(typeof o!="function")throw new TypeError(`${Z} on() takes a function`);if(s in t&&!e._eventWarned?.has(s)){(e._eventWarned||=new Set).add(s);let a=t[s];console.warn(`${Z} the '${s}' event is deprecated (removed in 1.31)${a?` \u2014 listen for '${a}'`:" \u2014 it is internal now; diagnostics() has the wall"}`)}return e.listeners.has(s)||e.listeners.set(s,new Set),e.listeners.get(s).add(o),()=>e.listeners.get(s)?.delete(o)},off(s,o){e.listeners.get(s)?.delete(o)}},n={wall:["diagnostics().wall (or the wall you passed / sharedInline3D())",()=>e.wall],format:["localFormat",()=>i.localFormat],sendHint:["nothing \u2014 auto-convergence superseded it",()=>s=>e.sendHint(s)],_debug:["diagnostics()",()=>({transport:e.transport,kill:s=>e.transport?._debugKill(s)})]};for(let[s,[o,a]]of Object.entries(n))Object.defineProperty(i,s,{enumerable:!1,configurable:!0,get(){return e._handleWarned?.has(s)||((e._handleWarned||=new Set).add(s),console.warn(`${Z} handle.${s} is deprecated (removed in 1.31) \u2014 use ${o}`)),a()}});return i}};function Na(r){let e=Math.min(globalThis.devicePixelRatio||1,2),t=Math.round((r.clientWidth||0)*e),i=Math.round((r.clientHeight||0)*e);return!t||!i?!1:((r.width!==t||r.height!==i)&&(r.width=t,r.height=i),!0)}function ks(r,e,{eyeHalf:t=null,mirror:i=!1}={}){if(!Na(r))return;let n=r.getContext("2d"),s=e.videoWidth,o=e.videoHeight;if(!s||!o||(e.readyState||0)<2)return;let a=t===null?s:s/2,l=q(a,o,r.width/r.height,0,0);n.save(),i&&(n.translate(r.width,0),n.scale(-1,1)),n.drawImage(e,(t||0)*a+l.sx,l.sy,l.sw,l.sh,0,0,r.width,r.height),n.restore()}var jt=class{constructor(e,t){this.call=e,this.id=t,this.hello=null,this.format=null,this.route=null,this.routedKey=null,this.handle=null,this.conn="connecting",this.remote={muted:!1,cameraOff:!1,speaking:!1},this.level=0,this.speaking=!1,this.quality=null,this.conv=Fe(),this.autoTrack=dt(),this.autoFocus=$e(),this.autoAt=0,this.autoCanvas=null,this.autoLocked=!1,this.autoStats={n:0,ms:0,readMs:0,method:null,via:null},this.autoPending=!1,this.autoGen=0,this.luma=null,this.destroyed=!1,this.conv.depth=e.depth,this.hintGate=_i(di),this.layerFails=0,this.forceFlat=!1,this.lifted=!1,this.liftHandle=null,this.liftLive=!1,this.liftFailed=!1,this.liftFails=0,this.visible=!0,this.video=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,autoplay:!0}),this.audio=Object.assign(document.createElement("audio"),{autoplay:!0}),this.video.addEventListener("playing",()=>this._maybeRoute()),this.video.addEventListener("loadeddata",()=>this._maybeRoute()),this.video.addEventListener("resize",()=>this._maybeRoute()),this.canvas=A("canvas"),this.cover=A("div",{class:"dxr-call-cover dxr-call-hidden"}),this.badge=A("div",{class:"dxr-call-badge",part:"badge"}),this.plate=A("div",{class:"dxr-call-state",part:"plate",text:e.t("connecting")}),this.stage=A("div",{class:"dxr-call-stage"},[this.canvas,this.cover,this.badge,this.plate]),this.stage.style.aspectRatio=String(e.o.tileAspect),this.el=A("div",{class:"dxr-call-tile",part:"tile","data-dxr-peer":t,"data-peer":t},[this.stage,A("div",{class:"dxr-call-talk"})]),e.o.ui||z(this.badge,!1),e.ui.grid.appendChild(this.el),this._renderBadge(),this.cursor=null,e.o.cursor&&(e._pairCursorMod=e._pairCursorMod||Promise.resolve().then(()=>(Ji(),Ki)),e._pairCursorMod.then(i=>{this.destroyed||(this.cursor=new i.PairCursor(this.canvas,e.o.cursor))}))}display(){return yi(this.route)}info(){return Object.freeze({id:this.id,format:this.format||"mono",display:this.display(),state:this.conn,muted:this.remote.muted,cameraOff:this.remote.cameraOff,speaking:this.speaking})}diag(){return{...this.info(),route:this.route,rectified:!!(this.hello&&this.hello.rectified),hello:this.hello,quality:this.quality,convergencePx:this.conv.current,cursor:this.cursor?this.cursor.last:null,autoConverge:{disparityPx:this.conv.measuredPx,ms:this.autoStats.n?this.autoStats.ms/this.autoStats.n:null,readMs:this.autoStats.n?this.autoStats.readMs/this.autoStats.n:null,method:this.autoStats.method,via:this.autoStats.via},lift:this.lifted?{live:this.liftLive,native:!!(this.liftHandle&&this.liftHandle.native),priority:this.call.liftPool?this.call.liftPool.priority(this.id):null,state:this.liftHandle?this.liftHandle.state||null:"pending"}:null,element:this.el}}setStream(e){this.video.srcObject!==e&&(this.video.srcObject=e,this.audio.srcObject=e,this._resetAutoConverge()),this.video.play().catch(()=>{}),this.audio.play().catch(()=>{})}onChannelOpen(){clearTimeout(this.helloTimer),this.helloTimer=setTimeout(()=>{this.format||(this.format="mono",this._maybeRoute())},Ta)}setHello(e){clearTimeout(this.helloTimer),this.hello=e,this.conv.hello=e;let t=this.format!==e.format;this.format=e.format,this.call.log("hello",{peer:this.id,format:e.format,width:e.width,height:e.height,rectified:e.rectified}),t?this._maybeRoute():this._renderBadge()}setHint(e){this.hintGate(performance.now())&&(this.conv.subjectZmm=e.subjectZmm)}setRemoteState(e){this.remote=e,this._renderBadge(),this._renderPlate(),this._updateVisible()}setSpeaking(e){e!==this.speaking&&(this.speaking=e,this.el.classList.toggle("dxr-call-tile--speaking",e))}setConn(e){e==="unreachable"&&this.conn!=="unreachable"&&this.call.error("unreachable",`${this.call.t("unreachable")}. Still retrying in the background.`,Object.assign(new Error("unreachable"),{peer:this.id})),this.conn=e,e==="connected"&&this.leaveTimer&&(clearTimeout(this.leaveTimer),this.leaveTimer=null),this._renderPlate()}_renderPlate(){let e=this.call.t,t=this.conn==="left"?e("leftCall"):this.conn==="unreachable"?e("unreachable"):this.conn==="reconnecting"?e("reconnecting"):this.conn!=="connected"?e("connecting"):this.remote.cameraOff?e("cameraOffPlate"):null;this.plate.textContent=t||"",z(this.plate,!!t)}_renderBadge(){let e=this.call.t,t=this.route==="woven-sbs"?e("badge3D"):this.route==="lifted"?e("badge2D3D"):e("badge2D"),i=this.route?this.route==="lifted"&&!this.liftLive?`${t}${e("badgePending")}`:t:e("badgePending");this.badge.replaceChildren(A("b",{text:i})),this.badge.dataset.route=this.route||"",this.remote.muted&&this.badge.insertAdjacentHTML("beforeend",J.mutedSmall)}_maybeRoute(){!this.format||(this.video.readyState||0)<2||!this.video.videoWidth||this.reroute(!1)}reroute(e){let t=this.call,i=t.liftPool,n=this.forceFlat&&this.format==="sbs"?{route:"flat-left"}:vi({format:this.format,woven:t.woven,mono3D:t.mono3DOn?"auto":"off",lift:!!i,overBudget:i?!i.canAcquire(this.id):!1,failed:this.liftFailed});this.format!=="sbs"&&t.woven&&t.mono3DOn&&!t._liftP&&t._ensureLift(),this.format!=="sbs"&&t.woven&&t.liftMissing&&t._warnLiftMissing();let s=`${n.route}|${this.format}`;!e&&s===this.routedKey||(this.routedKey=s,this._unregister(),this.route=n.route,n.route==="woven-sbs"?this._registerWoven():n.route==="lifted"&&this._registerLifted(),t.log("route",{peer:this.id,route:n.route,format:this.format,mono3d:n.mono3d||null}),t.emit("display",{id:this.id,display:this.display()}),t.listeners.get("format")?.size&&t.emit("format",{id:this.id,format:this.format,route:n.route,mono3d:n.mono3d||null,hello:this.hello}),this._renderBadge())}_registerWoven(){let e=this.call;this.convCanvas||(this.convCanvas=document.createElement("canvas")),this._paintConv(),z(this.cover,!0);let t=e.wall.addImage(this.canvas,this.convCanvas);this.handle=t,t.firstWoven?.then(i=>{this.handle===t&&(z(this.cover,!1),e.log("first-woven",{peer:this.id,woven:i.woven,reason:i.reason,ms:Math.round(i.ms)}),!i.woven&&i.reason==="layer-failed"&&this._layerFailed())})}_registerLifted(){let e=this.call,t=e.liftPool;this.lifted=!0,this.liftLive=!1,this.video.classList.add("dxr-call-liftsrc"),this.canvas.classList.add("dxr-call-liftflat"),this.video.parentNode!==this.stage&&this.stage.insertBefore(this.video,this.stage.firstChild),this._observeVisible(),t.acquire(this.id,this.video,{wall:e.wall,visible:this.visible,onError:i=>this._liftError(i)}).then(i=>{if(!i||!this.lifted||t.handle(this.id)!==i)return;this.liftHandle=i;let n=s=>{s==="live"?this._liftShowing(!0):(s==="error"||s==="disposed")&&this._liftShowing(!1)};this._liftOff=[i.on?.("statechange",s=>n(s&&s.state)),i.on?.("error",s=>{s&&s.fatal&&this._liftError(s.error)})],i.state==="live"?this._liftShowing(!0):i.canvas&&i.canvas.style&&(i.canvas.style.visibility="hidden"),e.log("lifted",{peer:this.id,native:!!i.native,woven:!!i.woven,state:i.state||null,provider:i.stats&&i.stats.provider||null})})}_liftShowing(e){if(e===this.liftLive)return;this.liftLive=e;let t=this.liftHandle;e?(t&&t.canvas&&t.canvas.style&&!t.native&&(t.canvas.style.visibility=""),this.canvas.style.visibility="hidden",this.liftFails=0,this.call.liftProven||(this.call.liftProven=!0,this.call._refreshLobby())):this.canvas.style.visibility="",this.call.log("lift-live",{peer:this.id,live:e}),this._renderBadge()}_liftError(e){this.lifted&&(this.call.log("lift-error",{peer:this.id,message:String(e&&e.message||e).slice(0,200)}),this.liftFailed=!0,this.reroute(!0),!(this.liftFails++>=Aa)&&(clearTimeout(this.liftTimer),this.liftTimer=setTimeout(()=>{this.liftFailed=!1,this.reroute(!1)},K(this.liftFails-1,{baseMs:3e3,maxMs:3e4}))))}_observeVisible(){this._io||typeof IntersectionObserver!="function"||(this._io=new IntersectionObserver(e=>{let t=e[e.length-1];this._onscreen=!!(t&&t.isIntersecting),this._updateVisible()}),this._io.observe(this.stage))}_updateVisible(){let e=this._onscreen!==!1&&!this.remote.cameraOff;e!==this.visible&&(this.visible=e,this.call.liftPool?.setVisible(this.id,e))}_layerFailed(){if(this.forceFlat=!0,this.reroute(!0),this.layerFails++>=Pa)return;let e=K(this.layerFails-1,{baseMs:1500,maxMs:2e4});this.call.log("layer-retry",{peer:this.id,attempt:this.layerFails,inMs:e}),clearTimeout(this.layerTimer),this.layerTimer=setTimeout(()=>{this.forceFlat=!1,this.call.woven&&this.reroute(!0)},e)}onWallLost(){this.handle=null,this.reroute(!0)}_unregister(){if(z(this.cover,!1),this.lifted){this.lifted=!1;for(let e of this._liftOff||[])typeof e=="function"&&e();this._liftOff=null,this.call.liftPool?.release(this.id),queueMicrotask(()=>this.call.state!=="left"&&this.call._rerouteMono()),this.liftHandle=null,this.liftLive=!1,this.canvas.style.visibility="",this.canvas.classList.remove("dxr-call-liftflat"),this._io&&(this._io.disconnect(),this._io=null),this.video.parentNode&&(this.video.remove(),this.video.classList.remove("dxr-call-liftsrc"),setTimeout(()=>this.video.srcObject&&this.video.play().catch(()=>{}),0))}if(this.handle){try{this.handle.remove()}catch{}this.handle=null}}paint(){this.route&&(this.route!=="woven-sbs"&&this.cursor?.idle(),this.route==="woven-sbs"?this._paintConv():this.route==="lifted"?this.liftLive||ks(this.canvas,this.video):ks(this.canvas,this.video,{eyeHalf:this.route==="flat-left"?0:null}))}_paintConv(){let e=this.video,t=e.videoWidth,i=e.videoHeight;if(!t||!i||(e.readyState||0)<2||!this.convCanvas)return;let n=t/2,s=this.call.o.tileAspect,{w:o,h:a}=Ie(n,i,s),l=this.convCanvas;(l.width!==2*o||l.height!==a)&&(l.width=2*o,l.height=a);let c=!!(this.cursor&&this.cursor.hovering);(this.call.o.autoConverge||c)&&this._sampleDisparity(e,t,i,c);let u=this.conv.step(n),f=l.getContext("2d"),h=[];for(let d of[0,1]){let p=h[d]=q(n,i,s,u,d);f.drawImage(e,d*n+p.sx,p.sy,p.sw,p.sh,d*o,0,o,a)}this.cursor&&this.cursor.draw(f,this.luma,{rL:h[0],rR:h[1],outW:o,outH:a,handle:this.handle},performance.now()/1e3)}_sampleDisparity(e,t,i,n=!1){let s=performance.now();if(this.autoPending||s-this.autoAt<(n?Ia:La))return;if(this.autoAt=s,typeof VideoFrame=="function"){let h=null;try{h=new VideoFrame(e)}catch{h=null}if(h&&Fa.has(h.format)){this.autoPending=!0;let d=this.autoGen,p=h.visibleRect?h.visibleRect.width:h.displayWidth,g=h.visibleRect?h.visibleRect.height:h.displayHeight,w=new Uint8Array(h.allocationSize());h.copyTo(w).then(m=>{if(d!==this.autoGen)return;let _=performance.now(),S=Math.max(1,Math.ceil(p/2/Cs)),x=nn(w,m[0].offset,m[0].stride,p,g,S);this._applyMeasurement(x.img,x.w,x.h,x.w/p,s,performance.now()-_,"videoframe")}).catch(()=>{d===this.autoGen&&this._applyMeasurement(null,0,0,1,s,0,"videoframe")}).finally(()=>{h.close(),this.autoPending=!1});return}h&&h.close()}let o=Math.min(1,Cs/(t/2)),a=Math.max(2,Math.round(t*o/2)*2),l=Math.max(2,Math.round(i*o));this.autoCanvas||(this.autoCanvas=document.createElement("canvas"));let c=this.autoCanvas;(c.width!==a||c.height!==l)&&(c.width=a,c.height=l);let u=c.getContext("2d",{willReadFrequently:!0}),f=null;try{u.drawImage(e,0,0,a,l),f=ut(u.getImageData(0,0,a,l).data,a*l)}catch{f=null}this._applyMeasurement(f,a,l,a/t,s,performance.now()-s,"canvas")}_applyMeasurement(e,t,i,n,s,o,a){if(this.destroyed||(e&&(this.luma={img:e,w:t,h:i,scale:n}),!this.call.o.autoConverge))return;let l=performance.now(),c=e?this.autoFocus.measure(e,t,i,s):null,u=this.autoTrack.push(c?c.d/n:null);this.conv.measuredPx=u,this.autoStats.n++,this.autoStats.readMs+=o,this.autoStats.ms+=o+(performance.now()-l),this.autoStats.method=c?c.method:null,this.autoStats.via=a,c&&!this.autoLocked&&(this.autoLocked=!0,this.call.log("auto-converge",{peer:this.id,disparityPx:Math.round(u*10)/10,at:{x:Math.round(c.x/n),y:Math.round(c.y/n)},ncc:Math.round(c.c*100)/100,method:c.method,via:a,ms:Math.round(o+(performance.now()-l))}))}_resetAutoConverge(){this.autoGen++,this.luma=null,this.autoTrack.reset(),this.autoFocus.reset(),this.conv.measuredPx=null,this.autoLocked=!1}destroy(){this.destroyed=!0,this.autoGen++,this.cursor?.dispose(),this.cursor=null,clearTimeout(this.helloTimer),clearTimeout(this.layerTimer),clearTimeout(this.leaveTimer),clearTimeout(this.liftTimer),this._unregister(),this.video.srcObject=null,this.audio.srcObject=null,this.el.remove()}},pr=class{constructor(e,t){this.call=e,this.canvas=A("canvas"),this.badge=A("div",{class:"dxr-call-badge",part:"badge"}),this.plate=A("div",{class:"dxr-call-state dxr-call-hidden",part:"plate"}),this.stage=A("div",{class:"dxr-call-stage"},[this.canvas,this.badge,this.plate]),this.stage.style.aspectRatio=String(e.o.tileAspect),this.el=A("div",{class:"dxr-call-tile dxr-call-tile--self",part:"tile"},[this.stage,A("div",{class:"dxr-call-talk"})]),t.appendChild(this.el),this.view=null,this.cam=null}get route(){return this.view?this.view.route:null}update(){let e=this.call.local,t=this.call.t,i=!e||!e.videoTrack;this.plate.textContent=i?this.call.camStatus==="busy"?t("cameraBusy"):this.call.camStatus==="pending"?"":t("noCamera"):this.call.camOff?t("cameraOffPlate"):"",z(this.plate,i||this.call.camOff),this.reroute(!1)}reroute(e){let t=this.call.local,i=t&&t.videoTrack?t.cam:null,n=this.call.woven?this.call.wall:{supported:!1};if(!i||i.state!=="live")return this.detach(),this._badge();this.view&&this.cam===i?this.view._reroute(e,n):(this.detach(),this.cam=i,this.view=tr(n,this.canvas,i,{autoConverge:!!this.call.o.autoConverge,cursor:this.call.o.cursor||void 0,aspect:this.call.o.tileAspect,onRouteChange:(s,o)=>{this.cam===i&&(this.call.log("self-route",{route:s,woven:o.woven,reason:o.reason}),this._badge())}})),this._badge()}_badge(){let e=this.call.t,t=!!(this.view&&this.view.woven);this.badge.replaceChildren(A("b",{text:`${e("you")} \xB7 ${e(t?"badge3D":"badge2D")}`})),this.badge.dataset.route=this.route||""}diag(){return this.view?this.view.weaveState():{route:null,woven:!1,reason:"no-camera",firstWoven:null,layerRetries:0}}onWallLost(){this.view?._onWallLost(),this._badge()}detach(){this.view&&this.view.remove(),this.view=null,this.cam=null}setSpeaking(e){this.el.classList.toggle("dxr-call-tile--speaking",e)}},ja="1.31",Ts=new Set;function F(r,e,t){let i=()=>{Ts.has(r)||(Ts.add(r),console.warn(`${Z} \`${r}\` is internal and leaves '@displayxr/inline3d/call' in ${ja} \u2014 import it from ${e} if you must, or stop depending on it`))};return typeof t=="function"?new Proxy(t,{apply(n,s,o){return i(),Reflect.apply(n,s,o)},construct(n,s){return i(),Reflect.construct(n,s)}}):t&&typeof t=="object"?new Proxy(t,{get(n,s,o){return typeof s=="string"&&i(),Reflect.get(n,s,o)}}):t}var vc=F("normalizeCallOptions","js/call/options.js",ar),yc=F("newRoomId","js/call/wire.js",fi),wc=F("isValidRoomId","js/call/wire.js",me),bc=F("buildInviteLink","js/call/wire.js",at),xc=F("normalizeHello","js/call/wire.js",pi),Sc=F("makeHello","js/call/wire.js",mi),Mc=F("routeFor","js/call/wire.js",vi),Ec=F("badgeFor","js/call/wire.js",yi),Rc=F("createLiveGate","js/call/wire.js",wi),Cc=F("convergenceShiftPx","js/camera/converge.js",rt),kc=F("lowPass","js/camera/converge.js",st),Tc=F("clampShift","js/camera/converge.js",nt),Oc=F("eyeCropRect","js/camera/geometry.js",q),Dc=F("mirrorSwapOps","js/camera/geometry.js",fe),Pc=F("mirrorSwapPixels","js/camera/geometry.js",hi),Ac=F("maxBitrateKbps","js/call/wire.js",lt),Lc=F("measureFocusDisparity","js/camera/disparity.js",Mi),Ic=F("preferVideoCodecs","js/call/sdp.js",ze),Fc=F("sortCodecCapabilities","js/call/sdp.js",ct),Nc=F("VIDEO_CODEC_ORDER","js/call/sdp.js",je),jc=F("MeshTransport","js/call/transport.js",We),zc=F("clampMaxPeers","js/call/transport.js",He),Wc=F("qrEncode","js/call/qr.js",nr),Hc=F("roomKey","js/call/signaling.js",sr);var $c=F("PLATE_TEXT","js/call/ui.js (CALL_STRINGS)",Object.freeze({unreachable:Ge.unreachable,cameraBusy:Ge.cameraBusy})),Uc=F("CALL_ACCENTS","js/call/ui.js",or),Vc=F("normalizeMono3D","js/call/lift.js",Ae),Bc=F("resolveLift","js/call/lift.js",Wt),Xc=F("createLiftPool","js/call/lift.js",Ut),qc=F("createFrameWatch","js/call/lift.js",$t),Gc=F("liftConvergenceFor","js/call/lift.js",Pe),Yc=F("liftPriorityFor","js/call/lift.js",Ye),Kc=F("setLiftPriority","js/call/lift.js",Ht),Jc=F("defaultLiftSpecifier","js/call/lift.js",zt),Zc=F("LIFT_PRIORITY","js/call/lift.js",De);Nt();gr(()=>new URL("./lift.js",import.meta.url).href);export{cr as CALL_EVENT_PREFIX,cs as CAMERA_SDK,Ft as DXR_SIGNAL_DEFAULT,ke as DxrCallElement,Os as addCall,tr as addCameraView,hr as attrsToOpts,Ur as createInline3D,Nt as defineCallElement,Re as dxrSignaling,Hr as inline3DAvailable,It as isStereoCamera,ur as mountCall,er as openCamera,Ne as parseInviteLink,ki as parseStereoXmp,pn as readJpegStereoMeta,Ti as readJpegXmp,bn as readWebmStereoMeta,it as sharedInline3D,Lt as suggestedName};
|
|
100
|
+
`;function xs(r=document){if(r.getElementById(vs))return;let e=r.createElement("style");e.id=vs,e.textContent=Ma,(r.head||r.documentElement).appendChild(e)}var ae=r=>`<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${r}"/></svg>`,J={mic:ae("M12 14a3 3 0 0 0 3-3V5a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21h2v-3.08A7 7 0 0 0 19 11z"),micOff:ae("M19 11h-2a5 5 0 0 1-.4 1.97l1.47 1.47A6.96 6.96 0 0 0 19 11zM15 11V5a3 3 0 0 0-5.94-.6L15 10.34zM4.27 3 3 4.27l6 6V11a3 3 0 0 0 4.52 2.59l1.46 1.46A5 5 0 0 1 7 11H5a7 7 0 0 0 6 6.92V21h2v-3.08a6.9 6.9 0 0 0 3.02-1.14L19.73 21 21 19.73z"),cam:ae("M17 10.5V7a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-3.5l4 4v-11z"),camOff:ae("M21 6.5l-4 4V7a1 1 0 0 0-1-1H9.82L21 17.18zM3.27 2 2 3.27 4.73 6H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h12c.21 0 .39-.08.54-.18L19.73 21 21 19.73z"),link:ae("M3.9 12a3.1 3.1 0 0 1 3.1-3.1h4V7H7a5 5 0 0 0 0 10h4v-1.9H7A3.1 3.1 0 0 1 3.9 12zM8 13h8v-2H8zm9-6h-4v1.9h4a3.1 3.1 0 0 1 0 6.2h-4V17h4a5 5 0 0 0 0-10z"),leave:ae("M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85a1 1 0 0 1-1.41-.02L.29 13.08a1 1 0 0 1 0-1.41C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67a1 1 0 0 1 0 1.41l-2.48 2.48a1 1 0 0 1-1.41.02 11.3 11.3 0 0 0-2.66-1.85 1 1 0 0 1-.56-.9v-3.1A15.3 15.3 0 0 0 12 9z"),mutedSmall:ae("M19 11h-2a5 5 0 0 1-.4 1.97l1.47 1.47A6.96 6.96 0 0 0 19 11zM15 11V5a3 3 0 0 0-5.94-.6L15 10.34zM4.27 3 3 4.27l6 6V11a3 3 0 0 0 4.52 2.59l1.46 1.46A5 5 0 0 1 7 11H5a7 7 0 0 0 6 6.92V21h2v-3.08a6.9 6.9 0 0 0 3.02-1.14L19.73 21 21 19.73z")};function A(r,e={},t=[]){let i=document.createElement(r);for(let[n,s]of Object.entries(e))s!=null&&(n==="class"?i.className=s:n==="html"?i.innerHTML=s:n==="text"?i.textContent=s:n.startsWith("on")&&typeof s=="function"?i.addEventListener(n.slice(2),s):n in i&&typeof s!="string"?i[n]=s:i.setAttribute(n,s));for(let n of[].concat(t))n&&i.appendChild(typeof n=="string"?document.createTextNode(n):n);return i}var z=(r,e)=>r&&r.classList.toggle("dxr-call-hidden",!e);we();var Ms="[inline3d/call]",Ea="https://github.com/DisplayXR/displayxr-browser",Es=Object.freeze({accent:"theme.accent",tileAspect:"theme.tileAspect",inviteBase:"invite.base",updateUrl:"invite.updateUrl",browserUrl:"landing.browserUrl",maxLifted:"liftOptions.max",calibration:"openCamera({ calibration }) of '@displayxr/inline3d/camera' (pass the camera as `camera`)",rectify:"openCamera({ rectify }) of '@displayxr/inline3d/camera'",log:"debug: true (and diagnostics())",recoverSession:"nothing \u2014 a call always recovers the document's session (sharedInline3D())",wallOptions:"sharedInline3D(opts) \u2014 the document's wall is configured by the page",scrollIntoView:"nothing \u2014 always on with ui: true"}),Ss=new Set;function Ra(r){Ss.has(r)||(Ss.add(r),console.warn(`${Ms} option \`${r}\` is deprecated (removed in 1.31) \u2014 use ${Es[r]}`))}function ar(r={}){for(let b of Object.keys(Es))r[b]!==void 0&&Ra(b);let e=r.theme&&typeof r.theme=="object"?r.theme:{},t=r.invite&&typeof r.invite=="object"?r.invite:{},i=r.landing&&typeof r.landing=="object"?r.landing:{},n=r.ui===void 0?!0:r.ui==="tiles"?"tiles":!!r.ui,s=n===!0,o=e.tileAspect!==void 0?e.tileAspect:r.tileAspect,a=typeof o=="number"&&o>.3&&o<4?o:16/9,l=r.room===void 0||r.room===null?"auto":r.room;if(l!=="auto"&&!me(l)){let b=Ne(l);if(!b)throw new Error(`@displayxr/inline3d/call: room "${l}" is not a valid room id (16-64 base64url chars) or invite link`);l=b}let c=r.liftOptions&&typeof r.liftOptions=="object"?{...r.liftOptions}:null,d=c&&c.max!==void 0?c.max:r.maxLifted;c&&delete c.max;let f=e.accent!==void 0?e.accent:r.accent,h={};for(let[b,w]of Object.entries(ws)){let g=b==="accent"?f:e[b];typeof g=="string"&&g?h[w]=b==="accent"?ys(g):g:typeof g=="number"&&b==="radius"&&(h[w]=`${g}px`)}let u=t.base!==void 0?t.base:r.inviteBase,m=t.updateUrl!==void 0?t.updateUrl:r.updateUrl,p=i.browserUrl!==void 0?i.browserUrl:r.browserUrl;return{room:l,signaling:r.signaling||Re(void 0,typeof r.key=="string"&&r.key?{key:r.key}:{}),iceServers:Array.isArray(r.iceServers)?r.iceServers:void 0,camera:r.camera===void 0?"auto":r.camera,format:r.format==="sbs"?"sbs":r.format==="mono"?"mono":void 0,calibration:r.calibration&&typeof r.calibration=="object"?{...r.calibration}:{},rectify:typeof r.rectify=="function"?r.rectify:null,audio:r.audio===void 0?!0:!!r.audio,autoConverge:r.autoConverge===void 0?!0:!!r.autoConverge,cursor:yt(r.cursor,"@displayxr/inline3d/call"),mono3D:Ae(r.mono3D),maxPeers:He(r.maxPeers===void 0?pe:r.maxPeers),liftOptions:c&&Object.keys(c).length?c:null,maxLifted:Number.isFinite(+d)&&d!==null&&d!==void 0?Math.max(0,Math.min(pe,Math.floor(+d))):pe,layout:r.layout==="speaker"?"speaker":r.layout==="none"?"none":"grid",ui:n,chrome:s,autoJoin:r.autoJoin===void 0?!s:!!r.autoJoin,selfView:r.selfView===void 0?!0:!!r.selfView,tileAspect:a,cssVars:h,strings:e.strings&&typeof e.strings=="object"?{...e.strings}:null,invite:{base:typeof u=="string"?u:null,updateUrl:m===void 0?s:!!m},landing:{browserUrl:typeof p=="string"?p:Ea,allow2D:i.allow2D===void 0?!0:!!i.allow2D},debug:!!r.debug,log:typeof r.log=="function"?r.log:r.debug?(b,w)=>console.log(`${Ms} ${b} ${JSON.stringify(w)}`):null,_liftImporter:typeof r._liftImporter=="function"?r._liftImporter:void 0}}var ec=Object.freeze(["normalizeCallOptions","newRoomId","isValidRoomId","buildInviteLink","normalizeHello","makeHello","routeFor","badgeFor","createLiveGate","convergenceShiftPx","lowPass","clampShift","eyeCropRect","mirrorSwapOps","mirrorSwapPixels","maxBitrateKbps","measureFocusDisparity","preferVideoCodecs","sortCodecCapabilities","VIDEO_CODEC_ORDER","MeshTransport","clampMaxPeers","qrEncode","roomKey","SIGNAL_PROTOCOL","WIRE_VERSION","CALL_SDK","PLATE_TEXT","CALL_ACCENTS","normalizeMono3D","resolveLift","createLiftPool","createFrameWatch","liftConvergenceFor","liftPriorityFor","setLiftPriority","defaultLiftSpecifier","LIFT_PRIORITY"]);var cr="dxr-call:",Ca=["joined","left","peer","peerleft","state","display","speaker","quality","error","warning"],lr="[inline3d/call] <dxr-call>",Ce=r=>r!=null&&!/^(false|0|off|no)$/i.test(String(r).trim()),Rs=r=>{if(r==null||String(r).trim()==="")return;let e=/^\s*([0-9.]+)\s*\/\s*([0-9.]+)\s*$/.exec(String(r)),t=e?+e[1]/+e[2]:+r;return Number.isFinite(t)?t:void 0},H=r=>r==null||String(r).trim()===""?void 0:String(r).trim();function hr(r){let e=typeof r=="function"?r:l=>r&&typeof r.getAttribute=="function"?r.getAttribute(l):null,t={},i=(l,c)=>{c!==void 0&&(t[l]=c)};i("room",H(e("room")));let n=H(e("signaling"));n&&(t.signaling=Re(n,H(e("key"))?{key:H(e("key"))}:{})),i("key",H(e("key"))),i("camera",H(e("camera"))),i("layout",H(e("layout"))),i("maxPeers",Rs(e("max-peers")));let s=H(e("ui"));Ce(e("no-ui"))?t.ui=!1:s==="tiles"&&(t.ui="tiles"),Ce(e("auto-join"))&&(t.autoJoin=!0);let o=H(e("mono3d"));o&&/^(off|false|0|no)$/i.test(o)&&(t.mono3D="off"),Ce(e("no-audio"))&&(t.audio=!1),Ce(e("no-self-view"))&&(t.selfView=!1),Ce(e("no-auto-converge"))&&(t.autoConverge=!1),H(e("cursor"))==="depth"&&(t.cursor="depth");let a={accent:H(e("accent")),tileAspect:Rs(e("tile-aspect"))};return(a.accent!==void 0||a.tileAspect!==void 0)&&(t.theme=Object.fromEntries(Object.entries(a).filter(([,l])=>l!==void 0))),H(e("invite-base"))&&(t.invite={base:H(e("invite-base"))}),H(e("browser-url"))&&(t.landing={browserUrl:H(e("browser-url"))}),Ce(e("debug"))&&(t.debug=!0),t}var ka=typeof HTMLElement=="function"?HTMLElement:class{},ke=class r extends ka{static mount=null;constructor(){super(),this.options=null,this.call=null,this.ready=null,this._gen=0,this._off=[],this._pending=null}connectedCallback(){if(this.call||this._pending)return;let e=++this._gen,t={...hr(this),...this.options&&typeof this.options=="object"?this.options:{}},i=this.constructor.mount||r.mount||ur;this._pending=new Promise(n=>n(i(this,t))).then(n=>{if(this._pending=null,e!==this._gen)return n.leave(),null;if(this.call=n,this._off=Ca.map(s=>n.on(s,o=>this._dispatch(s,o))),this._off.push(n.on("error",s=>console.warn(`${lr} ${s.code}: ${s.message}`))),this._dispatch("ready",{call:n}),n.state==="in-call"){this._dispatch("joined",{room:n.room,id:n.id});for(let s of n.peers)this._dispatch("peer",{id:s.id})}return n},n=>{throw this._pending=null,this._dispatch("error",{code:"mount-failed",message:String(n&&n.message||n),error:n||null}),console.warn(`${lr} mount failed: ${String(n&&n.message||n)}`),n}),this.ready=this._pending,this.ready.catch(()=>{})}disconnectedCallback(){this._gen++;let e=this.call;this.call=null,e&&e.leave();for(let t of this._off)try{t()}catch{}this._off=[]}_dispatch(e,t){typeof CustomEvent!="function"||typeof this.dispatchEvent!="function"||this.dispatchEvent(new CustomEvent(cr+e,{detail:t,bubbles:!0,composed:!0}))}};function jt(r="dxr-call",e=globalThis.customElements){if(!e||typeof e.define!="function")return!1;let t=e.get(r);return t?(t!==ke&&console.warn(`${lr} <${r}> is already defined by another class; leaving it`),!1):(e.define(r,ke),!0)}var Z="[inline3d/call]",Ta=2e3,Oa=2500,Da=500,dr=.02,Pa=4,Aa=2,La=200,Cs=240,Ia=66,Fa=new Set(["I420","I420A","I422","I444","NV12"]);async function Os(r,e,t={}){if(!e||typeof e.appendChild!="function")throw new TypeError("@displayxr/inline3d/call: addCall(wall, container, opts) needs a container element");let i=ar(t);if(!i.signaling||typeof i.signaling.join!="function")throw new TypeError("@displayxr/inline3d/call: opts.signaling must be a SignalingAdapter \u2014 dxrSignaling([url]) or your own");let n=new fr(r,e,i);return await n._init(),n.handle}async function ur(r,e={}){if(!r||typeof r.appendChild!="function")throw new TypeError("@displayxr/inline3d/call: mountCall(el, opts) needs a container element");let{wall:t,...i}=e,n=t||await it(i.wallOptions);return Os(n,r,i)}var fr=class{constructor(e,t,i){this.o=i,this.t=bs(i.strings),this.container=t,this.wall=e||null,this.wallLive=!!(e&&e.supported),this.weaveLive=!1,this.camStatus="pending",this.id=Gr(),this.room=i.room==="auto"?Ne(globalThis.location):i.room,this.state="idle",this.tiles=new Map,this.listeners=new Map,this.local=null,this.muted=!1,this.camOff=!1,this.depth=0,this.speakerId=null,this.transport=null,this._raf=0,this._statsTimer=0,this._hintGate=vi(fi),this.mono3D=i.mono3D,this.mono3DOn=i.mono3D!=="off",this.liftApi=null,this.liftPool=null,this._liftP=null,this.liftProven=!1,this.liftMissing=!1,this._liftWarned=!1,this._frameWatch=Ut(),this.handle=this._makeHandle(),this.wallLive&&this._hookWall(this.wall)}get woven(){return!!(this.wall&&this.wall.supported&&this.wallLive)}log(e,t={}){this.o.log&&this.o.log(e,t)}emit(e,t){let i=this.listeners.get(e);if(i)for(let n of[...i])try{n(t)}catch(s){console.error(`${Z} '${e}' listener threw`,s)}}error(e,t,i){this.log("error",{code:e,message:t}),this.listeners.get("error")?.size||console.warn(`${Z} ${e}: ${t}`),this.emit("error",{code:e,message:t,error:i||null})}warning(e,t){this.log("warning",{code:e,message:t}),console.warn(`${Z} ${e}: ${t}`),this.emit("warning",{code:e,message:t})}async _init(){this._buildDom(),this.wallLive&&this._ensureLift(),await this._openMedia(this.o.camera),this._startLoop(),this.o.autoJoin?await this.join():this._setState("lobby")}async _openMedia(e,t,{keepOnFail:i=!1}={}){let n=(h,u)=>this.log(h,u),s=null,o=null,a=Ft(e)?e:null;try{if(s=a||await er({prefer:e,format:t||this.o.format,calibration:this.o.calibration,rectify:this.o.rectify||void 0,log:n}),a&&a.state!=="live")throw Object.assign(new Error("the camera given is not live"),{code:"no-camera",skipped:[]})}catch(h){o=h;let u=h.code==="camera-busy";if(this.error(u?"camera-busy":h.code||"no-camera",u?`${this.t("cameraBusy")}. Joining audio-only.`:`no camera: ${h.message}. Joining audio-only.`,h),i&&this.local&&this.local.videoTrack)return this.local;this.camStatus=u?"busy":"none"}s&&(this.camStatus="ok"),s&&s.rectifyError&&this.error("rectify-failed",`rectify() threw \u2014 sending the raw pair: ${s.rectifyError.message}`,s.rectifyError);let l=this.local?this.local.audioTrack:null;this.o.audio&&!l&&(l=await tn({log:n})),l&&(l.enabled=!this.muted);let c=s&&s.stream.getVideoTracks()[0]||null;if(c){try{c.contentHint="detail"}catch{}c.enabled=!this.camOff}let d=new MediaStream([c,l].filter(Boolean)),f=this.local;return this.local={stream:d,cam:s,camStream:s?s.stream:null,video:s?s.video:null,videoTrack:c,audioTrack:l,format:s?s.format:"mono",width:s?s.width:0,height:s?s.height:0,calibration:s?s.calibration:{},owned:s?s.owned&&s!==a:!1,label:s?s.label:"",skipped:s?s.skipped:o?.skipped||[]},s&&s!==f?.cam&&(this._camEndedOff?.(),this._camEndedOff=s.on("ended",()=>{this.local?.cam===s&&(this.local.videoTrack=null,this.camStatus="none",this.error("no-camera",'the camera ended (revoked, unplugged, or taken by another app). Audio-only until "Retry camera".'),this.transport?.broadcast(this.stateMsg()),this._refreshSelf(),this._refreshBar())})),this.log("camera",{format:this.local.format,width:this.local.width,height:this.local.height,label:this.local.label,skipped:this.local.skipped.length}),f&&f.owned&&f.cam&&f.cam!==s&&f.cam.close(),this._refreshSelf(),this._refreshLobby(),this.local}hello(){let e=this.local||{};return gi({format:e.format,width:e.width,height:e.height,baselineMm:e.calibration?.baselineMm,hfovDeg:e.calibration?.hfovDeg,rectified:!!e.calibration?.rectified})}stateMsg(){return{type:"state",muted:this.muted,cameraOff:this.camOff||!this.local?.videoTrack,speaking:!!this._selfSpeaking}}async join(){if(this.state==="joining"||this.state==="in-call")return this.handle;if(this.state==="left"&&!this.local?.videoTrack&&await this._openMedia(this.o.camera),this.room||(this.room=pi(),this.log("room-created",{})),this.o.invite.updateUrl&&globalThis.history&&globalThis.location)try{history.replaceState(history.state,"",at(location.href,this.room))}catch{}this._setState("joining");let e=new We({signaling:this.o.signaling,id:this.id,maxPeers:this.o.maxPeers,iceServers:this.o.iceServers,log:(i,n)=>this.log(i,n)});this.transport=e;let t=null;try{t=await e.start({room:this.room,localStream:this.local.stream,sendFormat:this.local.format,onPeer:i=>this._onPeer(i),onPeerLeft:(i,n)=>this._onPeerLeft(i,n),onStream:(i,n)=>this.tiles.get(i)?.setStream(n),onMessage:(i,n)=>this._onMessage(i,n),onPeerState:(i,n)=>{this.tiles.get(i)?.setConn(n),this.emit("state",{id:i,state:n})},onRefused:i=>this.log("refused-peer",{id:i}),onGhost:(i,n)=>this._onGhost(i,n),onSignalingState:(i,n)=>{this.log("signaling",{state:i}),i==="closed"&&n&&this.error(n.code||"signaling-closed",n.message,n)}})}catch(i){throw this.transport=null,i&&i.code==="room-full"?(this._setState("full"),this.error("room-full",i.message,i)):(this._setState("lobby"),this.error(i.code||"join-failed",`could not join: ${i.message}`,i)),i}if(this._setState("in-call"),this.o.chrome)try{this.container.scrollIntoView?.({block:"start",behavior:"instant"}),this._fitGrid()}catch{}return this._startStats(),this._pagehide=()=>this.leave("pagehide"),globalThis.addEventListener?.("pagehide",this._pagehide),this.log("joined",{id:this.id,peers:this.tiles.size}),this.emit("joined",{room:this.room,id:this.id}),setTimeout(()=>{this.transport===e&&this._reportTurn(t)},0),this.handle}_reportTurn(e){let t=e&&e.turn;!t||typeof t!="object"||(t.status==="off"&&t.reason==="cap"?this.error("turn-cap","relay (TURN) capacity for this month is used up; direct connections still work, but a participant behind a strict NAT may be unreachable",null):(t.reason==="budget"||t.reason==="rate")&&this.warning("turn-shed",t.reason==="rate"?"no relay (TURN) for this session: too many credential requests from this address this hour":"no relay (TURN) for this anonymous session: the hosted service is near its monthly relay budget (a publishable key keeps TURN)"))}_onPeer(e){if(this.tiles.has(e))return;let t=new zt(this,e);this.tiles.set(e,t),this._layout(),this.emit("peer",{id:e})}_onGhost(e,t){let i=this.tiles.get(e);if(t&&!i){let n=new zt(this,e);n.ghost=!0,this.tiles.set(e,n),n.setConn("unreachable"),this._layout()}else!t&&i&&i.ghost&&(i.destroy(),this.tiles.delete(e),this._layout())}_onPeerLeft(e,t){let i=this.tiles.get(e);i&&(i.setConn("left"),this.emit("peerleft",{id:e,reason:t}),i.leaveTimer=setTimeout(()=>{i.destroy(),this.tiles.get(e)===i&&this.tiles.delete(e),this.speakerId===e&&this._setSpeaker(null),this._layout()},Oa))}_onMessage(e,t){let i=this.tiles.get(e);if(!i||!t)return;if(t.type==="__open"){this.transport.send(e,this.hello()),this.transport.send(e,this.stateMsg()),i.onChannelOpen();return}let n=mi(t);if(n)return i.setHello(n);let s=_i(t);if(s)return i.setHint(s);let o=Kr(t);if(o)return i.setRemoteState(o)}inviteLink(){if(!this.room)return null;let e=this.o.invite.base||(globalThis.location?location.href:"");return at(e,this.room)}mute(e){return this.muted=e===void 0?!this.muted:!!e,this.local?.audioTrack&&(this.local.audioTrack.enabled=!this.muted),this.transport?.broadcast(this.stateMsg()),this._refreshBar(),this.log("mute",{muted:this.muted}),this.muted}setCameraOff(e){return this.camOff=e===void 0?!this.camOff:!!e,this.local?.videoTrack&&(this.local.videoTrack.enabled=!this.camOff),this.transport?.broadcast(this.stateMsg()),this._refreshBar(),this._refreshSelf(),this.camOff}setDepth(e){let t=e==null||!Number.isFinite(+e)?0:Math.max(-1,Math.min(1,+e));this.depth=t;for(let i of this.tiles.values())i.conv.depth=t;return this.liftPool?.setDepth(t),this.ui?.depth&&+this.ui.depth.value!==t&&(this.ui.depth.value=String(t)),t}async setCamera(e,{format:t}={}){let i=this.local?.format,n=await this._openMedia(e,t,{keepOnFail:!0});return this.transport&&(await this.transport.replaceTrack("video",n.videoTrack,n.stream),await this.transport.setSendFormat(n.format),this.transport.broadcast(this.hello()),this.transport.broadcast(this.stateMsg())),i!==n.format&&this.log("send-format",{format:n.format}),{format:n.format,width:n.width,height:n.height,label:n.label}}retryCamera(){return this.setCamera(this.o.camera,{format:this.o.format})}sendHint(e){if(!this._hintGate(performance.now()))return!1;let t=_i({type:"hint",subjectZmm:e});return t?(this.transport?.broadcast(t),!0):!1}leave(e="left"){if(this.state!=="left"){globalThis.removeEventListener?.("pagehide",this._pagehide),this.transport?.stop(),this.transport=null;for(let t of this.tiles.values())t.destroy();this.tiles.clear(),this.liftPool?.releaseAll(),clearInterval(this._statsTimer),this._setSpeaker(null),this.local&&(this._camEndedOff?.(),this._camEndedOff=null,this.local.stream.getTracks().forEach(t=>t.stop()),this.local.owned&&this.local.cam?this.local.cam.close():this.local.cam&&this.self?.detach(),this.local.videoTrack=null,this.local.audioTrack=null),this.self?.detach(),this._unhookWall(),this._setState("left"),this._layout(),this.emit("left",{room:this.room,reason:e})}}_hookWall(e){if(!e||!e.session||typeof e.session.addEventListener!="function")return;let t=e.close;this._wallHook={w:e,orig:t,pageClosed:!1};let i=this._wallHook;e.close=(...n)=>(i.pageClosed=!0,t.apply(e,n)),i.onEnd=()=>this._sessionEnded(i),e.session.addEventListener("end",i.onEnd),this._watchLive(e)}_watchLive(e){this.weaveLive=!1;let t=e.session;if(!t||typeof t.requestAnimationFrame!="function"){this.weaveLive=!0;return}let i=bi(),n=performance.now(),s=(o,a)=>{if(e!==this.wall||!this.wallLive||this.state==="left")return;let l=null;if(e.refSpace)try{let c=a.getViewerPose(e.refSpace);l=c&&c.views?c.views.length:0}catch{l=0}if(!i.feed(l)){try{t.requestAnimationFrame(s)}catch{}return}this.weaveLive=!0,this.log("weave-live",{ms:Math.round(performance.now()-n)});for(let c of this.tiles.values())(c.route==="woven-sbs"||c.route==="lifted")&&c.reroute(!0);this.self&&this.self.route==="woven-sbs"&&this.self.reroute(!0),this._layout()};try{t.requestAnimationFrame(s)}catch{this.weaveLive=!0}}_unhookWall(){let e=this._wallHook;if(e){this._wallHook=null,e.w.close!==e.orig&&(e.w.close=e.orig);try{e.w.session.removeEventListener("end",e.onEnd)}catch{}}}_sessionEnded(e){if(this._wallHook===e){this.wallLive=!1,this.weaveLive=!1,this.log("session-ended",{byPage:e.pageClosed});for(let t of this.tiles.values())t.onWallLost();if(this.self?.onWallLost(),e.pageClosed||this.state==="left"){this._unhookWall();return}this.error("session-ended","the inline-3D session ended; tiles are flat while it is re-opened"),this._unhookWall(),this._recoverWall(0)}}_recoverWall(e){this.state==="left"||e>10||setTimeout(async()=>{if(this.state==="left")return;let t=null;try{t=await it()}catch{t=null}if(!t||!t.supported)return this._recoverWall(e+1);this.wall=t,this.wallLive=!0,this._hookWall(t),this.log("session-recovered",{attempt:e});for(let i of this.tiles.values())i.reroute(!0);this.self?.reroute(!0)},K(e,{baseMs:1e3,maxMs:15e3}))}_startLoop(){let e=0,t=i=>{this._raf=requestAnimationFrame(t);for(let n of this.tiles.values())n.paint();e&&this.liftPool&&this.liftPool.anyWeb&&this._watchFrames(i-e),e=i};this._raf=requestAnimationFrame(t)}_watchFrames(e){let t=this._frameWatch.feed(e);if(!t)return;let i={degraded:t==="degraded",frameMs:Math.round(this._frameWatch.frameMs*10)/10,tiles:this.liftPool.size};this.log("lift-frame-time",i),t==="degraded"&&console.warn(`${Z} lifted tiles are slowing the page (~${Math.round(1e3/i.frameMs)} fps with ${i.tiles} lifted) \u2014 setMono3D(false) shows mono peers flat`),this.emit("quality",{id:null,in:null,out:null,lift:i})}_ensureLift(){if(!this.mono3DOn)return Promise.resolve(null);if(!this._liftP){let e=(n,s)=>this.log(n,s),t=this.o.liftOptions,i={webFallback:!0,...t&&t.models?{models:t.models}:{}};this._liftP=Ht(this.mono3D,{log:e,capsOpts:i,...this.o._liftImporter?{importer:this.o._liftImporter}:{}}).then(n=>(this.liftApi=n,n.lift?(this.liftPool=Vt({lift:n.lift,max:this.o.maxLifted,log:e,options:this.o.liftOptions}),this.liftPool.setDepth(this.depth),this.liftPool.setSpeaker(this.speakerId),!n.caps&&n.capabilities&&Promise.resolve().then(()=>n.capabilities(i)).then(s=>{n.caps=s||null,this._refreshLobby()}).catch(()=>{})):n.reason==="import-failed"||n.reason==="no-lift-export"?this.liftMissing=!0:n.reason!=="off"&&console.info(`${Z} mono\u21923D unavailable (${n.reason}) \u2014 mono participants are shown flat`),this._rerouteMono(),this._refreshLobby(),n))}return this._liftP}_warnLiftMissing(){this._liftWarned||!this.liftMissing||!this.mono3DOn||(this._liftWarned=!0,this.warning("lift-not-bundled","a 2D participant is on a 3D display but the 2D\u21923D module could not be imported from this build, so they stay flat. Import it explicitly \u2014 `import { lift } from '@displayxr/inline3d/lift'; mountCall(el, { mono3D: lift })` \u2014 or use `@displayxr/inline3d/call/full`, which bundles it."))}_rerouteMono(){for(let e of this.tiles.values())e.format&&e.format!=="sbs"&&e.reroute(!1)}setMono3D(e){let t=e===void 0?!this.mono3DOn:!!e;return t===this.mono3DOn||(this.mono3DOn=t,t&&this.mono3D==="off"&&(this.mono3D="auto"),this._frameWatch.reset(),this.log("mono3d",{on:t}),this._rerouteMono(),t&&this.wallLive&&this._ensureLift(),this._refreshLobby()),t}_liftHint(){if(!this.wallLive)return"";let e=this.t;if(!this.mono3DOn)return e("liftOff");let t=this.liftApi;if(!t)return e("liftChecking");if(!t.lift)return this.liftMissing?e("liftMissing"):e("liftNoProvider");let i=t.caps;return i&&i.native?e("liftNative",{provider:i.provider?`, ${i.provider}`:""}):i&&i.webFallback&&i.webFallback.webgpu?e("liftWeb"):this.liftProven?e("liftProven"):e("liftUnproven")}_mono3DInfo(){let e=this.liftApi,t=e&&e.caps;return Object.freeze({on:this.mono3DOn,state:this.mono3DOn?e?e.lift?"ready":"unavailable":this._liftP?"loading":"idle":"off",reason:e?e.reason:null,native:t?!!t.native:null,provider:t&&t.provider||null,lifted:this.liftPool?this.liftPool.size:0,max:this.o.maxLifted,proven:this.liftProven})}_startStats(){clearInterval(this._statsTimer);let e=0;this._statsTimer=setInterval(()=>this._stats(++e%4===0),Da)}async _stats(e){if(!this.transport)return;let t=null,i=0;for(let[o,a]of this.tiles){let l=this.transport.peerConnection(o);if(!l)continue;let c;try{c=await l.getStats()}catch{continue}let d={};c.forEach(u=>{u.type==="codec"&&(d[u.id]=u.mimeType)});let f={in:null,out:null};c.forEach(u=>{if(u.type==="inbound-rtp"&&u.kind==="audio"&&typeof u.audioLevel=="number"&&(a.level=Math.max(u.audioLevel,(a.level||0)*.6)),u.type==="media-source"&&u.kind==="audio"&&typeof u.audioLevel=="number"&&(i=Math.max(i,u.audioLevel)),!!e){if(u.type==="inbound-rtp"&&u.kind==="video"){let m=a._prevIn;f.in={width:u.frameWidth||0,height:u.frameHeight||0,fps:u.framesPerSecond||0,codec:d[u.codecId]||null,kbps:m?Math.round((u.bytesReceived-m.bytes)*8/(u.timestamp-m.t)):null,dropped:u.framesDropped||0,decoder:u.decoderImplementation||null},a._prevIn={bytes:u.bytesReceived,t:u.timestamp}}else if(u.type==="outbound-rtp"&&u.kind==="video"){let m=a._prevOut;f.out={width:u.frameWidth||0,height:u.frameHeight||0,fps:u.framesPerSecond||0,codec:d[u.codecId]||null,kbps:m?Math.round((u.bytesSent-m.bytes)*8/(u.timestamp-m.t)):null,limitation:u.qualityLimitationReason||null,encoder:u.encoderImplementation||null},a._prevOut={bytes:u.bytesSent,t:u.timestamp}}}}),e&&(f.in||f.out)&&(a.quality=f,this.emit("quality",{id:o,...f}));let h=a.remote.muted?0:a.level||0;a.setSpeaking(h>dr||a.remote.speaking),h>dr&&(!t||h>t.lvl)&&(t={id:o,lvl:h})}let n=t?t.id:null;n&&n!==this.speakerId?(this._challengeTicks=this._challenger===n?(this._challengeTicks||0)+1:1,this._challenger=n,this._challengeTicks>=2&&this._setSpeaker(n)):(this._challenger=null,this._challengeTicks=0);let s=!this.muted&&i>dr;s!==!!this._selfSpeaking&&(this._selfSpeaking=s,this.transport?.broadcast(this.stateMsg()),this.self?.setSpeaking(s))}_setSpeaker(e){e!==this.speakerId&&(this.speakerId=e,this._challengeTicks=0,this.liftPool?.setSpeaker(e),this.emit("speaker",{id:e}),this.o.layout==="speaker"&&this._layout())}_fitGrid(){let e=this.ui;if(!e||!this.o.chrome||typeof globalThis.innerHeight!="number")return;let t=this.container.getBoundingClientRect?.(),i=e.grid.getBoundingClientRect?.();if(!t||!i||!i.height)return;let n=Math.max(160,Math.floor(globalThis.innerHeight-Math.max(0,t.top)-(t.height-i.height)-8)),s=parseFloat(this.container.style.getPropertyValue("--dxr-call-fit"))||0;Math.abs(n-s)>2&&this.container.style.setProperty("--dxr-call-fit",`${n}px`),this._fitHooked||(this._fitHooked=!0,globalThis.addEventListener?.("resize",()=>this._fitGrid()))}_setState(e){this.state=e,this.log("state",{state:e}),this._layout()}_buildDom(){let e=this.container,t=this.t;xs(e.ownerDocument||document),e.classList.add("dxr-call-host");for(let[n,s]of Object.entries(this.o.cssVars))e.style.setProperty(n,s);let i=this.ui={};i.banner=A("div",{class:"dxr-call-banner dxr-call-hidden",part:"banner"},[A("span",{text:t("banner2D")}),A("a",{href:this.o.landing.browserUrl,target:"_blank",rel:"noopener",text:t("bannerLink")})]),i.grid=A("div",{class:"dxr-call-grid",part:"grid","data-layout":this.o.layout,"data-n":"0"}),i.panel=A("div",{class:"dxr-call-panel dxr-call-hidden",part:"lobby"}),i.selfSlot=A("div",{class:"dxr-call-self",part:"self"}),i.bar=A("div",{class:"dxr-call-bar",part:"bar"}),i.foot=A("div",{class:"dxr-call-foot"},[i.selfSlot,i.bar]),i.invite=A("div",{class:"dxr-call-panel dxr-call-hidden",part:"invite"}),this.o.chrome||z(i.bar,!1),e.append(i.banner,i.panel,i.grid,i.invite,i.foot),this.o.selfView?this.self=new pr(this,i.selfSlot):z(i.selfSlot,!1),this.o.chrome&&this._buildBar()}_buildBar(){let e=this.ui,t=this.t,i=(n,s,o,a="")=>A("button",{class:`dxr-call-ib ${a}`,type:"button","aria-label":n,title:n,html:s,onclick:o});e.mic=i(t("mute"),J.mic,()=>this.mute()),e.cam=i(t("cameraOff"),J.cam,()=>this.local?.videoTrack?this.setCameraOff():this.retryCamera().catch(()=>{})),e.depth=A("input",{type:"range",min:"-1",max:"1",step:"0.05",value:"0","aria-label":t("depth")}),e.depth.addEventListener("input",()=>this.setDepth(+e.depth.value)),e.depth.addEventListener("dblclick",()=>this.setDepth(0)),e.inviteBtn=i(t("invite"),J.link,()=>{this._showInvite=!this._showInvite,this._layout()}),e.leave=i(t("leave"),J.leave,()=>this.leave(),"dxr-call-ib--leave"),e.bar.append(e.mic,e.cam,A("label",{class:"dxr-call-depth"},[t("depth"),e.depth]),e.inviteBtn,e.leave)}_refreshBar(){let e=this.ui;if(!e||!e.mic)return;let t=this.t;e.mic.innerHTML=this.muted?J.micOff:J.mic,e.mic.setAttribute("aria-pressed",String(this.muted)),e.mic.title=this.muted?t("unmute"):t("mute");let i=!this.local?.videoTrack;e.cam.innerHTML=this.camOff||i?J.camOff:J.cam,e.cam.setAttribute("aria-pressed",String(this.camOff||i)),e.cam.title=i?this.camStatus==="busy"?t("cameraBusyRetry",{cameraBusy:t("cameraBusy")}):t("cameraRetry"):this.camOff?t("cameraOn"):t("cameraOff")}_refreshSelf(){this.self?.update()}_refreshLobby(){(this.state==="lobby"||this.state==="idle")&&this._layout()}_renderInvite(e,t,i){e.replaceChildren();let n=this.inviteLink();if(!n)return;let s=this.t,o=A("input",{type:"text",readOnly:!0,value:n,"aria-label":s("inviteLink")});o.addEventListener("focus",()=>o.select());let a=A("button",{class:"dxr-call-btn dxr-call-btn--primary",type:"button",text:s("copyLink")});a.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(n),a.textContent=s("copied")}catch{o.select(),a.textContent=s("pressCopy")}setTimeout(()=>a.textContent=s("copyLink"),1800)});let l=A("canvas",{"aria-label":s("qrLabel"),role:"img"});try{ms(l,n,{px:4})}catch{l.style.display="none"}e.append(A("h3",{text:t}),A("p",{text:i}),A("div",{class:"dxr-call-invite"},[A("div",{class:"dxr-call-row",style:"flex:1 1 280px"},[o,a]),l]))}_layout(){let e=this.ui;if(!e)return;let t=this.container,i=this.t,n=this.o.chrome&&(this.state==="lobby"||this.state==="idle"||this.state==="full"||this.state==="left");t.classList.toggle("dxr-call-host--lobby",n),z(e.banner,this.o.chrome&&!this.woven);let s=this.tiles.size;e.grid.dataset.n=String(Math.min(s,4)),z(e.grid,s>0&&this.state!=="left");let o=this.o.layout==="speaker"?this.speakerId||[...this.tiles.keys()][0]:null;for(let[c,d]of this.tiles)d.el.classList.toggle("dxr-call-tile--main",c===o);if(!this.o.chrome)return;this._refreshBar(),queueMicrotask(()=>this._fitGrid());let a=e.panel;if(n){z(a,!0),a.replaceChildren();let c=this.local,d=!!this.room,f=this.state==="full"?i("lobbyFullTitle"):this.state==="left"?i("lobbyLeftTitle"):i(d?"lobbyJoinTitle":"lobbyStartTitle"),h={width:c?.width||0,height:c?.height||0},u=this.camStatus==="busy"?i("kindBusy"):!c||!c.videoTrack?i("kindNone"):c.format==="sbs"?i("kindSbs",h):i("kindMono",h),m=this.state==="full"?i("lobbyFullText",{maxPeers:this.o.maxPeers}):`${i("lobbyText",{camera:c?.label||i("cameraDefault"),kind:u})}${this._liftHint()?` ${this._liftHint()}`:""}`,p=A("button",{class:"dxr-call-btn dxr-call-btn--primary",type:"button",text:this.state==="left"?i("rejoin"):i(d?"join":"start")});p.addEventListener("click",()=>this.join().catch(()=>{}));let b=A("select",{class:"dxr-call-select","aria-label":i("cameraSelect")});this._fillCameras(b),b.addEventListener("change",()=>this.setCamera(b.value).catch(g=>this.error("camera-failed",g.message,g)));let w=!c||!c.videoTrack?A("button",{class:"dxr-call-btn",type:"button",text:i("retryCamera")}):null;w?.addEventListener("click",()=>this.retryCamera().catch(()=>{})),a.append(A("h3",{text:f}),A("p",{text:m}),A("div",{class:"dxr-call-row"},[this.state==="full"?null:p,w,b]))}else this.state==="in-call"&&s===0?(z(a,!0),this._renderInvite(a,i("waitingTitle"),i("waitingText"))):this.state==="joining"?(z(a,!0),a.replaceChildren(A("p",{text:i("joining")}))):z(a,!1);let l=this.state==="in-call"&&s>0&&this._showInvite;l&&!e.invite.childElementCount&&this._renderInvite(e.invite,i("inviteTitle"),i("inviteText")),z(e.invite,l),l||e.invite.replaceChildren(),e.inviteBtn?.setAttribute("aria-pressed",String(!!l))}diagnostics(){let e=this.local;return{sdk:di,wire:ot,state:this.state,wall:this.wall,wallLive:this.wallLive,weaveLive:this.weaveLive,woven:this.woven,local:e?{format:e.format,width:e.width,height:e.height,label:e.label,calibration:e.calibration,owned:e.owned,skipped:e.skipped,camera:e.cam||null,stream:e.stream}:null,hello:this.hello(),transport:this.transport,peers:[...this.tiles.values()].map(t=>t.diag()),self:this.self?this.self.diag():null,mono3D:{...this._mono3DInfo(),lift:this.liftApi,pool:this.liftPool?this.liftPool.list():[]},speaker:this.speakerId,depth:this.depth,options:this.o,kill:t=>this.transport?._debugKill(t)}}async _fillCameras(e){let t=[];try{t=(await navigator.mediaDevices.enumerateDevices()).filter(n=>n.kind==="videoinput")}catch{}let i=this.local?.videoTrack?.getSettings?.().deviceId;e.replaceChildren(...t.map((n,s)=>A("option",{value:n.deviceId,text:n.label||`Camera ${s+1}`}))),i&&(e.value=i),z(e,t.length>1)}_makeHandle(){let e=this,t={format:"display",session:null},i={get room(){return e.room},get id(){return e.id},get state(){return e.state},get localFormat(){return e.local?e.local.format:null},get muted(){return e.muted},get cameraOff(){return e.camOff},get depth(){return e.depth},get speaker(){return e.speakerId},get camera(){return e.camStatus},get mono3D(){return e._mono3DInfo()},get peers(){return Object.freeze([...e.tiles.values()].map(s=>s.info()))},join:()=>e.join().then(()=>{}),inviteLink:()=>e.inviteLink(),mute:s=>e.mute(s),setCameraOff:s=>e.setCameraOff(s),setCamera:(s,o)=>e.setCamera(s,o),setDepth:s=>e.setDepth(s),retryCamera:()=>e.retryCamera(),setMono3D:s=>e.setMono3D(s),leave:()=>e.leave("left"),tile:s=>e.tiles.get(s)?.el||null,diagnostics:()=>e.diagnostics(),on(s,o){if(typeof o!="function")throw new TypeError(`${Z} on() takes a function`);if(s in t&&!e._eventWarned?.has(s)){(e._eventWarned||=new Set).add(s);let a=t[s];console.warn(`${Z} the '${s}' event is deprecated (removed in 1.31)${a?` \u2014 listen for '${a}'`:" \u2014 it is internal now; diagnostics() has the wall"}`)}return e.listeners.has(s)||e.listeners.set(s,new Set),e.listeners.get(s).add(o),()=>e.listeners.get(s)?.delete(o)},off(s,o){e.listeners.get(s)?.delete(o)}},n={wall:["diagnostics().wall (or the wall you passed / sharedInline3D())",()=>e.wall],format:["localFormat",()=>i.localFormat],sendHint:["nothing \u2014 auto-convergence superseded it",()=>s=>e.sendHint(s)],_debug:["diagnostics()",()=>({transport:e.transport,kill:s=>e.transport?._debugKill(s)})]};for(let[s,[o,a]]of Object.entries(n))Object.defineProperty(i,s,{enumerable:!1,configurable:!0,get(){return e._handleWarned?.has(s)||((e._handleWarned||=new Set).add(s),console.warn(`${Z} handle.${s} is deprecated (removed in 1.31) \u2014 use ${o}`)),a()}});return i}};function Na(r){let e=Math.min(globalThis.devicePixelRatio||1,2),t=Math.round((r.clientWidth||0)*e),i=Math.round((r.clientHeight||0)*e);return!t||!i?!1:((r.width!==t||r.height!==i)&&(r.width=t,r.height=i),!0)}function ks(r,e,{eyeHalf:t=null,mirror:i=!1}={}){if(!Na(r))return;let n=r.getContext("2d"),s=e.videoWidth,o=e.videoHeight;if(!s||!o||(e.readyState||0)<2)return;let a=t===null?s:s/2,l=q(a,o,r.width/r.height,0,0);n.save(),i&&(n.translate(r.width,0),n.scale(-1,1)),n.drawImage(e,(t||0)*a+l.sx,l.sy,l.sw,l.sh,0,0,r.width,r.height),n.restore()}var zt=class{constructor(e,t){this.call=e,this.id=t,this.hello=null,this.format=null,this.route=null,this.routedKey=null,this.handle=null,this.conn="connecting",this.remote={muted:!1,cameraOff:!1,speaking:!1},this.level=0,this.speaking=!1,this.quality=null,this.conv=Fe(),this.autoTrack=ft(),this.autoFocus=$e(),this.autoAt=0,this.autoCanvas=null,this.autoLocked=!1,this.autoStats={n:0,ms:0,readMs:0,method:null,via:null},this.autoPending=!1,this.autoGen=0,this.luma=null,this.destroyed=!1,this.conv.depth=e.depth,this.hintGate=vi(fi),this.layerFails=0,this.forceFlat=!1,this.lifted=!1,this.liftHandle=null,this.liftLive=!1,this.liftFailed=!1,this.liftFails=0,this.visible=!0,this.video=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,autoplay:!0}),this.audio=Object.assign(document.createElement("audio"),{autoplay:!0}),this.video.addEventListener("playing",()=>this._maybeRoute()),this.video.addEventListener("loadeddata",()=>this._maybeRoute()),this.video.addEventListener("resize",()=>this._maybeRoute()),this.canvas=A("canvas"),this.cover=A("div",{class:"dxr-call-cover dxr-call-hidden"}),this.badge=A("div",{class:"dxr-call-badge",part:"badge"}),this.plate=A("div",{class:"dxr-call-state",part:"plate",text:e.t("connecting")}),this.stage=A("div",{class:"dxr-call-stage"},[this.canvas,this.cover,this.badge,this.plate]),this.stage.style.aspectRatio=String(e.o.tileAspect),this.el=A("div",{class:"dxr-call-tile",part:"tile","data-dxr-peer":t,"data-peer":t},[this.stage,A("div",{class:"dxr-call-talk"})]),e.o.ui||z(this.badge,!1),e.ui.grid.appendChild(this.el),this._renderBadge(),this.cursor=null,e.o.cursor&&(e._pairCursorMod=e._pairCursorMod||Promise.resolve().then(()=>(Ji(),Ki)),e._pairCursorMod.then(i=>{this.destroyed||(this.cursor=new i.PairCursor(this.canvas,e.o.cursor))}))}display(){return wi(this.route)}info(){return Object.freeze({id:this.id,format:this.format||"mono",display:this.display(),state:this.conn,muted:this.remote.muted,cameraOff:this.remote.cameraOff,speaking:this.speaking})}diag(){return{...this.info(),route:this.route,rectified:!!(this.hello&&this.hello.rectified),hello:this.hello,quality:this.quality,convergencePx:this.conv.current,cursor:this.cursor?this.cursor.last:null,autoConverge:{disparityPx:this.conv.measuredPx,ms:this.autoStats.n?this.autoStats.ms/this.autoStats.n:null,readMs:this.autoStats.n?this.autoStats.readMs/this.autoStats.n:null,method:this.autoStats.method,via:this.autoStats.via},lift:this.lifted?{live:this.liftLive,native:!!(this.liftHandle&&this.liftHandle.native),priority:this.call.liftPool?this.call.liftPool.priority(this.id):null,state:this.liftHandle?this.liftHandle.state||null:"pending"}:null,element:this.el}}setStream(e){this.video.srcObject!==e&&(this.video.srcObject=e,this.audio.srcObject=e,this._resetAutoConverge()),this.video.play().catch(()=>{}),this.audio.play().catch(()=>{})}onChannelOpen(){clearTimeout(this.helloTimer),this.helloTimer=setTimeout(()=>{this.format||(this.format="mono",this._maybeRoute())},Ta)}setHello(e){clearTimeout(this.helloTimer),this.hello=e,this.conv.hello=e;let t=this.format!==e.format;this.format=e.format,this.call.log("hello",{peer:this.id,format:e.format,width:e.width,height:e.height,rectified:e.rectified}),t?this._maybeRoute():this._renderBadge()}setHint(e){this.hintGate(performance.now())&&(this.conv.subjectZmm=e.subjectZmm)}setRemoteState(e){this.remote=e,this._renderBadge(),this._renderPlate(),this._updateVisible()}setSpeaking(e){e!==this.speaking&&(this.speaking=e,this.el.classList.toggle("dxr-call-tile--speaking",e))}setConn(e){e==="unreachable"&&this.conn!=="unreachable"&&this.call.error("unreachable",`${this.call.t("unreachable")}. Still retrying in the background.`,Object.assign(new Error("unreachable"),{peer:this.id})),this.conn=e,e==="connected"&&this.leaveTimer&&(clearTimeout(this.leaveTimer),this.leaveTimer=null),this._renderPlate()}_renderPlate(){let e=this.call.t,t=this.conn==="left"?e("leftCall"):this.conn==="unreachable"?e("unreachable"):this.conn==="reconnecting"?e("reconnecting"):this.conn!=="connected"?e("connecting"):this.remote.cameraOff?e("cameraOffPlate"):null;this.plate.textContent=t||"",z(this.plate,!!t)}_renderBadge(){let e=this.call.t,t=this.route==="woven-sbs"?e("badge3D"):this.route==="lifted"?e("badge2D3D"):e("badge2D"),i=this.route?this.route==="lifted"&&!this.liftLive?`${t}${e("badgePending")}`:t:e("badgePending");this.badge.replaceChildren(A("b",{text:i})),this.badge.dataset.route=this.route||"",this.remote.muted&&this.badge.insertAdjacentHTML("beforeend",J.mutedSmall)}_maybeRoute(){!this.format||(this.video.readyState||0)<2||!this.video.videoWidth||this.reroute(!1)}reroute(e){let t=this.call,i=t.liftPool,n=this.forceFlat&&this.format==="sbs"?{route:"flat-left"}:yi({format:this.format,woven:t.woven,mono3D:t.mono3DOn?"auto":"off",lift:!!i,overBudget:i?!i.canAcquire(this.id):!1,failed:this.liftFailed});this.format!=="sbs"&&t.woven&&t.mono3DOn&&!t._liftP&&t._ensureLift(),this.format!=="sbs"&&t.woven&&t.liftMissing&&t._warnLiftMissing();let s=`${n.route}|${this.format}`;!e&&s===this.routedKey||(this.routedKey=s,this._unregister(),this.route=n.route,n.route==="woven-sbs"?this._registerWoven():n.route==="lifted"&&this._registerLifted(),t.log("route",{peer:this.id,route:n.route,format:this.format,mono3d:n.mono3d||null}),t.emit("display",{id:this.id,display:this.display()}),t.listeners.get("format")?.size&&t.emit("format",{id:this.id,format:this.format,route:n.route,mono3d:n.mono3d||null,hello:this.hello}),this._renderBadge())}_registerWoven(){let e=this.call;this.convCanvas||(this.convCanvas=document.createElement("canvas")),this._paintConv(),z(this.cover,!0);let t=e.wall.addImage(this.canvas,this.convCanvas);this.handle=t,t.firstWoven?.then(i=>{this.handle===t&&(z(this.cover,!1),e.log("first-woven",{peer:this.id,woven:i.woven,reason:i.reason,ms:Math.round(i.ms)}),!i.woven&&i.reason==="layer-failed"&&this._layerFailed())})}_registerLifted(){let e=this.call,t=e.liftPool;this.lifted=!0,this.liftLive=!1,this.video.classList.add("dxr-call-liftsrc"),this.canvas.classList.add("dxr-call-liftflat"),this.video.parentNode!==this.stage&&this.stage.insertBefore(this.video,this.stage.firstChild),this._observeVisible(),t.acquire(this.id,this.video,{wall:e.wall,visible:this.visible,onError:i=>this._liftError(i)}).then(i=>{if(!i||!this.lifted||t.handle(this.id)!==i)return;this.liftHandle=i;let n=s=>{s==="live"?this._liftShowing(!0):(s==="error"||s==="disposed")&&this._liftShowing(!1)};this._liftOff=[i.on?.("statechange",s=>n(s&&s.state)),i.on?.("error",s=>{s&&s.fatal&&this._liftError(s.error)})],i.state==="live"?this._liftShowing(!0):i.canvas&&i.canvas.style&&(i.canvas.style.visibility="hidden"),e.log("lifted",{peer:this.id,native:!!i.native,woven:!!i.woven,state:i.state||null,provider:i.stats&&i.stats.provider||null})})}_liftShowing(e){if(e===this.liftLive)return;this.liftLive=e;let t=this.liftHandle;e?(t&&t.canvas&&t.canvas.style&&!t.native&&(t.canvas.style.visibility=""),this.canvas.style.visibility="hidden",this.liftFails=0,this.call.liftProven||(this.call.liftProven=!0,this.call._refreshLobby())):this.canvas.style.visibility="",this.call.log("lift-live",{peer:this.id,live:e}),this._renderBadge()}_liftError(e){this.lifted&&(this.call.log("lift-error",{peer:this.id,message:String(e&&e.message||e).slice(0,200)}),this.liftFailed=!0,this.reroute(!0),!(this.liftFails++>=Aa)&&(clearTimeout(this.liftTimer),this.liftTimer=setTimeout(()=>{this.liftFailed=!1,this.reroute(!1)},K(this.liftFails-1,{baseMs:3e3,maxMs:3e4}))))}_observeVisible(){this._io||typeof IntersectionObserver!="function"||(this._io=new IntersectionObserver(e=>{let t=e[e.length-1];this._onscreen=!!(t&&t.isIntersecting),this._updateVisible()}),this._io.observe(this.stage))}_updateVisible(){let e=this._onscreen!==!1&&!this.remote.cameraOff;e!==this.visible&&(this.visible=e,this.call.liftPool?.setVisible(this.id,e))}_layerFailed(){if(this.forceFlat=!0,this.reroute(!0),this.layerFails++>=Pa)return;let e=K(this.layerFails-1,{baseMs:1500,maxMs:2e4});this.call.log("layer-retry",{peer:this.id,attempt:this.layerFails,inMs:e}),clearTimeout(this.layerTimer),this.layerTimer=setTimeout(()=>{this.forceFlat=!1,this.call.woven&&this.reroute(!0)},e)}onWallLost(){this.handle=null,this.reroute(!0)}_unregister(){if(z(this.cover,!1),this.lifted){this.lifted=!1;for(let e of this._liftOff||[])typeof e=="function"&&e();this._liftOff=null,this.call.liftPool?.release(this.id),queueMicrotask(()=>this.call.state!=="left"&&this.call._rerouteMono()),this.liftHandle=null,this.liftLive=!1,this.canvas.style.visibility="",this.canvas.classList.remove("dxr-call-liftflat"),this._io&&(this._io.disconnect(),this._io=null),this.video.parentNode&&(this.video.remove(),this.video.classList.remove("dxr-call-liftsrc"),setTimeout(()=>this.video.srcObject&&this.video.play().catch(()=>{}),0))}if(this.handle){try{this.handle.remove()}catch{}this.handle=null}}paint(){this.route&&(this.route!=="woven-sbs"&&this.cursor?.idle(),this.route==="woven-sbs"?this._paintConv():this.route==="lifted"?this.liftLive||ks(this.canvas,this.video):ks(this.canvas,this.video,{eyeHalf:this.route==="flat-left"?0:null}))}_paintConv(){let e=this.video,t=e.videoWidth,i=e.videoHeight;if(!t||!i||(e.readyState||0)<2||!this.convCanvas)return;let n=t/2,s=this.call.o.tileAspect,{w:o,h:a}=Ie(n,i,s),l=this.convCanvas;(l.width!==2*o||l.height!==a)&&(l.width=2*o,l.height=a);let c=!!(this.cursor&&this.cursor.hovering);(this.call.o.autoConverge||c)&&this._sampleDisparity(e,t,i,c);let d=this.conv.step(n),f=l.getContext("2d"),h=[];for(let u of[0,1]){let m=h[u]=q(n,i,s,d,u);f.drawImage(e,u*n+m.sx,m.sy,m.sw,m.sh,u*o,0,o,a)}this.cursor&&this.cursor.draw(f,this.luma,{rL:h[0],rR:h[1],outW:o,outH:a,handle:this.handle},performance.now()/1e3)}_sampleDisparity(e,t,i,n=!1){let s=performance.now();if(this.autoPending||s-this.autoAt<(n?Ia:La))return;if(this.autoAt=s,typeof VideoFrame=="function"){let h=null;try{h=new VideoFrame(e)}catch{h=null}if(h&&Fa.has(h.format)){this.autoPending=!0;let u=this.autoGen,m=h.visibleRect?h.visibleRect.width:h.displayWidth,p=h.visibleRect?h.visibleRect.height:h.displayHeight,b=new Uint8Array(h.allocationSize());h.copyTo(b).then(w=>{if(u!==this.autoGen)return;let g=performance.now(),x=Math.max(1,Math.ceil(m/2/Cs)),_=nn(b,w[0].offset,w[0].stride,m,p,x);this._applyMeasurement(_.img,_.w,_.h,_.w/m,s,performance.now()-g,"videoframe")}).catch(()=>{u===this.autoGen&&this._applyMeasurement(null,0,0,1,s,0,"videoframe")}).finally(()=>{h.close(),this.autoPending=!1});return}h&&h.close()}let o=Math.min(1,Cs/(t/2)),a=Math.max(2,Math.round(t*o/2)*2),l=Math.max(2,Math.round(i*o));this.autoCanvas||(this.autoCanvas=document.createElement("canvas"));let c=this.autoCanvas;(c.width!==a||c.height!==l)&&(c.width=a,c.height=l);let d=c.getContext("2d",{willReadFrequently:!0}),f=null;try{d.drawImage(e,0,0,a,l),f=dt(d.getImageData(0,0,a,l).data,a*l)}catch{f=null}this._applyMeasurement(f,a,l,a/t,s,performance.now()-s,"canvas")}_applyMeasurement(e,t,i,n,s,o,a){if(this.destroyed||(e&&(this.luma={img:e,w:t,h:i,scale:n}),!this.call.o.autoConverge))return;let l=performance.now(),c=e?this.autoFocus.measure(e,t,i,s):null,d=this.autoTrack.push(c?c.d/n:null);this.conv.measuredPx=d,this.autoStats.n++,this.autoStats.readMs+=o,this.autoStats.ms+=o+(performance.now()-l),this.autoStats.method=c?c.method:null,this.autoStats.via=a,c&&!this.autoLocked&&(this.autoLocked=!0,this.call.log("auto-converge",{peer:this.id,disparityPx:Math.round(d*10)/10,at:{x:Math.round(c.x/n),y:Math.round(c.y/n)},ncc:Math.round(c.c*100)/100,method:c.method,via:a,ms:Math.round(o+(performance.now()-l))}))}_resetAutoConverge(){this.autoGen++,this.luma=null,this.autoTrack.reset(),this.autoFocus.reset(),this.conv.measuredPx=null,this.autoLocked=!1}destroy(){this.destroyed=!0,this.autoGen++,this.cursor?.dispose(),this.cursor=null,clearTimeout(this.helloTimer),clearTimeout(this.layerTimer),clearTimeout(this.leaveTimer),clearTimeout(this.liftTimer),this._unregister(),this.video.srcObject=null,this.audio.srcObject=null,this.el.remove()}},pr=class{constructor(e,t){this.call=e,this.canvas=A("canvas"),this.badge=A("div",{class:"dxr-call-badge",part:"badge"}),this.plate=A("div",{class:"dxr-call-state dxr-call-hidden",part:"plate"}),this.stage=A("div",{class:"dxr-call-stage"},[this.canvas,this.badge,this.plate]),this.stage.style.aspectRatio=String(e.o.tileAspect),this.el=A("div",{class:"dxr-call-tile dxr-call-tile--self",part:"tile"},[this.stage,A("div",{class:"dxr-call-talk"})]),t.appendChild(this.el),this.view=null,this.cam=null}get route(){return this.view?this.view.route:null}update(){let e=this.call.local,t=this.call.t,i=!e||!e.videoTrack;this.plate.textContent=i?this.call.camStatus==="busy"?t("cameraBusy"):this.call.camStatus==="pending"?"":t("noCamera"):this.call.camOff?t("cameraOffPlate"):"",z(this.plate,i||this.call.camOff),this.reroute(!1)}reroute(e){let t=this.call.local,i=t&&t.videoTrack?t.cam:null,n=this.call.woven?this.call.wall:{supported:!1};if(!i||i.state!=="live")return this.detach(),this._badge();this.view&&this.cam===i?this.view._reroute(e,n):(this.detach(),this.cam=i,this.view=tr(n,this.canvas,i,{autoConverge:!!this.call.o.autoConverge,cursor:this.call.o.cursor||void 0,aspect:this.call.o.tileAspect,onRouteChange:(s,o)=>{this.cam===i&&(this.call.log("self-route",{route:s,woven:o.woven,reason:o.reason}),this._badge())}})),this._badge()}_badge(){let e=this.call.t,t=!!(this.view&&this.view.woven);this.badge.replaceChildren(A("b",{text:`${e("you")} \xB7 ${e(t?"badge3D":"badge2D")}`})),this.badge.dataset.route=this.route||""}diag(){return this.view?this.view.weaveState():{route:null,woven:!1,reason:"no-camera",firstWoven:null,layerRetries:0}}onWallLost(){this.view?._onWallLost(),this._badge()}detach(){this.view&&this.view.remove(),this.view=null,this.cam=null}setSpeaking(e){this.el.classList.toggle("dxr-call-tile--speaking",e)}},ja="1.31",Ts=new Set;function F(r,e,t){let i=()=>{Ts.has(r)||(Ts.add(r),console.warn(`${Z} \`${r}\` is internal and leaves '@displayxr/inline3d/call' in ${ja} \u2014 import it from ${e} if you must, or stop depending on it`))};return typeof t=="function"?new Proxy(t,{apply(n,s,o){return i(),Reflect.apply(n,s,o)},construct(n,s){return i(),Reflect.construct(n,s)}}):t&&typeof t=="object"?new Proxy(t,{get(n,s,o){return typeof s=="string"&&i(),Reflect.get(n,s,o)}}):t}var vc=F("normalizeCallOptions","js/call/options.js",ar),yc=F("newRoomId","js/call/wire.js",pi),wc=F("isValidRoomId","js/call/wire.js",me),bc=F("buildInviteLink","js/call/wire.js",at),xc=F("normalizeHello","js/call/wire.js",mi),Sc=F("makeHello","js/call/wire.js",gi),Mc=F("routeFor","js/call/wire.js",yi),Ec=F("badgeFor","js/call/wire.js",wi),Rc=F("createLiveGate","js/call/wire.js",bi),Cc=F("convergenceShiftPx","js/camera/converge.js",rt),kc=F("lowPass","js/camera/converge.js",st),Tc=F("clampShift","js/camera/converge.js",nt),Oc=F("eyeCropRect","js/camera/geometry.js",q),Dc=F("mirrorSwapOps","js/camera/geometry.js",fe),Pc=F("mirrorSwapPixels","js/camera/geometry.js",ui),Ac=F("maxBitrateKbps","js/call/wire.js",lt),Lc=F("measureFocusDisparity","js/camera/disparity.js",Mi),Ic=F("preferVideoCodecs","js/call/sdp.js",ze),Fc=F("sortCodecCapabilities","js/call/sdp.js",ct),Nc=F("VIDEO_CODEC_ORDER","js/call/sdp.js",je),jc=F("MeshTransport","js/call/transport.js",We),zc=F("clampMaxPeers","js/call/transport.js",He),Wc=F("qrEncode","js/call/qr.js",nr),Hc=F("roomKey","js/call/signaling.js",sr);var $c=F("PLATE_TEXT","js/call/ui.js (CALL_STRINGS)",Object.freeze({unreachable:Ge.unreachable,cameraBusy:Ge.cameraBusy})),Uc=F("CALL_ACCENTS","js/call/ui.js",or),Vc=F("normalizeMono3D","js/call/lift.js",Ae),Bc=F("resolveLift","js/call/lift.js",Ht),Xc=F("createLiftPool","js/call/lift.js",Vt),qc=F("createFrameWatch","js/call/lift.js",Ut),Gc=F("liftConvergenceFor","js/call/lift.js",Pe),Yc=F("liftPriorityFor","js/call/lift.js",Ye),Kc=F("setLiftPriority","js/call/lift.js",$t),Jc=F("defaultLiftSpecifier","js/call/lift.js",Wt),Zc=F("LIFT_PRIORITY","js/call/lift.js",De);jt();gr(()=>new URL("./lift.js",import.meta.url).href);export{cr as CALL_EVENT_PREFIX,cs as CAMERA_SDK,Nt as DXR_SIGNAL_DEFAULT,ke as DxrCallElement,Os as addCall,tr as addCameraView,hr as attrsToOpts,Ur as createInline3D,jt as defineCallElement,Re as dxrSignaling,Hr as inline3DAvailable,Ft as isStereoCamera,ur as mountCall,er as openCamera,Ne as parseInviteLink,ki as parseStereoXmp,pn as readJpegStereoMeta,Ti as readJpegXmp,bn as readWebmStereoMeta,it as sharedInline3D,It as suggestedName};
|