@vincentt-xr/sdk 2.0.0-alpha.4 → 2.0.0-alpha.6

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 (67) hide show
  1. package/GROUNDING.md +11 -4
  2. package/README.md +85 -52
  3. package/dist/{DebuggerUI-DhKTXTY2.js → DebuggerUI-C_rbLdkh.js} +1 -1
  4. package/dist/{DebuggerUI-bnGHSSOb.cjs → DebuggerUI-DYT_dk1E.cjs} +1 -1
  5. package/dist/FaceMeshRenderer-D1WsrTLA.cjs +155 -0
  6. package/dist/FaceMeshRenderer-DSCd1H55.js +1264 -0
  7. package/dist/{FaceRetouch-Bg-OBU4n.js → FaceRetouch-CMJbGThL.js} +30 -30
  8. package/dist/{FaceRetouch-TZeBGIqW.cjs → FaceRetouch-DsE0Dbw-.cjs} +1 -1
  9. package/dist/components/FaceMesh/canonical/CanonicalFaceMeshRenderer.d.ts +11 -1
  10. package/dist/components/FaceMesh/canonical/geometryGroups.d.ts +1 -1
  11. package/dist/components/FaceMesh/canonical/parseCanonicalFaceModel.d.ts +1 -0
  12. package/dist/components/LipEffect/LipEffect.d.ts +2 -0
  13. package/dist/components/LipEffect/LipEffectMaterial.d.ts +10 -0
  14. package/dist/components/LipEffect/defaults.d.ts +9 -0
  15. package/dist/components/LipEffect/index.d.ts +4 -0
  16. package/dist/components/LipEffect/types.d.ts +22 -0
  17. package/dist/{contexts-B2_NsTnk.js → contexts-DvQI4PqI.js} +6 -3
  18. package/dist/contexts-h-9TRH0r.cjs +1 -0
  19. package/dist/debug-ui/media-source.cjs +1 -1
  20. package/dist/debug-ui/media-source.js +1 -1
  21. package/dist/debug-ui.cjs +1 -1
  22. package/dist/debug-ui.js +10 -10
  23. package/dist/entries/face-effects.d.ts +2 -0
  24. package/dist/face-effects.cjs +1 -1
  25. package/dist/face-effects.js +621 -508
  26. package/dist/{getFaceInfo-4DhcPZDJ.js → getFaceInfo-B43Cwq4n.js} +1 -1
  27. package/dist/{getFaceInfo-QOQ_dc-W.cjs → getFaceInfo-DEzcL_Ub.cjs} +1 -1
  28. package/dist/{index-D1kj6uc-.js → index-B-s4YbWu.js} +1 -1
  29. package/dist/index-C0-fg1Hk.cjs +1 -0
  30. package/dist/{index-C9yQVzAh.cjs → index-CY7Z8cHV.cjs} +1 -1
  31. package/dist/{index-ZaDEzDtR.cjs → index-CxMEeCRP.cjs} +1 -1
  32. package/dist/{index-WPPnlFO1.cjs → index-D67hHm44.cjs} +1 -1
  33. package/dist/{index-CNGzE49z.cjs → index-DPPpU5By.cjs} +1 -1
  34. package/dist/{index-g250Tqme.js → index-DYfY9ljy.js} +1 -1
  35. package/dist/{index-Cj3fGDtZ.js → index-G_5h_FJQ.js} +8 -8
  36. package/dist/{index-BMeBJ0dV.js → index-I4eF5TKT.js} +227 -191
  37. package/dist/{index-72Wb15Ca.js → index-uE3sKczj.js} +1 -1
  38. package/dist/{internal-Dtvo4WYo.cjs → internal-MvKrz0Nt.cjs} +1 -1
  39. package/dist/{internal-34pb7djs.js → internal-ldPYiUF0.js} +3 -3
  40. package/dist/internal.cjs +1 -1
  41. package/dist/internal.js +1 -1
  42. package/dist/low-level.cjs +1 -1
  43. package/dist/low-level.js +11 -11
  44. package/dist/main.cjs +1 -1
  45. package/dist/main.js +12 -12
  46. package/dist/{renderGroups-jSUOY1Oq.cjs → renderGroups-BJsx32q5.cjs} +1 -1
  47. package/dist/{renderGroups-CPWUX6z9.js → renderGroups-CFt1yYLB.js} +1 -1
  48. package/dist/{renderPasses-CLlYRdMk.js → renderPasses-C72MbZ-a.js} +4 -4
  49. package/dist/{renderPasses-KUJUSevp.cjs → renderPasses-D-Krl6D0.cjs} +1 -1
  50. package/dist/scene-object.cjs +1 -1
  51. package/dist/scene-object.js +2 -2
  52. package/dist/{selectors-DLxL8Q66.js → selectors-ByKNTXeA.js} +1 -1
  53. package/dist/{selectors-S8g25ke9.cjs → selectors-CAwmL9VW.cjs} +1 -1
  54. package/dist/{session-DP8AF7Rg.cjs → session-CANvoLD6.cjs} +1 -1
  55. package/dist/{session-CbtvwiaD.js → session-Dhi0OqZo.js} +1 -1
  56. package/dist/tracking.cjs +1 -1
  57. package/dist/tracking.js +9 -9
  58. package/dist/{useFaceInfo-BvZeUBsL.cjs → useFaceInfo-BSZq7AO1.cjs} +1 -1
  59. package/dist/{useFaceInfo-C06EyScd.js → useFaceInfo-FVQBBNdY.js} +3 -3
  60. package/dist/{useFaceResults-CCNiH7VZ.cjs → useFaceResults-C3oZkn2Z.cjs} +1 -1
  61. package/dist/{useFaceResults-C1Ppc8rS.js → useFaceResults-D62STzT1.js} +1 -1
  62. package/dist/utils/visionWasm.d.ts +18 -0
  63. package/package.json +2 -2
  64. package/dist/FaceMeshRenderer-B2i2NW71.js +0 -1195
  65. package/dist/FaceMeshRenderer-BSOq1OnG.cjs +0 -155
  66. package/dist/contexts-BgWfyxre.cjs +0 -1
  67. package/dist/index-Da7uycur.cjs +0 -1
