lecodes-cli 2.4.1 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +18914 -1829
- package/package.json +10 -9
- package/runtime/sdk-types.json +1 -1
- package/runtime/web/VERSION.json +3 -3
- package/runtime/web/assets/ar-D6oDL4pw.js +1 -0
- package/runtime/web/assets/ar-mVXX3kRQ.js +2 -0
- package/runtime/web/assets/qrAnchorWorker-Cb5E8cF-.js +1 -0
- package/runtime/web/assets/qr_anchor_wasm_bg-D_ePkCCu.wasm +0 -0
- package/runtime/web/index.html +1 -0
- package/runtime/web/player.js +12 -12
- package/runtime/web-lite/assets/{index-B2zEJlWS.js → index-oPsDD47E.js} +1 -1
- package/runtime/web-lite/assets/scene3d-BAl_QQyi.js +1105 -0
- package/runtime/web-lite/features.json +2 -2
- package/runtime/web-lite/index.html +2 -1
- package/runtime/web-lite/lite.js +9 -9
- package/runtime/web-lite/plugins/ar/_virtual_lecodes-half-resources-CNYmVR88.js +1 -0
- package/runtime/web-lite/plugins/ar/assets/qrAnchorWorker-DcxVKAqo.js +1 -0
- package/runtime/web-lite/plugins/ar/assets/qr_anchor_wasm_bg-D_ePkCCu.wasm +0 -0
- package/runtime/web-lite/plugins/ar/index-C2uuuLhz.js +2 -0
- package/runtime/web-lite/plugins.json +1 -1
- package/src/commands/app/index.ts +26 -9
- package/src/commands/app/shared.ts +72 -22
- package/src/commands/plugin.ts +3 -3
- package/src/commands/push.ts +2 -2
- package/src/commands/web.ts +12 -5
- package/src/compile/collect.ts +2 -3
- package/src/compile/collectLocal.ts +13 -2
- package/src/compile/designCompile.ts +2 -3
- package/src/compile/projectCompile.ts +3 -0
- package/src/dev/devServer.ts +63 -7
- package/src/dev/https.ts +50 -0
- package/src/dev/serve.ts +15 -9
- package/src/dev/webRunner.ts +11 -3
- package/src/platform/serverDiff.ts +2 -3
- package/src/plugin/emitWeb.ts +17 -8
- package/src/plugin/firstParty.ts +30 -0
- package/src/plugin/generate.ts +41 -21
- package/src/plugin/manifest.ts +33 -3
- package/src/project/localFiles.ts +44 -7
- package/src/web/build.ts +33 -9
- package/src/web/halves.ts +76 -0
- package/runtime/web/assets/ar-CHvaraG4.js +0 -1
- package/runtime/web-lite/assets/scene3d-Bew8g7Ws.js +0 -1081
- package/runtime/web-lite/plugins/ar/index-CHvaraG4.js +0 -1
package/runtime/web/VERSION.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const r=""+new URL("qrAnchorWorker-Cb5E8cF-.js",import.meta.url).href,o={qrAnchorWorker:r};export{o as resources};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var et=Object.defineProperty;var tt=(e,t,n)=>t in e?et(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var fe=(e,t,n)=>tt(e,typeof t!="symbol"?t+"":t,n);const nt=(e,t)=>{const n=t.data instanceof Uint8Array?t.data.slice().buffer:t.data;return{systemId:e.putBuffer(n),name:t.name,size:n.byteLength}},S={present:e=>e!=null,f64:e=>typeof e=="number"&&Number.isFinite(e)?e:void 0,i32:e=>typeof e=="number"&&Number.isInteger(e)&&e>=-2147483648&&e<=2147483647?e:void 0,bool:e=>typeof e=="boolean"?e:void 0,string:e=>typeof e=="string"?e:void 0,json:e=>e,bytes:e=>Object.prototype.toString.call(e)==="[object Uint8Array]"?e.slice():void 0,object:e=>typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0,array:(e,t)=>Array.isArray(e)&&(t===void 0||e.length===t)?e:void 0,list:(e,t)=>{if(!Array.isArray(e))return;const n=[];for(const r of e){const s=t(r);if(s===void 0)return;n.push(s)}return n},map:(e,t)=>{if(typeof e!="object"||e===null||Array.isArray(e))return;const n={};for(const[r,s]of Object.entries(e)){const i=t(s);if(i===void 0)return;n[r]=i}return n}};let xe;const rt=e=>{const t=S.object(e),n=t?S.i32(t.systemId):void 0,r=n===void 0||xe==null?void 0:xe(n);return t&&r?{data:r,name:S.string(t.name)??""}:void 0},he=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0&&e<=4294967295?e:void 0,ot=e=>{const t=S.object(e);if(!t)return;let n;if(S.present(t.scene)){const i=he(t.scene);if(i===void 0)return;n=i}let r;if(S.present(t.camera)){const i=he(t.camera);if(i===void 0)return;r=i}const s={};return n!==void 0&&(s.scene=n),r!==void 0&&(s.camera=r),s},st=e=>e==="world"||e==="images"?e:void 0,it=e=>e==="horizontal"||e==="vertical"||e==="both"||e==="none"?e:void 0,Ke=e=>{const t=S.object(e);if(!t)return;const n=rt(t.image);if(n===void 0)return;const r=S.f64(t.physicalWidth);if(r===void 0)return;const s=he(t.entity);return s===void 0?void 0:{image:n,physicalWidth:r,entity:s}},Qe=e=>{const t=S.object(e);if(!t)return;const n=S.string(t.text);if(n===void 0)return;const r=S.f64(t.size);if(r===void 0)return;const s=he(t.entity);return s===void 0?void 0:{text:n,size:r,entity:s}},at=e=>e==="gravity"||e==="gravityAndHeading"?e:void 0,ct=e=>{const t=S.object(e);if(!t)return;let n;if(S.present(t.mode)){const h=st(t.mode);if(h===void 0)return;n=h}let r;if(S.present(t.planes)){const h=it(t.planes);if(h===void 0)return;r=h}let s;if(S.present(t.images)){const h=S.list(t.images,p=>Ke(p));if(h===void 0)return;s=h}let i;if(S.present(t.codes)){const h=S.list(t.codes,p=>Qe(p));if(h===void 0)return;i=h}let u;if(S.present(t.worldAlignment)){const h=at(t.worldAlignment);if(h===void 0)return;u=h}let w;if(S.present(t.lightEstimation)){const h=S.bool(t.lightEstimation);if(h===void 0)return;w=h}let l;if(S.present(t.autoFocus)){const h=S.bool(t.autoFocus);if(h===void 0)return;l=h}const f={};return n!==void 0&&(f.mode=n),r!==void 0&&(f.planes=r),s!==void 0&&(f.images=s),i!==void 0&&(f.codes=i),u!==void 0&&(f.worldAlignment=u),w!==void 0&&(f.lightEstimation=w),l!==void 0&&(f.autoFocus=l),f},lt=e=>e==="planes"||e==="estimated"||e==="any"?e:void 0,dt=e=>{const t=S.object(e);if(!t)return;const n=S.f64(t.x);if(n===void 0)return;const r=S.f64(t.y);if(r===void 0)return;const s=S.f64(t.z);return s===void 0?void 0:{x:n,y:r,z:s}},ft=e=>{const t=S.object(e);if(!t)return;const n=S.f64(t.x);if(n===void 0)return;const r=S.f64(t.y);if(r===void 0)return;const s=S.f64(t.z);if(s===void 0)return;const i=S.f64(t.w);return i===void 0?void 0:{x:n,y:r,z:s,w:i}},ut=e=>{const t=S.object(e);if(!t)return;const n=dt(t.position);if(n===void 0)return;const r=ft(t.rotation);return r===void 0?void 0:{position:n,rotation:r}};class z extends Error{constructor(t){super(t),this.code=t}}const Ie={name:"ar",version:2},ht=(e,t)=>{xe=n=>e.getBuffer(n),e.registerService(Ie.name,(n,r)=>{const s={tracking:w=>r.emit("tracking",w),plane:w=>r.emit("plane",w),image:w=>r.emit("image",w),anchor:w=>r.emit("anchor",w),light:w=>r.emit("light",w),error:w=>r.emit("error",w),ended:w=>r.emit("ended",w)},i=t(ot(n)??{},s);return{call:async(w,l)=>{switch(w){case"start":{let f;if(S.present(l[0])){const h=ct(l[0]);if(h===void 0)throw new Error("bad arguments — AR.start: options");f=h}await i.start(f);return}case"stop":{await i.stop();return}case"setImages":{const f=S.list(l[0],h=>Ke(h));if(f===void 0)throw new Error("bad arguments — AR.setImages: images");await i.setImages(f);return}case"setCodes":{const f=S.list(l[0],h=>Qe(h));if(f===void 0)throw new Error("bad arguments — AR.setCodes: codes");await i.setCodes(f);return}case"hitTest":{const f=S.f64(l[0]);if(f===void 0)throw new Error("bad arguments — AR.hitTest: x");const h=S.f64(l[1]);if(h===void 0)throw new Error("bad arguments — AR.hitTest: y");let p;if(S.present(l[2])){const E=lt(l[2]);if(E===void 0)throw new Error("bad arguments — AR.hitTest: target");p=E}return await i.hitTest(f,h,p)}case"anchor":{const f=he(l[0]);if(f===void 0)throw new Error("bad arguments — AR.anchor: entity");const h=ut(l[1]);if(h===void 0)throw new Error("bad arguments — AR.anchor: pose");await i.anchor(f,h);return}case"release":{const f=he(l[0]);if(f===void 0)throw new Error("bad arguments — AR.release: entity");await i.release(f);return}case"captureFrame":{const f=await i.captureFrame();return nt(e,f)}default:throw new Error(`Unknown method: ${w}`)}},close:()=>{var w;return(w=i.close)==null?void 0:w.call(i)}}},Ie.version)},ce=Math.PI/180,ge=(e,t)=>[e[3]*t[0]+e[0]*t[3]+e[1]*t[2]-e[2]*t[1],e[3]*t[1]-e[0]*t[2]+e[1]*t[3]+e[2]*t[0],e[3]*t[2]+e[0]*t[1]-e[1]*t[0]+e[2]*t[3],e[3]*t[3]-e[0]*t[0]-e[1]*t[1]-e[2]*t[2]],Me=e=>{const t=Math.hypot(e[0],e[1],e[2],e[3])||1;return[e[0]/t,e[1]/t,e[2]/t,e[3]/t]},ue=(e,t)=>{const n=Math.sin(t/2);return[e[0]*n,e[1]*n,e[2]*n,Math.cos(t/2)]},Le=(e,t)=>{const[n,r,s,i]=e,u=2*(r*t[2]-s*t[1]),w=2*(s*t[0]-n*t[2]),l=2*(n*t[1]-r*t[0]);return[t[0]+i*u+(r*l-s*w),t[1]+i*w+(s*u-n*l),t[2]+i*l+(n*w-r*u)]},_e=(e,t,n)=>ge(ge(ue([0,0,1],e*ce),ue([1,0,0],t*ce)),ue([0,1,0],n*ce)),Ye=e=>{const[t,n,r,s]=e;return[2*(t*r-s*n),2*(s*t+n*r),s*s-t*t-n*n+r*r]},mt=(e,t)=>{const n=e[0]*t[0]+e[1]*t[1]+e[2]*t[2];if(n<-.999999)return[1,0,0,0];const r=[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]];return Me([r[0],r[1],r[2],1+n])};class Pe{constructor(t=1,n=.05){fe(this,"q",[0,0,0,1]);fe(this,"seeded",!1);fe(this,"ix",0);fe(this,"iy",0);fe(this,"iz",0);this.kp=t,this.ki=n}get ready(){return this.seeded}seed(t){this.q=Me(t),this.seeded=!0}update(t,n,r){const s=Math.hypot(n[0],n[1],n[2]);if(!this.seeded){if(s===0)return;this.seed(mt([n[0]/s,n[1]/s,n[2]/s],[0,0,1]));return}let i=t[0],u=t[1],w=t[2];if(s>0){const x=n[0]/s,M=n[1]/s,$=n[2]/s,R=Ye(this.q),P=M*R[2]-$*R[1],j=$*R[0]-x*R[2],N=x*R[1]-M*R[0];this.ki>0&&(this.ix+=this.ki*P*r,this.iy+=this.ki*j*r,this.iz+=this.ki*N*r,i+=this.ix,u+=this.iy,w+=this.iz),i+=this.kp*P,u+=this.kp*j,w+=this.kp*N}const l=.5*r*i,f=.5*r*u,h=.5*r*w,[p,E,y,A]=this.q;this.q=Me([p+A*l+E*h-y*f,E+A*f-p*h+y*l,y+A*h+p*f-E*l,A-p*l-E*f-y*h])}}const wt=ue([1,0,0],-Math.PI/2),gt=(e,t)=>ge(ge(wt,e),ue([0,0,1],-t*ce)),yt=e=>{let[t,,n]=Le(e,[0,0,-1]);return Math.hypot(t,n)<.3&&([t,,n]=Le(e,[0,1,0])),ue([0,1,0],-Math.atan2(-t,-n))},pt=e=>{const[t,n,r,s]=e;return[1-2*(n*n+r*r),2*(t*n+s*r),2*(t*r-s*n),0,2*(t*n-s*r),1-2*(t*t+r*r),2*(n*r+s*t),0,2*(t*r+s*n),2*(n*r-s*t),1-2*(t*t+n*n),0,0,0,0,1]},xt=(e,t,n,r,s)=>{const i=Math.max(e,t)/2/Math.tan(s*ce/2),u=Math.max(n/e,r/t);return 2*Math.atan(r/u/2/i)/ce},vt=(e,t,n,r)=>{const s=1/Math.tan(e*ce/2);return[s/t,0,0,0,0,s,0,0,0,0,(r+n)/(n-r),-1,0,0,2*r*n/(n-r),0]},kt=(e,t,n,r)=>{const s=Math.max(n/e,r/t),i=n/(e*s),u=r/(t*s);return[i,0,(1-i)/2,0,u,(1-u)/2]},Et=68,Oe=.01,Te=1e3,ke=Math.PI/180,je=30,bt=(e,t,n)=>{const r=t.scene;let s=0,i=!1,u=!1,w=null,l=null,f=null,h="",p=new Pe,E=!1,y=null,A=null,x=0,M=0,$=0,R=null,P=null;const j=k=>{k.alpha===null||k.beta===null||k.gamma===null||k.alpha===0&&k.beta===0&&k.gamma===0||(A=[k.beta,k.gamma],y=_e(k.alpha,k.beta,k.gamma))},N=k=>{const I=k.rotationRate,F=k.accelerationIncludingGravity;if(!I||!F||I.alpha===null||I.beta===null||I.gamma===null||F.x===null||F.y===null||F.z===null)return;const L=k.timeStamp;if(M||(M=L),$===0)if(A){const K=Ye(_e(0,A[0],A[1])),te=Math.hypot(F.x,F.y,F.z)||1;$=(K[0]*F.x+K[1]*F.y+K[2]*F.z)/te<0?-1:1}else if(L-M>500)$=1;else return;const G=x?Math.min(.1,Math.max(0,(L-x)/1e3)):0;x=L,E||(E=!0,y&&p.seed(y)),p.update([I.beta*ke,I.gamma*ke,I.alpha*ke],[F.x*$,F.y*$,F.z*$],G)},V=()=>{if(!l||r===void 0)return;const k=e.viewport(r),{width:I,height:F}=k,L=`${l.videoWidth}x${l.videoHeight}:${I}x${F}`;if(L!==h&&l.videoWidth>0&&I>0&&F>0){h=L;const te=xt(l.videoWidth,l.videoHeight,I,F,Et);e.setProjection(r,vt(te,I/F,Oe,Te),Oe,Te),e.setBackground(r,l,kt(l.videoWidth,l.videoHeight,I,F))}const G=E?p.ready?p.q:null:y;if(!G)return;const K=gt(G,k.rotation);R??(R=yt(K)),e.setCameraMatrix(r,pt(ge(R,K)))},H=async()=>{const k=[window.DeviceMotionEvent,window.DeviceOrientationEvent];if(!k[1])return!1;let I=!0;for(const F of k)if(typeof(F==null?void 0:F.requestPermission)=="function")try{I=await F.requestPermission()==="granted"&&I}catch{I=!1}return I},Y=()=>{P&&window.removeEventListener("pointerup",P,!0),P=null},X=()=>{P||(P=()=>{Y(),H().then(k=>{k||console.warn("[ar] the page was not given the device's sensors: the camera of the scene stays as the app turned it")})},window.addEventListener("pointerup",P,!0))},J=()=>{s++,i=!1,u=!1,f==null||f(),f=null;for(const k of(w==null?void 0:w.getTracks())??[])k.stop();w=null,l&&(l.srcObject=null,r!==void 0&&(e.setBackground(r,null),e.clearProjection(r)),l.remove()),l=null,h="",Y(),window.removeEventListener("deviceorientation",j),window.removeEventListener("devicemotion",N),p=new Pe,E=!1,y=null,A=null,x=0,M=0,$=0,R=null};return{async start(k){var K,te;if(i||u)throw new z("busy");if(r===void 0||t.camera===void 0)throw console.warn("[ar] start: the session has no scene or camera to drive (ARScene opens it with both)"),new z("failed");((k==null?void 0:k.mode)==="images"||(K=k==null?void 0:k.images)!=null&&K.length)&&console.warn("[ar] the web finds no images in the camera's picture: their anchors are never tracked"),(te=k==null?void 0:k.codes)!=null&&te.length&&console.warn("[ar] the web finds no codes in the camera's picture yet: their anchors are never tracked"),u=!0;const I=++s,F=H();let L;try{L=await navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:{ideal:"environment"},width:{ideal:1280},height:{ideal:720}}})}catch(Z){I===s&&(u=!1);const m=Z instanceof DOMException?Z.name:"";throw console.warn(`[ar] no camera: ${Z instanceof Error?Z.message:Z}`),new z(m==="NotAllowedError"||m==="SecurityError"?"denied":m==="NotFoundError"||m==="OverconstrainedError"?"unavailable":"failed")}if(I!==s){for(const Z of L.getTracks())Z.stop();throw new z("failed")}w=L;const G=document.createElement("video");if(G.muted=!0,G.playsInline=!0,G.autoplay=!0,G.srcObject=L,l=G,await new Promise(Z=>{if(G.readyState>=2)return Z();G.addEventListener("loadeddata",()=>Z(),{once:!0})}),await G.play().catch(()=>{}),I!==s)throw new z("failed");window.addEventListener("deviceorientation",j),window.addEventListener("devicemotion",N),f=e.onFrame(V),V(),u=!1,i=!0,n.tracking({state:"normal"}),F.then(Z=>{!Z&&I===s&&X()})},stop(){J()},setImages(k){if(!i)throw new z("notRunning");k.length&&console.warn("[ar] the web finds no images in the camera's picture: their anchors are never tracked")},setCodes(k){if(!i)throw new z("notRunning");k.length&&console.warn("[ar] the web finds no codes in the camera's picture yet: their anchors are never tracked")},hitTest(){if(!i)throw new z("notRunning");return[]},anchor(){if(!i)throw new z("notRunning")},release(){},async captureFrame(){const k=l;if(!i||!k)throw new z("notRunning");const I=s;for(let K=0;k.readyState<2||k.videoWidth===0;K++){if(K>=je)throw console.warn(`[ar] captureFrame: the camera gave no picture in ${je} frames`),new z("failed");if(await new Promise(te=>requestAnimationFrame(te)),I!==s)throw new z("notRunning")}const F=document.createElement("canvas");F.width=k.videoWidth,F.height=k.videoHeight;const L=F.getContext("2d");if(!L)throw new z("failed");L.drawImage(k,0,0);const G=await new Promise(K=>F.toBlob(K,"image/jpeg",.9));if(!G)throw new z("failed");return{data:await G.arrayBuffer(),name:"frame.jpg"}},close(){J()}}},At=180/Math.PI,Re=({position:e,rotation:t})=>{const{x:n,y:r,z:s,w:i}=t;return[1-2*(r*r+s*s),2*(n*r+i*s),2*(n*s-i*r),0,2*(n*r-i*s),1-2*(n*n+s*s),2*(r*s+i*n),0,2*(n*s+i*r),2*(r*s-i*n),1-2*(n*n+r*r),0,e.x,e.y,e.z,1]},ze=e=>{const[t,n,r,s,i,u,w,l,f,h,p,E,y,A,x,M]=Array.from(e),$=t*u-n*i,R=t*w-r*i,P=t*l-s*i,j=n*w-r*u,N=n*l-s*u,V=r*l-s*w,H=f*A-h*y,Y=f*x-p*y,X=f*M-E*y,J=h*x-p*A,k=h*M-E*A,I=p*M-E*x,F=$*I-R*k+P*J+j*X-N*Y+V*H;if(!F)return null;const L=1/F;return[(u*I-w*k+l*J)*L,(r*k-n*I-s*J)*L,(A*V-x*N+M*j)*L,(p*N-h*V-E*j)*L,(w*X-i*I-l*Y)*L,(t*I-r*X+s*Y)*L,(x*P-y*V-M*R)*L,(f*V-p*P+E*R)*L,(i*k-u*X+l*H)*L,(n*X-t*k-s*H)*L,(y*N-A*P+M*$)*L,(h*P-f*N-E*$)*L,(u*Y-i*J-w*H)*L,(t*J-n*Y+r*H)*L,(A*R-y*j-x*$)*L,(f*j-h*R+p*$)*L]},Mt=(e,t)=>{const n=new Array(16);for(let r=0;r<4;r++)for(let s=0;s<4;s++)n[r*4+s]=e[s]*t[r*4]+e[4+s]*t[r*4+1]+e[8+s]*t[r*4+2]+e[12+s]*t[r*4+3];return n},Rt=e=>{const t=e[0],n=e[1],r=e[2],s=e[4],i=e[5],u=e[6],w=e[8],l=e[9],f=e[10],h=t+i+f;let p,E,y,A;if(h>0){const M=Math.sqrt(h+1)*2;A=M/4,p=(u-l)/M,E=(w-r)/M,y=(n-s)/M}else if(t>i&&t>f){const M=Math.sqrt(1+t-i-f)*2;A=(u-l)/M,p=M/4,E=(s+n)/M,y=(w+r)/M}else if(i>f){const M=Math.sqrt(1+i-t-f)*2;A=(w-r)/M,p=(s+n)/M,E=M/4,y=(l+u)/M}else{const M=Math.sqrt(1+f-t-i)*2;A=(n-s)/M,p=(w+r)/M,E=(l+u)/M,y=M/4}const x=Math.hypot(p,E,y,A)||1;return{x:p/x,y:E/x,z:y/x,w:A/x}},zt=e=>({position:{x:e[12],y:e[13],z:e[14]},rotation:Rt(e)}),qe=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y,e.z-t.z),De=(e,t)=>{const n=Math.min(1,Math.abs(e.x*t.x+e.y*t.y+e.z*t.z+e.w*t.w));return 2*Math.acos(n)*At},$t=(e,t,n)=>{let r=e.x*t.x+e.y*t.y+e.z*t.z+e.w*t.w;const s=r<0?-1:1;r*=s;let i,u;if(r>.9995)i=1-n,u=n*s;else{const E=Math.acos(r),y=Math.sin(E);i=Math.sin((1-n)*E)/y,u=Math.sin(n*E)/y*s}const w=i*e.x+u*t.x,l=i*e.y+u*t.y,f=i*e.z+u*t.z,h=i*e.w+u*t.w,p=Math.hypot(w,l,f,h)||1;return{x:w/p,y:l/p,z:f/p,w:h/p}},Ft=(e,t,n)=>({position:{x:e.position.x+(t.position.x-e.position.x)*n,y:e.position.y+(t.position.y-e.position.y)*n,z:e.position.z+(t.position.z-e.position.z)*n},rotation:$t(e.rotation,t.rotation,n)}),St=(e,t,n,r,s)=>{const i=n,u=t,w=i[0]*e.x+i[4]*e.y+i[8]*e.z+i[12],l=i[1]*e.x+i[5]*e.y+i[9]*e.z+i[13],f=i[2]*e.x+i[6]*e.y+i[10]*e.z+i[14],h=i[3]*e.x+i[7]*e.y+i[11]*e.z+i[15],p=u[0]*w+u[4]*l+u[8]*f+u[12]*h,E=u[1]*w+u[5]*l+u[9]*f+u[13]*h,y=u[3]*w+u[7]*l+u[11]*f+u[15]*h;return y>0?[(p/y+1)*r/2,(1-E/y)*s/2]:null},It=(e,t,n)=>{const r=n,s=t,i=r[0]*e.x+r[4]*e.y+r[8]*e.z+r[12],u=r[1]*e.x+r[5]*e.y+r[9]*e.z+r[13],w=r[2]*e.x+r[6]*e.y+r[10]*e.z+r[14],l=r[3]*e.x+r[7]*e.y+r[11]*e.z+r[15],f=s[0]*i+s[4]*u+s[8]*w+s[12]*l,h=s[1]*i+s[5]*u+s[9]*w+s[13]*l,p=s[3]*i+s[7]*u+s[11]*w+s[15]*l;return p>0&&Math.abs(f)<=p&&Math.abs(h)<=p},Se={window:24,minObservations:6,minBaseline:.04,minSpread:.01,min:.8,max:1.25,maxResidual:.008,step:.25},Lt=(e,t)=>({p:{x:e[12],y:e[13],z:e[14]},u:{x:e[0]*t.x+e[4]*t.y+e[8]*t.z,y:e[1]*t.x+e[5]*t.y+e[9]*t.z,z:e[2]*t.x+e[6]*t.y+e[10]*t.z}}),_t=(e,t=Se)=>{const n=e.length;if(n<Math.max(2,t.minObservations))return null;let r=0;for(let $=0;$<n;$++)for(let R=$+1;R<n;R++){const P=e[$].p,j=e[R].p;r=Math.max(r,Math.hypot(P.x-j.x,P.y-j.y,P.z-j.z))}if(!(r>=t.minBaseline))return null;let s=0,i=0,u=0,w=0,l=0,f=0;for(const{p:$,u:R}of e)s+=$.x,i+=$.y,u+=$.z,w+=R.x,l+=R.y,f+=R.z;s/=n,i/=n,u/=n,w/=n,l/=n,f/=n;let h=0,p=0;for(const{p:$,u:R}of e){const P=R.x-w,j=R.y-l,N=R.z-f;h+=P*($.x-s)+j*($.y-i)+N*($.z-u),p+=P*P+j*j+N*N}const E=Math.sqrt(p/n);if(!(E>=t.minSpread))return null;const y=-h/p,A=Math.min(t.max,Math.max(t.min,y)),x={x:s+A*w,y:i+A*l,z:u+A*f};let M=0;for(const{p:$,u:R}of e){const P=A*R.x+$.x-x.x,j=A*R.y+$.y-x.y,N=A*R.z+$.z-x.z;M+=P*P+j*j+N*N}return{scale:A,unclamped:y,point:x,residual:Math.sqrt(M/n),baseline:r,spread:E,n}},Pt=(e=Se)=>{const t=[];let n=1,r=null;return{get scale(){return n},get estimate(){return r},add(s){t.push(s),t.length>e.window&&t.splice(0,t.length-e.window);const i=_t(t,e);return!i||!(i.residual<=e.maxResidual)?{fit:i,taken:!1}:(n+=(r===null?1:e.step)*(i.scale-n),r=i.scale,{fit:i,taken:!0})},reset(){t.length=0,n=1,r=null}}},ve={min_init_side_px:40,min_reacquire_side_px:20,max_rms_px:.6},Ot={seeking:{...ve,search_first:!1},holding:{...ve,search_first:!0,full_detect_interval:1e6}},Ce=480,Ee=960,be=6,We=16,Tt=24,jt=2,qt=15,Dt=5,Ct=.02,Wt=2,Nt=.01,Ht=1,Ut=.03,Gt=5,$e=.8,Ne=10,He=30,Bt=.5,Vt=500,Ae=2e3,Xt=5e3,Kt=.005,pe=28,Qt=(e,t,n=ve.max_rms_px)=>e.rms<=n?e.metres>Ut||e.degrees>Gt?e.inliers!==void 0&&(e.inliers<Tt||e.side<$e*t)?"kept":"move":e.metres<=Nt&&e.degrees<=Ht?"near":e.side>=$e*t?"replace":"kept":"bad",Ue=e=>({position:{x:e.position.x,y:e.position.y,z:e.position.z},rotation:{x:e.orientation.x,y:e.orientation.y,z:e.orientation.z,w:e.orientation.w}});let Fe=!1;const ae=e=>{if(!Fe)try{e==null||e.delete()}catch{}},Ge=e=>e instanceof Error?e.message:String(e),Yt=e=>{const t=new URL(e,location.href);if(t.origin===location.origin)return{worker:new Worker(t,{type:"module"}),blob:null};const n=URL.createObjectURL(new Blob([`import ${JSON.stringify(t.href)}
|
|
2
|
+
`],{type:"text/javascript"}));try{return{worker:new Worker(n,{type:"module"}),blob:n}}catch(r){throw URL.revokeObjectURL(n),r}},Zt=e=>{let t=[],n=0,r=null,s=null,i=!1,u=!1,w=!1,l=null,f=0,h=!1,p=0,E=0,y=null;const A=new Set,x={phase:"seeking",since:0,captures:0,found:0,workerMs:0,captureFrames:0,resultFrames:0},M=o=>{x.since=o,x.captures=x.found=x.workerMs=x.captureFrames=x.resultFrames=0},$=o=>[o.target.size,o.target.size],R=(o,c,a)=>{o.tracked!==c&&(o.tracked=c,console.log(`[ar] qr ${o.target.text}: ${a}`),e.image({entity:o.target.entity,tracked:c,extent:$(o)}))},P=()=>t.map(o=>({text:o.target.text,size:o.target.size})),j=(o,c=[])=>r==null?void 0:r.postMessage(o,c),N=()=>{s&&URL.revokeObjectURL(s),s=null},V=()=>{r==null||r.terminate(),r=null,N(),i=u=h=!1,l=null},H=o=>{w||(w=!0,V(),console.warn(`[ar] the QR detector failed (${o}): QR codes are not tracked`))},Y=()=>{if(r||u||w||t.length===0)return;if(typeof Worker>"u"){H("this browser has no workers");return}u=!0;const o=n;e.workerUrl().then(c=>{if(o!==n)return;if(u=!1,!c)throw new Error("the half was built without its worker (the manifest's qrAnchorWorker)");const a=Yt(c),d=a.worker;r=d,s=a.blob,d.onmessage=g=>{r===d&&te(g.data)},d.onerror=g=>{g.preventDefault(),r===d&&H(g.message||"its module did not load")},j({type:"init",config:Ot,targets:P()})}).catch(c=>{o===n&&H(Ge(c))})},X=o=>({target:o,anchor:null,anchorPose:null,anchorTracked:!1,asked:null,next:null,nextFrames:0,shown:null,tracked:!1,slew:null,corners:null,cornersIn:[0,0],side:0,misses:0,bestSide:0,loggedAt:-1/0,keptLoggedAt:-1/0,depth:Pt(),depthLogged:null,depthRefusedAt:-1/0}),J=(o,c)=>{ae(o.anchor),ae(o.next),o.anchor=o.next=null,o.asked=null,o.depth.reset(),o.depthLogged=null,c&&R(o,!1,"no longer a target")},k=(o,c,a,d)=>{const{fit:g,taken:v}=o.depth.add(Lt(c,a));if(!g)return;const _=g.scale!==g.unclamped?`, clamped from ${g.unclamped.toFixed(3)}`:"",q=`baseline ${(g.baseline*100).toFixed(1)} cm, residual ${(g.residual*1e3).toFixed(1)} mm, ${g.n} obs${_}`;if(v){if(o.depthLogged!==null&&Math.abs(g.scale-o.depthLogged)<=Kt*o.depthLogged)return;o.depthLogged=g.scale,console.log(`[ar] qr ${o.target.text}: depth scale ${o.depth.scale.toFixed(3)} (estimate ${g.scale.toFixed(3)}, ${q})`)}else d-o.depthRefusedAt>=Ae&&(o.depthRefusedAt=d,console.log(`[ar] qr ${o.target.text}: depth scale estimate ${g.scale.toFixed(3)} refused (${q}; the residual over ${(Se.maxResidual*1e3).toFixed(0)} mm), the scale stays ${o.depth.scale.toFixed(3)}`))},I=o=>o.asked||o.next?"waiting":o.anchor&&o.anchorTracked?"holding":"seeking",F=(o,c)=>{const a=n,d={pose:c,wanted:()=>a===n&&o.asked===d&&t.includes(o),settle:g=>{if(o.asked!==d){ae(g);return}o.asked=null,g&&(ae(o.next),o.next=g,o.nextFrames=0)}};o.asked=d,e.anchor(d)},L=(o,c,a)=>{try{if(o.trackedAnchors&&!o.trackedAnchors.has(a))return null;const d=o.getPose(a.anchorSpace,c);return d?Ue(d.transform):null}catch{return null}},G=(o,c)=>{for(const a of t){if(a.next)if(L(o,c,a.next)){const v=a.anchor;a.anchor=a.next,a.next=null,a.anchorTracked=!1,ae(v),a.slew=a.shown?{from:a.shown,frame:0}:null}else++a.nextFrames>He&&(console.warn(`[ar] qr ${a.target.text}: the new anchor was not tracked in ${He} frames: given up`),ae(a.next),a.next=null);if(!a.anchor)continue;const d=L(o,c,a.anchor);if(!d){a.anchorTracked&&(a.anchorTracked=!1,R(a,!1,"lost (its anchor is not tracked)"));continue}a.anchorTracked=!0,a.anchorPose=d;let g=d;a.slew&&(a.slew.frame++,g=Ft(a.slew.from,d,Math.min(1,a.slew.frame/Ne)),a.slew.frame>=Ne&&(a.slew=null)),a.shown=g,e.setMatrix(a.target.entity,Re(g)),R(a,!0,"regained (its anchor is tracked again)")}},K=(o,c,a,d,g)=>{const{picture:v}=a,_=c[1],q=c[2],U=c[3],B=c.subarray(4,20),ee=performance.now();if(o.misses=0,U<We){ee-o.keptLoggedAt>=Ae&&(o.keptLoggedAt=ee,console.log(`[ar] qr ${o.target.text}: ignored (${U} points < ${We}; side ${_.toFixed(0)} px of ${v.width}, rms ${q.toFixed(2)} px)`));return}q<=ve.max_rms_px&&k(o,v.viewMatrix,{x:B[12],y:B[13],z:B[14]},ee);const O=o.depth.scale,C=Array.from(B);C[12]=B[12]*O,C[13]=B[13]*O,C[14]=B[14]*O;const D=Mt(v.viewMatrix,C),T=zt(D);o.corners=Array.from(c.subarray(20,28)),o.cornersIn=[v.width,v.height],o.side=_;const W=_*Ee/v.width;ee-o.loggedAt>=Vt&&(o.loggedAt=ee,console.log(`[ar] qr ${o.target.text}: side ${_.toFixed(0)} px of ${v.width}, rms ${q.toFixed(2)} px, inliers ${U}, t=(${B[12].toFixed(3)} ${B[13].toFixed(3)} ${B[14].toFixed(3)}) m, the picture after ${a.capturedAt-a.askedAt} frames, the result after ${g}, worker ${d.toFixed(1)} ms`));const re=I(o);if(re==="waiting")return;if(re==="seeking"){o.anchor&&(ae(o.anchor),o.anchor=null,o.anchorPose=null),o.slew=null,o.shown=T,o.bestSide=W,e.setMatrix(o.target.entity,D),R(o,!0,`found at (${T.position.x.toFixed(3)} ${T.position.y.toFixed(3)} ${T.position.z.toFixed(3)}) m`),e.anchors()&&F(o,T);return}const le=o.anchorPose,me=qe(T.position,le.position),ie=De(T.rotation,le.rotation),Q=Qt({metres:me,degrees:ie,side:W,rms:q,inliers:U},o.bestSide),ne=`Δ ${(me*1e3).toFixed(1)} mm, ${ie.toFixed(2)}°`;Q==="near"?o.bestSide=Math.max(o.bestSide,W):Q==="kept"?ee-o.keptLoggedAt>=Ae&&(o.keptLoggedAt=ee,console.log(`[ar] qr ${o.target.text}: kept (side ${W.toFixed(0)} < ${$e} × ${o.bestSide.toFixed(0)} px), ${ne} (rms ${q.toFixed(2)} px)`)):(Q==="replace"||Q==="move")&&(console.log(`[ar] qr ${o.target.text}: anchor replaced${Q==="move"?" (a large Δ)":""}, ${ne} (side ${W.toFixed(0)} px, best ${o.bestSide.toFixed(0)}, rms ${q.toFixed(2)} px)`),o.bestSide=W,F(o,T))},te=o=>{if(N(),o.type==="ready"){i=!0,console.log(`[ar] qr: qr-anchor ${o.version} loaded in its worker in ${o.ms.toFixed(0)} ms`);return}if(o.type==="failed"){H(o.message);return}const c=l;if(!c||o.seq!==c.seq)return;l=null,h=!1;const a=o.observations,d=Math.floor(a.length/pe),g=p-c.askedAt;if(x.since&&c.phase===x.phase&&(x.captures++,x.workerMs+=o.processMs,x.captureFrames+=c.capturedAt-c.askedAt,x.resultFrames+=g,d>0&&x.found++),!c.stale){if(c.phase==="holding"){const v=new Set;for(let _=0;_<d;_++)v.add(a[_*pe]);t.forEach((_,q)=>{!v.has(q)&&I(_)==="holding"&&_.misses++})}for(let v=0;v<d;v++){const _=a.subarray(v*pe,(v+1)*pe),q=t[_[0]];q&&K(q,_,c,o.processMs,g)}}},Z=(o,c,a)=>{if(!r||!i){h=!1;return}const{width:d,height:g}=o,v=o.projection;if(!A.has(d)){A.add(d);const O=v[0]*d/2,C=v[5]*g/2,D=(1-v[8])*d/2-.5,T=(1+v[9])*g/2-.5;console.log(`[ar] qr: the capture is ${d}×${g} gray (seeking ${Ce} px / holding ${Ee} px, worker), fx ${O.toFixed(1)} fy ${C.toFixed(1)} cx ${D.toFixed(1)} cy ${T.toFixed(1)} px`)}const _=[],q=ze(o.viewMatrix);t.forEach((O,C)=>{if(I(O)!=="holding")return;let D=1/0,T=1/0,W=-1/0,re=-1/0,le=0;const me=O.anchorPose;if(me&&q){const Q=Re(me),ne=O.target.size/2;for(const[se,de]of[[-ne,-ne],[ne,-ne],[ne,ne],[-ne,ne]]){const ye=Q[0]*se+Q[8]*de+Q[12],Ze=Q[1]*se+Q[9]*de+Q[13],Je=Q[2]*se+Q[10]*de+Q[14],we=St({x:ye,y:Ze,z:Je},v,q,d,g);if(!we){D=1/0;break}D=Math.min(D,we[0]),W=Math.max(W,we[0]),T=Math.min(T,we[1]),re=Math.max(re,we[1])}le=Math.max(W-D,re-T)}if(!(D<1/0)&&O.corners){const Q=d/O.cornersIn[0],ne=g/O.cornersIn[1];D=1/0,T=1/0,W=-1/0,re=-1/0;for(let se=0;se<4;se++){const de=O.corners[2*se]*Q,ye=O.corners[2*se+1]*ne;D=Math.min(D,de),W=Math.max(W,de),T=Math.min(T,ye),re=Math.max(re,ye)}le=O.side*Math.max(Q,ne)}if(!(D<1/0))return;const ie=Bt*le;_.push([C,Math.floor(D-ie),Math.floor(T-ie),Math.ceil(W+ie),Math.ceil(re+ie)])});const U=o.data,B=U.byteOffset===0&&U.byteLength===U.buffer.byteLength?U.buffer:U.slice().buffer,ee=++f;l={seq:ee,phase:c,picture:o,askedAt:a,capturedAt:p,stale:!1},j({type:"frame",seq:ee,phase:c,gray:B,width:d,height:g,p0:v[0],p5:v[5],p8:v[8],p9:v[9],hints:_},[B])},m=o=>{const c=y;return y=o,!!c&&qe(o.position,c.position)<Ct&&De(o.rotation,c.rotation)<Wt},b=(o,c,a)=>(c?o/c:0).toFixed(a);return{setCodes(o){const c=o.map(d=>t.find(g=>g.target.entity===d.entity&&g.target.text===d.text&&g.target.size===d.size)??X(d));for(const d of t)c.includes(d)||J(d,!0);const a=c.length!==t.length||c.some((d,g)=>d!==t[g]);t=c,a&&(l&&(l.stale=!0),j({type:"targets",targets:P()})),Y()},frame(o,c,a){if(p++,t.length===0||!c)return;G(o,c);const d=a==null?void 0:a.views[0];if(!a||!d||a.emulatedPosition){y=null;return}const g=m(Ue(a.transform));E++;const v=t.map(I),_=t.some((O,C)=>v[C]==="seeking"||v[C]==="holding"&&O.misses>=be);if(_||v.includes("holding")){const O=performance.now(),C=_?"seeking":"holding";if(!x.since||x.phase!==C)x.phase=C,M(O);else if(O-x.since>=Xt){const D=x.captures,T=t.map(W=>t.length>1?`${W.target.text} ${W.depth.scale.toFixed(3)}`:W.depth.scale.toFixed(3)).join(", ");console.log(`[ar] qr: ${C} — ${D} captures in ${((O-x.since)/1e3).toFixed(0)} s, ${x.found} with a code, the picture after ${b(x.captureFrames,D,1)} frames, the result after ${b(x.resultFrames,D,1)}, worker ${b(x.workerMs,D,1)} ms mean, depth scale ${T}${t.some(W=>W.misses>=be)?`, sought again after ${be} misses`:""}`),M(O)}}else x.since=0;if(h||!i)return;let q;if(_)q=E>=jt;else{const O=t.some((D,T)=>v[T]==="holding"&&D.depth.estimate===null)?Dt:qt,C=E>=O&&g?ze(d.transform.matrix):null;q=!!C&&t.some((D,T)=>v[T]==="holding"&&D.anchorPose&&It(D.anchorPose.position,d.projectionMatrix,C))}if(!q)return;E=0,h=!0;const U=n,B=p,ee=_?"seeking":"holding";e.capture(_?Ce:Ee).then(O=>{U===n&&(O?Z(O,ee,B):h=!1)},O=>{U===n&&(h=!1,console.warn(`[ar] qr: the capture failed (${Ge(O)})`))})},clear(o=!1){n++,Fe=o;try{for(const c of t)J(c,!1)}finally{Fe=!1}t=[],V(),w=!1,E=0,y=null,A.clear(),M(0)}}},Be=["hit-test","anchors","dom-overlay","camera-access","light-estimation"],Jt=4,en=100,Ve=new Set,oe=(e,t)=>{Ve.has(e)||(Ve.add(e),console.warn(`[ar] ${t}`))},tn=async e=>{const t=typeof navigator>"u"?void 0:navigator.xr;if(!t||typeof e.presentXR!="function")return!1;try{return await t.isSessionSupported("immersive-ar")}catch{return!1}},Xe=(e,t,n,r)=>{const s=e[3]*t+e[7]*n+e[11]*r+e[15];return[(e[0]*t+e[4]*n+e[8]*r+e[12])/s,(e[1]*t+e[5]*n+e[9]*r+e[13])/s,(e[2]*t+e[6]*n+e[10]*r+e[14])/s]},nn=(e,t,n,r)=>{const s=t.scene;let i=0,u=!1,w=!1,l=null,f=null,h=null,p=null,E=null,y=new Set,A="",x=!1,M=null,$=[0,0,0],R=null,P=-1/0,j=-1,N=!0,V=[],H=[];const Y=new Map,X=new Map,J=Zt({setMatrix:(m,b)=>e.setMatrix(m,b),image:m=>n.image(m),capture:m=>p?p.captureCamera({gray:!0,maxWidth:m}):Promise.resolve(null),anchor:m=>{H.push(m)},anchors:()=>y.has("anchors"),workerUrl:async()=>{var m;return(m=await(r==null?void 0:r()))==null?void 0:m.qrAnchorWorker}}),k=m=>m.preventDefault(),I=m=>{let b="normal",o;(!m||m.emulatedPosition)&&(b="limited",o=x?"relocalizing":"initializing"),m&&!m.emulatedPosition&&(x=!0);const c=`${b}:${o??""}`;c!==A&&(A=c,n.tracking(o?{state:b,reason:o}:{state:b}))},F=(m,b)=>{const o=[];for(const c of m.getHitTestResults(b)){const a=f?c.getPose(f):void 0;if(!a)continue;const d=a.transform.position,g=a.transform.orientation;o.push({type:"estimated",pose:{position:{x:d.x,y:d.y,z:d.z},rotation:{x:g.x,y:g.y,z:g.z,w:g.w}},distance:Math.hypot(d.x-$[0],d.y-$[1],d.z-$[2])})}return o.sort((c,a)=>c.distance-a.distance)},L=(m,b)=>{var g;if(!b.wanted()){b.settle(null,!1);return}const o=i,{position:c,rotation:a}=b.pose;let d;try{d=f?(g=m.createAnchor)==null?void 0:g.call(m,new XRRigidTransform({x:c.x,y:c.y,z:c.z,w:1},{x:a.x,y:a.y,z:a.z,w:a.w}),f):void 0}catch(v){d=Promise.reject(v)}if(!d){b.settle(null,!1);return}d.then(v=>{if(o!==i||!b.wanted()){v.delete(),b.settle(null,o!==i);return}b.settle(v,!1)},v=>{oe("anchor",`the session made no anchor (${v instanceof Error?v.message:v}): an anchored node stays where it was put`),b.settle(null,o!==i)})},G=(m,b)=>{var d;if(!R||m-P<en)return;const o=(d=b.getLightEstimate)==null?void 0:d.call(b,R);if(!o)return;P=m;const c=o.primaryLightIntensity,a=Math.max(c.x,c.y,c.z)*1e3;Math.abs(a-j)<1||(j=a,n.light({intensity:a,temperature:6500}))},K=(m,b,o)=>{if(b.session!==l)return;I(o);const c=o==null?void 0:o.views[0];if(o&&c){M=ze(c.projectionMatrix);const a=o.transform.position;$=[a.x,a.y,a.z]}for(const[a,d]of X){const v=(b.trackedAnchors?b.trackedAnchors.has(d.anchor):!0)&&f?b.getPose(d.anchor.anchorSpace,f):void 0;v&&e.setMatrix(a,v.transform.matrix);const _=!!v;_&&(d.seen=!0),_!==d.tracked&&d.seen&&(d.tracked=_,n.anchor({entity:a,tracked:_}))}if(J.frame(b,f,o),H.length){const a=H;H=[];for(const d of a)L(b,d)}V.length&&(V=V.filter(a=>{const d=F(b,a.source);return d.length===0&&++a.frames<Jt?!0:(a.source.cancel(),a.resolve(d),!1)})),G(m,b),E==null||E()},te=(m=!1)=>{var c;i++,u=!1,w=!1,E==null||E(new z("failed")),p==null||p.end(),p=null;const b=l;l=null,b&&(b.removeEventListener("end",Z),m||b.end().catch(()=>{}),s!==void 0&&e.clearProjection(s)),(c=document.body)==null||c.removeEventListener("beforexrselect",k);for(const a of V){if(!m)try{a.source.cancel()}catch{}a.reject(new z("notRunning"))}V=[];const o=H;H=[];for(const a of o)a.settle(null,!0);if(Y.clear(),!m)for(const a of X.values())try{a.anchor.delete()}catch{}X.clear(),J.clear(m),f=null,h=null,y=new Set,A="",x=!1,M=null,$=[0,0,0],R=null,P=-1/0,j=-1},Z=()=>{const m=u;te(!0),m&&n.ended({reason:"user"})};return{async start(m){var d;if(u||w)throw new z("busy");if(s===void 0||t.camera===void 0)throw console.warn("[ar] start: the session has no scene or camera to drive (ARScene opens it with both)"),new z("failed");const b=navigator.xr,o=e.presentXR;if(!b||!o)throw new z("unavailable");((m==null?void 0:m.mode)==="images"||(d=m==null?void 0:m.images)!=null&&d.length)&&console.warn("[ar] the web finds no images in the camera's picture: their anchors are never tracked"),(m==null?void 0:m.worldAlignment)==="gravityAndHeading"&&oe("heading","WebXR has no compass: the world is aligned with gravity alone, −Z where the session began"),w=!0;const c=++i;J.setCodes((m==null?void 0:m.codes)??[]);let a;try{a=await b.requestSession("immersive-ar",{requiredFeatures:["local"],optionalFeatures:Be,domOverlay:{root:document.body}})}catch(g){c===i&&(w=!1);const v=g instanceof Error?g.name:"";throw console.warn(`[ar] no AR session: ${g instanceof Error?g.message:g}`),new z(v==="NotAllowedError"||v==="SecurityError"?"denied":v==="NotSupportedError"?"unavailable":"failed")}if(c!==i)throw a.end().catch(()=>{}),new z("failed");l=a,a.addEventListener("end",Z),document.body.addEventListener("beforexrselect",k),y=new Set(a.enabledFeatures??["local",...Be]);try{const g=await a.requestReferenceSpace("local");if(f=g,h=await a.requestReferenceSpace("viewer"),m!=null&&m.lightEstimation){const q=a.requestLightProbe;y.has("light-estimation")&&q?R=await q.call(a).catch(U=>(oe("light",`no light estimate: ${U instanceof Error?U.message:U}`),null)):oe("light","the AR session has no light estimate: no light event comes")}if(c!==i)throw new z("failed");const v=new Promise((q,U)=>{E=B=>{E=null,B?U(B):q()}}),_=await o.call(e,s,a,g,K);if(c!==i)throw _.end(),new z("failed");p=_,await v}catch(g){throw g instanceof z||console.warn(`[ar] the AR session did not start: ${g instanceof Error?g.message:g}`),c===i&&te(),g instanceof z?g:new z("failed")}if(c!==i)throw new z("failed");w=!1,u=!0},stop(){te()},setImages(m){if(!u)throw new z("notRunning");m.length&&console.warn("[ar] the web finds no images in the camera's picture: their anchors are never tracked")},setCodes(m){if(!u)throw new z("notRunning");J.setCodes(m)},async hitTest(m,b,o){const c=l;if(!u||!c||!h||s===void 0)throw new z("notRunning");if(!y.has("hit-test")||!c.requestHitTestSource)return oe("hit-test","the AR session has no hit test: hitTest finds nothing"),[];const a=e.viewport(s),d=M;if(!d||!a.width||!a.height)return[];const g=m/a.width*2-1,v=1-b/a.height*2,_=Xe(d,g,v,-1),q=Xe(d,g,v,1),U={x:q[0]-_[0],y:q[1]-_[1],z:q[2]-_[2],w:0},B=new XRRay({x:0,y:0,z:0,w:1},U),ee=i,O=async T=>c.requestHitTestSource({space:h,offsetRay:B,entityTypes:T});let C;try{C=await O(o==="planes"||!N?["plane"]:["plane","point"])}catch(T){if(o==="planes"||!N||ee!==i){if(oe("hit-source",`the session made no hit test: ${T instanceof Error?T.message:T}`),ee!==i)throw new z("notRunning");return[]}N=!1;try{C=await O(["plane"])}catch(W){oe("hit-source",`the session made no hit test: ${W instanceof Error?W.message:W}`)}}if(ee!==i)throw C==null||C.cancel(),new z("notRunning");if(!C)return[];const D=C;return new Promise((T,W)=>{V.push({source:D,frames:0,resolve:T,reject:W})})},anchor(m,b){if(!u||!l)throw new z("notRunning");if(e.setMatrix(m,Re(b)),!y.has("anchors")){oe("anchors","the AR session has no anchors: an anchored node stays where it was put (the world map does not refine it)");return}const o=X.get(m);if(o){X.delete(m);try{o.anchor.delete()}catch{}}return new Promise((c,a)=>{const d={pose:b,wanted:()=>Y.get(m)===d,settle:(g,v)=>{Y.get(m)===d&&Y.delete(m),g&&X.set(m,{anchor:g,tracked:!0,seen:!1}),v?a(new z("notRunning")):c()}};Y.set(m,d),H.push(d)})},release(m){Y.delete(m);const b=X.get(m);if(b){X.delete(m);try{b.anchor.delete()}catch{}}},async captureFrame(){const m=p;if(!u||!m)throw new z("notRunning");const b=i,o=await m.captureCamera();if(b!==i)throw new z("notRunning");if(!o)throw oe("capture","captureFrame: the AR session gives no camera picture (WebXR's camera-access: Chrome on Android, the camera allowed)"),new z("failed");const c=document.createElement("canvas");c.width=o.width,c.height=o.height;const a=c.getContext("2d");if(!a)throw new z("failed");a.putImageData(new ImageData(new Uint8ClampedArray(o.rgba.buffer,o.rgba.byteOffset,o.rgba.byteLength),o.width,o.height),0,0);const d=await new Promise(g=>c.toBlob(g,"image/jpeg",.9));if(!d)throw new z("failed");return{data:await d.arrayBuffer(),name:"frame.jpg"}},close(){te()}}},on=(e,t)=>{var r;if(typeof navigator>"u"||!((r=navigator.mediaDevices)!=null&&r.getUserMedia))return;const n=e.gl;ht(e,(s,i)=>{let u=null,w=null,l=null,f=!1,h=0;const p=()=>{if(!l)throw new z("notRunning");return l},E=()=>{h++;const y=l;return l=null,y};return{async start(y){if(f)throw new z("busy");if(l)return l.start(y);f=!0;const A=h;let x;try{x=await tn(n)?w??(w=nn(n,s,i,t)):u??(u=bt(n,s,i))}finally{f=!1}if(A!==h)throw new z("failed");l=x;try{await x.start(y)}catch(M){throw l===x&&(l=null),M}},stop(){var y;return(y=E())==null?void 0:y.stop()},setImages(y){return p().setImages(y)},setCodes(y){return p().setCodes(y)},hitTest(y,A,x){return p().hitTest(y,A,x)},anchor(y,A){return p().anchor(y,A)},release(y){return l==null?void 0:l.release(y)},captureFrame(){return p().captureFrame()},close(){var y,A;(A=(y=E())==null?void 0:y.close)==null||A.call(y)}}})};export{on as register};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){"use strict";class g{__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,S.unregister(this),t}free(){const t=this.__destroy_into_raw();s.__wbg_qranchor_free(t,0)}clear_hints(){s.qranchor_clear_hints(this.__wbg_ptr)}frame_height(){return s.qranchor_frame_height(this.__wbg_ptr)>>>0}frame_ptr(t,r){return s.qranchor_frame_ptr(this.__wbg_ptr,t,r)>>>0}frame_width(){return s.qranchor_frame_width(this.__wbg_ptr)>>>0}gray_from_rgba(){s.qranchor_gray_from_rgba(this.__wbg_ptr)}constructor(t){const r=q(t,s.__wbindgen_malloc,s.__wbindgen_realloc),n=w,o=s.qranchor_new(r,n);if(o[2])throw k(o[1]);return this.__wbg_ptr=o[0],S.register(this,this.__wbg_ptr,this),this}output_len(){return s.qranchor_output_len(this.__wbg_ptr)>>>0}output_ptr(){return s.qranchor_output_ptr(this.__wbg_ptr)>>>0}process(t,r,n,o){return s.qranchor_process(this.__wbg_ptr,t,r,n,o)>>>0}process_gl(t,r,n,o){return s.qranchor_process_gl(this.__wbg_ptr,t,r,n,o)>>>0}reset(){s.qranchor_reset(this.__wbg_ptr)}rgba_ptr(t,r){return s.qranchor_rgba_ptr(this.__wbg_ptr,t,r)>>>0}set_hint(t,r,n,o,_){s.qranchor_set_hint(this.__wbg_ptr,t,r,n,o,_)}set_targets(t){const r=q(t,s.__wbindgen_malloc,s.__wbindgen_realloc),n=w,o=s.qranchor_set_targets(this.__wbg_ptr,r,n);if(o[2])throw k(o[1]);return o[0]>>>0}}Symbol.dispose&&(g.prototype[Symbol.dispose]=g.prototype.free);function x(){return s.output_layout_version()>>>0}function T(){return s.output_stride()>>>0}function F(){let e,t;try{const r=s.version();return e=r[0],t=r[1],h(r[0],r[1])}finally{s.__wbindgen_free(e,t,1)}}function I(){return{__proto__:null,"./qr_anchor_wasm_bg.js":{__proto__:null,__wbg_Error_30c8987f7c2ed4e2:function(t,r){return Error(h(t,r))},__wbg___wbindgen_throw_41e9ee4f547fc59a:function(t,r){throw new Error(h(t,r))},__wbg_error_757e9472f8410341:function(t,r){let n,o;try{n=t,o=r,console.error(h(t,r))}finally{s.__wbindgen_free(n,o,1)}},__wbg_new_227d7c05414eb861:function(){return new Error},__wbg_stack_3b0d974bbf31e44f:function(t,r){const n=r.stack,o=q(n,s.__wbindgen_malloc,s.__wbindgen_realloc),_=w;M().setInt32(t+4,_,!0),M().setInt32(t+0,o,!0)},__wbindgen_init_externref_table:function(){const t=s.__wbindgen_externrefs,r=t.grow(4);t.set(0,void 0),t.set(r+0,void 0),t.set(r+1,null),t.set(r+2,!0),t.set(r+3,!1)}}}}const S=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>s.__wbg_qranchor_free(e,1));let f=null;function M(){return(f===null||f.buffer.detached===!0||f.buffer.detached===void 0&&f.buffer!==s.memory.buffer)&&(f=new DataView(s.memory.buffer)),f}function h(e,t){return C(e>>>0,t)}let u=null;function p(){return(u===null||u.byteLength===0)&&(u=new Uint8Array(s.memory.buffer)),u}function q(e,t,r){if(r===void 0){const c=l.encode(e),a=t(c.length,1)>>>0;return p().subarray(a,a+c.length).set(c),w=c.length,a}let n=e.length,o=t(n,1)>>>0;const _=p();let i=0;for(;i<n;i++){const c=e.charCodeAt(i);if(c>127)break;_[o+i]=c}if(i!==n){i!==0&&(e=e.slice(i)),o=r(o,n,n=i+e.length*3,1)>>>0;const c=p().subarray(o+i,o+n),a=l.encodeInto(e,c);i+=a.written,o=r(o,n,i,1)>>>0}return w=i,o}function k(e){const t=s.__wbindgen_externrefs.get(e);return s.__externref_table_dealloc(e),t}let d=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});d.decode();const L=2146435072;let A=0;function C(e,t){return A+=t,A>=L&&(d=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),d.decode(),A=t),d.decode(p().subarray(e,e+t))}const l=new TextEncoder;"encodeInto"in l||(l.encodeInto=function(e,t){const r=l.encode(e);return t.set(r),{read:e.length,written:r.length}});let w=0,s;function $(e,t){return s=e.exports,f=null,u=null,s.__wbindgen_start(),s}async function j(e,t){if(typeof Response=="function"&&e instanceof Response){if(!e.ok)throw new Error(`failed to fetch Wasm: ${e.status} ${e.statusText} fetching '${e.url}'`);if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(e,t)}catch(o){if(r(e.type)&&e.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",o);else throw o}const n=await e.arrayBuffer();return await WebAssembly.instantiate(n,t)}else{const n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}function r(n){switch(n){case"basic":case"cors":case"default":return!0}return!1}}async function z(e){if(s!==void 0)return s;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),e===void 0&&(e=new URL(""+new URL("qr_anchor_wasm_bg-D_ePkCCu.wasm",self.location.href).href,self.location.href));const t=I();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));const{instance:r,module:n}=await j(await e,t);return $(r)}const v=1,D=28,y=self;let m=null;const b={};let O=!1;const U=e=>{var r,n;const t=JSON.stringify(e);(r=b.seeking)==null||r.set_targets(t),(n=b.holding)==null||n.set_targets(t)},B=async e=>{if(e.type==="init"){const E=performance.now(),R=await z({module_or_path:new URL(""+new URL("qr_anchor_wasm_bg-D_ePkCCu.wasm",self.location.href).href,self.location.href)});if(x()!==v||T()!==D)throw new Error(`its output is layout ${x()} × ${T()}, this worker reads ${v} × ${D}`);m=R.memory,b.seeking=new g(JSON.stringify(e.config.seeking)),b.holding=new g(JSON.stringify(e.config.holding)),U(e.targets),y.postMessage({type:"ready",version:F(),ms:performance.now()-E});return}if(e.type==="targets"){U(e.targets);return}const t=b[e.phase];if(!t||!m)throw new Error("a frame before the detector was made");const{seq:r,width:n,height:o}=e,_=performance.now(),i=t.frame_ptr(n,o);let c=0;if(i){new Uint8Array(m.buffer,i,n*o).set(new Uint8Array(e.gray,0,n*o));for(const[E,R,N,P,V]of e.hints)t.set_hint(E,R,N,P,V);c=t.process_gl(e.p0,e.p5,e.p8,e.p9)}const a=c>0?new Float64Array(m.buffer,t.output_ptr(),t.output_len()).slice():new Float64Array(0);y.postMessage({type:"result",seq:r,observations:a,processMs:performance.now()-_},[a.buffer])};let W=Promise.resolve();y.onmessage=e=>{const t=e.data;W=W.then(()=>{if(!O)return B(t).catch(r=>{O=!0,y.postMessage({type:"failed",message:r instanceof Error?r.message:String(r)})})})}})();
|
|
Binary file
|
package/runtime/web/index.html
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, viewport-fit=cover" />
|
|
6
|
+
<meta name="color-scheme" content="only light" />
|
|
6
7
|
<title>LeCodes</title>
|
|
7
8
|
<style>
|
|
8
9
|
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: #000; }
|