@omnidotdev/rdk 0.11.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/build/assets/onnxWorker-BNjoneWr.js +1 -0
  2. package/build/geolocation/geolocationBackend.d.ts +1 -1
  3. package/build/geolocation/geolocationBackend.d.ts.map +1 -1
  4. package/build/{geolocation-D_rCGA-C.cjs → geolocation-CT1kLdSh.cjs} +1 -1
  5. package/build/{geolocation-DqxybM8d.js → geolocation-Dl910ZC5.js} +74 -73
  6. package/build/geolocation.cjs +1 -1
  7. package/build/geolocation.js +1 -1
  8. package/build/index.cjs +1 -1
  9. package/build/index.js +6 -6
  10. package/build/vision/index.d.ts +2 -2
  11. package/build/vision/index.d.ts.map +1 -1
  12. package/build/vision/presets.d.ts +9 -0
  13. package/build/vision/presets.d.ts.map +1 -1
  14. package/build/vision/providers/onnxProvider.d.ts.map +1 -1
  15. package/build/vision/types.d.ts +19 -1
  16. package/build/vision/types.d.ts.map +1 -1
  17. package/build/vision/worker/decoders/index.d.ts +1 -1
  18. package/build/vision/worker/decoders/index.d.ts.map +1 -1
  19. package/build/vision/worker/decoders/rfDetr.d.ts.map +1 -1
  20. package/build/vision/worker/decoders/types.d.ts +8 -3
  21. package/build/vision/worker/decoders/types.d.ts.map +1 -1
  22. package/build/vision/worker/decoders/yolo.d.ts.map +1 -1
  23. package/build/vision/worker/decoders/yoloSeg.d.ts +11 -0
  24. package/build/vision/worker/decoders/yoloSeg.d.ts.map +1 -0
  25. package/build/vision/worker/types.d.ts +2 -1
  26. package/build/vision/worker/types.d.ts.map +1 -1
  27. package/build/{vision-BKOfvNSR.js → vision-Bdhf3N-w.js} +34 -26
  28. package/build/vision-sMKG7-na.cjs +1 -0
  29. package/build/vision.cjs +1 -1
  30. package/build/vision.js +2 -2
  31. package/package.json +3 -3
  32. package/build/assets/onnxWorker-B_g0sj2t.js +0 -1
  33. package/build/vision-CRUCg7uc.cjs +0 -1
@@ -0,0 +1 @@
1
+ const e=(e,t)=>{let n=e.x+e.width,r=e.y+e.height,i=t.x+t.width,a=t.y+t.height,o=Math.max(e.x,t.x),s=Math.max(e.y,t.y),c=Math.min(n,i),l=Math.min(r,a),u=Math.max(0,c-o)*Math.max(0,l-s);if(u===0)return 0;let d=e.width*e.height+t.width*t.height-u;return d<=0?0:u/d},t=(t,n)=>{let r=[...t].sort((e,t)=>t.confidence-e.confidence),i=[];for(let t of r)i.some(r=>r.label===t.label&&e(r.bbox,t.bbox)>n)||i.push(t);return i},n=(e,t,n,r,i)=>{let a=(e-i.padX)/i.scale,o=(t-i.padY)/i.scale,s=(n-i.padX)/i.scale,c=(r-i.padY)/i.scale,l=Math.max(0,Math.min(a,i.sourceWidth)),u=Math.max(0,Math.min(o,i.sourceHeight)),d=Math.max(0,Math.min(s,i.sourceWidth)),f=Math.max(0,Math.min(c,i.sourceHeight)),p=d-l,m=f-u;return p<=0||m<=0?null:{x:l,y:u,width:p,height:m}},r=e=>1/(1+Math.exp(-e)),i=e=>{let t=Object.values(e).filter(e=>e.dims.length===3),n=t.find(e=>e.dims[2]===4),r=t.find(e=>e!==n);if(!n||!r)throw Error(`RF-DETR decoder: expected a [1, Q, 4] boxes tensor and a [1, Q, C] logits tensor`);return{boxes:n,logits:r}},a={name:`rfdetr`,decode(e,t){let{boxes:a,logits:o}=i(e),s=a.dims[1],c=o.dims[2],l=a.data,u=o.data,d=[];for(let e=0;e<s;e++){let i=0,a=-1;for(let t=0;t<c;t++){let n=r(u[e*c+t]);n>i&&(i=n,a=t)}if(a<0||i<t.minConfidence)continue;let o=e*4,s=l[o]*t.inputSize,f=l[o+1]*t.inputSize,p=l[o+2]*t.inputSize,m=l[o+3]*t.inputSize,h=n(s-p/2,f-m/2,s+p/2,f+m/2,t);h&&d.push({label:t.labels[a]??String(a),confidence:i,bbox:h})}return{objects:d.sort((e,t)=>t.confidence-e.confidence).slice(0,t.maxResults)}}},o=e=>{let t=Object.values(e);if(t.length===0)throw Error(`YOLO decoder: no output tensors`);return t[0]},s={name:`yolo`,decode(e,r){let{dims:i,data:a}=o(e);if(i.length!==3||i[0]!==1)throw Error(`YOLO decoder: expected [1, C, A] output, got [${i.join(`, `)}]`);let s=i[1],c=i[2],l=s-4;if(l<=0)throw Error(`YOLO decoder: too few channels (${s})`);let u=[];for(let e=0;e<c;e++){let t=0,i=-1;for(let n=0;n<l;n++){let r=a[(4+n)*c+e];r>t&&(t=r,i=n)}if(i<0||t<r.minConfidence)continue;let o=a[e],s=a[c+e],d=a[2*c+e],f=a[3*c+e],p=n(o-d/2,s-f/2,o+d/2,s+f/2,r);p&&u.push({label:r.labels[i]??String(i),confidence:t,bbox:p})}return{objects:t(u,.45).sort((e,t)=>t.confidence-e.confidence).slice(0,r.maxResults)}}},c=e=>1/(1+Math.exp(-e)),l={yolo:s,rfdetr:a,yoloseg:{name:`yoloseg`,decode(t,r){let i=Object.values(t),a=i.find(e=>e.dims.length===4),o=i.find(e=>e.dims.length===3);if(!a||!o)throw Error(`YOLO-seg decoder: expected a [1, C, A] detection tensor and a [1, M, H, W] prototype tensor`);let s=a.dims[1],l=a.dims[2],u=a.dims[3],d=o.dims[1],f=o.dims[2],p=d-4-s;if(p<=0)throw Error(`YOLO-seg decoder: bad channel count (${d})`);let m=o.data,h=[];for(let e=0;e<f;e++){let t=0,i=-1;for(let n=0;n<p;n++){let r=m[(4+n)*f+e];r>t&&(t=r,i=n)}if(i<0||t<r.minConfidence)continue;let a=m[e],o=m[f+e],c=m[2*f+e],l=m[3*f+e],u=n(a-c/2,o-l/2,a+c/2,o+l/2,r);if(!u)continue;let d=[];for(let t=0;t<s;t++)d.push(m[(4+p+t)*f+e]);h.push({label:r.labels[i]??String(i),confidence:t,bbox:u,coeffs:d})}h.sort((e,t)=>t.confidence-e.confidence);let g=[];for(let t of h)if(g.some(n=>n.label===t.label&&e(n.bbox,t.bbox)>.45)||g.push(t),g.length>=r.maxResults)break;let _=a.data,v=l*u,y=u/r.inputSize,b=l/r.inputSize,x=g.map(e=>{let{x:t,y:n,width:i,height:a}=e.bbox,o=t*r.scale+r.padX,d=n*r.scale+r.padY,f=(t+i)*r.scale+r.padX,p=(n+a)*r.scale+r.padY,m=Math.max(0,Math.floor(o*y)),h=Math.max(0,Math.floor(d*b)),g=Math.min(u,Math.ceil(f*y)),x=Math.min(l,Math.ceil(p*b)),S=Math.max(1,g-m),C=Math.max(1,x-h),w=new Uint8Array(S*C);for(let t=h;t<x;t++)for(let n=m;n<g;n++){let r=0;for(let i=0;i<s;i++)r+=e.coeffs[i]*_[i*v+t*u+n];c(r)>.5&&(w[(t-h)*S+(n-m)]=255)}return{label:e.label,confidence:e.confidence,bbox:e.bbox,mask:w,maskWidth:S,maskHeight:C}});return{objects:g.map(e=>({label:e.label,confidence:e.confidence,bbox:e.bbox})),masks:x}}}},u=(e=`yolo`)=>l[e]??s,d=(e,t,n)=>{let r=Math.min(n/e,n/t),i=e*r,a=t*r;return{scale:r,drawWidth:i,drawHeight:a,padX:(n-i)/2,padY:(n-a)/2}},f=(e,t)=>{let n=t*t,r=new Float32Array(3*n);for(let t=0;t<n;t++)r[t]=e[t*4]/255,r[n+t]=e[t*4+1]/255,r[2*n+t]=e[t*4+2]/255;return r};let p=null;const m=new Map,h=()=>(p||=import(`onnxruntime-web`).then(e=>(e.env.wasm.wasmPaths=`https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/`,e)),p),g=(e,t)=>{t&&t.length>0?self.postMessage(e,{transfer:t}):self.postMessage(e)},_=async(e,t,n,r,i,a)=>{let o=t.config.inputSize??640,{scale:s,padX:c,padY:l,drawWidth:p,drawHeight:m}=d(r,i,o),h=new OffscreenCanvas(o,o).getContext(`2d`);if(!h)throw Error(`Failed to acquire OffscreenCanvas 2D context`);h.fillStyle=`rgb(114, 114, 114)`,h.fillRect(0,0,o,o),h.drawImage(n,c,l,p,m);let{data:g}=h.getImageData(0,0,o,o),_=new e.Tensor(`float32`,f(g,o),[1,3,o,o]),v={[t.session.inputNames[0]]:_},y=await t.session.run(v),b={};for(let[e,t]of Object.entries(y))b[e]={data:t.data,dims:t.dims};let x={inputSize:o,sourceWidth:r,sourceHeight:i,scale:s,padX:c,padY:l,labels:t.config.labels??[],minConfidence:a.minConfidence,maxResults:a.maxResults};return u(t.config.decoder).decode(b,x)};self.addEventListener(`message`,async e=>{let t=e.data;switch(t.type){case`init`:g({type:`initialized`});break;case`loadModel`:{let{model:e}=t;try{let t=await(await h()).InferenceSession.create(e.path,{executionProviders:[`webgpu`,`wasm`]});m.set(e.name,{config:e,session:t}),g({type:`modelLoaded`,modelName:e.name})}catch(t){g({type:`modelError`,modelName:e.name,error:t instanceof Error?t.message:`Unknown error`})}break}case`process`:{let{imageBitmap:e,sourceWidth:n,sourceHeight:r,options:i}=t;try{let t=await h(),a=performance.now(),o=[],s=[];for(let a of m.values()){let c=await _(t,a,e,n,r,i);c.objects&&o.push(...c.objects),c.masks&&s.push(...c.masks)}let c=s.map(e=>e.mask.buffer);g({type:`result`,result:{detections:o,masks:s,frameSize:{width:n,height:r},timestamp:Date.now(),processingTime:performance.now()-a}},c)}catch(e){g({type:`error`,error:e instanceof Error?e.message:`Unknown error`})}finally{e.close()}break}case`dispose`:for(let{session:e}of m.values())e.release();m.clear();break}});
@@ -1,5 +1,5 @@
1
- import { DeviceOrientationControls, LocAR, Webcam } from 'locar';
2
1
  import { Backend } from 'lib/types/engine';
2
+ import { DeviceOrientationControls, LocAR, Webcam } from 'locar';
3
3
  import { Camera, Group, Scene } from 'three';