@@ -1,155 +0,0 @@
1
- "use strict";const u=require("react/jsx-runtime"),ee=require("@react-three/fiber"),i=require("react"),J=require("three"),q=require("./index-Da7uycur.cjs"),je=require("./selectors-S8g25ke9.cjs"),_e=require("./index-ZaDEzDtR.cjs"),Xt=require("@react-three/drei");function Wt(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const y=Wt(J),ue=8,V={type:"linear",stops:[{offset:0,color:"#38bdf8"},{offset:1,color:"#a78bfa"}],angle:0,center:{x:.5,y:.5},radius:.5},Yt=e=>{const n=e.slice(0,ue).map(t=>({...t,offset:J.MathUtils.clamp(t.offset,0,1)})).sort((t,r)=>t.offset-r.offset);return n.length>=2?n:V.stops.map(t=>({...t}))},Be=e=>({...V,...e,center:{...V.center,...e==null?void 0:e.center},radius:Math.max(.01,(e==null?void 0:e.radius)??V.radius),stops:Yt((e==null?void 0:e.stops)??V.stops)}),Kt=`
2
- varying vec2 vPosition;
3
- void main() {
4
- vPosition = position.xy;
5
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
6
- }
7
- `,$t=`
8
- #define MAX_STOPS 8
9
- uniform vec3 stopColors[MAX_STOPS];
10
- uniform float stopOffsets[MAX_STOPS];
11
- uniform int stopCount;
12
- uniform int gradientType;
13
- uniform vec2 direction;
14
- uniform vec2 center;
15
- uniform float radius;
16
- uniform float angleOffset;
17
- uniform float opacity;
18
- varying vec2 vPosition;
19
-
20
- vec3 sampleGradient(float amount) {
21
- vec3 color = stopColors[0];
22
- for (int index = 1; index < MAX_STOPS; index++) {
23
- if (index >= stopCount) break;
24
- if (amount <= stopOffsets[index]) {
25
- float width = max(0.0001, stopOffsets[index] - stopOffsets[index - 1]);
26
- return mix(stopColors[index - 1], stopColors[index], clamp((amount - stopOffsets[index - 1]) / width, 0.0, 1.0));
27
- }
28
- color = stopColors[index];
29
- }
30
- return color;
31
- }
32
-
33
- void main() {
34
- vec2 delta = vPosition - center;
35
- float amount;
36
- if (gradientType == 1) {
37
- amount = clamp(length(delta) / radius, 0.0, 1.0);
38
- } else if (gradientType == 2) {
39
- amount = fract(atan(delta.y, delta.x) / 6.28318530718 + 0.5 + angleOffset);
40
- } else {
41
- amount = clamp(dot(delta, direction) + 0.5, 0.0, 1.0);
42
- }
43
- gl_FragColor = vec4(sampleGradient(amount), opacity);
44
- }
45
- `,qt={linear:0,radial:1,angular:2},Ve=({opacity:e=1,value:n})=>{const t=i.useMemo(()=>{const r=Be(n),a=J.MathUtils.degToRad(r.angle),o=r.stops.map(c=>new J.Color(c.color)),s=r.stops.map(c=>c.offset);for(;o.length<ue;)o.push(o[o.length-1]);for(;s.length<ue;)s.push(1);return{stopColors:{value:o},stopOffsets:{value:s},stopCount:{value:r.stops.length},gradientType:{value:qt[r.type]},direction:{value:new J.Vector2(Math.cos(a),Math.sin(a))},center:{value:new J.Vector2(r.center.x-.5,.5-r.center.y)},radius:{value:r.radius},angleOffset:{value:r.angle/360},opacity:{value:e}}},[e,n]);return u.jsx("shaderMaterial",{uniforms:t,vertexShader:Kt,fragmentShader:$t,transparent:e<1,depthTest:!1,depthWrite:!1,toneMapped:!1})},Qt="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO2YpZcAAAAASUVORK5CYII=",Zt={source:"solid",color:"#ffffff",opacity:1,textureUrl:"",gradient:V},ke=e=>({...V,stops:[{offset:0,color:"#ffffff"},{offset:1,color:e}]}),Jt=({depthTest:e,depthWrite:n,settings:t,side:r,toneMapped:a})=>{const o=ee.useLoader(y.TextureLoader,t.textureUrl||Qt);return u.jsx("meshBasicMaterial",{color:t.color,map:o,transparent:!0,opacity:t.opacity,side:r,depthWrite:n,depthTest:e,toneMapped:a})},Xe=({depthTest:e=!1,depthWrite:n=!1,settings:t,side:r,toneMapped:a=!1})=>{const o=i.useMemo(()=>t.gradient??ke(t.color),[t.color,t.gradient]);return t.source==="gradient"?u.jsx(Ve,{value:o,opacity:t.opacity}):t.source==="texture"?u.jsx(Jt,{settings:t,side:r,depthTest:e,depthWrite:n,toneMapped:a}):u.jsx("meshBasicMaterial",{color:t.color,transparent:!0,opacity:t.opacity,side:r,depthWrite:n,depthTest:e,toneMapped:a})},be=Math.PI/180,xe=180/Math.PI,N=e=>Number(e.toFixed(6)),Ce={enabled:!0,linked:{position:!1,rotation:!1,scale:!1},showTransformControls:!1,transformControlMode:"translate",transformControlSpace:"local",position:{x:0,y:0,z:0},rotation:{x:0,y:0,z:0},scale:{x:1,y:1,z:1},visible:!0},en=({children:e,objectRef:n,onChange:t,value:r})=>{const a=i.useRef(null),o=i.useRef(n);o.current=n;const[s,c]=i.useState(null),_=i.useCallback(d=>{var S;a.current=d,c(d),(S=o.current)==null||S.call(o,d)},[]),R=i.useCallback(()=>{const d=a.current;!d||!t||t({...r,position:{x:N(d.position.x),y:N(d.position.y),z:N(d.position.z)},rotation:{x:N(d.rotation.x*xe),y:N(d.rotation.y*xe),z:N(d.rotation.z*xe)},scale:{x:N(d.scale.x),y:N(d.scale.y),z:N(d.scale.z)}})},[t,r]);return r.enabled?u.jsxs(u.Fragment,{children:[u.jsx("group",{ref:_,position:[r.position.x,r.position.y,r.position.z],rotation:[r.rotation.x*be,r.rotation.y*be,r.rotation.z*be],scale:[r.scale.x,r.scale.y,r.scale.z],visible:r.visible,children:e}),s&&r.showTransformControls&&u.jsx(Xt.TransformControls,{object:s,mode:r.transformControlMode,space:r.transformControlSpace,size:.85,onMouseUp:R,onObjectChange:R})]}):null},ae=e=>Math.min(1,Math.max(0,e)),k=(e,n,t)=>ae(1-Math.abs(e-n)/t),tn=e=>{let n=1/0,t=-1/0,r=1/0,a=-1/0;for(const c of e)n=Math.min(n,c.x),t=Math.max(t,c.x),r=Math.min(r,c.y),a=Math.max(a,c.y);const o=Math.max(t-n,.001),s=Math.max(a-r,.001);return{centerX:n+o*.5,centerY:r+s*.5,width:o,height:s}},nn=e=>e!=null&&e.enabled?(e.strength??1)!==0&&Object.entries(e).some(([n,t])=>n!=="enabled"&&n!=="strength"&&typeof t=="number"&&t!==0):!1,rn=(e,n,t,r)=>{const a=t.enabled?t.strength??1:0;if(a===0)return r.x=e.x,r.y=e.y,r.z=e.z,r;const o=(e.x-n.centerX)/n.width,s=(e.y-n.centerY)/n.height,c=Math.abs(o),_=ae((-s+.42)/.55),R=k(s,-.02,.34),d=k(s,-.24,.16)*ae((c-.05)/.28),S=k(s,.02,.26)*k(c,0,.18),C=k(s,.29,.18)*k(c,0,.36),I=ae((s-.16)/.36),b=R*k(c,.34,.22),m=_*k(c,0,.48),x=k(s,-.19,.1)*ae((c-.05)/.3),X=k(s,.48,.2)*k(c,0,.26);let f=e.x,l=e.y,h=e.z;const A=(K,U=1)=>{f+=o*n.width*K*a*U},E=(K,U=1)=>{l+=s*n.height*K*a*U};A(t.faceWidth??0),E(t.faceHeight??0),A(t.faceRoundness??0,R*(1-c)),l-=n.height*(t.midfaceHeight??0)*a*R*.25,E(-(t.foreheadHeight??0),m),A(t.foreheadWidth??0,m),A(t.cheekboneWidth??0,k(s,-.06,.16)*k(c,.34,.2)),A(t.cheekWidth??0,b),A(t.jawWidth??0,I),E(t.chinHeight??0,X),l-=n.height*(t.scalpHeight??0)*a*_*.3,h-=(t.midfaceDepth??0)*a*R*.08,h+=(t.cheekHollowness??0)*a*b*.06,h-=(t.browDepth??0)*a*x*.05,l-=n.height*(t.browHeight??0)*a*x*.2,f+=Math.sign(o||1)*n.width*(t.browDistance??0)*a*x*.16;const v=(t.headCurve??0)*a*(s+.1);h-=v*v*.04*Math.sign(t.headCurve??0),f+=n.width*(t.faceTwist??0)*a*s*.18;const j=(t.faceSwirl??0)*a*.22;f+=-s*n.width*j,l+=o*n.height*j;const W=o<0?t.leftEyeSize??0:t.rightEyeSize??0,L=((t.eyeSize??0)+W)*a*d;f+=o*n.width*L*.45,l+=(s+.24)*n.height*L*.7,f+=Math.sign(o||1)*n.width*(t.eyeDistance??0)*a*d*.2,f+=n.width*(o<0?t.leftEyeX??0:t.rightEyeX??0)*a*d*.15,l+=n.height*(o<0?t.leftEyeY??0:t.rightEyeY??0)*a*d*.15;const Y=(t.noseSize??0)*a*S;return f+=o*n.width*Y*.7,l+=(s-.02)*n.height*Y*.5,l+=n.height*(t.noseLength??0)*a*S*Math.max(s+.08,0)*.4,h-=(t.noseSize??0)*a*S*.08,f+=o*n.width*(t.mouthWidth??0)*a*C,l+=(s-.29)*n.height*(t.mouthHeight??0)*a*C,r.x=f,r.y=l,r.z=h,r},ge=new Set([61,146,91,181,84,17,314,405,321,375,291,78,95,88,178,87,14,317,402,318,324,308,191,80,81,82,13,312,311,310,415]),Re=new Set([33,7,163,144,145,153,154,155,133,173,157,158,159,160,161,246]),Se=new Set([362,382,381,380,374,373,390,249,263,466,388,387,386,385,384,398]),an=new Set([814,815,816,817,818,819,830,831,832,833]),on=(e,n,t)=>{const r=ge.has(e)&&ge.has(n)&&ge.has(t),a=Re.has(e)&&Re.has(n)&&Re.has(t),o=Se.has(e)&&Se.has(n)&&Se.has(t);return r?"mouth":a?"leftEye":o?"rightEye":"base"},We=e=>{const n=[],t=[],r=[],a=[],o=[],s=[],c=[];let _=0,R=0;e.split(`
46
- `).forEach(b=>{const m=b.trim();if(!m)return;if(m.startsWith("v ")){_+=1;return}if(m.startsWith("vt ")){const[,l,h]=m.split(/\s+/);s.push([Number(l),Number(h)]);return}if(!m.startsWith("f "))return;const x=R;R+=1;const[,...X]=m.split(/\s+/),f=X.map(l=>{const[h,A]=l.split("/"),E=Number(h)-1,v=Number(A)-1;return v>=0&&s[v]&&!c[E]&&(c[E]=s[v]),E});if(!(f.length<3))for(let l=1;l<f.length-1;l+=1){const h=f[0],A=f[l],E=f[l+1],v=on(h,A,E);an.has(x)?o.push(h,A,E):v==="mouth"?t.push(h,A,E):v==="leftEye"?r.push(h,A,E):v==="rightEye"?a.push(h,A,E):n.push(h,A,E)}});const d=[];for(let b=0;b<_;b+=1){const[m,x]=c[b]??[0,0];d.push(m,x)}const S=new Uint16Array(r),C=new Uint16Array(a),I=new Uint16Array(r.length+a.length);return I.set(S),I.set(C,S.length),{baseIndices:new Uint16Array(n),mouthIndices:new Uint16Array(t),leftEyeIndices:S,rightEyeIndices:C,eyeIndices:I,noseIndices:new Uint16Array(o),uvs:new Float32Array(d),vertexCount:_}},sn="canonical_face_model.obj",cn=new TextDecoder("utf-8"),ve=new Map,ln=e=>{const n=ve.get(e);if(n)return n;const t=q.fetchAndVerify(e).then(r=>We(cn.decode(r))).catch(r=>{throw ve.delete(e),r});return ve.set(e,t),t},Ye=e=>{const{mesh:n,url:t}=e??{},r=t??`${q.libConfig.sdkAssetsBaseUrl}/${sn}`,[a,o]=i.useState(n??null);return i.useEffect(()=>{if(n){o(n);return}let s=!1;return ln(r).then(c=>{s||o(c)}).catch(c=>{s||console.error(`${q.libConfig.loggerPrefix} canonical face mesh load failed`,c)}),()=>{s=!0}},[n,r]),a},g={basic:"basic",standard:"standard",physical:"physical",toon:"toon",normal:"normal",matcap:"matcap",wireframe:"wireframe",shader:"shader"},G={originalFace:"originalFace",composite:"composite"},H={none:"none",canonical:"canonical",style2:"style2"},$={none:"none",canonical:"canonical"},re={solid:"solid",gradient:"gradient",imageUrl:"imageUrl",mediaUrl:"mediaUrl"},te={front:"front",back:"back",double:"double"},Ue={normal:"normal",add:"add",subtract:"subtract",multiply:"multiply",screen:"screen",overlay:"overlay",softLight:"softLight",hardLight:"hardLight",lighten:"lighten",darken:"darken",difference:"difference",exclusion:"exclusion"},un={textureMap:H.canonical,alphaMap:$.canonical,alphaOpacity:1},ze={...un,blendMode:Ue.hardLight,blendOpacity:.85,baseColor:"#ffffff",opacity:1,compositeShading:!0},O={materialType:g.basic,shaderPreset:G.originalFace,textureMap:H.none,alphaMap:$.none,alphaOpacity:1,side:te.front,blendMode:Ue.normal,blendOpacity:1,baseColor:"#38bdf8",opacity:.45,compositeShading:!1};g.shader,G.composite,te.front;const le={mouth:!0,eyes:!0,nose:!0},ne={textureSource:re.solid,color:"#111111",opacity:.5},dn=24,Ke=10,we=(e,n,t)=>e!==g.shader?"none":n===G.originalFace?"originalFace":n===G.composite?t===H.none?"originalFace":"composite":"none",fn=(e,n)=>e===g.basic||e===g.standard||e===g.physical||e===g.toon||e===g.shader&&n===G.composite,hn=(e,n,t=H.canonical)=>we(e,n,t)==="composite",mn=(e,n,t)=>we(e,n,t)==="originalFace",de=e=>e===re.imageUrl||e===re.mediaUrl,$e=e=>e===re.solid||e===re.gradient,Fe={normal:0,add:1,subtract:2,multiply:3,screen:4,overlay:5,softLight:6,hardLight:7,lighten:8,darken:9,difference:10,exclusion:11},Te="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO2YpZcAAAAASUVORK5CYII=",pn=()=>{const e=new Uint8Array([32,32,32,255,96,96,96,255,176,176,176,255,255,255,255,255]),n=new y.DataTexture(e,4,1,y.RGBAFormat);return n.minFilter=y.NearestFilter,n.magFilter=y.NearestFilter,n.generateMipmaps=!1,n.needsUpdate=!0,n},En=()=>{const e=document.createElement("canvas");e.width=256,e.height=256;const n=e.getContext("2d");if(!n)return new y.CanvasTexture(e);const t=n.createRadialGradient(96,80,10,128,128,128);t.addColorStop(0,"#ffffff"),t.addColorStop(.18,"#f7d794"),t.addColorStop(.45,"#d97706"),t.addColorStop(.72,"#78350f"),t.addColorStop(1,"#120701"),n.fillStyle=t,n.fillRect(0,0,e.width,e.height);const r=new y.CanvasTexture(e);return r.needsUpdate=!0,r},Mn=`
47
- attribute vec2 faceUv;
48
- varying vec2 vUv;
49
- varying vec2 vFaceUv;
50
- varying vec3 vNormal;
51
-
52
- void main() {
53
- vUv = uv;
54
- vFaceUv = faceUv;
55
- vNormal = normalize(normalMatrix * normal);
56
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
57
- }
58
- `,yn=`
59
- uniform sampler2D cameraTexture;
60
- uniform sampler2D canonicalTexture;
61
- uniform sampler2D alphaMask;
62
- uniform vec3 textureTint;
63
- uniform float opacity;
64
- uniform int blendMode;
65
- uniform float blendOpacity;
66
- uniform float useCanonicalTexture;
67
- uniform float useAlphaMask;
68
- uniform float alphaOpacity;
69
- uniform float compositeShading;
70
- uniform vec3 lightDirection;
71
- uniform float ambientStrength;
72
- uniform float directionalStrength;
73
- varying vec2 vUv;
74
- varying vec2 vFaceUv;
75
- varying vec3 vNormal;
76
-
77
- vec3 linearToSrgb(vec3 value) {
78
- vec3 low = value * 12.92;
79
- vec3 high = 1.055 * pow(max(value, vec3(0.0)), vec3(1.0 / 2.4)) - 0.055;
80
- return mix(high, low, step(value, vec3(0.0031308)));
81
- }
82
-
83
- vec3 srgbToLinear(vec3 value) {
84
- vec3 low = value / 12.92;
85
- vec3 high = pow(max((value + 0.055) / 1.055, vec3(0.0)), vec3(2.4));
86
- return mix(high, low, step(value, vec3(0.04045)));
87
- }
88
-
89
- float overlayChannel(float base, float blend) {
90
- return base < 0.5 ? 2.0 * base * blend : 1.0 - 2.0 * (1.0 - base) * (1.0 - blend);
91
- }
92
-
93
- float hardLightChannel(float base, float blend) {
94
- return blend < 0.5 ? 2.0 * base * blend : 1.0 - 2.0 * (1.0 - base) * (1.0 - blend);
95
- }
96
-
97
- float softLightChannel(float base, float blend) {
98
- if (blend <= 0.5) {
99
- return base - (1.0 - 2.0 * blend) * base * (1.0 - base);
100
- }
101
-
102
- float d = base <= 0.25
103
- ? ((16.0 * base - 12.0) * base + 4.0) * base
104
- : sqrt(base);
105
-
106
- return base + (2.0 * blend - 1.0) * (d - base);
107
- }
108
-
109
- vec3 applyBlendMode(vec3 base, vec3 blend, int mode) {
110
- if (mode == 0) return blend;
111
- if (mode == 1) return min(base + blend, 1.0);
112
- if (mode == 2) return max(base - blend, 0.0);
113
- if (mode == 3) return base * blend;
114
- if (mode == 4) return 1.0 - (1.0 - base) * (1.0 - blend);
115
- if (mode == 5) {
116
- return vec3(
117
- overlayChannel(base.r, blend.r),
118
- overlayChannel(base.g, blend.g),
119
- overlayChannel(base.b, blend.b)
120
- );
121
- }
122
- if (mode == 6) {
123
- return vec3(
124
- softLightChannel(base.r, blend.r),
125
- softLightChannel(base.g, blend.g),
126
- softLightChannel(base.b, blend.b)
127
- );
128
- }
129
- if (mode == 7) {
130
- return vec3(
131
- hardLightChannel(base.r, blend.r),
132
- hardLightChannel(base.g, blend.g),
133
- hardLightChannel(base.b, blend.b)
134
- );
135
- }
136
- if (mode == 8) return max(base, blend);
137
- if (mode == 9) return min(base, blend);
138
- if (mode == 10) return abs(base - blend);
139
- return base + blend - 2.0 * base * blend;
140
- }
141
-
142
- void main() {
143
- vec3 base = linearToSrgb(texture2D(cameraTexture, vFaceUv).rgb);
144
- vec4 textureSample = texture2D(canonicalTexture, vUv);
145
- vec3 blend = linearToSrgb(textureSample.rgb) * textureTint;
146
- float light = ambientStrength + max(dot(normalize(vNormal), normalize(lightDirection)), 0.0) * directionalStrength;
147
- blend *= mix(1.0, clamp(light, 0.35, 1.35), compositeShading);
148
- float maskSample = texture2D(alphaMask, vUv).r;
149
- float mask = useAlphaMask > 0.5 ? mix(1.0, maskSample, alphaOpacity) : 1.0;
150
- float textureAlpha = useCanonicalTexture > 0.5 ? textureSample.a : 1.0;
151
- vec3 blended = applyBlendMode(base, blend, blendMode);
152
- vec3 color = useCanonicalTexture > 0.5 ? mix(base, blended, blendOpacity) : base;
153
- gl_FragColor = vec4(srgbToLinear(color), opacity * mask * textureAlpha);
154
- }
155
- `,qe=({alphaMap:e,alphaOpacity:n,blendMode:t,blendOpacity:r,cameraTexture:a,color:o,compositeShading:s,faceAlphaMaskUrl:c,faceTextureStyle2Url:_,faceTextureUrl:R,masked:d=!1,maskColor:S,maskOpacity:C,maskSourceUrl:I,maskTextureSource:b,materialType:m,opacity:x,shaderPreset:X,side:f,textureMap:l})=>{const h=ee.useLoader(y.TextureLoader,R||Te),A=ee.useLoader(y.TextureLoader,_||R||Te),E=ee.useLoader(y.TextureLoader,c||Te),v=i.useMemo(()=>pn(),[]),j=i.useMemo(()=>En(),[]);i.useEffect(()=>()=>{v.dispose(),j.dispose()},[j,v]);const W=l===H.style2?A:h,L=l!==H.none,Y=we(m,X,l),K=["composite-material",l,e,n,t,r,s?"lit":"flat",o,x,R,_,c].join("|"),U={side:f,transparent:!0,opacity:x,wireframe:!1},fe=i.useMemo(()=>({source:de(b)?"texture":b,color:$e(b)?S:"#ffffff",opacity:C,textureUrl:de(b)?I:"",gradient:ke(S)}),[S,C,I,b]),T=i.useMemo(()=>({cameraTexture:{value:null},canonicalTexture:{value:null},alphaMask:{value:null},textureTint:{value:new y.Color(o)},opacity:{value:x},blendMode:{value:Fe[t]},blendOpacity:{value:r},useCanonicalTexture:{value:L?1:0},useAlphaMask:{value:e===$.canonical?1:0},alphaOpacity:{value:n},compositeShading:{value:s?1:0},lightDirection:{value:new y.Vector3(.3,.65,.7).normalize()},ambientStrength:{value:.78},directionalStrength:{value:.38}}),[e,n,t,r,o,s,L,x]);if(i.useEffect(()=>{T.cameraTexture.value=a??h,T.canonicalTexture.value=W,T.alphaMask.value=E,T.textureTint.value.set(o),T.opacity.value=x,T.blendMode.value=Fe[t],T.blendOpacity.value=r,T.useCanonicalTexture.value=L?1:0,T.useAlphaMask.value=e===$.canonical?1:0,T.alphaOpacity.value=n,T.compositeShading.value=s?1:0},[e,E,n,t,r,a,o,s,T,h,L,x,W]),d)return u.jsx(Xe,{settings:fe,side:f},`masked-${b}-material`);if(m===g.wireframe)return u.jsx("meshBasicMaterial",{color:o,transparent:!0,opacity:x,side:f,depthWrite:!1,depthTest:!1,wireframe:!0,toneMapped:!1},"wireframe-material");if(Y==="originalFace"&&a)return u.jsx("meshBasicMaterial",{map:a,alphaMap:E,transparent:!0,opacity:x,side:f,depthWrite:!1,depthTest:!0,toneMapped:!1},"use-original-face-material");if(Y==="composite"&&a)return u.jsx("shaderMaterial",{uniforms:T,vertexShader:Mn,fragmentShader:yn,transparent:!0,side:f,depthWrite:!1,depthTest:!0,toneMapped:!1},K);const z=L?W:null,Q=e===$.canonical&&n>0?E:null,B=`${m}-${l}-${e}-${n>0?"alpha-on":"alpha-off"}`;return m===g.standard?u.jsx("meshStandardMaterial",{...U,color:o,map:z??void 0,alphaMap:Q??void 0,depthWrite:!0,depthTest:!0,metalness:.05,roughness:.72},B):m===g.physical?u.jsx("meshPhysicalMaterial",{...U,color:o,map:z??void 0,alphaMap:Q??void 0,depthWrite:!0,depthTest:!0,roughness:.58,metalness:.08,clearcoat:.35,clearcoatRoughness:.4},B):m===g.toon?u.jsx("meshToonMaterial",{...U,color:o,map:z??void 0,alphaMap:Q??void 0,gradientMap:v,depthWrite:!0,depthTest:!0},B):m===g.normal?u.jsx("meshNormalMaterial",{...U,depthWrite:!0,depthTest:!0,flatShading:!1},"normal-material"):m===g.matcap?u.jsx("meshMatcapMaterial",{...U,color:o,matcap:j,depthWrite:!0,depthTest:!0},"matcap-material"):u.jsx("meshBasicMaterial",{...U,color:o,map:z??void 0,alphaMap:Q??void 0,depthWrite:!1,depthTest:l!==H.none||e!==$.none,toneMapped:!1},B)},Qe=[{key:"base",getIndices:e=>e.baseIndices,masked:!1,renderOrderOffset:0},{key:"mouth",getIndices:e=>e.mouthIndices,masked:!1,renderOrderOffset:2},{key:"left-eye",getIndices:e=>e.leftEyeIndices,masked:!1,renderOrderOffset:2},{key:"right-eye",getIndices:e=>e.rightEyeIndices,masked:!1,renderOrderOffset:2},{key:"nose",getIndices:e=>e.noseIndices,masked:!1,renderOrderOffset:2},{key:"mouth-mask",getIndices:e=>e.mouthIndices,masked:!0,renderOrderOffset:3},{key:"left-eye-mask",getIndices:e=>e.leftEyeIndices,masked:!0,renderOrderOffset:3},{key:"right-eye-mask",getIndices:e=>e.rightEyeIndices,masked:!0,renderOrderOffset:3},{key:"nose-mask",getIndices:e=>e.noseIndices,masked:!0,renderOrderOffset:3}],An={[te.front]:y.FrontSide,[te.back]:y.BackSide,[te.double]:y.DoubleSide},bn=(e,n,t)=>{e.setAttribute("position",n.position),e.setAttribute("uv",n.uv),e.setAttribute("faceUv",n.faceUv),e.setIndex(new y.BufferAttribute(t,1))},Ze=({faceIndex:e=0,baseColor:n,color:t=O.baseColor,opacity:r=O.opacity,materialType:a=O.materialType,shaderPreset:o=O.shaderPreset,textureMap:s=O.textureMap,alphaMap:c=O.alphaMap,alphaOpacity:_=O.alphaOpacity,side:R=O.side,blendMode:d=O.blendMode,blendOpacity:S=O.blendOpacity,showOverlayMask:C=!1,showMouthMask:I=le.mouth,showEyeMask:b=le.eyes,showLeftEyeMask:m,showRightEyeMask:x,showNoseMask:X=le.nose,showEyeGeometry:f=!0,showLeftEyeGeometry:l,showRightEyeGeometry:h,showMouthGeometry:A=!0,showNoseGeometry:E=!0,maskTextureSource:v=ne.textureSource,maskSourceUrl:j="",maskColor:W=ne.color,maskOpacity:L=ne.opacity,faceTextureUrl:Y="",faceTextureStyle2Url:K="",faceAlphaMaskUrl:U="",compositeShading:fe=!1,faceWarp3D:T,transform:z,renderOrder:Q=Ke,externalScale:B=1,mesh:at,meshUrl:ot})=>{const he=je.useXRModelNode(q.XRModel.FACE_TRACKER),st=je.useXRCameraTexture(),{camera:it}=ee.useThree(),D=Ye({mesh:at,url:ot}),Oe=i.useRef(null),ct=i.useRef(null),lt=i.useRef(null),ut=i.useRef(null),dt=i.useRef(null),ft=i.useRef(null),ht=i.useRef(null),mt=i.useRef(null),pt=i.useRef(null),Et=i.useRef(null),Mt=i.useRef(null),yt=i.useRef(null),At=i.useRef(null),bt=i.useRef(null),xt=i.useRef(null),gt=i.useRef(null),Rt=i.useRef(null),St=i.useRef(null),me=i.useRef(null),pe=i.useRef(null),Ee=i.useRef(null),Ie=i.useRef(null),vt=i.useRef(new y.Vector3),Tt=i.useRef({x:0,y:0,z:0}),_t=i.useRef({x:0,y:0,z:0}),Ct=i.useRef({x:0,y:0,z:0}),oe=i.useRef(!1),Ft=An[R],kt=n??t,Ut=l??f,wt=h??f,Ot=C||(m??b),It=C||(x??b),Lt=C||I,Dt=C||X,Pt={base:Oe,mouth:ct,"left-eye":lt,"right-eye":ut,nose:dt,"mouth-mask":ft,"left-eye-mask":ht,"right-eye-mask":mt,"nose-mask":pt},Nt={base:Et,mouth:Mt,"left-eye":yt,"right-eye":At,nose:bt,"mouth-mask":xt,"left-eye-mask":gt,"right-eye-mask":Rt,"nose-mask":St},Gt={base:!0,mouth:A,"left-eye":Ut,"right-eye":wt,nose:E,"mouth-mask":Lt,"left-eye-mask":Ot,"right-eye-mask":It,"nose-mask":Dt},Ht=M=>u.jsx(qe,{alphaMap:c,alphaOpacity:_,blendMode:d,blendOpacity:S,cameraTexture:st,color:kt,compositeShading:fe,faceAlphaMaskUrl:U,faceTextureStyle2Url:K,faceTextureUrl:Y,masked:M,maskColor:W,maskOpacity:L,maskSourceUrl:j,maskTextureSource:v,materialType:a,opacity:r,shaderPreset:o,side:Ft,textureMap:s}),Z=Qe.map(M=>({...M,geometryRef:Pt[M.key],meshRef:Nt[M.key],visible:Gt[M.key]})),jt=M=>_e.projectLandmarkWithDepth(M,it,vt.current);return ee.useFrame(()=>{var Ne,Ge;const M=Oe.current,P=(Ge=(Ne=he==null?void 0:he.detectionResults)==null?void 0:Ne.faceLandmarks)==null?void 0:Ge[e],zt=Z.every(p=>p.geometryRef.current&&p.meshRef.current);if(!D||!M||!zt)return;if(!P||P.length<D.vertexCount){Z.forEach(p=>{p.meshRef.current.visible=!1});return}if(Ie.current!==D){me.current=new Float32Array(D.vertexCount*3),pe.current=new Float32Array(D.uvs),Ee.current=new Float32Array(D.vertexCount*2);const p={position:new y.BufferAttribute(me.current,3),uv:new y.BufferAttribute(pe.current,2),faceUv:new y.BufferAttribute(Ee.current,2)};Z.forEach(F=>{bn(F.geometryRef.current,p,F.getIndices(D))}),p.uv.needsUpdate=!0,Ie.current=D,oe.current=!1}const se=me.current,Me=Ee.current,ie=pe.current;if(!se||!Me||!ie)return;const Le=mn(a,o,s),De=nn(T),Pe=De?tn(P):null,w=z?Ct.current:null;if(w){w.x=0,w.y=0,w.z=0;for(let p=0;p<P.length;p++){const F=P[p];w.x+=F.x,w.y+=F.y,w.z+=F.z}w.x/=P.length,w.y/=P.length,w.z/=P.length}const Bt=Math.min(P.length,D.vertexCount);for(let p=0;p<Bt;p++){const F=P[p],He=De&&Pe?rn(F,Pe,T,Tt.current):F,Vt=z&&w?_e.transformFaceMeshLandmark(He,w,z,_t.current):He,ye=p*3,ce=p*2,Ae=jt(Vt);se[ye]=Ae.x,se[ye+1]=Ae.y,se[ye+2]=Ae.z,Me[ce]=F.x,Me[ce+1]=1-F.y,Le&&(ie[ce]=F.x,ie[ce+1]=1-F.y)}Le?(M.attributes.uv.needsUpdate=!0,oe.current=!0):oe.current&&(ie.set(D.uvs),M.attributes.uv.needsUpdate=!0,oe.current=!1),Z.forEach(p=>{p.meshRef.current.visible=p.visible}),M.attributes.position.needsUpdate=!0,M.attributes.faceUv.needsUpdate=!0,Z.forEach(p=>{p.geometryRef.current.computeVertexNormals()})}),u.jsx("group",{scale:[B,B,B],children:Z.map(M=>u.jsxs("mesh",{ref:M.meshRef,renderOrder:Q+M.renderOrderOffset,frustumCulled:!1,children:[u.jsx("bufferGeometry",{ref:M.geometryRef}),Ht(M.masked)]},M.key))})},Je=`${q.libConfig.sdkAssetsBaseUrl}/Canonical_Face_Color.png`,et=`${q.libConfig.sdkAssetsBaseUrl}/Canonical_Face_Color_style_2.png`,tt=`${q.libConfig.sdkAssetsBaseUrl}/Canonical_Face_Color_Mask.png`,nt={...Ce,position:{...Ce.position,y:.001}},xn={enabled:!0,faceIndex:0,targetFps:dn,...O,showLeftEyeGeometry:!0,showRightEyeGeometry:!0,showMouthGeometry:!0,showNoseGeometry:!0,externalScale:1,showOverlayMask:!1,showMouthMask:!1,showLeftEyeMask:!1,showRightEyeMask:!1,showNoseMask:!1,maskTextureSource:ne.textureSource,maskSourceUrl:"",maskColor:ne.color,maskOpacity:ne.opacity,faceTextureUrl:Je,faceTextureStyle2Url:et,faceAlphaMaskUrl:tt,renderOrder:Ke},rt=e=>{const{externalMeshUrl:n,...t}=e;return{...t,color:t.baseColor,meshUrl:n}},gn=(e,n)=>{const t={...e,...n};return n.maskTextureSource&&!de(n.maskTextureSource)&&(t.maskSourceUrl=""),t.materialType===g.shader&&n.shaderPreset===G.composite?{...t,...ze,materialType:g.shader,shaderPreset:G.composite}:t.materialType===g.shader&&t.shaderPreset===G.composite&&t.textureMap===H.none?{...t,textureMap:ze.textureMap}:t},Rn=({transform:e,value:n})=>n.enabled?u.jsxs(u.Fragment,{children:[u.jsx(_e.FaceTracker,{active:n.enabled,faceIndex:n.faceIndex,numFaces:n.faceIndex+1,targetFps:n.targetFps}),u.jsx(Ze,{...rt(n),transform:e??nt})]}):null;exports.CANONICAL_FACE_MESH_GEOMETRY_SPECS=Qe;exports.CanonicalFaceMeshRenderer=Ze;exports.DEFAULT_APPEARANCE=O;exports.DEFAULT_FACE_MESH_RENDERER=xn;exports.DEFAULT_FACE_MESH_TRANSFORM=nt;exports.DEFAULT_MASKING=le;exports.DEFAULT_MATERIAL_FILL=Zt;exports.DEFAULT_SCREEN_GRADIENT=V;exports.DEFAULT_TRANSFORM_3D=Ce;exports.FACE_MESH_ALPHA_MAPS=$;exports.FACE_MESH_BLEND_MODES=Ue;exports.FACE_MESH_MASK_TEXTURE_SOURCES=re;exports.FACE_MESH_MATERIAL_TYPES=g;exports.FACE_MESH_SHADER_PRESETS=G;exports.FACE_MESH_SIDES=te;exports.FACE_MESH_TEXTURE_MAPS=H;exports.FaceMeshMaterial=qe;exports.FaceMeshRenderer=Rn;exports.MAX_SCREEN_GRADIENT_STOPS=ue;exports.MaterialFill=Xe;exports.ScreenGradientMaterial=Ve;exports.Transform3D=en;exports.blendModeIndices=Fe;exports.canonicalFaceAlphaMaskUrl=tt;exports.canonicalFaceTextureStyle2Url=et;exports.canonicalFaceTextureUrl=Je;exports.createTwoStopGradient=ke;exports.mapFaceMeshRendererSettingsToProps=rt;exports.normalizeScreenGradient=Be;exports.parseCanonicalFaceModel=We;exports.resolveFaceMeshRendererSettings=gn;exports.supportsBlendMode=hn;exports.supportsTexturePanel=fn;exports.useCanonicalFaceMesh=Ye;exports.usesMaskColor=$e;exports.usesMaskSourceUrl=de;
@@ -1 +0,0 @@
1
- "use strict";var Ee=Object.defineProperty;var Te=(e,t,n)=>t in e?Ee(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var O=(e,t,n)=>Te(e,typeof t!="symbol"?t+"":t,n);const B=require("react/jsx-runtime"),ne=require("@react-three/fiber"),A=require("react"),Fe=require("three"),fe=require("./renderLayers-lDtL0_43.cjs"),ie=require("./selectors-S8g25ke9.cjs"),ue=require("./index-Da7uycur.cjs"),se=require("./index-C9yQVzAh.cjs");function Me(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const U=Me(Fe),xe={display:"flex",alignItems:"center",justifyContent:"center",height:"100%",background:"#363636",color:"white",fontFamily:"monospace"},Ae=()=>B.jsx("div",{style:xe,children:"Loading..."}),Ce=e=>B.jsx("div",{style:xe,children:e.error}),le={position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:10},ce={sceneColorTexture:null,sceneDepthTexture:null},ke=({onRenderOutputs:e,renderOutputs:t,size:n})=>{const{gl:a,scene:r,size:s}=ne.useThree(),{session:c}=ue.useXRContext(),i=Math.max(1,Math.round((n==null?void 0:n.width)??s.width)),d=Math.max(1,Math.round((n==null?void 0:n.height)??s.height)),f=!!(t.sceneColor||t.sceneDepth),l=A.useMemo(()=>{if(!f)return null;const o=new U.WebGLRenderTarget(i,d,{colorSpace:U.SRGBColorSpace,depthBuffer:!0,stencilBuffer:!1});return t.sceneDepth&&(o.depthTexture=new U.DepthTexture(i,d),o.depthTexture.format=U.DepthFormat,o.depthTexture.type=U.UnsignedShortType),o},[f,d,t.sceneDepth,i]);return A.useEffect(()=>{if(!l){e==null||e(ce);return}return e==null||e({sceneColorTexture:t.sceneColor?l.texture:null,sceneDepthTexture:t.sceneDepth&&l.depthTexture?l.depthTexture:null}),()=>{var o;l.dispose(),(o=l.depthTexture)==null||o.dispose(),e==null||e(ce)}},[e,t.sceneColor,t.sceneDepth,l]),ne.useFrame(()=>{if(!l)return;const o=[];t.excludeScreenUI!==!1&&r.traverse(x=>{x.visible&&x.renderOrder>=fe.RENDER_LAYERS.SCREEN_UI&&(o.push(x),x.visible=!1)});const p=a.getRenderTarget(),v=a.xr.enabled;a.xr.enabled=!1,a.setRenderTarget(l),a.clear(),c._renderFrame(),a.setRenderTarget(p),a.xr.enabled=v,o.forEach(x=>{x.visible=!0})},-100),null},Ie=({style:e,canvasProps:t,children:n,loadingComponent:a,loadingTransitionDuration:r,errorComponent:s,renderTargetSize:c,renderOutputs:i={},onRenderOutputs:d})=>{const f=A.useRef(null),l=A.useRef(null),o=A.useRef(null),p=A.useRef(!1),{session:v}=ue.useXRContext(),x=ie.useXRReady(),u=ie.useXRError(),[h,g]=A.useState(!0);return A.useEffect(()=>{if(c){v._setRenderSize(Math.round(c.width),Math.round(c.height));return}const S=(w,E)=>{w<=0||E<=0||v._setRenderSize(Math.round(w),Math.round(E))},m=()=>{!l.current||p.current||(p.current=!0,v._setRenderTarget(l.current))},M=(w,E)=>{o.current!==null&&cancelAnimationFrame(o.current),o.current=requestAnimationFrame(()=>{o.current=null,S(w,E)})},_=new ResizeObserver(w=>{const E=w[0];if(!E)return;const{width:G,height:I}=E.contentRect;m(),M(G,I)});return f.current&&_.observe(f.current),m(),()=>{_.disconnect(),o.current!==null&&(cancelAnimationFrame(o.current),o.current=null),p.current=!1}},[c,v]),A.useEffect(()=>{x&&(r?setTimeout(()=>{g(!1)},r):g(!1))},[x,r]),B.jsxs("div",{id:"vincentt-xr-container",ref:f,style:{width:"100%",height:"100%",...e,position:"relative"},children:[h&&B.jsx("div",{style:le,children:a||B.jsx(Ae,{})}),u&&B.jsx("div",{style:le,children:s||B.jsx(Ce,{error:u.message})}),B.jsxs(ne.Canvas,{id:"vincentt-xr-canvas",ref:l,dpr:[1,3],gl:{alpha:!0,preserveDrawingBuffer:!1,antialias:!0,premultipliedAlpha:!1,toneMapping:U.NoToneMapping},...t,onCreated:S=>{c?v._setRenderSize(Math.round(c.width),Math.round(c.height)):v._setRenderTarget(l.current),v._setR3FState({renderer:S.gl,scene:S.scene,camera:S.camera}),S.gl.outputColorSpace=U.SRGBColorSpace,t!=null&&t.onCreated&&t.onCreated(S)},children:[B.jsx(ke,{onRenderOutputs:d,renderOutputs:i,size:c}),n]})]})},ve=(e,t,n,a,r)=>{const s=e/2,c=t/2,i=n.left*s+a.left,d=n.right*s-a.right,f=n.bottom*c+a.bottom,l=n.top*c-a.top,o=d-i,p=l-f,v=(i+d)/2,x=(f+l)/2,u=r[0]*o/2,h=r[1]*p/2;return{centerX:v,centerY:x,width:o,height:p,pivotX:u,pivotY:h}},Le={left:0,right:0,top:0,bottom:0},Be={left:0,right:0,top:0,bottom:0},Ge=[0,0],Xe=({anchors:e,offsets:t,pivot:n=Ge,children:a})=>{const{width:r,height:s}=se.useScreenSpace(),c=A.useMemo(()=>({anchors:{...Le,...e??{}},offsets:{...Be,...t??{}}}),[e,t]),i=A.useMemo(()=>ve(r,s,c.anchors,c.offsets,n),[r,s,c,n]);A.useEffect(()=>{const o=c.anchors;o.left>o.right&&console.warn(`[ScreenTransform] inverted X axis: anchors.left (${o.left}) > anchors.right (${o.right})`),o.bottom>o.top&&console.warn(`[ScreenTransform] inverted Y axis: anchors.bottom (${o.bottom}) > anchors.top (${o.top})`),i.width<=0&&console.warn(`[ScreenTransform] zero or negative width (${i.width.toFixed(3)}) — anchors + offsets collapse the X extent`),i.height<=0&&console.warn(`[ScreenTransform] zero or negative height (${i.height.toFixed(3)}) — anchors + offsets collapse the Y extent`)},[c,i.width,i.height]);const d=n[0]!==0||n[1]!==0,f=d?[1,1,1]:[i.width,i.height,1],l=!d&&i.width>0&&i.height>0?i.width/i.height:null;return B.jsx("group",{position:[i.centerX-i.pivotX,i.centerY-i.pivotY,0],scale:f,renderOrder:fe.RENDER_LAYERS.SCREEN_UI,children:B.jsx(se.ScreenRectAspectContext.Provider,{value:l,children:a})})};class pe{constructor(t,n){O(this,"capabilities");O(this,"snapshot");O(this,"listeners",new Set);O(this,"eventListeners",new Map);this.capabilities=t,this.snapshot={state:"idle",frame:0,time:0,playMode:"forward",loop:!0,loopCount:0,...n}}play(){const t=this.snapshot.state==="paused";this.update({state:"playing"}),this.emit(t?"Resume":"PlayBegin")}pause(){this.update({state:"paused"}),this.emit("Pause")}restart(){this.update({state:"playing",frame:0,time:0}),this.emit("PlayBegin")}setPlayMode(t){!this.capabilities.canReverse&&(t==="reverse"||t==="ping-pong"||t==="random")||this.update({playMode:t})}setLoop(t,n=0){this.update({loop:t,loopCount:n})}seek(t){this.capabilities.canSeek&&this.update({frame:Math.max(0,Math.floor(t)),time:Math.max(0,t)})}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}on(t,n){const a=this.eventListeners.get(t)??new Set;return a.add(n),this.eventListeners.set(t,a),()=>this.off(t,n)}off(t,n){var a;(a=this.eventListeners.get(t))==null||a.delete(n)}getSnapshot(){return this.snapshot}dispose(){this.listeners.clear(),this.eventListeners.clear(),this.snapshot={...this.snapshot,state:"idle"}}updateSnapshot(t){this.update(t)}emit(t){var n;(n=this.eventListeners.get(t))==null||n.forEach(a=>a({type:t,snapshot:this.snapshot}))}update(t){this.snapshot={...this.snapshot,...t},this.listeners.forEach(n=>n(this.snapshot))}}const ge=(e,t,n,a,r)=>{const s=Math.max(1,Math.floor(t)),c=Math.max(0,Math.floor(e)),i=n==="ping-pong"&&s>1?s*2-2:s,d=Math.floor(c/i),f=r>0?d>=r:!a&&c>=i,l=f?i-1:c%i;return{frame:n==="reverse"?s-1-l%s:n==="random"?l*7919%s:n==="ping-pong"&&l>=s?i-l:l,ended:f,loop:d}},De=(e,t,n)=>{const a=Math.max(1,Math.floor(n));return Math.floor(Math.max(0,e)*Math.max(0,t))%a};var he={},me,Ue;function je(e,t,n,s){var r=0,s=s===void 0?{}:s,c=s.loop===void 0?null:s.loop,i=s.palette===void 0?null:s.palette;if(t<=0||n<=0||t>65535||n>65535)throw new Error("Width/Height invalid.");function d(h){var g=h.length;if(g<2||g>256||g&g-1)throw new Error("Invalid code/color length, must be power of 2 and 2 .. 256.");return g}e[r++]=71,e[r++]=73,e[r++]=70,e[r++]=56,e[r++]=57,e[r++]=97;var f=0,l=0;if(i!==null){for(var o=d(i);o>>=1;)++f;if(o=1<<f,--f,s.background!==void 0){if(l=s.background,l>=o)throw new Error("Background index out of range.");if(l===0)throw new Error("Background index explicitly passed as 0.")}}if(e[r++]=t&255,e[r++]=t>>8&255,e[r++]=n&255,e[r++]=n>>8&255,e[r++]=(i!==null?128:0)|f,e[r++]=l,e[r++]=0,i!==null)for(var p=0,v=i.length;p<v;++p){var x=i[p];e[r++]=x>>16&255,e[r++]=x>>8&255,e[r++]=x&255}if(c!==null){if(c<0||c>65535)throw new Error("Loop count invalid.");e[r++]=33,e[r++]=255,e[r++]=11,e[r++]=78,e[r++]=69,e[r++]=84,e[r++]=83,e[r++]=67,e[r++]=65,e[r++]=80,e[r++]=69,e[r++]=50,e[r++]=46,e[r++]=48,e[r++]=3,e[r++]=1,e[r++]=c&255,e[r++]=c>>8&255,e[r++]=0}var u=!1;this.addFrame=function(h,g,S,m,M,_){if(u===!0&&(--r,u=!1),_=_===void 0?{}:_,h<0||g<0||h>65535||g>65535)throw new Error("x/y invalid.");if(S<=0||m<=0||S>65535||m>65535)throw new Error("Width/Height invalid.");if(M.length<S*m)throw new Error("Not enough pixels for the frame size.");var w=!0,E=_.palette;if(E==null&&(w=!1,E=i),E==null)throw new Error("Must supply either a local or global palette.");for(var G=d(E),I=0;G>>=1;)++I;G=1<<I;var j=_.delay===void 0?0:_.delay,R=_.disposal===void 0?0:_.disposal;if(R<0||R>3)throw new Error("Disposal out of range.");var T=!1,k=0;if(_.transparent!==void 0&&_.transparent!==null&&(T=!0,k=_.transparent,k<0||k>=G))throw new Error("Transparent color index.");if((R!==0||T||j!==0)&&(e[r++]=33,e[r++]=249,e[r++]=4,e[r++]=R<<2|(T===!0?1:0),e[r++]=j&255,e[r++]=j>>8&255,e[r++]=k,e[r++]=0),e[r++]=44,e[r++]=h&255,e[r++]=h>>8&255,e[r++]=g&255,e[r++]=g>>8&255,e[r++]=S&255,e[r++]=S>>8&255,e[r++]=m&255,e[r++]=m>>8&255,e[r++]=w===!0?128|I-1:0,w===!0)for(var $=0,L=E.length;$<L;++$){var C=E[$];e[r++]=C>>16&255,e[r++]=C>>8&255,e[r++]=C&255}return r=$e(e,r,I<2?2:I,M),r},this.end=function(){return u===!1&&(e[r++]=59,u=!0),r},this.getOutputBuffer=function(){return e},this.setOutputBuffer=function(h){e=h},this.getOutputBufferPosition=function(){return r},this.setOutputBufferPosition=function(h){r=h}}function $e(e,t,n,a){e[t++]=n;var r=t++,s=1<<n,c=s-1,i=s+1,d=i+1,f=n+1,l=0,o=0;function p(_){for(;l>=_;)e[t++]=o&255,o>>=8,l-=8,t===r+256&&(e[r]=255,r=t++)}function v(_){o|=_<<l,l+=f,p(8)}var x=a[0]&c,u={};v(s);for(var h=1,g=a.length;h<g;++h){var S=a[h]&c,m=x<<8|S,M=u[m];if(M===void 0){for(o|=x<<l,l+=f;l>=8;)e[t++]=o&255,o>>=8,l-=8,t===r+256&&(e[r]=255,r=t++);d===4096?(v(s),d=i+1,f=n+1,u={}):(d>=1<<f&&++f,u[m]=d++),x=S}else x=M}return v(x),v(i),p(1),r+1===t?e[r]=0:(e[r]=t-r-1,e[t++]=0),t}function Pe(e){var t=0;if(e[t++]!==71||e[t++]!==73||e[t++]!==70||e[t++]!==56||(e[t++]+1&253)!==56||e[t++]!==97)throw new Error("Invalid GIF 87a/89a header.");var n=e[t++]|e[t++]<<8,a=e[t++]|e[t++]<<8,r=e[t++],s=r>>7,c=r&7,i=1<<c+1;e[t++],e[t++];var d=null,f=null;s&&(d=t,f=i,t+=i*3);var l=!0,o=[],p=0,v=null,x=0,u=null;for(this.width=n,this.height=a;l&&t<e.length;)switch(e[t++]){case 33:switch(e[t++]){case 255:if(e[t]!==11||e[t+1]==78&&e[t+2]==69&&e[t+3]==84&&e[t+4]==83&&e[t+5]==67&&e[t+6]==65&&e[t+7]==80&&e[t+8]==69&&e[t+9]==50&&e[t+10]==46&&e[t+11]==48&&e[t+12]==3&&e[t+13]==1&&e[t+16]==0)t+=14,u=e[t++]|e[t++]<<8,t++;else for(t+=12;;){var h=e[t++];if(!(h>=0))throw Error("Invalid block size");if(h===0)break;t+=h}break;case 249:if(e[t++]!==4||e[t+4]!==0)throw new Error("Invalid graphics extension block.");var g=e[t++];p=e[t++]|e[t++]<<8,v=e[t++],g&1||(v=null),x=g>>2&7,t++;break;case 254:for(;;){var h=e[t++];if(!(h>=0))throw Error("Invalid block size");if(h===0)break;t+=h}break;default:throw new Error("Unknown graphic control label: 0x"+e[t-1].toString(16))}break;case 44:var S=e[t++]|e[t++]<<8,m=e[t++]|e[t++]<<8,M=e[t++]|e[t++]<<8,_=e[t++]|e[t++]<<8,w=e[t++],E=w>>7,G=w>>6&1,I=w&7,j=1<<I+1,R=d,T=f,k=!1;if(E){var k=!0;R=t,T=j,t+=j*3}var $=t;for(t++;;){var h=e[t++];if(!(h>=0))throw Error("Invalid block size");if(h===0)break;t+=h}o.push({x:S,y:m,width:M,height:_,has_local_palette:k,palette_offset:R,palette_size:T,data_offset:$,data_length:t-$,transparent_index:v,interlaced:!!G,delay:p,disposal:x});break;case 59:l=!1;break;default:throw new Error("Unknown gif block: 0x"+e[t-1].toString(16))}this.numFrames=function(){return o.length},this.loopCount=function(){return u},this.frameInfo=function(L){if(L<0||L>=o.length)throw new Error("Frame index out of range.");return o[L]},this.decodeAndBlitFrameBGRA=function(L,C){var y=this.frameInfo(L),Z=y.width*y.height,P=new Uint8Array(Z);de(e,y.data_offset,P,Z);var q=y.palette_offset,W=y.transparent_index;W===null&&(W=256);var X=y.width,N=n-X,Y=X,K=(y.y*n+y.x)*4,Q=((y.y+y.height)*n+y.x)*4,F=K,V=N*4;y.interlaced===!0&&(V+=n*4*7);for(var H=8,z=0,b=P.length;z<b;++z){var D=P[z];if(Y===0&&(F+=V,Y=X,F>=Q&&(V=N*4+n*4*(H-1),F=K+(X+N)*(H<<1),H>>=1)),D===W)F+=4;else{var ee=e[q+D*3],te=e[q+D*3+1],re=e[q+D*3+2];C[F++]=re,C[F++]=te,C[F++]=ee,C[F++]=255}--Y}},this.decodeAndBlitFrameRGBA=function(L,C){var y=this.frameInfo(L),Z=y.width*y.height,P=new Uint8Array(Z);de(e,y.data_offset,P,Z);var q=y.palette_offset,W=y.transparent_index;W===null&&(W=256);var X=y.width,N=n-X,Y=X,K=(y.y*n+y.x)*4,Q=((y.y+y.height)*n+y.x)*4,F=K,V=N*4;y.interlaced===!0&&(V+=n*4*7);for(var H=8,z=0,b=P.length;z<b;++z){var D=P[z];if(Y===0&&(F+=V,Y=X,F>=Q&&(V=N*4+n*4*(H-1),F=K+(X+N)*(H<<1),H>>=1)),D===W)F+=4;else{var ee=e[q+D*3],te=e[q+D*3+1],re=e[q+D*3+2];C[F++]=ee,C[F++]=te,C[F++]=re,C[F++]=255}--Y}}}function de(e,t,n,a){for(var r=e[t++],s=1<<r,c=s+1,i=c+1,d=r+1,f=(1<<d)-1,l=0,o=0,p=0,v=e[t++],x=new Int32Array(4096),u=null;;){for(;l<16&&v!==0;)o|=e[t++]<<l,l+=8,v===1?v=e[t++]:--v;if(l<d)break;var h=o&f;if(o>>=d,l-=d,h===s){i=c+1,d=r+1,f=(1<<d)-1,u=null;continue}else if(h===c)break;for(var g=h<i?h:u,S=0,m=g;m>s;)m=x[m]>>8,++S;var M=m,_=p+S+(g!==h?1:0);if(_>a){console.log("Warning, gif stream longer than expected.");return}n[p++]=M,p+=S;var w=p;for(g!==h&&(n[p++]=M),m=g;S--;)m=x[m],n[--w]=m&255,m>>=8;u!==null&&i<4096&&(x[i++]=u<<8|M,i>=f+1&&d<12&&(++d,f=f<<1|1)),u=h}return p!==a&&console.log("Warning, gif stream shorter than expected."),n}try{Ue=he.GifWriter=je,me=he.GifReader=Pe}catch{}const qe=me;function We(e){return async(t,n)=>{const a=e.find(r=>r.canResolve(t));if(!a)throw new we("No texture provider matched source",t);return Se(a.resolve.bind(a),t,n)}}class we extends Error{constructor(n,a){super(n);O(this,"source");this.name="TextureSourceLoadError",this.source=a}}function J(e){if(e.aborted)throw new DOMException("Texture source load aborted","AbortError")}async function Se(e,t,n){J(n);const a=await e(t,n);return n.aborted&&(a.dispose(),J(n)),a}function Ne(e){e==null||e.dispose()}const _e=5*1024*1024,ae=1e6,oe=180,Ye=(e,t,n)=>{for(let a=n.y;a<n.y+n.height;a+=1)e.fill(0,(a*t+n.x)*4,(a*t+n.x+n.width)*4)},Ve=(e,t,n,a,r)=>t.byteLength>_e?`file is ${(t.byteLength/1024/1024).toFixed(1)} MB; max is 5 MB`:n*a>ae?`canvas is ${n}x${a}; max area is ${ae}`:r>oe?`frame count is ${r}; max is ${oe}`:r===0?"frame count is 0":e?null:"source URL is empty",He=e=>typeof e=="string"?e:e.src,ze={canResolve:e=>typeof e=="string"?/\.gif(?:[?#].*)?$/i.test(e):e.kind==="gif",async resolve(e,t){const n=He(e),a=await fetch(n,{signal:t});if(!a.ok)throw new Error(`GIF request failed with ${a.status}`);const r=new Uint8Array(await a.arrayBuffer());J(t);const s=new qe(r),c=s.numFrames(),i=Ve(n,r,s.width,s.height,c);if(i)throw console.warn(`[xr-sdk] GIF ScreenImage source rejected: ${i}`,n),new Error(`GIF source rejected: ${i}`);const d=document.createElement("canvas");d.width=s.width,d.height=s.height;const f=d.getContext("2d");if(!f)throw new Error("Could not create GIF canvas context");const l=new U.CanvasTexture(d);l.colorSpace=U.SRGBColorSpace;const o=new Uint8Array(s.width*s.height*4),p=new ImageData(new Uint8ClampedArray(o.buffer),s.width,s.height),v=Array.from({length:c},(R,T)=>s.frameInfo(T)),x=v.reduce((R,T)=>R+Math.max(20,T.delay*10),0)/1e3,u=new pe({canSeek:!1,canReverse:!1,supportsLoopCount:!0},{state:"ready",duration:x,frameCount:c});let h=0,g=0,S=!1,m=!1,M=0,_=0,w=null;const E=(R,T=!1)=>{T&&(o.fill(0),w=null),(w==null?void 0:w.info.disposal)===2?Ye(o,s.width,w.info):w!=null&&w.restorePixels&&o.set(w.restorePixels);const k=v[R],$=k.disposal===3?new Uint8Array(o):null;return s.decodeAndBlitFrameRGBA(R,o),f.putImageData(p,0,0),l.needsUpdate=!0,w={info:k,restorePixels:$},m=!0,u.updateSnapshot({frame:R,time:v.slice(0,R).reduce((L,C)=>L+Math.max(20,C.delay*10),0)/1e3}),m=!1,u.emit("KeyFrameInSecond"),Math.max(20,k.delay*10)},G=R=>{g=window.setTimeout(()=>{h=requestAnimationFrame(I)},R)},I=()=>{if(S||u.getSnapshot().state!=="playing")return;const R=u.getSnapshot(),T=ge(M,c,R.playMode,R.loop,R.loopCount);if(T.ended){u.updateSnapshot({state:"ended",frame:T.frame,time:x}),u.emit("PlayEnd");return}const k=T.loop!==_;_=T.loop,M+=1,G(E(T.frame,k))},j=u.subscribe(R=>{m||(clearTimeout(g),cancelAnimationFrame(h),R.state==="playing"&&(h=requestAnimationFrame(I)))});return E(0),u.play(),{texture:l,controller:u,metadata:{width:s.width,height:s.height,duration:x,frameCount:c},dispose(){S=!0,j(),clearTimeout(g),cancelAnimationFrame(h),u.dispose(),l.dispose()}}}},ye=A.createContext(null),Re=A.createContext(null),Oe=()=>A.useContext(ye),Ze=()=>A.useContext(Re);exports.BasicAnimatedTextureController=pe;exports.MAX_GIF_BYTES=_e;exports.MAX_GIF_FRAMES=oe;exports.MAX_GIF_PIXELS=ae;exports.ScreenTransform=Xe;exports.TextureSourceLoadError=we;exports.XRScene=Ie;exports.XRViewportRenderOutputsContext=Re;exports.XRViewportStateContext=ye;exports.computeScreenTransform=ve;exports.createTextureSourceResolver=We;exports.disposeResolvedTextureSource=Ne;exports.getPlaybackFrame=ge;exports.getSequenceFrame=De;exports.gifTextureSourceProvider=ze;exports.resolveTextureSource=Se;exports.throwIfAborted=J;exports.useXRViewportRenderOutputs=Ze;exports.useXRViewportState=Oe;
@@ -1 +0,0 @@
1
- "use strict";var Re=Object.defineProperty;var Me=(n,s,e)=>s in n?Re(n,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[s]=e;var h=(n,s,e)=>Me(n,typeof s!="symbol"?s+"":s,e);const ie=require("react/jsx-runtime"),b=require("react"),_=require("@mediapipe/tasks-vision"),P=require("three");function Te(n){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(s,e,t.get?t:{enumerable:!0,get:()=>n[e]})}}return s.default=n,Object.freeze(s)}const D=Te(P);var x=(n=>(n.WEBCAM="webcam",n.STREAM="stream",n.CANVAS="canvas",n))(x||{}),L=(n=>(n.HAND_TRACKER="vincentt.xr.hand-tracker",n.GESTURE_TRACKER="vincentt.xr.gesture-tracker",n.FACE_TRACKER="vincentt.xr.face-tracker",n.BODY_TRACKER="vincentt.xr.body-tracker",n.BACKGROUND_SEGMENTATION="vincentt.xr.background-segmentation",n))(L||{});class I extends Error{constructor(s){super(s),this.name="VincenttXRError"}}const xe=(n,s)=>s,E={apiBaseUrl:xe(void 0,"https://api.vincentt.studio"),assetStorageEndpoint:"https://cdn.vincentt.studio",sdkAssetsBaseUrl:"https://cdn.vincentt.studio/assets/sdk/face/v1",loggerPrefix:"[vincentt-xr]:",sessionCheckInterval:3e4};class Fe{constructor(s){h(this,"options");const e={verbose:!1,prefix:E.loggerPrefix};this.options={...e,...s}}log(...s){const{verbose:e,prefix:t}=this.options;e&&console.info(t,...s)}error(...s){const{verbose:e,prefix:t}=this.options;e&&console.error(t,...s)}}const B=n=>n*2-1,Y=new D.Vector3,Q=new D.Vector3,q=({x:n,y:s,z:e},t,a)=>{Y.set((n-.5)*2,(.5-s)*2,-e),Y.unproject(t),Q.copy(Y).sub(t.position).normalize();const r=-t.position.z/Q.z;return a.copy(t.position).addScaledVector(Q,r),a},Ae=(n,s)=>q(n,s,new D.Vector3),be=(n,s,e=.2)=>e*s+(1-e)*n;class ${constructor(s){h(this,"canvas");this.maxDimension=s}draw(s){const e=s.width,t=s.height,a=Math.min(1,this.maxDimension/Math.max(e,t));if(a>=1)return s;const r=Math.max(1,Math.round(e*a)),o=Math.max(1,Math.round(t*a));(!this.canvas||this.canvas.width!==r||this.canvas.height!==o)&&(this.canvas=new OffscreenCanvas(r,o));const d=this.canvas.getContext("2d");return d?(d.setTransform(1,0,0,1,0,0),d.clearRect(0,0,r,o),d.drawImage(s,0,0,r,o),this.canvas):s}dispose(){this.canvas=void 0}}const Ee={"/assets/xr/models/face_tracking.task":"sha384-tYQh+yJE8llY+zO4RviZmWaSKs5W9tsB0ix5rjQVpF5/CLTqmwtP7bYtkUi2w65P","/assets/xr/models/hand_tracking.task":"sha384-uWvruVKd887ov8k43S+DBHCsi7UXXS+CKvvdM1PX00rjPzx/B0QrAPfJ1U9yKcze","/assets/xr/models/gesture_tracking.task":"sha384-2zuseP9JKKWAYlWQGKA2N+ooabB8V/yIxu23Mv8mtY7SowcySB+xKiOmqBhVvlUC","/assets/xr/models/body_tracking.task":"sha384-3Wk9dvRYo36b3Nc9xVjKamb4wCKt9FwiPjcHKfrvyJL/jXoGs+uRLnii6yjWLKul","/assets/xr/models/segmentation.tflite":"sha384-A2bQ8+iZyQM3KIGVBUf0FyetqxuynyKpjsjCE8uzoJEnj1ghCu6ge2daiRffAiS5","/assets/xr/3d-models/head-occluder-v2.glb":"sha384-+0G60Q6EBVE6hpITxGzQgofAeKexPltpsfPq5T5et9GGBjRhFP5HOdsKAhe73OaI","/assets/sdk/face/v1/canonical_face_model.obj":"sha384-xP8YM/72TXKvbMptXB9a8JUlUf3MZQ8uLurExrsZc05v6/P5RrsaNGMUYS/BZx8A","/opencv/facial_expression_recognition/resolve/main/facial_expression_recognition_mobilefacenet_2022july_int8.onnx":"sha384-g8mtFubiIc/yhqi591RsxD76AJLw2CfYgKhKbVkIiFlwBmIyG7ZAIVyGPXafrDGB"};async function re(n){const s=await fetch(n);if(!s.ok)throw new Error(`fetchAndVerify: ${s.status} ${n}`);const e=await s.arrayBuffer(),t=De(n);if(!t){if(Ie(n))throw new Error(`[xr-sdk integrity] no SRI hash for SDK asset ${n}`);return console.warn(`[xr-sdk integrity] no SRI hash for ${n} — passing through`),e}const a=await _e(e);if(a!==t)throw new Error(`[xr-sdk integrity] SRI mismatch for ${n}: expected ${t}, got ${a}`);return e}function Ie(n){try{return new URL(n).origin===new URL(E.assetStorageEndpoint).origin}catch{return!1}}async function H(n){const s=await re(n);return new Uint8Array(s)}function De(n){try{const s=new URL(n);return Ee[s.pathname]}catch{return}}async function _e(n){const s=await crypto.subtle.digest("SHA-384",n),e=new Uint8Array(s);let t="";for(let a=0;a<e.byteLength;a++)t+=String.fromCharCode(e[a]);return`sha384-${btoa(t)}`}class G{constructor(){h(this,"disposed",!1);h(this,"paused",!1);h(this,"rafId",null);h(this,"targetFrameIntervalMs",0);h(this,"lastInferenceMs",0)}setTargetFps(s){this.targetFrameIntervalMs=s&&s>0?1e3/s:0}shouldRunInference(){if(this.targetFrameIntervalMs<=0)return!0;const s=performance.now();return s-this.lastInferenceMs<this.targetFrameIntervalMs?!1:(this.lastInferenceMs=s,!0)}async initialize(s){}async run(s){}getModelNode(){return{}}async getPerformanceData(){return{name:this.constructor.name,processingTime:null}}pause(){this.paused=!0,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}resume(){this.paused=!1}dispose(){this.disposed=!0,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}}const Pe=768;class Oe extends G{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"coordinates");h(this,"sourceCanvas");h(this,"downscaler",new $(Pe))}async getBodyData(){if(!this.landmarker||!this.sourceCanvas)return;const e=this.downscaler.draw(this.sourceCanvas),t=performance.now(),a=this.landmarker.detectForVideo(e,t),r=performance.now();this.processingTime=r-t;const o=a.landmarks,d=[];if(o)return o.forEach((m,u)=>{d[u]||(d[u]=[]),m.forEach(S=>{const M=B(S.x),R=B(1-S.y),F=B(S.z);d[u].push({x:M,y:R,z:F})})}),{coordinatesList:d}}async processBodyTracking(){if(!(this.disposed||this.paused||!this.landmarker)){if(this.shouldRunInference()){const e=await this.getBodyData();e&&(this.coordinates=e.coordinatesList)}this.disposed||this.paused||(this.rafId=requestAnimationFrame(this.processBodyTracking.bind(this)))}}resume(){this.paused&&(super.resume(),this.processBodyTracking())}dispose(){if(super.dispose(),this.landmarker){try{this.landmarker.close()}catch{}this.landmarker=null}this.sourceCanvas=void 0,this.downscaler.dispose(),this.coordinates=void 0}getLandmarks2D(e=0){if(this.coordinates)return this.coordinates[e]}async initialize(e){const t=await _.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",E.assetStorageEndpoint).toString()),a=await H(new URL("/assets/xr/models/body_tracking.task",E.assetStorageEndpoint).toString());this.landmarker=await _.PoseLandmarker.createFromOptions(t,{baseOptions:{modelAssetBuffer:a,delegate:"GPU"},runningMode:"VIDEO",numPoses:(e==null?void 0:e.numPoses)||1})}async run({sourceCanvas:e,targetFps:t}){this.sourceCanvas=e,this.setTargetFps(t),this.rafId===null&&await this.processBodyTracking()}getModelNode(){return{getLandmarks2D:this.getLandmarks2D.bind(this)}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const Ue=.11,ze=.004,Le=(n,s)=>s.set(n.x,-n.y,n.z);class Be extends G{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"sourceCanvas");h(this,"analysisCanvas");h(this,"getSource");h(this,"detectionResults");h(this,"numFaces",1);h(this,"cameras",[]);h(this,"faces",[]);h(this,"leftCheekScratch",[]);h(this,"rightCheekScratch",[]);h(this,"landmarkScratch",{x:0,y:0,z:0,visibility:0});h(this,"rotMatrixScratch",new D.Matrix4);h(this,"rotQuatScratch",new D.Quaternion);h(this,"rotEulerScratch",new D.Euler)}landmarkForSource(e,t){return t?(this.landmarkScratch.x=1-e.x,this.landmarkScratch.y=e.y,this.landmarkScratch.z=e.z,this.landmarkScratch.visibility=e.visibility,this.landmarkScratch):e}extractAndUpdateFaceData(e){var a;if(!e.faceLandmarks.length){this.faces=[];return}const t=e.faceLandmarks.length;for(this.faces.length>t&&(this.faces.length=t,this.leftCheekScratch.length=t,this.rightCheekScratch.length=t);this.faces.length<t;)this.faces.push({transform:{position:new D.Vector3,rotation:new D.Vector3,scale:new D.Vector3},gestures:{}}),this.leftCheekScratch.push(new D.Vector3),this.rightCheekScratch.push(new D.Vector3);for(let r=0;r<t;r+=1){if(!this.cameras[r])continue;const o=this.faces[r],d=(a=this.getSource)==null?void 0:a.call(this),m=!(d==="webcam"||!d),u=e.faceLandmarks[r],S=e.facialTransformationMatrixes[r];this.rotMatrixScratch.fromArray(S.data),this.rotQuatScratch.setFromRotationMatrix(this.rotMatrixScratch),this.rotQuatScratch.set(-this.rotQuatScratch.x,this.rotQuatScratch.y,this.rotQuatScratch.z,this.rotQuatScratch.w),this.rotEulerScratch.setFromQuaternion(this.rotQuatScratch,"XYZ"),Le(this.rotEulerScratch,o.transform.rotation),q(this.landmarkForSource(u[4],m),this.cameras[r],o.transform.position),q(this.landmarkForSource(u[50],m),this.cameras[r],this.leftCheekScratch[r]),q(this.landmarkForSource(u[280],m),this.cameras[r],this.rightCheekScratch[r]);const R=this.leftCheekScratch[r].distanceTo(this.rightCheekScratch[r])*Ue,F=Math.abs(D.MathUtils.radToDeg(this.rotEulerScratch.y)),l=R+F*ze,f=o.transform.scale.x,w=be(isNaN(f)?0:f,l);o.transform.scale.set(w,w,w);const p=o.gestures,k=e.faceBlendshapes[r].categories;for(const C of k)p[C.categoryName]=C.score}}async processFaceTracking(){if(this.disposed||this.paused||!this.landmarker||!this.sourceCanvas)return null;if(!this.shouldRunInference()){this.rafId=requestAnimationFrame(this.processFaceTracking.bind(this));return}const e=Ve(this.numFaces),t=this.sourceCanvas.width,a=this.sourceCanvas.height,r=Math.min(1,e/Math.max(t,a)),o=Math.max(1,Math.round(t*r)),d=Math.max(1,Math.round(a*r));(!this.analysisCanvas||this.analysisCanvas.width!==o||this.analysisCanvas.height!==d)&&(this.analysisCanvas=new OffscreenCanvas(o,d));const m=this.analysisCanvas.getContext("2d");if(!m){this.rafId=requestAnimationFrame(this.processFaceTracking.bind(this));return}m.setTransform(1,0,0,1,0,0),m.clearRect(0,0,o,d),m.drawImage(this.sourceCanvas,0,0,o,d);const u=performance.now(),S=this.landmarker.detectForVideo(this.analysisCanvas,u),M=performance.now();this.processingTime=M-u,this.detectionResults=S,this.extractAndUpdateFaceData(S),!(this.disposed||this.paused)&&(this.rafId=requestAnimationFrame(this.processFaceTracking.bind(this)))}resume(){this.paused&&(super.resume(),this.processFaceTracking())}dispose(){if(super.dispose(),this.landmarker){try{this.landmarker.close()}catch{}this.landmarker=null}this.sourceCanvas=void 0,this.analysisCanvas=void 0,this.getSource=void 0,this.detectionResults=void 0,this.processingTime=null,this.cameras=[],this.faces=[],this.leftCheekScratch=[],this.rightCheekScratch=[]}getFace(e=0){return this.faces[e]}getDetectionResults(){return this.detectionResults}getRawFaceTrackingData(e=0){var t,a,r,o;if(this.detectionResults)return{landmarks:(t=this.detectionResults.faceLandmarks)==null?void 0:t[e],blendshapes:(r=(a=this.detectionResults.faceBlendshapes)==null?void 0:a[e])==null?void 0:r.categories,transformationMatrix:(o=this.detectionResults.facialTransformationMatrixes)==null?void 0:o[e]}}async initialize(e){this.numFaces=(e==null?void 0:e.numFaces)||1;const t=await _.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",E.assetStorageEndpoint).toString()),a=await H(new URL("/assets/xr/models/face_tracking.task",E.assetStorageEndpoint).toString()),r=await _.FaceLandmarker.createFromOptions(t,{baseOptions:{modelAssetBuffer:a,delegate:"GPU"},minFaceDetectionConfidence:.3,minFacePresenceConfidence:.3,minTrackingConfidence:.3,outputFaceBlendshapes:!0,outputFacialTransformationMatrixes:!0,runningMode:"VIDEO",numFaces:this.numFaces});if(this.disposed){r.close();return}this.landmarker=r}async run({sourceCanvas:e,getSource:t,targetFps:a}){this.sourceCanvas=e,this.getSource=t,this.setTargetFps(a),this.analysisCanvas=void 0,this.rafId===null&&this.processFaceTracking()}getModelNode(){const e=this;return{get detectionResults(){return e.detectionResults},getDetectionResults:this.getDetectionResults.bind(this),getFace:this.getFace.bind(this),getRawFaceTrackingData:this.getRawFaceTrackingData.bind(this),setCamera:(a,r=0)=>{this.cameras[r]=a}}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const Ve=n=>n>1?1024:512;var O=(n=>(n.ClosedFist="closed_fist",n.OpenPalm="open_palm",n.PointingUp="pointing_up",n.ThumbDown="thumb_down",n.ThumbUp="thumb_up",n.Victory="victory",n.ILoveYou="i_love_you",n.None="none",n))(O||{});const Ke=512,Ne={Closed_Fist:O.ClosedFist,Open_Palm:O.OpenPalm,Pointing_Up:O.PointingUp,Thumb_Down:O.ThumbDown,Thumb_Up:O.ThumbUp,Victory:O.Victory,ILoveYou:O.ILoveYou,None:O.None},qe=15;class He extends G{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"coordinates");h(this,"gesture");h(this,"sourceCanvas");h(this,"downscaler",new $(Ke))}async getGestureData(){if(!this.landmarker||!this.sourceCanvas)return;const e=this.downscaler.draw(this.sourceCanvas),t=performance.now(),a=this.landmarker.recognizeForVideo(e,t),r=performance.now();this.processingTime=r-t;const o=a.landmarks[0],d=[];if(o){const m=a.gestures[0][0].categoryName;return o.forEach(u=>{d.push({x:B(u.x),y:B(1-u.y),z:-u.z})}),{coordinates:d,gesture:Ne[m]}}return{coordinates:void 0,gesture:void 0}}async processGestureTracking(){if(!this.disposed){if(this.shouldRunInference()){const e=await this.getGestureData();e&&(this.coordinates=e.coordinates,this.gesture=e.gesture)}this.disposed||this.paused||(this.rafId=requestAnimationFrame(this.processGestureTracking.bind(this)))}}resume(){this.paused&&(super.resume(),this.processGestureTracking())}dispose(){if(super.dispose(),this.landmarker){try{this.landmarker.close()}catch{}this.landmarker=null}this.sourceCanvas=void 0,this.downscaler.dispose(),this.coordinates=void 0,this.gesture=void 0}async initialize(){const e=await _.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",E.assetStorageEndpoint).toString()),t=await H(new URL("/assets/xr/models/gesture_tracking.task",E.assetStorageEndpoint).toString()),a=await _.GestureRecognizer.createFromOptions(e,{baseOptions:{modelAssetBuffer:t,delegate:"GPU"},runningMode:"VIDEO",numHands:1});this.landmarker=a}async run({sourceCanvas:e,targetFps:t}){this.sourceCanvas=e,this.setTargetFps(t??qe),this.rafId===null&&await this.processGestureTracking()}getModelNode(){const e=this;return{get coordinates(){return e.coordinates},get gesture(){return e.gesture}}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const Ge=512;class je extends G{constructor(){super();h(this,"landmarker",null);h(this,"processingTime",null);h(this,"hands");h(this,"coordinates");h(this,"gesture");h(this,"handedness");h(this,"sourceCanvas");h(this,"downscaler",new $(Ge))}async getHandData(){if(!this.landmarker||!this.sourceCanvas)return;const e=this.downscaler.draw(this.sourceCanvas),t=performance.now(),a=this.landmarker.detectForVideo(e,t),r=performance.now();this.processingTime=r-t;const o=[],d=a.handedness??a.handednesses??[];if(a.landmarks.forEach((u,S)=>{var f,w,p;if(!u||u.length===0)return;const M=u.map(k=>({x:B(k.x),y:B(1-k.y),z:-k.z})),R=(p=(w=(f=d[S])==null?void 0:f[0])==null?void 0:w.categoryName)==null?void 0:p.toLowerCase(),F=R==="left"||R==="right"?R:void 0,l=u[0].z<0?"closed_fist":"open_palm";o.push({coordinates:M,gesture:l,handedness:F})}),!o.length)return{hands:void 0,coordinates:void 0,gesture:void 0,handedness:void 0};const m=o[0];return{hands:o,coordinates:m.coordinates,gesture:m.gesture,handedness:m.handedness}}async processHandTracking(){if(!this.disposed){if(this.shouldRunInference()){const e=await this.getHandData();e&&(this.hands=e.hands,this.coordinates=e.coordinates,this.gesture=e.gesture,this.handedness=e.handedness)}this.disposed||this.paused||(this.rafId=requestAnimationFrame(this.processHandTracking.bind(this)))}}resume(){this.paused&&(super.resume(),this.processHandTracking())}dispose(){if(super.dispose(),this.landmarker){try{this.landmarker.close()}catch{}this.landmarker=null}this.sourceCanvas=void 0,this.hands=void 0,this.downscaler.dispose(),this.coordinates=void 0,this.gesture=void 0,this.handedness=void 0}async initialize(){const e=await _.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",E.assetStorageEndpoint).toString()),t=await H(new URL("/assets/xr/models/hand_tracking.task",E.assetStorageEndpoint).toString()),a=await _.HandLandmarker.createFromOptions(e,{baseOptions:{modelAssetBuffer:t,delegate:"GPU"},runningMode:"VIDEO",numHands:2});this.landmarker=a}async run({sourceCanvas:e,targetFps:t}){this.sourceCanvas=e,this.setTargetFps(t),this.rafId===null&&await this.processHandTracking()}getModelNode(){const e=this;return{get hands(){return e.hands},get coordinates(){return e.coordinates},get gesture(){return e.gesture},get handedness(){return e.handedness}}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const We=24,Xe=720,Ye=[[255,255,255,255],[0,0,0,0]];class Qe extends G{constructor(){super();h(this,"segmenter",null);h(this,"processingTime",null);h(this,"sourceCanvas");h(this,"processCanvas");h(this,"filterCanvas");h(this,"inputSource");h(this,"inputSourceSize");h(this,"glCanvas");h(this,"drawingUtils");h(this,"useGpuMaskPath",!1);h(this,"maskImageData");h(this,"maskCanvas",null);h(this,"segmentationMaskTexture");h(this,"isMaskSetup",!1);h(this,"isProcessing",!1);h(this,"latestMask",null);h(this,"rawCache",null);h(this,"quality","medium");h(this,"stagingCanvas")}getQualityScaleFactor(){switch(this.quality){case"low":return .5;case"medium":return .75;case"high":return 1;default:return .5}}setInputSource(e){this.inputSource=e,this.inputSourceSize=e?this.readIntrinsicSize(e):void 0}readIntrinsicSize(e){if(e instanceof HTMLVideoElement)return e.videoWidth>0?{width:e.videoWidth,height:e.videoHeight}:void 0;if(e instanceof HTMLImageElement)return e.naturalWidth>0?{width:e.naturalWidth,height:e.naturalHeight}:void 0;const t=e.width,a=e.height;return typeof t=="number"&&t>0&&typeof a=="number"&&a>0?{width:t,height:a}:void 0}ensureProcessCanvasForInput(){if(!this.processCanvas||!this.inputSource)return;const e=this.readIntrinsicSize(this.inputSource);if(!e)return;this.inputSourceSize=e;const t=Math.min(1,Xe/Math.max(e.width,e.height)),a=Math.max(1,Math.round(e.width*t)),r=Math.max(1,Math.round(e.height*t));this.processCanvas.width===a&&this.processCanvas.height===r||(this.processCanvas.width=a,this.processCanvas.height=r,this.glCanvas&&(this.glCanvas.width=a,this.glCanvas.height=r),this.maskImageData=void 0)}async processSegmentation(){if(this.disposed||!this.isProcessing||!this.maskCanvas||!this.processCanvas)return;if(!this.shouldRunInference()){if(this.disposed||this.paused)return;this.rafId=requestAnimationFrame(this.processSegmentation.bind(this));return}const e=this.inputSource??this.sourceCanvas;if(!this.segmenter||!e){if(this.disposed||this.paused)return;this.rafId=requestAnimationFrame(this.processSegmentation.bind(this));return}const t=performance.now();this.ensureProcessCanvasForInput();const a=this.processCanvas.getContext("2d");if(a){const d=this.processCanvas.width,m=this.processCanvas.height;if(a.clearRect(0,0,d,m),this.inputSource&&this.inputSourceSize){const{width:u,height:S}=this.inputSourceSize,M=Math.min(d/u,m/S),R=u*M,F=S*M;a.drawImage(this.inputSource,(d-R)/2,(m-F)/2,R,F)}else a.drawImage(e,0,0,d,m)}const o=this.segmenter.segmentForVideo(this.processCanvas,performance.now()).categoryMask;if(!o){if(this.disposed||this.paused)return;this.rafId=requestAnimationFrame(this.processSegmentation.bind(this));return}if(this.rawCache=null,this.latestMask&&(this.latestMask.close(),this.latestMask=null),this.useGpuMaskPath&&this.drawingUtils&&this.glCanvas)this.drawingUtils.drawCategoryMask(o,Ye),this.latestMask=o.clone(),o.close(),this.blitGlToMask();else{this.latestMask=o.clone();const d=this.readMaskToImageData(o);o.close(),d&&this.blitImageDataToMask(d)}this.segmentationMaskTexture&&(this.isMaskSetup||(this.segmentationMaskTexture.format=P.RGBAFormat,this.segmentationMaskTexture.minFilter=P.LinearFilter,this.segmentationMaskTexture.magFilter=P.LinearFilter,this.segmentationMaskTexture.generateMipmaps=!1,this.isMaskSetup=!0),this.segmentationMaskTexture.needsUpdate=!0),this.processingTime=performance.now()-t,!(this.disposed||this.paused)&&(this.rafId=requestAnimationFrame(this.processSegmentation.bind(this)))}blitGlToMask(){if(!this.maskCanvas||!this.filterCanvas||!this.glCanvas)return;const e=this.maskCanvas.getContext("2d"),t=this.filterCanvas.getContext("2d");!e||!t||(t.filter="blur(0.5px)",t.clearRect(0,0,this.filterCanvas.width,this.filterCanvas.height),t.drawImage(this.glCanvas,0,0,this.filterCanvas.width,this.filterCanvas.height),e.clearRect(0,0,this.maskCanvas.width,this.maskCanvas.height),e.drawImage(this.filterCanvas,0,0,this.maskCanvas.width,this.maskCanvas.height))}readMaskToImageData(e){const t=e.getAsUint8Array(),{width:a,height:r}=e;if(!t||a<=0||r<=0)return null;(!this.maskImageData||this.maskImageData.width!==a||this.maskImageData.height!==r)&&(this.maskImageData=new ImageData(a,r));const o=this.maskImageData.data;for(let d=0;d<t.length;d+=1){const m=t[d]===255?0:255;o[d*4]=255,o[d*4+1]=m,o[d*4+2]=255,o[d*4+3]=m}return this.maskImageData}blitImageDataToMask(e){if(!this.maskCanvas||!this.filterCanvas)return;const t=this.maskCanvas.getContext("2d"),a=this.filterCanvas.getContext("2d");if(!t||!a)return;const r=this.getStagingCanvas(e.width,e.height),o=r.getContext("2d");o&&(o.putImageData(e,0,0),a.filter="blur(0.5px)",a.clearRect(0,0,this.filterCanvas.width,this.filterCanvas.height),a.drawImage(r,0,0,this.filterCanvas.width,this.filterCanvas.height),t.clearRect(0,0,this.maskCanvas.width,this.maskCanvas.height),t.drawImage(this.filterCanvas,0,0,this.maskCanvas.width,this.maskCanvas.height))}getStagingCanvas(e,t){return this.stagingCanvas||(this.stagingCanvas=document.createElement("canvas")),this.stagingCanvas.width!==e&&(this.stagingCanvas.width=e),this.stagingCanvas.height!==t&&(this.stagingCanvas.height=t),this.stagingCanvas}resume(){this.paused&&(super.resume(),this.processSegmentation())}dispose(){if(super.dispose(),this.isProcessing=!1,this.latestMask){try{this.latestMask.close()}catch{}this.latestMask=null}if(this.rawCache=null,this.segmenter){try{this.segmenter.close()}catch{}this.segmenter=null}this.drawingUtils=void 0,this.glCanvas=void 0,this.maskImageData=void 0,this.segmentationMaskTexture&&(this.segmentationMaskTexture.dispose(),this.segmentationMaskTexture=void 0),this.sourceCanvas=void 0,this.inputSource=void 0,this.inputSourceSize=void 0,this.processCanvas=void 0,this.filterCanvas=void 0,this.stagingCanvas=void 0,this.maskCanvas=null}async initialize(e){this.quality=(e==null?void 0:e.quality)??"low";const t=await _.FilesetResolver.forVisionTasks(new URL("/assets/xr/wasm",E.assetStorageEndpoint).toString()),a=await H(new URL("/assets/xr/models/segmentation.tflite",E.assetStorageEndpoint).toString());this.glCanvas=new OffscreenCanvas(1,1);const r=this.glCanvas.getContext("webgl2",{preserveDrawingBuffer:!0});this.segmenter=await _.ImageSegmenter.createFromOptions(t,{baseOptions:{modelAssetBuffer:a,delegate:"GPU"},...r?{canvas:this.glCanvas}:{},outputCategoryMask:!0,outputConfidenceMasks:!1,runningMode:"VIDEO"}),r?(this.drawingUtils=new _.DrawingUtils(r),this.useGpuMaskPath=!0):this.useGpuMaskPath=!1}async run({sourceCanvas:e,renderWidth:t,renderHeight:a,targetFps:r}){var d;if(!e)return;this.setTargetFps(r??We),this.isProcessing=!1,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null);const o=this.getQualityScaleFactor();this.sourceCanvas=e,this.processCanvas=document.createElement("canvas"),this.processCanvas.width=e.width*o,this.processCanvas.height=e.height*o,this.glCanvas&&(this.glCanvas.width=this.processCanvas.width,this.glCanvas.height=this.processCanvas.height),this.maskImageData=void 0,this.maskCanvas=document.createElement("canvas"),this.maskCanvas.width=t,this.maskCanvas.height=a,this.filterCanvas=document.createElement("canvas"),this.filterCanvas.width=t,this.filterCanvas.height=a,(d=this.segmentationMaskTexture)==null||d.dispose(),this.segmentationMaskTexture=new P.CanvasTexture(this.maskCanvas),this.isMaskSetup=!1,this.rawCache=null,this.isProcessing=!0,this.lastInferenceMs=0,this.rafId=requestAnimationFrame(this.processSegmentation.bind(this))}getRawSegmentationData(){if(this.rawCache)return this.rawCache;if(!this.latestMask)return null;const e=this.latestMask.getAsUint8Array();return this.rawCache={maskData:e,width:this.latestMask.width,height:this.latestMask.height},this.rawCache}getModelNode(){const e=this;return{get backgroundSegmentationMask(){return e.segmentationMaskTexture},getMaskCanvas:()=>e.maskCanvas,getRawSegmentationData:()=>e.getRawSegmentationData(),setInputSource:t=>e.setInputSource(t??void 0)}}async getPerformanceData(){return{name:this.constructor.name,processingTime:this.processingTime}}}const ae={[L.BACKGROUND_SEGMENTATION]:Qe,[L.HAND_TRACKER]:je,[L.GESTURE_TRACKER]:He,[L.FACE_TRACKER]:Be,[L.BODY_TRACKER]:Oe},Ze=async n=>{const s=document.createElement("video");s.srcObject=n,s.muted=!0,s.playsInline=!0,s.autoplay=!0,await new Promise(t=>{s.onloadedmetadata=()=>{s.play(),t()}});const e=s;return await new Promise(t=>{const a=setTimeout(t,150),r=()=>{clearTimeout(a),t()};typeof e.requestVideoFrameCallback=="function"?e.requestVideoFrameCallback(r):requestAnimationFrame(()=>requestAnimationFrame(()=>r()))}),s},$e=n=>{const s=new P.CanvasTexture(n);return s.colorSpace=P.SRGBColorSpace,s.format=P.RGBAFormat,s.minFilter=P.LinearFilter,s.magFilter=P.LinearFilter,s.generateMipmaps=!1,s.needsUpdate=!0,s},Je=(n,s)=>{const e=n.videoWidth,t=n.videoHeight;e>0&&t>0&&(s.width!==e&&(s.width=e),s.height!==t&&(s.height=t));const a=s.getContext("2d",{colorSpace:"srgb"});a.save(),a.scale(-1,1),a.drawImage(n,-s.width,0,s.width,s.height),a.restore()},et=(n,s,e=1)=>{const t=s.getContext("2d",{colorSpace:"srgb"}),a=s.width/s.height,r=n.width/n.height;let o,d;r>a?(d=s.height,o=n.width*(s.height/n.height)):(o=s.width,d=n.height*(s.width/n.width));const m=Number.isFinite(e)&&e>0?e:1;o*=m,d*=m;const u=(s.width-o)/2,S=(s.height-d)/2;t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,s.width,s.height),t.drawImage(n,0,0,n.width,n.height,u,S,o,d)},tt=n=>{switch(n instanceof DOMException?n.name:""){case"NotAllowedError":case"PermissionDeniedError":return"permission-denied";case"NotReadableError":case"TrackStartError":return"camera-in-use";case"NotFoundError":case"DevicesNotFoundError":return"no-camera";case"NotSupportedError":case"SecurityError":return"unsupported";default:return n instanceof TypeError?"unsupported":"unknown"}},st={"permission-denied":"Camera access was blocked. Allow camera permissions in your browser, then refresh.","camera-in-use":"Camera is already in use by another app or browser tab. Close it and refresh.","no-camera":"No camera was found on this device.",unsupported:"Unable to access camera. Allow camera permissions in your browser, then refresh.",unknown:"Unable to access camera. Allow camera permissions in your browser, then refresh."},nt=(n,s,e)=>{const t=new Map;let a=!1;const r=(l,f)=>{var w;try{(w=f.dispose)==null||w.call(f)}catch(p){console.warn(`[xr-sdk registry] dispose threw for ${l}`,p)}};return{acquire:async(l,f,w)=>{let p=t.get(l);if(p)return p.refs.add(f),p.activeRefs.add(f),p.initPromise;const k=s[l];if(!k)throw new Error(`Invalid model: ${l}`);const C=new k,K=new Set([f]),V=new Set([f]),U=(async()=>{await C.initialize(w);const N=t.get(l);if(!N||N.model!==C||N.refs.size===0)return r(l,C),C;e&&await e(l,C);const T=t.get(l);return T&&T.refs.size>0&&n.setPipeline(z=>z.set(l,C)),C})();return p={model:C,refs:K,activeRefs:V,initPromise:U,options:w},t.set(l,p),U.catch(()=>{t.get(l)===p&&(t.delete(l),n.setPipeline(T=>T.delete(l))),r(l,C)}),U},release:(l,f)=>{const w=t.get(l);w&&(w.refs.delete(f),w.activeRefs.delete(f)&&w.refs.size>0&&w.activeRefs.size===0&&w.model.pause(),!(w.refs.size>0)&&(t.delete(l),r(l,w.model),n.setPipeline(p=>p.delete(l))))},setActive:(l,f,w)=>{const p=t.get(l);if(!p||!p.refs.has(f))return;const k=p.activeRefs.size>0;w?p.activeRefs.add(f):p.activeRefs.delete(f);const C=p.activeRefs.size>0;k!==C&&(C&&!a?p.model.resume():p.model.pause())},suspendAll:()=>{a=!0;for(const l of t.values())l.model.pause()},resumeActive:()=>{a=!1;for(const l of t.values())l.activeRefs.size>0&&l.model.resume()},get:l=>{var f;return(f=t.get(l))==null?void 0:f.model},getOptions:l=>{var f;return(f=t.get(l))==null?void 0:f.options},releaseAll:()=>{for(const l of Array.from(t.keys())){const f=t.get(l);f&&(f.refs.clear(),t.delete(l),r(l,f.model))}n.setPipeline(l=>l.clear())}}},it={lifecycle:"idle",ready:!1,error:void 0,cameraTexture:void 0,renderWidth:0,renderHeight:0,source:void 0,sourceKind:void 0,pipeline:new Map},at=()=>{let n={...it,pipeline:new Map};const s=new Set,e=()=>{s.forEach(t=>t())};return{getSnapshot:()=>n,set:t=>{let a=!1;for(const r of Object.keys(t))if(t[r]!==n[r]){a=!0;break}a&&(n={...n,...t},e())},setPipeline:t=>{const a=new Map(n.pipeline);return t(a),n={...n,pipeline:a},e(),a},subscribe:t=>(s.add(t),()=>{s.delete(t)})}},rt=({renderHeight:n,renderWidth:s,videoHeight:e,videoWidth:t})=>({height:n||e,width:s||t}),ot=n=>{const s=new Fe({verbose:!0}),e=at();let t=n;const a=i=>{var g;const c=(g=T.getOptions(i))==null?void 0:g.targetFps;return typeof c=="number"?c:t==null?void 0:t.targetFps};let r,o,d,m,u,S,M,R,F,l,f,w=!1,p=!1,k=0;const C=new Set,K=new Set,V=i=>{const c=e.getSnapshot().cameraTexture;c&&c.dispose();const g=$e(i);return e.set({cameraTexture:g}),g},U=async(i,c)=>{if(C.has(i)||e.getSnapshot().lifecycle!=="running"||!u)return;C.add(i);const g=k;try{await c.run({sourceCanvas:u,renderWidth:e.getSnapshot().renderWidth,renderHeight:e.getSnapshot().renderHeight,getSource:()=>e.getSnapshot().sourceKind,targetFps:a(i)}),p&&(await new Promise(v=>requestAnimationFrame(()=>v())),await new Promise(v=>requestAnimationFrame(()=>v())),p&&k===g&&T.suspendAll())}catch(v){throw C.delete(i),v}},T=nt(e,ae,(i,c)=>U(i,c));e.subscribe(()=>{if(e.getSnapshot().lifecycle!=="running")return;const i=e.getSnapshot().pipeline;for(const[c,g]of i.entries())C.has(c)||U(c,g)});const z=()=>{if(f!==void 0&&(cancelAnimationFrame(f),f=void 0),o){try{o.pause()}catch{}try{o.srcObject=null}catch{}o=void 0}if(d){try{d.getTracks().forEach(i=>i.stop())}catch{}d=void 0}},j=()=>{if(w||!o||!m||!u)return;const i=window.__xr_debugger_metrics;if(i!=null&&i.trackCameraFrame&&i.trackCameraFrame(),(e.getSnapshot().sourceKind??"webcam")==="webcam")Je(o,m);else{const v=m.getContext("2d");if(!v)return;const y=o.videoWidth,A=o.videoHeight;m.width!==y&&(m.width=y),m.height!==A&&(m.height=A),v.setTransform(1,0,0,1,0,0),v.clearRect(0,0,y,A),v.drawImage(o,0,0,y,A)}et(m,u,(t==null?void 0:t.cameraZoom)??1.2);const g=e.getSnapshot().cameraTexture;g&&(g.needsUpdate=!0)},J=()=>{if(!o||!m||!u)return;if(p){j();return}const i=()=>{f=requestAnimationFrame(i),j()};f=requestAnimationFrame(i)},de=async i=>{if(i.source===x.WEBCAM)try{const c=t!=null&&t.camRes&&t.camRes>0?t.camRes:960;return await navigator.mediaDevices.getUserMedia({video:{facingMode:"user",frameRate:{min:24,ideal:30,max:60},width:{ideal:c}}})}catch(c){const g=tt(c),v=st[g];throw e.set({error:{error:"PermissionError",message:v,reason:g}}),new I(c instanceof Error?c.message:"getUserMedia failed")}return i.stream},W=async i=>{const c=await de(i);d=c;const g=await Ze(c);o=g,m=new OffscreenCanvas(g.videoWidth,g.videoHeight);const{renderWidth:v,renderHeight:y}=e.getSnapshot(),A=rt({renderWidth:v,renderHeight:y,videoWidth:g.videoWidth,videoHeight:g.videoHeight});u?(u.width!==A.width||u.height!==A.height)&&(u.width=A.width,u.height=A.height,V(u)):(u=new OffscreenCanvas(A.width,A.height),V(u));const ne=i.source===x.STREAM?i.static===!0:!1;p=ne,r=i.source===x.WEBCAM?{source:x.WEBCAM,sourceKind:"webcam"}:{source:x.STREAM,stream:i.stream,static:ne,sourceKind:i.sourceKind??"webcam"},e.set({source:i.source,sourceKind:r.sourceKind,error:void 0})},X=async i=>{const c=i.sourceKind??"webcam";u=i.canvas;const g=V(u);e.set({cameraTexture:g,source:x.CANVAS,sourceKind:c,renderWidth:u.width,renderHeight:u.height,error:void 0}),r={source:x.CANVAS,canvas:i.canvas,sourceKind:c}},le=(i,c)=>!c||i.source!==c.source?!1:i.source===x.STREAM&&c.source===x.STREAM?i.stream===c.stream&&(i.sourceKind??"webcam")===c.sourceKind:!0,ge=async()=>{if(!u)return;const i=k,c=e.getSnapshot().pipeline;for(const[,g]of c.entries())g.resume();await new Promise(g=>requestAnimationFrame(()=>g())),await new Promise(g=>requestAnimationFrame(()=>g())),p&&k===i&&T.suspendAll()},me=(i,c)=>!c||c.source!==x.CANVAS?!1:i.canvas===c.canvas&&(i.sourceKind??"webcam")===c.sourceKind,fe=async i=>{const c=i.source;if(c!==x.WEBCAM&&c!==x.STREAM)throw new I(`Invalid media source: ${String(c)}`);if(le(i,r)){s.log("Media source unchanged, skipping rebind.");return}k+=1;const{lifecycle:g}=e.getSnapshot();if(g==="idle"||g==="stopped"){await W(i),e.set({lifecycle:"media-bound"}),s.log("Media source set to:",i.source);return}if(g==="media-bound"){z(),await W(i),s.log("Media source rebound to:",i.source);return}w=!0,await new Promise(v=>requestAnimationFrame(()=>v())),z(),await W(i),w=!1,J(),p?await ge():T.resumeActive(),s.log("Media source swapped to:",i.source)},pe=async i=>{if(me(i,r)){s.log("Frame source unchanged, skipping rebind.");return}k+=1;const{lifecycle:c}=e.getSnapshot();if(c==="idle"||c==="stopped"){await X(i),e.set({lifecycle:"media-bound"}),s.log("Frame source set to canvas.");return}if(c==="media-bound"){z(),await X(i),s.log("Frame source rebound to canvas.");return}w=!0,await new Promise(g=>requestAnimationFrame(()=>g())),z(),await X(i),w=!1,s.log("Frame source swapped to canvas.")},ve=async()=>{const{lifecycle:i}=e.getSnapshot();if(i==="running")return;if(i==="idle")throw new I("session.start() called before setMediaSource — call setMediaSource first");if(!u)throw new I("session.start(): media source not bound");const c=(r==null?void 0:r.source)===x.CANVAS;if(!c&&(!o||!m))throw i==="stopped"?new I("session.start() called from stopped state without a media source — call setMediaSource first"):new I("session.start(): media source not bound");c||J(),T.resumeActive(),e.set({lifecycle:"running"}),await new Promise(v=>requestAnimationFrame(()=>v()));const g=e.getSnapshot().pipeline;for(const[v,y]of g.entries())await U(v,y);e.set({ready:!0}),s.log("XR session started.")},ee=async()=>{const{lifecycle:i}=e.getSnapshot();i==="stopped"||i==="idle"||(z(),T.suspendAll(),e.set({lifecycle:"stopped",ready:!1}),s.log("XR session stopped."))},we=async()=>{await ee(),T.releaseAll(),K.clear();const i=e.getSnapshot().cameraTexture;i&&i.dispose(),C.clear(),r=void 0,k+=1,u=void 0,m=void 0,p=!1,e.set({lifecycle:"idle",cameraTexture:void 0,source:void 0}),s.log("XR session reset.")},Ce=async i=>{const c="legacy:registerXRPipeline",g=[];await Promise.all(i.map(async v=>{const{model:y}=v;if(!ae[y])throw new I(`Invalid model: ${y}`);K.has(y)||g.push(y);const A="options"in v?v.options:void 0;await T.acquire(y,c,A)})),g.length>0&&(g.forEach(v=>K.add(v)),s.log("XR pipeline registered."))},Se=i=>{const c=T.get(i);if(!c)throw new I(`Model ${i} is not registered in the pipeline`);return c.getModelNode()},te=async(i,c)=>{i<=0||c<=0||(e.set({renderWidth:i,renderHeight:c}),u&&(u.width!==i||u.height!==c)&&(u.width=i,u.height=c,V(u),p&&j()),s.log(`Source canvas set. Render size: ${i}x${c}`))},ke=async i=>{var y;S=i;const c=(y=i.getBoundingClientRect)==null?void 0:y.call(i),g=c&&c.width>0?Math.round(c.width):i.clientWidth,v=c&&c.height>0?Math.round(c.height):i.clientHeight;await te(g,v)},ye=i=>{M=i.renderer,R=i.scene,F=i.camera,l=i.renderFrame},se=()=>{if(!M||!R||!F)throw new I("XR frame render requested before the R3F state was bound — make sure <XRScene> is mounted");l?l():M.render(R,F)};return{store:e,registry:T,setMediaSource:fe,start:ve,stop:ee,reset:we,setFrameSource:pe,registerXRPipeline:Ce,getModelNode:Se,captureFrame:()=>{if(!S)throw new I("session.captureFrame() called before the XRScene render target was bound — make sure <XRScene> is mounted");if(!M||!R||!F)throw new I("session.captureFrame() called before the R3F state was bound — make sure <XRScene> is mounted");return se(),S.toDataURL("image/png")},getInputFrame:()=>u??null,_setRenderTarget:ke,_setRenderSize:te,_setR3FState:ye,_renderFrame:se,_getVideoElement:()=>o,_setPerf:i=>{if(t=i,e.getSnapshot().lifecycle!=="running"||!u)return;const c=e.getSnapshot().pipeline;for(const[g,v]of c.entries())v.run({sourceCanvas:u,renderWidth:e.getSnapshot().renderWidth,renderHeight:e.getSnapshot().renderHeight,getSource:()=>e.getSnapshot().sourceKind,targetFps:a(g)})}}},ct=n=>{const s=b.useRef(n),e=b.useMemo(()=>ot(s.current),[]),t=JSON.stringify(n??{});return b.useEffect(()=>{e._setPerf(n)},[e,t]),e},Z=new Map,ht=()=>({register:(n,s)=>{s?Z.set(n,s):Z.delete(n)},resolve:n=>n?Z.get(n)??null:null}),oe=ht(),ce=b.createContext(null),ut=({children:n})=>{const s=b.useRef(new Map),e=b.useCallback((r,o)=>{o?s.current.set(r,o):s.current.delete(r)},[]),t=b.useCallback(r=>r?s.current.get(r)??null:null,[]),a=b.useMemo(()=>({register:e,resolve:t}),[e,t]);return b.createElement(ce.Provider,{value:a},n)},he=()=>b.useContext(ce)??oe,dt=()=>he().register,lt=()=>he().resolve;oe.register;const ue=b.createContext(void 0),gt=()=>{const n=b.useContext(ue);if(!n)throw new I("XR context can only be used inside XRProvider, did you forget to wrap your app in <XRProvider>?");return n},mt=({children:n,perf:s})=>{const e=ct(s),t=b.useMemo(()=>({session:e}),[e]);return ie.jsx(ue.Provider,{value:t,children:ie.jsx(ut,{children:n})})};exports.XRMediaSource=x;exports.XRModel=L;exports.XRProvider=mt;exports.fetchAndVerify=re;exports.libConfig=E;exports.unprojectToZZero=Ae;exports.unprojectToZZeroInto=q;exports.useRegisterRuntimeObject=dt;exports.useResolveRuntimeObject=lt;exports.useXRContext=gt;