diff --git "a/face-canvas.js" "b/face-canvas.js" --- "a/face-canvas.js" +++ "b/face-canvas.js" @@ -16,12 +16,4 @@ gl_FragColor = texture2D(sampler0, vTex); }`,1),l=n.createProgram();if(n.attachShader(l,r),n.attachShader(l,o),n.linkProgram(l),!n.getProgramParameter(l,n.LINK_STATUS))throw Error(`Could not compile WebGL program. -`+n.getProgramInfoLog(l));r=t.m=l,n.useProgram(r),o=n.getUniformLocation(r,"sampler0"),t.j={I:n.getAttribLocation(r,"aVertex"),H:n.getAttribLocation(r,"aTex"),da:o},t.s=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,t.s),n.enableVertexAttribArray(t.j.I),n.vertexAttribPointer(t.j.I,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,1,1,-1]),n.STATIC_DRAW),n.bindBuffer(n.ARRAY_BUFFER,null),t.o=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,t.o),n.enableVertexAttribArray(t.j.H),n.vertexAttribPointer(t.j.H,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,1,0,0,1,0,1,1]),n.STATIC_DRAW),n.bindBuffer(n.ARRAY_BUFFER,null),n.uniform1i(o,0)}r=t.j,n.useProgram(t.m),n.canvas.width=e.width,n.canvas.height=e.height,n.viewport(0,0,e.width,e.height),n.activeTexture(n.TEXTURE0),t.h.bindTexture2d(e.glName),n.enableVertexAttribArray(r.I),n.bindBuffer(n.ARRAY_BUFFER,t.s),n.vertexAttribPointer(r.I,2,n.FLOAT,!1,0,0),n.enableVertexAttribArray(r.H),n.bindBuffer(n.ARRAY_BUFFER,t.o),n.vertexAttribPointer(r.H,2,n.FLOAT,!1,0,0),n.bindFramebuffer(n.DRAW_FRAMEBUFFER?n.DRAW_FRAMEBUFFER:n.FRAMEBUFFER,null),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.colorMask(!0,!0,!0,!0),n.drawArrays(n.TRIANGLE_FAN,0,4),n.disableVertexAttribArray(r.I),n.disableVertexAttribArray(r.H),n.bindBuffer(n.ARRAY_BUFFER,null),t.h.bindTexture2d(0)}function kn(t){this.g=t}var An=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,9,1,7,0,65,0,253,15,26,11]);function On(t,e){return e+t}function He(t,e){window[t]=e}function Sn(t){var e=document.createElement("script");return e.setAttribute("src",t),e.setAttribute("crossorigin","anonymous"),new Promise(function(n){e.addEventListener("load",function(){n()},!1),e.addEventListener("error",function(){n()},!1),document.body.appendChild(e)})}function Tn(){return it(this,function t(){return H(t,function(e){switch(e.g){case 1:return e.m=2,Y(e,WebAssembly.instantiate(An),4);case 4:e.g=3,e.m=0;break;case 2:return e.m=0,e.j=null,e.return(!1);case 3:return e.return(!0)}})})}function de(t){if(this.g=t,this.listeners={},this.j={},this.F={},this.m={},this.s={},this.G=this.o=this.R=!0,this.C=Promise.resolve(),this.P="",this.B={},this.locateFile=t&&t.locateFile||On,typeof window=="object")var e=window.location.pathname.toString().substring(0,window.location.pathname.toString().lastIndexOf("/"))+"/";else if(typeof location<"u")e=location.pathname.toString().substring(0,location.pathname.toString().lastIndexOf("/"))+"/";else throw Error("solutions can only be loaded on a web page or in a web worker");if(this.S=e,t.options){e=C(Object.keys(t.options));for(var n=e.next();!n.done;n=e.next()){n=n.value;var r=t.options[n].default;r!==void 0&&(this.j[n]=typeof r=="function"?r():r)}}}i=de.prototype,i.close=function(){return this.i&&this.i.delete(),Promise.resolve()};function Rn(t,e){return t.g.files===void 0?[]:typeof t.g.files=="function"?t.g.files(e):t.g.files}function Fn(t){return it(t,function e(){var n=this,r,o,l,s,c,h,d,E,V,R,k;return H(e,function(w){switch(w.g){case 1:return r=n,n.R?(o=Rn(n,n.j),Y(w,Tn(),2)):w.return();case 2:if(l=w.h,typeof window=="object")return He("createMediapipeSolutionsWasm",{locateFile:n.locateFile}),He("createMediapipeSolutionsPackedAssets",{locateFile:n.locateFile}),h=o.filter(function(x){return x.data!==void 0}),d=o.filter(function(x){return x.data===void 0}),E=Promise.all(h.map(function(x){var T=pe(r,x.url);if(x.path!==void 0){var P=x.path;T=T.then(function(et){return r.overrideFile(P,et),Promise.resolve(et)})}return T})),V=Promise.all(d.map(function(x){return x.simd===void 0||x.simd&&l||!x.simd&&!l?Sn(r.locateFile(x.url,r.S)):Promise.resolve()})).then(function(){return it(r,function x(){var T,P,et=this;return H(x,function(W){if(W.g==1)return T=window.createMediapipeSolutionsWasm,P=window.createMediapipeSolutionsPackedAssets,Y(W,T(P),2);et.h=W.h,W.g=0})})}),R=function(){return it(r,function x(){var T=this;return H(x,function(P){return T.g.graph&&T.g.graph.url?P=Y(P,pe(T,T.g.graph.url),0):(P.g=0,P=void 0),P})})}(),Y(w,Promise.all([V,E,R]),7);if(typeof importScripts!="function")throw Error("solutions can only be loaded on a web page or in a web worker");return s=o.filter(function(x){return x.simd===void 0||x.simd&&l||!x.simd&&!l}).map(function(x){return r.locateFile(x.url,r.S)}),importScripts.apply(null,L(s)),Y(w,createMediapipeSolutionsWasm(Module),6);case 6:n.h=w.h,n.l=new OffscreenCanvas(1,1),n.h.canvas=n.l,c=n.h.GL.createContext(n.l,{antialias:!1,alpha:!1,ba:typeof WebGL2RenderingContext<"u"?2:1}),n.h.GL.makeContextCurrent(c),w.g=4;break;case 7:if(n.l=document.createElement("canvas"),k=n.l.getContext("webgl2",{}),!k&&(k=n.l.getContext("webgl",{}),!k))return alert("Failed to create WebGL canvas context when passing video frame."),w.return();n.D=k,n.h.canvas=n.l,n.h.createContext(n.l,!0,!0,{});case 4:n.i=new n.h.SolutionWasm,n.R=!1,w.g=0}})})}function Ln(t){return it(t,function e(){var n=this,r,o,l,s,c,h,d,E;return H(e,function(V){if(V.g==1){if(n.g.graph&&n.g.graph.url&&n.P===n.g.graph.url)return V.return();if(n.o=!0,!n.g.graph||!n.g.graph.url){V.g=2;return}return n.P=n.g.graph.url,Y(V,pe(n,n.g.graph.url),3)}for(V.g!=2&&(r=V.h,n.i.loadGraph(r)),o=C(Object.keys(n.B)),l=o.next();!l.done;l=o.next())s=l.value,n.i.overrideFile(s,n.B[s]);if(n.B={},n.g.listeners)for(c=C(n.g.listeners),h=c.next();!h.done;h=c.next())d=h.value,Nn(n,d);E=n.j,n.j={},n.setOptions(E),V.g=0})})}i.reset=function(){return it(this,function t(){var e=this;return H(t,function(n){e.i&&(e.i.reset(),e.m={},e.s={}),n.g=0})})},i.setOptions=function(t,e){var n=this;if(e=e||this.g.options){for(var r=[],o=[],l={},s=C(Object.keys(t)),c=s.next();!c.done;l={K:l.K,L:l.L},c=s.next()){var h=c.value;h in this.j&&this.j[h]===t[h]||(this.j[h]=t[h],c=e[h],c!==void 0&&(c.onChange&&(l.K=c.onChange,l.L=t[h],r.push(function(d){return function(){return it(n,function E(){var V,R=this;return H(E,function(k){if(k.g==1)return Y(k,d.K(d.L),2);V=k.h,V===!0&&(R.o=!0),k.g=0})})}}(l))),c.graphOptionXref&&(h={valueNumber:c.type===1?t[h]:0,valueBoolean:c.type===0?t[h]:!1,valueString:c.type===2?t[h]:""},c=Object.assign(Object.assign(Object.assign({},{calculatorName:"",calculatorIndex:0}),c.graphOptionXref),h),o.push(c))))}(r.length!==0||o.length!==0)&&(this.o=!0,this.A=(this.A===void 0?[]:this.A).concat(o),this.u=(this.u===void 0?[]:this.u).concat(r))}};function Mn(t){return it(t,function e(){var n=this,r,o,l,s,c,h,d;return H(e,function(E){switch(E.g){case 1:if(!n.o)return E.return();if(!n.u){E.g=2;break}r=C(n.u),o=r.next();case 3:if(o.done){E.g=5;break}return l=o.value,Y(E,l(),4);case 4:o=r.next(),E.g=3;break;case 5:n.u=void 0;case 2:if(n.A){for(s=new n.h.GraphOptionChangeRequestList,c=C(n.A),h=c.next();!h.done;h=c.next())d=h.value,s.push_back(d);n.i.changeOptions(s),s.delete(),n.A=void 0}n.o=!1,E.g=0}})})}i.initialize=function(){return it(this,function t(){var e=this;return H(t,function(n){return n.g==1?Y(n,Fn(e),2):n.g!=3?Y(n,Ln(e),3):Y(n,Mn(e),0)})})};function pe(t,e){return it(t,function n(){var r=this,o,l;return H(n,function(s){return e in r.F?s.return(r.F[e]):(o=r.locateFile(e,""),l=fetch(o).then(function(c){return c.arrayBuffer()}),r.F[e]=l,s.return(l))})})}i.overrideFile=function(t,e){this.i?this.i.overrideFile(t,e):this.B[t]=e},i.clearOverriddenFiles=function(){this.B={},this.i&&this.i.clearOverriddenFiles()},i.send=function(t,e){return it(this,function n(){var r=this,o,l,s,c,h,d,E,V,R;return H(n,function(k){switch(k.g){case 1:return r.g.inputs?(o=1e3*(e??performance.now()),Y(k,r.C,2)):k.return();case 2:return Y(k,r.initialize(),3);case 3:for(l=new r.h.PacketDataList,s=C(Object.keys(t)),c=s.next();!c.done;c=s.next())if(h=c.value,d=r.g.inputs[h]){t:{var w=r,x=t[h];switch(d.type){case"video":var T=w.m[d.stream];if(T||(T=new ge(w.h,w.D),w.m[d.stream]=T),w=T,w.l===0&&(w.l=w.h.createTexture()),typeof HTMLVideoElement<"u"&&x instanceof HTMLVideoElement){var P=x.videoWidth;T=x.videoHeight}else typeof HTMLImageElement<"u"&&x instanceof HTMLImageElement?(P=x.naturalWidth,T=x.naturalHeight):(P=x.width,T=x.height);T={glName:w.l,width:P,height:T},P=w.g,P.canvas.width=T.width,P.canvas.height=T.height,P.activeTexture(P.TEXTURE0),w.h.bindTexture2d(w.l),P.texImage2D(P.TEXTURE_2D,0,P.RGBA,P.RGBA,P.UNSIGNED_BYTE,x),w.h.bindTexture2d(0),w=T;break t;case"detections":for(T=w.m[d.stream],T||(T=new kn(w.h),w.m[d.stream]=T),w=T,w.data||(w.data=new w.g.DetectionListData),w.data.reset(x.length),T=0;TI,I=Math.abs(I);var B=I>>>0;for(I=Math.floor((I-B)/4294967296),I>>>=0,G&&(I=~I>>>0,B=(~B>>>0)+1,4294967295>>7|B<<25)>>>0,B>>>=7;F.push(G)}if(ce(A,N),Z=le(Z),W.call(et,ot,Z),P.O)for(et=0;etI;I++)G.push(B&127|128),B>>=7;G.push(1)}gt(F,2,X(N,2)),G=X(N,3),G!=null&&(G=J(G),jt(F.g,26),jt(F.g,G.length),Ut(F,F.g.end()),Ut(F,G)),G=X(N,4),G!=null&&(G=J(G),jt(F.g,34),jt(F.g,G.length),Ut(F,F.g.end()),Ut(F,G)),ce(N,F),A=le(A),ot.call(W,Z,A)}}w=w.data;break t;default:w={}}}switch(E=w,V=d.stream,d.type){case"video":l.pushTexture2d(Object.assign(Object.assign({},E),{stream:V,timestamp:o}));break;case"detections":R=E,R.stream=V,R.timestamp=o,l.pushDetectionList(R);break;default:throw Error("Unknown input config type: '"+d.type+"'")}}return r.i.send(l),Y(k,r.C,4);case 4:l.delete(),k.g=0}})})};function Cn(t,e,n){return it(t,function r(){var o,l,s,c,h,d,E=this,V,R,k,w,x,T,P,et;return H(r,function(W){switch(W.g){case 1:if(!n)return W.return(e);for(o={},l=0,s=C(Object.keys(n)),c=s.next();!c.done;c=s.next())h=c.value,d=n[h],typeof d!="string"&&d.type==="texture"&&e[d.stream]!==void 0&&++l;1>>0)+"_",z=0;return f}),v("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var f="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),b=0;b"u"?!0:(typeof g=="function"?g=new g("unhandledrejection",{cancelable:!0}):typeof m=="function"?g=new m("unhandledrejection",{cancelable:!0}):(g=_.document.createEvent("CustomEvent"),g.initCustomEvent("unhandledrejection",!1,!0,g)),g.promise=this,g.reason=this.i,$(g))},f.prototype.H=function(){if(this.g!=null){for(var g=0;g"u"||lt.execScript("var "+ft[0]);for(var H;ft.length&&(H=ft.shift());)ft.length||Y===void 0?lt[H]&<[H]!==Object.prototype[H]?lt=lt[H]:lt=lt[H]={}:lt[H]=Y}).call(Yt);const be=[33,7,163,144,145,153,154,155,133,173,157,157,158,159,160,161,246],_e=[263,249,390,373,374,380,381,382,362,398,384,384,385,386,387,388,466],Ee=[70,63,105,66,107],f1=[46,53,52,65,55],xe=[300,293,334,296,336],h1=[276,283,282,295,285],je=[78,191,80,81,82,13,312,311,310,415,308,324,318,402,317,14,87,178,88,95],ke=[61,185,40,39,37,0,267,269,270,409,291,375,321,405,314,17,84,181,91,146],un=[6,197,195,5,4],ln=[98,97,2,328,327],cn=[454,323,361,288,397,365,379,378,400,377,152,148,176,149,150,136,172,58,132,93,234],g1=[468],d1=[473],p1=[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];var se=(i=>(i.LANDMARKS="landmarks",i.POINTS="points",i.CRUCIBLEAI="crucibleAI",i))(se||{});const v1={landmarks:w1,points:m1,crucibleAI:y1};function y1(i,u){nt(i,u,_e,"rgb(180, 200, 10)",4,!1,!0,!0),nt(i,u,be,"rgb(10, 200, 180)",4,!1,!0,!0),nt(i,u,Ee,"rgb(10, 200, 180)",4,!1,!0,!1),nt(i,u,f1,"rgb(10, 200, 180)",4,!1,!0,!1),nt(i,u,xe,"rgb(180, 200, 10)",4,!1,!0,!1),nt(i,u,h1,"rgb(180, 200, 10)",4,!1,!0,!1),nt(i,u,ke,"rgb(10, 180, 10)",4,!1,!0,!0),nt(i,u,je,"rgb(10, 180, 10)",4,!1,!0,!0),nt(i,u,p1,"rgb(10, 200, 10)",4,!1,!0,!0),dt(i,u,g1,"rgb(250, 200, 10)",2,"square"),dt(i,u,d1,"rgb(10, 200, 250)",2,"square")}function w1(i,u){nt(i,u,_e,"magenta",4,!0,!1,!0),nt(i,u,be,"magenta",4,!0,!1,!0),nt(i,u,Ee,"yellow",4,!1,!0,!1),nt(i,u,xe,"yellow",4,!1,!0,!1),nt(i,u,ke,"cyan",4,!0,!1,!0),nt(i,u,je,"blue",4,!0,!1,!0),nt(i,u,un,"orange",4,!1,!0,!1),nt(i,u,ln,"orange",4,!1,!0,!1),nt(i,u,cn,"lime",4,!1,!0,!1)}function m1(i,u){dt(i,u,_e,"black",2),dt(i,u,be,"black",2),dt(i,u,Ee,"black",2),dt(i,u,xe,"black",2),dt(i,u,ke,"black",2),dt(i,u,je,"black",2),dt(i,u,un,"black",2),dt(i,u,ln,"black",2),dt(i,u,cn,"black",2)}function nt(i,u,p,_="lime",v=4,O=!1,S=!0,C=!1){i.save(),i.beginPath(),i.strokeStyle=_,i.fillStyle=_,i.lineJoin="round",i.lineWidth=v;for(const[L,j]of p.entries()){const U=u[j];L===0?i.moveTo(U.x*i.canvas.width,U.y*i.canvas.height):i.lineTo(U.x*i.canvas.width,U.y*i.canvas.height)}C&&i.closePath(),O&&i.fill(),S&&i.stroke(),i.restore()}function dt(i,u,p,_="black",v=2.5,O="circle",S=!0,C=!1){i.save(),i.fillStyle=_,i.lineJoin="round",i.strokeStyle=_;for(const[L,j]of p.entries()){const U=u[j];i.beginPath(),O==="circle"?(i.ellipse(U.x*i.canvas.width,U.y*i.canvas.height,v,v,0,0,2*Math.PI),i.closePath()):O==="square"&&i.rect(U.x*i.canvas.width-v,U.y*i.canvas.height-v,v*2,v*2),C&&i.stroke(),S&&i.fill()}i.restore()}function b1(i){zn(i,"svelte-39b13y","canvas.svelte-39b13y{border-radius:0.5rem;--tw-shadow:0 1px 2px 0 rgb(0 0 0 / 0.05);--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}.capture-btn.svelte-39b13y{z-index:10;border-radius:0.5rem;--tw-bg-opacity:1;background-color:rgb(248 250 252 / var(--tw-bg-opacity));padding-left:0.5rem;padding-right:0.5rem;padding-top:0.25rem;padding-bottom:0.25rem;font-weight:700;--tw-text-opacity:1;color:rgb(0 0 0 / var(--tw-text-opacity));--tw-shadow:0 1px 2px 0 rgb(0 0 0 / 0.05);--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}.capture-btn.svelte-39b13y:hover{--tw-bg-opacity:1;background-color:rgb(207 250 254 / var(--tw-bg-opacity))}.container.svelte-39b13y *{color:black !important}")}function _1(i){let u,p,_,v,O,S,C,L,j,U,K;return{c(){u=Mt("div"),p=Mt("video"),_=ve(),v=Mt("canvas"),O=ve(),S=Mt("div"),C=Mt("button"),C.textContent="Snap",L=ve(),j=Mt("canvas"),vt(p,"class","hidden"),p.muted=!0,p.playsInline=!0,vt(v,"width",`512 - - px`),vt(v,"height",`512 - - px`),vt(v,"class","w-full svelte-39b13y"),vt(C,"class","capture-btn svelte-39b13y"),vt(j,"width",`512 - - px`),vt(j,"height",`512 - - px`),vt(j,"class","w-32 svelte-39b13y"),vt(S,"class","flex absolute bottom-1 left-1 items-end"),vt(u,"class","relative container svelte-39b13y")},m(Q,q){Xn(Q,u,q),Et(u,p),i[4](p),Et(u,_),Et(u,v),i[5](v),Et(u,O),Et(u,S),Et(S,C),Et(S,L),Et(S,j),i[6](j),U||(K=Dn(C,"click",i[3]),U=!0)},p:zt,i:zt,o:zt,d(Q){Q&&sn(u),i[4](null),i[5](null),i[6](null),U=!1,K()}}}function E1(i,u,p){const _=l1.FaceMesh||window.FaceMesh,v=c1.Camera||window.Camera;let O,S,C,L,j,U,K,Q,q=se.LANDMARKS,at=5;Zn(()=>{if(Q=document.getElementById("canvas-root"),Q._data||(Q._data={image:null}),Q.dataset.mode){const yt=Q.dataset.mode;q=se[yt.toUpperCase()],at=parseInt(Q.dataset.maxNumFaces)||5}C=S.getContext("2d"),U=document.createElement("canvas"),K=U.getContext("2d"),U.width=S.width,U.height=S.height;const D=new _({locateFile:yt=>`https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${yt}`});D.setOptions({maxNumFaces:at,refineLandmarks:!0,minDetectionConfidence:.5,minTrackingConfidence:.5}),D.onResults(ut),new v(O,{onFrame:async()=>{await D.send({image:O})},width:512,height:512}).start()});function ut(D){if(C.save(),C.clearRect(0,0,S.width,S.height),C.drawImage(D.image,0,0,S.width,S.height),K.clearRect(0,0,U.width,U.height),D.multiFaceLandmarks)for(const Ct of D.multiFaceLandmarks)v1[q](K,Ct);C.drawImage(U,0,0,S.width,S.height)}function At(){j=L.getContext("2d"),j.save(),j.fillStyle=q===se.POINTS?"white":"black",j.fillRect(0,0,L.width,L.height),j.drawImage(U,0,0,L.width,L.height),q==="points"&&(j.globalCompositeOperation="difference",j.fillStyle="white",j.fillRect(0,0,L.width,L.height),j.drawImage(U,0,0,L.width,L.height)),j.restore(),Q._data.image=L.toDataURL()}function Ot(D){Zt[D?"unshift":"push"](()=>{O=D,p(0,O)})}function St(D){Zt[D?"unshift":"push"](()=>{S=D,p(1,S)})}function Y(D){Zt[D?"unshift":"push"](()=>{L=D,p(2,L)})}return[O,S,L,At,Ot,St,Y]}class x1 extends u1{constructor(u){super(),a1(this,u,E1,_1,$n,{},b1)}}class j1 extends HTMLElement{constructor(){super()}connectedCallback(){const u=this.attachShadow({mode:"open"}),p=document.createElement("style");p.appendChild(document.createTextNode(Bn)),u.appendChild(p),new x1({target:u})}}customElements.define("face-canvas",j1); +`+n.getProgramInfoLog(l));r=t.m=l,n.useProgram(r),o=n.getUniformLocation(r,"sampler0"),t.j={I:n.getAttribLocation(r,"aVertex"),H:n.getAttribLocation(r,"aTex"),da:o},t.s=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,t.s),n.enableVertexAttribArray(t.j.I),n.vertexAttribPointer(t.j.I,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,1,1,-1]),n.STATIC_DRAW),n.bindBuffer(n.ARRAY_BUFFER,null),t.o=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,t.o),n.enableVertexAttribArray(t.j.H),n.vertexAttribPointer(t.j.H,2,n.FLOAT,!1,0,0),n.bufferData(n.ARRAY_BUFFER,new Float32Array([0,1,0,0,1,0,1,1]),n.STATIC_DRAW),n.bindBuffer(n.ARRAY_BUFFER,null),n.uniform1i(o,0)}r=t.j,n.useProgram(t.m),n.canvas.width=e.width,n.canvas.height=e.height,n.viewport(0,0,e.width,e.height),n.activeTexture(n.TEXTURE0),t.h.bindTexture2d(e.glName),n.enableVertexAttribArray(r.I),n.bindBuffer(n.ARRAY_BUFFER,t.s),n.vertexAttribPointer(r.I,2,n.FLOAT,!1,0,0),n.enableVertexAttribArray(r.H),n.bindBuffer(n.ARRAY_BUFFER,t.o),n.vertexAttribPointer(r.H,2,n.FLOAT,!1,0,0),n.bindFramebuffer(n.DRAW_FRAMEBUFFER?n.DRAW_FRAMEBUFFER:n.FRAMEBUFFER,null),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.colorMask(!0,!0,!0,!0),n.drawArrays(n.TRIANGLE_FAN,0,4),n.disableVertexAttribArray(r.I),n.disableVertexAttribArray(r.H),n.bindBuffer(n.ARRAY_BUFFER,null),t.h.bindTexture2d(0)}function kn(t){this.g=t}var An=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,9,1,7,0,65,0,253,15,26,11]);function On(t,e){return e+t}function He(t,e){window[t]=e}function Sn(t){var e=document.createElement("script");return e.setAttribute("src",t),e.setAttribute("crossorigin","anonymous"),new Promise(function(n){e.addEventListener("load",function(){n()},!1),e.addEventListener("error",function(){n()},!1),document.body.appendChild(e)})}function Tn(){return it(this,function t(){return H(t,function(e){switch(e.g){case 1:return e.m=2,Y(e,WebAssembly.instantiate(An),4);case 4:e.g=3,e.m=0;break;case 2:return e.m=0,e.j=null,e.return(!1);case 3:return e.return(!0)}})})}function de(t){if(this.g=t,this.listeners={},this.j={},this.F={},this.m={},this.s={},this.G=this.o=this.R=!0,this.C=Promise.resolve(),this.P="",this.B={},this.locateFile=t&&t.locateFile||On,typeof window=="object")var e=window.location.pathname.toString().substring(0,window.location.pathname.toString().lastIndexOf("/"))+"/";else if(typeof location<"u")e=location.pathname.toString().substring(0,location.pathname.toString().lastIndexOf("/"))+"/";else throw Error("solutions can only be loaded on a web page or in a web worker");if(this.S=e,t.options){e=C(Object.keys(t.options));for(var n=e.next();!n.done;n=e.next()){n=n.value;var r=t.options[n].default;r!==void 0&&(this.j[n]=typeof r=="function"?r():r)}}}i=de.prototype,i.close=function(){return this.i&&this.i.delete(),Promise.resolve()};function Rn(t,e){return t.g.files===void 0?[]:typeof t.g.files=="function"?t.g.files(e):t.g.files}function Fn(t){return it(t,function e(){var n=this,r,o,l,s,c,h,d,E,V,R,k;return H(e,function(w){switch(w.g){case 1:return r=n,n.R?(o=Rn(n,n.j),Y(w,Tn(),2)):w.return();case 2:if(l=w.h,typeof window=="object")return He("createMediapipeSolutionsWasm",{locateFile:n.locateFile}),He("createMediapipeSolutionsPackedAssets",{locateFile:n.locateFile}),h=o.filter(function(x){return x.data!==void 0}),d=o.filter(function(x){return x.data===void 0}),E=Promise.all(h.map(function(x){var T=pe(r,x.url);if(x.path!==void 0){var P=x.path;T=T.then(function(et){return r.overrideFile(P,et),Promise.resolve(et)})}return T})),V=Promise.all(d.map(function(x){return x.simd===void 0||x.simd&&l||!x.simd&&!l?Sn(r.locateFile(x.url,r.S)):Promise.resolve()})).then(function(){return it(r,function x(){var T,P,et=this;return H(x,function(W){if(W.g==1)return T=window.createMediapipeSolutionsWasm,P=window.createMediapipeSolutionsPackedAssets,Y(W,T(P),2);et.h=W.h,W.g=0})})}),R=function(){return it(r,function x(){var T=this;return H(x,function(P){return T.g.graph&&T.g.graph.url?P=Y(P,pe(T,T.g.graph.url),0):(P.g=0,P=void 0),P})})}(),Y(w,Promise.all([V,E,R]),7);if(typeof importScripts!="function")throw Error("solutions can only be loaded on a web page or in a web worker");return s=o.filter(function(x){return x.simd===void 0||x.simd&&l||!x.simd&&!l}).map(function(x){return r.locateFile(x.url,r.S)}),importScripts.apply(null,L(s)),Y(w,createMediapipeSolutionsWasm(Module),6);case 6:n.h=w.h,n.l=new OffscreenCanvas(1,1),n.h.canvas=n.l,c=n.h.GL.createContext(n.l,{antialias:!1,alpha:!1,ba:typeof WebGL2RenderingContext<"u"?2:1}),n.h.GL.makeContextCurrent(c),w.g=4;break;case 7:if(n.l=document.createElement("canvas"),k=n.l.getContext("webgl2",{}),!k&&(k=n.l.getContext("webgl",{}),!k))return alert("Failed to create WebGL canvas context when passing video frame."),w.return();n.D=k,n.h.canvas=n.l,n.h.createContext(n.l,!0,!0,{});case 4:n.i=new n.h.SolutionWasm,n.R=!1,w.g=0}})})}function Ln(t){return it(t,function e(){var n=this,r,o,l,s,c,h,d,E;return H(e,function(V){if(V.g==1){if(n.g.graph&&n.g.graph.url&&n.P===n.g.graph.url)return V.return();if(n.o=!0,!n.g.graph||!n.g.graph.url){V.g=2;return}return n.P=n.g.graph.url,Y(V,pe(n,n.g.graph.url),3)}for(V.g!=2&&(r=V.h,n.i.loadGraph(r)),o=C(Object.keys(n.B)),l=o.next();!l.done;l=o.next())s=l.value,n.i.overrideFile(s,n.B[s]);if(n.B={},n.g.listeners)for(c=C(n.g.listeners),h=c.next();!h.done;h=c.next())d=h.value,Nn(n,d);E=n.j,n.j={},n.setOptions(E),V.g=0})})}i.reset=function(){return it(this,function t(){var e=this;return H(t,function(n){e.i&&(e.i.reset(),e.m={},e.s={}),n.g=0})})},i.setOptions=function(t,e){var n=this;if(e=e||this.g.options){for(var r=[],o=[],l={},s=C(Object.keys(t)),c=s.next();!c.done;l={K:l.K,L:l.L},c=s.next()){var h=c.value;h in this.j&&this.j[h]===t[h]||(this.j[h]=t[h],c=e[h],c!==void 0&&(c.onChange&&(l.K=c.onChange,l.L=t[h],r.push(function(d){return function(){return it(n,function E(){var V,R=this;return H(E,function(k){if(k.g==1)return Y(k,d.K(d.L),2);V=k.h,V===!0&&(R.o=!0),k.g=0})})}}(l))),c.graphOptionXref&&(h={valueNumber:c.type===1?t[h]:0,valueBoolean:c.type===0?t[h]:!1,valueString:c.type===2?t[h]:""},c=Object.assign(Object.assign(Object.assign({},{calculatorName:"",calculatorIndex:0}),c.graphOptionXref),h),o.push(c))))}(r.length!==0||o.length!==0)&&(this.o=!0,this.A=(this.A===void 0?[]:this.A).concat(o),this.u=(this.u===void 0?[]:this.u).concat(r))}};function Mn(t){return it(t,function e(){var n=this,r,o,l,s,c,h,d;return H(e,function(E){switch(E.g){case 1:if(!n.o)return E.return();if(!n.u){E.g=2;break}r=C(n.u),o=r.next();case 3:if(o.done){E.g=5;break}return l=o.value,Y(E,l(),4);case 4:o=r.next(),E.g=3;break;case 5:n.u=void 0;case 2:if(n.A){for(s=new n.h.GraphOptionChangeRequestList,c=C(n.A),h=c.next();!h.done;h=c.next())d=h.value,s.push_back(d);n.i.changeOptions(s),s.delete(),n.A=void 0}n.o=!1,E.g=0}})})}i.initialize=function(){return it(this,function t(){var e=this;return H(t,function(n){return n.g==1?Y(n,Fn(e),2):n.g!=3?Y(n,Ln(e),3):Y(n,Mn(e),0)})})};function pe(t,e){return it(t,function n(){var r=this,o,l;return H(n,function(s){return e in r.F?s.return(r.F[e]):(o=r.locateFile(e,""),l=fetch(o).then(function(c){return c.arrayBuffer()}),r.F[e]=l,s.return(l))})})}i.overrideFile=function(t,e){this.i?this.i.overrideFile(t,e):this.B[t]=e},i.clearOverriddenFiles=function(){this.B={},this.i&&this.i.clearOverriddenFiles()},i.send=function(t,e){return it(this,function n(){var r=this,o,l,s,c,h,d,E,V,R;return H(n,function(k){switch(k.g){case 1:return r.g.inputs?(o=1e3*(e??performance.now()),Y(k,r.C,2)):k.return();case 2:return Y(k,r.initialize(),3);case 3:for(l=new r.h.PacketDataList,s=C(Object.keys(t)),c=s.next();!c.done;c=s.next())if(h=c.value,d=r.g.inputs[h]){t:{var w=r,x=t[h];switch(d.type){case"video":var T=w.m[d.stream];if(T||(T=new ge(w.h,w.D),w.m[d.stream]=T),w=T,w.l===0&&(w.l=w.h.createTexture()),typeof HTMLVideoElement<"u"&&x instanceof HTMLVideoElement){var P=x.videoWidth;T=x.videoHeight}else typeof HTMLImageElement<"u"&&x instanceof HTMLImageElement?(P=x.naturalWidth,T=x.naturalHeight):(P=x.width,T=x.height);T={glName:w.l,width:P,height:T},P=w.g,P.canvas.width=T.width,P.canvas.height=T.height,P.activeTexture(P.TEXTURE0),w.h.bindTexture2d(w.l),P.texImage2D(P.TEXTURE_2D,0,P.RGBA,P.RGBA,P.UNSIGNED_BYTE,x),w.h.bindTexture2d(0),w=T;break t;case"detections":for(T=w.m[d.stream],T||(T=new kn(w.h),w.m[d.stream]=T),w=T,w.data||(w.data=new w.g.DetectionListData),w.data.reset(x.length),T=0;TI,I=Math.abs(I);var B=I>>>0;for(I=Math.floor((I-B)/4294967296),I>>>=0,G&&(I=~I>>>0,B=(~B>>>0)+1,4294967295>>7|B<<25)>>>0,B>>>=7;F.push(G)}if(ce(A,N),Z=le(Z),W.call(et,ot,Z),P.O)for(et=0;etI;I++)G.push(B&127|128),B>>=7;G.push(1)}gt(F,2,X(N,2)),G=X(N,3),G!=null&&(G=J(G),jt(F.g,26),jt(F.g,G.length),Ut(F,F.g.end()),Ut(F,G)),G=X(N,4),G!=null&&(G=J(G),jt(F.g,34),jt(F.g,G.length),Ut(F,F.g.end()),Ut(F,G)),ce(N,F),A=le(A),ot.call(W,Z,A)}}w=w.data;break t;default:w={}}}switch(E=w,V=d.stream,d.type){case"video":l.pushTexture2d(Object.assign(Object.assign({},E),{stream:V,timestamp:o}));break;case"detections":R=E,R.stream=V,R.timestamp=o,l.pushDetectionList(R);break;default:throw Error("Unknown input config type: '"+d.type+"'")}}return r.i.send(l),Y(k,r.C,4);case 4:l.delete(),k.g=0}})})};function Cn(t,e,n){return it(t,function r(){var o,l,s,c,h,d,E=this,V,R,k,w,x,T,P,et;return H(r,function(W){switch(W.g){case 1:if(!n)return W.return(e);for(o={},l=0,s=C(Object.keys(n)),c=s.next();!c.done;c=s.next())h=c.value,d=n[h],typeof d!="string"&&d.type==="texture"&&e[d.stream]!==void 0&&++l;1>>0)+"_",z=0;return f}),v("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var f="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),b=0;b"u"?!0:(typeof g=="function"?g=new g("unhandledrejection",{cancelable:!0}):typeof m=="function"?g=new m("unhandledrejection",{cancelable:!0}):(g=_.document.createEvent("CustomEvent"),g.initCustomEvent("unhandledrejection",!1,!0,g)),g.promise=this,g.reason=this.i,$(g))},f.prototype.H=function(){if(this.g!=null){for(var g=0;g"u"||lt.execScript("var "+ft[0]);for(var H;ft.length&&(H=ft.shift());)ft.length||Y===void 0?lt[H]&<[H]!==Object.prototype[H]?lt=lt[H]:lt=lt[H]={}:lt[H]=Y}).call(Yt);const be=[33,7,163,144,145,153,154,155,133,173,157,157,158,159,160,161,246],_e=[263,249,390,373,374,380,381,382,362,398,384,384,385,386,387,388,466],Ee=[70,63,105,66,107],f1=[46,53,52,65,55],xe=[300,293,334,296,336],h1=[276,283,282,295,285],je=[78,191,80,81,82,13,312,311,310,415,308,324,318,402,317,14,87,178,88,95],ke=[61,185,40,39,37,0,267,269,270,409,291,375,321,405,314,17,84,181,91,146],un=[6,197,195,5,4],ln=[98,97,2,328,327],cn=[454,323,361,288,397,365,379,378,400,377,152,148,176,149,150,136,172,58,132,93,234],g1=[468],d1=[473],p1=[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];var se=(i=>(i.LANDMARKS="landmarks",i.POINTS="points",i.CRUCIBLEAI="crucibleAI",i))(se||{});const v1={landmarks:w1,points:m1,crucibleAI:y1};function y1(i,u){nt(i,u,_e,"rgb(180, 200, 10)",4,!1,!0,!0),nt(i,u,be,"rgb(10, 200, 180)",4,!1,!0,!0),nt(i,u,Ee,"rgb(10, 200, 180)",4,!1,!0,!1),nt(i,u,f1,"rgb(10, 200, 180)",4,!1,!0,!1),nt(i,u,xe,"rgb(180, 200, 10)",4,!1,!0,!1),nt(i,u,h1,"rgb(180, 200, 10)",4,!1,!0,!1),nt(i,u,ke,"rgb(10, 180, 10)",4,!1,!0,!0),nt(i,u,je,"rgb(10, 180, 10)",4,!1,!0,!0),nt(i,u,p1,"rgb(10, 200, 10)",4,!1,!0,!0),dt(i,u,g1,"rgb(250, 200, 10)",2,"square"),dt(i,u,d1,"rgb(10, 200, 250)",2,"square")}function w1(i,u){nt(i,u,_e,"magenta",4,!0,!1,!0),nt(i,u,be,"magenta",4,!0,!1,!0),nt(i,u,Ee,"yellow",4,!1,!0,!1),nt(i,u,xe,"yellow",4,!1,!0,!1),nt(i,u,ke,"cyan",4,!0,!1,!0),nt(i,u,je,"blue",4,!0,!1,!0),nt(i,u,un,"orange",4,!1,!0,!1),nt(i,u,ln,"orange",4,!1,!0,!1),nt(i,u,cn,"lime",4,!1,!0,!1)}function m1(i,u){dt(i,u,_e,"black",2),dt(i,u,be,"black",2),dt(i,u,Ee,"black",2),dt(i,u,xe,"black",2),dt(i,u,ke,"black",2),dt(i,u,je,"black",2),dt(i,u,un,"black",2),dt(i,u,ln,"black",2),dt(i,u,cn,"black",2)}function nt(i,u,p,_="lime",v=4,O=!1,S=!0,C=!1){i.save(),i.beginPath(),i.strokeStyle=_,i.fillStyle=_,i.lineJoin="round",i.lineWidth=v;for(const[L,j]of p.entries()){const U=u[j];L===0?i.moveTo(U.x*i.canvas.width,U.y*i.canvas.height):i.lineTo(U.x*i.canvas.width,U.y*i.canvas.height)}C&&i.closePath(),O&&i.fill(),S&&i.stroke(),i.restore()}function dt(i,u,p,_="black",v=2.5,O="circle",S=!0,C=!1){i.save(),i.fillStyle=_,i.lineJoin="round",i.strokeStyle=_;for(const[L,j]of p.entries()){const U=u[j];i.beginPath(),O==="circle"?(i.ellipse(U.x*i.canvas.width,U.y*i.canvas.height,v,v,0,0,2*Math.PI),i.closePath()):O==="square"&&i.rect(U.x*i.canvas.width-v,U.y*i.canvas.height-v,v*2,v*2),C&&i.stroke(),S&&i.fill()}i.restore()}function b1(i){zn(i,"svelte-39b13y","canvas.svelte-39b13y{border-radius:0.5rem;--tw-shadow:0 1px 2px 0 rgb(0 0 0 / 0.05);--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}.capture-btn.svelte-39b13y{z-index:10;border-radius:0.5rem;--tw-bg-opacity:1;background-color:rgb(248 250 252 / var(--tw-bg-opacity));padding-left:0.5rem;padding-right:0.5rem;padding-top:0.25rem;padding-bottom:0.25rem;font-weight:700;--tw-text-opacity:1;color:rgb(0 0 0 / var(--tw-text-opacity));--tw-shadow:0 1px 2px 0 rgb(0 0 0 / 0.05);--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}.capture-btn.svelte-39b13y:hover{--tw-bg-opacity:1;background-color:rgb(207 250 254 / var(--tw-bg-opacity))}.container.svelte-39b13y *{color:black !important}")}function _1(i){let u,p,_,v,O,S,C,L,j,U,K;return{c(){u=Mt("div"),p=Mt("video"),_=ve(),v=Mt("canvas"),O=ve(),S=Mt("div"),C=Mt("button"),C.textContent="Snap",L=ve(),j=Mt("canvas"),vt(p,"class","hidden"),p.muted=!0,p.playsInline=!0,vt(v,"width","712px"),vt(v,"height","712px"),vt(v,"class","w-full svelte-39b13y"),vt(C,"class","capture-btn svelte-39b13y"),vt(j,"width","712px"),vt(j,"height","712px"),vt(j,"class","w-32 svelte-39b13y"),vt(S,"class","flex absolute bottom-1 left-1 items-end"),vt(u,"class","relative container svelte-39b13y")},m(Q,q){Xn(Q,u,q),Et(u,p),i[4](p),Et(u,_),Et(u,v),i[5](v),Et(u,O),Et(u,S),Et(S,C),Et(S,L),Et(S,j),i[6](j),U||(K=Dn(C,"click",i[3]),U=!0)},p:zt,i:zt,o:zt,d(Q){Q&&sn(u),i[4](null),i[5](null),i[6](null),U=!1,K()}}}function E1(i,u,p){const _=l1.FaceMesh||window.FaceMesh,v=c1.Camera||window.Camera;let O,S,C,L,j,U,K,Q,q=se.LANDMARKS,at=5;Zn(()=>{if(Q=document.getElementById("canvas-root"),Q._data||(Q._data={image:null}),Q.dataset.mode){const yt=Q.dataset.mode;q=se[yt.toUpperCase()],at=parseInt(Q.dataset.maxNumFaces)||5}C=S.getContext("2d"),U=document.createElement("canvas"),K=U.getContext("2d"),U.width=S.width,U.height=S.height;const D=new _({locateFile:yt=>`https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${yt}`});D.setOptions({maxNumFaces:at,refineLandmarks:!0,minDetectionConfidence:.5,minTrackingConfidence:.5}),D.onResults(ut),new v(O,{onFrame:async()=>{await D.send({image:O})},width:712,height:712}).start()});function ut(D){if(C.save(),C.clearRect(0,0,S.width,S.height),C.drawImage(D.image,0,0,S.width,S.height),K.clearRect(0,0,U.width,U.height),D.multiFaceLandmarks)for(const Ct of D.multiFaceLandmarks)v1[q](K,Ct);C.drawImage(U,0,0,S.width,S.height)}function At(){j=L.getContext("2d"),j.save(),j.fillStyle=q===se.POINTS?"white":"black",j.fillRect(0,0,L.width,L.height),j.drawImage(U,0,0,L.width,L.height),q==="points"&&(j.globalCompositeOperation="difference",j.fillStyle="white",j.fillRect(0,0,L.width,L.height),j.drawImage(U,0,0,L.width,L.height)),j.restore(),Q._data.image=L.toDataURL()}function Ot(D){Zt[D?"unshift":"push"](()=>{O=D,p(0,O)})}function St(D){Zt[D?"unshift":"push"](()=>{S=D,p(1,S)})}function Y(D){Zt[D?"unshift":"push"](()=>{L=D,p(2,L)})}return[O,S,L,At,Ot,St,Y]}class x1 extends u1{constructor(u){super(),a1(this,u,E1,_1,$n,{},b1)}}class j1 extends HTMLElement{constructor(){super()}connectedCallback(){const u=this.attachShadow({mode:"open"}),p=document.createElement("style");p.appendChild(document.createTextNode(Bn)),u.appendChild(p),new x1({target:u})}}customElements.define("face-canvas",j1);