4
4
  /**
5
5
  * GPS update event structure emitted by LocAR.
@@ -1 +1 @@
1
- {"version":3,"file":"geolocationBackend.d.ts","sourceRoot":"","sources":["../../src/geolocation/geolocationBackend.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAA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- const e=require(`./useXRStore-8Vl3wsP5.cjs`);let t=require(`react`),n=require(`@react-three/fiber`),r=require(`react/jsx-runtime`),i=require(`three`),a=require(`three/addons/lines/Line2.js`),o=require(`three/addons/lines/LineGeometry.js`),s=require(`three/addons/lines/LineMaterial.js`),c=require(`locar`);var l={isPending:!0,isSuccess:!1,locar:null,webcam:null,deviceOrientation:null,scene:null,camera:null,lastPosition:null,registerAnchor:()=>{},unregisterAnchor:()=>{},getAnchor:()=>void 0},u=()=>{let t=e.r(e=>e.backends).get(e.i.GEOLOCATION);return t?{...t.getInternal(),isPending:!1,isSuccess:!0}:l},d=(e,t)=>{let n=e.length-1,r=[],a=0,o=0;for(let i=0;i<n;i++){let n=e[i+1].x-e[i].x,s=e[i+1].y-e[i].y,c=e[i+1].z-e[i].z,l=Math.sqrt(n*n+s*s+c*c),u=t/2,d=-(c*u)/l,f=n*u/l,p=i>0?(d+a)/2:d,m=i>0?(f+o)/2:f;r.push(e[i].x-p,e[i].y,e[i].z-m,e[i].x+p,e[i].y,e[i].z+m),a=d,o=f}r.push(e[n].x-a,e[n].y,e[n].z-o,e[n].x+a,e[n].y,e[n].z+o);let s=[];for(let e=0;e<n;e++)s.push(e*2,e*2+1,e*2+2),s.push(e*2+1,e*2+3,e*2+2);let c=new i.BufferGeometry;return c.setIndex(s),c.setAttribute(`position`,new i.BufferAttribute(new Float32Array(r),3)),c.computeBoundingBox(),c},f=({coordinates:e,color:c=`#ff0000`,isDashed:l=!1,dashSize:f=3,gapSize:p=1,lineWidth:m=1})=>{let h=u(),g=(0,t.useRef)(h);g.current=h;let[_]=(0,t.useState)(()=>new i.Group),v=(0,t.useMemo)(()=>Math.random().toString(36).slice(2,11),[]),[y,b]=(0,t.useState)(null);return(0,t.useEffect)(()=>{if(!h.isSuccess||e.length<2)return;let[t,n,r=0]=e[0];return g.current.registerAnchor(v,{anchor:_,isAttached:!1,latitude:n,longitude:t,altitude:r,onAttach:t=>{let[n,r,u=0]=e[0],[h,g]=t.lonLatToWorldCoords(n,r),_=e.map(([e,n,r=0])=>{let[a,o]=t.lonLatToWorldCoords(e,n);return new i.Vector3(a-h,r-u,o-g)});if(l){let e=new a.Line2(new o.LineGeometry().setFromPoints(_),new s.LineMaterial({color:c,dashSize:f,gapSize:p,dashed:!0,worldUnits:!0,linewidth:m}));e.computeLineDistances(),b(e)}else b(new i.Mesh(d(_,m),new i.MeshBasicMaterial({color:c,side:i.DoubleSide})))}}),()=>{g.current.unregisterAnchor(v),b(e=>(e&&(e.geometry.dispose(),e.material.dispose()),null))}},[v,_,e,c,l,f,p,m,h.isSuccess]),(0,n.createPortal)((0,r.jsx)(`group`,{children:y&&(0,r.jsx)(`primitive`,{object:y})}),_)},p=({latitude:e,longitude:a,altitude:o=0,isBillboard:s=!0,onAttach:c,onGpsUpdate:l,children:d})=>{let f=u(),p=(0,t.useRef)(f);p.current=f;let{camera:m}=(0,n.useThree)(),[h]=(0,t.useState)(()=>new i.Group),g=(0,t.useMemo)(()=>Math.random().toString(36).slice(2,11),[]),_=(0,t.useCallback)(()=>{c?.()},[c]),v=(0,t.useCallback)((e,t)=>{l?.(e,t)},[l]);return(0,t.useEffect)(()=>{if(f.isSuccess)return p.current.registerAnchor(g,{anchor:h,isAttached:!1,latitude:e,longitude:a,altitude:o,onAttach:_,onGpsUpdate:v}),()=>{p.current.unregisterAnchor(g)}},[h,g,e,a,o,_,v,f.isSuccess]),(0,n.useFrame)(()=>{!s||!m||!f.isSuccess||f.getAnchor(g)?.isAttached&&h.lookAt(m.position)}),(0,n.createPortal)((0,r.jsx)(`group`,{children:d}),h)},m=({options:r={},children:i})=>{let{scene:a,camera:o,gl:s}=(0,n.useThree)(),{registerBackend:c,unregisterBackend:l}=e.r(),u=(0,t.useRef)(null),d=(0,t.useRef)(r);return d.current=r,(0,t.useEffect)(()=>{if(u.current)return;let e=!1;return(async()=>{try{let t=_(d.current);if(e)return;await c(t,{scene:a,camera:o,renderer:s}),u.current=t}catch(e){console.error(`[GeolocationSession] Failed to initialize:`,e)}})(),()=>{e=!0,u.current&&=(l(u.current),null)}},[a,o,s,c,l]),i},h={front:i.FrontSide,back:i.BackSide,double:i.DoubleSide},g=({coordinates:e,holes:a,color:o=`#ff0000`,opacity:s=1,isWireframe:c=!1,side:l=`double`})=>{let d=u(),f=(0,t.useRef)(d);f.current=d;let[p]=(0,t.useState)(()=>new i.Group),m=(0,t.useMemo)(()=>Math.random().toString(36).slice(2,11),[]),[g,_]=(0,t.useState)(null);return(0,t.useEffect)(()=>{if(!d.isSuccess||e.length<3)return;let[t,n,r=0]=e[0];return f.current.registerAnchor(m,{anchor:p,isAttached:!1,latitude:n,longitude:t,altitude:r,onAttach:t=>{let[n,r,o=0]=e[0],[s,c]=t.lonLatToWorldCoords(n,r),l=[];for(let[n,r,i=0]of e){let[e,a]=t.lonLatToWorldCoords(n,r);l.push({x:e-s,z:a-c,elev:i-o})}let u=new i.Shape;u.moveTo(l[0].x,l[0].z);for(let e=1;e<l.length;e++)u.lineTo(l[e].x,l[e].z);if(u.closePath(),a&&a.length>0)for(let e of a){if(e.length<3)continue;let n=new i.Path,[r,a]=e[0],[o,l]=t.lonLatToWorldCoords(r,a);n.moveTo(o-s,l-c);for(let r=1;r<e.length;r++){let[i,a]=e[r],[o,l]=t.lonLatToWorldCoords(i,a);n.lineTo(o-s,l-c)}n.closePath(),u.holes.push(n)}let d=new i.ShapeGeometry(u),f=l.reduce((e,t)=>e+t.elev,0)/l.length;d.rotateX(-Math.PI/2),_({geometry:d,avgElevation:f})}}),()=>{f.current.unregisterAnchor(m),_(e=>(e&&e.geometry.dispose(),null))}},[m,p,e,a,d.isSuccess]),(0,n.createPortal)((0,r.jsx)(`group`,{children:g&&(0,r.jsx)(`group`,{position:[0,g.avgElevation,0],children:(0,r.jsx)(`mesh`,{geometry:g.geometry,children:(0,r.jsx)(`meshBasicMaterial`,{color:o,opacity:s,transparent:s<1,wireframe:c,side:h[l]})})})}),p)},_=t=>{let n=null,r=null,i=null,a,o=null,s=null,l=null,u=null,d=null,f=new Map,p=null,m=e=>{if(!(!n||e.isAttached))try{n.add(e.anchor,e.longitude,e.latitude,e.altitude),e.isAttached=!0,e.onAttach?.(n)}catch(e){console.error(`❌ Failed to attach anchor:`,e)}},h=(e,t)=>{f.set(e,t),p!==null&&!t.isAttached&&(m(t),t.onGpsUpdate?.(p,0))},g=e=>{let t=f.get(e);if(t?.isAttached)try{t.anchor.removeFromParent()}catch(t){console.error(`⚠️ Error removing anchor ${e}:`,t)}f.delete(e)},_=e=>f.get(e);return{type:e.i.GEOLOCATION,async init(e){let{camera:h,renderer:g,scene:_}=e;if(!_)throw Error(`[geolocationBackend] A THREE.Scene is required for location-based AR`);l=h,u=g,d=_,n=new c.LocAR(_,h),g.setClearAlpha?.(0);let v=new Set(document.querySelectorAll(`video`));r=new c.Webcam(t?.webcamConstraints??{video:{facingMode:`environment`}});for(let e of document.querySelectorAll(`video`))if(!v.has(e)){o=e;break}s=e=>{p=e.position;for(let t of f.values())t.isAttached||m(t),t.onGpsUpdate?.(e.position,e.distMoved);t?.onGpsUpdate?.(e.position,e.distMoved)},n.on(`gpsupdate`,s),r.on(`webcamerror`,e=>{console.error(`[geolocationBackend] webcam error:`,e)}),i=new c.DeviceOrientationControls(h),i.on(`deviceorientationgranted`,e=>{e.target?.connect?.()}),i.on(`deviceorientationerror`,e=>{console.error(`[geolocationBackend] Device orientation error:`,e)}),i.init?.(),n.on(`gpserror`,e=>{console.error(`[geolocationBackend] gps error:`,e)}),n.startGps(),typeof t?.fakeLat==`number`&&typeof t?.fakeLon==`number`&&n.fakeGps(t.fakeLon,t.fakeLat);let y=n.getLastKnownLocation();y!==null&&(p={coords:{longitude:y.longitude,latitude:y.latitude,accuracy:0,altitude:null,altitudeAccuracy:null,heading:null,speed:null,toJSON:()=>y},timestamp:Date.now(),toJSON:()=>y});let b=()=>{if(!u||!l)return;let e=window.innerWidth,t=window.innerHeight;u.setSize(e,t,!1),l.aspect=e/t,l.updateProjectionMatrix?.()};b(),window.addEventListener(`resize`,b),a=b},update(){i?.update?.()},dispose(){if(n&&s&&n.off(`gpsupdate`,s),n?.stopGps?.(),o){let e=o.srcObject;for(let t of e?.getTracks()??[])t.stop();o.srcObject=null,o.remove(),o=null}u?.setClearAlpha?.(1),i?.dispose?.(),a&&=(window.removeEventListener(`resize`,a),void 0);for(let e of f.values())if(e.isAttached)try{e.anchor.removeFromParent()}catch(e){console.error(`⚠️ Error removing anchor:`,e)}f.clear(),n=null,r=null,i=null,l=null,u=null,d=null,s=null,p=null},getInternal:()=>({locar:n,webcam:r,deviceOrientation:i,scene:d,camera:l,lastPosition:p,registerAnchor:h,unregisterAnchor:g,getAnchor:_})}};Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return _}});
1
+ const e=require(`./useXRStore-8Vl3wsP5.cjs`);let t=require(`react`),n=require(`@react-three/fiber`),r=require(`react/jsx-runtime`),i=require(`three`),a=require(`three/addons/lines/Line2.js`),o=require(`three/addons/lines/LineGeometry.js`),s=require(`three/addons/lines/LineMaterial.js`),c=require(`locar`);var l={isPending:!0,isSuccess:!1,locar:null,webcam:null,deviceOrientation:null,scene:null,camera:null,lastPosition:null,registerAnchor:()=>{},unregisterAnchor:()=>{},getAnchor:()=>void 0},u=()=>{let t=e.r(e=>e.backends).get(e.i.GEOLOCATION);return t?{...t.getInternal(),isPending:!1,isSuccess:!0}:l},d=(e,t)=>{let n=e.length-1,r=[],a=0,o=0;for(let i=0;i<n;i++){let n=e[i+1].x-e[i].x,s=e[i+1].y-e[i].y,c=e[i+1].z-e[i].z,l=Math.sqrt(n*n+s*s+c*c),u=t/2,d=-(c*u)/l,f=n*u/l,p=i>0?(d+a)/2:d,m=i>0?(f+o)/2:f;r.push(e[i].x-p,e[i].y,e[i].z-m,e[i].x+p,e[i].y,e[i].z+m),a=d,o=f}r.push(e[n].x-a,e[n].y,e[n].z-o,e[n].x+a,e[n].y,e[n].z+o);let s=[];for(let e=0;e<n;e++)s.push(e*2,e*2+1,e*2+2),s.push(e*2+1,e*2+3,e*2+2);let c=new i.BufferGeometry;return c.setIndex(s),c.setAttribute(`position`,new i.BufferAttribute(new Float32Array(r),3)),c.computeBoundingBox(),c},f=({coordinates:e,color:c=`#ff0000`,isDashed:l=!1,dashSize:f=3,gapSize:p=1,lineWidth:m=1})=>{let h=u(),g=(0,t.useRef)(h);g.current=h;let[_]=(0,t.useState)(()=>new i.Group),v=(0,t.useMemo)(()=>Math.random().toString(36).slice(2,11),[]),[y,b]=(0,t.useState)(null);return(0,t.useEffect)(()=>{if(!h.isSuccess||e.length<2)return;let[t,n,r=0]=e[0];return g.current.registerAnchor(v,{anchor:_,isAttached:!1,latitude:n,longitude:t,altitude:r,onAttach:t=>{let[n,r,u=0]=e[0],[h,g]=t.lonLatToWorldCoords(n,r),_=e.map(([e,n,r=0])=>{let[a,o]=t.lonLatToWorldCoords(e,n);return new i.Vector3(a-h,r-u,o-g)});if(l){let e=new a.Line2(new o.LineGeometry().setFromPoints(_),new s.LineMaterial({color:c,dashSize:f,gapSize:p,dashed:!0,worldUnits:!0,linewidth:m}));e.computeLineDistances(),b(e)}else b(new i.Mesh(d(_,m),new i.MeshBasicMaterial({color:c,side:i.DoubleSide})))}}),()=>{g.current.unregisterAnchor(v),b(e=>(e&&(e.geometry.dispose(),e.material.dispose()),null))}},[v,_,e,c,l,f,p,m,h.isSuccess]),(0,n.createPortal)((0,r.jsx)(`group`,{children:y&&(0,r.jsx)(`primitive`,{object:y})}),_)},p=({latitude:e,longitude:a,altitude:o=0,isBillboard:s=!0,onAttach:c,onGpsUpdate:l,children:d})=>{let f=u(),p=(0,t.useRef)(f);p.current=f;let{camera:m}=(0,n.useThree)(),[h]=(0,t.useState)(()=>new i.Group),g=(0,t.useMemo)(()=>Math.random().toString(36).slice(2,11),[]),_=(0,t.useCallback)(()=>{c?.()},[c]),v=(0,t.useCallback)((e,t)=>{l?.(e,t)},[l]);return(0,t.useEffect)(()=>{if(f.isSuccess)return p.current.registerAnchor(g,{anchor:h,isAttached:!1,latitude:e,longitude:a,altitude:o,onAttach:_,onGpsUpdate:v}),()=>{p.current.unregisterAnchor(g)}},[h,g,e,a,o,_,v,f.isSuccess]),(0,n.useFrame)(()=>{!s||!m||!f.isSuccess||f.getAnchor(g)?.isAttached&&h.lookAt(m.position)}),(0,n.createPortal)((0,r.jsx)(`group`,{children:d}),h)},m=({options:r={},children:i})=>{let{scene:a,camera:o,gl:s}=(0,n.useThree)(),{registerBackend:c,unregisterBackend:l}=e.r(),u=(0,t.useRef)(null),d=(0,t.useRef)(r);return d.current=r,(0,t.useEffect)(()=>{if(u.current)return;let e=!1;return(async()=>{try{let t=_(d.current);if(e)return;await c(t,{scene:a,camera:o,renderer:s}),u.current=t}catch(e){console.error(`[GeolocationSession] Failed to initialize:`,e)}})(),()=>{e=!0,u.current&&=(l(u.current),null)}},[a,o,s,c,l]),i},h={front:i.FrontSide,back:i.BackSide,double:i.DoubleSide},g=({coordinates:e,holes:a,color:o=`#ff0000`,opacity:s=1,isWireframe:c=!1,side:l=`double`})=>{let d=u(),f=(0,t.useRef)(d);f.current=d;let[p]=(0,t.useState)(()=>new i.Group),m=(0,t.useMemo)(()=>Math.random().toString(36).slice(2,11),[]),[g,_]=(0,t.useState)(null);return(0,t.useEffect)(()=>{if(!d.isSuccess||e.length<3)return;let[t,n,r=0]=e[0];return f.current.registerAnchor(m,{anchor:p,isAttached:!1,latitude:n,longitude:t,altitude:r,onAttach:t=>{let[n,r,o=0]=e[0],[s,c]=t.lonLatToWorldCoords(n,r),l=[];for(let[n,r,i=0]of e){let[e,a]=t.lonLatToWorldCoords(n,r);l.push({x:e-s,z:a-c,elev:i-o})}let u=new i.Shape;u.moveTo(l[0].x,l[0].z);for(let e=1;e<l.length;e++)u.lineTo(l[e].x,l[e].z);if(u.closePath(),a&&a.length>0)for(let e of a){if(e.length<3)continue;let n=new i.Path,[r,a]=e[0],[o,l]=t.lonLatToWorldCoords(r,a);n.moveTo(o-s,l-c);for(let r=1;r<e.length;r++){let[i,a]=e[r],[o,l]=t.lonLatToWorldCoords(i,a);n.lineTo(o-s,l-c)}n.closePath(),u.holes.push(n)}let d=new i.ShapeGeometry(u),f=l.reduce((e,t)=>e+t.elev,0)/l.length;d.rotateX(-Math.PI/2),_({geometry:d,avgElevation:f})}}),()=>{f.current.unregisterAnchor(m),_(e=>(e&&e.geometry.dispose(),null))}},[m,p,e,a,d.isSuccess]),(0,n.createPortal)((0,r.jsx)(`group`,{children:g&&(0,r.jsx)(`group`,{position:[0,g.avgElevation,0],children:(0,r.jsx)(`mesh`,{geometry:g.geometry,children:(0,r.jsx)(`meshBasicMaterial`,{color:o,opacity:s,transparent:s<1,wireframe:c,side:h[l]})})})}),p)},_=t=>{let n=null,r=null,i,a=null,o=null,s=null,l=null,u=new Map,d=null,f=e=>{if(!(!r||e.isAttached))try{r.add(e.anchor,e.longitude,e.latitude,e.altitude),e.isAttached=!0,e.onAttach?.(r)}catch(e){console.error(`❌ Failed to attach anchor:`,e)}},p=(e,t)=>{u.set(e,t),d!==null&&!t.isAttached&&(f(t),t.onGpsUpdate?.(d,0))},m=e=>{let t=u.get(e);if(t?.isAttached)try{t.anchor.removeFromParent()}catch(t){console.error(`⚠️ Error removing anchor ${e}:`,t)}u.delete(e)},h=e=>u.get(e);return{type:e.i.GEOLOCATION,async init(e){let{camera:p,renderer:m,scene:h}=e;if(!h)throw Error(`[geolocationBackend] A THREE.Scene is required for location-based AR`);o=p,s=m,l=h,n=new c.App({threeObjects:{camera:p,renderer:m,scene:h},videoConstraints:t?.webcamConstraints??{video:{facingMode:`environment`}},deviceOrientationOptions:{enabled:!0}}),m.setClearAlpha?.(0),a=e=>{d=e.position;for(let t of u.values())t.isAttached||f(t),t.onGpsUpdate?.(e.position,e.distMoved);t?.onGpsUpdate?.(e.position,e.distMoved)},r=await n.start();let g=n.deviceOrientationControls;if(g&&g.orientationChangeEventName!==`deviceorientation`)try{g.disconnect(),g.orientationChangeEventName=`deviceorientation`,g.connect()}catch(e){console.error(`[geolocationBackend] failed to rebind device orientation event:`,e)}r.on(`gpsupdate`,a),n.webcam?.on?.(`webcamerror`,e=>{console.error(`[geolocationBackend] webcam error:`,e)}),n.deviceOrientationControls?.on?.(`deviceorientationerror`,e=>{console.error(`[geolocationBackend] Device orientation error:`,e)}),r.on(`gpserror`,e=>{console.error(`[geolocationBackend] gps error:`,e)}),r.startGps(),typeof t?.fakeLat==`number`&&typeof t?.fakeLon==`number`&&r.fakeGps(t.fakeLon,t.fakeLat);let _=r.getLastKnownLocation();_!==null&&(d={coords:{longitude:_.longitude,latitude:_.latitude,accuracy:0,altitude:null,altitudeAccuracy:null,heading:null,speed:null,toJSON:()=>_},timestamp:Date.now(),toJSON:()=>_});let v=()=>{if(!s||!o)return;let e=window.innerWidth,t=window.innerHeight;s.setSize(e,t,!1),o.aspect=e/t,o.updateProjectionMatrix?.()};v(),window.addEventListener(`resize`,v),i=v},update(){n?.deviceOrientationControls?.update?.()},dispose(){r&&a&&r.off(`gpsupdate`,a),r?.stopGps?.(),n?.webcam?.dispose?.(),s?.setClearAlpha?.(1),n?.deviceOrientationControls?.dispose?.(),i&&=(window.removeEventListener(`resize`,i),void 0);for(let e of u.values())if(e.isAttached)try{e.anchor.removeFromParent()}catch(e){console.error(`⚠️ Error removing anchor:`,e)}u.clear(),n=null,r=null,o=null,s=null,l=null,a=null,d=null},getInternal:()=>({locar:r,webcam:n?.webcam??null,deviceOrientation:n?.deviceOrientationControls??null,scene:l,camera:o,lastPosition:d,registerAnchor:p,unregisterAnchor:m,getAnchor:h})}};Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return _}});
@@ -6,9 +6,9 @@ import { BackSide as d, BufferAttribute as f, BufferGeometry as p, DoubleSide as
6
6
  import { Line2 as C } from "three/addons/lines/Line2.js";
7
7
  import { LineGeometry as w } from "three/addons/lines/LineGeometry.js";
8
8
  import { LineMaterial as T } from "three/addons/lines/LineMaterial.js";
9
- import { DeviceOrientationControls as E, LocAR as D, Webcam as O } from "locar";
9
+ import { App as E } from "locar";
10
10
  //#region src/geolocation/useGeolocationBackend.ts
11
- var k = {
11
+ var D = {
12
12
  isPending: !0,
13
13
  isSuccess: !1,
14
14
  locar: null,
@@ -20,14 +20,14 @@ var k = {
20
20
  registerAnchor: () => {},
21
21
  unregisterAnchor: () => {},
22
22
  getAnchor: () => void 0
23
- }, A = () => {
23
+ }, O = () => {
24
24
  let n = t((e) => e.backends).get(e.GEOLOCATION);
25
25
  return n ? {
26
26
  ...n.getInternal(),
27
27
  isPending: !1,
28
28
  isSuccess: !0
29
- } : k;
30
- }, j = (e, t) => {
29
+ } : D;
30
+ }, k = (e, t) => {
31
31
  let n = e.length - 1, r = [], i = 0, a = 0;
32
32
  for (let o = 0; o < n; o++) {
33
33
  let n = e[o + 1].x - e[o].x, s = e[o + 1].y - e[o].y, c = e[o + 1].z - e[o].z, l = Math.sqrt(n * n + s * s + c * c), u = t / 2, d = -(c * u) / l, f = n * u / l, p = o > 0 ? (d + i) / 2 : d, m = o > 0 ? (f + a) / 2 : f;
@@ -38,8 +38,8 @@ var k = {
38
38
  for (let e = 0; e < n; e++) o.push(e * 2, e * 2 + 1, e * 2 + 2), o.push(e * 2 + 1, e * 2 + 3, e * 2 + 2);
39
39
  let s = new p();
40
40
  return s.setIndex(o), s.setAttribute("position", new f(new Float32Array(r), 3)), s.computeBoundingBox(), s;
41
- }, M = ({ coordinates: e, color: t = "#ff0000", isDashed: n = !1, dashSize: c = 3, gapSize: l = 1, lineWidth: d = 1 }) => {
42
- let f = A(), p = a(f);
41
+ }, A = ({ coordinates: e, color: t = "#ff0000", isDashed: n = !1, dashSize: c = 3, gapSize: l = 1, lineWidth: d = 1 }) => {
42
+ let f = O(), p = a(f);
43
43
  p.current = f;
44
44
  let [h] = o(() => new g()), y = i(() => Math.random().toString(36).slice(2, 11), []), [b, x] = o(null);
45
45
  return r(() => {
@@ -66,7 +66,7 @@ var k = {
66
66
  linewidth: d
67
67
  }));
68
68
  e.computeLineDistances(), x(e);
69
- } else x(new _(j(f, d), new v({
69
+ } else x(new _(k(f, d), new v({
70
70
  color: t,
71
71
  side: m
72
72
  })));
@@ -85,8 +85,8 @@ var k = {
85
85
  d,
86
86
  f.isSuccess
87
87
  ]), s(/* @__PURE__ */ u("group", { children: b && /* @__PURE__ */ u("primitive", { object: b }) }), h);
