facezk-core
Version:
ZKP-AI Proof of Humanity: Live Selfie Check with Biometric Template Extraction and Fuzzy Hashing
94 lines • 2.62 MB
JavaScript
"use strict";var $U=Object.create;var g0=Object.defineProperty;var GU=Object.getOwnPropertyDescriptor;var HU=Object.getOwnPropertyNames;var qU=Object.getPrototypeOf,jU=Object.prototype.hasOwnProperty;var y0=(t,e)=>()=>(t&&(e=t(t=0)),e);var nt=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),KU=(t,e)=>{for(var n in e)g0(t,n,{get:e[n],enumerable:!0})},xx=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of HU(e))!jU.call(t,a)&&a!==n&&g0(t,a,{get:()=>e[a],enumerable:!(r=GU(e,a))||r.enumerable});return t};var ml=(t,e,n)=>(n=t!=null?$U(qU(t)):{},xx(e||!t||!t.__esModule?g0(n,"default",{value:t,enumerable:!0}):n,t)),XU=t=>xx(g0({},"__esModule",{value:!0}),t);var lt,ci,Di,Wn,Ko,ia,x0,Ld,Xo=y0(()=>{"use strict";lt=class extends Error{constructor(e,n,r){super(e),this.name="FaceZKError",this.code=n,this.details=r}},ci=class extends lt{constructor(e,n){super(e,"VALIDATION_ERROR",n),this.name="ValidationError"}},Di=class extends lt{constructor(e,n){super(e,"PLUGIN_ERROR",n),this.name="PluginError"}},Wn=class extends lt{constructor(e,n){super(e,"CRYPTO_ERROR",n),this.name="CryptoError"}},Ko=class extends lt{constructor(e,n){super(e,"MEMORY_ERROR",n),this.name="MemoryError"}},ia=class extends lt{constructor(e,n){super(e,"AUDIT_ERROR",n),this.name="AuditError"}},x0={RETRY:"retry",FALLBACK:"fallback",DEGRADE:"degrade",ABORT:"abort",LOG_AND_CONTINUE:"log_and_continue"},Ld=class{async handle(e){console.error(`[${e.code}] ${e.message}`,e.details),await this.logToExternalService(e)}canRecover(e){return["PROCESSING_ERROR","MEMORY_ERROR","PERFORMANCE_ERROR"].includes(e.code)}getRecoveryStrategy(e){switch(e.code){case"MEMORY_ERROR":return x0.RETRY;case"PERFORMANCE_ERROR":return x0.DEGRADE;case"PROCESSING_ERROR":return x0.FALLBACK;default:return x0.ABORT}}async logToExternalService(e){try{let n={code:e.code,message:e.message,details:e.details,timestamp:new Date().toISOString(),userAgent:navigator.userAgent,url:window.location.href};await fetch("/api/errors",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})}catch(n){console.error("Failed to log error to external service:",n)}}}});var Gb=nt((XZe,$b)=>{"use strict";var ZU=Object.create,Kd=Object.defineProperty,YU=Object.getOwnPropertyDescriptor,JU=Object.getOwnPropertyNames,QU=Object.getPrototypeOf,e$=Object.prototype.hasOwnProperty,j9=t=>{throw TypeError(t)},t$=(t,e,n)=>e in t?Kd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,n$=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),yu=(t,e)=>{for(var n in e)Kd(t,n,{get:e[n],enumerable:!0})},K9=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of JU(e))!e$.call(t,a)&&a!==n&&Kd(t,a,{get:()=>e[a],enumerable:!(r=YU(e,a))||r.enumerable});return t},wt=(t,e,n)=>(n=t!=null?ZU(QU(t)):{},K9(e||!t||!t.__esModule?Kd(n,"default",{value:t,enumerable:!0}):n,t)),r$=t=>K9(Kd({},"__esModule",{value:!0}),t),He=(t,e,n)=>t$(t,typeof e!="symbol"?e+"":e,n),X9=(t,e,n)=>e.has(t)||j9("Cannot "+n),Fi=(t,e,n)=>(X9(t,e,"read from private field"),n?n.call(t):e.get(t)),cu=(t,e,n)=>e.has(t)?j9("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),El=(t,e,n,r)=>(X9(t,e,"write to private field"),r?r.call(t,n):e.set(t,n),n),kt=n$((t,e)=>{"use strict";var n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty,o=(y,A)=>{for(var x in A)n(y,x,{get:A[x],enumerable:!0})},s=(y,A,x,b)=>{if(A&&typeof A=="object"||typeof A=="function")for(let w of a(A))!i.call(y,w)&&w!==x&&n(y,w,{get:()=>A[w],enumerable:!(b=r(A,w))||b.enumerable});return y},u=(y,A,x)=>(s(y,A,"default"),x&&s(x,A,"default")),l=y=>s(n({},"__esModule",{value:!0}),y),c={};o(c,{version:()=>g}),e.exports=l(c),u(c,require("@tensorflow/tfjs-node"),e.exports);var p="4.22.0",d="4.22.0",f="4.22.0",h="4.22.0",m="4.22.0",v="4.22.0",g={tfjs:p,"tfjs-core":p,"tfjs-converter":d,"tfjs-backend-cpu":f,"tfjs-backend-webgl":h,"tfjs-backend-wasm":m,"tfjs-backend-webgpu":v}}),Z9={};yu(Z9,{Env:()=>Q9,Human:()=>q9,default:()=>q9,defaults:()=>np,draw:()=>$g,empty:()=>Cl,env:()=>Fe,match:()=>Kg,models:()=>Pb});$b.exports=r$(Z9);var gl=wt(kt());function fe(...t){let e=new Date,n=`${e.getHours().toString().padStart(2,"0")}:${e.getMinutes().toString().padStart(2,"0")}:${e.getSeconds().toString().padStart(2,"0")}.${e.getMilliseconds().toString().padStart(3,"0")}`;t&&console.log(n,"Human:",...t)}function a$(t,e){let n=t.endsWith("/")?"":"/",r=e.startsWith(".")||e.startsWith("/")||e.startsWith("http:")||e.startsWith("https:")||e.startsWith("file:")?`${e}`:`${t}${n}${e}`;if(!r.toLocaleLowerCase().includes(".json"))throw new Error(`modelpath error: expecting json file: ${r}`);return r}var Ee=()=>typeof performance<"u"?performance.now():parseInt((Number(process.hrtime.bigint())/1e3/1e3).toString());function Y9(t,e,n="config",r=[]){for(let a of Object.keys(e))if(typeof e[a]=="object")Y9(t[a],e[a],a,r);else{let i=t&&typeof t[a]<"u";i||r.push({reason:"unknown property",where:`${n}.${a} = ${e[a]}`});let o=t&&typeof t[a]==typeof e[a];i&&!o&&r.push({reason:"property type mismatch",where:`${n}.${a} = ${e[a]}`,expected:typeof t[a]})}return e.debug&&n==="config"&&r.length>0&&fe("invalid configuration",r),r}function ca(...t){let e=n=>n&&typeof n=="object";return t.reduce((n,r)=>(Object.keys(r||{}).forEach(a=>{let i=n[a],o=r[a];Array.isArray(i)&&Array.isArray(o)?n[a]=i.concat(...o):e(i)&&e(o)?n[a]=ca(i,o):n[a]=o}),n),{})}var np={backend:"",modelBasePath:"",cacheModels:!0,validateModels:!0,wasmPath:"",wasmPlatformFetch:!1,debug:!1,async:!0,warmup:"full",cacheSensitivity:.7,skipAllowed:!1,deallocate:!1,flags:{},softwareKernels:!1,filter:{enabled:!0,equalization:!1,width:0,height:0,flip:!1,return:!0,autoBrightness:!0,brightness:0,contrast:0,sharpness:0,blur:0,saturation:0,hue:0,negative:!1,sepia:!1,vintage:!1,kodachrome:!1,technicolor:!1,polaroid:!1,pixelate:0},gesture:{enabled:!0},face:{enabled:!0,detector:{modelPath:"blazeface.json",rotation:!1,maxDetected:1,skipFrames:99,skipTime:2500,minConfidence:.2,minSize:0,iouThreshold:.1,scale:1.4,mask:!1,return:!1},mesh:{enabled:!0,modelPath:"facemesh.json",keepInvalid:!1},attention:{enabled:!1,modelPath:"facemesh-attention.json"},iris:{enabled:!0,scale:2.3,modelPath:"iris.json"},emotion:{enabled:!0,minConfidence:.1,skipFrames:99,skipTime:1500,modelPath:"emotion.json"},description:{enabled:!0,modelPath:"faceres.json",skipFrames:99,skipTime:3e3,minConfidence:.1},antispoof:{enabled:!1,skipFrames:99,skipTime:4e3,modelPath:"antispoof.json"},liveness:{enabled:!1,skipFrames:99,skipTime:4e3,modelPath:"liveness.json"}},body:{enabled:!0,modelPath:"movenet-lightning.json",maxDetected:-1,minConfidence:.3,skipFrames:1,skipTime:200},hand:{enabled:!0,rotation:!0,skipFrames:99,skipTime:1e3,minConfidence:.5,iouThreshold:.2,maxDetected:-1,landmarks:!0,detector:{modelPath:"handtrack.json"},skeleton:{modelPath:"handlandmark-lite.json"}},object:{enabled:!1,modelPath:"centernet.json",minConfidence:.2,iouThreshold:.4,maxDetected:10,skipFrames:99,skipTime:2e3},segmentation:{enabled:!1,modelPath:"rvm.json",ratio:.5,mode:"default"}},Zo=wt(kt()),bt=wt(kt()),i$=`
precision highp float;
attribute vec2 pos;
attribute vec2 uv;
varying vec2 vUv;
uniform float flipY;
void main(void) {
vUv = uv;
gl_Position = vec4(pos.x, pos.y*flipY, 0.0, 1.);
}
`,o$=`
precision highp float;
varying vec2 vUv;
uniform sampler2D texture;
uniform float m[20];
void main(void) {
vec4 c = texture2D(texture, vUv);
gl_FragColor.r = m[0] * c.r + m[1] * c.g + m[2] * c.b + m[3] * c.a + m[4];
gl_FragColor.g = m[5] * c.r + m[6] * c.g + m[7] * c.b + m[8] * c.a + m[9];
gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[13] * c.a + m[14];
gl_FragColor.a = m[15] * c.r + m[16] * c.g + m[17] * c.b + m[18] * c.a + m[19];
}
`,s$=`
precision highp float;
varying vec2 vUv;
uniform sampler2D texture;
uniform float m[20];
void main(void) {
vec4 c = texture2D(texture, vUv);
gl_FragColor.r = m[0] * c.r + m[1] * c.g + m[2] * c.b + m[4];
gl_FragColor.g = m[5] * c.r + m[6] * c.g + m[7] * c.b + m[9];
gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[14];
gl_FragColor.a = c.a;
}
`,u$=`
precision highp float;
varying vec2 vUv;
uniform vec2 size;
uniform sampler2D texture;
vec2 pixelate(vec2 coord, vec2 size) {
return floor( coord / size ) * size;
}
void main(void) {
gl_FragColor = vec4(0.0);
vec2 coord = pixelate(vUv, size);
gl_FragColor += texture2D(texture, coord);
}
`,l$=`
precision highp float;
varying vec2 vUv;
uniform sampler2D texture;
uniform vec2 px;
void main(void) {
gl_FragColor = vec4(0.0);
gl_FragColor += texture2D(texture, vUv + vec2(-7.0*px.x, -7.0*px.y))*0.0044299121055113265;
gl_FragColor += texture2D(texture, vUv + vec2(-6.0*px.x, -6.0*px.y))*0.00895781211794;
gl_FragColor += texture2D(texture, vUv + vec2(-5.0*px.x, -5.0*px.y))*0.0215963866053;
gl_FragColor += texture2D(texture, vUv + vec2(-4.0*px.x, -4.0*px.y))*0.0443683338718;
gl_FragColor += texture2D(texture, vUv + vec2(-3.0*px.x, -3.0*px.y))*0.0776744219933;
gl_FragColor += texture2D(texture, vUv + vec2(-2.0*px.x, -2.0*px.y))*0.115876621105;
gl_FragColor += texture2D(texture, vUv + vec2(-1.0*px.x, -1.0*px.y))*0.147308056121;
gl_FragColor += texture2D(texture, vUv )*0.159576912161;
gl_FragColor += texture2D(texture, vUv + vec2( 1.0*px.x, 1.0*px.y))*0.147308056121;
gl_FragColor += texture2D(texture, vUv + vec2( 2.0*px.x, 2.0*px.y))*0.115876621105;
gl_FragColor += texture2D(texture, vUv + vec2( 3.0*px.x, 3.0*px.y))*0.0776744219933;
gl_FragColor += texture2D(texture, vUv + vec2( 4.0*px.x, 4.0*px.y))*0.0443683338718;
gl_FragColor += texture2D(texture, vUv + vec2( 5.0*px.x, 5.0*px.y))*0.0215963866053;
gl_FragColor += texture2D(texture, vUv + vec2( 6.0*px.x, 6.0*px.y))*0.00895781211794;
gl_FragColor += texture2D(texture, vUv + vec2( 7.0*px.x, 7.0*px.y))*0.0044299121055113265;
}
`,c$=`
precision highp float;
varying vec2 vUv;
uniform sampler2D texture;
uniform vec2 px;
uniform float m[9];
void main(void) {
vec4 c11 = texture2D(texture, vUv - px); // top left
vec4 c12 = texture2D(texture, vec2(vUv.x, vUv.y - px.y)); // top center
vec4 c13 = texture2D(texture, vec2(vUv.x + px.x, vUv.y - px.y)); // top right
vec4 c21 = texture2D(texture, vec2(vUv.x - px.x, vUv.y) ); // mid left
vec4 c22 = texture2D(texture, vUv); // mid center
vec4 c23 = texture2D(texture, vec2(vUv.x + px.x, vUv.y) ); // mid right
vec4 c31 = texture2D(texture, vec2(vUv.x - px.x, vUv.y + px.y) ); // bottom left
vec4 c32 = texture2D(texture, vec2(vUv.x, vUv.y + px.y) ); // bottom center
vec4 c33 = texture2D(texture, vUv + px ); // bottom right
gl_FragColor =
c11 * m[0] + c12 * m[1] + c22 * m[2] +
c21 * m[3] + c22 * m[4] + c23 * m[5] +
c31 * m[6] + c32 * m[7] + c33 * m[8];
gl_FragColor.a = c22.a;
}
`,Qv=(t,e,n)=>{let r=new RegExp("\\b"+e+" \\w+ (\\w+)","ig");t.replace(r,(a,i)=>(n[i]=0,a))},p$=class{constructor(t,e,n){He(this,"uniform",{}),He(this,"attribute",{}),He(this,"gl"),He(this,"id"),He(this,"compile",(i,o)=>{let s=this.gl.createShader(o);return s?(this.gl.shaderSource(s,i),this.gl.compileShader(s),this.gl.getShaderParameter(s,this.gl.COMPILE_STATUS)?s:(fe(`filter: gl compile failed: ${this.gl.getShaderInfoLog(s)||"unknown"}`),null)):(fe("filter: could not create shader"),null)}),this.gl=t;let r=this.compile(e,this.gl.VERTEX_SHADER),a=this.compile(n,this.gl.FRAGMENT_SHADER);if(this.id=this.gl.createProgram(),!(!r||!a)){if(!this.id){fe("filter: could not create webgl program");return}if(this.gl.attachShader(this.id,r),this.gl.attachShader(this.id,a),this.gl.linkProgram(this.id),!this.gl.getProgramParameter(this.id,this.gl.LINK_STATUS)){fe(`filter: gl link failed: ${this.gl.getProgramInfoLog(this.id)||"unknown"}`);return}this.gl.useProgram(this.id),Qv(e,"attribute",this.attribute);for(let i in this.attribute)this.attribute[i]=this.gl.getAttribLocation(this.id,i);Qv(e,"uniform",this.uniform),Qv(n,"uniform",this.uniform);for(let i in this.uniform)this.uniform[i]=this.gl.getUniformLocation(this.id,i)}}};function d$(){let t=0,e=null,n=!1,r=-1,a=[null,null],i=[],o=null,s=null,u=hu(100,100),l={},c={INTERMEDIATE:1},p=u.getContext("webgl");if(!p){fe("filter: cannot get webgl context");return}this.gl=p;function d(y,A){if(!(y===u.width&&A===u.height)){if(u.width=y,u.height=A,!o){let x=new Float32Array([-1,-1,0,1,1,-1,1,1,-1,1,0,0,-1,1,0,0,1,-1,1,1,1,1,1,0]);o=p.createBuffer(),p.bindBuffer(p.ARRAY_BUFFER,o),p.bufferData(p.ARRAY_BUFFER,x,p.STATIC_DRAW),p.pixelStorei(p.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0)}p.viewport(0,0,u.width,u.height),a=[null,null]}}function f(y,A){let x=p.createFramebuffer();p.bindFramebuffer(p.FRAMEBUFFER,x);let b=p.createRenderbuffer();p.bindRenderbuffer(p.RENDERBUFFER,b);let w=p.createTexture();return p.bindTexture(p.TEXTURE_2D,w),p.texImage2D(p.TEXTURE_2D,0,p.RGBA,y,A,0,p.RGBA,p.UNSIGNED_BYTE,null),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MAG_FILTER,p.LINEAR),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MIN_FILTER,p.LINEAR),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_S,p.CLAMP_TO_EDGE),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_T,p.CLAMP_TO_EDGE),p.framebufferTexture2D(p.FRAMEBUFFER,p.COLOR_ATTACHMENT0,p.TEXTURE_2D,w,0),p.bindTexture(p.TEXTURE_2D,null),p.bindFramebuffer(p.FRAMEBUFFER,null),{fbo:x,texture:w}}function h(y){return a[y]=a[y]||f(u.width,u.height),a[y]}function m(y=0){if(!s)return;let A=null,x=null,b=!1;t===0?A=e:A=h(r).texture||null,t++,n&&!(y&c.INTERMEDIATE)?(x=null,b=t%2===0):(r=(r+1)%2,x=h(r).fbo||null),p.bindTexture(p.TEXTURE_2D,A),p.bindFramebuffer(p.FRAMEBUFFER,x),p.uniform1f(s.uniform.flipY,b?-1:1),p.drawArrays(p.TRIANGLES,0,6)}function v(y){if(l[y])return s=l[y],p.useProgram((s?s.id:null)||null),s;if(s=new p$(p,i$,y),!s)return fe("filter: could not get webgl program"),null;let A=Float32Array.BYTES_PER_ELEMENT,x=4*A;return p.enableVertexAttribArray(s.attribute.pos),p.vertexAttribPointer(s.attribute.pos,2,p.FLOAT,!1,x,0*A),p.enableVertexAttribArray(s.attribute.uv),p.vertexAttribPointer(s.attribute.uv,2,p.FLOAT,!1,x,2*A),l[y]=s,s}let g={colorMatrix:y=>{let A=new Float32Array(y);A[4]/=255,A[9]/=255,A[14]/=255,A[19]/=255;let x=A[18]===1&&A[3]===0&&A[8]===0&&A[13]===0&&A[15]===0&&A[16]===0&&A[17]===0&&A[19]===0?s$:o$,b=v(x);b&&(p.uniform1fv(b.uniform.m,A),m())},brightness:y=>{let A=(y||0)+1;g.colorMatrix([A,0,0,0,0,0,A,0,0,0,0,0,A,0,0,0,0,0,1,0])},saturation:y=>{let A=(y||0)*2/3+1,x=(A-1)*-.5;g.colorMatrix([A,x,x,0,0,x,A,x,0,0,x,x,A,0,0,0,0,0,1,0])},desaturate:()=>{g.saturation(-1)},contrast:y=>{let A=(y||0)+1,x=-128*(A-1);g.colorMatrix([A,0,0,0,x,0,A,0,0,x,0,0,A,0,x,0,0,0,1,0])},negative:()=>{g.contrast(-2)},hue:y=>{y=(y||0)/180*Math.PI;let A=Math.cos(y),x=Math.sin(y),b=.213,w=.715,k=.072;g.colorMatrix([b+A*(1-b)+x*-b,w+A*-w+x*-w,k+A*-k+x*(1-k),0,0,b+A*-b+x*.143,w+A*(1-w)+x*.14,k+A*-k+x*-.283,0,0,b+A*-b+x*-(1-b),w+A*-w+x*w,k+A*(1-k)+x*k,0,0,0,0,0,1,0])},desaturateLuminance:()=>{g.colorMatrix([.2764723,.929708,.0938197,0,-37.1,.2764723,.929708,.0938197,0,-37.1,.2764723,.929708,.0938197,0,-37.1,0,0,0,1,0])},sepia:()=>{g.colorMatrix([.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0])},brownie:()=>{g.colorMatrix([.5997023498159715,.34553243048391263,-.2708298674538042,0,47.43192855600873,-.037703249837783157,.8609577587992641,.15059552388459913,0,-36.96841498319127,.24113635128153335,-.07441037908422492,.44972182064877153,0,-7.562075277591283,0,0,0,1,0])},vintagePinhole:()=>{g.colorMatrix([.6279345635605994,.3202183420819367,-.03965408211312453,0,9.651285835294123,.02578397704808868,.6441188644374771,.03259127616149294,0,7.462829176470591,.0466055556782719,-.0851232987247891,.5241648018700465,0,5.159190588235296,0,0,0,1,0])},kodachrome:()=>{g.colorMatrix([1.1285582396593525,-.3967382283601348,-.03992559172921793,0,63.72958762196502,-.16404339962244616,1.0835251566291304,-.05498805115633132,0,24.732407896706203,-.16786010706155763,-.5603416277695248,1.6014850761964943,0,35.62982807460946,0,0,0,1,0])},technicolor:()=>{g.colorMatrix([1.9125277891456083,-.8545344976951645,-.09155508482755585,0,11.793603434377337,-.3087833385928097,1.7658908555458428,-.10601743074722245,0,-70.35205161461398,-.231103377548616,-.7501899197440212,1.847597816108189,0,30.950940869491138,0,0,0,1,0])},polaroid:()=>{g.colorMatrix([1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0])},shiftToBGR:()=>{g.colorMatrix([0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0])},convolution:y=>{let A=new Float32Array(y),x=1/u.width,b=1/u.height,w=v(c$);w&&(p.uniform1fv(w.uniform.m,A),p.uniform2f(w.uniform.px,x,b),m())},detectEdges:()=>{g.convolution.call(this,[0,1,0,1,-4,1,0,1,0])},sobelX:()=>{g.convolution.call(this,[-1,0,1,-2,0,2,-1,0,1])},sobelY:()=>{g.convolution.call(this,[-1,-2,-1,0,0,0,1,2,1])},sharpen:y=>{let A=y||1;g.convolution.call(this,[0,-1*A,0,-1*A,1+4*A,-1*A,0,-1*A,0])},emboss:y=>{let A=y||1;g.convolution.call(this,[-2*A,-1*A,0,-1*A,1,1*A,0,1*A,2*A])},blur:y=>{let A=y/7/u.width,x=y/7/u.height,b=v(l$);b&&(p.uniform2f(b.uniform.px,0,x),m(c.INTERMEDIATE),p.uniform2f(b.uniform.px,A,0),m())},pixelate:y=>{let A=y/u.width,x=y/u.height,b=v(u$);b&&(p.uniform2f(b.uniform.size,A,x),m())}};this.add=function(y){let A=Array.prototype.slice.call(arguments,1),x=g[y];i.push({func:x,args:A})},this.reset=function(){i=[]},this.get=function(){return i},this.apply=function(y){d(y.width,y.height),t=0,e||(e=p.createTexture()),p.bindTexture(p.TEXTURE_2D,e),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_S,p.CLAMP_TO_EDGE),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_T,p.CLAMP_TO_EDGE),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MIN_FILTER,p.NEAREST),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MAG_FILTER,p.NEAREST),p.texImage2D(p.TEXTURE_2D,0,p.RGBA,p.RGBA,p.UNSIGNED_BYTE,y);for(let A=0;A<i.length;A++){n=A===i.length-1;let x=i[A];x.func.apply(this,x.args||[])}return u},this.draw=function(y){return this.add("brightness",0),this.apply(y)}}var jn=wt(kt());async function J9(t){let e=t.shape.length===4?jn.squeeze(t):t,n=jn.split(e,3,2),r=[jn.min(n[0]),jn.min(n[1]),jn.min(n[2])],a=[jn.max(n[0]),jn.max(n[1]),jn.max(n[2])],i=await Promise.all(a.map(l=>l.data())),o=Math.max(i[0][0],i[1][0],i[2][0]),s=(o>1?255:1)/o,u;if(s>1){let l=[jn.sub(n[0],r[0]),jn.sub(n[1],r[1]),jn.sub(n[2],r[2])],c=[jn.sub(a[0],r[0]),jn.sub(a[1],r[1]),jn.sub(a[2],r[2])],p=[jn.mul(l[0],s),jn.mul(l[1],s),jn.mul(l[2],s)],d=jn.stack([p[0],p[1],p[2]],2);u=jn.reshape(d,[1,e.shape[0]||0,e.shape[1]||0,3]),jn.dispose([...l,...c,...p,d])}else u=jn.expandDims(e,0);return jn.dispose([...n,...r,...a,n,e,t]),u}var A0=3840,Sr=null,Er=null,Yc=null,pn,di={inputSum:0,cacheDiff:1,sumMethod:0,inputTensor:void 0};function Ax(){di.inputSum=0,di.cacheDiff=1,di.sumMethod=0,di.inputTensor=void 0}function hu(t,e){let n;if(Fe.browser)if(Fe.worker){if(typeof OffscreenCanvas>"u")throw new Error("canvas error: attempted to run in web worker but OffscreenCanvas is not supported");n=new OffscreenCanvas(t,e)}else if(typeof document<"u")n=document.createElement("canvas"),n.width=t,n.height=e;else if(typeof navigator<"u"&&navigator.product==="ReactNative")if(typeof Fe.Canvas<"u")n=new Fe.Canvas(t,e);else if(typeof globalThis.Canvas<"u")n=new globalThis.Canvas(t,e);else throw new Error("canvas error: attempted to use canvas in react-native without canvas support installed");else throw new Error("canvas error: attempted to run in browser but DOM is not defined");else typeof Fe.Canvas<"u"?n=new Fe.Canvas(t,e):typeof globalThis.Canvas<"u"&&(n=new globalThis.Canvas(t,e));return n}function b0(t,e){let n=e||hu(t.width,t.height);return n.getContext("2d").drawImage(t,0,0),n}async function eg(t,e,n=!0){var r,a,i;if(!t)return e.debug&&fe("input error: input is missing"),{tensor:null,canvas:null};if(!(t instanceof bt.Tensor)&&!(typeof Image<"u"&&t instanceof Image)&&!(typeof globalThis.Canvas<"u"&&t instanceof globalThis.Canvas)&&!(typeof ImageData<"u"&&t instanceof ImageData)&&!(typeof ImageBitmap<"u"&&t instanceof ImageBitmap)&&!(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement)&&!(typeof HTMLMediaElement<"u"&&t instanceof HTMLMediaElement)&&!(typeof HTMLVideoElement<"u"&&t instanceof HTMLVideoElement)&&!(typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement)&&!(typeof OffscreenCanvas<"u"&&t instanceof OffscreenCanvas))throw new Error("input error: type not recognized");if(t instanceof bt.Tensor){let m=null;if(t.isDisposedInternal)throw new Error("input error: attempted to use tensor but it is disposed");if(!t.shape)throw new Error("input error: attempted to use tensor without a shape");if(t.shape.length===3){if(t.shape[2]===3)m=bt.expandDims(t,0);else if(t.shape[2]===4){let v=bt.slice3d(t,[0,0,0],[-1,-1,3]);m=bt.expandDims(v,0),bt.dispose(v)}}else t.shape.length===4&&(t.shape[3]===3?m=bt.clone(t):t.shape[3]===4&&(m=bt.slice4d(t,[0,0,0,0],[-1,-1,-1,3])));if(m==null||m.shape.length!==4||m.shape[0]!==1||m.shape[3]!==3)throw new Error(`input error: attempted to use tensor with unrecognized shape: ${t.shape.toString()}`);if(m.dtype==="int32"){let v=bt.cast(m,"float32");bt.dispose(m),m=v}return{tensor:m,canvas:e.filter.return?Er:null}}if(typeof t.readyState<"u"&&t.readyState<=2)return e.debug&&fe("input stream is not ready"),{tensor:null,canvas:Sr};let o=t.naturalWidth||t.videoWidth||t.width||t.shape&&t.shape[1]>0,s=t.naturalHeight||t.videoHeight||t.height||t.shape&&t.shape[2]>0;if(!o||!s)return e.debug&&fe("cannot determine input dimensions"),{tensor:null,canvas:Sr};let u=o,l=s;if(u>A0&&(u=A0,l=Math.trunc(u*s/o)),l>A0&&(l=A0,u=Math.trunc(l*o/s)),(((r=e.filter)==null?void 0:r.width)||0)>0?u=e.filter.width:(((a=e.filter)==null?void 0:a.height)||0)>0&&(u=o*((e.filter.height||0)/s)),(e.filter.height||0)>0?l=e.filter.height:(e.filter.width||0)>0&&(l=s*((e.filter.width||0)/o)),!u||!l)throw new Error("input error: cannot determine dimension");(!Sr||Sr.width!==u||Sr.height!==l)&&(Sr=hu(u,l));let c=Sr.getContext("2d");if(typeof ImageData<"u"&&t instanceof ImageData?c.putImageData(t,0,0):e.filter.flip&&typeof c.translate<"u"?(c.translate(o,0),c.scale(-1,1),c.drawImage(t,0,0,o,s,0,0,Sr.width,Sr.height),c.setTransform(1,0,0,1,0,0)):c.drawImage(t,0,0,o,s,0,0,Sr.width,Sr.height),(!Er||Sr.width!==Er.width||Sr.height!==Er.height)&&(Er=hu(Sr.width,Sr.height)),e.filter.enabled&&Fe.webgl.supported?(pn||(pn=Fe.browser?new d$:null),Fe.filter=!!pn,pn!=null&&pn.add?(pn.reset(),e.filter.brightness!==0&&pn.add("brightness",e.filter.brightness),e.filter.contrast!==0&&pn.add("contrast",e.filter.contrast),e.filter.sharpness!==0&&pn.add("sharpen",e.filter.sharpness),e.filter.blur!==0&&pn.add("blur",e.filter.blur),e.filter.saturation!==0&&pn.add("saturation",e.filter.saturation),e.filter.hue!==0&&pn.add("hue",e.filter.hue),e.filter.negative&&pn.add("negative"),e.filter.sepia&&pn.add("sepia"),e.filter.vintage&&pn.add("brownie"),e.filter.sepia&&pn.add("sepia"),e.filter.kodachrome&&pn.add("kodachrome"),e.filter.technicolor&&pn.add("technicolor"),e.filter.polaroid&&pn.add("polaroid"),e.filter.pixelate!==0&&pn.add("pixelate",e.filter.pixelate),((i=pn.get())==null?void 0:i.length)>1?Er=pn.apply(Sr):Er=pn.draw(Sr)):(e.debug&&fe("input process error: cannot initialize filters"),Fe.webgl.supported=!1,e.filter.enabled=!1,b0(Sr,Er))):(b0(Sr,Er),pn&&(pn=null),Fe.filter=!!pn),!n)return{tensor:null,canvas:Er};if(!Er)throw new Error("canvas error: cannot create output");let p,d=3;if(typeof ImageData<"u"&&t instanceof ImageData||t.data&&t.width&&t.height)if(Fe.browser&&bt.browser)p=bt.browser?bt.browser.fromPixels(t):null;else{d=t.data.length/t.height/t.width;let m=new Uint8Array(t.data.buffer);p=bt.tensor(m,[t.height,t.width,d],"int32")}else if((!Yc||Er.width!==Yc.width||Er.height!==Yc.height)&&(Yc=hu(Er.width,Er.height)),bt.browser&&Fe.browser)e.backend==="webgl"||e.backend==="humangl"||e.backend==="webgpu"?p=bt.browser.fromPixels(Er):(Yc=b0(Er),p=bt.browser.fromPixels(Yc));else{let m=b0(Er).getContext("2d").getImageData(0,0,u,l);d=m.data.length/u/l;let v=new Uint8Array(m.data.buffer);p=bt.tensor(v,[u,l,d])}if(d===4){let m=bt.slice3d(p,[0,0,0],[-1,-1,3]);bt.dispose(p),p=m}if(!p)throw new Error("input error: cannot create tensor");let f=bt.cast(p,"float32"),h=e.filter.equalization?await J9(f):bt.expandDims(f,0);if(bt.dispose([p,f]),e.filter.autoBrightness){let m=bt.max(h),v=await m.data();e.filter.brightness=v[0]>1?1-v[0]/255:1-v[0],bt.dispose(m)}return{tensor:h,canvas:e.filter.return?Er:null}}async function f$(t,e){let n=!1;if(t.cacheSensitivity===0||!e.shape||e.shape.length!==4||e.shape[1]>3840||e.shape[2]>2160)return n;if(!di.inputTensor)di.inputTensor=bt.clone(e);else if(di.inputTensor.shape[1]!==e.shape[1]||di.inputTensor.shape[2]!==e.shape[2])bt.dispose(di.inputTensor),di.inputTensor=bt.clone(e);else{let r={};r.diff=bt.sub(e,di.inputTensor),r.squared=bt.mul(r.diff,r.diff),r.sum=bt.sum(r.squared);let a=(await r.sum.data())[0]/(e.shape[1]||1)/(e.shape[2]||1)/255/3;bt.dispose([di.inputTensor,r.diff,r.squared,r.sum]),di.inputTensor=bt.clone(e),n=a<=(t.cacheSensitivity||0)}return n}async function h$(t,e,n){let r={};if(!e||!n||e.shape.length!==4||e.shape.length!==n.shape.length)return t.debug||fe("invalid input tensor or tensor shapes do not match:",e.shape,n.shape),0;if(e.shape[0]!==1||n.shape[0]!==1||e.shape[3]!==3||n.shape[3]!==3)return t.debug||fe("input tensors must be of shape [1, height, width, 3]:",e.shape,n.shape),0;r.input1=bt.clone(e),r.input2=e.shape[1]!==n.shape[1]||e.shape[2]!==n.shape[2]?bt.image.resizeBilinear(n,[e.shape[1],e.shape[2]]):bt.clone(n),r.diff=bt.sub(r.input1,r.input2),r.squared=bt.mul(r.diff,r.diff),r.sum=bt.sum(r.squared);let a=(await r.sum.data())[0]/(e.shape[1]||1)/(e.shape[2]||1)/255/3;return bt.dispose([r.input1,r.input2,r.diff,r.squared,r.sum]),a}var M0,B0,z0,Q9=class{constructor(){if(He(this,"browser"),He(this,"node"),He(this,"worker"),He(this,"platform",""),He(this,"agent",""),He(this,"backends",[]),He(this,"initial"),He(this,"filter"),He(this,"tfjs"),He(this,"offscreen"),He(this,"perfadd",!1),He(this,"tensorflow",{version:void 0,gpu:void 0}),He(this,"wasm",{supported:void 0,backend:void 0,simd:void 0,multithread:void 0}),He(this,"webgl",{supported:void 0,backend:void 0,version:void 0,renderer:void 0,shader:void 0,vendor:void 0}),He(this,"webgpu",{supported:void 0,backend:void 0,adapter:void 0}),He(this,"cpu",{model:void 0,flags:[]}),He(this,"kernels",[]),cu(this,M0),cu(this,B0),cu(this,z0),this.browser=typeof navigator<"u"&&typeof navigator.appVersion<"u",this.node=typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u",this.tfjs={version:Zo.version["tfjs-core"]},this.offscreen=typeof OffscreenCanvas<"u",this.initial=!0,this.worker=this.browser&&this.offscreen?typeof WorkerGlobalScope<"u":void 0,typeof navigator<"u"&&typeof navigator.userAgent<"u"){let t=navigator.userAgent||"",e=t.match(/\(([^()]+)\)/g);if(e!=null&&e[0]){let n=e[0].match(/\(([^()]+)\)/g);this.platform=n!=null&&n[0]?n[0].replace(/\(|\)/g,""):"",this.agent=t.replace(e[0],""),this.platform[1]&&(this.agent=this.agent.replace(e[1],"")),this.agent=this.agent.replace(/ /g," ")}}else typeof process<"u"&&(this.platform=`${process.platform} ${process.arch}`,this.agent=`NodeJS ${process.version}`)}get Canvas(){return Fi(this,M0)}set Canvas(t){El(this,M0,t),globalThis.Canvas=t}get Image(){return Fi(this,B0)}set Image(t){El(this,B0,t),globalThis.Image=t}get ImageData(){return Fi(this,z0)}set ImageData(t){El(this,z0,t),globalThis.ImageData=t}async updateBackend(){this.backends=Object.keys(Zo.engine().registryFactory);try{this.tensorflow={version:Zo.backend().binding?Zo.backend().binding.TF_Version:void 0,gpu:Zo.backend().binding?Zo.backend().binding.isUsingGpuDevice():void 0}}catch{}this.wasm.supported=typeof WebAssembly<"u",this.wasm.backend=this.backends.includes("wasm"),this.wasm.supported&&this.wasm.backend&&(this.wasm.simd=await Zo.env().getAsync("WASM_HAS_SIMD_SUPPORT"),this.wasm.multithread=await Zo.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"));let t=hu(100,100),e=t?t.getContext("webgl2"):void 0;this.webgl.supported=typeof e<"u",this.webgl.backend=this.backends.includes("webgl"),this.webgl.supported&&this.webgl.backend&&e&&(this.webgl.version=e.getParameter(e.VERSION),this.webgl.vendor=e.getParameter(e.VENDOR),this.webgl.renderer=e.getParameter(e.RENDERER),this.webgl.shader=e.getParameter(e.SHADING_LANGUAGE_VERSION)),this.webgpu.supported=this.browser&&typeof navigator<"u"&&typeof navigator.gpu<"u",this.webgpu.backend=this.backends.includes("webgpu");try{if(this.webgpu.supported){let n=await navigator.gpu.requestAdapter();n&&("requestAdapterInfo"in n?this.webgpu.adapter=await n.requestAdapterInfo():this.webgpu.adapter=await n.info)}}catch{this.webgpu.supported=!1}try{this.kernels=Zo.getKernelsForBackend(Zo.getBackend()).map(n=>n.kernelName.toLowerCase())}catch{}}updateCPU(){let t={model:"",flags:[]};this.node&&this.platform.startsWith("linux"),this.cpu?this.cpu=t:Object.defineProperty(this,"cpu",{value:t})}};M0=new WeakMap,B0=new WeakMap,z0=new WeakMap;var Fe=new Q9,m$=class{constructor(){He(this,"config"),He(this,"element"),He(this,"stream"),He(this,"devices",[]),He(this,"enumerate",async()=>{try{let t=await navigator.mediaDevices.enumerateDevices();this.devices=t.filter(e=>e.kind==="videoinput")}catch{this.devices=[]}return this.devices}),He(this,"start",async t=>{var e,n;if(t!=null&&t.debug&&(this.config.debug=t==null?void 0:t.debug),t!=null&&t.crop&&(this.config.crop=t==null?void 0:t.crop),t!=null&&t.mode&&(this.config.mode=t==null?void 0:t.mode),t!=null&&t.width&&(this.config.width=t==null?void 0:t.width),t!=null&&t.height&&(this.config.height=t==null?void 0:t.height),t!=null&&t.id&&(this.config.id=t==null?void 0:t.id),t!=null&&t.element)if(typeof t.element=="string"){let a=document.getElementById(t.element);if(a&&a instanceof HTMLVideoElement)this.element=a;else return this.config.debug&&fe("webcam","cannot get dom element",t.element),`webcam error: cannot get dom element: ${t.element}`}else if(t.element instanceof HTMLVideoElement)this.element=t.element;else return this.config.debug&&fe("webcam","unknown dom element",t.element),`webcam error: unknown dom element: ${t.element}`;else this.element=document.createElement("video");let r={audio:!1,video:{facingMode:this.config.mode==="front"?"user":"environment",resizeMode:this.config.crop?"crop-and-scale":"none"}};if(((e=this.config)==null?void 0:e.width)>0&&(r.video.width={ideal:this.config.width}),((n=this.config)==null?void 0:n.height)>0&&(r.video.height={ideal:this.config.height}),this.config.id&&(r.video.deviceId=this.config.id),this.element.addEventListener("play",()=>{this.config.debug&&fe("webcam","play")}),this.element.addEventListener("pause",()=>{this.config.debug&&fe("webcam","pause")}),this.element.addEventListener("click",async()=>{!this.element||!this.stream||(this.element.paused?await this.element.play():this.element.pause())}),!(navigator!=null&&navigator.mediaDevices))return this.config.debug&&fe("webcam error","no devices"),"webcam error: no devices";try{this.stream=await navigator.mediaDevices.getUserMedia(r)}catch(a){return fe("webcam",a),`webcam error: ${a}`}return this.stream?(this.element.srcObject=this.stream,await new Promise(a=>{this.element?this.element.onloadeddata=()=>a(!0):a(!1)}),await this.element.play(),this.config.debug&&fe("webcam",{width:this.width,height:this.height,label:this.label,stream:this.stream,track:this.track,settings:this.settings,constraints:this.constraints,capabilities:this.capabilities}),`webcam: ${this.label}`):(this.config.debug&&fe("webcam error","no stream"),"webcam error no stream")}),He(this,"pause",()=>{this.element&&this.element.pause()}),He(this,"play",async()=>{this.element&&await this.element.play()}),He(this,"stop",()=>{this.config.debug&&fe("webcam","stop"),this.track&&this.track.stop()}),this.config={element:void 0,debug:!0,mode:"front",crop:!1,width:0,height:0}}get track(){if(this.stream)return this.stream.getVideoTracks()[0]}get capabilities(){if(this.track)return this.track.getCapabilities?this.track.getCapabilities():void 0}get constraints(){if(this.track)return this.track.getConstraints?this.track.getConstraints():void 0}get settings(){if(!this.stream)return;let t=this.stream.getVideoTracks()[0];return t.getSettings?t.getSettings():void 0}get label(){return this.track?this.track.label:""}get paused(){var t;return((t=this.element)==null?void 0:t.paused)||!1}get width(){var t;return((t=this.element)==null?void 0:t.videoWidth)||0}get height(){var t;return((t=this.element)==null?void 0:t.videoHeight)||0}},tg=wt(kt()),eA={};yu(eA,{"affectnet-mobilenet":()=>fA,age:()=>hA,"anti-spoofing":()=>qA,antispoof:()=>tA,blazeface:()=>nA,"blazeface-back":()=>mA,"blazeface-front":()=>vA,"blazepose-detector":()=>gA,"blazepose-full":()=>yA,"blazepose-heavy":()=>xA,"blazepose-lite":()=>AA,centernet:()=>rA,default:()=>v$,efficientpose:()=>bA,"efficientpose-i-lite":()=>jA,"efficientpose-ii-lite":()=>KA,"efficientpose-iv":()=>XA,emotion:()=>aA,faceboxes:()=>wA,facemesh:()=>iA,"facemesh-attention":()=>SA,"facemesh-attention-pinto":()=>kA,"facemesh-detection-full":()=>EA,"facemesh-detection-short":()=>TA,faceres:()=>oA,"faceres-deep":()=>NA,gear:()=>DA,"gear-e1":()=>CA,"gear-e2":()=>IA,gender:()=>_A,"gender-ssrnet-imdb":()=>FA,handdetect:()=>RA,"handlandmark-full":()=>PA,"handlandmark-lite":()=>sA,"handlandmark-sparse":()=>OA,handskeleton:()=>MA,handtrack:()=>uA,"insightface-efficientnet-b0":()=>ZA,"insightface-ghostnet-strides1":()=>YA,"insightface-ghostnet-strides2":()=>JA,"insightface-mobilenet-emore":()=>QA,"insightface-mobilenet-swish":()=>eb,iris:()=>lA,liveness:()=>cA,meet:()=>BA,mobileface:()=>zA,mobilefacenet:()=>LA,models:()=>pA,"movenet-lightning":()=>dA,"movenet-multipose":()=>VA,"movenet-thunder":()=>WA,nanodet:()=>UA,"nanodet-e":()=>tb,"nanodet-g":()=>nb,"nanodet-m":()=>rb,"nanodet-t":()=>ab,posenet:()=>$A,rvm:()=>GA,selfie:()=>HA});var tA=853098,nA=538928,rA=4030290,aA=820516,iA=1477958,oA=6978814,sA=2023432,uA=2964837,lA=2599092,cA=592976,pA=0,dA=4650216,fA=6920630,hA=161240,mA=538928,vA=402048,gA=5928856,yA=6339202,xA=27502466,AA=2726402,bA=5651240,wA=2013002,kA=2387598,SA=2382414,EA=1026192,TA=201268,NA=13957620,CA=112438,IA=112438,DA=1498916,FA=161236,_A=201808,RA=3515612,PA=5431368,OA=5286322,MA=5502280,BA=372228,zA=2183192,LA=5171976,VA=9448838,WA=12477112,UA=7574558,$A=5032780,GA=3739355,HA=212886,qA=853098,jA=2269064,KA=5651240,XA=25643252,ZA=13013224,YA=8093408,JA=8049584,QA=6938536,eb=12168584,tb=12319156,nb=7574558,rb=1887474,ab=5294216,v$={antispoof:tA,blazeface:nA,centernet:rA,emotion:aA,facemesh:iA,faceres:oA,"handlandmark-lite":sA,handtrack:uA,iris:lA,liveness:cA,models:pA,"movenet-lightning":dA,"affectnet-mobilenet":fA,age:hA,"blazeface-back":mA,"blazeface-front":vA,"blazepose-detector":gA,"blazepose-full":yA,"blazepose-heavy":xA,"blazepose-lite":AA,efficientpose:bA,faceboxes:wA,"facemesh-attention-pinto":kA,"facemesh-attention":SA,"facemesh-detection-full":EA,"facemesh-detection-short":TA,"faceres-deep":NA,"gear-e1":CA,"gear-e2":IA,gear:DA,"gender-ssrnet-imdb":FA,gender:_A,handdetect:RA,"handlandmark-full":PA,"handlandmark-sparse":OA,handskeleton:MA,meet:BA,mobileface:zA,mobilefacenet:LA,"movenet-multipose":VA,"movenet-thunder":WA,nanodet:UA,posenet:$A,rvm:GA,selfie:HA,"anti-spoofing":qA,"efficientpose-i-lite":jA,"efficientpose-ii-lite":KA,"efficientpose-iv":XA,"insightface-efficientnet-b0":ZA,"insightface-ghostnet-strides1":YA,"insightface-ghostnet-strides2":JA,"insightface-mobilenet-emore":QA,"insightface-mobilenet-swish":eb,"nanodet-e":tb,"nanodet-g":nb,"nanodet-m":rb,"nanodet-t":ab},sa={cacheModels:!0,cacheSupported:!0,verbose:!0,debug:!1,modelBasePath:""},Nr={};async function g$(t,e){return sa.debug&&fe("load model fetch:",t,e),fetch(t,e)}function y$(t){sa.cacheModels=t.cacheModels,sa.verbose=t.debug,sa.modelBasePath=t.modelBasePath}async function an(t){var e,n,r,a,i,o;let s=a$(sa.modelBasePath,t||"");s.toLowerCase().endsWith(".json")||(s+=".json");let u=s.includes("/")?s.split("/"):s.split("\\"),l=u[u.length-1].replace(".json",""),c="indexeddb://"+l;Nr[l]={name:l,loaded:!1,sizeFromManifest:0,sizeLoadedWeights:0,sizeDesired:eA[l],inCache:!1,url:""},sa.cacheSupported=typeof indexedDB<"u";let p={};try{p=sa.cacheSupported&&sa.cacheModels?await tg.io.listModels():{}}catch{sa.cacheSupported=!1}Nr[l].inCache=sa.cacheSupported&&sa.cacheModels&&Object.keys(p).includes(c),Nr[l].url=Nr[l].inCache?c:s;let d=typeof fetch>"u"?{}:{fetchFunc:(h,m)=>g$(h,m)},f=new tg.GraphModel(Nr[l].url,d);Nr[l].loaded=!1;try{f.findIOHandler(),sa.debug&&fe("model load handler:",f.handler)}catch(h){fe("error finding model i/o handler:",s,h)}try{let h=await((e=f.handler)==null?void 0:e.load())||null;Nr[l].sizeFromManifest=((n=h==null?void 0:h.weightData)==null?void 0:n.byteLength)||0,h?f.loadSync(h):f=await tg.loadGraphModel(Nr[l].inCache?c:s,d),Nr[l].sizeLoadedWeights=((a=(r=f.artifacts)==null?void 0:r.weightData)==null?void 0:a.byteLength)||((o=(i=f.artifacts)==null?void 0:i.weightData)==null?void 0:o[0].byteLength)||0,sa.verbose&&fe("load:",{model:l,url:f.modelUrl,bytes:Nr[l].sizeLoadedWeights}),Nr[l].loaded=!0}catch(h){fe("error loading model:",s,h)}if(Nr[l].loaded&&sa.cacheModels&&sa.cacheSupported&&!Nr[l].inCache)try{let h=await f.save(c);sa.debug&&fe("model saved:",c,h)}catch(h){fe("error saving model:",s,h)}return f}var bx="3.3.5",ft=wt(kt()),ho=wt(kt()),Pn={name:"humangl",priority:999,canvas:null,gl:null,extensions:[],webGLattr:{alpha:!1,antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,depth:!1,stencil:!1,failIfMajorPerformanceCaveat:!1,desynchronized:!0}};function x$(){let t=Pn.gl;t&&(Pn.extensions=t.getSupportedExtensions())}function A$(t){var e;if(t.config.backend==="humangl"&&(Pn.name in ho.engine().registry&&!((e=Pn==null?void 0:Pn.gl)!=null&&e.getParameter(Pn.gl.VERSION))&&(fe("humangl error: backend invalid context"),t.models.reset()),!ho.findBackend(Pn.name))){try{Pn.canvas=hu(100,100)}catch(a){fe("humangl error: cannot create canvas:",a);return}try{if(Pn.gl=Pn.canvas.getContext("webgl2",Pn.webGLattr),!Pn.gl){fe("humangl error: cannot get webgl context");return}if(!Pn.gl.getParameter(Pn.gl.VERSION).includes("2.0")){fe("backend override: using fallback webgl backend as webgl 2.0 is not detected"),t.config.backend="webgl";return}Pn.canvas&&(Pn.canvas.addEventListener("webglcontextlost",a=>{throw fe("humangl error:",a.type),fe("possible browser memory leak using webgl or conflict with multiple backend registrations"),t.emit("error"),new Error("backend error: webgl context lost")}),Pn.canvas.addEventListener("webglcontextrestored",a=>{fe("humangl error: context restored:",a)}),Pn.canvas.addEventListener("webglcontextcreationerror",a=>{fe("humangl error: context create:",a)}))}catch(a){fe("humangl error: cannot get webgl context:",a);return}try{ho.setWebGLContext(2,Pn.gl)}catch(a){fe("humangl error: cannot set webgl context:",a);return}try{let a=new ho.GPGPUContext(Pn.gl);ho.registerBackend(Pn.name,()=>new ho.MathBackendWebGL(a),Pn.priority)}catch(a){fe("humangl error: cannot register webgl backend:",a);return}try{ho.getKernelsForBackend("webgl").forEach(a=>{let i={...a,backendName:Pn.name};ho.registerKernel(i)})}catch(a){fe("humangl error: cannot update webgl backend registration:",a);return}try{ho.env().flagRegistry.WEBGL_VERSION&&ho.env().set("WEBGL_VERSION",2)}catch(a){fe("humangl error: cannot set WebGL backend flags:",a);return}x$();let n=ho.backend(),r=typeof n.gpgpu<"u"?n.getGPGPUContext().gl:null;r?t.config.debug&&fe("humangl backend registered:",{webgl:r.getParameter(r.VERSION),renderer:r.getParameter(r.RENDERER)}):fe("humangl error: no current gl context:",r,Pn.gl)}}var Jc=wt(kt()),Vt={tf255:255,tf1:1,tf2:2,tf05:.5,tf127:127.5,rgb:[.2989,.587,.114]};function b$(){Vt.tf255=Jc.scalar(255,"float32"),Vt.tf1=Jc.scalar(1,"float32"),Vt.tf2=Jc.scalar(2,"float32"),Vt.tf05=Jc.scalar(.5,"float32"),Vt.tf127=Jc.scalar(127.5,"float32"),Vt.rgb=Jc.tensor1d([.2989,.587,.114],"float32")}async function w$(){var t;return await Fe.updateBackend(),(t=Fe.tensorflow)!=null&&t.version?"tensorflow":Fe.webgpu.supported&&Fe.webgpu.backend?"webgpu":Fe.webgl.supported&&Fe.webgl.backend?"webgl":Fe.wasm.supported&&Fe.wasm.backend?"wasm":"cpu"}function k$(t){let e=[];if(!Fe.kernels.includes("mod")){let n={kernelName:"Mod",backendName:ft.getBackend(),kernelFunc:r=>ft.tidy(()=>ft.sub(r.inputs.a,ft.mul(ft.div(r.inputs.a,r.inputs.b),r.inputs.b)))};ft.registerKernel(n),Fe.kernels.push("mod"),e.push("mod")}if(!Fe.kernels.includes("floormod")){let n={kernelName:"FloorMod",backendName:ft.getBackend(),kernelFunc:r=>ft.tidy(()=>ft.add(ft.mul(ft.floorDiv(r.inputs.a,r.inputs.b),r.inputs.b),ft.mod(r.inputs.a,r.inputs.b)))};ft.registerKernel(n),Fe.kernels.push("floormod"),e.push("floormod")}if(!Fe.kernels.includes("rotatewithoffset")&&t.softwareKernels){let n={kernelName:"RotateWithOffset",backendName:ft.getBackend(),kernelFunc:r=>ft.tidy(()=>{let a=ft.getBackend();ft.setBackend("cpu");let i=ft.image.rotateWithOffset(r.inputs.image,r.attrs.radians,r.attrs.fillValue,r.attrs.center);return ft.setBackend(a),i})};ft.registerKernel(n),Fe.kernels.push("rotatewithoffset"),e.push("rotatewithoffset")}e.length>0&&t.debug&&fe("registered kernels:",e)}var wx={};async function _g(t,e=!1){var n,r;if(t.state="backend",((n=t.config.backend)==null?void 0:n.length)===0&&(t.config.backend=await w$()),e||Fe.initial||t.config.backend&&t.config.backend.length>0&&ft.getBackend()!==t.config.backend){let a=Ee();if(t.config.backend&&t.config.backend.length>0){typeof window>"u"&&typeof WorkerGlobalScope<"u"&&t.config.debug&&t.config.debug&&fe("running inside web worker"),typeof navigator<"u"&&(r=navigator==null?void 0:navigator.userAgent)!=null&&r.toLowerCase().includes("electron")&&t.config.debug&&fe("running inside electron");let i=Object.keys(ft.engine().registryFactory);if(t.config.backend==="humangl"&&!i.includes("humangl")&&(A$(t),i=Object.keys(ft.engine().registryFactory)),t.config.debug&&fe("available backends:",i),Fe.browser&&!Fe.node&&t.config.backend==="tensorflow"&&i.includes("webgl")&&(t.config.debug&&fe("override: backend set to tensorflow while running in browser"),t.config.backend="webgl"),Fe.node&&!Fe.browser&&(t.config.backend==="webgl"||t.config.backend==="humangl")&&i.includes("tensorflow")&&(t.config.debug&&fe(`override: backend set to ${t.config.backend} while running in nodejs`),t.config.backend="tensorflow"),Fe.browser&&t.config.backend==="webgpu")if(typeof navigator>"u"||typeof navigator.gpu>"u")fe("override: backend set to webgpu but browser does not support webgpu"),t.config.backend="webgl";else{let o=await navigator.gpu.requestAdapter();if(t.config.debug&&fe("enumerated webgpu adapter:",o),!o)fe("override: backend set to webgpu but browser reports no available gpu"),t.config.backend="webgl";else{let s;"requestAdapterInfo"in o?s=await(o==null?void 0:o.requestAdapterInfo()):s=o.info,fe("webgpu adapter info:",s)}}if(i.includes(t.config.backend)||(fe(`error: backend ${t.config.backend} not found in registry`),t.config.backend=Fe.node?"tensorflow":"webgl",t.config.debug&&fe(`override: setting backend ${t.config.backend}`)),t.config.debug&&fe("setting backend:",[t.config.backend]),t.config.backend==="wasm"){if(ft.env().flagRegistry.CANVAS2D_WILL_READ_FREQUENTLY&&ft.env().set("CANVAS2D_WILL_READ_FREQUENTLY",!0),t.config.debug&&fe("wasm path:",t.config.wasmPath),typeof ft.setWasmPaths<"u")ft.setWasmPaths(t.config.wasmPath,t.config.wasmPlatformFetch);else throw new Error("backend error: attempting to use wasm backend but wasm path is not set");let o=!1,s=!1;try{o=await ft.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"),s=await ft.env().getAsync("WASM_HAS_SIMD_SUPPORT"),t.config.debug&&fe(`wasm execution: ${s?"simd":"no simd"} ${o?"multithreaded":"singlethreaded"}`),t.config.debug&&!s&&fe("warning: wasm simd support is not enabled")}catch{fe("wasm detection failed")}}try{await ft.setBackend(t.config.backend),await ft.ready()}catch(o){return fe("error: cannot set backend:",t.config.backend,o),!1}t.config.debug&&(wx=JSON.parse(JSON.stringify(ft.env().flags)))}if((ft.getBackend()==="humangl"||ft.getBackend()==="webgl")&&(ft.env().flagRegistry.WEBGL_USE_SHAPES_UNIFORMS&&ft.env().set("WEBGL_USE_SHAPES_UNIFORMS",!0),ft.env().flagRegistry.WEBGL_EXP_CONV&&ft.env().set("WEBGL_EXP_CONV",!0),t.config.debug&&typeof t.config.deallocate<"u"&&t.config.deallocate&&(fe("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",!0),ft.env().set("WEBGL_DELETE_TEXTURE_THRESHOLD",0))),ft.getBackend(),t.config.debug){let i=ft.env().flags,o={};for(let s of Object.keys(i))wx[s]!==i[s]&&(o[s]=i[s]);t.config.debug&&Object.keys(o).length>0&&fe("backend:",ft.getBackend(),"flags:",o)}if(t.config.flags&&Object.keys(t.config.flags).length>0){t.config.debug&&fe("flags:",t.config.flags);for(let[i,o]of Object.entries(t.config.flags))ft.env().set(i,o)}ft.enableProdMode(),b$(),t.performance.initBackend=Math.trunc(Ee()-a),t.config.backend=ft.getBackend(),await Fe.updateBackend(),k$(t.config)}return!0}function ib(t,e){for(let n of t){let r={kernelName:n,backendName:e.backend,kernelFunc:a=>{var i;return e.debug&&fe("kernelFunc",n,e.backend,a),(i=a==null?void 0:a.inputs)==null?void 0:i.info}};ft.registerKernel(r)}Fe.kernels=ft.getKernelsForBackend(ft.getBackend()).map(n=>n.kernelName.toLowerCase())}var $g={};yu($g,{all:()=>rG,body:()=>ub,canvas:()=>tG,face:()=>sb,gesture:()=>pb,hand:()=>lb,init:()=>db,object:()=>cb,options:()=>Na,person:()=>eG,tensor:()=>nG});var S$=wt(kt()),Fl=t=>{if(!t)fe("draw error: invalid canvas");else if(!t.getContext)fe("draw error: canvas context not defined");else{let e=t.getContext("2d",{willReadFrequently:!0});if(!e)fe("draw error: cannot get canvas context");else return e}return null},ap=t=>Math.round(t*180/Math.PI),rn=(t,e,n)=>t.replace(e,typeof n=="number"?n.toFixed(1):n),jd=(t,e)=>{if(!e.useDepth||typeof t>"u")return e.color;let n=Uint8ClampedArray.from([127+2*t,127-2*t,255]);return`rgba(${n[0]}, ${n[1]}, ${n[2]}, ${e.alpha})`};function gu(t,e,n,r,a){let i=e.replace(/\[.*\]/g,"").split(`
`).map(s=>s.trim()),o=Math.max(0,n);for(let s=i.length-1;s>=0;s--){let u=s*a.lineHeight+r;a.shadowColor&&a.shadowColor!==""&&(t.fillStyle=a.shadowColor,t.fillText(i[s],o+5,u+16)),t.fillStyle=a.labelColor,t.fillText(i[s],o+4,u+15)}}function bl(t,e,n,r,a){t.fillStyle=jd(r,a),t.beginPath(),t.arc(e,n,a.pointSize,0,2*Math.PI),t.fill()}function Xd(t,e,n,r,a,i){if(t.beginPath(),t.lineWidth=i.lineWidth,i.useCurves){let o=(e+e+r)/2,s=(n+n+a)/2;t.ellipse(o,s,r/2,a/2,0,0,2*Math.PI)}else t.moveTo(e+i.roundRect,n),t.lineTo(e+r-i.roundRect,n),t.quadraticCurveTo(e+r,n,e+r,n+i.roundRect),t.lineTo(e+r,n+a-i.roundRect),t.quadraticCurveTo(e+r,n+a,e+r-i.roundRect,n+a),t.lineTo(e+i.roundRect,n+a),t.quadraticCurveTo(e,n+a,e,n+a-i.roundRect),t.lineTo(e,n+i.roundRect),t.quadraticCurveTo(e,n,e+i.roundRect,n),t.closePath();t.stroke()}function ob(t,e,n){if(!(e.length<2)){t.beginPath(),t.moveTo(e[0][0],e[0][1]);for(let r of e)t.strokeStyle=jd(r[2]||0,n),t.lineTo(Math.trunc(r[0]),Math.trunc(r[1]));t.stroke(),n.fillPolygons&&(t.closePath(),t.fill())}}function E$(t,e,n){if(!(e.length<2)){if(t.lineWidth=n.lineWidth,!n.useCurves||e.length<=2){ob(t,e,n);return}t.moveTo(e[0][0],e[0][1]);for(let r=0;r<e.length-2;r++){let a=(e[r][0]+e[r+1][0])/2,i=(e[r][1]+e[r+1][1])/2;t.quadraticCurveTo(e[r][0],e[r][1],a,i)}t.quadraticCurveTo(e[e.length-2][0],e[e.length-2][1],e[e.length-1][0],e[e.length-1][1]),t.stroke(),n.fillPolygons&&(t.closePath(),t.fill())}}function kx(t,e,n,r=5){let a,i,o;t.beginPath(),t.moveTo(e[0],e[1]),t.lineTo(n[0],n[1]),a=Math.atan2(n[1]-e[1],n[0]-e[0]),i=r*Math.cos(a)+n[0],o=r*Math.sin(a)+n[1],t.moveTo(i,o),a+=1/3*(2*Math.PI),i=r*Math.cos(a)+n[0],o=r*Math.sin(a)+n[1],t.lineTo(i,o),a+=1/3*(2*Math.PI),i=r*Math.cos(a)+n[0],o=r*Math.sin(a)+n[1],t.lineTo(i,o),t.closePath(),t.stroke(),t.fill()}var Na={color:"rgba(173, 216, 230, 0.6)",labelColor:"rgba(173, 216, 230, 1)",shadowColor:"black",alpha:.5,font:'small-caps 16px "Segoe UI"',lineHeight:18,lineWidth:4,pointSize:2,roundRect:8,drawPoints:!1,drawLabels:!0,drawBoxes:!0,drawAttention:!0,drawGestures:!0,drawPolygons:!0,drawGaze:!0,fillPolygons:!1,useDepth:!0,useCurves:!1,faceLabels:"",bodyLabels:"",bodyPartLabels:"",objectLabels:"",handLabels:"",fingerLabels:"",gestureLabels:""},Cs={silhouette:[10,338,297,332,284,251,389,356,454,323,361,288,397,365,379,378,400,377,152,148,176,149,150,136,172,58,132,93,234,127,162,21,54,103,67,109],lipsUpperOuter:[185,40,39,37,0,267,269,270,409],lipsLowerOuter:[61,146,91,181,84,17,314,405,321,375,291],lipsUpperInner:[191,80,81,82,13,312,311,310,415],lipsLowerInner:[78,95,88,178,87,14,317,402,318,324,308],lipsLowerSemiOuter:[76,77,90,180,85,16,315,404,320,307,306],lipsUpperSemiOuter:[184,74,73,72,11,302,303,304,408],lipsLowerSemiInner:[62,96,89,179,86,15,316,403,319,325,292],lipsUpperSemiInner:[183,42,41,38,12,268,271,272,407],rightEyeUpper0:[246,161,160,159,158,157,173],rightEyeLower0:[33,7,163,144,145,153,154,155,133],rightEyeUpper1:[247,30,29,27,28,56,190],rightEyeLower1:[130,25,110,24,23,22,26,112,243],rightEyeUpper2:[113,225,224,223,222,221,189],rightEyeLower2:[226,31,228,229,230,231,232,233,244],rightEyeLower3:[143,111,117,118,119,120,121,128,245],rightEyebrowUpper:[156,70,63,105,66,107,55,193],rightEyebrowLower:[35,124,46,53,52,65],rightEyeIris:[473,474,475,476,477],leftEyeUpper0:[466,388,387,386,385,384,398],leftEyeLower0:[263,249,390,373,374,380,381,382,362],leftEyeUpper1:[467,260,259,257,258,286,414],leftEyeLower1:[359,255,339,254,253,252,256,341,463],leftEyeUpper2:[342,445,444,443,442,441,413],leftEyeLower2:[446,261,448,449,450,451,452,453,464],leftEyeLower3:[372,340,346,347,348,349,350,357,465],leftEyebrowUpper:[383,300,293,334,296,336,285,417],leftEyebrowLower:[265,353,276,283,282,295],leftEyeIris:[468,469,470,471,472],midwayBetweenEyes:[168],nose