88
- }, N = ({ latitude: e, longitude: t, altitude: d = 0, isBillboard: f = !0, onAttach: p, onGpsUpdate: m, children: h }) => {
89
- let _ = A(), v = a(_);
88
+ }, j = ({ latitude: e, longitude: t, altitude: d = 0, isBillboard: f = !0, onAttach: p, onGpsUpdate: m, children: h }) => {
89
+ let _ = O(), v = a(_);
90
90
  v.current = _;
91
91
  let { camera: y } = l(), [b] = o(() => new g()), x = i(() => Math.random().toString(36).slice(2, 11), []), S = n(() => {
92
92
  p?.();
@@ -117,14 +117,14 @@ var k = {
117
117
  ]), c(() => {
118
118
  !f || !y || !_.isSuccess || _.getAnchor(x)?.isAttached && b.lookAt(y.position);
119
119
  }), s(/* @__PURE__ */ u("group", { children: h }), b);
120
- }, P = ({ options: e = {}, children: n }) => {
120
+ }, M = ({ options: e = {}, children: n }) => {
121
121
  let { scene: i, camera: o, gl: s } = l(), { registerBackend: c, unregisterBackend: u } = t(), d = a(null), f = a(e);
122
122
  return f.current = e, r(() => {
123
123
  if (d.current) return;
124
124
  let e = !1;
125
125
  return (async () => {
126
126
  try {
127
- let t = L(f.current);
127
+ let t = F(f.current);
128
128
  if (e) return;
129
129
  await c(t, {
130
130
  scene: i,
@@ -144,12 +144,12 @@ var k = {
144
144
  c,
145
145
  u
146
146
  ]), n;
147
- }, F = {
147
+ }, N = {
148
148
  front: h,
149
149
  back: d,
150
150
  double: m
151
- }, I = ({ coordinates: e, holes: t, color: n = "#ff0000", opacity: c = 1, isWireframe: l = !1, side: d = "double" }) => {
152
- let f = A(), p = a(f);
151
+ }, P = ({ coordinates: e, holes: t, color: n = "#ff0000", opacity: c = 1, isWireframe: l = !1, side: d = "double" }) => {
152
+ let f = O(), p = a(f);
153
153
  p.current = f;
154
154
  let [m] = o(() => new g()), h = i(() => Math.random().toString(36).slice(2, 11), []), [_, v] = o(null);
155
155
  return r(() => {
@@ -212,104 +212,105 @@ var k = {
212
212
  opacity: c,
213
213
  transparent: c < 1,
214
214
  wireframe: l,
215
- side: F[d]
215
+ side: N[d]
216
216
  })
217
217
  })
218
218
  }) }), m);
219
- }, L = (t) => {
220
- let n = null, r = null, i = null, a, o = null, s = null, c = null, l = null, u = null, d = /* @__PURE__ */ new Map(), f = null, p = (e) => {
221
- if (!(!n || e.isAttached)) try {
222
- n.add(e.anchor, e.longitude, e.latitude, e.altitude), e.isAttached = !0, e.onAttach?.(n);
219
+ }, F = (t) => {
220
+ let n = null, r = null, i, a = null, o = null, s = null, c = null, l = /* @__PURE__ */ new Map(), u = null, d = (e) => {
221
+ if (!(!r || e.isAttached)) try {
222
+ r.add(e.anchor, e.longitude, e.latitude, e.altitude), e.isAttached = !0, e.onAttach?.(r);
223
223
  } catch (e) {
224
224
  console.error("❌ Failed to attach anchor:", e);
225
225
  }
226
- }, m = (e, t) => {
227
- d.set(e, t), f !== null && !t.isAttached && (p(t), t.onGpsUpdate?.(f, 0));
228
- }, h = (e) => {
229
- let t = d.get(e);
226
+ }, f = (e, t) => {
227
+ l.set(e, t), u !== null && !t.isAttached && (d(t), t.onGpsUpdate?.(u, 0));
228
+ }, p = (e) => {
229
+ let t = l.get(e);
230
230
  if (t?.isAttached) try {
231
231
  t.anchor.removeFromParent();
232
232
  } catch (t) {
233
233
  console.error(`⚠️ Error removing anchor ${e}:`, t);
234
234
  }
235
- d.delete(e);
236
- }, g = (e) => d.get(e);
235
+ l.delete(e);
236
+ }, m = (e) => l.get(e);
237
237
  return {
238
238
  type: e.GEOLOCATION,
239
239
  async init(e) {
240
- let { camera: m, renderer: h, scene: g } = e;
241
- if (!g) throw Error("[geolocationBackend] A THREE.Scene is required for location-based AR");
242
- c = m, l = h, u = g, n = new D(g, m), h.setClearAlpha?.(0);
243
- let _ = new Set(document.querySelectorAll("video"));
244
- r = new O(t?.webcamConstraints ?? { video: { facingMode: "environment" } });
245
- for (let e of document.querySelectorAll("video")) if (!_.has(e)) {
246
- o = e;
247
- break;
248
- }
249
- s = (e) => {
250
- f = e.position;
251
- for (let t of d.values()) t.isAttached || p(t), t.onGpsUpdate?.(e.position, e.distMoved);
240
+ let { camera: f, renderer: p, scene: m } = e;
241
+ if (!m) throw Error("[geolocationBackend] A THREE.Scene is required for location-based AR");
242
+ o = f, s = p, c = m, n = new E({
243
+ threeObjects: {
244
+ camera: f,
245
+ renderer: p,
246
+ scene: m
247
+ },
248
+ videoConstraints: t?.webcamConstraints ?? { video: { facingMode: "environment" } },
249
+ deviceOrientationOptions: { enabled: !0 }
250
+ }), p.setClearAlpha?.(0), a = (e) => {
251
+ u = e.position;
252
+ for (let t of l.values()) t.isAttached || d(t), t.onGpsUpdate?.(e.position, e.distMoved);
252
253
  t?.onGpsUpdate?.(e.position, e.distMoved);
253
- }, n.on("gpsupdate", s), r.on("webcamerror", (e) => {
254
+ }, r = await n.start();
255
+ let h = n.deviceOrientationControls;
256
+ if (h && h.orientationChangeEventName !== "deviceorientation") try {
257
+ h.disconnect(), h.orientationChangeEventName = "deviceorientation", h.connect();
258
+ } catch (e) {
259
+ console.error("[geolocationBackend] failed to rebind device orientation event:", e);
260
+ }
261
+ r.on("gpsupdate", a), n.webcam?.on?.("webcamerror", (e) => {
254
262
  console.error("[geolocationBackend] webcam error:", e);
255
- }), i = new E(m), i.on("deviceorientationgranted", (e) => {
256
- e.target?.connect?.();
257
- }), i.on("deviceorientationerror", (e) => {
263
+ }), n.deviceOrientationControls?.on?.("deviceorientationerror", (e) => {
258
264
  console.error("[geolocationBackend] Device orientation error:", e);
259
- }), i.init?.(), n.on("gpserror", (e) => {
265
+ }), r.on("gpserror", (e) => {
260
266
  console.error("[geolocationBackend] gps error:", e);
261
- }), n.startGps(), typeof t?.fakeLat == "number" && typeof t?.fakeLon == "number" && n.fakeGps(t.fakeLon, t.fakeLat);
262
- let v = n.getLastKnownLocation();
263
- v !== null && (f = {
267
+ }), r.startGps(), typeof t?.fakeLat == "number" && typeof t?.fakeLon == "number" && r.fakeGps(t.fakeLon, t.fakeLat);
268
+ let g = r.getLastKnownLocation();
269
+ g !== null && (u = {
264
270
  coords: {
265
- longitude: v.longitude,
266
- latitude: v.latitude,
271
+ longitude: g.longitude,
272
+ latitude: g.latitude,
267
273
  accuracy: 0,
268
274
  altitude: null,
269
275
  altitudeAccuracy: null,
270
276
  heading: null,
271
277
  speed: null,
272
- toJSON: () => v
278
+ toJSON: () => g
273
279
  },
274
280
  timestamp: Date.now(),
275
- toJSON: () => v
281
+ toJSON: () => g
276
282
  });
277
- let y = () => {
278
- if (!l || !c) return;
283
+ let _ = () => {
284
+ if (!s || !o) return;
279
285
  let e = window.innerWidth, t = window.innerHeight;
280
- l.setSize(e, t, !1), c.aspect = e / t, c.updateProjectionMatrix?.();
286
+ s.setSize(e, t, !1), o.aspect = e / t, o.updateProjectionMatrix?.();
281
287
  };
282
- y(), window.addEventListener("resize", y), a = y;
288
+ _(), window.addEventListener("resize", _), i = _;
283
289
  },
284
290
  update() {
285
- i?.update?.();
291
+ n?.deviceOrientationControls?.update?.();
286
292
  },
287
293
  dispose() {
288
- if (n && s && n.off("gpsupdate", s), n?.stopGps?.(), o) {
289
- let e = o.srcObject;
290
- for (let t of e?.getTracks() ?? []) t.stop();
291
- o.srcObject = null, o.remove(), o = null;
292
- }
293
- l?.setClearAlpha?.(1), i?.dispose?.(), a &&= (window.removeEventListener("resize", a), void 0);
294
- for (let e of d.values()) if (e.isAttached) try {
294
+ r && a && r.off("gpsupdate", a), r?.stopGps?.(), n?.webcam?.dispose?.(), s?.setClearAlpha?.(1), n?.deviceOrientationControls?.dispose?.(), i &&= (window.removeEventListener("resize", i), void 0);
295
+ for (let e of l.values()) if (e.isAttached) try {
295
296
  e.anchor.removeFromParent();
296
297
  } catch (e) {
297
298
  console.error("⚠️ Error removing anchor:", e);
298
299
  }
299
- d.clear(), n = null, r = null, i = null, c = null, l = null, u = null, s = null, f = null;
300
+ l.clear(), n = null, r = null, o = null, s = null, c = null, a = null, u = null;
300
301
  },
301
302
  getInternal: () => ({
302
- locar: n,
303
- webcam: r,
304
- deviceOrientation: i,
305
- scene: u,
306
- camera: c,
307
- lastPosition: f,
308
- registerAnchor: m,
309
- unregisterAnchor: h,
310
- getAnchor: g
303
+ locar: r,
304
+ webcam: n?.webcam ?? null,
305
+ deviceOrientation: n?.deviceOrientationControls ?? null,
306
+ scene: c,
307
+ camera: o,
308
+ lastPosition: u,
309
+ registerAnchor: f,
310
+ unregisterAnchor: p,
311
+ getAnchor: m
311
312
  })
312
313
  };
313
314
  };
314
315
  //#endregion
315
- export { M as a, N as i, I as n, A as o, P as r, L as t };
316
+ export { A as a, j as i, P as n, O as o, M as r, F as t };
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./useXRStore-8Vl3wsP5.cjs`);const e=require(`./geolocation-D_rCGA-C.cjs`);exports.GeoLine=e.a,exports.GeoPolygon=e.n,exports.GeolocationAnchor=e.i,exports.GeolocationSession=e.r,exports.createGeolocationBackend=e.t,exports.useGeolocationBackend=e.o;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./useXRStore-8Vl3wsP5.cjs`);const e=require(`./geolocation-CT1kLdSh.cjs`);exports.GeoLine=e.a,exports.GeoPolygon=e.n,exports.GeolocationAnchor=e.i,exports.GeolocationSession=e.r,exports.createGeolocationBackend=e.t,exports.useGeolocationBackend=e.o;
@@ -1,3 +1,3 @@
1
1
  import "./useXRStore-Dsm1C1fI.js";
2
- import { a as e, i as t, n, o as r, r as i, t as a } from "./geolocation-DqxybM8d.js";
2
+ import { a as e, i as t, n, o as r, r as i, t as a } from "./geolocation-Dl910ZC5.js";
3
3
  export { e as GeoLine, n as GeoPolygon, t as GeolocationAnchor, i as GeolocationSession, a as createGeolocationBackend, r as useGeolocationBackend };
package/build/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./useXRStore-8Vl3wsP5.cjs`),t=require(`./fiducial-DdfnVsvF.cjs`),n=require(`./geolocation-D_rCGA-C.cjs`),r=require(`./immersive-DKHCJlkN.cjs`),i=require(`./magic-CWhj_WTi.cjs`),a=require(`./vision-CRUCg7uc.cjs`);let o=require(`@react-three/fiber`);var s=({children:t})=>{let{updateBackends:n}=e.r();return(0,o.useFrame)((e,t)=>{n(t)}),t};exports.BACKEND_TYPES=e.i,exports.COCO_LABELS=a.c,exports.CameraBackground=a.S,exports.DEFAULT_GESTURES=a.g,exports.FiducialAnchor=t.r,exports.FiducialSession=t.n,exports.GeoLine=n.a,exports.GeoPolygon=n.n,exports.GeolocationAnchor=n.i,exports.GeolocationSession=n.r,exports.HandTracker=a.d,exports.ImmersiveSession=r.t,exports.MagicSession=i.n,exports.VisionAnchor=a.o,exports.VisionDebug=a.a,exports.VisionOverlay=a.t,exports.VisionSession=a.r,exports.VisionStatus=a.n,exports.WorldAnchor=i.t,exports.XR=s,exports.createFiducialBackend=t.t,exports.createGeolocationBackend=n.t,exports.createMagicBackend=i.r,exports.createVisionBackend=a.i,exports.detectGesture=a.h,exports.fist=a._,exports.getXRStore=e.t,exports.landmarkToWorld=a.p,exports.landmarksCentroid=a.m,exports.ok=a.v,exports.openHand=a.y,exports.peace=a.b,exports.rfDetr=a.l,exports.subscribeToXRStore=e.n,exports.thumbsUp=a.x,exports.useFiducialBackend=t.i,exports.useGeolocationBackend=n.o,exports.useVisionBackend=a.f,exports.useVisionFrame=a.s,exports.useXRStore=e.r,exports.yolo=a.u;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./useXRStore-8Vl3wsP5.cjs`),t=require(`./fiducial-DdfnVsvF.cjs`),n=require(`./geolocation-CT1kLdSh.cjs`),r=require(`./immersive-DKHCJlkN.cjs`),i=require(`./magic-CWhj_WTi.cjs`),a=require(`./vision-sMKG7-na.cjs`);let o=require(`@react-three/fiber`);var s=({children:t})=>{let{updateBackends:n}=e.r();return(0,o.useFrame)((e,t)=>{n(t)}),t};exports.BACKEND_TYPES=e.i,exports.COCO_LABELS=a.c,exports.CameraBackground=a.C,exports.DEFAULT_GESTURES=a._,exports.FiducialAnchor=t.r,exports.FiducialSession=t.n,exports.GeoLine=n.a,exports.GeoPolygon=n.n,exports.GeolocationAnchor=n.i,exports.GeolocationSession=n.r,exports.HandTracker=a.f,exports.ImmersiveSession=r.t,exports.MagicSession=i.n,exports.VisionAnchor=a.o,exports.VisionDebug=a.a,exports.VisionOverlay=a.t,exports.VisionSession=a.r,exports.VisionStatus=a.n,exports.WorldAnchor=i.t,exports.XR=s,exports.createFiducialBackend=t.t,exports.createGeolocationBackend=n.t,exports.createMagicBackend=i.r,exports.createVisionBackend=a.i,exports.detectGesture=a.g,exports.fist=a.v,exports.getXRStore=e.t,exports.landmarkToWorld=a.m,exports.landmarksCentroid=a.h,exports.ok=a.y,exports.openHand=a.b,exports.peace=a.x,exports.rfDetr=a.l,exports.subscribeToXRStore=e.n,exports.thumbsUp=a.S,exports.useFiducialBackend=t.i,exports.useGeolocationBackend=n.o,exports.useVisionBackend=a.p,exports.useVisionFrame=a.s,exports.useXRStore=e.r,exports.yolo=a.u,exports.yoloSeg=a.d;
package/build/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import { i as e, n as t, r as n, t as r } from "./useXRStore-Dsm1C1fI.js";
2
2
  import { i, n as a, r as o, t as s } from "./fiducial-Bi9lhbyN.js";
3
- import { a as c, i as l, n as u, o as d, r as f, t as p } from "./geolocation-DqxybM8d.js";
3
+ import { a as c, i as l, n as u, o as d, r as f, t as p } from "./geolocation-Dl910ZC5.js";
4
4
  import { t as m } from "./immersive-BTwiipnT.js";
5
5
  import { n as h, r as g, t as _ } from "./magic-CPIBm_8-.js";
6
- import { S as v, _ as y, a as b, b as x, c as S, d as C, f as w, g as T, h as E, i as D, l as O, m as k, n as A, o as j, p as M, r as N, s as P, t as F, u as I, v as L, x as R, y as z } from "./vision-BKOfvNSR.js";
7
- import { useFrame as B } from "@react-three/fiber";
6
+ import { C as v, S as y, _ as b, a as x, b as S, c as C, d as w, f as T, g as E, h as D, i as O, l as k, m as A, n as j, o as M, p as N, r as P, s as F, t as I, u as L, v as R, x as z, y as B } from "./vision-Bdhf3N-w.js";
7
+ import { useFrame as V } from "@react-three/fiber";
8
8
  //#region src/engine/XR.tsx
9
- var V = ({ children: e }) => {
9
+ var H = ({ children: e }) => {
10
10
  let { updateBackends: t } = n();
11
- return B((e, n) => {
11
+ return V((e, n) => {
12
12
  t(n);
13
13
  }), e;
14
14
  };
15
15
  //#endregion
16
- export { e as BACKEND_TYPES, S as COCO_LABELS, v as CameraBackground, T as DEFAULT_GESTURES, o as FiducialAnchor, a as FiducialSession, c as GeoLine, u as GeoPolygon, l as GeolocationAnchor, f as GeolocationSession, C as HandTracker, m as ImmersiveSession, h as MagicSession, j as VisionAnchor, b as VisionDebug, F as VisionOverlay, N as VisionSession, A as VisionStatus, _ as WorldAnchor, V as XR, s as createFiducialBackend, p as createGeolocationBackend, g as createMagicBackend, D as createVisionBackend, E as detectGesture, y as fist, r as getXRStore, M as landmarkToWorld, k as landmarksCentroid, L as ok, z as openHand, x as peace, O as rfDetr, t as subscribeToXRStore, R as thumbsUp, i as useFiducialBackend, d as useGeolocationBackend, w as useVisionBackend, P as useVisionFrame, n as useXRStore, I as yolo };
16
+ export { e as BACKEND_TYPES, C as COCO_LABELS, v as CameraBackground, b as DEFAULT_GESTURES, o as FiducialAnchor, a as FiducialSession, c as GeoLine, u as GeoPolygon, l as GeolocationAnchor, f as GeolocationSession, T as HandTracker, m as ImmersiveSession, h as MagicSession, M as VisionAnchor, x as VisionDebug, I as VisionOverlay, P as VisionSession, j as VisionStatus, _ as WorldAnchor, H as XR, s as createFiducialBackend, p as createGeolocationBackend, g as createMagicBackend, O as createVisionBackend, E as detectGesture, R as fist, r as getXRStore, A as landmarkToWorld, D as landmarksCentroid, B as ok, S as openHand, z as peace, k as rfDetr, t as subscribeToXRStore, y as thumbsUp, i as useFiducialBackend, d as useGeolocationBackend, N as useVisionBackend, F as useVisionFrame, n as useXRStore, L as yolo, w as yoloSeg };
@@ -2,7 +2,7 @@ export { default as CameraBackground } from './CameraBackground';
2
2
  export { DEFAULT_GESTURES, detectGesture, fist, ok, openHand, peace, thumbsUp, } from './gestures';
3
3
  export { default as HandTracker } from './HandTracker';
4
4
  export { landmarksCentroid, landmarkToWorld } from './landmarkMapping';
5
- export { COCO_LABELS, rfDetr, yolo } from './presets';
5
+ export { COCO_LABELS, rfDetr, yolo, yoloSeg } from './presets';
6
6
  export { default as useVisionBackend } from './useVisionBackend';
7
7
  export { default as useVisionFrame } from './useVisionFrame';
8
8
  export { default as VisionAnchor } from './VisionAnchor';
@@ -16,7 +16,7 @@ export type { GestureDetector, GestureResult } from './gestures';
16
16
  export type { HandTrackerProps } from './HandTracker';
17
17
  export type { FrameSize, Viewport } from './landmarkMapping';
18
18
  export type { PresetOverrides } from './presets';
19
- export type { LandmarkDetection, ObjectDetection, ONNXDecoderName, ONNXModelConfig, VisionFrame, VisionLandmark, VisionProgress, VisionProvider, VisionSessionOptions, VisionTask, } from './types';
19
+ export type { LandmarkDetection, ObjectDetection, ONNXDecoderName, ONNXModelConfig, SegmentationMask, VisionFrame, VisionLandmark, VisionProgress, VisionProvider, VisionSessionOptions, VisionTask, } from './types';
20
20
  export type { UseVisionFrameOptions } from './useVisionFrame';
21
21
  export type { VisionAnchorProps } from './VisionAnchor';
22
22
  export type { VisionDebugProps } from './VisionDebug';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vision/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,IAAI,EACJ,EAAE,EACF,QAAQ,EACR,KAAK,EACL,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEjE,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,YAA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,gBAAgB,CAAC;AACxD,YAAY,EACV,kBAAkB,EAClB,cAAc,GACf,MAAM,iBAAiB,CAAC"}
@@ -22,4 +22,13 @@ export declare const yolo: (path: string, overrides?: PresetOverrides) => ONNXMo
22
22
  * Weights are not bundled.
23
23
  */
24
24
  export declare const rfDetr: (path: string, overrides?: PresetOverrides) => ONNXModelConfig;
25
+ /**
26
+ * Build a config for a YOLOv8/v11-**seg** instance-segmentation model. Expects a
27
+ * `[1, 4 + numClasses + M, numAnchors]` detection output and a
28
+ * `[1, M, protoH, protoW]` prototype output; produces per-instance masks.
29
+ *
30
+ * @param path URL or same-origin path to the exported `.onnx` weights
31
+ * (e.g. from `yolo export format=onnx` on a `-seg` model). Weights are not bundled.
32
+ */
33
+ export declare const yoloSeg: (path: string, overrides?: PresetOverrides) => ONNXModelConfig;
25
34
  //# sourceMappingURL=presets.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../../src/vision/presets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,WAAW,w2BAiFd,CAAC;AAEX,iEAAiE;AACjE,MAAM,MAAM,eAAe,GAAG,OAAO,CACnC,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC,CAC1C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,IAAI,GACf,MAAM,MAAM,EACZ,YAAW,eAAoB,KAC9B,eAOD,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,GACjB,MAAM,MAAM,EACZ,YAAW,eAAoB,KAC9B,eAOD,CAAC"}
1
+ {"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../../src/vision/presets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,WAAW,w2BAiFd,CAAC;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CAAC,mBAAmB;IAwC3B,OAAO,CAAC,YAAY;CA6BrB;AAED,eAAe,YAAY,CAAC"}
@@ -20,12 +20,30 @@ export type ObjectDetection = {
20
20
  height: number;
21
21
  };
22
22
  };
23
+ /** A per-instance segmentation mask, cropped to its bounding box */
24
+ export type SegmentationMask = {
25
+ label: string;
26
+ confidence: number;
27
+ /** Bounding box in source pixel coordinates */
28
+ bbox: {
29
+ x: number;
30
+ y: number;
31
+ width: number;
32
+ height: number;
33
+ };
34
+ /** Row-major alpha values (0-255) covering the bbox, sized maskWidth x maskHeight */
35
+ mask: Uint8Array;
36
+ maskWidth: number;
37
+ maskHeight: number;
38
+ };
23
39
  /** A single frame of vision detection results */
24
40
  export type VisionFrame = {
25
41
  hands: LandmarkDetection[];
26
42
  faces: LandmarkDetection[];
27
43
  poses: LandmarkDetection[];
28
44
  objects: ObjectDetection[];
45
+ /** Per-instance segmentation masks (present when a segmentation model runs) */
46
+ masks?: SegmentationMask[];
29
47
  timestamp: number;
30
48
  frameSize: {
31
49
  width: number;
@@ -37,7 +55,7 @@ export type VisionFrame = {
37
55
  /** Supported vision tasks */
38
56
  export type VisionTask = "hands" | "faces" | "poses" | "objects";
39
57
  /** Identifier of a registered ONNX output decoder */
40
- export type ONNXDecoderName = "yolo" | "rfdetr";
58
+ export type ONNXDecoderName = "yolo" | "rfdetr" | "yoloseg";
41
59
  /** ONNX model configuration */
42
60
  export type ONNXModelConfig = {
43
61
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/vision/types.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,MAAM,MAAM,cAAc,GAAG;IAC3B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAEF,oEAAoE;AACpE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,cAAc,EAAE,CAAC;IAC5B,UAAU,EAA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c,GAAG,IAAI,KAAK,IAAI,CAAC;IACvD,4BAA4B;IAC5B,IAAI,CAAC,EAAE;QACL,MAAM,EAAE,eAAe,EAAE,CAAC;KAC3B,CAAC;CACH,CAAC;AAEF,gCAAgC;AAChC,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,cAAc,IAAI,IAAI,CAAC;IACvB,aAAa,IAAI,IAAI,CAAC;IACtB,WAAW,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAChE,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC"}
@@ -2,5 +2,5 @@ import { ONNXDecoderName } from '../../types';
2
2
  import { ONNXDecoder } from './types';
3
3
  /** Resolve a decoder by name, defaulting to YOLO */
4
4
  export declare const getDecoder: (name?: ONNXDecoderName) => ONNXDecoder;
5
- export type { DecodeContext, ONNXDecoder, TensorLike } from './types';
5
+ export type { DecodeContext, DecodeResult, ONNXDecoder, TensorLike, } from './types';
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/vision/worker/decoders/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAQ3C,oDAAoD;AACpD,eAAO,MAAM,UAAU,GAAI,OAAM,eAAwB,KAAG,WAC7B,CAAC;AAEhC,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/vision/worker/decoders/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAS3C,oDAAoD;AACpD,eAAO,MAAM,UAAU,GAAI,OAAM,eAAwB,KAAG,WAC7B,CAAC;AAEhC,YAAY,EACV,aAAa,EACb,YAAY,EACZ,WAAW,EACX,UAAU,GACX,MAAM,SAAS,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"rfDetr.d.ts","sourceRoot":"","sources":["../../../../src/vision/worker/decoders/rfDetr.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAiB,WAAW,EAAc,MAAM,SAAS,CAAC;AAoBtE;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,EAAE,WAyD3B,CAAC"}
1
+ {"version":3,"file":"rfDetr.d.ts","sourceRoot":"","sources":["../../../../src/vision/worker/decoders/rfDetr.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAGV,WAAW,EAEZ,MAAM,SAAS,CAAC;AAoBjB;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,EAAE,WA2D3B,CAAC"}
@@ -1,4 +1,4 @@
1
- import { ObjectDetection } from '../../types';
1
+ import { ObjectDetection, SegmentationMask } from '../../types';
2
2
  /**
3
3
  * Minimal structural view of an onnxruntime-web tensor. Decoders depend on this
4
4
  * rather than the ort types so they stay pure and unit-testable with fixtures.
@@ -29,12 +29,17 @@ export type DecodeContext = {
29
29
  /** Maximum detections to return */
30
30
  maxResults: number;
31
31
  };
32
+ /** Output of a decoder: detections and/or per-instance segmentation masks */
33
+ export type DecodeResult = {
34
+ objects?: ObjectDetection[];
35
+ masks?: SegmentationMask[];
36
+ };
32
37
  /**
33
- * Interprets a model's raw output tensors into detections in source pixel
38
+ * Interprets a model's raw output tensors into detections/masks in source pixel
34
39
  * coordinates. Register concrete decoders by {@link import("../../types").ONNXDecoderName}.
35
40
  */
36
41
  export type ONNXDecoder = {
37
42
  readonly name: string;
38
- decode(outputs: Record<string, TensorLike>, ctx: DecodeContext): ObjectDetection[];
43
+ decode(outputs: Record<string, TensorLike>, ctx: DecodeContext): DecodeResult;
39
44
  };
40
45
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/vision/worker/decoders/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,YAAY,GAAG,MAAM,EAAE,CAAC;IAC9B,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,qFAAqF;IACrF,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,6CAA6C;IAC7C,aAAa,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,MAAM,CACJ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,EACnC,GAAG,EAAE,aAAa,GACjB,eAAe,EAAE,CAAC;CACtB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/vision/worker/decoders/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAErE;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,YAAY,GAAG,MAAM,EAAE,CAAC;IAC9B,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,qFAAqF;IACrF,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,6CAA6C;IAC7C,aAAa,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,6EAA6E;AAC7E,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAC5B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CAAC;CAC/E,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"yolo.d.ts","sourceRoot":"","sources":["../../../../src/vision/worker/decoders/yolo.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAiB,WAAW,EAAc,MAAM,SAAS,CAAC;AAYtE;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,EAAE,WAgEzB,CAAC"}
1
+ {"version":3,"file":"yolo.d.ts","sourceRoot":"","sources":["../../../../src/vision/worker/decoders/yolo.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAGV,WAAW,EAEZ,MAAM,SAAS,CAAC;AAYjB;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,EAAE,WAkEzB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { ONNXDecoder } from './types';
2
+ /**
3
+ * Decoder for YOLOv8/v11-**seg** instance-segmentation heads.
4
+ *
5
+ * Two outputs: detection `[1, 4 + numClasses + M, numAnchors]` (box + class
6
+ * scores + M mask coefficients) and prototypes `[1, M, protoH, protoW]`. Each
7
+ * kept detection's mask is `sigmoid(coeffs . prototypes)`, thresholded and
8
+ * cropped to its box (prototypes live in the same letterboxed input space).
9
+ */
10
+ export declare const yoloSegDecoder: ONNXDecoder;
11
+ //# sourceMappingURL=yoloSeg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yoloSeg.d.ts","sourceRoot":"","sources":["../../../../src/vision/worker/decoders/yoloSeg.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAGV,WAAW,EAEZ,MAAM,SAAS,CAAC;AAgBjB;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,EAAE,WAkI5B,CAAC"}
@@ -1,4 +1,4 @@
1
- import { ObjectDetection, ONNXModelConfig } from '../types';
1
+ import { ObjectDetection, ONNXModelConfig, SegmentationMask } from '../types';
2
2
  export type { VisionProgress } from '../types';
3
3
  /** Options forwarded to the worker for a single processed frame */
4
4
  export type ONNXProcessOptions = {
@@ -8,6 +8,7 @@ export type ONNXProcessOptions = {
8
8
  /** Result payload the ONNX worker produces for a processed frame */
9
9
  export type ONNXWorkerResult = {
10
10
  detections: ObjectDetection[];
11
+ masks: SegmentationMask[];
11
12
  frameSize: {
12
13
  width: number;
13
14
  height: number;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/vision/worker/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEjE,YAAY,EAAE,cAAc,EAAE,MAA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C,MAAM,EAAE,gBAAgB,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -169,7 +169,14 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
169
169
  ...t,
170
170
  path: e,
171
171
  decoder: "rfdetr"
172
- }), P = (e) => {
172
+ }), P = (e, t = {}) => ({
173
+ name: "yolo-seg",
174
+ inputSize: 640,
175
+ labels: [...j],
176
+ ...t,
177
+ path: e,
178
+ decoder: "yoloseg"
179
+ }), F = (e) => {
173
180
  let { isSuccess: t, onDetection: n } = k(), [i, s] = o(null), c = e?.throttle ?? 16, l = a(0);
174
181
  return r(() => {
175
182
  if (!t) {
@@ -185,7 +192,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
185
192
  n,
186
193
  c
187
194
  ]), i;
188
- }, F = 478, I = (e, t) => t === "faces" ? e.faces : t === "poses" ? e.poses : e.hands, L = ({ task: e, index: t = 0, debug: n = !1, mirror: o = !0, smoothing: s = .4, children: u }) => {
195
+ }, I = 478, L = (e, t) => t === "faces" ? e.faces : t === "poses" ? e.poses : e.hands, R = ({ task: e, index: t = 0, debug: n = !1, mirror: o = !0, smoothing: s = .4, children: u }) => {
189
196
  let { onDetection: h, isSuccess: g } = k(), { viewport: _ } = l(), v = a(null), y = a(null), b = a(null), x = i(() => new p(), []), S = i(() => new m(), []);
190
197
  return r(() => {
191
198
  y.current && (y.current.visible = !1), b.current && (b.current.count = 0);
@@ -196,7 +203,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
196
203
  }, [g, h]), c(() => {
197
204
  let r = v.current, i = y.current;
198
205
  if (!r || !i) return;
199
- let a = I(r, e)[t], c = b.current;
206
+ let a = L(r, e)[t], c = b.current;
200
207
  if (!a || a.landmarks.length === 0) {
201
208
  i.visible = !1, c && (c.count = 0);
202
209
  return;
@@ -205,7 +212,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
205
212
  i.visible = !0;
206
213
  let [u, d, f] = E(D(a.landmarks), _, r.frameSize, o);
207
214
  if (S.set(u, d, f), !l || s >= 1 ? i.position.copy(S) : i.position.lerp(S, s), n && c) {
208
- let e = i.position, t = Math.min(a.landmarks.length, F);
215
+ let e = i.position, t = Math.min(a.landmarks.length, I);
209
216
  for (let n = 0; n < t; n++) {
210
217
  let [t, i, s] = E(a.landmarks[n], _, r.frameSize, o);
211
218
  x.position.set(t - e.x, i - e.y, s - e.z), x.updateMatrix(), c.setMatrixAt(n, x.matrix);
@@ -219,7 +226,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
219
226
  args: [
220
227
  void 0,
221
228
  void 0,
222
- F
229
+ I
223
230
  ],
224
231
  children: [/* @__PURE__ */ d("sphereGeometry", { args: [
225
232
  .02,
@@ -228,8 +235,8 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
228
235
  ] }), /* @__PURE__ */ d("meshBasicMaterial", { color: "#00ff88" })]
229
236
  })]
230
237
  });
231
- }, R = ({ tasks: e, width: t = 320, height: n = 240, style: r }) => {
232
- let i = P({ throttle: 50 });
238
+ }, z = ({ tasks: e, width: t = 320, height: n = 240, style: r }) => {
239
+ let i = F({ throttle: 50 });
233
240
  return /* @__PURE__ */ f("div", {
234
241
  style: {
235
242
  background: "rgba(0, 0, 0, 0.8)",
@@ -256,7 +263,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
256
263
  e.includes("objects") && /* @__PURE__ */ f("div", { children: ["Objects: ", i.objects.length] })
257
264
  ] })]
258
265
  });
259
- }, z = class {
266
+ }, B = class {
260
267
  type = "mediapipe";
261
268
  models = {};
262
269
  isInitialized = !1;
@@ -442,7 +449,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
442
449
  console.error("Error in vision callback:", e);
443
450
  }
444
451
  }
445
- }, B = 5e3, V = class {
452
+ }, V = 5e3, H = class {
446
453
  type = "onnx";
447
454
  worker = null;
448
455
  isInitialized = !1;
@@ -466,7 +473,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
466
473
  async initialize(e) {
467
474
  this.videoElement = e, this.worker = new Worker(new URL(
468
475
  /* @vite-ignore */
469
- "/assets/onnxWorker-B_g0sj2t.js",
476
+ "/assets/onnxWorker-BNjoneWr.js",
470
477
  "" + import.meta.url
471
478
  ), { type: "module" }), await new Promise((e, t) => {
472
479
  let n = setTimeout(() => {
@@ -512,7 +519,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
512
519
  this.animationId = requestAnimationFrame(e);
513
520
  return;
514
521
  }
515
- this.isProcessing && this.processingStartTime > 0 && t - this.processingStartTime > B && (console.warn("ONNX processing stall detected, resetting"), this.isProcessing = !1), this.isProcessing || this.processCurrentFrame(), this.animationId = requestAnimationFrame(e);
522
+ this.isProcessing && this.processingStartTime > 0 && t - this.processingStartTime > V && (console.warn("ONNX processing stall detected, resetting"), this.isProcessing = !1), this.isProcessing || this.processCurrentFrame(), this.animationId = requestAnimationFrame(e);
516
523
  };
517
524
  e();
518
525
  }
@@ -571,6 +578,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
571
578
  faces: [],
572
579
  poses: [],
573
580
  objects: e.detections.filter((e) => e.confidence >= t).sort((e, t) => t.confidence - e.confidence).slice(0, n),
581
+ masks: e.masks.length > 0 ? e.masks : void 0,
574
582
  timestamp: e.timestamp,
575
583
  frameSize: e.frameSize,
576
584
  processingTime: e.processingTime
@@ -581,7 +589,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
581
589
  console.error("Error in ONNX detection callback:", e);
582
590
  }
583
591
  }
584
- }, H = (e) => e.provider === "onnx" ? new V(e) : new z(e), U = async (e) => {
592
+ }, U = (e) => e.provider === "onnx" ? new H(e) : new B(e), W = async (e) => {
585
593
  let t = document.createElement("video");
586
594
  t.style.display = "none", document.body.appendChild(t);
587
595
  try {
@@ -607,12 +615,12 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
607
615
  } catch (e) {
608
616
  throw document.body.removeChild(t), e;
609
617
  }
610
- }, W = (e) => {
618
+ }, G = (e) => {
611
619
  if (!e) return;
612
620
  let t = e.srcObject;
613
621
  if (t) for (let e of t.getTracks()) e.stop();
614
622
  e.parentNode && e.parentNode.removeChild(e);
615
- }, G = (t) => {
623
+ }, K = (t) => {
616
624
  let n = null, r = null, i = !1, a = null, o = [], s = (e) => (o.push(e), () => {
617
625
  let t = o.indexOf(e);
618
626
  t > -1 && o.splice(t, 1);
@@ -620,7 +628,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
620
628
  return {
621
629
  type: e.VISION,
622
630
  async init(e) {
623
- t.videoElement ? (r = t.videoElement, i = !1) : (r = await U(t), i = !0), n = H(t), await n.initialize(r), a = n.onDetection((e) => {
631
+ t.videoElement ? (r = t.videoElement, i = !1) : (r = await W(t), i = !0), n = U(t), await n.initialize(r), a = n.onDetection((e) => {
624
632
  for (let t of o) try {
625
633
  t(e);
626
634
  } catch (e) {
@@ -630,7 +638,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
630
638
  },
631
639
  update(e) {},
632
640
  dispose() {
633
- a?.(), a = null, n?.dispose(), i && W(r), r = null, n = null, o.length = 0;
641
+ a?.(), a = null, n?.dispose(), i && G(r), r = null, n = null, o.length = 0;
634
642
  },
635
643
  getInternal: () => ({
636
644
  provider: n,
@@ -638,7 +646,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
638
646
  onDetection: s
639
647
  })
640
648
  };
641
- }, K = ({ options: e, children: n, onError: i }) => {
649
+ }, q = ({ options: e, children: n, onError: i }) => {
642
650
  let { scene: o, camera: s, gl: c } = l(), { registerBackend: f, unregisterBackend: p } = t(), m = a(null), h = a(e);
643
651
  h.current = e;
644
652
  let g = a(i);
@@ -647,7 +655,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
647
655
  let e = !1;
648
656
  return (async () => {
649
657
  try {
650
- let t = G(h.current);
658
+ let t = K(h.current);
651
659
  if (e) return;
652
660
  if (await f(t, {
653
661
  scene: o,
@@ -672,8 +680,8 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
672
680
  f,
673
681
  p
674
682
  ]), /* @__PURE__ */ d(u, { children: n });
675
- }, q = ({ tasks: e, progress: t, showDebug: n, onToggleDebug: r }) => {
676
- let i = P({ throttle: 100 }), a = (e) => {
683
+ }, J = ({ tasks: e, progress: t, showDebug: n, onToggleDebug: r }) => {
684
+ let i = F({ throttle: 100 }), a = (e) => {
677
685
  if (!i) return !1;
678
686
  switch (e) {
679
687
  case "hands": return i.hands.length > 0;
@@ -738,7 +746,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
738
746
  },
739
747
  children: [n ? "Hide" : "Show", " Debug"]
740
748
  })] });
741
- }, J = {}, Y = ({ tasks: e = ["hands"], options: t, children: r, showDebug: c = !1, cameraConstraints: l, canvasStyle: u = J, onReady: p, onError: m }) => {
749
+ }, Y = {}, X = ({ tasks: e = ["hands"], options: t, children: r, showDebug: c = !1, cameraConstraints: l, canvasStyle: u = Y, onReady: p, onError: m }) => {
742
750
  let [g, _] = o(c), [v, y] = o(null), [b, x] = o(null), S = a(p);
743
751
  S.current = p;
744
752
  let C = a(x);
@@ -790,19 +798,19 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
790
798
  alpha: !0,
791
799
  premultipliedAlpha: !1
792
800
  },
793
- children: /* @__PURE__ */ d(X, {
801
+ children: /* @__PURE__ */ d(Z, {
794
802
  options: E,
795
803
  onError: m,
796
804
  children: r
797
805
  })
798
806
  }),
799
- /* @__PURE__ */ d(q, {
807
+ /* @__PURE__ */ d(J, {
800
808
  tasks: e,
801
809
  progress: b,
802
810
  showDebug: g,
803
811
  onToggleDebug: () => _((e) => !e)
804
812
  }),
805
- g && /* @__PURE__ */ d(R, {
813
+ g && /* @__PURE__ */ d(z, {
806
814
  tasks: e,
807
815
  width: 320,
808
816
  height: 240,
@@ -816,7 +824,7 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
816
824
  })
817
825
  ]
818
826
  });
819
- }, X = ({ options: e, onError: t, children: n }) => /* @__PURE__ */ f(K, {
827
+ }, Z = ({ options: e, onError: t, children: n }) => /* @__PURE__ */ f(q, {
820
828
  options: e,
821
829
  onError: t,
822
830
  children: [
@@ -833,4 +841,4 @@ var h = ({ constraints: e, onReady: t, onError: n, mirrored: i = !0 }) => {
833
841
  ]
834
842
  });
835
843
  //#endregion
836
- export { h as S, S as _, R as a, y as b, j as c, A as d, k as f, C as g, T as h, G as i, N as l, D as m, q as n, L as o, E as p, K as r, P as s, Y as t, M as u, b as v, v as x, x as y };
844
+ export { h as C, v as S, C as _, z as a, x as b, j as c, P as d, A as f, T as g, D as h, K as i, N as l, E as m, J as n, R as o, k as p, q as r, F as s, X as t, M as u, S as v, y as x, b as y };
@@ -0,0 +1 @@
1
+ const e=require(`./useXRStore-8Vl3wsP5.cjs`);let t=require(`react`),n=require(`@react-three/fiber`),r=require(`react/jsx-runtime`),i=require(`three`);var a=({constraints:e,onReady:n,onError:i,mirrored:a=!0})=>{let o=(0,t.useRef)(null),[s,c]=(0,t.useState)(!1),l=(0,t.useRef)(n);l.current=n;let u=(0,t.useRef)(i);return u.current=i,(0,t.useEffect)(()=>{let t=!1;return(async()=>{try{let n=await navigator.mediaDevices.getUserMedia({video:e||{width:{ideal:1280},height:{ideal:720},facingMode:`user`}});if(t||!o.current){for(let e of n.getTracks())e.stop();return}if(o.current.srcObject=n,await new Promise((e,t)=>{let n=o.current;if(!n){t(Error(`Video ref lost`));return}let r=()=>{n.removeEventListener(`canplay`,r),n.removeEventListener(`error`,i),e()},i=()=>{n.removeEventListener(`canplay`,r),n.removeEventListener(`error`,i),t(Error(`Video failed to load`))};n.addEventListener(`canplay`,r,{once:!0}),n.addEventListener(`error`,i,{once:!0})}),t)return;await o.current.play(),c(!0),l.current?.(o.current)}catch(e){if(t)return;let n=e instanceof Error?e:Error(`Failed to access camera`);console.error(`Camera error:`,n),u.current?.(n)}})(),()=>{if(t=!0,o.current?.srcObject){let e=o.current.srcObject;for(let t of e.getTracks())t.stop()}}},[e]),(0,r.jsx)(`video`,{ref:o,style:{position:`absolute`,inset:0,width:`100%`,height:`100%`,objectFit:`cover`,transform:a?`scaleX(-1)`:void 0,opacity:s?1:0,transition:`opacity 0.5s ease`},autoPlay:!0,playsInline:!0,muted:!0})},o=(e,t)=>e.y<t.y,s=e=>[Math.abs(e[4].x-e[9].x)>Math.abs(e[3].x-e[9].x),o(e[8],e[6]),o(e[12],e[10]),o(e[16],e[14]),o(e[20],e[18])],c=e=>{if(e.length<21)return null;let t=s(e);return t[0]&&!t[1]&&!t[2]&&!t[3]&&!t[4]?{gesture:`thumbs_up`,confidence:.9}:null},l=e=>{if(e.length<21)return null;let t=s(e);return!t[0]&&t[1]&&t[2]&&!t[3]&&!t[4]?{gesture:`peace`,confidence:.8}:null},u=e=>{if(e.length<21)return null;let t=s(e);return Math.sqrt((e[4].x-e[8].x)**2+(e[4].y-e[8].y)**2)<.05&&t[2]&&t[3]&&t[4]?{gesture:`ok`,confidence:.8}:null},d=e=>e.length<21?null:s(e).filter(Boolean).length===5?{gesture:`open_hand`,confidence:.7}:null,f=e=>e.length<21?null:s(e).filter(Boolean).length<=1?{gesture:`fist`,confidence:.7}:null,p=[c,l,u,d,f],m={gesture:`none`,confidence:0},h=(e,t=p)=>{let n=m;for(let r of t){let t=r(e);t&&t.confidence>n.confidence&&(n=t)}return n},g=(e,t,n,r=!0)=>{let i=t.width/t.height,a=n.width/n.height,o=a>i?a/i:1,s=a>i?1:i/a,c=.5+(e.x-.5)*o,l=.5+(e.y-.5)*s;return[(r?.5-c:c-.5)*t.width,(.5-l)*t.height,0]},_=e=>{let t=e.length||1,n=0,r=0,i=0;for(let t of e)n+=t.x,r+=t.y,i+=t.z??0;return{x:n/t,y:r/t,z:i/t}},v={isPending:!0,isSuccess:!1,provider:null,videoElement:null,onDetection:()=>()=>{}},y=()=>{let t=e.r(e=>e.backends).get(e.i.VISION);return t?{...t.getInternal(),isPending:!1,isSuccess:!0}:v},b=({onHandMove:e,onGesture:a,landmarkIndex:o=9,mirror:s=!0,children:c})=>{let{onDetection:l,isSuccess:u}=y(),{viewport:d}=(0,n.useThree)(),f=(0,t.useRef)(null),p=(0,t.useRef)(new i.Vector3),m=(0,t.useRef)(``);return(0,t.useEffect)(()=>{if(u)return l(e=>{f.current=e})},[u,l]),(0,n.useFrame)(()=>{let t=f.current;if(!t)return;let n=t.hands[0];if(!n||n.landmarks.length===0)return;let[r,i,c]=g(n.landmarks[o]??n.landmarks[0],d,t.frameSize,s);p.current.set(r,i,c),e?.(p.current);let l=h(n.landmarks);l.gesture!==m.current&&(m.current=l.gesture,a?.(l.gesture,l.confidence))}),(0,r.jsx)(`group`,{children:c})},x=`person.bicycle.car.motorcycle.airplane.bus.train.truck.boat.traffic light.fire hydrant.stop sign.parking meter.bench.bird.cat.dog.horse.sheep.cow.elephant.bear.zebra.giraffe.backpack.umbrella.handbag.tie.suitcase.frisbee.skis.snowboard.sports ball.kite.baseball bat.baseball glove.skateboard.surfboard.tennis racket.bottle.wine glass.cup.fork.knife.spoon.bowl.banana.apple.sandwich.orange.broccoli.carrot.hot dog.pizza.donut.cake.chair.couch.potted plant.bed.dining table.toilet.tv.laptop.mouse.remote.keyboard.cell phone.microwave.oven.toaster.sink.refrigerator.book.clock.vase.scissors.teddy bear.hair drier.toothbrush`.split(`.`),S=(e,t={})=>({name:`yolo`,inputSize:640,labels:[...x],...t,path:e,decoder:`yolo`}),C=(e,t={})=>({name:`rf-detr`,inputSize:560,labels:[...x],...t,path:e,decoder:`rfdetr`}),w=(e,t={})=>({name:`yolo-seg`,inputSize:640,labels:[...x],...t,path:e,decoder:`yoloseg`}),T=e=>{let{isSuccess:n,onDetection:r}=y(),[i,a]=(0,t.useState)(null),o=e?.throttle??16,s=(0,t.useRef)(0);return(0,t.useEffect)(()=>{if(!n){a(null);return}return r(e=>{let t=performance.now();t-s.current<o||(s.current=t,a(e))})},[n,r,o]),i},E=478,D=(e,t)=>t===`faces`?e.faces:t===`poses`?e.poses:e.hands,O=({task:e,index:a=0,debug:o=!1,mirror:s=!0,smoothing:c=.4,children:l})=>{let{onDetection:u,isSuccess:d}=y(),{viewport:f}=(0,n.useThree)(),p=(0,t.useRef)(null),m=(0,t.useRef)(null),h=(0,t.useRef)(null),v=(0,t.useMemo)(()=>new i.Object3D,[]),b=(0,t.useMemo)(()=>new i.Vector3,[]);return(0,t.useEffect)(()=>{m.current&&(m.current.visible=!1),h.current&&(h.current.count=0)},[]),(0,t.useEffect)(()=>{if(d)return u(e=>{p.current=e})},[d,u]),(0,n.useFrame)(()=>{let t=p.current,n=m.current;if(!t||!n)return;let r=D(t,e)[a],i=h.current;if(!r||r.landmarks.length===0){n.visible=!1,i&&(i.count=0);return}let l=n.visible;n.visible=!0;let[u,d,y]=g(_(r.landmarks),f,t.frameSize,s);if(b.set(u,d,y),!l||c>=1?n.position.copy(b):n.position.lerp(b,c),o&&i){let e=n.position,a=Math.min(r.landmarks.length,E);for(let n=0;n<a;n++){let[a,o,c]=g(r.landmarks[n],f,t.frameSize,s);v.position.set(a-e.x,o-e.y,c-e.z),v.updateMatrix(),i.setMatrixAt(n,v.matrix)}i.count=a,i.instanceMatrix.needsUpdate=!0}}),(0,r.jsxs)(`group`,{ref:m,children:[l,o&&(0,r.jsxs)(`instancedMesh`,{ref:h,args:[void 0,void 0,E],children:[(0,r.jsx)(`sphereGeometry`,{args:[.02,6,6]}),(0,r.jsx)(`meshBasicMaterial`,{color:`#00ff88`})]})]})},k=({tasks:e,width:t=320,height:n=240,style:i})=>{let a=T({throttle:50});return(0,r.jsxs)(`div`,{style:{background:`rgba(0, 0, 0, 0.8)`,color:`#00ff88`,padding:`8px`,borderRadius:`8px`,fontFamily:`monospace`,fontSize:`0.75rem`,width:t,height:n,overflow:`auto`,...i},children:[(0,r.jsxs)(`div`,{children:[`Frame: `,a?`active`:`none`]}),a&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(`div`,{children:[`Size: `,a.frameSize.width,`x`,a.frameSize.height]}),e.includes(`hands`)&&(0,r.jsxs)(`div`,{children:[`Hands: `,a.hands.length]}),e.includes(`faces`)&&(0,r.jsxs)(`div`,{children:[`Faces: `,a.faces.length]}),e.includes(`poses`)&&(0,r.jsxs)(`div`,{children:[`Poses: `,a.poses.length]}),e.includes(`objects`)&&(0,r.jsxs)(`div`,{children:[`Objects: `,a.objects.length]})]})]})},A=class{type=`mediapipe`;models={};isInitialized=!1;isProcessing=!1;isDisposed=!1;videoElement=null;animationId=null;lastProcessTime=0;callbacks=[];options;constructor(e){this.options=e}async initialize(e){this.videoElement=e;let{FilesetResolver:t,HandLandmarker:n,FaceLandmarker:r,PoseLandmarker:i}=await import(`@mediapipe/tasks-vision`),a=await t.forVisionTasks(`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10/wasm`),o=this.options.useGpu??!0?`GPU`:`CPU`,s=async e=>{if(o===`CPU`)return e(`CPU`);try{return await e(`GPU`)}catch{return console.warn(`MediaPipe GPU delegate failed, falling back to CPU`),e(`CPU`)}},c=new Set(this.options.tasks??[`hands`,`faces`,`poses`]),l=[`hands`,`faces`,`poses`].filter(e=>c.has(e)),u=0;c.has(`hands`)&&(this.options.onProgress?.({step:++u,total:l.length,label:`hand landmarker`}),this.models.handLandmarker=await s(e=>n.createFromOptions(a,{baseOptions:{modelAssetPath:`https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task`,delegate:e},runningMode:`VIDEO`,numHands:2,minHandDetectionConfidence:.7,minHandPresenceConfidence:.5,minTrackingConfidence:.5}))),c.has(`faces`)&&(this.options.onProgress?.({step:++u,total:l.length,label:`face landmarker`}),this.models.faceLandmarker=await s(e=>r.createFromOptions(a,{baseOptions:{modelAssetPath:`https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task`,delegate:e},runningMode:`VIDEO`,numFaces:1,minFaceDetectionConfidence:.7,minFacePresenceConfidence:.5,minTrackingConfidence:.5,outputFaceBlendshapes:!1,outputFacialTransformationMatrixes:!1}))),c.has(`poses`)&&(this.options.onProgress?.({step:++u,total:l.length,label:`pose landmarker`}),this.models.poseLandmarker=await s(e=>i.createFromOptions(a,{baseOptions:{modelAssetPath:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_lite/float16/1/pose_landmarker_lite.task`,delegate:e},runningMode:`VIDEO`,numPoses:1,minPoseDetectionConfidence:.7,minPosePresenceConfidence:.5,minTrackingConfidence:.5,outputSegmentationMasks:this.options.segmentation??!1}))),this.isInitialized=!0,this.options.onProgress?.(null)}startDetection(){!this.isInitialized||!this.videoElement||this.isProcessing||(this.isProcessing=!0,this.processFrame())}stopDetection(){this.isProcessing=!1,this.animationId&&=(cancelAnimationFrame(this.animationId),null)}onDetection(e){return this.callbacks.push(e),()=>{let t=this.callbacks.indexOf(e);t>-1&&this.callbacks.splice(t,1)}}dispose(){this.isDisposed=!0,this.stopDetection(),this.models.handLandmarker&&this.models.handLandmarker.close(),this.models.faceLandmarker&&this.models.faceLandmarker.close(),this.models.poseLandmarker&&this.models.poseLandmarker.close(),this.models={},this.videoElement=null,this.callbacks=[],this.isInitialized=!1,this.isProcessing=!1}processFrame=()=>{if(!this.isProcessing||!this.videoElement||this.isDisposed)return;let e=performance.now(),t=this.options.throttle??16;if(e-this.lastProcessTime<t){this.animationId=requestAnimationFrame(this.processFrame);return}let{videoWidth:n,videoHeight:r}=this.videoElement;if(n===0||r===0){this.animationId=requestAnimationFrame(this.processFrame);return}this.lastProcessTime=e;let i=e;try{let e={hands:[],faces:[],poses:[],objects:[],timestamp:i,frameSize:{width:n,height:r}};if(this.models.handLandmarker){let t=this.models.handLandmarker.detectForVideo(this.videoElement,i);e.hands=t.landmarks.map((e,n)=>({landmarks:e.map(e=>({x:e.x,y:e.y,z:e.z||0})),confidence:t.handednesses?.[n]?.[0]?.score||.5}))}if(this.models.faceLandmarker&&(e.faces=this.models.faceLandmarker.detectForVideo(this.videoElement,i).faceLandmarks.map(e=>{let t=e.map(e=>e.x),n=e.map(e=>e.y),r=(Math.max(...t)-Math.min(...t))*(Math.max(...n)-Math.min(...n)),i=Math.min(.95,Math.max(.6,r*4));return{landmarks:e.map(e=>({x:e.x,y:e.y,z:e.z||0})),confidence:i}})),this.models.poseLandmarker){let t=this.models.poseLandmarker.detectForVideo(this.videoElement,i);e.poses=t.landmarks.map(e=>{let t=0,n=0;for(let r of e)typeof r.visibility==`number`&&(t+=r.visibility,n++);let r=n>0?t/n:.5;return{landmarks:e.map(e=>({x:e.x,y:e.y,z:e.z||0})),confidence:r}});let n=t.segmentationMasks?.[0];if(n){let t=new OffscreenCanvas(n.width,n.height).getContext(`2d`),r=n.getAsFloat32Array(),i=t.createImageData(n.width,n.height);for(let e=0;e<r.length;e++){let t=r[e]*255;i.data[e*4]=t,i.data[e*4+1]=t,i.data[e*4+2]=t,i.data[e*4+3]=255}e.segmentationMask=i}}this.handleResult(e)}catch(e){console.error(`Vision processing error:`,e)}this.animationId=requestAnimationFrame(this.processFrame)};handleResult(e){let t=this.options.minConfidence??.7,n=this.options.maxResults??2,r={...e,hands:e.hands.filter(e=>e.confidence>=t).slice(0,n),faces:e.faces.filter(e=>e.confidence>=t).slice(0,n),poses:e.poses.filter(e=>e.confidence>=t).slice(0,n),objects:[]};for(let e of this.callbacks)try{e(r)}catch(e){console.error(`Error in vision callback:`,e)}}},j=5e3,M=class{type=`onnx`;worker=null;isInitialized=!1;isDisposed=!1;isProcessing=!1;videoElement=null;animationId=null;loadedModels=new Map;lastProcessTime=0;processingStartTime=0;callbacks=[];options;messageHandler=null;pendingModelCallbacks=new Map;constructor(e){this.options=e}post(e,t){t?this.worker?.postMessage(e,t):this.worker?.postMessage(e)}async initialize(e){this.videoElement=e,this.worker=new Worker(new URL(`/assets/onnxWorker-BNjoneWr.js`,``+{}.url),{type:`module`}),await new Promise((e,t)=>{let n=setTimeout(()=>{t(Error(`ONNX worker initialization timeout`))},1e4);this.messageHandler=r=>{let i=r.data;switch(i.type){case`initialized`:clearTimeout(n),this.isInitialized=!0,e();break;case`result`:this.isProcessing=!1,this.handleResult(i.result);break;case`modelLoaded`:{let e=this.pendingModelCallbacks.get(i.modelName);e&&(this.pendingModelCallbacks.delete(i.modelName),e.resolve());break}case`modelError`:{let e=this.pendingModelCallbacks.get(i.modelName);e&&(this.pendingModelCallbacks.delete(i.modelName),e.reject(Error(i.error)));break}case`error`:this.isProcessing=!1,this.isInitialized?console.error(`ONNX worker error:`,i.error):(clearTimeout(n),t(Error(i.error)));break}},this.worker?.addEventListener(`message`,this.messageHandler),this.post({type:`init`})});let t=this.options.onnx?.models??[];for(let e of t)await this.loadModel(e)}startDetection(){if(!this.isInitialized||!this.videoElement){console.warn(`ONNX provider not initialized`);return}let e=()=>{if(!this.videoElement||!this.isInitialized)return;let t=Date.now(),n=this.options.throttle??100;if(t-this.lastProcessTime<n){this.animationId=requestAnimationFrame(e);return}this.isProcessing&&this.processingStartTime>0&&t-this.processingStartTime>j&&(console.warn(`ONNX processing stall detected, resetting`),this.isProcessing=!1),this.isProcessing||this.processCurrentFrame(),this.animationId=requestAnimationFrame(e)};e()}stopDetection(){this.animationId&&=(cancelAnimationFrame(this.animationId),null),this.isProcessing=!1}onDetection(e){return this.callbacks.push(e),()=>{let t=this.callbacks.indexOf(e);t>-1&&this.callbacks.splice(t,1)}}dispose(){this.isDisposed=!0,this.stopDetection(),this.worker&&=(this.messageHandler&&=(this.worker.removeEventListener(`message`,this.messageHandler),null),this.post({type:`dispose`}),this.worker.terminate(),null),this.videoElement=null,this.callbacks.length=0,this.loadedModels.clear(),this.pendingModelCallbacks.clear(),this.isInitialized=!1}async loadModel(e){if(!this.worker)throw Error(`Worker not initialized`);let t=new Promise((t,n)=>{this.pendingModelCallbacks.set(e.name,{resolve:t,reject:n})});this.post({type:`loadModel`,model:e}),await t,this.loadedModels.set(e.name,e)}processCurrentFrame(){if(!this.videoElement||!this.worker||this.isProcessing)return;let e=Date.now();this.isProcessing=!0,this.lastProcessTime=e,this.processingStartTime=e;let{videoWidth:t,videoHeight:n}=this.videoElement;createImageBitmap(this.videoElement).then(e=>{if(this.isDisposed){e.close();return}this.post({type:`process`,imageBitmap:e,sourceWidth:t,sourceHeight:n,options:{minConfidence:this.options.minConfidence??.5,maxResults:this.options.maxResults??100}},[e])},e=>{this.isProcessing=!1,console.error(`Error creating ImageBitmap:`,e)})}handleResult(e){let t=this.options.minConfidence??.5,n=this.options.maxResults??100,r={hands:[],faces:[],poses:[],objects:e.detections.filter(e=>e.confidence>=t).sort((e,t)=>t.confidence-e.confidence).slice(0,n),masks:e.masks.length>0?e.masks:void 0,timestamp:e.timestamp,frameSize:e.frameSize,processingTime:e.processingTime};for(let e of this.callbacks)try{e(r)}catch(e){console.error(`Error in ONNX detection callback:`,e)}}},N=e=>e.provider===`onnx`?new M(e):new A(e),P=async e=>{let t=document.createElement(`video`);t.style.display=`none`,document.body.appendChild(t);try{return t.srcObject=await navigator.mediaDevices.getUserMedia({video:{width:{ideal:1280,min:640},height:{ideal:720,min:480},facingMode:e.provider===`onnx`?`environment`:`user`,frameRate:{ideal:30,min:15}}}),t.playsInline=!0,t.muted=!0,await new Promise((e,n)=>{t.onloadedmetadata=()=>{t.play().then(e).catch(n)},t.onerror=n}),t}catch(e){throw document.body.removeChild(t),e}},F=e=>{if(!e)return;let t=e.srcObject;if(t)for(let e of t.getTracks())e.stop();e.parentNode&&e.parentNode.removeChild(e)},I=t=>{let n=null,r=null,i=!1,a=null,o=[],s=e=>(o.push(e),()=>{let t=o.indexOf(e);t>-1&&o.splice(t,1)});return{type:e.i.VISION,async init(e){t.videoElement?(r=t.videoElement,i=!1):(r=await P(t),i=!0),n=N(t),await n.initialize(r),a=n.onDetection(e=>{for(let t of o)try{t(e)}catch(e){console.error(`Error in vision detection callback:`,e)}}),n.startDetection()},update(e){},dispose(){a?.(),a=null,n?.dispose(),i&&F(r),r=null,n=null,o.length=0},getInternal:()=>({provider:n,videoElement:r,onDetection:s})}},L=({options:i,children:a,onError:o})=>{let{scene:s,camera:c,gl:l}=(0,n.useThree)(),{registerBackend:u,unregisterBackend:d}=e.r(),f=(0,t.useRef)(null),p=(0,t.useRef)(i);p.current=i;let m=(0,t.useRef)(o);return m.current=o,(0,t.useEffect)(()=>{if(f.current)return;let e=!1;return(async()=>{try{let t=I(p.current);if(e)return;if(await u(t,{scene:s,camera:c,renderer:l}),e){d(t);return}f.current=t}catch(e){let t=e instanceof Error?e:Error(String(e));console.error(`[VisionSession] Failed to initialize:`,t),m.current?.(t)}})(),()=>{e=!0,f.current&&=(d(f.current),null)}},[s,c,l,u,d]),(0,r.jsx)(r.Fragment,{children:a})},R=({tasks:e,progress:t,showDebug:n,onToggleDebug:i})=>{let a=T({throttle:100}),o=e=>{if(!a)return!1;switch(e){case`hands`:return a.hands.length>0;case`faces`:return a.faces.length>0;case`poses`:return a.poses.length>0;case`objects`:return a.objects.length>0;default:return!1}},s=e.some(o),c=a!==null;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(`div`,{style:{position:`fixed`,top:`20px`,left:`20px`,background:`rgba(0, 0, 0, 0.7)`,color:`white`,padding:`12px`,borderRadius:`8px`,fontFamily:`system-ui, sans-serif`,fontSize:`0.9rem`,zIndex:1e3},children:[(0,r.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,marginBottom:`8px`},children:[(0,r.jsx)(`div`,{style:{width:`8px`,height:`8px`,borderRadius:`50%`,background:c?`#00ff88`:`#ffaa00`}}),(0,r.jsx)(`span`,{children:s?`Active`:c?`Ready`:t?`Loading models (${t.step}/${t.total}) ${t.label}...`:`Starting...`})]}),e.map(e=>(0,r.jsxs)(`div`,{style:{fontSize:`0.8rem`,opacity:.8,display:`flex`,justifyContent:`space-between`,gap:`12px`},children:[(0,r.jsx)(`span`,{children:e}),(0,r.jsx)(`span`,{children:o(e)?`active`:c?`idle`:`...`})]},e))]}),(0,r.jsxs)(`button`,{onClick:i,type:`button`,style:{position:`fixed`,top:`20px`,right:`20px`,background:`rgba(0, 0, 0, 0.7)`,color:`white`,border:`1px solid #333`,padding:`8px 12px`,borderRadius:`6px`,cursor:`pointer`,fontFamily:`system-ui, sans-serif`,fontSize:`0.8rem`,zIndex:1e3},children:[n?`Hide`:`Show`,` Debug`]})]})},z={},B=({tasks:e=[`hands`],options:i,children:o,showDebug:s=!1,cameraConstraints:c,canvasStyle:l=z,onReady:u,onError:d})=>{let[f,p]=(0,t.useState)(s),[m,h]=(0,t.useState)(null),[g,_]=(0,t.useState)(null),v=(0,t.useRef)(u);v.current=u;let y=(0,t.useRef)(_);y.current=_;let b=(0,t.useCallback)(e=>y.current(e),[]),x=(0,t.useCallback)(e=>{h(e),v.current?.()},[]),S=(0,t.useMemo)(()=>({tasks:e,minConfidence:.6,maxResults:2,useGpu:!0,...i,videoElement:m??void 0,onProgress:b}),[e,i,m,b]);return(0,r.jsxs)(`div`,{style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,r.jsx)(a,{constraints:c,onReady:x,onError:d}),m&&(0,r.jsx)(n.Canvas,{style:{position:`absolute`,inset:0,pointerEvents:`none`,...l},camera:{position:[0,0,5],fov:75},gl:{alpha:!0,premultipliedAlpha:!1},children:(0,r.jsx)(V,{options:S,onError:d,children:o})}),(0,r.jsx)(R,{tasks:e,progress:g,showDebug:f,onToggleDebug:()=>p(e=>!e)}),f&&(0,r.jsx)(k,{tasks:e,width:320,height:240,style:{position:`fixed`,bottom:`80px`,right:`20px`,maxWidth:`calc(100vw - 40px)`,overflow:`hidden`}})]})},V=({options:e,onError:t,children:n})=>(0,r.jsxs)(L,{options:e,onError:t,children:[(0,r.jsx)(`ambientLight`,{intensity:.6}),(0,r.jsx)(`directionalLight`,{position:[10,10,10],intensity:.8}),n]});Object.defineProperty(exports,`C`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`S`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return u}});
package/build/vision.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./useXRStore-8Vl3wsP5.cjs`);const e=require(`./vision-CRUCg7uc.cjs`);exports.COCO_LABELS=e.c,exports.CameraBackground=e.S,exports.DEFAULT_GESTURES=e.g,exports.HandTracker=e.d,exports.VisionAnchor=e.o,exports.VisionDebug=e.a,exports.VisionOverlay=e.t,exports.VisionSession=e.r,exports.VisionStatus=e.n,exports.createVisionBackend=e.i,exports.detectGesture=e.h,exports.fist=e._,exports.landmarkToWorld=e.p,exports.landmarksCentroid=e.m,exports.ok=e.v,exports.openHand=e.y,exports.peace=e.b,exports.rfDetr=e.l,exports.thumbsUp=e.x,exports.useVisionBackend=e.f,exports.useVisionFrame=e.s,exports.yolo=e.u;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./useXRStore-8Vl3wsP5.cjs`);const e=require(`./vision-sMKG7-na.cjs`);exports.COCO_LABELS=e.c,exports.CameraBackground=e.C,exports.DEFAULT_GESTURES=e._,exports.HandTracker=e.f,exports.VisionAnchor=e.o,exports.VisionDebug=e.a,exports.VisionOverlay=e.t,exports.VisionSession=e.r,exports.VisionStatus=e.n,exports.createVisionBackend=e.i,exports.detectGesture=e.g,exports.fist=e.v,exports.landmarkToWorld=e.m,exports.landmarksCentroid=e.h,exports.ok=e.y,exports.openHand=e.b,exports.peace=e.x,exports.rfDetr=e.l,exports.thumbsUp=e.S,exports.useVisionBackend=e.p,exports.useVisionFrame=e.s,exports.yolo=e.u,exports.yoloSeg=e.d;
package/build/vision.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import "./useXRStore-Dsm1C1fI.js";
2
- import { S as e, _ as t, a as n, b as r, c as i, d as a, f as o, g as s, h as c, i as l, l as u, m as d, n as f, o as p, p as m, r as h, s as g, t as _, u as v, v as y, x as b, y as x } from "./vision-BKOfvNSR.js";
3
- export { i as COCO_LABELS, e as CameraBackground, s as DEFAULT_GESTURES, a as HandTracker, p as VisionAnchor, n as VisionDebug, _ as VisionOverlay, h as VisionSession, f as VisionStatus, l as createVisionBackend, c as detectGesture, t as fist, m as landmarkToWorld, d as landmarksCentroid, y as ok, x as openHand, r as peace, u as rfDetr, b as thumbsUp, o as useVisionBackend, g as useVisionFrame, v as yolo };
2
+ import { C as e, S as t, _ as n, a as r, b as i, c as a, d as o, f as s, g as c, h as l, i as u, l as d, m as f, n as p, o as m, p as h, r as g, s as _, t as v, u as y, v as b, x, y as S } from "./vision-Bdhf3N-w.js";
3
+ export { a as COCO_LABELS, e as CameraBackground, n as DEFAULT_GESTURES, s as HandTracker, m as VisionAnchor, r as VisionDebug, v as VisionOverlay, g as VisionSession, p as VisionStatus, u as createVisionBackend, c as detectGesture, b as fist, f as landmarkToWorld, l as landmarksCentroid, S as ok, i as openHand, x as peace, d as rfDetr, t as thumbsUp, h as useVisionBackend, _ as useVisionFrame, y as yolo, o as yoloSeg };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@omnidotdev/rdk",
3
3
  "description": "Reality Development Kit, a unified React-first XR engine",
4
- "version": "0.11.0",
4
+ "version": "0.12.1",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "main": "build/index.js",
@@ -76,7 +76,7 @@
76
76
  "@mediapipe/tasks-vision": "^0.10.0",
77
77
  "@react-three/fiber": "^9.5.0",
78
78
  "@react-three/xr": "^6.6.29",
79
- "locar": "^0.2.3",
79
+ "locar": "^0.2.7",
80
80
  "onnxruntime-web": "^1.22.0",
81
81
  "react": "^19.2.0",
82
82
  "react-dom": "^19.2.0",
@@ -111,7 +111,7 @@
111
111
  "@types/react-dom": "^19.2.3",
112
112
  "@types/three": "^0.185.0",
113
113
  "jsdom": "^29.0.0",
114
- "locar": "^0.2.3",
114
+ "locar": "^0.2.7",
115
115
  "onnxruntime-web": "^1.27.0",
116
116
  "react": "^19.2.3",
117
117
  "react-dom": "^19.2.3",
@@ -1 +0,0 @@
1
- const e=(e,t)=>{let n=e.x+e.width,r=e.y+e.height,i=t.x+t.width,a=t.y+t.height,o=Math.max(e.x,t.x),s=Math.max(e.y,t.y),c=Math.min(n,i),l=Math.min(r,a),u=Math.max(0,c-o)*Math.max(0,l-s);if(u===0)return 0;let d=e.width*e.height+t.width*t.height-u;return d<=0?0:u/d},t=(t,n)=>{let r=[...t].sort((e,t)=>t.confidence-e.confidence),i=[];for(let t of r)i.some(r=>r.label===t.label&&e(r.bbox,t.bbox)>n)||i.push(t);return i},n=(e,t,n,r,i)=>{let a=(e-i.padX)/i.scale,o=(t-i.padY)/i.scale,s=(n-i.padX)/i.scale,c=(r-i.padY)/i.scale,l=Math.max(0,Math.min(a,i.sourceWidth)),u=Math.max(0,Math.min(o,i.sourceHeight)),d=Math.max(0,Math.min(s,i.sourceWidth)),f=Math.max(0,Math.min(c,i.sourceHeight)),p=d-l,m=f-u;return p<=0||m<=0?null:{x:l,y:u,width:p,height:m}},r=e=>1/(1+Math.exp(-e)),i=e=>{let t=Object.values(e).filter(e=>e.dims.length===3),n=t.find(e=>e.dims[2]===4),r=t.find(e=>e!==n);if(!n||!r)throw Error(`RF-DETR decoder: expected a [1, Q, 4] boxes tensor and a [1, Q, C] logits tensor`);return{boxes:n,logits:r}},a={name:`rfdetr`,decode(e,t){let{boxes:a,logits:o}=i(e),s=a.dims[1],c=o.dims[2],l=a.data,u=o.data,d=[];for(let e=0;e<s;e++){let i=0,a=-1;for(let t=0;t<c;t++){let n=r(u[e*c+t]);n>i&&(i=n,a=t)}if(a<0||i<t.minConfidence)continue;let o=e*4,s=l[o]*t.inputSize,f=l[o+1]*t.inputSize,p=l[o+2]*t.inputSize,m=l[o+3]*t.inputSize,h=n(s-p/2,f-m/2,s+p/2,f+m/2,t);h&&d.push({label:t.labels[a]??String(a),confidence:i,bbox:h})}return d.sort((e,t)=>t.confidence-e.confidence).slice(0,t.maxResults)}},o=e=>{let t=Object.values(e);if(t.length===0)throw Error(`YOLO decoder: no output tensors`);return t[0]},s={name:`yolo`,decode(e,r){let{dims:i,data:a}=o(e);if(i.length!==3||i[0]!==1)throw Error(`YOLO decoder: expected [1, C, A] output, got [${i.join(`, `)}]`);let s=i[1],c=i[2],l=s-4;if(l<=0)throw Error(`YOLO decoder: too few channels (${s})`);let u=[];for(let e=0;e<c;e++){let t=0,i=-1;for(let n=0;n<l;n++){let r=a[(4+n)*c+e];r>t&&(t=r,i=n)}if(i<0||t<r.minConfidence)continue;let o=a[e],s=a[c+e],d=a[2*c+e],f=a[3*c+e],p=n(o-d/2,s-f/2,o+d/2,s+f/2,r);p&&u.push({label:r.labels[i]??String(i),confidence:t,bbox:p})}return t(u,.45).sort((e,t)=>t.confidence-e.confidence).slice(0,r.maxResults)}},c={yolo:s,rfdetr:a},l=(e=`yolo`)=>c[e]??s,u=(e,t,n)=>{let r=Math.min(n/e,n/t),i=e*r,a=t*r;return{scale:r,drawWidth:i,drawHeight:a,padX:(n-i)/2,padY:(n-a)/2}},d=(e,t)=>{let n=t*t,r=new Float32Array(3*n);for(let t=0;t<n;t++)r[t]=e[t*4]/255,r[n+t]=e[t*4+1]/255,r[2*n+t]=e[t*4+2]/255;return r};let f=null;const p=new Map,m=()=>(f||=import(`onnxruntime-web`).then(e=>(e.env.wasm.wasmPaths=`https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/`,e)),f),h=e=>{self.postMessage(e)},g=async(e,t,n,r,i,a)=>{let o=t.config.inputSize??640,{scale:s,padX:c,padY:f,drawWidth:p,drawHeight:m}=u(r,i,o),h=new OffscreenCanvas(o,o).getContext(`2d`);if(!h)throw Error(`Failed to acquire OffscreenCanvas 2D context`);h.fillStyle=`rgb(114, 114, 114)`,h.fillRect(0,0,o,o),h.drawImage(n,c,f,p,m);let{data:g}=h.getImageData(0,0,o,o),_=new e.Tensor(`float32`,d(g,o),[1,3,o,o]),v={[t.session.inputNames[0]]:_},y=await t.session.run(v),b={};for(let[e,t]of Object.entries(y))b[e]={data:t.data,dims:t.dims};let x={inputSize:o,sourceWidth:r,sourceHeight:i,scale:s,padX:c,padY:f,labels:t.config.labels??[],minConfidence:a.minConfidence,maxResults:a.maxResults};return l(t.config.decoder).decode(b,x)};self.addEventListener(`message`,async e=>{let t=e.data;switch(t.type){case`init`:h({type:`initialized`});break;case`loadModel`:{let{model:e}=t;try{let t=await(await m()).InferenceSession.create(e.path,{executionProviders:[`webgpu`,`wasm`]});p.set(e.name,{config:e,session:t}),h({type:`modelLoaded`,modelName:e.name})}catch(t){h({type:`modelError`,modelName:e.name,error:t instanceof Error?t.message:`Unknown error`})}break}case`process`:{let{imageBitmap:e,sourceWidth:n,sourceHeight:r,options:i}=t;try{let t=await m(),a=performance.now(),o=[];for(let a of p.values())o.push(...await g(t,a,e,n,r,i));h({type:`result`,result:{detections:o,frameSize:{width:n,height:r},timestamp:Date.now(),processingTime:performance.now()-a}})}catch(e){h({type:`error`,error:e instanceof Error?e.message:`Unknown error`})}finally{e.close()}break}case`dispose`:for(let{session:e}of p.values())e.release();p.clear();break}});
@@ -1 +0,0 @@
1
- const e=require(`./useXRStore-8Vl3wsP5.cjs`);let t=require(`react`),n=require(`@react-three/fiber`),r=require(`react/jsx-runtime`),i=require(`three`);var a=({constraints:e,onReady:n,onError:i,mirrored:a=!0})=>{let o=(0,t.useRef)(null),[s,c]=(0,t.useState)(!1),l=(0,t.useRef)(n);l.current=n;let u=(0,t.useRef)(i);return u.current=i,(0,t.useEffect)(()=>{let t=!1;return(async()=>{try{let n=await navigator.mediaDevices.getUserMedia({video:e||{width:{ideal:1280},height:{ideal:720},facingMode:`user`}});if(t||!o.current){for(let e of n.getTracks())e.stop();return}if(o.current.srcObject=n,await new Promise((e,t)=>{let n=o.current;if(!n){t(Error(`Video ref lost`));return}let r=()=>{n.removeEventListener(`canplay`,r),n.removeEventListener(`error`,i),e()},i=()=>{n.removeEventListener(`canplay`,r),n.removeEventListener(`error`,i),t(Error(`Video failed to load`))};n.addEventListener(`canplay`,r,{once:!0}),n.addEventListener(`error`,i,{once:!0})}),t)return;await o.current.play(),c(!0),l.current?.(o.current)}catch(e){if(t)return;let n=e instanceof Error?e:Error(`Failed to access camera`);console.error(`Camera error:`,n),u.current?.(n)}})(),()=>{if(t=!0,o.current?.srcObject){let e=o.current.srcObject;for(let t of e.getTracks())t.stop()}}},[e]),(0,r.jsx)(`video`,{ref:o,style:{position:`absolute`,inset:0,width:`100%`,height:`100%`,objectFit:`cover`,transform:a?`scaleX(-1)`:void 0,opacity:s?1:0,transition:`opacity 0.5s ease`},autoPlay:!0,playsInline:!0,muted:!0})},o=(e,t)=>e.y<t.y,s=e=>[Math.abs(e[4].x-e[9].x)>Math.abs(e[3].x-e[9].x),o(e[8],e[6]),o(e[12],e[10]),o(e[16],e[14]),o(e[20],e[18])],c=e=>{if(e.length<21)return null;let t=s(e);return t[0]&&!t[1]&&!t[2]&&!t[3]&&!t[4]?{gesture:`thumbs_up`,confidence:.9}:null},l=e=>{if(e.length<21)return null;let t=s(e);return!t[0]&&t[1]&&t[2]&&!t[3]&&!t[4]?{gesture:`peace`,confidence:.8}:null},u=e=>{if(e.length<21)return null;let t=s(e);return Math.sqrt((e[4].x-e[8].x)**2+(e[4].y-e[8].y)**2)<.05&&t[2]&&t[3]&&t[4]?{gesture:`ok`,confidence:.8}:null},d=e=>e.length<21?null:s(e).filter(Boolean).length===5?{gesture:`open_hand`,confidence:.7}:null,f=e=>e.length<21?null:s(e).filter(Boolean).length<=1?{gesture:`fist`,confidence:.7}:null,p=[c,l,u,d,f],m={gesture:`none`,confidence:0},h=(e,t=p)=>{let n=m;for(let r of t){let t=r(e);t&&t.confidence>n.confidence&&(n=t)}return n},g=(e,t,n,r=!0)=>{let i=t.width/t.height,a=n.width/n.height,o=a>i?a/i:1,s=a>i?1:i/a,c=.5+(e.x-.5)*o,l=.5+(e.y-.5)*s;return[(r?.5-c:c-.5)*t.width,(.5-l)*t.height,0]},_=e=>{let t=e.length||1,n=0,r=0,i=0;for(let t of e)n+=t.x,r+=t.y,i+=t.z??0;return{x:n/t,y:r/t,z:i/t}},v={isPending:!0,isSuccess:!1,provider:null,videoElement:null,onDetection:()=>()=>{}},y=()=>{let t=e.r(e=>e.backends).get(e.i.VISION);return t?{...t.getInternal(),isPending:!1,isSuccess:!0}:v},b=({onHandMove:e,onGesture:a,landmarkIndex:o=9,mirror:s=!0,children:c})=>{let{onDetection:l,isSuccess:u}=y(),{viewport:d}=(0,n.useThree)(),f=(0,t.useRef)(null),p=(0,t.useRef)(new i.Vector3),m=(0,t.useRef)(``);return(0,t.useEffect)(()=>{if(u)return l(e=>{f.current=e})},[u,l]),(0,n.useFrame)(()=>{let t=f.current;if(!t)return;let n=t.hands[0];if(!n||n.landmarks.length===0)return;let[r,i,c]=g(n.landmarks[o]??n.landmarks[0],d,t.frameSize,s);p.current.set(r,i,c),e?.(p.current);let l=h(n.landmarks);l.gesture!==m.current&&(m.current=l.gesture,a?.(l.gesture,l.confidence))}),(0,r.jsx)(`group`,{children:c})},x=`person.bicycle.car.motorcycle.airplane.bus.train.truck.boat.traffic light.fire hydrant.stop sign.parking meter.bench.bird.cat.dog.horse.sheep.cow.elephant.bear.zebra.giraffe.backpack.umbrella.handbag.tie.suitcase.frisbee.skis.snowboard.sports ball.kite.baseball bat.baseball glove.skateboard.surfboard.tennis racket.bottle.wine glass.cup.fork.knife.spoon.bowl.banana.apple.sandwich.orange.broccoli.carrot.hot dog.pizza.donut.cake.chair.couch.potted plant.bed.dining table.toilet.tv.laptop.mouse.remote.keyboard.cell phone.microwave.oven.toaster.sink.refrigerator.book.clock.vase.scissors.teddy bear.hair drier.toothbrush`.split(`.`),S=(e,t={})=>({name:`yolo`,inputSize:640,labels:[...x],...t,path:e,decoder:`yolo`}),C=(e,t={})=>({name:`rf-detr`,inputSize:560,labels:[...x],...t,path:e,decoder:`rfdetr`}),w=e=>{let{isSuccess:n,onDetection:r}=y(),[i,a]=(0,t.useState)(null),o=e?.throttle??16,s=(0,t.useRef)(0);return(0,t.useEffect)(()=>{if(!n){a(null);return}return r(e=>{let t=performance.now();t-s.current<o||(s.current=t,a(e))})},[n,r,o]),i},T=478,E=(e,t)=>t===`faces`?e.faces:t===`poses`?e.poses:e.hands,D=({task:e,index:a=0,debug:o=!1,mirror:s=!0,smoothing:c=.4,children:l})=>{let{onDetection:u,isSuccess:d}=y(),{viewport:f}=(0,n.useThree)(),p=(0,t.useRef)(null),m=(0,t.useRef)(null),h=(0,t.useRef)(null),v=(0,t.useMemo)(()=>new i.Object3D,[]),b=(0,t.useMemo)(()=>new i.Vector3,[]);return(0,t.useEffect)(()=>{m.current&&(m.current.visible=!1),h.current&&(h.current.count=0)},[]),(0,t.useEffect)(()=>{if(d)return u(e=>{p.current=e})},[d,u]),(0,n.useFrame)(()=>{let t=p.current,n=m.current;if(!t||!n)return;let r=E(t,e)[a],i=h.current;if(!r||r.landmarks.length===0){n.visible=!1,i&&(i.count=0);return}let l=n.visible;n.visible=!0;let[u,d,y]=g(_(r.landmarks),f,t.frameSize,s);if(b.set(u,d,y),!l||c>=1?n.position.copy(b):n.position.lerp(b,c),o&&i){let e=n.position,a=Math.min(r.landmarks.length,T);for(let n=0;n<a;n++){let[a,o,c]=g(r.landmarks[n],f,t.frameSize,s);v.position.set(a-e.x,o-e.y,c-e.z),v.updateMatrix(),i.setMatrixAt(n,v.matrix)}i.count=a,i.instanceMatrix.needsUpdate=!0}}),(0,r.jsxs)(`group`,{ref:m,children:[l,o&&(0,r.jsxs)(`instancedMesh`,{ref:h,args:[void 0,void 0,T],children:[(0,r.jsx)(`sphereGeometry`,{args:[.02,6,6]}),(0,r.jsx)(`meshBasicMaterial`,{color:`#00ff88`})]})]})},O=({tasks:e,width:t=320,height:n=240,style:i})=>{let a=w({throttle:50});return(0,r.jsxs)(`div`,{style:{background:`rgba(0, 0, 0, 0.8)`,color:`#00ff88`,padding:`8px`,borderRadius:`8px`,fontFamily:`monospace`,fontSize:`0.75rem`,width:t,height:n,overflow:`auto`,...i},children:[(0,r.jsxs)(`div`,{children:[`Frame: `,a?`active`:`none`]}),a&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(`div`,{children:[`Size: `,a.frameSize.width,`x`,a.frameSize.height]}),e.includes(`hands`)&&(0,r.jsxs)(`div`,{children:[`Hands: `,a.hands.length]}),e.includes(`faces`)&&(0,r.jsxs)(`div`,{children:[`Faces: `,a.faces.length]}),e.includes(`poses`)&&(0,r.jsxs)(`div`,{children:[`Poses: `,a.poses.length]}),e.includes(`objects`)&&(0,r.jsxs)(`div`,{children:[`Objects: `,a.objects.length]})]})]})},k=class{type=`mediapipe`;models={};isInitialized=!1;isProcessing=!1;isDisposed=!1;videoElement=null;animationId=null;lastProcessTime=0;callbacks=[];options;constructor(e){this.options=e}async initialize(e){this.videoElement=e;let{FilesetResolver:t,HandLandmarker:n,FaceLandmarker:r,PoseLandmarker:i}=await import(`@mediapipe/tasks-vision`),a=await t.forVisionTasks(`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10/wasm`),o=this.options.useGpu??!0?`GPU`:`CPU`,s=async e=>{if(o===`CPU`)return e(`CPU`);try{return await e(`GPU`)}catch{return console.warn(`MediaPipe GPU delegate failed, falling back to CPU`),e(`CPU`)}},c=new Set(this.options.tasks??[`hands`,`faces`,`poses`]),l=[`hands`,`faces`,`poses`].filter(e=>c.has(e)),u=0;c.has(`hands`)&&(this.options.onProgress?.({step:++u,total:l.length,label:`hand landmarker`}),this.models.handLandmarker=await s(e=>n.createFromOptions(a,{baseOptions:{modelAssetPath:`https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task`,delegate:e},runningMode:`VIDEO`,numHands:2,minHandDetectionConfidence:.7,minHandPresenceConfidence:.5,minTrackingConfidence:.5}))),c.has(`faces`)&&(this.options.onProgress?.({step:++u,total:l.length,label:`face landmarker`}),this.models.faceLandmarker=await s(e=>r.createFromOptions(a,{baseOptions:{modelAssetPath:`https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task`,delegate:e},runningMode:`VIDEO`,numFaces:1,minFaceDetectionConfidence:.7,minFacePresenceConfidence:.5,minTrackingConfidence:.5,outputFaceBlendshapes:!1,outputFacialTransformationMatrixes:!1}))),c.has(`poses`)&&(this.options.onProgress?.({step:++u,total:l.length,label:`pose landmarker`}),this.models.poseLandmarker=await s(e=>i.createFromOptions(a,{baseOptions:{modelAssetPath:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_lite/float16/1/pose_landmarker_lite.task`,delegate:e},runningMode:`VIDEO`,numPoses:1,minPoseDetectionConfidence:.7,minPosePresenceConfidence:.5,minTrackingConfidence:.5,outputSegmentationMasks:this.options.segmentation??!1}))),this.isInitialized=!0,this.options.onProgress?.(null)}startDetection(){!this.isInitialized||!this.videoElement||this.isProcessing||(this.isProcessing=!0,this.processFrame())}stopDetection(){this.isProcessing=!1,this.animationId&&=(cancelAnimationFrame(this.animationId),null)}onDetection(e){return this.callbacks.push(e),()=>{let t=this.callbacks.indexOf(e);t>-1&&this.callbacks.splice(t,1)}}dispose(){this.isDisposed=!0,this.stopDetection(),this.models.handLandmarker&&this.models.handLandmarker.close(),this.models.faceLandmarker&&this.models.faceLandmarker.close(),this.models.poseLandmarker&&this.models.poseLandmarker.close(),this.models={},this.videoElement=null,this.callbacks=[],this.isInitialized=!1,this.isProcessing=!1}processFrame=()=>{if(!this.isProcessing||!this.videoElement||this.isDisposed)return;let e=performance.now(),t=this.options.throttle??16;if(e-this.lastProcessTime<t){this.animationId=requestAnimationFrame(this.processFrame);return}let{videoWidth:n,videoHeight:r}=this.videoElement;if(n===0||r===0){this.animationId=requestAnimationFrame(this.processFrame);return}this.lastProcessTime=e;let i=e;try{let e={hands:[],faces:[],poses:[],objects:[],timestamp:i,frameSize:{width:n,height:r}};if(this.models.handLandmarker){let t=this.models.handLandmarker.detectForVideo(this.videoElement,i);e.hands=t.landmarks.map((e,n)=>({landmarks:e.map(e=>({x:e.x,y:e.y,z:e.z||0})),confidence:t.handednesses?.[n]?.[0]?.score||.5}))}if(this.models.faceLandmarker&&(e.faces=this.models.faceLandmarker.detectForVideo(this.videoElement,i).faceLandmarks.map(e=>{let t=e.map(e=>e.x),n=e.map(e=>e.y),r=(Math.max(...t)-Math.min(...t))*(Math.max(...n)-Math.min(...n)),i=Math.min(.95,Math.max(.6,r*4));return{landmarks:e.map(e=>({x:e.x,y:e.y,z:e.z||0})),confidence:i}})),this.models.poseLandmarker){let t=this.models.poseLandmarker.detectForVideo(this.videoElement,i);e.poses=t.landmarks.map(e=>{let t=0,n=0;for(let r of e)typeof r.visibility==`number`&&(t+=r.visibility,n++);let r=n>0?t/n:.5;return{landmarks:e.map(e=>({x:e.x,y:e.y,z:e.z||0})),confidence:r}});let n=t.segmentationMasks?.[0];if(n){let t=new OffscreenCanvas(n.width,n.height).getContext(`2d`),r=n.getAsFloat32Array(),i=t.createImageData(n.width,n.height);for(let e=0;e<r.length;e++){let t=r[e]*255;i.data[e*4]=t,i.data[e*4+1]=t,i.data[e*4+2]=t,i.data[e*4+3]=255}e.segmentationMask=i}}this.handleResult(e)}catch(e){console.error(`Vision processing error:`,e)}this.animationId=requestAnimationFrame(this.processFrame)};handleResult(e){let t=this.options.minConfidence??.7,n=this.options.maxResults??2,r={...e,hands:e.hands.filter(e=>e.confidence>=t).slice(0,n),faces:e.faces.filter(e=>e.confidence>=t).slice(0,n),poses:e.poses.filter(e=>e.confidence>=t).slice(0,n),objects:[]};for(let e of this.callbacks)try{e(r)}catch(e){console.error(`Error in vision callback:`,e)}}},A=5e3,j=class{type=`onnx`;worker=null;isInitialized=!1;isDisposed=!1;isProcessing=!1;videoElement=null;animationId=null;loadedModels=new Map;lastProcessTime=0;processingStartTime=0;callbacks=[];options;messageHandler=null;pendingModelCallbacks=new Map;constructor(e){this.options=e}post(e,t){t?this.worker?.postMessage(e,t):this.worker?.postMessage(e)}async initialize(e){this.videoElement=e,this.worker=new Worker(new URL(`/assets/onnxWorker-B_g0sj2t.js`,``+{}.url),{type:`module`}),await new Promise((e,t)=>{let n=setTimeout(()=>{t(Error(`ONNX worker initialization timeout`))},1e4);this.messageHandler=r=>{let i=r.data;switch(i.type){case`initialized`:clearTimeout(n),this.isInitialized=!0,e();break;case`result`:this.isProcessing=!1,this.handleResult(i.result);break;case`modelLoaded`:{let e=this.pendingModelCallbacks.get(i.modelName);e&&(this.pendingModelCallbacks.delete(i.modelName),e.resolve());break}case`modelError`:{let e=this.pendingModelCallbacks.get(i.modelName);e&&(this.pendingModelCallbacks.delete(i.modelName),e.reject(Error(i.error)));break}case`error`:this.isProcessing=!1,this.isInitialized?console.error(`ONNX worker error:`,i.error):(clearTimeout(n),t(Error(i.error)));break}},this.worker?.addEventListener(`message`,this.messageHandler),this.post({type:`init`})});let t=this.options.onnx?.models??[];for(let e of t)await this.loadModel(e)}startDetection(){if(!this.isInitialized||!this.videoElement){console.warn(`ONNX provider not initialized`);return}let e=()=>{if(!this.videoElement||!this.isInitialized)return;let t=Date.now(),n=this.options.throttle??100;if(t-this.lastProcessTime<n){this.animationId=requestAnimationFrame(e);return}this.isProcessing&&this.processingStartTime>0&&t-this.processingStartTime>A&&(console.warn(`ONNX processing stall detected, resetting`),this.isProcessing=!1),this.isProcessing||this.processCurrentFrame(),this.animationId=requestAnimationFrame(e)};e()}stopDetection(){this.animationId&&=(cancelAnimationFrame(this.animationId),null),this.isProcessing=!1}onDetection(e){return this.callbacks.push(e),()=>{let t=this.callbacks.indexOf(e);t>-1&&this.callbacks.splice(t,1)}}dispose(){this.isDisposed=!0,this.stopDetection(),this.worker&&=(this.messageHandler&&=(this.worker.removeEventListener(`message`,this.messageHandler),null),this.post({type:`dispose`}),this.worker.terminate(),null),this.videoElement=null,this.callbacks.length=0,this.loadedModels.clear(),this.pendingModelCallbacks.clear(),this.isInitialized=!1}async loadModel(e){if(!this.worker)throw Error(`Worker not initialized`);let t=new Promise((t,n)=>{this.pendingModelCallbacks.set(e.name,{resolve:t,reject:n})});this.post({type:`loadModel`,model:e}),await t,this.loadedModels.set(e.name,e)}processCurrentFrame(){if(!this.videoElement||!this.worker||this.isProcessing)return;let e=Date.now();this.isProcessing=!0,this.lastProcessTime=e,this.processingStartTime=e;let{videoWidth:t,videoHeight:n}=this.videoElement;createImageBitmap(this.videoElement).then(e=>{if(this.isDisposed){e.close();return}this.post({type:`process`,imageBitmap:e,sourceWidth:t,sourceHeight:n,options:{minConfidence:this.options.minConfidence??.5,maxResults:this.options.maxResults??100}},[e])},e=>{this.isProcessing=!1,console.error(`Error creating ImageBitmap:`,e)})}handleResult(e){let t=this.options.minConfidence??.5,n=this.options.maxResults??100,r={hands:[],faces:[],poses:[],objects:e.detections.filter(e=>e.confidence>=t).sort((e,t)=>t.confidence-e.confidence).slice(0,n),timestamp:e.timestamp,frameSize:e.frameSize,processingTime:e.processingTime};for(let e of this.callbacks)try{e(r)}catch(e){console.error(`Error in ONNX detection callback:`,e)}}},M=e=>e.provider===`onnx`?new j(e):new k(e),N=async e=>{let t=document.createElement(`video`);t.style.display=`none`,document.body.appendChild(t);try{return t.srcObject=await navigator.mediaDevices.getUserMedia({video:{width:{ideal:1280,min:640},height:{ideal:720,min:480},facingMode:e.provider===`onnx`?`environment`:`user`,frameRate:{ideal:30,min:15}}}),t.playsInline=!0,t.muted=!0,await new Promise((e,n)=>{t.onloadedmetadata=()=>{t.play().then(e).catch(n)},t.onerror=n}),t}catch(e){throw document.body.removeChild(t),e}},P=e=>{if(!e)return;let t=e.srcObject;if(t)for(let e of t.getTracks())e.stop();e.parentNode&&e.parentNode.removeChild(e)},F=t=>{let n=null,r=null,i=!1,a=null,o=[],s=e=>(o.push(e),()=>{let t=o.indexOf(e);t>-1&&o.splice(t,1)});return{type:e.i.VISION,async init(e){t.videoElement?(r=t.videoElement,i=!1):(r=await N(t),i=!0),n=M(t),await n.initialize(r),a=n.onDetection(e=>{for(let t of o)try{t(e)}catch(e){console.error(`Error in vision detection callback:`,e)}}),n.startDetection()},update(e){},dispose(){a?.(),a=null,n?.dispose(),i&&P(r),r=null,n=null,o.length=0},getInternal:()=>({provider:n,videoElement:r,onDetection:s})}},I=({options:i,children:a,onError:o})=>{let{scene:s,camera:c,gl:l}=(0,n.useThree)(),{registerBackend:u,unregisterBackend:d}=e.r(),f=(0,t.useRef)(null),p=(0,t.useRef)(i);p.current=i;let m=(0,t.useRef)(o);return m.current=o,(0,t.useEffect)(()=>{if(f.current)return;let e=!1;return(async()=>{try{let t=F(p.current);if(e)return;if(await u(t,{scene:s,camera:c,renderer:l}),e){d(t);return}f.current=t}catch(e){let t=e instanceof Error?e:Error(String(e));console.error(`[VisionSession] Failed to initialize:`,t),m.current?.(t)}})(),()=>{e=!0,f.current&&=(d(f.current),null)}},[s,c,l,u,d]),(0,r.jsx)(r.Fragment,{children:a})},L=({tasks:e,progress:t,showDebug:n,onToggleDebug:i})=>{let a=w({throttle:100}),o=e=>{if(!a)return!1;switch(e){case`hands`:return a.hands.length>0;case`faces`:return a.faces.length>0;case`poses`:return a.poses.length>0;case`objects`:return a.objects.length>0;default:return!1}},s=e.some(o),c=a!==null;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(`div`,{style:{position:`fixed`,top:`20px`,left:`20px`,background:`rgba(0, 0, 0, 0.7)`,color:`white`,padding:`12px`,borderRadius:`8px`,fontFamily:`system-ui, sans-serif`,fontSize:`0.9rem`,zIndex:1e3},children:[(0,r.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,marginBottom:`8px`},children:[(0,r.jsx)(`div`,{style:{width:`8px`,height:`8px`,borderRadius:`50%`,background:c?`#00ff88`:`#ffaa00`}}),(0,r.jsx)(`span`,{children:s?`Active`:c?`Ready`:t?`Loading models (${t.step}/${t.total}) ${t.label}...`:`Starting...`})]}),e.map(e=>(0,r.jsxs)(`div`,{style:{fontSize:`0.8rem`,opacity:.8,display:`flex`,justifyContent:`space-between`,gap:`12px`},children:[(0,r.jsx)(`span`,{children:e}),(0,r.jsx)(`span`,{children:o(e)?`active`:c?`idle`:`...`})]},e))]}),(0,r.jsxs)(`button`,{onClick:i,type:`button`,style:{position:`fixed`,top:`20px`,right:`20px`,background:`rgba(0, 0, 0, 0.7)`,color:`white`,border:`1px solid #333`,padding:`8px 12px`,borderRadius:`6px`,cursor:`pointer`,fontFamily:`system-ui, sans-serif`,fontSize:`0.8rem`,zIndex:1e3},children:[n?`Hide`:`Show`,` Debug`]})]})},R={},z=({tasks:e=[`hands`],options:i,children:o,showDebug:s=!1,cameraConstraints:c,canvasStyle:l=R,onReady:u,onError:d})=>{let[f,p]=(0,t.useState)(s),[m,h]=(0,t.useState)(null),[g,_]=(0,t.useState)(null),v=(0,t.useRef)(u);v.current=u;let y=(0,t.useRef)(_);y.current=_;let b=(0,t.useCallback)(e=>y.current(e),[]),x=(0,t.useCallback)(e=>{h(e),v.current?.()},[]),S=(0,t.useMemo)(()=>({tasks:e,minConfidence:.6,maxResults:2,useGpu:!0,...i,videoElement:m??void 0,onProgress:b}),[e,i,m,b]);return(0,r.jsxs)(`div`,{style:{position:`relative`,width:`100%`,height:`100%`},children:[(0,r.jsx)(a,{constraints:c,onReady:x,onError:d}),m&&(0,r.jsx)(n.Canvas,{style:{position:`absolute`,inset:0,pointerEvents:`none`,...l},camera:{position:[0,0,5],fov:75},gl:{alpha:!0,premultipliedAlpha:!1},children:(0,r.jsx)(B,{options:S,onError:d,children:o})}),(0,r.jsx)(L,{tasks:e,progress:g,showDebug:f,onToggleDebug:()=>p(e=>!e)}),f&&(0,r.jsx)(O,{tasks:e,width:320,height:240,style:{position:`fixed`,bottom:`80px`,right:`20px`,maxWidth:`calc(100vw - 40px)`,overflow:`hidden`}})]})},B=({options:e,onError:t,children:n})=>(0,r.jsxs)(I,{options:e,onError:t,children:[(0,r.jsx)(`ambientLight`,{intensity:.6}),(0,r.jsx)(`directionalLight`,{position:[10,10,10],intensity:.8}),n]});Object.defineProperty(exports,`S`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return d}});