diff --git a/CHANGELOG.md b/CHANGELOG.md index dbf970cb..4ea322f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # @vladmandic/human - Version: **3.0.1** + Version: **3.0.2** Description: **Human: AI-powered 3D Face Detection & Rotation Tracking, Face Description & Recognition, Body Pose Tracking, 3D Hand & Finger Tracking, Iris Analysis, Age & Gender & Emotion Prediction, Gesture Recognition** Author: **Vladimir Mandic ** @@ -9,8 +9,12 @@ ## Changelog -### **HEAD -> main** 2023/01/03 mandic00@live.com +### **HEAD -> main** 2023/01/06 mandic00@live.com + +### **3.0.2** 2023/01/06 mandic00@live.com + +- full rebuild - default face.rotation disabled ### **release: 3.0.1** 2022/11/22 mandic00@live.com diff --git a/demo/faceid/index.js b/demo/faceid/index.js index 44cecc9a..37f2e0ac 100644 --- a/demo/faceid/index.js +++ b/demo/faceid/index.js @@ -4,358 +4,6 @@ author: ' */ - -// demo/faceid/index.ts -import * as H from "../../dist/human.esm.js"; - -// demo/faceid/indexdb.ts -var db; -var database = "human"; -var table = "person"; -var log = (...msg) => console.log("indexdb", ...msg); -async function open() { - if (db) - return true; - return new Promise((resolve) => { - const request = indexedDB.open(database, 1); - request.onerror = (evt) => log("error:", evt); - request.onupgradeneeded = (evt) => { - log("create:", evt.target); - db = evt.target.result; - db.createObjectStore(table, { keyPath: "id", autoIncrement: true }); - }; - request.onsuccess = (evt) => { - db = evt.target.result; - log("open:", db); - resolve(true); - }; - }); -} -async function load() { - const faceDB = []; - if (!db) - await open(); - return new Promise((resolve) => { - const cursor = db.transaction([table], "readwrite").objectStore(table).openCursor(null, "next"); - cursor.onerror = (evt) => log("load error:", evt); - cursor.onsuccess = (evt) => { - if (evt.target.result) { - faceDB.push(evt.target.result.value); - evt.target.result.continue(); - } else { - resolve(faceDB); - } - }; - }); -} -async function count() { - if (!db) - await open(); - return new Promise((resolve) => { - const store = db.transaction([table], "readwrite").objectStore(table).count(); - store.onerror = (evt) => log("count error:", evt); - store.onsuccess = () => resolve(store.result); - }); -} -async function save(faceRecord) { - if (!db) - await open(); - const newRecord = { name: faceRecord.name, descriptor: faceRecord.descriptor, image: faceRecord.image }; - db.transaction([table], "readwrite").objectStore(table).put(newRecord); - log("save:", newRecord); -} -async function remove(faceRecord) { - if (!db) - await open(); - db.transaction([table], "readwrite").objectStore(table).delete(faceRecord.id); - log("delete:", faceRecord); -} - -// demo/faceid/index.ts -var humanConfig = { - cacheSensitivity: 0, - modelBasePath: "../../models", - filter: { enabled: true, equalization: true }, - debug: true, - face: { - enabled: true, - detector: { rotation: true, return: true, mask: false }, - description: { enabled: true }, - iris: { enabled: true }, - emotion: { enabled: false }, - antispoof: { enabled: true }, - liveness: { enabled: true } - }, - body: { enabled: false }, - hand: { enabled: false }, - object: { enabled: false }, - gesture: { enabled: true } -}; -var matchOptions = { order: 2, multiplier: 25, min: 0.2, max: 0.8 }; -var options = { - minConfidence: 0.6, - minSize: 224, - maxTime: 3e4, - blinkMin: 10, - blinkMax: 800, - threshold: 0.5, - distanceMin: 0.4, - distanceMax: 1, - mask: humanConfig.face.detector.mask, - rotation: humanConfig.face.detector.rotation, - ...matchOptions -}; -var ok = { - faceCount: { status: false, val: 0 }, - faceConfidence: { status: false, val: 0 }, - facingCenter: { status: false, val: 0 }, - lookingCenter: { status: false, val: 0 }, - blinkDetected: { status: false, val: 0 }, - faceSize: { status: false, val: 0 }, - antispoofCheck: { status: false, val: 0 }, - livenessCheck: { status: false, val: 0 }, - distance: { status: false, val: 0 }, - age: { status: false, val: 0 }, - gender: { status: false, val: 0 }, - timeout: { status: true, val: 0 }, - descriptor: { status: false, val: 0 }, - elapsedMs: { status: void 0, val: 0 }, - detectFPS: { status: void 0, val: 0 }, - drawFPS: { status: void 0, val: 0 } -}; -var allOk = () => ok.faceCount.status && ok.faceSize.status && ok.blinkDetected.status && ok.facingCenter.status && ok.lookingCenter.status && ok.faceConfidence.status && ok.antispoofCheck.status && ok.livenessCheck.status && ok.distance.status && ok.descriptor.status && ok.age.status && ok.gender.status; -var current = { face: null, record: null }; -var blink = { - start: 0, - end: 0, - time: 0 -}; -var human = new H.Human(humanConfig); -human.env.perfadd = false; -human.draw.options.font = 'small-caps 18px "Lato"'; -human.draw.options.lineHeight = 20; -var dom = { - video: document.getElementById("video"), - canvas: document.getElementById("canvas"), - log: document.getElementById("log"), - fps: document.getElementById("fps"), - match: document.getElementById("match"), - name: document.getElementById("name"), - save: document.getElementById("save"), - delete: document.getElementById("delete"), - retry: document.getElementById("retry"), - source: document.getElementById("source"), - ok: document.getElementById("ok") -}; -var timestamp = { detect: 0, draw: 0 }; -var startTime = 0; -var log2 = (...msg) => { - dom.log.innerText += msg.join(" ") + "\n"; - console.log(...msg); -}; -async function webCam() { - const cameraOptions = { audio: false, video: { facingMode: "user", resizeMode: "none", width: { ideal: document.body.clientWidth } } }; - const stream = await navigator.mediaDevices.getUserMedia(cameraOptions); - const ready = new Promise((resolve) => { - dom.video.onloadeddata = () => resolve(true); - }); - dom.video.srcObject = stream; - void dom.video.play(); - await ready; - dom.canvas.width = dom.video.videoWidth; - dom.canvas.height = dom.video.videoHeight; - dom.canvas.style.width = "50%"; - dom.canvas.style.height = "50%"; - if (human.env.initial) - log2("video:", dom.video.videoWidth, dom.video.videoHeight, "|", stream.getVideoTracks()[0].label); - dom.canvas.onclick = () => { - if (dom.video.paused) - void dom.video.play(); - else - dom.video.pause(); - }; -} -async function detectionLoop() { - var _a; - if (!dom.video.paused) { - if ((_a = current.face) == null ? void 0 : _a.tensor) - human.tf.dispose(current.face.tensor); - await human.detect(dom.video); - const now = human.now(); - ok.detectFPS.val = Math.round(1e4 / (now - timestamp.detect)) / 10; - timestamp.detect = now; - requestAnimationFrame(detectionLoop); - } -} -function drawValidationTests() { - let y = 32; - for (const [key, val] of Object.entries(ok)) { - let el = document.getElementById(`ok-${key}`); - if (!el) { - el = document.createElement("div"); - el.id = `ok-${key}`; - el.innerText = key; - el.className = "ok"; - el.style.top = `${y}px`; - dom.ok.appendChild(el); - } - if (typeof val.status === "boolean") - el.style.backgroundColor = val.status ? "lightgreen" : "lightcoral"; - const status = val.status ? "ok" : "fail"; - el.innerText = `${key}: ${val.val === 0 ? status : val.val}`; - y += 28; - } -} -async function validationLoop() { - var _a; - const interpolated = human.next(human.result); - human.draw.canvas(dom.video, dom.canvas); - await human.draw.all(dom.canvas, interpolated); - const now = human.now(); - ok.drawFPS.val = Math.round(1e4 / (now - timestamp.draw)) / 10; - timestamp.draw = now; - ok.faceCount.val = human.result.face.length; - ok.faceCount.status = ok.faceCount.val === 1; - if (ok.faceCount.status) { - const gestures = Object.values(human.result.gesture).map((gesture) => gesture.gesture); - if (gestures.includes("blink left eye") || gestures.includes("blink right eye")) - blink.start = human.now(); - if (blink.start > 0 && !gestures.includes("blink left eye") && !gestures.includes("blink right eye")) - blink.end = human.now(); - ok.blinkDetected.status = ok.blinkDetected.status || Math.abs(blink.end - blink.start) > options.blinkMin && Math.abs(blink.end - blink.start) < options.blinkMax; - if (ok.blinkDetected.status && blink.time === 0) - blink.time = Math.trunc(blink.end - blink.start); - ok.facingCenter.status = gestures.includes("facing center"); - ok.lookingCenter.status = gestures.includes("looking center"); - ok.faceConfidence.val = human.result.face[0].faceScore || human.result.face[0].boxScore || 0; - ok.faceConfidence.status = ok.faceConfidence.val >= options.minConfidence; - ok.antispoofCheck.val = human.result.face[0].real || 0; - ok.antispoofCheck.status = ok.antispoofCheck.val >= options.minConfidence; - ok.livenessCheck.val = human.result.face[0].live || 0; - ok.livenessCheck.status = ok.livenessCheck.val >= options.minConfidence; - ok.faceSize.val = Math.min(human.result.face[0].box[2], human.result.face[0].box[3]); - ok.faceSize.status = ok.faceSize.val >= options.minSize; - ok.distance.val = human.result.face[0].distance || 0; - ok.distance.status = ok.distance.val >= options.distanceMin && ok.distance.val <= options.distanceMax; - ok.descriptor.val = ((_a = human.result.face[0].embedding) == null ? void 0 : _a.length) || 0; - ok.descriptor.status = ok.descriptor.val > 0; - ok.age.val = human.result.face[0].age || 0; - ok.age.status = ok.age.val > 0; - ok.gender.val = human.result.face[0].genderScore || 0; - ok.gender.status = ok.gender.val >= options.minConfidence; - } - ok.timeout.status = ok.elapsedMs.val <= options.maxTime; - drawValidationTests(); - if (allOk() || !ok.timeout.status) { - dom.video.pause(); - return human.result.face[0]; - } - ok.elapsedMs.val = Math.trunc(human.now() - startTime); - return new Promise((resolve) => { - setTimeout(async () => { - await validationLoop(); - resolve(human.result.face[0]); - }, 30); - }); -} -async function saveRecords() { - var _a, _b, _c, _d; - if (dom.name.value.length > 0) { - const image = (_a = dom.canvas.getContext("2d")) == null ? void 0 : _a.getImageData(0, 0, dom.canvas.width, dom.canvas.height); - const rec = { id: 0, name: dom.name.value, descriptor: (_b = current.face) == null ? void 0 : _b.embedding, image }; - await save(rec); - log2("saved face record:", rec.name, "descriptor length:", (_d = (_c = current.face) == null ? void 0 : _c.embedding) == null ? void 0 : _d.length); - log2("known face records:", await count()); - } else { - log2("invalid name"); - } -} -async function deleteRecord() { - if (current.record && current.record.id > 0) { - await remove(current.record); - } -} -async function detectFace() { - var _a, _b, _c, _d; - dom.canvas.style.height = ""; - (_a = dom.canvas.getContext("2d")) == null ? void 0 : _a.clearRect(0, 0, options.minSize, options.minSize); - if (!((_b = current == null ? void 0 : current.face) == null ? void 0 : _b.tensor) || !((_c = current == null ? void 0 : current.face) == null ? void 0 : _c.embedding)) - return false; - console.log("face record:", current.face); - log2(`detected face: ${current.face.gender} ${current.face.age || 0}y distance ${100 * (current.face.distance || 0)}cm/${Math.round(100 * (current.face.distance || 0) / 2.54)}in`); - await human.tf.browser.toPixels(current.face.tensor, dom.canvas); - if (await count() === 0) { - log2("face database is empty: nothing to compare face with"); - document.body.style.background = "black"; - dom.delete.style.display = "none"; - return false; - } - const db2 = await load(); - const descriptors = db2.map((rec) => rec.descriptor).filter((desc) => desc.length > 0); - const res = human.match.find(current.face.embedding, descriptors, matchOptions); - current.record = db2[res.index] || null; - if (current.record) { - log2(`best match: ${current.record.name} | id: ${current.record.id} | similarity: ${Math.round(1e3 * res.similarity) / 10}%`); - dom.name.value = current.record.name; - dom.source.style.display = ""; - (_d = dom.source.getContext("2d")) == null ? void 0 : _d.putImageData(current.record.image, 0, 0); - } - document.body.style.background = res.similarity > options.threshold ? "darkgreen" : "maroon"; - return res.similarity > options.threshold; -} -async function main() { - var _a, _b, _c, _d; - ok.faceCount.status = false; - ok.faceConfidence.status = false; - ok.facingCenter.status = false; - ok.blinkDetected.status = false; - ok.faceSize.status = false; - ok.antispoofCheck.status = false; - ok.livenessCheck.status = false; - ok.age.status = false; - ok.gender.status = false; - ok.elapsedMs.val = 0; - dom.match.style.display = "none"; - dom.retry.style.display = "none"; - dom.source.style.display = "none"; - dom.canvas.style.height = "50%"; - document.body.style.background = "black"; - await webCam(); - await detectionLoop(); - startTime = human.now(); - current.face = await validationLoop(); - dom.canvas.width = ((_b = (_a = current.face) == null ? void 0 : _a.tensor) == null ? void 0 : _b.shape[1]) || options.minSize; - dom.canvas.height = ((_d = (_c = current.face) == null ? void 0 : _c.tensor) == null ? void 0 : _d.shape[0]) || options.minSize; - dom.source.width = dom.canvas.width; - dom.source.height = dom.canvas.height; - dom.canvas.style.width = ""; - dom.match.style.display = "flex"; - dom.save.style.display = "flex"; - dom.delete.style.display = "flex"; - dom.retry.style.display = "block"; - if (!allOk()) { - log2("did not find valid face"); - return false; - } - return detectFace(); -} -async function init() { - var _a, _b; - log2("human version:", human.version, "| tfjs version:", human.tf.version["tfjs-core"]); - log2("options:", JSON.stringify(options).replace(/{|}|"|\[|\]/g, "").replace(/,/g, " ")); - log2("initializing webcam..."); - await webCam(); - log2("loading human models..."); - await human.load(); - log2("initializing human..."); - log2("face embedding model:", humanConfig.face.description.enabled ? "faceres" : "", ((_a = humanConfig.face["mobilefacenet"]) == null ? void 0 : _a.enabled) ? "mobilefacenet" : "", ((_b = humanConfig.face["insightface"]) == null ? void 0 : _b.enabled) ? "insightface" : ""); - log2("loading face database..."); - log2("known face records:", await count()); - dom.retry.addEventListener("click", main); - dom.save.addEventListener("click", saveRecords); - dom.delete.addEventListener("click", deleteRecord); - await human.warmup(); - await main(); -} -window.onload = init; +import*as S from"../../dist/human.esm.js";var l,L="human",f="person",v=(...a)=>console.log("indexdb",...a);async function h(){return l?!0:new Promise(a=>{let n=indexedDB.open(L,1);n.onerror=o=>v("error:",o),n.onupgradeneeded=o=>{v("create:",o.target),l=o.target.result,l.createObjectStore(f,{keyPath:"id",autoIncrement:!0})},n.onsuccess=o=>{l=o.target.result,v("open:",l),a(!0)}})}async function C(){let a=[];return l||await h(),new Promise(n=>{let o=l.transaction([f],"readwrite").objectStore(f).openCursor(null,"next");o.onerror=i=>v("load error:",i),o.onsuccess=i=>{i.target.result?(a.push(i.target.result.value),i.target.result.continue()):n(a)}})}async function b(){return l||await h(),new Promise(a=>{let n=l.transaction([f],"readwrite").objectStore(f).count();n.onerror=o=>v("count error:",o),n.onsuccess=()=>a(n.result)})}async function x(a){l||await h();let n={name:a.name,descriptor:a.descriptor,image:a.image};l.transaction([f],"readwrite").objectStore(f).put(n),v("save:",n)}async function D(a){l||await h(),l.transaction([f],"readwrite").objectStore(f).delete(a.id),v("delete:",a)}var g={cacheSensitivity:0,modelBasePath:"../../models",filter:{enabled:!0,equalization:!0},debug:!0,face:{enabled:!0,detector:{rotation:!0,return:!0,mask:!1},description:{enabled:!0},iris:{enabled:!0},emotion:{enabled:!1},antispoof:{enabled:!0},liveness:{enabled:!0}},body:{enabled:!1},hand:{enabled:!1},object:{enabled:!1},gesture:{enabled:!0}},B={order:2,multiplier:25,min:.2,max:.8},r={minConfidence:.6,minSize:224,maxTime:3e4,blinkMin:10,blinkMax:800,threshold:.5,distanceMin:.4,distanceMax:1,mask:g.face.detector.mask,rotation:g.face.detector.rotation,...B},e={faceCount:{status:!1,val:0},faceConfidence:{status:!1,val:0},facingCenter:{status:!1,val:0},lookingCenter:{status:!1,val:0},blinkDetected:{status:!1,val:0},faceSize:{status:!1,val:0},antispoofCheck:{status:!1,val:0},livenessCheck:{status:!1,val:0},distance:{status:!1,val:0},age:{status:!1,val:0},gender:{status:!1,val:0},timeout:{status:!0,val:0},descriptor:{status:!1,val:0},elapsedMs:{status:void 0,val:0},detectFPS:{status:void 0,val:0},drawFPS:{status:void 0,val:0}},E=()=>e.faceCount.status&&e.faceSize.status&&e.blinkDetected.status&&e.facingCenter.status&&e.lookingCenter.status&&e.faceConfidence.status&&e.antispoofCheck.status&&e.livenessCheck.status&&e.distance.status&&e.descriptor.status&&e.age.status&&e.gender.status,c={face:null,record:null},u={start:0,end:0,time:0},s=new S.Human(g);s.env.perfadd=!1;s.draw.options.font='small-caps 18px "Lato"';s.draw.options.lineHeight=20;var t={video:document.getElementById("video"),canvas:document.getElementById("canvas"),log:document.getElementById("log"),fps:document.getElementById("fps"),match:document.getElementById("match"),name:document.getElementById("name"),save:document.getElementById("save"),delete:document.getElementById("delete"),retry:document.getElementById("retry"),source:document.getElementById("source"),ok:document.getElementById("ok")},y={detect:0,draw:0},I=0,d=(...a)=>{t.log.innerText+=a.join(" ")+` +`,console.log(...a)};async function H(){let a={audio:!1,video:{facingMode:"user",resizeMode:"none",width:{ideal:document.body.clientWidth}}},n=await navigator.mediaDevices.getUserMedia(a),o=new Promise(i=>{t.video.onloadeddata=()=>i(!0)});t.video.srcObject=n,t.video.play(),await o,t.canvas.width=t.video.videoWidth,t.canvas.height=t.video.videoHeight,t.canvas.style.width="50%",t.canvas.style.height="50%",s.env.initial&&d("video:",t.video.videoWidth,t.video.videoHeight,"|",n.getVideoTracks()[0].label),t.canvas.onclick=()=>{t.video.paused?t.video.play():t.video.pause()}}async function T(){var a;if(!t.video.paused){(a=c.face)!=null&&a.tensor&&s.tf.dispose(c.face.tensor),await s.detect(t.video);let n=s.now();e.detectFPS.val=Math.round(1e4/(n-y.detect))/10,y.detect=n,requestAnimationFrame(T)}}function z(){let a=32;for(let[n,o]of Object.entries(e)){let i=document.getElementById(`ok-${n}`);i||(i=document.createElement("div"),i.id=`ok-${n}`,i.innerText=n,i.className="ok",i.style.top=`${a}px`,t.ok.appendChild(i)),typeof o.status=="boolean"&&(i.style.backgroundColor=o.status?"lightgreen":"lightcoral");let m=o.status?"ok":"fail";i.innerText=`${n}: ${o.val===0?m:o.val}`,a+=28}}async function R(){var o;let a=s.next(s.result);s.draw.canvas(t.video,t.canvas),await s.draw.all(t.canvas,a);let n=s.now();if(e.drawFPS.val=Math.round(1e4/(n-y.draw))/10,y.draw=n,e.faceCount.val=s.result.face.length,e.faceCount.status=e.faceCount.val===1,e.faceCount.status){let i=Object.values(s.result.gesture).map(m=>m.gesture);(i.includes("blink left eye")||i.includes("blink right eye"))&&(u.start=s.now()),u.start>0&&!i.includes("blink left eye")&&!i.includes("blink right eye")&&(u.end=s.now()),e.blinkDetected.status=e.blinkDetected.status||Math.abs(u.end-u.start)>r.blinkMin&&Math.abs(u.end-u.start)=r.minConfidence,e.antispoofCheck.val=s.result.face[0].real||0,e.antispoofCheck.status=e.antispoofCheck.val>=r.minConfidence,e.livenessCheck.val=s.result.face[0].live||0,e.livenessCheck.status=e.livenessCheck.val>=r.minConfidence,e.faceSize.val=Math.min(s.result.face[0].box[2],s.result.face[0].box[3]),e.faceSize.status=e.faceSize.val>=r.minSize,e.distance.val=s.result.face[0].distance||0,e.distance.status=e.distance.val>=r.distanceMin&&e.distance.val<=r.distanceMax,e.descriptor.val=((o=s.result.face[0].embedding)==null?void 0:o.length)||0,e.descriptor.status=e.descriptor.val>0,e.age.val=s.result.face[0].age||0,e.age.status=e.age.val>0,e.gender.val=s.result.face[0].genderScore||0,e.gender.status=e.gender.val>=r.minConfidence}return e.timeout.status=e.elapsedMs.val<=r.maxTime,z(),E()||!e.timeout.status?(t.video.pause(),s.result.face[0]):(e.elapsedMs.val=Math.trunc(s.now()-I),new Promise(i=>{setTimeout(async()=>{await R(),i(s.result.face[0])},30)}))}async function F(){var a,n,o,i;if(t.name.value.length>0){let m=(a=t.canvas.getContext("2d"))==null?void 0:a.getImageData(0,0,t.canvas.width,t.canvas.height),p={id:0,name:t.name.value,descriptor:(n=c.face)==null?void 0:n.embedding,image:m};await x(p),d("saved face record:",p.name,"descriptor length:",(i=(o=c.face)==null?void 0:o.embedding)==null?void 0:i.length),d("known face records:",await b())}else d("invalid name")}async function j(){c.record&&c.record.id>0&&await D(c.record)}async function $(){var i,m,p,k;if(t.canvas.style.height="",(i=t.canvas.getContext("2d"))==null||i.clearRect(0,0,r.minSize,r.minSize),!((m=c==null?void 0:c.face)!=null&&m.tensor)||!((p=c==null?void 0:c.face)!=null&&p.embedding))return!1;if(console.log("face record:",c.face),d(`detected face: ${c.face.gender} ${c.face.age||0}y distance ${100*(c.face.distance||0)}cm/${Math.round(100*(c.face.distance||0)/2.54)}in`),await s.tf.browser.toPixels(c.face.tensor,t.canvas),await b()===0)return d("face database is empty: nothing to compare face with"),document.body.style.background="black",t.delete.style.display="none",!1;let a=await C(),n=a.map(w=>w.descriptor).filter(w=>w.length>0),o=s.match.find(c.face.embedding,n,B);return c.record=a[o.index]||null,c.record&&(d(`best match: ${c.record.name} | id: ${c.record.id} | similarity: ${Math.round(1e3*o.similarity)/10}%`),t.name.value=c.record.name,t.source.style.display="",(k=t.source.getContext("2d"))==null||k.putImageData(c.record.image,0,0)),document.body.style.background=o.similarity>r.threshold?"darkgreen":"maroon",o.similarity>r.threshold}async function M(){var a,n,o,i;return e.faceCount.status=!1,e.faceConfidence.status=!1,e.facingCenter.status=!1,e.blinkDetected.status=!1,e.faceSize.status=!1,e.antispoofCheck.status=!1,e.livenessCheck.status=!1,e.age.status=!1,e.gender.status=!1,e.elapsedMs.val=0,t.match.style.display="none",t.retry.style.display="none",t.source.style.display="none",t.canvas.style.height="50%",document.body.style.background="black",await H(),await T(),I=s.now(),c.face=await R(),t.canvas.width=((n=(a=c.face)==null?void 0:a.tensor)==null?void 0:n.shape[1])||r.minSize,t.canvas.height=((i=(o=c.face)==null?void 0:o.tensor)==null?void 0:i.shape[0])||r.minSize,t.source.width=t.canvas.width,t.source.height=t.canvas.height,t.canvas.style.width="",t.match.style.display="flex",t.save.style.display="flex",t.delete.style.display="flex",t.retry.style.display="block",E()?$():(d("did not find valid face"),!1)}async function q(){var a,n;d("human version:",s.version,"| tfjs version:",s.tf.version["tfjs-core"]),d("options:",JSON.stringify(r).replace(/{|}|"|\[|\]/g,"").replace(/,/g," ")),d("initializing webcam..."),await H(),d("loading human models..."),await s.load(),d("initializing human..."),d("face embedding model:",g.face.description.enabled?"faceres":"",(a=g.face.mobilefacenet)!=null&&a.enabled?"mobilefacenet":"",(n=g.face.insightface)!=null&&n.enabled?"insightface":""),d("loading face database..."),d("known face records:",await b()),t.retry.addEventListener("click",M),t.save.addEventListener("click",F),t.delete.addEventListener("click",j),await s.warmup(),await M()}window.onload=q; //# sourceMappingURL=index.js.map diff --git a/demo/faceid/index.js.map b/demo/faceid/index.js.map index 12daf6a7..a089c033 100644 --- a/demo/faceid/index.js.map +++ b/demo/faceid/index.js.map @@ -2,6 +2,6 @@ "version": 3, "sources": ["index.ts", "indexdb.ts"], "sourcesContent": ["/**\n * Human demo for browsers\n * @default Human Library\n * @summary \n * @author \n * @copyright \n * @license MIT\n */\n\nimport * as H from '../../dist/human.esm.js'; // equivalent of @vladmandic/Human\nimport * as indexDb from './indexdb'; // methods to deal with indexdb\n\nconst humanConfig = { // user configuration for human, used to fine-tune behavior\n cacheSensitivity: 0,\n modelBasePath: '../../models',\n filter: { enabled: true, equalization: true }, // lets run with histogram equilizer\n debug: true,\n face: {\n enabled: true,\n detector: { rotation: true, return: true, mask: false }, // return tensor is used to get detected face image\n description: { enabled: true }, // default model for face descriptor extraction is faceres\n // mobilefacenet: { enabled: true, modelPath: 'https://vladmandic.github.io/human-models/models/mobilefacenet.json' }, // alternative model\n // insightface: { enabled: true, modelPath: 'https://vladmandic.github.io/insightface/models/insightface-mobilenet-swish.json' }, // alternative model\n iris: { enabled: true }, // needed to determine gaze direction\n emotion: { enabled: false }, // not needed\n antispoof: { enabled: true }, // enable optional antispoof module\n liveness: { enabled: true }, // enable optional liveness module\n },\n body: { enabled: false },\n hand: { enabled: false },\n object: { enabled: false },\n gesture: { enabled: true }, // parses face and iris gestures\n};\n\n// const matchOptions = { order: 2, multiplier: 1000, min: 0.0, max: 1.0 }; // for embedding model\nconst matchOptions = { order: 2, multiplier: 25, min: 0.2, max: 0.8 }; // for faceres model\n\nconst options = {\n minConfidence: 0.6, // overal face confidence for box, face, gender, real, live\n minSize: 224, // min input to face descriptor model before degradation\n maxTime: 30000, // max time before giving up\n blinkMin: 10, // minimum duration of a valid blink\n blinkMax: 800, // maximum duration of a valid blink\n threshold: 0.5, // minimum similarity\n distanceMin: 0.4, // closest that face is allowed to be to the cammera in cm\n distanceMax: 1.0, // farthest that face is allowed to be to the cammera in cm\n mask: humanConfig.face.detector.mask,\n rotation: humanConfig.face.detector.rotation,\n ...matchOptions,\n};\n\nconst ok: Record = { // must meet all rules\n faceCount: { status: false, val: 0 },\n faceConfidence: { status: false, val: 0 },\n facingCenter: { status: false, val: 0 },\n lookingCenter: { status: false, val: 0 },\n blinkDetected: { status: false, val: 0 },\n faceSize: { status: false, val: 0 },\n antispoofCheck: { status: false, val: 0 },\n livenessCheck: { status: false, val: 0 },\n distance: { status: false, val: 0 },\n age: { status: false, val: 0 },\n gender: { status: false, val: 0 },\n timeout: { status: true, val: 0 },\n descriptor: { status: false, val: 0 },\n elapsedMs: { status: undefined, val: 0 }, // total time while waiting for valid face\n detectFPS: { status: undefined, val: 0 }, // mark detection fps performance\n drawFPS: { status: undefined, val: 0 }, // mark redraw fps performance\n};\n\nconst allOk = () => ok.faceCount.status\n && ok.faceSize.status\n && ok.blinkDetected.status\n && ok.facingCenter.status\n && ok.lookingCenter.status\n && ok.faceConfidence.status\n && ok.antispoofCheck.status\n && ok.livenessCheck.status\n && ok.distance.status\n && ok.descriptor.status\n && ok.age.status\n && ok.gender.status;\n\nconst current: { face: H.FaceResult | null, record: indexDb.FaceRecord | null } = { face: null, record: null }; // current face record and matched database record\n\nconst blink = { // internal timers for blink start/end/duration\n start: 0,\n end: 0,\n time: 0,\n};\n\n// let db: Array<{ name: string, source: string, embedding: number[] }> = []; // holds loaded face descriptor database\nconst human = new H.Human(humanConfig); // create instance of human with overrides from user configuration\n\nhuman.env.perfadd = false; // is performance data showing instant or total values\nhuman.draw.options.font = 'small-caps 18px \"Lato\"'; // set font used to draw labels when using draw methods\nhuman.draw.options.lineHeight = 20;\n\nconst dom = { // grab instances of dom objects so we dont have to look them up later\n video: document.getElementById('video') as HTMLVideoElement,\n canvas: document.getElementById('canvas') as HTMLCanvasElement,\n log: document.getElementById('log') as HTMLPreElement,\n fps: document.getElementById('fps') as HTMLPreElement,\n match: document.getElementById('match') as HTMLDivElement,\n name: document.getElementById('name') as HTMLInputElement,\n save: document.getElementById('save') as HTMLSpanElement,\n delete: document.getElementById('delete') as HTMLSpanElement,\n retry: document.getElementById('retry') as HTMLDivElement,\n source: document.getElementById('source') as HTMLCanvasElement,\n ok: document.getElementById('ok') as HTMLDivElement,\n};\nconst timestamp = { detect: 0, draw: 0 }; // holds information used to calculate performance and possible memory leaks\nlet startTime = 0;\n\nconst log = (...msg) => { // helper method to output messages\n dom.log.innerText += msg.join(' ') + '\\n';\n console.log(...msg); // eslint-disable-line no-console\n};\n\nasync function webCam() { // initialize webcam\n // @ts-ignore resizeMode is not yet defined in tslib\n const cameraOptions: MediaStreamConstraints = { audio: false, video: { facingMode: 'user', resizeMode: 'none', width: { ideal: document.body.clientWidth } } };\n const stream: MediaStream = await navigator.mediaDevices.getUserMedia(cameraOptions);\n const ready = new Promise((resolve) => { dom.video.onloadeddata = () => resolve(true); });\n dom.video.srcObject = stream;\n void dom.video.play();\n await ready;\n dom.canvas.width = dom.video.videoWidth;\n dom.canvas.height = dom.video.videoHeight;\n dom.canvas.style.width = '50%';\n dom.canvas.style.height = '50%';\n if (human.env.initial) log('video:', dom.video.videoWidth, dom.video.videoHeight, '|', stream.getVideoTracks()[0].label);\n dom.canvas.onclick = () => { // pause when clicked on screen and resume on next click\n if (dom.video.paused) void dom.video.play();\n else dom.video.pause();\n };\n}\n\nasync function detectionLoop() { // main detection loop\n if (!dom.video.paused) {\n if (current.face?.tensor) human.tf.dispose(current.face.tensor); // dispose previous tensor\n await human.detect(dom.video); // actual detection; were not capturing output in a local variable as it can also be reached via human.result\n const now = human.now();\n ok.detectFPS.val = Math.round(10000 / (now - timestamp.detect)) / 10;\n timestamp.detect = now;\n requestAnimationFrame(detectionLoop); // start new frame immediately\n }\n}\n\nfunction drawValidationTests() {\n let y = 32;\n for (const [key, val] of Object.entries(ok)) {\n let el = document.getElementById(`ok-${key}`);\n if (!el) {\n el = document.createElement('div');\n el.id = `ok-${key}`;\n el.innerText = key;\n el.className = 'ok';\n el.style.top = `${y}px`;\n dom.ok.appendChild(el);\n }\n if (typeof val.status === 'boolean') el.style.backgroundColor = val.status ? 'lightgreen' : 'lightcoral';\n const status = val.status ? 'ok' : 'fail';\n el.innerText = `${key}: ${val.val === 0 ? status : val.val}`;\n y += 28;\n }\n}\n\nasync function validationLoop(): Promise { // main screen refresh loop\n const interpolated = human.next(human.result); // smoothen result using last-known results\n human.draw.canvas(dom.video, dom.canvas); // draw canvas to screen\n await human.draw.all(dom.canvas, interpolated); // draw labels, boxes, lines, etc.\n const now = human.now();\n ok.drawFPS.val = Math.round(10000 / (now - timestamp.draw)) / 10;\n timestamp.draw = now;\n ok.faceCount.val = human.result.face.length;\n ok.faceCount.status = ok.faceCount.val === 1; // must be exactly detected face\n if (ok.faceCount.status) { // skip the rest if no face\n const gestures: string[] = Object.values(human.result.gesture).map((gesture: H.GestureResult) => gesture.gesture); // flatten all gestures\n if (gestures.includes('blink left eye') || gestures.includes('blink right eye')) blink.start = human.now(); // blink starts when eyes get closed\n if (blink.start > 0 && !gestures.includes('blink left eye') && !gestures.includes('blink right eye')) blink.end = human.now(); // if blink started how long until eyes are back open\n ok.blinkDetected.status = ok.blinkDetected.status || (Math.abs(blink.end - blink.start) > options.blinkMin && Math.abs(blink.end - blink.start) < options.blinkMax);\n if (ok.blinkDetected.status && blink.time === 0) blink.time = Math.trunc(blink.end - blink.start);\n ok.facingCenter.status = gestures.includes('facing center');\n ok.lookingCenter.status = gestures.includes('looking center'); // must face camera and look at camera\n ok.faceConfidence.val = human.result.face[0].faceScore || human.result.face[0].boxScore || 0;\n ok.faceConfidence.status = ok.faceConfidence.val >= options.minConfidence;\n ok.antispoofCheck.val = human.result.face[0].real || 0;\n ok.antispoofCheck.status = ok.antispoofCheck.val >= options.minConfidence;\n ok.livenessCheck.val = human.result.face[0].live || 0;\n ok.livenessCheck.status = ok.livenessCheck.val >= options.minConfidence;\n ok.faceSize.val = Math.min(human.result.face[0].box[2], human.result.face[0].box[3]);\n ok.faceSize.status = ok.faceSize.val >= options.minSize;\n ok.distance.val = human.result.face[0].distance || 0;\n ok.distance.status = (ok.distance.val >= options.distanceMin) && (ok.distance.val <= options.distanceMax);\n ok.descriptor.val = human.result.face[0].embedding?.length || 0;\n ok.descriptor.status = ok.descriptor.val > 0;\n ok.age.val = human.result.face[0].age || 0;\n ok.age.status = ok.age.val > 0;\n ok.gender.val = human.result.face[0].genderScore || 0;\n ok.gender.status = ok.gender.val >= options.minConfidence;\n }\n // run again\n ok.timeout.status = ok.elapsedMs.val <= options.maxTime;\n drawValidationTests();\n if (allOk() || !ok.timeout.status) { // all criteria met\n dom.video.pause();\n return human.result.face[0];\n }\n ok.elapsedMs.val = Math.trunc(human.now() - startTime);\n return new Promise((resolve) => {\n setTimeout(async () => {\n await validationLoop(); // run validation loop until conditions are met\n resolve(human.result.face[0]); // recursive promise resolve\n }, 30); // use to slow down refresh from max refresh rate to target of 30 fps\n });\n}\n\nasync function saveRecords() {\n if (dom.name.value.length > 0) {\n const image = dom.canvas.getContext('2d')?.getImageData(0, 0, dom.canvas.width, dom.canvas.height) as ImageData;\n const rec = { id: 0, name: dom.name.value, descriptor: current.face?.embedding as number[], image };\n await indexDb.save(rec);\n log('saved face record:', rec.name, 'descriptor length:', current.face?.embedding?.length);\n log('known face records:', await indexDb.count());\n } else {\n log('invalid name');\n }\n}\n\nasync function deleteRecord() {\n if (current.record && current.record.id > 0) {\n await indexDb.remove(current.record);\n }\n}\n\nasync function detectFace() {\n dom.canvas.style.height = '';\n dom.canvas.getContext('2d')?.clearRect(0, 0, options.minSize, options.minSize);\n if (!current?.face?.tensor || !current?.face?.embedding) return false;\n console.log('face record:', current.face); // eslint-disable-line no-console\n log(`detected face: ${current.face.gender} ${current.face.age || 0}y distance ${100 * (current.face.distance || 0)}cm/${Math.round(100 * (current.face.distance || 0) / 2.54)}in`);\n await human.tf.browser.toPixels(current.face.tensor, dom.canvas);\n if (await indexDb.count() === 0) {\n log('face database is empty: nothing to compare face with');\n document.body.style.background = 'black';\n dom.delete.style.display = 'none';\n return false;\n }\n const db = await indexDb.load();\n const descriptors = db.map((rec) => rec.descriptor).filter((desc) => desc.length > 0);\n const res = human.match.find(current.face.embedding, descriptors, matchOptions);\n current.record = db[res.index] || null;\n if (current.record) {\n log(`best match: ${current.record.name} | id: ${current.record.id} | similarity: ${Math.round(1000 * res.similarity) / 10}%`);\n dom.name.value = current.record.name;\n dom.source.style.display = '';\n dom.source.getContext('2d')?.putImageData(current.record.image, 0, 0);\n }\n document.body.style.background = res.similarity > options.threshold ? 'darkgreen' : 'maroon';\n return res.similarity > options.threshold;\n}\n\nasync function main() { // main entry point\n ok.faceCount.status = false;\n ok.faceConfidence.status = false;\n ok.facingCenter.status = false;\n ok.blinkDetected.status = false;\n ok.faceSize.status = false;\n ok.antispoofCheck.status = false;\n ok.livenessCheck.status = false;\n ok.age.status = false;\n ok.gender.status = false;\n ok.elapsedMs.val = 0;\n dom.match.style.display = 'none';\n dom.retry.style.display = 'none';\n dom.source.style.display = 'none';\n dom.canvas.style.height = '50%';\n document.body.style.background = 'black';\n await webCam();\n await detectionLoop(); // start detection loop\n startTime = human.now();\n current.face = await validationLoop(); // start validation loop\n dom.canvas.width = current.face?.tensor?.shape[1] || options.minSize;\n dom.canvas.height = current.face?.tensor?.shape[0] || options.minSize;\n dom.source.width = dom.canvas.width;\n dom.source.height = dom.canvas.height;\n dom.canvas.style.width = '';\n dom.match.style.display = 'flex';\n dom.save.style.display = 'flex';\n dom.delete.style.display = 'flex';\n dom.retry.style.display = 'block';\n if (!allOk()) { // is all criteria met?\n log('did not find valid face');\n return false;\n }\n return detectFace();\n}\n\nasync function init() {\n log('human version:', human.version, '| tfjs version:', human.tf.version['tfjs-core']);\n log('options:', JSON.stringify(options).replace(/{|}|\"|\\[|\\]/g, '').replace(/,/g, ' '));\n log('initializing webcam...');\n await webCam(); // start webcam\n log('loading human models...');\n await human.load(); // preload all models\n log('initializing human...');\n log('face embedding model:', humanConfig.face.description.enabled ? 'faceres' : '', humanConfig.face['mobilefacenet']?.enabled ? 'mobilefacenet' : '', humanConfig.face['insightface']?.enabled ? 'insightface' : '');\n log('loading face database...');\n log('known face records:', await indexDb.count());\n dom.retry.addEventListener('click', main);\n dom.save.addEventListener('click', saveRecords);\n dom.delete.addEventListener('click', deleteRecord);\n await human.warmup(); // warmup function to initialize backend for future faster detection\n await main();\n}\n\nwindow.onload = init;\n", "let db: IDBDatabase; // instance of indexdb\n\nconst database = 'human';\nconst table = 'person';\n\nexport interface FaceRecord { id: number, name: string, descriptor: number[], image: ImageData }\n\nconst log = (...msg) => console.log('indexdb', ...msg); // eslint-disable-line no-console\n\nexport async function open() {\n if (db) return true;\n return new Promise((resolve) => {\n const request: IDBOpenDBRequest = indexedDB.open(database, 1);\n request.onerror = (evt) => log('error:', evt);\n request.onupgradeneeded = (evt: IDBVersionChangeEvent) => { // create if doesnt exist\n log('create:', evt.target);\n db = (evt.target as IDBOpenDBRequest).result;\n db.createObjectStore(table, { keyPath: 'id', autoIncrement: true });\n };\n request.onsuccess = (evt) => { // open\n db = (evt.target as IDBOpenDBRequest).result;\n log('open:', db);\n resolve(true);\n };\n });\n}\n\nexport async function load(): Promise {\n const faceDB: FaceRecord[] = [];\n if (!db) await open(); // open or create if not already done\n return new Promise((resolve) => {\n const cursor: IDBRequest = db.transaction([table], 'readwrite').objectStore(table).openCursor(null, 'next');\n cursor.onerror = (evt) => log('load error:', evt);\n cursor.onsuccess = (evt) => {\n if ((evt.target as IDBRequest).result) {\n faceDB.push((evt.target as IDBRequest).result.value);\n (evt.target as IDBRequest).result.continue();\n } else {\n resolve(faceDB);\n }\n };\n });\n}\n\nexport async function count(): Promise {\n if (!db) await open(); // open or create if not already done\n return new Promise((resolve) => {\n const store: IDBRequest = db.transaction([table], 'readwrite').objectStore(table).count();\n store.onerror = (evt) => log('count error:', evt);\n store.onsuccess = () => resolve(store.result);\n });\n}\n\nexport async function save(faceRecord: FaceRecord) {\n if (!db) await open(); // open or create if not already done\n const newRecord = { name: faceRecord.name, descriptor: faceRecord.descriptor, image: faceRecord.image }; // omit id as its autoincrement\n db.transaction([table], 'readwrite').objectStore(table).put(newRecord);\n log('save:', newRecord);\n}\n\nexport async function remove(faceRecord: FaceRecord) {\n if (!db) await open(); // open or create if not already done\n db.transaction([table], 'readwrite').objectStore(table).delete(faceRecord.id); // delete based on id\n log('delete:', faceRecord);\n}\n"], - "mappings": ";;;;;;;;AASA,YAAY,OAAO;;;ACTnB,IAAI;AAEJ,IAAM,WAAW;AACjB,IAAM,QAAQ;AAId,IAAM,MAAM,IAAI,QAAQ,QAAQ,IAAI,WAAW,GAAG,GAAG;AAErD,eAAsB,OAAO;AAC3B,MAAI;AAAI,WAAO;AACf,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,UAA4B,UAAU,KAAK,UAAU,CAAC;AAC5D,YAAQ,UAAU,CAAC,QAAQ,IAAI,UAAU,GAAG;AAC5C,YAAQ,kBAAkB,CAAC,QAA+B;AACxD,UAAI,WAAW,IAAI,MAAM;AACzB,WAAM,IAAI,OAA4B;AACtC,SAAG,kBAAkB,OAAO,EAAE,SAAS,MAAM,eAAe,KAAK,CAAC;AAAA,IACpE;AACA,YAAQ,YAAY,CAAC,QAAQ;AAC3B,WAAM,IAAI,OAA4B;AACtC,UAAI,SAAS,EAAE;AACf,cAAQ,IAAI;AAAA,IACd;AAAA,EACF,CAAC;AACH;AAEA,eAAsB,OAA8B;AAClD,QAAM,SAAuB,CAAC;AAC9B,MAAI,CAAC;AAAI,UAAM,KAAK;AACpB,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,SAAqB,GAAG,YAAY,CAAC,KAAK,GAAG,WAAW,EAAE,YAAY,KAAK,EAAE,WAAW,MAAM,MAAM;AAC1G,WAAO,UAAU,CAAC,QAAQ,IAAI,eAAe,GAAG;AAChD,WAAO,YAAY,CAAC,QAAQ;AAC1B,UAAK,IAAI,OAAsB,QAAQ;AACrC,eAAO,KAAM,IAAI,OAAsB,OAAO,KAAK;AACnD,QAAC,IAAI,OAAsB,OAAO,SAAS;AAAA,MAC7C,OAAO;AACL,gBAAQ,MAAM;AAAA,MAChB;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA,eAAsB,QAAyB;AAC7C,MAAI,CAAC;AAAI,UAAM,KAAK;AACpB,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,QAAoB,GAAG,YAAY,CAAC,KAAK,GAAG,WAAW,EAAE,YAAY,KAAK,EAAE,MAAM;AACxF,UAAM,UAAU,CAAC,QAAQ,IAAI,gBAAgB,GAAG;AAChD,UAAM,YAAY,MAAM,QAAQ,MAAM,MAAM;AAAA,EAC9C,CAAC;AACH;AAEA,eAAsB,KAAK,YAAwB;AACjD,MAAI,CAAC;AAAI,UAAM,KAAK;AACpB,QAAM,YAAY,EAAE,MAAM,WAAW,MAAM,YAAY,WAAW,YAAY,OAAO,WAAW,MAAM;AACtG,KAAG,YAAY,CAAC,KAAK,GAAG,WAAW,EAAE,YAAY,KAAK,EAAE,IAAI,SAAS;AACrE,MAAI,SAAS,SAAS;AACxB;AAEA,eAAsB,OAAO,YAAwB;AACnD,MAAI,CAAC;AAAI,UAAM,KAAK;AACpB,KAAG,YAAY,CAAC,KAAK,GAAG,WAAW,EAAE,YAAY,KAAK,EAAE,OAAO,WAAW,EAAE;AAC5E,MAAI,WAAW,UAAU;AAC3B;;;ADpDA,IAAM,cAAc;AAAA,EAClB,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,QAAQ,EAAE,SAAS,MAAM,cAAc,KAAK;AAAA,EAC5C,OAAO;AAAA,EACP,MAAM;AAAA,IACJ,SAAS;AAAA,IACT,UAAU,EAAE,UAAU,MAAM,QAAQ,MAAM,MAAM,MAAM;AAAA,IACtD,aAAa,EAAE,SAAS,KAAK;AAAA,IAG7B,MAAM,EAAE,SAAS,KAAK;AAAA,IACtB,SAAS,EAAE,SAAS,MAAM;AAAA,IAC1B,WAAW,EAAE,SAAS,KAAK;AAAA,IAC3B,UAAU,EAAE,SAAS,KAAK;AAAA,EAC5B;AAAA,EACA,MAAM,EAAE,SAAS,MAAM;AAAA,EACvB,MAAM,EAAE,SAAS,MAAM;AAAA,EACvB,QAAQ,EAAE,SAAS,MAAM;AAAA,EACzB,SAAS,EAAE,SAAS,KAAK;AAC3B;AAGA,IAAM,eAAe,EAAE,OAAO,GAAG,YAAY,IAAI,KAAK,KAAK,KAAK,IAAI;AAEpE,IAAM,UAAU;AAAA,EACd,eAAe;AAAA,EACf,SAAS;AAAA,EACT,SAAS;AAAA,EACT,UAAU;AAAA,EACV,UAAU;AAAA,EACV,WAAW;AAAA,EACX,aAAa;AAAA,EACb,aAAa;AAAA,EACb,MAAM,YAAY,KAAK,SAAS;AAAA,EAChC,UAAU,YAAY,KAAK,SAAS;AAAA,EACpC,GAAG;AACL;AAEA,IAAM,KAAmE;AAAA,EACvE,WAAW,EAAE,QAAQ,OAAO,KAAK,EAAE;AAAA,EACnC,gBAAgB,EAAE,QAAQ,OAAO,KAAK,EAAE;AAAA,EACxC,cAAc,EAAE,QAAQ,OAAO,KAAK,EAAE;AAAA,EACtC,eAAe,EAAE,QAAQ,OAAO,KAAK,EAAE;AAAA,EACvC,eAAe,EAAE,QAAQ,OAAO,KAAK,EAAE;AAAA,EACvC,UAAU,EAAE,QAAQ,OAAO,KAAK,EAAE;AAAA,EAClC,gBAAgB,EAAE,QAAQ,OAAO,KAAK,EAAE;AAAA,EACxC,eAAe,EAAE,QAAQ,OAAO,KAAK,EAAE;AAAA,EACvC,UAAU,EAAE,QAAQ,OAAO,KAAK,EAAE;AAAA,EAClC,KAAK,EAAE,QAAQ,OAAO,KAAK,EAAE;AAAA,EAC7B,QAAQ,EAAE,QAAQ,OAAO,KAAK,EAAE;AAAA,EAChC,SAAS,EAAE,QAAQ,MAAM,KAAK,EAAE;AAAA,EAChC,YAAY,EAAE,QAAQ,OAAO,KAAK,EAAE;AAAA,EACpC,WAAW,EAAE,QAAQ,QAAW,KAAK,EAAE;AAAA,EACvC,WAAW,EAAE,QAAQ,QAAW,KAAK,EAAE;AAAA,EACvC,SAAS,EAAE,QAAQ,QAAW,KAAK,EAAE;AACvC;AAEA,IAAM,QAAQ,MAAM,GAAG,UAAU,UAC5B,GAAG,SAAS,UACZ,GAAG,cAAc,UACjB,GAAG,aAAa,UAChB,GAAG,cAAc,UACjB,GAAG,eAAe,UAClB,GAAG,eAAe,UAClB,GAAG,cAAc,UACjB,GAAG,SAAS,UACZ,GAAG,WAAW,UACd,GAAG,IAAI,UACP,GAAG,OAAO;AAEf,IAAM,UAA4E,EAAE,MAAM,MAAM,QAAQ,KAAK;AAE7G,IAAM,QAAQ;AAAA,EACZ,OAAO;AAAA,EACP,KAAK;AAAA,EACL,MAAM;AACR;AAGA,IAAM,QAAQ,IAAM,QAAM,WAAW;AAErC,MAAM,IAAI,UAAU;AACpB,MAAM,KAAK,QAAQ,OAAO;AAC1B,MAAM,KAAK,QAAQ,aAAa;AAEhC,IAAM,MAAM;AAAA,EACV,OAAO,SAAS,eAAe,OAAO;AAAA,EACtC,QAAQ,SAAS,eAAe,QAAQ;AAAA,EACxC,KAAK,SAAS,eAAe,KAAK;AAAA,EAClC,KAAK,SAAS,eAAe,KAAK;AAAA,EAClC,OAAO,SAAS,eAAe,OAAO;AAAA,EACtC,MAAM,SAAS,eAAe,MAAM;AAAA,EACpC,MAAM,SAAS,eAAe,MAAM;AAAA,EACpC,QAAQ,SAAS,eAAe,QAAQ;AAAA,EACxC,OAAO,SAAS,eAAe,OAAO;AAAA,EACtC,QAAQ,SAAS,eAAe,QAAQ;AAAA,EACxC,IAAI,SAAS,eAAe,IAAI;AAClC;AACA,IAAM,YAAY,EAAE,QAAQ,GAAG,MAAM,EAAE;AACvC,IAAI,YAAY;AAEhB,IAAMA,OAAM,IAAI,QAAQ;AACtB,MAAI,IAAI,aAAa,IAAI,KAAK,GAAG,IAAI;AACrC,UAAQ,IAAI,GAAG,GAAG;AACpB;AAEA,eAAe,SAAS;AAEtB,QAAM,gBAAwC,EAAE,OAAO,OAAO,OAAO,EAAE,YAAY,QAAQ,YAAY,QAAQ,OAAO,EAAE,OAAO,SAAS,KAAK,YAAY,EAAE,EAAE;AAC7J,QAAM,SAAsB,MAAM,UAAU,aAAa,aAAa,aAAa;AACnF,QAAM,QAAQ,IAAI,QAAQ,CAAC,YAAY;AAAE,QAAI,MAAM,eAAe,MAAM,QAAQ,IAAI;AAAA,EAAG,CAAC;AACxF,MAAI,MAAM,YAAY;AACtB,OAAK,IAAI,MAAM,KAAK;AACpB,QAAM;AACN,MAAI,OAAO,QAAQ,IAAI,MAAM;AAC7B,MAAI,OAAO,SAAS,IAAI,MAAM;AAC9B,MAAI,OAAO,MAAM,QAAQ;AACzB,MAAI,OAAO,MAAM,SAAS;AAC1B,MAAI,MAAM,IAAI;AAAS,IAAAA,KAAI,UAAU,IAAI,MAAM,YAAY,IAAI,MAAM,aAAa,KAAK,OAAO,eAAe,EAAE,GAAG,KAAK;AACvH,MAAI,OAAO,UAAU,MAAM;AACzB,QAAI,IAAI,MAAM;AAAQ,WAAK,IAAI,MAAM,KAAK;AAAA;AACrC,UAAI,MAAM,MAAM;AAAA,EACvB;AACF;AAEA,eAAe,gBAAgB;AA1I/B;AA2IE,MAAI,CAAC,IAAI,MAAM,QAAQ;AACrB,SAAI,aAAQ,SAAR,mBAAc;AAAQ,YAAM,GAAG,QAAQ,QAAQ,KAAK,MAAM;AAC9D,UAAM,MAAM,OAAO,IAAI,KAAK;AAC5B,UAAM,MAAM,MAAM,IAAI;AACtB,OAAG,UAAU,MAAM,KAAK,MAAM,OAAS,MAAM,UAAU,OAAO,IAAI;AAClE,cAAU,SAAS;AACnB,0BAAsB,aAAa;AAAA,EACrC;AACF;AAEA,SAAS,sBAAsB;AAC7B,MAAI,IAAI;AACR,aAAW,CAAC,KAAK,GAAG,KAAK,OAAO,QAAQ,EAAE,GAAG;AAC3C,QAAI,KAAK,SAAS,eAAe,MAAM,KAAK;AAC5C,QAAI,CAAC,IAAI;AACP,WAAK,SAAS,cAAc,KAAK;AACjC,SAAG,KAAK,MAAM;AACd,SAAG,YAAY;AACf,SAAG,YAAY;AACf,SAAG,MAAM,MAAM,GAAG;AAClB,UAAI,GAAG,YAAY,EAAE;AAAA,IACvB;AACA,QAAI,OAAO,IAAI,WAAW;AAAW,SAAG,MAAM,kBAAkB,IAAI,SAAS,eAAe;AAC5F,UAAM,SAAS,IAAI,SAAS,OAAO;AACnC,OAAG,YAAY,GAAG,QAAQ,IAAI,QAAQ,IAAI,SAAS,IAAI;AACvD,SAAK;AAAA,EACP;AACF;AAEA,eAAe,iBAAwC;AAxKvD;AAyKE,QAAM,eAAe,MAAM,KAAK,MAAM,MAAM;AAC5C,QAAM,KAAK,OAAO,IAAI,OAAO,IAAI,MAAM;AACvC,QAAM,MAAM,KAAK,IAAI,IAAI,QAAQ,YAAY;AAC7C,QAAM,MAAM,MAAM,IAAI;AACtB,KAAG,QAAQ,MAAM,KAAK,MAAM,OAAS,MAAM,UAAU,KAAK,IAAI;AAC9D,YAAU,OAAO;AACjB,KAAG,UAAU,MAAM,MAAM,OAAO,KAAK;AACrC,KAAG,UAAU,SAAS,GAAG,UAAU,QAAQ;AAC3C,MAAI,GAAG,UAAU,QAAQ;AACvB,UAAM,WAAqB,OAAO,OAAO,MAAM,OAAO,OAAO,EAAE,IAAI,CAAC,YAA6B,QAAQ,OAAO;AAChH,QAAI,SAAS,SAAS,gBAAgB,KAAK,SAAS,SAAS,iBAAiB;AAAG,YAAM,QAAQ,MAAM,IAAI;AACzG,QAAI,MAAM,QAAQ,KAAK,CAAC,SAAS,SAAS,gBAAgB,KAAK,CAAC,SAAS,SAAS,iBAAiB;AAAG,YAAM,MAAM,MAAM,IAAI;AAC5H,OAAG,cAAc,SAAS,GAAG,cAAc,UAAW,KAAK,IAAI,MAAM,MAAM,MAAM,KAAK,IAAI,QAAQ,YAAY,KAAK,IAAI,MAAM,MAAM,MAAM,KAAK,IAAI,QAAQ;AAC1J,QAAI,GAAG,cAAc,UAAU,MAAM,SAAS;AAAG,YAAM,OAAO,KAAK,MAAM,MAAM,MAAM,MAAM,KAAK;AAChG,OAAG,aAAa,SAAS,SAAS,SAAS,eAAe;AAC1D,OAAG,cAAc,SAAS,SAAS,SAAS,gBAAgB;AAC5D,OAAG,eAAe,MAAM,MAAM,OAAO,KAAK,GAAG,aAAa,MAAM,OAAO,KAAK,GAAG,YAAY;AAC3F,OAAG,eAAe,SAAS,GAAG,eAAe,OAAO,QAAQ;AAC5D,OAAG,eAAe,MAAM,MAAM,OAAO,KAAK,GAAG,QAAQ;AACrD,OAAG,eAAe,SAAS,GAAG,eAAe,OAAO,QAAQ;AAC5D,OAAG,cAAc,MAAM,MAAM,OAAO,KAAK,GAAG,QAAQ;AACpD,OAAG,cAAc,SAAS,GAAG,cAAc,OAAO,QAAQ;AAC1D,OAAG,SAAS,MAAM,KAAK,IAAI,MAAM,OAAO,KAAK,GAAG,IAAI,IAAI,MAAM,OAAO,KAAK,GAAG,IAAI,EAAE;AACnF,OAAG,SAAS,SAAS,GAAG,SAAS,OAAO,QAAQ;AAChD,OAAG,SAAS,MAAM,MAAM,OAAO,KAAK,GAAG,YAAY;AACnD,OAAG,SAAS,SAAU,GAAG,SAAS,OAAO,QAAQ,eAAiB,GAAG,SAAS,OAAO,QAAQ;AAC7F,OAAG,WAAW,QAAM,WAAM,OAAO,KAAK,GAAG,cAArB,mBAAgC,WAAU;AAC9D,OAAG,WAAW,SAAS,GAAG,WAAW,MAAM;AAC3C,OAAG,IAAI,MAAM,MAAM,OAAO,KAAK,GAAG,OAAO;AACzC,OAAG,IAAI,SAAS,GAAG,IAAI,MAAM;AAC7B,OAAG,OAAO,MAAM,MAAM,OAAO,KAAK,GAAG,eAAe;AACpD,OAAG,OAAO,SAAS,GAAG,OAAO,OAAO,QAAQ;AAAA,EAC9C;AAEA,KAAG,QAAQ,SAAS,GAAG,UAAU,OAAO,QAAQ;AAChD,sBAAoB;AACpB,MAAI,MAAM,KAAK,CAAC,GAAG,QAAQ,QAAQ;AACjC,QAAI,MAAM,MAAM;AAChB,WAAO,MAAM,OAAO,KAAK;AAAA,EAC3B;AACA,KAAG,UAAU,MAAM,KAAK,MAAM,MAAM,IAAI,IAAI,SAAS;AACrD,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,eAAW,YAAY;AACrB,YAAM,eAAe;AACrB,cAAQ,MAAM,OAAO,KAAK,EAAE;AAAA,IAC9B,GAAG,EAAE;AAAA,EACP,CAAC;AACH;AAEA,eAAe,cAAc;AA1N7B;AA2NE,MAAI,IAAI,KAAK,MAAM,SAAS,GAAG;AAC7B,UAAM,SAAQ,SAAI,OAAO,WAAW,IAAI,MAA1B,mBAA6B,aAAa,GAAG,GAAG,IAAI,OAAO,OAAO,IAAI,OAAO;AAC3F,UAAM,MAAM,EAAE,IAAI,GAAG,MAAM,IAAI,KAAK,OAAO,aAAY,aAAQ,SAAR,mBAAc,WAAuB,MAAM;AAClG,UAAc,KAAK,GAAG;AACtB,IAAAA,KAAI,sBAAsB,IAAI,MAAM,uBAAsB,mBAAQ,SAAR,mBAAc,cAAd,mBAAyB,MAAM;AACzF,IAAAA,KAAI,uBAAuB,MAAc,MAAM,CAAC;AAAA,EAClD,OAAO;AACL,IAAAA,KAAI,cAAc;AAAA,EACpB;AACF;AAEA,eAAe,eAAe;AAC5B,MAAI,QAAQ,UAAU,QAAQ,OAAO,KAAK,GAAG;AAC3C,UAAc,OAAO,QAAQ,MAAM;AAAA,EACrC;AACF;AAEA,eAAe,aAAa;AA5O5B;AA6OE,MAAI,OAAO,MAAM,SAAS;AAC1B,YAAI,OAAO,WAAW,IAAI,MAA1B,mBAA6B,UAAU,GAAG,GAAG,QAAQ,SAAS,QAAQ;AACtE,MAAI,GAAC,wCAAS,SAAT,mBAAe,WAAU,GAAC,wCAAS,SAAT,mBAAe;AAAW,WAAO;AAChE,UAAQ,IAAI,gBAAgB,QAAQ,IAAI;AACxC,EAAAA,KAAI,kBAAkB,QAAQ,KAAK,UAAU,QAAQ,KAAK,OAAO,eAAe,OAAO,QAAQ,KAAK,YAAY,QAAQ,KAAK,MAAM,OAAO,QAAQ,KAAK,YAAY,KAAK,IAAI,KAAK;AACjL,QAAM,MAAM,GAAG,QAAQ,SAAS,QAAQ,KAAK,QAAQ,IAAI,MAAM;AAC/D,MAAI,MAAc,MAAM,MAAM,GAAG;AAC/B,IAAAA,KAAI,sDAAsD;AAC1D,aAAS,KAAK,MAAM,aAAa;AACjC,QAAI,OAAO,MAAM,UAAU;AAC3B,WAAO;AAAA,EACT;AACA,QAAMC,MAAK,MAAc,KAAK;AAC9B,QAAM,cAAcA,IAAG,IAAI,CAAC,QAAQ,IAAI,UAAU,EAAE,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC;AACpF,QAAM,MAAM,MAAM,MAAM,KAAK,QAAQ,KAAK,WAAW,aAAa,YAAY;AAC9E,UAAQ,SAASA,IAAG,IAAI,UAAU;AAClC,MAAI,QAAQ,QAAQ;AAClB,IAAAD,KAAI,eAAe,QAAQ,OAAO,cAAc,QAAQ,OAAO,oBAAoB,KAAK,MAAM,MAAO,IAAI,UAAU,IAAI,KAAK;AAC5H,QAAI,KAAK,QAAQ,QAAQ,OAAO;AAChC,QAAI,OAAO,MAAM,UAAU;AAC3B,cAAI,OAAO,WAAW,IAAI,MAA1B,mBAA6B,aAAa,QAAQ,OAAO,OAAO,GAAG;AAAA,EACrE;AACA,WAAS,KAAK,MAAM,aAAa,IAAI,aAAa,QAAQ,YAAY,cAAc;AACpF,SAAO,IAAI,aAAa,QAAQ;AAClC;AAEA,eAAe,OAAO;AAvQtB;AAwQE,KAAG,UAAU,SAAS;AACtB,KAAG,eAAe,SAAS;AAC3B,KAAG,aAAa,SAAS;AACzB,KAAG,cAAc,SAAS;AAC1B,KAAG,SAAS,SAAS;AACrB,KAAG,eAAe,SAAS;AAC3B,KAAG,cAAc,SAAS;AAC1B,KAAG,IAAI,SAAS;AAChB,KAAG,OAAO,SAAS;AACnB,KAAG,UAAU,MAAM;AACnB,MAAI,MAAM,MAAM,UAAU;AAC1B,MAAI,MAAM,MAAM,UAAU;AAC1B,MAAI,OAAO,MAAM,UAAU;AAC3B,MAAI,OAAO,MAAM,SAAS;AAC1B,WAAS,KAAK,MAAM,aAAa;AACjC,QAAM,OAAO;AACb,QAAM,cAAc;AACpB,cAAY,MAAM,IAAI;AACtB,UAAQ,OAAO,MAAM,eAAe;AACpC,MAAI,OAAO,UAAQ,mBAAQ,SAAR,mBAAc,WAAd,mBAAsB,MAAM,OAAM,QAAQ;AAC7D,MAAI,OAAO,WAAS,mBAAQ,SAAR,mBAAc,WAAd,mBAAsB,MAAM,OAAM,QAAQ;AAC9D,MAAI,OAAO,QAAQ,IAAI,OAAO;AAC9B,MAAI,OAAO,SAAS,IAAI,OAAO;AAC/B,MAAI,OAAO,MAAM,QAAQ;AACzB,MAAI,MAAM,MAAM,UAAU;AAC1B,MAAI,KAAK,MAAM,UAAU;AACzB,MAAI,OAAO,MAAM,UAAU;AAC3B,MAAI,MAAM,MAAM,UAAU;AAC1B,MAAI,CAAC,MAAM,GAAG;AACZ,IAAAA,KAAI,yBAAyB;AAC7B,WAAO;AAAA,EACT;AACA,SAAO,WAAW;AACpB;AAEA,eAAe,OAAO;AA3StB;AA4SE,EAAAA,KAAI,kBAAkB,MAAM,SAAS,mBAAmB,MAAM,GAAG,QAAQ,YAAY;AACrF,EAAAA,KAAI,YAAY,KAAK,UAAU,OAAO,EAAE,QAAQ,gBAAgB,EAAE,EAAE,QAAQ,MAAM,GAAG,CAAC;AACtF,EAAAA,KAAI,wBAAwB;AAC5B,QAAM,OAAO;AACb,EAAAA,KAAI,yBAAyB;AAC7B,QAAM,MAAM,KAAK;AACjB,EAAAA,KAAI,uBAAuB;AAC3B,EAAAA,KAAI,yBAAyB,YAAY,KAAK,YAAY,UAAU,YAAY,MAAI,iBAAY,KAAK,qBAAjB,mBAAmC,WAAU,kBAAkB,MAAI,iBAAY,KAAK,mBAAjB,mBAAiC,WAAU,gBAAgB,EAAE;AACpN,EAAAA,KAAI,0BAA0B;AAC9B,EAAAA,KAAI,uBAAuB,MAAc,MAAM,CAAC;AAChD,MAAI,MAAM,iBAAiB,SAAS,IAAI;AACxC,MAAI,KAAK,iBAAiB,SAAS,WAAW;AAC9C,MAAI,OAAO,iBAAiB,SAAS,YAAY;AACjD,QAAM,MAAM,OAAO;AACnB,QAAM,KAAK;AACb;AAEA,OAAO,SAAS;", - "names": ["log", "db"] + "mappings": ";;;;;;AASA,UAAYA,MAAO,0BCTnB,IAAIC,EAEEC,EAAW,QACXC,EAAQ,SAIRC,EAAM,IAAIC,IAAQ,QAAQ,IAAI,UAAW,GAAGA,CAAG,EAErD,eAAsBC,GAAO,CAC3B,OAAIL,EAAW,GACR,IAAI,QAASM,GAAY,CAC9B,IAAMC,EAA4B,UAAU,KAAKN,EAAU,CAAC,EAC5DM,EAAQ,QAAWC,GAAQL,EAAI,SAAUK,CAAG,EAC5CD,EAAQ,gBAAmBC,GAA+B,CACxDL,EAAI,UAAWK,EAAI,MAAM,EACzBR,EAAMQ,EAAI,OAA4B,OACtCR,EAAG,kBAAkBE,EAAO,CAAE,QAAS,KAAM,cAAe,EAAK,CAAC,CACpE,EACAK,EAAQ,UAAaC,GAAQ,CAC3BR,EAAMQ,EAAI,OAA4B,OACtCL,EAAI,QAASH,CAAE,EACfM,EAAQ,EAAI,CACd,CACF,CAAC,CACH,CAEA,eAAsBG,GAA8B,CAClD,IAAMC,EAAuB,CAAC,EAC9B,OAAKV,GAAI,MAAMK,EAAK,EACb,IAAI,QAASC,GAAY,CAC9B,IAAMK,EAAqBX,EAAG,YAAY,CAACE,CAAK,EAAG,WAAW,EAAE,YAAYA,CAAK,EAAE,WAAW,KAAM,MAAM,EAC1GS,EAAO,QAAWH,GAAQL,EAAI,cAAeK,CAAG,EAChDG,EAAO,UAAaH,GAAQ,CACrBA,EAAI,OAAsB,QAC7BE,EAAO,KAAMF,EAAI,OAAsB,OAAO,KAAK,EAClDA,EAAI,OAAsB,OAAO,SAAS,GAE3CF,EAAQI,CAAM,CAElB,CACF,CAAC,CACH,CAEA,eAAsBE,GAAyB,CAC7C,OAAKZ,GAAI,MAAMK,EAAK,EACb,IAAI,QAASC,GAAY,CAC9B,IAAMO,EAAoBb,EAAG,YAAY,CAACE,CAAK,EAAG,WAAW,EAAE,YAAYA,CAAK,EAAE,MAAM,EACxFW,EAAM,QAAWL,GAAQL,EAAI,eAAgBK,CAAG,EAChDK,EAAM,UAAY,IAAMP,EAAQO,EAAM,MAAM,CAC9C,CAAC,CACH,CAEA,eAAsBC,EAAKC,EAAwB,CAC5Cf,GAAI,MAAMK,EAAK,EACpB,IAAMW,EAAY,CAAE,KAAMD,EAAW,KAAM,WAAYA,EAAW,WAAY,MAAOA,EAAW,KAAM,EACtGf,EAAG,YAAY,CAACE,CAAK,EAAG,WAAW,EAAE,YAAYA,CAAK,EAAE,IAAIc,CAAS,EACrEb,EAAI,QAASa,CAAS,CACxB,CAEA,eAAsBC,EAAOF,EAAwB,CAC9Cf,GAAI,MAAMK,EAAK,EACpBL,EAAG,YAAY,CAACE,CAAK,EAAG,WAAW,EAAE,YAAYA,CAAK,EAAE,OAAOa,EAAW,EAAE,EAC5EZ,EAAI,UAAWY,CAAU,CAC3B,CDpDA,IAAMG,EAAc,CAClB,iBAAkB,EAClB,cAAe,eACf,OAAQ,CAAE,QAAS,GAAM,aAAc,EAAK,EAC5C,MAAO,GACP,KAAM,CACJ,QAAS,GACT,SAAU,CAAE,SAAU,GAAM,OAAQ,GAAM,KAAM,EAAM,EACtD,YAAa,CAAE,QAAS,EAAK,EAG7B,KAAM,CAAE,QAAS,EAAK,EACtB,QAAS,CAAE,QAAS,EAAM,EAC1B,UAAW,CAAE,QAAS,EAAK,EAC3B,SAAU,CAAE,QAAS,EAAK,CAC5B,EACA,KAAM,CAAE,QAAS,EAAM,EACvB,KAAM,CAAE,QAAS,EAAM,EACvB,OAAQ,CAAE,QAAS,EAAM,EACzB,QAAS,CAAE,QAAS,EAAK,CAC3B,EAGMC,EAAe,CAAE,MAAO,EAAG,WAAY,GAAI,IAAK,GAAK,IAAK,EAAI,EAE9DC,EAAU,CACd,cAAe,GACf,QAAS,IACT,QAAS,IACT,SAAU,GACV,SAAU,IACV,UAAW,GACX,YAAa,GACb,YAAa,EACb,KAAMF,EAAY,KAAK,SAAS,KAChC,SAAUA,EAAY,KAAK,SAAS,SACpC,GAAGC,CACL,EAEME,EAAmE,CACvE,UAAW,CAAE,OAAQ,GAAO,IAAK,CAAE,EACnC,eAAgB,CAAE,OAAQ,GAAO,IAAK,CAAE,EACxC,aAAc,CAAE,OAAQ,GAAO,IAAK,CAAE,EACtC,cAAe,CAAE,OAAQ,GAAO,IAAK,CAAE,EACvC,cAAe,CAAE,OAAQ,GAAO,IAAK,CAAE,EACvC,SAAU,CAAE,OAAQ,GAAO,IAAK,CAAE,EAClC,eAAgB,CAAE,OAAQ,GAAO,IAAK,CAAE,EACxC,cAAe,CAAE,OAAQ,GAAO,IAAK,CAAE,EACvC,SAAU,CAAE,OAAQ,GAAO,IAAK,CAAE,EAClC,IAAK,CAAE,OAAQ,GAAO,IAAK,CAAE,EAC7B,OAAQ,CAAE,OAAQ,GAAO,IAAK,CAAE,EAChC,QAAS,CAAE,OAAQ,GAAM,IAAK,CAAE,EAChC,WAAY,CAAE,OAAQ,GAAO,IAAK,CAAE,EACpC,UAAW,CAAE,OAAQ,OAAW,IAAK,CAAE,EACvC,UAAW,CAAE,OAAQ,OAAW,IAAK,CAAE,EACvC,QAAS,CAAE,OAAQ,OAAW,IAAK,CAAE,CACvC,EAEMC,EAAQ,IAAMD,EAAG,UAAU,QAC5BA,EAAG,SAAS,QACZA,EAAG,cAAc,QACjBA,EAAG,aAAa,QAChBA,EAAG,cAAc,QACjBA,EAAG,eAAe,QAClBA,EAAG,eAAe,QAClBA,EAAG,cAAc,QACjBA,EAAG,SAAS,QACZA,EAAG,WAAW,QACdA,EAAG,IAAI,QACPA,EAAG,OAAO,OAETE,EAA4E,CAAE,KAAM,KAAM,OAAQ,IAAK,EAEvGC,EAAQ,CACZ,MAAO,EACP,IAAK,EACL,KAAM,CACR,EAGMC,EAAQ,IAAM,QAAMP,CAAW,EAErCO,EAAM,IAAI,QAAU,GACpBA,EAAM,KAAK,QAAQ,KAAO,yBAC1BA,EAAM,KAAK,QAAQ,WAAa,GAEhC,IAAMC,EAAM,CACV,MAAO,SAAS,eAAe,OAAO,EACtC,OAAQ,SAAS,eAAe,QAAQ,EACxC,IAAK,SAAS,eAAe,KAAK,EAClC,IAAK,SAAS,eAAe,KAAK,EAClC,MAAO,SAAS,eAAe,OAAO,EACtC,KAAM,SAAS,eAAe,MAAM,EACpC,KAAM,SAAS,eAAe,MAAM,EACpC,OAAQ,SAAS,eAAe,QAAQ,EACxC,MAAO,SAAS,eAAe,OAAO,EACtC,OAAQ,SAAS,eAAe,QAAQ,EACxC,GAAI,SAAS,eAAe,IAAI,CAClC,EACMC,EAAY,CAAE,OAAQ,EAAG,KAAM,CAAE,EACnCC,EAAY,EAEVC,EAAM,IAAIC,IAAQ,CACtBJ,EAAI,IAAI,WAAaI,EAAI,KAAK,GAAG,EAAI;AAAA,EACrC,QAAQ,IAAI,GAAGA,CAAG,CACpB,EAEA,eAAeC,GAAS,CAEtB,IAAMC,EAAwC,CAAE,MAAO,GAAO,MAAO,CAAE,WAAY,OAAQ,WAAY,OAAQ,MAAO,CAAE,MAAO,SAAS,KAAK,WAAY,CAAE,CAAE,EACvJC,EAAsB,MAAM,UAAU,aAAa,aAAaD,CAAa,EAC7EE,EAAQ,IAAI,QAASC,GAAY,CAAET,EAAI,MAAM,aAAe,IAAMS,EAAQ,EAAI,CAAG,CAAC,EACxFT,EAAI,MAAM,UAAYO,EACjBP,EAAI,MAAM,KAAK,EACpB,MAAMQ,EACNR,EAAI,OAAO,MAAQA,EAAI,MAAM,WAC7BA,EAAI,OAAO,OAASA,EAAI,MAAM,YAC9BA,EAAI,OAAO,MAAM,MAAQ,MACzBA,EAAI,OAAO,MAAM,OAAS,MACtBD,EAAM,IAAI,SAASI,EAAI,SAAUH,EAAI,MAAM,WAAYA,EAAI,MAAM,YAAa,IAAKO,EAAO,eAAe,EAAE,GAAG,KAAK,EACvHP,EAAI,OAAO,QAAU,IAAM,CACrBA,EAAI,MAAM,OAAaA,EAAI,MAAM,KAAK,EACrCA,EAAI,MAAM,MAAM,CACvB,CACF,CAEA,eAAeU,GAAgB,CA1I/B,IAAAC,EA2IE,GAAI,CAACX,EAAI,MAAM,OAAQ,EACjBW,EAAAd,EAAQ,OAAR,MAAAc,EAAc,QAAQZ,EAAM,GAAG,QAAQF,EAAQ,KAAK,MAAM,EAC9D,MAAME,EAAM,OAAOC,EAAI,KAAK,EAC5B,IAAMY,EAAMb,EAAM,IAAI,EACtBJ,EAAG,UAAU,IAAM,KAAK,MAAM,KAASiB,EAAMX,EAAU,OAAO,EAAI,GAClEA,EAAU,OAASW,EACnB,sBAAsBF,CAAa,CACrC,CACF,CAEA,SAASG,GAAsB,CAC7B,IAAIC,EAAI,GACR,OAAW,CAACC,EAAKC,CAAG,IAAK,OAAO,QAAQrB,CAAE,EAAG,CAC3C,IAAIsB,EAAK,SAAS,eAAe,MAAMF,GAAK,EACvCE,IACHA,EAAK,SAAS,cAAc,KAAK,EACjCA,EAAG,GAAK,MAAMF,IACdE,EAAG,UAAYF,EACfE,EAAG,UAAY,KACfA,EAAG,MAAM,IAAM,GAAGH,MAClBd,EAAI,GAAG,YAAYiB,CAAE,GAEnB,OAAOD,EAAI,QAAW,YAAWC,EAAG,MAAM,gBAAkBD,EAAI,OAAS,aAAe,cAC5F,IAAME,EAASF,EAAI,OAAS,KAAO,OACnCC,EAAG,UAAY,GAAGF,MAAQC,EAAI,MAAQ,EAAIE,EAASF,EAAI,MACvDF,GAAK,EACP,CACF,CAEA,eAAeK,GAAwC,CAxKvD,IAAAR,EAyKE,IAAMS,EAAerB,EAAM,KAAKA,EAAM,MAAM,EAC5CA,EAAM,KAAK,OAAOC,EAAI,MAAOA,EAAI,MAAM,EACvC,MAAMD,EAAM,KAAK,IAAIC,EAAI,OAAQoB,CAAY,EAC7C,IAAMR,EAAMb,EAAM,IAAI,EAKtB,GAJAJ,EAAG,QAAQ,IAAM,KAAK,MAAM,KAASiB,EAAMX,EAAU,KAAK,EAAI,GAC9DA,EAAU,KAAOW,EACjBjB,EAAG,UAAU,IAAMI,EAAM,OAAO,KAAK,OACrCJ,EAAG,UAAU,OAASA,EAAG,UAAU,MAAQ,EACvCA,EAAG,UAAU,OAAQ,CACvB,IAAM0B,EAAqB,OAAO,OAAOtB,EAAM,OAAO,OAAO,EAAE,IAAKuB,GAA6BA,EAAQ,OAAO,GAC5GD,EAAS,SAAS,gBAAgB,GAAKA,EAAS,SAAS,iBAAiB,KAAGvB,EAAM,MAAQC,EAAM,IAAI,GACrGD,EAAM,MAAQ,GAAK,CAACuB,EAAS,SAAS,gBAAgB,GAAK,CAACA,EAAS,SAAS,iBAAiB,IAAGvB,EAAM,IAAMC,EAAM,IAAI,GAC5HJ,EAAG,cAAc,OAASA,EAAG,cAAc,QAAW,KAAK,IAAIG,EAAM,IAAMA,EAAM,KAAK,EAAIJ,EAAQ,UAAY,KAAK,IAAII,EAAM,IAAMA,EAAM,KAAK,EAAIJ,EAAQ,SACtJC,EAAG,cAAc,QAAUG,EAAM,OAAS,IAAGA,EAAM,KAAO,KAAK,MAAMA,EAAM,IAAMA,EAAM,KAAK,GAChGH,EAAG,aAAa,OAAS0B,EAAS,SAAS,eAAe,EAC1D1B,EAAG,cAAc,OAAS0B,EAAS,SAAS,gBAAgB,EAC5D1B,EAAG,eAAe,IAAMI,EAAM,OAAO,KAAK,GAAG,WAAaA,EAAM,OAAO,KAAK,GAAG,UAAY,EAC3FJ,EAAG,eAAe,OAASA,EAAG,eAAe,KAAOD,EAAQ,cAC5DC,EAAG,eAAe,IAAMI,EAAM,OAAO,KAAK,GAAG,MAAQ,EACrDJ,EAAG,eAAe,OAASA,EAAG,eAAe,KAAOD,EAAQ,cAC5DC,EAAG,cAAc,IAAMI,EAAM,OAAO,KAAK,GAAG,MAAQ,EACpDJ,EAAG,cAAc,OAASA,EAAG,cAAc,KAAOD,EAAQ,cAC1DC,EAAG,SAAS,IAAM,KAAK,IAAII,EAAM,OAAO,KAAK,GAAG,IAAI,GAAIA,EAAM,OAAO,KAAK,GAAG,IAAI,EAAE,EACnFJ,EAAG,SAAS,OAASA,EAAG,SAAS,KAAOD,EAAQ,QAChDC,EAAG,SAAS,IAAMI,EAAM,OAAO,KAAK,GAAG,UAAY,EACnDJ,EAAG,SAAS,OAAUA,EAAG,SAAS,KAAOD,EAAQ,aAAiBC,EAAG,SAAS,KAAOD,EAAQ,YAC7FC,EAAG,WAAW,MAAMgB,EAAAZ,EAAM,OAAO,KAAK,GAAG,YAArB,YAAAY,EAAgC,SAAU,EAC9DhB,EAAG,WAAW,OAASA,EAAG,WAAW,IAAM,EAC3CA,EAAG,IAAI,IAAMI,EAAM,OAAO,KAAK,GAAG,KAAO,EACzCJ,EAAG,IAAI,OAASA,EAAG,IAAI,IAAM,EAC7BA,EAAG,OAAO,IAAMI,EAAM,OAAO,KAAK,GAAG,aAAe,EACpDJ,EAAG,OAAO,OAASA,EAAG,OAAO,KAAOD,EAAQ,aAC9C,CAIA,OAFAC,EAAG,QAAQ,OAASA,EAAG,UAAU,KAAOD,EAAQ,QAChDmB,EAAoB,EAChBjB,EAAM,GAAK,CAACD,EAAG,QAAQ,QACzBK,EAAI,MAAM,MAAM,EACTD,EAAM,OAAO,KAAK,KAE3BJ,EAAG,UAAU,IAAM,KAAK,MAAMI,EAAM,IAAI,EAAIG,CAAS,EAC9C,IAAI,QAASO,GAAY,CAC9B,WAAW,SAAY,CACrB,MAAMU,EAAe,EACrBV,EAAQV,EAAM,OAAO,KAAK,EAAE,CAC9B,EAAG,EAAE,CACP,CAAC,EACH,CAEA,eAAewB,GAAc,CA1N7B,IAAAZ,EAAAa,EAAAC,EAAAC,EA2NE,GAAI1B,EAAI,KAAK,MAAM,OAAS,EAAG,CAC7B,IAAM2B,GAAQhB,EAAAX,EAAI,OAAO,WAAW,IAAI,IAA1B,YAAAW,EAA6B,aAAa,EAAG,EAAGX,EAAI,OAAO,MAAOA,EAAI,OAAO,QACrF4B,EAAM,CAAE,GAAI,EAAG,KAAM5B,EAAI,KAAK,MAAO,YAAYwB,EAAA3B,EAAQ,OAAR,YAAA2B,EAAc,UAAuB,MAAAG,CAAM,EAClG,MAAcE,EAAKD,CAAG,EACtBzB,EAAI,qBAAsByB,EAAI,KAAM,sBAAsBF,GAAAD,EAAA5B,EAAQ,OAAR,YAAA4B,EAAc,YAAd,YAAAC,EAAyB,MAAM,EACzFvB,EAAI,sBAAuB,MAAc2B,EAAM,CAAC,CAClD,MACE3B,EAAI,cAAc,CAEtB,CAEA,eAAe4B,GAAe,CACxBlC,EAAQ,QAAUA,EAAQ,OAAO,GAAK,GACxC,MAAcmC,EAAOnC,EAAQ,MAAM,CAEvC,CAEA,eAAeoC,GAAa,CA5O5B,IAAAtB,EAAAa,EAAAC,EAAAC,EA+OE,GAFA1B,EAAI,OAAO,MAAM,OAAS,IAC1BW,EAAAX,EAAI,OAAO,WAAW,IAAI,IAA1B,MAAAW,EAA6B,UAAU,EAAG,EAAGjB,EAAQ,QAASA,EAAQ,SAClE,GAAC8B,EAAA3B,GAAA,YAAAA,EAAS,OAAT,MAAA2B,EAAe,SAAU,GAACC,EAAA5B,GAAA,YAAAA,EAAS,OAAT,MAAA4B,EAAe,WAAW,MAAO,GAIhE,GAHA,QAAQ,IAAI,eAAgB5B,EAAQ,IAAI,EACxCM,EAAI,kBAAkBN,EAAQ,KAAK,UAAUA,EAAQ,KAAK,KAAO,eAAe,KAAOA,EAAQ,KAAK,UAAY,QAAQ,KAAK,MAAM,KAAOA,EAAQ,KAAK,UAAY,GAAK,IAAI,KAAK,EACjL,MAAME,EAAM,GAAG,QAAQ,SAASF,EAAQ,KAAK,OAAQG,EAAI,MAAM,EAC3D,MAAc8B,EAAM,IAAM,EAC5B,OAAA3B,EAAI,sDAAsD,EAC1D,SAAS,KAAK,MAAM,WAAa,QACjCH,EAAI,OAAO,MAAM,QAAU,OACpB,GAET,IAAMkC,EAAK,MAAcC,EAAK,EACxBC,EAAcF,EAAG,IAAKN,GAAQA,EAAI,UAAU,EAAE,OAAQS,GAASA,EAAK,OAAS,CAAC,EAC9EC,EAAMvC,EAAM,MAAM,KAAKF,EAAQ,KAAK,UAAWuC,EAAa3C,CAAY,EAC9E,OAAAI,EAAQ,OAASqC,EAAGI,EAAI,QAAU,KAC9BzC,EAAQ,SACVM,EAAI,eAAeN,EAAQ,OAAO,cAAcA,EAAQ,OAAO,oBAAoB,KAAK,MAAM,IAAOyC,EAAI,UAAU,EAAI,KAAK,EAC5HtC,EAAI,KAAK,MAAQH,EAAQ,OAAO,KAChCG,EAAI,OAAO,MAAM,QAAU,IAC3B0B,EAAA1B,EAAI,OAAO,WAAW,IAAI,IAA1B,MAAA0B,EAA6B,aAAa7B,EAAQ,OAAO,MAAO,EAAG,IAErE,SAAS,KAAK,MAAM,WAAayC,EAAI,WAAa5C,EAAQ,UAAY,YAAc,SAC7E4C,EAAI,WAAa5C,EAAQ,SAClC,CAEA,eAAe6C,GAAO,CAvQtB,IAAA5B,EAAAa,EAAAC,EAAAC,EAoSE,OA5BA/B,EAAG,UAAU,OAAS,GACtBA,EAAG,eAAe,OAAS,GAC3BA,EAAG,aAAa,OAAS,GACzBA,EAAG,cAAc,OAAS,GAC1BA,EAAG,SAAS,OAAS,GACrBA,EAAG,eAAe,OAAS,GAC3BA,EAAG,cAAc,OAAS,GAC1BA,EAAG,IAAI,OAAS,GAChBA,EAAG,OAAO,OAAS,GACnBA,EAAG,UAAU,IAAM,EACnBK,EAAI,MAAM,MAAM,QAAU,OAC1BA,EAAI,MAAM,MAAM,QAAU,OAC1BA,EAAI,OAAO,MAAM,QAAU,OAC3BA,EAAI,OAAO,MAAM,OAAS,MAC1B,SAAS,KAAK,MAAM,WAAa,QACjC,MAAMK,EAAO,EACb,MAAMK,EAAc,EACpBR,EAAYH,EAAM,IAAI,EACtBF,EAAQ,KAAO,MAAMsB,EAAe,EACpCnB,EAAI,OAAO,QAAQwB,GAAAb,EAAAd,EAAQ,OAAR,YAAAc,EAAc,SAAd,YAAAa,EAAsB,MAAM,KAAM9B,EAAQ,QAC7DM,EAAI,OAAO,SAAS0B,GAAAD,EAAA5B,EAAQ,OAAR,YAAA4B,EAAc,SAAd,YAAAC,EAAsB,MAAM,KAAMhC,EAAQ,QAC9DM,EAAI,OAAO,MAAQA,EAAI,OAAO,MAC9BA,EAAI,OAAO,OAASA,EAAI,OAAO,OAC/BA,EAAI,OAAO,MAAM,MAAQ,GACzBA,EAAI,MAAM,MAAM,QAAU,OAC1BA,EAAI,KAAK,MAAM,QAAU,OACzBA,EAAI,OAAO,MAAM,QAAU,OAC3BA,EAAI,MAAM,MAAM,QAAU,QACrBJ,EAAM,EAIJqC,EAAW,GAHhB9B,EAAI,yBAAyB,EACtB,GAGX,CAEA,eAAeqC,GAAO,CA3StB,IAAA7B,EAAAa,EA4SErB,EAAI,iBAAkBJ,EAAM,QAAS,kBAAmBA,EAAM,GAAG,QAAQ,YAAY,EACrFI,EAAI,WAAY,KAAK,UAAUT,CAAO,EAAE,QAAQ,eAAgB,EAAE,EAAE,QAAQ,KAAM,GAAG,CAAC,EACtFS,EAAI,wBAAwB,EAC5B,MAAME,EAAO,EACbF,EAAI,yBAAyB,EAC7B,MAAMJ,EAAM,KAAK,EACjBI,EAAI,uBAAuB,EAC3BA,EAAI,wBAAyBX,EAAY,KAAK,YAAY,QAAU,UAAY,IAAImB,EAAAnB,EAAY,KAAK,gBAAjB,MAAAmB,EAAmC,QAAU,gBAAkB,IAAIa,EAAAhC,EAAY,KAAK,cAAjB,MAAAgC,EAAiC,QAAU,cAAgB,EAAE,EACpNrB,EAAI,0BAA0B,EAC9BA,EAAI,sBAAuB,MAAc2B,EAAM,CAAC,EAChD9B,EAAI,MAAM,iBAAiB,QAASuC,CAAI,EACxCvC,EAAI,KAAK,iBAAiB,QAASuB,CAAW,EAC9CvB,EAAI,OAAO,iBAAiB,QAAS+B,CAAY,EACjD,MAAMhC,EAAM,OAAO,EACnB,MAAMwC,EAAK,CACb,CAEA,OAAO,OAASC", + "names": ["H", "db", "database", "table", "log", "msg", "open", "resolve", "request", "evt", "load", "faceDB", "cursor", "count", "store", "save", "faceRecord", "newRecord", "remove", "humanConfig", "matchOptions", "options", "ok", "allOk", "current", "blink", "human", "dom", "timestamp", "startTime", "log", "msg", "webCam", "cameraOptions", "stream", "ready", "resolve", "detectionLoop", "_a", "now", "drawValidationTests", "y", "key", "val", "el", "status", "validationLoop", "interpolated", "gestures", "gesture", "saveRecords", "_b", "_c", "_d", "image", "rec", "save", "count", "deleteRecord", "remove", "detectFace", "db", "load", "descriptors", "desc", "res", "main", "init"] } diff --git a/demo/typescript/index.js b/demo/typescript/index.js index 14dfc71c..2bf3f49d 100644 --- a/demo/typescript/index.js +++ b/demo/typescript/index.js @@ -4,100 +4,6 @@ author: ' */ - -// demo/typescript/index.ts -import * as H from "../../dist/human.esm.js"; -var width = 1920; -var humanConfig = { - modelBasePath: "../../models", - filter: { enabled: true, equalization: false, flip: false }, - face: { enabled: true, detector: { rotation: true }, mesh: { enabled: true }, attention: { enabled: false }, iris: { enabled: true }, description: { enabled: true }, emotion: { enabled: true }, antispoof: { enabled: true }, liveness: { enabled: true } }, - body: { enabled: true }, - hand: { enabled: false }, - object: { enabled: false }, - segmentation: { enabled: false }, - gesture: { enabled: true } -}; -var human = new H.Human(humanConfig); -human.env.perfadd = false; -human.draw.options.font = 'small-caps 18px "Lato"'; -human.draw.options.lineHeight = 20; -var dom = { - video: document.getElementById("video"), - canvas: document.getElementById("canvas"), - log: document.getElementById("log"), - fps: document.getElementById("status"), - perf: document.getElementById("performance") -}; -var timestamp = { detect: 0, draw: 0, tensors: 0, start: 0 }; -var fps = { detectFPS: 0, drawFPS: 0, frames: 0, averageMs: 0 }; -var log = (...msg) => { - dom.log.innerText += msg.join(" ") + "\n"; - console.log(...msg); -}; -var status = (msg) => dom.fps.innerText = msg; -var perf = (msg) => dom.perf.innerText = "tensors:" + human.tf.memory().numTensors.toString() + " | performance: " + JSON.stringify(msg).replace(/"|{|}/g, "").replace(/,/g, " | "); -async function detectionLoop() { - if (!dom.video.paused) { - if (timestamp.start === 0) - timestamp.start = human.now(); - await human.detect(dom.video); - const tensors = human.tf.memory().numTensors; - if (tensors - timestamp.tensors !== 0) - log("allocated tensors:", tensors - timestamp.tensors); - timestamp.tensors = tensors; - fps.detectFPS = Math.round(1e3 * 1e3 / (human.now() - timestamp.detect)) / 1e3; - fps.frames++; - fps.averageMs = Math.round(1e3 * (human.now() - timestamp.start) / fps.frames) / 1e3; - if (fps.frames % 100 === 0 && !dom.video.paused) - log("performance", { ...fps, tensors: timestamp.tensors }); - } - timestamp.detect = human.now(); - requestAnimationFrame(detectionLoop); -} -async function drawLoop() { - var _a, _b, _c; - if (!dom.video.paused) { - const interpolated = human.next(human.result); - const processed = await human.image(dom.video); - human.draw.canvas(processed.canvas, dom.canvas); - const opt = { bodyLabels: `person confidence [score] and ${(_c = (_b = (_a = human.result) == null ? void 0 : _a.body) == null ? void 0 : _b[0]) == null ? void 0 : _c.keypoints.length} keypoints` }; - await human.draw.all(dom.canvas, interpolated, opt); - perf(interpolated.performance); - } - const now = human.now(); - fps.drawFPS = Math.round(1e3 * 1e3 / (now - timestamp.draw)) / 1e3; - timestamp.draw = now; - status(dom.video.paused ? "paused" : `fps: ${fps.detectFPS.toFixed(1).padStart(5, " ")} detect | ${fps.drawFPS.toFixed(1).padStart(5, " ")} draw`); - setTimeout(drawLoop, 30); -} -async function webCam() { - const devices = await human.webcam.enumerate(); - const id = devices[0].deviceId; - await human.webcam.start({ element: dom.video, crop: false, width, id }); - dom.canvas.width = human.webcam.width; - dom.canvas.height = human.webcam.height; - dom.canvas.onclick = async () => { - if (human.webcam.paused) - await human.webcam.play(); - else - human.webcam.pause(); - }; -} -async function main() { - log("human version:", human.version, "| tfjs version:", human.tf.version["tfjs-core"]); - log("platform:", human.env.platform, "| agent:", human.env.agent); - status("loading..."); - await human.load(); - log("backend:", human.tf.getBackend(), "| available:", human.env.backends); - log("models stats:", human.models.stats()); - log("models loaded:", human.models.loaded()); - log("environment", human.env); - status("initializing..."); - await human.warmup(); - await webCam(); - await detectionLoop(); - await drawLoop(); -} -window.onload = main; +import*as m from"../../dist/human.esm.js";var v=1920,b={modelBasePath:"../../models",filter:{enabled:!0,equalization:!1,flip:!1},face:{enabled:!0,detector:{rotation:!0},mesh:{enabled:!0},attention:{enabled:!1},iris:{enabled:!0},description:{enabled:!0},emotion:{enabled:!0},antispoof:{enabled:!0},liveness:{enabled:!0}},body:{enabled:!0},hand:{enabled:!1},object:{enabled:!1},segmentation:{enabled:!1},gesture:{enabled:!0}},e=new m.Human(b);e.env.perfadd=!1;e.draw.options.font='small-caps 18px "Lato"';e.draw.options.lineHeight=20;var a={video:document.getElementById("video"),canvas:document.getElementById("canvas"),log:document.getElementById("log"),fps:document.getElementById("status"),perf:document.getElementById("performance")},n={detect:0,draw:0,tensors:0,start:0},s={detectFPS:0,drawFPS:0,frames:0,averageMs:0},o=(...t)=>{a.log.innerText+=t.join(" ")+` +`,console.log(...t)},r=t=>a.fps.innerText=t,g=t=>a.perf.innerText="tensors:"+e.tf.memory().numTensors.toString()+" | performance: "+JSON.stringify(t).replace(/"|{|}/g,"").replace(/,/g," | ");async function f(){if(!a.video.paused){n.start===0&&(n.start=e.now()),await e.detect(a.video);let t=e.tf.memory().numTensors;t-n.tensors!==0&&o("allocated tensors:",t-n.tensors),n.tensors=t,s.detectFPS=Math.round(1e3*1e3/(e.now()-n.detect))/1e3,s.frames++,s.averageMs=Math.round(1e3*(e.now()-n.start)/s.frames)/1e3,s.frames%100===0&&!a.video.paused&&o("performance",{...s,tensors:n.tensors})}n.detect=e.now(),requestAnimationFrame(f)}async function p(){var d,i,c;if(!a.video.paused){let l=e.next(e.result),u=await e.image(a.video);e.draw.canvas(u.canvas,a.canvas);let w={bodyLabels:`person confidence [score] and ${(c=(i=(d=e.result)==null?void 0:d.body)==null?void 0:i[0])==null?void 0:c.keypoints.length} keypoints`};await e.draw.all(a.canvas,l,w),g(l.performance)}let t=e.now();s.drawFPS=Math.round(1e3*1e3/(t-n.draw))/1e3,n.draw=t,r(a.video.paused?"paused":`fps: ${s.detectFPS.toFixed(1).padStart(5," ")} detect | ${s.drawFPS.toFixed(1).padStart(5," ")} draw`),setTimeout(p,30)}async function y(){let d=(await e.webcam.enumerate())[0].deviceId;await e.webcam.start({element:a.video,crop:!1,width:v,id:d}),a.canvas.width=e.webcam.width,a.canvas.height=e.webcam.height,a.canvas.onclick=async()=>{e.webcam.paused?await e.webcam.play():e.webcam.pause()}}async function h(){o("human version:",e.version,"| tfjs version:",e.tf.version["tfjs-core"]),o("platform:",e.env.platform,"| agent:",e.env.agent),r("loading..."),await e.load(),o("backend:",e.tf.getBackend(),"| available:",e.env.backends),o("models stats:",e.models.stats()),o("models loaded:",e.models.loaded()),o("environment",e.env),r("initializing..."),await e.warmup(),await y(),await f(),await p()}window.onload=h; //# sourceMappingURL=index.js.map diff --git a/demo/typescript/index.js.map b/demo/typescript/index.js.map index 62861400..622fbf92 100644 --- a/demo/typescript/index.js.map +++ b/demo/typescript/index.js.map @@ -2,6 +2,6 @@ "version": 3, "sources": ["index.ts"], "sourcesContent": ["/**\n * Human demo for browsers\n * @default Human Library\n * @summary \n * @author \n * @copyright \n * @license MIT\n */\n\nimport * as H from '../../dist/human.esm.js'; // equivalent of @vladmandic/Human\n\nconst width = 1920; // used by webcam config as well as human maximum resultion // can be anything, but resolutions higher than 4k will disable internal optimizations\n\nconst humanConfig: Partial = { // user configuration for human, used to fine-tune behavior\n // backend: 'webgpu',\n modelBasePath: '../../models',\n filter: { enabled: true, equalization: false, flip: false },\n face: { enabled: true, detector: { rotation: true }, mesh: { enabled: true }, attention: { enabled: false }, iris: { enabled: true }, description: { enabled: true }, emotion: { enabled: true }, antispoof: { enabled: true }, liveness: { enabled: true } },\n body: { enabled: true },\n // hand: { enabled: true },\n hand: { enabled: false },\n object: { enabled: false },\n segmentation: { enabled: false },\n gesture: { enabled: true },\n};\n\nconst human = new H.Human(humanConfig); // create instance of human with overrides from user configuration\n\nhuman.env.perfadd = false; // is performance data showing instant or total values\nhuman.draw.options.font = 'small-caps 18px \"Lato\"'; // set font used to draw labels when using draw methods\nhuman.draw.options.lineHeight = 20;\n// human.draw.options.fillPolygons = true;\n\nconst dom = { // grab instances of dom objects so we dont have to look them up later\n video: document.getElementById('video') as HTMLVideoElement,\n canvas: document.getElementById('canvas') as HTMLCanvasElement,\n log: document.getElementById('log') as HTMLPreElement,\n fps: document.getElementById('status') as HTMLPreElement,\n perf: document.getElementById('performance') as HTMLDivElement,\n};\nconst timestamp = { detect: 0, draw: 0, tensors: 0, start: 0 }; // holds information used to calculate performance and possible memory leaks\nconst fps = { detectFPS: 0, drawFPS: 0, frames: 0, averageMs: 0 }; // holds calculated fps information for both detect and screen refresh\n\nconst log = (...msg) => { // helper method to output messages\n dom.log.innerText += msg.join(' ') + '\\n';\n console.log(...msg); // eslint-disable-line no-console\n};\nconst status = (msg) => dom.fps.innerText = msg; // print status element\nconst perf = (msg) => dom.perf.innerText = 'tensors:' + human.tf.memory().numTensors.toString() + ' | performance: ' + JSON.stringify(msg).replace(/\"|{|}/g, '').replace(/,/g, ' | '); // print performance element\n\nasync function detectionLoop() { // main detection loop\n if (!dom.video.paused) {\n if (timestamp.start === 0) timestamp.start = human.now();\n // log('profiling data:', await human.profile(dom.video));\n await human.detect(dom.video); // actual detection; were not capturing output in a local variable as it can also be reached via human.result\n const tensors = human.tf.memory().numTensors; // check current tensor usage for memory leaks\n if (tensors - timestamp.tensors !== 0) log('allocated tensors:', tensors - timestamp.tensors); // printed on start and each time there is a tensor leak\n timestamp.tensors = tensors;\n fps.detectFPS = Math.round(1000 * 1000 / (human.now() - timestamp.detect)) / 1000;\n fps.frames++;\n fps.averageMs = Math.round(1000 * (human.now() - timestamp.start) / fps.frames) / 1000;\n if (fps.frames % 100 === 0 && !dom.video.paused) log('performance', { ...fps, tensors: timestamp.tensors });\n }\n timestamp.detect = human.now();\n requestAnimationFrame(detectionLoop); // start new frame immediately\n}\n\nasync function drawLoop() { // main screen refresh loop\n if (!dom.video.paused) {\n const interpolated = human.next(human.result); // smoothen result using last-known results\n const processed = await human.image(dom.video); // get current video frame, but enhanced with human.filters\n human.draw.canvas(processed.canvas as HTMLCanvasElement, dom.canvas);\n\n const opt: Partial = { bodyLabels: `person confidence [score] and ${human.result?.body?.[0]?.keypoints.length} keypoints` };\n await human.draw.all(dom.canvas, interpolated, opt); // draw labels, boxes, lines, etc.\n perf(interpolated.performance); // write performance data\n }\n const now = human.now();\n fps.drawFPS = Math.round(1000 * 1000 / (now - timestamp.draw)) / 1000;\n timestamp.draw = now;\n status(dom.video.paused ? 'paused' : `fps: ${fps.detectFPS.toFixed(1).padStart(5, ' ')} detect | ${fps.drawFPS.toFixed(1).padStart(5, ' ')} draw`); // write status\n setTimeout(drawLoop, 30); // use to slow down refresh from max refresh rate to target of 30 fps\n}\n\nasync function webCam() {\n const devices = await human.webcam.enumerate();\n const id = devices[0].deviceId; // use first available video source\n await human.webcam.start({ element: dom.video, crop: false, width, id }); // use human webcam helper methods and associate webcam stream with a dom element\n dom.canvas.width = human.webcam.width;\n dom.canvas.height = human.webcam.height;\n dom.canvas.onclick = async () => { // pause when clicked on screen and resume on next click\n if (human.webcam.paused) await human.webcam.play();\n else human.webcam.pause();\n };\n}\n\nasync function main() { // main entry point\n log('human version:', human.version, '| tfjs version:', human.tf.version['tfjs-core']);\n log('platform:', human.env.platform, '| agent:', human.env.agent);\n status('loading...');\n await human.load(); // preload all models\n log('backend:', human.tf.getBackend(), '| available:', human.env.backends);\n log('models stats:', human.models.stats());\n log('models loaded:', human.models.loaded());\n log('environment', human.env);\n status('initializing...');\n await human.warmup(); // warmup function to initialize backend for future faster detection\n await webCam(); // start webcam\n await detectionLoop(); // start detection loop\n await drawLoop(); // start draw loop\n}\n\nwindow.onload = main;\n"], - "mappings": ";;;;;;;;AASA,YAAY,OAAO;AAEnB,IAAM,QAAQ;AAEd,IAAM,cAAiC;AAAA,EAErC,eAAe;AAAA,EACf,QAAQ,EAAE,SAAS,MAAM,cAAc,OAAO,MAAM,MAAM;AAAA,EAC1D,MAAM,EAAE,SAAS,MAAM,UAAU,EAAE,UAAU,KAAK,GAAG,MAAM,EAAE,SAAS,KAAK,GAAG,WAAW,EAAE,SAAS,MAAM,GAAG,MAAM,EAAE,SAAS,KAAK,GAAG,aAAa,EAAE,SAAS,KAAK,GAAG,SAAS,EAAE,SAAS,KAAK,GAAG,WAAW,EAAE,SAAS,KAAK,GAAG,UAAU,EAAE,SAAS,KAAK,EAAE;AAAA,EAC5P,MAAM,EAAE,SAAS,KAAK;AAAA,EAEtB,MAAM,EAAE,SAAS,MAAM;AAAA,EACvB,QAAQ,EAAE,SAAS,MAAM;AAAA,EACzB,cAAc,EAAE,SAAS,MAAM;AAAA,EAC/B,SAAS,EAAE,SAAS,KAAK;AAC3B;AAEA,IAAM,QAAQ,IAAM,QAAM,WAAW;AAErC,MAAM,IAAI,UAAU;AACpB,MAAM,KAAK,QAAQ,OAAO;AAC1B,MAAM,KAAK,QAAQ,aAAa;AAGhC,IAAM,MAAM;AAAA,EACV,OAAO,SAAS,eAAe,OAAO;AAAA,EACtC,QAAQ,SAAS,eAAe,QAAQ;AAAA,EACxC,KAAK,SAAS,eAAe,KAAK;AAAA,EAClC,KAAK,SAAS,eAAe,QAAQ;AAAA,EACrC,MAAM,SAAS,eAAe,aAAa;AAC7C;AACA,IAAM,YAAY,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,EAAE;AAC7D,IAAM,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,EAAE;AAEhE,IAAM,MAAM,IAAI,QAAQ;AACtB,MAAI,IAAI,aAAa,IAAI,KAAK,GAAG,IAAI;AACrC,UAAQ,IAAI,GAAG,GAAG;AACpB;AACA,IAAM,SAAS,CAAC,QAAQ,IAAI,IAAI,YAAY;AAC5C,IAAM,OAAO,CAAC,QAAQ,IAAI,KAAK,YAAY,aAAa,MAAM,GAAG,OAAO,EAAE,WAAW,SAAS,IAAI,qBAAqB,KAAK,UAAU,GAAG,EAAE,QAAQ,UAAU,EAAE,EAAE,QAAQ,MAAM,KAAK;AAEpL,eAAe,gBAAgB;AAC7B,MAAI,CAAC,IAAI,MAAM,QAAQ;AACrB,QAAI,UAAU,UAAU;AAAG,gBAAU,QAAQ,MAAM,IAAI;AAEvD,UAAM,MAAM,OAAO,IAAI,KAAK;AAC5B,UAAM,UAAU,MAAM,GAAG,OAAO,EAAE;AAClC,QAAI,UAAU,UAAU,YAAY;AAAG,UAAI,sBAAsB,UAAU,UAAU,OAAO;AAC5F,cAAU,UAAU;AACpB,QAAI,YAAY,KAAK,MAAM,MAAO,OAAQ,MAAM,IAAI,IAAI,UAAU,OAAO,IAAI;AAC7E,QAAI;AACJ,QAAI,YAAY,KAAK,MAAM,OAAQ,MAAM,IAAI,IAAI,UAAU,SAAS,IAAI,MAAM,IAAI;AAClF,QAAI,IAAI,SAAS,QAAQ,KAAK,CAAC,IAAI,MAAM;AAAQ,UAAI,eAAe,EAAE,GAAG,KAAK,SAAS,UAAU,QAAQ,CAAC;AAAA,EAC5G;AACA,YAAU,SAAS,MAAM,IAAI;AAC7B,wBAAsB,aAAa;AACrC;AAEA,eAAe,WAAW;AAnE1B;AAoEE,MAAI,CAAC,IAAI,MAAM,QAAQ;AACrB,UAAM,eAAe,MAAM,KAAK,MAAM,MAAM;AAC5C,UAAM,YAAY,MAAM,MAAM,MAAM,IAAI,KAAK;AAC7C,UAAM,KAAK,OAAO,UAAU,QAA6B,IAAI,MAAM;AAEnE,UAAM,MAA8B,EAAE,YAAY,kCAAiC,uBAAM,WAAN,mBAAc,SAAd,mBAAqB,OAArB,mBAAyB,UAAU,mBAAmB;AACzI,UAAM,MAAM,KAAK,IAAI,IAAI,QAAQ,cAAc,GAAG;AAClD,SAAK,aAAa,WAAW;AAAA,EAC/B;AACA,QAAM,MAAM,MAAM,IAAI;AACtB,MAAI,UAAU,KAAK,MAAM,MAAO,OAAQ,MAAM,UAAU,KAAK,IAAI;AACjE,YAAU,OAAO;AACjB,SAAO,IAAI,MAAM,SAAS,WAAW,QAAQ,IAAI,UAAU,QAAQ,CAAC,EAAE,SAAS,GAAG,GAAG,cAAc,IAAI,QAAQ,QAAQ,CAAC,EAAE,SAAS,GAAG,GAAG,QAAQ;AACjJ,aAAW,UAAU,EAAE;AACzB;AAEA,eAAe,SAAS;AACtB,QAAM,UAAU,MAAM,MAAM,OAAO,UAAU;AAC7C,QAAM,KAAK,QAAQ,GAAG;AACtB,QAAM,MAAM,OAAO,MAAM,EAAE,SAAS,IAAI,OAAO,MAAM,OAAO,OAAO,GAAG,CAAC;AACvE,MAAI,OAAO,QAAQ,MAAM,OAAO;AAChC,MAAI,OAAO,SAAS,MAAM,OAAO;AACjC,MAAI,OAAO,UAAU,YAAY;AAC/B,QAAI,MAAM,OAAO;AAAQ,YAAM,MAAM,OAAO,KAAK;AAAA;AAC5C,YAAM,OAAO,MAAM;AAAA,EAC1B;AACF;AAEA,eAAe,OAAO;AACpB,MAAI,kBAAkB,MAAM,SAAS,mBAAmB,MAAM,GAAG,QAAQ,YAAY;AACrF,MAAI,aAAa,MAAM,IAAI,UAAU,YAAY,MAAM,IAAI,KAAK;AAChE,SAAO,YAAY;AACnB,QAAM,MAAM,KAAK;AACjB,MAAI,YAAY,MAAM,GAAG,WAAW,GAAG,gBAAgB,MAAM,IAAI,QAAQ;AACzE,MAAI,iBAAiB,MAAM,OAAO,MAAM,CAAC;AACzC,MAAI,kBAAkB,MAAM,OAAO,OAAO,CAAC;AAC3C,MAAI,eAAe,MAAM,GAAG;AAC5B,SAAO,iBAAiB;AACxB,QAAM,MAAM,OAAO;AACnB,QAAM,OAAO;AACb,QAAM,cAAc;AACpB,QAAM,SAAS;AACjB;AAEA,OAAO,SAAS;", - "names": [] + "mappings": ";;;;;;AASA,UAAYA,MAAO,0BAEnB,IAAMC,EAAQ,KAERC,EAAiC,CAErC,cAAe,eACf,OAAQ,CAAE,QAAS,GAAM,aAAc,GAAO,KAAM,EAAM,EAC1D,KAAM,CAAE,QAAS,GAAM,SAAU,CAAE,SAAU,EAAK,EAAG,KAAM,CAAE,QAAS,EAAK,EAAG,UAAW,CAAE,QAAS,EAAM,EAAG,KAAM,CAAE,QAAS,EAAK,EAAG,YAAa,CAAE,QAAS,EAAK,EAAG,QAAS,CAAE,QAAS,EAAK,EAAG,UAAW,CAAE,QAAS,EAAK,EAAG,SAAU,CAAE,QAAS,EAAK,CAAE,EAC5P,KAAM,CAAE,QAAS,EAAK,EAEtB,KAAM,CAAE,QAAS,EAAM,EACvB,OAAQ,CAAE,QAAS,EAAM,EACzB,aAAc,CAAE,QAAS,EAAM,EAC/B,QAAS,CAAE,QAAS,EAAK,CAC3B,EAEMC,EAAQ,IAAM,QAAMD,CAAW,EAErCC,EAAM,IAAI,QAAU,GACpBA,EAAM,KAAK,QAAQ,KAAO,yBAC1BA,EAAM,KAAK,QAAQ,WAAa,GAGhC,IAAMC,EAAM,CACV,MAAO,SAAS,eAAe,OAAO,EACtC,OAAQ,SAAS,eAAe,QAAQ,EACxC,IAAK,SAAS,eAAe,KAAK,EAClC,IAAK,SAAS,eAAe,QAAQ,EACrC,KAAM,SAAS,eAAe,aAAa,CAC7C,EACMC,EAAY,CAAE,OAAQ,EAAG,KAAM,EAAG,QAAS,EAAG,MAAO,CAAE,EACvDC,EAAM,CAAE,UAAW,EAAG,QAAS,EAAG,OAAQ,EAAG,UAAW,CAAE,EAE1DC,EAAM,IAAIC,IAAQ,CACtBJ,EAAI,IAAI,WAAaI,EAAI,KAAK,GAAG,EAAI;AAAA,EACrC,QAAQ,IAAI,GAAGA,CAAG,CACpB,EACMC,EAAUD,GAAQJ,EAAI,IAAI,UAAYI,EACtCE,EAAQF,GAAQJ,EAAI,KAAK,UAAY,WAAaD,EAAM,GAAG,OAAO,EAAE,WAAW,SAAS,EAAI,mBAAqB,KAAK,UAAUK,CAAG,EAAE,QAAQ,SAAU,EAAE,EAAE,QAAQ,KAAM,KAAK,EAEpL,eAAeG,GAAgB,CAC7B,GAAI,CAACP,EAAI,MAAM,OAAQ,CACjBC,EAAU,QAAU,IAAGA,EAAU,MAAQF,EAAM,IAAI,GAEvD,MAAMA,EAAM,OAAOC,EAAI,KAAK,EAC5B,IAAMQ,EAAUT,EAAM,GAAG,OAAO,EAAE,WAC9BS,EAAUP,EAAU,UAAY,GAAGE,EAAI,qBAAsBK,EAAUP,EAAU,OAAO,EAC5FA,EAAU,QAAUO,EACpBN,EAAI,UAAY,KAAK,MAAM,IAAO,KAAQH,EAAM,IAAI,EAAIE,EAAU,OAAO,EAAI,IAC7EC,EAAI,SACJA,EAAI,UAAY,KAAK,MAAM,KAAQH,EAAM,IAAI,EAAIE,EAAU,OAASC,EAAI,MAAM,EAAI,IAC9EA,EAAI,OAAS,MAAQ,GAAK,CAACF,EAAI,MAAM,QAAQG,EAAI,cAAe,CAAE,GAAGD,EAAK,QAASD,EAAU,OAAQ,CAAC,CAC5G,CACAA,EAAU,OAASF,EAAM,IAAI,EAC7B,sBAAsBQ,CAAa,CACrC,CAEA,eAAeE,GAAW,CAnE1B,IAAAC,EAAAC,EAAAC,EAoEE,GAAI,CAACZ,EAAI,MAAM,OAAQ,CACrB,IAAMa,EAAed,EAAM,KAAKA,EAAM,MAAM,EACtCe,EAAY,MAAMf,EAAM,MAAMC,EAAI,KAAK,EAC7CD,EAAM,KAAK,OAAOe,EAAU,OAA6Bd,EAAI,MAAM,EAEnE,IAAMe,EAA8B,CAAE,WAAY,kCAAiCH,GAAAD,GAAAD,EAAAX,EAAM,SAAN,YAAAW,EAAc,OAAd,YAAAC,EAAqB,KAArB,YAAAC,EAAyB,UAAU,kBAAmB,EACzI,MAAMb,EAAM,KAAK,IAAIC,EAAI,OAAQa,EAAcE,CAAG,EAClDT,EAAKO,EAAa,WAAW,CAC/B,CACA,IAAMG,EAAMjB,EAAM,IAAI,EACtBG,EAAI,QAAU,KAAK,MAAM,IAAO,KAAQc,EAAMf,EAAU,KAAK,EAAI,IACjEA,EAAU,KAAOe,EACjBX,EAAOL,EAAI,MAAM,OAAS,SAAW,QAAQE,EAAI,UAAU,QAAQ,CAAC,EAAE,SAAS,EAAG,GAAG,cAAcA,EAAI,QAAQ,QAAQ,CAAC,EAAE,SAAS,EAAG,GAAG,QAAQ,EACjJ,WAAWO,EAAU,EAAE,CACzB,CAEA,eAAeQ,GAAS,CAEtB,IAAMC,GADU,MAAMnB,EAAM,OAAO,UAAU,GAC1B,GAAG,SACtB,MAAMA,EAAM,OAAO,MAAM,CAAE,QAASC,EAAI,MAAO,KAAM,GAAO,MAAAH,EAAO,GAAAqB,CAAG,CAAC,EACvElB,EAAI,OAAO,MAAQD,EAAM,OAAO,MAChCC,EAAI,OAAO,OAASD,EAAM,OAAO,OACjCC,EAAI,OAAO,QAAU,SAAY,CAC3BD,EAAM,OAAO,OAAQ,MAAMA,EAAM,OAAO,KAAK,EAC5CA,EAAM,OAAO,MAAM,CAC1B,CACF,CAEA,eAAeoB,GAAO,CACpBhB,EAAI,iBAAkBJ,EAAM,QAAS,kBAAmBA,EAAM,GAAG,QAAQ,YAAY,EACrFI,EAAI,YAAaJ,EAAM,IAAI,SAAU,WAAYA,EAAM,IAAI,KAAK,EAChEM,EAAO,YAAY,EACnB,MAAMN,EAAM,KAAK,EACjBI,EAAI,WAAYJ,EAAM,GAAG,WAAW,EAAG,eAAgBA,EAAM,IAAI,QAAQ,EACzEI,EAAI,gBAAiBJ,EAAM,OAAO,MAAM,CAAC,EACzCI,EAAI,iBAAkBJ,EAAM,OAAO,OAAO,CAAC,EAC3CI,EAAI,cAAeJ,EAAM,GAAG,EAC5BM,EAAO,iBAAiB,EACxB,MAAMN,EAAM,OAAO,EACnB,MAAMkB,EAAO,EACb,MAAMV,EAAc,EACpB,MAAME,EAAS,CACjB,CAEA,OAAO,OAASU", + "names": ["H", "width", "humanConfig", "human", "dom", "timestamp", "fps", "log", "msg", "status", "perf", "detectionLoop", "tensors", "drawLoop", "_a", "_b", "_c", "interpolated", "processed", "opt", "now", "webCam", "id", "main"] } diff --git a/dist/human.esm-nobundle.js b/dist/human.esm-nobundle.js index 53ad48e7..dd72cfda 100644 --- a/dist/human.esm-nobundle.js +++ b/dist/human.esm-nobundle.js @@ -4,271 +4,7 @@ author: ' */ -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; -var __export = (target, all2) => { - for (var name in all2) - __defProp(target, name, { get: all2[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __reExport = (target, mod3, secondTarget) => (__copyProps(target, mod3, "default"), secondTarget && __copyProps(secondTarget, mod3, "default")); -var __publicField = (obj, key, value) => { - __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); - return value; -}; -var __accessCheck = (obj, member, msg) => { - if (!member.has(obj)) - throw TypeError("Cannot " + msg); -}; -var __privateGet = (obj, member, getter) => { - __accessCheck(obj, member, "read from private field"); - return getter ? getter.call(obj) : member.get(obj); -}; -var __privateAdd = (obj, member, value) => { - if (member.has(obj)) - throw TypeError("Cannot add the same private member more than once"); - member instanceof WeakSet ? member.add(obj) : member.set(obj, value); -}; -var __privateSet = (obj, member, value, setter) => { - __accessCheck(obj, member, "write to private field"); - setter ? setter.call(obj, value) : member.set(obj, value); - return value; -}; - -// dist/tfjs.esm.js -var tfjs_esm_exports = {}; -__export(tfjs_esm_exports, { - version: () => version7 -}); -__reExport(tfjs_esm_exports, dist_star); -__reExport(tfjs_esm_exports, dist_star2); -__reExport(tfjs_esm_exports, dist_star3); -__reExport(tfjs_esm_exports, dist_star4); -__reExport(tfjs_esm_exports, dist_star5); -__reExport(tfjs_esm_exports, dist_star6); -import * as dist_star from "@tensorflow/tfjs-core/dist/index.js"; -import * as dist_star2 from "@tensorflow/tfjs-converter/dist/index.js"; -import * as dist_star3 from "@tensorflow/tfjs-backend-cpu/dist/index.js"; -import * as dist_star4 from "@tensorflow/tfjs-backend-webgl/dist/index.js"; -import * as dist_star5 from "@tensorflow/tfjs-backend-wasm/dist/index.js"; -import * as dist_star6 from "@tensorflow/tfjs-backend-webgpu/dist/index.js"; -var version = "4.2.0"; -var version2 = "4.2.0"; -var version3 = "4.2.0"; -var version4 = "4.2.0"; -var version5 = "4.2.0"; -var version6 = "0.0.1-alpha.17"; -var version7 = { - tfjs: version, - "tfjs-core": version, - "tfjs-converter": version2, - "tfjs-backend-cpu": version3, - "tfjs-backend-webgl": version4, - "tfjs-backend-wasm": version5, - "tfjs-backend-webgpu": version6 -}; - -// src/util/util.ts -function log(...msg) { - const dt = new Date(); - const ts = `${dt.getHours().toString().padStart(2, "0")}:${dt.getMinutes().toString().padStart(2, "0")}:${dt.getSeconds().toString().padStart(2, "0")}.${dt.getMilliseconds().toString().padStart(3, "0")}`; - if (msg) - console.log(ts, "Human:", ...msg); -} -function join(folder, file) { - const separator = folder.endsWith("/") ? "" : "/"; - const skipJoin = file.startsWith(".") || file.startsWith("/") || file.startsWith("http:") || file.startsWith("https:") || file.startsWith("file:"); - const path = skipJoin ? `${file}` : `${folder}${separator}${file}`; - if (!path.toLocaleLowerCase().includes(".json")) - throw new Error(`modelpath error: expecting json file: ${path}`); - return path; -} -var now = () => { - if (typeof performance !== "undefined") - return performance.now(); - return parseInt((Number(process.hrtime.bigint()) / 1e3 / 1e3).toString()); -}; -function validate(defaults, config3, parent = "config", msgs = []) { - for (const key of Object.keys(config3)) { - if (typeof config3[key] === "object") { - validate(defaults[key], config3[key], key, msgs); - } else { - const defined = defaults && typeof defaults[key] !== "undefined"; - if (!defined) - msgs.push({ reason: "unknown property", where: `${parent}.${key} = ${config3[key]}` }); - const same = defaults && typeof defaults[key] === typeof config3[key]; - if (defined && !same) - msgs.push({ reason: "property type mismatch", where: `${parent}.${key} = ${config3[key]}`, expected: typeof defaults[key] }); - } - } - if (config3.debug && parent === "config" && msgs.length > 0) - log("invalid configuration", msgs); - return msgs; -} -function mergeDeep(...objects) { - const isObject = (obj) => obj && typeof obj === "object"; - return objects.reduce((prev, obj) => { - Object.keys(obj || {}).forEach((key) => { - const pVal = prev[key]; - const oVal = obj[key]; - if (Array.isArray(pVal) && Array.isArray(oVal)) - prev[key] = pVal.concat(...oVal); - else if (isObject(pVal) && isObject(oVal)) - prev[key] = mergeDeep(pVal, oVal); - else - prev[key] = oVal; - }); - return prev; - }, {}); -} - -// src/config.ts -var config = { - backend: "", - modelBasePath: "", - cacheModels: true, - validateModels: true, - wasmPath: "", - wasmPlatformFetch: false, - debug: false, - async: true, - warmup: "full", - cacheSensitivity: 0.7, - skipAllowed: false, - deallocate: false, - flags: {}, - softwareKernels: false, - filter: { - enabled: true, - equalization: false, - width: 0, - height: 0, - flip: false, - return: true, - autoBrightness: true, - brightness: 0, - contrast: 0, - sharpness: 0, - blur: 0, - saturation: 0, - hue: 0, - negative: false, - sepia: false, - vintage: false, - kodachrome: false, - technicolor: false, - polaroid: false, - pixelate: 0 - }, - gesture: { - enabled: true - }, - face: { - enabled: true, - detector: { - modelPath: "blazeface.json", - rotation: false, - maxDetected: 1, - skipFrames: 99, - skipTime: 2500, - minConfidence: 0.2, - iouThreshold: 0.1, - mask: false, - return: false - }, - mesh: { - enabled: true, - modelPath: "facemesh.json", - keepInvalid: false - }, - attention: { - enabled: false, - modelPath: "facemesh-attention.json" - }, - iris: { - enabled: true, - modelPath: "iris.json" - }, - emotion: { - enabled: true, - minConfidence: 0.1, - skipFrames: 99, - skipTime: 1500, - modelPath: "emotion.json" - }, - description: { - enabled: true, - modelPath: "faceres.json", - skipFrames: 99, - skipTime: 3e3, - minConfidence: 0.1 - }, - antispoof: { - enabled: false, - skipFrames: 99, - skipTime: 4e3, - modelPath: "antispoof.json" - }, - liveness: { - enabled: false, - skipFrames: 99, - skipTime: 4e3, - modelPath: "liveness.json" - } - }, - body: { - enabled: true, - modelPath: "movenet-lightning.json", - maxDetected: -1, - minConfidence: 0.3, - skipFrames: 1, - skipTime: 200 - }, - hand: { - enabled: true, - rotation: true, - skipFrames: 99, - skipTime: 1e3, - minConfidence: 0.5, - iouThreshold: 0.2, - maxDetected: -1, - landmarks: true, - detector: { - modelPath: "handtrack.json" - }, - skeleton: { - modelPath: "handlandmark-lite.json" - } - }, - object: { - enabled: false, - modelPath: "centernet.json", - minConfidence: 0.2, - iouThreshold: 0.4, - maxDetected: 10, - skipFrames: 99, - skipTime: 2e3 - }, - segmentation: { - enabled: false, - modelPath: "rvm.json", - ratio: 0.5, - mode: "default" - } -}; - -// src/image/imagefxshaders.ts -var vertexIdentity = ` +var st=Object.defineProperty;var Zn=Object.getOwnPropertyDescriptor;var Xn=Object.getOwnPropertyNames;var qn=Object.prototype.hasOwnProperty;var Un=(e,t,n)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var oe=(e,t)=>{for(var n in t)st(e,n,{get:t[n],enumerable:!0})},F5=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Xn(t))!qn.call(e,s)&&s!==n&&st(e,s,{get:()=>t[s],enumerable:!(o=Zn(t,s))||o.enumerable});return e},w=(e,t,n)=>(F5(e,t,"default"),n&&F5(n,t,"default"));var E=(e,t,n)=>(Un(e,typeof t!="symbol"?t+"":t,n),n),B5=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)};var v0=(e,t,n)=>(B5(e,t,"read from private field"),n?n.call(e):t.get(e)),Z0=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},Y0=(e,t,n,o)=>(B5(e,t,"write to private field"),o?o.call(e,n):t.set(e,n),n);var r={};oe(r,{version:()=>Ke});w(r,fA);w(r,mA);w(r,pA);w(r,uA);w(r,hA);w(r,bA);import*as fA from"@tensorflow/tfjs-core/dist/index.js";import*as mA from"@tensorflow/tfjs-converter/dist/index.js";import*as pA from"@tensorflow/tfjs-backend-cpu/dist/index.js";import*as uA from"@tensorflow/tfjs-backend-webgl/dist/index.js";import*as hA from"@tensorflow/tfjs-backend-wasm/dist/index.js";import*as bA from"@tensorflow/tfjs-backend-webgpu/dist/index.js";var H5="4.2.0",Yn="4.2.0",Kn="4.2.0",Jn="4.2.0",Qn="4.2.0",_n="0.0.1-alpha.17",Ke={tfjs:H5,"tfjs-core":H5,"tfjs-converter":Yn,"tfjs-backend-cpu":Kn,"tfjs-backend-webgl":Jn,"tfjs-backend-wasm":Qn,"tfjs-backend-webgpu":_n};function h(...e){let t=new Date,n=`${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}:${t.getSeconds().toString().padStart(2,"0")}.${t.getMilliseconds().toString().padStart(3,"0")}`;e&&console.log(n,"Human:",...e)}function G5(e,t){let n=e.endsWith("/")?"":"/",s=t.startsWith(".")||t.startsWith("/")||t.startsWith("http:")||t.startsWith("https:")||t.startsWith("file:")?`${t}`:`${e}${n}${t}`;if(!s.toLocaleLowerCase().includes(".json"))throw new Error(`modelpath error: expecting json file: ${s}`);return s}var T=()=>typeof performance!="undefined"?performance.now():parseInt((Number(process.hrtime.bigint())/1e3/1e3).toString());function At(e,t,n="config",o=[]){for(let s of Object.keys(t))if(typeof t[s]=="object")At(e[s],t[s],s,o);else{let A=e&&typeof e[s]!="undefined";A||o.push({reason:"unknown property",where:`${n}.${s} = ${t[s]}`});let a=e&&typeof e[s]==typeof t[s];A&&!a&&o.push({reason:"property type mismatch",where:`${n}.${s} = ${t[s]}`,expected:typeof e[s]})}return t.debug&&n==="config"&&o.length>0&&h("invalid configuration",o),o}function Q(...e){let t=n=>n&&typeof n=="object";return e.reduce((n,o)=>(Object.keys(o||{}).forEach(s=>{let A=n[s],a=o[s];Array.isArray(A)&&Array.isArray(a)?n[s]=A.concat(...a):t(A)&&t(a)?n[s]=Q(A,a):n[s]=a}),n),{})}var Le={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,iouThreshold:.1,mask:!1,return:!1},mesh:{enabled:!0,modelPath:"facemesh.json",keepInvalid:!1},attention:{enabled:!1,modelPath:"facemesh-attention.json"},iris:{enabled:!0,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"}};var V5=` precision highp float; attribute vec2 pos; attribute vec2 uv; @@ -278,8 +14,7 @@ var vertexIdentity = ` vUv = uv; gl_Position = vec4(pos.x, pos.y*flipY, 0.0, 1.); } -`; -var colorMatrixWithAlpha = ` +`;var Z5=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -291,8 +26,7 @@ var colorMatrixWithAlpha = ` 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]; } -`; -var colorMatrixWithoutAlpha = ` +`,X5=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -304,8 +38,7 @@ var colorMatrixWithoutAlpha = ` gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[14]; gl_FragColor.a = c.a; } -`; -var pixelate = ` +`,q5=` precision highp float; varying vec2 vUv; uniform vec2 size; @@ -318,8 +51,7 @@ var pixelate = ` vec2 coord = pixelate(vUv, size); gl_FragColor += texture2D(texture, coord); } -`; -var blur = ` +`,U5=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -342,8 +74,7 @@ var blur = ` 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; } -`; -var convolution = ` +`,Y5=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -365,6046 +96,20 @@ var convolution = ` c31 * m[6] + c32 * m[7] + c33 * m[8]; gl_FragColor.a = c22.a; } -`; - -// src/image/imagefx.ts -var collect = (source, prefix, collection) => { - const r = new RegExp("\\b" + prefix + " \\w+ (\\w+)", "ig"); - source.replace(r, (match2, name) => { - collection[name] = 0; - return match2; - }); -}; -var GLProgram = class { - constructor(gl, vertexSource, fragmentSource) { - __publicField(this, "uniform", {}); - __publicField(this, "attribute", {}); - __publicField(this, "gl"); - __publicField(this, "id"); - __publicField(this, "compile", (source, type) => { - const shader = this.gl.createShader(type); - if (!shader) { - log("filter: could not create shader"); - return null; - } - this.gl.shaderSource(shader, source); - this.gl.compileShader(shader); - if (!this.gl.getShaderParameter(shader, this.gl.COMPILE_STATUS)) { - log(`filter: gl compile failed: ${this.gl.getShaderInfoLog(shader) || "unknown"}`); - return null; - } - return shader; - }); - this.gl = gl; - const vertexShader = this.compile(vertexSource, this.gl.VERTEX_SHADER); - const fragmentShader = this.compile(fragmentSource, this.gl.FRAGMENT_SHADER); - this.id = this.gl.createProgram(); - if (!vertexShader || !fragmentShader) - return; - if (!this.id) { - log("filter: could not create webgl program"); - return; - } - this.gl.attachShader(this.id, vertexShader); - this.gl.attachShader(this.id, fragmentShader); - this.gl.linkProgram(this.id); - if (!this.gl.getProgramParameter(this.id, this.gl.LINK_STATUS)) { - log(`filter: gl link failed: ${this.gl.getProgramInfoLog(this.id) || "unknown"}`); - return; - } - this.gl.useProgram(this.id); - collect(vertexSource, "attribute", this.attribute); - for (const a in this.attribute) - this.attribute[a] = this.gl.getAttribLocation(this.id, a); - collect(vertexSource, "uniform", this.uniform); - collect(fragmentSource, "uniform", this.uniform); - for (const u in this.uniform) - this.uniform[u] = this.gl.getUniformLocation(this.id, u); - } -}; -function GLImageFilter() { - let drawCount = 0; - let sourceTexture = null; - let lastInChain = false; - let currentFramebufferIndex = -1; - let tempFramebuffers = [null, null]; - let filterChain = []; - let vertexBuffer = null; - let currentProgram = null; - const fxcanvas = canvas(100, 100); - const shaderProgramCache = {}; - const DRAW = { INTERMEDIATE: 1 }; - const gl = fxcanvas.getContext("webgl"); - if (!gl) { - log("filter: cannot get webgl context"); - return; - } - this.gl = gl; - function resize(width, height) { - if (width === fxcanvas.width && height === fxcanvas.height) - return; - fxcanvas.width = width; - fxcanvas.height = height; - if (!vertexBuffer) { - const vertices = 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]); - vertexBuffer = gl.createBuffer(); - gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true); - } - gl.viewport(0, 0, fxcanvas.width, fxcanvas.height); - tempFramebuffers = [null, null]; - } - function createFramebufferTexture(width, height) { - const fbo = gl.createFramebuffer(); - gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); - const renderbuffer = gl.createRenderbuffer(); - gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer); - const texture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, texture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); - gl.bindTexture(gl.TEXTURE_2D, null); - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - return { fbo, texture }; - } - function getTempFramebuffer(index2) { - tempFramebuffers[index2] = tempFramebuffers[index2] || createFramebufferTexture(fxcanvas.width, fxcanvas.height); - return tempFramebuffers[index2]; - } - function draw(flags = 0) { - if (!currentProgram) - return; - let source = null; - let target = null; - let flipY = false; - if (drawCount === 0) - source = sourceTexture; - else - source = getTempFramebuffer(currentFramebufferIndex).texture || null; - drawCount++; - if (lastInChain && !(flags & DRAW.INTERMEDIATE)) { - target = null; - flipY = drawCount % 2 === 0; - } else { - currentFramebufferIndex = (currentFramebufferIndex + 1) % 2; - target = getTempFramebuffer(currentFramebufferIndex).fbo || null; - } - gl.bindTexture(gl.TEXTURE_2D, source); - gl.bindFramebuffer(gl.FRAMEBUFFER, target); - gl.uniform1f(currentProgram.uniform["flipY"], flipY ? -1 : 1); - gl.drawArrays(gl.TRIANGLES, 0, 6); - } - function compileShader(fragmentSource) { - if (shaderProgramCache[fragmentSource]) { - currentProgram = shaderProgramCache[fragmentSource]; - gl.useProgram((currentProgram ? currentProgram.id : null) || null); - return currentProgram; - } - currentProgram = new GLProgram(gl, vertexIdentity, fragmentSource); - if (!currentProgram) { - log("filter: could not get webgl program"); - return null; - } - const floatSize = Float32Array.BYTES_PER_ELEMENT; - const vertSize = 4 * floatSize; - gl.enableVertexAttribArray(currentProgram.attribute["pos"]); - gl.vertexAttribPointer(currentProgram.attribute["pos"], 2, gl.FLOAT, false, vertSize, 0 * floatSize); - gl.enableVertexAttribArray(currentProgram.attribute["uv"]); - gl.vertexAttribPointer(currentProgram.attribute["uv"], 2, gl.FLOAT, false, vertSize, 2 * floatSize); - shaderProgramCache[fragmentSource] = currentProgram; - return currentProgram; - } - const filter = { - colorMatrix: (matrix) => { - const m = new Float32Array(matrix); - m[4] /= 255; - m[9] /= 255; - m[14] /= 255; - m[19] /= 255; - const shader = m[18] === 1 && m[3] === 0 && m[8] === 0 && m[13] === 0 && m[15] === 0 && m[16] === 0 && m[17] === 0 && m[19] === 0 ? colorMatrixWithoutAlpha : colorMatrixWithAlpha; - const program = compileShader(shader); - if (!program) - return; - gl.uniform1fv(program.uniform["m"], m); - draw(); - }, - brightness: (brightness) => { - const b = (brightness || 0) + 1; - filter.colorMatrix([ - b, - 0, - 0, - 0, - 0, - 0, - b, - 0, - 0, - 0, - 0, - 0, - b, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - saturation: (amount) => { - const x = (amount || 0) * 2 / 3 + 1; - const y = (x - 1) * -0.5; - filter.colorMatrix([ - x, - y, - y, - 0, - 0, - y, - x, - y, - 0, - 0, - y, - y, - x, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - desaturate: () => { - filter.saturation(-1); - }, - contrast: (amount) => { - const v = (amount || 0) + 1; - const o = -128 * (v - 1); - filter.colorMatrix([ - v, - 0, - 0, - 0, - o, - 0, - v, - 0, - 0, - o, - 0, - 0, - v, - 0, - o, - 0, - 0, - 0, - 1, - 0 - ]); - }, - negative: () => { - filter.contrast(-2); - }, - hue: (rotation) => { - rotation = (rotation || 0) / 180 * Math.PI; - const cos = Math.cos(rotation); - const sin = Math.sin(rotation); - const lumR = 0.213; - const lumG = 0.715; - const lumB = 0.072; - filter.colorMatrix([ - lumR + cos * (1 - lumR) + sin * -lumR, - lumG + cos * -lumG + sin * -lumG, - lumB + cos * -lumB + sin * (1 - lumB), - 0, - 0, - lumR + cos * -lumR + sin * 0.143, - lumG + cos * (1 - lumG) + sin * 0.14, - lumB + cos * -lumB + sin * -0.283, - 0, - 0, - lumR + cos * -lumR + sin * -(1 - lumR), - lumG + cos * -lumG + sin * lumG, - lumB + cos * (1 - lumB) + sin * lumB, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - desaturateLuminance: () => { - filter.colorMatrix([ - 0.2764723, - 0.929708, - 0.0938197, - 0, - -37.1, - 0.2764723, - 0.929708, - 0.0938197, - 0, - -37.1, - 0.2764723, - 0.929708, - 0.0938197, - 0, - -37.1, - 0, - 0, - 0, - 1, - 0 - ]); - }, - sepia: () => { - filter.colorMatrix([ - 0.393, - 0.7689999, - 0.18899999, - 0, - 0, - 0.349, - 0.6859999, - 0.16799999, - 0, - 0, - 0.272, - 0.5339999, - 0.13099999, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - brownie: () => { - filter.colorMatrix([ - 0.5997023498159715, - 0.34553243048391263, - -0.2708298674538042, - 0, - 47.43192855600873, - -0.037703249837783157, - 0.8609577587992641, - 0.15059552388459913, - 0, - -36.96841498319127, - 0.24113635128153335, - -0.07441037908422492, - 0.44972182064877153, - 0, - -7.562075277591283, - 0, - 0, - 0, - 1, - 0 - ]); - }, - vintagePinhole: () => { - filter.colorMatrix([ - 0.6279345635605994, - 0.3202183420819367, - -0.03965408211312453, - 0, - 9.651285835294123, - 0.02578397704808868, - 0.6441188644374771, - 0.03259127616149294, - 0, - 7.462829176470591, - 0.0466055556782719, - -0.0851232987247891, - 0.5241648018700465, - 0, - 5.159190588235296, - 0, - 0, - 0, - 1, - 0 - ]); - }, - kodachrome: () => { - filter.colorMatrix([ - 1.1285582396593525, - -0.3967382283601348, - -0.03992559172921793, - 0, - 63.72958762196502, - -0.16404339962244616, - 1.0835251566291304, - -0.05498805115633132, - 0, - 24.732407896706203, - -0.16786010706155763, - -0.5603416277695248, - 1.6014850761964943, - 0, - 35.62982807460946, - 0, - 0, - 0, - 1, - 0 - ]); - }, - technicolor: () => { - filter.colorMatrix([ - 1.9125277891456083, - -0.8545344976951645, - -0.09155508482755585, - 0, - 11.793603434377337, - -0.3087833385928097, - 1.7658908555458428, - -0.10601743074722245, - 0, - -70.35205161461398, - -0.231103377548616, - -0.7501899197440212, - 1.847597816108189, - 0, - 30.950940869491138, - 0, - 0, - 0, - 1, - 0 - ]); - }, - polaroid: () => { - filter.colorMatrix([ - 1.438, - -0.062, - -0.062, - 0, - 0, - -0.122, - 1.378, - -0.122, - 0, - 0, - -0.016, - -0.016, - 1.483, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - shiftToBGR: () => { - filter.colorMatrix([ - 0, - 0, - 1, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - convolution: (matrix) => { - const m = new Float32Array(matrix); - const pixelSizeX = 1 / fxcanvas.width; - const pixelSizeY = 1 / fxcanvas.height; - const program = compileShader(convolution); - if (!program) - return; - gl.uniform1fv(program.uniform["m"], m); - gl.uniform2f(program.uniform["px"], pixelSizeX, pixelSizeY); - draw(); - }, - detectEdges: () => { - filter.convolution.call(this, [ - 0, - 1, - 0, - 1, - -4, - 1, - 0, - 1, - 0 - ]); - }, - sobelX: () => { - filter.convolution.call(this, [ - -1, - 0, - 1, - -2, - 0, - 2, - -1, - 0, - 1 - ]); - }, - sobelY: () => { - filter.convolution.call(this, [ - -1, - -2, - -1, - 0, - 0, - 0, - 1, - 2, - 1 - ]); - }, - sharpen: (amount) => { - const a = amount || 1; - filter.convolution.call(this, [ - 0, - -1 * a, - 0, - -1 * a, - 1 + 4 * a, - -1 * a, - 0, - -1 * a, - 0 - ]); - }, - emboss: (size2) => { - const s = size2 || 1; - filter.convolution.call(this, [ - -2 * s, - -1 * s, - 0, - -1 * s, - 1, - 1 * s, - 0, - 1 * s, - 2 * s - ]); - }, - blur: (size2) => { - const blurSizeX = size2 / 7 / fxcanvas.width; - const blurSizeY = size2 / 7 / fxcanvas.height; - const program = compileShader(blur); - if (!program) - return; - gl.uniform2f(program.uniform["px"], 0, blurSizeY); - draw(DRAW.INTERMEDIATE); - gl.uniform2f(program.uniform["px"], blurSizeX, 0); - draw(); - }, - pixelate: (size2) => { - const blurSizeX = size2 / fxcanvas.width; - const blurSizeY = size2 / fxcanvas.height; - const program = compileShader(pixelate); - if (!program) - return; - gl.uniform2f(program.uniform["size"], blurSizeX, blurSizeY); - draw(); - } - }; - this.add = function(name) { - const args = Array.prototype.slice.call(arguments, 1); - const func = filter[name]; - filterChain.push({ func, args }); - }; - this.reset = function() { - filterChain = []; - }; - this.get = function() { - return filterChain; - }; - this.apply = function(image28) { - resize(image28.width, image28.height); - drawCount = 0; - if (!sourceTexture) - sourceTexture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, sourceTexture); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image28); - for (let i = 0; i < filterChain.length; i++) { - lastInChain = i === filterChain.length - 1; - const f = filterChain[i]; - f.func.apply(this, f.args || []); - } - return fxcanvas; - }; - this.draw = function(image28) { - this.add("brightness", 0); - return this.apply(image28); - }; -} - -// src/image/enhance.ts -async function histogramEqualization(inputImage) { - const squeeze14 = inputImage.shape.length === 4 ? tfjs_esm_exports.squeeze(inputImage) : inputImage; - const rgb2 = tfjs_esm_exports.split(squeeze14, 3, 2); - const min2 = [tfjs_esm_exports.min(rgb2[0]), tfjs_esm_exports.min(rgb2[1]), tfjs_esm_exports.min(rgb2[2])]; - const max5 = [tfjs_esm_exports.max(rgb2[0]), tfjs_esm_exports.max(rgb2[1]), tfjs_esm_exports.max(rgb2[2])]; - const absMax = await Promise.all(max5.map((channel) => channel.data())); - const maxValue = Math.max(absMax[0][0], absMax[1][0], absMax[2][0]); - const maxRange = maxValue > 1 ? 255 : 1; - const factor = maxRange / maxValue; - let final; - if (factor > 1) { - const sub11 = [tfjs_esm_exports.sub(rgb2[0], min2[0]), tfjs_esm_exports.sub(rgb2[1], min2[1]), tfjs_esm_exports.sub(rgb2[2], min2[2])]; - const range = [tfjs_esm_exports.sub(max5[0], min2[0]), tfjs_esm_exports.sub(max5[1], min2[1]), tfjs_esm_exports.sub(max5[2], min2[2])]; - const enh = [tfjs_esm_exports.mul(sub11[0], factor), tfjs_esm_exports.mul(sub11[1], factor), tfjs_esm_exports.mul(sub11[2], factor)]; - const stack5 = tfjs_esm_exports.stack([enh[0], enh[1], enh[2]], 2); - final = tfjs_esm_exports.reshape(stack5, [1, squeeze14.shape[0] || 0, squeeze14.shape[1] || 0, 3]); - tfjs_esm_exports.dispose([...sub11, ...range, ...enh]); - } else { - final = tfjs_esm_exports.expandDims(squeeze14, 0); - } - tfjs_esm_exports.dispose([...rgb2, ...min2, ...max5, rgb2, squeeze14, inputImage]); - return final; -} - -// src/image/image.ts -var maxSize = 3840; -var inCanvas = null; -var outCanvas = null; -var tmpCanvas = null; -var fx; -var last = { - inputSum: 0, - cacheDiff: 1, - sumMethod: 0, - inputTensor: void 0 -}; -function reset() { - last.inputSum = 0; - last.cacheDiff = 1; - last.sumMethod = 0; - last.inputTensor = void 0; -} -function canvas(width, height) { - let c; - if (env.browser) { - if (env.worker) { - if (typeof OffscreenCanvas === "undefined") - throw new Error("canvas error: attempted to run in web worker but OffscreenCanvas is not supported"); - c = new OffscreenCanvas(width, height); - } else { - if (typeof document === "undefined") - throw new Error("canvas error: attempted to run in browser but DOM is not defined"); - c = document.createElement("canvas"); - c.width = width; - c.height = height; - } - } else { - if (typeof env.Canvas !== "undefined") - c = new env.Canvas(width, height); - else if (typeof globalThis.Canvas !== "undefined") - c = new globalThis.Canvas(width, height); - } - return c; -} -function copy(input, output) { - const outputCanvas = output || canvas(input.width, input.height); - const ctx = outputCanvas.getContext("2d"); - ctx.drawImage(input, 0, 0); - return outputCanvas; -} -async function process2(input, config3, getTensor = true) { - var _a, _b, _c; - if (!input) { - if (config3.debug) - log("input error: input is missing"); - return { tensor: null, canvas: null }; - } - if (!(input instanceof tfjs_esm_exports.Tensor) && !(typeof Image !== "undefined" && input instanceof Image) && !(typeof globalThis.Canvas !== "undefined" && input instanceof globalThis.Canvas) && !(typeof ImageData !== "undefined" && input instanceof ImageData) && !(typeof ImageBitmap !== "undefined" && input instanceof ImageBitmap) && !(typeof HTMLImageElement !== "undefined" && input instanceof HTMLImageElement) && !(typeof HTMLMediaElement !== "undefined" && input instanceof HTMLMediaElement) && !(typeof HTMLVideoElement !== "undefined" && input instanceof HTMLVideoElement) && !(typeof HTMLCanvasElement !== "undefined" && input instanceof HTMLCanvasElement) && !(typeof OffscreenCanvas !== "undefined" && input instanceof OffscreenCanvas)) { - throw new Error("input error: type not recognized"); - } - if (input instanceof tfjs_esm_exports.Tensor) { - let tensor7 = null; - if (input["isDisposedInternal"]) - throw new Error("input error: attempted to use tensor but it is disposed"); - if (!input.shape) - throw new Error("input error: attempted to use tensor without a shape"); - if (input.shape.length === 3) { - if (input.shape[2] === 3) { - tensor7 = tfjs_esm_exports.expandDims(input, 0); - } else if (input.shape[2] === 4) { - const rgb2 = tfjs_esm_exports.slice3d(input, [0, 0, 0], [-1, -1, 3]); - tensor7 = tfjs_esm_exports.expandDims(rgb2, 0); - tfjs_esm_exports.dispose(rgb2); - } - } else if (input.shape.length === 4) { - if (input.shape[3] === 3) { - tensor7 = tfjs_esm_exports.clone(input); - } else if (input.shape[3] === 4) { - tensor7 = tfjs_esm_exports.slice4d(input, [0, 0, 0, 0], [-1, -1, -1, 3]); - } - } - if (tensor7 == null || tensor7.shape.length !== 4 || tensor7.shape[0] !== 1 || tensor7.shape[3] !== 3) - throw new Error(`input error: attempted to use tensor with unrecognized shape: ${input.shape.toString()}`); - if (tensor7.dtype === "int32") { - const cast8 = tfjs_esm_exports.cast(tensor7, "float32"); - tfjs_esm_exports.dispose(tensor7); - tensor7 = cast8; - } - return { tensor: tensor7, canvas: config3.filter.return ? outCanvas : null }; - } - if (typeof input["readyState"] !== "undefined" && input.readyState <= 2) { - if (config3.debug) - log("input stream is not ready"); - return { tensor: null, canvas: inCanvas }; - } - const originalWidth = input["naturalWidth"] || input["videoWidth"] || input["width"] || input["shape"] && input["shape"][1] > 0; - const originalHeight = input["naturalHeight"] || input["videoHeight"] || input["height"] || input["shape"] && input["shape"][2] > 0; - if (!originalWidth || !originalHeight) { - if (config3.debug) - log("cannot determine input dimensions"); - return { tensor: null, canvas: inCanvas }; - } - let targetWidth = originalWidth; - let targetHeight = originalHeight; - if (targetWidth > maxSize) { - targetWidth = maxSize; - targetHeight = Math.trunc(targetWidth * originalHeight / originalWidth); - } - if (targetHeight > maxSize) { - targetHeight = maxSize; - targetWidth = Math.trunc(targetHeight * originalWidth / originalHeight); - } - if ((((_a = config3.filter) == null ? void 0 : _a.width) || 0) > 0) - targetWidth = config3.filter.width; - else if ((((_b = config3.filter) == null ? void 0 : _b.height) || 0) > 0) - targetWidth = originalWidth * ((config3.filter.height || 0) / originalHeight); - if ((config3.filter.height || 0) > 0) - targetHeight = config3.filter.height; - else if ((config3.filter.width || 0) > 0) - targetHeight = originalHeight * ((config3.filter.width || 0) / originalWidth); - if (!targetWidth || !targetHeight) - throw new Error("input error: cannot determine dimension"); - if (!inCanvas || inCanvas.width !== targetWidth || inCanvas.height !== targetHeight) - inCanvas = canvas(targetWidth, targetHeight); - const inCtx = inCanvas.getContext("2d"); - if (typeof ImageData !== "undefined" && input instanceof ImageData) { - inCtx.putImageData(input, 0, 0); - } else { - if (config3.filter.flip && typeof inCtx.translate !== "undefined") { - inCtx.translate(originalWidth, 0); - inCtx.scale(-1, 1); - inCtx.drawImage(input, 0, 0, originalWidth, originalHeight, 0, 0, inCanvas.width, inCanvas.height); - inCtx.setTransform(1, 0, 0, 1, 0, 0); - } else { - inCtx.drawImage(input, 0, 0, originalWidth, originalHeight, 0, 0, inCanvas.width, inCanvas.height); - } - } - if (!outCanvas || inCanvas.width !== outCanvas.width || inCanvas.height !== outCanvas.height) - outCanvas = canvas(inCanvas.width, inCanvas.height); - if (config3.filter.enabled && env.webgl.supported) { - if (!fx) - fx = env.browser ? new GLImageFilter() : null; - env.filter = !!fx; - if (!(fx == null ? void 0 : fx.add)) { - if (config3.debug) - log("input process error: cannot initialize filters"); - env.webgl.supported = false; - config3.filter.enabled = false; - copy(inCanvas, outCanvas); - } else { - fx.reset(); - if (config3.filter.brightness !== 0) - fx.add("brightness", config3.filter.brightness); - if (config3.filter.contrast !== 0) - fx.add("contrast", config3.filter.contrast); - if (config3.filter.sharpness !== 0) - fx.add("sharpen", config3.filter.sharpness); - if (config3.filter.blur !== 0) - fx.add("blur", config3.filter.blur); - if (config3.filter.saturation !== 0) - fx.add("saturation", config3.filter.saturation); - if (config3.filter.hue !== 0) - fx.add("hue", config3.filter.hue); - if (config3.filter.negative) - fx.add("negative"); - if (config3.filter.sepia) - fx.add("sepia"); - if (config3.filter.vintage) - fx.add("brownie"); - if (config3.filter.sepia) - fx.add("sepia"); - if (config3.filter.kodachrome) - fx.add("kodachrome"); - if (config3.filter.technicolor) - fx.add("technicolor"); - if (config3.filter.polaroid) - fx.add("polaroid"); - if (config3.filter.pixelate !== 0) - fx.add("pixelate", config3.filter.pixelate); - if (((_c = fx.get()) == null ? void 0 : _c.length) > 1) - outCanvas = fx.apply(inCanvas); - else - outCanvas = fx.draw(inCanvas); - } - } else { - copy(inCanvas, outCanvas); - if (fx) - fx = null; - env.filter = !!fx; - } - if (!getTensor) - return { tensor: null, canvas: outCanvas }; - if (!outCanvas) - throw new Error("canvas error: cannot create output"); - let pixels; - let depth = 3; - if (typeof ImageData !== "undefined" && input instanceof ImageData || input.data && input.width && input.height) { - if (env.browser && tfjs_esm_exports.browser) { - pixels = tfjs_esm_exports.browser ? tfjs_esm_exports.browser.fromPixels(input) : null; - } else { - depth = input.data.length / input.height / input.width; - const arr = new Uint8Array(input.data.buffer); - pixels = tfjs_esm_exports.tensor(arr, [input.height, input.width, depth], "int32"); - } - } else { - if (!tmpCanvas || outCanvas.width !== tmpCanvas.width || outCanvas.height !== tmpCanvas.height) - tmpCanvas = canvas(outCanvas.width, outCanvas.height); - if (tfjs_esm_exports.browser && env.browser) { - if (config3.backend === "webgl" || config3.backend === "humangl" || config3.backend === "webgpu") { - pixels = tfjs_esm_exports.browser.fromPixels(outCanvas); - } else { - tmpCanvas = copy(outCanvas); - pixels = tfjs_esm_exports.browser.fromPixels(tmpCanvas); - } - } else { - const tempCanvas = copy(outCanvas); - const tempCtx = tempCanvas.getContext("2d"); - const tempData = tempCtx.getImageData(0, 0, targetWidth, targetHeight); - depth = tempData.data.length / targetWidth / targetHeight; - const arr = new Uint8Array(tempData.data.buffer); - pixels = tfjs_esm_exports.tensor(arr, [targetWidth, targetHeight, depth]); - } - } - if (depth === 4) { - const rgb2 = tfjs_esm_exports.slice3d(pixels, [0, 0, 0], [-1, -1, 3]); - tfjs_esm_exports.dispose(pixels); - pixels = rgb2; - } - if (!pixels) - throw new Error("input error: cannot create tensor"); - const casted = tfjs_esm_exports.cast(pixels, "float32"); - const tensor6 = config3.filter.equalization ? await histogramEqualization(casted) : tfjs_esm_exports.expandDims(casted, 0); - tfjs_esm_exports.dispose([pixels, casted]); - if (config3.filter.autoBrightness) { - const max5 = tfjs_esm_exports.max(tensor6); - const maxVal = await max5.data(); - config3.filter.brightness = maxVal[0] > 1 ? 1 - maxVal[0] / 255 : 1 - maxVal[0]; - tfjs_esm_exports.dispose(max5); - } - return { tensor: tensor6, canvas: config3.filter.return ? outCanvas : null }; -} -async function skip(config3, input) { - let skipFrame = false; - if (config3.cacheSensitivity === 0 || !input.shape || input.shape.length !== 4 || input.shape[1] > 3840 || input.shape[2] > 2160) - return skipFrame; - if (!last.inputTensor) { - last.inputTensor = tfjs_esm_exports.clone(input); - } else if (last.inputTensor.shape[1] !== input.shape[1] || last.inputTensor.shape[2] !== input.shape[2]) { - tfjs_esm_exports.dispose(last.inputTensor); - last.inputTensor = tfjs_esm_exports.clone(input); - } else { - const t2 = {}; - t2.diff = tfjs_esm_exports.sub(input, last.inputTensor); - t2.squared = tfjs_esm_exports.mul(t2.diff, t2.diff); - t2.sum = tfjs_esm_exports.sum(t2.squared); - const diffSum = await t2.sum.data(); - const diffRelative = diffSum[0] / (input.shape[1] || 1) / (input.shape[2] || 1) / 255 / 3; - tfjs_esm_exports.dispose([last.inputTensor, t2.diff, t2.squared, t2.sum]); - last.inputTensor = tfjs_esm_exports.clone(input); - skipFrame = diffRelative <= (config3.cacheSensitivity || 0); - } - return skipFrame; -} -async function compare(config3, input1, input2) { - const t2 = {}; - if (!input1 || !input2 || input1.shape.length !== 4 || input1.shape.length !== input2.shape.length) { - if (!config3.debug) - log("invalid input tensor or tensor shapes do not match:", input1.shape, input2.shape); - return 0; - } - if (input1.shape[0] !== 1 || input2.shape[0] !== 1 || input1.shape[3] !== 3 || input2.shape[3] !== 3) { - if (!config3.debug) - log("input tensors must be of shape [1, height, width, 3]:", input1.shape, input2.shape); - return 0; - } - t2.input1 = tfjs_esm_exports.clone(input1); - t2.input2 = input1.shape[1] !== input2.shape[1] || input1.shape[2] !== input2.shape[2] ? tfjs_esm_exports.image.resizeBilinear(input2, [input1.shape[1], input1.shape[2]]) : tfjs_esm_exports.clone(input2); - t2.diff = tfjs_esm_exports.sub(t2.input1, t2.input2); - t2.squared = tfjs_esm_exports.mul(t2.diff, t2.diff); - t2.sum = tfjs_esm_exports.sum(t2.squared); - const diffSum = await t2.sum.data(); - const diffRelative = diffSum[0] / (input1.shape[1] || 1) / (input1.shape[2] || 1) / 255 / 3; - tfjs_esm_exports.dispose([t2.input1, t2.input2, t2.diff, t2.squared, t2.sum]); - return diffRelative; -} - -// src/util/env.ts -var _canvas, _image, _imageData; -var Env = class { - constructor() { - __publicField(this, "browser"); - __publicField(this, "node"); - __publicField(this, "worker"); - __publicField(this, "platform", ""); - __publicField(this, "agent", ""); - __publicField(this, "backends", []); - __publicField(this, "initial"); - __publicField(this, "filter"); - __publicField(this, "tfjs"); - __publicField(this, "offscreen"); - __publicField(this, "perfadd", false); - __publicField(this, "tensorflow", { - version: void 0, - gpu: void 0 - }); - __publicField(this, "wasm", { - supported: void 0, - backend: void 0, - simd: void 0, - multithread: void 0 - }); - __publicField(this, "webgl", { - supported: void 0, - backend: void 0, - version: void 0, - renderer: void 0, - shader: void 0, - vendor: void 0 - }); - __publicField(this, "webgpu", { - supported: void 0, - backend: void 0, - adapter: void 0 - }); - __publicField(this, "cpu", { - model: void 0, - flags: [] - }); - __publicField(this, "kernels", []); - __privateAdd(this, _canvas, void 0); - __privateAdd(this, _image, void 0); - __privateAdd(this, _imageData, void 0); - this.browser = typeof navigator !== "undefined"; - this.node = typeof process !== "undefined" && typeof process.versions !== "undefined" && typeof process.versions.node !== "undefined"; - this.tfjs = { version: version7["tfjs-core"] }; - this.offscreen = typeof OffscreenCanvas !== "undefined"; - this.initial = true; - this.worker = this.browser && this.offscreen ? typeof WorkerGlobalScope !== "undefined" : void 0; - if (typeof navigator !== "undefined") { - const raw = navigator.userAgent.match(/\(([^()]+)\)/g); - if (raw == null ? void 0 : raw[0]) { - const platformMatch = raw[0].match(/\(([^()]+)\)/g); - this.platform = (platformMatch == null ? void 0 : platformMatch[0]) ? platformMatch[0].replace(/\(|\)/g, "") : ""; - this.agent = navigator.userAgent.replace(raw[0], ""); - if (this.platform[1]) - this.agent = this.agent.replace(raw[1], ""); - this.agent = this.agent.replace(/ /g, " "); - } - } else if (typeof process !== "undefined") { - this.platform = `${process.platform} ${process.arch}`; - this.agent = `NodeJS ${process.version}`; - } - } - get Canvas() { - return __privateGet(this, _canvas); - } - set Canvas(val) { - __privateSet(this, _canvas, val); - globalThis.Canvas = val; - } - get Image() { - return __privateGet(this, _image); - } - set Image(val) { - __privateSet(this, _image, val); - globalThis.Image = val; - } - get ImageData() { - return __privateGet(this, _imageData); - } - set ImageData(val) { - __privateSet(this, _imageData, val); - globalThis.ImageData = val; - } - async updateBackend() { - this.backends = Object.keys(tfjs_esm_exports.engine().registryFactory); - try { - this.tensorflow = { - version: tfjs_esm_exports.backend()["binding"] ? tfjs_esm_exports.backend()["binding"].TF_Version : void 0, - gpu: tfjs_esm_exports.backend()["binding"] ? tfjs_esm_exports.backend()["binding"].isUsingGpuDevice() : void 0 - }; - } catch (e) { - } - this.wasm.supported = typeof WebAssembly !== "undefined"; - this.wasm.backend = this.backends.includes("wasm"); - if (this.wasm.supported && this.wasm.backend) { - this.wasm.simd = await tfjs_esm_exports.env().getAsync("WASM_HAS_SIMD_SUPPORT"); - this.wasm.multithread = await tfjs_esm_exports.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"); - } - const c = canvas(100, 100); - const gl = c ? c.getContext("webgl2") : void 0; - this.webgl.supported = typeof gl !== "undefined"; - this.webgl.backend = this.backends.includes("webgl"); - if (this.webgl.supported && this.webgl.backend && gl) { - this.webgl.version = gl.getParameter(gl.VERSION); - this.webgl.vendor = gl.getParameter(gl.VENDOR); - this.webgl.renderer = gl.getParameter(gl.RENDERER); - this.webgl.shader = gl.getParameter(gl.SHADING_LANGUAGE_VERSION); - } - this.webgpu.supported = this.browser && typeof navigator.gpu !== "undefined"; - this.webgpu.backend = this.backends.includes("webgpu"); - try { - if (this.webgpu.supported) { - const adapter = await navigator.gpu.requestAdapter(); - this.webgpu.adapter = await (adapter == null ? void 0 : adapter.requestAdapterInfo()); - } - } catch (e) { - this.webgpu.supported = false; - } - try { - this.kernels = tfjs_esm_exports.getKernelsForBackend(tfjs_esm_exports.getBackend()).map((kernel) => kernel.kernelName.toLowerCase()); - } catch (e) { - } - } - updateCPU() { - const cpu = { model: "", flags: [] }; - if (this.node && this.platform.startsWith("linux")) { - } - if (!this.cpu) - Object.defineProperty(this, "cpu", { value: cpu }); - else - this.cpu = cpu; - } -}; -_canvas = new WeakMap(); -_image = new WeakMap(); -_imageData = new WeakMap(); -var env = new Env(); - -// src/util/webcam.ts -var WebCam = class { - constructor() { - __publicField(this, "config"); - __publicField(this, "element"); - __publicField(this, "stream"); - __publicField(this, "devices", []); - __publicField(this, "enumerate", async () => { - try { - const devices = await navigator.mediaDevices.enumerateDevices(); - this.devices = devices.filter((device) => device.kind === "videoinput"); - } catch (e) { - this.devices = []; - } - return this.devices; - }); - __publicField(this, "start", async (webcamConfig) => { - var _a, _b; - if (webcamConfig == null ? void 0 : webcamConfig.debug) - this.config.debug = webcamConfig == null ? void 0 : webcamConfig.debug; - if (webcamConfig == null ? void 0 : webcamConfig.crop) - this.config.crop = webcamConfig == null ? void 0 : webcamConfig.crop; - if (webcamConfig == null ? void 0 : webcamConfig.mode) - this.config.mode = webcamConfig == null ? void 0 : webcamConfig.mode; - if (webcamConfig == null ? void 0 : webcamConfig.width) - this.config.width = webcamConfig == null ? void 0 : webcamConfig.width; - if (webcamConfig == null ? void 0 : webcamConfig.height) - this.config.height = webcamConfig == null ? void 0 : webcamConfig.height; - if (webcamConfig == null ? void 0 : webcamConfig.id) - this.config.id = webcamConfig == null ? void 0 : webcamConfig.id; - if (webcamConfig == null ? void 0 : webcamConfig.element) { - if (typeof webcamConfig.element === "string") { - const el = document.getElementById(webcamConfig.element); - if (el && el instanceof HTMLVideoElement) { - this.element = el; - } else { - if (this.config.debug) - log("webcam", "cannot get dom element", webcamConfig.element); - return; - } - } else if (webcamConfig.element instanceof HTMLVideoElement) { - this.element = webcamConfig.element; - } else { - if (this.config.debug) - log("webcam", "unknown dom element", webcamConfig.element); - return; - } - } else { - this.element = document.createElement("video"); - } - const requestedConstraints = { - audio: false, - video: { - facingMode: this.config.mode === "front" ? "user" : "environment", - resizeMode: this.config.crop ? "crop-and-scale" : "none" - } - }; - if (((_a = this.config) == null ? void 0 : _a.width) > 0) - requestedConstraints.video.width = { ideal: this.config.width }; - if (((_b = this.config) == null ? void 0 : _b.height) > 0) - requestedConstraints.video.height = { ideal: this.config.height }; - if (this.config.id) - requestedConstraints.video.deviceId = this.config.id; - this.element.addEventListener("play", () => { - if (this.config.debug) - log("webcam", "play"); - }); - this.element.addEventListener("pause", () => { - if (this.config.debug) - log("webcam", "pause"); - }); - this.element.addEventListener("click", async () => { - if (!this.element || !this.stream) - return; - if (this.element.paused) - await this.element.play(); - else - this.element.pause(); - }); - if (!(navigator == null ? void 0 : navigator.mediaDevices)) { - if (this.config.debug) - log("webcam", "no devices"); - return; - } - try { - this.stream = await navigator.mediaDevices.getUserMedia(requestedConstraints); - } catch (err) { - log("webcam", err); - return; - } - if (!this.stream) { - if (this.config.debug) - log("webcam", "no stream"); - return; - } - this.element.srcObject = this.stream; - const ready3 = new Promise((resolve) => { - if (!this.element) - resolve(false); - else - this.element.onloadeddata = () => resolve(true); - }); - await ready3; - await this.element.play(); - if (this.config.debug) { - log("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 - }); - } - }); - __publicField(this, "pause", () => { - if (this.element) - this.element.pause(); - }); - __publicField(this, "play", async () => { - if (this.element) - await this.element.play(); - }); - __publicField(this, "stop", () => { - if (this.config.debug) - log("webcam", "stop"); - if (this.track) - this.track.stop(); - }); - this.config = { - element: void 0, - debug: true, - mode: "front", - crop: false, - width: 0, - height: 0 - }; - } - get track() { - if (!this.stream) - return void 0; - return this.stream.getVideoTracks()[0]; - } - get capabilities() { - if (!this.track) - return void 0; - return this.track.getCapabilities ? this.track.getCapabilities() : void 0; - } - get constraints() { - if (!this.track) - return void 0; - return this.track.getConstraints ? this.track.getConstraints() : void 0; - } - get settings() { - if (!this.stream) - return void 0; - const track = this.stream.getVideoTracks()[0]; - return track.getSettings ? track.getSettings() : void 0; - } - get label() { - if (!this.track) - return ""; - return this.track.label; - } - get paused() { - var _a; - return ((_a = this.element) == null ? void 0 : _a.paused) || false; - } - get width() { - var _a; - return ((_a = this.element) == null ? void 0 : _a.videoWidth) || 0; - } - get height() { - var _a; - return ((_a = this.element) == null ? void 0 : _a.videoHeight) || 0; - } -}; - -// models/models.json -var models_exports = {}; -__export(models_exports, { - age: () => age, - "anti-spoofing": () => anti_spoofing, - antispoof: () => antispoof, - blazeface: () => blazeface, - "blazeface-back": () => blazeface_back, - "blazeface-front": () => blazeface_front, - "blazepose-detector": () => blazepose_detector, - "blazepose-full": () => blazepose_full, - "blazepose-heavy": () => blazepose_heavy, - "blazepose-lite": () => blazepose_lite, - centernet: () => centernet, - default: () => models_default, - efficientpose: () => efficientpose, - "efficientpose-i-lite": () => efficientpose_i_lite, - "efficientpose-ii-lite": () => efficientpose_ii_lite, - "efficientpose-iv": () => efficientpose_iv, - emotion: () => emotion, - faceboxes: () => faceboxes, - facemesh: () => facemesh, - "facemesh-attention": () => facemesh_attention, - "facemesh-attention-pinto": () => facemesh_attention_pinto, - "facemesh-detection-full": () => facemesh_detection_full, - "facemesh-detection-short": () => facemesh_detection_short, - faceres: () => faceres, - "faceres-deep": () => faceres_deep, - gear: () => gear, - gender: () => gender, - "gender-ssrnet-imdb": () => gender_ssrnet_imdb, - handdetect: () => handdetect, - "handlandmark-full": () => handlandmark_full, - "handlandmark-lite": () => handlandmark_lite, - "handlandmark-sparse": () => handlandmark_sparse, - handskeleton: () => handskeleton, - handtrack: () => handtrack, - "insightface-efficientnet-b0": () => insightface_efficientnet_b0, - "insightface-ghostnet-strides1": () => insightface_ghostnet_strides1, - "insightface-ghostnet-strides2": () => insightface_ghostnet_strides2, - "insightface-mobilenet-emore": () => insightface_mobilenet_emore, - "insightface-mobilenet-swish": () => insightface_mobilenet_swish, - iris: () => iris, - liveness: () => liveness, - meet: () => meet, - mobileface: () => mobileface, - mobilefacenet: () => mobilefacenet, - models: () => models, - "movenet-lightning": () => movenet_lightning, - "movenet-multipose": () => movenet_multipose, - "movenet-thunder": () => movenet_thunder, - nanodet: () => nanodet, - "nanodet-e": () => nanodet_e, - "nanodet-g": () => nanodet_g, - "nanodet-m": () => nanodet_m, - "nanodet-t": () => nanodet_t, - posenet: () => posenet, - rvm: () => rvm, - selfie: () => selfie -}); -var antispoof = 853098; -var blazeface = 538928; -var centernet = 4030290; -var emotion = 820516; -var facemesh = 1477958; -var faceres = 6978814; -var handlandmark_lite = 2023432; -var handtrack = 2964837; -var iris = 2599092; -var liveness = 592976; -var models = 0; -var movenet_lightning = 4650216; -var age = 161240; -var blazeface_back = 538928; -var blazeface_front = 402048; -var blazepose_detector = 5928856; -var blazepose_full = 6339202; -var blazepose_heavy = 27502466; -var blazepose_lite = 2726402; -var efficientpose = 5651240; -var faceboxes = 2013002; -var facemesh_attention_pinto = 2387598; -var facemesh_attention = 2382414; -var facemesh_detection_full = 1026192; -var facemesh_detection_short = 201268; -var faceres_deep = 13957620; -var gear = 1498916; -var gender_ssrnet_imdb = 161236; -var gender = 201808; -var handdetect = 3515612; -var handlandmark_full = 5431368; -var handlandmark_sparse = 5286322; -var handskeleton = 5502280; -var meet = 372228; -var mobileface = 2183192; -var mobilefacenet = 5171976; -var movenet_multipose = 9448838; -var movenet_thunder = 12477112; -var nanodet = 7574558; -var posenet = 5032780; -var rvm = 3739355; -var selfie = 212886; -var anti_spoofing = 853098; -var efficientpose_i_lite = 2269064; -var efficientpose_ii_lite = 5651240; -var efficientpose_iv = 25643252; -var insightface_efficientnet_b0 = 13013224; -var insightface_ghostnet_strides1 = 8093408; -var insightface_ghostnet_strides2 = 8049584; -var insightface_mobilenet_emore = 6938536; -var insightface_mobilenet_swish = 12168584; -var nanodet_e = 12319156; -var nanodet_g = 7574558; -var nanodet_m = 1887474; -var nanodet_t = 5294216; -var models_default = { - antispoof, - blazeface, - centernet, - emotion, - facemesh, - faceres, - "handlandmark-lite": handlandmark_lite, - handtrack, - iris, - liveness, - models, - "movenet-lightning": movenet_lightning, - age, - "blazeface-back": blazeface_back, - "blazeface-front": blazeface_front, - "blazepose-detector": blazepose_detector, - "blazepose-full": blazepose_full, - "blazepose-heavy": blazepose_heavy, - "blazepose-lite": blazepose_lite, - efficientpose, - faceboxes, - "facemesh-attention-pinto": facemesh_attention_pinto, - "facemesh-attention": facemesh_attention, - "facemesh-detection-full": facemesh_detection_full, - "facemesh-detection-short": facemesh_detection_short, - "faceres-deep": faceres_deep, - gear, - "gender-ssrnet-imdb": gender_ssrnet_imdb, - gender, - handdetect, - "handlandmark-full": handlandmark_full, - "handlandmark-sparse": handlandmark_sparse, - handskeleton, - meet, - mobileface, - mobilefacenet, - "movenet-multipose": movenet_multipose, - "movenet-thunder": movenet_thunder, - nanodet, - posenet, - rvm, - selfie, - "anti-spoofing": anti_spoofing, - "efficientpose-i-lite": efficientpose_i_lite, - "efficientpose-ii-lite": efficientpose_ii_lite, - "efficientpose-iv": efficientpose_iv, - "insightface-efficientnet-b0": insightface_efficientnet_b0, - "insightface-ghostnet-strides1": insightface_ghostnet_strides1, - "insightface-ghostnet-strides2": insightface_ghostnet_strides2, - "insightface-mobilenet-emore": insightface_mobilenet_emore, - "insightface-mobilenet-swish": insightface_mobilenet_swish, - "nanodet-e": nanodet_e, - "nanodet-g": nanodet_g, - "nanodet-m": nanodet_m, - "nanodet-t": nanodet_t -}; - -// src/tfjs/load.ts -var options = { - cacheModels: true, - cacheSupported: true, - verbose: true, - debug: false, - modelBasePath: "" -}; -var modelStats = {}; -async function httpHandler(url, init4) { - if (options.debug) - log("load model fetch:", url, init4); - return fetch(url, init4); -} -function setModelLoadOptions(config3) { - options.cacheModels = config3.cacheModels; - options.verbose = config3.debug; - options.modelBasePath = config3.modelBasePath; -} -async function loadModel(modelPath) { - var _a, _b, _c, _d; - let modelUrl = join(options.modelBasePath, modelPath || ""); - if (!modelUrl.toLowerCase().endsWith(".json")) - modelUrl += ".json"; - const modelPathSegments = modelUrl.includes("/") ? modelUrl.split("/") : modelUrl.split("\\"); - const shortModelName = modelPathSegments[modelPathSegments.length - 1].replace(".json", ""); - const cachedModelName = "indexeddb://" + shortModelName; - modelStats[shortModelName] = { - name: shortModelName, - sizeFromManifest: 0, - sizeLoadedWeights: 0, - sizeDesired: models_exports[shortModelName], - inCache: false, - url: "" - }; - options.cacheSupported = typeof indexedDB !== "undefined"; - let cachedModels = {}; - try { - cachedModels = options.cacheSupported && options.cacheModels ? await tfjs_esm_exports.io.listModels() : {}; - } catch (e) { - options.cacheSupported = false; - } - modelStats[shortModelName].inCache = options.cacheSupported && options.cacheModels && Object.keys(cachedModels).includes(cachedModelName); - modelStats[shortModelName].url = modelStats[shortModelName].inCache ? cachedModelName : modelUrl; - const tfLoadOptions = typeof fetch === "undefined" ? {} : { fetchFunc: (url, init4) => httpHandler(url, init4) }; - let model23 = new tfjs_esm_exports.GraphModel(modelStats[shortModelName].url, tfLoadOptions); - let loaded = false; - try { - model23.findIOHandler(); - if (options.debug) - log("model load handler:", model23["handler"]); - } catch (err) { - log("error finding model i/o handler:", modelUrl, err); - } - try { - const artifacts = await ((_a = model23.handler) == null ? void 0 : _a.load()) || null; - modelStats[shortModelName].sizeFromManifest = ((_b = artifacts == null ? void 0 : artifacts.weightData) == null ? void 0 : _b.byteLength) || 0; - if (artifacts) - model23.loadSync(artifacts); - else - model23 = await tfjs_esm_exports.loadGraphModel(modelStats[shortModelName].inCache ? cachedModelName : modelUrl, tfLoadOptions); - modelStats[shortModelName].sizeLoadedWeights = ((_d = (_c = model23.artifacts) == null ? void 0 : _c.weightData) == null ? void 0 : _d.byteLength) || 0; - if (options.verbose) - log("load:", { model: shortModelName, url: model23["modelUrl"], bytes: modelStats[shortModelName].sizeLoadedWeights }); - loaded = true; - } catch (err) { - log("error loading model:", modelUrl, err); - } - if (loaded && options.cacheModels && options.cacheSupported && !modelStats[shortModelName].inCache) { - try { - const saveResult = await model23.save(cachedModelName); - if (options.debug) - log("model saved:", cachedModelName, saveResult); - } catch (err) { - log("error saving model:", modelUrl, err); - } - } - return model23; -} - -// package.json -var version8 = "3.0.2"; - -// src/tfjs/humangl.ts -var config2 = { - name: "humangl", - priority: 999, - canvas: null, - gl: null, - extensions: [], - webGLattr: { - alpha: false, - antialias: false, - premultipliedAlpha: false, - preserveDrawingBuffer: false, - depth: false, - stencil: false, - failIfMajorPerformanceCaveat: false, - desynchronized: true - } -}; -function extensions() { - const gl = config2.gl; - if (!gl) - return; - config2.extensions = gl.getSupportedExtensions(); -} -function register(instance) { - var _a; - if (instance.config.backend !== "humangl") - return; - if (config2.name in tfjs_esm_exports.engine().registry && !((_a = config2 == null ? void 0 : config2.gl) == null ? void 0 : _a.getParameter(config2.gl.VERSION))) { - log("humangl error: backend invalid context"); - instance.models.reset(); - } - if (!tfjs_esm_exports.findBackend(config2.name)) { - try { - config2.canvas = canvas(100, 100); - } catch (err) { - log("humangl error: cannot create canvas:", err); - return; - } - try { - config2.gl = config2.canvas.getContext("webgl2", config2.webGLattr); - if (!config2.gl) { - log("humangl error: cannot get webgl context"); - return; - } - const glv2 = config2.gl.getParameter(config2.gl.VERSION).includes("2.0"); - if (!glv2) { - log("backend override: using fallback webgl backend as webgl 2.0 is not detected"); - instance.config.backend = "webgl"; - return; - } - if (config2.canvas) { - config2.canvas.addEventListener("webglcontextlost", (e) => { - log("humangl error:", e.type); - log("possible browser memory leak using webgl or conflict with multiple backend registrations"); - instance.emit("error"); - throw new Error("backend error: webgl context lost"); - }); - config2.canvas.addEventListener("webglcontextrestored", (e) => { - log("humangl error: context restored:", e); - }); - config2.canvas.addEventListener("webglcontextcreationerror", (e) => { - log("humangl error: context create:", e); - }); - } - } catch (err) { - log("humangl error: cannot get webgl context:", err); - return; - } - try { - tfjs_esm_exports.setWebGLContext(2, config2.gl); - } catch (err) { - log("humangl error: cannot set webgl context:", err); - return; - } - try { - const ctx = new tfjs_esm_exports.GPGPUContext(config2.gl); - tfjs_esm_exports.registerBackend(config2.name, () => new tfjs_esm_exports.MathBackendWebGL(ctx), config2.priority); - } catch (err) { - log("humangl error: cannot register webgl backend:", err); - return; - } - try { - const kernels = tfjs_esm_exports.getKernelsForBackend("webgl"); - kernels.forEach((kernelConfig) => { - const newKernelConfig = { ...kernelConfig, backendName: config2.name }; - tfjs_esm_exports.registerKernel(newKernelConfig); - }); - } catch (err) { - log("humangl error: cannot update webgl backend registration:", err); - return; - } - try { - if (tfjs_esm_exports.env().flagRegistry.WEBGL_VERSION) - tfjs_esm_exports.env().set("WEBGL_VERSION", 2); - } catch (err) { - log("humangl error: cannot set WebGL backend flags:", err); - return; - } - extensions(); - const backend4 = tfjs_esm_exports.backend(); - const current = typeof backend4["gpgpu"] !== "undefined" ? backend4["getGPGPUContext"]().gl : null; - if (current) { - if (instance.config.debug) - log("humangl backend registered:", { webgl: current.getParameter(current.VERSION), renderer: current.getParameter(current.RENDERER) }); - } else { - log("humangl error: no current gl context:", current, config2.gl); - } - } -} - -// src/tfjs/constants.ts -var constants = { - tf255: 255, - tf1: 1, - tf2: 2, - tf05: 0.5, - tf127: 127.5, - rgb: [0.2989, 0.587, 0.114] -}; -function init() { - constants.tf255 = tfjs_esm_exports.scalar(255, "float32"); - constants.tf1 = tfjs_esm_exports.scalar(1, "float32"); - constants.tf2 = tfjs_esm_exports.scalar(2, "float32"); - constants.tf05 = tfjs_esm_exports.scalar(0.5, "float32"); - constants.tf127 = tfjs_esm_exports.scalar(127.5, "float32"); - constants.rgb = tfjs_esm_exports.tensor1d([0.2989, 0.587, 0.114], "float32"); -} - -// src/tfjs/backend.ts -async function getBestBackend() { - var _a; - await env.updateBackend(); - if ((_a = env.tensorflow) == null ? void 0 : _a.version) - return "tensorflow"; - if (env.webgpu.supported && env.webgpu.backend) - return "webgpu"; - if (env.webgl.supported && env.webgl.backend) - return "webgl"; - if (env.wasm.supported && env.wasm.backend) - return "wasm"; - return "cpu"; -} -function registerCustomOps(config3) { - const newKernels = []; - if (!env.kernels.includes("mod")) { - const kernelMod = { - kernelName: "Mod", - backendName: tfjs_esm_exports.getBackend(), - kernelFunc: (op) => tfjs_esm_exports.tidy(() => tfjs_esm_exports.sub(op.inputs.a, tfjs_esm_exports.mul(tfjs_esm_exports.div(op.inputs.a, op.inputs.b), op.inputs.b))) - }; - tfjs_esm_exports.registerKernel(kernelMod); - env.kernels.push("mod"); - newKernels.push("mod"); - } - if (!env.kernels.includes("floormod")) { - const kernelFloorMod = { - kernelName: "FloorMod", - backendName: tfjs_esm_exports.getBackend(), - kernelFunc: (op) => tfjs_esm_exports.tidy(() => tfjs_esm_exports.add(tfjs_esm_exports.mul(tfjs_esm_exports.floorDiv(op.inputs.a, op.inputs.b), op.inputs.b), tfjs_esm_exports.mod(op.inputs.a, op.inputs.b))) - }; - tfjs_esm_exports.registerKernel(kernelFloorMod); - env.kernels.push("floormod"); - newKernels.push("floormod"); - } - if (!env.kernels.includes("rotatewithoffset") && config3.softwareKernels) { - const kernelRotateWithOffset = { - kernelName: "RotateWithOffset", - backendName: tfjs_esm_exports.getBackend(), - kernelFunc: (op) => tfjs_esm_exports.tidy(() => { - const backend4 = tfjs_esm_exports.getBackend(); - tfjs_esm_exports.setBackend("cpu"); - const t2 = tfjs_esm_exports.image.rotateWithOffset(op.inputs.image, op.attrs.radians, op.attrs.fillValue, op.attrs.center); - tfjs_esm_exports.setBackend(backend4); - return t2; - }) - }; - tfjs_esm_exports.registerKernel(kernelRotateWithOffset); - env.kernels.push("rotatewithoffset"); - newKernels.push("rotatewithoffset"); - } - if (newKernels.length > 0 && config3.debug) - log("registered kernels:", newKernels); -} -var defaultFlags = {}; -async function check(instance, force = false) { - var _a; - instance.state = "backend"; - if (((_a = instance.config.backend) == null ? void 0 : _a.length) === 0) - instance.config.backend = await getBestBackend(); - if (force || env.initial || instance.config.backend && instance.config.backend.length > 0 && tfjs_esm_exports.getBackend() !== instance.config.backend) { - const timeStamp = now(); - if (instance.config.backend && instance.config.backend.length > 0) { - if (typeof window === "undefined" && typeof WorkerGlobalScope !== "undefined" && instance.config.debug) { - if (instance.config.debug) - log("running inside web worker"); - } - if (env.browser && instance.config.backend === "tensorflow") { - if (instance.config.debug) - log("override: backend set to tensorflow while running in browser"); - instance.config.backend = "webgl"; - } - if (env.node && (instance.config.backend === "webgl" || instance.config.backend === "humangl")) { - if (instance.config.debug) - log(`override: backend set to ${instance.config.backend} while running in nodejs`); - instance.config.backend = "tensorflow"; - } - if (env.browser && instance.config.backend === "webgpu") { - if (typeof navigator === "undefined" || typeof navigator.gpu === "undefined") { - log("override: backend set to webgpu but browser does not support webgpu"); - instance.config.backend = "webgl"; - } else { - const adapter = await navigator.gpu.requestAdapter(); - if (instance.config.debug) - log("enumerated webgpu adapter:", adapter); - if (!adapter) { - log("override: backend set to webgpu but browser reports no available gpu"); - instance.config.backend = "webgl"; - } else { - const adapterInfo = "requestAdapterInfo" in adapter ? await adapter.requestAdapterInfo() : void 0; - log("webgpu adapter info:", adapterInfo); - } - } - } - let available = Object.keys(tfjs_esm_exports.engine().registryFactory); - if (instance.config.backend === "humangl" && !available.includes("humangl")) { - register(instance); - available = Object.keys(tfjs_esm_exports.engine().registryFactory); - } - if (instance.config.debug) - log("available backends:", available); - if (!available.includes(instance.config.backend)) { - log(`error: backend ${instance.config.backend} not found in registry`); - instance.config.backend = env.node ? "tensorflow" : "webgl"; - if (instance.config.debug) - log(`override: setting backend ${instance.config.backend}`); - } - if (instance.config.debug) - log("setting backend:", [instance.config.backend]); - if (instance.config.backend === "wasm") { - if (tfjs_esm_exports.env().flagRegistry.CANVAS2D_WILL_READ_FREQUENTLY) - tfjs_esm_exports.env().set("CANVAS2D_WILL_READ_FREQUENTLY", true); - if (instance.config.debug) - log("wasm path:", instance.config.wasmPath); - if (typeof tfjs_esm_exports.setWasmPaths !== "undefined") - tfjs_esm_exports.setWasmPaths(instance.config.wasmPath, instance.config.wasmPlatformFetch); - else - throw new Error("backend error: attempting to use wasm backend but wasm path is not set"); - let mt = false; - let simd = false; - try { - mt = await tfjs_esm_exports.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"); - simd = await tfjs_esm_exports.env().getAsync("WASM_HAS_SIMD_SUPPORT"); - if (instance.config.debug) - log(`wasm execution: ${simd ? "simd" : "no simd"} ${mt ? "multithreaded" : "singlethreaded"}`); - if (instance.config.debug && !simd) - log("warning: wasm simd support is not enabled"); - } catch (e) { - log("wasm detection failed"); - } - } - try { - await tfjs_esm_exports.setBackend(instance.config.backend); - await tfjs_esm_exports.ready(); - } catch (err) { - log("error: cannot set backend:", instance.config.backend, err); - return false; - } - if (instance.config.debug) - defaultFlags = JSON.parse(JSON.stringify(tfjs_esm_exports.env().flags)); - } - if (tfjs_esm_exports.getBackend() === "humangl" || tfjs_esm_exports.getBackend() === "webgl") { - if (tfjs_esm_exports.env().flagRegistry.WEBGL_USE_SHAPES_UNIFORMS) - tfjs_esm_exports.env().set("WEBGL_USE_SHAPES_UNIFORMS", true); - if (tfjs_esm_exports.env().flagRegistry.WEBGL_EXP_CONV) - tfjs_esm_exports.env().set("WEBGL_EXP_CONV", true); - if (instance.config.debug && typeof instance.config.deallocate !== "undefined" && instance.config.deallocate) { - log("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:", true); - tfjs_esm_exports.env().set("WEBGL_DELETE_TEXTURE_THRESHOLD", 0); - } - } - if (tfjs_esm_exports.getBackend() === "webgpu") { - } - if (instance.config.debug) { - const newFlags = tfjs_esm_exports.env().flags; - const updatedFlags = {}; - for (const key of Object.keys(newFlags)) { - if (defaultFlags[key] === newFlags[key]) - continue; - updatedFlags[key] = newFlags[key]; - } - if (instance.config.debug && Object.keys(updatedFlags).length > 0) - log("backend:", tfjs_esm_exports.getBackend(), "flags:", updatedFlags); - } - if (instance.config.flags && Object.keys(instance.config.flags).length > 0) { - if (instance.config.debug) - log("flags:", instance.config["flags"]); - for (const [key, val] of Object.entries(instance.config.flags)) { - tfjs_esm_exports.env().set(key, val); - } - } - tfjs_esm_exports.enableProdMode(); - init(); - instance.performance.initBackend = Math.trunc(now() - timeStamp); - instance.config.backend = tfjs_esm_exports.getBackend(); - await env.updateBackend(); - registerCustomOps(instance.config); - env.initial = false; - } - return true; -} -function fakeOps(kernelNames, config3) { - for (const kernelName of kernelNames) { - const kernelConfig = { - kernelName, - backendName: config3.backend, - kernelFunc: (param) => { - var _a; - if (config3.debug) - log("kernelFunc", kernelName, config3.backend, param); - return (_a = param == null ? void 0 : param.inputs) == null ? void 0 : _a.info; - } - }; - tfjs_esm_exports.registerKernel(kernelConfig); - } - env.kernels = tfjs_esm_exports.getKernelsForBackend(tfjs_esm_exports.getBackend()).map((kernel) => kernel.kernelName.toLowerCase()); -} - -// src/draw/draw.ts -var draw_exports = {}; -__export(draw_exports, { - all: () => all, - body: () => body, - canvas: () => canvas2, - face: () => face, - gesture: () => gesture, - hand: () => hand, - init: () => init2, - object: () => object, - options: () => options2, - person: () => person -}); - -// src/draw/primitives.ts -var getCanvasContext = (input) => { - if (!input) - log("draw error: invalid canvas"); - else if (!input.getContext) - log("draw error: canvas context not defined"); - else { - const ctx = input.getContext("2d"); - if (!ctx) - log("draw error: cannot get canvas context"); - else - return ctx; - } - return null; -}; -var rad2deg = (theta) => Math.round(theta * 180 / Math.PI); -var replace = (str, source, target) => str.replace(source, typeof target === "number" ? target.toFixed(1) : target); -var colorDepth = (z, opt) => { - if (!opt.useDepth || typeof z === "undefined") - return opt.color; - const rgb2 = Uint8ClampedArray.from([127 + 2 * z, 127 - 2 * z, 255]); - return `rgba(${rgb2[0]}, ${rgb2[1]}, ${rgb2[2]}, ${opt.alpha})`; -}; -function labels(ctx, str, startX, startY, localOptions2) { - const line = str.replace(/\[.*\]/g, "").split("\n").map((l) => l.trim()); - const x = Math.max(0, startX); - for (let i = line.length - 1; i >= 0; i--) { - const y = i * localOptions2.lineHeight + startY; - if (localOptions2.shadowColor && localOptions2.shadowColor !== "") { - ctx.fillStyle = localOptions2.shadowColor; - ctx.fillText(line[i], x + 5, y + 16); - } - ctx.fillStyle = localOptions2.labelColor; - ctx.fillText(line[i], x + 4, y + 15); - } -} -function point(ctx, x, y, z, localOptions2) { - ctx.fillStyle = colorDepth(z, localOptions2); - ctx.beginPath(); - ctx.arc(x, y, localOptions2.pointSize, 0, 2 * Math.PI); - ctx.fill(); -} -function rect(ctx, x, y, width, height, localOptions2) { - ctx.beginPath(); - ctx.lineWidth = localOptions2.lineWidth; - if (localOptions2.useCurves) { - const cx = (x + x + width) / 2; - const cy = (y + y + height) / 2; - ctx.ellipse(cx, cy, width / 2, height / 2, 0, 0, 2 * Math.PI); - } else { - ctx.moveTo(x + localOptions2.roundRect, y); - ctx.lineTo(x + width - localOptions2.roundRect, y); - ctx.quadraticCurveTo(x + width, y, x + width, y + localOptions2.roundRect); - ctx.lineTo(x + width, y + height - localOptions2.roundRect); - ctx.quadraticCurveTo(x + width, y + height, x + width - localOptions2.roundRect, y + height); - ctx.lineTo(x + localOptions2.roundRect, y + height); - ctx.quadraticCurveTo(x, y + height, x, y + height - localOptions2.roundRect); - ctx.lineTo(x, y + localOptions2.roundRect); - ctx.quadraticCurveTo(x, y, x + localOptions2.roundRect, y); - ctx.closePath(); - } - ctx.stroke(); -} -function lines(ctx, points, localOptions2) { - if (points.length < 2) - return; - ctx.beginPath(); - ctx.moveTo(points[0][0], points[0][1]); - for (const pt of points) { - ctx.strokeStyle = colorDepth(pt[2] || 0, localOptions2); - ctx.lineTo(Math.trunc(pt[0]), Math.trunc(pt[1])); - } - ctx.stroke(); - if (localOptions2.fillPolygons) { - ctx.closePath(); - ctx.fill(); - } -} -function curves(ctx, points, localOptions2) { - if (points.length < 2) - return; - ctx.lineWidth = localOptions2.lineWidth; - if (!localOptions2.useCurves || points.length <= 2) { - lines(ctx, points, localOptions2); - return; - } - ctx.moveTo(points[0][0], points[0][1]); - for (let i = 0; i < points.length - 2; i++) { - const xc = (points[i][0] + points[i + 1][0]) / 2; - const yc = (points[i][1] + points[i + 1][1]) / 2; - ctx.quadraticCurveTo(points[i][0], points[i][1], xc, yc); - } - ctx.quadraticCurveTo(points[points.length - 2][0], points[points.length - 2][1], points[points.length - 1][0], points[points.length - 1][1]); - ctx.stroke(); - if (localOptions2.fillPolygons) { - ctx.closePath(); - ctx.fill(); - } -} -function arrow(ctx, from, to, radius = 5) { - let angle; - let x; - let y; - ctx.beginPath(); - ctx.moveTo(from[0], from[1]); - ctx.lineTo(to[0], to[1]); - angle = Math.atan2(to[1] - from[1], to[0] - from[0]); - x = radius * Math.cos(angle) + to[0]; - y = radius * Math.sin(angle) + to[1]; - ctx.moveTo(x, y); - angle += 1 / 3 * (2 * Math.PI); - x = radius * Math.cos(angle) + to[0]; - y = radius * Math.sin(angle) + to[1]; - ctx.lineTo(x, y); - angle += 1 / 3 * (2 * Math.PI); - x = radius * Math.cos(angle) + to[0]; - y = radius * Math.sin(angle) + to[1]; - ctx.lineTo(x, y); - ctx.closePath(); - ctx.stroke(); - ctx.fill(); -} - -// src/draw/options.ts -var options2 = { - color: "rgba(173, 216, 230, 0.6)", - labelColor: "rgba(173, 216, 230, 1)", - shadowColor: "black", - alpha: 0.5, - font: 'small-caps 16px "Segoe UI"', - lineHeight: 18, - lineWidth: 4, - pointSize: 2, - roundRect: 8, - drawPoints: false, - drawLabels: true, - drawBoxes: true, - drawAttention: true, - drawGestures: true, - drawPolygons: true, - drawGaze: true, - fillPolygons: false, - useDepth: true, - useCurves: false, - faceLabels: "", - bodyLabels: "", - bodyPartLabels: "", - objectLabels: "", - handLabels: "", - fingerLabels: "", - gestureLabels: "" -}; - -// src/face/facemeshcoords.ts -var meshAnnotations = { - 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], - noseTip: [1], - noseBottom: [2], - noseRightCorner: [98], - noseLeftCorner: [327], - rightCheek: [205], - leftCheek: [425] -}; -var meshLandmarks = { - count: 468, - mouth: 13, - symmetryLine: [13, meshAnnotations.midwayBetweenEyes[0]] -}; -var blazeFaceLandmarks = { - leftEye: 0, - rightEye: 1, - nose: 2, - mouth: 3, - leftEar: 4, - rightEar: 5, - symmetryLine: [3, 2] -}; -var irisIndices = [ - { key: "EyeUpper0", indices: [9, 10, 11, 12, 13, 14, 15] }, - { key: "EyeUpper1", indices: [25, 26, 27, 28, 29, 30, 31] }, - { key: "EyeUpper2", indices: [41, 42, 43, 44, 45, 46, 47] }, - { key: "EyeLower0", indices: [0, 1, 2, 3, 4, 5, 6, 7, 8] }, - { key: "EyeLower1", indices: [16, 17, 18, 19, 20, 21, 22, 23, 24] }, - { key: "EyeLower2", indices: [32, 33, 34, 35, 36, 37, 38, 39, 40] }, - { key: "EyeLower3", indices: [54, 55, 56, 57, 58, 59, 60, 61, 62] }, - { key: "EyebrowUpper", indices: [63, 64, 65, 66, 67, 68, 69, 70] }, - { key: "EyebrowLower", indices: [48, 49, 50, 51, 52, 53] } -]; -var UV468 = [ - [0.499976992607117, 0.652534008026123], - [0.500025987625122, 0.547487020492554], - [0.499974012374878, 0.602371990680695], - [0.482113003730774, 0.471979022026062], - [0.500150978565216, 0.527155995368958], - [0.499909996986389, 0.498252987861633], - [0.499523013830185, 0.40106201171875], - [0.289712011814117, 0.380764007568359], - [0.499954998493195, 0.312398016452789], - [0.499987006187439, 0.269918978214264], - [0.500023007392883, 0.107050001621246], - [0.500023007392883, 0.666234016418457], - [0.5000159740448, 0.679224014282227], - [0.500023007392883, 0.692348003387451], - [0.499976992607117, 0.695277988910675], - [0.499976992607117, 0.70593398809433], - [0.499976992607117, 0.719385027885437], - [0.499976992607117, 0.737019002437592], - [0.499967992305756, 0.781370997428894], - [0.499816000461578, 0.562981009483337], - [0.473773002624512, 0.573909997940063], - [0.104906998574734, 0.254140973091125], - [0.365929991006851, 0.409575998783112], - [0.338757991790771, 0.41302502155304], - [0.311120003461838, 0.409460008144379], - [0.274657994508743, 0.389131009578705], - [0.393361985683441, 0.403706014156342], - [0.345234006643295, 0.344011008739471], - [0.370094001293182, 0.346076011657715], - [0.319321990013123, 0.347265005111694], - [0.297903001308441, 0.353591024875641], - [0.24779200553894, 0.410809993743896], - [0.396889001131058, 0.842755019664764], - [0.280097991228104, 0.375599980354309], - [0.106310002505779, 0.399955987930298], - [0.2099249958992, 0.391353011131287], - [0.355807989835739, 0.534406006336212], - [0.471751004457474, 0.65040397644043], - [0.474155008792877, 0.680191993713379], - [0.439785003662109, 0.657229006290436], - [0.414617002010345, 0.66654098033905], - [0.450374007225037, 0.680860996246338], - [0.428770989179611, 0.682690978050232], - [0.374971002340317, 0.727805018424988], - [0.486716985702515, 0.547628998756409], - [0.485300987958908, 0.527395009994507], - [0.257764995098114, 0.314490020275116], - [0.401223003864288, 0.455172002315521], - [0.429818987846375, 0.548614978790283], - [0.421351999044418, 0.533740997314453], - [0.276895999908447, 0.532056987285614], - [0.483370006084442, 0.499586999416351], - [0.33721199631691, 0.282882988452911], - [0.296391993761063, 0.293242990970612], - [0.169294998049736, 0.193813979625702], - [0.447580009698868, 0.302609980106354], - [0.392390012741089, 0.353887975215912], - [0.354490011930466, 0.696784019470215], - [0.067304998636246, 0.730105042457581], - [0.442739009857178, 0.572826027870178], - [0.457098007202148, 0.584792017936707], - [0.381974011659622, 0.694710969924927], - [0.392388999462128, 0.694203019142151], - [0.277076005935669, 0.271932005882263], - [0.422551989555359, 0.563233017921448], - [0.385919004678726, 0.281364023685455], - [0.383103013038635, 0.255840003490448], - [0.331431001424789, 0.119714021682739], - [0.229923993349075, 0.232002973556519], - [0.364500999450684, 0.189113974571228], - [0.229622006416321, 0.299540996551514], - [0.173287004232407, 0.278747975826263], - [0.472878992557526, 0.666198015213013], - [0.446828007698059, 0.668527007102966], - [0.422762006521225, 0.673889994621277], - [0.445307999849319, 0.580065965652466], - [0.388103008270264, 0.693961024284363], - [0.403039008378983, 0.706539988517761], - [0.403629004955292, 0.693953037261963], - [0.460041999816895, 0.557139039039612], - [0.431158006191254, 0.692366003990173], - [0.452181994915009, 0.692366003990173], - [0.475387006998062, 0.692366003990173], - [0.465828001499176, 0.779190003871918], - [0.472328990697861, 0.736225962638855], - [0.473087012767792, 0.717857003211975], - [0.473122000694275, 0.704625964164734], - [0.473033010959625, 0.695277988910675], - [0.427942007780075, 0.695277988910675], - [0.426479011774063, 0.703539967536926], - [0.423162013292313, 0.711845993995667], - [0.4183090031147, 0.720062971115112], - [0.390094995498657, 0.639572978019714], - [0.013953999616206, 0.560034036636353], - [0.499913990497589, 0.58014702796936], - [0.413199990987778, 0.69539999961853], - [0.409626007080078, 0.701822996139526], - [0.468080013990402, 0.601534962654114], - [0.422728985548019, 0.585985004901886], - [0.463079988956451, 0.593783974647522], - [0.37211999297142, 0.47341400384903], - [0.334562003612518, 0.496073007583618], - [0.411671012639999, 0.546965003013611], - [0.242175996303558, 0.14767599105835], - [0.290776997804642, 0.201445996761322], - [0.327338010072708, 0.256527006626129], - [0.399509996175766, 0.748921036720276], - [0.441727995872498, 0.261676013469696], - [0.429764986038208, 0.187834024429321], - [0.412198007106781, 0.108901023864746], - [0.288955003023148, 0.398952007293701], - [0.218936994671822, 0.435410976409912], - [0.41278201341629, 0.398970007896423], - [0.257135003805161, 0.355440020561218], - [0.427684992551804, 0.437960982322693], - [0.448339998722076, 0.536936044692993], - [0.178560003638268, 0.45755398273468], - [0.247308000922203, 0.457193970680237], - [0.286267012357712, 0.467674970626831], - [0.332827985286713, 0.460712015628815], - [0.368755996227264, 0.447206974029541], - [0.398963987827301, 0.432654976844788], - [0.476410001516342, 0.405806005001068], - [0.189241006970406, 0.523923993110657], - [0.228962004184723, 0.348950982093811], - [0.490725994110107, 0.562400996685028], - [0.404670000076294, 0.485132992267609], - [0.019469000399113, 0.401564002037048], - [0.426243007183075, 0.420431017875671], - [0.396993011236191, 0.548797011375427], - [0.266469985246658, 0.376977026462555], - [0.439121007919312, 0.51895797252655], - [0.032313998788595, 0.644356966018677], - [0.419054001569748, 0.387154996395111], - [0.462783008813858, 0.505746960639954], - [0.238978996872902, 0.779744982719421], - [0.198220998048782, 0.831938028335571], - [0.107550002634525, 0.540755033493042], - [0.183610007166862, 0.740257024765015], - [0.134409993886948, 0.333683013916016], - [0.385764002799988, 0.883153975009918], - [0.490967005491257, 0.579378008842468], - [0.382384985685349, 0.508572995662689], - [0.174399003386497, 0.397670984268188], - [0.318785011768341, 0.39623498916626], - [0.343364000320435, 0.400596976280212], - [0.396100014448166, 0.710216999053955], - [0.187885001301765, 0.588537991046906], - [0.430987000465393, 0.944064974784851], - [0.318993002176285, 0.898285031318665], - [0.266247987747192, 0.869701027870178], - [0.500023007392883, 0.190576016902924], - [0.499976992607117, 0.954452991485596], - [0.366169989109039, 0.398822009563446], - [0.393207013607025, 0.39553701877594], - [0.410373002290726, 0.391080021858215], - [0.194993004202843, 0.342101991176605], - [0.388664990663528, 0.362284004688263], - [0.365961998701096, 0.355970978736877], - [0.343364000320435, 0.355356991291046], - [0.318785011768341, 0.35834002494812], - [0.301414996385574, 0.363156020641327], - [0.058132998645306, 0.319076001644135], - [0.301414996385574, 0.387449026107788], - [0.499987989664078, 0.618434011936188], - [0.415838003158569, 0.624195992946625], - [0.445681989192963, 0.566076993942261], - [0.465844005346298, 0.620640993118286], - [0.49992299079895, 0.351523995399475], - [0.288718998432159, 0.819945991039276], - [0.335278987884521, 0.852819979190826], - [0.440512001514435, 0.902418971061707], - [0.128294005990028, 0.791940987110138], - [0.408771991729736, 0.373893976211548], - [0.455606997013092, 0.451801002025604], - [0.499877005815506, 0.908990025520325], - [0.375436991453171, 0.924192011356354], - [0.11421000212431, 0.615022003650665], - [0.448662012815475, 0.695277988910675], - [0.4480200111866, 0.704632043838501], - [0.447111994028091, 0.715808033943176], - [0.444831997156143, 0.730794012546539], - [0.430011987686157, 0.766808986663818], - [0.406787008047104, 0.685672998428345], - [0.400738000869751, 0.681069016456604], - [0.392399996519089, 0.677703022956848], - [0.367855995893478, 0.663918972015381], - [0.247923001646996, 0.601333022117615], - [0.452769994735718, 0.420849978923798], - [0.43639200925827, 0.359887003898621], - [0.416164010763168, 0.368713974952698], - [0.413385987281799, 0.692366003990173], - [0.228018000721931, 0.683571994304657], - [0.468268007040024, 0.352671027183533], - [0.411361992359161, 0.804327011108398], - [0.499989002943039, 0.469825029373169], - [0.479153990745544, 0.442654013633728], - [0.499974012374878, 0.439637005329132], - [0.432112008333206, 0.493588984012604], - [0.499886006116867, 0.866917014122009], - [0.49991300702095, 0.821729004383087], - [0.456548988819122, 0.819200992584229], - [0.344549000263214, 0.745438992977142], - [0.37890899181366, 0.574010014533997], - [0.374292999505997, 0.780184984207153], - [0.319687992334366, 0.570737957954407], - [0.357154995203018, 0.604269981384277], - [0.295284003019333, 0.621580958366394], - [0.447750002145767, 0.862477004528046], - [0.410986006259918, 0.508723020553589], - [0.31395098567009, 0.775308012962341], - [0.354128003120422, 0.812552988529205], - [0.324548006057739, 0.703992962837219], - [0.189096003770828, 0.646299958229065], - [0.279776990413666, 0.71465802192688], - [0.1338230073452, 0.682700991630554], - [0.336768001317978, 0.644733011722565], - [0.429883986711502, 0.466521978378296], - [0.455527991056442, 0.548622965812683], - [0.437114000320435, 0.558896005153656], - [0.467287987470627, 0.529924988746643], - [0.414712011814117, 0.335219979286194], - [0.37704598903656, 0.322777986526489], - [0.344107985496521, 0.320150971412659], - [0.312875986099243, 0.32233202457428], - [0.283526003360748, 0.333190023899078], - [0.241245999932289, 0.382785975933075], - [0.102986000478268, 0.468762993812561], - [0.267612010240555, 0.424560010433197], - [0.297879010438919, 0.433175981044769], - [0.333433985710144, 0.433878004550934], - [0.366427004337311, 0.426115989685059], - [0.396012008190155, 0.416696012020111], - [0.420121014118195, 0.41022801399231], - [0.007561000064015, 0.480777025222778], - [0.432949006557465, 0.569517970085144], - [0.458638995885849, 0.479089021682739], - [0.473466008901596, 0.545744001865387], - [0.476087987422943, 0.563830018043518], - [0.468472003936768, 0.555056989192963], - [0.433990985155106, 0.582361996173859], - [0.483518004417419, 0.562983989715576], - [0.482482999563217, 0.57784903049469], - [0.42645001411438, 0.389798998832703], - [0.438998997211456, 0.39649498462677], - [0.450067013502121, 0.400434017181396], - [0.289712011814117, 0.368252992630005], - [0.276670008897781, 0.363372981548309], - [0.517862021923065, 0.471948027610779], - [0.710287988185883, 0.380764007568359], - [0.526226997375488, 0.573909997940063], - [0.895093023777008, 0.254140973091125], - [0.634069979190826, 0.409575998783112], - [0.661242008209229, 0.41302502155304], - [0.688880026340485, 0.409460008144379], - [0.725341975688934, 0.389131009578705], - [0.606630027294159, 0.40370500087738], - [0.654766023159027, 0.344011008739471], - [0.629905998706818, 0.346076011657715], - [0.680678009986877, 0.347265005111694], - [0.702096998691559, 0.353591024875641], - [0.75221198797226, 0.410804986953735], - [0.602918028831482, 0.842862963676453], - [0.719901978969574, 0.375599980354309], - [0.893692970275879, 0.399959981441498], - [0.790081977844238, 0.391354024410248], - [0.643998026847839, 0.534487962722778], - [0.528249025344849, 0.65040397644043], - [0.525849997997284, 0.680191040039062], - [0.560214996337891, 0.657229006290436], - [0.585384011268616, 0.66654098033905], - [0.549625992774963, 0.680860996246338], - [0.57122802734375, 0.682691991329193], - [0.624852001667023, 0.72809898853302], - [0.513050019741058, 0.547281980514526], - [0.51509702205658, 0.527251958847046], - [0.742246985435486, 0.314507007598877], - [0.598631024360657, 0.454979002475739], - [0.570338010787964, 0.548575043678284], - [0.578631997108459, 0.533622980117798], - [0.723087012767792, 0.532054007053375], - [0.516445994377136, 0.499638974666595], - [0.662801027297974, 0.282917976379395], - [0.70362401008606, 0.293271005153656], - [0.830704987049103, 0.193813979625702], - [0.552385985851288, 0.302568018436432], - [0.607609987258911, 0.353887975215912], - [0.645429015159607, 0.696707010269165], - [0.932694971561432, 0.730105042457581], - [0.557260990142822, 0.572826027870178], - [0.542901992797852, 0.584792017936707], - [0.6180260181427, 0.694710969924927], - [0.607590973377228, 0.694203019142151], - [0.722943007946014, 0.271963000297546], - [0.577413976192474, 0.563166975975037], - [0.614082992076874, 0.281386971473694], - [0.616907000541687, 0.255886018276215], - [0.668509006500244, 0.119913995265961], - [0.770092010498047, 0.232020974159241], - [0.635536015033722, 0.189248979091644], - [0.77039098739624, 0.299556016921997], - [0.826722025871277, 0.278755009174347], - [0.527121007442474, 0.666198015213013], - [0.553171992301941, 0.668527007102966], - [0.577238023281097, 0.673889994621277], - [0.554691970348358, 0.580065965652466], - [0.611896991729736, 0.693961024284363], - [0.59696102142334, 0.706539988517761], - [0.596370995044708, 0.693953037261963], - [0.539958000183105, 0.557139039039612], - [0.568841993808746, 0.692366003990173], - [0.547818005084991, 0.692366003990173], - [0.52461302280426, 0.692366003990173], - [0.534089982509613, 0.779141008853912], - [0.527670979499817, 0.736225962638855], - [0.526912987232208, 0.717857003211975], - [0.526877999305725, 0.704625964164734], - [0.526966989040375, 0.695277988910675], - [0.572058022022247, 0.695277988910675], - [0.573521018028259, 0.703539967536926], - [0.57683801651001, 0.711845993995667], - [0.581691026687622, 0.720062971115112], - [0.609944999217987, 0.639909982681274], - [0.986046016216278, 0.560034036636353], - [0.5867999792099, 0.69539999961853], - [0.590372025966644, 0.701822996139526], - [0.531915009021759, 0.601536989212036], - [0.577268004417419, 0.585934996604919], - [0.536915004253387, 0.593786001205444], - [0.627542972564697, 0.473352015018463], - [0.665585994720459, 0.495950996875763], - [0.588353991508484, 0.546862006187439], - [0.757824003696442, 0.14767599105835], - [0.709249973297119, 0.201507985591888], - [0.672684013843536, 0.256581008434296], - [0.600408971309662, 0.74900496006012], - [0.55826598405838, 0.261672019958496], - [0.570303976535797, 0.187870979309082], - [0.588165998458862, 0.109044015407562], - [0.711045026779175, 0.398952007293701], - [0.781069993972778, 0.435405015945435], - [0.587247014045715, 0.398931980133057], - [0.742869973182678, 0.355445981025696], - [0.572156012058258, 0.437651991844177], - [0.55186802148819, 0.536570012569427], - [0.821442008018494, 0.457556009292603], - [0.752701997756958, 0.457181990146637], - [0.71375697851181, 0.467626988887787], - [0.66711300611496, 0.460672974586487], - [0.631101012229919, 0.447153985500336], - [0.6008620262146, 0.432473003864288], - [0.523481011390686, 0.405627012252808], - [0.810747981071472, 0.523926019668579], - [0.771045982837677, 0.348959028720856], - [0.509127020835876, 0.562718033790588], - [0.595292985439301, 0.485023975372314], - [0.980530977249146, 0.401564002037048], - [0.573499977588654, 0.420000016689301], - [0.602994978427887, 0.548687994480133], - [0.733529984951019, 0.376977026462555], - [0.560611009597778, 0.519016981124878], - [0.967685997486115, 0.644356966018677], - [0.580985009670258, 0.387160003185272], - [0.537728011608124, 0.505385041236877], - [0.760966002941132, 0.779752969741821], - [0.801778972148895, 0.831938028335571], - [0.892440974712372, 0.54076099395752], - [0.816350996494293, 0.740260004997253], - [0.865594983100891, 0.333687007427216], - [0.614073991775513, 0.883246004581451], - [0.508952975273132, 0.579437971115112], - [0.617941975593567, 0.508316040039062], - [0.825608015060425, 0.397674977779388], - [0.681214988231659, 0.39623498916626], - [0.656635999679565, 0.400596976280212], - [0.603900015354156, 0.710216999053955], - [0.81208598613739, 0.588539004325867], - [0.56801301240921, 0.944564998149872], - [0.681007981300354, 0.898285031318665], - [0.733752012252808, 0.869701027870178], - [0.633830010890961, 0.398822009563446], - [0.606792986392975, 0.39553701877594], - [0.589659988880157, 0.391062021255493], - [0.805015981197357, 0.342108011245728], - [0.611334979534149, 0.362284004688263], - [0.634037971496582, 0.355970978736877], - [0.656635999679565, 0.355356991291046], - [0.681214988231659, 0.35834002494812], - [0.698584973812103, 0.363156020641327], - [0.941866993904114, 0.319076001644135], - [0.698584973812103, 0.387449026107788], - [0.584177017211914, 0.624107003211975], - [0.554318010807037, 0.566076993942261], - [0.534153997898102, 0.62064003944397], - [0.711217999458313, 0.819975018501282], - [0.664629995822906, 0.852871000766754], - [0.559099972248077, 0.902631998062134], - [0.871706008911133, 0.791940987110138], - [0.591234028339386, 0.373893976211548], - [0.544341027736664, 0.451583981513977], - [0.624562978744507, 0.924192011356354], - [0.88577002286911, 0.615028977394104], - [0.551338016986847, 0.695277988910675], - [0.551980018615723, 0.704632043838501], - [0.552887976169586, 0.715808033943176], - [0.555167973041534, 0.730794012546539], - [0.569944024085999, 0.767035007476807], - [0.593203008174896, 0.685675978660583], - [0.599261999130249, 0.681069016456604], - [0.607599973678589, 0.677703022956848], - [0.631937980651855, 0.663500010967255], - [0.752032995223999, 0.601315021514893], - [0.547226011753082, 0.420395016670227], - [0.563543975353241, 0.359827995300293], - [0.583841025829315, 0.368713974952698], - [0.586614012718201, 0.692366003990173], - [0.771915018558502, 0.683578014373779], - [0.531597018241882, 0.352482974529266], - [0.588370978832245, 0.804440975189209], - [0.52079701423645, 0.442565023899078], - [0.567984998226166, 0.493479013442993], - [0.543282985687256, 0.819254994392395], - [0.655317008495331, 0.745514988899231], - [0.621008992195129, 0.574018001556396], - [0.625559985637665, 0.78031200170517], - [0.680198013782501, 0.570719003677368], - [0.64276397228241, 0.604337990283966], - [0.704662978649139, 0.621529996395111], - [0.552012026309967, 0.862591981887817], - [0.589071989059448, 0.508637011051178], - [0.685944974422455, 0.775357007980347], - [0.645735025405884, 0.812640011310577], - [0.675342977046967, 0.703978002071381], - [0.810858011245728, 0.646304965019226], - [0.72012197971344, 0.714666962623596], - [0.866151988506317, 0.682704985141754], - [0.663187026977539, 0.644596993923187], - [0.570082008838654, 0.466325998306274], - [0.544561982154846, 0.548375964164734], - [0.562758982181549, 0.558784961700439], - [0.531987011432648, 0.530140042304993], - [0.585271000862122, 0.335177004337311], - [0.622952997684479, 0.32277899980545], - [0.655896008014679, 0.320163011550903], - [0.687132000923157, 0.322345972061157], - [0.716481983661652, 0.333200991153717], - [0.758756995201111, 0.382786989212036], - [0.897013008594513, 0.468769013881683], - [0.732392013072968, 0.424547016620636], - [0.70211398601532, 0.433162987232208], - [0.66652500629425, 0.433866024017334], - [0.633504986763, 0.426087975502014], - [0.603875994682312, 0.416586995124817], - [0.579657971858978, 0.409945011138916], - [0.992439985275269, 0.480777025222778], - [0.567192018032074, 0.569419980049133], - [0.54136598110199, 0.478899002075195], - [0.526564002037048, 0.546118021011353], - [0.523913025856018, 0.563830018043518], - [0.531529009342194, 0.555056989192963], - [0.566035985946655, 0.582329034805298], - [0.51631098985672, 0.563053965568542], - [0.5174720287323, 0.577877044677734], - [0.573594987392426, 0.389806985855103], - [0.560697972774506, 0.395331978797913], - [0.549755990505219, 0.399751007556915], - [0.710287988185883, 0.368252992630005], - [0.723330020904541, 0.363372981548309] -]; -var TRI468 = [ - 127, - 34, - 139, - 11, - 0, - 37, - 232, - 231, - 120, - 72, - 37, - 39, - 128, - 121, - 47, - 232, - 121, - 128, - 104, - 69, - 67, - 175, - 171, - 148, - 157, - 154, - 155, - 118, - 50, - 101, - 73, - 39, - 40, - 9, - 151, - 108, - 48, - 115, - 131, - 194, - 204, - 211, - 74, - 40, - 185, - 80, - 42, - 183, - 40, - 92, - 186, - 230, - 229, - 118, - 202, - 212, - 214, - 83, - 18, - 17, - 76, - 61, - 146, - 160, - 29, - 30, - 56, - 157, - 173, - 106, - 204, - 194, - 135, - 214, - 192, - 203, - 165, - 98, - 21, - 71, - 68, - 51, - 45, - 4, - 144, - 24, - 23, - 77, - 146, - 91, - 205, - 50, - 187, - 201, - 200, - 18, - 91, - 106, - 182, - 90, - 91, - 181, - 85, - 84, - 17, - 206, - 203, - 36, - 148, - 171, - 140, - 92, - 40, - 39, - 193, - 189, - 244, - 159, - 158, - 28, - 247, - 246, - 161, - 236, - 3, - 196, - 54, - 68, - 104, - 193, - 168, - 8, - 117, - 228, - 31, - 189, - 193, - 55, - 98, - 97, - 99, - 126, - 47, - 100, - 166, - 79, - 218, - 155, - 154, - 26, - 209, - 49, - 131, - 135, - 136, - 150, - 47, - 126, - 217, - 223, - 52, - 53, - 45, - 51, - 134, - 211, - 170, - 140, - 67, - 69, - 108, - 43, - 106, - 91, - 230, - 119, - 120, - 226, - 130, - 247, - 63, - 53, - 52, - 238, - 20, - 242, - 46, - 70, - 156, - 78, - 62, - 96, - 46, - 53, - 63, - 143, - 34, - 227, - 173, - 155, - 133, - 123, - 117, - 111, - 44, - 125, - 19, - 236, - 134, - 51, - 216, - 206, - 205, - 154, - 153, - 22, - 39, - 37, - 167, - 200, - 201, - 208, - 36, - 142, - 100, - 57, - 212, - 202, - 20, - 60, - 99, - 28, - 158, - 157, - 35, - 226, - 113, - 160, - 159, - 27, - 204, - 202, - 210, - 113, - 225, - 46, - 43, - 202, - 204, - 62, - 76, - 77, - 137, - 123, - 116, - 41, - 38, - 72, - 203, - 129, - 142, - 64, - 98, - 240, - 49, - 102, - 64, - 41, - 73, - 74, - 212, - 216, - 207, - 42, - 74, - 184, - 169, - 170, - 211, - 170, - 149, - 176, - 105, - 66, - 69, - 122, - 6, - 168, - 123, - 147, - 187, - 96, - 77, - 90, - 65, - 55, - 107, - 89, - 90, - 180, - 101, - 100, - 120, - 63, - 105, - 104, - 93, - 137, - 227, - 15, - 86, - 85, - 129, - 102, - 49, - 14, - 87, - 86, - 55, - 8, - 9, - 100, - 47, - 121, - 145, - 23, - 22, - 88, - 89, - 179, - 6, - 122, - 196, - 88, - 95, - 96, - 138, - 172, - 136, - 215, - 58, - 172, - 115, - 48, - 219, - 42, - 80, - 81, - 195, - 3, - 51, - 43, - 146, - 61, - 171, - 175, - 199, - 81, - 82, - 38, - 53, - 46, - 225, - 144, - 163, - 110, - 246, - 33, - 7, - 52, - 65, - 66, - 229, - 228, - 117, - 34, - 127, - 234, - 107, - 108, - 69, - 109, - 108, - 151, - 48, - 64, - 235, - 62, - 78, - 191, - 129, - 209, - 126, - 111, - 35, - 143, - 163, - 161, - 246, - 117, - 123, - 50, - 222, - 65, - 52, - 19, - 125, - 141, - 221, - 55, - 65, - 3, - 195, - 197, - 25, - 7, - 33, - 220, - 237, - 44, - 70, - 71, - 139, - 122, - 193, - 245, - 247, - 130, - 33, - 71, - 21, - 162, - 153, - 158, - 159, - 170, - 169, - 150, - 188, - 174, - 196, - 216, - 186, - 92, - 144, - 160, - 161, - 2, - 97, - 167, - 141, - 125, - 241, - 164, - 167, - 37, - 72, - 38, - 12, - 145, - 159, - 160, - 38, - 82, - 13, - 63, - 68, - 71, - 226, - 35, - 111, - 158, - 153, - 154, - 101, - 50, - 205, - 206, - 92, - 165, - 209, - 198, - 217, - 165, - 167, - 97, - 220, - 115, - 218, - 133, - 112, - 243, - 239, - 238, - 241, - 214, - 135, - 169, - 190, - 173, - 133, - 171, - 208, - 32, - 125, - 44, - 237, - 86, - 87, - 178, - 85, - 86, - 179, - 84, - 85, - 180, - 83, - 84, - 181, - 201, - 83, - 182, - 137, - 93, - 132, - 76, - 62, - 183, - 61, - 76, - 184, - 57, - 61, - 185, - 212, - 57, - 186, - 214, - 207, - 187, - 34, - 143, - 156, - 79, - 239, - 237, - 123, - 137, - 177, - 44, - 1, - 4, - 201, - 194, - 32, - 64, - 102, - 129, - 213, - 215, - 138, - 59, - 166, - 219, - 242, - 99, - 97, - 2, - 94, - 141, - 75, - 59, - 235, - 24, - 110, - 228, - 25, - 130, - 226, - 23, - 24, - 229, - 22, - 23, - 230, - 26, - 22, - 231, - 112, - 26, - 232, - 189, - 190, - 243, - 221, - 56, - 190, - 28, - 56, - 221, - 27, - 28, - 222, - 29, - 27, - 223, - 30, - 29, - 224, - 247, - 30, - 225, - 238, - 79, - 20, - 166, - 59, - 75, - 60, - 75, - 240, - 147, - 177, - 215, - 20, - 79, - 166, - 187, - 147, - 213, - 112, - 233, - 244, - 233, - 128, - 245, - 128, - 114, - 188, - 114, - 217, - 174, - 131, - 115, - 220, - 217, - 198, - 236, - 198, - 131, - 134, - 177, - 132, - 58, - 143, - 35, - 124, - 110, - 163, - 7, - 228, - 110, - 25, - 356, - 389, - 368, - 11, - 302, - 267, - 452, - 350, - 349, - 302, - 303, - 269, - 357, - 343, - 277, - 452, - 453, - 357, - 333, - 332, - 297, - 175, - 152, - 377, - 384, - 398, - 382, - 347, - 348, - 330, - 303, - 304, - 270, - 9, - 336, - 337, - 278, - 279, - 360, - 418, - 262, - 431, - 304, - 408, - 409, - 310, - 415, - 407, - 270, - 409, - 410, - 450, - 348, - 347, - 422, - 430, - 434, - 313, - 314, - 17, - 306, - 307, - 375, - 387, - 388, - 260, - 286, - 414, - 398, - 335, - 406, - 418, - 364, - 367, - 416, - 423, - 358, - 327, - 251, - 284, - 298, - 281, - 5, - 4, - 373, - 374, - 253, - 307, - 320, - 321, - 425, - 427, - 411, - 421, - 313, - 18, - 321, - 405, - 406, - 320, - 404, - 405, - 315, - 16, - 17, - 426, - 425, - 266, - 377, - 400, - 369, - 322, - 391, - 269, - 417, - 465, - 464, - 386, - 257, - 258, - 466, - 260, - 388, - 456, - 399, - 419, - 284, - 332, - 333, - 417, - 285, - 8, - 346, - 340, - 261, - 413, - 441, - 285, - 327, - 460, - 328, - 355, - 371, - 329, - 392, - 439, - 438, - 382, - 341, - 256, - 429, - 420, - 360, - 364, - 394, - 379, - 277, - 343, - 437, - 443, - 444, - 283, - 275, - 440, - 363, - 431, - 262, - 369, - 297, - 338, - 337, - 273, - 375, - 321, - 450, - 451, - 349, - 446, - 342, - 467, - 293, - 334, - 282, - 458, - 461, - 462, - 276, - 353, - 383, - 308, - 324, - 325, - 276, - 300, - 293, - 372, - 345, - 447, - 382, - 398, - 362, - 352, - 345, - 340, - 274, - 1, - 19, - 456, - 248, - 281, - 436, - 427, - 425, - 381, - 256, - 252, - 269, - 391, - 393, - 200, - 199, - 428, - 266, - 330, - 329, - 287, - 273, - 422, - 250, - 462, - 328, - 258, - 286, - 384, - 265, - 353, - 342, - 387, - 259, - 257, - 424, - 431, - 430, - 342, - 353, - 276, - 273, - 335, - 424, - 292, - 325, - 307, - 366, - 447, - 345, - 271, - 303, - 302, - 423, - 266, - 371, - 294, - 455, - 460, - 279, - 278, - 294, - 271, - 272, - 304, - 432, - 434, - 427, - 272, - 407, - 408, - 394, - 430, - 431, - 395, - 369, - 400, - 334, - 333, - 299, - 351, - 417, - 168, - 352, - 280, - 411, - 325, - 319, - 320, - 295, - 296, - 336, - 319, - 403, - 404, - 330, - 348, - 349, - 293, - 298, - 333, - 323, - 454, - 447, - 15, - 16, - 315, - 358, - 429, - 279, - 14, - 15, - 316, - 285, - 336, - 9, - 329, - 349, - 350, - 374, - 380, - 252, - 318, - 402, - 403, - 6, - 197, - 419, - 318, - 319, - 325, - 367, - 364, - 365, - 435, - 367, - 397, - 344, - 438, - 439, - 272, - 271, - 311, - 195, - 5, - 281, - 273, - 287, - 291, - 396, - 428, - 199, - 311, - 271, - 268, - 283, - 444, - 445, - 373, - 254, - 339, - 263, - 466, - 249, - 282, - 334, - 296, - 449, - 347, - 346, - 264, - 447, - 454, - 336, - 296, - 299, - 338, - 10, - 151, - 278, - 439, - 455, - 292, - 407, - 415, - 358, - 371, - 355, - 340, - 345, - 372, - 390, - 249, - 466, - 346, - 347, - 280, - 442, - 443, - 282, - 19, - 94, - 370, - 441, - 442, - 295, - 248, - 419, - 197, - 263, - 255, - 359, - 440, - 275, - 274, - 300, - 383, - 368, - 351, - 412, - 465, - 263, - 467, - 466, - 301, - 368, - 389, - 380, - 374, - 386, - 395, - 378, - 379, - 412, - 351, - 419, - 436, - 426, - 322, - 373, - 390, - 388, - 2, - 164, - 393, - 370, - 462, - 461, - 164, - 0, - 267, - 302, - 11, - 12, - 374, - 373, - 387, - 268, - 12, - 13, - 293, - 300, - 301, - 446, - 261, - 340, - 385, - 384, - 381, - 330, - 266, - 425, - 426, - 423, - 391, - 429, - 355, - 437, - 391, - 327, - 326, - 440, - 457, - 438, - 341, - 382, - 362, - 459, - 457, - 461, - 434, - 430, - 394, - 414, - 463, - 362, - 396, - 369, - 262, - 354, - 461, - 457, - 316, - 403, - 402, - 315, - 404, - 403, - 314, - 405, - 404, - 313, - 406, - 405, - 421, - 418, - 406, - 366, - 401, - 361, - 306, - 408, - 407, - 291, - 409, - 408, - 287, - 410, - 409, - 432, - 436, - 410, - 434, - 416, - 411, - 264, - 368, - 383, - 309, - 438, - 457, - 352, - 376, - 401, - 274, - 275, - 4, - 421, - 428, - 262, - 294, - 327, - 358, - 433, - 416, - 367, - 289, - 455, - 439, - 462, - 370, - 326, - 2, - 326, - 370, - 305, - 460, - 455, - 254, - 449, - 448, - 255, - 261, - 446, - 253, - 450, - 449, - 252, - 451, - 450, - 256, - 452, - 451, - 341, - 453, - 452, - 413, - 464, - 463, - 441, - 413, - 414, - 258, - 442, - 441, - 257, - 443, - 442, - 259, - 444, - 443, - 260, - 445, - 444, - 467, - 342, - 445, - 459, - 458, - 250, - 289, - 392, - 290, - 290, - 328, - 460, - 376, - 433, - 435, - 250, - 290, - 392, - 411, - 416, - 433, - 341, - 463, - 464, - 453, - 464, - 465, - 357, - 465, - 412, - 343, - 412, - 399, - 360, - 363, - 440, - 437, - 399, - 456, - 420, - 456, - 363, - 401, - 435, - 288, - 372, - 383, - 353, - 339, - 255, - 249, - 448, - 261, - 255, - 133, - 243, - 190, - 133, - 155, - 112, - 33, - 246, - 247, - 33, - 130, - 25, - 398, - 384, - 286, - 362, - 398, - 414, - 362, - 463, - 341, - 263, - 359, - 467, - 263, - 249, - 255, - 466, - 467, - 260, - 75, - 60, - 166, - 238, - 239, - 79, - 162, - 127, - 139, - 72, - 11, - 37, - 121, - 232, - 120, - 73, - 72, - 39, - 114, - 128, - 47, - 233, - 232, - 128, - 103, - 104, - 67, - 152, - 175, - 148, - 173, - 157, - 155, - 119, - 118, - 101, - 74, - 73, - 40, - 107, - 9, - 108, - 49, - 48, - 131, - 32, - 194, - 211, - 184, - 74, - 185, - 191, - 80, - 183, - 185, - 40, - 186, - 119, - 230, - 118, - 210, - 202, - 214, - 84, - 83, - 17, - 77, - 76, - 146, - 161, - 160, - 30, - 190, - 56, - 173, - 182, - 106, - 194, - 138, - 135, - 192, - 129, - 203, - 98, - 54, - 21, - 68, - 5, - 51, - 4, - 145, - 144, - 23, - 90, - 77, - 91, - 207, - 205, - 187, - 83, - 201, - 18, - 181, - 91, - 182, - 180, - 90, - 181, - 16, - 85, - 17, - 205, - 206, - 36, - 176, - 148, - 140, - 165, - 92, - 39, - 245, - 193, - 244, - 27, - 159, - 28, - 30, - 247, - 161, - 174, - 236, - 196, - 103, - 54, - 104, - 55, - 193, - 8, - 111, - 117, - 31, - 221, - 189, - 55, - 240, - 98, - 99, - 142, - 126, - 100, - 219, - 166, - 218, - 112, - 155, - 26, - 198, - 209, - 131, - 169, - 135, - 150, - 114, - 47, - 217, - 224, - 223, - 53, - 220, - 45, - 134, - 32, - 211, - 140, - 109, - 67, - 108, - 146, - 43, - 91, - 231, - 230, - 120, - 113, - 226, - 247, - 105, - 63, - 52, - 241, - 238, - 242, - 124, - 46, - 156, - 95, - 78, - 96, - 70, - 46, - 63, - 116, - 143, - 227, - 116, - 123, - 111, - 1, - 44, - 19, - 3, - 236, - 51, - 207, - 216, - 205, - 26, - 154, - 22, - 165, - 39, - 167, - 199, - 200, - 208, - 101, - 36, - 100, - 43, - 57, - 202, - 242, - 20, - 99, - 56, - 28, - 157, - 124, - 35, - 113, - 29, - 160, - 27, - 211, - 204, - 210, - 124, - 113, - 46, - 106, - 43, - 204, - 96, - 62, - 77, - 227, - 137, - 116, - 73, - 41, - 72, - 36, - 203, - 142, - 235, - 64, - 240, - 48, - 49, - 64, - 42, - 41, - 74, - 214, - 212, - 207, - 183, - 42, - 184, - 210, - 169, - 211, - 140, - 170, - 176, - 104, - 105, - 69, - 193, - 122, - 168, - 50, - 123, - 187, - 89, - 96, - 90, - 66, - 65, - 107, - 179, - 89, - 180, - 119, - 101, - 120, - 68, - 63, - 104, - 234, - 93, - 227, - 16, - 15, - 85, - 209, - 129, - 49, - 15, - 14, - 86, - 107, - 55, - 9, - 120, - 100, - 121, - 153, - 145, - 22, - 178, - 88, - 179, - 197, - 6, - 196, - 89, - 88, - 96, - 135, - 138, - 136, - 138, - 215, - 172, - 218, - 115, - 219, - 41, - 42, - 81, - 5, - 195, - 51, - 57, - 43, - 61, - 208, - 171, - 199, - 41, - 81, - 38, - 224, - 53, - 225, - 24, - 144, - 110, - 105, - 52, - 66, - 118, - 229, - 117, - 227, - 34, - 234, - 66, - 107, - 69, - 10, - 109, - 151, - 219, - 48, - 235, - 183, - 62, - 191, - 142, - 129, - 126, - 116, - 111, - 143, - 7, - 163, - 246, - 118, - 117, - 50, - 223, - 222, - 52, - 94, - 19, - 141, - 222, - 221, - 65, - 196, - 3, - 197, - 45, - 220, - 44, - 156, - 70, - 139, - 188, - 122, - 245, - 139, - 71, - 162, - 145, - 153, - 159, - 149, - 170, - 150, - 122, - 188, - 196, - 206, - 216, - 92, - 163, - 144, - 161, - 164, - 2, - 167, - 242, - 141, - 241, - 0, - 164, - 37, - 11, - 72, - 12, - 144, - 145, - 160, - 12, - 38, - 13, - 70, - 63, - 71, - 31, - 226, - 111, - 157, - 158, - 154, - 36, - 101, - 205, - 203, - 206, - 165, - 126, - 209, - 217, - 98, - 165, - 97, - 237, - 220, - 218, - 237, - 239, - 241, - 210, - 214, - 169, - 140, - 171, - 32, - 241, - 125, - 237, - 179, - 86, - 178, - 180, - 85, - 179, - 181, - 84, - 180, - 182, - 83, - 181, - 194, - 201, - 182, - 177, - 137, - 132, - 184, - 76, - 183, - 185, - 61, - 184, - 186, - 57, - 185, - 216, - 212, - 186, - 192, - 214, - 187, - 139, - 34, - 156, - 218, - 79, - 237, - 147, - 123, - 177, - 45, - 44, - 4, - 208, - 201, - 32, - 98, - 64, - 129, - 192, - 213, - 138, - 235, - 59, - 219, - 141, - 242, - 97, - 97, - 2, - 141, - 240, - 75, - 235, - 229, - 24, - 228, - 31, - 25, - 226, - 230, - 23, - 229, - 231, - 22, - 230, - 232, - 26, - 231, - 233, - 112, - 232, - 244, - 189, - 243, - 189, - 221, - 190, - 222, - 28, - 221, - 223, - 27, - 222, - 224, - 29, - 223, - 225, - 30, - 224, - 113, - 247, - 225, - 99, - 60, - 240, - 213, - 147, - 215, - 60, - 20, - 166, - 192, - 187, - 213, - 243, - 112, - 244, - 244, - 233, - 245, - 245, - 128, - 188, - 188, - 114, - 174, - 134, - 131, - 220, - 174, - 217, - 236, - 236, - 198, - 134, - 215, - 177, - 58, - 156, - 143, - 124, - 25, - 110, - 7, - 31, - 228, - 25, - 264, - 356, - 368, - 0, - 11, - 267, - 451, - 452, - 349, - 267, - 302, - 269, - 350, - 357, - 277, - 350, - 452, - 357, - 299, - 333, - 297, - 396, - 175, - 377, - 381, - 384, - 382, - 280, - 347, - 330, - 269, - 303, - 270, - 151, - 9, - 337, - 344, - 278, - 360, - 424, - 418, - 431, - 270, - 304, - 409, - 272, - 310, - 407, - 322, - 270, - 410, - 449, - 450, - 347, - 432, - 422, - 434, - 18, - 313, - 17, - 291, - 306, - 375, - 259, - 387, - 260, - 424, - 335, - 418, - 434, - 364, - 416, - 391, - 423, - 327, - 301, - 251, - 298, - 275, - 281, - 4, - 254, - 373, - 253, - 375, - 307, - 321, - 280, - 425, - 411, - 200, - 421, - 18, - 335, - 321, - 406, - 321, - 320, - 405, - 314, - 315, - 17, - 423, - 426, - 266, - 396, - 377, - 369, - 270, - 322, - 269, - 413, - 417, - 464, - 385, - 386, - 258, - 248, - 456, - 419, - 298, - 284, - 333, - 168, - 417, - 8, - 448, - 346, - 261, - 417, - 413, - 285, - 326, - 327, - 328, - 277, - 355, - 329, - 309, - 392, - 438, - 381, - 382, - 256, - 279, - 429, - 360, - 365, - 364, - 379, - 355, - 277, - 437, - 282, - 443, - 283, - 281, - 275, - 363, - 395, - 431, - 369, - 299, - 297, - 337, - 335, - 273, - 321, - 348, - 450, - 349, - 359, - 446, - 467, - 283, - 293, - 282, - 250, - 458, - 462, - 300, - 276, - 383, - 292, - 308, - 325, - 283, - 276, - 293, - 264, - 372, - 447, - 346, - 352, - 340, - 354, - 274, - 19, - 363, - 456, - 281, - 426, - 436, - 425, - 380, - 381, - 252, - 267, - 269, - 393, - 421, - 200, - 428, - 371, - 266, - 329, - 432, - 287, - 422, - 290, - 250, - 328, - 385, - 258, - 384, - 446, - 265, - 342, - 386, - 387, - 257, - 422, - 424, - 430, - 445, - 342, - 276, - 422, - 273, - 424, - 306, - 292, - 307, - 352, - 366, - 345, - 268, - 271, - 302, - 358, - 423, - 371, - 327, - 294, - 460, - 331, - 279, - 294, - 303, - 271, - 304, - 436, - 432, - 427, - 304, - 272, - 408, - 395, - 394, - 431, - 378, - 395, - 400, - 296, - 334, - 299, - 6, - 351, - 168, - 376, - 352, - 411, - 307, - 325, - 320, - 285, - 295, - 336, - 320, - 319, - 404, - 329, - 330, - 349, - 334, - 293, - 333, - 366, - 323, - 447, - 316, - 15, - 315, - 331, - 358, - 279, - 317, - 14, - 316, - 8, - 285, - 9, - 277, - 329, - 350, - 253, - 374, - 252, - 319, - 318, - 403, - 351, - 6, - 419, - 324, - 318, - 325, - 397, - 367, - 365, - 288, - 435, - 397, - 278, - 344, - 439, - 310, - 272, - 311, - 248, - 195, - 281, - 375, - 273, - 291, - 175, - 396, - 199, - 312, - 311, - 268, - 276, - 283, - 445, - 390, - 373, - 339, - 295, - 282, - 296, - 448, - 449, - 346, - 356, - 264, - 454, - 337, - 336, - 299, - 337, - 338, - 151, - 294, - 278, - 455, - 308, - 292, - 415, - 429, - 358, - 355, - 265, - 340, - 372, - 388, - 390, - 466, - 352, - 346, - 280, - 295, - 442, - 282, - 354, - 19, - 370, - 285, - 441, - 295, - 195, - 248, - 197, - 457, - 440, - 274, - 301, - 300, - 368, - 417, - 351, - 465, - 251, - 301, - 389, - 385, - 380, - 386, - 394, - 395, - 379, - 399, - 412, - 419, - 410, - 436, - 322, - 387, - 373, - 388, - 326, - 2, - 393, - 354, - 370, - 461, - 393, - 164, - 267, - 268, - 302, - 12, - 386, - 374, - 387, - 312, - 268, - 13, - 298, - 293, - 301, - 265, - 446, - 340, - 380, - 385, - 381, - 280, - 330, - 425, - 322, - 426, - 391, - 420, - 429, - 437, - 393, - 391, - 326, - 344, - 440, - 438, - 458, - 459, - 461, - 364, - 434, - 394, - 428, - 396, - 262, - 274, - 354, - 457, - 317, - 316, - 402, - 316, - 315, - 403, - 315, - 314, - 404, - 314, - 313, - 405, - 313, - 421, - 406, - 323, - 366, - 361, - 292, - 306, - 407, - 306, - 291, - 408, - 291, - 287, - 409, - 287, - 432, - 410, - 427, - 434, - 411, - 372, - 264, - 383, - 459, - 309, - 457, - 366, - 352, - 401, - 1, - 274, - 4, - 418, - 421, - 262, - 331, - 294, - 358, - 435, - 433, - 367, - 392, - 289, - 439, - 328, - 462, - 326, - 94, - 2, - 370, - 289, - 305, - 455, - 339, - 254, - 448, - 359, - 255, - 446, - 254, - 253, - 449, - 253, - 252, - 450, - 252, - 256, - 451, - 256, - 341, - 452, - 414, - 413, - 463, - 286, - 441, - 414, - 286, - 258, - 441, - 258, - 257, - 442, - 257, - 259, - 443, - 259, - 260, - 444, - 260, - 467, - 445, - 309, - 459, - 250, - 305, - 289, - 290, - 305, - 290, - 460, - 401, - 376, - 435, - 309, - 250, - 392, - 376, - 411, - 433, - 453, - 341, - 464, - 357, - 453, - 465, - 343, - 357, - 412, - 437, - 343, - 399, - 344, - 360, - 440, - 420, - 437, - 456, - 360, - 420, - 363, - 361, - 401, - 288, - 265, - 372, - 353, - 390, - 339, - 249, - 339, - 448, - 255 -]; -var VTX68 = [ - 127, - 234, - 132, - 58, - 172, - 150, - 149, - 148, - 152, - 377, - 378, - 379, - 397, - 288, - 361, - 454, - 356, - 70, - 63, - 105, - 66, - 107, - 336, - 296, - 334, - 293, - 300, - 168, - 6, - 195, - 4, - 98, - 97, - 2, - 326, - 327, - 33, - 160, - 158, - 133, - 153, - 144, - 362, - 385, - 387, - 263, - 373, - 380, - 57, - 40, - 37, - 0, - 267, - 270, - 287, - 321, - 314, - 17, - 84, - 91, - 78, - 81, - 13, - 311, - 308, - 402, - 14, - 178 -]; -var VTX33 = [33, 133, 362, 263, 1, 62, 308, 159, 145, 386, 374, 6, 102, 331, 2, 13, 14, 70, 105, 107, 336, 334, 300, 54, 10, 284, 50, 280, 234, 454, 58, 288, 152]; -var VTX7 = [33, 133, 362, 263, 1, 78, 308]; -var UV68 = VTX68.map((x) => UV468[x]); -var UV33 = VTX33.map((x) => UV468[x]); -var UV7 = VTX7.map((x) => UV468[x]); -function connectionsToIndices(connections) { - const indices = connections.map((connection) => connection[0]); - indices.push(connections[connections.length - 1][1]); - return indices; -} -var pairsLips = [ - [61, 146], - [146, 91], - [91, 181], - [181, 84], - [84, 17], - [17, 314], - [314, 405], - [405, 321], - [321, 375], - [375, 291], - [61, 185], - [185, 40], - [40, 39], - [39, 37], - [37, 0], - [0, 267], - [267, 269], - [269, 270], - [270, 409], - [409, 291], - [78, 95], - [95, 88], - [88, 178], - [178, 87], - [87, 14], - [14, 317], - [317, 402], - [402, 318], - [318, 324], - [324, 308], - [78, 191], - [191, 80], - [80, 81], - [81, 82], - [82, 13], - [13, 312], - [312, 311], - [311, 310], - [310, 415], - [415, 308] -]; -var pairsLeftEye = [[263, 249], [249, 390], [390, 373], [373, 374], [374, 380], [380, 381], [381, 382], [382, 362], [263, 466], [466, 388], [388, 387], [387, 386], [386, 385], [385, 384], [384, 398], [398, 362]]; -var pairsLeftEyebrow = [[276, 283], [283, 282], [282, 295], [295, 285], [300, 293], [293, 334], [334, 296], [296, 336]]; -var pairsLeftIris = [[474, 475], [475, 476], [476, 477], [477, 474]]; -var pairsRightEye = [[33, 7], [7, 163], [163, 144], [144, 145], [145, 153], [153, 154], [154, 155], [155, 133], [33, 246], [246, 161], [161, 160], [160, 159], [159, 158], [158, 157], [157, 173], [173, 133]]; -var pairsRightEyebrow = [[46, 53], [53, 52], [52, 65], [65, 55], [70, 63], [63, 105], [105, 66], [66, 107]]; -var pairsRightIris = [[469, 470], [470, 471], [471, 472], [472, 469]]; -var pairsFaceContour = [ - [10, 338], - [338, 297], - [297, 332], - [332, 284], - [284, 251], - [251, 389], - [389, 356], - [356, 454], - [454, 323], - [323, 361], - [361, 288], - [288, 397], - [397, 365], - [365, 379], - [379, 378], - [378, 400], - [400, 377], - [377, 152], - [152, 148], - [148, 176], - [176, 149], - [149, 150], - [150, 136], - [136, 172], - [172, 58], - [58, 132], - [132, 93], - [93, 234], - [234, 127], - [127, 162], - [162, 21], - [21, 54], - [54, 103], - [103, 67], - [67, 109], - [109, 10] -]; -var contourKeypoints = { - lips: connectionsToIndices(pairsLips), - leftEye: connectionsToIndices(pairsLeftEye), - leftEyebrow: connectionsToIndices(pairsLeftEyebrow), - leftIris: connectionsToIndices(pairsLeftIris), - rightEye: connectionsToIndices(pairsRightEye), - rightEyebrow: connectionsToIndices(pairsRightEyebrow), - rightIris: connectionsToIndices(pairsRightIris), - faceOval: connectionsToIndices(pairsFaceContour) -}; - -// src/face/constants.ts -var LIPS_CONNECTIONS = [ - [61, 146], - [146, 91], - [91, 181], - [181, 84], - [84, 17], - [17, 314], - [314, 405], - [405, 321], - [321, 375], - [375, 291], - [61, 185], - [185, 40], - [40, 39], - [39, 37], - [37, 0], - [0, 267], - [267, 269], - [269, 270], - [270, 409], - [409, 291], - [78, 95], - [95, 88], - [88, 178], - [178, 87], - [87, 14], - [14, 317], - [317, 402], - [402, 318], - [318, 324], - [324, 308], - [78, 191], - [191, 80], - [80, 81], - [81, 82], - [82, 13], - [13, 312], - [312, 311], - [311, 310], - [310, 415], - [415, 308] -]; -var LEFT_EYE_CONNECTIONS = [[263, 249], [249, 390], [390, 373], [373, 374], [374, 380], [380, 381], [381, 382], [382, 362], [263, 466], [466, 388], [388, 387], [387, 386], [386, 385], [385, 384], [384, 398], [398, 362]]; -var LEFT_EYEBROW_CONNECTIONS = [[276, 283], [283, 282], [282, 295], [295, 285], [300, 293], [293, 334], [334, 296], [296, 336]]; -var LEFT_IRIS_CONNECTIONS = [[474, 475], [475, 476], [476, 477], [477, 474]]; -var RIGHT_EYE_CONNECTIONS = [[33, 7], [7, 163], [163, 144], [144, 145], [145, 153], [153, 154], [154, 155], [155, 133], [33, 246], [246, 161], [161, 160], [160, 159], [159, 158], [158, 157], [157, 173], [173, 133]]; -var RIGHT_EYEBROW_CONNECTIONS = [[46, 53], [53, 52], [52, 65], [65, 55], [70, 63], [63, 105], [105, 66], [66, 107]]; -var RIGHT_IRIS_CONNECTIONS = [[469, 470], [470, 471], [471, 472], [472, 469]]; -var FACE_OVAL_CONNECTIONS = [ - [10, 338], - [338, 297], - [297, 332], - [332, 284], - [284, 251], - [251, 389], - [389, 356], - [356, 454], - [454, 323], - [323, 361], - [361, 288], - [288, 397], - [397, 365], - [365, 379], - [379, 378], - [378, 400], - [400, 377], - [377, 152], - [152, 148], - [148, 176], - [176, 149], - [149, 150], - [150, 136], - [136, 172], - [172, 58], - [58, 132], - [132, 93], - [93, 234], - [234, 127], - [127, 162], - [162, 21], - [21, 54], - [54, 103], - [103, 67], - [67, 109], - [109, 10] -]; -function connectionsToIndices2(connections) { - const indices = connections.map((connection) => connection[0]); - indices.push(connections[connections.length - 1][1]); - return indices; -} -var MEDIAPIPE_FACE_MESH_KEYPOINTS_BY_CONTOUR = { - lips: connectionsToIndices2(LIPS_CONNECTIONS), - leftEye: connectionsToIndices2(LEFT_EYE_CONNECTIONS), - leftEyebrow: connectionsToIndices2(LEFT_EYEBROW_CONNECTIONS), - leftIris: connectionsToIndices2(LEFT_IRIS_CONNECTIONS), - rightEye: connectionsToIndices2(RIGHT_EYE_CONNECTIONS), - rightEyebrow: connectionsToIndices2(RIGHT_EYEBROW_CONNECTIONS), - rightIris: connectionsToIndices2(RIGHT_IRIS_CONNECTIONS), - faceOval: connectionsToIndices2(FACE_OVAL_CONNECTIONS) -}; -var indexLabelPairs = Object.entries(MEDIAPIPE_FACE_MESH_KEYPOINTS_BY_CONTOUR).map(([label, indices]) => indices.map((index2) => [index2, label])).flat(); -var MEDIAPIPE_FACE_MESH_KEYPOINTS = new Map(indexLabelPairs); -var LANDMARKS_REFINEMENT_LIPS_CONFIG = [ - 61, - 146, - 91, - 181, - 84, - 17, - 314, - 405, - 321, - 375, - 291, - 185, - 40, - 39, - 37, - 0, - 267, - 269, - 270, - 409, - 78, - 95, - 88, - 178, - 87, - 14, - 317, - 402, - 318, - 324, - 308, - 191, - 80, - 81, - 82, - 13, - 312, - 311, - 310, - 415, - 76, - 77, - 90, - 180, - 85, - 16, - 315, - 404, - 320, - 307, - 306, - 184, - 74, - 73, - 72, - 11, - 302, - 303, - 304, - 408, - 62, - 96, - 89, - 179, - 86, - 15, - 316, - 403, - 319, - 325, - 292, - 183, - 42, - 41, - 38, - 12, - 268, - 271, - 272, - 407 -]; -var LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG = [ - 33, - 7, - 163, - 144, - 145, - 153, - 154, - 155, - 133, - 246, - 161, - 160, - 159, - 158, - 157, - 173, - 130, - 25, - 110, - 24, - 23, - 22, - 26, - 112, - 243, - 247, - 30, - 29, - 27, - 28, - 56, - 190, - 226, - 31, - 228, - 229, - 230, - 231, - 232, - 233, - 244, - 113, - 225, - 224, - 223, - 222, - 221, - 189, - 35, - 124, - 46, - 53, - 52, - 65, - 143, - 111, - 117, - 118, - 119, - 120, - 121, - 128, - 245, - 156, - 70, - 63, - 105, - 66, - 107, - 55, - 193 -]; -var LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG = [ - 263, - 249, - 390, - 373, - 374, - 380, - 381, - 382, - 362, - 466, - 388, - 387, - 386, - 385, - 384, - 398, - 359, - 255, - 339, - 254, - 253, - 252, - 256, - 341, - 463, - 467, - 260, - 259, - 257, - 258, - 286, - 414, - 446, - 261, - 448, - 449, - 450, - 451, - 452, - 453, - 464, - 342, - 445, - 444, - 443, - 442, - 441, - 413, - 265, - 353, - 276, - 283, - 282, - 295, - 372, - 340, - 346, - 347, - 348, - 349, - 350, - 357, - 465, - 383, - 300, - 293, - 334, - 296, - 336, - 285, - 417 -]; - -// src/draw/face.ts -var localOptions; -function drawLabels(f, ctx) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i; - if (!localOptions.drawLabels || ((_a = localOptions.faceLabels) == null ? void 0 : _a.length) === 0) - return; - let l = localOptions.faceLabels.slice(); - if (f.score) - l = replace(l, "[score]", 100 * f.score); - if (f.gender) - l = replace(l, "[gender]", f.gender); - if (f.genderScore) - l = replace(l, "[genderScore]", 100 * f.genderScore); - if (f.age) - l = replace(l, "[age]", f.age); - if (f.distance) - l = replace(l, "[distance]", 100 * f.distance); - if (f.real) - l = replace(l, "[real]", 100 * f.real); - if (f.live) - l = replace(l, "[live]", 100 * f.live); - if (f.emotion && f.emotion.length > 0) { - const emotion2 = f.emotion.map((a) => `${Math.trunc(100 * a.score)}% ${a.emotion}`); - if (emotion2.length > 3) - emotion2.length = 3; - l = replace(l, "[emotions]", emotion2.join(" ")); - } - if ((_c = (_b = f.rotation) == null ? void 0 : _b.angle) == null ? void 0 : _c.roll) - l = replace(l, "[roll]", rad2deg(f.rotation.angle.roll)); - if ((_e = (_d = f.rotation) == null ? void 0 : _d.angle) == null ? void 0 : _e.yaw) - l = replace(l, "[yaw]", rad2deg(f.rotation.angle.yaw)); - if ((_g = (_f = f.rotation) == null ? void 0 : _f.angle) == null ? void 0 : _g.pitch) - l = replace(l, "[pitch]", rad2deg(f.rotation.angle.pitch)); - if ((_i = (_h = f.rotation) == null ? void 0 : _h.gaze) == null ? void 0 : _i.bearing) - l = replace(l, "[gaze]", rad2deg(f.rotation.gaze.bearing)); - labels(ctx, l, f.box[0], f.box[1], localOptions); -} -function drawIrisElipse(f, ctx) { - var _a, _b, _c, _d; - if (((_a = f.annotations) == null ? void 0 : _a.leftEyeIris) && ((_b = f.annotations) == null ? void 0 : _b.leftEyeIris[0])) { - ctx.strokeStyle = localOptions.useDepth ? "rgba(255, 200, 255, 0.3)" : localOptions.color; - ctx.beginPath(); - const sizeX = Math.abs(f.annotations.leftEyeIris[3][0] - f.annotations.leftEyeIris[1][0]) / 2; - const sizeY = Math.abs(f.annotations.leftEyeIris[4][1] - f.annotations.leftEyeIris[2][1]) / 2; - ctx.ellipse(f.annotations.leftEyeIris[0][0], f.annotations.leftEyeIris[0][1], sizeX, sizeY, 0, 0, 2 * Math.PI); - ctx.stroke(); - if (localOptions.fillPolygons) { - ctx.fillStyle = localOptions.useDepth ? "rgba(255, 255, 200, 0.3)" : localOptions.color; - ctx.fill(); - } - } - if (((_c = f.annotations) == null ? void 0 : _c.rightEyeIris) && ((_d = f.annotations) == null ? void 0 : _d.rightEyeIris[0])) { - ctx.strokeStyle = localOptions.useDepth ? "rgba(255, 200, 255, 0.3)" : localOptions.color; - ctx.beginPath(); - const sizeX = Math.abs(f.annotations.rightEyeIris[3][0] - f.annotations.rightEyeIris[1][0]) / 2; - const sizeY = Math.abs(f.annotations.rightEyeIris[4][1] - f.annotations.rightEyeIris[2][1]) / 2; - ctx.ellipse(f.annotations.rightEyeIris[0][0], f.annotations.rightEyeIris[0][1], sizeX, sizeY, 0, 0, 2 * Math.PI); - ctx.stroke(); - if (localOptions.fillPolygons) { - ctx.fillStyle = localOptions.useDepth ? "rgba(255, 255, 200, 0.3)" : localOptions.color; - ctx.fill(); - } - } -} -function drawGazeSpheres(f, ctx) { - var _a; - if (localOptions.drawGaze && ((_a = f.rotation) == null ? void 0 : _a.angle) && typeof Path2D !== "undefined") { - ctx.strokeStyle = "pink"; - const valX = f.box[0] + f.box[2] / 2 - f.box[3] * rad2deg(f.rotation.angle.yaw) / 90; - const valY = f.box[1] + f.box[3] / 2 + f.box[2] * rad2deg(f.rotation.angle.pitch) / 90; - const pathV = new Path2D(` - M ${f.box[0] + f.box[2] / 2} ${f.box[1]} +`;var at=(e,t,n)=>{let o=new RegExp("\\b"+t+" \\w+ (\\w+)","ig");e.replace(o,(s,A)=>(n[A]=0,s))},it=class{constructor(t,n,o){E(this,"uniform",{});E(this,"attribute",{});E(this,"gl");E(this,"id");E(this,"compile",(t,n)=>{let o=this.gl.createShader(n);return o?(this.gl.shaderSource(o,t),this.gl.compileShader(o),this.gl.getShaderParameter(o,this.gl.COMPILE_STATUS)?o:(h(`filter: gl compile failed: ${this.gl.getShaderInfoLog(o)||"unknown"}`),null)):(h("filter: could not create shader"),null)});this.gl=t;let s=this.compile(n,this.gl.VERTEX_SHADER),A=this.compile(o,this.gl.FRAGMENT_SHADER);if(this.id=this.gl.createProgram(),!(!s||!A)){if(!this.id){h("filter: could not create webgl program");return}if(this.gl.attachShader(this.id,s),this.gl.attachShader(this.id,A),this.gl.linkProgram(this.id),!this.gl.getProgramParameter(this.id,this.gl.LINK_STATUS)){h(`filter: gl link failed: ${this.gl.getProgramInfoLog(this.id)||"unknown"}`);return}this.gl.useProgram(this.id),at(n,"attribute",this.attribute);for(let a in this.attribute)this.attribute[a]=this.gl.getAttribLocation(this.id,a);at(n,"uniform",this.uniform),at(o,"uniform",this.uniform);for(let a in this.uniform)this.uniform[a]=this.gl.getUniformLocation(this.id,a)}}};function K5(){let e=0,t=null,n=!1,o=-1,s=[null,null],A=[],a=null,i=null,c=L0(100,100),d={},y={INTERMEDIATE:1},l=c.getContext("webgl");if(!l){h("filter: cannot get webgl context");return}this.gl=l;function f(v,p){if(!(v===c.width&&p===c.height)){if(c.width=v,c.height=p,!a){let b=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]);a=l.createBuffer(),l.bindBuffer(l.ARRAY_BUFFER,a),l.bufferData(l.ARRAY_BUFFER,b,l.STATIC_DRAW),l.pixelStorei(l.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0)}l.viewport(0,0,c.width,c.height),s=[null,null]}}function x(v,p){let b=l.createFramebuffer();l.bindFramebuffer(l.FRAMEBUFFER,b);let j=l.createRenderbuffer();l.bindRenderbuffer(l.RENDERBUFFER,j);let k=l.createTexture();return l.bindTexture(l.TEXTURE_2D,k),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,v,p,0,l.RGBA,l.UNSIGNED_BYTE,null),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.LINEAR),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.LINEAR),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.framebufferTexture2D(l.FRAMEBUFFER,l.COLOR_ATTACHMENT0,l.TEXTURE_2D,k,0),l.bindTexture(l.TEXTURE_2D,null),l.bindFramebuffer(l.FRAMEBUFFER,null),{fbo:b,texture:k}}function u(v){return s[v]=s[v]||x(c.width,c.height),s[v]}function m(v=0){if(!i)return;let p=null,b=null,j=!1;e===0?p=t:p=u(o).texture||null,e++,n&&!(v&y.INTERMEDIATE)?(b=null,j=e%2===0):(o=(o+1)%2,b=u(o).fbo||null),l.bindTexture(l.TEXTURE_2D,p),l.bindFramebuffer(l.FRAMEBUFFER,b),l.uniform1f(i.uniform.flipY,j?-1:1),l.drawArrays(l.TRIANGLES,0,6)}function g(v){if(d[v])return i=d[v],l.useProgram((i?i.id:null)||null),i;if(i=new it(l,V5,v),!i)return h("filter: could not get webgl program"),null;let p=Float32Array.BYTES_PER_ELEMENT,b=4*p;return l.enableVertexAttribArray(i.attribute.pos),l.vertexAttribPointer(i.attribute.pos,2,l.FLOAT,!1,b,0*p),l.enableVertexAttribArray(i.attribute.uv),l.vertexAttribPointer(i.attribute.uv,2,l.FLOAT,!1,b,2*p),d[v]=i,i}let P={colorMatrix:v=>{let p=new Float32Array(v);p[4]/=255,p[9]/=255,p[14]/=255,p[19]/=255;let b=p[18]===1&&p[3]===0&&p[8]===0&&p[13]===0&&p[15]===0&&p[16]===0&&p[17]===0&&p[19]===0?X5:Z5,j=g(b);!j||(l.uniform1fv(j.uniform.m,p),m())},brightness:v=>{let p=(v||0)+1;P.colorMatrix([p,0,0,0,0,0,p,0,0,0,0,0,p,0,0,0,0,0,1,0])},saturation:v=>{let p=(v||0)*2/3+1,b=(p-1)*-.5;P.colorMatrix([p,b,b,0,0,b,p,b,0,0,b,b,p,0,0,0,0,0,1,0])},desaturate:()=>{P.saturation(-1)},contrast:v=>{let p=(v||0)+1,b=-128*(p-1);P.colorMatrix([p,0,0,0,b,0,p,0,0,b,0,0,p,0,b,0,0,0,1,0])},negative:()=>{P.contrast(-2)},hue:v=>{v=(v||0)/180*Math.PI;let p=Math.cos(v),b=Math.sin(v),j=.213,k=.715,N=.072;P.colorMatrix([j+p*(1-j)+b*-j,k+p*-k+b*-k,N+p*-N+b*(1-N),0,0,j+p*-j+b*.143,k+p*(1-k)+b*.14,N+p*-N+b*-.283,0,0,j+p*-j+b*-(1-j),k+p*-k+b*k,N+p*(1-N)+b*N,0,0,0,0,0,1,0])},desaturateLuminance:()=>{P.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:()=>{P.colorMatrix([.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0])},brownie:()=>{P.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:()=>{P.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:()=>{P.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:()=>{P.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:()=>{P.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:()=>{P.colorMatrix([0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0])},convolution:v=>{let p=new Float32Array(v),b=1/c.width,j=1/c.height,k=g(Y5);!k||(l.uniform1fv(k.uniform.m,p),l.uniform2f(k.uniform.px,b,j),m())},detectEdges:()=>{P.convolution.call(this,[0,1,0,1,-4,1,0,1,0])},sobelX:()=>{P.convolution.call(this,[-1,0,1,-2,0,2,-1,0,1])},sobelY:()=>{P.convolution.call(this,[-1,-2,-1,0,0,0,1,2,1])},sharpen:v=>{let p=v||1;P.convolution.call(this,[0,-1*p,0,-1*p,1+4*p,-1*p,0,-1*p,0])},emboss:v=>{let p=v||1;P.convolution.call(this,[-2*p,-1*p,0,-1*p,1,1*p,0,1*p,2*p])},blur:v=>{let p=v/7/c.width,b=v/7/c.height,j=g(U5);!j||(l.uniform2f(j.uniform.px,0,b),m(y.INTERMEDIATE),l.uniform2f(j.uniform.px,p,0),m())},pixelate:v=>{let p=v/c.width,b=v/c.height,j=g(q5);!j||(l.uniform2f(j.uniform.size,p,b),m())}};this.add=function(v){let p=Array.prototype.slice.call(arguments,1),b=P[v];A.push({func:b,args:p})},this.reset=function(){A=[]},this.get=function(){return A},this.apply=function(v){f(v.width,v.height),e=0,t||(t=l.createTexture()),l.bindTexture(l.TEXTURE_2D,t),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,l.RGBA,l.UNSIGNED_BYTE,v);for(let p=0;py.data())),a=Math.max(A[0][0],A[1][0],A[2][0]),c=(a>1?255:1)/a,d;if(c>1){let y=[r.sub(n[0],o[0]),r.sub(n[1],o[1]),r.sub(n[2],o[2])],l=[r.sub(s[0],o[0]),r.sub(s[1],o[1]),r.sub(s[2],o[2])],f=[r.mul(y[0],c),r.mul(y[1],c),r.mul(y[2],c)],x=r.stack([f[0],f[1],f[2]],2);d=r.reshape(x,[1,t.shape[0]||0,t.shape[1]||0,3]),r.dispose([...y,...l,...f])}else d=r.expandDims(t,0);return r.dispose([...n,...o,...s,n,t,e]),d}var d2=3840,l0=null,c0=null,Oe=null,X,z0={inputSum:0,cacheDiff:1,sumMethod:0,inputTensor:void 0};function lt(){z0.inputSum=0,z0.cacheDiff=1,z0.sumMethod=0,z0.inputTensor=void 0}function L0(e,t){let n;if(M.browser)if(M.worker){if(typeof OffscreenCanvas=="undefined")throw new Error("canvas error: attempted to run in web worker but OffscreenCanvas is not supported");n=new OffscreenCanvas(e,t)}else{if(typeof document=="undefined")throw new Error("canvas error: attempted to run in browser but DOM is not defined");n=document.createElement("canvas"),n.width=e,n.height=t}else typeof M.Canvas!="undefined"?n=new M.Canvas(e,t):typeof globalThis.Canvas!="undefined"&&(n=new globalThis.Canvas(e,t));return n}function x2(e,t){let n=t||L0(e.width,e.height);return n.getContext("2d").drawImage(e,0,0),n}async function y2(e,t,n=!0){var f,x,u;if(!e)return t.debug&&h("input error: input is missing"),{tensor:null,canvas:null};if(!(e instanceof r.Tensor)&&!(typeof Image!="undefined"&&e instanceof Image)&&!(typeof globalThis.Canvas!="undefined"&&e instanceof globalThis.Canvas)&&!(typeof ImageData!="undefined"&&e instanceof ImageData)&&!(typeof ImageBitmap!="undefined"&&e instanceof ImageBitmap)&&!(typeof HTMLImageElement!="undefined"&&e instanceof HTMLImageElement)&&!(typeof HTMLMediaElement!="undefined"&&e instanceof HTMLMediaElement)&&!(typeof HTMLVideoElement!="undefined"&&e instanceof HTMLVideoElement)&&!(typeof HTMLCanvasElement!="undefined"&&e instanceof HTMLCanvasElement)&&!(typeof OffscreenCanvas!="undefined"&&e instanceof OffscreenCanvas))throw new Error("input error: type not recognized");if(e instanceof r.Tensor){let m=null;if(e.isDisposedInternal)throw new Error("input error: attempted to use tensor but it is disposed");if(!e.shape)throw new Error("input error: attempted to use tensor without a shape");if(e.shape.length===3){if(e.shape[2]===3)m=r.expandDims(e,0);else if(e.shape[2]===4){let g=r.slice3d(e,[0,0,0],[-1,-1,3]);m=r.expandDims(g,0),r.dispose(g)}}else e.shape.length===4&&(e.shape[3]===3?m=r.clone(e):e.shape[3]===4&&(m=r.slice4d(e,[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: ${e.shape.toString()}`);if(m.dtype==="int32"){let g=r.cast(m,"float32");r.dispose(m),m=g}return{tensor:m,canvas:t.filter.return?c0:null}}if(typeof e.readyState!="undefined"&&e.readyState<=2)return t.debug&&h("input stream is not ready"),{tensor:null,canvas:l0};let o=e.naturalWidth||e.videoWidth||e.width||e.shape&&e.shape[1]>0,s=e.naturalHeight||e.videoHeight||e.height||e.shape&&e.shape[2]>0;if(!o||!s)return t.debug&&h("cannot determine input dimensions"),{tensor:null,canvas:l0};let A=o,a=s;if(A>d2&&(A=d2,a=Math.trunc(A*s/o)),a>d2&&(a=d2,A=Math.trunc(a*o/s)),(((f=t.filter)==null?void 0:f.width)||0)>0?A=t.filter.width:(((x=t.filter)==null?void 0:x.height)||0)>0&&(A=o*((t.filter.height||0)/s)),(t.filter.height||0)>0?a=t.filter.height:(t.filter.width||0)>0&&(a=s*((t.filter.width||0)/o)),!A||!a)throw new Error("input error: cannot determine dimension");(!l0||l0.width!==A||l0.height!==a)&&(l0=L0(A,a));let i=l0.getContext("2d");if(typeof ImageData!="undefined"&&e instanceof ImageData?i.putImageData(e,0,0):t.filter.flip&&typeof i.translate!="undefined"?(i.translate(o,0),i.scale(-1,1),i.drawImage(e,0,0,o,s,0,0,l0.width,l0.height),i.setTransform(1,0,0,1,0,0)):i.drawImage(e,0,0,o,s,0,0,l0.width,l0.height),(!c0||l0.width!==c0.width||l0.height!==c0.height)&&(c0=L0(l0.width,l0.height)),t.filter.enabled&&M.webgl.supported?(X||(X=M.browser?new K5:null),M.filter=!!X,X!=null&&X.add?(X.reset(),t.filter.brightness!==0&&X.add("brightness",t.filter.brightness),t.filter.contrast!==0&&X.add("contrast",t.filter.contrast),t.filter.sharpness!==0&&X.add("sharpen",t.filter.sharpness),t.filter.blur!==0&&X.add("blur",t.filter.blur),t.filter.saturation!==0&&X.add("saturation",t.filter.saturation),t.filter.hue!==0&&X.add("hue",t.filter.hue),t.filter.negative&&X.add("negative"),t.filter.sepia&&X.add("sepia"),t.filter.vintage&&X.add("brownie"),t.filter.sepia&&X.add("sepia"),t.filter.kodachrome&&X.add("kodachrome"),t.filter.technicolor&&X.add("technicolor"),t.filter.polaroid&&X.add("polaroid"),t.filter.pixelate!==0&&X.add("pixelate",t.filter.pixelate),((u=X.get())==null?void 0:u.length)>1?c0=X.apply(l0):c0=X.draw(l0)):(t.debug&&h("input process error: cannot initialize filters"),M.webgl.supported=!1,t.filter.enabled=!1,x2(l0,c0))):(x2(l0,c0),X&&(X=null),M.filter=!!X),!n)return{tensor:null,canvas:c0};if(!c0)throw new Error("canvas error: cannot create output");let c,d=3;if(typeof ImageData!="undefined"&&e instanceof ImageData||e.data&&e.width&&e.height)if(M.browser&&r.browser)c=r.browser?r.browser.fromPixels(e):null;else{d=e.data.length/e.height/e.width;let m=new Uint8Array(e.data.buffer);c=r.tensor(m,[e.height,e.width,d],"int32")}else if((!Oe||c0.width!==Oe.width||c0.height!==Oe.height)&&(Oe=L0(c0.width,c0.height)),r.browser&&M.browser)t.backend==="webgl"||t.backend==="humangl"||t.backend==="webgpu"?c=r.browser.fromPixels(c0):(Oe=x2(c0),c=r.browser.fromPixels(Oe));else{let P=x2(c0).getContext("2d").getImageData(0,0,A,a);d=P.data.length/A/a;let v=new Uint8Array(P.data.buffer);c=r.tensor(v,[A,a,d])}if(d===4){let m=r.slice3d(c,[0,0,0],[-1,-1,3]);r.dispose(c),c=m}if(!c)throw new Error("input error: cannot create tensor");let y=r.cast(c,"float32"),l=t.filter.equalization?await c2(y):r.expandDims(y,0);if(r.dispose([c,y]),t.filter.autoBrightness){let m=r.max(l),g=await m.data();t.filter.brightness=g[0]>1?1-g[0]/255:1-g[0],r.dispose(m)}return{tensor:l,canvas:t.filter.return?c0:null}}async function J5(e,t){let n=!1;if(e.cacheSensitivity===0||!t.shape||t.shape.length!==4||t.shape[1]>3840||t.shape[2]>2160)return n;if(!z0.inputTensor)z0.inputTensor=r.clone(t);else if(z0.inputTensor.shape[1]!==t.shape[1]||z0.inputTensor.shape[2]!==t.shape[2])r.dispose(z0.inputTensor),z0.inputTensor=r.clone(t);else{let o={};o.diff=r.sub(t,z0.inputTensor),o.squared=r.mul(o.diff,o.diff),o.sum=r.sum(o.squared);let A=(await o.sum.data())[0]/(t.shape[1]||1)/(t.shape[2]||1)/255/3;r.dispose([z0.inputTensor,o.diff,o.squared,o.sum]),z0.inputTensor=r.clone(t),n=A<=(e.cacheSensitivity||0)}return n}async function Q5(e,t,n){let o={};if(!t||!n||t.shape.length!==4||t.shape.length!==n.shape.length)return e.debug||h("invalid input tensor or tensor shapes do not match:",t.shape,n.shape),0;if(t.shape[0]!==1||n.shape[0]!==1||t.shape[3]!==3||n.shape[3]!==3)return e.debug||h("input tensors must be of shape [1, height, width, 3]:",t.shape,n.shape),0;o.input1=r.clone(t),o.input2=t.shape[1]!==n.shape[1]||t.shape[2]!==n.shape[2]?r.image.resizeBilinear(n,[t.shape[1],t.shape[2]]):r.clone(n),o.diff=r.sub(o.input1,o.input2),o.squared=r.mul(o.diff,o.diff),o.sum=r.sum(o.squared);let A=(await o.sum.data())[0]/(t.shape[1]||1)/(t.shape[2]||1)/255/3;return r.dispose([o.input1,o.input2,o.diff,o.squared,o.sum]),A}var Je,Qe,_e,m2=class{constructor(){E(this,"browser");E(this,"node");E(this,"worker");E(this,"platform","");E(this,"agent","");E(this,"backends",[]);E(this,"initial");E(this,"filter");E(this,"tfjs");E(this,"offscreen");E(this,"perfadd",!1);E(this,"tensorflow",{version:void 0,gpu:void 0});E(this,"wasm",{supported:void 0,backend:void 0,simd:void 0,multithread:void 0});E(this,"webgl",{supported:void 0,backend:void 0,version:void 0,renderer:void 0,shader:void 0,vendor:void 0});E(this,"webgpu",{supported:void 0,backend:void 0,adapter:void 0});E(this,"cpu",{model:void 0,flags:[]});E(this,"kernels",[]);Z0(this,Je,void 0);Z0(this,Qe,void 0);Z0(this,_e,void 0);if(this.browser=typeof navigator!="undefined",this.node=typeof process!="undefined"&&typeof process.versions!="undefined"&&typeof process.versions.node!="undefined",this.tfjs={version:Ke["tfjs-core"]},this.offscreen=typeof OffscreenCanvas!="undefined",this.initial=!0,this.worker=this.browser&&this.offscreen?typeof WorkerGlobalScope!="undefined":void 0,typeof navigator!="undefined"){let t=navigator.userAgent.match(/\(([^()]+)\)/g);if(t!=null&&t[0]){let n=t[0].match(/\(([^()]+)\)/g);this.platform=n!=null&&n[0]?n[0].replace(/\(|\)/g,""):"",this.agent=navigator.userAgent.replace(t[0],""),this.platform[1]&&(this.agent=this.agent.replace(t[1],"")),this.agent=this.agent.replace(/ /g," ")}}else typeof process!="undefined"&&(this.platform=`${process.platform} ${process.arch}`,this.agent=`NodeJS ${process.version}`)}get Canvas(){return v0(this,Je)}set Canvas(t){Y0(this,Je,t),globalThis.Canvas=t}get Image(){return v0(this,Qe)}set Image(t){Y0(this,Qe,t),globalThis.Image=t}get ImageData(){return v0(this,_e)}set ImageData(t){Y0(this,_e,t),globalThis.ImageData=t}async updateBackend(){this.backends=Object.keys(r.engine().registryFactory);try{this.tensorflow={version:r.backend().binding?r.backend().binding.TF_Version:void 0,gpu:r.backend().binding?r.backend().binding.isUsingGpuDevice():void 0}}catch(o){}this.wasm.supported=typeof WebAssembly!="undefined",this.wasm.backend=this.backends.includes("wasm"),this.wasm.supported&&this.wasm.backend&&(this.wasm.simd=await r.env().getAsync("WASM_HAS_SIMD_SUPPORT"),this.wasm.multithread=await r.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"));let t=L0(100,100),n=t?t.getContext("webgl2"):void 0;this.webgl.supported=typeof n!="undefined",this.webgl.backend=this.backends.includes("webgl"),this.webgl.supported&&this.webgl.backend&&n&&(this.webgl.version=n.getParameter(n.VERSION),this.webgl.vendor=n.getParameter(n.VENDOR),this.webgl.renderer=n.getParameter(n.RENDERER),this.webgl.shader=n.getParameter(n.SHADING_LANGUAGE_VERSION)),this.webgpu.supported=this.browser&&typeof navigator.gpu!="undefined",this.webgpu.backend=this.backends.includes("webgpu");try{if(this.webgpu.supported){let o=await navigator.gpu.requestAdapter();this.webgpu.adapter=await(o==null?void 0:o.requestAdapterInfo())}}catch(o){this.webgpu.supported=!1}try{this.kernels=r.getKernelsForBackend(r.getBackend()).map(o=>o.kernelName.toLowerCase())}catch(o){}}updateCPU(){let t={model:"",flags:[]};this.node&&this.platform.startsWith("linux"),this.cpu?this.cpu=t:Object.defineProperty(this,"cpu",{value:t})}};Je=new WeakMap,Qe=new WeakMap,_e=new WeakMap;var M=new m2;var p2=class{constructor(){E(this,"config");E(this,"element");E(this,"stream");E(this,"devices",[]);E(this,"enumerate",async()=>{try{let t=await navigator.mediaDevices.enumerateDevices();this.devices=t.filter(n=>n.kind==="videoinput")}catch(t){this.devices=[]}return this.devices});E(this,"start",async t=>{var s,A;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{this.config.debug&&h("webcam","cannot get dom element",t.element);return}}else if(t.element instanceof HTMLVideoElement)this.element=t.element;else{this.config.debug&&h("webcam","unknown dom element",t.element);return}else this.element=document.createElement("video");let n={audio:!1,video:{facingMode:this.config.mode==="front"?"user":"environment",resizeMode:this.config.crop?"crop-and-scale":"none"}};if(((s=this.config)==null?void 0:s.width)>0&&(n.video.width={ideal:this.config.width}),((A=this.config)==null?void 0:A.height)>0&&(n.video.height={ideal:this.config.height}),this.config.id&&(n.video.deviceId=this.config.id),this.element.addEventListener("play",()=>{this.config.debug&&h("webcam","play")}),this.element.addEventListener("pause",()=>{this.config.debug&&h("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)){this.config.debug&&h("webcam","no devices");return}try{this.stream=await navigator.mediaDevices.getUserMedia(n)}catch(a){h("webcam",a);return}if(!this.stream){this.config.debug&&h("webcam","no stream");return}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&&h("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})});E(this,"pause",()=>{this.element&&this.element.pause()});E(this,"play",async()=>{this.element&&await this.element.play()});E(this,"stop",()=>{this.config.debug&&h("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}};var ct={};oe(ct,{age:()=>mo,"anti-spoofing":()=>Xo,antispoof:()=>no,blazeface:()=>oo,"blazeface-back":()=>po,"blazeface-front":()=>uo,"blazepose-detector":()=>ho,"blazepose-full":()=>bo,"blazepose-heavy":()=>go,"blazepose-lite":()=>To,centernet:()=>ro,default:()=>rr,efficientpose:()=>vo,"efficientpose-i-lite":()=>qo,"efficientpose-ii-lite":()=>Uo,"efficientpose-iv":()=>Yo,emotion:()=>so,faceboxes:()=>Ro,facemesh:()=>Ao,"facemesh-attention":()=>Po,"facemesh-attention-pinto":()=>Mo,"facemesh-detection-full":()=>ko,"facemesh-detection-short":()=>wo,faceres:()=>ao,"faceres-deep":()=>Eo,gear:()=>zo,gender:()=>jo,"gender-ssrnet-imdb":()=>So,handdetect:()=>Io,"handlandmark-full":()=>No,"handlandmark-lite":()=>io,"handlandmark-sparse":()=>Lo,handskeleton:()=>Oo,handtrack:()=>lo,"insightface-efficientnet-b0":()=>Ko,"insightface-ghostnet-strides1":()=>Jo,"insightface-ghostnet-strides2":()=>Qo,"insightface-mobilenet-emore":()=>_o,"insightface-mobilenet-swish":()=>$o,iris:()=>co,liveness:()=>xo,meet:()=>Co,mobileface:()=>Wo,mobilefacenet:()=>Do,models:()=>yo,"movenet-lightning":()=>fo,"movenet-multipose":()=>Fo,"movenet-thunder":()=>Bo,nanodet:()=>Ho,"nanodet-e":()=>er,"nanodet-g":()=>tr,"nanodet-m":()=>nr,"nanodet-t":()=>or,posenet:()=>Go,rvm:()=>Vo,selfie:()=>Zo});var no=853098,oo=538928,ro=4030290,so=820516,Ao=1477958,ao=6978814,io=2023432,lo=2964837,co=2599092,xo=592976,yo=0,fo=4650216,mo=161240,po=538928,uo=402048,ho=5928856,bo=6339202,go=27502466,To=2726402,vo=5651240,Ro=2013002,Mo=2387598,Po=2382414,ko=1026192,wo=201268,Eo=13957620,zo=1498916,So=161236,jo=201808,Io=3515612,No=5431368,Lo=5286322,Oo=5502280,Co=372228,Wo=2183192,Do=5171976,Fo=9448838,Bo=12477112,Ho=7574558,Go=5032780,Vo=3739355,Zo=212886,Xo=853098,qo=2269064,Uo=5651240,Yo=25643252,Ko=13013224,Jo=8093408,Qo=8049584,_o=6938536,$o=12168584,er=12319156,tr=7574558,nr=1887474,or=5294216,rr={antispoof:no,blazeface:oo,centernet:ro,emotion:so,facemesh:Ao,faceres:ao,"handlandmark-lite":io,handtrack:lo,iris:co,liveness:xo,models:yo,"movenet-lightning":fo,age:mo,"blazeface-back":po,"blazeface-front":uo,"blazepose-detector":ho,"blazepose-full":bo,"blazepose-heavy":go,"blazepose-lite":To,efficientpose:vo,faceboxes:Ro,"facemesh-attention-pinto":Mo,"facemesh-attention":Po,"facemesh-detection-full":ko,"facemesh-detection-short":wo,"faceres-deep":Eo,gear:zo,"gender-ssrnet-imdb":So,gender:jo,handdetect:Io,"handlandmark-full":No,"handlandmark-sparse":Lo,handskeleton:Oo,meet:Co,mobileface:Wo,mobilefacenet:Do,"movenet-multipose":Fo,"movenet-thunder":Bo,nanodet:Ho,posenet:Go,rvm:Vo,selfie:Zo,"anti-spoofing":Xo,"efficientpose-i-lite":qo,"efficientpose-ii-lite":Uo,"efficientpose-iv":Yo,"insightface-efficientnet-b0":Ko,"insightface-ghostnet-strides1":Jo,"insightface-ghostnet-strides2":Qo,"insightface-mobilenet-emore":_o,"insightface-mobilenet-swish":$o,"nanodet-e":er,"nanodet-g":tr,"nanodet-m":nr,"nanodet-t":or};var u0={cacheModels:!0,cacheSupported:!0,verbose:!0,debug:!1,modelBasePath:""},y0={};async function sr(e,t){return u0.debug&&h("load model fetch:",e,t),fetch(e,t)}function _5(e){u0.cacheModels=e.cacheModels,u0.verbose=e.debug,u0.modelBasePath=e.modelBasePath}async function L(e){var d,y,l,f;let t=G5(u0.modelBasePath,e||"");t.toLowerCase().endsWith(".json")||(t+=".json");let n=t.includes("/")?t.split("/"):t.split("\\"),o=n[n.length-1].replace(".json",""),s="indexeddb://"+o;y0[o]={name:o,sizeFromManifest:0,sizeLoadedWeights:0,sizeDesired:ct[o],inCache:!1,url:""},u0.cacheSupported=typeof indexedDB!="undefined";let A={};try{A=u0.cacheSupported&&u0.cacheModels?await r.io.listModels():{}}catch(x){u0.cacheSupported=!1}y0[o].inCache=u0.cacheSupported&&u0.cacheModels&&Object.keys(A).includes(s),y0[o].url=y0[o].inCache?s:t;let a=typeof fetch=="undefined"?{}:{fetchFunc:(x,u)=>sr(x,u)},i=new r.GraphModel(y0[o].url,a),c=!1;try{i.findIOHandler(),u0.debug&&h("model load handler:",i.handler)}catch(x){h("error finding model i/o handler:",t,x)}try{let x=await((d=i.handler)==null?void 0:d.load())||null;y0[o].sizeFromManifest=((y=x==null?void 0:x.weightData)==null?void 0:y.byteLength)||0,x?i.loadSync(x):i=await r.loadGraphModel(y0[o].inCache?s:t,a),y0[o].sizeLoadedWeights=((f=(l=i.artifacts)==null?void 0:l.weightData)==null?void 0:f.byteLength)||0,u0.verbose&&h("load:",{model:o,url:i.modelUrl,bytes:y0[o].sizeLoadedWeights}),c=!0}catch(x){h("error loading model:",t,x)}if(c&&u0.cacheModels&&u0.cacheSupported&&!y0[o].inCache)try{let x=await i.save(s);u0.debug&&h("model saved:",s,x)}catch(x){h("error saving model:",t,x)}return i}var dt="3.0.2";var Y={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 ir(){let e=Y.gl;!e||(Y.extensions=e.getSupportedExtensions())}function $5(e){var t;if(e.config.backend==="humangl"&&(Y.name in r.engine().registry&&!((t=Y==null?void 0:Y.gl)!=null&&t.getParameter(Y.gl.VERSION))&&(h("humangl error: backend invalid context"),e.models.reset()),!r.findBackend(Y.name))){try{Y.canvas=L0(100,100)}catch(s){h("humangl error: cannot create canvas:",s);return}try{if(Y.gl=Y.canvas.getContext("webgl2",Y.webGLattr),!Y.gl){h("humangl error: cannot get webgl context");return}if(!Y.gl.getParameter(Y.gl.VERSION).includes("2.0")){h("backend override: using fallback webgl backend as webgl 2.0 is not detected"),e.config.backend="webgl";return}Y.canvas&&(Y.canvas.addEventListener("webglcontextlost",A=>{throw h("humangl error:",A.type),h("possible browser memory leak using webgl or conflict with multiple backend registrations"),e.emit("error"),new Error("backend error: webgl context lost")}),Y.canvas.addEventListener("webglcontextrestored",A=>{h("humangl error: context restored:",A)}),Y.canvas.addEventListener("webglcontextcreationerror",A=>{h("humangl error: context create:",A)}))}catch(s){h("humangl error: cannot get webgl context:",s);return}try{r.setWebGLContext(2,Y.gl)}catch(s){h("humangl error: cannot set webgl context:",s);return}try{let s=new r.GPGPUContext(Y.gl);r.registerBackend(Y.name,()=>new r.MathBackendWebGL(s),Y.priority)}catch(s){h("humangl error: cannot register webgl backend:",s);return}try{r.getKernelsForBackend("webgl").forEach(A=>{let a={...A,backendName:Y.name};r.registerKernel(a)})}catch(s){h("humangl error: cannot update webgl backend registration:",s);return}try{r.env().flagRegistry.WEBGL_VERSION&&r.env().set("WEBGL_VERSION",2)}catch(s){h("humangl error: cannot set WebGL backend flags:",s);return}ir();let n=r.backend(),o=typeof n.gpgpu!="undefined"?n.getGPGPUContext().gl:null;o?e.config.debug&&h("humangl backend registered:",{webgl:o.getParameter(o.VERSION),renderer:o.getParameter(o.RENDERER)}):h("humangl error: no current gl context:",o,Y.gl)}}var O={tf255:255,tf1:1,tf2:2,tf05:.5,tf127:127.5,rgb:[.2989,.587,.114]};function e1(){O.tf255=r.scalar(255,"float32"),O.tf1=r.scalar(1,"float32"),O.tf2=r.scalar(2,"float32"),O.tf05=r.scalar(.5,"float32"),O.tf127=r.scalar(127.5,"float32"),O.rgb=r.tensor1d([.2989,.587,.114],"float32")}async function dr(){var e;return await M.updateBackend(),(e=M.tensorflow)!=null&&e.version?"tensorflow":M.webgpu.supported&&M.webgpu.backend?"webgpu":M.webgl.supported&&M.webgl.backend?"webgl":M.wasm.supported&&M.wasm.backend?"wasm":"cpu"}function xr(e){let t=[];if(!M.kernels.includes("mod")){let n={kernelName:"Mod",backendName:r.getBackend(),kernelFunc:o=>r.tidy(()=>r.sub(o.inputs.a,r.mul(r.div(o.inputs.a,o.inputs.b),o.inputs.b)))};r.registerKernel(n),M.kernels.push("mod"),t.push("mod")}if(!M.kernels.includes("floormod")){let n={kernelName:"FloorMod",backendName:r.getBackend(),kernelFunc:o=>r.tidy(()=>r.add(r.mul(r.floorDiv(o.inputs.a,o.inputs.b),o.inputs.b),r.mod(o.inputs.a,o.inputs.b)))};r.registerKernel(n),M.kernels.push("floormod"),t.push("floormod")}if(!M.kernels.includes("rotatewithoffset")&&e.softwareKernels){let n={kernelName:"RotateWithOffset",backendName:r.getBackend(),kernelFunc:o=>r.tidy(()=>{let s=r.getBackend();r.setBackend("cpu");let A=r.image.rotateWithOffset(o.inputs.image,o.attrs.radians,o.attrs.fillValue,o.attrs.center);return r.setBackend(s),A})};r.registerKernel(n),M.kernels.push("rotatewithoffset"),t.push("rotatewithoffset")}t.length>0&&e.debug&&h("registered kernels:",t)}var t1={};async function $e(e,t=!1){var n;if(e.state="backend",((n=e.config.backend)==null?void 0:n.length)===0&&(e.config.backend=await dr()),t||M.initial||e.config.backend&&e.config.backend.length>0&&r.getBackend()!==e.config.backend){let o=T();if(e.config.backend&&e.config.backend.length>0){if(typeof window=="undefined"&&typeof WorkerGlobalScope!="undefined"&&e.config.debug&&e.config.debug&&h("running inside web worker"),M.browser&&e.config.backend==="tensorflow"&&(e.config.debug&&h("override: backend set to tensorflow while running in browser"),e.config.backend="webgl"),M.node&&(e.config.backend==="webgl"||e.config.backend==="humangl")&&(e.config.debug&&h(`override: backend set to ${e.config.backend} while running in nodejs`),e.config.backend="tensorflow"),M.browser&&e.config.backend==="webgpu")if(typeof navigator=="undefined"||typeof navigator.gpu=="undefined")h("override: backend set to webgpu but browser does not support webgpu"),e.config.backend="webgl";else{let A=await navigator.gpu.requestAdapter();if(e.config.debug&&h("enumerated webgpu adapter:",A),!A)h("override: backend set to webgpu but browser reports no available gpu"),e.config.backend="webgl";else{let a="requestAdapterInfo"in A?await A.requestAdapterInfo():void 0;h("webgpu adapter info:",a)}}let s=Object.keys(r.engine().registryFactory);if(e.config.backend==="humangl"&&!s.includes("humangl")&&($5(e),s=Object.keys(r.engine().registryFactory)),e.config.debug&&h("available backends:",s),s.includes(e.config.backend)||(h(`error: backend ${e.config.backend} not found in registry`),e.config.backend=M.node?"tensorflow":"webgl",e.config.debug&&h(`override: setting backend ${e.config.backend}`)),e.config.debug&&h("setting backend:",[e.config.backend]),e.config.backend==="wasm"){if(r.env().flagRegistry.CANVAS2D_WILL_READ_FREQUENTLY&&r.env().set("CANVAS2D_WILL_READ_FREQUENTLY",!0),e.config.debug&&h("wasm path:",e.config.wasmPath),typeof r.setWasmPaths!="undefined")r.setWasmPaths(e.config.wasmPath,e.config.wasmPlatformFetch);else throw new Error("backend error: attempting to use wasm backend but wasm path is not set");let A=!1,a=!1;try{A=await r.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"),a=await r.env().getAsync("WASM_HAS_SIMD_SUPPORT"),e.config.debug&&h(`wasm execution: ${a?"simd":"no simd"} ${A?"multithreaded":"singlethreaded"}`),e.config.debug&&!a&&h("warning: wasm simd support is not enabled")}catch(i){h("wasm detection failed")}}try{await r.setBackend(e.config.backend),await r.ready()}catch(A){return h("error: cannot set backend:",e.config.backend,A),!1}e.config.debug&&(t1=JSON.parse(JSON.stringify(r.env().flags)))}if((r.getBackend()==="humangl"||r.getBackend()==="webgl")&&(r.env().flagRegistry.WEBGL_USE_SHAPES_UNIFORMS&&r.env().set("WEBGL_USE_SHAPES_UNIFORMS",!0),r.env().flagRegistry.WEBGL_EXP_CONV&&r.env().set("WEBGL_EXP_CONV",!0),e.config.debug&&typeof e.config.deallocate!="undefined"&&e.config.deallocate&&(h("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",!0),r.env().set("WEBGL_DELETE_TEXTURE_THRESHOLD",0))),r.getBackend(),e.config.debug){let s=r.env().flags,A={};for(let a of Object.keys(s))t1[a]!==s[a]&&(A[a]=s[a]);e.config.debug&&Object.keys(A).length>0&&h("backend:",r.getBackend(),"flags:",A)}if(e.config.flags&&Object.keys(e.config.flags).length>0){e.config.debug&&h("flags:",e.config.flags);for(let[s,A]of Object.entries(e.config.flags))r.env().set(s,A)}r.enableProdMode(),e1(),e.performance.initBackend=Math.trunc(T()-o),e.config.backend=r.getBackend(),await M.updateBackend(),xr(e.config),M.initial=!1}return!0}function u2(e,t){for(let n of e){let o={kernelName:n,backendName:t.backend,kernelFunc:s=>{var A;return t.debug&&h("kernelFunc",n,t.backend,s),(A=s==null?void 0:s.inputs)==null?void 0:A.info}};r.registerKernel(o)}M.kernels=r.getKernelsForBackend(r.getBackend()).map(n=>n.kernelName.toLowerCase())}var bt={};oe(bt,{all:()=>Vr,body:()=>b2,canvas:()=>Gr,face:()=>h2,gesture:()=>v2,hand:()=>g2,init:()=>ht,object:()=>T2,options:()=>e0,person:()=>Hr});var S0=e=>{if(!e)h("draw error: invalid canvas");else if(!e.getContext)h("draw error: canvas context not defined");else{let t=e.getContext("2d");if(!t)h("draw error: cannot get canvas context");else return t}return null},be=e=>Math.round(e*180/Math.PI),V=(e,t,n)=>e.replace(t,typeof n=="number"?n.toFixed(1):n),ge=(e,t)=>{if(!t.useDepth||typeof e=="undefined")return t.color;let n=Uint8ClampedArray.from([127+2*e,127-2*e,255]);return`rgba(${n[0]}, ${n[1]}, ${n[2]}, ${t.alpha})`};function O0(e,t,n,o,s){let A=t.replace(/\[.*\]/g,"").split(` +`).map(i=>i.trim()),a=Math.max(0,n);for(let i=A.length-1;i>=0;i--){let c=i*s.lineHeight+o;s.shadowColor&&s.shadowColor!==""&&(e.fillStyle=s.shadowColor,e.fillText(A[i],a+5,c+16)),e.fillStyle=s.labelColor,e.fillText(A[i],a+4,c+15)}}function K0(e,t,n,o,s){e.fillStyle=ge(o,s),e.beginPath(),e.arc(t,n,s.pointSize,0,2*Math.PI),e.fill()}function X0(e,t,n,o,s,A){if(e.beginPath(),e.lineWidth=A.lineWidth,A.useCurves){let a=(t+t+o)/2,i=(n+n+s)/2;e.ellipse(a,i,o/2,s/2,0,0,2*Math.PI)}else e.moveTo(t+A.roundRect,n),e.lineTo(t+o-A.roundRect,n),e.quadraticCurveTo(t+o,n,t+o,n+A.roundRect),e.lineTo(t+o,n+s-A.roundRect),e.quadraticCurveTo(t+o,n+s,t+o-A.roundRect,n+s),e.lineTo(t+A.roundRect,n+s),e.quadraticCurveTo(t,n+s,t,n+s-A.roundRect),e.lineTo(t,n+A.roundRect),e.quadraticCurveTo(t,n,t+A.roundRect,n),e.closePath();e.stroke()}function xt(e,t,n){if(!(t.length<2)){e.beginPath(),e.moveTo(t[0][0],t[0][1]);for(let o of t)e.strokeStyle=ge(o[2]||0,n),e.lineTo(Math.trunc(o[0]),Math.trunc(o[1]));e.stroke(),n.fillPolygons&&(e.closePath(),e.fill())}}function o1(e,t,n){if(!(t.length<2)){if(e.lineWidth=n.lineWidth,!n.useCurves||t.length<=2){xt(e,t,n);return}e.moveTo(t[0][0],t[0][1]);for(let o=0;oe2[e]),HA=fr.map(e=>e2[e]),GA=mr.map(e=>e2[e]);function re(e){let t=e.map(n=>n[0]);return t.push(e[e.length-1][1]),t}var pr=[[61,146],[146,91],[91,181],[181,84],[84,17],[17,314],[314,405],[405,321],[321,375],[375,291],[61,185],[185,40],[40,39],[39,37],[37,0],[0,267],[267,269],[269,270],[270,409],[409,291],[78,95],[95,88],[88,178],[178,87],[87,14],[14,317],[317,402],[402,318],[318,324],[324,308],[78,191],[191,80],[80,81],[81,82],[82,13],[13,312],[312,311],[311,310],[310,415],[415,308]],ur=[[263,249],[249,390],[390,373],[373,374],[374,380],[380,381],[381,382],[382,362],[263,466],[466,388],[388,387],[387,386],[386,385],[385,384],[384,398],[398,362]],hr=[[276,283],[283,282],[282,295],[295,285],[300,293],[293,334],[334,296],[296,336]],br=[[474,475],[475,476],[476,477],[477,474]],gr=[[33,7],[7,163],[163,144],[144,145],[145,153],[153,154],[154,155],[155,133],[33,246],[246,161],[161,160],[160,159],[159,158],[158,157],[157,173],[173,133]],Tr=[[46,53],[53,52],[52,65],[65,55],[70,63],[63,105],[105,66],[66,107]],vr=[[469,470],[470,471],[471,472],[472,469]],Rr=[[10,338],[338,297],[297,332],[332,284],[284,251],[251,389],[389,356],[356,454],[454,323],[323,361],[361,288],[288,397],[397,365],[365,379],[379,378],[378,400],[400,377],[377,152],[152,148],[148,176],[176,149],[149,150],[150,136],[136,172],[172,58],[58,132],[132,93],[93,234],[234,127],[127,162],[162,21],[21,54],[54,103],[103,67],[67,109],[109,10]],VA={lips:re(pr),leftEye:re(ur),leftEyebrow:re(hr),leftIris:re(br),rightEye:re(gr),rightEyebrow:re(Tr),rightIris:re(vr),faceOval:re(Rr)};var Mr=[[61,146],[146,91],[91,181],[181,84],[84,17],[17,314],[314,405],[405,321],[321,375],[375,291],[61,185],[185,40],[40,39],[39,37],[37,0],[0,267],[267,269],[269,270],[270,409],[409,291],[78,95],[95,88],[88,178],[178,87],[87,14],[14,317],[317,402],[402,318],[318,324],[324,308],[78,191],[191,80],[80,81],[81,82],[82,13],[13,312],[312,311],[311,310],[310,415],[415,308]],Pr=[[263,249],[249,390],[390,373],[373,374],[374,380],[380,381],[381,382],[382,362],[263,466],[466,388],[388,387],[387,386],[386,385],[385,384],[384,398],[398,362]],kr=[[276,283],[283,282],[282,295],[295,285],[300,293],[293,334],[334,296],[296,336]],wr=[[474,475],[475,476],[476,477],[477,474]],Er=[[33,7],[7,163],[163,144],[144,145],[145,153],[153,154],[154,155],[155,133],[33,246],[246,161],[161,160],[160,159],[159,158],[158,157],[157,173],[173,133]],zr=[[46,53],[53,52],[52,65],[65,55],[70,63],[63,105],[105,66],[66,107]],Sr=[[469,470],[470,471],[471,472],[472,469]],jr=[[10,338],[338,297],[297,332],[332,284],[284,251],[251,389],[389,356],[356,454],[454,323],[323,361],[361,288],[288,397],[397,365],[365,379],[379,378],[378,400],[400,377],[377,152],[152,148],[148,176],[176,149],[149,150],[150,136],[136,172],[172,58],[58,132],[132,93],[93,234],[234,127],[127,162],[162,21],[21,54],[54,103],[103,67],[67,109],[109,10]];function se(e){let t=e.map(n=>n[0]);return t.push(e[e.length-1][1]),t}var Ir={lips:se(Mr),leftEye:se(Pr),leftEyebrow:se(kr),leftIris:se(wr),rightEye:se(Er),rightEyebrow:se(zr),rightIris:se(Sr),faceOval:se(jr)},Nr=Object.entries(Ir).map(([e,t])=>t.map(n=>[n,e])).flat(),ZA=new Map(Nr),t2=[61,146,91,181,84,17,314,405,321,375,291,185,40,39,37,0,267,269,270,409,78,95,88,178,87,14,317,402,318,324,308,191,80,81,82,13,312,311,310,415,76,77,90,180,85,16,315,404,320,307,306,184,74,73,72,11,302,303,304,408,62,96,89,179,86,15,316,403,319,325,292,183,42,41,38,12,268,271,272,407],Re=[33,7,163,144,145,153,154,155,133,246,161,160,159,158,157,173,130,25,110,24,23,22,26,112,243,247,30,29,27,28,56,190,226,31,228,229,230,231,232,233,244,113,225,224,223,222,221,189,35,124,46,53,52,65,143,111,117,118,119,120,121,128,245,156,70,63,105,66,107,55,193],Me=[263,249,390,373,374,380,381,382,362,466,388,387,386,385,384,398,359,255,339,254,253,252,256,341,463,467,260,259,257,258,286,414,446,261,448,449,450,451,452,453,464,342,445,444,443,442,441,413,265,353,276,283,282,295,372,340,346,347,348,349,350,357,465,383,300,293,334,296,336,285,417];var G;function Lr(e,t){var o,s,A,a,i,c,d,y,l;if(!G.drawLabels||((o=G.faceLabels)==null?void 0:o.length)===0)return;let n=G.faceLabels.slice();if(e.score&&(n=V(n,"[score]",100*e.score)),e.gender&&(n=V(n,"[gender]",e.gender)),e.genderScore&&(n=V(n,"[genderScore]",100*e.genderScore)),e.age&&(n=V(n,"[age]",e.age)),e.distance&&(n=V(n,"[distance]",100*e.distance)),e.real&&(n=V(n,"[real]",100*e.real)),e.live&&(n=V(n,"[live]",100*e.live)),e.emotion&&e.emotion.length>0){let f=e.emotion.map(x=>`${Math.trunc(100*x.score)}% ${x.emotion}`);f.length>3&&(f.length=3),n=V(n,"[emotions]",f.join(" "))}(A=(s=e.rotation)==null?void 0:s.angle)!=null&&A.roll&&(n=V(n,"[roll]",be(e.rotation.angle.roll))),(i=(a=e.rotation)==null?void 0:a.angle)!=null&&i.yaw&&(n=V(n,"[yaw]",be(e.rotation.angle.yaw))),(d=(c=e.rotation)==null?void 0:c.angle)!=null&&d.pitch&&(n=V(n,"[pitch]",be(e.rotation.angle.pitch))),(l=(y=e.rotation)==null?void 0:y.gaze)!=null&&l.bearing&&(n=V(n,"[gaze]",be(e.rotation.gaze.bearing))),O0(t,n,e.box[0],e.box[1],G)}function Or(e,t){var n,o,s,A;if(((n=e.annotations)==null?void 0:n.leftEyeIris)&&((o=e.annotations)==null?void 0:o.leftEyeIris[0])){t.strokeStyle=G.useDepth?"rgba(255, 200, 255, 0.3)":G.color,t.beginPath();let a=Math.abs(e.annotations.leftEyeIris[3][0]-e.annotations.leftEyeIris[1][0])/2,i=Math.abs(e.annotations.leftEyeIris[4][1]-e.annotations.leftEyeIris[2][1])/2;t.ellipse(e.annotations.leftEyeIris[0][0],e.annotations.leftEyeIris[0][1],a,i,0,0,2*Math.PI),t.stroke(),G.fillPolygons&&(t.fillStyle=G.useDepth?"rgba(255, 255, 200, 0.3)":G.color,t.fill())}if(((s=e.annotations)==null?void 0:s.rightEyeIris)&&((A=e.annotations)==null?void 0:A.rightEyeIris[0])){t.strokeStyle=G.useDepth?"rgba(255, 200, 255, 0.3)":G.color,t.beginPath();let a=Math.abs(e.annotations.rightEyeIris[3][0]-e.annotations.rightEyeIris[1][0])/2,i=Math.abs(e.annotations.rightEyeIris[4][1]-e.annotations.rightEyeIris[2][1])/2;t.ellipse(e.annotations.rightEyeIris[0][0],e.annotations.rightEyeIris[0][1],a,i,0,0,2*Math.PI),t.stroke(),G.fillPolygons&&(t.fillStyle=G.useDepth?"rgba(255, 255, 200, 0.3)":G.color,t.fill())}}function Cr(e,t){var n;if(G.drawGaze&&((n=e.rotation)==null?void 0:n.angle)&&typeof Path2D!="undefined"){t.strokeStyle="pink";let o=e.box[0]+e.box[2]/2-e.box[3]*be(e.rotation.angle.yaw)/90,s=e.box[1]+e.box[3]/2+e.box[2]*be(e.rotation.angle.pitch)/90,A=new Path2D(` + M ${e.box[0]+e.box[2]/2} ${e.box[1]} C - ${valX} ${f.box[1]}, - ${valX} ${f.box[1] + f.box[3]}, - ${f.box[0] + f.box[2] / 2} ${f.box[1] + f.box[3]} - `); - const pathH = new Path2D(` - M ${f.box[0]} ${f.box[1] + f.box[3] / 2} + ${o} ${e.box[1]}, + ${o} ${e.box[1]+e.box[3]}, + ${e.box[0]+e.box[2]/2} ${e.box[1]+e.box[3]} + `),a=new Path2D(` + M ${e.box[0]} ${e.box[1]+e.box[3]/2} C - ${f.box[0]} ${valY}, - ${f.box[0] + f.box[2]} ${valY}, - ${f.box[0] + f.box[2]} ${f.box[1] + f.box[3] / 2} - `); - ctx.stroke(pathH); - ctx.stroke(pathV); - } -} -function drawGazeArrows(f, ctx) { - var _a; - if (localOptions.drawGaze && ((_a = f.rotation) == null ? void 0 : _a.gaze.strength) && f.rotation.gaze.bearing && f.annotations.leftEyeIris && f.annotations.rightEyeIris && f.annotations.leftEyeIris[0] && f.annotations.rightEyeIris[0]) { - ctx.strokeStyle = "pink"; - ctx.fillStyle = "pink"; - const leftGaze = [ - f.annotations.leftEyeIris[0][0] + Math.sin(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[3], - f.annotations.leftEyeIris[0][1] + Math.cos(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[2] - ]; - arrow(ctx, [f.annotations.leftEyeIris[0][0], f.annotations.leftEyeIris[0][1]], [leftGaze[0], leftGaze[1]], 4); - const rightGaze = [ - f.annotations.rightEyeIris[0][0] + Math.sin(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[3], - f.annotations.rightEyeIris[0][1] + Math.cos(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[2] - ]; - arrow(ctx, [f.annotations.rightEyeIris[0][0], f.annotations.rightEyeIris[0][1]], [rightGaze[0], rightGaze[1]], 4); - } -} -function drawFacePolygons(f, ctx) { - if (localOptions.drawPolygons && f.mesh.length >= 468) { - ctx.lineWidth = 1; - for (let i = 0; i < TRI468.length / 3; i++) { - const points = [TRI468[i * 3 + 0], TRI468[i * 3 + 1], TRI468[i * 3 + 2]].map((index2) => f.mesh[index2]); - lines(ctx, points, localOptions); - } - drawIrisElipse(f, ctx); - } -} -function drawFacePoints(f, ctx) { - if (localOptions.drawPoints && f.mesh.length >= 468) { - for (let i = 0; i < f.mesh.length; i++) { - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2], localOptions); - if (localOptions.drawAttention) { - if (LANDMARKS_REFINEMENT_LIPS_CONFIG.includes(i)) - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2] + 127, localOptions); - if (LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG.includes(i)) - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2] - 127, localOptions); - if (LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG.includes(i)) - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2] - 127, localOptions); - } - } - } -} -function drawFaceBoxes(f, ctx) { - if (localOptions.drawBoxes) { - rect(ctx, f.box[0], f.box[1], f.box[2], f.box[3], localOptions); - } -} -function face(inCanvas2, result, drawOptions) { - localOptions = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.font = localOptions.font; - ctx.strokeStyle = localOptions.color; - ctx.fillStyle = localOptions.color; - for (const f of result) { - drawFaceBoxes(f, ctx); - drawLabels(f, ctx); - if (f.mesh && f.mesh.length > 0) { - drawFacePoints(f, ctx); - drawFacePolygons(f, ctx); - drawGazeSpheres(f, ctx); - drawGazeArrows(f, ctx); - } - } -} - -// src/draw/body.ts -function body(inCanvas2, result, drawOptions) { - var _a, _b; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - for (let i = 0; i < result.length; i++) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - ctx.lineWidth = localOptions2.lineWidth; - ctx.font = localOptions2.font; - if (localOptions2.drawBoxes && result[i].box && result[i].box.length === 4) { - rect(ctx, result[i].box[0], result[i].box[1], result[i].box[2], result[i].box[3], localOptions2); - if (localOptions2.drawLabels && ((_a = localOptions2.bodyLabels) == null ? void 0 : _a.length) > 0) { - let l = localOptions2.bodyLabels.slice(); - l = replace(l, "[score]", 100 * result[i].score); - labels(ctx, l, result[i].box[0], result[i].box[1], localOptions2); - } - } - if (localOptions2.drawPoints && result[i].keypoints) { - for (let pt = 0; pt < result[i].keypoints.length; pt++) { - if (!result[i].keypoints[pt].score || result[i].keypoints[pt].score === 0) - continue; - ctx.fillStyle = colorDepth(result[i].keypoints[pt].position[2], localOptions2); - point(ctx, result[i].keypoints[pt].position[0], result[i].keypoints[pt].position[1], 0, localOptions2); - } - } - if (localOptions2.drawLabels && ((_b = localOptions2.bodyPartLabels) == null ? void 0 : _b.length) > 0 && result[i].keypoints) { - ctx.font = localOptions2.font; - for (const pt of result[i].keypoints) { - if (!pt.score || pt.score === 0) - continue; - let l = localOptions2.bodyPartLabels.slice(); - l = replace(l, "[label]", pt.part); - l = replace(l, "[score]", 100 * pt.score); - labels(ctx, l, pt.position[0], pt.position[1], localOptions2); - } - } - if (localOptions2.drawPolygons && result[i].keypoints && result[i].annotations) { - for (const part of Object.values(result[i].annotations)) { - for (const connected4 of part) - curves(ctx, connected4, localOptions2); - } - } - } -} - -// src/draw/hand.ts -function hand(inCanvas2, result, drawOptions) { - var _a, _b; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - ctx.font = localOptions2.font; - for (const h of result) { - if (localOptions2.drawBoxes) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - rect(ctx, h.box[0], h.box[1], h.box[2], h.box[3], localOptions2); - if (localOptions2.drawLabels && ((_a = localOptions2.handLabels) == null ? void 0 : _a.length) > 0) { - let l = localOptions2.handLabels.slice(); - l = replace(l, "[label]", h.label); - l = replace(l, "[score]", 100 * h.score); - labels(ctx, l, h.box[0], h.box[1], localOptions2); - } - ctx.stroke(); - } - if (localOptions2.drawPoints) { - if (h.keypoints && h.keypoints.length > 0) { - for (const pt of h.keypoints) { - ctx.fillStyle = colorDepth(pt[2], localOptions2); - point(ctx, pt[0], pt[1], 0, localOptions2); - } - } - } - if (localOptions2.drawLabels && h.annotations && ((_b = localOptions2.fingerLabels) == null ? void 0 : _b.length) > 0) { - for (const [part, pt] of Object.entries(h.annotations)) { - let l = localOptions2.fingerLabels.slice(); - l = replace(l, "[label]", part); - labels(ctx, l, pt[pt.length - 1][0], pt[pt.length - 1][1], localOptions2); - } - } - if (localOptions2.drawPolygons && h.annotations) { - const addHandLine = (part) => { - if (!part || part.length === 0 || !part[0]) - return; - for (let i = 0; i < part.length; i++) { - ctx.beginPath(); - const z = part[i][2] || 0; - ctx.strokeStyle = colorDepth(i * z, localOptions2); - ctx.moveTo(part[i > 0 ? i - 1 : 0][0], part[i > 0 ? i - 1 : 0][1]); - ctx.lineTo(part[i][0], part[i][1]); - ctx.stroke(); - } - }; - ctx.lineWidth = localOptions2.lineWidth; - addHandLine(h.annotations.index); - addHandLine(h.annotations.middle); - addHandLine(h.annotations.ring); - addHandLine(h.annotations.pinky); - addHandLine(h.annotations.thumb); - } - } -} - -// src/draw/object.ts -function object(inCanvas2, result, drawOptions) { - var _a; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - ctx.font = localOptions2.font; - for (const h of result) { - if (localOptions2.drawBoxes) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - rect(ctx, h.box[0], h.box[1], h.box[2], h.box[3], localOptions2); - if (localOptions2.drawLabels && ((_a = localOptions2.objectLabels) == null ? void 0 : _a.length) > 0) { - let l = localOptions2.objectLabels.slice(); - l = replace(l, "[label]", h.label); - l = replace(l, "[score]", 100 * h.score); - labels(ctx, l, h.box[0], h.box[1], localOptions2); - } - ctx.stroke(); - } - } -} - -// src/draw/gesture.ts -function gesture(inCanvas2, result, drawOptions) { - var _a; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - if (localOptions2.drawGestures && ((_a = localOptions2.gestureLabels) == null ? void 0 : _a.length) > 0) { - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.font = localOptions2.font; - ctx.fillStyle = localOptions2.color; - let i = 1; - for (let j = 0; j < result.length; j++) { - const [where, what] = Object.entries(result[j]); - if (what.length > 1 && what[1].length > 0) { - const who = where[1] > 0 ? `#${where[1]}` : ""; - let l = localOptions2.gestureLabels.slice(); - l = replace(l, "[where]", where[0]); - l = replace(l, "[who]", who); - l = replace(l, "[what]", what[1]); - labels(ctx, l, 8, 2 + i * localOptions2.lineHeight, localOptions2); - i += 1; - } - } - } -} - -// src/draw/labels.ts -var defaultLabels = { - face: `face + ${e.box[0]} ${s}, + ${e.box[0]+e.box[2]} ${s}, + ${e.box[0]+e.box[2]} ${e.box[1]+e.box[3]/2} + `);t.stroke(a),t.stroke(A)}}function Wr(e,t){var n;if(G.drawGaze&&((n=e.rotation)==null?void 0:n.gaze.strength)&&e.rotation.gaze.bearing&&e.annotations.leftEyeIris&&e.annotations.rightEyeIris&&e.annotations.leftEyeIris[0]&&e.annotations.rightEyeIris[0]){t.strokeStyle="pink",t.fillStyle="pink";let o=[e.annotations.leftEyeIris[0][0]+Math.sin(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[3],e.annotations.leftEyeIris[0][1]+Math.cos(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[2]];yt(t,[e.annotations.leftEyeIris[0][0],e.annotations.leftEyeIris[0][1]],[o[0],o[1]],4);let s=[e.annotations.rightEyeIris[0][0]+Math.sin(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[3],e.annotations.rightEyeIris[0][1]+Math.cos(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[2]];yt(t,[e.annotations.rightEyeIris[0][0],e.annotations.rightEyeIris[0][1]],[s[0],s[1]],4)}}function Dr(e,t){if(G.drawPolygons&&e.mesh.length>=468){t.lineWidth=1;for(let n=0;ne.mesh[s]);xt(t,o,G)}Or(e,t)}}function Fr(e,t){if(G.drawPoints&&e.mesh.length>=468)for(let n=0;n0&&(Fr(s,o),Dr(s,o),Cr(s,o),Wr(s,o))}}function b2(e,t,n){var A,a;let o=Q(e0,n);if(!t||!e)return;let s=S0(e);if(!!s){s.lineJoin="round";for(let i=0;i0)){let c=o.bodyLabels.slice();c=V(c,"[score]",100*t[i].score),O0(s,c,t[i].box[0],t[i].box[1],o)}if(o.drawPoints&&t[i].keypoints)for(let c=0;c0&&t[i].keypoints){s.font=o.font;for(let c of t[i].keypoints){if(!c.score||c.score===0)continue;let d=o.bodyPartLabels.slice();d=V(d,"[label]",c.part),d=V(d,"[score]",100*c.score),O0(s,d,c.position[0],c.position[1],o)}}if(o.drawPolygons&&t[i].keypoints&&t[i].annotations)for(let c of Object.values(t[i].annotations))for(let d of c)o1(s,d,o)}}}function g2(e,t,n){var A,a;let o=Q(e0,n);if(!t||!e)return;let s=S0(e);if(!!s){s.lineJoin="round",s.font=o.font;for(let i of t){if(o.drawBoxes){if(s.strokeStyle=o.color,s.fillStyle=o.color,X0(s,i.box[0],i.box[1],i.box[2],i.box[3],o),o.drawLabels&&((A=o.handLabels)==null?void 0:A.length)>0){let c=o.handLabels.slice();c=V(c,"[label]",i.label),c=V(c,"[score]",100*i.score),O0(s,c,i.box[0],i.box[1],o)}s.stroke()}if(o.drawPoints&&i.keypoints&&i.keypoints.length>0)for(let c of i.keypoints)s.fillStyle=ge(c[2],o),K0(s,c[0],c[1],0,o);if(o.drawLabels&&i.annotations&&((a=o.fingerLabels)==null?void 0:a.length)>0)for(let[c,d]of Object.entries(i.annotations)){let y=o.fingerLabels.slice();y=V(y,"[label]",c),O0(s,y,d[d.length-1][0],d[d.length-1][1],o)}if(o.drawPolygons&&i.annotations){let c=d=>{if(!(!d||d.length===0||!d[0]))for(let y=0;y0?y-1:0][0],d[y>0?y-1:0][1]),s.lineTo(d[y][0],d[y][1]),s.stroke()}};s.lineWidth=o.lineWidth,c(i.annotations.index),c(i.annotations.middle),c(i.annotations.ring),c(i.annotations.pinky),c(i.annotations.thumb)}}}}function T2(e,t,n){var A;let o=Q(e0,n);if(!t||!e)return;let s=S0(e);if(!!s){s.lineJoin="round",s.font=o.font;for(let a of t)if(o.drawBoxes){if(s.strokeStyle=o.color,s.fillStyle=o.color,X0(s,a.box[0],a.box[1],a.box[2],a.box[3],o),o.drawLabels&&((A=o.objectLabels)==null?void 0:A.length)>0){let i=o.objectLabels.slice();i=V(i,"[label]",a.label),i=V(i,"[score]",100*a.score),O0(s,i,a.box[0],a.box[1],o)}s.stroke()}}}function v2(e,t,n){var s;let o=Q(e0,n);if(!(!t||!e)&&o.drawGestures&&((s=o.gestureLabels)==null?void 0:s.length)>0){let A=S0(e);if(!A)return;A.font=o.font,A.fillStyle=o.color;let a=1;for(let i=0;i1&&d[1].length>0){let y=c[1]>0?`#${c[1]}`:"",l=o.gestureLabels.slice();l=V(l,"[where]",c[0]),l=V(l,"[who]",y),l=V(l,"[what]",d[1]),O0(A,l,8,2+a*o.lineHeight,o),a+=1}}}}var Ae={face:`face confidence: [score]% [gender] [genderScore]% age: [age] years @@ -6413,7473 +118,7 @@ var defaultLabels = { live: [live]% [emotions] roll: [roll]\xB0 yaw:[yaw]\xB0 pitch:[pitch]\xB0 - gaze: [gaze]\xB0`, - body: "body [score]%", - bodyPart: "[label] [score]%", - object: "[label] [score]%", - hand: "[label] [score]%", - finger: "[label]", - gesture: "[where] [who]: [what]" -}; - -// src/draw/draw.ts -var drawTime = 0; -function person(inCanvas2, result, drawOptions) { - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - ctx.font = localOptions2.font; - for (let i = 0; i < result.length; i++) { - if (localOptions2.drawBoxes) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - rect(ctx, result[i].box[0], result[i].box[1], result[i].box[2], result[i].box[3], localOptions2); - if (localOptions2.drawLabels) { - const label = `person #${i}`; - if (localOptions2.shadowColor && localOptions2.shadowColor !== "") { - ctx.fillStyle = localOptions2.shadowColor; - ctx.fillText(label, result[i].box[0] + 3, 1 + result[i].box[1] + localOptions2.lineHeight, result[i].box[2]); - } - ctx.fillStyle = localOptions2.labelColor; - ctx.fillText(label, result[i].box[0] + 2, 0 + result[i].box[1] + localOptions2.lineHeight, result[i].box[2]); - } - ctx.stroke(); - } - } -} -function canvas2(input, output) { - if (!input || !output) - return; - const ctx = getCanvasContext(output); - if (!ctx) - return; - ctx.drawImage(input, 0, 0); -} -async function all(inCanvas2, result, drawOptions) { - if (!(result == null ? void 0 : result.performance) || !inCanvas2) - return null; - const timeStamp = now(); - const localOptions2 = mergeDeep(options2, drawOptions); - const promise = Promise.all([ - face(inCanvas2, result.face, localOptions2), - body(inCanvas2, result.body, localOptions2), - hand(inCanvas2, result.hand, localOptions2), - object(inCanvas2, result.object, localOptions2), - gesture(inCanvas2, result.gesture, localOptions2) - ]); - drawTime = env.perfadd ? drawTime + Math.round(now() - timeStamp) : Math.round(now() - timeStamp); - result.performance.draw = drawTime; - return promise; -} -function init2() { - options2.faceLabels = defaultLabels.face; - options2.bodyLabels = defaultLabels.body; - options2.bodyPartLabels = defaultLabels.bodyPart; - options2.handLabels = defaultLabels.hand; - options2.fingerLabels = defaultLabels.finger; - options2.objectLabels = defaultLabels.object; - options2.gestureLabels = defaultLabels.gesture; -} - -// src/body/blazeposecoords.ts -var blazeposecoords_exports = {}; -__export(blazeposecoords_exports, { - connected: () => connected, - kpt: () => kpt -}); -var kpt = [ - "nose", - "leftEyeInside", - "leftEye", - "leftEyeOutside", - "rightEyeInside", - "rightEye", - "rightEyeOutside", - "leftEar", - "rightEar", - "leftMouth", - "rightMouth", - "leftShoulder", - "rightShoulder", - "leftElbow", - "rightElbow", - "leftWrist", - "rightWrist", - "leftPinky", - "rightPinky", - "leftIndex", - "rightIndex", - "leftThumb", - "rightThumb", - "leftHip", - "rightHip", - "leftKnee", - "rightKnee", - "leftAnkle", - "rightAnkle", - "leftHeel", - "rightHeel", - "leftFoot", - "rightFoot", - "bodyCenter", - "bodyTop", - "leftPalm", - "leftHand", - "rightPalm", - "rightHand" -]; -var connected = { - shoulders: ["leftShoulder", "rightShoulder"], - hips: ["rightHip", "leftHip"], - mouth: ["leftMouth", "rightMouth"], - leftLegUpper: ["leftHip", "leftKnee"], - leftLegLower: ["leftKnee", "leftAnkle"], - leftFoot: ["leftAnkle", "leftHeel", "leftFoot"], - leftTorso: ["leftShoulder", "leftHip"], - leftArmUpper: ["leftShoulder", "leftElbow"], - leftArmLower: ["leftElbow", "leftWrist"], - leftHand: ["leftWrist", "leftPalm"], - leftHandPinky: ["leftPalm", "leftPinky"], - leftHandIndex: ["leftPalm", "leftIndex"], - leftHandThumb: ["leftPalm", "leftThumb"], - leftEyeOutline: ["leftEyeInside", "leftEyeOutside"], - rightLegUpper: ["rightHip", "rightKnee"], - rightLegLower: ["rightKnee", "rightAnkle"], - rightFoot: ["rightAnkle", "rightHeel", "rightFoot"], - rightTorso: ["rightShoulder", "rightHip"], - rightArmUpper: ["rightShoulder", "rightElbow"], - rightArmLower: ["rightElbow", "rightWrist"], - rightHand: ["rightWrist", "rightPalm"], - rightHandPinky: ["rightPalm", "rightPinky"], - rightHandIndex: ["rightPalm", "rightIndex"], - rightHandThumb: ["rightPalm", "rightThumb"], - rightEyeOutline: ["rightEyeInside", "rightEyeOutside"] -}; - -// src/body/blazeposedetector.ts -var model; -var inputSize = 224; -var anchorTensor; -var numLayers = 5; -var strides = [8, 16, 32, 32, 32]; -function createAnchors() { - const anchors3 = []; - let layerId = 0; - while (layerId < numLayers) { - let anchorCount = 0; - let lastSameStrideLayer = layerId; - while (lastSameStrideLayer < strides.length && strides[lastSameStrideLayer] === strides[layerId]) { - anchorCount += 2; - lastSameStrideLayer++; - } - const stride = strides[layerId]; - const featureMapHeight = Math.ceil(inputSize / stride); - const featureMapWidth = Math.ceil(inputSize / stride); - for (let y = 0; y < featureMapHeight; ++y) { - for (let x = 0; x < featureMapWidth; ++x) { - for (let anchorId = 0; anchorId < anchorCount; ++anchorId) { - anchors3.push({ x: (x + 0.5) / featureMapWidth, y: (y + 0.5) / featureMapHeight }); - } - } - } - layerId = lastSameStrideLayer; - } - anchorTensor = { x: tfjs_esm_exports.tensor1d(anchors3.map((a) => a.x)), y: tfjs_esm_exports.tensor1d(anchors3.map((a) => a.y)) }; -} -async function loadDetector(config3) { - if (env.initial) - model = null; - if (!model && config3.body["detector"] && config3.body["detector"].modelPath || "") { - model = await loadModel(config3.body["detector"].modelPath); - const inputs = (model == null ? void 0 : model["executor"]) ? Object.values(model.modelSignature["inputs"]) : void 0; - inputSize = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - } else if (config3.debug && model) - log("cached model:", model["modelUrl"]); - createAnchors(); - return model; -} -var cropFactor = [5, 5]; -function decodeBoxes(boxesTensor, anchor) { - return tfjs_esm_exports.tidy(() => { - const split6 = tfjs_esm_exports.split(boxesTensor, 12, 1); - let xCenter = tfjs_esm_exports.squeeze(split6[0]); - let yCenter = tfjs_esm_exports.squeeze(split6[1]); - let width = tfjs_esm_exports.squeeze(split6[2]); - let height = tfjs_esm_exports.squeeze(split6[3]); - xCenter = tfjs_esm_exports.add(tfjs_esm_exports.div(xCenter, inputSize), anchor.x); - yCenter = tfjs_esm_exports.add(tfjs_esm_exports.div(yCenter, inputSize), anchor.y); - width = tfjs_esm_exports.mul(tfjs_esm_exports.div(width, inputSize), cropFactor[0]); - height = tfjs_esm_exports.mul(tfjs_esm_exports.div(height, inputSize), cropFactor[1]); - const xMin = tfjs_esm_exports.sub(xCenter, tfjs_esm_exports.div(width, 2)); - const yMin = tfjs_esm_exports.sub(yCenter, tfjs_esm_exports.div(height, 2)); - const xMax = tfjs_esm_exports.add(xMin, width); - const yMax = tfjs_esm_exports.add(yMin, height); - const boxes = tfjs_esm_exports.stack([xMin, yMin, xMax, yMax], 1); - return boxes; - }); -} -async function decodeResults(boxesTensor, logitsTensor, config3, outputSize2) { - var _a, _b; - const detectedBoxes = []; - const t2 = {}; - t2.boxes = decodeBoxes(boxesTensor, anchorTensor); - t2.scores = tfjs_esm_exports.sigmoid(logitsTensor); - t2.nms = await tfjs_esm_exports.image.nonMaxSuppressionAsync(t2.boxes, t2.scores, 1, ((_a = config3.body["detector"]) == null ? void 0 : _a.minConfidence) || 0.1, ((_b = config3.body["detector"]) == null ? void 0 : _b.iouThreshold) || 0.1); - const nms = await t2.nms.data(); - const scores = await t2.scores.data(); - const boxes = await t2.boxes.array(); - for (const i of Array.from(nms)) { - const score = scores[i]; - const boxRaw = boxes[i]; - const box = [Math.round(boxRaw[0] * outputSize2[0]), Math.round(boxRaw[1] * outputSize2[1]), Math.round(boxRaw[2] * outputSize2[0]), Math.round(boxRaw[3] * outputSize2[1])]; - const detectedBox = { score, boxRaw, box }; - detectedBoxes.push(detectedBox); - } - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - return detectedBoxes; -} -async function detectBoxes(input, config3, outputSize2) { - const t2 = {}; - t2.res = model == null ? void 0 : model.execute(input, ["Identity"]); - t2.logitsRaw = tfjs_esm_exports.slice(t2.res, [0, 0, 0], [1, -1, 1]); - t2.boxesRaw = tfjs_esm_exports.slice(t2.res, [0, 0, 1], [1, -1, -1]); - t2.logits = tfjs_esm_exports.squeeze(t2.logitsRaw); - t2.boxes = tfjs_esm_exports.squeeze(t2.boxesRaw); - const boxes = await decodeResults(t2.boxes, t2.logits, config3, outputSize2); - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - return boxes; -} - -// src/util/box.ts -function calc(keypoints, outputSize2 = [1, 1]) { - const coords = [keypoints.map((pt) => pt[0]), keypoints.map((pt) => pt[1])]; - const min2 = [Math.min(...coords[0]), Math.min(...coords[1])]; - const max5 = [Math.max(...coords[0]), Math.max(...coords[1])]; - const box = [min2[0], min2[1], max5[0] - min2[0], max5[1] - min2[1]]; - const boxRaw = [box[0] / outputSize2[0], box[1] / outputSize2[1], box[2] / outputSize2[0], box[3] / outputSize2[1]]; - return { box, boxRaw }; -} -function square(keypoints, outputSize2 = [1, 1]) { - const coords = [keypoints.map((pt) => pt[0]), keypoints.map((pt) => pt[1])]; - const min2 = [Math.min(...coords[0]), Math.min(...coords[1])]; - const max5 = [Math.max(...coords[0]), Math.max(...coords[1])]; - const center = [(min2[0] + max5[0]) / 2, (min2[1] + max5[1]) / 2]; - const dist = Math.max(center[0] - min2[0], center[1] - min2[1], -center[0] + max5[0], -center[1] + max5[1]); - const box = [Math.trunc(center[0] - dist), Math.trunc(center[1] - dist), Math.trunc(2 * dist), Math.trunc(2 * dist)]; - const boxRaw = [box[0] / outputSize2[0], box[1] / outputSize2[1], box[2] / outputSize2[0], box[3] / outputSize2[1]]; - return { box, boxRaw }; -} -function scale(box, scaleFact) { - const dist = [box[2] * scaleFact, box[3] * scaleFact]; - const newBox = [ - box[0] - (dist[0] - box[2]) / 2, - box[1] - (dist[1] - box[3]) / 2, - dist[0], - dist[1] - ]; - return newBox; -} - -// src/body/blazepose.ts -var model2; -var inputSize2 = 256; -var skipped = Number.MAX_SAFE_INTEGER; -var outputNodes = { - landmarks: ["ld_3d", "activation_segmentation", "activation_heatmap", "world_3d", "output_poseflag"], - detector: [] -}; -var cache = []; -var padding = [[0, 0], [0, 0], [0, 0], [0, 0]]; -var lastTime = 0; -var sigmoid2 = (x) => 1 - 1 / (1 + Math.exp(x)); -var loadDetect = (config3) => loadDetector(config3); -async function loadPose(config3) { - if (env.initial) - model2 = null; - if (!model2) { - model2 = await loadModel(config3.body.modelPath); - const inputs = (model2 == null ? void 0 : model2["executor"]) ? Object.values(model2.modelSignature["inputs"]) : void 0; - inputSize2 = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - } else if (config3.debug) - log("cached model:", model2["modelUrl"]); - return model2; -} -function prepareImage(input, size2, cropBox) { - var _a, _b; - const t2 = {}; - if (!((_a = input == null ? void 0 : input.shape) == null ? void 0 : _a[1]) || !((_b = input == null ? void 0 : input.shape) == null ? void 0 : _b[2])) - return input; - let final; - if (cropBox) { - t2.cropped = tfjs_esm_exports.image.cropAndResize(input, [cropBox], [0], [input.shape[1], input.shape[2]]); - } - if (input.shape[1] !== input.shape[2]) { - const height = [ - input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0, - input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0 - ]; - const width = [ - input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0, - input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0 - ]; - padding = [ - [0, 0], - height, - width, - [0, 0] - ]; - t2.pad = tfjs_esm_exports.pad(t2.cropped || input, padding); - t2.resize = tfjs_esm_exports.image.resizeBilinear(t2.pad, [size2, size2]); - final = tfjs_esm_exports.div(t2.resize, constants.tf255); - } else if (input.shape[1] !== size2) { - t2.resize = tfjs_esm_exports.image.resizeBilinear(t2.cropped || input, [size2, size2]); - final = tfjs_esm_exports.div(t2.resize, constants.tf255); - } else { - final = tfjs_esm_exports.div(t2.cropped || input, constants.tf255); - } - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - return final; -} -function rescaleKeypoints(keypoints, outputSize2, cropBox) { - for (const kpt4 of keypoints) { - kpt4.position = [ - Math.trunc(kpt4.position[0] * (outputSize2[0] + padding[2][0] + padding[2][1]) / outputSize2[0] - padding[2][0]), - Math.trunc(kpt4.position[1] * (outputSize2[1] + padding[1][0] + padding[1][1]) / outputSize2[1] - padding[1][0]), - kpt4.position[2] - ]; - kpt4.positionRaw = [kpt4.position[0] / outputSize2[0], kpt4.position[1] / outputSize2[1], 2 * kpt4.position[2] / (outputSize2[0] + outputSize2[1])]; - } - if (cropBox) { - const width = cropBox[2] - cropBox[0]; - const height = cropBox[3] - cropBox[1]; - for (const kpt4 of keypoints) { - kpt4.positionRaw = [ - kpt4.positionRaw[0] / height + cropBox[1], - kpt4.positionRaw[1] / width + cropBox[0], - kpt4.positionRaw[2] - ]; - kpt4.position = [ - Math.trunc(kpt4.positionRaw[0] * outputSize2[0]), - Math.trunc(kpt4.positionRaw[1] * outputSize2[1]), - kpt4.positionRaw[2] - ]; - } - } - return keypoints; -} -function fixKeypoints(keypoints) { - const leftPalm = keypoints.find((k) => k.part === "leftPalm"); - const leftWrist = keypoints.find((k) => k.part === "leftWrist"); - const leftIndex = keypoints.find((k) => k.part === "leftIndex"); - leftPalm.position[2] = ((leftWrist.position[2] || 0) + (leftIndex.position[2] || 0)) / 2; - const rightPalm = keypoints.find((k) => k.part === "rightPalm"); - const rightWrist = keypoints.find((k) => k.part === "rightWrist"); - const rightIndex = keypoints.find((k) => k.part === "rightIndex"); - rightPalm.position[2] = ((rightWrist.position[2] || 0) + (rightIndex.position[2] || 0)) / 2; -} -async function detectLandmarks(input, config3, outputSize2) { - if (!(model2 == null ? void 0 : model2["executor"])) - return null; - const t2 = {}; - [t2.ld, t2.segmentation, t2.heatmap, t2.world, t2.poseflag] = model2 == null ? void 0 : model2.execute(input, outputNodes.landmarks); - const poseScore = (await t2.poseflag.data())[0]; - const points = await t2.ld.data(); - const distances = await t2.world.data(); - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - const keypointsRelative = []; - const depth = 5; - for (let i = 0; i < points.length / depth; i++) { - const score = sigmoid2(points[depth * i + 3]); - const presence = sigmoid2(points[depth * i + 4]); - const adjScore = Math.trunc(100 * score * presence * poseScore) / 100; - const positionRaw = [points[depth * i + 0] / inputSize2, points[depth * i + 1] / inputSize2, points[depth * i + 2] + 0]; - const position = [Math.trunc(outputSize2[0] * positionRaw[0]), Math.trunc(outputSize2[1] * positionRaw[1]), positionRaw[2]]; - const distance2 = [distances[depth * i + 0], distances[depth * i + 1], distances[depth * i + 2] + 0]; - keypointsRelative.push({ part: kpt[i], positionRaw, position, distance: distance2, score: adjScore }); - } - if (poseScore < (config3.body.minConfidence || 0)) - return null; - fixKeypoints(keypointsRelative); - const keypoints = rescaleKeypoints(keypointsRelative, outputSize2); - const kpts = keypoints.map((k) => k.position); - const boxes = calc(kpts, [outputSize2[0], outputSize2[1]]); - const annotations2 = {}; - for (const [name, indexes] of Object.entries(connected)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = keypoints.find((kpt4) => kpt4.part === indexes[i]); - const pt1 = keypoints.find((kpt4) => kpt4.part === indexes[i + 1]); - if (pt0 && pt1) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - const body4 = { id: 0, score: Math.trunc(100 * poseScore) / 100, box: boxes.box, boxRaw: boxes.boxRaw, keypoints, annotations: annotations2 }; - return body4; -} -async function predict(input, config3) { - var _a, _b, _c; - const outputSize2 = [input.shape[2] || 0, input.shape[1] || 0]; - const skipTime = (config3.body.skipTime || 0) > now() - lastTime; - const skipFrame = skipped < (config3.body.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && cache !== null) { - skipped++; - } else { - let boxes = []; - if ((_b = (_a = config3.body) == null ? void 0 : _a["detector"]) == null ? void 0 : _b["enabled"]) { - const preparedImage = prepareImage(input, 224); - boxes = await detectBoxes(preparedImage, config3, outputSize2); - tfjs_esm_exports.dispose(preparedImage); - } else { - boxes = [{ box: [0, 0, 0, 0], boxRaw: [0, 0, 1, 1], score: 0 }]; - } - for (let i = 0; i < boxes.length; i++) { - const preparedBox = prepareImage(input, 256, (_c = boxes[i]) == null ? void 0 : _c.boxRaw); - cache.length = 0; - const bodyResult = await detectLandmarks(preparedBox, config3, outputSize2); - tfjs_esm_exports.dispose(preparedBox); - if (!bodyResult) - continue; - bodyResult.id = i; - cache.push(bodyResult); - } - lastTime = now(); - skipped = 0; - } - return cache; -} - -// src/object/labels.ts -var labels2 = [ - { class: 1, label: "person" }, - { class: 2, label: "bicycle" }, - { class: 3, label: "car" }, - { class: 4, label: "motorcycle" }, - { class: 5, label: "airplane" }, - { class: 6, label: "bus" }, - { class: 7, label: "train" }, - { class: 8, label: "truck" }, - { class: 9, label: "boat" }, - { class: 10, label: "traffic light" }, - { class: 11, label: "fire hydrant" }, - { class: 12, label: "stop sign" }, - { class: 13, label: "parking meter" }, - { class: 14, label: "bench" }, - { class: 15, label: "bird" }, - { class: 16, label: "cat" }, - { class: 17, label: "dog" }, - { class: 18, label: "horse" }, - { class: 19, label: "sheep" }, - { class: 20, label: "cow" }, - { class: 21, label: "elephant" }, - { class: 22, label: "bear" }, - { class: 23, label: "zebra" }, - { class: 24, label: "giraffe" }, - { class: 25, label: "backpack" }, - { class: 26, label: "umbrella" }, - { class: 27, label: "handbag" }, - { class: 28, label: "tie" }, - { class: 29, label: "suitcase" }, - { class: 30, label: "frisbee" }, - { class: 31, label: "skis" }, - { class: 32, label: "snowboard" }, - { class: 33, label: "sports ball" }, - { class: 34, label: "kite" }, - { class: 35, label: "baseball bat" }, - { class: 36, label: "baseball glove" }, - { class: 37, label: "skateboard" }, - { class: 38, label: "surfboard" }, - { class: 39, label: "tennis racket" }, - { class: 40, label: "bottle" }, - { class: 41, label: "wine glass" }, - { class: 42, label: "cup" }, - { class: 43, label: "fork" }, - { class: 44, label: "knife" }, - { class: 45, label: "spoon" }, - { class: 46, label: "bowl" }, - { class: 47, label: "banana" }, - { class: 48, label: "apple" }, - { class: 49, label: "sandwich" }, - { class: 50, label: "orange" }, - { class: 51, label: "broccoli" }, - { class: 52, label: "carrot" }, - { class: 53, label: "hot dog" }, - { class: 54, label: "pizza" }, - { class: 55, label: "donut" }, - { class: 56, label: "cake" }, - { class: 57, label: "chair" }, - { class: 58, label: "couch" }, - { class: 59, label: "potted plant" }, - { class: 60, label: "bed" }, - { class: 61, label: "dining table" }, - { class: 62, label: "toilet" }, - { class: 63, label: "tv" }, - { class: 64, label: "laptop" }, - { class: 65, label: "mouse" }, - { class: 66, label: "remote" }, - { class: 67, label: "keyboard" }, - { class: 68, label: "cell phone" }, - { class: 69, label: "microwave" }, - { class: 70, label: "oven" }, - { class: 71, label: "toaster" }, - { class: 72, label: "sink" }, - { class: 73, label: "refrigerator" }, - { class: 74, label: "book" }, - { class: 75, label: "clock" }, - { class: 76, label: "vase" }, - { class: 77, label: "scissors" }, - { class: 78, label: "teddy bear" }, - { class: 79, label: "hair drier" }, - { class: 80, label: "toothbrush" } -]; - -// src/object/centernet.ts -var model3; -var inputSize3 = 0; -var last2 = []; -var lastTime2 = 0; -var skipped2 = Number.MAX_SAFE_INTEGER; -async function load(config3) { - if (env.initial) - model3 = null; - if (!model3) { - model3 = await loadModel(config3.object.modelPath); - const inputs = (model3 == null ? void 0 : model3["executor"]) ? Object.values(model3.modelSignature["inputs"]) : void 0; - inputSize3 = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 0; - } else if (config3.debug) - log("cached model:", model3["modelUrl"]); - return model3; -} -async function process3(res, outputShape, config3) { - if (!res) - return []; - const t2 = {}; - const results = []; - const detections = await res.array(); - t2.squeeze = tfjs_esm_exports.squeeze(res); - const arr = tfjs_esm_exports.split(t2.squeeze, 6, 1); - t2.stack = tfjs_esm_exports.stack([arr[1], arr[0], arr[3], arr[2]], 1); - t2.boxes = tfjs_esm_exports.squeeze(t2.stack); - t2.scores = tfjs_esm_exports.squeeze(arr[4]); - t2.classes = tfjs_esm_exports.squeeze(arr[5]); - tfjs_esm_exports.dispose([res, ...arr]); - t2.nms = await tfjs_esm_exports.image.nonMaxSuppressionAsync(t2.boxes, t2.scores, config3.object.maxDetected || 0, config3.object.iouThreshold, config3.object.minConfidence || 0); - const nms = await t2.nms.data(); - let i = 0; - for (const id of Array.from(nms)) { - const score = Math.trunc(100 * detections[0][id][4]) / 100; - const classVal = detections[0][id][5]; - if (Number.isNaN(classVal)) - continue; - const label = labels2[classVal].label; - const [x, y] = [ - detections[0][id][0] / inputSize3, - detections[0][id][1] / inputSize3 - ]; - const boxRaw = [ - x, - y, - detections[0][id][2] / inputSize3 - x, - detections[0][id][3] / inputSize3 - y - ]; - const box = [ - Math.trunc(boxRaw[0] * outputShape[0]), - Math.trunc(boxRaw[1] * outputShape[1]), - Math.trunc(boxRaw[2] * outputShape[0]), - Math.trunc(boxRaw[3] * outputShape[1]) - ]; - results.push({ id: i++, score, class: classVal, label, box, boxRaw }); - } - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - return results; -} -async function predict2(input, config3) { - if (!(model3 == null ? void 0 : model3["executor"])) - return []; - const skipTime = (config3.object.skipTime || 0) > now() - lastTime2; - const skipFrame = skipped2 < (config3.object.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && last2.length > 0) { - skipped2++; - return last2; - } - skipped2 = 0; - return new Promise(async (resolve) => { - const outputSize2 = [input.shape[2] || 0, input.shape[1] || 0]; - const resize = tfjs_esm_exports.image.resizeBilinear(input, [inputSize3, inputSize3]); - const objectT = config3.object.enabled ? model3 == null ? void 0 : model3.execute(resize, ["tower_0/detections"]) : null; - lastTime2 = now(); - tfjs_esm_exports.dispose(resize); - const obj = await process3(objectT, outputSize2, config3); - last2 = obj; - resolve(obj); - }); -} - -// src/body/efficientposecoords.ts -var efficientposecoords_exports = {}; -__export(efficientposecoords_exports, { - connected: () => connected2, - kpt: () => kpt2 -}); -var kpt2 = [ - "head", - "neck", - "rightShoulder", - "rightElbow", - "rightWrist", - "chest", - "leftShoulder", - "leftElbow", - "leftWrist", - "bodyCenter", - "rightHip", - "rightKnee", - "rightAnkle", - "leftHip", - "leftKnee", - "leftAnkle" -]; -var connected2 = { - leftLeg: ["leftHip", "leftKnee", "leftAnkle"], - rightLeg: ["rightHip", "rightKnee", "rightAnkle"], - torso: ["leftShoulder", "rightShoulder", "rightHip", "leftHip", "leftShoulder"], - leftArm: ["leftShoulder", "leftElbow", "leftWrist"], - rightArm: ["rightShoulder", "rightElbow", "rightWrist"], - head: [] -}; - -// src/body/efficientpose.ts -var model4; -var lastTime3 = 0; -var cache2 = { id: 0, keypoints: [], box: [0, 0, 0, 0], boxRaw: [0, 0, 0, 0], score: 0, annotations: {} }; -var skipped3 = Number.MAX_SAFE_INTEGER; -async function load2(config3) { - if (env.initial) - model4 = null; - if (!model4) - model4 = await loadModel(config3.body.modelPath); - else if (config3.debug) - log("cached model:", model4["modelUrl"]); - return model4; -} -async function max2d(inputs, minScore) { - const [width, height] = inputs.shape; - const reshaped = tfjs_esm_exports.reshape(inputs, [height * width]); - const max5 = tfjs_esm_exports.max(reshaped, 0); - const newScore = (await max5.data())[0]; - if (newScore > minScore) { - const coordinates = tfjs_esm_exports.argMax(reshaped, 0); - const mod3 = tfjs_esm_exports.mod(coordinates, width); - const x = (await mod3.data())[0]; - const div15 = tfjs_esm_exports.div(coordinates, width); - const y = (await div15.data())[0]; - tfjs_esm_exports.dispose([reshaped, max5, coordinates, mod3, div15]); - return [x, y, newScore]; - } - tfjs_esm_exports.dispose([reshaped, max5]); - return [0, 0, newScore]; -} -async function predict3(image28, config3) { - if (!(model4 == null ? void 0 : model4["executor"]) || !(model4 == null ? void 0 : model4.inputs[0].shape)) - return []; - const skipTime = (config3.body.skipTime || 0) > now() - lastTime3; - const skipFrame = skipped3 < (config3.body.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && Object.keys(cache2.keypoints).length > 0) { - skipped3++; - return [cache2]; - } - skipped3 = 0; - return new Promise(async (resolve) => { - const tensor6 = tfjs_esm_exports.tidy(() => { - var _a, _b; - const resize = tfjs_esm_exports.image.resizeBilinear(image28, [((_a = model4 == null ? void 0 : model4.inputs[0].shape) == null ? void 0 : _a[2]) || 0, ((_b = model4 == null ? void 0 : model4.inputs[0].shape) == null ? void 0 : _b[1]) || 0], false); - const enhance2 = tfjs_esm_exports.mul(resize, constants.tf2); - const norm = tfjs_esm_exports.sub(enhance2, constants.tf1); - return norm; - }); - let resT; - if (config3.body.enabled) - resT = model4 == null ? void 0 : model4.execute(tensor6); - lastTime3 = now(); - tfjs_esm_exports.dispose(tensor6); - if (resT) { - cache2.keypoints.length = 0; - const squeeze14 = tfjs_esm_exports.squeeze(resT); - tfjs_esm_exports.dispose(resT); - const stack5 = tfjs_esm_exports.unstack(squeeze14, 2); - tfjs_esm_exports.dispose(squeeze14); - for (let id = 0; id < stack5.length; id++) { - const [x2, y2, partScore] = await max2d(stack5[id], config3.body.minConfidence); - if (partScore > (config3.body.minConfidence || 0)) { - cache2.keypoints.push({ - score: Math.round(100 * partScore) / 100, - part: kpt2[id], - positionRaw: [ - x2 / model4.inputs[0].shape[2], - y2 / model4.inputs[0].shape[1] - ], - position: [ - Math.round(image28.shape[2] * x2 / model4.inputs[0].shape[2]), - Math.round(image28.shape[1] * y2 / model4.inputs[0].shape[1]) - ] - }); - } - } - stack5.forEach((s) => tfjs_esm_exports.dispose(s)); - } - cache2.score = cache2.keypoints.reduce((prev, curr) => curr.score > prev ? curr.score : prev, 0); - const x = cache2.keypoints.map((a) => a.position[0]); - const y = cache2.keypoints.map((a) => a.position[1]); - cache2.box = [ - Math.min(...x), - Math.min(...y), - Math.max(...x) - Math.min(...x), - Math.max(...y) - Math.min(...y) - ]; - const xRaw = cache2.keypoints.map((a) => a.positionRaw[0]); - const yRaw = cache2.keypoints.map((a) => a.positionRaw[1]); - cache2.boxRaw = [ - Math.min(...xRaw), - Math.min(...yRaw), - Math.max(...xRaw) - Math.min(...xRaw), - Math.max(...yRaw) - Math.min(...yRaw) - ]; - for (const [name, indexes] of Object.entries(connected2)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = cache2.keypoints.find((kpt4) => kpt4.part === indexes[i]); - const pt1 = cache2.keypoints.find((kpt4) => kpt4.part === indexes[i + 1]); - if (pt0 && pt1 && pt0.score > (config3.body.minConfidence || 0) && pt1.score > (config3.body.minConfidence || 0)) - pt.push([pt0.position, pt1.position]); - } - cache2.annotations[name] = pt; - } - resolve([cache2]); - }); -} - -// src/face/facemeshutil.ts -var getBoxSize = (box) => [Math.abs(box.endPoint[0] - box.startPoint[0]), Math.abs(box.endPoint[1] - box.startPoint[1])]; -var getBoxCenter = (box) => [box.startPoint[0] + (box.endPoint[0] - box.startPoint[0]) / 2, box.startPoint[1] + (box.endPoint[1] - box.startPoint[1]) / 2, 1]; -var clampBox = (box, input) => box ? [ - Math.trunc(Math.max(0, box.startPoint[0])), - Math.trunc(Math.max(0, box.startPoint[1])), - Math.trunc(Math.min(input.shape[2] || 0, box.endPoint[0]) - Math.max(0, box.startPoint[0])), - Math.trunc(Math.min(input.shape[1] || 0, box.endPoint[1]) - Math.max(0, box.startPoint[1])) -] : [0, 0, 0, 0]; -var getRawBox = (box, input) => box ? [ - box.startPoint[0] / (input.shape[2] || 0), - box.startPoint[1] / (input.shape[1] || 0), - (box.endPoint[0] - box.startPoint[0]) / (input.shape[2] || 0), - (box.endPoint[1] - box.startPoint[1]) / (input.shape[1] || 0) -] : [0, 0, 0, 0]; -var scaleBoxCoordinates = (box, factor) => { - const startPoint = [box.startPoint[0] * factor[0], box.startPoint[1] * factor[1]]; - const endPoint = [box.endPoint[0] * factor[0], box.endPoint[1] * factor[1]]; - return { startPoint, endPoint, landmarks: box.landmarks, confidence: box.confidence }; -}; -var cutAndResize = (box, image28, cropSize) => { - const h = image28.shape[1]; - const w = image28.shape[2]; - const cutBox = [box.startPoint[1] / h, box.startPoint[0] / w, box.endPoint[1] / h, box.endPoint[0] / w]; - const crop = tfjs_esm_exports.image.cropAndResize(image28, [cutBox], [0], cropSize); - const norm = tfjs_esm_exports.div(crop, constants.tf255); - tfjs_esm_exports.dispose(crop); - return norm; -}; -var enlargeBox = (box, factor) => { - const center = getBoxCenter(box); - const size2 = getBoxSize(box); - const halfSize = [factor * size2[0] / 2, factor * size2[1] / 2]; - return { startPoint: [center[0] - halfSize[0], center[1] - halfSize[1]], endPoint: [center[0] + halfSize[0], center[1] + halfSize[1]], landmarks: box.landmarks, confidence: box.confidence }; -}; -var squarifyBox = (box) => { - const centers = getBoxCenter(box); - const size2 = getBoxSize(box); - const halfSize = Math.max(...size2) / 2; - return { startPoint: [Math.round(centers[0] - halfSize), Math.round(centers[1] - halfSize)], endPoint: [Math.round(centers[0] + halfSize), Math.round(centers[1] + halfSize)], landmarks: box.landmarks, confidence: box.confidence }; -}; -var calculateLandmarksBoundingBox = (landmarks) => { - const x = landmarks.map((d) => d[0]); - const y = landmarks.map((d) => d[1]); - return { startPoint: [Math.min(...x), Math.min(...y)], endPoint: [Math.max(...x), Math.max(...y)], landmarks }; -}; -var fixedRotationMatrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; -var normalizeRadians = (angle) => angle - 2 * Math.PI * Math.floor((angle + Math.PI) / (2 * Math.PI)); -var computeRotation = (point1, point2) => normalizeRadians(Math.PI / 2 - Math.atan2(-(point2[1] - point1[1]), point2[0] - point1[0])); -var buildTranslationMatrix = (x, y) => [[1, 0, x], [0, 1, y], [0, 0, 1]]; -var dot = (v1, v2) => { - let product = 0; - for (let i = 0; i < v1.length; i++) - product += v1[i] * v2[i]; - return product; -}; -var getColumnFrom2DArr = (arr, columnIndex) => { - const column = []; - for (let i = 0; i < arr.length; i++) - column.push(arr[i][columnIndex]); - return column; -}; -var multiplyTransformMatrices = (mat1, mat2) => { - const product = []; - const size2 = mat1.length; - for (let row = 0; row < size2; row++) { - product.push([]); - for (let col = 0; col < size2; col++) - product[row].push(dot(mat1[row], getColumnFrom2DArr(mat2, col))); - } - return product; -}; -var buildRotationMatrix = (rotation, center) => { - const cosA = Math.cos(rotation); - const sinA = Math.sin(rotation); - const rotationMatrix = [[cosA, -sinA, 0], [sinA, cosA, 0], [0, 0, 1]]; - const translationMatrix = buildTranslationMatrix(center[0], center[1]); - const translationTimesRotation = multiplyTransformMatrices(translationMatrix, rotationMatrix); - const negativeTranslationMatrix = buildTranslationMatrix(-center[0], -center[1]); - return multiplyTransformMatrices(translationTimesRotation, negativeTranslationMatrix); -}; -var invertTransformMatrix = (matrix) => { - const rotationComponent = [[matrix[0][0], matrix[1][0]], [matrix[0][1], matrix[1][1]]]; - const translationComponent = [matrix[0][2], matrix[1][2]]; - const invertedTranslation = [-dot(rotationComponent[0], translationComponent), -dot(rotationComponent[1], translationComponent)]; - return [rotationComponent[0].concat(invertedTranslation[0]), rotationComponent[1].concat(invertedTranslation[1]), [0, 0, 1]]; -}; -var rotatePoint = (homogeneousCoordinate, rotationMatrix) => [dot(homogeneousCoordinate, rotationMatrix[0]), dot(homogeneousCoordinate, rotationMatrix[1])]; -function generateAnchors(inputSize10) { - const spec = inputSize10 === 192 ? { strides: [4], anchors: [1] } : { strides: [inputSize10 / 16, inputSize10 / 8], anchors: [2, 6] }; - const anchors3 = []; - for (let i = 0; i < spec.strides.length; i++) { - const stride = spec.strides[i]; - const gridRows = Math.floor((inputSize10 + stride - 1) / stride); - const gridCols = Math.floor((inputSize10 + stride - 1) / stride); - const anchorsNum = spec.anchors[i]; - for (let gridY = 0; gridY < gridRows; gridY++) { - const anchorY = stride * (gridY + 0.5); - for (let gridX = 0; gridX < gridCols; gridX++) { - const anchorX = stride * (gridX + 0.5); - for (let n = 0; n < anchorsNum; n++) - anchors3.push([anchorX, anchorY]); - } - } - } - return anchors3; -} -function transformRawCoords(coordsRaw, box, angle, rotationMatrix, inputSize10) { - const boxSize = getBoxSize(box); - const coordsScaled = coordsRaw.map((coord) => [ - boxSize[0] / inputSize10 * (coord[0] - inputSize10 / 2), - boxSize[1] / inputSize10 * (coord[1] - inputSize10 / 2), - coord[2] || 0 - ]); - const largeAngle = angle && angle !== 0 && Math.abs(angle) > 0.2; - const coordsRotationMatrix = largeAngle ? buildRotationMatrix(angle, [0, 0]) : fixedRotationMatrix; - const coordsRotated = largeAngle ? coordsScaled.map((coord) => [...rotatePoint(coord, coordsRotationMatrix), coord[2]]) : coordsScaled; - const inverseRotationMatrix = largeAngle ? invertTransformMatrix(rotationMatrix) : fixedRotationMatrix; - const boxCenter = getBoxCenter(box); - const offsets = [dot(boxCenter, inverseRotationMatrix[0]), dot(boxCenter, inverseRotationMatrix[1])]; - return coordsRotated.map((coord) => [ - Math.trunc(coord[0] + offsets[0]), - Math.trunc(coord[1] + offsets[1]), - Math.trunc(coord[2] || 0) - ]); -} -function correctFaceRotation(rotate, box, input, inputSize10) { - const symmetryLine = box.landmarks.length >= meshLandmarks.count ? meshLandmarks.symmetryLine : blazeFaceLandmarks.symmetryLine; - let angle = 0; - let rotationMatrix = fixedRotationMatrix; - let face4; - if (rotate && env.kernels.includes("rotatewithoffset")) { - angle = computeRotation(box.landmarks[symmetryLine[0]], box.landmarks[symmetryLine[1]]); - const largeAngle = angle && angle !== 0 && Math.abs(angle) > 0.2; - if (largeAngle) { - const center = getBoxCenter(box); - const centerRaw = [center[0] / input.shape[2], center[1] / input.shape[1]]; - const rotated = tfjs_esm_exports.image.rotateWithOffset(input, angle, 0, [centerRaw[0], centerRaw[1]]); - rotationMatrix = buildRotationMatrix(-angle, center); - face4 = cutAndResize(box, rotated, [inputSize10, inputSize10]); - tfjs_esm_exports.dispose(rotated); - } else { - face4 = cutAndResize(box, input, [inputSize10, inputSize10]); - } - } else { - face4 = cutAndResize(box, input, [inputSize10, inputSize10]); - } - return [angle, rotationMatrix, face4]; -} -var findFaceCenter = (mesh) => { - const x = mesh.map((m) => m[0]); - const y = mesh.map((m) => m[1]); - return [Math.min(...x) + (Math.max(...x) - Math.min(...x)) / 2, Math.min(...y) + (Math.max(...y) - Math.min(...y)) / 2]; -}; -var calculateFaceBox = (mesh, previousBox) => { - const center = findFaceCenter(mesh); - const boxSize = getBoxSize(previousBox); - const calculatedBox = { - startPoint: [center[0] - boxSize[0] / 2, center[1] - boxSize[1] / 2], - endPoint: [center[0] + boxSize[0] / 2, center[1] + boxSize[1] / 2] - }; - return calculatedBox; -}; - -// src/face/blazeface.ts -var keypointsCount = 6; -var faceBoxScaleFactor = 1.4; -var model5; -var anchors = null; -var inputSize4 = 0; -var inputSizeT = null; -var size = () => inputSize4; -async function load3(config3) { - var _a; - if (env.initial) - model5 = null; - if (!model5) - model5 = await loadModel((_a = config3.face.detector) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model5["modelUrl"]); - inputSize4 = model5["executor"] && model5.inputs[0].shape ? model5.inputs[0].shape[2] : 256; - inputSizeT = tfjs_esm_exports.scalar(inputSize4, "int32"); - anchors = tfjs_esm_exports.tensor2d(generateAnchors(inputSize4)); - return model5; -} -function decodeBoxes2(boxOutputs) { - if (!anchors || !inputSizeT) - return tfjs_esm_exports.zeros([0, 0]); - const t2 = {}; - t2.boxStarts = tfjs_esm_exports.slice(boxOutputs, [0, 1], [-1, 2]); - t2.centers = tfjs_esm_exports.add(t2.boxStarts, anchors); - t2.boxSizes = tfjs_esm_exports.slice(boxOutputs, [0, 3], [-1, 2]); - t2.boxSizesNormalized = tfjs_esm_exports.div(t2.boxSizes, inputSizeT); - t2.centersNormalized = tfjs_esm_exports.div(t2.centers, inputSizeT); - t2.halfBoxSize = tfjs_esm_exports.div(t2.boxSizesNormalized, constants.tf2); - t2.starts = tfjs_esm_exports.sub(t2.centersNormalized, t2.halfBoxSize); - t2.ends = tfjs_esm_exports.add(t2.centersNormalized, t2.halfBoxSize); - t2.startNormalized = tfjs_esm_exports.mul(t2.starts, inputSizeT); - t2.endNormalized = tfjs_esm_exports.mul(t2.ends, inputSizeT); - const boxes = tfjs_esm_exports.concat2d([t2.startNormalized, t2.endNormalized], 1); - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - return boxes; -} -async function getBoxes(inputImage, config3) { - var _a, _b, _c, _d; - if (!inputImage || inputImage["isDisposedInternal"] || inputImage.shape.length !== 4 || inputImage.shape[1] < 1 || inputImage.shape[2] < 1) - return []; - const t2 = {}; - t2.resized = tfjs_esm_exports.image.resizeBilinear(inputImage, [inputSize4, inputSize4]); - t2.div = tfjs_esm_exports.div(t2.resized, constants.tf127); - t2.normalized = tfjs_esm_exports.sub(t2.div, constants.tf05); - const res = model5 == null ? void 0 : model5.execute(t2.normalized); - if (Array.isArray(res) && res.length > 2) { - const sorted = res.sort((a, b) => a.size - b.size); - t2.concat384 = tfjs_esm_exports.concat([sorted[0], sorted[2]], 2); - t2.concat512 = tfjs_esm_exports.concat([sorted[1], sorted[3]], 2); - t2.concat = tfjs_esm_exports.concat([t2.concat512, t2.concat384], 1); - t2.batch = tfjs_esm_exports.squeeze(t2.concat, [0]); - } else if (Array.isArray(res)) { - t2.batch = tfjs_esm_exports.squeeze(res[0]); - } else { - t2.batch = tfjs_esm_exports.squeeze(res); - } - tfjs_esm_exports.dispose(res); - t2.boxes = decodeBoxes2(t2.batch); - t2.logits = tfjs_esm_exports.slice(t2.batch, [0, 0], [-1, 1]); - t2.sigmoid = tfjs_esm_exports.sigmoid(t2.logits); - t2.scores = tfjs_esm_exports.squeeze(t2.sigmoid); - t2.nms = await tfjs_esm_exports.image.nonMaxSuppressionAsync(t2.boxes, t2.scores, ((_a = config3.face.detector) == null ? void 0 : _a.maxDetected) || 0, ((_b = config3.face.detector) == null ? void 0 : _b.iouThreshold) || 0, ((_c = config3.face.detector) == null ? void 0 : _c.minConfidence) || 0); - const nms = await t2.nms.array(); - const boxes = []; - const scores = await t2.scores.data(); - for (let i = 0; i < nms.length; i++) { - const confidence = scores[nms[i]]; - if (confidence > (((_d = config3.face.detector) == null ? void 0 : _d.minConfidence) || 0)) { - const b = {}; - b.bbox = tfjs_esm_exports.slice(t2.boxes, [nms[i], 0], [1, -1]); - b.slice = tfjs_esm_exports.slice(t2.batch, [nms[i], keypointsCount - 1], [1, -1]); - b.squeeze = tfjs_esm_exports.squeeze(b.slice); - b.landmarks = tfjs_esm_exports.reshape(b.squeeze, [keypointsCount, -1]); - const points = await b.bbox.data(); - const rawBox = { - startPoint: [points[0], points[1]], - endPoint: [points[2], points[3]], - landmarks: await b.landmarks.array(), - confidence - }; - const scaledBox = scaleBoxCoordinates(rawBox, [(inputImage.shape[2] || 0) / inputSize4, (inputImage.shape[1] || 0) / inputSize4]); - const enlargedBox = enlargeBox(scaledBox, config3.face["scale"] || faceBoxScaleFactor); - const squaredBox = squarifyBox(enlargedBox); - boxes.push(squaredBox); - Object.keys(b).forEach((tensor6) => tfjs_esm_exports.dispose(b[tensor6])); - } - } - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - return boxes; -} - -// src/face/iris.ts -var model6; -var inputSize5 = 0; -var irisEnlarge = 2.3; -var leftOutline = meshAnnotations.leftEyeLower0; -var rightOutline = meshAnnotations.rightEyeLower0; -var eyeLandmarks = { - leftBounds: [leftOutline[0], leftOutline[leftOutline.length - 1]], - rightBounds: [rightOutline[0], rightOutline[rightOutline.length - 1]] -}; -var irisLandmarks = { - upperCenter: 3, - lowerCenter: 4, - index: 71, - numCoordinates: 76 -}; -async function load4(config3) { - var _a, _b; - if (env.initial) - model6 = null; - if (!model6) - model6 = await loadModel((_a = config3.face.iris) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model6["modelUrl"]); - inputSize5 = (model6 == null ? void 0 : model6["executor"]) && ((_b = model6.inputs) == null ? void 0 : _b[0].shape) ? model6.inputs[0].shape[2] : 0; - if (inputSize5 === -1) - inputSize5 = 64; - return model6; -} -function replaceIrisCoords(rawCoords, newCoords, prefix, keys) { - for (let i = 0; i < irisIndices.length; i++) { - const { key, indices } = irisIndices[i]; - const originalIndices = meshAnnotations[`${prefix}${key}`]; - if (!keys || keys.includes(key)) { - for (let j = 0; j < indices.length; j++) { - const index2 = indices[j]; - rawCoords[originalIndices[j]] = [ - newCoords[index2][0], - newCoords[index2][1], - (newCoords[index2][2] + rawCoords[originalIndices[j]][2]) / 2 - ]; - } - } - } -} -var getLeftToRightEyeDepthDifference = (rawCoords) => { - const leftEyeZ = rawCoords[eyeLandmarks.leftBounds[0]][2]; - const rightEyeZ = rawCoords[eyeLandmarks.rightBounds[0]][2]; - return leftEyeZ - rightEyeZ; -}; -var getEyeBox = (rawCoords, face4, eyeInnerCornerIndex, eyeOuterCornerIndex, meshSize, flip = false) => { - const box = squarifyBox(enlargeBox(calculateLandmarksBoundingBox([rawCoords[eyeInnerCornerIndex], rawCoords[eyeOuterCornerIndex]]), irisEnlarge)); - const boxSize = getBoxSize(box); - let crop = tfjs_esm_exports.image.cropAndResize(face4, [[ - box.startPoint[1] / meshSize, - box.startPoint[0] / meshSize, - box.endPoint[1] / meshSize, - box.endPoint[0] / meshSize - ]], [0], [inputSize5, inputSize5]); - if (flip && env.kernels.includes("flipleftright")) { - const flipped = tfjs_esm_exports.image.flipLeftRight(crop); - tfjs_esm_exports.dispose(crop); - crop = flipped; - } - return { box, boxSize, crop }; -}; -var getEyeCoords = (eyeData, eyeBox, eyeBoxSize, flip = false) => { - const eyeRawCoords = []; - for (let i = 0; i < irisLandmarks.numCoordinates; i++) { - const x = eyeData[i * 3]; - const y = eyeData[i * 3 + 1]; - const z = eyeData[i * 3 + 2]; - eyeRawCoords.push([ - (flip ? 1 - x / inputSize5 : x / inputSize5) * eyeBoxSize[0] + eyeBox.startPoint[0], - y / inputSize5 * eyeBoxSize[1] + eyeBox.startPoint[1], - z - ]); - } - return { rawCoords: eyeRawCoords, iris: eyeRawCoords.slice(irisLandmarks.index) }; -}; -var getAdjustedIrisCoords = (rawCoords, irisCoords, direction) => { - const upperCenterZ = rawCoords[meshAnnotations[`${direction}EyeUpper0`][irisLandmarks.upperCenter]][2]; - const lowerCenterZ = rawCoords[meshAnnotations[`${direction}EyeLower0`][irisLandmarks.lowerCenter]][2]; - const averageZ = (upperCenterZ + lowerCenterZ) / 2; - return irisCoords.map((coord, i) => { - let z = averageZ; - if (i === 2) { - z = upperCenterZ; - } else if (i === 4) { - z = lowerCenterZ; - } - return [coord[0], coord[1], z]; - }); -}; -async function augmentIris(rawCoords, face4, meshSize) { - if (!(model6 == null ? void 0 : model6["executor"])) - return rawCoords; - const { box: leftEyeBox, boxSize: leftEyeBoxSize, crop: leftEyeCrop } = getEyeBox(rawCoords, face4, eyeLandmarks.leftBounds[0], eyeLandmarks.leftBounds[1], meshSize, true); - const { box: rightEyeBox, boxSize: rightEyeBoxSize, crop: rightEyeCrop } = getEyeBox(rawCoords, face4, eyeLandmarks.rightBounds[0], eyeLandmarks.rightBounds[1], meshSize, true); - const combined = tfjs_esm_exports.concat([leftEyeCrop, rightEyeCrop]); - tfjs_esm_exports.dispose(leftEyeCrop); - tfjs_esm_exports.dispose(rightEyeCrop); - const eyePredictions = model6.execute(combined); - tfjs_esm_exports.dispose(combined); - const eyePredictionsData = await eyePredictions.data(); - tfjs_esm_exports.dispose(eyePredictions); - const leftEyeData = eyePredictionsData.slice(0, irisLandmarks.numCoordinates * 3); - const { rawCoords: leftEyeRawCoords, iris: leftIrisRawCoords } = getEyeCoords(leftEyeData, leftEyeBox, leftEyeBoxSize, true); - const rightEyeData = eyePredictionsData.slice(irisLandmarks.numCoordinates * 3); - const { rawCoords: rightEyeRawCoords, iris: rightIrisRawCoords } = getEyeCoords(rightEyeData, rightEyeBox, rightEyeBoxSize, false); - const leftToRightEyeDepthDifference = getLeftToRightEyeDepthDifference(rawCoords); - if (Math.abs(leftToRightEyeDepthDifference) < 30) { - replaceIrisCoords(rawCoords, leftEyeRawCoords, "left", null); - replaceIrisCoords(rawCoords, rightEyeRawCoords, "right", null); - } else if (leftToRightEyeDepthDifference < 1) { - replaceIrisCoords(rawCoords, leftEyeRawCoords, "left", ["EyeUpper0", "EyeLower0"]); - } else { - replaceIrisCoords(rawCoords, rightEyeRawCoords, "right", ["EyeUpper0", "EyeLower0"]); - } - const adjustedLeftIrisCoords = getAdjustedIrisCoords(rawCoords, leftIrisRawCoords, "left"); - const adjustedRightIrisCoords = getAdjustedIrisCoords(rawCoords, rightIrisRawCoords, "right"); - const newCoords = rawCoords.concat(adjustedLeftIrisCoords).concat(adjustedRightIrisCoords); - return newCoords; -} - -// src/face/attention.ts -async function augment(rawCoords, results) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; - const t2 = { - lips: await ((_b = (_a = results.filter((r) => r.size === 160)) == null ? void 0 : _a[0]) == null ? void 0 : _b.data()), - irisL: await ((_d = (_c = results.filter((r) => r.size === 10)) == null ? void 0 : _c[0]) == null ? void 0 : _d.data()), - eyeL: await ((_f = (_e = results.filter((r) => r.size === 142)) == null ? void 0 : _e[0]) == null ? void 0 : _f.data()), - irisR: await ((_h = (_g = results.filter((r) => r.size === 10)) == null ? void 0 : _g[1]) == null ? void 0 : _h.data()), - eyeR: await ((_j = (_i = results.filter((r) => r.size === 142)) == null ? void 0 : _i[1]) == null ? void 0 : _j.data()) - }; - for (const val of Object.values(t2)) { - if (!val) - return rawCoords; - } - const irisLDepth = LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG.reduce((prev, curr) => prev += rawCoords[curr][2], 0) / LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG.length; - for (let i = 0; i < t2.irisL.length / 2; i++) - rawCoords.push([t2.irisL[2 * i + 0], t2.irisL[2 * i + 1], irisLDepth]); - const irisRDepth = LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG.reduce((prev, curr) => prev += rawCoords[curr][2], 0) / LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG.length; - for (let i = 0; i < t2.irisR.length / 2; i++) - rawCoords.push([t2.irisR[2 * i + 0], t2.irisR[2 * i + 1], irisRDepth]); - for (let i = 0; i < t2.eyeL.length / 2; i++) - rawCoords[LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG[i]] = [t2.eyeL[2 * i + 0], t2.eyeL[2 * i + 1], rawCoords[LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG[i]][2]]; - for (let i = 0; i < t2.eyeR.length / 2; i++) - rawCoords[LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG[i]] = [t2.eyeR[2 * i + 0], t2.eyeR[2 * i + 1], rawCoords[LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG[i]][2]]; - for (let i = 0; i < t2.lips.length / 2; i++) - rawCoords[LANDMARKS_REFINEMENT_LIPS_CONFIG[i]] = [t2.lips[2 * i + 0], t2.lips[2 * i + 1], rawCoords[LANDMARKS_REFINEMENT_LIPS_CONFIG[i]][2]]; - return rawCoords; -} - -// src/face/facemesh.ts -var cache3 = { - boxes: [], - skipped: Number.MAX_SAFE_INTEGER, - timestamp: 0 -}; -var model7 = null; -var inputSize6 = 0; -async function predict4(input, config3) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; - if (!(model7 == null ? void 0 : model7["executor"])) - return []; - const skipTime = (((_a = config3.face.detector) == null ? void 0 : _a.skipTime) || 0) > now() - cache3.timestamp; - const skipFrame = cache3.skipped < (((_b = config3.face.detector) == null ? void 0 : _b.skipFrames) || 0); - if (!config3.skipAllowed || !skipTime || !skipFrame || cache3.boxes.length === 0) { - cache3.boxes = await getBoxes(input, config3); - cache3.timestamp = now(); - cache3.skipped = 0; - } else { - cache3.skipped++; - } - const faces = []; - const newCache = []; - let id = 0; - const size2 = inputSize6; - for (let i = 0; i < cache3.boxes.length; i++) { - const box = cache3.boxes[i]; - let angle = 0; - let rotationMatrix; - const face4 = { - id: id++, - mesh: [], - meshRaw: [], - box: [0, 0, 0, 0], - boxRaw: [0, 0, 0, 0], - score: 0, - boxScore: 0, - faceScore: 0, - annotations: {} - }; - [angle, rotationMatrix, face4.tensor] = correctFaceRotation((_c = config3.face.detector) == null ? void 0 : _c.rotation, box, input, ((_d = config3.face.mesh) == null ? void 0 : _d.enabled) ? inputSize6 : size()); - if (config3.filter.equalization) { - const equilized = face4.tensor ? await histogramEqualization(face4.tensor) : void 0; - tfjs_esm_exports.dispose(face4.tensor); - if (equilized) - face4.tensor = equilized; - } - face4.boxScore = Math.round(100 * box.confidence) / 100; - if (!((_e = config3.face.mesh) == null ? void 0 : _e.enabled)) { - face4.box = clampBox(box, input); - face4.boxRaw = getRawBox(box, input); - face4.score = face4.boxScore; - face4.mesh = box.landmarks.map((pt) => [ - (box.startPoint[0] + box.endPoint[0]) / 2 + (box.endPoint[0] + box.startPoint[0]) * pt[0] / size(), - (box.startPoint[1] + box.endPoint[1]) / 2 + (box.endPoint[1] + box.startPoint[1]) * pt[1] / size() - ]); - face4.meshRaw = face4.mesh.map((pt) => [pt[0] / (input.shape[2] || 0), pt[1] / (input.shape[1] || 0), (pt[2] || 0) / size2]); - for (const key of Object.keys(blazeFaceLandmarks)) { - face4.annotations[key] = [face4.mesh[blazeFaceLandmarks[key]]]; - } - } else if (!model7) { - if (config3.debug) - log("face mesh detection requested, but model is not loaded"); - } else { - if (((_f = config3.face.attention) == null ? void 0 : _f.enabled) && !env.kernels.includes("atan2")) { - config3.face.attention.enabled = false; - tfjs_esm_exports.dispose(face4.tensor); - return faces; - } - const results = model7.execute(face4.tensor); - const confidenceT = results.find((t2) => t2.shape[t2.shape.length - 1] === 1); - const faceConfidence = await confidenceT.data(); - face4.faceScore = Math.round(100 * faceConfidence[0]) / 100; - if (face4.faceScore < (((_g = config3.face.detector) == null ? void 0 : _g.minConfidence) || 1)) { - box.confidence = face4.faceScore; - if (config3.face.mesh.keepInvalid) { - face4.box = clampBox(box, input); - face4.boxRaw = getRawBox(box, input); - face4.score = face4.boxScore; - face4.mesh = box.landmarks.map((pt) => [ - (box.startPoint[0] + box.endPoint[0]) / 2 + (box.endPoint[0] + box.startPoint[0]) * pt[0] / size(), - (box.startPoint[1] + box.endPoint[1]) / 2 + (box.endPoint[1] + box.startPoint[1]) * pt[1] / size() - ]); - face4.meshRaw = face4.mesh.map((pt) => [pt[0] / (input.shape[2] || 1), pt[1] / (input.shape[1] || 1), (pt[2] || 0) / size2]); - for (const key of Object.keys(blazeFaceLandmarks)) { - face4.annotations[key] = [face4.mesh[blazeFaceLandmarks[key]]]; - } - } - } else { - const meshT = results.find((t2) => t2.shape[t2.shape.length - 1] === 1404); - const coordsReshaped = tfjs_esm_exports.reshape(meshT, [-1, 3]); - let rawCoords = await coordsReshaped.array(); - tfjs_esm_exports.dispose(coordsReshaped); - if ((_h = config3.face.attention) == null ? void 0 : _h.enabled) { - rawCoords = await augment(rawCoords, results); - } else if ((_i = config3.face.iris) == null ? void 0 : _i.enabled) { - rawCoords = await augmentIris(rawCoords, face4.tensor, inputSize6); - } - face4.mesh = transformRawCoords(rawCoords, box, angle, rotationMatrix, inputSize6); - face4.meshRaw = face4.mesh.map((pt) => [pt[0] / (input.shape[2] || 0), pt[1] / (input.shape[1] || 0), (pt[2] || 0) / size2]); - for (const key of Object.keys(meshAnnotations)) - face4.annotations[key] = meshAnnotations[key].map((index2) => face4.mesh[index2]); - face4.score = face4.faceScore; - const calculatedBox = { ...calculateFaceBox(face4.mesh, box), confidence: box.confidence, landmarks: box.landmarks }; - face4.box = clampBox(calculatedBox, input); - face4.boxRaw = getRawBox(calculatedBox, input); - newCache.push(calculatedBox); - } - tfjs_esm_exports.dispose(results); - } - if (face4.score > (((_j = config3.face.detector) == null ? void 0 : _j.minConfidence) || 1)) - faces.push(face4); - else - tfjs_esm_exports.dispose(face4.tensor); - } - cache3.boxes = newCache; - return faces; -} -async function load5(config3) { - var _a, _b, _c, _d, _e, _f; - if (env.initial) - model7 = null; - if (((_a = config3.face.attention) == null ? void 0 : _a.enabled) && (model7 == null ? void 0 : model7["signature"])) { - if (Object.keys(((_b = model7 == null ? void 0 : model7["signature"]) == null ? void 0 : _b.outputs) || {}).length < 6) - model7 = null; - } - if (!model7) { - if ((_c = config3.face.attention) == null ? void 0 : _c.enabled) - model7 = await loadModel(config3.face.attention.modelPath); - else - model7 = await loadModel((_d = config3.face.mesh) == null ? void 0 : _d.modelPath); - } else if (config3.debug) { - log("cached model:", model7["modelUrl"]); - } - inputSize6 = model7["executor"] && ((_e = model7 == null ? void 0 : model7.inputs) == null ? void 0 : _e[0].shape) ? (_f = model7 == null ? void 0 : model7.inputs) == null ? void 0 : _f[0].shape[2] : 256; - return model7; -} -var triangulation = TRI468; -var uvmap = UV468; - -// src/gear/emotion.ts -var annotations = ["angry", "disgust", "fear", "happy", "sad", "surprise", "neutral"]; -var model8; -var last3 = []; -var lastCount = 0; -var lastTime4 = 0; -var skipped4 = Number.MAX_SAFE_INTEGER; -async function load6(config3) { - var _a; - if (env.initial) - model8 = null; - if (!model8) - model8 = await loadModel((_a = config3.face.emotion) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model8["modelUrl"]); - return model8; -} -async function predict5(image28, config3, idx, count2) { - var _a, _b; - if (!model8) - return []; - const skipFrame = skipped4 < (((_a = config3.face.emotion) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face.emotion) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime4; - if (config3.skipAllowed && skipTime && skipFrame && lastCount === count2 && last3[idx] && last3[idx].length > 0) { - skipped4++; - return last3[idx]; - } - skipped4 = 0; - return new Promise(async (resolve) => { - var _a2; - const obj = []; - if ((_a2 = config3.face.emotion) == null ? void 0 : _a2.enabled) { - const t2 = {}; - const inputSize10 = (model8 == null ? void 0 : model8.inputs[0].shape) ? model8.inputs[0].shape[2] : 0; - t2.resize = tfjs_esm_exports.image.resizeBilinear(image28, [inputSize10, inputSize10], false); - t2.channels = tfjs_esm_exports.mul(t2.resize, constants.rgb); - t2.grayscale = tfjs_esm_exports.sum(t2.channels, 3, true); - t2.grayscaleSub = tfjs_esm_exports.sub(t2.grayscale, constants.tf05); - t2.grayscaleMul = tfjs_esm_exports.mul(t2.grayscaleSub, constants.tf2); - t2.emotion = model8 == null ? void 0 : model8.execute(t2.grayscaleMul); - lastTime4 = now(); - const data = await t2.emotion.data(); - for (let i = 0; i < data.length; i++) { - if (data[i] > (config3.face.emotion.minConfidence || 0)) - obj.push({ score: Math.min(0.99, Math.trunc(100 * data[i]) / 100), emotion: annotations[i] }); - } - obj.sort((a, b) => b.score - a.score); - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - } - last3[idx] = obj; - lastCount = count2; - resolve(obj); - }); -} - -// src/face/faceres.ts -var model9; -var last4 = []; -var lastTime5 = 0; -var lastCount2 = 0; -var skipped5 = Number.MAX_SAFE_INTEGER; -async function load7(config3) { - var _a; - if (env.initial) - model9 = null; - if (!model9) - model9 = await loadModel((_a = config3.face.description) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model9["modelUrl"]); - return model9; -} -function enhance(input) { - const tensor6 = input.image || input.tensor || input; - if (!(model9 == null ? void 0 : model9.inputs[0].shape)) - return tensor6; - const crop = tfjs_esm_exports.image.resizeBilinear(tensor6, [model9.inputs[0].shape[2], model9.inputs[0].shape[1]], false); - const norm = tfjs_esm_exports.mul(crop, constants.tf255); - tfjs_esm_exports.dispose(crop); - return norm; -} -async function predict6(image28, config3, idx, count2) { - var _a, _b, _c, _d; - const obj = { - age: 0, - gender: "unknown", - genderScore: 0, - descriptor: [] - }; - if (!(model9 == null ? void 0 : model9["executor"])) - return obj; - const skipFrame = skipped5 < (((_a = config3.face.description) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face.description) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime5; - if (config3.skipAllowed && skipFrame && skipTime && lastCount2 === count2 && ((_c = last4 == null ? void 0 : last4[idx]) == null ? void 0 : _c.age) > 0 && ((_d = last4 == null ? void 0 : last4[idx]) == null ? void 0 : _d.genderScore) > 0) { - skipped5++; - return last4[idx]; - } - skipped5 = 0; - return new Promise(async (resolve) => { - var _a2; - if ((_a2 = config3.face.description) == null ? void 0 : _a2.enabled) { - const enhanced = enhance(image28); - const resT = model9 == null ? void 0 : model9.execute(enhanced); - lastTime5 = now(); - tfjs_esm_exports.dispose(enhanced); - const genderT = resT.find((t2) => t2.shape[1] === 1); - const gender2 = await genderT.data(); - const confidence = Math.trunc(200 * Math.abs(gender2[0] - 0.5)) / 100; - if (confidence > (config3.face.description.minConfidence || 0)) { - obj.gender = gender2[0] <= 0.5 ? "female" : "male"; - obj.genderScore = Math.min(0.99, confidence); - } - const argmax = tfjs_esm_exports.argMax(resT.find((t2) => t2.shape[1] === 100), 1); - const ageIdx = (await argmax.data())[0]; - tfjs_esm_exports.dispose(argmax); - const ageT = resT.find((t2) => t2.shape[1] === 100); - const all2 = await ageT.data(); - obj.age = Math.round(all2[ageIdx - 1] > all2[ageIdx + 1] ? 10 * ageIdx - 100 * all2[ageIdx - 1] : 10 * ageIdx + 100 * all2[ageIdx + 1]) / 10; - if (Number.isNaN(gender2[0]) || Number.isNaN(all2[0])) - log("faceres error:", { model: model9, result: resT }); - const desc = resT.find((t2) => t2.shape[1] === 1024); - const descriptor = desc ? await desc.data() : []; - obj.descriptor = Array.from(descriptor); - resT.forEach((t2) => tfjs_esm_exports.dispose(t2)); - } - last4[idx] = obj; - lastCount2 = count2; - resolve(obj); - }); -} - -// src/face/mask.ts -var expandFact = 0.1; -var alpha = 0.5; -function insidePoly(x, y, polygon) { - let inside = false; - let j = polygon.length - 1; - for (let i = 0; i < polygon.length; j = i++) { - if (polygon[i].y > y !== polygon[j].y > y && x < (polygon[j].x - polygon[i].x) * (y - polygon[i].y) / (polygon[j].y - polygon[i].y) + polygon[i].x) - inside = !inside; - } - return inside; -} -async function mask(face4) { - if (!face4.tensor) - return face4.tensor; - if (!face4.mesh || face4.mesh.length < 100) - return face4.tensor; - const width = face4.tensor.shape[2] || 0; - const height = face4.tensor.shape[1] || 0; - const buffer = await face4.tensor.buffer(); - let silhouette = []; - for (const pt of meshAnnotations.silhouette) - silhouette.push({ x: (face4.mesh[pt][0] - face4.box[0]) / face4.box[2], y: (face4.mesh[pt][1] - face4.box[1]) / face4.box[3] }); - if (expandFact && expandFact > 0) - silhouette = silhouette.map((pt) => ({ x: pt.x > 0.5 ? pt.x + expandFact : pt.x - expandFact, y: pt.y > 0.5 ? pt.y + expandFact : pt.y - expandFact })); - for (let x = 0; x < width; x++) { - for (let y = 0; y < height; y++) { - const inside = insidePoly(x / width, y / width, silhouette); - if (!inside) { - buffer.set(alpha * buffer.get(0, y, x, 0), 0, y, x, 0); - buffer.set(alpha * buffer.get(0, y, x, 1), 0, y, x, 1); - buffer.set(alpha * buffer.get(0, y, x, 2), 0, y, x, 2); - } - } - } - const output = buffer.toTensor(); - return output; -} - -// src/face/antispoof.ts -var model10; -var cached = []; -var skipped6 = Number.MAX_SAFE_INTEGER; -var lastCount3 = 0; -var lastTime6 = 0; -async function load8(config3) { - var _a; - if (env.initial) - model10 = null; - if (!model10) - model10 = await loadModel((_a = config3.face.antispoof) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model10["modelUrl"]); - return model10; -} -async function predict7(image28, config3, idx, count2) { - var _a, _b; - if (!(model10 == null ? void 0 : model10["executor"])) - return 0; - const skipTime = (((_a = config3.face.antispoof) == null ? void 0 : _a.skipTime) || 0) > now() - lastTime6; - const skipFrame = skipped6 < (((_b = config3.face.antispoof) == null ? void 0 : _b.skipFrames) || 0); - if (config3.skipAllowed && skipTime && skipFrame && lastCount3 === count2 && cached[idx]) { - skipped6++; - return cached[idx]; - } - skipped6 = 0; - return new Promise(async (resolve) => { - const resize = tfjs_esm_exports.image.resizeBilinear(image28, [(model10 == null ? void 0 : model10.inputs[0].shape) ? model10.inputs[0].shape[2] : 0, (model10 == null ? void 0 : model10.inputs[0].shape) ? model10.inputs[0].shape[1] : 0], false); - const res = model10 == null ? void 0 : model10.execute(resize); - const num = (await res.data())[0]; - cached[idx] = Math.round(100 * num) / 100; - lastCount3 = count2; - lastTime6 = now(); - tfjs_esm_exports.dispose([resize, res]); - resolve(cached[idx]); - }); -} - -// src/face/liveness.ts -var model11; -var cached2 = []; -var skipped7 = Number.MAX_SAFE_INTEGER; -var lastCount4 = 0; -var lastTime7 = 0; -async function load9(config3) { - var _a; - if (env.initial) - model11 = null; - if (!model11) - model11 = await loadModel((_a = config3.face.liveness) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model11["modelUrl"]); - return model11; -} -async function predict8(image28, config3, idx, count2) { - var _a, _b; - if (!(model11 == null ? void 0 : model11["executor"])) - return 0; - const skipTime = (((_a = config3.face.liveness) == null ? void 0 : _a.skipTime) || 0) > now() - lastTime7; - const skipFrame = skipped7 < (((_b = config3.face.liveness) == null ? void 0 : _b.skipFrames) || 0); - if (config3.skipAllowed && skipTime && skipFrame && lastCount4 === count2 && cached2[idx]) { - skipped7++; - return cached2[idx]; - } - skipped7 = 0; - return new Promise(async (resolve) => { - const resize = tfjs_esm_exports.image.resizeBilinear(image28, [(model11 == null ? void 0 : model11.inputs[0].shape) ? model11.inputs[0].shape[2] : 0, (model11 == null ? void 0 : model11.inputs[0].shape) ? model11.inputs[0].shape[1] : 0], false); - const res = model11 == null ? void 0 : model11.execute(resize); - const num = (await res.data())[0]; - cached2[idx] = Math.round(100 * num) / 100; - lastCount4 = count2; - lastTime7 = now(); - tfjs_esm_exports.dispose([resize, res]); - resolve(cached2[idx]); - }); -} - -// src/gear/gear.ts -var model12; -var last5 = []; -var raceNames = ["white", "black", "asian", "indian", "other"]; -var ageWeights = [15, 23, 28, 35.5, 45.5, 55.5, 65]; -var lastCount5 = 0; -var lastTime8 = 0; -var skipped8 = Number.MAX_SAFE_INTEGER; -async function load10(config3) { - var _a; - if (env.initial) - model12 = null; - if (!model12) - model12 = await loadModel((_a = config3.face.gear) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model12["modelUrl"]); - return model12; -} -async function predict9(image28, config3, idx, count2) { - var _a, _b; - if (!model12) - return { age: 0, gender: "unknown", genderScore: 0, race: [] }; - const skipFrame = skipped8 < (((_a = config3.face.gear) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face.gear) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime8; - if (config3.skipAllowed && skipTime && skipFrame && lastCount5 === count2 && last5[idx]) { - skipped8++; - return last5[idx]; - } - skipped8 = 0; - return new Promise(async (resolve) => { - var _a2, _b2; - if (!(model12 == null ? void 0 : model12.inputs[0].shape)) - return; - const t2 = {}; - const box = [[0, 0.1, 0.9, 0.9]]; - t2.resize = tfjs_esm_exports.image.cropAndResize(image28, box, [0], [model12.inputs[0].shape[2], model12.inputs[0].shape[1]]); - const obj = { age: 0, gender: "unknown", genderScore: 0, race: [] }; - if ((_a2 = config3.face.gear) == null ? void 0 : _a2.enabled) - [t2.age, t2.gender, t2.race] = model12.execute(t2.resize, ["age_output", "gender_output", "race_output"]); - const gender2 = await t2.gender.data(); - obj.gender = gender2[0] > gender2[1] ? "male" : "female"; - obj.genderScore = Math.round(100 * (gender2[0] > gender2[1] ? gender2[0] : gender2[1])) / 100; - const race = await t2.race.data(); - for (let i = 0; i < race.length; i++) { - if (race[i] > (((_b2 = config3.face.gear) == null ? void 0 : _b2.minConfidence) || 0.2)) - obj.race.push({ score: Math.round(100 * race[i]) / 100, race: raceNames[i] }); - } - obj.race.sort((a, b) => b.score - a.score); - const ageDistribution = Array.from(await t2.age.data()); - const ageSorted = ageDistribution.map((a, i) => [ageWeights[i], a]).sort((a, b) => b[1] - a[1]); - let age2 = ageSorted[0][0]; - for (let i = 1; i < ageSorted.length; i++) - age2 += ageSorted[i][1] * (ageSorted[i][0] - age2); - obj.age = Math.round(10 * age2) / 10; - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - last5[idx] = obj; - lastCount5 = count2; - lastTime8 = now(); - resolve(obj); - }); -} - -// src/gear/ssrnet-age.ts -var model13; -var last6 = []; -var lastCount6 = 0; -var lastTime9 = 0; -var skipped9 = Number.MAX_SAFE_INTEGER; -async function load11(config3) { - if (env.initial) - model13 = null; - if (!model13) - model13 = await loadModel(config3.face["ssrnet"].modelPathAge); - else if (config3.debug) - log("cached model:", model13["modelUrl"]); - return model13; -} -async function predict10(image28, config3, idx, count2) { - var _a, _b, _c, _d; - if (!model13) - return { age: 0 }; - const skipFrame = skipped9 < (((_a = config3.face["ssrnet"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["ssrnet"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime9; - if (config3.skipAllowed && skipFrame && skipTime && lastCount6 === count2 && ((_c = last6[idx]) == null ? void 0 : _c.age) && ((_d = last6[idx]) == null ? void 0 : _d.age) > 0) { - skipped9++; - return last6[idx]; - } - skipped9 = 0; - return new Promise(async (resolve) => { - var _a2; - if (!(model13 == null ? void 0 : model13.inputs) || !model13.inputs[0] || !model13.inputs[0].shape) - return; - const t2 = {}; - t2.resize = tfjs_esm_exports.image.resizeBilinear(image28, [model13.inputs[0].shape[2], model13.inputs[0].shape[1]], false); - t2.enhance = tfjs_esm_exports.mul(t2.resize, constants.tf255); - const obj = { age: 0 }; - if ((_a2 = config3.face["ssrnet"]) == null ? void 0 : _a2.enabled) - t2.age = model13.execute(t2.enhance); - if (t2.age) { - const data = await t2.age.data(); - obj.age = Math.trunc(10 * data[0]) / 10; - } - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - last6[idx] = obj; - lastCount6 = count2; - lastTime9 = now(); - resolve(obj); - }); -} - -// src/gear/ssrnet-gender.ts -var model14; -var last7 = []; -var lastCount7 = 0; -var lastTime10 = 0; -var skipped10 = Number.MAX_SAFE_INTEGER; -var rgb = [0.2989, 0.587, 0.114]; -async function load12(config3) { - var _a; - if (env.initial) - model14 = null; - if (!model14) - model14 = await loadModel((_a = config3.face["ssrnet"]) == null ? void 0 : _a.modelPathGender); - else if (config3.debug) - log("cached model:", model14["modelUrl"]); - return model14; -} -async function predict11(image28, config3, idx, count2) { - var _a, _b, _c, _d; - if (!model14) - return { gender: "unknown", genderScore: 0 }; - const skipFrame = skipped10 < (((_a = config3.face["ssrnet"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["ssrnet"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime10; - if (config3.skipAllowed && skipFrame && skipTime && lastCount7 === count2 && ((_c = last7[idx]) == null ? void 0 : _c.gender) && ((_d = last7[idx]) == null ? void 0 : _d.genderScore) > 0) { - skipped10++; - return last7[idx]; - } - skipped10 = 0; - return new Promise(async (resolve) => { - var _a2; - if (!(model14 == null ? void 0 : model14.inputs[0].shape)) - return; - const t2 = {}; - t2.resize = tfjs_esm_exports.image.resizeBilinear(image28, [model14.inputs[0].shape[2], model14.inputs[0].shape[1]], false); - t2.enhance = tfjs_esm_exports.tidy(() => { - const [red, green, blue] = tfjs_esm_exports.split(t2.resize, 3, 3); - const redNorm = tfjs_esm_exports.mul(red, rgb[0]); - const greenNorm = tfjs_esm_exports.mul(green, rgb[1]); - const blueNorm = tfjs_esm_exports.mul(blue, rgb[2]); - const grayscale = tfjs_esm_exports.addN([redNorm, greenNorm, blueNorm]); - const normalize2 = tfjs_esm_exports.mul(tfjs_esm_exports.sub(grayscale, constants.tf05), 2); - return normalize2; - }); - const obj = { gender: "unknown", genderScore: 0 }; - if ((_a2 = config3.face["ssrnet"]) == null ? void 0 : _a2.enabled) - t2.gender = model14.execute(t2.enhance); - const data = await t2.gender.data(); - obj.gender = data[0] > data[1] ? "female" : "male"; - obj.genderScore = data[0] > data[1] ? Math.trunc(100 * data[0]) / 100 : Math.trunc(100 * data[1]) / 100; - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - last7[idx] = obj; - lastCount7 = count2; - lastTime10 = now(); - resolve(obj); - }); -} - -// src/face/mobilefacenet.ts -var model15; -var last8 = []; -var lastCount8 = 0; -var lastTime11 = 0; -var skipped11 = Number.MAX_SAFE_INTEGER; -async function load13(config3) { - var _a; - if (env.initial) - model15 = null; - if (!model15) - model15 = await loadModel((_a = config3.face["mobilefacenet"]) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model15["modelUrl"]); - return model15; -} -async function predict12(input, config3, idx, count2) { - var _a, _b; - if (!(model15 == null ? void 0 : model15["executor"])) - return []; - const skipFrame = skipped11 < (((_a = config3.face["mobilefacenet"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["mobilefacenet"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime11; - if (config3.skipAllowed && skipTime && skipFrame && lastCount8 === count2 && last8[idx]) { - skipped11++; - return last8[idx]; - } - return new Promise(async (resolve) => { - var _a2; - let data = []; - if (((_a2 = config3.face["mobilefacenet"]) == null ? void 0 : _a2.enabled) && (model15 == null ? void 0 : model15.inputs[0].shape)) { - const t2 = {}; - t2.crop = tfjs_esm_exports.image.resizeBilinear(input, [model15.inputs[0].shape[2], model15.inputs[0].shape[1]], false); - t2.data = model15.execute(t2.crop); - const output = await t2.data.data(); - data = Array.from(output); - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - } - last8[idx] = data; - lastCount8 = count2; - lastTime11 = now(); - resolve(data); - }); -} - -// src/face/insightface.ts -var model16; -var last9 = []; -var lastCount9 = 0; -var lastTime12 = 0; -var skipped12 = Number.MAX_SAFE_INTEGER; -async function load14(config3) { - if (env.initial) - model16 = null; - if (!model16) - model16 = await loadModel(config3.face["insightface"].modelPath); - else if (config3.debug) - log("cached model:", model16["modelUrl"]); - return model16; -} -async function predict13(input, config3, idx, count2) { - var _a, _b; - if (!(model16 == null ? void 0 : model16["executor"])) - return []; - const skipFrame = skipped12 < (((_a = config3.face["insightface"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["insightface"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime12; - if (config3.skipAllowed && skipTime && skipFrame && lastCount9 === count2 && last9[idx]) { - skipped12++; - return last9[idx]; - } - return new Promise(async (resolve) => { - var _a2; - let data = []; - if (((_a2 = config3.face["insightface"]) == null ? void 0 : _a2.enabled) && (model16 == null ? void 0 : model16.inputs[0].shape)) { - const t2 = {}; - t2.crop = tfjs_esm_exports.image.resizeBilinear(input, [model16.inputs[0].shape[2], model16.inputs[0].shape[1]], false); - t2.data = model16.execute(t2.crop); - const output = await t2.data.data(); - data = Array.from(output); - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - } - last9[idx] = data; - lastCount9 = count2; - lastTime12 = now(); - resolve(data); - }); -} - -// src/face/angles.ts -var calculateGaze = (face4) => { - const radians = (pt1, pt2) => Math.atan2(pt1[1] - pt2[1], pt1[0] - pt2[0]); - if (!face4.annotations.rightEyeIris || !face4.annotations.leftEyeIris) - return { bearing: 0, strength: 0 }; - const offsetIris = [0, -0.1]; - const eyeRatio = 1; - const left = (face4.mesh[33][2] || 0) > (face4.mesh[263][2] || 0); - const irisCenter = left ? face4.mesh[473] : face4.mesh[468]; - const eyeCenter = left ? [(face4.mesh[133][0] + face4.mesh[33][0]) / 2, (face4.mesh[133][1] + face4.mesh[33][1]) / 2] : [(face4.mesh[263][0] + face4.mesh[362][0]) / 2, (face4.mesh[263][1] + face4.mesh[362][1]) / 2]; - const eyeSize = left ? [face4.mesh[133][0] - face4.mesh[33][0], face4.mesh[23][1] - face4.mesh[27][1]] : [face4.mesh[263][0] - face4.mesh[362][0], face4.mesh[253][1] - face4.mesh[257][1]]; - const eyeDiff = [ - (eyeCenter[0] - irisCenter[0]) / eyeSize[0] - offsetIris[0], - eyeRatio * (irisCenter[1] - eyeCenter[1]) / eyeSize[1] - offsetIris[1] - ]; - let strength = Math.sqrt(eyeDiff[0] * eyeDiff[0] + eyeDiff[1] * eyeDiff[1]); - strength = Math.min(strength, face4.boxRaw[2] / 2, face4.boxRaw[3] / 2); - const bearing = (radians([0, 0], eyeDiff) + Math.PI / 2) % Math.PI; - return { bearing, strength }; -}; -var calculateFaceAngle = (face4, imageSize) => { - const normalize2 = (v) => { - const length = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); - v[0] /= length; - v[1] /= length; - v[2] /= length; - return v; - }; - const subVectors = (a, b) => { - const x = a[0] - b[0]; - const y = a[1] - b[1]; - const z = a[2] - b[2]; - return [x, y, z]; - }; - const crossVectors = (a, b) => { - const x = a[1] * b[2] - a[2] * b[1]; - const y = a[2] * b[0] - a[0] * b[2]; - const z = a[0] * b[1] - a[1] * b[0]; - return [x, y, z]; - }; - const rotationMatrixToEulerAngle = (r) => { - const [r00, _r01, _r02, r10, r11, r12, r20, r21, r22] = r; - let thetaX; - let thetaY; - let thetaZ; - if (r10 < 1) { - if (r10 > -1) { - thetaZ = Math.asin(r10); - thetaY = Math.atan2(-r20, r00); - thetaX = Math.atan2(-r12, r11); - } else { - thetaZ = -Math.PI / 2; - thetaY = -Math.atan2(r21, r22); - thetaX = 0; - } - } else { - thetaZ = Math.PI / 2; - thetaY = Math.atan2(r21, r22); - thetaX = 0; - } - if (Number.isNaN(thetaX)) - thetaX = 0; - if (Number.isNaN(thetaY)) - thetaY = 0; - if (Number.isNaN(thetaZ)) - thetaZ = 0; - return { pitch: 2 * -thetaX, yaw: 2 * -thetaY, roll: 2 * -thetaZ }; - }; - const mesh = face4.meshRaw; - if (!mesh || mesh.length < 300) - return { angle: { pitch: 0, yaw: 0, roll: 0 }, matrix: [1, 0, 0, 0, 1, 0, 0, 0, 1], gaze: { bearing: 0, strength: 0 } }; - const size2 = Math.max(face4.boxRaw[2] * imageSize[0], face4.boxRaw[3] * imageSize[1]) / 1.5; - const pts = [mesh[10], mesh[152], mesh[234], mesh[454]].map((pt) => [pt[0] * imageSize[0] / size2, pt[1] * imageSize[1] / size2, pt[2]]); - const yAxis = normalize2(subVectors(pts[1], pts[0])); - let xAxis = normalize2(subVectors(pts[3], pts[2])); - const zAxis = normalize2(crossVectors(xAxis, yAxis)); - xAxis = crossVectors(yAxis, zAxis); - const matrix = [ - xAxis[0], - xAxis[1], - xAxis[2], - yAxis[0], - yAxis[1], - yAxis[2], - zAxis[0], - zAxis[1], - zAxis[2] - ]; - const angle = rotationMatrixToEulerAngle(matrix); - const gaze = mesh.length === 478 ? calculateGaze(face4) : { bearing: 0, strength: 0 }; - return { angle, matrix, gaze }; -}; - -// src/face/anthropometry.ts -function calculateCameraDistance(face4, width) { - const f = face4 == null ? void 0 : face4.annotations; - if (!f) - return 0; - const irisSize = Math.max(Math.abs(f.leftEyeIris[3][0] - f.leftEyeIris[1][0]), Math.abs(f.rightEyeIris[3][0] - f.rightEyeIris[1][0])) / width; - const cameraDistance = Math.round(1.17 / irisSize) / 100; - return cameraDistance; -} - -// src/face/face.ts -var detectFace = async (instance, input) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w; - let timeStamp = now(); - let ageRes; - let gearRes; - let genderRes; - let emotionRes; - let mobilefacenetRes; - let insightfaceRes; - let antispoofRes; - let livenessRes; - let descRes; - const faceRes = []; - instance.state = "run:face"; - const faces = await predict4(input, instance.config); - instance.performance.face = env.perfadd ? (instance.performance.face || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - if (!input.shape || input.shape.length !== 4) - return []; - if (!faces) - return []; - for (let i = 0; i < faces.length; i++) { - instance.analyze("Get Face"); - if (!faces[i].tensor || faces[i].tensor.isDisposedInternal) { - log("Face object is disposed:", faces[i].tensor); - continue; - } - if ((_a = instance.config.face.detector) == null ? void 0 : _a.mask) { - const masked = await mask(faces[i]); - tfjs_esm_exports.dispose(faces[i].tensor); - if (masked) - faces[i].tensor = masked; - } - const rotation = faces[i].mesh && faces[i].mesh.length > 200 ? calculateFaceAngle(faces[i], [input.shape[2], input.shape[1]]) : null; - instance.analyze("Start Emotion:"); - if (instance.config.async) { - emotionRes = ((_b = instance.config.face.emotion) == null ? void 0 : _b.enabled) ? predict5(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : []; - } else { - instance.state = "run:emotion"; - timeStamp = now(); - emotionRes = ((_c = instance.config.face.emotion) == null ? void 0 : _c.enabled) ? await predict5(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : []; - instance.performance.emotion = env.perfadd ? (instance.performance.emotion || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End Emotion:"); - instance.analyze("Start AntiSpoof:"); - if (instance.config.async) { - antispoofRes = ((_d = instance.config.face.antispoof) == null ? void 0 : _d.enabled) ? predict7(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : 0; - } else { - instance.state = "run:antispoof"; - timeStamp = now(); - antispoofRes = ((_e = instance.config.face.antispoof) == null ? void 0 : _e.enabled) ? await predict7(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : 0; - instance.performance.antispoof = env.perfadd ? (instance.performance.antispoof || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End AntiSpoof:"); - instance.analyze("Start Liveness:"); - if (instance.config.async) { - livenessRes = ((_f = instance.config.face.liveness) == null ? void 0 : _f.enabled) ? predict8(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : 0; - } else { - instance.state = "run:liveness"; - timeStamp = now(); - livenessRes = ((_g = instance.config.face.liveness) == null ? void 0 : _g.enabled) ? await predict8(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : 0; - instance.performance.liveness = env.perfadd ? (instance.performance.antispoof || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End Liveness:"); - instance.analyze("Start GEAR:"); - if (instance.config.async) { - gearRes = ((_h = instance.config.face.gear) == null ? void 0 : _h.enabled) ? predict9(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:gear"; - timeStamp = now(); - gearRes = ((_i = instance.config.face.gear) == null ? void 0 : _i.enabled) ? await predict9(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : null; - instance.performance.gear = Math.trunc(now() - timeStamp); - } - instance.analyze("End GEAR:"); - instance.analyze("Start SSRNet:"); - if (instance.config.async) { - ageRes = ((_j = instance.config.face["ssrnet"]) == null ? void 0 : _j.enabled) ? predict10(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : null; - genderRes = ((_k = instance.config.face["ssrnet"]) == null ? void 0 : _k.enabled) ? predict11(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:ssrnet"; - timeStamp = now(); - ageRes = ((_l = instance.config.face["ssrnet"]) == null ? void 0 : _l.enabled) ? await predict10(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : null; - genderRes = ((_m = instance.config.face["ssrnet"]) == null ? void 0 : _m.enabled) ? await predict11(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : null; - instance.performance.ssrnet = Math.trunc(now() - timeStamp); - } - instance.analyze("End SSRNet:"); - instance.analyze("Start MobileFaceNet:"); - if (instance.config.async) { - mobilefacenetRes = ((_n = instance.config.face["mobilefacenet"]) == null ? void 0 : _n.enabled) ? predict12(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:mobilefacenet"; - timeStamp = now(); - mobilefacenetRes = ((_o = instance.config.face["mobilefacenet"]) == null ? void 0 : _o.enabled) ? await predict12(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : null; - instance.performance.mobilefacenet = Math.trunc(now() - timeStamp); - } - instance.analyze("End MobileFaceNet:"); - instance.analyze("Start InsightFace:"); - if (instance.config.async) { - insightfaceRes = ((_p = instance.config.face["insightface"]) == null ? void 0 : _p.enabled) ? predict13(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:mobilefacenet"; - timeStamp = now(); - insightfaceRes = ((_q = instance.config.face["insightface"]) == null ? void 0 : _q.enabled) ? await predict13(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length) : null; - instance.performance.mobilefacenet = Math.trunc(now() - timeStamp); - } - instance.analyze("End InsightFace:"); - instance.analyze("Start Description:"); - if (instance.config.async) { - descRes = predict6(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length); - } else { - instance.state = "run:description"; - timeStamp = now(); - descRes = await predict6(faces[i].tensor || tfjs_esm_exports.tensor([]), instance.config, i, faces.length); - instance.performance.description = env.perfadd ? (instance.performance.description || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End Description:"); - if (instance.config.async) { - [ageRes, genderRes, emotionRes, mobilefacenetRes, insightfaceRes, descRes, gearRes, antispoofRes, livenessRes] = await Promise.all([ageRes, genderRes, emotionRes, mobilefacenetRes, insightfaceRes, descRes, gearRes, antispoofRes, livenessRes]); - } - instance.analyze("Finish Face:"); - if (((_r = instance.config.face["ssrnet"]) == null ? void 0 : _r.enabled) && ageRes && genderRes) { - descRes = { - ...descRes, - age: ageRes.age, - gender: genderRes.gender, - genderScore: genderRes.genderScore - }; - } - if (((_s = instance.config.face.gear) == null ? void 0 : _s.enabled) && gearRes) { - descRes = { - ...descRes, - age: gearRes.age, - gender: gearRes.gender, - genderScore: gearRes.genderScore, - race: gearRes.race - }; - } - if (((_t = instance.config.face["mobilefacenet"]) == null ? void 0 : _t.enabled) && mobilefacenetRes) { - descRes.descriptor = mobilefacenetRes; - } - if (((_u = instance.config.face["insightface"]) == null ? void 0 : _u.enabled) && insightfaceRes) { - descRes.descriptor = insightfaceRes; - } - const irisSize = ((_v = instance.config.face.iris) == null ? void 0 : _v.enabled) ? calculateCameraDistance(faces[i], input.shape[2]) : 0; - const tensor6 = ((_w = instance.config.face.detector) == null ? void 0 : _w.return) ? tfjs_esm_exports.squeeze(faces[i].tensor) : null; - tfjs_esm_exports.dispose(faces[i].tensor); - if (faces[i].tensor) - delete faces[i].tensor; - const res = { - ...faces[i], - id: i - }; - if (descRes.age) - res.age = descRes.age; - if (descRes.gender) - res.gender = descRes.gender; - if (descRes.genderScore) - res.genderScore = descRes.genderScore; - if (descRes.descriptor) - res.embedding = descRes.descriptor; - if (descRes.race) - res.race = descRes.race; - if (emotionRes) - res.emotion = emotionRes; - if (antispoofRes) - res.real = antispoofRes; - if (livenessRes) - res.live = livenessRes; - if (irisSize > 0) - res.distance = irisSize; - if (rotation) - res.rotation = rotation; - if (tensor6) - res.tensor = tensor6; - faceRes.push(res); - instance.analyze("End Face"); - } - instance.analyze("End FaceMesh:"); - if (instance.config.async) { - if (instance.performance.face) - delete instance.performance.face; - if (instance.performance.age) - delete instance.performance.age; - if (instance.performance.gender) - delete instance.performance.gender; - if (instance.performance.emotion) - delete instance.performance.emotion; - } - return faceRes; -}; - -// src/hand/fingerdef.ts -var Finger = { - thumb: 0, - index: 1, - middle: 2, - ring: 3, - pinky: 4, - all: [0, 1, 2, 3, 4], - nameMapping: { 0: "thumb", 1: "index", 2: "middle", 3: "ring", 4: "pinky" }, - pointsMapping: { - 0: [[0, 1], [1, 2], [2, 3], [3, 4]], - 1: [[0, 5], [5, 6], [6, 7], [7, 8]], - 2: [[0, 9], [9, 10], [10, 11], [11, 12]], - 3: [[0, 13], [13, 14], [14, 15], [15, 16]], - 4: [[0, 17], [17, 18], [18, 19], [19, 20]] - }, - getName: (value) => Finger.nameMapping[value], - getPoints: (value) => Finger.pointsMapping[value] -}; -var FingerCurl = { - none: 0, - half: 1, - full: 2, - nameMapping: { 0: "none", 1: "half", 2: "full" }, - getName: (value) => FingerCurl.nameMapping[value] -}; -var FingerDirection = { - verticalUp: 0, - verticalDown: 1, - horizontalLeft: 2, - horizontalRight: 3, - diagonalUpRight: 4, - diagonalUpLeft: 5, - diagonalDownRight: 6, - diagonalDownLeft: 7, - nameMapping: { 0: "verticalUp", 1: "verticalDown", 2: "horizontalLeft", 3: "horizontalRight", 4: "diagonalUpRight", 5: "diagonalUpLeft", 6: "diagonalDownRight", 7: "diagonalDownLeft" }, - getName: (value) => FingerDirection.nameMapping[value] -}; -var FingerGesture = class { - constructor(name) { - __publicField(this, "name"); - __publicField(this, "curls"); - __publicField(this, "directions"); - __publicField(this, "weights"); - __publicField(this, "weightsRelative"); - this.name = name; - this.curls = {}; - this.directions = {}; - this.weights = [1, 1, 1, 1, 1]; - this.weightsRelative = [1, 1, 1, 1, 1]; - } - curl(finger, curl, confidence) { - if (typeof this.curls[finger] === "undefined") - this.curls[finger] = []; - this.curls[finger].push([curl, confidence]); - } - direction(finger, position, confidence) { - if (!this.directions[finger]) - this.directions[finger] = []; - this.directions[finger].push([position, confidence]); - } - weight(finger, weight) { - this.weights[finger] = weight; - const total = this.weights.reduce((a, b) => a + b, 0); - this.weightsRelative = this.weights.map((el) => el * 5 / total); - } - matchAgainst(detectedCurls, detectedDirections) { - let confidence = 0; - for (const fingerIdx in detectedCurls) { - const detectedCurl = detectedCurls[fingerIdx]; - const expectedCurls = this.curls[fingerIdx]; - if (typeof expectedCurls === "undefined") { - confidence += this.weightsRelative[fingerIdx]; - continue; - } - for (const [expectedCurl, score] of expectedCurls) { - if (detectedCurl === expectedCurl) { - confidence += score * this.weightsRelative[fingerIdx]; - break; - } - } - } - for (const fingerIdx in detectedDirections) { - const detectedDirection = detectedDirections[fingerIdx]; - const expectedDirections = this.directions[fingerIdx]; - if (typeof expectedDirections === "undefined") { - confidence += this.weightsRelative[fingerIdx]; - continue; - } - for (const [expectedDirection, score] of expectedDirections) { - if (detectedDirection === expectedDirection) { - confidence += score * this.weightsRelative[fingerIdx]; - break; - } - } - } - return confidence / 10; - } -}; - -// src/hand/fingergesture.ts -var { thumb, index, middle, ring, pinky } = Finger; -var { none, half, full } = FingerCurl; -var { verticalUp, verticalDown, horizontalLeft, horizontalRight, diagonalUpRight, diagonalUpLeft, diagonalDownRight, diagonalDownLeft } = FingerDirection; -var ThumbsUp = new FingerGesture("thumbs up"); -ThumbsUp.curl(thumb, none, 1); -ThumbsUp.direction(thumb, verticalUp, 1); -ThumbsUp.direction(thumb, diagonalUpLeft, 0.25); -ThumbsUp.direction(thumb, diagonalUpRight, 0.25); -for (const finger of [Finger.index, Finger.middle, Finger.ring, Finger.pinky]) { - ThumbsUp.curl(finger, full, 1); - ThumbsUp.direction(finger, horizontalLeft, 1); - ThumbsUp.direction(finger, horizontalRight, 1); -} -var Victory = new FingerGesture("victory"); -Victory.curl(thumb, half, 0.5); -Victory.curl(thumb, none, 0.5); -Victory.direction(thumb, verticalUp, 1); -Victory.direction(thumb, diagonalUpLeft, 1); -Victory.curl(index, none, 1); -Victory.direction(index, verticalUp, 0.75); -Victory.direction(index, diagonalUpLeft, 1); -Victory.curl(middle, none, 1); -Victory.direction(middle, verticalUp, 1); -Victory.direction(middle, diagonalUpLeft, 0.75); -Victory.curl(ring, full, 1); -Victory.direction(ring, verticalUp, 0.2); -Victory.direction(ring, diagonalUpLeft, 1); -Victory.direction(ring, horizontalLeft, 0.2); -Victory.curl(pinky, full, 1); -Victory.direction(pinky, verticalUp, 0.2); -Victory.direction(pinky, diagonalUpLeft, 1); -Victory.direction(pinky, horizontalLeft, 0.2); -Victory.weight(index, 2); -Victory.weight(middle, 2); -var Point = new FingerGesture("point"); -Point.curl(thumb, full, 1); -Point.curl(index, none, 0.5); -Point.curl(middle, full, 0.5); -Point.curl(ring, full, 0.5); -Point.curl(pinky, full, 0.5); -Point.weight(index, 2); -Point.weight(middle, 2); -var MiddleFinger = new FingerGesture("middle finger"); -MiddleFinger.curl(thumb, none, 1); -MiddleFinger.curl(index, full, 0.5); -MiddleFinger.curl(middle, full, 0.5); -MiddleFinger.curl(ring, full, 0.5); -MiddleFinger.curl(pinky, full, 0.5); -MiddleFinger.weight(index, 2); -MiddleFinger.weight(middle, 2); -var OpenPalm = new FingerGesture("open palm"); -OpenPalm.curl(thumb, none, 0.75); -OpenPalm.curl(index, none, 0.75); -OpenPalm.curl(middle, none, 0.75); -OpenPalm.curl(ring, none, 0.75); -OpenPalm.curl(pinky, none, 0.75); -var fingergesture_default = [ThumbsUp, Victory, Point, MiddleFinger, OpenPalm]; - -// src/hand/fingerpose.ts -var minConfidence = 0.7; -var options3 = { - HALF_CURL_START_LIMIT: 60, - NO_CURL_START_LIMIT: 130, - DISTANCE_VOTE_POWER: 1.1, - SINGLE_ANGLE_VOTE_POWER: 0.9, - TOTAL_ANGLE_VOTE_POWER: 1.6 -}; -function calculateSlope(point1x, point1y, point2x, point2y) { - const value = (point1y - point2y) / (point1x - point2x); - let slope = Math.atan(value) * 180 / Math.PI; - if (slope <= 0) - slope = -slope; - else if (slope > 0) - slope = 180 - slope; - return slope; -} -function getSlopes(point1, point2) { - if (!point1 || !point2) - return [0, 0]; - const slopeXY = calculateSlope(point1[0], point1[1], point2[0], point2[1]); - if (point1.length === 2) - return slopeXY; - const slopeYZ = calculateSlope(point1[1], point1[2], point2[1], point2[2]); - return [slopeXY, slopeYZ]; -} -function angleOrientationAt(angle, weightageAt = 1) { - let isVertical = 0; - let isDiagonal = 0; - let isHorizontal = 0; - if (angle >= 75 && angle <= 105) - isVertical = 1 * weightageAt; - else if (angle >= 25 && angle <= 155) - isDiagonal = 1 * weightageAt; - else - isHorizontal = 1 * weightageAt; - return [isVertical, isDiagonal, isHorizontal]; -} -function estimateFingerCurl(startPoint, midPoint, endPoint) { - const start_mid_x_dist = startPoint[0] - midPoint[0]; - const start_end_x_dist = startPoint[0] - endPoint[0]; - const mid_end_x_dist = midPoint[0] - endPoint[0]; - const start_mid_y_dist = startPoint[1] - midPoint[1]; - const start_end_y_dist = startPoint[1] - endPoint[1]; - const mid_end_y_dist = midPoint[1] - endPoint[1]; - const start_mid_z_dist = startPoint[2] - midPoint[2]; - const start_end_z_dist = startPoint[2] - endPoint[2]; - const mid_end_z_dist = midPoint[2] - endPoint[2]; - const start_mid_dist = Math.sqrt(start_mid_x_dist * start_mid_x_dist + start_mid_y_dist * start_mid_y_dist + start_mid_z_dist * start_mid_z_dist); - const start_end_dist = Math.sqrt(start_end_x_dist * start_end_x_dist + start_end_y_dist * start_end_y_dist + start_end_z_dist * start_end_z_dist); - const mid_end_dist = Math.sqrt(mid_end_x_dist * mid_end_x_dist + mid_end_y_dist * mid_end_y_dist + mid_end_z_dist * mid_end_z_dist); - let cos_in = (mid_end_dist * mid_end_dist + start_mid_dist * start_mid_dist - start_end_dist * start_end_dist) / (2 * mid_end_dist * start_mid_dist); - if (cos_in > 1) - cos_in = 1; - else if (cos_in < -1) - cos_in = -1; - let angleOfCurve = Math.acos(cos_in); - angleOfCurve = 57.2958 * angleOfCurve % 180; - let fingerCurl; - if (angleOfCurve > options3.NO_CURL_START_LIMIT) - fingerCurl = FingerCurl.none; - else if (angleOfCurve > options3.HALF_CURL_START_LIMIT) - fingerCurl = FingerCurl.half; - else - fingerCurl = FingerCurl.full; - return fingerCurl; -} -function estimateHorizontalDirection(start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x) { - let estimatedDirection; - if (max_dist_x === Math.abs(start_end_x_dist)) { - if (start_end_x_dist > 0) - estimatedDirection = FingerDirection.horizontalLeft; - else - estimatedDirection = FingerDirection.horizontalRight; - } else if (max_dist_x === Math.abs(start_mid_x_dist)) { - if (start_mid_x_dist > 0) - estimatedDirection = FingerDirection.horizontalLeft; - else - estimatedDirection = FingerDirection.horizontalRight; - } else { - if (mid_end_x_dist > 0) - estimatedDirection = FingerDirection.horizontalLeft; - else - estimatedDirection = FingerDirection.horizontalRight; - } - return estimatedDirection; -} -function estimateVerticalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y) { - let estimatedDirection; - if (max_dist_y === Math.abs(start_end_y_dist)) { - if (start_end_y_dist < 0) - estimatedDirection = FingerDirection.verticalDown; - else - estimatedDirection = FingerDirection.verticalUp; - } else if (max_dist_y === Math.abs(start_mid_y_dist)) { - if (start_mid_y_dist < 0) - estimatedDirection = FingerDirection.verticalDown; - else - estimatedDirection = FingerDirection.verticalUp; - } else { - if (mid_end_y_dist < 0) - estimatedDirection = FingerDirection.verticalDown; - else - estimatedDirection = FingerDirection.verticalUp; - } - return estimatedDirection; -} -function estimateDiagonalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y, start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x) { - let estimatedDirection; - const reqd_vertical_direction = estimateVerticalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y); - const reqd_horizontal_direction = estimateHorizontalDirection(start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x); - if (reqd_vertical_direction === FingerDirection.verticalUp) { - if (reqd_horizontal_direction === FingerDirection.horizontalLeft) - estimatedDirection = FingerDirection.diagonalUpLeft; - else - estimatedDirection = FingerDirection.diagonalUpRight; - } else { - if (reqd_horizontal_direction === FingerDirection.horizontalLeft) - estimatedDirection = FingerDirection.diagonalDownLeft; - else - estimatedDirection = FingerDirection.diagonalDownRight; - } - return estimatedDirection; -} -function calculateFingerDirection(startPoint, midPoint, endPoint, fingerSlopes) { - const start_mid_x_dist = startPoint[0] - midPoint[0]; - const start_end_x_dist = startPoint[0] - endPoint[0]; - const mid_end_x_dist = midPoint[0] - endPoint[0]; - const start_mid_y_dist = startPoint[1] - midPoint[1]; - const start_end_y_dist = startPoint[1] - endPoint[1]; - const mid_end_y_dist = midPoint[1] - endPoint[1]; - const max_dist_x = Math.max(Math.abs(start_mid_x_dist), Math.abs(start_end_x_dist), Math.abs(mid_end_x_dist)); - const max_dist_y = Math.max(Math.abs(start_mid_y_dist), Math.abs(start_end_y_dist), Math.abs(mid_end_y_dist)); - let voteVertical = 0; - let voteDiagonal = 0; - let voteHorizontal = 0; - const start_end_x_y_dist_ratio = max_dist_y / (max_dist_x + 1e-5); - if (start_end_x_y_dist_ratio > 1.5) - voteVertical += options3.DISTANCE_VOTE_POWER; - else if (start_end_x_y_dist_ratio > 0.66) - voteDiagonal += options3.DISTANCE_VOTE_POWER; - else - voteHorizontal += options3.DISTANCE_VOTE_POWER; - const start_mid_dist = Math.sqrt(start_mid_x_dist * start_mid_x_dist + start_mid_y_dist * start_mid_y_dist); - const start_end_dist = Math.sqrt(start_end_x_dist * start_end_x_dist + start_end_y_dist * start_end_y_dist); - const mid_end_dist = Math.sqrt(mid_end_x_dist * mid_end_x_dist + mid_end_y_dist * mid_end_y_dist); - const max_dist = Math.max(start_mid_dist, start_end_dist, mid_end_dist); - let calc_start_point_x = startPoint[0]; - let calc_start_point_y = startPoint[1]; - let calc_end_point_x = endPoint[0]; - let calc_end_point_y = endPoint[1]; - if (max_dist === start_mid_dist) { - calc_end_point_x = endPoint[0]; - calc_end_point_y = endPoint[1]; - } else if (max_dist === mid_end_dist) { - calc_start_point_x = midPoint[0]; - calc_start_point_y = midPoint[1]; - } - const calcStartPoint = [calc_start_point_x, calc_start_point_y]; - const calcEndPoint = [calc_end_point_x, calc_end_point_y]; - const totalAngle = getSlopes(calcStartPoint, calcEndPoint); - const votes = angleOrientationAt(totalAngle, options3.TOTAL_ANGLE_VOTE_POWER); - voteVertical += votes[0]; - voteDiagonal += votes[1]; - voteHorizontal += votes[2]; - for (const fingerSlope of fingerSlopes) { - const fingerVotes = angleOrientationAt(fingerSlope, options3.SINGLE_ANGLE_VOTE_POWER); - voteVertical += fingerVotes[0]; - voteDiagonal += fingerVotes[1]; - voteHorizontal += fingerVotes[2]; - } - let estimatedDirection; - if (voteVertical === Math.max(voteVertical, voteDiagonal, voteHorizontal)) { - estimatedDirection = estimateVerticalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y); - } else if (voteHorizontal === Math.max(voteDiagonal, voteHorizontal)) { - estimatedDirection = estimateHorizontalDirection(start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x); - } else { - estimatedDirection = estimateDiagonalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y, start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x); - } - return estimatedDirection; -} -function estimate(landmarks) { - const slopesXY = []; - const slopesYZ = []; - const fingerCurls = []; - const fingerDirections = []; - if (!landmarks) - return { curls: fingerCurls, directions: fingerDirections }; - for (const finger of Finger.all) { - const points = Finger.getPoints(finger); - const slopeAtXY = []; - const slopeAtYZ = []; - for (const point2 of points) { - const point1 = landmarks[point2[0]]; - const point22 = landmarks[point2[1]]; - const slopes = getSlopes(point1, point22); - const slopeXY = slopes[0]; - const slopeYZ = slopes[1]; - slopeAtXY.push(slopeXY); - slopeAtYZ.push(slopeYZ); - } - slopesXY.push(slopeAtXY); - slopesYZ.push(slopeAtYZ); - } - for (const finger of Finger.all) { - const pointIndexAt = finger === Finger.thumb ? 1 : 0; - const fingerPointsAt = Finger.getPoints(finger); - const startPoint = landmarks[fingerPointsAt[pointIndexAt][0]]; - const midPoint = landmarks[fingerPointsAt[pointIndexAt + 1][1]]; - const endPoint = landmarks[fingerPointsAt[3][1]]; - const fingerCurled = estimateFingerCurl(startPoint, midPoint, endPoint); - const fingerPosition = calculateFingerDirection(startPoint, midPoint, endPoint, slopesXY[finger].slice(pointIndexAt)); - fingerCurls[finger] = fingerCurled; - fingerDirections[finger] = fingerPosition; - } - return { curls: fingerCurls, directions: fingerDirections }; -} -function analyze(keypoints) { - if (!keypoints || keypoints.length === 0) - return null; - const estimatorRes = estimate(keypoints); - const landmarks = {}; - for (const fingerIdx of Finger.all) { - landmarks[Finger.getName(fingerIdx)] = { - curl: FingerCurl.getName(estimatorRes.curls[fingerIdx]), - direction: FingerDirection.getName(estimatorRes.directions[fingerIdx]) - }; - } - return landmarks; -} -function match(keypoints) { - const poses = []; - if (!keypoints || keypoints.length === 0) - return poses; - const estimatorRes = estimate(keypoints); - for (const gesture2 of fingergesture_default) { - const confidence = gesture2.matchAgainst(estimatorRes.curls, estimatorRes.directions); - if (confidence >= minConfidence) - poses.push({ name: gesture2.name, confidence }); - } - return poses; -} - -// src/gesture/gesture.ts -var body2 = (res) => { - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - const leftWrist = res[i].keypoints.find((a) => a.part === "leftWrist"); - const rightWrist = res[i].keypoints.find((a) => a.part === "rightWrist"); - const nose = res[i].keypoints.find((a) => a.part === "nose"); - if (nose && leftWrist && rightWrist && leftWrist.position[1] < nose.position[1] && rightWrist.position[1] < nose.position[1]) - gestures.push({ body: i, gesture: "i give up" }); - else if (nose && leftWrist && leftWrist.position[1] < nose.position[1]) - gestures.push({ body: i, gesture: "raise left hand" }); - else if (nose && rightWrist && rightWrist.position[1] < nose.position[1]) - gestures.push({ body: i, gesture: "raise right hand" }); - const leftShoulder = res[i].keypoints.find((a) => a.part === "leftShoulder"); - const rightShoulder = res[i].keypoints.find((a) => a.part === "rightShoulder"); - if (leftShoulder && rightShoulder && Math.abs(leftShoulder.positionRaw[1] - rightShoulder.positionRaw[1]) > 0.1) { - gestures.push({ body: i, gesture: `leaning ${leftShoulder.position[1] > rightShoulder.position[1] ? "left" : "right"}` }); - } - } - return gestures; -}; -var face2 = (res) => { - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - if (res[i].mesh && res[i].mesh.length > 450) { - const zDiff = (res[i].mesh[33][2] || 0) - (res[i].mesh[263][2] || 0); - const xDiff = res[i].mesh[33][0] - res[i].mesh[263][0]; - if (Math.abs(zDiff / xDiff) <= 0.15) - gestures.push({ face: i, gesture: "facing center" }); - else - gestures.push({ face: i, gesture: `facing ${zDiff < 0 ? "left" : "right"}` }); - const openLeft = Math.abs(res[i].mesh[374][1] - res[i].mesh[386][1]) / Math.abs(res[i].mesh[443][1] - res[i].mesh[450][1]); - if (openLeft < 0.2) - gestures.push({ face: i, gesture: "blink left eye" }); - const openRight = Math.abs(res[i].mesh[145][1] - res[i].mesh[159][1]) / Math.abs(res[i].mesh[223][1] - res[i].mesh[230][1]); - if (openRight < 0.2) - gestures.push({ face: i, gesture: "blink right eye" }); - const mouthOpen = Math.min(100, 500 * Math.abs(res[i].mesh[13][1] - res[i].mesh[14][1]) / Math.abs(res[i].mesh[10][1] - res[i].mesh[152][1])); - if (mouthOpen > 10) - gestures.push({ face: i, gesture: `mouth ${Math.trunc(mouthOpen)}% open` }); - const chinDepth = res[i].mesh[152][2] || 0; - if (Math.abs(chinDepth) > 10) - gestures.push({ face: i, gesture: `head ${chinDepth < 0 ? "up" : "down"}` }); - } - } - return gestures; -}; -var iris2 = (res) => { - var _a, _b, _c, _d; - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - if (!((_b = (_a = res[i].annotations) == null ? void 0 : _a.leftEyeIris) == null ? void 0 : _b[0]) || !((_d = (_c = res[i].annotations) == null ? void 0 : _c.rightEyeIris) == null ? void 0 : _d[0])) - continue; - const sizeXLeft = res[i].annotations.leftEyeIris[3][0] - res[i].annotations.leftEyeIris[1][0]; - const sizeYLeft = res[i].annotations.leftEyeIris[4][1] - res[i].annotations.leftEyeIris[2][1]; - const areaLeft = Math.abs(sizeXLeft * sizeYLeft); - const sizeXRight = res[i].annotations.rightEyeIris[3][0] - res[i].annotations.rightEyeIris[1][0]; - const sizeYRight = res[i].annotations.rightEyeIris[4][1] - res[i].annotations.rightEyeIris[2][1]; - const areaRight = Math.abs(sizeXRight * sizeYRight); - let center = false; - const difference = Math.abs(areaLeft - areaRight) / Math.max(areaLeft, areaRight); - if (difference < 0.25) { - center = true; - gestures.push({ iris: i, gesture: "facing center" }); - } - const leftIrisCenterX = Math.abs(res[i].mesh[263][0] - res[i].annotations.leftEyeIris[0][0]) / res[i].box[2]; - const rightIrisCenterX = Math.abs(res[i].mesh[33][0] - res[i].annotations.rightEyeIris[0][0]) / res[i].box[2]; - if (leftIrisCenterX > 0.06 || rightIrisCenterX > 0.06) - center = false; - if (leftIrisCenterX > rightIrisCenterX) { - if (leftIrisCenterX > 0.05) - gestures.push({ iris: i, gesture: "looking right" }); - } else { - if (rightIrisCenterX > 0.05) - gestures.push({ iris: i, gesture: "looking left" }); - } - const rightIrisCenterY = Math.abs(res[i].mesh[145][1] - res[i].annotations.rightEyeIris[0][1]) / res[i].box[3]; - const leftIrisCenterY = Math.abs(res[i].mesh[374][1] - res[i].annotations.leftEyeIris[0][1]) / res[i].box[3]; - if (leftIrisCenterY < 0.01 || rightIrisCenterY < 0.01 || leftIrisCenterY > 0.022 || rightIrisCenterY > 0.022) - center = false; - if (leftIrisCenterY < 0.01 || rightIrisCenterY < 0.01) - gestures.push({ iris: i, gesture: "looking down" }); - if (leftIrisCenterY > 0.022 || rightIrisCenterY > 0.022) - gestures.push({ iris: i, gesture: "looking up" }); - if (center) - gestures.push({ iris: i, gesture: "looking center" }); - } - return gestures; -}; -var hand2 = (res) => { - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - const fingers = []; - if (res[i].annotations) { - for (const [finger, pos] of Object.entries(res[i].annotations)) { - if (finger !== "palmBase" && Array.isArray(pos) && pos[0]) - fingers.push({ name: finger.toLowerCase(), position: pos[0] }); - } - } - if (fingers && fingers.length > 0) { - const closest = fingers.reduce((best, a) => (best.position[2] || 0) < (a.position[2] || 0) ? best : a); - gestures.push({ hand: i, gesture: `${closest.name} forward` }); - const highest = fingers.reduce((best, a) => best.position[1] < a.position[1] ? best : a); - gestures.push({ hand: i, gesture: `${highest.name} up` }); - } - if (res[i].keypoints) { - const poses = match(res[i].keypoints); - for (const pose of poses) - gestures.push({ hand: i, gesture: pose.name }); - } - } - return gestures; -}; - -// src/hand/handposeutil.ts -function getBoxSize2(box) { - return [ - Math.abs(box.endPoint[0] - box.startPoint[0]), - Math.abs(box.endPoint[1] - box.startPoint[1]) - ]; -} -function getBoxCenter2(box) { - return [ - box.startPoint[0] + (box.endPoint[0] - box.startPoint[0]) / 2, - box.startPoint[1] + (box.endPoint[1] - box.startPoint[1]) / 2 - ]; -} -function cutBoxFromImageAndResize(box, image28, cropSize) { - const h = image28.shape[1]; - const w = image28.shape[2]; - const boxes = [[ - box.startPoint[1] / h, - box.startPoint[0] / w, - box.endPoint[1] / h, - box.endPoint[0] / w - ]]; - return tfjs_esm_exports.image.cropAndResize(image28, boxes, [0], cropSize); -} -function scaleBoxCoordinates2(box, factor) { - const startPoint = [box.startPoint[0] * factor[0], box.startPoint[1] * factor[1]]; - const endPoint = [box.endPoint[0] * factor[0], box.endPoint[1] * factor[1]]; - const palmLandmarks = box.palmLandmarks.map((coord) => { - const scaledCoord = [coord[0] * factor[0], coord[1] * factor[1]]; - return scaledCoord; - }); - return { startPoint, endPoint, palmLandmarks, confidence: box.confidence }; -} -function enlargeBox2(box, factor = 1.5) { - const center = getBoxCenter2(box); - const size2 = getBoxSize2(box); - const newHalfSize = [factor * size2[0] / 2, factor * size2[1] / 2]; - const startPoint = [center[0] - newHalfSize[0], center[1] - newHalfSize[1]]; - const endPoint = [center[0] + newHalfSize[0], center[1] + newHalfSize[1]]; - return { startPoint, endPoint, palmLandmarks: box.palmLandmarks }; -} -function squarifyBox2(box) { - const centers = getBoxCenter2(box); - const size2 = getBoxSize2(box); - const maxEdge = Math.max(...size2); - const halfSize = maxEdge / 2; - const startPoint = [centers[0] - halfSize, centers[1] - halfSize]; - const endPoint = [centers[0] + halfSize, centers[1] + halfSize]; - return { startPoint, endPoint, palmLandmarks: box.palmLandmarks }; -} -function normalizeRadians2(angle) { - return angle - 2 * Math.PI * Math.floor((angle + Math.PI) / (2 * Math.PI)); -} -function computeRotation2(point1, point2) { - const radians = Math.PI / 2 - Math.atan2(-(point2[1] - point1[1]), point2[0] - point1[0]); - return normalizeRadians2(radians); -} -var buildTranslationMatrix2 = (x, y) => [[1, 0, x], [0, 1, y], [0, 0, 1]]; -function dot2(v1, v2) { - let product = 0; - for (let i = 0; i < v1.length; i++) { - product += v1[i] * v2[i]; - } - return product; -} -function getColumnFrom2DArr2(arr, columnIndex) { - const column = []; - for (let i = 0; i < arr.length; i++) { - column.push(arr[i][columnIndex]); - } - return column; -} -function multiplyTransformMatrices2(mat1, mat2) { - const product = []; - const size2 = mat1.length; - for (let row = 0; row < size2; row++) { - product.push([]); - for (let col = 0; col < size2; col++) { - product[row].push(dot2(mat1[row], getColumnFrom2DArr2(mat2, col))); - } - } - return product; -} -function buildRotationMatrix2(rotation, center) { - const cosA = Math.cos(rotation); - const sinA = Math.sin(rotation); - const rotationMatrix = [[cosA, -sinA, 0], [sinA, cosA, 0], [0, 0, 1]]; - const translationMatrix = buildTranslationMatrix2(center[0], center[1]); - const translationTimesRotation = multiplyTransformMatrices2(translationMatrix, rotationMatrix); - const negativeTranslationMatrix = buildTranslationMatrix2(-center[0], -center[1]); - return multiplyTransformMatrices2(translationTimesRotation, negativeTranslationMatrix); -} -function invertTransformMatrix2(matrix) { - const rotationComponent = [[matrix[0][0], matrix[1][0]], [matrix[0][1], matrix[1][1]]]; - const translationComponent = [matrix[0][2], matrix[1][2]]; - const invertedTranslation = [ - -dot2(rotationComponent[0], translationComponent), - -dot2(rotationComponent[1], translationComponent) - ]; - return [ - rotationComponent[0].concat(invertedTranslation[0]), - rotationComponent[1].concat(invertedTranslation[1]), - [0, 0, 1] - ]; -} -function rotatePoint2(homogeneousCoordinate, rotationMatrix) { - return [ - dot2(homogeneousCoordinate, rotationMatrix[0]), - dot2(homogeneousCoordinate, rotationMatrix[1]) - ]; -} - -// src/hand/handposeanchors.ts -var anchors2 = [ - { x: 0.015625, y: 0.015625 }, - { x: 0.015625, y: 0.015625 }, - { x: 0.046875, y: 0.015625 }, - { x: 0.046875, y: 0.015625 }, - { x: 0.078125, y: 0.015625 }, - { x: 0.078125, y: 0.015625 }, - { x: 0.109375, y: 0.015625 }, - { x: 0.109375, y: 0.015625 }, - { x: 0.140625, y: 0.015625 }, - { x: 0.140625, y: 0.015625 }, - { x: 0.171875, y: 0.015625 }, - { x: 0.171875, y: 0.015625 }, - { x: 0.203125, y: 0.015625 }, - { x: 0.203125, y: 0.015625 }, - { x: 0.234375, y: 0.015625 }, - { x: 0.234375, y: 0.015625 }, - { x: 0.265625, y: 0.015625 }, - { x: 0.265625, y: 0.015625 }, - { x: 0.296875, y: 0.015625 }, - { x: 0.296875, y: 0.015625 }, - { x: 0.328125, y: 0.015625 }, - { x: 0.328125, y: 0.015625 }, - { x: 0.359375, y: 0.015625 }, - { x: 0.359375, y: 0.015625 }, - { x: 0.390625, y: 0.015625 }, - { x: 0.390625, y: 0.015625 }, - { x: 0.421875, y: 0.015625 }, - { x: 0.421875, y: 0.015625 }, - { x: 0.453125, y: 0.015625 }, - { x: 0.453125, y: 0.015625 }, - { x: 0.484375, y: 0.015625 }, - { x: 0.484375, y: 0.015625 }, - { x: 0.515625, y: 0.015625 }, - { x: 0.515625, y: 0.015625 }, - { x: 0.546875, y: 0.015625 }, - { x: 0.546875, y: 0.015625 }, - { x: 0.578125, y: 0.015625 }, - { x: 0.578125, y: 0.015625 }, - { x: 0.609375, y: 0.015625 }, - { x: 0.609375, y: 0.015625 }, - { x: 0.640625, y: 0.015625 }, - { x: 0.640625, y: 0.015625 }, - { x: 0.671875, y: 0.015625 }, - { x: 0.671875, y: 0.015625 }, - { x: 0.703125, y: 0.015625 }, - { x: 0.703125, y: 0.015625 }, - { x: 0.734375, y: 0.015625 }, - { x: 0.734375, y: 0.015625 }, - { x: 0.765625, y: 0.015625 }, - { x: 0.765625, y: 0.015625 }, - { x: 0.796875, y: 0.015625 }, - { x: 0.796875, y: 0.015625 }, - { x: 0.828125, y: 0.015625 }, - { x: 0.828125, y: 0.015625 }, - { x: 0.859375, y: 0.015625 }, - { x: 0.859375, y: 0.015625 }, - { x: 0.890625, y: 0.015625 }, - { x: 0.890625, y: 0.015625 }, - { x: 0.921875, y: 0.015625 }, - { x: 0.921875, y: 0.015625 }, - { x: 0.953125, y: 0.015625 }, - { x: 0.953125, y: 0.015625 }, - { x: 0.984375, y: 0.015625 }, - { x: 0.984375, y: 0.015625 }, - { x: 0.015625, y: 0.046875 }, - { x: 0.015625, y: 0.046875 }, - { x: 0.046875, y: 0.046875 }, - { x: 0.046875, y: 0.046875 }, - { x: 0.078125, y: 0.046875 }, - { x: 0.078125, y: 0.046875 }, - { x: 0.109375, y: 0.046875 }, - { x: 0.109375, y: 0.046875 }, - { x: 0.140625, y: 0.046875 }, - { x: 0.140625, y: 0.046875 }, - { x: 0.171875, y: 0.046875 }, - { x: 0.171875, y: 0.046875 }, - { x: 0.203125, y: 0.046875 }, - { x: 0.203125, y: 0.046875 }, - { x: 0.234375, y: 0.046875 }, - { x: 0.234375, y: 0.046875 }, - { x: 0.265625, y: 0.046875 }, - { x: 0.265625, y: 0.046875 }, - { x: 0.296875, y: 0.046875 }, - { x: 0.296875, y: 0.046875 }, - { x: 0.328125, y: 0.046875 }, - { x: 0.328125, y: 0.046875 }, - { x: 0.359375, y: 0.046875 }, - { x: 0.359375, y: 0.046875 }, - { x: 0.390625, y: 0.046875 }, - { x: 0.390625, y: 0.046875 }, - { x: 0.421875, y: 0.046875 }, - { x: 0.421875, y: 0.046875 }, - { x: 0.453125, y: 0.046875 }, - { x: 0.453125, y: 0.046875 }, - { x: 0.484375, y: 0.046875 }, - { x: 0.484375, y: 0.046875 }, - { x: 0.515625, y: 0.046875 }, - { x: 0.515625, y: 0.046875 }, - { x: 0.546875, y: 0.046875 }, - { x: 0.546875, y: 0.046875 }, - { x: 0.578125, y: 0.046875 }, - { x: 0.578125, y: 0.046875 }, - { x: 0.609375, y: 0.046875 }, - { x: 0.609375, y: 0.046875 }, - { x: 0.640625, y: 0.046875 }, - { x: 0.640625, y: 0.046875 }, - { x: 0.671875, y: 0.046875 }, - { x: 0.671875, y: 0.046875 }, - { x: 0.703125, y: 0.046875 }, - { x: 0.703125, y: 0.046875 }, - { x: 0.734375, y: 0.046875 }, - { x: 0.734375, y: 0.046875 }, - { x: 0.765625, y: 0.046875 }, - { x: 0.765625, y: 0.046875 }, - { x: 0.796875, y: 0.046875 }, - { x: 0.796875, y: 0.046875 }, - { x: 0.828125, y: 0.046875 }, - { x: 0.828125, y: 0.046875 }, - { x: 0.859375, y: 0.046875 }, - { x: 0.859375, y: 0.046875 }, - { x: 0.890625, y: 0.046875 }, - { x: 0.890625, y: 0.046875 }, - { x: 0.921875, y: 0.046875 }, - { x: 0.921875, y: 0.046875 }, - { x: 0.953125, y: 0.046875 }, - { x: 0.953125, y: 0.046875 }, - { x: 0.984375, y: 0.046875 }, - { x: 0.984375, y: 0.046875 }, - { x: 0.015625, y: 0.078125 }, - { x: 0.015625, y: 0.078125 }, - { x: 0.046875, y: 0.078125 }, - { x: 0.046875, y: 0.078125 }, - { x: 0.078125, y: 0.078125 }, - { x: 0.078125, y: 0.078125 }, - { x: 0.109375, y: 0.078125 }, - { x: 0.109375, y: 0.078125 }, - { x: 0.140625, y: 0.078125 }, - { x: 0.140625, y: 0.078125 }, - { x: 0.171875, y: 0.078125 }, - { x: 0.171875, y: 0.078125 }, - { x: 0.203125, y: 0.078125 }, - { x: 0.203125, y: 0.078125 }, - { x: 0.234375, y: 0.078125 }, - { x: 0.234375, y: 0.078125 }, - { x: 0.265625, y: 0.078125 }, - { x: 0.265625, y: 0.078125 }, - { x: 0.296875, y: 0.078125 }, - { x: 0.296875, y: 0.078125 }, - { x: 0.328125, y: 0.078125 }, - { x: 0.328125, y: 0.078125 }, - { x: 0.359375, y: 0.078125 }, - { x: 0.359375, y: 0.078125 }, - { x: 0.390625, y: 0.078125 }, - { x: 0.390625, y: 0.078125 }, - { x: 0.421875, y: 0.078125 }, - { x: 0.421875, y: 0.078125 }, - { x: 0.453125, y: 0.078125 }, - { x: 0.453125, y: 0.078125 }, - { x: 0.484375, y: 0.078125 }, - { x: 0.484375, y: 0.078125 }, - { x: 0.515625, y: 0.078125 }, - { x: 0.515625, y: 0.078125 }, - { x: 0.546875, y: 0.078125 }, - { x: 0.546875, y: 0.078125 }, - { x: 0.578125, y: 0.078125 }, - { x: 0.578125, y: 0.078125 }, - { x: 0.609375, y: 0.078125 }, - { x: 0.609375, y: 0.078125 }, - { x: 0.640625, y: 0.078125 }, - { x: 0.640625, y: 0.078125 }, - { x: 0.671875, y: 0.078125 }, - { x: 0.671875, y: 0.078125 }, - { x: 0.703125, y: 0.078125 }, - { x: 0.703125, y: 0.078125 }, - { x: 0.734375, y: 0.078125 }, - { x: 0.734375, y: 0.078125 }, - { x: 0.765625, y: 0.078125 }, - { x: 0.765625, y: 0.078125 }, - { x: 0.796875, y: 0.078125 }, - { x: 0.796875, y: 0.078125 }, - { x: 0.828125, y: 0.078125 }, - { x: 0.828125, y: 0.078125 }, - { x: 0.859375, y: 0.078125 }, - { x: 0.859375, y: 0.078125 }, - { x: 0.890625, y: 0.078125 }, - { x: 0.890625, y: 0.078125 }, - { x: 0.921875, y: 0.078125 }, - { x: 0.921875, y: 0.078125 }, - { x: 0.953125, y: 0.078125 }, - { x: 0.953125, y: 0.078125 }, - { x: 0.984375, y: 0.078125 }, - { x: 0.984375, y: 0.078125 }, - { x: 0.015625, y: 0.109375 }, - { x: 0.015625, y: 0.109375 }, - { x: 0.046875, y: 0.109375 }, - { x: 0.046875, y: 0.109375 }, - { x: 0.078125, y: 0.109375 }, - { x: 0.078125, y: 0.109375 }, - { x: 0.109375, y: 0.109375 }, - { x: 0.109375, y: 0.109375 }, - { x: 0.140625, y: 0.109375 }, - { x: 0.140625, y: 0.109375 }, - { x: 0.171875, y: 0.109375 }, - { x: 0.171875, y: 0.109375 }, - { x: 0.203125, y: 0.109375 }, - { x: 0.203125, y: 0.109375 }, - { x: 0.234375, y: 0.109375 }, - { x: 0.234375, y: 0.109375 }, - { x: 0.265625, y: 0.109375 }, - { x: 0.265625, y: 0.109375 }, - { x: 0.296875, y: 0.109375 }, - { x: 0.296875, y: 0.109375 }, - { x: 0.328125, y: 0.109375 }, - { x: 0.328125, y: 0.109375 }, - { x: 0.359375, y: 0.109375 }, - { x: 0.359375, y: 0.109375 }, - { x: 0.390625, y: 0.109375 }, - { x: 0.390625, y: 0.109375 }, - { x: 0.421875, y: 0.109375 }, - { x: 0.421875, y: 0.109375 }, - { x: 0.453125, y: 0.109375 }, - { x: 0.453125, y: 0.109375 }, - { x: 0.484375, y: 0.109375 }, - { x: 0.484375, y: 0.109375 }, - { x: 0.515625, y: 0.109375 }, - { x: 0.515625, y: 0.109375 }, - { x: 0.546875, y: 0.109375 }, - { x: 0.546875, y: 0.109375 }, - { x: 0.578125, y: 0.109375 }, - { x: 0.578125, y: 0.109375 }, - { x: 0.609375, y: 0.109375 }, - { x: 0.609375, y: 0.109375 }, - { x: 0.640625, y: 0.109375 }, - { x: 0.640625, y: 0.109375 }, - { x: 0.671875, y: 0.109375 }, - { x: 0.671875, y: 0.109375 }, - { x: 0.703125, y: 0.109375 }, - { x: 0.703125, y: 0.109375 }, - { x: 0.734375, y: 0.109375 }, - { x: 0.734375, y: 0.109375 }, - { x: 0.765625, y: 0.109375 }, - { x: 0.765625, y: 0.109375 }, - { x: 0.796875, y: 0.109375 }, - { x: 0.796875, y: 0.109375 }, - { x: 0.828125, y: 0.109375 }, - { x: 0.828125, y: 0.109375 }, - { x: 0.859375, y: 0.109375 }, - { x: 0.859375, y: 0.109375 }, - { x: 0.890625, y: 0.109375 }, - { x: 0.890625, y: 0.109375 }, - { x: 0.921875, y: 0.109375 }, - { x: 0.921875, y: 0.109375 }, - { x: 0.953125, y: 0.109375 }, - { x: 0.953125, y: 0.109375 }, - { x: 0.984375, y: 0.109375 }, - { x: 0.984375, y: 0.109375 }, - { x: 0.015625, y: 0.140625 }, - { x: 0.015625, y: 0.140625 }, - { x: 0.046875, y: 0.140625 }, - { x: 0.046875, y: 0.140625 }, - { x: 0.078125, y: 0.140625 }, - { x: 0.078125, y: 0.140625 }, - { x: 0.109375, y: 0.140625 }, - { x: 0.109375, y: 0.140625 }, - { x: 0.140625, y: 0.140625 }, - { x: 0.140625, y: 0.140625 }, - { x: 0.171875, y: 0.140625 }, - { x: 0.171875, y: 0.140625 }, - { x: 0.203125, y: 0.140625 }, - { x: 0.203125, y: 0.140625 }, - { x: 0.234375, y: 0.140625 }, - { x: 0.234375, y: 0.140625 }, - { x: 0.265625, y: 0.140625 }, - { x: 0.265625, y: 0.140625 }, - { x: 0.296875, y: 0.140625 }, - { x: 0.296875, y: 0.140625 }, - { x: 0.328125, y: 0.140625 }, - { x: 0.328125, y: 0.140625 }, - { x: 0.359375, y: 0.140625 }, - { x: 0.359375, y: 0.140625 }, - { x: 0.390625, y: 0.140625 }, - { x: 0.390625, y: 0.140625 }, - { x: 0.421875, y: 0.140625 }, - { x: 0.421875, y: 0.140625 }, - { x: 0.453125, y: 0.140625 }, - { x: 0.453125, y: 0.140625 }, - { x: 0.484375, y: 0.140625 }, - { x: 0.484375, y: 0.140625 }, - { x: 0.515625, y: 0.140625 }, - { x: 0.515625, y: 0.140625 }, - { x: 0.546875, y: 0.140625 }, - { x: 0.546875, y: 0.140625 }, - { x: 0.578125, y: 0.140625 }, - { x: 0.578125, y: 0.140625 }, - { x: 0.609375, y: 0.140625 }, - { x: 0.609375, y: 0.140625 }, - { x: 0.640625, y: 0.140625 }, - { x: 0.640625, y: 0.140625 }, - { x: 0.671875, y: 0.140625 }, - { x: 0.671875, y: 0.140625 }, - { x: 0.703125, y: 0.140625 }, - { x: 0.703125, y: 0.140625 }, - { x: 0.734375, y: 0.140625 }, - { x: 0.734375, y: 0.140625 }, - { x: 0.765625, y: 0.140625 }, - { x: 0.765625, y: 0.140625 }, - { x: 0.796875, y: 0.140625 }, - { x: 0.796875, y: 0.140625 }, - { x: 0.828125, y: 0.140625 }, - { x: 0.828125, y: 0.140625 }, - { x: 0.859375, y: 0.140625 }, - { x: 0.859375, y: 0.140625 }, - { x: 0.890625, y: 0.140625 }, - { x: 0.890625, y: 0.140625 }, - { x: 0.921875, y: 0.140625 }, - { x: 0.921875, y: 0.140625 }, - { x: 0.953125, y: 0.140625 }, - { x: 0.953125, y: 0.140625 }, - { x: 0.984375, y: 0.140625 }, - { x: 0.984375, y: 0.140625 }, - { x: 0.015625, y: 0.171875 }, - { x: 0.015625, y: 0.171875 }, - { x: 0.046875, y: 0.171875 }, - { x: 0.046875, y: 0.171875 }, - { x: 0.078125, y: 0.171875 }, - { x: 0.078125, y: 0.171875 }, - { x: 0.109375, y: 0.171875 }, - { x: 0.109375, y: 0.171875 }, - { x: 0.140625, y: 0.171875 }, - { x: 0.140625, y: 0.171875 }, - { x: 0.171875, y: 0.171875 }, - { x: 0.171875, y: 0.171875 }, - { x: 0.203125, y: 0.171875 }, - { x: 0.203125, y: 0.171875 }, - { x: 0.234375, y: 0.171875 }, - { x: 0.234375, y: 0.171875 }, - { x: 0.265625, y: 0.171875 }, - { x: 0.265625, y: 0.171875 }, - { x: 0.296875, y: 0.171875 }, - { x: 0.296875, y: 0.171875 }, - { x: 0.328125, y: 0.171875 }, - { x: 0.328125, y: 0.171875 }, - { x: 0.359375, y: 0.171875 }, - { x: 0.359375, y: 0.171875 }, - { x: 0.390625, y: 0.171875 }, - { x: 0.390625, y: 0.171875 }, - { x: 0.421875, y: 0.171875 }, - { x: 0.421875, y: 0.171875 }, - { x: 0.453125, y: 0.171875 }, - { x: 0.453125, y: 0.171875 }, - { x: 0.484375, y: 0.171875 }, - { x: 0.484375, y: 0.171875 }, - { x: 0.515625, y: 0.171875 }, - { x: 0.515625, y: 0.171875 }, - { x: 0.546875, y: 0.171875 }, - { x: 0.546875, y: 0.171875 }, - { x: 0.578125, y: 0.171875 }, - { x: 0.578125, y: 0.171875 }, - { x: 0.609375, y: 0.171875 }, - { x: 0.609375, y: 0.171875 }, - { x: 0.640625, y: 0.171875 }, - { x: 0.640625, y: 0.171875 }, - { x: 0.671875, y: 0.171875 }, - { x: 0.671875, y: 0.171875 }, - { x: 0.703125, y: 0.171875 }, - { x: 0.703125, y: 0.171875 }, - { x: 0.734375, y: 0.171875 }, - { x: 0.734375, y: 0.171875 }, - { x: 0.765625, y: 0.171875 }, - { x: 0.765625, y: 0.171875 }, - { x: 0.796875, y: 0.171875 }, - { x: 0.796875, y: 0.171875 }, - { x: 0.828125, y: 0.171875 }, - { x: 0.828125, y: 0.171875 }, - { x: 0.859375, y: 0.171875 }, - { x: 0.859375, y: 0.171875 }, - { x: 0.890625, y: 0.171875 }, - { x: 0.890625, y: 0.171875 }, - { x: 0.921875, y: 0.171875 }, - { x: 0.921875, y: 0.171875 }, - { x: 0.953125, y: 0.171875 }, - { x: 0.953125, y: 0.171875 }, - { x: 0.984375, y: 0.171875 }, - { x: 0.984375, y: 0.171875 }, - { x: 0.015625, y: 0.203125 }, - { x: 0.015625, y: 0.203125 }, - { x: 0.046875, y: 0.203125 }, - { x: 0.046875, y: 0.203125 }, - { x: 0.078125, y: 0.203125 }, - { x: 0.078125, y: 0.203125 }, - { x: 0.109375, y: 0.203125 }, - { x: 0.109375, y: 0.203125 }, - { x: 0.140625, y: 0.203125 }, - { x: 0.140625, y: 0.203125 }, - { x: 0.171875, y: 0.203125 }, - { x: 0.171875, y: 0.203125 }, - { x: 0.203125, y: 0.203125 }, - { x: 0.203125, y: 0.203125 }, - { x: 0.234375, y: 0.203125 }, - { x: 0.234375, y: 0.203125 }, - { x: 0.265625, y: 0.203125 }, - { x: 0.265625, y: 0.203125 }, - { x: 0.296875, y: 0.203125 }, - { x: 0.296875, y: 0.203125 }, - { x: 0.328125, y: 0.203125 }, - { x: 0.328125, y: 0.203125 }, - { x: 0.359375, y: 0.203125 }, - { x: 0.359375, y: 0.203125 }, - { x: 0.390625, y: 0.203125 }, - { x: 0.390625, y: 0.203125 }, - { x: 0.421875, y: 0.203125 }, - { x: 0.421875, y: 0.203125 }, - { x: 0.453125, y: 0.203125 }, - { x: 0.453125, y: 0.203125 }, - { x: 0.484375, y: 0.203125 }, - { x: 0.484375, y: 0.203125 }, - { x: 0.515625, y: 0.203125 }, - { x: 0.515625, y: 0.203125 }, - { x: 0.546875, y: 0.203125 }, - { x: 0.546875, y: 0.203125 }, - { x: 0.578125, y: 0.203125 }, - { x: 0.578125, y: 0.203125 }, - { x: 0.609375, y: 0.203125 }, - { x: 0.609375, y: 0.203125 }, - { x: 0.640625, y: 0.203125 }, - { x: 0.640625, y: 0.203125 }, - { x: 0.671875, y: 0.203125 }, - { x: 0.671875, y: 0.203125 }, - { x: 0.703125, y: 0.203125 }, - { x: 0.703125, y: 0.203125 }, - { x: 0.734375, y: 0.203125 }, - { x: 0.734375, y: 0.203125 }, - { x: 0.765625, y: 0.203125 }, - { x: 0.765625, y: 0.203125 }, - { x: 0.796875, y: 0.203125 }, - { x: 0.796875, y: 0.203125 }, - { x: 0.828125, y: 0.203125 }, - { x: 0.828125, y: 0.203125 }, - { x: 0.859375, y: 0.203125 }, - { x: 0.859375, y: 0.203125 }, - { x: 0.890625, y: 0.203125 }, - { x: 0.890625, y: 0.203125 }, - { x: 0.921875, y: 0.203125 }, - { x: 0.921875, y: 0.203125 }, - { x: 0.953125, y: 0.203125 }, - { x: 0.953125, y: 0.203125 }, - { x: 0.984375, y: 0.203125 }, - { x: 0.984375, y: 0.203125 }, - { x: 0.015625, y: 0.234375 }, - { x: 0.015625, y: 0.234375 }, - { x: 0.046875, y: 0.234375 }, - { x: 0.046875, y: 0.234375 }, - { x: 0.078125, y: 0.234375 }, - { x: 0.078125, y: 0.234375 }, - { x: 0.109375, y: 0.234375 }, - { x: 0.109375, y: 0.234375 }, - { x: 0.140625, y: 0.234375 }, - { x: 0.140625, y: 0.234375 }, - { x: 0.171875, y: 0.234375 }, - { x: 0.171875, y: 0.234375 }, - { x: 0.203125, y: 0.234375 }, - { x: 0.203125, y: 0.234375 }, - { x: 0.234375, y: 0.234375 }, - { x: 0.234375, y: 0.234375 }, - { x: 0.265625, y: 0.234375 }, - { x: 0.265625, y: 0.234375 }, - { x: 0.296875, y: 0.234375 }, - { x: 0.296875, y: 0.234375 }, - { x: 0.328125, y: 0.234375 }, - { x: 0.328125, y: 0.234375 }, - { x: 0.359375, y: 0.234375 }, - { x: 0.359375, y: 0.234375 }, - { x: 0.390625, y: 0.234375 }, - { x: 0.390625, y: 0.234375 }, - { x: 0.421875, y: 0.234375 }, - { x: 0.421875, y: 0.234375 }, - { x: 0.453125, y: 0.234375 }, - { x: 0.453125, y: 0.234375 }, - { x: 0.484375, y: 0.234375 }, - { x: 0.484375, y: 0.234375 }, - { x: 0.515625, y: 0.234375 }, - { x: 0.515625, y: 0.234375 }, - { x: 0.546875, y: 0.234375 }, - { x: 0.546875, y: 0.234375 }, - { x: 0.578125, y: 0.234375 }, - { x: 0.578125, y: 0.234375 }, - { x: 0.609375, y: 0.234375 }, - { x: 0.609375, y: 0.234375 }, - { x: 0.640625, y: 0.234375 }, - { x: 0.640625, y: 0.234375 }, - { x: 0.671875, y: 0.234375 }, - { x: 0.671875, y: 0.234375 }, - { x: 0.703125, y: 0.234375 }, - { x: 0.703125, y: 0.234375 }, - { x: 0.734375, y: 0.234375 }, - { x: 0.734375, y: 0.234375 }, - { x: 0.765625, y: 0.234375 }, - { x: 0.765625, y: 0.234375 }, - { x: 0.796875, y: 0.234375 }, - { x: 0.796875, y: 0.234375 }, - { x: 0.828125, y: 0.234375 }, - { x: 0.828125, y: 0.234375 }, - { x: 0.859375, y: 0.234375 }, - { x: 0.859375, y: 0.234375 }, - { x: 0.890625, y: 0.234375 }, - { x: 0.890625, y: 0.234375 }, - { x: 0.921875, y: 0.234375 }, - { x: 0.921875, y: 0.234375 }, - { x: 0.953125, y: 0.234375 }, - { x: 0.953125, y: 0.234375 }, - { x: 0.984375, y: 0.234375 }, - { x: 0.984375, y: 0.234375 }, - { x: 0.015625, y: 0.265625 }, - { x: 0.015625, y: 0.265625 }, - { x: 0.046875, y: 0.265625 }, - { x: 0.046875, y: 0.265625 }, - { x: 0.078125, y: 0.265625 }, - { x: 0.078125, y: 0.265625 }, - { x: 0.109375, y: 0.265625 }, - { x: 0.109375, y: 0.265625 }, - { x: 0.140625, y: 0.265625 }, - { x: 0.140625, y: 0.265625 }, - { x: 0.171875, y: 0.265625 }, - { x: 0.171875, y: 0.265625 }, - { x: 0.203125, y: 0.265625 }, - { x: 0.203125, y: 0.265625 }, - { x: 0.234375, y: 0.265625 }, - { x: 0.234375, y: 0.265625 }, - { x: 0.265625, y: 0.265625 }, - { x: 0.265625, y: 0.265625 }, - { x: 0.296875, y: 0.265625 }, - { x: 0.296875, y: 0.265625 }, - { x: 0.328125, y: 0.265625 }, - { x: 0.328125, y: 0.265625 }, - { x: 0.359375, y: 0.265625 }, - { x: 0.359375, y: 0.265625 }, - { x: 0.390625, y: 0.265625 }, - { x: 0.390625, y: 0.265625 }, - { x: 0.421875, y: 0.265625 }, - { x: 0.421875, y: 0.265625 }, - { x: 0.453125, y: 0.265625 }, - { x: 0.453125, y: 0.265625 }, - { x: 0.484375, y: 0.265625 }, - { x: 0.484375, y: 0.265625 }, - { x: 0.515625, y: 0.265625 }, - { x: 0.515625, y: 0.265625 }, - { x: 0.546875, y: 0.265625 }, - { x: 0.546875, y: 0.265625 }, - { x: 0.578125, y: 0.265625 }, - { x: 0.578125, y: 0.265625 }, - { x: 0.609375, y: 0.265625 }, - { x: 0.609375, y: 0.265625 }, - { x: 0.640625, y: 0.265625 }, - { x: 0.640625, y: 0.265625 }, - { x: 0.671875, y: 0.265625 }, - { x: 0.671875, y: 0.265625 }, - { x: 0.703125, y: 0.265625 }, - { x: 0.703125, y: 0.265625 }, - { x: 0.734375, y: 0.265625 }, - { x: 0.734375, y: 0.265625 }, - { x: 0.765625, y: 0.265625 }, - { x: 0.765625, y: 0.265625 }, - { x: 0.796875, y: 0.265625 }, - { x: 0.796875, y: 0.265625 }, - { x: 0.828125, y: 0.265625 }, - { x: 0.828125, y: 0.265625 }, - { x: 0.859375, y: 0.265625 }, - { x: 0.859375, y: 0.265625 }, - { x: 0.890625, y: 0.265625 }, - { x: 0.890625, y: 0.265625 }, - { x: 0.921875, y: 0.265625 }, - { x: 0.921875, y: 0.265625 }, - { x: 0.953125, y: 0.265625 }, - { x: 0.953125, y: 0.265625 }, - { x: 0.984375, y: 0.265625 }, - { x: 0.984375, y: 0.265625 }, - { x: 0.015625, y: 0.296875 }, - { x: 0.015625, y: 0.296875 }, - { x: 0.046875, y: 0.296875 }, - { x: 0.046875, y: 0.296875 }, - { x: 0.078125, y: 0.296875 }, - { x: 0.078125, y: 0.296875 }, - { x: 0.109375, y: 0.296875 }, - { x: 0.109375, y: 0.296875 }, - { x: 0.140625, y: 0.296875 }, - { x: 0.140625, y: 0.296875 }, - { x: 0.171875, y: 0.296875 }, - { x: 0.171875, y: 0.296875 }, - { x: 0.203125, y: 0.296875 }, - { x: 0.203125, y: 0.296875 }, - { x: 0.234375, y: 0.296875 }, - { x: 0.234375, y: 0.296875 }, - { x: 0.265625, y: 0.296875 }, - { x: 0.265625, y: 0.296875 }, - { x: 0.296875, y: 0.296875 }, - { x: 0.296875, y: 0.296875 }, - { x: 0.328125, y: 0.296875 }, - { x: 0.328125, y: 0.296875 }, - { x: 0.359375, y: 0.296875 }, - { x: 0.359375, y: 0.296875 }, - { x: 0.390625, y: 0.296875 }, - { x: 0.390625, y: 0.296875 }, - { x: 0.421875, y: 0.296875 }, - { x: 0.421875, y: 0.296875 }, - { x: 0.453125, y: 0.296875 }, - { x: 0.453125, y: 0.296875 }, - { x: 0.484375, y: 0.296875 }, - { x: 0.484375, y: 0.296875 }, - { x: 0.515625, y: 0.296875 }, - { x: 0.515625, y: 0.296875 }, - { x: 0.546875, y: 0.296875 }, - { x: 0.546875, y: 0.296875 }, - { x: 0.578125, y: 0.296875 }, - { x: 0.578125, y: 0.296875 }, - { x: 0.609375, y: 0.296875 }, - { x: 0.609375, y: 0.296875 }, - { x: 0.640625, y: 0.296875 }, - { x: 0.640625, y: 0.296875 }, - { x: 0.671875, y: 0.296875 }, - { x: 0.671875, y: 0.296875 }, - { x: 0.703125, y: 0.296875 }, - { x: 0.703125, y: 0.296875 }, - { x: 0.734375, y: 0.296875 }, - { x: 0.734375, y: 0.296875 }, - { x: 0.765625, y: 0.296875 }, - { x: 0.765625, y: 0.296875 }, - { x: 0.796875, y: 0.296875 }, - { x: 0.796875, y: 0.296875 }, - { x: 0.828125, y: 0.296875 }, - { x: 0.828125, y: 0.296875 }, - { x: 0.859375, y: 0.296875 }, - { x: 0.859375, y: 0.296875 }, - { x: 0.890625, y: 0.296875 }, - { x: 0.890625, y: 0.296875 }, - { x: 0.921875, y: 0.296875 }, - { x: 0.921875, y: 0.296875 }, - { x: 0.953125, y: 0.296875 }, - { x: 0.953125, y: 0.296875 }, - { x: 0.984375, y: 0.296875 }, - { x: 0.984375, y: 0.296875 }, - { x: 0.015625, y: 0.328125 }, - { x: 0.015625, y: 0.328125 }, - { x: 0.046875, y: 0.328125 }, - { x: 0.046875, y: 0.328125 }, - { x: 0.078125, y: 0.328125 }, - { x: 0.078125, y: 0.328125 }, - { x: 0.109375, y: 0.328125 }, - { x: 0.109375, y: 0.328125 }, - { x: 0.140625, y: 0.328125 }, - { x: 0.140625, y: 0.328125 }, - { x: 0.171875, y: 0.328125 }, - { x: 0.171875, y: 0.328125 }, - { x: 0.203125, y: 0.328125 }, - { x: 0.203125, y: 0.328125 }, - { x: 0.234375, y: 0.328125 }, - { x: 0.234375, y: 0.328125 }, - { x: 0.265625, y: 0.328125 }, - { x: 0.265625, y: 0.328125 }, - { x: 0.296875, y: 0.328125 }, - { x: 0.296875, y: 0.328125 }, - { x: 0.328125, y: 0.328125 }, - { x: 0.328125, y: 0.328125 }, - { x: 0.359375, y: 0.328125 }, - { x: 0.359375, y: 0.328125 }, - { x: 0.390625, y: 0.328125 }, - { x: 0.390625, y: 0.328125 }, - { x: 0.421875, y: 0.328125 }, - { x: 0.421875, y: 0.328125 }, - { x: 0.453125, y: 0.328125 }, - { x: 0.453125, y: 0.328125 }, - { x: 0.484375, y: 0.328125 }, - { x: 0.484375, y: 0.328125 }, - { x: 0.515625, y: 0.328125 }, - { x: 0.515625, y: 0.328125 }, - { x: 0.546875, y: 0.328125 }, - { x: 0.546875, y: 0.328125 }, - { x: 0.578125, y: 0.328125 }, - { x: 0.578125, y: 0.328125 }, - { x: 0.609375, y: 0.328125 }, - { x: 0.609375, y: 0.328125 }, - { x: 0.640625, y: 0.328125 }, - { x: 0.640625, y: 0.328125 }, - { x: 0.671875, y: 0.328125 }, - { x: 0.671875, y: 0.328125 }, - { x: 0.703125, y: 0.328125 }, - { x: 0.703125, y: 0.328125 }, - { x: 0.734375, y: 0.328125 }, - { x: 0.734375, y: 0.328125 }, - { x: 0.765625, y: 0.328125 }, - { x: 0.765625, y: 0.328125 }, - { x: 0.796875, y: 0.328125 }, - { x: 0.796875, y: 0.328125 }, - { x: 0.828125, y: 0.328125 }, - { x: 0.828125, y: 0.328125 }, - { x: 0.859375, y: 0.328125 }, - { x: 0.859375, y: 0.328125 }, - { x: 0.890625, y: 0.328125 }, - { x: 0.890625, y: 0.328125 }, - { x: 0.921875, y: 0.328125 }, - { x: 0.921875, y: 0.328125 }, - { x: 0.953125, y: 0.328125 }, - { x: 0.953125, y: 0.328125 }, - { x: 0.984375, y: 0.328125 }, - { x: 0.984375, y: 0.328125 }, - { x: 0.015625, y: 0.359375 }, - { x: 0.015625, y: 0.359375 }, - { x: 0.046875, y: 0.359375 }, - { x: 0.046875, y: 0.359375 }, - { x: 0.078125, y: 0.359375 }, - { x: 0.078125, y: 0.359375 }, - { x: 0.109375, y: 0.359375 }, - { x: 0.109375, y: 0.359375 }, - { x: 0.140625, y: 0.359375 }, - { x: 0.140625, y: 0.359375 }, - { x: 0.171875, y: 0.359375 }, - { x: 0.171875, y: 0.359375 }, - { x: 0.203125, y: 0.359375 }, - { x: 0.203125, y: 0.359375 }, - { x: 0.234375, y: 0.359375 }, - { x: 0.234375, y: 0.359375 }, - { x: 0.265625, y: 0.359375 }, - { x: 0.265625, y: 0.359375 }, - { x: 0.296875, y: 0.359375 }, - { x: 0.296875, y: 0.359375 }, - { x: 0.328125, y: 0.359375 }, - { x: 0.328125, y: 0.359375 }, - { x: 0.359375, y: 0.359375 }, - { x: 0.359375, y: 0.359375 }, - { x: 0.390625, y: 0.359375 }, - { x: 0.390625, y: 0.359375 }, - { x: 0.421875, y: 0.359375 }, - { x: 0.421875, y: 0.359375 }, - { x: 0.453125, y: 0.359375 }, - { x: 0.453125, y: 0.359375 }, - { x: 0.484375, y: 0.359375 }, - { x: 0.484375, y: 0.359375 }, - { x: 0.515625, y: 0.359375 }, - { x: 0.515625, y: 0.359375 }, - { x: 0.546875, y: 0.359375 }, - { x: 0.546875, y: 0.359375 }, - { x: 0.578125, y: 0.359375 }, - { x: 0.578125, y: 0.359375 }, - { x: 0.609375, y: 0.359375 }, - { x: 0.609375, y: 0.359375 }, - { x: 0.640625, y: 0.359375 }, - { x: 0.640625, y: 0.359375 }, - { x: 0.671875, y: 0.359375 }, - { x: 0.671875, y: 0.359375 }, - { x: 0.703125, y: 0.359375 }, - { x: 0.703125, y: 0.359375 }, - { x: 0.734375, y: 0.359375 }, - { x: 0.734375, y: 0.359375 }, - { x: 0.765625, y: 0.359375 }, - { x: 0.765625, y: 0.359375 }, - { x: 0.796875, y: 0.359375 }, - { x: 0.796875, y: 0.359375 }, - { x: 0.828125, y: 0.359375 }, - { x: 0.828125, y: 0.359375 }, - { x: 0.859375, y: 0.359375 }, - { x: 0.859375, y: 0.359375 }, - { x: 0.890625, y: 0.359375 }, - { x: 0.890625, y: 0.359375 }, - { x: 0.921875, y: 0.359375 }, - { x: 0.921875, y: 0.359375 }, - { x: 0.953125, y: 0.359375 }, - { x: 0.953125, y: 0.359375 }, - { x: 0.984375, y: 0.359375 }, - { x: 0.984375, y: 0.359375 }, - { x: 0.015625, y: 0.390625 }, - { x: 0.015625, y: 0.390625 }, - { x: 0.046875, y: 0.390625 }, - { x: 0.046875, y: 0.390625 }, - { x: 0.078125, y: 0.390625 }, - { x: 0.078125, y: 0.390625 }, - { x: 0.109375, y: 0.390625 }, - { x: 0.109375, y: 0.390625 }, - { x: 0.140625, y: 0.390625 }, - { x: 0.140625, y: 0.390625 }, - { x: 0.171875, y: 0.390625 }, - { x: 0.171875, y: 0.390625 }, - { x: 0.203125, y: 0.390625 }, - { x: 0.203125, y: 0.390625 }, - { x: 0.234375, y: 0.390625 }, - { x: 0.234375, y: 0.390625 }, - { x: 0.265625, y: 0.390625 }, - { x: 0.265625, y: 0.390625 }, - { x: 0.296875, y: 0.390625 }, - { x: 0.296875, y: 0.390625 }, - { x: 0.328125, y: 0.390625 }, - { x: 0.328125, y: 0.390625 }, - { x: 0.359375, y: 0.390625 }, - { x: 0.359375, y: 0.390625 }, - { x: 0.390625, y: 0.390625 }, - { x: 0.390625, y: 0.390625 }, - { x: 0.421875, y: 0.390625 }, - { x: 0.421875, y: 0.390625 }, - { x: 0.453125, y: 0.390625 }, - { x: 0.453125, y: 0.390625 }, - { x: 0.484375, y: 0.390625 }, - { x: 0.484375, y: 0.390625 }, - { x: 0.515625, y: 0.390625 }, - { x: 0.515625, y: 0.390625 }, - { x: 0.546875, y: 0.390625 }, - { x: 0.546875, y: 0.390625 }, - { x: 0.578125, y: 0.390625 }, - { x: 0.578125, y: 0.390625 }, - { x: 0.609375, y: 0.390625 }, - { x: 0.609375, y: 0.390625 }, - { x: 0.640625, y: 0.390625 }, - { x: 0.640625, y: 0.390625 }, - { x: 0.671875, y: 0.390625 }, - { x: 0.671875, y: 0.390625 }, - { x: 0.703125, y: 0.390625 }, - { x: 0.703125, y: 0.390625 }, - { x: 0.734375, y: 0.390625 }, - { x: 0.734375, y: 0.390625 }, - { x: 0.765625, y: 0.390625 }, - { x: 0.765625, y: 0.390625 }, - { x: 0.796875, y: 0.390625 }, - { x: 0.796875, y: 0.390625 }, - { x: 0.828125, y: 0.390625 }, - { x: 0.828125, y: 0.390625 }, - { x: 0.859375, y: 0.390625 }, - { x: 0.859375, y: 0.390625 }, - { x: 0.890625, y: 0.390625 }, - { x: 0.890625, y: 0.390625 }, - { x: 0.921875, y: 0.390625 }, - { x: 0.921875, y: 0.390625 }, - { x: 0.953125, y: 0.390625 }, - { x: 0.953125, y: 0.390625 }, - { x: 0.984375, y: 0.390625 }, - { x: 0.984375, y: 0.390625 }, - { x: 0.015625, y: 0.421875 }, - { x: 0.015625, y: 0.421875 }, - { x: 0.046875, y: 0.421875 }, - { x: 0.046875, y: 0.421875 }, - { x: 0.078125, y: 0.421875 }, - { x: 0.078125, y: 0.421875 }, - { x: 0.109375, y: 0.421875 }, - { x: 0.109375, y: 0.421875 }, - { x: 0.140625, y: 0.421875 }, - { x: 0.140625, y: 0.421875 }, - { x: 0.171875, y: 0.421875 }, - { x: 0.171875, y: 0.421875 }, - { x: 0.203125, y: 0.421875 }, - { x: 0.203125, y: 0.421875 }, - { x: 0.234375, y: 0.421875 }, - { x: 0.234375, y: 0.421875 }, - { x: 0.265625, y: 0.421875 }, - { x: 0.265625, y: 0.421875 }, - { x: 0.296875, y: 0.421875 }, - { x: 0.296875, y: 0.421875 }, - { x: 0.328125, y: 0.421875 }, - { x: 0.328125, y: 0.421875 }, - { x: 0.359375, y: 0.421875 }, - { x: 0.359375, y: 0.421875 }, - { x: 0.390625, y: 0.421875 }, - { x: 0.390625, y: 0.421875 }, - { x: 0.421875, y: 0.421875 }, - { x: 0.421875, y: 0.421875 }, - { x: 0.453125, y: 0.421875 }, - { x: 0.453125, y: 0.421875 }, - { x: 0.484375, y: 0.421875 }, - { x: 0.484375, y: 0.421875 }, - { x: 0.515625, y: 0.421875 }, - { x: 0.515625, y: 0.421875 }, - { x: 0.546875, y: 0.421875 }, - { x: 0.546875, y: 0.421875 }, - { x: 0.578125, y: 0.421875 }, - { x: 0.578125, y: 0.421875 }, - { x: 0.609375, y: 0.421875 }, - { x: 0.609375, y: 0.421875 }, - { x: 0.640625, y: 0.421875 }, - { x: 0.640625, y: 0.421875 }, - { x: 0.671875, y: 0.421875 }, - { x: 0.671875, y: 0.421875 }, - { x: 0.703125, y: 0.421875 }, - { x: 0.703125, y: 0.421875 }, - { x: 0.734375, y: 0.421875 }, - { x: 0.734375, y: 0.421875 }, - { x: 0.765625, y: 0.421875 }, - { x: 0.765625, y: 0.421875 }, - { x: 0.796875, y: 0.421875 }, - { x: 0.796875, y: 0.421875 }, - { x: 0.828125, y: 0.421875 }, - { x: 0.828125, y: 0.421875 }, - { x: 0.859375, y: 0.421875 }, - { x: 0.859375, y: 0.421875 }, - { x: 0.890625, y: 0.421875 }, - { x: 0.890625, y: 0.421875 }, - { x: 0.921875, y: 0.421875 }, - { x: 0.921875, y: 0.421875 }, - { x: 0.953125, y: 0.421875 }, - { x: 0.953125, y: 0.421875 }, - { x: 0.984375, y: 0.421875 }, - { x: 0.984375, y: 0.421875 }, - { x: 0.015625, y: 0.453125 }, - { x: 0.015625, y: 0.453125 }, - { x: 0.046875, y: 0.453125 }, - { x: 0.046875, y: 0.453125 }, - { x: 0.078125, y: 0.453125 }, - { x: 0.078125, y: 0.453125 }, - { x: 0.109375, y: 0.453125 }, - { x: 0.109375, y: 0.453125 }, - { x: 0.140625, y: 0.453125 }, - { x: 0.140625, y: 0.453125 }, - { x: 0.171875, y: 0.453125 }, - { x: 0.171875, y: 0.453125 }, - { x: 0.203125, y: 0.453125 }, - { x: 0.203125, y: 0.453125 }, - { x: 0.234375, y: 0.453125 }, - { x: 0.234375, y: 0.453125 }, - { x: 0.265625, y: 0.453125 }, - { x: 0.265625, y: 0.453125 }, - { x: 0.296875, y: 0.453125 }, - { x: 0.296875, y: 0.453125 }, - { x: 0.328125, y: 0.453125 }, - { x: 0.328125, y: 0.453125 }, - { x: 0.359375, y: 0.453125 }, - { x: 0.359375, y: 0.453125 }, - { x: 0.390625, y: 0.453125 }, - { x: 0.390625, y: 0.453125 }, - { x: 0.421875, y: 0.453125 }, - { x: 0.421875, y: 0.453125 }, - { x: 0.453125, y: 0.453125 }, - { x: 0.453125, y: 0.453125 }, - { x: 0.484375, y: 0.453125 }, - { x: 0.484375, y: 0.453125 }, - { x: 0.515625, y: 0.453125 }, - { x: 0.515625, y: 0.453125 }, - { x: 0.546875, y: 0.453125 }, - { x: 0.546875, y: 0.453125 }, - { x: 0.578125, y: 0.453125 }, - { x: 0.578125, y: 0.453125 }, - { x: 0.609375, y: 0.453125 }, - { x: 0.609375, y: 0.453125 }, - { x: 0.640625, y: 0.453125 }, - { x: 0.640625, y: 0.453125 }, - { x: 0.671875, y: 0.453125 }, - { x: 0.671875, y: 0.453125 }, - { x: 0.703125, y: 0.453125 }, - { x: 0.703125, y: 0.453125 }, - { x: 0.734375, y: 0.453125 }, - { x: 0.734375, y: 0.453125 }, - { x: 0.765625, y: 0.453125 }, - { x: 0.765625, y: 0.453125 }, - { x: 0.796875, y: 0.453125 }, - { x: 0.796875, y: 0.453125 }, - { x: 0.828125, y: 0.453125 }, - { x: 0.828125, y: 0.453125 }, - { x: 0.859375, y: 0.453125 }, - { x: 0.859375, y: 0.453125 }, - { x: 0.890625, y: 0.453125 }, - { x: 0.890625, y: 0.453125 }, - { x: 0.921875, y: 0.453125 }, - { x: 0.921875, y: 0.453125 }, - { x: 0.953125, y: 0.453125 }, - { x: 0.953125, y: 0.453125 }, - { x: 0.984375, y: 0.453125 }, - { x: 0.984375, y: 0.453125 }, - { x: 0.015625, y: 0.484375 }, - { x: 0.015625, y: 0.484375 }, - { x: 0.046875, y: 0.484375 }, - { x: 0.046875, y: 0.484375 }, - { x: 0.078125, y: 0.484375 }, - { x: 0.078125, y: 0.484375 }, - { x: 0.109375, y: 0.484375 }, - { x: 0.109375, y: 0.484375 }, - { x: 0.140625, y: 0.484375 }, - { x: 0.140625, y: 0.484375 }, - { x: 0.171875, y: 0.484375 }, - { x: 0.171875, y: 0.484375 }, - { x: 0.203125, y: 0.484375 }, - { x: 0.203125, y: 0.484375 }, - { x: 0.234375, y: 0.484375 }, - { x: 0.234375, y: 0.484375 }, - { x: 0.265625, y: 0.484375 }, - { x: 0.265625, y: 0.484375 }, - { x: 0.296875, y: 0.484375 }, - { x: 0.296875, y: 0.484375 }, - { x: 0.328125, y: 0.484375 }, - { x: 0.328125, y: 0.484375 }, - { x: 0.359375, y: 0.484375 }, - { x: 0.359375, y: 0.484375 }, - { x: 0.390625, y: 0.484375 }, - { x: 0.390625, y: 0.484375 }, - { x: 0.421875, y: 0.484375 }, - { x: 0.421875, y: 0.484375 }, - { x: 0.453125, y: 0.484375 }, - { x: 0.453125, y: 0.484375 }, - { x: 0.484375, y: 0.484375 }, - { x: 0.484375, y: 0.484375 }, - { x: 0.515625, y: 0.484375 }, - { x: 0.515625, y: 0.484375 }, - { x: 0.546875, y: 0.484375 }, - { x: 0.546875, y: 0.484375 }, - { x: 0.578125, y: 0.484375 }, - { x: 0.578125, y: 0.484375 }, - { x: 0.609375, y: 0.484375 }, - { x: 0.609375, y: 0.484375 }, - { x: 0.640625, y: 0.484375 }, - { x: 0.640625, y: 0.484375 }, - { x: 0.671875, y: 0.484375 }, - { x: 0.671875, y: 0.484375 }, - { x: 0.703125, y: 0.484375 }, - { x: 0.703125, y: 0.484375 }, - { x: 0.734375, y: 0.484375 }, - { x: 0.734375, y: 0.484375 }, - { x: 0.765625, y: 0.484375 }, - { x: 0.765625, y: 0.484375 }, - { x: 0.796875, y: 0.484375 }, - { x: 0.796875, y: 0.484375 }, - { x: 0.828125, y: 0.484375 }, - { x: 0.828125, y: 0.484375 }, - { x: 0.859375, y: 0.484375 }, - { x: 0.859375, y: 0.484375 }, - { x: 0.890625, y: 0.484375 }, - { x: 0.890625, y: 0.484375 }, - { x: 0.921875, y: 0.484375 }, - { x: 0.921875, y: 0.484375 }, - { x: 0.953125, y: 0.484375 }, - { x: 0.953125, y: 0.484375 }, - { x: 0.984375, y: 0.484375 }, - { x: 0.984375, y: 0.484375 }, - { x: 0.015625, y: 0.515625 }, - { x: 0.015625, y: 0.515625 }, - { x: 0.046875, y: 0.515625 }, - { x: 0.046875, y: 0.515625 }, - { x: 0.078125, y: 0.515625 }, - { x: 0.078125, y: 0.515625 }, - { x: 0.109375, y: 0.515625 }, - { x: 0.109375, y: 0.515625 }, - { x: 0.140625, y: 0.515625 }, - { x: 0.140625, y: 0.515625 }, - { x: 0.171875, y: 0.515625 }, - { x: 0.171875, y: 0.515625 }, - { x: 0.203125, y: 0.515625 }, - { x: 0.203125, y: 0.515625 }, - { x: 0.234375, y: 0.515625 }, - { x: 0.234375, y: 0.515625 }, - { x: 0.265625, y: 0.515625 }, - { x: 0.265625, y: 0.515625 }, - { x: 0.296875, y: 0.515625 }, - { x: 0.296875, y: 0.515625 }, - { x: 0.328125, y: 0.515625 }, - { x: 0.328125, y: 0.515625 }, - { x: 0.359375, y: 0.515625 }, - { x: 0.359375, y: 0.515625 }, - { x: 0.390625, y: 0.515625 }, - { x: 0.390625, y: 0.515625 }, - { x: 0.421875, y: 0.515625 }, - { x: 0.421875, y: 0.515625 }, - { x: 0.453125, y: 0.515625 }, - { x: 0.453125, y: 0.515625 }, - { x: 0.484375, y: 0.515625 }, - { x: 0.484375, y: 0.515625 }, - { x: 0.515625, y: 0.515625 }, - { x: 0.515625, y: 0.515625 }, - { x: 0.546875, y: 0.515625 }, - { x: 0.546875, y: 0.515625 }, - { x: 0.578125, y: 0.515625 }, - { x: 0.578125, y: 0.515625 }, - { x: 0.609375, y: 0.515625 }, - { x: 0.609375, y: 0.515625 }, - { x: 0.640625, y: 0.515625 }, - { x: 0.640625, y: 0.515625 }, - { x: 0.671875, y: 0.515625 }, - { x: 0.671875, y: 0.515625 }, - { x: 0.703125, y: 0.515625 }, - { x: 0.703125, y: 0.515625 }, - { x: 0.734375, y: 0.515625 }, - { x: 0.734375, y: 0.515625 }, - { x: 0.765625, y: 0.515625 }, - { x: 0.765625, y: 0.515625 }, - { x: 0.796875, y: 0.515625 }, - { x: 0.796875, y: 0.515625 }, - { x: 0.828125, y: 0.515625 }, - { x: 0.828125, y: 0.515625 }, - { x: 0.859375, y: 0.515625 }, - { x: 0.859375, y: 0.515625 }, - { x: 0.890625, y: 0.515625 }, - { x: 0.890625, y: 0.515625 }, - { x: 0.921875, y: 0.515625 }, - { x: 0.921875, y: 0.515625 }, - { x: 0.953125, y: 0.515625 }, - { x: 0.953125, y: 0.515625 }, - { x: 0.984375, y: 0.515625 }, - { x: 0.984375, y: 0.515625 }, - { x: 0.015625, y: 0.546875 }, - { x: 0.015625, y: 0.546875 }, - { x: 0.046875, y: 0.546875 }, - { x: 0.046875, y: 0.546875 }, - { x: 0.078125, y: 0.546875 }, - { x: 0.078125, y: 0.546875 }, - { x: 0.109375, y: 0.546875 }, - { x: 0.109375, y: 0.546875 }, - { x: 0.140625, y: 0.546875 }, - { x: 0.140625, y: 0.546875 }, - { x: 0.171875, y: 0.546875 }, - { x: 0.171875, y: 0.546875 }, - { x: 0.203125, y: 0.546875 }, - { x: 0.203125, y: 0.546875 }, - { x: 0.234375, y: 0.546875 }, - { x: 0.234375, y: 0.546875 }, - { x: 0.265625, y: 0.546875 }, - { x: 0.265625, y: 0.546875 }, - { x: 0.296875, y: 0.546875 }, - { x: 0.296875, y: 0.546875 }, - { x: 0.328125, y: 0.546875 }, - { x: 0.328125, y: 0.546875 }, - { x: 0.359375, y: 0.546875 }, - { x: 0.359375, y: 0.546875 }, - { x: 0.390625, y: 0.546875 }, - { x: 0.390625, y: 0.546875 }, - { x: 0.421875, y: 0.546875 }, - { x: 0.421875, y: 0.546875 }, - { x: 0.453125, y: 0.546875 }, - { x: 0.453125, y: 0.546875 }, - { x: 0.484375, y: 0.546875 }, - { x: 0.484375, y: 0.546875 }, - { x: 0.515625, y: 0.546875 }, - { x: 0.515625, y: 0.546875 }, - { x: 0.546875, y: 0.546875 }, - { x: 0.546875, y: 0.546875 }, - { x: 0.578125, y: 0.546875 }, - { x: 0.578125, y: 0.546875 }, - { x: 0.609375, y: 0.546875 }, - { x: 0.609375, y: 0.546875 }, - { x: 0.640625, y: 0.546875 }, - { x: 0.640625, y: 0.546875 }, - { x: 0.671875, y: 0.546875 }, - { x: 0.671875, y: 0.546875 }, - { x: 0.703125, y: 0.546875 }, - { x: 0.703125, y: 0.546875 }, - { x: 0.734375, y: 0.546875 }, - { x: 0.734375, y: 0.546875 }, - { x: 0.765625, y: 0.546875 }, - { x: 0.765625, y: 0.546875 }, - { x: 0.796875, y: 0.546875 }, - { x: 0.796875, y: 0.546875 }, - { x: 0.828125, y: 0.546875 }, - { x: 0.828125, y: 0.546875 }, - { x: 0.859375, y: 0.546875 }, - { x: 0.859375, y: 0.546875 }, - { x: 0.890625, y: 0.546875 }, - { x: 0.890625, y: 0.546875 }, - { x: 0.921875, y: 0.546875 }, - { x: 0.921875, y: 0.546875 }, - { x: 0.953125, y: 0.546875 }, - { x: 0.953125, y: 0.546875 }, - { x: 0.984375, y: 0.546875 }, - { x: 0.984375, y: 0.546875 }, - { x: 0.015625, y: 0.578125 }, - { x: 0.015625, y: 0.578125 }, - { x: 0.046875, y: 0.578125 }, - { x: 0.046875, y: 0.578125 }, - { x: 0.078125, y: 0.578125 }, - { x: 0.078125, y: 0.578125 }, - { x: 0.109375, y: 0.578125 }, - { x: 0.109375, y: 0.578125 }, - { x: 0.140625, y: 0.578125 }, - { x: 0.140625, y: 0.578125 }, - { x: 0.171875, y: 0.578125 }, - { x: 0.171875, y: 0.578125 }, - { x: 0.203125, y: 0.578125 }, - { x: 0.203125, y: 0.578125 }, - { x: 0.234375, y: 0.578125 }, - { x: 0.234375, y: 0.578125 }, - { x: 0.265625, y: 0.578125 }, - { x: 0.265625, y: 0.578125 }, - { x: 0.296875, y: 0.578125 }, - { x: 0.296875, y: 0.578125 }, - { x: 0.328125, y: 0.578125 }, - { x: 0.328125, y: 0.578125 }, - { x: 0.359375, y: 0.578125 }, - { x: 0.359375, y: 0.578125 }, - { x: 0.390625, y: 0.578125 }, - { x: 0.390625, y: 0.578125 }, - { x: 0.421875, y: 0.578125 }, - { x: 0.421875, y: 0.578125 }, - { x: 0.453125, y: 0.578125 }, - { x: 0.453125, y: 0.578125 }, - { x: 0.484375, y: 0.578125 }, - { x: 0.484375, y: 0.578125 }, - { x: 0.515625, y: 0.578125 }, - { x: 0.515625, y: 0.578125 }, - { x: 0.546875, y: 0.578125 }, - { x: 0.546875, y: 0.578125 }, - { x: 0.578125, y: 0.578125 }, - { x: 0.578125, y: 0.578125 }, - { x: 0.609375, y: 0.578125 }, - { x: 0.609375, y: 0.578125 }, - { x: 0.640625, y: 0.578125 }, - { x: 0.640625, y: 0.578125 }, - { x: 0.671875, y: 0.578125 }, - { x: 0.671875, y: 0.578125 }, - { x: 0.703125, y: 0.578125 }, - { x: 0.703125, y: 0.578125 }, - { x: 0.734375, y: 0.578125 }, - { x: 0.734375, y: 0.578125 }, - { x: 0.765625, y: 0.578125 }, - { x: 0.765625, y: 0.578125 }, - { x: 0.796875, y: 0.578125 }, - { x: 0.796875, y: 0.578125 }, - { x: 0.828125, y: 0.578125 }, - { x: 0.828125, y: 0.578125 }, - { x: 0.859375, y: 0.578125 }, - { x: 0.859375, y: 0.578125 }, - { x: 0.890625, y: 0.578125 }, - { x: 0.890625, y: 0.578125 }, - { x: 0.921875, y: 0.578125 }, - { x: 0.921875, y: 0.578125 }, - { x: 0.953125, y: 0.578125 }, - { x: 0.953125, y: 0.578125 }, - { x: 0.984375, y: 0.578125 }, - { x: 0.984375, y: 0.578125 }, - { x: 0.015625, y: 0.609375 }, - { x: 0.015625, y: 0.609375 }, - { x: 0.046875, y: 0.609375 }, - { x: 0.046875, y: 0.609375 }, - { x: 0.078125, y: 0.609375 }, - { x: 0.078125, y: 0.609375 }, - { x: 0.109375, y: 0.609375 }, - { x: 0.109375, y: 0.609375 }, - { x: 0.140625, y: 0.609375 }, - { x: 0.140625, y: 0.609375 }, - { x: 0.171875, y: 0.609375 }, - { x: 0.171875, y: 0.609375 }, - { x: 0.203125, y: 0.609375 }, - { x: 0.203125, y: 0.609375 }, - { x: 0.234375, y: 0.609375 }, - { x: 0.234375, y: 0.609375 }, - { x: 0.265625, y: 0.609375 }, - { x: 0.265625, y: 0.609375 }, - { x: 0.296875, y: 0.609375 }, - { x: 0.296875, y: 0.609375 }, - { x: 0.328125, y: 0.609375 }, - { x: 0.328125, y: 0.609375 }, - { x: 0.359375, y: 0.609375 }, - { x: 0.359375, y: 0.609375 }, - { x: 0.390625, y: 0.609375 }, - { x: 0.390625, y: 0.609375 }, - { x: 0.421875, y: 0.609375 }, - { x: 0.421875, y: 0.609375 }, - { x: 0.453125, y: 0.609375 }, - { x: 0.453125, y: 0.609375 }, - { x: 0.484375, y: 0.609375 }, - { x: 0.484375, y: 0.609375 }, - { x: 0.515625, y: 0.609375 }, - { x: 0.515625, y: 0.609375 }, - { x: 0.546875, y: 0.609375 }, - { x: 0.546875, y: 0.609375 }, - { x: 0.578125, y: 0.609375 }, - { x: 0.578125, y: 0.609375 }, - { x: 0.609375, y: 0.609375 }, - { x: 0.609375, y: 0.609375 }, - { x: 0.640625, y: 0.609375 }, - { x: 0.640625, y: 0.609375 }, - { x: 0.671875, y: 0.609375 }, - { x: 0.671875, y: 0.609375 }, - { x: 0.703125, y: 0.609375 }, - { x: 0.703125, y: 0.609375 }, - { x: 0.734375, y: 0.609375 }, - { x: 0.734375, y: 0.609375 }, - { x: 0.765625, y: 0.609375 }, - { x: 0.765625, y: 0.609375 }, - { x: 0.796875, y: 0.609375 }, - { x: 0.796875, y: 0.609375 }, - { x: 0.828125, y: 0.609375 }, - { x: 0.828125, y: 0.609375 }, - { x: 0.859375, y: 0.609375 }, - { x: 0.859375, y: 0.609375 }, - { x: 0.890625, y: 0.609375 }, - { x: 0.890625, y: 0.609375 }, - { x: 0.921875, y: 0.609375 }, - { x: 0.921875, y: 0.609375 }, - { x: 0.953125, y: 0.609375 }, - { x: 0.953125, y: 0.609375 }, - { x: 0.984375, y: 0.609375 }, - { x: 0.984375, y: 0.609375 }, - { x: 0.015625, y: 0.640625 }, - { x: 0.015625, y: 0.640625 }, - { x: 0.046875, y: 0.640625 }, - { x: 0.046875, y: 0.640625 }, - { x: 0.078125, y: 0.640625 }, - { x: 0.078125, y: 0.640625 }, - { x: 0.109375, y: 0.640625 }, - { x: 0.109375, y: 0.640625 }, - { x: 0.140625, y: 0.640625 }, - { x: 0.140625, y: 0.640625 }, - { x: 0.171875, y: 0.640625 }, - { x: 0.171875, y: 0.640625 }, - { x: 0.203125, y: 0.640625 }, - { x: 0.203125, y: 0.640625 }, - { x: 0.234375, y: 0.640625 }, - { x: 0.234375, y: 0.640625 }, - { x: 0.265625, y: 0.640625 }, - { x: 0.265625, y: 0.640625 }, - { x: 0.296875, y: 0.640625 }, - { x: 0.296875, y: 0.640625 }, - { x: 0.328125, y: 0.640625 }, - { x: 0.328125, y: 0.640625 }, - { x: 0.359375, y: 0.640625 }, - { x: 0.359375, y: 0.640625 }, - { x: 0.390625, y: 0.640625 }, - { x: 0.390625, y: 0.640625 }, - { x: 0.421875, y: 0.640625 }, - { x: 0.421875, y: 0.640625 }, - { x: 0.453125, y: 0.640625 }, - { x: 0.453125, y: 0.640625 }, - { x: 0.484375, y: 0.640625 }, - { x: 0.484375, y: 0.640625 }, - { x: 0.515625, y: 0.640625 }, - { x: 0.515625, y: 0.640625 }, - { x: 0.546875, y: 0.640625 }, - { x: 0.546875, y: 0.640625 }, - { x: 0.578125, y: 0.640625 }, - { x: 0.578125, y: 0.640625 }, - { x: 0.609375, y: 0.640625 }, - { x: 0.609375, y: 0.640625 }, - { x: 0.640625, y: 0.640625 }, - { x: 0.640625, y: 0.640625 }, - { x: 0.671875, y: 0.640625 }, - { x: 0.671875, y: 0.640625 }, - { x: 0.703125, y: 0.640625 }, - { x: 0.703125, y: 0.640625 }, - { x: 0.734375, y: 0.640625 }, - { x: 0.734375, y: 0.640625 }, - { x: 0.765625, y: 0.640625 }, - { x: 0.765625, y: 0.640625 }, - { x: 0.796875, y: 0.640625 }, - { x: 0.796875, y: 0.640625 }, - { x: 0.828125, y: 0.640625 }, - { x: 0.828125, y: 0.640625 }, - { x: 0.859375, y: 0.640625 }, - { x: 0.859375, y: 0.640625 }, - { x: 0.890625, y: 0.640625 }, - { x: 0.890625, y: 0.640625 }, - { x: 0.921875, y: 0.640625 }, - { x: 0.921875, y: 0.640625 }, - { x: 0.953125, y: 0.640625 }, - { x: 0.953125, y: 0.640625 }, - { x: 0.984375, y: 0.640625 }, - { x: 0.984375, y: 0.640625 }, - { x: 0.015625, y: 0.671875 }, - { x: 0.015625, y: 0.671875 }, - { x: 0.046875, y: 0.671875 }, - { x: 0.046875, y: 0.671875 }, - { x: 0.078125, y: 0.671875 }, - { x: 0.078125, y: 0.671875 }, - { x: 0.109375, y: 0.671875 }, - { x: 0.109375, y: 0.671875 }, - { x: 0.140625, y: 0.671875 }, - { x: 0.140625, y: 0.671875 }, - { x: 0.171875, y: 0.671875 }, - { x: 0.171875, y: 0.671875 }, - { x: 0.203125, y: 0.671875 }, - { x: 0.203125, y: 0.671875 }, - { x: 0.234375, y: 0.671875 }, - { x: 0.234375, y: 0.671875 }, - { x: 0.265625, y: 0.671875 }, - { x: 0.265625, y: 0.671875 }, - { x: 0.296875, y: 0.671875 }, - { x: 0.296875, y: 0.671875 }, - { x: 0.328125, y: 0.671875 }, - { x: 0.328125, y: 0.671875 }, - { x: 0.359375, y: 0.671875 }, - { x: 0.359375, y: 0.671875 }, - { x: 0.390625, y: 0.671875 }, - { x: 0.390625, y: 0.671875 }, - { x: 0.421875, y: 0.671875 }, - { x: 0.421875, y: 0.671875 }, - { x: 0.453125, y: 0.671875 }, - { x: 0.453125, y: 0.671875 }, - { x: 0.484375, y: 0.671875 }, - { x: 0.484375, y: 0.671875 }, - { x: 0.515625, y: 0.671875 }, - { x: 0.515625, y: 0.671875 }, - { x: 0.546875, y: 0.671875 }, - { x: 0.546875, y: 0.671875 }, - { x: 0.578125, y: 0.671875 }, - { x: 0.578125, y: 0.671875 }, - { x: 0.609375, y: 0.671875 }, - { x: 0.609375, y: 0.671875 }, - { x: 0.640625, y: 0.671875 }, - { x: 0.640625, y: 0.671875 }, - { x: 0.671875, y: 0.671875 }, - { x: 0.671875, y: 0.671875 }, - { x: 0.703125, y: 0.671875 }, - { x: 0.703125, y: 0.671875 }, - { x: 0.734375, y: 0.671875 }, - { x: 0.734375, y: 0.671875 }, - { x: 0.765625, y: 0.671875 }, - { x: 0.765625, y: 0.671875 }, - { x: 0.796875, y: 0.671875 }, - { x: 0.796875, y: 0.671875 }, - { x: 0.828125, y: 0.671875 }, - { x: 0.828125, y: 0.671875 }, - { x: 0.859375, y: 0.671875 }, - { x: 0.859375, y: 0.671875 }, - { x: 0.890625, y: 0.671875 }, - { x: 0.890625, y: 0.671875 }, - { x: 0.921875, y: 0.671875 }, - { x: 0.921875, y: 0.671875 }, - { x: 0.953125, y: 0.671875 }, - { x: 0.953125, y: 0.671875 }, - { x: 0.984375, y: 0.671875 }, - { x: 0.984375, y: 0.671875 }, - { x: 0.015625, y: 0.703125 }, - { x: 0.015625, y: 0.703125 }, - { x: 0.046875, y: 0.703125 }, - { x: 0.046875, y: 0.703125 }, - { x: 0.078125, y: 0.703125 }, - { x: 0.078125, y: 0.703125 }, - { x: 0.109375, y: 0.703125 }, - { x: 0.109375, y: 0.703125 }, - { x: 0.140625, y: 0.703125 }, - { x: 0.140625, y: 0.703125 }, - { x: 0.171875, y: 0.703125 }, - { x: 0.171875, y: 0.703125 }, - { x: 0.203125, y: 0.703125 }, - { x: 0.203125, y: 0.703125 }, - { x: 0.234375, y: 0.703125 }, - { x: 0.234375, y: 0.703125 }, - { x: 0.265625, y: 0.703125 }, - { x: 0.265625, y: 0.703125 }, - { x: 0.296875, y: 0.703125 }, - { x: 0.296875, y: 0.703125 }, - { x: 0.328125, y: 0.703125 }, - { x: 0.328125, y: 0.703125 }, - { x: 0.359375, y: 0.703125 }, - { x: 0.359375, y: 0.703125 }, - { x: 0.390625, y: 0.703125 }, - { x: 0.390625, y: 0.703125 }, - { x: 0.421875, y: 0.703125 }, - { x: 0.421875, y: 0.703125 }, - { x: 0.453125, y: 0.703125 }, - { x: 0.453125, y: 0.703125 }, - { x: 0.484375, y: 0.703125 }, - { x: 0.484375, y: 0.703125 }, - { x: 0.515625, y: 0.703125 }, - { x: 0.515625, y: 0.703125 }, - { x: 0.546875, y: 0.703125 }, - { x: 0.546875, y: 0.703125 }, - { x: 0.578125, y: 0.703125 }, - { x: 0.578125, y: 0.703125 }, - { x: 0.609375, y: 0.703125 }, - { x: 0.609375, y: 0.703125 }, - { x: 0.640625, y: 0.703125 }, - { x: 0.640625, y: 0.703125 }, - { x: 0.671875, y: 0.703125 }, - { x: 0.671875, y: 0.703125 }, - { x: 0.703125, y: 0.703125 }, - { x: 0.703125, y: 0.703125 }, - { x: 0.734375, y: 0.703125 }, - { x: 0.734375, y: 0.703125 }, - { x: 0.765625, y: 0.703125 }, - { x: 0.765625, y: 0.703125 }, - { x: 0.796875, y: 0.703125 }, - { x: 0.796875, y: 0.703125 }, - { x: 0.828125, y: 0.703125 }, - { x: 0.828125, y: 0.703125 }, - { x: 0.859375, y: 0.703125 }, - { x: 0.859375, y: 0.703125 }, - { x: 0.890625, y: 0.703125 }, - { x: 0.890625, y: 0.703125 }, - { x: 0.921875, y: 0.703125 }, - { x: 0.921875, y: 0.703125 }, - { x: 0.953125, y: 0.703125 }, - { x: 0.953125, y: 0.703125 }, - { x: 0.984375, y: 0.703125 }, - { x: 0.984375, y: 0.703125 }, - { x: 0.015625, y: 0.734375 }, - { x: 0.015625, y: 0.734375 }, - { x: 0.046875, y: 0.734375 }, - { x: 0.046875, y: 0.734375 }, - { x: 0.078125, y: 0.734375 }, - { x: 0.078125, y: 0.734375 }, - { x: 0.109375, y: 0.734375 }, - { x: 0.109375, y: 0.734375 }, - { x: 0.140625, y: 0.734375 }, - { x: 0.140625, y: 0.734375 }, - { x: 0.171875, y: 0.734375 }, - { x: 0.171875, y: 0.734375 }, - { x: 0.203125, y: 0.734375 }, - { x: 0.203125, y: 0.734375 }, - { x: 0.234375, y: 0.734375 }, - { x: 0.234375, y: 0.734375 }, - { x: 0.265625, y: 0.734375 }, - { x: 0.265625, y: 0.734375 }, - { x: 0.296875, y: 0.734375 }, - { x: 0.296875, y: 0.734375 }, - { x: 0.328125, y: 0.734375 }, - { x: 0.328125, y: 0.734375 }, - { x: 0.359375, y: 0.734375 }, - { x: 0.359375, y: 0.734375 }, - { x: 0.390625, y: 0.734375 }, - { x: 0.390625, y: 0.734375 }, - { x: 0.421875, y: 0.734375 }, - { x: 0.421875, y: 0.734375 }, - { x: 0.453125, y: 0.734375 }, - { x: 0.453125, y: 0.734375 }, - { x: 0.484375, y: 0.734375 }, - { x: 0.484375, y: 0.734375 }, - { x: 0.515625, y: 0.734375 }, - { x: 0.515625, y: 0.734375 }, - { x: 0.546875, y: 0.734375 }, - { x: 0.546875, y: 0.734375 }, - { x: 0.578125, y: 0.734375 }, - { x: 0.578125, y: 0.734375 }, - { x: 0.609375, y: 0.734375 }, - { x: 0.609375, y: 0.734375 }, - { x: 0.640625, y: 0.734375 }, - { x: 0.640625, y: 0.734375 }, - { x: 0.671875, y: 0.734375 }, - { x: 0.671875, y: 0.734375 }, - { x: 0.703125, y: 0.734375 }, - { x: 0.703125, y: 0.734375 }, - { x: 0.734375, y: 0.734375 }, - { x: 0.734375, y: 0.734375 }, - { x: 0.765625, y: 0.734375 }, - { x: 0.765625, y: 0.734375 }, - { x: 0.796875, y: 0.734375 }, - { x: 0.796875, y: 0.734375 }, - { x: 0.828125, y: 0.734375 }, - { x: 0.828125, y: 0.734375 }, - { x: 0.859375, y: 0.734375 }, - { x: 0.859375, y: 0.734375 }, - { x: 0.890625, y: 0.734375 }, - { x: 0.890625, y: 0.734375 }, - { x: 0.921875, y: 0.734375 }, - { x: 0.921875, y: 0.734375 }, - { x: 0.953125, y: 0.734375 }, - { x: 0.953125, y: 0.734375 }, - { x: 0.984375, y: 0.734375 }, - { x: 0.984375, y: 0.734375 }, - { x: 0.015625, y: 0.765625 }, - { x: 0.015625, y: 0.765625 }, - { x: 0.046875, y: 0.765625 }, - { x: 0.046875, y: 0.765625 }, - { x: 0.078125, y: 0.765625 }, - { x: 0.078125, y: 0.765625 }, - { x: 0.109375, y: 0.765625 }, - { x: 0.109375, y: 0.765625 }, - { x: 0.140625, y: 0.765625 }, - { x: 0.140625, y: 0.765625 }, - { x: 0.171875, y: 0.765625 }, - { x: 0.171875, y: 0.765625 }, - { x: 0.203125, y: 0.765625 }, - { x: 0.203125, y: 0.765625 }, - { x: 0.234375, y: 0.765625 }, - { x: 0.234375, y: 0.765625 }, - { x: 0.265625, y: 0.765625 }, - { x: 0.265625, y: 0.765625 }, - { x: 0.296875, y: 0.765625 }, - { x: 0.296875, y: 0.765625 }, - { x: 0.328125, y: 0.765625 }, - { x: 0.328125, y: 0.765625 }, - { x: 0.359375, y: 0.765625 }, - { x: 0.359375, y: 0.765625 }, - { x: 0.390625, y: 0.765625 }, - { x: 0.390625, y: 0.765625 }, - { x: 0.421875, y: 0.765625 }, - { x: 0.421875, y: 0.765625 }, - { x: 0.453125, y: 0.765625 }, - { x: 0.453125, y: 0.765625 }, - { x: 0.484375, y: 0.765625 }, - { x: 0.484375, y: 0.765625 }, - { x: 0.515625, y: 0.765625 }, - { x: 0.515625, y: 0.765625 }, - { x: 0.546875, y: 0.765625 }, - { x: 0.546875, y: 0.765625 }, - { x: 0.578125, y: 0.765625 }, - { x: 0.578125, y: 0.765625 }, - { x: 0.609375, y: 0.765625 }, - { x: 0.609375, y: 0.765625 }, - { x: 0.640625, y: 0.765625 }, - { x: 0.640625, y: 0.765625 }, - { x: 0.671875, y: 0.765625 }, - { x: 0.671875, y: 0.765625 }, - { x: 0.703125, y: 0.765625 }, - { x: 0.703125, y: 0.765625 }, - { x: 0.734375, y: 0.765625 }, - { x: 0.734375, y: 0.765625 }, - { x: 0.765625, y: 0.765625 }, - { x: 0.765625, y: 0.765625 }, - { x: 0.796875, y: 0.765625 }, - { x: 0.796875, y: 0.765625 }, - { x: 0.828125, y: 0.765625 }, - { x: 0.828125, y: 0.765625 }, - { x: 0.859375, y: 0.765625 }, - { x: 0.859375, y: 0.765625 }, - { x: 0.890625, y: 0.765625 }, - { x: 0.890625, y: 0.765625 }, - { x: 0.921875, y: 0.765625 }, - { x: 0.921875, y: 0.765625 }, - { x: 0.953125, y: 0.765625 }, - { x: 0.953125, y: 0.765625 }, - { x: 0.984375, y: 0.765625 }, - { x: 0.984375, y: 0.765625 }, - { x: 0.015625, y: 0.796875 }, - { x: 0.015625, y: 0.796875 }, - { x: 0.046875, y: 0.796875 }, - { x: 0.046875, y: 0.796875 }, - { x: 0.078125, y: 0.796875 }, - { x: 0.078125, y: 0.796875 }, - { x: 0.109375, y: 0.796875 }, - { x: 0.109375, y: 0.796875 }, - { x: 0.140625, y: 0.796875 }, - { x: 0.140625, y: 0.796875 }, - { x: 0.171875, y: 0.796875 }, - { x: 0.171875, y: 0.796875 }, - { x: 0.203125, y: 0.796875 }, - { x: 0.203125, y: 0.796875 }, - { x: 0.234375, y: 0.796875 }, - { x: 0.234375, y: 0.796875 }, - { x: 0.265625, y: 0.796875 }, - { x: 0.265625, y: 0.796875 }, - { x: 0.296875, y: 0.796875 }, - { x: 0.296875, y: 0.796875 }, - { x: 0.328125, y: 0.796875 }, - { x: 0.328125, y: 0.796875 }, - { x: 0.359375, y: 0.796875 }, - { x: 0.359375, y: 0.796875 }, - { x: 0.390625, y: 0.796875 }, - { x: 0.390625, y: 0.796875 }, - { x: 0.421875, y: 0.796875 }, - { x: 0.421875, y: 0.796875 }, - { x: 0.453125, y: 0.796875 }, - { x: 0.453125, y: 0.796875 }, - { x: 0.484375, y: 0.796875 }, - { x: 0.484375, y: 0.796875 }, - { x: 0.515625, y: 0.796875 }, - { x: 0.515625, y: 0.796875 }, - { x: 0.546875, y: 0.796875 }, - { x: 0.546875, y: 0.796875 }, - { x: 0.578125, y: 0.796875 }, - { x: 0.578125, y: 0.796875 }, - { x: 0.609375, y: 0.796875 }, - { x: 0.609375, y: 0.796875 }, - { x: 0.640625, y: 0.796875 }, - { x: 0.640625, y: 0.796875 }, - { x: 0.671875, y: 0.796875 }, - { x: 0.671875, y: 0.796875 }, - { x: 0.703125, y: 0.796875 }, - { x: 0.703125, y: 0.796875 }, - { x: 0.734375, y: 0.796875 }, - { x: 0.734375, y: 0.796875 }, - { x: 0.765625, y: 0.796875 }, - { x: 0.765625, y: 0.796875 }, - { x: 0.796875, y: 0.796875 }, - { x: 0.796875, y: 0.796875 }, - { x: 0.828125, y: 0.796875 }, - { x: 0.828125, y: 0.796875 }, - { x: 0.859375, y: 0.796875 }, - { x: 0.859375, y: 0.796875 }, - { x: 0.890625, y: 0.796875 }, - { x: 0.890625, y: 0.796875 }, - { x: 0.921875, y: 0.796875 }, - { x: 0.921875, y: 0.796875 }, - { x: 0.953125, y: 0.796875 }, - { x: 0.953125, y: 0.796875 }, - { x: 0.984375, y: 0.796875 }, - { x: 0.984375, y: 0.796875 }, - { x: 0.015625, y: 0.828125 }, - { x: 0.015625, y: 0.828125 }, - { x: 0.046875, y: 0.828125 }, - { x: 0.046875, y: 0.828125 }, - { x: 0.078125, y: 0.828125 }, - { x: 0.078125, y: 0.828125 }, - { x: 0.109375, y: 0.828125 }, - { x: 0.109375, y: 0.828125 }, - { x: 0.140625, y: 0.828125 }, - { x: 0.140625, y: 0.828125 }, - { x: 0.171875, y: 0.828125 }, - { x: 0.171875, y: 0.828125 }, - { x: 0.203125, y: 0.828125 }, - { x: 0.203125, y: 0.828125 }, - { x: 0.234375, y: 0.828125 }, - { x: 0.234375, y: 0.828125 }, - { x: 0.265625, y: 0.828125 }, - { x: 0.265625, y: 0.828125 }, - { x: 0.296875, y: 0.828125 }, - { x: 0.296875, y: 0.828125 }, - { x: 0.328125, y: 0.828125 }, - { x: 0.328125, y: 0.828125 }, - { x: 0.359375, y: 0.828125 }, - { x: 0.359375, y: 0.828125 }, - { x: 0.390625, y: 0.828125 }, - { x: 0.390625, y: 0.828125 }, - { x: 0.421875, y: 0.828125 }, - { x: 0.421875, y: 0.828125 }, - { x: 0.453125, y: 0.828125 }, - { x: 0.453125, y: 0.828125 }, - { x: 0.484375, y: 0.828125 }, - { x: 0.484375, y: 0.828125 }, - { x: 0.515625, y: 0.828125 }, - { x: 0.515625, y: 0.828125 }, - { x: 0.546875, y: 0.828125 }, - { x: 0.546875, y: 0.828125 }, - { x: 0.578125, y: 0.828125 }, - { x: 0.578125, y: 0.828125 }, - { x: 0.609375, y: 0.828125 }, - { x: 0.609375, y: 0.828125 }, - { x: 0.640625, y: 0.828125 }, - { x: 0.640625, y: 0.828125 }, - { x: 0.671875, y: 0.828125 }, - { x: 0.671875, y: 0.828125 }, - { x: 0.703125, y: 0.828125 }, - { x: 0.703125, y: 0.828125 }, - { x: 0.734375, y: 0.828125 }, - { x: 0.734375, y: 0.828125 }, - { x: 0.765625, y: 0.828125 }, - { x: 0.765625, y: 0.828125 }, - { x: 0.796875, y: 0.828125 }, - { x: 0.796875, y: 0.828125 }, - { x: 0.828125, y: 0.828125 }, - { x: 0.828125, y: 0.828125 }, - { x: 0.859375, y: 0.828125 }, - { x: 0.859375, y: 0.828125 }, - { x: 0.890625, y: 0.828125 }, - { x: 0.890625, y: 0.828125 }, - { x: 0.921875, y: 0.828125 }, - { x: 0.921875, y: 0.828125 }, - { x: 0.953125, y: 0.828125 }, - { x: 0.953125, y: 0.828125 }, - { x: 0.984375, y: 0.828125 }, - { x: 0.984375, y: 0.828125 }, - { x: 0.015625, y: 0.859375 }, - { x: 0.015625, y: 0.859375 }, - { x: 0.046875, y: 0.859375 }, - { x: 0.046875, y: 0.859375 }, - { x: 0.078125, y: 0.859375 }, - { x: 0.078125, y: 0.859375 }, - { x: 0.109375, y: 0.859375 }, - { x: 0.109375, y: 0.859375 }, - { x: 0.140625, y: 0.859375 }, - { x: 0.140625, y: 0.859375 }, - { x: 0.171875, y: 0.859375 }, - { x: 0.171875, y: 0.859375 }, - { x: 0.203125, y: 0.859375 }, - { x: 0.203125, y: 0.859375 }, - { x: 0.234375, y: 0.859375 }, - { x: 0.234375, y: 0.859375 }, - { x: 0.265625, y: 0.859375 }, - { x: 0.265625, y: 0.859375 }, - { x: 0.296875, y: 0.859375 }, - { x: 0.296875, y: 0.859375 }, - { x: 0.328125, y: 0.859375 }, - { x: 0.328125, y: 0.859375 }, - { x: 0.359375, y: 0.859375 }, - { x: 0.359375, y: 0.859375 }, - { x: 0.390625, y: 0.859375 }, - { x: 0.390625, y: 0.859375 }, - { x: 0.421875, y: 0.859375 }, - { x: 0.421875, y: 0.859375 }, - { x: 0.453125, y: 0.859375 }, - { x: 0.453125, y: 0.859375 }, - { x: 0.484375, y: 0.859375 }, - { x: 0.484375, y: 0.859375 }, - { x: 0.515625, y: 0.859375 }, - { x: 0.515625, y: 0.859375 }, - { x: 0.546875, y: 0.859375 }, - { x: 0.546875, y: 0.859375 }, - { x: 0.578125, y: 0.859375 }, - { x: 0.578125, y: 0.859375 }, - { x: 0.609375, y: 0.859375 }, - { x: 0.609375, y: 0.859375 }, - { x: 0.640625, y: 0.859375 }, - { x: 0.640625, y: 0.859375 }, - { x: 0.671875, y: 0.859375 }, - { x: 0.671875, y: 0.859375 }, - { x: 0.703125, y: 0.859375 }, - { x: 0.703125, y: 0.859375 }, - { x: 0.734375, y: 0.859375 }, - { x: 0.734375, y: 0.859375 }, - { x: 0.765625, y: 0.859375 }, - { x: 0.765625, y: 0.859375 }, - { x: 0.796875, y: 0.859375 }, - { x: 0.796875, y: 0.859375 }, - { x: 0.828125, y: 0.859375 }, - { x: 0.828125, y: 0.859375 }, - { x: 0.859375, y: 0.859375 }, - { x: 0.859375, y: 0.859375 }, - { x: 0.890625, y: 0.859375 }, - { x: 0.890625, y: 0.859375 }, - { x: 0.921875, y: 0.859375 }, - { x: 0.921875, y: 0.859375 }, - { x: 0.953125, y: 0.859375 }, - { x: 0.953125, y: 0.859375 }, - { x: 0.984375, y: 0.859375 }, - { x: 0.984375, y: 0.859375 }, - { x: 0.015625, y: 0.890625 }, - { x: 0.015625, y: 0.890625 }, - { x: 0.046875, y: 0.890625 }, - { x: 0.046875, y: 0.890625 }, - { x: 0.078125, y: 0.890625 }, - { x: 0.078125, y: 0.890625 }, - { x: 0.109375, y: 0.890625 }, - { x: 0.109375, y: 0.890625 }, - { x: 0.140625, y: 0.890625 }, - { x: 0.140625, y: 0.890625 }, - { x: 0.171875, y: 0.890625 }, - { x: 0.171875, y: 0.890625 }, - { x: 0.203125, y: 0.890625 }, - { x: 0.203125, y: 0.890625 }, - { x: 0.234375, y: 0.890625 }, - { x: 0.234375, y: 0.890625 }, - { x: 0.265625, y: 0.890625 }, - { x: 0.265625, y: 0.890625 }, - { x: 0.296875, y: 0.890625 }, - { x: 0.296875, y: 0.890625 }, - { x: 0.328125, y: 0.890625 }, - { x: 0.328125, y: 0.890625 }, - { x: 0.359375, y: 0.890625 }, - { x: 0.359375, y: 0.890625 }, - { x: 0.390625, y: 0.890625 }, - { x: 0.390625, y: 0.890625 }, - { x: 0.421875, y: 0.890625 }, - { x: 0.421875, y: 0.890625 }, - { x: 0.453125, y: 0.890625 }, - { x: 0.453125, y: 0.890625 }, - { x: 0.484375, y: 0.890625 }, - { x: 0.484375, y: 0.890625 }, - { x: 0.515625, y: 0.890625 }, - { x: 0.515625, y: 0.890625 }, - { x: 0.546875, y: 0.890625 }, - { x: 0.546875, y: 0.890625 }, - { x: 0.578125, y: 0.890625 }, - { x: 0.578125, y: 0.890625 }, - { x: 0.609375, y: 0.890625 }, - { x: 0.609375, y: 0.890625 }, - { x: 0.640625, y: 0.890625 }, - { x: 0.640625, y: 0.890625 }, - { x: 0.671875, y: 0.890625 }, - { x: 0.671875, y: 0.890625 }, - { x: 0.703125, y: 0.890625 }, - { x: 0.703125, y: 0.890625 }, - { x: 0.734375, y: 0.890625 }, - { x: 0.734375, y: 0.890625 }, - { x: 0.765625, y: 0.890625 }, - { x: 0.765625, y: 0.890625 }, - { x: 0.796875, y: 0.890625 }, - { x: 0.796875, y: 0.890625 }, - { x: 0.828125, y: 0.890625 }, - { x: 0.828125, y: 0.890625 }, - { x: 0.859375, y: 0.890625 }, - { x: 0.859375, y: 0.890625 }, - { x: 0.890625, y: 0.890625 }, - { x: 0.890625, y: 0.890625 }, - { x: 0.921875, y: 0.890625 }, - { x: 0.921875, y: 0.890625 }, - { x: 0.953125, y: 0.890625 }, - { x: 0.953125, y: 0.890625 }, - { x: 0.984375, y: 0.890625 }, - { x: 0.984375, y: 0.890625 }, - { x: 0.015625, y: 0.921875 }, - { x: 0.015625, y: 0.921875 }, - { x: 0.046875, y: 0.921875 }, - { x: 0.046875, y: 0.921875 }, - { x: 0.078125, y: 0.921875 }, - { x: 0.078125, y: 0.921875 }, - { x: 0.109375, y: 0.921875 }, - { x: 0.109375, y: 0.921875 }, - { x: 0.140625, y: 0.921875 }, - { x: 0.140625, y: 0.921875 }, - { x: 0.171875, y: 0.921875 }, - { x: 0.171875, y: 0.921875 }, - { x: 0.203125, y: 0.921875 }, - { x: 0.203125, y: 0.921875 }, - { x: 0.234375, y: 0.921875 }, - { x: 0.234375, y: 0.921875 }, - { x: 0.265625, y: 0.921875 }, - { x: 0.265625, y: 0.921875 }, - { x: 0.296875, y: 0.921875 }, - { x: 0.296875, y: 0.921875 }, - { x: 0.328125, y: 0.921875 }, - { x: 0.328125, y: 0.921875 }, - { x: 0.359375, y: 0.921875 }, - { x: 0.359375, y: 0.921875 }, - { x: 0.390625, y: 0.921875 }, - { x: 0.390625, y: 0.921875 }, - { x: 0.421875, y: 0.921875 }, - { x: 0.421875, y: 0.921875 }, - { x: 0.453125, y: 0.921875 }, - { x: 0.453125, y: 0.921875 }, - { x: 0.484375, y: 0.921875 }, - { x: 0.484375, y: 0.921875 }, - { x: 0.515625, y: 0.921875 }, - { x: 0.515625, y: 0.921875 }, - { x: 0.546875, y: 0.921875 }, - { x: 0.546875, y: 0.921875 }, - { x: 0.578125, y: 0.921875 }, - { x: 0.578125, y: 0.921875 }, - { x: 0.609375, y: 0.921875 }, - { x: 0.609375, y: 0.921875 }, - { x: 0.640625, y: 0.921875 }, - { x: 0.640625, y: 0.921875 }, - { x: 0.671875, y: 0.921875 }, - { x: 0.671875, y: 0.921875 }, - { x: 0.703125, y: 0.921875 }, - { x: 0.703125, y: 0.921875 }, - { x: 0.734375, y: 0.921875 }, - { x: 0.734375, y: 0.921875 }, - { x: 0.765625, y: 0.921875 }, - { x: 0.765625, y: 0.921875 }, - { x: 0.796875, y: 0.921875 }, - { x: 0.796875, y: 0.921875 }, - { x: 0.828125, y: 0.921875 }, - { x: 0.828125, y: 0.921875 }, - { x: 0.859375, y: 0.921875 }, - { x: 0.859375, y: 0.921875 }, - { x: 0.890625, y: 0.921875 }, - { x: 0.890625, y: 0.921875 }, - { x: 0.921875, y: 0.921875 }, - { x: 0.921875, y: 0.921875 }, - { x: 0.953125, y: 0.921875 }, - { x: 0.953125, y: 0.921875 }, - { x: 0.984375, y: 0.921875 }, - { x: 0.984375, y: 0.921875 }, - { x: 0.015625, y: 0.953125 }, - { x: 0.015625, y: 0.953125 }, - { x: 0.046875, y: 0.953125 }, - { x: 0.046875, y: 0.953125 }, - { x: 0.078125, y: 0.953125 }, - { x: 0.078125, y: 0.953125 }, - { x: 0.109375, y: 0.953125 }, - { x: 0.109375, y: 0.953125 }, - { x: 0.140625, y: 0.953125 }, - { x: 0.140625, y: 0.953125 }, - { x: 0.171875, y: 0.953125 }, - { x: 0.171875, y: 0.953125 }, - { x: 0.203125, y: 0.953125 }, - { x: 0.203125, y: 0.953125 }, - { x: 0.234375, y: 0.953125 }, - { x: 0.234375, y: 0.953125 }, - { x: 0.265625, y: 0.953125 }, - { x: 0.265625, y: 0.953125 }, - { x: 0.296875, y: 0.953125 }, - { x: 0.296875, y: 0.953125 }, - { x: 0.328125, y: 0.953125 }, - { x: 0.328125, y: 0.953125 }, - { x: 0.359375, y: 0.953125 }, - { x: 0.359375, y: 0.953125 }, - { x: 0.390625, y: 0.953125 }, - { x: 0.390625, y: 0.953125 }, - { x: 0.421875, y: 0.953125 }, - { x: 0.421875, y: 0.953125 }, - { x: 0.453125, y: 0.953125 }, - { x: 0.453125, y: 0.953125 }, - { x: 0.484375, y: 0.953125 }, - { x: 0.484375, y: 0.953125 }, - { x: 0.515625, y: 0.953125 }, - { x: 0.515625, y: 0.953125 }, - { x: 0.546875, y: 0.953125 }, - { x: 0.546875, y: 0.953125 }, - { x: 0.578125, y: 0.953125 }, - { x: 0.578125, y: 0.953125 }, - { x: 0.609375, y: 0.953125 }, - { x: 0.609375, y: 0.953125 }, - { x: 0.640625, y: 0.953125 }, - { x: 0.640625, y: 0.953125 }, - { x: 0.671875, y: 0.953125 }, - { x: 0.671875, y: 0.953125 }, - { x: 0.703125, y: 0.953125 }, - { x: 0.703125, y: 0.953125 }, - { x: 0.734375, y: 0.953125 }, - { x: 0.734375, y: 0.953125 }, - { x: 0.765625, y: 0.953125 }, - { x: 0.765625, y: 0.953125 }, - { x: 0.796875, y: 0.953125 }, - { x: 0.796875, y: 0.953125 }, - { x: 0.828125, y: 0.953125 }, - { x: 0.828125, y: 0.953125 }, - { x: 0.859375, y: 0.953125 }, - { x: 0.859375, y: 0.953125 }, - { x: 0.890625, y: 0.953125 }, - { x: 0.890625, y: 0.953125 }, - { x: 0.921875, y: 0.953125 }, - { x: 0.921875, y: 0.953125 }, - { x: 0.953125, y: 0.953125 }, - { x: 0.953125, y: 0.953125 }, - { x: 0.984375, y: 0.953125 }, - { x: 0.984375, y: 0.953125 }, - { x: 0.015625, y: 0.984375 }, - { x: 0.015625, y: 0.984375 }, - { x: 0.046875, y: 0.984375 }, - { x: 0.046875, y: 0.984375 }, - { x: 0.078125, y: 0.984375 }, - { x: 0.078125, y: 0.984375 }, - { x: 0.109375, y: 0.984375 }, - { x: 0.109375, y: 0.984375 }, - { x: 0.140625, y: 0.984375 }, - { x: 0.140625, y: 0.984375 }, - { x: 0.171875, y: 0.984375 }, - { x: 0.171875, y: 0.984375 }, - { x: 0.203125, y: 0.984375 }, - { x: 0.203125, y: 0.984375 }, - { x: 0.234375, y: 0.984375 }, - { x: 0.234375, y: 0.984375 }, - { x: 0.265625, y: 0.984375 }, - { x: 0.265625, y: 0.984375 }, - { x: 0.296875, y: 0.984375 }, - { x: 0.296875, y: 0.984375 }, - { x: 0.328125, y: 0.984375 }, - { x: 0.328125, y: 0.984375 }, - { x: 0.359375, y: 0.984375 }, - { x: 0.359375, y: 0.984375 }, - { x: 0.390625, y: 0.984375 }, - { x: 0.390625, y: 0.984375 }, - { x: 0.421875, y: 0.984375 }, - { x: 0.421875, y: 0.984375 }, - { x: 0.453125, y: 0.984375 }, - { x: 0.453125, y: 0.984375 }, - { x: 0.484375, y: 0.984375 }, - { x: 0.484375, y: 0.984375 }, - { x: 0.515625, y: 0.984375 }, - { x: 0.515625, y: 0.984375 }, - { x: 0.546875, y: 0.984375 }, - { x: 0.546875, y: 0.984375 }, - { x: 0.578125, y: 0.984375 }, - { x: 0.578125, y: 0.984375 }, - { x: 0.609375, y: 0.984375 }, - { x: 0.609375, y: 0.984375 }, - { x: 0.640625, y: 0.984375 }, - { x: 0.640625, y: 0.984375 }, - { x: 0.671875, y: 0.984375 }, - { x: 0.671875, y: 0.984375 }, - { x: 0.703125, y: 0.984375 }, - { x: 0.703125, y: 0.984375 }, - { x: 0.734375, y: 0.984375 }, - { x: 0.734375, y: 0.984375 }, - { x: 0.765625, y: 0.984375 }, - { x: 0.765625, y: 0.984375 }, - { x: 0.796875, y: 0.984375 }, - { x: 0.796875, y: 0.984375 }, - { x: 0.828125, y: 0.984375 }, - { x: 0.828125, y: 0.984375 }, - { x: 0.859375, y: 0.984375 }, - { x: 0.859375, y: 0.984375 }, - { x: 0.890625, y: 0.984375 }, - { x: 0.890625, y: 0.984375 }, - { x: 0.921875, y: 0.984375 }, - { x: 0.921875, y: 0.984375 }, - { x: 0.953125, y: 0.984375 }, - { x: 0.953125, y: 0.984375 }, - { x: 0.984375, y: 0.984375 }, - { x: 0.984375, y: 0.984375 }, - { x: 0.03125, y: 0.03125 }, - { x: 0.03125, y: 0.03125 }, - { x: 0.09375, y: 0.03125 }, - { x: 0.09375, y: 0.03125 }, - { x: 0.15625, y: 0.03125 }, - { x: 0.15625, y: 0.03125 }, - { x: 0.21875, y: 0.03125 }, - { x: 0.21875, y: 0.03125 }, - { x: 0.28125, y: 0.03125 }, - { x: 0.28125, y: 0.03125 }, - { x: 0.34375, y: 0.03125 }, - { x: 0.34375, y: 0.03125 }, - { x: 0.40625, y: 0.03125 }, - { x: 0.40625, y: 0.03125 }, - { x: 0.46875, y: 0.03125 }, - { x: 0.46875, y: 0.03125 }, - { x: 0.53125, y: 0.03125 }, - { x: 0.53125, y: 0.03125 }, - { x: 0.59375, y: 0.03125 }, - { x: 0.59375, y: 0.03125 }, - { x: 0.65625, y: 0.03125 }, - { x: 0.65625, y: 0.03125 }, - { x: 0.71875, y: 0.03125 }, - { x: 0.71875, y: 0.03125 }, - { x: 0.78125, y: 0.03125 }, - { x: 0.78125, y: 0.03125 }, - { x: 0.84375, y: 0.03125 }, - { x: 0.84375, y: 0.03125 }, - { x: 0.90625, y: 0.03125 }, - { x: 0.90625, y: 0.03125 }, - { x: 0.96875, y: 0.03125 }, - { x: 0.96875, y: 0.03125 }, - { x: 0.03125, y: 0.09375 }, - { x: 0.03125, y: 0.09375 }, - { x: 0.09375, y: 0.09375 }, - { x: 0.09375, y: 0.09375 }, - { x: 0.15625, y: 0.09375 }, - { x: 0.15625, y: 0.09375 }, - { x: 0.21875, y: 0.09375 }, - { x: 0.21875, y: 0.09375 }, - { x: 0.28125, y: 0.09375 }, - { x: 0.28125, y: 0.09375 }, - { x: 0.34375, y: 0.09375 }, - { x: 0.34375, y: 0.09375 }, - { x: 0.40625, y: 0.09375 }, - { x: 0.40625, y: 0.09375 }, - { x: 0.46875, y: 0.09375 }, - { x: 0.46875, y: 0.09375 }, - { x: 0.53125, y: 0.09375 }, - { x: 0.53125, y: 0.09375 }, - { x: 0.59375, y: 0.09375 }, - { x: 0.59375, y: 0.09375 }, - { x: 0.65625, y: 0.09375 }, - { x: 0.65625, y: 0.09375 }, - { x: 0.71875, y: 0.09375 }, - { x: 0.71875, y: 0.09375 }, - { x: 0.78125, y: 0.09375 }, - { x: 0.78125, y: 0.09375 }, - { x: 0.84375, y: 0.09375 }, - { x: 0.84375, y: 0.09375 }, - { x: 0.90625, y: 0.09375 }, - { x: 0.90625, y: 0.09375 }, - { x: 0.96875, y: 0.09375 }, - { x: 0.96875, y: 0.09375 }, - { x: 0.03125, y: 0.15625 }, - { x: 0.03125, y: 0.15625 }, - { x: 0.09375, y: 0.15625 }, - { x: 0.09375, y: 0.15625 }, - { x: 0.15625, y: 0.15625 }, - { x: 0.15625, y: 0.15625 }, - { x: 0.21875, y: 0.15625 }, - { x: 0.21875, y: 0.15625 }, - { x: 0.28125, y: 0.15625 }, - { x: 0.28125, y: 0.15625 }, - { x: 0.34375, y: 0.15625 }, - { x: 0.34375, y: 0.15625 }, - { x: 0.40625, y: 0.15625 }, - { x: 0.40625, y: 0.15625 }, - { x: 0.46875, y: 0.15625 }, - { x: 0.46875, y: 0.15625 }, - { x: 0.53125, y: 0.15625 }, - { x: 0.53125, y: 0.15625 }, - { x: 0.59375, y: 0.15625 }, - { x: 0.59375, y: 0.15625 }, - { x: 0.65625, y: 0.15625 }, - { x: 0.65625, y: 0.15625 }, - { x: 0.71875, y: 0.15625 }, - { x: 0.71875, y: 0.15625 }, - { x: 0.78125, y: 0.15625 }, - { x: 0.78125, y: 0.15625 }, - { x: 0.84375, y: 0.15625 }, - { x: 0.84375, y: 0.15625 }, - { x: 0.90625, y: 0.15625 }, - { x: 0.90625, y: 0.15625 }, - { x: 0.96875, y: 0.15625 }, - { x: 0.96875, y: 0.15625 }, - { x: 0.03125, y: 0.21875 }, - { x: 0.03125, y: 0.21875 }, - { x: 0.09375, y: 0.21875 }, - { x: 0.09375, y: 0.21875 }, - { x: 0.15625, y: 0.21875 }, - { x: 0.15625, y: 0.21875 }, - { x: 0.21875, y: 0.21875 }, - { x: 0.21875, y: 0.21875 }, - { x: 0.28125, y: 0.21875 }, - { x: 0.28125, y: 0.21875 }, - { x: 0.34375, y: 0.21875 }, - { x: 0.34375, y: 0.21875 }, - { x: 0.40625, y: 0.21875 }, - { x: 0.40625, y: 0.21875 }, - { x: 0.46875, y: 0.21875 }, - { x: 0.46875, y: 0.21875 }, - { x: 0.53125, y: 0.21875 }, - { x: 0.53125, y: 0.21875 }, - { x: 0.59375, y: 0.21875 }, - { x: 0.59375, y: 0.21875 }, - { x: 0.65625, y: 0.21875 }, - { x: 0.65625, y: 0.21875 }, - { x: 0.71875, y: 0.21875 }, - { x: 0.71875, y: 0.21875 }, - { x: 0.78125, y: 0.21875 }, - { x: 0.78125, y: 0.21875 }, - { x: 0.84375, y: 0.21875 }, - { x: 0.84375, y: 0.21875 }, - { x: 0.90625, y: 0.21875 }, - { x: 0.90625, y: 0.21875 }, - { x: 0.96875, y: 0.21875 }, - { x: 0.96875, y: 0.21875 }, - { x: 0.03125, y: 0.28125 }, - { x: 0.03125, y: 0.28125 }, - { x: 0.09375, y: 0.28125 }, - { x: 0.09375, y: 0.28125 }, - { x: 0.15625, y: 0.28125 }, - { x: 0.15625, y: 0.28125 }, - { x: 0.21875, y: 0.28125 }, - { x: 0.21875, y: 0.28125 }, - { x: 0.28125, y: 0.28125 }, - { x: 0.28125, y: 0.28125 }, - { x: 0.34375, y: 0.28125 }, - { x: 0.34375, y: 0.28125 }, - { x: 0.40625, y: 0.28125 }, - { x: 0.40625, y: 0.28125 }, - { x: 0.46875, y: 0.28125 }, - { x: 0.46875, y: 0.28125 }, - { x: 0.53125, y: 0.28125 }, - { x: 0.53125, y: 0.28125 }, - { x: 0.59375, y: 0.28125 }, - { x: 0.59375, y: 0.28125 }, - { x: 0.65625, y: 0.28125 }, - { x: 0.65625, y: 0.28125 }, - { x: 0.71875, y: 0.28125 }, - { x: 0.71875, y: 0.28125 }, - { x: 0.78125, y: 0.28125 }, - { x: 0.78125, y: 0.28125 }, - { x: 0.84375, y: 0.28125 }, - { x: 0.84375, y: 0.28125 }, - { x: 0.90625, y: 0.28125 }, - { x: 0.90625, y: 0.28125 }, - { x: 0.96875, y: 0.28125 }, - { x: 0.96875, y: 0.28125 }, - { x: 0.03125, y: 0.34375 }, - { x: 0.03125, y: 0.34375 }, - { x: 0.09375, y: 0.34375 }, - { x: 0.09375, y: 0.34375 }, - { x: 0.15625, y: 0.34375 }, - { x: 0.15625, y: 0.34375 }, - { x: 0.21875, y: 0.34375 }, - { x: 0.21875, y: 0.34375 }, - { x: 0.28125, y: 0.34375 }, - { x: 0.28125, y: 0.34375 }, - { x: 0.34375, y: 0.34375 }, - { x: 0.34375, y: 0.34375 }, - { x: 0.40625, y: 0.34375 }, - { x: 0.40625, y: 0.34375 }, - { x: 0.46875, y: 0.34375 }, - { x: 0.46875, y: 0.34375 }, - { x: 0.53125, y: 0.34375 }, - { x: 0.53125, y: 0.34375 }, - { x: 0.59375, y: 0.34375 }, - { x: 0.59375, y: 0.34375 }, - { x: 0.65625, y: 0.34375 }, - { x: 0.65625, y: 0.34375 }, - { x: 0.71875, y: 0.34375 }, - { x: 0.71875, y: 0.34375 }, - { x: 0.78125, y: 0.34375 }, - { x: 0.78125, y: 0.34375 }, - { x: 0.84375, y: 0.34375 }, - { x: 0.84375, y: 0.34375 }, - { x: 0.90625, y: 0.34375 }, - { x: 0.90625, y: 0.34375 }, - { x: 0.96875, y: 0.34375 }, - { x: 0.96875, y: 0.34375 }, - { x: 0.03125, y: 0.40625 }, - { x: 0.03125, y: 0.40625 }, - { x: 0.09375, y: 0.40625 }, - { x: 0.09375, y: 0.40625 }, - { x: 0.15625, y: 0.40625 }, - { x: 0.15625, y: 0.40625 }, - { x: 0.21875, y: 0.40625 }, - { x: 0.21875, y: 0.40625 }, - { x: 0.28125, y: 0.40625 }, - { x: 0.28125, y: 0.40625 }, - { x: 0.34375, y: 0.40625 }, - { x: 0.34375, y: 0.40625 }, - { x: 0.40625, y: 0.40625 }, - { x: 0.40625, y: 0.40625 }, - { x: 0.46875, y: 0.40625 }, - { x: 0.46875, y: 0.40625 }, - { x: 0.53125, y: 0.40625 }, - { x: 0.53125, y: 0.40625 }, - { x: 0.59375, y: 0.40625 }, - { x: 0.59375, y: 0.40625 }, - { x: 0.65625, y: 0.40625 }, - { x: 0.65625, y: 0.40625 }, - { x: 0.71875, y: 0.40625 }, - { x: 0.71875, y: 0.40625 }, - { x: 0.78125, y: 0.40625 }, - { x: 0.78125, y: 0.40625 }, - { x: 0.84375, y: 0.40625 }, - { x: 0.84375, y: 0.40625 }, - { x: 0.90625, y: 0.40625 }, - { x: 0.90625, y: 0.40625 }, - { x: 0.96875, y: 0.40625 }, - { x: 0.96875, y: 0.40625 }, - { x: 0.03125, y: 0.46875 }, - { x: 0.03125, y: 0.46875 }, - { x: 0.09375, y: 0.46875 }, - { x: 0.09375, y: 0.46875 }, - { x: 0.15625, y: 0.46875 }, - { x: 0.15625, y: 0.46875 }, - { x: 0.21875, y: 0.46875 }, - { x: 0.21875, y: 0.46875 }, - { x: 0.28125, y: 0.46875 }, - { x: 0.28125, y: 0.46875 }, - { x: 0.34375, y: 0.46875 }, - { x: 0.34375, y: 0.46875 }, - { x: 0.40625, y: 0.46875 }, - { x: 0.40625, y: 0.46875 }, - { x: 0.46875, y: 0.46875 }, - { x: 0.46875, y: 0.46875 }, - { x: 0.53125, y: 0.46875 }, - { x: 0.53125, y: 0.46875 }, - { x: 0.59375, y: 0.46875 }, - { x: 0.59375, y: 0.46875 }, - { x: 0.65625, y: 0.46875 }, - { x: 0.65625, y: 0.46875 }, - { x: 0.71875, y: 0.46875 }, - { x: 0.71875, y: 0.46875 }, - { x: 0.78125, y: 0.46875 }, - { x: 0.78125, y: 0.46875 }, - { x: 0.84375, y: 0.46875 }, - { x: 0.84375, y: 0.46875 }, - { x: 0.90625, y: 0.46875 }, - { x: 0.90625, y: 0.46875 }, - { x: 0.96875, y: 0.46875 }, - { x: 0.96875, y: 0.46875 }, - { x: 0.03125, y: 0.53125 }, - { x: 0.03125, y: 0.53125 }, - { x: 0.09375, y: 0.53125 }, - { x: 0.09375, y: 0.53125 }, - { x: 0.15625, y: 0.53125 }, - { x: 0.15625, y: 0.53125 }, - { x: 0.21875, y: 0.53125 }, - { x: 0.21875, y: 0.53125 }, - { x: 0.28125, y: 0.53125 }, - { x: 0.28125, y: 0.53125 }, - { x: 0.34375, y: 0.53125 }, - { x: 0.34375, y: 0.53125 }, - { x: 0.40625, y: 0.53125 }, - { x: 0.40625, y: 0.53125 }, - { x: 0.46875, y: 0.53125 }, - { x: 0.46875, y: 0.53125 }, - { x: 0.53125, y: 0.53125 }, - { x: 0.53125, y: 0.53125 }, - { x: 0.59375, y: 0.53125 }, - { x: 0.59375, y: 0.53125 }, - { x: 0.65625, y: 0.53125 }, - { x: 0.65625, y: 0.53125 }, - { x: 0.71875, y: 0.53125 }, - { x: 0.71875, y: 0.53125 }, - { x: 0.78125, y: 0.53125 }, - { x: 0.78125, y: 0.53125 }, - { x: 0.84375, y: 0.53125 }, - { x: 0.84375, y: 0.53125 }, - { x: 0.90625, y: 0.53125 }, - { x: 0.90625, y: 0.53125 }, - { x: 0.96875, y: 0.53125 }, - { x: 0.96875, y: 0.53125 }, - { x: 0.03125, y: 0.59375 }, - { x: 0.03125, y: 0.59375 }, - { x: 0.09375, y: 0.59375 }, - { x: 0.09375, y: 0.59375 }, - { x: 0.15625, y: 0.59375 }, - { x: 0.15625, y: 0.59375 }, - { x: 0.21875, y: 0.59375 }, - { x: 0.21875, y: 0.59375 }, - { x: 0.28125, y: 0.59375 }, - { x: 0.28125, y: 0.59375 }, - { x: 0.34375, y: 0.59375 }, - { x: 0.34375, y: 0.59375 }, - { x: 0.40625, y: 0.59375 }, - { x: 0.40625, y: 0.59375 }, - { x: 0.46875, y: 0.59375 }, - { x: 0.46875, y: 0.59375 }, - { x: 0.53125, y: 0.59375 }, - { x: 0.53125, y: 0.59375 }, - { x: 0.59375, y: 0.59375 }, - { x: 0.59375, y: 0.59375 }, - { x: 0.65625, y: 0.59375 }, - { x: 0.65625, y: 0.59375 }, - { x: 0.71875, y: 0.59375 }, - { x: 0.71875, y: 0.59375 }, - { x: 0.78125, y: 0.59375 }, - { x: 0.78125, y: 0.59375 }, - { x: 0.84375, y: 0.59375 }, - { x: 0.84375, y: 0.59375 }, - { x: 0.90625, y: 0.59375 }, - { x: 0.90625, y: 0.59375 }, - { x: 0.96875, y: 0.59375 }, - { x: 0.96875, y: 0.59375 }, - { x: 0.03125, y: 0.65625 }, - { x: 0.03125, y: 0.65625 }, - { x: 0.09375, y: 0.65625 }, - { x: 0.09375, y: 0.65625 }, - { x: 0.15625, y: 0.65625 }, - { x: 0.15625, y: 0.65625 }, - { x: 0.21875, y: 0.65625 }, - { x: 0.21875, y: 0.65625 }, - { x: 0.28125, y: 0.65625 }, - { x: 0.28125, y: 0.65625 }, - { x: 0.34375, y: 0.65625 }, - { x: 0.34375, y: 0.65625 }, - { x: 0.40625, y: 0.65625 }, - { x: 0.40625, y: 0.65625 }, - { x: 0.46875, y: 0.65625 }, - { x: 0.46875, y: 0.65625 }, - { x: 0.53125, y: 0.65625 }, - { x: 0.53125, y: 0.65625 }, - { x: 0.59375, y: 0.65625 }, - { x: 0.59375, y: 0.65625 }, - { x: 0.65625, y: 0.65625 }, - { x: 0.65625, y: 0.65625 }, - { x: 0.71875, y: 0.65625 }, - { x: 0.71875, y: 0.65625 }, - { x: 0.78125, y: 0.65625 }, - { x: 0.78125, y: 0.65625 }, - { x: 0.84375, y: 0.65625 }, - { x: 0.84375, y: 0.65625 }, - { x: 0.90625, y: 0.65625 }, - { x: 0.90625, y: 0.65625 }, - { x: 0.96875, y: 0.65625 }, - { x: 0.96875, y: 0.65625 }, - { x: 0.03125, y: 0.71875 }, - { x: 0.03125, y: 0.71875 }, - { x: 0.09375, y: 0.71875 }, - { x: 0.09375, y: 0.71875 }, - { x: 0.15625, y: 0.71875 }, - { x: 0.15625, y: 0.71875 }, - { x: 0.21875, y: 0.71875 }, - { x: 0.21875, y: 0.71875 }, - { x: 0.28125, y: 0.71875 }, - { x: 0.28125, y: 0.71875 }, - { x: 0.34375, y: 0.71875 }, - { x: 0.34375, y: 0.71875 }, - { x: 0.40625, y: 0.71875 }, - { x: 0.40625, y: 0.71875 }, - { x: 0.46875, y: 0.71875 }, - { x: 0.46875, y: 0.71875 }, - { x: 0.53125, y: 0.71875 }, - { x: 0.53125, y: 0.71875 }, - { x: 0.59375, y: 0.71875 }, - { x: 0.59375, y: 0.71875 }, - { x: 0.65625, y: 0.71875 }, - { x: 0.65625, y: 0.71875 }, - { x: 0.71875, y: 0.71875 }, - { x: 0.71875, y: 0.71875 }, - { x: 0.78125, y: 0.71875 }, - { x: 0.78125, y: 0.71875 }, - { x: 0.84375, y: 0.71875 }, - { x: 0.84375, y: 0.71875 }, - { x: 0.90625, y: 0.71875 }, - { x: 0.90625, y: 0.71875 }, - { x: 0.96875, y: 0.71875 }, - { x: 0.96875, y: 0.71875 }, - { x: 0.03125, y: 0.78125 }, - { x: 0.03125, y: 0.78125 }, - { x: 0.09375, y: 0.78125 }, - { x: 0.09375, y: 0.78125 }, - { x: 0.15625, y: 0.78125 }, - { x: 0.15625, y: 0.78125 }, - { x: 0.21875, y: 0.78125 }, - { x: 0.21875, y: 0.78125 }, - { x: 0.28125, y: 0.78125 }, - { x: 0.28125, y: 0.78125 }, - { x: 0.34375, y: 0.78125 }, - { x: 0.34375, y: 0.78125 }, - { x: 0.40625, y: 0.78125 }, - { x: 0.40625, y: 0.78125 }, - { x: 0.46875, y: 0.78125 }, - { x: 0.46875, y: 0.78125 }, - { x: 0.53125, y: 0.78125 }, - { x: 0.53125, y: 0.78125 }, - { x: 0.59375, y: 0.78125 }, - { x: 0.59375, y: 0.78125 }, - { x: 0.65625, y: 0.78125 }, - { x: 0.65625, y: 0.78125 }, - { x: 0.71875, y: 0.78125 }, - { x: 0.71875, y: 0.78125 }, - { x: 0.78125, y: 0.78125 }, - { x: 0.78125, y: 0.78125 }, - { x: 0.84375, y: 0.78125 }, - { x: 0.84375, y: 0.78125 }, - { x: 0.90625, y: 0.78125 }, - { x: 0.90625, y: 0.78125 }, - { x: 0.96875, y: 0.78125 }, - { x: 0.96875, y: 0.78125 }, - { x: 0.03125, y: 0.84375 }, - { x: 0.03125, y: 0.84375 }, - { x: 0.09375, y: 0.84375 }, - { x: 0.09375, y: 0.84375 }, - { x: 0.15625, y: 0.84375 }, - { x: 0.15625, y: 0.84375 }, - { x: 0.21875, y: 0.84375 }, - { x: 0.21875, y: 0.84375 }, - { x: 0.28125, y: 0.84375 }, - { x: 0.28125, y: 0.84375 }, - { x: 0.34375, y: 0.84375 }, - { x: 0.34375, y: 0.84375 }, - { x: 0.40625, y: 0.84375 }, - { x: 0.40625, y: 0.84375 }, - { x: 0.46875, y: 0.84375 }, - { x: 0.46875, y: 0.84375 }, - { x: 0.53125, y: 0.84375 }, - { x: 0.53125, y: 0.84375 }, - { x: 0.59375, y: 0.84375 }, - { x: 0.59375, y: 0.84375 }, - { x: 0.65625, y: 0.84375 }, - { x: 0.65625, y: 0.84375 }, - { x: 0.71875, y: 0.84375 }, - { x: 0.71875, y: 0.84375 }, - { x: 0.78125, y: 0.84375 }, - { x: 0.78125, y: 0.84375 }, - { x: 0.84375, y: 0.84375 }, - { x: 0.84375, y: 0.84375 }, - { x: 0.90625, y: 0.84375 }, - { x: 0.90625, y: 0.84375 }, - { x: 0.96875, y: 0.84375 }, - { x: 0.96875, y: 0.84375 }, - { x: 0.03125, y: 0.90625 }, - { x: 0.03125, y: 0.90625 }, - { x: 0.09375, y: 0.90625 }, - { x: 0.09375, y: 0.90625 }, - { x: 0.15625, y: 0.90625 }, - { x: 0.15625, y: 0.90625 }, - { x: 0.21875, y: 0.90625 }, - { x: 0.21875, y: 0.90625 }, - { x: 0.28125, y: 0.90625 }, - { x: 0.28125, y: 0.90625 }, - { x: 0.34375, y: 0.90625 }, - { x: 0.34375, y: 0.90625 }, - { x: 0.40625, y: 0.90625 }, - { x: 0.40625, y: 0.90625 }, - { x: 0.46875, y: 0.90625 }, - { x: 0.46875, y: 0.90625 }, - { x: 0.53125, y: 0.90625 }, - { x: 0.53125, y: 0.90625 }, - { x: 0.59375, y: 0.90625 }, - { x: 0.59375, y: 0.90625 }, - { x: 0.65625, y: 0.90625 }, - { x: 0.65625, y: 0.90625 }, - { x: 0.71875, y: 0.90625 }, - { x: 0.71875, y: 0.90625 }, - { x: 0.78125, y: 0.90625 }, - { x: 0.78125, y: 0.90625 }, - { x: 0.84375, y: 0.90625 }, - { x: 0.84375, y: 0.90625 }, - { x: 0.90625, y: 0.90625 }, - { x: 0.90625, y: 0.90625 }, - { x: 0.96875, y: 0.90625 }, - { x: 0.96875, y: 0.90625 }, - { x: 0.03125, y: 0.96875 }, - { x: 0.03125, y: 0.96875 }, - { x: 0.09375, y: 0.96875 }, - { x: 0.09375, y: 0.96875 }, - { x: 0.15625, y: 0.96875 }, - { x: 0.15625, y: 0.96875 }, - { x: 0.21875, y: 0.96875 }, - { x: 0.21875, y: 0.96875 }, - { x: 0.28125, y: 0.96875 }, - { x: 0.28125, y: 0.96875 }, - { x: 0.34375, y: 0.96875 }, - { x: 0.34375, y: 0.96875 }, - { x: 0.40625, y: 0.96875 }, - { x: 0.40625, y: 0.96875 }, - { x: 0.46875, y: 0.96875 }, - { x: 0.46875, y: 0.96875 }, - { x: 0.53125, y: 0.96875 }, - { x: 0.53125, y: 0.96875 }, - { x: 0.59375, y: 0.96875 }, - { x: 0.59375, y: 0.96875 }, - { x: 0.65625, y: 0.96875 }, - { x: 0.65625, y: 0.96875 }, - { x: 0.71875, y: 0.96875 }, - { x: 0.71875, y: 0.96875 }, - { x: 0.78125, y: 0.96875 }, - { x: 0.78125, y: 0.96875 }, - { x: 0.84375, y: 0.96875 }, - { x: 0.84375, y: 0.96875 }, - { x: 0.90625, y: 0.96875 }, - { x: 0.90625, y: 0.96875 }, - { x: 0.96875, y: 0.96875 }, - { x: 0.96875, y: 0.96875 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 } -]; - -// src/hand/handposedetector.ts -var HandDetector = class { - constructor(model23) { - __publicField(this, "model"); - __publicField(this, "anchors"); - __publicField(this, "anchorsTensor"); - __publicField(this, "inputSize"); - __publicField(this, "inputSizeTensor"); - __publicField(this, "doubleInputSizeTensor"); - var _a, _b, _c, _d; - this.model = model23; - this.anchors = anchors2.map((anchor) => [anchor.x, anchor.y]); - this.anchorsTensor = tfjs_esm_exports.tensor2d(this.anchors); - this.inputSize = ((_d = (_c = (_b = (_a = this == null ? void 0 : this.model) == null ? void 0 : _a.inputs) == null ? void 0 : _b[0]) == null ? void 0 : _c.shape) == null ? void 0 : _d[2]) || 0; - this.inputSizeTensor = tfjs_esm_exports.tensor1d([this.inputSize, this.inputSize]); - this.doubleInputSizeTensor = tfjs_esm_exports.tensor1d([this.inputSize * 2, this.inputSize * 2]); - } - normalizeBoxes(boxes) { - const t2 = {}; - t2.boxOffsets = tfjs_esm_exports.slice(boxes, [0, 0], [-1, 2]); - t2.boxSizes = tfjs_esm_exports.slice(boxes, [0, 2], [-1, 2]); - t2.div = tfjs_esm_exports.div(t2.boxOffsets, this.inputSizeTensor); - t2.boxCenterPoints = tfjs_esm_exports.add(t2.div, this.anchorsTensor); - t2.halfBoxSizes = tfjs_esm_exports.div(t2.boxSizes, this.doubleInputSizeTensor); - t2.sub = tfjs_esm_exports.sub(t2.boxCenterPoints, t2.halfBoxSizes); - t2.startPoints = tfjs_esm_exports.mul(t2.sub, this.inputSizeTensor); - t2.add = tfjs_esm_exports.add(t2.boxCenterPoints, t2.halfBoxSizes); - t2.endPoints = tfjs_esm_exports.mul(t2.add, this.inputSizeTensor); - const res = tfjs_esm_exports.concat2d([t2.startPoints, t2.endPoints], 1); - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - return res; - } - normalizeLandmarks(rawPalmLandmarks, index2) { - const t2 = {}; - t2.reshape = tfjs_esm_exports.reshape(rawPalmLandmarks, [-1, 7, 2]); - t2.div = tfjs_esm_exports.div(t2.reshape, this.inputSizeTensor); - t2.landmarks = tfjs_esm_exports.add(t2.div, this.anchors[index2] ? this.anchors[index2] : 0); - const res = tfjs_esm_exports.mul(t2.landmarks, this.inputSizeTensor); - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - return res; - } - async predict(input, config3) { - var _a; - const t2 = {}; - t2.resize = tfjs_esm_exports.image.resizeBilinear(input, [this.inputSize, this.inputSize]); - t2.div = tfjs_esm_exports.div(t2.resize, constants.tf127); - t2.image = tfjs_esm_exports.sub(t2.div, constants.tf1); - t2.batched = this.model.execute(t2.image); - t2.predictions = tfjs_esm_exports.squeeze(t2.batched); - t2.slice = tfjs_esm_exports.slice(t2.predictions, [0, 0], [-1, 1]); - t2.sigmoid = tfjs_esm_exports.sigmoid(t2.slice); - t2.scores = tfjs_esm_exports.squeeze(t2.sigmoid); - const scores = await t2.scores.data(); - t2.boxes = tfjs_esm_exports.slice(t2.predictions, [0, 1], [-1, 4]); - t2.norm = this.normalizeBoxes(t2.boxes); - t2.nms = await tfjs_esm_exports.image.nonMaxSuppressionAsync(t2.norm, t2.scores, 3 * (((_a = config3.hand) == null ? void 0 : _a.maxDetected) || 1), config3.hand.iouThreshold, config3.hand.minConfidence); - const nms = await t2.nms.array(); - const hands = []; - for (const index2 of nms) { - const p = {}; - p.box = tfjs_esm_exports.slice(t2.norm, [index2, 0], [1, -1]); - p.slice = tfjs_esm_exports.slice(t2.predictions, [index2, 5], [1, 14]); - p.norm = this.normalizeLandmarks(p.slice, index2); - p.palmLandmarks = tfjs_esm_exports.reshape(p.norm, [-1, 2]); - const box = await p.box.data(); - const startPoint = box.slice(0, 2); - const endPoint = box.slice(2, 4); - const palmLandmarks = await p.palmLandmarks.array(); - const hand3 = { startPoint, endPoint, palmLandmarks, confidence: scores[index2] }; - const scaled = scaleBoxCoordinates2(hand3, [(input.shape[2] || 1) / this.inputSize, (input.shape[1] || 0) / this.inputSize]); - hands.push(scaled); - Object.keys(p).forEach((tensor6) => tfjs_esm_exports.dispose(p[tensor6])); - } - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - return hands; - } -}; - -// src/hand/handposepipeline.ts -var palmBoxEnlargeFactor = 5; -var handBoxEnlargeFactor = 1.65; -var palmLandmarkIds = [0, 5, 9, 13, 17, 1, 2]; -var palmLandmarksPalmBase = 0; -var palmLandmarksMiddleFingerBase = 2; -var lastTime13 = 0; -var HandPipeline = class { - constructor(handDetector, handPoseModel2) { - __publicField(this, "handDetector"); - __publicField(this, "handPoseModel"); - __publicField(this, "inputSize"); - __publicField(this, "storedBoxes"); - __publicField(this, "skipped"); - __publicField(this, "detectedHands"); - var _a, _b, _c; - this.handDetector = handDetector; - this.handPoseModel = handPoseModel2; - this.inputSize = ((_c = (_b = (_a = this.handPoseModel) == null ? void 0 : _a.inputs) == null ? void 0 : _b[0].shape) == null ? void 0 : _c[2]) || 0; - this.storedBoxes = []; - this.skipped = Number.MAX_SAFE_INTEGER; - this.detectedHands = 0; - } - calculateLandmarksBoundingBox(landmarks) { - const xs = landmarks.map((d) => d[0]); - const ys = landmarks.map((d) => d[1]); - const startPoint = [Math.min(...xs), Math.min(...ys)]; - const endPoint = [Math.max(...xs), Math.max(...ys)]; - return { startPoint, endPoint }; - } - getBoxForPalmLandmarks(palmLandmarks, rotationMatrix) { - const rotatedPalmLandmarks = palmLandmarks.map((coord) => rotatePoint2([...coord, 1], rotationMatrix)); - const boxAroundPalm = this.calculateLandmarksBoundingBox(rotatedPalmLandmarks); - return enlargeBox2(squarifyBox2(boxAroundPalm), palmBoxEnlargeFactor); - } - getBoxForHandLandmarks(landmarks) { - const boundingBox = this.calculateLandmarksBoundingBox(landmarks); - const boxAroundHand = enlargeBox2(squarifyBox2(boundingBox), handBoxEnlargeFactor); - boxAroundHand.palmLandmarks = []; - for (let i = 0; i < palmLandmarkIds.length; i++) { - boxAroundHand.palmLandmarks.push(landmarks[palmLandmarkIds[i]].slice(0, 2)); - } - return boxAroundHand; - } - transformRawCoords(rawCoords, box2, angle, rotationMatrix) { - const boxSize = getBoxSize2(box2); - const scaleFactor = [boxSize[0] / this.inputSize, boxSize[1] / this.inputSize, (boxSize[0] + boxSize[1]) / this.inputSize / 2]; - const coordsScaled = rawCoords.map((coord) => [ - scaleFactor[0] * (coord[0] - this.inputSize / 2), - scaleFactor[1] * (coord[1] - this.inputSize / 2), - scaleFactor[2] * coord[2] - ]); - const coordsRotationMatrix = buildRotationMatrix2(angle, [0, 0]); - const coordsRotated = coordsScaled.map((coord) => { - const rotated = rotatePoint2(coord, coordsRotationMatrix); - return [...rotated, coord[2]]; - }); - const inverseRotationMatrix = invertTransformMatrix2(rotationMatrix); - const boxCenter = [...getBoxCenter2(box2), 1]; - const originalBoxCenter = [ - dot2(boxCenter, inverseRotationMatrix[0]), - dot2(boxCenter, inverseRotationMatrix[1]) - ]; - return coordsRotated.map((coord) => [ - Math.trunc(coord[0] + originalBoxCenter[0]), - Math.trunc(coord[1] + originalBoxCenter[1]), - Math.trunc(coord[2]) - ]); - } - async estimateHands(image28, config3) { - let useFreshBox = false; - let boxes; - const skipTime = (config3.hand.skipTime || 0) > now() - lastTime13; - const skipFrame = this.skipped < (config3.hand.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame) { - boxes = await this.handDetector.predict(image28, config3); - this.skipped = 0; - } - if (config3.skipAllowed) - this.skipped++; - if (boxes && boxes.length > 0 && (boxes.length !== this.detectedHands && this.detectedHands !== config3.hand.maxDetected || !config3.hand.landmarks)) { - this.detectedHands = 0; - this.storedBoxes = [...boxes]; - if (this.storedBoxes.length > 0) - useFreshBox = true; - } - const hands = []; - for (let i = 0; i < this.storedBoxes.length; i++) { - const currentBox = this.storedBoxes[i]; - if (!currentBox) - continue; - if (config3.hand.landmarks) { - const angle = config3.hand.rotation ? computeRotation2(currentBox.palmLandmarks[palmLandmarksPalmBase], currentBox.palmLandmarks[palmLandmarksMiddleFingerBase]) : 0; - const palmCenter = getBoxCenter2(currentBox); - const palmCenterNormalized = [palmCenter[0] / image28.shape[2], palmCenter[1] / image28.shape[1]]; - const rotatedImage = config3.hand.rotation && env.kernels.includes("rotatewithoffset") ? tfjs_esm_exports.image.rotateWithOffset(image28, angle, 0, palmCenterNormalized) : image28.clone(); - const rotationMatrix = buildRotationMatrix2(-angle, palmCenter); - const newBox = useFreshBox ? this.getBoxForPalmLandmarks(currentBox.palmLandmarks, rotationMatrix) : currentBox; - const croppedInput = cutBoxFromImageAndResize(newBox, rotatedImage, [this.inputSize, this.inputSize]); - const handImage = tfjs_esm_exports.div(croppedInput, constants.tf255); - tfjs_esm_exports.dispose(croppedInput); - tfjs_esm_exports.dispose(rotatedImage); - const [confidenceT, keypoints] = this.handPoseModel.execute(handImage); - lastTime13 = now(); - tfjs_esm_exports.dispose(handImage); - const confidence = (await confidenceT.data())[0]; - tfjs_esm_exports.dispose(confidenceT); - if (confidence >= config3.hand.minConfidence / 4) { - const keypointsReshaped = tfjs_esm_exports.reshape(keypoints, [-1, 3]); - const rawCoords = await keypointsReshaped.array(); - tfjs_esm_exports.dispose(keypoints); - tfjs_esm_exports.dispose(keypointsReshaped); - const coords = this.transformRawCoords(rawCoords, newBox, angle, rotationMatrix); - const nextBoundingBox = this.getBoxForHandLandmarks(coords); - this.storedBoxes[i] = { ...nextBoundingBox, confidence }; - const result = { - landmarks: coords, - confidence, - boxConfidence: currentBox.confidence, - fingerConfidence: confidence, - box: { topLeft: nextBoundingBox.startPoint, bottomRight: nextBoundingBox.endPoint } - }; - hands.push(result); - } else { - this.storedBoxes[i] = null; - } - tfjs_esm_exports.dispose(keypoints); - } else { - const enlarged = enlargeBox2(squarifyBox2(currentBox), handBoxEnlargeFactor); - const result = { - confidence: currentBox.confidence, - boxConfidence: currentBox.confidence, - fingerConfidence: 0, - box: { topLeft: enlarged.startPoint, bottomRight: enlarged.endPoint }, - landmarks: [] - }; - hands.push(result); - } - } - this.storedBoxes = this.storedBoxes.filter((a) => a !== null); - this.detectedHands = hands.length; - if (hands.length > config3.hand.maxDetected) - hands.length = config3.hand.maxDetected; - return hands; - } -}; - -// src/hand/handpose.ts -var meshAnnotations2 = { - thumb: [1, 2, 3, 4], - index: [5, 6, 7, 8], - middle: [9, 10, 11, 12], - ring: [13, 14, 15, 16], - pinky: [17, 18, 19, 20], - palm: [0] -}; -var handDetectorModel; -var handPoseModel; -var handPipeline; -async function predict14(input, config3) { - const predictions = await handPipeline.estimateHands(input, config3); - if (!predictions) - return []; - const hands = []; - for (let i = 0; i < predictions.length; i++) { - const annotations2 = {}; - if (predictions[i].landmarks) { - for (const key of Object.keys(meshAnnotations2)) { - annotations2[key] = meshAnnotations2[key].map((index2) => predictions[i].landmarks[index2]); - } - } - const keypoints = predictions[i].landmarks; - let box = [Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, 0, 0]; - let boxRaw = [0, 0, 0, 0]; - if (keypoints && keypoints.length > 0) { - for (const pt of keypoints) { - if (pt[0] < box[0]) - box[0] = pt[0]; - if (pt[1] < box[1]) - box[1] = pt[1]; - if (pt[0] > box[2]) - box[2] = pt[0]; - if (pt[1] > box[3]) - box[3] = pt[1]; - } - box[2] -= box[0]; - box[3] -= box[1]; - boxRaw = [box[0] / (input.shape[2] || 0), box[1] / (input.shape[1] || 0), box[2] / (input.shape[2] || 0), box[3] / (input.shape[1] || 0)]; - } else { - box = predictions[i].box ? [ - Math.trunc(Math.max(0, predictions[i].box.topLeft[0])), - Math.trunc(Math.max(0, predictions[i].box.topLeft[1])), - Math.trunc(Math.min(input.shape[2] || 0, predictions[i].box.bottomRight[0]) - Math.max(0, predictions[i].box.topLeft[0])), - Math.trunc(Math.min(input.shape[1] || 0, predictions[i].box.bottomRight[1]) - Math.max(0, predictions[i].box.topLeft[1])) - ] : [0, 0, 0, 0]; - boxRaw = [ - predictions[i].box.topLeft[0] / (input.shape[2] || 0), - predictions[i].box.topLeft[1] / (input.shape[1] || 0), - (predictions[i].box.bottomRight[0] - predictions[i].box.topLeft[0]) / (input.shape[2] || 0), - (predictions[i].box.bottomRight[1] - predictions[i].box.topLeft[1]) / (input.shape[1] || 0) - ]; - } - const landmarks = analyze(keypoints); - hands.push({ - id: i, - score: Math.round(100 * predictions[i].confidence) / 100, - boxScore: Math.round(100 * predictions[i].boxConfidence) / 100, - fingerScore: Math.round(100 * predictions[i].fingerConfidence) / 100, - label: "hand", - box, - boxRaw, - keypoints, - annotations: annotations2, - landmarks - }); - } - return hands; -} -async function load15(config3) { - var _a, _b; - if (env.initial) { - handDetectorModel = null; - handPoseModel = null; - } - if (!handDetectorModel || !handPoseModel) { - [handDetectorModel, handPoseModel] = await Promise.all([ - config3.hand.enabled ? loadModel((_a = config3.hand.detector) == null ? void 0 : _a.modelPath) : null, - config3.hand.landmarks ? loadModel((_b = config3.hand.skeleton) == null ? void 0 : _b.modelPath) : null - ]); - } else { - if (config3.debug) - log("cached model:", handDetectorModel["modelUrl"]); - if (config3.debug) - log("cached model:", handPoseModel["modelUrl"]); - } - const handDetector = handDetectorModel ? new HandDetector(handDetectorModel) : void 0; - if (handDetector && handPoseModel) - handPipeline = new HandPipeline(handDetector, handPoseModel); - return [handDetectorModel, handPoseModel]; -} - -// src/hand/handtrack.ts -var models2 = [null, null]; -var modelOutputNodes = ["StatefulPartitionedCall/Postprocessor/Slice", "StatefulPartitionedCall/Postprocessor/ExpandDims_1"]; -var inputSize7 = [[0, 0], [0, 0]]; -var classes = ["hand", "fist", "pinch", "point", "face", "tip", "pinchtip"]; -var faceIndex = 4; -var boxExpandFact = 1.6; -var maxDetectorResolution = 512; -var detectorExpandFact = 1.4; -var skipped13 = Number.MAX_SAFE_INTEGER; -var lastTime14 = 0; -var outputSize = [0, 0]; -var cache4 = { - boxes: [], - hands: [] -}; -var fingerMap = { - thumb: [1, 2, 3, 4], - index: [5, 6, 7, 8], - middle: [9, 10, 11, 12], - ring: [13, 14, 15, 16], - pinky: [17, 18, 19, 20], - base: [0], - palm: [0, 17, 13, 9, 5, 1, 0] -}; -async function loadDetect2(config3) { - var _a; - if (env.initial) - models2[0] = null; - if (!models2[0]) { - fakeOps(["tensorlistreserve", "enter", "tensorlistfromtensor", "merge", "loopcond", "switch", "exit", "tensorliststack", "nextiteration", "tensorlistsetitem", "tensorlistgetitem", "reciprocal", "shape", "split", "where"], config3); - models2[0] = await loadModel((_a = config3.hand.detector) == null ? void 0 : _a.modelPath); - const inputs = models2[0]["executor"] ? Object.values(models2[0].modelSignature["inputs"]) : void 0; - inputSize7[0][0] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - inputSize7[0][1] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 0; - } else if (config3.debug) - log("cached model:", models2[0]["modelUrl"]); - return models2[0]; -} -async function loadSkeleton(config3) { - var _a; - if (env.initial) - models2[1] = null; - if (!models2[1]) { - models2[1] = await loadModel((_a = config3.hand.skeleton) == null ? void 0 : _a.modelPath); - const inputs = models2[1]["executor"] ? Object.values(models2[1].modelSignature["inputs"]) : void 0; - inputSize7[1][0] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - inputSize7[1][1] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 0; - } else if (config3.debug) - log("cached model:", models2[1]["modelUrl"]); - return models2[1]; -} -async function detectHands(input, config3) { - const hands = []; - if (!input || !models2[0]) - return hands; - const t2 = {}; - const ratio2 = (input.shape[2] || 1) / (input.shape[1] || 1); - const height = Math.min(Math.round((input.shape[1] || 0) / 8) * 8, maxDetectorResolution); - const width = Math.round(height * ratio2 / 8) * 8; - t2.resize = tfjs_esm_exports.image.resizeBilinear(input, [height, width]); - t2.cast = tfjs_esm_exports.cast(t2.resize, "int32"); - [t2.rawScores, t2.rawBoxes] = await models2[0].executeAsync(t2.cast, modelOutputNodes); - t2.boxes = tfjs_esm_exports.squeeze(t2.rawBoxes, [0, 2]); - t2.scores = tfjs_esm_exports.squeeze(t2.rawScores, [0]); - const classScores = tfjs_esm_exports.unstack(t2.scores, 1); - tfjs_esm_exports.dispose(classScores[faceIndex]); - classScores.splice(faceIndex, 1); - t2.filtered = tfjs_esm_exports.stack(classScores, 1); - tfjs_esm_exports.dispose(classScores); - t2.max = tfjs_esm_exports.max(t2.filtered, 1); - t2.argmax = tfjs_esm_exports.argMax(t2.filtered, 1); - let id = 0; - t2.nms = await tfjs_esm_exports.image.nonMaxSuppressionAsync(t2.boxes, t2.max, (config3.hand.maxDetected || 0) + 1, config3.hand.iouThreshold || 0, config3.hand.minConfidence || 1); - const nms = await t2.nms.data(); - const scores = await t2.max.data(); - const classNum = await t2.argmax.data(); - for (const nmsIndex of Array.from(nms)) { - const boxSlice = tfjs_esm_exports.slice(t2.boxes, nmsIndex, 1); - const boxYX = await boxSlice.data(); - tfjs_esm_exports.dispose(boxSlice); - const boxData = [boxYX[1], boxYX[0], boxYX[3] - boxYX[1], boxYX[2] - boxYX[0]]; - const boxRaw = scale(boxData, detectorExpandFact); - const boxFull = [Math.trunc(boxData[0] * outputSize[0]), Math.trunc(boxData[1] * outputSize[1]), Math.trunc(boxData[2] * outputSize[0]), Math.trunc(boxData[3] * outputSize[1])]; - const score = scores[nmsIndex]; - const label = classes[classNum[nmsIndex]]; - const hand3 = { id: id++, score, box: boxFull, boxRaw, label }; - hands.push(hand3); - } - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - hands.sort((a, b) => b.score - a.score); - if (hands.length > (config3.hand.maxDetected || 1)) - hands.length = config3.hand.maxDetected || 1; - return hands; -} -async function detectFingers(input, h, config3) { - const hand3 = { - id: h.id, - score: Math.round(100 * h.score) / 100, - boxScore: Math.round(100 * h.score) / 100, - fingerScore: 0, - box: h.box, - boxRaw: h.boxRaw, - label: h.label, - keypoints: [], - landmarks: {}, - annotations: {} - }; - if (input && models2[1] && config3.hand.landmarks && h.score > (config3.hand.minConfidence || 0)) { - const t2 = {}; - const boxCrop = [h.boxRaw[1], h.boxRaw[0], h.boxRaw[3] + h.boxRaw[1], h.boxRaw[2] + h.boxRaw[0]]; - t2.crop = tfjs_esm_exports.image.cropAndResize(input, [boxCrop], [0], [inputSize7[1][0], inputSize7[1][1]], "bilinear"); - t2.div = tfjs_esm_exports.div(t2.crop, constants.tf255); - [t2.score, t2.keypoints] = models2[1].execute(t2.div, ["Identity_1", "Identity"]); - const rawScore = (await t2.score.data())[0]; - const score = (100 - Math.trunc(100 / (1 + Math.exp(rawScore)))) / 100; - if (score >= (config3.hand.minConfidence || 0)) { - hand3.fingerScore = score; - t2.reshaped = tfjs_esm_exports.reshape(t2.keypoints, [-1, 3]); - const coordsData = await t2.reshaped.array(); - const coordsRaw = coordsData.map((kpt4) => [kpt4[0] / inputSize7[1][1], kpt4[1] / inputSize7[1][0], kpt4[2] || 0]); - const coordsNorm = coordsRaw.map((kpt4) => [kpt4[0] * h.boxRaw[2], kpt4[1] * h.boxRaw[3], kpt4[2] || 0]); - hand3.keypoints = coordsNorm.map((kpt4) => [outputSize[0] * (kpt4[0] + h.boxRaw[0]), outputSize[1] * (kpt4[1] + h.boxRaw[1]), kpt4[2] || 0]); - hand3.landmarks = analyze(hand3.keypoints); - for (const key of Object.keys(fingerMap)) { - hand3.annotations[key] = fingerMap[key].map((index2) => hand3.landmarks && hand3.keypoints[index2] ? hand3.keypoints[index2] : null); - } - } - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - } - return hand3; -} -async function predict15(input, config3) { - var _a, _b; - if (!((_a = models2[0]) == null ? void 0 : _a["executor"]) || !((_b = models2[1]) == null ? void 0 : _b["executor"]) || !models2[0].inputs[0].shape || !models2[1].inputs[0].shape) - return []; - outputSize = [input.shape[2] || 0, input.shape[1] || 0]; - skipped13++; - const skipTime = (config3.hand.skipTime || 0) > now() - lastTime14; - const skipFrame = skipped13 < (config3.hand.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame) { - return cache4.hands; - } - return new Promise(async (resolve) => { - const skipTimeExtended = 3 * (config3.hand.skipTime || 0) > now() - lastTime14; - const skipFrameExtended = skipped13 < 3 * (config3.hand.skipFrames || 0); - if (config3.skipAllowed && cache4.hands.length === config3.hand.maxDetected) { - cache4.hands = await Promise.all(cache4.boxes.map((handBox) => detectFingers(input, handBox, config3))); - } else if (config3.skipAllowed && skipTimeExtended && skipFrameExtended && cache4.hands.length > 0) { - cache4.hands = await Promise.all(cache4.boxes.map((handBox) => detectFingers(input, handBox, config3))); - } else { - cache4.boxes = await detectHands(input, config3); - lastTime14 = now(); - cache4.hands = await Promise.all(cache4.boxes.map((handBox) => detectFingers(input, handBox, config3))); - skipped13 = 0; - } - const oldCache = [...cache4.boxes]; - cache4.boxes.length = 0; - if (config3.cacheSensitivity > 0) { - for (let i = 0; i < cache4.hands.length; i++) { - const boxKpt = square(cache4.hands[i].keypoints, outputSize); - if (boxKpt.box[2] / (input.shape[2] || 1) > 0.05 && boxKpt.box[3] / (input.shape[1] || 1) > 0.05 && cache4.hands[i].fingerScore && cache4.hands[i].fingerScore > (config3.hand.minConfidence || 0)) { - const boxScale = scale(boxKpt.box, boxExpandFact); - const boxScaleRaw = scale(boxKpt.boxRaw, boxExpandFact); - cache4.boxes.push({ ...oldCache[i], box: boxScale, boxRaw: boxScaleRaw }); - } - } - } - for (let i = 0; i < cache4.hands.length; i++) { - const bbox = calc(cache4.hands[i].keypoints, outputSize); - cache4.hands[i].box = bbox.box; - cache4.hands[i].boxRaw = bbox.boxRaw; - } - resolve(cache4.hands); - }); -} - -// src/result.ts -var empty = (error = null) => ({ face: [], body: [], hand: [], gesture: [], object: [], persons: [], performance: {}, timestamp: 0, width: 0, height: 0, error }); - -// src/body/movenetcoords.ts -var movenetcoords_exports = {}; -__export(movenetcoords_exports, { - connected: () => connected3, - horizontal: () => horizontal, - kpt: () => kpt3, - relative: () => relative, - vertical: () => vertical -}); -var kpt3 = [ - "nose", - "leftEye", - "rightEye", - "leftEar", - "rightEar", - "leftShoulder", - "rightShoulder", - "leftElbow", - "rightElbow", - "leftWrist", - "rightWrist", - "leftHip", - "rightHip", - "leftKnee", - "rightKnee", - "leftAnkle", - "rightAnkle" -]; -var horizontal = [ - ["leftEye", "rightEye"], - ["leftEar", "rightEar"], - ["leftShoulder", "rightShoulder"], - ["leftElbow", "rightElbow"], - ["leftWrist", "rightWrist"], - ["leftHip", "rightHip"], - ["leftKnee", "rightKnee"], - ["leftAnkle", "rightAnkle"] -]; -var vertical = [ - ["leftKnee", "leftShoulder"], - ["rightKnee", "rightShoulder"], - ["leftAnkle", "leftKnee"], - ["rightAnkle", "rightKnee"] -]; -var relative = [ - [["leftHip", "rightHip"], ["leftShoulder", "rightShoulder"]], - [["leftElbow", "rightElbow"], ["leftShoulder", "rightShoulder"]] -]; -var connected3 = { - leftLeg: ["leftHip", "leftKnee", "leftAnkle"], - rightLeg: ["rightHip", "rightKnee", "rightAnkle"], - torso: ["leftShoulder", "rightShoulder", "rightHip", "leftHip", "leftShoulder"], - leftArm: ["leftShoulder", "leftElbow", "leftWrist"], - rightArm: ["rightShoulder", "rightElbow", "rightWrist"], - head: [] -}; - -// src/util/interpolate.ts -var bufferedResult = empty(); -var interpolateTime = 0; -function calc2(newResult, config3) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w; - const t0 = now(); - if (!newResult) - return empty(); - const elapsed = Date.now() - newResult.timestamp; - const bufferedFactor = elapsed < 1e3 ? 8 - Math.log(elapsed + 1) : 1; - if (newResult.canvas) - bufferedResult.canvas = newResult.canvas; - if (newResult.error) - bufferedResult.error = newResult.error; - if (!bufferedResult.body || newResult.body.length !== bufferedResult.body.length) { - bufferedResult.body = JSON.parse(JSON.stringify(newResult.body)); - } else { - for (let i = 0; i < newResult.body.length; i++) { - const box = newResult.body[i].box.map((newBoxCoord, j) => ((bufferedFactor - 1) * bufferedResult.body[i].box[j] + newBoxCoord) / bufferedFactor); - const boxRaw = newResult.body[i].boxRaw.map((newBoxCoord, j) => ((bufferedFactor - 1) * bufferedResult.body[i].boxRaw[j] + newBoxCoord) / bufferedFactor); - const keypoints = newResult.body[i].keypoints.map((newKpt, j) => { - var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2; - return { - score: newKpt.score, - part: newKpt.part, - position: [ - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].position[0] || 0) + (newKpt.position[0] || 0)) / bufferedFactor : newKpt.position[0], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].position[1] || 0) + (newKpt.position[1] || 0)) / bufferedFactor : newKpt.position[1], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].position[2] || 0) + (newKpt.position[2] || 0)) / bufferedFactor : newKpt.position[2] - ], - positionRaw: [ - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].positionRaw[0] || 0) + (newKpt.positionRaw[0] || 0)) / bufferedFactor : newKpt.positionRaw[0], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].positionRaw[1] || 0) + (newKpt.positionRaw[1] || 0)) / bufferedFactor : newKpt.positionRaw[1], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].positionRaw[2] || 0) + (newKpt.positionRaw[2] || 0)) / bufferedFactor : newKpt.positionRaw[2] - ], - distance: [ - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (((_a2 = bufferedResult.body[i].keypoints[j].distance) == null ? void 0 : _a2[0]) || 0) + (((_b2 = newKpt.distance) == null ? void 0 : _b2[0]) || 0)) / bufferedFactor : (_c2 = newKpt.distance) == null ? void 0 : _c2[0], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (((_d2 = bufferedResult.body[i].keypoints[j].distance) == null ? void 0 : _d2[1]) || 0) + (((_e2 = newKpt.distance) == null ? void 0 : _e2[1]) || 0)) / bufferedFactor : (_f2 = newKpt.distance) == null ? void 0 : _f2[1], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (((_g2 = bufferedResult.body[i].keypoints[j].distance) == null ? void 0 : _g2[2]) || 0) + (((_h2 = newKpt.distance) == null ? void 0 : _h2[2]) || 0)) / bufferedFactor : (_i2 = newKpt.distance) == null ? void 0 : _i2[2] - ] - }; - }); - const annotations2 = {}; - let coords = { connected: {} }; - if ((_a = config3.body.modelPath) == null ? void 0 : _a.includes("efficientpose")) - coords = efficientposecoords_exports; - else if ((_b = config3.body.modelPath) == null ? void 0 : _b.includes("blazepose")) - coords = blazeposecoords_exports; - else if ((_c = config3.body.modelPath) == null ? void 0 : _c.includes("movenet")) - coords = movenetcoords_exports; - for (const [name, indexes] of Object.entries(coords.connected)) { - const pt = []; - for (let j = 0; j < indexes.length - 1; j++) { - const pt0 = keypoints.find((kp) => kp.part === indexes[j]); - const pt1 = keypoints.find((kp) => kp.part === indexes[j + 1]); - if (pt0 && pt1) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - bufferedResult.body[i] = { ...newResult.body[i], box, boxRaw, keypoints, annotations: annotations2 }; - } - } - if (!bufferedResult.hand || newResult.hand.length !== bufferedResult.hand.length) { - bufferedResult.hand = JSON.parse(JSON.stringify(newResult.hand)); - } else { - for (let i = 0; i < newResult.hand.length; i++) { - const box = newResult.hand[i].box.map((b, j) => ((bufferedFactor - 1) * bufferedResult.hand[i].box[j] + b) / bufferedFactor); - const boxRaw = newResult.hand[i].boxRaw.map((b, j) => ((bufferedFactor - 1) * bufferedResult.hand[i].boxRaw[j] + b) / bufferedFactor); - if (bufferedResult.hand[i].keypoints.length !== newResult.hand[i].keypoints.length) - bufferedResult.hand[i].keypoints = newResult.hand[i].keypoints; - const keypoints = newResult.hand[i].keypoints && newResult.hand[i].keypoints.length > 0 ? newResult.hand[i].keypoints.map((landmark, j) => landmark.map((coord, k) => ((bufferedFactor - 1) * (bufferedResult.hand[i].keypoints[j][k] || 1) + (coord || 0)) / bufferedFactor)) : []; - let annotations2 = {}; - if (Object.keys(bufferedResult.hand[i].annotations).length !== Object.keys(newResult.hand[i].annotations).length) { - bufferedResult.hand[i].annotations = newResult.hand[i].annotations; - annotations2 = bufferedResult.hand[i].annotations; - } else if (newResult.hand[i].annotations) { - for (const key of Object.keys(newResult.hand[i].annotations)) { - annotations2[key] = ((_f = (_e = (_d = newResult.hand[i]) == null ? void 0 : _d.annotations) == null ? void 0 : _e[key]) == null ? void 0 : _f[0]) ? newResult.hand[i].annotations[key].map((val, j) => val.map((coord, k) => ((bufferedFactor - 1) * bufferedResult.hand[i].annotations[key][j][k] + coord) / bufferedFactor)) : null; - } - } - bufferedResult.hand[i] = { ...newResult.hand[i], box, boxRaw, keypoints, annotations: annotations2 }; - } - } - if (!bufferedResult.face || newResult.face.length !== bufferedResult.face.length) { - bufferedResult.face = JSON.parse(JSON.stringify(newResult.face)); - } else { - for (let i = 0; i < newResult.face.length; i++) { - const box = newResult.face[i].box.map((b, j) => ((bufferedFactor - 1) * bufferedResult.face[i].box[j] + b) / bufferedFactor); - const boxRaw = newResult.face[i].boxRaw.map((b, j) => ((bufferedFactor - 1) * bufferedResult.face[i].boxRaw[j] + b) / bufferedFactor); - if (newResult.face[i].rotation) { - const rotation = { matrix: [0, 0, 0, 0, 0, 0, 0, 0, 0], angle: { roll: 0, yaw: 0, pitch: 0 }, gaze: { bearing: 0, strength: 0 } }; - rotation.matrix = (_g = newResult.face[i].rotation) == null ? void 0 : _g.matrix; - rotation.angle = { - roll: ((bufferedFactor - 1) * (((_i = (_h = bufferedResult.face[i].rotation) == null ? void 0 : _h.angle) == null ? void 0 : _i.roll) || 0) + (((_k = (_j = newResult.face[i].rotation) == null ? void 0 : _j.angle) == null ? void 0 : _k.roll) || 0)) / bufferedFactor, - yaw: ((bufferedFactor - 1) * (((_m = (_l = bufferedResult.face[i].rotation) == null ? void 0 : _l.angle) == null ? void 0 : _m.yaw) || 0) + (((_o = (_n = newResult.face[i].rotation) == null ? void 0 : _n.angle) == null ? void 0 : _o.yaw) || 0)) / bufferedFactor, - pitch: ((bufferedFactor - 1) * (((_q = (_p = bufferedResult.face[i].rotation) == null ? void 0 : _p.angle) == null ? void 0 : _q.pitch) || 0) + (((_s = (_r = newResult.face[i].rotation) == null ? void 0 : _r.angle) == null ? void 0 : _s.pitch) || 0)) / bufferedFactor - }; - rotation.gaze = { - bearing: ((bufferedFactor - 1) * (((_t = bufferedResult.face[i].rotation) == null ? void 0 : _t.gaze.bearing) || 0) + (((_u = newResult.face[i].rotation) == null ? void 0 : _u.gaze.bearing) || 0)) / bufferedFactor, - strength: ((bufferedFactor - 1) * (((_v = bufferedResult.face[i].rotation) == null ? void 0 : _v.gaze.strength) || 0) + (((_w = newResult.face[i].rotation) == null ? void 0 : _w.gaze.strength) || 0)) / bufferedFactor - }; - bufferedResult.face[i] = { ...newResult.face[i], rotation, box, boxRaw }; - } else { - bufferedResult.face[i] = { ...newResult.face[i], box, boxRaw }; - } - } - } - if (!bufferedResult.object || newResult.object.length !== bufferedResult.object.length) { - bufferedResult.object = JSON.parse(JSON.stringify(newResult.object)); - } else { - for (let i = 0; i < newResult.object.length; i++) { - const box = newResult.object[i].box.map((b, j) => ((bufferedFactor - 1) * bufferedResult.object[i].box[j] + b) / bufferedFactor); - const boxRaw = newResult.object[i].boxRaw.map((b, j) => ((bufferedFactor - 1) * bufferedResult.object[i].boxRaw[j] + b) / bufferedFactor); - bufferedResult.object[i] = { ...newResult.object[i], box, boxRaw }; - } - } - if (newResult.persons) { - const newPersons = newResult.persons; - if (!bufferedResult.persons || newPersons.length !== bufferedResult.persons.length) { - bufferedResult.persons = JSON.parse(JSON.stringify(newPersons)); - } else { - for (let i = 0; i < newPersons.length; i++) { - bufferedResult.persons[i].box = newPersons[i].box.map((box, j) => ((bufferedFactor - 1) * bufferedResult.persons[i].box[j] + box) / bufferedFactor); - } - } - } - if (newResult.gesture) - bufferedResult.gesture = newResult.gesture; - bufferedResult.width = newResult.width; - bufferedResult.height = newResult.height; - const t1 = now(); - interpolateTime = env.perfadd ? interpolateTime + Math.round(t1 - t0) : Math.round(t1 - t0); - if (newResult.performance) - bufferedResult.performance = { ...newResult.performance, interpolate: interpolateTime }; - return bufferedResult; -} - -// src/segmentation/meet.ts -var model17; -async function load16(config3) { - if (!model17 || env.initial) - model17 = await loadModel(config3.segmentation.modelPath); - else if (config3.debug) - log("cached model:", model17["modelUrl"]); - return model17; -} -async function predict16(input, config3) { - var _a; - if (!model17) - model17 = await load16(config3); - if (!(model17 == null ? void 0 : model17["executor"]) || !((_a = model17 == null ? void 0 : model17.inputs) == null ? void 0 : _a[0].shape)) - return null; - const t2 = {}; - t2.resize = tfjs_esm_exports.image.resizeBilinear(input, [model17.inputs[0].shape ? model17.inputs[0].shape[1] : 0, model17.inputs[0].shape ? model17.inputs[0].shape[2] : 0], false); - t2.norm = tfjs_esm_exports.div(t2.resize, constants.tf255); - t2.res = model17.execute(t2.norm); - t2.squeeze = tfjs_esm_exports.squeeze(t2.res, [0]); - [t2.bgRaw, t2.fgRaw] = tfjs_esm_exports.unstack(t2.squeeze, 2); - t2.fg = tfjs_esm_exports.softmax(t2.fgRaw); - t2.mul = tfjs_esm_exports.mul(t2.fg, constants.tf255); - t2.expand = tfjs_esm_exports.expandDims(t2.mul, 2); - t2.output = tfjs_esm_exports.image.resizeBilinear(t2.expand, [input.shape[1] || 0, input.shape[2] || 0]); - let rgba; - switch (config3.segmentation.mode || "default") { - case "default": - t2.input = tfjs_esm_exports.squeeze(input); - t2.concat = tfjs_esm_exports.concat([t2.input, t2.output], -1); - rgba = tfjs_esm_exports.cast(t2.concat, "int32"); - break; - case "alpha": - rgba = tfjs_esm_exports.cast(t2.output, "int32"); - break; - default: - rgba = tfjs_esm_exports.tensor(0); - } - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - return rgba; -} - -// src/face/match.ts -var match_exports = {}; -__export(match_exports, { - distance: () => distance, - find: () => find, - similarity: () => similarity -}); -function distance(descriptor1, descriptor2, options4 = { order: 2, multiplier: 25 }) { - if (!descriptor1 || !descriptor1) - return Number.MAX_SAFE_INTEGER; - let sum3 = 0; - for (let i = 0; i < descriptor1.length; i++) { - const diff = !options4.order || options4.order === 2 ? descriptor1[i] - descriptor2[i] : Math.abs(descriptor1[i] - descriptor2[i]); - sum3 += !options4.order || options4.order === 2 ? diff * diff : diff ** options4.order; - } - return (options4.multiplier || 20) * sum3; -} -var normalizeDistance = (dist, order, min2, max5) => { - if (dist === 0) - return 1; - const root = order === 2 ? Math.sqrt(dist) : dist ** (1 / order); - const norm = (1 - root / 100 - min2) / (max5 - min2); - const clamp2 = Math.max(Math.min(norm, 1), 0); - return clamp2; -}; -function similarity(descriptor1, descriptor2, options4 = { order: 2, multiplier: 25, min: 0.2, max: 0.8 }) { - const dist = distance(descriptor1, descriptor2, options4); - return normalizeDistance(dist, options4.order || 2, options4.min || 0, options4.max || 1); -} -function find(descriptor, descriptors, options4 = { order: 2, multiplier: 25, threshold: 0, min: 0.2, max: 0.8 }) { - if (!Array.isArray(descriptor) || !Array.isArray(descriptors) || descriptor.length < 64 || descriptors.length === 0) { - return { index: -1, distance: Number.POSITIVE_INFINITY, similarity: 0 }; - } - let lowestDistance = Number.MAX_SAFE_INTEGER; - let index2 = -1; - for (let i = 0; i < descriptors.length; i++) { - const res = descriptors[i].length === descriptor.length ? distance(descriptor, descriptors[i], options4) : Number.MAX_SAFE_INTEGER; - if (res < lowestDistance) { - lowestDistance = res; - index2 = i; - } - if (lowestDistance < (options4.threshold || 0)) - break; - } - const normalizedSimilarity = normalizeDistance(lowestDistance, options4.order || 2, options4.min || 0, options4.max || 1); - return { index: index2, distance: lowestDistance, similarity: normalizedSimilarity }; -} - -// src/models.ts -var models_exports2 = {}; -__export(models_exports2, { - Models: () => Models, - validateModel: () => validateModel -}); - -// src/body/movenetfix.ts -var maxJitter = 5e-3; -var cache5 = { - keypoints: [], - padding: [[0, 0], [0, 0], [0, 0], [0, 0]] -}; -function bodyParts(body4) { - for (const pair of horizontal) { - const left = body4.keypoints.findIndex((kp) => kp.part === pair[0]); - const right = body4.keypoints.findIndex((kp) => kp.part === pair[1]); - if (body4.keypoints[left] && body4.keypoints[right]) { - if (body4.keypoints[left].position[0] < body4.keypoints[right].position[0]) { - const tmp = body4.keypoints[left]; - body4.keypoints[left] = body4.keypoints[right]; - body4.keypoints[right] = tmp; - } - } - } - for (const pair of vertical) { - const lower = body4.keypoints.findIndex((kp) => kp && kp.part === pair[0]); - const higher = body4.keypoints.findIndex((kp) => kp && kp.part === pair[1]); - if (body4.keypoints[lower] && body4.keypoints[higher]) { - if (body4.keypoints[lower].position[1] < body4.keypoints[higher].position[1]) { - body4.keypoints.splice(lower, 1); - } - } - } - for (const [pair, compare2] of relative) { - const left = body4.keypoints.findIndex((kp) => kp && kp.part === pair[0]); - const right = body4.keypoints.findIndex((kp) => kp && kp.part === pair[1]); - const leftTo = body4.keypoints.findIndex((kp) => kp && kp.part === compare2[0]); - const rightTo = body4.keypoints.findIndex((kp) => kp && kp.part === compare2[1]); - if (!body4.keypoints[leftTo] || !body4.keypoints[rightTo]) - continue; - const distanceLeft = body4.keypoints[left] ? [ - Math.abs(body4.keypoints[leftTo].position[0] - body4.keypoints[left].position[0]), - Math.abs(body4.keypoints[rightTo].position[0] - body4.keypoints[left].position[0]) - ] : [0, 0]; - const distanceRight = body4.keypoints[right] ? [ - Math.abs(body4.keypoints[rightTo].position[0] - body4.keypoints[right].position[0]), - Math.abs(body4.keypoints[leftTo].position[0] - body4.keypoints[right].position[0]) - ] : [0, 0]; - if (distanceLeft[0] > distanceLeft[1] || distanceRight[0] > distanceRight[1]) { - const tmp = body4.keypoints[left]; - body4.keypoints[left] = body4.keypoints[right]; - body4.keypoints[right] = tmp; - } - } -} -function jitter(keypoints) { - for (let i = 0; i < keypoints.length; i++) { - if (keypoints[i] && cache5.keypoints[i]) { - const diff = [Math.abs(keypoints[i].positionRaw[0] - cache5.keypoints[i].positionRaw[0]), Math.abs(keypoints[i].positionRaw[1] - cache5.keypoints[i].positionRaw[1])]; - if (diff[0] < maxJitter && diff[1] < maxJitter) { - keypoints[i] = cache5.keypoints[i]; - } else { - cache5.keypoints[i] = keypoints[i]; - } - } else { - cache5.keypoints[i] = keypoints[i]; - } - } - return keypoints; -} -function padInput(input, inputSize10) { - var _a, _b; - const t2 = {}; - if (!((_a = input == null ? void 0 : input.shape) == null ? void 0 : _a[1]) || !((_b = input == null ? void 0 : input.shape) == null ? void 0 : _b[2])) - return input; - cache5.padding = [ - [0, 0], - [input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0, input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0], - [input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0, input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0], - [0, 0] - ]; - t2.pad = tfjs_esm_exports.pad(input, cache5.padding); - t2.resize = tfjs_esm_exports.image.resizeBilinear(t2.pad, [inputSize10, inputSize10]); - const final = tfjs_esm_exports.cast(t2.resize, "int32"); - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - return final; -} -function rescaleBody(body4, outputSize2) { - body4.keypoints = body4.keypoints.filter((kpt4) => kpt4 == null ? void 0 : kpt4.position); - for (const kpt4 of body4.keypoints) { - kpt4.position = [ - kpt4.position[0] * (outputSize2[0] + cache5.padding[2][0] + cache5.padding[2][1]) / outputSize2[0] - cache5.padding[2][0], - kpt4.position[1] * (outputSize2[1] + cache5.padding[1][0] + cache5.padding[1][1]) / outputSize2[1] - cache5.padding[1][0] - ]; - kpt4.positionRaw = [ - kpt4.position[0] / outputSize2[0], - kpt4.position[1] / outputSize2[1] - ]; - } - const rescaledBoxes = calc(body4.keypoints.map((pt) => pt.position), outputSize2); - body4.box = rescaledBoxes.box; - body4.boxRaw = rescaledBoxes.boxRaw; - return body4; -} - -// src/body/movenet.ts -var model18; -var inputSize8 = 0; -var skipped14 = Number.MAX_SAFE_INTEGER; -var cache6 = { - boxes: [], - bodies: [], - last: 0 -}; -async function load17(config3) { - var _a; - if (env.initial) - model18 = null; - if (!model18) { - fakeOps(["size"], config3); - model18 = await loadModel(config3.body.modelPath); - } else if (config3.debug) - log("cached model:", model18["modelUrl"]); - inputSize8 = (model18 == null ? void 0 : model18["executor"]) && ((_a = model18 == null ? void 0 : model18.inputs) == null ? void 0 : _a[0].shape) ? model18.inputs[0].shape[2] : 0; - if (inputSize8 < 64) - inputSize8 = 256; - return model18; -} -function parseSinglePose(res, config3, image28) { - const kpt4 = res[0][0]; - const keypoints = []; - let score = 0; - for (let id = 0; id < kpt4.length; id++) { - score = kpt4[id][2]; - if (score > config3.body.minConfidence) { - const positionRaw = [kpt4[id][1], kpt4[id][0]]; - keypoints.push({ - score: Math.round(100 * score) / 100, - part: kpt3[id], - positionRaw, - position: [ - Math.round((image28.shape[2] || 0) * positionRaw[0]), - Math.round((image28.shape[1] || 0) * positionRaw[1]) - ] - }); - } - } - score = keypoints.reduce((prev, curr) => curr.score > prev ? curr.score : prev, 0); - const bodies = []; - const newBox = calc(keypoints.map((pt) => pt.position), [image28.shape[2], image28.shape[1]]); - const annotations2 = {}; - for (const [name, indexes] of Object.entries(connected3)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = keypoints.find((kp) => kp.part === indexes[i]); - const pt1 = keypoints.find((kp) => kp.part === indexes[i + 1]); - if (pt0 && pt1 && pt0.score > (config3.body.minConfidence || 0) && pt1.score > (config3.body.minConfidence || 0)) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - const body4 = { id: 0, score, box: newBox.box, boxRaw: newBox.boxRaw, keypoints, annotations: annotations2 }; - bodyParts(body4); - bodies.push(body4); - return bodies; -} -function parseMultiPose(res, config3, image28) { - const bodies = []; - for (let id = 0; id < res[0].length; id++) { - const kpt4 = res[0][id]; - const totalScore = Math.round(100 * kpt4[51 + 4]) / 100; - if (totalScore > config3.body.minConfidence) { - const keypoints = []; - for (let i = 0; i < 17; i++) { - const score = kpt4[3 * i + 2]; - if (score > config3.body.minConfidence) { - const positionRaw = [kpt4[3 * i + 1], kpt4[3 * i + 0]]; - keypoints.push({ - part: kpt3[i], - score: Math.round(100 * score) / 100, - positionRaw, - position: [Math.round((image28.shape[2] || 0) * positionRaw[0]), Math.round((image28.shape[1] || 0) * positionRaw[1])] - }); - } - } - const newBox = calc(keypoints.map((pt) => pt.position), [image28.shape[2], image28.shape[1]]); - const annotations2 = {}; - for (const [name, indexes] of Object.entries(connected3)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = keypoints.find((kp) => kp.part === indexes[i]); - const pt1 = keypoints.find((kp) => kp.part === indexes[i + 1]); - if (pt0 && pt1 && pt0.score > (config3.body.minConfidence || 0) && pt1.score > (config3.body.minConfidence || 0)) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - const body4 = { id, score: totalScore, box: newBox.box, boxRaw: newBox.boxRaw, keypoints: [...keypoints], annotations: annotations2 }; - bodyParts(body4); - bodies.push(body4); - } - } - bodies.sort((a, b) => b.score - a.score); - if (bodies.length > config3.body.maxDetected) - bodies.length = config3.body.maxDetected; - return bodies; -} -async function predict17(input, config3) { - var _a; - if (!(model18 == null ? void 0 : model18["executor"]) || !((_a = model18 == null ? void 0 : model18.inputs) == null ? void 0 : _a[0].shape)) - return []; - if (!config3.skipAllowed) - cache6.boxes.length = 0; - skipped14++; - const skipTime = (config3.body.skipTime || 0) > now() - cache6.last; - const skipFrame = skipped14 < (config3.body.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame) { - return cache6.bodies; - } - return new Promise(async (resolve) => { - const t2 = {}; - skipped14 = 0; - t2.input = padInput(input, inputSize8); - t2.res = model18 == null ? void 0 : model18.execute(t2.input); - cache6.last = now(); - const res = await t2.res.array(); - cache6.bodies = t2.res.shape[2] === 17 ? parseSinglePose(res, config3, input) : parseMultiPose(res, config3, input); - for (const body4 of cache6.bodies) { - rescaleBody(body4, [input.shape[2] || 1, input.shape[1] || 1]); - jitter(body4.keypoints); - } - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - resolve(cache6.bodies); - }); -} - -// src/object/nanodet.ts -var model19; -var last10 = []; -var lastTime15 = 0; -var skipped15 = Number.MAX_SAFE_INTEGER; -var inputSize9 = 0; -var scaleBox = 2.5; -async function load18(config3) { - if (!model19 || env.initial) { - model19 = await loadModel(config3.object.modelPath); - const inputs = (model19 == null ? void 0 : model19["executor"]) ? Object.values(model19.modelSignature["inputs"]) : void 0; - inputSize9 = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 416; - } else if (config3.debug) - log("cached model:", model19["modelUrl"]); - return model19; -} -async function process4(res, outputShape, config3) { - var _a, _b; - let id = 0; - let results = []; - const size2 = inputSize9; - for (const strideSize of [1, 2, 4]) { - const baseSize = strideSize * 13; - const scoresT = tfjs_esm_exports.squeeze(res.find((a) => a.shape[1] === baseSize ** 2 && (a.shape[2] || 0) === labels2.length)); - const scores = await scoresT.array(); - const featuresT = tfjs_esm_exports.squeeze(res.find((a) => a.shape[1] === baseSize ** 2 && (a.shape[2] || 0) < labels2.length)); - const boxesMaxT = tfjs_esm_exports.reshape(featuresT, [-1, 4, (((_a = featuresT.shape) == null ? void 0 : _a[1]) || 0) / 4]); - const boxIdxT = tfjs_esm_exports.argMax(boxesMaxT, 2); - const boxIdx = await boxIdxT.array(); - for (let i = 0; i < scoresT.shape[0]; i++) { - for (let j = 0; j < (((_b = scoresT.shape) == null ? void 0 : _b[1]) || 0); j++) { - const score = scores[i][j]; - if (score > (config3.object.minConfidence || 0) && j !== 61) { - const cx = (0.5 + Math.trunc(i % baseSize)) / baseSize; - const cy = (0.5 + Math.trunc(i / baseSize)) / baseSize; - const boxOffset = boxIdx[i].map((a) => a * (baseSize / strideSize / size2)); - const [x, y] = [ - cx - scaleBox / strideSize * boxOffset[0], - cy - scaleBox / strideSize * boxOffset[1] - ]; - const [w, h] = [ - cx + scaleBox / strideSize * boxOffset[2] - x, - cy + scaleBox / strideSize * boxOffset[3] - y - ]; - let boxRaw = [x, y, w, h]; - boxRaw = boxRaw.map((a) => Math.max(0, Math.min(a, 1))); - const box = [ - boxRaw[0] * outputShape[0], - boxRaw[1] * outputShape[1], - boxRaw[2] * outputShape[0], - boxRaw[3] * outputShape[1] - ]; - const result = { - id: id++, - score: Math.round(100 * score) / 100, - class: j + 1, - label: labels2[j].label, - box: box.map((a) => Math.trunc(a)), - boxRaw - }; - results.push(result); - } - } - } - tfjs_esm_exports.dispose([scoresT, featuresT, boxesMaxT, boxIdxT]); - } - const nmsBoxes = results.map((a) => [a.boxRaw[1], a.boxRaw[0], a.boxRaw[3], a.boxRaw[2]]); - const nmsScores = results.map((a) => a.score); - let nmsIdx = []; - if (nmsBoxes && nmsBoxes.length > 0) { - const nms = await tfjs_esm_exports.image.nonMaxSuppressionAsync(nmsBoxes, nmsScores, config3.object.maxDetected || 0, config3.object.iouThreshold, config3.object.minConfidence); - nmsIdx = Array.from(await nms.data()); - tfjs_esm_exports.dispose(nms); - } - results = results.filter((_val, idx) => nmsIdx.includes(idx)).sort((a, b) => b.score - a.score); - return results; -} -async function predict18(image28, config3) { - if (!(model19 == null ? void 0 : model19["executor"])) - return []; - const skipTime = (config3.object.skipTime || 0) > now() - lastTime15; - const skipFrame = skipped15 < (config3.object.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && last10.length > 0) { - skipped15++; - return last10; - } - skipped15 = 0; - if (!env.kernels.includes("mod") || !env.kernels.includes("sparsetodense")) - return last10; - return new Promise(async (resolve) => { - const outputSize2 = [image28.shape[2] || 0, image28.shape[1] || 0]; - const resizeT = tfjs_esm_exports.image.resizeBilinear(image28, [inputSize9, inputSize9], false); - const normT = tfjs_esm_exports.div(resizeT, constants.tf255); - const transposeT = tfjs_esm_exports.transpose(normT, [0, 3, 1, 2]); - let objectT; - if (config3.object.enabled) - objectT = model19.execute(transposeT); - lastTime15 = now(); - const obj = await process4(objectT, outputSize2, config3); - last10 = obj; - tfjs_esm_exports.dispose([resizeT, normT, transposeT, ...objectT]); - resolve(obj); - }); -} - -// src/body/posenetutils.ts -var partNames = [ - "nose", - "leftEye", - "rightEye", - "leftEar", - "rightEar", - "leftShoulder", - "rightShoulder", - "leftElbow", - "rightElbow", - "leftWrist", - "rightWrist", - "leftHip", - "rightHip", - "leftKnee", - "rightKnee", - "leftAnkle", - "rightAnkle" -]; -var count = partNames.length; -var partIds = partNames.reduce((result, jointName, i) => { - result[jointName] = i; - return result; -}, {}); -var connectedPartNames = [ - ["leftHip", "leftShoulder"], - ["leftElbow", "leftShoulder"], - ["leftElbow", "leftWrist"], - ["leftHip", "leftKnee"], - ["leftKnee", "leftAnkle"], - ["rightHip", "rightShoulder"], - ["rightElbow", "rightShoulder"], - ["rightElbow", "rightWrist"], - ["rightHip", "rightKnee"], - ["rightKnee", "rightAnkle"], - ["leftShoulder", "rightShoulder"], - ["leftHip", "rightHip"] -]; -var connectedPartIndices = connectedPartNames.map(([jointNameA, jointNameB]) => [partIds[jointNameA], partIds[jointNameB]]); -var poseChain = [ - ["nose", "leftEye"], - ["leftEye", "leftEar"], - ["nose", "rightEye"], - ["rightEye", "rightEar"], - ["nose", "leftShoulder"], - ["leftShoulder", "leftElbow"], - ["leftElbow", "leftWrist"], - ["leftShoulder", "leftHip"], - ["leftHip", "leftKnee"], - ["leftKnee", "leftAnkle"], - ["nose", "rightShoulder"], - ["rightShoulder", "rightElbow"], - ["rightElbow", "rightWrist"], - ["rightShoulder", "rightHip"], - ["rightHip", "rightKnee"], - ["rightKnee", "rightAnkle"] -]; -function getBoundingBox(keypoints) { - const coord = keypoints.reduce(({ maxX, maxY, minX, minY }, { position: { x, y } }) => ({ - maxX: Math.max(maxX, x), - maxY: Math.max(maxY, y), - minX: Math.min(minX, x), - minY: Math.min(minY, y) - }), { - maxX: Number.NEGATIVE_INFINITY, - maxY: Number.NEGATIVE_INFINITY, - minX: Number.POSITIVE_INFINITY, - minY: Number.POSITIVE_INFINITY - }); - return [coord.minX, coord.minY, coord.maxX - coord.minX, coord.maxY - coord.minY]; -} -function scalePoses(poses, [height, width], [inputResolutionHeight, inputResolutionWidth]) { - const scaleY = height / inputResolutionHeight; - const scaleX = width / inputResolutionWidth; - const scalePose = (pose, i) => ({ - id: i, - score: pose.score, - boxRaw: [pose.box[0] / inputResolutionWidth, pose.box[1] / inputResolutionHeight, pose.box[2] / inputResolutionWidth, pose.box[3] / inputResolutionHeight], - box: [Math.trunc(pose.box[0] * scaleX), Math.trunc(pose.box[1] * scaleY), Math.trunc(pose.box[2] * scaleX), Math.trunc(pose.box[3] * scaleY)], - keypoints: pose.keypoints.map(({ score, part, position }) => ({ - score, - part, - position: [Math.trunc(position.x * scaleX), Math.trunc(position.y * scaleY)], - positionRaw: [position.x / inputResolutionHeight, position.y / inputResolutionHeight] - })), - annotations: {} - }); - const scaledPoses = poses.map((pose, i) => scalePose(pose, i)); - return scaledPoses; -} -var MaxHeap = class { - constructor(maxSize2, getElementValue) { - __publicField(this, "priorityQueue"); - __publicField(this, "numberOfElements"); - __publicField(this, "getElementValue"); - this.priorityQueue = new Array(maxSize2); - this.numberOfElements = -1; - this.getElementValue = getElementValue; - } - enqueue(x) { - this.priorityQueue[++this.numberOfElements] = x; - this.swim(this.numberOfElements); - } - dequeue() { - const max5 = this.priorityQueue[0]; - this.exchange(0, this.numberOfElements--); - this.sink(0); - this.priorityQueue[this.numberOfElements + 1] = null; - return max5; - } - empty() { - return this.numberOfElements === -1; - } - size() { - return this.numberOfElements + 1; - } - all() { - return this.priorityQueue.slice(0, this.numberOfElements + 1); - } - max() { - return this.priorityQueue[0]; - } - swim(k) { - while (k > 0 && this.less(Math.floor(k / 2), k)) { - this.exchange(k, Math.floor(k / 2)); - k = Math.floor(k / 2); - } - } - sink(k) { - while (2 * k <= this.numberOfElements) { - let j = 2 * k; - if (j < this.numberOfElements && this.less(j, j + 1)) - j++; - if (!this.less(k, j)) - break; - this.exchange(k, j); - k = j; - } - } - getValueAt(i) { - return this.getElementValue(this.priorityQueue[i]); - } - less(i, j) { - return this.getValueAt(i) < this.getValueAt(j); - } - exchange(i, j) { - const t2 = this.priorityQueue[i]; - this.priorityQueue[i] = this.priorityQueue[j]; - this.priorityQueue[j] = t2; - } -}; -function getOffsetPoint(y, x, keypoint, offsets) { - return { - y: offsets.get(y, x, keypoint), - x: offsets.get(y, x, keypoint + count) - }; -} -function getImageCoords(part, outputStride2, offsets) { - const { heatmapY, heatmapX, id: keypoint } = part; - const { y, x } = getOffsetPoint(heatmapY, heatmapX, keypoint, offsets); - return { - x: part.heatmapX * outputStride2 + x, - y: part.heatmapY * outputStride2 + y - }; -} -function clamp(a, min2, max5) { - if (a < min2) - return min2; - if (a > max5) - return max5; - return a; -} -function squaredDistance(y1, x1, y2, x2) { - const dy = y2 - y1; - const dx = x2 - x1; - return dy * dy + dx * dx; -} -function addVectors(a, b) { - return { x: a.x + b.x, y: a.y + b.y }; -} - -// src/body/posenet.ts -var model20; -var poseNetOutputs = ["MobilenetV1/offset_2/BiasAdd", "MobilenetV1/heatmap_2/BiasAdd", "MobilenetV1/displacement_fwd_2/BiasAdd", "MobilenetV1/displacement_bwd_2/BiasAdd"]; -var localMaximumRadius = 1; -var outputStride = 16; -var squaredNmsRadius = 50 ** 2; -function traverse(edgeId, sourceKeypoint, targetId, scores, offsets, displacements, offsetRefineStep = 2) { - const getDisplacement = (point2) => ({ - y: displacements.get(point2.y, point2.x, edgeId), - x: displacements.get(point2.y, point2.x, displacements.shape[2] / 2 + edgeId) - }); - const getStridedIndexNearPoint = (point2, height2, width2) => ({ - y: clamp(Math.round(point2.y / outputStride), 0, height2 - 1), - x: clamp(Math.round(point2.x / outputStride), 0, width2 - 1) - }); - const [height, width] = scores.shape; - const sourceKeypointIndices = getStridedIndexNearPoint(sourceKeypoint.position, height, width); - const displacement = getDisplacement(sourceKeypointIndices); - const displacedPoint = addVectors(sourceKeypoint.position, displacement); - let targetKeypoint = displacedPoint; - for (let i = 0; i < offsetRefineStep; i++) { - const targetKeypointIndices = getStridedIndexNearPoint(targetKeypoint, height, width); - const offsetPoint = getOffsetPoint(targetKeypointIndices.y, targetKeypointIndices.x, targetId, offsets); - targetKeypoint = addVectors( - { x: targetKeypointIndices.x * outputStride, y: targetKeypointIndices.y * outputStride }, - { x: offsetPoint.x, y: offsetPoint.y } - ); - } - const targetKeyPointIndices = getStridedIndexNearPoint(targetKeypoint, height, width); - const score = scores.get(targetKeyPointIndices.y, targetKeyPointIndices.x, targetId); - return { position: targetKeypoint, part: partNames[targetId], score }; -} -function decodePose(root, scores, offsets, displacementsFwd, displacementsBwd) { - const tuples = poseChain.map(([parentJoinName, childJoinName]) => [partIds[parentJoinName], partIds[childJoinName]]); - const edgesFwd = tuples.map(([, childJointId]) => childJointId); - const edgesBwd = tuples.map(([parentJointId]) => parentJointId); - const numParts = scores.shape[2]; - const numEdges = edgesFwd.length; - const keypoints = new Array(numParts); - const rootPoint = getImageCoords(root.part, outputStride, offsets); - keypoints[root.part.id] = { - score: root.score, - part: partNames[root.part.id], - position: rootPoint - }; - for (let edge = numEdges - 1; edge >= 0; --edge) { - const sourceId = edgesFwd[edge]; - const targetId = edgesBwd[edge]; - if (keypoints[sourceId] && !keypoints[targetId]) { - keypoints[targetId] = traverse(edge, keypoints[sourceId], targetId, scores, offsets, displacementsBwd); - } - } - for (let edge = 0; edge < numEdges; ++edge) { - const sourceId = edgesBwd[edge]; - const targetId = edgesFwd[edge]; - if (keypoints[sourceId] && !keypoints[targetId]) { - keypoints[targetId] = traverse(edge, keypoints[sourceId], targetId, scores, offsets, displacementsFwd); - } - } - return keypoints; -} -function scoreIsMaximumInLocalWindow(keypointId, score, heatmapY, heatmapX, scores) { - const [height, width] = scores.shape; - let localMaximum = true; - const yStart = Math.max(heatmapY - localMaximumRadius, 0); - const yEnd = Math.min(heatmapY + localMaximumRadius + 1, height); - for (let yCurrent = yStart; yCurrent < yEnd; ++yCurrent) { - const xStart = Math.max(heatmapX - localMaximumRadius, 0); - const xEnd = Math.min(heatmapX + localMaximumRadius + 1, width); - for (let xCurrent = xStart; xCurrent < xEnd; ++xCurrent) { - if (scores.get(yCurrent, xCurrent, keypointId) > score) { - localMaximum = false; - break; - } - } - if (!localMaximum) - break; - } - return localMaximum; -} -function buildPartWithScoreQueue(minConfidence2, scores) { - const [height, width, numKeypoints] = scores.shape; - const queue = new MaxHeap(height * width * numKeypoints, ({ score }) => score); - for (let heatmapY = 0; heatmapY < height; ++heatmapY) { - for (let heatmapX = 0; heatmapX < width; ++heatmapX) { - for (let keypointId = 0; keypointId < numKeypoints; ++keypointId) { - const score = scores.get(heatmapY, heatmapX, keypointId); - if (score < minConfidence2) - continue; - if (scoreIsMaximumInLocalWindow(keypointId, score, heatmapY, heatmapX, scores)) - queue.enqueue({ score, part: { heatmapY, heatmapX, id: keypointId } }); - } - } - } - return queue; -} -function withinRadius(poses, { x, y }, keypointId) { - return poses.some(({ keypoints }) => { - var _a; - const correspondingKeypoint = (_a = keypoints[keypointId]) == null ? void 0 : _a.position; - if (!correspondingKeypoint) - return false; - return squaredDistance(y, x, correspondingKeypoint.y, correspondingKeypoint.x) <= squaredNmsRadius; - }); -} -function getInstanceScore(existingPoses, keypoints) { - const notOverlappedKeypointScores = keypoints.reduce((result, { position, score }, keypointId) => { - if (!withinRadius(existingPoses, position, keypointId)) - result += score; - return result; - }, 0); - return notOverlappedKeypointScores / keypoints.length; -} -function decode(offsets, scores, displacementsFwd, displacementsBwd, maxDetected, minConfidence2) { - const poses = []; - const queue = buildPartWithScoreQueue(minConfidence2, scores); - while (poses.length < maxDetected && !queue.empty()) { - const root = queue.dequeue(); - const rootImageCoords = getImageCoords(root.part, outputStride, offsets); - if (withinRadius(poses, rootImageCoords, root.part.id)) - continue; - let keypoints = decodePose(root, scores, offsets, displacementsFwd, displacementsBwd); - keypoints = keypoints.filter((a) => a.score > minConfidence2); - const score = getInstanceScore(poses, keypoints); - const box = getBoundingBox(keypoints); - if (score > minConfidence2) - poses.push({ keypoints, box, score: Math.round(100 * score) / 100 }); - } - return poses; -} -async function predict19(input, config3) { - if (!(model20 == null ? void 0 : model20["executor"])) - return []; - const res = tfjs_esm_exports.tidy(() => { - if (!model20.inputs[0].shape) - return []; - const resized = tfjs_esm_exports.image.resizeBilinear(input, [model20.inputs[0].shape[2], model20.inputs[0].shape[1]]); - const normalized = tfjs_esm_exports.sub(tfjs_esm_exports.div(tfjs_esm_exports.cast(resized, "float32"), 127.5), 1); - const results = model20.execute(normalized, poseNetOutputs); - const results3d = results.map((y) => tfjs_esm_exports.squeeze(y, [0])); - results3d[1] = tfjs_esm_exports.sigmoid(results3d[1]); - return results3d; - }); - const buffers = await Promise.all(res.map((tensor6) => tensor6.buffer())); - for (const t2 of res) - tfjs_esm_exports.dispose(t2); - const decoded = decode(buffers[0], buffers[1], buffers[2], buffers[3], config3.body.maxDetected, config3.body.minConfidence); - if (!model20.inputs[0].shape) - return []; - const scaled = scalePoses(decoded, [input.shape[1], input.shape[2]], [model20.inputs[0].shape[2], model20.inputs[0].shape[1]]); - return scaled; -} -async function load19(config3) { - if (!model20 || env.initial) - model20 = await loadModel(config3.body.modelPath); - else if (config3.debug) - log("cached model:", model20["modelUrl"]); - return model20; -} - -// src/segmentation/rvm.ts -var model21; -var outputNodes2 = ["fgr", "pha", "r1o", "r2o", "r3o", "r4o"]; -var t = {}; -var ratio = 0; -function init3(config3) { - tfjs_esm_exports.dispose([t.r1i, t.r2i, t.r3i, t.r4i, t.downsample_ratio]); - t.r1i = tfjs_esm_exports.tensor(0); - t.r2i = tfjs_esm_exports.tensor(0); - t.r3i = tfjs_esm_exports.tensor(0); - t.r4i = tfjs_esm_exports.tensor(0); - ratio = config3.segmentation.ratio || 0.5; - t.downsample_ratio = tfjs_esm_exports.tensor(ratio); -} -async function load20(config3) { - if (!model21 || env.initial) - model21 = await loadModel(config3.segmentation.modelPath); - else if (config3.debug) - log("cached model:", model21["modelUrl"]); - init3(config3); - return model21; -} -var normalize = (r) => tfjs_esm_exports.tidy(() => { - const squeeze14 = tfjs_esm_exports.squeeze(r, [0]); - const mul15 = tfjs_esm_exports.mul(squeeze14, constants.tf255); - const cast8 = tfjs_esm_exports.cast(mul15, "int32"); - return cast8; -}); -function getRGBA(fgr, pha) { - const rgb2 = fgr ? normalize(fgr) : tfjs_esm_exports.fill([pha.shape[1] || 0, pha.shape[2] || 0, 3], 255, "int32"); - const a = pha ? normalize(pha) : tfjs_esm_exports.fill([fgr.shape[1] || 0, fgr.shape[2] || 0, 1], 255, "int32"); - const rgba = tfjs_esm_exports.concat([rgb2, a], -1); - tfjs_esm_exports.dispose([rgb2, a]); - return rgba; -} -function getState(state) { - return tfjs_esm_exports.tidy(() => { - const r = {}; - r.unstack = tfjs_esm_exports.unstack(state, -1); - r.concat = tfjs_esm_exports.concat(r.unstack, 1); - r.split = tfjs_esm_exports.split(r.concat, 4, 1); - r.stack = tfjs_esm_exports.concat(r.split, 2); - r.squeeze = tfjs_esm_exports.squeeze(r.stack, [0]); - r.expand = tfjs_esm_exports.expandDims(r.squeeze, -1); - r.add = tfjs_esm_exports.add(r.expand, 1); - r.mul = tfjs_esm_exports.mul(r.add, 127.5); - r.cast = tfjs_esm_exports.cast(r.mul, "int32"); - r.tile = tfjs_esm_exports.tile(r.cast, [1, 1, 3]); - r.alpha = tfjs_esm_exports.fill([r.tile.shape[0] || 0, r.tile.shape[1] || 0, 1], 255, "int32"); - return tfjs_esm_exports.concat([r.tile, r.alpha], -1); - }); -} -async function predict20(input, config3) { - if (!model21) - model21 = await load20(config3); - if (!(model21 == null ? void 0 : model21["executor"])) - return null; - t.src = tfjs_esm_exports.div(input, 255); - if (ratio !== config3.segmentation.ratio) - init3(config3); - const [fgr, pha, r1o, r2o, r3o, r4o] = await model21.executeAsync(t, outputNodes2); - let rgba; - switch (config3.segmentation.mode || "default") { - case "default": - rgba = getRGBA(fgr, pha); - break; - case "alpha": - rgba = getRGBA(null, pha); - break; - case "foreground": - rgba = getRGBA(fgr, null); - break; - case "state": - rgba = getState(r1o); - break; - default: - rgba = tfjs_esm_exports.tensor(0); - } - tfjs_esm_exports.dispose([t.src, fgr, pha, t.r1i, t.r2i, t.r3i, t.r4i]); - [t.r1i, t.r2i, t.r3i, t.r4i] = [r1o, r2o, r3o, r4o]; - return rgba; -} - -// src/segmentation/selfie.ts -var model22; -async function load21(config3) { - if (!model22 || env.initial) - model22 = await loadModel(config3.segmentation.modelPath); - else if (config3.debug) - log("cached model:", model22["modelUrl"]); - return model22; -} -async function predict21(input, config3) { - var _a; - if (!model22) - model22 = await load21(config3); - if (!(model22 == null ? void 0 : model22["executor"]) || !((_a = model22 == null ? void 0 : model22.inputs) == null ? void 0 : _a[0].shape)) - return null; - const t2 = {}; - t2.resize = tfjs_esm_exports.image.resizeBilinear(input, [model22.inputs[0].shape ? model22.inputs[0].shape[1] : 0, model22.inputs[0].shape ? model22.inputs[0].shape[2] : 0], false); - t2.norm = tfjs_esm_exports.div(t2.resize, constants.tf255); - t2.res = model22.execute(t2.norm); - t2.squeeze = tfjs_esm_exports.squeeze(t2.res, [0]); - t2.alpha = tfjs_esm_exports.image.resizeBilinear(t2.squeeze, [input.shape[1] || 0, input.shape[2] || 0]); - t2.mul = tfjs_esm_exports.mul(t2.alpha, constants.tf255); - let rgba; - switch (config3.segmentation.mode || "default") { - case "default": - t2.input = tfjs_esm_exports.squeeze(input); - t2.concat = tfjs_esm_exports.concat([t2.input, t2.mul], -1); - rgba = tfjs_esm_exports.cast(t2.concat, "int32"); - break; - case "alpha": - rgba = tfjs_esm_exports.cast(t2.mul, "int32"); - break; - default: - rgba = tfjs_esm_exports.tensor(0); - } - Object.keys(t2).forEach((tensor6) => tfjs_esm_exports.dispose(t2[tensor6])); - return rgba; -} - -// src/models.ts -function validateModel(instance, model23, name) { - var _a, _b; - if (!model23) - return null; - if (!((_a = instance == null ? void 0 : instance.config) == null ? void 0 : _a.validateModels)) - return null; - const simpleOps = ["const", "placeholder", "noop", "pad", "squeeze", "add", "sub", "mul", "div"]; - const ignoreOps = ["biasadd", "fusedbatchnormv3", "matmul", "switch", "shape", "merge", "split", "broadcastto"]; - const ops = []; - const missing = []; - const url = model23["modelUrl"]; - const executor = model23["executor"]; - if ((_b = executor == null ? void 0 : executor.graph) == null ? void 0 : _b.nodes) { - for (const kernel of Object.values(executor.graph.nodes)) { - const op = kernel.op.toLowerCase(); - if (!ops.includes(op)) - ops.push(op); - } - } else { - if (!executor && instance.config.debug) { - log("model not loaded", name); - } - } - for (const op of ops) { - if (!simpleOps.includes(op) && !ignoreOps.includes(op) && !instance.env.kernels.includes(op) && !instance.env.kernels.includes(op.replace("_", "")) && !instance.env.kernels.includes(op.replace("native", "")) && !instance.env.kernels.includes(op.replace("v2", ""))) { - missing.push(op); - } - } - if (instance.config.debug && missing.length > 0) - log("model validation failed:", name, missing); - return missing.length > 0 ? { name, missing, ops, url } : null; -} -var Models = class { - constructor(currentInstance) { - __publicField(this, "instance"); - __publicField(this, "models", {}); - this.models = {}; - this.instance = currentInstance; - } - stats() { - let totalSizeFromManifest = 0; - let totalSizeWeights = 0; - let totalSizeLoading = 0; - for (const m of Object.values(modelStats)) { - totalSizeFromManifest += m.sizeFromManifest; - totalSizeWeights += m.sizeLoadedWeights; - totalSizeLoading += m.sizeDesired; - } - const percentageLoaded = totalSizeLoading > 0 ? totalSizeWeights / totalSizeLoading : 0; - return { - numLoadedModels: Object.values(modelStats).length, - numDefinedModels: Object.keys(this.models).length, - percentageLoaded, - totalSizeFromManifest, - totalSizeWeights, - totalSizeLoading, - modelStats: Object.values(modelStats) - }; - } - reset() { - for (const model23 of Object.keys(this.models)) - this.models[model23] = null; - } - async load(instance) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A; - if (env.initial) - this.reset(); - if (instance) - this.instance = instance; - const m = {}; - m.blazeface = this.instance.config.face.enabled && !this.models.blazeface ? load3(this.instance.config) : null; - m.antispoof = this.instance.config.face.enabled && ((_a = this.instance.config.face.antispoof) == null ? void 0 : _a.enabled) && !this.models.antispoof ? load8(this.instance.config) : null; - m.liveness = this.instance.config.face.enabled && ((_b = this.instance.config.face.liveness) == null ? void 0 : _b.enabled) && !this.models.liveness ? load9(this.instance.config) : null; - m.faceres = this.instance.config.face.enabled && ((_c = this.instance.config.face.description) == null ? void 0 : _c.enabled) && !this.models.faceres ? load7(this.instance.config) : null; - m.emotion = this.instance.config.face.enabled && ((_d = this.instance.config.face.emotion) == null ? void 0 : _d.enabled) && !this.models.emotion ? load6(this.instance.config) : null; - m.iris = this.instance.config.face.enabled && ((_e = this.instance.config.face.iris) == null ? void 0 : _e.enabled) && !((_f = this.instance.config.face.attention) == null ? void 0 : _f.enabled) && !this.models.iris ? load4(this.instance.config) : null; - m.facemesh = this.instance.config.face.enabled && ((_g = this.instance.config.face.mesh) == null ? void 0 : _g.enabled) && !this.models.facemesh ? load5(this.instance.config) : null; - m.gear = this.instance.config.face.enabled && ((_h = this.instance.config.face["gear"]) == null ? void 0 : _h.enabled) && !this.models.gear ? load10(this.instance.config) : null; - m.ssrnetage = this.instance.config.face.enabled && ((_i = this.instance.config.face["ssrnet"]) == null ? void 0 : _i.enabled) && !this.models.ssrnetage ? load11(this.instance.config) : null; - m.ssrnetgender = this.instance.config.face.enabled && ((_j = this.instance.config.face["ssrnet"]) == null ? void 0 : _j.enabled) && !this.models.ssrnetgender ? load12(this.instance.config) : null; - m.mobilefacenet = this.instance.config.face.enabled && ((_k = this.instance.config.face["mobilefacenet"]) == null ? void 0 : _k.enabled) && !this.models.mobilefacenet ? load13(this.instance.config) : null; - m.insightface = this.instance.config.face.enabled && ((_l = this.instance.config.face["insightface"]) == null ? void 0 : _l.enabled) && !this.models.insightface ? load14(this.instance.config) : null; - m.blazepose = this.instance.config.body.enabled && !this.models.blazepose && ((_m = this.instance.config.body.modelPath) == null ? void 0 : _m.includes("blazepose")) ? loadPose(this.instance.config) : null; - m.blazeposedetect = this.instance.config.body.enabled && !this.models.blazeposedetect && this.instance.config.body["detector"] && this.instance.config.body["detector"].modelPath ? loadDetect(this.instance.config) : null; - m.efficientpose = this.instance.config.body.enabled && !this.models.efficientpose && ((_n = this.instance.config.body.modelPath) == null ? void 0 : _n.includes("efficientpose")) ? load2(this.instance.config) : null; - m.movenet = this.instance.config.body.enabled && !this.models.movenet && ((_o = this.instance.config.body.modelPath) == null ? void 0 : _o.includes("movenet")) ? load17(this.instance.config) : null; - m.posenet = this.instance.config.body.enabled && !this.models.posenet && ((_p = this.instance.config.body.modelPath) == null ? void 0 : _p.includes("posenet")) ? load19(this.instance.config) : null; - m.handtrack = this.instance.config.hand.enabled && !this.models.handtrack && ((_r = (_q = this.instance.config.hand.detector) == null ? void 0 : _q.modelPath) == null ? void 0 : _r.includes("handtrack")) ? loadDetect2(this.instance.config) : null; - m.handskeleton = this.instance.config.hand.enabled && this.instance.config.hand.landmarks && !this.models.handskeleton && ((_t = (_s = this.instance.config.hand.detector) == null ? void 0 : _s.modelPath) == null ? void 0 : _t.includes("handtrack")) ? loadSkeleton(this.instance.config) : null; - if ((_v = (_u = this.instance.config.hand.detector) == null ? void 0 : _u.modelPath) == null ? void 0 : _v.includes("handdetect")) - [m.handpose, m.handskeleton] = !this.models.handpose ? await load15(this.instance.config) : [null, null]; - m.centernet = this.instance.config.object.enabled && !this.models.centernet && ((_w = this.instance.config.object.modelPath) == null ? void 0 : _w.includes("centernet")) ? load(this.instance.config) : null; - m.nanodet = this.instance.config.object.enabled && !this.models.nanodet && ((_x = this.instance.config.object.modelPath) == null ? void 0 : _x.includes("nanodet")) ? load18(this.instance.config) : null; - m.selfie = this.instance.config.segmentation.enabled && !this.models.selfie && ((_y = this.instance.config.segmentation.modelPath) == null ? void 0 : _y.includes("selfie")) ? load21(this.instance.config) : null; - m.meet = this.instance.config.segmentation.enabled && !this.models.meet && ((_z = this.instance.config.segmentation.modelPath) == null ? void 0 : _z.includes("meet")) ? load16(this.instance.config) : null; - m.rvm = this.instance.config.segmentation.enabled && !this.models.rvm && ((_A = this.instance.config.segmentation.modelPath) == null ? void 0 : _A.includes("rvm")) ? load20(this.instance.config) : null; - for (const [model23, promise] of Object.entries(m)) { - if (promise == null ? void 0 : promise["then"]) - promise["then"]((val) => this.models[model23] = val); - } - await Promise.all(Object.values(m)); - } - list() { - const models3 = Object.keys(this.models).map((model23) => { - var _a; - return { name: model23, loaded: this.models[model23] !== null, size: 0, url: this.models[model23] ? (_a = this.models[model23]) == null ? void 0 : _a["modelUrl"] : null }; - }); - for (const m of models3) { - const stats = Object.keys(modelStats).find((s) => s.startsWith(m.name)); - if (!stats) - continue; - m.size = modelStats[stats].sizeLoadedWeights; - m.url = modelStats[stats].url; - } - return models3; - } - loaded() { - const list = this.list(); - const loaded = list.filter((model23) => model23.loaded).map((model23) => model23.name); - return loaded; - } - validate() { - const missing = []; - for (const defined of Object.keys(this.models)) { - const model23 = this.models[defined]; - if (!model23) - continue; - const res = validateModel(this.instance, model23, defined); - if (res) - missing.push(res); - } - return missing; - } -}; - -// src/util/persons.ts -function join2(faces, bodies, hands, gestures, shape) { - var _a, _b, _c, _d, _e, _f; - let id = 0; - const persons = []; - for (const face4 of faces) { - const person2 = { id: id++, face: face4, body: null, hands: { left: null, right: null }, gestures: [], box: [0, 0, 0, 0] }; - for (const body4 of bodies) { - if (face4.box[0] > body4.box[0] && face4.box[0] < body4.box[0] + body4.box[2] && face4.box[1] + face4.box[3] > body4.box[1] && face4.box[1] + face4.box[3] < body4.box[1] + body4.box[3]) { - person2.body = body4; - } - } - if (person2.body) { - for (const hand3 of hands) { - if (hand3.box[0] + hand3.box[2] > person2.body.box[0] && hand3.box[0] + hand3.box[2] < person2.body.box[0] + person2.body.box[2] && hand3.box[1] + hand3.box[3] > person2.body.box[1] && hand3.box[1] + hand3.box[3] < person2.body.box[1] + person2.body.box[3]) { - if (person2.hands) - person2.hands.left = hand3; - } - if (hand3.box[0] < person2.body.box[0] + person2.body.box[2] && hand3.box[0] > person2.body.box[0] && hand3.box[1] + hand3.box[3] > person2.body.box[1] && hand3.box[1] + hand3.box[3] < person2.body.box[1] + person2.body.box[3]) { - if (person2.hands) - person2.hands.right = hand3; - } - } - } - for (const gesture2 of gestures) { - if (gesture2["face"] !== void 0 && gesture2["face"] === face4.id) - person2.gestures.push(gesture2); - else if (gesture2["iris"] !== void 0 && gesture2["iris"] === face4.id) - person2.gestures.push(gesture2); - else if (gesture2["body"] !== void 0 && gesture2["body"] === ((_a = person2.body) == null ? void 0 : _a.id)) - person2.gestures.push(gesture2); - else if (gesture2["hand"] !== void 0 && gesture2["hand"] === ((_b = person2.hands.left) == null ? void 0 : _b.id)) - person2.gestures.push(gesture2); - else if (gesture2["hand"] !== void 0 && gesture2["hand"] === ((_c = person2.hands.right) == null ? void 0 : _c.id)) - person2.gestures.push(gesture2); - } - const x = []; - const y = []; - const extractXY = (box) => { - if (box && box.length === 4) { - x.push(box[0], box[0] + box[2]); - y.push(box[1], box[1] + box[3]); - } - }; - extractXY(person2.face.box); - extractXY((_d = person2.body) == null ? void 0 : _d.box); - extractXY((_e = person2.hands.left) == null ? void 0 : _e.box); - extractXY((_f = person2.hands.right) == null ? void 0 : _f.box); - const minX = Math.min(...x); - const minY = Math.min(...y); - person2.box = [minX, minY, Math.max(...x) - minX, Math.max(...y) - minY]; - if ((shape == null ? void 0 : shape[1]) && (shape == null ? void 0 : shape[2])) - person2.boxRaw = [person2.box[0] / shape[2], person2.box[1] / shape[1], person2.box[2] / shape[2], person2.box[3] / shape[1]]; - persons.push(person2); - } - return persons; -} - -// src/sample.ts -var face3 = ` + gaze: [gaze]\xB0`,body:"body [score]%",bodyPart:"[label] [score]%",object:"[label] [score]%",hand:"[label] [score]%",finger:"[label]",gesture:"[where] [who]: [what]"};var ut=0;function Hr(e,t,n){let o=Q(e0,n);if(!t||!e)return;let s=S0(e);if(!!s){s.lineJoin="round",s.font=o.font;for(let A=0;ATt,kpt:()=>gt});var gt=["nose","leftEyeInside","leftEye","leftEyeOutside","rightEyeInside","rightEye","rightEyeOutside","leftEar","rightEar","leftMouth","rightMouth","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftPinky","rightPinky","leftIndex","rightIndex","leftThumb","rightThumb","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle","leftHeel","rightHeel","leftFoot","rightFoot","bodyCenter","bodyTop","leftPalm","leftHand","rightPalm","rightHand"],Tt={shoulders:["leftShoulder","rightShoulder"],hips:["rightHip","leftHip"],mouth:["leftMouth","rightMouth"],leftLegUpper:["leftHip","leftKnee"],leftLegLower:["leftKnee","leftAnkle"],leftFoot:["leftAnkle","leftHeel","leftFoot"],leftTorso:["leftShoulder","leftHip"],leftArmUpper:["leftShoulder","leftElbow"],leftArmLower:["leftElbow","leftWrist"],leftHand:["leftWrist","leftPalm"],leftHandPinky:["leftPalm","leftPinky"],leftHandIndex:["leftPalm","leftIndex"],leftHandThumb:["leftPalm","leftThumb"],leftEyeOutline:["leftEyeInside","leftEyeOutside"],rightLegUpper:["rightHip","rightKnee"],rightLegLower:["rightKnee","rightAnkle"],rightFoot:["rightAnkle","rightHeel","rightFoot"],rightTorso:["rightShoulder","rightHip"],rightArmUpper:["rightShoulder","rightElbow"],rightArmLower:["rightElbow","rightWrist"],rightHand:["rightWrist","rightPalm"],rightHandPinky:["rightPalm","rightPinky"],rightHandIndex:["rightPalm","rightIndex"],rightHandThumb:["rightPalm","rightThumb"],rightEyeOutline:["rightEyeInside","rightEyeOutside"]};var j0,Pe=224,A1,Zr=5,M2=[8,16,32,32,32];function Xr(){let e=[],t=0;for(;tn.x)),y:r.tensor1d(e.map(n=>n.y))}}async function a1(e){if(M.initial&&(j0=null),!j0&&e.body.detector&&e.body.detector.modelPath){j0=await L(e.body.detector.modelPath);let t=j0!=null&&j0.executor?Object.values(j0.modelSignature.inputs):void 0;Pe=Array.isArray(t)?parseInt(t[0].tensorShape.dim[1].size):0}else e.debug&&j0&&h("cached model:",j0.modelUrl);return Xr(),j0}var s1=[5,5];function qr(e,t){return r.tidy(()=>{let n=r.split(e,12,1),o=r.squeeze(n[0]),s=r.squeeze(n[1]),A=r.squeeze(n[2]),a=r.squeeze(n[3]);o=r.add(r.div(o,Pe),t.x),s=r.add(r.div(s,Pe),t.y),A=r.mul(r.div(A,Pe),s1[0]),a=r.mul(r.div(a,Pe),s1[1]);let i=r.sub(o,r.div(A,2)),c=r.sub(s,r.div(a,2)),d=r.add(i,A),y=r.add(c,a);return r.stack([i,c,d,y],1)})}async function Ur(e,t,n,o){var d,y;let s=[],A={};A.boxes=qr(e,A1),A.scores=r.sigmoid(t),A.nms=await r.image.nonMaxSuppressionAsync(A.boxes,A.scores,1,((d=n.body.detector)==null?void 0:d.minConfidence)||.1,((y=n.body.detector)==null?void 0:y.iouThreshold)||.1);let a=await A.nms.data(),i=await A.scores.data(),c=await A.boxes.array();for(let l of Array.from(a)){let f=i[l],x=c[l],u=[Math.round(x[0]*o[0]),Math.round(x[1]*o[1]),Math.round(x[2]*o[0]),Math.round(x[3]*o[1])],m={score:f,boxRaw:x,box:u};s.push(m)}return Object.keys(A).forEach(l=>r.dispose(A[l])),s}async function i1(e,t,n){let o={};o.res=j0==null?void 0:j0.execute(e,["Identity"]),o.logitsRaw=r.slice(o.res,[0,0,0],[1,-1,1]),o.boxesRaw=r.slice(o.res,[0,0,1],[1,-1,-1]),o.logits=r.squeeze(o.logitsRaw),o.boxes=r.squeeze(o.boxesRaw);let s=await Ur(o.boxes,o.logits,t,n);return Object.keys(o).forEach(A=>r.dispose(o[A])),s}function J0(e,t=[1,1]){let n=[e.map(i=>i[0]),e.map(i=>i[1])],o=[Math.min(...n[0]),Math.min(...n[1])],s=[Math.max(...n[0]),Math.max(...n[1])],A=[o[0],o[1],s[0]-o[0],s[1]-o[1]],a=[A[0]/t[0],A[1]/t[1],A[2]/t[0],A[3]/t[1]];return{box:A,boxRaw:a}}function l1(e,t=[1,1]){let n=[e.map(d=>d[0]),e.map(d=>d[1])],o=[Math.min(...n[0]),Math.min(...n[1])],s=[Math.max(...n[0]),Math.max(...n[1])],A=[(o[0]+s[0])/2,(o[1]+s[1])/2],a=Math.max(A[0]-o[0],A[1]-o[1],-A[0]+s[0],-A[1]+s[1]),i=[Math.trunc(A[0]-a),Math.trunc(A[1]-a),Math.trunc(2*a),Math.trunc(2*a)],c=[i[0]/t[0],i[1]/t[1],i[2]/t[0],i[3]/t[1]];return{box:i,boxRaw:c}}function P2(e,t){let n=[e[2]*t,e[3]*t];return[e[0]-(n[0]-e[2])/2,e[1]-(n[1]-e[3])/2,n[0],n[1]]}var g0,Rt=256,vt=Number.MAX_SAFE_INTEGER,Yr={landmarks:["ld_3d","activation_segmentation","activation_heatmap","world_3d","output_poseflag"],detector:[]},w2=[],ae=[[0,0],[0,0],[0,0],[0,0]],c1=0,d1=e=>1-1/(1+Math.exp(e)),y1=e=>a1(e);async function f1(e){if(M.initial&&(g0=null),g0)e.debug&&h("cached model:",g0.modelUrl);else{g0=await L(e.body.modelPath);let t=g0!=null&&g0.executor?Object.values(g0.modelSignature.inputs):void 0;Rt=Array.isArray(t)?parseInt(t[0].tensorShape.dim[1].size):0}return g0}function x1(e,t,n){var A,a;let o={};if(!((A=e==null?void 0:e.shape)!=null&&A[1])||!((a=e==null?void 0:e.shape)!=null&&a[2]))return e;let s;if(n&&(o.cropped=r.image.cropAndResize(e,[n],[0],[e.shape[1],e.shape[2]])),e.shape[1]!==e.shape[2]){let i=[e.shape[2]>e.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0,e.shape[2]>e.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0],c=[e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0,e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0];ae=[[0,0],i,c,[0,0]],o.pad=r.pad(o.cropped||e,ae),o.resize=r.image.resizeBilinear(o.pad,[t,t]),s=r.div(o.resize,O.tf255)}else e.shape[1]!==t?(o.resize=r.image.resizeBilinear(o.cropped||e,[t,t]),s=r.div(o.resize,O.tf255)):s=r.div(o.cropped||e,O.tf255);return Object.keys(o).forEach(i=>r.dispose(o[i])),s}function Kr(e,t,n){for(let o of e)o.position=[Math.trunc(o.position[0]*(t[0]+ae[2][0]+ae[2][1])/t[0]-ae[2][0]),Math.trunc(o.position[1]*(t[1]+ae[1][0]+ae[1][1])/t[1]-ae[1][0]),o.position[2]],o.positionRaw=[o.position[0]/t[0],o.position[1]/t[1],2*o.position[2]/(t[0]+t[1])];if(n){let o=n[2]-n[0],s=n[3]-n[1];for(let A of e)A.positionRaw=[A.positionRaw[0]/s+n[1],A.positionRaw[1]/o+n[0],A.positionRaw[2]],A.position=[Math.trunc(A.positionRaw[0]*t[0]),Math.trunc(A.positionRaw[1]*t[1]),A.positionRaw[2]]}return e}function Jr(e){let t=e.find(i=>i.part==="leftPalm"),n=e.find(i=>i.part==="leftWrist"),o=e.find(i=>i.part==="leftIndex");t.position[2]=((n.position[2]||0)+(o.position[2]||0))/2;let s=e.find(i=>i.part==="rightPalm"),A=e.find(i=>i.part==="rightWrist"),a=e.find(i=>i.part==="rightIndex");s.position[2]=((A.position[2]||0)+(a.position[2]||0))/2}async function Qr(e,t,n){if(!(g0!=null&&g0.executor))return null;let o={};[o.ld,o.segmentation,o.heatmap,o.world,o.poseflag]=g0==null?void 0:g0.execute(e,Yr.landmarks);let s=(await o.poseflag.data())[0],A=await o.ld.data(),a=await o.world.data();Object.keys(o).forEach(u=>r.dispose(o[u]));let i=[],c=5;for(let u=0;uu.position),l=J0(y,[n[0],n[1]]),f={};for(let[u,m]of Object.entries(Tt)){let g=[];for(let P=0;Pb.part===m[P]),p=d.find(b=>b.part===m[P+1]);v&&p&&g.push([v.position,p.position])}f[u]=g}return{id:0,score:Math.trunc(100*s)/100,box:l.box,boxRaw:l.boxRaw,keypoints:d,annotations:f}}async function Mt(e,t){var A,a,i;let n=[e.shape[2]||0,e.shape[1]||0],o=(t.body.skipTime||0)>T()-c1,s=vt<(t.body.skipFrames||0);if(t.skipAllowed&&o&&s&&w2!==null)vt++;else{let c=[];if((a=(A=t.body)==null?void 0:A.detector)!=null&&a.enabled){let d=x1(e,224);c=await i1(d,t,n),r.dispose(d)}else c=[{box:[0,0,0,0],boxRaw:[0,0,1,1],score:0}];for(let d=0;dr.dispose(o[d])),s}async function wt(e,t){if(!(T0!=null&&T0.executor))return[];let n=(t.object.skipTime||0)>T()-p1,o=kt<(t.object.skipFrames||0);return t.skipAllowed&&n&&o&&Pt.length>0?(kt++,Pt):(kt=0,new Promise(async s=>{let A=[e.shape[2]||0,e.shape[1]||0],a=r.image.resizeBilinear(e,[ke,ke]),i=t.object.enabled?T0==null?void 0:T0.execute(a,["tower_0/detections"]):null;p1=T(),r.dispose(a);let c=await _r(i,A,t);Pt=c,s(c)}))}var E2={};oe(E2,{connected:()=>zt,kpt:()=>Et});var Et=["head","neck","rightShoulder","rightElbow","rightWrist","chest","leftShoulder","leftElbow","leftWrist","bodyCenter","rightHip","rightKnee","rightAnkle","leftHip","leftKnee","leftAnkle"],zt={leftLeg:["leftHip","leftKnee","leftAnkle"],rightLeg:["rightHip","rightKnee","rightAnkle"],torso:["leftShoulder","rightShoulder","rightHip","leftHip","leftShoulder"],leftArm:["leftShoulder","leftElbow","leftWrist"],rightArm:["rightShoulder","rightElbow","rightWrist"],head:[]};var _,b1=0,h0={id:0,keypoints:[],box:[0,0,0,0],boxRaw:[0,0,0,0],score:0,annotations:{}},St=Number.MAX_SAFE_INTEGER;async function g1(e){return M.initial&&(_=null),_?e.debug&&h("cached model:",_.modelUrl):_=await L(e.body.modelPath),_}async function $r(e,t){let[n,o]=e.shape,s=r.reshape(e,[o*n]),A=r.max(s,0),a=(await A.data())[0];if(a>t){let i=r.argMax(s,0),c=r.mod(i,n),d=(await c.data())[0],y=r.div(i,n),l=(await y.data())[0];return r.dispose([s,A,i,c,y]),[d,l,a]}return r.dispose([s,A]),[0,0,a]}async function jt(e,t){if(!(_!=null&&_.executor)||!(_!=null&&_.inputs[0].shape))return[];let n=(t.body.skipTime||0)>T()-b1,o=St<(t.body.skipFrames||0);return t.skipAllowed&&n&&o&&Object.keys(h0.keypoints).length>0?(St++,[h0]):(St=0,new Promise(async s=>{let A=r.tidy(()=>{var u,m;let l=r.image.resizeBilinear(e,[((u=_==null?void 0:_.inputs[0].shape)==null?void 0:u[2])||0,((m=_==null?void 0:_.inputs[0].shape)==null?void 0:m[1])||0],!1),f=r.mul(l,O.tf2);return r.sub(f,O.tf1)}),a;if(t.body.enabled&&(a=_==null?void 0:_.execute(A)),b1=T(),r.dispose(A),a){h0.keypoints.length=0;let l=r.squeeze(a);r.dispose(a);let f=r.unstack(l,2);r.dispose(l);for(let x=0;x(t.body.minConfidence||0)&&h0.keypoints.push({score:Math.round(100*g)/100,part:Et[x],positionRaw:[u/_.inputs[0].shape[2],m/_.inputs[0].shape[1]],position:[Math.round(e.shape[2]*u/_.inputs[0].shape[2]),Math.round(e.shape[1]*m/_.inputs[0].shape[1])]})}f.forEach(x=>r.dispose(x))}h0.score=h0.keypoints.reduce((l,f)=>f.score>l?f.score:l,0);let i=h0.keypoints.map(l=>l.position[0]),c=h0.keypoints.map(l=>l.position[1]);h0.box=[Math.min(...i),Math.min(...c),Math.max(...i)-Math.min(...i),Math.max(...c)-Math.min(...c)];let d=h0.keypoints.map(l=>l.positionRaw[0]),y=h0.keypoints.map(l=>l.positionRaw[1]);h0.boxRaw=[Math.min(...d),Math.min(...y),Math.max(...d)-Math.min(...d),Math.max(...y)-Math.min(...y)];for(let[l,f]of Object.entries(zt)){let x=[];for(let u=0;uP.part===f[u]),g=h0.keypoints.find(P=>P.part===f[u+1]);m&&g&&m.score>(t.body.minConfidence||0)&&g.score>(t.body.minConfidence||0)&&x.push([m.position,g.position])}h0.annotations[l]=x}s([h0])}))}var We=e=>[Math.abs(e.endPoint[0]-e.startPoint[0]),Math.abs(e.endPoint[1]-e.startPoint[1])],z2=e=>[e.startPoint[0]+(e.endPoint[0]-e.startPoint[0])/2,e.startPoint[1]+(e.endPoint[1]-e.startPoint[1])/2,1],S2=(e,t)=>e?[Math.trunc(Math.max(0,e.startPoint[0])),Math.trunc(Math.max(0,e.startPoint[1])),Math.trunc(Math.min(t.shape[2]||0,e.endPoint[0])-Math.max(0,e.startPoint[0])),Math.trunc(Math.min(t.shape[1]||0,e.endPoint[1])-Math.max(0,e.startPoint[1]))]:[0,0,0,0],j2=(e,t)=>e?[e.startPoint[0]/(t.shape[2]||0),e.startPoint[1]/(t.shape[1]||0),(e.endPoint[0]-e.startPoint[0])/(t.shape[2]||0),(e.endPoint[1]-e.startPoint[1])/(t.shape[1]||0)]:[0,0,0,0],M1=(e,t)=>{let n=[e.startPoint[0]*t[0],e.startPoint[1]*t[1]],o=[e.endPoint[0]*t[0],e.endPoint[1]*t[1]];return{startPoint:n,endPoint:o,landmarks:e.landmarks,confidence:e.confidence}},It=(e,t,n)=>{let o=t.shape[1],s=t.shape[2],A=[e.startPoint[1]/o,e.startPoint[0]/s,e.endPoint[1]/o,e.endPoint[0]/s],a=r.image.cropAndResize(t,[A],[0],n),i=r.div(a,O.tf255);return r.dispose(a),i},I2=(e,t)=>{let n=z2(e),o=We(e),s=[t*o[0]/2,t*o[1]/2];return{startPoint:[n[0]-s[0],n[1]-s[1]],endPoint:[n[0]+s[0],n[1]+s[1]],landmarks:e.landmarks,confidence:e.confidence}},N2=e=>{let t=z2(e),n=We(e),o=Math.max(...n)/2;return{startPoint:[Math.round(t[0]-o),Math.round(t[1]-o)],endPoint:[Math.round(t[0]+o),Math.round(t[1]+o)],landmarks:e.landmarks,confidence:e.confidence}},P1=e=>{let t=e.map(o=>o[0]),n=e.map(o=>o[1]);return{startPoint:[Math.min(...t),Math.min(...n)],endPoint:[Math.max(...t),Math.max(...n)],landmarks:e}},Nt=[[1,0,0],[0,1,0],[0,0,1]],es=e=>e-2*Math.PI*Math.floor((e+Math.PI)/(2*Math.PI)),ts=(e,t)=>es(Math.PI/2-Math.atan2(-(t[1]-e[1]),t[0]-e[0]));var v1=(e,t)=>[[1,0,e],[0,1,t],[0,0,1]],we=(e,t)=>{let n=0;for(let o=0;o{let n=[];for(let o=0;o{let n=[],o=e.length;for(let s=0;s{let n=Math.cos(e),o=Math.sin(e),s=[[n,-o,0],[o,n,0],[0,0,1]],A=v1(t[0],t[1]),a=R1(A,s),i=v1(-t[0],-t[1]);return R1(a,i)},os=e=>{let t=[[e[0][0],e[1][0]],[e[0][1],e[1][1]]],n=[e[0][2],e[1][2]],o=[-we(t[0],n),-we(t[1],n)];return[t[0].concat(o[0]),t[1].concat(o[1]),[0,0,1]]},rs=(e,t)=>[we(e,t[0]),we(e,t[1])];function w1(e){let t=e===192?{strides:[4],anchors:[1]}:{strides:[e/16,e/8],anchors:[2,6]},n=[];for(let o=0;o[A[0]/s*(x[0]-s/2),A[1]/s*(x[1]-s/2),x[2]||0]),i=n&&n!==0&&Math.abs(n)>.2,c=i?k1(n,[0,0]):Nt,d=i?a.map(x=>[...rs(x,c),x[2]]):a,y=i?os(o):Nt,l=z2(t),f=[we(l,y[0]),we(l,y[1])];return d.map(x=>[Math.trunc(x[0]+f[0]),Math.trunc(x[1]+f[1]),Math.trunc(x[2]||0)])}function z1(e,t,n,o){let s=t.landmarks.length>=ft.count?ft.symmetryLine:Te.symmetryLine,A=0,a=Nt,i;if(e&&M.kernels.includes("rotatewithoffset"))if(A=ts(t.landmarks[s[0]],t.landmarks[s[1]]),A&&A!==0&&Math.abs(A)>.2){let d=z2(t),y=[d[0]/n.shape[2],d[1]/n.shape[1]],l=r.image.rotateWithOffset(n,A,0,[y[0],y[1]]);a=k1(-A,d),i=It(t,l,[o,o]),r.dispose(l)}else i=It(t,n,[o,o]);else i=It(t,n,[o,o]);return[A,a,i]}var ss=e=>{let t=e.map(o=>o[0]),n=e.map(o=>o[1]);return[Math.min(...t)+(Math.max(...t)-Math.min(...t))/2,Math.min(...n)+(Math.max(...n)-Math.min(...n))/2]},S1=(e,t)=>{let n=ss(e),o=We(t);return{startPoint:[n[0]-o[0]/2,n[1]-o[1]/2],endPoint:[n[0]+o[0]/2,n[1]+o[1]/2]}};var j1=6,As=1.4,B0,Ot=null,ie=0,De=null,Fe=()=>ie;async function I1(e){var t;return M.initial&&(B0=null),B0?e.debug&&h("cached model:",B0.modelUrl):B0=await L((t=e.face.detector)==null?void 0:t.modelPath),ie=B0.executor&&B0.inputs[0].shape?B0.inputs[0].shape[2]:256,De=r.scalar(ie,"int32"),Ot=r.tensor2d(w1(ie)),B0}function as(e){if(!Ot||!De)return r.zeros([0,0]);let t={};t.boxStarts=r.slice(e,[0,1],[-1,2]),t.centers=r.add(t.boxStarts,Ot),t.boxSizes=r.slice(e,[0,3],[-1,2]),t.boxSizesNormalized=r.div(t.boxSizes,De),t.centersNormalized=r.div(t.centers,De),t.halfBoxSize=r.div(t.boxSizesNormalized,O.tf2),t.starts=r.sub(t.centersNormalized,t.halfBoxSize),t.ends=r.add(t.centersNormalized,t.halfBoxSize),t.startNormalized=r.mul(t.starts,De),t.endNormalized=r.mul(t.ends,De);let n=r.concat2d([t.startNormalized,t.endNormalized],1);return Object.keys(t).forEach(o=>r.dispose(t[o])),n}async function N1(e,t){var i,c,d,y;if(!e||e.isDisposedInternal||e.shape.length!==4||e.shape[1]<1||e.shape[2]<1)return[];let n={};n.resized=r.image.resizeBilinear(e,[ie,ie]),n.div=r.div(n.resized,O.tf127),n.normalized=r.sub(n.div,O.tf05);let o=B0==null?void 0:B0.execute(n.normalized);if(Array.isArray(o)&&o.length>2){let l=o.sort((f,x)=>f.size-x.size);n.concat384=r.concat([l[0],l[2]],2),n.concat512=r.concat([l[1],l[3]],2),n.concat=r.concat([n.concat512,n.concat384],1),n.batch=r.squeeze(n.concat,[0])}else Array.isArray(o)?n.batch=r.squeeze(o[0]):n.batch=r.squeeze(o);r.dispose(o),n.boxes=as(n.batch),n.logits=r.slice(n.batch,[0,0],[-1,1]),n.sigmoid=r.sigmoid(n.logits),n.scores=r.squeeze(n.sigmoid),n.nms=await r.image.nonMaxSuppressionAsync(n.boxes,n.scores,((i=t.face.detector)==null?void 0:i.maxDetected)||0,((c=t.face.detector)==null?void 0:c.iouThreshold)||0,((d=t.face.detector)==null?void 0:d.minConfidence)||0);let s=await n.nms.array(),A=[],a=await n.scores.data();for(let l=0;l(((y=t.face.detector)==null?void 0:y.minConfidence)||0)){let x={};x.bbox=r.slice(n.boxes,[s[l],0],[1,-1]),x.slice=r.slice(n.batch,[s[l],j1-1],[1,-1]),x.squeeze=r.squeeze(x.slice),x.landmarks=r.reshape(x.squeeze,[j1,-1]);let u=await x.bbox.data(),m={startPoint:[u[0],u[1]],endPoint:[u[2],u[3]],landmarks:await x.landmarks.array(),confidence:f},g=M1(m,[(e.shape[2]||0)/ie,(e.shape[1]||0)/ie]),P=I2(g,t.face.scale||As),v=N2(P);A.push(v),Object.keys(x).forEach(p=>r.dispose(x[p]))}}return Object.keys(n).forEach(l=>r.dispose(n[l])),A}var R0,le=0,is=2.3,Ct=C0.leftEyeLower0,Wt=C0.rightEyeLower0,Be={leftBounds:[Ct[0],Ct[Ct.length-1]],rightBounds:[Wt[0],Wt[Wt.length-1]]},He={upperCenter:3,lowerCenter:4,index:71,numCoordinates:76};async function D1(e){var t,n;return M.initial&&(R0=null),R0?e.debug&&h("cached model:",R0.modelUrl):R0=await L((t=e.face.iris)==null?void 0:t.modelPath),le=(R0==null?void 0:R0.executor)&&((n=R0.inputs)==null?void 0:n[0].shape)?R0.inputs[0].shape[2]:0,le===-1&&(le=64),R0}function L2(e,t,n,o){for(let s=0;s{let t=e[Be.leftBounds[0]][2],n=e[Be.rightBounds[0]][2];return t-n},O1=(e,t,n,o,s,A=!1)=>{let a=N2(I2(P1([e[n],e[o]]),is)),i=We(a),c=r.image.cropAndResize(t,[[a.startPoint[1]/s,a.startPoint[0]/s,a.endPoint[1]/s,a.endPoint[0]/s]],[0],[le,le]);if(A&&M.kernels.includes("flipleftright")){let d=r.image.flipLeftRight(c);r.dispose(c),c=d}return{box:a,boxSize:i,crop:c}},C1=(e,t,n,o=!1)=>{let s=[];for(let A=0;A{let o=e[C0[`${n}EyeUpper0`][He.upperCenter]][2],s=e[C0[`${n}EyeLower0`][He.lowerCenter]][2],A=(o+s)/2;return t.map((a,i)=>{let c=A;return i===2?c=o:i===4&&(c=s),[a[0],a[1],c]})};async function F1(e,t,n){if(!(R0!=null&&R0.executor))return e;let{box:o,boxSize:s,crop:A}=O1(e,t,Be.leftBounds[0],Be.leftBounds[1],n,!0),{box:a,boxSize:i,crop:c}=O1(e,t,Be.rightBounds[0],Be.rightBounds[1],n,!0),d=r.concat([A,c]);r.dispose(A),r.dispose(c);let y=R0.execute(d);r.dispose(d);let l=await y.data();r.dispose(y);let f=l.slice(0,He.numCoordinates*3),{rawCoords:x,iris:u}=C1(f,o,s,!0),m=l.slice(He.numCoordinates*3),{rawCoords:g,iris:P}=C1(m,a,i,!1),v=ls(e);Math.abs(v)<30?(L2(e,x,"left",null),L2(e,g,"right",null)):v<1?L2(e,x,"left",["EyeUpper0","EyeLower0"]):L2(e,g,"right",["EyeUpper0","EyeLower0"]);let p=W1(e,u,"left"),b=W1(e,P,"right");return e.concat(p).concat(b)}async function H1(e,t){var A,a,i,c,d,y,l,f,x,u;let n={lips:await((a=(A=t.filter(m=>m.size===160))==null?void 0:A[0])==null?void 0:a.data()),irisL:await((c=(i=t.filter(m=>m.size===10))==null?void 0:i[0])==null?void 0:c.data()),eyeL:await((y=(d=t.filter(m=>m.size===142))==null?void 0:d[0])==null?void 0:y.data()),irisR:await((f=(l=t.filter(m=>m.size===10))==null?void 0:l[1])==null?void 0:f.data()),eyeR:await((u=(x=t.filter(m=>m.size===142))==null?void 0:x[1])==null?void 0:u.data())};for(let m of Object.values(n))if(!m)return e;let o=Re.reduce((m,g)=>m+=e[g][2],0)/Re.length;for(let m=0;mm+=e[g][2],0)/Me.length;for(let m=0;mT()-q0.timestamp,o=q0.skipped<(((d=t.face.detector)==null?void 0:d.skipFrames)||0);!t.skipAllowed||!n||!o||q0.boxes.length===0?(q0.boxes=await N1(e,t),q0.timestamp=T(),q0.skipped=0):q0.skipped++;let s=[],A=[],a=0,i=n2;for(let v=0;vW.shape[W.shape.length-1]===1).data();if(k.faceScore=Math.round(100*q[0])/100,k.faceScore<(((u=t.face.detector)==null?void 0:u.minConfidence)||1)){if(p.confidence=k.faceScore,t.face.mesh.keepInvalid){k.box=S2(p,e),k.boxRaw=j2(p,e),k.score=k.boxScore,k.mesh=p.landmarks.map(W=>[(p.startPoint[0]+p.endPoint[0])/2+(p.endPoint[0]+p.startPoint[0])*W[0]/Fe(),(p.startPoint[1]+p.endPoint[1])/2+(p.endPoint[1]+p.startPoint[1])*W[1]/Fe()]),k.meshRaw=k.mesh.map(W=>[W[0]/(e.shape[2]||1),W[1]/(e.shape[1]||1),(W[2]||0)/i]);for(let W of Object.keys(Te))k.annotations[W]=[k.mesh[Te[W]]]}}else{let W=N.find(D=>D.shape[D.shape.length-1]===1404),Z=r.reshape(W,[-1,3]),J=await Z.array();r.dispose(Z),(m=t.face.attention)!=null&&m.enabled?J=await H1(J,N):(g=t.face.iris)!=null&&g.enabled&&(J=await F1(J,k.tensor,n2)),k.mesh=E1(J,p,b,j,n2),k.meshRaw=k.mesh.map(D=>[D[0]/(e.shape[2]||0),D[1]/(e.shape[1]||0),(D[2]||0)/i]);for(let D of Object.keys(C0))k.annotations[D]=C0[D].map(U=>k.mesh[U]);k.score=k.faceScore;let R={...S1(k.mesh,p),confidence:p.confidence,landmarks:p.landmarks};k.box=S2(R,e),k.boxRaw=j2(R,e),A.push(R)}r.dispose(N)}else{k.box=S2(p,e),k.boxRaw=j2(p,e),k.score=k.boxScore,k.mesh=p.landmarks.map(N=>[(p.startPoint[0]+p.endPoint[0])/2+(p.endPoint[0]+p.startPoint[0])*N[0]/Fe(),(p.startPoint[1]+p.endPoint[1])/2+(p.endPoint[1]+p.startPoint[1])*N[1]/Fe()]),k.meshRaw=k.mesh.map(N=>[N[0]/(e.shape[2]||0),N[1]/(e.shape[1]||0),(N[2]||0)/i]);for(let N of Object.keys(Te))k.annotations[N]=[k.mesh[Te[N]]]}k.score>(((P=t.face.detector)==null?void 0:P.minConfidence)||1)?s.push(k):r.dispose(k.tensor)}return q0.boxes=A,s}async function V1(e){var t,n,o,s,A,a;return M.initial&&(K=null),((t=e.face.attention)==null?void 0:t.enabled)&&(K==null?void 0:K.signature)&&Object.keys(((n=K==null?void 0:K.signature)==null?void 0:n.outputs)||{}).length<6&&(K=null),K?e.debug&&h("cached model:",K.modelUrl):(o=e.face.attention)!=null&&o.enabled?K=await L(e.face.attention.modelPath):K=await L((s=e.face.mesh)==null?void 0:s.modelPath),n2=K.executor&&((A=K==null?void 0:K.inputs)==null?void 0:A[0].shape)?(a=K==null?void 0:K.inputs)==null?void 0:a[0].shape[2]:256,K}var Z1=ve,X1=e2;var ds=["angry","disgust","fear","happy","sad","surprise","neutral"],I0,O2=[],q1=0,U1=0,Ft=Number.MAX_SAFE_INTEGER;async function Y1(e){var t;return M.initial&&(I0=null),I0?e.debug&&h("cached model:",I0.modelUrl):I0=await L((t=e.face.emotion)==null?void 0:t.modelPath),I0}async function Bt(e,t,n,o){var a,i;if(!I0)return[];let s=Ft<(((a=t.face.emotion)==null?void 0:a.skipFrames)||0),A=(((i=t.face.emotion)==null?void 0:i.skipTime)||0)>T()-U1;return t.skipAllowed&&A&&s&&q1===o&&O2[n]&&O2[n].length>0?(Ft++,O2[n]):(Ft=0,new Promise(async c=>{var y;let d=[];if((y=t.face.emotion)!=null&&y.enabled){let l={},f=I0!=null&&I0.inputs[0].shape?I0.inputs[0].shape[2]:0;l.resize=r.image.resizeBilinear(e,[f,f],!1),l.channels=r.mul(l.resize,O.rgb),l.grayscale=r.sum(l.channels,3,!0),l.grayscaleSub=r.sub(l.grayscale,O.tf05),l.grayscaleMul=r.mul(l.grayscaleSub,O.tf2),l.emotion=I0==null?void 0:I0.execute(l.grayscaleMul),U1=T();let x=await l.emotion.data();for(let u=0;u(t.face.emotion.minConfidence||0)&&d.push({score:Math.min(.99,Math.trunc(100*x[u])/100),emotion:ds[u]});d.sort((u,m)=>m.score-u.score),Object.keys(l).forEach(u=>r.dispose(l[u]))}O2[n]=d,q1=o,c(d)}))}var f0,ce=[],J1=0,Q1=0,Ht=Number.MAX_SAFE_INTEGER;async function _1(e){var t;return M.initial&&(f0=null),f0?e.debug&&h("cached model:",f0.modelUrl):f0=await L((t=e.face.description)==null?void 0:t.modelPath),f0}function xs(e){let t=e.image||e.tensor||e;if(!(f0!=null&&f0.inputs[0].shape))return t;let n=r.image.resizeBilinear(t,[f0.inputs[0].shape[2],f0.inputs[0].shape[1]],!1),o=r.mul(n,O.tf255);return r.dispose(n),o}async function Gt(e,t,n,o){var i,c,d,y;let s={age:0,gender:"unknown",genderScore:0,descriptor:[]};if(!(f0!=null&&f0.executor))return s;let A=Ht<(((i=t.face.description)==null?void 0:i.skipFrames)||0),a=(((c=t.face.description)==null?void 0:c.skipTime)||0)>T()-J1;return t.skipAllowed&&A&&a&&Q1===o&&((d=ce==null?void 0:ce[n])==null?void 0:d.age)>0&&((y=ce==null?void 0:ce[n])==null?void 0:y.genderScore)>0?(Ht++,ce[n]):(Ht=0,new Promise(async l=>{var f;if((f=t.face.description)!=null&&f.enabled){let x=xs(e),u=f0==null?void 0:f0.execute(x);J1=T(),r.dispose(x);let g=await u.find(B=>B.shape[1]===1).data(),P=Math.trunc(200*Math.abs(g[0]-.5))/100;P>(t.face.description.minConfidence||0)&&(s.gender=g[0]<=.5?"female":"male",s.genderScore=Math.min(.99,P));let v=r.argMax(u.find(B=>B.shape[1]===100),1),p=(await v.data())[0];r.dispose(v);let j=await u.find(B=>B.shape[1]===100).data();s.age=Math.round(j[p-1]>j[p+1]?10*p-100*j[p-1]:10*p+100*j[p+1])/10,(Number.isNaN(g[0])||Number.isNaN(j[0]))&&h("faceres error:",{model:f0,result:u});let k=u.find(B=>B.shape[1]===1024),N=k?await k.data():[];s.descriptor=Array.from(N),u.forEach(B=>r.dispose(B))}ce[n]=s,Q1=o,l(s)}))}var Ge=.1,Vt=.5;function ys(e,t,n){let o=!1,s=n.length-1;for(let A=0;At!=n[s].y>t&&e<(n[s].x-n[A].x)*(t-n[A].y)/(n[s].y-n[A].y)+n[A].x&&(o=!o);return o}async function e3(e){if(!e.tensor||!e.mesh||e.mesh.length<100)return e.tensor;let t=e.tensor.shape[2]||0,n=e.tensor.shape[1]||0,o=await e.tensor.buffer(),s=[];for(let a of C0.silhouette)s.push({x:(e.mesh[a][0]-e.box[0])/e.box[2],y:(e.mesh[a][1]-e.box[1])/e.box[3]});Ge&&Ge>0&&(s=s.map(a=>({x:a.x>.5?a.x+Ge:a.x-Ge,y:a.y>.5?a.y+Ge:a.y-Ge})));for(let a=0;aT()-n3,A=Zt<(((i=t.face.antispoof)==null?void 0:i.skipFrames)||0);return t.skipAllowed&&s&&A&&t3===o&&C2[n]?(Zt++,C2[n]):(Zt=0,new Promise(async c=>{let d=r.image.resizeBilinear(e,[d0!=null&&d0.inputs[0].shape?d0.inputs[0].shape[2]:0,d0!=null&&d0.inputs[0].shape?d0.inputs[0].shape[1]:0],!1),y=d0==null?void 0:d0.execute(d),l=(await y.data())[0];C2[n]=Math.round(100*l)/100,t3=o,n3=T(),r.dispose([d,y]),c(C2[n])}))}var x0,W2=[],qt=Number.MAX_SAFE_INTEGER,s3=0,A3=0;async function a3(e){var t;return M.initial&&(x0=null),x0?e.debug&&h("cached model:",x0.modelUrl):x0=await L((t=e.face.liveness)==null?void 0:t.modelPath),x0}async function Ut(e,t,n,o){var a,i;if(!(x0!=null&&x0.executor))return 0;let s=(((a=t.face.liveness)==null?void 0:a.skipTime)||0)>T()-A3,A=qt<(((i=t.face.liveness)==null?void 0:i.skipFrames)||0);return t.skipAllowed&&s&&A&&s3===o&&W2[n]?(qt++,W2[n]):(qt=0,new Promise(async c=>{let d=r.image.resizeBilinear(e,[x0!=null&&x0.inputs[0].shape?x0.inputs[0].shape[2]:0,x0!=null&&x0.inputs[0].shape?x0.inputs[0].shape[1]:0],!1),y=x0==null?void 0:x0.execute(d),l=(await y.data())[0];W2[n]=Math.round(100*l)/100,s3=o,A3=T(),r.dispose([d,y]),c(W2[n])}))}var W0,Yt=[],ms=["white","black","asian","indian","other"],ps=[15,23,28,35.5,45.5,55.5,65],l3=0,c3=0,Kt=Number.MAX_SAFE_INTEGER;async function d3(e){var t;return M.initial&&(W0=null),W0?e.debug&&h("cached model:",W0.modelUrl):W0=await L((t=e.face.gear)==null?void 0:t.modelPath),W0}async function Jt(e,t,n,o){var a,i;if(!W0)return{age:0,gender:"unknown",genderScore:0,race:[]};let s=Kt<(((a=t.face.gear)==null?void 0:a.skipFrames)||0),A=(((i=t.face.gear)==null?void 0:i.skipTime)||0)>T()-c3;return t.skipAllowed&&A&&s&&l3===o&&Yt[n]?(Kt++,Yt[n]):(Kt=0,new Promise(async c=>{var P,v;if(!(W0!=null&&W0.inputs[0].shape))return;let d={},y=[[0,.1,.9,.9]];d.resize=r.image.cropAndResize(e,y,[0],[W0.inputs[0].shape[2],W0.inputs[0].shape[1]]);let l={age:0,gender:"unknown",genderScore:0,race:[]};(P=t.face.gear)!=null&&P.enabled&&([d.age,d.gender,d.race]=W0.execute(d.resize,["age_output","gender_output","race_output"]));let f=await d.gender.data();l.gender=f[0]>f[1]?"male":"female",l.genderScore=Math.round(100*(f[0]>f[1]?f[0]:f[1]))/100;let x=await d.race.data();for(let p=0;p(((v=t.face.gear)==null?void 0:v.minConfidence)||.2)&&l.race.push({score:Math.round(100*x[p])/100,race:ms[p]});l.race.sort((p,b)=>b.score-p.score);let m=Array.from(await d.age.data()).map((p,b)=>[ps[b],p]).sort((p,b)=>b[1]-p[1]),g=m[0][0];for(let p=1;pr.dispose(d[p])),Yt[n]=l,l3=o,c3=T(),c(l)}))}var M0,D2=[],y3=0,f3=0,Qt=Number.MAX_SAFE_INTEGER;async function m3(e){return M.initial&&(M0=null),M0?e.debug&&h("cached model:",M0.modelUrl):M0=await L(e.face.ssrnet.modelPathAge),M0}async function _t(e,t,n,o){var a,i,c,d;if(!M0)return{age:0};let s=Qt<(((a=t.face.ssrnet)==null?void 0:a.skipFrames)||0),A=(((i=t.face.ssrnet)==null?void 0:i.skipTime)||0)>T()-f3;return t.skipAllowed&&s&&A&&y3===o&&((c=D2[n])==null?void 0:c.age)&&((d=D2[n])==null?void 0:d.age)>0?(Qt++,D2[n]):(Qt=0,new Promise(async y=>{var x;if(!(M0!=null&&M0.inputs)||!M0.inputs[0]||!M0.inputs[0].shape)return;let l={};l.resize=r.image.resizeBilinear(e,[M0.inputs[0].shape[2],M0.inputs[0].shape[1]],!1),l.enhance=r.mul(l.resize,O.tf255);let f={age:0};if((x=t.face.ssrnet)!=null&&x.enabled&&(l.age=M0.execute(l.enhance)),l.age){let u=await l.age.data();f.age=Math.trunc(10*u[0])/10}Object.keys(l).forEach(u=>r.dispose(l[u])),D2[n]=f,y3=o,f3=T(),y(f)}))}var D0,F2=[],u3=0,h3=0,$t=Number.MAX_SAFE_INTEGER,e5=[.2989,.587,.114];async function b3(e){var t;return M.initial&&(D0=null),D0?e.debug&&h("cached model:",D0.modelUrl):D0=await L((t=e.face.ssrnet)==null?void 0:t.modelPathGender),D0}async function t5(e,t,n,o){var a,i,c,d;if(!D0)return{gender:"unknown",genderScore:0};let s=$t<(((a=t.face.ssrnet)==null?void 0:a.skipFrames)||0),A=(((i=t.face.ssrnet)==null?void 0:i.skipTime)||0)>T()-h3;return t.skipAllowed&&s&&A&&u3===o&&((c=F2[n])==null?void 0:c.gender)&&((d=F2[n])==null?void 0:d.genderScore)>0?($t++,F2[n]):($t=0,new Promise(async y=>{var u;if(!(D0!=null&&D0.inputs[0].shape))return;let l={};l.resize=r.image.resizeBilinear(e,[D0.inputs[0].shape[2],D0.inputs[0].shape[1]],!1),l.enhance=r.tidy(()=>{let[m,g,P]=r.split(l.resize,3,3),v=r.mul(m,e5[0]),p=r.mul(g,e5[1]),b=r.mul(P,e5[2]),j=r.addN([v,p,b]);return r.mul(r.sub(j,O.tf05),2)});let f={gender:"unknown",genderScore:0};(u=t.face.ssrnet)!=null&&u.enabled&&(l.gender=D0.execute(l.enhance));let x=await l.gender.data();f.gender=x[0]>x[1]?"female":"male",f.genderScore=x[0]>x[1]?Math.trunc(100*x[0])/100:Math.trunc(100*x[1])/100,Object.keys(l).forEach(m=>r.dispose(l[m])),F2[n]=f,u3=o,h3=T(),y(f)}))}var P0,n5=[],T3=0,v3=0,R3=Number.MAX_SAFE_INTEGER;async function M3(e){var t;return M.initial&&(P0=null),P0?e.debug&&h("cached model:",P0.modelUrl):P0=await L((t=e.face.mobilefacenet)==null?void 0:t.modelPath),P0}async function o5(e,t,n,o){var a,i;if(!(P0!=null&&P0.executor))return[];let s=R3<(((a=t.face.mobilefacenet)==null?void 0:a.skipFrames)||0),A=(((i=t.face.mobilefacenet)==null?void 0:i.skipTime)||0)>T()-v3;return t.skipAllowed&&A&&s&&T3===o&&n5[n]?(R3++,n5[n]):new Promise(async c=>{var y;let d=[];if(((y=t.face.mobilefacenet)==null?void 0:y.enabled)&&(P0==null?void 0:P0.inputs[0].shape)){let l={};l.crop=r.image.resizeBilinear(e,[P0.inputs[0].shape[2],P0.inputs[0].shape[1]],!1),l.data=P0.execute(l.crop);let f=await l.data.data();d=Array.from(f),Object.keys(l).forEach(x=>r.dispose(l[x]))}n5[n]=d,T3=o,v3=T(),c(d)})}var k0,r5=[],k3=0,w3=0,E3=Number.MAX_SAFE_INTEGER;async function z3(e){return M.initial&&(k0=null),k0?e.debug&&h("cached model:",k0.modelUrl):k0=await L(e.face.insightface.modelPath),k0}async function s5(e,t,n,o){var a,i;if(!(k0!=null&&k0.executor))return[];let s=E3<(((a=t.face.insightface)==null?void 0:a.skipFrames)||0),A=(((i=t.face.insightface)==null?void 0:i.skipTime)||0)>T()-w3;return t.skipAllowed&&A&&s&&k3===o&&r5[n]?(E3++,r5[n]):new Promise(async c=>{var y;let d=[];if(((y=t.face.insightface)==null?void 0:y.enabled)&&(k0==null?void 0:k0.inputs[0].shape)){let l={};l.crop=r.image.resizeBilinear(e,[k0.inputs[0].shape[2],k0.inputs[0].shape[1]],!1),l.data=k0.execute(l.crop);let f=await l.data.data();d=Array.from(f),Object.keys(l).forEach(x=>r.dispose(l[x]))}r5[n]=d,k3=o,w3=T(),c(d)})}var us=e=>{let t=(l,f)=>Math.atan2(l[1]-f[1],l[0]-f[0]);if(!e.annotations.rightEyeIris||!e.annotations.leftEyeIris)return{bearing:0,strength:0};let n=[0,-.1],o=1,s=(e.mesh[33][2]||0)>(e.mesh[263][2]||0),A=s?e.mesh[473]:e.mesh[468],a=s?[(e.mesh[133][0]+e.mesh[33][0])/2,(e.mesh[133][1]+e.mesh[33][1])/2]:[(e.mesh[263][0]+e.mesh[362][0])/2,(e.mesh[263][1]+e.mesh[362][1])/2],i=s?[e.mesh[133][0]-e.mesh[33][0],e.mesh[23][1]-e.mesh[27][1]]:[e.mesh[263][0]-e.mesh[362][0],e.mesh[253][1]-e.mesh[257][1]],c=[(a[0]-A[0])/i[0]-n[0],o*(A[1]-a[1])/i[1]-n[1]],d=Math.sqrt(c[0]*c[0]+c[1]*c[1]);return d=Math.min(d,e.boxRaw[2]/2,e.boxRaw[3]/2),{bearing:(t([0,0],c)+Math.PI/2)%Math.PI,strength:d}},j3=(e,t)=>{let n=m=>{let g=Math.sqrt(m[0]*m[0]+m[1]*m[1]+m[2]*m[2]);return m[0]/=g,m[1]/=g,m[2]/=g,m},o=(m,g)=>{let P=m[0]-g[0],v=m[1]-g[1],p=m[2]-g[2];return[P,v,p]},s=(m,g)=>{let P=m[1]*g[2]-m[2]*g[1],v=m[2]*g[0]-m[0]*g[2],p=m[0]*g[1]-m[1]*g[0];return[P,v,p]},A=m=>{let[g,P,v,p,b,j,k,N,B]=m,q,W,Z;return p<1?p>-1?(Z=Math.asin(p),W=Math.atan2(-k,g),q=Math.atan2(-j,b)):(Z=-Math.PI/2,W=-Math.atan2(N,B),q=0):(Z=Math.PI/2,W=Math.atan2(N,B),q=0),Number.isNaN(q)&&(q=0),Number.isNaN(W)&&(W=0),Number.isNaN(Z)&&(Z=0),{pitch:2*-q,yaw:2*-W,roll:2*-Z}},a=e.meshRaw;if(!a||a.length<300)return{angle:{pitch:0,yaw:0,roll:0},matrix:[1,0,0,0,1,0,0,0,1],gaze:{bearing:0,strength:0}};let i=Math.max(e.boxRaw[2]*t[0],e.boxRaw[3]*t[1])/1.5,c=[a[10],a[152],a[234],a[454]].map(m=>[m[0]*t[0]/i,m[1]*t[1]/i,m[2]]),d=n(o(c[1],c[0])),y=n(o(c[3],c[2])),l=n(s(y,d));y=s(d,l);let f=[y[0],y[1],y[2],d[0],d[1],d[2],l[0],l[1],l[2]],x=A(f),u=a.length===478?us(e):{bearing:0,strength:0};return{angle:x,matrix:f,gaze:u}};function I3(e,t){let n=e==null?void 0:e.annotations;if(!n)return 0;let o=Math.max(Math.abs(n.leftEyeIris[3][0]-n.leftEyeIris[1][0]),Math.abs(n.rightEyeIris[3][0]-n.rightEyeIris[1][0]))/t;return Math.round(1.17/o)/100}var A5=async(e,t)=>{var u,m,g,P,v,p,b,j,k,N,B,q,W,Z,J,R,D,U,H,a0,o0,C,F;let n=T(),o,s,A,a,i,c,d,y,l,f=[];e.state="run:face";let x=await G1(t,e.config);if(e.performance.face=M.perfadd?(e.performance.face||0)+Math.trunc(T()-n):Math.trunc(T()-n),!t.shape||t.shape.length!==4)return[];if(!x)return[];for(let S=0;S200?j3(x[S],[t.shape[2],t.shape[1]]):null;e.analyze("Start Emotion:"),e.config.async?a=(m=e.config.face.emotion)!=null&&m.enabled?Bt(x[S].tensor||r.tensor([]),e.config,S,x.length):[]:(e.state="run:emotion",n=T(),a=(g=e.config.face.emotion)!=null&&g.enabled?await Bt(x[S].tensor||r.tensor([]),e.config,S,x.length):[],e.performance.emotion=M.perfadd?(e.performance.emotion||0)+Math.trunc(T()-n):Math.trunc(T()-n)),e.analyze("End Emotion:"),e.analyze("Start AntiSpoof:"),e.config.async?d=(P=e.config.face.antispoof)!=null&&P.enabled?Xt(x[S].tensor||r.tensor([]),e.config,S,x.length):0:(e.state="run:antispoof",n=T(),d=(v=e.config.face.antispoof)!=null&&v.enabled?await Xt(x[S].tensor||r.tensor([]),e.config,S,x.length):0,e.performance.antispoof=M.perfadd?(e.performance.antispoof||0)+Math.trunc(T()-n):Math.trunc(T()-n)),e.analyze("End AntiSpoof:"),e.analyze("Start Liveness:"),e.config.async?y=(p=e.config.face.liveness)!=null&&p.enabled?Ut(x[S].tensor||r.tensor([]),e.config,S,x.length):0:(e.state="run:liveness",n=T(),y=(b=e.config.face.liveness)!=null&&b.enabled?await Ut(x[S].tensor||r.tensor([]),e.config,S,x.length):0,e.performance.liveness=M.perfadd?(e.performance.antispoof||0)+Math.trunc(T()-n):Math.trunc(T()-n)),e.analyze("End Liveness:"),e.analyze("Start GEAR:"),e.config.async?s=(j=e.config.face.gear)!=null&&j.enabled?Jt(x[S].tensor||r.tensor([]),e.config,S,x.length):null:(e.state="run:gear",n=T(),s=(k=e.config.face.gear)!=null&&k.enabled?await Jt(x[S].tensor||r.tensor([]),e.config,S,x.length):null,e.performance.gear=Math.trunc(T()-n)),e.analyze("End GEAR:"),e.analyze("Start SSRNet:"),e.config.async?(o=(N=e.config.face.ssrnet)!=null&&N.enabled?_t(x[S].tensor||r.tensor([]),e.config,S,x.length):null,A=(B=e.config.face.ssrnet)!=null&&B.enabled?t5(x[S].tensor||r.tensor([]),e.config,S,x.length):null):(e.state="run:ssrnet",n=T(),o=(q=e.config.face.ssrnet)!=null&&q.enabled?await _t(x[S].tensor||r.tensor([]),e.config,S,x.length):null,A=(W=e.config.face.ssrnet)!=null&&W.enabled?await t5(x[S].tensor||r.tensor([]),e.config,S,x.length):null,e.performance.ssrnet=Math.trunc(T()-n)),e.analyze("End SSRNet:"),e.analyze("Start MobileFaceNet:"),e.config.async?i=(Z=e.config.face.mobilefacenet)!=null&&Z.enabled?o5(x[S].tensor||r.tensor([]),e.config,S,x.length):null:(e.state="run:mobilefacenet",n=T(),i=(J=e.config.face.mobilefacenet)!=null&&J.enabled?await o5(x[S].tensor||r.tensor([]),e.config,S,x.length):null,e.performance.mobilefacenet=Math.trunc(T()-n)),e.analyze("End MobileFaceNet:"),e.analyze("Start InsightFace:"),e.config.async?c=(R=e.config.face.insightface)!=null&&R.enabled?s5(x[S].tensor||r.tensor([]),e.config,S,x.length):null:(e.state="run:mobilefacenet",n=T(),c=(D=e.config.face.insightface)!=null&&D.enabled?await s5(x[S].tensor||r.tensor([]),e.config,S,x.length):null,e.performance.mobilefacenet=Math.trunc(T()-n)),e.analyze("End InsightFace:"),e.analyze("Start Description:"),e.config.async?l=Gt(x[S].tensor||r.tensor([]),e.config,S,x.length):(e.state="run:description",n=T(),l=await Gt(x[S].tensor||r.tensor([]),e.config,S,x.length),e.performance.description=M.perfadd?(e.performance.description||0)+Math.trunc(T()-n):Math.trunc(T()-n)),e.analyze("End Description:"),e.config.async&&([o,A,a,i,c,l,s,d,y]=await Promise.all([o,A,a,i,c,l,s,d,y])),e.analyze("Finish Face:"),((U=e.config.face.ssrnet)==null?void 0:U.enabled)&&o&&A&&(l={...l,age:o.age,gender:A.gender,genderScore:A.genderScore}),((H=e.config.face.gear)==null?void 0:H.enabled)&&s&&(l={...l,age:s.age,gender:s.gender,genderScore:s.genderScore,race:s.race}),((a0=e.config.face.mobilefacenet)==null?void 0:a0.enabled)&&i&&(l.descriptor=i),((o0=e.config.face.insightface)==null?void 0:o0.enabled)&&c&&(l.descriptor=c);let te=(C=e.config.face.iris)!=null&&C.enabled?I3(x[S],t.shape[2]):0,ne=(F=e.config.face.detector)!=null&&F.return?r.squeeze(x[S].tensor):null;r.dispose(x[S].tensor),x[S].tensor&&delete x[S].tensor;let i0={...x[S],id:S};l.age&&(i0.age=l.age),l.gender&&(i0.gender=l.gender),l.genderScore&&(i0.genderScore=l.genderScore),l.descriptor&&(i0.embedding=l.descriptor),l.race&&(i0.race=l.race),a&&(i0.emotion=a),d&&(i0.real=d),y&&(i0.live=y),te>0&&(i0.distance=te),N0&&(i0.rotation=N0),ne&&(i0.tensor=ne),f.push(i0),e.analyze("End Face")}return e.analyze("End FaceMesh:"),e.config.async&&(e.performance.face&&delete e.performance.face,e.performance.age&&delete e.performance.age,e.performance.gender&&delete e.performance.gender,e.performance.emotion&&delete e.performance.emotion),f};var b0={thumb:0,index:1,middle:2,ring:3,pinky:4,all:[0,1,2,3,4],nameMapping:{0:"thumb",1:"index",2:"middle",3:"ring",4:"pinky"},pointsMapping:{0:[[0,1],[1,2],[2,3],[3,4]],1:[[0,5],[5,6],[6,7],[7,8]],2:[[0,9],[9,10],[10,11],[11,12]],3:[[0,13],[13,14],[14,15],[15,16]],4:[[0,17],[17,18],[18,19],[19,20]]},getName:e=>b0.nameMapping[e],getPoints:e=>b0.pointsMapping[e]},xe={none:0,half:1,full:2,nameMapping:{0:"none",1:"half",2:"full"},getName:e=>xe.nameMapping[e]},$={verticalUp:0,verticalDown:1,horizontalLeft:2,horizontalRight:3,diagonalUpRight:4,diagonalUpLeft:5,diagonalDownRight:6,diagonalDownLeft:7,nameMapping:{0:"verticalUp",1:"verticalDown",2:"horizontalLeft",3:"horizontalRight",4:"diagonalUpRight",5:"diagonalUpLeft",6:"diagonalDownRight",7:"diagonalDownLeft"},getName:e=>$.nameMapping[e]},de=class{constructor(t){E(this,"name");E(this,"curls");E(this,"directions");E(this,"weights");E(this,"weightsRelative");this.name=t,this.curls={},this.directions={},this.weights=[1,1,1,1,1],this.weightsRelative=[1,1,1,1,1]}curl(t,n,o){typeof this.curls[t]=="undefined"&&(this.curls[t]=[]),this.curls[t].push([n,o])}direction(t,n,o){this.directions[t]||(this.directions[t]=[]),this.directions[t].push([n,o])}weight(t,n){this.weights[t]=n;let o=this.weights.reduce((s,A)=>s+A,0);this.weightsRelative=this.weights.map(s=>s*5/o)}matchAgainst(t,n){let o=0;for(let s in t){let A=t[s],a=this.curls[s];if(typeof a=="undefined"){o+=this.weightsRelative[s];continue}for(let[i,c]of a)if(A===i){o+=c*this.weightsRelative[s];break}}for(let s in n){let A=n[s],a=this.directions[s];if(typeof a=="undefined"){o+=this.weightsRelative[s];continue}for(let[i,c]of a)if(A===i){o+=c*this.weightsRelative[s];break}}return o/10}};var{thumb:H0,index:Q0,middle:_0,ring:Ee,pinky:ze}=b0,{none:G0,half:bs,full:V0}=xe,{verticalUp:Ve,verticalDown:Y4,horizontalLeft:a5,horizontalRight:gs,diagonalUpRight:Ts,diagonalUpLeft:Ze,diagonalDownRight:K4,diagonalDownLeft:J4}=$,ye=new de("thumbs up");ye.curl(H0,G0,1);ye.direction(H0,Ve,1);ye.direction(H0,Ze,.25);ye.direction(H0,Ts,.25);for(let e of[b0.index,b0.middle,b0.ring,b0.pinky])ye.curl(e,V0,1),ye.direction(e,a5,1),ye.direction(e,gs,1);var r0=new de("victory");r0.curl(H0,bs,.5);r0.curl(H0,G0,.5);r0.direction(H0,Ve,1);r0.direction(H0,Ze,1);r0.curl(Q0,G0,1);r0.direction(Q0,Ve,.75);r0.direction(Q0,Ze,1);r0.curl(_0,G0,1);r0.direction(_0,Ve,1);r0.direction(_0,Ze,.75);r0.curl(Ee,V0,1);r0.direction(Ee,Ve,.2);r0.direction(Ee,Ze,1);r0.direction(Ee,a5,.2);r0.curl(ze,V0,1);r0.direction(ze,Ve,.2);r0.direction(ze,Ze,1);r0.direction(ze,a5,.2);r0.weight(Q0,2);r0.weight(_0,2);var fe=new de("point");fe.curl(H0,V0,1);fe.curl(Q0,G0,.5);fe.curl(_0,V0,.5);fe.curl(Ee,V0,.5);fe.curl(ze,V0,.5);fe.weight(Q0,2);fe.weight(_0,2);var me=new de("middle finger");me.curl(H0,G0,1);me.curl(Q0,V0,.5);me.curl(_0,V0,.5);me.curl(Ee,V0,.5);me.curl(ze,V0,.5);me.weight(Q0,2);me.weight(_0,2);var Xe=new de("open palm");Xe.curl(H0,G0,.75);Xe.curl(Q0,G0,.75);Xe.curl(_0,G0,.75);Xe.curl(Ee,G0,.75);Xe.curl(ze,G0,.75);var N3=[ye,r0,fe,me,Xe];var vs=.7,Se={HALF_CURL_START_LIMIT:60,NO_CURL_START_LIMIT:130,DISTANCE_VOTE_POWER:1.1,SINGLE_ANGLE_VOTE_POWER:.9,TOTAL_ANGLE_VOTE_POWER:1.6};function L3(e,t,n,o){let s=(t-o)/(e-n),A=Math.atan(s)*180/Math.PI;return A<=0?A=-A:A>0&&(A=180-A),A}function C3(e,t){if(!e||!t)return[0,0];let n=L3(e[0],e[1],t[0],t[1]);if(e.length===2)return n;let o=L3(e[1],e[2],t[1],t[2]);return[n,o]}function O3(e,t=1){let n=0,o=0,s=0;return e>=75&&e<=105?n=1*t:e>=25&&e<=155?o=1*t:s=1*t,[n,o,s]}function Rs(e,t,n){let o=e[0]-t[0],s=e[0]-n[0],A=t[0]-n[0],a=e[1]-t[1],i=e[1]-n[1],c=t[1]-n[1],d=e[2]-t[2],y=e[2]-n[2],l=t[2]-n[2],f=Math.sqrt(o*o+a*a+d*d),x=Math.sqrt(s*s+i*i+y*y),u=Math.sqrt(A*A+c*c+l*l),m=(u*u+f*f-x*x)/(2*u*f);m>1?m=1:m<-1&&(m=-1);let g=Math.acos(m);g=57.2958*g%180;let P;return g>Se.NO_CURL_START_LIMIT?P=xe.none:g>Se.HALF_CURL_START_LIMIT?P=xe.half:P=xe.full,P}function W3(e,t,n,o){let s;return o===Math.abs(e)?e>0?s=$.horizontalLeft:s=$.horizontalRight:o===Math.abs(t)?t>0?s=$.horizontalLeft:s=$.horizontalRight:n>0?s=$.horizontalLeft:s=$.horizontalRight,s}function D3(e,t,n,o){let s;return o===Math.abs(e)?e<0?s=$.verticalDown:s=$.verticalUp:o===Math.abs(t)?t<0?s=$.verticalDown:s=$.verticalUp:n<0?s=$.verticalDown:s=$.verticalUp,s}function Ms(e,t,n,o,s,A,a,i){let c,d=D3(e,t,n,o),y=W3(s,A,a,i);return d===$.verticalUp?y===$.horizontalLeft?c=$.diagonalUpLeft:c=$.diagonalUpRight:y===$.horizontalLeft?c=$.diagonalDownLeft:c=$.diagonalDownRight,c}function Ps(e,t,n,o){let s=e[0]-t[0],A=e[0]-n[0],a=t[0]-n[0],i=e[1]-t[1],c=e[1]-n[1],d=t[1]-n[1],y=Math.max(Math.abs(s),Math.abs(A),Math.abs(a)),l=Math.max(Math.abs(i),Math.abs(c),Math.abs(d)),f=0,x=0,u=0,m=l/(y+1e-5);m>1.5?f+=Se.DISTANCE_VOTE_POWER:m>.66?x+=Se.DISTANCE_VOTE_POWER:u+=Se.DISTANCE_VOTE_POWER;let g=Math.sqrt(s*s+i*i),P=Math.sqrt(A*A+c*c),v=Math.sqrt(a*a+d*d),p=Math.max(g,P,v),b=e[0],j=e[1],k=n[0],N=n[1];p===g?(k=n[0],N=n[1]):p===v&&(b=t[0],j=t[1]);let W=C3([b,j],[k,N]),Z=O3(W,Se.TOTAL_ANGLE_VOTE_POWER);f+=Z[0],x+=Z[1],u+=Z[2];for(let R of o){let D=O3(R,Se.SINGLE_ANGLE_VOTE_POWER);f+=D[0],x+=D[1],u+=D[2]}let J;return f===Math.max(f,x,u)?J=D3(c,i,d,l):u===Math.max(x,u)?J=W3(A,s,a,y):J=Ms(c,i,d,l,A,s,a,y),J}function F3(e){let t=[],n=[],o=[],s=[];if(!e)return{curls:o,directions:s};for(let A of b0.all){let a=b0.getPoints(A),i=[],c=[];for(let d of a){let y=e[d[0]],l=e[d[1]],f=C3(y,l),x=f[0],u=f[1];i.push(x),c.push(u)}t.push(i),n.push(c)}for(let A of b0.all){let a=A===b0.thumb?1:0,i=b0.getPoints(A),c=e[i[a][0]],d=e[i[a+1][1]],y=e[i[3][1]],l=Rs(c,d,y),f=Ps(c,d,y,t[A].slice(a));o[A]=l,s[A]=f}return{curls:o,directions:s}}function B2(e){if(!e||e.length===0)return null;let t=F3(e),n={};for(let o of b0.all)n[b0.getName(o)]={curl:xe.getName(t.curls[o]),direction:$.getName(t.directions[o])};return n}function B3(e){let t=[];if(!e||e.length===0)return t;let n=F3(e);for(let o of N3){let s=o.matchAgainst(n.curls,n.directions);s>=vs&&t.push({name:o.name,confidence:s})}return t}var H3=e=>{if(!e)return[];let t=[];for(let n=0;nc.part==="leftWrist"),s=e[n].keypoints.find(c=>c.part==="rightWrist"),A=e[n].keypoints.find(c=>c.part==="nose");A&&o&&s&&o.position[1]c.part==="leftShoulder"),i=e[n].keypoints.find(c=>c.part==="rightShoulder");a&&i&&Math.abs(a.positionRaw[1]-i.positionRaw[1])>.1&&t.push({body:n,gesture:`leaning ${a.position[1]>i.position[1]?"left":"right"}`})}return t},G3=e=>{if(!e)return[];let t=[];for(let n=0;n450){let o=(e[n].mesh[33][2]||0)-(e[n].mesh[263][2]||0),s=e[n].mesh[33][0]-e[n].mesh[263][0];Math.abs(o/s)<=.15?t.push({face:n,gesture:"facing center"}):t.push({face:n,gesture:`facing ${o<0?"left":"right"}`}),Math.abs(e[n].mesh[374][1]-e[n].mesh[386][1])/Math.abs(e[n].mesh[443][1]-e[n].mesh[450][1])<.2&&t.push({face:n,gesture:"blink left eye"}),Math.abs(e[n].mesh[145][1]-e[n].mesh[159][1])/Math.abs(e[n].mesh[223][1]-e[n].mesh[230][1])<.2&&t.push({face:n,gesture:"blink right eye"});let i=Math.min(100,500*Math.abs(e[n].mesh[13][1]-e[n].mesh[14][1])/Math.abs(e[n].mesh[10][1]-e[n].mesh[152][1]));i>10&&t.push({face:n,gesture:`mouth ${Math.trunc(i)}% open`});let c=e[n].mesh[152][2]||0;Math.abs(c)>10&&t.push({face:n,gesture:`head ${c<0?"up":"down"}`})}return t},V3=e=>{var n,o,s,A;if(!e)return[];let t=[];for(let a=0;a.06||g>.06)&&(x=!1),m>g?m>.05&&t.push({iris:a,gesture:"looking right"}):g>.05&&t.push({iris:a,gesture:"looking left"});let P=Math.abs(e[a].mesh[145][1]-e[a].annotations.rightEyeIris[0][1])/e[a].box[3],v=Math.abs(e[a].mesh[374][1]-e[a].annotations.leftEyeIris[0][1])/e[a].box[3];(v<.01||P<.01||v>.022||P>.022)&&(x=!1),(v<.01||P<.01)&&t.push({iris:a,gesture:"looking down"}),(v>.022||P>.022)&&t.push({iris:a,gesture:"looking up"}),x&&t.push({iris:a,gesture:"looking center"})}return t},Z3=e=>{if(!e)return[];let t=[];for(let n=0;n0){let s=o.reduce((a,i)=>(a.position[2]||0)<(i.position[2]||0)?a:i);t.push({hand:n,gesture:`${s.name} forward`});let A=o.reduce((a,i)=>a.position[1][A[0]*t[0],A[1]*t[1]]);return{startPoint:n,endPoint:o,palmLandmarks:s,confidence:e.confidence}}function G2(e,t=1.5){let n=o2(e),o=H2(e),s=[t*o[0]/2,t*o[1]/2],A=[n[0]-s[0],n[1]-s[1]],a=[n[0]+s[0],n[1]+s[1]];return{startPoint:A,endPoint:a,palmLandmarks:e.palmLandmarks}}function V2(e){let t=o2(e),n=H2(e),s=Math.max(...n)/2,A=[t[0]-s,t[1]-s],a=[t[0]+s,t[1]+s];return{startPoint:A,endPoint:a,palmLandmarks:e.palmLandmarks}}function ws(e){return e-2*Math.PI*Math.floor((e+Math.PI)/(2*Math.PI))}function K3(e,t){let n=Math.PI/2-Math.atan2(-(t[1]-e[1]),t[0]-e[0]);return ws(n)}var X3=(e,t)=>[[1,0,e],[0,1,t],[0,0,1]];function pe(e,t){let n=0;for(let o=0;o[a.x,a.y]),this.anchorsTensor=r.tensor2d(this.anchors),this.inputSize=((A=(s=(o=(n=this==null?void 0:this.model)==null?void 0:n.inputs)==null?void 0:o[0])==null?void 0:s.shape)==null?void 0:A[2])||0,this.inputSizeTensor=r.tensor1d([this.inputSize,this.inputSize]),this.doubleInputSizeTensor=r.tensor1d([this.inputSize*2,this.inputSize*2])}normalizeBoxes(t){let n={};n.boxOffsets=r.slice(t,[0,0],[-1,2]),n.boxSizes=r.slice(t,[0,2],[-1,2]),n.div=r.div(n.boxOffsets,this.inputSizeTensor),n.boxCenterPoints=r.add(n.div,this.anchorsTensor),n.halfBoxSizes=r.div(n.boxSizes,this.doubleInputSizeTensor),n.sub=r.sub(n.boxCenterPoints,n.halfBoxSizes),n.startPoints=r.mul(n.sub,this.inputSizeTensor),n.add=r.add(n.boxCenterPoints,n.halfBoxSizes),n.endPoints=r.mul(n.add,this.inputSizeTensor);let o=r.concat2d([n.startPoints,n.endPoints],1);return Object.keys(n).forEach(s=>r.dispose(n[s])),o}normalizeLandmarks(t,n){let o={};o.reshape=r.reshape(t,[-1,7,2]),o.div=r.div(o.reshape,this.inputSizeTensor),o.landmarks=r.add(o.div,this.anchors[n]?this.anchors[n]:0);let s=r.mul(o.landmarks,this.inputSizeTensor);return Object.keys(o).forEach(A=>r.dispose(o[A])),s}async predict(t,n){var i;let o={};o.resize=r.image.resizeBilinear(t,[this.inputSize,this.inputSize]),o.div=r.div(o.resize,O.tf127),o.image=r.sub(o.div,O.tf1),o.batched=this.model.execute(o.image),o.predictions=r.squeeze(o.batched),o.slice=r.slice(o.predictions,[0,0],[-1,1]),o.sigmoid=r.sigmoid(o.slice),o.scores=r.squeeze(o.sigmoid);let s=await o.scores.data();o.boxes=r.slice(o.predictions,[0,1],[-1,4]),o.norm=this.normalizeBoxes(o.boxes),o.nms=await r.image.nonMaxSuppressionAsync(o.norm,o.scores,3*(((i=n.hand)==null?void 0:i.maxDetected)||1),n.hand.iouThreshold,n.hand.minConfidence);let A=await o.nms.array(),a=[];for(let c of A){let d={};d.box=r.slice(o.norm,[c,0],[1,-1]),d.slice=r.slice(o.predictions,[c,5],[1,14]),d.norm=this.normalizeLandmarks(d.slice,c),d.palmLandmarks=r.reshape(d.norm,[-1,2]);let y=await d.box.data(),l=y.slice(0,2),f=y.slice(2,4),x=await d.palmLandmarks.array(),u={startPoint:l,endPoint:f,palmLandmarks:x,confidence:s[c]},m=Y3(u,[(t.shape[2]||1)/this.inputSize,(t.shape[1]||0)/this.inputSize]);a.push(m),Object.keys(d).forEach(g=>r.dispose(d[g]))}return Object.keys(o).forEach(c=>r.dispose(o[c])),a}};var js=5,$3=1.65,en=[0,5,9,13,17,1,2],Is=0,Ns=2,tn=0,X2=class{constructor(t,n){E(this,"handDetector");E(this,"handPoseModel");E(this,"inputSize");E(this,"storedBoxes");E(this,"skipped");E(this,"detectedHands");var o,s,A;this.handDetector=t,this.handPoseModel=n,this.inputSize=((A=(s=(o=this.handPoseModel)==null?void 0:o.inputs)==null?void 0:s[0].shape)==null?void 0:A[2])||0,this.storedBoxes=[],this.skipped=Number.MAX_SAFE_INTEGER,this.detectedHands=0}calculateLandmarksBoundingBox(t){let n=t.map(a=>a[0]),o=t.map(a=>a[1]),s=[Math.min(...n),Math.min(...o)],A=[Math.max(...n),Math.max(...o)];return{startPoint:s,endPoint:A}}getBoxForPalmLandmarks(t,n){let o=t.map(A=>c5([...A,1],n)),s=this.calculateLandmarksBoundingBox(o);return G2(V2(s),js)}getBoxForHandLandmarks(t){let n=this.calculateLandmarksBoundingBox(t),o=G2(V2(n),$3);o.palmLandmarks=[];for(let s=0;s[a[0]*(x[0]-this.inputSize/2),a[1]*(x[1]-this.inputSize/2),a[2]*x[2]]),c=l5(o,[0,0]),d=i.map(x=>[...c5(x,c),x[2]]),y=J3(s),l=[...o2(n),1],f=[pe(l,y[0]),pe(l,y[1])];return d.map(x=>[Math.trunc(x[0]+f[0]),Math.trunc(x[1]+f[1]),Math.trunc(x[2])])}async estimateHands(t,n){let o=!1,s,A=(n.hand.skipTime||0)>T()-tn,a=this.skipped<(n.hand.skipFrames||0);n.skipAllowed&&A&&a&&(s=await this.handDetector.predict(t,n),this.skipped=0),n.skipAllowed&&this.skipped++,s&&s.length>0&&(s.length!==this.detectedHands&&this.detectedHands!==n.hand.maxDetected||!n.hand.landmarks)&&(this.detectedHands=0,this.storedBoxes=[...s],this.storedBoxes.length>0&&(o=!0));let i=[];for(let c=0;c=n.hand.minConfidence/4){let j=r.reshape(p,[-1,3]),k=await j.array();r.dispose(p),r.dispose(j);let N=this.transformRawCoords(k,m,y,u),B=this.getBoxForHandLandmarks(N);this.storedBoxes[c]={...B,confidence:b};let q={landmarks:N,confidence:b,boxConfidence:d.confidence,fingerConfidence:b,box:{topLeft:B.startPoint,bottomRight:B.endPoint}};i.push(q)}else this.storedBoxes[c]=null;r.dispose(p)}else{let y=G2(V2(d),$3),l={confidence:d.confidence,boxConfidence:d.confidence,fingerConfidence:0,box:{topLeft:y.startPoint,bottomRight:y.endPoint},landmarks:[]};i.push(l)}}return this.storedBoxes=this.storedBoxes.filter(c=>c!==null),this.detectedHands=i.length,i.length>n.hand.maxDetected&&(i.length=n.hand.maxDetected),i}};var nn={thumb:[1,2,3,4],index:[5,6,7,8],middle:[9,10,11,12],ring:[13,14,15,16],pinky:[17,18,19,20],palm:[0]},je,Ie,on;async function d5(e,t){let n=await on.estimateHands(e,t);if(!n)return[];let o=[];for(let s=0;sn[s].landmarks[l]);let a=n[s].landmarks,i=[Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,0,0],c=[0,0,0,0];if(a&&a.length>0){for(let y of a)y[0]i[2]&&(i[2]=y[0]),y[1]>i[3]&&(i[3]=y[1]);i[2]-=i[0],i[3]-=i[1],c=[i[0]/(e.shape[2]||0),i[1]/(e.shape[1]||0),i[2]/(e.shape[2]||0),i[3]/(e.shape[1]||0)]}else i=n[s].box?[Math.trunc(Math.max(0,n[s].box.topLeft[0])),Math.trunc(Math.max(0,n[s].box.topLeft[1])),Math.trunc(Math.min(e.shape[2]||0,n[s].box.bottomRight[0])-Math.max(0,n[s].box.topLeft[0])),Math.trunc(Math.min(e.shape[1]||0,n[s].box.bottomRight[1])-Math.max(0,n[s].box.topLeft[1]))]:[0,0,0,0],c=[n[s].box.topLeft[0]/(e.shape[2]||0),n[s].box.topLeft[1]/(e.shape[1]||0),(n[s].box.bottomRight[0]-n[s].box.topLeft[0])/(e.shape[2]||0),(n[s].box.bottomRight[1]-n[s].box.topLeft[1])/(e.shape[1]||0)];let d=B2(a);o.push({id:s,score:Math.round(100*n[s].confidence)/100,boxScore:Math.round(100*n[s].boxConfidence)/100,fingerScore:Math.round(100*n[s].fingerConfidence)/100,label:"hand",box:i,boxRaw:c,keypoints:a,annotations:A,landmarks:d})}return o}async function rn(e){var n,o;M.initial&&(je=null,Ie=null),!je||!Ie?[je,Ie]=await Promise.all([e.hand.enabled?L((n=e.hand.detector)==null?void 0:n.modelPath):null,e.hand.landmarks?L((o=e.hand.skeleton)==null?void 0:o.modelPath):null]):(e.debug&&h("cached model:",je.modelUrl),e.debug&&h("cached model:",Ie.modelUrl));let t=je?new Z2(je):void 0;return t&&Ie&&(on=new X2(t,Ie)),[je,Ie]}var n0=[null,null],Os=["StatefulPartitionedCall/Postprocessor/Slice","StatefulPartitionedCall/Postprocessor/ExpandDims_1"],ue=[[0,0],[0,0]],Cs=["hand","fist","pinch","point","face","tip","pinchtip"],An=4,an=1.6,Ws=512,Ds=1.4,q2=Number.MAX_SAFE_INTEGER,x5=0,$0=[0,0],t0={boxes:[],hands:[]},ln={thumb:[1,2,3,4],index:[5,6,7,8],middle:[9,10,11,12],ring:[13,14,15,16],pinky:[17,18,19,20],base:[0],palm:[0,17,13,9,5,1,0]};async function cn(e){var t;if(M.initial&&(n0[0]=null),n0[0])e.debug&&h("cached model:",n0[0].modelUrl);else{u2(["tensorlistreserve","enter","tensorlistfromtensor","merge","loopcond","switch","exit","tensorliststack","nextiteration","tensorlistsetitem","tensorlistgetitem","reciprocal","shape","split","where"],e),n0[0]=await L((t=e.hand.detector)==null?void 0:t.modelPath);let n=n0[0].executor?Object.values(n0[0].modelSignature.inputs):void 0;ue[0][0]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[1].size):0,ue[0][1]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[2].size):0}return n0[0]}async function dn(e){var t;if(M.initial&&(n0[1]=null),n0[1])e.debug&&h("cached model:",n0[1].modelUrl);else{n0[1]=await L((t=e.hand.skeleton)==null?void 0:t.modelPath);let n=n0[1].executor?Object.values(n0[1].modelSignature.inputs):void 0;ue[1][0]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[1].size):0,ue[1][1]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[2].size):0}return n0[1]}async function Fs(e,t){let n=[];if(!e||!n0[0])return n;let o={},s=(e.shape[2]||1)/(e.shape[1]||1),A=Math.min(Math.round((e.shape[1]||0)/8)*8,Ws),a=Math.round(A*s/8)*8;o.resize=r.image.resizeBilinear(e,[A,a]),o.cast=r.cast(o.resize,"int32"),[o.rawScores,o.rawBoxes]=await n0[0].executeAsync(o.cast,Os),o.boxes=r.squeeze(o.rawBoxes,[0,2]),o.scores=r.squeeze(o.rawScores,[0]);let i=r.unstack(o.scores,1);r.dispose(i[An]),i.splice(An,1),o.filtered=r.stack(i,1),r.dispose(i),o.max=r.max(o.filtered,1),o.argmax=r.argMax(o.filtered,1);let c=0;o.nms=await r.image.nonMaxSuppressionAsync(o.boxes,o.max,(t.hand.maxDetected||0)+1,t.hand.iouThreshold||0,t.hand.minConfidence||1);let d=await o.nms.data(),y=await o.max.data(),l=await o.argmax.data();for(let f of Array.from(d)){let x=r.slice(o.boxes,f,1),u=await x.data();r.dispose(x);let m=[u[1],u[0],u[3]-u[1],u[2]-u[0]],g=P2(m,Ds),P=[Math.trunc(m[0]*$0[0]),Math.trunc(m[1]*$0[1]),Math.trunc(m[2]*$0[0]),Math.trunc(m[3]*$0[1])],v=y[f],p=Cs[l[f]],b={id:c++,score:v,box:P,boxRaw:g,label:p};n.push(b)}return Object.keys(o).forEach(f=>r.dispose(o[f])),n.sort((f,x)=>x.score-f.score),n.length>(t.hand.maxDetected||1)&&(n.length=t.hand.maxDetected||1),n}async function y5(e,t,n){let o={id:t.id,score:Math.round(100*t.score)/100,boxScore:Math.round(100*t.score)/100,fingerScore:0,box:t.box,boxRaw:t.boxRaw,label:t.label,keypoints:[],landmarks:{},annotations:{}};if(e&&n0[1]&&n.hand.landmarks&&t.score>(n.hand.minConfidence||0)){let s={},A=[t.boxRaw[1],t.boxRaw[0],t.boxRaw[3]+t.boxRaw[1],t.boxRaw[2]+t.boxRaw[0]];s.crop=r.image.cropAndResize(e,[A],[0],[ue[1][0],ue[1][1]],"bilinear"),s.div=r.div(s.crop,O.tf255),[s.score,s.keypoints]=n0[1].execute(s.div,["Identity_1","Identity"]);let a=(await s.score.data())[0],i=(100-Math.trunc(100/(1+Math.exp(a))))/100;if(i>=(n.hand.minConfidence||0)){o.fingerScore=i,s.reshaped=r.reshape(s.keypoints,[-1,3]);let y=(await s.reshaped.array()).map(l=>[l[0]/ue[1][1],l[1]/ue[1][0],l[2]||0]).map(l=>[l[0]*t.boxRaw[2],l[1]*t.boxRaw[3],l[2]||0]);o.keypoints=y.map(l=>[$0[0]*(l[0]+t.boxRaw[0]),$0[1]*(l[1]+t.boxRaw[1]),l[2]||0]),o.landmarks=B2(o.keypoints);for(let l of Object.keys(ln))o.annotations[l]=ln[l].map(f=>o.landmarks&&o.keypoints[f]?o.keypoints[f]:null)}Object.keys(s).forEach(c=>r.dispose(s[c]))}return o}async function f5(e,t){var s,A;if(!((s=n0[0])!=null&&s.executor)||!((A=n0[1])!=null&&A.executor)||!n0[0].inputs[0].shape||!n0[1].inputs[0].shape)return[];$0=[e.shape[2]||0,e.shape[1]||0],q2++;let n=(t.hand.skipTime||0)>T()-x5,o=q2<(t.hand.skipFrames||0);return t.skipAllowed&&n&&o?t0.hands:new Promise(async a=>{let i=3*(t.hand.skipTime||0)>T()-x5,c=q2<3*(t.hand.skipFrames||0);t.skipAllowed&&t0.hands.length===t.hand.maxDetected?t0.hands=await Promise.all(t0.boxes.map(y=>y5(e,y,t))):t.skipAllowed&&i&&c&&t0.hands.length>0?t0.hands=await Promise.all(t0.boxes.map(y=>y5(e,y,t))):(t0.boxes=await Fs(e,t),x5=T(),t0.hands=await Promise.all(t0.boxes.map(y=>y5(e,y,t))),q2=0);let d=[...t0.boxes];if(t0.boxes.length=0,t.cacheSensitivity>0)for(let y=0;y.05&&l.box[3]/(e.shape[1]||1)>.05&&t0.hands[y].fingerScore&&t0.hands[y].fingerScore>(t.hand.minConfidence||0)){let f=P2(l.box,an),x=P2(l.boxRaw,an);t0.boxes.push({...d[y],box:f,boxRaw:x})}}for(let y=0;y({face:[],body:[],hand:[],gesture:[],object:[],persons:[],performance:{},timestamp:0,width:0,height:0,error:e});var r2={};oe(r2,{connected:()=>Y2,horizontal:()=>m5,kpt:()=>U2,relative:()=>u5,vertical:()=>p5});var U2=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"],m5=[["leftEye","rightEye"],["leftEar","rightEar"],["leftShoulder","rightShoulder"],["leftElbow","rightElbow"],["leftWrist","rightWrist"],["leftHip","rightHip"],["leftKnee","rightKnee"],["leftAnkle","rightAnkle"]],p5=[["leftKnee","leftShoulder"],["rightKnee","rightShoulder"],["leftAnkle","leftKnee"],["rightAnkle","rightKnee"]],u5=[[["leftHip","rightHip"],["leftShoulder","rightShoulder"]],[["leftElbow","rightElbow"],["leftShoulder","rightShoulder"]]],Y2={leftLeg:["leftHip","leftKnee","leftAnkle"],rightLeg:["rightHip","rightKnee","rightAnkle"],torso:["leftShoulder","rightShoulder","rightHip","leftHip","leftShoulder"],leftArm:["leftShoulder","leftElbow","leftWrist"],rightArm:["rightShoulder","rightElbow","rightWrist"],head:[]};var z=ee(),h5=0;function yn(e,t){var a,i,c,d,y,l,f,x,u,m,g,P,v,p,b,j,k,N,B,q,W,Z,J;let n=T();if(!e)return ee();let o=Date.now()-e.timestamp,s=o<1e3?8-Math.log(o+1):1;if(e.canvas&&(z.canvas=e.canvas),e.error&&(z.error=e.error),!z.body||e.body.length!==z.body.length)z.body=JSON.parse(JSON.stringify(e.body));else for(let R=0;R((s-1)*z.body[R].box[F]+C)/s),U=e.body[R].boxRaw.map((C,F)=>((s-1)*z.body[R].boxRaw[F]+C)/s),H=e.body[R].keypoints.map((C,F)=>{var S,N0,te,ne,i0,Ye,C5,W5,D5;return{score:C.score,part:C.part,position:[z.body[R].keypoints[F]?((s-1)*(z.body[R].keypoints[F].position[0]||0)+(C.position[0]||0))/s:C.position[0],z.body[R].keypoints[F]?((s-1)*(z.body[R].keypoints[F].position[1]||0)+(C.position[1]||0))/s:C.position[1],z.body[R].keypoints[F]?((s-1)*(z.body[R].keypoints[F].position[2]||0)+(C.position[2]||0))/s:C.position[2]],positionRaw:[z.body[R].keypoints[F]?((s-1)*(z.body[R].keypoints[F].positionRaw[0]||0)+(C.positionRaw[0]||0))/s:C.positionRaw[0],z.body[R].keypoints[F]?((s-1)*(z.body[R].keypoints[F].positionRaw[1]||0)+(C.positionRaw[1]||0))/s:C.positionRaw[1],z.body[R].keypoints[F]?((s-1)*(z.body[R].keypoints[F].positionRaw[2]||0)+(C.positionRaw[2]||0))/s:C.positionRaw[2]],distance:[z.body[R].keypoints[F]?((s-1)*(((S=z.body[R].keypoints[F].distance)==null?void 0:S[0])||0)+(((N0=C.distance)==null?void 0:N0[0])||0))/s:(te=C.distance)==null?void 0:te[0],z.body[R].keypoints[F]?((s-1)*(((ne=z.body[R].keypoints[F].distance)==null?void 0:ne[1])||0)+(((i0=C.distance)==null?void 0:i0[1])||0))/s:(Ye=C.distance)==null?void 0:Ye[1],z.body[R].keypoints[F]?((s-1)*(((C5=z.body[R].keypoints[F].distance)==null?void 0:C5[2])||0)+(((W5=C.distance)==null?void 0:W5[2])||0))/s:(D5=C.distance)==null?void 0:D5[2]]}}),a0={},o0={connected:{}};(a=t.body.modelPath)!=null&&a.includes("efficientpose")?o0=E2:(i=t.body.modelPath)!=null&&i.includes("blazepose")?o0=R2:(c=t.body.modelPath)!=null&&c.includes("movenet")&&(o0=r2);for(let[C,F]of Object.entries(o0.connected)){let S=[];for(let N0=0;N0i0.part===F[N0]),ne=H.find(i0=>i0.part===F[N0+1]);te&&ne&&S.push([te.position,ne.position])}a0[C]=S}z.body[R]={...e.body[R],box:D,boxRaw:U,keypoints:H,annotations:a0}}if(!z.hand||e.hand.length!==z.hand.length)z.hand=JSON.parse(JSON.stringify(e.hand));else for(let R=0;R((s-1)*z.hand[R].box[C]+o0)/s),U=e.hand[R].boxRaw.map((o0,C)=>((s-1)*z.hand[R].boxRaw[C]+o0)/s);z.hand[R].keypoints.length!==e.hand[R].keypoints.length&&(z.hand[R].keypoints=e.hand[R].keypoints);let H=e.hand[R].keypoints&&e.hand[R].keypoints.length>0?e.hand[R].keypoints.map((o0,C)=>o0.map((F,S)=>((s-1)*(z.hand[R].keypoints[C][S]||1)+(F||0))/s)):[],a0={};if(Object.keys(z.hand[R].annotations).length!==Object.keys(e.hand[R].annotations).length)z.hand[R].annotations=e.hand[R].annotations,a0=z.hand[R].annotations;else if(e.hand[R].annotations)for(let o0 of Object.keys(e.hand[R].annotations))a0[o0]=(l=(y=(d=e.hand[R])==null?void 0:d.annotations)==null?void 0:y[o0])!=null&&l[0]?e.hand[R].annotations[o0].map((C,F)=>C.map((S,N0)=>((s-1)*z.hand[R].annotations[o0][F][N0]+S)/s)):null;z.hand[R]={...e.hand[R],box:D,boxRaw:U,keypoints:H,annotations:a0}}if(!z.face||e.face.length!==z.face.length)z.face=JSON.parse(JSON.stringify(e.face));else for(let R=0;R((s-1)*z.face[R].box[a0]+H)/s),U=e.face[R].boxRaw.map((H,a0)=>((s-1)*z.face[R].boxRaw[a0]+H)/s);if(e.face[R].rotation){let H={matrix:[0,0,0,0,0,0,0,0,0],angle:{roll:0,yaw:0,pitch:0},gaze:{bearing:0,strength:0}};H.matrix=(f=e.face[R].rotation)==null?void 0:f.matrix,H.angle={roll:((s-1)*(((u=(x=z.face[R].rotation)==null?void 0:x.angle)==null?void 0:u.roll)||0)+(((g=(m=e.face[R].rotation)==null?void 0:m.angle)==null?void 0:g.roll)||0))/s,yaw:((s-1)*(((v=(P=z.face[R].rotation)==null?void 0:P.angle)==null?void 0:v.yaw)||0)+(((b=(p=e.face[R].rotation)==null?void 0:p.angle)==null?void 0:b.yaw)||0))/s,pitch:((s-1)*(((k=(j=z.face[R].rotation)==null?void 0:j.angle)==null?void 0:k.pitch)||0)+(((B=(N=e.face[R].rotation)==null?void 0:N.angle)==null?void 0:B.pitch)||0))/s},H.gaze={bearing:((s-1)*(((q=z.face[R].rotation)==null?void 0:q.gaze.bearing)||0)+(((W=e.face[R].rotation)==null?void 0:W.gaze.bearing)||0))/s,strength:((s-1)*(((Z=z.face[R].rotation)==null?void 0:Z.gaze.strength)||0)+(((J=e.face[R].rotation)==null?void 0:J.gaze.strength)||0))/s},z.face[R]={...e.face[R],rotation:H,box:D,boxRaw:U}}else z.face[R]={...e.face[R],box:D,boxRaw:U}}if(!z.object||e.object.length!==z.object.length)z.object=JSON.parse(JSON.stringify(e.object));else for(let R=0;R((s-1)*z.object[R].box[a0]+H)/s),U=e.object[R].boxRaw.map((H,a0)=>((s-1)*z.object[R].boxRaw[a0]+H)/s);z.object[R]={...e.object[R],box:D,boxRaw:U}}if(e.persons){let R=e.persons;if(!z.persons||R.length!==z.persons.length)z.persons=JSON.parse(JSON.stringify(R));else for(let D=0;D((s-1)*z.persons[D].box[H]+U)/s)}e.gesture&&(z.gesture=e.gesture),z.width=e.width,z.height=e.height;let A=T();return h5=M.perfadd?h5+Math.round(A-n):Math.round(A-n),e.performance&&(z.performance={...e.performance,interpolate:h5}),z}var m0;async function b5(e){return!m0||M.initial?m0=await L(e.segmentation.modelPath):e.debug&&h("cached model:",m0.modelUrl),m0}async function fn(e,t){var s;if(m0||(m0=await b5(t)),!(m0!=null&&m0.executor)||!((s=m0==null?void 0:m0.inputs)!=null&&s[0].shape))return null;let n={};n.resize=r.image.resizeBilinear(e,[m0.inputs[0].shape?m0.inputs[0].shape[1]:0,m0.inputs[0].shape?m0.inputs[0].shape[2]:0],!1),n.norm=r.div(n.resize,O.tf255),n.res=m0.execute(n.norm),n.squeeze=r.squeeze(n.res,[0]),[n.bgRaw,n.fgRaw]=r.unstack(n.squeeze,2),n.fg=r.softmax(n.fgRaw),n.mul=r.mul(n.fg,O.tf255),n.expand=r.expandDims(n.mul,2),n.output=r.image.resizeBilinear(n.expand,[e.shape[1]||0,e.shape[2]||0]);let o;switch(t.segmentation.mode||"default"){case"default":n.input=r.squeeze(e),n.concat=r.concat([n.input,n.output],-1),o=r.cast(n.concat,"int32");break;case"alpha":o=r.cast(n.output,"int32");break;default:o=r.tensor(0)}return Object.keys(n).forEach(A=>r.dispose(n[A])),o}var T5={};oe(T5,{distance:()=>g5,find:()=>Gs,similarity:()=>Hs});function g5(e,t,n={order:2,multiplier:25}){if(!e||!e)return Number.MAX_SAFE_INTEGER;let o=0;for(let s=0;s{if(e===0)return 1;let A=(1-(t===2?Math.sqrt(e):e**(1/t))/100-n)/(o-n);return Math.max(Math.min(A,1),0)};function Hs(e,t,n={order:2,multiplier:25,min:.2,max:.8}){let o=g5(e,t,n);return pn(o,n.order||2,n.min||0,n.max||1)}function Gs(e,t,n={order:2,multiplier:25,threshold:0,min:.2,max:.8}){if(!Array.isArray(e)||!Array.isArray(t)||e.length<64||t.length===0)return{index:-1,distance:Number.POSITIVE_INFINITY,similarity:0};let o=Number.MAX_SAFE_INTEGER,s=-1;for(let a=0;aa2,validateModel:()=>tt});var un=.005,w0={keypoints:[],padding:[[0,0],[0,0],[0,0],[0,0]]};function v5(e){for(let t of m5){let n=e.keypoints.findIndex(s=>s.part===t[0]),o=e.keypoints.findIndex(s=>s.part===t[1]);if(e.keypoints[n]&&e.keypoints[o]&&e.keypoints[n].position[0]s&&s.part===t[0]),o=e.keypoints.findIndex(s=>s&&s.part===t[1]);e.keypoints[n]&&e.keypoints[o]&&e.keypoints[n].position[1]d&&d.part===t[0]),s=e.keypoints.findIndex(d=>d&&d.part===t[1]),A=e.keypoints.findIndex(d=>d&&d.part===n[0]),a=e.keypoints.findIndex(d=>d&&d.part===n[1]);if(!e.keypoints[A]||!e.keypoints[a])continue;let i=e.keypoints[o]?[Math.abs(e.keypoints[A].position[0]-e.keypoints[o].position[0]),Math.abs(e.keypoints[a].position[0]-e.keypoints[o].position[0])]:[0,0],c=e.keypoints[s]?[Math.abs(e.keypoints[a].position[0]-e.keypoints[s].position[0]),Math.abs(e.keypoints[A].position[0]-e.keypoints[s].position[0])]:[0,0];if(i[0]>i[1]||c[0]>c[1]){let d=e.keypoints[o];e.keypoints[o]=e.keypoints[s],e.keypoints[s]=d}}}function hn(e){for(let t=0;te.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0,e.shape[2]>e.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0],[e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0,e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0],[0,0]],n.pad=r.pad(e,w0.padding),n.resize=r.image.resizeBilinear(n.pad,[t,t]);let o=r.cast(n.resize,"int32");return Object.keys(n).forEach(a=>r.dispose(n[a])),o}function gn(e,t){e.keypoints=e.keypoints.filter(o=>o==null?void 0:o.position);for(let o of e.keypoints)o.position=[o.position[0]*(t[0]+w0.padding[2][0]+w0.padding[2][1])/t[0]-w0.padding[2][0],o.position[1]*(t[1]+w0.padding[1][0]+w0.padding[1][1])/t[1]-w0.padding[1][0]],o.positionRaw=[o.position[0]/t[0],o.position[1]/t[1]];let n=J0(e.keypoints.map(o=>o.position),t);return e.box=n.box,e.boxRaw=n.boxRaw,e}var s0,K2=0,R5=Number.MAX_SAFE_INTEGER,Ne={boxes:[],bodies:[],last:0};async function Tn(e){var t;return M.initial&&(s0=null),s0?e.debug&&h("cached model:",s0.modelUrl):(u2(["size"],e),s0=await L(e.body.modelPath)),K2=(s0==null?void 0:s0.executor)&&((t=s0==null?void 0:s0.inputs)==null?void 0:t[0].shape)?s0.inputs[0].shape[2]:0,K2<64&&(K2=256),s0}function Zs(e,t,n){let o=e[0][0],s=[],A=0;for(let y=0;yt.body.minConfidence){let l=[o[y][1],o[y][0]];s.push({score:Math.round(100*A)/100,part:U2[y],positionRaw:l,position:[Math.round((n.shape[2]||0)*l[0]),Math.round((n.shape[1]||0)*l[1])]})}A=s.reduce((y,l)=>l.score>y?l.score:y,0);let a=[],i=J0(s.map(y=>y.position),[n.shape[2],n.shape[1]]),c={};for(let[y,l]of Object.entries(Y2)){let f=[];for(let x=0;xg.part===l[x]),m=s.find(g=>g.part===l[x+1]);u&&m&&u.score>(t.body.minConfidence||0)&&m.score>(t.body.minConfidence||0)&&f.push([u.position,m.position])}c[y]=f}let d={id:0,score:A,box:i.box,boxRaw:i.boxRaw,keypoints:s,annotations:c};return v5(d),a.push(d),a}function Xs(e,t,n){let o=[];for(let s=0;st.body.minConfidence){let i=[];for(let l=0;l<17;l++){let f=A[3*l+2];if(f>t.body.minConfidence){let x=[A[3*l+1],A[3*l+0]];i.push({part:U2[l],score:Math.round(100*f)/100,positionRaw:x,position:[Math.round((n.shape[2]||0)*x[0]),Math.round((n.shape[1]||0)*x[1])]})}}let c=J0(i.map(l=>l.position),[n.shape[2],n.shape[1]]),d={};for(let[l,f]of Object.entries(Y2)){let x=[];for(let u=0;uP.part===f[u]),g=i.find(P=>P.part===f[u+1]);m&&g&&m.score>(t.body.minConfidence||0)&&g.score>(t.body.minConfidence||0)&&x.push([m.position,g.position])}d[l]=x}let y={id:s,score:a,box:c.box,boxRaw:c.boxRaw,keypoints:[...i],annotations:d};v5(y),o.push(y)}}return o.sort((s,A)=>A.score-s.score),o.length>t.body.maxDetected&&(o.length=t.body.maxDetected),o}async function M5(e,t){var s;if(!(s0!=null&&s0.executor)||!((s=s0==null?void 0:s0.inputs)!=null&&s[0].shape))return[];t.skipAllowed||(Ne.boxes.length=0),R5++;let n=(t.body.skipTime||0)>T()-Ne.last,o=R5<(t.body.skipFrames||0);return t.skipAllowed&&n&&o?Ne.bodies:new Promise(async A=>{let a={};R5=0,a.input=bn(e,K2),a.res=s0==null?void 0:s0.execute(a.input),Ne.last=T();let i=await a.res.array();Ne.bodies=a.res.shape[2]===17?Zs(i,t,e):Xs(i,t,e);for(let c of Ne.bodies)gn(c,[e.shape[2]||1,e.shape[1]||1]),hn(c.keypoints);Object.keys(a).forEach(c=>r.dispose(a[c])),A(Ne.bodies)})}var F0,J2=[],Rn=0,P5=Number.MAX_SAFE_INTEGER,_2=0,Q2=2.5;async function Mn(e){if(!F0||M.initial){F0=await L(e.object.modelPath);let t=F0!=null&&F0.executor?Object.values(F0.modelSignature.inputs):void 0;_2=Array.isArray(t)?parseInt(t[0].tensorShape.dim[2].size):416}else e.debug&&h("cached model:",F0.modelUrl);return F0}async function qs(e,t,n){var d,y;let o=0,s=[],A=_2;for(let l of[1,2,4]){let f=l*13,x=r.squeeze(e.find(p=>p.shape[1]===f**2&&(p.shape[2]||0)===Ce.length)),u=await x.array(),m=r.squeeze(e.find(p=>p.shape[1]===f**2&&(p.shape[2]||0)(n.object.minConfidence||0)&&b!==61){let k=(.5+Math.trunc(p%f))/f,N=(.5+Math.trunc(p/f))/f,B=v[p].map(H=>H*(f/l/A)),[q,W]=[k-Q2/l*B[0],N-Q2/l*B[1]],[Z,J]=[k+Q2/l*B[2]-q,N+Q2/l*B[3]-W],R=[q,W,Z,J];R=R.map(H=>Math.max(0,Math.min(H,1)));let D=[R[0]*t[0],R[1]*t[1],R[2]*t[0],R[3]*t[1]],U={id:o++,score:Math.round(100*j)/100,class:b+1,label:Ce[b].label,box:D.map(H=>Math.trunc(H)),boxRaw:R};s.push(U)}}r.dispose([x,m,g,P])}let a=s.map(l=>[l.boxRaw[1],l.boxRaw[0],l.boxRaw[3],l.boxRaw[2]]),i=s.map(l=>l.score),c=[];if(a&&a.length>0){let l=await r.image.nonMaxSuppressionAsync(a,i,n.object.maxDetected||0,n.object.iouThreshold,n.object.minConfidence);c=Array.from(await l.data()),r.dispose(l)}return s=s.filter((l,f)=>c.includes(f)).sort((l,f)=>f.score-l.score),s}async function k5(e,t){if(!(F0!=null&&F0.executor))return[];let n=(t.object.skipTime||0)>T()-Rn,o=P5<(t.object.skipFrames||0);return t.skipAllowed&&n&&o&&J2.length>0?(P5++,J2):(P5=0,!M.kernels.includes("mod")||!M.kernels.includes("sparsetodense")?J2:new Promise(async s=>{let A=[e.shape[2]||0,e.shape[1]||0],a=r.image.resizeBilinear(e,[_2,_2],!1),i=r.div(a,O.tf255),c=r.transpose(i,[0,3,1,2]),d;t.object.enabled&&(d=F0.execute(c)),Rn=T();let y=await qs(d,A,t);J2=y,r.dispose([a,i,c,...d]),s(y)}))}var A2=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"],Us=A2.length,s2=A2.reduce((e,t,n)=>(e[t]=n,e),{}),Ys=[["leftHip","leftShoulder"],["leftElbow","leftShoulder"],["leftElbow","leftWrist"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["rightHip","rightShoulder"],["rightElbow","rightShoulder"],["rightElbow","rightWrist"],["rightHip","rightKnee"],["rightKnee","rightAnkle"],["leftShoulder","rightShoulder"],["leftHip","rightHip"]],H7=Ys.map(([e,t])=>[s2[e],s2[t]]),kn=[["nose","leftEye"],["leftEye","leftEar"],["nose","rightEye"],["rightEye","rightEar"],["nose","leftShoulder"],["leftShoulder","leftElbow"],["leftElbow","leftWrist"],["leftShoulder","leftHip"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["nose","rightShoulder"],["rightShoulder","rightElbow"],["rightElbow","rightWrist"],["rightShoulder","rightHip"],["rightHip","rightKnee"],["rightKnee","rightAnkle"]];function wn(e){let t=e.reduce(({maxX:n,maxY:o,minX:s,minY:A},{position:{x:a,y:i}})=>({maxX:Math.max(n,a),maxY:Math.max(o,i),minX:Math.min(s,a),minY:Math.min(A,i)}),{maxX:Number.NEGATIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY,minX:Number.POSITIVE_INFINITY,minY:Number.POSITIVE_INFINITY});return[t.minX,t.minY,t.maxX-t.minX,t.maxY-t.minY]}function En(e,[t,n],[o,s]){let A=t/o,a=n/s,i=(d,y)=>({id:y,score:d.score,boxRaw:[d.box[0]/s,d.box[1]/o,d.box[2]/s,d.box[3]/o],box:[Math.trunc(d.box[0]*a),Math.trunc(d.box[1]*A),Math.trunc(d.box[2]*a),Math.trunc(d.box[3]*A)],keypoints:d.keypoints.map(({score:l,part:f,position:x})=>({score:l,part:f,position:[Math.trunc(x.x*a),Math.trunc(x.y*A)],positionRaw:[x.x/o,x.y/o]})),annotations:{}});return e.map((d,y)=>i(d,y))}var $2=class{constructor(t,n){E(this,"priorityQueue");E(this,"numberOfElements");E(this,"getElementValue");this.priorityQueue=new Array(t),this.numberOfElements=-1,this.getElementValue=n}enqueue(t){this.priorityQueue[++this.numberOfElements]=t,this.swim(this.numberOfElements)}dequeue(){let t=this.priorityQueue[0];return this.exchange(0,this.numberOfElements--),this.sink(0),this.priorityQueue[this.numberOfElements+1]=null,t}empty(){return this.numberOfElements===-1}size(){return this.numberOfElements+1}all(){return this.priorityQueue.slice(0,this.numberOfElements+1)}max(){return this.priorityQueue[0]}swim(t){for(;t>0&&this.less(Math.floor(t/2),t);)this.exchange(t,Math.floor(t/2)),t=Math.floor(t/2)}sink(t){for(;2*t<=this.numberOfElements;){let n=2*t;if(nn?n:e}function zn(e,t,n,o){let s=n-e,A=o-t;return s*s+A*A}function S5(e,t){return{x:e.x+t.x,y:e.y+t.y}}var E0,Js=["MobilenetV1/offset_2/BiasAdd","MobilenetV1/heatmap_2/BiasAdd","MobilenetV1/displacement_fwd_2/BiasAdd","MobilenetV1/displacement_bwd_2/BiasAdd"],et=1,qe=16,Qs=50**2;function Sn(e,t,n,o,s,A,a=2){let i=P=>({y:A.get(P.y,P.x,e),x:A.get(P.y,P.x,A.shape[2]/2+e)}),c=(P,v,p)=>({y:z5(Math.round(P.y/qe),0,v-1),x:z5(Math.round(P.x/qe),0,p-1)}),[d,y]=o.shape,l=c(t.position,d,y),f=i(l),u=S5(t.position,f);for(let P=0;P[s2[f],s2[x]]),a=A.map(([,f])=>f),i=A.map(([f])=>f),c=t.shape[2],d=a.length,y=new Array(c),l=E5(e.part,qe,n);y[e.part.id]={score:e.score,part:A2[e.part.id],position:l};for(let f=d-1;f>=0;--f){let x=a[f],u=i[f];y[x]&&!y[u]&&(y[u]=Sn(f,y[x],u,t,n,s))}for(let f=0;ft){i=!1;break}if(!i)break}return i}function eA(e,t){let[n,o,s]=t.shape,A=new $2(n*o*s,({score:a})=>a);for(let a=0;a{var a;let A=(a=s[o])==null?void 0:a.position;return A?zn(n,t,A.y,A.x)<=Qs:!1})}function tA(e,t){return t.reduce((o,{position:s,score:A},a)=>(jn(e,s,a)||(o+=A),o),0)/t.length}function nA(e,t,n,o,s,A){let a=[],i=eA(A,t);for(;a.lengthx.score>A);let l=tA(a,y),f=wn(y);l>A&&a.push({keypoints:y,box:f,score:Math.round(100*l)/100})}return a}async function j5(e,t){if(!(E0!=null&&E0.executor))return[];let n=r.tidy(()=>{if(!E0.inputs[0].shape)return[];let a=r.image.resizeBilinear(e,[E0.inputs[0].shape[2],E0.inputs[0].shape[1]]),i=r.sub(r.div(r.cast(a,"float32"),127.5),1),d=E0.execute(i,Js).map(y=>r.squeeze(y,[0]));return d[1]=r.sigmoid(d[1]),d}),o=await Promise.all(n.map(a=>a.buffer()));for(let a of n)r.dispose(a);let s=nA(o[0],o[1],o[2],o[3],t.body.maxDetected,t.body.minConfidence);return E0.inputs[0].shape?En(s,[e.shape[1],e.shape[2]],[E0.inputs[0].shape[2],E0.inputs[0].shape[1]]):[]}async function In(e){return!E0||M.initial?E0=await L(e.body.modelPath):e.debug&&h("cached model:",E0.modelUrl),E0}var U0,oA=["fgr","pha","r1o","r2o","r3o","r4o"],A0={},N5=0;function On(e){r.dispose([A0.r1i,A0.r2i,A0.r3i,A0.r4i,A0.downsample_ratio]),A0.r1i=r.tensor(0),A0.r2i=r.tensor(0),A0.r3i=r.tensor(0),A0.r4i=r.tensor(0),N5=e.segmentation.ratio||.5,A0.downsample_ratio=r.tensor(N5)}async function L5(e){return!U0||M.initial?U0=await L(e.segmentation.modelPath):e.debug&&h("cached model:",U0.modelUrl),On(e),U0}var Ln=e=>r.tidy(()=>{let t=r.squeeze(e,[0]),n=r.mul(t,O.tf255);return r.cast(n,"int32")});function I5(e,t){let n=e?Ln(e):r.fill([t.shape[1]||0,t.shape[2]||0,3],255,"int32"),o=t?Ln(t):r.fill([e.shape[1]||0,e.shape[2]||0,1],255,"int32"),s=r.concat([n,o],-1);return r.dispose([n,o]),s}function rA(e){return r.tidy(()=>{let t={};return t.unstack=r.unstack(e,-1),t.concat=r.concat(t.unstack,1),t.split=r.split(t.concat,4,1),t.stack=r.concat(t.split,2),t.squeeze=r.squeeze(t.stack,[0]),t.expand=r.expandDims(t.squeeze,-1),t.add=r.add(t.expand,1),t.mul=r.mul(t.add,127.5),t.cast=r.cast(t.mul,"int32"),t.tile=r.tile(t.cast,[1,1,3]),t.alpha=r.fill([t.tile.shape[0]||0,t.tile.shape[1]||0,1],255,"int32"),r.concat([t.tile,t.alpha],-1)})}async function Cn(e,t){if(U0||(U0=await L5(t)),!(U0!=null&&U0.executor))return null;A0.src=r.div(e,255),N5!==t.segmentation.ratio&&On(t);let[n,o,s,A,a,i]=await U0.executeAsync(A0,oA),c;switch(t.segmentation.mode||"default"){case"default":c=I5(n,o);break;case"alpha":c=I5(null,o);break;case"foreground":c=I5(n,null);break;case"state":c=rA(s);break;default:c=r.tensor(0)}return r.dispose([A0.src,n,o,A0.r1i,A0.r2i,A0.r3i,A0.r4i]),[A0.r1i,A0.r2i,A0.r3i,A0.r4i]=[s,A,a,i],c}var p0;async function O5(e){return!p0||M.initial?p0=await L(e.segmentation.modelPath):e.debug&&h("cached model:",p0.modelUrl),p0}async function Dn(e,t){var s;if(p0||(p0=await O5(t)),!(p0!=null&&p0.executor)||!((s=p0==null?void 0:p0.inputs)!=null&&s[0].shape))return null;let n={};n.resize=r.image.resizeBilinear(e,[p0.inputs[0].shape?p0.inputs[0].shape[1]:0,p0.inputs[0].shape?p0.inputs[0].shape[2]:0],!1),n.norm=r.div(n.resize,O.tf255),n.res=p0.execute(n.norm),n.squeeze=r.squeeze(n.res,[0]),n.alpha=r.image.resizeBilinear(n.squeeze,[e.shape[1]||0,e.shape[2]||0]),n.mul=r.mul(n.alpha,O.tf255);let o;switch(t.segmentation.mode||"default"){case"default":n.input=r.squeeze(e),n.concat=r.concat([n.input,n.mul],-1),o=r.cast(n.concat,"int32");break;case"alpha":o=r.cast(n.mul,"int32");break;default:o=r.tensor(0)}return Object.keys(n).forEach(A=>r.dispose(n[A])),o}function tt(e,t,n){var d,y;if(!t||!((d=e==null?void 0:e.config)!=null&&d.validateModels))return null;let o=["const","placeholder","noop","pad","squeeze","add","sub","mul","div"],s=["biasadd","fusedbatchnormv3","matmul","switch","shape","merge","split","broadcastto"],A=[],a=[],i=t.modelUrl,c=t.executor;if((y=c==null?void 0:c.graph)!=null&&y.nodes)for(let l of Object.values(c.graph.nodes)){let f=l.op.toLowerCase();A.includes(f)||A.push(f)}else!c&&e.config.debug&&h("model not loaded",n);for(let l of A)!o.includes(l)&&!s.includes(l)&&!e.env.kernels.includes(l)&&!e.env.kernels.includes(l.replace("_",""))&&!e.env.kernels.includes(l.replace("native",""))&&!e.env.kernels.includes(l.replace("v2",""))&&a.push(l);return e.config.debug&&a.length>0&&h("model validation failed:",n,a),a.length>0?{name:n,missing:a,ops:A,url:i}:null}var a2=class{constructor(t){E(this,"instance");E(this,"models",{});this.models={},this.instance=t}stats(){let t=0,n=0,o=0;for(let A of Object.values(y0))t+=A.sizeFromManifest,n+=A.sizeLoadedWeights,o+=A.sizeDesired;let s=o>0?n/o:0;return{numLoadedModels:Object.values(y0).length,numDefinedModels:Object.keys(this.models).length,percentageLoaded:s,totalSizeFromManifest:t,totalSizeWeights:n,totalSizeLoading:o,modelStats:Object.values(y0)}}reset(){for(let t of Object.keys(this.models))this.models[t]=null}async load(t){var o,s,A,a,i,c,d,y,l,f,x,u,m,g,P,v,p,b,j,k,N,B,q,W,Z,J,R;M.initial&&this.reset(),t&&(this.instance=t);let n={};n.blazeface=this.instance.config.face.enabled&&!this.models.blazeface?I1(this.instance.config):null,n.antispoof=this.instance.config.face.enabled&&((o=this.instance.config.face.antispoof)==null?void 0:o.enabled)&&!this.models.antispoof?o3(this.instance.config):null,n.liveness=this.instance.config.face.enabled&&((s=this.instance.config.face.liveness)==null?void 0:s.enabled)&&!this.models.liveness?a3(this.instance.config):null,n.faceres=this.instance.config.face.enabled&&((A=this.instance.config.face.description)==null?void 0:A.enabled)&&!this.models.faceres?_1(this.instance.config):null,n.emotion=this.instance.config.face.enabled&&((a=this.instance.config.face.emotion)==null?void 0:a.enabled)&&!this.models.emotion?Y1(this.instance.config):null,n.iris=this.instance.config.face.enabled&&((i=this.instance.config.face.iris)==null?void 0:i.enabled)&&!((c=this.instance.config.face.attention)!=null&&c.enabled)&&!this.models.iris?D1(this.instance.config):null,n.facemesh=this.instance.config.face.enabled&&((d=this.instance.config.face.mesh)==null?void 0:d.enabled)&&!this.models.facemesh?V1(this.instance.config):null,n.gear=this.instance.config.face.enabled&&((y=this.instance.config.face.gear)==null?void 0:y.enabled)&&!this.models.gear?d3(this.instance.config):null,n.ssrnetage=this.instance.config.face.enabled&&((l=this.instance.config.face.ssrnet)==null?void 0:l.enabled)&&!this.models.ssrnetage?m3(this.instance.config):null,n.ssrnetgender=this.instance.config.face.enabled&&((f=this.instance.config.face.ssrnet)==null?void 0:f.enabled)&&!this.models.ssrnetgender?b3(this.instance.config):null,n.mobilefacenet=this.instance.config.face.enabled&&((x=this.instance.config.face.mobilefacenet)==null?void 0:x.enabled)&&!this.models.mobilefacenet?M3(this.instance.config):null,n.insightface=this.instance.config.face.enabled&&((u=this.instance.config.face.insightface)==null?void 0:u.enabled)&&!this.models.insightface?z3(this.instance.config):null,n.blazepose=this.instance.config.body.enabled&&!this.models.blazepose&&((m=this.instance.config.body.modelPath)==null?void 0:m.includes("blazepose"))?f1(this.instance.config):null,n.blazeposedetect=this.instance.config.body.enabled&&!this.models.blazeposedetect&&this.instance.config.body.detector&&this.instance.config.body.detector.modelPath?y1(this.instance.config):null,n.efficientpose=this.instance.config.body.enabled&&!this.models.efficientpose&&((g=this.instance.config.body.modelPath)==null?void 0:g.includes("efficientpose"))?g1(this.instance.config):null,n.movenet=this.instance.config.body.enabled&&!this.models.movenet&&((P=this.instance.config.body.modelPath)==null?void 0:P.includes("movenet"))?Tn(this.instance.config):null,n.posenet=this.instance.config.body.enabled&&!this.models.posenet&&((v=this.instance.config.body.modelPath)==null?void 0:v.includes("posenet"))?In(this.instance.config):null,n.handtrack=this.instance.config.hand.enabled&&!this.models.handtrack&&((b=(p=this.instance.config.hand.detector)==null?void 0:p.modelPath)==null?void 0:b.includes("handtrack"))?cn(this.instance.config):null,n.handskeleton=this.instance.config.hand.enabled&&this.instance.config.hand.landmarks&&!this.models.handskeleton&&((k=(j=this.instance.config.hand.detector)==null?void 0:j.modelPath)==null?void 0:k.includes("handtrack"))?dn(this.instance.config):null,(B=(N=this.instance.config.hand.detector)==null?void 0:N.modelPath)!=null&&B.includes("handdetect")&&([n.handpose,n.handskeleton]=this.models.handpose?[null,null]:await rn(this.instance.config)),n.centernet=this.instance.config.object.enabled&&!this.models.centernet&&((q=this.instance.config.object.modelPath)==null?void 0:q.includes("centernet"))?u1(this.instance.config):null,n.nanodet=this.instance.config.object.enabled&&!this.models.nanodet&&((W=this.instance.config.object.modelPath)==null?void 0:W.includes("nanodet"))?Mn(this.instance.config):null,n.selfie=this.instance.config.segmentation.enabled&&!this.models.selfie&&((Z=this.instance.config.segmentation.modelPath)==null?void 0:Z.includes("selfie"))?O5(this.instance.config):null,n.meet=this.instance.config.segmentation.enabled&&!this.models.meet&&((J=this.instance.config.segmentation.modelPath)==null?void 0:J.includes("meet"))?b5(this.instance.config):null,n.rvm=this.instance.config.segmentation.enabled&&!this.models.rvm&&((R=this.instance.config.segmentation.modelPath)==null?void 0:R.includes("rvm"))?L5(this.instance.config):null;for(let[D,U]of Object.entries(n))U!=null&&U.then&&U.then(H=>this.models[D]=H);await Promise.all(Object.values(n))}list(){let t=Object.keys(this.models).map(n=>{var o;return{name:n,loaded:this.models[n]!==null,size:0,url:this.models[n]?(o=this.models[n])==null?void 0:o.modelUrl:null}});for(let n of t){let o=Object.keys(y0).find(s=>s.startsWith(n.name));!o||(n.size=y0[o].sizeLoadedWeights,n.url=y0[o].url)}return t}loaded(){return this.list().filter(o=>o.loaded).map(o=>o.name)}validate(){let t=[];for(let n of Object.keys(this.models)){let o=this.models[n];if(!o)continue;let s=tt(this.instance,o,n);s&&t.push(s)}return t}};function Hn(e,t,n,o,s){var i,c,d,y,l,f;let A=0,a=[];for(let x of e){let u={id:A++,face:x,body:null,hands:{left:null,right:null},gestures:[],box:[0,0,0,0]};for(let b of t)x.box[0]>b.box[0]&&x.box[0]b.box[1]&&x.box[1]+x.box[3]u.body.box[0]&&b.box[0]+b.box[2]u.body.box[1]&&b.box[1]+b.box[3]u.body.box[0]&&b.box[1]+b.box[3]>u.body.box[1]&&b.box[1]+b.box[3]{b&&b.length===4&&(m.push(b[0],b[0]+b[2]),g.push(b[1],b[1]+b[3]))};P(u.face.box),P((y=u.body)==null?void 0:y.box),P((l=u.hands.left)==null?void 0:l.box),P((f=u.hands.right)==null?void 0:f.box);let v=Math.min(...m),p=Math.min(...g);u.box=[v,p,Math.max(...m)-v,Math.max(...g)-p],(s==null?void 0:s[1])&&(s==null?void 0:s[2])&&(u.boxRaw=[u.box[0]/s[2],u.box[1]/s[1],u.box[2]/s[2],u.box[3]/s[1]]),a.push(u)}return a}var nt=` /9j/4AAQSkZJRgABAQEAYABgAAD/4QBoRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUA AAABAAAARgEoAAMAAAABAAIAAAExAAIAAAARAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQu bmV0IDQuMi4xMwAA/9sAQwAGBAUGBQQGBgUGBwcGCAoQCgoJCQoUDg8MEBcUGBgXFBYWGh0lHxob @@ -14030,8 +269,7 @@ PQ4GJ+ashuK0MhWaoWcA0AaOmASMK7jRNPWYBmHyiuepO2x10qfcv6vYxCzYqoGK4HVYVTJrmb5l c6oaM5TUJ8EgGsG4kLNUHT0M64OaqMMikSRsuKbnFMRLG3zVehOaGNE445NNlnVFpDMu6uie9Vo1 8z5mOAOST2pDK91cNN+5tsrH3PrW54a06KxT7fdrlh/q1Pc+tJ6IUdZGvHPLezMcnBOWbsPap5r3 ylFtbdT1xUWNWzU0/Zbwlgfmx8zGsHWtRHmMqE59aAMyNifvHPc1f0gtPdqkY5JosJHeNci2tktY -euPnNY+oXWZEVJNrZ9aun8SIq/CzodHuriIokhDIR1ronbKZr0o6o8ipoz//2Q==`; -var body3 = ` +euPnNY+oXWZEVJNrZ9aun8SIq/CzodHuriIokhDIR1ronbKZr0o6o8ipoz//2Q==`,ot=` /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAsICAoIBwsKCQoNDAsNERwSEQ8PESIZGhQcKSQrKigk JyctMkA3LTA9MCcnOEw5PUNFSElIKzZPVU5GVEBHSEX/2wBDAQwNDREPESESEiFFLicuRUVFRUVF RUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUX/wAARCASwBLADASIA @@ -14599,563 +837,4 @@ AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp+bfwab+vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2 SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ -2Q==`; - -// src/warmup.ts -async function warmupBitmap(instance) { - const b64toBlob = (base64, type = "application/octet-stream") => fetch(`data:${type};base64,${base64}`).then((res2) => res2.blob()); - let blob; - let res; - switch (instance.config.warmup) { - case "face": - blob = await b64toBlob(face3); - break; - case "body": - case "full": - blob = await b64toBlob(body3); - break; - default: - blob = null; - } - if (blob) { - const bitmap = await createImageBitmap(blob); - res = await instance.detect(bitmap, instance.config); - bitmap.close(); - } - return res; -} -async function warmupCanvas(instance) { - return new Promise((resolve) => { - let src; - switch (instance.config.warmup) { - case "face": - src = "data:image/jpeg;base64," + face3; - break; - case "full": - case "body": - src = "data:image/jpeg;base64," + body3; - break; - default: - src = ""; - } - let img; - if (typeof Image !== "undefined") - img = new Image(); - else if (env.Image) - img = new env.Image(); - else { - resolve(void 0); - return; - } - img.onload = async () => { - const canvas3 = canvas(img.naturalWidth, img.naturalHeight); - if (!canvas3) { - log("Warmup: Canvas not found"); - resolve(void 0); - } else { - const ctx = canvas3.getContext("2d"); - if (ctx) - ctx.drawImage(img, 0, 0); - const tensor6 = await instance.image(canvas3, true); - const res = tensor6.tensor ? await instance.detect(tensor6.tensor, instance.config) : void 0; - resolve(res); - } - }; - if (src) - img.src = src; - else - resolve(void 0); - }); -} -async function warmupNode(instance) { - const atob = (str) => Buffer.from(str, "base64"); - let img; - if (instance.config.warmup === "face") - img = atob(face3); - else - img = atob(body3); - let res; - if ("node" in tfjs_esm_exports && tfjs_esm_exports.getBackend() === "tensorflow") { - const data = tfjs_esm_exports["node"].decodeJpeg(img); - const expanded = tfjs_esm_exports.expandDims(data, 0); - instance.tf.dispose(data); - res = await instance.detect(expanded, instance.config); - instance.tf.dispose(expanded); - } else { - if (instance.config.debug) - log("Warmup tfjs-node not loaded"); - } - return res; -} -async function runInference(instance) { - let res; - if (typeof createImageBitmap === "function") - res = await warmupBitmap(instance); - else if (typeof Image !== "undefined" || env.Canvas !== void 0) - res = await warmupCanvas(instance); - else - res = await warmupNode(instance); - return res; -} -async function runCompile(instance) { - var _a, _b, _c, _d; - if (!tfjs_esm_exports.env().flagRegistry.ENGINE_COMPILE_ONLY) - return; - const backendType = tfjs_esm_exports.getBackend(); - const webGLBackend = tfjs_esm_exports.backend(); - if (backendType !== "webgl" && backendType !== "humangl" || !(webGLBackend == null ? void 0 : webGLBackend["checkCompileCompletion"])) { - return; - } - tfjs_esm_exports.env().set("ENGINE_COMPILE_ONLY", true); - const numTensorsStart = tfjs_esm_exports.engine().state.numTensors; - const compiledModels = []; - for (const [modelName, model23] of Object.entries(instance.models.models)) { - if (!model23) - continue; - const shape = (model23 == null ? void 0 : model23.modelSignature) && ((_b = (_a = model23 == null ? void 0 : model23.inputs) == null ? void 0 : _a[0]) == null ? void 0 : _b.shape) ? [...model23.inputs[0].shape] : [1, 64, 64, 3]; - const dtype = (model23 == null ? void 0 : model23.modelSignature) && ((_d = (_c = model23 == null ? void 0 : model23.inputs) == null ? void 0 : _c[0]) == null ? void 0 : _d.dtype) ? model23.inputs[0].dtype : "float32"; - for (let dim = 0; dim < shape.length; dim++) { - if (shape[dim] === -1) - shape[dim] = dim === 0 ? 1 : 64; - } - const tensor6 = tfjs_esm_exports.zeros(shape, dtype); - try { - const res = model23.execute(tensor6); - compiledModels.push(modelName); - if (Array.isArray(res)) - res.forEach((t2) => tfjs_esm_exports.dispose(t2)); - else - tfjs_esm_exports.dispose(res); - } catch (e) { - if (instance.config.debug) - log("compile fail model:", modelName); - } - tfjs_esm_exports.dispose(tensor6); - } - const kernels = await webGLBackend["checkCompileCompletionAsync"](); - webGLBackend["getUniformLocations"](); - if (instance.config.debug) - log("compile pass:", { models: compiledModels, kernels: kernels.length }); - tfjs_esm_exports.env().set("ENGINE_COMPILE_ONLY", false); - const numTensorsEnd = tfjs_esm_exports.engine().state.numTensors; - if (numTensorsEnd - numTensorsStart > 0) - log("tensor leak:", numTensorsEnd - numTensorsStart); -} -async function warmup(instance, userConfig) { - await check(instance, false); - const t0 = now(); - instance.state = "warmup"; - if (userConfig) - instance.config = mergeDeep(instance.config, userConfig); - if (!instance.config.warmup || instance.config.warmup.length === 0 || instance.config.warmup === "none") { - return empty(); - } - return new Promise(async (resolve) => { - await instance.models.load(); - await runCompile(instance); - const res = await runInference(instance); - const t1 = now(); - if (instance.config.debug) - log("warmup", instance.config.warmup, Math.round(t1 - t0), "ms"); - instance.emit("warmup"); - resolve(res); - }); -} - -// src/human.ts -var _numTensors, _analyzeMemoryLeaks, _checkSanity, _sanity, _loops; -var Human = class { - constructor(userConfig) { - __publicField(this, "version"); - __publicField(this, "config"); - __publicField(this, "result"); - __publicField(this, "state"); - __publicField(this, "process"); - __publicField(this, "tf"); - __publicField(this, "env", env); - __publicField(this, "draw", draw_exports); - __publicField(this, "match", match_exports); - __publicField(this, "models"); - __publicField(this, "events"); - __publicField(this, "faceTriangulation"); - __publicField(this, "faceUVMap"); - __publicField(this, "performance"); - __privateAdd(this, _numTensors, void 0); - __privateAdd(this, _analyzeMemoryLeaks, void 0); - __privateAdd(this, _checkSanity, void 0); - __publicField(this, "analyze", (...msg) => { - if (!__privateGet(this, _analyzeMemoryLeaks)) - return; - const currentTensors = this.tf.engine().state.numTensors; - const previousTensors = __privateGet(this, _numTensors); - __privateSet(this, _numTensors, currentTensors); - const leaked = currentTensors - previousTensors; - if (leaked !== 0) - log(...msg, leaked); - }); - __privateAdd(this, _sanity, (input) => { - if (!__privateGet(this, _checkSanity)) - return null; - if (!input) - return "input is not defined"; - if (this.env.node && !(input instanceof tfjs_esm_exports.Tensor)) - return "input must be a tensor"; - try { - this.tf.getBackend(); - } catch (e) { - return "backend not loaded"; - } - return null; - }); - __publicField(this, "webcam", new WebCam()); - __publicField(this, "emit", (event) => { - var _a; - if ((_a = this.events) == null ? void 0 : _a.dispatchEvent) - this.events.dispatchEvent(new Event(event)); - }); - __privateAdd(this, _loops, {}); - const tfVersion = (version7.tfjs || tfjs_esm_exports.version_core).replace(/-(.*)/, ""); - config.wasmPath = `https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${tfVersion}/dist/`; - config.modelBasePath = env.browser ? "../models/" : "file://models/"; - this.version = version8; - Object.defineProperty(this, "version", { value: version8 }); - this.config = JSON.parse(JSON.stringify(config)); - Object.seal(this.config); - this.config.cacheModels = typeof indexedDB !== "undefined"; - if (userConfig) - this.config = mergeDeep(this.config, userConfig); - setModelLoadOptions(this.config); - this.tf = tfjs_esm_exports; - this.state = "idle"; - __privateSet(this, _numTensors, 0); - __privateSet(this, _analyzeMemoryLeaks, false); - __privateSet(this, _checkSanity, false); - this.performance = {}; - this.events = typeof EventTarget !== "undefined" ? new EventTarget() : void 0; - this.models = new Models(this); - init2(); - this.result = empty(); - this.process = { tensor: null, canvas: null }; - this.faceTriangulation = triangulation; - this.faceUVMap = uvmap; - validateModel(this, null, ""); - this.emit("create"); - if (this.config.debug || this.env.browser) - log(`version: ${this.version}`); - if (this.config.debug) - log(`tfjs version: ${this.tf.version["tfjs-core"]}`); - const envTemp = JSON.parse(JSON.stringify(this.env)); - delete envTemp.kernels; - delete envTemp.initial; - delete envTemp.perfadd; - if (this.config.debug) - log("environment:", envTemp); - } - reset() { - const currentBackend = this.config.backend; - this.config = JSON.parse(JSON.stringify(config)); - this.config.backend = currentBackend; - reset(); - env.initial = true; - } - validate(userConfig) { - const msgs = validate(config, userConfig || this.config); - if (msgs.length === 0) - this.config = mergeDeep(this.config, userConfig); - return msgs; - } - now() { - return now(); - } - image(input, getTensor = false) { - return process2(input, this.config, getTensor); - } - async segmentation(input, userConfig) { - var _a, _b, _c; - if (userConfig) - this.config = mergeDeep(this.config, userConfig); - if (!this.config.segmentation.enabled) - return null; - const processed = await process2(input, this.config); - if (!processed.tensor) - return null; - let tensor6 = null; - if ((_a = this.config.segmentation.modelPath) == null ? void 0 : _a.includes("rvm")) - tensor6 = await predict20(processed.tensor, this.config); - if ((_b = this.config.segmentation.modelPath) == null ? void 0 : _b.includes("meet")) - tensor6 = await predict16(processed.tensor, this.config); - if ((_c = this.config.segmentation.modelPath) == null ? void 0 : _c.includes("selfie")) - tensor6 = await predict21(processed.tensor, this.config); - tfjs_esm_exports.dispose(processed.tensor); - return tensor6; - } - compare(firstImageTensor, secondImageTensor) { - return compare(this.config, firstImageTensor, secondImageTensor); - } - async init() { - await check(this, true); - await this.tf.ready(); - reset(); - } - async load(userConfig) { - this.state = "load"; - const timeStamp = now(); - const count2 = Object.values(this.models.models).filter((model23) => model23).length; - if (userConfig) - this.config = mergeDeep(this.config, userConfig); - if (this.env.initial) { - if (!await check(this, false)) - log("error: backend check failed"); - await tfjs_esm_exports.ready(); - if (this.env.browser) { - if (this.config.debug) - log("configuration:", this.config); - if (this.config.debug) - log("tf flags:", this.tf.ENV.flags); - } - } - await this.models.load(this); - if (this.env.initial && this.config.debug) - log("tf engine state:", this.tf.engine().state.numBytes, "bytes", this.tf.engine().state.numTensors, "tensors"); - this.env.initial = false; - const loaded = Object.values(this.models.models).filter((model23) => model23).length; - if (loaded !== count2) { - this.models.validate(); - this.emit("load"); - } - const current = Math.trunc(now() - timeStamp); - if (current > (this.performance.loadModels || 0)) - this.performance.loadModels = this.env.perfadd ? (this.performance.loadModels || 0) + current : current; - } - next(result = this.result) { - return calc2(result, this.config); - } - async warmup(userConfig) { - const t0 = now(); - const res = await warmup(this, userConfig); - const t1 = now(); - this.performance.warmup = Math.trunc(t1 - t0); - return res; - } - async profile(input, userConfig) { - const profile = await this.tf.profile(() => this.detect(input, userConfig)); - const kernels = {}; - let total = 0; - for (const kernel of profile.kernels) { - const ms = Number(kernel.kernelTimeMs) || 0; - if (kernels[kernel.name]) - kernels[kernel.name] += ms; - else - kernels[kernel.name] = ms; - total += ms; - } - const kernelArr = []; - Object.entries(kernels).forEach((key) => kernelArr.push({ kernel: key[0], time: key[1], perc: 0 })); - for (const kernel of kernelArr) { - kernel.perc = Math.round(1e3 * kernel.time / total) / 1e3; - kernel.time = Math.round(1e3 * kernel.time) / 1e3; - } - kernelArr.sort((a, b) => b.time - a.time); - kernelArr.length = 20; - return kernelArr; - } - async detect(input, userConfig) { - this.state = "detect"; - return new Promise(async (resolve) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u; - this.state = "config"; - let timeStamp; - this.config = mergeDeep(this.config, userConfig); - this.state = "check"; - const error = __privateGet(this, _sanity).call(this, input); - if (error) { - log(error, input); - this.emit("error"); - resolve(empty(error)); - } - const timeStart = now(); - await this.load(); - timeStamp = now(); - this.state = "image"; - const img = await process2(input, this.config); - this.process = img; - this.performance.inputProcess = this.env.perfadd ? (this.performance.inputProcess || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - this.analyze("Get Image:"); - if (!img.tensor) { - if (this.config.debug) - log("could not convert input to tensor"); - this.emit("error"); - resolve(empty("could not convert input to tensor")); - return; - } - this.emit("image"); - timeStamp = now(); - this.config.skipAllowed = await skip(this.config, img.tensor); - this.config.filter.autoBrightness = (this.config.filter.autoBrightness || false) && this.config.skipAllowed; - if (!this.performance.totalFrames) - this.performance.totalFrames = 0; - if (!this.performance.cachedFrames) - this.performance.cachedFrames = 0; - this.performance.totalFrames++; - if (this.config.skipAllowed) - this.performance.cachedFrames++; - this.performance.cacheCheck = this.env.perfadd ? (this.performance.cacheCheck || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - this.analyze("Check Changed:"); - let faceRes = []; - let bodyRes = []; - let handRes = []; - let objectRes = []; - this.state = "detect:face"; - if (this.config.async) { - faceRes = this.config.face.enabled ? detectFace(this, img.tensor) : []; - if (this.performance.face) - delete this.performance.face; - } else { - timeStamp = now(); - faceRes = this.config.face.enabled ? await detectFace(this, img.tensor) : []; - this.performance.face = this.env.perfadd ? (this.performance.face || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - if (this.config.async && (this.config.body.maxDetected === -1 || this.config.hand.maxDetected === -1)) - faceRes = await faceRes; - this.analyze("Start Body:"); - this.state = "detect:body"; - const bodyConfig = this.config.body.maxDetected === -1 ? mergeDeep(this.config, { body: { maxDetected: this.config.face.enabled ? 1 * faceRes.length : 1 } }) : this.config; - if (this.config.async) { - if ((_a = this.config.body.modelPath) == null ? void 0 : _a.includes("posenet")) - bodyRes = this.config.body.enabled ? predict19(img.tensor, bodyConfig) : []; - else if ((_b = this.config.body.modelPath) == null ? void 0 : _b.includes("blazepose")) - bodyRes = this.config.body.enabled ? predict(img.tensor, bodyConfig) : []; - else if ((_c = this.config.body.modelPath) == null ? void 0 : _c.includes("efficientpose")) - bodyRes = this.config.body.enabled ? predict3(img.tensor, bodyConfig) : []; - else if ((_d = this.config.body.modelPath) == null ? void 0 : _d.includes("movenet")) - bodyRes = this.config.body.enabled ? predict17(img.tensor, bodyConfig) : []; - if (this.performance.body) - delete this.performance.body; - } else { - timeStamp = now(); - if ((_e = this.config.body.modelPath) == null ? void 0 : _e.includes("posenet")) - bodyRes = this.config.body.enabled ? await predict19(img.tensor, bodyConfig) : []; - else if ((_f = this.config.body.modelPath) == null ? void 0 : _f.includes("blazepose")) - bodyRes = this.config.body.enabled ? await predict(img.tensor, bodyConfig) : []; - else if ((_g = this.config.body.modelPath) == null ? void 0 : _g.includes("efficientpose")) - bodyRes = this.config.body.enabled ? await predict3(img.tensor, bodyConfig) : []; - else if ((_h = this.config.body.modelPath) == null ? void 0 : _h.includes("movenet")) - bodyRes = this.config.body.enabled ? await predict17(img.tensor, bodyConfig) : []; - this.performance.body = this.env.perfadd ? (this.performance.body || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - this.analyze("End Body:"); - this.analyze("Start Hand:"); - this.state = "detect:hand"; - const handConfig = this.config.hand.maxDetected === -1 ? mergeDeep(this.config, { hand: { maxDetected: this.config.face.enabled ? 2 * faceRes.length : 1 } }) : this.config; - if (this.config.async) { - if ((_j = (_i = this.config.hand.detector) == null ? void 0 : _i.modelPath) == null ? void 0 : _j.includes("handdetect")) - handRes = this.config.hand.enabled ? predict14(img.tensor, handConfig) : []; - else if ((_l = (_k = this.config.hand.detector) == null ? void 0 : _k.modelPath) == null ? void 0 : _l.includes("handtrack")) - handRes = this.config.hand.enabled ? predict15(img.tensor, handConfig) : []; - if (this.performance.hand) - delete this.performance.hand; - } else { - timeStamp = now(); - if ((_n = (_m = this.config.hand.detector) == null ? void 0 : _m.modelPath) == null ? void 0 : _n.includes("handdetect")) - handRes = this.config.hand.enabled ? await predict14(img.tensor, handConfig) : []; - else if ((_p = (_o = this.config.hand.detector) == null ? void 0 : _o.modelPath) == null ? void 0 : _p.includes("handtrack")) - handRes = this.config.hand.enabled ? await predict15(img.tensor, handConfig) : []; - this.performance.hand = this.env.perfadd ? (this.performance.hand || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - this.analyze("End Hand:"); - this.analyze("Start Object:"); - this.state = "detect:object"; - if (this.config.async) { - if ((_q = this.config.object.modelPath) == null ? void 0 : _q.includes("nanodet")) - objectRes = this.config.object.enabled ? predict18(img.tensor, this.config) : []; - else if ((_r = this.config.object.modelPath) == null ? void 0 : _r.includes("centernet")) - objectRes = this.config.object.enabled ? predict2(img.tensor, this.config) : []; - if (this.performance.object) - delete this.performance.object; - } else { - timeStamp = now(); - if ((_s = this.config.object.modelPath) == null ? void 0 : _s.includes("nanodet")) - objectRes = this.config.object.enabled ? await predict18(img.tensor, this.config) : []; - else if ((_t = this.config.object.modelPath) == null ? void 0 : _t.includes("centernet")) - objectRes = this.config.object.enabled ? await predict2(img.tensor, this.config) : []; - this.performance.object = this.env.perfadd ? (this.performance.object || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - this.analyze("End Object:"); - this.state = "detect:await"; - if (this.config.async) - [faceRes, bodyRes, handRes, objectRes] = await Promise.all([faceRes, bodyRes, handRes, objectRes]); - this.state = "detect:gesture"; - let gestureRes = []; - if (this.config.gesture.enabled) { - timeStamp = now(); - gestureRes = [...face2(faceRes), ...body2(bodyRes), ...hand2(handRes), ...iris2(faceRes)]; - if (!this.config.async) - this.performance.gesture = this.env.perfadd ? (this.performance.gesture || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - else if (this.performance.gesture) - delete this.performance.gesture; - } - this.performance.total = this.env.perfadd ? (this.performance.total || 0) + Math.trunc(now() - timeStart) : Math.trunc(now() - timeStart); - const shape = ((_u = this.process.tensor) == null ? void 0 : _u.shape) || [0, 0, 0, 0]; - this.result = { - face: faceRes, - body: bodyRes, - hand: handRes, - gesture: gestureRes, - object: objectRes, - performance: this.performance, - canvas: this.process.canvas, - timestamp: Date.now(), - error: null, - width: shape[2], - height: shape[1], - get persons() { - return join2(faceRes, bodyRes, handRes, gestureRes, shape); - } - }; - tfjs_esm_exports.dispose(img.tensor); - this.emit("detect"); - this.state = "idle"; - resolve(this.result); - }); - } - async sleep(ms) { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); - } - async video(element, run = true, delay = 0) { - if (run) { - if (!__privateGet(this, _loops)[element.id]) { - if (this.config.debug) - log("video start", element.id); - __privateGet(this, _loops)[element.id] = true; - } - if (!element.paused && __privateGet(this, _loops)[element.id] && element.readyState >= 2) - await this.detect(element); - if (delay > 0) - await this.sleep(delay); - if (__privateGet(this, _loops)[element.id]) - requestAnimationFrame(() => this.video(element, run, delay)); - } else { - if (this.config.debug) - log("video stop", element.id); - __privateGet(this, _loops)[element.id] = false; - } - } -}; -_numTensors = new WeakMap(); -_analyzeMemoryLeaks = new WeakMap(); -_checkSanity = new WeakMap(); -_sanity = new WeakMap(); -_loops = new WeakMap(); -export { - Env, - Human, - Human as default, - config as defaults, - draw_exports as draw, - empty, - env, - match_exports as match, - models_exports2 as models -}; +2Q==`;async function aA(e){let t=(s,A="application/octet-stream")=>fetch(`data:${A};base64,${s}`).then(a=>a.blob()),n,o;switch(e.config.warmup){case"face":n=await t(nt);break;case"body":case"full":n=await t(ot);break;default:n=null}if(n){let s=await createImageBitmap(n);o=await e.detect(s,e.config),s.close()}return o}async function iA(e){return new Promise(t=>{let n;switch(e.config.warmup){case"face":n="data:image/jpeg;base64,"+nt;break;case"full":case"body":n="data:image/jpeg;base64,"+ot;break;default:n=""}let o;if(typeof Image!="undefined")o=new Image;else if(M.Image)o=new M.Image;else{t(void 0);return}o.onload=async()=>{let s=L0(o.naturalWidth,o.naturalHeight);if(!s)h("Warmup: Canvas not found"),t(void 0);else{let A=s.getContext("2d");A&&A.drawImage(o,0,0);let a=await e.image(s,!0),i=a.tensor?await e.detect(a.tensor,e.config):void 0;t(i)}},n?o.src=n:t(void 0)})}async function lA(e){let t=s=>Buffer.from(s,"base64"),n;e.config.warmup==="face"?n=t(nt):n=t(ot);let o;if("node"in r&&r.getBackend()==="tensorflow"){let s=r.node.decodeJpeg(n),A=r.expandDims(s,0);e.tf.dispose(s),o=await e.detect(A,e.config),e.tf.dispose(A)}else e.config.debug&&h("Warmup tfjs-node not loaded");return o}async function cA(e){let t;return typeof createImageBitmap=="function"?t=await aA(e):typeof Image!="undefined"||M.Canvas!==void 0?t=await iA(e):t=await lA(e),t}async function dA(e){var i,c,d,y;if(!r.env().flagRegistry.ENGINE_COMPILE_ONLY)return;let t=r.getBackend(),n=r.backend();if(t!=="webgl"&&t!=="humangl"||!(n!=null&&n.checkCompileCompletion))return;r.env().set("ENGINE_COMPILE_ONLY",!0);let o=r.engine().state.numTensors,s=[];for(let[l,f]of Object.entries(e.models.models)){if(!f)continue;let x=(f==null?void 0:f.modelSignature)&&((c=(i=f==null?void 0:f.inputs)==null?void 0:i[0])==null?void 0:c.shape)?[...f.inputs[0].shape]:[1,64,64,3],u=(f==null?void 0:f.modelSignature)&&((y=(d=f==null?void 0:f.inputs)==null?void 0:d[0])==null?void 0:y.dtype)?f.inputs[0].dtype:"float32";for(let g=0;gr.dispose(P)):r.dispose(g)}catch(g){e.config.debug&&h("compile fail model:",l)}r.dispose(m)}let A=await n.checkCompileCompletionAsync();n.getUniformLocations(),e.config.debug&&h("compile pass:",{models:s,kernels:A.length}),r.env().set("ENGINE_COMPILE_ONLY",!1);let a=r.engine().state.numTensors;a-o>0&&h("tensor leak:",a-o)}async function Gn(e,t){await $e(e,!1);let n=T();return e.state="warmup",t&&(e.config=Q(e.config,t)),!e.config.warmup||e.config.warmup.length===0||e.config.warmup==="none"?ee():new Promise(async o=>{await e.models.load(),await dA(e);let s=await cA(e),A=T();e.config.debug&&h("warmup",e.config.warmup,Math.round(A-n),"ms"),e.emit("warmup"),o(s)})}var Ue,i2,l2,rt,he,Vn=class{constructor(t){E(this,"version");E(this,"config");E(this,"result");E(this,"state");E(this,"process");E(this,"tf");E(this,"env",M);E(this,"draw",bt);E(this,"match",T5);E(this,"models");E(this,"events");E(this,"faceTriangulation");E(this,"faceUVMap");E(this,"performance");Z0(this,Ue,void 0);Z0(this,i2,void 0);Z0(this,l2,void 0);E(this,"analyze",(...t)=>{if(!v0(this,i2))return;let n=this.tf.engine().state.numTensors,o=v0(this,Ue);Y0(this,Ue,n);let s=n-o;s!==0&&h(...t,s)});Z0(this,rt,t=>{if(!v0(this,l2))return null;if(!t)return"input is not defined";if(this.env.node&&!(t instanceof r.Tensor))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});E(this,"webcam",new p2);E(this,"emit",t=>{var n;(n=this.events)!=null&&n.dispatchEvent&&this.events.dispatchEvent(new Event(t))});Z0(this,he,{});let n=(Ke.tfjs||r.version_core).replace(/-(.*)/,"");Le.wasmPath=`https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${n}/dist/`,Le.modelBasePath=M.browser?"../models/":"file://models/",this.version=dt,Object.defineProperty(this,"version",{value:dt}),this.config=JSON.parse(JSON.stringify(Le)),Object.seal(this.config),this.config.cacheModels=typeof indexedDB!="undefined",t&&(this.config=Q(this.config,t)),_5(this.config),this.tf=r,this.state="idle",Y0(this,Ue,0),Y0(this,i2,!1),Y0(this,l2,!1),this.performance={},this.events=typeof EventTarget!="undefined"?new EventTarget:void 0,this.models=new a2(this),ht(),this.result=ee(),this.process={tensor:null,canvas:null},this.faceTriangulation=Z1,this.faceUVMap=X1,tt(this,null,""),this.emit("create"),(this.config.debug||this.env.browser)&&h(`version: ${this.version}`),this.config.debug&&h(`tfjs version: ${this.tf.version["tfjs-core"]}`);let o=JSON.parse(JSON.stringify(this.env));delete o.kernels,delete o.initial,delete o.perfadd,this.config.debug&&h("environment:",o)}reset(){let t=this.config.backend;this.config=JSON.parse(JSON.stringify(Le)),this.config.backend=t,lt(),M.initial=!0}validate(t){let n=At(Le,t||this.config);return n.length===0&&(this.config=Q(this.config,t)),n}now(){return T()}image(t,n=!1){return y2(t,this.config,n)}async segmentation(t,n){var A,a,i;if(n&&(this.config=Q(this.config,n)),!this.config.segmentation.enabled)return null;let o=await y2(t,this.config);if(!o.tensor)return null;let s=null;return(A=this.config.segmentation.modelPath)!=null&&A.includes("rvm")&&(s=await Cn(o.tensor,this.config)),(a=this.config.segmentation.modelPath)!=null&&a.includes("meet")&&(s=await fn(o.tensor,this.config)),(i=this.config.segmentation.modelPath)!=null&&i.includes("selfie")&&(s=await Dn(o.tensor,this.config)),r.dispose(o.tensor),s}compare(t,n){return Q5(this.config,t,n)}async init(){await $e(this,!0),await this.tf.ready(),lt()}async load(t){this.state="load";let n=T(),o=Object.values(this.models.models).filter(a=>a).length;t&&(this.config=Q(this.config,t)),this.env.initial&&(await $e(this,!1)||h("error: backend check failed"),await r.ready(),this.env.browser&&(this.config.debug&&h("configuration:",this.config),this.config.debug&&h("tf flags:",this.tf.ENV.flags))),await this.models.load(this),this.env.initial&&this.config.debug&&h("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),this.env.initial=!1,Object.values(this.models.models).filter(a=>a).length!==o&&(this.models.validate(),this.emit("load"));let A=Math.trunc(T()-n);A>(this.performance.loadModels||0)&&(this.performance.loadModels=this.env.perfadd?(this.performance.loadModels||0)+A:A)}next(t=this.result){return yn(t,this.config)}async warmup(t){let n=T(),o=await Gn(this,t),s=T();return this.performance.warmup=Math.trunc(s-n),o}async profile(t,n){let o=await this.tf.profile(()=>this.detect(t,n)),s={},A=0;for(let i of o.kernels){let c=Number(i.kernelTimeMs)||0;s[i.name]?s[i.name]+=c:s[i.name]=c,A+=c}let a=[];Object.entries(s).forEach(i=>a.push({kernel:i[0],time:i[1],perc:0}));for(let i of a)i.perc=Math.round(1e3*i.time/A)/1e3,i.time=Math.round(1e3*i.time)/1e3;return a.sort((i,c)=>c.time-i.time),a.length=20,a}async detect(t,n){return this.state="detect",new Promise(async o=>{var g,P,v,p,b,j,k,N,B,q,W,Z,J,R,D,U,H,a0,o0,C,F;this.state="config";let s;this.config=Q(this.config,n),this.state="check";let A=v0(this,rt).call(this,t);A&&(h(A,t),this.emit("error"),o(ee(A)));let a=T();await this.load(),s=T(),this.state="image";let i=await y2(t,this.config);if(this.process=i,this.performance.inputProcess=this.env.perfadd?(this.performance.inputProcess||0)+Math.trunc(T()-s):Math.trunc(T()-s),this.analyze("Get Image:"),!i.tensor){this.config.debug&&h("could not convert input to tensor"),this.emit("error"),o(ee("could not convert input to tensor"));return}this.emit("image"),s=T(),this.config.skipAllowed=await J5(this.config,i.tensor),this.config.filter.autoBrightness=(this.config.filter.autoBrightness||!1)&&this.config.skipAllowed,this.performance.totalFrames||(this.performance.totalFrames=0),this.performance.cachedFrames||(this.performance.cachedFrames=0),this.performance.totalFrames++,this.config.skipAllowed&&this.performance.cachedFrames++,this.performance.cacheCheck=this.env.perfadd?(this.performance.cacheCheck||0)+Math.trunc(T()-s):Math.trunc(T()-s),this.analyze("Check Changed:");let c=[],d=[],y=[],l=[];this.state="detect:face",this.config.async?(c=this.config.face.enabled?A5(this,i.tensor):[],this.performance.face&&delete this.performance.face):(s=T(),c=this.config.face.enabled?await A5(this,i.tensor):[],this.performance.face=this.env.perfadd?(this.performance.face||0)+Math.trunc(T()-s):Math.trunc(T()-s)),this.config.async&&(this.config.body.maxDetected===-1||this.config.hand.maxDetected===-1)&&(c=await c),this.analyze("Start Body:"),this.state="detect:body";let f=this.config.body.maxDetected===-1?Q(this.config,{body:{maxDetected:this.config.face.enabled?1*c.length:1}}):this.config;this.config.async?((g=this.config.body.modelPath)!=null&&g.includes("posenet")?d=this.config.body.enabled?j5(i.tensor,f):[]:(P=this.config.body.modelPath)!=null&&P.includes("blazepose")?d=this.config.body.enabled?Mt(i.tensor,f):[]:(v=this.config.body.modelPath)!=null&&v.includes("efficientpose")?d=this.config.body.enabled?jt(i.tensor,f):[]:(p=this.config.body.modelPath)!=null&&p.includes("movenet")&&(d=this.config.body.enabled?M5(i.tensor,f):[]),this.performance.body&&delete this.performance.body):(s=T(),(b=this.config.body.modelPath)!=null&&b.includes("posenet")?d=this.config.body.enabled?await j5(i.tensor,f):[]:(j=this.config.body.modelPath)!=null&&j.includes("blazepose")?d=this.config.body.enabled?await Mt(i.tensor,f):[]:(k=this.config.body.modelPath)!=null&&k.includes("efficientpose")?d=this.config.body.enabled?await jt(i.tensor,f):[]:(N=this.config.body.modelPath)!=null&&N.includes("movenet")&&(d=this.config.body.enabled?await M5(i.tensor,f):[]),this.performance.body=this.env.perfadd?(this.performance.body||0)+Math.trunc(T()-s):Math.trunc(T()-s)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.state="detect:hand";let x=this.config.hand.maxDetected===-1?Q(this.config,{hand:{maxDetected:this.config.face.enabled?2*c.length:1}}):this.config;this.config.async?((q=(B=this.config.hand.detector)==null?void 0:B.modelPath)!=null&&q.includes("handdetect")?y=this.config.hand.enabled?d5(i.tensor,x):[]:(Z=(W=this.config.hand.detector)==null?void 0:W.modelPath)!=null&&Z.includes("handtrack")&&(y=this.config.hand.enabled?f5(i.tensor,x):[]),this.performance.hand&&delete this.performance.hand):(s=T(),(R=(J=this.config.hand.detector)==null?void 0:J.modelPath)!=null&&R.includes("handdetect")?y=this.config.hand.enabled?await d5(i.tensor,x):[]:(U=(D=this.config.hand.detector)==null?void 0:D.modelPath)!=null&&U.includes("handtrack")&&(y=this.config.hand.enabled?await f5(i.tensor,x):[]),this.performance.hand=this.env.perfadd?(this.performance.hand||0)+Math.trunc(T()-s):Math.trunc(T()-s)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.state="detect:object",this.config.async?((H=this.config.object.modelPath)!=null&&H.includes("nanodet")?l=this.config.object.enabled?k5(i.tensor,this.config):[]:(a0=this.config.object.modelPath)!=null&&a0.includes("centernet")&&(l=this.config.object.enabled?wt(i.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(s=T(),(o0=this.config.object.modelPath)!=null&&o0.includes("nanodet")?l=this.config.object.enabled?await k5(i.tensor,this.config):[]:(C=this.config.object.modelPath)!=null&&C.includes("centernet")&&(l=this.config.object.enabled?await wt(i.tensor,this.config):[]),this.performance.object=this.env.perfadd?(this.performance.object||0)+Math.trunc(T()-s):Math.trunc(T()-s)),this.analyze("End Object:"),this.state="detect:await",this.config.async&&([c,d,y,l]=await Promise.all([c,d,y,l])),this.state="detect:gesture";let u=[];this.config.gesture.enabled&&(s=T(),u=[...G3(c),...H3(d),...Z3(y),...V3(c)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=this.env.perfadd?(this.performance.gesture||0)+Math.trunc(T()-s):Math.trunc(T()-s)),this.performance.total=this.env.perfadd?(this.performance.total||0)+Math.trunc(T()-a):Math.trunc(T()-a);let m=((F=this.process.tensor)==null?void 0:F.shape)||[0,0,0,0];this.result={face:c,body:d,hand:y,gesture:u,object:l,performance:this.performance,canvas:this.process.canvas,timestamp:Date.now(),error:null,width:m[2],height:m[1],get persons(){return Hn(c,d,y,u,m)}},r.dispose(i.tensor),this.emit("detect"),this.state="idle",o(this.result)})}async sleep(t){return new Promise(n=>{setTimeout(n,t)})}async video(t,n=!0,o=0){n?(v0(this,he)[t.id]||(this.config.debug&&h("video start",t.id),v0(this,he)[t.id]=!0),!t.paused&&v0(this,he)[t.id]&&t.readyState>=2&&await this.detect(t),o>0&&await this.sleep(o),v0(this,he)[t.id]&&requestAnimationFrame(()=>this.video(t,n,o))):(this.config.debug&&h("video stop",t.id),v0(this,he)[t.id]=!1)}};Ue=new WeakMap,i2=new WeakMap,l2=new WeakMap,rt=new WeakMap,he=new WeakMap;export{m2 as Env,Vn as Human,Vn as default,Le as defaults,bt as draw,ee as empty,M as env,T5 as match,Bn as models}; diff --git a/dist/human.node-gpu.js b/dist/human.node-gpu.js index e129a722..9ff47bce 100644 --- a/dist/human.node-gpu.js +++ b/dist/human.node-gpu.js @@ -4,316 +4,7 @@ author: ' */ -"use strict"; -var __create = Object.create; -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __getProtoOf = Object.getPrototypeOf; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; -var __commonJS = (cb, mod3) => function __require() { - return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports; -}; -var __export = (target, all2) => { - for (var name in all2) - __defProp(target, name, { get: all2[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toESM = (mod3, isNodeMode, target) => (target = mod3 != null ? __create(__getProtoOf(mod3)) : {}, __copyProps( - isNodeMode || !mod3 || !mod3.__esModule ? __defProp(target, "default", { value: mod3, enumerable: true }) : target, - mod3 -)); -var __toCommonJS = (mod3) => __copyProps(__defProp({}, "__esModule", { value: true }), mod3); -var __publicField = (obj, key, value) => { - __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); - return value; -}; -var __accessCheck = (obj, member, msg) => { - if (!member.has(obj)) - throw TypeError("Cannot " + msg); -}; -var __privateGet = (obj, member, getter) => { - __accessCheck(obj, member, "read from private field"); - return getter ? getter.call(obj) : member.get(obj); -}; -var __privateAdd = (obj, member, value) => { - if (member.has(obj)) - throw TypeError("Cannot add the same private member more than once"); - member instanceof WeakSet ? member.add(obj) : member.set(obj, value); -}; -var __privateSet = (obj, member, value, setter) => { - __accessCheck(obj, member, "write to private field"); - setter ? setter.call(obj, value) : member.set(obj, value); - return value; -}; - -// dist/tfjs.esm.js -var require_tfjs_esm = __commonJS({ - "dist/tfjs.esm.js"(exports, module2) { - "use strict"; - var __defProp2 = Object.defineProperty; - var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; - var __getOwnPropNames2 = Object.getOwnPropertyNames; - var __hasOwnProp2 = Object.prototype.hasOwnProperty; - var __export2 = (target, all2) => { - for (var name in all2) - __defProp2(target, name, { get: all2[name], enumerable: true }); - }; - var __copyProps2 = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames2(from)) - if (!__hasOwnProp2.call(to, key) && key !== except) - __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); - } - return to; - }; - var __reExport = (target, mod3, secondTarget) => (__copyProps2(target, mod3, "default"), secondTarget && __copyProps2(secondTarget, mod3, "default")); - var __toCommonJS2 = (mod3) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod3); - var tf_node_gpu_exports = {}; - __export2(tf_node_gpu_exports, { - version: () => version7 - }); - module2.exports = __toCommonJS2(tf_node_gpu_exports); - __reExport(tf_node_gpu_exports, require("@tensorflow/tfjs-node-gpu"), module2.exports); - var version4 = "4.2.0"; - var version22 = "4.2.0"; - var version32 = "4.2.0"; - var version42 = "4.2.0"; - var version5 = "4.2.0"; - var version6 = "0.0.1-alpha.17"; - var version7 = { - tfjs: version4, - "tfjs-core": version4, - "tfjs-converter": version22, - "tfjs-backend-cpu": version32, - "tfjs-backend-webgl": version42, - "tfjs-backend-wasm": version5, - "tfjs-backend-webgpu": version6 - }; - } -}); - -// src/human.ts -var human_exports = {}; -__export(human_exports, { - Env: () => Env, - Human: () => Human, - default: () => Human, - defaults: () => config, - draw: () => draw_exports, - empty: () => empty, - env: () => env, - match: () => match_exports, - models: () => models_exports2 -}); -module.exports = __toCommonJS(human_exports); -var tf38 = __toESM(require_tfjs_esm()); - -// src/util/util.ts -function log(...msg) { - const dt = new Date(); - const ts = `${dt.getHours().toString().padStart(2, "0")}:${dt.getMinutes().toString().padStart(2, "0")}:${dt.getSeconds().toString().padStart(2, "0")}.${dt.getMilliseconds().toString().padStart(3, "0")}`; - if (msg) - console.log(ts, "Human:", ...msg); -} -function join(folder, file) { - const separator = folder.endsWith("/") ? "" : "/"; - const skipJoin = file.startsWith(".") || file.startsWith("/") || file.startsWith("http:") || file.startsWith("https:") || file.startsWith("file:"); - const path = skipJoin ? `${file}` : `${folder}${separator}${file}`; - if (!path.toLocaleLowerCase().includes(".json")) - throw new Error(`modelpath error: expecting json file: ${path}`); - return path; -} -var now = () => { - if (typeof performance !== "undefined") - return performance.now(); - return parseInt((Number(process.hrtime.bigint()) / 1e3 / 1e3).toString()); -}; -function validate(defaults, config3, parent = "config", msgs = []) { - for (const key of Object.keys(config3)) { - if (typeof config3[key] === "object") { - validate(defaults[key], config3[key], key, msgs); - } else { - const defined = defaults && typeof defaults[key] !== "undefined"; - if (!defined) - msgs.push({ reason: "unknown property", where: `${parent}.${key} = ${config3[key]}` }); - const same = defaults && typeof defaults[key] === typeof config3[key]; - if (defined && !same) - msgs.push({ reason: "property type mismatch", where: `${parent}.${key} = ${config3[key]}`, expected: typeof defaults[key] }); - } - } - if (config3.debug && parent === "config" && msgs.length > 0) - log("invalid configuration", msgs); - return msgs; -} -function mergeDeep(...objects) { - const isObject = (obj) => obj && typeof obj === "object"; - return objects.reduce((prev, obj) => { - Object.keys(obj || {}).forEach((key) => { - const pVal = prev[key]; - const oVal = obj[key]; - if (Array.isArray(pVal) && Array.isArray(oVal)) - prev[key] = pVal.concat(...oVal); - else if (isObject(pVal) && isObject(oVal)) - prev[key] = mergeDeep(pVal, oVal); - else - prev[key] = oVal; - }); - return prev; - }, {}); -} - -// src/config.ts -var config = { - backend: "", - modelBasePath: "", - cacheModels: true, - validateModels: true, - wasmPath: "", - wasmPlatformFetch: false, - debug: false, - async: true, - warmup: "full", - cacheSensitivity: 0.7, - skipAllowed: false, - deallocate: false, - flags: {}, - softwareKernels: false, - filter: { - enabled: true, - equalization: false, - width: 0, - height: 0, - flip: false, - return: true, - autoBrightness: true, - brightness: 0, - contrast: 0, - sharpness: 0, - blur: 0, - saturation: 0, - hue: 0, - negative: false, - sepia: false, - vintage: false, - kodachrome: false, - technicolor: false, - polaroid: false, - pixelate: 0 - }, - gesture: { - enabled: true - }, - face: { - enabled: true, - detector: { - modelPath: "blazeface.json", - rotation: false, - maxDetected: 1, - skipFrames: 99, - skipTime: 2500, - minConfidence: 0.2, - iouThreshold: 0.1, - mask: false, - return: false - }, - mesh: { - enabled: true, - modelPath: "facemesh.json", - keepInvalid: false - }, - attention: { - enabled: false, - modelPath: "facemesh-attention.json" - }, - iris: { - enabled: true, - modelPath: "iris.json" - }, - emotion: { - enabled: true, - minConfidence: 0.1, - skipFrames: 99, - skipTime: 1500, - modelPath: "emotion.json" - }, - description: { - enabled: true, - modelPath: "faceres.json", - skipFrames: 99, - skipTime: 3e3, - minConfidence: 0.1 - }, - antispoof: { - enabled: false, - skipFrames: 99, - skipTime: 4e3, - modelPath: "antispoof.json" - }, - liveness: { - enabled: false, - skipFrames: 99, - skipTime: 4e3, - modelPath: "liveness.json" - } - }, - body: { - enabled: true, - modelPath: "movenet-lightning.json", - maxDetected: -1, - minConfidence: 0.3, - skipFrames: 1, - skipTime: 200 - }, - hand: { - enabled: true, - rotation: true, - skipFrames: 99, - skipTime: 1e3, - minConfidence: 0.5, - iouThreshold: 0.2, - maxDetected: -1, - landmarks: true, - detector: { - modelPath: "handtrack.json" - }, - skeleton: { - modelPath: "handlandmark-lite.json" - } - }, - object: { - enabled: false, - modelPath: "centernet.json", - minConfidence: 0.2, - iouThreshold: 0.4, - maxDetected: 10, - skipFrames: 99, - skipTime: 2e3 - }, - segmentation: { - enabled: false, - modelPath: "rvm.json", - ratio: 0.5, - mode: "default" - } -}; - -// src/util/env.ts -var tf3 = __toESM(require_tfjs_esm()); - -// src/image/image.ts -var tf2 = __toESM(require_tfjs_esm()); - -// src/image/imagefxshaders.ts -var vertexIdentity = ` +"use strict";var No=Object.create;var k2=Object.defineProperty;var Io=Object.getOwnPropertyDescriptor;var Oo=Object.getOwnPropertyNames;var Lo=Object.getPrototypeOf,Co=Object.prototype.hasOwnProperty;var Wo=(e,t,n)=>t in e?k2(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Do=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ze=(e,t)=>{for(var n in t)k2(e,n,{get:t[n],enumerable:!0})},k1=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Oo(t))!Co.call(e,r)&&r!==n&&k2(e,r,{get:()=>t[r],enumerable:!(o=Io(t,r))||o.enumerable});return e};var Z=(e,t,n)=>(n=e!=null?No(Lo(e)):{},k1(t||!e||!e.__esModule?k2(n,"default",{value:e,enumerable:!0}):n,e)),Fo=e=>k1(k2({},"__esModule",{value:!0}),e);var k=(e,t,n)=>(Wo(e,typeof t!="symbol"?t+"":t,n),n),w1=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)};var G0=(e,t,n)=>(w1(e,t,"read from private field"),n?n.call(e):t.get(e)),me=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},ge=(e,t,n,o)=>(w1(e,t,"write to private field"),o?o.call(e,n):t.set(e,n),n);var H=Do((ya,qt)=>{"use strict";var Zt=Object.defineProperty,Bo=Object.getOwnPropertyDescriptor,Ho=Object.getOwnPropertyNames,Go=Object.prototype.hasOwnProperty,Vo=(e,t)=>{for(var n in t)Zt(e,n,{get:t[n],enumerable:!0})},Vt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ho(t))!Go.call(e,r)&&r!==n&&Zt(e,r,{get:()=>t[r],enumerable:!(o=Bo(t,r))||o.enumerable});return e},Zo=(e,t,n)=>(Vt(e,t,"default"),n&&Vt(n,t,"default")),Xo=e=>Vt(Zt({},"__esModule",{value:!0}),e),Xt={};Vo(Xt,{version:()=>Qo});qt.exports=Xo(Xt);Zo(Xt,require("@tensorflow/tfjs-node-gpu"),qt.exports);var E1="4.2.0",qo="4.2.0",Uo="4.2.0",Yo="4.2.0",Ko="4.2.0",Jo="0.0.1-alpha.17",Qo={tfjs:E1,"tfjs-core":E1,"tfjs-converter":qo,"tfjs-backend-cpu":Uo,"tfjs-backend-webgl":Yo,"tfjs-backend-wasm":Ko,"tfjs-backend-webgpu":Jo}});var da={};ze(da,{Env:()=>w2,Human:()=>v1,default:()=>v1,defaults:()=>Ye,draw:()=>et,empty:()=>he,env:()=>R,match:()=>Nt,models:()=>T1});module.exports=Fo(da);var ae=Z(H());function u(...e){let t=new Date,n=`${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}:${t.getSeconds().toString().padStart(2,"0")}.${t.getMilliseconds().toString().padStart(3,"0")}`;e&&console.log(n,"Human:",...e)}function z1(e,t){let n=e.endsWith("/")?"":"/",r=t.startsWith(".")||t.startsWith("/")||t.startsWith("http:")||t.startsWith("https:")||t.startsWith("file:")?`${t}`:`${e}${n}${t}`;if(!r.toLocaleLowerCase().includes(".json"))throw new Error(`modelpath error: expecting json file: ${r}`);return r}var g=()=>typeof performance!="undefined"?performance.now():parseInt((Number(process.hrtime.bigint())/1e3/1e3).toString());function Ut(e,t,n="config",o=[]){for(let r of Object.keys(t))if(typeof t[r]=="object")Ut(e[r],t[r],r,o);else{let s=e&&typeof e[r]!="undefined";s||o.push({reason:"unknown property",where:`${n}.${r} = ${t[r]}`});let A=e&&typeof e[r]==typeof t[r];s&&!A&&o.push({reason:"property type mismatch",where:`${n}.${r} = ${t[r]}`,expected:typeof e[r]})}return t.debug&&n==="config"&&o.length>0&&u("invalid configuration",o),o}function a0(...e){let t=n=>n&&typeof n=="object";return e.reduce((n,o)=>(Object.keys(o||{}).forEach(r=>{let s=n[r],A=o[r];Array.isArray(s)&&Array.isArray(A)?n[r]=s.concat(...A):t(s)&&t(A)?n[r]=a0(s,A):n[r]=A}),n),{})}var Ye={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,iouThreshold:.1,mask:!1,return:!1},mesh:{enabled:!0,modelPath:"facemesh.json",keepInvalid:!1},attention:{enabled:!1,modelPath:"facemesh-attention.json"},iris:{enabled:!0,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"}};var I0=Z(H());var N=Z(H());var S1=` precision highp float; attribute vec2 pos; attribute vec2 uv; @@ -323,8 +14,7 @@ var vertexIdentity = ` vUv = uv; gl_Position = vec4(pos.x, pos.y*flipY, 0.0, 1.); } -`; -var colorMatrixWithAlpha = ` +`;var j1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -336,8 +26,7 @@ var colorMatrixWithAlpha = ` 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]; } -`; -var colorMatrixWithoutAlpha = ` +`,N1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -349,8 +38,7 @@ var colorMatrixWithoutAlpha = ` gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[14]; gl_FragColor.a = c.a; } -`; -var pixelate = ` +`,I1=` precision highp float; varying vec2 vUv; uniform vec2 size; @@ -363,8 +51,7 @@ var pixelate = ` vec2 coord = pixelate(vUv, size); gl_FragColor += texture2D(texture, coord); } -`; -var blur = ` +`,O1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -387,8 +74,7 @@ var blur = ` 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; } -`; -var convolution = ` +`,L1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -410,6055 +96,20 @@ var convolution = ` c31 * m[6] + c32 * m[7] + c33 * m[8]; gl_FragColor.a = c22.a; } -`; - -// src/image/imagefx.ts -var collect = (source, prefix, collection) => { - const r = new RegExp("\\b" + prefix + " \\w+ (\\w+)", "ig"); - source.replace(r, (match2, name) => { - collection[name] = 0; - return match2; - }); -}; -var GLProgram = class { - constructor(gl, vertexSource, fragmentSource) { - __publicField(this, "uniform", {}); - __publicField(this, "attribute", {}); - __publicField(this, "gl"); - __publicField(this, "id"); - __publicField(this, "compile", (source, type) => { - const shader = this.gl.createShader(type); - if (!shader) { - log("filter: could not create shader"); - return null; - } - this.gl.shaderSource(shader, source); - this.gl.compileShader(shader); - if (!this.gl.getShaderParameter(shader, this.gl.COMPILE_STATUS)) { - log(`filter: gl compile failed: ${this.gl.getShaderInfoLog(shader) || "unknown"}`); - return null; - } - return shader; - }); - this.gl = gl; - const vertexShader = this.compile(vertexSource, this.gl.VERTEX_SHADER); - const fragmentShader = this.compile(fragmentSource, this.gl.FRAGMENT_SHADER); - this.id = this.gl.createProgram(); - if (!vertexShader || !fragmentShader) - return; - if (!this.id) { - log("filter: could not create webgl program"); - return; - } - this.gl.attachShader(this.id, vertexShader); - this.gl.attachShader(this.id, fragmentShader); - this.gl.linkProgram(this.id); - if (!this.gl.getProgramParameter(this.id, this.gl.LINK_STATUS)) { - log(`filter: gl link failed: ${this.gl.getProgramInfoLog(this.id) || "unknown"}`); - return; - } - this.gl.useProgram(this.id); - collect(vertexSource, "attribute", this.attribute); - for (const a in this.attribute) - this.attribute[a] = this.gl.getAttribLocation(this.id, a); - collect(vertexSource, "uniform", this.uniform); - collect(fragmentSource, "uniform", this.uniform); - for (const u in this.uniform) - this.uniform[u] = this.gl.getUniformLocation(this.id, u); - } -}; -function GLImageFilter() { - let drawCount = 0; - let sourceTexture = null; - let lastInChain = false; - let currentFramebufferIndex = -1; - let tempFramebuffers = [null, null]; - let filterChain = []; - let vertexBuffer = null; - let currentProgram = null; - const fxcanvas = canvas(100, 100); - const shaderProgramCache = {}; - const DRAW = { INTERMEDIATE: 1 }; - const gl = fxcanvas.getContext("webgl"); - if (!gl) { - log("filter: cannot get webgl context"); - return; - } - this.gl = gl; - function resize(width, height) { - if (width === fxcanvas.width && height === fxcanvas.height) - return; - fxcanvas.width = width; - fxcanvas.height = height; - if (!vertexBuffer) { - const vertices = 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]); - vertexBuffer = gl.createBuffer(); - gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true); - } - gl.viewport(0, 0, fxcanvas.width, fxcanvas.height); - tempFramebuffers = [null, null]; - } - function createFramebufferTexture(width, height) { - const fbo = gl.createFramebuffer(); - gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); - const renderbuffer = gl.createRenderbuffer(); - gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer); - const texture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, texture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); - gl.bindTexture(gl.TEXTURE_2D, null); - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - return { fbo, texture }; - } - function getTempFramebuffer(index2) { - tempFramebuffers[index2] = tempFramebuffers[index2] || createFramebufferTexture(fxcanvas.width, fxcanvas.height); - return tempFramebuffers[index2]; - } - function draw(flags = 0) { - if (!currentProgram) - return; - let source = null; - let target = null; - let flipY = false; - if (drawCount === 0) - source = sourceTexture; - else - source = getTempFramebuffer(currentFramebufferIndex).texture || null; - drawCount++; - if (lastInChain && !(flags & DRAW.INTERMEDIATE)) { - target = null; - flipY = drawCount % 2 === 0; - } else { - currentFramebufferIndex = (currentFramebufferIndex + 1) % 2; - target = getTempFramebuffer(currentFramebufferIndex).fbo || null; - } - gl.bindTexture(gl.TEXTURE_2D, source); - gl.bindFramebuffer(gl.FRAMEBUFFER, target); - gl.uniform1f(currentProgram.uniform["flipY"], flipY ? -1 : 1); - gl.drawArrays(gl.TRIANGLES, 0, 6); - } - function compileShader(fragmentSource) { - if (shaderProgramCache[fragmentSource]) { - currentProgram = shaderProgramCache[fragmentSource]; - gl.useProgram((currentProgram ? currentProgram.id : null) || null); - return currentProgram; - } - currentProgram = new GLProgram(gl, vertexIdentity, fragmentSource); - if (!currentProgram) { - log("filter: could not get webgl program"); - return null; - } - const floatSize = Float32Array.BYTES_PER_ELEMENT; - const vertSize = 4 * floatSize; - gl.enableVertexAttribArray(currentProgram.attribute["pos"]); - gl.vertexAttribPointer(currentProgram.attribute["pos"], 2, gl.FLOAT, false, vertSize, 0 * floatSize); - gl.enableVertexAttribArray(currentProgram.attribute["uv"]); - gl.vertexAttribPointer(currentProgram.attribute["uv"], 2, gl.FLOAT, false, vertSize, 2 * floatSize); - shaderProgramCache[fragmentSource] = currentProgram; - return currentProgram; - } - const filter = { - colorMatrix: (matrix) => { - const m = new Float32Array(matrix); - m[4] /= 255; - m[9] /= 255; - m[14] /= 255; - m[19] /= 255; - const shader = m[18] === 1 && m[3] === 0 && m[8] === 0 && m[13] === 0 && m[15] === 0 && m[16] === 0 && m[17] === 0 && m[19] === 0 ? colorMatrixWithoutAlpha : colorMatrixWithAlpha; - const program = compileShader(shader); - if (!program) - return; - gl.uniform1fv(program.uniform["m"], m); - draw(); - }, - brightness: (brightness) => { - const b = (brightness || 0) + 1; - filter.colorMatrix([ - b, - 0, - 0, - 0, - 0, - 0, - b, - 0, - 0, - 0, - 0, - 0, - b, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - saturation: (amount) => { - const x = (amount || 0) * 2 / 3 + 1; - const y = (x - 1) * -0.5; - filter.colorMatrix([ - x, - y, - y, - 0, - 0, - y, - x, - y, - 0, - 0, - y, - y, - x, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - desaturate: () => { - filter.saturation(-1); - }, - contrast: (amount) => { - const v = (amount || 0) + 1; - const o = -128 * (v - 1); - filter.colorMatrix([ - v, - 0, - 0, - 0, - o, - 0, - v, - 0, - 0, - o, - 0, - 0, - v, - 0, - o, - 0, - 0, - 0, - 1, - 0 - ]); - }, - negative: () => { - filter.contrast(-2); - }, - hue: (rotation) => { - rotation = (rotation || 0) / 180 * Math.PI; - const cos = Math.cos(rotation); - const sin = Math.sin(rotation); - const lumR = 0.213; - const lumG = 0.715; - const lumB = 0.072; - filter.colorMatrix([ - lumR + cos * (1 - lumR) + sin * -lumR, - lumG + cos * -lumG + sin * -lumG, - lumB + cos * -lumB + sin * (1 - lumB), - 0, - 0, - lumR + cos * -lumR + sin * 0.143, - lumG + cos * (1 - lumG) + sin * 0.14, - lumB + cos * -lumB + sin * -0.283, - 0, - 0, - lumR + cos * -lumR + sin * -(1 - lumR), - lumG + cos * -lumG + sin * lumG, - lumB + cos * (1 - lumB) + sin * lumB, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - desaturateLuminance: () => { - filter.colorMatrix([ - 0.2764723, - 0.929708, - 0.0938197, - 0, - -37.1, - 0.2764723, - 0.929708, - 0.0938197, - 0, - -37.1, - 0.2764723, - 0.929708, - 0.0938197, - 0, - -37.1, - 0, - 0, - 0, - 1, - 0 - ]); - }, - sepia: () => { - filter.colorMatrix([ - 0.393, - 0.7689999, - 0.18899999, - 0, - 0, - 0.349, - 0.6859999, - 0.16799999, - 0, - 0, - 0.272, - 0.5339999, - 0.13099999, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - brownie: () => { - filter.colorMatrix([ - 0.5997023498159715, - 0.34553243048391263, - -0.2708298674538042, - 0, - 47.43192855600873, - -0.037703249837783157, - 0.8609577587992641, - 0.15059552388459913, - 0, - -36.96841498319127, - 0.24113635128153335, - -0.07441037908422492, - 0.44972182064877153, - 0, - -7.562075277591283, - 0, - 0, - 0, - 1, - 0 - ]); - }, - vintagePinhole: () => { - filter.colorMatrix([ - 0.6279345635605994, - 0.3202183420819367, - -0.03965408211312453, - 0, - 9.651285835294123, - 0.02578397704808868, - 0.6441188644374771, - 0.03259127616149294, - 0, - 7.462829176470591, - 0.0466055556782719, - -0.0851232987247891, - 0.5241648018700465, - 0, - 5.159190588235296, - 0, - 0, - 0, - 1, - 0 - ]); - }, - kodachrome: () => { - filter.colorMatrix([ - 1.1285582396593525, - -0.3967382283601348, - -0.03992559172921793, - 0, - 63.72958762196502, - -0.16404339962244616, - 1.0835251566291304, - -0.05498805115633132, - 0, - 24.732407896706203, - -0.16786010706155763, - -0.5603416277695248, - 1.6014850761964943, - 0, - 35.62982807460946, - 0, - 0, - 0, - 1, - 0 - ]); - }, - technicolor: () => { - filter.colorMatrix([ - 1.9125277891456083, - -0.8545344976951645, - -0.09155508482755585, - 0, - 11.793603434377337, - -0.3087833385928097, - 1.7658908555458428, - -0.10601743074722245, - 0, - -70.35205161461398, - -0.231103377548616, - -0.7501899197440212, - 1.847597816108189, - 0, - 30.950940869491138, - 0, - 0, - 0, - 1, - 0 - ]); - }, - polaroid: () => { - filter.colorMatrix([ - 1.438, - -0.062, - -0.062, - 0, - 0, - -0.122, - 1.378, - -0.122, - 0, - 0, - -0.016, - -0.016, - 1.483, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - shiftToBGR: () => { - filter.colorMatrix([ - 0, - 0, - 1, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - convolution: (matrix) => { - const m = new Float32Array(matrix); - const pixelSizeX = 1 / fxcanvas.width; - const pixelSizeY = 1 / fxcanvas.height; - const program = compileShader(convolution); - if (!program) - return; - gl.uniform1fv(program.uniform["m"], m); - gl.uniform2f(program.uniform["px"], pixelSizeX, pixelSizeY); - draw(); - }, - detectEdges: () => { - filter.convolution.call(this, [ - 0, - 1, - 0, - 1, - -4, - 1, - 0, - 1, - 0 - ]); - }, - sobelX: () => { - filter.convolution.call(this, [ - -1, - 0, - 1, - -2, - 0, - 2, - -1, - 0, - 1 - ]); - }, - sobelY: () => { - filter.convolution.call(this, [ - -1, - -2, - -1, - 0, - 0, - 0, - 1, - 2, - 1 - ]); - }, - sharpen: (amount) => { - const a = amount || 1; - filter.convolution.call(this, [ - 0, - -1 * a, - 0, - -1 * a, - 1 + 4 * a, - -1 * a, - 0, - -1 * a, - 0 - ]); - }, - emboss: (size2) => { - const s = size2 || 1; - filter.convolution.call(this, [ - -2 * s, - -1 * s, - 0, - -1 * s, - 1, - 1 * s, - 0, - 1 * s, - 2 * s - ]); - }, - blur: (size2) => { - const blurSizeX = size2 / 7 / fxcanvas.width; - const blurSizeY = size2 / 7 / fxcanvas.height; - const program = compileShader(blur); - if (!program) - return; - gl.uniform2f(program.uniform["px"], 0, blurSizeY); - draw(DRAW.INTERMEDIATE); - gl.uniform2f(program.uniform["px"], blurSizeX, 0); - draw(); - }, - pixelate: (size2) => { - const blurSizeX = size2 / fxcanvas.width; - const blurSizeY = size2 / fxcanvas.height; - const program = compileShader(pixelate); - if (!program) - return; - gl.uniform2f(program.uniform["size"], blurSizeX, blurSizeY); - draw(); - } - }; - this.add = function(name) { - const args = Array.prototype.slice.call(arguments, 1); - const func = filter[name]; - filterChain.push({ func, args }); - }; - this.reset = function() { - filterChain = []; - }; - this.get = function() { - return filterChain; - }; - this.apply = function(image28) { - resize(image28.width, image28.height); - drawCount = 0; - if (!sourceTexture) - sourceTexture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, sourceTexture); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image28); - for (let i = 0; i < filterChain.length; i++) { - lastInChain = i === filterChain.length - 1; - const f = filterChain[i]; - f.func.apply(this, f.args || []); - } - return fxcanvas; - }; - this.draw = function(image28) { - this.add("brightness", 0); - return this.apply(image28); - }; -} - -// src/image/enhance.ts -var tf = __toESM(require_tfjs_esm()); -async function histogramEqualization(inputImage) { - const squeeze14 = inputImage.shape.length === 4 ? tf.squeeze(inputImage) : inputImage; - const rgb2 = tf.split(squeeze14, 3, 2); - const min2 = [tf.min(rgb2[0]), tf.min(rgb2[1]), tf.min(rgb2[2])]; - const max5 = [tf.max(rgb2[0]), tf.max(rgb2[1]), tf.max(rgb2[2])]; - const absMax = await Promise.all(max5.map((channel) => channel.data())); - const maxValue = Math.max(absMax[0][0], absMax[1][0], absMax[2][0]); - const maxRange = maxValue > 1 ? 255 : 1; - const factor = maxRange / maxValue; - let final; - if (factor > 1) { - const sub11 = [tf.sub(rgb2[0], min2[0]), tf.sub(rgb2[1], min2[1]), tf.sub(rgb2[2], min2[2])]; - const range = [tf.sub(max5[0], min2[0]), tf.sub(max5[1], min2[1]), tf.sub(max5[2], min2[2])]; - const enh = [tf.mul(sub11[0], factor), tf.mul(sub11[1], factor), tf.mul(sub11[2], factor)]; - const stack5 = tf.stack([enh[0], enh[1], enh[2]], 2); - final = tf.reshape(stack5, [1, squeeze14.shape[0] || 0, squeeze14.shape[1] || 0, 3]); - tf.dispose([...sub11, ...range, ...enh]); - } else { - final = tf.expandDims(squeeze14, 0); - } - tf.dispose([...rgb2, ...min2, ...max5, rgb2, squeeze14, inputImage]); - return final; -} - -// src/image/image.ts -var maxSize = 3840; -var inCanvas = null; -var outCanvas = null; -var tmpCanvas = null; -var fx; -var last = { - inputSum: 0, - cacheDiff: 1, - sumMethod: 0, - inputTensor: void 0 -}; -function reset() { - last.inputSum = 0; - last.cacheDiff = 1; - last.sumMethod = 0; - last.inputTensor = void 0; -} -function canvas(width, height) { - let c; - if (env.browser) { - if (env.worker) { - if (typeof OffscreenCanvas === "undefined") - throw new Error("canvas error: attempted to run in web worker but OffscreenCanvas is not supported"); - c = new OffscreenCanvas(width, height); - } else { - if (typeof document === "undefined") - throw new Error("canvas error: attempted to run in browser but DOM is not defined"); - c = document.createElement("canvas"); - c.width = width; - c.height = height; - } - } else { - if (typeof env.Canvas !== "undefined") - c = new env.Canvas(width, height); - else if (typeof globalThis.Canvas !== "undefined") - c = new globalThis.Canvas(width, height); - } - return c; -} -function copy(input, output) { - const outputCanvas = output || canvas(input.width, input.height); - const ctx = outputCanvas.getContext("2d"); - ctx.drawImage(input, 0, 0); - return outputCanvas; -} -async function process2(input, config3, getTensor = true) { - var _a, _b, _c; - if (!input) { - if (config3.debug) - log("input error: input is missing"); - return { tensor: null, canvas: null }; - } - if (!(input instanceof tf2.Tensor) && !(typeof Image !== "undefined" && input instanceof Image) && !(typeof globalThis.Canvas !== "undefined" && input instanceof globalThis.Canvas) && !(typeof ImageData !== "undefined" && input instanceof ImageData) && !(typeof ImageBitmap !== "undefined" && input instanceof ImageBitmap) && !(typeof HTMLImageElement !== "undefined" && input instanceof HTMLImageElement) && !(typeof HTMLMediaElement !== "undefined" && input instanceof HTMLMediaElement) && !(typeof HTMLVideoElement !== "undefined" && input instanceof HTMLVideoElement) && !(typeof HTMLCanvasElement !== "undefined" && input instanceof HTMLCanvasElement) && !(typeof OffscreenCanvas !== "undefined" && input instanceof OffscreenCanvas)) { - throw new Error("input error: type not recognized"); - } - if (input instanceof tf2.Tensor) { - let tensor7 = null; - if (input["isDisposedInternal"]) - throw new Error("input error: attempted to use tensor but it is disposed"); - if (!input.shape) - throw new Error("input error: attempted to use tensor without a shape"); - if (input.shape.length === 3) { - if (input.shape[2] === 3) { - tensor7 = tf2.expandDims(input, 0); - } else if (input.shape[2] === 4) { - const rgb2 = tf2.slice3d(input, [0, 0, 0], [-1, -1, 3]); - tensor7 = tf2.expandDims(rgb2, 0); - tf2.dispose(rgb2); - } - } else if (input.shape.length === 4) { - if (input.shape[3] === 3) { - tensor7 = tf2.clone(input); - } else if (input.shape[3] === 4) { - tensor7 = tf2.slice4d(input, [0, 0, 0, 0], [-1, -1, -1, 3]); - } - } - if (tensor7 == null || tensor7.shape.length !== 4 || tensor7.shape[0] !== 1 || tensor7.shape[3] !== 3) - throw new Error(`input error: attempted to use tensor with unrecognized shape: ${input.shape.toString()}`); - if (tensor7.dtype === "int32") { - const cast8 = tf2.cast(tensor7, "float32"); - tf2.dispose(tensor7); - tensor7 = cast8; - } - return { tensor: tensor7, canvas: config3.filter.return ? outCanvas : null }; - } - if (typeof input["readyState"] !== "undefined" && input.readyState <= 2) { - if (config3.debug) - log("input stream is not ready"); - return { tensor: null, canvas: inCanvas }; - } - const originalWidth = input["naturalWidth"] || input["videoWidth"] || input["width"] || input["shape"] && input["shape"][1] > 0; - const originalHeight = input["naturalHeight"] || input["videoHeight"] || input["height"] || input["shape"] && input["shape"][2] > 0; - if (!originalWidth || !originalHeight) { - if (config3.debug) - log("cannot determine input dimensions"); - return { tensor: null, canvas: inCanvas }; - } - let targetWidth = originalWidth; - let targetHeight = originalHeight; - if (targetWidth > maxSize) { - targetWidth = maxSize; - targetHeight = Math.trunc(targetWidth * originalHeight / originalWidth); - } - if (targetHeight > maxSize) { - targetHeight = maxSize; - targetWidth = Math.trunc(targetHeight * originalWidth / originalHeight); - } - if ((((_a = config3.filter) == null ? void 0 : _a.width) || 0) > 0) - targetWidth = config3.filter.width; - else if ((((_b = config3.filter) == null ? void 0 : _b.height) || 0) > 0) - targetWidth = originalWidth * ((config3.filter.height || 0) / originalHeight); - if ((config3.filter.height || 0) > 0) - targetHeight = config3.filter.height; - else if ((config3.filter.width || 0) > 0) - targetHeight = originalHeight * ((config3.filter.width || 0) / originalWidth); - if (!targetWidth || !targetHeight) - throw new Error("input error: cannot determine dimension"); - if (!inCanvas || inCanvas.width !== targetWidth || inCanvas.height !== targetHeight) - inCanvas = canvas(targetWidth, targetHeight); - const inCtx = inCanvas.getContext("2d"); - if (typeof ImageData !== "undefined" && input instanceof ImageData) { - inCtx.putImageData(input, 0, 0); - } else { - if (config3.filter.flip && typeof inCtx.translate !== "undefined") { - inCtx.translate(originalWidth, 0); - inCtx.scale(-1, 1); - inCtx.drawImage(input, 0, 0, originalWidth, originalHeight, 0, 0, inCanvas.width, inCanvas.height); - inCtx.setTransform(1, 0, 0, 1, 0, 0); - } else { - inCtx.drawImage(input, 0, 0, originalWidth, originalHeight, 0, 0, inCanvas.width, inCanvas.height); - } - } - if (!outCanvas || inCanvas.width !== outCanvas.width || inCanvas.height !== outCanvas.height) - outCanvas = canvas(inCanvas.width, inCanvas.height); - if (config3.filter.enabled && env.webgl.supported) { - if (!fx) - fx = env.browser ? new GLImageFilter() : null; - env.filter = !!fx; - if (!(fx == null ? void 0 : fx.add)) { - if (config3.debug) - log("input process error: cannot initialize filters"); - env.webgl.supported = false; - config3.filter.enabled = false; - copy(inCanvas, outCanvas); - } else { - fx.reset(); - if (config3.filter.brightness !== 0) - fx.add("brightness", config3.filter.brightness); - if (config3.filter.contrast !== 0) - fx.add("contrast", config3.filter.contrast); - if (config3.filter.sharpness !== 0) - fx.add("sharpen", config3.filter.sharpness); - if (config3.filter.blur !== 0) - fx.add("blur", config3.filter.blur); - if (config3.filter.saturation !== 0) - fx.add("saturation", config3.filter.saturation); - if (config3.filter.hue !== 0) - fx.add("hue", config3.filter.hue); - if (config3.filter.negative) - fx.add("negative"); - if (config3.filter.sepia) - fx.add("sepia"); - if (config3.filter.vintage) - fx.add("brownie"); - if (config3.filter.sepia) - fx.add("sepia"); - if (config3.filter.kodachrome) - fx.add("kodachrome"); - if (config3.filter.technicolor) - fx.add("technicolor"); - if (config3.filter.polaroid) - fx.add("polaroid"); - if (config3.filter.pixelate !== 0) - fx.add("pixelate", config3.filter.pixelate); - if (((_c = fx.get()) == null ? void 0 : _c.length) > 1) - outCanvas = fx.apply(inCanvas); - else - outCanvas = fx.draw(inCanvas); - } - } else { - copy(inCanvas, outCanvas); - if (fx) - fx = null; - env.filter = !!fx; - } - if (!getTensor) - return { tensor: null, canvas: outCanvas }; - if (!outCanvas) - throw new Error("canvas error: cannot create output"); - let pixels; - let depth = 3; - if (typeof ImageData !== "undefined" && input instanceof ImageData || input.data && input.width && input.height) { - if (env.browser && tf2.browser) { - pixels = tf2.browser ? tf2.browser.fromPixels(input) : null; - } else { - depth = input.data.length / input.height / input.width; - const arr = new Uint8Array(input.data.buffer); - pixels = tf2.tensor(arr, [input.height, input.width, depth], "int32"); - } - } else { - if (!tmpCanvas || outCanvas.width !== tmpCanvas.width || outCanvas.height !== tmpCanvas.height) - tmpCanvas = canvas(outCanvas.width, outCanvas.height); - if (tf2.browser && env.browser) { - if (config3.backend === "webgl" || config3.backend === "humangl" || config3.backend === "webgpu") { - pixels = tf2.browser.fromPixels(outCanvas); - } else { - tmpCanvas = copy(outCanvas); - pixels = tf2.browser.fromPixels(tmpCanvas); - } - } else { - const tempCanvas = copy(outCanvas); - const tempCtx = tempCanvas.getContext("2d"); - const tempData = tempCtx.getImageData(0, 0, targetWidth, targetHeight); - depth = tempData.data.length / targetWidth / targetHeight; - const arr = new Uint8Array(tempData.data.buffer); - pixels = tf2.tensor(arr, [targetWidth, targetHeight, depth]); - } - } - if (depth === 4) { - const rgb2 = tf2.slice3d(pixels, [0, 0, 0], [-1, -1, 3]); - tf2.dispose(pixels); - pixels = rgb2; - } - if (!pixels) - throw new Error("input error: cannot create tensor"); - const casted = tf2.cast(pixels, "float32"); - const tensor6 = config3.filter.equalization ? await histogramEqualization(casted) : tf2.expandDims(casted, 0); - tf2.dispose([pixels, casted]); - if (config3.filter.autoBrightness) { - const max5 = tf2.max(tensor6); - const maxVal = await max5.data(); - config3.filter.brightness = maxVal[0] > 1 ? 1 - maxVal[0] / 255 : 1 - maxVal[0]; - tf2.dispose(max5); - } - return { tensor: tensor6, canvas: config3.filter.return ? outCanvas : null }; -} -async function skip(config3, input) { - let skipFrame = false; - if (config3.cacheSensitivity === 0 || !input.shape || input.shape.length !== 4 || input.shape[1] > 3840 || input.shape[2] > 2160) - return skipFrame; - if (!last.inputTensor) { - last.inputTensor = tf2.clone(input); - } else if (last.inputTensor.shape[1] !== input.shape[1] || last.inputTensor.shape[2] !== input.shape[2]) { - tf2.dispose(last.inputTensor); - last.inputTensor = tf2.clone(input); - } else { - const t2 = {}; - t2.diff = tf2.sub(input, last.inputTensor); - t2.squared = tf2.mul(t2.diff, t2.diff); - t2.sum = tf2.sum(t2.squared); - const diffSum = await t2.sum.data(); - const diffRelative = diffSum[0] / (input.shape[1] || 1) / (input.shape[2] || 1) / 255 / 3; - tf2.dispose([last.inputTensor, t2.diff, t2.squared, t2.sum]); - last.inputTensor = tf2.clone(input); - skipFrame = diffRelative <= (config3.cacheSensitivity || 0); - } - return skipFrame; -} -async function compare(config3, input1, input2) { - const t2 = {}; - if (!input1 || !input2 || input1.shape.length !== 4 || input1.shape.length !== input2.shape.length) { - if (!config3.debug) - log("invalid input tensor or tensor shapes do not match:", input1.shape, input2.shape); - return 0; - } - if (input1.shape[0] !== 1 || input2.shape[0] !== 1 || input1.shape[3] !== 3 || input2.shape[3] !== 3) { - if (!config3.debug) - log("input tensors must be of shape [1, height, width, 3]:", input1.shape, input2.shape); - return 0; - } - t2.input1 = tf2.clone(input1); - t2.input2 = input1.shape[1] !== input2.shape[1] || input1.shape[2] !== input2.shape[2] ? tf2.image.resizeBilinear(input2, [input1.shape[1], input1.shape[2]]) : tf2.clone(input2); - t2.diff = tf2.sub(t2.input1, t2.input2); - t2.squared = tf2.mul(t2.diff, t2.diff); - t2.sum = tf2.sum(t2.squared); - const diffSum = await t2.sum.data(); - const diffRelative = diffSum[0] / (input1.shape[1] || 1) / (input1.shape[2] || 1) / 255 / 3; - tf2.dispose([t2.input1, t2.input2, t2.diff, t2.squared, t2.sum]); - return diffRelative; -} - -// src/util/env.ts -var _canvas, _image, _imageData; -var Env = class { - constructor() { - __publicField(this, "browser"); - __publicField(this, "node"); - __publicField(this, "worker"); - __publicField(this, "platform", ""); - __publicField(this, "agent", ""); - __publicField(this, "backends", []); - __publicField(this, "initial"); - __publicField(this, "filter"); - __publicField(this, "tfjs"); - __publicField(this, "offscreen"); - __publicField(this, "perfadd", false); - __publicField(this, "tensorflow", { - version: void 0, - gpu: void 0 - }); - __publicField(this, "wasm", { - supported: void 0, - backend: void 0, - simd: void 0, - multithread: void 0 - }); - __publicField(this, "webgl", { - supported: void 0, - backend: void 0, - version: void 0, - renderer: void 0, - shader: void 0, - vendor: void 0 - }); - __publicField(this, "webgpu", { - supported: void 0, - backend: void 0, - adapter: void 0 - }); - __publicField(this, "cpu", { - model: void 0, - flags: [] - }); - __publicField(this, "kernels", []); - __privateAdd(this, _canvas, void 0); - __privateAdd(this, _image, void 0); - __privateAdd(this, _imageData, void 0); - this.browser = typeof navigator !== "undefined"; - this.node = typeof process !== "undefined" && typeof process.versions !== "undefined" && typeof process.versions.node !== "undefined"; - this.tfjs = { version: tf3.version["tfjs-core"] }; - this.offscreen = typeof OffscreenCanvas !== "undefined"; - this.initial = true; - this.worker = this.browser && this.offscreen ? typeof WorkerGlobalScope !== "undefined" : void 0; - if (typeof navigator !== "undefined") { - const raw = navigator.userAgent.match(/\(([^()]+)\)/g); - if (raw == null ? void 0 : raw[0]) { - const platformMatch = raw[0].match(/\(([^()]+)\)/g); - this.platform = (platformMatch == null ? void 0 : platformMatch[0]) ? platformMatch[0].replace(/\(|\)/g, "") : ""; - this.agent = navigator.userAgent.replace(raw[0], ""); - if (this.platform[1]) - this.agent = this.agent.replace(raw[1], ""); - this.agent = this.agent.replace(/ /g, " "); - } - } else if (typeof process !== "undefined") { - this.platform = `${process.platform} ${process.arch}`; - this.agent = `NodeJS ${process.version}`; - } - } - get Canvas() { - return __privateGet(this, _canvas); - } - set Canvas(val) { - __privateSet(this, _canvas, val); - globalThis.Canvas = val; - } - get Image() { - return __privateGet(this, _image); - } - set Image(val) { - __privateSet(this, _image, val); - globalThis.Image = val; - } - get ImageData() { - return __privateGet(this, _imageData); - } - set ImageData(val) { - __privateSet(this, _imageData, val); - globalThis.ImageData = val; - } - async updateBackend() { - this.backends = Object.keys(tf3.engine().registryFactory); - try { - this.tensorflow = { - version: tf3.backend()["binding"] ? tf3.backend()["binding"].TF_Version : void 0, - gpu: tf3.backend()["binding"] ? tf3.backend()["binding"].isUsingGpuDevice() : void 0 - }; - } catch (e) { - } - this.wasm.supported = typeof WebAssembly !== "undefined"; - this.wasm.backend = this.backends.includes("wasm"); - if (this.wasm.supported && this.wasm.backend) { - this.wasm.simd = await tf3.env().getAsync("WASM_HAS_SIMD_SUPPORT"); - this.wasm.multithread = await tf3.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"); - } - const c = canvas(100, 100); - const gl = c ? c.getContext("webgl2") : void 0; - this.webgl.supported = typeof gl !== "undefined"; - this.webgl.backend = this.backends.includes("webgl"); - if (this.webgl.supported && this.webgl.backend && gl) { - this.webgl.version = gl.getParameter(gl.VERSION); - this.webgl.vendor = gl.getParameter(gl.VENDOR); - this.webgl.renderer = gl.getParameter(gl.RENDERER); - this.webgl.shader = gl.getParameter(gl.SHADING_LANGUAGE_VERSION); - } - this.webgpu.supported = this.browser && typeof navigator.gpu !== "undefined"; - this.webgpu.backend = this.backends.includes("webgpu"); - try { - if (this.webgpu.supported) { - const adapter = await navigator.gpu.requestAdapter(); - this.webgpu.adapter = await (adapter == null ? void 0 : adapter.requestAdapterInfo()); - } - } catch (e) { - this.webgpu.supported = false; - } - try { - this.kernels = tf3.getKernelsForBackend(tf3.getBackend()).map((kernel) => kernel.kernelName.toLowerCase()); - } catch (e) { - } - } - updateCPU() { - const cpu = { model: "", flags: [] }; - if (this.node && this.platform.startsWith("linux")) { - } - if (!this.cpu) - Object.defineProperty(this, "cpu", { value: cpu }); - else - this.cpu = cpu; - } -}; -_canvas = new WeakMap(); -_image = new WeakMap(); -_imageData = new WeakMap(); -var env = new Env(); - -// src/util/webcam.ts -var WebCam = class { - constructor() { - __publicField(this, "config"); - __publicField(this, "element"); - __publicField(this, "stream"); - __publicField(this, "devices", []); - __publicField(this, "enumerate", async () => { - try { - const devices = await navigator.mediaDevices.enumerateDevices(); - this.devices = devices.filter((device) => device.kind === "videoinput"); - } catch (e) { - this.devices = []; - } - return this.devices; - }); - __publicField(this, "start", async (webcamConfig) => { - var _a, _b; - if (webcamConfig == null ? void 0 : webcamConfig.debug) - this.config.debug = webcamConfig == null ? void 0 : webcamConfig.debug; - if (webcamConfig == null ? void 0 : webcamConfig.crop) - this.config.crop = webcamConfig == null ? void 0 : webcamConfig.crop; - if (webcamConfig == null ? void 0 : webcamConfig.mode) - this.config.mode = webcamConfig == null ? void 0 : webcamConfig.mode; - if (webcamConfig == null ? void 0 : webcamConfig.width) - this.config.width = webcamConfig == null ? void 0 : webcamConfig.width; - if (webcamConfig == null ? void 0 : webcamConfig.height) - this.config.height = webcamConfig == null ? void 0 : webcamConfig.height; - if (webcamConfig == null ? void 0 : webcamConfig.id) - this.config.id = webcamConfig == null ? void 0 : webcamConfig.id; - if (webcamConfig == null ? void 0 : webcamConfig.element) { - if (typeof webcamConfig.element === "string") { - const el = document.getElementById(webcamConfig.element); - if (el && el instanceof HTMLVideoElement) { - this.element = el; - } else { - if (this.config.debug) - log("webcam", "cannot get dom element", webcamConfig.element); - return; - } - } else if (webcamConfig.element instanceof HTMLVideoElement) { - this.element = webcamConfig.element; - } else { - if (this.config.debug) - log("webcam", "unknown dom element", webcamConfig.element); - return; - } - } else { - this.element = document.createElement("video"); - } - const requestedConstraints = { - audio: false, - video: { - facingMode: this.config.mode === "front" ? "user" : "environment", - resizeMode: this.config.crop ? "crop-and-scale" : "none" - } - }; - if (((_a = this.config) == null ? void 0 : _a.width) > 0) - requestedConstraints.video.width = { ideal: this.config.width }; - if (((_b = this.config) == null ? void 0 : _b.height) > 0) - requestedConstraints.video.height = { ideal: this.config.height }; - if (this.config.id) - requestedConstraints.video.deviceId = this.config.id; - this.element.addEventListener("play", () => { - if (this.config.debug) - log("webcam", "play"); - }); - this.element.addEventListener("pause", () => { - if (this.config.debug) - log("webcam", "pause"); - }); - this.element.addEventListener("click", async () => { - if (!this.element || !this.stream) - return; - if (this.element.paused) - await this.element.play(); - else - this.element.pause(); - }); - if (!(navigator == null ? void 0 : navigator.mediaDevices)) { - if (this.config.debug) - log("webcam", "no devices"); - return; - } - try { - this.stream = await navigator.mediaDevices.getUserMedia(requestedConstraints); - } catch (err) { - log("webcam", err); - return; - } - if (!this.stream) { - if (this.config.debug) - log("webcam", "no stream"); - return; - } - this.element.srcObject = this.stream; - const ready3 = new Promise((resolve) => { - if (!this.element) - resolve(false); - else - this.element.onloadeddata = () => resolve(true); - }); - await ready3; - await this.element.play(); - if (this.config.debug) { - log("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 - }); - } - }); - __publicField(this, "pause", () => { - if (this.element) - this.element.pause(); - }); - __publicField(this, "play", async () => { - if (this.element) - await this.element.play(); - }); - __publicField(this, "stop", () => { - if (this.config.debug) - log("webcam", "stop"); - if (this.track) - this.track.stop(); - }); - this.config = { - element: void 0, - debug: true, - mode: "front", - crop: false, - width: 0, - height: 0 - }; - } - get track() { - if (!this.stream) - return void 0; - return this.stream.getVideoTracks()[0]; - } - get capabilities() { - if (!this.track) - return void 0; - return this.track.getCapabilities ? this.track.getCapabilities() : void 0; - } - get constraints() { - if (!this.track) - return void 0; - return this.track.getConstraints ? this.track.getConstraints() : void 0; - } - get settings() { - if (!this.stream) - return void 0; - const track = this.stream.getVideoTracks()[0]; - return track.getSettings ? track.getSettings() : void 0; - } - get label() { - if (!this.track) - return ""; - return this.track.label; - } - get paused() { - var _a; - return ((_a = this.element) == null ? void 0 : _a.paused) || false; - } - get width() { - var _a; - return ((_a = this.element) == null ? void 0 : _a.videoWidth) || 0; - } - get height() { - var _a; - return ((_a = this.element) == null ? void 0 : _a.videoHeight) || 0; - } -}; - -// src/tfjs/load.ts -var tf4 = __toESM(require_tfjs_esm()); - -// models/models.json -var models_exports = {}; -__export(models_exports, { - age: () => age, - "anti-spoofing": () => anti_spoofing, - antispoof: () => antispoof, - blazeface: () => blazeface, - "blazeface-back": () => blazeface_back, - "blazeface-front": () => blazeface_front, - "blazepose-detector": () => blazepose_detector, - "blazepose-full": () => blazepose_full, - "blazepose-heavy": () => blazepose_heavy, - "blazepose-lite": () => blazepose_lite, - centernet: () => centernet, - default: () => models_default, - efficientpose: () => efficientpose, - "efficientpose-i-lite": () => efficientpose_i_lite, - "efficientpose-ii-lite": () => efficientpose_ii_lite, - "efficientpose-iv": () => efficientpose_iv, - emotion: () => emotion, - faceboxes: () => faceboxes, - facemesh: () => facemesh, - "facemesh-attention": () => facemesh_attention, - "facemesh-attention-pinto": () => facemesh_attention_pinto, - "facemesh-detection-full": () => facemesh_detection_full, - "facemesh-detection-short": () => facemesh_detection_short, - faceres: () => faceres, - "faceres-deep": () => faceres_deep, - gear: () => gear, - gender: () => gender, - "gender-ssrnet-imdb": () => gender_ssrnet_imdb, - handdetect: () => handdetect, - "handlandmark-full": () => handlandmark_full, - "handlandmark-lite": () => handlandmark_lite, - "handlandmark-sparse": () => handlandmark_sparse, - handskeleton: () => handskeleton, - handtrack: () => handtrack, - "insightface-efficientnet-b0": () => insightface_efficientnet_b0, - "insightface-ghostnet-strides1": () => insightface_ghostnet_strides1, - "insightface-ghostnet-strides2": () => insightface_ghostnet_strides2, - "insightface-mobilenet-emore": () => insightface_mobilenet_emore, - "insightface-mobilenet-swish": () => insightface_mobilenet_swish, - iris: () => iris, - liveness: () => liveness, - meet: () => meet, - mobileface: () => mobileface, - mobilefacenet: () => mobilefacenet, - models: () => models, - "movenet-lightning": () => movenet_lightning, - "movenet-multipose": () => movenet_multipose, - "movenet-thunder": () => movenet_thunder, - nanodet: () => nanodet, - "nanodet-e": () => nanodet_e, - "nanodet-g": () => nanodet_g, - "nanodet-m": () => nanodet_m, - "nanodet-t": () => nanodet_t, - posenet: () => posenet, - rvm: () => rvm, - selfie: () => selfie -}); -var antispoof = 853098; -var blazeface = 538928; -var centernet = 4030290; -var emotion = 820516; -var facemesh = 1477958; -var faceres = 6978814; -var handlandmark_lite = 2023432; -var handtrack = 2964837; -var iris = 2599092; -var liveness = 592976; -var models = 0; -var movenet_lightning = 4650216; -var age = 161240; -var blazeface_back = 538928; -var blazeface_front = 402048; -var blazepose_detector = 5928856; -var blazepose_full = 6339202; -var blazepose_heavy = 27502466; -var blazepose_lite = 2726402; -var efficientpose = 5651240; -var faceboxes = 2013002; -var facemesh_attention_pinto = 2387598; -var facemesh_attention = 2382414; -var facemesh_detection_full = 1026192; -var facemesh_detection_short = 201268; -var faceres_deep = 13957620; -var gear = 1498916; -var gender_ssrnet_imdb = 161236; -var gender = 201808; -var handdetect = 3515612; -var handlandmark_full = 5431368; -var handlandmark_sparse = 5286322; -var handskeleton = 5502280; -var meet = 372228; -var mobileface = 2183192; -var mobilefacenet = 5171976; -var movenet_multipose = 9448838; -var movenet_thunder = 12477112; -var nanodet = 7574558; -var posenet = 5032780; -var rvm = 3739355; -var selfie = 212886; -var anti_spoofing = 853098; -var efficientpose_i_lite = 2269064; -var efficientpose_ii_lite = 5651240; -var efficientpose_iv = 25643252; -var insightface_efficientnet_b0 = 13013224; -var insightface_ghostnet_strides1 = 8093408; -var insightface_ghostnet_strides2 = 8049584; -var insightface_mobilenet_emore = 6938536; -var insightface_mobilenet_swish = 12168584; -var nanodet_e = 12319156; -var nanodet_g = 7574558; -var nanodet_m = 1887474; -var nanodet_t = 5294216; -var models_default = { - antispoof, - blazeface, - centernet, - emotion, - facemesh, - faceres, - "handlandmark-lite": handlandmark_lite, - handtrack, - iris, - liveness, - models, - "movenet-lightning": movenet_lightning, - age, - "blazeface-back": blazeface_back, - "blazeface-front": blazeface_front, - "blazepose-detector": blazepose_detector, - "blazepose-full": blazepose_full, - "blazepose-heavy": blazepose_heavy, - "blazepose-lite": blazepose_lite, - efficientpose, - faceboxes, - "facemesh-attention-pinto": facemesh_attention_pinto, - "facemesh-attention": facemesh_attention, - "facemesh-detection-full": facemesh_detection_full, - "facemesh-detection-short": facemesh_detection_short, - "faceres-deep": faceres_deep, - gear, - "gender-ssrnet-imdb": gender_ssrnet_imdb, - gender, - handdetect, - "handlandmark-full": handlandmark_full, - "handlandmark-sparse": handlandmark_sparse, - handskeleton, - meet, - mobileface, - mobilefacenet, - "movenet-multipose": movenet_multipose, - "movenet-thunder": movenet_thunder, - nanodet, - posenet, - rvm, - selfie, - "anti-spoofing": anti_spoofing, - "efficientpose-i-lite": efficientpose_i_lite, - "efficientpose-ii-lite": efficientpose_ii_lite, - "efficientpose-iv": efficientpose_iv, - "insightface-efficientnet-b0": insightface_efficientnet_b0, - "insightface-ghostnet-strides1": insightface_ghostnet_strides1, - "insightface-ghostnet-strides2": insightface_ghostnet_strides2, - "insightface-mobilenet-emore": insightface_mobilenet_emore, - "insightface-mobilenet-swish": insightface_mobilenet_swish, - "nanodet-e": nanodet_e, - "nanodet-g": nanodet_g, - "nanodet-m": nanodet_m, - "nanodet-t": nanodet_t -}; - -// src/tfjs/load.ts -var options = { - cacheModels: true, - cacheSupported: true, - verbose: true, - debug: false, - modelBasePath: "" -}; -var modelStats = {}; -async function httpHandler(url, init4) { - if (options.debug) - log("load model fetch:", url, init4); - return fetch(url, init4); -} -function setModelLoadOptions(config3) { - options.cacheModels = config3.cacheModels; - options.verbose = config3.debug; - options.modelBasePath = config3.modelBasePath; -} -async function loadModel(modelPath) { - var _a, _b, _c, _d; - let modelUrl = join(options.modelBasePath, modelPath || ""); - if (!modelUrl.toLowerCase().endsWith(".json")) - modelUrl += ".json"; - const modelPathSegments = modelUrl.includes("/") ? modelUrl.split("/") : modelUrl.split("\\"); - const shortModelName = modelPathSegments[modelPathSegments.length - 1].replace(".json", ""); - const cachedModelName = "indexeddb://" + shortModelName; - modelStats[shortModelName] = { - name: shortModelName, - sizeFromManifest: 0, - sizeLoadedWeights: 0, - sizeDesired: models_exports[shortModelName], - inCache: false, - url: "" - }; - options.cacheSupported = typeof indexedDB !== "undefined"; - let cachedModels = {}; - try { - cachedModels = options.cacheSupported && options.cacheModels ? await tf4.io.listModels() : {}; - } catch (e) { - options.cacheSupported = false; - } - modelStats[shortModelName].inCache = options.cacheSupported && options.cacheModels && Object.keys(cachedModels).includes(cachedModelName); - modelStats[shortModelName].url = modelStats[shortModelName].inCache ? cachedModelName : modelUrl; - const tfLoadOptions = typeof fetch === "undefined" ? {} : { fetchFunc: (url, init4) => httpHandler(url, init4) }; - let model23 = new tf4.GraphModel(modelStats[shortModelName].url, tfLoadOptions); - let loaded = false; - try { - model23.findIOHandler(); - if (options.debug) - log("model load handler:", model23["handler"]); - } catch (err) { - log("error finding model i/o handler:", modelUrl, err); - } - try { - const artifacts = await ((_a = model23.handler) == null ? void 0 : _a.load()) || null; - modelStats[shortModelName].sizeFromManifest = ((_b = artifacts == null ? void 0 : artifacts.weightData) == null ? void 0 : _b.byteLength) || 0; - if (artifacts) - model23.loadSync(artifacts); - else - model23 = await tf4.loadGraphModel(modelStats[shortModelName].inCache ? cachedModelName : modelUrl, tfLoadOptions); - modelStats[shortModelName].sizeLoadedWeights = ((_d = (_c = model23.artifacts) == null ? void 0 : _c.weightData) == null ? void 0 : _d.byteLength) || 0; - if (options.verbose) - log("load:", { model: shortModelName, url: model23["modelUrl"], bytes: modelStats[shortModelName].sizeLoadedWeights }); - loaded = true; - } catch (err) { - log("error loading model:", modelUrl, err); - } - if (loaded && options.cacheModels && options.cacheSupported && !modelStats[shortModelName].inCache) { - try { - const saveResult = await model23.save(cachedModelName); - if (options.debug) - log("model saved:", cachedModelName, saveResult); - } catch (err) { - log("error saving model:", modelUrl, err); - } - } - return model23; -} - -// package.json -var version2 = "3.0.2"; - -// src/tfjs/backend.ts -var tf7 = __toESM(require_tfjs_esm()); - -// src/tfjs/humangl.ts -var tf5 = __toESM(require_tfjs_esm()); -var config2 = { - name: "humangl", - priority: 999, - canvas: null, - gl: null, - extensions: [], - webGLattr: { - alpha: false, - antialias: false, - premultipliedAlpha: false, - preserveDrawingBuffer: false, - depth: false, - stencil: false, - failIfMajorPerformanceCaveat: false, - desynchronized: true - } -}; -function extensions() { - const gl = config2.gl; - if (!gl) - return; - config2.extensions = gl.getSupportedExtensions(); -} -function register(instance) { - var _a; - if (instance.config.backend !== "humangl") - return; - if (config2.name in tf5.engine().registry && !((_a = config2 == null ? void 0 : config2.gl) == null ? void 0 : _a.getParameter(config2.gl.VERSION))) { - log("humangl error: backend invalid context"); - instance.models.reset(); - } - if (!tf5.findBackend(config2.name)) { - try { - config2.canvas = canvas(100, 100); - } catch (err) { - log("humangl error: cannot create canvas:", err); - return; - } - try { - config2.gl = config2.canvas.getContext("webgl2", config2.webGLattr); - if (!config2.gl) { - log("humangl error: cannot get webgl context"); - return; - } - const glv2 = config2.gl.getParameter(config2.gl.VERSION).includes("2.0"); - if (!glv2) { - log("backend override: using fallback webgl backend as webgl 2.0 is not detected"); - instance.config.backend = "webgl"; - return; - } - if (config2.canvas) { - config2.canvas.addEventListener("webglcontextlost", (e) => { - log("humangl error:", e.type); - log("possible browser memory leak using webgl or conflict with multiple backend registrations"); - instance.emit("error"); - throw new Error("backend error: webgl context lost"); - }); - config2.canvas.addEventListener("webglcontextrestored", (e) => { - log("humangl error: context restored:", e); - }); - config2.canvas.addEventListener("webglcontextcreationerror", (e) => { - log("humangl error: context create:", e); - }); - } - } catch (err) { - log("humangl error: cannot get webgl context:", err); - return; - } - try { - tf5.setWebGLContext(2, config2.gl); - } catch (err) { - log("humangl error: cannot set webgl context:", err); - return; - } - try { - const ctx = new tf5.GPGPUContext(config2.gl); - tf5.registerBackend(config2.name, () => new tf5.MathBackendWebGL(ctx), config2.priority); - } catch (err) { - log("humangl error: cannot register webgl backend:", err); - return; - } - try { - const kernels = tf5.getKernelsForBackend("webgl"); - kernels.forEach((kernelConfig) => { - const newKernelConfig = { ...kernelConfig, backendName: config2.name }; - tf5.registerKernel(newKernelConfig); - }); - } catch (err) { - log("humangl error: cannot update webgl backend registration:", err); - return; - } - try { - if (tf5.env().flagRegistry.WEBGL_VERSION) - tf5.env().set("WEBGL_VERSION", 2); - } catch (err) { - log("humangl error: cannot set WebGL backend flags:", err); - return; - } - extensions(); - const backend4 = tf5.backend(); - const current = typeof backend4["gpgpu"] !== "undefined" ? backend4["getGPGPUContext"]().gl : null; - if (current) { - if (instance.config.debug) - log("humangl backend registered:", { webgl: current.getParameter(current.VERSION), renderer: current.getParameter(current.RENDERER) }); - } else { - log("humangl error: no current gl context:", current, config2.gl); - } - } -} - -// src/tfjs/constants.ts -var tf6 = __toESM(require_tfjs_esm()); -var constants = { - tf255: 255, - tf1: 1, - tf2: 2, - tf05: 0.5, - tf127: 127.5, - rgb: [0.2989, 0.587, 0.114] -}; -function init() { - constants.tf255 = tf6.scalar(255, "float32"); - constants.tf1 = tf6.scalar(1, "float32"); - constants.tf2 = tf6.scalar(2, "float32"); - constants.tf05 = tf6.scalar(0.5, "float32"); - constants.tf127 = tf6.scalar(127.5, "float32"); - constants.rgb = tf6.tensor1d([0.2989, 0.587, 0.114], "float32"); -} - -// src/tfjs/backend.ts -async function getBestBackend() { - var _a; - await env.updateBackend(); - if ((_a = env.tensorflow) == null ? void 0 : _a.version) - return "tensorflow"; - if (env.webgpu.supported && env.webgpu.backend) - return "webgpu"; - if (env.webgl.supported && env.webgl.backend) - return "webgl"; - if (env.wasm.supported && env.wasm.backend) - return "wasm"; - return "cpu"; -} -function registerCustomOps(config3) { - const newKernels = []; - if (!env.kernels.includes("mod")) { - const kernelMod = { - kernelName: "Mod", - backendName: tf7.getBackend(), - kernelFunc: (op) => tf7.tidy(() => tf7.sub(op.inputs.a, tf7.mul(tf7.div(op.inputs.a, op.inputs.b), op.inputs.b))) - }; - tf7.registerKernel(kernelMod); - env.kernels.push("mod"); - newKernels.push("mod"); - } - if (!env.kernels.includes("floormod")) { - const kernelFloorMod = { - kernelName: "FloorMod", - backendName: tf7.getBackend(), - kernelFunc: (op) => tf7.tidy(() => tf7.add(tf7.mul(tf7.floorDiv(op.inputs.a, op.inputs.b), op.inputs.b), tf7.mod(op.inputs.a, op.inputs.b))) - }; - tf7.registerKernel(kernelFloorMod); - env.kernels.push("floormod"); - newKernels.push("floormod"); - } - if (!env.kernels.includes("rotatewithoffset") && config3.softwareKernels) { - const kernelRotateWithOffset = { - kernelName: "RotateWithOffset", - backendName: tf7.getBackend(), - kernelFunc: (op) => tf7.tidy(() => { - const backend4 = tf7.getBackend(); - tf7.setBackend("cpu"); - const t2 = tf7.image.rotateWithOffset(op.inputs.image, op.attrs.radians, op.attrs.fillValue, op.attrs.center); - tf7.setBackend(backend4); - return t2; - }) - }; - tf7.registerKernel(kernelRotateWithOffset); - env.kernels.push("rotatewithoffset"); - newKernels.push("rotatewithoffset"); - } - if (newKernels.length > 0 && config3.debug) - log("registered kernels:", newKernels); -} -var defaultFlags = {}; -async function check(instance, force = false) { - var _a; - instance.state = "backend"; - if (((_a = instance.config.backend) == null ? void 0 : _a.length) === 0) - instance.config.backend = await getBestBackend(); - if (force || env.initial || instance.config.backend && instance.config.backend.length > 0 && tf7.getBackend() !== instance.config.backend) { - const timeStamp = now(); - if (instance.config.backend && instance.config.backend.length > 0) { - if (typeof window === "undefined" && typeof WorkerGlobalScope !== "undefined" && instance.config.debug) { - if (instance.config.debug) - log("running inside web worker"); - } - if (env.browser && instance.config.backend === "tensorflow") { - if (instance.config.debug) - log("override: backend set to tensorflow while running in browser"); - instance.config.backend = "webgl"; - } - if (env.node && (instance.config.backend === "webgl" || instance.config.backend === "humangl")) { - if (instance.config.debug) - log(`override: backend set to ${instance.config.backend} while running in nodejs`); - instance.config.backend = "tensorflow"; - } - if (env.browser && instance.config.backend === "webgpu") { - if (typeof navigator === "undefined" || typeof navigator.gpu === "undefined") { - log("override: backend set to webgpu but browser does not support webgpu"); - instance.config.backend = "webgl"; - } else { - const adapter = await navigator.gpu.requestAdapter(); - if (instance.config.debug) - log("enumerated webgpu adapter:", adapter); - if (!adapter) { - log("override: backend set to webgpu but browser reports no available gpu"); - instance.config.backend = "webgl"; - } else { - const adapterInfo = "requestAdapterInfo" in adapter ? await adapter.requestAdapterInfo() : void 0; - log("webgpu adapter info:", adapterInfo); - } - } - } - let available = Object.keys(tf7.engine().registryFactory); - if (instance.config.backend === "humangl" && !available.includes("humangl")) { - register(instance); - available = Object.keys(tf7.engine().registryFactory); - } - if (instance.config.debug) - log("available backends:", available); - if (!available.includes(instance.config.backend)) { - log(`error: backend ${instance.config.backend} not found in registry`); - instance.config.backend = env.node ? "tensorflow" : "webgl"; - if (instance.config.debug) - log(`override: setting backend ${instance.config.backend}`); - } - if (instance.config.debug) - log("setting backend:", [instance.config.backend]); - if (instance.config.backend === "wasm") { - if (tf7.env().flagRegistry.CANVAS2D_WILL_READ_FREQUENTLY) - tf7.env().set("CANVAS2D_WILL_READ_FREQUENTLY", true); - if (instance.config.debug) - log("wasm path:", instance.config.wasmPath); - if (typeof tf7.setWasmPaths !== "undefined") - tf7.setWasmPaths(instance.config.wasmPath, instance.config.wasmPlatformFetch); - else - throw new Error("backend error: attempting to use wasm backend but wasm path is not set"); - let mt = false; - let simd = false; - try { - mt = await tf7.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"); - simd = await tf7.env().getAsync("WASM_HAS_SIMD_SUPPORT"); - if (instance.config.debug) - log(`wasm execution: ${simd ? "simd" : "no simd"} ${mt ? "multithreaded" : "singlethreaded"}`); - if (instance.config.debug && !simd) - log("warning: wasm simd support is not enabled"); - } catch (e) { - log("wasm detection failed"); - } - } - try { - await tf7.setBackend(instance.config.backend); - await tf7.ready(); - } catch (err) { - log("error: cannot set backend:", instance.config.backend, err); - return false; - } - if (instance.config.debug) - defaultFlags = JSON.parse(JSON.stringify(tf7.env().flags)); - } - if (tf7.getBackend() === "humangl" || tf7.getBackend() === "webgl") { - if (tf7.env().flagRegistry.WEBGL_USE_SHAPES_UNIFORMS) - tf7.env().set("WEBGL_USE_SHAPES_UNIFORMS", true); - if (tf7.env().flagRegistry.WEBGL_EXP_CONV) - tf7.env().set("WEBGL_EXP_CONV", true); - if (instance.config.debug && typeof instance.config.deallocate !== "undefined" && instance.config.deallocate) { - log("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:", true); - tf7.env().set("WEBGL_DELETE_TEXTURE_THRESHOLD", 0); - } - } - if (tf7.getBackend() === "webgpu") { - } - if (instance.config.debug) { - const newFlags = tf7.env().flags; - const updatedFlags = {}; - for (const key of Object.keys(newFlags)) { - if (defaultFlags[key] === newFlags[key]) - continue; - updatedFlags[key] = newFlags[key]; - } - if (instance.config.debug && Object.keys(updatedFlags).length > 0) - log("backend:", tf7.getBackend(), "flags:", updatedFlags); - } - if (instance.config.flags && Object.keys(instance.config.flags).length > 0) { - if (instance.config.debug) - log("flags:", instance.config["flags"]); - for (const [key, val] of Object.entries(instance.config.flags)) { - tf7.env().set(key, val); - } - } - tf7.enableProdMode(); - init(); - instance.performance.initBackend = Math.trunc(now() - timeStamp); - instance.config.backend = tf7.getBackend(); - await env.updateBackend(); - registerCustomOps(instance.config); - env.initial = false; - } - return true; -} -function fakeOps(kernelNames, config3) { - for (const kernelName of kernelNames) { - const kernelConfig = { - kernelName, - backendName: config3.backend, - kernelFunc: (param) => { - var _a; - if (config3.debug) - log("kernelFunc", kernelName, config3.backend, param); - return (_a = param == null ? void 0 : param.inputs) == null ? void 0 : _a.info; - } - }; - tf7.registerKernel(kernelConfig); - } - env.kernels = tf7.getKernelsForBackend(tf7.getBackend()).map((kernel) => kernel.kernelName.toLowerCase()); -} - -// src/draw/draw.ts -var draw_exports = {}; -__export(draw_exports, { - all: () => all, - body: () => body, - canvas: () => canvas2, - face: () => face, - gesture: () => gesture, - hand: () => hand, - init: () => init2, - object: () => object, - options: () => options2, - person: () => person -}); - -// src/draw/primitives.ts -var getCanvasContext = (input) => { - if (!input) - log("draw error: invalid canvas"); - else if (!input.getContext) - log("draw error: canvas context not defined"); - else { - const ctx = input.getContext("2d"); - if (!ctx) - log("draw error: cannot get canvas context"); - else - return ctx; - } - return null; -}; -var rad2deg = (theta) => Math.round(theta * 180 / Math.PI); -var replace = (str, source, target) => str.replace(source, typeof target === "number" ? target.toFixed(1) : target); -var colorDepth = (z, opt) => { - if (!opt.useDepth || typeof z === "undefined") - return opt.color; - const rgb2 = Uint8ClampedArray.from([127 + 2 * z, 127 - 2 * z, 255]); - return `rgba(${rgb2[0]}, ${rgb2[1]}, ${rgb2[2]}, ${opt.alpha})`; -}; -function labels(ctx, str, startX, startY, localOptions2) { - const line = str.replace(/\[.*\]/g, "").split("\n").map((l) => l.trim()); - const x = Math.max(0, startX); - for (let i = line.length - 1; i >= 0; i--) { - const y = i * localOptions2.lineHeight + startY; - if (localOptions2.shadowColor && localOptions2.shadowColor !== "") { - ctx.fillStyle = localOptions2.shadowColor; - ctx.fillText(line[i], x + 5, y + 16); - } - ctx.fillStyle = localOptions2.labelColor; - ctx.fillText(line[i], x + 4, y + 15); - } -} -function point(ctx, x, y, z, localOptions2) { - ctx.fillStyle = colorDepth(z, localOptions2); - ctx.beginPath(); - ctx.arc(x, y, localOptions2.pointSize, 0, 2 * Math.PI); - ctx.fill(); -} -function rect(ctx, x, y, width, height, localOptions2) { - ctx.beginPath(); - ctx.lineWidth = localOptions2.lineWidth; - if (localOptions2.useCurves) { - const cx = (x + x + width) / 2; - const cy = (y + y + height) / 2; - ctx.ellipse(cx, cy, width / 2, height / 2, 0, 0, 2 * Math.PI); - } else { - ctx.moveTo(x + localOptions2.roundRect, y); - ctx.lineTo(x + width - localOptions2.roundRect, y); - ctx.quadraticCurveTo(x + width, y, x + width, y + localOptions2.roundRect); - ctx.lineTo(x + width, y + height - localOptions2.roundRect); - ctx.quadraticCurveTo(x + width, y + height, x + width - localOptions2.roundRect, y + height); - ctx.lineTo(x + localOptions2.roundRect, y + height); - ctx.quadraticCurveTo(x, y + height, x, y + height - localOptions2.roundRect); - ctx.lineTo(x, y + localOptions2.roundRect); - ctx.quadraticCurveTo(x, y, x + localOptions2.roundRect, y); - ctx.closePath(); - } - ctx.stroke(); -} -function lines(ctx, points, localOptions2) { - if (points.length < 2) - return; - ctx.beginPath(); - ctx.moveTo(points[0][0], points[0][1]); - for (const pt of points) { - ctx.strokeStyle = colorDepth(pt[2] || 0, localOptions2); - ctx.lineTo(Math.trunc(pt[0]), Math.trunc(pt[1])); - } - ctx.stroke(); - if (localOptions2.fillPolygons) { - ctx.closePath(); - ctx.fill(); - } -} -function curves(ctx, points, localOptions2) { - if (points.length < 2) - return; - ctx.lineWidth = localOptions2.lineWidth; - if (!localOptions2.useCurves || points.length <= 2) { - lines(ctx, points, localOptions2); - return; - } - ctx.moveTo(points[0][0], points[0][1]); - for (let i = 0; i < points.length - 2; i++) { - const xc = (points[i][0] + points[i + 1][0]) / 2; - const yc = (points[i][1] + points[i + 1][1]) / 2; - ctx.quadraticCurveTo(points[i][0], points[i][1], xc, yc); - } - ctx.quadraticCurveTo(points[points.length - 2][0], points[points.length - 2][1], points[points.length - 1][0], points[points.length - 1][1]); - ctx.stroke(); - if (localOptions2.fillPolygons) { - ctx.closePath(); - ctx.fill(); - } -} -function arrow(ctx, from, to, radius = 5) { - let angle; - let x; - let y; - ctx.beginPath(); - ctx.moveTo(from[0], from[1]); - ctx.lineTo(to[0], to[1]); - angle = Math.atan2(to[1] - from[1], to[0] - from[0]); - x = radius * Math.cos(angle) + to[0]; - y = radius * Math.sin(angle) + to[1]; - ctx.moveTo(x, y); - angle += 1 / 3 * (2 * Math.PI); - x = radius * Math.cos(angle) + to[0]; - y = radius * Math.sin(angle) + to[1]; - ctx.lineTo(x, y); - angle += 1 / 3 * (2 * Math.PI); - x = radius * Math.cos(angle) + to[0]; - y = radius * Math.sin(angle) + to[1]; - ctx.lineTo(x, y); - ctx.closePath(); - ctx.stroke(); - ctx.fill(); -} - -// src/draw/options.ts -var options2 = { - color: "rgba(173, 216, 230, 0.6)", - labelColor: "rgba(173, 216, 230, 1)", - shadowColor: "black", - alpha: 0.5, - font: 'small-caps 16px "Segoe UI"', - lineHeight: 18, - lineWidth: 4, - pointSize: 2, - roundRect: 8, - drawPoints: false, - drawLabels: true, - drawBoxes: true, - drawAttention: true, - drawGestures: true, - drawPolygons: true, - drawGaze: true, - fillPolygons: false, - useDepth: true, - useCurves: false, - faceLabels: "", - bodyLabels: "", - bodyPartLabels: "", - objectLabels: "", - handLabels: "", - fingerLabels: "", - gestureLabels: "" -}; - -// src/face/facemeshcoords.ts -var meshAnnotations = { - 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], - noseTip: [1], - noseBottom: [2], - noseRightCorner: [98], - noseLeftCorner: [327], - rightCheek: [205], - leftCheek: [425] -}; -var meshLandmarks = { - count: 468, - mouth: 13, - symmetryLine: [13, meshAnnotations.midwayBetweenEyes[0]] -}; -var blazeFaceLandmarks = { - leftEye: 0, - rightEye: 1, - nose: 2, - mouth: 3, - leftEar: 4, - rightEar: 5, - symmetryLine: [3, 2] -}; -var irisIndices = [ - { key: "EyeUpper0", indices: [9, 10, 11, 12, 13, 14, 15] }, - { key: "EyeUpper1", indices: [25, 26, 27, 28, 29, 30, 31] }, - { key: "EyeUpper2", indices: [41, 42, 43, 44, 45, 46, 47] }, - { key: "EyeLower0", indices: [0, 1, 2, 3, 4, 5, 6, 7, 8] }, - { key: "EyeLower1", indices: [16, 17, 18, 19, 20, 21, 22, 23, 24] }, - { key: "EyeLower2", indices: [32, 33, 34, 35, 36, 37, 38, 39, 40] }, - { key: "EyeLower3", indices: [54, 55, 56, 57, 58, 59, 60, 61, 62] }, - { key: "EyebrowUpper", indices: [63, 64, 65, 66, 67, 68, 69, 70] }, - { key: "EyebrowLower", indices: [48, 49, 50, 51, 52, 53] } -]; -var UV468 = [ - [0.499976992607117, 0.652534008026123], - [0.500025987625122, 0.547487020492554], - [0.499974012374878, 0.602371990680695], - [0.482113003730774, 0.471979022026062], - [0.500150978565216, 0.527155995368958], - [0.499909996986389, 0.498252987861633], - [0.499523013830185, 0.40106201171875], - [0.289712011814117, 0.380764007568359], - [0.499954998493195, 0.312398016452789], - [0.499987006187439, 0.269918978214264], - [0.500023007392883, 0.107050001621246], - [0.500023007392883, 0.666234016418457], - [0.5000159740448, 0.679224014282227], - [0.500023007392883, 0.692348003387451], - [0.499976992607117, 0.695277988910675], - [0.499976992607117, 0.70593398809433], - [0.499976992607117, 0.719385027885437], - [0.499976992607117, 0.737019002437592], - [0.499967992305756, 0.781370997428894], - [0.499816000461578, 0.562981009483337], - [0.473773002624512, 0.573909997940063], - [0.104906998574734, 0.254140973091125], - [0.365929991006851, 0.409575998783112], - [0.338757991790771, 0.41302502155304], - [0.311120003461838, 0.409460008144379], - [0.274657994508743, 0.389131009578705], - [0.393361985683441, 0.403706014156342], - [0.345234006643295, 0.344011008739471], - [0.370094001293182, 0.346076011657715], - [0.319321990013123, 0.347265005111694], - [0.297903001308441, 0.353591024875641], - [0.24779200553894, 0.410809993743896], - [0.396889001131058, 0.842755019664764], - [0.280097991228104, 0.375599980354309], - [0.106310002505779, 0.399955987930298], - [0.2099249958992, 0.391353011131287], - [0.355807989835739, 0.534406006336212], - [0.471751004457474, 0.65040397644043], - [0.474155008792877, 0.680191993713379], - [0.439785003662109, 0.657229006290436], - [0.414617002010345, 0.66654098033905], - [0.450374007225037, 0.680860996246338], - [0.428770989179611, 0.682690978050232], - [0.374971002340317, 0.727805018424988], - [0.486716985702515, 0.547628998756409], - [0.485300987958908, 0.527395009994507], - [0.257764995098114, 0.314490020275116], - [0.401223003864288, 0.455172002315521], - [0.429818987846375, 0.548614978790283], - [0.421351999044418, 0.533740997314453], - [0.276895999908447, 0.532056987285614], - [0.483370006084442, 0.499586999416351], - [0.33721199631691, 0.282882988452911], - [0.296391993761063, 0.293242990970612], - [0.169294998049736, 0.193813979625702], - [0.447580009698868, 0.302609980106354], - [0.392390012741089, 0.353887975215912], - [0.354490011930466, 0.696784019470215], - [0.067304998636246, 0.730105042457581], - [0.442739009857178, 0.572826027870178], - [0.457098007202148, 0.584792017936707], - [0.381974011659622, 0.694710969924927], - [0.392388999462128, 0.694203019142151], - [0.277076005935669, 0.271932005882263], - [0.422551989555359, 0.563233017921448], - [0.385919004678726, 0.281364023685455], - [0.383103013038635, 0.255840003490448], - [0.331431001424789, 0.119714021682739], - [0.229923993349075, 0.232002973556519], - [0.364500999450684, 0.189113974571228], - [0.229622006416321, 0.299540996551514], - [0.173287004232407, 0.278747975826263], - [0.472878992557526, 0.666198015213013], - [0.446828007698059, 0.668527007102966], - [0.422762006521225, 0.673889994621277], - [0.445307999849319, 0.580065965652466], - [0.388103008270264, 0.693961024284363], - [0.403039008378983, 0.706539988517761], - [0.403629004955292, 0.693953037261963], - [0.460041999816895, 0.557139039039612], - [0.431158006191254, 0.692366003990173], - [0.452181994915009, 0.692366003990173], - [0.475387006998062, 0.692366003990173], - [0.465828001499176, 0.779190003871918], - [0.472328990697861, 0.736225962638855], - [0.473087012767792, 0.717857003211975], - [0.473122000694275, 0.704625964164734], - [0.473033010959625, 0.695277988910675], - [0.427942007780075, 0.695277988910675], - [0.426479011774063, 0.703539967536926], - [0.423162013292313, 0.711845993995667], - [0.4183090031147, 0.720062971115112], - [0.390094995498657, 0.639572978019714], - [0.013953999616206, 0.560034036636353], - [0.499913990497589, 0.58014702796936], - [0.413199990987778, 0.69539999961853], - [0.409626007080078, 0.701822996139526], - [0.468080013990402, 0.601534962654114], - [0.422728985548019, 0.585985004901886], - [0.463079988956451, 0.593783974647522], - [0.37211999297142, 0.47341400384903], - [0.334562003612518, 0.496073007583618], - [0.411671012639999, 0.546965003013611], - [0.242175996303558, 0.14767599105835], - [0.290776997804642, 0.201445996761322], - [0.327338010072708, 0.256527006626129], - [0.399509996175766, 0.748921036720276], - [0.441727995872498, 0.261676013469696], - [0.429764986038208, 0.187834024429321], - [0.412198007106781, 0.108901023864746], - [0.288955003023148, 0.398952007293701], - [0.218936994671822, 0.435410976409912], - [0.41278201341629, 0.398970007896423], - [0.257135003805161, 0.355440020561218], - [0.427684992551804, 0.437960982322693], - [0.448339998722076, 0.536936044692993], - [0.178560003638268, 0.45755398273468], - [0.247308000922203, 0.457193970680237], - [0.286267012357712, 0.467674970626831], - [0.332827985286713, 0.460712015628815], - [0.368755996227264, 0.447206974029541], - [0.398963987827301, 0.432654976844788], - [0.476410001516342, 0.405806005001068], - [0.189241006970406, 0.523923993110657], - [0.228962004184723, 0.348950982093811], - [0.490725994110107, 0.562400996685028], - [0.404670000076294, 0.485132992267609], - [0.019469000399113, 0.401564002037048], - [0.426243007183075, 0.420431017875671], - [0.396993011236191, 0.548797011375427], - [0.266469985246658, 0.376977026462555], - [0.439121007919312, 0.51895797252655], - [0.032313998788595, 0.644356966018677], - [0.419054001569748, 0.387154996395111], - [0.462783008813858, 0.505746960639954], - [0.238978996872902, 0.779744982719421], - [0.198220998048782, 0.831938028335571], - [0.107550002634525, 0.540755033493042], - [0.183610007166862, 0.740257024765015], - [0.134409993886948, 0.333683013916016], - [0.385764002799988, 0.883153975009918], - [0.490967005491257, 0.579378008842468], - [0.382384985685349, 0.508572995662689], - [0.174399003386497, 0.397670984268188], - [0.318785011768341, 0.39623498916626], - [0.343364000320435, 0.400596976280212], - [0.396100014448166, 0.710216999053955], - [0.187885001301765, 0.588537991046906], - [0.430987000465393, 0.944064974784851], - [0.318993002176285, 0.898285031318665], - [0.266247987747192, 0.869701027870178], - [0.500023007392883, 0.190576016902924], - [0.499976992607117, 0.954452991485596], - [0.366169989109039, 0.398822009563446], - [0.393207013607025, 0.39553701877594], - [0.410373002290726, 0.391080021858215], - [0.194993004202843, 0.342101991176605], - [0.388664990663528, 0.362284004688263], - [0.365961998701096, 0.355970978736877], - [0.343364000320435, 0.355356991291046], - [0.318785011768341, 0.35834002494812], - [0.301414996385574, 0.363156020641327], - [0.058132998645306, 0.319076001644135], - [0.301414996385574, 0.387449026107788], - [0.499987989664078, 0.618434011936188], - [0.415838003158569, 0.624195992946625], - [0.445681989192963, 0.566076993942261], - [0.465844005346298, 0.620640993118286], - [0.49992299079895, 0.351523995399475], - [0.288718998432159, 0.819945991039276], - [0.335278987884521, 0.852819979190826], - [0.440512001514435, 0.902418971061707], - [0.128294005990028, 0.791940987110138], - [0.408771991729736, 0.373893976211548], - [0.455606997013092, 0.451801002025604], - [0.499877005815506, 0.908990025520325], - [0.375436991453171, 0.924192011356354], - [0.11421000212431, 0.615022003650665], - [0.448662012815475, 0.695277988910675], - [0.4480200111866, 0.704632043838501], - [0.447111994028091, 0.715808033943176], - [0.444831997156143, 0.730794012546539], - [0.430011987686157, 0.766808986663818], - [0.406787008047104, 0.685672998428345], - [0.400738000869751, 0.681069016456604], - [0.392399996519089, 0.677703022956848], - [0.367855995893478, 0.663918972015381], - [0.247923001646996, 0.601333022117615], - [0.452769994735718, 0.420849978923798], - [0.43639200925827, 0.359887003898621], - [0.416164010763168, 0.368713974952698], - [0.413385987281799, 0.692366003990173], - [0.228018000721931, 0.683571994304657], - [0.468268007040024, 0.352671027183533], - [0.411361992359161, 0.804327011108398], - [0.499989002943039, 0.469825029373169], - [0.479153990745544, 0.442654013633728], - [0.499974012374878, 0.439637005329132], - [0.432112008333206, 0.493588984012604], - [0.499886006116867, 0.866917014122009], - [0.49991300702095, 0.821729004383087], - [0.456548988819122, 0.819200992584229], - [0.344549000263214, 0.745438992977142], - [0.37890899181366, 0.574010014533997], - [0.374292999505997, 0.780184984207153], - [0.319687992334366, 0.570737957954407], - [0.357154995203018, 0.604269981384277], - [0.295284003019333, 0.621580958366394], - [0.447750002145767, 0.862477004528046], - [0.410986006259918, 0.508723020553589], - [0.31395098567009, 0.775308012962341], - [0.354128003120422, 0.812552988529205], - [0.324548006057739, 0.703992962837219], - [0.189096003770828, 0.646299958229065], - [0.279776990413666, 0.71465802192688], - [0.1338230073452, 0.682700991630554], - [0.336768001317978, 0.644733011722565], - [0.429883986711502, 0.466521978378296], - [0.455527991056442, 0.548622965812683], - [0.437114000320435, 0.558896005153656], - [0.467287987470627, 0.529924988746643], - [0.414712011814117, 0.335219979286194], - [0.37704598903656, 0.322777986526489], - [0.344107985496521, 0.320150971412659], - [0.312875986099243, 0.32233202457428], - [0.283526003360748, 0.333190023899078], - [0.241245999932289, 0.382785975933075], - [0.102986000478268, 0.468762993812561], - [0.267612010240555, 0.424560010433197], - [0.297879010438919, 0.433175981044769], - [0.333433985710144, 0.433878004550934], - [0.366427004337311, 0.426115989685059], - [0.396012008190155, 0.416696012020111], - [0.420121014118195, 0.41022801399231], - [0.007561000064015, 0.480777025222778], - [0.432949006557465, 0.569517970085144], - [0.458638995885849, 0.479089021682739], - [0.473466008901596, 0.545744001865387], - [0.476087987422943, 0.563830018043518], - [0.468472003936768, 0.555056989192963], - [0.433990985155106, 0.582361996173859], - [0.483518004417419, 0.562983989715576], - [0.482482999563217, 0.57784903049469], - [0.42645001411438, 0.389798998832703], - [0.438998997211456, 0.39649498462677], - [0.450067013502121, 0.400434017181396], - [0.289712011814117, 0.368252992630005], - [0.276670008897781, 0.363372981548309], - [0.517862021923065, 0.471948027610779], - [0.710287988185883, 0.380764007568359], - [0.526226997375488, 0.573909997940063], - [0.895093023777008, 0.254140973091125], - [0.634069979190826, 0.409575998783112], - [0.661242008209229, 0.41302502155304], - [0.688880026340485, 0.409460008144379], - [0.725341975688934, 0.389131009578705], - [0.606630027294159, 0.40370500087738], - [0.654766023159027, 0.344011008739471], - [0.629905998706818, 0.346076011657715], - [0.680678009986877, 0.347265005111694], - [0.702096998691559, 0.353591024875641], - [0.75221198797226, 0.410804986953735], - [0.602918028831482, 0.842862963676453], - [0.719901978969574, 0.375599980354309], - [0.893692970275879, 0.399959981441498], - [0.790081977844238, 0.391354024410248], - [0.643998026847839, 0.534487962722778], - [0.528249025344849, 0.65040397644043], - [0.525849997997284, 0.680191040039062], - [0.560214996337891, 0.657229006290436], - [0.585384011268616, 0.66654098033905], - [0.549625992774963, 0.680860996246338], - [0.57122802734375, 0.682691991329193], - [0.624852001667023, 0.72809898853302], - [0.513050019741058, 0.547281980514526], - [0.51509702205658, 0.527251958847046], - [0.742246985435486, 0.314507007598877], - [0.598631024360657, 0.454979002475739], - [0.570338010787964, 0.548575043678284], - [0.578631997108459, 0.533622980117798], - [0.723087012767792, 0.532054007053375], - [0.516445994377136, 0.499638974666595], - [0.662801027297974, 0.282917976379395], - [0.70362401008606, 0.293271005153656], - [0.830704987049103, 0.193813979625702], - [0.552385985851288, 0.302568018436432], - [0.607609987258911, 0.353887975215912], - [0.645429015159607, 0.696707010269165], - [0.932694971561432, 0.730105042457581], - [0.557260990142822, 0.572826027870178], - [0.542901992797852, 0.584792017936707], - [0.6180260181427, 0.694710969924927], - [0.607590973377228, 0.694203019142151], - [0.722943007946014, 0.271963000297546], - [0.577413976192474, 0.563166975975037], - [0.614082992076874, 0.281386971473694], - [0.616907000541687, 0.255886018276215], - [0.668509006500244, 0.119913995265961], - [0.770092010498047, 0.232020974159241], - [0.635536015033722, 0.189248979091644], - [0.77039098739624, 0.299556016921997], - [0.826722025871277, 0.278755009174347], - [0.527121007442474, 0.666198015213013], - [0.553171992301941, 0.668527007102966], - [0.577238023281097, 0.673889994621277], - [0.554691970348358, 0.580065965652466], - [0.611896991729736, 0.693961024284363], - [0.59696102142334, 0.706539988517761], - [0.596370995044708, 0.693953037261963], - [0.539958000183105, 0.557139039039612], - [0.568841993808746, 0.692366003990173], - [0.547818005084991, 0.692366003990173], - [0.52461302280426, 0.692366003990173], - [0.534089982509613, 0.779141008853912], - [0.527670979499817, 0.736225962638855], - [0.526912987232208, 0.717857003211975], - [0.526877999305725, 0.704625964164734], - [0.526966989040375, 0.695277988910675], - [0.572058022022247, 0.695277988910675], - [0.573521018028259, 0.703539967536926], - [0.57683801651001, 0.711845993995667], - [0.581691026687622, 0.720062971115112], - [0.609944999217987, 0.639909982681274], - [0.986046016216278, 0.560034036636353], - [0.5867999792099, 0.69539999961853], - [0.590372025966644, 0.701822996139526], - [0.531915009021759, 0.601536989212036], - [0.577268004417419, 0.585934996604919], - [0.536915004253387, 0.593786001205444], - [0.627542972564697, 0.473352015018463], - [0.665585994720459, 0.495950996875763], - [0.588353991508484, 0.546862006187439], - [0.757824003696442, 0.14767599105835], - [0.709249973297119, 0.201507985591888], - [0.672684013843536, 0.256581008434296], - [0.600408971309662, 0.74900496006012], - [0.55826598405838, 0.261672019958496], - [0.570303976535797, 0.187870979309082], - [0.588165998458862, 0.109044015407562], - [0.711045026779175, 0.398952007293701], - [0.781069993972778, 0.435405015945435], - [0.587247014045715, 0.398931980133057], - [0.742869973182678, 0.355445981025696], - [0.572156012058258, 0.437651991844177], - [0.55186802148819, 0.536570012569427], - [0.821442008018494, 0.457556009292603], - [0.752701997756958, 0.457181990146637], - [0.71375697851181, 0.467626988887787], - [0.66711300611496, 0.460672974586487], - [0.631101012229919, 0.447153985500336], - [0.6008620262146, 0.432473003864288], - [0.523481011390686, 0.405627012252808], - [0.810747981071472, 0.523926019668579], - [0.771045982837677, 0.348959028720856], - [0.509127020835876, 0.562718033790588], - [0.595292985439301, 0.485023975372314], - [0.980530977249146, 0.401564002037048], - [0.573499977588654, 0.420000016689301], - [0.602994978427887, 0.548687994480133], - [0.733529984951019, 0.376977026462555], - [0.560611009597778, 0.519016981124878], - [0.967685997486115, 0.644356966018677], - [0.580985009670258, 0.387160003185272], - [0.537728011608124, 0.505385041236877], - [0.760966002941132, 0.779752969741821], - [0.801778972148895, 0.831938028335571], - [0.892440974712372, 0.54076099395752], - [0.816350996494293, 0.740260004997253], - [0.865594983100891, 0.333687007427216], - [0.614073991775513, 0.883246004581451], - [0.508952975273132, 0.579437971115112], - [0.617941975593567, 0.508316040039062], - [0.825608015060425, 0.397674977779388], - [0.681214988231659, 0.39623498916626], - [0.656635999679565, 0.400596976280212], - [0.603900015354156, 0.710216999053955], - [0.81208598613739, 0.588539004325867], - [0.56801301240921, 0.944564998149872], - [0.681007981300354, 0.898285031318665], - [0.733752012252808, 0.869701027870178], - [0.633830010890961, 0.398822009563446], - [0.606792986392975, 0.39553701877594], - [0.589659988880157, 0.391062021255493], - [0.805015981197357, 0.342108011245728], - [0.611334979534149, 0.362284004688263], - [0.634037971496582, 0.355970978736877], - [0.656635999679565, 0.355356991291046], - [0.681214988231659, 0.35834002494812], - [0.698584973812103, 0.363156020641327], - [0.941866993904114, 0.319076001644135], - [0.698584973812103, 0.387449026107788], - [0.584177017211914, 0.624107003211975], - [0.554318010807037, 0.566076993942261], - [0.534153997898102, 0.62064003944397], - [0.711217999458313, 0.819975018501282], - [0.664629995822906, 0.852871000766754], - [0.559099972248077, 0.902631998062134], - [0.871706008911133, 0.791940987110138], - [0.591234028339386, 0.373893976211548], - [0.544341027736664, 0.451583981513977], - [0.624562978744507, 0.924192011356354], - [0.88577002286911, 0.615028977394104], - [0.551338016986847, 0.695277988910675], - [0.551980018615723, 0.704632043838501], - [0.552887976169586, 0.715808033943176], - [0.555167973041534, 0.730794012546539], - [0.569944024085999, 0.767035007476807], - [0.593203008174896, 0.685675978660583], - [0.599261999130249, 0.681069016456604], - [0.607599973678589, 0.677703022956848], - [0.631937980651855, 0.663500010967255], - [0.752032995223999, 0.601315021514893], - [0.547226011753082, 0.420395016670227], - [0.563543975353241, 0.359827995300293], - [0.583841025829315, 0.368713974952698], - [0.586614012718201, 0.692366003990173], - [0.771915018558502, 0.683578014373779], - [0.531597018241882, 0.352482974529266], - [0.588370978832245, 0.804440975189209], - [0.52079701423645, 0.442565023899078], - [0.567984998226166, 0.493479013442993], - [0.543282985687256, 0.819254994392395], - [0.655317008495331, 0.745514988899231], - [0.621008992195129, 0.574018001556396], - [0.625559985637665, 0.78031200170517], - [0.680198013782501, 0.570719003677368], - [0.64276397228241, 0.604337990283966], - [0.704662978649139, 0.621529996395111], - [0.552012026309967, 0.862591981887817], - [0.589071989059448, 0.508637011051178], - [0.685944974422455, 0.775357007980347], - [0.645735025405884, 0.812640011310577], - [0.675342977046967, 0.703978002071381], - [0.810858011245728, 0.646304965019226], - [0.72012197971344, 0.714666962623596], - [0.866151988506317, 0.682704985141754], - [0.663187026977539, 0.644596993923187], - [0.570082008838654, 0.466325998306274], - [0.544561982154846, 0.548375964164734], - [0.562758982181549, 0.558784961700439], - [0.531987011432648, 0.530140042304993], - [0.585271000862122, 0.335177004337311], - [0.622952997684479, 0.32277899980545], - [0.655896008014679, 0.320163011550903], - [0.687132000923157, 0.322345972061157], - [0.716481983661652, 0.333200991153717], - [0.758756995201111, 0.382786989212036], - [0.897013008594513, 0.468769013881683], - [0.732392013072968, 0.424547016620636], - [0.70211398601532, 0.433162987232208], - [0.66652500629425, 0.433866024017334], - [0.633504986763, 0.426087975502014], - [0.603875994682312, 0.416586995124817], - [0.579657971858978, 0.409945011138916], - [0.992439985275269, 0.480777025222778], - [0.567192018032074, 0.569419980049133], - [0.54136598110199, 0.478899002075195], - [0.526564002037048, 0.546118021011353], - [0.523913025856018, 0.563830018043518], - [0.531529009342194, 0.555056989192963], - [0.566035985946655, 0.582329034805298], - [0.51631098985672, 0.563053965568542], - [0.5174720287323, 0.577877044677734], - [0.573594987392426, 0.389806985855103], - [0.560697972774506, 0.395331978797913], - [0.549755990505219, 0.399751007556915], - [0.710287988185883, 0.368252992630005], - [0.723330020904541, 0.363372981548309] -]; -var TRI468 = [ - 127, - 34, - 139, - 11, - 0, - 37, - 232, - 231, - 120, - 72, - 37, - 39, - 128, - 121, - 47, - 232, - 121, - 128, - 104, - 69, - 67, - 175, - 171, - 148, - 157, - 154, - 155, - 118, - 50, - 101, - 73, - 39, - 40, - 9, - 151, - 108, - 48, - 115, - 131, - 194, - 204, - 211, - 74, - 40, - 185, - 80, - 42, - 183, - 40, - 92, - 186, - 230, - 229, - 118, - 202, - 212, - 214, - 83, - 18, - 17, - 76, - 61, - 146, - 160, - 29, - 30, - 56, - 157, - 173, - 106, - 204, - 194, - 135, - 214, - 192, - 203, - 165, - 98, - 21, - 71, - 68, - 51, - 45, - 4, - 144, - 24, - 23, - 77, - 146, - 91, - 205, - 50, - 187, - 201, - 200, - 18, - 91, - 106, - 182, - 90, - 91, - 181, - 85, - 84, - 17, - 206, - 203, - 36, - 148, - 171, - 140, - 92, - 40, - 39, - 193, - 189, - 244, - 159, - 158, - 28, - 247, - 246, - 161, - 236, - 3, - 196, - 54, - 68, - 104, - 193, - 168, - 8, - 117, - 228, - 31, - 189, - 193, - 55, - 98, - 97, - 99, - 126, - 47, - 100, - 166, - 79, - 218, - 155, - 154, - 26, - 209, - 49, - 131, - 135, - 136, - 150, - 47, - 126, - 217, - 223, - 52, - 53, - 45, - 51, - 134, - 211, - 170, - 140, - 67, - 69, - 108, - 43, - 106, - 91, - 230, - 119, - 120, - 226, - 130, - 247, - 63, - 53, - 52, - 238, - 20, - 242, - 46, - 70, - 156, - 78, - 62, - 96, - 46, - 53, - 63, - 143, - 34, - 227, - 173, - 155, - 133, - 123, - 117, - 111, - 44, - 125, - 19, - 236, - 134, - 51, - 216, - 206, - 205, - 154, - 153, - 22, - 39, - 37, - 167, - 200, - 201, - 208, - 36, - 142, - 100, - 57, - 212, - 202, - 20, - 60, - 99, - 28, - 158, - 157, - 35, - 226, - 113, - 160, - 159, - 27, - 204, - 202, - 210, - 113, - 225, - 46, - 43, - 202, - 204, - 62, - 76, - 77, - 137, - 123, - 116, - 41, - 38, - 72, - 203, - 129, - 142, - 64, - 98, - 240, - 49, - 102, - 64, - 41, - 73, - 74, - 212, - 216, - 207, - 42, - 74, - 184, - 169, - 170, - 211, - 170, - 149, - 176, - 105, - 66, - 69, - 122, - 6, - 168, - 123, - 147, - 187, - 96, - 77, - 90, - 65, - 55, - 107, - 89, - 90, - 180, - 101, - 100, - 120, - 63, - 105, - 104, - 93, - 137, - 227, - 15, - 86, - 85, - 129, - 102, - 49, - 14, - 87, - 86, - 55, - 8, - 9, - 100, - 47, - 121, - 145, - 23, - 22, - 88, - 89, - 179, - 6, - 122, - 196, - 88, - 95, - 96, - 138, - 172, - 136, - 215, - 58, - 172, - 115, - 48, - 219, - 42, - 80, - 81, - 195, - 3, - 51, - 43, - 146, - 61, - 171, - 175, - 199, - 81, - 82, - 38, - 53, - 46, - 225, - 144, - 163, - 110, - 246, - 33, - 7, - 52, - 65, - 66, - 229, - 228, - 117, - 34, - 127, - 234, - 107, - 108, - 69, - 109, - 108, - 151, - 48, - 64, - 235, - 62, - 78, - 191, - 129, - 209, - 126, - 111, - 35, - 143, - 163, - 161, - 246, - 117, - 123, - 50, - 222, - 65, - 52, - 19, - 125, - 141, - 221, - 55, - 65, - 3, - 195, - 197, - 25, - 7, - 33, - 220, - 237, - 44, - 70, - 71, - 139, - 122, - 193, - 245, - 247, - 130, - 33, - 71, - 21, - 162, - 153, - 158, - 159, - 170, - 169, - 150, - 188, - 174, - 196, - 216, - 186, - 92, - 144, - 160, - 161, - 2, - 97, - 167, - 141, - 125, - 241, - 164, - 167, - 37, - 72, - 38, - 12, - 145, - 159, - 160, - 38, - 82, - 13, - 63, - 68, - 71, - 226, - 35, - 111, - 158, - 153, - 154, - 101, - 50, - 205, - 206, - 92, - 165, - 209, - 198, - 217, - 165, - 167, - 97, - 220, - 115, - 218, - 133, - 112, - 243, - 239, - 238, - 241, - 214, - 135, - 169, - 190, - 173, - 133, - 171, - 208, - 32, - 125, - 44, - 237, - 86, - 87, - 178, - 85, - 86, - 179, - 84, - 85, - 180, - 83, - 84, - 181, - 201, - 83, - 182, - 137, - 93, - 132, - 76, - 62, - 183, - 61, - 76, - 184, - 57, - 61, - 185, - 212, - 57, - 186, - 214, - 207, - 187, - 34, - 143, - 156, - 79, - 239, - 237, - 123, - 137, - 177, - 44, - 1, - 4, - 201, - 194, - 32, - 64, - 102, - 129, - 213, - 215, - 138, - 59, - 166, - 219, - 242, - 99, - 97, - 2, - 94, - 141, - 75, - 59, - 235, - 24, - 110, - 228, - 25, - 130, - 226, - 23, - 24, - 229, - 22, - 23, - 230, - 26, - 22, - 231, - 112, - 26, - 232, - 189, - 190, - 243, - 221, - 56, - 190, - 28, - 56, - 221, - 27, - 28, - 222, - 29, - 27, - 223, - 30, - 29, - 224, - 247, - 30, - 225, - 238, - 79, - 20, - 166, - 59, - 75, - 60, - 75, - 240, - 147, - 177, - 215, - 20, - 79, - 166, - 187, - 147, - 213, - 112, - 233, - 244, - 233, - 128, - 245, - 128, - 114, - 188, - 114, - 217, - 174, - 131, - 115, - 220, - 217, - 198, - 236, - 198, - 131, - 134, - 177, - 132, - 58, - 143, - 35, - 124, - 110, - 163, - 7, - 228, - 110, - 25, - 356, - 389, - 368, - 11, - 302, - 267, - 452, - 350, - 349, - 302, - 303, - 269, - 357, - 343, - 277, - 452, - 453, - 357, - 333, - 332, - 297, - 175, - 152, - 377, - 384, - 398, - 382, - 347, - 348, - 330, - 303, - 304, - 270, - 9, - 336, - 337, - 278, - 279, - 360, - 418, - 262, - 431, - 304, - 408, - 409, - 310, - 415, - 407, - 270, - 409, - 410, - 450, - 348, - 347, - 422, - 430, - 434, - 313, - 314, - 17, - 306, - 307, - 375, - 387, - 388, - 260, - 286, - 414, - 398, - 335, - 406, - 418, - 364, - 367, - 416, - 423, - 358, - 327, - 251, - 284, - 298, - 281, - 5, - 4, - 373, - 374, - 253, - 307, - 320, - 321, - 425, - 427, - 411, - 421, - 313, - 18, - 321, - 405, - 406, - 320, - 404, - 405, - 315, - 16, - 17, - 426, - 425, - 266, - 377, - 400, - 369, - 322, - 391, - 269, - 417, - 465, - 464, - 386, - 257, - 258, - 466, - 260, - 388, - 456, - 399, - 419, - 284, - 332, - 333, - 417, - 285, - 8, - 346, - 340, - 261, - 413, - 441, - 285, - 327, - 460, - 328, - 355, - 371, - 329, - 392, - 439, - 438, - 382, - 341, - 256, - 429, - 420, - 360, - 364, - 394, - 379, - 277, - 343, - 437, - 443, - 444, - 283, - 275, - 440, - 363, - 431, - 262, - 369, - 297, - 338, - 337, - 273, - 375, - 321, - 450, - 451, - 349, - 446, - 342, - 467, - 293, - 334, - 282, - 458, - 461, - 462, - 276, - 353, - 383, - 308, - 324, - 325, - 276, - 300, - 293, - 372, - 345, - 447, - 382, - 398, - 362, - 352, - 345, - 340, - 274, - 1, - 19, - 456, - 248, - 281, - 436, - 427, - 425, - 381, - 256, - 252, - 269, - 391, - 393, - 200, - 199, - 428, - 266, - 330, - 329, - 287, - 273, - 422, - 250, - 462, - 328, - 258, - 286, - 384, - 265, - 353, - 342, - 387, - 259, - 257, - 424, - 431, - 430, - 342, - 353, - 276, - 273, - 335, - 424, - 292, - 325, - 307, - 366, - 447, - 345, - 271, - 303, - 302, - 423, - 266, - 371, - 294, - 455, - 460, - 279, - 278, - 294, - 271, - 272, - 304, - 432, - 434, - 427, - 272, - 407, - 408, - 394, - 430, - 431, - 395, - 369, - 400, - 334, - 333, - 299, - 351, - 417, - 168, - 352, - 280, - 411, - 325, - 319, - 320, - 295, - 296, - 336, - 319, - 403, - 404, - 330, - 348, - 349, - 293, - 298, - 333, - 323, - 454, - 447, - 15, - 16, - 315, - 358, - 429, - 279, - 14, - 15, - 316, - 285, - 336, - 9, - 329, - 349, - 350, - 374, - 380, - 252, - 318, - 402, - 403, - 6, - 197, - 419, - 318, - 319, - 325, - 367, - 364, - 365, - 435, - 367, - 397, - 344, - 438, - 439, - 272, - 271, - 311, - 195, - 5, - 281, - 273, - 287, - 291, - 396, - 428, - 199, - 311, - 271, - 268, - 283, - 444, - 445, - 373, - 254, - 339, - 263, - 466, - 249, - 282, - 334, - 296, - 449, - 347, - 346, - 264, - 447, - 454, - 336, - 296, - 299, - 338, - 10, - 151, - 278, - 439, - 455, - 292, - 407, - 415, - 358, - 371, - 355, - 340, - 345, - 372, - 390, - 249, - 466, - 346, - 347, - 280, - 442, - 443, - 282, - 19, - 94, - 370, - 441, - 442, - 295, - 248, - 419, - 197, - 263, - 255, - 359, - 440, - 275, - 274, - 300, - 383, - 368, - 351, - 412, - 465, - 263, - 467, - 466, - 301, - 368, - 389, - 380, - 374, - 386, - 395, - 378, - 379, - 412, - 351, - 419, - 436, - 426, - 322, - 373, - 390, - 388, - 2, - 164, - 393, - 370, - 462, - 461, - 164, - 0, - 267, - 302, - 11, - 12, - 374, - 373, - 387, - 268, - 12, - 13, - 293, - 300, - 301, - 446, - 261, - 340, - 385, - 384, - 381, - 330, - 266, - 425, - 426, - 423, - 391, - 429, - 355, - 437, - 391, - 327, - 326, - 440, - 457, - 438, - 341, - 382, - 362, - 459, - 457, - 461, - 434, - 430, - 394, - 414, - 463, - 362, - 396, - 369, - 262, - 354, - 461, - 457, - 316, - 403, - 402, - 315, - 404, - 403, - 314, - 405, - 404, - 313, - 406, - 405, - 421, - 418, - 406, - 366, - 401, - 361, - 306, - 408, - 407, - 291, - 409, - 408, - 287, - 410, - 409, - 432, - 436, - 410, - 434, - 416, - 411, - 264, - 368, - 383, - 309, - 438, - 457, - 352, - 376, - 401, - 274, - 275, - 4, - 421, - 428, - 262, - 294, - 327, - 358, - 433, - 416, - 367, - 289, - 455, - 439, - 462, - 370, - 326, - 2, - 326, - 370, - 305, - 460, - 455, - 254, - 449, - 448, - 255, - 261, - 446, - 253, - 450, - 449, - 252, - 451, - 450, - 256, - 452, - 451, - 341, - 453, - 452, - 413, - 464, - 463, - 441, - 413, - 414, - 258, - 442, - 441, - 257, - 443, - 442, - 259, - 444, - 443, - 260, - 445, - 444, - 467, - 342, - 445, - 459, - 458, - 250, - 289, - 392, - 290, - 290, - 328, - 460, - 376, - 433, - 435, - 250, - 290, - 392, - 411, - 416, - 433, - 341, - 463, - 464, - 453, - 464, - 465, - 357, - 465, - 412, - 343, - 412, - 399, - 360, - 363, - 440, - 437, - 399, - 456, - 420, - 456, - 363, - 401, - 435, - 288, - 372, - 383, - 353, - 339, - 255, - 249, - 448, - 261, - 255, - 133, - 243, - 190, - 133, - 155, - 112, - 33, - 246, - 247, - 33, - 130, - 25, - 398, - 384, - 286, - 362, - 398, - 414, - 362, - 463, - 341, - 263, - 359, - 467, - 263, - 249, - 255, - 466, - 467, - 260, - 75, - 60, - 166, - 238, - 239, - 79, - 162, - 127, - 139, - 72, - 11, - 37, - 121, - 232, - 120, - 73, - 72, - 39, - 114, - 128, - 47, - 233, - 232, - 128, - 103, - 104, - 67, - 152, - 175, - 148, - 173, - 157, - 155, - 119, - 118, - 101, - 74, - 73, - 40, - 107, - 9, - 108, - 49, - 48, - 131, - 32, - 194, - 211, - 184, - 74, - 185, - 191, - 80, - 183, - 185, - 40, - 186, - 119, - 230, - 118, - 210, - 202, - 214, - 84, - 83, - 17, - 77, - 76, - 146, - 161, - 160, - 30, - 190, - 56, - 173, - 182, - 106, - 194, - 138, - 135, - 192, - 129, - 203, - 98, - 54, - 21, - 68, - 5, - 51, - 4, - 145, - 144, - 23, - 90, - 77, - 91, - 207, - 205, - 187, - 83, - 201, - 18, - 181, - 91, - 182, - 180, - 90, - 181, - 16, - 85, - 17, - 205, - 206, - 36, - 176, - 148, - 140, - 165, - 92, - 39, - 245, - 193, - 244, - 27, - 159, - 28, - 30, - 247, - 161, - 174, - 236, - 196, - 103, - 54, - 104, - 55, - 193, - 8, - 111, - 117, - 31, - 221, - 189, - 55, - 240, - 98, - 99, - 142, - 126, - 100, - 219, - 166, - 218, - 112, - 155, - 26, - 198, - 209, - 131, - 169, - 135, - 150, - 114, - 47, - 217, - 224, - 223, - 53, - 220, - 45, - 134, - 32, - 211, - 140, - 109, - 67, - 108, - 146, - 43, - 91, - 231, - 230, - 120, - 113, - 226, - 247, - 105, - 63, - 52, - 241, - 238, - 242, - 124, - 46, - 156, - 95, - 78, - 96, - 70, - 46, - 63, - 116, - 143, - 227, - 116, - 123, - 111, - 1, - 44, - 19, - 3, - 236, - 51, - 207, - 216, - 205, - 26, - 154, - 22, - 165, - 39, - 167, - 199, - 200, - 208, - 101, - 36, - 100, - 43, - 57, - 202, - 242, - 20, - 99, - 56, - 28, - 157, - 124, - 35, - 113, - 29, - 160, - 27, - 211, - 204, - 210, - 124, - 113, - 46, - 106, - 43, - 204, - 96, - 62, - 77, - 227, - 137, - 116, - 73, - 41, - 72, - 36, - 203, - 142, - 235, - 64, - 240, - 48, - 49, - 64, - 42, - 41, - 74, - 214, - 212, - 207, - 183, - 42, - 184, - 210, - 169, - 211, - 140, - 170, - 176, - 104, - 105, - 69, - 193, - 122, - 168, - 50, - 123, - 187, - 89, - 96, - 90, - 66, - 65, - 107, - 179, - 89, - 180, - 119, - 101, - 120, - 68, - 63, - 104, - 234, - 93, - 227, - 16, - 15, - 85, - 209, - 129, - 49, - 15, - 14, - 86, - 107, - 55, - 9, - 120, - 100, - 121, - 153, - 145, - 22, - 178, - 88, - 179, - 197, - 6, - 196, - 89, - 88, - 96, - 135, - 138, - 136, - 138, - 215, - 172, - 218, - 115, - 219, - 41, - 42, - 81, - 5, - 195, - 51, - 57, - 43, - 61, - 208, - 171, - 199, - 41, - 81, - 38, - 224, - 53, - 225, - 24, - 144, - 110, - 105, - 52, - 66, - 118, - 229, - 117, - 227, - 34, - 234, - 66, - 107, - 69, - 10, - 109, - 151, - 219, - 48, - 235, - 183, - 62, - 191, - 142, - 129, - 126, - 116, - 111, - 143, - 7, - 163, - 246, - 118, - 117, - 50, - 223, - 222, - 52, - 94, - 19, - 141, - 222, - 221, - 65, - 196, - 3, - 197, - 45, - 220, - 44, - 156, - 70, - 139, - 188, - 122, - 245, - 139, - 71, - 162, - 145, - 153, - 159, - 149, - 170, - 150, - 122, - 188, - 196, - 206, - 216, - 92, - 163, - 144, - 161, - 164, - 2, - 167, - 242, - 141, - 241, - 0, - 164, - 37, - 11, - 72, - 12, - 144, - 145, - 160, - 12, - 38, - 13, - 70, - 63, - 71, - 31, - 226, - 111, - 157, - 158, - 154, - 36, - 101, - 205, - 203, - 206, - 165, - 126, - 209, - 217, - 98, - 165, - 97, - 237, - 220, - 218, - 237, - 239, - 241, - 210, - 214, - 169, - 140, - 171, - 32, - 241, - 125, - 237, - 179, - 86, - 178, - 180, - 85, - 179, - 181, - 84, - 180, - 182, - 83, - 181, - 194, - 201, - 182, - 177, - 137, - 132, - 184, - 76, - 183, - 185, - 61, - 184, - 186, - 57, - 185, - 216, - 212, - 186, - 192, - 214, - 187, - 139, - 34, - 156, - 218, - 79, - 237, - 147, - 123, - 177, - 45, - 44, - 4, - 208, - 201, - 32, - 98, - 64, - 129, - 192, - 213, - 138, - 235, - 59, - 219, - 141, - 242, - 97, - 97, - 2, - 141, - 240, - 75, - 235, - 229, - 24, - 228, - 31, - 25, - 226, - 230, - 23, - 229, - 231, - 22, - 230, - 232, - 26, - 231, - 233, - 112, - 232, - 244, - 189, - 243, - 189, - 221, - 190, - 222, - 28, - 221, - 223, - 27, - 222, - 224, - 29, - 223, - 225, - 30, - 224, - 113, - 247, - 225, - 99, - 60, - 240, - 213, - 147, - 215, - 60, - 20, - 166, - 192, - 187, - 213, - 243, - 112, - 244, - 244, - 233, - 245, - 245, - 128, - 188, - 188, - 114, - 174, - 134, - 131, - 220, - 174, - 217, - 236, - 236, - 198, - 134, - 215, - 177, - 58, - 156, - 143, - 124, - 25, - 110, - 7, - 31, - 228, - 25, - 264, - 356, - 368, - 0, - 11, - 267, - 451, - 452, - 349, - 267, - 302, - 269, - 350, - 357, - 277, - 350, - 452, - 357, - 299, - 333, - 297, - 396, - 175, - 377, - 381, - 384, - 382, - 280, - 347, - 330, - 269, - 303, - 270, - 151, - 9, - 337, - 344, - 278, - 360, - 424, - 418, - 431, - 270, - 304, - 409, - 272, - 310, - 407, - 322, - 270, - 410, - 449, - 450, - 347, - 432, - 422, - 434, - 18, - 313, - 17, - 291, - 306, - 375, - 259, - 387, - 260, - 424, - 335, - 418, - 434, - 364, - 416, - 391, - 423, - 327, - 301, - 251, - 298, - 275, - 281, - 4, - 254, - 373, - 253, - 375, - 307, - 321, - 280, - 425, - 411, - 200, - 421, - 18, - 335, - 321, - 406, - 321, - 320, - 405, - 314, - 315, - 17, - 423, - 426, - 266, - 396, - 377, - 369, - 270, - 322, - 269, - 413, - 417, - 464, - 385, - 386, - 258, - 248, - 456, - 419, - 298, - 284, - 333, - 168, - 417, - 8, - 448, - 346, - 261, - 417, - 413, - 285, - 326, - 327, - 328, - 277, - 355, - 329, - 309, - 392, - 438, - 381, - 382, - 256, - 279, - 429, - 360, - 365, - 364, - 379, - 355, - 277, - 437, - 282, - 443, - 283, - 281, - 275, - 363, - 395, - 431, - 369, - 299, - 297, - 337, - 335, - 273, - 321, - 348, - 450, - 349, - 359, - 446, - 467, - 283, - 293, - 282, - 250, - 458, - 462, - 300, - 276, - 383, - 292, - 308, - 325, - 283, - 276, - 293, - 264, - 372, - 447, - 346, - 352, - 340, - 354, - 274, - 19, - 363, - 456, - 281, - 426, - 436, - 425, - 380, - 381, - 252, - 267, - 269, - 393, - 421, - 200, - 428, - 371, - 266, - 329, - 432, - 287, - 422, - 290, - 250, - 328, - 385, - 258, - 384, - 446, - 265, - 342, - 386, - 387, - 257, - 422, - 424, - 430, - 445, - 342, - 276, - 422, - 273, - 424, - 306, - 292, - 307, - 352, - 366, - 345, - 268, - 271, - 302, - 358, - 423, - 371, - 327, - 294, - 460, - 331, - 279, - 294, - 303, - 271, - 304, - 436, - 432, - 427, - 304, - 272, - 408, - 395, - 394, - 431, - 378, - 395, - 400, - 296, - 334, - 299, - 6, - 351, - 168, - 376, - 352, - 411, - 307, - 325, - 320, - 285, - 295, - 336, - 320, - 319, - 404, - 329, - 330, - 349, - 334, - 293, - 333, - 366, - 323, - 447, - 316, - 15, - 315, - 331, - 358, - 279, - 317, - 14, - 316, - 8, - 285, - 9, - 277, - 329, - 350, - 253, - 374, - 252, - 319, - 318, - 403, - 351, - 6, - 419, - 324, - 318, - 325, - 397, - 367, - 365, - 288, - 435, - 397, - 278, - 344, - 439, - 310, - 272, - 311, - 248, - 195, - 281, - 375, - 273, - 291, - 175, - 396, - 199, - 312, - 311, - 268, - 276, - 283, - 445, - 390, - 373, - 339, - 295, - 282, - 296, - 448, - 449, - 346, - 356, - 264, - 454, - 337, - 336, - 299, - 337, - 338, - 151, - 294, - 278, - 455, - 308, - 292, - 415, - 429, - 358, - 355, - 265, - 340, - 372, - 388, - 390, - 466, - 352, - 346, - 280, - 295, - 442, - 282, - 354, - 19, - 370, - 285, - 441, - 295, - 195, - 248, - 197, - 457, - 440, - 274, - 301, - 300, - 368, - 417, - 351, - 465, - 251, - 301, - 389, - 385, - 380, - 386, - 394, - 395, - 379, - 399, - 412, - 419, - 410, - 436, - 322, - 387, - 373, - 388, - 326, - 2, - 393, - 354, - 370, - 461, - 393, - 164, - 267, - 268, - 302, - 12, - 386, - 374, - 387, - 312, - 268, - 13, - 298, - 293, - 301, - 265, - 446, - 340, - 380, - 385, - 381, - 280, - 330, - 425, - 322, - 426, - 391, - 420, - 429, - 437, - 393, - 391, - 326, - 344, - 440, - 438, - 458, - 459, - 461, - 364, - 434, - 394, - 428, - 396, - 262, - 274, - 354, - 457, - 317, - 316, - 402, - 316, - 315, - 403, - 315, - 314, - 404, - 314, - 313, - 405, - 313, - 421, - 406, - 323, - 366, - 361, - 292, - 306, - 407, - 306, - 291, - 408, - 291, - 287, - 409, - 287, - 432, - 410, - 427, - 434, - 411, - 372, - 264, - 383, - 459, - 309, - 457, - 366, - 352, - 401, - 1, - 274, - 4, - 418, - 421, - 262, - 331, - 294, - 358, - 435, - 433, - 367, - 392, - 289, - 439, - 328, - 462, - 326, - 94, - 2, - 370, - 289, - 305, - 455, - 339, - 254, - 448, - 359, - 255, - 446, - 254, - 253, - 449, - 253, - 252, - 450, - 252, - 256, - 451, - 256, - 341, - 452, - 414, - 413, - 463, - 286, - 441, - 414, - 286, - 258, - 441, - 258, - 257, - 442, - 257, - 259, - 443, - 259, - 260, - 444, - 260, - 467, - 445, - 309, - 459, - 250, - 305, - 289, - 290, - 305, - 290, - 460, - 401, - 376, - 435, - 309, - 250, - 392, - 376, - 411, - 433, - 453, - 341, - 464, - 357, - 453, - 465, - 343, - 357, - 412, - 437, - 343, - 399, - 344, - 360, - 440, - 420, - 437, - 456, - 360, - 420, - 363, - 361, - 401, - 288, - 265, - 372, - 353, - 390, - 339, - 249, - 339, - 448, - 255 -]; -var VTX68 = [ - 127, - 234, - 132, - 58, - 172, - 150, - 149, - 148, - 152, - 377, - 378, - 379, - 397, - 288, - 361, - 454, - 356, - 70, - 63, - 105, - 66, - 107, - 336, - 296, - 334, - 293, - 300, - 168, - 6, - 195, - 4, - 98, - 97, - 2, - 326, - 327, - 33, - 160, - 158, - 133, - 153, - 144, - 362, - 385, - 387, - 263, - 373, - 380, - 57, - 40, - 37, - 0, - 267, - 270, - 287, - 321, - 314, - 17, - 84, - 91, - 78, - 81, - 13, - 311, - 308, - 402, - 14, - 178 -]; -var VTX33 = [33, 133, 362, 263, 1, 62, 308, 159, 145, 386, 374, 6, 102, 331, 2, 13, 14, 70, 105, 107, 336, 334, 300, 54, 10, 284, 50, 280, 234, 454, 58, 288, 152]; -var VTX7 = [33, 133, 362, 263, 1, 78, 308]; -var UV68 = VTX68.map((x) => UV468[x]); -var UV33 = VTX33.map((x) => UV468[x]); -var UV7 = VTX7.map((x) => UV468[x]); -function connectionsToIndices(connections) { - const indices = connections.map((connection) => connection[0]); - indices.push(connections[connections.length - 1][1]); - return indices; -} -var pairsLips = [ - [61, 146], - [146, 91], - [91, 181], - [181, 84], - [84, 17], - [17, 314], - [314, 405], - [405, 321], - [321, 375], - [375, 291], - [61, 185], - [185, 40], - [40, 39], - [39, 37], - [37, 0], - [0, 267], - [267, 269], - [269, 270], - [270, 409], - [409, 291], - [78, 95], - [95, 88], - [88, 178], - [178, 87], - [87, 14], - [14, 317], - [317, 402], - [402, 318], - [318, 324], - [324, 308], - [78, 191], - [191, 80], - [80, 81], - [81, 82], - [82, 13], - [13, 312], - [312, 311], - [311, 310], - [310, 415], - [415, 308] -]; -var pairsLeftEye = [[263, 249], [249, 390], [390, 373], [373, 374], [374, 380], [380, 381], [381, 382], [382, 362], [263, 466], [466, 388], [388, 387], [387, 386], [386, 385], [385, 384], [384, 398], [398, 362]]; -var pairsLeftEyebrow = [[276, 283], [283, 282], [282, 295], [295, 285], [300, 293], [293, 334], [334, 296], [296, 336]]; -var pairsLeftIris = [[474, 475], [475, 476], [476, 477], [477, 474]]; -var pairsRightEye = [[33, 7], [7, 163], [163, 144], [144, 145], [145, 153], [153, 154], [154, 155], [155, 133], [33, 246], [246, 161], [161, 160], [160, 159], [159, 158], [158, 157], [157, 173], [173, 133]]; -var pairsRightEyebrow = [[46, 53], [53, 52], [52, 65], [65, 55], [70, 63], [63, 105], [105, 66], [66, 107]]; -var pairsRightIris = [[469, 470], [470, 471], [471, 472], [472, 469]]; -var pairsFaceContour = [ - [10, 338], - [338, 297], - [297, 332], - [332, 284], - [284, 251], - [251, 389], - [389, 356], - [356, 454], - [454, 323], - [323, 361], - [361, 288], - [288, 397], - [397, 365], - [365, 379], - [379, 378], - [378, 400], - [400, 377], - [377, 152], - [152, 148], - [148, 176], - [176, 149], - [149, 150], - [150, 136], - [136, 172], - [172, 58], - [58, 132], - [132, 93], - [93, 234], - [234, 127], - [127, 162], - [162, 21], - [21, 54], - [54, 103], - [103, 67], - [67, 109], - [109, 10] -]; -var contourKeypoints = { - lips: connectionsToIndices(pairsLips), - leftEye: connectionsToIndices(pairsLeftEye), - leftEyebrow: connectionsToIndices(pairsLeftEyebrow), - leftIris: connectionsToIndices(pairsLeftIris), - rightEye: connectionsToIndices(pairsRightEye), - rightEyebrow: connectionsToIndices(pairsRightEyebrow), - rightIris: connectionsToIndices(pairsRightIris), - faceOval: connectionsToIndices(pairsFaceContour) -}; - -// src/face/constants.ts -var LIPS_CONNECTIONS = [ - [61, 146], - [146, 91], - [91, 181], - [181, 84], - [84, 17], - [17, 314], - [314, 405], - [405, 321], - [321, 375], - [375, 291], - [61, 185], - [185, 40], - [40, 39], - [39, 37], - [37, 0], - [0, 267], - [267, 269], - [269, 270], - [270, 409], - [409, 291], - [78, 95], - [95, 88], - [88, 178], - [178, 87], - [87, 14], - [14, 317], - [317, 402], - [402, 318], - [318, 324], - [324, 308], - [78, 191], - [191, 80], - [80, 81], - [81, 82], - [82, 13], - [13, 312], - [312, 311], - [311, 310], - [310, 415], - [415, 308] -]; -var LEFT_EYE_CONNECTIONS = [[263, 249], [249, 390], [390, 373], [373, 374], [374, 380], [380, 381], [381, 382], [382, 362], [263, 466], [466, 388], [388, 387], [387, 386], [386, 385], [385, 384], [384, 398], [398, 362]]; -var LEFT_EYEBROW_CONNECTIONS = [[276, 283], [283, 282], [282, 295], [295, 285], [300, 293], [293, 334], [334, 296], [296, 336]]; -var LEFT_IRIS_CONNECTIONS = [[474, 475], [475, 476], [476, 477], [477, 474]]; -var RIGHT_EYE_CONNECTIONS = [[33, 7], [7, 163], [163, 144], [144, 145], [145, 153], [153, 154], [154, 155], [155, 133], [33, 246], [246, 161], [161, 160], [160, 159], [159, 158], [158, 157], [157, 173], [173, 133]]; -var RIGHT_EYEBROW_CONNECTIONS = [[46, 53], [53, 52], [52, 65], [65, 55], [70, 63], [63, 105], [105, 66], [66, 107]]; -var RIGHT_IRIS_CONNECTIONS = [[469, 470], [470, 471], [471, 472], [472, 469]]; -var FACE_OVAL_CONNECTIONS = [ - [10, 338], - [338, 297], - [297, 332], - [332, 284], - [284, 251], - [251, 389], - [389, 356], - [356, 454], - [454, 323], - [323, 361], - [361, 288], - [288, 397], - [397, 365], - [365, 379], - [379, 378], - [378, 400], - [400, 377], - [377, 152], - [152, 148], - [148, 176], - [176, 149], - [149, 150], - [150, 136], - [136, 172], - [172, 58], - [58, 132], - [132, 93], - [93, 234], - [234, 127], - [127, 162], - [162, 21], - [21, 54], - [54, 103], - [103, 67], - [67, 109], - [109, 10] -]; -function connectionsToIndices2(connections) { - const indices = connections.map((connection) => connection[0]); - indices.push(connections[connections.length - 1][1]); - return indices; -} -var MEDIAPIPE_FACE_MESH_KEYPOINTS_BY_CONTOUR = { - lips: connectionsToIndices2(LIPS_CONNECTIONS), - leftEye: connectionsToIndices2(LEFT_EYE_CONNECTIONS), - leftEyebrow: connectionsToIndices2(LEFT_EYEBROW_CONNECTIONS), - leftIris: connectionsToIndices2(LEFT_IRIS_CONNECTIONS), - rightEye: connectionsToIndices2(RIGHT_EYE_CONNECTIONS), - rightEyebrow: connectionsToIndices2(RIGHT_EYEBROW_CONNECTIONS), - rightIris: connectionsToIndices2(RIGHT_IRIS_CONNECTIONS), - faceOval: connectionsToIndices2(FACE_OVAL_CONNECTIONS) -}; -var indexLabelPairs = Object.entries(MEDIAPIPE_FACE_MESH_KEYPOINTS_BY_CONTOUR).map(([label, indices]) => indices.map((index2) => [index2, label])).flat(); -var MEDIAPIPE_FACE_MESH_KEYPOINTS = new Map(indexLabelPairs); -var LANDMARKS_REFINEMENT_LIPS_CONFIG = [ - 61, - 146, - 91, - 181, - 84, - 17, - 314, - 405, - 321, - 375, - 291, - 185, - 40, - 39, - 37, - 0, - 267, - 269, - 270, - 409, - 78, - 95, - 88, - 178, - 87, - 14, - 317, - 402, - 318, - 324, - 308, - 191, - 80, - 81, - 82, - 13, - 312, - 311, - 310, - 415, - 76, - 77, - 90, - 180, - 85, - 16, - 315, - 404, - 320, - 307, - 306, - 184, - 74, - 73, - 72, - 11, - 302, - 303, - 304, - 408, - 62, - 96, - 89, - 179, - 86, - 15, - 316, - 403, - 319, - 325, - 292, - 183, - 42, - 41, - 38, - 12, - 268, - 271, - 272, - 407 -]; -var LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG = [ - 33, - 7, - 163, - 144, - 145, - 153, - 154, - 155, - 133, - 246, - 161, - 160, - 159, - 158, - 157, - 173, - 130, - 25, - 110, - 24, - 23, - 22, - 26, - 112, - 243, - 247, - 30, - 29, - 27, - 28, - 56, - 190, - 226, - 31, - 228, - 229, - 230, - 231, - 232, - 233, - 244, - 113, - 225, - 224, - 223, - 222, - 221, - 189, - 35, - 124, - 46, - 53, - 52, - 65, - 143, - 111, - 117, - 118, - 119, - 120, - 121, - 128, - 245, - 156, - 70, - 63, - 105, - 66, - 107, - 55, - 193 -]; -var LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG = [ - 263, - 249, - 390, - 373, - 374, - 380, - 381, - 382, - 362, - 466, - 388, - 387, - 386, - 385, - 384, - 398, - 359, - 255, - 339, - 254, - 253, - 252, - 256, - 341, - 463, - 467, - 260, - 259, - 257, - 258, - 286, - 414, - 446, - 261, - 448, - 449, - 450, - 451, - 452, - 453, - 464, - 342, - 445, - 444, - 443, - 442, - 441, - 413, - 265, - 353, - 276, - 283, - 282, - 295, - 372, - 340, - 346, - 347, - 348, - 349, - 350, - 357, - 465, - 383, - 300, - 293, - 334, - 296, - 336, - 285, - 417 -]; - -// src/draw/face.ts -var localOptions; -function drawLabels(f, ctx) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i; - if (!localOptions.drawLabels || ((_a = localOptions.faceLabels) == null ? void 0 : _a.length) === 0) - return; - let l = localOptions.faceLabels.slice(); - if (f.score) - l = replace(l, "[score]", 100 * f.score); - if (f.gender) - l = replace(l, "[gender]", f.gender); - if (f.genderScore) - l = replace(l, "[genderScore]", 100 * f.genderScore); - if (f.age) - l = replace(l, "[age]", f.age); - if (f.distance) - l = replace(l, "[distance]", 100 * f.distance); - if (f.real) - l = replace(l, "[real]", 100 * f.real); - if (f.live) - l = replace(l, "[live]", 100 * f.live); - if (f.emotion && f.emotion.length > 0) { - const emotion2 = f.emotion.map((a) => `${Math.trunc(100 * a.score)}% ${a.emotion}`); - if (emotion2.length > 3) - emotion2.length = 3; - l = replace(l, "[emotions]", emotion2.join(" ")); - } - if ((_c = (_b = f.rotation) == null ? void 0 : _b.angle) == null ? void 0 : _c.roll) - l = replace(l, "[roll]", rad2deg(f.rotation.angle.roll)); - if ((_e = (_d = f.rotation) == null ? void 0 : _d.angle) == null ? void 0 : _e.yaw) - l = replace(l, "[yaw]", rad2deg(f.rotation.angle.yaw)); - if ((_g = (_f = f.rotation) == null ? void 0 : _f.angle) == null ? void 0 : _g.pitch) - l = replace(l, "[pitch]", rad2deg(f.rotation.angle.pitch)); - if ((_i = (_h = f.rotation) == null ? void 0 : _h.gaze) == null ? void 0 : _i.bearing) - l = replace(l, "[gaze]", rad2deg(f.rotation.gaze.bearing)); - labels(ctx, l, f.box[0], f.box[1], localOptions); -} -function drawIrisElipse(f, ctx) { - var _a, _b, _c, _d; - if (((_a = f.annotations) == null ? void 0 : _a.leftEyeIris) && ((_b = f.annotations) == null ? void 0 : _b.leftEyeIris[0])) { - ctx.strokeStyle = localOptions.useDepth ? "rgba(255, 200, 255, 0.3)" : localOptions.color; - ctx.beginPath(); - const sizeX = Math.abs(f.annotations.leftEyeIris[3][0] - f.annotations.leftEyeIris[1][0]) / 2; - const sizeY = Math.abs(f.annotations.leftEyeIris[4][1] - f.annotations.leftEyeIris[2][1]) / 2; - ctx.ellipse(f.annotations.leftEyeIris[0][0], f.annotations.leftEyeIris[0][1], sizeX, sizeY, 0, 0, 2 * Math.PI); - ctx.stroke(); - if (localOptions.fillPolygons) { - ctx.fillStyle = localOptions.useDepth ? "rgba(255, 255, 200, 0.3)" : localOptions.color; - ctx.fill(); - } - } - if (((_c = f.annotations) == null ? void 0 : _c.rightEyeIris) && ((_d = f.annotations) == null ? void 0 : _d.rightEyeIris[0])) { - ctx.strokeStyle = localOptions.useDepth ? "rgba(255, 200, 255, 0.3)" : localOptions.color; - ctx.beginPath(); - const sizeX = Math.abs(f.annotations.rightEyeIris[3][0] - f.annotations.rightEyeIris[1][0]) / 2; - const sizeY = Math.abs(f.annotations.rightEyeIris[4][1] - f.annotations.rightEyeIris[2][1]) / 2; - ctx.ellipse(f.annotations.rightEyeIris[0][0], f.annotations.rightEyeIris[0][1], sizeX, sizeY, 0, 0, 2 * Math.PI); - ctx.stroke(); - if (localOptions.fillPolygons) { - ctx.fillStyle = localOptions.useDepth ? "rgba(255, 255, 200, 0.3)" : localOptions.color; - ctx.fill(); - } - } -} -function drawGazeSpheres(f, ctx) { - var _a; - if (localOptions.drawGaze && ((_a = f.rotation) == null ? void 0 : _a.angle) && typeof Path2D !== "undefined") { - ctx.strokeStyle = "pink"; - const valX = f.box[0] + f.box[2] / 2 - f.box[3] * rad2deg(f.rotation.angle.yaw) / 90; - const valY = f.box[1] + f.box[3] / 2 + f.box[2] * rad2deg(f.rotation.angle.pitch) / 90; - const pathV = new Path2D(` - M ${f.box[0] + f.box[2] / 2} ${f.box[1]} +`;var Yt=(e,t,n)=>{let o=new RegExp("\\b"+t+" \\w+ (\\w+)","ig");e.replace(o,(r,s)=>(n[s]=0,r))},Kt=class{constructor(t,n,o){k(this,"uniform",{});k(this,"attribute",{});k(this,"gl");k(this,"id");k(this,"compile",(t,n)=>{let o=this.gl.createShader(n);return o?(this.gl.shaderSource(o,t),this.gl.compileShader(o),this.gl.getShaderParameter(o,this.gl.COMPILE_STATUS)?o:(u(`filter: gl compile failed: ${this.gl.getShaderInfoLog(o)||"unknown"}`),null)):(u("filter: could not create shader"),null)});this.gl=t;let r=this.compile(n,this.gl.VERTEX_SHADER),s=this.compile(o,this.gl.FRAGMENT_SHADER);if(this.id=this.gl.createProgram(),!(!r||!s)){if(!this.id){u("filter: could not create webgl program");return}if(this.gl.attachShader(this.id,r),this.gl.attachShader(this.id,s),this.gl.linkProgram(this.id),!this.gl.getProgramParameter(this.id,this.gl.LINK_STATUS)){u(`filter: gl link failed: ${this.gl.getProgramInfoLog(this.id)||"unknown"}`);return}this.gl.useProgram(this.id),Yt(n,"attribute",this.attribute);for(let A in this.attribute)this.attribute[A]=this.gl.getAttribLocation(this.id,A);Yt(n,"uniform",this.uniform),Yt(o,"uniform",this.uniform);for(let A in this.uniform)this.uniform[A]=this.gl.getUniformLocation(this.id,A)}}};function C1(){let e=0,t=null,n=!1,o=-1,r=[null,null],s=[],A=null,a=null,l=te(100,100),c={},x={INTERMEDIATE:1},i=l.getContext("webgl");if(!i){u("filter: cannot get webgl context");return}this.gl=i;function y(T,m){if(!(T===l.width&&m===l.height)){if(l.width=T,l.height=m,!A){let h=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]);A=i.createBuffer(),i.bindBuffer(i.ARRAY_BUFFER,A),i.bufferData(i.ARRAY_BUFFER,h,i.STATIC_DRAW),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0)}i.viewport(0,0,l.width,l.height),r=[null,null]}}function d(T,m){let h=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,h);let S=i.createRenderbuffer();i.bindRenderbuffer(i.RENDERBUFFER,S);let P=i.createTexture();return i.bindTexture(i.TEXTURE_2D,P),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,T,m,0,i.RGBA,i.UNSIGNED_BYTE,null),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,P,0),i.bindTexture(i.TEXTURE_2D,null),i.bindFramebuffer(i.FRAMEBUFFER,null),{fbo:h,texture:P}}function p(T){return r[T]=r[T]||d(l.width,l.height),r[T]}function f(T=0){if(!a)return;let m=null,h=null,S=!1;e===0?m=t:m=p(o).texture||null,e++,n&&!(T&x.INTERMEDIATE)?(h=null,S=e%2===0):(o=(o+1)%2,h=p(o).fbo||null),i.bindTexture(i.TEXTURE_2D,m),i.bindFramebuffer(i.FRAMEBUFFER,h),i.uniform1f(a.uniform.flipY,S?-1:1),i.drawArrays(i.TRIANGLES,0,6)}function b(T){if(c[T])return a=c[T],i.useProgram((a?a.id:null)||null),a;if(a=new Kt(i,S1,T),!a)return u("filter: could not get webgl program"),null;let m=Float32Array.BYTES_PER_ELEMENT,h=4*m;return i.enableVertexAttribArray(a.attribute.pos),i.vertexAttribPointer(a.attribute.pos,2,i.FLOAT,!1,h,0*m),i.enableVertexAttribArray(a.attribute.uv),i.vertexAttribPointer(a.attribute.uv,2,i.FLOAT,!1,h,2*m),c[T]=a,a}let M={colorMatrix:T=>{let m=new Float32Array(T);m[4]/=255,m[9]/=255,m[14]/=255,m[19]/=255;let h=m[18]===1&&m[3]===0&&m[8]===0&&m[13]===0&&m[15]===0&&m[16]===0&&m[17]===0&&m[19]===0?N1:j1,S=b(h);!S||(i.uniform1fv(S.uniform.m,m),f())},brightness:T=>{let m=(T||0)+1;M.colorMatrix([m,0,0,0,0,0,m,0,0,0,0,0,m,0,0,0,0,0,1,0])},saturation:T=>{let m=(T||0)*2/3+1,h=(m-1)*-.5;M.colorMatrix([m,h,h,0,0,h,m,h,0,0,h,h,m,0,0,0,0,0,1,0])},desaturate:()=>{M.saturation(-1)},contrast:T=>{let m=(T||0)+1,h=-128*(m-1);M.colorMatrix([m,0,0,0,h,0,m,0,0,h,0,0,m,0,h,0,0,0,1,0])},negative:()=>{M.contrast(-2)},hue:T=>{T=(T||0)/180*Math.PI;let m=Math.cos(T),h=Math.sin(T),S=.213,P=.715,I=.072;M.colorMatrix([S+m*(1-S)+h*-S,P+m*-P+h*-P,I+m*-I+h*(1-I),0,0,S+m*-S+h*.143,P+m*(1-P)+h*.14,I+m*-I+h*-.283,0,0,S+m*-S+h*-(1-S),P+m*-P+h*P,I+m*(1-I)+h*I,0,0,0,0,0,1,0])},desaturateLuminance:()=>{M.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:()=>{M.colorMatrix([.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0])},brownie:()=>{M.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:()=>{M.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:()=>{M.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:()=>{M.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:()=>{M.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:()=>{M.colorMatrix([0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0])},convolution:T=>{let m=new Float32Array(T),h=1/l.width,S=1/l.height,P=b(L1);!P||(i.uniform1fv(P.uniform.m,m),i.uniform2f(P.uniform.px,h,S),f())},detectEdges:()=>{M.convolution.call(this,[0,1,0,1,-4,1,0,1,0])},sobelX:()=>{M.convolution.call(this,[-1,0,1,-2,0,2,-1,0,1])},sobelY:()=>{M.convolution.call(this,[-1,-2,-1,0,0,0,1,2,1])},sharpen:T=>{let m=T||1;M.convolution.call(this,[0,-1*m,0,-1*m,1+4*m,-1*m,0,-1*m,0])},emboss:T=>{let m=T||1;M.convolution.call(this,[-2*m,-1*m,0,-1*m,1,1*m,0,1*m,2*m])},blur:T=>{let m=T/7/l.width,h=T/7/l.height,S=b(O1);!S||(i.uniform2f(S.uniform.px,0,h),f(x.INTERMEDIATE),i.uniform2f(S.uniform.px,m,0),f())},pixelate:T=>{let m=T/l.width,h=T/l.height,S=b(I1);!S||(i.uniform2f(S.uniform.size,m,h),f())}};this.add=function(T){let m=Array.prototype.slice.call(arguments,1),h=M[T];s.push({func:h,args:m})},this.reset=function(){s=[]},this.get=function(){return s},this.apply=function(T){y(T.width,T.height),e=0,t||(t=i.createTexture()),i.bindTexture(i.TEXTURE_2D,t),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,T);for(let m=0;mx.data())),A=Math.max(s[0][0],s[1][0],s[2][0]),l=(A>1?255:1)/A,c;if(l>1){let x=[Y.sub(n[0],o[0]),Y.sub(n[1],o[1]),Y.sub(n[2],o[2])],i=[Y.sub(r[0],o[0]),Y.sub(r[1],o[1]),Y.sub(r[2],o[2])],y=[Y.mul(x[0],l),Y.mul(x[1],l),Y.mul(x[2],l)],d=Y.stack([y[0],y[1],y[2]],2);c=Y.reshape(d,[1,t.shape[0]||0,t.shape[1]||0,3]),Y.dispose([...x,...i,...y])}else c=Y.expandDims(t,0);return Y.dispose([...n,...o,...r,n,t,e]),c}var V2=3840,v0=null,R0=null,c2=null,e0,J0={inputSum:0,cacheDiff:1,sumMethod:0,inputTensor:void 0};function Jt(){J0.inputSum=0,J0.cacheDiff=1,J0.sumMethod=0,J0.inputTensor=void 0}function te(e,t){let n;if(R.browser)if(R.worker){if(typeof OffscreenCanvas=="undefined")throw new Error("canvas error: attempted to run in web worker but OffscreenCanvas is not supported");n=new OffscreenCanvas(e,t)}else{if(typeof document=="undefined")throw new Error("canvas error: attempted to run in browser but DOM is not defined");n=document.createElement("canvas"),n.width=e,n.height=t}else typeof R.Canvas!="undefined"?n=new R.Canvas(e,t):typeof globalThis.Canvas!="undefined"&&(n=new globalThis.Canvas(e,t));return n}function Z2(e,t){let n=t||te(e.width,e.height);return n.getContext("2d").drawImage(e,0,0),n}async function X2(e,t,n=!0){var y,d,p;if(!e)return t.debug&&u("input error: input is missing"),{tensor:null,canvas:null};if(!(e instanceof N.Tensor)&&!(typeof Image!="undefined"&&e instanceof Image)&&!(typeof globalThis.Canvas!="undefined"&&e instanceof globalThis.Canvas)&&!(typeof ImageData!="undefined"&&e instanceof ImageData)&&!(typeof ImageBitmap!="undefined"&&e instanceof ImageBitmap)&&!(typeof HTMLImageElement!="undefined"&&e instanceof HTMLImageElement)&&!(typeof HTMLMediaElement!="undefined"&&e instanceof HTMLMediaElement)&&!(typeof HTMLVideoElement!="undefined"&&e instanceof HTMLVideoElement)&&!(typeof HTMLCanvasElement!="undefined"&&e instanceof HTMLCanvasElement)&&!(typeof OffscreenCanvas!="undefined"&&e instanceof OffscreenCanvas))throw new Error("input error: type not recognized");if(e instanceof N.Tensor){let f=null;if(e.isDisposedInternal)throw new Error("input error: attempted to use tensor but it is disposed");if(!e.shape)throw new Error("input error: attempted to use tensor without a shape");if(e.shape.length===3){if(e.shape[2]===3)f=N.expandDims(e,0);else if(e.shape[2]===4){let b=N.slice3d(e,[0,0,0],[-1,-1,3]);f=N.expandDims(b,0),N.dispose(b)}}else e.shape.length===4&&(e.shape[3]===3?f=N.clone(e):e.shape[3]===4&&(f=N.slice4d(e,[0,0,0,0],[-1,-1,-1,3])));if(f==null||f.shape.length!==4||f.shape[0]!==1||f.shape[3]!==3)throw new Error(`input error: attempted to use tensor with unrecognized shape: ${e.shape.toString()}`);if(f.dtype==="int32"){let b=N.cast(f,"float32");N.dispose(f),f=b}return{tensor:f,canvas:t.filter.return?R0:null}}if(typeof e.readyState!="undefined"&&e.readyState<=2)return t.debug&&u("input stream is not ready"),{tensor:null,canvas:v0};let o=e.naturalWidth||e.videoWidth||e.width||e.shape&&e.shape[1]>0,r=e.naturalHeight||e.videoHeight||e.height||e.shape&&e.shape[2]>0;if(!o||!r)return t.debug&&u("cannot determine input dimensions"),{tensor:null,canvas:v0};let s=o,A=r;if(s>V2&&(s=V2,A=Math.trunc(s*r/o)),A>V2&&(A=V2,s=Math.trunc(A*o/r)),(((y=t.filter)==null?void 0:y.width)||0)>0?s=t.filter.width:(((d=t.filter)==null?void 0:d.height)||0)>0&&(s=o*((t.filter.height||0)/r)),(t.filter.height||0)>0?A=t.filter.height:(t.filter.width||0)>0&&(A=r*((t.filter.width||0)/o)),!s||!A)throw new Error("input error: cannot determine dimension");(!v0||v0.width!==s||v0.height!==A)&&(v0=te(s,A));let a=v0.getContext("2d");if(typeof ImageData!="undefined"&&e instanceof ImageData?a.putImageData(e,0,0):t.filter.flip&&typeof a.translate!="undefined"?(a.translate(o,0),a.scale(-1,1),a.drawImage(e,0,0,o,r,0,0,v0.width,v0.height),a.setTransform(1,0,0,1,0,0)):a.drawImage(e,0,0,o,r,0,0,v0.width,v0.height),(!R0||v0.width!==R0.width||v0.height!==R0.height)&&(R0=te(v0.width,v0.height)),t.filter.enabled&&R.webgl.supported?(e0||(e0=R.browser?new C1:null),R.filter=!!e0,e0!=null&&e0.add?(e0.reset(),t.filter.brightness!==0&&e0.add("brightness",t.filter.brightness),t.filter.contrast!==0&&e0.add("contrast",t.filter.contrast),t.filter.sharpness!==0&&e0.add("sharpen",t.filter.sharpness),t.filter.blur!==0&&e0.add("blur",t.filter.blur),t.filter.saturation!==0&&e0.add("saturation",t.filter.saturation),t.filter.hue!==0&&e0.add("hue",t.filter.hue),t.filter.negative&&e0.add("negative"),t.filter.sepia&&e0.add("sepia"),t.filter.vintage&&e0.add("brownie"),t.filter.sepia&&e0.add("sepia"),t.filter.kodachrome&&e0.add("kodachrome"),t.filter.technicolor&&e0.add("technicolor"),t.filter.polaroid&&e0.add("polaroid"),t.filter.pixelate!==0&&e0.add("pixelate",t.filter.pixelate),((p=e0.get())==null?void 0:p.length)>1?R0=e0.apply(v0):R0=e0.draw(v0)):(t.debug&&u("input process error: cannot initialize filters"),R.webgl.supported=!1,t.filter.enabled=!1,Z2(v0,R0))):(Z2(v0,R0),e0&&(e0=null),R.filter=!!e0),!n)return{tensor:null,canvas:R0};if(!R0)throw new Error("canvas error: cannot create output");let l,c=3;if(typeof ImageData!="undefined"&&e instanceof ImageData||e.data&&e.width&&e.height)if(R.browser&&N.browser)l=N.browser?N.browser.fromPixels(e):null;else{c=e.data.length/e.height/e.width;let f=new Uint8Array(e.data.buffer);l=N.tensor(f,[e.height,e.width,c],"int32")}else if((!c2||R0.width!==c2.width||R0.height!==c2.height)&&(c2=te(R0.width,R0.height)),N.browser&&R.browser)t.backend==="webgl"||t.backend==="humangl"||t.backend==="webgpu"?l=N.browser.fromPixels(R0):(c2=Z2(R0),l=N.browser.fromPixels(c2));else{let M=Z2(R0).getContext("2d").getImageData(0,0,s,A);c=M.data.length/s/A;let T=new Uint8Array(M.data.buffer);l=N.tensor(T,[s,A,c])}if(c===4){let f=N.slice3d(l,[0,0,0],[-1,-1,3]);N.dispose(l),l=f}if(!l)throw new Error("input error: cannot create tensor");let x=N.cast(l,"float32"),i=t.filter.equalization?await G2(x):N.expandDims(x,0);if(N.dispose([l,x]),t.filter.autoBrightness){let f=N.max(i),b=await f.data();t.filter.brightness=b[0]>1?1-b[0]/255:1-b[0],N.dispose(f)}return{tensor:i,canvas:t.filter.return?R0:null}}async function W1(e,t){let n=!1;if(e.cacheSensitivity===0||!t.shape||t.shape.length!==4||t.shape[1]>3840||t.shape[2]>2160)return n;if(!J0.inputTensor)J0.inputTensor=N.clone(t);else if(J0.inputTensor.shape[1]!==t.shape[1]||J0.inputTensor.shape[2]!==t.shape[2])N.dispose(J0.inputTensor),J0.inputTensor=N.clone(t);else{let o={};o.diff=N.sub(t,J0.inputTensor),o.squared=N.mul(o.diff,o.diff),o.sum=N.sum(o.squared);let s=(await o.sum.data())[0]/(t.shape[1]||1)/(t.shape[2]||1)/255/3;N.dispose([J0.inputTensor,o.diff,o.squared,o.sum]),J0.inputTensor=N.clone(t),n=s<=(e.cacheSensitivity||0)}return n}async function D1(e,t,n){let o={};if(!t||!n||t.shape.length!==4||t.shape.length!==n.shape.length)return e.debug||u("invalid input tensor or tensor shapes do not match:",t.shape,n.shape),0;if(t.shape[0]!==1||n.shape[0]!==1||t.shape[3]!==3||n.shape[3]!==3)return e.debug||u("input tensors must be of shape [1, height, width, 3]:",t.shape,n.shape),0;o.input1=N.clone(t),o.input2=t.shape[1]!==n.shape[1]||t.shape[2]!==n.shape[2]?N.image.resizeBilinear(n,[t.shape[1],t.shape[2]]):N.clone(n),o.diff=N.sub(o.input1,o.input2),o.squared=N.mul(o.diff,o.diff),o.sum=N.sum(o.squared);let s=(await o.sum.data())[0]/(t.shape[1]||1)/(t.shape[2]||1)/255/3;return N.dispose([o.input1,o.input2,o.diff,o.squared,o.sum]),s}var E2,z2,S2,w2=class{constructor(){k(this,"browser");k(this,"node");k(this,"worker");k(this,"platform","");k(this,"agent","");k(this,"backends",[]);k(this,"initial");k(this,"filter");k(this,"tfjs");k(this,"offscreen");k(this,"perfadd",!1);k(this,"tensorflow",{version:void 0,gpu:void 0});k(this,"wasm",{supported:void 0,backend:void 0,simd:void 0,multithread:void 0});k(this,"webgl",{supported:void 0,backend:void 0,version:void 0,renderer:void 0,shader:void 0,vendor:void 0});k(this,"webgpu",{supported:void 0,backend:void 0,adapter:void 0});k(this,"cpu",{model:void 0,flags:[]});k(this,"kernels",[]);me(this,E2,void 0);me(this,z2,void 0);me(this,S2,void 0);if(this.browser=typeof navigator!="undefined",this.node=typeof process!="undefined"&&typeof process.versions!="undefined"&&typeof process.versions.node!="undefined",this.tfjs={version:I0.version["tfjs-core"]},this.offscreen=typeof OffscreenCanvas!="undefined",this.initial=!0,this.worker=this.browser&&this.offscreen?typeof WorkerGlobalScope!="undefined":void 0,typeof navigator!="undefined"){let t=navigator.userAgent.match(/\(([^()]+)\)/g);if(t!=null&&t[0]){let n=t[0].match(/\(([^()]+)\)/g);this.platform=n!=null&&n[0]?n[0].replace(/\(|\)/g,""):"",this.agent=navigator.userAgent.replace(t[0],""),this.platform[1]&&(this.agent=this.agent.replace(t[1],"")),this.agent=this.agent.replace(/ /g," ")}}else typeof process!="undefined"&&(this.platform=`${process.platform} ${process.arch}`,this.agent=`NodeJS ${process.version}`)}get Canvas(){return G0(this,E2)}set Canvas(t){ge(this,E2,t),globalThis.Canvas=t}get Image(){return G0(this,z2)}set Image(t){ge(this,z2,t),globalThis.Image=t}get ImageData(){return G0(this,S2)}set ImageData(t){ge(this,S2,t),globalThis.ImageData=t}async updateBackend(){this.backends=Object.keys(I0.engine().registryFactory);try{this.tensorflow={version:I0.backend().binding?I0.backend().binding.TF_Version:void 0,gpu:I0.backend().binding?I0.backend().binding.isUsingGpuDevice():void 0}}catch(o){}this.wasm.supported=typeof WebAssembly!="undefined",this.wasm.backend=this.backends.includes("wasm"),this.wasm.supported&&this.wasm.backend&&(this.wasm.simd=await I0.env().getAsync("WASM_HAS_SIMD_SUPPORT"),this.wasm.multithread=await I0.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"));let t=te(100,100),n=t?t.getContext("webgl2"):void 0;this.webgl.supported=typeof n!="undefined",this.webgl.backend=this.backends.includes("webgl"),this.webgl.supported&&this.webgl.backend&&n&&(this.webgl.version=n.getParameter(n.VERSION),this.webgl.vendor=n.getParameter(n.VENDOR),this.webgl.renderer=n.getParameter(n.RENDERER),this.webgl.shader=n.getParameter(n.SHADING_LANGUAGE_VERSION)),this.webgpu.supported=this.browser&&typeof navigator.gpu!="undefined",this.webgpu.backend=this.backends.includes("webgpu");try{if(this.webgpu.supported){let o=await navigator.gpu.requestAdapter();this.webgpu.adapter=await(o==null?void 0:o.requestAdapterInfo())}}catch(o){this.webgpu.supported=!1}try{this.kernels=I0.getKernelsForBackend(I0.getBackend()).map(o=>o.kernelName.toLowerCase())}catch(o){}}updateCPU(){let t={model:"",flags:[]};this.node&&this.platform.startsWith("linux"),this.cpu?this.cpu=t:Object.defineProperty(this,"cpu",{value:t})}};E2=new WeakMap,z2=new WeakMap,S2=new WeakMap;var R=new w2;var U2=class{constructor(){k(this,"config");k(this,"element");k(this,"stream");k(this,"devices",[]);k(this,"enumerate",async()=>{try{let t=await navigator.mediaDevices.enumerateDevices();this.devices=t.filter(n=>n.kind==="videoinput")}catch(t){this.devices=[]}return this.devices});k(this,"start",async t=>{var r,s;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{this.config.debug&&u("webcam","cannot get dom element",t.element);return}}else if(t.element instanceof HTMLVideoElement)this.element=t.element;else{this.config.debug&&u("webcam","unknown dom element",t.element);return}else this.element=document.createElement("video");let n={audio:!1,video:{facingMode:this.config.mode==="front"?"user":"environment",resizeMode:this.config.crop?"crop-and-scale":"none"}};if(((r=this.config)==null?void 0:r.width)>0&&(n.video.width={ideal:this.config.width}),((s=this.config)==null?void 0:s.height)>0&&(n.video.height={ideal:this.config.height}),this.config.id&&(n.video.deviceId=this.config.id),this.element.addEventListener("play",()=>{this.config.debug&&u("webcam","play")}),this.element.addEventListener("pause",()=>{this.config.debug&&u("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)){this.config.debug&&u("webcam","no devices");return}try{this.stream=await navigator.mediaDevices.getUserMedia(n)}catch(A){u("webcam",A);return}if(!this.stream){this.config.debug&&u("webcam","no stream");return}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&&u("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})});k(this,"pause",()=>{this.element&&this.element.pause()});k(this,"play",async()=>{this.element&&await this.element.play()});k(this,"stop",()=>{this.config.debug&&u("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}};var d2=Z(H());var Qt={};ze(Qt,{age:()=>yr,"anti-spoofing":()=>Vr,antispoof:()=>tr,blazeface:()=>nr,"blazeface-back":()=>fr,"blazeface-front":()=>mr,"blazepose-detector":()=>pr,"blazepose-full":()=>ur,"blazepose-heavy":()=>hr,"blazepose-lite":()=>br,centernet:()=>or,default:()=>ns,efficientpose:()=>gr,"efficientpose-i-lite":()=>Zr,"efficientpose-ii-lite":()=>Xr,"efficientpose-iv":()=>qr,emotion:()=>rr,faceboxes:()=>Tr,facemesh:()=>sr,"facemesh-attention":()=>Rr,"facemesh-attention-pinto":()=>vr,"facemesh-detection-full":()=>Mr,"facemesh-detection-short":()=>Pr,faceres:()=>Ar,"faceres-deep":()=>kr,gear:()=>wr,gender:()=>zr,"gender-ssrnet-imdb":()=>Er,handdetect:()=>Sr,"handlandmark-full":()=>jr,"handlandmark-lite":()=>ar,"handlandmark-sparse":()=>Nr,handskeleton:()=>Ir,handtrack:()=>ir,"insightface-efficientnet-b0":()=>Ur,"insightface-ghostnet-strides1":()=>Yr,"insightface-ghostnet-strides2":()=>Kr,"insightface-mobilenet-emore":()=>Jr,"insightface-mobilenet-swish":()=>Qr,iris:()=>lr,liveness:()=>cr,meet:()=>Or,mobileface:()=>Lr,mobilefacenet:()=>Cr,models:()=>dr,"movenet-lightning":()=>xr,"movenet-multipose":()=>Wr,"movenet-thunder":()=>Dr,nanodet:()=>Fr,"nanodet-e":()=>_r,"nanodet-g":()=>$r,"nanodet-m":()=>es,"nanodet-t":()=>ts,posenet:()=>Br,rvm:()=>Hr,selfie:()=>Gr});var tr=853098,nr=538928,or=4030290,rr=820516,sr=1477958,Ar=6978814,ar=2023432,ir=2964837,lr=2599092,cr=592976,dr=0,xr=4650216,yr=161240,fr=538928,mr=402048,pr=5928856,ur=6339202,hr=27502466,br=2726402,gr=5651240,Tr=2013002,vr=2387598,Rr=2382414,Mr=1026192,Pr=201268,kr=13957620,wr=1498916,Er=161236,zr=201808,Sr=3515612,jr=5431368,Nr=5286322,Ir=5502280,Or=372228,Lr=2183192,Cr=5171976,Wr=9448838,Dr=12477112,Fr=7574558,Br=5032780,Hr=3739355,Gr=212886,Vr=853098,Zr=2269064,Xr=5651240,qr=25643252,Ur=13013224,Yr=8093408,Kr=8049584,Jr=6938536,Qr=12168584,_r=12319156,$r=7574558,es=1887474,ts=5294216,ns={antispoof:tr,blazeface:nr,centernet:or,emotion:rr,facemesh:sr,faceres:Ar,"handlandmark-lite":ar,handtrack:ir,iris:lr,liveness:cr,models:dr,"movenet-lightning":xr,age:yr,"blazeface-back":fr,"blazeface-front":mr,"blazepose-detector":pr,"blazepose-full":ur,"blazepose-heavy":hr,"blazepose-lite":br,efficientpose:gr,faceboxes:Tr,"facemesh-attention-pinto":vr,"facemesh-attention":Rr,"facemesh-detection-full":Mr,"facemesh-detection-short":Pr,"faceres-deep":kr,gear:wr,"gender-ssrnet-imdb":Er,gender:zr,handdetect:Sr,"handlandmark-full":jr,"handlandmark-sparse":Nr,handskeleton:Ir,meet:Or,mobileface:Lr,mobilefacenet:Cr,"movenet-multipose":Wr,"movenet-thunder":Dr,nanodet:Fr,posenet:Br,rvm:Hr,selfie:Gr,"anti-spoofing":Vr,"efficientpose-i-lite":Zr,"efficientpose-ii-lite":Xr,"efficientpose-iv":qr,"insightface-efficientnet-b0":Ur,"insightface-ghostnet-strides1":Yr,"insightface-ghostnet-strides2":Kr,"insightface-mobilenet-emore":Jr,"insightface-mobilenet-swish":Qr,"nanodet-e":_r,"nanodet-g":$r,"nanodet-m":es,"nanodet-t":ts};var O0={cacheModels:!0,cacheSupported:!0,verbose:!0,debug:!1,modelBasePath:""},E0={};async function os(e,t){return O0.debug&&u("load model fetch:",e,t),fetch(e,t)}function F1(e){O0.cacheModels=e.cacheModels,O0.verbose=e.debug,O0.modelBasePath=e.modelBasePath}async function O(e){var c,x,i,y;let t=z1(O0.modelBasePath,e||"");t.toLowerCase().endsWith(".json")||(t+=".json");let n=t.includes("/")?t.split("/"):t.split("\\"),o=n[n.length-1].replace(".json",""),r="indexeddb://"+o;E0[o]={name:o,sizeFromManifest:0,sizeLoadedWeights:0,sizeDesired:Qt[o],inCache:!1,url:""},O0.cacheSupported=typeof indexedDB!="undefined";let s={};try{s=O0.cacheSupported&&O0.cacheModels?await d2.io.listModels():{}}catch(d){O0.cacheSupported=!1}E0[o].inCache=O0.cacheSupported&&O0.cacheModels&&Object.keys(s).includes(r),E0[o].url=E0[o].inCache?r:t;let A=typeof fetch=="undefined"?{}:{fetchFunc:(d,p)=>os(d,p)},a=new d2.GraphModel(E0[o].url,A),l=!1;try{a.findIOHandler(),O0.debug&&u("model load handler:",a.handler)}catch(d){u("error finding model i/o handler:",t,d)}try{let d=await((c=a.handler)==null?void 0:c.load())||null;E0[o].sizeFromManifest=((x=d==null?void 0:d.weightData)==null?void 0:x.byteLength)||0,d?a.loadSync(d):a=await d2.loadGraphModel(E0[o].inCache?r:t,A),E0[o].sizeLoadedWeights=((y=(i=a.artifacts)==null?void 0:i.weightData)==null?void 0:y.byteLength)||0,O0.verbose&&u("load:",{model:o,url:a.modelUrl,bytes:E0[o].sizeLoadedWeights}),l=!0}catch(d){u("error loading model:",t,d)}if(l&&O0.cacheModels&&O0.cacheSupported&&!E0[o].inCache)try{let d=await a.save(r);O0.debug&&u("model saved:",r,d)}catch(d){u("error saving model:",t,d)}return a}var _t="3.0.2";var E=Z(H());var p0=Z(H());var o0={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 As(){let e=o0.gl;!e||(o0.extensions=e.getSupportedExtensions())}function B1(e){var t;if(e.config.backend==="humangl"&&(o0.name in p0.engine().registry&&!((t=o0==null?void 0:o0.gl)!=null&&t.getParameter(o0.gl.VERSION))&&(u("humangl error: backend invalid context"),e.models.reset()),!p0.findBackend(o0.name))){try{o0.canvas=te(100,100)}catch(r){u("humangl error: cannot create canvas:",r);return}try{if(o0.gl=o0.canvas.getContext("webgl2",o0.webGLattr),!o0.gl){u("humangl error: cannot get webgl context");return}if(!o0.gl.getParameter(o0.gl.VERSION).includes("2.0")){u("backend override: using fallback webgl backend as webgl 2.0 is not detected"),e.config.backend="webgl";return}o0.canvas&&(o0.canvas.addEventListener("webglcontextlost",s=>{throw u("humangl error:",s.type),u("possible browser memory leak using webgl or conflict with multiple backend registrations"),e.emit("error"),new Error("backend error: webgl context lost")}),o0.canvas.addEventListener("webglcontextrestored",s=>{u("humangl error: context restored:",s)}),o0.canvas.addEventListener("webglcontextcreationerror",s=>{u("humangl error: context create:",s)}))}catch(r){u("humangl error: cannot get webgl context:",r);return}try{p0.setWebGLContext(2,o0.gl)}catch(r){u("humangl error: cannot set webgl context:",r);return}try{let r=new p0.GPGPUContext(o0.gl);p0.registerBackend(o0.name,()=>new p0.MathBackendWebGL(r),o0.priority)}catch(r){u("humangl error: cannot register webgl backend:",r);return}try{p0.getKernelsForBackend("webgl").forEach(s=>{let A={...s,backendName:o0.name};p0.registerKernel(A)})}catch(r){u("humangl error: cannot update webgl backend registration:",r);return}try{p0.env().flagRegistry.WEBGL_VERSION&&p0.env().set("WEBGL_VERSION",2)}catch(r){u("humangl error: cannot set WebGL backend flags:",r);return}As();let n=p0.backend(),o=typeof n.gpgpu!="undefined"?n.getGPGPUContext().gl:null;o?e.config.debug&&u("humangl backend registered:",{webgl:o.getParameter(o.VERSION),renderer:o.getParameter(o.RENDERER)}):u("humangl error: no current gl context:",o,o0.gl)}}var Se=Z(H()),C={tf255:255,tf1:1,tf2:2,tf05:.5,tf127:127.5,rgb:[.2989,.587,.114]};function H1(){C.tf255=Se.scalar(255,"float32"),C.tf1=Se.scalar(1,"float32"),C.tf2=Se.scalar(2,"float32"),C.tf05=Se.scalar(.5,"float32"),C.tf127=Se.scalar(127.5,"float32"),C.rgb=Se.tensor1d([.2989,.587,.114],"float32")}async function ls(){var e;return await R.updateBackend(),(e=R.tensorflow)!=null&&e.version?"tensorflow":R.webgpu.supported&&R.webgpu.backend?"webgpu":R.webgl.supported&&R.webgl.backend?"webgl":R.wasm.supported&&R.wasm.backend?"wasm":"cpu"}function cs(e){let t=[];if(!R.kernels.includes("mod")){let n={kernelName:"Mod",backendName:E.getBackend(),kernelFunc:o=>E.tidy(()=>E.sub(o.inputs.a,E.mul(E.div(o.inputs.a,o.inputs.b),o.inputs.b)))};E.registerKernel(n),R.kernels.push("mod"),t.push("mod")}if(!R.kernels.includes("floormod")){let n={kernelName:"FloorMod",backendName:E.getBackend(),kernelFunc:o=>E.tidy(()=>E.add(E.mul(E.floorDiv(o.inputs.a,o.inputs.b),o.inputs.b),E.mod(o.inputs.a,o.inputs.b)))};E.registerKernel(n),R.kernels.push("floormod"),t.push("floormod")}if(!R.kernels.includes("rotatewithoffset")&&e.softwareKernels){let n={kernelName:"RotateWithOffset",backendName:E.getBackend(),kernelFunc:o=>E.tidy(()=>{let r=E.getBackend();E.setBackend("cpu");let s=E.image.rotateWithOffset(o.inputs.image,o.attrs.radians,o.attrs.fillValue,o.attrs.center);return E.setBackend(r),s})};E.registerKernel(n),R.kernels.push("rotatewithoffset"),t.push("rotatewithoffset")}t.length>0&&e.debug&&u("registered kernels:",t)}var G1={};async function j2(e,t=!1){var n;if(e.state="backend",((n=e.config.backend)==null?void 0:n.length)===0&&(e.config.backend=await ls()),t||R.initial||e.config.backend&&e.config.backend.length>0&&E.getBackend()!==e.config.backend){let o=g();if(e.config.backend&&e.config.backend.length>0){if(typeof window=="undefined"&&typeof WorkerGlobalScope!="undefined"&&e.config.debug&&e.config.debug&&u("running inside web worker"),R.browser&&e.config.backend==="tensorflow"&&(e.config.debug&&u("override: backend set to tensorflow while running in browser"),e.config.backend="webgl"),R.node&&(e.config.backend==="webgl"||e.config.backend==="humangl")&&(e.config.debug&&u(`override: backend set to ${e.config.backend} while running in nodejs`),e.config.backend="tensorflow"),R.browser&&e.config.backend==="webgpu")if(typeof navigator=="undefined"||typeof navigator.gpu=="undefined")u("override: backend set to webgpu but browser does not support webgpu"),e.config.backend="webgl";else{let s=await navigator.gpu.requestAdapter();if(e.config.debug&&u("enumerated webgpu adapter:",s),!s)u("override: backend set to webgpu but browser reports no available gpu"),e.config.backend="webgl";else{let A="requestAdapterInfo"in s?await s.requestAdapterInfo():void 0;u("webgpu adapter info:",A)}}let r=Object.keys(E.engine().registryFactory);if(e.config.backend==="humangl"&&!r.includes("humangl")&&(B1(e),r=Object.keys(E.engine().registryFactory)),e.config.debug&&u("available backends:",r),r.includes(e.config.backend)||(u(`error: backend ${e.config.backend} not found in registry`),e.config.backend=R.node?"tensorflow":"webgl",e.config.debug&&u(`override: setting backend ${e.config.backend}`)),e.config.debug&&u("setting backend:",[e.config.backend]),e.config.backend==="wasm"){if(E.env().flagRegistry.CANVAS2D_WILL_READ_FREQUENTLY&&E.env().set("CANVAS2D_WILL_READ_FREQUENTLY",!0),e.config.debug&&u("wasm path:",e.config.wasmPath),typeof E.setWasmPaths!="undefined")E.setWasmPaths(e.config.wasmPath,e.config.wasmPlatformFetch);else throw new Error("backend error: attempting to use wasm backend but wasm path is not set");let s=!1,A=!1;try{s=await E.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"),A=await E.env().getAsync("WASM_HAS_SIMD_SUPPORT"),e.config.debug&&u(`wasm execution: ${A?"simd":"no simd"} ${s?"multithreaded":"singlethreaded"}`),e.config.debug&&!A&&u("warning: wasm simd support is not enabled")}catch(a){u("wasm detection failed")}}try{await E.setBackend(e.config.backend),await E.ready()}catch(s){return u("error: cannot set backend:",e.config.backend,s),!1}e.config.debug&&(G1=JSON.parse(JSON.stringify(E.env().flags)))}if((E.getBackend()==="humangl"||E.getBackend()==="webgl")&&(E.env().flagRegistry.WEBGL_USE_SHAPES_UNIFORMS&&E.env().set("WEBGL_USE_SHAPES_UNIFORMS",!0),E.env().flagRegistry.WEBGL_EXP_CONV&&E.env().set("WEBGL_EXP_CONV",!0),e.config.debug&&typeof e.config.deallocate!="undefined"&&e.config.deallocate&&(u("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",!0),E.env().set("WEBGL_DELETE_TEXTURE_THRESHOLD",0))),E.getBackend(),e.config.debug){let r=E.env().flags,s={};for(let A of Object.keys(r))G1[A]!==r[A]&&(s[A]=r[A]);e.config.debug&&Object.keys(s).length>0&&u("backend:",E.getBackend(),"flags:",s)}if(e.config.flags&&Object.keys(e.config.flags).length>0){e.config.debug&&u("flags:",e.config.flags);for(let[r,s]of Object.entries(e.config.flags))E.env().set(r,s)}E.enableProdMode(),H1(),e.performance.initBackend=Math.trunc(g()-o),e.config.backend=E.getBackend(),await R.updateBackend(),cs(e.config),R.initial=!1}return!0}function Y2(e,t){for(let n of e){let o={kernelName:n,backendName:t.backend,kernelFunc:r=>{var s;return t.debug&&u("kernelFunc",n,t.backend,r),(s=r==null?void 0:r.inputs)==null?void 0:s.info}};E.registerKernel(o)}R.kernels=E.getKernelsForBackend(E.getBackend()).map(n=>n.kernelName.toLowerCase())}var et={};ze(et,{all:()=>Hs,body:()=>J2,canvas:()=>Bs,face:()=>K2,gesture:()=>$2,hand:()=>Q2,init:()=>s5,object:()=>_2,options:()=>x0,person:()=>Fs});var Q0=e=>{if(!e)u("draw error: invalid canvas");else if(!e.getContext)u("draw error: canvas context not defined");else{let t=e.getContext("2d");if(!t)u("draw error: cannot get canvas context");else return t}return null},Ke=e=>Math.round(e*180/Math.PI),_=(e,t,n)=>e.replace(t,typeof n=="number"?n.toFixed(1):n),Je=(e,t)=>{if(!t.useDepth||typeof e=="undefined")return t.color;let n=Uint8ClampedArray.from([127+2*e,127-2*e,255]);return`rgba(${n[0]}, ${n[1]}, ${n[2]}, ${t.alpha})`};function ne(e,t,n,o,r){let s=t.replace(/\[.*\]/g,"").split(` +`).map(a=>a.trim()),A=Math.max(0,n);for(let a=s.length-1;a>=0;a--){let l=a*r.lineHeight+o;r.shadowColor&&r.shadowColor!==""&&(e.fillStyle=r.shadowColor,e.fillText(s[a],A+5,l+16)),e.fillStyle=r.labelColor,e.fillText(s[a],A+4,l+15)}}function Te(e,t,n,o,r){e.fillStyle=Je(o,r),e.beginPath(),e.arc(t,n,r.pointSize,0,2*Math.PI),e.fill()}function pe(e,t,n,o,r,s){if(e.beginPath(),e.lineWidth=s.lineWidth,s.useCurves){let A=(t+t+o)/2,a=(n+n+r)/2;e.ellipse(A,a,o/2,r/2,0,0,2*Math.PI)}else e.moveTo(t+s.roundRect,n),e.lineTo(t+o-s.roundRect,n),e.quadraticCurveTo(t+o,n,t+o,n+s.roundRect),e.lineTo(t+o,n+r-s.roundRect),e.quadraticCurveTo(t+o,n+r,t+o-s.roundRect,n+r),e.lineTo(t+s.roundRect,n+r),e.quadraticCurveTo(t,n+r,t,n+r-s.roundRect),e.lineTo(t,n+s.roundRect),e.quadraticCurveTo(t,n,t+s.roundRect,n),e.closePath();e.stroke()}function $t(e,t,n){if(!(t.length<2)){e.beginPath(),e.moveTo(t[0][0],t[0][1]);for(let o of t)e.strokeStyle=Je(o[2]||0,n),e.lineTo(Math.trunc(o[0]),Math.trunc(o[1]));e.stroke(),n.fillPolygons&&(e.closePath(),e.fill())}}function Z1(e,t,n){if(!(t.length<2)){if(e.lineWidth=n.lineWidth,!n.useCurves||t.length<=2){$t(e,t,n);return}e.moveTo(t[0][0],t[0][1]);for(let o=0;oN2[e]),La=xs.map(e=>N2[e]),Ca=ys.map(e=>N2[e]);function je(e){let t=e.map(n=>n[0]);return t.push(e[e.length-1][1]),t}var fs=[[61,146],[146,91],[91,181],[181,84],[84,17],[17,314],[314,405],[405,321],[321,375],[375,291],[61,185],[185,40],[40,39],[39,37],[37,0],[0,267],[267,269],[269,270],[270,409],[409,291],[78,95],[95,88],[88,178],[178,87],[87,14],[14,317],[317,402],[402,318],[318,324],[324,308],[78,191],[191,80],[80,81],[81,82],[82,13],[13,312],[312,311],[311,310],[310,415],[415,308]],ms=[[263,249],[249,390],[390,373],[373,374],[374,380],[380,381],[381,382],[382,362],[263,466],[466,388],[388,387],[387,386],[386,385],[385,384],[384,398],[398,362]],ps=[[276,283],[283,282],[282,295],[295,285],[300,293],[293,334],[334,296],[296,336]],us=[[474,475],[475,476],[476,477],[477,474]],hs=[[33,7],[7,163],[163,144],[144,145],[145,153],[153,154],[154,155],[155,133],[33,246],[246,161],[161,160],[160,159],[159,158],[158,157],[157,173],[173,133]],bs=[[46,53],[53,52],[52,65],[65,55],[70,63],[63,105],[105,66],[66,107]],gs=[[469,470],[470,471],[471,472],[472,469]],Ts=[[10,338],[338,297],[297,332],[332,284],[284,251],[251,389],[389,356],[356,454],[454,323],[323,361],[361,288],[288,397],[397,365],[365,379],[379,378],[378,400],[400,377],[377,152],[152,148],[148,176],[176,149],[149,150],[150,136],[136,172],[172,58],[58,132],[132,93],[93,234],[234,127],[127,162],[162,21],[21,54],[54,103],[103,67],[67,109],[109,10]],Wa={lips:je(fs),leftEye:je(ms),leftEyebrow:je(ps),leftIris:je(us),rightEye:je(hs),rightEyebrow:je(bs),rightIris:je(gs),faceOval:je(Ts)};var vs=[[61,146],[146,91],[91,181],[181,84],[84,17],[17,314],[314,405],[405,321],[321,375],[375,291],[61,185],[185,40],[40,39],[39,37],[37,0],[0,267],[267,269],[269,270],[270,409],[409,291],[78,95],[95,88],[88,178],[178,87],[87,14],[14,317],[317,402],[402,318],[318,324],[324,308],[78,191],[191,80],[80,81],[81,82],[82,13],[13,312],[312,311],[311,310],[310,415],[415,308]],Rs=[[263,249],[249,390],[390,373],[373,374],[374,380],[380,381],[381,382],[382,362],[263,466],[466,388],[388,387],[387,386],[386,385],[385,384],[384,398],[398,362]],Ms=[[276,283],[283,282],[282,295],[295,285],[300,293],[293,334],[334,296],[296,336]],Ps=[[474,475],[475,476],[476,477],[477,474]],ks=[[33,7],[7,163],[163,144],[144,145],[145,153],[153,154],[154,155],[155,133],[33,246],[246,161],[161,160],[160,159],[159,158],[158,157],[157,173],[173,133]],ws=[[46,53],[53,52],[52,65],[65,55],[70,63],[63,105],[105,66],[66,107]],Es=[[469,470],[470,471],[471,472],[472,469]],zs=[[10,338],[338,297],[297,332],[332,284],[284,251],[251,389],[389,356],[356,454],[454,323],[323,361],[361,288],[288,397],[397,365],[365,379],[379,378],[378,400],[400,377],[377,152],[152,148],[148,176],[176,149],[149,150],[150,136],[136,172],[172,58],[58,132],[132,93],[93,234],[234,127],[127,162],[162,21],[21,54],[54,103],[103,67],[67,109],[109,10]];function Ne(e){let t=e.map(n=>n[0]);return t.push(e[e.length-1][1]),t}var Ss={lips:Ne(vs),leftEye:Ne(Rs),leftEyebrow:Ne(Ms),leftIris:Ne(Ps),rightEye:Ne(ks),rightEyebrow:Ne(ws),rightIris:Ne(Es),faceOval:Ne(zs)},js=Object.entries(Ss).map(([e,t])=>t.map(n=>[n,e])).flat(),Da=new Map(js),I2=[61,146,91,181,84,17,314,405,321,375,291,185,40,39,37,0,267,269,270,409,78,95,88,178,87,14,317,402,318,324,308,191,80,81,82,13,312,311,310,415,76,77,90,180,85,16,315,404,320,307,306,184,74,73,72,11,302,303,304,408,62,96,89,179,86,15,316,403,319,325,292,183,42,41,38,12,268,271,272,407],$e=[33,7,163,144,145,153,154,155,133,246,161,160,159,158,157,173,130,25,110,24,23,22,26,112,243,247,30,29,27,28,56,190,226,31,228,229,230,231,232,233,244,113,225,224,223,222,221,189,35,124,46,53,52,65,143,111,117,118,119,120,121,128,245,156,70,63,105,66,107,55,193],e2=[263,249,390,373,374,380,381,382,362,466,388,387,386,385,384,398,359,255,339,254,253,252,256,341,463,467,260,259,257,258,286,414,446,261,448,449,450,451,452,453,464,342,445,444,443,442,441,413,265,353,276,283,282,295,372,340,346,347,348,349,350,357,465,383,300,293,334,296,336,285,417];var K;function Ns(e,t){var o,r,s,A,a,l,c,x,i;if(!K.drawLabels||((o=K.faceLabels)==null?void 0:o.length)===0)return;let n=K.faceLabels.slice();if(e.score&&(n=_(n,"[score]",100*e.score)),e.gender&&(n=_(n,"[gender]",e.gender)),e.genderScore&&(n=_(n,"[genderScore]",100*e.genderScore)),e.age&&(n=_(n,"[age]",e.age)),e.distance&&(n=_(n,"[distance]",100*e.distance)),e.real&&(n=_(n,"[real]",100*e.real)),e.live&&(n=_(n,"[live]",100*e.live)),e.emotion&&e.emotion.length>0){let y=e.emotion.map(d=>`${Math.trunc(100*d.score)}% ${d.emotion}`);y.length>3&&(y.length=3),n=_(n,"[emotions]",y.join(" "))}(s=(r=e.rotation)==null?void 0:r.angle)!=null&&s.roll&&(n=_(n,"[roll]",Ke(e.rotation.angle.roll))),(a=(A=e.rotation)==null?void 0:A.angle)!=null&&a.yaw&&(n=_(n,"[yaw]",Ke(e.rotation.angle.yaw))),(c=(l=e.rotation)==null?void 0:l.angle)!=null&&c.pitch&&(n=_(n,"[pitch]",Ke(e.rotation.angle.pitch))),(i=(x=e.rotation)==null?void 0:x.gaze)!=null&&i.bearing&&(n=_(n,"[gaze]",Ke(e.rotation.gaze.bearing))),ne(t,n,e.box[0],e.box[1],K)}function Is(e,t){var n,o,r,s;if(((n=e.annotations)==null?void 0:n.leftEyeIris)&&((o=e.annotations)==null?void 0:o.leftEyeIris[0])){t.strokeStyle=K.useDepth?"rgba(255, 200, 255, 0.3)":K.color,t.beginPath();let A=Math.abs(e.annotations.leftEyeIris[3][0]-e.annotations.leftEyeIris[1][0])/2,a=Math.abs(e.annotations.leftEyeIris[4][1]-e.annotations.leftEyeIris[2][1])/2;t.ellipse(e.annotations.leftEyeIris[0][0],e.annotations.leftEyeIris[0][1],A,a,0,0,2*Math.PI),t.stroke(),K.fillPolygons&&(t.fillStyle=K.useDepth?"rgba(255, 255, 200, 0.3)":K.color,t.fill())}if(((r=e.annotations)==null?void 0:r.rightEyeIris)&&((s=e.annotations)==null?void 0:s.rightEyeIris[0])){t.strokeStyle=K.useDepth?"rgba(255, 200, 255, 0.3)":K.color,t.beginPath();let A=Math.abs(e.annotations.rightEyeIris[3][0]-e.annotations.rightEyeIris[1][0])/2,a=Math.abs(e.annotations.rightEyeIris[4][1]-e.annotations.rightEyeIris[2][1])/2;t.ellipse(e.annotations.rightEyeIris[0][0],e.annotations.rightEyeIris[0][1],A,a,0,0,2*Math.PI),t.stroke(),K.fillPolygons&&(t.fillStyle=K.useDepth?"rgba(255, 255, 200, 0.3)":K.color,t.fill())}}function Os(e,t){var n;if(K.drawGaze&&((n=e.rotation)==null?void 0:n.angle)&&typeof Path2D!="undefined"){t.strokeStyle="pink";let o=e.box[0]+e.box[2]/2-e.box[3]*Ke(e.rotation.angle.yaw)/90,r=e.box[1]+e.box[3]/2+e.box[2]*Ke(e.rotation.angle.pitch)/90,s=new Path2D(` + M ${e.box[0]+e.box[2]/2} ${e.box[1]} C - ${valX} ${f.box[1]}, - ${valX} ${f.box[1] + f.box[3]}, - ${f.box[0] + f.box[2] / 2} ${f.box[1] + f.box[3]} - `); - const pathH = new Path2D(` - M ${f.box[0]} ${f.box[1] + f.box[3] / 2} + ${o} ${e.box[1]}, + ${o} ${e.box[1]+e.box[3]}, + ${e.box[0]+e.box[2]/2} ${e.box[1]+e.box[3]} + `),A=new Path2D(` + M ${e.box[0]} ${e.box[1]+e.box[3]/2} C - ${f.box[0]} ${valY}, - ${f.box[0] + f.box[2]} ${valY}, - ${f.box[0] + f.box[2]} ${f.box[1] + f.box[3] / 2} - `); - ctx.stroke(pathH); - ctx.stroke(pathV); - } -} -function drawGazeArrows(f, ctx) { - var _a; - if (localOptions.drawGaze && ((_a = f.rotation) == null ? void 0 : _a.gaze.strength) && f.rotation.gaze.bearing && f.annotations.leftEyeIris && f.annotations.rightEyeIris && f.annotations.leftEyeIris[0] && f.annotations.rightEyeIris[0]) { - ctx.strokeStyle = "pink"; - ctx.fillStyle = "pink"; - const leftGaze = [ - f.annotations.leftEyeIris[0][0] + Math.sin(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[3], - f.annotations.leftEyeIris[0][1] + Math.cos(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[2] - ]; - arrow(ctx, [f.annotations.leftEyeIris[0][0], f.annotations.leftEyeIris[0][1]], [leftGaze[0], leftGaze[1]], 4); - const rightGaze = [ - f.annotations.rightEyeIris[0][0] + Math.sin(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[3], - f.annotations.rightEyeIris[0][1] + Math.cos(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[2] - ]; - arrow(ctx, [f.annotations.rightEyeIris[0][0], f.annotations.rightEyeIris[0][1]], [rightGaze[0], rightGaze[1]], 4); - } -} -function drawFacePolygons(f, ctx) { - if (localOptions.drawPolygons && f.mesh.length >= 468) { - ctx.lineWidth = 1; - for (let i = 0; i < TRI468.length / 3; i++) { - const points = [TRI468[i * 3 + 0], TRI468[i * 3 + 1], TRI468[i * 3 + 2]].map((index2) => f.mesh[index2]); - lines(ctx, points, localOptions); - } - drawIrisElipse(f, ctx); - } -} -function drawFacePoints(f, ctx) { - if (localOptions.drawPoints && f.mesh.length >= 468) { - for (let i = 0; i < f.mesh.length; i++) { - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2], localOptions); - if (localOptions.drawAttention) { - if (LANDMARKS_REFINEMENT_LIPS_CONFIG.includes(i)) - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2] + 127, localOptions); - if (LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG.includes(i)) - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2] - 127, localOptions); - if (LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG.includes(i)) - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2] - 127, localOptions); - } - } - } -} -function drawFaceBoxes(f, ctx) { - if (localOptions.drawBoxes) { - rect(ctx, f.box[0], f.box[1], f.box[2], f.box[3], localOptions); - } -} -function face(inCanvas2, result, drawOptions) { - localOptions = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.font = localOptions.font; - ctx.strokeStyle = localOptions.color; - ctx.fillStyle = localOptions.color; - for (const f of result) { - drawFaceBoxes(f, ctx); - drawLabels(f, ctx); - if (f.mesh && f.mesh.length > 0) { - drawFacePoints(f, ctx); - drawFacePolygons(f, ctx); - drawGazeSpheres(f, ctx); - drawGazeArrows(f, ctx); - } - } -} - -// src/draw/body.ts -function body(inCanvas2, result, drawOptions) { - var _a, _b; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - for (let i = 0; i < result.length; i++) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - ctx.lineWidth = localOptions2.lineWidth; - ctx.font = localOptions2.font; - if (localOptions2.drawBoxes && result[i].box && result[i].box.length === 4) { - rect(ctx, result[i].box[0], result[i].box[1], result[i].box[2], result[i].box[3], localOptions2); - if (localOptions2.drawLabels && ((_a = localOptions2.bodyLabels) == null ? void 0 : _a.length) > 0) { - let l = localOptions2.bodyLabels.slice(); - l = replace(l, "[score]", 100 * result[i].score); - labels(ctx, l, result[i].box[0], result[i].box[1], localOptions2); - } - } - if (localOptions2.drawPoints && result[i].keypoints) { - for (let pt = 0; pt < result[i].keypoints.length; pt++) { - if (!result[i].keypoints[pt].score || result[i].keypoints[pt].score === 0) - continue; - ctx.fillStyle = colorDepth(result[i].keypoints[pt].position[2], localOptions2); - point(ctx, result[i].keypoints[pt].position[0], result[i].keypoints[pt].position[1], 0, localOptions2); - } - } - if (localOptions2.drawLabels && ((_b = localOptions2.bodyPartLabels) == null ? void 0 : _b.length) > 0 && result[i].keypoints) { - ctx.font = localOptions2.font; - for (const pt of result[i].keypoints) { - if (!pt.score || pt.score === 0) - continue; - let l = localOptions2.bodyPartLabels.slice(); - l = replace(l, "[label]", pt.part); - l = replace(l, "[score]", 100 * pt.score); - labels(ctx, l, pt.position[0], pt.position[1], localOptions2); - } - } - if (localOptions2.drawPolygons && result[i].keypoints && result[i].annotations) { - for (const part of Object.values(result[i].annotations)) { - for (const connected4 of part) - curves(ctx, connected4, localOptions2); - } - } - } -} - -// src/draw/hand.ts -function hand(inCanvas2, result, drawOptions) { - var _a, _b; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - ctx.font = localOptions2.font; - for (const h of result) { - if (localOptions2.drawBoxes) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - rect(ctx, h.box[0], h.box[1], h.box[2], h.box[3], localOptions2); - if (localOptions2.drawLabels && ((_a = localOptions2.handLabels) == null ? void 0 : _a.length) > 0) { - let l = localOptions2.handLabels.slice(); - l = replace(l, "[label]", h.label); - l = replace(l, "[score]", 100 * h.score); - labels(ctx, l, h.box[0], h.box[1], localOptions2); - } - ctx.stroke(); - } - if (localOptions2.drawPoints) { - if (h.keypoints && h.keypoints.length > 0) { - for (const pt of h.keypoints) { - ctx.fillStyle = colorDepth(pt[2], localOptions2); - point(ctx, pt[0], pt[1], 0, localOptions2); - } - } - } - if (localOptions2.drawLabels && h.annotations && ((_b = localOptions2.fingerLabels) == null ? void 0 : _b.length) > 0) { - for (const [part, pt] of Object.entries(h.annotations)) { - let l = localOptions2.fingerLabels.slice(); - l = replace(l, "[label]", part); - labels(ctx, l, pt[pt.length - 1][0], pt[pt.length - 1][1], localOptions2); - } - } - if (localOptions2.drawPolygons && h.annotations) { - const addHandLine = (part) => { - if (!part || part.length === 0 || !part[0]) - return; - for (let i = 0; i < part.length; i++) { - ctx.beginPath(); - const z = part[i][2] || 0; - ctx.strokeStyle = colorDepth(i * z, localOptions2); - ctx.moveTo(part[i > 0 ? i - 1 : 0][0], part[i > 0 ? i - 1 : 0][1]); - ctx.lineTo(part[i][0], part[i][1]); - ctx.stroke(); - } - }; - ctx.lineWidth = localOptions2.lineWidth; - addHandLine(h.annotations.index); - addHandLine(h.annotations.middle); - addHandLine(h.annotations.ring); - addHandLine(h.annotations.pinky); - addHandLine(h.annotations.thumb); - } - } -} - -// src/draw/object.ts -function object(inCanvas2, result, drawOptions) { - var _a; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - ctx.font = localOptions2.font; - for (const h of result) { - if (localOptions2.drawBoxes) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - rect(ctx, h.box[0], h.box[1], h.box[2], h.box[3], localOptions2); - if (localOptions2.drawLabels && ((_a = localOptions2.objectLabels) == null ? void 0 : _a.length) > 0) { - let l = localOptions2.objectLabels.slice(); - l = replace(l, "[label]", h.label); - l = replace(l, "[score]", 100 * h.score); - labels(ctx, l, h.box[0], h.box[1], localOptions2); - } - ctx.stroke(); - } - } -} - -// src/draw/gesture.ts -function gesture(inCanvas2, result, drawOptions) { - var _a; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - if (localOptions2.drawGestures && ((_a = localOptions2.gestureLabels) == null ? void 0 : _a.length) > 0) { - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.font = localOptions2.font; - ctx.fillStyle = localOptions2.color; - let i = 1; - for (let j = 0; j < result.length; j++) { - const [where, what] = Object.entries(result[j]); - if (what.length > 1 && what[1].length > 0) { - const who = where[1] > 0 ? `#${where[1]}` : ""; - let l = localOptions2.gestureLabels.slice(); - l = replace(l, "[where]", where[0]); - l = replace(l, "[who]", who); - l = replace(l, "[what]", what[1]); - labels(ctx, l, 8, 2 + i * localOptions2.lineHeight, localOptions2); - i += 1; - } - } - } -} - -// src/draw/labels.ts -var defaultLabels = { - face: `face + ${e.box[0]} ${r}, + ${e.box[0]+e.box[2]} ${r}, + ${e.box[0]+e.box[2]} ${e.box[1]+e.box[3]/2} + `);t.stroke(A),t.stroke(s)}}function Ls(e,t){var n;if(K.drawGaze&&((n=e.rotation)==null?void 0:n.gaze.strength)&&e.rotation.gaze.bearing&&e.annotations.leftEyeIris&&e.annotations.rightEyeIris&&e.annotations.leftEyeIris[0]&&e.annotations.rightEyeIris[0]){t.strokeStyle="pink",t.fillStyle="pink";let o=[e.annotations.leftEyeIris[0][0]+Math.sin(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[3],e.annotations.leftEyeIris[0][1]+Math.cos(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[2]];e5(t,[e.annotations.leftEyeIris[0][0],e.annotations.leftEyeIris[0][1]],[o[0],o[1]],4);let r=[e.annotations.rightEyeIris[0][0]+Math.sin(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[3],e.annotations.rightEyeIris[0][1]+Math.cos(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[2]];e5(t,[e.annotations.rightEyeIris[0][0],e.annotations.rightEyeIris[0][1]],[r[0],r[1]],4)}}function Cs(e,t){if(K.drawPolygons&&e.mesh.length>=468){t.lineWidth=1;for(let n=0;n<_e.length/3;n++){let o=[_e[n*3+0],_e[n*3+1],_e[n*3+2]].map(r=>e.mesh[r]);$t(t,o,K)}Is(e,t)}}function Ws(e,t){if(K.drawPoints&&e.mesh.length>=468)for(let n=0;n0&&(Ws(r,o),Cs(r,o),Os(r,o),Ls(r,o))}}function J2(e,t,n){var s,A;let o=a0(x0,n);if(!t||!e)return;let r=Q0(e);if(!!r){r.lineJoin="round";for(let a=0;a0)){let l=o.bodyLabels.slice();l=_(l,"[score]",100*t[a].score),ne(r,l,t[a].box[0],t[a].box[1],o)}if(o.drawPoints&&t[a].keypoints)for(let l=0;l0&&t[a].keypoints){r.font=o.font;for(let l of t[a].keypoints){if(!l.score||l.score===0)continue;let c=o.bodyPartLabels.slice();c=_(c,"[label]",l.part),c=_(c,"[score]",100*l.score),ne(r,c,l.position[0],l.position[1],o)}}if(o.drawPolygons&&t[a].keypoints&&t[a].annotations)for(let l of Object.values(t[a].annotations))for(let c of l)Z1(r,c,o)}}}function Q2(e,t,n){var s,A;let o=a0(x0,n);if(!t||!e)return;let r=Q0(e);if(!!r){r.lineJoin="round",r.font=o.font;for(let a of t){if(o.drawBoxes){if(r.strokeStyle=o.color,r.fillStyle=o.color,pe(r,a.box[0],a.box[1],a.box[2],a.box[3],o),o.drawLabels&&((s=o.handLabels)==null?void 0:s.length)>0){let l=o.handLabels.slice();l=_(l,"[label]",a.label),l=_(l,"[score]",100*a.score),ne(r,l,a.box[0],a.box[1],o)}r.stroke()}if(o.drawPoints&&a.keypoints&&a.keypoints.length>0)for(let l of a.keypoints)r.fillStyle=Je(l[2],o),Te(r,l[0],l[1],0,o);if(o.drawLabels&&a.annotations&&((A=o.fingerLabels)==null?void 0:A.length)>0)for(let[l,c]of Object.entries(a.annotations)){let x=o.fingerLabels.slice();x=_(x,"[label]",l),ne(r,x,c[c.length-1][0],c[c.length-1][1],o)}if(o.drawPolygons&&a.annotations){let l=c=>{if(!(!c||c.length===0||!c[0]))for(let x=0;x0?x-1:0][0],c[x>0?x-1:0][1]),r.lineTo(c[x][0],c[x][1]),r.stroke()}};r.lineWidth=o.lineWidth,l(a.annotations.index),l(a.annotations.middle),l(a.annotations.ring),l(a.annotations.pinky),l(a.annotations.thumb)}}}}function _2(e,t,n){var s;let o=a0(x0,n);if(!t||!e)return;let r=Q0(e);if(!!r){r.lineJoin="round",r.font=o.font;for(let A of t)if(o.drawBoxes){if(r.strokeStyle=o.color,r.fillStyle=o.color,pe(r,A.box[0],A.box[1],A.box[2],A.box[3],o),o.drawLabels&&((s=o.objectLabels)==null?void 0:s.length)>0){let a=o.objectLabels.slice();a=_(a,"[label]",A.label),a=_(a,"[score]",100*A.score),ne(r,a,A.box[0],A.box[1],o)}r.stroke()}}}function $2(e,t,n){var r;let o=a0(x0,n);if(!(!t||!e)&&o.drawGestures&&((r=o.gestureLabels)==null?void 0:r.length)>0){let s=Q0(e);if(!s)return;s.font=o.font,s.fillStyle=o.color;let A=1;for(let a=0;a1&&c[1].length>0){let x=l[1]>0?`#${l[1]}`:"",i=o.gestureLabels.slice();i=_(i,"[where]",l[0]),i=_(i,"[who]",x),i=_(i,"[what]",c[1]),ne(s,i,8,2+A*o.lineHeight,o),A+=1}}}}var Ie={face:`face confidence: [score]% [gender] [genderScore]% age: [age] years @@ -6467,7523 +118,7 @@ var defaultLabels = { live: [live]% [emotions] roll: [roll]\xB0 yaw:[yaw]\xB0 pitch:[pitch]\xB0 - gaze: [gaze]\xB0`, - body: "body [score]%", - bodyPart: "[label] [score]%", - object: "[label] [score]%", - hand: "[label] [score]%", - finger: "[label]", - gesture: "[where] [who]: [what]" -}; - -// src/draw/draw.ts -var drawTime = 0; -function person(inCanvas2, result, drawOptions) { - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - ctx.font = localOptions2.font; - for (let i = 0; i < result.length; i++) { - if (localOptions2.drawBoxes) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - rect(ctx, result[i].box[0], result[i].box[1], result[i].box[2], result[i].box[3], localOptions2); - if (localOptions2.drawLabels) { - const label = `person #${i}`; - if (localOptions2.shadowColor && localOptions2.shadowColor !== "") { - ctx.fillStyle = localOptions2.shadowColor; - ctx.fillText(label, result[i].box[0] + 3, 1 + result[i].box[1] + localOptions2.lineHeight, result[i].box[2]); - } - ctx.fillStyle = localOptions2.labelColor; - ctx.fillText(label, result[i].box[0] + 2, 0 + result[i].box[1] + localOptions2.lineHeight, result[i].box[2]); - } - ctx.stroke(); - } - } -} -function canvas2(input, output) { - if (!input || !output) - return; - const ctx = getCanvasContext(output); - if (!ctx) - return; - ctx.drawImage(input, 0, 0); -} -async function all(inCanvas2, result, drawOptions) { - if (!(result == null ? void 0 : result.performance) || !inCanvas2) - return null; - const timeStamp = now(); - const localOptions2 = mergeDeep(options2, drawOptions); - const promise = Promise.all([ - face(inCanvas2, result.face, localOptions2), - body(inCanvas2, result.body, localOptions2), - hand(inCanvas2, result.hand, localOptions2), - object(inCanvas2, result.object, localOptions2), - gesture(inCanvas2, result.gesture, localOptions2) - ]); - drawTime = env.perfadd ? drawTime + Math.round(now() - timeStamp) : Math.round(now() - timeStamp); - result.performance.draw = drawTime; - return promise; -} -function init2() { - options2.faceLabels = defaultLabels.face; - options2.bodyLabels = defaultLabels.body; - options2.bodyPartLabels = defaultLabels.bodyPart; - options2.handLabels = defaultLabels.hand; - options2.fingerLabels = defaultLabels.finger; - options2.objectLabels = defaultLabels.object; - options2.gestureLabels = defaultLabels.gesture; -} - -// src/body/blazepose.ts -var tf9 = __toESM(require_tfjs_esm()); - -// src/body/blazeposecoords.ts -var blazeposecoords_exports = {}; -__export(blazeposecoords_exports, { - connected: () => connected, - kpt: () => kpt -}); -var kpt = [ - "nose", - "leftEyeInside", - "leftEye", - "leftEyeOutside", - "rightEyeInside", - "rightEye", - "rightEyeOutside", - "leftEar", - "rightEar", - "leftMouth", - "rightMouth", - "leftShoulder", - "rightShoulder", - "leftElbow", - "rightElbow", - "leftWrist", - "rightWrist", - "leftPinky", - "rightPinky", - "leftIndex", - "rightIndex", - "leftThumb", - "rightThumb", - "leftHip", - "rightHip", - "leftKnee", - "rightKnee", - "leftAnkle", - "rightAnkle", - "leftHeel", - "rightHeel", - "leftFoot", - "rightFoot", - "bodyCenter", - "bodyTop", - "leftPalm", - "leftHand", - "rightPalm", - "rightHand" -]; -var connected = { - shoulders: ["leftShoulder", "rightShoulder"], - hips: ["rightHip", "leftHip"], - mouth: ["leftMouth", "rightMouth"], - leftLegUpper: ["leftHip", "leftKnee"], - leftLegLower: ["leftKnee", "leftAnkle"], - leftFoot: ["leftAnkle", "leftHeel", "leftFoot"], - leftTorso: ["leftShoulder", "leftHip"], - leftArmUpper: ["leftShoulder", "leftElbow"], - leftArmLower: ["leftElbow", "leftWrist"], - leftHand: ["leftWrist", "leftPalm"], - leftHandPinky: ["leftPalm", "leftPinky"], - leftHandIndex: ["leftPalm", "leftIndex"], - leftHandThumb: ["leftPalm", "leftThumb"], - leftEyeOutline: ["leftEyeInside", "leftEyeOutside"], - rightLegUpper: ["rightHip", "rightKnee"], - rightLegLower: ["rightKnee", "rightAnkle"], - rightFoot: ["rightAnkle", "rightHeel", "rightFoot"], - rightTorso: ["rightShoulder", "rightHip"], - rightArmUpper: ["rightShoulder", "rightElbow"], - rightArmLower: ["rightElbow", "rightWrist"], - rightHand: ["rightWrist", "rightPalm"], - rightHandPinky: ["rightPalm", "rightPinky"], - rightHandIndex: ["rightPalm", "rightIndex"], - rightHandThumb: ["rightPalm", "rightThumb"], - rightEyeOutline: ["rightEyeInside", "rightEyeOutside"] -}; - -// src/body/blazeposedetector.ts -var tf8 = __toESM(require_tfjs_esm()); -var model; -var inputSize = 224; -var anchorTensor; -var numLayers = 5; -var strides = [8, 16, 32, 32, 32]; -function createAnchors() { - const anchors3 = []; - let layerId = 0; - while (layerId < numLayers) { - let anchorCount = 0; - let lastSameStrideLayer = layerId; - while (lastSameStrideLayer < strides.length && strides[lastSameStrideLayer] === strides[layerId]) { - anchorCount += 2; - lastSameStrideLayer++; - } - const stride = strides[layerId]; - const featureMapHeight = Math.ceil(inputSize / stride); - const featureMapWidth = Math.ceil(inputSize / stride); - for (let y = 0; y < featureMapHeight; ++y) { - for (let x = 0; x < featureMapWidth; ++x) { - for (let anchorId = 0; anchorId < anchorCount; ++anchorId) { - anchors3.push({ x: (x + 0.5) / featureMapWidth, y: (y + 0.5) / featureMapHeight }); - } - } - } - layerId = lastSameStrideLayer; - } - anchorTensor = { x: tf8.tensor1d(anchors3.map((a) => a.x)), y: tf8.tensor1d(anchors3.map((a) => a.y)) }; -} -async function loadDetector(config3) { - if (env.initial) - model = null; - if (!model && config3.body["detector"] && config3.body["detector"].modelPath || "") { - model = await loadModel(config3.body["detector"].modelPath); - const inputs = (model == null ? void 0 : model["executor"]) ? Object.values(model.modelSignature["inputs"]) : void 0; - inputSize = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - } else if (config3.debug && model) - log("cached model:", model["modelUrl"]); - createAnchors(); - return model; -} -var cropFactor = [5, 5]; -function decodeBoxes(boxesTensor, anchor) { - return tf8.tidy(() => { - const split6 = tf8.split(boxesTensor, 12, 1); - let xCenter = tf8.squeeze(split6[0]); - let yCenter = tf8.squeeze(split6[1]); - let width = tf8.squeeze(split6[2]); - let height = tf8.squeeze(split6[3]); - xCenter = tf8.add(tf8.div(xCenter, inputSize), anchor.x); - yCenter = tf8.add(tf8.div(yCenter, inputSize), anchor.y); - width = tf8.mul(tf8.div(width, inputSize), cropFactor[0]); - height = tf8.mul(tf8.div(height, inputSize), cropFactor[1]); - const xMin = tf8.sub(xCenter, tf8.div(width, 2)); - const yMin = tf8.sub(yCenter, tf8.div(height, 2)); - const xMax = tf8.add(xMin, width); - const yMax = tf8.add(yMin, height); - const boxes = tf8.stack([xMin, yMin, xMax, yMax], 1); - return boxes; - }); -} -async function decodeResults(boxesTensor, logitsTensor, config3, outputSize2) { - var _a, _b; - const detectedBoxes = []; - const t2 = {}; - t2.boxes = decodeBoxes(boxesTensor, anchorTensor); - t2.scores = tf8.sigmoid(logitsTensor); - t2.nms = await tf8.image.nonMaxSuppressionAsync(t2.boxes, t2.scores, 1, ((_a = config3.body["detector"]) == null ? void 0 : _a.minConfidence) || 0.1, ((_b = config3.body["detector"]) == null ? void 0 : _b.iouThreshold) || 0.1); - const nms = await t2.nms.data(); - const scores = await t2.scores.data(); - const boxes = await t2.boxes.array(); - for (const i of Array.from(nms)) { - const score = scores[i]; - const boxRaw = boxes[i]; - const box = [Math.round(boxRaw[0] * outputSize2[0]), Math.round(boxRaw[1] * outputSize2[1]), Math.round(boxRaw[2] * outputSize2[0]), Math.round(boxRaw[3] * outputSize2[1])]; - const detectedBox = { score, boxRaw, box }; - detectedBoxes.push(detectedBox); - } - Object.keys(t2).forEach((tensor6) => tf8.dispose(t2[tensor6])); - return detectedBoxes; -} -async function detectBoxes(input, config3, outputSize2) { - const t2 = {}; - t2.res = model == null ? void 0 : model.execute(input, ["Identity"]); - t2.logitsRaw = tf8.slice(t2.res, [0, 0, 0], [1, -1, 1]); - t2.boxesRaw = tf8.slice(t2.res, [0, 0, 1], [1, -1, -1]); - t2.logits = tf8.squeeze(t2.logitsRaw); - t2.boxes = tf8.squeeze(t2.boxesRaw); - const boxes = await decodeResults(t2.boxes, t2.logits, config3, outputSize2); - Object.keys(t2).forEach((tensor6) => tf8.dispose(t2[tensor6])); - return boxes; -} - -// src/util/box.ts -function calc(keypoints, outputSize2 = [1, 1]) { - const coords = [keypoints.map((pt) => pt[0]), keypoints.map((pt) => pt[1])]; - const min2 = [Math.min(...coords[0]), Math.min(...coords[1])]; - const max5 = [Math.max(...coords[0]), Math.max(...coords[1])]; - const box = [min2[0], min2[1], max5[0] - min2[0], max5[1] - min2[1]]; - const boxRaw = [box[0] / outputSize2[0], box[1] / outputSize2[1], box[2] / outputSize2[0], box[3] / outputSize2[1]]; - return { box, boxRaw }; -} -function square(keypoints, outputSize2 = [1, 1]) { - const coords = [keypoints.map((pt) => pt[0]), keypoints.map((pt) => pt[1])]; - const min2 = [Math.min(...coords[0]), Math.min(...coords[1])]; - const max5 = [Math.max(...coords[0]), Math.max(...coords[1])]; - const center = [(min2[0] + max5[0]) / 2, (min2[1] + max5[1]) / 2]; - const dist = Math.max(center[0] - min2[0], center[1] - min2[1], -center[0] + max5[0], -center[1] + max5[1]); - const box = [Math.trunc(center[0] - dist), Math.trunc(center[1] - dist), Math.trunc(2 * dist), Math.trunc(2 * dist)]; - const boxRaw = [box[0] / outputSize2[0], box[1] / outputSize2[1], box[2] / outputSize2[0], box[3] / outputSize2[1]]; - return { box, boxRaw }; -} -function scale(box, scaleFact) { - const dist = [box[2] * scaleFact, box[3] * scaleFact]; - const newBox = [ - box[0] - (dist[0] - box[2]) / 2, - box[1] - (dist[1] - box[3]) / 2, - dist[0], - dist[1] - ]; - return newBox; -} - -// src/body/blazepose.ts -var model2; -var inputSize2 = 256; -var skipped = Number.MAX_SAFE_INTEGER; -var outputNodes = { - landmarks: ["ld_3d", "activation_segmentation", "activation_heatmap", "world_3d", "output_poseflag"], - detector: [] -}; -var cache = []; -var padding = [[0, 0], [0, 0], [0, 0], [0, 0]]; -var lastTime = 0; -var sigmoid2 = (x) => 1 - 1 / (1 + Math.exp(x)); -var loadDetect = (config3) => loadDetector(config3); -async function loadPose(config3) { - if (env.initial) - model2 = null; - if (!model2) { - model2 = await loadModel(config3.body.modelPath); - const inputs = (model2 == null ? void 0 : model2["executor"]) ? Object.values(model2.modelSignature["inputs"]) : void 0; - inputSize2 = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - } else if (config3.debug) - log("cached model:", model2["modelUrl"]); - return model2; -} -function prepareImage(input, size2, cropBox) { - var _a, _b; - const t2 = {}; - if (!((_a = input == null ? void 0 : input.shape) == null ? void 0 : _a[1]) || !((_b = input == null ? void 0 : input.shape) == null ? void 0 : _b[2])) - return input; - let final; - if (cropBox) { - t2.cropped = tf9.image.cropAndResize(input, [cropBox], [0], [input.shape[1], input.shape[2]]); - } - if (input.shape[1] !== input.shape[2]) { - const height = [ - input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0, - input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0 - ]; - const width = [ - input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0, - input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0 - ]; - padding = [ - [0, 0], - height, - width, - [0, 0] - ]; - t2.pad = tf9.pad(t2.cropped || input, padding); - t2.resize = tf9.image.resizeBilinear(t2.pad, [size2, size2]); - final = tf9.div(t2.resize, constants.tf255); - } else if (input.shape[1] !== size2) { - t2.resize = tf9.image.resizeBilinear(t2.cropped || input, [size2, size2]); - final = tf9.div(t2.resize, constants.tf255); - } else { - final = tf9.div(t2.cropped || input, constants.tf255); - } - Object.keys(t2).forEach((tensor6) => tf9.dispose(t2[tensor6])); - return final; -} -function rescaleKeypoints(keypoints, outputSize2, cropBox) { - for (const kpt4 of keypoints) { - kpt4.position = [ - Math.trunc(kpt4.position[0] * (outputSize2[0] + padding[2][0] + padding[2][1]) / outputSize2[0] - padding[2][0]), - Math.trunc(kpt4.position[1] * (outputSize2[1] + padding[1][0] + padding[1][1]) / outputSize2[1] - padding[1][0]), - kpt4.position[2] - ]; - kpt4.positionRaw = [kpt4.position[0] / outputSize2[0], kpt4.position[1] / outputSize2[1], 2 * kpt4.position[2] / (outputSize2[0] + outputSize2[1])]; - } - if (cropBox) { - const width = cropBox[2] - cropBox[0]; - const height = cropBox[3] - cropBox[1]; - for (const kpt4 of keypoints) { - kpt4.positionRaw = [ - kpt4.positionRaw[0] / height + cropBox[1], - kpt4.positionRaw[1] / width + cropBox[0], - kpt4.positionRaw[2] - ]; - kpt4.position = [ - Math.trunc(kpt4.positionRaw[0] * outputSize2[0]), - Math.trunc(kpt4.positionRaw[1] * outputSize2[1]), - kpt4.positionRaw[2] - ]; - } - } - return keypoints; -} -function fixKeypoints(keypoints) { - const leftPalm = keypoints.find((k) => k.part === "leftPalm"); - const leftWrist = keypoints.find((k) => k.part === "leftWrist"); - const leftIndex = keypoints.find((k) => k.part === "leftIndex"); - leftPalm.position[2] = ((leftWrist.position[2] || 0) + (leftIndex.position[2] || 0)) / 2; - const rightPalm = keypoints.find((k) => k.part === "rightPalm"); - const rightWrist = keypoints.find((k) => k.part === "rightWrist"); - const rightIndex = keypoints.find((k) => k.part === "rightIndex"); - rightPalm.position[2] = ((rightWrist.position[2] || 0) + (rightIndex.position[2] || 0)) / 2; -} -async function detectLandmarks(input, config3, outputSize2) { - if (!(model2 == null ? void 0 : model2["executor"])) - return null; - const t2 = {}; - [t2.ld, t2.segmentation, t2.heatmap, t2.world, t2.poseflag] = model2 == null ? void 0 : model2.execute(input, outputNodes.landmarks); - const poseScore = (await t2.poseflag.data())[0]; - const points = await t2.ld.data(); - const distances = await t2.world.data(); - Object.keys(t2).forEach((tensor6) => tf9.dispose(t2[tensor6])); - const keypointsRelative = []; - const depth = 5; - for (let i = 0; i < points.length / depth; i++) { - const score = sigmoid2(points[depth * i + 3]); - const presence = sigmoid2(points[depth * i + 4]); - const adjScore = Math.trunc(100 * score * presence * poseScore) / 100; - const positionRaw = [points[depth * i + 0] / inputSize2, points[depth * i + 1] / inputSize2, points[depth * i + 2] + 0]; - const position = [Math.trunc(outputSize2[0] * positionRaw[0]), Math.trunc(outputSize2[1] * positionRaw[1]), positionRaw[2]]; - const distance2 = [distances[depth * i + 0], distances[depth * i + 1], distances[depth * i + 2] + 0]; - keypointsRelative.push({ part: kpt[i], positionRaw, position, distance: distance2, score: adjScore }); - } - if (poseScore < (config3.body.minConfidence || 0)) - return null; - fixKeypoints(keypointsRelative); - const keypoints = rescaleKeypoints(keypointsRelative, outputSize2); - const kpts = keypoints.map((k) => k.position); - const boxes = calc(kpts, [outputSize2[0], outputSize2[1]]); - const annotations2 = {}; - for (const [name, indexes] of Object.entries(connected)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = keypoints.find((kpt4) => kpt4.part === indexes[i]); - const pt1 = keypoints.find((kpt4) => kpt4.part === indexes[i + 1]); - if (pt0 && pt1) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - const body4 = { id: 0, score: Math.trunc(100 * poseScore) / 100, box: boxes.box, boxRaw: boxes.boxRaw, keypoints, annotations: annotations2 }; - return body4; -} -async function predict(input, config3) { - var _a, _b, _c; - const outputSize2 = [input.shape[2] || 0, input.shape[1] || 0]; - const skipTime = (config3.body.skipTime || 0) > now() - lastTime; - const skipFrame = skipped < (config3.body.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && cache !== null) { - skipped++; - } else { - let boxes = []; - if ((_b = (_a = config3.body) == null ? void 0 : _a["detector"]) == null ? void 0 : _b["enabled"]) { - const preparedImage = prepareImage(input, 224); - boxes = await detectBoxes(preparedImage, config3, outputSize2); - tf9.dispose(preparedImage); - } else { - boxes = [{ box: [0, 0, 0, 0], boxRaw: [0, 0, 1, 1], score: 0 }]; - } - for (let i = 0; i < boxes.length; i++) { - const preparedBox = prepareImage(input, 256, (_c = boxes[i]) == null ? void 0 : _c.boxRaw); - cache.length = 0; - const bodyResult = await detectLandmarks(preparedBox, config3, outputSize2); - tf9.dispose(preparedBox); - if (!bodyResult) - continue; - bodyResult.id = i; - cache.push(bodyResult); - } - lastTime = now(); - skipped = 0; - } - return cache; -} - -// src/object/centernet.ts -var tf10 = __toESM(require_tfjs_esm()); - -// src/object/labels.ts -var labels2 = [ - { class: 1, label: "person" }, - { class: 2, label: "bicycle" }, - { class: 3, label: "car" }, - { class: 4, label: "motorcycle" }, - { class: 5, label: "airplane" }, - { class: 6, label: "bus" }, - { class: 7, label: "train" }, - { class: 8, label: "truck" }, - { class: 9, label: "boat" }, - { class: 10, label: "traffic light" }, - { class: 11, label: "fire hydrant" }, - { class: 12, label: "stop sign" }, - { class: 13, label: "parking meter" }, - { class: 14, label: "bench" }, - { class: 15, label: "bird" }, - { class: 16, label: "cat" }, - { class: 17, label: "dog" }, - { class: 18, label: "horse" }, - { class: 19, label: "sheep" }, - { class: 20, label: "cow" }, - { class: 21, label: "elephant" }, - { class: 22, label: "bear" }, - { class: 23, label: "zebra" }, - { class: 24, label: "giraffe" }, - { class: 25, label: "backpack" }, - { class: 26, label: "umbrella" }, - { class: 27, label: "handbag" }, - { class: 28, label: "tie" }, - { class: 29, label: "suitcase" }, - { class: 30, label: "frisbee" }, - { class: 31, label: "skis" }, - { class: 32, label: "snowboard" }, - { class: 33, label: "sports ball" }, - { class: 34, label: "kite" }, - { class: 35, label: "baseball bat" }, - { class: 36, label: "baseball glove" }, - { class: 37, label: "skateboard" }, - { class: 38, label: "surfboard" }, - { class: 39, label: "tennis racket" }, - { class: 40, label: "bottle" }, - { class: 41, label: "wine glass" }, - { class: 42, label: "cup" }, - { class: 43, label: "fork" }, - { class: 44, label: "knife" }, - { class: 45, label: "spoon" }, - { class: 46, label: "bowl" }, - { class: 47, label: "banana" }, - { class: 48, label: "apple" }, - { class: 49, label: "sandwich" }, - { class: 50, label: "orange" }, - { class: 51, label: "broccoli" }, - { class: 52, label: "carrot" }, - { class: 53, label: "hot dog" }, - { class: 54, label: "pizza" }, - { class: 55, label: "donut" }, - { class: 56, label: "cake" }, - { class: 57, label: "chair" }, - { class: 58, label: "couch" }, - { class: 59, label: "potted plant" }, - { class: 60, label: "bed" }, - { class: 61, label: "dining table" }, - { class: 62, label: "toilet" }, - { class: 63, label: "tv" }, - { class: 64, label: "laptop" }, - { class: 65, label: "mouse" }, - { class: 66, label: "remote" }, - { class: 67, label: "keyboard" }, - { class: 68, label: "cell phone" }, - { class: 69, label: "microwave" }, - { class: 70, label: "oven" }, - { class: 71, label: "toaster" }, - { class: 72, label: "sink" }, - { class: 73, label: "refrigerator" }, - { class: 74, label: "book" }, - { class: 75, label: "clock" }, - { class: 76, label: "vase" }, - { class: 77, label: "scissors" }, - { class: 78, label: "teddy bear" }, - { class: 79, label: "hair drier" }, - { class: 80, label: "toothbrush" } -]; - -// src/object/centernet.ts -var model3; -var inputSize3 = 0; -var last2 = []; -var lastTime2 = 0; -var skipped2 = Number.MAX_SAFE_INTEGER; -async function load(config3) { - if (env.initial) - model3 = null; - if (!model3) { - model3 = await loadModel(config3.object.modelPath); - const inputs = (model3 == null ? void 0 : model3["executor"]) ? Object.values(model3.modelSignature["inputs"]) : void 0; - inputSize3 = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 0; - } else if (config3.debug) - log("cached model:", model3["modelUrl"]); - return model3; -} -async function process3(res, outputShape, config3) { - if (!res) - return []; - const t2 = {}; - const results = []; - const detections = await res.array(); - t2.squeeze = tf10.squeeze(res); - const arr = tf10.split(t2.squeeze, 6, 1); - t2.stack = tf10.stack([arr[1], arr[0], arr[3], arr[2]], 1); - t2.boxes = tf10.squeeze(t2.stack); - t2.scores = tf10.squeeze(arr[4]); - t2.classes = tf10.squeeze(arr[5]); - tf10.dispose([res, ...arr]); - t2.nms = await tf10.image.nonMaxSuppressionAsync(t2.boxes, t2.scores, config3.object.maxDetected || 0, config3.object.iouThreshold, config3.object.minConfidence || 0); - const nms = await t2.nms.data(); - let i = 0; - for (const id of Array.from(nms)) { - const score = Math.trunc(100 * detections[0][id][4]) / 100; - const classVal = detections[0][id][5]; - if (Number.isNaN(classVal)) - continue; - const label = labels2[classVal].label; - const [x, y] = [ - detections[0][id][0] / inputSize3, - detections[0][id][1] / inputSize3 - ]; - const boxRaw = [ - x, - y, - detections[0][id][2] / inputSize3 - x, - detections[0][id][3] / inputSize3 - y - ]; - const box = [ - Math.trunc(boxRaw[0] * outputShape[0]), - Math.trunc(boxRaw[1] * outputShape[1]), - Math.trunc(boxRaw[2] * outputShape[0]), - Math.trunc(boxRaw[3] * outputShape[1]) - ]; - results.push({ id: i++, score, class: classVal, label, box, boxRaw }); - } - Object.keys(t2).forEach((tensor6) => tf10.dispose(t2[tensor6])); - return results; -} -async function predict2(input, config3) { - if (!(model3 == null ? void 0 : model3["executor"])) - return []; - const skipTime = (config3.object.skipTime || 0) > now() - lastTime2; - const skipFrame = skipped2 < (config3.object.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && last2.length > 0) { - skipped2++; - return last2; - } - skipped2 = 0; - return new Promise(async (resolve) => { - const outputSize2 = [input.shape[2] || 0, input.shape[1] || 0]; - const resize = tf10.image.resizeBilinear(input, [inputSize3, inputSize3]); - const objectT = config3.object.enabled ? model3 == null ? void 0 : model3.execute(resize, ["tower_0/detections"]) : null; - lastTime2 = now(); - tf10.dispose(resize); - const obj = await process3(objectT, outputSize2, config3); - last2 = obj; - resolve(obj); - }); -} - -// src/body/efficientpose.ts -var tf11 = __toESM(require_tfjs_esm()); - -// src/body/efficientposecoords.ts -var efficientposecoords_exports = {}; -__export(efficientposecoords_exports, { - connected: () => connected2, - kpt: () => kpt2 -}); -var kpt2 = [ - "head", - "neck", - "rightShoulder", - "rightElbow", - "rightWrist", - "chest", - "leftShoulder", - "leftElbow", - "leftWrist", - "bodyCenter", - "rightHip", - "rightKnee", - "rightAnkle", - "leftHip", - "leftKnee", - "leftAnkle" -]; -var connected2 = { - leftLeg: ["leftHip", "leftKnee", "leftAnkle"], - rightLeg: ["rightHip", "rightKnee", "rightAnkle"], - torso: ["leftShoulder", "rightShoulder", "rightHip", "leftHip", "leftShoulder"], - leftArm: ["leftShoulder", "leftElbow", "leftWrist"], - rightArm: ["rightShoulder", "rightElbow", "rightWrist"], - head: [] -}; - -// src/body/efficientpose.ts -var model4; -var lastTime3 = 0; -var cache2 = { id: 0, keypoints: [], box: [0, 0, 0, 0], boxRaw: [0, 0, 0, 0], score: 0, annotations: {} }; -var skipped3 = Number.MAX_SAFE_INTEGER; -async function load2(config3) { - if (env.initial) - model4 = null; - if (!model4) - model4 = await loadModel(config3.body.modelPath); - else if (config3.debug) - log("cached model:", model4["modelUrl"]); - return model4; -} -async function max2d(inputs, minScore) { - const [width, height] = inputs.shape; - const reshaped = tf11.reshape(inputs, [height * width]); - const max5 = tf11.max(reshaped, 0); - const newScore = (await max5.data())[0]; - if (newScore > minScore) { - const coordinates = tf11.argMax(reshaped, 0); - const mod3 = tf11.mod(coordinates, width); - const x = (await mod3.data())[0]; - const div15 = tf11.div(coordinates, width); - const y = (await div15.data())[0]; - tf11.dispose([reshaped, max5, coordinates, mod3, div15]); - return [x, y, newScore]; - } - tf11.dispose([reshaped, max5]); - return [0, 0, newScore]; -} -async function predict3(image28, config3) { - if (!(model4 == null ? void 0 : model4["executor"]) || !(model4 == null ? void 0 : model4.inputs[0].shape)) - return []; - const skipTime = (config3.body.skipTime || 0) > now() - lastTime3; - const skipFrame = skipped3 < (config3.body.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && Object.keys(cache2.keypoints).length > 0) { - skipped3++; - return [cache2]; - } - skipped3 = 0; - return new Promise(async (resolve) => { - const tensor6 = tf11.tidy(() => { - var _a, _b; - const resize = tf11.image.resizeBilinear(image28, [((_a = model4 == null ? void 0 : model4.inputs[0].shape) == null ? void 0 : _a[2]) || 0, ((_b = model4 == null ? void 0 : model4.inputs[0].shape) == null ? void 0 : _b[1]) || 0], false); - const enhance2 = tf11.mul(resize, constants.tf2); - const norm = tf11.sub(enhance2, constants.tf1); - return norm; - }); - let resT; - if (config3.body.enabled) - resT = model4 == null ? void 0 : model4.execute(tensor6); - lastTime3 = now(); - tf11.dispose(tensor6); - if (resT) { - cache2.keypoints.length = 0; - const squeeze14 = tf11.squeeze(resT); - tf11.dispose(resT); - const stack5 = tf11.unstack(squeeze14, 2); - tf11.dispose(squeeze14); - for (let id = 0; id < stack5.length; id++) { - const [x2, y2, partScore] = await max2d(stack5[id], config3.body.minConfidence); - if (partScore > (config3.body.minConfidence || 0)) { - cache2.keypoints.push({ - score: Math.round(100 * partScore) / 100, - part: kpt2[id], - positionRaw: [ - x2 / model4.inputs[0].shape[2], - y2 / model4.inputs[0].shape[1] - ], - position: [ - Math.round(image28.shape[2] * x2 / model4.inputs[0].shape[2]), - Math.round(image28.shape[1] * y2 / model4.inputs[0].shape[1]) - ] - }); - } - } - stack5.forEach((s) => tf11.dispose(s)); - } - cache2.score = cache2.keypoints.reduce((prev, curr) => curr.score > prev ? curr.score : prev, 0); - const x = cache2.keypoints.map((a) => a.position[0]); - const y = cache2.keypoints.map((a) => a.position[1]); - cache2.box = [ - Math.min(...x), - Math.min(...y), - Math.max(...x) - Math.min(...x), - Math.max(...y) - Math.min(...y) - ]; - const xRaw = cache2.keypoints.map((a) => a.positionRaw[0]); - const yRaw = cache2.keypoints.map((a) => a.positionRaw[1]); - cache2.boxRaw = [ - Math.min(...xRaw), - Math.min(...yRaw), - Math.max(...xRaw) - Math.min(...xRaw), - Math.max(...yRaw) - Math.min(...yRaw) - ]; - for (const [name, indexes] of Object.entries(connected2)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = cache2.keypoints.find((kpt4) => kpt4.part === indexes[i]); - const pt1 = cache2.keypoints.find((kpt4) => kpt4.part === indexes[i + 1]); - if (pt0 && pt1 && pt0.score > (config3.body.minConfidence || 0) && pt1.score > (config3.body.minConfidence || 0)) - pt.push([pt0.position, pt1.position]); - } - cache2.annotations[name] = pt; - } - resolve([cache2]); - }); -} - -// src/face/face.ts -var tf25 = __toESM(require_tfjs_esm()); - -// src/face/facemesh.ts -var tf15 = __toESM(require_tfjs_esm()); - -// src/face/blazeface.ts -var tf13 = __toESM(require_tfjs_esm()); - -// src/face/facemeshutil.ts -var tf12 = __toESM(require_tfjs_esm()); -var getBoxSize = (box) => [Math.abs(box.endPoint[0] - box.startPoint[0]), Math.abs(box.endPoint[1] - box.startPoint[1])]; -var getBoxCenter = (box) => [box.startPoint[0] + (box.endPoint[0] - box.startPoint[0]) / 2, box.startPoint[1] + (box.endPoint[1] - box.startPoint[1]) / 2, 1]; -var clampBox = (box, input) => box ? [ - Math.trunc(Math.max(0, box.startPoint[0])), - Math.trunc(Math.max(0, box.startPoint[1])), - Math.trunc(Math.min(input.shape[2] || 0, box.endPoint[0]) - Math.max(0, box.startPoint[0])), - Math.trunc(Math.min(input.shape[1] || 0, box.endPoint[1]) - Math.max(0, box.startPoint[1])) -] : [0, 0, 0, 0]; -var getRawBox = (box, input) => box ? [ - box.startPoint[0] / (input.shape[2] || 0), - box.startPoint[1] / (input.shape[1] || 0), - (box.endPoint[0] - box.startPoint[0]) / (input.shape[2] || 0), - (box.endPoint[1] - box.startPoint[1]) / (input.shape[1] || 0) -] : [0, 0, 0, 0]; -var scaleBoxCoordinates = (box, factor) => { - const startPoint = [box.startPoint[0] * factor[0], box.startPoint[1] * factor[1]]; - const endPoint = [box.endPoint[0] * factor[0], box.endPoint[1] * factor[1]]; - return { startPoint, endPoint, landmarks: box.landmarks, confidence: box.confidence }; -}; -var cutAndResize = (box, image28, cropSize) => { - const h = image28.shape[1]; - const w = image28.shape[2]; - const cutBox = [box.startPoint[1] / h, box.startPoint[0] / w, box.endPoint[1] / h, box.endPoint[0] / w]; - const crop = tf12.image.cropAndResize(image28, [cutBox], [0], cropSize); - const norm = tf12.div(crop, constants.tf255); - tf12.dispose(crop); - return norm; -}; -var enlargeBox = (box, factor) => { - const center = getBoxCenter(box); - const size2 = getBoxSize(box); - const halfSize = [factor * size2[0] / 2, factor * size2[1] / 2]; - return { startPoint: [center[0] - halfSize[0], center[1] - halfSize[1]], endPoint: [center[0] + halfSize[0], center[1] + halfSize[1]], landmarks: box.landmarks, confidence: box.confidence }; -}; -var squarifyBox = (box) => { - const centers = getBoxCenter(box); - const size2 = getBoxSize(box); - const halfSize = Math.max(...size2) / 2; - return { startPoint: [Math.round(centers[0] - halfSize), Math.round(centers[1] - halfSize)], endPoint: [Math.round(centers[0] + halfSize), Math.round(centers[1] + halfSize)], landmarks: box.landmarks, confidence: box.confidence }; -}; -var calculateLandmarksBoundingBox = (landmarks) => { - const x = landmarks.map((d) => d[0]); - const y = landmarks.map((d) => d[1]); - return { startPoint: [Math.min(...x), Math.min(...y)], endPoint: [Math.max(...x), Math.max(...y)], landmarks }; -}; -var fixedRotationMatrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; -var normalizeRadians = (angle) => angle - 2 * Math.PI * Math.floor((angle + Math.PI) / (2 * Math.PI)); -var computeRotation = (point1, point2) => normalizeRadians(Math.PI / 2 - Math.atan2(-(point2[1] - point1[1]), point2[0] - point1[0])); -var buildTranslationMatrix = (x, y) => [[1, 0, x], [0, 1, y], [0, 0, 1]]; -var dot = (v1, v2) => { - let product = 0; - for (let i = 0; i < v1.length; i++) - product += v1[i] * v2[i]; - return product; -}; -var getColumnFrom2DArr = (arr, columnIndex) => { - const column = []; - for (let i = 0; i < arr.length; i++) - column.push(arr[i][columnIndex]); - return column; -}; -var multiplyTransformMatrices = (mat1, mat2) => { - const product = []; - const size2 = mat1.length; - for (let row = 0; row < size2; row++) { - product.push([]); - for (let col = 0; col < size2; col++) - product[row].push(dot(mat1[row], getColumnFrom2DArr(mat2, col))); - } - return product; -}; -var buildRotationMatrix = (rotation, center) => { - const cosA = Math.cos(rotation); - const sinA = Math.sin(rotation); - const rotationMatrix = [[cosA, -sinA, 0], [sinA, cosA, 0], [0, 0, 1]]; - const translationMatrix = buildTranslationMatrix(center[0], center[1]); - const translationTimesRotation = multiplyTransformMatrices(translationMatrix, rotationMatrix); - const negativeTranslationMatrix = buildTranslationMatrix(-center[0], -center[1]); - return multiplyTransformMatrices(translationTimesRotation, negativeTranslationMatrix); -}; -var invertTransformMatrix = (matrix) => { - const rotationComponent = [[matrix[0][0], matrix[1][0]], [matrix[0][1], matrix[1][1]]]; - const translationComponent = [matrix[0][2], matrix[1][2]]; - const invertedTranslation = [-dot(rotationComponent[0], translationComponent), -dot(rotationComponent[1], translationComponent)]; - return [rotationComponent[0].concat(invertedTranslation[0]), rotationComponent[1].concat(invertedTranslation[1]), [0, 0, 1]]; -}; -var rotatePoint = (homogeneousCoordinate, rotationMatrix) => [dot(homogeneousCoordinate, rotationMatrix[0]), dot(homogeneousCoordinate, rotationMatrix[1])]; -function generateAnchors(inputSize10) { - const spec = inputSize10 === 192 ? { strides: [4], anchors: [1] } : { strides: [inputSize10 / 16, inputSize10 / 8], anchors: [2, 6] }; - const anchors3 = []; - for (let i = 0; i < spec.strides.length; i++) { - const stride = spec.strides[i]; - const gridRows = Math.floor((inputSize10 + stride - 1) / stride); - const gridCols = Math.floor((inputSize10 + stride - 1) / stride); - const anchorsNum = spec.anchors[i]; - for (let gridY = 0; gridY < gridRows; gridY++) { - const anchorY = stride * (gridY + 0.5); - for (let gridX = 0; gridX < gridCols; gridX++) { - const anchorX = stride * (gridX + 0.5); - for (let n = 0; n < anchorsNum; n++) - anchors3.push([anchorX, anchorY]); - } - } - } - return anchors3; -} -function transformRawCoords(coordsRaw, box, angle, rotationMatrix, inputSize10) { - const boxSize = getBoxSize(box); - const coordsScaled = coordsRaw.map((coord) => [ - boxSize[0] / inputSize10 * (coord[0] - inputSize10 / 2), - boxSize[1] / inputSize10 * (coord[1] - inputSize10 / 2), - coord[2] || 0 - ]); - const largeAngle = angle && angle !== 0 && Math.abs(angle) > 0.2; - const coordsRotationMatrix = largeAngle ? buildRotationMatrix(angle, [0, 0]) : fixedRotationMatrix; - const coordsRotated = largeAngle ? coordsScaled.map((coord) => [...rotatePoint(coord, coordsRotationMatrix), coord[2]]) : coordsScaled; - const inverseRotationMatrix = largeAngle ? invertTransformMatrix(rotationMatrix) : fixedRotationMatrix; - const boxCenter = getBoxCenter(box); - const offsets = [dot(boxCenter, inverseRotationMatrix[0]), dot(boxCenter, inverseRotationMatrix[1])]; - return coordsRotated.map((coord) => [ - Math.trunc(coord[0] + offsets[0]), - Math.trunc(coord[1] + offsets[1]), - Math.trunc(coord[2] || 0) - ]); -} -function correctFaceRotation(rotate, box, input, inputSize10) { - const symmetryLine = box.landmarks.length >= meshLandmarks.count ? meshLandmarks.symmetryLine : blazeFaceLandmarks.symmetryLine; - let angle = 0; - let rotationMatrix = fixedRotationMatrix; - let face4; - if (rotate && env.kernels.includes("rotatewithoffset")) { - angle = computeRotation(box.landmarks[symmetryLine[0]], box.landmarks[symmetryLine[1]]); - const largeAngle = angle && angle !== 0 && Math.abs(angle) > 0.2; - if (largeAngle) { - const center = getBoxCenter(box); - const centerRaw = [center[0] / input.shape[2], center[1] / input.shape[1]]; - const rotated = tf12.image.rotateWithOffset(input, angle, 0, [centerRaw[0], centerRaw[1]]); - rotationMatrix = buildRotationMatrix(-angle, center); - face4 = cutAndResize(box, rotated, [inputSize10, inputSize10]); - tf12.dispose(rotated); - } else { - face4 = cutAndResize(box, input, [inputSize10, inputSize10]); - } - } else { - face4 = cutAndResize(box, input, [inputSize10, inputSize10]); - } - return [angle, rotationMatrix, face4]; -} -var findFaceCenter = (mesh) => { - const x = mesh.map((m) => m[0]); - const y = mesh.map((m) => m[1]); - return [Math.min(...x) + (Math.max(...x) - Math.min(...x)) / 2, Math.min(...y) + (Math.max(...y) - Math.min(...y)) / 2]; -}; -var calculateFaceBox = (mesh, previousBox) => { - const center = findFaceCenter(mesh); - const boxSize = getBoxSize(previousBox); - const calculatedBox = { - startPoint: [center[0] - boxSize[0] / 2, center[1] - boxSize[1] / 2], - endPoint: [center[0] + boxSize[0] / 2, center[1] + boxSize[1] / 2] - }; - return calculatedBox; -}; - -// src/face/blazeface.ts -var keypointsCount = 6; -var faceBoxScaleFactor = 1.4; -var model5; -var anchors = null; -var inputSize4 = 0; -var inputSizeT = null; -var size = () => inputSize4; -async function load3(config3) { - var _a; - if (env.initial) - model5 = null; - if (!model5) - model5 = await loadModel((_a = config3.face.detector) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model5["modelUrl"]); - inputSize4 = model5["executor"] && model5.inputs[0].shape ? model5.inputs[0].shape[2] : 256; - inputSizeT = tf13.scalar(inputSize4, "int32"); - anchors = tf13.tensor2d(generateAnchors(inputSize4)); - return model5; -} -function decodeBoxes2(boxOutputs) { - if (!anchors || !inputSizeT) - return tf13.zeros([0, 0]); - const t2 = {}; - t2.boxStarts = tf13.slice(boxOutputs, [0, 1], [-1, 2]); - t2.centers = tf13.add(t2.boxStarts, anchors); - t2.boxSizes = tf13.slice(boxOutputs, [0, 3], [-1, 2]); - t2.boxSizesNormalized = tf13.div(t2.boxSizes, inputSizeT); - t2.centersNormalized = tf13.div(t2.centers, inputSizeT); - t2.halfBoxSize = tf13.div(t2.boxSizesNormalized, constants.tf2); - t2.starts = tf13.sub(t2.centersNormalized, t2.halfBoxSize); - t2.ends = tf13.add(t2.centersNormalized, t2.halfBoxSize); - t2.startNormalized = tf13.mul(t2.starts, inputSizeT); - t2.endNormalized = tf13.mul(t2.ends, inputSizeT); - const boxes = tf13.concat2d([t2.startNormalized, t2.endNormalized], 1); - Object.keys(t2).forEach((tensor6) => tf13.dispose(t2[tensor6])); - return boxes; -} -async function getBoxes(inputImage, config3) { - var _a, _b, _c, _d; - if (!inputImage || inputImage["isDisposedInternal"] || inputImage.shape.length !== 4 || inputImage.shape[1] < 1 || inputImage.shape[2] < 1) - return []; - const t2 = {}; - t2.resized = tf13.image.resizeBilinear(inputImage, [inputSize4, inputSize4]); - t2.div = tf13.div(t2.resized, constants.tf127); - t2.normalized = tf13.sub(t2.div, constants.tf05); - const res = model5 == null ? void 0 : model5.execute(t2.normalized); - if (Array.isArray(res) && res.length > 2) { - const sorted = res.sort((a, b) => a.size - b.size); - t2.concat384 = tf13.concat([sorted[0], sorted[2]], 2); - t2.concat512 = tf13.concat([sorted[1], sorted[3]], 2); - t2.concat = tf13.concat([t2.concat512, t2.concat384], 1); - t2.batch = tf13.squeeze(t2.concat, [0]); - } else if (Array.isArray(res)) { - t2.batch = tf13.squeeze(res[0]); - } else { - t2.batch = tf13.squeeze(res); - } - tf13.dispose(res); - t2.boxes = decodeBoxes2(t2.batch); - t2.logits = tf13.slice(t2.batch, [0, 0], [-1, 1]); - t2.sigmoid = tf13.sigmoid(t2.logits); - t2.scores = tf13.squeeze(t2.sigmoid); - t2.nms = await tf13.image.nonMaxSuppressionAsync(t2.boxes, t2.scores, ((_a = config3.face.detector) == null ? void 0 : _a.maxDetected) || 0, ((_b = config3.face.detector) == null ? void 0 : _b.iouThreshold) || 0, ((_c = config3.face.detector) == null ? void 0 : _c.minConfidence) || 0); - const nms = await t2.nms.array(); - const boxes = []; - const scores = await t2.scores.data(); - for (let i = 0; i < nms.length; i++) { - const confidence = scores[nms[i]]; - if (confidence > (((_d = config3.face.detector) == null ? void 0 : _d.minConfidence) || 0)) { - const b = {}; - b.bbox = tf13.slice(t2.boxes, [nms[i], 0], [1, -1]); - b.slice = tf13.slice(t2.batch, [nms[i], keypointsCount - 1], [1, -1]); - b.squeeze = tf13.squeeze(b.slice); - b.landmarks = tf13.reshape(b.squeeze, [keypointsCount, -1]); - const points = await b.bbox.data(); - const rawBox = { - startPoint: [points[0], points[1]], - endPoint: [points[2], points[3]], - landmarks: await b.landmarks.array(), - confidence - }; - const scaledBox = scaleBoxCoordinates(rawBox, [(inputImage.shape[2] || 0) / inputSize4, (inputImage.shape[1] || 0) / inputSize4]); - const enlargedBox = enlargeBox(scaledBox, config3.face["scale"] || faceBoxScaleFactor); - const squaredBox = squarifyBox(enlargedBox); - boxes.push(squaredBox); - Object.keys(b).forEach((tensor6) => tf13.dispose(b[tensor6])); - } - } - Object.keys(t2).forEach((tensor6) => tf13.dispose(t2[tensor6])); - return boxes; -} - -// src/face/iris.ts -var tf14 = __toESM(require_tfjs_esm()); -var model6; -var inputSize5 = 0; -var irisEnlarge = 2.3; -var leftOutline = meshAnnotations.leftEyeLower0; -var rightOutline = meshAnnotations.rightEyeLower0; -var eyeLandmarks = { - leftBounds: [leftOutline[0], leftOutline[leftOutline.length - 1]], - rightBounds: [rightOutline[0], rightOutline[rightOutline.length - 1]] -}; -var irisLandmarks = { - upperCenter: 3, - lowerCenter: 4, - index: 71, - numCoordinates: 76 -}; -async function load4(config3) { - var _a, _b; - if (env.initial) - model6 = null; - if (!model6) - model6 = await loadModel((_a = config3.face.iris) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model6["modelUrl"]); - inputSize5 = (model6 == null ? void 0 : model6["executor"]) && ((_b = model6.inputs) == null ? void 0 : _b[0].shape) ? model6.inputs[0].shape[2] : 0; - if (inputSize5 === -1) - inputSize5 = 64; - return model6; -} -function replaceIrisCoords(rawCoords, newCoords, prefix, keys) { - for (let i = 0; i < irisIndices.length; i++) { - const { key, indices } = irisIndices[i]; - const originalIndices = meshAnnotations[`${prefix}${key}`]; - if (!keys || keys.includes(key)) { - for (let j = 0; j < indices.length; j++) { - const index2 = indices[j]; - rawCoords[originalIndices[j]] = [ - newCoords[index2][0], - newCoords[index2][1], - (newCoords[index2][2] + rawCoords[originalIndices[j]][2]) / 2 - ]; - } - } - } -} -var getLeftToRightEyeDepthDifference = (rawCoords) => { - const leftEyeZ = rawCoords[eyeLandmarks.leftBounds[0]][2]; - const rightEyeZ = rawCoords[eyeLandmarks.rightBounds[0]][2]; - return leftEyeZ - rightEyeZ; -}; -var getEyeBox = (rawCoords, face4, eyeInnerCornerIndex, eyeOuterCornerIndex, meshSize, flip = false) => { - const box = squarifyBox(enlargeBox(calculateLandmarksBoundingBox([rawCoords[eyeInnerCornerIndex], rawCoords[eyeOuterCornerIndex]]), irisEnlarge)); - const boxSize = getBoxSize(box); - let crop = tf14.image.cropAndResize(face4, [[ - box.startPoint[1] / meshSize, - box.startPoint[0] / meshSize, - box.endPoint[1] / meshSize, - box.endPoint[0] / meshSize - ]], [0], [inputSize5, inputSize5]); - if (flip && env.kernels.includes("flipleftright")) { - const flipped = tf14.image.flipLeftRight(crop); - tf14.dispose(crop); - crop = flipped; - } - return { box, boxSize, crop }; -}; -var getEyeCoords = (eyeData, eyeBox, eyeBoxSize, flip = false) => { - const eyeRawCoords = []; - for (let i = 0; i < irisLandmarks.numCoordinates; i++) { - const x = eyeData[i * 3]; - const y = eyeData[i * 3 + 1]; - const z = eyeData[i * 3 + 2]; - eyeRawCoords.push([ - (flip ? 1 - x / inputSize5 : x / inputSize5) * eyeBoxSize[0] + eyeBox.startPoint[0], - y / inputSize5 * eyeBoxSize[1] + eyeBox.startPoint[1], - z - ]); - } - return { rawCoords: eyeRawCoords, iris: eyeRawCoords.slice(irisLandmarks.index) }; -}; -var getAdjustedIrisCoords = (rawCoords, irisCoords, direction) => { - const upperCenterZ = rawCoords[meshAnnotations[`${direction}EyeUpper0`][irisLandmarks.upperCenter]][2]; - const lowerCenterZ = rawCoords[meshAnnotations[`${direction}EyeLower0`][irisLandmarks.lowerCenter]][2]; - const averageZ = (upperCenterZ + lowerCenterZ) / 2; - return irisCoords.map((coord, i) => { - let z = averageZ; - if (i === 2) { - z = upperCenterZ; - } else if (i === 4) { - z = lowerCenterZ; - } - return [coord[0], coord[1], z]; - }); -}; -async function augmentIris(rawCoords, face4, meshSize) { - if (!(model6 == null ? void 0 : model6["executor"])) - return rawCoords; - const { box: leftEyeBox, boxSize: leftEyeBoxSize, crop: leftEyeCrop } = getEyeBox(rawCoords, face4, eyeLandmarks.leftBounds[0], eyeLandmarks.leftBounds[1], meshSize, true); - const { box: rightEyeBox, boxSize: rightEyeBoxSize, crop: rightEyeCrop } = getEyeBox(rawCoords, face4, eyeLandmarks.rightBounds[0], eyeLandmarks.rightBounds[1], meshSize, true); - const combined = tf14.concat([leftEyeCrop, rightEyeCrop]); - tf14.dispose(leftEyeCrop); - tf14.dispose(rightEyeCrop); - const eyePredictions = model6.execute(combined); - tf14.dispose(combined); - const eyePredictionsData = await eyePredictions.data(); - tf14.dispose(eyePredictions); - const leftEyeData = eyePredictionsData.slice(0, irisLandmarks.numCoordinates * 3); - const { rawCoords: leftEyeRawCoords, iris: leftIrisRawCoords } = getEyeCoords(leftEyeData, leftEyeBox, leftEyeBoxSize, true); - const rightEyeData = eyePredictionsData.slice(irisLandmarks.numCoordinates * 3); - const { rawCoords: rightEyeRawCoords, iris: rightIrisRawCoords } = getEyeCoords(rightEyeData, rightEyeBox, rightEyeBoxSize, false); - const leftToRightEyeDepthDifference = getLeftToRightEyeDepthDifference(rawCoords); - if (Math.abs(leftToRightEyeDepthDifference) < 30) { - replaceIrisCoords(rawCoords, leftEyeRawCoords, "left", null); - replaceIrisCoords(rawCoords, rightEyeRawCoords, "right", null); - } else if (leftToRightEyeDepthDifference < 1) { - replaceIrisCoords(rawCoords, leftEyeRawCoords, "left", ["EyeUpper0", "EyeLower0"]); - } else { - replaceIrisCoords(rawCoords, rightEyeRawCoords, "right", ["EyeUpper0", "EyeLower0"]); - } - const adjustedLeftIrisCoords = getAdjustedIrisCoords(rawCoords, leftIrisRawCoords, "left"); - const adjustedRightIrisCoords = getAdjustedIrisCoords(rawCoords, rightIrisRawCoords, "right"); - const newCoords = rawCoords.concat(adjustedLeftIrisCoords).concat(adjustedRightIrisCoords); - return newCoords; -} - -// src/face/attention.ts -async function augment(rawCoords, results) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; - const t2 = { - lips: await ((_b = (_a = results.filter((r) => r.size === 160)) == null ? void 0 : _a[0]) == null ? void 0 : _b.data()), - irisL: await ((_d = (_c = results.filter((r) => r.size === 10)) == null ? void 0 : _c[0]) == null ? void 0 : _d.data()), - eyeL: await ((_f = (_e = results.filter((r) => r.size === 142)) == null ? void 0 : _e[0]) == null ? void 0 : _f.data()), - irisR: await ((_h = (_g = results.filter((r) => r.size === 10)) == null ? void 0 : _g[1]) == null ? void 0 : _h.data()), - eyeR: await ((_j = (_i = results.filter((r) => r.size === 142)) == null ? void 0 : _i[1]) == null ? void 0 : _j.data()) - }; - for (const val of Object.values(t2)) { - if (!val) - return rawCoords; - } - const irisLDepth = LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG.reduce((prev, curr) => prev += rawCoords[curr][2], 0) / LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG.length; - for (let i = 0; i < t2.irisL.length / 2; i++) - rawCoords.push([t2.irisL[2 * i + 0], t2.irisL[2 * i + 1], irisLDepth]); - const irisRDepth = LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG.reduce((prev, curr) => prev += rawCoords[curr][2], 0) / LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG.length; - for (let i = 0; i < t2.irisR.length / 2; i++) - rawCoords.push([t2.irisR[2 * i + 0], t2.irisR[2 * i + 1], irisRDepth]); - for (let i = 0; i < t2.eyeL.length / 2; i++) - rawCoords[LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG[i]] = [t2.eyeL[2 * i + 0], t2.eyeL[2 * i + 1], rawCoords[LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG[i]][2]]; - for (let i = 0; i < t2.eyeR.length / 2; i++) - rawCoords[LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG[i]] = [t2.eyeR[2 * i + 0], t2.eyeR[2 * i + 1], rawCoords[LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG[i]][2]]; - for (let i = 0; i < t2.lips.length / 2; i++) - rawCoords[LANDMARKS_REFINEMENT_LIPS_CONFIG[i]] = [t2.lips[2 * i + 0], t2.lips[2 * i + 1], rawCoords[LANDMARKS_REFINEMENT_LIPS_CONFIG[i]][2]]; - return rawCoords; -} - -// src/face/facemesh.ts -var cache3 = { - boxes: [], - skipped: Number.MAX_SAFE_INTEGER, - timestamp: 0 -}; -var model7 = null; -var inputSize6 = 0; -async function predict4(input, config3) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; - if (!(model7 == null ? void 0 : model7["executor"])) - return []; - const skipTime = (((_a = config3.face.detector) == null ? void 0 : _a.skipTime) || 0) > now() - cache3.timestamp; - const skipFrame = cache3.skipped < (((_b = config3.face.detector) == null ? void 0 : _b.skipFrames) || 0); - if (!config3.skipAllowed || !skipTime || !skipFrame || cache3.boxes.length === 0) { - cache3.boxes = await getBoxes(input, config3); - cache3.timestamp = now(); - cache3.skipped = 0; - } else { - cache3.skipped++; - } - const faces = []; - const newCache = []; - let id = 0; - const size2 = inputSize6; - for (let i = 0; i < cache3.boxes.length; i++) { - const box = cache3.boxes[i]; - let angle = 0; - let rotationMatrix; - const face4 = { - id: id++, - mesh: [], - meshRaw: [], - box: [0, 0, 0, 0], - boxRaw: [0, 0, 0, 0], - score: 0, - boxScore: 0, - faceScore: 0, - annotations: {} - }; - [angle, rotationMatrix, face4.tensor] = correctFaceRotation((_c = config3.face.detector) == null ? void 0 : _c.rotation, box, input, ((_d = config3.face.mesh) == null ? void 0 : _d.enabled) ? inputSize6 : size()); - if (config3.filter.equalization) { - const equilized = face4.tensor ? await histogramEqualization(face4.tensor) : void 0; - tf15.dispose(face4.tensor); - if (equilized) - face4.tensor = equilized; - } - face4.boxScore = Math.round(100 * box.confidence) / 100; - if (!((_e = config3.face.mesh) == null ? void 0 : _e.enabled)) { - face4.box = clampBox(box, input); - face4.boxRaw = getRawBox(box, input); - face4.score = face4.boxScore; - face4.mesh = box.landmarks.map((pt) => [ - (box.startPoint[0] + box.endPoint[0]) / 2 + (box.endPoint[0] + box.startPoint[0]) * pt[0] / size(), - (box.startPoint[1] + box.endPoint[1]) / 2 + (box.endPoint[1] + box.startPoint[1]) * pt[1] / size() - ]); - face4.meshRaw = face4.mesh.map((pt) => [pt[0] / (input.shape[2] || 0), pt[1] / (input.shape[1] || 0), (pt[2] || 0) / size2]); - for (const key of Object.keys(blazeFaceLandmarks)) { - face4.annotations[key] = [face4.mesh[blazeFaceLandmarks[key]]]; - } - } else if (!model7) { - if (config3.debug) - log("face mesh detection requested, but model is not loaded"); - } else { - if (((_f = config3.face.attention) == null ? void 0 : _f.enabled) && !env.kernels.includes("atan2")) { - config3.face.attention.enabled = false; - tf15.dispose(face4.tensor); - return faces; - } - const results = model7.execute(face4.tensor); - const confidenceT = results.find((t2) => t2.shape[t2.shape.length - 1] === 1); - const faceConfidence = await confidenceT.data(); - face4.faceScore = Math.round(100 * faceConfidence[0]) / 100; - if (face4.faceScore < (((_g = config3.face.detector) == null ? void 0 : _g.minConfidence) || 1)) { - box.confidence = face4.faceScore; - if (config3.face.mesh.keepInvalid) { - face4.box = clampBox(box, input); - face4.boxRaw = getRawBox(box, input); - face4.score = face4.boxScore; - face4.mesh = box.landmarks.map((pt) => [ - (box.startPoint[0] + box.endPoint[0]) / 2 + (box.endPoint[0] + box.startPoint[0]) * pt[0] / size(), - (box.startPoint[1] + box.endPoint[1]) / 2 + (box.endPoint[1] + box.startPoint[1]) * pt[1] / size() - ]); - face4.meshRaw = face4.mesh.map((pt) => [pt[0] / (input.shape[2] || 1), pt[1] / (input.shape[1] || 1), (pt[2] || 0) / size2]); - for (const key of Object.keys(blazeFaceLandmarks)) { - face4.annotations[key] = [face4.mesh[blazeFaceLandmarks[key]]]; - } - } - } else { - const meshT = results.find((t2) => t2.shape[t2.shape.length - 1] === 1404); - const coordsReshaped = tf15.reshape(meshT, [-1, 3]); - let rawCoords = await coordsReshaped.array(); - tf15.dispose(coordsReshaped); - if ((_h = config3.face.attention) == null ? void 0 : _h.enabled) { - rawCoords = await augment(rawCoords, results); - } else if ((_i = config3.face.iris) == null ? void 0 : _i.enabled) { - rawCoords = await augmentIris(rawCoords, face4.tensor, inputSize6); - } - face4.mesh = transformRawCoords(rawCoords, box, angle, rotationMatrix, inputSize6); - face4.meshRaw = face4.mesh.map((pt) => [pt[0] / (input.shape[2] || 0), pt[1] / (input.shape[1] || 0), (pt[2] || 0) / size2]); - for (const key of Object.keys(meshAnnotations)) - face4.annotations[key] = meshAnnotations[key].map((index2) => face4.mesh[index2]); - face4.score = face4.faceScore; - const calculatedBox = { ...calculateFaceBox(face4.mesh, box), confidence: box.confidence, landmarks: box.landmarks }; - face4.box = clampBox(calculatedBox, input); - face4.boxRaw = getRawBox(calculatedBox, input); - newCache.push(calculatedBox); - } - tf15.dispose(results); - } - if (face4.score > (((_j = config3.face.detector) == null ? void 0 : _j.minConfidence) || 1)) - faces.push(face4); - else - tf15.dispose(face4.tensor); - } - cache3.boxes = newCache; - return faces; -} -async function load5(config3) { - var _a, _b, _c, _d, _e, _f; - if (env.initial) - model7 = null; - if (((_a = config3.face.attention) == null ? void 0 : _a.enabled) && (model7 == null ? void 0 : model7["signature"])) { - if (Object.keys(((_b = model7 == null ? void 0 : model7["signature"]) == null ? void 0 : _b.outputs) || {}).length < 6) - model7 = null; - } - if (!model7) { - if ((_c = config3.face.attention) == null ? void 0 : _c.enabled) - model7 = await loadModel(config3.face.attention.modelPath); - else - model7 = await loadModel((_d = config3.face.mesh) == null ? void 0 : _d.modelPath); - } else if (config3.debug) { - log("cached model:", model7["modelUrl"]); - } - inputSize6 = model7["executor"] && ((_e = model7 == null ? void 0 : model7.inputs) == null ? void 0 : _e[0].shape) ? (_f = model7 == null ? void 0 : model7.inputs) == null ? void 0 : _f[0].shape[2] : 256; - return model7; -} -var triangulation = TRI468; -var uvmap = UV468; - -// src/gear/emotion.ts -var tf16 = __toESM(require_tfjs_esm()); -var annotations = ["angry", "disgust", "fear", "happy", "sad", "surprise", "neutral"]; -var model8; -var last3 = []; -var lastCount = 0; -var lastTime4 = 0; -var skipped4 = Number.MAX_SAFE_INTEGER; -async function load6(config3) { - var _a; - if (env.initial) - model8 = null; - if (!model8) - model8 = await loadModel((_a = config3.face.emotion) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model8["modelUrl"]); - return model8; -} -async function predict5(image28, config3, idx, count2) { - var _a, _b; - if (!model8) - return []; - const skipFrame = skipped4 < (((_a = config3.face.emotion) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face.emotion) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime4; - if (config3.skipAllowed && skipTime && skipFrame && lastCount === count2 && last3[idx] && last3[idx].length > 0) { - skipped4++; - return last3[idx]; - } - skipped4 = 0; - return new Promise(async (resolve) => { - var _a2; - const obj = []; - if ((_a2 = config3.face.emotion) == null ? void 0 : _a2.enabled) { - const t2 = {}; - const inputSize10 = (model8 == null ? void 0 : model8.inputs[0].shape) ? model8.inputs[0].shape[2] : 0; - t2.resize = tf16.image.resizeBilinear(image28, [inputSize10, inputSize10], false); - t2.channels = tf16.mul(t2.resize, constants.rgb); - t2.grayscale = tf16.sum(t2.channels, 3, true); - t2.grayscaleSub = tf16.sub(t2.grayscale, constants.tf05); - t2.grayscaleMul = tf16.mul(t2.grayscaleSub, constants.tf2); - t2.emotion = model8 == null ? void 0 : model8.execute(t2.grayscaleMul); - lastTime4 = now(); - const data = await t2.emotion.data(); - for (let i = 0; i < data.length; i++) { - if (data[i] > (config3.face.emotion.minConfidence || 0)) - obj.push({ score: Math.min(0.99, Math.trunc(100 * data[i]) / 100), emotion: annotations[i] }); - } - obj.sort((a, b) => b.score - a.score); - Object.keys(t2).forEach((tensor6) => tf16.dispose(t2[tensor6])); - } - last3[idx] = obj; - lastCount = count2; - resolve(obj); - }); -} - -// src/face/faceres.ts -var tf17 = __toESM(require_tfjs_esm()); -var model9; -var last4 = []; -var lastTime5 = 0; -var lastCount2 = 0; -var skipped5 = Number.MAX_SAFE_INTEGER; -async function load7(config3) { - var _a; - if (env.initial) - model9 = null; - if (!model9) - model9 = await loadModel((_a = config3.face.description) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model9["modelUrl"]); - return model9; -} -function enhance(input) { - const tensor6 = input.image || input.tensor || input; - if (!(model9 == null ? void 0 : model9.inputs[0].shape)) - return tensor6; - const crop = tf17.image.resizeBilinear(tensor6, [model9.inputs[0].shape[2], model9.inputs[0].shape[1]], false); - const norm = tf17.mul(crop, constants.tf255); - tf17.dispose(crop); - return norm; -} -async function predict6(image28, config3, idx, count2) { - var _a, _b, _c, _d; - const obj = { - age: 0, - gender: "unknown", - genderScore: 0, - descriptor: [] - }; - if (!(model9 == null ? void 0 : model9["executor"])) - return obj; - const skipFrame = skipped5 < (((_a = config3.face.description) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face.description) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime5; - if (config3.skipAllowed && skipFrame && skipTime && lastCount2 === count2 && ((_c = last4 == null ? void 0 : last4[idx]) == null ? void 0 : _c.age) > 0 && ((_d = last4 == null ? void 0 : last4[idx]) == null ? void 0 : _d.genderScore) > 0) { - skipped5++; - return last4[idx]; - } - skipped5 = 0; - return new Promise(async (resolve) => { - var _a2; - if ((_a2 = config3.face.description) == null ? void 0 : _a2.enabled) { - const enhanced = enhance(image28); - const resT = model9 == null ? void 0 : model9.execute(enhanced); - lastTime5 = now(); - tf17.dispose(enhanced); - const genderT = resT.find((t2) => t2.shape[1] === 1); - const gender2 = await genderT.data(); - const confidence = Math.trunc(200 * Math.abs(gender2[0] - 0.5)) / 100; - if (confidence > (config3.face.description.minConfidence || 0)) { - obj.gender = gender2[0] <= 0.5 ? "female" : "male"; - obj.genderScore = Math.min(0.99, confidence); - } - const argmax = tf17.argMax(resT.find((t2) => t2.shape[1] === 100), 1); - const ageIdx = (await argmax.data())[0]; - tf17.dispose(argmax); - const ageT = resT.find((t2) => t2.shape[1] === 100); - const all2 = await ageT.data(); - obj.age = Math.round(all2[ageIdx - 1] > all2[ageIdx + 1] ? 10 * ageIdx - 100 * all2[ageIdx - 1] : 10 * ageIdx + 100 * all2[ageIdx + 1]) / 10; - if (Number.isNaN(gender2[0]) || Number.isNaN(all2[0])) - log("faceres error:", { model: model9, result: resT }); - const desc = resT.find((t2) => t2.shape[1] === 1024); - const descriptor = desc ? await desc.data() : []; - obj.descriptor = Array.from(descriptor); - resT.forEach((t2) => tf17.dispose(t2)); - } - last4[idx] = obj; - lastCount2 = count2; - resolve(obj); - }); -} - -// src/face/mask.ts -var expandFact = 0.1; -var alpha = 0.5; -function insidePoly(x, y, polygon) { - let inside = false; - let j = polygon.length - 1; - for (let i = 0; i < polygon.length; j = i++) { - if (polygon[i].y > y !== polygon[j].y > y && x < (polygon[j].x - polygon[i].x) * (y - polygon[i].y) / (polygon[j].y - polygon[i].y) + polygon[i].x) - inside = !inside; - } - return inside; -} -async function mask(face4) { - if (!face4.tensor) - return face4.tensor; - if (!face4.mesh || face4.mesh.length < 100) - return face4.tensor; - const width = face4.tensor.shape[2] || 0; - const height = face4.tensor.shape[1] || 0; - const buffer = await face4.tensor.buffer(); - let silhouette = []; - for (const pt of meshAnnotations.silhouette) - silhouette.push({ x: (face4.mesh[pt][0] - face4.box[0]) / face4.box[2], y: (face4.mesh[pt][1] - face4.box[1]) / face4.box[3] }); - if (expandFact && expandFact > 0) - silhouette = silhouette.map((pt) => ({ x: pt.x > 0.5 ? pt.x + expandFact : pt.x - expandFact, y: pt.y > 0.5 ? pt.y + expandFact : pt.y - expandFact })); - for (let x = 0; x < width; x++) { - for (let y = 0; y < height; y++) { - const inside = insidePoly(x / width, y / width, silhouette); - if (!inside) { - buffer.set(alpha * buffer.get(0, y, x, 0), 0, y, x, 0); - buffer.set(alpha * buffer.get(0, y, x, 1), 0, y, x, 1); - buffer.set(alpha * buffer.get(0, y, x, 2), 0, y, x, 2); - } - } - } - const output = buffer.toTensor(); - return output; -} - -// src/face/antispoof.ts -var tf18 = __toESM(require_tfjs_esm()); -var model10; -var cached = []; -var skipped6 = Number.MAX_SAFE_INTEGER; -var lastCount3 = 0; -var lastTime6 = 0; -async function load8(config3) { - var _a; - if (env.initial) - model10 = null; - if (!model10) - model10 = await loadModel((_a = config3.face.antispoof) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model10["modelUrl"]); - return model10; -} -async function predict7(image28, config3, idx, count2) { - var _a, _b; - if (!(model10 == null ? void 0 : model10["executor"])) - return 0; - const skipTime = (((_a = config3.face.antispoof) == null ? void 0 : _a.skipTime) || 0) > now() - lastTime6; - const skipFrame = skipped6 < (((_b = config3.face.antispoof) == null ? void 0 : _b.skipFrames) || 0); - if (config3.skipAllowed && skipTime && skipFrame && lastCount3 === count2 && cached[idx]) { - skipped6++; - return cached[idx]; - } - skipped6 = 0; - return new Promise(async (resolve) => { - const resize = tf18.image.resizeBilinear(image28, [(model10 == null ? void 0 : model10.inputs[0].shape) ? model10.inputs[0].shape[2] : 0, (model10 == null ? void 0 : model10.inputs[0].shape) ? model10.inputs[0].shape[1] : 0], false); - const res = model10 == null ? void 0 : model10.execute(resize); - const num = (await res.data())[0]; - cached[idx] = Math.round(100 * num) / 100; - lastCount3 = count2; - lastTime6 = now(); - tf18.dispose([resize, res]); - resolve(cached[idx]); - }); -} - -// src/face/liveness.ts -var tf19 = __toESM(require_tfjs_esm()); -var model11; -var cached2 = []; -var skipped7 = Number.MAX_SAFE_INTEGER; -var lastCount4 = 0; -var lastTime7 = 0; -async function load9(config3) { - var _a; - if (env.initial) - model11 = null; - if (!model11) - model11 = await loadModel((_a = config3.face.liveness) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model11["modelUrl"]); - return model11; -} -async function predict8(image28, config3, idx, count2) { - var _a, _b; - if (!(model11 == null ? void 0 : model11["executor"])) - return 0; - const skipTime = (((_a = config3.face.liveness) == null ? void 0 : _a.skipTime) || 0) > now() - lastTime7; - const skipFrame = skipped7 < (((_b = config3.face.liveness) == null ? void 0 : _b.skipFrames) || 0); - if (config3.skipAllowed && skipTime && skipFrame && lastCount4 === count2 && cached2[idx]) { - skipped7++; - return cached2[idx]; - } - skipped7 = 0; - return new Promise(async (resolve) => { - const resize = tf19.image.resizeBilinear(image28, [(model11 == null ? void 0 : model11.inputs[0].shape) ? model11.inputs[0].shape[2] : 0, (model11 == null ? void 0 : model11.inputs[0].shape) ? model11.inputs[0].shape[1] : 0], false); - const res = model11 == null ? void 0 : model11.execute(resize); - const num = (await res.data())[0]; - cached2[idx] = Math.round(100 * num) / 100; - lastCount4 = count2; - lastTime7 = now(); - tf19.dispose([resize, res]); - resolve(cached2[idx]); - }); -} - -// src/gear/gear.ts -var tf20 = __toESM(require_tfjs_esm()); -var model12; -var last5 = []; -var raceNames = ["white", "black", "asian", "indian", "other"]; -var ageWeights = [15, 23, 28, 35.5, 45.5, 55.5, 65]; -var lastCount5 = 0; -var lastTime8 = 0; -var skipped8 = Number.MAX_SAFE_INTEGER; -async function load10(config3) { - var _a; - if (env.initial) - model12 = null; - if (!model12) - model12 = await loadModel((_a = config3.face.gear) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model12["modelUrl"]); - return model12; -} -async function predict9(image28, config3, idx, count2) { - var _a, _b; - if (!model12) - return { age: 0, gender: "unknown", genderScore: 0, race: [] }; - const skipFrame = skipped8 < (((_a = config3.face.gear) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face.gear) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime8; - if (config3.skipAllowed && skipTime && skipFrame && lastCount5 === count2 && last5[idx]) { - skipped8++; - return last5[idx]; - } - skipped8 = 0; - return new Promise(async (resolve) => { - var _a2, _b2; - if (!(model12 == null ? void 0 : model12.inputs[0].shape)) - return; - const t2 = {}; - const box = [[0, 0.1, 0.9, 0.9]]; - t2.resize = tf20.image.cropAndResize(image28, box, [0], [model12.inputs[0].shape[2], model12.inputs[0].shape[1]]); - const obj = { age: 0, gender: "unknown", genderScore: 0, race: [] }; - if ((_a2 = config3.face.gear) == null ? void 0 : _a2.enabled) - [t2.age, t2.gender, t2.race] = model12.execute(t2.resize, ["age_output", "gender_output", "race_output"]); - const gender2 = await t2.gender.data(); - obj.gender = gender2[0] > gender2[1] ? "male" : "female"; - obj.genderScore = Math.round(100 * (gender2[0] > gender2[1] ? gender2[0] : gender2[1])) / 100; - const race = await t2.race.data(); - for (let i = 0; i < race.length; i++) { - if (race[i] > (((_b2 = config3.face.gear) == null ? void 0 : _b2.minConfidence) || 0.2)) - obj.race.push({ score: Math.round(100 * race[i]) / 100, race: raceNames[i] }); - } - obj.race.sort((a, b) => b.score - a.score); - const ageDistribution = Array.from(await t2.age.data()); - const ageSorted = ageDistribution.map((a, i) => [ageWeights[i], a]).sort((a, b) => b[1] - a[1]); - let age2 = ageSorted[0][0]; - for (let i = 1; i < ageSorted.length; i++) - age2 += ageSorted[i][1] * (ageSorted[i][0] - age2); - obj.age = Math.round(10 * age2) / 10; - Object.keys(t2).forEach((tensor6) => tf20.dispose(t2[tensor6])); - last5[idx] = obj; - lastCount5 = count2; - lastTime8 = now(); - resolve(obj); - }); -} - -// src/gear/ssrnet-age.ts -var tf21 = __toESM(require_tfjs_esm()); -var model13; -var last6 = []; -var lastCount6 = 0; -var lastTime9 = 0; -var skipped9 = Number.MAX_SAFE_INTEGER; -async function load11(config3) { - if (env.initial) - model13 = null; - if (!model13) - model13 = await loadModel(config3.face["ssrnet"].modelPathAge); - else if (config3.debug) - log("cached model:", model13["modelUrl"]); - return model13; -} -async function predict10(image28, config3, idx, count2) { - var _a, _b, _c, _d; - if (!model13) - return { age: 0 }; - const skipFrame = skipped9 < (((_a = config3.face["ssrnet"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["ssrnet"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime9; - if (config3.skipAllowed && skipFrame && skipTime && lastCount6 === count2 && ((_c = last6[idx]) == null ? void 0 : _c.age) && ((_d = last6[idx]) == null ? void 0 : _d.age) > 0) { - skipped9++; - return last6[idx]; - } - skipped9 = 0; - return new Promise(async (resolve) => { - var _a2; - if (!(model13 == null ? void 0 : model13.inputs) || !model13.inputs[0] || !model13.inputs[0].shape) - return; - const t2 = {}; - t2.resize = tf21.image.resizeBilinear(image28, [model13.inputs[0].shape[2], model13.inputs[0].shape[1]], false); - t2.enhance = tf21.mul(t2.resize, constants.tf255); - const obj = { age: 0 }; - if ((_a2 = config3.face["ssrnet"]) == null ? void 0 : _a2.enabled) - t2.age = model13.execute(t2.enhance); - if (t2.age) { - const data = await t2.age.data(); - obj.age = Math.trunc(10 * data[0]) / 10; - } - Object.keys(t2).forEach((tensor6) => tf21.dispose(t2[tensor6])); - last6[idx] = obj; - lastCount6 = count2; - lastTime9 = now(); - resolve(obj); - }); -} - -// src/gear/ssrnet-gender.ts -var tf22 = __toESM(require_tfjs_esm()); -var model14; -var last7 = []; -var lastCount7 = 0; -var lastTime10 = 0; -var skipped10 = Number.MAX_SAFE_INTEGER; -var rgb = [0.2989, 0.587, 0.114]; -async function load12(config3) { - var _a; - if (env.initial) - model14 = null; - if (!model14) - model14 = await loadModel((_a = config3.face["ssrnet"]) == null ? void 0 : _a.modelPathGender); - else if (config3.debug) - log("cached model:", model14["modelUrl"]); - return model14; -} -async function predict11(image28, config3, idx, count2) { - var _a, _b, _c, _d; - if (!model14) - return { gender: "unknown", genderScore: 0 }; - const skipFrame = skipped10 < (((_a = config3.face["ssrnet"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["ssrnet"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime10; - if (config3.skipAllowed && skipFrame && skipTime && lastCount7 === count2 && ((_c = last7[idx]) == null ? void 0 : _c.gender) && ((_d = last7[idx]) == null ? void 0 : _d.genderScore) > 0) { - skipped10++; - return last7[idx]; - } - skipped10 = 0; - return new Promise(async (resolve) => { - var _a2; - if (!(model14 == null ? void 0 : model14.inputs[0].shape)) - return; - const t2 = {}; - t2.resize = tf22.image.resizeBilinear(image28, [model14.inputs[0].shape[2], model14.inputs[0].shape[1]], false); - t2.enhance = tf22.tidy(() => { - const [red, green, blue] = tf22.split(t2.resize, 3, 3); - const redNorm = tf22.mul(red, rgb[0]); - const greenNorm = tf22.mul(green, rgb[1]); - const blueNorm = tf22.mul(blue, rgb[2]); - const grayscale = tf22.addN([redNorm, greenNorm, blueNorm]); - const normalize2 = tf22.mul(tf22.sub(grayscale, constants.tf05), 2); - return normalize2; - }); - const obj = { gender: "unknown", genderScore: 0 }; - if ((_a2 = config3.face["ssrnet"]) == null ? void 0 : _a2.enabled) - t2.gender = model14.execute(t2.enhance); - const data = await t2.gender.data(); - obj.gender = data[0] > data[1] ? "female" : "male"; - obj.genderScore = data[0] > data[1] ? Math.trunc(100 * data[0]) / 100 : Math.trunc(100 * data[1]) / 100; - Object.keys(t2).forEach((tensor6) => tf22.dispose(t2[tensor6])); - last7[idx] = obj; - lastCount7 = count2; - lastTime10 = now(); - resolve(obj); - }); -} - -// src/face/mobilefacenet.ts -var tf23 = __toESM(require_tfjs_esm()); -var model15; -var last8 = []; -var lastCount8 = 0; -var lastTime11 = 0; -var skipped11 = Number.MAX_SAFE_INTEGER; -async function load13(config3) { - var _a; - if (env.initial) - model15 = null; - if (!model15) - model15 = await loadModel((_a = config3.face["mobilefacenet"]) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model15["modelUrl"]); - return model15; -} -async function predict12(input, config3, idx, count2) { - var _a, _b; - if (!(model15 == null ? void 0 : model15["executor"])) - return []; - const skipFrame = skipped11 < (((_a = config3.face["mobilefacenet"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["mobilefacenet"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime11; - if (config3.skipAllowed && skipTime && skipFrame && lastCount8 === count2 && last8[idx]) { - skipped11++; - return last8[idx]; - } - return new Promise(async (resolve) => { - var _a2; - let data = []; - if (((_a2 = config3.face["mobilefacenet"]) == null ? void 0 : _a2.enabled) && (model15 == null ? void 0 : model15.inputs[0].shape)) { - const t2 = {}; - t2.crop = tf23.image.resizeBilinear(input, [model15.inputs[0].shape[2], model15.inputs[0].shape[1]], false); - t2.data = model15.execute(t2.crop); - const output = await t2.data.data(); - data = Array.from(output); - Object.keys(t2).forEach((tensor6) => tf23.dispose(t2[tensor6])); - } - last8[idx] = data; - lastCount8 = count2; - lastTime11 = now(); - resolve(data); - }); -} - -// src/face/insightface.ts -var tf24 = __toESM(require_tfjs_esm()); -var model16; -var last9 = []; -var lastCount9 = 0; -var lastTime12 = 0; -var skipped12 = Number.MAX_SAFE_INTEGER; -async function load14(config3) { - if (env.initial) - model16 = null; - if (!model16) - model16 = await loadModel(config3.face["insightface"].modelPath); - else if (config3.debug) - log("cached model:", model16["modelUrl"]); - return model16; -} -async function predict13(input, config3, idx, count2) { - var _a, _b; - if (!(model16 == null ? void 0 : model16["executor"])) - return []; - const skipFrame = skipped12 < (((_a = config3.face["insightface"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["insightface"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime12; - if (config3.skipAllowed && skipTime && skipFrame && lastCount9 === count2 && last9[idx]) { - skipped12++; - return last9[idx]; - } - return new Promise(async (resolve) => { - var _a2; - let data = []; - if (((_a2 = config3.face["insightface"]) == null ? void 0 : _a2.enabled) && (model16 == null ? void 0 : model16.inputs[0].shape)) { - const t2 = {}; - t2.crop = tf24.image.resizeBilinear(input, [model16.inputs[0].shape[2], model16.inputs[0].shape[1]], false); - t2.data = model16.execute(t2.crop); - const output = await t2.data.data(); - data = Array.from(output); - Object.keys(t2).forEach((tensor6) => tf24.dispose(t2[tensor6])); - } - last9[idx] = data; - lastCount9 = count2; - lastTime12 = now(); - resolve(data); - }); -} - -// src/face/angles.ts -var calculateGaze = (face4) => { - const radians = (pt1, pt2) => Math.atan2(pt1[1] - pt2[1], pt1[0] - pt2[0]); - if (!face4.annotations.rightEyeIris || !face4.annotations.leftEyeIris) - return { bearing: 0, strength: 0 }; - const offsetIris = [0, -0.1]; - const eyeRatio = 1; - const left = (face4.mesh[33][2] || 0) > (face4.mesh[263][2] || 0); - const irisCenter = left ? face4.mesh[473] : face4.mesh[468]; - const eyeCenter = left ? [(face4.mesh[133][0] + face4.mesh[33][0]) / 2, (face4.mesh[133][1] + face4.mesh[33][1]) / 2] : [(face4.mesh[263][0] + face4.mesh[362][0]) / 2, (face4.mesh[263][1] + face4.mesh[362][1]) / 2]; - const eyeSize = left ? [face4.mesh[133][0] - face4.mesh[33][0], face4.mesh[23][1] - face4.mesh[27][1]] : [face4.mesh[263][0] - face4.mesh[362][0], face4.mesh[253][1] - face4.mesh[257][1]]; - const eyeDiff = [ - (eyeCenter[0] - irisCenter[0]) / eyeSize[0] - offsetIris[0], - eyeRatio * (irisCenter[1] - eyeCenter[1]) / eyeSize[1] - offsetIris[1] - ]; - let strength = Math.sqrt(eyeDiff[0] * eyeDiff[0] + eyeDiff[1] * eyeDiff[1]); - strength = Math.min(strength, face4.boxRaw[2] / 2, face4.boxRaw[3] / 2); - const bearing = (radians([0, 0], eyeDiff) + Math.PI / 2) % Math.PI; - return { bearing, strength }; -}; -var calculateFaceAngle = (face4, imageSize) => { - const normalize2 = (v) => { - const length = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); - v[0] /= length; - v[1] /= length; - v[2] /= length; - return v; - }; - const subVectors = (a, b) => { - const x = a[0] - b[0]; - const y = a[1] - b[1]; - const z = a[2] - b[2]; - return [x, y, z]; - }; - const crossVectors = (a, b) => { - const x = a[1] * b[2] - a[2] * b[1]; - const y = a[2] * b[0] - a[0] * b[2]; - const z = a[0] * b[1] - a[1] * b[0]; - return [x, y, z]; - }; - const rotationMatrixToEulerAngle = (r) => { - const [r00, _r01, _r02, r10, r11, r12, r20, r21, r22] = r; - let thetaX; - let thetaY; - let thetaZ; - if (r10 < 1) { - if (r10 > -1) { - thetaZ = Math.asin(r10); - thetaY = Math.atan2(-r20, r00); - thetaX = Math.atan2(-r12, r11); - } else { - thetaZ = -Math.PI / 2; - thetaY = -Math.atan2(r21, r22); - thetaX = 0; - } - } else { - thetaZ = Math.PI / 2; - thetaY = Math.atan2(r21, r22); - thetaX = 0; - } - if (Number.isNaN(thetaX)) - thetaX = 0; - if (Number.isNaN(thetaY)) - thetaY = 0; - if (Number.isNaN(thetaZ)) - thetaZ = 0; - return { pitch: 2 * -thetaX, yaw: 2 * -thetaY, roll: 2 * -thetaZ }; - }; - const mesh = face4.meshRaw; - if (!mesh || mesh.length < 300) - return { angle: { pitch: 0, yaw: 0, roll: 0 }, matrix: [1, 0, 0, 0, 1, 0, 0, 0, 1], gaze: { bearing: 0, strength: 0 } }; - const size2 = Math.max(face4.boxRaw[2] * imageSize[0], face4.boxRaw[3] * imageSize[1]) / 1.5; - const pts = [mesh[10], mesh[152], mesh[234], mesh[454]].map((pt) => [pt[0] * imageSize[0] / size2, pt[1] * imageSize[1] / size2, pt[2]]); - const yAxis = normalize2(subVectors(pts[1], pts[0])); - let xAxis = normalize2(subVectors(pts[3], pts[2])); - const zAxis = normalize2(crossVectors(xAxis, yAxis)); - xAxis = crossVectors(yAxis, zAxis); - const matrix = [ - xAxis[0], - xAxis[1], - xAxis[2], - yAxis[0], - yAxis[1], - yAxis[2], - zAxis[0], - zAxis[1], - zAxis[2] - ]; - const angle = rotationMatrixToEulerAngle(matrix); - const gaze = mesh.length === 478 ? calculateGaze(face4) : { bearing: 0, strength: 0 }; - return { angle, matrix, gaze }; -}; - -// src/face/anthropometry.ts -function calculateCameraDistance(face4, width) { - const f = face4 == null ? void 0 : face4.annotations; - if (!f) - return 0; - const irisSize = Math.max(Math.abs(f.leftEyeIris[3][0] - f.leftEyeIris[1][0]), Math.abs(f.rightEyeIris[3][0] - f.rightEyeIris[1][0])) / width; - const cameraDistance = Math.round(1.17 / irisSize) / 100; - return cameraDistance; -} - -// src/face/face.ts -var detectFace = async (instance, input) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w; - let timeStamp = now(); - let ageRes; - let gearRes; - let genderRes; - let emotionRes; - let mobilefacenetRes; - let insightfaceRes; - let antispoofRes; - let livenessRes; - let descRes; - const faceRes = []; - instance.state = "run:face"; - const faces = await predict4(input, instance.config); - instance.performance.face = env.perfadd ? (instance.performance.face || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - if (!input.shape || input.shape.length !== 4) - return []; - if (!faces) - return []; - for (let i = 0; i < faces.length; i++) { - instance.analyze("Get Face"); - if (!faces[i].tensor || faces[i].tensor.isDisposedInternal) { - log("Face object is disposed:", faces[i].tensor); - continue; - } - if ((_a = instance.config.face.detector) == null ? void 0 : _a.mask) { - const masked = await mask(faces[i]); - tf25.dispose(faces[i].tensor); - if (masked) - faces[i].tensor = masked; - } - const rotation = faces[i].mesh && faces[i].mesh.length > 200 ? calculateFaceAngle(faces[i], [input.shape[2], input.shape[1]]) : null; - instance.analyze("Start Emotion:"); - if (instance.config.async) { - emotionRes = ((_b = instance.config.face.emotion) == null ? void 0 : _b.enabled) ? predict5(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : []; - } else { - instance.state = "run:emotion"; - timeStamp = now(); - emotionRes = ((_c = instance.config.face.emotion) == null ? void 0 : _c.enabled) ? await predict5(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : []; - instance.performance.emotion = env.perfadd ? (instance.performance.emotion || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End Emotion:"); - instance.analyze("Start AntiSpoof:"); - if (instance.config.async) { - antispoofRes = ((_d = instance.config.face.antispoof) == null ? void 0 : _d.enabled) ? predict7(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : 0; - } else { - instance.state = "run:antispoof"; - timeStamp = now(); - antispoofRes = ((_e = instance.config.face.antispoof) == null ? void 0 : _e.enabled) ? await predict7(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : 0; - instance.performance.antispoof = env.perfadd ? (instance.performance.antispoof || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End AntiSpoof:"); - instance.analyze("Start Liveness:"); - if (instance.config.async) { - livenessRes = ((_f = instance.config.face.liveness) == null ? void 0 : _f.enabled) ? predict8(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : 0; - } else { - instance.state = "run:liveness"; - timeStamp = now(); - livenessRes = ((_g = instance.config.face.liveness) == null ? void 0 : _g.enabled) ? await predict8(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : 0; - instance.performance.liveness = env.perfadd ? (instance.performance.antispoof || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End Liveness:"); - instance.analyze("Start GEAR:"); - if (instance.config.async) { - gearRes = ((_h = instance.config.face.gear) == null ? void 0 : _h.enabled) ? predict9(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:gear"; - timeStamp = now(); - gearRes = ((_i = instance.config.face.gear) == null ? void 0 : _i.enabled) ? await predict9(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - instance.performance.gear = Math.trunc(now() - timeStamp); - } - instance.analyze("End GEAR:"); - instance.analyze("Start SSRNet:"); - if (instance.config.async) { - ageRes = ((_j = instance.config.face["ssrnet"]) == null ? void 0 : _j.enabled) ? predict10(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - genderRes = ((_k = instance.config.face["ssrnet"]) == null ? void 0 : _k.enabled) ? predict11(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:ssrnet"; - timeStamp = now(); - ageRes = ((_l = instance.config.face["ssrnet"]) == null ? void 0 : _l.enabled) ? await predict10(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - genderRes = ((_m = instance.config.face["ssrnet"]) == null ? void 0 : _m.enabled) ? await predict11(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - instance.performance.ssrnet = Math.trunc(now() - timeStamp); - } - instance.analyze("End SSRNet:"); - instance.analyze("Start MobileFaceNet:"); - if (instance.config.async) { - mobilefacenetRes = ((_n = instance.config.face["mobilefacenet"]) == null ? void 0 : _n.enabled) ? predict12(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:mobilefacenet"; - timeStamp = now(); - mobilefacenetRes = ((_o = instance.config.face["mobilefacenet"]) == null ? void 0 : _o.enabled) ? await predict12(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - instance.performance.mobilefacenet = Math.trunc(now() - timeStamp); - } - instance.analyze("End MobileFaceNet:"); - instance.analyze("Start InsightFace:"); - if (instance.config.async) { - insightfaceRes = ((_p = instance.config.face["insightface"]) == null ? void 0 : _p.enabled) ? predict13(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:mobilefacenet"; - timeStamp = now(); - insightfaceRes = ((_q = instance.config.face["insightface"]) == null ? void 0 : _q.enabled) ? await predict13(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - instance.performance.mobilefacenet = Math.trunc(now() - timeStamp); - } - instance.analyze("End InsightFace:"); - instance.analyze("Start Description:"); - if (instance.config.async) { - descRes = predict6(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length); - } else { - instance.state = "run:description"; - timeStamp = now(); - descRes = await predict6(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length); - instance.performance.description = env.perfadd ? (instance.performance.description || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End Description:"); - if (instance.config.async) { - [ageRes, genderRes, emotionRes, mobilefacenetRes, insightfaceRes, descRes, gearRes, antispoofRes, livenessRes] = await Promise.all([ageRes, genderRes, emotionRes, mobilefacenetRes, insightfaceRes, descRes, gearRes, antispoofRes, livenessRes]); - } - instance.analyze("Finish Face:"); - if (((_r = instance.config.face["ssrnet"]) == null ? void 0 : _r.enabled) && ageRes && genderRes) { - descRes = { - ...descRes, - age: ageRes.age, - gender: genderRes.gender, - genderScore: genderRes.genderScore - }; - } - if (((_s = instance.config.face.gear) == null ? void 0 : _s.enabled) && gearRes) { - descRes = { - ...descRes, - age: gearRes.age, - gender: gearRes.gender, - genderScore: gearRes.genderScore, - race: gearRes.race - }; - } - if (((_t = instance.config.face["mobilefacenet"]) == null ? void 0 : _t.enabled) && mobilefacenetRes) { - descRes.descriptor = mobilefacenetRes; - } - if (((_u = instance.config.face["insightface"]) == null ? void 0 : _u.enabled) && insightfaceRes) { - descRes.descriptor = insightfaceRes; - } - const irisSize = ((_v = instance.config.face.iris) == null ? void 0 : _v.enabled) ? calculateCameraDistance(faces[i], input.shape[2]) : 0; - const tensor6 = ((_w = instance.config.face.detector) == null ? void 0 : _w.return) ? tf25.squeeze(faces[i].tensor) : null; - tf25.dispose(faces[i].tensor); - if (faces[i].tensor) - delete faces[i].tensor; - const res = { - ...faces[i], - id: i - }; - if (descRes.age) - res.age = descRes.age; - if (descRes.gender) - res.gender = descRes.gender; - if (descRes.genderScore) - res.genderScore = descRes.genderScore; - if (descRes.descriptor) - res.embedding = descRes.descriptor; - if (descRes.race) - res.race = descRes.race; - if (emotionRes) - res.emotion = emotionRes; - if (antispoofRes) - res.real = antispoofRes; - if (livenessRes) - res.live = livenessRes; - if (irisSize > 0) - res.distance = irisSize; - if (rotation) - res.rotation = rotation; - if (tensor6) - res.tensor = tensor6; - faceRes.push(res); - instance.analyze("End Face"); - } - instance.analyze("End FaceMesh:"); - if (instance.config.async) { - if (instance.performance.face) - delete instance.performance.face; - if (instance.performance.age) - delete instance.performance.age; - if (instance.performance.gender) - delete instance.performance.gender; - if (instance.performance.emotion) - delete instance.performance.emotion; - } - return faceRes; -}; - -// src/hand/fingerdef.ts -var Finger = { - thumb: 0, - index: 1, - middle: 2, - ring: 3, - pinky: 4, - all: [0, 1, 2, 3, 4], - nameMapping: { 0: "thumb", 1: "index", 2: "middle", 3: "ring", 4: "pinky" }, - pointsMapping: { - 0: [[0, 1], [1, 2], [2, 3], [3, 4]], - 1: [[0, 5], [5, 6], [6, 7], [7, 8]], - 2: [[0, 9], [9, 10], [10, 11], [11, 12]], - 3: [[0, 13], [13, 14], [14, 15], [15, 16]], - 4: [[0, 17], [17, 18], [18, 19], [19, 20]] - }, - getName: (value) => Finger.nameMapping[value], - getPoints: (value) => Finger.pointsMapping[value] -}; -var FingerCurl = { - none: 0, - half: 1, - full: 2, - nameMapping: { 0: "none", 1: "half", 2: "full" }, - getName: (value) => FingerCurl.nameMapping[value] -}; -var FingerDirection = { - verticalUp: 0, - verticalDown: 1, - horizontalLeft: 2, - horizontalRight: 3, - diagonalUpRight: 4, - diagonalUpLeft: 5, - diagonalDownRight: 6, - diagonalDownLeft: 7, - nameMapping: { 0: "verticalUp", 1: "verticalDown", 2: "horizontalLeft", 3: "horizontalRight", 4: "diagonalUpRight", 5: "diagonalUpLeft", 6: "diagonalDownRight", 7: "diagonalDownLeft" }, - getName: (value) => FingerDirection.nameMapping[value] -}; -var FingerGesture = class { - constructor(name) { - __publicField(this, "name"); - __publicField(this, "curls"); - __publicField(this, "directions"); - __publicField(this, "weights"); - __publicField(this, "weightsRelative"); - this.name = name; - this.curls = {}; - this.directions = {}; - this.weights = [1, 1, 1, 1, 1]; - this.weightsRelative = [1, 1, 1, 1, 1]; - } - curl(finger, curl, confidence) { - if (typeof this.curls[finger] === "undefined") - this.curls[finger] = []; - this.curls[finger].push([curl, confidence]); - } - direction(finger, position, confidence) { - if (!this.directions[finger]) - this.directions[finger] = []; - this.directions[finger].push([position, confidence]); - } - weight(finger, weight) { - this.weights[finger] = weight; - const total = this.weights.reduce((a, b) => a + b, 0); - this.weightsRelative = this.weights.map((el) => el * 5 / total); - } - matchAgainst(detectedCurls, detectedDirections) { - let confidence = 0; - for (const fingerIdx in detectedCurls) { - const detectedCurl = detectedCurls[fingerIdx]; - const expectedCurls = this.curls[fingerIdx]; - if (typeof expectedCurls === "undefined") { - confidence += this.weightsRelative[fingerIdx]; - continue; - } - for (const [expectedCurl, score] of expectedCurls) { - if (detectedCurl === expectedCurl) { - confidence += score * this.weightsRelative[fingerIdx]; - break; - } - } - } - for (const fingerIdx in detectedDirections) { - const detectedDirection = detectedDirections[fingerIdx]; - const expectedDirections = this.directions[fingerIdx]; - if (typeof expectedDirections === "undefined") { - confidence += this.weightsRelative[fingerIdx]; - continue; - } - for (const [expectedDirection, score] of expectedDirections) { - if (detectedDirection === expectedDirection) { - confidence += score * this.weightsRelative[fingerIdx]; - break; - } - } - } - return confidence / 10; - } -}; - -// src/hand/fingergesture.ts -var { thumb, index, middle, ring, pinky } = Finger; -var { none, half, full } = FingerCurl; -var { verticalUp, verticalDown, horizontalLeft, horizontalRight, diagonalUpRight, diagonalUpLeft, diagonalDownRight, diagonalDownLeft } = FingerDirection; -var ThumbsUp = new FingerGesture("thumbs up"); -ThumbsUp.curl(thumb, none, 1); -ThumbsUp.direction(thumb, verticalUp, 1); -ThumbsUp.direction(thumb, diagonalUpLeft, 0.25); -ThumbsUp.direction(thumb, diagonalUpRight, 0.25); -for (const finger of [Finger.index, Finger.middle, Finger.ring, Finger.pinky]) { - ThumbsUp.curl(finger, full, 1); - ThumbsUp.direction(finger, horizontalLeft, 1); - ThumbsUp.direction(finger, horizontalRight, 1); -} -var Victory = new FingerGesture("victory"); -Victory.curl(thumb, half, 0.5); -Victory.curl(thumb, none, 0.5); -Victory.direction(thumb, verticalUp, 1); -Victory.direction(thumb, diagonalUpLeft, 1); -Victory.curl(index, none, 1); -Victory.direction(index, verticalUp, 0.75); -Victory.direction(index, diagonalUpLeft, 1); -Victory.curl(middle, none, 1); -Victory.direction(middle, verticalUp, 1); -Victory.direction(middle, diagonalUpLeft, 0.75); -Victory.curl(ring, full, 1); -Victory.direction(ring, verticalUp, 0.2); -Victory.direction(ring, diagonalUpLeft, 1); -Victory.direction(ring, horizontalLeft, 0.2); -Victory.curl(pinky, full, 1); -Victory.direction(pinky, verticalUp, 0.2); -Victory.direction(pinky, diagonalUpLeft, 1); -Victory.direction(pinky, horizontalLeft, 0.2); -Victory.weight(index, 2); -Victory.weight(middle, 2); -var Point = new FingerGesture("point"); -Point.curl(thumb, full, 1); -Point.curl(index, none, 0.5); -Point.curl(middle, full, 0.5); -Point.curl(ring, full, 0.5); -Point.curl(pinky, full, 0.5); -Point.weight(index, 2); -Point.weight(middle, 2); -var MiddleFinger = new FingerGesture("middle finger"); -MiddleFinger.curl(thumb, none, 1); -MiddleFinger.curl(index, full, 0.5); -MiddleFinger.curl(middle, full, 0.5); -MiddleFinger.curl(ring, full, 0.5); -MiddleFinger.curl(pinky, full, 0.5); -MiddleFinger.weight(index, 2); -MiddleFinger.weight(middle, 2); -var OpenPalm = new FingerGesture("open palm"); -OpenPalm.curl(thumb, none, 0.75); -OpenPalm.curl(index, none, 0.75); -OpenPalm.curl(middle, none, 0.75); -OpenPalm.curl(ring, none, 0.75); -OpenPalm.curl(pinky, none, 0.75); -var fingergesture_default = [ThumbsUp, Victory, Point, MiddleFinger, OpenPalm]; - -// src/hand/fingerpose.ts -var minConfidence = 0.7; -var options3 = { - HALF_CURL_START_LIMIT: 60, - NO_CURL_START_LIMIT: 130, - DISTANCE_VOTE_POWER: 1.1, - SINGLE_ANGLE_VOTE_POWER: 0.9, - TOTAL_ANGLE_VOTE_POWER: 1.6 -}; -function calculateSlope(point1x, point1y, point2x, point2y) { - const value = (point1y - point2y) / (point1x - point2x); - let slope = Math.atan(value) * 180 / Math.PI; - if (slope <= 0) - slope = -slope; - else if (slope > 0) - slope = 180 - slope; - return slope; -} -function getSlopes(point1, point2) { - if (!point1 || !point2) - return [0, 0]; - const slopeXY = calculateSlope(point1[0], point1[1], point2[0], point2[1]); - if (point1.length === 2) - return slopeXY; - const slopeYZ = calculateSlope(point1[1], point1[2], point2[1], point2[2]); - return [slopeXY, slopeYZ]; -} -function angleOrientationAt(angle, weightageAt = 1) { - let isVertical = 0; - let isDiagonal = 0; - let isHorizontal = 0; - if (angle >= 75 && angle <= 105) - isVertical = 1 * weightageAt; - else if (angle >= 25 && angle <= 155) - isDiagonal = 1 * weightageAt; - else - isHorizontal = 1 * weightageAt; - return [isVertical, isDiagonal, isHorizontal]; -} -function estimateFingerCurl(startPoint, midPoint, endPoint) { - const start_mid_x_dist = startPoint[0] - midPoint[0]; - const start_end_x_dist = startPoint[0] - endPoint[0]; - const mid_end_x_dist = midPoint[0] - endPoint[0]; - const start_mid_y_dist = startPoint[1] - midPoint[1]; - const start_end_y_dist = startPoint[1] - endPoint[1]; - const mid_end_y_dist = midPoint[1] - endPoint[1]; - const start_mid_z_dist = startPoint[2] - midPoint[2]; - const start_end_z_dist = startPoint[2] - endPoint[2]; - const mid_end_z_dist = midPoint[2] - endPoint[2]; - const start_mid_dist = Math.sqrt(start_mid_x_dist * start_mid_x_dist + start_mid_y_dist * start_mid_y_dist + start_mid_z_dist * start_mid_z_dist); - const start_end_dist = Math.sqrt(start_end_x_dist * start_end_x_dist + start_end_y_dist * start_end_y_dist + start_end_z_dist * start_end_z_dist); - const mid_end_dist = Math.sqrt(mid_end_x_dist * mid_end_x_dist + mid_end_y_dist * mid_end_y_dist + mid_end_z_dist * mid_end_z_dist); - let cos_in = (mid_end_dist * mid_end_dist + start_mid_dist * start_mid_dist - start_end_dist * start_end_dist) / (2 * mid_end_dist * start_mid_dist); - if (cos_in > 1) - cos_in = 1; - else if (cos_in < -1) - cos_in = -1; - let angleOfCurve = Math.acos(cos_in); - angleOfCurve = 57.2958 * angleOfCurve % 180; - let fingerCurl; - if (angleOfCurve > options3.NO_CURL_START_LIMIT) - fingerCurl = FingerCurl.none; - else if (angleOfCurve > options3.HALF_CURL_START_LIMIT) - fingerCurl = FingerCurl.half; - else - fingerCurl = FingerCurl.full; - return fingerCurl; -} -function estimateHorizontalDirection(start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x) { - let estimatedDirection; - if (max_dist_x === Math.abs(start_end_x_dist)) { - if (start_end_x_dist > 0) - estimatedDirection = FingerDirection.horizontalLeft; - else - estimatedDirection = FingerDirection.horizontalRight; - } else if (max_dist_x === Math.abs(start_mid_x_dist)) { - if (start_mid_x_dist > 0) - estimatedDirection = FingerDirection.horizontalLeft; - else - estimatedDirection = FingerDirection.horizontalRight; - } else { - if (mid_end_x_dist > 0) - estimatedDirection = FingerDirection.horizontalLeft; - else - estimatedDirection = FingerDirection.horizontalRight; - } - return estimatedDirection; -} -function estimateVerticalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y) { - let estimatedDirection; - if (max_dist_y === Math.abs(start_end_y_dist)) { - if (start_end_y_dist < 0) - estimatedDirection = FingerDirection.verticalDown; - else - estimatedDirection = FingerDirection.verticalUp; - } else if (max_dist_y === Math.abs(start_mid_y_dist)) { - if (start_mid_y_dist < 0) - estimatedDirection = FingerDirection.verticalDown; - else - estimatedDirection = FingerDirection.verticalUp; - } else { - if (mid_end_y_dist < 0) - estimatedDirection = FingerDirection.verticalDown; - else - estimatedDirection = FingerDirection.verticalUp; - } - return estimatedDirection; -} -function estimateDiagonalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y, start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x) { - let estimatedDirection; - const reqd_vertical_direction = estimateVerticalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y); - const reqd_horizontal_direction = estimateHorizontalDirection(start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x); - if (reqd_vertical_direction === FingerDirection.verticalUp) { - if (reqd_horizontal_direction === FingerDirection.horizontalLeft) - estimatedDirection = FingerDirection.diagonalUpLeft; - else - estimatedDirection = FingerDirection.diagonalUpRight; - } else { - if (reqd_horizontal_direction === FingerDirection.horizontalLeft) - estimatedDirection = FingerDirection.diagonalDownLeft; - else - estimatedDirection = FingerDirection.diagonalDownRight; - } - return estimatedDirection; -} -function calculateFingerDirection(startPoint, midPoint, endPoint, fingerSlopes) { - const start_mid_x_dist = startPoint[0] - midPoint[0]; - const start_end_x_dist = startPoint[0] - endPoint[0]; - const mid_end_x_dist = midPoint[0] - endPoint[0]; - const start_mid_y_dist = startPoint[1] - midPoint[1]; - const start_end_y_dist = startPoint[1] - endPoint[1]; - const mid_end_y_dist = midPoint[1] - endPoint[1]; - const max_dist_x = Math.max(Math.abs(start_mid_x_dist), Math.abs(start_end_x_dist), Math.abs(mid_end_x_dist)); - const max_dist_y = Math.max(Math.abs(start_mid_y_dist), Math.abs(start_end_y_dist), Math.abs(mid_end_y_dist)); - let voteVertical = 0; - let voteDiagonal = 0; - let voteHorizontal = 0; - const start_end_x_y_dist_ratio = max_dist_y / (max_dist_x + 1e-5); - if (start_end_x_y_dist_ratio > 1.5) - voteVertical += options3.DISTANCE_VOTE_POWER; - else if (start_end_x_y_dist_ratio > 0.66) - voteDiagonal += options3.DISTANCE_VOTE_POWER; - else - voteHorizontal += options3.DISTANCE_VOTE_POWER; - const start_mid_dist = Math.sqrt(start_mid_x_dist * start_mid_x_dist + start_mid_y_dist * start_mid_y_dist); - const start_end_dist = Math.sqrt(start_end_x_dist * start_end_x_dist + start_end_y_dist * start_end_y_dist); - const mid_end_dist = Math.sqrt(mid_end_x_dist * mid_end_x_dist + mid_end_y_dist * mid_end_y_dist); - const max_dist = Math.max(start_mid_dist, start_end_dist, mid_end_dist); - let calc_start_point_x = startPoint[0]; - let calc_start_point_y = startPoint[1]; - let calc_end_point_x = endPoint[0]; - let calc_end_point_y = endPoint[1]; - if (max_dist === start_mid_dist) { - calc_end_point_x = endPoint[0]; - calc_end_point_y = endPoint[1]; - } else if (max_dist === mid_end_dist) { - calc_start_point_x = midPoint[0]; - calc_start_point_y = midPoint[1]; - } - const calcStartPoint = [calc_start_point_x, calc_start_point_y]; - const calcEndPoint = [calc_end_point_x, calc_end_point_y]; - const totalAngle = getSlopes(calcStartPoint, calcEndPoint); - const votes = angleOrientationAt(totalAngle, options3.TOTAL_ANGLE_VOTE_POWER); - voteVertical += votes[0]; - voteDiagonal += votes[1]; - voteHorizontal += votes[2]; - for (const fingerSlope of fingerSlopes) { - const fingerVotes = angleOrientationAt(fingerSlope, options3.SINGLE_ANGLE_VOTE_POWER); - voteVertical += fingerVotes[0]; - voteDiagonal += fingerVotes[1]; - voteHorizontal += fingerVotes[2]; - } - let estimatedDirection; - if (voteVertical === Math.max(voteVertical, voteDiagonal, voteHorizontal)) { - estimatedDirection = estimateVerticalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y); - } else if (voteHorizontal === Math.max(voteDiagonal, voteHorizontal)) { - estimatedDirection = estimateHorizontalDirection(start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x); - } else { - estimatedDirection = estimateDiagonalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y, start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x); - } - return estimatedDirection; -} -function estimate(landmarks) { - const slopesXY = []; - const slopesYZ = []; - const fingerCurls = []; - const fingerDirections = []; - if (!landmarks) - return { curls: fingerCurls, directions: fingerDirections }; - for (const finger of Finger.all) { - const points = Finger.getPoints(finger); - const slopeAtXY = []; - const slopeAtYZ = []; - for (const point2 of points) { - const point1 = landmarks[point2[0]]; - const point22 = landmarks[point2[1]]; - const slopes = getSlopes(point1, point22); - const slopeXY = slopes[0]; - const slopeYZ = slopes[1]; - slopeAtXY.push(slopeXY); - slopeAtYZ.push(slopeYZ); - } - slopesXY.push(slopeAtXY); - slopesYZ.push(slopeAtYZ); - } - for (const finger of Finger.all) { - const pointIndexAt = finger === Finger.thumb ? 1 : 0; - const fingerPointsAt = Finger.getPoints(finger); - const startPoint = landmarks[fingerPointsAt[pointIndexAt][0]]; - const midPoint = landmarks[fingerPointsAt[pointIndexAt + 1][1]]; - const endPoint = landmarks[fingerPointsAt[3][1]]; - const fingerCurled = estimateFingerCurl(startPoint, midPoint, endPoint); - const fingerPosition = calculateFingerDirection(startPoint, midPoint, endPoint, slopesXY[finger].slice(pointIndexAt)); - fingerCurls[finger] = fingerCurled; - fingerDirections[finger] = fingerPosition; - } - return { curls: fingerCurls, directions: fingerDirections }; -} -function analyze(keypoints) { - if (!keypoints || keypoints.length === 0) - return null; - const estimatorRes = estimate(keypoints); - const landmarks = {}; - for (const fingerIdx of Finger.all) { - landmarks[Finger.getName(fingerIdx)] = { - curl: FingerCurl.getName(estimatorRes.curls[fingerIdx]), - direction: FingerDirection.getName(estimatorRes.directions[fingerIdx]) - }; - } - return landmarks; -} -function match(keypoints) { - const poses = []; - if (!keypoints || keypoints.length === 0) - return poses; - const estimatorRes = estimate(keypoints); - for (const gesture2 of fingergesture_default) { - const confidence = gesture2.matchAgainst(estimatorRes.curls, estimatorRes.directions); - if (confidence >= minConfidence) - poses.push({ name: gesture2.name, confidence }); - } - return poses; -} - -// src/gesture/gesture.ts -var body2 = (res) => { - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - const leftWrist = res[i].keypoints.find((a) => a.part === "leftWrist"); - const rightWrist = res[i].keypoints.find((a) => a.part === "rightWrist"); - const nose = res[i].keypoints.find((a) => a.part === "nose"); - if (nose && leftWrist && rightWrist && leftWrist.position[1] < nose.position[1] && rightWrist.position[1] < nose.position[1]) - gestures.push({ body: i, gesture: "i give up" }); - else if (nose && leftWrist && leftWrist.position[1] < nose.position[1]) - gestures.push({ body: i, gesture: "raise left hand" }); - else if (nose && rightWrist && rightWrist.position[1] < nose.position[1]) - gestures.push({ body: i, gesture: "raise right hand" }); - const leftShoulder = res[i].keypoints.find((a) => a.part === "leftShoulder"); - const rightShoulder = res[i].keypoints.find((a) => a.part === "rightShoulder"); - if (leftShoulder && rightShoulder && Math.abs(leftShoulder.positionRaw[1] - rightShoulder.positionRaw[1]) > 0.1) { - gestures.push({ body: i, gesture: `leaning ${leftShoulder.position[1] > rightShoulder.position[1] ? "left" : "right"}` }); - } - } - return gestures; -}; -var face2 = (res) => { - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - if (res[i].mesh && res[i].mesh.length > 450) { - const zDiff = (res[i].mesh[33][2] || 0) - (res[i].mesh[263][2] || 0); - const xDiff = res[i].mesh[33][0] - res[i].mesh[263][0]; - if (Math.abs(zDiff / xDiff) <= 0.15) - gestures.push({ face: i, gesture: "facing center" }); - else - gestures.push({ face: i, gesture: `facing ${zDiff < 0 ? "left" : "right"}` }); - const openLeft = Math.abs(res[i].mesh[374][1] - res[i].mesh[386][1]) / Math.abs(res[i].mesh[443][1] - res[i].mesh[450][1]); - if (openLeft < 0.2) - gestures.push({ face: i, gesture: "blink left eye" }); - const openRight = Math.abs(res[i].mesh[145][1] - res[i].mesh[159][1]) / Math.abs(res[i].mesh[223][1] - res[i].mesh[230][1]); - if (openRight < 0.2) - gestures.push({ face: i, gesture: "blink right eye" }); - const mouthOpen = Math.min(100, 500 * Math.abs(res[i].mesh[13][1] - res[i].mesh[14][1]) / Math.abs(res[i].mesh[10][1] - res[i].mesh[152][1])); - if (mouthOpen > 10) - gestures.push({ face: i, gesture: `mouth ${Math.trunc(mouthOpen)}% open` }); - const chinDepth = res[i].mesh[152][2] || 0; - if (Math.abs(chinDepth) > 10) - gestures.push({ face: i, gesture: `head ${chinDepth < 0 ? "up" : "down"}` }); - } - } - return gestures; -}; -var iris2 = (res) => { - var _a, _b, _c, _d; - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - if (!((_b = (_a = res[i].annotations) == null ? void 0 : _a.leftEyeIris) == null ? void 0 : _b[0]) || !((_d = (_c = res[i].annotations) == null ? void 0 : _c.rightEyeIris) == null ? void 0 : _d[0])) - continue; - const sizeXLeft = res[i].annotations.leftEyeIris[3][0] - res[i].annotations.leftEyeIris[1][0]; - const sizeYLeft = res[i].annotations.leftEyeIris[4][1] - res[i].annotations.leftEyeIris[2][1]; - const areaLeft = Math.abs(sizeXLeft * sizeYLeft); - const sizeXRight = res[i].annotations.rightEyeIris[3][0] - res[i].annotations.rightEyeIris[1][0]; - const sizeYRight = res[i].annotations.rightEyeIris[4][1] - res[i].annotations.rightEyeIris[2][1]; - const areaRight = Math.abs(sizeXRight * sizeYRight); - let center = false; - const difference = Math.abs(areaLeft - areaRight) / Math.max(areaLeft, areaRight); - if (difference < 0.25) { - center = true; - gestures.push({ iris: i, gesture: "facing center" }); - } - const leftIrisCenterX = Math.abs(res[i].mesh[263][0] - res[i].annotations.leftEyeIris[0][0]) / res[i].box[2]; - const rightIrisCenterX = Math.abs(res[i].mesh[33][0] - res[i].annotations.rightEyeIris[0][0]) / res[i].box[2]; - if (leftIrisCenterX > 0.06 || rightIrisCenterX > 0.06) - center = false; - if (leftIrisCenterX > rightIrisCenterX) { - if (leftIrisCenterX > 0.05) - gestures.push({ iris: i, gesture: "looking right" }); - } else { - if (rightIrisCenterX > 0.05) - gestures.push({ iris: i, gesture: "looking left" }); - } - const rightIrisCenterY = Math.abs(res[i].mesh[145][1] - res[i].annotations.rightEyeIris[0][1]) / res[i].box[3]; - const leftIrisCenterY = Math.abs(res[i].mesh[374][1] - res[i].annotations.leftEyeIris[0][1]) / res[i].box[3]; - if (leftIrisCenterY < 0.01 || rightIrisCenterY < 0.01 || leftIrisCenterY > 0.022 || rightIrisCenterY > 0.022) - center = false; - if (leftIrisCenterY < 0.01 || rightIrisCenterY < 0.01) - gestures.push({ iris: i, gesture: "looking down" }); - if (leftIrisCenterY > 0.022 || rightIrisCenterY > 0.022) - gestures.push({ iris: i, gesture: "looking up" }); - if (center) - gestures.push({ iris: i, gesture: "looking center" }); - } - return gestures; -}; -var hand2 = (res) => { - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - const fingers = []; - if (res[i].annotations) { - for (const [finger, pos] of Object.entries(res[i].annotations)) { - if (finger !== "palmBase" && Array.isArray(pos) && pos[0]) - fingers.push({ name: finger.toLowerCase(), position: pos[0] }); - } - } - if (fingers && fingers.length > 0) { - const closest = fingers.reduce((best, a) => (best.position[2] || 0) < (a.position[2] || 0) ? best : a); - gestures.push({ hand: i, gesture: `${closest.name} forward` }); - const highest = fingers.reduce((best, a) => best.position[1] < a.position[1] ? best : a); - gestures.push({ hand: i, gesture: `${highest.name} up` }); - } - if (res[i].keypoints) { - const poses = match(res[i].keypoints); - for (const pose of poses) - gestures.push({ hand: i, gesture: pose.name }); - } - } - return gestures; -}; - -// src/hand/handposedetector.ts -var tf27 = __toESM(require_tfjs_esm()); - -// src/hand/handposeutil.ts -var tf26 = __toESM(require_tfjs_esm()); -function getBoxSize2(box) { - return [ - Math.abs(box.endPoint[0] - box.startPoint[0]), - Math.abs(box.endPoint[1] - box.startPoint[1]) - ]; -} -function getBoxCenter2(box) { - return [ - box.startPoint[0] + (box.endPoint[0] - box.startPoint[0]) / 2, - box.startPoint[1] + (box.endPoint[1] - box.startPoint[1]) / 2 - ]; -} -function cutBoxFromImageAndResize(box, image28, cropSize) { - const h = image28.shape[1]; - const w = image28.shape[2]; - const boxes = [[ - box.startPoint[1] / h, - box.startPoint[0] / w, - box.endPoint[1] / h, - box.endPoint[0] / w - ]]; - return tf26.image.cropAndResize(image28, boxes, [0], cropSize); -} -function scaleBoxCoordinates2(box, factor) { - const startPoint = [box.startPoint[0] * factor[0], box.startPoint[1] * factor[1]]; - const endPoint = [box.endPoint[0] * factor[0], box.endPoint[1] * factor[1]]; - const palmLandmarks = box.palmLandmarks.map((coord) => { - const scaledCoord = [coord[0] * factor[0], coord[1] * factor[1]]; - return scaledCoord; - }); - return { startPoint, endPoint, palmLandmarks, confidence: box.confidence }; -} -function enlargeBox2(box, factor = 1.5) { - const center = getBoxCenter2(box); - const size2 = getBoxSize2(box); - const newHalfSize = [factor * size2[0] / 2, factor * size2[1] / 2]; - const startPoint = [center[0] - newHalfSize[0], center[1] - newHalfSize[1]]; - const endPoint = [center[0] + newHalfSize[0], center[1] + newHalfSize[1]]; - return { startPoint, endPoint, palmLandmarks: box.palmLandmarks }; -} -function squarifyBox2(box) { - const centers = getBoxCenter2(box); - const size2 = getBoxSize2(box); - const maxEdge = Math.max(...size2); - const halfSize = maxEdge / 2; - const startPoint = [centers[0] - halfSize, centers[1] - halfSize]; - const endPoint = [centers[0] + halfSize, centers[1] + halfSize]; - return { startPoint, endPoint, palmLandmarks: box.palmLandmarks }; -} -function normalizeRadians2(angle) { - return angle - 2 * Math.PI * Math.floor((angle + Math.PI) / (2 * Math.PI)); -} -function computeRotation2(point1, point2) { - const radians = Math.PI / 2 - Math.atan2(-(point2[1] - point1[1]), point2[0] - point1[0]); - return normalizeRadians2(radians); -} -var buildTranslationMatrix2 = (x, y) => [[1, 0, x], [0, 1, y], [0, 0, 1]]; -function dot2(v1, v2) { - let product = 0; - for (let i = 0; i < v1.length; i++) { - product += v1[i] * v2[i]; - } - return product; -} -function getColumnFrom2DArr2(arr, columnIndex) { - const column = []; - for (let i = 0; i < arr.length; i++) { - column.push(arr[i][columnIndex]); - } - return column; -} -function multiplyTransformMatrices2(mat1, mat2) { - const product = []; - const size2 = mat1.length; - for (let row = 0; row < size2; row++) { - product.push([]); - for (let col = 0; col < size2; col++) { - product[row].push(dot2(mat1[row], getColumnFrom2DArr2(mat2, col))); - } - } - return product; -} -function buildRotationMatrix2(rotation, center) { - const cosA = Math.cos(rotation); - const sinA = Math.sin(rotation); - const rotationMatrix = [[cosA, -sinA, 0], [sinA, cosA, 0], [0, 0, 1]]; - const translationMatrix = buildTranslationMatrix2(center[0], center[1]); - const translationTimesRotation = multiplyTransformMatrices2(translationMatrix, rotationMatrix); - const negativeTranslationMatrix = buildTranslationMatrix2(-center[0], -center[1]); - return multiplyTransformMatrices2(translationTimesRotation, negativeTranslationMatrix); -} -function invertTransformMatrix2(matrix) { - const rotationComponent = [[matrix[0][0], matrix[1][0]], [matrix[0][1], matrix[1][1]]]; - const translationComponent = [matrix[0][2], matrix[1][2]]; - const invertedTranslation = [ - -dot2(rotationComponent[0], translationComponent), - -dot2(rotationComponent[1], translationComponent) - ]; - return [ - rotationComponent[0].concat(invertedTranslation[0]), - rotationComponent[1].concat(invertedTranslation[1]), - [0, 0, 1] - ]; -} -function rotatePoint2(homogeneousCoordinate, rotationMatrix) { - return [ - dot2(homogeneousCoordinate, rotationMatrix[0]), - dot2(homogeneousCoordinate, rotationMatrix[1]) - ]; -} - -// src/hand/handposeanchors.ts -var anchors2 = [ - { x: 0.015625, y: 0.015625 }, - { x: 0.015625, y: 0.015625 }, - { x: 0.046875, y: 0.015625 }, - { x: 0.046875, y: 0.015625 }, - { x: 0.078125, y: 0.015625 }, - { x: 0.078125, y: 0.015625 }, - { x: 0.109375, y: 0.015625 }, - { x: 0.109375, y: 0.015625 }, - { x: 0.140625, y: 0.015625 }, - { x: 0.140625, y: 0.015625 }, - { x: 0.171875, y: 0.015625 }, - { x: 0.171875, y: 0.015625 }, - { x: 0.203125, y: 0.015625 }, - { x: 0.203125, y: 0.015625 }, - { x: 0.234375, y: 0.015625 }, - { x: 0.234375, y: 0.015625 }, - { x: 0.265625, y: 0.015625 }, - { x: 0.265625, y: 0.015625 }, - { x: 0.296875, y: 0.015625 }, - { x: 0.296875, y: 0.015625 }, - { x: 0.328125, y: 0.015625 }, - { x: 0.328125, y: 0.015625 }, - { x: 0.359375, y: 0.015625 }, - { x: 0.359375, y: 0.015625 }, - { x: 0.390625, y: 0.015625 }, - { x: 0.390625, y: 0.015625 }, - { x: 0.421875, y: 0.015625 }, - { x: 0.421875, y: 0.015625 }, - { x: 0.453125, y: 0.015625 }, - { x: 0.453125, y: 0.015625 }, - { x: 0.484375, y: 0.015625 }, - { x: 0.484375, y: 0.015625 }, - { x: 0.515625, y: 0.015625 }, - { x: 0.515625, y: 0.015625 }, - { x: 0.546875, y: 0.015625 }, - { x: 0.546875, y: 0.015625 }, - { x: 0.578125, y: 0.015625 }, - { x: 0.578125, y: 0.015625 }, - { x: 0.609375, y: 0.015625 }, - { x: 0.609375, y: 0.015625 }, - { x: 0.640625, y: 0.015625 }, - { x: 0.640625, y: 0.015625 }, - { x: 0.671875, y: 0.015625 }, - { x: 0.671875, y: 0.015625 }, - { x: 0.703125, y: 0.015625 }, - { x: 0.703125, y: 0.015625 }, - { x: 0.734375, y: 0.015625 }, - { x: 0.734375, y: 0.015625 }, - { x: 0.765625, y: 0.015625 }, - { x: 0.765625, y: 0.015625 }, - { x: 0.796875, y: 0.015625 }, - { x: 0.796875, y: 0.015625 }, - { x: 0.828125, y: 0.015625 }, - { x: 0.828125, y: 0.015625 }, - { x: 0.859375, y: 0.015625 }, - { x: 0.859375, y: 0.015625 }, - { x: 0.890625, y: 0.015625 }, - { x: 0.890625, y: 0.015625 }, - { x: 0.921875, y: 0.015625 }, - { x: 0.921875, y: 0.015625 }, - { x: 0.953125, y: 0.015625 }, - { x: 0.953125, y: 0.015625 }, - { x: 0.984375, y: 0.015625 }, - { x: 0.984375, y: 0.015625 }, - { x: 0.015625, y: 0.046875 }, - { x: 0.015625, y: 0.046875 }, - { x: 0.046875, y: 0.046875 }, - { x: 0.046875, y: 0.046875 }, - { x: 0.078125, y: 0.046875 }, - { x: 0.078125, y: 0.046875 }, - { x: 0.109375, y: 0.046875 }, - { x: 0.109375, y: 0.046875 }, - { x: 0.140625, y: 0.046875 }, - { x: 0.140625, y: 0.046875 }, - { x: 0.171875, y: 0.046875 }, - { x: 0.171875, y: 0.046875 }, - { x: 0.203125, y: 0.046875 }, - { x: 0.203125, y: 0.046875 }, - { x: 0.234375, y: 0.046875 }, - { x: 0.234375, y: 0.046875 }, - { x: 0.265625, y: 0.046875 }, - { x: 0.265625, y: 0.046875 }, - { x: 0.296875, y: 0.046875 }, - { x: 0.296875, y: 0.046875 }, - { x: 0.328125, y: 0.046875 }, - { x: 0.328125, y: 0.046875 }, - { x: 0.359375, y: 0.046875 }, - { x: 0.359375, y: 0.046875 }, - { x: 0.390625, y: 0.046875 }, - { x: 0.390625, y: 0.046875 }, - { x: 0.421875, y: 0.046875 }, - { x: 0.421875, y: 0.046875 }, - { x: 0.453125, y: 0.046875 }, - { x: 0.453125, y: 0.046875 }, - { x: 0.484375, y: 0.046875 }, - { x: 0.484375, y: 0.046875 }, - { x: 0.515625, y: 0.046875 }, - { x: 0.515625, y: 0.046875 }, - { x: 0.546875, y: 0.046875 }, - { x: 0.546875, y: 0.046875 }, - { x: 0.578125, y: 0.046875 }, - { x: 0.578125, y: 0.046875 }, - { x: 0.609375, y: 0.046875 }, - { x: 0.609375, y: 0.046875 }, - { x: 0.640625, y: 0.046875 }, - { x: 0.640625, y: 0.046875 }, - { x: 0.671875, y: 0.046875 }, - { x: 0.671875, y: 0.046875 }, - { x: 0.703125, y: 0.046875 }, - { x: 0.703125, y: 0.046875 }, - { x: 0.734375, y: 0.046875 }, - { x: 0.734375, y: 0.046875 }, - { x: 0.765625, y: 0.046875 }, - { x: 0.765625, y: 0.046875 }, - { x: 0.796875, y: 0.046875 }, - { x: 0.796875, y: 0.046875 }, - { x: 0.828125, y: 0.046875 }, - { x: 0.828125, y: 0.046875 }, - { x: 0.859375, y: 0.046875 }, - { x: 0.859375, y: 0.046875 }, - { x: 0.890625, y: 0.046875 }, - { x: 0.890625, y: 0.046875 }, - { x: 0.921875, y: 0.046875 }, - { x: 0.921875, y: 0.046875 }, - { x: 0.953125, y: 0.046875 }, - { x: 0.953125, y: 0.046875 }, - { x: 0.984375, y: 0.046875 }, - { x: 0.984375, y: 0.046875 }, - { x: 0.015625, y: 0.078125 }, - { x: 0.015625, y: 0.078125 }, - { x: 0.046875, y: 0.078125 }, - { x: 0.046875, y: 0.078125 }, - { x: 0.078125, y: 0.078125 }, - { x: 0.078125, y: 0.078125 }, - { x: 0.109375, y: 0.078125 }, - { x: 0.109375, y: 0.078125 }, - { x: 0.140625, y: 0.078125 }, - { x: 0.140625, y: 0.078125 }, - { x: 0.171875, y: 0.078125 }, - { x: 0.171875, y: 0.078125 }, - { x: 0.203125, y: 0.078125 }, - { x: 0.203125, y: 0.078125 }, - { x: 0.234375, y: 0.078125 }, - { x: 0.234375, y: 0.078125 }, - { x: 0.265625, y: 0.078125 }, - { x: 0.265625, y: 0.078125 }, - { x: 0.296875, y: 0.078125 }, - { x: 0.296875, y: 0.078125 }, - { x: 0.328125, y: 0.078125 }, - { x: 0.328125, y: 0.078125 }, - { x: 0.359375, y: 0.078125 }, - { x: 0.359375, y: 0.078125 }, - { x: 0.390625, y: 0.078125 }, - { x: 0.390625, y: 0.078125 }, - { x: 0.421875, y: 0.078125 }, - { x: 0.421875, y: 0.078125 }, - { x: 0.453125, y: 0.078125 }, - { x: 0.453125, y: 0.078125 }, - { x: 0.484375, y: 0.078125 }, - { x: 0.484375, y: 0.078125 }, - { x: 0.515625, y: 0.078125 }, - { x: 0.515625, y: 0.078125 }, - { x: 0.546875, y: 0.078125 }, - { x: 0.546875, y: 0.078125 }, - { x: 0.578125, y: 0.078125 }, - { x: 0.578125, y: 0.078125 }, - { x: 0.609375, y: 0.078125 }, - { x: 0.609375, y: 0.078125 }, - { x: 0.640625, y: 0.078125 }, - { x: 0.640625, y: 0.078125 }, - { x: 0.671875, y: 0.078125 }, - { x: 0.671875, y: 0.078125 }, - { x: 0.703125, y: 0.078125 }, - { x: 0.703125, y: 0.078125 }, - { x: 0.734375, y: 0.078125 }, - { x: 0.734375, y: 0.078125 }, - { x: 0.765625, y: 0.078125 }, - { x: 0.765625, y: 0.078125 }, - { x: 0.796875, y: 0.078125 }, - { x: 0.796875, y: 0.078125 }, - { x: 0.828125, y: 0.078125 }, - { x: 0.828125, y: 0.078125 }, - { x: 0.859375, y: 0.078125 }, - { x: 0.859375, y: 0.078125 }, - { x: 0.890625, y: 0.078125 }, - { x: 0.890625, y: 0.078125 }, - { x: 0.921875, y: 0.078125 }, - { x: 0.921875, y: 0.078125 }, - { x: 0.953125, y: 0.078125 }, - { x: 0.953125, y: 0.078125 }, - { x: 0.984375, y: 0.078125 }, - { x: 0.984375, y: 0.078125 }, - { x: 0.015625, y: 0.109375 }, - { x: 0.015625, y: 0.109375 }, - { x: 0.046875, y: 0.109375 }, - { x: 0.046875, y: 0.109375 }, - { x: 0.078125, y: 0.109375 }, - { x: 0.078125, y: 0.109375 }, - { x: 0.109375, y: 0.109375 }, - { x: 0.109375, y: 0.109375 }, - { x: 0.140625, y: 0.109375 }, - { x: 0.140625, y: 0.109375 }, - { x: 0.171875, y: 0.109375 }, - { x: 0.171875, y: 0.109375 }, - { x: 0.203125, y: 0.109375 }, - { x: 0.203125, y: 0.109375 }, - { x: 0.234375, y: 0.109375 }, - { x: 0.234375, y: 0.109375 }, - { x: 0.265625, y: 0.109375 }, - { x: 0.265625, y: 0.109375 }, - { x: 0.296875, y: 0.109375 }, - { x: 0.296875, y: 0.109375 }, - { x: 0.328125, y: 0.109375 }, - { x: 0.328125, y: 0.109375 }, - { x: 0.359375, y: 0.109375 }, - { x: 0.359375, y: 0.109375 }, - { x: 0.390625, y: 0.109375 }, - { x: 0.390625, y: 0.109375 }, - { x: 0.421875, y: 0.109375 }, - { x: 0.421875, y: 0.109375 }, - { x: 0.453125, y: 0.109375 }, - { x: 0.453125, y: 0.109375 }, - { x: 0.484375, y: 0.109375 }, - { x: 0.484375, y: 0.109375 }, - { x: 0.515625, y: 0.109375 }, - { x: 0.515625, y: 0.109375 }, - { x: 0.546875, y: 0.109375 }, - { x: 0.546875, y: 0.109375 }, - { x: 0.578125, y: 0.109375 }, - { x: 0.578125, y: 0.109375 }, - { x: 0.609375, y: 0.109375 }, - { x: 0.609375, y: 0.109375 }, - { x: 0.640625, y: 0.109375 }, - { x: 0.640625, y: 0.109375 }, - { x: 0.671875, y: 0.109375 }, - { x: 0.671875, y: 0.109375 }, - { x: 0.703125, y: 0.109375 }, - { x: 0.703125, y: 0.109375 }, - { x: 0.734375, y: 0.109375 }, - { x: 0.734375, y: 0.109375 }, - { x: 0.765625, y: 0.109375 }, - { x: 0.765625, y: 0.109375 }, - { x: 0.796875, y: 0.109375 }, - { x: 0.796875, y: 0.109375 }, - { x: 0.828125, y: 0.109375 }, - { x: 0.828125, y: 0.109375 }, - { x: 0.859375, y: 0.109375 }, - { x: 0.859375, y: 0.109375 }, - { x: 0.890625, y: 0.109375 }, - { x: 0.890625, y: 0.109375 }, - { x: 0.921875, y: 0.109375 }, - { x: 0.921875, y: 0.109375 }, - { x: 0.953125, y: 0.109375 }, - { x: 0.953125, y: 0.109375 }, - { x: 0.984375, y: 0.109375 }, - { x: 0.984375, y: 0.109375 }, - { x: 0.015625, y: 0.140625 }, - { x: 0.015625, y: 0.140625 }, - { x: 0.046875, y: 0.140625 }, - { x: 0.046875, y: 0.140625 }, - { x: 0.078125, y: 0.140625 }, - { x: 0.078125, y: 0.140625 }, - { x: 0.109375, y: 0.140625 }, - { x: 0.109375, y: 0.140625 }, - { x: 0.140625, y: 0.140625 }, - { x: 0.140625, y: 0.140625 }, - { x: 0.171875, y: 0.140625 }, - { x: 0.171875, y: 0.140625 }, - { x: 0.203125, y: 0.140625 }, - { x: 0.203125, y: 0.140625 }, - { x: 0.234375, y: 0.140625 }, - { x: 0.234375, y: 0.140625 }, - { x: 0.265625, y: 0.140625 }, - { x: 0.265625, y: 0.140625 }, - { x: 0.296875, y: 0.140625 }, - { x: 0.296875, y: 0.140625 }, - { x: 0.328125, y: 0.140625 }, - { x: 0.328125, y: 0.140625 }, - { x: 0.359375, y: 0.140625 }, - { x: 0.359375, y: 0.140625 }, - { x: 0.390625, y: 0.140625 }, - { x: 0.390625, y: 0.140625 }, - { x: 0.421875, y: 0.140625 }, - { x: 0.421875, y: 0.140625 }, - { x: 0.453125, y: 0.140625 }, - { x: 0.453125, y: 0.140625 }, - { x: 0.484375, y: 0.140625 }, - { x: 0.484375, y: 0.140625 }, - { x: 0.515625, y: 0.140625 }, - { x: 0.515625, y: 0.140625 }, - { x: 0.546875, y: 0.140625 }, - { x: 0.546875, y: 0.140625 }, - { x: 0.578125, y: 0.140625 }, - { x: 0.578125, y: 0.140625 }, - { x: 0.609375, y: 0.140625 }, - { x: 0.609375, y: 0.140625 }, - { x: 0.640625, y: 0.140625 }, - { x: 0.640625, y: 0.140625 }, - { x: 0.671875, y: 0.140625 }, - { x: 0.671875, y: 0.140625 }, - { x: 0.703125, y: 0.140625 }, - { x: 0.703125, y: 0.140625 }, - { x: 0.734375, y: 0.140625 }, - { x: 0.734375, y: 0.140625 }, - { x: 0.765625, y: 0.140625 }, - { x: 0.765625, y: 0.140625 }, - { x: 0.796875, y: 0.140625 }, - { x: 0.796875, y: 0.140625 }, - { x: 0.828125, y: 0.140625 }, - { x: 0.828125, y: 0.140625 }, - { x: 0.859375, y: 0.140625 }, - { x: 0.859375, y: 0.140625 }, - { x: 0.890625, y: 0.140625 }, - { x: 0.890625, y: 0.140625 }, - { x: 0.921875, y: 0.140625 }, - { x: 0.921875, y: 0.140625 }, - { x: 0.953125, y: 0.140625 }, - { x: 0.953125, y: 0.140625 }, - { x: 0.984375, y: 0.140625 }, - { x: 0.984375, y: 0.140625 }, - { x: 0.015625, y: 0.171875 }, - { x: 0.015625, y: 0.171875 }, - { x: 0.046875, y: 0.171875 }, - { x: 0.046875, y: 0.171875 }, - { x: 0.078125, y: 0.171875 }, - { x: 0.078125, y: 0.171875 }, - { x: 0.109375, y: 0.171875 }, - { x: 0.109375, y: 0.171875 }, - { x: 0.140625, y: 0.171875 }, - { x: 0.140625, y: 0.171875 }, - { x: 0.171875, y: 0.171875 }, - { x: 0.171875, y: 0.171875 }, - { x: 0.203125, y: 0.171875 }, - { x: 0.203125, y: 0.171875 }, - { x: 0.234375, y: 0.171875 }, - { x: 0.234375, y: 0.171875 }, - { x: 0.265625, y: 0.171875 }, - { x: 0.265625, y: 0.171875 }, - { x: 0.296875, y: 0.171875 }, - { x: 0.296875, y: 0.171875 }, - { x: 0.328125, y: 0.171875 }, - { x: 0.328125, y: 0.171875 }, - { x: 0.359375, y: 0.171875 }, - { x: 0.359375, y: 0.171875 }, - { x: 0.390625, y: 0.171875 }, - { x: 0.390625, y: 0.171875 }, - { x: 0.421875, y: 0.171875 }, - { x: 0.421875, y: 0.171875 }, - { x: 0.453125, y: 0.171875 }, - { x: 0.453125, y: 0.171875 }, - { x: 0.484375, y: 0.171875 }, - { x: 0.484375, y: 0.171875 }, - { x: 0.515625, y: 0.171875 }, - { x: 0.515625, y: 0.171875 }, - { x: 0.546875, y: 0.171875 }, - { x: 0.546875, y: 0.171875 }, - { x: 0.578125, y: 0.171875 }, - { x: 0.578125, y: 0.171875 }, - { x: 0.609375, y: 0.171875 }, - { x: 0.609375, y: 0.171875 }, - { x: 0.640625, y: 0.171875 }, - { x: 0.640625, y: 0.171875 }, - { x: 0.671875, y: 0.171875 }, - { x: 0.671875, y: 0.171875 }, - { x: 0.703125, y: 0.171875 }, - { x: 0.703125, y: 0.171875 }, - { x: 0.734375, y: 0.171875 }, - { x: 0.734375, y: 0.171875 }, - { x: 0.765625, y: 0.171875 }, - { x: 0.765625, y: 0.171875 }, - { x: 0.796875, y: 0.171875 }, - { x: 0.796875, y: 0.171875 }, - { x: 0.828125, y: 0.171875 }, - { x: 0.828125, y: 0.171875 }, - { x: 0.859375, y: 0.171875 }, - { x: 0.859375, y: 0.171875 }, - { x: 0.890625, y: 0.171875 }, - { x: 0.890625, y: 0.171875 }, - { x: 0.921875, y: 0.171875 }, - { x: 0.921875, y: 0.171875 }, - { x: 0.953125, y: 0.171875 }, - { x: 0.953125, y: 0.171875 }, - { x: 0.984375, y: 0.171875 }, - { x: 0.984375, y: 0.171875 }, - { x: 0.015625, y: 0.203125 }, - { x: 0.015625, y: 0.203125 }, - { x: 0.046875, y: 0.203125 }, - { x: 0.046875, y: 0.203125 }, - { x: 0.078125, y: 0.203125 }, - { x: 0.078125, y: 0.203125 }, - { x: 0.109375, y: 0.203125 }, - { x: 0.109375, y: 0.203125 }, - { x: 0.140625, y: 0.203125 }, - { x: 0.140625, y: 0.203125 }, - { x: 0.171875, y: 0.203125 }, - { x: 0.171875, y: 0.203125 }, - { x: 0.203125, y: 0.203125 }, - { x: 0.203125, y: 0.203125 }, - { x: 0.234375, y: 0.203125 }, - { x: 0.234375, y: 0.203125 }, - { x: 0.265625, y: 0.203125 }, - { x: 0.265625, y: 0.203125 }, - { x: 0.296875, y: 0.203125 }, - { x: 0.296875, y: 0.203125 }, - { x: 0.328125, y: 0.203125 }, - { x: 0.328125, y: 0.203125 }, - { x: 0.359375, y: 0.203125 }, - { x: 0.359375, y: 0.203125 }, - { x: 0.390625, y: 0.203125 }, - { x: 0.390625, y: 0.203125 }, - { x: 0.421875, y: 0.203125 }, - { x: 0.421875, y: 0.203125 }, - { x: 0.453125, y: 0.203125 }, - { x: 0.453125, y: 0.203125 }, - { x: 0.484375, y: 0.203125 }, - { x: 0.484375, y: 0.203125 }, - { x: 0.515625, y: 0.203125 }, - { x: 0.515625, y: 0.203125 }, - { x: 0.546875, y: 0.203125 }, - { x: 0.546875, y: 0.203125 }, - { x: 0.578125, y: 0.203125 }, - { x: 0.578125, y: 0.203125 }, - { x: 0.609375, y: 0.203125 }, - { x: 0.609375, y: 0.203125 }, - { x: 0.640625, y: 0.203125 }, - { x: 0.640625, y: 0.203125 }, - { x: 0.671875, y: 0.203125 }, - { x: 0.671875, y: 0.203125 }, - { x: 0.703125, y: 0.203125 }, - { x: 0.703125, y: 0.203125 }, - { x: 0.734375, y: 0.203125 }, - { x: 0.734375, y: 0.203125 }, - { x: 0.765625, y: 0.203125 }, - { x: 0.765625, y: 0.203125 }, - { x: 0.796875, y: 0.203125 }, - { x: 0.796875, y: 0.203125 }, - { x: 0.828125, y: 0.203125 }, - { x: 0.828125, y: 0.203125 }, - { x: 0.859375, y: 0.203125 }, - { x: 0.859375, y: 0.203125 }, - { x: 0.890625, y: 0.203125 }, - { x: 0.890625, y: 0.203125 }, - { x: 0.921875, y: 0.203125 }, - { x: 0.921875, y: 0.203125 }, - { x: 0.953125, y: 0.203125 }, - { x: 0.953125, y: 0.203125 }, - { x: 0.984375, y: 0.203125 }, - { x: 0.984375, y: 0.203125 }, - { x: 0.015625, y: 0.234375 }, - { x: 0.015625, y: 0.234375 }, - { x: 0.046875, y: 0.234375 }, - { x: 0.046875, y: 0.234375 }, - { x: 0.078125, y: 0.234375 }, - { x: 0.078125, y: 0.234375 }, - { x: 0.109375, y: 0.234375 }, - { x: 0.109375, y: 0.234375 }, - { x: 0.140625, y: 0.234375 }, - { x: 0.140625, y: 0.234375 }, - { x: 0.171875, y: 0.234375 }, - { x: 0.171875, y: 0.234375 }, - { x: 0.203125, y: 0.234375 }, - { x: 0.203125, y: 0.234375 }, - { x: 0.234375, y: 0.234375 }, - { x: 0.234375, y: 0.234375 }, - { x: 0.265625, y: 0.234375 }, - { x: 0.265625, y: 0.234375 }, - { x: 0.296875, y: 0.234375 }, - { x: 0.296875, y: 0.234375 }, - { x: 0.328125, y: 0.234375 }, - { x: 0.328125, y: 0.234375 }, - { x: 0.359375, y: 0.234375 }, - { x: 0.359375, y: 0.234375 }, - { x: 0.390625, y: 0.234375 }, - { x: 0.390625, y: 0.234375 }, - { x: 0.421875, y: 0.234375 }, - { x: 0.421875, y: 0.234375 }, - { x: 0.453125, y: 0.234375 }, - { x: 0.453125, y: 0.234375 }, - { x: 0.484375, y: 0.234375 }, - { x: 0.484375, y: 0.234375 }, - { x: 0.515625, y: 0.234375 }, - { x: 0.515625, y: 0.234375 }, - { x: 0.546875, y: 0.234375 }, - { x: 0.546875, y: 0.234375 }, - { x: 0.578125, y: 0.234375 }, - { x: 0.578125, y: 0.234375 }, - { x: 0.609375, y: 0.234375 }, - { x: 0.609375, y: 0.234375 }, - { x: 0.640625, y: 0.234375 }, - { x: 0.640625, y: 0.234375 }, - { x: 0.671875, y: 0.234375 }, - { x: 0.671875, y: 0.234375 }, - { x: 0.703125, y: 0.234375 }, - { x: 0.703125, y: 0.234375 }, - { x: 0.734375, y: 0.234375 }, - { x: 0.734375, y: 0.234375 }, - { x: 0.765625, y: 0.234375 }, - { x: 0.765625, y: 0.234375 }, - { x: 0.796875, y: 0.234375 }, - { x: 0.796875, y: 0.234375 }, - { x: 0.828125, y: 0.234375 }, - { x: 0.828125, y: 0.234375 }, - { x: 0.859375, y: 0.234375 }, - { x: 0.859375, y: 0.234375 }, - { x: 0.890625, y: 0.234375 }, - { x: 0.890625, y: 0.234375 }, - { x: 0.921875, y: 0.234375 }, - { x: 0.921875, y: 0.234375 }, - { x: 0.953125, y: 0.234375 }, - { x: 0.953125, y: 0.234375 }, - { x: 0.984375, y: 0.234375 }, - { x: 0.984375, y: 0.234375 }, - { x: 0.015625, y: 0.265625 }, - { x: 0.015625, y: 0.265625 }, - { x: 0.046875, y: 0.265625 }, - { x: 0.046875, y: 0.265625 }, - { x: 0.078125, y: 0.265625 }, - { x: 0.078125, y: 0.265625 }, - { x: 0.109375, y: 0.265625 }, - { x: 0.109375, y: 0.265625 }, - { x: 0.140625, y: 0.265625 }, - { x: 0.140625, y: 0.265625 }, - { x: 0.171875, y: 0.265625 }, - { x: 0.171875, y: 0.265625 }, - { x: 0.203125, y: 0.265625 }, - { x: 0.203125, y: 0.265625 }, - { x: 0.234375, y: 0.265625 }, - { x: 0.234375, y: 0.265625 }, - { x: 0.265625, y: 0.265625 }, - { x: 0.265625, y: 0.265625 }, - { x: 0.296875, y: 0.265625 }, - { x: 0.296875, y: 0.265625 }, - { x: 0.328125, y: 0.265625 }, - { x: 0.328125, y: 0.265625 }, - { x: 0.359375, y: 0.265625 }, - { x: 0.359375, y: 0.265625 }, - { x: 0.390625, y: 0.265625 }, - { x: 0.390625, y: 0.265625 }, - { x: 0.421875, y: 0.265625 }, - { x: 0.421875, y: 0.265625 }, - { x: 0.453125, y: 0.265625 }, - { x: 0.453125, y: 0.265625 }, - { x: 0.484375, y: 0.265625 }, - { x: 0.484375, y: 0.265625 }, - { x: 0.515625, y: 0.265625 }, - { x: 0.515625, y: 0.265625 }, - { x: 0.546875, y: 0.265625 }, - { x: 0.546875, y: 0.265625 }, - { x: 0.578125, y: 0.265625 }, - { x: 0.578125, y: 0.265625 }, - { x: 0.609375, y: 0.265625 }, - { x: 0.609375, y: 0.265625 }, - { x: 0.640625, y: 0.265625 }, - { x: 0.640625, y: 0.265625 }, - { x: 0.671875, y: 0.265625 }, - { x: 0.671875, y: 0.265625 }, - { x: 0.703125, y: 0.265625 }, - { x: 0.703125, y: 0.265625 }, - { x: 0.734375, y: 0.265625 }, - { x: 0.734375, y: 0.265625 }, - { x: 0.765625, y: 0.265625 }, - { x: 0.765625, y: 0.265625 }, - { x: 0.796875, y: 0.265625 }, - { x: 0.796875, y: 0.265625 }, - { x: 0.828125, y: 0.265625 }, - { x: 0.828125, y: 0.265625 }, - { x: 0.859375, y: 0.265625 }, - { x: 0.859375, y: 0.265625 }, - { x: 0.890625, y: 0.265625 }, - { x: 0.890625, y: 0.265625 }, - { x: 0.921875, y: 0.265625 }, - { x: 0.921875, y: 0.265625 }, - { x: 0.953125, y: 0.265625 }, - { x: 0.953125, y: 0.265625 }, - { x: 0.984375, y: 0.265625 }, - { x: 0.984375, y: 0.265625 }, - { x: 0.015625, y: 0.296875 }, - { x: 0.015625, y: 0.296875 }, - { x: 0.046875, y: 0.296875 }, - { x: 0.046875, y: 0.296875 }, - { x: 0.078125, y: 0.296875 }, - { x: 0.078125, y: 0.296875 }, - { x: 0.109375, y: 0.296875 }, - { x: 0.109375, y: 0.296875 }, - { x: 0.140625, y: 0.296875 }, - { x: 0.140625, y: 0.296875 }, - { x: 0.171875, y: 0.296875 }, - { x: 0.171875, y: 0.296875 }, - { x: 0.203125, y: 0.296875 }, - { x: 0.203125, y: 0.296875 }, - { x: 0.234375, y: 0.296875 }, - { x: 0.234375, y: 0.296875 }, - { x: 0.265625, y: 0.296875 }, - { x: 0.265625, y: 0.296875 }, - { x: 0.296875, y: 0.296875 }, - { x: 0.296875, y: 0.296875 }, - { x: 0.328125, y: 0.296875 }, - { x: 0.328125, y: 0.296875 }, - { x: 0.359375, y: 0.296875 }, - { x: 0.359375, y: 0.296875 }, - { x: 0.390625, y: 0.296875 }, - { x: 0.390625, y: 0.296875 }, - { x: 0.421875, y: 0.296875 }, - { x: 0.421875, y: 0.296875 }, - { x: 0.453125, y: 0.296875 }, - { x: 0.453125, y: 0.296875 }, - { x: 0.484375, y: 0.296875 }, - { x: 0.484375, y: 0.296875 }, - { x: 0.515625, y: 0.296875 }, - { x: 0.515625, y: 0.296875 }, - { x: 0.546875, y: 0.296875 }, - { x: 0.546875, y: 0.296875 }, - { x: 0.578125, y: 0.296875 }, - { x: 0.578125, y: 0.296875 }, - { x: 0.609375, y: 0.296875 }, - { x: 0.609375, y: 0.296875 }, - { x: 0.640625, y: 0.296875 }, - { x: 0.640625, y: 0.296875 }, - { x: 0.671875, y: 0.296875 }, - { x: 0.671875, y: 0.296875 }, - { x: 0.703125, y: 0.296875 }, - { x: 0.703125, y: 0.296875 }, - { x: 0.734375, y: 0.296875 }, - { x: 0.734375, y: 0.296875 }, - { x: 0.765625, y: 0.296875 }, - { x: 0.765625, y: 0.296875 }, - { x: 0.796875, y: 0.296875 }, - { x: 0.796875, y: 0.296875 }, - { x: 0.828125, y: 0.296875 }, - { x: 0.828125, y: 0.296875 }, - { x: 0.859375, y: 0.296875 }, - { x: 0.859375, y: 0.296875 }, - { x: 0.890625, y: 0.296875 }, - { x: 0.890625, y: 0.296875 }, - { x: 0.921875, y: 0.296875 }, - { x: 0.921875, y: 0.296875 }, - { x: 0.953125, y: 0.296875 }, - { x: 0.953125, y: 0.296875 }, - { x: 0.984375, y: 0.296875 }, - { x: 0.984375, y: 0.296875 }, - { x: 0.015625, y: 0.328125 }, - { x: 0.015625, y: 0.328125 }, - { x: 0.046875, y: 0.328125 }, - { x: 0.046875, y: 0.328125 }, - { x: 0.078125, y: 0.328125 }, - { x: 0.078125, y: 0.328125 }, - { x: 0.109375, y: 0.328125 }, - { x: 0.109375, y: 0.328125 }, - { x: 0.140625, y: 0.328125 }, - { x: 0.140625, y: 0.328125 }, - { x: 0.171875, y: 0.328125 }, - { x: 0.171875, y: 0.328125 }, - { x: 0.203125, y: 0.328125 }, - { x: 0.203125, y: 0.328125 }, - { x: 0.234375, y: 0.328125 }, - { x: 0.234375, y: 0.328125 }, - { x: 0.265625, y: 0.328125 }, - { x: 0.265625, y: 0.328125 }, - { x: 0.296875, y: 0.328125 }, - { x: 0.296875, y: 0.328125 }, - { x: 0.328125, y: 0.328125 }, - { x: 0.328125, y: 0.328125 }, - { x: 0.359375, y: 0.328125 }, - { x: 0.359375, y: 0.328125 }, - { x: 0.390625, y: 0.328125 }, - { x: 0.390625, y: 0.328125 }, - { x: 0.421875, y: 0.328125 }, - { x: 0.421875, y: 0.328125 }, - { x: 0.453125, y: 0.328125 }, - { x: 0.453125, y: 0.328125 }, - { x: 0.484375, y: 0.328125 }, - { x: 0.484375, y: 0.328125 }, - { x: 0.515625, y: 0.328125 }, - { x: 0.515625, y: 0.328125 }, - { x: 0.546875, y: 0.328125 }, - { x: 0.546875, y: 0.328125 }, - { x: 0.578125, y: 0.328125 }, - { x: 0.578125, y: 0.328125 }, - { x: 0.609375, y: 0.328125 }, - { x: 0.609375, y: 0.328125 }, - { x: 0.640625, y: 0.328125 }, - { x: 0.640625, y: 0.328125 }, - { x: 0.671875, y: 0.328125 }, - { x: 0.671875, y: 0.328125 }, - { x: 0.703125, y: 0.328125 }, - { x: 0.703125, y: 0.328125 }, - { x: 0.734375, y: 0.328125 }, - { x: 0.734375, y: 0.328125 }, - { x: 0.765625, y: 0.328125 }, - { x: 0.765625, y: 0.328125 }, - { x: 0.796875, y: 0.328125 }, - { x: 0.796875, y: 0.328125 }, - { x: 0.828125, y: 0.328125 }, - { x: 0.828125, y: 0.328125 }, - { x: 0.859375, y: 0.328125 }, - { x: 0.859375, y: 0.328125 }, - { x: 0.890625, y: 0.328125 }, - { x: 0.890625, y: 0.328125 }, - { x: 0.921875, y: 0.328125 }, - { x: 0.921875, y: 0.328125 }, - { x: 0.953125, y: 0.328125 }, - { x: 0.953125, y: 0.328125 }, - { x: 0.984375, y: 0.328125 }, - { x: 0.984375, y: 0.328125 }, - { x: 0.015625, y: 0.359375 }, - { x: 0.015625, y: 0.359375 }, - { x: 0.046875, y: 0.359375 }, - { x: 0.046875, y: 0.359375 }, - { x: 0.078125, y: 0.359375 }, - { x: 0.078125, y: 0.359375 }, - { x: 0.109375, y: 0.359375 }, - { x: 0.109375, y: 0.359375 }, - { x: 0.140625, y: 0.359375 }, - { x: 0.140625, y: 0.359375 }, - { x: 0.171875, y: 0.359375 }, - { x: 0.171875, y: 0.359375 }, - { x: 0.203125, y: 0.359375 }, - { x: 0.203125, y: 0.359375 }, - { x: 0.234375, y: 0.359375 }, - { x: 0.234375, y: 0.359375 }, - { x: 0.265625, y: 0.359375 }, - { x: 0.265625, y: 0.359375 }, - { x: 0.296875, y: 0.359375 }, - { x: 0.296875, y: 0.359375 }, - { x: 0.328125, y: 0.359375 }, - { x: 0.328125, y: 0.359375 }, - { x: 0.359375, y: 0.359375 }, - { x: 0.359375, y: 0.359375 }, - { x: 0.390625, y: 0.359375 }, - { x: 0.390625, y: 0.359375 }, - { x: 0.421875, y: 0.359375 }, - { x: 0.421875, y: 0.359375 }, - { x: 0.453125, y: 0.359375 }, - { x: 0.453125, y: 0.359375 }, - { x: 0.484375, y: 0.359375 }, - { x: 0.484375, y: 0.359375 }, - { x: 0.515625, y: 0.359375 }, - { x: 0.515625, y: 0.359375 }, - { x: 0.546875, y: 0.359375 }, - { x: 0.546875, y: 0.359375 }, - { x: 0.578125, y: 0.359375 }, - { x: 0.578125, y: 0.359375 }, - { x: 0.609375, y: 0.359375 }, - { x: 0.609375, y: 0.359375 }, - { x: 0.640625, y: 0.359375 }, - { x: 0.640625, y: 0.359375 }, - { x: 0.671875, y: 0.359375 }, - { x: 0.671875, y: 0.359375 }, - { x: 0.703125, y: 0.359375 }, - { x: 0.703125, y: 0.359375 }, - { x: 0.734375, y: 0.359375 }, - { x: 0.734375, y: 0.359375 }, - { x: 0.765625, y: 0.359375 }, - { x: 0.765625, y: 0.359375 }, - { x: 0.796875, y: 0.359375 }, - { x: 0.796875, y: 0.359375 }, - { x: 0.828125, y: 0.359375 }, - { x: 0.828125, y: 0.359375 }, - { x: 0.859375, y: 0.359375 }, - { x: 0.859375, y: 0.359375 }, - { x: 0.890625, y: 0.359375 }, - { x: 0.890625, y: 0.359375 }, - { x: 0.921875, y: 0.359375 }, - { x: 0.921875, y: 0.359375 }, - { x: 0.953125, y: 0.359375 }, - { x: 0.953125, y: 0.359375 }, - { x: 0.984375, y: 0.359375 }, - { x: 0.984375, y: 0.359375 }, - { x: 0.015625, y: 0.390625 }, - { x: 0.015625, y: 0.390625 }, - { x: 0.046875, y: 0.390625 }, - { x: 0.046875, y: 0.390625 }, - { x: 0.078125, y: 0.390625 }, - { x: 0.078125, y: 0.390625 }, - { x: 0.109375, y: 0.390625 }, - { x: 0.109375, y: 0.390625 }, - { x: 0.140625, y: 0.390625 }, - { x: 0.140625, y: 0.390625 }, - { x: 0.171875, y: 0.390625 }, - { x: 0.171875, y: 0.390625 }, - { x: 0.203125, y: 0.390625 }, - { x: 0.203125, y: 0.390625 }, - { x: 0.234375, y: 0.390625 }, - { x: 0.234375, y: 0.390625 }, - { x: 0.265625, y: 0.390625 }, - { x: 0.265625, y: 0.390625 }, - { x: 0.296875, y: 0.390625 }, - { x: 0.296875, y: 0.390625 }, - { x: 0.328125, y: 0.390625 }, - { x: 0.328125, y: 0.390625 }, - { x: 0.359375, y: 0.390625 }, - { x: 0.359375, y: 0.390625 }, - { x: 0.390625, y: 0.390625 }, - { x: 0.390625, y: 0.390625 }, - { x: 0.421875, y: 0.390625 }, - { x: 0.421875, y: 0.390625 }, - { x: 0.453125, y: 0.390625 }, - { x: 0.453125, y: 0.390625 }, - { x: 0.484375, y: 0.390625 }, - { x: 0.484375, y: 0.390625 }, - { x: 0.515625, y: 0.390625 }, - { x: 0.515625, y: 0.390625 }, - { x: 0.546875, y: 0.390625 }, - { x: 0.546875, y: 0.390625 }, - { x: 0.578125, y: 0.390625 }, - { x: 0.578125, y: 0.390625 }, - { x: 0.609375, y: 0.390625 }, - { x: 0.609375, y: 0.390625 }, - { x: 0.640625, y: 0.390625 }, - { x: 0.640625, y: 0.390625 }, - { x: 0.671875, y: 0.390625 }, - { x: 0.671875, y: 0.390625 }, - { x: 0.703125, y: 0.390625 }, - { x: 0.703125, y: 0.390625 }, - { x: 0.734375, y: 0.390625 }, - { x: 0.734375, y: 0.390625 }, - { x: 0.765625, y: 0.390625 }, - { x: 0.765625, y: 0.390625 }, - { x: 0.796875, y: 0.390625 }, - { x: 0.796875, y: 0.390625 }, - { x: 0.828125, y: 0.390625 }, - { x: 0.828125, y: 0.390625 }, - { x: 0.859375, y: 0.390625 }, - { x: 0.859375, y: 0.390625 }, - { x: 0.890625, y: 0.390625 }, - { x: 0.890625, y: 0.390625 }, - { x: 0.921875, y: 0.390625 }, - { x: 0.921875, y: 0.390625 }, - { x: 0.953125, y: 0.390625 }, - { x: 0.953125, y: 0.390625 }, - { x: 0.984375, y: 0.390625 }, - { x: 0.984375, y: 0.390625 }, - { x: 0.015625, y: 0.421875 }, - { x: 0.015625, y: 0.421875 }, - { x: 0.046875, y: 0.421875 }, - { x: 0.046875, y: 0.421875 }, - { x: 0.078125, y: 0.421875 }, - { x: 0.078125, y: 0.421875 }, - { x: 0.109375, y: 0.421875 }, - { x: 0.109375, y: 0.421875 }, - { x: 0.140625, y: 0.421875 }, - { x: 0.140625, y: 0.421875 }, - { x: 0.171875, y: 0.421875 }, - { x: 0.171875, y: 0.421875 }, - { x: 0.203125, y: 0.421875 }, - { x: 0.203125, y: 0.421875 }, - { x: 0.234375, y: 0.421875 }, - { x: 0.234375, y: 0.421875 }, - { x: 0.265625, y: 0.421875 }, - { x: 0.265625, y: 0.421875 }, - { x: 0.296875, y: 0.421875 }, - { x: 0.296875, y: 0.421875 }, - { x: 0.328125, y: 0.421875 }, - { x: 0.328125, y: 0.421875 }, - { x: 0.359375, y: 0.421875 }, - { x: 0.359375, y: 0.421875 }, - { x: 0.390625, y: 0.421875 }, - { x: 0.390625, y: 0.421875 }, - { x: 0.421875, y: 0.421875 }, - { x: 0.421875, y: 0.421875 }, - { x: 0.453125, y: 0.421875 }, - { x: 0.453125, y: 0.421875 }, - { x: 0.484375, y: 0.421875 }, - { x: 0.484375, y: 0.421875 }, - { x: 0.515625, y: 0.421875 }, - { x: 0.515625, y: 0.421875 }, - { x: 0.546875, y: 0.421875 }, - { x: 0.546875, y: 0.421875 }, - { x: 0.578125, y: 0.421875 }, - { x: 0.578125, y: 0.421875 }, - { x: 0.609375, y: 0.421875 }, - { x: 0.609375, y: 0.421875 }, - { x: 0.640625, y: 0.421875 }, - { x: 0.640625, y: 0.421875 }, - { x: 0.671875, y: 0.421875 }, - { x: 0.671875, y: 0.421875 }, - { x: 0.703125, y: 0.421875 }, - { x: 0.703125, y: 0.421875 }, - { x: 0.734375, y: 0.421875 }, - { x: 0.734375, y: 0.421875 }, - { x: 0.765625, y: 0.421875 }, - { x: 0.765625, y: 0.421875 }, - { x: 0.796875, y: 0.421875 }, - { x: 0.796875, y: 0.421875 }, - { x: 0.828125, y: 0.421875 }, - { x: 0.828125, y: 0.421875 }, - { x: 0.859375, y: 0.421875 }, - { x: 0.859375, y: 0.421875 }, - { x: 0.890625, y: 0.421875 }, - { x: 0.890625, y: 0.421875 }, - { x: 0.921875, y: 0.421875 }, - { x: 0.921875, y: 0.421875 }, - { x: 0.953125, y: 0.421875 }, - { x: 0.953125, y: 0.421875 }, - { x: 0.984375, y: 0.421875 }, - { x: 0.984375, y: 0.421875 }, - { x: 0.015625, y: 0.453125 }, - { x: 0.015625, y: 0.453125 }, - { x: 0.046875, y: 0.453125 }, - { x: 0.046875, y: 0.453125 }, - { x: 0.078125, y: 0.453125 }, - { x: 0.078125, y: 0.453125 }, - { x: 0.109375, y: 0.453125 }, - { x: 0.109375, y: 0.453125 }, - { x: 0.140625, y: 0.453125 }, - { x: 0.140625, y: 0.453125 }, - { x: 0.171875, y: 0.453125 }, - { x: 0.171875, y: 0.453125 }, - { x: 0.203125, y: 0.453125 }, - { x: 0.203125, y: 0.453125 }, - { x: 0.234375, y: 0.453125 }, - { x: 0.234375, y: 0.453125 }, - { x: 0.265625, y: 0.453125 }, - { x: 0.265625, y: 0.453125 }, - { x: 0.296875, y: 0.453125 }, - { x: 0.296875, y: 0.453125 }, - { x: 0.328125, y: 0.453125 }, - { x: 0.328125, y: 0.453125 }, - { x: 0.359375, y: 0.453125 }, - { x: 0.359375, y: 0.453125 }, - { x: 0.390625, y: 0.453125 }, - { x: 0.390625, y: 0.453125 }, - { x: 0.421875, y: 0.453125 }, - { x: 0.421875, y: 0.453125 }, - { x: 0.453125, y: 0.453125 }, - { x: 0.453125, y: 0.453125 }, - { x: 0.484375, y: 0.453125 }, - { x: 0.484375, y: 0.453125 }, - { x: 0.515625, y: 0.453125 }, - { x: 0.515625, y: 0.453125 }, - { x: 0.546875, y: 0.453125 }, - { x: 0.546875, y: 0.453125 }, - { x: 0.578125, y: 0.453125 }, - { x: 0.578125, y: 0.453125 }, - { x: 0.609375, y: 0.453125 }, - { x: 0.609375, y: 0.453125 }, - { x: 0.640625, y: 0.453125 }, - { x: 0.640625, y: 0.453125 }, - { x: 0.671875, y: 0.453125 }, - { x: 0.671875, y: 0.453125 }, - { x: 0.703125, y: 0.453125 }, - { x: 0.703125, y: 0.453125 }, - { x: 0.734375, y: 0.453125 }, - { x: 0.734375, y: 0.453125 }, - { x: 0.765625, y: 0.453125 }, - { x: 0.765625, y: 0.453125 }, - { x: 0.796875, y: 0.453125 }, - { x: 0.796875, y: 0.453125 }, - { x: 0.828125, y: 0.453125 }, - { x: 0.828125, y: 0.453125 }, - { x: 0.859375, y: 0.453125 }, - { x: 0.859375, y: 0.453125 }, - { x: 0.890625, y: 0.453125 }, - { x: 0.890625, y: 0.453125 }, - { x: 0.921875, y: 0.453125 }, - { x: 0.921875, y: 0.453125 }, - { x: 0.953125, y: 0.453125 }, - { x: 0.953125, y: 0.453125 }, - { x: 0.984375, y: 0.453125 }, - { x: 0.984375, y: 0.453125 }, - { x: 0.015625, y: 0.484375 }, - { x: 0.015625, y: 0.484375 }, - { x: 0.046875, y: 0.484375 }, - { x: 0.046875, y: 0.484375 }, - { x: 0.078125, y: 0.484375 }, - { x: 0.078125, y: 0.484375 }, - { x: 0.109375, y: 0.484375 }, - { x: 0.109375, y: 0.484375 }, - { x: 0.140625, y: 0.484375 }, - { x: 0.140625, y: 0.484375 }, - { x: 0.171875, y: 0.484375 }, - { x: 0.171875, y: 0.484375 }, - { x: 0.203125, y: 0.484375 }, - { x: 0.203125, y: 0.484375 }, - { x: 0.234375, y: 0.484375 }, - { x: 0.234375, y: 0.484375 }, - { x: 0.265625, y: 0.484375 }, - { x: 0.265625, y: 0.484375 }, - { x: 0.296875, y: 0.484375 }, - { x: 0.296875, y: 0.484375 }, - { x: 0.328125, y: 0.484375 }, - { x: 0.328125, y: 0.484375 }, - { x: 0.359375, y: 0.484375 }, - { x: 0.359375, y: 0.484375 }, - { x: 0.390625, y: 0.484375 }, - { x: 0.390625, y: 0.484375 }, - { x: 0.421875, y: 0.484375 }, - { x: 0.421875, y: 0.484375 }, - { x: 0.453125, y: 0.484375 }, - { x: 0.453125, y: 0.484375 }, - { x: 0.484375, y: 0.484375 }, - { x: 0.484375, y: 0.484375 }, - { x: 0.515625, y: 0.484375 }, - { x: 0.515625, y: 0.484375 }, - { x: 0.546875, y: 0.484375 }, - { x: 0.546875, y: 0.484375 }, - { x: 0.578125, y: 0.484375 }, - { x: 0.578125, y: 0.484375 }, - { x: 0.609375, y: 0.484375 }, - { x: 0.609375, y: 0.484375 }, - { x: 0.640625, y: 0.484375 }, - { x: 0.640625, y: 0.484375 }, - { x: 0.671875, y: 0.484375 }, - { x: 0.671875, y: 0.484375 }, - { x: 0.703125, y: 0.484375 }, - { x: 0.703125, y: 0.484375 }, - { x: 0.734375, y: 0.484375 }, - { x: 0.734375, y: 0.484375 }, - { x: 0.765625, y: 0.484375 }, - { x: 0.765625, y: 0.484375 }, - { x: 0.796875, y: 0.484375 }, - { x: 0.796875, y: 0.484375 }, - { x: 0.828125, y: 0.484375 }, - { x: 0.828125, y: 0.484375 }, - { x: 0.859375, y: 0.484375 }, - { x: 0.859375, y: 0.484375 }, - { x: 0.890625, y: 0.484375 }, - { x: 0.890625, y: 0.484375 }, - { x: 0.921875, y: 0.484375 }, - { x: 0.921875, y: 0.484375 }, - { x: 0.953125, y: 0.484375 }, - { x: 0.953125, y: 0.484375 }, - { x: 0.984375, y: 0.484375 }, - { x: 0.984375, y: 0.484375 }, - { x: 0.015625, y: 0.515625 }, - { x: 0.015625, y: 0.515625 }, - { x: 0.046875, y: 0.515625 }, - { x: 0.046875, y: 0.515625 }, - { x: 0.078125, y: 0.515625 }, - { x: 0.078125, y: 0.515625 }, - { x: 0.109375, y: 0.515625 }, - { x: 0.109375, y: 0.515625 }, - { x: 0.140625, y: 0.515625 }, - { x: 0.140625, y: 0.515625 }, - { x: 0.171875, y: 0.515625 }, - { x: 0.171875, y: 0.515625 }, - { x: 0.203125, y: 0.515625 }, - { x: 0.203125, y: 0.515625 }, - { x: 0.234375, y: 0.515625 }, - { x: 0.234375, y: 0.515625 }, - { x: 0.265625, y: 0.515625 }, - { x: 0.265625, y: 0.515625 }, - { x: 0.296875, y: 0.515625 }, - { x: 0.296875, y: 0.515625 }, - { x: 0.328125, y: 0.515625 }, - { x: 0.328125, y: 0.515625 }, - { x: 0.359375, y: 0.515625 }, - { x: 0.359375, y: 0.515625 }, - { x: 0.390625, y: 0.515625 }, - { x: 0.390625, y: 0.515625 }, - { x: 0.421875, y: 0.515625 }, - { x: 0.421875, y: 0.515625 }, - { x: 0.453125, y: 0.515625 }, - { x: 0.453125, y: 0.515625 }, - { x: 0.484375, y: 0.515625 }, - { x: 0.484375, y: 0.515625 }, - { x: 0.515625, y: 0.515625 }, - { x: 0.515625, y: 0.515625 }, - { x: 0.546875, y: 0.515625 }, - { x: 0.546875, y: 0.515625 }, - { x: 0.578125, y: 0.515625 }, - { x: 0.578125, y: 0.515625 }, - { x: 0.609375, y: 0.515625 }, - { x: 0.609375, y: 0.515625 }, - { x: 0.640625, y: 0.515625 }, - { x: 0.640625, y: 0.515625 }, - { x: 0.671875, y: 0.515625 }, - { x: 0.671875, y: 0.515625 }, - { x: 0.703125, y: 0.515625 }, - { x: 0.703125, y: 0.515625 }, - { x: 0.734375, y: 0.515625 }, - { x: 0.734375, y: 0.515625 }, - { x: 0.765625, y: 0.515625 }, - { x: 0.765625, y: 0.515625 }, - { x: 0.796875, y: 0.515625 }, - { x: 0.796875, y: 0.515625 }, - { x: 0.828125, y: 0.515625 }, - { x: 0.828125, y: 0.515625 }, - { x: 0.859375, y: 0.515625 }, - { x: 0.859375, y: 0.515625 }, - { x: 0.890625, y: 0.515625 }, - { x: 0.890625, y: 0.515625 }, - { x: 0.921875, y: 0.515625 }, - { x: 0.921875, y: 0.515625 }, - { x: 0.953125, y: 0.515625 }, - { x: 0.953125, y: 0.515625 }, - { x: 0.984375, y: 0.515625 }, - { x: 0.984375, y: 0.515625 }, - { x: 0.015625, y: 0.546875 }, - { x: 0.015625, y: 0.546875 }, - { x: 0.046875, y: 0.546875 }, - { x: 0.046875, y: 0.546875 }, - { x: 0.078125, y: 0.546875 }, - { x: 0.078125, y: 0.546875 }, - { x: 0.109375, y: 0.546875 }, - { x: 0.109375, y: 0.546875 }, - { x: 0.140625, y: 0.546875 }, - { x: 0.140625, y: 0.546875 }, - { x: 0.171875, y: 0.546875 }, - { x: 0.171875, y: 0.546875 }, - { x: 0.203125, y: 0.546875 }, - { x: 0.203125, y: 0.546875 }, - { x: 0.234375, y: 0.546875 }, - { x: 0.234375, y: 0.546875 }, - { x: 0.265625, y: 0.546875 }, - { x: 0.265625, y: 0.546875 }, - { x: 0.296875, y: 0.546875 }, - { x: 0.296875, y: 0.546875 }, - { x: 0.328125, y: 0.546875 }, - { x: 0.328125, y: 0.546875 }, - { x: 0.359375, y: 0.546875 }, - { x: 0.359375, y: 0.546875 }, - { x: 0.390625, y: 0.546875 }, - { x: 0.390625, y: 0.546875 }, - { x: 0.421875, y: 0.546875 }, - { x: 0.421875, y: 0.546875 }, - { x: 0.453125, y: 0.546875 }, - { x: 0.453125, y: 0.546875 }, - { x: 0.484375, y: 0.546875 }, - { x: 0.484375, y: 0.546875 }, - { x: 0.515625, y: 0.546875 }, - { x: 0.515625, y: 0.546875 }, - { x: 0.546875, y: 0.546875 }, - { x: 0.546875, y: 0.546875 }, - { x: 0.578125, y: 0.546875 }, - { x: 0.578125, y: 0.546875 }, - { x: 0.609375, y: 0.546875 }, - { x: 0.609375, y: 0.546875 }, - { x: 0.640625, y: 0.546875 }, - { x: 0.640625, y: 0.546875 }, - { x: 0.671875, y: 0.546875 }, - { x: 0.671875, y: 0.546875 }, - { x: 0.703125, y: 0.546875 }, - { x: 0.703125, y: 0.546875 }, - { x: 0.734375, y: 0.546875 }, - { x: 0.734375, y: 0.546875 }, - { x: 0.765625, y: 0.546875 }, - { x: 0.765625, y: 0.546875 }, - { x: 0.796875, y: 0.546875 }, - { x: 0.796875, y: 0.546875 }, - { x: 0.828125, y: 0.546875 }, - { x: 0.828125, y: 0.546875 }, - { x: 0.859375, y: 0.546875 }, - { x: 0.859375, y: 0.546875 }, - { x: 0.890625, y: 0.546875 }, - { x: 0.890625, y: 0.546875 }, - { x: 0.921875, y: 0.546875 }, - { x: 0.921875, y: 0.546875 }, - { x: 0.953125, y: 0.546875 }, - { x: 0.953125, y: 0.546875 }, - { x: 0.984375, y: 0.546875 }, - { x: 0.984375, y: 0.546875 }, - { x: 0.015625, y: 0.578125 }, - { x: 0.015625, y: 0.578125 }, - { x: 0.046875, y: 0.578125 }, - { x: 0.046875, y: 0.578125 }, - { x: 0.078125, y: 0.578125 }, - { x: 0.078125, y: 0.578125 }, - { x: 0.109375, y: 0.578125 }, - { x: 0.109375, y: 0.578125 }, - { x: 0.140625, y: 0.578125 }, - { x: 0.140625, y: 0.578125 }, - { x: 0.171875, y: 0.578125 }, - { x: 0.171875, y: 0.578125 }, - { x: 0.203125, y: 0.578125 }, - { x: 0.203125, y: 0.578125 }, - { x: 0.234375, y: 0.578125 }, - { x: 0.234375, y: 0.578125 }, - { x: 0.265625, y: 0.578125 }, - { x: 0.265625, y: 0.578125 }, - { x: 0.296875, y: 0.578125 }, - { x: 0.296875, y: 0.578125 }, - { x: 0.328125, y: 0.578125 }, - { x: 0.328125, y: 0.578125 }, - { x: 0.359375, y: 0.578125 }, - { x: 0.359375, y: 0.578125 }, - { x: 0.390625, y: 0.578125 }, - { x: 0.390625, y: 0.578125 }, - { x: 0.421875, y: 0.578125 }, - { x: 0.421875, y: 0.578125 }, - { x: 0.453125, y: 0.578125 }, - { x: 0.453125, y: 0.578125 }, - { x: 0.484375, y: 0.578125 }, - { x: 0.484375, y: 0.578125 }, - { x: 0.515625, y: 0.578125 }, - { x: 0.515625, y: 0.578125 }, - { x: 0.546875, y: 0.578125 }, - { x: 0.546875, y: 0.578125 }, - { x: 0.578125, y: 0.578125 }, - { x: 0.578125, y: 0.578125 }, - { x: 0.609375, y: 0.578125 }, - { x: 0.609375, y: 0.578125 }, - { x: 0.640625, y: 0.578125 }, - { x: 0.640625, y: 0.578125 }, - { x: 0.671875, y: 0.578125 }, - { x: 0.671875, y: 0.578125 }, - { x: 0.703125, y: 0.578125 }, - { x: 0.703125, y: 0.578125 }, - { x: 0.734375, y: 0.578125 }, - { x: 0.734375, y: 0.578125 }, - { x: 0.765625, y: 0.578125 }, - { x: 0.765625, y: 0.578125 }, - { x: 0.796875, y: 0.578125 }, - { x: 0.796875, y: 0.578125 }, - { x: 0.828125, y: 0.578125 }, - { x: 0.828125, y: 0.578125 }, - { x: 0.859375, y: 0.578125 }, - { x: 0.859375, y: 0.578125 }, - { x: 0.890625, y: 0.578125 }, - { x: 0.890625, y: 0.578125 }, - { x: 0.921875, y: 0.578125 }, - { x: 0.921875, y: 0.578125 }, - { x: 0.953125, y: 0.578125 }, - { x: 0.953125, y: 0.578125 }, - { x: 0.984375, y: 0.578125 }, - { x: 0.984375, y: 0.578125 }, - { x: 0.015625, y: 0.609375 }, - { x: 0.015625, y: 0.609375 }, - { x: 0.046875, y: 0.609375 }, - { x: 0.046875, y: 0.609375 }, - { x: 0.078125, y: 0.609375 }, - { x: 0.078125, y: 0.609375 }, - { x: 0.109375, y: 0.609375 }, - { x: 0.109375, y: 0.609375 }, - { x: 0.140625, y: 0.609375 }, - { x: 0.140625, y: 0.609375 }, - { x: 0.171875, y: 0.609375 }, - { x: 0.171875, y: 0.609375 }, - { x: 0.203125, y: 0.609375 }, - { x: 0.203125, y: 0.609375 }, - { x: 0.234375, y: 0.609375 }, - { x: 0.234375, y: 0.609375 }, - { x: 0.265625, y: 0.609375 }, - { x: 0.265625, y: 0.609375 }, - { x: 0.296875, y: 0.609375 }, - { x: 0.296875, y: 0.609375 }, - { x: 0.328125, y: 0.609375 }, - { x: 0.328125, y: 0.609375 }, - { x: 0.359375, y: 0.609375 }, - { x: 0.359375, y: 0.609375 }, - { x: 0.390625, y: 0.609375 }, - { x: 0.390625, y: 0.609375 }, - { x: 0.421875, y: 0.609375 }, - { x: 0.421875, y: 0.609375 }, - { x: 0.453125, y: 0.609375 }, - { x: 0.453125, y: 0.609375 }, - { x: 0.484375, y: 0.609375 }, - { x: 0.484375, y: 0.609375 }, - { x: 0.515625, y: 0.609375 }, - { x: 0.515625, y: 0.609375 }, - { x: 0.546875, y: 0.609375 }, - { x: 0.546875, y: 0.609375 }, - { x: 0.578125, y: 0.609375 }, - { x: 0.578125, y: 0.609375 }, - { x: 0.609375, y: 0.609375 }, - { x: 0.609375, y: 0.609375 }, - { x: 0.640625, y: 0.609375 }, - { x: 0.640625, y: 0.609375 }, - { x: 0.671875, y: 0.609375 }, - { x: 0.671875, y: 0.609375 }, - { x: 0.703125, y: 0.609375 }, - { x: 0.703125, y: 0.609375 }, - { x: 0.734375, y: 0.609375 }, - { x: 0.734375, y: 0.609375 }, - { x: 0.765625, y: 0.609375 }, - { x: 0.765625, y: 0.609375 }, - { x: 0.796875, y: 0.609375 }, - { x: 0.796875, y: 0.609375 }, - { x: 0.828125, y: 0.609375 }, - { x: 0.828125, y: 0.609375 }, - { x: 0.859375, y: 0.609375 }, - { x: 0.859375, y: 0.609375 }, - { x: 0.890625, y: 0.609375 }, - { x: 0.890625, y: 0.609375 }, - { x: 0.921875, y: 0.609375 }, - { x: 0.921875, y: 0.609375 }, - { x: 0.953125, y: 0.609375 }, - { x: 0.953125, y: 0.609375 }, - { x: 0.984375, y: 0.609375 }, - { x: 0.984375, y: 0.609375 }, - { x: 0.015625, y: 0.640625 }, - { x: 0.015625, y: 0.640625 }, - { x: 0.046875, y: 0.640625 }, - { x: 0.046875, y: 0.640625 }, - { x: 0.078125, y: 0.640625 }, - { x: 0.078125, y: 0.640625 }, - { x: 0.109375, y: 0.640625 }, - { x: 0.109375, y: 0.640625 }, - { x: 0.140625, y: 0.640625 }, - { x: 0.140625, y: 0.640625 }, - { x: 0.171875, y: 0.640625 }, - { x: 0.171875, y: 0.640625 }, - { x: 0.203125, y: 0.640625 }, - { x: 0.203125, y: 0.640625 }, - { x: 0.234375, y: 0.640625 }, - { x: 0.234375, y: 0.640625 }, - { x: 0.265625, y: 0.640625 }, - { x: 0.265625, y: 0.640625 }, - { x: 0.296875, y: 0.640625 }, - { x: 0.296875, y: 0.640625 }, - { x: 0.328125, y: 0.640625 }, - { x: 0.328125, y: 0.640625 }, - { x: 0.359375, y: 0.640625 }, - { x: 0.359375, y: 0.640625 }, - { x: 0.390625, y: 0.640625 }, - { x: 0.390625, y: 0.640625 }, - { x: 0.421875, y: 0.640625 }, - { x: 0.421875, y: 0.640625 }, - { x: 0.453125, y: 0.640625 }, - { x: 0.453125, y: 0.640625 }, - { x: 0.484375, y: 0.640625 }, - { x: 0.484375, y: 0.640625 }, - { x: 0.515625, y: 0.640625 }, - { x: 0.515625, y: 0.640625 }, - { x: 0.546875, y: 0.640625 }, - { x: 0.546875, y: 0.640625 }, - { x: 0.578125, y: 0.640625 }, - { x: 0.578125, y: 0.640625 }, - { x: 0.609375, y: 0.640625 }, - { x: 0.609375, y: 0.640625 }, - { x: 0.640625, y: 0.640625 }, - { x: 0.640625, y: 0.640625 }, - { x: 0.671875, y: 0.640625 }, - { x: 0.671875, y: 0.640625 }, - { x: 0.703125, y: 0.640625 }, - { x: 0.703125, y: 0.640625 }, - { x: 0.734375, y: 0.640625 }, - { x: 0.734375, y: 0.640625 }, - { x: 0.765625, y: 0.640625 }, - { x: 0.765625, y: 0.640625 }, - { x: 0.796875, y: 0.640625 }, - { x: 0.796875, y: 0.640625 }, - { x: 0.828125, y: 0.640625 }, - { x: 0.828125, y: 0.640625 }, - { x: 0.859375, y: 0.640625 }, - { x: 0.859375, y: 0.640625 }, - { x: 0.890625, y: 0.640625 }, - { x: 0.890625, y: 0.640625 }, - { x: 0.921875, y: 0.640625 }, - { x: 0.921875, y: 0.640625 }, - { x: 0.953125, y: 0.640625 }, - { x: 0.953125, y: 0.640625 }, - { x: 0.984375, y: 0.640625 }, - { x: 0.984375, y: 0.640625 }, - { x: 0.015625, y: 0.671875 }, - { x: 0.015625, y: 0.671875 }, - { x: 0.046875, y: 0.671875 }, - { x: 0.046875, y: 0.671875 }, - { x: 0.078125, y: 0.671875 }, - { x: 0.078125, y: 0.671875 }, - { x: 0.109375, y: 0.671875 }, - { x: 0.109375, y: 0.671875 }, - { x: 0.140625, y: 0.671875 }, - { x: 0.140625, y: 0.671875 }, - { x: 0.171875, y: 0.671875 }, - { x: 0.171875, y: 0.671875 }, - { x: 0.203125, y: 0.671875 }, - { x: 0.203125, y: 0.671875 }, - { x: 0.234375, y: 0.671875 }, - { x: 0.234375, y: 0.671875 }, - { x: 0.265625, y: 0.671875 }, - { x: 0.265625, y: 0.671875 }, - { x: 0.296875, y: 0.671875 }, - { x: 0.296875, y: 0.671875 }, - { x: 0.328125, y: 0.671875 }, - { x: 0.328125, y: 0.671875 }, - { x: 0.359375, y: 0.671875 }, - { x: 0.359375, y: 0.671875 }, - { x: 0.390625, y: 0.671875 }, - { x: 0.390625, y: 0.671875 }, - { x: 0.421875, y: 0.671875 }, - { x: 0.421875, y: 0.671875 }, - { x: 0.453125, y: 0.671875 }, - { x: 0.453125, y: 0.671875 }, - { x: 0.484375, y: 0.671875 }, - { x: 0.484375, y: 0.671875 }, - { x: 0.515625, y: 0.671875 }, - { x: 0.515625, y: 0.671875 }, - { x: 0.546875, y: 0.671875 }, - { x: 0.546875, y: 0.671875 }, - { x: 0.578125, y: 0.671875 }, - { x: 0.578125, y: 0.671875 }, - { x: 0.609375, y: 0.671875 }, - { x: 0.609375, y: 0.671875 }, - { x: 0.640625, y: 0.671875 }, - { x: 0.640625, y: 0.671875 }, - { x: 0.671875, y: 0.671875 }, - { x: 0.671875, y: 0.671875 }, - { x: 0.703125, y: 0.671875 }, - { x: 0.703125, y: 0.671875 }, - { x: 0.734375, y: 0.671875 }, - { x: 0.734375, y: 0.671875 }, - { x: 0.765625, y: 0.671875 }, - { x: 0.765625, y: 0.671875 }, - { x: 0.796875, y: 0.671875 }, - { x: 0.796875, y: 0.671875 }, - { x: 0.828125, y: 0.671875 }, - { x: 0.828125, y: 0.671875 }, - { x: 0.859375, y: 0.671875 }, - { x: 0.859375, y: 0.671875 }, - { x: 0.890625, y: 0.671875 }, - { x: 0.890625, y: 0.671875 }, - { x: 0.921875, y: 0.671875 }, - { x: 0.921875, y: 0.671875 }, - { x: 0.953125, y: 0.671875 }, - { x: 0.953125, y: 0.671875 }, - { x: 0.984375, y: 0.671875 }, - { x: 0.984375, y: 0.671875 }, - { x: 0.015625, y: 0.703125 }, - { x: 0.015625, y: 0.703125 }, - { x: 0.046875, y: 0.703125 }, - { x: 0.046875, y: 0.703125 }, - { x: 0.078125, y: 0.703125 }, - { x: 0.078125, y: 0.703125 }, - { x: 0.109375, y: 0.703125 }, - { x: 0.109375, y: 0.703125 }, - { x: 0.140625, y: 0.703125 }, - { x: 0.140625, y: 0.703125 }, - { x: 0.171875, y: 0.703125 }, - { x: 0.171875, y: 0.703125 }, - { x: 0.203125, y: 0.703125 }, - { x: 0.203125, y: 0.703125 }, - { x: 0.234375, y: 0.703125 }, - { x: 0.234375, y: 0.703125 }, - { x: 0.265625, y: 0.703125 }, - { x: 0.265625, y: 0.703125 }, - { x: 0.296875, y: 0.703125 }, - { x: 0.296875, y: 0.703125 }, - { x: 0.328125, y: 0.703125 }, - { x: 0.328125, y: 0.703125 }, - { x: 0.359375, y: 0.703125 }, - { x: 0.359375, y: 0.703125 }, - { x: 0.390625, y: 0.703125 }, - { x: 0.390625, y: 0.703125 }, - { x: 0.421875, y: 0.703125 }, - { x: 0.421875, y: 0.703125 }, - { x: 0.453125, y: 0.703125 }, - { x: 0.453125, y: 0.703125 }, - { x: 0.484375, y: 0.703125 }, - { x: 0.484375, y: 0.703125 }, - { x: 0.515625, y: 0.703125 }, - { x: 0.515625, y: 0.703125 }, - { x: 0.546875, y: 0.703125 }, - { x: 0.546875, y: 0.703125 }, - { x: 0.578125, y: 0.703125 }, - { x: 0.578125, y: 0.703125 }, - { x: 0.609375, y: 0.703125 }, - { x: 0.609375, y: 0.703125 }, - { x: 0.640625, y: 0.703125 }, - { x: 0.640625, y: 0.703125 }, - { x: 0.671875, y: 0.703125 }, - { x: 0.671875, y: 0.703125 }, - { x: 0.703125, y: 0.703125 }, - { x: 0.703125, y: 0.703125 }, - { x: 0.734375, y: 0.703125 }, - { x: 0.734375, y: 0.703125 }, - { x: 0.765625, y: 0.703125 }, - { x: 0.765625, y: 0.703125 }, - { x: 0.796875, y: 0.703125 }, - { x: 0.796875, y: 0.703125 }, - { x: 0.828125, y: 0.703125 }, - { x: 0.828125, y: 0.703125 }, - { x: 0.859375, y: 0.703125 }, - { x: 0.859375, y: 0.703125 }, - { x: 0.890625, y: 0.703125 }, - { x: 0.890625, y: 0.703125 }, - { x: 0.921875, y: 0.703125 }, - { x: 0.921875, y: 0.703125 }, - { x: 0.953125, y: 0.703125 }, - { x: 0.953125, y: 0.703125 }, - { x: 0.984375, y: 0.703125 }, - { x: 0.984375, y: 0.703125 }, - { x: 0.015625, y: 0.734375 }, - { x: 0.015625, y: 0.734375 }, - { x: 0.046875, y: 0.734375 }, - { x: 0.046875, y: 0.734375 }, - { x: 0.078125, y: 0.734375 }, - { x: 0.078125, y: 0.734375 }, - { x: 0.109375, y: 0.734375 }, - { x: 0.109375, y: 0.734375 }, - { x: 0.140625, y: 0.734375 }, - { x: 0.140625, y: 0.734375 }, - { x: 0.171875, y: 0.734375 }, - { x: 0.171875, y: 0.734375 }, - { x: 0.203125, y: 0.734375 }, - { x: 0.203125, y: 0.734375 }, - { x: 0.234375, y: 0.734375 }, - { x: 0.234375, y: 0.734375 }, - { x: 0.265625, y: 0.734375 }, - { x: 0.265625, y: 0.734375 }, - { x: 0.296875, y: 0.734375 }, - { x: 0.296875, y: 0.734375 }, - { x: 0.328125, y: 0.734375 }, - { x: 0.328125, y: 0.734375 }, - { x: 0.359375, y: 0.734375 }, - { x: 0.359375, y: 0.734375 }, - { x: 0.390625, y: 0.734375 }, - { x: 0.390625, y: 0.734375 }, - { x: 0.421875, y: 0.734375 }, - { x: 0.421875, y: 0.734375 }, - { x: 0.453125, y: 0.734375 }, - { x: 0.453125, y: 0.734375 }, - { x: 0.484375, y: 0.734375 }, - { x: 0.484375, y: 0.734375 }, - { x: 0.515625, y: 0.734375 }, - { x: 0.515625, y: 0.734375 }, - { x: 0.546875, y: 0.734375 }, - { x: 0.546875, y: 0.734375 }, - { x: 0.578125, y: 0.734375 }, - { x: 0.578125, y: 0.734375 }, - { x: 0.609375, y: 0.734375 }, - { x: 0.609375, y: 0.734375 }, - { x: 0.640625, y: 0.734375 }, - { x: 0.640625, y: 0.734375 }, - { x: 0.671875, y: 0.734375 }, - { x: 0.671875, y: 0.734375 }, - { x: 0.703125, y: 0.734375 }, - { x: 0.703125, y: 0.734375 }, - { x: 0.734375, y: 0.734375 }, - { x: 0.734375, y: 0.734375 }, - { x: 0.765625, y: 0.734375 }, - { x: 0.765625, y: 0.734375 }, - { x: 0.796875, y: 0.734375 }, - { x: 0.796875, y: 0.734375 }, - { x: 0.828125, y: 0.734375 }, - { x: 0.828125, y: 0.734375 }, - { x: 0.859375, y: 0.734375 }, - { x: 0.859375, y: 0.734375 }, - { x: 0.890625, y: 0.734375 }, - { x: 0.890625, y: 0.734375 }, - { x: 0.921875, y: 0.734375 }, - { x: 0.921875, y: 0.734375 }, - { x: 0.953125, y: 0.734375 }, - { x: 0.953125, y: 0.734375 }, - { x: 0.984375, y: 0.734375 }, - { x: 0.984375, y: 0.734375 }, - { x: 0.015625, y: 0.765625 }, - { x: 0.015625, y: 0.765625 }, - { x: 0.046875, y: 0.765625 }, - { x: 0.046875, y: 0.765625 }, - { x: 0.078125, y: 0.765625 }, - { x: 0.078125, y: 0.765625 }, - { x: 0.109375, y: 0.765625 }, - { x: 0.109375, y: 0.765625 }, - { x: 0.140625, y: 0.765625 }, - { x: 0.140625, y: 0.765625 }, - { x: 0.171875, y: 0.765625 }, - { x: 0.171875, y: 0.765625 }, - { x: 0.203125, y: 0.765625 }, - { x: 0.203125, y: 0.765625 }, - { x: 0.234375, y: 0.765625 }, - { x: 0.234375, y: 0.765625 }, - { x: 0.265625, y: 0.765625 }, - { x: 0.265625, y: 0.765625 }, - { x: 0.296875, y: 0.765625 }, - { x: 0.296875, y: 0.765625 }, - { x: 0.328125, y: 0.765625 }, - { x: 0.328125, y: 0.765625 }, - { x: 0.359375, y: 0.765625 }, - { x: 0.359375, y: 0.765625 }, - { x: 0.390625, y: 0.765625 }, - { x: 0.390625, y: 0.765625 }, - { x: 0.421875, y: 0.765625 }, - { x: 0.421875, y: 0.765625 }, - { x: 0.453125, y: 0.765625 }, - { x: 0.453125, y: 0.765625 }, - { x: 0.484375, y: 0.765625 }, - { x: 0.484375, y: 0.765625 }, - { x: 0.515625, y: 0.765625 }, - { x: 0.515625, y: 0.765625 }, - { x: 0.546875, y: 0.765625 }, - { x: 0.546875, y: 0.765625 }, - { x: 0.578125, y: 0.765625 }, - { x: 0.578125, y: 0.765625 }, - { x: 0.609375, y: 0.765625 }, - { x: 0.609375, y: 0.765625 }, - { x: 0.640625, y: 0.765625 }, - { x: 0.640625, y: 0.765625 }, - { x: 0.671875, y: 0.765625 }, - { x: 0.671875, y: 0.765625 }, - { x: 0.703125, y: 0.765625 }, - { x: 0.703125, y: 0.765625 }, - { x: 0.734375, y: 0.765625 }, - { x: 0.734375, y: 0.765625 }, - { x: 0.765625, y: 0.765625 }, - { x: 0.765625, y: 0.765625 }, - { x: 0.796875, y: 0.765625 }, - { x: 0.796875, y: 0.765625 }, - { x: 0.828125, y: 0.765625 }, - { x: 0.828125, y: 0.765625 }, - { x: 0.859375, y: 0.765625 }, - { x: 0.859375, y: 0.765625 }, - { x: 0.890625, y: 0.765625 }, - { x: 0.890625, y: 0.765625 }, - { x: 0.921875, y: 0.765625 }, - { x: 0.921875, y: 0.765625 }, - { x: 0.953125, y: 0.765625 }, - { x: 0.953125, y: 0.765625 }, - { x: 0.984375, y: 0.765625 }, - { x: 0.984375, y: 0.765625 }, - { x: 0.015625, y: 0.796875 }, - { x: 0.015625, y: 0.796875 }, - { x: 0.046875, y: 0.796875 }, - { x: 0.046875, y: 0.796875 }, - { x: 0.078125, y: 0.796875 }, - { x: 0.078125, y: 0.796875 }, - { x: 0.109375, y: 0.796875 }, - { x: 0.109375, y: 0.796875 }, - { x: 0.140625, y: 0.796875 }, - { x: 0.140625, y: 0.796875 }, - { x: 0.171875, y: 0.796875 }, - { x: 0.171875, y: 0.796875 }, - { x: 0.203125, y: 0.796875 }, - { x: 0.203125, y: 0.796875 }, - { x: 0.234375, y: 0.796875 }, - { x: 0.234375, y: 0.796875 }, - { x: 0.265625, y: 0.796875 }, - { x: 0.265625, y: 0.796875 }, - { x: 0.296875, y: 0.796875 }, - { x: 0.296875, y: 0.796875 }, - { x: 0.328125, y: 0.796875 }, - { x: 0.328125, y: 0.796875 }, - { x: 0.359375, y: 0.796875 }, - { x: 0.359375, y: 0.796875 }, - { x: 0.390625, y: 0.796875 }, - { x: 0.390625, y: 0.796875 }, - { x: 0.421875, y: 0.796875 }, - { x: 0.421875, y: 0.796875 }, - { x: 0.453125, y: 0.796875 }, - { x: 0.453125, y: 0.796875 }, - { x: 0.484375, y: 0.796875 }, - { x: 0.484375, y: 0.796875 }, - { x: 0.515625, y: 0.796875 }, - { x: 0.515625, y: 0.796875 }, - { x: 0.546875, y: 0.796875 }, - { x: 0.546875, y: 0.796875 }, - { x: 0.578125, y: 0.796875 }, - { x: 0.578125, y: 0.796875 }, - { x: 0.609375, y: 0.796875 }, - { x: 0.609375, y: 0.796875 }, - { x: 0.640625, y: 0.796875 }, - { x: 0.640625, y: 0.796875 }, - { x: 0.671875, y: 0.796875 }, - { x: 0.671875, y: 0.796875 }, - { x: 0.703125, y: 0.796875 }, - { x: 0.703125, y: 0.796875 }, - { x: 0.734375, y: 0.796875 }, - { x: 0.734375, y: 0.796875 }, - { x: 0.765625, y: 0.796875 }, - { x: 0.765625, y: 0.796875 }, - { x: 0.796875, y: 0.796875 }, - { x: 0.796875, y: 0.796875 }, - { x: 0.828125, y: 0.796875 }, - { x: 0.828125, y: 0.796875 }, - { x: 0.859375, y: 0.796875 }, - { x: 0.859375, y: 0.796875 }, - { x: 0.890625, y: 0.796875 }, - { x: 0.890625, y: 0.796875 }, - { x: 0.921875, y: 0.796875 }, - { x: 0.921875, y: 0.796875 }, - { x: 0.953125, y: 0.796875 }, - { x: 0.953125, y: 0.796875 }, - { x: 0.984375, y: 0.796875 }, - { x: 0.984375, y: 0.796875 }, - { x: 0.015625, y: 0.828125 }, - { x: 0.015625, y: 0.828125 }, - { x: 0.046875, y: 0.828125 }, - { x: 0.046875, y: 0.828125 }, - { x: 0.078125, y: 0.828125 }, - { x: 0.078125, y: 0.828125 }, - { x: 0.109375, y: 0.828125 }, - { x: 0.109375, y: 0.828125 }, - { x: 0.140625, y: 0.828125 }, - { x: 0.140625, y: 0.828125 }, - { x: 0.171875, y: 0.828125 }, - { x: 0.171875, y: 0.828125 }, - { x: 0.203125, y: 0.828125 }, - { x: 0.203125, y: 0.828125 }, - { x: 0.234375, y: 0.828125 }, - { x: 0.234375, y: 0.828125 }, - { x: 0.265625, y: 0.828125 }, - { x: 0.265625, y: 0.828125 }, - { x: 0.296875, y: 0.828125 }, - { x: 0.296875, y: 0.828125 }, - { x: 0.328125, y: 0.828125 }, - { x: 0.328125, y: 0.828125 }, - { x: 0.359375, y: 0.828125 }, - { x: 0.359375, y: 0.828125 }, - { x: 0.390625, y: 0.828125 }, - { x: 0.390625, y: 0.828125 }, - { x: 0.421875, y: 0.828125 }, - { x: 0.421875, y: 0.828125 }, - { x: 0.453125, y: 0.828125 }, - { x: 0.453125, y: 0.828125 }, - { x: 0.484375, y: 0.828125 }, - { x: 0.484375, y: 0.828125 }, - { x: 0.515625, y: 0.828125 }, - { x: 0.515625, y: 0.828125 }, - { x: 0.546875, y: 0.828125 }, - { x: 0.546875, y: 0.828125 }, - { x: 0.578125, y: 0.828125 }, - { x: 0.578125, y: 0.828125 }, - { x: 0.609375, y: 0.828125 }, - { x: 0.609375, y: 0.828125 }, - { x: 0.640625, y: 0.828125 }, - { x: 0.640625, y: 0.828125 }, - { x: 0.671875, y: 0.828125 }, - { x: 0.671875, y: 0.828125 }, - { x: 0.703125, y: 0.828125 }, - { x: 0.703125, y: 0.828125 }, - { x: 0.734375, y: 0.828125 }, - { x: 0.734375, y: 0.828125 }, - { x: 0.765625, y: 0.828125 }, - { x: 0.765625, y: 0.828125 }, - { x: 0.796875, y: 0.828125 }, - { x: 0.796875, y: 0.828125 }, - { x: 0.828125, y: 0.828125 }, - { x: 0.828125, y: 0.828125 }, - { x: 0.859375, y: 0.828125 }, - { x: 0.859375, y: 0.828125 }, - { x: 0.890625, y: 0.828125 }, - { x: 0.890625, y: 0.828125 }, - { x: 0.921875, y: 0.828125 }, - { x: 0.921875, y: 0.828125 }, - { x: 0.953125, y: 0.828125 }, - { x: 0.953125, y: 0.828125 }, - { x: 0.984375, y: 0.828125 }, - { x: 0.984375, y: 0.828125 }, - { x: 0.015625, y: 0.859375 }, - { x: 0.015625, y: 0.859375 }, - { x: 0.046875, y: 0.859375 }, - { x: 0.046875, y: 0.859375 }, - { x: 0.078125, y: 0.859375 }, - { x: 0.078125, y: 0.859375 }, - { x: 0.109375, y: 0.859375 }, - { x: 0.109375, y: 0.859375 }, - { x: 0.140625, y: 0.859375 }, - { x: 0.140625, y: 0.859375 }, - { x: 0.171875, y: 0.859375 }, - { x: 0.171875, y: 0.859375 }, - { x: 0.203125, y: 0.859375 }, - { x: 0.203125, y: 0.859375 }, - { x: 0.234375, y: 0.859375 }, - { x: 0.234375, y: 0.859375 }, - { x: 0.265625, y: 0.859375 }, - { x: 0.265625, y: 0.859375 }, - { x: 0.296875, y: 0.859375 }, - { x: 0.296875, y: 0.859375 }, - { x: 0.328125, y: 0.859375 }, - { x: 0.328125, y: 0.859375 }, - { x: 0.359375, y: 0.859375 }, - { x: 0.359375, y: 0.859375 }, - { x: 0.390625, y: 0.859375 }, - { x: 0.390625, y: 0.859375 }, - { x: 0.421875, y: 0.859375 }, - { x: 0.421875, y: 0.859375 }, - { x: 0.453125, y: 0.859375 }, - { x: 0.453125, y: 0.859375 }, - { x: 0.484375, y: 0.859375 }, - { x: 0.484375, y: 0.859375 }, - { x: 0.515625, y: 0.859375 }, - { x: 0.515625, y: 0.859375 }, - { x: 0.546875, y: 0.859375 }, - { x: 0.546875, y: 0.859375 }, - { x: 0.578125, y: 0.859375 }, - { x: 0.578125, y: 0.859375 }, - { x: 0.609375, y: 0.859375 }, - { x: 0.609375, y: 0.859375 }, - { x: 0.640625, y: 0.859375 }, - { x: 0.640625, y: 0.859375 }, - { x: 0.671875, y: 0.859375 }, - { x: 0.671875, y: 0.859375 }, - { x: 0.703125, y: 0.859375 }, - { x: 0.703125, y: 0.859375 }, - { x: 0.734375, y: 0.859375 }, - { x: 0.734375, y: 0.859375 }, - { x: 0.765625, y: 0.859375 }, - { x: 0.765625, y: 0.859375 }, - { x: 0.796875, y: 0.859375 }, - { x: 0.796875, y: 0.859375 }, - { x: 0.828125, y: 0.859375 }, - { x: 0.828125, y: 0.859375 }, - { x: 0.859375, y: 0.859375 }, - { x: 0.859375, y: 0.859375 }, - { x: 0.890625, y: 0.859375 }, - { x: 0.890625, y: 0.859375 }, - { x: 0.921875, y: 0.859375 }, - { x: 0.921875, y: 0.859375 }, - { x: 0.953125, y: 0.859375 }, - { x: 0.953125, y: 0.859375 }, - { x: 0.984375, y: 0.859375 }, - { x: 0.984375, y: 0.859375 }, - { x: 0.015625, y: 0.890625 }, - { x: 0.015625, y: 0.890625 }, - { x: 0.046875, y: 0.890625 }, - { x: 0.046875, y: 0.890625 }, - { x: 0.078125, y: 0.890625 }, - { x: 0.078125, y: 0.890625 }, - { x: 0.109375, y: 0.890625 }, - { x: 0.109375, y: 0.890625 }, - { x: 0.140625, y: 0.890625 }, - { x: 0.140625, y: 0.890625 }, - { x: 0.171875, y: 0.890625 }, - { x: 0.171875, y: 0.890625 }, - { x: 0.203125, y: 0.890625 }, - { x: 0.203125, y: 0.890625 }, - { x: 0.234375, y: 0.890625 }, - { x: 0.234375, y: 0.890625 }, - { x: 0.265625, y: 0.890625 }, - { x: 0.265625, y: 0.890625 }, - { x: 0.296875, y: 0.890625 }, - { x: 0.296875, y: 0.890625 }, - { x: 0.328125, y: 0.890625 }, - { x: 0.328125, y: 0.890625 }, - { x: 0.359375, y: 0.890625 }, - { x: 0.359375, y: 0.890625 }, - { x: 0.390625, y: 0.890625 }, - { x: 0.390625, y: 0.890625 }, - { x: 0.421875, y: 0.890625 }, - { x: 0.421875, y: 0.890625 }, - { x: 0.453125, y: 0.890625 }, - { x: 0.453125, y: 0.890625 }, - { x: 0.484375, y: 0.890625 }, - { x: 0.484375, y: 0.890625 }, - { x: 0.515625, y: 0.890625 }, - { x: 0.515625, y: 0.890625 }, - { x: 0.546875, y: 0.890625 }, - { x: 0.546875, y: 0.890625 }, - { x: 0.578125, y: 0.890625 }, - { x: 0.578125, y: 0.890625 }, - { x: 0.609375, y: 0.890625 }, - { x: 0.609375, y: 0.890625 }, - { x: 0.640625, y: 0.890625 }, - { x: 0.640625, y: 0.890625 }, - { x: 0.671875, y: 0.890625 }, - { x: 0.671875, y: 0.890625 }, - { x: 0.703125, y: 0.890625 }, - { x: 0.703125, y: 0.890625 }, - { x: 0.734375, y: 0.890625 }, - { x: 0.734375, y: 0.890625 }, - { x: 0.765625, y: 0.890625 }, - { x: 0.765625, y: 0.890625 }, - { x: 0.796875, y: 0.890625 }, - { x: 0.796875, y: 0.890625 }, - { x: 0.828125, y: 0.890625 }, - { x: 0.828125, y: 0.890625 }, - { x: 0.859375, y: 0.890625 }, - { x: 0.859375, y: 0.890625 }, - { x: 0.890625, y: 0.890625 }, - { x: 0.890625, y: 0.890625 }, - { x: 0.921875, y: 0.890625 }, - { x: 0.921875, y: 0.890625 }, - { x: 0.953125, y: 0.890625 }, - { x: 0.953125, y: 0.890625 }, - { x: 0.984375, y: 0.890625 }, - { x: 0.984375, y: 0.890625 }, - { x: 0.015625, y: 0.921875 }, - { x: 0.015625, y: 0.921875 }, - { x: 0.046875, y: 0.921875 }, - { x: 0.046875, y: 0.921875 }, - { x: 0.078125, y: 0.921875 }, - { x: 0.078125, y: 0.921875 }, - { x: 0.109375, y: 0.921875 }, - { x: 0.109375, y: 0.921875 }, - { x: 0.140625, y: 0.921875 }, - { x: 0.140625, y: 0.921875 }, - { x: 0.171875, y: 0.921875 }, - { x: 0.171875, y: 0.921875 }, - { x: 0.203125, y: 0.921875 }, - { x: 0.203125, y: 0.921875 }, - { x: 0.234375, y: 0.921875 }, - { x: 0.234375, y: 0.921875 }, - { x: 0.265625, y: 0.921875 }, - { x: 0.265625, y: 0.921875 }, - { x: 0.296875, y: 0.921875 }, - { x: 0.296875, y: 0.921875 }, - { x: 0.328125, y: 0.921875 }, - { x: 0.328125, y: 0.921875 }, - { x: 0.359375, y: 0.921875 }, - { x: 0.359375, y: 0.921875 }, - { x: 0.390625, y: 0.921875 }, - { x: 0.390625, y: 0.921875 }, - { x: 0.421875, y: 0.921875 }, - { x: 0.421875, y: 0.921875 }, - { x: 0.453125, y: 0.921875 }, - { x: 0.453125, y: 0.921875 }, - { x: 0.484375, y: 0.921875 }, - { x: 0.484375, y: 0.921875 }, - { x: 0.515625, y: 0.921875 }, - { x: 0.515625, y: 0.921875 }, - { x: 0.546875, y: 0.921875 }, - { x: 0.546875, y: 0.921875 }, - { x: 0.578125, y: 0.921875 }, - { x: 0.578125, y: 0.921875 }, - { x: 0.609375, y: 0.921875 }, - { x: 0.609375, y: 0.921875 }, - { x: 0.640625, y: 0.921875 }, - { x: 0.640625, y: 0.921875 }, - { x: 0.671875, y: 0.921875 }, - { x: 0.671875, y: 0.921875 }, - { x: 0.703125, y: 0.921875 }, - { x: 0.703125, y: 0.921875 }, - { x: 0.734375, y: 0.921875 }, - { x: 0.734375, y: 0.921875 }, - { x: 0.765625, y: 0.921875 }, - { x: 0.765625, y: 0.921875 }, - { x: 0.796875, y: 0.921875 }, - { x: 0.796875, y: 0.921875 }, - { x: 0.828125, y: 0.921875 }, - { x: 0.828125, y: 0.921875 }, - { x: 0.859375, y: 0.921875 }, - { x: 0.859375, y: 0.921875 }, - { x: 0.890625, y: 0.921875 }, - { x: 0.890625, y: 0.921875 }, - { x: 0.921875, y: 0.921875 }, - { x: 0.921875, y: 0.921875 }, - { x: 0.953125, y: 0.921875 }, - { x: 0.953125, y: 0.921875 }, - { x: 0.984375, y: 0.921875 }, - { x: 0.984375, y: 0.921875 }, - { x: 0.015625, y: 0.953125 }, - { x: 0.015625, y: 0.953125 }, - { x: 0.046875, y: 0.953125 }, - { x: 0.046875, y: 0.953125 }, - { x: 0.078125, y: 0.953125 }, - { x: 0.078125, y: 0.953125 }, - { x: 0.109375, y: 0.953125 }, - { x: 0.109375, y: 0.953125 }, - { x: 0.140625, y: 0.953125 }, - { x: 0.140625, y: 0.953125 }, - { x: 0.171875, y: 0.953125 }, - { x: 0.171875, y: 0.953125 }, - { x: 0.203125, y: 0.953125 }, - { x: 0.203125, y: 0.953125 }, - { x: 0.234375, y: 0.953125 }, - { x: 0.234375, y: 0.953125 }, - { x: 0.265625, y: 0.953125 }, - { x: 0.265625, y: 0.953125 }, - { x: 0.296875, y: 0.953125 }, - { x: 0.296875, y: 0.953125 }, - { x: 0.328125, y: 0.953125 }, - { x: 0.328125, y: 0.953125 }, - { x: 0.359375, y: 0.953125 }, - { x: 0.359375, y: 0.953125 }, - { x: 0.390625, y: 0.953125 }, - { x: 0.390625, y: 0.953125 }, - { x: 0.421875, y: 0.953125 }, - { x: 0.421875, y: 0.953125 }, - { x: 0.453125, y: 0.953125 }, - { x: 0.453125, y: 0.953125 }, - { x: 0.484375, y: 0.953125 }, - { x: 0.484375, y: 0.953125 }, - { x: 0.515625, y: 0.953125 }, - { x: 0.515625, y: 0.953125 }, - { x: 0.546875, y: 0.953125 }, - { x: 0.546875, y: 0.953125 }, - { x: 0.578125, y: 0.953125 }, - { x: 0.578125, y: 0.953125 }, - { x: 0.609375, y: 0.953125 }, - { x: 0.609375, y: 0.953125 }, - { x: 0.640625, y: 0.953125 }, - { x: 0.640625, y: 0.953125 }, - { x: 0.671875, y: 0.953125 }, - { x: 0.671875, y: 0.953125 }, - { x: 0.703125, y: 0.953125 }, - { x: 0.703125, y: 0.953125 }, - { x: 0.734375, y: 0.953125 }, - { x: 0.734375, y: 0.953125 }, - { x: 0.765625, y: 0.953125 }, - { x: 0.765625, y: 0.953125 }, - { x: 0.796875, y: 0.953125 }, - { x: 0.796875, y: 0.953125 }, - { x: 0.828125, y: 0.953125 }, - { x: 0.828125, y: 0.953125 }, - { x: 0.859375, y: 0.953125 }, - { x: 0.859375, y: 0.953125 }, - { x: 0.890625, y: 0.953125 }, - { x: 0.890625, y: 0.953125 }, - { x: 0.921875, y: 0.953125 }, - { x: 0.921875, y: 0.953125 }, - { x: 0.953125, y: 0.953125 }, - { x: 0.953125, y: 0.953125 }, - { x: 0.984375, y: 0.953125 }, - { x: 0.984375, y: 0.953125 }, - { x: 0.015625, y: 0.984375 }, - { x: 0.015625, y: 0.984375 }, - { x: 0.046875, y: 0.984375 }, - { x: 0.046875, y: 0.984375 }, - { x: 0.078125, y: 0.984375 }, - { x: 0.078125, y: 0.984375 }, - { x: 0.109375, y: 0.984375 }, - { x: 0.109375, y: 0.984375 }, - { x: 0.140625, y: 0.984375 }, - { x: 0.140625, y: 0.984375 }, - { x: 0.171875, y: 0.984375 }, - { x: 0.171875, y: 0.984375 }, - { x: 0.203125, y: 0.984375 }, - { x: 0.203125, y: 0.984375 }, - { x: 0.234375, y: 0.984375 }, - { x: 0.234375, y: 0.984375 }, - { x: 0.265625, y: 0.984375 }, - { x: 0.265625, y: 0.984375 }, - { x: 0.296875, y: 0.984375 }, - { x: 0.296875, y: 0.984375 }, - { x: 0.328125, y: 0.984375 }, - { x: 0.328125, y: 0.984375 }, - { x: 0.359375, y: 0.984375 }, - { x: 0.359375, y: 0.984375 }, - { x: 0.390625, y: 0.984375 }, - { x: 0.390625, y: 0.984375 }, - { x: 0.421875, y: 0.984375 }, - { x: 0.421875, y: 0.984375 }, - { x: 0.453125, y: 0.984375 }, - { x: 0.453125, y: 0.984375 }, - { x: 0.484375, y: 0.984375 }, - { x: 0.484375, y: 0.984375 }, - { x: 0.515625, y: 0.984375 }, - { x: 0.515625, y: 0.984375 }, - { x: 0.546875, y: 0.984375 }, - { x: 0.546875, y: 0.984375 }, - { x: 0.578125, y: 0.984375 }, - { x: 0.578125, y: 0.984375 }, - { x: 0.609375, y: 0.984375 }, - { x: 0.609375, y: 0.984375 }, - { x: 0.640625, y: 0.984375 }, - { x: 0.640625, y: 0.984375 }, - { x: 0.671875, y: 0.984375 }, - { x: 0.671875, y: 0.984375 }, - { x: 0.703125, y: 0.984375 }, - { x: 0.703125, y: 0.984375 }, - { x: 0.734375, y: 0.984375 }, - { x: 0.734375, y: 0.984375 }, - { x: 0.765625, y: 0.984375 }, - { x: 0.765625, y: 0.984375 }, - { x: 0.796875, y: 0.984375 }, - { x: 0.796875, y: 0.984375 }, - { x: 0.828125, y: 0.984375 }, - { x: 0.828125, y: 0.984375 }, - { x: 0.859375, y: 0.984375 }, - { x: 0.859375, y: 0.984375 }, - { x: 0.890625, y: 0.984375 }, - { x: 0.890625, y: 0.984375 }, - { x: 0.921875, y: 0.984375 }, - { x: 0.921875, y: 0.984375 }, - { x: 0.953125, y: 0.984375 }, - { x: 0.953125, y: 0.984375 }, - { x: 0.984375, y: 0.984375 }, - { x: 0.984375, y: 0.984375 }, - { x: 0.03125, y: 0.03125 }, - { x: 0.03125, y: 0.03125 }, - { x: 0.09375, y: 0.03125 }, - { x: 0.09375, y: 0.03125 }, - { x: 0.15625, y: 0.03125 }, - { x: 0.15625, y: 0.03125 }, - { x: 0.21875, y: 0.03125 }, - { x: 0.21875, y: 0.03125 }, - { x: 0.28125, y: 0.03125 }, - { x: 0.28125, y: 0.03125 }, - { x: 0.34375, y: 0.03125 }, - { x: 0.34375, y: 0.03125 }, - { x: 0.40625, y: 0.03125 }, - { x: 0.40625, y: 0.03125 }, - { x: 0.46875, y: 0.03125 }, - { x: 0.46875, y: 0.03125 }, - { x: 0.53125, y: 0.03125 }, - { x: 0.53125, y: 0.03125 }, - { x: 0.59375, y: 0.03125 }, - { x: 0.59375, y: 0.03125 }, - { x: 0.65625, y: 0.03125 }, - { x: 0.65625, y: 0.03125 }, - { x: 0.71875, y: 0.03125 }, - { x: 0.71875, y: 0.03125 }, - { x: 0.78125, y: 0.03125 }, - { x: 0.78125, y: 0.03125 }, - { x: 0.84375, y: 0.03125 }, - { x: 0.84375, y: 0.03125 }, - { x: 0.90625, y: 0.03125 }, - { x: 0.90625, y: 0.03125 }, - { x: 0.96875, y: 0.03125 }, - { x: 0.96875, y: 0.03125 }, - { x: 0.03125, y: 0.09375 }, - { x: 0.03125, y: 0.09375 }, - { x: 0.09375, y: 0.09375 }, - { x: 0.09375, y: 0.09375 }, - { x: 0.15625, y: 0.09375 }, - { x: 0.15625, y: 0.09375 }, - { x: 0.21875, y: 0.09375 }, - { x: 0.21875, y: 0.09375 }, - { x: 0.28125, y: 0.09375 }, - { x: 0.28125, y: 0.09375 }, - { x: 0.34375, y: 0.09375 }, - { x: 0.34375, y: 0.09375 }, - { x: 0.40625, y: 0.09375 }, - { x: 0.40625, y: 0.09375 }, - { x: 0.46875, y: 0.09375 }, - { x: 0.46875, y: 0.09375 }, - { x: 0.53125, y: 0.09375 }, - { x: 0.53125, y: 0.09375 }, - { x: 0.59375, y: 0.09375 }, - { x: 0.59375, y: 0.09375 }, - { x: 0.65625, y: 0.09375 }, - { x: 0.65625, y: 0.09375 }, - { x: 0.71875, y: 0.09375 }, - { x: 0.71875, y: 0.09375 }, - { x: 0.78125, y: 0.09375 }, - { x: 0.78125, y: 0.09375 }, - { x: 0.84375, y: 0.09375 }, - { x: 0.84375, y: 0.09375 }, - { x: 0.90625, y: 0.09375 }, - { x: 0.90625, y: 0.09375 }, - { x: 0.96875, y: 0.09375 }, - { x: 0.96875, y: 0.09375 }, - { x: 0.03125, y: 0.15625 }, - { x: 0.03125, y: 0.15625 }, - { x: 0.09375, y: 0.15625 }, - { x: 0.09375, y: 0.15625 }, - { x: 0.15625, y: 0.15625 }, - { x: 0.15625, y: 0.15625 }, - { x: 0.21875, y: 0.15625 }, - { x: 0.21875, y: 0.15625 }, - { x: 0.28125, y: 0.15625 }, - { x: 0.28125, y: 0.15625 }, - { x: 0.34375, y: 0.15625 }, - { x: 0.34375, y: 0.15625 }, - { x: 0.40625, y: 0.15625 }, - { x: 0.40625, y: 0.15625 }, - { x: 0.46875, y: 0.15625 }, - { x: 0.46875, y: 0.15625 }, - { x: 0.53125, y: 0.15625 }, - { x: 0.53125, y: 0.15625 }, - { x: 0.59375, y: 0.15625 }, - { x: 0.59375, y: 0.15625 }, - { x: 0.65625, y: 0.15625 }, - { x: 0.65625, y: 0.15625 }, - { x: 0.71875, y: 0.15625 }, - { x: 0.71875, y: 0.15625 }, - { x: 0.78125, y: 0.15625 }, - { x: 0.78125, y: 0.15625 }, - { x: 0.84375, y: 0.15625 }, - { x: 0.84375, y: 0.15625 }, - { x: 0.90625, y: 0.15625 }, - { x: 0.90625, y: 0.15625 }, - { x: 0.96875, y: 0.15625 }, - { x: 0.96875, y: 0.15625 }, - { x: 0.03125, y: 0.21875 }, - { x: 0.03125, y: 0.21875 }, - { x: 0.09375, y: 0.21875 }, - { x: 0.09375, y: 0.21875 }, - { x: 0.15625, y: 0.21875 }, - { x: 0.15625, y: 0.21875 }, - { x: 0.21875, y: 0.21875 }, - { x: 0.21875, y: 0.21875 }, - { x: 0.28125, y: 0.21875 }, - { x: 0.28125, y: 0.21875 }, - { x: 0.34375, y: 0.21875 }, - { x: 0.34375, y: 0.21875 }, - { x: 0.40625, y: 0.21875 }, - { x: 0.40625, y: 0.21875 }, - { x: 0.46875, y: 0.21875 }, - { x: 0.46875, y: 0.21875 }, - { x: 0.53125, y: 0.21875 }, - { x: 0.53125, y: 0.21875 }, - { x: 0.59375, y: 0.21875 }, - { x: 0.59375, y: 0.21875 }, - { x: 0.65625, y: 0.21875 }, - { x: 0.65625, y: 0.21875 }, - { x: 0.71875, y: 0.21875 }, - { x: 0.71875, y: 0.21875 }, - { x: 0.78125, y: 0.21875 }, - { x: 0.78125, y: 0.21875 }, - { x: 0.84375, y: 0.21875 }, - { x: 0.84375, y: 0.21875 }, - { x: 0.90625, y: 0.21875 }, - { x: 0.90625, y: 0.21875 }, - { x: 0.96875, y: 0.21875 }, - { x: 0.96875, y: 0.21875 }, - { x: 0.03125, y: 0.28125 }, - { x: 0.03125, y: 0.28125 }, - { x: 0.09375, y: 0.28125 }, - { x: 0.09375, y: 0.28125 }, - { x: 0.15625, y: 0.28125 }, - { x: 0.15625, y: 0.28125 }, - { x: 0.21875, y: 0.28125 }, - { x: 0.21875, y: 0.28125 }, - { x: 0.28125, y: 0.28125 }, - { x: 0.28125, y: 0.28125 }, - { x: 0.34375, y: 0.28125 }, - { x: 0.34375, y: 0.28125 }, - { x: 0.40625, y: 0.28125 }, - { x: 0.40625, y: 0.28125 }, - { x: 0.46875, y: 0.28125 }, - { x: 0.46875, y: 0.28125 }, - { x: 0.53125, y: 0.28125 }, - { x: 0.53125, y: 0.28125 }, - { x: 0.59375, y: 0.28125 }, - { x: 0.59375, y: 0.28125 }, - { x: 0.65625, y: 0.28125 }, - { x: 0.65625, y: 0.28125 }, - { x: 0.71875, y: 0.28125 }, - { x: 0.71875, y: 0.28125 }, - { x: 0.78125, y: 0.28125 }, - { x: 0.78125, y: 0.28125 }, - { x: 0.84375, y: 0.28125 }, - { x: 0.84375, y: 0.28125 }, - { x: 0.90625, y: 0.28125 }, - { x: 0.90625, y: 0.28125 }, - { x: 0.96875, y: 0.28125 }, - { x: 0.96875, y: 0.28125 }, - { x: 0.03125, y: 0.34375 }, - { x: 0.03125, y: 0.34375 }, - { x: 0.09375, y: 0.34375 }, - { x: 0.09375, y: 0.34375 }, - { x: 0.15625, y: 0.34375 }, - { x: 0.15625, y: 0.34375 }, - { x: 0.21875, y: 0.34375 }, - { x: 0.21875, y: 0.34375 }, - { x: 0.28125, y: 0.34375 }, - { x: 0.28125, y: 0.34375 }, - { x: 0.34375, y: 0.34375 }, - { x: 0.34375, y: 0.34375 }, - { x: 0.40625, y: 0.34375 }, - { x: 0.40625, y: 0.34375 }, - { x: 0.46875, y: 0.34375 }, - { x: 0.46875, y: 0.34375 }, - { x: 0.53125, y: 0.34375 }, - { x: 0.53125, y: 0.34375 }, - { x: 0.59375, y: 0.34375 }, - { x: 0.59375, y: 0.34375 }, - { x: 0.65625, y: 0.34375 }, - { x: 0.65625, y: 0.34375 }, - { x: 0.71875, y: 0.34375 }, - { x: 0.71875, y: 0.34375 }, - { x: 0.78125, y: 0.34375 }, - { x: 0.78125, y: 0.34375 }, - { x: 0.84375, y: 0.34375 }, - { x: 0.84375, y: 0.34375 }, - { x: 0.90625, y: 0.34375 }, - { x: 0.90625, y: 0.34375 }, - { x: 0.96875, y: 0.34375 }, - { x: 0.96875, y: 0.34375 }, - { x: 0.03125, y: 0.40625 }, - { x: 0.03125, y: 0.40625 }, - { x: 0.09375, y: 0.40625 }, - { x: 0.09375, y: 0.40625 }, - { x: 0.15625, y: 0.40625 }, - { x: 0.15625, y: 0.40625 }, - { x: 0.21875, y: 0.40625 }, - { x: 0.21875, y: 0.40625 }, - { x: 0.28125, y: 0.40625 }, - { x: 0.28125, y: 0.40625 }, - { x: 0.34375, y: 0.40625 }, - { x: 0.34375, y: 0.40625 }, - { x: 0.40625, y: 0.40625 }, - { x: 0.40625, y: 0.40625 }, - { x: 0.46875, y: 0.40625 }, - { x: 0.46875, y: 0.40625 }, - { x: 0.53125, y: 0.40625 }, - { x: 0.53125, y: 0.40625 }, - { x: 0.59375, y: 0.40625 }, - { x: 0.59375, y: 0.40625 }, - { x: 0.65625, y: 0.40625 }, - { x: 0.65625, y: 0.40625 }, - { x: 0.71875, y: 0.40625 }, - { x: 0.71875, y: 0.40625 }, - { x: 0.78125, y: 0.40625 }, - { x: 0.78125, y: 0.40625 }, - { x: 0.84375, y: 0.40625 }, - { x: 0.84375, y: 0.40625 }, - { x: 0.90625, y: 0.40625 }, - { x: 0.90625, y: 0.40625 }, - { x: 0.96875, y: 0.40625 }, - { x: 0.96875, y: 0.40625 }, - { x: 0.03125, y: 0.46875 }, - { x: 0.03125, y: 0.46875 }, - { x: 0.09375, y: 0.46875 }, - { x: 0.09375, y: 0.46875 }, - { x: 0.15625, y: 0.46875 }, - { x: 0.15625, y: 0.46875 }, - { x: 0.21875, y: 0.46875 }, - { x: 0.21875, y: 0.46875 }, - { x: 0.28125, y: 0.46875 }, - { x: 0.28125, y: 0.46875 }, - { x: 0.34375, y: 0.46875 }, - { x: 0.34375, y: 0.46875 }, - { x: 0.40625, y: 0.46875 }, - { x: 0.40625, y: 0.46875 }, - { x: 0.46875, y: 0.46875 }, - { x: 0.46875, y: 0.46875 }, - { x: 0.53125, y: 0.46875 }, - { x: 0.53125, y: 0.46875 }, - { x: 0.59375, y: 0.46875 }, - { x: 0.59375, y: 0.46875 }, - { x: 0.65625, y: 0.46875 }, - { x: 0.65625, y: 0.46875 }, - { x: 0.71875, y: 0.46875 }, - { x: 0.71875, y: 0.46875 }, - { x: 0.78125, y: 0.46875 }, - { x: 0.78125, y: 0.46875 }, - { x: 0.84375, y: 0.46875 }, - { x: 0.84375, y: 0.46875 }, - { x: 0.90625, y: 0.46875 }, - { x: 0.90625, y: 0.46875 }, - { x: 0.96875, y: 0.46875 }, - { x: 0.96875, y: 0.46875 }, - { x: 0.03125, y: 0.53125 }, - { x: 0.03125, y: 0.53125 }, - { x: 0.09375, y: 0.53125 }, - { x: 0.09375, y: 0.53125 }, - { x: 0.15625, y: 0.53125 }, - { x: 0.15625, y: 0.53125 }, - { x: 0.21875, y: 0.53125 }, - { x: 0.21875, y: 0.53125 }, - { x: 0.28125, y: 0.53125 }, - { x: 0.28125, y: 0.53125 }, - { x: 0.34375, y: 0.53125 }, - { x: 0.34375, y: 0.53125 }, - { x: 0.40625, y: 0.53125 }, - { x: 0.40625, y: 0.53125 }, - { x: 0.46875, y: 0.53125 }, - { x: 0.46875, y: 0.53125 }, - { x: 0.53125, y: 0.53125 }, - { x: 0.53125, y: 0.53125 }, - { x: 0.59375, y: 0.53125 }, - { x: 0.59375, y: 0.53125 }, - { x: 0.65625, y: 0.53125 }, - { x: 0.65625, y: 0.53125 }, - { x: 0.71875, y: 0.53125 }, - { x: 0.71875, y: 0.53125 }, - { x: 0.78125, y: 0.53125 }, - { x: 0.78125, y: 0.53125 }, - { x: 0.84375, y: 0.53125 }, - { x: 0.84375, y: 0.53125 }, - { x: 0.90625, y: 0.53125 }, - { x: 0.90625, y: 0.53125 }, - { x: 0.96875, y: 0.53125 }, - { x: 0.96875, y: 0.53125 }, - { x: 0.03125, y: 0.59375 }, - { x: 0.03125, y: 0.59375 }, - { x: 0.09375, y: 0.59375 }, - { x: 0.09375, y: 0.59375 }, - { x: 0.15625, y: 0.59375 }, - { x: 0.15625, y: 0.59375 }, - { x: 0.21875, y: 0.59375 }, - { x: 0.21875, y: 0.59375 }, - { x: 0.28125, y: 0.59375 }, - { x: 0.28125, y: 0.59375 }, - { x: 0.34375, y: 0.59375 }, - { x: 0.34375, y: 0.59375 }, - { x: 0.40625, y: 0.59375 }, - { x: 0.40625, y: 0.59375 }, - { x: 0.46875, y: 0.59375 }, - { x: 0.46875, y: 0.59375 }, - { x: 0.53125, y: 0.59375 }, - { x: 0.53125, y: 0.59375 }, - { x: 0.59375, y: 0.59375 }, - { x: 0.59375, y: 0.59375 }, - { x: 0.65625, y: 0.59375 }, - { x: 0.65625, y: 0.59375 }, - { x: 0.71875, y: 0.59375 }, - { x: 0.71875, y: 0.59375 }, - { x: 0.78125, y: 0.59375 }, - { x: 0.78125, y: 0.59375 }, - { x: 0.84375, y: 0.59375 }, - { x: 0.84375, y: 0.59375 }, - { x: 0.90625, y: 0.59375 }, - { x: 0.90625, y: 0.59375 }, - { x: 0.96875, y: 0.59375 }, - { x: 0.96875, y: 0.59375 }, - { x: 0.03125, y: 0.65625 }, - { x: 0.03125, y: 0.65625 }, - { x: 0.09375, y: 0.65625 }, - { x: 0.09375, y: 0.65625 }, - { x: 0.15625, y: 0.65625 }, - { x: 0.15625, y: 0.65625 }, - { x: 0.21875, y: 0.65625 }, - { x: 0.21875, y: 0.65625 }, - { x: 0.28125, y: 0.65625 }, - { x: 0.28125, y: 0.65625 }, - { x: 0.34375, y: 0.65625 }, - { x: 0.34375, y: 0.65625 }, - { x: 0.40625, y: 0.65625 }, - { x: 0.40625, y: 0.65625 }, - { x: 0.46875, y: 0.65625 }, - { x: 0.46875, y: 0.65625 }, - { x: 0.53125, y: 0.65625 }, - { x: 0.53125, y: 0.65625 }, - { x: 0.59375, y: 0.65625 }, - { x: 0.59375, y: 0.65625 }, - { x: 0.65625, y: 0.65625 }, - { x: 0.65625, y: 0.65625 }, - { x: 0.71875, y: 0.65625 }, - { x: 0.71875, y: 0.65625 }, - { x: 0.78125, y: 0.65625 }, - { x: 0.78125, y: 0.65625 }, - { x: 0.84375, y: 0.65625 }, - { x: 0.84375, y: 0.65625 }, - { x: 0.90625, y: 0.65625 }, - { x: 0.90625, y: 0.65625 }, - { x: 0.96875, y: 0.65625 }, - { x: 0.96875, y: 0.65625 }, - { x: 0.03125, y: 0.71875 }, - { x: 0.03125, y: 0.71875 }, - { x: 0.09375, y: 0.71875 }, - { x: 0.09375, y: 0.71875 }, - { x: 0.15625, y: 0.71875 }, - { x: 0.15625, y: 0.71875 }, - { x: 0.21875, y: 0.71875 }, - { x: 0.21875, y: 0.71875 }, - { x: 0.28125, y: 0.71875 }, - { x: 0.28125, y: 0.71875 }, - { x: 0.34375, y: 0.71875 }, - { x: 0.34375, y: 0.71875 }, - { x: 0.40625, y: 0.71875 }, - { x: 0.40625, y: 0.71875 }, - { x: 0.46875, y: 0.71875 }, - { x: 0.46875, y: 0.71875 }, - { x: 0.53125, y: 0.71875 }, - { x: 0.53125, y: 0.71875 }, - { x: 0.59375, y: 0.71875 }, - { x: 0.59375, y: 0.71875 }, - { x: 0.65625, y: 0.71875 }, - { x: 0.65625, y: 0.71875 }, - { x: 0.71875, y: 0.71875 }, - { x: 0.71875, y: 0.71875 }, - { x: 0.78125, y: 0.71875 }, - { x: 0.78125, y: 0.71875 }, - { x: 0.84375, y: 0.71875 }, - { x: 0.84375, y: 0.71875 }, - { x: 0.90625, y: 0.71875 }, - { x: 0.90625, y: 0.71875 }, - { x: 0.96875, y: 0.71875 }, - { x: 0.96875, y: 0.71875 }, - { x: 0.03125, y: 0.78125 }, - { x: 0.03125, y: 0.78125 }, - { x: 0.09375, y: 0.78125 }, - { x: 0.09375, y: 0.78125 }, - { x: 0.15625, y: 0.78125 }, - { x: 0.15625, y: 0.78125 }, - { x: 0.21875, y: 0.78125 }, - { x: 0.21875, y: 0.78125 }, - { x: 0.28125, y: 0.78125 }, - { x: 0.28125, y: 0.78125 }, - { x: 0.34375, y: 0.78125 }, - { x: 0.34375, y: 0.78125 }, - { x: 0.40625, y: 0.78125 }, - { x: 0.40625, y: 0.78125 }, - { x: 0.46875, y: 0.78125 }, - { x: 0.46875, y: 0.78125 }, - { x: 0.53125, y: 0.78125 }, - { x: 0.53125, y: 0.78125 }, - { x: 0.59375, y: 0.78125 }, - { x: 0.59375, y: 0.78125 }, - { x: 0.65625, y: 0.78125 }, - { x: 0.65625, y: 0.78125 }, - { x: 0.71875, y: 0.78125 }, - { x: 0.71875, y: 0.78125 }, - { x: 0.78125, y: 0.78125 }, - { x: 0.78125, y: 0.78125 }, - { x: 0.84375, y: 0.78125 }, - { x: 0.84375, y: 0.78125 }, - { x: 0.90625, y: 0.78125 }, - { x: 0.90625, y: 0.78125 }, - { x: 0.96875, y: 0.78125 }, - { x: 0.96875, y: 0.78125 }, - { x: 0.03125, y: 0.84375 }, - { x: 0.03125, y: 0.84375 }, - { x: 0.09375, y: 0.84375 }, - { x: 0.09375, y: 0.84375 }, - { x: 0.15625, y: 0.84375 }, - { x: 0.15625, y: 0.84375 }, - { x: 0.21875, y: 0.84375 }, - { x: 0.21875, y: 0.84375 }, - { x: 0.28125, y: 0.84375 }, - { x: 0.28125, y: 0.84375 }, - { x: 0.34375, y: 0.84375 }, - { x: 0.34375, y: 0.84375 }, - { x: 0.40625, y: 0.84375 }, - { x: 0.40625, y: 0.84375 }, - { x: 0.46875, y: 0.84375 }, - { x: 0.46875, y: 0.84375 }, - { x: 0.53125, y: 0.84375 }, - { x: 0.53125, y: 0.84375 }, - { x: 0.59375, y: 0.84375 }, - { x: 0.59375, y: 0.84375 }, - { x: 0.65625, y: 0.84375 }, - { x: 0.65625, y: 0.84375 }, - { x: 0.71875, y: 0.84375 }, - { x: 0.71875, y: 0.84375 }, - { x: 0.78125, y: 0.84375 }, - { x: 0.78125, y: 0.84375 }, - { x: 0.84375, y: 0.84375 }, - { x: 0.84375, y: 0.84375 }, - { x: 0.90625, y: 0.84375 }, - { x: 0.90625, y: 0.84375 }, - { x: 0.96875, y: 0.84375 }, - { x: 0.96875, y: 0.84375 }, - { x: 0.03125, y: 0.90625 }, - { x: 0.03125, y: 0.90625 }, - { x: 0.09375, y: 0.90625 }, - { x: 0.09375, y: 0.90625 }, - { x: 0.15625, y: 0.90625 }, - { x: 0.15625, y: 0.90625 }, - { x: 0.21875, y: 0.90625 }, - { x: 0.21875, y: 0.90625 }, - { x: 0.28125, y: 0.90625 }, - { x: 0.28125, y: 0.90625 }, - { x: 0.34375, y: 0.90625 }, - { x: 0.34375, y: 0.90625 }, - { x: 0.40625, y: 0.90625 }, - { x: 0.40625, y: 0.90625 }, - { x: 0.46875, y: 0.90625 }, - { x: 0.46875, y: 0.90625 }, - { x: 0.53125, y: 0.90625 }, - { x: 0.53125, y: 0.90625 }, - { x: 0.59375, y: 0.90625 }, - { x: 0.59375, y: 0.90625 }, - { x: 0.65625, y: 0.90625 }, - { x: 0.65625, y: 0.90625 }, - { x: 0.71875, y: 0.90625 }, - { x: 0.71875, y: 0.90625 }, - { x: 0.78125, y: 0.90625 }, - { x: 0.78125, y: 0.90625 }, - { x: 0.84375, y: 0.90625 }, - { x: 0.84375, y: 0.90625 }, - { x: 0.90625, y: 0.90625 }, - { x: 0.90625, y: 0.90625 }, - { x: 0.96875, y: 0.90625 }, - { x: 0.96875, y: 0.90625 }, - { x: 0.03125, y: 0.96875 }, - { x: 0.03125, y: 0.96875 }, - { x: 0.09375, y: 0.96875 }, - { x: 0.09375, y: 0.96875 }, - { x: 0.15625, y: 0.96875 }, - { x: 0.15625, y: 0.96875 }, - { x: 0.21875, y: 0.96875 }, - { x: 0.21875, y: 0.96875 }, - { x: 0.28125, y: 0.96875 }, - { x: 0.28125, y: 0.96875 }, - { x: 0.34375, y: 0.96875 }, - { x: 0.34375, y: 0.96875 }, - { x: 0.40625, y: 0.96875 }, - { x: 0.40625, y: 0.96875 }, - { x: 0.46875, y: 0.96875 }, - { x: 0.46875, y: 0.96875 }, - { x: 0.53125, y: 0.96875 }, - { x: 0.53125, y: 0.96875 }, - { x: 0.59375, y: 0.96875 }, - { x: 0.59375, y: 0.96875 }, - { x: 0.65625, y: 0.96875 }, - { x: 0.65625, y: 0.96875 }, - { x: 0.71875, y: 0.96875 }, - { x: 0.71875, y: 0.96875 }, - { x: 0.78125, y: 0.96875 }, - { x: 0.78125, y: 0.96875 }, - { x: 0.84375, y: 0.96875 }, - { x: 0.84375, y: 0.96875 }, - { x: 0.90625, y: 0.96875 }, - { x: 0.90625, y: 0.96875 }, - { x: 0.96875, y: 0.96875 }, - { x: 0.96875, y: 0.96875 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 } -]; - -// src/hand/handposedetector.ts -var HandDetector = class { - constructor(model23) { - __publicField(this, "model"); - __publicField(this, "anchors"); - __publicField(this, "anchorsTensor"); - __publicField(this, "inputSize"); - __publicField(this, "inputSizeTensor"); - __publicField(this, "doubleInputSizeTensor"); - var _a, _b, _c, _d; - this.model = model23; - this.anchors = anchors2.map((anchor) => [anchor.x, anchor.y]); - this.anchorsTensor = tf27.tensor2d(this.anchors); - this.inputSize = ((_d = (_c = (_b = (_a = this == null ? void 0 : this.model) == null ? void 0 : _a.inputs) == null ? void 0 : _b[0]) == null ? void 0 : _c.shape) == null ? void 0 : _d[2]) || 0; - this.inputSizeTensor = tf27.tensor1d([this.inputSize, this.inputSize]); - this.doubleInputSizeTensor = tf27.tensor1d([this.inputSize * 2, this.inputSize * 2]); - } - normalizeBoxes(boxes) { - const t2 = {}; - t2.boxOffsets = tf27.slice(boxes, [0, 0], [-1, 2]); - t2.boxSizes = tf27.slice(boxes, [0, 2], [-1, 2]); - t2.div = tf27.div(t2.boxOffsets, this.inputSizeTensor); - t2.boxCenterPoints = tf27.add(t2.div, this.anchorsTensor); - t2.halfBoxSizes = tf27.div(t2.boxSizes, this.doubleInputSizeTensor); - t2.sub = tf27.sub(t2.boxCenterPoints, t2.halfBoxSizes); - t2.startPoints = tf27.mul(t2.sub, this.inputSizeTensor); - t2.add = tf27.add(t2.boxCenterPoints, t2.halfBoxSizes); - t2.endPoints = tf27.mul(t2.add, this.inputSizeTensor); - const res = tf27.concat2d([t2.startPoints, t2.endPoints], 1); - Object.keys(t2).forEach((tensor6) => tf27.dispose(t2[tensor6])); - return res; - } - normalizeLandmarks(rawPalmLandmarks, index2) { - const t2 = {}; - t2.reshape = tf27.reshape(rawPalmLandmarks, [-1, 7, 2]); - t2.div = tf27.div(t2.reshape, this.inputSizeTensor); - t2.landmarks = tf27.add(t2.div, this.anchors[index2] ? this.anchors[index2] : 0); - const res = tf27.mul(t2.landmarks, this.inputSizeTensor); - Object.keys(t2).forEach((tensor6) => tf27.dispose(t2[tensor6])); - return res; - } - async predict(input, config3) { - var _a; - const t2 = {}; - t2.resize = tf27.image.resizeBilinear(input, [this.inputSize, this.inputSize]); - t2.div = tf27.div(t2.resize, constants.tf127); - t2.image = tf27.sub(t2.div, constants.tf1); - t2.batched = this.model.execute(t2.image); - t2.predictions = tf27.squeeze(t2.batched); - t2.slice = tf27.slice(t2.predictions, [0, 0], [-1, 1]); - t2.sigmoid = tf27.sigmoid(t2.slice); - t2.scores = tf27.squeeze(t2.sigmoid); - const scores = await t2.scores.data(); - t2.boxes = tf27.slice(t2.predictions, [0, 1], [-1, 4]); - t2.norm = this.normalizeBoxes(t2.boxes); - t2.nms = await tf27.image.nonMaxSuppressionAsync(t2.norm, t2.scores, 3 * (((_a = config3.hand) == null ? void 0 : _a.maxDetected) || 1), config3.hand.iouThreshold, config3.hand.minConfidence); - const nms = await t2.nms.array(); - const hands = []; - for (const index2 of nms) { - const p = {}; - p.box = tf27.slice(t2.norm, [index2, 0], [1, -1]); - p.slice = tf27.slice(t2.predictions, [index2, 5], [1, 14]); - p.norm = this.normalizeLandmarks(p.slice, index2); - p.palmLandmarks = tf27.reshape(p.norm, [-1, 2]); - const box = await p.box.data(); - const startPoint = box.slice(0, 2); - const endPoint = box.slice(2, 4); - const palmLandmarks = await p.palmLandmarks.array(); - const hand3 = { startPoint, endPoint, palmLandmarks, confidence: scores[index2] }; - const scaled = scaleBoxCoordinates2(hand3, [(input.shape[2] || 1) / this.inputSize, (input.shape[1] || 0) / this.inputSize]); - hands.push(scaled); - Object.keys(p).forEach((tensor6) => tf27.dispose(p[tensor6])); - } - Object.keys(t2).forEach((tensor6) => tf27.dispose(t2[tensor6])); - return hands; - } -}; - -// src/hand/handposepipeline.ts -var tf28 = __toESM(require_tfjs_esm()); -var palmBoxEnlargeFactor = 5; -var handBoxEnlargeFactor = 1.65; -var palmLandmarkIds = [0, 5, 9, 13, 17, 1, 2]; -var palmLandmarksPalmBase = 0; -var palmLandmarksMiddleFingerBase = 2; -var lastTime13 = 0; -var HandPipeline = class { - constructor(handDetector, handPoseModel2) { - __publicField(this, "handDetector"); - __publicField(this, "handPoseModel"); - __publicField(this, "inputSize"); - __publicField(this, "storedBoxes"); - __publicField(this, "skipped"); - __publicField(this, "detectedHands"); - var _a, _b, _c; - this.handDetector = handDetector; - this.handPoseModel = handPoseModel2; - this.inputSize = ((_c = (_b = (_a = this.handPoseModel) == null ? void 0 : _a.inputs) == null ? void 0 : _b[0].shape) == null ? void 0 : _c[2]) || 0; - this.storedBoxes = []; - this.skipped = Number.MAX_SAFE_INTEGER; - this.detectedHands = 0; - } - calculateLandmarksBoundingBox(landmarks) { - const xs = landmarks.map((d) => d[0]); - const ys = landmarks.map((d) => d[1]); - const startPoint = [Math.min(...xs), Math.min(...ys)]; - const endPoint = [Math.max(...xs), Math.max(...ys)]; - return { startPoint, endPoint }; - } - getBoxForPalmLandmarks(palmLandmarks, rotationMatrix) { - const rotatedPalmLandmarks = palmLandmarks.map((coord) => rotatePoint2([...coord, 1], rotationMatrix)); - const boxAroundPalm = this.calculateLandmarksBoundingBox(rotatedPalmLandmarks); - return enlargeBox2(squarifyBox2(boxAroundPalm), palmBoxEnlargeFactor); - } - getBoxForHandLandmarks(landmarks) { - const boundingBox = this.calculateLandmarksBoundingBox(landmarks); - const boxAroundHand = enlargeBox2(squarifyBox2(boundingBox), handBoxEnlargeFactor); - boxAroundHand.palmLandmarks = []; - for (let i = 0; i < palmLandmarkIds.length; i++) { - boxAroundHand.palmLandmarks.push(landmarks[palmLandmarkIds[i]].slice(0, 2)); - } - return boxAroundHand; - } - transformRawCoords(rawCoords, box2, angle, rotationMatrix) { - const boxSize = getBoxSize2(box2); - const scaleFactor = [boxSize[0] / this.inputSize, boxSize[1] / this.inputSize, (boxSize[0] + boxSize[1]) / this.inputSize / 2]; - const coordsScaled = rawCoords.map((coord) => [ - scaleFactor[0] * (coord[0] - this.inputSize / 2), - scaleFactor[1] * (coord[1] - this.inputSize / 2), - scaleFactor[2] * coord[2] - ]); - const coordsRotationMatrix = buildRotationMatrix2(angle, [0, 0]); - const coordsRotated = coordsScaled.map((coord) => { - const rotated = rotatePoint2(coord, coordsRotationMatrix); - return [...rotated, coord[2]]; - }); - const inverseRotationMatrix = invertTransformMatrix2(rotationMatrix); - const boxCenter = [...getBoxCenter2(box2), 1]; - const originalBoxCenter = [ - dot2(boxCenter, inverseRotationMatrix[0]), - dot2(boxCenter, inverseRotationMatrix[1]) - ]; - return coordsRotated.map((coord) => [ - Math.trunc(coord[0] + originalBoxCenter[0]), - Math.trunc(coord[1] + originalBoxCenter[1]), - Math.trunc(coord[2]) - ]); - } - async estimateHands(image28, config3) { - let useFreshBox = false; - let boxes; - const skipTime = (config3.hand.skipTime || 0) > now() - lastTime13; - const skipFrame = this.skipped < (config3.hand.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame) { - boxes = await this.handDetector.predict(image28, config3); - this.skipped = 0; - } - if (config3.skipAllowed) - this.skipped++; - if (boxes && boxes.length > 0 && (boxes.length !== this.detectedHands && this.detectedHands !== config3.hand.maxDetected || !config3.hand.landmarks)) { - this.detectedHands = 0; - this.storedBoxes = [...boxes]; - if (this.storedBoxes.length > 0) - useFreshBox = true; - } - const hands = []; - for (let i = 0; i < this.storedBoxes.length; i++) { - const currentBox = this.storedBoxes[i]; - if (!currentBox) - continue; - if (config3.hand.landmarks) { - const angle = config3.hand.rotation ? computeRotation2(currentBox.palmLandmarks[palmLandmarksPalmBase], currentBox.palmLandmarks[palmLandmarksMiddleFingerBase]) : 0; - const palmCenter = getBoxCenter2(currentBox); - const palmCenterNormalized = [palmCenter[0] / image28.shape[2], palmCenter[1] / image28.shape[1]]; - const rotatedImage = config3.hand.rotation && env.kernels.includes("rotatewithoffset") ? tf28.image.rotateWithOffset(image28, angle, 0, palmCenterNormalized) : image28.clone(); - const rotationMatrix = buildRotationMatrix2(-angle, palmCenter); - const newBox = useFreshBox ? this.getBoxForPalmLandmarks(currentBox.palmLandmarks, rotationMatrix) : currentBox; - const croppedInput = cutBoxFromImageAndResize(newBox, rotatedImage, [this.inputSize, this.inputSize]); - const handImage = tf28.div(croppedInput, constants.tf255); - tf28.dispose(croppedInput); - tf28.dispose(rotatedImage); - const [confidenceT, keypoints] = this.handPoseModel.execute(handImage); - lastTime13 = now(); - tf28.dispose(handImage); - const confidence = (await confidenceT.data())[0]; - tf28.dispose(confidenceT); - if (confidence >= config3.hand.minConfidence / 4) { - const keypointsReshaped = tf28.reshape(keypoints, [-1, 3]); - const rawCoords = await keypointsReshaped.array(); - tf28.dispose(keypoints); - tf28.dispose(keypointsReshaped); - const coords = this.transformRawCoords(rawCoords, newBox, angle, rotationMatrix); - const nextBoundingBox = this.getBoxForHandLandmarks(coords); - this.storedBoxes[i] = { ...nextBoundingBox, confidence }; - const result = { - landmarks: coords, - confidence, - boxConfidence: currentBox.confidence, - fingerConfidence: confidence, - box: { topLeft: nextBoundingBox.startPoint, bottomRight: nextBoundingBox.endPoint } - }; - hands.push(result); - } else { - this.storedBoxes[i] = null; - } - tf28.dispose(keypoints); - } else { - const enlarged = enlargeBox2(squarifyBox2(currentBox), handBoxEnlargeFactor); - const result = { - confidence: currentBox.confidence, - boxConfidence: currentBox.confidence, - fingerConfidence: 0, - box: { topLeft: enlarged.startPoint, bottomRight: enlarged.endPoint }, - landmarks: [] - }; - hands.push(result); - } - } - this.storedBoxes = this.storedBoxes.filter((a) => a !== null); - this.detectedHands = hands.length; - if (hands.length > config3.hand.maxDetected) - hands.length = config3.hand.maxDetected; - return hands; - } -}; - -// src/hand/handpose.ts -var meshAnnotations2 = { - thumb: [1, 2, 3, 4], - index: [5, 6, 7, 8], - middle: [9, 10, 11, 12], - ring: [13, 14, 15, 16], - pinky: [17, 18, 19, 20], - palm: [0] -}; -var handDetectorModel; -var handPoseModel; -var handPipeline; -async function predict14(input, config3) { - const predictions = await handPipeline.estimateHands(input, config3); - if (!predictions) - return []; - const hands = []; - for (let i = 0; i < predictions.length; i++) { - const annotations2 = {}; - if (predictions[i].landmarks) { - for (const key of Object.keys(meshAnnotations2)) { - annotations2[key] = meshAnnotations2[key].map((index2) => predictions[i].landmarks[index2]); - } - } - const keypoints = predictions[i].landmarks; - let box = [Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, 0, 0]; - let boxRaw = [0, 0, 0, 0]; - if (keypoints && keypoints.length > 0) { - for (const pt of keypoints) { - if (pt[0] < box[0]) - box[0] = pt[0]; - if (pt[1] < box[1]) - box[1] = pt[1]; - if (pt[0] > box[2]) - box[2] = pt[0]; - if (pt[1] > box[3]) - box[3] = pt[1]; - } - box[2] -= box[0]; - box[3] -= box[1]; - boxRaw = [box[0] / (input.shape[2] || 0), box[1] / (input.shape[1] || 0), box[2] / (input.shape[2] || 0), box[3] / (input.shape[1] || 0)]; - } else { - box = predictions[i].box ? [ - Math.trunc(Math.max(0, predictions[i].box.topLeft[0])), - Math.trunc(Math.max(0, predictions[i].box.topLeft[1])), - Math.trunc(Math.min(input.shape[2] || 0, predictions[i].box.bottomRight[0]) - Math.max(0, predictions[i].box.topLeft[0])), - Math.trunc(Math.min(input.shape[1] || 0, predictions[i].box.bottomRight[1]) - Math.max(0, predictions[i].box.topLeft[1])) - ] : [0, 0, 0, 0]; - boxRaw = [ - predictions[i].box.topLeft[0] / (input.shape[2] || 0), - predictions[i].box.topLeft[1] / (input.shape[1] || 0), - (predictions[i].box.bottomRight[0] - predictions[i].box.topLeft[0]) / (input.shape[2] || 0), - (predictions[i].box.bottomRight[1] - predictions[i].box.topLeft[1]) / (input.shape[1] || 0) - ]; - } - const landmarks = analyze(keypoints); - hands.push({ - id: i, - score: Math.round(100 * predictions[i].confidence) / 100, - boxScore: Math.round(100 * predictions[i].boxConfidence) / 100, - fingerScore: Math.round(100 * predictions[i].fingerConfidence) / 100, - label: "hand", - box, - boxRaw, - keypoints, - annotations: annotations2, - landmarks - }); - } - return hands; -} -async function load15(config3) { - var _a, _b; - if (env.initial) { - handDetectorModel = null; - handPoseModel = null; - } - if (!handDetectorModel || !handPoseModel) { - [handDetectorModel, handPoseModel] = await Promise.all([ - config3.hand.enabled ? loadModel((_a = config3.hand.detector) == null ? void 0 : _a.modelPath) : null, - config3.hand.landmarks ? loadModel((_b = config3.hand.skeleton) == null ? void 0 : _b.modelPath) : null - ]); - } else { - if (config3.debug) - log("cached model:", handDetectorModel["modelUrl"]); - if (config3.debug) - log("cached model:", handPoseModel["modelUrl"]); - } - const handDetector = handDetectorModel ? new HandDetector(handDetectorModel) : void 0; - if (handDetector && handPoseModel) - handPipeline = new HandPipeline(handDetector, handPoseModel); - return [handDetectorModel, handPoseModel]; -} - -// src/hand/handtrack.ts -var tf29 = __toESM(require_tfjs_esm()); -var models2 = [null, null]; -var modelOutputNodes = ["StatefulPartitionedCall/Postprocessor/Slice", "StatefulPartitionedCall/Postprocessor/ExpandDims_1"]; -var inputSize7 = [[0, 0], [0, 0]]; -var classes = ["hand", "fist", "pinch", "point", "face", "tip", "pinchtip"]; -var faceIndex = 4; -var boxExpandFact = 1.6; -var maxDetectorResolution = 512; -var detectorExpandFact = 1.4; -var skipped13 = Number.MAX_SAFE_INTEGER; -var lastTime14 = 0; -var outputSize = [0, 0]; -var cache4 = { - boxes: [], - hands: [] -}; -var fingerMap = { - thumb: [1, 2, 3, 4], - index: [5, 6, 7, 8], - middle: [9, 10, 11, 12], - ring: [13, 14, 15, 16], - pinky: [17, 18, 19, 20], - base: [0], - palm: [0, 17, 13, 9, 5, 1, 0] -}; -async function loadDetect2(config3) { - var _a; - if (env.initial) - models2[0] = null; - if (!models2[0]) { - fakeOps(["tensorlistreserve", "enter", "tensorlistfromtensor", "merge", "loopcond", "switch", "exit", "tensorliststack", "nextiteration", "tensorlistsetitem", "tensorlistgetitem", "reciprocal", "shape", "split", "where"], config3); - models2[0] = await loadModel((_a = config3.hand.detector) == null ? void 0 : _a.modelPath); - const inputs = models2[0]["executor"] ? Object.values(models2[0].modelSignature["inputs"]) : void 0; - inputSize7[0][0] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - inputSize7[0][1] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 0; - } else if (config3.debug) - log("cached model:", models2[0]["modelUrl"]); - return models2[0]; -} -async function loadSkeleton(config3) { - var _a; - if (env.initial) - models2[1] = null; - if (!models2[1]) { - models2[1] = await loadModel((_a = config3.hand.skeleton) == null ? void 0 : _a.modelPath); - const inputs = models2[1]["executor"] ? Object.values(models2[1].modelSignature["inputs"]) : void 0; - inputSize7[1][0] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - inputSize7[1][1] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 0; - } else if (config3.debug) - log("cached model:", models2[1]["modelUrl"]); - return models2[1]; -} -async function detectHands(input, config3) { - const hands = []; - if (!input || !models2[0]) - return hands; - const t2 = {}; - const ratio2 = (input.shape[2] || 1) / (input.shape[1] || 1); - const height = Math.min(Math.round((input.shape[1] || 0) / 8) * 8, maxDetectorResolution); - const width = Math.round(height * ratio2 / 8) * 8; - t2.resize = tf29.image.resizeBilinear(input, [height, width]); - t2.cast = tf29.cast(t2.resize, "int32"); - [t2.rawScores, t2.rawBoxes] = await models2[0].executeAsync(t2.cast, modelOutputNodes); - t2.boxes = tf29.squeeze(t2.rawBoxes, [0, 2]); - t2.scores = tf29.squeeze(t2.rawScores, [0]); - const classScores = tf29.unstack(t2.scores, 1); - tf29.dispose(classScores[faceIndex]); - classScores.splice(faceIndex, 1); - t2.filtered = tf29.stack(classScores, 1); - tf29.dispose(classScores); - t2.max = tf29.max(t2.filtered, 1); - t2.argmax = tf29.argMax(t2.filtered, 1); - let id = 0; - t2.nms = await tf29.image.nonMaxSuppressionAsync(t2.boxes, t2.max, (config3.hand.maxDetected || 0) + 1, config3.hand.iouThreshold || 0, config3.hand.minConfidence || 1); - const nms = await t2.nms.data(); - const scores = await t2.max.data(); - const classNum = await t2.argmax.data(); - for (const nmsIndex of Array.from(nms)) { - const boxSlice = tf29.slice(t2.boxes, nmsIndex, 1); - const boxYX = await boxSlice.data(); - tf29.dispose(boxSlice); - const boxData = [boxYX[1], boxYX[0], boxYX[3] - boxYX[1], boxYX[2] - boxYX[0]]; - const boxRaw = scale(boxData, detectorExpandFact); - const boxFull = [Math.trunc(boxData[0] * outputSize[0]), Math.trunc(boxData[1] * outputSize[1]), Math.trunc(boxData[2] * outputSize[0]), Math.trunc(boxData[3] * outputSize[1])]; - const score = scores[nmsIndex]; - const label = classes[classNum[nmsIndex]]; - const hand3 = { id: id++, score, box: boxFull, boxRaw, label }; - hands.push(hand3); - } - Object.keys(t2).forEach((tensor6) => tf29.dispose(t2[tensor6])); - hands.sort((a, b) => b.score - a.score); - if (hands.length > (config3.hand.maxDetected || 1)) - hands.length = config3.hand.maxDetected || 1; - return hands; -} -async function detectFingers(input, h, config3) { - const hand3 = { - id: h.id, - score: Math.round(100 * h.score) / 100, - boxScore: Math.round(100 * h.score) / 100, - fingerScore: 0, - box: h.box, - boxRaw: h.boxRaw, - label: h.label, - keypoints: [], - landmarks: {}, - annotations: {} - }; - if (input && models2[1] && config3.hand.landmarks && h.score > (config3.hand.minConfidence || 0)) { - const t2 = {}; - const boxCrop = [h.boxRaw[1], h.boxRaw[0], h.boxRaw[3] + h.boxRaw[1], h.boxRaw[2] + h.boxRaw[0]]; - t2.crop = tf29.image.cropAndResize(input, [boxCrop], [0], [inputSize7[1][0], inputSize7[1][1]], "bilinear"); - t2.div = tf29.div(t2.crop, constants.tf255); - [t2.score, t2.keypoints] = models2[1].execute(t2.div, ["Identity_1", "Identity"]); - const rawScore = (await t2.score.data())[0]; - const score = (100 - Math.trunc(100 / (1 + Math.exp(rawScore)))) / 100; - if (score >= (config3.hand.minConfidence || 0)) { - hand3.fingerScore = score; - t2.reshaped = tf29.reshape(t2.keypoints, [-1, 3]); - const coordsData = await t2.reshaped.array(); - const coordsRaw = coordsData.map((kpt4) => [kpt4[0] / inputSize7[1][1], kpt4[1] / inputSize7[1][0], kpt4[2] || 0]); - const coordsNorm = coordsRaw.map((kpt4) => [kpt4[0] * h.boxRaw[2], kpt4[1] * h.boxRaw[3], kpt4[2] || 0]); - hand3.keypoints = coordsNorm.map((kpt4) => [outputSize[0] * (kpt4[0] + h.boxRaw[0]), outputSize[1] * (kpt4[1] + h.boxRaw[1]), kpt4[2] || 0]); - hand3.landmarks = analyze(hand3.keypoints); - for (const key of Object.keys(fingerMap)) { - hand3.annotations[key] = fingerMap[key].map((index2) => hand3.landmarks && hand3.keypoints[index2] ? hand3.keypoints[index2] : null); - } - } - Object.keys(t2).forEach((tensor6) => tf29.dispose(t2[tensor6])); - } - return hand3; -} -async function predict15(input, config3) { - var _a, _b; - if (!((_a = models2[0]) == null ? void 0 : _a["executor"]) || !((_b = models2[1]) == null ? void 0 : _b["executor"]) || !models2[0].inputs[0].shape || !models2[1].inputs[0].shape) - return []; - outputSize = [input.shape[2] || 0, input.shape[1] || 0]; - skipped13++; - const skipTime = (config3.hand.skipTime || 0) > now() - lastTime14; - const skipFrame = skipped13 < (config3.hand.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame) { - return cache4.hands; - } - return new Promise(async (resolve) => { - const skipTimeExtended = 3 * (config3.hand.skipTime || 0) > now() - lastTime14; - const skipFrameExtended = skipped13 < 3 * (config3.hand.skipFrames || 0); - if (config3.skipAllowed && cache4.hands.length === config3.hand.maxDetected) { - cache4.hands = await Promise.all(cache4.boxes.map((handBox) => detectFingers(input, handBox, config3))); - } else if (config3.skipAllowed && skipTimeExtended && skipFrameExtended && cache4.hands.length > 0) { - cache4.hands = await Promise.all(cache4.boxes.map((handBox) => detectFingers(input, handBox, config3))); - } else { - cache4.boxes = await detectHands(input, config3); - lastTime14 = now(); - cache4.hands = await Promise.all(cache4.boxes.map((handBox) => detectFingers(input, handBox, config3))); - skipped13 = 0; - } - const oldCache = [...cache4.boxes]; - cache4.boxes.length = 0; - if (config3.cacheSensitivity > 0) { - for (let i = 0; i < cache4.hands.length; i++) { - const boxKpt = square(cache4.hands[i].keypoints, outputSize); - if (boxKpt.box[2] / (input.shape[2] || 1) > 0.05 && boxKpt.box[3] / (input.shape[1] || 1) > 0.05 && cache4.hands[i].fingerScore && cache4.hands[i].fingerScore > (config3.hand.minConfidence || 0)) { - const boxScale = scale(boxKpt.box, boxExpandFact); - const boxScaleRaw = scale(boxKpt.boxRaw, boxExpandFact); - cache4.boxes.push({ ...oldCache[i], box: boxScale, boxRaw: boxScaleRaw }); - } - } - } - for (let i = 0; i < cache4.hands.length; i++) { - const bbox = calc(cache4.hands[i].keypoints, outputSize); - cache4.hands[i].box = bbox.box; - cache4.hands[i].boxRaw = bbox.boxRaw; - } - resolve(cache4.hands); - }); -} - -// src/result.ts -var empty = (error = null) => ({ face: [], body: [], hand: [], gesture: [], object: [], persons: [], performance: {}, timestamp: 0, width: 0, height: 0, error }); - -// src/body/movenetcoords.ts -var movenetcoords_exports = {}; -__export(movenetcoords_exports, { - connected: () => connected3, - horizontal: () => horizontal, - kpt: () => kpt3, - relative: () => relative, - vertical: () => vertical -}); -var kpt3 = [ - "nose", - "leftEye", - "rightEye", - "leftEar", - "rightEar", - "leftShoulder", - "rightShoulder", - "leftElbow", - "rightElbow", - "leftWrist", - "rightWrist", - "leftHip", - "rightHip", - "leftKnee", - "rightKnee", - "leftAnkle", - "rightAnkle" -]; -var horizontal = [ - ["leftEye", "rightEye"], - ["leftEar", "rightEar"], - ["leftShoulder", "rightShoulder"], - ["leftElbow", "rightElbow"], - ["leftWrist", "rightWrist"], - ["leftHip", "rightHip"], - ["leftKnee", "rightKnee"], - ["leftAnkle", "rightAnkle"] -]; -var vertical = [ - ["leftKnee", "leftShoulder"], - ["rightKnee", "rightShoulder"], - ["leftAnkle", "leftKnee"], - ["rightAnkle", "rightKnee"] -]; -var relative = [ - [["leftHip", "rightHip"], ["leftShoulder", "rightShoulder"]], - [["leftElbow", "rightElbow"], ["leftShoulder", "rightShoulder"]] -]; -var connected3 = { - leftLeg: ["leftHip", "leftKnee", "leftAnkle"], - rightLeg: ["rightHip", "rightKnee", "rightAnkle"], - torso: ["leftShoulder", "rightShoulder", "rightHip", "leftHip", "leftShoulder"], - leftArm: ["leftShoulder", "leftElbow", "leftWrist"], - rightArm: ["rightShoulder", "rightElbow", "rightWrist"], - head: [] -}; - -// src/util/interpolate.ts -var bufferedResult = empty(); -var interpolateTime = 0; -function calc2(newResult, config3) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w; - const t0 = now(); - if (!newResult) - return empty(); - const elapsed = Date.now() - newResult.timestamp; - const bufferedFactor = elapsed < 1e3 ? 8 - Math.log(elapsed + 1) : 1; - if (newResult.canvas) - bufferedResult.canvas = newResult.canvas; - if (newResult.error) - bufferedResult.error = newResult.error; - if (!bufferedResult.body || newResult.body.length !== bufferedResult.body.length) { - bufferedResult.body = JSON.parse(JSON.stringify(newResult.body)); - } else { - for (let i = 0; i < newResult.body.length; i++) { - const box = newResult.body[i].box.map((newBoxCoord, j) => ((bufferedFactor - 1) * bufferedResult.body[i].box[j] + newBoxCoord) / bufferedFactor); - const boxRaw = newResult.body[i].boxRaw.map((newBoxCoord, j) => ((bufferedFactor - 1) * bufferedResult.body[i].boxRaw[j] + newBoxCoord) / bufferedFactor); - const keypoints = newResult.body[i].keypoints.map((newKpt, j) => { - var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2; - return { - score: newKpt.score, - part: newKpt.part, - position: [ - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].position[0] || 0) + (newKpt.position[0] || 0)) / bufferedFactor : newKpt.position[0], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].position[1] || 0) + (newKpt.position[1] || 0)) / bufferedFactor : newKpt.position[1], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].position[2] || 0) + (newKpt.position[2] || 0)) / bufferedFactor : newKpt.position[2] - ], - positionRaw: [ - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].positionRaw[0] || 0) + (newKpt.positionRaw[0] || 0)) / bufferedFactor : newKpt.positionRaw[0], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].positionRaw[1] || 0) + (newKpt.positionRaw[1] || 0)) / bufferedFactor : newKpt.positionRaw[1], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].positionRaw[2] || 0) + (newKpt.positionRaw[2] || 0)) / bufferedFactor : newKpt.positionRaw[2] - ], - distance: [ - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (((_a2 = bufferedResult.body[i].keypoints[j].distance) == null ? void 0 : _a2[0]) || 0) + (((_b2 = newKpt.distance) == null ? void 0 : _b2[0]) || 0)) / bufferedFactor : (_c2 = newKpt.distance) == null ? void 0 : _c2[0], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (((_d2 = bufferedResult.body[i].keypoints[j].distance) == null ? void 0 : _d2[1]) || 0) + (((_e2 = newKpt.distance) == null ? void 0 : _e2[1]) || 0)) / bufferedFactor : (_f2 = newKpt.distance) == null ? void 0 : _f2[1], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (((_g2 = bufferedResult.body[i].keypoints[j].distance) == null ? void 0 : _g2[2]) || 0) + (((_h2 = newKpt.distance) == null ? void 0 : _h2[2]) || 0)) / bufferedFactor : (_i2 = newKpt.distance) == null ? void 0 : _i2[2] - ] - }; - }); - const annotations2 = {}; - let coords = { connected: {} }; - if ((_a = config3.body.modelPath) == null ? void 0 : _a.includes("efficientpose")) - coords = efficientposecoords_exports; - else if ((_b = config3.body.modelPath) == null ? void 0 : _b.includes("blazepose")) - coords = blazeposecoords_exports; - else if ((_c = config3.body.modelPath) == null ? void 0 : _c.includes("movenet")) - coords = movenetcoords_exports; - for (const [name, indexes] of Object.entries(coords.connected)) { - const pt = []; - for (let j = 0; j < indexes.length - 1; j++) { - const pt0 = keypoints.find((kp) => kp.part === indexes[j]); - const pt1 = keypoints.find((kp) => kp.part === indexes[j + 1]); - if (pt0 && pt1) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - bufferedResult.body[i] = { ...newResult.body[i], box, boxRaw, keypoints, annotations: annotations2 }; - } - } - if (!bufferedResult.hand || newResult.hand.length !== bufferedResult.hand.length) { - bufferedResult.hand = JSON.parse(JSON.stringify(newResult.hand)); - } else { - for (let i = 0; i < newResult.hand.length; i++) { - const box = newResult.hand[i].box.map((b, j) => ((bufferedFactor - 1) * bufferedResult.hand[i].box[j] + b) / bufferedFactor); - const boxRaw = newResult.hand[i].boxRaw.map((b, j) => ((bufferedFactor - 1) * bufferedResult.hand[i].boxRaw[j] + b) / bufferedFactor); - if (bufferedResult.hand[i].keypoints.length !== newResult.hand[i].keypoints.length) - bufferedResult.hand[i].keypoints = newResult.hand[i].keypoints; - const keypoints = newResult.hand[i].keypoints && newResult.hand[i].keypoints.length > 0 ? newResult.hand[i].keypoints.map((landmark, j) => landmark.map((coord, k) => ((bufferedFactor - 1) * (bufferedResult.hand[i].keypoints[j][k] || 1) + (coord || 0)) / bufferedFactor)) : []; - let annotations2 = {}; - if (Object.keys(bufferedResult.hand[i].annotations).length !== Object.keys(newResult.hand[i].annotations).length) { - bufferedResult.hand[i].annotations = newResult.hand[i].annotations; - annotations2 = bufferedResult.hand[i].annotations; - } else if (newResult.hand[i].annotations) { - for (const key of Object.keys(newResult.hand[i].annotations)) { - annotations2[key] = ((_f = (_e = (_d = newResult.hand[i]) == null ? void 0 : _d.annotations) == null ? void 0 : _e[key]) == null ? void 0 : _f[0]) ? newResult.hand[i].annotations[key].map((val, j) => val.map((coord, k) => ((bufferedFactor - 1) * bufferedResult.hand[i].annotations[key][j][k] + coord) / bufferedFactor)) : null; - } - } - bufferedResult.hand[i] = { ...newResult.hand[i], box, boxRaw, keypoints, annotations: annotations2 }; - } - } - if (!bufferedResult.face || newResult.face.length !== bufferedResult.face.length) { - bufferedResult.face = JSON.parse(JSON.stringify(newResult.face)); - } else { - for (let i = 0; i < newResult.face.length; i++) { - const box = newResult.face[i].box.map((b, j) => ((bufferedFactor - 1) * bufferedResult.face[i].box[j] + b) / bufferedFactor); - const boxRaw = newResult.face[i].boxRaw.map((b, j) => ((bufferedFactor - 1) * bufferedResult.face[i].boxRaw[j] + b) / bufferedFactor); - if (newResult.face[i].rotation) { - const rotation = { matrix: [0, 0, 0, 0, 0, 0, 0, 0, 0], angle: { roll: 0, yaw: 0, pitch: 0 }, gaze: { bearing: 0, strength: 0 } }; - rotation.matrix = (_g = newResult.face[i].rotation) == null ? void 0 : _g.matrix; - rotation.angle = { - roll: ((bufferedFactor - 1) * (((_i = (_h = bufferedResult.face[i].rotation) == null ? void 0 : _h.angle) == null ? void 0 : _i.roll) || 0) + (((_k = (_j = newResult.face[i].rotation) == null ? void 0 : _j.angle) == null ? void 0 : _k.roll) || 0)) / bufferedFactor, - yaw: ((bufferedFactor - 1) * (((_m = (_l = bufferedResult.face[i].rotation) == null ? void 0 : _l.angle) == null ? void 0 : _m.yaw) || 0) + (((_o = (_n = newResult.face[i].rotation) == null ? void 0 : _n.angle) == null ? void 0 : _o.yaw) || 0)) / bufferedFactor, - pitch: ((bufferedFactor - 1) * (((_q = (_p = bufferedResult.face[i].rotation) == null ? void 0 : _p.angle) == null ? void 0 : _q.pitch) || 0) + (((_s = (_r = newResult.face[i].rotation) == null ? void 0 : _r.angle) == null ? void 0 : _s.pitch) || 0)) / bufferedFactor - }; - rotation.gaze = { - bearing: ((bufferedFactor - 1) * (((_t = bufferedResult.face[i].rotation) == null ? void 0 : _t.gaze.bearing) || 0) + (((_u = newResult.face[i].rotation) == null ? void 0 : _u.gaze.bearing) || 0)) / bufferedFactor, - strength: ((bufferedFactor - 1) * (((_v = bufferedResult.face[i].rotation) == null ? void 0 : _v.gaze.strength) || 0) + (((_w = newResult.face[i].rotation) == null ? void 0 : _w.gaze.strength) || 0)) / bufferedFactor - }; - bufferedResult.face[i] = { ...newResult.face[i], rotation, box, boxRaw }; - } else { - bufferedResult.face[i] = { ...newResult.face[i], box, boxRaw }; - } - } - } - if (!bufferedResult.object || newResult.object.length !== bufferedResult.object.length) { - bufferedResult.object = JSON.parse(JSON.stringify(newResult.object)); - } else { - for (let i = 0; i < newResult.object.length; i++) { - const box = newResult.object[i].box.map((b, j) => ((bufferedFactor - 1) * bufferedResult.object[i].box[j] + b) / bufferedFactor); - const boxRaw = newResult.object[i].boxRaw.map((b, j) => ((bufferedFactor - 1) * bufferedResult.object[i].boxRaw[j] + b) / bufferedFactor); - bufferedResult.object[i] = { ...newResult.object[i], box, boxRaw }; - } - } - if (newResult.persons) { - const newPersons = newResult.persons; - if (!bufferedResult.persons || newPersons.length !== bufferedResult.persons.length) { - bufferedResult.persons = JSON.parse(JSON.stringify(newPersons)); - } else { - for (let i = 0; i < newPersons.length; i++) { - bufferedResult.persons[i].box = newPersons[i].box.map((box, j) => ((bufferedFactor - 1) * bufferedResult.persons[i].box[j] + box) / bufferedFactor); - } - } - } - if (newResult.gesture) - bufferedResult.gesture = newResult.gesture; - bufferedResult.width = newResult.width; - bufferedResult.height = newResult.height; - const t1 = now(); - interpolateTime = env.perfadd ? interpolateTime + Math.round(t1 - t0) : Math.round(t1 - t0); - if (newResult.performance) - bufferedResult.performance = { ...newResult.performance, interpolate: interpolateTime }; - return bufferedResult; -} - -// src/segmentation/meet.ts -var tf30 = __toESM(require_tfjs_esm()); -var model17; -async function load16(config3) { - if (!model17 || env.initial) - model17 = await loadModel(config3.segmentation.modelPath); - else if (config3.debug) - log("cached model:", model17["modelUrl"]); - return model17; -} -async function predict16(input, config3) { - var _a; - if (!model17) - model17 = await load16(config3); - if (!(model17 == null ? void 0 : model17["executor"]) || !((_a = model17 == null ? void 0 : model17.inputs) == null ? void 0 : _a[0].shape)) - return null; - const t2 = {}; - t2.resize = tf30.image.resizeBilinear(input, [model17.inputs[0].shape ? model17.inputs[0].shape[1] : 0, model17.inputs[0].shape ? model17.inputs[0].shape[2] : 0], false); - t2.norm = tf30.div(t2.resize, constants.tf255); - t2.res = model17.execute(t2.norm); - t2.squeeze = tf30.squeeze(t2.res, [0]); - [t2.bgRaw, t2.fgRaw] = tf30.unstack(t2.squeeze, 2); - t2.fg = tf30.softmax(t2.fgRaw); - t2.mul = tf30.mul(t2.fg, constants.tf255); - t2.expand = tf30.expandDims(t2.mul, 2); - t2.output = tf30.image.resizeBilinear(t2.expand, [input.shape[1] || 0, input.shape[2] || 0]); - let rgba; - switch (config3.segmentation.mode || "default") { - case "default": - t2.input = tf30.squeeze(input); - t2.concat = tf30.concat([t2.input, t2.output], -1); - rgba = tf30.cast(t2.concat, "int32"); - break; - case "alpha": - rgba = tf30.cast(t2.output, "int32"); - break; - default: - rgba = tf30.tensor(0); - } - Object.keys(t2).forEach((tensor6) => tf30.dispose(t2[tensor6])); - return rgba; -} - -// src/face/match.ts -var match_exports = {}; -__export(match_exports, { - distance: () => distance, - find: () => find, - similarity: () => similarity -}); -function distance(descriptor1, descriptor2, options4 = { order: 2, multiplier: 25 }) { - if (!descriptor1 || !descriptor1) - return Number.MAX_SAFE_INTEGER; - let sum3 = 0; - for (let i = 0; i < descriptor1.length; i++) { - const diff = !options4.order || options4.order === 2 ? descriptor1[i] - descriptor2[i] : Math.abs(descriptor1[i] - descriptor2[i]); - sum3 += !options4.order || options4.order === 2 ? diff * diff : diff ** options4.order; - } - return (options4.multiplier || 20) * sum3; -} -var normalizeDistance = (dist, order, min2, max5) => { - if (dist === 0) - return 1; - const root = order === 2 ? Math.sqrt(dist) : dist ** (1 / order); - const norm = (1 - root / 100 - min2) / (max5 - min2); - const clamp2 = Math.max(Math.min(norm, 1), 0); - return clamp2; -}; -function similarity(descriptor1, descriptor2, options4 = { order: 2, multiplier: 25, min: 0.2, max: 0.8 }) { - const dist = distance(descriptor1, descriptor2, options4); - return normalizeDistance(dist, options4.order || 2, options4.min || 0, options4.max || 1); -} -function find(descriptor, descriptors, options4 = { order: 2, multiplier: 25, threshold: 0, min: 0.2, max: 0.8 }) { - if (!Array.isArray(descriptor) || !Array.isArray(descriptors) || descriptor.length < 64 || descriptors.length === 0) { - return { index: -1, distance: Number.POSITIVE_INFINITY, similarity: 0 }; - } - let lowestDistance = Number.MAX_SAFE_INTEGER; - let index2 = -1; - for (let i = 0; i < descriptors.length; i++) { - const res = descriptors[i].length === descriptor.length ? distance(descriptor, descriptors[i], options4) : Number.MAX_SAFE_INTEGER; - if (res < lowestDistance) { - lowestDistance = res; - index2 = i; - } - if (lowestDistance < (options4.threshold || 0)) - break; - } - const normalizedSimilarity = normalizeDistance(lowestDistance, options4.order || 2, options4.min || 0, options4.max || 1); - return { index: index2, distance: lowestDistance, similarity: normalizedSimilarity }; -} - -// src/models.ts -var models_exports2 = {}; -__export(models_exports2, { - Models: () => Models, - validateModel: () => validateModel -}); - -// src/body/movenet.ts -var tf32 = __toESM(require_tfjs_esm()); - -// src/body/movenetfix.ts -var tf31 = __toESM(require_tfjs_esm()); -var maxJitter = 5e-3; -var cache5 = { - keypoints: [], - padding: [[0, 0], [0, 0], [0, 0], [0, 0]] -}; -function bodyParts(body4) { - for (const pair of horizontal) { - const left = body4.keypoints.findIndex((kp) => kp.part === pair[0]); - const right = body4.keypoints.findIndex((kp) => kp.part === pair[1]); - if (body4.keypoints[left] && body4.keypoints[right]) { - if (body4.keypoints[left].position[0] < body4.keypoints[right].position[0]) { - const tmp = body4.keypoints[left]; - body4.keypoints[left] = body4.keypoints[right]; - body4.keypoints[right] = tmp; - } - } - } - for (const pair of vertical) { - const lower = body4.keypoints.findIndex((kp) => kp && kp.part === pair[0]); - const higher = body4.keypoints.findIndex((kp) => kp && kp.part === pair[1]); - if (body4.keypoints[lower] && body4.keypoints[higher]) { - if (body4.keypoints[lower].position[1] < body4.keypoints[higher].position[1]) { - body4.keypoints.splice(lower, 1); - } - } - } - for (const [pair, compare2] of relative) { - const left = body4.keypoints.findIndex((kp) => kp && kp.part === pair[0]); - const right = body4.keypoints.findIndex((kp) => kp && kp.part === pair[1]); - const leftTo = body4.keypoints.findIndex((kp) => kp && kp.part === compare2[0]); - const rightTo = body4.keypoints.findIndex((kp) => kp && kp.part === compare2[1]); - if (!body4.keypoints[leftTo] || !body4.keypoints[rightTo]) - continue; - const distanceLeft = body4.keypoints[left] ? [ - Math.abs(body4.keypoints[leftTo].position[0] - body4.keypoints[left].position[0]), - Math.abs(body4.keypoints[rightTo].position[0] - body4.keypoints[left].position[0]) - ] : [0, 0]; - const distanceRight = body4.keypoints[right] ? [ - Math.abs(body4.keypoints[rightTo].position[0] - body4.keypoints[right].position[0]), - Math.abs(body4.keypoints[leftTo].position[0] - body4.keypoints[right].position[0]) - ] : [0, 0]; - if (distanceLeft[0] > distanceLeft[1] || distanceRight[0] > distanceRight[1]) { - const tmp = body4.keypoints[left]; - body4.keypoints[left] = body4.keypoints[right]; - body4.keypoints[right] = tmp; - } - } -} -function jitter(keypoints) { - for (let i = 0; i < keypoints.length; i++) { - if (keypoints[i] && cache5.keypoints[i]) { - const diff = [Math.abs(keypoints[i].positionRaw[0] - cache5.keypoints[i].positionRaw[0]), Math.abs(keypoints[i].positionRaw[1] - cache5.keypoints[i].positionRaw[1])]; - if (diff[0] < maxJitter && diff[1] < maxJitter) { - keypoints[i] = cache5.keypoints[i]; - } else { - cache5.keypoints[i] = keypoints[i]; - } - } else { - cache5.keypoints[i] = keypoints[i]; - } - } - return keypoints; -} -function padInput(input, inputSize10) { - var _a, _b; - const t2 = {}; - if (!((_a = input == null ? void 0 : input.shape) == null ? void 0 : _a[1]) || !((_b = input == null ? void 0 : input.shape) == null ? void 0 : _b[2])) - return input; - cache5.padding = [ - [0, 0], - [input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0, input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0], - [input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0, input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0], - [0, 0] - ]; - t2.pad = tf31.pad(input, cache5.padding); - t2.resize = tf31.image.resizeBilinear(t2.pad, [inputSize10, inputSize10]); - const final = tf31.cast(t2.resize, "int32"); - Object.keys(t2).forEach((tensor6) => tf31.dispose(t2[tensor6])); - return final; -} -function rescaleBody(body4, outputSize2) { - body4.keypoints = body4.keypoints.filter((kpt4) => kpt4 == null ? void 0 : kpt4.position); - for (const kpt4 of body4.keypoints) { - kpt4.position = [ - kpt4.position[0] * (outputSize2[0] + cache5.padding[2][0] + cache5.padding[2][1]) / outputSize2[0] - cache5.padding[2][0], - kpt4.position[1] * (outputSize2[1] + cache5.padding[1][0] + cache5.padding[1][1]) / outputSize2[1] - cache5.padding[1][0] - ]; - kpt4.positionRaw = [ - kpt4.position[0] / outputSize2[0], - kpt4.position[1] / outputSize2[1] - ]; - } - const rescaledBoxes = calc(body4.keypoints.map((pt) => pt.position), outputSize2); - body4.box = rescaledBoxes.box; - body4.boxRaw = rescaledBoxes.boxRaw; - return body4; -} - -// src/body/movenet.ts -var model18; -var inputSize8 = 0; -var skipped14 = Number.MAX_SAFE_INTEGER; -var cache6 = { - boxes: [], - bodies: [], - last: 0 -}; -async function load17(config3) { - var _a; - if (env.initial) - model18 = null; - if (!model18) { - fakeOps(["size"], config3); - model18 = await loadModel(config3.body.modelPath); - } else if (config3.debug) - log("cached model:", model18["modelUrl"]); - inputSize8 = (model18 == null ? void 0 : model18["executor"]) && ((_a = model18 == null ? void 0 : model18.inputs) == null ? void 0 : _a[0].shape) ? model18.inputs[0].shape[2] : 0; - if (inputSize8 < 64) - inputSize8 = 256; - return model18; -} -function parseSinglePose(res, config3, image28) { - const kpt4 = res[0][0]; - const keypoints = []; - let score = 0; - for (let id = 0; id < kpt4.length; id++) { - score = kpt4[id][2]; - if (score > config3.body.minConfidence) { - const positionRaw = [kpt4[id][1], kpt4[id][0]]; - keypoints.push({ - score: Math.round(100 * score) / 100, - part: kpt3[id], - positionRaw, - position: [ - Math.round((image28.shape[2] || 0) * positionRaw[0]), - Math.round((image28.shape[1] || 0) * positionRaw[1]) - ] - }); - } - } - score = keypoints.reduce((prev, curr) => curr.score > prev ? curr.score : prev, 0); - const bodies = []; - const newBox = calc(keypoints.map((pt) => pt.position), [image28.shape[2], image28.shape[1]]); - const annotations2 = {}; - for (const [name, indexes] of Object.entries(connected3)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = keypoints.find((kp) => kp.part === indexes[i]); - const pt1 = keypoints.find((kp) => kp.part === indexes[i + 1]); - if (pt0 && pt1 && pt0.score > (config3.body.minConfidence || 0) && pt1.score > (config3.body.minConfidence || 0)) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - const body4 = { id: 0, score, box: newBox.box, boxRaw: newBox.boxRaw, keypoints, annotations: annotations2 }; - bodyParts(body4); - bodies.push(body4); - return bodies; -} -function parseMultiPose(res, config3, image28) { - const bodies = []; - for (let id = 0; id < res[0].length; id++) { - const kpt4 = res[0][id]; - const totalScore = Math.round(100 * kpt4[51 + 4]) / 100; - if (totalScore > config3.body.minConfidence) { - const keypoints = []; - for (let i = 0; i < 17; i++) { - const score = kpt4[3 * i + 2]; - if (score > config3.body.minConfidence) { - const positionRaw = [kpt4[3 * i + 1], kpt4[3 * i + 0]]; - keypoints.push({ - part: kpt3[i], - score: Math.round(100 * score) / 100, - positionRaw, - position: [Math.round((image28.shape[2] || 0) * positionRaw[0]), Math.round((image28.shape[1] || 0) * positionRaw[1])] - }); - } - } - const newBox = calc(keypoints.map((pt) => pt.position), [image28.shape[2], image28.shape[1]]); - const annotations2 = {}; - for (const [name, indexes] of Object.entries(connected3)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = keypoints.find((kp) => kp.part === indexes[i]); - const pt1 = keypoints.find((kp) => kp.part === indexes[i + 1]); - if (pt0 && pt1 && pt0.score > (config3.body.minConfidence || 0) && pt1.score > (config3.body.minConfidence || 0)) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - const body4 = { id, score: totalScore, box: newBox.box, boxRaw: newBox.boxRaw, keypoints: [...keypoints], annotations: annotations2 }; - bodyParts(body4); - bodies.push(body4); - } - } - bodies.sort((a, b) => b.score - a.score); - if (bodies.length > config3.body.maxDetected) - bodies.length = config3.body.maxDetected; - return bodies; -} -async function predict17(input, config3) { - var _a; - if (!(model18 == null ? void 0 : model18["executor"]) || !((_a = model18 == null ? void 0 : model18.inputs) == null ? void 0 : _a[0].shape)) - return []; - if (!config3.skipAllowed) - cache6.boxes.length = 0; - skipped14++; - const skipTime = (config3.body.skipTime || 0) > now() - cache6.last; - const skipFrame = skipped14 < (config3.body.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame) { - return cache6.bodies; - } - return new Promise(async (resolve) => { - const t2 = {}; - skipped14 = 0; - t2.input = padInput(input, inputSize8); - t2.res = model18 == null ? void 0 : model18.execute(t2.input); - cache6.last = now(); - const res = await t2.res.array(); - cache6.bodies = t2.res.shape[2] === 17 ? parseSinglePose(res, config3, input) : parseMultiPose(res, config3, input); - for (const body4 of cache6.bodies) { - rescaleBody(body4, [input.shape[2] || 1, input.shape[1] || 1]); - jitter(body4.keypoints); - } - Object.keys(t2).forEach((tensor6) => tf32.dispose(t2[tensor6])); - resolve(cache6.bodies); - }); -} - -// src/object/nanodet.ts -var tf33 = __toESM(require_tfjs_esm()); -var model19; -var last10 = []; -var lastTime15 = 0; -var skipped15 = Number.MAX_SAFE_INTEGER; -var inputSize9 = 0; -var scaleBox = 2.5; -async function load18(config3) { - if (!model19 || env.initial) { - model19 = await loadModel(config3.object.modelPath); - const inputs = (model19 == null ? void 0 : model19["executor"]) ? Object.values(model19.modelSignature["inputs"]) : void 0; - inputSize9 = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 416; - } else if (config3.debug) - log("cached model:", model19["modelUrl"]); - return model19; -} -async function process4(res, outputShape, config3) { - var _a, _b; - let id = 0; - let results = []; - const size2 = inputSize9; - for (const strideSize of [1, 2, 4]) { - const baseSize = strideSize * 13; - const scoresT = tf33.squeeze(res.find((a) => a.shape[1] === baseSize ** 2 && (a.shape[2] || 0) === labels2.length)); - const scores = await scoresT.array(); - const featuresT = tf33.squeeze(res.find((a) => a.shape[1] === baseSize ** 2 && (a.shape[2] || 0) < labels2.length)); - const boxesMaxT = tf33.reshape(featuresT, [-1, 4, (((_a = featuresT.shape) == null ? void 0 : _a[1]) || 0) / 4]); - const boxIdxT = tf33.argMax(boxesMaxT, 2); - const boxIdx = await boxIdxT.array(); - for (let i = 0; i < scoresT.shape[0]; i++) { - for (let j = 0; j < (((_b = scoresT.shape) == null ? void 0 : _b[1]) || 0); j++) { - const score = scores[i][j]; - if (score > (config3.object.minConfidence || 0) && j !== 61) { - const cx = (0.5 + Math.trunc(i % baseSize)) / baseSize; - const cy = (0.5 + Math.trunc(i / baseSize)) / baseSize; - const boxOffset = boxIdx[i].map((a) => a * (baseSize / strideSize / size2)); - const [x, y] = [ - cx - scaleBox / strideSize * boxOffset[0], - cy - scaleBox / strideSize * boxOffset[1] - ]; - const [w, h] = [ - cx + scaleBox / strideSize * boxOffset[2] - x, - cy + scaleBox / strideSize * boxOffset[3] - y - ]; - let boxRaw = [x, y, w, h]; - boxRaw = boxRaw.map((a) => Math.max(0, Math.min(a, 1))); - const box = [ - boxRaw[0] * outputShape[0], - boxRaw[1] * outputShape[1], - boxRaw[2] * outputShape[0], - boxRaw[3] * outputShape[1] - ]; - const result = { - id: id++, - score: Math.round(100 * score) / 100, - class: j + 1, - label: labels2[j].label, - box: box.map((a) => Math.trunc(a)), - boxRaw - }; - results.push(result); - } - } - } - tf33.dispose([scoresT, featuresT, boxesMaxT, boxIdxT]); - } - const nmsBoxes = results.map((a) => [a.boxRaw[1], a.boxRaw[0], a.boxRaw[3], a.boxRaw[2]]); - const nmsScores = results.map((a) => a.score); - let nmsIdx = []; - if (nmsBoxes && nmsBoxes.length > 0) { - const nms = await tf33.image.nonMaxSuppressionAsync(nmsBoxes, nmsScores, config3.object.maxDetected || 0, config3.object.iouThreshold, config3.object.minConfidence); - nmsIdx = Array.from(await nms.data()); - tf33.dispose(nms); - } - results = results.filter((_val, idx) => nmsIdx.includes(idx)).sort((a, b) => b.score - a.score); - return results; -} -async function predict18(image28, config3) { - if (!(model19 == null ? void 0 : model19["executor"])) - return []; - const skipTime = (config3.object.skipTime || 0) > now() - lastTime15; - const skipFrame = skipped15 < (config3.object.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && last10.length > 0) { - skipped15++; - return last10; - } - skipped15 = 0; - if (!env.kernels.includes("mod") || !env.kernels.includes("sparsetodense")) - return last10; - return new Promise(async (resolve) => { - const outputSize2 = [image28.shape[2] || 0, image28.shape[1] || 0]; - const resizeT = tf33.image.resizeBilinear(image28, [inputSize9, inputSize9], false); - const normT = tf33.div(resizeT, constants.tf255); - const transposeT = tf33.transpose(normT, [0, 3, 1, 2]); - let objectT; - if (config3.object.enabled) - objectT = model19.execute(transposeT); - lastTime15 = now(); - const obj = await process4(objectT, outputSize2, config3); - last10 = obj; - tf33.dispose([resizeT, normT, transposeT, ...objectT]); - resolve(obj); - }); -} - -// src/body/posenet.ts -var tf34 = __toESM(require_tfjs_esm()); - -// src/body/posenetutils.ts -var partNames = [ - "nose", - "leftEye", - "rightEye", - "leftEar", - "rightEar", - "leftShoulder", - "rightShoulder", - "leftElbow", - "rightElbow", - "leftWrist", - "rightWrist", - "leftHip", - "rightHip", - "leftKnee", - "rightKnee", - "leftAnkle", - "rightAnkle" -]; -var count = partNames.length; -var partIds = partNames.reduce((result, jointName, i) => { - result[jointName] = i; - return result; -}, {}); -var connectedPartNames = [ - ["leftHip", "leftShoulder"], - ["leftElbow", "leftShoulder"], - ["leftElbow", "leftWrist"], - ["leftHip", "leftKnee"], - ["leftKnee", "leftAnkle"], - ["rightHip", "rightShoulder"], - ["rightElbow", "rightShoulder"], - ["rightElbow", "rightWrist"], - ["rightHip", "rightKnee"], - ["rightKnee", "rightAnkle"], - ["leftShoulder", "rightShoulder"], - ["leftHip", "rightHip"] -]; -var connectedPartIndices = connectedPartNames.map(([jointNameA, jointNameB]) => [partIds[jointNameA], partIds[jointNameB]]); -var poseChain = [ - ["nose", "leftEye"], - ["leftEye", "leftEar"], - ["nose", "rightEye"], - ["rightEye", "rightEar"], - ["nose", "leftShoulder"], - ["leftShoulder", "leftElbow"], - ["leftElbow", "leftWrist"], - ["leftShoulder", "leftHip"], - ["leftHip", "leftKnee"], - ["leftKnee", "leftAnkle"], - ["nose", "rightShoulder"], - ["rightShoulder", "rightElbow"], - ["rightElbow", "rightWrist"], - ["rightShoulder", "rightHip"], - ["rightHip", "rightKnee"], - ["rightKnee", "rightAnkle"] -]; -function getBoundingBox(keypoints) { - const coord = keypoints.reduce(({ maxX, maxY, minX, minY }, { position: { x, y } }) => ({ - maxX: Math.max(maxX, x), - maxY: Math.max(maxY, y), - minX: Math.min(minX, x), - minY: Math.min(minY, y) - }), { - maxX: Number.NEGATIVE_INFINITY, - maxY: Number.NEGATIVE_INFINITY, - minX: Number.POSITIVE_INFINITY, - minY: Number.POSITIVE_INFINITY - }); - return [coord.minX, coord.minY, coord.maxX - coord.minX, coord.maxY - coord.minY]; -} -function scalePoses(poses, [height, width], [inputResolutionHeight, inputResolutionWidth]) { - const scaleY = height / inputResolutionHeight; - const scaleX = width / inputResolutionWidth; - const scalePose = (pose, i) => ({ - id: i, - score: pose.score, - boxRaw: [pose.box[0] / inputResolutionWidth, pose.box[1] / inputResolutionHeight, pose.box[2] / inputResolutionWidth, pose.box[3] / inputResolutionHeight], - box: [Math.trunc(pose.box[0] * scaleX), Math.trunc(pose.box[1] * scaleY), Math.trunc(pose.box[2] * scaleX), Math.trunc(pose.box[3] * scaleY)], - keypoints: pose.keypoints.map(({ score, part, position }) => ({ - score, - part, - position: [Math.trunc(position.x * scaleX), Math.trunc(position.y * scaleY)], - positionRaw: [position.x / inputResolutionHeight, position.y / inputResolutionHeight] - })), - annotations: {} - }); - const scaledPoses = poses.map((pose, i) => scalePose(pose, i)); - return scaledPoses; -} -var MaxHeap = class { - constructor(maxSize2, getElementValue) { - __publicField(this, "priorityQueue"); - __publicField(this, "numberOfElements"); - __publicField(this, "getElementValue"); - this.priorityQueue = new Array(maxSize2); - this.numberOfElements = -1; - this.getElementValue = getElementValue; - } - enqueue(x) { - this.priorityQueue[++this.numberOfElements] = x; - this.swim(this.numberOfElements); - } - dequeue() { - const max5 = this.priorityQueue[0]; - this.exchange(0, this.numberOfElements--); - this.sink(0); - this.priorityQueue[this.numberOfElements + 1] = null; - return max5; - } - empty() { - return this.numberOfElements === -1; - } - size() { - return this.numberOfElements + 1; - } - all() { - return this.priorityQueue.slice(0, this.numberOfElements + 1); - } - max() { - return this.priorityQueue[0]; - } - swim(k) { - while (k > 0 && this.less(Math.floor(k / 2), k)) { - this.exchange(k, Math.floor(k / 2)); - k = Math.floor(k / 2); - } - } - sink(k) { - while (2 * k <= this.numberOfElements) { - let j = 2 * k; - if (j < this.numberOfElements && this.less(j, j + 1)) - j++; - if (!this.less(k, j)) - break; - this.exchange(k, j); - k = j; - } - } - getValueAt(i) { - return this.getElementValue(this.priorityQueue[i]); - } - less(i, j) { - return this.getValueAt(i) < this.getValueAt(j); - } - exchange(i, j) { - const t2 = this.priorityQueue[i]; - this.priorityQueue[i] = this.priorityQueue[j]; - this.priorityQueue[j] = t2; - } -}; -function getOffsetPoint(y, x, keypoint, offsets) { - return { - y: offsets.get(y, x, keypoint), - x: offsets.get(y, x, keypoint + count) - }; -} -function getImageCoords(part, outputStride2, offsets) { - const { heatmapY, heatmapX, id: keypoint } = part; - const { y, x } = getOffsetPoint(heatmapY, heatmapX, keypoint, offsets); - return { - x: part.heatmapX * outputStride2 + x, - y: part.heatmapY * outputStride2 + y - }; -} -function clamp(a, min2, max5) { - if (a < min2) - return min2; - if (a > max5) - return max5; - return a; -} -function squaredDistance(y1, x1, y2, x2) { - const dy = y2 - y1; - const dx = x2 - x1; - return dy * dy + dx * dx; -} -function addVectors(a, b) { - return { x: a.x + b.x, y: a.y + b.y }; -} - -// src/body/posenet.ts -var model20; -var poseNetOutputs = ["MobilenetV1/offset_2/BiasAdd", "MobilenetV1/heatmap_2/BiasAdd", "MobilenetV1/displacement_fwd_2/BiasAdd", "MobilenetV1/displacement_bwd_2/BiasAdd"]; -var localMaximumRadius = 1; -var outputStride = 16; -var squaredNmsRadius = 50 ** 2; -function traverse(edgeId, sourceKeypoint, targetId, scores, offsets, displacements, offsetRefineStep = 2) { - const getDisplacement = (point2) => ({ - y: displacements.get(point2.y, point2.x, edgeId), - x: displacements.get(point2.y, point2.x, displacements.shape[2] / 2 + edgeId) - }); - const getStridedIndexNearPoint = (point2, height2, width2) => ({ - y: clamp(Math.round(point2.y / outputStride), 0, height2 - 1), - x: clamp(Math.round(point2.x / outputStride), 0, width2 - 1) - }); - const [height, width] = scores.shape; - const sourceKeypointIndices = getStridedIndexNearPoint(sourceKeypoint.position, height, width); - const displacement = getDisplacement(sourceKeypointIndices); - const displacedPoint = addVectors(sourceKeypoint.position, displacement); - let targetKeypoint = displacedPoint; - for (let i = 0; i < offsetRefineStep; i++) { - const targetKeypointIndices = getStridedIndexNearPoint(targetKeypoint, height, width); - const offsetPoint = getOffsetPoint(targetKeypointIndices.y, targetKeypointIndices.x, targetId, offsets); - targetKeypoint = addVectors( - { x: targetKeypointIndices.x * outputStride, y: targetKeypointIndices.y * outputStride }, - { x: offsetPoint.x, y: offsetPoint.y } - ); - } - const targetKeyPointIndices = getStridedIndexNearPoint(targetKeypoint, height, width); - const score = scores.get(targetKeyPointIndices.y, targetKeyPointIndices.x, targetId); - return { position: targetKeypoint, part: partNames[targetId], score }; -} -function decodePose(root, scores, offsets, displacementsFwd, displacementsBwd) { - const tuples = poseChain.map(([parentJoinName, childJoinName]) => [partIds[parentJoinName], partIds[childJoinName]]); - const edgesFwd = tuples.map(([, childJointId]) => childJointId); - const edgesBwd = tuples.map(([parentJointId]) => parentJointId); - const numParts = scores.shape[2]; - const numEdges = edgesFwd.length; - const keypoints = new Array(numParts); - const rootPoint = getImageCoords(root.part, outputStride, offsets); - keypoints[root.part.id] = { - score: root.score, - part: partNames[root.part.id], - position: rootPoint - }; - for (let edge = numEdges - 1; edge >= 0; --edge) { - const sourceId = edgesFwd[edge]; - const targetId = edgesBwd[edge]; - if (keypoints[sourceId] && !keypoints[targetId]) { - keypoints[targetId] = traverse(edge, keypoints[sourceId], targetId, scores, offsets, displacementsBwd); - } - } - for (let edge = 0; edge < numEdges; ++edge) { - const sourceId = edgesBwd[edge]; - const targetId = edgesFwd[edge]; - if (keypoints[sourceId] && !keypoints[targetId]) { - keypoints[targetId] = traverse(edge, keypoints[sourceId], targetId, scores, offsets, displacementsFwd); - } - } - return keypoints; -} -function scoreIsMaximumInLocalWindow(keypointId, score, heatmapY, heatmapX, scores) { - const [height, width] = scores.shape; - let localMaximum = true; - const yStart = Math.max(heatmapY - localMaximumRadius, 0); - const yEnd = Math.min(heatmapY + localMaximumRadius + 1, height); - for (let yCurrent = yStart; yCurrent < yEnd; ++yCurrent) { - const xStart = Math.max(heatmapX - localMaximumRadius, 0); - const xEnd = Math.min(heatmapX + localMaximumRadius + 1, width); - for (let xCurrent = xStart; xCurrent < xEnd; ++xCurrent) { - if (scores.get(yCurrent, xCurrent, keypointId) > score) { - localMaximum = false; - break; - } - } - if (!localMaximum) - break; - } - return localMaximum; -} -function buildPartWithScoreQueue(minConfidence2, scores) { - const [height, width, numKeypoints] = scores.shape; - const queue = new MaxHeap(height * width * numKeypoints, ({ score }) => score); - for (let heatmapY = 0; heatmapY < height; ++heatmapY) { - for (let heatmapX = 0; heatmapX < width; ++heatmapX) { - for (let keypointId = 0; keypointId < numKeypoints; ++keypointId) { - const score = scores.get(heatmapY, heatmapX, keypointId); - if (score < minConfidence2) - continue; - if (scoreIsMaximumInLocalWindow(keypointId, score, heatmapY, heatmapX, scores)) - queue.enqueue({ score, part: { heatmapY, heatmapX, id: keypointId } }); - } - } - } - return queue; -} -function withinRadius(poses, { x, y }, keypointId) { - return poses.some(({ keypoints }) => { - var _a; - const correspondingKeypoint = (_a = keypoints[keypointId]) == null ? void 0 : _a.position; - if (!correspondingKeypoint) - return false; - return squaredDistance(y, x, correspondingKeypoint.y, correspondingKeypoint.x) <= squaredNmsRadius; - }); -} -function getInstanceScore(existingPoses, keypoints) { - const notOverlappedKeypointScores = keypoints.reduce((result, { position, score }, keypointId) => { - if (!withinRadius(existingPoses, position, keypointId)) - result += score; - return result; - }, 0); - return notOverlappedKeypointScores / keypoints.length; -} -function decode(offsets, scores, displacementsFwd, displacementsBwd, maxDetected, minConfidence2) { - const poses = []; - const queue = buildPartWithScoreQueue(minConfidence2, scores); - while (poses.length < maxDetected && !queue.empty()) { - const root = queue.dequeue(); - const rootImageCoords = getImageCoords(root.part, outputStride, offsets); - if (withinRadius(poses, rootImageCoords, root.part.id)) - continue; - let keypoints = decodePose(root, scores, offsets, displacementsFwd, displacementsBwd); - keypoints = keypoints.filter((a) => a.score > minConfidence2); - const score = getInstanceScore(poses, keypoints); - const box = getBoundingBox(keypoints); - if (score > minConfidence2) - poses.push({ keypoints, box, score: Math.round(100 * score) / 100 }); - } - return poses; -} -async function predict19(input, config3) { - if (!(model20 == null ? void 0 : model20["executor"])) - return []; - const res = tf34.tidy(() => { - if (!model20.inputs[0].shape) - return []; - const resized = tf34.image.resizeBilinear(input, [model20.inputs[0].shape[2], model20.inputs[0].shape[1]]); - const normalized = tf34.sub(tf34.div(tf34.cast(resized, "float32"), 127.5), 1); - const results = model20.execute(normalized, poseNetOutputs); - const results3d = results.map((y) => tf34.squeeze(y, [0])); - results3d[1] = tf34.sigmoid(results3d[1]); - return results3d; - }); - const buffers = await Promise.all(res.map((tensor6) => tensor6.buffer())); - for (const t2 of res) - tf34.dispose(t2); - const decoded = decode(buffers[0], buffers[1], buffers[2], buffers[3], config3.body.maxDetected, config3.body.minConfidence); - if (!model20.inputs[0].shape) - return []; - const scaled = scalePoses(decoded, [input.shape[1], input.shape[2]], [model20.inputs[0].shape[2], model20.inputs[0].shape[1]]); - return scaled; -} -async function load19(config3) { - if (!model20 || env.initial) - model20 = await loadModel(config3.body.modelPath); - else if (config3.debug) - log("cached model:", model20["modelUrl"]); - return model20; -} - -// src/segmentation/rvm.ts -var tf35 = __toESM(require_tfjs_esm()); -var model21; -var outputNodes2 = ["fgr", "pha", "r1o", "r2o", "r3o", "r4o"]; -var t = {}; -var ratio = 0; -function init3(config3) { - tf35.dispose([t.r1i, t.r2i, t.r3i, t.r4i, t.downsample_ratio]); - t.r1i = tf35.tensor(0); - t.r2i = tf35.tensor(0); - t.r3i = tf35.tensor(0); - t.r4i = tf35.tensor(0); - ratio = config3.segmentation.ratio || 0.5; - t.downsample_ratio = tf35.tensor(ratio); -} -async function load20(config3) { - if (!model21 || env.initial) - model21 = await loadModel(config3.segmentation.modelPath); - else if (config3.debug) - log("cached model:", model21["modelUrl"]); - init3(config3); - return model21; -} -var normalize = (r) => tf35.tidy(() => { - const squeeze14 = tf35.squeeze(r, [0]); - const mul15 = tf35.mul(squeeze14, constants.tf255); - const cast8 = tf35.cast(mul15, "int32"); - return cast8; -}); -function getRGBA(fgr, pha) { - const rgb2 = fgr ? normalize(fgr) : tf35.fill([pha.shape[1] || 0, pha.shape[2] || 0, 3], 255, "int32"); - const a = pha ? normalize(pha) : tf35.fill([fgr.shape[1] || 0, fgr.shape[2] || 0, 1], 255, "int32"); - const rgba = tf35.concat([rgb2, a], -1); - tf35.dispose([rgb2, a]); - return rgba; -} -function getState(state) { - return tf35.tidy(() => { - const r = {}; - r.unstack = tf35.unstack(state, -1); - r.concat = tf35.concat(r.unstack, 1); - r.split = tf35.split(r.concat, 4, 1); - r.stack = tf35.concat(r.split, 2); - r.squeeze = tf35.squeeze(r.stack, [0]); - r.expand = tf35.expandDims(r.squeeze, -1); - r.add = tf35.add(r.expand, 1); - r.mul = tf35.mul(r.add, 127.5); - r.cast = tf35.cast(r.mul, "int32"); - r.tile = tf35.tile(r.cast, [1, 1, 3]); - r.alpha = tf35.fill([r.tile.shape[0] || 0, r.tile.shape[1] || 0, 1], 255, "int32"); - return tf35.concat([r.tile, r.alpha], -1); - }); -} -async function predict20(input, config3) { - if (!model21) - model21 = await load20(config3); - if (!(model21 == null ? void 0 : model21["executor"])) - return null; - t.src = tf35.div(input, 255); - if (ratio !== config3.segmentation.ratio) - init3(config3); - const [fgr, pha, r1o, r2o, r3o, r4o] = await model21.executeAsync(t, outputNodes2); - let rgba; - switch (config3.segmentation.mode || "default") { - case "default": - rgba = getRGBA(fgr, pha); - break; - case "alpha": - rgba = getRGBA(null, pha); - break; - case "foreground": - rgba = getRGBA(fgr, null); - break; - case "state": - rgba = getState(r1o); - break; - default: - rgba = tf35.tensor(0); - } - tf35.dispose([t.src, fgr, pha, t.r1i, t.r2i, t.r3i, t.r4i]); - [t.r1i, t.r2i, t.r3i, t.r4i] = [r1o, r2o, r3o, r4o]; - return rgba; -} - -// src/segmentation/selfie.ts -var tf36 = __toESM(require_tfjs_esm()); -var model22; -async function load21(config3) { - if (!model22 || env.initial) - model22 = await loadModel(config3.segmentation.modelPath); - else if (config3.debug) - log("cached model:", model22["modelUrl"]); - return model22; -} -async function predict21(input, config3) { - var _a; - if (!model22) - model22 = await load21(config3); - if (!(model22 == null ? void 0 : model22["executor"]) || !((_a = model22 == null ? void 0 : model22.inputs) == null ? void 0 : _a[0].shape)) - return null; - const t2 = {}; - t2.resize = tf36.image.resizeBilinear(input, [model22.inputs[0].shape ? model22.inputs[0].shape[1] : 0, model22.inputs[0].shape ? model22.inputs[0].shape[2] : 0], false); - t2.norm = tf36.div(t2.resize, constants.tf255); - t2.res = model22.execute(t2.norm); - t2.squeeze = tf36.squeeze(t2.res, [0]); - t2.alpha = tf36.image.resizeBilinear(t2.squeeze, [input.shape[1] || 0, input.shape[2] || 0]); - t2.mul = tf36.mul(t2.alpha, constants.tf255); - let rgba; - switch (config3.segmentation.mode || "default") { - case "default": - t2.input = tf36.squeeze(input); - t2.concat = tf36.concat([t2.input, t2.mul], -1); - rgba = tf36.cast(t2.concat, "int32"); - break; - case "alpha": - rgba = tf36.cast(t2.mul, "int32"); - break; - default: - rgba = tf36.tensor(0); - } - Object.keys(t2).forEach((tensor6) => tf36.dispose(t2[tensor6])); - return rgba; -} - -// src/models.ts -function validateModel(instance, model23, name) { - var _a, _b; - if (!model23) - return null; - if (!((_a = instance == null ? void 0 : instance.config) == null ? void 0 : _a.validateModels)) - return null; - const simpleOps = ["const", "placeholder", "noop", "pad", "squeeze", "add", "sub", "mul", "div"]; - const ignoreOps = ["biasadd", "fusedbatchnormv3", "matmul", "switch", "shape", "merge", "split", "broadcastto"]; - const ops = []; - const missing = []; - const url = model23["modelUrl"]; - const executor = model23["executor"]; - if ((_b = executor == null ? void 0 : executor.graph) == null ? void 0 : _b.nodes) { - for (const kernel of Object.values(executor.graph.nodes)) { - const op = kernel.op.toLowerCase(); - if (!ops.includes(op)) - ops.push(op); - } - } else { - if (!executor && instance.config.debug) { - log("model not loaded", name); - } - } - for (const op of ops) { - if (!simpleOps.includes(op) && !ignoreOps.includes(op) && !instance.env.kernels.includes(op) && !instance.env.kernels.includes(op.replace("_", "")) && !instance.env.kernels.includes(op.replace("native", "")) && !instance.env.kernels.includes(op.replace("v2", ""))) { - missing.push(op); - } - } - if (instance.config.debug && missing.length > 0) - log("model validation failed:", name, missing); - return missing.length > 0 ? { name, missing, ops, url } : null; -} -var Models = class { - constructor(currentInstance) { - __publicField(this, "instance"); - __publicField(this, "models", {}); - this.models = {}; - this.instance = currentInstance; - } - stats() { - let totalSizeFromManifest = 0; - let totalSizeWeights = 0; - let totalSizeLoading = 0; - for (const m of Object.values(modelStats)) { - totalSizeFromManifest += m.sizeFromManifest; - totalSizeWeights += m.sizeLoadedWeights; - totalSizeLoading += m.sizeDesired; - } - const percentageLoaded = totalSizeLoading > 0 ? totalSizeWeights / totalSizeLoading : 0; - return { - numLoadedModels: Object.values(modelStats).length, - numDefinedModels: Object.keys(this.models).length, - percentageLoaded, - totalSizeFromManifest, - totalSizeWeights, - totalSizeLoading, - modelStats: Object.values(modelStats) - }; - } - reset() { - for (const model23 of Object.keys(this.models)) - this.models[model23] = null; - } - async load(instance) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A; - if (env.initial) - this.reset(); - if (instance) - this.instance = instance; - const m = {}; - m.blazeface = this.instance.config.face.enabled && !this.models.blazeface ? load3(this.instance.config) : null; - m.antispoof = this.instance.config.face.enabled && ((_a = this.instance.config.face.antispoof) == null ? void 0 : _a.enabled) && !this.models.antispoof ? load8(this.instance.config) : null; - m.liveness = this.instance.config.face.enabled && ((_b = this.instance.config.face.liveness) == null ? void 0 : _b.enabled) && !this.models.liveness ? load9(this.instance.config) : null; - m.faceres = this.instance.config.face.enabled && ((_c = this.instance.config.face.description) == null ? void 0 : _c.enabled) && !this.models.faceres ? load7(this.instance.config) : null; - m.emotion = this.instance.config.face.enabled && ((_d = this.instance.config.face.emotion) == null ? void 0 : _d.enabled) && !this.models.emotion ? load6(this.instance.config) : null; - m.iris = this.instance.config.face.enabled && ((_e = this.instance.config.face.iris) == null ? void 0 : _e.enabled) && !((_f = this.instance.config.face.attention) == null ? void 0 : _f.enabled) && !this.models.iris ? load4(this.instance.config) : null; - m.facemesh = this.instance.config.face.enabled && ((_g = this.instance.config.face.mesh) == null ? void 0 : _g.enabled) && !this.models.facemesh ? load5(this.instance.config) : null; - m.gear = this.instance.config.face.enabled && ((_h = this.instance.config.face["gear"]) == null ? void 0 : _h.enabled) && !this.models.gear ? load10(this.instance.config) : null; - m.ssrnetage = this.instance.config.face.enabled && ((_i = this.instance.config.face["ssrnet"]) == null ? void 0 : _i.enabled) && !this.models.ssrnetage ? load11(this.instance.config) : null; - m.ssrnetgender = this.instance.config.face.enabled && ((_j = this.instance.config.face["ssrnet"]) == null ? void 0 : _j.enabled) && !this.models.ssrnetgender ? load12(this.instance.config) : null; - m.mobilefacenet = this.instance.config.face.enabled && ((_k = this.instance.config.face["mobilefacenet"]) == null ? void 0 : _k.enabled) && !this.models.mobilefacenet ? load13(this.instance.config) : null; - m.insightface = this.instance.config.face.enabled && ((_l = this.instance.config.face["insightface"]) == null ? void 0 : _l.enabled) && !this.models.insightface ? load14(this.instance.config) : null; - m.blazepose = this.instance.config.body.enabled && !this.models.blazepose && ((_m = this.instance.config.body.modelPath) == null ? void 0 : _m.includes("blazepose")) ? loadPose(this.instance.config) : null; - m.blazeposedetect = this.instance.config.body.enabled && !this.models.blazeposedetect && this.instance.config.body["detector"] && this.instance.config.body["detector"].modelPath ? loadDetect(this.instance.config) : null; - m.efficientpose = this.instance.config.body.enabled && !this.models.efficientpose && ((_n = this.instance.config.body.modelPath) == null ? void 0 : _n.includes("efficientpose")) ? load2(this.instance.config) : null; - m.movenet = this.instance.config.body.enabled && !this.models.movenet && ((_o = this.instance.config.body.modelPath) == null ? void 0 : _o.includes("movenet")) ? load17(this.instance.config) : null; - m.posenet = this.instance.config.body.enabled && !this.models.posenet && ((_p = this.instance.config.body.modelPath) == null ? void 0 : _p.includes("posenet")) ? load19(this.instance.config) : null; - m.handtrack = this.instance.config.hand.enabled && !this.models.handtrack && ((_r = (_q = this.instance.config.hand.detector) == null ? void 0 : _q.modelPath) == null ? void 0 : _r.includes("handtrack")) ? loadDetect2(this.instance.config) : null; - m.handskeleton = this.instance.config.hand.enabled && this.instance.config.hand.landmarks && !this.models.handskeleton && ((_t = (_s = this.instance.config.hand.detector) == null ? void 0 : _s.modelPath) == null ? void 0 : _t.includes("handtrack")) ? loadSkeleton(this.instance.config) : null; - if ((_v = (_u = this.instance.config.hand.detector) == null ? void 0 : _u.modelPath) == null ? void 0 : _v.includes("handdetect")) - [m.handpose, m.handskeleton] = !this.models.handpose ? await load15(this.instance.config) : [null, null]; - m.centernet = this.instance.config.object.enabled && !this.models.centernet && ((_w = this.instance.config.object.modelPath) == null ? void 0 : _w.includes("centernet")) ? load(this.instance.config) : null; - m.nanodet = this.instance.config.object.enabled && !this.models.nanodet && ((_x = this.instance.config.object.modelPath) == null ? void 0 : _x.includes("nanodet")) ? load18(this.instance.config) : null; - m.selfie = this.instance.config.segmentation.enabled && !this.models.selfie && ((_y = this.instance.config.segmentation.modelPath) == null ? void 0 : _y.includes("selfie")) ? load21(this.instance.config) : null; - m.meet = this.instance.config.segmentation.enabled && !this.models.meet && ((_z = this.instance.config.segmentation.modelPath) == null ? void 0 : _z.includes("meet")) ? load16(this.instance.config) : null; - m.rvm = this.instance.config.segmentation.enabled && !this.models.rvm && ((_A = this.instance.config.segmentation.modelPath) == null ? void 0 : _A.includes("rvm")) ? load20(this.instance.config) : null; - for (const [model23, promise] of Object.entries(m)) { - if (promise == null ? void 0 : promise["then"]) - promise["then"]((val) => this.models[model23] = val); - } - await Promise.all(Object.values(m)); - } - list() { - const models3 = Object.keys(this.models).map((model23) => { - var _a; - return { name: model23, loaded: this.models[model23] !== null, size: 0, url: this.models[model23] ? (_a = this.models[model23]) == null ? void 0 : _a["modelUrl"] : null }; - }); - for (const m of models3) { - const stats = Object.keys(modelStats).find((s) => s.startsWith(m.name)); - if (!stats) - continue; - m.size = modelStats[stats].sizeLoadedWeights; - m.url = modelStats[stats].url; - } - return models3; - } - loaded() { - const list = this.list(); - const loaded = list.filter((model23) => model23.loaded).map((model23) => model23.name); - return loaded; - } - validate() { - const missing = []; - for (const defined of Object.keys(this.models)) { - const model23 = this.models[defined]; - if (!model23) - continue; - const res = validateModel(this.instance, model23, defined); - if (res) - missing.push(res); - } - return missing; - } -}; - -// src/util/persons.ts -function join2(faces, bodies, hands, gestures, shape) { - var _a, _b, _c, _d, _e, _f; - let id = 0; - const persons = []; - for (const face4 of faces) { - const person2 = { id: id++, face: face4, body: null, hands: { left: null, right: null }, gestures: [], box: [0, 0, 0, 0] }; - for (const body4 of bodies) { - if (face4.box[0] > body4.box[0] && face4.box[0] < body4.box[0] + body4.box[2] && face4.box[1] + face4.box[3] > body4.box[1] && face4.box[1] + face4.box[3] < body4.box[1] + body4.box[3]) { - person2.body = body4; - } - } - if (person2.body) { - for (const hand3 of hands) { - if (hand3.box[0] + hand3.box[2] > person2.body.box[0] && hand3.box[0] + hand3.box[2] < person2.body.box[0] + person2.body.box[2] && hand3.box[1] + hand3.box[3] > person2.body.box[1] && hand3.box[1] + hand3.box[3] < person2.body.box[1] + person2.body.box[3]) { - if (person2.hands) - person2.hands.left = hand3; - } - if (hand3.box[0] < person2.body.box[0] + person2.body.box[2] && hand3.box[0] > person2.body.box[0] && hand3.box[1] + hand3.box[3] > person2.body.box[1] && hand3.box[1] + hand3.box[3] < person2.body.box[1] + person2.body.box[3]) { - if (person2.hands) - person2.hands.right = hand3; - } - } - } - for (const gesture2 of gestures) { - if (gesture2["face"] !== void 0 && gesture2["face"] === face4.id) - person2.gestures.push(gesture2); - else if (gesture2["iris"] !== void 0 && gesture2["iris"] === face4.id) - person2.gestures.push(gesture2); - else if (gesture2["body"] !== void 0 && gesture2["body"] === ((_a = person2.body) == null ? void 0 : _a.id)) - person2.gestures.push(gesture2); - else if (gesture2["hand"] !== void 0 && gesture2["hand"] === ((_b = person2.hands.left) == null ? void 0 : _b.id)) - person2.gestures.push(gesture2); - else if (gesture2["hand"] !== void 0 && gesture2["hand"] === ((_c = person2.hands.right) == null ? void 0 : _c.id)) - person2.gestures.push(gesture2); - } - const x = []; - const y = []; - const extractXY = (box) => { - if (box && box.length === 4) { - x.push(box[0], box[0] + box[2]); - y.push(box[1], box[1] + box[3]); - } - }; - extractXY(person2.face.box); - extractXY((_d = person2.body) == null ? void 0 : _d.box); - extractXY((_e = person2.hands.left) == null ? void 0 : _e.box); - extractXY((_f = person2.hands.right) == null ? void 0 : _f.box); - const minX = Math.min(...x); - const minY = Math.min(...y); - person2.box = [minX, minY, Math.max(...x) - minX, Math.max(...y) - minY]; - if ((shape == null ? void 0 : shape[1]) && (shape == null ? void 0 : shape[2])) - person2.boxRaw = [person2.box[0] / shape[2], person2.box[1] / shape[1], person2.box[2] / shape[2], person2.box[3] / shape[1]]; - persons.push(person2); - } - return persons; -} - -// src/warmup.ts -var tf37 = __toESM(require_tfjs_esm()); - -// src/sample.ts -var face3 = ` + gaze: [gaze]\xB0`,body:"body [score]%",bodyPart:"[label] [score]%",object:"[label] [score]%",hand:"[label] [score]%",finger:"[label]",gesture:"[where] [who]: [what]"};var r5=0;function Fs(e,t,n){let o=a0(x0,n);if(!t||!e)return;let r=Q0(e);if(!!r){r.lineJoin="round",r.font=o.font;for(let s=0;sa5,kpt:()=>A5});var A5=["nose","leftEyeInside","leftEye","leftEyeOutside","rightEyeInside","rightEye","rightEyeOutside","leftEar","rightEar","leftMouth","rightMouth","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftPinky","rightPinky","leftIndex","rightIndex","leftThumb","rightThumb","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle","leftHeel","rightHeel","leftFoot","rightFoot","bodyCenter","bodyTop","leftPalm","leftHand","rightPalm","rightHand"],a5={shoulders:["leftShoulder","rightShoulder"],hips:["rightHip","leftHip"],mouth:["leftMouth","rightMouth"],leftLegUpper:["leftHip","leftKnee"],leftLegLower:["leftKnee","leftAnkle"],leftFoot:["leftAnkle","leftHeel","leftFoot"],leftTorso:["leftShoulder","leftHip"],leftArmUpper:["leftShoulder","leftElbow"],leftArmLower:["leftElbow","leftWrist"],leftHand:["leftWrist","leftPalm"],leftHandPinky:["leftPalm","leftPinky"],leftHandIndex:["leftPalm","leftIndex"],leftHandThumb:["leftPalm","leftThumb"],leftEyeOutline:["leftEyeInside","leftEyeOutside"],rightLegUpper:["rightHip","rightKnee"],rightLegLower:["rightKnee","rightAnkle"],rightFoot:["rightAnkle","rightHeel","rightFoot"],rightTorso:["rightShoulder","rightHip"],rightArmUpper:["rightShoulder","rightElbow"],rightArmLower:["rightElbow","rightWrist"],rightHand:["rightWrist","rightPalm"],rightHandPinky:["rightPalm","rightPinky"],rightHandIndex:["rightPalm","rightIndex"],rightHandThumb:["rightPalm","rightThumb"],rightEyeOutline:["rightEyeInside","rightEyeOutside"]};var D=Z(H());var _0,t2=224,U1,Gs=5,nt=[8,16,32,32,32];function Vs(){let e=[],t=0;for(;tn.x)),y:D.tensor1d(e.map(n=>n.y))}}async function Y1(e){if(R.initial&&(_0=null),!_0&&e.body.detector&&e.body.detector.modelPath){_0=await O(e.body.detector.modelPath);let t=_0!=null&&_0.executor?Object.values(_0.modelSignature.inputs):void 0;t2=Array.isArray(t)?parseInt(t[0].tensorShape.dim[1].size):0}else e.debug&&_0&&u("cached model:",_0.modelUrl);return Vs(),_0}var q1=[5,5];function Zs(e,t){return D.tidy(()=>{let n=D.split(e,12,1),o=D.squeeze(n[0]),r=D.squeeze(n[1]),s=D.squeeze(n[2]),A=D.squeeze(n[3]);o=D.add(D.div(o,t2),t.x),r=D.add(D.div(r,t2),t.y),s=D.mul(D.div(s,t2),q1[0]),A=D.mul(D.div(A,t2),q1[1]);let a=D.sub(o,D.div(s,2)),l=D.sub(r,D.div(A,2)),c=D.add(a,s),x=D.add(l,A);return D.stack([a,l,c,x],1)})}async function Xs(e,t,n,o){var c,x;let r=[],s={};s.boxes=Zs(e,U1),s.scores=D.sigmoid(t),s.nms=await D.image.nonMaxSuppressionAsync(s.boxes,s.scores,1,((c=n.body.detector)==null?void 0:c.minConfidence)||.1,((x=n.body.detector)==null?void 0:x.iouThreshold)||.1);let A=await s.nms.data(),a=await s.scores.data(),l=await s.boxes.array();for(let i of Array.from(A)){let y=a[i],d=l[i],p=[Math.round(d[0]*o[0]),Math.round(d[1]*o[1]),Math.round(d[2]*o[0]),Math.round(d[3]*o[1])],f={score:y,boxRaw:d,box:p};r.push(f)}return Object.keys(s).forEach(i=>D.dispose(s[i])),r}async function K1(e,t,n){let o={};o.res=_0==null?void 0:_0.execute(e,["Identity"]),o.logitsRaw=D.slice(o.res,[0,0,0],[1,-1,1]),o.boxesRaw=D.slice(o.res,[0,0,1],[1,-1,-1]),o.logits=D.squeeze(o.logitsRaw),o.boxes=D.squeeze(o.boxesRaw);let r=await Xs(o.boxes,o.logits,t,n);return Object.keys(o).forEach(s=>D.dispose(o[s])),r}function ve(e,t=[1,1]){let n=[e.map(a=>a[0]),e.map(a=>a[1])],o=[Math.min(...n[0]),Math.min(...n[1])],r=[Math.max(...n[0]),Math.max(...n[1])],s=[o[0],o[1],r[0]-o[0],r[1]-o[1]],A=[s[0]/t[0],s[1]/t[1],s[2]/t[0],s[3]/t[1]];return{box:s,boxRaw:A}}function J1(e,t=[1,1]){let n=[e.map(c=>c[0]),e.map(c=>c[1])],o=[Math.min(...n[0]),Math.min(...n[1])],r=[Math.max(...n[0]),Math.max(...n[1])],s=[(o[0]+r[0])/2,(o[1]+r[1])/2],A=Math.max(s[0]-o[0],s[1]-o[1],-s[0]+r[0],-s[1]+r[1]),a=[Math.trunc(s[0]-A),Math.trunc(s[1]-A),Math.trunc(2*A),Math.trunc(2*A)],l=[a[0]/t[0],a[1]/t[1],a[2]/t[0],a[3]/t[1]];return{box:a,boxRaw:l}}function ot(e,t){let n=[e[2]*t,e[3]*t];return[e[0]-(n[0]-e[2])/2,e[1]-(n[1]-e[3])/2,n[0],n[1]]}var F0,l5=256,i5=Number.MAX_SAFE_INTEGER,qs={landmarks:["ld_3d","activation_segmentation","activation_heatmap","world_3d","output_poseflag"],detector:[]},st=[],Oe=[[0,0],[0,0],[0,0],[0,0]],Q1=0,_1=e=>1-1/(1+Math.exp(e)),e3=e=>Y1(e);async function t3(e){if(R.initial&&(F0=null),F0)e.debug&&u("cached model:",F0.modelUrl);else{F0=await O(e.body.modelPath);let t=F0!=null&&F0.executor?Object.values(F0.modelSignature.inputs):void 0;l5=Array.isArray(t)?parseInt(t[0].tensorShape.dim[1].size):0}return F0}function $1(e,t,n){var s,A;let o={};if(!((s=e==null?void 0:e.shape)!=null&&s[1])||!((A=e==null?void 0:e.shape)!=null&&A[2]))return e;let r;if(n&&(o.cropped=B0.image.cropAndResize(e,[n],[0],[e.shape[1],e.shape[2]])),e.shape[1]!==e.shape[2]){let a=[e.shape[2]>e.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0,e.shape[2]>e.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0],l=[e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0,e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0];Oe=[[0,0],a,l,[0,0]],o.pad=B0.pad(o.cropped||e,Oe),o.resize=B0.image.resizeBilinear(o.pad,[t,t]),r=B0.div(o.resize,C.tf255)}else e.shape[1]!==t?(o.resize=B0.image.resizeBilinear(o.cropped||e,[t,t]),r=B0.div(o.resize,C.tf255)):r=B0.div(o.cropped||e,C.tf255);return Object.keys(o).forEach(a=>B0.dispose(o[a])),r}function Us(e,t,n){for(let o of e)o.position=[Math.trunc(o.position[0]*(t[0]+Oe[2][0]+Oe[2][1])/t[0]-Oe[2][0]),Math.trunc(o.position[1]*(t[1]+Oe[1][0]+Oe[1][1])/t[1]-Oe[1][0]),o.position[2]],o.positionRaw=[o.position[0]/t[0],o.position[1]/t[1],2*o.position[2]/(t[0]+t[1])];if(n){let o=n[2]-n[0],r=n[3]-n[1];for(let s of e)s.positionRaw=[s.positionRaw[0]/r+n[1],s.positionRaw[1]/o+n[0],s.positionRaw[2]],s.position=[Math.trunc(s.positionRaw[0]*t[0]),Math.trunc(s.positionRaw[1]*t[1]),s.positionRaw[2]]}return e}function Ys(e){let t=e.find(a=>a.part==="leftPalm"),n=e.find(a=>a.part==="leftWrist"),o=e.find(a=>a.part==="leftIndex");t.position[2]=((n.position[2]||0)+(o.position[2]||0))/2;let r=e.find(a=>a.part==="rightPalm"),s=e.find(a=>a.part==="rightWrist"),A=e.find(a=>a.part==="rightIndex");r.position[2]=((s.position[2]||0)+(A.position[2]||0))/2}async function Ks(e,t,n){if(!(F0!=null&&F0.executor))return null;let o={};[o.ld,o.segmentation,o.heatmap,o.world,o.poseflag]=F0==null?void 0:F0.execute(e,qs.landmarks);let r=(await o.poseflag.data())[0],s=await o.ld.data(),A=await o.world.data();Object.keys(o).forEach(p=>B0.dispose(o[p]));let a=[],l=5;for(let p=0;pp.position),i=ve(x,[n[0],n[1]]),y={};for(let[p,f]of Object.entries(a5)){let b=[];for(let M=0;Mh.part===f[M]),m=c.find(h=>h.part===f[M+1]);T&&m&&b.push([T.position,m.position])}y[p]=b}return{id:0,score:Math.trunc(100*r)/100,box:i.box,boxRaw:i.boxRaw,keypoints:c,annotations:y}}async function c5(e,t){var s,A,a;let n=[e.shape[2]||0,e.shape[1]||0],o=(t.body.skipTime||0)>g()-Q1,r=i5<(t.body.skipFrames||0);if(t.skipAllowed&&o&&r&&st!==null)i5++;else{let l=[];if((A=(s=t.body)==null?void 0:s.detector)!=null&&A.enabled){let c=$1(e,224);l=await K1(c,t,n),B0.dispose(c)}else l=[{box:[0,0,0,0],boxRaw:[0,0,1,1],score:0}];for(let c=0;cL0.dispose(o[c])),r}async function y5(e,t){if(!(H0!=null&&H0.executor))return[];let n=(t.object.skipTime||0)>g()-o3,o=x5<(t.object.skipFrames||0);return t.skipAllowed&&n&&o&&d5.length>0?(x5++,d5):(x5=0,new Promise(async r=>{let s=[e.shape[2]||0,e.shape[1]||0],A=L0.image.resizeBilinear(e,[n2,n2]),a=t.object.enabled?H0==null?void 0:H0.execute(A,["tower_0/detections"]):null;o3=g(),L0.dispose(A);let l=await Js(a,s,t);d5=l,r(l)}))}var J=Z(H());var At={};ze(At,{connected:()=>m5,kpt:()=>f5});var f5=["head","neck","rightShoulder","rightElbow","rightWrist","chest","leftShoulder","leftElbow","leftWrist","bodyCenter","rightHip","rightKnee","rightAnkle","leftHip","leftKnee","leftAnkle"],m5={leftLeg:["leftHip","leftKnee","leftAnkle"],rightLeg:["rightHip","rightKnee","rightAnkle"],torso:["leftShoulder","rightShoulder","rightHip","leftHip","leftShoulder"],leftArm:["leftShoulder","leftElbow","leftWrist"],rightArm:["rightShoulder","rightElbow","rightWrist"],head:[]};var i0,A3=0,C0={id:0,keypoints:[],box:[0,0,0,0],boxRaw:[0,0,0,0],score:0,annotations:{}},p5=Number.MAX_SAFE_INTEGER;async function a3(e){return R.initial&&(i0=null),i0?e.debug&&u("cached model:",i0.modelUrl):i0=await O(e.body.modelPath),i0}async function Qs(e,t){let[n,o]=e.shape,r=J.reshape(e,[o*n]),s=J.max(r,0),A=(await s.data())[0];if(A>t){let a=J.argMax(r,0),l=J.mod(a,n),c=(await l.data())[0],x=J.div(a,n),i=(await x.data())[0];return J.dispose([r,s,a,l,x]),[c,i,A]}return J.dispose([r,s]),[0,0,A]}async function u5(e,t){if(!(i0!=null&&i0.executor)||!(i0!=null&&i0.inputs[0].shape))return[];let n=(t.body.skipTime||0)>g()-A3,o=p5<(t.body.skipFrames||0);return t.skipAllowed&&n&&o&&Object.keys(C0.keypoints).length>0?(p5++,[C0]):(p5=0,new Promise(async r=>{let s=J.tidy(()=>{var p,f;let i=J.image.resizeBilinear(e,[((p=i0==null?void 0:i0.inputs[0].shape)==null?void 0:p[2])||0,((f=i0==null?void 0:i0.inputs[0].shape)==null?void 0:f[1])||0],!1),y=J.mul(i,C.tf2);return J.sub(y,C.tf1)}),A;if(t.body.enabled&&(A=i0==null?void 0:i0.execute(s)),A3=g(),J.dispose(s),A){C0.keypoints.length=0;let i=J.squeeze(A);J.dispose(A);let y=J.unstack(i,2);J.dispose(i);for(let d=0;d(t.body.minConfidence||0)&&C0.keypoints.push({score:Math.round(100*b)/100,part:f5[d],positionRaw:[p/i0.inputs[0].shape[2],f/i0.inputs[0].shape[1]],position:[Math.round(e.shape[2]*p/i0.inputs[0].shape[2]),Math.round(e.shape[1]*f/i0.inputs[0].shape[1])]})}y.forEach(d=>J.dispose(d))}C0.score=C0.keypoints.reduce((i,y)=>y.score>i?y.score:i,0);let a=C0.keypoints.map(i=>i.position[0]),l=C0.keypoints.map(i=>i.position[1]);C0.box=[Math.min(...a),Math.min(...l),Math.max(...a)-Math.min(...a),Math.max(...l)-Math.min(...l)];let c=C0.keypoints.map(i=>i.positionRaw[0]),x=C0.keypoints.map(i=>i.positionRaw[1]);C0.boxRaw=[Math.min(...c),Math.min(...x),Math.max(...c)-Math.min(...c),Math.max(...x)-Math.min(...x)];for(let[i,y]of Object.entries(m5)){let d=[];for(let p=0;pM.part===y[p]),b=C0.keypoints.find(M=>M.part===y[p+1]);f&&b&&f.score>(t.body.minConfidence||0)&&b.score>(t.body.minConfidence||0)&&d.push([f.position,b.position])}C0.annotations[i]=d}r([C0])}))}var l0=Z(H());var We=Z(H());var L=Z(H());var Re=Z(H());var y2=e=>[Math.abs(e.endPoint[0]-e.startPoint[0]),Math.abs(e.endPoint[1]-e.startPoint[1])],at=e=>[e.startPoint[0]+(e.endPoint[0]-e.startPoint[0])/2,e.startPoint[1]+(e.endPoint[1]-e.startPoint[1])/2,1],it=(e,t)=>e?[Math.trunc(Math.max(0,e.startPoint[0])),Math.trunc(Math.max(0,e.startPoint[1])),Math.trunc(Math.min(t.shape[2]||0,e.endPoint[0])-Math.max(0,e.startPoint[0])),Math.trunc(Math.min(t.shape[1]||0,e.endPoint[1])-Math.max(0,e.startPoint[1]))]:[0,0,0,0],lt=(e,t)=>e?[e.startPoint[0]/(t.shape[2]||0),e.startPoint[1]/(t.shape[1]||0),(e.endPoint[0]-e.startPoint[0])/(t.shape[2]||0),(e.endPoint[1]-e.startPoint[1])/(t.shape[1]||0)]:[0,0,0,0],d3=(e,t)=>{let n=[e.startPoint[0]*t[0],e.startPoint[1]*t[1]],o=[e.endPoint[0]*t[0],e.endPoint[1]*t[1]];return{startPoint:n,endPoint:o,landmarks:e.landmarks,confidence:e.confidence}},h5=(e,t,n)=>{let o=t.shape[1],r=t.shape[2],s=[e.startPoint[1]/o,e.startPoint[0]/r,e.endPoint[1]/o,e.endPoint[0]/r],A=Re.image.cropAndResize(t,[s],[0],n),a=Re.div(A,C.tf255);return Re.dispose(A),a},ct=(e,t)=>{let n=at(e),o=y2(e),r=[t*o[0]/2,t*o[1]/2];return{startPoint:[n[0]-r[0],n[1]-r[1]],endPoint:[n[0]+r[0],n[1]+r[1]],landmarks:e.landmarks,confidence:e.confidence}},dt=e=>{let t=at(e),n=y2(e),o=Math.max(...n)/2;return{startPoint:[Math.round(t[0]-o),Math.round(t[1]-o)],endPoint:[Math.round(t[0]+o),Math.round(t[1]+o)],landmarks:e.landmarks,confidence:e.confidence}},x3=e=>{let t=e.map(o=>o[0]),n=e.map(o=>o[1]);return{startPoint:[Math.min(...t),Math.min(...n)],endPoint:[Math.max(...t),Math.max(...n)],landmarks:e}},b5=[[1,0,0],[0,1,0],[0,0,1]],_s=e=>e-2*Math.PI*Math.floor((e+Math.PI)/(2*Math.PI)),$s=(e,t)=>_s(Math.PI/2-Math.atan2(-(t[1]-e[1]),t[0]-e[0]));var l3=(e,t)=>[[1,0,e],[0,1,t],[0,0,1]],o2=(e,t)=>{let n=0;for(let o=0;o{let n=[];for(let o=0;o{let n=[],o=e.length;for(let r=0;r{let n=Math.cos(e),o=Math.sin(e),r=[[n,-o,0],[o,n,0],[0,0,1]],s=l3(t[0],t[1]),A=c3(s,r),a=l3(-t[0],-t[1]);return c3(A,a)},tA=e=>{let t=[[e[0][0],e[1][0]],[e[0][1],e[1][1]]],n=[e[0][2],e[1][2]],o=[-o2(t[0],n),-o2(t[1],n)];return[t[0].concat(o[0]),t[1].concat(o[1]),[0,0,1]]},nA=(e,t)=>[o2(e,t[0]),o2(e,t[1])];function f3(e){let t=e===192?{strides:[4],anchors:[1]}:{strides:[e/16,e/8],anchors:[2,6]},n=[];for(let o=0;o[s[0]/r*(d[0]-r/2),s[1]/r*(d[1]-r/2),d[2]||0]),a=n&&n!==0&&Math.abs(n)>.2,l=a?y3(n,[0,0]):b5,c=a?A.map(d=>[...nA(d,l),d[2]]):A,x=a?tA(o):b5,i=at(t),y=[o2(i,x[0]),o2(i,x[1])];return c.map(d=>[Math.trunc(d[0]+y[0]),Math.trunc(d[1]+y[1]),Math.trunc(d[2]||0)])}function p3(e,t,n,o){let r=t.landmarks.length>=t5.count?t5.symmetryLine:Qe.symmetryLine,s=0,A=b5,a;if(e&&R.kernels.includes("rotatewithoffset"))if(s=$s(t.landmarks[r[0]],t.landmarks[r[1]]),s&&s!==0&&Math.abs(s)>.2){let c=at(t),x=[c[0]/n.shape[2],c[1]/n.shape[1]],i=Re.image.rotateWithOffset(n,s,0,[x[0],x[1]]);A=y3(-s,c),a=h5(t,i,[o,o]),Re.dispose(i)}else a=h5(t,n,[o,o]);else a=h5(t,n,[o,o]);return[s,A,a]}var oA=e=>{let t=e.map(o=>o[0]),n=e.map(o=>o[1]);return[Math.min(...t)+(Math.max(...t)-Math.min(...t))/2,Math.min(...n)+(Math.max(...n)-Math.min(...n))/2]},u3=(e,t)=>{let n=oA(e),o=y2(t);return{startPoint:[n[0]-o[0]/2,n[1]-o[1]/2],endPoint:[n[0]+o[0]/2,n[1]+o[1]/2]}};var h3=6,rA=1.4,ie,T5=null,Le=0,f2=null,m2=()=>Le;async function b3(e){var t;return R.initial&&(ie=null),ie?e.debug&&u("cached model:",ie.modelUrl):ie=await O((t=e.face.detector)==null?void 0:t.modelPath),Le=ie.executor&&ie.inputs[0].shape?ie.inputs[0].shape[2]:256,f2=L.scalar(Le,"int32"),T5=L.tensor2d(f3(Le)),ie}function sA(e){if(!T5||!f2)return L.zeros([0,0]);let t={};t.boxStarts=L.slice(e,[0,1],[-1,2]),t.centers=L.add(t.boxStarts,T5),t.boxSizes=L.slice(e,[0,3],[-1,2]),t.boxSizesNormalized=L.div(t.boxSizes,f2),t.centersNormalized=L.div(t.centers,f2),t.halfBoxSize=L.div(t.boxSizesNormalized,C.tf2),t.starts=L.sub(t.centersNormalized,t.halfBoxSize),t.ends=L.add(t.centersNormalized,t.halfBoxSize),t.startNormalized=L.mul(t.starts,f2),t.endNormalized=L.mul(t.ends,f2);let n=L.concat2d([t.startNormalized,t.endNormalized],1);return Object.keys(t).forEach(o=>L.dispose(t[o])),n}async function g3(e,t){var a,l,c,x;if(!e||e.isDisposedInternal||e.shape.length!==4||e.shape[1]<1||e.shape[2]<1)return[];let n={};n.resized=L.image.resizeBilinear(e,[Le,Le]),n.div=L.div(n.resized,C.tf127),n.normalized=L.sub(n.div,C.tf05);let o=ie==null?void 0:ie.execute(n.normalized);if(Array.isArray(o)&&o.length>2){let i=o.sort((y,d)=>y.size-d.size);n.concat384=L.concat([i[0],i[2]],2),n.concat512=L.concat([i[1],i[3]],2),n.concat=L.concat([n.concat512,n.concat384],1),n.batch=L.squeeze(n.concat,[0])}else Array.isArray(o)?n.batch=L.squeeze(o[0]):n.batch=L.squeeze(o);L.dispose(o),n.boxes=sA(n.batch),n.logits=L.slice(n.batch,[0,0],[-1,1]),n.sigmoid=L.sigmoid(n.logits),n.scores=L.squeeze(n.sigmoid),n.nms=await L.image.nonMaxSuppressionAsync(n.boxes,n.scores,((a=t.face.detector)==null?void 0:a.maxDetected)||0,((l=t.face.detector)==null?void 0:l.iouThreshold)||0,((c=t.face.detector)==null?void 0:c.minConfidence)||0);let r=await n.nms.array(),s=[],A=await n.scores.data();for(let i=0;i(((x=t.face.detector)==null?void 0:x.minConfidence)||0)){let d={};d.bbox=L.slice(n.boxes,[r[i],0],[1,-1]),d.slice=L.slice(n.batch,[r[i],h3-1],[1,-1]),d.squeeze=L.squeeze(d.slice),d.landmarks=L.reshape(d.squeeze,[h3,-1]);let p=await d.bbox.data(),f={startPoint:[p[0],p[1]],endPoint:[p[2],p[3]],landmarks:await d.landmarks.array(),confidence:y},b=d3(f,[(e.shape[2]||0)/Le,(e.shape[1]||0)/Le]),M=ct(b,t.face.scale||rA),T=dt(M);s.push(T),Object.keys(d).forEach(m=>L.dispose(d[m]))}}return Object.keys(n).forEach(i=>L.dispose(n[i])),s}var le=Z(H());var V0,Ce=0,AA=2.3,v5=oe.leftEyeLower0,R5=oe.rightEyeLower0,p2={leftBounds:[v5[0],v5[v5.length-1]],rightBounds:[R5[0],R5[R5.length-1]]},u2={upperCenter:3,lowerCenter:4,index:71,numCoordinates:76};async function P3(e){var t,n;return R.initial&&(V0=null),V0?e.debug&&u("cached model:",V0.modelUrl):V0=await O((t=e.face.iris)==null?void 0:t.modelPath),Ce=(V0==null?void 0:V0.executor)&&((n=V0.inputs)==null?void 0:n[0].shape)?V0.inputs[0].shape[2]:0,Ce===-1&&(Ce=64),V0}function xt(e,t,n,o){for(let r=0;r{let t=e[p2.leftBounds[0]][2],n=e[p2.rightBounds[0]][2];return t-n},v3=(e,t,n,o,r,s=!1)=>{let A=dt(ct(x3([e[n],e[o]]),AA)),a=y2(A),l=le.image.cropAndResize(t,[[A.startPoint[1]/r,A.startPoint[0]/r,A.endPoint[1]/r,A.endPoint[0]/r]],[0],[Ce,Ce]);if(s&&R.kernels.includes("flipleftright")){let c=le.image.flipLeftRight(l);le.dispose(l),l=c}return{box:A,boxSize:a,crop:l}},R3=(e,t,n,o=!1)=>{let r=[];for(let s=0;s{let o=e[oe[`${n}EyeUpper0`][u2.upperCenter]][2],r=e[oe[`${n}EyeLower0`][u2.lowerCenter]][2],s=(o+r)/2;return t.map((A,a)=>{let l=s;return a===2?l=o:a===4&&(l=r),[A[0],A[1],l]})};async function k3(e,t,n){if(!(V0!=null&&V0.executor))return e;let{box:o,boxSize:r,crop:s}=v3(e,t,p2.leftBounds[0],p2.leftBounds[1],n,!0),{box:A,boxSize:a,crop:l}=v3(e,t,p2.rightBounds[0],p2.rightBounds[1],n,!0),c=le.concat([s,l]);le.dispose(s),le.dispose(l);let x=V0.execute(c);le.dispose(c);let i=await x.data();le.dispose(x);let y=i.slice(0,u2.numCoordinates*3),{rawCoords:d,iris:p}=R3(y,o,r,!0),f=i.slice(u2.numCoordinates*3),{rawCoords:b,iris:M}=R3(f,A,a,!1),T=aA(e);Math.abs(T)<30?(xt(e,d,"left",null),xt(e,b,"right",null)):T<1?xt(e,d,"left",["EyeUpper0","EyeLower0"]):xt(e,b,"right",["EyeUpper0","EyeLower0"]);let m=M3(e,p,"left"),h=M3(e,M,"right");return e.concat(m).concat(h)}async function E3(e,t){var s,A,a,l,c,x,i,y,d,p;let n={lips:await((A=(s=t.filter(f=>f.size===160))==null?void 0:s[0])==null?void 0:A.data()),irisL:await((l=(a=t.filter(f=>f.size===10))==null?void 0:a[0])==null?void 0:l.data()),eyeL:await((x=(c=t.filter(f=>f.size===142))==null?void 0:c[0])==null?void 0:x.data()),irisR:await((y=(i=t.filter(f=>f.size===10))==null?void 0:i[1])==null?void 0:y.data()),eyeR:await((p=(d=t.filter(f=>f.size===142))==null?void 0:d[1])==null?void 0:p.data())};for(let f of Object.values(n))if(!f)return e;let o=$e.reduce((f,b)=>f+=e[b][2],0)/$e.length;for(let f=0;ff+=e[b][2],0)/e2.length;for(let f=0;fg()-ue.timestamp,o=ue.skipped<(((c=t.face.detector)==null?void 0:c.skipFrames)||0);!t.skipAllowed||!n||!o||ue.boxes.length===0?(ue.boxes=await g3(e,t),ue.timestamp=g(),ue.skipped=0):ue.skipped++;let r=[],s=[],A=0,a=O2;for(let T=0;TG.shape[G.shape.length-1]===1).data();if(P.faceScore=Math.round(100*t0[0])/100,P.faceScore<(((p=t.face.detector)==null?void 0:p.minConfidence)||1)){if(m.confidence=P.faceScore,t.face.mesh.keepInvalid){P.box=it(m,e),P.boxRaw=lt(m,e),P.score=P.boxScore,P.mesh=m.landmarks.map(G=>[(m.startPoint[0]+m.endPoint[0])/2+(m.endPoint[0]+m.startPoint[0])*G[0]/m2(),(m.startPoint[1]+m.endPoint[1])/2+(m.endPoint[1]+m.startPoint[1])*G[1]/m2()]),P.meshRaw=P.mesh.map(G=>[G[0]/(e.shape[2]||1),G[1]/(e.shape[1]||1),(G[2]||0)/a]);for(let G of Object.keys(Qe))P.annotations[G]=[P.mesh[Qe[G]]]}}else{let G=I.find(V=>V.shape[V.shape.length-1]===1404),$=We.reshape(G,[-1,3]),A0=await $.array();We.dispose($),(f=t.face.attention)!=null&&f.enabled?A0=await E3(A0,I):(b=t.face.iris)!=null&&b.enabled&&(A0=await k3(A0,P.tensor,O2)),P.mesh=m3(A0,m,h,S,O2),P.meshRaw=P.mesh.map(V=>[V[0]/(e.shape[2]||0),V[1]/(e.shape[1]||0),(V[2]||0)/a]);for(let V of Object.keys(oe))P.annotations[V]=oe[V].map(n0=>P.mesh[n0]);P.score=P.faceScore;let v={...u3(P.mesh,m),confidence:m.confidence,landmarks:m.landmarks};P.box=it(v,e),P.boxRaw=lt(v,e),s.push(v)}We.dispose(I)}else{P.box=it(m,e),P.boxRaw=lt(m,e),P.score=P.boxScore,P.mesh=m.landmarks.map(I=>[(m.startPoint[0]+m.endPoint[0])/2+(m.endPoint[0]+m.startPoint[0])*I[0]/m2(),(m.startPoint[1]+m.endPoint[1])/2+(m.endPoint[1]+m.startPoint[1])*I[1]/m2()]),P.meshRaw=P.mesh.map(I=>[I[0]/(e.shape[2]||0),I[1]/(e.shape[1]||0),(I[2]||0)/a]);for(let I of Object.keys(Qe))P.annotations[I]=[P.mesh[Qe[I]]]}P.score>(((M=t.face.detector)==null?void 0:M.minConfidence)||1)?r.push(P):We.dispose(P.tensor)}return ue.boxes=s,r}async function S3(e){var t,n,o,r,s,A;return R.initial&&(r0=null),((t=e.face.attention)==null?void 0:t.enabled)&&(r0==null?void 0:r0.signature)&&Object.keys(((n=r0==null?void 0:r0.signature)==null?void 0:n.outputs)||{}).length<6&&(r0=null),r0?e.debug&&u("cached model:",r0.modelUrl):(o=e.face.attention)!=null&&o.enabled?r0=await O(e.face.attention.modelPath):r0=await O((r=e.face.mesh)==null?void 0:r.modelPath),O2=r0.executor&&((s=r0==null?void 0:r0.inputs)==null?void 0:s[0].shape)?(A=r0==null?void 0:r0.inputs)==null?void 0:A[0].shape[2]:256,r0}var j3=_e,N3=N2;var ce=Z(H());var lA=["angry","disgust","fear","happy","sad","surprise","neutral"],$0,yt=[],I3=0,O3=0,P5=Number.MAX_SAFE_INTEGER;async function L3(e){var t;return R.initial&&($0=null),$0?e.debug&&u("cached model:",$0.modelUrl):$0=await O((t=e.face.emotion)==null?void 0:t.modelPath),$0}async function k5(e,t,n,o){var A,a;if(!$0)return[];let r=P5<(((A=t.face.emotion)==null?void 0:A.skipFrames)||0),s=(((a=t.face.emotion)==null?void 0:a.skipTime)||0)>g()-O3;return t.skipAllowed&&s&&r&&I3===o&&yt[n]&&yt[n].length>0?(P5++,yt[n]):(P5=0,new Promise(async l=>{var x;let c=[];if((x=t.face.emotion)!=null&&x.enabled){let i={},y=$0!=null&&$0.inputs[0].shape?$0.inputs[0].shape[2]:0;i.resize=ce.image.resizeBilinear(e,[y,y],!1),i.channels=ce.mul(i.resize,C.rgb),i.grayscale=ce.sum(i.channels,3,!0),i.grayscaleSub=ce.sub(i.grayscale,C.tf05),i.grayscaleMul=ce.mul(i.grayscaleSub,C.tf2),i.emotion=$0==null?void 0:$0.execute(i.grayscaleMul),O3=g();let d=await i.emotion.data();for(let p=0;p(t.face.emotion.minConfidence||0)&&c.push({score:Math.min(.99,Math.trunc(100*d[p])/100),emotion:lA[p]});c.sort((p,f)=>f.score-p.score),Object.keys(i).forEach(p=>ce.dispose(i[p]))}yt[n]=c,I3=o,l(c)}))}var de=Z(H());var z0,De=[],W3=0,D3=0,w5=Number.MAX_SAFE_INTEGER;async function F3(e){var t;return R.initial&&(z0=null),z0?e.debug&&u("cached model:",z0.modelUrl):z0=await O((t=e.face.description)==null?void 0:t.modelPath),z0}function cA(e){let t=e.image||e.tensor||e;if(!(z0!=null&&z0.inputs[0].shape))return t;let n=de.image.resizeBilinear(t,[z0.inputs[0].shape[2],z0.inputs[0].shape[1]],!1),o=de.mul(n,C.tf255);return de.dispose(n),o}async function E5(e,t,n,o){var a,l,c,x;let r={age:0,gender:"unknown",genderScore:0,descriptor:[]};if(!(z0!=null&&z0.executor))return r;let s=w5<(((a=t.face.description)==null?void 0:a.skipFrames)||0),A=(((l=t.face.description)==null?void 0:l.skipTime)||0)>g()-W3;return t.skipAllowed&&s&&A&&D3===o&&((c=De==null?void 0:De[n])==null?void 0:c.age)>0&&((x=De==null?void 0:De[n])==null?void 0:x.genderScore)>0?(w5++,De[n]):(w5=0,new Promise(async i=>{var y;if((y=t.face.description)!=null&&y.enabled){let d=cA(e),p=z0==null?void 0:z0.execute(d);W3=g(),de.dispose(d);let b=await p.find(q=>q.shape[1]===1).data(),M=Math.trunc(200*Math.abs(b[0]-.5))/100;M>(t.face.description.minConfidence||0)&&(r.gender=b[0]<=.5?"female":"male",r.genderScore=Math.min(.99,M));let T=de.argMax(p.find(q=>q.shape[1]===100),1),m=(await T.data())[0];de.dispose(T);let S=await p.find(q=>q.shape[1]===100).data();r.age=Math.round(S[m-1]>S[m+1]?10*m-100*S[m-1]:10*m+100*S[m+1])/10,(Number.isNaN(b[0])||Number.isNaN(S[0]))&&u("faceres error:",{model:z0,result:p});let P=p.find(q=>q.shape[1]===1024),I=P?await P.data():[];r.descriptor=Array.from(I),p.forEach(q=>de.dispose(q))}De[n]=r,D3=o,i(r)}))}var h2=.1,z5=.5;function dA(e,t,n){let o=!1,r=n.length-1;for(let s=0;st!=n[r].y>t&&e<(n[r].x-n[s].x)*(t-n[s].y)/(n[r].y-n[s].y)+n[s].x&&(o=!o);return o}async function H3(e){if(!e.tensor||!e.mesh||e.mesh.length<100)return e.tensor;let t=e.tensor.shape[2]||0,n=e.tensor.shape[1]||0,o=await e.tensor.buffer(),r=[];for(let A of oe.silhouette)r.push({x:(e.mesh[A][0]-e.box[0])/e.box[2],y:(e.mesh[A][1]-e.box[1])/e.box[3]});h2&&h2>0&&(r=r.map(A=>({x:A.x>.5?A.x+h2:A.x-h2,y:A.y>.5?A.y+h2:A.y-h2})));for(let A=0;Ag()-V3,s=S5<(((a=t.face.antispoof)==null?void 0:a.skipFrames)||0);return t.skipAllowed&&r&&s&&G3===o&&ft[n]?(S5++,ft[n]):(S5=0,new Promise(async l=>{let c=mt.image.resizeBilinear(e,[M0!=null&&M0.inputs[0].shape?M0.inputs[0].shape[2]:0,M0!=null&&M0.inputs[0].shape?M0.inputs[0].shape[1]:0],!1),x=M0==null?void 0:M0.execute(c),i=(await x.data())[0];ft[n]=Math.round(100*i)/100,G3=o,V3=g(),mt.dispose([c,x]),l(ft[n])}))}var ut=Z(H());var P0,pt=[],N5=Number.MAX_SAFE_INTEGER,q3=0,U3=0;async function Y3(e){var t;return R.initial&&(P0=null),P0?e.debug&&u("cached model:",P0.modelUrl):P0=await O((t=e.face.liveness)==null?void 0:t.modelPath),P0}async function I5(e,t,n,o){var A,a;if(!(P0!=null&&P0.executor))return 0;let r=(((A=t.face.liveness)==null?void 0:A.skipTime)||0)>g()-U3,s=N5<(((a=t.face.liveness)==null?void 0:a.skipFrames)||0);return t.skipAllowed&&r&&s&&q3===o&&pt[n]?(N5++,pt[n]):(N5=0,new Promise(async l=>{let c=ut.image.resizeBilinear(e,[P0!=null&&P0.inputs[0].shape?P0.inputs[0].shape[2]:0,P0!=null&&P0.inputs[0].shape?P0.inputs[0].shape[1]:0],!1),x=P0==null?void 0:P0.execute(c),i=(await x.data())[0];pt[n]=Math.round(100*i)/100,q3=o,U3=g(),ut.dispose([c,x]),l(pt[n])}))}var ht=Z(H());var re,O5=[],yA=["white","black","asian","indian","other"],fA=[15,23,28,35.5,45.5,55.5,65],J3=0,Q3=0,L5=Number.MAX_SAFE_INTEGER;async function _3(e){var t;return R.initial&&(re=null),re?e.debug&&u("cached model:",re.modelUrl):re=await O((t=e.face.gear)==null?void 0:t.modelPath),re}async function C5(e,t,n,o){var A,a;if(!re)return{age:0,gender:"unknown",genderScore:0,race:[]};let r=L5<(((A=t.face.gear)==null?void 0:A.skipFrames)||0),s=(((a=t.face.gear)==null?void 0:a.skipTime)||0)>g()-Q3;return t.skipAllowed&&s&&r&&J3===o&&O5[n]?(L5++,O5[n]):(L5=0,new Promise(async l=>{var M,T;if(!(re!=null&&re.inputs[0].shape))return;let c={},x=[[0,.1,.9,.9]];c.resize=ht.image.cropAndResize(e,x,[0],[re.inputs[0].shape[2],re.inputs[0].shape[1]]);let i={age:0,gender:"unknown",genderScore:0,race:[]};(M=t.face.gear)!=null&&M.enabled&&([c.age,c.gender,c.race]=re.execute(c.resize,["age_output","gender_output","race_output"]));let y=await c.gender.data();i.gender=y[0]>y[1]?"male":"female",i.genderScore=Math.round(100*(y[0]>y[1]?y[0]:y[1]))/100;let d=await c.race.data();for(let m=0;m(((T=t.face.gear)==null?void 0:T.minConfidence)||.2)&&i.race.push({score:Math.round(100*d[m])/100,race:yA[m]});i.race.sort((m,h)=>h.score-m.score);let f=Array.from(await c.age.data()).map((m,h)=>[fA[h],m]).sort((m,h)=>h[1]-m[1]),b=f[0][0];for(let m=1;mht.dispose(c[m])),O5[n]=i,J3=o,Q3=g(),l(i)}))}var b2=Z(H());var Z0,bt=[],en=0,tn=0,W5=Number.MAX_SAFE_INTEGER;async function nn(e){return R.initial&&(Z0=null),Z0?e.debug&&u("cached model:",Z0.modelUrl):Z0=await O(e.face.ssrnet.modelPathAge),Z0}async function D5(e,t,n,o){var A,a,l,c;if(!Z0)return{age:0};let r=W5<(((A=t.face.ssrnet)==null?void 0:A.skipFrames)||0),s=(((a=t.face.ssrnet)==null?void 0:a.skipTime)||0)>g()-tn;return t.skipAllowed&&r&&s&&en===o&&((l=bt[n])==null?void 0:l.age)&&((c=bt[n])==null?void 0:c.age)>0?(W5++,bt[n]):(W5=0,new Promise(async x=>{var d;if(!(Z0!=null&&Z0.inputs)||!Z0.inputs[0]||!Z0.inputs[0].shape)return;let i={};i.resize=b2.image.resizeBilinear(e,[Z0.inputs[0].shape[2],Z0.inputs[0].shape[1]],!1),i.enhance=b2.mul(i.resize,C.tf255);let y={age:0};if((d=t.face.ssrnet)!=null&&d.enabled&&(i.age=Z0.execute(i.enhance)),i.age){let p=await i.age.data();y.age=Math.trunc(10*p[0])/10}Object.keys(i).forEach(p=>b2.dispose(i[p])),bt[n]=y,en=o,tn=g(),x(y)}))}var S0=Z(H());var se,gt=[],rn=0,sn=0,F5=Number.MAX_SAFE_INTEGER,B5=[.2989,.587,.114];async function An(e){var t;return R.initial&&(se=null),se?e.debug&&u("cached model:",se.modelUrl):se=await O((t=e.face.ssrnet)==null?void 0:t.modelPathGender),se}async function H5(e,t,n,o){var A,a,l,c;if(!se)return{gender:"unknown",genderScore:0};let r=F5<(((A=t.face.ssrnet)==null?void 0:A.skipFrames)||0),s=(((a=t.face.ssrnet)==null?void 0:a.skipTime)||0)>g()-sn;return t.skipAllowed&&r&&s&&rn===o&&((l=gt[n])==null?void 0:l.gender)&&((c=gt[n])==null?void 0:c.genderScore)>0?(F5++,gt[n]):(F5=0,new Promise(async x=>{var p;if(!(se!=null&&se.inputs[0].shape))return;let i={};i.resize=S0.image.resizeBilinear(e,[se.inputs[0].shape[2],se.inputs[0].shape[1]],!1),i.enhance=S0.tidy(()=>{let[f,b,M]=S0.split(i.resize,3,3),T=S0.mul(f,B5[0]),m=S0.mul(b,B5[1]),h=S0.mul(M,B5[2]),S=S0.addN([T,m,h]);return S0.mul(S0.sub(S,C.tf05),2)});let y={gender:"unknown",genderScore:0};(p=t.face.ssrnet)!=null&&p.enabled&&(i.gender=se.execute(i.enhance));let d=await i.gender.data();y.gender=d[0]>d[1]?"female":"male",y.genderScore=d[0]>d[1]?Math.trunc(100*d[0])/100:Math.trunc(100*d[1])/100,Object.keys(i).forEach(f=>S0.dispose(i[f])),gt[n]=y,rn=o,sn=g(),x(y)}))}var Tt=Z(H());var X0,G5=[],ln=0,cn=0,dn=Number.MAX_SAFE_INTEGER;async function xn(e){var t;return R.initial&&(X0=null),X0?e.debug&&u("cached model:",X0.modelUrl):X0=await O((t=e.face.mobilefacenet)==null?void 0:t.modelPath),X0}async function V5(e,t,n,o){var A,a;if(!(X0!=null&&X0.executor))return[];let r=dn<(((A=t.face.mobilefacenet)==null?void 0:A.skipFrames)||0),s=(((a=t.face.mobilefacenet)==null?void 0:a.skipTime)||0)>g()-cn;return t.skipAllowed&&s&&r&&ln===o&&G5[n]?(dn++,G5[n]):new Promise(async l=>{var x;let c=[];if(((x=t.face.mobilefacenet)==null?void 0:x.enabled)&&(X0==null?void 0:X0.inputs[0].shape)){let i={};i.crop=Tt.image.resizeBilinear(e,[X0.inputs[0].shape[2],X0.inputs[0].shape[1]],!1),i.data=X0.execute(i.crop);let y=await i.data.data();c=Array.from(y),Object.keys(i).forEach(d=>Tt.dispose(i[d]))}G5[n]=c,ln=o,cn=g(),l(c)})}var vt=Z(H());var q0,Z5=[],fn=0,mn=0,pn=Number.MAX_SAFE_INTEGER;async function un(e){return R.initial&&(q0=null),q0?e.debug&&u("cached model:",q0.modelUrl):q0=await O(e.face.insightface.modelPath),q0}async function X5(e,t,n,o){var A,a;if(!(q0!=null&&q0.executor))return[];let r=pn<(((A=t.face.insightface)==null?void 0:A.skipFrames)||0),s=(((a=t.face.insightface)==null?void 0:a.skipTime)||0)>g()-mn;return t.skipAllowed&&s&&r&&fn===o&&Z5[n]?(pn++,Z5[n]):new Promise(async l=>{var x;let c=[];if(((x=t.face.insightface)==null?void 0:x.enabled)&&(q0==null?void 0:q0.inputs[0].shape)){let i={};i.crop=vt.image.resizeBilinear(e,[q0.inputs[0].shape[2],q0.inputs[0].shape[1]],!1),i.data=q0.execute(i.crop);let y=await i.data.data();c=Array.from(y),Object.keys(i).forEach(d=>vt.dispose(i[d]))}Z5[n]=c,fn=o,mn=g(),l(c)})}var mA=e=>{let t=(i,y)=>Math.atan2(i[1]-y[1],i[0]-y[0]);if(!e.annotations.rightEyeIris||!e.annotations.leftEyeIris)return{bearing:0,strength:0};let n=[0,-.1],o=1,r=(e.mesh[33][2]||0)>(e.mesh[263][2]||0),s=r?e.mesh[473]:e.mesh[468],A=r?[(e.mesh[133][0]+e.mesh[33][0])/2,(e.mesh[133][1]+e.mesh[33][1])/2]:[(e.mesh[263][0]+e.mesh[362][0])/2,(e.mesh[263][1]+e.mesh[362][1])/2],a=r?[e.mesh[133][0]-e.mesh[33][0],e.mesh[23][1]-e.mesh[27][1]]:[e.mesh[263][0]-e.mesh[362][0],e.mesh[253][1]-e.mesh[257][1]],l=[(A[0]-s[0])/a[0]-n[0],o*(s[1]-A[1])/a[1]-n[1]],c=Math.sqrt(l[0]*l[0]+l[1]*l[1]);return c=Math.min(c,e.boxRaw[2]/2,e.boxRaw[3]/2),{bearing:(t([0,0],l)+Math.PI/2)%Math.PI,strength:c}},bn=(e,t)=>{let n=f=>{let b=Math.sqrt(f[0]*f[0]+f[1]*f[1]+f[2]*f[2]);return f[0]/=b,f[1]/=b,f[2]/=b,f},o=(f,b)=>{let M=f[0]-b[0],T=f[1]-b[1],m=f[2]-b[2];return[M,T,m]},r=(f,b)=>{let M=f[1]*b[2]-f[2]*b[1],T=f[2]*b[0]-f[0]*b[2],m=f[0]*b[1]-f[1]*b[0];return[M,T,m]},s=f=>{let[b,M,T,m,h,S,P,I,q]=f,t0,G,$;return m<1?m>-1?($=Math.asin(m),G=Math.atan2(-P,b),t0=Math.atan2(-S,h)):($=-Math.PI/2,G=-Math.atan2(I,q),t0=0):($=Math.PI/2,G=Math.atan2(I,q),t0=0),Number.isNaN(t0)&&(t0=0),Number.isNaN(G)&&(G=0),Number.isNaN($)&&($=0),{pitch:2*-t0,yaw:2*-G,roll:2*-$}},A=e.meshRaw;if(!A||A.length<300)return{angle:{pitch:0,yaw:0,roll:0},matrix:[1,0,0,0,1,0,0,0,1],gaze:{bearing:0,strength:0}};let a=Math.max(e.boxRaw[2]*t[0],e.boxRaw[3]*t[1])/1.5,l=[A[10],A[152],A[234],A[454]].map(f=>[f[0]*t[0]/a,f[1]*t[1]/a,f[2]]),c=n(o(l[1],l[0])),x=n(o(l[3],l[2])),i=n(r(x,c));x=r(c,i);let y=[x[0],x[1],x[2],c[0],c[1],c[2],i[0],i[1],i[2]],d=s(y),p=A.length===478?mA(e):{bearing:0,strength:0};return{angle:d,matrix:y,gaze:p}};function gn(e,t){let n=e==null?void 0:e.annotations;if(!n)return 0;let o=Math.max(Math.abs(n.leftEyeIris[3][0]-n.leftEyeIris[1][0]),Math.abs(n.rightEyeIris[3][0]-n.rightEyeIris[1][0]))/t;return Math.round(1.17/o)/100}var q5=async(e,t)=>{var p,f,b,M,T,m,h,S,P,I,q,t0,G,$,A0,v,V,n0,U,g0,m0,B,X;let n=g(),o,r,s,A,a,l,c,x,i,y=[];e.state="run:face";let d=await z3(t,e.config);if(e.performance.face=R.perfadd?(e.performance.face||0)+Math.trunc(g()-n):Math.trunc(g()-n),!t.shape||t.shape.length!==4)return[];if(!d)return[];for(let z=0;z200?bn(d[z],[t.shape[2],t.shape[1]]):null;e.analyze("Start Emotion:"),e.config.async?A=(f=e.config.face.emotion)!=null&&f.enabled?k5(d[z].tensor||l0.tensor([]),e.config,z,d.length):[]:(e.state="run:emotion",n=g(),A=(b=e.config.face.emotion)!=null&&b.enabled?await k5(d[z].tensor||l0.tensor([]),e.config,z,d.length):[],e.performance.emotion=R.perfadd?(e.performance.emotion||0)+Math.trunc(g()-n):Math.trunc(g()-n)),e.analyze("End Emotion:"),e.analyze("Start AntiSpoof:"),e.config.async?c=(M=e.config.face.antispoof)!=null&&M.enabled?j5(d[z].tensor||l0.tensor([]),e.config,z,d.length):0:(e.state="run:antispoof",n=g(),c=(T=e.config.face.antispoof)!=null&&T.enabled?await j5(d[z].tensor||l0.tensor([]),e.config,z,d.length):0,e.performance.antispoof=R.perfadd?(e.performance.antispoof||0)+Math.trunc(g()-n):Math.trunc(g()-n)),e.analyze("End AntiSpoof:"),e.analyze("Start Liveness:"),e.config.async?x=(m=e.config.face.liveness)!=null&&m.enabled?I5(d[z].tensor||l0.tensor([]),e.config,z,d.length):0:(e.state="run:liveness",n=g(),x=(h=e.config.face.liveness)!=null&&h.enabled?await I5(d[z].tensor||l0.tensor([]),e.config,z,d.length):0,e.performance.liveness=R.perfadd?(e.performance.antispoof||0)+Math.trunc(g()-n):Math.trunc(g()-n)),e.analyze("End Liveness:"),e.analyze("Start GEAR:"),e.config.async?r=(S=e.config.face.gear)!=null&&S.enabled?C5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null:(e.state="run:gear",n=g(),r=(P=e.config.face.gear)!=null&&P.enabled?await C5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,e.performance.gear=Math.trunc(g()-n)),e.analyze("End GEAR:"),e.analyze("Start SSRNet:"),e.config.async?(o=(I=e.config.face.ssrnet)!=null&&I.enabled?D5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,s=(q=e.config.face.ssrnet)!=null&&q.enabled?H5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null):(e.state="run:ssrnet",n=g(),o=(t0=e.config.face.ssrnet)!=null&&t0.enabled?await D5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,s=(G=e.config.face.ssrnet)!=null&&G.enabled?await H5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,e.performance.ssrnet=Math.trunc(g()-n)),e.analyze("End SSRNet:"),e.analyze("Start MobileFaceNet:"),e.config.async?a=($=e.config.face.mobilefacenet)!=null&&$.enabled?V5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null:(e.state="run:mobilefacenet",n=g(),a=(A0=e.config.face.mobilefacenet)!=null&&A0.enabled?await V5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,e.performance.mobilefacenet=Math.trunc(g()-n)),e.analyze("End MobileFaceNet:"),e.analyze("Start InsightFace:"),e.config.async?l=(v=e.config.face.insightface)!=null&&v.enabled?X5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null:(e.state="run:mobilefacenet",n=g(),l=(V=e.config.face.insightface)!=null&&V.enabled?await X5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,e.performance.mobilefacenet=Math.trunc(g()-n)),e.analyze("End InsightFace:"),e.analyze("Start Description:"),e.config.async?i=E5(d[z].tensor||l0.tensor([]),e.config,z,d.length):(e.state="run:description",n=g(),i=await E5(d[z].tensor||l0.tensor([]),e.config,z,d.length),e.performance.description=R.perfadd?(e.performance.description||0)+Math.trunc(g()-n):Math.trunc(g()-n)),e.analyze("End Description:"),e.config.async&&([o,s,A,a,l,i,r,c,x]=await Promise.all([o,s,A,a,l,i,r,c,x])),e.analyze("Finish Face:"),((n0=e.config.face.ssrnet)==null?void 0:n0.enabled)&&o&&s&&(i={...i,age:o.age,gender:s.gender,genderScore:s.genderScore}),((U=e.config.face.gear)==null?void 0:U.enabled)&&r&&(i={...i,age:r.age,gender:r.gender,genderScore:r.genderScore,race:r.race}),((g0=e.config.face.mobilefacenet)==null?void 0:g0.enabled)&&a&&(i.descriptor=a),((m0=e.config.face.insightface)==null?void 0:m0.enabled)&&l&&(i.descriptor=l);let we=(B=e.config.face.iris)!=null&&B.enabled?gn(d[z],t.shape[2]):0,Ee=(X=e.config.face.detector)!=null&&X.return?l0.squeeze(d[z].tensor):null;l0.dispose(d[z].tensor),d[z].tensor&&delete d[z].tensor;let T0={...d[z],id:z};i.age&&(T0.age=i.age),i.gender&&(T0.gender=i.gender),i.genderScore&&(T0.genderScore=i.genderScore),i.descriptor&&(T0.embedding=i.descriptor),i.race&&(T0.race=i.race),A&&(T0.emotion=A),c&&(T0.real=c),x&&(T0.live=x),we>0&&(T0.distance=we),ee&&(T0.rotation=ee),Ee&&(T0.tensor=Ee),y.push(T0),e.analyze("End Face")}return e.analyze("End FaceMesh:"),e.config.async&&(e.performance.face&&delete e.performance.face,e.performance.age&&delete e.performance.age,e.performance.gender&&delete e.performance.gender,e.performance.emotion&&delete e.performance.emotion),y};var W0={thumb:0,index:1,middle:2,ring:3,pinky:4,all:[0,1,2,3,4],nameMapping:{0:"thumb",1:"index",2:"middle",3:"ring",4:"pinky"},pointsMapping:{0:[[0,1],[1,2],[2,3],[3,4]],1:[[0,5],[5,6],[6,7],[7,8]],2:[[0,9],[9,10],[10,11],[11,12]],3:[[0,13],[13,14],[14,15],[15,16]],4:[[0,17],[17,18],[18,19],[19,20]]},getName:e=>W0.nameMapping[e],getPoints:e=>W0.pointsMapping[e]},Be={none:0,half:1,full:2,nameMapping:{0:"none",1:"half",2:"full"},getName:e=>Be.nameMapping[e]},c0={verticalUp:0,verticalDown:1,horizontalLeft:2,horizontalRight:3,diagonalUpRight:4,diagonalUpLeft:5,diagonalDownRight:6,diagonalDownLeft:7,nameMapping:{0:"verticalUp",1:"verticalDown",2:"horizontalLeft",3:"horizontalRight",4:"diagonalUpRight",5:"diagonalUpLeft",6:"diagonalDownRight",7:"diagonalDownLeft"},getName:e=>c0.nameMapping[e]},Fe=class{constructor(t){k(this,"name");k(this,"curls");k(this,"directions");k(this,"weights");k(this,"weightsRelative");this.name=t,this.curls={},this.directions={},this.weights=[1,1,1,1,1],this.weightsRelative=[1,1,1,1,1]}curl(t,n,o){typeof this.curls[t]=="undefined"&&(this.curls[t]=[]),this.curls[t].push([n,o])}direction(t,n,o){this.directions[t]||(this.directions[t]=[]),this.directions[t].push([n,o])}weight(t,n){this.weights[t]=n;let o=this.weights.reduce((r,s)=>r+s,0);this.weightsRelative=this.weights.map(r=>r*5/o)}matchAgainst(t,n){let o=0;for(let r in t){let s=t[r],A=this.curls[r];if(typeof A=="undefined"){o+=this.weightsRelative[r];continue}for(let[a,l]of A)if(s===a){o+=l*this.weightsRelative[r];break}}for(let r in n){let s=n[r],A=this.directions[r];if(typeof A=="undefined"){o+=this.weightsRelative[r];continue}for(let[a,l]of A)if(s===a){o+=l*this.weightsRelative[r];break}}return o/10}};var{thumb:xe,index:Me,middle:Pe,ring:r2,pinky:s2}=W0,{none:ye,half:uA,full:fe}=Be,{verticalUp:g2,verticalDown:G7,horizontalLeft:U5,horizontalRight:hA,diagonalUpRight:bA,diagonalUpLeft:T2,diagonalDownRight:V7,diagonalDownLeft:Z7}=c0,He=new Fe("thumbs up");He.curl(xe,ye,1);He.direction(xe,g2,1);He.direction(xe,T2,.25);He.direction(xe,bA,.25);for(let e of[W0.index,W0.middle,W0.ring,W0.pinky])He.curl(e,fe,1),He.direction(e,U5,1),He.direction(e,hA,1);var u0=new Fe("victory");u0.curl(xe,uA,.5);u0.curl(xe,ye,.5);u0.direction(xe,g2,1);u0.direction(xe,T2,1);u0.curl(Me,ye,1);u0.direction(Me,g2,.75);u0.direction(Me,T2,1);u0.curl(Pe,ye,1);u0.direction(Pe,g2,1);u0.direction(Pe,T2,.75);u0.curl(r2,fe,1);u0.direction(r2,g2,.2);u0.direction(r2,T2,1);u0.direction(r2,U5,.2);u0.curl(s2,fe,1);u0.direction(s2,g2,.2);u0.direction(s2,T2,1);u0.direction(s2,U5,.2);u0.weight(Me,2);u0.weight(Pe,2);var Ge=new Fe("point");Ge.curl(xe,fe,1);Ge.curl(Me,ye,.5);Ge.curl(Pe,fe,.5);Ge.curl(r2,fe,.5);Ge.curl(s2,fe,.5);Ge.weight(Me,2);Ge.weight(Pe,2);var Ve=new Fe("middle finger");Ve.curl(xe,ye,1);Ve.curl(Me,fe,.5);Ve.curl(Pe,fe,.5);Ve.curl(r2,fe,.5);Ve.curl(s2,fe,.5);Ve.weight(Me,2);Ve.weight(Pe,2);var v2=new Fe("open palm");v2.curl(xe,ye,.75);v2.curl(Me,ye,.75);v2.curl(Pe,ye,.75);v2.curl(r2,ye,.75);v2.curl(s2,ye,.75);var Tn=[He,u0,Ge,Ve,v2];var gA=.7,A2={HALF_CURL_START_LIMIT:60,NO_CURL_START_LIMIT:130,DISTANCE_VOTE_POWER:1.1,SINGLE_ANGLE_VOTE_POWER:.9,TOTAL_ANGLE_VOTE_POWER:1.6};function vn(e,t,n,o){let r=(t-o)/(e-n),s=Math.atan(r)*180/Math.PI;return s<=0?s=-s:s>0&&(s=180-s),s}function Mn(e,t){if(!e||!t)return[0,0];let n=vn(e[0],e[1],t[0],t[1]);if(e.length===2)return n;let o=vn(e[1],e[2],t[1],t[2]);return[n,o]}function Rn(e,t=1){let n=0,o=0,r=0;return e>=75&&e<=105?n=1*t:e>=25&&e<=155?o=1*t:r=1*t,[n,o,r]}function TA(e,t,n){let o=e[0]-t[0],r=e[0]-n[0],s=t[0]-n[0],A=e[1]-t[1],a=e[1]-n[1],l=t[1]-n[1],c=e[2]-t[2],x=e[2]-n[2],i=t[2]-n[2],y=Math.sqrt(o*o+A*A+c*c),d=Math.sqrt(r*r+a*a+x*x),p=Math.sqrt(s*s+l*l+i*i),f=(p*p+y*y-d*d)/(2*p*y);f>1?f=1:f<-1&&(f=-1);let b=Math.acos(f);b=57.2958*b%180;let M;return b>A2.NO_CURL_START_LIMIT?M=Be.none:b>A2.HALF_CURL_START_LIMIT?M=Be.half:M=Be.full,M}function Pn(e,t,n,o){let r;return o===Math.abs(e)?e>0?r=c0.horizontalLeft:r=c0.horizontalRight:o===Math.abs(t)?t>0?r=c0.horizontalLeft:r=c0.horizontalRight:n>0?r=c0.horizontalLeft:r=c0.horizontalRight,r}function kn(e,t,n,o){let r;return o===Math.abs(e)?e<0?r=c0.verticalDown:r=c0.verticalUp:o===Math.abs(t)?t<0?r=c0.verticalDown:r=c0.verticalUp:n<0?r=c0.verticalDown:r=c0.verticalUp,r}function vA(e,t,n,o,r,s,A,a){let l,c=kn(e,t,n,o),x=Pn(r,s,A,a);return c===c0.verticalUp?x===c0.horizontalLeft?l=c0.diagonalUpLeft:l=c0.diagonalUpRight:x===c0.horizontalLeft?l=c0.diagonalDownLeft:l=c0.diagonalDownRight,l}function RA(e,t,n,o){let r=e[0]-t[0],s=e[0]-n[0],A=t[0]-n[0],a=e[1]-t[1],l=e[1]-n[1],c=t[1]-n[1],x=Math.max(Math.abs(r),Math.abs(s),Math.abs(A)),i=Math.max(Math.abs(a),Math.abs(l),Math.abs(c)),y=0,d=0,p=0,f=i/(x+1e-5);f>1.5?y+=A2.DISTANCE_VOTE_POWER:f>.66?d+=A2.DISTANCE_VOTE_POWER:p+=A2.DISTANCE_VOTE_POWER;let b=Math.sqrt(r*r+a*a),M=Math.sqrt(s*s+l*l),T=Math.sqrt(A*A+c*c),m=Math.max(b,M,T),h=e[0],S=e[1],P=n[0],I=n[1];m===b?(P=n[0],I=n[1]):m===T&&(h=t[0],S=t[1]);let G=Mn([h,S],[P,I]),$=Rn(G,A2.TOTAL_ANGLE_VOTE_POWER);y+=$[0],d+=$[1],p+=$[2];for(let v of o){let V=Rn(v,A2.SINGLE_ANGLE_VOTE_POWER);y+=V[0],d+=V[1],p+=V[2]}let A0;return y===Math.max(y,d,p)?A0=kn(l,a,c,i):p===Math.max(d,p)?A0=Pn(s,r,A,x):A0=vA(l,a,c,i,s,r,A,x),A0}function wn(e){let t=[],n=[],o=[],r=[];if(!e)return{curls:o,directions:r};for(let s of W0.all){let A=W0.getPoints(s),a=[],l=[];for(let c of A){let x=e[c[0]],i=e[c[1]],y=Mn(x,i),d=y[0],p=y[1];a.push(d),l.push(p)}t.push(a),n.push(l)}for(let s of W0.all){let A=s===W0.thumb?1:0,a=W0.getPoints(s),l=e[a[A][0]],c=e[a[A+1][1]],x=e[a[3][1]],i=TA(l,c,x),y=RA(l,c,x,t[s].slice(A));o[s]=i,r[s]=y}return{curls:o,directions:r}}function Rt(e){if(!e||e.length===0)return null;let t=wn(e),n={};for(let o of W0.all)n[W0.getName(o)]={curl:Be.getName(t.curls[o]),direction:c0.getName(t.directions[o])};return n}function En(e){let t=[];if(!e||e.length===0)return t;let n=wn(e);for(let o of Tn){let r=o.matchAgainst(n.curls,n.directions);r>=gA&&t.push({name:o.name,confidence:r})}return t}var zn=e=>{if(!e)return[];let t=[];for(let n=0;nl.part==="leftWrist"),r=e[n].keypoints.find(l=>l.part==="rightWrist"),s=e[n].keypoints.find(l=>l.part==="nose");s&&o&&r&&o.position[1]l.part==="leftShoulder"),a=e[n].keypoints.find(l=>l.part==="rightShoulder");A&&a&&Math.abs(A.positionRaw[1]-a.positionRaw[1])>.1&&t.push({body:n,gesture:`leaning ${A.position[1]>a.position[1]?"left":"right"}`})}return t},Sn=e=>{if(!e)return[];let t=[];for(let n=0;n450){let o=(e[n].mesh[33][2]||0)-(e[n].mesh[263][2]||0),r=e[n].mesh[33][0]-e[n].mesh[263][0];Math.abs(o/r)<=.15?t.push({face:n,gesture:"facing center"}):t.push({face:n,gesture:`facing ${o<0?"left":"right"}`}),Math.abs(e[n].mesh[374][1]-e[n].mesh[386][1])/Math.abs(e[n].mesh[443][1]-e[n].mesh[450][1])<.2&&t.push({face:n,gesture:"blink left eye"}),Math.abs(e[n].mesh[145][1]-e[n].mesh[159][1])/Math.abs(e[n].mesh[223][1]-e[n].mesh[230][1])<.2&&t.push({face:n,gesture:"blink right eye"});let a=Math.min(100,500*Math.abs(e[n].mesh[13][1]-e[n].mesh[14][1])/Math.abs(e[n].mesh[10][1]-e[n].mesh[152][1]));a>10&&t.push({face:n,gesture:`mouth ${Math.trunc(a)}% open`});let l=e[n].mesh[152][2]||0;Math.abs(l)>10&&t.push({face:n,gesture:`head ${l<0?"up":"down"}`})}return t},jn=e=>{var n,o,r,s;if(!e)return[];let t=[];for(let A=0;A.06||b>.06)&&(d=!1),f>b?f>.05&&t.push({iris:A,gesture:"looking right"}):b>.05&&t.push({iris:A,gesture:"looking left"});let M=Math.abs(e[A].mesh[145][1]-e[A].annotations.rightEyeIris[0][1])/e[A].box[3],T=Math.abs(e[A].mesh[374][1]-e[A].annotations.leftEyeIris[0][1])/e[A].box[3];(T<.01||M<.01||T>.022||M>.022)&&(d=!1),(T<.01||M<.01)&&t.push({iris:A,gesture:"looking down"}),(T>.022||M>.022)&&t.push({iris:A,gesture:"looking up"}),d&&t.push({iris:A,gesture:"looking center"})}return t},Nn=e=>{if(!e)return[];let t=[];for(let n=0;n0){let r=o.reduce((A,a)=>(A.position[2]||0)<(a.position[2]||0)?A:a);t.push({hand:n,gesture:`${r.name} forward`});let s=o.reduce((A,a)=>A.position[1][s[0]*t[0],s[1]*t[1]]);return{startPoint:n,endPoint:o,palmLandmarks:r,confidence:e.confidence}}function Pt(e,t=1.5){let n=L2(e),o=Mt(e),r=[t*o[0]/2,t*o[1]/2],s=[n[0]-r[0],n[1]-r[1]],A=[n[0]+r[0],n[1]+r[1]];return{startPoint:s,endPoint:A,palmLandmarks:e.palmLandmarks}}function kt(e){let t=L2(e),n=Mt(e),r=Math.max(...n)/2,s=[t[0]-r,t[1]-r],A=[t[0]+r,t[1]+r];return{startPoint:s,endPoint:A,palmLandmarks:e.palmLandmarks}}function PA(e){return e-2*Math.PI*Math.floor((e+Math.PI)/(2*Math.PI))}function Dn(e,t){let n=Math.PI/2-Math.atan2(-(t[1]-e[1]),t[0]-e[0]);return PA(n)}var In=(e,t)=>[[1,0,e],[0,1,t],[0,0,1]];function Ze(e,t){let n=0;for(let o=0;o[A.x,A.y]),this.anchorsTensor=W.tensor2d(this.anchors),this.inputSize=((s=(r=(o=(n=this==null?void 0:this.model)==null?void 0:n.inputs)==null?void 0:o[0])==null?void 0:r.shape)==null?void 0:s[2])||0,this.inputSizeTensor=W.tensor1d([this.inputSize,this.inputSize]),this.doubleInputSizeTensor=W.tensor1d([this.inputSize*2,this.inputSize*2])}normalizeBoxes(t){let n={};n.boxOffsets=W.slice(t,[0,0],[-1,2]),n.boxSizes=W.slice(t,[0,2],[-1,2]),n.div=W.div(n.boxOffsets,this.inputSizeTensor),n.boxCenterPoints=W.add(n.div,this.anchorsTensor),n.halfBoxSizes=W.div(n.boxSizes,this.doubleInputSizeTensor),n.sub=W.sub(n.boxCenterPoints,n.halfBoxSizes),n.startPoints=W.mul(n.sub,this.inputSizeTensor),n.add=W.add(n.boxCenterPoints,n.halfBoxSizes),n.endPoints=W.mul(n.add,this.inputSizeTensor);let o=W.concat2d([n.startPoints,n.endPoints],1);return Object.keys(n).forEach(r=>W.dispose(n[r])),o}normalizeLandmarks(t,n){let o={};o.reshape=W.reshape(t,[-1,7,2]),o.div=W.div(o.reshape,this.inputSizeTensor),o.landmarks=W.add(o.div,this.anchors[n]?this.anchors[n]:0);let r=W.mul(o.landmarks,this.inputSizeTensor);return Object.keys(o).forEach(s=>W.dispose(o[s])),r}async predict(t,n){var a;let o={};o.resize=W.image.resizeBilinear(t,[this.inputSize,this.inputSize]),o.div=W.div(o.resize,C.tf127),o.image=W.sub(o.div,C.tf1),o.batched=this.model.execute(o.image),o.predictions=W.squeeze(o.batched),o.slice=W.slice(o.predictions,[0,0],[-1,1]),o.sigmoid=W.sigmoid(o.slice),o.scores=W.squeeze(o.sigmoid);let r=await o.scores.data();o.boxes=W.slice(o.predictions,[0,1],[-1,4]),o.norm=this.normalizeBoxes(o.boxes),o.nms=await W.image.nonMaxSuppressionAsync(o.norm,o.scores,3*(((a=n.hand)==null?void 0:a.maxDetected)||1),n.hand.iouThreshold,n.hand.minConfidence);let s=await o.nms.array(),A=[];for(let l of s){let c={};c.box=W.slice(o.norm,[l,0],[1,-1]),c.slice=W.slice(o.predictions,[l,5],[1,14]),c.norm=this.normalizeLandmarks(c.slice,l),c.palmLandmarks=W.reshape(c.norm,[-1,2]);let x=await c.box.data(),i=x.slice(0,2),y=x.slice(2,4),d=await c.palmLandmarks.array(),p={startPoint:i,endPoint:y,palmLandmarks:d,confidence:r[l]},f=Wn(p,[(t.shape[2]||1)/this.inputSize,(t.shape[1]||0)/this.inputSize]);A.push(f),Object.keys(c).forEach(b=>W.dispose(c[b]))}return Object.keys(o).forEach(l=>W.dispose(o[l])),A}};var U0=Z(H());var zA=5,Gn=1.65,Vn=[0,5,9,13,17,1,2],SA=0,jA=2,Zn=0,Et=class{constructor(t,n){k(this,"handDetector");k(this,"handPoseModel");k(this,"inputSize");k(this,"storedBoxes");k(this,"skipped");k(this,"detectedHands");var o,r,s;this.handDetector=t,this.handPoseModel=n,this.inputSize=((s=(r=(o=this.handPoseModel)==null?void 0:o.inputs)==null?void 0:r[0].shape)==null?void 0:s[2])||0,this.storedBoxes=[],this.skipped=Number.MAX_SAFE_INTEGER,this.detectedHands=0}calculateLandmarksBoundingBox(t){let n=t.map(A=>A[0]),o=t.map(A=>A[1]),r=[Math.min(...n),Math.min(...o)],s=[Math.max(...n),Math.max(...o)];return{startPoint:r,endPoint:s}}getBoxForPalmLandmarks(t,n){let o=t.map(s=>J5([...s,1],n)),r=this.calculateLandmarksBoundingBox(o);return Pt(kt(r),zA)}getBoxForHandLandmarks(t){let n=this.calculateLandmarksBoundingBox(t),o=Pt(kt(n),Gn);o.palmLandmarks=[];for(let r=0;r[A[0]*(d[0]-this.inputSize/2),A[1]*(d[1]-this.inputSize/2),A[2]*d[2]]),l=K5(o,[0,0]),c=a.map(d=>[...J5(d,l),d[2]]),x=Fn(r),i=[...L2(n),1],y=[Ze(i,x[0]),Ze(i,x[1])];return c.map(d=>[Math.trunc(d[0]+y[0]),Math.trunc(d[1]+y[1]),Math.trunc(d[2])])}async estimateHands(t,n){let o=!1,r,s=(n.hand.skipTime||0)>g()-Zn,A=this.skipped<(n.hand.skipFrames||0);n.skipAllowed&&s&&A&&(r=await this.handDetector.predict(t,n),this.skipped=0),n.skipAllowed&&this.skipped++,r&&r.length>0&&(r.length!==this.detectedHands&&this.detectedHands!==n.hand.maxDetected||!n.hand.landmarks)&&(this.detectedHands=0,this.storedBoxes=[...r],this.storedBoxes.length>0&&(o=!0));let a=[];for(let l=0;l=n.hand.minConfidence/4){let S=U0.reshape(m,[-1,3]),P=await S.array();U0.dispose(m),U0.dispose(S);let I=this.transformRawCoords(P,f,x,p),q=this.getBoxForHandLandmarks(I);this.storedBoxes[l]={...q,confidence:h};let t0={landmarks:I,confidence:h,boxConfidence:c.confidence,fingerConfidence:h,box:{topLeft:q.startPoint,bottomRight:q.endPoint}};a.push(t0)}else this.storedBoxes[l]=null;U0.dispose(m)}else{let x=Pt(kt(c),Gn),i={confidence:c.confidence,boxConfidence:c.confidence,fingerConfidence:0,box:{topLeft:x.startPoint,bottomRight:x.endPoint},landmarks:[]};a.push(i)}}return this.storedBoxes=this.storedBoxes.filter(l=>l!==null),this.detectedHands=a.length,a.length>n.hand.maxDetected&&(a.length=n.hand.maxDetected),a}};var Xn={thumb:[1,2,3,4],index:[5,6,7,8],middle:[9,10,11,12],ring:[13,14,15,16],pinky:[17,18,19,20],palm:[0]},a2,i2,qn;async function Q5(e,t){let n=await qn.estimateHands(e,t);if(!n)return[];let o=[];for(let r=0;rn[r].landmarks[i]);let A=n[r].landmarks,a=[Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,0,0],l=[0,0,0,0];if(A&&A.length>0){for(let x of A)x[0]a[2]&&(a[2]=x[0]),x[1]>a[3]&&(a[3]=x[1]);a[2]-=a[0],a[3]-=a[1],l=[a[0]/(e.shape[2]||0),a[1]/(e.shape[1]||0),a[2]/(e.shape[2]||0),a[3]/(e.shape[1]||0)]}else a=n[r].box?[Math.trunc(Math.max(0,n[r].box.topLeft[0])),Math.trunc(Math.max(0,n[r].box.topLeft[1])),Math.trunc(Math.min(e.shape[2]||0,n[r].box.bottomRight[0])-Math.max(0,n[r].box.topLeft[0])),Math.trunc(Math.min(e.shape[1]||0,n[r].box.bottomRight[1])-Math.max(0,n[r].box.topLeft[1]))]:[0,0,0,0],l=[n[r].box.topLeft[0]/(e.shape[2]||0),n[r].box.topLeft[1]/(e.shape[1]||0),(n[r].box.bottomRight[0]-n[r].box.topLeft[0])/(e.shape[2]||0),(n[r].box.bottomRight[1]-n[r].box.topLeft[1])/(e.shape[1]||0)];let c=Rt(A);o.push({id:r,score:Math.round(100*n[r].confidence)/100,boxScore:Math.round(100*n[r].boxConfidence)/100,fingerScore:Math.round(100*n[r].fingerConfidence)/100,label:"hand",box:a,boxRaw:l,keypoints:A,annotations:s,landmarks:c})}return o}async function Un(e){var n,o;R.initial&&(a2=null,i2=null),!a2||!i2?[a2,i2]=await Promise.all([e.hand.enabled?O((n=e.hand.detector)==null?void 0:n.modelPath):null,e.hand.landmarks?O((o=e.hand.skeleton)==null?void 0:o.modelPath):null]):(e.debug&&u("cached model:",a2.modelUrl),e.debug&&u("cached model:",i2.modelUrl));let t=a2?new wt(a2):void 0;return t&&i2&&(qn=new Et(t,i2)),[a2,i2]}var Q=Z(H());var f0=[null,null],IA=["StatefulPartitionedCall/Postprocessor/Slice","StatefulPartitionedCall/Postprocessor/ExpandDims_1"],Xe=[[0,0],[0,0]],OA=["hand","fist","pinch","point","face","tip","pinchtip"],Kn=4,Jn=1.6,LA=512,CA=1.4,zt=Number.MAX_SAFE_INTEGER,_5=0,ke=[0,0],y0={boxes:[],hands:[]},Qn={thumb:[1,2,3,4],index:[5,6,7,8],middle:[9,10,11,12],ring:[13,14,15,16],pinky:[17,18,19,20],base:[0],palm:[0,17,13,9,5,1,0]};async function _n(e){var t;if(R.initial&&(f0[0]=null),f0[0])e.debug&&u("cached model:",f0[0].modelUrl);else{Y2(["tensorlistreserve","enter","tensorlistfromtensor","merge","loopcond","switch","exit","tensorliststack","nextiteration","tensorlistsetitem","tensorlistgetitem","reciprocal","shape","split","where"],e),f0[0]=await O((t=e.hand.detector)==null?void 0:t.modelPath);let n=f0[0].executor?Object.values(f0[0].modelSignature.inputs):void 0;Xe[0][0]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[1].size):0,Xe[0][1]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[2].size):0}return f0[0]}async function $n(e){var t;if(R.initial&&(f0[1]=null),f0[1])e.debug&&u("cached model:",f0[1].modelUrl);else{f0[1]=await O((t=e.hand.skeleton)==null?void 0:t.modelPath);let n=f0[1].executor?Object.values(f0[1].modelSignature.inputs):void 0;Xe[1][0]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[1].size):0,Xe[1][1]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[2].size):0}return f0[1]}async function WA(e,t){let n=[];if(!e||!f0[0])return n;let o={},r=(e.shape[2]||1)/(e.shape[1]||1),s=Math.min(Math.round((e.shape[1]||0)/8)*8,LA),A=Math.round(s*r/8)*8;o.resize=Q.image.resizeBilinear(e,[s,A]),o.cast=Q.cast(o.resize,"int32"),[o.rawScores,o.rawBoxes]=await f0[0].executeAsync(o.cast,IA),o.boxes=Q.squeeze(o.rawBoxes,[0,2]),o.scores=Q.squeeze(o.rawScores,[0]);let a=Q.unstack(o.scores,1);Q.dispose(a[Kn]),a.splice(Kn,1),o.filtered=Q.stack(a,1),Q.dispose(a),o.max=Q.max(o.filtered,1),o.argmax=Q.argMax(o.filtered,1);let l=0;o.nms=await Q.image.nonMaxSuppressionAsync(o.boxes,o.max,(t.hand.maxDetected||0)+1,t.hand.iouThreshold||0,t.hand.minConfidence||1);let c=await o.nms.data(),x=await o.max.data(),i=await o.argmax.data();for(let y of Array.from(c)){let d=Q.slice(o.boxes,y,1),p=await d.data();Q.dispose(d);let f=[p[1],p[0],p[3]-p[1],p[2]-p[0]],b=ot(f,CA),M=[Math.trunc(f[0]*ke[0]),Math.trunc(f[1]*ke[1]),Math.trunc(f[2]*ke[0]),Math.trunc(f[3]*ke[1])],T=x[y],m=OA[i[y]],h={id:l++,score:T,box:M,boxRaw:b,label:m};n.push(h)}return Object.keys(o).forEach(y=>Q.dispose(o[y])),n.sort((y,d)=>d.score-y.score),n.length>(t.hand.maxDetected||1)&&(n.length=t.hand.maxDetected||1),n}async function $5(e,t,n){let o={id:t.id,score:Math.round(100*t.score)/100,boxScore:Math.round(100*t.score)/100,fingerScore:0,box:t.box,boxRaw:t.boxRaw,label:t.label,keypoints:[],landmarks:{},annotations:{}};if(e&&f0[1]&&n.hand.landmarks&&t.score>(n.hand.minConfidence||0)){let r={},s=[t.boxRaw[1],t.boxRaw[0],t.boxRaw[3]+t.boxRaw[1],t.boxRaw[2]+t.boxRaw[0]];r.crop=Q.image.cropAndResize(e,[s],[0],[Xe[1][0],Xe[1][1]],"bilinear"),r.div=Q.div(r.crop,C.tf255),[r.score,r.keypoints]=f0[1].execute(r.div,["Identity_1","Identity"]);let A=(await r.score.data())[0],a=(100-Math.trunc(100/(1+Math.exp(A))))/100;if(a>=(n.hand.minConfidence||0)){o.fingerScore=a,r.reshaped=Q.reshape(r.keypoints,[-1,3]);let x=(await r.reshaped.array()).map(i=>[i[0]/Xe[1][1],i[1]/Xe[1][0],i[2]||0]).map(i=>[i[0]*t.boxRaw[2],i[1]*t.boxRaw[3],i[2]||0]);o.keypoints=x.map(i=>[ke[0]*(i[0]+t.boxRaw[0]),ke[1]*(i[1]+t.boxRaw[1]),i[2]||0]),o.landmarks=Rt(o.keypoints);for(let i of Object.keys(Qn))o.annotations[i]=Qn[i].map(y=>o.landmarks&&o.keypoints[y]?o.keypoints[y]:null)}Object.keys(r).forEach(l=>Q.dispose(r[l]))}return o}async function e1(e,t){var r,s;if(!((r=f0[0])!=null&&r.executor)||!((s=f0[1])!=null&&s.executor)||!f0[0].inputs[0].shape||!f0[1].inputs[0].shape)return[];ke=[e.shape[2]||0,e.shape[1]||0],zt++;let n=(t.hand.skipTime||0)>g()-_5,o=zt<(t.hand.skipFrames||0);return t.skipAllowed&&n&&o?y0.hands:new Promise(async A=>{let a=3*(t.hand.skipTime||0)>g()-_5,l=zt<3*(t.hand.skipFrames||0);t.skipAllowed&&y0.hands.length===t.hand.maxDetected?y0.hands=await Promise.all(y0.boxes.map(x=>$5(e,x,t))):t.skipAllowed&&a&&l&&y0.hands.length>0?y0.hands=await Promise.all(y0.boxes.map(x=>$5(e,x,t))):(y0.boxes=await WA(e,t),_5=g(),y0.hands=await Promise.all(y0.boxes.map(x=>$5(e,x,t))),zt=0);let c=[...y0.boxes];if(y0.boxes.length=0,t.cacheSensitivity>0)for(let x=0;x.05&&i.box[3]/(e.shape[1]||1)>.05&&y0.hands[x].fingerScore&&y0.hands[x].fingerScore>(t.hand.minConfidence||0)){let y=ot(i.box,Jn),d=ot(i.boxRaw,Jn);y0.boxes.push({...c[x],box:y,boxRaw:d})}}for(let x=0;x({face:[],body:[],hand:[],gesture:[],object:[],persons:[],performance:{},timestamp:0,width:0,height:0,error:e});var C2={};ze(C2,{connected:()=>jt,horizontal:()=>t1,kpt:()=>St,relative:()=>o1,vertical:()=>n1});var St=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"],t1=[["leftEye","rightEye"],["leftEar","rightEar"],["leftShoulder","rightShoulder"],["leftElbow","rightElbow"],["leftWrist","rightWrist"],["leftHip","rightHip"],["leftKnee","rightKnee"],["leftAnkle","rightAnkle"]],n1=[["leftKnee","leftShoulder"],["rightKnee","rightShoulder"],["leftAnkle","leftKnee"],["rightAnkle","rightKnee"]],o1=[[["leftHip","rightHip"],["leftShoulder","rightShoulder"]],[["leftElbow","rightElbow"],["leftShoulder","rightShoulder"]]],jt={leftLeg:["leftHip","leftKnee","leftAnkle"],rightLeg:["rightHip","rightKnee","rightAnkle"],torso:["leftShoulder","rightShoulder","rightHip","leftHip","leftShoulder"],leftArm:["leftShoulder","leftElbow","leftWrist"],rightArm:["rightShoulder","rightElbow","rightWrist"],head:[]};var w=he(),r1=0;function to(e,t){var A,a,l,c,x,i,y,d,p,f,b,M,T,m,h,S,P,I,q,t0,G,$,A0;let n=g();if(!e)return he();let o=Date.now()-e.timestamp,r=o<1e3?8-Math.log(o+1):1;if(e.canvas&&(w.canvas=e.canvas),e.error&&(w.error=e.error),!w.body||e.body.length!==w.body.length)w.body=JSON.parse(JSON.stringify(e.body));else for(let v=0;v((r-1)*w.body[v].box[X]+B)/r),n0=e.body[v].boxRaw.map((B,X)=>((r-1)*w.body[v].boxRaw[X]+B)/r),U=e.body[v].keypoints.map((B,X)=>{var z,ee,we,Ee,T0,P2,R1,M1,P1;return{score:B.score,part:B.part,position:[w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].position[0]||0)+(B.position[0]||0))/r:B.position[0],w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].position[1]||0)+(B.position[1]||0))/r:B.position[1],w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].position[2]||0)+(B.position[2]||0))/r:B.position[2]],positionRaw:[w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].positionRaw[0]||0)+(B.positionRaw[0]||0))/r:B.positionRaw[0],w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].positionRaw[1]||0)+(B.positionRaw[1]||0))/r:B.positionRaw[1],w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].positionRaw[2]||0)+(B.positionRaw[2]||0))/r:B.positionRaw[2]],distance:[w.body[v].keypoints[X]?((r-1)*(((z=w.body[v].keypoints[X].distance)==null?void 0:z[0])||0)+(((ee=B.distance)==null?void 0:ee[0])||0))/r:(we=B.distance)==null?void 0:we[0],w.body[v].keypoints[X]?((r-1)*(((Ee=w.body[v].keypoints[X].distance)==null?void 0:Ee[1])||0)+(((T0=B.distance)==null?void 0:T0[1])||0))/r:(P2=B.distance)==null?void 0:P2[1],w.body[v].keypoints[X]?((r-1)*(((R1=w.body[v].keypoints[X].distance)==null?void 0:R1[2])||0)+(((M1=B.distance)==null?void 0:M1[2])||0))/r:(P1=B.distance)==null?void 0:P1[2]]}}),g0={},m0={connected:{}};(A=t.body.modelPath)!=null&&A.includes("efficientpose")?m0=At:(a=t.body.modelPath)!=null&&a.includes("blazepose")?m0=tt:(l=t.body.modelPath)!=null&&l.includes("movenet")&&(m0=C2);for(let[B,X]of Object.entries(m0.connected)){let z=[];for(let ee=0;eeT0.part===X[ee]),Ee=U.find(T0=>T0.part===X[ee+1]);we&&Ee&&z.push([we.position,Ee.position])}g0[B]=z}w.body[v]={...e.body[v],box:V,boxRaw:n0,keypoints:U,annotations:g0}}if(!w.hand||e.hand.length!==w.hand.length)w.hand=JSON.parse(JSON.stringify(e.hand));else for(let v=0;v((r-1)*w.hand[v].box[B]+m0)/r),n0=e.hand[v].boxRaw.map((m0,B)=>((r-1)*w.hand[v].boxRaw[B]+m0)/r);w.hand[v].keypoints.length!==e.hand[v].keypoints.length&&(w.hand[v].keypoints=e.hand[v].keypoints);let U=e.hand[v].keypoints&&e.hand[v].keypoints.length>0?e.hand[v].keypoints.map((m0,B)=>m0.map((X,z)=>((r-1)*(w.hand[v].keypoints[B][z]||1)+(X||0))/r)):[],g0={};if(Object.keys(w.hand[v].annotations).length!==Object.keys(e.hand[v].annotations).length)w.hand[v].annotations=e.hand[v].annotations,g0=w.hand[v].annotations;else if(e.hand[v].annotations)for(let m0 of Object.keys(e.hand[v].annotations))g0[m0]=(i=(x=(c=e.hand[v])==null?void 0:c.annotations)==null?void 0:x[m0])!=null&&i[0]?e.hand[v].annotations[m0].map((B,X)=>B.map((z,ee)=>((r-1)*w.hand[v].annotations[m0][X][ee]+z)/r)):null;w.hand[v]={...e.hand[v],box:V,boxRaw:n0,keypoints:U,annotations:g0}}if(!w.face||e.face.length!==w.face.length)w.face=JSON.parse(JSON.stringify(e.face));else for(let v=0;v((r-1)*w.face[v].box[g0]+U)/r),n0=e.face[v].boxRaw.map((U,g0)=>((r-1)*w.face[v].boxRaw[g0]+U)/r);if(e.face[v].rotation){let U={matrix:[0,0,0,0,0,0,0,0,0],angle:{roll:0,yaw:0,pitch:0},gaze:{bearing:0,strength:0}};U.matrix=(y=e.face[v].rotation)==null?void 0:y.matrix,U.angle={roll:((r-1)*(((p=(d=w.face[v].rotation)==null?void 0:d.angle)==null?void 0:p.roll)||0)+(((b=(f=e.face[v].rotation)==null?void 0:f.angle)==null?void 0:b.roll)||0))/r,yaw:((r-1)*(((T=(M=w.face[v].rotation)==null?void 0:M.angle)==null?void 0:T.yaw)||0)+(((h=(m=e.face[v].rotation)==null?void 0:m.angle)==null?void 0:h.yaw)||0))/r,pitch:((r-1)*(((P=(S=w.face[v].rotation)==null?void 0:S.angle)==null?void 0:P.pitch)||0)+(((q=(I=e.face[v].rotation)==null?void 0:I.angle)==null?void 0:q.pitch)||0))/r},U.gaze={bearing:((r-1)*(((t0=w.face[v].rotation)==null?void 0:t0.gaze.bearing)||0)+(((G=e.face[v].rotation)==null?void 0:G.gaze.bearing)||0))/r,strength:((r-1)*((($=w.face[v].rotation)==null?void 0:$.gaze.strength)||0)+(((A0=e.face[v].rotation)==null?void 0:A0.gaze.strength)||0))/r},w.face[v]={...e.face[v],rotation:U,box:V,boxRaw:n0}}else w.face[v]={...e.face[v],box:V,boxRaw:n0}}if(!w.object||e.object.length!==w.object.length)w.object=JSON.parse(JSON.stringify(e.object));else for(let v=0;v((r-1)*w.object[v].box[g0]+U)/r),n0=e.object[v].boxRaw.map((U,g0)=>((r-1)*w.object[v].boxRaw[g0]+U)/r);w.object[v]={...e.object[v],box:V,boxRaw:n0}}if(e.persons){let v=e.persons;if(!w.persons||v.length!==w.persons.length)w.persons=JSON.parse(JSON.stringify(v));else for(let V=0;V((r-1)*w.persons[V].box[U]+n0)/r)}e.gesture&&(w.gesture=e.gesture),w.width=e.width,w.height=e.height;let s=g();return r1=R.perfadd?r1+Math.round(s-n):Math.round(s-n),e.performance&&(w.performance={...e.performance,interpolate:r1}),w}var s0=Z(H());var j0;async function s1(e){return!j0||R.initial?j0=await O(e.segmentation.modelPath):e.debug&&u("cached model:",j0.modelUrl),j0}async function no(e,t){var r;if(j0||(j0=await s1(t)),!(j0!=null&&j0.executor)||!((r=j0==null?void 0:j0.inputs)!=null&&r[0].shape))return null;let n={};n.resize=s0.image.resizeBilinear(e,[j0.inputs[0].shape?j0.inputs[0].shape[1]:0,j0.inputs[0].shape?j0.inputs[0].shape[2]:0],!1),n.norm=s0.div(n.resize,C.tf255),n.res=j0.execute(n.norm),n.squeeze=s0.squeeze(n.res,[0]),[n.bgRaw,n.fgRaw]=s0.unstack(n.squeeze,2),n.fg=s0.softmax(n.fgRaw),n.mul=s0.mul(n.fg,C.tf255),n.expand=s0.expandDims(n.mul,2),n.output=s0.image.resizeBilinear(n.expand,[e.shape[1]||0,e.shape[2]||0]);let o;switch(t.segmentation.mode||"default"){case"default":n.input=s0.squeeze(e),n.concat=s0.concat([n.input,n.output],-1),o=s0.cast(n.concat,"int32");break;case"alpha":o=s0.cast(n.output,"int32");break;default:o=s0.tensor(0)}return Object.keys(n).forEach(s=>s0.dispose(n[s])),o}var Nt={};ze(Nt,{distance:()=>A1,find:()=>BA,similarity:()=>FA});function A1(e,t,n={order:2,multiplier:25}){if(!e||!e)return Number.MAX_SAFE_INTEGER;let o=0;for(let r=0;r{if(e===0)return 1;let s=(1-(t===2?Math.sqrt(e):e**(1/t))/100-n)/(o-n);return Math.max(Math.min(s,1),0)};function FA(e,t,n={order:2,multiplier:25,min:.2,max:.8}){let o=A1(e,t,n);return ro(o,n.order||2,n.min||0,n.max||1)}function BA(e,t,n={order:2,multiplier:25,threshold:0,min:.2,max:.8}){if(!Array.isArray(e)||!Array.isArray(t)||e.length<64||t.length===0)return{index:-1,distance:Number.POSITIVE_INFINITY,similarity:0};let o=Number.MAX_SAFE_INTEGER,r=-1;for(let A=0;AF2,validateModel:()=>Ft});var lo=Z(H());var qe=Z(H());var so=.005,Y0={keypoints:[],padding:[[0,0],[0,0],[0,0],[0,0]]};function a1(e){for(let t of t1){let n=e.keypoints.findIndex(r=>r.part===t[0]),o=e.keypoints.findIndex(r=>r.part===t[1]);if(e.keypoints[n]&&e.keypoints[o]&&e.keypoints[n].position[0]r&&r.part===t[0]),o=e.keypoints.findIndex(r=>r&&r.part===t[1]);e.keypoints[n]&&e.keypoints[o]&&e.keypoints[n].position[1]c&&c.part===t[0]),r=e.keypoints.findIndex(c=>c&&c.part===t[1]),s=e.keypoints.findIndex(c=>c&&c.part===n[0]),A=e.keypoints.findIndex(c=>c&&c.part===n[1]);if(!e.keypoints[s]||!e.keypoints[A])continue;let a=e.keypoints[o]?[Math.abs(e.keypoints[s].position[0]-e.keypoints[o].position[0]),Math.abs(e.keypoints[A].position[0]-e.keypoints[o].position[0])]:[0,0],l=e.keypoints[r]?[Math.abs(e.keypoints[A].position[0]-e.keypoints[r].position[0]),Math.abs(e.keypoints[s].position[0]-e.keypoints[r].position[0])]:[0,0];if(a[0]>a[1]||l[0]>l[1]){let c=e.keypoints[o];e.keypoints[o]=e.keypoints[r],e.keypoints[r]=c}}}function Ao(e){for(let t=0;te.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0,e.shape[2]>e.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0],[e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0,e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0],[0,0]],n.pad=qe.pad(e,Y0.padding),n.resize=qe.image.resizeBilinear(n.pad,[t,t]);let o=qe.cast(n.resize,"int32");return Object.keys(n).forEach(A=>qe.dispose(n[A])),o}function io(e,t){e.keypoints=e.keypoints.filter(o=>o==null?void 0:o.position);for(let o of e.keypoints)o.position=[o.position[0]*(t[0]+Y0.padding[2][0]+Y0.padding[2][1])/t[0]-Y0.padding[2][0],o.position[1]*(t[1]+Y0.padding[1][0]+Y0.padding[1][1])/t[1]-Y0.padding[1][0]],o.positionRaw=[o.position[0]/t[0],o.position[1]/t[1]];let n=ve(e.keypoints.map(o=>o.position),t);return e.box=n.box,e.boxRaw=n.boxRaw,e}var h0,It=0,i1=Number.MAX_SAFE_INTEGER,l2={boxes:[],bodies:[],last:0};async function co(e){var t;return R.initial&&(h0=null),h0?e.debug&&u("cached model:",h0.modelUrl):(Y2(["size"],e),h0=await O(e.body.modelPath)),It=(h0==null?void 0:h0.executor)&&((t=h0==null?void 0:h0.inputs)==null?void 0:t[0].shape)?h0.inputs[0].shape[2]:0,It<64&&(It=256),h0}function GA(e,t,n){let o=e[0][0],r=[],s=0;for(let x=0;xt.body.minConfidence){let i=[o[x][1],o[x][0]];r.push({score:Math.round(100*s)/100,part:St[x],positionRaw:i,position:[Math.round((n.shape[2]||0)*i[0]),Math.round((n.shape[1]||0)*i[1])]})}s=r.reduce((x,i)=>i.score>x?i.score:x,0);let A=[],a=ve(r.map(x=>x.position),[n.shape[2],n.shape[1]]),l={};for(let[x,i]of Object.entries(jt)){let y=[];for(let d=0;db.part===i[d]),f=r.find(b=>b.part===i[d+1]);p&&f&&p.score>(t.body.minConfidence||0)&&f.score>(t.body.minConfidence||0)&&y.push([p.position,f.position])}l[x]=y}let c={id:0,score:s,box:a.box,boxRaw:a.boxRaw,keypoints:r,annotations:l};return a1(c),A.push(c),A}function VA(e,t,n){let o=[];for(let r=0;rt.body.minConfidence){let a=[];for(let i=0;i<17;i++){let y=s[3*i+2];if(y>t.body.minConfidence){let d=[s[3*i+1],s[3*i+0]];a.push({part:St[i],score:Math.round(100*y)/100,positionRaw:d,position:[Math.round((n.shape[2]||0)*d[0]),Math.round((n.shape[1]||0)*d[1])]})}}let l=ve(a.map(i=>i.position),[n.shape[2],n.shape[1]]),c={};for(let[i,y]of Object.entries(jt)){let d=[];for(let p=0;pM.part===y[p]),b=a.find(M=>M.part===y[p+1]);f&&b&&f.score>(t.body.minConfidence||0)&&b.score>(t.body.minConfidence||0)&&d.push([f.position,b.position])}c[i]=d}let x={id:r,score:A,box:l.box,boxRaw:l.boxRaw,keypoints:[...a],annotations:c};a1(x),o.push(x)}}return o.sort((r,s)=>s.score-r.score),o.length>t.body.maxDetected&&(o.length=t.body.maxDetected),o}async function l1(e,t){var r;if(!(h0!=null&&h0.executor)||!((r=h0==null?void 0:h0.inputs)!=null&&r[0].shape))return[];t.skipAllowed||(l2.boxes.length=0),i1++;let n=(t.body.skipTime||0)>g()-l2.last,o=i1<(t.body.skipFrames||0);return t.skipAllowed&&n&&o?l2.bodies:new Promise(async s=>{let A={};i1=0,A.input=ao(e,It),A.res=h0==null?void 0:h0.execute(A.input),l2.last=g();let a=await A.res.array();l2.bodies=A.res.shape[2]===17?GA(a,t,e):VA(a,t,e);for(let l of l2.bodies)io(l,[e.shape[2]||1,e.shape[1]||1]),Ao(l.keypoints);Object.keys(A).forEach(l=>lo.dispose(A[l])),s(l2.bodies)})}var w0=Z(H());var Ae,Ot=[],yo=0,c1=Number.MAX_SAFE_INTEGER,Ct=0,Lt=2.5;async function fo(e){if(!Ae||R.initial){Ae=await O(e.object.modelPath);let t=Ae!=null&&Ae.executor?Object.values(Ae.modelSignature.inputs):void 0;Ct=Array.isArray(t)?parseInt(t[0].tensorShape.dim[2].size):416}else e.debug&&u("cached model:",Ae.modelUrl);return Ae}async function ZA(e,t,n){var c,x;let o=0,r=[],s=Ct;for(let i of[1,2,4]){let y=i*13,d=w0.squeeze(e.find(m=>m.shape[1]===y**2&&(m.shape[2]||0)===x2.length)),p=await d.array(),f=w0.squeeze(e.find(m=>m.shape[1]===y**2&&(m.shape[2]||0)(n.object.minConfidence||0)&&h!==61){let P=(.5+Math.trunc(m%y))/y,I=(.5+Math.trunc(m/y))/y,q=T[m].map(U=>U*(y/i/s)),[t0,G]=[P-Lt/i*q[0],I-Lt/i*q[1]],[$,A0]=[P+Lt/i*q[2]-t0,I+Lt/i*q[3]-G],v=[t0,G,$,A0];v=v.map(U=>Math.max(0,Math.min(U,1)));let V=[v[0]*t[0],v[1]*t[1],v[2]*t[0],v[3]*t[1]],n0={id:o++,score:Math.round(100*S)/100,class:h+1,label:x2[h].label,box:V.map(U=>Math.trunc(U)),boxRaw:v};r.push(n0)}}w0.dispose([d,f,b,M])}let A=r.map(i=>[i.boxRaw[1],i.boxRaw[0],i.boxRaw[3],i.boxRaw[2]]),a=r.map(i=>i.score),l=[];if(A&&A.length>0){let i=await w0.image.nonMaxSuppressionAsync(A,a,n.object.maxDetected||0,n.object.iouThreshold,n.object.minConfidence);l=Array.from(await i.data()),w0.dispose(i)}return r=r.filter((i,y)=>l.includes(y)).sort((i,y)=>y.score-i.score),r}async function d1(e,t){if(!(Ae!=null&&Ae.executor))return[];let n=(t.object.skipTime||0)>g()-yo,o=c1<(t.object.skipFrames||0);return t.skipAllowed&&n&&o&&Ot.length>0?(c1++,Ot):(c1=0,!R.kernels.includes("mod")||!R.kernels.includes("sparsetodense")?Ot:new Promise(async r=>{let s=[e.shape[2]||0,e.shape[1]||0],A=w0.image.resizeBilinear(e,[Ct,Ct],!1),a=w0.div(A,C.tf255),l=w0.transpose(a,[0,3,1,2]),c;t.object.enabled&&(c=Ae.execute(l)),yo=g();let x=await ZA(c,s,t);Ot=x,w0.dispose([A,a,l,...c]),r(x)}))}var D0=Z(H());var D2=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"],XA=D2.length,W2=D2.reduce((e,t,n)=>(e[t]=n,e),{}),qA=[["leftHip","leftShoulder"],["leftElbow","leftShoulder"],["leftElbow","leftWrist"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["rightHip","rightShoulder"],["rightElbow","rightShoulder"],["rightElbow","rightWrist"],["rightHip","rightKnee"],["rightKnee","rightAnkle"],["leftShoulder","rightShoulder"],["leftHip","rightHip"]],Li=qA.map(([e,t])=>[W2[e],W2[t]]),po=[["nose","leftEye"],["leftEye","leftEar"],["nose","rightEye"],["rightEye","rightEar"],["nose","leftShoulder"],["leftShoulder","leftElbow"],["leftElbow","leftWrist"],["leftShoulder","leftHip"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["nose","rightShoulder"],["rightShoulder","rightElbow"],["rightElbow","rightWrist"],["rightShoulder","rightHip"],["rightHip","rightKnee"],["rightKnee","rightAnkle"]];function uo(e){let t=e.reduce(({maxX:n,maxY:o,minX:r,minY:s},{position:{x:A,y:a}})=>({maxX:Math.max(n,A),maxY:Math.max(o,a),minX:Math.min(r,A),minY:Math.min(s,a)}),{maxX:Number.NEGATIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY,minX:Number.POSITIVE_INFINITY,minY:Number.POSITIVE_INFINITY});return[t.minX,t.minY,t.maxX-t.minX,t.maxY-t.minY]}function ho(e,[t,n],[o,r]){let s=t/o,A=n/r,a=(c,x)=>({id:x,score:c.score,boxRaw:[c.box[0]/r,c.box[1]/o,c.box[2]/r,c.box[3]/o],box:[Math.trunc(c.box[0]*A),Math.trunc(c.box[1]*s),Math.trunc(c.box[2]*A),Math.trunc(c.box[3]*s)],keypoints:c.keypoints.map(({score:i,part:y,position:d})=>({score:i,part:y,position:[Math.trunc(d.x*A),Math.trunc(d.y*s)],positionRaw:[d.x/o,d.y/o]})),annotations:{}});return e.map((c,x)=>a(c,x))}var Wt=class{constructor(t,n){k(this,"priorityQueue");k(this,"numberOfElements");k(this,"getElementValue");this.priorityQueue=new Array(t),this.numberOfElements=-1,this.getElementValue=n}enqueue(t){this.priorityQueue[++this.numberOfElements]=t,this.swim(this.numberOfElements)}dequeue(){let t=this.priorityQueue[0];return this.exchange(0,this.numberOfElements--),this.sink(0),this.priorityQueue[this.numberOfElements+1]=null,t}empty(){return this.numberOfElements===-1}size(){return this.numberOfElements+1}all(){return this.priorityQueue.slice(0,this.numberOfElements+1)}max(){return this.priorityQueue[0]}swim(t){for(;t>0&&this.less(Math.floor(t/2),t);)this.exchange(t,Math.floor(t/2)),t=Math.floor(t/2)}sink(t){for(;2*t<=this.numberOfElements;){let n=2*t;if(nn?n:e}function bo(e,t,n,o){let r=n-e,s=o-t;return r*r+s*s}function m1(e,t){return{x:e.x+t.x,y:e.y+t.y}}var K0,YA=["MobilenetV1/offset_2/BiasAdd","MobilenetV1/heatmap_2/BiasAdd","MobilenetV1/displacement_fwd_2/BiasAdd","MobilenetV1/displacement_bwd_2/BiasAdd"],Dt=1,R2=16,KA=50**2;function go(e,t,n,o,r,s,A=2){let a=M=>({y:s.get(M.y,M.x,e),x:s.get(M.y,M.x,s.shape[2]/2+e)}),l=(M,T,m)=>({y:f1(Math.round(M.y/R2),0,T-1),x:f1(Math.round(M.x/R2),0,m-1)}),[c,x]=o.shape,i=l(t.position,c,x),y=a(i),p=m1(t.position,y);for(let M=0;M[W2[y],W2[d]]),A=s.map(([,y])=>y),a=s.map(([y])=>y),l=t.shape[2],c=A.length,x=new Array(l),i=y1(e.part,R2,n);x[e.part.id]={score:e.score,part:D2[e.part.id],position:i};for(let y=c-1;y>=0;--y){let d=A[y],p=a[y];x[d]&&!x[p]&&(x[p]=go(y,x[d],p,t,n,r))}for(let y=0;yt){a=!1;break}if(!a)break}return a}function _A(e,t){let[n,o,r]=t.shape,s=new Wt(n*o*r,({score:A})=>A);for(let A=0;A{var A;let s=(A=r[o])==null?void 0:A.position;return s?bo(n,t,s.y,s.x)<=KA:!1})}function $A(e,t){return t.reduce((o,{position:r,score:s},A)=>(To(e,r,A)||(o+=s),o),0)/t.length}function ea(e,t,n,o,r,s){let A=[],a=_A(s,t);for(;A.lengthd.score>s);let i=$A(A,x),y=uo(x);i>s&&A.push({keypoints:x,box:y,score:Math.round(100*i)/100})}return A}async function p1(e,t){if(!(K0!=null&&K0.executor))return[];let n=D0.tidy(()=>{if(!K0.inputs[0].shape)return[];let A=D0.image.resizeBilinear(e,[K0.inputs[0].shape[2],K0.inputs[0].shape[1]]),a=D0.sub(D0.div(D0.cast(A,"float32"),127.5),1),c=K0.execute(a,YA).map(x=>D0.squeeze(x,[0]));return c[1]=D0.sigmoid(c[1]),c}),o=await Promise.all(n.map(A=>A.buffer()));for(let A of n)D0.dispose(A);let r=ea(o[0],o[1],o[2],o[3],t.body.maxDetected,t.body.minConfidence);return K0.inputs[0].shape?ho(r,[e.shape[1],e.shape[2]],[K0.inputs[0].shape[2],K0.inputs[0].shape[1]]):[]}async function vo(e){return!K0||R.initial?K0=await O(e.body.modelPath):e.debug&&u("cached model:",K0.modelUrl),K0}var F=Z(H());var be,ta=["fgr","pha","r1o","r2o","r3o","r4o"],b0={},h1=0;function Po(e){F.dispose([b0.r1i,b0.r2i,b0.r3i,b0.r4i,b0.downsample_ratio]),b0.r1i=F.tensor(0),b0.r2i=F.tensor(0),b0.r3i=F.tensor(0),b0.r4i=F.tensor(0),h1=e.segmentation.ratio||.5,b0.downsample_ratio=F.tensor(h1)}async function b1(e){return!be||R.initial?be=await O(e.segmentation.modelPath):e.debug&&u("cached model:",be.modelUrl),Po(e),be}var Mo=e=>F.tidy(()=>{let t=F.squeeze(e,[0]),n=F.mul(t,C.tf255);return F.cast(n,"int32")});function u1(e,t){let n=e?Mo(e):F.fill([t.shape[1]||0,t.shape[2]||0,3],255,"int32"),o=t?Mo(t):F.fill([e.shape[1]||0,e.shape[2]||0,1],255,"int32"),r=F.concat([n,o],-1);return F.dispose([n,o]),r}function na(e){return F.tidy(()=>{let t={};return t.unstack=F.unstack(e,-1),t.concat=F.concat(t.unstack,1),t.split=F.split(t.concat,4,1),t.stack=F.concat(t.split,2),t.squeeze=F.squeeze(t.stack,[0]),t.expand=F.expandDims(t.squeeze,-1),t.add=F.add(t.expand,1),t.mul=F.mul(t.add,127.5),t.cast=F.cast(t.mul,"int32"),t.tile=F.tile(t.cast,[1,1,3]),t.alpha=F.fill([t.tile.shape[0]||0,t.tile.shape[1]||0,1],255,"int32"),F.concat([t.tile,t.alpha],-1)})}async function ko(e,t){if(be||(be=await b1(t)),!(be!=null&&be.executor))return null;b0.src=F.div(e,255),h1!==t.segmentation.ratio&&Po(t);let[n,o,r,s,A,a]=await be.executeAsync(b0,ta),l;switch(t.segmentation.mode||"default"){case"default":l=u1(n,o);break;case"alpha":l=u1(null,o);break;case"foreground":l=u1(n,null);break;case"state":l=na(r);break;default:l=F.tensor(0)}return F.dispose([b0.src,n,o,b0.r1i,b0.r2i,b0.r3i,b0.r4i]),[b0.r1i,b0.r2i,b0.r3i,b0.r4i]=[r,s,A,a],l}var k0=Z(H());var N0;async function g1(e){return!N0||R.initial?N0=await O(e.segmentation.modelPath):e.debug&&u("cached model:",N0.modelUrl),N0}async function Eo(e,t){var r;if(N0||(N0=await g1(t)),!(N0!=null&&N0.executor)||!((r=N0==null?void 0:N0.inputs)!=null&&r[0].shape))return null;let n={};n.resize=k0.image.resizeBilinear(e,[N0.inputs[0].shape?N0.inputs[0].shape[1]:0,N0.inputs[0].shape?N0.inputs[0].shape[2]:0],!1),n.norm=k0.div(n.resize,C.tf255),n.res=N0.execute(n.norm),n.squeeze=k0.squeeze(n.res,[0]),n.alpha=k0.image.resizeBilinear(n.squeeze,[e.shape[1]||0,e.shape[2]||0]),n.mul=k0.mul(n.alpha,C.tf255);let o;switch(t.segmentation.mode||"default"){case"default":n.input=k0.squeeze(e),n.concat=k0.concat([n.input,n.mul],-1),o=k0.cast(n.concat,"int32");break;case"alpha":o=k0.cast(n.mul,"int32");break;default:o=k0.tensor(0)}return Object.keys(n).forEach(s=>k0.dispose(n[s])),o}function Ft(e,t,n){var c,x;if(!t||!((c=e==null?void 0:e.config)!=null&&c.validateModels))return null;let o=["const","placeholder","noop","pad","squeeze","add","sub","mul","div"],r=["biasadd","fusedbatchnormv3","matmul","switch","shape","merge","split","broadcastto"],s=[],A=[],a=t.modelUrl,l=t.executor;if((x=l==null?void 0:l.graph)!=null&&x.nodes)for(let i of Object.values(l.graph.nodes)){let y=i.op.toLowerCase();s.includes(y)||s.push(y)}else!l&&e.config.debug&&u("model not loaded",n);for(let i of s)!o.includes(i)&&!r.includes(i)&&!e.env.kernels.includes(i)&&!e.env.kernels.includes(i.replace("_",""))&&!e.env.kernels.includes(i.replace("native",""))&&!e.env.kernels.includes(i.replace("v2",""))&&A.push(i);return e.config.debug&&A.length>0&&u("model validation failed:",n,A),A.length>0?{name:n,missing:A,ops:s,url:a}:null}var F2=class{constructor(t){k(this,"instance");k(this,"models",{});this.models={},this.instance=t}stats(){let t=0,n=0,o=0;for(let s of Object.values(E0))t+=s.sizeFromManifest,n+=s.sizeLoadedWeights,o+=s.sizeDesired;let r=o>0?n/o:0;return{numLoadedModels:Object.values(E0).length,numDefinedModels:Object.keys(this.models).length,percentageLoaded:r,totalSizeFromManifest:t,totalSizeWeights:n,totalSizeLoading:o,modelStats:Object.values(E0)}}reset(){for(let t of Object.keys(this.models))this.models[t]=null}async load(t){var o,r,s,A,a,l,c,x,i,y,d,p,f,b,M,T,m,h,S,P,I,q,t0,G,$,A0,v;R.initial&&this.reset(),t&&(this.instance=t);let n={};n.blazeface=this.instance.config.face.enabled&&!this.models.blazeface?b3(this.instance.config):null,n.antispoof=this.instance.config.face.enabled&&((o=this.instance.config.face.antispoof)==null?void 0:o.enabled)&&!this.models.antispoof?Z3(this.instance.config):null,n.liveness=this.instance.config.face.enabled&&((r=this.instance.config.face.liveness)==null?void 0:r.enabled)&&!this.models.liveness?Y3(this.instance.config):null,n.faceres=this.instance.config.face.enabled&&((s=this.instance.config.face.description)==null?void 0:s.enabled)&&!this.models.faceres?F3(this.instance.config):null,n.emotion=this.instance.config.face.enabled&&((A=this.instance.config.face.emotion)==null?void 0:A.enabled)&&!this.models.emotion?L3(this.instance.config):null,n.iris=this.instance.config.face.enabled&&((a=this.instance.config.face.iris)==null?void 0:a.enabled)&&!((l=this.instance.config.face.attention)!=null&&l.enabled)&&!this.models.iris?P3(this.instance.config):null,n.facemesh=this.instance.config.face.enabled&&((c=this.instance.config.face.mesh)==null?void 0:c.enabled)&&!this.models.facemesh?S3(this.instance.config):null,n.gear=this.instance.config.face.enabled&&((x=this.instance.config.face.gear)==null?void 0:x.enabled)&&!this.models.gear?_3(this.instance.config):null,n.ssrnetage=this.instance.config.face.enabled&&((i=this.instance.config.face.ssrnet)==null?void 0:i.enabled)&&!this.models.ssrnetage?nn(this.instance.config):null,n.ssrnetgender=this.instance.config.face.enabled&&((y=this.instance.config.face.ssrnet)==null?void 0:y.enabled)&&!this.models.ssrnetgender?An(this.instance.config):null,n.mobilefacenet=this.instance.config.face.enabled&&((d=this.instance.config.face.mobilefacenet)==null?void 0:d.enabled)&&!this.models.mobilefacenet?xn(this.instance.config):null,n.insightface=this.instance.config.face.enabled&&((p=this.instance.config.face.insightface)==null?void 0:p.enabled)&&!this.models.insightface?un(this.instance.config):null,n.blazepose=this.instance.config.body.enabled&&!this.models.blazepose&&((f=this.instance.config.body.modelPath)==null?void 0:f.includes("blazepose"))?t3(this.instance.config):null,n.blazeposedetect=this.instance.config.body.enabled&&!this.models.blazeposedetect&&this.instance.config.body.detector&&this.instance.config.body.detector.modelPath?e3(this.instance.config):null,n.efficientpose=this.instance.config.body.enabled&&!this.models.efficientpose&&((b=this.instance.config.body.modelPath)==null?void 0:b.includes("efficientpose"))?a3(this.instance.config):null,n.movenet=this.instance.config.body.enabled&&!this.models.movenet&&((M=this.instance.config.body.modelPath)==null?void 0:M.includes("movenet"))?co(this.instance.config):null,n.posenet=this.instance.config.body.enabled&&!this.models.posenet&&((T=this.instance.config.body.modelPath)==null?void 0:T.includes("posenet"))?vo(this.instance.config):null,n.handtrack=this.instance.config.hand.enabled&&!this.models.handtrack&&((h=(m=this.instance.config.hand.detector)==null?void 0:m.modelPath)==null?void 0:h.includes("handtrack"))?_n(this.instance.config):null,n.handskeleton=this.instance.config.hand.enabled&&this.instance.config.hand.landmarks&&!this.models.handskeleton&&((P=(S=this.instance.config.hand.detector)==null?void 0:S.modelPath)==null?void 0:P.includes("handtrack"))?$n(this.instance.config):null,(q=(I=this.instance.config.hand.detector)==null?void 0:I.modelPath)!=null&&q.includes("handdetect")&&([n.handpose,n.handskeleton]=this.models.handpose?[null,null]:await Un(this.instance.config)),n.centernet=this.instance.config.object.enabled&&!this.models.centernet&&((t0=this.instance.config.object.modelPath)==null?void 0:t0.includes("centernet"))?r3(this.instance.config):null,n.nanodet=this.instance.config.object.enabled&&!this.models.nanodet&&((G=this.instance.config.object.modelPath)==null?void 0:G.includes("nanodet"))?fo(this.instance.config):null,n.selfie=this.instance.config.segmentation.enabled&&!this.models.selfie&&(($=this.instance.config.segmentation.modelPath)==null?void 0:$.includes("selfie"))?g1(this.instance.config):null,n.meet=this.instance.config.segmentation.enabled&&!this.models.meet&&((A0=this.instance.config.segmentation.modelPath)==null?void 0:A0.includes("meet"))?s1(this.instance.config):null,n.rvm=this.instance.config.segmentation.enabled&&!this.models.rvm&&((v=this.instance.config.segmentation.modelPath)==null?void 0:v.includes("rvm"))?b1(this.instance.config):null;for(let[V,n0]of Object.entries(n))n0!=null&&n0.then&&n0.then(U=>this.models[V]=U);await Promise.all(Object.values(n))}list(){let t=Object.keys(this.models).map(n=>{var o;return{name:n,loaded:this.models[n]!==null,size:0,url:this.models[n]?(o=this.models[n])==null?void 0:o.modelUrl:null}});for(let n of t){let o=Object.keys(E0).find(r=>r.startsWith(n.name));!o||(n.size=E0[o].sizeLoadedWeights,n.url=E0[o].url)}return t}loaded(){return this.list().filter(o=>o.loaded).map(o=>o.name)}validate(){let t=[];for(let n of Object.keys(this.models)){let o=this.models[n];if(!o)continue;let r=Ft(this.instance,o,n);r&&t.push(r)}return t}};function So(e,t,n,o,r){var a,l,c,x,i,y;let s=0,A=[];for(let d of e){let p={id:s++,face:d,body:null,hands:{left:null,right:null},gestures:[],box:[0,0,0,0]};for(let h of t)d.box[0]>h.box[0]&&d.box[0]h.box[1]&&d.box[1]+d.box[3]p.body.box[0]&&h.box[0]+h.box[2]p.body.box[1]&&h.box[1]+h.box[3]p.body.box[0]&&h.box[1]+h.box[3]>p.body.box[1]&&h.box[1]+h.box[3]{h&&h.length===4&&(f.push(h[0],h[0]+h[2]),b.push(h[1],h[1]+h[3]))};M(p.face.box),M((x=p.body)==null?void 0:x.box),M((i=p.hands.left)==null?void 0:i.box),M((y=p.hands.right)==null?void 0:y.box);let T=Math.min(...f),m=Math.min(...b);p.box=[T,m,Math.max(...f)-T,Math.max(...b)-m],(r==null?void 0:r[1])&&(r==null?void 0:r[2])&&(p.boxRaw=[p.box[0]/r[2],p.box[1]/r[1],p.box[2]/r[2],p.box[3]/r[1]]),A.push(p)}return A}var d0=Z(H());var Bt=` /9j/4AAQSkZJRgABAQEAYABgAAD/4QBoRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUA AAABAAAARgEoAAMAAAABAAIAAAExAAIAAAARAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQu bmV0IDQuMi4xMwAA/9sAQwAGBAUGBQQGBgUGBwcGCAoQCgoJCQoUDg8MEBcUGBgXFBYWGh0lHxob @@ -14134,8 +269,7 @@ PQ4GJ+ashuK0MhWaoWcA0AaOmASMK7jRNPWYBmHyiuepO2x10qfcv6vYxCzYqoGK4HVYVTJrmb5l c6oaM5TUJ8EgGsG4kLNUHT0M64OaqMMikSRsuKbnFMRLG3zVehOaGNE445NNlnVFpDMu6uie9Vo1 8z5mOAOST2pDK91cNN+5tsrH3PrW54a06KxT7fdrlh/q1Pc+tJ6IUdZGvHPLezMcnBOWbsPap5r3 ylFtbdT1xUWNWzU0/Zbwlgfmx8zGsHWtRHmMqE59aAMyNifvHPc1f0gtPdqkY5JosJHeNci2tktY -euPnNY+oXWZEVJNrZ9aun8SIq/CzodHuriIokhDIR1ronbKZr0o6o8ipoz//2Q==`; -var body3 = ` +euPnNY+oXWZEVJNrZ9aun8SIq/CzodHuriIokhDIR1ronbKZr0o6o8ipoz//2Q==`,Ht=` /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAsICAoIBwsKCQoNDAsNERwSEQ8PESIZGhQcKSQrKigk JyctMkA3LTA9MCcnOEw5PUNFSElIKzZPVU5GVEBHSEX/2wBDAQwNDREPESESEiFFLicuRUVFRUVF RUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUX/wAARCASwBLADASIA @@ -14703,563 +837,4 @@ AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp+bfwab+vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2 SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ -2Q==`; - -// src/warmup.ts -async function warmupBitmap(instance) { - const b64toBlob = (base64, type = "application/octet-stream") => fetch(`data:${type};base64,${base64}`).then((res2) => res2.blob()); - let blob; - let res; - switch (instance.config.warmup) { - case "face": - blob = await b64toBlob(face3); - break; - case "body": - case "full": - blob = await b64toBlob(body3); - break; - default: - blob = null; - } - if (blob) { - const bitmap = await createImageBitmap(blob); - res = await instance.detect(bitmap, instance.config); - bitmap.close(); - } - return res; -} -async function warmupCanvas(instance) { - return new Promise((resolve) => { - let src; - switch (instance.config.warmup) { - case "face": - src = "data:image/jpeg;base64," + face3; - break; - case "full": - case "body": - src = "data:image/jpeg;base64," + body3; - break; - default: - src = ""; - } - let img; - if (typeof Image !== "undefined") - img = new Image(); - else if (env.Image) - img = new env.Image(); - else { - resolve(void 0); - return; - } - img.onload = async () => { - const canvas3 = canvas(img.naturalWidth, img.naturalHeight); - if (!canvas3) { - log("Warmup: Canvas not found"); - resolve(void 0); - } else { - const ctx = canvas3.getContext("2d"); - if (ctx) - ctx.drawImage(img, 0, 0); - const tensor6 = await instance.image(canvas3, true); - const res = tensor6.tensor ? await instance.detect(tensor6.tensor, instance.config) : void 0; - resolve(res); - } - }; - if (src) - img.src = src; - else - resolve(void 0); - }); -} -async function warmupNode(instance) { - const atob = (str) => Buffer.from(str, "base64"); - let img; - if (instance.config.warmup === "face") - img = atob(face3); - else - img = atob(body3); - let res; - if ("node" in tf37 && tf37.getBackend() === "tensorflow") { - const data = tf37["node"].decodeJpeg(img); - const expanded = tf37.expandDims(data, 0); - instance.tf.dispose(data); - res = await instance.detect(expanded, instance.config); - instance.tf.dispose(expanded); - } else { - if (instance.config.debug) - log("Warmup tfjs-node not loaded"); - } - return res; -} -async function runInference(instance) { - let res; - if (typeof createImageBitmap === "function") - res = await warmupBitmap(instance); - else if (typeof Image !== "undefined" || env.Canvas !== void 0) - res = await warmupCanvas(instance); - else - res = await warmupNode(instance); - return res; -} -async function runCompile(instance) { - var _a, _b, _c, _d; - if (!tf37.env().flagRegistry.ENGINE_COMPILE_ONLY) - return; - const backendType = tf37.getBackend(); - const webGLBackend = tf37.backend(); - if (backendType !== "webgl" && backendType !== "humangl" || !(webGLBackend == null ? void 0 : webGLBackend["checkCompileCompletion"])) { - return; - } - tf37.env().set("ENGINE_COMPILE_ONLY", true); - const numTensorsStart = tf37.engine().state.numTensors; - const compiledModels = []; - for (const [modelName, model23] of Object.entries(instance.models.models)) { - if (!model23) - continue; - const shape = (model23 == null ? void 0 : model23.modelSignature) && ((_b = (_a = model23 == null ? void 0 : model23.inputs) == null ? void 0 : _a[0]) == null ? void 0 : _b.shape) ? [...model23.inputs[0].shape] : [1, 64, 64, 3]; - const dtype = (model23 == null ? void 0 : model23.modelSignature) && ((_d = (_c = model23 == null ? void 0 : model23.inputs) == null ? void 0 : _c[0]) == null ? void 0 : _d.dtype) ? model23.inputs[0].dtype : "float32"; - for (let dim = 0; dim < shape.length; dim++) { - if (shape[dim] === -1) - shape[dim] = dim === 0 ? 1 : 64; - } - const tensor6 = tf37.zeros(shape, dtype); - try { - const res = model23.execute(tensor6); - compiledModels.push(modelName); - if (Array.isArray(res)) - res.forEach((t2) => tf37.dispose(t2)); - else - tf37.dispose(res); - } catch (e) { - if (instance.config.debug) - log("compile fail model:", modelName); - } - tf37.dispose(tensor6); - } - const kernels = await webGLBackend["checkCompileCompletionAsync"](); - webGLBackend["getUniformLocations"](); - if (instance.config.debug) - log("compile pass:", { models: compiledModels, kernels: kernels.length }); - tf37.env().set("ENGINE_COMPILE_ONLY", false); - const numTensorsEnd = tf37.engine().state.numTensors; - if (numTensorsEnd - numTensorsStart > 0) - log("tensor leak:", numTensorsEnd - numTensorsStart); -} -async function warmup(instance, userConfig) { - await check(instance, false); - const t0 = now(); - instance.state = "warmup"; - if (userConfig) - instance.config = mergeDeep(instance.config, userConfig); - if (!instance.config.warmup || instance.config.warmup.length === 0 || instance.config.warmup === "none") { - return empty(); - } - return new Promise(async (resolve) => { - await instance.models.load(); - await runCompile(instance); - const res = await runInference(instance); - const t1 = now(); - if (instance.config.debug) - log("warmup", instance.config.warmup, Math.round(t1 - t0), "ms"); - instance.emit("warmup"); - resolve(res); - }); -} - -// src/human.ts -var _numTensors, _analyzeMemoryLeaks, _checkSanity, _sanity, _loops; -var Human = class { - constructor(userConfig) { - __publicField(this, "version"); - __publicField(this, "config"); - __publicField(this, "result"); - __publicField(this, "state"); - __publicField(this, "process"); - __publicField(this, "tf"); - __publicField(this, "env", env); - __publicField(this, "draw", draw_exports); - __publicField(this, "match", match_exports); - __publicField(this, "models"); - __publicField(this, "events"); - __publicField(this, "faceTriangulation"); - __publicField(this, "faceUVMap"); - __publicField(this, "performance"); - __privateAdd(this, _numTensors, void 0); - __privateAdd(this, _analyzeMemoryLeaks, void 0); - __privateAdd(this, _checkSanity, void 0); - __publicField(this, "analyze", (...msg) => { - if (!__privateGet(this, _analyzeMemoryLeaks)) - return; - const currentTensors = this.tf.engine().state.numTensors; - const previousTensors = __privateGet(this, _numTensors); - __privateSet(this, _numTensors, currentTensors); - const leaked = currentTensors - previousTensors; - if (leaked !== 0) - log(...msg, leaked); - }); - __privateAdd(this, _sanity, (input) => { - if (!__privateGet(this, _checkSanity)) - return null; - if (!input) - return "input is not defined"; - if (this.env.node && !(input instanceof tf38.Tensor)) - return "input must be a tensor"; - try { - this.tf.getBackend(); - } catch (e) { - return "backend not loaded"; - } - return null; - }); - __publicField(this, "webcam", new WebCam()); - __publicField(this, "emit", (event) => { - var _a; - if ((_a = this.events) == null ? void 0 : _a.dispatchEvent) - this.events.dispatchEvent(new Event(event)); - }); - __privateAdd(this, _loops, {}); - const tfVersion = (tf38.version.tfjs || tf38.version_core).replace(/-(.*)/, ""); - config.wasmPath = `https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${tfVersion}/dist/`; - config.modelBasePath = env.browser ? "../models/" : "file://models/"; - this.version = version2; - Object.defineProperty(this, "version", { value: version2 }); - this.config = JSON.parse(JSON.stringify(config)); - Object.seal(this.config); - this.config.cacheModels = typeof indexedDB !== "undefined"; - if (userConfig) - this.config = mergeDeep(this.config, userConfig); - setModelLoadOptions(this.config); - this.tf = tf38; - this.state = "idle"; - __privateSet(this, _numTensors, 0); - __privateSet(this, _analyzeMemoryLeaks, false); - __privateSet(this, _checkSanity, false); - this.performance = {}; - this.events = typeof EventTarget !== "undefined" ? new EventTarget() : void 0; - this.models = new Models(this); - init2(); - this.result = empty(); - this.process = { tensor: null, canvas: null }; - this.faceTriangulation = triangulation; - this.faceUVMap = uvmap; - validateModel(this, null, ""); - this.emit("create"); - if (this.config.debug || this.env.browser) - log(`version: ${this.version}`); - if (this.config.debug) - log(`tfjs version: ${this.tf.version["tfjs-core"]}`); - const envTemp = JSON.parse(JSON.stringify(this.env)); - delete envTemp.kernels; - delete envTemp.initial; - delete envTemp.perfadd; - if (this.config.debug) - log("environment:", envTemp); - } - reset() { - const currentBackend = this.config.backend; - this.config = JSON.parse(JSON.stringify(config)); - this.config.backend = currentBackend; - reset(); - env.initial = true; - } - validate(userConfig) { - const msgs = validate(config, userConfig || this.config); - if (msgs.length === 0) - this.config = mergeDeep(this.config, userConfig); - return msgs; - } - now() { - return now(); - } - image(input, getTensor = false) { - return process2(input, this.config, getTensor); - } - async segmentation(input, userConfig) { - var _a, _b, _c; - if (userConfig) - this.config = mergeDeep(this.config, userConfig); - if (!this.config.segmentation.enabled) - return null; - const processed = await process2(input, this.config); - if (!processed.tensor) - return null; - let tensor6 = null; - if ((_a = this.config.segmentation.modelPath) == null ? void 0 : _a.includes("rvm")) - tensor6 = await predict20(processed.tensor, this.config); - if ((_b = this.config.segmentation.modelPath) == null ? void 0 : _b.includes("meet")) - tensor6 = await predict16(processed.tensor, this.config); - if ((_c = this.config.segmentation.modelPath) == null ? void 0 : _c.includes("selfie")) - tensor6 = await predict21(processed.tensor, this.config); - tf38.dispose(processed.tensor); - return tensor6; - } - compare(firstImageTensor, secondImageTensor) { - return compare(this.config, firstImageTensor, secondImageTensor); - } - async init() { - await check(this, true); - await this.tf.ready(); - reset(); - } - async load(userConfig) { - this.state = "load"; - const timeStamp = now(); - const count2 = Object.values(this.models.models).filter((model23) => model23).length; - if (userConfig) - this.config = mergeDeep(this.config, userConfig); - if (this.env.initial) { - if (!await check(this, false)) - log("error: backend check failed"); - await tf38.ready(); - if (this.env.browser) { - if (this.config.debug) - log("configuration:", this.config); - if (this.config.debug) - log("tf flags:", this.tf.ENV.flags); - } - } - await this.models.load(this); - if (this.env.initial && this.config.debug) - log("tf engine state:", this.tf.engine().state.numBytes, "bytes", this.tf.engine().state.numTensors, "tensors"); - this.env.initial = false; - const loaded = Object.values(this.models.models).filter((model23) => model23).length; - if (loaded !== count2) { - this.models.validate(); - this.emit("load"); - } - const current = Math.trunc(now() - timeStamp); - if (current > (this.performance.loadModels || 0)) - this.performance.loadModels = this.env.perfadd ? (this.performance.loadModels || 0) + current : current; - } - next(result = this.result) { - return calc2(result, this.config); - } - async warmup(userConfig) { - const t0 = now(); - const res = await warmup(this, userConfig); - const t1 = now(); - this.performance.warmup = Math.trunc(t1 - t0); - return res; - } - async profile(input, userConfig) { - const profile = await this.tf.profile(() => this.detect(input, userConfig)); - const kernels = {}; - let total = 0; - for (const kernel of profile.kernels) { - const ms = Number(kernel.kernelTimeMs) || 0; - if (kernels[kernel.name]) - kernels[kernel.name] += ms; - else - kernels[kernel.name] = ms; - total += ms; - } - const kernelArr = []; - Object.entries(kernels).forEach((key) => kernelArr.push({ kernel: key[0], time: key[1], perc: 0 })); - for (const kernel of kernelArr) { - kernel.perc = Math.round(1e3 * kernel.time / total) / 1e3; - kernel.time = Math.round(1e3 * kernel.time) / 1e3; - } - kernelArr.sort((a, b) => b.time - a.time); - kernelArr.length = 20; - return kernelArr; - } - async detect(input, userConfig) { - this.state = "detect"; - return new Promise(async (resolve) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u; - this.state = "config"; - let timeStamp; - this.config = mergeDeep(this.config, userConfig); - this.state = "check"; - const error = __privateGet(this, _sanity).call(this, input); - if (error) { - log(error, input); - this.emit("error"); - resolve(empty(error)); - } - const timeStart = now(); - await this.load(); - timeStamp = now(); - this.state = "image"; - const img = await process2(input, this.config); - this.process = img; - this.performance.inputProcess = this.env.perfadd ? (this.performance.inputProcess || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - this.analyze("Get Image:"); - if (!img.tensor) { - if (this.config.debug) - log("could not convert input to tensor"); - this.emit("error"); - resolve(empty("could not convert input to tensor")); - return; - } - this.emit("image"); - timeStamp = now(); - this.config.skipAllowed = await skip(this.config, img.tensor); - this.config.filter.autoBrightness = (this.config.filter.autoBrightness || false) && this.config.skipAllowed; - if (!this.performance.totalFrames) - this.performance.totalFrames = 0; - if (!this.performance.cachedFrames) - this.performance.cachedFrames = 0; - this.performance.totalFrames++; - if (this.config.skipAllowed) - this.performance.cachedFrames++; - this.performance.cacheCheck = this.env.perfadd ? (this.performance.cacheCheck || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - this.analyze("Check Changed:"); - let faceRes = []; - let bodyRes = []; - let handRes = []; - let objectRes = []; - this.state = "detect:face"; - if (this.config.async) { - faceRes = this.config.face.enabled ? detectFace(this, img.tensor) : []; - if (this.performance.face) - delete this.performance.face; - } else { - timeStamp = now(); - faceRes = this.config.face.enabled ? await detectFace(this, img.tensor) : []; - this.performance.face = this.env.perfadd ? (this.performance.face || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - if (this.config.async && (this.config.body.maxDetected === -1 || this.config.hand.maxDetected === -1)) - faceRes = await faceRes; - this.analyze("Start Body:"); - this.state = "detect:body"; - const bodyConfig = this.config.body.maxDetected === -1 ? mergeDeep(this.config, { body: { maxDetected: this.config.face.enabled ? 1 * faceRes.length : 1 } }) : this.config; - if (this.config.async) { - if ((_a = this.config.body.modelPath) == null ? void 0 : _a.includes("posenet")) - bodyRes = this.config.body.enabled ? predict19(img.tensor, bodyConfig) : []; - else if ((_b = this.config.body.modelPath) == null ? void 0 : _b.includes("blazepose")) - bodyRes = this.config.body.enabled ? predict(img.tensor, bodyConfig) : []; - else if ((_c = this.config.body.modelPath) == null ? void 0 : _c.includes("efficientpose")) - bodyRes = this.config.body.enabled ? predict3(img.tensor, bodyConfig) : []; - else if ((_d = this.config.body.modelPath) == null ? void 0 : _d.includes("movenet")) - bodyRes = this.config.body.enabled ? predict17(img.tensor, bodyConfig) : []; - if (this.performance.body) - delete this.performance.body; - } else { - timeStamp = now(); - if ((_e = this.config.body.modelPath) == null ? void 0 : _e.includes("posenet")) - bodyRes = this.config.body.enabled ? await predict19(img.tensor, bodyConfig) : []; - else if ((_f = this.config.body.modelPath) == null ? void 0 : _f.includes("blazepose")) - bodyRes = this.config.body.enabled ? await predict(img.tensor, bodyConfig) : []; - else if ((_g = this.config.body.modelPath) == null ? void 0 : _g.includes("efficientpose")) - bodyRes = this.config.body.enabled ? await predict3(img.tensor, bodyConfig) : []; - else if ((_h = this.config.body.modelPath) == null ? void 0 : _h.includes("movenet")) - bodyRes = this.config.body.enabled ? await predict17(img.tensor, bodyConfig) : []; - this.performance.body = this.env.perfadd ? (this.performance.body || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - this.analyze("End Body:"); - this.analyze("Start Hand:"); - this.state = "detect:hand"; - const handConfig = this.config.hand.maxDetected === -1 ? mergeDeep(this.config, { hand: { maxDetected: this.config.face.enabled ? 2 * faceRes.length : 1 } }) : this.config; - if (this.config.async) { - if ((_j = (_i = this.config.hand.detector) == null ? void 0 : _i.modelPath) == null ? void 0 : _j.includes("handdetect")) - handRes = this.config.hand.enabled ? predict14(img.tensor, handConfig) : []; - else if ((_l = (_k = this.config.hand.detector) == null ? void 0 : _k.modelPath) == null ? void 0 : _l.includes("handtrack")) - handRes = this.config.hand.enabled ? predict15(img.tensor, handConfig) : []; - if (this.performance.hand) - delete this.performance.hand; - } else { - timeStamp = now(); - if ((_n = (_m = this.config.hand.detector) == null ? void 0 : _m.modelPath) == null ? void 0 : _n.includes("handdetect")) - handRes = this.config.hand.enabled ? await predict14(img.tensor, handConfig) : []; - else if ((_p = (_o = this.config.hand.detector) == null ? void 0 : _o.modelPath) == null ? void 0 : _p.includes("handtrack")) - handRes = this.config.hand.enabled ? await predict15(img.tensor, handConfig) : []; - this.performance.hand = this.env.perfadd ? (this.performance.hand || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - this.analyze("End Hand:"); - this.analyze("Start Object:"); - this.state = "detect:object"; - if (this.config.async) { - if ((_q = this.config.object.modelPath) == null ? void 0 : _q.includes("nanodet")) - objectRes = this.config.object.enabled ? predict18(img.tensor, this.config) : []; - else if ((_r = this.config.object.modelPath) == null ? void 0 : _r.includes("centernet")) - objectRes = this.config.object.enabled ? predict2(img.tensor, this.config) : []; - if (this.performance.object) - delete this.performance.object; - } else { - timeStamp = now(); - if ((_s = this.config.object.modelPath) == null ? void 0 : _s.includes("nanodet")) - objectRes = this.config.object.enabled ? await predict18(img.tensor, this.config) : []; - else if ((_t = this.config.object.modelPath) == null ? void 0 : _t.includes("centernet")) - objectRes = this.config.object.enabled ? await predict2(img.tensor, this.config) : []; - this.performance.object = this.env.perfadd ? (this.performance.object || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - this.analyze("End Object:"); - this.state = "detect:await"; - if (this.config.async) - [faceRes, bodyRes, handRes, objectRes] = await Promise.all([faceRes, bodyRes, handRes, objectRes]); - this.state = "detect:gesture"; - let gestureRes = []; - if (this.config.gesture.enabled) { - timeStamp = now(); - gestureRes = [...face2(faceRes), ...body2(bodyRes), ...hand2(handRes), ...iris2(faceRes)]; - if (!this.config.async) - this.performance.gesture = this.env.perfadd ? (this.performance.gesture || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - else if (this.performance.gesture) - delete this.performance.gesture; - } - this.performance.total = this.env.perfadd ? (this.performance.total || 0) + Math.trunc(now() - timeStart) : Math.trunc(now() - timeStart); - const shape = ((_u = this.process.tensor) == null ? void 0 : _u.shape) || [0, 0, 0, 0]; - this.result = { - face: faceRes, - body: bodyRes, - hand: handRes, - gesture: gestureRes, - object: objectRes, - performance: this.performance, - canvas: this.process.canvas, - timestamp: Date.now(), - error: null, - width: shape[2], - height: shape[1], - get persons() { - return join2(faceRes, bodyRes, handRes, gestureRes, shape); - } - }; - tf38.dispose(img.tensor); - this.emit("detect"); - this.state = "idle"; - resolve(this.result); - }); - } - async sleep(ms) { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); - } - async video(element, run = true, delay = 0) { - if (run) { - if (!__privateGet(this, _loops)[element.id]) { - if (this.config.debug) - log("video start", element.id); - __privateGet(this, _loops)[element.id] = true; - } - if (!element.paused && __privateGet(this, _loops)[element.id] && element.readyState >= 2) - await this.detect(element); - if (delay > 0) - await this.sleep(delay); - if (__privateGet(this, _loops)[element.id]) - requestAnimationFrame(() => this.video(element, run, delay)); - } else { - if (this.config.debug) - log("video stop", element.id); - __privateGet(this, _loops)[element.id] = false; - } - } -}; -_numTensors = new WeakMap(); -_analyzeMemoryLeaks = new WeakMap(); -_checkSanity = new WeakMap(); -_sanity = new WeakMap(); -_loops = new WeakMap(); -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = { - Env, - Human, - defaults, - draw, - empty, - env, - match, - models -}); +2Q==`;async function sa(e){let t=(r,s="application/octet-stream")=>fetch(`data:${s};base64,${r}`).then(A=>A.blob()),n,o;switch(e.config.warmup){case"face":n=await t(Bt);break;case"body":case"full":n=await t(Ht);break;default:n=null}if(n){let r=await createImageBitmap(n);o=await e.detect(r,e.config),r.close()}return o}async function Aa(e){return new Promise(t=>{let n;switch(e.config.warmup){case"face":n="data:image/jpeg;base64,"+Bt;break;case"full":case"body":n="data:image/jpeg;base64,"+Ht;break;default:n=""}let o;if(typeof Image!="undefined")o=new Image;else if(R.Image)o=new R.Image;else{t(void 0);return}o.onload=async()=>{let r=te(o.naturalWidth,o.naturalHeight);if(!r)u("Warmup: Canvas not found"),t(void 0);else{let s=r.getContext("2d");s&&s.drawImage(o,0,0);let A=await e.image(r,!0),a=A.tensor?await e.detect(A.tensor,e.config):void 0;t(a)}},n?o.src=n:t(void 0)})}async function aa(e){let t=r=>Buffer.from(r,"base64"),n;e.config.warmup==="face"?n=t(Bt):n=t(Ht);let o;if("node"in d0&&d0.getBackend()==="tensorflow"){let r=d0.node.decodeJpeg(n),s=d0.expandDims(r,0);e.tf.dispose(r),o=await e.detect(s,e.config),e.tf.dispose(s)}else e.config.debug&&u("Warmup tfjs-node not loaded");return o}async function ia(e){let t;return typeof createImageBitmap=="function"?t=await sa(e):typeof Image!="undefined"||R.Canvas!==void 0?t=await Aa(e):t=await aa(e),t}async function la(e){var a,l,c,x;if(!d0.env().flagRegistry.ENGINE_COMPILE_ONLY)return;let t=d0.getBackend(),n=d0.backend();if(t!=="webgl"&&t!=="humangl"||!(n!=null&&n.checkCompileCompletion))return;d0.env().set("ENGINE_COMPILE_ONLY",!0);let o=d0.engine().state.numTensors,r=[];for(let[i,y]of Object.entries(e.models.models)){if(!y)continue;let d=(y==null?void 0:y.modelSignature)&&((l=(a=y==null?void 0:y.inputs)==null?void 0:a[0])==null?void 0:l.shape)?[...y.inputs[0].shape]:[1,64,64,3],p=(y==null?void 0:y.modelSignature)&&((x=(c=y==null?void 0:y.inputs)==null?void 0:c[0])==null?void 0:x.dtype)?y.inputs[0].dtype:"float32";for(let b=0;bd0.dispose(M)):d0.dispose(b)}catch(b){e.config.debug&&u("compile fail model:",i)}d0.dispose(f)}let s=await n.checkCompileCompletionAsync();n.getUniformLocations(),e.config.debug&&u("compile pass:",{models:r,kernels:s.length}),d0.env().set("ENGINE_COMPILE_ONLY",!1);let A=d0.engine().state.numTensors;A-o>0&&u("tensor leak:",A-o)}async function jo(e,t){await j2(e,!1);let n=g();return e.state="warmup",t&&(e.config=a0(e.config,t)),!e.config.warmup||e.config.warmup.length===0||e.config.warmup==="none"?he():new Promise(async o=>{await e.models.load(),await la(e);let r=await ia(e),s=g();e.config.debug&&u("warmup",e.config.warmup,Math.round(s-n),"ms"),e.emit("warmup"),o(r)})}var M2,B2,H2,Gt,Ue,v1=class{constructor(t){k(this,"version");k(this,"config");k(this,"result");k(this,"state");k(this,"process");k(this,"tf");k(this,"env",R);k(this,"draw",et);k(this,"match",Nt);k(this,"models");k(this,"events");k(this,"faceTriangulation");k(this,"faceUVMap");k(this,"performance");me(this,M2,void 0);me(this,B2,void 0);me(this,H2,void 0);k(this,"analyze",(...t)=>{if(!G0(this,B2))return;let n=this.tf.engine().state.numTensors,o=G0(this,M2);ge(this,M2,n);let r=n-o;r!==0&&u(...t,r)});me(this,Gt,t=>{if(!G0(this,H2))return null;if(!t)return"input is not defined";if(this.env.node&&!(t instanceof ae.Tensor))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});k(this,"webcam",new U2);k(this,"emit",t=>{var n;(n=this.events)!=null&&n.dispatchEvent&&this.events.dispatchEvent(new Event(t))});me(this,Ue,{});let n=(ae.version.tfjs||ae.version_core).replace(/-(.*)/,"");Ye.wasmPath=`https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${n}/dist/`,Ye.modelBasePath=R.browser?"../models/":"file://models/",this.version=_t,Object.defineProperty(this,"version",{value:_t}),this.config=JSON.parse(JSON.stringify(Ye)),Object.seal(this.config),this.config.cacheModels=typeof indexedDB!="undefined",t&&(this.config=a0(this.config,t)),F1(this.config),this.tf=ae,this.state="idle",ge(this,M2,0),ge(this,B2,!1),ge(this,H2,!1),this.performance={},this.events=typeof EventTarget!="undefined"?new EventTarget:void 0,this.models=new F2(this),s5(),this.result=he(),this.process={tensor:null,canvas:null},this.faceTriangulation=j3,this.faceUVMap=N3,Ft(this,null,""),this.emit("create"),(this.config.debug||this.env.browser)&&u(`version: ${this.version}`),this.config.debug&&u(`tfjs version: ${this.tf.version["tfjs-core"]}`);let o=JSON.parse(JSON.stringify(this.env));delete o.kernels,delete o.initial,delete o.perfadd,this.config.debug&&u("environment:",o)}reset(){let t=this.config.backend;this.config=JSON.parse(JSON.stringify(Ye)),this.config.backend=t,Jt(),R.initial=!0}validate(t){let n=Ut(Ye,t||this.config);return n.length===0&&(this.config=a0(this.config,t)),n}now(){return g()}image(t,n=!1){return X2(t,this.config,n)}async segmentation(t,n){var s,A,a;if(n&&(this.config=a0(this.config,n)),!this.config.segmentation.enabled)return null;let o=await X2(t,this.config);if(!o.tensor)return null;let r=null;return(s=this.config.segmentation.modelPath)!=null&&s.includes("rvm")&&(r=await ko(o.tensor,this.config)),(A=this.config.segmentation.modelPath)!=null&&A.includes("meet")&&(r=await no(o.tensor,this.config)),(a=this.config.segmentation.modelPath)!=null&&a.includes("selfie")&&(r=await Eo(o.tensor,this.config)),ae.dispose(o.tensor),r}compare(t,n){return D1(this.config,t,n)}async init(){await j2(this,!0),await this.tf.ready(),Jt()}async load(t){this.state="load";let n=g(),o=Object.values(this.models.models).filter(A=>A).length;t&&(this.config=a0(this.config,t)),this.env.initial&&(await j2(this,!1)||u("error: backend check failed"),await ae.ready(),this.env.browser&&(this.config.debug&&u("configuration:",this.config),this.config.debug&&u("tf flags:",this.tf.ENV.flags))),await this.models.load(this),this.env.initial&&this.config.debug&&u("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),this.env.initial=!1,Object.values(this.models.models).filter(A=>A).length!==o&&(this.models.validate(),this.emit("load"));let s=Math.trunc(g()-n);s>(this.performance.loadModels||0)&&(this.performance.loadModels=this.env.perfadd?(this.performance.loadModels||0)+s:s)}next(t=this.result){return to(t,this.config)}async warmup(t){let n=g(),o=await jo(this,t),r=g();return this.performance.warmup=Math.trunc(r-n),o}async profile(t,n){let o=await this.tf.profile(()=>this.detect(t,n)),r={},s=0;for(let a of o.kernels){let l=Number(a.kernelTimeMs)||0;r[a.name]?r[a.name]+=l:r[a.name]=l,s+=l}let A=[];Object.entries(r).forEach(a=>A.push({kernel:a[0],time:a[1],perc:0}));for(let a of A)a.perc=Math.round(1e3*a.time/s)/1e3,a.time=Math.round(1e3*a.time)/1e3;return A.sort((a,l)=>l.time-a.time),A.length=20,A}async detect(t,n){return this.state="detect",new Promise(async o=>{var b,M,T,m,h,S,P,I,q,t0,G,$,A0,v,V,n0,U,g0,m0,B,X;this.state="config";let r;this.config=a0(this.config,n),this.state="check";let s=G0(this,Gt).call(this,t);s&&(u(s,t),this.emit("error"),o(he(s)));let A=g();await this.load(),r=g(),this.state="image";let a=await X2(t,this.config);if(this.process=a,this.performance.inputProcess=this.env.perfadd?(this.performance.inputProcess||0)+Math.trunc(g()-r):Math.trunc(g()-r),this.analyze("Get Image:"),!a.tensor){this.config.debug&&u("could not convert input to tensor"),this.emit("error"),o(he("could not convert input to tensor"));return}this.emit("image"),r=g(),this.config.skipAllowed=await W1(this.config,a.tensor),this.config.filter.autoBrightness=(this.config.filter.autoBrightness||!1)&&this.config.skipAllowed,this.performance.totalFrames||(this.performance.totalFrames=0),this.performance.cachedFrames||(this.performance.cachedFrames=0),this.performance.totalFrames++,this.config.skipAllowed&&this.performance.cachedFrames++,this.performance.cacheCheck=this.env.perfadd?(this.performance.cacheCheck||0)+Math.trunc(g()-r):Math.trunc(g()-r),this.analyze("Check Changed:");let l=[],c=[],x=[],i=[];this.state="detect:face",this.config.async?(l=this.config.face.enabled?q5(this,a.tensor):[],this.performance.face&&delete this.performance.face):(r=g(),l=this.config.face.enabled?await q5(this,a.tensor):[],this.performance.face=this.env.perfadd?(this.performance.face||0)+Math.trunc(g()-r):Math.trunc(g()-r)),this.config.async&&(this.config.body.maxDetected===-1||this.config.hand.maxDetected===-1)&&(l=await l),this.analyze("Start Body:"),this.state="detect:body";let y=this.config.body.maxDetected===-1?a0(this.config,{body:{maxDetected:this.config.face.enabled?1*l.length:1}}):this.config;this.config.async?((b=this.config.body.modelPath)!=null&&b.includes("posenet")?c=this.config.body.enabled?p1(a.tensor,y):[]:(M=this.config.body.modelPath)!=null&&M.includes("blazepose")?c=this.config.body.enabled?c5(a.tensor,y):[]:(T=this.config.body.modelPath)!=null&&T.includes("efficientpose")?c=this.config.body.enabled?u5(a.tensor,y):[]:(m=this.config.body.modelPath)!=null&&m.includes("movenet")&&(c=this.config.body.enabled?l1(a.tensor,y):[]),this.performance.body&&delete this.performance.body):(r=g(),(h=this.config.body.modelPath)!=null&&h.includes("posenet")?c=this.config.body.enabled?await p1(a.tensor,y):[]:(S=this.config.body.modelPath)!=null&&S.includes("blazepose")?c=this.config.body.enabled?await c5(a.tensor,y):[]:(P=this.config.body.modelPath)!=null&&P.includes("efficientpose")?c=this.config.body.enabled?await u5(a.tensor,y):[]:(I=this.config.body.modelPath)!=null&&I.includes("movenet")&&(c=this.config.body.enabled?await l1(a.tensor,y):[]),this.performance.body=this.env.perfadd?(this.performance.body||0)+Math.trunc(g()-r):Math.trunc(g()-r)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.state="detect:hand";let d=this.config.hand.maxDetected===-1?a0(this.config,{hand:{maxDetected:this.config.face.enabled?2*l.length:1}}):this.config;this.config.async?((t0=(q=this.config.hand.detector)==null?void 0:q.modelPath)!=null&&t0.includes("handdetect")?x=this.config.hand.enabled?Q5(a.tensor,d):[]:($=(G=this.config.hand.detector)==null?void 0:G.modelPath)!=null&&$.includes("handtrack")&&(x=this.config.hand.enabled?e1(a.tensor,d):[]),this.performance.hand&&delete this.performance.hand):(r=g(),(v=(A0=this.config.hand.detector)==null?void 0:A0.modelPath)!=null&&v.includes("handdetect")?x=this.config.hand.enabled?await Q5(a.tensor,d):[]:(n0=(V=this.config.hand.detector)==null?void 0:V.modelPath)!=null&&n0.includes("handtrack")&&(x=this.config.hand.enabled?await e1(a.tensor,d):[]),this.performance.hand=this.env.perfadd?(this.performance.hand||0)+Math.trunc(g()-r):Math.trunc(g()-r)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.state="detect:object",this.config.async?((U=this.config.object.modelPath)!=null&&U.includes("nanodet")?i=this.config.object.enabled?d1(a.tensor,this.config):[]:(g0=this.config.object.modelPath)!=null&&g0.includes("centernet")&&(i=this.config.object.enabled?y5(a.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(r=g(),(m0=this.config.object.modelPath)!=null&&m0.includes("nanodet")?i=this.config.object.enabled?await d1(a.tensor,this.config):[]:(B=this.config.object.modelPath)!=null&&B.includes("centernet")&&(i=this.config.object.enabled?await y5(a.tensor,this.config):[]),this.performance.object=this.env.perfadd?(this.performance.object||0)+Math.trunc(g()-r):Math.trunc(g()-r)),this.analyze("End Object:"),this.state="detect:await",this.config.async&&([l,c,x,i]=await Promise.all([l,c,x,i])),this.state="detect:gesture";let p=[];this.config.gesture.enabled&&(r=g(),p=[...Sn(l),...zn(c),...Nn(x),...jn(l)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=this.env.perfadd?(this.performance.gesture||0)+Math.trunc(g()-r):Math.trunc(g()-r)),this.performance.total=this.env.perfadd?(this.performance.total||0)+Math.trunc(g()-A):Math.trunc(g()-A);let f=((X=this.process.tensor)==null?void 0:X.shape)||[0,0,0,0];this.result={face:l,body:c,hand:x,gesture:p,object:i,performance:this.performance,canvas:this.process.canvas,timestamp:Date.now(),error:null,width:f[2],height:f[1],get persons(){return So(l,c,x,p,f)}},ae.dispose(a.tensor),this.emit("detect"),this.state="idle",o(this.result)})}async sleep(t){return new Promise(n=>{setTimeout(n,t)})}async video(t,n=!0,o=0){n?(G0(this,Ue)[t.id]||(this.config.debug&&u("video start",t.id),G0(this,Ue)[t.id]=!0),!t.paused&&G0(this,Ue)[t.id]&&t.readyState>=2&&await this.detect(t),o>0&&await this.sleep(o),G0(this,Ue)[t.id]&&requestAnimationFrame(()=>this.video(t,n,o))):(this.config.debug&&u("video stop",t.id),G0(this,Ue)[t.id]=!1)}};M2=new WeakMap,B2=new WeakMap,H2=new WeakMap,Gt=new WeakMap,Ue=new WeakMap;0&&(module.exports={Env,Human,defaults,draw,empty,env,match,models}); diff --git a/dist/human.node-wasm.js b/dist/human.node-wasm.js index 724c66ea..8b94cc16 100644 --- a/dist/human.node-wasm.js +++ b/dist/human.node-wasm.js @@ -4,318 +4,7 @@ author: ' */ -"use strict"; -var __create = Object.create; -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __getProtoOf = Object.getPrototypeOf; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; -var __commonJS = (cb, mod3) => function __require() { - return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports; -}; -var __export = (target, all2) => { - for (var name in all2) - __defProp(target, name, { get: all2[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toESM = (mod3, isNodeMode, target) => (target = mod3 != null ? __create(__getProtoOf(mod3)) : {}, __copyProps( - isNodeMode || !mod3 || !mod3.__esModule ? __defProp(target, "default", { value: mod3, enumerable: true }) : target, - mod3 -)); -var __toCommonJS = (mod3) => __copyProps(__defProp({}, "__esModule", { value: true }), mod3); -var __publicField = (obj, key, value) => { - __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); - return value; -}; -var __accessCheck = (obj, member, msg) => { - if (!member.has(obj)) - throw TypeError("Cannot " + msg); -}; -var __privateGet = (obj, member, getter) => { - __accessCheck(obj, member, "read from private field"); - return getter ? getter.call(obj) : member.get(obj); -}; -var __privateAdd = (obj, member, value) => { - if (member.has(obj)) - throw TypeError("Cannot add the same private member more than once"); - member instanceof WeakSet ? member.add(obj) : member.set(obj, value); -}; -var __privateSet = (obj, member, value, setter) => { - __accessCheck(obj, member, "write to private field"); - setter ? setter.call(obj, value) : member.set(obj, value); - return value; -}; - -// dist/tfjs.esm.js -var require_tfjs_esm = __commonJS({ - "dist/tfjs.esm.js"(exports, module2) { - "use strict"; - var __defProp2 = Object.defineProperty; - var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; - var __getOwnPropNames2 = Object.getOwnPropertyNames; - var __hasOwnProp2 = Object.prototype.hasOwnProperty; - var __export2 = (target, all2) => { - for (var name in all2) - __defProp2(target, name, { get: all2[name], enumerable: true }); - }; - var __copyProps2 = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames2(from)) - if (!__hasOwnProp2.call(to, key) && key !== except) - __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); - } - return to; - }; - var __reExport = (target, mod3, secondTarget) => (__copyProps2(target, mod3, "default"), secondTarget && __copyProps2(secondTarget, mod3, "default")); - var __toCommonJS2 = (mod3) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod3); - var tf_node_wasm_exports = {}; - __export2(tf_node_wasm_exports, { - version: () => version7 - }); - module2.exports = __toCommonJS2(tf_node_wasm_exports); - __reExport(tf_node_wasm_exports, require("@tensorflow/tfjs-core"), module2.exports); - __reExport(tf_node_wasm_exports, require("@tensorflow/tfjs-converter"), module2.exports); - __reExport(tf_node_wasm_exports, require("@tensorflow/tfjs-backend-wasm"), module2.exports); - var version4 = "4.2.0"; - var version22 = "4.2.0"; - var version32 = "4.2.0"; - var version42 = "4.2.0"; - var version5 = "4.2.0"; - var version6 = "0.0.1-alpha.17"; - var version7 = { - tfjs: version4, - "tfjs-core": version4, - "tfjs-converter": version22, - "tfjs-backend-cpu": version32, - "tfjs-backend-webgl": version42, - "tfjs-backend-wasm": version5, - "tfjs-backend-webgpu": version6 - }; - } -}); - -// src/human.ts -var human_exports = {}; -__export(human_exports, { - Env: () => Env, - Human: () => Human, - default: () => Human, - defaults: () => config, - draw: () => draw_exports, - empty: () => empty, - env: () => env, - match: () => match_exports, - models: () => models_exports2 -}); -module.exports = __toCommonJS(human_exports); -var tf38 = __toESM(require_tfjs_esm()); - -// src/util/util.ts -function log(...msg) { - const dt = new Date(); - const ts = `${dt.getHours().toString().padStart(2, "0")}:${dt.getMinutes().toString().padStart(2, "0")}:${dt.getSeconds().toString().padStart(2, "0")}.${dt.getMilliseconds().toString().padStart(3, "0")}`; - if (msg) - console.log(ts, "Human:", ...msg); -} -function join(folder, file) { - const separator = folder.endsWith("/") ? "" : "/"; - const skipJoin = file.startsWith(".") || file.startsWith("/") || file.startsWith("http:") || file.startsWith("https:") || file.startsWith("file:"); - const path = skipJoin ? `${file}` : `${folder}${separator}${file}`; - if (!path.toLocaleLowerCase().includes(".json")) - throw new Error(`modelpath error: expecting json file: ${path}`); - return path; -} -var now = () => { - if (typeof performance !== "undefined") - return performance.now(); - return parseInt((Number(process.hrtime.bigint()) / 1e3 / 1e3).toString()); -}; -function validate(defaults, config3, parent = "config", msgs = []) { - for (const key of Object.keys(config3)) { - if (typeof config3[key] === "object") { - validate(defaults[key], config3[key], key, msgs); - } else { - const defined = defaults && typeof defaults[key] !== "undefined"; - if (!defined) - msgs.push({ reason: "unknown property", where: `${parent}.${key} = ${config3[key]}` }); - const same = defaults && typeof defaults[key] === typeof config3[key]; - if (defined && !same) - msgs.push({ reason: "property type mismatch", where: `${parent}.${key} = ${config3[key]}`, expected: typeof defaults[key] }); - } - } - if (config3.debug && parent === "config" && msgs.length > 0) - log("invalid configuration", msgs); - return msgs; -} -function mergeDeep(...objects) { - const isObject = (obj) => obj && typeof obj === "object"; - return objects.reduce((prev, obj) => { - Object.keys(obj || {}).forEach((key) => { - const pVal = prev[key]; - const oVal = obj[key]; - if (Array.isArray(pVal) && Array.isArray(oVal)) - prev[key] = pVal.concat(...oVal); - else if (isObject(pVal) && isObject(oVal)) - prev[key] = mergeDeep(pVal, oVal); - else - prev[key] = oVal; - }); - return prev; - }, {}); -} - -// src/config.ts -var config = { - backend: "", - modelBasePath: "", - cacheModels: true, - validateModels: true, - wasmPath: "", - wasmPlatformFetch: false, - debug: false, - async: true, - warmup: "full", - cacheSensitivity: 0.7, - skipAllowed: false, - deallocate: false, - flags: {}, - softwareKernels: false, - filter: { - enabled: true, - equalization: false, - width: 0, - height: 0, - flip: false, - return: true, - autoBrightness: true, - brightness: 0, - contrast: 0, - sharpness: 0, - blur: 0, - saturation: 0, - hue: 0, - negative: false, - sepia: false, - vintage: false, - kodachrome: false, - technicolor: false, - polaroid: false, - pixelate: 0 - }, - gesture: { - enabled: true - }, - face: { - enabled: true, - detector: { - modelPath: "blazeface.json", - rotation: false, - maxDetected: 1, - skipFrames: 99, - skipTime: 2500, - minConfidence: 0.2, - iouThreshold: 0.1, - mask: false, - return: false - }, - mesh: { - enabled: true, - modelPath: "facemesh.json", - keepInvalid: false - }, - attention: { - enabled: false, - modelPath: "facemesh-attention.json" - }, - iris: { - enabled: true, - modelPath: "iris.json" - }, - emotion: { - enabled: true, - minConfidence: 0.1, - skipFrames: 99, - skipTime: 1500, - modelPath: "emotion.json" - }, - description: { - enabled: true, - modelPath: "faceres.json", - skipFrames: 99, - skipTime: 3e3, - minConfidence: 0.1 - }, - antispoof: { - enabled: false, - skipFrames: 99, - skipTime: 4e3, - modelPath: "antispoof.json" - }, - liveness: { - enabled: false, - skipFrames: 99, - skipTime: 4e3, - modelPath: "liveness.json" - } - }, - body: { - enabled: true, - modelPath: "movenet-lightning.json", - maxDetected: -1, - minConfidence: 0.3, - skipFrames: 1, - skipTime: 200 - }, - hand: { - enabled: true, - rotation: true, - skipFrames: 99, - skipTime: 1e3, - minConfidence: 0.5, - iouThreshold: 0.2, - maxDetected: -1, - landmarks: true, - detector: { - modelPath: "handtrack.json" - }, - skeleton: { - modelPath: "handlandmark-lite.json" - } - }, - object: { - enabled: false, - modelPath: "centernet.json", - minConfidence: 0.2, - iouThreshold: 0.4, - maxDetected: 10, - skipFrames: 99, - skipTime: 2e3 - }, - segmentation: { - enabled: false, - modelPath: "rvm.json", - ratio: 0.5, - mode: "default" - } -}; - -// src/util/env.ts -var tf3 = __toESM(require_tfjs_esm()); - -// src/image/image.ts -var tf2 = __toESM(require_tfjs_esm()); - -// src/image/imagefxshaders.ts -var vertexIdentity = ` +"use strict";var Io=Object.create;var k2=Object.defineProperty;var Oo=Object.getOwnPropertyDescriptor;var Lo=Object.getOwnPropertyNames;var Co=Object.getPrototypeOf,Wo=Object.prototype.hasOwnProperty;var Do=(e,t,n)=>t in e?k2(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Fo=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ze=(e,t)=>{for(var n in t)k2(e,n,{get:t[n],enumerable:!0})},w1=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Lo(t))!Wo.call(e,r)&&r!==n&&k2(e,r,{get:()=>t[r],enumerable:!(o=Oo(t,r))||o.enumerable});return e};var Z=(e,t,n)=>(n=e!=null?Io(Co(e)):{},w1(t||!e||!e.__esModule?k2(n,"default",{value:e,enumerable:!0}):n,e)),Bo=e=>w1(k2({},"__esModule",{value:!0}),e);var k=(e,t,n)=>(Do(e,typeof t!="symbol"?t+"":t,n),n),E1=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)};var G0=(e,t,n)=>(E1(e,t,"read from private field"),n?n.call(e):t.get(e)),me=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},ge=(e,t,n,o)=>(E1(e,t,"write to private field"),o?o.call(e,n):t.set(e,n),n);var H=Fo((ya,E2)=>{"use strict";var qt=Object.defineProperty,Ho=Object.getOwnPropertyDescriptor,Go=Object.getOwnPropertyNames,Vo=Object.prototype.hasOwnProperty,Zo=(e,t)=>{for(var n in t)qt(e,n,{get:t[n],enumerable:!0})},Xt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Go(t))!Vo.call(e,r)&&r!==n&&qt(e,r,{get:()=>t[r],enumerable:!(o=Ho(t,r))||o.enumerable});return e},Ut=(e,t,n)=>(Xt(e,t,"default"),n&&Xt(n,t,"default")),Xo=e=>Xt(qt({},"__esModule",{value:!0}),e),w2={};Zo(w2,{version:()=>Qo});E2.exports=Xo(w2);Ut(w2,require("@tensorflow/tfjs-core"),E2.exports);Ut(w2,require("@tensorflow/tfjs-converter"),E2.exports);Ut(w2,require("@tensorflow/tfjs-backend-wasm"),E2.exports);var z1="4.2.0",qo="4.2.0",Uo="4.2.0",Yo="4.2.0",Ko="4.2.0",Jo="0.0.1-alpha.17",Qo={tfjs:z1,"tfjs-core":z1,"tfjs-converter":qo,"tfjs-backend-cpu":Uo,"tfjs-backend-webgl":Yo,"tfjs-backend-wasm":Ko,"tfjs-backend-webgpu":Jo}});var da={};ze(da,{Env:()=>z2,Human:()=>R1,default:()=>R1,defaults:()=>Ye,draw:()=>nt,empty:()=>he,env:()=>R,match:()=>Ot,models:()=>v1});module.exports=Bo(da);var ae=Z(H());function u(...e){let t=new Date,n=`${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}:${t.getSeconds().toString().padStart(2,"0")}.${t.getMilliseconds().toString().padStart(3,"0")}`;e&&console.log(n,"Human:",...e)}function S1(e,t){let n=e.endsWith("/")?"":"/",r=t.startsWith(".")||t.startsWith("/")||t.startsWith("http:")||t.startsWith("https:")||t.startsWith("file:")?`${t}`:`${e}${n}${t}`;if(!r.toLocaleLowerCase().includes(".json"))throw new Error(`modelpath error: expecting json file: ${r}`);return r}var g=()=>typeof performance!="undefined"?performance.now():parseInt((Number(process.hrtime.bigint())/1e3/1e3).toString());function Yt(e,t,n="config",o=[]){for(let r of Object.keys(t))if(typeof t[r]=="object")Yt(e[r],t[r],r,o);else{let s=e&&typeof e[r]!="undefined";s||o.push({reason:"unknown property",where:`${n}.${r} = ${t[r]}`});let A=e&&typeof e[r]==typeof t[r];s&&!A&&o.push({reason:"property type mismatch",where:`${n}.${r} = ${t[r]}`,expected:typeof e[r]})}return t.debug&&n==="config"&&o.length>0&&u("invalid configuration",o),o}function a0(...e){let t=n=>n&&typeof n=="object";return e.reduce((n,o)=>(Object.keys(o||{}).forEach(r=>{let s=n[r],A=o[r];Array.isArray(s)&&Array.isArray(A)?n[r]=s.concat(...A):t(s)&&t(A)?n[r]=a0(s,A):n[r]=A}),n),{})}var Ye={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,iouThreshold:.1,mask:!1,return:!1},mesh:{enabled:!0,modelPath:"facemesh.json",keepInvalid:!1},attention:{enabled:!1,modelPath:"facemesh-attention.json"},iris:{enabled:!0,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"}};var I0=Z(H());var N=Z(H());var j1=` precision highp float; attribute vec2 pos; attribute vec2 uv; @@ -325,8 +14,7 @@ var vertexIdentity = ` vUv = uv; gl_Position = vec4(pos.x, pos.y*flipY, 0.0, 1.); } -`; -var colorMatrixWithAlpha = ` +`;var N1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -338,8 +26,7 @@ var colorMatrixWithAlpha = ` 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]; } -`; -var colorMatrixWithoutAlpha = ` +`,I1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -351,8 +38,7 @@ var colorMatrixWithoutAlpha = ` gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[14]; gl_FragColor.a = c.a; } -`; -var pixelate = ` +`,O1=` precision highp float; varying vec2 vUv; uniform vec2 size; @@ -365,8 +51,7 @@ var pixelate = ` vec2 coord = pixelate(vUv, size); gl_FragColor += texture2D(texture, coord); } -`; -var blur = ` +`,L1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -389,8 +74,7 @@ var blur = ` 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; } -`; -var convolution = ` +`,C1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -412,6055 +96,20 @@ var convolution = ` c31 * m[6] + c32 * m[7] + c33 * m[8]; gl_FragColor.a = c22.a; } -`; - -// src/image/imagefx.ts -var collect = (source, prefix, collection) => { - const r = new RegExp("\\b" + prefix + " \\w+ (\\w+)", "ig"); - source.replace(r, (match2, name) => { - collection[name] = 0; - return match2; - }); -}; -var GLProgram = class { - constructor(gl, vertexSource, fragmentSource) { - __publicField(this, "uniform", {}); - __publicField(this, "attribute", {}); - __publicField(this, "gl"); - __publicField(this, "id"); - __publicField(this, "compile", (source, type) => { - const shader = this.gl.createShader(type); - if (!shader) { - log("filter: could not create shader"); - return null; - } - this.gl.shaderSource(shader, source); - this.gl.compileShader(shader); - if (!this.gl.getShaderParameter(shader, this.gl.COMPILE_STATUS)) { - log(`filter: gl compile failed: ${this.gl.getShaderInfoLog(shader) || "unknown"}`); - return null; - } - return shader; - }); - this.gl = gl; - const vertexShader = this.compile(vertexSource, this.gl.VERTEX_SHADER); - const fragmentShader = this.compile(fragmentSource, this.gl.FRAGMENT_SHADER); - this.id = this.gl.createProgram(); - if (!vertexShader || !fragmentShader) - return; - if (!this.id) { - log("filter: could not create webgl program"); - return; - } - this.gl.attachShader(this.id, vertexShader); - this.gl.attachShader(this.id, fragmentShader); - this.gl.linkProgram(this.id); - if (!this.gl.getProgramParameter(this.id, this.gl.LINK_STATUS)) { - log(`filter: gl link failed: ${this.gl.getProgramInfoLog(this.id) || "unknown"}`); - return; - } - this.gl.useProgram(this.id); - collect(vertexSource, "attribute", this.attribute); - for (const a in this.attribute) - this.attribute[a] = this.gl.getAttribLocation(this.id, a); - collect(vertexSource, "uniform", this.uniform); - collect(fragmentSource, "uniform", this.uniform); - for (const u in this.uniform) - this.uniform[u] = this.gl.getUniformLocation(this.id, u); - } -}; -function GLImageFilter() { - let drawCount = 0; - let sourceTexture = null; - let lastInChain = false; - let currentFramebufferIndex = -1; - let tempFramebuffers = [null, null]; - let filterChain = []; - let vertexBuffer = null; - let currentProgram = null; - const fxcanvas = canvas(100, 100); - const shaderProgramCache = {}; - const DRAW = { INTERMEDIATE: 1 }; - const gl = fxcanvas.getContext("webgl"); - if (!gl) { - log("filter: cannot get webgl context"); - return; - } - this.gl = gl; - function resize(width, height) { - if (width === fxcanvas.width && height === fxcanvas.height) - return; - fxcanvas.width = width; - fxcanvas.height = height; - if (!vertexBuffer) { - const vertices = 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]); - vertexBuffer = gl.createBuffer(); - gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true); - } - gl.viewport(0, 0, fxcanvas.width, fxcanvas.height); - tempFramebuffers = [null, null]; - } - function createFramebufferTexture(width, height) { - const fbo = gl.createFramebuffer(); - gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); - const renderbuffer = gl.createRenderbuffer(); - gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer); - const texture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, texture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); - gl.bindTexture(gl.TEXTURE_2D, null); - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - return { fbo, texture }; - } - function getTempFramebuffer(index2) { - tempFramebuffers[index2] = tempFramebuffers[index2] || createFramebufferTexture(fxcanvas.width, fxcanvas.height); - return tempFramebuffers[index2]; - } - function draw(flags = 0) { - if (!currentProgram) - return; - let source = null; - let target = null; - let flipY = false; - if (drawCount === 0) - source = sourceTexture; - else - source = getTempFramebuffer(currentFramebufferIndex).texture || null; - drawCount++; - if (lastInChain && !(flags & DRAW.INTERMEDIATE)) { - target = null; - flipY = drawCount % 2 === 0; - } else { - currentFramebufferIndex = (currentFramebufferIndex + 1) % 2; - target = getTempFramebuffer(currentFramebufferIndex).fbo || null; - } - gl.bindTexture(gl.TEXTURE_2D, source); - gl.bindFramebuffer(gl.FRAMEBUFFER, target); - gl.uniform1f(currentProgram.uniform["flipY"], flipY ? -1 : 1); - gl.drawArrays(gl.TRIANGLES, 0, 6); - } - function compileShader(fragmentSource) { - if (shaderProgramCache[fragmentSource]) { - currentProgram = shaderProgramCache[fragmentSource]; - gl.useProgram((currentProgram ? currentProgram.id : null) || null); - return currentProgram; - } - currentProgram = new GLProgram(gl, vertexIdentity, fragmentSource); - if (!currentProgram) { - log("filter: could not get webgl program"); - return null; - } - const floatSize = Float32Array.BYTES_PER_ELEMENT; - const vertSize = 4 * floatSize; - gl.enableVertexAttribArray(currentProgram.attribute["pos"]); - gl.vertexAttribPointer(currentProgram.attribute["pos"], 2, gl.FLOAT, false, vertSize, 0 * floatSize); - gl.enableVertexAttribArray(currentProgram.attribute["uv"]); - gl.vertexAttribPointer(currentProgram.attribute["uv"], 2, gl.FLOAT, false, vertSize, 2 * floatSize); - shaderProgramCache[fragmentSource] = currentProgram; - return currentProgram; - } - const filter = { - colorMatrix: (matrix) => { - const m = new Float32Array(matrix); - m[4] /= 255; - m[9] /= 255; - m[14] /= 255; - m[19] /= 255; - const shader = m[18] === 1 && m[3] === 0 && m[8] === 0 && m[13] === 0 && m[15] === 0 && m[16] === 0 && m[17] === 0 && m[19] === 0 ? colorMatrixWithoutAlpha : colorMatrixWithAlpha; - const program = compileShader(shader); - if (!program) - return; - gl.uniform1fv(program.uniform["m"], m); - draw(); - }, - brightness: (brightness) => { - const b = (brightness || 0) + 1; - filter.colorMatrix([ - b, - 0, - 0, - 0, - 0, - 0, - b, - 0, - 0, - 0, - 0, - 0, - b, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - saturation: (amount) => { - const x = (amount || 0) * 2 / 3 + 1; - const y = (x - 1) * -0.5; - filter.colorMatrix([ - x, - y, - y, - 0, - 0, - y, - x, - y, - 0, - 0, - y, - y, - x, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - desaturate: () => { - filter.saturation(-1); - }, - contrast: (amount) => { - const v = (amount || 0) + 1; - const o = -128 * (v - 1); - filter.colorMatrix([ - v, - 0, - 0, - 0, - o, - 0, - v, - 0, - 0, - o, - 0, - 0, - v, - 0, - o, - 0, - 0, - 0, - 1, - 0 - ]); - }, - negative: () => { - filter.contrast(-2); - }, - hue: (rotation) => { - rotation = (rotation || 0) / 180 * Math.PI; - const cos = Math.cos(rotation); - const sin = Math.sin(rotation); - const lumR = 0.213; - const lumG = 0.715; - const lumB = 0.072; - filter.colorMatrix([ - lumR + cos * (1 - lumR) + sin * -lumR, - lumG + cos * -lumG + sin * -lumG, - lumB + cos * -lumB + sin * (1 - lumB), - 0, - 0, - lumR + cos * -lumR + sin * 0.143, - lumG + cos * (1 - lumG) + sin * 0.14, - lumB + cos * -lumB + sin * -0.283, - 0, - 0, - lumR + cos * -lumR + sin * -(1 - lumR), - lumG + cos * -lumG + sin * lumG, - lumB + cos * (1 - lumB) + sin * lumB, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - desaturateLuminance: () => { - filter.colorMatrix([ - 0.2764723, - 0.929708, - 0.0938197, - 0, - -37.1, - 0.2764723, - 0.929708, - 0.0938197, - 0, - -37.1, - 0.2764723, - 0.929708, - 0.0938197, - 0, - -37.1, - 0, - 0, - 0, - 1, - 0 - ]); - }, - sepia: () => { - filter.colorMatrix([ - 0.393, - 0.7689999, - 0.18899999, - 0, - 0, - 0.349, - 0.6859999, - 0.16799999, - 0, - 0, - 0.272, - 0.5339999, - 0.13099999, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - brownie: () => { - filter.colorMatrix([ - 0.5997023498159715, - 0.34553243048391263, - -0.2708298674538042, - 0, - 47.43192855600873, - -0.037703249837783157, - 0.8609577587992641, - 0.15059552388459913, - 0, - -36.96841498319127, - 0.24113635128153335, - -0.07441037908422492, - 0.44972182064877153, - 0, - -7.562075277591283, - 0, - 0, - 0, - 1, - 0 - ]); - }, - vintagePinhole: () => { - filter.colorMatrix([ - 0.6279345635605994, - 0.3202183420819367, - -0.03965408211312453, - 0, - 9.651285835294123, - 0.02578397704808868, - 0.6441188644374771, - 0.03259127616149294, - 0, - 7.462829176470591, - 0.0466055556782719, - -0.0851232987247891, - 0.5241648018700465, - 0, - 5.159190588235296, - 0, - 0, - 0, - 1, - 0 - ]); - }, - kodachrome: () => { - filter.colorMatrix([ - 1.1285582396593525, - -0.3967382283601348, - -0.03992559172921793, - 0, - 63.72958762196502, - -0.16404339962244616, - 1.0835251566291304, - -0.05498805115633132, - 0, - 24.732407896706203, - -0.16786010706155763, - -0.5603416277695248, - 1.6014850761964943, - 0, - 35.62982807460946, - 0, - 0, - 0, - 1, - 0 - ]); - }, - technicolor: () => { - filter.colorMatrix([ - 1.9125277891456083, - -0.8545344976951645, - -0.09155508482755585, - 0, - 11.793603434377337, - -0.3087833385928097, - 1.7658908555458428, - -0.10601743074722245, - 0, - -70.35205161461398, - -0.231103377548616, - -0.7501899197440212, - 1.847597816108189, - 0, - 30.950940869491138, - 0, - 0, - 0, - 1, - 0 - ]); - }, - polaroid: () => { - filter.colorMatrix([ - 1.438, - -0.062, - -0.062, - 0, - 0, - -0.122, - 1.378, - -0.122, - 0, - 0, - -0.016, - -0.016, - 1.483, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - shiftToBGR: () => { - filter.colorMatrix([ - 0, - 0, - 1, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - convolution: (matrix) => { - const m = new Float32Array(matrix); - const pixelSizeX = 1 / fxcanvas.width; - const pixelSizeY = 1 / fxcanvas.height; - const program = compileShader(convolution); - if (!program) - return; - gl.uniform1fv(program.uniform["m"], m); - gl.uniform2f(program.uniform["px"], pixelSizeX, pixelSizeY); - draw(); - }, - detectEdges: () => { - filter.convolution.call(this, [ - 0, - 1, - 0, - 1, - -4, - 1, - 0, - 1, - 0 - ]); - }, - sobelX: () => { - filter.convolution.call(this, [ - -1, - 0, - 1, - -2, - 0, - 2, - -1, - 0, - 1 - ]); - }, - sobelY: () => { - filter.convolution.call(this, [ - -1, - -2, - -1, - 0, - 0, - 0, - 1, - 2, - 1 - ]); - }, - sharpen: (amount) => { - const a = amount || 1; - filter.convolution.call(this, [ - 0, - -1 * a, - 0, - -1 * a, - 1 + 4 * a, - -1 * a, - 0, - -1 * a, - 0 - ]); - }, - emboss: (size2) => { - const s = size2 || 1; - filter.convolution.call(this, [ - -2 * s, - -1 * s, - 0, - -1 * s, - 1, - 1 * s, - 0, - 1 * s, - 2 * s - ]); - }, - blur: (size2) => { - const blurSizeX = size2 / 7 / fxcanvas.width; - const blurSizeY = size2 / 7 / fxcanvas.height; - const program = compileShader(blur); - if (!program) - return; - gl.uniform2f(program.uniform["px"], 0, blurSizeY); - draw(DRAW.INTERMEDIATE); - gl.uniform2f(program.uniform["px"], blurSizeX, 0); - draw(); - }, - pixelate: (size2) => { - const blurSizeX = size2 / fxcanvas.width; - const blurSizeY = size2 / fxcanvas.height; - const program = compileShader(pixelate); - if (!program) - return; - gl.uniform2f(program.uniform["size"], blurSizeX, blurSizeY); - draw(); - } - }; - this.add = function(name) { - const args = Array.prototype.slice.call(arguments, 1); - const func = filter[name]; - filterChain.push({ func, args }); - }; - this.reset = function() { - filterChain = []; - }; - this.get = function() { - return filterChain; - }; - this.apply = function(image28) { - resize(image28.width, image28.height); - drawCount = 0; - if (!sourceTexture) - sourceTexture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, sourceTexture); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image28); - for (let i = 0; i < filterChain.length; i++) { - lastInChain = i === filterChain.length - 1; - const f = filterChain[i]; - f.func.apply(this, f.args || []); - } - return fxcanvas; - }; - this.draw = function(image28) { - this.add("brightness", 0); - return this.apply(image28); - }; -} - -// src/image/enhance.ts -var tf = __toESM(require_tfjs_esm()); -async function histogramEqualization(inputImage) { - const squeeze14 = inputImage.shape.length === 4 ? tf.squeeze(inputImage) : inputImage; - const rgb2 = tf.split(squeeze14, 3, 2); - const min2 = [tf.min(rgb2[0]), tf.min(rgb2[1]), tf.min(rgb2[2])]; - const max5 = [tf.max(rgb2[0]), tf.max(rgb2[1]), tf.max(rgb2[2])]; - const absMax = await Promise.all(max5.map((channel) => channel.data())); - const maxValue = Math.max(absMax[0][0], absMax[1][0], absMax[2][0]); - const maxRange = maxValue > 1 ? 255 : 1; - const factor = maxRange / maxValue; - let final; - if (factor > 1) { - const sub11 = [tf.sub(rgb2[0], min2[0]), tf.sub(rgb2[1], min2[1]), tf.sub(rgb2[2], min2[2])]; - const range = [tf.sub(max5[0], min2[0]), tf.sub(max5[1], min2[1]), tf.sub(max5[2], min2[2])]; - const enh = [tf.mul(sub11[0], factor), tf.mul(sub11[1], factor), tf.mul(sub11[2], factor)]; - const stack5 = tf.stack([enh[0], enh[1], enh[2]], 2); - final = tf.reshape(stack5, [1, squeeze14.shape[0] || 0, squeeze14.shape[1] || 0, 3]); - tf.dispose([...sub11, ...range, ...enh]); - } else { - final = tf.expandDims(squeeze14, 0); - } - tf.dispose([...rgb2, ...min2, ...max5, rgb2, squeeze14, inputImage]); - return final; -} - -// src/image/image.ts -var maxSize = 3840; -var inCanvas = null; -var outCanvas = null; -var tmpCanvas = null; -var fx; -var last = { - inputSum: 0, - cacheDiff: 1, - sumMethod: 0, - inputTensor: void 0 -}; -function reset() { - last.inputSum = 0; - last.cacheDiff = 1; - last.sumMethod = 0; - last.inputTensor = void 0; -} -function canvas(width, height) { - let c; - if (env.browser) { - if (env.worker) { - if (typeof OffscreenCanvas === "undefined") - throw new Error("canvas error: attempted to run in web worker but OffscreenCanvas is not supported"); - c = new OffscreenCanvas(width, height); - } else { - if (typeof document === "undefined") - throw new Error("canvas error: attempted to run in browser but DOM is not defined"); - c = document.createElement("canvas"); - c.width = width; - c.height = height; - } - } else { - if (typeof env.Canvas !== "undefined") - c = new env.Canvas(width, height); - else if (typeof globalThis.Canvas !== "undefined") - c = new globalThis.Canvas(width, height); - } - return c; -} -function copy(input, output) { - const outputCanvas = output || canvas(input.width, input.height); - const ctx = outputCanvas.getContext("2d"); - ctx.drawImage(input, 0, 0); - return outputCanvas; -} -async function process2(input, config3, getTensor = true) { - var _a, _b, _c; - if (!input) { - if (config3.debug) - log("input error: input is missing"); - return { tensor: null, canvas: null }; - } - if (!(input instanceof tf2.Tensor) && !(typeof Image !== "undefined" && input instanceof Image) && !(typeof globalThis.Canvas !== "undefined" && input instanceof globalThis.Canvas) && !(typeof ImageData !== "undefined" && input instanceof ImageData) && !(typeof ImageBitmap !== "undefined" && input instanceof ImageBitmap) && !(typeof HTMLImageElement !== "undefined" && input instanceof HTMLImageElement) && !(typeof HTMLMediaElement !== "undefined" && input instanceof HTMLMediaElement) && !(typeof HTMLVideoElement !== "undefined" && input instanceof HTMLVideoElement) && !(typeof HTMLCanvasElement !== "undefined" && input instanceof HTMLCanvasElement) && !(typeof OffscreenCanvas !== "undefined" && input instanceof OffscreenCanvas)) { - throw new Error("input error: type not recognized"); - } - if (input instanceof tf2.Tensor) { - let tensor7 = null; - if (input["isDisposedInternal"]) - throw new Error("input error: attempted to use tensor but it is disposed"); - if (!input.shape) - throw new Error("input error: attempted to use tensor without a shape"); - if (input.shape.length === 3) { - if (input.shape[2] === 3) { - tensor7 = tf2.expandDims(input, 0); - } else if (input.shape[2] === 4) { - const rgb2 = tf2.slice3d(input, [0, 0, 0], [-1, -1, 3]); - tensor7 = tf2.expandDims(rgb2, 0); - tf2.dispose(rgb2); - } - } else if (input.shape.length === 4) { - if (input.shape[3] === 3) { - tensor7 = tf2.clone(input); - } else if (input.shape[3] === 4) { - tensor7 = tf2.slice4d(input, [0, 0, 0, 0], [-1, -1, -1, 3]); - } - } - if (tensor7 == null || tensor7.shape.length !== 4 || tensor7.shape[0] !== 1 || tensor7.shape[3] !== 3) - throw new Error(`input error: attempted to use tensor with unrecognized shape: ${input.shape.toString()}`); - if (tensor7.dtype === "int32") { - const cast8 = tf2.cast(tensor7, "float32"); - tf2.dispose(tensor7); - tensor7 = cast8; - } - return { tensor: tensor7, canvas: config3.filter.return ? outCanvas : null }; - } - if (typeof input["readyState"] !== "undefined" && input.readyState <= 2) { - if (config3.debug) - log("input stream is not ready"); - return { tensor: null, canvas: inCanvas }; - } - const originalWidth = input["naturalWidth"] || input["videoWidth"] || input["width"] || input["shape"] && input["shape"][1] > 0; - const originalHeight = input["naturalHeight"] || input["videoHeight"] || input["height"] || input["shape"] && input["shape"][2] > 0; - if (!originalWidth || !originalHeight) { - if (config3.debug) - log("cannot determine input dimensions"); - return { tensor: null, canvas: inCanvas }; - } - let targetWidth = originalWidth; - let targetHeight = originalHeight; - if (targetWidth > maxSize) { - targetWidth = maxSize; - targetHeight = Math.trunc(targetWidth * originalHeight / originalWidth); - } - if (targetHeight > maxSize) { - targetHeight = maxSize; - targetWidth = Math.trunc(targetHeight * originalWidth / originalHeight); - } - if ((((_a = config3.filter) == null ? void 0 : _a.width) || 0) > 0) - targetWidth = config3.filter.width; - else if ((((_b = config3.filter) == null ? void 0 : _b.height) || 0) > 0) - targetWidth = originalWidth * ((config3.filter.height || 0) / originalHeight); - if ((config3.filter.height || 0) > 0) - targetHeight = config3.filter.height; - else if ((config3.filter.width || 0) > 0) - targetHeight = originalHeight * ((config3.filter.width || 0) / originalWidth); - if (!targetWidth || !targetHeight) - throw new Error("input error: cannot determine dimension"); - if (!inCanvas || inCanvas.width !== targetWidth || inCanvas.height !== targetHeight) - inCanvas = canvas(targetWidth, targetHeight); - const inCtx = inCanvas.getContext("2d"); - if (typeof ImageData !== "undefined" && input instanceof ImageData) { - inCtx.putImageData(input, 0, 0); - } else { - if (config3.filter.flip && typeof inCtx.translate !== "undefined") { - inCtx.translate(originalWidth, 0); - inCtx.scale(-1, 1); - inCtx.drawImage(input, 0, 0, originalWidth, originalHeight, 0, 0, inCanvas.width, inCanvas.height); - inCtx.setTransform(1, 0, 0, 1, 0, 0); - } else { - inCtx.drawImage(input, 0, 0, originalWidth, originalHeight, 0, 0, inCanvas.width, inCanvas.height); - } - } - if (!outCanvas || inCanvas.width !== outCanvas.width || inCanvas.height !== outCanvas.height) - outCanvas = canvas(inCanvas.width, inCanvas.height); - if (config3.filter.enabled && env.webgl.supported) { - if (!fx) - fx = env.browser ? new GLImageFilter() : null; - env.filter = !!fx; - if (!(fx == null ? void 0 : fx.add)) { - if (config3.debug) - log("input process error: cannot initialize filters"); - env.webgl.supported = false; - config3.filter.enabled = false; - copy(inCanvas, outCanvas); - } else { - fx.reset(); - if (config3.filter.brightness !== 0) - fx.add("brightness", config3.filter.brightness); - if (config3.filter.contrast !== 0) - fx.add("contrast", config3.filter.contrast); - if (config3.filter.sharpness !== 0) - fx.add("sharpen", config3.filter.sharpness); - if (config3.filter.blur !== 0) - fx.add("blur", config3.filter.blur); - if (config3.filter.saturation !== 0) - fx.add("saturation", config3.filter.saturation); - if (config3.filter.hue !== 0) - fx.add("hue", config3.filter.hue); - if (config3.filter.negative) - fx.add("negative"); - if (config3.filter.sepia) - fx.add("sepia"); - if (config3.filter.vintage) - fx.add("brownie"); - if (config3.filter.sepia) - fx.add("sepia"); - if (config3.filter.kodachrome) - fx.add("kodachrome"); - if (config3.filter.technicolor) - fx.add("technicolor"); - if (config3.filter.polaroid) - fx.add("polaroid"); - if (config3.filter.pixelate !== 0) - fx.add("pixelate", config3.filter.pixelate); - if (((_c = fx.get()) == null ? void 0 : _c.length) > 1) - outCanvas = fx.apply(inCanvas); - else - outCanvas = fx.draw(inCanvas); - } - } else { - copy(inCanvas, outCanvas); - if (fx) - fx = null; - env.filter = !!fx; - } - if (!getTensor) - return { tensor: null, canvas: outCanvas }; - if (!outCanvas) - throw new Error("canvas error: cannot create output"); - let pixels; - let depth = 3; - if (typeof ImageData !== "undefined" && input instanceof ImageData || input.data && input.width && input.height) { - if (env.browser && tf2.browser) { - pixels = tf2.browser ? tf2.browser.fromPixels(input) : null; - } else { - depth = input.data.length / input.height / input.width; - const arr = new Uint8Array(input.data.buffer); - pixels = tf2.tensor(arr, [input.height, input.width, depth], "int32"); - } - } else { - if (!tmpCanvas || outCanvas.width !== tmpCanvas.width || outCanvas.height !== tmpCanvas.height) - tmpCanvas = canvas(outCanvas.width, outCanvas.height); - if (tf2.browser && env.browser) { - if (config3.backend === "webgl" || config3.backend === "humangl" || config3.backend === "webgpu") { - pixels = tf2.browser.fromPixels(outCanvas); - } else { - tmpCanvas = copy(outCanvas); - pixels = tf2.browser.fromPixels(tmpCanvas); - } - } else { - const tempCanvas = copy(outCanvas); - const tempCtx = tempCanvas.getContext("2d"); - const tempData = tempCtx.getImageData(0, 0, targetWidth, targetHeight); - depth = tempData.data.length / targetWidth / targetHeight; - const arr = new Uint8Array(tempData.data.buffer); - pixels = tf2.tensor(arr, [targetWidth, targetHeight, depth]); - } - } - if (depth === 4) { - const rgb2 = tf2.slice3d(pixels, [0, 0, 0], [-1, -1, 3]); - tf2.dispose(pixels); - pixels = rgb2; - } - if (!pixels) - throw new Error("input error: cannot create tensor"); - const casted = tf2.cast(pixels, "float32"); - const tensor6 = config3.filter.equalization ? await histogramEqualization(casted) : tf2.expandDims(casted, 0); - tf2.dispose([pixels, casted]); - if (config3.filter.autoBrightness) { - const max5 = tf2.max(tensor6); - const maxVal = await max5.data(); - config3.filter.brightness = maxVal[0] > 1 ? 1 - maxVal[0] / 255 : 1 - maxVal[0]; - tf2.dispose(max5); - } - return { tensor: tensor6, canvas: config3.filter.return ? outCanvas : null }; -} -async function skip(config3, input) { - let skipFrame = false; - if (config3.cacheSensitivity === 0 || !input.shape || input.shape.length !== 4 || input.shape[1] > 3840 || input.shape[2] > 2160) - return skipFrame; - if (!last.inputTensor) { - last.inputTensor = tf2.clone(input); - } else if (last.inputTensor.shape[1] !== input.shape[1] || last.inputTensor.shape[2] !== input.shape[2]) { - tf2.dispose(last.inputTensor); - last.inputTensor = tf2.clone(input); - } else { - const t2 = {}; - t2.diff = tf2.sub(input, last.inputTensor); - t2.squared = tf2.mul(t2.diff, t2.diff); - t2.sum = tf2.sum(t2.squared); - const diffSum = await t2.sum.data(); - const diffRelative = diffSum[0] / (input.shape[1] || 1) / (input.shape[2] || 1) / 255 / 3; - tf2.dispose([last.inputTensor, t2.diff, t2.squared, t2.sum]); - last.inputTensor = tf2.clone(input); - skipFrame = diffRelative <= (config3.cacheSensitivity || 0); - } - return skipFrame; -} -async function compare(config3, input1, input2) { - const t2 = {}; - if (!input1 || !input2 || input1.shape.length !== 4 || input1.shape.length !== input2.shape.length) { - if (!config3.debug) - log("invalid input tensor or tensor shapes do not match:", input1.shape, input2.shape); - return 0; - } - if (input1.shape[0] !== 1 || input2.shape[0] !== 1 || input1.shape[3] !== 3 || input2.shape[3] !== 3) { - if (!config3.debug) - log("input tensors must be of shape [1, height, width, 3]:", input1.shape, input2.shape); - return 0; - } - t2.input1 = tf2.clone(input1); - t2.input2 = input1.shape[1] !== input2.shape[1] || input1.shape[2] !== input2.shape[2] ? tf2.image.resizeBilinear(input2, [input1.shape[1], input1.shape[2]]) : tf2.clone(input2); - t2.diff = tf2.sub(t2.input1, t2.input2); - t2.squared = tf2.mul(t2.diff, t2.diff); - t2.sum = tf2.sum(t2.squared); - const diffSum = await t2.sum.data(); - const diffRelative = diffSum[0] / (input1.shape[1] || 1) / (input1.shape[2] || 1) / 255 / 3; - tf2.dispose([t2.input1, t2.input2, t2.diff, t2.squared, t2.sum]); - return diffRelative; -} - -// src/util/env.ts -var _canvas, _image, _imageData; -var Env = class { - constructor() { - __publicField(this, "browser"); - __publicField(this, "node"); - __publicField(this, "worker"); - __publicField(this, "platform", ""); - __publicField(this, "agent", ""); - __publicField(this, "backends", []); - __publicField(this, "initial"); - __publicField(this, "filter"); - __publicField(this, "tfjs"); - __publicField(this, "offscreen"); - __publicField(this, "perfadd", false); - __publicField(this, "tensorflow", { - version: void 0, - gpu: void 0 - }); - __publicField(this, "wasm", { - supported: void 0, - backend: void 0, - simd: void 0, - multithread: void 0 - }); - __publicField(this, "webgl", { - supported: void 0, - backend: void 0, - version: void 0, - renderer: void 0, - shader: void 0, - vendor: void 0 - }); - __publicField(this, "webgpu", { - supported: void 0, - backend: void 0, - adapter: void 0 - }); - __publicField(this, "cpu", { - model: void 0, - flags: [] - }); - __publicField(this, "kernels", []); - __privateAdd(this, _canvas, void 0); - __privateAdd(this, _image, void 0); - __privateAdd(this, _imageData, void 0); - this.browser = typeof navigator !== "undefined"; - this.node = typeof process !== "undefined" && typeof process.versions !== "undefined" && typeof process.versions.node !== "undefined"; - this.tfjs = { version: tf3.version["tfjs-core"] }; - this.offscreen = typeof OffscreenCanvas !== "undefined"; - this.initial = true; - this.worker = this.browser && this.offscreen ? typeof WorkerGlobalScope !== "undefined" : void 0; - if (typeof navigator !== "undefined") { - const raw = navigator.userAgent.match(/\(([^()]+)\)/g); - if (raw == null ? void 0 : raw[0]) { - const platformMatch = raw[0].match(/\(([^()]+)\)/g); - this.platform = (platformMatch == null ? void 0 : platformMatch[0]) ? platformMatch[0].replace(/\(|\)/g, "") : ""; - this.agent = navigator.userAgent.replace(raw[0], ""); - if (this.platform[1]) - this.agent = this.agent.replace(raw[1], ""); - this.agent = this.agent.replace(/ /g, " "); - } - } else if (typeof process !== "undefined") { - this.platform = `${process.platform} ${process.arch}`; - this.agent = `NodeJS ${process.version}`; - } - } - get Canvas() { - return __privateGet(this, _canvas); - } - set Canvas(val) { - __privateSet(this, _canvas, val); - globalThis.Canvas = val; - } - get Image() { - return __privateGet(this, _image); - } - set Image(val) { - __privateSet(this, _image, val); - globalThis.Image = val; - } - get ImageData() { - return __privateGet(this, _imageData); - } - set ImageData(val) { - __privateSet(this, _imageData, val); - globalThis.ImageData = val; - } - async updateBackend() { - this.backends = Object.keys(tf3.engine().registryFactory); - try { - this.tensorflow = { - version: tf3.backend()["binding"] ? tf3.backend()["binding"].TF_Version : void 0, - gpu: tf3.backend()["binding"] ? tf3.backend()["binding"].isUsingGpuDevice() : void 0 - }; - } catch (e) { - } - this.wasm.supported = typeof WebAssembly !== "undefined"; - this.wasm.backend = this.backends.includes("wasm"); - if (this.wasm.supported && this.wasm.backend) { - this.wasm.simd = await tf3.env().getAsync("WASM_HAS_SIMD_SUPPORT"); - this.wasm.multithread = await tf3.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"); - } - const c = canvas(100, 100); - const gl = c ? c.getContext("webgl2") : void 0; - this.webgl.supported = typeof gl !== "undefined"; - this.webgl.backend = this.backends.includes("webgl"); - if (this.webgl.supported && this.webgl.backend && gl) { - this.webgl.version = gl.getParameter(gl.VERSION); - this.webgl.vendor = gl.getParameter(gl.VENDOR); - this.webgl.renderer = gl.getParameter(gl.RENDERER); - this.webgl.shader = gl.getParameter(gl.SHADING_LANGUAGE_VERSION); - } - this.webgpu.supported = this.browser && typeof navigator.gpu !== "undefined"; - this.webgpu.backend = this.backends.includes("webgpu"); - try { - if (this.webgpu.supported) { - const adapter = await navigator.gpu.requestAdapter(); - this.webgpu.adapter = await (adapter == null ? void 0 : adapter.requestAdapterInfo()); - } - } catch (e) { - this.webgpu.supported = false; - } - try { - this.kernels = tf3.getKernelsForBackend(tf3.getBackend()).map((kernel) => kernel.kernelName.toLowerCase()); - } catch (e) { - } - } - updateCPU() { - const cpu = { model: "", flags: [] }; - if (this.node && this.platform.startsWith("linux")) { - } - if (!this.cpu) - Object.defineProperty(this, "cpu", { value: cpu }); - else - this.cpu = cpu; - } -}; -_canvas = new WeakMap(); -_image = new WeakMap(); -_imageData = new WeakMap(); -var env = new Env(); - -// src/util/webcam.ts -var WebCam = class { - constructor() { - __publicField(this, "config"); - __publicField(this, "element"); - __publicField(this, "stream"); - __publicField(this, "devices", []); - __publicField(this, "enumerate", async () => { - try { - const devices = await navigator.mediaDevices.enumerateDevices(); - this.devices = devices.filter((device) => device.kind === "videoinput"); - } catch (e) { - this.devices = []; - } - return this.devices; - }); - __publicField(this, "start", async (webcamConfig) => { - var _a, _b; - if (webcamConfig == null ? void 0 : webcamConfig.debug) - this.config.debug = webcamConfig == null ? void 0 : webcamConfig.debug; - if (webcamConfig == null ? void 0 : webcamConfig.crop) - this.config.crop = webcamConfig == null ? void 0 : webcamConfig.crop; - if (webcamConfig == null ? void 0 : webcamConfig.mode) - this.config.mode = webcamConfig == null ? void 0 : webcamConfig.mode; - if (webcamConfig == null ? void 0 : webcamConfig.width) - this.config.width = webcamConfig == null ? void 0 : webcamConfig.width; - if (webcamConfig == null ? void 0 : webcamConfig.height) - this.config.height = webcamConfig == null ? void 0 : webcamConfig.height; - if (webcamConfig == null ? void 0 : webcamConfig.id) - this.config.id = webcamConfig == null ? void 0 : webcamConfig.id; - if (webcamConfig == null ? void 0 : webcamConfig.element) { - if (typeof webcamConfig.element === "string") { - const el = document.getElementById(webcamConfig.element); - if (el && el instanceof HTMLVideoElement) { - this.element = el; - } else { - if (this.config.debug) - log("webcam", "cannot get dom element", webcamConfig.element); - return; - } - } else if (webcamConfig.element instanceof HTMLVideoElement) { - this.element = webcamConfig.element; - } else { - if (this.config.debug) - log("webcam", "unknown dom element", webcamConfig.element); - return; - } - } else { - this.element = document.createElement("video"); - } - const requestedConstraints = { - audio: false, - video: { - facingMode: this.config.mode === "front" ? "user" : "environment", - resizeMode: this.config.crop ? "crop-and-scale" : "none" - } - }; - if (((_a = this.config) == null ? void 0 : _a.width) > 0) - requestedConstraints.video.width = { ideal: this.config.width }; - if (((_b = this.config) == null ? void 0 : _b.height) > 0) - requestedConstraints.video.height = { ideal: this.config.height }; - if (this.config.id) - requestedConstraints.video.deviceId = this.config.id; - this.element.addEventListener("play", () => { - if (this.config.debug) - log("webcam", "play"); - }); - this.element.addEventListener("pause", () => { - if (this.config.debug) - log("webcam", "pause"); - }); - this.element.addEventListener("click", async () => { - if (!this.element || !this.stream) - return; - if (this.element.paused) - await this.element.play(); - else - this.element.pause(); - }); - if (!(navigator == null ? void 0 : navigator.mediaDevices)) { - if (this.config.debug) - log("webcam", "no devices"); - return; - } - try { - this.stream = await navigator.mediaDevices.getUserMedia(requestedConstraints); - } catch (err) { - log("webcam", err); - return; - } - if (!this.stream) { - if (this.config.debug) - log("webcam", "no stream"); - return; - } - this.element.srcObject = this.stream; - const ready3 = new Promise((resolve) => { - if (!this.element) - resolve(false); - else - this.element.onloadeddata = () => resolve(true); - }); - await ready3; - await this.element.play(); - if (this.config.debug) { - log("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 - }); - } - }); - __publicField(this, "pause", () => { - if (this.element) - this.element.pause(); - }); - __publicField(this, "play", async () => { - if (this.element) - await this.element.play(); - }); - __publicField(this, "stop", () => { - if (this.config.debug) - log("webcam", "stop"); - if (this.track) - this.track.stop(); - }); - this.config = { - element: void 0, - debug: true, - mode: "front", - crop: false, - width: 0, - height: 0 - }; - } - get track() { - if (!this.stream) - return void 0; - return this.stream.getVideoTracks()[0]; - } - get capabilities() { - if (!this.track) - return void 0; - return this.track.getCapabilities ? this.track.getCapabilities() : void 0; - } - get constraints() { - if (!this.track) - return void 0; - return this.track.getConstraints ? this.track.getConstraints() : void 0; - } - get settings() { - if (!this.stream) - return void 0; - const track = this.stream.getVideoTracks()[0]; - return track.getSettings ? track.getSettings() : void 0; - } - get label() { - if (!this.track) - return ""; - return this.track.label; - } - get paused() { - var _a; - return ((_a = this.element) == null ? void 0 : _a.paused) || false; - } - get width() { - var _a; - return ((_a = this.element) == null ? void 0 : _a.videoWidth) || 0; - } - get height() { - var _a; - return ((_a = this.element) == null ? void 0 : _a.videoHeight) || 0; - } -}; - -// src/tfjs/load.ts -var tf4 = __toESM(require_tfjs_esm()); - -// models/models.json -var models_exports = {}; -__export(models_exports, { - age: () => age, - "anti-spoofing": () => anti_spoofing, - antispoof: () => antispoof, - blazeface: () => blazeface, - "blazeface-back": () => blazeface_back, - "blazeface-front": () => blazeface_front, - "blazepose-detector": () => blazepose_detector, - "blazepose-full": () => blazepose_full, - "blazepose-heavy": () => blazepose_heavy, - "blazepose-lite": () => blazepose_lite, - centernet: () => centernet, - default: () => models_default, - efficientpose: () => efficientpose, - "efficientpose-i-lite": () => efficientpose_i_lite, - "efficientpose-ii-lite": () => efficientpose_ii_lite, - "efficientpose-iv": () => efficientpose_iv, - emotion: () => emotion, - faceboxes: () => faceboxes, - facemesh: () => facemesh, - "facemesh-attention": () => facemesh_attention, - "facemesh-attention-pinto": () => facemesh_attention_pinto, - "facemesh-detection-full": () => facemesh_detection_full, - "facemesh-detection-short": () => facemesh_detection_short, - faceres: () => faceres, - "faceres-deep": () => faceres_deep, - gear: () => gear, - gender: () => gender, - "gender-ssrnet-imdb": () => gender_ssrnet_imdb, - handdetect: () => handdetect, - "handlandmark-full": () => handlandmark_full, - "handlandmark-lite": () => handlandmark_lite, - "handlandmark-sparse": () => handlandmark_sparse, - handskeleton: () => handskeleton, - handtrack: () => handtrack, - "insightface-efficientnet-b0": () => insightface_efficientnet_b0, - "insightface-ghostnet-strides1": () => insightface_ghostnet_strides1, - "insightface-ghostnet-strides2": () => insightface_ghostnet_strides2, - "insightface-mobilenet-emore": () => insightface_mobilenet_emore, - "insightface-mobilenet-swish": () => insightface_mobilenet_swish, - iris: () => iris, - liveness: () => liveness, - meet: () => meet, - mobileface: () => mobileface, - mobilefacenet: () => mobilefacenet, - models: () => models, - "movenet-lightning": () => movenet_lightning, - "movenet-multipose": () => movenet_multipose, - "movenet-thunder": () => movenet_thunder, - nanodet: () => nanodet, - "nanodet-e": () => nanodet_e, - "nanodet-g": () => nanodet_g, - "nanodet-m": () => nanodet_m, - "nanodet-t": () => nanodet_t, - posenet: () => posenet, - rvm: () => rvm, - selfie: () => selfie -}); -var antispoof = 853098; -var blazeface = 538928; -var centernet = 4030290; -var emotion = 820516; -var facemesh = 1477958; -var faceres = 6978814; -var handlandmark_lite = 2023432; -var handtrack = 2964837; -var iris = 2599092; -var liveness = 592976; -var models = 0; -var movenet_lightning = 4650216; -var age = 161240; -var blazeface_back = 538928; -var blazeface_front = 402048; -var blazepose_detector = 5928856; -var blazepose_full = 6339202; -var blazepose_heavy = 27502466; -var blazepose_lite = 2726402; -var efficientpose = 5651240; -var faceboxes = 2013002; -var facemesh_attention_pinto = 2387598; -var facemesh_attention = 2382414; -var facemesh_detection_full = 1026192; -var facemesh_detection_short = 201268; -var faceres_deep = 13957620; -var gear = 1498916; -var gender_ssrnet_imdb = 161236; -var gender = 201808; -var handdetect = 3515612; -var handlandmark_full = 5431368; -var handlandmark_sparse = 5286322; -var handskeleton = 5502280; -var meet = 372228; -var mobileface = 2183192; -var mobilefacenet = 5171976; -var movenet_multipose = 9448838; -var movenet_thunder = 12477112; -var nanodet = 7574558; -var posenet = 5032780; -var rvm = 3739355; -var selfie = 212886; -var anti_spoofing = 853098; -var efficientpose_i_lite = 2269064; -var efficientpose_ii_lite = 5651240; -var efficientpose_iv = 25643252; -var insightface_efficientnet_b0 = 13013224; -var insightface_ghostnet_strides1 = 8093408; -var insightface_ghostnet_strides2 = 8049584; -var insightface_mobilenet_emore = 6938536; -var insightface_mobilenet_swish = 12168584; -var nanodet_e = 12319156; -var nanodet_g = 7574558; -var nanodet_m = 1887474; -var nanodet_t = 5294216; -var models_default = { - antispoof, - blazeface, - centernet, - emotion, - facemesh, - faceres, - "handlandmark-lite": handlandmark_lite, - handtrack, - iris, - liveness, - models, - "movenet-lightning": movenet_lightning, - age, - "blazeface-back": blazeface_back, - "blazeface-front": blazeface_front, - "blazepose-detector": blazepose_detector, - "blazepose-full": blazepose_full, - "blazepose-heavy": blazepose_heavy, - "blazepose-lite": blazepose_lite, - efficientpose, - faceboxes, - "facemesh-attention-pinto": facemesh_attention_pinto, - "facemesh-attention": facemesh_attention, - "facemesh-detection-full": facemesh_detection_full, - "facemesh-detection-short": facemesh_detection_short, - "faceres-deep": faceres_deep, - gear, - "gender-ssrnet-imdb": gender_ssrnet_imdb, - gender, - handdetect, - "handlandmark-full": handlandmark_full, - "handlandmark-sparse": handlandmark_sparse, - handskeleton, - meet, - mobileface, - mobilefacenet, - "movenet-multipose": movenet_multipose, - "movenet-thunder": movenet_thunder, - nanodet, - posenet, - rvm, - selfie, - "anti-spoofing": anti_spoofing, - "efficientpose-i-lite": efficientpose_i_lite, - "efficientpose-ii-lite": efficientpose_ii_lite, - "efficientpose-iv": efficientpose_iv, - "insightface-efficientnet-b0": insightface_efficientnet_b0, - "insightface-ghostnet-strides1": insightface_ghostnet_strides1, - "insightface-ghostnet-strides2": insightface_ghostnet_strides2, - "insightface-mobilenet-emore": insightface_mobilenet_emore, - "insightface-mobilenet-swish": insightface_mobilenet_swish, - "nanodet-e": nanodet_e, - "nanodet-g": nanodet_g, - "nanodet-m": nanodet_m, - "nanodet-t": nanodet_t -}; - -// src/tfjs/load.ts -var options = { - cacheModels: true, - cacheSupported: true, - verbose: true, - debug: false, - modelBasePath: "" -}; -var modelStats = {}; -async function httpHandler(url, init4) { - if (options.debug) - log("load model fetch:", url, init4); - return fetch(url, init4); -} -function setModelLoadOptions(config3) { - options.cacheModels = config3.cacheModels; - options.verbose = config3.debug; - options.modelBasePath = config3.modelBasePath; -} -async function loadModel(modelPath) { - var _a, _b, _c, _d; - let modelUrl = join(options.modelBasePath, modelPath || ""); - if (!modelUrl.toLowerCase().endsWith(".json")) - modelUrl += ".json"; - const modelPathSegments = modelUrl.includes("/") ? modelUrl.split("/") : modelUrl.split("\\"); - const shortModelName = modelPathSegments[modelPathSegments.length - 1].replace(".json", ""); - const cachedModelName = "indexeddb://" + shortModelName; - modelStats[shortModelName] = { - name: shortModelName, - sizeFromManifest: 0, - sizeLoadedWeights: 0, - sizeDesired: models_exports[shortModelName], - inCache: false, - url: "" - }; - options.cacheSupported = typeof indexedDB !== "undefined"; - let cachedModels = {}; - try { - cachedModels = options.cacheSupported && options.cacheModels ? await tf4.io.listModels() : {}; - } catch (e) { - options.cacheSupported = false; - } - modelStats[shortModelName].inCache = options.cacheSupported && options.cacheModels && Object.keys(cachedModels).includes(cachedModelName); - modelStats[shortModelName].url = modelStats[shortModelName].inCache ? cachedModelName : modelUrl; - const tfLoadOptions = typeof fetch === "undefined" ? {} : { fetchFunc: (url, init4) => httpHandler(url, init4) }; - let model23 = new tf4.GraphModel(modelStats[shortModelName].url, tfLoadOptions); - let loaded = false; - try { - model23.findIOHandler(); - if (options.debug) - log("model load handler:", model23["handler"]); - } catch (err) { - log("error finding model i/o handler:", modelUrl, err); - } - try { - const artifacts = await ((_a = model23.handler) == null ? void 0 : _a.load()) || null; - modelStats[shortModelName].sizeFromManifest = ((_b = artifacts == null ? void 0 : artifacts.weightData) == null ? void 0 : _b.byteLength) || 0; - if (artifacts) - model23.loadSync(artifacts); - else - model23 = await tf4.loadGraphModel(modelStats[shortModelName].inCache ? cachedModelName : modelUrl, tfLoadOptions); - modelStats[shortModelName].sizeLoadedWeights = ((_d = (_c = model23.artifacts) == null ? void 0 : _c.weightData) == null ? void 0 : _d.byteLength) || 0; - if (options.verbose) - log("load:", { model: shortModelName, url: model23["modelUrl"], bytes: modelStats[shortModelName].sizeLoadedWeights }); - loaded = true; - } catch (err) { - log("error loading model:", modelUrl, err); - } - if (loaded && options.cacheModels && options.cacheSupported && !modelStats[shortModelName].inCache) { - try { - const saveResult = await model23.save(cachedModelName); - if (options.debug) - log("model saved:", cachedModelName, saveResult); - } catch (err) { - log("error saving model:", modelUrl, err); - } - } - return model23; -} - -// package.json -var version2 = "3.0.2"; - -// src/tfjs/backend.ts -var tf7 = __toESM(require_tfjs_esm()); - -// src/tfjs/humangl.ts -var tf5 = __toESM(require_tfjs_esm()); -var config2 = { - name: "humangl", - priority: 999, - canvas: null, - gl: null, - extensions: [], - webGLattr: { - alpha: false, - antialias: false, - premultipliedAlpha: false, - preserveDrawingBuffer: false, - depth: false, - stencil: false, - failIfMajorPerformanceCaveat: false, - desynchronized: true - } -}; -function extensions() { - const gl = config2.gl; - if (!gl) - return; - config2.extensions = gl.getSupportedExtensions(); -} -function register(instance) { - var _a; - if (instance.config.backend !== "humangl") - return; - if (config2.name in tf5.engine().registry && !((_a = config2 == null ? void 0 : config2.gl) == null ? void 0 : _a.getParameter(config2.gl.VERSION))) { - log("humangl error: backend invalid context"); - instance.models.reset(); - } - if (!tf5.findBackend(config2.name)) { - try { - config2.canvas = canvas(100, 100); - } catch (err) { - log("humangl error: cannot create canvas:", err); - return; - } - try { - config2.gl = config2.canvas.getContext("webgl2", config2.webGLattr); - if (!config2.gl) { - log("humangl error: cannot get webgl context"); - return; - } - const glv2 = config2.gl.getParameter(config2.gl.VERSION).includes("2.0"); - if (!glv2) { - log("backend override: using fallback webgl backend as webgl 2.0 is not detected"); - instance.config.backend = "webgl"; - return; - } - if (config2.canvas) { - config2.canvas.addEventListener("webglcontextlost", (e) => { - log("humangl error:", e.type); - log("possible browser memory leak using webgl or conflict with multiple backend registrations"); - instance.emit("error"); - throw new Error("backend error: webgl context lost"); - }); - config2.canvas.addEventListener("webglcontextrestored", (e) => { - log("humangl error: context restored:", e); - }); - config2.canvas.addEventListener("webglcontextcreationerror", (e) => { - log("humangl error: context create:", e); - }); - } - } catch (err) { - log("humangl error: cannot get webgl context:", err); - return; - } - try { - tf5.setWebGLContext(2, config2.gl); - } catch (err) { - log("humangl error: cannot set webgl context:", err); - return; - } - try { - const ctx = new tf5.GPGPUContext(config2.gl); - tf5.registerBackend(config2.name, () => new tf5.MathBackendWebGL(ctx), config2.priority); - } catch (err) { - log("humangl error: cannot register webgl backend:", err); - return; - } - try { - const kernels = tf5.getKernelsForBackend("webgl"); - kernels.forEach((kernelConfig) => { - const newKernelConfig = { ...kernelConfig, backendName: config2.name }; - tf5.registerKernel(newKernelConfig); - }); - } catch (err) { - log("humangl error: cannot update webgl backend registration:", err); - return; - } - try { - if (tf5.env().flagRegistry.WEBGL_VERSION) - tf5.env().set("WEBGL_VERSION", 2); - } catch (err) { - log("humangl error: cannot set WebGL backend flags:", err); - return; - } - extensions(); - const backend4 = tf5.backend(); - const current = typeof backend4["gpgpu"] !== "undefined" ? backend4["getGPGPUContext"]().gl : null; - if (current) { - if (instance.config.debug) - log("humangl backend registered:", { webgl: current.getParameter(current.VERSION), renderer: current.getParameter(current.RENDERER) }); - } else { - log("humangl error: no current gl context:", current, config2.gl); - } - } -} - -// src/tfjs/constants.ts -var tf6 = __toESM(require_tfjs_esm()); -var constants = { - tf255: 255, - tf1: 1, - tf2: 2, - tf05: 0.5, - tf127: 127.5, - rgb: [0.2989, 0.587, 0.114] -}; -function init() { - constants.tf255 = tf6.scalar(255, "float32"); - constants.tf1 = tf6.scalar(1, "float32"); - constants.tf2 = tf6.scalar(2, "float32"); - constants.tf05 = tf6.scalar(0.5, "float32"); - constants.tf127 = tf6.scalar(127.5, "float32"); - constants.rgb = tf6.tensor1d([0.2989, 0.587, 0.114], "float32"); -} - -// src/tfjs/backend.ts -async function getBestBackend() { - var _a; - await env.updateBackend(); - if ((_a = env.tensorflow) == null ? void 0 : _a.version) - return "tensorflow"; - if (env.webgpu.supported && env.webgpu.backend) - return "webgpu"; - if (env.webgl.supported && env.webgl.backend) - return "webgl"; - if (env.wasm.supported && env.wasm.backend) - return "wasm"; - return "cpu"; -} -function registerCustomOps(config3) { - const newKernels = []; - if (!env.kernels.includes("mod")) { - const kernelMod = { - kernelName: "Mod", - backendName: tf7.getBackend(), - kernelFunc: (op) => tf7.tidy(() => tf7.sub(op.inputs.a, tf7.mul(tf7.div(op.inputs.a, op.inputs.b), op.inputs.b))) - }; - tf7.registerKernel(kernelMod); - env.kernels.push("mod"); - newKernels.push("mod"); - } - if (!env.kernels.includes("floormod")) { - const kernelFloorMod = { - kernelName: "FloorMod", - backendName: tf7.getBackend(), - kernelFunc: (op) => tf7.tidy(() => tf7.add(tf7.mul(tf7.floorDiv(op.inputs.a, op.inputs.b), op.inputs.b), tf7.mod(op.inputs.a, op.inputs.b))) - }; - tf7.registerKernel(kernelFloorMod); - env.kernels.push("floormod"); - newKernels.push("floormod"); - } - if (!env.kernels.includes("rotatewithoffset") && config3.softwareKernels) { - const kernelRotateWithOffset = { - kernelName: "RotateWithOffset", - backendName: tf7.getBackend(), - kernelFunc: (op) => tf7.tidy(() => { - const backend4 = tf7.getBackend(); - tf7.setBackend("cpu"); - const t2 = tf7.image.rotateWithOffset(op.inputs.image, op.attrs.radians, op.attrs.fillValue, op.attrs.center); - tf7.setBackend(backend4); - return t2; - }) - }; - tf7.registerKernel(kernelRotateWithOffset); - env.kernels.push("rotatewithoffset"); - newKernels.push("rotatewithoffset"); - } - if (newKernels.length > 0 && config3.debug) - log("registered kernels:", newKernels); -} -var defaultFlags = {}; -async function check(instance, force = false) { - var _a; - instance.state = "backend"; - if (((_a = instance.config.backend) == null ? void 0 : _a.length) === 0) - instance.config.backend = await getBestBackend(); - if (force || env.initial || instance.config.backend && instance.config.backend.length > 0 && tf7.getBackend() !== instance.config.backend) { - const timeStamp = now(); - if (instance.config.backend && instance.config.backend.length > 0) { - if (typeof window === "undefined" && typeof WorkerGlobalScope !== "undefined" && instance.config.debug) { - if (instance.config.debug) - log("running inside web worker"); - } - if (env.browser && instance.config.backend === "tensorflow") { - if (instance.config.debug) - log("override: backend set to tensorflow while running in browser"); - instance.config.backend = "webgl"; - } - if (env.node && (instance.config.backend === "webgl" || instance.config.backend === "humangl")) { - if (instance.config.debug) - log(`override: backend set to ${instance.config.backend} while running in nodejs`); - instance.config.backend = "tensorflow"; - } - if (env.browser && instance.config.backend === "webgpu") { - if (typeof navigator === "undefined" || typeof navigator.gpu === "undefined") { - log("override: backend set to webgpu but browser does not support webgpu"); - instance.config.backend = "webgl"; - } else { - const adapter = await navigator.gpu.requestAdapter(); - if (instance.config.debug) - log("enumerated webgpu adapter:", adapter); - if (!adapter) { - log("override: backend set to webgpu but browser reports no available gpu"); - instance.config.backend = "webgl"; - } else { - const adapterInfo = "requestAdapterInfo" in adapter ? await adapter.requestAdapterInfo() : void 0; - log("webgpu adapter info:", adapterInfo); - } - } - } - let available = Object.keys(tf7.engine().registryFactory); - if (instance.config.backend === "humangl" && !available.includes("humangl")) { - register(instance); - available = Object.keys(tf7.engine().registryFactory); - } - if (instance.config.debug) - log("available backends:", available); - if (!available.includes(instance.config.backend)) { - log(`error: backend ${instance.config.backend} not found in registry`); - instance.config.backend = env.node ? "tensorflow" : "webgl"; - if (instance.config.debug) - log(`override: setting backend ${instance.config.backend}`); - } - if (instance.config.debug) - log("setting backend:", [instance.config.backend]); - if (instance.config.backend === "wasm") { - if (tf7.env().flagRegistry.CANVAS2D_WILL_READ_FREQUENTLY) - tf7.env().set("CANVAS2D_WILL_READ_FREQUENTLY", true); - if (instance.config.debug) - log("wasm path:", instance.config.wasmPath); - if (typeof tf7.setWasmPaths !== "undefined") - tf7.setWasmPaths(instance.config.wasmPath, instance.config.wasmPlatformFetch); - else - throw new Error("backend error: attempting to use wasm backend but wasm path is not set"); - let mt = false; - let simd = false; - try { - mt = await tf7.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"); - simd = await tf7.env().getAsync("WASM_HAS_SIMD_SUPPORT"); - if (instance.config.debug) - log(`wasm execution: ${simd ? "simd" : "no simd"} ${mt ? "multithreaded" : "singlethreaded"}`); - if (instance.config.debug && !simd) - log("warning: wasm simd support is not enabled"); - } catch (e) { - log("wasm detection failed"); - } - } - try { - await tf7.setBackend(instance.config.backend); - await tf7.ready(); - } catch (err) { - log("error: cannot set backend:", instance.config.backend, err); - return false; - } - if (instance.config.debug) - defaultFlags = JSON.parse(JSON.stringify(tf7.env().flags)); - } - if (tf7.getBackend() === "humangl" || tf7.getBackend() === "webgl") { - if (tf7.env().flagRegistry.WEBGL_USE_SHAPES_UNIFORMS) - tf7.env().set("WEBGL_USE_SHAPES_UNIFORMS", true); - if (tf7.env().flagRegistry.WEBGL_EXP_CONV) - tf7.env().set("WEBGL_EXP_CONV", true); - if (instance.config.debug && typeof instance.config.deallocate !== "undefined" && instance.config.deallocate) { - log("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:", true); - tf7.env().set("WEBGL_DELETE_TEXTURE_THRESHOLD", 0); - } - } - if (tf7.getBackend() === "webgpu") { - } - if (instance.config.debug) { - const newFlags = tf7.env().flags; - const updatedFlags = {}; - for (const key of Object.keys(newFlags)) { - if (defaultFlags[key] === newFlags[key]) - continue; - updatedFlags[key] = newFlags[key]; - } - if (instance.config.debug && Object.keys(updatedFlags).length > 0) - log("backend:", tf7.getBackend(), "flags:", updatedFlags); - } - if (instance.config.flags && Object.keys(instance.config.flags).length > 0) { - if (instance.config.debug) - log("flags:", instance.config["flags"]); - for (const [key, val] of Object.entries(instance.config.flags)) { - tf7.env().set(key, val); - } - } - tf7.enableProdMode(); - init(); - instance.performance.initBackend = Math.trunc(now() - timeStamp); - instance.config.backend = tf7.getBackend(); - await env.updateBackend(); - registerCustomOps(instance.config); - env.initial = false; - } - return true; -} -function fakeOps(kernelNames, config3) { - for (const kernelName of kernelNames) { - const kernelConfig = { - kernelName, - backendName: config3.backend, - kernelFunc: (param) => { - var _a; - if (config3.debug) - log("kernelFunc", kernelName, config3.backend, param); - return (_a = param == null ? void 0 : param.inputs) == null ? void 0 : _a.info; - } - }; - tf7.registerKernel(kernelConfig); - } - env.kernels = tf7.getKernelsForBackend(tf7.getBackend()).map((kernel) => kernel.kernelName.toLowerCase()); -} - -// src/draw/draw.ts -var draw_exports = {}; -__export(draw_exports, { - all: () => all, - body: () => body, - canvas: () => canvas2, - face: () => face, - gesture: () => gesture, - hand: () => hand, - init: () => init2, - object: () => object, - options: () => options2, - person: () => person -}); - -// src/draw/primitives.ts -var getCanvasContext = (input) => { - if (!input) - log("draw error: invalid canvas"); - else if (!input.getContext) - log("draw error: canvas context not defined"); - else { - const ctx = input.getContext("2d"); - if (!ctx) - log("draw error: cannot get canvas context"); - else - return ctx; - } - return null; -}; -var rad2deg = (theta) => Math.round(theta * 180 / Math.PI); -var replace = (str, source, target) => str.replace(source, typeof target === "number" ? target.toFixed(1) : target); -var colorDepth = (z, opt) => { - if (!opt.useDepth || typeof z === "undefined") - return opt.color; - const rgb2 = Uint8ClampedArray.from([127 + 2 * z, 127 - 2 * z, 255]); - return `rgba(${rgb2[0]}, ${rgb2[1]}, ${rgb2[2]}, ${opt.alpha})`; -}; -function labels(ctx, str, startX, startY, localOptions2) { - const line = str.replace(/\[.*\]/g, "").split("\n").map((l) => l.trim()); - const x = Math.max(0, startX); - for (let i = line.length - 1; i >= 0; i--) { - const y = i * localOptions2.lineHeight + startY; - if (localOptions2.shadowColor && localOptions2.shadowColor !== "") { - ctx.fillStyle = localOptions2.shadowColor; - ctx.fillText(line[i], x + 5, y + 16); - } - ctx.fillStyle = localOptions2.labelColor; - ctx.fillText(line[i], x + 4, y + 15); - } -} -function point(ctx, x, y, z, localOptions2) { - ctx.fillStyle = colorDepth(z, localOptions2); - ctx.beginPath(); - ctx.arc(x, y, localOptions2.pointSize, 0, 2 * Math.PI); - ctx.fill(); -} -function rect(ctx, x, y, width, height, localOptions2) { - ctx.beginPath(); - ctx.lineWidth = localOptions2.lineWidth; - if (localOptions2.useCurves) { - const cx = (x + x + width) / 2; - const cy = (y + y + height) / 2; - ctx.ellipse(cx, cy, width / 2, height / 2, 0, 0, 2 * Math.PI); - } else { - ctx.moveTo(x + localOptions2.roundRect, y); - ctx.lineTo(x + width - localOptions2.roundRect, y); - ctx.quadraticCurveTo(x + width, y, x + width, y + localOptions2.roundRect); - ctx.lineTo(x + width, y + height - localOptions2.roundRect); - ctx.quadraticCurveTo(x + width, y + height, x + width - localOptions2.roundRect, y + height); - ctx.lineTo(x + localOptions2.roundRect, y + height); - ctx.quadraticCurveTo(x, y + height, x, y + height - localOptions2.roundRect); - ctx.lineTo(x, y + localOptions2.roundRect); - ctx.quadraticCurveTo(x, y, x + localOptions2.roundRect, y); - ctx.closePath(); - } - ctx.stroke(); -} -function lines(ctx, points, localOptions2) { - if (points.length < 2) - return; - ctx.beginPath(); - ctx.moveTo(points[0][0], points[0][1]); - for (const pt of points) { - ctx.strokeStyle = colorDepth(pt[2] || 0, localOptions2); - ctx.lineTo(Math.trunc(pt[0]), Math.trunc(pt[1])); - } - ctx.stroke(); - if (localOptions2.fillPolygons) { - ctx.closePath(); - ctx.fill(); - } -} -function curves(ctx, points, localOptions2) { - if (points.length < 2) - return; - ctx.lineWidth = localOptions2.lineWidth; - if (!localOptions2.useCurves || points.length <= 2) { - lines(ctx, points, localOptions2); - return; - } - ctx.moveTo(points[0][0], points[0][1]); - for (let i = 0; i < points.length - 2; i++) { - const xc = (points[i][0] + points[i + 1][0]) / 2; - const yc = (points[i][1] + points[i + 1][1]) / 2; - ctx.quadraticCurveTo(points[i][0], points[i][1], xc, yc); - } - ctx.quadraticCurveTo(points[points.length - 2][0], points[points.length - 2][1], points[points.length - 1][0], points[points.length - 1][1]); - ctx.stroke(); - if (localOptions2.fillPolygons) { - ctx.closePath(); - ctx.fill(); - } -} -function arrow(ctx, from, to, radius = 5) { - let angle; - let x; - let y; - ctx.beginPath(); - ctx.moveTo(from[0], from[1]); - ctx.lineTo(to[0], to[1]); - angle = Math.atan2(to[1] - from[1], to[0] - from[0]); - x = radius * Math.cos(angle) + to[0]; - y = radius * Math.sin(angle) + to[1]; - ctx.moveTo(x, y); - angle += 1 / 3 * (2 * Math.PI); - x = radius * Math.cos(angle) + to[0]; - y = radius * Math.sin(angle) + to[1]; - ctx.lineTo(x, y); - angle += 1 / 3 * (2 * Math.PI); - x = radius * Math.cos(angle) + to[0]; - y = radius * Math.sin(angle) + to[1]; - ctx.lineTo(x, y); - ctx.closePath(); - ctx.stroke(); - ctx.fill(); -} - -// src/draw/options.ts -var options2 = { - color: "rgba(173, 216, 230, 0.6)", - labelColor: "rgba(173, 216, 230, 1)", - shadowColor: "black", - alpha: 0.5, - font: 'small-caps 16px "Segoe UI"', - lineHeight: 18, - lineWidth: 4, - pointSize: 2, - roundRect: 8, - drawPoints: false, - drawLabels: true, - drawBoxes: true, - drawAttention: true, - drawGestures: true, - drawPolygons: true, - drawGaze: true, - fillPolygons: false, - useDepth: true, - useCurves: false, - faceLabels: "", - bodyLabels: "", - bodyPartLabels: "", - objectLabels: "", - handLabels: "", - fingerLabels: "", - gestureLabels: "" -}; - -// src/face/facemeshcoords.ts -var meshAnnotations = { - 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], - noseTip: [1], - noseBottom: [2], - noseRightCorner: [98], - noseLeftCorner: [327], - rightCheek: [205], - leftCheek: [425] -}; -var meshLandmarks = { - count: 468, - mouth: 13, - symmetryLine: [13, meshAnnotations.midwayBetweenEyes[0]] -}; -var blazeFaceLandmarks = { - leftEye: 0, - rightEye: 1, - nose: 2, - mouth: 3, - leftEar: 4, - rightEar: 5, - symmetryLine: [3, 2] -}; -var irisIndices = [ - { key: "EyeUpper0", indices: [9, 10, 11, 12, 13, 14, 15] }, - { key: "EyeUpper1", indices: [25, 26, 27, 28, 29, 30, 31] }, - { key: "EyeUpper2", indices: [41, 42, 43, 44, 45, 46, 47] }, - { key: "EyeLower0", indices: [0, 1, 2, 3, 4, 5, 6, 7, 8] }, - { key: "EyeLower1", indices: [16, 17, 18, 19, 20, 21, 22, 23, 24] }, - { key: "EyeLower2", indices: [32, 33, 34, 35, 36, 37, 38, 39, 40] }, - { key: "EyeLower3", indices: [54, 55, 56, 57, 58, 59, 60, 61, 62] }, - { key: "EyebrowUpper", indices: [63, 64, 65, 66, 67, 68, 69, 70] }, - { key: "EyebrowLower", indices: [48, 49, 50, 51, 52, 53] } -]; -var UV468 = [ - [0.499976992607117, 0.652534008026123], - [0.500025987625122, 0.547487020492554], - [0.499974012374878, 0.602371990680695], - [0.482113003730774, 0.471979022026062], - [0.500150978565216, 0.527155995368958], - [0.499909996986389, 0.498252987861633], - [0.499523013830185, 0.40106201171875], - [0.289712011814117, 0.380764007568359], - [0.499954998493195, 0.312398016452789], - [0.499987006187439, 0.269918978214264], - [0.500023007392883, 0.107050001621246], - [0.500023007392883, 0.666234016418457], - [0.5000159740448, 0.679224014282227], - [0.500023007392883, 0.692348003387451], - [0.499976992607117, 0.695277988910675], - [0.499976992607117, 0.70593398809433], - [0.499976992607117, 0.719385027885437], - [0.499976992607117, 0.737019002437592], - [0.499967992305756, 0.781370997428894], - [0.499816000461578, 0.562981009483337], - [0.473773002624512, 0.573909997940063], - [0.104906998574734, 0.254140973091125], - [0.365929991006851, 0.409575998783112], - [0.338757991790771, 0.41302502155304], - [0.311120003461838, 0.409460008144379], - [0.274657994508743, 0.389131009578705], - [0.393361985683441, 0.403706014156342], - [0.345234006643295, 0.344011008739471], - [0.370094001293182, 0.346076011657715], - [0.319321990013123, 0.347265005111694], - [0.297903001308441, 0.353591024875641], - [0.24779200553894, 0.410809993743896], - [0.396889001131058, 0.842755019664764], - [0.280097991228104, 0.375599980354309], - [0.106310002505779, 0.399955987930298], - [0.2099249958992, 0.391353011131287], - [0.355807989835739, 0.534406006336212], - [0.471751004457474, 0.65040397644043], - [0.474155008792877, 0.680191993713379], - [0.439785003662109, 0.657229006290436], - [0.414617002010345, 0.66654098033905], - [0.450374007225037, 0.680860996246338], - [0.428770989179611, 0.682690978050232], - [0.374971002340317, 0.727805018424988], - [0.486716985702515, 0.547628998756409], - [0.485300987958908, 0.527395009994507], - [0.257764995098114, 0.314490020275116], - [0.401223003864288, 0.455172002315521], - [0.429818987846375, 0.548614978790283], - [0.421351999044418, 0.533740997314453], - [0.276895999908447, 0.532056987285614], - [0.483370006084442, 0.499586999416351], - [0.33721199631691, 0.282882988452911], - [0.296391993761063, 0.293242990970612], - [0.169294998049736, 0.193813979625702], - [0.447580009698868, 0.302609980106354], - [0.392390012741089, 0.353887975215912], - [0.354490011930466, 0.696784019470215], - [0.067304998636246, 0.730105042457581], - [0.442739009857178, 0.572826027870178], - [0.457098007202148, 0.584792017936707], - [0.381974011659622, 0.694710969924927], - [0.392388999462128, 0.694203019142151], - [0.277076005935669, 0.271932005882263], - [0.422551989555359, 0.563233017921448], - [0.385919004678726, 0.281364023685455], - [0.383103013038635, 0.255840003490448], - [0.331431001424789, 0.119714021682739], - [0.229923993349075, 0.232002973556519], - [0.364500999450684, 0.189113974571228], - [0.229622006416321, 0.299540996551514], - [0.173287004232407, 0.278747975826263], - [0.472878992557526, 0.666198015213013], - [0.446828007698059, 0.668527007102966], - [0.422762006521225, 0.673889994621277], - [0.445307999849319, 0.580065965652466], - [0.388103008270264, 0.693961024284363], - [0.403039008378983, 0.706539988517761], - [0.403629004955292, 0.693953037261963], - [0.460041999816895, 0.557139039039612], - [0.431158006191254, 0.692366003990173], - [0.452181994915009, 0.692366003990173], - [0.475387006998062, 0.692366003990173], - [0.465828001499176, 0.779190003871918], - [0.472328990697861, 0.736225962638855], - [0.473087012767792, 0.717857003211975], - [0.473122000694275, 0.704625964164734], - [0.473033010959625, 0.695277988910675], - [0.427942007780075, 0.695277988910675], - [0.426479011774063, 0.703539967536926], - [0.423162013292313, 0.711845993995667], - [0.4183090031147, 0.720062971115112], - [0.390094995498657, 0.639572978019714], - [0.013953999616206, 0.560034036636353], - [0.499913990497589, 0.58014702796936], - [0.413199990987778, 0.69539999961853], - [0.409626007080078, 0.701822996139526], - [0.468080013990402, 0.601534962654114], - [0.422728985548019, 0.585985004901886], - [0.463079988956451, 0.593783974647522], - [0.37211999297142, 0.47341400384903], - [0.334562003612518, 0.496073007583618], - [0.411671012639999, 0.546965003013611], - [0.242175996303558, 0.14767599105835], - [0.290776997804642, 0.201445996761322], - [0.327338010072708, 0.256527006626129], - [0.399509996175766, 0.748921036720276], - [0.441727995872498, 0.261676013469696], - [0.429764986038208, 0.187834024429321], - [0.412198007106781, 0.108901023864746], - [0.288955003023148, 0.398952007293701], - [0.218936994671822, 0.435410976409912], - [0.41278201341629, 0.398970007896423], - [0.257135003805161, 0.355440020561218], - [0.427684992551804, 0.437960982322693], - [0.448339998722076, 0.536936044692993], - [0.178560003638268, 0.45755398273468], - [0.247308000922203, 0.457193970680237], - [0.286267012357712, 0.467674970626831], - [0.332827985286713, 0.460712015628815], - [0.368755996227264, 0.447206974029541], - [0.398963987827301, 0.432654976844788], - [0.476410001516342, 0.405806005001068], - [0.189241006970406, 0.523923993110657], - [0.228962004184723, 0.348950982093811], - [0.490725994110107, 0.562400996685028], - [0.404670000076294, 0.485132992267609], - [0.019469000399113, 0.401564002037048], - [0.426243007183075, 0.420431017875671], - [0.396993011236191, 0.548797011375427], - [0.266469985246658, 0.376977026462555], - [0.439121007919312, 0.51895797252655], - [0.032313998788595, 0.644356966018677], - [0.419054001569748, 0.387154996395111], - [0.462783008813858, 0.505746960639954], - [0.238978996872902, 0.779744982719421], - [0.198220998048782, 0.831938028335571], - [0.107550002634525, 0.540755033493042], - [0.183610007166862, 0.740257024765015], - [0.134409993886948, 0.333683013916016], - [0.385764002799988, 0.883153975009918], - [0.490967005491257, 0.579378008842468], - [0.382384985685349, 0.508572995662689], - [0.174399003386497, 0.397670984268188], - [0.318785011768341, 0.39623498916626], - [0.343364000320435, 0.400596976280212], - [0.396100014448166, 0.710216999053955], - [0.187885001301765, 0.588537991046906], - [0.430987000465393, 0.944064974784851], - [0.318993002176285, 0.898285031318665], - [0.266247987747192, 0.869701027870178], - [0.500023007392883, 0.190576016902924], - [0.499976992607117, 0.954452991485596], - [0.366169989109039, 0.398822009563446], - [0.393207013607025, 0.39553701877594], - [0.410373002290726, 0.391080021858215], - [0.194993004202843, 0.342101991176605], - [0.388664990663528, 0.362284004688263], - [0.365961998701096, 0.355970978736877], - [0.343364000320435, 0.355356991291046], - [0.318785011768341, 0.35834002494812], - [0.301414996385574, 0.363156020641327], - [0.058132998645306, 0.319076001644135], - [0.301414996385574, 0.387449026107788], - [0.499987989664078, 0.618434011936188], - [0.415838003158569, 0.624195992946625], - [0.445681989192963, 0.566076993942261], - [0.465844005346298, 0.620640993118286], - [0.49992299079895, 0.351523995399475], - [0.288718998432159, 0.819945991039276], - [0.335278987884521, 0.852819979190826], - [0.440512001514435, 0.902418971061707], - [0.128294005990028, 0.791940987110138], - [0.408771991729736, 0.373893976211548], - [0.455606997013092, 0.451801002025604], - [0.499877005815506, 0.908990025520325], - [0.375436991453171, 0.924192011356354], - [0.11421000212431, 0.615022003650665], - [0.448662012815475, 0.695277988910675], - [0.4480200111866, 0.704632043838501], - [0.447111994028091, 0.715808033943176], - [0.444831997156143, 0.730794012546539], - [0.430011987686157, 0.766808986663818], - [0.406787008047104, 0.685672998428345], - [0.400738000869751, 0.681069016456604], - [0.392399996519089, 0.677703022956848], - [0.367855995893478, 0.663918972015381], - [0.247923001646996, 0.601333022117615], - [0.452769994735718, 0.420849978923798], - [0.43639200925827, 0.359887003898621], - [0.416164010763168, 0.368713974952698], - [0.413385987281799, 0.692366003990173], - [0.228018000721931, 0.683571994304657], - [0.468268007040024, 0.352671027183533], - [0.411361992359161, 0.804327011108398], - [0.499989002943039, 0.469825029373169], - [0.479153990745544, 0.442654013633728], - [0.499974012374878, 0.439637005329132], - [0.432112008333206, 0.493588984012604], - [0.499886006116867, 0.866917014122009], - [0.49991300702095, 0.821729004383087], - [0.456548988819122, 0.819200992584229], - [0.344549000263214, 0.745438992977142], - [0.37890899181366, 0.574010014533997], - [0.374292999505997, 0.780184984207153], - [0.319687992334366, 0.570737957954407], - [0.357154995203018, 0.604269981384277], - [0.295284003019333, 0.621580958366394], - [0.447750002145767, 0.862477004528046], - [0.410986006259918, 0.508723020553589], - [0.31395098567009, 0.775308012962341], - [0.354128003120422, 0.812552988529205], - [0.324548006057739, 0.703992962837219], - [0.189096003770828, 0.646299958229065], - [0.279776990413666, 0.71465802192688], - [0.1338230073452, 0.682700991630554], - [0.336768001317978, 0.644733011722565], - [0.429883986711502, 0.466521978378296], - [0.455527991056442, 0.548622965812683], - [0.437114000320435, 0.558896005153656], - [0.467287987470627, 0.529924988746643], - [0.414712011814117, 0.335219979286194], - [0.37704598903656, 0.322777986526489], - [0.344107985496521, 0.320150971412659], - [0.312875986099243, 0.32233202457428], - [0.283526003360748, 0.333190023899078], - [0.241245999932289, 0.382785975933075], - [0.102986000478268, 0.468762993812561], - [0.267612010240555, 0.424560010433197], - [0.297879010438919, 0.433175981044769], - [0.333433985710144, 0.433878004550934], - [0.366427004337311, 0.426115989685059], - [0.396012008190155, 0.416696012020111], - [0.420121014118195, 0.41022801399231], - [0.007561000064015, 0.480777025222778], - [0.432949006557465, 0.569517970085144], - [0.458638995885849, 0.479089021682739], - [0.473466008901596, 0.545744001865387], - [0.476087987422943, 0.563830018043518], - [0.468472003936768, 0.555056989192963], - [0.433990985155106, 0.582361996173859], - [0.483518004417419, 0.562983989715576], - [0.482482999563217, 0.57784903049469], - [0.42645001411438, 0.389798998832703], - [0.438998997211456, 0.39649498462677], - [0.450067013502121, 0.400434017181396], - [0.289712011814117, 0.368252992630005], - [0.276670008897781, 0.363372981548309], - [0.517862021923065, 0.471948027610779], - [0.710287988185883, 0.380764007568359], - [0.526226997375488, 0.573909997940063], - [0.895093023777008, 0.254140973091125], - [0.634069979190826, 0.409575998783112], - [0.661242008209229, 0.41302502155304], - [0.688880026340485, 0.409460008144379], - [0.725341975688934, 0.389131009578705], - [0.606630027294159, 0.40370500087738], - [0.654766023159027, 0.344011008739471], - [0.629905998706818, 0.346076011657715], - [0.680678009986877, 0.347265005111694], - [0.702096998691559, 0.353591024875641], - [0.75221198797226, 0.410804986953735], - [0.602918028831482, 0.842862963676453], - [0.719901978969574, 0.375599980354309], - [0.893692970275879, 0.399959981441498], - [0.790081977844238, 0.391354024410248], - [0.643998026847839, 0.534487962722778], - [0.528249025344849, 0.65040397644043], - [0.525849997997284, 0.680191040039062], - [0.560214996337891, 0.657229006290436], - [0.585384011268616, 0.66654098033905], - [0.549625992774963, 0.680860996246338], - [0.57122802734375, 0.682691991329193], - [0.624852001667023, 0.72809898853302], - [0.513050019741058, 0.547281980514526], - [0.51509702205658, 0.527251958847046], - [0.742246985435486, 0.314507007598877], - [0.598631024360657, 0.454979002475739], - [0.570338010787964, 0.548575043678284], - [0.578631997108459, 0.533622980117798], - [0.723087012767792, 0.532054007053375], - [0.516445994377136, 0.499638974666595], - [0.662801027297974, 0.282917976379395], - [0.70362401008606, 0.293271005153656], - [0.830704987049103, 0.193813979625702], - [0.552385985851288, 0.302568018436432], - [0.607609987258911, 0.353887975215912], - [0.645429015159607, 0.696707010269165], - [0.932694971561432, 0.730105042457581], - [0.557260990142822, 0.572826027870178], - [0.542901992797852, 0.584792017936707], - [0.6180260181427, 0.694710969924927], - [0.607590973377228, 0.694203019142151], - [0.722943007946014, 0.271963000297546], - [0.577413976192474, 0.563166975975037], - [0.614082992076874, 0.281386971473694], - [0.616907000541687, 0.255886018276215], - [0.668509006500244, 0.119913995265961], - [0.770092010498047, 0.232020974159241], - [0.635536015033722, 0.189248979091644], - [0.77039098739624, 0.299556016921997], - [0.826722025871277, 0.278755009174347], - [0.527121007442474, 0.666198015213013], - [0.553171992301941, 0.668527007102966], - [0.577238023281097, 0.673889994621277], - [0.554691970348358, 0.580065965652466], - [0.611896991729736, 0.693961024284363], - [0.59696102142334, 0.706539988517761], - [0.596370995044708, 0.693953037261963], - [0.539958000183105, 0.557139039039612], - [0.568841993808746, 0.692366003990173], - [0.547818005084991, 0.692366003990173], - [0.52461302280426, 0.692366003990173], - [0.534089982509613, 0.779141008853912], - [0.527670979499817, 0.736225962638855], - [0.526912987232208, 0.717857003211975], - [0.526877999305725, 0.704625964164734], - [0.526966989040375, 0.695277988910675], - [0.572058022022247, 0.695277988910675], - [0.573521018028259, 0.703539967536926], - [0.57683801651001, 0.711845993995667], - [0.581691026687622, 0.720062971115112], - [0.609944999217987, 0.639909982681274], - [0.986046016216278, 0.560034036636353], - [0.5867999792099, 0.69539999961853], - [0.590372025966644, 0.701822996139526], - [0.531915009021759, 0.601536989212036], - [0.577268004417419, 0.585934996604919], - [0.536915004253387, 0.593786001205444], - [0.627542972564697, 0.473352015018463], - [0.665585994720459, 0.495950996875763], - [0.588353991508484, 0.546862006187439], - [0.757824003696442, 0.14767599105835], - [0.709249973297119, 0.201507985591888], - [0.672684013843536, 0.256581008434296], - [0.600408971309662, 0.74900496006012], - [0.55826598405838, 0.261672019958496], - [0.570303976535797, 0.187870979309082], - [0.588165998458862, 0.109044015407562], - [0.711045026779175, 0.398952007293701], - [0.781069993972778, 0.435405015945435], - [0.587247014045715, 0.398931980133057], - [0.742869973182678, 0.355445981025696], - [0.572156012058258, 0.437651991844177], - [0.55186802148819, 0.536570012569427], - [0.821442008018494, 0.457556009292603], - [0.752701997756958, 0.457181990146637], - [0.71375697851181, 0.467626988887787], - [0.66711300611496, 0.460672974586487], - [0.631101012229919, 0.447153985500336], - [0.6008620262146, 0.432473003864288], - [0.523481011390686, 0.405627012252808], - [0.810747981071472, 0.523926019668579], - [0.771045982837677, 0.348959028720856], - [0.509127020835876, 0.562718033790588], - [0.595292985439301, 0.485023975372314], - [0.980530977249146, 0.401564002037048], - [0.573499977588654, 0.420000016689301], - [0.602994978427887, 0.548687994480133], - [0.733529984951019, 0.376977026462555], - [0.560611009597778, 0.519016981124878], - [0.967685997486115, 0.644356966018677], - [0.580985009670258, 0.387160003185272], - [0.537728011608124, 0.505385041236877], - [0.760966002941132, 0.779752969741821], - [0.801778972148895, 0.831938028335571], - [0.892440974712372, 0.54076099395752], - [0.816350996494293, 0.740260004997253], - [0.865594983100891, 0.333687007427216], - [0.614073991775513, 0.883246004581451], - [0.508952975273132, 0.579437971115112], - [0.617941975593567, 0.508316040039062], - [0.825608015060425, 0.397674977779388], - [0.681214988231659, 0.39623498916626], - [0.656635999679565, 0.400596976280212], - [0.603900015354156, 0.710216999053955], - [0.81208598613739, 0.588539004325867], - [0.56801301240921, 0.944564998149872], - [0.681007981300354, 0.898285031318665], - [0.733752012252808, 0.869701027870178], - [0.633830010890961, 0.398822009563446], - [0.606792986392975, 0.39553701877594], - [0.589659988880157, 0.391062021255493], - [0.805015981197357, 0.342108011245728], - [0.611334979534149, 0.362284004688263], - [0.634037971496582, 0.355970978736877], - [0.656635999679565, 0.355356991291046], - [0.681214988231659, 0.35834002494812], - [0.698584973812103, 0.363156020641327], - [0.941866993904114, 0.319076001644135], - [0.698584973812103, 0.387449026107788], - [0.584177017211914, 0.624107003211975], - [0.554318010807037, 0.566076993942261], - [0.534153997898102, 0.62064003944397], - [0.711217999458313, 0.819975018501282], - [0.664629995822906, 0.852871000766754], - [0.559099972248077, 0.902631998062134], - [0.871706008911133, 0.791940987110138], - [0.591234028339386, 0.373893976211548], - [0.544341027736664, 0.451583981513977], - [0.624562978744507, 0.924192011356354], - [0.88577002286911, 0.615028977394104], - [0.551338016986847, 0.695277988910675], - [0.551980018615723, 0.704632043838501], - [0.552887976169586, 0.715808033943176], - [0.555167973041534, 0.730794012546539], - [0.569944024085999, 0.767035007476807], - [0.593203008174896, 0.685675978660583], - [0.599261999130249, 0.681069016456604], - [0.607599973678589, 0.677703022956848], - [0.631937980651855, 0.663500010967255], - [0.752032995223999, 0.601315021514893], - [0.547226011753082, 0.420395016670227], - [0.563543975353241, 0.359827995300293], - [0.583841025829315, 0.368713974952698], - [0.586614012718201, 0.692366003990173], - [0.771915018558502, 0.683578014373779], - [0.531597018241882, 0.352482974529266], - [0.588370978832245, 0.804440975189209], - [0.52079701423645, 0.442565023899078], - [0.567984998226166, 0.493479013442993], - [0.543282985687256, 0.819254994392395], - [0.655317008495331, 0.745514988899231], - [0.621008992195129, 0.574018001556396], - [0.625559985637665, 0.78031200170517], - [0.680198013782501, 0.570719003677368], - [0.64276397228241, 0.604337990283966], - [0.704662978649139, 0.621529996395111], - [0.552012026309967, 0.862591981887817], - [0.589071989059448, 0.508637011051178], - [0.685944974422455, 0.775357007980347], - [0.645735025405884, 0.812640011310577], - [0.675342977046967, 0.703978002071381], - [0.810858011245728, 0.646304965019226], - [0.72012197971344, 0.714666962623596], - [0.866151988506317, 0.682704985141754], - [0.663187026977539, 0.644596993923187], - [0.570082008838654, 0.466325998306274], - [0.544561982154846, 0.548375964164734], - [0.562758982181549, 0.558784961700439], - [0.531987011432648, 0.530140042304993], - [0.585271000862122, 0.335177004337311], - [0.622952997684479, 0.32277899980545], - [0.655896008014679, 0.320163011550903], - [0.687132000923157, 0.322345972061157], - [0.716481983661652, 0.333200991153717], - [0.758756995201111, 0.382786989212036], - [0.897013008594513, 0.468769013881683], - [0.732392013072968, 0.424547016620636], - [0.70211398601532, 0.433162987232208], - [0.66652500629425, 0.433866024017334], - [0.633504986763, 0.426087975502014], - [0.603875994682312, 0.416586995124817], - [0.579657971858978, 0.409945011138916], - [0.992439985275269, 0.480777025222778], - [0.567192018032074, 0.569419980049133], - [0.54136598110199, 0.478899002075195], - [0.526564002037048, 0.546118021011353], - [0.523913025856018, 0.563830018043518], - [0.531529009342194, 0.555056989192963], - [0.566035985946655, 0.582329034805298], - [0.51631098985672, 0.563053965568542], - [0.5174720287323, 0.577877044677734], - [0.573594987392426, 0.389806985855103], - [0.560697972774506, 0.395331978797913], - [0.549755990505219, 0.399751007556915], - [0.710287988185883, 0.368252992630005], - [0.723330020904541, 0.363372981548309] -]; -var TRI468 = [ - 127, - 34, - 139, - 11, - 0, - 37, - 232, - 231, - 120, - 72, - 37, - 39, - 128, - 121, - 47, - 232, - 121, - 128, - 104, - 69, - 67, - 175, - 171, - 148, - 157, - 154, - 155, - 118, - 50, - 101, - 73, - 39, - 40, - 9, - 151, - 108, - 48, - 115, - 131, - 194, - 204, - 211, - 74, - 40, - 185, - 80, - 42, - 183, - 40, - 92, - 186, - 230, - 229, - 118, - 202, - 212, - 214, - 83, - 18, - 17, - 76, - 61, - 146, - 160, - 29, - 30, - 56, - 157, - 173, - 106, - 204, - 194, - 135, - 214, - 192, - 203, - 165, - 98, - 21, - 71, - 68, - 51, - 45, - 4, - 144, - 24, - 23, - 77, - 146, - 91, - 205, - 50, - 187, - 201, - 200, - 18, - 91, - 106, - 182, - 90, - 91, - 181, - 85, - 84, - 17, - 206, - 203, - 36, - 148, - 171, - 140, - 92, - 40, - 39, - 193, - 189, - 244, - 159, - 158, - 28, - 247, - 246, - 161, - 236, - 3, - 196, - 54, - 68, - 104, - 193, - 168, - 8, - 117, - 228, - 31, - 189, - 193, - 55, - 98, - 97, - 99, - 126, - 47, - 100, - 166, - 79, - 218, - 155, - 154, - 26, - 209, - 49, - 131, - 135, - 136, - 150, - 47, - 126, - 217, - 223, - 52, - 53, - 45, - 51, - 134, - 211, - 170, - 140, - 67, - 69, - 108, - 43, - 106, - 91, - 230, - 119, - 120, - 226, - 130, - 247, - 63, - 53, - 52, - 238, - 20, - 242, - 46, - 70, - 156, - 78, - 62, - 96, - 46, - 53, - 63, - 143, - 34, - 227, - 173, - 155, - 133, - 123, - 117, - 111, - 44, - 125, - 19, - 236, - 134, - 51, - 216, - 206, - 205, - 154, - 153, - 22, - 39, - 37, - 167, - 200, - 201, - 208, - 36, - 142, - 100, - 57, - 212, - 202, - 20, - 60, - 99, - 28, - 158, - 157, - 35, - 226, - 113, - 160, - 159, - 27, - 204, - 202, - 210, - 113, - 225, - 46, - 43, - 202, - 204, - 62, - 76, - 77, - 137, - 123, - 116, - 41, - 38, - 72, - 203, - 129, - 142, - 64, - 98, - 240, - 49, - 102, - 64, - 41, - 73, - 74, - 212, - 216, - 207, - 42, - 74, - 184, - 169, - 170, - 211, - 170, - 149, - 176, - 105, - 66, - 69, - 122, - 6, - 168, - 123, - 147, - 187, - 96, - 77, - 90, - 65, - 55, - 107, - 89, - 90, - 180, - 101, - 100, - 120, - 63, - 105, - 104, - 93, - 137, - 227, - 15, - 86, - 85, - 129, - 102, - 49, - 14, - 87, - 86, - 55, - 8, - 9, - 100, - 47, - 121, - 145, - 23, - 22, - 88, - 89, - 179, - 6, - 122, - 196, - 88, - 95, - 96, - 138, - 172, - 136, - 215, - 58, - 172, - 115, - 48, - 219, - 42, - 80, - 81, - 195, - 3, - 51, - 43, - 146, - 61, - 171, - 175, - 199, - 81, - 82, - 38, - 53, - 46, - 225, - 144, - 163, - 110, - 246, - 33, - 7, - 52, - 65, - 66, - 229, - 228, - 117, - 34, - 127, - 234, - 107, - 108, - 69, - 109, - 108, - 151, - 48, - 64, - 235, - 62, - 78, - 191, - 129, - 209, - 126, - 111, - 35, - 143, - 163, - 161, - 246, - 117, - 123, - 50, - 222, - 65, - 52, - 19, - 125, - 141, - 221, - 55, - 65, - 3, - 195, - 197, - 25, - 7, - 33, - 220, - 237, - 44, - 70, - 71, - 139, - 122, - 193, - 245, - 247, - 130, - 33, - 71, - 21, - 162, - 153, - 158, - 159, - 170, - 169, - 150, - 188, - 174, - 196, - 216, - 186, - 92, - 144, - 160, - 161, - 2, - 97, - 167, - 141, - 125, - 241, - 164, - 167, - 37, - 72, - 38, - 12, - 145, - 159, - 160, - 38, - 82, - 13, - 63, - 68, - 71, - 226, - 35, - 111, - 158, - 153, - 154, - 101, - 50, - 205, - 206, - 92, - 165, - 209, - 198, - 217, - 165, - 167, - 97, - 220, - 115, - 218, - 133, - 112, - 243, - 239, - 238, - 241, - 214, - 135, - 169, - 190, - 173, - 133, - 171, - 208, - 32, - 125, - 44, - 237, - 86, - 87, - 178, - 85, - 86, - 179, - 84, - 85, - 180, - 83, - 84, - 181, - 201, - 83, - 182, - 137, - 93, - 132, - 76, - 62, - 183, - 61, - 76, - 184, - 57, - 61, - 185, - 212, - 57, - 186, - 214, - 207, - 187, - 34, - 143, - 156, - 79, - 239, - 237, - 123, - 137, - 177, - 44, - 1, - 4, - 201, - 194, - 32, - 64, - 102, - 129, - 213, - 215, - 138, - 59, - 166, - 219, - 242, - 99, - 97, - 2, - 94, - 141, - 75, - 59, - 235, - 24, - 110, - 228, - 25, - 130, - 226, - 23, - 24, - 229, - 22, - 23, - 230, - 26, - 22, - 231, - 112, - 26, - 232, - 189, - 190, - 243, - 221, - 56, - 190, - 28, - 56, - 221, - 27, - 28, - 222, - 29, - 27, - 223, - 30, - 29, - 224, - 247, - 30, - 225, - 238, - 79, - 20, - 166, - 59, - 75, - 60, - 75, - 240, - 147, - 177, - 215, - 20, - 79, - 166, - 187, - 147, - 213, - 112, - 233, - 244, - 233, - 128, - 245, - 128, - 114, - 188, - 114, - 217, - 174, - 131, - 115, - 220, - 217, - 198, - 236, - 198, - 131, - 134, - 177, - 132, - 58, - 143, - 35, - 124, - 110, - 163, - 7, - 228, - 110, - 25, - 356, - 389, - 368, - 11, - 302, - 267, - 452, - 350, - 349, - 302, - 303, - 269, - 357, - 343, - 277, - 452, - 453, - 357, - 333, - 332, - 297, - 175, - 152, - 377, - 384, - 398, - 382, - 347, - 348, - 330, - 303, - 304, - 270, - 9, - 336, - 337, - 278, - 279, - 360, - 418, - 262, - 431, - 304, - 408, - 409, - 310, - 415, - 407, - 270, - 409, - 410, - 450, - 348, - 347, - 422, - 430, - 434, - 313, - 314, - 17, - 306, - 307, - 375, - 387, - 388, - 260, - 286, - 414, - 398, - 335, - 406, - 418, - 364, - 367, - 416, - 423, - 358, - 327, - 251, - 284, - 298, - 281, - 5, - 4, - 373, - 374, - 253, - 307, - 320, - 321, - 425, - 427, - 411, - 421, - 313, - 18, - 321, - 405, - 406, - 320, - 404, - 405, - 315, - 16, - 17, - 426, - 425, - 266, - 377, - 400, - 369, - 322, - 391, - 269, - 417, - 465, - 464, - 386, - 257, - 258, - 466, - 260, - 388, - 456, - 399, - 419, - 284, - 332, - 333, - 417, - 285, - 8, - 346, - 340, - 261, - 413, - 441, - 285, - 327, - 460, - 328, - 355, - 371, - 329, - 392, - 439, - 438, - 382, - 341, - 256, - 429, - 420, - 360, - 364, - 394, - 379, - 277, - 343, - 437, - 443, - 444, - 283, - 275, - 440, - 363, - 431, - 262, - 369, - 297, - 338, - 337, - 273, - 375, - 321, - 450, - 451, - 349, - 446, - 342, - 467, - 293, - 334, - 282, - 458, - 461, - 462, - 276, - 353, - 383, - 308, - 324, - 325, - 276, - 300, - 293, - 372, - 345, - 447, - 382, - 398, - 362, - 352, - 345, - 340, - 274, - 1, - 19, - 456, - 248, - 281, - 436, - 427, - 425, - 381, - 256, - 252, - 269, - 391, - 393, - 200, - 199, - 428, - 266, - 330, - 329, - 287, - 273, - 422, - 250, - 462, - 328, - 258, - 286, - 384, - 265, - 353, - 342, - 387, - 259, - 257, - 424, - 431, - 430, - 342, - 353, - 276, - 273, - 335, - 424, - 292, - 325, - 307, - 366, - 447, - 345, - 271, - 303, - 302, - 423, - 266, - 371, - 294, - 455, - 460, - 279, - 278, - 294, - 271, - 272, - 304, - 432, - 434, - 427, - 272, - 407, - 408, - 394, - 430, - 431, - 395, - 369, - 400, - 334, - 333, - 299, - 351, - 417, - 168, - 352, - 280, - 411, - 325, - 319, - 320, - 295, - 296, - 336, - 319, - 403, - 404, - 330, - 348, - 349, - 293, - 298, - 333, - 323, - 454, - 447, - 15, - 16, - 315, - 358, - 429, - 279, - 14, - 15, - 316, - 285, - 336, - 9, - 329, - 349, - 350, - 374, - 380, - 252, - 318, - 402, - 403, - 6, - 197, - 419, - 318, - 319, - 325, - 367, - 364, - 365, - 435, - 367, - 397, - 344, - 438, - 439, - 272, - 271, - 311, - 195, - 5, - 281, - 273, - 287, - 291, - 396, - 428, - 199, - 311, - 271, - 268, - 283, - 444, - 445, - 373, - 254, - 339, - 263, - 466, - 249, - 282, - 334, - 296, - 449, - 347, - 346, - 264, - 447, - 454, - 336, - 296, - 299, - 338, - 10, - 151, - 278, - 439, - 455, - 292, - 407, - 415, - 358, - 371, - 355, - 340, - 345, - 372, - 390, - 249, - 466, - 346, - 347, - 280, - 442, - 443, - 282, - 19, - 94, - 370, - 441, - 442, - 295, - 248, - 419, - 197, - 263, - 255, - 359, - 440, - 275, - 274, - 300, - 383, - 368, - 351, - 412, - 465, - 263, - 467, - 466, - 301, - 368, - 389, - 380, - 374, - 386, - 395, - 378, - 379, - 412, - 351, - 419, - 436, - 426, - 322, - 373, - 390, - 388, - 2, - 164, - 393, - 370, - 462, - 461, - 164, - 0, - 267, - 302, - 11, - 12, - 374, - 373, - 387, - 268, - 12, - 13, - 293, - 300, - 301, - 446, - 261, - 340, - 385, - 384, - 381, - 330, - 266, - 425, - 426, - 423, - 391, - 429, - 355, - 437, - 391, - 327, - 326, - 440, - 457, - 438, - 341, - 382, - 362, - 459, - 457, - 461, - 434, - 430, - 394, - 414, - 463, - 362, - 396, - 369, - 262, - 354, - 461, - 457, - 316, - 403, - 402, - 315, - 404, - 403, - 314, - 405, - 404, - 313, - 406, - 405, - 421, - 418, - 406, - 366, - 401, - 361, - 306, - 408, - 407, - 291, - 409, - 408, - 287, - 410, - 409, - 432, - 436, - 410, - 434, - 416, - 411, - 264, - 368, - 383, - 309, - 438, - 457, - 352, - 376, - 401, - 274, - 275, - 4, - 421, - 428, - 262, - 294, - 327, - 358, - 433, - 416, - 367, - 289, - 455, - 439, - 462, - 370, - 326, - 2, - 326, - 370, - 305, - 460, - 455, - 254, - 449, - 448, - 255, - 261, - 446, - 253, - 450, - 449, - 252, - 451, - 450, - 256, - 452, - 451, - 341, - 453, - 452, - 413, - 464, - 463, - 441, - 413, - 414, - 258, - 442, - 441, - 257, - 443, - 442, - 259, - 444, - 443, - 260, - 445, - 444, - 467, - 342, - 445, - 459, - 458, - 250, - 289, - 392, - 290, - 290, - 328, - 460, - 376, - 433, - 435, - 250, - 290, - 392, - 411, - 416, - 433, - 341, - 463, - 464, - 453, - 464, - 465, - 357, - 465, - 412, - 343, - 412, - 399, - 360, - 363, - 440, - 437, - 399, - 456, - 420, - 456, - 363, - 401, - 435, - 288, - 372, - 383, - 353, - 339, - 255, - 249, - 448, - 261, - 255, - 133, - 243, - 190, - 133, - 155, - 112, - 33, - 246, - 247, - 33, - 130, - 25, - 398, - 384, - 286, - 362, - 398, - 414, - 362, - 463, - 341, - 263, - 359, - 467, - 263, - 249, - 255, - 466, - 467, - 260, - 75, - 60, - 166, - 238, - 239, - 79, - 162, - 127, - 139, - 72, - 11, - 37, - 121, - 232, - 120, - 73, - 72, - 39, - 114, - 128, - 47, - 233, - 232, - 128, - 103, - 104, - 67, - 152, - 175, - 148, - 173, - 157, - 155, - 119, - 118, - 101, - 74, - 73, - 40, - 107, - 9, - 108, - 49, - 48, - 131, - 32, - 194, - 211, - 184, - 74, - 185, - 191, - 80, - 183, - 185, - 40, - 186, - 119, - 230, - 118, - 210, - 202, - 214, - 84, - 83, - 17, - 77, - 76, - 146, - 161, - 160, - 30, - 190, - 56, - 173, - 182, - 106, - 194, - 138, - 135, - 192, - 129, - 203, - 98, - 54, - 21, - 68, - 5, - 51, - 4, - 145, - 144, - 23, - 90, - 77, - 91, - 207, - 205, - 187, - 83, - 201, - 18, - 181, - 91, - 182, - 180, - 90, - 181, - 16, - 85, - 17, - 205, - 206, - 36, - 176, - 148, - 140, - 165, - 92, - 39, - 245, - 193, - 244, - 27, - 159, - 28, - 30, - 247, - 161, - 174, - 236, - 196, - 103, - 54, - 104, - 55, - 193, - 8, - 111, - 117, - 31, - 221, - 189, - 55, - 240, - 98, - 99, - 142, - 126, - 100, - 219, - 166, - 218, - 112, - 155, - 26, - 198, - 209, - 131, - 169, - 135, - 150, - 114, - 47, - 217, - 224, - 223, - 53, - 220, - 45, - 134, - 32, - 211, - 140, - 109, - 67, - 108, - 146, - 43, - 91, - 231, - 230, - 120, - 113, - 226, - 247, - 105, - 63, - 52, - 241, - 238, - 242, - 124, - 46, - 156, - 95, - 78, - 96, - 70, - 46, - 63, - 116, - 143, - 227, - 116, - 123, - 111, - 1, - 44, - 19, - 3, - 236, - 51, - 207, - 216, - 205, - 26, - 154, - 22, - 165, - 39, - 167, - 199, - 200, - 208, - 101, - 36, - 100, - 43, - 57, - 202, - 242, - 20, - 99, - 56, - 28, - 157, - 124, - 35, - 113, - 29, - 160, - 27, - 211, - 204, - 210, - 124, - 113, - 46, - 106, - 43, - 204, - 96, - 62, - 77, - 227, - 137, - 116, - 73, - 41, - 72, - 36, - 203, - 142, - 235, - 64, - 240, - 48, - 49, - 64, - 42, - 41, - 74, - 214, - 212, - 207, - 183, - 42, - 184, - 210, - 169, - 211, - 140, - 170, - 176, - 104, - 105, - 69, - 193, - 122, - 168, - 50, - 123, - 187, - 89, - 96, - 90, - 66, - 65, - 107, - 179, - 89, - 180, - 119, - 101, - 120, - 68, - 63, - 104, - 234, - 93, - 227, - 16, - 15, - 85, - 209, - 129, - 49, - 15, - 14, - 86, - 107, - 55, - 9, - 120, - 100, - 121, - 153, - 145, - 22, - 178, - 88, - 179, - 197, - 6, - 196, - 89, - 88, - 96, - 135, - 138, - 136, - 138, - 215, - 172, - 218, - 115, - 219, - 41, - 42, - 81, - 5, - 195, - 51, - 57, - 43, - 61, - 208, - 171, - 199, - 41, - 81, - 38, - 224, - 53, - 225, - 24, - 144, - 110, - 105, - 52, - 66, - 118, - 229, - 117, - 227, - 34, - 234, - 66, - 107, - 69, - 10, - 109, - 151, - 219, - 48, - 235, - 183, - 62, - 191, - 142, - 129, - 126, - 116, - 111, - 143, - 7, - 163, - 246, - 118, - 117, - 50, - 223, - 222, - 52, - 94, - 19, - 141, - 222, - 221, - 65, - 196, - 3, - 197, - 45, - 220, - 44, - 156, - 70, - 139, - 188, - 122, - 245, - 139, - 71, - 162, - 145, - 153, - 159, - 149, - 170, - 150, - 122, - 188, - 196, - 206, - 216, - 92, - 163, - 144, - 161, - 164, - 2, - 167, - 242, - 141, - 241, - 0, - 164, - 37, - 11, - 72, - 12, - 144, - 145, - 160, - 12, - 38, - 13, - 70, - 63, - 71, - 31, - 226, - 111, - 157, - 158, - 154, - 36, - 101, - 205, - 203, - 206, - 165, - 126, - 209, - 217, - 98, - 165, - 97, - 237, - 220, - 218, - 237, - 239, - 241, - 210, - 214, - 169, - 140, - 171, - 32, - 241, - 125, - 237, - 179, - 86, - 178, - 180, - 85, - 179, - 181, - 84, - 180, - 182, - 83, - 181, - 194, - 201, - 182, - 177, - 137, - 132, - 184, - 76, - 183, - 185, - 61, - 184, - 186, - 57, - 185, - 216, - 212, - 186, - 192, - 214, - 187, - 139, - 34, - 156, - 218, - 79, - 237, - 147, - 123, - 177, - 45, - 44, - 4, - 208, - 201, - 32, - 98, - 64, - 129, - 192, - 213, - 138, - 235, - 59, - 219, - 141, - 242, - 97, - 97, - 2, - 141, - 240, - 75, - 235, - 229, - 24, - 228, - 31, - 25, - 226, - 230, - 23, - 229, - 231, - 22, - 230, - 232, - 26, - 231, - 233, - 112, - 232, - 244, - 189, - 243, - 189, - 221, - 190, - 222, - 28, - 221, - 223, - 27, - 222, - 224, - 29, - 223, - 225, - 30, - 224, - 113, - 247, - 225, - 99, - 60, - 240, - 213, - 147, - 215, - 60, - 20, - 166, - 192, - 187, - 213, - 243, - 112, - 244, - 244, - 233, - 245, - 245, - 128, - 188, - 188, - 114, - 174, - 134, - 131, - 220, - 174, - 217, - 236, - 236, - 198, - 134, - 215, - 177, - 58, - 156, - 143, - 124, - 25, - 110, - 7, - 31, - 228, - 25, - 264, - 356, - 368, - 0, - 11, - 267, - 451, - 452, - 349, - 267, - 302, - 269, - 350, - 357, - 277, - 350, - 452, - 357, - 299, - 333, - 297, - 396, - 175, - 377, - 381, - 384, - 382, - 280, - 347, - 330, - 269, - 303, - 270, - 151, - 9, - 337, - 344, - 278, - 360, - 424, - 418, - 431, - 270, - 304, - 409, - 272, - 310, - 407, - 322, - 270, - 410, - 449, - 450, - 347, - 432, - 422, - 434, - 18, - 313, - 17, - 291, - 306, - 375, - 259, - 387, - 260, - 424, - 335, - 418, - 434, - 364, - 416, - 391, - 423, - 327, - 301, - 251, - 298, - 275, - 281, - 4, - 254, - 373, - 253, - 375, - 307, - 321, - 280, - 425, - 411, - 200, - 421, - 18, - 335, - 321, - 406, - 321, - 320, - 405, - 314, - 315, - 17, - 423, - 426, - 266, - 396, - 377, - 369, - 270, - 322, - 269, - 413, - 417, - 464, - 385, - 386, - 258, - 248, - 456, - 419, - 298, - 284, - 333, - 168, - 417, - 8, - 448, - 346, - 261, - 417, - 413, - 285, - 326, - 327, - 328, - 277, - 355, - 329, - 309, - 392, - 438, - 381, - 382, - 256, - 279, - 429, - 360, - 365, - 364, - 379, - 355, - 277, - 437, - 282, - 443, - 283, - 281, - 275, - 363, - 395, - 431, - 369, - 299, - 297, - 337, - 335, - 273, - 321, - 348, - 450, - 349, - 359, - 446, - 467, - 283, - 293, - 282, - 250, - 458, - 462, - 300, - 276, - 383, - 292, - 308, - 325, - 283, - 276, - 293, - 264, - 372, - 447, - 346, - 352, - 340, - 354, - 274, - 19, - 363, - 456, - 281, - 426, - 436, - 425, - 380, - 381, - 252, - 267, - 269, - 393, - 421, - 200, - 428, - 371, - 266, - 329, - 432, - 287, - 422, - 290, - 250, - 328, - 385, - 258, - 384, - 446, - 265, - 342, - 386, - 387, - 257, - 422, - 424, - 430, - 445, - 342, - 276, - 422, - 273, - 424, - 306, - 292, - 307, - 352, - 366, - 345, - 268, - 271, - 302, - 358, - 423, - 371, - 327, - 294, - 460, - 331, - 279, - 294, - 303, - 271, - 304, - 436, - 432, - 427, - 304, - 272, - 408, - 395, - 394, - 431, - 378, - 395, - 400, - 296, - 334, - 299, - 6, - 351, - 168, - 376, - 352, - 411, - 307, - 325, - 320, - 285, - 295, - 336, - 320, - 319, - 404, - 329, - 330, - 349, - 334, - 293, - 333, - 366, - 323, - 447, - 316, - 15, - 315, - 331, - 358, - 279, - 317, - 14, - 316, - 8, - 285, - 9, - 277, - 329, - 350, - 253, - 374, - 252, - 319, - 318, - 403, - 351, - 6, - 419, - 324, - 318, - 325, - 397, - 367, - 365, - 288, - 435, - 397, - 278, - 344, - 439, - 310, - 272, - 311, - 248, - 195, - 281, - 375, - 273, - 291, - 175, - 396, - 199, - 312, - 311, - 268, - 276, - 283, - 445, - 390, - 373, - 339, - 295, - 282, - 296, - 448, - 449, - 346, - 356, - 264, - 454, - 337, - 336, - 299, - 337, - 338, - 151, - 294, - 278, - 455, - 308, - 292, - 415, - 429, - 358, - 355, - 265, - 340, - 372, - 388, - 390, - 466, - 352, - 346, - 280, - 295, - 442, - 282, - 354, - 19, - 370, - 285, - 441, - 295, - 195, - 248, - 197, - 457, - 440, - 274, - 301, - 300, - 368, - 417, - 351, - 465, - 251, - 301, - 389, - 385, - 380, - 386, - 394, - 395, - 379, - 399, - 412, - 419, - 410, - 436, - 322, - 387, - 373, - 388, - 326, - 2, - 393, - 354, - 370, - 461, - 393, - 164, - 267, - 268, - 302, - 12, - 386, - 374, - 387, - 312, - 268, - 13, - 298, - 293, - 301, - 265, - 446, - 340, - 380, - 385, - 381, - 280, - 330, - 425, - 322, - 426, - 391, - 420, - 429, - 437, - 393, - 391, - 326, - 344, - 440, - 438, - 458, - 459, - 461, - 364, - 434, - 394, - 428, - 396, - 262, - 274, - 354, - 457, - 317, - 316, - 402, - 316, - 315, - 403, - 315, - 314, - 404, - 314, - 313, - 405, - 313, - 421, - 406, - 323, - 366, - 361, - 292, - 306, - 407, - 306, - 291, - 408, - 291, - 287, - 409, - 287, - 432, - 410, - 427, - 434, - 411, - 372, - 264, - 383, - 459, - 309, - 457, - 366, - 352, - 401, - 1, - 274, - 4, - 418, - 421, - 262, - 331, - 294, - 358, - 435, - 433, - 367, - 392, - 289, - 439, - 328, - 462, - 326, - 94, - 2, - 370, - 289, - 305, - 455, - 339, - 254, - 448, - 359, - 255, - 446, - 254, - 253, - 449, - 253, - 252, - 450, - 252, - 256, - 451, - 256, - 341, - 452, - 414, - 413, - 463, - 286, - 441, - 414, - 286, - 258, - 441, - 258, - 257, - 442, - 257, - 259, - 443, - 259, - 260, - 444, - 260, - 467, - 445, - 309, - 459, - 250, - 305, - 289, - 290, - 305, - 290, - 460, - 401, - 376, - 435, - 309, - 250, - 392, - 376, - 411, - 433, - 453, - 341, - 464, - 357, - 453, - 465, - 343, - 357, - 412, - 437, - 343, - 399, - 344, - 360, - 440, - 420, - 437, - 456, - 360, - 420, - 363, - 361, - 401, - 288, - 265, - 372, - 353, - 390, - 339, - 249, - 339, - 448, - 255 -]; -var VTX68 = [ - 127, - 234, - 132, - 58, - 172, - 150, - 149, - 148, - 152, - 377, - 378, - 379, - 397, - 288, - 361, - 454, - 356, - 70, - 63, - 105, - 66, - 107, - 336, - 296, - 334, - 293, - 300, - 168, - 6, - 195, - 4, - 98, - 97, - 2, - 326, - 327, - 33, - 160, - 158, - 133, - 153, - 144, - 362, - 385, - 387, - 263, - 373, - 380, - 57, - 40, - 37, - 0, - 267, - 270, - 287, - 321, - 314, - 17, - 84, - 91, - 78, - 81, - 13, - 311, - 308, - 402, - 14, - 178 -]; -var VTX33 = [33, 133, 362, 263, 1, 62, 308, 159, 145, 386, 374, 6, 102, 331, 2, 13, 14, 70, 105, 107, 336, 334, 300, 54, 10, 284, 50, 280, 234, 454, 58, 288, 152]; -var VTX7 = [33, 133, 362, 263, 1, 78, 308]; -var UV68 = VTX68.map((x) => UV468[x]); -var UV33 = VTX33.map((x) => UV468[x]); -var UV7 = VTX7.map((x) => UV468[x]); -function connectionsToIndices(connections) { - const indices = connections.map((connection) => connection[0]); - indices.push(connections[connections.length - 1][1]); - return indices; -} -var pairsLips = [ - [61, 146], - [146, 91], - [91, 181], - [181, 84], - [84, 17], - [17, 314], - [314, 405], - [405, 321], - [321, 375], - [375, 291], - [61, 185], - [185, 40], - [40, 39], - [39, 37], - [37, 0], - [0, 267], - [267, 269], - [269, 270], - [270, 409], - [409, 291], - [78, 95], - [95, 88], - [88, 178], - [178, 87], - [87, 14], - [14, 317], - [317, 402], - [402, 318], - [318, 324], - [324, 308], - [78, 191], - [191, 80], - [80, 81], - [81, 82], - [82, 13], - [13, 312], - [312, 311], - [311, 310], - [310, 415], - [415, 308] -]; -var pairsLeftEye = [[263, 249], [249, 390], [390, 373], [373, 374], [374, 380], [380, 381], [381, 382], [382, 362], [263, 466], [466, 388], [388, 387], [387, 386], [386, 385], [385, 384], [384, 398], [398, 362]]; -var pairsLeftEyebrow = [[276, 283], [283, 282], [282, 295], [295, 285], [300, 293], [293, 334], [334, 296], [296, 336]]; -var pairsLeftIris = [[474, 475], [475, 476], [476, 477], [477, 474]]; -var pairsRightEye = [[33, 7], [7, 163], [163, 144], [144, 145], [145, 153], [153, 154], [154, 155], [155, 133], [33, 246], [246, 161], [161, 160], [160, 159], [159, 158], [158, 157], [157, 173], [173, 133]]; -var pairsRightEyebrow = [[46, 53], [53, 52], [52, 65], [65, 55], [70, 63], [63, 105], [105, 66], [66, 107]]; -var pairsRightIris = [[469, 470], [470, 471], [471, 472], [472, 469]]; -var pairsFaceContour = [ - [10, 338], - [338, 297], - [297, 332], - [332, 284], - [284, 251], - [251, 389], - [389, 356], - [356, 454], - [454, 323], - [323, 361], - [361, 288], - [288, 397], - [397, 365], - [365, 379], - [379, 378], - [378, 400], - [400, 377], - [377, 152], - [152, 148], - [148, 176], - [176, 149], - [149, 150], - [150, 136], - [136, 172], - [172, 58], - [58, 132], - [132, 93], - [93, 234], - [234, 127], - [127, 162], - [162, 21], - [21, 54], - [54, 103], - [103, 67], - [67, 109], - [109, 10] -]; -var contourKeypoints = { - lips: connectionsToIndices(pairsLips), - leftEye: connectionsToIndices(pairsLeftEye), - leftEyebrow: connectionsToIndices(pairsLeftEyebrow), - leftIris: connectionsToIndices(pairsLeftIris), - rightEye: connectionsToIndices(pairsRightEye), - rightEyebrow: connectionsToIndices(pairsRightEyebrow), - rightIris: connectionsToIndices(pairsRightIris), - faceOval: connectionsToIndices(pairsFaceContour) -}; - -// src/face/constants.ts -var LIPS_CONNECTIONS = [ - [61, 146], - [146, 91], - [91, 181], - [181, 84], - [84, 17], - [17, 314], - [314, 405], - [405, 321], - [321, 375], - [375, 291], - [61, 185], - [185, 40], - [40, 39], - [39, 37], - [37, 0], - [0, 267], - [267, 269], - [269, 270], - [270, 409], - [409, 291], - [78, 95], - [95, 88], - [88, 178], - [178, 87], - [87, 14], - [14, 317], - [317, 402], - [402, 318], - [318, 324], - [324, 308], - [78, 191], - [191, 80], - [80, 81], - [81, 82], - [82, 13], - [13, 312], - [312, 311], - [311, 310], - [310, 415], - [415, 308] -]; -var LEFT_EYE_CONNECTIONS = [[263, 249], [249, 390], [390, 373], [373, 374], [374, 380], [380, 381], [381, 382], [382, 362], [263, 466], [466, 388], [388, 387], [387, 386], [386, 385], [385, 384], [384, 398], [398, 362]]; -var LEFT_EYEBROW_CONNECTIONS = [[276, 283], [283, 282], [282, 295], [295, 285], [300, 293], [293, 334], [334, 296], [296, 336]]; -var LEFT_IRIS_CONNECTIONS = [[474, 475], [475, 476], [476, 477], [477, 474]]; -var RIGHT_EYE_CONNECTIONS = [[33, 7], [7, 163], [163, 144], [144, 145], [145, 153], [153, 154], [154, 155], [155, 133], [33, 246], [246, 161], [161, 160], [160, 159], [159, 158], [158, 157], [157, 173], [173, 133]]; -var RIGHT_EYEBROW_CONNECTIONS = [[46, 53], [53, 52], [52, 65], [65, 55], [70, 63], [63, 105], [105, 66], [66, 107]]; -var RIGHT_IRIS_CONNECTIONS = [[469, 470], [470, 471], [471, 472], [472, 469]]; -var FACE_OVAL_CONNECTIONS = [ - [10, 338], - [338, 297], - [297, 332], - [332, 284], - [284, 251], - [251, 389], - [389, 356], - [356, 454], - [454, 323], - [323, 361], - [361, 288], - [288, 397], - [397, 365], - [365, 379], - [379, 378], - [378, 400], - [400, 377], - [377, 152], - [152, 148], - [148, 176], - [176, 149], - [149, 150], - [150, 136], - [136, 172], - [172, 58], - [58, 132], - [132, 93], - [93, 234], - [234, 127], - [127, 162], - [162, 21], - [21, 54], - [54, 103], - [103, 67], - [67, 109], - [109, 10] -]; -function connectionsToIndices2(connections) { - const indices = connections.map((connection) => connection[0]); - indices.push(connections[connections.length - 1][1]); - return indices; -} -var MEDIAPIPE_FACE_MESH_KEYPOINTS_BY_CONTOUR = { - lips: connectionsToIndices2(LIPS_CONNECTIONS), - leftEye: connectionsToIndices2(LEFT_EYE_CONNECTIONS), - leftEyebrow: connectionsToIndices2(LEFT_EYEBROW_CONNECTIONS), - leftIris: connectionsToIndices2(LEFT_IRIS_CONNECTIONS), - rightEye: connectionsToIndices2(RIGHT_EYE_CONNECTIONS), - rightEyebrow: connectionsToIndices2(RIGHT_EYEBROW_CONNECTIONS), - rightIris: connectionsToIndices2(RIGHT_IRIS_CONNECTIONS), - faceOval: connectionsToIndices2(FACE_OVAL_CONNECTIONS) -}; -var indexLabelPairs = Object.entries(MEDIAPIPE_FACE_MESH_KEYPOINTS_BY_CONTOUR).map(([label, indices]) => indices.map((index2) => [index2, label])).flat(); -var MEDIAPIPE_FACE_MESH_KEYPOINTS = new Map(indexLabelPairs); -var LANDMARKS_REFINEMENT_LIPS_CONFIG = [ - 61, - 146, - 91, - 181, - 84, - 17, - 314, - 405, - 321, - 375, - 291, - 185, - 40, - 39, - 37, - 0, - 267, - 269, - 270, - 409, - 78, - 95, - 88, - 178, - 87, - 14, - 317, - 402, - 318, - 324, - 308, - 191, - 80, - 81, - 82, - 13, - 312, - 311, - 310, - 415, - 76, - 77, - 90, - 180, - 85, - 16, - 315, - 404, - 320, - 307, - 306, - 184, - 74, - 73, - 72, - 11, - 302, - 303, - 304, - 408, - 62, - 96, - 89, - 179, - 86, - 15, - 316, - 403, - 319, - 325, - 292, - 183, - 42, - 41, - 38, - 12, - 268, - 271, - 272, - 407 -]; -var LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG = [ - 33, - 7, - 163, - 144, - 145, - 153, - 154, - 155, - 133, - 246, - 161, - 160, - 159, - 158, - 157, - 173, - 130, - 25, - 110, - 24, - 23, - 22, - 26, - 112, - 243, - 247, - 30, - 29, - 27, - 28, - 56, - 190, - 226, - 31, - 228, - 229, - 230, - 231, - 232, - 233, - 244, - 113, - 225, - 224, - 223, - 222, - 221, - 189, - 35, - 124, - 46, - 53, - 52, - 65, - 143, - 111, - 117, - 118, - 119, - 120, - 121, - 128, - 245, - 156, - 70, - 63, - 105, - 66, - 107, - 55, - 193 -]; -var LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG = [ - 263, - 249, - 390, - 373, - 374, - 380, - 381, - 382, - 362, - 466, - 388, - 387, - 386, - 385, - 384, - 398, - 359, - 255, - 339, - 254, - 253, - 252, - 256, - 341, - 463, - 467, - 260, - 259, - 257, - 258, - 286, - 414, - 446, - 261, - 448, - 449, - 450, - 451, - 452, - 453, - 464, - 342, - 445, - 444, - 443, - 442, - 441, - 413, - 265, - 353, - 276, - 283, - 282, - 295, - 372, - 340, - 346, - 347, - 348, - 349, - 350, - 357, - 465, - 383, - 300, - 293, - 334, - 296, - 336, - 285, - 417 -]; - -// src/draw/face.ts -var localOptions; -function drawLabels(f, ctx) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i; - if (!localOptions.drawLabels || ((_a = localOptions.faceLabels) == null ? void 0 : _a.length) === 0) - return; - let l = localOptions.faceLabels.slice(); - if (f.score) - l = replace(l, "[score]", 100 * f.score); - if (f.gender) - l = replace(l, "[gender]", f.gender); - if (f.genderScore) - l = replace(l, "[genderScore]", 100 * f.genderScore); - if (f.age) - l = replace(l, "[age]", f.age); - if (f.distance) - l = replace(l, "[distance]", 100 * f.distance); - if (f.real) - l = replace(l, "[real]", 100 * f.real); - if (f.live) - l = replace(l, "[live]", 100 * f.live); - if (f.emotion && f.emotion.length > 0) { - const emotion2 = f.emotion.map((a) => `${Math.trunc(100 * a.score)}% ${a.emotion}`); - if (emotion2.length > 3) - emotion2.length = 3; - l = replace(l, "[emotions]", emotion2.join(" ")); - } - if ((_c = (_b = f.rotation) == null ? void 0 : _b.angle) == null ? void 0 : _c.roll) - l = replace(l, "[roll]", rad2deg(f.rotation.angle.roll)); - if ((_e = (_d = f.rotation) == null ? void 0 : _d.angle) == null ? void 0 : _e.yaw) - l = replace(l, "[yaw]", rad2deg(f.rotation.angle.yaw)); - if ((_g = (_f = f.rotation) == null ? void 0 : _f.angle) == null ? void 0 : _g.pitch) - l = replace(l, "[pitch]", rad2deg(f.rotation.angle.pitch)); - if ((_i = (_h = f.rotation) == null ? void 0 : _h.gaze) == null ? void 0 : _i.bearing) - l = replace(l, "[gaze]", rad2deg(f.rotation.gaze.bearing)); - labels(ctx, l, f.box[0], f.box[1], localOptions); -} -function drawIrisElipse(f, ctx) { - var _a, _b, _c, _d; - if (((_a = f.annotations) == null ? void 0 : _a.leftEyeIris) && ((_b = f.annotations) == null ? void 0 : _b.leftEyeIris[0])) { - ctx.strokeStyle = localOptions.useDepth ? "rgba(255, 200, 255, 0.3)" : localOptions.color; - ctx.beginPath(); - const sizeX = Math.abs(f.annotations.leftEyeIris[3][0] - f.annotations.leftEyeIris[1][0]) / 2; - const sizeY = Math.abs(f.annotations.leftEyeIris[4][1] - f.annotations.leftEyeIris[2][1]) / 2; - ctx.ellipse(f.annotations.leftEyeIris[0][0], f.annotations.leftEyeIris[0][1], sizeX, sizeY, 0, 0, 2 * Math.PI); - ctx.stroke(); - if (localOptions.fillPolygons) { - ctx.fillStyle = localOptions.useDepth ? "rgba(255, 255, 200, 0.3)" : localOptions.color; - ctx.fill(); - } - } - if (((_c = f.annotations) == null ? void 0 : _c.rightEyeIris) && ((_d = f.annotations) == null ? void 0 : _d.rightEyeIris[0])) { - ctx.strokeStyle = localOptions.useDepth ? "rgba(255, 200, 255, 0.3)" : localOptions.color; - ctx.beginPath(); - const sizeX = Math.abs(f.annotations.rightEyeIris[3][0] - f.annotations.rightEyeIris[1][0]) / 2; - const sizeY = Math.abs(f.annotations.rightEyeIris[4][1] - f.annotations.rightEyeIris[2][1]) / 2; - ctx.ellipse(f.annotations.rightEyeIris[0][0], f.annotations.rightEyeIris[0][1], sizeX, sizeY, 0, 0, 2 * Math.PI); - ctx.stroke(); - if (localOptions.fillPolygons) { - ctx.fillStyle = localOptions.useDepth ? "rgba(255, 255, 200, 0.3)" : localOptions.color; - ctx.fill(); - } - } -} -function drawGazeSpheres(f, ctx) { - var _a; - if (localOptions.drawGaze && ((_a = f.rotation) == null ? void 0 : _a.angle) && typeof Path2D !== "undefined") { - ctx.strokeStyle = "pink"; - const valX = f.box[0] + f.box[2] / 2 - f.box[3] * rad2deg(f.rotation.angle.yaw) / 90; - const valY = f.box[1] + f.box[3] / 2 + f.box[2] * rad2deg(f.rotation.angle.pitch) / 90; - const pathV = new Path2D(` - M ${f.box[0] + f.box[2] / 2} ${f.box[1]} +`;var Kt=(e,t,n)=>{let o=new RegExp("\\b"+t+" \\w+ (\\w+)","ig");e.replace(o,(r,s)=>(n[s]=0,r))},Jt=class{constructor(t,n,o){k(this,"uniform",{});k(this,"attribute",{});k(this,"gl");k(this,"id");k(this,"compile",(t,n)=>{let o=this.gl.createShader(n);return o?(this.gl.shaderSource(o,t),this.gl.compileShader(o),this.gl.getShaderParameter(o,this.gl.COMPILE_STATUS)?o:(u(`filter: gl compile failed: ${this.gl.getShaderInfoLog(o)||"unknown"}`),null)):(u("filter: could not create shader"),null)});this.gl=t;let r=this.compile(n,this.gl.VERTEX_SHADER),s=this.compile(o,this.gl.FRAGMENT_SHADER);if(this.id=this.gl.createProgram(),!(!r||!s)){if(!this.id){u("filter: could not create webgl program");return}if(this.gl.attachShader(this.id,r),this.gl.attachShader(this.id,s),this.gl.linkProgram(this.id),!this.gl.getProgramParameter(this.id,this.gl.LINK_STATUS)){u(`filter: gl link failed: ${this.gl.getProgramInfoLog(this.id)||"unknown"}`);return}this.gl.useProgram(this.id),Kt(n,"attribute",this.attribute);for(let A in this.attribute)this.attribute[A]=this.gl.getAttribLocation(this.id,A);Kt(n,"uniform",this.uniform),Kt(o,"uniform",this.uniform);for(let A in this.uniform)this.uniform[A]=this.gl.getUniformLocation(this.id,A)}}};function W1(){let e=0,t=null,n=!1,o=-1,r=[null,null],s=[],A=null,a=null,l=te(100,100),c={},x={INTERMEDIATE:1},i=l.getContext("webgl");if(!i){u("filter: cannot get webgl context");return}this.gl=i;function y(T,m){if(!(T===l.width&&m===l.height)){if(l.width=T,l.height=m,!A){let h=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]);A=i.createBuffer(),i.bindBuffer(i.ARRAY_BUFFER,A),i.bufferData(i.ARRAY_BUFFER,h,i.STATIC_DRAW),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0)}i.viewport(0,0,l.width,l.height),r=[null,null]}}function d(T,m){let h=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,h);let S=i.createRenderbuffer();i.bindRenderbuffer(i.RENDERBUFFER,S);let P=i.createTexture();return i.bindTexture(i.TEXTURE_2D,P),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,T,m,0,i.RGBA,i.UNSIGNED_BYTE,null),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,P,0),i.bindTexture(i.TEXTURE_2D,null),i.bindFramebuffer(i.FRAMEBUFFER,null),{fbo:h,texture:P}}function p(T){return r[T]=r[T]||d(l.width,l.height),r[T]}function f(T=0){if(!a)return;let m=null,h=null,S=!1;e===0?m=t:m=p(o).texture||null,e++,n&&!(T&x.INTERMEDIATE)?(h=null,S=e%2===0):(o=(o+1)%2,h=p(o).fbo||null),i.bindTexture(i.TEXTURE_2D,m),i.bindFramebuffer(i.FRAMEBUFFER,h),i.uniform1f(a.uniform.flipY,S?-1:1),i.drawArrays(i.TRIANGLES,0,6)}function b(T){if(c[T])return a=c[T],i.useProgram((a?a.id:null)||null),a;if(a=new Jt(i,j1,T),!a)return u("filter: could not get webgl program"),null;let m=Float32Array.BYTES_PER_ELEMENT,h=4*m;return i.enableVertexAttribArray(a.attribute.pos),i.vertexAttribPointer(a.attribute.pos,2,i.FLOAT,!1,h,0*m),i.enableVertexAttribArray(a.attribute.uv),i.vertexAttribPointer(a.attribute.uv,2,i.FLOAT,!1,h,2*m),c[T]=a,a}let M={colorMatrix:T=>{let m=new Float32Array(T);m[4]/=255,m[9]/=255,m[14]/=255,m[19]/=255;let h=m[18]===1&&m[3]===0&&m[8]===0&&m[13]===0&&m[15]===0&&m[16]===0&&m[17]===0&&m[19]===0?I1:N1,S=b(h);!S||(i.uniform1fv(S.uniform.m,m),f())},brightness:T=>{let m=(T||0)+1;M.colorMatrix([m,0,0,0,0,0,m,0,0,0,0,0,m,0,0,0,0,0,1,0])},saturation:T=>{let m=(T||0)*2/3+1,h=(m-1)*-.5;M.colorMatrix([m,h,h,0,0,h,m,h,0,0,h,h,m,0,0,0,0,0,1,0])},desaturate:()=>{M.saturation(-1)},contrast:T=>{let m=(T||0)+1,h=-128*(m-1);M.colorMatrix([m,0,0,0,h,0,m,0,0,h,0,0,m,0,h,0,0,0,1,0])},negative:()=>{M.contrast(-2)},hue:T=>{T=(T||0)/180*Math.PI;let m=Math.cos(T),h=Math.sin(T),S=.213,P=.715,I=.072;M.colorMatrix([S+m*(1-S)+h*-S,P+m*-P+h*-P,I+m*-I+h*(1-I),0,0,S+m*-S+h*.143,P+m*(1-P)+h*.14,I+m*-I+h*-.283,0,0,S+m*-S+h*-(1-S),P+m*-P+h*P,I+m*(1-I)+h*I,0,0,0,0,0,1,0])},desaturateLuminance:()=>{M.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:()=>{M.colorMatrix([.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0])},brownie:()=>{M.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:()=>{M.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:()=>{M.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:()=>{M.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:()=>{M.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:()=>{M.colorMatrix([0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0])},convolution:T=>{let m=new Float32Array(T),h=1/l.width,S=1/l.height,P=b(C1);!P||(i.uniform1fv(P.uniform.m,m),i.uniform2f(P.uniform.px,h,S),f())},detectEdges:()=>{M.convolution.call(this,[0,1,0,1,-4,1,0,1,0])},sobelX:()=>{M.convolution.call(this,[-1,0,1,-2,0,2,-1,0,1])},sobelY:()=>{M.convolution.call(this,[-1,-2,-1,0,0,0,1,2,1])},sharpen:T=>{let m=T||1;M.convolution.call(this,[0,-1*m,0,-1*m,1+4*m,-1*m,0,-1*m,0])},emboss:T=>{let m=T||1;M.convolution.call(this,[-2*m,-1*m,0,-1*m,1,1*m,0,1*m,2*m])},blur:T=>{let m=T/7/l.width,h=T/7/l.height,S=b(L1);!S||(i.uniform2f(S.uniform.px,0,h),f(x.INTERMEDIATE),i.uniform2f(S.uniform.px,m,0),f())},pixelate:T=>{let m=T/l.width,h=T/l.height,S=b(O1);!S||(i.uniform2f(S.uniform.size,m,h),f())}};this.add=function(T){let m=Array.prototype.slice.call(arguments,1),h=M[T];s.push({func:h,args:m})},this.reset=function(){s=[]},this.get=function(){return s},this.apply=function(T){y(T.width,T.height),e=0,t||(t=i.createTexture()),i.bindTexture(i.TEXTURE_2D,t),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,T);for(let m=0;mx.data())),A=Math.max(s[0][0],s[1][0],s[2][0]),l=(A>1?255:1)/A,c;if(l>1){let x=[Y.sub(n[0],o[0]),Y.sub(n[1],o[1]),Y.sub(n[2],o[2])],i=[Y.sub(r[0],o[0]),Y.sub(r[1],o[1]),Y.sub(r[2],o[2])],y=[Y.mul(x[0],l),Y.mul(x[1],l),Y.mul(x[2],l)],d=Y.stack([y[0],y[1],y[2]],2);c=Y.reshape(d,[1,t.shape[0]||0,t.shape[1]||0,3]),Y.dispose([...x,...i,...y])}else c=Y.expandDims(t,0);return Y.dispose([...n,...o,...r,n,t,e]),c}var X2=3840,v0=null,R0=null,c2=null,e0,J0={inputSum:0,cacheDiff:1,sumMethod:0,inputTensor:void 0};function Qt(){J0.inputSum=0,J0.cacheDiff=1,J0.sumMethod=0,J0.inputTensor=void 0}function te(e,t){let n;if(R.browser)if(R.worker){if(typeof OffscreenCanvas=="undefined")throw new Error("canvas error: attempted to run in web worker but OffscreenCanvas is not supported");n=new OffscreenCanvas(e,t)}else{if(typeof document=="undefined")throw new Error("canvas error: attempted to run in browser but DOM is not defined");n=document.createElement("canvas"),n.width=e,n.height=t}else typeof R.Canvas!="undefined"?n=new R.Canvas(e,t):typeof globalThis.Canvas!="undefined"&&(n=new globalThis.Canvas(e,t));return n}function q2(e,t){let n=t||te(e.width,e.height);return n.getContext("2d").drawImage(e,0,0),n}async function U2(e,t,n=!0){var y,d,p;if(!e)return t.debug&&u("input error: input is missing"),{tensor:null,canvas:null};if(!(e instanceof N.Tensor)&&!(typeof Image!="undefined"&&e instanceof Image)&&!(typeof globalThis.Canvas!="undefined"&&e instanceof globalThis.Canvas)&&!(typeof ImageData!="undefined"&&e instanceof ImageData)&&!(typeof ImageBitmap!="undefined"&&e instanceof ImageBitmap)&&!(typeof HTMLImageElement!="undefined"&&e instanceof HTMLImageElement)&&!(typeof HTMLMediaElement!="undefined"&&e instanceof HTMLMediaElement)&&!(typeof HTMLVideoElement!="undefined"&&e instanceof HTMLVideoElement)&&!(typeof HTMLCanvasElement!="undefined"&&e instanceof HTMLCanvasElement)&&!(typeof OffscreenCanvas!="undefined"&&e instanceof OffscreenCanvas))throw new Error("input error: type not recognized");if(e instanceof N.Tensor){let f=null;if(e.isDisposedInternal)throw new Error("input error: attempted to use tensor but it is disposed");if(!e.shape)throw new Error("input error: attempted to use tensor without a shape");if(e.shape.length===3){if(e.shape[2]===3)f=N.expandDims(e,0);else if(e.shape[2]===4){let b=N.slice3d(e,[0,0,0],[-1,-1,3]);f=N.expandDims(b,0),N.dispose(b)}}else e.shape.length===4&&(e.shape[3]===3?f=N.clone(e):e.shape[3]===4&&(f=N.slice4d(e,[0,0,0,0],[-1,-1,-1,3])));if(f==null||f.shape.length!==4||f.shape[0]!==1||f.shape[3]!==3)throw new Error(`input error: attempted to use tensor with unrecognized shape: ${e.shape.toString()}`);if(f.dtype==="int32"){let b=N.cast(f,"float32");N.dispose(f),f=b}return{tensor:f,canvas:t.filter.return?R0:null}}if(typeof e.readyState!="undefined"&&e.readyState<=2)return t.debug&&u("input stream is not ready"),{tensor:null,canvas:v0};let o=e.naturalWidth||e.videoWidth||e.width||e.shape&&e.shape[1]>0,r=e.naturalHeight||e.videoHeight||e.height||e.shape&&e.shape[2]>0;if(!o||!r)return t.debug&&u("cannot determine input dimensions"),{tensor:null,canvas:v0};let s=o,A=r;if(s>X2&&(s=X2,A=Math.trunc(s*r/o)),A>X2&&(A=X2,s=Math.trunc(A*o/r)),(((y=t.filter)==null?void 0:y.width)||0)>0?s=t.filter.width:(((d=t.filter)==null?void 0:d.height)||0)>0&&(s=o*((t.filter.height||0)/r)),(t.filter.height||0)>0?A=t.filter.height:(t.filter.width||0)>0&&(A=r*((t.filter.width||0)/o)),!s||!A)throw new Error("input error: cannot determine dimension");(!v0||v0.width!==s||v0.height!==A)&&(v0=te(s,A));let a=v0.getContext("2d");if(typeof ImageData!="undefined"&&e instanceof ImageData?a.putImageData(e,0,0):t.filter.flip&&typeof a.translate!="undefined"?(a.translate(o,0),a.scale(-1,1),a.drawImage(e,0,0,o,r,0,0,v0.width,v0.height),a.setTransform(1,0,0,1,0,0)):a.drawImage(e,0,0,o,r,0,0,v0.width,v0.height),(!R0||v0.width!==R0.width||v0.height!==R0.height)&&(R0=te(v0.width,v0.height)),t.filter.enabled&&R.webgl.supported?(e0||(e0=R.browser?new W1:null),R.filter=!!e0,e0!=null&&e0.add?(e0.reset(),t.filter.brightness!==0&&e0.add("brightness",t.filter.brightness),t.filter.contrast!==0&&e0.add("contrast",t.filter.contrast),t.filter.sharpness!==0&&e0.add("sharpen",t.filter.sharpness),t.filter.blur!==0&&e0.add("blur",t.filter.blur),t.filter.saturation!==0&&e0.add("saturation",t.filter.saturation),t.filter.hue!==0&&e0.add("hue",t.filter.hue),t.filter.negative&&e0.add("negative"),t.filter.sepia&&e0.add("sepia"),t.filter.vintage&&e0.add("brownie"),t.filter.sepia&&e0.add("sepia"),t.filter.kodachrome&&e0.add("kodachrome"),t.filter.technicolor&&e0.add("technicolor"),t.filter.polaroid&&e0.add("polaroid"),t.filter.pixelate!==0&&e0.add("pixelate",t.filter.pixelate),((p=e0.get())==null?void 0:p.length)>1?R0=e0.apply(v0):R0=e0.draw(v0)):(t.debug&&u("input process error: cannot initialize filters"),R.webgl.supported=!1,t.filter.enabled=!1,q2(v0,R0))):(q2(v0,R0),e0&&(e0=null),R.filter=!!e0),!n)return{tensor:null,canvas:R0};if(!R0)throw new Error("canvas error: cannot create output");let l,c=3;if(typeof ImageData!="undefined"&&e instanceof ImageData||e.data&&e.width&&e.height)if(R.browser&&N.browser)l=N.browser?N.browser.fromPixels(e):null;else{c=e.data.length/e.height/e.width;let f=new Uint8Array(e.data.buffer);l=N.tensor(f,[e.height,e.width,c],"int32")}else if((!c2||R0.width!==c2.width||R0.height!==c2.height)&&(c2=te(R0.width,R0.height)),N.browser&&R.browser)t.backend==="webgl"||t.backend==="humangl"||t.backend==="webgpu"?l=N.browser.fromPixels(R0):(c2=q2(R0),l=N.browser.fromPixels(c2));else{let M=q2(R0).getContext("2d").getImageData(0,0,s,A);c=M.data.length/s/A;let T=new Uint8Array(M.data.buffer);l=N.tensor(T,[s,A,c])}if(c===4){let f=N.slice3d(l,[0,0,0],[-1,-1,3]);N.dispose(l),l=f}if(!l)throw new Error("input error: cannot create tensor");let x=N.cast(l,"float32"),i=t.filter.equalization?await Z2(x):N.expandDims(x,0);if(N.dispose([l,x]),t.filter.autoBrightness){let f=N.max(i),b=await f.data();t.filter.brightness=b[0]>1?1-b[0]/255:1-b[0],N.dispose(f)}return{tensor:i,canvas:t.filter.return?R0:null}}async function D1(e,t){let n=!1;if(e.cacheSensitivity===0||!t.shape||t.shape.length!==4||t.shape[1]>3840||t.shape[2]>2160)return n;if(!J0.inputTensor)J0.inputTensor=N.clone(t);else if(J0.inputTensor.shape[1]!==t.shape[1]||J0.inputTensor.shape[2]!==t.shape[2])N.dispose(J0.inputTensor),J0.inputTensor=N.clone(t);else{let o={};o.diff=N.sub(t,J0.inputTensor),o.squared=N.mul(o.diff,o.diff),o.sum=N.sum(o.squared);let s=(await o.sum.data())[0]/(t.shape[1]||1)/(t.shape[2]||1)/255/3;N.dispose([J0.inputTensor,o.diff,o.squared,o.sum]),J0.inputTensor=N.clone(t),n=s<=(e.cacheSensitivity||0)}return n}async function F1(e,t,n){let o={};if(!t||!n||t.shape.length!==4||t.shape.length!==n.shape.length)return e.debug||u("invalid input tensor or tensor shapes do not match:",t.shape,n.shape),0;if(t.shape[0]!==1||n.shape[0]!==1||t.shape[3]!==3||n.shape[3]!==3)return e.debug||u("input tensors must be of shape [1, height, width, 3]:",t.shape,n.shape),0;o.input1=N.clone(t),o.input2=t.shape[1]!==n.shape[1]||t.shape[2]!==n.shape[2]?N.image.resizeBilinear(n,[t.shape[1],t.shape[2]]):N.clone(n),o.diff=N.sub(o.input1,o.input2),o.squared=N.mul(o.diff,o.diff),o.sum=N.sum(o.squared);let s=(await o.sum.data())[0]/(t.shape[1]||1)/(t.shape[2]||1)/255/3;return N.dispose([o.input1,o.input2,o.diff,o.squared,o.sum]),s}var S2,j2,N2,z2=class{constructor(){k(this,"browser");k(this,"node");k(this,"worker");k(this,"platform","");k(this,"agent","");k(this,"backends",[]);k(this,"initial");k(this,"filter");k(this,"tfjs");k(this,"offscreen");k(this,"perfadd",!1);k(this,"tensorflow",{version:void 0,gpu:void 0});k(this,"wasm",{supported:void 0,backend:void 0,simd:void 0,multithread:void 0});k(this,"webgl",{supported:void 0,backend:void 0,version:void 0,renderer:void 0,shader:void 0,vendor:void 0});k(this,"webgpu",{supported:void 0,backend:void 0,adapter:void 0});k(this,"cpu",{model:void 0,flags:[]});k(this,"kernels",[]);me(this,S2,void 0);me(this,j2,void 0);me(this,N2,void 0);if(this.browser=typeof navigator!="undefined",this.node=typeof process!="undefined"&&typeof process.versions!="undefined"&&typeof process.versions.node!="undefined",this.tfjs={version:I0.version["tfjs-core"]},this.offscreen=typeof OffscreenCanvas!="undefined",this.initial=!0,this.worker=this.browser&&this.offscreen?typeof WorkerGlobalScope!="undefined":void 0,typeof navigator!="undefined"){let t=navigator.userAgent.match(/\(([^()]+)\)/g);if(t!=null&&t[0]){let n=t[0].match(/\(([^()]+)\)/g);this.platform=n!=null&&n[0]?n[0].replace(/\(|\)/g,""):"",this.agent=navigator.userAgent.replace(t[0],""),this.platform[1]&&(this.agent=this.agent.replace(t[1],"")),this.agent=this.agent.replace(/ /g," ")}}else typeof process!="undefined"&&(this.platform=`${process.platform} ${process.arch}`,this.agent=`NodeJS ${process.version}`)}get Canvas(){return G0(this,S2)}set Canvas(t){ge(this,S2,t),globalThis.Canvas=t}get Image(){return G0(this,j2)}set Image(t){ge(this,j2,t),globalThis.Image=t}get ImageData(){return G0(this,N2)}set ImageData(t){ge(this,N2,t),globalThis.ImageData=t}async updateBackend(){this.backends=Object.keys(I0.engine().registryFactory);try{this.tensorflow={version:I0.backend().binding?I0.backend().binding.TF_Version:void 0,gpu:I0.backend().binding?I0.backend().binding.isUsingGpuDevice():void 0}}catch(o){}this.wasm.supported=typeof WebAssembly!="undefined",this.wasm.backend=this.backends.includes("wasm"),this.wasm.supported&&this.wasm.backend&&(this.wasm.simd=await I0.env().getAsync("WASM_HAS_SIMD_SUPPORT"),this.wasm.multithread=await I0.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"));let t=te(100,100),n=t?t.getContext("webgl2"):void 0;this.webgl.supported=typeof n!="undefined",this.webgl.backend=this.backends.includes("webgl"),this.webgl.supported&&this.webgl.backend&&n&&(this.webgl.version=n.getParameter(n.VERSION),this.webgl.vendor=n.getParameter(n.VENDOR),this.webgl.renderer=n.getParameter(n.RENDERER),this.webgl.shader=n.getParameter(n.SHADING_LANGUAGE_VERSION)),this.webgpu.supported=this.browser&&typeof navigator.gpu!="undefined",this.webgpu.backend=this.backends.includes("webgpu");try{if(this.webgpu.supported){let o=await navigator.gpu.requestAdapter();this.webgpu.adapter=await(o==null?void 0:o.requestAdapterInfo())}}catch(o){this.webgpu.supported=!1}try{this.kernels=I0.getKernelsForBackend(I0.getBackend()).map(o=>o.kernelName.toLowerCase())}catch(o){}}updateCPU(){let t={model:"",flags:[]};this.node&&this.platform.startsWith("linux"),this.cpu?this.cpu=t:Object.defineProperty(this,"cpu",{value:t})}};S2=new WeakMap,j2=new WeakMap,N2=new WeakMap;var R=new z2;var K2=class{constructor(){k(this,"config");k(this,"element");k(this,"stream");k(this,"devices",[]);k(this,"enumerate",async()=>{try{let t=await navigator.mediaDevices.enumerateDevices();this.devices=t.filter(n=>n.kind==="videoinput")}catch(t){this.devices=[]}return this.devices});k(this,"start",async t=>{var r,s;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{this.config.debug&&u("webcam","cannot get dom element",t.element);return}}else if(t.element instanceof HTMLVideoElement)this.element=t.element;else{this.config.debug&&u("webcam","unknown dom element",t.element);return}else this.element=document.createElement("video");let n={audio:!1,video:{facingMode:this.config.mode==="front"?"user":"environment",resizeMode:this.config.crop?"crop-and-scale":"none"}};if(((r=this.config)==null?void 0:r.width)>0&&(n.video.width={ideal:this.config.width}),((s=this.config)==null?void 0:s.height)>0&&(n.video.height={ideal:this.config.height}),this.config.id&&(n.video.deviceId=this.config.id),this.element.addEventListener("play",()=>{this.config.debug&&u("webcam","play")}),this.element.addEventListener("pause",()=>{this.config.debug&&u("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)){this.config.debug&&u("webcam","no devices");return}try{this.stream=await navigator.mediaDevices.getUserMedia(n)}catch(A){u("webcam",A);return}if(!this.stream){this.config.debug&&u("webcam","no stream");return}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&&u("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})});k(this,"pause",()=>{this.element&&this.element.pause()});k(this,"play",async()=>{this.element&&await this.element.play()});k(this,"stop",()=>{this.config.debug&&u("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}};var d2=Z(H());var _t={};ze(_t,{age:()=>yr,"anti-spoofing":()=>Vr,antispoof:()=>tr,blazeface:()=>nr,"blazeface-back":()=>fr,"blazeface-front":()=>mr,"blazepose-detector":()=>pr,"blazepose-full":()=>ur,"blazepose-heavy":()=>hr,"blazepose-lite":()=>br,centernet:()=>or,default:()=>ns,efficientpose:()=>gr,"efficientpose-i-lite":()=>Zr,"efficientpose-ii-lite":()=>Xr,"efficientpose-iv":()=>qr,emotion:()=>rr,faceboxes:()=>Tr,facemesh:()=>sr,"facemesh-attention":()=>Rr,"facemesh-attention-pinto":()=>vr,"facemesh-detection-full":()=>Mr,"facemesh-detection-short":()=>Pr,faceres:()=>Ar,"faceres-deep":()=>kr,gear:()=>wr,gender:()=>zr,"gender-ssrnet-imdb":()=>Er,handdetect:()=>Sr,"handlandmark-full":()=>jr,"handlandmark-lite":()=>ar,"handlandmark-sparse":()=>Nr,handskeleton:()=>Ir,handtrack:()=>ir,"insightface-efficientnet-b0":()=>Ur,"insightface-ghostnet-strides1":()=>Yr,"insightface-ghostnet-strides2":()=>Kr,"insightface-mobilenet-emore":()=>Jr,"insightface-mobilenet-swish":()=>Qr,iris:()=>lr,liveness:()=>cr,meet:()=>Or,mobileface:()=>Lr,mobilefacenet:()=>Cr,models:()=>dr,"movenet-lightning":()=>xr,"movenet-multipose":()=>Wr,"movenet-thunder":()=>Dr,nanodet:()=>Fr,"nanodet-e":()=>_r,"nanodet-g":()=>$r,"nanodet-m":()=>es,"nanodet-t":()=>ts,posenet:()=>Br,rvm:()=>Hr,selfie:()=>Gr});var tr=853098,nr=538928,or=4030290,rr=820516,sr=1477958,Ar=6978814,ar=2023432,ir=2964837,lr=2599092,cr=592976,dr=0,xr=4650216,yr=161240,fr=538928,mr=402048,pr=5928856,ur=6339202,hr=27502466,br=2726402,gr=5651240,Tr=2013002,vr=2387598,Rr=2382414,Mr=1026192,Pr=201268,kr=13957620,wr=1498916,Er=161236,zr=201808,Sr=3515612,jr=5431368,Nr=5286322,Ir=5502280,Or=372228,Lr=2183192,Cr=5171976,Wr=9448838,Dr=12477112,Fr=7574558,Br=5032780,Hr=3739355,Gr=212886,Vr=853098,Zr=2269064,Xr=5651240,qr=25643252,Ur=13013224,Yr=8093408,Kr=8049584,Jr=6938536,Qr=12168584,_r=12319156,$r=7574558,es=1887474,ts=5294216,ns={antispoof:tr,blazeface:nr,centernet:or,emotion:rr,facemesh:sr,faceres:Ar,"handlandmark-lite":ar,handtrack:ir,iris:lr,liveness:cr,models:dr,"movenet-lightning":xr,age:yr,"blazeface-back":fr,"blazeface-front":mr,"blazepose-detector":pr,"blazepose-full":ur,"blazepose-heavy":hr,"blazepose-lite":br,efficientpose:gr,faceboxes:Tr,"facemesh-attention-pinto":vr,"facemesh-attention":Rr,"facemesh-detection-full":Mr,"facemesh-detection-short":Pr,"faceres-deep":kr,gear:wr,"gender-ssrnet-imdb":Er,gender:zr,handdetect:Sr,"handlandmark-full":jr,"handlandmark-sparse":Nr,handskeleton:Ir,meet:Or,mobileface:Lr,mobilefacenet:Cr,"movenet-multipose":Wr,"movenet-thunder":Dr,nanodet:Fr,posenet:Br,rvm:Hr,selfie:Gr,"anti-spoofing":Vr,"efficientpose-i-lite":Zr,"efficientpose-ii-lite":Xr,"efficientpose-iv":qr,"insightface-efficientnet-b0":Ur,"insightface-ghostnet-strides1":Yr,"insightface-ghostnet-strides2":Kr,"insightface-mobilenet-emore":Jr,"insightface-mobilenet-swish":Qr,"nanodet-e":_r,"nanodet-g":$r,"nanodet-m":es,"nanodet-t":ts};var O0={cacheModels:!0,cacheSupported:!0,verbose:!0,debug:!1,modelBasePath:""},E0={};async function os(e,t){return O0.debug&&u("load model fetch:",e,t),fetch(e,t)}function B1(e){O0.cacheModels=e.cacheModels,O0.verbose=e.debug,O0.modelBasePath=e.modelBasePath}async function O(e){var c,x,i,y;let t=S1(O0.modelBasePath,e||"");t.toLowerCase().endsWith(".json")||(t+=".json");let n=t.includes("/")?t.split("/"):t.split("\\"),o=n[n.length-1].replace(".json",""),r="indexeddb://"+o;E0[o]={name:o,sizeFromManifest:0,sizeLoadedWeights:0,sizeDesired:_t[o],inCache:!1,url:""},O0.cacheSupported=typeof indexedDB!="undefined";let s={};try{s=O0.cacheSupported&&O0.cacheModels?await d2.io.listModels():{}}catch(d){O0.cacheSupported=!1}E0[o].inCache=O0.cacheSupported&&O0.cacheModels&&Object.keys(s).includes(r),E0[o].url=E0[o].inCache?r:t;let A=typeof fetch=="undefined"?{}:{fetchFunc:(d,p)=>os(d,p)},a=new d2.GraphModel(E0[o].url,A),l=!1;try{a.findIOHandler(),O0.debug&&u("model load handler:",a.handler)}catch(d){u("error finding model i/o handler:",t,d)}try{let d=await((c=a.handler)==null?void 0:c.load())||null;E0[o].sizeFromManifest=((x=d==null?void 0:d.weightData)==null?void 0:x.byteLength)||0,d?a.loadSync(d):a=await d2.loadGraphModel(E0[o].inCache?r:t,A),E0[o].sizeLoadedWeights=((y=(i=a.artifacts)==null?void 0:i.weightData)==null?void 0:y.byteLength)||0,O0.verbose&&u("load:",{model:o,url:a.modelUrl,bytes:E0[o].sizeLoadedWeights}),l=!0}catch(d){u("error loading model:",t,d)}if(l&&O0.cacheModels&&O0.cacheSupported&&!E0[o].inCache)try{let d=await a.save(r);O0.debug&&u("model saved:",r,d)}catch(d){u("error saving model:",t,d)}return a}var $t="3.0.2";var E=Z(H());var p0=Z(H());var o0={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 As(){let e=o0.gl;!e||(o0.extensions=e.getSupportedExtensions())}function H1(e){var t;if(e.config.backend==="humangl"&&(o0.name in p0.engine().registry&&!((t=o0==null?void 0:o0.gl)!=null&&t.getParameter(o0.gl.VERSION))&&(u("humangl error: backend invalid context"),e.models.reset()),!p0.findBackend(o0.name))){try{o0.canvas=te(100,100)}catch(r){u("humangl error: cannot create canvas:",r);return}try{if(o0.gl=o0.canvas.getContext("webgl2",o0.webGLattr),!o0.gl){u("humangl error: cannot get webgl context");return}if(!o0.gl.getParameter(o0.gl.VERSION).includes("2.0")){u("backend override: using fallback webgl backend as webgl 2.0 is not detected"),e.config.backend="webgl";return}o0.canvas&&(o0.canvas.addEventListener("webglcontextlost",s=>{throw u("humangl error:",s.type),u("possible browser memory leak using webgl or conflict with multiple backend registrations"),e.emit("error"),new Error("backend error: webgl context lost")}),o0.canvas.addEventListener("webglcontextrestored",s=>{u("humangl error: context restored:",s)}),o0.canvas.addEventListener("webglcontextcreationerror",s=>{u("humangl error: context create:",s)}))}catch(r){u("humangl error: cannot get webgl context:",r);return}try{p0.setWebGLContext(2,o0.gl)}catch(r){u("humangl error: cannot set webgl context:",r);return}try{let r=new p0.GPGPUContext(o0.gl);p0.registerBackend(o0.name,()=>new p0.MathBackendWebGL(r),o0.priority)}catch(r){u("humangl error: cannot register webgl backend:",r);return}try{p0.getKernelsForBackend("webgl").forEach(s=>{let A={...s,backendName:o0.name};p0.registerKernel(A)})}catch(r){u("humangl error: cannot update webgl backend registration:",r);return}try{p0.env().flagRegistry.WEBGL_VERSION&&p0.env().set("WEBGL_VERSION",2)}catch(r){u("humangl error: cannot set WebGL backend flags:",r);return}As();let n=p0.backend(),o=typeof n.gpgpu!="undefined"?n.getGPGPUContext().gl:null;o?e.config.debug&&u("humangl backend registered:",{webgl:o.getParameter(o.VERSION),renderer:o.getParameter(o.RENDERER)}):u("humangl error: no current gl context:",o,o0.gl)}}var Se=Z(H()),C={tf255:255,tf1:1,tf2:2,tf05:.5,tf127:127.5,rgb:[.2989,.587,.114]};function G1(){C.tf255=Se.scalar(255,"float32"),C.tf1=Se.scalar(1,"float32"),C.tf2=Se.scalar(2,"float32"),C.tf05=Se.scalar(.5,"float32"),C.tf127=Se.scalar(127.5,"float32"),C.rgb=Se.tensor1d([.2989,.587,.114],"float32")}async function ls(){var e;return await R.updateBackend(),(e=R.tensorflow)!=null&&e.version?"tensorflow":R.webgpu.supported&&R.webgpu.backend?"webgpu":R.webgl.supported&&R.webgl.backend?"webgl":R.wasm.supported&&R.wasm.backend?"wasm":"cpu"}function cs(e){let t=[];if(!R.kernels.includes("mod")){let n={kernelName:"Mod",backendName:E.getBackend(),kernelFunc:o=>E.tidy(()=>E.sub(o.inputs.a,E.mul(E.div(o.inputs.a,o.inputs.b),o.inputs.b)))};E.registerKernel(n),R.kernels.push("mod"),t.push("mod")}if(!R.kernels.includes("floormod")){let n={kernelName:"FloorMod",backendName:E.getBackend(),kernelFunc:o=>E.tidy(()=>E.add(E.mul(E.floorDiv(o.inputs.a,o.inputs.b),o.inputs.b),E.mod(o.inputs.a,o.inputs.b)))};E.registerKernel(n),R.kernels.push("floormod"),t.push("floormod")}if(!R.kernels.includes("rotatewithoffset")&&e.softwareKernels){let n={kernelName:"RotateWithOffset",backendName:E.getBackend(),kernelFunc:o=>E.tidy(()=>{let r=E.getBackend();E.setBackend("cpu");let s=E.image.rotateWithOffset(o.inputs.image,o.attrs.radians,o.attrs.fillValue,o.attrs.center);return E.setBackend(r),s})};E.registerKernel(n),R.kernels.push("rotatewithoffset"),t.push("rotatewithoffset")}t.length>0&&e.debug&&u("registered kernels:",t)}var V1={};async function I2(e,t=!1){var n;if(e.state="backend",((n=e.config.backend)==null?void 0:n.length)===0&&(e.config.backend=await ls()),t||R.initial||e.config.backend&&e.config.backend.length>0&&E.getBackend()!==e.config.backend){let o=g();if(e.config.backend&&e.config.backend.length>0){if(typeof window=="undefined"&&typeof WorkerGlobalScope!="undefined"&&e.config.debug&&e.config.debug&&u("running inside web worker"),R.browser&&e.config.backend==="tensorflow"&&(e.config.debug&&u("override: backend set to tensorflow while running in browser"),e.config.backend="webgl"),R.node&&(e.config.backend==="webgl"||e.config.backend==="humangl")&&(e.config.debug&&u(`override: backend set to ${e.config.backend} while running in nodejs`),e.config.backend="tensorflow"),R.browser&&e.config.backend==="webgpu")if(typeof navigator=="undefined"||typeof navigator.gpu=="undefined")u("override: backend set to webgpu but browser does not support webgpu"),e.config.backend="webgl";else{let s=await navigator.gpu.requestAdapter();if(e.config.debug&&u("enumerated webgpu adapter:",s),!s)u("override: backend set to webgpu but browser reports no available gpu"),e.config.backend="webgl";else{let A="requestAdapterInfo"in s?await s.requestAdapterInfo():void 0;u("webgpu adapter info:",A)}}let r=Object.keys(E.engine().registryFactory);if(e.config.backend==="humangl"&&!r.includes("humangl")&&(H1(e),r=Object.keys(E.engine().registryFactory)),e.config.debug&&u("available backends:",r),r.includes(e.config.backend)||(u(`error: backend ${e.config.backend} not found in registry`),e.config.backend=R.node?"tensorflow":"webgl",e.config.debug&&u(`override: setting backend ${e.config.backend}`)),e.config.debug&&u("setting backend:",[e.config.backend]),e.config.backend==="wasm"){if(E.env().flagRegistry.CANVAS2D_WILL_READ_FREQUENTLY&&E.env().set("CANVAS2D_WILL_READ_FREQUENTLY",!0),e.config.debug&&u("wasm path:",e.config.wasmPath),typeof E.setWasmPaths!="undefined")E.setWasmPaths(e.config.wasmPath,e.config.wasmPlatformFetch);else throw new Error("backend error: attempting to use wasm backend but wasm path is not set");let s=!1,A=!1;try{s=await E.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"),A=await E.env().getAsync("WASM_HAS_SIMD_SUPPORT"),e.config.debug&&u(`wasm execution: ${A?"simd":"no simd"} ${s?"multithreaded":"singlethreaded"}`),e.config.debug&&!A&&u("warning: wasm simd support is not enabled")}catch(a){u("wasm detection failed")}}try{await E.setBackend(e.config.backend),await E.ready()}catch(s){return u("error: cannot set backend:",e.config.backend,s),!1}e.config.debug&&(V1=JSON.parse(JSON.stringify(E.env().flags)))}if((E.getBackend()==="humangl"||E.getBackend()==="webgl")&&(E.env().flagRegistry.WEBGL_USE_SHAPES_UNIFORMS&&E.env().set("WEBGL_USE_SHAPES_UNIFORMS",!0),E.env().flagRegistry.WEBGL_EXP_CONV&&E.env().set("WEBGL_EXP_CONV",!0),e.config.debug&&typeof e.config.deallocate!="undefined"&&e.config.deallocate&&(u("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",!0),E.env().set("WEBGL_DELETE_TEXTURE_THRESHOLD",0))),E.getBackend(),e.config.debug){let r=E.env().flags,s={};for(let A of Object.keys(r))V1[A]!==r[A]&&(s[A]=r[A]);e.config.debug&&Object.keys(s).length>0&&u("backend:",E.getBackend(),"flags:",s)}if(e.config.flags&&Object.keys(e.config.flags).length>0){e.config.debug&&u("flags:",e.config.flags);for(let[r,s]of Object.entries(e.config.flags))E.env().set(r,s)}E.enableProdMode(),G1(),e.performance.initBackend=Math.trunc(g()-o),e.config.backend=E.getBackend(),await R.updateBackend(),cs(e.config),R.initial=!1}return!0}function J2(e,t){for(let n of e){let o={kernelName:n,backendName:t.backend,kernelFunc:r=>{var s;return t.debug&&u("kernelFunc",n,t.backend,r),(s=r==null?void 0:r.inputs)==null?void 0:s.info}};E.registerKernel(o)}R.kernels=E.getKernelsForBackend(E.getBackend()).map(n=>n.kernelName.toLowerCase())}var nt={};ze(nt,{all:()=>Hs,body:()=>_2,canvas:()=>Bs,face:()=>Q2,gesture:()=>tt,hand:()=>$2,init:()=>A5,object:()=>et,options:()=>x0,person:()=>Fs});var Q0=e=>{if(!e)u("draw error: invalid canvas");else if(!e.getContext)u("draw error: canvas context not defined");else{let t=e.getContext("2d");if(!t)u("draw error: cannot get canvas context");else return t}return null},Ke=e=>Math.round(e*180/Math.PI),_=(e,t,n)=>e.replace(t,typeof n=="number"?n.toFixed(1):n),Je=(e,t)=>{if(!t.useDepth||typeof e=="undefined")return t.color;let n=Uint8ClampedArray.from([127+2*e,127-2*e,255]);return`rgba(${n[0]}, ${n[1]}, ${n[2]}, ${t.alpha})`};function ne(e,t,n,o,r){let s=t.replace(/\[.*\]/g,"").split(` +`).map(a=>a.trim()),A=Math.max(0,n);for(let a=s.length-1;a>=0;a--){let l=a*r.lineHeight+o;r.shadowColor&&r.shadowColor!==""&&(e.fillStyle=r.shadowColor,e.fillText(s[a],A+5,l+16)),e.fillStyle=r.labelColor,e.fillText(s[a],A+4,l+15)}}function Te(e,t,n,o,r){e.fillStyle=Je(o,r),e.beginPath(),e.arc(t,n,r.pointSize,0,2*Math.PI),e.fill()}function pe(e,t,n,o,r,s){if(e.beginPath(),e.lineWidth=s.lineWidth,s.useCurves){let A=(t+t+o)/2,a=(n+n+r)/2;e.ellipse(A,a,o/2,r/2,0,0,2*Math.PI)}else e.moveTo(t+s.roundRect,n),e.lineTo(t+o-s.roundRect,n),e.quadraticCurveTo(t+o,n,t+o,n+s.roundRect),e.lineTo(t+o,n+r-s.roundRect),e.quadraticCurveTo(t+o,n+r,t+o-s.roundRect,n+r),e.lineTo(t+s.roundRect,n+r),e.quadraticCurveTo(t,n+r,t,n+r-s.roundRect),e.lineTo(t,n+s.roundRect),e.quadraticCurveTo(t,n,t+s.roundRect,n),e.closePath();e.stroke()}function e5(e,t,n){if(!(t.length<2)){e.beginPath(),e.moveTo(t[0][0],t[0][1]);for(let o of t)e.strokeStyle=Je(o[2]||0,n),e.lineTo(Math.trunc(o[0]),Math.trunc(o[1]));e.stroke(),n.fillPolygons&&(e.closePath(),e.fill())}}function X1(e,t,n){if(!(t.length<2)){if(e.lineWidth=n.lineWidth,!n.useCurves||t.length<=2){e5(e,t,n);return}e.moveTo(t[0][0],t[0][1]);for(let o=0;oO2[e]),La=xs.map(e=>O2[e]),Ca=ys.map(e=>O2[e]);function je(e){let t=e.map(n=>n[0]);return t.push(e[e.length-1][1]),t}var fs=[[61,146],[146,91],[91,181],[181,84],[84,17],[17,314],[314,405],[405,321],[321,375],[375,291],[61,185],[185,40],[40,39],[39,37],[37,0],[0,267],[267,269],[269,270],[270,409],[409,291],[78,95],[95,88],[88,178],[178,87],[87,14],[14,317],[317,402],[402,318],[318,324],[324,308],[78,191],[191,80],[80,81],[81,82],[82,13],[13,312],[312,311],[311,310],[310,415],[415,308]],ms=[[263,249],[249,390],[390,373],[373,374],[374,380],[380,381],[381,382],[382,362],[263,466],[466,388],[388,387],[387,386],[386,385],[385,384],[384,398],[398,362]],ps=[[276,283],[283,282],[282,295],[295,285],[300,293],[293,334],[334,296],[296,336]],us=[[474,475],[475,476],[476,477],[477,474]],hs=[[33,7],[7,163],[163,144],[144,145],[145,153],[153,154],[154,155],[155,133],[33,246],[246,161],[161,160],[160,159],[159,158],[158,157],[157,173],[173,133]],bs=[[46,53],[53,52],[52,65],[65,55],[70,63],[63,105],[105,66],[66,107]],gs=[[469,470],[470,471],[471,472],[472,469]],Ts=[[10,338],[338,297],[297,332],[332,284],[284,251],[251,389],[389,356],[356,454],[454,323],[323,361],[361,288],[288,397],[397,365],[365,379],[379,378],[378,400],[400,377],[377,152],[152,148],[148,176],[176,149],[149,150],[150,136],[136,172],[172,58],[58,132],[132,93],[93,234],[234,127],[127,162],[162,21],[21,54],[54,103],[103,67],[67,109],[109,10]],Wa={lips:je(fs),leftEye:je(ms),leftEyebrow:je(ps),leftIris:je(us),rightEye:je(hs),rightEyebrow:je(bs),rightIris:je(gs),faceOval:je(Ts)};var vs=[[61,146],[146,91],[91,181],[181,84],[84,17],[17,314],[314,405],[405,321],[321,375],[375,291],[61,185],[185,40],[40,39],[39,37],[37,0],[0,267],[267,269],[269,270],[270,409],[409,291],[78,95],[95,88],[88,178],[178,87],[87,14],[14,317],[317,402],[402,318],[318,324],[324,308],[78,191],[191,80],[80,81],[81,82],[82,13],[13,312],[312,311],[311,310],[310,415],[415,308]],Rs=[[263,249],[249,390],[390,373],[373,374],[374,380],[380,381],[381,382],[382,362],[263,466],[466,388],[388,387],[387,386],[386,385],[385,384],[384,398],[398,362]],Ms=[[276,283],[283,282],[282,295],[295,285],[300,293],[293,334],[334,296],[296,336]],Ps=[[474,475],[475,476],[476,477],[477,474]],ks=[[33,7],[7,163],[163,144],[144,145],[145,153],[153,154],[154,155],[155,133],[33,246],[246,161],[161,160],[160,159],[159,158],[158,157],[157,173],[173,133]],ws=[[46,53],[53,52],[52,65],[65,55],[70,63],[63,105],[105,66],[66,107]],Es=[[469,470],[470,471],[471,472],[472,469]],zs=[[10,338],[338,297],[297,332],[332,284],[284,251],[251,389],[389,356],[356,454],[454,323],[323,361],[361,288],[288,397],[397,365],[365,379],[379,378],[378,400],[400,377],[377,152],[152,148],[148,176],[176,149],[149,150],[150,136],[136,172],[172,58],[58,132],[132,93],[93,234],[234,127],[127,162],[162,21],[21,54],[54,103],[103,67],[67,109],[109,10]];function Ne(e){let t=e.map(n=>n[0]);return t.push(e[e.length-1][1]),t}var Ss={lips:Ne(vs),leftEye:Ne(Rs),leftEyebrow:Ne(Ms),leftIris:Ne(Ps),rightEye:Ne(ks),rightEyebrow:Ne(ws),rightIris:Ne(Es),faceOval:Ne(zs)},js=Object.entries(Ss).map(([e,t])=>t.map(n=>[n,e])).flat(),Da=new Map(js),L2=[61,146,91,181,84,17,314,405,321,375,291,185,40,39,37,0,267,269,270,409,78,95,88,178,87,14,317,402,318,324,308,191,80,81,82,13,312,311,310,415,76,77,90,180,85,16,315,404,320,307,306,184,74,73,72,11,302,303,304,408,62,96,89,179,86,15,316,403,319,325,292,183,42,41,38,12,268,271,272,407],$e=[33,7,163,144,145,153,154,155,133,246,161,160,159,158,157,173,130,25,110,24,23,22,26,112,243,247,30,29,27,28,56,190,226,31,228,229,230,231,232,233,244,113,225,224,223,222,221,189,35,124,46,53,52,65,143,111,117,118,119,120,121,128,245,156,70,63,105,66,107,55,193],e2=[263,249,390,373,374,380,381,382,362,466,388,387,386,385,384,398,359,255,339,254,253,252,256,341,463,467,260,259,257,258,286,414,446,261,448,449,450,451,452,453,464,342,445,444,443,442,441,413,265,353,276,283,282,295,372,340,346,347,348,349,350,357,465,383,300,293,334,296,336,285,417];var K;function Ns(e,t){var o,r,s,A,a,l,c,x,i;if(!K.drawLabels||((o=K.faceLabels)==null?void 0:o.length)===0)return;let n=K.faceLabels.slice();if(e.score&&(n=_(n,"[score]",100*e.score)),e.gender&&(n=_(n,"[gender]",e.gender)),e.genderScore&&(n=_(n,"[genderScore]",100*e.genderScore)),e.age&&(n=_(n,"[age]",e.age)),e.distance&&(n=_(n,"[distance]",100*e.distance)),e.real&&(n=_(n,"[real]",100*e.real)),e.live&&(n=_(n,"[live]",100*e.live)),e.emotion&&e.emotion.length>0){let y=e.emotion.map(d=>`${Math.trunc(100*d.score)}% ${d.emotion}`);y.length>3&&(y.length=3),n=_(n,"[emotions]",y.join(" "))}(s=(r=e.rotation)==null?void 0:r.angle)!=null&&s.roll&&(n=_(n,"[roll]",Ke(e.rotation.angle.roll))),(a=(A=e.rotation)==null?void 0:A.angle)!=null&&a.yaw&&(n=_(n,"[yaw]",Ke(e.rotation.angle.yaw))),(c=(l=e.rotation)==null?void 0:l.angle)!=null&&c.pitch&&(n=_(n,"[pitch]",Ke(e.rotation.angle.pitch))),(i=(x=e.rotation)==null?void 0:x.gaze)!=null&&i.bearing&&(n=_(n,"[gaze]",Ke(e.rotation.gaze.bearing))),ne(t,n,e.box[0],e.box[1],K)}function Is(e,t){var n,o,r,s;if(((n=e.annotations)==null?void 0:n.leftEyeIris)&&((o=e.annotations)==null?void 0:o.leftEyeIris[0])){t.strokeStyle=K.useDepth?"rgba(255, 200, 255, 0.3)":K.color,t.beginPath();let A=Math.abs(e.annotations.leftEyeIris[3][0]-e.annotations.leftEyeIris[1][0])/2,a=Math.abs(e.annotations.leftEyeIris[4][1]-e.annotations.leftEyeIris[2][1])/2;t.ellipse(e.annotations.leftEyeIris[0][0],e.annotations.leftEyeIris[0][1],A,a,0,0,2*Math.PI),t.stroke(),K.fillPolygons&&(t.fillStyle=K.useDepth?"rgba(255, 255, 200, 0.3)":K.color,t.fill())}if(((r=e.annotations)==null?void 0:r.rightEyeIris)&&((s=e.annotations)==null?void 0:s.rightEyeIris[0])){t.strokeStyle=K.useDepth?"rgba(255, 200, 255, 0.3)":K.color,t.beginPath();let A=Math.abs(e.annotations.rightEyeIris[3][0]-e.annotations.rightEyeIris[1][0])/2,a=Math.abs(e.annotations.rightEyeIris[4][1]-e.annotations.rightEyeIris[2][1])/2;t.ellipse(e.annotations.rightEyeIris[0][0],e.annotations.rightEyeIris[0][1],A,a,0,0,2*Math.PI),t.stroke(),K.fillPolygons&&(t.fillStyle=K.useDepth?"rgba(255, 255, 200, 0.3)":K.color,t.fill())}}function Os(e,t){var n;if(K.drawGaze&&((n=e.rotation)==null?void 0:n.angle)&&typeof Path2D!="undefined"){t.strokeStyle="pink";let o=e.box[0]+e.box[2]/2-e.box[3]*Ke(e.rotation.angle.yaw)/90,r=e.box[1]+e.box[3]/2+e.box[2]*Ke(e.rotation.angle.pitch)/90,s=new Path2D(` + M ${e.box[0]+e.box[2]/2} ${e.box[1]} C - ${valX} ${f.box[1]}, - ${valX} ${f.box[1] + f.box[3]}, - ${f.box[0] + f.box[2] / 2} ${f.box[1] + f.box[3]} - `); - const pathH = new Path2D(` - M ${f.box[0]} ${f.box[1] + f.box[3] / 2} + ${o} ${e.box[1]}, + ${o} ${e.box[1]+e.box[3]}, + ${e.box[0]+e.box[2]/2} ${e.box[1]+e.box[3]} + `),A=new Path2D(` + M ${e.box[0]} ${e.box[1]+e.box[3]/2} C - ${f.box[0]} ${valY}, - ${f.box[0] + f.box[2]} ${valY}, - ${f.box[0] + f.box[2]} ${f.box[1] + f.box[3] / 2} - `); - ctx.stroke(pathH); - ctx.stroke(pathV); - } -} -function drawGazeArrows(f, ctx) { - var _a; - if (localOptions.drawGaze && ((_a = f.rotation) == null ? void 0 : _a.gaze.strength) && f.rotation.gaze.bearing && f.annotations.leftEyeIris && f.annotations.rightEyeIris && f.annotations.leftEyeIris[0] && f.annotations.rightEyeIris[0]) { - ctx.strokeStyle = "pink"; - ctx.fillStyle = "pink"; - const leftGaze = [ - f.annotations.leftEyeIris[0][0] + Math.sin(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[3], - f.annotations.leftEyeIris[0][1] + Math.cos(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[2] - ]; - arrow(ctx, [f.annotations.leftEyeIris[0][0], f.annotations.leftEyeIris[0][1]], [leftGaze[0], leftGaze[1]], 4); - const rightGaze = [ - f.annotations.rightEyeIris[0][0] + Math.sin(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[3], - f.annotations.rightEyeIris[0][1] + Math.cos(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[2] - ]; - arrow(ctx, [f.annotations.rightEyeIris[0][0], f.annotations.rightEyeIris[0][1]], [rightGaze[0], rightGaze[1]], 4); - } -} -function drawFacePolygons(f, ctx) { - if (localOptions.drawPolygons && f.mesh.length >= 468) { - ctx.lineWidth = 1; - for (let i = 0; i < TRI468.length / 3; i++) { - const points = [TRI468[i * 3 + 0], TRI468[i * 3 + 1], TRI468[i * 3 + 2]].map((index2) => f.mesh[index2]); - lines(ctx, points, localOptions); - } - drawIrisElipse(f, ctx); - } -} -function drawFacePoints(f, ctx) { - if (localOptions.drawPoints && f.mesh.length >= 468) { - for (let i = 0; i < f.mesh.length; i++) { - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2], localOptions); - if (localOptions.drawAttention) { - if (LANDMARKS_REFINEMENT_LIPS_CONFIG.includes(i)) - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2] + 127, localOptions); - if (LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG.includes(i)) - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2] - 127, localOptions); - if (LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG.includes(i)) - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2] - 127, localOptions); - } - } - } -} -function drawFaceBoxes(f, ctx) { - if (localOptions.drawBoxes) { - rect(ctx, f.box[0], f.box[1], f.box[2], f.box[3], localOptions); - } -} -function face(inCanvas2, result, drawOptions) { - localOptions = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.font = localOptions.font; - ctx.strokeStyle = localOptions.color; - ctx.fillStyle = localOptions.color; - for (const f of result) { - drawFaceBoxes(f, ctx); - drawLabels(f, ctx); - if (f.mesh && f.mesh.length > 0) { - drawFacePoints(f, ctx); - drawFacePolygons(f, ctx); - drawGazeSpheres(f, ctx); - drawGazeArrows(f, ctx); - } - } -} - -// src/draw/body.ts -function body(inCanvas2, result, drawOptions) { - var _a, _b; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - for (let i = 0; i < result.length; i++) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - ctx.lineWidth = localOptions2.lineWidth; - ctx.font = localOptions2.font; - if (localOptions2.drawBoxes && result[i].box && result[i].box.length === 4) { - rect(ctx, result[i].box[0], result[i].box[1], result[i].box[2], result[i].box[3], localOptions2); - if (localOptions2.drawLabels && ((_a = localOptions2.bodyLabels) == null ? void 0 : _a.length) > 0) { - let l = localOptions2.bodyLabels.slice(); - l = replace(l, "[score]", 100 * result[i].score); - labels(ctx, l, result[i].box[0], result[i].box[1], localOptions2); - } - } - if (localOptions2.drawPoints && result[i].keypoints) { - for (let pt = 0; pt < result[i].keypoints.length; pt++) { - if (!result[i].keypoints[pt].score || result[i].keypoints[pt].score === 0) - continue; - ctx.fillStyle = colorDepth(result[i].keypoints[pt].position[2], localOptions2); - point(ctx, result[i].keypoints[pt].position[0], result[i].keypoints[pt].position[1], 0, localOptions2); - } - } - if (localOptions2.drawLabels && ((_b = localOptions2.bodyPartLabels) == null ? void 0 : _b.length) > 0 && result[i].keypoints) { - ctx.font = localOptions2.font; - for (const pt of result[i].keypoints) { - if (!pt.score || pt.score === 0) - continue; - let l = localOptions2.bodyPartLabels.slice(); - l = replace(l, "[label]", pt.part); - l = replace(l, "[score]", 100 * pt.score); - labels(ctx, l, pt.position[0], pt.position[1], localOptions2); - } - } - if (localOptions2.drawPolygons && result[i].keypoints && result[i].annotations) { - for (const part of Object.values(result[i].annotations)) { - for (const connected4 of part) - curves(ctx, connected4, localOptions2); - } - } - } -} - -// src/draw/hand.ts -function hand(inCanvas2, result, drawOptions) { - var _a, _b; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - ctx.font = localOptions2.font; - for (const h of result) { - if (localOptions2.drawBoxes) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - rect(ctx, h.box[0], h.box[1], h.box[2], h.box[3], localOptions2); - if (localOptions2.drawLabels && ((_a = localOptions2.handLabels) == null ? void 0 : _a.length) > 0) { - let l = localOptions2.handLabels.slice(); - l = replace(l, "[label]", h.label); - l = replace(l, "[score]", 100 * h.score); - labels(ctx, l, h.box[0], h.box[1], localOptions2); - } - ctx.stroke(); - } - if (localOptions2.drawPoints) { - if (h.keypoints && h.keypoints.length > 0) { - for (const pt of h.keypoints) { - ctx.fillStyle = colorDepth(pt[2], localOptions2); - point(ctx, pt[0], pt[1], 0, localOptions2); - } - } - } - if (localOptions2.drawLabels && h.annotations && ((_b = localOptions2.fingerLabels) == null ? void 0 : _b.length) > 0) { - for (const [part, pt] of Object.entries(h.annotations)) { - let l = localOptions2.fingerLabels.slice(); - l = replace(l, "[label]", part); - labels(ctx, l, pt[pt.length - 1][0], pt[pt.length - 1][1], localOptions2); - } - } - if (localOptions2.drawPolygons && h.annotations) { - const addHandLine = (part) => { - if (!part || part.length === 0 || !part[0]) - return; - for (let i = 0; i < part.length; i++) { - ctx.beginPath(); - const z = part[i][2] || 0; - ctx.strokeStyle = colorDepth(i * z, localOptions2); - ctx.moveTo(part[i > 0 ? i - 1 : 0][0], part[i > 0 ? i - 1 : 0][1]); - ctx.lineTo(part[i][0], part[i][1]); - ctx.stroke(); - } - }; - ctx.lineWidth = localOptions2.lineWidth; - addHandLine(h.annotations.index); - addHandLine(h.annotations.middle); - addHandLine(h.annotations.ring); - addHandLine(h.annotations.pinky); - addHandLine(h.annotations.thumb); - } - } -} - -// src/draw/object.ts -function object(inCanvas2, result, drawOptions) { - var _a; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - ctx.font = localOptions2.font; - for (const h of result) { - if (localOptions2.drawBoxes) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - rect(ctx, h.box[0], h.box[1], h.box[2], h.box[3], localOptions2); - if (localOptions2.drawLabels && ((_a = localOptions2.objectLabels) == null ? void 0 : _a.length) > 0) { - let l = localOptions2.objectLabels.slice(); - l = replace(l, "[label]", h.label); - l = replace(l, "[score]", 100 * h.score); - labels(ctx, l, h.box[0], h.box[1], localOptions2); - } - ctx.stroke(); - } - } -} - -// src/draw/gesture.ts -function gesture(inCanvas2, result, drawOptions) { - var _a; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - if (localOptions2.drawGestures && ((_a = localOptions2.gestureLabels) == null ? void 0 : _a.length) > 0) { - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.font = localOptions2.font; - ctx.fillStyle = localOptions2.color; - let i = 1; - for (let j = 0; j < result.length; j++) { - const [where, what] = Object.entries(result[j]); - if (what.length > 1 && what[1].length > 0) { - const who = where[1] > 0 ? `#${where[1]}` : ""; - let l = localOptions2.gestureLabels.slice(); - l = replace(l, "[where]", where[0]); - l = replace(l, "[who]", who); - l = replace(l, "[what]", what[1]); - labels(ctx, l, 8, 2 + i * localOptions2.lineHeight, localOptions2); - i += 1; - } - } - } -} - -// src/draw/labels.ts -var defaultLabels = { - face: `face + ${e.box[0]} ${r}, + ${e.box[0]+e.box[2]} ${r}, + ${e.box[0]+e.box[2]} ${e.box[1]+e.box[3]/2} + `);t.stroke(A),t.stroke(s)}}function Ls(e,t){var n;if(K.drawGaze&&((n=e.rotation)==null?void 0:n.gaze.strength)&&e.rotation.gaze.bearing&&e.annotations.leftEyeIris&&e.annotations.rightEyeIris&&e.annotations.leftEyeIris[0]&&e.annotations.rightEyeIris[0]){t.strokeStyle="pink",t.fillStyle="pink";let o=[e.annotations.leftEyeIris[0][0]+Math.sin(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[3],e.annotations.leftEyeIris[0][1]+Math.cos(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[2]];t5(t,[e.annotations.leftEyeIris[0][0],e.annotations.leftEyeIris[0][1]],[o[0],o[1]],4);let r=[e.annotations.rightEyeIris[0][0]+Math.sin(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[3],e.annotations.rightEyeIris[0][1]+Math.cos(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[2]];t5(t,[e.annotations.rightEyeIris[0][0],e.annotations.rightEyeIris[0][1]],[r[0],r[1]],4)}}function Cs(e,t){if(K.drawPolygons&&e.mesh.length>=468){t.lineWidth=1;for(let n=0;n<_e.length/3;n++){let o=[_e[n*3+0],_e[n*3+1],_e[n*3+2]].map(r=>e.mesh[r]);e5(t,o,K)}Is(e,t)}}function Ws(e,t){if(K.drawPoints&&e.mesh.length>=468)for(let n=0;n0&&(Ws(r,o),Cs(r,o),Os(r,o),Ls(r,o))}}function _2(e,t,n){var s,A;let o=a0(x0,n);if(!t||!e)return;let r=Q0(e);if(!!r){r.lineJoin="round";for(let a=0;a0)){let l=o.bodyLabels.slice();l=_(l,"[score]",100*t[a].score),ne(r,l,t[a].box[0],t[a].box[1],o)}if(o.drawPoints&&t[a].keypoints)for(let l=0;l0&&t[a].keypoints){r.font=o.font;for(let l of t[a].keypoints){if(!l.score||l.score===0)continue;let c=o.bodyPartLabels.slice();c=_(c,"[label]",l.part),c=_(c,"[score]",100*l.score),ne(r,c,l.position[0],l.position[1],o)}}if(o.drawPolygons&&t[a].keypoints&&t[a].annotations)for(let l of Object.values(t[a].annotations))for(let c of l)X1(r,c,o)}}}function $2(e,t,n){var s,A;let o=a0(x0,n);if(!t||!e)return;let r=Q0(e);if(!!r){r.lineJoin="round",r.font=o.font;for(let a of t){if(o.drawBoxes){if(r.strokeStyle=o.color,r.fillStyle=o.color,pe(r,a.box[0],a.box[1],a.box[2],a.box[3],o),o.drawLabels&&((s=o.handLabels)==null?void 0:s.length)>0){let l=o.handLabels.slice();l=_(l,"[label]",a.label),l=_(l,"[score]",100*a.score),ne(r,l,a.box[0],a.box[1],o)}r.stroke()}if(o.drawPoints&&a.keypoints&&a.keypoints.length>0)for(let l of a.keypoints)r.fillStyle=Je(l[2],o),Te(r,l[0],l[1],0,o);if(o.drawLabels&&a.annotations&&((A=o.fingerLabels)==null?void 0:A.length)>0)for(let[l,c]of Object.entries(a.annotations)){let x=o.fingerLabels.slice();x=_(x,"[label]",l),ne(r,x,c[c.length-1][0],c[c.length-1][1],o)}if(o.drawPolygons&&a.annotations){let l=c=>{if(!(!c||c.length===0||!c[0]))for(let x=0;x0?x-1:0][0],c[x>0?x-1:0][1]),r.lineTo(c[x][0],c[x][1]),r.stroke()}};r.lineWidth=o.lineWidth,l(a.annotations.index),l(a.annotations.middle),l(a.annotations.ring),l(a.annotations.pinky),l(a.annotations.thumb)}}}}function et(e,t,n){var s;let o=a0(x0,n);if(!t||!e)return;let r=Q0(e);if(!!r){r.lineJoin="round",r.font=o.font;for(let A of t)if(o.drawBoxes){if(r.strokeStyle=o.color,r.fillStyle=o.color,pe(r,A.box[0],A.box[1],A.box[2],A.box[3],o),o.drawLabels&&((s=o.objectLabels)==null?void 0:s.length)>0){let a=o.objectLabels.slice();a=_(a,"[label]",A.label),a=_(a,"[score]",100*A.score),ne(r,a,A.box[0],A.box[1],o)}r.stroke()}}}function tt(e,t,n){var r;let o=a0(x0,n);if(!(!t||!e)&&o.drawGestures&&((r=o.gestureLabels)==null?void 0:r.length)>0){let s=Q0(e);if(!s)return;s.font=o.font,s.fillStyle=o.color;let A=1;for(let a=0;a1&&c[1].length>0){let x=l[1]>0?`#${l[1]}`:"",i=o.gestureLabels.slice();i=_(i,"[where]",l[0]),i=_(i,"[who]",x),i=_(i,"[what]",c[1]),ne(s,i,8,2+A*o.lineHeight,o),A+=1}}}}var Ie={face:`face confidence: [score]% [gender] [genderScore]% age: [age] years @@ -6469,7523 +118,7 @@ var defaultLabels = { live: [live]% [emotions] roll: [roll]\xB0 yaw:[yaw]\xB0 pitch:[pitch]\xB0 - gaze: [gaze]\xB0`, - body: "body [score]%", - bodyPart: "[label] [score]%", - object: "[label] [score]%", - hand: "[label] [score]%", - finger: "[label]", - gesture: "[where] [who]: [what]" -}; - -// src/draw/draw.ts -var drawTime = 0; -function person(inCanvas2, result, drawOptions) { - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - ctx.font = localOptions2.font; - for (let i = 0; i < result.length; i++) { - if (localOptions2.drawBoxes) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - rect(ctx, result[i].box[0], result[i].box[1], result[i].box[2], result[i].box[3], localOptions2); - if (localOptions2.drawLabels) { - const label = `person #${i}`; - if (localOptions2.shadowColor && localOptions2.shadowColor !== "") { - ctx.fillStyle = localOptions2.shadowColor; - ctx.fillText(label, result[i].box[0] + 3, 1 + result[i].box[1] + localOptions2.lineHeight, result[i].box[2]); - } - ctx.fillStyle = localOptions2.labelColor; - ctx.fillText(label, result[i].box[0] + 2, 0 + result[i].box[1] + localOptions2.lineHeight, result[i].box[2]); - } - ctx.stroke(); - } - } -} -function canvas2(input, output) { - if (!input || !output) - return; - const ctx = getCanvasContext(output); - if (!ctx) - return; - ctx.drawImage(input, 0, 0); -} -async function all(inCanvas2, result, drawOptions) { - if (!(result == null ? void 0 : result.performance) || !inCanvas2) - return null; - const timeStamp = now(); - const localOptions2 = mergeDeep(options2, drawOptions); - const promise = Promise.all([ - face(inCanvas2, result.face, localOptions2), - body(inCanvas2, result.body, localOptions2), - hand(inCanvas2, result.hand, localOptions2), - object(inCanvas2, result.object, localOptions2), - gesture(inCanvas2, result.gesture, localOptions2) - ]); - drawTime = env.perfadd ? drawTime + Math.round(now() - timeStamp) : Math.round(now() - timeStamp); - result.performance.draw = drawTime; - return promise; -} -function init2() { - options2.faceLabels = defaultLabels.face; - options2.bodyLabels = defaultLabels.body; - options2.bodyPartLabels = defaultLabels.bodyPart; - options2.handLabels = defaultLabels.hand; - options2.fingerLabels = defaultLabels.finger; - options2.objectLabels = defaultLabels.object; - options2.gestureLabels = defaultLabels.gesture; -} - -// src/body/blazepose.ts -var tf9 = __toESM(require_tfjs_esm()); - -// src/body/blazeposecoords.ts -var blazeposecoords_exports = {}; -__export(blazeposecoords_exports, { - connected: () => connected, - kpt: () => kpt -}); -var kpt = [ - "nose", - "leftEyeInside", - "leftEye", - "leftEyeOutside", - "rightEyeInside", - "rightEye", - "rightEyeOutside", - "leftEar", - "rightEar", - "leftMouth", - "rightMouth", - "leftShoulder", - "rightShoulder", - "leftElbow", - "rightElbow", - "leftWrist", - "rightWrist", - "leftPinky", - "rightPinky", - "leftIndex", - "rightIndex", - "leftThumb", - "rightThumb", - "leftHip", - "rightHip", - "leftKnee", - "rightKnee", - "leftAnkle", - "rightAnkle", - "leftHeel", - "rightHeel", - "leftFoot", - "rightFoot", - "bodyCenter", - "bodyTop", - "leftPalm", - "leftHand", - "rightPalm", - "rightHand" -]; -var connected = { - shoulders: ["leftShoulder", "rightShoulder"], - hips: ["rightHip", "leftHip"], - mouth: ["leftMouth", "rightMouth"], - leftLegUpper: ["leftHip", "leftKnee"], - leftLegLower: ["leftKnee", "leftAnkle"], - leftFoot: ["leftAnkle", "leftHeel", "leftFoot"], - leftTorso: ["leftShoulder", "leftHip"], - leftArmUpper: ["leftShoulder", "leftElbow"], - leftArmLower: ["leftElbow", "leftWrist"], - leftHand: ["leftWrist", "leftPalm"], - leftHandPinky: ["leftPalm", "leftPinky"], - leftHandIndex: ["leftPalm", "leftIndex"], - leftHandThumb: ["leftPalm", "leftThumb"], - leftEyeOutline: ["leftEyeInside", "leftEyeOutside"], - rightLegUpper: ["rightHip", "rightKnee"], - rightLegLower: ["rightKnee", "rightAnkle"], - rightFoot: ["rightAnkle", "rightHeel", "rightFoot"], - rightTorso: ["rightShoulder", "rightHip"], - rightArmUpper: ["rightShoulder", "rightElbow"], - rightArmLower: ["rightElbow", "rightWrist"], - rightHand: ["rightWrist", "rightPalm"], - rightHandPinky: ["rightPalm", "rightPinky"], - rightHandIndex: ["rightPalm", "rightIndex"], - rightHandThumb: ["rightPalm", "rightThumb"], - rightEyeOutline: ["rightEyeInside", "rightEyeOutside"] -}; - -// src/body/blazeposedetector.ts -var tf8 = __toESM(require_tfjs_esm()); -var model; -var inputSize = 224; -var anchorTensor; -var numLayers = 5; -var strides = [8, 16, 32, 32, 32]; -function createAnchors() { - const anchors3 = []; - let layerId = 0; - while (layerId < numLayers) { - let anchorCount = 0; - let lastSameStrideLayer = layerId; - while (lastSameStrideLayer < strides.length && strides[lastSameStrideLayer] === strides[layerId]) { - anchorCount += 2; - lastSameStrideLayer++; - } - const stride = strides[layerId]; - const featureMapHeight = Math.ceil(inputSize / stride); - const featureMapWidth = Math.ceil(inputSize / stride); - for (let y = 0; y < featureMapHeight; ++y) { - for (let x = 0; x < featureMapWidth; ++x) { - for (let anchorId = 0; anchorId < anchorCount; ++anchorId) { - anchors3.push({ x: (x + 0.5) / featureMapWidth, y: (y + 0.5) / featureMapHeight }); - } - } - } - layerId = lastSameStrideLayer; - } - anchorTensor = { x: tf8.tensor1d(anchors3.map((a) => a.x)), y: tf8.tensor1d(anchors3.map((a) => a.y)) }; -} -async function loadDetector(config3) { - if (env.initial) - model = null; - if (!model && config3.body["detector"] && config3.body["detector"].modelPath || "") { - model = await loadModel(config3.body["detector"].modelPath); - const inputs = (model == null ? void 0 : model["executor"]) ? Object.values(model.modelSignature["inputs"]) : void 0; - inputSize = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - } else if (config3.debug && model) - log("cached model:", model["modelUrl"]); - createAnchors(); - return model; -} -var cropFactor = [5, 5]; -function decodeBoxes(boxesTensor, anchor) { - return tf8.tidy(() => { - const split6 = tf8.split(boxesTensor, 12, 1); - let xCenter = tf8.squeeze(split6[0]); - let yCenter = tf8.squeeze(split6[1]); - let width = tf8.squeeze(split6[2]); - let height = tf8.squeeze(split6[3]); - xCenter = tf8.add(tf8.div(xCenter, inputSize), anchor.x); - yCenter = tf8.add(tf8.div(yCenter, inputSize), anchor.y); - width = tf8.mul(tf8.div(width, inputSize), cropFactor[0]); - height = tf8.mul(tf8.div(height, inputSize), cropFactor[1]); - const xMin = tf8.sub(xCenter, tf8.div(width, 2)); - const yMin = tf8.sub(yCenter, tf8.div(height, 2)); - const xMax = tf8.add(xMin, width); - const yMax = tf8.add(yMin, height); - const boxes = tf8.stack([xMin, yMin, xMax, yMax], 1); - return boxes; - }); -} -async function decodeResults(boxesTensor, logitsTensor, config3, outputSize2) { - var _a, _b; - const detectedBoxes = []; - const t2 = {}; - t2.boxes = decodeBoxes(boxesTensor, anchorTensor); - t2.scores = tf8.sigmoid(logitsTensor); - t2.nms = await tf8.image.nonMaxSuppressionAsync(t2.boxes, t2.scores, 1, ((_a = config3.body["detector"]) == null ? void 0 : _a.minConfidence) || 0.1, ((_b = config3.body["detector"]) == null ? void 0 : _b.iouThreshold) || 0.1); - const nms = await t2.nms.data(); - const scores = await t2.scores.data(); - const boxes = await t2.boxes.array(); - for (const i of Array.from(nms)) { - const score = scores[i]; - const boxRaw = boxes[i]; - const box = [Math.round(boxRaw[0] * outputSize2[0]), Math.round(boxRaw[1] * outputSize2[1]), Math.round(boxRaw[2] * outputSize2[0]), Math.round(boxRaw[3] * outputSize2[1])]; - const detectedBox = { score, boxRaw, box }; - detectedBoxes.push(detectedBox); - } - Object.keys(t2).forEach((tensor6) => tf8.dispose(t2[tensor6])); - return detectedBoxes; -} -async function detectBoxes(input, config3, outputSize2) { - const t2 = {}; - t2.res = model == null ? void 0 : model.execute(input, ["Identity"]); - t2.logitsRaw = tf8.slice(t2.res, [0, 0, 0], [1, -1, 1]); - t2.boxesRaw = tf8.slice(t2.res, [0, 0, 1], [1, -1, -1]); - t2.logits = tf8.squeeze(t2.logitsRaw); - t2.boxes = tf8.squeeze(t2.boxesRaw); - const boxes = await decodeResults(t2.boxes, t2.logits, config3, outputSize2); - Object.keys(t2).forEach((tensor6) => tf8.dispose(t2[tensor6])); - return boxes; -} - -// src/util/box.ts -function calc(keypoints, outputSize2 = [1, 1]) { - const coords = [keypoints.map((pt) => pt[0]), keypoints.map((pt) => pt[1])]; - const min2 = [Math.min(...coords[0]), Math.min(...coords[1])]; - const max5 = [Math.max(...coords[0]), Math.max(...coords[1])]; - const box = [min2[0], min2[1], max5[0] - min2[0], max5[1] - min2[1]]; - const boxRaw = [box[0] / outputSize2[0], box[1] / outputSize2[1], box[2] / outputSize2[0], box[3] / outputSize2[1]]; - return { box, boxRaw }; -} -function square(keypoints, outputSize2 = [1, 1]) { - const coords = [keypoints.map((pt) => pt[0]), keypoints.map((pt) => pt[1])]; - const min2 = [Math.min(...coords[0]), Math.min(...coords[1])]; - const max5 = [Math.max(...coords[0]), Math.max(...coords[1])]; - const center = [(min2[0] + max5[0]) / 2, (min2[1] + max5[1]) / 2]; - const dist = Math.max(center[0] - min2[0], center[1] - min2[1], -center[0] + max5[0], -center[1] + max5[1]); - const box = [Math.trunc(center[0] - dist), Math.trunc(center[1] - dist), Math.trunc(2 * dist), Math.trunc(2 * dist)]; - const boxRaw = [box[0] / outputSize2[0], box[1] / outputSize2[1], box[2] / outputSize2[0], box[3] / outputSize2[1]]; - return { box, boxRaw }; -} -function scale(box, scaleFact) { - const dist = [box[2] * scaleFact, box[3] * scaleFact]; - const newBox = [ - box[0] - (dist[0] - box[2]) / 2, - box[1] - (dist[1] - box[3]) / 2, - dist[0], - dist[1] - ]; - return newBox; -} - -// src/body/blazepose.ts -var model2; -var inputSize2 = 256; -var skipped = Number.MAX_SAFE_INTEGER; -var outputNodes = { - landmarks: ["ld_3d", "activation_segmentation", "activation_heatmap", "world_3d", "output_poseflag"], - detector: [] -}; -var cache = []; -var padding = [[0, 0], [0, 0], [0, 0], [0, 0]]; -var lastTime = 0; -var sigmoid2 = (x) => 1 - 1 / (1 + Math.exp(x)); -var loadDetect = (config3) => loadDetector(config3); -async function loadPose(config3) { - if (env.initial) - model2 = null; - if (!model2) { - model2 = await loadModel(config3.body.modelPath); - const inputs = (model2 == null ? void 0 : model2["executor"]) ? Object.values(model2.modelSignature["inputs"]) : void 0; - inputSize2 = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - } else if (config3.debug) - log("cached model:", model2["modelUrl"]); - return model2; -} -function prepareImage(input, size2, cropBox) { - var _a, _b; - const t2 = {}; - if (!((_a = input == null ? void 0 : input.shape) == null ? void 0 : _a[1]) || !((_b = input == null ? void 0 : input.shape) == null ? void 0 : _b[2])) - return input; - let final; - if (cropBox) { - t2.cropped = tf9.image.cropAndResize(input, [cropBox], [0], [input.shape[1], input.shape[2]]); - } - if (input.shape[1] !== input.shape[2]) { - const height = [ - input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0, - input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0 - ]; - const width = [ - input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0, - input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0 - ]; - padding = [ - [0, 0], - height, - width, - [0, 0] - ]; - t2.pad = tf9.pad(t2.cropped || input, padding); - t2.resize = tf9.image.resizeBilinear(t2.pad, [size2, size2]); - final = tf9.div(t2.resize, constants.tf255); - } else if (input.shape[1] !== size2) { - t2.resize = tf9.image.resizeBilinear(t2.cropped || input, [size2, size2]); - final = tf9.div(t2.resize, constants.tf255); - } else { - final = tf9.div(t2.cropped || input, constants.tf255); - } - Object.keys(t2).forEach((tensor6) => tf9.dispose(t2[tensor6])); - return final; -} -function rescaleKeypoints(keypoints, outputSize2, cropBox) { - for (const kpt4 of keypoints) { - kpt4.position = [ - Math.trunc(kpt4.position[0] * (outputSize2[0] + padding[2][0] + padding[2][1]) / outputSize2[0] - padding[2][0]), - Math.trunc(kpt4.position[1] * (outputSize2[1] + padding[1][0] + padding[1][1]) / outputSize2[1] - padding[1][0]), - kpt4.position[2] - ]; - kpt4.positionRaw = [kpt4.position[0] / outputSize2[0], kpt4.position[1] / outputSize2[1], 2 * kpt4.position[2] / (outputSize2[0] + outputSize2[1])]; - } - if (cropBox) { - const width = cropBox[2] - cropBox[0]; - const height = cropBox[3] - cropBox[1]; - for (const kpt4 of keypoints) { - kpt4.positionRaw = [ - kpt4.positionRaw[0] / height + cropBox[1], - kpt4.positionRaw[1] / width + cropBox[0], - kpt4.positionRaw[2] - ]; - kpt4.position = [ - Math.trunc(kpt4.positionRaw[0] * outputSize2[0]), - Math.trunc(kpt4.positionRaw[1] * outputSize2[1]), - kpt4.positionRaw[2] - ]; - } - } - return keypoints; -} -function fixKeypoints(keypoints) { - const leftPalm = keypoints.find((k) => k.part === "leftPalm"); - const leftWrist = keypoints.find((k) => k.part === "leftWrist"); - const leftIndex = keypoints.find((k) => k.part === "leftIndex"); - leftPalm.position[2] = ((leftWrist.position[2] || 0) + (leftIndex.position[2] || 0)) / 2; - const rightPalm = keypoints.find((k) => k.part === "rightPalm"); - const rightWrist = keypoints.find((k) => k.part === "rightWrist"); - const rightIndex = keypoints.find((k) => k.part === "rightIndex"); - rightPalm.position[2] = ((rightWrist.position[2] || 0) + (rightIndex.position[2] || 0)) / 2; -} -async function detectLandmarks(input, config3, outputSize2) { - if (!(model2 == null ? void 0 : model2["executor"])) - return null; - const t2 = {}; - [t2.ld, t2.segmentation, t2.heatmap, t2.world, t2.poseflag] = model2 == null ? void 0 : model2.execute(input, outputNodes.landmarks); - const poseScore = (await t2.poseflag.data())[0]; - const points = await t2.ld.data(); - const distances = await t2.world.data(); - Object.keys(t2).forEach((tensor6) => tf9.dispose(t2[tensor6])); - const keypointsRelative = []; - const depth = 5; - for (let i = 0; i < points.length / depth; i++) { - const score = sigmoid2(points[depth * i + 3]); - const presence = sigmoid2(points[depth * i + 4]); - const adjScore = Math.trunc(100 * score * presence * poseScore) / 100; - const positionRaw = [points[depth * i + 0] / inputSize2, points[depth * i + 1] / inputSize2, points[depth * i + 2] + 0]; - const position = [Math.trunc(outputSize2[0] * positionRaw[0]), Math.trunc(outputSize2[1] * positionRaw[1]), positionRaw[2]]; - const distance2 = [distances[depth * i + 0], distances[depth * i + 1], distances[depth * i + 2] + 0]; - keypointsRelative.push({ part: kpt[i], positionRaw, position, distance: distance2, score: adjScore }); - } - if (poseScore < (config3.body.minConfidence || 0)) - return null; - fixKeypoints(keypointsRelative); - const keypoints = rescaleKeypoints(keypointsRelative, outputSize2); - const kpts = keypoints.map((k) => k.position); - const boxes = calc(kpts, [outputSize2[0], outputSize2[1]]); - const annotations2 = {}; - for (const [name, indexes] of Object.entries(connected)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = keypoints.find((kpt4) => kpt4.part === indexes[i]); - const pt1 = keypoints.find((kpt4) => kpt4.part === indexes[i + 1]); - if (pt0 && pt1) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - const body4 = { id: 0, score: Math.trunc(100 * poseScore) / 100, box: boxes.box, boxRaw: boxes.boxRaw, keypoints, annotations: annotations2 }; - return body4; -} -async function predict(input, config3) { - var _a, _b, _c; - const outputSize2 = [input.shape[2] || 0, input.shape[1] || 0]; - const skipTime = (config3.body.skipTime || 0) > now() - lastTime; - const skipFrame = skipped < (config3.body.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && cache !== null) { - skipped++; - } else { - let boxes = []; - if ((_b = (_a = config3.body) == null ? void 0 : _a["detector"]) == null ? void 0 : _b["enabled"]) { - const preparedImage = prepareImage(input, 224); - boxes = await detectBoxes(preparedImage, config3, outputSize2); - tf9.dispose(preparedImage); - } else { - boxes = [{ box: [0, 0, 0, 0], boxRaw: [0, 0, 1, 1], score: 0 }]; - } - for (let i = 0; i < boxes.length; i++) { - const preparedBox = prepareImage(input, 256, (_c = boxes[i]) == null ? void 0 : _c.boxRaw); - cache.length = 0; - const bodyResult = await detectLandmarks(preparedBox, config3, outputSize2); - tf9.dispose(preparedBox); - if (!bodyResult) - continue; - bodyResult.id = i; - cache.push(bodyResult); - } - lastTime = now(); - skipped = 0; - } - return cache; -} - -// src/object/centernet.ts -var tf10 = __toESM(require_tfjs_esm()); - -// src/object/labels.ts -var labels2 = [ - { class: 1, label: "person" }, - { class: 2, label: "bicycle" }, - { class: 3, label: "car" }, - { class: 4, label: "motorcycle" }, - { class: 5, label: "airplane" }, - { class: 6, label: "bus" }, - { class: 7, label: "train" }, - { class: 8, label: "truck" }, - { class: 9, label: "boat" }, - { class: 10, label: "traffic light" }, - { class: 11, label: "fire hydrant" }, - { class: 12, label: "stop sign" }, - { class: 13, label: "parking meter" }, - { class: 14, label: "bench" }, - { class: 15, label: "bird" }, - { class: 16, label: "cat" }, - { class: 17, label: "dog" }, - { class: 18, label: "horse" }, - { class: 19, label: "sheep" }, - { class: 20, label: "cow" }, - { class: 21, label: "elephant" }, - { class: 22, label: "bear" }, - { class: 23, label: "zebra" }, - { class: 24, label: "giraffe" }, - { class: 25, label: "backpack" }, - { class: 26, label: "umbrella" }, - { class: 27, label: "handbag" }, - { class: 28, label: "tie" }, - { class: 29, label: "suitcase" }, - { class: 30, label: "frisbee" }, - { class: 31, label: "skis" }, - { class: 32, label: "snowboard" }, - { class: 33, label: "sports ball" }, - { class: 34, label: "kite" }, - { class: 35, label: "baseball bat" }, - { class: 36, label: "baseball glove" }, - { class: 37, label: "skateboard" }, - { class: 38, label: "surfboard" }, - { class: 39, label: "tennis racket" }, - { class: 40, label: "bottle" }, - { class: 41, label: "wine glass" }, - { class: 42, label: "cup" }, - { class: 43, label: "fork" }, - { class: 44, label: "knife" }, - { class: 45, label: "spoon" }, - { class: 46, label: "bowl" }, - { class: 47, label: "banana" }, - { class: 48, label: "apple" }, - { class: 49, label: "sandwich" }, - { class: 50, label: "orange" }, - { class: 51, label: "broccoli" }, - { class: 52, label: "carrot" }, - { class: 53, label: "hot dog" }, - { class: 54, label: "pizza" }, - { class: 55, label: "donut" }, - { class: 56, label: "cake" }, - { class: 57, label: "chair" }, - { class: 58, label: "couch" }, - { class: 59, label: "potted plant" }, - { class: 60, label: "bed" }, - { class: 61, label: "dining table" }, - { class: 62, label: "toilet" }, - { class: 63, label: "tv" }, - { class: 64, label: "laptop" }, - { class: 65, label: "mouse" }, - { class: 66, label: "remote" }, - { class: 67, label: "keyboard" }, - { class: 68, label: "cell phone" }, - { class: 69, label: "microwave" }, - { class: 70, label: "oven" }, - { class: 71, label: "toaster" }, - { class: 72, label: "sink" }, - { class: 73, label: "refrigerator" }, - { class: 74, label: "book" }, - { class: 75, label: "clock" }, - { class: 76, label: "vase" }, - { class: 77, label: "scissors" }, - { class: 78, label: "teddy bear" }, - { class: 79, label: "hair drier" }, - { class: 80, label: "toothbrush" } -]; - -// src/object/centernet.ts -var model3; -var inputSize3 = 0; -var last2 = []; -var lastTime2 = 0; -var skipped2 = Number.MAX_SAFE_INTEGER; -async function load(config3) { - if (env.initial) - model3 = null; - if (!model3) { - model3 = await loadModel(config3.object.modelPath); - const inputs = (model3 == null ? void 0 : model3["executor"]) ? Object.values(model3.modelSignature["inputs"]) : void 0; - inputSize3 = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 0; - } else if (config3.debug) - log("cached model:", model3["modelUrl"]); - return model3; -} -async function process3(res, outputShape, config3) { - if (!res) - return []; - const t2 = {}; - const results = []; - const detections = await res.array(); - t2.squeeze = tf10.squeeze(res); - const arr = tf10.split(t2.squeeze, 6, 1); - t2.stack = tf10.stack([arr[1], arr[0], arr[3], arr[2]], 1); - t2.boxes = tf10.squeeze(t2.stack); - t2.scores = tf10.squeeze(arr[4]); - t2.classes = tf10.squeeze(arr[5]); - tf10.dispose([res, ...arr]); - t2.nms = await tf10.image.nonMaxSuppressionAsync(t2.boxes, t2.scores, config3.object.maxDetected || 0, config3.object.iouThreshold, config3.object.minConfidence || 0); - const nms = await t2.nms.data(); - let i = 0; - for (const id of Array.from(nms)) { - const score = Math.trunc(100 * detections[0][id][4]) / 100; - const classVal = detections[0][id][5]; - if (Number.isNaN(classVal)) - continue; - const label = labels2[classVal].label; - const [x, y] = [ - detections[0][id][0] / inputSize3, - detections[0][id][1] / inputSize3 - ]; - const boxRaw = [ - x, - y, - detections[0][id][2] / inputSize3 - x, - detections[0][id][3] / inputSize3 - y - ]; - const box = [ - Math.trunc(boxRaw[0] * outputShape[0]), - Math.trunc(boxRaw[1] * outputShape[1]), - Math.trunc(boxRaw[2] * outputShape[0]), - Math.trunc(boxRaw[3] * outputShape[1]) - ]; - results.push({ id: i++, score, class: classVal, label, box, boxRaw }); - } - Object.keys(t2).forEach((tensor6) => tf10.dispose(t2[tensor6])); - return results; -} -async function predict2(input, config3) { - if (!(model3 == null ? void 0 : model3["executor"])) - return []; - const skipTime = (config3.object.skipTime || 0) > now() - lastTime2; - const skipFrame = skipped2 < (config3.object.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && last2.length > 0) { - skipped2++; - return last2; - } - skipped2 = 0; - return new Promise(async (resolve) => { - const outputSize2 = [input.shape[2] || 0, input.shape[1] || 0]; - const resize = tf10.image.resizeBilinear(input, [inputSize3, inputSize3]); - const objectT = config3.object.enabled ? model3 == null ? void 0 : model3.execute(resize, ["tower_0/detections"]) : null; - lastTime2 = now(); - tf10.dispose(resize); - const obj = await process3(objectT, outputSize2, config3); - last2 = obj; - resolve(obj); - }); -} - -// src/body/efficientpose.ts -var tf11 = __toESM(require_tfjs_esm()); - -// src/body/efficientposecoords.ts -var efficientposecoords_exports = {}; -__export(efficientposecoords_exports, { - connected: () => connected2, - kpt: () => kpt2 -}); -var kpt2 = [ - "head", - "neck", - "rightShoulder", - "rightElbow", - "rightWrist", - "chest", - "leftShoulder", - "leftElbow", - "leftWrist", - "bodyCenter", - "rightHip", - "rightKnee", - "rightAnkle", - "leftHip", - "leftKnee", - "leftAnkle" -]; -var connected2 = { - leftLeg: ["leftHip", "leftKnee", "leftAnkle"], - rightLeg: ["rightHip", "rightKnee", "rightAnkle"], - torso: ["leftShoulder", "rightShoulder", "rightHip", "leftHip", "leftShoulder"], - leftArm: ["leftShoulder", "leftElbow", "leftWrist"], - rightArm: ["rightShoulder", "rightElbow", "rightWrist"], - head: [] -}; - -// src/body/efficientpose.ts -var model4; -var lastTime3 = 0; -var cache2 = { id: 0, keypoints: [], box: [0, 0, 0, 0], boxRaw: [0, 0, 0, 0], score: 0, annotations: {} }; -var skipped3 = Number.MAX_SAFE_INTEGER; -async function load2(config3) { - if (env.initial) - model4 = null; - if (!model4) - model4 = await loadModel(config3.body.modelPath); - else if (config3.debug) - log("cached model:", model4["modelUrl"]); - return model4; -} -async function max2d(inputs, minScore) { - const [width, height] = inputs.shape; - const reshaped = tf11.reshape(inputs, [height * width]); - const max5 = tf11.max(reshaped, 0); - const newScore = (await max5.data())[0]; - if (newScore > minScore) { - const coordinates = tf11.argMax(reshaped, 0); - const mod3 = tf11.mod(coordinates, width); - const x = (await mod3.data())[0]; - const div15 = tf11.div(coordinates, width); - const y = (await div15.data())[0]; - tf11.dispose([reshaped, max5, coordinates, mod3, div15]); - return [x, y, newScore]; - } - tf11.dispose([reshaped, max5]); - return [0, 0, newScore]; -} -async function predict3(image28, config3) { - if (!(model4 == null ? void 0 : model4["executor"]) || !(model4 == null ? void 0 : model4.inputs[0].shape)) - return []; - const skipTime = (config3.body.skipTime || 0) > now() - lastTime3; - const skipFrame = skipped3 < (config3.body.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && Object.keys(cache2.keypoints).length > 0) { - skipped3++; - return [cache2]; - } - skipped3 = 0; - return new Promise(async (resolve) => { - const tensor6 = tf11.tidy(() => { - var _a, _b; - const resize = tf11.image.resizeBilinear(image28, [((_a = model4 == null ? void 0 : model4.inputs[0].shape) == null ? void 0 : _a[2]) || 0, ((_b = model4 == null ? void 0 : model4.inputs[0].shape) == null ? void 0 : _b[1]) || 0], false); - const enhance2 = tf11.mul(resize, constants.tf2); - const norm = tf11.sub(enhance2, constants.tf1); - return norm; - }); - let resT; - if (config3.body.enabled) - resT = model4 == null ? void 0 : model4.execute(tensor6); - lastTime3 = now(); - tf11.dispose(tensor6); - if (resT) { - cache2.keypoints.length = 0; - const squeeze14 = tf11.squeeze(resT); - tf11.dispose(resT); - const stack5 = tf11.unstack(squeeze14, 2); - tf11.dispose(squeeze14); - for (let id = 0; id < stack5.length; id++) { - const [x2, y2, partScore] = await max2d(stack5[id], config3.body.minConfidence); - if (partScore > (config3.body.minConfidence || 0)) { - cache2.keypoints.push({ - score: Math.round(100 * partScore) / 100, - part: kpt2[id], - positionRaw: [ - x2 / model4.inputs[0].shape[2], - y2 / model4.inputs[0].shape[1] - ], - position: [ - Math.round(image28.shape[2] * x2 / model4.inputs[0].shape[2]), - Math.round(image28.shape[1] * y2 / model4.inputs[0].shape[1]) - ] - }); - } - } - stack5.forEach((s) => tf11.dispose(s)); - } - cache2.score = cache2.keypoints.reduce((prev, curr) => curr.score > prev ? curr.score : prev, 0); - const x = cache2.keypoints.map((a) => a.position[0]); - const y = cache2.keypoints.map((a) => a.position[1]); - cache2.box = [ - Math.min(...x), - Math.min(...y), - Math.max(...x) - Math.min(...x), - Math.max(...y) - Math.min(...y) - ]; - const xRaw = cache2.keypoints.map((a) => a.positionRaw[0]); - const yRaw = cache2.keypoints.map((a) => a.positionRaw[1]); - cache2.boxRaw = [ - Math.min(...xRaw), - Math.min(...yRaw), - Math.max(...xRaw) - Math.min(...xRaw), - Math.max(...yRaw) - Math.min(...yRaw) - ]; - for (const [name, indexes] of Object.entries(connected2)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = cache2.keypoints.find((kpt4) => kpt4.part === indexes[i]); - const pt1 = cache2.keypoints.find((kpt4) => kpt4.part === indexes[i + 1]); - if (pt0 && pt1 && pt0.score > (config3.body.minConfidence || 0) && pt1.score > (config3.body.minConfidence || 0)) - pt.push([pt0.position, pt1.position]); - } - cache2.annotations[name] = pt; - } - resolve([cache2]); - }); -} - -// src/face/face.ts -var tf25 = __toESM(require_tfjs_esm()); - -// src/face/facemesh.ts -var tf15 = __toESM(require_tfjs_esm()); - -// src/face/blazeface.ts -var tf13 = __toESM(require_tfjs_esm()); - -// src/face/facemeshutil.ts -var tf12 = __toESM(require_tfjs_esm()); -var getBoxSize = (box) => [Math.abs(box.endPoint[0] - box.startPoint[0]), Math.abs(box.endPoint[1] - box.startPoint[1])]; -var getBoxCenter = (box) => [box.startPoint[0] + (box.endPoint[0] - box.startPoint[0]) / 2, box.startPoint[1] + (box.endPoint[1] - box.startPoint[1]) / 2, 1]; -var clampBox = (box, input) => box ? [ - Math.trunc(Math.max(0, box.startPoint[0])), - Math.trunc(Math.max(0, box.startPoint[1])), - Math.trunc(Math.min(input.shape[2] || 0, box.endPoint[0]) - Math.max(0, box.startPoint[0])), - Math.trunc(Math.min(input.shape[1] || 0, box.endPoint[1]) - Math.max(0, box.startPoint[1])) -] : [0, 0, 0, 0]; -var getRawBox = (box, input) => box ? [ - box.startPoint[0] / (input.shape[2] || 0), - box.startPoint[1] / (input.shape[1] || 0), - (box.endPoint[0] - box.startPoint[0]) / (input.shape[2] || 0), - (box.endPoint[1] - box.startPoint[1]) / (input.shape[1] || 0) -] : [0, 0, 0, 0]; -var scaleBoxCoordinates = (box, factor) => { - const startPoint = [box.startPoint[0] * factor[0], box.startPoint[1] * factor[1]]; - const endPoint = [box.endPoint[0] * factor[0], box.endPoint[1] * factor[1]]; - return { startPoint, endPoint, landmarks: box.landmarks, confidence: box.confidence }; -}; -var cutAndResize = (box, image28, cropSize) => { - const h = image28.shape[1]; - const w = image28.shape[2]; - const cutBox = [box.startPoint[1] / h, box.startPoint[0] / w, box.endPoint[1] / h, box.endPoint[0] / w]; - const crop = tf12.image.cropAndResize(image28, [cutBox], [0], cropSize); - const norm = tf12.div(crop, constants.tf255); - tf12.dispose(crop); - return norm; -}; -var enlargeBox = (box, factor) => { - const center = getBoxCenter(box); - const size2 = getBoxSize(box); - const halfSize = [factor * size2[0] / 2, factor * size2[1] / 2]; - return { startPoint: [center[0] - halfSize[0], center[1] - halfSize[1]], endPoint: [center[0] + halfSize[0], center[1] + halfSize[1]], landmarks: box.landmarks, confidence: box.confidence }; -}; -var squarifyBox = (box) => { - const centers = getBoxCenter(box); - const size2 = getBoxSize(box); - const halfSize = Math.max(...size2) / 2; - return { startPoint: [Math.round(centers[0] - halfSize), Math.round(centers[1] - halfSize)], endPoint: [Math.round(centers[0] + halfSize), Math.round(centers[1] + halfSize)], landmarks: box.landmarks, confidence: box.confidence }; -}; -var calculateLandmarksBoundingBox = (landmarks) => { - const x = landmarks.map((d) => d[0]); - const y = landmarks.map((d) => d[1]); - return { startPoint: [Math.min(...x), Math.min(...y)], endPoint: [Math.max(...x), Math.max(...y)], landmarks }; -}; -var fixedRotationMatrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; -var normalizeRadians = (angle) => angle - 2 * Math.PI * Math.floor((angle + Math.PI) / (2 * Math.PI)); -var computeRotation = (point1, point2) => normalizeRadians(Math.PI / 2 - Math.atan2(-(point2[1] - point1[1]), point2[0] - point1[0])); -var buildTranslationMatrix = (x, y) => [[1, 0, x], [0, 1, y], [0, 0, 1]]; -var dot = (v1, v2) => { - let product = 0; - for (let i = 0; i < v1.length; i++) - product += v1[i] * v2[i]; - return product; -}; -var getColumnFrom2DArr = (arr, columnIndex) => { - const column = []; - for (let i = 0; i < arr.length; i++) - column.push(arr[i][columnIndex]); - return column; -}; -var multiplyTransformMatrices = (mat1, mat2) => { - const product = []; - const size2 = mat1.length; - for (let row = 0; row < size2; row++) { - product.push([]); - for (let col = 0; col < size2; col++) - product[row].push(dot(mat1[row], getColumnFrom2DArr(mat2, col))); - } - return product; -}; -var buildRotationMatrix = (rotation, center) => { - const cosA = Math.cos(rotation); - const sinA = Math.sin(rotation); - const rotationMatrix = [[cosA, -sinA, 0], [sinA, cosA, 0], [0, 0, 1]]; - const translationMatrix = buildTranslationMatrix(center[0], center[1]); - const translationTimesRotation = multiplyTransformMatrices(translationMatrix, rotationMatrix); - const negativeTranslationMatrix = buildTranslationMatrix(-center[0], -center[1]); - return multiplyTransformMatrices(translationTimesRotation, negativeTranslationMatrix); -}; -var invertTransformMatrix = (matrix) => { - const rotationComponent = [[matrix[0][0], matrix[1][0]], [matrix[0][1], matrix[1][1]]]; - const translationComponent = [matrix[0][2], matrix[1][2]]; - const invertedTranslation = [-dot(rotationComponent[0], translationComponent), -dot(rotationComponent[1], translationComponent)]; - return [rotationComponent[0].concat(invertedTranslation[0]), rotationComponent[1].concat(invertedTranslation[1]), [0, 0, 1]]; -}; -var rotatePoint = (homogeneousCoordinate, rotationMatrix) => [dot(homogeneousCoordinate, rotationMatrix[0]), dot(homogeneousCoordinate, rotationMatrix[1])]; -function generateAnchors(inputSize10) { - const spec = inputSize10 === 192 ? { strides: [4], anchors: [1] } : { strides: [inputSize10 / 16, inputSize10 / 8], anchors: [2, 6] }; - const anchors3 = []; - for (let i = 0; i < spec.strides.length; i++) { - const stride = spec.strides[i]; - const gridRows = Math.floor((inputSize10 + stride - 1) / stride); - const gridCols = Math.floor((inputSize10 + stride - 1) / stride); - const anchorsNum = spec.anchors[i]; - for (let gridY = 0; gridY < gridRows; gridY++) { - const anchorY = stride * (gridY + 0.5); - for (let gridX = 0; gridX < gridCols; gridX++) { - const anchorX = stride * (gridX + 0.5); - for (let n = 0; n < anchorsNum; n++) - anchors3.push([anchorX, anchorY]); - } - } - } - return anchors3; -} -function transformRawCoords(coordsRaw, box, angle, rotationMatrix, inputSize10) { - const boxSize = getBoxSize(box); - const coordsScaled = coordsRaw.map((coord) => [ - boxSize[0] / inputSize10 * (coord[0] - inputSize10 / 2), - boxSize[1] / inputSize10 * (coord[1] - inputSize10 / 2), - coord[2] || 0 - ]); - const largeAngle = angle && angle !== 0 && Math.abs(angle) > 0.2; - const coordsRotationMatrix = largeAngle ? buildRotationMatrix(angle, [0, 0]) : fixedRotationMatrix; - const coordsRotated = largeAngle ? coordsScaled.map((coord) => [...rotatePoint(coord, coordsRotationMatrix), coord[2]]) : coordsScaled; - const inverseRotationMatrix = largeAngle ? invertTransformMatrix(rotationMatrix) : fixedRotationMatrix; - const boxCenter = getBoxCenter(box); - const offsets = [dot(boxCenter, inverseRotationMatrix[0]), dot(boxCenter, inverseRotationMatrix[1])]; - return coordsRotated.map((coord) => [ - Math.trunc(coord[0] + offsets[0]), - Math.trunc(coord[1] + offsets[1]), - Math.trunc(coord[2] || 0) - ]); -} -function correctFaceRotation(rotate, box, input, inputSize10) { - const symmetryLine = box.landmarks.length >= meshLandmarks.count ? meshLandmarks.symmetryLine : blazeFaceLandmarks.symmetryLine; - let angle = 0; - let rotationMatrix = fixedRotationMatrix; - let face4; - if (rotate && env.kernels.includes("rotatewithoffset")) { - angle = computeRotation(box.landmarks[symmetryLine[0]], box.landmarks[symmetryLine[1]]); - const largeAngle = angle && angle !== 0 && Math.abs(angle) > 0.2; - if (largeAngle) { - const center = getBoxCenter(box); - const centerRaw = [center[0] / input.shape[2], center[1] / input.shape[1]]; - const rotated = tf12.image.rotateWithOffset(input, angle, 0, [centerRaw[0], centerRaw[1]]); - rotationMatrix = buildRotationMatrix(-angle, center); - face4 = cutAndResize(box, rotated, [inputSize10, inputSize10]); - tf12.dispose(rotated); - } else { - face4 = cutAndResize(box, input, [inputSize10, inputSize10]); - } - } else { - face4 = cutAndResize(box, input, [inputSize10, inputSize10]); - } - return [angle, rotationMatrix, face4]; -} -var findFaceCenter = (mesh) => { - const x = mesh.map((m) => m[0]); - const y = mesh.map((m) => m[1]); - return [Math.min(...x) + (Math.max(...x) - Math.min(...x)) / 2, Math.min(...y) + (Math.max(...y) - Math.min(...y)) / 2]; -}; -var calculateFaceBox = (mesh, previousBox) => { - const center = findFaceCenter(mesh); - const boxSize = getBoxSize(previousBox); - const calculatedBox = { - startPoint: [center[0] - boxSize[0] / 2, center[1] - boxSize[1] / 2], - endPoint: [center[0] + boxSize[0] / 2, center[1] + boxSize[1] / 2] - }; - return calculatedBox; -}; - -// src/face/blazeface.ts -var keypointsCount = 6; -var faceBoxScaleFactor = 1.4; -var model5; -var anchors = null; -var inputSize4 = 0; -var inputSizeT = null; -var size = () => inputSize4; -async function load3(config3) { - var _a; - if (env.initial) - model5 = null; - if (!model5) - model5 = await loadModel((_a = config3.face.detector) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model5["modelUrl"]); - inputSize4 = model5["executor"] && model5.inputs[0].shape ? model5.inputs[0].shape[2] : 256; - inputSizeT = tf13.scalar(inputSize4, "int32"); - anchors = tf13.tensor2d(generateAnchors(inputSize4)); - return model5; -} -function decodeBoxes2(boxOutputs) { - if (!anchors || !inputSizeT) - return tf13.zeros([0, 0]); - const t2 = {}; - t2.boxStarts = tf13.slice(boxOutputs, [0, 1], [-1, 2]); - t2.centers = tf13.add(t2.boxStarts, anchors); - t2.boxSizes = tf13.slice(boxOutputs, [0, 3], [-1, 2]); - t2.boxSizesNormalized = tf13.div(t2.boxSizes, inputSizeT); - t2.centersNormalized = tf13.div(t2.centers, inputSizeT); - t2.halfBoxSize = tf13.div(t2.boxSizesNormalized, constants.tf2); - t2.starts = tf13.sub(t2.centersNormalized, t2.halfBoxSize); - t2.ends = tf13.add(t2.centersNormalized, t2.halfBoxSize); - t2.startNormalized = tf13.mul(t2.starts, inputSizeT); - t2.endNormalized = tf13.mul(t2.ends, inputSizeT); - const boxes = tf13.concat2d([t2.startNormalized, t2.endNormalized], 1); - Object.keys(t2).forEach((tensor6) => tf13.dispose(t2[tensor6])); - return boxes; -} -async function getBoxes(inputImage, config3) { - var _a, _b, _c, _d; - if (!inputImage || inputImage["isDisposedInternal"] || inputImage.shape.length !== 4 || inputImage.shape[1] < 1 || inputImage.shape[2] < 1) - return []; - const t2 = {}; - t2.resized = tf13.image.resizeBilinear(inputImage, [inputSize4, inputSize4]); - t2.div = tf13.div(t2.resized, constants.tf127); - t2.normalized = tf13.sub(t2.div, constants.tf05); - const res = model5 == null ? void 0 : model5.execute(t2.normalized); - if (Array.isArray(res) && res.length > 2) { - const sorted = res.sort((a, b) => a.size - b.size); - t2.concat384 = tf13.concat([sorted[0], sorted[2]], 2); - t2.concat512 = tf13.concat([sorted[1], sorted[3]], 2); - t2.concat = tf13.concat([t2.concat512, t2.concat384], 1); - t2.batch = tf13.squeeze(t2.concat, [0]); - } else if (Array.isArray(res)) { - t2.batch = tf13.squeeze(res[0]); - } else { - t2.batch = tf13.squeeze(res); - } - tf13.dispose(res); - t2.boxes = decodeBoxes2(t2.batch); - t2.logits = tf13.slice(t2.batch, [0, 0], [-1, 1]); - t2.sigmoid = tf13.sigmoid(t2.logits); - t2.scores = tf13.squeeze(t2.sigmoid); - t2.nms = await tf13.image.nonMaxSuppressionAsync(t2.boxes, t2.scores, ((_a = config3.face.detector) == null ? void 0 : _a.maxDetected) || 0, ((_b = config3.face.detector) == null ? void 0 : _b.iouThreshold) || 0, ((_c = config3.face.detector) == null ? void 0 : _c.minConfidence) || 0); - const nms = await t2.nms.array(); - const boxes = []; - const scores = await t2.scores.data(); - for (let i = 0; i < nms.length; i++) { - const confidence = scores[nms[i]]; - if (confidence > (((_d = config3.face.detector) == null ? void 0 : _d.minConfidence) || 0)) { - const b = {}; - b.bbox = tf13.slice(t2.boxes, [nms[i], 0], [1, -1]); - b.slice = tf13.slice(t2.batch, [nms[i], keypointsCount - 1], [1, -1]); - b.squeeze = tf13.squeeze(b.slice); - b.landmarks = tf13.reshape(b.squeeze, [keypointsCount, -1]); - const points = await b.bbox.data(); - const rawBox = { - startPoint: [points[0], points[1]], - endPoint: [points[2], points[3]], - landmarks: await b.landmarks.array(), - confidence - }; - const scaledBox = scaleBoxCoordinates(rawBox, [(inputImage.shape[2] || 0) / inputSize4, (inputImage.shape[1] || 0) / inputSize4]); - const enlargedBox = enlargeBox(scaledBox, config3.face["scale"] || faceBoxScaleFactor); - const squaredBox = squarifyBox(enlargedBox); - boxes.push(squaredBox); - Object.keys(b).forEach((tensor6) => tf13.dispose(b[tensor6])); - } - } - Object.keys(t2).forEach((tensor6) => tf13.dispose(t2[tensor6])); - return boxes; -} - -// src/face/iris.ts -var tf14 = __toESM(require_tfjs_esm()); -var model6; -var inputSize5 = 0; -var irisEnlarge = 2.3; -var leftOutline = meshAnnotations.leftEyeLower0; -var rightOutline = meshAnnotations.rightEyeLower0; -var eyeLandmarks = { - leftBounds: [leftOutline[0], leftOutline[leftOutline.length - 1]], - rightBounds: [rightOutline[0], rightOutline[rightOutline.length - 1]] -}; -var irisLandmarks = { - upperCenter: 3, - lowerCenter: 4, - index: 71, - numCoordinates: 76 -}; -async function load4(config3) { - var _a, _b; - if (env.initial) - model6 = null; - if (!model6) - model6 = await loadModel((_a = config3.face.iris) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model6["modelUrl"]); - inputSize5 = (model6 == null ? void 0 : model6["executor"]) && ((_b = model6.inputs) == null ? void 0 : _b[0].shape) ? model6.inputs[0].shape[2] : 0; - if (inputSize5 === -1) - inputSize5 = 64; - return model6; -} -function replaceIrisCoords(rawCoords, newCoords, prefix, keys) { - for (let i = 0; i < irisIndices.length; i++) { - const { key, indices } = irisIndices[i]; - const originalIndices = meshAnnotations[`${prefix}${key}`]; - if (!keys || keys.includes(key)) { - for (let j = 0; j < indices.length; j++) { - const index2 = indices[j]; - rawCoords[originalIndices[j]] = [ - newCoords[index2][0], - newCoords[index2][1], - (newCoords[index2][2] + rawCoords[originalIndices[j]][2]) / 2 - ]; - } - } - } -} -var getLeftToRightEyeDepthDifference = (rawCoords) => { - const leftEyeZ = rawCoords[eyeLandmarks.leftBounds[0]][2]; - const rightEyeZ = rawCoords[eyeLandmarks.rightBounds[0]][2]; - return leftEyeZ - rightEyeZ; -}; -var getEyeBox = (rawCoords, face4, eyeInnerCornerIndex, eyeOuterCornerIndex, meshSize, flip = false) => { - const box = squarifyBox(enlargeBox(calculateLandmarksBoundingBox([rawCoords[eyeInnerCornerIndex], rawCoords[eyeOuterCornerIndex]]), irisEnlarge)); - const boxSize = getBoxSize(box); - let crop = tf14.image.cropAndResize(face4, [[ - box.startPoint[1] / meshSize, - box.startPoint[0] / meshSize, - box.endPoint[1] / meshSize, - box.endPoint[0] / meshSize - ]], [0], [inputSize5, inputSize5]); - if (flip && env.kernels.includes("flipleftright")) { - const flipped = tf14.image.flipLeftRight(crop); - tf14.dispose(crop); - crop = flipped; - } - return { box, boxSize, crop }; -}; -var getEyeCoords = (eyeData, eyeBox, eyeBoxSize, flip = false) => { - const eyeRawCoords = []; - for (let i = 0; i < irisLandmarks.numCoordinates; i++) { - const x = eyeData[i * 3]; - const y = eyeData[i * 3 + 1]; - const z = eyeData[i * 3 + 2]; - eyeRawCoords.push([ - (flip ? 1 - x / inputSize5 : x / inputSize5) * eyeBoxSize[0] + eyeBox.startPoint[0], - y / inputSize5 * eyeBoxSize[1] + eyeBox.startPoint[1], - z - ]); - } - return { rawCoords: eyeRawCoords, iris: eyeRawCoords.slice(irisLandmarks.index) }; -}; -var getAdjustedIrisCoords = (rawCoords, irisCoords, direction) => { - const upperCenterZ = rawCoords[meshAnnotations[`${direction}EyeUpper0`][irisLandmarks.upperCenter]][2]; - const lowerCenterZ = rawCoords[meshAnnotations[`${direction}EyeLower0`][irisLandmarks.lowerCenter]][2]; - const averageZ = (upperCenterZ + lowerCenterZ) / 2; - return irisCoords.map((coord, i) => { - let z = averageZ; - if (i === 2) { - z = upperCenterZ; - } else if (i === 4) { - z = lowerCenterZ; - } - return [coord[0], coord[1], z]; - }); -}; -async function augmentIris(rawCoords, face4, meshSize) { - if (!(model6 == null ? void 0 : model6["executor"])) - return rawCoords; - const { box: leftEyeBox, boxSize: leftEyeBoxSize, crop: leftEyeCrop } = getEyeBox(rawCoords, face4, eyeLandmarks.leftBounds[0], eyeLandmarks.leftBounds[1], meshSize, true); - const { box: rightEyeBox, boxSize: rightEyeBoxSize, crop: rightEyeCrop } = getEyeBox(rawCoords, face4, eyeLandmarks.rightBounds[0], eyeLandmarks.rightBounds[1], meshSize, true); - const combined = tf14.concat([leftEyeCrop, rightEyeCrop]); - tf14.dispose(leftEyeCrop); - tf14.dispose(rightEyeCrop); - const eyePredictions = model6.execute(combined); - tf14.dispose(combined); - const eyePredictionsData = await eyePredictions.data(); - tf14.dispose(eyePredictions); - const leftEyeData = eyePredictionsData.slice(0, irisLandmarks.numCoordinates * 3); - const { rawCoords: leftEyeRawCoords, iris: leftIrisRawCoords } = getEyeCoords(leftEyeData, leftEyeBox, leftEyeBoxSize, true); - const rightEyeData = eyePredictionsData.slice(irisLandmarks.numCoordinates * 3); - const { rawCoords: rightEyeRawCoords, iris: rightIrisRawCoords } = getEyeCoords(rightEyeData, rightEyeBox, rightEyeBoxSize, false); - const leftToRightEyeDepthDifference = getLeftToRightEyeDepthDifference(rawCoords); - if (Math.abs(leftToRightEyeDepthDifference) < 30) { - replaceIrisCoords(rawCoords, leftEyeRawCoords, "left", null); - replaceIrisCoords(rawCoords, rightEyeRawCoords, "right", null); - } else if (leftToRightEyeDepthDifference < 1) { - replaceIrisCoords(rawCoords, leftEyeRawCoords, "left", ["EyeUpper0", "EyeLower0"]); - } else { - replaceIrisCoords(rawCoords, rightEyeRawCoords, "right", ["EyeUpper0", "EyeLower0"]); - } - const adjustedLeftIrisCoords = getAdjustedIrisCoords(rawCoords, leftIrisRawCoords, "left"); - const adjustedRightIrisCoords = getAdjustedIrisCoords(rawCoords, rightIrisRawCoords, "right"); - const newCoords = rawCoords.concat(adjustedLeftIrisCoords).concat(adjustedRightIrisCoords); - return newCoords; -} - -// src/face/attention.ts -async function augment(rawCoords, results) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; - const t2 = { - lips: await ((_b = (_a = results.filter((r) => r.size === 160)) == null ? void 0 : _a[0]) == null ? void 0 : _b.data()), - irisL: await ((_d = (_c = results.filter((r) => r.size === 10)) == null ? void 0 : _c[0]) == null ? void 0 : _d.data()), - eyeL: await ((_f = (_e = results.filter((r) => r.size === 142)) == null ? void 0 : _e[0]) == null ? void 0 : _f.data()), - irisR: await ((_h = (_g = results.filter((r) => r.size === 10)) == null ? void 0 : _g[1]) == null ? void 0 : _h.data()), - eyeR: await ((_j = (_i = results.filter((r) => r.size === 142)) == null ? void 0 : _i[1]) == null ? void 0 : _j.data()) - }; - for (const val of Object.values(t2)) { - if (!val) - return rawCoords; - } - const irisLDepth = LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG.reduce((prev, curr) => prev += rawCoords[curr][2], 0) / LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG.length; - for (let i = 0; i < t2.irisL.length / 2; i++) - rawCoords.push([t2.irisL[2 * i + 0], t2.irisL[2 * i + 1], irisLDepth]); - const irisRDepth = LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG.reduce((prev, curr) => prev += rawCoords[curr][2], 0) / LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG.length; - for (let i = 0; i < t2.irisR.length / 2; i++) - rawCoords.push([t2.irisR[2 * i + 0], t2.irisR[2 * i + 1], irisRDepth]); - for (let i = 0; i < t2.eyeL.length / 2; i++) - rawCoords[LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG[i]] = [t2.eyeL[2 * i + 0], t2.eyeL[2 * i + 1], rawCoords[LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG[i]][2]]; - for (let i = 0; i < t2.eyeR.length / 2; i++) - rawCoords[LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG[i]] = [t2.eyeR[2 * i + 0], t2.eyeR[2 * i + 1], rawCoords[LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG[i]][2]]; - for (let i = 0; i < t2.lips.length / 2; i++) - rawCoords[LANDMARKS_REFINEMENT_LIPS_CONFIG[i]] = [t2.lips[2 * i + 0], t2.lips[2 * i + 1], rawCoords[LANDMARKS_REFINEMENT_LIPS_CONFIG[i]][2]]; - return rawCoords; -} - -// src/face/facemesh.ts -var cache3 = { - boxes: [], - skipped: Number.MAX_SAFE_INTEGER, - timestamp: 0 -}; -var model7 = null; -var inputSize6 = 0; -async function predict4(input, config3) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; - if (!(model7 == null ? void 0 : model7["executor"])) - return []; - const skipTime = (((_a = config3.face.detector) == null ? void 0 : _a.skipTime) || 0) > now() - cache3.timestamp; - const skipFrame = cache3.skipped < (((_b = config3.face.detector) == null ? void 0 : _b.skipFrames) || 0); - if (!config3.skipAllowed || !skipTime || !skipFrame || cache3.boxes.length === 0) { - cache3.boxes = await getBoxes(input, config3); - cache3.timestamp = now(); - cache3.skipped = 0; - } else { - cache3.skipped++; - } - const faces = []; - const newCache = []; - let id = 0; - const size2 = inputSize6; - for (let i = 0; i < cache3.boxes.length; i++) { - const box = cache3.boxes[i]; - let angle = 0; - let rotationMatrix; - const face4 = { - id: id++, - mesh: [], - meshRaw: [], - box: [0, 0, 0, 0], - boxRaw: [0, 0, 0, 0], - score: 0, - boxScore: 0, - faceScore: 0, - annotations: {} - }; - [angle, rotationMatrix, face4.tensor] = correctFaceRotation((_c = config3.face.detector) == null ? void 0 : _c.rotation, box, input, ((_d = config3.face.mesh) == null ? void 0 : _d.enabled) ? inputSize6 : size()); - if (config3.filter.equalization) { - const equilized = face4.tensor ? await histogramEqualization(face4.tensor) : void 0; - tf15.dispose(face4.tensor); - if (equilized) - face4.tensor = equilized; - } - face4.boxScore = Math.round(100 * box.confidence) / 100; - if (!((_e = config3.face.mesh) == null ? void 0 : _e.enabled)) { - face4.box = clampBox(box, input); - face4.boxRaw = getRawBox(box, input); - face4.score = face4.boxScore; - face4.mesh = box.landmarks.map((pt) => [ - (box.startPoint[0] + box.endPoint[0]) / 2 + (box.endPoint[0] + box.startPoint[0]) * pt[0] / size(), - (box.startPoint[1] + box.endPoint[1]) / 2 + (box.endPoint[1] + box.startPoint[1]) * pt[1] / size() - ]); - face4.meshRaw = face4.mesh.map((pt) => [pt[0] / (input.shape[2] || 0), pt[1] / (input.shape[1] || 0), (pt[2] || 0) / size2]); - for (const key of Object.keys(blazeFaceLandmarks)) { - face4.annotations[key] = [face4.mesh[blazeFaceLandmarks[key]]]; - } - } else if (!model7) { - if (config3.debug) - log("face mesh detection requested, but model is not loaded"); - } else { - if (((_f = config3.face.attention) == null ? void 0 : _f.enabled) && !env.kernels.includes("atan2")) { - config3.face.attention.enabled = false; - tf15.dispose(face4.tensor); - return faces; - } - const results = model7.execute(face4.tensor); - const confidenceT = results.find((t2) => t2.shape[t2.shape.length - 1] === 1); - const faceConfidence = await confidenceT.data(); - face4.faceScore = Math.round(100 * faceConfidence[0]) / 100; - if (face4.faceScore < (((_g = config3.face.detector) == null ? void 0 : _g.minConfidence) || 1)) { - box.confidence = face4.faceScore; - if (config3.face.mesh.keepInvalid) { - face4.box = clampBox(box, input); - face4.boxRaw = getRawBox(box, input); - face4.score = face4.boxScore; - face4.mesh = box.landmarks.map((pt) => [ - (box.startPoint[0] + box.endPoint[0]) / 2 + (box.endPoint[0] + box.startPoint[0]) * pt[0] / size(), - (box.startPoint[1] + box.endPoint[1]) / 2 + (box.endPoint[1] + box.startPoint[1]) * pt[1] / size() - ]); - face4.meshRaw = face4.mesh.map((pt) => [pt[0] / (input.shape[2] || 1), pt[1] / (input.shape[1] || 1), (pt[2] || 0) / size2]); - for (const key of Object.keys(blazeFaceLandmarks)) { - face4.annotations[key] = [face4.mesh[blazeFaceLandmarks[key]]]; - } - } - } else { - const meshT = results.find((t2) => t2.shape[t2.shape.length - 1] === 1404); - const coordsReshaped = tf15.reshape(meshT, [-1, 3]); - let rawCoords = await coordsReshaped.array(); - tf15.dispose(coordsReshaped); - if ((_h = config3.face.attention) == null ? void 0 : _h.enabled) { - rawCoords = await augment(rawCoords, results); - } else if ((_i = config3.face.iris) == null ? void 0 : _i.enabled) { - rawCoords = await augmentIris(rawCoords, face4.tensor, inputSize6); - } - face4.mesh = transformRawCoords(rawCoords, box, angle, rotationMatrix, inputSize6); - face4.meshRaw = face4.mesh.map((pt) => [pt[0] / (input.shape[2] || 0), pt[1] / (input.shape[1] || 0), (pt[2] || 0) / size2]); - for (const key of Object.keys(meshAnnotations)) - face4.annotations[key] = meshAnnotations[key].map((index2) => face4.mesh[index2]); - face4.score = face4.faceScore; - const calculatedBox = { ...calculateFaceBox(face4.mesh, box), confidence: box.confidence, landmarks: box.landmarks }; - face4.box = clampBox(calculatedBox, input); - face4.boxRaw = getRawBox(calculatedBox, input); - newCache.push(calculatedBox); - } - tf15.dispose(results); - } - if (face4.score > (((_j = config3.face.detector) == null ? void 0 : _j.minConfidence) || 1)) - faces.push(face4); - else - tf15.dispose(face4.tensor); - } - cache3.boxes = newCache; - return faces; -} -async function load5(config3) { - var _a, _b, _c, _d, _e, _f; - if (env.initial) - model7 = null; - if (((_a = config3.face.attention) == null ? void 0 : _a.enabled) && (model7 == null ? void 0 : model7["signature"])) { - if (Object.keys(((_b = model7 == null ? void 0 : model7["signature"]) == null ? void 0 : _b.outputs) || {}).length < 6) - model7 = null; - } - if (!model7) { - if ((_c = config3.face.attention) == null ? void 0 : _c.enabled) - model7 = await loadModel(config3.face.attention.modelPath); - else - model7 = await loadModel((_d = config3.face.mesh) == null ? void 0 : _d.modelPath); - } else if (config3.debug) { - log("cached model:", model7["modelUrl"]); - } - inputSize6 = model7["executor"] && ((_e = model7 == null ? void 0 : model7.inputs) == null ? void 0 : _e[0].shape) ? (_f = model7 == null ? void 0 : model7.inputs) == null ? void 0 : _f[0].shape[2] : 256; - return model7; -} -var triangulation = TRI468; -var uvmap = UV468; - -// src/gear/emotion.ts -var tf16 = __toESM(require_tfjs_esm()); -var annotations = ["angry", "disgust", "fear", "happy", "sad", "surprise", "neutral"]; -var model8; -var last3 = []; -var lastCount = 0; -var lastTime4 = 0; -var skipped4 = Number.MAX_SAFE_INTEGER; -async function load6(config3) { - var _a; - if (env.initial) - model8 = null; - if (!model8) - model8 = await loadModel((_a = config3.face.emotion) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model8["modelUrl"]); - return model8; -} -async function predict5(image28, config3, idx, count2) { - var _a, _b; - if (!model8) - return []; - const skipFrame = skipped4 < (((_a = config3.face.emotion) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face.emotion) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime4; - if (config3.skipAllowed && skipTime && skipFrame && lastCount === count2 && last3[idx] && last3[idx].length > 0) { - skipped4++; - return last3[idx]; - } - skipped4 = 0; - return new Promise(async (resolve) => { - var _a2; - const obj = []; - if ((_a2 = config3.face.emotion) == null ? void 0 : _a2.enabled) { - const t2 = {}; - const inputSize10 = (model8 == null ? void 0 : model8.inputs[0].shape) ? model8.inputs[0].shape[2] : 0; - t2.resize = tf16.image.resizeBilinear(image28, [inputSize10, inputSize10], false); - t2.channels = tf16.mul(t2.resize, constants.rgb); - t2.grayscale = tf16.sum(t2.channels, 3, true); - t2.grayscaleSub = tf16.sub(t2.grayscale, constants.tf05); - t2.grayscaleMul = tf16.mul(t2.grayscaleSub, constants.tf2); - t2.emotion = model8 == null ? void 0 : model8.execute(t2.grayscaleMul); - lastTime4 = now(); - const data = await t2.emotion.data(); - for (let i = 0; i < data.length; i++) { - if (data[i] > (config3.face.emotion.minConfidence || 0)) - obj.push({ score: Math.min(0.99, Math.trunc(100 * data[i]) / 100), emotion: annotations[i] }); - } - obj.sort((a, b) => b.score - a.score); - Object.keys(t2).forEach((tensor6) => tf16.dispose(t2[tensor6])); - } - last3[idx] = obj; - lastCount = count2; - resolve(obj); - }); -} - -// src/face/faceres.ts -var tf17 = __toESM(require_tfjs_esm()); -var model9; -var last4 = []; -var lastTime5 = 0; -var lastCount2 = 0; -var skipped5 = Number.MAX_SAFE_INTEGER; -async function load7(config3) { - var _a; - if (env.initial) - model9 = null; - if (!model9) - model9 = await loadModel((_a = config3.face.description) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model9["modelUrl"]); - return model9; -} -function enhance(input) { - const tensor6 = input.image || input.tensor || input; - if (!(model9 == null ? void 0 : model9.inputs[0].shape)) - return tensor6; - const crop = tf17.image.resizeBilinear(tensor6, [model9.inputs[0].shape[2], model9.inputs[0].shape[1]], false); - const norm = tf17.mul(crop, constants.tf255); - tf17.dispose(crop); - return norm; -} -async function predict6(image28, config3, idx, count2) { - var _a, _b, _c, _d; - const obj = { - age: 0, - gender: "unknown", - genderScore: 0, - descriptor: [] - }; - if (!(model9 == null ? void 0 : model9["executor"])) - return obj; - const skipFrame = skipped5 < (((_a = config3.face.description) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face.description) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime5; - if (config3.skipAllowed && skipFrame && skipTime && lastCount2 === count2 && ((_c = last4 == null ? void 0 : last4[idx]) == null ? void 0 : _c.age) > 0 && ((_d = last4 == null ? void 0 : last4[idx]) == null ? void 0 : _d.genderScore) > 0) { - skipped5++; - return last4[idx]; - } - skipped5 = 0; - return new Promise(async (resolve) => { - var _a2; - if ((_a2 = config3.face.description) == null ? void 0 : _a2.enabled) { - const enhanced = enhance(image28); - const resT = model9 == null ? void 0 : model9.execute(enhanced); - lastTime5 = now(); - tf17.dispose(enhanced); - const genderT = resT.find((t2) => t2.shape[1] === 1); - const gender2 = await genderT.data(); - const confidence = Math.trunc(200 * Math.abs(gender2[0] - 0.5)) / 100; - if (confidence > (config3.face.description.minConfidence || 0)) { - obj.gender = gender2[0] <= 0.5 ? "female" : "male"; - obj.genderScore = Math.min(0.99, confidence); - } - const argmax = tf17.argMax(resT.find((t2) => t2.shape[1] === 100), 1); - const ageIdx = (await argmax.data())[0]; - tf17.dispose(argmax); - const ageT = resT.find((t2) => t2.shape[1] === 100); - const all2 = await ageT.data(); - obj.age = Math.round(all2[ageIdx - 1] > all2[ageIdx + 1] ? 10 * ageIdx - 100 * all2[ageIdx - 1] : 10 * ageIdx + 100 * all2[ageIdx + 1]) / 10; - if (Number.isNaN(gender2[0]) || Number.isNaN(all2[0])) - log("faceres error:", { model: model9, result: resT }); - const desc = resT.find((t2) => t2.shape[1] === 1024); - const descriptor = desc ? await desc.data() : []; - obj.descriptor = Array.from(descriptor); - resT.forEach((t2) => tf17.dispose(t2)); - } - last4[idx] = obj; - lastCount2 = count2; - resolve(obj); - }); -} - -// src/face/mask.ts -var expandFact = 0.1; -var alpha = 0.5; -function insidePoly(x, y, polygon) { - let inside = false; - let j = polygon.length - 1; - for (let i = 0; i < polygon.length; j = i++) { - if (polygon[i].y > y !== polygon[j].y > y && x < (polygon[j].x - polygon[i].x) * (y - polygon[i].y) / (polygon[j].y - polygon[i].y) + polygon[i].x) - inside = !inside; - } - return inside; -} -async function mask(face4) { - if (!face4.tensor) - return face4.tensor; - if (!face4.mesh || face4.mesh.length < 100) - return face4.tensor; - const width = face4.tensor.shape[2] || 0; - const height = face4.tensor.shape[1] || 0; - const buffer = await face4.tensor.buffer(); - let silhouette = []; - for (const pt of meshAnnotations.silhouette) - silhouette.push({ x: (face4.mesh[pt][0] - face4.box[0]) / face4.box[2], y: (face4.mesh[pt][1] - face4.box[1]) / face4.box[3] }); - if (expandFact && expandFact > 0) - silhouette = silhouette.map((pt) => ({ x: pt.x > 0.5 ? pt.x + expandFact : pt.x - expandFact, y: pt.y > 0.5 ? pt.y + expandFact : pt.y - expandFact })); - for (let x = 0; x < width; x++) { - for (let y = 0; y < height; y++) { - const inside = insidePoly(x / width, y / width, silhouette); - if (!inside) { - buffer.set(alpha * buffer.get(0, y, x, 0), 0, y, x, 0); - buffer.set(alpha * buffer.get(0, y, x, 1), 0, y, x, 1); - buffer.set(alpha * buffer.get(0, y, x, 2), 0, y, x, 2); - } - } - } - const output = buffer.toTensor(); - return output; -} - -// src/face/antispoof.ts -var tf18 = __toESM(require_tfjs_esm()); -var model10; -var cached = []; -var skipped6 = Number.MAX_SAFE_INTEGER; -var lastCount3 = 0; -var lastTime6 = 0; -async function load8(config3) { - var _a; - if (env.initial) - model10 = null; - if (!model10) - model10 = await loadModel((_a = config3.face.antispoof) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model10["modelUrl"]); - return model10; -} -async function predict7(image28, config3, idx, count2) { - var _a, _b; - if (!(model10 == null ? void 0 : model10["executor"])) - return 0; - const skipTime = (((_a = config3.face.antispoof) == null ? void 0 : _a.skipTime) || 0) > now() - lastTime6; - const skipFrame = skipped6 < (((_b = config3.face.antispoof) == null ? void 0 : _b.skipFrames) || 0); - if (config3.skipAllowed && skipTime && skipFrame && lastCount3 === count2 && cached[idx]) { - skipped6++; - return cached[idx]; - } - skipped6 = 0; - return new Promise(async (resolve) => { - const resize = tf18.image.resizeBilinear(image28, [(model10 == null ? void 0 : model10.inputs[0].shape) ? model10.inputs[0].shape[2] : 0, (model10 == null ? void 0 : model10.inputs[0].shape) ? model10.inputs[0].shape[1] : 0], false); - const res = model10 == null ? void 0 : model10.execute(resize); - const num = (await res.data())[0]; - cached[idx] = Math.round(100 * num) / 100; - lastCount3 = count2; - lastTime6 = now(); - tf18.dispose([resize, res]); - resolve(cached[idx]); - }); -} - -// src/face/liveness.ts -var tf19 = __toESM(require_tfjs_esm()); -var model11; -var cached2 = []; -var skipped7 = Number.MAX_SAFE_INTEGER; -var lastCount4 = 0; -var lastTime7 = 0; -async function load9(config3) { - var _a; - if (env.initial) - model11 = null; - if (!model11) - model11 = await loadModel((_a = config3.face.liveness) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model11["modelUrl"]); - return model11; -} -async function predict8(image28, config3, idx, count2) { - var _a, _b; - if (!(model11 == null ? void 0 : model11["executor"])) - return 0; - const skipTime = (((_a = config3.face.liveness) == null ? void 0 : _a.skipTime) || 0) > now() - lastTime7; - const skipFrame = skipped7 < (((_b = config3.face.liveness) == null ? void 0 : _b.skipFrames) || 0); - if (config3.skipAllowed && skipTime && skipFrame && lastCount4 === count2 && cached2[idx]) { - skipped7++; - return cached2[idx]; - } - skipped7 = 0; - return new Promise(async (resolve) => { - const resize = tf19.image.resizeBilinear(image28, [(model11 == null ? void 0 : model11.inputs[0].shape) ? model11.inputs[0].shape[2] : 0, (model11 == null ? void 0 : model11.inputs[0].shape) ? model11.inputs[0].shape[1] : 0], false); - const res = model11 == null ? void 0 : model11.execute(resize); - const num = (await res.data())[0]; - cached2[idx] = Math.round(100 * num) / 100; - lastCount4 = count2; - lastTime7 = now(); - tf19.dispose([resize, res]); - resolve(cached2[idx]); - }); -} - -// src/gear/gear.ts -var tf20 = __toESM(require_tfjs_esm()); -var model12; -var last5 = []; -var raceNames = ["white", "black", "asian", "indian", "other"]; -var ageWeights = [15, 23, 28, 35.5, 45.5, 55.5, 65]; -var lastCount5 = 0; -var lastTime8 = 0; -var skipped8 = Number.MAX_SAFE_INTEGER; -async function load10(config3) { - var _a; - if (env.initial) - model12 = null; - if (!model12) - model12 = await loadModel((_a = config3.face.gear) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model12["modelUrl"]); - return model12; -} -async function predict9(image28, config3, idx, count2) { - var _a, _b; - if (!model12) - return { age: 0, gender: "unknown", genderScore: 0, race: [] }; - const skipFrame = skipped8 < (((_a = config3.face.gear) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face.gear) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime8; - if (config3.skipAllowed && skipTime && skipFrame && lastCount5 === count2 && last5[idx]) { - skipped8++; - return last5[idx]; - } - skipped8 = 0; - return new Promise(async (resolve) => { - var _a2, _b2; - if (!(model12 == null ? void 0 : model12.inputs[0].shape)) - return; - const t2 = {}; - const box = [[0, 0.1, 0.9, 0.9]]; - t2.resize = tf20.image.cropAndResize(image28, box, [0], [model12.inputs[0].shape[2], model12.inputs[0].shape[1]]); - const obj = { age: 0, gender: "unknown", genderScore: 0, race: [] }; - if ((_a2 = config3.face.gear) == null ? void 0 : _a2.enabled) - [t2.age, t2.gender, t2.race] = model12.execute(t2.resize, ["age_output", "gender_output", "race_output"]); - const gender2 = await t2.gender.data(); - obj.gender = gender2[0] > gender2[1] ? "male" : "female"; - obj.genderScore = Math.round(100 * (gender2[0] > gender2[1] ? gender2[0] : gender2[1])) / 100; - const race = await t2.race.data(); - for (let i = 0; i < race.length; i++) { - if (race[i] > (((_b2 = config3.face.gear) == null ? void 0 : _b2.minConfidence) || 0.2)) - obj.race.push({ score: Math.round(100 * race[i]) / 100, race: raceNames[i] }); - } - obj.race.sort((a, b) => b.score - a.score); - const ageDistribution = Array.from(await t2.age.data()); - const ageSorted = ageDistribution.map((a, i) => [ageWeights[i], a]).sort((a, b) => b[1] - a[1]); - let age2 = ageSorted[0][0]; - for (let i = 1; i < ageSorted.length; i++) - age2 += ageSorted[i][1] * (ageSorted[i][0] - age2); - obj.age = Math.round(10 * age2) / 10; - Object.keys(t2).forEach((tensor6) => tf20.dispose(t2[tensor6])); - last5[idx] = obj; - lastCount5 = count2; - lastTime8 = now(); - resolve(obj); - }); -} - -// src/gear/ssrnet-age.ts -var tf21 = __toESM(require_tfjs_esm()); -var model13; -var last6 = []; -var lastCount6 = 0; -var lastTime9 = 0; -var skipped9 = Number.MAX_SAFE_INTEGER; -async function load11(config3) { - if (env.initial) - model13 = null; - if (!model13) - model13 = await loadModel(config3.face["ssrnet"].modelPathAge); - else if (config3.debug) - log("cached model:", model13["modelUrl"]); - return model13; -} -async function predict10(image28, config3, idx, count2) { - var _a, _b, _c, _d; - if (!model13) - return { age: 0 }; - const skipFrame = skipped9 < (((_a = config3.face["ssrnet"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["ssrnet"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime9; - if (config3.skipAllowed && skipFrame && skipTime && lastCount6 === count2 && ((_c = last6[idx]) == null ? void 0 : _c.age) && ((_d = last6[idx]) == null ? void 0 : _d.age) > 0) { - skipped9++; - return last6[idx]; - } - skipped9 = 0; - return new Promise(async (resolve) => { - var _a2; - if (!(model13 == null ? void 0 : model13.inputs) || !model13.inputs[0] || !model13.inputs[0].shape) - return; - const t2 = {}; - t2.resize = tf21.image.resizeBilinear(image28, [model13.inputs[0].shape[2], model13.inputs[0].shape[1]], false); - t2.enhance = tf21.mul(t2.resize, constants.tf255); - const obj = { age: 0 }; - if ((_a2 = config3.face["ssrnet"]) == null ? void 0 : _a2.enabled) - t2.age = model13.execute(t2.enhance); - if (t2.age) { - const data = await t2.age.data(); - obj.age = Math.trunc(10 * data[0]) / 10; - } - Object.keys(t2).forEach((tensor6) => tf21.dispose(t2[tensor6])); - last6[idx] = obj; - lastCount6 = count2; - lastTime9 = now(); - resolve(obj); - }); -} - -// src/gear/ssrnet-gender.ts -var tf22 = __toESM(require_tfjs_esm()); -var model14; -var last7 = []; -var lastCount7 = 0; -var lastTime10 = 0; -var skipped10 = Number.MAX_SAFE_INTEGER; -var rgb = [0.2989, 0.587, 0.114]; -async function load12(config3) { - var _a; - if (env.initial) - model14 = null; - if (!model14) - model14 = await loadModel((_a = config3.face["ssrnet"]) == null ? void 0 : _a.modelPathGender); - else if (config3.debug) - log("cached model:", model14["modelUrl"]); - return model14; -} -async function predict11(image28, config3, idx, count2) { - var _a, _b, _c, _d; - if (!model14) - return { gender: "unknown", genderScore: 0 }; - const skipFrame = skipped10 < (((_a = config3.face["ssrnet"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["ssrnet"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime10; - if (config3.skipAllowed && skipFrame && skipTime && lastCount7 === count2 && ((_c = last7[idx]) == null ? void 0 : _c.gender) && ((_d = last7[idx]) == null ? void 0 : _d.genderScore) > 0) { - skipped10++; - return last7[idx]; - } - skipped10 = 0; - return new Promise(async (resolve) => { - var _a2; - if (!(model14 == null ? void 0 : model14.inputs[0].shape)) - return; - const t2 = {}; - t2.resize = tf22.image.resizeBilinear(image28, [model14.inputs[0].shape[2], model14.inputs[0].shape[1]], false); - t2.enhance = tf22.tidy(() => { - const [red, green, blue] = tf22.split(t2.resize, 3, 3); - const redNorm = tf22.mul(red, rgb[0]); - const greenNorm = tf22.mul(green, rgb[1]); - const blueNorm = tf22.mul(blue, rgb[2]); - const grayscale = tf22.addN([redNorm, greenNorm, blueNorm]); - const normalize2 = tf22.mul(tf22.sub(grayscale, constants.tf05), 2); - return normalize2; - }); - const obj = { gender: "unknown", genderScore: 0 }; - if ((_a2 = config3.face["ssrnet"]) == null ? void 0 : _a2.enabled) - t2.gender = model14.execute(t2.enhance); - const data = await t2.gender.data(); - obj.gender = data[0] > data[1] ? "female" : "male"; - obj.genderScore = data[0] > data[1] ? Math.trunc(100 * data[0]) / 100 : Math.trunc(100 * data[1]) / 100; - Object.keys(t2).forEach((tensor6) => tf22.dispose(t2[tensor6])); - last7[idx] = obj; - lastCount7 = count2; - lastTime10 = now(); - resolve(obj); - }); -} - -// src/face/mobilefacenet.ts -var tf23 = __toESM(require_tfjs_esm()); -var model15; -var last8 = []; -var lastCount8 = 0; -var lastTime11 = 0; -var skipped11 = Number.MAX_SAFE_INTEGER; -async function load13(config3) { - var _a; - if (env.initial) - model15 = null; - if (!model15) - model15 = await loadModel((_a = config3.face["mobilefacenet"]) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model15["modelUrl"]); - return model15; -} -async function predict12(input, config3, idx, count2) { - var _a, _b; - if (!(model15 == null ? void 0 : model15["executor"])) - return []; - const skipFrame = skipped11 < (((_a = config3.face["mobilefacenet"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["mobilefacenet"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime11; - if (config3.skipAllowed && skipTime && skipFrame && lastCount8 === count2 && last8[idx]) { - skipped11++; - return last8[idx]; - } - return new Promise(async (resolve) => { - var _a2; - let data = []; - if (((_a2 = config3.face["mobilefacenet"]) == null ? void 0 : _a2.enabled) && (model15 == null ? void 0 : model15.inputs[0].shape)) { - const t2 = {}; - t2.crop = tf23.image.resizeBilinear(input, [model15.inputs[0].shape[2], model15.inputs[0].shape[1]], false); - t2.data = model15.execute(t2.crop); - const output = await t2.data.data(); - data = Array.from(output); - Object.keys(t2).forEach((tensor6) => tf23.dispose(t2[tensor6])); - } - last8[idx] = data; - lastCount8 = count2; - lastTime11 = now(); - resolve(data); - }); -} - -// src/face/insightface.ts -var tf24 = __toESM(require_tfjs_esm()); -var model16; -var last9 = []; -var lastCount9 = 0; -var lastTime12 = 0; -var skipped12 = Number.MAX_SAFE_INTEGER; -async function load14(config3) { - if (env.initial) - model16 = null; - if (!model16) - model16 = await loadModel(config3.face["insightface"].modelPath); - else if (config3.debug) - log("cached model:", model16["modelUrl"]); - return model16; -} -async function predict13(input, config3, idx, count2) { - var _a, _b; - if (!(model16 == null ? void 0 : model16["executor"])) - return []; - const skipFrame = skipped12 < (((_a = config3.face["insightface"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["insightface"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime12; - if (config3.skipAllowed && skipTime && skipFrame && lastCount9 === count2 && last9[idx]) { - skipped12++; - return last9[idx]; - } - return new Promise(async (resolve) => { - var _a2; - let data = []; - if (((_a2 = config3.face["insightface"]) == null ? void 0 : _a2.enabled) && (model16 == null ? void 0 : model16.inputs[0].shape)) { - const t2 = {}; - t2.crop = tf24.image.resizeBilinear(input, [model16.inputs[0].shape[2], model16.inputs[0].shape[1]], false); - t2.data = model16.execute(t2.crop); - const output = await t2.data.data(); - data = Array.from(output); - Object.keys(t2).forEach((tensor6) => tf24.dispose(t2[tensor6])); - } - last9[idx] = data; - lastCount9 = count2; - lastTime12 = now(); - resolve(data); - }); -} - -// src/face/angles.ts -var calculateGaze = (face4) => { - const radians = (pt1, pt2) => Math.atan2(pt1[1] - pt2[1], pt1[0] - pt2[0]); - if (!face4.annotations.rightEyeIris || !face4.annotations.leftEyeIris) - return { bearing: 0, strength: 0 }; - const offsetIris = [0, -0.1]; - const eyeRatio = 1; - const left = (face4.mesh[33][2] || 0) > (face4.mesh[263][2] || 0); - const irisCenter = left ? face4.mesh[473] : face4.mesh[468]; - const eyeCenter = left ? [(face4.mesh[133][0] + face4.mesh[33][0]) / 2, (face4.mesh[133][1] + face4.mesh[33][1]) / 2] : [(face4.mesh[263][0] + face4.mesh[362][0]) / 2, (face4.mesh[263][1] + face4.mesh[362][1]) / 2]; - const eyeSize = left ? [face4.mesh[133][0] - face4.mesh[33][0], face4.mesh[23][1] - face4.mesh[27][1]] : [face4.mesh[263][0] - face4.mesh[362][0], face4.mesh[253][1] - face4.mesh[257][1]]; - const eyeDiff = [ - (eyeCenter[0] - irisCenter[0]) / eyeSize[0] - offsetIris[0], - eyeRatio * (irisCenter[1] - eyeCenter[1]) / eyeSize[1] - offsetIris[1] - ]; - let strength = Math.sqrt(eyeDiff[0] * eyeDiff[0] + eyeDiff[1] * eyeDiff[1]); - strength = Math.min(strength, face4.boxRaw[2] / 2, face4.boxRaw[3] / 2); - const bearing = (radians([0, 0], eyeDiff) + Math.PI / 2) % Math.PI; - return { bearing, strength }; -}; -var calculateFaceAngle = (face4, imageSize) => { - const normalize2 = (v) => { - const length = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); - v[0] /= length; - v[1] /= length; - v[2] /= length; - return v; - }; - const subVectors = (a, b) => { - const x = a[0] - b[0]; - const y = a[1] - b[1]; - const z = a[2] - b[2]; - return [x, y, z]; - }; - const crossVectors = (a, b) => { - const x = a[1] * b[2] - a[2] * b[1]; - const y = a[2] * b[0] - a[0] * b[2]; - const z = a[0] * b[1] - a[1] * b[0]; - return [x, y, z]; - }; - const rotationMatrixToEulerAngle = (r) => { - const [r00, _r01, _r02, r10, r11, r12, r20, r21, r22] = r; - let thetaX; - let thetaY; - let thetaZ; - if (r10 < 1) { - if (r10 > -1) { - thetaZ = Math.asin(r10); - thetaY = Math.atan2(-r20, r00); - thetaX = Math.atan2(-r12, r11); - } else { - thetaZ = -Math.PI / 2; - thetaY = -Math.atan2(r21, r22); - thetaX = 0; - } - } else { - thetaZ = Math.PI / 2; - thetaY = Math.atan2(r21, r22); - thetaX = 0; - } - if (Number.isNaN(thetaX)) - thetaX = 0; - if (Number.isNaN(thetaY)) - thetaY = 0; - if (Number.isNaN(thetaZ)) - thetaZ = 0; - return { pitch: 2 * -thetaX, yaw: 2 * -thetaY, roll: 2 * -thetaZ }; - }; - const mesh = face4.meshRaw; - if (!mesh || mesh.length < 300) - return { angle: { pitch: 0, yaw: 0, roll: 0 }, matrix: [1, 0, 0, 0, 1, 0, 0, 0, 1], gaze: { bearing: 0, strength: 0 } }; - const size2 = Math.max(face4.boxRaw[2] * imageSize[0], face4.boxRaw[3] * imageSize[1]) / 1.5; - const pts = [mesh[10], mesh[152], mesh[234], mesh[454]].map((pt) => [pt[0] * imageSize[0] / size2, pt[1] * imageSize[1] / size2, pt[2]]); - const yAxis = normalize2(subVectors(pts[1], pts[0])); - let xAxis = normalize2(subVectors(pts[3], pts[2])); - const zAxis = normalize2(crossVectors(xAxis, yAxis)); - xAxis = crossVectors(yAxis, zAxis); - const matrix = [ - xAxis[0], - xAxis[1], - xAxis[2], - yAxis[0], - yAxis[1], - yAxis[2], - zAxis[0], - zAxis[1], - zAxis[2] - ]; - const angle = rotationMatrixToEulerAngle(matrix); - const gaze = mesh.length === 478 ? calculateGaze(face4) : { bearing: 0, strength: 0 }; - return { angle, matrix, gaze }; -}; - -// src/face/anthropometry.ts -function calculateCameraDistance(face4, width) { - const f = face4 == null ? void 0 : face4.annotations; - if (!f) - return 0; - const irisSize = Math.max(Math.abs(f.leftEyeIris[3][0] - f.leftEyeIris[1][0]), Math.abs(f.rightEyeIris[3][0] - f.rightEyeIris[1][0])) / width; - const cameraDistance = Math.round(1.17 / irisSize) / 100; - return cameraDistance; -} - -// src/face/face.ts -var detectFace = async (instance, input) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w; - let timeStamp = now(); - let ageRes; - let gearRes; - let genderRes; - let emotionRes; - let mobilefacenetRes; - let insightfaceRes; - let antispoofRes; - let livenessRes; - let descRes; - const faceRes = []; - instance.state = "run:face"; - const faces = await predict4(input, instance.config); - instance.performance.face = env.perfadd ? (instance.performance.face || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - if (!input.shape || input.shape.length !== 4) - return []; - if (!faces) - return []; - for (let i = 0; i < faces.length; i++) { - instance.analyze("Get Face"); - if (!faces[i].tensor || faces[i].tensor.isDisposedInternal) { - log("Face object is disposed:", faces[i].tensor); - continue; - } - if ((_a = instance.config.face.detector) == null ? void 0 : _a.mask) { - const masked = await mask(faces[i]); - tf25.dispose(faces[i].tensor); - if (masked) - faces[i].tensor = masked; - } - const rotation = faces[i].mesh && faces[i].mesh.length > 200 ? calculateFaceAngle(faces[i], [input.shape[2], input.shape[1]]) : null; - instance.analyze("Start Emotion:"); - if (instance.config.async) { - emotionRes = ((_b = instance.config.face.emotion) == null ? void 0 : _b.enabled) ? predict5(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : []; - } else { - instance.state = "run:emotion"; - timeStamp = now(); - emotionRes = ((_c = instance.config.face.emotion) == null ? void 0 : _c.enabled) ? await predict5(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : []; - instance.performance.emotion = env.perfadd ? (instance.performance.emotion || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End Emotion:"); - instance.analyze("Start AntiSpoof:"); - if (instance.config.async) { - antispoofRes = ((_d = instance.config.face.antispoof) == null ? void 0 : _d.enabled) ? predict7(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : 0; - } else { - instance.state = "run:antispoof"; - timeStamp = now(); - antispoofRes = ((_e = instance.config.face.antispoof) == null ? void 0 : _e.enabled) ? await predict7(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : 0; - instance.performance.antispoof = env.perfadd ? (instance.performance.antispoof || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End AntiSpoof:"); - instance.analyze("Start Liveness:"); - if (instance.config.async) { - livenessRes = ((_f = instance.config.face.liveness) == null ? void 0 : _f.enabled) ? predict8(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : 0; - } else { - instance.state = "run:liveness"; - timeStamp = now(); - livenessRes = ((_g = instance.config.face.liveness) == null ? void 0 : _g.enabled) ? await predict8(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : 0; - instance.performance.liveness = env.perfadd ? (instance.performance.antispoof || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End Liveness:"); - instance.analyze("Start GEAR:"); - if (instance.config.async) { - gearRes = ((_h = instance.config.face.gear) == null ? void 0 : _h.enabled) ? predict9(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:gear"; - timeStamp = now(); - gearRes = ((_i = instance.config.face.gear) == null ? void 0 : _i.enabled) ? await predict9(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - instance.performance.gear = Math.trunc(now() - timeStamp); - } - instance.analyze("End GEAR:"); - instance.analyze("Start SSRNet:"); - if (instance.config.async) { - ageRes = ((_j = instance.config.face["ssrnet"]) == null ? void 0 : _j.enabled) ? predict10(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - genderRes = ((_k = instance.config.face["ssrnet"]) == null ? void 0 : _k.enabled) ? predict11(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:ssrnet"; - timeStamp = now(); - ageRes = ((_l = instance.config.face["ssrnet"]) == null ? void 0 : _l.enabled) ? await predict10(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - genderRes = ((_m = instance.config.face["ssrnet"]) == null ? void 0 : _m.enabled) ? await predict11(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - instance.performance.ssrnet = Math.trunc(now() - timeStamp); - } - instance.analyze("End SSRNet:"); - instance.analyze("Start MobileFaceNet:"); - if (instance.config.async) { - mobilefacenetRes = ((_n = instance.config.face["mobilefacenet"]) == null ? void 0 : _n.enabled) ? predict12(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:mobilefacenet"; - timeStamp = now(); - mobilefacenetRes = ((_o = instance.config.face["mobilefacenet"]) == null ? void 0 : _o.enabled) ? await predict12(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - instance.performance.mobilefacenet = Math.trunc(now() - timeStamp); - } - instance.analyze("End MobileFaceNet:"); - instance.analyze("Start InsightFace:"); - if (instance.config.async) { - insightfaceRes = ((_p = instance.config.face["insightface"]) == null ? void 0 : _p.enabled) ? predict13(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:mobilefacenet"; - timeStamp = now(); - insightfaceRes = ((_q = instance.config.face["insightface"]) == null ? void 0 : _q.enabled) ? await predict13(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - instance.performance.mobilefacenet = Math.trunc(now() - timeStamp); - } - instance.analyze("End InsightFace:"); - instance.analyze("Start Description:"); - if (instance.config.async) { - descRes = predict6(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length); - } else { - instance.state = "run:description"; - timeStamp = now(); - descRes = await predict6(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length); - instance.performance.description = env.perfadd ? (instance.performance.description || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End Description:"); - if (instance.config.async) { - [ageRes, genderRes, emotionRes, mobilefacenetRes, insightfaceRes, descRes, gearRes, antispoofRes, livenessRes] = await Promise.all([ageRes, genderRes, emotionRes, mobilefacenetRes, insightfaceRes, descRes, gearRes, antispoofRes, livenessRes]); - } - instance.analyze("Finish Face:"); - if (((_r = instance.config.face["ssrnet"]) == null ? void 0 : _r.enabled) && ageRes && genderRes) { - descRes = { - ...descRes, - age: ageRes.age, - gender: genderRes.gender, - genderScore: genderRes.genderScore - }; - } - if (((_s = instance.config.face.gear) == null ? void 0 : _s.enabled) && gearRes) { - descRes = { - ...descRes, - age: gearRes.age, - gender: gearRes.gender, - genderScore: gearRes.genderScore, - race: gearRes.race - }; - } - if (((_t = instance.config.face["mobilefacenet"]) == null ? void 0 : _t.enabled) && mobilefacenetRes) { - descRes.descriptor = mobilefacenetRes; - } - if (((_u = instance.config.face["insightface"]) == null ? void 0 : _u.enabled) && insightfaceRes) { - descRes.descriptor = insightfaceRes; - } - const irisSize = ((_v = instance.config.face.iris) == null ? void 0 : _v.enabled) ? calculateCameraDistance(faces[i], input.shape[2]) : 0; - const tensor6 = ((_w = instance.config.face.detector) == null ? void 0 : _w.return) ? tf25.squeeze(faces[i].tensor) : null; - tf25.dispose(faces[i].tensor); - if (faces[i].tensor) - delete faces[i].tensor; - const res = { - ...faces[i], - id: i - }; - if (descRes.age) - res.age = descRes.age; - if (descRes.gender) - res.gender = descRes.gender; - if (descRes.genderScore) - res.genderScore = descRes.genderScore; - if (descRes.descriptor) - res.embedding = descRes.descriptor; - if (descRes.race) - res.race = descRes.race; - if (emotionRes) - res.emotion = emotionRes; - if (antispoofRes) - res.real = antispoofRes; - if (livenessRes) - res.live = livenessRes; - if (irisSize > 0) - res.distance = irisSize; - if (rotation) - res.rotation = rotation; - if (tensor6) - res.tensor = tensor6; - faceRes.push(res); - instance.analyze("End Face"); - } - instance.analyze("End FaceMesh:"); - if (instance.config.async) { - if (instance.performance.face) - delete instance.performance.face; - if (instance.performance.age) - delete instance.performance.age; - if (instance.performance.gender) - delete instance.performance.gender; - if (instance.performance.emotion) - delete instance.performance.emotion; - } - return faceRes; -}; - -// src/hand/fingerdef.ts -var Finger = { - thumb: 0, - index: 1, - middle: 2, - ring: 3, - pinky: 4, - all: [0, 1, 2, 3, 4], - nameMapping: { 0: "thumb", 1: "index", 2: "middle", 3: "ring", 4: "pinky" }, - pointsMapping: { - 0: [[0, 1], [1, 2], [2, 3], [3, 4]], - 1: [[0, 5], [5, 6], [6, 7], [7, 8]], - 2: [[0, 9], [9, 10], [10, 11], [11, 12]], - 3: [[0, 13], [13, 14], [14, 15], [15, 16]], - 4: [[0, 17], [17, 18], [18, 19], [19, 20]] - }, - getName: (value) => Finger.nameMapping[value], - getPoints: (value) => Finger.pointsMapping[value] -}; -var FingerCurl = { - none: 0, - half: 1, - full: 2, - nameMapping: { 0: "none", 1: "half", 2: "full" }, - getName: (value) => FingerCurl.nameMapping[value] -}; -var FingerDirection = { - verticalUp: 0, - verticalDown: 1, - horizontalLeft: 2, - horizontalRight: 3, - diagonalUpRight: 4, - diagonalUpLeft: 5, - diagonalDownRight: 6, - diagonalDownLeft: 7, - nameMapping: { 0: "verticalUp", 1: "verticalDown", 2: "horizontalLeft", 3: "horizontalRight", 4: "diagonalUpRight", 5: "diagonalUpLeft", 6: "diagonalDownRight", 7: "diagonalDownLeft" }, - getName: (value) => FingerDirection.nameMapping[value] -}; -var FingerGesture = class { - constructor(name) { - __publicField(this, "name"); - __publicField(this, "curls"); - __publicField(this, "directions"); - __publicField(this, "weights"); - __publicField(this, "weightsRelative"); - this.name = name; - this.curls = {}; - this.directions = {}; - this.weights = [1, 1, 1, 1, 1]; - this.weightsRelative = [1, 1, 1, 1, 1]; - } - curl(finger, curl, confidence) { - if (typeof this.curls[finger] === "undefined") - this.curls[finger] = []; - this.curls[finger].push([curl, confidence]); - } - direction(finger, position, confidence) { - if (!this.directions[finger]) - this.directions[finger] = []; - this.directions[finger].push([position, confidence]); - } - weight(finger, weight) { - this.weights[finger] = weight; - const total = this.weights.reduce((a, b) => a + b, 0); - this.weightsRelative = this.weights.map((el) => el * 5 / total); - } - matchAgainst(detectedCurls, detectedDirections) { - let confidence = 0; - for (const fingerIdx in detectedCurls) { - const detectedCurl = detectedCurls[fingerIdx]; - const expectedCurls = this.curls[fingerIdx]; - if (typeof expectedCurls === "undefined") { - confidence += this.weightsRelative[fingerIdx]; - continue; - } - for (const [expectedCurl, score] of expectedCurls) { - if (detectedCurl === expectedCurl) { - confidence += score * this.weightsRelative[fingerIdx]; - break; - } - } - } - for (const fingerIdx in detectedDirections) { - const detectedDirection = detectedDirections[fingerIdx]; - const expectedDirections = this.directions[fingerIdx]; - if (typeof expectedDirections === "undefined") { - confidence += this.weightsRelative[fingerIdx]; - continue; - } - for (const [expectedDirection, score] of expectedDirections) { - if (detectedDirection === expectedDirection) { - confidence += score * this.weightsRelative[fingerIdx]; - break; - } - } - } - return confidence / 10; - } -}; - -// src/hand/fingergesture.ts -var { thumb, index, middle, ring, pinky } = Finger; -var { none, half, full } = FingerCurl; -var { verticalUp, verticalDown, horizontalLeft, horizontalRight, diagonalUpRight, diagonalUpLeft, diagonalDownRight, diagonalDownLeft } = FingerDirection; -var ThumbsUp = new FingerGesture("thumbs up"); -ThumbsUp.curl(thumb, none, 1); -ThumbsUp.direction(thumb, verticalUp, 1); -ThumbsUp.direction(thumb, diagonalUpLeft, 0.25); -ThumbsUp.direction(thumb, diagonalUpRight, 0.25); -for (const finger of [Finger.index, Finger.middle, Finger.ring, Finger.pinky]) { - ThumbsUp.curl(finger, full, 1); - ThumbsUp.direction(finger, horizontalLeft, 1); - ThumbsUp.direction(finger, horizontalRight, 1); -} -var Victory = new FingerGesture("victory"); -Victory.curl(thumb, half, 0.5); -Victory.curl(thumb, none, 0.5); -Victory.direction(thumb, verticalUp, 1); -Victory.direction(thumb, diagonalUpLeft, 1); -Victory.curl(index, none, 1); -Victory.direction(index, verticalUp, 0.75); -Victory.direction(index, diagonalUpLeft, 1); -Victory.curl(middle, none, 1); -Victory.direction(middle, verticalUp, 1); -Victory.direction(middle, diagonalUpLeft, 0.75); -Victory.curl(ring, full, 1); -Victory.direction(ring, verticalUp, 0.2); -Victory.direction(ring, diagonalUpLeft, 1); -Victory.direction(ring, horizontalLeft, 0.2); -Victory.curl(pinky, full, 1); -Victory.direction(pinky, verticalUp, 0.2); -Victory.direction(pinky, diagonalUpLeft, 1); -Victory.direction(pinky, horizontalLeft, 0.2); -Victory.weight(index, 2); -Victory.weight(middle, 2); -var Point = new FingerGesture("point"); -Point.curl(thumb, full, 1); -Point.curl(index, none, 0.5); -Point.curl(middle, full, 0.5); -Point.curl(ring, full, 0.5); -Point.curl(pinky, full, 0.5); -Point.weight(index, 2); -Point.weight(middle, 2); -var MiddleFinger = new FingerGesture("middle finger"); -MiddleFinger.curl(thumb, none, 1); -MiddleFinger.curl(index, full, 0.5); -MiddleFinger.curl(middle, full, 0.5); -MiddleFinger.curl(ring, full, 0.5); -MiddleFinger.curl(pinky, full, 0.5); -MiddleFinger.weight(index, 2); -MiddleFinger.weight(middle, 2); -var OpenPalm = new FingerGesture("open palm"); -OpenPalm.curl(thumb, none, 0.75); -OpenPalm.curl(index, none, 0.75); -OpenPalm.curl(middle, none, 0.75); -OpenPalm.curl(ring, none, 0.75); -OpenPalm.curl(pinky, none, 0.75); -var fingergesture_default = [ThumbsUp, Victory, Point, MiddleFinger, OpenPalm]; - -// src/hand/fingerpose.ts -var minConfidence = 0.7; -var options3 = { - HALF_CURL_START_LIMIT: 60, - NO_CURL_START_LIMIT: 130, - DISTANCE_VOTE_POWER: 1.1, - SINGLE_ANGLE_VOTE_POWER: 0.9, - TOTAL_ANGLE_VOTE_POWER: 1.6 -}; -function calculateSlope(point1x, point1y, point2x, point2y) { - const value = (point1y - point2y) / (point1x - point2x); - let slope = Math.atan(value) * 180 / Math.PI; - if (slope <= 0) - slope = -slope; - else if (slope > 0) - slope = 180 - slope; - return slope; -} -function getSlopes(point1, point2) { - if (!point1 || !point2) - return [0, 0]; - const slopeXY = calculateSlope(point1[0], point1[1], point2[0], point2[1]); - if (point1.length === 2) - return slopeXY; - const slopeYZ = calculateSlope(point1[1], point1[2], point2[1], point2[2]); - return [slopeXY, slopeYZ]; -} -function angleOrientationAt(angle, weightageAt = 1) { - let isVertical = 0; - let isDiagonal = 0; - let isHorizontal = 0; - if (angle >= 75 && angle <= 105) - isVertical = 1 * weightageAt; - else if (angle >= 25 && angle <= 155) - isDiagonal = 1 * weightageAt; - else - isHorizontal = 1 * weightageAt; - return [isVertical, isDiagonal, isHorizontal]; -} -function estimateFingerCurl(startPoint, midPoint, endPoint) { - const start_mid_x_dist = startPoint[0] - midPoint[0]; - const start_end_x_dist = startPoint[0] - endPoint[0]; - const mid_end_x_dist = midPoint[0] - endPoint[0]; - const start_mid_y_dist = startPoint[1] - midPoint[1]; - const start_end_y_dist = startPoint[1] - endPoint[1]; - const mid_end_y_dist = midPoint[1] - endPoint[1]; - const start_mid_z_dist = startPoint[2] - midPoint[2]; - const start_end_z_dist = startPoint[2] - endPoint[2]; - const mid_end_z_dist = midPoint[2] - endPoint[2]; - const start_mid_dist = Math.sqrt(start_mid_x_dist * start_mid_x_dist + start_mid_y_dist * start_mid_y_dist + start_mid_z_dist * start_mid_z_dist); - const start_end_dist = Math.sqrt(start_end_x_dist * start_end_x_dist + start_end_y_dist * start_end_y_dist + start_end_z_dist * start_end_z_dist); - const mid_end_dist = Math.sqrt(mid_end_x_dist * mid_end_x_dist + mid_end_y_dist * mid_end_y_dist + mid_end_z_dist * mid_end_z_dist); - let cos_in = (mid_end_dist * mid_end_dist + start_mid_dist * start_mid_dist - start_end_dist * start_end_dist) / (2 * mid_end_dist * start_mid_dist); - if (cos_in > 1) - cos_in = 1; - else if (cos_in < -1) - cos_in = -1; - let angleOfCurve = Math.acos(cos_in); - angleOfCurve = 57.2958 * angleOfCurve % 180; - let fingerCurl; - if (angleOfCurve > options3.NO_CURL_START_LIMIT) - fingerCurl = FingerCurl.none; - else if (angleOfCurve > options3.HALF_CURL_START_LIMIT) - fingerCurl = FingerCurl.half; - else - fingerCurl = FingerCurl.full; - return fingerCurl; -} -function estimateHorizontalDirection(start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x) { - let estimatedDirection; - if (max_dist_x === Math.abs(start_end_x_dist)) { - if (start_end_x_dist > 0) - estimatedDirection = FingerDirection.horizontalLeft; - else - estimatedDirection = FingerDirection.horizontalRight; - } else if (max_dist_x === Math.abs(start_mid_x_dist)) { - if (start_mid_x_dist > 0) - estimatedDirection = FingerDirection.horizontalLeft; - else - estimatedDirection = FingerDirection.horizontalRight; - } else { - if (mid_end_x_dist > 0) - estimatedDirection = FingerDirection.horizontalLeft; - else - estimatedDirection = FingerDirection.horizontalRight; - } - return estimatedDirection; -} -function estimateVerticalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y) { - let estimatedDirection; - if (max_dist_y === Math.abs(start_end_y_dist)) { - if (start_end_y_dist < 0) - estimatedDirection = FingerDirection.verticalDown; - else - estimatedDirection = FingerDirection.verticalUp; - } else if (max_dist_y === Math.abs(start_mid_y_dist)) { - if (start_mid_y_dist < 0) - estimatedDirection = FingerDirection.verticalDown; - else - estimatedDirection = FingerDirection.verticalUp; - } else { - if (mid_end_y_dist < 0) - estimatedDirection = FingerDirection.verticalDown; - else - estimatedDirection = FingerDirection.verticalUp; - } - return estimatedDirection; -} -function estimateDiagonalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y, start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x) { - let estimatedDirection; - const reqd_vertical_direction = estimateVerticalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y); - const reqd_horizontal_direction = estimateHorizontalDirection(start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x); - if (reqd_vertical_direction === FingerDirection.verticalUp) { - if (reqd_horizontal_direction === FingerDirection.horizontalLeft) - estimatedDirection = FingerDirection.diagonalUpLeft; - else - estimatedDirection = FingerDirection.diagonalUpRight; - } else { - if (reqd_horizontal_direction === FingerDirection.horizontalLeft) - estimatedDirection = FingerDirection.diagonalDownLeft; - else - estimatedDirection = FingerDirection.diagonalDownRight; - } - return estimatedDirection; -} -function calculateFingerDirection(startPoint, midPoint, endPoint, fingerSlopes) { - const start_mid_x_dist = startPoint[0] - midPoint[0]; - const start_end_x_dist = startPoint[0] - endPoint[0]; - const mid_end_x_dist = midPoint[0] - endPoint[0]; - const start_mid_y_dist = startPoint[1] - midPoint[1]; - const start_end_y_dist = startPoint[1] - endPoint[1]; - const mid_end_y_dist = midPoint[1] - endPoint[1]; - const max_dist_x = Math.max(Math.abs(start_mid_x_dist), Math.abs(start_end_x_dist), Math.abs(mid_end_x_dist)); - const max_dist_y = Math.max(Math.abs(start_mid_y_dist), Math.abs(start_end_y_dist), Math.abs(mid_end_y_dist)); - let voteVertical = 0; - let voteDiagonal = 0; - let voteHorizontal = 0; - const start_end_x_y_dist_ratio = max_dist_y / (max_dist_x + 1e-5); - if (start_end_x_y_dist_ratio > 1.5) - voteVertical += options3.DISTANCE_VOTE_POWER; - else if (start_end_x_y_dist_ratio > 0.66) - voteDiagonal += options3.DISTANCE_VOTE_POWER; - else - voteHorizontal += options3.DISTANCE_VOTE_POWER; - const start_mid_dist = Math.sqrt(start_mid_x_dist * start_mid_x_dist + start_mid_y_dist * start_mid_y_dist); - const start_end_dist = Math.sqrt(start_end_x_dist * start_end_x_dist + start_end_y_dist * start_end_y_dist); - const mid_end_dist = Math.sqrt(mid_end_x_dist * mid_end_x_dist + mid_end_y_dist * mid_end_y_dist); - const max_dist = Math.max(start_mid_dist, start_end_dist, mid_end_dist); - let calc_start_point_x = startPoint[0]; - let calc_start_point_y = startPoint[1]; - let calc_end_point_x = endPoint[0]; - let calc_end_point_y = endPoint[1]; - if (max_dist === start_mid_dist) { - calc_end_point_x = endPoint[0]; - calc_end_point_y = endPoint[1]; - } else if (max_dist === mid_end_dist) { - calc_start_point_x = midPoint[0]; - calc_start_point_y = midPoint[1]; - } - const calcStartPoint = [calc_start_point_x, calc_start_point_y]; - const calcEndPoint = [calc_end_point_x, calc_end_point_y]; - const totalAngle = getSlopes(calcStartPoint, calcEndPoint); - const votes = angleOrientationAt(totalAngle, options3.TOTAL_ANGLE_VOTE_POWER); - voteVertical += votes[0]; - voteDiagonal += votes[1]; - voteHorizontal += votes[2]; - for (const fingerSlope of fingerSlopes) { - const fingerVotes = angleOrientationAt(fingerSlope, options3.SINGLE_ANGLE_VOTE_POWER); - voteVertical += fingerVotes[0]; - voteDiagonal += fingerVotes[1]; - voteHorizontal += fingerVotes[2]; - } - let estimatedDirection; - if (voteVertical === Math.max(voteVertical, voteDiagonal, voteHorizontal)) { - estimatedDirection = estimateVerticalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y); - } else if (voteHorizontal === Math.max(voteDiagonal, voteHorizontal)) { - estimatedDirection = estimateHorizontalDirection(start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x); - } else { - estimatedDirection = estimateDiagonalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y, start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x); - } - return estimatedDirection; -} -function estimate(landmarks) { - const slopesXY = []; - const slopesYZ = []; - const fingerCurls = []; - const fingerDirections = []; - if (!landmarks) - return { curls: fingerCurls, directions: fingerDirections }; - for (const finger of Finger.all) { - const points = Finger.getPoints(finger); - const slopeAtXY = []; - const slopeAtYZ = []; - for (const point2 of points) { - const point1 = landmarks[point2[0]]; - const point22 = landmarks[point2[1]]; - const slopes = getSlopes(point1, point22); - const slopeXY = slopes[0]; - const slopeYZ = slopes[1]; - slopeAtXY.push(slopeXY); - slopeAtYZ.push(slopeYZ); - } - slopesXY.push(slopeAtXY); - slopesYZ.push(slopeAtYZ); - } - for (const finger of Finger.all) { - const pointIndexAt = finger === Finger.thumb ? 1 : 0; - const fingerPointsAt = Finger.getPoints(finger); - const startPoint = landmarks[fingerPointsAt[pointIndexAt][0]]; - const midPoint = landmarks[fingerPointsAt[pointIndexAt + 1][1]]; - const endPoint = landmarks[fingerPointsAt[3][1]]; - const fingerCurled = estimateFingerCurl(startPoint, midPoint, endPoint); - const fingerPosition = calculateFingerDirection(startPoint, midPoint, endPoint, slopesXY[finger].slice(pointIndexAt)); - fingerCurls[finger] = fingerCurled; - fingerDirections[finger] = fingerPosition; - } - return { curls: fingerCurls, directions: fingerDirections }; -} -function analyze(keypoints) { - if (!keypoints || keypoints.length === 0) - return null; - const estimatorRes = estimate(keypoints); - const landmarks = {}; - for (const fingerIdx of Finger.all) { - landmarks[Finger.getName(fingerIdx)] = { - curl: FingerCurl.getName(estimatorRes.curls[fingerIdx]), - direction: FingerDirection.getName(estimatorRes.directions[fingerIdx]) - }; - } - return landmarks; -} -function match(keypoints) { - const poses = []; - if (!keypoints || keypoints.length === 0) - return poses; - const estimatorRes = estimate(keypoints); - for (const gesture2 of fingergesture_default) { - const confidence = gesture2.matchAgainst(estimatorRes.curls, estimatorRes.directions); - if (confidence >= minConfidence) - poses.push({ name: gesture2.name, confidence }); - } - return poses; -} - -// src/gesture/gesture.ts -var body2 = (res) => { - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - const leftWrist = res[i].keypoints.find((a) => a.part === "leftWrist"); - const rightWrist = res[i].keypoints.find((a) => a.part === "rightWrist"); - const nose = res[i].keypoints.find((a) => a.part === "nose"); - if (nose && leftWrist && rightWrist && leftWrist.position[1] < nose.position[1] && rightWrist.position[1] < nose.position[1]) - gestures.push({ body: i, gesture: "i give up" }); - else if (nose && leftWrist && leftWrist.position[1] < nose.position[1]) - gestures.push({ body: i, gesture: "raise left hand" }); - else if (nose && rightWrist && rightWrist.position[1] < nose.position[1]) - gestures.push({ body: i, gesture: "raise right hand" }); - const leftShoulder = res[i].keypoints.find((a) => a.part === "leftShoulder"); - const rightShoulder = res[i].keypoints.find((a) => a.part === "rightShoulder"); - if (leftShoulder && rightShoulder && Math.abs(leftShoulder.positionRaw[1] - rightShoulder.positionRaw[1]) > 0.1) { - gestures.push({ body: i, gesture: `leaning ${leftShoulder.position[1] > rightShoulder.position[1] ? "left" : "right"}` }); - } - } - return gestures; -}; -var face2 = (res) => { - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - if (res[i].mesh && res[i].mesh.length > 450) { - const zDiff = (res[i].mesh[33][2] || 0) - (res[i].mesh[263][2] || 0); - const xDiff = res[i].mesh[33][0] - res[i].mesh[263][0]; - if (Math.abs(zDiff / xDiff) <= 0.15) - gestures.push({ face: i, gesture: "facing center" }); - else - gestures.push({ face: i, gesture: `facing ${zDiff < 0 ? "left" : "right"}` }); - const openLeft = Math.abs(res[i].mesh[374][1] - res[i].mesh[386][1]) / Math.abs(res[i].mesh[443][1] - res[i].mesh[450][1]); - if (openLeft < 0.2) - gestures.push({ face: i, gesture: "blink left eye" }); - const openRight = Math.abs(res[i].mesh[145][1] - res[i].mesh[159][1]) / Math.abs(res[i].mesh[223][1] - res[i].mesh[230][1]); - if (openRight < 0.2) - gestures.push({ face: i, gesture: "blink right eye" }); - const mouthOpen = Math.min(100, 500 * Math.abs(res[i].mesh[13][1] - res[i].mesh[14][1]) / Math.abs(res[i].mesh[10][1] - res[i].mesh[152][1])); - if (mouthOpen > 10) - gestures.push({ face: i, gesture: `mouth ${Math.trunc(mouthOpen)}% open` }); - const chinDepth = res[i].mesh[152][2] || 0; - if (Math.abs(chinDepth) > 10) - gestures.push({ face: i, gesture: `head ${chinDepth < 0 ? "up" : "down"}` }); - } - } - return gestures; -}; -var iris2 = (res) => { - var _a, _b, _c, _d; - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - if (!((_b = (_a = res[i].annotations) == null ? void 0 : _a.leftEyeIris) == null ? void 0 : _b[0]) || !((_d = (_c = res[i].annotations) == null ? void 0 : _c.rightEyeIris) == null ? void 0 : _d[0])) - continue; - const sizeXLeft = res[i].annotations.leftEyeIris[3][0] - res[i].annotations.leftEyeIris[1][0]; - const sizeYLeft = res[i].annotations.leftEyeIris[4][1] - res[i].annotations.leftEyeIris[2][1]; - const areaLeft = Math.abs(sizeXLeft * sizeYLeft); - const sizeXRight = res[i].annotations.rightEyeIris[3][0] - res[i].annotations.rightEyeIris[1][0]; - const sizeYRight = res[i].annotations.rightEyeIris[4][1] - res[i].annotations.rightEyeIris[2][1]; - const areaRight = Math.abs(sizeXRight * sizeYRight); - let center = false; - const difference = Math.abs(areaLeft - areaRight) / Math.max(areaLeft, areaRight); - if (difference < 0.25) { - center = true; - gestures.push({ iris: i, gesture: "facing center" }); - } - const leftIrisCenterX = Math.abs(res[i].mesh[263][0] - res[i].annotations.leftEyeIris[0][0]) / res[i].box[2]; - const rightIrisCenterX = Math.abs(res[i].mesh[33][0] - res[i].annotations.rightEyeIris[0][0]) / res[i].box[2]; - if (leftIrisCenterX > 0.06 || rightIrisCenterX > 0.06) - center = false; - if (leftIrisCenterX > rightIrisCenterX) { - if (leftIrisCenterX > 0.05) - gestures.push({ iris: i, gesture: "looking right" }); - } else { - if (rightIrisCenterX > 0.05) - gestures.push({ iris: i, gesture: "looking left" }); - } - const rightIrisCenterY = Math.abs(res[i].mesh[145][1] - res[i].annotations.rightEyeIris[0][1]) / res[i].box[3]; - const leftIrisCenterY = Math.abs(res[i].mesh[374][1] - res[i].annotations.leftEyeIris[0][1]) / res[i].box[3]; - if (leftIrisCenterY < 0.01 || rightIrisCenterY < 0.01 || leftIrisCenterY > 0.022 || rightIrisCenterY > 0.022) - center = false; - if (leftIrisCenterY < 0.01 || rightIrisCenterY < 0.01) - gestures.push({ iris: i, gesture: "looking down" }); - if (leftIrisCenterY > 0.022 || rightIrisCenterY > 0.022) - gestures.push({ iris: i, gesture: "looking up" }); - if (center) - gestures.push({ iris: i, gesture: "looking center" }); - } - return gestures; -}; -var hand2 = (res) => { - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - const fingers = []; - if (res[i].annotations) { - for (const [finger, pos] of Object.entries(res[i].annotations)) { - if (finger !== "palmBase" && Array.isArray(pos) && pos[0]) - fingers.push({ name: finger.toLowerCase(), position: pos[0] }); - } - } - if (fingers && fingers.length > 0) { - const closest = fingers.reduce((best, a) => (best.position[2] || 0) < (a.position[2] || 0) ? best : a); - gestures.push({ hand: i, gesture: `${closest.name} forward` }); - const highest = fingers.reduce((best, a) => best.position[1] < a.position[1] ? best : a); - gestures.push({ hand: i, gesture: `${highest.name} up` }); - } - if (res[i].keypoints) { - const poses = match(res[i].keypoints); - for (const pose of poses) - gestures.push({ hand: i, gesture: pose.name }); - } - } - return gestures; -}; - -// src/hand/handposedetector.ts -var tf27 = __toESM(require_tfjs_esm()); - -// src/hand/handposeutil.ts -var tf26 = __toESM(require_tfjs_esm()); -function getBoxSize2(box) { - return [ - Math.abs(box.endPoint[0] - box.startPoint[0]), - Math.abs(box.endPoint[1] - box.startPoint[1]) - ]; -} -function getBoxCenter2(box) { - return [ - box.startPoint[0] + (box.endPoint[0] - box.startPoint[0]) / 2, - box.startPoint[1] + (box.endPoint[1] - box.startPoint[1]) / 2 - ]; -} -function cutBoxFromImageAndResize(box, image28, cropSize) { - const h = image28.shape[1]; - const w = image28.shape[2]; - const boxes = [[ - box.startPoint[1] / h, - box.startPoint[0] / w, - box.endPoint[1] / h, - box.endPoint[0] / w - ]]; - return tf26.image.cropAndResize(image28, boxes, [0], cropSize); -} -function scaleBoxCoordinates2(box, factor) { - const startPoint = [box.startPoint[0] * factor[0], box.startPoint[1] * factor[1]]; - const endPoint = [box.endPoint[0] * factor[0], box.endPoint[1] * factor[1]]; - const palmLandmarks = box.palmLandmarks.map((coord) => { - const scaledCoord = [coord[0] * factor[0], coord[1] * factor[1]]; - return scaledCoord; - }); - return { startPoint, endPoint, palmLandmarks, confidence: box.confidence }; -} -function enlargeBox2(box, factor = 1.5) { - const center = getBoxCenter2(box); - const size2 = getBoxSize2(box); - const newHalfSize = [factor * size2[0] / 2, factor * size2[1] / 2]; - const startPoint = [center[0] - newHalfSize[0], center[1] - newHalfSize[1]]; - const endPoint = [center[0] + newHalfSize[0], center[1] + newHalfSize[1]]; - return { startPoint, endPoint, palmLandmarks: box.palmLandmarks }; -} -function squarifyBox2(box) { - const centers = getBoxCenter2(box); - const size2 = getBoxSize2(box); - const maxEdge = Math.max(...size2); - const halfSize = maxEdge / 2; - const startPoint = [centers[0] - halfSize, centers[1] - halfSize]; - const endPoint = [centers[0] + halfSize, centers[1] + halfSize]; - return { startPoint, endPoint, palmLandmarks: box.palmLandmarks }; -} -function normalizeRadians2(angle) { - return angle - 2 * Math.PI * Math.floor((angle + Math.PI) / (2 * Math.PI)); -} -function computeRotation2(point1, point2) { - const radians = Math.PI / 2 - Math.atan2(-(point2[1] - point1[1]), point2[0] - point1[0]); - return normalizeRadians2(radians); -} -var buildTranslationMatrix2 = (x, y) => [[1, 0, x], [0, 1, y], [0, 0, 1]]; -function dot2(v1, v2) { - let product = 0; - for (let i = 0; i < v1.length; i++) { - product += v1[i] * v2[i]; - } - return product; -} -function getColumnFrom2DArr2(arr, columnIndex) { - const column = []; - for (let i = 0; i < arr.length; i++) { - column.push(arr[i][columnIndex]); - } - return column; -} -function multiplyTransformMatrices2(mat1, mat2) { - const product = []; - const size2 = mat1.length; - for (let row = 0; row < size2; row++) { - product.push([]); - for (let col = 0; col < size2; col++) { - product[row].push(dot2(mat1[row], getColumnFrom2DArr2(mat2, col))); - } - } - return product; -} -function buildRotationMatrix2(rotation, center) { - const cosA = Math.cos(rotation); - const sinA = Math.sin(rotation); - const rotationMatrix = [[cosA, -sinA, 0], [sinA, cosA, 0], [0, 0, 1]]; - const translationMatrix = buildTranslationMatrix2(center[0], center[1]); - const translationTimesRotation = multiplyTransformMatrices2(translationMatrix, rotationMatrix); - const negativeTranslationMatrix = buildTranslationMatrix2(-center[0], -center[1]); - return multiplyTransformMatrices2(translationTimesRotation, negativeTranslationMatrix); -} -function invertTransformMatrix2(matrix) { - const rotationComponent = [[matrix[0][0], matrix[1][0]], [matrix[0][1], matrix[1][1]]]; - const translationComponent = [matrix[0][2], matrix[1][2]]; - const invertedTranslation = [ - -dot2(rotationComponent[0], translationComponent), - -dot2(rotationComponent[1], translationComponent) - ]; - return [ - rotationComponent[0].concat(invertedTranslation[0]), - rotationComponent[1].concat(invertedTranslation[1]), - [0, 0, 1] - ]; -} -function rotatePoint2(homogeneousCoordinate, rotationMatrix) { - return [ - dot2(homogeneousCoordinate, rotationMatrix[0]), - dot2(homogeneousCoordinate, rotationMatrix[1]) - ]; -} - -// src/hand/handposeanchors.ts -var anchors2 = [ - { x: 0.015625, y: 0.015625 }, - { x: 0.015625, y: 0.015625 }, - { x: 0.046875, y: 0.015625 }, - { x: 0.046875, y: 0.015625 }, - { x: 0.078125, y: 0.015625 }, - { x: 0.078125, y: 0.015625 }, - { x: 0.109375, y: 0.015625 }, - { x: 0.109375, y: 0.015625 }, - { x: 0.140625, y: 0.015625 }, - { x: 0.140625, y: 0.015625 }, - { x: 0.171875, y: 0.015625 }, - { x: 0.171875, y: 0.015625 }, - { x: 0.203125, y: 0.015625 }, - { x: 0.203125, y: 0.015625 }, - { x: 0.234375, y: 0.015625 }, - { x: 0.234375, y: 0.015625 }, - { x: 0.265625, y: 0.015625 }, - { x: 0.265625, y: 0.015625 }, - { x: 0.296875, y: 0.015625 }, - { x: 0.296875, y: 0.015625 }, - { x: 0.328125, y: 0.015625 }, - { x: 0.328125, y: 0.015625 }, - { x: 0.359375, y: 0.015625 }, - { x: 0.359375, y: 0.015625 }, - { x: 0.390625, y: 0.015625 }, - { x: 0.390625, y: 0.015625 }, - { x: 0.421875, y: 0.015625 }, - { x: 0.421875, y: 0.015625 }, - { x: 0.453125, y: 0.015625 }, - { x: 0.453125, y: 0.015625 }, - { x: 0.484375, y: 0.015625 }, - { x: 0.484375, y: 0.015625 }, - { x: 0.515625, y: 0.015625 }, - { x: 0.515625, y: 0.015625 }, - { x: 0.546875, y: 0.015625 }, - { x: 0.546875, y: 0.015625 }, - { x: 0.578125, y: 0.015625 }, - { x: 0.578125, y: 0.015625 }, - { x: 0.609375, y: 0.015625 }, - { x: 0.609375, y: 0.015625 }, - { x: 0.640625, y: 0.015625 }, - { x: 0.640625, y: 0.015625 }, - { x: 0.671875, y: 0.015625 }, - { x: 0.671875, y: 0.015625 }, - { x: 0.703125, y: 0.015625 }, - { x: 0.703125, y: 0.015625 }, - { x: 0.734375, y: 0.015625 }, - { x: 0.734375, y: 0.015625 }, - { x: 0.765625, y: 0.015625 }, - { x: 0.765625, y: 0.015625 }, - { x: 0.796875, y: 0.015625 }, - { x: 0.796875, y: 0.015625 }, - { x: 0.828125, y: 0.015625 }, - { x: 0.828125, y: 0.015625 }, - { x: 0.859375, y: 0.015625 }, - { x: 0.859375, y: 0.015625 }, - { x: 0.890625, y: 0.015625 }, - { x: 0.890625, y: 0.015625 }, - { x: 0.921875, y: 0.015625 }, - { x: 0.921875, y: 0.015625 }, - { x: 0.953125, y: 0.015625 }, - { x: 0.953125, y: 0.015625 }, - { x: 0.984375, y: 0.015625 }, - { x: 0.984375, y: 0.015625 }, - { x: 0.015625, y: 0.046875 }, - { x: 0.015625, y: 0.046875 }, - { x: 0.046875, y: 0.046875 }, - { x: 0.046875, y: 0.046875 }, - { x: 0.078125, y: 0.046875 }, - { x: 0.078125, y: 0.046875 }, - { x: 0.109375, y: 0.046875 }, - { x: 0.109375, y: 0.046875 }, - { x: 0.140625, y: 0.046875 }, - { x: 0.140625, y: 0.046875 }, - { x: 0.171875, y: 0.046875 }, - { x: 0.171875, y: 0.046875 }, - { x: 0.203125, y: 0.046875 }, - { x: 0.203125, y: 0.046875 }, - { x: 0.234375, y: 0.046875 }, - { x: 0.234375, y: 0.046875 }, - { x: 0.265625, y: 0.046875 }, - { x: 0.265625, y: 0.046875 }, - { x: 0.296875, y: 0.046875 }, - { x: 0.296875, y: 0.046875 }, - { x: 0.328125, y: 0.046875 }, - { x: 0.328125, y: 0.046875 }, - { x: 0.359375, y: 0.046875 }, - { x: 0.359375, y: 0.046875 }, - { x: 0.390625, y: 0.046875 }, - { x: 0.390625, y: 0.046875 }, - { x: 0.421875, y: 0.046875 }, - { x: 0.421875, y: 0.046875 }, - { x: 0.453125, y: 0.046875 }, - { x: 0.453125, y: 0.046875 }, - { x: 0.484375, y: 0.046875 }, - { x: 0.484375, y: 0.046875 }, - { x: 0.515625, y: 0.046875 }, - { x: 0.515625, y: 0.046875 }, - { x: 0.546875, y: 0.046875 }, - { x: 0.546875, y: 0.046875 }, - { x: 0.578125, y: 0.046875 }, - { x: 0.578125, y: 0.046875 }, - { x: 0.609375, y: 0.046875 }, - { x: 0.609375, y: 0.046875 }, - { x: 0.640625, y: 0.046875 }, - { x: 0.640625, y: 0.046875 }, - { x: 0.671875, y: 0.046875 }, - { x: 0.671875, y: 0.046875 }, - { x: 0.703125, y: 0.046875 }, - { x: 0.703125, y: 0.046875 }, - { x: 0.734375, y: 0.046875 }, - { x: 0.734375, y: 0.046875 }, - { x: 0.765625, y: 0.046875 }, - { x: 0.765625, y: 0.046875 }, - { x: 0.796875, y: 0.046875 }, - { x: 0.796875, y: 0.046875 }, - { x: 0.828125, y: 0.046875 }, - { x: 0.828125, y: 0.046875 }, - { x: 0.859375, y: 0.046875 }, - { x: 0.859375, y: 0.046875 }, - { x: 0.890625, y: 0.046875 }, - { x: 0.890625, y: 0.046875 }, - { x: 0.921875, y: 0.046875 }, - { x: 0.921875, y: 0.046875 }, - { x: 0.953125, y: 0.046875 }, - { x: 0.953125, y: 0.046875 }, - { x: 0.984375, y: 0.046875 }, - { x: 0.984375, y: 0.046875 }, - { x: 0.015625, y: 0.078125 }, - { x: 0.015625, y: 0.078125 }, - { x: 0.046875, y: 0.078125 }, - { x: 0.046875, y: 0.078125 }, - { x: 0.078125, y: 0.078125 }, - { x: 0.078125, y: 0.078125 }, - { x: 0.109375, y: 0.078125 }, - { x: 0.109375, y: 0.078125 }, - { x: 0.140625, y: 0.078125 }, - { x: 0.140625, y: 0.078125 }, - { x: 0.171875, y: 0.078125 }, - { x: 0.171875, y: 0.078125 }, - { x: 0.203125, y: 0.078125 }, - { x: 0.203125, y: 0.078125 }, - { x: 0.234375, y: 0.078125 }, - { x: 0.234375, y: 0.078125 }, - { x: 0.265625, y: 0.078125 }, - { x: 0.265625, y: 0.078125 }, - { x: 0.296875, y: 0.078125 }, - { x: 0.296875, y: 0.078125 }, - { x: 0.328125, y: 0.078125 }, - { x: 0.328125, y: 0.078125 }, - { x: 0.359375, y: 0.078125 }, - { x: 0.359375, y: 0.078125 }, - { x: 0.390625, y: 0.078125 }, - { x: 0.390625, y: 0.078125 }, - { x: 0.421875, y: 0.078125 }, - { x: 0.421875, y: 0.078125 }, - { x: 0.453125, y: 0.078125 }, - { x: 0.453125, y: 0.078125 }, - { x: 0.484375, y: 0.078125 }, - { x: 0.484375, y: 0.078125 }, - { x: 0.515625, y: 0.078125 }, - { x: 0.515625, y: 0.078125 }, - { x: 0.546875, y: 0.078125 }, - { x: 0.546875, y: 0.078125 }, - { x: 0.578125, y: 0.078125 }, - { x: 0.578125, y: 0.078125 }, - { x: 0.609375, y: 0.078125 }, - { x: 0.609375, y: 0.078125 }, - { x: 0.640625, y: 0.078125 }, - { x: 0.640625, y: 0.078125 }, - { x: 0.671875, y: 0.078125 }, - { x: 0.671875, y: 0.078125 }, - { x: 0.703125, y: 0.078125 }, - { x: 0.703125, y: 0.078125 }, - { x: 0.734375, y: 0.078125 }, - { x: 0.734375, y: 0.078125 }, - { x: 0.765625, y: 0.078125 }, - { x: 0.765625, y: 0.078125 }, - { x: 0.796875, y: 0.078125 }, - { x: 0.796875, y: 0.078125 }, - { x: 0.828125, y: 0.078125 }, - { x: 0.828125, y: 0.078125 }, - { x: 0.859375, y: 0.078125 }, - { x: 0.859375, y: 0.078125 }, - { x: 0.890625, y: 0.078125 }, - { x: 0.890625, y: 0.078125 }, - { x: 0.921875, y: 0.078125 }, - { x: 0.921875, y: 0.078125 }, - { x: 0.953125, y: 0.078125 }, - { x: 0.953125, y: 0.078125 }, - { x: 0.984375, y: 0.078125 }, - { x: 0.984375, y: 0.078125 }, - { x: 0.015625, y: 0.109375 }, - { x: 0.015625, y: 0.109375 }, - { x: 0.046875, y: 0.109375 }, - { x: 0.046875, y: 0.109375 }, - { x: 0.078125, y: 0.109375 }, - { x: 0.078125, y: 0.109375 }, - { x: 0.109375, y: 0.109375 }, - { x: 0.109375, y: 0.109375 }, - { x: 0.140625, y: 0.109375 }, - { x: 0.140625, y: 0.109375 }, - { x: 0.171875, y: 0.109375 }, - { x: 0.171875, y: 0.109375 }, - { x: 0.203125, y: 0.109375 }, - { x: 0.203125, y: 0.109375 }, - { x: 0.234375, y: 0.109375 }, - { x: 0.234375, y: 0.109375 }, - { x: 0.265625, y: 0.109375 }, - { x: 0.265625, y: 0.109375 }, - { x: 0.296875, y: 0.109375 }, - { x: 0.296875, y: 0.109375 }, - { x: 0.328125, y: 0.109375 }, - { x: 0.328125, y: 0.109375 }, - { x: 0.359375, y: 0.109375 }, - { x: 0.359375, y: 0.109375 }, - { x: 0.390625, y: 0.109375 }, - { x: 0.390625, y: 0.109375 }, - { x: 0.421875, y: 0.109375 }, - { x: 0.421875, y: 0.109375 }, - { x: 0.453125, y: 0.109375 }, - { x: 0.453125, y: 0.109375 }, - { x: 0.484375, y: 0.109375 }, - { x: 0.484375, y: 0.109375 }, - { x: 0.515625, y: 0.109375 }, - { x: 0.515625, y: 0.109375 }, - { x: 0.546875, y: 0.109375 }, - { x: 0.546875, y: 0.109375 }, - { x: 0.578125, y: 0.109375 }, - { x: 0.578125, y: 0.109375 }, - { x: 0.609375, y: 0.109375 }, - { x: 0.609375, y: 0.109375 }, - { x: 0.640625, y: 0.109375 }, - { x: 0.640625, y: 0.109375 }, - { x: 0.671875, y: 0.109375 }, - { x: 0.671875, y: 0.109375 }, - { x: 0.703125, y: 0.109375 }, - { x: 0.703125, y: 0.109375 }, - { x: 0.734375, y: 0.109375 }, - { x: 0.734375, y: 0.109375 }, - { x: 0.765625, y: 0.109375 }, - { x: 0.765625, y: 0.109375 }, - { x: 0.796875, y: 0.109375 }, - { x: 0.796875, y: 0.109375 }, - { x: 0.828125, y: 0.109375 }, - { x: 0.828125, y: 0.109375 }, - { x: 0.859375, y: 0.109375 }, - { x: 0.859375, y: 0.109375 }, - { x: 0.890625, y: 0.109375 }, - { x: 0.890625, y: 0.109375 }, - { x: 0.921875, y: 0.109375 }, - { x: 0.921875, y: 0.109375 }, - { x: 0.953125, y: 0.109375 }, - { x: 0.953125, y: 0.109375 }, - { x: 0.984375, y: 0.109375 }, - { x: 0.984375, y: 0.109375 }, - { x: 0.015625, y: 0.140625 }, - { x: 0.015625, y: 0.140625 }, - { x: 0.046875, y: 0.140625 }, - { x: 0.046875, y: 0.140625 }, - { x: 0.078125, y: 0.140625 }, - { x: 0.078125, y: 0.140625 }, - { x: 0.109375, y: 0.140625 }, - { x: 0.109375, y: 0.140625 }, - { x: 0.140625, y: 0.140625 }, - { x: 0.140625, y: 0.140625 }, - { x: 0.171875, y: 0.140625 }, - { x: 0.171875, y: 0.140625 }, - { x: 0.203125, y: 0.140625 }, - { x: 0.203125, y: 0.140625 }, - { x: 0.234375, y: 0.140625 }, - { x: 0.234375, y: 0.140625 }, - { x: 0.265625, y: 0.140625 }, - { x: 0.265625, y: 0.140625 }, - { x: 0.296875, y: 0.140625 }, - { x: 0.296875, y: 0.140625 }, - { x: 0.328125, y: 0.140625 }, - { x: 0.328125, y: 0.140625 }, - { x: 0.359375, y: 0.140625 }, - { x: 0.359375, y: 0.140625 }, - { x: 0.390625, y: 0.140625 }, - { x: 0.390625, y: 0.140625 }, - { x: 0.421875, y: 0.140625 }, - { x: 0.421875, y: 0.140625 }, - { x: 0.453125, y: 0.140625 }, - { x: 0.453125, y: 0.140625 }, - { x: 0.484375, y: 0.140625 }, - { x: 0.484375, y: 0.140625 }, - { x: 0.515625, y: 0.140625 }, - { x: 0.515625, y: 0.140625 }, - { x: 0.546875, y: 0.140625 }, - { x: 0.546875, y: 0.140625 }, - { x: 0.578125, y: 0.140625 }, - { x: 0.578125, y: 0.140625 }, - { x: 0.609375, y: 0.140625 }, - { x: 0.609375, y: 0.140625 }, - { x: 0.640625, y: 0.140625 }, - { x: 0.640625, y: 0.140625 }, - { x: 0.671875, y: 0.140625 }, - { x: 0.671875, y: 0.140625 }, - { x: 0.703125, y: 0.140625 }, - { x: 0.703125, y: 0.140625 }, - { x: 0.734375, y: 0.140625 }, - { x: 0.734375, y: 0.140625 }, - { x: 0.765625, y: 0.140625 }, - { x: 0.765625, y: 0.140625 }, - { x: 0.796875, y: 0.140625 }, - { x: 0.796875, y: 0.140625 }, - { x: 0.828125, y: 0.140625 }, - { x: 0.828125, y: 0.140625 }, - { x: 0.859375, y: 0.140625 }, - { x: 0.859375, y: 0.140625 }, - { x: 0.890625, y: 0.140625 }, - { x: 0.890625, y: 0.140625 }, - { x: 0.921875, y: 0.140625 }, - { x: 0.921875, y: 0.140625 }, - { x: 0.953125, y: 0.140625 }, - { x: 0.953125, y: 0.140625 }, - { x: 0.984375, y: 0.140625 }, - { x: 0.984375, y: 0.140625 }, - { x: 0.015625, y: 0.171875 }, - { x: 0.015625, y: 0.171875 }, - { x: 0.046875, y: 0.171875 }, - { x: 0.046875, y: 0.171875 }, - { x: 0.078125, y: 0.171875 }, - { x: 0.078125, y: 0.171875 }, - { x: 0.109375, y: 0.171875 }, - { x: 0.109375, y: 0.171875 }, - { x: 0.140625, y: 0.171875 }, - { x: 0.140625, y: 0.171875 }, - { x: 0.171875, y: 0.171875 }, - { x: 0.171875, y: 0.171875 }, - { x: 0.203125, y: 0.171875 }, - { x: 0.203125, y: 0.171875 }, - { x: 0.234375, y: 0.171875 }, - { x: 0.234375, y: 0.171875 }, - { x: 0.265625, y: 0.171875 }, - { x: 0.265625, y: 0.171875 }, - { x: 0.296875, y: 0.171875 }, - { x: 0.296875, y: 0.171875 }, - { x: 0.328125, y: 0.171875 }, - { x: 0.328125, y: 0.171875 }, - { x: 0.359375, y: 0.171875 }, - { x: 0.359375, y: 0.171875 }, - { x: 0.390625, y: 0.171875 }, - { x: 0.390625, y: 0.171875 }, - { x: 0.421875, y: 0.171875 }, - { x: 0.421875, y: 0.171875 }, - { x: 0.453125, y: 0.171875 }, - { x: 0.453125, y: 0.171875 }, - { x: 0.484375, y: 0.171875 }, - { x: 0.484375, y: 0.171875 }, - { x: 0.515625, y: 0.171875 }, - { x: 0.515625, y: 0.171875 }, - { x: 0.546875, y: 0.171875 }, - { x: 0.546875, y: 0.171875 }, - { x: 0.578125, y: 0.171875 }, - { x: 0.578125, y: 0.171875 }, - { x: 0.609375, y: 0.171875 }, - { x: 0.609375, y: 0.171875 }, - { x: 0.640625, y: 0.171875 }, - { x: 0.640625, y: 0.171875 }, - { x: 0.671875, y: 0.171875 }, - { x: 0.671875, y: 0.171875 }, - { x: 0.703125, y: 0.171875 }, - { x: 0.703125, y: 0.171875 }, - { x: 0.734375, y: 0.171875 }, - { x: 0.734375, y: 0.171875 }, - { x: 0.765625, y: 0.171875 }, - { x: 0.765625, y: 0.171875 }, - { x: 0.796875, y: 0.171875 }, - { x: 0.796875, y: 0.171875 }, - { x: 0.828125, y: 0.171875 }, - { x: 0.828125, y: 0.171875 }, - { x: 0.859375, y: 0.171875 }, - { x: 0.859375, y: 0.171875 }, - { x: 0.890625, y: 0.171875 }, - { x: 0.890625, y: 0.171875 }, - { x: 0.921875, y: 0.171875 }, - { x: 0.921875, y: 0.171875 }, - { x: 0.953125, y: 0.171875 }, - { x: 0.953125, y: 0.171875 }, - { x: 0.984375, y: 0.171875 }, - { x: 0.984375, y: 0.171875 }, - { x: 0.015625, y: 0.203125 }, - { x: 0.015625, y: 0.203125 }, - { x: 0.046875, y: 0.203125 }, - { x: 0.046875, y: 0.203125 }, - { x: 0.078125, y: 0.203125 }, - { x: 0.078125, y: 0.203125 }, - { x: 0.109375, y: 0.203125 }, - { x: 0.109375, y: 0.203125 }, - { x: 0.140625, y: 0.203125 }, - { x: 0.140625, y: 0.203125 }, - { x: 0.171875, y: 0.203125 }, - { x: 0.171875, y: 0.203125 }, - { x: 0.203125, y: 0.203125 }, - { x: 0.203125, y: 0.203125 }, - { x: 0.234375, y: 0.203125 }, - { x: 0.234375, y: 0.203125 }, - { x: 0.265625, y: 0.203125 }, - { x: 0.265625, y: 0.203125 }, - { x: 0.296875, y: 0.203125 }, - { x: 0.296875, y: 0.203125 }, - { x: 0.328125, y: 0.203125 }, - { x: 0.328125, y: 0.203125 }, - { x: 0.359375, y: 0.203125 }, - { x: 0.359375, y: 0.203125 }, - { x: 0.390625, y: 0.203125 }, - { x: 0.390625, y: 0.203125 }, - { x: 0.421875, y: 0.203125 }, - { x: 0.421875, y: 0.203125 }, - { x: 0.453125, y: 0.203125 }, - { x: 0.453125, y: 0.203125 }, - { x: 0.484375, y: 0.203125 }, - { x: 0.484375, y: 0.203125 }, - { x: 0.515625, y: 0.203125 }, - { x: 0.515625, y: 0.203125 }, - { x: 0.546875, y: 0.203125 }, - { x: 0.546875, y: 0.203125 }, - { x: 0.578125, y: 0.203125 }, - { x: 0.578125, y: 0.203125 }, - { x: 0.609375, y: 0.203125 }, - { x: 0.609375, y: 0.203125 }, - { x: 0.640625, y: 0.203125 }, - { x: 0.640625, y: 0.203125 }, - { x: 0.671875, y: 0.203125 }, - { x: 0.671875, y: 0.203125 }, - { x: 0.703125, y: 0.203125 }, - { x: 0.703125, y: 0.203125 }, - { x: 0.734375, y: 0.203125 }, - { x: 0.734375, y: 0.203125 }, - { x: 0.765625, y: 0.203125 }, - { x: 0.765625, y: 0.203125 }, - { x: 0.796875, y: 0.203125 }, - { x: 0.796875, y: 0.203125 }, - { x: 0.828125, y: 0.203125 }, - { x: 0.828125, y: 0.203125 }, - { x: 0.859375, y: 0.203125 }, - { x: 0.859375, y: 0.203125 }, - { x: 0.890625, y: 0.203125 }, - { x: 0.890625, y: 0.203125 }, - { x: 0.921875, y: 0.203125 }, - { x: 0.921875, y: 0.203125 }, - { x: 0.953125, y: 0.203125 }, - { x: 0.953125, y: 0.203125 }, - { x: 0.984375, y: 0.203125 }, - { x: 0.984375, y: 0.203125 }, - { x: 0.015625, y: 0.234375 }, - { x: 0.015625, y: 0.234375 }, - { x: 0.046875, y: 0.234375 }, - { x: 0.046875, y: 0.234375 }, - { x: 0.078125, y: 0.234375 }, - { x: 0.078125, y: 0.234375 }, - { x: 0.109375, y: 0.234375 }, - { x: 0.109375, y: 0.234375 }, - { x: 0.140625, y: 0.234375 }, - { x: 0.140625, y: 0.234375 }, - { x: 0.171875, y: 0.234375 }, - { x: 0.171875, y: 0.234375 }, - { x: 0.203125, y: 0.234375 }, - { x: 0.203125, y: 0.234375 }, - { x: 0.234375, y: 0.234375 }, - { x: 0.234375, y: 0.234375 }, - { x: 0.265625, y: 0.234375 }, - { x: 0.265625, y: 0.234375 }, - { x: 0.296875, y: 0.234375 }, - { x: 0.296875, y: 0.234375 }, - { x: 0.328125, y: 0.234375 }, - { x: 0.328125, y: 0.234375 }, - { x: 0.359375, y: 0.234375 }, - { x: 0.359375, y: 0.234375 }, - { x: 0.390625, y: 0.234375 }, - { x: 0.390625, y: 0.234375 }, - { x: 0.421875, y: 0.234375 }, - { x: 0.421875, y: 0.234375 }, - { x: 0.453125, y: 0.234375 }, - { x: 0.453125, y: 0.234375 }, - { x: 0.484375, y: 0.234375 }, - { x: 0.484375, y: 0.234375 }, - { x: 0.515625, y: 0.234375 }, - { x: 0.515625, y: 0.234375 }, - { x: 0.546875, y: 0.234375 }, - { x: 0.546875, y: 0.234375 }, - { x: 0.578125, y: 0.234375 }, - { x: 0.578125, y: 0.234375 }, - { x: 0.609375, y: 0.234375 }, - { x: 0.609375, y: 0.234375 }, - { x: 0.640625, y: 0.234375 }, - { x: 0.640625, y: 0.234375 }, - { x: 0.671875, y: 0.234375 }, - { x: 0.671875, y: 0.234375 }, - { x: 0.703125, y: 0.234375 }, - { x: 0.703125, y: 0.234375 }, - { x: 0.734375, y: 0.234375 }, - { x: 0.734375, y: 0.234375 }, - { x: 0.765625, y: 0.234375 }, - { x: 0.765625, y: 0.234375 }, - { x: 0.796875, y: 0.234375 }, - { x: 0.796875, y: 0.234375 }, - { x: 0.828125, y: 0.234375 }, - { x: 0.828125, y: 0.234375 }, - { x: 0.859375, y: 0.234375 }, - { x: 0.859375, y: 0.234375 }, - { x: 0.890625, y: 0.234375 }, - { x: 0.890625, y: 0.234375 }, - { x: 0.921875, y: 0.234375 }, - { x: 0.921875, y: 0.234375 }, - { x: 0.953125, y: 0.234375 }, - { x: 0.953125, y: 0.234375 }, - { x: 0.984375, y: 0.234375 }, - { x: 0.984375, y: 0.234375 }, - { x: 0.015625, y: 0.265625 }, - { x: 0.015625, y: 0.265625 }, - { x: 0.046875, y: 0.265625 }, - { x: 0.046875, y: 0.265625 }, - { x: 0.078125, y: 0.265625 }, - { x: 0.078125, y: 0.265625 }, - { x: 0.109375, y: 0.265625 }, - { x: 0.109375, y: 0.265625 }, - { x: 0.140625, y: 0.265625 }, - { x: 0.140625, y: 0.265625 }, - { x: 0.171875, y: 0.265625 }, - { x: 0.171875, y: 0.265625 }, - { x: 0.203125, y: 0.265625 }, - { x: 0.203125, y: 0.265625 }, - { x: 0.234375, y: 0.265625 }, - { x: 0.234375, y: 0.265625 }, - { x: 0.265625, y: 0.265625 }, - { x: 0.265625, y: 0.265625 }, - { x: 0.296875, y: 0.265625 }, - { x: 0.296875, y: 0.265625 }, - { x: 0.328125, y: 0.265625 }, - { x: 0.328125, y: 0.265625 }, - { x: 0.359375, y: 0.265625 }, - { x: 0.359375, y: 0.265625 }, - { x: 0.390625, y: 0.265625 }, - { x: 0.390625, y: 0.265625 }, - { x: 0.421875, y: 0.265625 }, - { x: 0.421875, y: 0.265625 }, - { x: 0.453125, y: 0.265625 }, - { x: 0.453125, y: 0.265625 }, - { x: 0.484375, y: 0.265625 }, - { x: 0.484375, y: 0.265625 }, - { x: 0.515625, y: 0.265625 }, - { x: 0.515625, y: 0.265625 }, - { x: 0.546875, y: 0.265625 }, - { x: 0.546875, y: 0.265625 }, - { x: 0.578125, y: 0.265625 }, - { x: 0.578125, y: 0.265625 }, - { x: 0.609375, y: 0.265625 }, - { x: 0.609375, y: 0.265625 }, - { x: 0.640625, y: 0.265625 }, - { x: 0.640625, y: 0.265625 }, - { x: 0.671875, y: 0.265625 }, - { x: 0.671875, y: 0.265625 }, - { x: 0.703125, y: 0.265625 }, - { x: 0.703125, y: 0.265625 }, - { x: 0.734375, y: 0.265625 }, - { x: 0.734375, y: 0.265625 }, - { x: 0.765625, y: 0.265625 }, - { x: 0.765625, y: 0.265625 }, - { x: 0.796875, y: 0.265625 }, - { x: 0.796875, y: 0.265625 }, - { x: 0.828125, y: 0.265625 }, - { x: 0.828125, y: 0.265625 }, - { x: 0.859375, y: 0.265625 }, - { x: 0.859375, y: 0.265625 }, - { x: 0.890625, y: 0.265625 }, - { x: 0.890625, y: 0.265625 }, - { x: 0.921875, y: 0.265625 }, - { x: 0.921875, y: 0.265625 }, - { x: 0.953125, y: 0.265625 }, - { x: 0.953125, y: 0.265625 }, - { x: 0.984375, y: 0.265625 }, - { x: 0.984375, y: 0.265625 }, - { x: 0.015625, y: 0.296875 }, - { x: 0.015625, y: 0.296875 }, - { x: 0.046875, y: 0.296875 }, - { x: 0.046875, y: 0.296875 }, - { x: 0.078125, y: 0.296875 }, - { x: 0.078125, y: 0.296875 }, - { x: 0.109375, y: 0.296875 }, - { x: 0.109375, y: 0.296875 }, - { x: 0.140625, y: 0.296875 }, - { x: 0.140625, y: 0.296875 }, - { x: 0.171875, y: 0.296875 }, - { x: 0.171875, y: 0.296875 }, - { x: 0.203125, y: 0.296875 }, - { x: 0.203125, y: 0.296875 }, - { x: 0.234375, y: 0.296875 }, - { x: 0.234375, y: 0.296875 }, - { x: 0.265625, y: 0.296875 }, - { x: 0.265625, y: 0.296875 }, - { x: 0.296875, y: 0.296875 }, - { x: 0.296875, y: 0.296875 }, - { x: 0.328125, y: 0.296875 }, - { x: 0.328125, y: 0.296875 }, - { x: 0.359375, y: 0.296875 }, - { x: 0.359375, y: 0.296875 }, - { x: 0.390625, y: 0.296875 }, - { x: 0.390625, y: 0.296875 }, - { x: 0.421875, y: 0.296875 }, - { x: 0.421875, y: 0.296875 }, - { x: 0.453125, y: 0.296875 }, - { x: 0.453125, y: 0.296875 }, - { x: 0.484375, y: 0.296875 }, - { x: 0.484375, y: 0.296875 }, - { x: 0.515625, y: 0.296875 }, - { x: 0.515625, y: 0.296875 }, - { x: 0.546875, y: 0.296875 }, - { x: 0.546875, y: 0.296875 }, - { x: 0.578125, y: 0.296875 }, - { x: 0.578125, y: 0.296875 }, - { x: 0.609375, y: 0.296875 }, - { x: 0.609375, y: 0.296875 }, - { x: 0.640625, y: 0.296875 }, - { x: 0.640625, y: 0.296875 }, - { x: 0.671875, y: 0.296875 }, - { x: 0.671875, y: 0.296875 }, - { x: 0.703125, y: 0.296875 }, - { x: 0.703125, y: 0.296875 }, - { x: 0.734375, y: 0.296875 }, - { x: 0.734375, y: 0.296875 }, - { x: 0.765625, y: 0.296875 }, - { x: 0.765625, y: 0.296875 }, - { x: 0.796875, y: 0.296875 }, - { x: 0.796875, y: 0.296875 }, - { x: 0.828125, y: 0.296875 }, - { x: 0.828125, y: 0.296875 }, - { x: 0.859375, y: 0.296875 }, - { x: 0.859375, y: 0.296875 }, - { x: 0.890625, y: 0.296875 }, - { x: 0.890625, y: 0.296875 }, - { x: 0.921875, y: 0.296875 }, - { x: 0.921875, y: 0.296875 }, - { x: 0.953125, y: 0.296875 }, - { x: 0.953125, y: 0.296875 }, - { x: 0.984375, y: 0.296875 }, - { x: 0.984375, y: 0.296875 }, - { x: 0.015625, y: 0.328125 }, - { x: 0.015625, y: 0.328125 }, - { x: 0.046875, y: 0.328125 }, - { x: 0.046875, y: 0.328125 }, - { x: 0.078125, y: 0.328125 }, - { x: 0.078125, y: 0.328125 }, - { x: 0.109375, y: 0.328125 }, - { x: 0.109375, y: 0.328125 }, - { x: 0.140625, y: 0.328125 }, - { x: 0.140625, y: 0.328125 }, - { x: 0.171875, y: 0.328125 }, - { x: 0.171875, y: 0.328125 }, - { x: 0.203125, y: 0.328125 }, - { x: 0.203125, y: 0.328125 }, - { x: 0.234375, y: 0.328125 }, - { x: 0.234375, y: 0.328125 }, - { x: 0.265625, y: 0.328125 }, - { x: 0.265625, y: 0.328125 }, - { x: 0.296875, y: 0.328125 }, - { x: 0.296875, y: 0.328125 }, - { x: 0.328125, y: 0.328125 }, - { x: 0.328125, y: 0.328125 }, - { x: 0.359375, y: 0.328125 }, - { x: 0.359375, y: 0.328125 }, - { x: 0.390625, y: 0.328125 }, - { x: 0.390625, y: 0.328125 }, - { x: 0.421875, y: 0.328125 }, - { x: 0.421875, y: 0.328125 }, - { x: 0.453125, y: 0.328125 }, - { x: 0.453125, y: 0.328125 }, - { x: 0.484375, y: 0.328125 }, - { x: 0.484375, y: 0.328125 }, - { x: 0.515625, y: 0.328125 }, - { x: 0.515625, y: 0.328125 }, - { x: 0.546875, y: 0.328125 }, - { x: 0.546875, y: 0.328125 }, - { x: 0.578125, y: 0.328125 }, - { x: 0.578125, y: 0.328125 }, - { x: 0.609375, y: 0.328125 }, - { x: 0.609375, y: 0.328125 }, - { x: 0.640625, y: 0.328125 }, - { x: 0.640625, y: 0.328125 }, - { x: 0.671875, y: 0.328125 }, - { x: 0.671875, y: 0.328125 }, - { x: 0.703125, y: 0.328125 }, - { x: 0.703125, y: 0.328125 }, - { x: 0.734375, y: 0.328125 }, - { x: 0.734375, y: 0.328125 }, - { x: 0.765625, y: 0.328125 }, - { x: 0.765625, y: 0.328125 }, - { x: 0.796875, y: 0.328125 }, - { x: 0.796875, y: 0.328125 }, - { x: 0.828125, y: 0.328125 }, - { x: 0.828125, y: 0.328125 }, - { x: 0.859375, y: 0.328125 }, - { x: 0.859375, y: 0.328125 }, - { x: 0.890625, y: 0.328125 }, - { x: 0.890625, y: 0.328125 }, - { x: 0.921875, y: 0.328125 }, - { x: 0.921875, y: 0.328125 }, - { x: 0.953125, y: 0.328125 }, - { x: 0.953125, y: 0.328125 }, - { x: 0.984375, y: 0.328125 }, - { x: 0.984375, y: 0.328125 }, - { x: 0.015625, y: 0.359375 }, - { x: 0.015625, y: 0.359375 }, - { x: 0.046875, y: 0.359375 }, - { x: 0.046875, y: 0.359375 }, - { x: 0.078125, y: 0.359375 }, - { x: 0.078125, y: 0.359375 }, - { x: 0.109375, y: 0.359375 }, - { x: 0.109375, y: 0.359375 }, - { x: 0.140625, y: 0.359375 }, - { x: 0.140625, y: 0.359375 }, - { x: 0.171875, y: 0.359375 }, - { x: 0.171875, y: 0.359375 }, - { x: 0.203125, y: 0.359375 }, - { x: 0.203125, y: 0.359375 }, - { x: 0.234375, y: 0.359375 }, - { x: 0.234375, y: 0.359375 }, - { x: 0.265625, y: 0.359375 }, - { x: 0.265625, y: 0.359375 }, - { x: 0.296875, y: 0.359375 }, - { x: 0.296875, y: 0.359375 }, - { x: 0.328125, y: 0.359375 }, - { x: 0.328125, y: 0.359375 }, - { x: 0.359375, y: 0.359375 }, - { x: 0.359375, y: 0.359375 }, - { x: 0.390625, y: 0.359375 }, - { x: 0.390625, y: 0.359375 }, - { x: 0.421875, y: 0.359375 }, - { x: 0.421875, y: 0.359375 }, - { x: 0.453125, y: 0.359375 }, - { x: 0.453125, y: 0.359375 }, - { x: 0.484375, y: 0.359375 }, - { x: 0.484375, y: 0.359375 }, - { x: 0.515625, y: 0.359375 }, - { x: 0.515625, y: 0.359375 }, - { x: 0.546875, y: 0.359375 }, - { x: 0.546875, y: 0.359375 }, - { x: 0.578125, y: 0.359375 }, - { x: 0.578125, y: 0.359375 }, - { x: 0.609375, y: 0.359375 }, - { x: 0.609375, y: 0.359375 }, - { x: 0.640625, y: 0.359375 }, - { x: 0.640625, y: 0.359375 }, - { x: 0.671875, y: 0.359375 }, - { x: 0.671875, y: 0.359375 }, - { x: 0.703125, y: 0.359375 }, - { x: 0.703125, y: 0.359375 }, - { x: 0.734375, y: 0.359375 }, - { x: 0.734375, y: 0.359375 }, - { x: 0.765625, y: 0.359375 }, - { x: 0.765625, y: 0.359375 }, - { x: 0.796875, y: 0.359375 }, - { x: 0.796875, y: 0.359375 }, - { x: 0.828125, y: 0.359375 }, - { x: 0.828125, y: 0.359375 }, - { x: 0.859375, y: 0.359375 }, - { x: 0.859375, y: 0.359375 }, - { x: 0.890625, y: 0.359375 }, - { x: 0.890625, y: 0.359375 }, - { x: 0.921875, y: 0.359375 }, - { x: 0.921875, y: 0.359375 }, - { x: 0.953125, y: 0.359375 }, - { x: 0.953125, y: 0.359375 }, - { x: 0.984375, y: 0.359375 }, - { x: 0.984375, y: 0.359375 }, - { x: 0.015625, y: 0.390625 }, - { x: 0.015625, y: 0.390625 }, - { x: 0.046875, y: 0.390625 }, - { x: 0.046875, y: 0.390625 }, - { x: 0.078125, y: 0.390625 }, - { x: 0.078125, y: 0.390625 }, - { x: 0.109375, y: 0.390625 }, - { x: 0.109375, y: 0.390625 }, - { x: 0.140625, y: 0.390625 }, - { x: 0.140625, y: 0.390625 }, - { x: 0.171875, y: 0.390625 }, - { x: 0.171875, y: 0.390625 }, - { x: 0.203125, y: 0.390625 }, - { x: 0.203125, y: 0.390625 }, - { x: 0.234375, y: 0.390625 }, - { x: 0.234375, y: 0.390625 }, - { x: 0.265625, y: 0.390625 }, - { x: 0.265625, y: 0.390625 }, - { x: 0.296875, y: 0.390625 }, - { x: 0.296875, y: 0.390625 }, - { x: 0.328125, y: 0.390625 }, - { x: 0.328125, y: 0.390625 }, - { x: 0.359375, y: 0.390625 }, - { x: 0.359375, y: 0.390625 }, - { x: 0.390625, y: 0.390625 }, - { x: 0.390625, y: 0.390625 }, - { x: 0.421875, y: 0.390625 }, - { x: 0.421875, y: 0.390625 }, - { x: 0.453125, y: 0.390625 }, - { x: 0.453125, y: 0.390625 }, - { x: 0.484375, y: 0.390625 }, - { x: 0.484375, y: 0.390625 }, - { x: 0.515625, y: 0.390625 }, - { x: 0.515625, y: 0.390625 }, - { x: 0.546875, y: 0.390625 }, - { x: 0.546875, y: 0.390625 }, - { x: 0.578125, y: 0.390625 }, - { x: 0.578125, y: 0.390625 }, - { x: 0.609375, y: 0.390625 }, - { x: 0.609375, y: 0.390625 }, - { x: 0.640625, y: 0.390625 }, - { x: 0.640625, y: 0.390625 }, - { x: 0.671875, y: 0.390625 }, - { x: 0.671875, y: 0.390625 }, - { x: 0.703125, y: 0.390625 }, - { x: 0.703125, y: 0.390625 }, - { x: 0.734375, y: 0.390625 }, - { x: 0.734375, y: 0.390625 }, - { x: 0.765625, y: 0.390625 }, - { x: 0.765625, y: 0.390625 }, - { x: 0.796875, y: 0.390625 }, - { x: 0.796875, y: 0.390625 }, - { x: 0.828125, y: 0.390625 }, - { x: 0.828125, y: 0.390625 }, - { x: 0.859375, y: 0.390625 }, - { x: 0.859375, y: 0.390625 }, - { x: 0.890625, y: 0.390625 }, - { x: 0.890625, y: 0.390625 }, - { x: 0.921875, y: 0.390625 }, - { x: 0.921875, y: 0.390625 }, - { x: 0.953125, y: 0.390625 }, - { x: 0.953125, y: 0.390625 }, - { x: 0.984375, y: 0.390625 }, - { x: 0.984375, y: 0.390625 }, - { x: 0.015625, y: 0.421875 }, - { x: 0.015625, y: 0.421875 }, - { x: 0.046875, y: 0.421875 }, - { x: 0.046875, y: 0.421875 }, - { x: 0.078125, y: 0.421875 }, - { x: 0.078125, y: 0.421875 }, - { x: 0.109375, y: 0.421875 }, - { x: 0.109375, y: 0.421875 }, - { x: 0.140625, y: 0.421875 }, - { x: 0.140625, y: 0.421875 }, - { x: 0.171875, y: 0.421875 }, - { x: 0.171875, y: 0.421875 }, - { x: 0.203125, y: 0.421875 }, - { x: 0.203125, y: 0.421875 }, - { x: 0.234375, y: 0.421875 }, - { x: 0.234375, y: 0.421875 }, - { x: 0.265625, y: 0.421875 }, - { x: 0.265625, y: 0.421875 }, - { x: 0.296875, y: 0.421875 }, - { x: 0.296875, y: 0.421875 }, - { x: 0.328125, y: 0.421875 }, - { x: 0.328125, y: 0.421875 }, - { x: 0.359375, y: 0.421875 }, - { x: 0.359375, y: 0.421875 }, - { x: 0.390625, y: 0.421875 }, - { x: 0.390625, y: 0.421875 }, - { x: 0.421875, y: 0.421875 }, - { x: 0.421875, y: 0.421875 }, - { x: 0.453125, y: 0.421875 }, - { x: 0.453125, y: 0.421875 }, - { x: 0.484375, y: 0.421875 }, - { x: 0.484375, y: 0.421875 }, - { x: 0.515625, y: 0.421875 }, - { x: 0.515625, y: 0.421875 }, - { x: 0.546875, y: 0.421875 }, - { x: 0.546875, y: 0.421875 }, - { x: 0.578125, y: 0.421875 }, - { x: 0.578125, y: 0.421875 }, - { x: 0.609375, y: 0.421875 }, - { x: 0.609375, y: 0.421875 }, - { x: 0.640625, y: 0.421875 }, - { x: 0.640625, y: 0.421875 }, - { x: 0.671875, y: 0.421875 }, - { x: 0.671875, y: 0.421875 }, - { x: 0.703125, y: 0.421875 }, - { x: 0.703125, y: 0.421875 }, - { x: 0.734375, y: 0.421875 }, - { x: 0.734375, y: 0.421875 }, - { x: 0.765625, y: 0.421875 }, - { x: 0.765625, y: 0.421875 }, - { x: 0.796875, y: 0.421875 }, - { x: 0.796875, y: 0.421875 }, - { x: 0.828125, y: 0.421875 }, - { x: 0.828125, y: 0.421875 }, - { x: 0.859375, y: 0.421875 }, - { x: 0.859375, y: 0.421875 }, - { x: 0.890625, y: 0.421875 }, - { x: 0.890625, y: 0.421875 }, - { x: 0.921875, y: 0.421875 }, - { x: 0.921875, y: 0.421875 }, - { x: 0.953125, y: 0.421875 }, - { x: 0.953125, y: 0.421875 }, - { x: 0.984375, y: 0.421875 }, - { x: 0.984375, y: 0.421875 }, - { x: 0.015625, y: 0.453125 }, - { x: 0.015625, y: 0.453125 }, - { x: 0.046875, y: 0.453125 }, - { x: 0.046875, y: 0.453125 }, - { x: 0.078125, y: 0.453125 }, - { x: 0.078125, y: 0.453125 }, - { x: 0.109375, y: 0.453125 }, - { x: 0.109375, y: 0.453125 }, - { x: 0.140625, y: 0.453125 }, - { x: 0.140625, y: 0.453125 }, - { x: 0.171875, y: 0.453125 }, - { x: 0.171875, y: 0.453125 }, - { x: 0.203125, y: 0.453125 }, - { x: 0.203125, y: 0.453125 }, - { x: 0.234375, y: 0.453125 }, - { x: 0.234375, y: 0.453125 }, - { x: 0.265625, y: 0.453125 }, - { x: 0.265625, y: 0.453125 }, - { x: 0.296875, y: 0.453125 }, - { x: 0.296875, y: 0.453125 }, - { x: 0.328125, y: 0.453125 }, - { x: 0.328125, y: 0.453125 }, - { x: 0.359375, y: 0.453125 }, - { x: 0.359375, y: 0.453125 }, - { x: 0.390625, y: 0.453125 }, - { x: 0.390625, y: 0.453125 }, - { x: 0.421875, y: 0.453125 }, - { x: 0.421875, y: 0.453125 }, - { x: 0.453125, y: 0.453125 }, - { x: 0.453125, y: 0.453125 }, - { x: 0.484375, y: 0.453125 }, - { x: 0.484375, y: 0.453125 }, - { x: 0.515625, y: 0.453125 }, - { x: 0.515625, y: 0.453125 }, - { x: 0.546875, y: 0.453125 }, - { x: 0.546875, y: 0.453125 }, - { x: 0.578125, y: 0.453125 }, - { x: 0.578125, y: 0.453125 }, - { x: 0.609375, y: 0.453125 }, - { x: 0.609375, y: 0.453125 }, - { x: 0.640625, y: 0.453125 }, - { x: 0.640625, y: 0.453125 }, - { x: 0.671875, y: 0.453125 }, - { x: 0.671875, y: 0.453125 }, - { x: 0.703125, y: 0.453125 }, - { x: 0.703125, y: 0.453125 }, - { x: 0.734375, y: 0.453125 }, - { x: 0.734375, y: 0.453125 }, - { x: 0.765625, y: 0.453125 }, - { x: 0.765625, y: 0.453125 }, - { x: 0.796875, y: 0.453125 }, - { x: 0.796875, y: 0.453125 }, - { x: 0.828125, y: 0.453125 }, - { x: 0.828125, y: 0.453125 }, - { x: 0.859375, y: 0.453125 }, - { x: 0.859375, y: 0.453125 }, - { x: 0.890625, y: 0.453125 }, - { x: 0.890625, y: 0.453125 }, - { x: 0.921875, y: 0.453125 }, - { x: 0.921875, y: 0.453125 }, - { x: 0.953125, y: 0.453125 }, - { x: 0.953125, y: 0.453125 }, - { x: 0.984375, y: 0.453125 }, - { x: 0.984375, y: 0.453125 }, - { x: 0.015625, y: 0.484375 }, - { x: 0.015625, y: 0.484375 }, - { x: 0.046875, y: 0.484375 }, - { x: 0.046875, y: 0.484375 }, - { x: 0.078125, y: 0.484375 }, - { x: 0.078125, y: 0.484375 }, - { x: 0.109375, y: 0.484375 }, - { x: 0.109375, y: 0.484375 }, - { x: 0.140625, y: 0.484375 }, - { x: 0.140625, y: 0.484375 }, - { x: 0.171875, y: 0.484375 }, - { x: 0.171875, y: 0.484375 }, - { x: 0.203125, y: 0.484375 }, - { x: 0.203125, y: 0.484375 }, - { x: 0.234375, y: 0.484375 }, - { x: 0.234375, y: 0.484375 }, - { x: 0.265625, y: 0.484375 }, - { x: 0.265625, y: 0.484375 }, - { x: 0.296875, y: 0.484375 }, - { x: 0.296875, y: 0.484375 }, - { x: 0.328125, y: 0.484375 }, - { x: 0.328125, y: 0.484375 }, - { x: 0.359375, y: 0.484375 }, - { x: 0.359375, y: 0.484375 }, - { x: 0.390625, y: 0.484375 }, - { x: 0.390625, y: 0.484375 }, - { x: 0.421875, y: 0.484375 }, - { x: 0.421875, y: 0.484375 }, - { x: 0.453125, y: 0.484375 }, - { x: 0.453125, y: 0.484375 }, - { x: 0.484375, y: 0.484375 }, - { x: 0.484375, y: 0.484375 }, - { x: 0.515625, y: 0.484375 }, - { x: 0.515625, y: 0.484375 }, - { x: 0.546875, y: 0.484375 }, - { x: 0.546875, y: 0.484375 }, - { x: 0.578125, y: 0.484375 }, - { x: 0.578125, y: 0.484375 }, - { x: 0.609375, y: 0.484375 }, - { x: 0.609375, y: 0.484375 }, - { x: 0.640625, y: 0.484375 }, - { x: 0.640625, y: 0.484375 }, - { x: 0.671875, y: 0.484375 }, - { x: 0.671875, y: 0.484375 }, - { x: 0.703125, y: 0.484375 }, - { x: 0.703125, y: 0.484375 }, - { x: 0.734375, y: 0.484375 }, - { x: 0.734375, y: 0.484375 }, - { x: 0.765625, y: 0.484375 }, - { x: 0.765625, y: 0.484375 }, - { x: 0.796875, y: 0.484375 }, - { x: 0.796875, y: 0.484375 }, - { x: 0.828125, y: 0.484375 }, - { x: 0.828125, y: 0.484375 }, - { x: 0.859375, y: 0.484375 }, - { x: 0.859375, y: 0.484375 }, - { x: 0.890625, y: 0.484375 }, - { x: 0.890625, y: 0.484375 }, - { x: 0.921875, y: 0.484375 }, - { x: 0.921875, y: 0.484375 }, - { x: 0.953125, y: 0.484375 }, - { x: 0.953125, y: 0.484375 }, - { x: 0.984375, y: 0.484375 }, - { x: 0.984375, y: 0.484375 }, - { x: 0.015625, y: 0.515625 }, - { x: 0.015625, y: 0.515625 }, - { x: 0.046875, y: 0.515625 }, - { x: 0.046875, y: 0.515625 }, - { x: 0.078125, y: 0.515625 }, - { x: 0.078125, y: 0.515625 }, - { x: 0.109375, y: 0.515625 }, - { x: 0.109375, y: 0.515625 }, - { x: 0.140625, y: 0.515625 }, - { x: 0.140625, y: 0.515625 }, - { x: 0.171875, y: 0.515625 }, - { x: 0.171875, y: 0.515625 }, - { x: 0.203125, y: 0.515625 }, - { x: 0.203125, y: 0.515625 }, - { x: 0.234375, y: 0.515625 }, - { x: 0.234375, y: 0.515625 }, - { x: 0.265625, y: 0.515625 }, - { x: 0.265625, y: 0.515625 }, - { x: 0.296875, y: 0.515625 }, - { x: 0.296875, y: 0.515625 }, - { x: 0.328125, y: 0.515625 }, - { x: 0.328125, y: 0.515625 }, - { x: 0.359375, y: 0.515625 }, - { x: 0.359375, y: 0.515625 }, - { x: 0.390625, y: 0.515625 }, - { x: 0.390625, y: 0.515625 }, - { x: 0.421875, y: 0.515625 }, - { x: 0.421875, y: 0.515625 }, - { x: 0.453125, y: 0.515625 }, - { x: 0.453125, y: 0.515625 }, - { x: 0.484375, y: 0.515625 }, - { x: 0.484375, y: 0.515625 }, - { x: 0.515625, y: 0.515625 }, - { x: 0.515625, y: 0.515625 }, - { x: 0.546875, y: 0.515625 }, - { x: 0.546875, y: 0.515625 }, - { x: 0.578125, y: 0.515625 }, - { x: 0.578125, y: 0.515625 }, - { x: 0.609375, y: 0.515625 }, - { x: 0.609375, y: 0.515625 }, - { x: 0.640625, y: 0.515625 }, - { x: 0.640625, y: 0.515625 }, - { x: 0.671875, y: 0.515625 }, - { x: 0.671875, y: 0.515625 }, - { x: 0.703125, y: 0.515625 }, - { x: 0.703125, y: 0.515625 }, - { x: 0.734375, y: 0.515625 }, - { x: 0.734375, y: 0.515625 }, - { x: 0.765625, y: 0.515625 }, - { x: 0.765625, y: 0.515625 }, - { x: 0.796875, y: 0.515625 }, - { x: 0.796875, y: 0.515625 }, - { x: 0.828125, y: 0.515625 }, - { x: 0.828125, y: 0.515625 }, - { x: 0.859375, y: 0.515625 }, - { x: 0.859375, y: 0.515625 }, - { x: 0.890625, y: 0.515625 }, - { x: 0.890625, y: 0.515625 }, - { x: 0.921875, y: 0.515625 }, - { x: 0.921875, y: 0.515625 }, - { x: 0.953125, y: 0.515625 }, - { x: 0.953125, y: 0.515625 }, - { x: 0.984375, y: 0.515625 }, - { x: 0.984375, y: 0.515625 }, - { x: 0.015625, y: 0.546875 }, - { x: 0.015625, y: 0.546875 }, - { x: 0.046875, y: 0.546875 }, - { x: 0.046875, y: 0.546875 }, - { x: 0.078125, y: 0.546875 }, - { x: 0.078125, y: 0.546875 }, - { x: 0.109375, y: 0.546875 }, - { x: 0.109375, y: 0.546875 }, - { x: 0.140625, y: 0.546875 }, - { x: 0.140625, y: 0.546875 }, - { x: 0.171875, y: 0.546875 }, - { x: 0.171875, y: 0.546875 }, - { x: 0.203125, y: 0.546875 }, - { x: 0.203125, y: 0.546875 }, - { x: 0.234375, y: 0.546875 }, - { x: 0.234375, y: 0.546875 }, - { x: 0.265625, y: 0.546875 }, - { x: 0.265625, y: 0.546875 }, - { x: 0.296875, y: 0.546875 }, - { x: 0.296875, y: 0.546875 }, - { x: 0.328125, y: 0.546875 }, - { x: 0.328125, y: 0.546875 }, - { x: 0.359375, y: 0.546875 }, - { x: 0.359375, y: 0.546875 }, - { x: 0.390625, y: 0.546875 }, - { x: 0.390625, y: 0.546875 }, - { x: 0.421875, y: 0.546875 }, - { x: 0.421875, y: 0.546875 }, - { x: 0.453125, y: 0.546875 }, - { x: 0.453125, y: 0.546875 }, - { x: 0.484375, y: 0.546875 }, - { x: 0.484375, y: 0.546875 }, - { x: 0.515625, y: 0.546875 }, - { x: 0.515625, y: 0.546875 }, - { x: 0.546875, y: 0.546875 }, - { x: 0.546875, y: 0.546875 }, - { x: 0.578125, y: 0.546875 }, - { x: 0.578125, y: 0.546875 }, - { x: 0.609375, y: 0.546875 }, - { x: 0.609375, y: 0.546875 }, - { x: 0.640625, y: 0.546875 }, - { x: 0.640625, y: 0.546875 }, - { x: 0.671875, y: 0.546875 }, - { x: 0.671875, y: 0.546875 }, - { x: 0.703125, y: 0.546875 }, - { x: 0.703125, y: 0.546875 }, - { x: 0.734375, y: 0.546875 }, - { x: 0.734375, y: 0.546875 }, - { x: 0.765625, y: 0.546875 }, - { x: 0.765625, y: 0.546875 }, - { x: 0.796875, y: 0.546875 }, - { x: 0.796875, y: 0.546875 }, - { x: 0.828125, y: 0.546875 }, - { x: 0.828125, y: 0.546875 }, - { x: 0.859375, y: 0.546875 }, - { x: 0.859375, y: 0.546875 }, - { x: 0.890625, y: 0.546875 }, - { x: 0.890625, y: 0.546875 }, - { x: 0.921875, y: 0.546875 }, - { x: 0.921875, y: 0.546875 }, - { x: 0.953125, y: 0.546875 }, - { x: 0.953125, y: 0.546875 }, - { x: 0.984375, y: 0.546875 }, - { x: 0.984375, y: 0.546875 }, - { x: 0.015625, y: 0.578125 }, - { x: 0.015625, y: 0.578125 }, - { x: 0.046875, y: 0.578125 }, - { x: 0.046875, y: 0.578125 }, - { x: 0.078125, y: 0.578125 }, - { x: 0.078125, y: 0.578125 }, - { x: 0.109375, y: 0.578125 }, - { x: 0.109375, y: 0.578125 }, - { x: 0.140625, y: 0.578125 }, - { x: 0.140625, y: 0.578125 }, - { x: 0.171875, y: 0.578125 }, - { x: 0.171875, y: 0.578125 }, - { x: 0.203125, y: 0.578125 }, - { x: 0.203125, y: 0.578125 }, - { x: 0.234375, y: 0.578125 }, - { x: 0.234375, y: 0.578125 }, - { x: 0.265625, y: 0.578125 }, - { x: 0.265625, y: 0.578125 }, - { x: 0.296875, y: 0.578125 }, - { x: 0.296875, y: 0.578125 }, - { x: 0.328125, y: 0.578125 }, - { x: 0.328125, y: 0.578125 }, - { x: 0.359375, y: 0.578125 }, - { x: 0.359375, y: 0.578125 }, - { x: 0.390625, y: 0.578125 }, - { x: 0.390625, y: 0.578125 }, - { x: 0.421875, y: 0.578125 }, - { x: 0.421875, y: 0.578125 }, - { x: 0.453125, y: 0.578125 }, - { x: 0.453125, y: 0.578125 }, - { x: 0.484375, y: 0.578125 }, - { x: 0.484375, y: 0.578125 }, - { x: 0.515625, y: 0.578125 }, - { x: 0.515625, y: 0.578125 }, - { x: 0.546875, y: 0.578125 }, - { x: 0.546875, y: 0.578125 }, - { x: 0.578125, y: 0.578125 }, - { x: 0.578125, y: 0.578125 }, - { x: 0.609375, y: 0.578125 }, - { x: 0.609375, y: 0.578125 }, - { x: 0.640625, y: 0.578125 }, - { x: 0.640625, y: 0.578125 }, - { x: 0.671875, y: 0.578125 }, - { x: 0.671875, y: 0.578125 }, - { x: 0.703125, y: 0.578125 }, - { x: 0.703125, y: 0.578125 }, - { x: 0.734375, y: 0.578125 }, - { x: 0.734375, y: 0.578125 }, - { x: 0.765625, y: 0.578125 }, - { x: 0.765625, y: 0.578125 }, - { x: 0.796875, y: 0.578125 }, - { x: 0.796875, y: 0.578125 }, - { x: 0.828125, y: 0.578125 }, - { x: 0.828125, y: 0.578125 }, - { x: 0.859375, y: 0.578125 }, - { x: 0.859375, y: 0.578125 }, - { x: 0.890625, y: 0.578125 }, - { x: 0.890625, y: 0.578125 }, - { x: 0.921875, y: 0.578125 }, - { x: 0.921875, y: 0.578125 }, - { x: 0.953125, y: 0.578125 }, - { x: 0.953125, y: 0.578125 }, - { x: 0.984375, y: 0.578125 }, - { x: 0.984375, y: 0.578125 }, - { x: 0.015625, y: 0.609375 }, - { x: 0.015625, y: 0.609375 }, - { x: 0.046875, y: 0.609375 }, - { x: 0.046875, y: 0.609375 }, - { x: 0.078125, y: 0.609375 }, - { x: 0.078125, y: 0.609375 }, - { x: 0.109375, y: 0.609375 }, - { x: 0.109375, y: 0.609375 }, - { x: 0.140625, y: 0.609375 }, - { x: 0.140625, y: 0.609375 }, - { x: 0.171875, y: 0.609375 }, - { x: 0.171875, y: 0.609375 }, - { x: 0.203125, y: 0.609375 }, - { x: 0.203125, y: 0.609375 }, - { x: 0.234375, y: 0.609375 }, - { x: 0.234375, y: 0.609375 }, - { x: 0.265625, y: 0.609375 }, - { x: 0.265625, y: 0.609375 }, - { x: 0.296875, y: 0.609375 }, - { x: 0.296875, y: 0.609375 }, - { x: 0.328125, y: 0.609375 }, - { x: 0.328125, y: 0.609375 }, - { x: 0.359375, y: 0.609375 }, - { x: 0.359375, y: 0.609375 }, - { x: 0.390625, y: 0.609375 }, - { x: 0.390625, y: 0.609375 }, - { x: 0.421875, y: 0.609375 }, - { x: 0.421875, y: 0.609375 }, - { x: 0.453125, y: 0.609375 }, - { x: 0.453125, y: 0.609375 }, - { x: 0.484375, y: 0.609375 }, - { x: 0.484375, y: 0.609375 }, - { x: 0.515625, y: 0.609375 }, - { x: 0.515625, y: 0.609375 }, - { x: 0.546875, y: 0.609375 }, - { x: 0.546875, y: 0.609375 }, - { x: 0.578125, y: 0.609375 }, - { x: 0.578125, y: 0.609375 }, - { x: 0.609375, y: 0.609375 }, - { x: 0.609375, y: 0.609375 }, - { x: 0.640625, y: 0.609375 }, - { x: 0.640625, y: 0.609375 }, - { x: 0.671875, y: 0.609375 }, - { x: 0.671875, y: 0.609375 }, - { x: 0.703125, y: 0.609375 }, - { x: 0.703125, y: 0.609375 }, - { x: 0.734375, y: 0.609375 }, - { x: 0.734375, y: 0.609375 }, - { x: 0.765625, y: 0.609375 }, - { x: 0.765625, y: 0.609375 }, - { x: 0.796875, y: 0.609375 }, - { x: 0.796875, y: 0.609375 }, - { x: 0.828125, y: 0.609375 }, - { x: 0.828125, y: 0.609375 }, - { x: 0.859375, y: 0.609375 }, - { x: 0.859375, y: 0.609375 }, - { x: 0.890625, y: 0.609375 }, - { x: 0.890625, y: 0.609375 }, - { x: 0.921875, y: 0.609375 }, - { x: 0.921875, y: 0.609375 }, - { x: 0.953125, y: 0.609375 }, - { x: 0.953125, y: 0.609375 }, - { x: 0.984375, y: 0.609375 }, - { x: 0.984375, y: 0.609375 }, - { x: 0.015625, y: 0.640625 }, - { x: 0.015625, y: 0.640625 }, - { x: 0.046875, y: 0.640625 }, - { x: 0.046875, y: 0.640625 }, - { x: 0.078125, y: 0.640625 }, - { x: 0.078125, y: 0.640625 }, - { x: 0.109375, y: 0.640625 }, - { x: 0.109375, y: 0.640625 }, - { x: 0.140625, y: 0.640625 }, - { x: 0.140625, y: 0.640625 }, - { x: 0.171875, y: 0.640625 }, - { x: 0.171875, y: 0.640625 }, - { x: 0.203125, y: 0.640625 }, - { x: 0.203125, y: 0.640625 }, - { x: 0.234375, y: 0.640625 }, - { x: 0.234375, y: 0.640625 }, - { x: 0.265625, y: 0.640625 }, - { x: 0.265625, y: 0.640625 }, - { x: 0.296875, y: 0.640625 }, - { x: 0.296875, y: 0.640625 }, - { x: 0.328125, y: 0.640625 }, - { x: 0.328125, y: 0.640625 }, - { x: 0.359375, y: 0.640625 }, - { x: 0.359375, y: 0.640625 }, - { x: 0.390625, y: 0.640625 }, - { x: 0.390625, y: 0.640625 }, - { x: 0.421875, y: 0.640625 }, - { x: 0.421875, y: 0.640625 }, - { x: 0.453125, y: 0.640625 }, - { x: 0.453125, y: 0.640625 }, - { x: 0.484375, y: 0.640625 }, - { x: 0.484375, y: 0.640625 }, - { x: 0.515625, y: 0.640625 }, - { x: 0.515625, y: 0.640625 }, - { x: 0.546875, y: 0.640625 }, - { x: 0.546875, y: 0.640625 }, - { x: 0.578125, y: 0.640625 }, - { x: 0.578125, y: 0.640625 }, - { x: 0.609375, y: 0.640625 }, - { x: 0.609375, y: 0.640625 }, - { x: 0.640625, y: 0.640625 }, - { x: 0.640625, y: 0.640625 }, - { x: 0.671875, y: 0.640625 }, - { x: 0.671875, y: 0.640625 }, - { x: 0.703125, y: 0.640625 }, - { x: 0.703125, y: 0.640625 }, - { x: 0.734375, y: 0.640625 }, - { x: 0.734375, y: 0.640625 }, - { x: 0.765625, y: 0.640625 }, - { x: 0.765625, y: 0.640625 }, - { x: 0.796875, y: 0.640625 }, - { x: 0.796875, y: 0.640625 }, - { x: 0.828125, y: 0.640625 }, - { x: 0.828125, y: 0.640625 }, - { x: 0.859375, y: 0.640625 }, - { x: 0.859375, y: 0.640625 }, - { x: 0.890625, y: 0.640625 }, - { x: 0.890625, y: 0.640625 }, - { x: 0.921875, y: 0.640625 }, - { x: 0.921875, y: 0.640625 }, - { x: 0.953125, y: 0.640625 }, - { x: 0.953125, y: 0.640625 }, - { x: 0.984375, y: 0.640625 }, - { x: 0.984375, y: 0.640625 }, - { x: 0.015625, y: 0.671875 }, - { x: 0.015625, y: 0.671875 }, - { x: 0.046875, y: 0.671875 }, - { x: 0.046875, y: 0.671875 }, - { x: 0.078125, y: 0.671875 }, - { x: 0.078125, y: 0.671875 }, - { x: 0.109375, y: 0.671875 }, - { x: 0.109375, y: 0.671875 }, - { x: 0.140625, y: 0.671875 }, - { x: 0.140625, y: 0.671875 }, - { x: 0.171875, y: 0.671875 }, - { x: 0.171875, y: 0.671875 }, - { x: 0.203125, y: 0.671875 }, - { x: 0.203125, y: 0.671875 }, - { x: 0.234375, y: 0.671875 }, - { x: 0.234375, y: 0.671875 }, - { x: 0.265625, y: 0.671875 }, - { x: 0.265625, y: 0.671875 }, - { x: 0.296875, y: 0.671875 }, - { x: 0.296875, y: 0.671875 }, - { x: 0.328125, y: 0.671875 }, - { x: 0.328125, y: 0.671875 }, - { x: 0.359375, y: 0.671875 }, - { x: 0.359375, y: 0.671875 }, - { x: 0.390625, y: 0.671875 }, - { x: 0.390625, y: 0.671875 }, - { x: 0.421875, y: 0.671875 }, - { x: 0.421875, y: 0.671875 }, - { x: 0.453125, y: 0.671875 }, - { x: 0.453125, y: 0.671875 }, - { x: 0.484375, y: 0.671875 }, - { x: 0.484375, y: 0.671875 }, - { x: 0.515625, y: 0.671875 }, - { x: 0.515625, y: 0.671875 }, - { x: 0.546875, y: 0.671875 }, - { x: 0.546875, y: 0.671875 }, - { x: 0.578125, y: 0.671875 }, - { x: 0.578125, y: 0.671875 }, - { x: 0.609375, y: 0.671875 }, - { x: 0.609375, y: 0.671875 }, - { x: 0.640625, y: 0.671875 }, - { x: 0.640625, y: 0.671875 }, - { x: 0.671875, y: 0.671875 }, - { x: 0.671875, y: 0.671875 }, - { x: 0.703125, y: 0.671875 }, - { x: 0.703125, y: 0.671875 }, - { x: 0.734375, y: 0.671875 }, - { x: 0.734375, y: 0.671875 }, - { x: 0.765625, y: 0.671875 }, - { x: 0.765625, y: 0.671875 }, - { x: 0.796875, y: 0.671875 }, - { x: 0.796875, y: 0.671875 }, - { x: 0.828125, y: 0.671875 }, - { x: 0.828125, y: 0.671875 }, - { x: 0.859375, y: 0.671875 }, - { x: 0.859375, y: 0.671875 }, - { x: 0.890625, y: 0.671875 }, - { x: 0.890625, y: 0.671875 }, - { x: 0.921875, y: 0.671875 }, - { x: 0.921875, y: 0.671875 }, - { x: 0.953125, y: 0.671875 }, - { x: 0.953125, y: 0.671875 }, - { x: 0.984375, y: 0.671875 }, - { x: 0.984375, y: 0.671875 }, - { x: 0.015625, y: 0.703125 }, - { x: 0.015625, y: 0.703125 }, - { x: 0.046875, y: 0.703125 }, - { x: 0.046875, y: 0.703125 }, - { x: 0.078125, y: 0.703125 }, - { x: 0.078125, y: 0.703125 }, - { x: 0.109375, y: 0.703125 }, - { x: 0.109375, y: 0.703125 }, - { x: 0.140625, y: 0.703125 }, - { x: 0.140625, y: 0.703125 }, - { x: 0.171875, y: 0.703125 }, - { x: 0.171875, y: 0.703125 }, - { x: 0.203125, y: 0.703125 }, - { x: 0.203125, y: 0.703125 }, - { x: 0.234375, y: 0.703125 }, - { x: 0.234375, y: 0.703125 }, - { x: 0.265625, y: 0.703125 }, - { x: 0.265625, y: 0.703125 }, - { x: 0.296875, y: 0.703125 }, - { x: 0.296875, y: 0.703125 }, - { x: 0.328125, y: 0.703125 }, - { x: 0.328125, y: 0.703125 }, - { x: 0.359375, y: 0.703125 }, - { x: 0.359375, y: 0.703125 }, - { x: 0.390625, y: 0.703125 }, - { x: 0.390625, y: 0.703125 }, - { x: 0.421875, y: 0.703125 }, - { x: 0.421875, y: 0.703125 }, - { x: 0.453125, y: 0.703125 }, - { x: 0.453125, y: 0.703125 }, - { x: 0.484375, y: 0.703125 }, - { x: 0.484375, y: 0.703125 }, - { x: 0.515625, y: 0.703125 }, - { x: 0.515625, y: 0.703125 }, - { x: 0.546875, y: 0.703125 }, - { x: 0.546875, y: 0.703125 }, - { x: 0.578125, y: 0.703125 }, - { x: 0.578125, y: 0.703125 }, - { x: 0.609375, y: 0.703125 }, - { x: 0.609375, y: 0.703125 }, - { x: 0.640625, y: 0.703125 }, - { x: 0.640625, y: 0.703125 }, - { x: 0.671875, y: 0.703125 }, - { x: 0.671875, y: 0.703125 }, - { x: 0.703125, y: 0.703125 }, - { x: 0.703125, y: 0.703125 }, - { x: 0.734375, y: 0.703125 }, - { x: 0.734375, y: 0.703125 }, - { x: 0.765625, y: 0.703125 }, - { x: 0.765625, y: 0.703125 }, - { x: 0.796875, y: 0.703125 }, - { x: 0.796875, y: 0.703125 }, - { x: 0.828125, y: 0.703125 }, - { x: 0.828125, y: 0.703125 }, - { x: 0.859375, y: 0.703125 }, - { x: 0.859375, y: 0.703125 }, - { x: 0.890625, y: 0.703125 }, - { x: 0.890625, y: 0.703125 }, - { x: 0.921875, y: 0.703125 }, - { x: 0.921875, y: 0.703125 }, - { x: 0.953125, y: 0.703125 }, - { x: 0.953125, y: 0.703125 }, - { x: 0.984375, y: 0.703125 }, - { x: 0.984375, y: 0.703125 }, - { x: 0.015625, y: 0.734375 }, - { x: 0.015625, y: 0.734375 }, - { x: 0.046875, y: 0.734375 }, - { x: 0.046875, y: 0.734375 }, - { x: 0.078125, y: 0.734375 }, - { x: 0.078125, y: 0.734375 }, - { x: 0.109375, y: 0.734375 }, - { x: 0.109375, y: 0.734375 }, - { x: 0.140625, y: 0.734375 }, - { x: 0.140625, y: 0.734375 }, - { x: 0.171875, y: 0.734375 }, - { x: 0.171875, y: 0.734375 }, - { x: 0.203125, y: 0.734375 }, - { x: 0.203125, y: 0.734375 }, - { x: 0.234375, y: 0.734375 }, - { x: 0.234375, y: 0.734375 }, - { x: 0.265625, y: 0.734375 }, - { x: 0.265625, y: 0.734375 }, - { x: 0.296875, y: 0.734375 }, - { x: 0.296875, y: 0.734375 }, - { x: 0.328125, y: 0.734375 }, - { x: 0.328125, y: 0.734375 }, - { x: 0.359375, y: 0.734375 }, - { x: 0.359375, y: 0.734375 }, - { x: 0.390625, y: 0.734375 }, - { x: 0.390625, y: 0.734375 }, - { x: 0.421875, y: 0.734375 }, - { x: 0.421875, y: 0.734375 }, - { x: 0.453125, y: 0.734375 }, - { x: 0.453125, y: 0.734375 }, - { x: 0.484375, y: 0.734375 }, - { x: 0.484375, y: 0.734375 }, - { x: 0.515625, y: 0.734375 }, - { x: 0.515625, y: 0.734375 }, - { x: 0.546875, y: 0.734375 }, - { x: 0.546875, y: 0.734375 }, - { x: 0.578125, y: 0.734375 }, - { x: 0.578125, y: 0.734375 }, - { x: 0.609375, y: 0.734375 }, - { x: 0.609375, y: 0.734375 }, - { x: 0.640625, y: 0.734375 }, - { x: 0.640625, y: 0.734375 }, - { x: 0.671875, y: 0.734375 }, - { x: 0.671875, y: 0.734375 }, - { x: 0.703125, y: 0.734375 }, - { x: 0.703125, y: 0.734375 }, - { x: 0.734375, y: 0.734375 }, - { x: 0.734375, y: 0.734375 }, - { x: 0.765625, y: 0.734375 }, - { x: 0.765625, y: 0.734375 }, - { x: 0.796875, y: 0.734375 }, - { x: 0.796875, y: 0.734375 }, - { x: 0.828125, y: 0.734375 }, - { x: 0.828125, y: 0.734375 }, - { x: 0.859375, y: 0.734375 }, - { x: 0.859375, y: 0.734375 }, - { x: 0.890625, y: 0.734375 }, - { x: 0.890625, y: 0.734375 }, - { x: 0.921875, y: 0.734375 }, - { x: 0.921875, y: 0.734375 }, - { x: 0.953125, y: 0.734375 }, - { x: 0.953125, y: 0.734375 }, - { x: 0.984375, y: 0.734375 }, - { x: 0.984375, y: 0.734375 }, - { x: 0.015625, y: 0.765625 }, - { x: 0.015625, y: 0.765625 }, - { x: 0.046875, y: 0.765625 }, - { x: 0.046875, y: 0.765625 }, - { x: 0.078125, y: 0.765625 }, - { x: 0.078125, y: 0.765625 }, - { x: 0.109375, y: 0.765625 }, - { x: 0.109375, y: 0.765625 }, - { x: 0.140625, y: 0.765625 }, - { x: 0.140625, y: 0.765625 }, - { x: 0.171875, y: 0.765625 }, - { x: 0.171875, y: 0.765625 }, - { x: 0.203125, y: 0.765625 }, - { x: 0.203125, y: 0.765625 }, - { x: 0.234375, y: 0.765625 }, - { x: 0.234375, y: 0.765625 }, - { x: 0.265625, y: 0.765625 }, - { x: 0.265625, y: 0.765625 }, - { x: 0.296875, y: 0.765625 }, - { x: 0.296875, y: 0.765625 }, - { x: 0.328125, y: 0.765625 }, - { x: 0.328125, y: 0.765625 }, - { x: 0.359375, y: 0.765625 }, - { x: 0.359375, y: 0.765625 }, - { x: 0.390625, y: 0.765625 }, - { x: 0.390625, y: 0.765625 }, - { x: 0.421875, y: 0.765625 }, - { x: 0.421875, y: 0.765625 }, - { x: 0.453125, y: 0.765625 }, - { x: 0.453125, y: 0.765625 }, - { x: 0.484375, y: 0.765625 }, - { x: 0.484375, y: 0.765625 }, - { x: 0.515625, y: 0.765625 }, - { x: 0.515625, y: 0.765625 }, - { x: 0.546875, y: 0.765625 }, - { x: 0.546875, y: 0.765625 }, - { x: 0.578125, y: 0.765625 }, - { x: 0.578125, y: 0.765625 }, - { x: 0.609375, y: 0.765625 }, - { x: 0.609375, y: 0.765625 }, - { x: 0.640625, y: 0.765625 }, - { x: 0.640625, y: 0.765625 }, - { x: 0.671875, y: 0.765625 }, - { x: 0.671875, y: 0.765625 }, - { x: 0.703125, y: 0.765625 }, - { x: 0.703125, y: 0.765625 }, - { x: 0.734375, y: 0.765625 }, - { x: 0.734375, y: 0.765625 }, - { x: 0.765625, y: 0.765625 }, - { x: 0.765625, y: 0.765625 }, - { x: 0.796875, y: 0.765625 }, - { x: 0.796875, y: 0.765625 }, - { x: 0.828125, y: 0.765625 }, - { x: 0.828125, y: 0.765625 }, - { x: 0.859375, y: 0.765625 }, - { x: 0.859375, y: 0.765625 }, - { x: 0.890625, y: 0.765625 }, - { x: 0.890625, y: 0.765625 }, - { x: 0.921875, y: 0.765625 }, - { x: 0.921875, y: 0.765625 }, - { x: 0.953125, y: 0.765625 }, - { x: 0.953125, y: 0.765625 }, - { x: 0.984375, y: 0.765625 }, - { x: 0.984375, y: 0.765625 }, - { x: 0.015625, y: 0.796875 }, - { x: 0.015625, y: 0.796875 }, - { x: 0.046875, y: 0.796875 }, - { x: 0.046875, y: 0.796875 }, - { x: 0.078125, y: 0.796875 }, - { x: 0.078125, y: 0.796875 }, - { x: 0.109375, y: 0.796875 }, - { x: 0.109375, y: 0.796875 }, - { x: 0.140625, y: 0.796875 }, - { x: 0.140625, y: 0.796875 }, - { x: 0.171875, y: 0.796875 }, - { x: 0.171875, y: 0.796875 }, - { x: 0.203125, y: 0.796875 }, - { x: 0.203125, y: 0.796875 }, - { x: 0.234375, y: 0.796875 }, - { x: 0.234375, y: 0.796875 }, - { x: 0.265625, y: 0.796875 }, - { x: 0.265625, y: 0.796875 }, - { x: 0.296875, y: 0.796875 }, - { x: 0.296875, y: 0.796875 }, - { x: 0.328125, y: 0.796875 }, - { x: 0.328125, y: 0.796875 }, - { x: 0.359375, y: 0.796875 }, - { x: 0.359375, y: 0.796875 }, - { x: 0.390625, y: 0.796875 }, - { x: 0.390625, y: 0.796875 }, - { x: 0.421875, y: 0.796875 }, - { x: 0.421875, y: 0.796875 }, - { x: 0.453125, y: 0.796875 }, - { x: 0.453125, y: 0.796875 }, - { x: 0.484375, y: 0.796875 }, - { x: 0.484375, y: 0.796875 }, - { x: 0.515625, y: 0.796875 }, - { x: 0.515625, y: 0.796875 }, - { x: 0.546875, y: 0.796875 }, - { x: 0.546875, y: 0.796875 }, - { x: 0.578125, y: 0.796875 }, - { x: 0.578125, y: 0.796875 }, - { x: 0.609375, y: 0.796875 }, - { x: 0.609375, y: 0.796875 }, - { x: 0.640625, y: 0.796875 }, - { x: 0.640625, y: 0.796875 }, - { x: 0.671875, y: 0.796875 }, - { x: 0.671875, y: 0.796875 }, - { x: 0.703125, y: 0.796875 }, - { x: 0.703125, y: 0.796875 }, - { x: 0.734375, y: 0.796875 }, - { x: 0.734375, y: 0.796875 }, - { x: 0.765625, y: 0.796875 }, - { x: 0.765625, y: 0.796875 }, - { x: 0.796875, y: 0.796875 }, - { x: 0.796875, y: 0.796875 }, - { x: 0.828125, y: 0.796875 }, - { x: 0.828125, y: 0.796875 }, - { x: 0.859375, y: 0.796875 }, - { x: 0.859375, y: 0.796875 }, - { x: 0.890625, y: 0.796875 }, - { x: 0.890625, y: 0.796875 }, - { x: 0.921875, y: 0.796875 }, - { x: 0.921875, y: 0.796875 }, - { x: 0.953125, y: 0.796875 }, - { x: 0.953125, y: 0.796875 }, - { x: 0.984375, y: 0.796875 }, - { x: 0.984375, y: 0.796875 }, - { x: 0.015625, y: 0.828125 }, - { x: 0.015625, y: 0.828125 }, - { x: 0.046875, y: 0.828125 }, - { x: 0.046875, y: 0.828125 }, - { x: 0.078125, y: 0.828125 }, - { x: 0.078125, y: 0.828125 }, - { x: 0.109375, y: 0.828125 }, - { x: 0.109375, y: 0.828125 }, - { x: 0.140625, y: 0.828125 }, - { x: 0.140625, y: 0.828125 }, - { x: 0.171875, y: 0.828125 }, - { x: 0.171875, y: 0.828125 }, - { x: 0.203125, y: 0.828125 }, - { x: 0.203125, y: 0.828125 }, - { x: 0.234375, y: 0.828125 }, - { x: 0.234375, y: 0.828125 }, - { x: 0.265625, y: 0.828125 }, - { x: 0.265625, y: 0.828125 }, - { x: 0.296875, y: 0.828125 }, - { x: 0.296875, y: 0.828125 }, - { x: 0.328125, y: 0.828125 }, - { x: 0.328125, y: 0.828125 }, - { x: 0.359375, y: 0.828125 }, - { x: 0.359375, y: 0.828125 }, - { x: 0.390625, y: 0.828125 }, - { x: 0.390625, y: 0.828125 }, - { x: 0.421875, y: 0.828125 }, - { x: 0.421875, y: 0.828125 }, - { x: 0.453125, y: 0.828125 }, - { x: 0.453125, y: 0.828125 }, - { x: 0.484375, y: 0.828125 }, - { x: 0.484375, y: 0.828125 }, - { x: 0.515625, y: 0.828125 }, - { x: 0.515625, y: 0.828125 }, - { x: 0.546875, y: 0.828125 }, - { x: 0.546875, y: 0.828125 }, - { x: 0.578125, y: 0.828125 }, - { x: 0.578125, y: 0.828125 }, - { x: 0.609375, y: 0.828125 }, - { x: 0.609375, y: 0.828125 }, - { x: 0.640625, y: 0.828125 }, - { x: 0.640625, y: 0.828125 }, - { x: 0.671875, y: 0.828125 }, - { x: 0.671875, y: 0.828125 }, - { x: 0.703125, y: 0.828125 }, - { x: 0.703125, y: 0.828125 }, - { x: 0.734375, y: 0.828125 }, - { x: 0.734375, y: 0.828125 }, - { x: 0.765625, y: 0.828125 }, - { x: 0.765625, y: 0.828125 }, - { x: 0.796875, y: 0.828125 }, - { x: 0.796875, y: 0.828125 }, - { x: 0.828125, y: 0.828125 }, - { x: 0.828125, y: 0.828125 }, - { x: 0.859375, y: 0.828125 }, - { x: 0.859375, y: 0.828125 }, - { x: 0.890625, y: 0.828125 }, - { x: 0.890625, y: 0.828125 }, - { x: 0.921875, y: 0.828125 }, - { x: 0.921875, y: 0.828125 }, - { x: 0.953125, y: 0.828125 }, - { x: 0.953125, y: 0.828125 }, - { x: 0.984375, y: 0.828125 }, - { x: 0.984375, y: 0.828125 }, - { x: 0.015625, y: 0.859375 }, - { x: 0.015625, y: 0.859375 }, - { x: 0.046875, y: 0.859375 }, - { x: 0.046875, y: 0.859375 }, - { x: 0.078125, y: 0.859375 }, - { x: 0.078125, y: 0.859375 }, - { x: 0.109375, y: 0.859375 }, - { x: 0.109375, y: 0.859375 }, - { x: 0.140625, y: 0.859375 }, - { x: 0.140625, y: 0.859375 }, - { x: 0.171875, y: 0.859375 }, - { x: 0.171875, y: 0.859375 }, - { x: 0.203125, y: 0.859375 }, - { x: 0.203125, y: 0.859375 }, - { x: 0.234375, y: 0.859375 }, - { x: 0.234375, y: 0.859375 }, - { x: 0.265625, y: 0.859375 }, - { x: 0.265625, y: 0.859375 }, - { x: 0.296875, y: 0.859375 }, - { x: 0.296875, y: 0.859375 }, - { x: 0.328125, y: 0.859375 }, - { x: 0.328125, y: 0.859375 }, - { x: 0.359375, y: 0.859375 }, - { x: 0.359375, y: 0.859375 }, - { x: 0.390625, y: 0.859375 }, - { x: 0.390625, y: 0.859375 }, - { x: 0.421875, y: 0.859375 }, - { x: 0.421875, y: 0.859375 }, - { x: 0.453125, y: 0.859375 }, - { x: 0.453125, y: 0.859375 }, - { x: 0.484375, y: 0.859375 }, - { x: 0.484375, y: 0.859375 }, - { x: 0.515625, y: 0.859375 }, - { x: 0.515625, y: 0.859375 }, - { x: 0.546875, y: 0.859375 }, - { x: 0.546875, y: 0.859375 }, - { x: 0.578125, y: 0.859375 }, - { x: 0.578125, y: 0.859375 }, - { x: 0.609375, y: 0.859375 }, - { x: 0.609375, y: 0.859375 }, - { x: 0.640625, y: 0.859375 }, - { x: 0.640625, y: 0.859375 }, - { x: 0.671875, y: 0.859375 }, - { x: 0.671875, y: 0.859375 }, - { x: 0.703125, y: 0.859375 }, - { x: 0.703125, y: 0.859375 }, - { x: 0.734375, y: 0.859375 }, - { x: 0.734375, y: 0.859375 }, - { x: 0.765625, y: 0.859375 }, - { x: 0.765625, y: 0.859375 }, - { x: 0.796875, y: 0.859375 }, - { x: 0.796875, y: 0.859375 }, - { x: 0.828125, y: 0.859375 }, - { x: 0.828125, y: 0.859375 }, - { x: 0.859375, y: 0.859375 }, - { x: 0.859375, y: 0.859375 }, - { x: 0.890625, y: 0.859375 }, - { x: 0.890625, y: 0.859375 }, - { x: 0.921875, y: 0.859375 }, - { x: 0.921875, y: 0.859375 }, - { x: 0.953125, y: 0.859375 }, - { x: 0.953125, y: 0.859375 }, - { x: 0.984375, y: 0.859375 }, - { x: 0.984375, y: 0.859375 }, - { x: 0.015625, y: 0.890625 }, - { x: 0.015625, y: 0.890625 }, - { x: 0.046875, y: 0.890625 }, - { x: 0.046875, y: 0.890625 }, - { x: 0.078125, y: 0.890625 }, - { x: 0.078125, y: 0.890625 }, - { x: 0.109375, y: 0.890625 }, - { x: 0.109375, y: 0.890625 }, - { x: 0.140625, y: 0.890625 }, - { x: 0.140625, y: 0.890625 }, - { x: 0.171875, y: 0.890625 }, - { x: 0.171875, y: 0.890625 }, - { x: 0.203125, y: 0.890625 }, - { x: 0.203125, y: 0.890625 }, - { x: 0.234375, y: 0.890625 }, - { x: 0.234375, y: 0.890625 }, - { x: 0.265625, y: 0.890625 }, - { x: 0.265625, y: 0.890625 }, - { x: 0.296875, y: 0.890625 }, - { x: 0.296875, y: 0.890625 }, - { x: 0.328125, y: 0.890625 }, - { x: 0.328125, y: 0.890625 }, - { x: 0.359375, y: 0.890625 }, - { x: 0.359375, y: 0.890625 }, - { x: 0.390625, y: 0.890625 }, - { x: 0.390625, y: 0.890625 }, - { x: 0.421875, y: 0.890625 }, - { x: 0.421875, y: 0.890625 }, - { x: 0.453125, y: 0.890625 }, - { x: 0.453125, y: 0.890625 }, - { x: 0.484375, y: 0.890625 }, - { x: 0.484375, y: 0.890625 }, - { x: 0.515625, y: 0.890625 }, - { x: 0.515625, y: 0.890625 }, - { x: 0.546875, y: 0.890625 }, - { x: 0.546875, y: 0.890625 }, - { x: 0.578125, y: 0.890625 }, - { x: 0.578125, y: 0.890625 }, - { x: 0.609375, y: 0.890625 }, - { x: 0.609375, y: 0.890625 }, - { x: 0.640625, y: 0.890625 }, - { x: 0.640625, y: 0.890625 }, - { x: 0.671875, y: 0.890625 }, - { x: 0.671875, y: 0.890625 }, - { x: 0.703125, y: 0.890625 }, - { x: 0.703125, y: 0.890625 }, - { x: 0.734375, y: 0.890625 }, - { x: 0.734375, y: 0.890625 }, - { x: 0.765625, y: 0.890625 }, - { x: 0.765625, y: 0.890625 }, - { x: 0.796875, y: 0.890625 }, - { x: 0.796875, y: 0.890625 }, - { x: 0.828125, y: 0.890625 }, - { x: 0.828125, y: 0.890625 }, - { x: 0.859375, y: 0.890625 }, - { x: 0.859375, y: 0.890625 }, - { x: 0.890625, y: 0.890625 }, - { x: 0.890625, y: 0.890625 }, - { x: 0.921875, y: 0.890625 }, - { x: 0.921875, y: 0.890625 }, - { x: 0.953125, y: 0.890625 }, - { x: 0.953125, y: 0.890625 }, - { x: 0.984375, y: 0.890625 }, - { x: 0.984375, y: 0.890625 }, - { x: 0.015625, y: 0.921875 }, - { x: 0.015625, y: 0.921875 }, - { x: 0.046875, y: 0.921875 }, - { x: 0.046875, y: 0.921875 }, - { x: 0.078125, y: 0.921875 }, - { x: 0.078125, y: 0.921875 }, - { x: 0.109375, y: 0.921875 }, - { x: 0.109375, y: 0.921875 }, - { x: 0.140625, y: 0.921875 }, - { x: 0.140625, y: 0.921875 }, - { x: 0.171875, y: 0.921875 }, - { x: 0.171875, y: 0.921875 }, - { x: 0.203125, y: 0.921875 }, - { x: 0.203125, y: 0.921875 }, - { x: 0.234375, y: 0.921875 }, - { x: 0.234375, y: 0.921875 }, - { x: 0.265625, y: 0.921875 }, - { x: 0.265625, y: 0.921875 }, - { x: 0.296875, y: 0.921875 }, - { x: 0.296875, y: 0.921875 }, - { x: 0.328125, y: 0.921875 }, - { x: 0.328125, y: 0.921875 }, - { x: 0.359375, y: 0.921875 }, - { x: 0.359375, y: 0.921875 }, - { x: 0.390625, y: 0.921875 }, - { x: 0.390625, y: 0.921875 }, - { x: 0.421875, y: 0.921875 }, - { x: 0.421875, y: 0.921875 }, - { x: 0.453125, y: 0.921875 }, - { x: 0.453125, y: 0.921875 }, - { x: 0.484375, y: 0.921875 }, - { x: 0.484375, y: 0.921875 }, - { x: 0.515625, y: 0.921875 }, - { x: 0.515625, y: 0.921875 }, - { x: 0.546875, y: 0.921875 }, - { x: 0.546875, y: 0.921875 }, - { x: 0.578125, y: 0.921875 }, - { x: 0.578125, y: 0.921875 }, - { x: 0.609375, y: 0.921875 }, - { x: 0.609375, y: 0.921875 }, - { x: 0.640625, y: 0.921875 }, - { x: 0.640625, y: 0.921875 }, - { x: 0.671875, y: 0.921875 }, - { x: 0.671875, y: 0.921875 }, - { x: 0.703125, y: 0.921875 }, - { x: 0.703125, y: 0.921875 }, - { x: 0.734375, y: 0.921875 }, - { x: 0.734375, y: 0.921875 }, - { x: 0.765625, y: 0.921875 }, - { x: 0.765625, y: 0.921875 }, - { x: 0.796875, y: 0.921875 }, - { x: 0.796875, y: 0.921875 }, - { x: 0.828125, y: 0.921875 }, - { x: 0.828125, y: 0.921875 }, - { x: 0.859375, y: 0.921875 }, - { x: 0.859375, y: 0.921875 }, - { x: 0.890625, y: 0.921875 }, - { x: 0.890625, y: 0.921875 }, - { x: 0.921875, y: 0.921875 }, - { x: 0.921875, y: 0.921875 }, - { x: 0.953125, y: 0.921875 }, - { x: 0.953125, y: 0.921875 }, - { x: 0.984375, y: 0.921875 }, - { x: 0.984375, y: 0.921875 }, - { x: 0.015625, y: 0.953125 }, - { x: 0.015625, y: 0.953125 }, - { x: 0.046875, y: 0.953125 }, - { x: 0.046875, y: 0.953125 }, - { x: 0.078125, y: 0.953125 }, - { x: 0.078125, y: 0.953125 }, - { x: 0.109375, y: 0.953125 }, - { x: 0.109375, y: 0.953125 }, - { x: 0.140625, y: 0.953125 }, - { x: 0.140625, y: 0.953125 }, - { x: 0.171875, y: 0.953125 }, - { x: 0.171875, y: 0.953125 }, - { x: 0.203125, y: 0.953125 }, - { x: 0.203125, y: 0.953125 }, - { x: 0.234375, y: 0.953125 }, - { x: 0.234375, y: 0.953125 }, - { x: 0.265625, y: 0.953125 }, - { x: 0.265625, y: 0.953125 }, - { x: 0.296875, y: 0.953125 }, - { x: 0.296875, y: 0.953125 }, - { x: 0.328125, y: 0.953125 }, - { x: 0.328125, y: 0.953125 }, - { x: 0.359375, y: 0.953125 }, - { x: 0.359375, y: 0.953125 }, - { x: 0.390625, y: 0.953125 }, - { x: 0.390625, y: 0.953125 }, - { x: 0.421875, y: 0.953125 }, - { x: 0.421875, y: 0.953125 }, - { x: 0.453125, y: 0.953125 }, - { x: 0.453125, y: 0.953125 }, - { x: 0.484375, y: 0.953125 }, - { x: 0.484375, y: 0.953125 }, - { x: 0.515625, y: 0.953125 }, - { x: 0.515625, y: 0.953125 }, - { x: 0.546875, y: 0.953125 }, - { x: 0.546875, y: 0.953125 }, - { x: 0.578125, y: 0.953125 }, - { x: 0.578125, y: 0.953125 }, - { x: 0.609375, y: 0.953125 }, - { x: 0.609375, y: 0.953125 }, - { x: 0.640625, y: 0.953125 }, - { x: 0.640625, y: 0.953125 }, - { x: 0.671875, y: 0.953125 }, - { x: 0.671875, y: 0.953125 }, - { x: 0.703125, y: 0.953125 }, - { x: 0.703125, y: 0.953125 }, - { x: 0.734375, y: 0.953125 }, - { x: 0.734375, y: 0.953125 }, - { x: 0.765625, y: 0.953125 }, - { x: 0.765625, y: 0.953125 }, - { x: 0.796875, y: 0.953125 }, - { x: 0.796875, y: 0.953125 }, - { x: 0.828125, y: 0.953125 }, - { x: 0.828125, y: 0.953125 }, - { x: 0.859375, y: 0.953125 }, - { x: 0.859375, y: 0.953125 }, - { x: 0.890625, y: 0.953125 }, - { x: 0.890625, y: 0.953125 }, - { x: 0.921875, y: 0.953125 }, - { x: 0.921875, y: 0.953125 }, - { x: 0.953125, y: 0.953125 }, - { x: 0.953125, y: 0.953125 }, - { x: 0.984375, y: 0.953125 }, - { x: 0.984375, y: 0.953125 }, - { x: 0.015625, y: 0.984375 }, - { x: 0.015625, y: 0.984375 }, - { x: 0.046875, y: 0.984375 }, - { x: 0.046875, y: 0.984375 }, - { x: 0.078125, y: 0.984375 }, - { x: 0.078125, y: 0.984375 }, - { x: 0.109375, y: 0.984375 }, - { x: 0.109375, y: 0.984375 }, - { x: 0.140625, y: 0.984375 }, - { x: 0.140625, y: 0.984375 }, - { x: 0.171875, y: 0.984375 }, - { x: 0.171875, y: 0.984375 }, - { x: 0.203125, y: 0.984375 }, - { x: 0.203125, y: 0.984375 }, - { x: 0.234375, y: 0.984375 }, - { x: 0.234375, y: 0.984375 }, - { x: 0.265625, y: 0.984375 }, - { x: 0.265625, y: 0.984375 }, - { x: 0.296875, y: 0.984375 }, - { x: 0.296875, y: 0.984375 }, - { x: 0.328125, y: 0.984375 }, - { x: 0.328125, y: 0.984375 }, - { x: 0.359375, y: 0.984375 }, - { x: 0.359375, y: 0.984375 }, - { x: 0.390625, y: 0.984375 }, - { x: 0.390625, y: 0.984375 }, - { x: 0.421875, y: 0.984375 }, - { x: 0.421875, y: 0.984375 }, - { x: 0.453125, y: 0.984375 }, - { x: 0.453125, y: 0.984375 }, - { x: 0.484375, y: 0.984375 }, - { x: 0.484375, y: 0.984375 }, - { x: 0.515625, y: 0.984375 }, - { x: 0.515625, y: 0.984375 }, - { x: 0.546875, y: 0.984375 }, - { x: 0.546875, y: 0.984375 }, - { x: 0.578125, y: 0.984375 }, - { x: 0.578125, y: 0.984375 }, - { x: 0.609375, y: 0.984375 }, - { x: 0.609375, y: 0.984375 }, - { x: 0.640625, y: 0.984375 }, - { x: 0.640625, y: 0.984375 }, - { x: 0.671875, y: 0.984375 }, - { x: 0.671875, y: 0.984375 }, - { x: 0.703125, y: 0.984375 }, - { x: 0.703125, y: 0.984375 }, - { x: 0.734375, y: 0.984375 }, - { x: 0.734375, y: 0.984375 }, - { x: 0.765625, y: 0.984375 }, - { x: 0.765625, y: 0.984375 }, - { x: 0.796875, y: 0.984375 }, - { x: 0.796875, y: 0.984375 }, - { x: 0.828125, y: 0.984375 }, - { x: 0.828125, y: 0.984375 }, - { x: 0.859375, y: 0.984375 }, - { x: 0.859375, y: 0.984375 }, - { x: 0.890625, y: 0.984375 }, - { x: 0.890625, y: 0.984375 }, - { x: 0.921875, y: 0.984375 }, - { x: 0.921875, y: 0.984375 }, - { x: 0.953125, y: 0.984375 }, - { x: 0.953125, y: 0.984375 }, - { x: 0.984375, y: 0.984375 }, - { x: 0.984375, y: 0.984375 }, - { x: 0.03125, y: 0.03125 }, - { x: 0.03125, y: 0.03125 }, - { x: 0.09375, y: 0.03125 }, - { x: 0.09375, y: 0.03125 }, - { x: 0.15625, y: 0.03125 }, - { x: 0.15625, y: 0.03125 }, - { x: 0.21875, y: 0.03125 }, - { x: 0.21875, y: 0.03125 }, - { x: 0.28125, y: 0.03125 }, - { x: 0.28125, y: 0.03125 }, - { x: 0.34375, y: 0.03125 }, - { x: 0.34375, y: 0.03125 }, - { x: 0.40625, y: 0.03125 }, - { x: 0.40625, y: 0.03125 }, - { x: 0.46875, y: 0.03125 }, - { x: 0.46875, y: 0.03125 }, - { x: 0.53125, y: 0.03125 }, - { x: 0.53125, y: 0.03125 }, - { x: 0.59375, y: 0.03125 }, - { x: 0.59375, y: 0.03125 }, - { x: 0.65625, y: 0.03125 }, - { x: 0.65625, y: 0.03125 }, - { x: 0.71875, y: 0.03125 }, - { x: 0.71875, y: 0.03125 }, - { x: 0.78125, y: 0.03125 }, - { x: 0.78125, y: 0.03125 }, - { x: 0.84375, y: 0.03125 }, - { x: 0.84375, y: 0.03125 }, - { x: 0.90625, y: 0.03125 }, - { x: 0.90625, y: 0.03125 }, - { x: 0.96875, y: 0.03125 }, - { x: 0.96875, y: 0.03125 }, - { x: 0.03125, y: 0.09375 }, - { x: 0.03125, y: 0.09375 }, - { x: 0.09375, y: 0.09375 }, - { x: 0.09375, y: 0.09375 }, - { x: 0.15625, y: 0.09375 }, - { x: 0.15625, y: 0.09375 }, - { x: 0.21875, y: 0.09375 }, - { x: 0.21875, y: 0.09375 }, - { x: 0.28125, y: 0.09375 }, - { x: 0.28125, y: 0.09375 }, - { x: 0.34375, y: 0.09375 }, - { x: 0.34375, y: 0.09375 }, - { x: 0.40625, y: 0.09375 }, - { x: 0.40625, y: 0.09375 }, - { x: 0.46875, y: 0.09375 }, - { x: 0.46875, y: 0.09375 }, - { x: 0.53125, y: 0.09375 }, - { x: 0.53125, y: 0.09375 }, - { x: 0.59375, y: 0.09375 }, - { x: 0.59375, y: 0.09375 }, - { x: 0.65625, y: 0.09375 }, - { x: 0.65625, y: 0.09375 }, - { x: 0.71875, y: 0.09375 }, - { x: 0.71875, y: 0.09375 }, - { x: 0.78125, y: 0.09375 }, - { x: 0.78125, y: 0.09375 }, - { x: 0.84375, y: 0.09375 }, - { x: 0.84375, y: 0.09375 }, - { x: 0.90625, y: 0.09375 }, - { x: 0.90625, y: 0.09375 }, - { x: 0.96875, y: 0.09375 }, - { x: 0.96875, y: 0.09375 }, - { x: 0.03125, y: 0.15625 }, - { x: 0.03125, y: 0.15625 }, - { x: 0.09375, y: 0.15625 }, - { x: 0.09375, y: 0.15625 }, - { x: 0.15625, y: 0.15625 }, - { x: 0.15625, y: 0.15625 }, - { x: 0.21875, y: 0.15625 }, - { x: 0.21875, y: 0.15625 }, - { x: 0.28125, y: 0.15625 }, - { x: 0.28125, y: 0.15625 }, - { x: 0.34375, y: 0.15625 }, - { x: 0.34375, y: 0.15625 }, - { x: 0.40625, y: 0.15625 }, - { x: 0.40625, y: 0.15625 }, - { x: 0.46875, y: 0.15625 }, - { x: 0.46875, y: 0.15625 }, - { x: 0.53125, y: 0.15625 }, - { x: 0.53125, y: 0.15625 }, - { x: 0.59375, y: 0.15625 }, - { x: 0.59375, y: 0.15625 }, - { x: 0.65625, y: 0.15625 }, - { x: 0.65625, y: 0.15625 }, - { x: 0.71875, y: 0.15625 }, - { x: 0.71875, y: 0.15625 }, - { x: 0.78125, y: 0.15625 }, - { x: 0.78125, y: 0.15625 }, - { x: 0.84375, y: 0.15625 }, - { x: 0.84375, y: 0.15625 }, - { x: 0.90625, y: 0.15625 }, - { x: 0.90625, y: 0.15625 }, - { x: 0.96875, y: 0.15625 }, - { x: 0.96875, y: 0.15625 }, - { x: 0.03125, y: 0.21875 }, - { x: 0.03125, y: 0.21875 }, - { x: 0.09375, y: 0.21875 }, - { x: 0.09375, y: 0.21875 }, - { x: 0.15625, y: 0.21875 }, - { x: 0.15625, y: 0.21875 }, - { x: 0.21875, y: 0.21875 }, - { x: 0.21875, y: 0.21875 }, - { x: 0.28125, y: 0.21875 }, - { x: 0.28125, y: 0.21875 }, - { x: 0.34375, y: 0.21875 }, - { x: 0.34375, y: 0.21875 }, - { x: 0.40625, y: 0.21875 }, - { x: 0.40625, y: 0.21875 }, - { x: 0.46875, y: 0.21875 }, - { x: 0.46875, y: 0.21875 }, - { x: 0.53125, y: 0.21875 }, - { x: 0.53125, y: 0.21875 }, - { x: 0.59375, y: 0.21875 }, - { x: 0.59375, y: 0.21875 }, - { x: 0.65625, y: 0.21875 }, - { x: 0.65625, y: 0.21875 }, - { x: 0.71875, y: 0.21875 }, - { x: 0.71875, y: 0.21875 }, - { x: 0.78125, y: 0.21875 }, - { x: 0.78125, y: 0.21875 }, - { x: 0.84375, y: 0.21875 }, - { x: 0.84375, y: 0.21875 }, - { x: 0.90625, y: 0.21875 }, - { x: 0.90625, y: 0.21875 }, - { x: 0.96875, y: 0.21875 }, - { x: 0.96875, y: 0.21875 }, - { x: 0.03125, y: 0.28125 }, - { x: 0.03125, y: 0.28125 }, - { x: 0.09375, y: 0.28125 }, - { x: 0.09375, y: 0.28125 }, - { x: 0.15625, y: 0.28125 }, - { x: 0.15625, y: 0.28125 }, - { x: 0.21875, y: 0.28125 }, - { x: 0.21875, y: 0.28125 }, - { x: 0.28125, y: 0.28125 }, - { x: 0.28125, y: 0.28125 }, - { x: 0.34375, y: 0.28125 }, - { x: 0.34375, y: 0.28125 }, - { x: 0.40625, y: 0.28125 }, - { x: 0.40625, y: 0.28125 }, - { x: 0.46875, y: 0.28125 }, - { x: 0.46875, y: 0.28125 }, - { x: 0.53125, y: 0.28125 }, - { x: 0.53125, y: 0.28125 }, - { x: 0.59375, y: 0.28125 }, - { x: 0.59375, y: 0.28125 }, - { x: 0.65625, y: 0.28125 }, - { x: 0.65625, y: 0.28125 }, - { x: 0.71875, y: 0.28125 }, - { x: 0.71875, y: 0.28125 }, - { x: 0.78125, y: 0.28125 }, - { x: 0.78125, y: 0.28125 }, - { x: 0.84375, y: 0.28125 }, - { x: 0.84375, y: 0.28125 }, - { x: 0.90625, y: 0.28125 }, - { x: 0.90625, y: 0.28125 }, - { x: 0.96875, y: 0.28125 }, - { x: 0.96875, y: 0.28125 }, - { x: 0.03125, y: 0.34375 }, - { x: 0.03125, y: 0.34375 }, - { x: 0.09375, y: 0.34375 }, - { x: 0.09375, y: 0.34375 }, - { x: 0.15625, y: 0.34375 }, - { x: 0.15625, y: 0.34375 }, - { x: 0.21875, y: 0.34375 }, - { x: 0.21875, y: 0.34375 }, - { x: 0.28125, y: 0.34375 }, - { x: 0.28125, y: 0.34375 }, - { x: 0.34375, y: 0.34375 }, - { x: 0.34375, y: 0.34375 }, - { x: 0.40625, y: 0.34375 }, - { x: 0.40625, y: 0.34375 }, - { x: 0.46875, y: 0.34375 }, - { x: 0.46875, y: 0.34375 }, - { x: 0.53125, y: 0.34375 }, - { x: 0.53125, y: 0.34375 }, - { x: 0.59375, y: 0.34375 }, - { x: 0.59375, y: 0.34375 }, - { x: 0.65625, y: 0.34375 }, - { x: 0.65625, y: 0.34375 }, - { x: 0.71875, y: 0.34375 }, - { x: 0.71875, y: 0.34375 }, - { x: 0.78125, y: 0.34375 }, - { x: 0.78125, y: 0.34375 }, - { x: 0.84375, y: 0.34375 }, - { x: 0.84375, y: 0.34375 }, - { x: 0.90625, y: 0.34375 }, - { x: 0.90625, y: 0.34375 }, - { x: 0.96875, y: 0.34375 }, - { x: 0.96875, y: 0.34375 }, - { x: 0.03125, y: 0.40625 }, - { x: 0.03125, y: 0.40625 }, - { x: 0.09375, y: 0.40625 }, - { x: 0.09375, y: 0.40625 }, - { x: 0.15625, y: 0.40625 }, - { x: 0.15625, y: 0.40625 }, - { x: 0.21875, y: 0.40625 }, - { x: 0.21875, y: 0.40625 }, - { x: 0.28125, y: 0.40625 }, - { x: 0.28125, y: 0.40625 }, - { x: 0.34375, y: 0.40625 }, - { x: 0.34375, y: 0.40625 }, - { x: 0.40625, y: 0.40625 }, - { x: 0.40625, y: 0.40625 }, - { x: 0.46875, y: 0.40625 }, - { x: 0.46875, y: 0.40625 }, - { x: 0.53125, y: 0.40625 }, - { x: 0.53125, y: 0.40625 }, - { x: 0.59375, y: 0.40625 }, - { x: 0.59375, y: 0.40625 }, - { x: 0.65625, y: 0.40625 }, - { x: 0.65625, y: 0.40625 }, - { x: 0.71875, y: 0.40625 }, - { x: 0.71875, y: 0.40625 }, - { x: 0.78125, y: 0.40625 }, - { x: 0.78125, y: 0.40625 }, - { x: 0.84375, y: 0.40625 }, - { x: 0.84375, y: 0.40625 }, - { x: 0.90625, y: 0.40625 }, - { x: 0.90625, y: 0.40625 }, - { x: 0.96875, y: 0.40625 }, - { x: 0.96875, y: 0.40625 }, - { x: 0.03125, y: 0.46875 }, - { x: 0.03125, y: 0.46875 }, - { x: 0.09375, y: 0.46875 }, - { x: 0.09375, y: 0.46875 }, - { x: 0.15625, y: 0.46875 }, - { x: 0.15625, y: 0.46875 }, - { x: 0.21875, y: 0.46875 }, - { x: 0.21875, y: 0.46875 }, - { x: 0.28125, y: 0.46875 }, - { x: 0.28125, y: 0.46875 }, - { x: 0.34375, y: 0.46875 }, - { x: 0.34375, y: 0.46875 }, - { x: 0.40625, y: 0.46875 }, - { x: 0.40625, y: 0.46875 }, - { x: 0.46875, y: 0.46875 }, - { x: 0.46875, y: 0.46875 }, - { x: 0.53125, y: 0.46875 }, - { x: 0.53125, y: 0.46875 }, - { x: 0.59375, y: 0.46875 }, - { x: 0.59375, y: 0.46875 }, - { x: 0.65625, y: 0.46875 }, - { x: 0.65625, y: 0.46875 }, - { x: 0.71875, y: 0.46875 }, - { x: 0.71875, y: 0.46875 }, - { x: 0.78125, y: 0.46875 }, - { x: 0.78125, y: 0.46875 }, - { x: 0.84375, y: 0.46875 }, - { x: 0.84375, y: 0.46875 }, - { x: 0.90625, y: 0.46875 }, - { x: 0.90625, y: 0.46875 }, - { x: 0.96875, y: 0.46875 }, - { x: 0.96875, y: 0.46875 }, - { x: 0.03125, y: 0.53125 }, - { x: 0.03125, y: 0.53125 }, - { x: 0.09375, y: 0.53125 }, - { x: 0.09375, y: 0.53125 }, - { x: 0.15625, y: 0.53125 }, - { x: 0.15625, y: 0.53125 }, - { x: 0.21875, y: 0.53125 }, - { x: 0.21875, y: 0.53125 }, - { x: 0.28125, y: 0.53125 }, - { x: 0.28125, y: 0.53125 }, - { x: 0.34375, y: 0.53125 }, - { x: 0.34375, y: 0.53125 }, - { x: 0.40625, y: 0.53125 }, - { x: 0.40625, y: 0.53125 }, - { x: 0.46875, y: 0.53125 }, - { x: 0.46875, y: 0.53125 }, - { x: 0.53125, y: 0.53125 }, - { x: 0.53125, y: 0.53125 }, - { x: 0.59375, y: 0.53125 }, - { x: 0.59375, y: 0.53125 }, - { x: 0.65625, y: 0.53125 }, - { x: 0.65625, y: 0.53125 }, - { x: 0.71875, y: 0.53125 }, - { x: 0.71875, y: 0.53125 }, - { x: 0.78125, y: 0.53125 }, - { x: 0.78125, y: 0.53125 }, - { x: 0.84375, y: 0.53125 }, - { x: 0.84375, y: 0.53125 }, - { x: 0.90625, y: 0.53125 }, - { x: 0.90625, y: 0.53125 }, - { x: 0.96875, y: 0.53125 }, - { x: 0.96875, y: 0.53125 }, - { x: 0.03125, y: 0.59375 }, - { x: 0.03125, y: 0.59375 }, - { x: 0.09375, y: 0.59375 }, - { x: 0.09375, y: 0.59375 }, - { x: 0.15625, y: 0.59375 }, - { x: 0.15625, y: 0.59375 }, - { x: 0.21875, y: 0.59375 }, - { x: 0.21875, y: 0.59375 }, - { x: 0.28125, y: 0.59375 }, - { x: 0.28125, y: 0.59375 }, - { x: 0.34375, y: 0.59375 }, - { x: 0.34375, y: 0.59375 }, - { x: 0.40625, y: 0.59375 }, - { x: 0.40625, y: 0.59375 }, - { x: 0.46875, y: 0.59375 }, - { x: 0.46875, y: 0.59375 }, - { x: 0.53125, y: 0.59375 }, - { x: 0.53125, y: 0.59375 }, - { x: 0.59375, y: 0.59375 }, - { x: 0.59375, y: 0.59375 }, - { x: 0.65625, y: 0.59375 }, - { x: 0.65625, y: 0.59375 }, - { x: 0.71875, y: 0.59375 }, - { x: 0.71875, y: 0.59375 }, - { x: 0.78125, y: 0.59375 }, - { x: 0.78125, y: 0.59375 }, - { x: 0.84375, y: 0.59375 }, - { x: 0.84375, y: 0.59375 }, - { x: 0.90625, y: 0.59375 }, - { x: 0.90625, y: 0.59375 }, - { x: 0.96875, y: 0.59375 }, - { x: 0.96875, y: 0.59375 }, - { x: 0.03125, y: 0.65625 }, - { x: 0.03125, y: 0.65625 }, - { x: 0.09375, y: 0.65625 }, - { x: 0.09375, y: 0.65625 }, - { x: 0.15625, y: 0.65625 }, - { x: 0.15625, y: 0.65625 }, - { x: 0.21875, y: 0.65625 }, - { x: 0.21875, y: 0.65625 }, - { x: 0.28125, y: 0.65625 }, - { x: 0.28125, y: 0.65625 }, - { x: 0.34375, y: 0.65625 }, - { x: 0.34375, y: 0.65625 }, - { x: 0.40625, y: 0.65625 }, - { x: 0.40625, y: 0.65625 }, - { x: 0.46875, y: 0.65625 }, - { x: 0.46875, y: 0.65625 }, - { x: 0.53125, y: 0.65625 }, - { x: 0.53125, y: 0.65625 }, - { x: 0.59375, y: 0.65625 }, - { x: 0.59375, y: 0.65625 }, - { x: 0.65625, y: 0.65625 }, - { x: 0.65625, y: 0.65625 }, - { x: 0.71875, y: 0.65625 }, - { x: 0.71875, y: 0.65625 }, - { x: 0.78125, y: 0.65625 }, - { x: 0.78125, y: 0.65625 }, - { x: 0.84375, y: 0.65625 }, - { x: 0.84375, y: 0.65625 }, - { x: 0.90625, y: 0.65625 }, - { x: 0.90625, y: 0.65625 }, - { x: 0.96875, y: 0.65625 }, - { x: 0.96875, y: 0.65625 }, - { x: 0.03125, y: 0.71875 }, - { x: 0.03125, y: 0.71875 }, - { x: 0.09375, y: 0.71875 }, - { x: 0.09375, y: 0.71875 }, - { x: 0.15625, y: 0.71875 }, - { x: 0.15625, y: 0.71875 }, - { x: 0.21875, y: 0.71875 }, - { x: 0.21875, y: 0.71875 }, - { x: 0.28125, y: 0.71875 }, - { x: 0.28125, y: 0.71875 }, - { x: 0.34375, y: 0.71875 }, - { x: 0.34375, y: 0.71875 }, - { x: 0.40625, y: 0.71875 }, - { x: 0.40625, y: 0.71875 }, - { x: 0.46875, y: 0.71875 }, - { x: 0.46875, y: 0.71875 }, - { x: 0.53125, y: 0.71875 }, - { x: 0.53125, y: 0.71875 }, - { x: 0.59375, y: 0.71875 }, - { x: 0.59375, y: 0.71875 }, - { x: 0.65625, y: 0.71875 }, - { x: 0.65625, y: 0.71875 }, - { x: 0.71875, y: 0.71875 }, - { x: 0.71875, y: 0.71875 }, - { x: 0.78125, y: 0.71875 }, - { x: 0.78125, y: 0.71875 }, - { x: 0.84375, y: 0.71875 }, - { x: 0.84375, y: 0.71875 }, - { x: 0.90625, y: 0.71875 }, - { x: 0.90625, y: 0.71875 }, - { x: 0.96875, y: 0.71875 }, - { x: 0.96875, y: 0.71875 }, - { x: 0.03125, y: 0.78125 }, - { x: 0.03125, y: 0.78125 }, - { x: 0.09375, y: 0.78125 }, - { x: 0.09375, y: 0.78125 }, - { x: 0.15625, y: 0.78125 }, - { x: 0.15625, y: 0.78125 }, - { x: 0.21875, y: 0.78125 }, - { x: 0.21875, y: 0.78125 }, - { x: 0.28125, y: 0.78125 }, - { x: 0.28125, y: 0.78125 }, - { x: 0.34375, y: 0.78125 }, - { x: 0.34375, y: 0.78125 }, - { x: 0.40625, y: 0.78125 }, - { x: 0.40625, y: 0.78125 }, - { x: 0.46875, y: 0.78125 }, - { x: 0.46875, y: 0.78125 }, - { x: 0.53125, y: 0.78125 }, - { x: 0.53125, y: 0.78125 }, - { x: 0.59375, y: 0.78125 }, - { x: 0.59375, y: 0.78125 }, - { x: 0.65625, y: 0.78125 }, - { x: 0.65625, y: 0.78125 }, - { x: 0.71875, y: 0.78125 }, - { x: 0.71875, y: 0.78125 }, - { x: 0.78125, y: 0.78125 }, - { x: 0.78125, y: 0.78125 }, - { x: 0.84375, y: 0.78125 }, - { x: 0.84375, y: 0.78125 }, - { x: 0.90625, y: 0.78125 }, - { x: 0.90625, y: 0.78125 }, - { x: 0.96875, y: 0.78125 }, - { x: 0.96875, y: 0.78125 }, - { x: 0.03125, y: 0.84375 }, - { x: 0.03125, y: 0.84375 }, - { x: 0.09375, y: 0.84375 }, - { x: 0.09375, y: 0.84375 }, - { x: 0.15625, y: 0.84375 }, - { x: 0.15625, y: 0.84375 }, - { x: 0.21875, y: 0.84375 }, - { x: 0.21875, y: 0.84375 }, - { x: 0.28125, y: 0.84375 }, - { x: 0.28125, y: 0.84375 }, - { x: 0.34375, y: 0.84375 }, - { x: 0.34375, y: 0.84375 }, - { x: 0.40625, y: 0.84375 }, - { x: 0.40625, y: 0.84375 }, - { x: 0.46875, y: 0.84375 }, - { x: 0.46875, y: 0.84375 }, - { x: 0.53125, y: 0.84375 }, - { x: 0.53125, y: 0.84375 }, - { x: 0.59375, y: 0.84375 }, - { x: 0.59375, y: 0.84375 }, - { x: 0.65625, y: 0.84375 }, - { x: 0.65625, y: 0.84375 }, - { x: 0.71875, y: 0.84375 }, - { x: 0.71875, y: 0.84375 }, - { x: 0.78125, y: 0.84375 }, - { x: 0.78125, y: 0.84375 }, - { x: 0.84375, y: 0.84375 }, - { x: 0.84375, y: 0.84375 }, - { x: 0.90625, y: 0.84375 }, - { x: 0.90625, y: 0.84375 }, - { x: 0.96875, y: 0.84375 }, - { x: 0.96875, y: 0.84375 }, - { x: 0.03125, y: 0.90625 }, - { x: 0.03125, y: 0.90625 }, - { x: 0.09375, y: 0.90625 }, - { x: 0.09375, y: 0.90625 }, - { x: 0.15625, y: 0.90625 }, - { x: 0.15625, y: 0.90625 }, - { x: 0.21875, y: 0.90625 }, - { x: 0.21875, y: 0.90625 }, - { x: 0.28125, y: 0.90625 }, - { x: 0.28125, y: 0.90625 }, - { x: 0.34375, y: 0.90625 }, - { x: 0.34375, y: 0.90625 }, - { x: 0.40625, y: 0.90625 }, - { x: 0.40625, y: 0.90625 }, - { x: 0.46875, y: 0.90625 }, - { x: 0.46875, y: 0.90625 }, - { x: 0.53125, y: 0.90625 }, - { x: 0.53125, y: 0.90625 }, - { x: 0.59375, y: 0.90625 }, - { x: 0.59375, y: 0.90625 }, - { x: 0.65625, y: 0.90625 }, - { x: 0.65625, y: 0.90625 }, - { x: 0.71875, y: 0.90625 }, - { x: 0.71875, y: 0.90625 }, - { x: 0.78125, y: 0.90625 }, - { x: 0.78125, y: 0.90625 }, - { x: 0.84375, y: 0.90625 }, - { x: 0.84375, y: 0.90625 }, - { x: 0.90625, y: 0.90625 }, - { x: 0.90625, y: 0.90625 }, - { x: 0.96875, y: 0.90625 }, - { x: 0.96875, y: 0.90625 }, - { x: 0.03125, y: 0.96875 }, - { x: 0.03125, y: 0.96875 }, - { x: 0.09375, y: 0.96875 }, - { x: 0.09375, y: 0.96875 }, - { x: 0.15625, y: 0.96875 }, - { x: 0.15625, y: 0.96875 }, - { x: 0.21875, y: 0.96875 }, - { x: 0.21875, y: 0.96875 }, - { x: 0.28125, y: 0.96875 }, - { x: 0.28125, y: 0.96875 }, - { x: 0.34375, y: 0.96875 }, - { x: 0.34375, y: 0.96875 }, - { x: 0.40625, y: 0.96875 }, - { x: 0.40625, y: 0.96875 }, - { x: 0.46875, y: 0.96875 }, - { x: 0.46875, y: 0.96875 }, - { x: 0.53125, y: 0.96875 }, - { x: 0.53125, y: 0.96875 }, - { x: 0.59375, y: 0.96875 }, - { x: 0.59375, y: 0.96875 }, - { x: 0.65625, y: 0.96875 }, - { x: 0.65625, y: 0.96875 }, - { x: 0.71875, y: 0.96875 }, - { x: 0.71875, y: 0.96875 }, - { x: 0.78125, y: 0.96875 }, - { x: 0.78125, y: 0.96875 }, - { x: 0.84375, y: 0.96875 }, - { x: 0.84375, y: 0.96875 }, - { x: 0.90625, y: 0.96875 }, - { x: 0.90625, y: 0.96875 }, - { x: 0.96875, y: 0.96875 }, - { x: 0.96875, y: 0.96875 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 } -]; - -// src/hand/handposedetector.ts -var HandDetector = class { - constructor(model23) { - __publicField(this, "model"); - __publicField(this, "anchors"); - __publicField(this, "anchorsTensor"); - __publicField(this, "inputSize"); - __publicField(this, "inputSizeTensor"); - __publicField(this, "doubleInputSizeTensor"); - var _a, _b, _c, _d; - this.model = model23; - this.anchors = anchors2.map((anchor) => [anchor.x, anchor.y]); - this.anchorsTensor = tf27.tensor2d(this.anchors); - this.inputSize = ((_d = (_c = (_b = (_a = this == null ? void 0 : this.model) == null ? void 0 : _a.inputs) == null ? void 0 : _b[0]) == null ? void 0 : _c.shape) == null ? void 0 : _d[2]) || 0; - this.inputSizeTensor = tf27.tensor1d([this.inputSize, this.inputSize]); - this.doubleInputSizeTensor = tf27.tensor1d([this.inputSize * 2, this.inputSize * 2]); - } - normalizeBoxes(boxes) { - const t2 = {}; - t2.boxOffsets = tf27.slice(boxes, [0, 0], [-1, 2]); - t2.boxSizes = tf27.slice(boxes, [0, 2], [-1, 2]); - t2.div = tf27.div(t2.boxOffsets, this.inputSizeTensor); - t2.boxCenterPoints = tf27.add(t2.div, this.anchorsTensor); - t2.halfBoxSizes = tf27.div(t2.boxSizes, this.doubleInputSizeTensor); - t2.sub = tf27.sub(t2.boxCenterPoints, t2.halfBoxSizes); - t2.startPoints = tf27.mul(t2.sub, this.inputSizeTensor); - t2.add = tf27.add(t2.boxCenterPoints, t2.halfBoxSizes); - t2.endPoints = tf27.mul(t2.add, this.inputSizeTensor); - const res = tf27.concat2d([t2.startPoints, t2.endPoints], 1); - Object.keys(t2).forEach((tensor6) => tf27.dispose(t2[tensor6])); - return res; - } - normalizeLandmarks(rawPalmLandmarks, index2) { - const t2 = {}; - t2.reshape = tf27.reshape(rawPalmLandmarks, [-1, 7, 2]); - t2.div = tf27.div(t2.reshape, this.inputSizeTensor); - t2.landmarks = tf27.add(t2.div, this.anchors[index2] ? this.anchors[index2] : 0); - const res = tf27.mul(t2.landmarks, this.inputSizeTensor); - Object.keys(t2).forEach((tensor6) => tf27.dispose(t2[tensor6])); - return res; - } - async predict(input, config3) { - var _a; - const t2 = {}; - t2.resize = tf27.image.resizeBilinear(input, [this.inputSize, this.inputSize]); - t2.div = tf27.div(t2.resize, constants.tf127); - t2.image = tf27.sub(t2.div, constants.tf1); - t2.batched = this.model.execute(t2.image); - t2.predictions = tf27.squeeze(t2.batched); - t2.slice = tf27.slice(t2.predictions, [0, 0], [-1, 1]); - t2.sigmoid = tf27.sigmoid(t2.slice); - t2.scores = tf27.squeeze(t2.sigmoid); - const scores = await t2.scores.data(); - t2.boxes = tf27.slice(t2.predictions, [0, 1], [-1, 4]); - t2.norm = this.normalizeBoxes(t2.boxes); - t2.nms = await tf27.image.nonMaxSuppressionAsync(t2.norm, t2.scores, 3 * (((_a = config3.hand) == null ? void 0 : _a.maxDetected) || 1), config3.hand.iouThreshold, config3.hand.minConfidence); - const nms = await t2.nms.array(); - const hands = []; - for (const index2 of nms) { - const p = {}; - p.box = tf27.slice(t2.norm, [index2, 0], [1, -1]); - p.slice = tf27.slice(t2.predictions, [index2, 5], [1, 14]); - p.norm = this.normalizeLandmarks(p.slice, index2); - p.palmLandmarks = tf27.reshape(p.norm, [-1, 2]); - const box = await p.box.data(); - const startPoint = box.slice(0, 2); - const endPoint = box.slice(2, 4); - const palmLandmarks = await p.palmLandmarks.array(); - const hand3 = { startPoint, endPoint, palmLandmarks, confidence: scores[index2] }; - const scaled = scaleBoxCoordinates2(hand3, [(input.shape[2] || 1) / this.inputSize, (input.shape[1] || 0) / this.inputSize]); - hands.push(scaled); - Object.keys(p).forEach((tensor6) => tf27.dispose(p[tensor6])); - } - Object.keys(t2).forEach((tensor6) => tf27.dispose(t2[tensor6])); - return hands; - } -}; - -// src/hand/handposepipeline.ts -var tf28 = __toESM(require_tfjs_esm()); -var palmBoxEnlargeFactor = 5; -var handBoxEnlargeFactor = 1.65; -var palmLandmarkIds = [0, 5, 9, 13, 17, 1, 2]; -var palmLandmarksPalmBase = 0; -var palmLandmarksMiddleFingerBase = 2; -var lastTime13 = 0; -var HandPipeline = class { - constructor(handDetector, handPoseModel2) { - __publicField(this, "handDetector"); - __publicField(this, "handPoseModel"); - __publicField(this, "inputSize"); - __publicField(this, "storedBoxes"); - __publicField(this, "skipped"); - __publicField(this, "detectedHands"); - var _a, _b, _c; - this.handDetector = handDetector; - this.handPoseModel = handPoseModel2; - this.inputSize = ((_c = (_b = (_a = this.handPoseModel) == null ? void 0 : _a.inputs) == null ? void 0 : _b[0].shape) == null ? void 0 : _c[2]) || 0; - this.storedBoxes = []; - this.skipped = Number.MAX_SAFE_INTEGER; - this.detectedHands = 0; - } - calculateLandmarksBoundingBox(landmarks) { - const xs = landmarks.map((d) => d[0]); - const ys = landmarks.map((d) => d[1]); - const startPoint = [Math.min(...xs), Math.min(...ys)]; - const endPoint = [Math.max(...xs), Math.max(...ys)]; - return { startPoint, endPoint }; - } - getBoxForPalmLandmarks(palmLandmarks, rotationMatrix) { - const rotatedPalmLandmarks = palmLandmarks.map((coord) => rotatePoint2([...coord, 1], rotationMatrix)); - const boxAroundPalm = this.calculateLandmarksBoundingBox(rotatedPalmLandmarks); - return enlargeBox2(squarifyBox2(boxAroundPalm), palmBoxEnlargeFactor); - } - getBoxForHandLandmarks(landmarks) { - const boundingBox = this.calculateLandmarksBoundingBox(landmarks); - const boxAroundHand = enlargeBox2(squarifyBox2(boundingBox), handBoxEnlargeFactor); - boxAroundHand.palmLandmarks = []; - for (let i = 0; i < palmLandmarkIds.length; i++) { - boxAroundHand.palmLandmarks.push(landmarks[palmLandmarkIds[i]].slice(0, 2)); - } - return boxAroundHand; - } - transformRawCoords(rawCoords, box2, angle, rotationMatrix) { - const boxSize = getBoxSize2(box2); - const scaleFactor = [boxSize[0] / this.inputSize, boxSize[1] / this.inputSize, (boxSize[0] + boxSize[1]) / this.inputSize / 2]; - const coordsScaled = rawCoords.map((coord) => [ - scaleFactor[0] * (coord[0] - this.inputSize / 2), - scaleFactor[1] * (coord[1] - this.inputSize / 2), - scaleFactor[2] * coord[2] - ]); - const coordsRotationMatrix = buildRotationMatrix2(angle, [0, 0]); - const coordsRotated = coordsScaled.map((coord) => { - const rotated = rotatePoint2(coord, coordsRotationMatrix); - return [...rotated, coord[2]]; - }); - const inverseRotationMatrix = invertTransformMatrix2(rotationMatrix); - const boxCenter = [...getBoxCenter2(box2), 1]; - const originalBoxCenter = [ - dot2(boxCenter, inverseRotationMatrix[0]), - dot2(boxCenter, inverseRotationMatrix[1]) - ]; - return coordsRotated.map((coord) => [ - Math.trunc(coord[0] + originalBoxCenter[0]), - Math.trunc(coord[1] + originalBoxCenter[1]), - Math.trunc(coord[2]) - ]); - } - async estimateHands(image28, config3) { - let useFreshBox = false; - let boxes; - const skipTime = (config3.hand.skipTime || 0) > now() - lastTime13; - const skipFrame = this.skipped < (config3.hand.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame) { - boxes = await this.handDetector.predict(image28, config3); - this.skipped = 0; - } - if (config3.skipAllowed) - this.skipped++; - if (boxes && boxes.length > 0 && (boxes.length !== this.detectedHands && this.detectedHands !== config3.hand.maxDetected || !config3.hand.landmarks)) { - this.detectedHands = 0; - this.storedBoxes = [...boxes]; - if (this.storedBoxes.length > 0) - useFreshBox = true; - } - const hands = []; - for (let i = 0; i < this.storedBoxes.length; i++) { - const currentBox = this.storedBoxes[i]; - if (!currentBox) - continue; - if (config3.hand.landmarks) { - const angle = config3.hand.rotation ? computeRotation2(currentBox.palmLandmarks[palmLandmarksPalmBase], currentBox.palmLandmarks[palmLandmarksMiddleFingerBase]) : 0; - const palmCenter = getBoxCenter2(currentBox); - const palmCenterNormalized = [palmCenter[0] / image28.shape[2], palmCenter[1] / image28.shape[1]]; - const rotatedImage = config3.hand.rotation && env.kernels.includes("rotatewithoffset") ? tf28.image.rotateWithOffset(image28, angle, 0, palmCenterNormalized) : image28.clone(); - const rotationMatrix = buildRotationMatrix2(-angle, palmCenter); - const newBox = useFreshBox ? this.getBoxForPalmLandmarks(currentBox.palmLandmarks, rotationMatrix) : currentBox; - const croppedInput = cutBoxFromImageAndResize(newBox, rotatedImage, [this.inputSize, this.inputSize]); - const handImage = tf28.div(croppedInput, constants.tf255); - tf28.dispose(croppedInput); - tf28.dispose(rotatedImage); - const [confidenceT, keypoints] = this.handPoseModel.execute(handImage); - lastTime13 = now(); - tf28.dispose(handImage); - const confidence = (await confidenceT.data())[0]; - tf28.dispose(confidenceT); - if (confidence >= config3.hand.minConfidence / 4) { - const keypointsReshaped = tf28.reshape(keypoints, [-1, 3]); - const rawCoords = await keypointsReshaped.array(); - tf28.dispose(keypoints); - tf28.dispose(keypointsReshaped); - const coords = this.transformRawCoords(rawCoords, newBox, angle, rotationMatrix); - const nextBoundingBox = this.getBoxForHandLandmarks(coords); - this.storedBoxes[i] = { ...nextBoundingBox, confidence }; - const result = { - landmarks: coords, - confidence, - boxConfidence: currentBox.confidence, - fingerConfidence: confidence, - box: { topLeft: nextBoundingBox.startPoint, bottomRight: nextBoundingBox.endPoint } - }; - hands.push(result); - } else { - this.storedBoxes[i] = null; - } - tf28.dispose(keypoints); - } else { - const enlarged = enlargeBox2(squarifyBox2(currentBox), handBoxEnlargeFactor); - const result = { - confidence: currentBox.confidence, - boxConfidence: currentBox.confidence, - fingerConfidence: 0, - box: { topLeft: enlarged.startPoint, bottomRight: enlarged.endPoint }, - landmarks: [] - }; - hands.push(result); - } - } - this.storedBoxes = this.storedBoxes.filter((a) => a !== null); - this.detectedHands = hands.length; - if (hands.length > config3.hand.maxDetected) - hands.length = config3.hand.maxDetected; - return hands; - } -}; - -// src/hand/handpose.ts -var meshAnnotations2 = { - thumb: [1, 2, 3, 4], - index: [5, 6, 7, 8], - middle: [9, 10, 11, 12], - ring: [13, 14, 15, 16], - pinky: [17, 18, 19, 20], - palm: [0] -}; -var handDetectorModel; -var handPoseModel; -var handPipeline; -async function predict14(input, config3) { - const predictions = await handPipeline.estimateHands(input, config3); - if (!predictions) - return []; - const hands = []; - for (let i = 0; i < predictions.length; i++) { - const annotations2 = {}; - if (predictions[i].landmarks) { - for (const key of Object.keys(meshAnnotations2)) { - annotations2[key] = meshAnnotations2[key].map((index2) => predictions[i].landmarks[index2]); - } - } - const keypoints = predictions[i].landmarks; - let box = [Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, 0, 0]; - let boxRaw = [0, 0, 0, 0]; - if (keypoints && keypoints.length > 0) { - for (const pt of keypoints) { - if (pt[0] < box[0]) - box[0] = pt[0]; - if (pt[1] < box[1]) - box[1] = pt[1]; - if (pt[0] > box[2]) - box[2] = pt[0]; - if (pt[1] > box[3]) - box[3] = pt[1]; - } - box[2] -= box[0]; - box[3] -= box[1]; - boxRaw = [box[0] / (input.shape[2] || 0), box[1] / (input.shape[1] || 0), box[2] / (input.shape[2] || 0), box[3] / (input.shape[1] || 0)]; - } else { - box = predictions[i].box ? [ - Math.trunc(Math.max(0, predictions[i].box.topLeft[0])), - Math.trunc(Math.max(0, predictions[i].box.topLeft[1])), - Math.trunc(Math.min(input.shape[2] || 0, predictions[i].box.bottomRight[0]) - Math.max(0, predictions[i].box.topLeft[0])), - Math.trunc(Math.min(input.shape[1] || 0, predictions[i].box.bottomRight[1]) - Math.max(0, predictions[i].box.topLeft[1])) - ] : [0, 0, 0, 0]; - boxRaw = [ - predictions[i].box.topLeft[0] / (input.shape[2] || 0), - predictions[i].box.topLeft[1] / (input.shape[1] || 0), - (predictions[i].box.bottomRight[0] - predictions[i].box.topLeft[0]) / (input.shape[2] || 0), - (predictions[i].box.bottomRight[1] - predictions[i].box.topLeft[1]) / (input.shape[1] || 0) - ]; - } - const landmarks = analyze(keypoints); - hands.push({ - id: i, - score: Math.round(100 * predictions[i].confidence) / 100, - boxScore: Math.round(100 * predictions[i].boxConfidence) / 100, - fingerScore: Math.round(100 * predictions[i].fingerConfidence) / 100, - label: "hand", - box, - boxRaw, - keypoints, - annotations: annotations2, - landmarks - }); - } - return hands; -} -async function load15(config3) { - var _a, _b; - if (env.initial) { - handDetectorModel = null; - handPoseModel = null; - } - if (!handDetectorModel || !handPoseModel) { - [handDetectorModel, handPoseModel] = await Promise.all([ - config3.hand.enabled ? loadModel((_a = config3.hand.detector) == null ? void 0 : _a.modelPath) : null, - config3.hand.landmarks ? loadModel((_b = config3.hand.skeleton) == null ? void 0 : _b.modelPath) : null - ]); - } else { - if (config3.debug) - log("cached model:", handDetectorModel["modelUrl"]); - if (config3.debug) - log("cached model:", handPoseModel["modelUrl"]); - } - const handDetector = handDetectorModel ? new HandDetector(handDetectorModel) : void 0; - if (handDetector && handPoseModel) - handPipeline = new HandPipeline(handDetector, handPoseModel); - return [handDetectorModel, handPoseModel]; -} - -// src/hand/handtrack.ts -var tf29 = __toESM(require_tfjs_esm()); -var models2 = [null, null]; -var modelOutputNodes = ["StatefulPartitionedCall/Postprocessor/Slice", "StatefulPartitionedCall/Postprocessor/ExpandDims_1"]; -var inputSize7 = [[0, 0], [0, 0]]; -var classes = ["hand", "fist", "pinch", "point", "face", "tip", "pinchtip"]; -var faceIndex = 4; -var boxExpandFact = 1.6; -var maxDetectorResolution = 512; -var detectorExpandFact = 1.4; -var skipped13 = Number.MAX_SAFE_INTEGER; -var lastTime14 = 0; -var outputSize = [0, 0]; -var cache4 = { - boxes: [], - hands: [] -}; -var fingerMap = { - thumb: [1, 2, 3, 4], - index: [5, 6, 7, 8], - middle: [9, 10, 11, 12], - ring: [13, 14, 15, 16], - pinky: [17, 18, 19, 20], - base: [0], - palm: [0, 17, 13, 9, 5, 1, 0] -}; -async function loadDetect2(config3) { - var _a; - if (env.initial) - models2[0] = null; - if (!models2[0]) { - fakeOps(["tensorlistreserve", "enter", "tensorlistfromtensor", "merge", "loopcond", "switch", "exit", "tensorliststack", "nextiteration", "tensorlistsetitem", "tensorlistgetitem", "reciprocal", "shape", "split", "where"], config3); - models2[0] = await loadModel((_a = config3.hand.detector) == null ? void 0 : _a.modelPath); - const inputs = models2[0]["executor"] ? Object.values(models2[0].modelSignature["inputs"]) : void 0; - inputSize7[0][0] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - inputSize7[0][1] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 0; - } else if (config3.debug) - log("cached model:", models2[0]["modelUrl"]); - return models2[0]; -} -async function loadSkeleton(config3) { - var _a; - if (env.initial) - models2[1] = null; - if (!models2[1]) { - models2[1] = await loadModel((_a = config3.hand.skeleton) == null ? void 0 : _a.modelPath); - const inputs = models2[1]["executor"] ? Object.values(models2[1].modelSignature["inputs"]) : void 0; - inputSize7[1][0] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - inputSize7[1][1] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 0; - } else if (config3.debug) - log("cached model:", models2[1]["modelUrl"]); - return models2[1]; -} -async function detectHands(input, config3) { - const hands = []; - if (!input || !models2[0]) - return hands; - const t2 = {}; - const ratio2 = (input.shape[2] || 1) / (input.shape[1] || 1); - const height = Math.min(Math.round((input.shape[1] || 0) / 8) * 8, maxDetectorResolution); - const width = Math.round(height * ratio2 / 8) * 8; - t2.resize = tf29.image.resizeBilinear(input, [height, width]); - t2.cast = tf29.cast(t2.resize, "int32"); - [t2.rawScores, t2.rawBoxes] = await models2[0].executeAsync(t2.cast, modelOutputNodes); - t2.boxes = tf29.squeeze(t2.rawBoxes, [0, 2]); - t2.scores = tf29.squeeze(t2.rawScores, [0]); - const classScores = tf29.unstack(t2.scores, 1); - tf29.dispose(classScores[faceIndex]); - classScores.splice(faceIndex, 1); - t2.filtered = tf29.stack(classScores, 1); - tf29.dispose(classScores); - t2.max = tf29.max(t2.filtered, 1); - t2.argmax = tf29.argMax(t2.filtered, 1); - let id = 0; - t2.nms = await tf29.image.nonMaxSuppressionAsync(t2.boxes, t2.max, (config3.hand.maxDetected || 0) + 1, config3.hand.iouThreshold || 0, config3.hand.minConfidence || 1); - const nms = await t2.nms.data(); - const scores = await t2.max.data(); - const classNum = await t2.argmax.data(); - for (const nmsIndex of Array.from(nms)) { - const boxSlice = tf29.slice(t2.boxes, nmsIndex, 1); - const boxYX = await boxSlice.data(); - tf29.dispose(boxSlice); - const boxData = [boxYX[1], boxYX[0], boxYX[3] - boxYX[1], boxYX[2] - boxYX[0]]; - const boxRaw = scale(boxData, detectorExpandFact); - const boxFull = [Math.trunc(boxData[0] * outputSize[0]), Math.trunc(boxData[1] * outputSize[1]), Math.trunc(boxData[2] * outputSize[0]), Math.trunc(boxData[3] * outputSize[1])]; - const score = scores[nmsIndex]; - const label = classes[classNum[nmsIndex]]; - const hand3 = { id: id++, score, box: boxFull, boxRaw, label }; - hands.push(hand3); - } - Object.keys(t2).forEach((tensor6) => tf29.dispose(t2[tensor6])); - hands.sort((a, b) => b.score - a.score); - if (hands.length > (config3.hand.maxDetected || 1)) - hands.length = config3.hand.maxDetected || 1; - return hands; -} -async function detectFingers(input, h, config3) { - const hand3 = { - id: h.id, - score: Math.round(100 * h.score) / 100, - boxScore: Math.round(100 * h.score) / 100, - fingerScore: 0, - box: h.box, - boxRaw: h.boxRaw, - label: h.label, - keypoints: [], - landmarks: {}, - annotations: {} - }; - if (input && models2[1] && config3.hand.landmarks && h.score > (config3.hand.minConfidence || 0)) { - const t2 = {}; - const boxCrop = [h.boxRaw[1], h.boxRaw[0], h.boxRaw[3] + h.boxRaw[1], h.boxRaw[2] + h.boxRaw[0]]; - t2.crop = tf29.image.cropAndResize(input, [boxCrop], [0], [inputSize7[1][0], inputSize7[1][1]], "bilinear"); - t2.div = tf29.div(t2.crop, constants.tf255); - [t2.score, t2.keypoints] = models2[1].execute(t2.div, ["Identity_1", "Identity"]); - const rawScore = (await t2.score.data())[0]; - const score = (100 - Math.trunc(100 / (1 + Math.exp(rawScore)))) / 100; - if (score >= (config3.hand.minConfidence || 0)) { - hand3.fingerScore = score; - t2.reshaped = tf29.reshape(t2.keypoints, [-1, 3]); - const coordsData = await t2.reshaped.array(); - const coordsRaw = coordsData.map((kpt4) => [kpt4[0] / inputSize7[1][1], kpt4[1] / inputSize7[1][0], kpt4[2] || 0]); - const coordsNorm = coordsRaw.map((kpt4) => [kpt4[0] * h.boxRaw[2], kpt4[1] * h.boxRaw[3], kpt4[2] || 0]); - hand3.keypoints = coordsNorm.map((kpt4) => [outputSize[0] * (kpt4[0] + h.boxRaw[0]), outputSize[1] * (kpt4[1] + h.boxRaw[1]), kpt4[2] || 0]); - hand3.landmarks = analyze(hand3.keypoints); - for (const key of Object.keys(fingerMap)) { - hand3.annotations[key] = fingerMap[key].map((index2) => hand3.landmarks && hand3.keypoints[index2] ? hand3.keypoints[index2] : null); - } - } - Object.keys(t2).forEach((tensor6) => tf29.dispose(t2[tensor6])); - } - return hand3; -} -async function predict15(input, config3) { - var _a, _b; - if (!((_a = models2[0]) == null ? void 0 : _a["executor"]) || !((_b = models2[1]) == null ? void 0 : _b["executor"]) || !models2[0].inputs[0].shape || !models2[1].inputs[0].shape) - return []; - outputSize = [input.shape[2] || 0, input.shape[1] || 0]; - skipped13++; - const skipTime = (config3.hand.skipTime || 0) > now() - lastTime14; - const skipFrame = skipped13 < (config3.hand.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame) { - return cache4.hands; - } - return new Promise(async (resolve) => { - const skipTimeExtended = 3 * (config3.hand.skipTime || 0) > now() - lastTime14; - const skipFrameExtended = skipped13 < 3 * (config3.hand.skipFrames || 0); - if (config3.skipAllowed && cache4.hands.length === config3.hand.maxDetected) { - cache4.hands = await Promise.all(cache4.boxes.map((handBox) => detectFingers(input, handBox, config3))); - } else if (config3.skipAllowed && skipTimeExtended && skipFrameExtended && cache4.hands.length > 0) { - cache4.hands = await Promise.all(cache4.boxes.map((handBox) => detectFingers(input, handBox, config3))); - } else { - cache4.boxes = await detectHands(input, config3); - lastTime14 = now(); - cache4.hands = await Promise.all(cache4.boxes.map((handBox) => detectFingers(input, handBox, config3))); - skipped13 = 0; - } - const oldCache = [...cache4.boxes]; - cache4.boxes.length = 0; - if (config3.cacheSensitivity > 0) { - for (let i = 0; i < cache4.hands.length; i++) { - const boxKpt = square(cache4.hands[i].keypoints, outputSize); - if (boxKpt.box[2] / (input.shape[2] || 1) > 0.05 && boxKpt.box[3] / (input.shape[1] || 1) > 0.05 && cache4.hands[i].fingerScore && cache4.hands[i].fingerScore > (config3.hand.minConfidence || 0)) { - const boxScale = scale(boxKpt.box, boxExpandFact); - const boxScaleRaw = scale(boxKpt.boxRaw, boxExpandFact); - cache4.boxes.push({ ...oldCache[i], box: boxScale, boxRaw: boxScaleRaw }); - } - } - } - for (let i = 0; i < cache4.hands.length; i++) { - const bbox = calc(cache4.hands[i].keypoints, outputSize); - cache4.hands[i].box = bbox.box; - cache4.hands[i].boxRaw = bbox.boxRaw; - } - resolve(cache4.hands); - }); -} - -// src/result.ts -var empty = (error = null) => ({ face: [], body: [], hand: [], gesture: [], object: [], persons: [], performance: {}, timestamp: 0, width: 0, height: 0, error }); - -// src/body/movenetcoords.ts -var movenetcoords_exports = {}; -__export(movenetcoords_exports, { - connected: () => connected3, - horizontal: () => horizontal, - kpt: () => kpt3, - relative: () => relative, - vertical: () => vertical -}); -var kpt3 = [ - "nose", - "leftEye", - "rightEye", - "leftEar", - "rightEar", - "leftShoulder", - "rightShoulder", - "leftElbow", - "rightElbow", - "leftWrist", - "rightWrist", - "leftHip", - "rightHip", - "leftKnee", - "rightKnee", - "leftAnkle", - "rightAnkle" -]; -var horizontal = [ - ["leftEye", "rightEye"], - ["leftEar", "rightEar"], - ["leftShoulder", "rightShoulder"], - ["leftElbow", "rightElbow"], - ["leftWrist", "rightWrist"], - ["leftHip", "rightHip"], - ["leftKnee", "rightKnee"], - ["leftAnkle", "rightAnkle"] -]; -var vertical = [ - ["leftKnee", "leftShoulder"], - ["rightKnee", "rightShoulder"], - ["leftAnkle", "leftKnee"], - ["rightAnkle", "rightKnee"] -]; -var relative = [ - [["leftHip", "rightHip"], ["leftShoulder", "rightShoulder"]], - [["leftElbow", "rightElbow"], ["leftShoulder", "rightShoulder"]] -]; -var connected3 = { - leftLeg: ["leftHip", "leftKnee", "leftAnkle"], - rightLeg: ["rightHip", "rightKnee", "rightAnkle"], - torso: ["leftShoulder", "rightShoulder", "rightHip", "leftHip", "leftShoulder"], - leftArm: ["leftShoulder", "leftElbow", "leftWrist"], - rightArm: ["rightShoulder", "rightElbow", "rightWrist"], - head: [] -}; - -// src/util/interpolate.ts -var bufferedResult = empty(); -var interpolateTime = 0; -function calc2(newResult, config3) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w; - const t0 = now(); - if (!newResult) - return empty(); - const elapsed = Date.now() - newResult.timestamp; - const bufferedFactor = elapsed < 1e3 ? 8 - Math.log(elapsed + 1) : 1; - if (newResult.canvas) - bufferedResult.canvas = newResult.canvas; - if (newResult.error) - bufferedResult.error = newResult.error; - if (!bufferedResult.body || newResult.body.length !== bufferedResult.body.length) { - bufferedResult.body = JSON.parse(JSON.stringify(newResult.body)); - } else { - for (let i = 0; i < newResult.body.length; i++) { - const box = newResult.body[i].box.map((newBoxCoord, j) => ((bufferedFactor - 1) * bufferedResult.body[i].box[j] + newBoxCoord) / bufferedFactor); - const boxRaw = newResult.body[i].boxRaw.map((newBoxCoord, j) => ((bufferedFactor - 1) * bufferedResult.body[i].boxRaw[j] + newBoxCoord) / bufferedFactor); - const keypoints = newResult.body[i].keypoints.map((newKpt, j) => { - var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2; - return { - score: newKpt.score, - part: newKpt.part, - position: [ - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].position[0] || 0) + (newKpt.position[0] || 0)) / bufferedFactor : newKpt.position[0], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].position[1] || 0) + (newKpt.position[1] || 0)) / bufferedFactor : newKpt.position[1], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].position[2] || 0) + (newKpt.position[2] || 0)) / bufferedFactor : newKpt.position[2] - ], - positionRaw: [ - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].positionRaw[0] || 0) + (newKpt.positionRaw[0] || 0)) / bufferedFactor : newKpt.positionRaw[0], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].positionRaw[1] || 0) + (newKpt.positionRaw[1] || 0)) / bufferedFactor : newKpt.positionRaw[1], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].positionRaw[2] || 0) + (newKpt.positionRaw[2] || 0)) / bufferedFactor : newKpt.positionRaw[2] - ], - distance: [ - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (((_a2 = bufferedResult.body[i].keypoints[j].distance) == null ? void 0 : _a2[0]) || 0) + (((_b2 = newKpt.distance) == null ? void 0 : _b2[0]) || 0)) / bufferedFactor : (_c2 = newKpt.distance) == null ? void 0 : _c2[0], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (((_d2 = bufferedResult.body[i].keypoints[j].distance) == null ? void 0 : _d2[1]) || 0) + (((_e2 = newKpt.distance) == null ? void 0 : _e2[1]) || 0)) / bufferedFactor : (_f2 = newKpt.distance) == null ? void 0 : _f2[1], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (((_g2 = bufferedResult.body[i].keypoints[j].distance) == null ? void 0 : _g2[2]) || 0) + (((_h2 = newKpt.distance) == null ? void 0 : _h2[2]) || 0)) / bufferedFactor : (_i2 = newKpt.distance) == null ? void 0 : _i2[2] - ] - }; - }); - const annotations2 = {}; - let coords = { connected: {} }; - if ((_a = config3.body.modelPath) == null ? void 0 : _a.includes("efficientpose")) - coords = efficientposecoords_exports; - else if ((_b = config3.body.modelPath) == null ? void 0 : _b.includes("blazepose")) - coords = blazeposecoords_exports; - else if ((_c = config3.body.modelPath) == null ? void 0 : _c.includes("movenet")) - coords = movenetcoords_exports; - for (const [name, indexes] of Object.entries(coords.connected)) { - const pt = []; - for (let j = 0; j < indexes.length - 1; j++) { - const pt0 = keypoints.find((kp) => kp.part === indexes[j]); - const pt1 = keypoints.find((kp) => kp.part === indexes[j + 1]); - if (pt0 && pt1) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - bufferedResult.body[i] = { ...newResult.body[i], box, boxRaw, keypoints, annotations: annotations2 }; - } - } - if (!bufferedResult.hand || newResult.hand.length !== bufferedResult.hand.length) { - bufferedResult.hand = JSON.parse(JSON.stringify(newResult.hand)); - } else { - for (let i = 0; i < newResult.hand.length; i++) { - const box = newResult.hand[i].box.map((b, j) => ((bufferedFactor - 1) * bufferedResult.hand[i].box[j] + b) / bufferedFactor); - const boxRaw = newResult.hand[i].boxRaw.map((b, j) => ((bufferedFactor - 1) * bufferedResult.hand[i].boxRaw[j] + b) / bufferedFactor); - if (bufferedResult.hand[i].keypoints.length !== newResult.hand[i].keypoints.length) - bufferedResult.hand[i].keypoints = newResult.hand[i].keypoints; - const keypoints = newResult.hand[i].keypoints && newResult.hand[i].keypoints.length > 0 ? newResult.hand[i].keypoints.map((landmark, j) => landmark.map((coord, k) => ((bufferedFactor - 1) * (bufferedResult.hand[i].keypoints[j][k] || 1) + (coord || 0)) / bufferedFactor)) : []; - let annotations2 = {}; - if (Object.keys(bufferedResult.hand[i].annotations).length !== Object.keys(newResult.hand[i].annotations).length) { - bufferedResult.hand[i].annotations = newResult.hand[i].annotations; - annotations2 = bufferedResult.hand[i].annotations; - } else if (newResult.hand[i].annotations) { - for (const key of Object.keys(newResult.hand[i].annotations)) { - annotations2[key] = ((_f = (_e = (_d = newResult.hand[i]) == null ? void 0 : _d.annotations) == null ? void 0 : _e[key]) == null ? void 0 : _f[0]) ? newResult.hand[i].annotations[key].map((val, j) => val.map((coord, k) => ((bufferedFactor - 1) * bufferedResult.hand[i].annotations[key][j][k] + coord) / bufferedFactor)) : null; - } - } - bufferedResult.hand[i] = { ...newResult.hand[i], box, boxRaw, keypoints, annotations: annotations2 }; - } - } - if (!bufferedResult.face || newResult.face.length !== bufferedResult.face.length) { - bufferedResult.face = JSON.parse(JSON.stringify(newResult.face)); - } else { - for (let i = 0; i < newResult.face.length; i++) { - const box = newResult.face[i].box.map((b, j) => ((bufferedFactor - 1) * bufferedResult.face[i].box[j] + b) / bufferedFactor); - const boxRaw = newResult.face[i].boxRaw.map((b, j) => ((bufferedFactor - 1) * bufferedResult.face[i].boxRaw[j] + b) / bufferedFactor); - if (newResult.face[i].rotation) { - const rotation = { matrix: [0, 0, 0, 0, 0, 0, 0, 0, 0], angle: { roll: 0, yaw: 0, pitch: 0 }, gaze: { bearing: 0, strength: 0 } }; - rotation.matrix = (_g = newResult.face[i].rotation) == null ? void 0 : _g.matrix; - rotation.angle = { - roll: ((bufferedFactor - 1) * (((_i = (_h = bufferedResult.face[i].rotation) == null ? void 0 : _h.angle) == null ? void 0 : _i.roll) || 0) + (((_k = (_j = newResult.face[i].rotation) == null ? void 0 : _j.angle) == null ? void 0 : _k.roll) || 0)) / bufferedFactor, - yaw: ((bufferedFactor - 1) * (((_m = (_l = bufferedResult.face[i].rotation) == null ? void 0 : _l.angle) == null ? void 0 : _m.yaw) || 0) + (((_o = (_n = newResult.face[i].rotation) == null ? void 0 : _n.angle) == null ? void 0 : _o.yaw) || 0)) / bufferedFactor, - pitch: ((bufferedFactor - 1) * (((_q = (_p = bufferedResult.face[i].rotation) == null ? void 0 : _p.angle) == null ? void 0 : _q.pitch) || 0) + (((_s = (_r = newResult.face[i].rotation) == null ? void 0 : _r.angle) == null ? void 0 : _s.pitch) || 0)) / bufferedFactor - }; - rotation.gaze = { - bearing: ((bufferedFactor - 1) * (((_t = bufferedResult.face[i].rotation) == null ? void 0 : _t.gaze.bearing) || 0) + (((_u = newResult.face[i].rotation) == null ? void 0 : _u.gaze.bearing) || 0)) / bufferedFactor, - strength: ((bufferedFactor - 1) * (((_v = bufferedResult.face[i].rotation) == null ? void 0 : _v.gaze.strength) || 0) + (((_w = newResult.face[i].rotation) == null ? void 0 : _w.gaze.strength) || 0)) / bufferedFactor - }; - bufferedResult.face[i] = { ...newResult.face[i], rotation, box, boxRaw }; - } else { - bufferedResult.face[i] = { ...newResult.face[i], box, boxRaw }; - } - } - } - if (!bufferedResult.object || newResult.object.length !== bufferedResult.object.length) { - bufferedResult.object = JSON.parse(JSON.stringify(newResult.object)); - } else { - for (let i = 0; i < newResult.object.length; i++) { - const box = newResult.object[i].box.map((b, j) => ((bufferedFactor - 1) * bufferedResult.object[i].box[j] + b) / bufferedFactor); - const boxRaw = newResult.object[i].boxRaw.map((b, j) => ((bufferedFactor - 1) * bufferedResult.object[i].boxRaw[j] + b) / bufferedFactor); - bufferedResult.object[i] = { ...newResult.object[i], box, boxRaw }; - } - } - if (newResult.persons) { - const newPersons = newResult.persons; - if (!bufferedResult.persons || newPersons.length !== bufferedResult.persons.length) { - bufferedResult.persons = JSON.parse(JSON.stringify(newPersons)); - } else { - for (let i = 0; i < newPersons.length; i++) { - bufferedResult.persons[i].box = newPersons[i].box.map((box, j) => ((bufferedFactor - 1) * bufferedResult.persons[i].box[j] + box) / bufferedFactor); - } - } - } - if (newResult.gesture) - bufferedResult.gesture = newResult.gesture; - bufferedResult.width = newResult.width; - bufferedResult.height = newResult.height; - const t1 = now(); - interpolateTime = env.perfadd ? interpolateTime + Math.round(t1 - t0) : Math.round(t1 - t0); - if (newResult.performance) - bufferedResult.performance = { ...newResult.performance, interpolate: interpolateTime }; - return bufferedResult; -} - -// src/segmentation/meet.ts -var tf30 = __toESM(require_tfjs_esm()); -var model17; -async function load16(config3) { - if (!model17 || env.initial) - model17 = await loadModel(config3.segmentation.modelPath); - else if (config3.debug) - log("cached model:", model17["modelUrl"]); - return model17; -} -async function predict16(input, config3) { - var _a; - if (!model17) - model17 = await load16(config3); - if (!(model17 == null ? void 0 : model17["executor"]) || !((_a = model17 == null ? void 0 : model17.inputs) == null ? void 0 : _a[0].shape)) - return null; - const t2 = {}; - t2.resize = tf30.image.resizeBilinear(input, [model17.inputs[0].shape ? model17.inputs[0].shape[1] : 0, model17.inputs[0].shape ? model17.inputs[0].shape[2] : 0], false); - t2.norm = tf30.div(t2.resize, constants.tf255); - t2.res = model17.execute(t2.norm); - t2.squeeze = tf30.squeeze(t2.res, [0]); - [t2.bgRaw, t2.fgRaw] = tf30.unstack(t2.squeeze, 2); - t2.fg = tf30.softmax(t2.fgRaw); - t2.mul = tf30.mul(t2.fg, constants.tf255); - t2.expand = tf30.expandDims(t2.mul, 2); - t2.output = tf30.image.resizeBilinear(t2.expand, [input.shape[1] || 0, input.shape[2] || 0]); - let rgba; - switch (config3.segmentation.mode || "default") { - case "default": - t2.input = tf30.squeeze(input); - t2.concat = tf30.concat([t2.input, t2.output], -1); - rgba = tf30.cast(t2.concat, "int32"); - break; - case "alpha": - rgba = tf30.cast(t2.output, "int32"); - break; - default: - rgba = tf30.tensor(0); - } - Object.keys(t2).forEach((tensor6) => tf30.dispose(t2[tensor6])); - return rgba; -} - -// src/face/match.ts -var match_exports = {}; -__export(match_exports, { - distance: () => distance, - find: () => find, - similarity: () => similarity -}); -function distance(descriptor1, descriptor2, options4 = { order: 2, multiplier: 25 }) { - if (!descriptor1 || !descriptor1) - return Number.MAX_SAFE_INTEGER; - let sum3 = 0; - for (let i = 0; i < descriptor1.length; i++) { - const diff = !options4.order || options4.order === 2 ? descriptor1[i] - descriptor2[i] : Math.abs(descriptor1[i] - descriptor2[i]); - sum3 += !options4.order || options4.order === 2 ? diff * diff : diff ** options4.order; - } - return (options4.multiplier || 20) * sum3; -} -var normalizeDistance = (dist, order, min2, max5) => { - if (dist === 0) - return 1; - const root = order === 2 ? Math.sqrt(dist) : dist ** (1 / order); - const norm = (1 - root / 100 - min2) / (max5 - min2); - const clamp2 = Math.max(Math.min(norm, 1), 0); - return clamp2; -}; -function similarity(descriptor1, descriptor2, options4 = { order: 2, multiplier: 25, min: 0.2, max: 0.8 }) { - const dist = distance(descriptor1, descriptor2, options4); - return normalizeDistance(dist, options4.order || 2, options4.min || 0, options4.max || 1); -} -function find(descriptor, descriptors, options4 = { order: 2, multiplier: 25, threshold: 0, min: 0.2, max: 0.8 }) { - if (!Array.isArray(descriptor) || !Array.isArray(descriptors) || descriptor.length < 64 || descriptors.length === 0) { - return { index: -1, distance: Number.POSITIVE_INFINITY, similarity: 0 }; - } - let lowestDistance = Number.MAX_SAFE_INTEGER; - let index2 = -1; - for (let i = 0; i < descriptors.length; i++) { - const res = descriptors[i].length === descriptor.length ? distance(descriptor, descriptors[i], options4) : Number.MAX_SAFE_INTEGER; - if (res < lowestDistance) { - lowestDistance = res; - index2 = i; - } - if (lowestDistance < (options4.threshold || 0)) - break; - } - const normalizedSimilarity = normalizeDistance(lowestDistance, options4.order || 2, options4.min || 0, options4.max || 1); - return { index: index2, distance: lowestDistance, similarity: normalizedSimilarity }; -} - -// src/models.ts -var models_exports2 = {}; -__export(models_exports2, { - Models: () => Models, - validateModel: () => validateModel -}); - -// src/body/movenet.ts -var tf32 = __toESM(require_tfjs_esm()); - -// src/body/movenetfix.ts -var tf31 = __toESM(require_tfjs_esm()); -var maxJitter = 5e-3; -var cache5 = { - keypoints: [], - padding: [[0, 0], [0, 0], [0, 0], [0, 0]] -}; -function bodyParts(body4) { - for (const pair of horizontal) { - const left = body4.keypoints.findIndex((kp) => kp.part === pair[0]); - const right = body4.keypoints.findIndex((kp) => kp.part === pair[1]); - if (body4.keypoints[left] && body4.keypoints[right]) { - if (body4.keypoints[left].position[0] < body4.keypoints[right].position[0]) { - const tmp = body4.keypoints[left]; - body4.keypoints[left] = body4.keypoints[right]; - body4.keypoints[right] = tmp; - } - } - } - for (const pair of vertical) { - const lower = body4.keypoints.findIndex((kp) => kp && kp.part === pair[0]); - const higher = body4.keypoints.findIndex((kp) => kp && kp.part === pair[1]); - if (body4.keypoints[lower] && body4.keypoints[higher]) { - if (body4.keypoints[lower].position[1] < body4.keypoints[higher].position[1]) { - body4.keypoints.splice(lower, 1); - } - } - } - for (const [pair, compare2] of relative) { - const left = body4.keypoints.findIndex((kp) => kp && kp.part === pair[0]); - const right = body4.keypoints.findIndex((kp) => kp && kp.part === pair[1]); - const leftTo = body4.keypoints.findIndex((kp) => kp && kp.part === compare2[0]); - const rightTo = body4.keypoints.findIndex((kp) => kp && kp.part === compare2[1]); - if (!body4.keypoints[leftTo] || !body4.keypoints[rightTo]) - continue; - const distanceLeft = body4.keypoints[left] ? [ - Math.abs(body4.keypoints[leftTo].position[0] - body4.keypoints[left].position[0]), - Math.abs(body4.keypoints[rightTo].position[0] - body4.keypoints[left].position[0]) - ] : [0, 0]; - const distanceRight = body4.keypoints[right] ? [ - Math.abs(body4.keypoints[rightTo].position[0] - body4.keypoints[right].position[0]), - Math.abs(body4.keypoints[leftTo].position[0] - body4.keypoints[right].position[0]) - ] : [0, 0]; - if (distanceLeft[0] > distanceLeft[1] || distanceRight[0] > distanceRight[1]) { - const tmp = body4.keypoints[left]; - body4.keypoints[left] = body4.keypoints[right]; - body4.keypoints[right] = tmp; - } - } -} -function jitter(keypoints) { - for (let i = 0; i < keypoints.length; i++) { - if (keypoints[i] && cache5.keypoints[i]) { - const diff = [Math.abs(keypoints[i].positionRaw[0] - cache5.keypoints[i].positionRaw[0]), Math.abs(keypoints[i].positionRaw[1] - cache5.keypoints[i].positionRaw[1])]; - if (diff[0] < maxJitter && diff[1] < maxJitter) { - keypoints[i] = cache5.keypoints[i]; - } else { - cache5.keypoints[i] = keypoints[i]; - } - } else { - cache5.keypoints[i] = keypoints[i]; - } - } - return keypoints; -} -function padInput(input, inputSize10) { - var _a, _b; - const t2 = {}; - if (!((_a = input == null ? void 0 : input.shape) == null ? void 0 : _a[1]) || !((_b = input == null ? void 0 : input.shape) == null ? void 0 : _b[2])) - return input; - cache5.padding = [ - [0, 0], - [input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0, input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0], - [input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0, input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0], - [0, 0] - ]; - t2.pad = tf31.pad(input, cache5.padding); - t2.resize = tf31.image.resizeBilinear(t2.pad, [inputSize10, inputSize10]); - const final = tf31.cast(t2.resize, "int32"); - Object.keys(t2).forEach((tensor6) => tf31.dispose(t2[tensor6])); - return final; -} -function rescaleBody(body4, outputSize2) { - body4.keypoints = body4.keypoints.filter((kpt4) => kpt4 == null ? void 0 : kpt4.position); - for (const kpt4 of body4.keypoints) { - kpt4.position = [ - kpt4.position[0] * (outputSize2[0] + cache5.padding[2][0] + cache5.padding[2][1]) / outputSize2[0] - cache5.padding[2][0], - kpt4.position[1] * (outputSize2[1] + cache5.padding[1][0] + cache5.padding[1][1]) / outputSize2[1] - cache5.padding[1][0] - ]; - kpt4.positionRaw = [ - kpt4.position[0] / outputSize2[0], - kpt4.position[1] / outputSize2[1] - ]; - } - const rescaledBoxes = calc(body4.keypoints.map((pt) => pt.position), outputSize2); - body4.box = rescaledBoxes.box; - body4.boxRaw = rescaledBoxes.boxRaw; - return body4; -} - -// src/body/movenet.ts -var model18; -var inputSize8 = 0; -var skipped14 = Number.MAX_SAFE_INTEGER; -var cache6 = { - boxes: [], - bodies: [], - last: 0 -}; -async function load17(config3) { - var _a; - if (env.initial) - model18 = null; - if (!model18) { - fakeOps(["size"], config3); - model18 = await loadModel(config3.body.modelPath); - } else if (config3.debug) - log("cached model:", model18["modelUrl"]); - inputSize8 = (model18 == null ? void 0 : model18["executor"]) && ((_a = model18 == null ? void 0 : model18.inputs) == null ? void 0 : _a[0].shape) ? model18.inputs[0].shape[2] : 0; - if (inputSize8 < 64) - inputSize8 = 256; - return model18; -} -function parseSinglePose(res, config3, image28) { - const kpt4 = res[0][0]; - const keypoints = []; - let score = 0; - for (let id = 0; id < kpt4.length; id++) { - score = kpt4[id][2]; - if (score > config3.body.minConfidence) { - const positionRaw = [kpt4[id][1], kpt4[id][0]]; - keypoints.push({ - score: Math.round(100 * score) / 100, - part: kpt3[id], - positionRaw, - position: [ - Math.round((image28.shape[2] || 0) * positionRaw[0]), - Math.round((image28.shape[1] || 0) * positionRaw[1]) - ] - }); - } - } - score = keypoints.reduce((prev, curr) => curr.score > prev ? curr.score : prev, 0); - const bodies = []; - const newBox = calc(keypoints.map((pt) => pt.position), [image28.shape[2], image28.shape[1]]); - const annotations2 = {}; - for (const [name, indexes] of Object.entries(connected3)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = keypoints.find((kp) => kp.part === indexes[i]); - const pt1 = keypoints.find((kp) => kp.part === indexes[i + 1]); - if (pt0 && pt1 && pt0.score > (config3.body.minConfidence || 0) && pt1.score > (config3.body.minConfidence || 0)) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - const body4 = { id: 0, score, box: newBox.box, boxRaw: newBox.boxRaw, keypoints, annotations: annotations2 }; - bodyParts(body4); - bodies.push(body4); - return bodies; -} -function parseMultiPose(res, config3, image28) { - const bodies = []; - for (let id = 0; id < res[0].length; id++) { - const kpt4 = res[0][id]; - const totalScore = Math.round(100 * kpt4[51 + 4]) / 100; - if (totalScore > config3.body.minConfidence) { - const keypoints = []; - for (let i = 0; i < 17; i++) { - const score = kpt4[3 * i + 2]; - if (score > config3.body.minConfidence) { - const positionRaw = [kpt4[3 * i + 1], kpt4[3 * i + 0]]; - keypoints.push({ - part: kpt3[i], - score: Math.round(100 * score) / 100, - positionRaw, - position: [Math.round((image28.shape[2] || 0) * positionRaw[0]), Math.round((image28.shape[1] || 0) * positionRaw[1])] - }); - } - } - const newBox = calc(keypoints.map((pt) => pt.position), [image28.shape[2], image28.shape[1]]); - const annotations2 = {}; - for (const [name, indexes] of Object.entries(connected3)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = keypoints.find((kp) => kp.part === indexes[i]); - const pt1 = keypoints.find((kp) => kp.part === indexes[i + 1]); - if (pt0 && pt1 && pt0.score > (config3.body.minConfidence || 0) && pt1.score > (config3.body.minConfidence || 0)) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - const body4 = { id, score: totalScore, box: newBox.box, boxRaw: newBox.boxRaw, keypoints: [...keypoints], annotations: annotations2 }; - bodyParts(body4); - bodies.push(body4); - } - } - bodies.sort((a, b) => b.score - a.score); - if (bodies.length > config3.body.maxDetected) - bodies.length = config3.body.maxDetected; - return bodies; -} -async function predict17(input, config3) { - var _a; - if (!(model18 == null ? void 0 : model18["executor"]) || !((_a = model18 == null ? void 0 : model18.inputs) == null ? void 0 : _a[0].shape)) - return []; - if (!config3.skipAllowed) - cache6.boxes.length = 0; - skipped14++; - const skipTime = (config3.body.skipTime || 0) > now() - cache6.last; - const skipFrame = skipped14 < (config3.body.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame) { - return cache6.bodies; - } - return new Promise(async (resolve) => { - const t2 = {}; - skipped14 = 0; - t2.input = padInput(input, inputSize8); - t2.res = model18 == null ? void 0 : model18.execute(t2.input); - cache6.last = now(); - const res = await t2.res.array(); - cache6.bodies = t2.res.shape[2] === 17 ? parseSinglePose(res, config3, input) : parseMultiPose(res, config3, input); - for (const body4 of cache6.bodies) { - rescaleBody(body4, [input.shape[2] || 1, input.shape[1] || 1]); - jitter(body4.keypoints); - } - Object.keys(t2).forEach((tensor6) => tf32.dispose(t2[tensor6])); - resolve(cache6.bodies); - }); -} - -// src/object/nanodet.ts -var tf33 = __toESM(require_tfjs_esm()); -var model19; -var last10 = []; -var lastTime15 = 0; -var skipped15 = Number.MAX_SAFE_INTEGER; -var inputSize9 = 0; -var scaleBox = 2.5; -async function load18(config3) { - if (!model19 || env.initial) { - model19 = await loadModel(config3.object.modelPath); - const inputs = (model19 == null ? void 0 : model19["executor"]) ? Object.values(model19.modelSignature["inputs"]) : void 0; - inputSize9 = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 416; - } else if (config3.debug) - log("cached model:", model19["modelUrl"]); - return model19; -} -async function process4(res, outputShape, config3) { - var _a, _b; - let id = 0; - let results = []; - const size2 = inputSize9; - for (const strideSize of [1, 2, 4]) { - const baseSize = strideSize * 13; - const scoresT = tf33.squeeze(res.find((a) => a.shape[1] === baseSize ** 2 && (a.shape[2] || 0) === labels2.length)); - const scores = await scoresT.array(); - const featuresT = tf33.squeeze(res.find((a) => a.shape[1] === baseSize ** 2 && (a.shape[2] || 0) < labels2.length)); - const boxesMaxT = tf33.reshape(featuresT, [-1, 4, (((_a = featuresT.shape) == null ? void 0 : _a[1]) || 0) / 4]); - const boxIdxT = tf33.argMax(boxesMaxT, 2); - const boxIdx = await boxIdxT.array(); - for (let i = 0; i < scoresT.shape[0]; i++) { - for (let j = 0; j < (((_b = scoresT.shape) == null ? void 0 : _b[1]) || 0); j++) { - const score = scores[i][j]; - if (score > (config3.object.minConfidence || 0) && j !== 61) { - const cx = (0.5 + Math.trunc(i % baseSize)) / baseSize; - const cy = (0.5 + Math.trunc(i / baseSize)) / baseSize; - const boxOffset = boxIdx[i].map((a) => a * (baseSize / strideSize / size2)); - const [x, y] = [ - cx - scaleBox / strideSize * boxOffset[0], - cy - scaleBox / strideSize * boxOffset[1] - ]; - const [w, h] = [ - cx + scaleBox / strideSize * boxOffset[2] - x, - cy + scaleBox / strideSize * boxOffset[3] - y - ]; - let boxRaw = [x, y, w, h]; - boxRaw = boxRaw.map((a) => Math.max(0, Math.min(a, 1))); - const box = [ - boxRaw[0] * outputShape[0], - boxRaw[1] * outputShape[1], - boxRaw[2] * outputShape[0], - boxRaw[3] * outputShape[1] - ]; - const result = { - id: id++, - score: Math.round(100 * score) / 100, - class: j + 1, - label: labels2[j].label, - box: box.map((a) => Math.trunc(a)), - boxRaw - }; - results.push(result); - } - } - } - tf33.dispose([scoresT, featuresT, boxesMaxT, boxIdxT]); - } - const nmsBoxes = results.map((a) => [a.boxRaw[1], a.boxRaw[0], a.boxRaw[3], a.boxRaw[2]]); - const nmsScores = results.map((a) => a.score); - let nmsIdx = []; - if (nmsBoxes && nmsBoxes.length > 0) { - const nms = await tf33.image.nonMaxSuppressionAsync(nmsBoxes, nmsScores, config3.object.maxDetected || 0, config3.object.iouThreshold, config3.object.minConfidence); - nmsIdx = Array.from(await nms.data()); - tf33.dispose(nms); - } - results = results.filter((_val, idx) => nmsIdx.includes(idx)).sort((a, b) => b.score - a.score); - return results; -} -async function predict18(image28, config3) { - if (!(model19 == null ? void 0 : model19["executor"])) - return []; - const skipTime = (config3.object.skipTime || 0) > now() - lastTime15; - const skipFrame = skipped15 < (config3.object.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && last10.length > 0) { - skipped15++; - return last10; - } - skipped15 = 0; - if (!env.kernels.includes("mod") || !env.kernels.includes("sparsetodense")) - return last10; - return new Promise(async (resolve) => { - const outputSize2 = [image28.shape[2] || 0, image28.shape[1] || 0]; - const resizeT = tf33.image.resizeBilinear(image28, [inputSize9, inputSize9], false); - const normT = tf33.div(resizeT, constants.tf255); - const transposeT = tf33.transpose(normT, [0, 3, 1, 2]); - let objectT; - if (config3.object.enabled) - objectT = model19.execute(transposeT); - lastTime15 = now(); - const obj = await process4(objectT, outputSize2, config3); - last10 = obj; - tf33.dispose([resizeT, normT, transposeT, ...objectT]); - resolve(obj); - }); -} - -// src/body/posenet.ts -var tf34 = __toESM(require_tfjs_esm()); - -// src/body/posenetutils.ts -var partNames = [ - "nose", - "leftEye", - "rightEye", - "leftEar", - "rightEar", - "leftShoulder", - "rightShoulder", - "leftElbow", - "rightElbow", - "leftWrist", - "rightWrist", - "leftHip", - "rightHip", - "leftKnee", - "rightKnee", - "leftAnkle", - "rightAnkle" -]; -var count = partNames.length; -var partIds = partNames.reduce((result, jointName, i) => { - result[jointName] = i; - return result; -}, {}); -var connectedPartNames = [ - ["leftHip", "leftShoulder"], - ["leftElbow", "leftShoulder"], - ["leftElbow", "leftWrist"], - ["leftHip", "leftKnee"], - ["leftKnee", "leftAnkle"], - ["rightHip", "rightShoulder"], - ["rightElbow", "rightShoulder"], - ["rightElbow", "rightWrist"], - ["rightHip", "rightKnee"], - ["rightKnee", "rightAnkle"], - ["leftShoulder", "rightShoulder"], - ["leftHip", "rightHip"] -]; -var connectedPartIndices = connectedPartNames.map(([jointNameA, jointNameB]) => [partIds[jointNameA], partIds[jointNameB]]); -var poseChain = [ - ["nose", "leftEye"], - ["leftEye", "leftEar"], - ["nose", "rightEye"], - ["rightEye", "rightEar"], - ["nose", "leftShoulder"], - ["leftShoulder", "leftElbow"], - ["leftElbow", "leftWrist"], - ["leftShoulder", "leftHip"], - ["leftHip", "leftKnee"], - ["leftKnee", "leftAnkle"], - ["nose", "rightShoulder"], - ["rightShoulder", "rightElbow"], - ["rightElbow", "rightWrist"], - ["rightShoulder", "rightHip"], - ["rightHip", "rightKnee"], - ["rightKnee", "rightAnkle"] -]; -function getBoundingBox(keypoints) { - const coord = keypoints.reduce(({ maxX, maxY, minX, minY }, { position: { x, y } }) => ({ - maxX: Math.max(maxX, x), - maxY: Math.max(maxY, y), - minX: Math.min(minX, x), - minY: Math.min(minY, y) - }), { - maxX: Number.NEGATIVE_INFINITY, - maxY: Number.NEGATIVE_INFINITY, - minX: Number.POSITIVE_INFINITY, - minY: Number.POSITIVE_INFINITY - }); - return [coord.minX, coord.minY, coord.maxX - coord.minX, coord.maxY - coord.minY]; -} -function scalePoses(poses, [height, width], [inputResolutionHeight, inputResolutionWidth]) { - const scaleY = height / inputResolutionHeight; - const scaleX = width / inputResolutionWidth; - const scalePose = (pose, i) => ({ - id: i, - score: pose.score, - boxRaw: [pose.box[0] / inputResolutionWidth, pose.box[1] / inputResolutionHeight, pose.box[2] / inputResolutionWidth, pose.box[3] / inputResolutionHeight], - box: [Math.trunc(pose.box[0] * scaleX), Math.trunc(pose.box[1] * scaleY), Math.trunc(pose.box[2] * scaleX), Math.trunc(pose.box[3] * scaleY)], - keypoints: pose.keypoints.map(({ score, part, position }) => ({ - score, - part, - position: [Math.trunc(position.x * scaleX), Math.trunc(position.y * scaleY)], - positionRaw: [position.x / inputResolutionHeight, position.y / inputResolutionHeight] - })), - annotations: {} - }); - const scaledPoses = poses.map((pose, i) => scalePose(pose, i)); - return scaledPoses; -} -var MaxHeap = class { - constructor(maxSize2, getElementValue) { - __publicField(this, "priorityQueue"); - __publicField(this, "numberOfElements"); - __publicField(this, "getElementValue"); - this.priorityQueue = new Array(maxSize2); - this.numberOfElements = -1; - this.getElementValue = getElementValue; - } - enqueue(x) { - this.priorityQueue[++this.numberOfElements] = x; - this.swim(this.numberOfElements); - } - dequeue() { - const max5 = this.priorityQueue[0]; - this.exchange(0, this.numberOfElements--); - this.sink(0); - this.priorityQueue[this.numberOfElements + 1] = null; - return max5; - } - empty() { - return this.numberOfElements === -1; - } - size() { - return this.numberOfElements + 1; - } - all() { - return this.priorityQueue.slice(0, this.numberOfElements + 1); - } - max() { - return this.priorityQueue[0]; - } - swim(k) { - while (k > 0 && this.less(Math.floor(k / 2), k)) { - this.exchange(k, Math.floor(k / 2)); - k = Math.floor(k / 2); - } - } - sink(k) { - while (2 * k <= this.numberOfElements) { - let j = 2 * k; - if (j < this.numberOfElements && this.less(j, j + 1)) - j++; - if (!this.less(k, j)) - break; - this.exchange(k, j); - k = j; - } - } - getValueAt(i) { - return this.getElementValue(this.priorityQueue[i]); - } - less(i, j) { - return this.getValueAt(i) < this.getValueAt(j); - } - exchange(i, j) { - const t2 = this.priorityQueue[i]; - this.priorityQueue[i] = this.priorityQueue[j]; - this.priorityQueue[j] = t2; - } -}; -function getOffsetPoint(y, x, keypoint, offsets) { - return { - y: offsets.get(y, x, keypoint), - x: offsets.get(y, x, keypoint + count) - }; -} -function getImageCoords(part, outputStride2, offsets) { - const { heatmapY, heatmapX, id: keypoint } = part; - const { y, x } = getOffsetPoint(heatmapY, heatmapX, keypoint, offsets); - return { - x: part.heatmapX * outputStride2 + x, - y: part.heatmapY * outputStride2 + y - }; -} -function clamp(a, min2, max5) { - if (a < min2) - return min2; - if (a > max5) - return max5; - return a; -} -function squaredDistance(y1, x1, y2, x2) { - const dy = y2 - y1; - const dx = x2 - x1; - return dy * dy + dx * dx; -} -function addVectors(a, b) { - return { x: a.x + b.x, y: a.y + b.y }; -} - -// src/body/posenet.ts -var model20; -var poseNetOutputs = ["MobilenetV1/offset_2/BiasAdd", "MobilenetV1/heatmap_2/BiasAdd", "MobilenetV1/displacement_fwd_2/BiasAdd", "MobilenetV1/displacement_bwd_2/BiasAdd"]; -var localMaximumRadius = 1; -var outputStride = 16; -var squaredNmsRadius = 50 ** 2; -function traverse(edgeId, sourceKeypoint, targetId, scores, offsets, displacements, offsetRefineStep = 2) { - const getDisplacement = (point2) => ({ - y: displacements.get(point2.y, point2.x, edgeId), - x: displacements.get(point2.y, point2.x, displacements.shape[2] / 2 + edgeId) - }); - const getStridedIndexNearPoint = (point2, height2, width2) => ({ - y: clamp(Math.round(point2.y / outputStride), 0, height2 - 1), - x: clamp(Math.round(point2.x / outputStride), 0, width2 - 1) - }); - const [height, width] = scores.shape; - const sourceKeypointIndices = getStridedIndexNearPoint(sourceKeypoint.position, height, width); - const displacement = getDisplacement(sourceKeypointIndices); - const displacedPoint = addVectors(sourceKeypoint.position, displacement); - let targetKeypoint = displacedPoint; - for (let i = 0; i < offsetRefineStep; i++) { - const targetKeypointIndices = getStridedIndexNearPoint(targetKeypoint, height, width); - const offsetPoint = getOffsetPoint(targetKeypointIndices.y, targetKeypointIndices.x, targetId, offsets); - targetKeypoint = addVectors( - { x: targetKeypointIndices.x * outputStride, y: targetKeypointIndices.y * outputStride }, - { x: offsetPoint.x, y: offsetPoint.y } - ); - } - const targetKeyPointIndices = getStridedIndexNearPoint(targetKeypoint, height, width); - const score = scores.get(targetKeyPointIndices.y, targetKeyPointIndices.x, targetId); - return { position: targetKeypoint, part: partNames[targetId], score }; -} -function decodePose(root, scores, offsets, displacementsFwd, displacementsBwd) { - const tuples = poseChain.map(([parentJoinName, childJoinName]) => [partIds[parentJoinName], partIds[childJoinName]]); - const edgesFwd = tuples.map(([, childJointId]) => childJointId); - const edgesBwd = tuples.map(([parentJointId]) => parentJointId); - const numParts = scores.shape[2]; - const numEdges = edgesFwd.length; - const keypoints = new Array(numParts); - const rootPoint = getImageCoords(root.part, outputStride, offsets); - keypoints[root.part.id] = { - score: root.score, - part: partNames[root.part.id], - position: rootPoint - }; - for (let edge = numEdges - 1; edge >= 0; --edge) { - const sourceId = edgesFwd[edge]; - const targetId = edgesBwd[edge]; - if (keypoints[sourceId] && !keypoints[targetId]) { - keypoints[targetId] = traverse(edge, keypoints[sourceId], targetId, scores, offsets, displacementsBwd); - } - } - for (let edge = 0; edge < numEdges; ++edge) { - const sourceId = edgesBwd[edge]; - const targetId = edgesFwd[edge]; - if (keypoints[sourceId] && !keypoints[targetId]) { - keypoints[targetId] = traverse(edge, keypoints[sourceId], targetId, scores, offsets, displacementsFwd); - } - } - return keypoints; -} -function scoreIsMaximumInLocalWindow(keypointId, score, heatmapY, heatmapX, scores) { - const [height, width] = scores.shape; - let localMaximum = true; - const yStart = Math.max(heatmapY - localMaximumRadius, 0); - const yEnd = Math.min(heatmapY + localMaximumRadius + 1, height); - for (let yCurrent = yStart; yCurrent < yEnd; ++yCurrent) { - const xStart = Math.max(heatmapX - localMaximumRadius, 0); - const xEnd = Math.min(heatmapX + localMaximumRadius + 1, width); - for (let xCurrent = xStart; xCurrent < xEnd; ++xCurrent) { - if (scores.get(yCurrent, xCurrent, keypointId) > score) { - localMaximum = false; - break; - } - } - if (!localMaximum) - break; - } - return localMaximum; -} -function buildPartWithScoreQueue(minConfidence2, scores) { - const [height, width, numKeypoints] = scores.shape; - const queue = new MaxHeap(height * width * numKeypoints, ({ score }) => score); - for (let heatmapY = 0; heatmapY < height; ++heatmapY) { - for (let heatmapX = 0; heatmapX < width; ++heatmapX) { - for (let keypointId = 0; keypointId < numKeypoints; ++keypointId) { - const score = scores.get(heatmapY, heatmapX, keypointId); - if (score < minConfidence2) - continue; - if (scoreIsMaximumInLocalWindow(keypointId, score, heatmapY, heatmapX, scores)) - queue.enqueue({ score, part: { heatmapY, heatmapX, id: keypointId } }); - } - } - } - return queue; -} -function withinRadius(poses, { x, y }, keypointId) { - return poses.some(({ keypoints }) => { - var _a; - const correspondingKeypoint = (_a = keypoints[keypointId]) == null ? void 0 : _a.position; - if (!correspondingKeypoint) - return false; - return squaredDistance(y, x, correspondingKeypoint.y, correspondingKeypoint.x) <= squaredNmsRadius; - }); -} -function getInstanceScore(existingPoses, keypoints) { - const notOverlappedKeypointScores = keypoints.reduce((result, { position, score }, keypointId) => { - if (!withinRadius(existingPoses, position, keypointId)) - result += score; - return result; - }, 0); - return notOverlappedKeypointScores / keypoints.length; -} -function decode(offsets, scores, displacementsFwd, displacementsBwd, maxDetected, minConfidence2) { - const poses = []; - const queue = buildPartWithScoreQueue(minConfidence2, scores); - while (poses.length < maxDetected && !queue.empty()) { - const root = queue.dequeue(); - const rootImageCoords = getImageCoords(root.part, outputStride, offsets); - if (withinRadius(poses, rootImageCoords, root.part.id)) - continue; - let keypoints = decodePose(root, scores, offsets, displacementsFwd, displacementsBwd); - keypoints = keypoints.filter((a) => a.score > minConfidence2); - const score = getInstanceScore(poses, keypoints); - const box = getBoundingBox(keypoints); - if (score > minConfidence2) - poses.push({ keypoints, box, score: Math.round(100 * score) / 100 }); - } - return poses; -} -async function predict19(input, config3) { - if (!(model20 == null ? void 0 : model20["executor"])) - return []; - const res = tf34.tidy(() => { - if (!model20.inputs[0].shape) - return []; - const resized = tf34.image.resizeBilinear(input, [model20.inputs[0].shape[2], model20.inputs[0].shape[1]]); - const normalized = tf34.sub(tf34.div(tf34.cast(resized, "float32"), 127.5), 1); - const results = model20.execute(normalized, poseNetOutputs); - const results3d = results.map((y) => tf34.squeeze(y, [0])); - results3d[1] = tf34.sigmoid(results3d[1]); - return results3d; - }); - const buffers = await Promise.all(res.map((tensor6) => tensor6.buffer())); - for (const t2 of res) - tf34.dispose(t2); - const decoded = decode(buffers[0], buffers[1], buffers[2], buffers[3], config3.body.maxDetected, config3.body.minConfidence); - if (!model20.inputs[0].shape) - return []; - const scaled = scalePoses(decoded, [input.shape[1], input.shape[2]], [model20.inputs[0].shape[2], model20.inputs[0].shape[1]]); - return scaled; -} -async function load19(config3) { - if (!model20 || env.initial) - model20 = await loadModel(config3.body.modelPath); - else if (config3.debug) - log("cached model:", model20["modelUrl"]); - return model20; -} - -// src/segmentation/rvm.ts -var tf35 = __toESM(require_tfjs_esm()); -var model21; -var outputNodes2 = ["fgr", "pha", "r1o", "r2o", "r3o", "r4o"]; -var t = {}; -var ratio = 0; -function init3(config3) { - tf35.dispose([t.r1i, t.r2i, t.r3i, t.r4i, t.downsample_ratio]); - t.r1i = tf35.tensor(0); - t.r2i = tf35.tensor(0); - t.r3i = tf35.tensor(0); - t.r4i = tf35.tensor(0); - ratio = config3.segmentation.ratio || 0.5; - t.downsample_ratio = tf35.tensor(ratio); -} -async function load20(config3) { - if (!model21 || env.initial) - model21 = await loadModel(config3.segmentation.modelPath); - else if (config3.debug) - log("cached model:", model21["modelUrl"]); - init3(config3); - return model21; -} -var normalize = (r) => tf35.tidy(() => { - const squeeze14 = tf35.squeeze(r, [0]); - const mul15 = tf35.mul(squeeze14, constants.tf255); - const cast8 = tf35.cast(mul15, "int32"); - return cast8; -}); -function getRGBA(fgr, pha) { - const rgb2 = fgr ? normalize(fgr) : tf35.fill([pha.shape[1] || 0, pha.shape[2] || 0, 3], 255, "int32"); - const a = pha ? normalize(pha) : tf35.fill([fgr.shape[1] || 0, fgr.shape[2] || 0, 1], 255, "int32"); - const rgba = tf35.concat([rgb2, a], -1); - tf35.dispose([rgb2, a]); - return rgba; -} -function getState(state) { - return tf35.tidy(() => { - const r = {}; - r.unstack = tf35.unstack(state, -1); - r.concat = tf35.concat(r.unstack, 1); - r.split = tf35.split(r.concat, 4, 1); - r.stack = tf35.concat(r.split, 2); - r.squeeze = tf35.squeeze(r.stack, [0]); - r.expand = tf35.expandDims(r.squeeze, -1); - r.add = tf35.add(r.expand, 1); - r.mul = tf35.mul(r.add, 127.5); - r.cast = tf35.cast(r.mul, "int32"); - r.tile = tf35.tile(r.cast, [1, 1, 3]); - r.alpha = tf35.fill([r.tile.shape[0] || 0, r.tile.shape[1] || 0, 1], 255, "int32"); - return tf35.concat([r.tile, r.alpha], -1); - }); -} -async function predict20(input, config3) { - if (!model21) - model21 = await load20(config3); - if (!(model21 == null ? void 0 : model21["executor"])) - return null; - t.src = tf35.div(input, 255); - if (ratio !== config3.segmentation.ratio) - init3(config3); - const [fgr, pha, r1o, r2o, r3o, r4o] = await model21.executeAsync(t, outputNodes2); - let rgba; - switch (config3.segmentation.mode || "default") { - case "default": - rgba = getRGBA(fgr, pha); - break; - case "alpha": - rgba = getRGBA(null, pha); - break; - case "foreground": - rgba = getRGBA(fgr, null); - break; - case "state": - rgba = getState(r1o); - break; - default: - rgba = tf35.tensor(0); - } - tf35.dispose([t.src, fgr, pha, t.r1i, t.r2i, t.r3i, t.r4i]); - [t.r1i, t.r2i, t.r3i, t.r4i] = [r1o, r2o, r3o, r4o]; - return rgba; -} - -// src/segmentation/selfie.ts -var tf36 = __toESM(require_tfjs_esm()); -var model22; -async function load21(config3) { - if (!model22 || env.initial) - model22 = await loadModel(config3.segmentation.modelPath); - else if (config3.debug) - log("cached model:", model22["modelUrl"]); - return model22; -} -async function predict21(input, config3) { - var _a; - if (!model22) - model22 = await load21(config3); - if (!(model22 == null ? void 0 : model22["executor"]) || !((_a = model22 == null ? void 0 : model22.inputs) == null ? void 0 : _a[0].shape)) - return null; - const t2 = {}; - t2.resize = tf36.image.resizeBilinear(input, [model22.inputs[0].shape ? model22.inputs[0].shape[1] : 0, model22.inputs[0].shape ? model22.inputs[0].shape[2] : 0], false); - t2.norm = tf36.div(t2.resize, constants.tf255); - t2.res = model22.execute(t2.norm); - t2.squeeze = tf36.squeeze(t2.res, [0]); - t2.alpha = tf36.image.resizeBilinear(t2.squeeze, [input.shape[1] || 0, input.shape[2] || 0]); - t2.mul = tf36.mul(t2.alpha, constants.tf255); - let rgba; - switch (config3.segmentation.mode || "default") { - case "default": - t2.input = tf36.squeeze(input); - t2.concat = tf36.concat([t2.input, t2.mul], -1); - rgba = tf36.cast(t2.concat, "int32"); - break; - case "alpha": - rgba = tf36.cast(t2.mul, "int32"); - break; - default: - rgba = tf36.tensor(0); - } - Object.keys(t2).forEach((tensor6) => tf36.dispose(t2[tensor6])); - return rgba; -} - -// src/models.ts -function validateModel(instance, model23, name) { - var _a, _b; - if (!model23) - return null; - if (!((_a = instance == null ? void 0 : instance.config) == null ? void 0 : _a.validateModels)) - return null; - const simpleOps = ["const", "placeholder", "noop", "pad", "squeeze", "add", "sub", "mul", "div"]; - const ignoreOps = ["biasadd", "fusedbatchnormv3", "matmul", "switch", "shape", "merge", "split", "broadcastto"]; - const ops = []; - const missing = []; - const url = model23["modelUrl"]; - const executor = model23["executor"]; - if ((_b = executor == null ? void 0 : executor.graph) == null ? void 0 : _b.nodes) { - for (const kernel of Object.values(executor.graph.nodes)) { - const op = kernel.op.toLowerCase(); - if (!ops.includes(op)) - ops.push(op); - } - } else { - if (!executor && instance.config.debug) { - log("model not loaded", name); - } - } - for (const op of ops) { - if (!simpleOps.includes(op) && !ignoreOps.includes(op) && !instance.env.kernels.includes(op) && !instance.env.kernels.includes(op.replace("_", "")) && !instance.env.kernels.includes(op.replace("native", "")) && !instance.env.kernels.includes(op.replace("v2", ""))) { - missing.push(op); - } - } - if (instance.config.debug && missing.length > 0) - log("model validation failed:", name, missing); - return missing.length > 0 ? { name, missing, ops, url } : null; -} -var Models = class { - constructor(currentInstance) { - __publicField(this, "instance"); - __publicField(this, "models", {}); - this.models = {}; - this.instance = currentInstance; - } - stats() { - let totalSizeFromManifest = 0; - let totalSizeWeights = 0; - let totalSizeLoading = 0; - for (const m of Object.values(modelStats)) { - totalSizeFromManifest += m.sizeFromManifest; - totalSizeWeights += m.sizeLoadedWeights; - totalSizeLoading += m.sizeDesired; - } - const percentageLoaded = totalSizeLoading > 0 ? totalSizeWeights / totalSizeLoading : 0; - return { - numLoadedModels: Object.values(modelStats).length, - numDefinedModels: Object.keys(this.models).length, - percentageLoaded, - totalSizeFromManifest, - totalSizeWeights, - totalSizeLoading, - modelStats: Object.values(modelStats) - }; - } - reset() { - for (const model23 of Object.keys(this.models)) - this.models[model23] = null; - } - async load(instance) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A; - if (env.initial) - this.reset(); - if (instance) - this.instance = instance; - const m = {}; - m.blazeface = this.instance.config.face.enabled && !this.models.blazeface ? load3(this.instance.config) : null; - m.antispoof = this.instance.config.face.enabled && ((_a = this.instance.config.face.antispoof) == null ? void 0 : _a.enabled) && !this.models.antispoof ? load8(this.instance.config) : null; - m.liveness = this.instance.config.face.enabled && ((_b = this.instance.config.face.liveness) == null ? void 0 : _b.enabled) && !this.models.liveness ? load9(this.instance.config) : null; - m.faceres = this.instance.config.face.enabled && ((_c = this.instance.config.face.description) == null ? void 0 : _c.enabled) && !this.models.faceres ? load7(this.instance.config) : null; - m.emotion = this.instance.config.face.enabled && ((_d = this.instance.config.face.emotion) == null ? void 0 : _d.enabled) && !this.models.emotion ? load6(this.instance.config) : null; - m.iris = this.instance.config.face.enabled && ((_e = this.instance.config.face.iris) == null ? void 0 : _e.enabled) && !((_f = this.instance.config.face.attention) == null ? void 0 : _f.enabled) && !this.models.iris ? load4(this.instance.config) : null; - m.facemesh = this.instance.config.face.enabled && ((_g = this.instance.config.face.mesh) == null ? void 0 : _g.enabled) && !this.models.facemesh ? load5(this.instance.config) : null; - m.gear = this.instance.config.face.enabled && ((_h = this.instance.config.face["gear"]) == null ? void 0 : _h.enabled) && !this.models.gear ? load10(this.instance.config) : null; - m.ssrnetage = this.instance.config.face.enabled && ((_i = this.instance.config.face["ssrnet"]) == null ? void 0 : _i.enabled) && !this.models.ssrnetage ? load11(this.instance.config) : null; - m.ssrnetgender = this.instance.config.face.enabled && ((_j = this.instance.config.face["ssrnet"]) == null ? void 0 : _j.enabled) && !this.models.ssrnetgender ? load12(this.instance.config) : null; - m.mobilefacenet = this.instance.config.face.enabled && ((_k = this.instance.config.face["mobilefacenet"]) == null ? void 0 : _k.enabled) && !this.models.mobilefacenet ? load13(this.instance.config) : null; - m.insightface = this.instance.config.face.enabled && ((_l = this.instance.config.face["insightface"]) == null ? void 0 : _l.enabled) && !this.models.insightface ? load14(this.instance.config) : null; - m.blazepose = this.instance.config.body.enabled && !this.models.blazepose && ((_m = this.instance.config.body.modelPath) == null ? void 0 : _m.includes("blazepose")) ? loadPose(this.instance.config) : null; - m.blazeposedetect = this.instance.config.body.enabled && !this.models.blazeposedetect && this.instance.config.body["detector"] && this.instance.config.body["detector"].modelPath ? loadDetect(this.instance.config) : null; - m.efficientpose = this.instance.config.body.enabled && !this.models.efficientpose && ((_n = this.instance.config.body.modelPath) == null ? void 0 : _n.includes("efficientpose")) ? load2(this.instance.config) : null; - m.movenet = this.instance.config.body.enabled && !this.models.movenet && ((_o = this.instance.config.body.modelPath) == null ? void 0 : _o.includes("movenet")) ? load17(this.instance.config) : null; - m.posenet = this.instance.config.body.enabled && !this.models.posenet && ((_p = this.instance.config.body.modelPath) == null ? void 0 : _p.includes("posenet")) ? load19(this.instance.config) : null; - m.handtrack = this.instance.config.hand.enabled && !this.models.handtrack && ((_r = (_q = this.instance.config.hand.detector) == null ? void 0 : _q.modelPath) == null ? void 0 : _r.includes("handtrack")) ? loadDetect2(this.instance.config) : null; - m.handskeleton = this.instance.config.hand.enabled && this.instance.config.hand.landmarks && !this.models.handskeleton && ((_t = (_s = this.instance.config.hand.detector) == null ? void 0 : _s.modelPath) == null ? void 0 : _t.includes("handtrack")) ? loadSkeleton(this.instance.config) : null; - if ((_v = (_u = this.instance.config.hand.detector) == null ? void 0 : _u.modelPath) == null ? void 0 : _v.includes("handdetect")) - [m.handpose, m.handskeleton] = !this.models.handpose ? await load15(this.instance.config) : [null, null]; - m.centernet = this.instance.config.object.enabled && !this.models.centernet && ((_w = this.instance.config.object.modelPath) == null ? void 0 : _w.includes("centernet")) ? load(this.instance.config) : null; - m.nanodet = this.instance.config.object.enabled && !this.models.nanodet && ((_x = this.instance.config.object.modelPath) == null ? void 0 : _x.includes("nanodet")) ? load18(this.instance.config) : null; - m.selfie = this.instance.config.segmentation.enabled && !this.models.selfie && ((_y = this.instance.config.segmentation.modelPath) == null ? void 0 : _y.includes("selfie")) ? load21(this.instance.config) : null; - m.meet = this.instance.config.segmentation.enabled && !this.models.meet && ((_z = this.instance.config.segmentation.modelPath) == null ? void 0 : _z.includes("meet")) ? load16(this.instance.config) : null; - m.rvm = this.instance.config.segmentation.enabled && !this.models.rvm && ((_A = this.instance.config.segmentation.modelPath) == null ? void 0 : _A.includes("rvm")) ? load20(this.instance.config) : null; - for (const [model23, promise] of Object.entries(m)) { - if (promise == null ? void 0 : promise["then"]) - promise["then"]((val) => this.models[model23] = val); - } - await Promise.all(Object.values(m)); - } - list() { - const models3 = Object.keys(this.models).map((model23) => { - var _a; - return { name: model23, loaded: this.models[model23] !== null, size: 0, url: this.models[model23] ? (_a = this.models[model23]) == null ? void 0 : _a["modelUrl"] : null }; - }); - for (const m of models3) { - const stats = Object.keys(modelStats).find((s) => s.startsWith(m.name)); - if (!stats) - continue; - m.size = modelStats[stats].sizeLoadedWeights; - m.url = modelStats[stats].url; - } - return models3; - } - loaded() { - const list = this.list(); - const loaded = list.filter((model23) => model23.loaded).map((model23) => model23.name); - return loaded; - } - validate() { - const missing = []; - for (const defined of Object.keys(this.models)) { - const model23 = this.models[defined]; - if (!model23) - continue; - const res = validateModel(this.instance, model23, defined); - if (res) - missing.push(res); - } - return missing; - } -}; - -// src/util/persons.ts -function join2(faces, bodies, hands, gestures, shape) { - var _a, _b, _c, _d, _e, _f; - let id = 0; - const persons = []; - for (const face4 of faces) { - const person2 = { id: id++, face: face4, body: null, hands: { left: null, right: null }, gestures: [], box: [0, 0, 0, 0] }; - for (const body4 of bodies) { - if (face4.box[0] > body4.box[0] && face4.box[0] < body4.box[0] + body4.box[2] && face4.box[1] + face4.box[3] > body4.box[1] && face4.box[1] + face4.box[3] < body4.box[1] + body4.box[3]) { - person2.body = body4; - } - } - if (person2.body) { - for (const hand3 of hands) { - if (hand3.box[0] + hand3.box[2] > person2.body.box[0] && hand3.box[0] + hand3.box[2] < person2.body.box[0] + person2.body.box[2] && hand3.box[1] + hand3.box[3] > person2.body.box[1] && hand3.box[1] + hand3.box[3] < person2.body.box[1] + person2.body.box[3]) { - if (person2.hands) - person2.hands.left = hand3; - } - if (hand3.box[0] < person2.body.box[0] + person2.body.box[2] && hand3.box[0] > person2.body.box[0] && hand3.box[1] + hand3.box[3] > person2.body.box[1] && hand3.box[1] + hand3.box[3] < person2.body.box[1] + person2.body.box[3]) { - if (person2.hands) - person2.hands.right = hand3; - } - } - } - for (const gesture2 of gestures) { - if (gesture2["face"] !== void 0 && gesture2["face"] === face4.id) - person2.gestures.push(gesture2); - else if (gesture2["iris"] !== void 0 && gesture2["iris"] === face4.id) - person2.gestures.push(gesture2); - else if (gesture2["body"] !== void 0 && gesture2["body"] === ((_a = person2.body) == null ? void 0 : _a.id)) - person2.gestures.push(gesture2); - else if (gesture2["hand"] !== void 0 && gesture2["hand"] === ((_b = person2.hands.left) == null ? void 0 : _b.id)) - person2.gestures.push(gesture2); - else if (gesture2["hand"] !== void 0 && gesture2["hand"] === ((_c = person2.hands.right) == null ? void 0 : _c.id)) - person2.gestures.push(gesture2); - } - const x = []; - const y = []; - const extractXY = (box) => { - if (box && box.length === 4) { - x.push(box[0], box[0] + box[2]); - y.push(box[1], box[1] + box[3]); - } - }; - extractXY(person2.face.box); - extractXY((_d = person2.body) == null ? void 0 : _d.box); - extractXY((_e = person2.hands.left) == null ? void 0 : _e.box); - extractXY((_f = person2.hands.right) == null ? void 0 : _f.box); - const minX = Math.min(...x); - const minY = Math.min(...y); - person2.box = [minX, minY, Math.max(...x) - minX, Math.max(...y) - minY]; - if ((shape == null ? void 0 : shape[1]) && (shape == null ? void 0 : shape[2])) - person2.boxRaw = [person2.box[0] / shape[2], person2.box[1] / shape[1], person2.box[2] / shape[2], person2.box[3] / shape[1]]; - persons.push(person2); - } - return persons; -} - -// src/warmup.ts -var tf37 = __toESM(require_tfjs_esm()); - -// src/sample.ts -var face3 = ` + gaze: [gaze]\xB0`,body:"body [score]%",bodyPart:"[label] [score]%",object:"[label] [score]%",hand:"[label] [score]%",finger:"[label]",gesture:"[where] [who]: [what]"};var s5=0;function Fs(e,t,n){let o=a0(x0,n);if(!t||!e)return;let r=Q0(e);if(!!r){r.lineJoin="round",r.font=o.font;for(let s=0;si5,kpt:()=>a5});var a5=["nose","leftEyeInside","leftEye","leftEyeOutside","rightEyeInside","rightEye","rightEyeOutside","leftEar","rightEar","leftMouth","rightMouth","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftPinky","rightPinky","leftIndex","rightIndex","leftThumb","rightThumb","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle","leftHeel","rightHeel","leftFoot","rightFoot","bodyCenter","bodyTop","leftPalm","leftHand","rightPalm","rightHand"],i5={shoulders:["leftShoulder","rightShoulder"],hips:["rightHip","leftHip"],mouth:["leftMouth","rightMouth"],leftLegUpper:["leftHip","leftKnee"],leftLegLower:["leftKnee","leftAnkle"],leftFoot:["leftAnkle","leftHeel","leftFoot"],leftTorso:["leftShoulder","leftHip"],leftArmUpper:["leftShoulder","leftElbow"],leftArmLower:["leftElbow","leftWrist"],leftHand:["leftWrist","leftPalm"],leftHandPinky:["leftPalm","leftPinky"],leftHandIndex:["leftPalm","leftIndex"],leftHandThumb:["leftPalm","leftThumb"],leftEyeOutline:["leftEyeInside","leftEyeOutside"],rightLegUpper:["rightHip","rightKnee"],rightLegLower:["rightKnee","rightAnkle"],rightFoot:["rightAnkle","rightHeel","rightFoot"],rightTorso:["rightShoulder","rightHip"],rightArmUpper:["rightShoulder","rightElbow"],rightArmLower:["rightElbow","rightWrist"],rightHand:["rightWrist","rightPalm"],rightHandPinky:["rightPalm","rightPinky"],rightHandIndex:["rightPalm","rightIndex"],rightHandThumb:["rightPalm","rightThumb"],rightEyeOutline:["rightEyeInside","rightEyeOutside"]};var D=Z(H());var _0,t2=224,Y1,Gs=5,rt=[8,16,32,32,32];function Vs(){let e=[],t=0;for(;tn.x)),y:D.tensor1d(e.map(n=>n.y))}}async function K1(e){if(R.initial&&(_0=null),!_0&&e.body.detector&&e.body.detector.modelPath){_0=await O(e.body.detector.modelPath);let t=_0!=null&&_0.executor?Object.values(_0.modelSignature.inputs):void 0;t2=Array.isArray(t)?parseInt(t[0].tensorShape.dim[1].size):0}else e.debug&&_0&&u("cached model:",_0.modelUrl);return Vs(),_0}var U1=[5,5];function Zs(e,t){return D.tidy(()=>{let n=D.split(e,12,1),o=D.squeeze(n[0]),r=D.squeeze(n[1]),s=D.squeeze(n[2]),A=D.squeeze(n[3]);o=D.add(D.div(o,t2),t.x),r=D.add(D.div(r,t2),t.y),s=D.mul(D.div(s,t2),U1[0]),A=D.mul(D.div(A,t2),U1[1]);let a=D.sub(o,D.div(s,2)),l=D.sub(r,D.div(A,2)),c=D.add(a,s),x=D.add(l,A);return D.stack([a,l,c,x],1)})}async function Xs(e,t,n,o){var c,x;let r=[],s={};s.boxes=Zs(e,Y1),s.scores=D.sigmoid(t),s.nms=await D.image.nonMaxSuppressionAsync(s.boxes,s.scores,1,((c=n.body.detector)==null?void 0:c.minConfidence)||.1,((x=n.body.detector)==null?void 0:x.iouThreshold)||.1);let A=await s.nms.data(),a=await s.scores.data(),l=await s.boxes.array();for(let i of Array.from(A)){let y=a[i],d=l[i],p=[Math.round(d[0]*o[0]),Math.round(d[1]*o[1]),Math.round(d[2]*o[0]),Math.round(d[3]*o[1])],f={score:y,boxRaw:d,box:p};r.push(f)}return Object.keys(s).forEach(i=>D.dispose(s[i])),r}async function J1(e,t,n){let o={};o.res=_0==null?void 0:_0.execute(e,["Identity"]),o.logitsRaw=D.slice(o.res,[0,0,0],[1,-1,1]),o.boxesRaw=D.slice(o.res,[0,0,1],[1,-1,-1]),o.logits=D.squeeze(o.logitsRaw),o.boxes=D.squeeze(o.boxesRaw);let r=await Xs(o.boxes,o.logits,t,n);return Object.keys(o).forEach(s=>D.dispose(o[s])),r}function ve(e,t=[1,1]){let n=[e.map(a=>a[0]),e.map(a=>a[1])],o=[Math.min(...n[0]),Math.min(...n[1])],r=[Math.max(...n[0]),Math.max(...n[1])],s=[o[0],o[1],r[0]-o[0],r[1]-o[1]],A=[s[0]/t[0],s[1]/t[1],s[2]/t[0],s[3]/t[1]];return{box:s,boxRaw:A}}function Q1(e,t=[1,1]){let n=[e.map(c=>c[0]),e.map(c=>c[1])],o=[Math.min(...n[0]),Math.min(...n[1])],r=[Math.max(...n[0]),Math.max(...n[1])],s=[(o[0]+r[0])/2,(o[1]+r[1])/2],A=Math.max(s[0]-o[0],s[1]-o[1],-s[0]+r[0],-s[1]+r[1]),a=[Math.trunc(s[0]-A),Math.trunc(s[1]-A),Math.trunc(2*A),Math.trunc(2*A)],l=[a[0]/t[0],a[1]/t[1],a[2]/t[0],a[3]/t[1]];return{box:a,boxRaw:l}}function st(e,t){let n=[e[2]*t,e[3]*t];return[e[0]-(n[0]-e[2])/2,e[1]-(n[1]-e[3])/2,n[0],n[1]]}var F0,c5=256,l5=Number.MAX_SAFE_INTEGER,qs={landmarks:["ld_3d","activation_segmentation","activation_heatmap","world_3d","output_poseflag"],detector:[]},at=[],Oe=[[0,0],[0,0],[0,0],[0,0]],_1=0,$1=e=>1-1/(1+Math.exp(e)),t3=e=>K1(e);async function n3(e){if(R.initial&&(F0=null),F0)e.debug&&u("cached model:",F0.modelUrl);else{F0=await O(e.body.modelPath);let t=F0!=null&&F0.executor?Object.values(F0.modelSignature.inputs):void 0;c5=Array.isArray(t)?parseInt(t[0].tensorShape.dim[1].size):0}return F0}function e3(e,t,n){var s,A;let o={};if(!((s=e==null?void 0:e.shape)!=null&&s[1])||!((A=e==null?void 0:e.shape)!=null&&A[2]))return e;let r;if(n&&(o.cropped=B0.image.cropAndResize(e,[n],[0],[e.shape[1],e.shape[2]])),e.shape[1]!==e.shape[2]){let a=[e.shape[2]>e.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0,e.shape[2]>e.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0],l=[e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0,e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0];Oe=[[0,0],a,l,[0,0]],o.pad=B0.pad(o.cropped||e,Oe),o.resize=B0.image.resizeBilinear(o.pad,[t,t]),r=B0.div(o.resize,C.tf255)}else e.shape[1]!==t?(o.resize=B0.image.resizeBilinear(o.cropped||e,[t,t]),r=B0.div(o.resize,C.tf255)):r=B0.div(o.cropped||e,C.tf255);return Object.keys(o).forEach(a=>B0.dispose(o[a])),r}function Us(e,t,n){for(let o of e)o.position=[Math.trunc(o.position[0]*(t[0]+Oe[2][0]+Oe[2][1])/t[0]-Oe[2][0]),Math.trunc(o.position[1]*(t[1]+Oe[1][0]+Oe[1][1])/t[1]-Oe[1][0]),o.position[2]],o.positionRaw=[o.position[0]/t[0],o.position[1]/t[1],2*o.position[2]/(t[0]+t[1])];if(n){let o=n[2]-n[0],r=n[3]-n[1];for(let s of e)s.positionRaw=[s.positionRaw[0]/r+n[1],s.positionRaw[1]/o+n[0],s.positionRaw[2]],s.position=[Math.trunc(s.positionRaw[0]*t[0]),Math.trunc(s.positionRaw[1]*t[1]),s.positionRaw[2]]}return e}function Ys(e){let t=e.find(a=>a.part==="leftPalm"),n=e.find(a=>a.part==="leftWrist"),o=e.find(a=>a.part==="leftIndex");t.position[2]=((n.position[2]||0)+(o.position[2]||0))/2;let r=e.find(a=>a.part==="rightPalm"),s=e.find(a=>a.part==="rightWrist"),A=e.find(a=>a.part==="rightIndex");r.position[2]=((s.position[2]||0)+(A.position[2]||0))/2}async function Ks(e,t,n){if(!(F0!=null&&F0.executor))return null;let o={};[o.ld,o.segmentation,o.heatmap,o.world,o.poseflag]=F0==null?void 0:F0.execute(e,qs.landmarks);let r=(await o.poseflag.data())[0],s=await o.ld.data(),A=await o.world.data();Object.keys(o).forEach(p=>B0.dispose(o[p]));let a=[],l=5;for(let p=0;pp.position),i=ve(x,[n[0],n[1]]),y={};for(let[p,f]of Object.entries(i5)){let b=[];for(let M=0;Mh.part===f[M]),m=c.find(h=>h.part===f[M+1]);T&&m&&b.push([T.position,m.position])}y[p]=b}return{id:0,score:Math.trunc(100*r)/100,box:i.box,boxRaw:i.boxRaw,keypoints:c,annotations:y}}async function d5(e,t){var s,A,a;let n=[e.shape[2]||0,e.shape[1]||0],o=(t.body.skipTime||0)>g()-_1,r=l5<(t.body.skipFrames||0);if(t.skipAllowed&&o&&r&&at!==null)l5++;else{let l=[];if((A=(s=t.body)==null?void 0:s.detector)!=null&&A.enabled){let c=e3(e,224);l=await J1(c,t,n),B0.dispose(c)}else l=[{box:[0,0,0,0],boxRaw:[0,0,1,1],score:0}];for(let c=0;cL0.dispose(o[c])),r}async function f5(e,t){if(!(H0!=null&&H0.executor))return[];let n=(t.object.skipTime||0)>g()-r3,o=y5<(t.object.skipFrames||0);return t.skipAllowed&&n&&o&&x5.length>0?(y5++,x5):(y5=0,new Promise(async r=>{let s=[e.shape[2]||0,e.shape[1]||0],A=L0.image.resizeBilinear(e,[n2,n2]),a=t.object.enabled?H0==null?void 0:H0.execute(A,["tower_0/detections"]):null;r3=g(),L0.dispose(A);let l=await Js(a,s,t);x5=l,r(l)}))}var J=Z(H());var it={};ze(it,{connected:()=>p5,kpt:()=>m5});var m5=["head","neck","rightShoulder","rightElbow","rightWrist","chest","leftShoulder","leftElbow","leftWrist","bodyCenter","rightHip","rightKnee","rightAnkle","leftHip","leftKnee","leftAnkle"],p5={leftLeg:["leftHip","leftKnee","leftAnkle"],rightLeg:["rightHip","rightKnee","rightAnkle"],torso:["leftShoulder","rightShoulder","rightHip","leftHip","leftShoulder"],leftArm:["leftShoulder","leftElbow","leftWrist"],rightArm:["rightShoulder","rightElbow","rightWrist"],head:[]};var i0,a3=0,C0={id:0,keypoints:[],box:[0,0,0,0],boxRaw:[0,0,0,0],score:0,annotations:{}},u5=Number.MAX_SAFE_INTEGER;async function i3(e){return R.initial&&(i0=null),i0?e.debug&&u("cached model:",i0.modelUrl):i0=await O(e.body.modelPath),i0}async function Qs(e,t){let[n,o]=e.shape,r=J.reshape(e,[o*n]),s=J.max(r,0),A=(await s.data())[0];if(A>t){let a=J.argMax(r,0),l=J.mod(a,n),c=(await l.data())[0],x=J.div(a,n),i=(await x.data())[0];return J.dispose([r,s,a,l,x]),[c,i,A]}return J.dispose([r,s]),[0,0,A]}async function h5(e,t){if(!(i0!=null&&i0.executor)||!(i0!=null&&i0.inputs[0].shape))return[];let n=(t.body.skipTime||0)>g()-a3,o=u5<(t.body.skipFrames||0);return t.skipAllowed&&n&&o&&Object.keys(C0.keypoints).length>0?(u5++,[C0]):(u5=0,new Promise(async r=>{let s=J.tidy(()=>{var p,f;let i=J.image.resizeBilinear(e,[((p=i0==null?void 0:i0.inputs[0].shape)==null?void 0:p[2])||0,((f=i0==null?void 0:i0.inputs[0].shape)==null?void 0:f[1])||0],!1),y=J.mul(i,C.tf2);return J.sub(y,C.tf1)}),A;if(t.body.enabled&&(A=i0==null?void 0:i0.execute(s)),a3=g(),J.dispose(s),A){C0.keypoints.length=0;let i=J.squeeze(A);J.dispose(A);let y=J.unstack(i,2);J.dispose(i);for(let d=0;d(t.body.minConfidence||0)&&C0.keypoints.push({score:Math.round(100*b)/100,part:m5[d],positionRaw:[p/i0.inputs[0].shape[2],f/i0.inputs[0].shape[1]],position:[Math.round(e.shape[2]*p/i0.inputs[0].shape[2]),Math.round(e.shape[1]*f/i0.inputs[0].shape[1])]})}y.forEach(d=>J.dispose(d))}C0.score=C0.keypoints.reduce((i,y)=>y.score>i?y.score:i,0);let a=C0.keypoints.map(i=>i.position[0]),l=C0.keypoints.map(i=>i.position[1]);C0.box=[Math.min(...a),Math.min(...l),Math.max(...a)-Math.min(...a),Math.max(...l)-Math.min(...l)];let c=C0.keypoints.map(i=>i.positionRaw[0]),x=C0.keypoints.map(i=>i.positionRaw[1]);C0.boxRaw=[Math.min(...c),Math.min(...x),Math.max(...c)-Math.min(...c),Math.max(...x)-Math.min(...x)];for(let[i,y]of Object.entries(p5)){let d=[];for(let p=0;pM.part===y[p]),b=C0.keypoints.find(M=>M.part===y[p+1]);f&&b&&f.score>(t.body.minConfidence||0)&&b.score>(t.body.minConfidence||0)&&d.push([f.position,b.position])}C0.annotations[i]=d}r([C0])}))}var l0=Z(H());var We=Z(H());var L=Z(H());var Re=Z(H());var y2=e=>[Math.abs(e.endPoint[0]-e.startPoint[0]),Math.abs(e.endPoint[1]-e.startPoint[1])],lt=e=>[e.startPoint[0]+(e.endPoint[0]-e.startPoint[0])/2,e.startPoint[1]+(e.endPoint[1]-e.startPoint[1])/2,1],ct=(e,t)=>e?[Math.trunc(Math.max(0,e.startPoint[0])),Math.trunc(Math.max(0,e.startPoint[1])),Math.trunc(Math.min(t.shape[2]||0,e.endPoint[0])-Math.max(0,e.startPoint[0])),Math.trunc(Math.min(t.shape[1]||0,e.endPoint[1])-Math.max(0,e.startPoint[1]))]:[0,0,0,0],dt=(e,t)=>e?[e.startPoint[0]/(t.shape[2]||0),e.startPoint[1]/(t.shape[1]||0),(e.endPoint[0]-e.startPoint[0])/(t.shape[2]||0),(e.endPoint[1]-e.startPoint[1])/(t.shape[1]||0)]:[0,0,0,0],x3=(e,t)=>{let n=[e.startPoint[0]*t[0],e.startPoint[1]*t[1]],o=[e.endPoint[0]*t[0],e.endPoint[1]*t[1]];return{startPoint:n,endPoint:o,landmarks:e.landmarks,confidence:e.confidence}},b5=(e,t,n)=>{let o=t.shape[1],r=t.shape[2],s=[e.startPoint[1]/o,e.startPoint[0]/r,e.endPoint[1]/o,e.endPoint[0]/r],A=Re.image.cropAndResize(t,[s],[0],n),a=Re.div(A,C.tf255);return Re.dispose(A),a},xt=(e,t)=>{let n=lt(e),o=y2(e),r=[t*o[0]/2,t*o[1]/2];return{startPoint:[n[0]-r[0],n[1]-r[1]],endPoint:[n[0]+r[0],n[1]+r[1]],landmarks:e.landmarks,confidence:e.confidence}},yt=e=>{let t=lt(e),n=y2(e),o=Math.max(...n)/2;return{startPoint:[Math.round(t[0]-o),Math.round(t[1]-o)],endPoint:[Math.round(t[0]+o),Math.round(t[1]+o)],landmarks:e.landmarks,confidence:e.confidence}},y3=e=>{let t=e.map(o=>o[0]),n=e.map(o=>o[1]);return{startPoint:[Math.min(...t),Math.min(...n)],endPoint:[Math.max(...t),Math.max(...n)],landmarks:e}},g5=[[1,0,0],[0,1,0],[0,0,1]],_s=e=>e-2*Math.PI*Math.floor((e+Math.PI)/(2*Math.PI)),$s=(e,t)=>_s(Math.PI/2-Math.atan2(-(t[1]-e[1]),t[0]-e[0]));var c3=(e,t)=>[[1,0,e],[0,1,t],[0,0,1]],o2=(e,t)=>{let n=0;for(let o=0;o{let n=[];for(let o=0;o{let n=[],o=e.length;for(let r=0;r{let n=Math.cos(e),o=Math.sin(e),r=[[n,-o,0],[o,n,0],[0,0,1]],s=c3(t[0],t[1]),A=d3(s,r),a=c3(-t[0],-t[1]);return d3(A,a)},tA=e=>{let t=[[e[0][0],e[1][0]],[e[0][1],e[1][1]]],n=[e[0][2],e[1][2]],o=[-o2(t[0],n),-o2(t[1],n)];return[t[0].concat(o[0]),t[1].concat(o[1]),[0,0,1]]},nA=(e,t)=>[o2(e,t[0]),o2(e,t[1])];function m3(e){let t=e===192?{strides:[4],anchors:[1]}:{strides:[e/16,e/8],anchors:[2,6]},n=[];for(let o=0;o[s[0]/r*(d[0]-r/2),s[1]/r*(d[1]-r/2),d[2]||0]),a=n&&n!==0&&Math.abs(n)>.2,l=a?f3(n,[0,0]):g5,c=a?A.map(d=>[...nA(d,l),d[2]]):A,x=a?tA(o):g5,i=lt(t),y=[o2(i,x[0]),o2(i,x[1])];return c.map(d=>[Math.trunc(d[0]+y[0]),Math.trunc(d[1]+y[1]),Math.trunc(d[2]||0)])}function u3(e,t,n,o){let r=t.landmarks.length>=n5.count?n5.symmetryLine:Qe.symmetryLine,s=0,A=g5,a;if(e&&R.kernels.includes("rotatewithoffset"))if(s=$s(t.landmarks[r[0]],t.landmarks[r[1]]),s&&s!==0&&Math.abs(s)>.2){let c=lt(t),x=[c[0]/n.shape[2],c[1]/n.shape[1]],i=Re.image.rotateWithOffset(n,s,0,[x[0],x[1]]);A=f3(-s,c),a=b5(t,i,[o,o]),Re.dispose(i)}else a=b5(t,n,[o,o]);else a=b5(t,n,[o,o]);return[s,A,a]}var oA=e=>{let t=e.map(o=>o[0]),n=e.map(o=>o[1]);return[Math.min(...t)+(Math.max(...t)-Math.min(...t))/2,Math.min(...n)+(Math.max(...n)-Math.min(...n))/2]},h3=(e,t)=>{let n=oA(e),o=y2(t);return{startPoint:[n[0]-o[0]/2,n[1]-o[1]/2],endPoint:[n[0]+o[0]/2,n[1]+o[1]/2]}};var b3=6,rA=1.4,ie,v5=null,Le=0,f2=null,m2=()=>Le;async function g3(e){var t;return R.initial&&(ie=null),ie?e.debug&&u("cached model:",ie.modelUrl):ie=await O((t=e.face.detector)==null?void 0:t.modelPath),Le=ie.executor&&ie.inputs[0].shape?ie.inputs[0].shape[2]:256,f2=L.scalar(Le,"int32"),v5=L.tensor2d(m3(Le)),ie}function sA(e){if(!v5||!f2)return L.zeros([0,0]);let t={};t.boxStarts=L.slice(e,[0,1],[-1,2]),t.centers=L.add(t.boxStarts,v5),t.boxSizes=L.slice(e,[0,3],[-1,2]),t.boxSizesNormalized=L.div(t.boxSizes,f2),t.centersNormalized=L.div(t.centers,f2),t.halfBoxSize=L.div(t.boxSizesNormalized,C.tf2),t.starts=L.sub(t.centersNormalized,t.halfBoxSize),t.ends=L.add(t.centersNormalized,t.halfBoxSize),t.startNormalized=L.mul(t.starts,f2),t.endNormalized=L.mul(t.ends,f2);let n=L.concat2d([t.startNormalized,t.endNormalized],1);return Object.keys(t).forEach(o=>L.dispose(t[o])),n}async function T3(e,t){var a,l,c,x;if(!e||e.isDisposedInternal||e.shape.length!==4||e.shape[1]<1||e.shape[2]<1)return[];let n={};n.resized=L.image.resizeBilinear(e,[Le,Le]),n.div=L.div(n.resized,C.tf127),n.normalized=L.sub(n.div,C.tf05);let o=ie==null?void 0:ie.execute(n.normalized);if(Array.isArray(o)&&o.length>2){let i=o.sort((y,d)=>y.size-d.size);n.concat384=L.concat([i[0],i[2]],2),n.concat512=L.concat([i[1],i[3]],2),n.concat=L.concat([n.concat512,n.concat384],1),n.batch=L.squeeze(n.concat,[0])}else Array.isArray(o)?n.batch=L.squeeze(o[0]):n.batch=L.squeeze(o);L.dispose(o),n.boxes=sA(n.batch),n.logits=L.slice(n.batch,[0,0],[-1,1]),n.sigmoid=L.sigmoid(n.logits),n.scores=L.squeeze(n.sigmoid),n.nms=await L.image.nonMaxSuppressionAsync(n.boxes,n.scores,((a=t.face.detector)==null?void 0:a.maxDetected)||0,((l=t.face.detector)==null?void 0:l.iouThreshold)||0,((c=t.face.detector)==null?void 0:c.minConfidence)||0);let r=await n.nms.array(),s=[],A=await n.scores.data();for(let i=0;i(((x=t.face.detector)==null?void 0:x.minConfidence)||0)){let d={};d.bbox=L.slice(n.boxes,[r[i],0],[1,-1]),d.slice=L.slice(n.batch,[r[i],b3-1],[1,-1]),d.squeeze=L.squeeze(d.slice),d.landmarks=L.reshape(d.squeeze,[b3,-1]);let p=await d.bbox.data(),f={startPoint:[p[0],p[1]],endPoint:[p[2],p[3]],landmarks:await d.landmarks.array(),confidence:y},b=x3(f,[(e.shape[2]||0)/Le,(e.shape[1]||0)/Le]),M=xt(b,t.face.scale||rA),T=yt(M);s.push(T),Object.keys(d).forEach(m=>L.dispose(d[m]))}}return Object.keys(n).forEach(i=>L.dispose(n[i])),s}var le=Z(H());var V0,Ce=0,AA=2.3,R5=oe.leftEyeLower0,M5=oe.rightEyeLower0,p2={leftBounds:[R5[0],R5[R5.length-1]],rightBounds:[M5[0],M5[M5.length-1]]},u2={upperCenter:3,lowerCenter:4,index:71,numCoordinates:76};async function k3(e){var t,n;return R.initial&&(V0=null),V0?e.debug&&u("cached model:",V0.modelUrl):V0=await O((t=e.face.iris)==null?void 0:t.modelPath),Ce=(V0==null?void 0:V0.executor)&&((n=V0.inputs)==null?void 0:n[0].shape)?V0.inputs[0].shape[2]:0,Ce===-1&&(Ce=64),V0}function ft(e,t,n,o){for(let r=0;r{let t=e[p2.leftBounds[0]][2],n=e[p2.rightBounds[0]][2];return t-n},R3=(e,t,n,o,r,s=!1)=>{let A=yt(xt(y3([e[n],e[o]]),AA)),a=y2(A),l=le.image.cropAndResize(t,[[A.startPoint[1]/r,A.startPoint[0]/r,A.endPoint[1]/r,A.endPoint[0]/r]],[0],[Ce,Ce]);if(s&&R.kernels.includes("flipleftright")){let c=le.image.flipLeftRight(l);le.dispose(l),l=c}return{box:A,boxSize:a,crop:l}},M3=(e,t,n,o=!1)=>{let r=[];for(let s=0;s{let o=e[oe[`${n}EyeUpper0`][u2.upperCenter]][2],r=e[oe[`${n}EyeLower0`][u2.lowerCenter]][2],s=(o+r)/2;return t.map((A,a)=>{let l=s;return a===2?l=o:a===4&&(l=r),[A[0],A[1],l]})};async function w3(e,t,n){if(!(V0!=null&&V0.executor))return e;let{box:o,boxSize:r,crop:s}=R3(e,t,p2.leftBounds[0],p2.leftBounds[1],n,!0),{box:A,boxSize:a,crop:l}=R3(e,t,p2.rightBounds[0],p2.rightBounds[1],n,!0),c=le.concat([s,l]);le.dispose(s),le.dispose(l);let x=V0.execute(c);le.dispose(c);let i=await x.data();le.dispose(x);let y=i.slice(0,u2.numCoordinates*3),{rawCoords:d,iris:p}=M3(y,o,r,!0),f=i.slice(u2.numCoordinates*3),{rawCoords:b,iris:M}=M3(f,A,a,!1),T=aA(e);Math.abs(T)<30?(ft(e,d,"left",null),ft(e,b,"right",null)):T<1?ft(e,d,"left",["EyeUpper0","EyeLower0"]):ft(e,b,"right",["EyeUpper0","EyeLower0"]);let m=P3(e,p,"left"),h=P3(e,M,"right");return e.concat(m).concat(h)}async function z3(e,t){var s,A,a,l,c,x,i,y,d,p;let n={lips:await((A=(s=t.filter(f=>f.size===160))==null?void 0:s[0])==null?void 0:A.data()),irisL:await((l=(a=t.filter(f=>f.size===10))==null?void 0:a[0])==null?void 0:l.data()),eyeL:await((x=(c=t.filter(f=>f.size===142))==null?void 0:c[0])==null?void 0:x.data()),irisR:await((y=(i=t.filter(f=>f.size===10))==null?void 0:i[1])==null?void 0:y.data()),eyeR:await((p=(d=t.filter(f=>f.size===142))==null?void 0:d[1])==null?void 0:p.data())};for(let f of Object.values(n))if(!f)return e;let o=$e.reduce((f,b)=>f+=e[b][2],0)/$e.length;for(let f=0;ff+=e[b][2],0)/e2.length;for(let f=0;fg()-ue.timestamp,o=ue.skipped<(((c=t.face.detector)==null?void 0:c.skipFrames)||0);!t.skipAllowed||!n||!o||ue.boxes.length===0?(ue.boxes=await T3(e,t),ue.timestamp=g(),ue.skipped=0):ue.skipped++;let r=[],s=[],A=0,a=C2;for(let T=0;TG.shape[G.shape.length-1]===1).data();if(P.faceScore=Math.round(100*t0[0])/100,P.faceScore<(((p=t.face.detector)==null?void 0:p.minConfidence)||1)){if(m.confidence=P.faceScore,t.face.mesh.keepInvalid){P.box=ct(m,e),P.boxRaw=dt(m,e),P.score=P.boxScore,P.mesh=m.landmarks.map(G=>[(m.startPoint[0]+m.endPoint[0])/2+(m.endPoint[0]+m.startPoint[0])*G[0]/m2(),(m.startPoint[1]+m.endPoint[1])/2+(m.endPoint[1]+m.startPoint[1])*G[1]/m2()]),P.meshRaw=P.mesh.map(G=>[G[0]/(e.shape[2]||1),G[1]/(e.shape[1]||1),(G[2]||0)/a]);for(let G of Object.keys(Qe))P.annotations[G]=[P.mesh[Qe[G]]]}}else{let G=I.find(V=>V.shape[V.shape.length-1]===1404),$=We.reshape(G,[-1,3]),A0=await $.array();We.dispose($),(f=t.face.attention)!=null&&f.enabled?A0=await z3(A0,I):(b=t.face.iris)!=null&&b.enabled&&(A0=await w3(A0,P.tensor,C2)),P.mesh=p3(A0,m,h,S,C2),P.meshRaw=P.mesh.map(V=>[V[0]/(e.shape[2]||0),V[1]/(e.shape[1]||0),(V[2]||0)/a]);for(let V of Object.keys(oe))P.annotations[V]=oe[V].map(n0=>P.mesh[n0]);P.score=P.faceScore;let v={...h3(P.mesh,m),confidence:m.confidence,landmarks:m.landmarks};P.box=ct(v,e),P.boxRaw=dt(v,e),s.push(v)}We.dispose(I)}else{P.box=ct(m,e),P.boxRaw=dt(m,e),P.score=P.boxScore,P.mesh=m.landmarks.map(I=>[(m.startPoint[0]+m.endPoint[0])/2+(m.endPoint[0]+m.startPoint[0])*I[0]/m2(),(m.startPoint[1]+m.endPoint[1])/2+(m.endPoint[1]+m.startPoint[1])*I[1]/m2()]),P.meshRaw=P.mesh.map(I=>[I[0]/(e.shape[2]||0),I[1]/(e.shape[1]||0),(I[2]||0)/a]);for(let I of Object.keys(Qe))P.annotations[I]=[P.mesh[Qe[I]]]}P.score>(((M=t.face.detector)==null?void 0:M.minConfidence)||1)?r.push(P):We.dispose(P.tensor)}return ue.boxes=s,r}async function j3(e){var t,n,o,r,s,A;return R.initial&&(r0=null),((t=e.face.attention)==null?void 0:t.enabled)&&(r0==null?void 0:r0.signature)&&Object.keys(((n=r0==null?void 0:r0.signature)==null?void 0:n.outputs)||{}).length<6&&(r0=null),r0?e.debug&&u("cached model:",r0.modelUrl):(o=e.face.attention)!=null&&o.enabled?r0=await O(e.face.attention.modelPath):r0=await O((r=e.face.mesh)==null?void 0:r.modelPath),C2=r0.executor&&((s=r0==null?void 0:r0.inputs)==null?void 0:s[0].shape)?(A=r0==null?void 0:r0.inputs)==null?void 0:A[0].shape[2]:256,r0}var N3=_e,I3=O2;var ce=Z(H());var lA=["angry","disgust","fear","happy","sad","surprise","neutral"],$0,mt=[],O3=0,L3=0,k5=Number.MAX_SAFE_INTEGER;async function C3(e){var t;return R.initial&&($0=null),$0?e.debug&&u("cached model:",$0.modelUrl):$0=await O((t=e.face.emotion)==null?void 0:t.modelPath),$0}async function w5(e,t,n,o){var A,a;if(!$0)return[];let r=k5<(((A=t.face.emotion)==null?void 0:A.skipFrames)||0),s=(((a=t.face.emotion)==null?void 0:a.skipTime)||0)>g()-L3;return t.skipAllowed&&s&&r&&O3===o&&mt[n]&&mt[n].length>0?(k5++,mt[n]):(k5=0,new Promise(async l=>{var x;let c=[];if((x=t.face.emotion)!=null&&x.enabled){let i={},y=$0!=null&&$0.inputs[0].shape?$0.inputs[0].shape[2]:0;i.resize=ce.image.resizeBilinear(e,[y,y],!1),i.channels=ce.mul(i.resize,C.rgb),i.grayscale=ce.sum(i.channels,3,!0),i.grayscaleSub=ce.sub(i.grayscale,C.tf05),i.grayscaleMul=ce.mul(i.grayscaleSub,C.tf2),i.emotion=$0==null?void 0:$0.execute(i.grayscaleMul),L3=g();let d=await i.emotion.data();for(let p=0;p(t.face.emotion.minConfidence||0)&&c.push({score:Math.min(.99,Math.trunc(100*d[p])/100),emotion:lA[p]});c.sort((p,f)=>f.score-p.score),Object.keys(i).forEach(p=>ce.dispose(i[p]))}mt[n]=c,O3=o,l(c)}))}var de=Z(H());var z0,De=[],D3=0,F3=0,E5=Number.MAX_SAFE_INTEGER;async function B3(e){var t;return R.initial&&(z0=null),z0?e.debug&&u("cached model:",z0.modelUrl):z0=await O((t=e.face.description)==null?void 0:t.modelPath),z0}function cA(e){let t=e.image||e.tensor||e;if(!(z0!=null&&z0.inputs[0].shape))return t;let n=de.image.resizeBilinear(t,[z0.inputs[0].shape[2],z0.inputs[0].shape[1]],!1),o=de.mul(n,C.tf255);return de.dispose(n),o}async function z5(e,t,n,o){var a,l,c,x;let r={age:0,gender:"unknown",genderScore:0,descriptor:[]};if(!(z0!=null&&z0.executor))return r;let s=E5<(((a=t.face.description)==null?void 0:a.skipFrames)||0),A=(((l=t.face.description)==null?void 0:l.skipTime)||0)>g()-D3;return t.skipAllowed&&s&&A&&F3===o&&((c=De==null?void 0:De[n])==null?void 0:c.age)>0&&((x=De==null?void 0:De[n])==null?void 0:x.genderScore)>0?(E5++,De[n]):(E5=0,new Promise(async i=>{var y;if((y=t.face.description)!=null&&y.enabled){let d=cA(e),p=z0==null?void 0:z0.execute(d);D3=g(),de.dispose(d);let b=await p.find(q=>q.shape[1]===1).data(),M=Math.trunc(200*Math.abs(b[0]-.5))/100;M>(t.face.description.minConfidence||0)&&(r.gender=b[0]<=.5?"female":"male",r.genderScore=Math.min(.99,M));let T=de.argMax(p.find(q=>q.shape[1]===100),1),m=(await T.data())[0];de.dispose(T);let S=await p.find(q=>q.shape[1]===100).data();r.age=Math.round(S[m-1]>S[m+1]?10*m-100*S[m-1]:10*m+100*S[m+1])/10,(Number.isNaN(b[0])||Number.isNaN(S[0]))&&u("faceres error:",{model:z0,result:p});let P=p.find(q=>q.shape[1]===1024),I=P?await P.data():[];r.descriptor=Array.from(I),p.forEach(q=>de.dispose(q))}De[n]=r,F3=o,i(r)}))}var h2=.1,S5=.5;function dA(e,t,n){let o=!1,r=n.length-1;for(let s=0;st!=n[r].y>t&&e<(n[r].x-n[s].x)*(t-n[s].y)/(n[r].y-n[s].y)+n[s].x&&(o=!o);return o}async function G3(e){if(!e.tensor||!e.mesh||e.mesh.length<100)return e.tensor;let t=e.tensor.shape[2]||0,n=e.tensor.shape[1]||0,o=await e.tensor.buffer(),r=[];for(let A of oe.silhouette)r.push({x:(e.mesh[A][0]-e.box[0])/e.box[2],y:(e.mesh[A][1]-e.box[1])/e.box[3]});h2&&h2>0&&(r=r.map(A=>({x:A.x>.5?A.x+h2:A.x-h2,y:A.y>.5?A.y+h2:A.y-h2})));for(let A=0;Ag()-Z3,s=j5<(((a=t.face.antispoof)==null?void 0:a.skipFrames)||0);return t.skipAllowed&&r&&s&&V3===o&&pt[n]?(j5++,pt[n]):(j5=0,new Promise(async l=>{let c=ut.image.resizeBilinear(e,[M0!=null&&M0.inputs[0].shape?M0.inputs[0].shape[2]:0,M0!=null&&M0.inputs[0].shape?M0.inputs[0].shape[1]:0],!1),x=M0==null?void 0:M0.execute(c),i=(await x.data())[0];pt[n]=Math.round(100*i)/100,V3=o,Z3=g(),ut.dispose([c,x]),l(pt[n])}))}var bt=Z(H());var P0,ht=[],I5=Number.MAX_SAFE_INTEGER,U3=0,Y3=0;async function K3(e){var t;return R.initial&&(P0=null),P0?e.debug&&u("cached model:",P0.modelUrl):P0=await O((t=e.face.liveness)==null?void 0:t.modelPath),P0}async function O5(e,t,n,o){var A,a;if(!(P0!=null&&P0.executor))return 0;let r=(((A=t.face.liveness)==null?void 0:A.skipTime)||0)>g()-Y3,s=I5<(((a=t.face.liveness)==null?void 0:a.skipFrames)||0);return t.skipAllowed&&r&&s&&U3===o&&ht[n]?(I5++,ht[n]):(I5=0,new Promise(async l=>{let c=bt.image.resizeBilinear(e,[P0!=null&&P0.inputs[0].shape?P0.inputs[0].shape[2]:0,P0!=null&&P0.inputs[0].shape?P0.inputs[0].shape[1]:0],!1),x=P0==null?void 0:P0.execute(c),i=(await x.data())[0];ht[n]=Math.round(100*i)/100,U3=o,Y3=g(),bt.dispose([c,x]),l(ht[n])}))}var gt=Z(H());var re,L5=[],yA=["white","black","asian","indian","other"],fA=[15,23,28,35.5,45.5,55.5,65],Q3=0,_3=0,C5=Number.MAX_SAFE_INTEGER;async function $3(e){var t;return R.initial&&(re=null),re?e.debug&&u("cached model:",re.modelUrl):re=await O((t=e.face.gear)==null?void 0:t.modelPath),re}async function W5(e,t,n,o){var A,a;if(!re)return{age:0,gender:"unknown",genderScore:0,race:[]};let r=C5<(((A=t.face.gear)==null?void 0:A.skipFrames)||0),s=(((a=t.face.gear)==null?void 0:a.skipTime)||0)>g()-_3;return t.skipAllowed&&s&&r&&Q3===o&&L5[n]?(C5++,L5[n]):(C5=0,new Promise(async l=>{var M,T;if(!(re!=null&&re.inputs[0].shape))return;let c={},x=[[0,.1,.9,.9]];c.resize=gt.image.cropAndResize(e,x,[0],[re.inputs[0].shape[2],re.inputs[0].shape[1]]);let i={age:0,gender:"unknown",genderScore:0,race:[]};(M=t.face.gear)!=null&&M.enabled&&([c.age,c.gender,c.race]=re.execute(c.resize,["age_output","gender_output","race_output"]));let y=await c.gender.data();i.gender=y[0]>y[1]?"male":"female",i.genderScore=Math.round(100*(y[0]>y[1]?y[0]:y[1]))/100;let d=await c.race.data();for(let m=0;m(((T=t.face.gear)==null?void 0:T.minConfidence)||.2)&&i.race.push({score:Math.round(100*d[m])/100,race:yA[m]});i.race.sort((m,h)=>h.score-m.score);let f=Array.from(await c.age.data()).map((m,h)=>[fA[h],m]).sort((m,h)=>h[1]-m[1]),b=f[0][0];for(let m=1;mgt.dispose(c[m])),L5[n]=i,Q3=o,_3=g(),l(i)}))}var b2=Z(H());var Z0,Tt=[],tn=0,nn=0,D5=Number.MAX_SAFE_INTEGER;async function on(e){return R.initial&&(Z0=null),Z0?e.debug&&u("cached model:",Z0.modelUrl):Z0=await O(e.face.ssrnet.modelPathAge),Z0}async function F5(e,t,n,o){var A,a,l,c;if(!Z0)return{age:0};let r=D5<(((A=t.face.ssrnet)==null?void 0:A.skipFrames)||0),s=(((a=t.face.ssrnet)==null?void 0:a.skipTime)||0)>g()-nn;return t.skipAllowed&&r&&s&&tn===o&&((l=Tt[n])==null?void 0:l.age)&&((c=Tt[n])==null?void 0:c.age)>0?(D5++,Tt[n]):(D5=0,new Promise(async x=>{var d;if(!(Z0!=null&&Z0.inputs)||!Z0.inputs[0]||!Z0.inputs[0].shape)return;let i={};i.resize=b2.image.resizeBilinear(e,[Z0.inputs[0].shape[2],Z0.inputs[0].shape[1]],!1),i.enhance=b2.mul(i.resize,C.tf255);let y={age:0};if((d=t.face.ssrnet)!=null&&d.enabled&&(i.age=Z0.execute(i.enhance)),i.age){let p=await i.age.data();y.age=Math.trunc(10*p[0])/10}Object.keys(i).forEach(p=>b2.dispose(i[p])),Tt[n]=y,tn=o,nn=g(),x(y)}))}var S0=Z(H());var se,vt=[],sn=0,An=0,B5=Number.MAX_SAFE_INTEGER,H5=[.2989,.587,.114];async function an(e){var t;return R.initial&&(se=null),se?e.debug&&u("cached model:",se.modelUrl):se=await O((t=e.face.ssrnet)==null?void 0:t.modelPathGender),se}async function G5(e,t,n,o){var A,a,l,c;if(!se)return{gender:"unknown",genderScore:0};let r=B5<(((A=t.face.ssrnet)==null?void 0:A.skipFrames)||0),s=(((a=t.face.ssrnet)==null?void 0:a.skipTime)||0)>g()-An;return t.skipAllowed&&r&&s&&sn===o&&((l=vt[n])==null?void 0:l.gender)&&((c=vt[n])==null?void 0:c.genderScore)>0?(B5++,vt[n]):(B5=0,new Promise(async x=>{var p;if(!(se!=null&&se.inputs[0].shape))return;let i={};i.resize=S0.image.resizeBilinear(e,[se.inputs[0].shape[2],se.inputs[0].shape[1]],!1),i.enhance=S0.tidy(()=>{let[f,b,M]=S0.split(i.resize,3,3),T=S0.mul(f,H5[0]),m=S0.mul(b,H5[1]),h=S0.mul(M,H5[2]),S=S0.addN([T,m,h]);return S0.mul(S0.sub(S,C.tf05),2)});let y={gender:"unknown",genderScore:0};(p=t.face.ssrnet)!=null&&p.enabled&&(i.gender=se.execute(i.enhance));let d=await i.gender.data();y.gender=d[0]>d[1]?"female":"male",y.genderScore=d[0]>d[1]?Math.trunc(100*d[0])/100:Math.trunc(100*d[1])/100,Object.keys(i).forEach(f=>S0.dispose(i[f])),vt[n]=y,sn=o,An=g(),x(y)}))}var Rt=Z(H());var X0,V5=[],cn=0,dn=0,xn=Number.MAX_SAFE_INTEGER;async function yn(e){var t;return R.initial&&(X0=null),X0?e.debug&&u("cached model:",X0.modelUrl):X0=await O((t=e.face.mobilefacenet)==null?void 0:t.modelPath),X0}async function Z5(e,t,n,o){var A,a;if(!(X0!=null&&X0.executor))return[];let r=xn<(((A=t.face.mobilefacenet)==null?void 0:A.skipFrames)||0),s=(((a=t.face.mobilefacenet)==null?void 0:a.skipTime)||0)>g()-dn;return t.skipAllowed&&s&&r&&cn===o&&V5[n]?(xn++,V5[n]):new Promise(async l=>{var x;let c=[];if(((x=t.face.mobilefacenet)==null?void 0:x.enabled)&&(X0==null?void 0:X0.inputs[0].shape)){let i={};i.crop=Rt.image.resizeBilinear(e,[X0.inputs[0].shape[2],X0.inputs[0].shape[1]],!1),i.data=X0.execute(i.crop);let y=await i.data.data();c=Array.from(y),Object.keys(i).forEach(d=>Rt.dispose(i[d]))}V5[n]=c,cn=o,dn=g(),l(c)})}var Mt=Z(H());var q0,X5=[],mn=0,pn=0,un=Number.MAX_SAFE_INTEGER;async function hn(e){return R.initial&&(q0=null),q0?e.debug&&u("cached model:",q0.modelUrl):q0=await O(e.face.insightface.modelPath),q0}async function q5(e,t,n,o){var A,a;if(!(q0!=null&&q0.executor))return[];let r=un<(((A=t.face.insightface)==null?void 0:A.skipFrames)||0),s=(((a=t.face.insightface)==null?void 0:a.skipTime)||0)>g()-pn;return t.skipAllowed&&s&&r&&mn===o&&X5[n]?(un++,X5[n]):new Promise(async l=>{var x;let c=[];if(((x=t.face.insightface)==null?void 0:x.enabled)&&(q0==null?void 0:q0.inputs[0].shape)){let i={};i.crop=Mt.image.resizeBilinear(e,[q0.inputs[0].shape[2],q0.inputs[0].shape[1]],!1),i.data=q0.execute(i.crop);let y=await i.data.data();c=Array.from(y),Object.keys(i).forEach(d=>Mt.dispose(i[d]))}X5[n]=c,mn=o,pn=g(),l(c)})}var mA=e=>{let t=(i,y)=>Math.atan2(i[1]-y[1],i[0]-y[0]);if(!e.annotations.rightEyeIris||!e.annotations.leftEyeIris)return{bearing:0,strength:0};let n=[0,-.1],o=1,r=(e.mesh[33][2]||0)>(e.mesh[263][2]||0),s=r?e.mesh[473]:e.mesh[468],A=r?[(e.mesh[133][0]+e.mesh[33][0])/2,(e.mesh[133][1]+e.mesh[33][1])/2]:[(e.mesh[263][0]+e.mesh[362][0])/2,(e.mesh[263][1]+e.mesh[362][1])/2],a=r?[e.mesh[133][0]-e.mesh[33][0],e.mesh[23][1]-e.mesh[27][1]]:[e.mesh[263][0]-e.mesh[362][0],e.mesh[253][1]-e.mesh[257][1]],l=[(A[0]-s[0])/a[0]-n[0],o*(s[1]-A[1])/a[1]-n[1]],c=Math.sqrt(l[0]*l[0]+l[1]*l[1]);return c=Math.min(c,e.boxRaw[2]/2,e.boxRaw[3]/2),{bearing:(t([0,0],l)+Math.PI/2)%Math.PI,strength:c}},gn=(e,t)=>{let n=f=>{let b=Math.sqrt(f[0]*f[0]+f[1]*f[1]+f[2]*f[2]);return f[0]/=b,f[1]/=b,f[2]/=b,f},o=(f,b)=>{let M=f[0]-b[0],T=f[1]-b[1],m=f[2]-b[2];return[M,T,m]},r=(f,b)=>{let M=f[1]*b[2]-f[2]*b[1],T=f[2]*b[0]-f[0]*b[2],m=f[0]*b[1]-f[1]*b[0];return[M,T,m]},s=f=>{let[b,M,T,m,h,S,P,I,q]=f,t0,G,$;return m<1?m>-1?($=Math.asin(m),G=Math.atan2(-P,b),t0=Math.atan2(-S,h)):($=-Math.PI/2,G=-Math.atan2(I,q),t0=0):($=Math.PI/2,G=Math.atan2(I,q),t0=0),Number.isNaN(t0)&&(t0=0),Number.isNaN(G)&&(G=0),Number.isNaN($)&&($=0),{pitch:2*-t0,yaw:2*-G,roll:2*-$}},A=e.meshRaw;if(!A||A.length<300)return{angle:{pitch:0,yaw:0,roll:0},matrix:[1,0,0,0,1,0,0,0,1],gaze:{bearing:0,strength:0}};let a=Math.max(e.boxRaw[2]*t[0],e.boxRaw[3]*t[1])/1.5,l=[A[10],A[152],A[234],A[454]].map(f=>[f[0]*t[0]/a,f[1]*t[1]/a,f[2]]),c=n(o(l[1],l[0])),x=n(o(l[3],l[2])),i=n(r(x,c));x=r(c,i);let y=[x[0],x[1],x[2],c[0],c[1],c[2],i[0],i[1],i[2]],d=s(y),p=A.length===478?mA(e):{bearing:0,strength:0};return{angle:d,matrix:y,gaze:p}};function Tn(e,t){let n=e==null?void 0:e.annotations;if(!n)return 0;let o=Math.max(Math.abs(n.leftEyeIris[3][0]-n.leftEyeIris[1][0]),Math.abs(n.rightEyeIris[3][0]-n.rightEyeIris[1][0]))/t;return Math.round(1.17/o)/100}var U5=async(e,t)=>{var p,f,b,M,T,m,h,S,P,I,q,t0,G,$,A0,v,V,n0,U,g0,m0,B,X;let n=g(),o,r,s,A,a,l,c,x,i,y=[];e.state="run:face";let d=await S3(t,e.config);if(e.performance.face=R.perfadd?(e.performance.face||0)+Math.trunc(g()-n):Math.trunc(g()-n),!t.shape||t.shape.length!==4)return[];if(!d)return[];for(let z=0;z200?gn(d[z],[t.shape[2],t.shape[1]]):null;e.analyze("Start Emotion:"),e.config.async?A=(f=e.config.face.emotion)!=null&&f.enabled?w5(d[z].tensor||l0.tensor([]),e.config,z,d.length):[]:(e.state="run:emotion",n=g(),A=(b=e.config.face.emotion)!=null&&b.enabled?await w5(d[z].tensor||l0.tensor([]),e.config,z,d.length):[],e.performance.emotion=R.perfadd?(e.performance.emotion||0)+Math.trunc(g()-n):Math.trunc(g()-n)),e.analyze("End Emotion:"),e.analyze("Start AntiSpoof:"),e.config.async?c=(M=e.config.face.antispoof)!=null&&M.enabled?N5(d[z].tensor||l0.tensor([]),e.config,z,d.length):0:(e.state="run:antispoof",n=g(),c=(T=e.config.face.antispoof)!=null&&T.enabled?await N5(d[z].tensor||l0.tensor([]),e.config,z,d.length):0,e.performance.antispoof=R.perfadd?(e.performance.antispoof||0)+Math.trunc(g()-n):Math.trunc(g()-n)),e.analyze("End AntiSpoof:"),e.analyze("Start Liveness:"),e.config.async?x=(m=e.config.face.liveness)!=null&&m.enabled?O5(d[z].tensor||l0.tensor([]),e.config,z,d.length):0:(e.state="run:liveness",n=g(),x=(h=e.config.face.liveness)!=null&&h.enabled?await O5(d[z].tensor||l0.tensor([]),e.config,z,d.length):0,e.performance.liveness=R.perfadd?(e.performance.antispoof||0)+Math.trunc(g()-n):Math.trunc(g()-n)),e.analyze("End Liveness:"),e.analyze("Start GEAR:"),e.config.async?r=(S=e.config.face.gear)!=null&&S.enabled?W5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null:(e.state="run:gear",n=g(),r=(P=e.config.face.gear)!=null&&P.enabled?await W5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,e.performance.gear=Math.trunc(g()-n)),e.analyze("End GEAR:"),e.analyze("Start SSRNet:"),e.config.async?(o=(I=e.config.face.ssrnet)!=null&&I.enabled?F5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,s=(q=e.config.face.ssrnet)!=null&&q.enabled?G5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null):(e.state="run:ssrnet",n=g(),o=(t0=e.config.face.ssrnet)!=null&&t0.enabled?await F5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,s=(G=e.config.face.ssrnet)!=null&&G.enabled?await G5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,e.performance.ssrnet=Math.trunc(g()-n)),e.analyze("End SSRNet:"),e.analyze("Start MobileFaceNet:"),e.config.async?a=($=e.config.face.mobilefacenet)!=null&&$.enabled?Z5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null:(e.state="run:mobilefacenet",n=g(),a=(A0=e.config.face.mobilefacenet)!=null&&A0.enabled?await Z5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,e.performance.mobilefacenet=Math.trunc(g()-n)),e.analyze("End MobileFaceNet:"),e.analyze("Start InsightFace:"),e.config.async?l=(v=e.config.face.insightface)!=null&&v.enabled?q5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null:(e.state="run:mobilefacenet",n=g(),l=(V=e.config.face.insightface)!=null&&V.enabled?await q5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,e.performance.mobilefacenet=Math.trunc(g()-n)),e.analyze("End InsightFace:"),e.analyze("Start Description:"),e.config.async?i=z5(d[z].tensor||l0.tensor([]),e.config,z,d.length):(e.state="run:description",n=g(),i=await z5(d[z].tensor||l0.tensor([]),e.config,z,d.length),e.performance.description=R.perfadd?(e.performance.description||0)+Math.trunc(g()-n):Math.trunc(g()-n)),e.analyze("End Description:"),e.config.async&&([o,s,A,a,l,i,r,c,x]=await Promise.all([o,s,A,a,l,i,r,c,x])),e.analyze("Finish Face:"),((n0=e.config.face.ssrnet)==null?void 0:n0.enabled)&&o&&s&&(i={...i,age:o.age,gender:s.gender,genderScore:s.genderScore}),((U=e.config.face.gear)==null?void 0:U.enabled)&&r&&(i={...i,age:r.age,gender:r.gender,genderScore:r.genderScore,race:r.race}),((g0=e.config.face.mobilefacenet)==null?void 0:g0.enabled)&&a&&(i.descriptor=a),((m0=e.config.face.insightface)==null?void 0:m0.enabled)&&l&&(i.descriptor=l);let we=(B=e.config.face.iris)!=null&&B.enabled?Tn(d[z],t.shape[2]):0,Ee=(X=e.config.face.detector)!=null&&X.return?l0.squeeze(d[z].tensor):null;l0.dispose(d[z].tensor),d[z].tensor&&delete d[z].tensor;let T0={...d[z],id:z};i.age&&(T0.age=i.age),i.gender&&(T0.gender=i.gender),i.genderScore&&(T0.genderScore=i.genderScore),i.descriptor&&(T0.embedding=i.descriptor),i.race&&(T0.race=i.race),A&&(T0.emotion=A),c&&(T0.real=c),x&&(T0.live=x),we>0&&(T0.distance=we),ee&&(T0.rotation=ee),Ee&&(T0.tensor=Ee),y.push(T0),e.analyze("End Face")}return e.analyze("End FaceMesh:"),e.config.async&&(e.performance.face&&delete e.performance.face,e.performance.age&&delete e.performance.age,e.performance.gender&&delete e.performance.gender,e.performance.emotion&&delete e.performance.emotion),y};var W0={thumb:0,index:1,middle:2,ring:3,pinky:4,all:[0,1,2,3,4],nameMapping:{0:"thumb",1:"index",2:"middle",3:"ring",4:"pinky"},pointsMapping:{0:[[0,1],[1,2],[2,3],[3,4]],1:[[0,5],[5,6],[6,7],[7,8]],2:[[0,9],[9,10],[10,11],[11,12]],3:[[0,13],[13,14],[14,15],[15,16]],4:[[0,17],[17,18],[18,19],[19,20]]},getName:e=>W0.nameMapping[e],getPoints:e=>W0.pointsMapping[e]},Be={none:0,half:1,full:2,nameMapping:{0:"none",1:"half",2:"full"},getName:e=>Be.nameMapping[e]},c0={verticalUp:0,verticalDown:1,horizontalLeft:2,horizontalRight:3,diagonalUpRight:4,diagonalUpLeft:5,diagonalDownRight:6,diagonalDownLeft:7,nameMapping:{0:"verticalUp",1:"verticalDown",2:"horizontalLeft",3:"horizontalRight",4:"diagonalUpRight",5:"diagonalUpLeft",6:"diagonalDownRight",7:"diagonalDownLeft"},getName:e=>c0.nameMapping[e]},Fe=class{constructor(t){k(this,"name");k(this,"curls");k(this,"directions");k(this,"weights");k(this,"weightsRelative");this.name=t,this.curls={},this.directions={},this.weights=[1,1,1,1,1],this.weightsRelative=[1,1,1,1,1]}curl(t,n,o){typeof this.curls[t]=="undefined"&&(this.curls[t]=[]),this.curls[t].push([n,o])}direction(t,n,o){this.directions[t]||(this.directions[t]=[]),this.directions[t].push([n,o])}weight(t,n){this.weights[t]=n;let o=this.weights.reduce((r,s)=>r+s,0);this.weightsRelative=this.weights.map(r=>r*5/o)}matchAgainst(t,n){let o=0;for(let r in t){let s=t[r],A=this.curls[r];if(typeof A=="undefined"){o+=this.weightsRelative[r];continue}for(let[a,l]of A)if(s===a){o+=l*this.weightsRelative[r];break}}for(let r in n){let s=n[r],A=this.directions[r];if(typeof A=="undefined"){o+=this.weightsRelative[r];continue}for(let[a,l]of A)if(s===a){o+=l*this.weightsRelative[r];break}}return o/10}};var{thumb:xe,index:Me,middle:Pe,ring:r2,pinky:s2}=W0,{none:ye,half:uA,full:fe}=Be,{verticalUp:g2,verticalDown:G7,horizontalLeft:Y5,horizontalRight:hA,diagonalUpRight:bA,diagonalUpLeft:T2,diagonalDownRight:V7,diagonalDownLeft:Z7}=c0,He=new Fe("thumbs up");He.curl(xe,ye,1);He.direction(xe,g2,1);He.direction(xe,T2,.25);He.direction(xe,bA,.25);for(let e of[W0.index,W0.middle,W0.ring,W0.pinky])He.curl(e,fe,1),He.direction(e,Y5,1),He.direction(e,hA,1);var u0=new Fe("victory");u0.curl(xe,uA,.5);u0.curl(xe,ye,.5);u0.direction(xe,g2,1);u0.direction(xe,T2,1);u0.curl(Me,ye,1);u0.direction(Me,g2,.75);u0.direction(Me,T2,1);u0.curl(Pe,ye,1);u0.direction(Pe,g2,1);u0.direction(Pe,T2,.75);u0.curl(r2,fe,1);u0.direction(r2,g2,.2);u0.direction(r2,T2,1);u0.direction(r2,Y5,.2);u0.curl(s2,fe,1);u0.direction(s2,g2,.2);u0.direction(s2,T2,1);u0.direction(s2,Y5,.2);u0.weight(Me,2);u0.weight(Pe,2);var Ge=new Fe("point");Ge.curl(xe,fe,1);Ge.curl(Me,ye,.5);Ge.curl(Pe,fe,.5);Ge.curl(r2,fe,.5);Ge.curl(s2,fe,.5);Ge.weight(Me,2);Ge.weight(Pe,2);var Ve=new Fe("middle finger");Ve.curl(xe,ye,1);Ve.curl(Me,fe,.5);Ve.curl(Pe,fe,.5);Ve.curl(r2,fe,.5);Ve.curl(s2,fe,.5);Ve.weight(Me,2);Ve.weight(Pe,2);var v2=new Fe("open palm");v2.curl(xe,ye,.75);v2.curl(Me,ye,.75);v2.curl(Pe,ye,.75);v2.curl(r2,ye,.75);v2.curl(s2,ye,.75);var vn=[He,u0,Ge,Ve,v2];var gA=.7,A2={HALF_CURL_START_LIMIT:60,NO_CURL_START_LIMIT:130,DISTANCE_VOTE_POWER:1.1,SINGLE_ANGLE_VOTE_POWER:.9,TOTAL_ANGLE_VOTE_POWER:1.6};function Rn(e,t,n,o){let r=(t-o)/(e-n),s=Math.atan(r)*180/Math.PI;return s<=0?s=-s:s>0&&(s=180-s),s}function Pn(e,t){if(!e||!t)return[0,0];let n=Rn(e[0],e[1],t[0],t[1]);if(e.length===2)return n;let o=Rn(e[1],e[2],t[1],t[2]);return[n,o]}function Mn(e,t=1){let n=0,o=0,r=0;return e>=75&&e<=105?n=1*t:e>=25&&e<=155?o=1*t:r=1*t,[n,o,r]}function TA(e,t,n){let o=e[0]-t[0],r=e[0]-n[0],s=t[0]-n[0],A=e[1]-t[1],a=e[1]-n[1],l=t[1]-n[1],c=e[2]-t[2],x=e[2]-n[2],i=t[2]-n[2],y=Math.sqrt(o*o+A*A+c*c),d=Math.sqrt(r*r+a*a+x*x),p=Math.sqrt(s*s+l*l+i*i),f=(p*p+y*y-d*d)/(2*p*y);f>1?f=1:f<-1&&(f=-1);let b=Math.acos(f);b=57.2958*b%180;let M;return b>A2.NO_CURL_START_LIMIT?M=Be.none:b>A2.HALF_CURL_START_LIMIT?M=Be.half:M=Be.full,M}function kn(e,t,n,o){let r;return o===Math.abs(e)?e>0?r=c0.horizontalLeft:r=c0.horizontalRight:o===Math.abs(t)?t>0?r=c0.horizontalLeft:r=c0.horizontalRight:n>0?r=c0.horizontalLeft:r=c0.horizontalRight,r}function wn(e,t,n,o){let r;return o===Math.abs(e)?e<0?r=c0.verticalDown:r=c0.verticalUp:o===Math.abs(t)?t<0?r=c0.verticalDown:r=c0.verticalUp:n<0?r=c0.verticalDown:r=c0.verticalUp,r}function vA(e,t,n,o,r,s,A,a){let l,c=wn(e,t,n,o),x=kn(r,s,A,a);return c===c0.verticalUp?x===c0.horizontalLeft?l=c0.diagonalUpLeft:l=c0.diagonalUpRight:x===c0.horizontalLeft?l=c0.diagonalDownLeft:l=c0.diagonalDownRight,l}function RA(e,t,n,o){let r=e[0]-t[0],s=e[0]-n[0],A=t[0]-n[0],a=e[1]-t[1],l=e[1]-n[1],c=t[1]-n[1],x=Math.max(Math.abs(r),Math.abs(s),Math.abs(A)),i=Math.max(Math.abs(a),Math.abs(l),Math.abs(c)),y=0,d=0,p=0,f=i/(x+1e-5);f>1.5?y+=A2.DISTANCE_VOTE_POWER:f>.66?d+=A2.DISTANCE_VOTE_POWER:p+=A2.DISTANCE_VOTE_POWER;let b=Math.sqrt(r*r+a*a),M=Math.sqrt(s*s+l*l),T=Math.sqrt(A*A+c*c),m=Math.max(b,M,T),h=e[0],S=e[1],P=n[0],I=n[1];m===b?(P=n[0],I=n[1]):m===T&&(h=t[0],S=t[1]);let G=Pn([h,S],[P,I]),$=Mn(G,A2.TOTAL_ANGLE_VOTE_POWER);y+=$[0],d+=$[1],p+=$[2];for(let v of o){let V=Mn(v,A2.SINGLE_ANGLE_VOTE_POWER);y+=V[0],d+=V[1],p+=V[2]}let A0;return y===Math.max(y,d,p)?A0=wn(l,a,c,i):p===Math.max(d,p)?A0=kn(s,r,A,x):A0=vA(l,a,c,i,s,r,A,x),A0}function En(e){let t=[],n=[],o=[],r=[];if(!e)return{curls:o,directions:r};for(let s of W0.all){let A=W0.getPoints(s),a=[],l=[];for(let c of A){let x=e[c[0]],i=e[c[1]],y=Pn(x,i),d=y[0],p=y[1];a.push(d),l.push(p)}t.push(a),n.push(l)}for(let s of W0.all){let A=s===W0.thumb?1:0,a=W0.getPoints(s),l=e[a[A][0]],c=e[a[A+1][1]],x=e[a[3][1]],i=TA(l,c,x),y=RA(l,c,x,t[s].slice(A));o[s]=i,r[s]=y}return{curls:o,directions:r}}function Pt(e){if(!e||e.length===0)return null;let t=En(e),n={};for(let o of W0.all)n[W0.getName(o)]={curl:Be.getName(t.curls[o]),direction:c0.getName(t.directions[o])};return n}function zn(e){let t=[];if(!e||e.length===0)return t;let n=En(e);for(let o of vn){let r=o.matchAgainst(n.curls,n.directions);r>=gA&&t.push({name:o.name,confidence:r})}return t}var Sn=e=>{if(!e)return[];let t=[];for(let n=0;nl.part==="leftWrist"),r=e[n].keypoints.find(l=>l.part==="rightWrist"),s=e[n].keypoints.find(l=>l.part==="nose");s&&o&&r&&o.position[1]l.part==="leftShoulder"),a=e[n].keypoints.find(l=>l.part==="rightShoulder");A&&a&&Math.abs(A.positionRaw[1]-a.positionRaw[1])>.1&&t.push({body:n,gesture:`leaning ${A.position[1]>a.position[1]?"left":"right"}`})}return t},jn=e=>{if(!e)return[];let t=[];for(let n=0;n450){let o=(e[n].mesh[33][2]||0)-(e[n].mesh[263][2]||0),r=e[n].mesh[33][0]-e[n].mesh[263][0];Math.abs(o/r)<=.15?t.push({face:n,gesture:"facing center"}):t.push({face:n,gesture:`facing ${o<0?"left":"right"}`}),Math.abs(e[n].mesh[374][1]-e[n].mesh[386][1])/Math.abs(e[n].mesh[443][1]-e[n].mesh[450][1])<.2&&t.push({face:n,gesture:"blink left eye"}),Math.abs(e[n].mesh[145][1]-e[n].mesh[159][1])/Math.abs(e[n].mesh[223][1]-e[n].mesh[230][1])<.2&&t.push({face:n,gesture:"blink right eye"});let a=Math.min(100,500*Math.abs(e[n].mesh[13][1]-e[n].mesh[14][1])/Math.abs(e[n].mesh[10][1]-e[n].mesh[152][1]));a>10&&t.push({face:n,gesture:`mouth ${Math.trunc(a)}% open`});let l=e[n].mesh[152][2]||0;Math.abs(l)>10&&t.push({face:n,gesture:`head ${l<0?"up":"down"}`})}return t},Nn=e=>{var n,o,r,s;if(!e)return[];let t=[];for(let A=0;A.06||b>.06)&&(d=!1),f>b?f>.05&&t.push({iris:A,gesture:"looking right"}):b>.05&&t.push({iris:A,gesture:"looking left"});let M=Math.abs(e[A].mesh[145][1]-e[A].annotations.rightEyeIris[0][1])/e[A].box[3],T=Math.abs(e[A].mesh[374][1]-e[A].annotations.leftEyeIris[0][1])/e[A].box[3];(T<.01||M<.01||T>.022||M>.022)&&(d=!1),(T<.01||M<.01)&&t.push({iris:A,gesture:"looking down"}),(T>.022||M>.022)&&t.push({iris:A,gesture:"looking up"}),d&&t.push({iris:A,gesture:"looking center"})}return t},In=e=>{if(!e)return[];let t=[];for(let n=0;n0){let r=o.reduce((A,a)=>(A.position[2]||0)<(a.position[2]||0)?A:a);t.push({hand:n,gesture:`${r.name} forward`});let s=o.reduce((A,a)=>A.position[1][s[0]*t[0],s[1]*t[1]]);return{startPoint:n,endPoint:o,palmLandmarks:r,confidence:e.confidence}}function wt(e,t=1.5){let n=W2(e),o=kt(e),r=[t*o[0]/2,t*o[1]/2],s=[n[0]-r[0],n[1]-r[1]],A=[n[0]+r[0],n[1]+r[1]];return{startPoint:s,endPoint:A,palmLandmarks:e.palmLandmarks}}function Et(e){let t=W2(e),n=kt(e),r=Math.max(...n)/2,s=[t[0]-r,t[1]-r],A=[t[0]+r,t[1]+r];return{startPoint:s,endPoint:A,palmLandmarks:e.palmLandmarks}}function PA(e){return e-2*Math.PI*Math.floor((e+Math.PI)/(2*Math.PI))}function Fn(e,t){let n=Math.PI/2-Math.atan2(-(t[1]-e[1]),t[0]-e[0]);return PA(n)}var On=(e,t)=>[[1,0,e],[0,1,t],[0,0,1]];function Ze(e,t){let n=0;for(let o=0;o[A.x,A.y]),this.anchorsTensor=W.tensor2d(this.anchors),this.inputSize=((s=(r=(o=(n=this==null?void 0:this.model)==null?void 0:n.inputs)==null?void 0:o[0])==null?void 0:r.shape)==null?void 0:s[2])||0,this.inputSizeTensor=W.tensor1d([this.inputSize,this.inputSize]),this.doubleInputSizeTensor=W.tensor1d([this.inputSize*2,this.inputSize*2])}normalizeBoxes(t){let n={};n.boxOffsets=W.slice(t,[0,0],[-1,2]),n.boxSizes=W.slice(t,[0,2],[-1,2]),n.div=W.div(n.boxOffsets,this.inputSizeTensor),n.boxCenterPoints=W.add(n.div,this.anchorsTensor),n.halfBoxSizes=W.div(n.boxSizes,this.doubleInputSizeTensor),n.sub=W.sub(n.boxCenterPoints,n.halfBoxSizes),n.startPoints=W.mul(n.sub,this.inputSizeTensor),n.add=W.add(n.boxCenterPoints,n.halfBoxSizes),n.endPoints=W.mul(n.add,this.inputSizeTensor);let o=W.concat2d([n.startPoints,n.endPoints],1);return Object.keys(n).forEach(r=>W.dispose(n[r])),o}normalizeLandmarks(t,n){let o={};o.reshape=W.reshape(t,[-1,7,2]),o.div=W.div(o.reshape,this.inputSizeTensor),o.landmarks=W.add(o.div,this.anchors[n]?this.anchors[n]:0);let r=W.mul(o.landmarks,this.inputSizeTensor);return Object.keys(o).forEach(s=>W.dispose(o[s])),r}async predict(t,n){var a;let o={};o.resize=W.image.resizeBilinear(t,[this.inputSize,this.inputSize]),o.div=W.div(o.resize,C.tf127),o.image=W.sub(o.div,C.tf1),o.batched=this.model.execute(o.image),o.predictions=W.squeeze(o.batched),o.slice=W.slice(o.predictions,[0,0],[-1,1]),o.sigmoid=W.sigmoid(o.slice),o.scores=W.squeeze(o.sigmoid);let r=await o.scores.data();o.boxes=W.slice(o.predictions,[0,1],[-1,4]),o.norm=this.normalizeBoxes(o.boxes),o.nms=await W.image.nonMaxSuppressionAsync(o.norm,o.scores,3*(((a=n.hand)==null?void 0:a.maxDetected)||1),n.hand.iouThreshold,n.hand.minConfidence);let s=await o.nms.array(),A=[];for(let l of s){let c={};c.box=W.slice(o.norm,[l,0],[1,-1]),c.slice=W.slice(o.predictions,[l,5],[1,14]),c.norm=this.normalizeLandmarks(c.slice,l),c.palmLandmarks=W.reshape(c.norm,[-1,2]);let x=await c.box.data(),i=x.slice(0,2),y=x.slice(2,4),d=await c.palmLandmarks.array(),p={startPoint:i,endPoint:y,palmLandmarks:d,confidence:r[l]},f=Dn(p,[(t.shape[2]||1)/this.inputSize,(t.shape[1]||0)/this.inputSize]);A.push(f),Object.keys(c).forEach(b=>W.dispose(c[b]))}return Object.keys(o).forEach(l=>W.dispose(o[l])),A}};var U0=Z(H());var zA=5,Vn=1.65,Zn=[0,5,9,13,17,1,2],SA=0,jA=2,Xn=0,St=class{constructor(t,n){k(this,"handDetector");k(this,"handPoseModel");k(this,"inputSize");k(this,"storedBoxes");k(this,"skipped");k(this,"detectedHands");var o,r,s;this.handDetector=t,this.handPoseModel=n,this.inputSize=((s=(r=(o=this.handPoseModel)==null?void 0:o.inputs)==null?void 0:r[0].shape)==null?void 0:s[2])||0,this.storedBoxes=[],this.skipped=Number.MAX_SAFE_INTEGER,this.detectedHands=0}calculateLandmarksBoundingBox(t){let n=t.map(A=>A[0]),o=t.map(A=>A[1]),r=[Math.min(...n),Math.min(...o)],s=[Math.max(...n),Math.max(...o)];return{startPoint:r,endPoint:s}}getBoxForPalmLandmarks(t,n){let o=t.map(s=>Q5([...s,1],n)),r=this.calculateLandmarksBoundingBox(o);return wt(Et(r),zA)}getBoxForHandLandmarks(t){let n=this.calculateLandmarksBoundingBox(t),o=wt(Et(n),Vn);o.palmLandmarks=[];for(let r=0;r[A[0]*(d[0]-this.inputSize/2),A[1]*(d[1]-this.inputSize/2),A[2]*d[2]]),l=J5(o,[0,0]),c=a.map(d=>[...Q5(d,l),d[2]]),x=Bn(r),i=[...W2(n),1],y=[Ze(i,x[0]),Ze(i,x[1])];return c.map(d=>[Math.trunc(d[0]+y[0]),Math.trunc(d[1]+y[1]),Math.trunc(d[2])])}async estimateHands(t,n){let o=!1,r,s=(n.hand.skipTime||0)>g()-Xn,A=this.skipped<(n.hand.skipFrames||0);n.skipAllowed&&s&&A&&(r=await this.handDetector.predict(t,n),this.skipped=0),n.skipAllowed&&this.skipped++,r&&r.length>0&&(r.length!==this.detectedHands&&this.detectedHands!==n.hand.maxDetected||!n.hand.landmarks)&&(this.detectedHands=0,this.storedBoxes=[...r],this.storedBoxes.length>0&&(o=!0));let a=[];for(let l=0;l=n.hand.minConfidence/4){let S=U0.reshape(m,[-1,3]),P=await S.array();U0.dispose(m),U0.dispose(S);let I=this.transformRawCoords(P,f,x,p),q=this.getBoxForHandLandmarks(I);this.storedBoxes[l]={...q,confidence:h};let t0={landmarks:I,confidence:h,boxConfidence:c.confidence,fingerConfidence:h,box:{topLeft:q.startPoint,bottomRight:q.endPoint}};a.push(t0)}else this.storedBoxes[l]=null;U0.dispose(m)}else{let x=wt(Et(c),Vn),i={confidence:c.confidence,boxConfidence:c.confidence,fingerConfidence:0,box:{topLeft:x.startPoint,bottomRight:x.endPoint},landmarks:[]};a.push(i)}}return this.storedBoxes=this.storedBoxes.filter(l=>l!==null),this.detectedHands=a.length,a.length>n.hand.maxDetected&&(a.length=n.hand.maxDetected),a}};var qn={thumb:[1,2,3,4],index:[5,6,7,8],middle:[9,10,11,12],ring:[13,14,15,16],pinky:[17,18,19,20],palm:[0]},a2,i2,Un;async function _5(e,t){let n=await Un.estimateHands(e,t);if(!n)return[];let o=[];for(let r=0;rn[r].landmarks[i]);let A=n[r].landmarks,a=[Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,0,0],l=[0,0,0,0];if(A&&A.length>0){for(let x of A)x[0]a[2]&&(a[2]=x[0]),x[1]>a[3]&&(a[3]=x[1]);a[2]-=a[0],a[3]-=a[1],l=[a[0]/(e.shape[2]||0),a[1]/(e.shape[1]||0),a[2]/(e.shape[2]||0),a[3]/(e.shape[1]||0)]}else a=n[r].box?[Math.trunc(Math.max(0,n[r].box.topLeft[0])),Math.trunc(Math.max(0,n[r].box.topLeft[1])),Math.trunc(Math.min(e.shape[2]||0,n[r].box.bottomRight[0])-Math.max(0,n[r].box.topLeft[0])),Math.trunc(Math.min(e.shape[1]||0,n[r].box.bottomRight[1])-Math.max(0,n[r].box.topLeft[1]))]:[0,0,0,0],l=[n[r].box.topLeft[0]/(e.shape[2]||0),n[r].box.topLeft[1]/(e.shape[1]||0),(n[r].box.bottomRight[0]-n[r].box.topLeft[0])/(e.shape[2]||0),(n[r].box.bottomRight[1]-n[r].box.topLeft[1])/(e.shape[1]||0)];let c=Pt(A);o.push({id:r,score:Math.round(100*n[r].confidence)/100,boxScore:Math.round(100*n[r].boxConfidence)/100,fingerScore:Math.round(100*n[r].fingerConfidence)/100,label:"hand",box:a,boxRaw:l,keypoints:A,annotations:s,landmarks:c})}return o}async function Yn(e){var n,o;R.initial&&(a2=null,i2=null),!a2||!i2?[a2,i2]=await Promise.all([e.hand.enabled?O((n=e.hand.detector)==null?void 0:n.modelPath):null,e.hand.landmarks?O((o=e.hand.skeleton)==null?void 0:o.modelPath):null]):(e.debug&&u("cached model:",a2.modelUrl),e.debug&&u("cached model:",i2.modelUrl));let t=a2?new zt(a2):void 0;return t&&i2&&(Un=new St(t,i2)),[a2,i2]}var Q=Z(H());var f0=[null,null],IA=["StatefulPartitionedCall/Postprocessor/Slice","StatefulPartitionedCall/Postprocessor/ExpandDims_1"],Xe=[[0,0],[0,0]],OA=["hand","fist","pinch","point","face","tip","pinchtip"],Jn=4,Qn=1.6,LA=512,CA=1.4,jt=Number.MAX_SAFE_INTEGER,$5=0,ke=[0,0],y0={boxes:[],hands:[]},_n={thumb:[1,2,3,4],index:[5,6,7,8],middle:[9,10,11,12],ring:[13,14,15,16],pinky:[17,18,19,20],base:[0],palm:[0,17,13,9,5,1,0]};async function $n(e){var t;if(R.initial&&(f0[0]=null),f0[0])e.debug&&u("cached model:",f0[0].modelUrl);else{J2(["tensorlistreserve","enter","tensorlistfromtensor","merge","loopcond","switch","exit","tensorliststack","nextiteration","tensorlistsetitem","tensorlistgetitem","reciprocal","shape","split","where"],e),f0[0]=await O((t=e.hand.detector)==null?void 0:t.modelPath);let n=f0[0].executor?Object.values(f0[0].modelSignature.inputs):void 0;Xe[0][0]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[1].size):0,Xe[0][1]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[2].size):0}return f0[0]}async function eo(e){var t;if(R.initial&&(f0[1]=null),f0[1])e.debug&&u("cached model:",f0[1].modelUrl);else{f0[1]=await O((t=e.hand.skeleton)==null?void 0:t.modelPath);let n=f0[1].executor?Object.values(f0[1].modelSignature.inputs):void 0;Xe[1][0]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[1].size):0,Xe[1][1]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[2].size):0}return f0[1]}async function WA(e,t){let n=[];if(!e||!f0[0])return n;let o={},r=(e.shape[2]||1)/(e.shape[1]||1),s=Math.min(Math.round((e.shape[1]||0)/8)*8,LA),A=Math.round(s*r/8)*8;o.resize=Q.image.resizeBilinear(e,[s,A]),o.cast=Q.cast(o.resize,"int32"),[o.rawScores,o.rawBoxes]=await f0[0].executeAsync(o.cast,IA),o.boxes=Q.squeeze(o.rawBoxes,[0,2]),o.scores=Q.squeeze(o.rawScores,[0]);let a=Q.unstack(o.scores,1);Q.dispose(a[Jn]),a.splice(Jn,1),o.filtered=Q.stack(a,1),Q.dispose(a),o.max=Q.max(o.filtered,1),o.argmax=Q.argMax(o.filtered,1);let l=0;o.nms=await Q.image.nonMaxSuppressionAsync(o.boxes,o.max,(t.hand.maxDetected||0)+1,t.hand.iouThreshold||0,t.hand.minConfidence||1);let c=await o.nms.data(),x=await o.max.data(),i=await o.argmax.data();for(let y of Array.from(c)){let d=Q.slice(o.boxes,y,1),p=await d.data();Q.dispose(d);let f=[p[1],p[0],p[3]-p[1],p[2]-p[0]],b=st(f,CA),M=[Math.trunc(f[0]*ke[0]),Math.trunc(f[1]*ke[1]),Math.trunc(f[2]*ke[0]),Math.trunc(f[3]*ke[1])],T=x[y],m=OA[i[y]],h={id:l++,score:T,box:M,boxRaw:b,label:m};n.push(h)}return Object.keys(o).forEach(y=>Q.dispose(o[y])),n.sort((y,d)=>d.score-y.score),n.length>(t.hand.maxDetected||1)&&(n.length=t.hand.maxDetected||1),n}async function e1(e,t,n){let o={id:t.id,score:Math.round(100*t.score)/100,boxScore:Math.round(100*t.score)/100,fingerScore:0,box:t.box,boxRaw:t.boxRaw,label:t.label,keypoints:[],landmarks:{},annotations:{}};if(e&&f0[1]&&n.hand.landmarks&&t.score>(n.hand.minConfidence||0)){let r={},s=[t.boxRaw[1],t.boxRaw[0],t.boxRaw[3]+t.boxRaw[1],t.boxRaw[2]+t.boxRaw[0]];r.crop=Q.image.cropAndResize(e,[s],[0],[Xe[1][0],Xe[1][1]],"bilinear"),r.div=Q.div(r.crop,C.tf255),[r.score,r.keypoints]=f0[1].execute(r.div,["Identity_1","Identity"]);let A=(await r.score.data())[0],a=(100-Math.trunc(100/(1+Math.exp(A))))/100;if(a>=(n.hand.minConfidence||0)){o.fingerScore=a,r.reshaped=Q.reshape(r.keypoints,[-1,3]);let x=(await r.reshaped.array()).map(i=>[i[0]/Xe[1][1],i[1]/Xe[1][0],i[2]||0]).map(i=>[i[0]*t.boxRaw[2],i[1]*t.boxRaw[3],i[2]||0]);o.keypoints=x.map(i=>[ke[0]*(i[0]+t.boxRaw[0]),ke[1]*(i[1]+t.boxRaw[1]),i[2]||0]),o.landmarks=Pt(o.keypoints);for(let i of Object.keys(_n))o.annotations[i]=_n[i].map(y=>o.landmarks&&o.keypoints[y]?o.keypoints[y]:null)}Object.keys(r).forEach(l=>Q.dispose(r[l]))}return o}async function t1(e,t){var r,s;if(!((r=f0[0])!=null&&r.executor)||!((s=f0[1])!=null&&s.executor)||!f0[0].inputs[0].shape||!f0[1].inputs[0].shape)return[];ke=[e.shape[2]||0,e.shape[1]||0],jt++;let n=(t.hand.skipTime||0)>g()-$5,o=jt<(t.hand.skipFrames||0);return t.skipAllowed&&n&&o?y0.hands:new Promise(async A=>{let a=3*(t.hand.skipTime||0)>g()-$5,l=jt<3*(t.hand.skipFrames||0);t.skipAllowed&&y0.hands.length===t.hand.maxDetected?y0.hands=await Promise.all(y0.boxes.map(x=>e1(e,x,t))):t.skipAllowed&&a&&l&&y0.hands.length>0?y0.hands=await Promise.all(y0.boxes.map(x=>e1(e,x,t))):(y0.boxes=await WA(e,t),$5=g(),y0.hands=await Promise.all(y0.boxes.map(x=>e1(e,x,t))),jt=0);let c=[...y0.boxes];if(y0.boxes.length=0,t.cacheSensitivity>0)for(let x=0;x.05&&i.box[3]/(e.shape[1]||1)>.05&&y0.hands[x].fingerScore&&y0.hands[x].fingerScore>(t.hand.minConfidence||0)){let y=st(i.box,Qn),d=st(i.boxRaw,Qn);y0.boxes.push({...c[x],box:y,boxRaw:d})}}for(let x=0;x({face:[],body:[],hand:[],gesture:[],object:[],persons:[],performance:{},timestamp:0,width:0,height:0,error:e});var D2={};ze(D2,{connected:()=>It,horizontal:()=>n1,kpt:()=>Nt,relative:()=>r1,vertical:()=>o1});var Nt=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"],n1=[["leftEye","rightEye"],["leftEar","rightEar"],["leftShoulder","rightShoulder"],["leftElbow","rightElbow"],["leftWrist","rightWrist"],["leftHip","rightHip"],["leftKnee","rightKnee"],["leftAnkle","rightAnkle"]],o1=[["leftKnee","leftShoulder"],["rightKnee","rightShoulder"],["leftAnkle","leftKnee"],["rightAnkle","rightKnee"]],r1=[[["leftHip","rightHip"],["leftShoulder","rightShoulder"]],[["leftElbow","rightElbow"],["leftShoulder","rightShoulder"]]],It={leftLeg:["leftHip","leftKnee","leftAnkle"],rightLeg:["rightHip","rightKnee","rightAnkle"],torso:["leftShoulder","rightShoulder","rightHip","leftHip","leftShoulder"],leftArm:["leftShoulder","leftElbow","leftWrist"],rightArm:["rightShoulder","rightElbow","rightWrist"],head:[]};var w=he(),s1=0;function no(e,t){var A,a,l,c,x,i,y,d,p,f,b,M,T,m,h,S,P,I,q,t0,G,$,A0;let n=g();if(!e)return he();let o=Date.now()-e.timestamp,r=o<1e3?8-Math.log(o+1):1;if(e.canvas&&(w.canvas=e.canvas),e.error&&(w.error=e.error),!w.body||e.body.length!==w.body.length)w.body=JSON.parse(JSON.stringify(e.body));else for(let v=0;v((r-1)*w.body[v].box[X]+B)/r),n0=e.body[v].boxRaw.map((B,X)=>((r-1)*w.body[v].boxRaw[X]+B)/r),U=e.body[v].keypoints.map((B,X)=>{var z,ee,we,Ee,T0,P2,M1,P1,k1;return{score:B.score,part:B.part,position:[w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].position[0]||0)+(B.position[0]||0))/r:B.position[0],w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].position[1]||0)+(B.position[1]||0))/r:B.position[1],w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].position[2]||0)+(B.position[2]||0))/r:B.position[2]],positionRaw:[w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].positionRaw[0]||0)+(B.positionRaw[0]||0))/r:B.positionRaw[0],w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].positionRaw[1]||0)+(B.positionRaw[1]||0))/r:B.positionRaw[1],w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].positionRaw[2]||0)+(B.positionRaw[2]||0))/r:B.positionRaw[2]],distance:[w.body[v].keypoints[X]?((r-1)*(((z=w.body[v].keypoints[X].distance)==null?void 0:z[0])||0)+(((ee=B.distance)==null?void 0:ee[0])||0))/r:(we=B.distance)==null?void 0:we[0],w.body[v].keypoints[X]?((r-1)*(((Ee=w.body[v].keypoints[X].distance)==null?void 0:Ee[1])||0)+(((T0=B.distance)==null?void 0:T0[1])||0))/r:(P2=B.distance)==null?void 0:P2[1],w.body[v].keypoints[X]?((r-1)*(((M1=w.body[v].keypoints[X].distance)==null?void 0:M1[2])||0)+(((P1=B.distance)==null?void 0:P1[2])||0))/r:(k1=B.distance)==null?void 0:k1[2]]}}),g0={},m0={connected:{}};(A=t.body.modelPath)!=null&&A.includes("efficientpose")?m0=it:(a=t.body.modelPath)!=null&&a.includes("blazepose")?m0=ot:(l=t.body.modelPath)!=null&&l.includes("movenet")&&(m0=D2);for(let[B,X]of Object.entries(m0.connected)){let z=[];for(let ee=0;eeT0.part===X[ee]),Ee=U.find(T0=>T0.part===X[ee+1]);we&&Ee&&z.push([we.position,Ee.position])}g0[B]=z}w.body[v]={...e.body[v],box:V,boxRaw:n0,keypoints:U,annotations:g0}}if(!w.hand||e.hand.length!==w.hand.length)w.hand=JSON.parse(JSON.stringify(e.hand));else for(let v=0;v((r-1)*w.hand[v].box[B]+m0)/r),n0=e.hand[v].boxRaw.map((m0,B)=>((r-1)*w.hand[v].boxRaw[B]+m0)/r);w.hand[v].keypoints.length!==e.hand[v].keypoints.length&&(w.hand[v].keypoints=e.hand[v].keypoints);let U=e.hand[v].keypoints&&e.hand[v].keypoints.length>0?e.hand[v].keypoints.map((m0,B)=>m0.map((X,z)=>((r-1)*(w.hand[v].keypoints[B][z]||1)+(X||0))/r)):[],g0={};if(Object.keys(w.hand[v].annotations).length!==Object.keys(e.hand[v].annotations).length)w.hand[v].annotations=e.hand[v].annotations,g0=w.hand[v].annotations;else if(e.hand[v].annotations)for(let m0 of Object.keys(e.hand[v].annotations))g0[m0]=(i=(x=(c=e.hand[v])==null?void 0:c.annotations)==null?void 0:x[m0])!=null&&i[0]?e.hand[v].annotations[m0].map((B,X)=>B.map((z,ee)=>((r-1)*w.hand[v].annotations[m0][X][ee]+z)/r)):null;w.hand[v]={...e.hand[v],box:V,boxRaw:n0,keypoints:U,annotations:g0}}if(!w.face||e.face.length!==w.face.length)w.face=JSON.parse(JSON.stringify(e.face));else for(let v=0;v((r-1)*w.face[v].box[g0]+U)/r),n0=e.face[v].boxRaw.map((U,g0)=>((r-1)*w.face[v].boxRaw[g0]+U)/r);if(e.face[v].rotation){let U={matrix:[0,0,0,0,0,0,0,0,0],angle:{roll:0,yaw:0,pitch:0},gaze:{bearing:0,strength:0}};U.matrix=(y=e.face[v].rotation)==null?void 0:y.matrix,U.angle={roll:((r-1)*(((p=(d=w.face[v].rotation)==null?void 0:d.angle)==null?void 0:p.roll)||0)+(((b=(f=e.face[v].rotation)==null?void 0:f.angle)==null?void 0:b.roll)||0))/r,yaw:((r-1)*(((T=(M=w.face[v].rotation)==null?void 0:M.angle)==null?void 0:T.yaw)||0)+(((h=(m=e.face[v].rotation)==null?void 0:m.angle)==null?void 0:h.yaw)||0))/r,pitch:((r-1)*(((P=(S=w.face[v].rotation)==null?void 0:S.angle)==null?void 0:P.pitch)||0)+(((q=(I=e.face[v].rotation)==null?void 0:I.angle)==null?void 0:q.pitch)||0))/r},U.gaze={bearing:((r-1)*(((t0=w.face[v].rotation)==null?void 0:t0.gaze.bearing)||0)+(((G=e.face[v].rotation)==null?void 0:G.gaze.bearing)||0))/r,strength:((r-1)*((($=w.face[v].rotation)==null?void 0:$.gaze.strength)||0)+(((A0=e.face[v].rotation)==null?void 0:A0.gaze.strength)||0))/r},w.face[v]={...e.face[v],rotation:U,box:V,boxRaw:n0}}else w.face[v]={...e.face[v],box:V,boxRaw:n0}}if(!w.object||e.object.length!==w.object.length)w.object=JSON.parse(JSON.stringify(e.object));else for(let v=0;v((r-1)*w.object[v].box[g0]+U)/r),n0=e.object[v].boxRaw.map((U,g0)=>((r-1)*w.object[v].boxRaw[g0]+U)/r);w.object[v]={...e.object[v],box:V,boxRaw:n0}}if(e.persons){let v=e.persons;if(!w.persons||v.length!==w.persons.length)w.persons=JSON.parse(JSON.stringify(v));else for(let V=0;V((r-1)*w.persons[V].box[U]+n0)/r)}e.gesture&&(w.gesture=e.gesture),w.width=e.width,w.height=e.height;let s=g();return s1=R.perfadd?s1+Math.round(s-n):Math.round(s-n),e.performance&&(w.performance={...e.performance,interpolate:s1}),w}var s0=Z(H());var j0;async function A1(e){return!j0||R.initial?j0=await O(e.segmentation.modelPath):e.debug&&u("cached model:",j0.modelUrl),j0}async function oo(e,t){var r;if(j0||(j0=await A1(t)),!(j0!=null&&j0.executor)||!((r=j0==null?void 0:j0.inputs)!=null&&r[0].shape))return null;let n={};n.resize=s0.image.resizeBilinear(e,[j0.inputs[0].shape?j0.inputs[0].shape[1]:0,j0.inputs[0].shape?j0.inputs[0].shape[2]:0],!1),n.norm=s0.div(n.resize,C.tf255),n.res=j0.execute(n.norm),n.squeeze=s0.squeeze(n.res,[0]),[n.bgRaw,n.fgRaw]=s0.unstack(n.squeeze,2),n.fg=s0.softmax(n.fgRaw),n.mul=s0.mul(n.fg,C.tf255),n.expand=s0.expandDims(n.mul,2),n.output=s0.image.resizeBilinear(n.expand,[e.shape[1]||0,e.shape[2]||0]);let o;switch(t.segmentation.mode||"default"){case"default":n.input=s0.squeeze(e),n.concat=s0.concat([n.input,n.output],-1),o=s0.cast(n.concat,"int32");break;case"alpha":o=s0.cast(n.output,"int32");break;default:o=s0.tensor(0)}return Object.keys(n).forEach(s=>s0.dispose(n[s])),o}var Ot={};ze(Ot,{distance:()=>a1,find:()=>BA,similarity:()=>FA});function a1(e,t,n={order:2,multiplier:25}){if(!e||!e)return Number.MAX_SAFE_INTEGER;let o=0;for(let r=0;r{if(e===0)return 1;let s=(1-(t===2?Math.sqrt(e):e**(1/t))/100-n)/(o-n);return Math.max(Math.min(s,1),0)};function FA(e,t,n={order:2,multiplier:25,min:.2,max:.8}){let o=a1(e,t,n);return so(o,n.order||2,n.min||0,n.max||1)}function BA(e,t,n={order:2,multiplier:25,threshold:0,min:.2,max:.8}){if(!Array.isArray(e)||!Array.isArray(t)||e.length<64||t.length===0)return{index:-1,distance:Number.POSITIVE_INFINITY,similarity:0};let o=Number.MAX_SAFE_INTEGER,r=-1;for(let A=0;AH2,validateModel:()=>Ht});var co=Z(H());var qe=Z(H());var Ao=.005,Y0={keypoints:[],padding:[[0,0],[0,0],[0,0],[0,0]]};function i1(e){for(let t of n1){let n=e.keypoints.findIndex(r=>r.part===t[0]),o=e.keypoints.findIndex(r=>r.part===t[1]);if(e.keypoints[n]&&e.keypoints[o]&&e.keypoints[n].position[0]r&&r.part===t[0]),o=e.keypoints.findIndex(r=>r&&r.part===t[1]);e.keypoints[n]&&e.keypoints[o]&&e.keypoints[n].position[1]c&&c.part===t[0]),r=e.keypoints.findIndex(c=>c&&c.part===t[1]),s=e.keypoints.findIndex(c=>c&&c.part===n[0]),A=e.keypoints.findIndex(c=>c&&c.part===n[1]);if(!e.keypoints[s]||!e.keypoints[A])continue;let a=e.keypoints[o]?[Math.abs(e.keypoints[s].position[0]-e.keypoints[o].position[0]),Math.abs(e.keypoints[A].position[0]-e.keypoints[o].position[0])]:[0,0],l=e.keypoints[r]?[Math.abs(e.keypoints[A].position[0]-e.keypoints[r].position[0]),Math.abs(e.keypoints[s].position[0]-e.keypoints[r].position[0])]:[0,0];if(a[0]>a[1]||l[0]>l[1]){let c=e.keypoints[o];e.keypoints[o]=e.keypoints[r],e.keypoints[r]=c}}}function ao(e){for(let t=0;te.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0,e.shape[2]>e.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0],[e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0,e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0],[0,0]],n.pad=qe.pad(e,Y0.padding),n.resize=qe.image.resizeBilinear(n.pad,[t,t]);let o=qe.cast(n.resize,"int32");return Object.keys(n).forEach(A=>qe.dispose(n[A])),o}function lo(e,t){e.keypoints=e.keypoints.filter(o=>o==null?void 0:o.position);for(let o of e.keypoints)o.position=[o.position[0]*(t[0]+Y0.padding[2][0]+Y0.padding[2][1])/t[0]-Y0.padding[2][0],o.position[1]*(t[1]+Y0.padding[1][0]+Y0.padding[1][1])/t[1]-Y0.padding[1][0]],o.positionRaw=[o.position[0]/t[0],o.position[1]/t[1]];let n=ve(e.keypoints.map(o=>o.position),t);return e.box=n.box,e.boxRaw=n.boxRaw,e}var h0,Lt=0,l1=Number.MAX_SAFE_INTEGER,l2={boxes:[],bodies:[],last:0};async function xo(e){var t;return R.initial&&(h0=null),h0?e.debug&&u("cached model:",h0.modelUrl):(J2(["size"],e),h0=await O(e.body.modelPath)),Lt=(h0==null?void 0:h0.executor)&&((t=h0==null?void 0:h0.inputs)==null?void 0:t[0].shape)?h0.inputs[0].shape[2]:0,Lt<64&&(Lt=256),h0}function GA(e,t,n){let o=e[0][0],r=[],s=0;for(let x=0;xt.body.minConfidence){let i=[o[x][1],o[x][0]];r.push({score:Math.round(100*s)/100,part:Nt[x],positionRaw:i,position:[Math.round((n.shape[2]||0)*i[0]),Math.round((n.shape[1]||0)*i[1])]})}s=r.reduce((x,i)=>i.score>x?i.score:x,0);let A=[],a=ve(r.map(x=>x.position),[n.shape[2],n.shape[1]]),l={};for(let[x,i]of Object.entries(It)){let y=[];for(let d=0;db.part===i[d]),f=r.find(b=>b.part===i[d+1]);p&&f&&p.score>(t.body.minConfidence||0)&&f.score>(t.body.minConfidence||0)&&y.push([p.position,f.position])}l[x]=y}let c={id:0,score:s,box:a.box,boxRaw:a.boxRaw,keypoints:r,annotations:l};return i1(c),A.push(c),A}function VA(e,t,n){let o=[];for(let r=0;rt.body.minConfidence){let a=[];for(let i=0;i<17;i++){let y=s[3*i+2];if(y>t.body.minConfidence){let d=[s[3*i+1],s[3*i+0]];a.push({part:Nt[i],score:Math.round(100*y)/100,positionRaw:d,position:[Math.round((n.shape[2]||0)*d[0]),Math.round((n.shape[1]||0)*d[1])]})}}let l=ve(a.map(i=>i.position),[n.shape[2],n.shape[1]]),c={};for(let[i,y]of Object.entries(It)){let d=[];for(let p=0;pM.part===y[p]),b=a.find(M=>M.part===y[p+1]);f&&b&&f.score>(t.body.minConfidence||0)&&b.score>(t.body.minConfidence||0)&&d.push([f.position,b.position])}c[i]=d}let x={id:r,score:A,box:l.box,boxRaw:l.boxRaw,keypoints:[...a],annotations:c};i1(x),o.push(x)}}return o.sort((r,s)=>s.score-r.score),o.length>t.body.maxDetected&&(o.length=t.body.maxDetected),o}async function c1(e,t){var r;if(!(h0!=null&&h0.executor)||!((r=h0==null?void 0:h0.inputs)!=null&&r[0].shape))return[];t.skipAllowed||(l2.boxes.length=0),l1++;let n=(t.body.skipTime||0)>g()-l2.last,o=l1<(t.body.skipFrames||0);return t.skipAllowed&&n&&o?l2.bodies:new Promise(async s=>{let A={};l1=0,A.input=io(e,Lt),A.res=h0==null?void 0:h0.execute(A.input),l2.last=g();let a=await A.res.array();l2.bodies=A.res.shape[2]===17?GA(a,t,e):VA(a,t,e);for(let l of l2.bodies)lo(l,[e.shape[2]||1,e.shape[1]||1]),ao(l.keypoints);Object.keys(A).forEach(l=>co.dispose(A[l])),s(l2.bodies)})}var w0=Z(H());var Ae,Ct=[],fo=0,d1=Number.MAX_SAFE_INTEGER,Dt=0,Wt=2.5;async function mo(e){if(!Ae||R.initial){Ae=await O(e.object.modelPath);let t=Ae!=null&&Ae.executor?Object.values(Ae.modelSignature.inputs):void 0;Dt=Array.isArray(t)?parseInt(t[0].tensorShape.dim[2].size):416}else e.debug&&u("cached model:",Ae.modelUrl);return Ae}async function ZA(e,t,n){var c,x;let o=0,r=[],s=Dt;for(let i of[1,2,4]){let y=i*13,d=w0.squeeze(e.find(m=>m.shape[1]===y**2&&(m.shape[2]||0)===x2.length)),p=await d.array(),f=w0.squeeze(e.find(m=>m.shape[1]===y**2&&(m.shape[2]||0)(n.object.minConfidence||0)&&h!==61){let P=(.5+Math.trunc(m%y))/y,I=(.5+Math.trunc(m/y))/y,q=T[m].map(U=>U*(y/i/s)),[t0,G]=[P-Wt/i*q[0],I-Wt/i*q[1]],[$,A0]=[P+Wt/i*q[2]-t0,I+Wt/i*q[3]-G],v=[t0,G,$,A0];v=v.map(U=>Math.max(0,Math.min(U,1)));let V=[v[0]*t[0],v[1]*t[1],v[2]*t[0],v[3]*t[1]],n0={id:o++,score:Math.round(100*S)/100,class:h+1,label:x2[h].label,box:V.map(U=>Math.trunc(U)),boxRaw:v};r.push(n0)}}w0.dispose([d,f,b,M])}let A=r.map(i=>[i.boxRaw[1],i.boxRaw[0],i.boxRaw[3],i.boxRaw[2]]),a=r.map(i=>i.score),l=[];if(A&&A.length>0){let i=await w0.image.nonMaxSuppressionAsync(A,a,n.object.maxDetected||0,n.object.iouThreshold,n.object.minConfidence);l=Array.from(await i.data()),w0.dispose(i)}return r=r.filter((i,y)=>l.includes(y)).sort((i,y)=>y.score-i.score),r}async function x1(e,t){if(!(Ae!=null&&Ae.executor))return[];let n=(t.object.skipTime||0)>g()-fo,o=d1<(t.object.skipFrames||0);return t.skipAllowed&&n&&o&&Ct.length>0?(d1++,Ct):(d1=0,!R.kernels.includes("mod")||!R.kernels.includes("sparsetodense")?Ct:new Promise(async r=>{let s=[e.shape[2]||0,e.shape[1]||0],A=w0.image.resizeBilinear(e,[Dt,Dt],!1),a=w0.div(A,C.tf255),l=w0.transpose(a,[0,3,1,2]),c;t.object.enabled&&(c=Ae.execute(l)),fo=g();let x=await ZA(c,s,t);Ct=x,w0.dispose([A,a,l,...c]),r(x)}))}var D0=Z(H());var B2=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"],XA=B2.length,F2=B2.reduce((e,t,n)=>(e[t]=n,e),{}),qA=[["leftHip","leftShoulder"],["leftElbow","leftShoulder"],["leftElbow","leftWrist"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["rightHip","rightShoulder"],["rightElbow","rightShoulder"],["rightElbow","rightWrist"],["rightHip","rightKnee"],["rightKnee","rightAnkle"],["leftShoulder","rightShoulder"],["leftHip","rightHip"]],Li=qA.map(([e,t])=>[F2[e],F2[t]]),uo=[["nose","leftEye"],["leftEye","leftEar"],["nose","rightEye"],["rightEye","rightEar"],["nose","leftShoulder"],["leftShoulder","leftElbow"],["leftElbow","leftWrist"],["leftShoulder","leftHip"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["nose","rightShoulder"],["rightShoulder","rightElbow"],["rightElbow","rightWrist"],["rightShoulder","rightHip"],["rightHip","rightKnee"],["rightKnee","rightAnkle"]];function ho(e){let t=e.reduce(({maxX:n,maxY:o,minX:r,minY:s},{position:{x:A,y:a}})=>({maxX:Math.max(n,A),maxY:Math.max(o,a),minX:Math.min(r,A),minY:Math.min(s,a)}),{maxX:Number.NEGATIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY,minX:Number.POSITIVE_INFINITY,minY:Number.POSITIVE_INFINITY});return[t.minX,t.minY,t.maxX-t.minX,t.maxY-t.minY]}function bo(e,[t,n],[o,r]){let s=t/o,A=n/r,a=(c,x)=>({id:x,score:c.score,boxRaw:[c.box[0]/r,c.box[1]/o,c.box[2]/r,c.box[3]/o],box:[Math.trunc(c.box[0]*A),Math.trunc(c.box[1]*s),Math.trunc(c.box[2]*A),Math.trunc(c.box[3]*s)],keypoints:c.keypoints.map(({score:i,part:y,position:d})=>({score:i,part:y,position:[Math.trunc(d.x*A),Math.trunc(d.y*s)],positionRaw:[d.x/o,d.y/o]})),annotations:{}});return e.map((c,x)=>a(c,x))}var Ft=class{constructor(t,n){k(this,"priorityQueue");k(this,"numberOfElements");k(this,"getElementValue");this.priorityQueue=new Array(t),this.numberOfElements=-1,this.getElementValue=n}enqueue(t){this.priorityQueue[++this.numberOfElements]=t,this.swim(this.numberOfElements)}dequeue(){let t=this.priorityQueue[0];return this.exchange(0,this.numberOfElements--),this.sink(0),this.priorityQueue[this.numberOfElements+1]=null,t}empty(){return this.numberOfElements===-1}size(){return this.numberOfElements+1}all(){return this.priorityQueue.slice(0,this.numberOfElements+1)}max(){return this.priorityQueue[0]}swim(t){for(;t>0&&this.less(Math.floor(t/2),t);)this.exchange(t,Math.floor(t/2)),t=Math.floor(t/2)}sink(t){for(;2*t<=this.numberOfElements;){let n=2*t;if(nn?n:e}function go(e,t,n,o){let r=n-e,s=o-t;return r*r+s*s}function p1(e,t){return{x:e.x+t.x,y:e.y+t.y}}var K0,YA=["MobilenetV1/offset_2/BiasAdd","MobilenetV1/heatmap_2/BiasAdd","MobilenetV1/displacement_fwd_2/BiasAdd","MobilenetV1/displacement_bwd_2/BiasAdd"],Bt=1,R2=16,KA=50**2;function To(e,t,n,o,r,s,A=2){let a=M=>({y:s.get(M.y,M.x,e),x:s.get(M.y,M.x,s.shape[2]/2+e)}),l=(M,T,m)=>({y:m1(Math.round(M.y/R2),0,T-1),x:m1(Math.round(M.x/R2),0,m-1)}),[c,x]=o.shape,i=l(t.position,c,x),y=a(i),p=p1(t.position,y);for(let M=0;M[F2[y],F2[d]]),A=s.map(([,y])=>y),a=s.map(([y])=>y),l=t.shape[2],c=A.length,x=new Array(l),i=f1(e.part,R2,n);x[e.part.id]={score:e.score,part:B2[e.part.id],position:i};for(let y=c-1;y>=0;--y){let d=A[y],p=a[y];x[d]&&!x[p]&&(x[p]=To(y,x[d],p,t,n,r))}for(let y=0;yt){a=!1;break}if(!a)break}return a}function _A(e,t){let[n,o,r]=t.shape,s=new Ft(n*o*r,({score:A})=>A);for(let A=0;A{var A;let s=(A=r[o])==null?void 0:A.position;return s?go(n,t,s.y,s.x)<=KA:!1})}function $A(e,t){return t.reduce((o,{position:r,score:s},A)=>(vo(e,r,A)||(o+=s),o),0)/t.length}function ea(e,t,n,o,r,s){let A=[],a=_A(s,t);for(;A.lengthd.score>s);let i=$A(A,x),y=ho(x);i>s&&A.push({keypoints:x,box:y,score:Math.round(100*i)/100})}return A}async function u1(e,t){if(!(K0!=null&&K0.executor))return[];let n=D0.tidy(()=>{if(!K0.inputs[0].shape)return[];let A=D0.image.resizeBilinear(e,[K0.inputs[0].shape[2],K0.inputs[0].shape[1]]),a=D0.sub(D0.div(D0.cast(A,"float32"),127.5),1),c=K0.execute(a,YA).map(x=>D0.squeeze(x,[0]));return c[1]=D0.sigmoid(c[1]),c}),o=await Promise.all(n.map(A=>A.buffer()));for(let A of n)D0.dispose(A);let r=ea(o[0],o[1],o[2],o[3],t.body.maxDetected,t.body.minConfidence);return K0.inputs[0].shape?bo(r,[e.shape[1],e.shape[2]],[K0.inputs[0].shape[2],K0.inputs[0].shape[1]]):[]}async function Ro(e){return!K0||R.initial?K0=await O(e.body.modelPath):e.debug&&u("cached model:",K0.modelUrl),K0}var F=Z(H());var be,ta=["fgr","pha","r1o","r2o","r3o","r4o"],b0={},b1=0;function ko(e){F.dispose([b0.r1i,b0.r2i,b0.r3i,b0.r4i,b0.downsample_ratio]),b0.r1i=F.tensor(0),b0.r2i=F.tensor(0),b0.r3i=F.tensor(0),b0.r4i=F.tensor(0),b1=e.segmentation.ratio||.5,b0.downsample_ratio=F.tensor(b1)}async function g1(e){return!be||R.initial?be=await O(e.segmentation.modelPath):e.debug&&u("cached model:",be.modelUrl),ko(e),be}var Po=e=>F.tidy(()=>{let t=F.squeeze(e,[0]),n=F.mul(t,C.tf255);return F.cast(n,"int32")});function h1(e,t){let n=e?Po(e):F.fill([t.shape[1]||0,t.shape[2]||0,3],255,"int32"),o=t?Po(t):F.fill([e.shape[1]||0,e.shape[2]||0,1],255,"int32"),r=F.concat([n,o],-1);return F.dispose([n,o]),r}function na(e){return F.tidy(()=>{let t={};return t.unstack=F.unstack(e,-1),t.concat=F.concat(t.unstack,1),t.split=F.split(t.concat,4,1),t.stack=F.concat(t.split,2),t.squeeze=F.squeeze(t.stack,[0]),t.expand=F.expandDims(t.squeeze,-1),t.add=F.add(t.expand,1),t.mul=F.mul(t.add,127.5),t.cast=F.cast(t.mul,"int32"),t.tile=F.tile(t.cast,[1,1,3]),t.alpha=F.fill([t.tile.shape[0]||0,t.tile.shape[1]||0,1],255,"int32"),F.concat([t.tile,t.alpha],-1)})}async function wo(e,t){if(be||(be=await g1(t)),!(be!=null&&be.executor))return null;b0.src=F.div(e,255),b1!==t.segmentation.ratio&&ko(t);let[n,o,r,s,A,a]=await be.executeAsync(b0,ta),l;switch(t.segmentation.mode||"default"){case"default":l=h1(n,o);break;case"alpha":l=h1(null,o);break;case"foreground":l=h1(n,null);break;case"state":l=na(r);break;default:l=F.tensor(0)}return F.dispose([b0.src,n,o,b0.r1i,b0.r2i,b0.r3i,b0.r4i]),[b0.r1i,b0.r2i,b0.r3i,b0.r4i]=[r,s,A,a],l}var k0=Z(H());var N0;async function T1(e){return!N0||R.initial?N0=await O(e.segmentation.modelPath):e.debug&&u("cached model:",N0.modelUrl),N0}async function zo(e,t){var r;if(N0||(N0=await T1(t)),!(N0!=null&&N0.executor)||!((r=N0==null?void 0:N0.inputs)!=null&&r[0].shape))return null;let n={};n.resize=k0.image.resizeBilinear(e,[N0.inputs[0].shape?N0.inputs[0].shape[1]:0,N0.inputs[0].shape?N0.inputs[0].shape[2]:0],!1),n.norm=k0.div(n.resize,C.tf255),n.res=N0.execute(n.norm),n.squeeze=k0.squeeze(n.res,[0]),n.alpha=k0.image.resizeBilinear(n.squeeze,[e.shape[1]||0,e.shape[2]||0]),n.mul=k0.mul(n.alpha,C.tf255);let o;switch(t.segmentation.mode||"default"){case"default":n.input=k0.squeeze(e),n.concat=k0.concat([n.input,n.mul],-1),o=k0.cast(n.concat,"int32");break;case"alpha":o=k0.cast(n.mul,"int32");break;default:o=k0.tensor(0)}return Object.keys(n).forEach(s=>k0.dispose(n[s])),o}function Ht(e,t,n){var c,x;if(!t||!((c=e==null?void 0:e.config)!=null&&c.validateModels))return null;let o=["const","placeholder","noop","pad","squeeze","add","sub","mul","div"],r=["biasadd","fusedbatchnormv3","matmul","switch","shape","merge","split","broadcastto"],s=[],A=[],a=t.modelUrl,l=t.executor;if((x=l==null?void 0:l.graph)!=null&&x.nodes)for(let i of Object.values(l.graph.nodes)){let y=i.op.toLowerCase();s.includes(y)||s.push(y)}else!l&&e.config.debug&&u("model not loaded",n);for(let i of s)!o.includes(i)&&!r.includes(i)&&!e.env.kernels.includes(i)&&!e.env.kernels.includes(i.replace("_",""))&&!e.env.kernels.includes(i.replace("native",""))&&!e.env.kernels.includes(i.replace("v2",""))&&A.push(i);return e.config.debug&&A.length>0&&u("model validation failed:",n,A),A.length>0?{name:n,missing:A,ops:s,url:a}:null}var H2=class{constructor(t){k(this,"instance");k(this,"models",{});this.models={},this.instance=t}stats(){let t=0,n=0,o=0;for(let s of Object.values(E0))t+=s.sizeFromManifest,n+=s.sizeLoadedWeights,o+=s.sizeDesired;let r=o>0?n/o:0;return{numLoadedModels:Object.values(E0).length,numDefinedModels:Object.keys(this.models).length,percentageLoaded:r,totalSizeFromManifest:t,totalSizeWeights:n,totalSizeLoading:o,modelStats:Object.values(E0)}}reset(){for(let t of Object.keys(this.models))this.models[t]=null}async load(t){var o,r,s,A,a,l,c,x,i,y,d,p,f,b,M,T,m,h,S,P,I,q,t0,G,$,A0,v;R.initial&&this.reset(),t&&(this.instance=t);let n={};n.blazeface=this.instance.config.face.enabled&&!this.models.blazeface?g3(this.instance.config):null,n.antispoof=this.instance.config.face.enabled&&((o=this.instance.config.face.antispoof)==null?void 0:o.enabled)&&!this.models.antispoof?X3(this.instance.config):null,n.liveness=this.instance.config.face.enabled&&((r=this.instance.config.face.liveness)==null?void 0:r.enabled)&&!this.models.liveness?K3(this.instance.config):null,n.faceres=this.instance.config.face.enabled&&((s=this.instance.config.face.description)==null?void 0:s.enabled)&&!this.models.faceres?B3(this.instance.config):null,n.emotion=this.instance.config.face.enabled&&((A=this.instance.config.face.emotion)==null?void 0:A.enabled)&&!this.models.emotion?C3(this.instance.config):null,n.iris=this.instance.config.face.enabled&&((a=this.instance.config.face.iris)==null?void 0:a.enabled)&&!((l=this.instance.config.face.attention)!=null&&l.enabled)&&!this.models.iris?k3(this.instance.config):null,n.facemesh=this.instance.config.face.enabled&&((c=this.instance.config.face.mesh)==null?void 0:c.enabled)&&!this.models.facemesh?j3(this.instance.config):null,n.gear=this.instance.config.face.enabled&&((x=this.instance.config.face.gear)==null?void 0:x.enabled)&&!this.models.gear?$3(this.instance.config):null,n.ssrnetage=this.instance.config.face.enabled&&((i=this.instance.config.face.ssrnet)==null?void 0:i.enabled)&&!this.models.ssrnetage?on(this.instance.config):null,n.ssrnetgender=this.instance.config.face.enabled&&((y=this.instance.config.face.ssrnet)==null?void 0:y.enabled)&&!this.models.ssrnetgender?an(this.instance.config):null,n.mobilefacenet=this.instance.config.face.enabled&&((d=this.instance.config.face.mobilefacenet)==null?void 0:d.enabled)&&!this.models.mobilefacenet?yn(this.instance.config):null,n.insightface=this.instance.config.face.enabled&&((p=this.instance.config.face.insightface)==null?void 0:p.enabled)&&!this.models.insightface?hn(this.instance.config):null,n.blazepose=this.instance.config.body.enabled&&!this.models.blazepose&&((f=this.instance.config.body.modelPath)==null?void 0:f.includes("blazepose"))?n3(this.instance.config):null,n.blazeposedetect=this.instance.config.body.enabled&&!this.models.blazeposedetect&&this.instance.config.body.detector&&this.instance.config.body.detector.modelPath?t3(this.instance.config):null,n.efficientpose=this.instance.config.body.enabled&&!this.models.efficientpose&&((b=this.instance.config.body.modelPath)==null?void 0:b.includes("efficientpose"))?i3(this.instance.config):null,n.movenet=this.instance.config.body.enabled&&!this.models.movenet&&((M=this.instance.config.body.modelPath)==null?void 0:M.includes("movenet"))?xo(this.instance.config):null,n.posenet=this.instance.config.body.enabled&&!this.models.posenet&&((T=this.instance.config.body.modelPath)==null?void 0:T.includes("posenet"))?Ro(this.instance.config):null,n.handtrack=this.instance.config.hand.enabled&&!this.models.handtrack&&((h=(m=this.instance.config.hand.detector)==null?void 0:m.modelPath)==null?void 0:h.includes("handtrack"))?$n(this.instance.config):null,n.handskeleton=this.instance.config.hand.enabled&&this.instance.config.hand.landmarks&&!this.models.handskeleton&&((P=(S=this.instance.config.hand.detector)==null?void 0:S.modelPath)==null?void 0:P.includes("handtrack"))?eo(this.instance.config):null,(q=(I=this.instance.config.hand.detector)==null?void 0:I.modelPath)!=null&&q.includes("handdetect")&&([n.handpose,n.handskeleton]=this.models.handpose?[null,null]:await Yn(this.instance.config)),n.centernet=this.instance.config.object.enabled&&!this.models.centernet&&((t0=this.instance.config.object.modelPath)==null?void 0:t0.includes("centernet"))?s3(this.instance.config):null,n.nanodet=this.instance.config.object.enabled&&!this.models.nanodet&&((G=this.instance.config.object.modelPath)==null?void 0:G.includes("nanodet"))?mo(this.instance.config):null,n.selfie=this.instance.config.segmentation.enabled&&!this.models.selfie&&(($=this.instance.config.segmentation.modelPath)==null?void 0:$.includes("selfie"))?T1(this.instance.config):null,n.meet=this.instance.config.segmentation.enabled&&!this.models.meet&&((A0=this.instance.config.segmentation.modelPath)==null?void 0:A0.includes("meet"))?A1(this.instance.config):null,n.rvm=this.instance.config.segmentation.enabled&&!this.models.rvm&&((v=this.instance.config.segmentation.modelPath)==null?void 0:v.includes("rvm"))?g1(this.instance.config):null;for(let[V,n0]of Object.entries(n))n0!=null&&n0.then&&n0.then(U=>this.models[V]=U);await Promise.all(Object.values(n))}list(){let t=Object.keys(this.models).map(n=>{var o;return{name:n,loaded:this.models[n]!==null,size:0,url:this.models[n]?(o=this.models[n])==null?void 0:o.modelUrl:null}});for(let n of t){let o=Object.keys(E0).find(r=>r.startsWith(n.name));!o||(n.size=E0[o].sizeLoadedWeights,n.url=E0[o].url)}return t}loaded(){return this.list().filter(o=>o.loaded).map(o=>o.name)}validate(){let t=[];for(let n of Object.keys(this.models)){let o=this.models[n];if(!o)continue;let r=Ht(this.instance,o,n);r&&t.push(r)}return t}};function jo(e,t,n,o,r){var a,l,c,x,i,y;let s=0,A=[];for(let d of e){let p={id:s++,face:d,body:null,hands:{left:null,right:null},gestures:[],box:[0,0,0,0]};for(let h of t)d.box[0]>h.box[0]&&d.box[0]h.box[1]&&d.box[1]+d.box[3]p.body.box[0]&&h.box[0]+h.box[2]p.body.box[1]&&h.box[1]+h.box[3]p.body.box[0]&&h.box[1]+h.box[3]>p.body.box[1]&&h.box[1]+h.box[3]{h&&h.length===4&&(f.push(h[0],h[0]+h[2]),b.push(h[1],h[1]+h[3]))};M(p.face.box),M((x=p.body)==null?void 0:x.box),M((i=p.hands.left)==null?void 0:i.box),M((y=p.hands.right)==null?void 0:y.box);let T=Math.min(...f),m=Math.min(...b);p.box=[T,m,Math.max(...f)-T,Math.max(...b)-m],(r==null?void 0:r[1])&&(r==null?void 0:r[2])&&(p.boxRaw=[p.box[0]/r[2],p.box[1]/r[1],p.box[2]/r[2],p.box[3]/r[1]]),A.push(p)}return A}var d0=Z(H());var Gt=` /9j/4AAQSkZJRgABAQEAYABgAAD/4QBoRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUA AAABAAAARgEoAAMAAAABAAIAAAExAAIAAAARAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQu bmV0IDQuMi4xMwAA/9sAQwAGBAUGBQQGBgUGBwcGCAoQCgoJCQoUDg8MEBcUGBgXFBYWGh0lHxob @@ -14136,8 +269,7 @@ PQ4GJ+ashuK0MhWaoWcA0AaOmASMK7jRNPWYBmHyiuepO2x10qfcv6vYxCzYqoGK4HVYVTJrmb5l c6oaM5TUJ8EgGsG4kLNUHT0M64OaqMMikSRsuKbnFMRLG3zVehOaGNE445NNlnVFpDMu6uie9Vo1 8z5mOAOST2pDK91cNN+5tsrH3PrW54a06KxT7fdrlh/q1Pc+tJ6IUdZGvHPLezMcnBOWbsPap5r3 ylFtbdT1xUWNWzU0/Zbwlgfmx8zGsHWtRHmMqE59aAMyNifvHPc1f0gtPdqkY5JosJHeNci2tktY -euPnNY+oXWZEVJNrZ9aun8SIq/CzodHuriIokhDIR1ronbKZr0o6o8ipoz//2Q==`; -var body3 = ` +euPnNY+oXWZEVJNrZ9aun8SIq/CzodHuriIokhDIR1ronbKZr0o6o8ipoz//2Q==`,Vt=` /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAsICAoIBwsKCQoNDAsNERwSEQ8PESIZGhQcKSQrKigk JyctMkA3LTA9MCcnOEw5PUNFSElIKzZPVU5GVEBHSEX/2wBDAQwNDREPESESEiFFLicuRUVFRUVF RUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUX/wAARCASwBLADASIA @@ -14705,563 +837,4 @@ AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp+bfwab+vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2 SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ -2Q==`; - -// src/warmup.ts -async function warmupBitmap(instance) { - const b64toBlob = (base64, type = "application/octet-stream") => fetch(`data:${type};base64,${base64}`).then((res2) => res2.blob()); - let blob; - let res; - switch (instance.config.warmup) { - case "face": - blob = await b64toBlob(face3); - break; - case "body": - case "full": - blob = await b64toBlob(body3); - break; - default: - blob = null; - } - if (blob) { - const bitmap = await createImageBitmap(blob); - res = await instance.detect(bitmap, instance.config); - bitmap.close(); - } - return res; -} -async function warmupCanvas(instance) { - return new Promise((resolve) => { - let src; - switch (instance.config.warmup) { - case "face": - src = "data:image/jpeg;base64," + face3; - break; - case "full": - case "body": - src = "data:image/jpeg;base64," + body3; - break; - default: - src = ""; - } - let img; - if (typeof Image !== "undefined") - img = new Image(); - else if (env.Image) - img = new env.Image(); - else { - resolve(void 0); - return; - } - img.onload = async () => { - const canvas3 = canvas(img.naturalWidth, img.naturalHeight); - if (!canvas3) { - log("Warmup: Canvas not found"); - resolve(void 0); - } else { - const ctx = canvas3.getContext("2d"); - if (ctx) - ctx.drawImage(img, 0, 0); - const tensor6 = await instance.image(canvas3, true); - const res = tensor6.tensor ? await instance.detect(tensor6.tensor, instance.config) : void 0; - resolve(res); - } - }; - if (src) - img.src = src; - else - resolve(void 0); - }); -} -async function warmupNode(instance) { - const atob = (str) => Buffer.from(str, "base64"); - let img; - if (instance.config.warmup === "face") - img = atob(face3); - else - img = atob(body3); - let res; - if ("node" in tf37 && tf37.getBackend() === "tensorflow") { - const data = tf37["node"].decodeJpeg(img); - const expanded = tf37.expandDims(data, 0); - instance.tf.dispose(data); - res = await instance.detect(expanded, instance.config); - instance.tf.dispose(expanded); - } else { - if (instance.config.debug) - log("Warmup tfjs-node not loaded"); - } - return res; -} -async function runInference(instance) { - let res; - if (typeof createImageBitmap === "function") - res = await warmupBitmap(instance); - else if (typeof Image !== "undefined" || env.Canvas !== void 0) - res = await warmupCanvas(instance); - else - res = await warmupNode(instance); - return res; -} -async function runCompile(instance) { - var _a, _b, _c, _d; - if (!tf37.env().flagRegistry.ENGINE_COMPILE_ONLY) - return; - const backendType = tf37.getBackend(); - const webGLBackend = tf37.backend(); - if (backendType !== "webgl" && backendType !== "humangl" || !(webGLBackend == null ? void 0 : webGLBackend["checkCompileCompletion"])) { - return; - } - tf37.env().set("ENGINE_COMPILE_ONLY", true); - const numTensorsStart = tf37.engine().state.numTensors; - const compiledModels = []; - for (const [modelName, model23] of Object.entries(instance.models.models)) { - if (!model23) - continue; - const shape = (model23 == null ? void 0 : model23.modelSignature) && ((_b = (_a = model23 == null ? void 0 : model23.inputs) == null ? void 0 : _a[0]) == null ? void 0 : _b.shape) ? [...model23.inputs[0].shape] : [1, 64, 64, 3]; - const dtype = (model23 == null ? void 0 : model23.modelSignature) && ((_d = (_c = model23 == null ? void 0 : model23.inputs) == null ? void 0 : _c[0]) == null ? void 0 : _d.dtype) ? model23.inputs[0].dtype : "float32"; - for (let dim = 0; dim < shape.length; dim++) { - if (shape[dim] === -1) - shape[dim] = dim === 0 ? 1 : 64; - } - const tensor6 = tf37.zeros(shape, dtype); - try { - const res = model23.execute(tensor6); - compiledModels.push(modelName); - if (Array.isArray(res)) - res.forEach((t2) => tf37.dispose(t2)); - else - tf37.dispose(res); - } catch (e) { - if (instance.config.debug) - log("compile fail model:", modelName); - } - tf37.dispose(tensor6); - } - const kernels = await webGLBackend["checkCompileCompletionAsync"](); - webGLBackend["getUniformLocations"](); - if (instance.config.debug) - log("compile pass:", { models: compiledModels, kernels: kernels.length }); - tf37.env().set("ENGINE_COMPILE_ONLY", false); - const numTensorsEnd = tf37.engine().state.numTensors; - if (numTensorsEnd - numTensorsStart > 0) - log("tensor leak:", numTensorsEnd - numTensorsStart); -} -async function warmup(instance, userConfig) { - await check(instance, false); - const t0 = now(); - instance.state = "warmup"; - if (userConfig) - instance.config = mergeDeep(instance.config, userConfig); - if (!instance.config.warmup || instance.config.warmup.length === 0 || instance.config.warmup === "none") { - return empty(); - } - return new Promise(async (resolve) => { - await instance.models.load(); - await runCompile(instance); - const res = await runInference(instance); - const t1 = now(); - if (instance.config.debug) - log("warmup", instance.config.warmup, Math.round(t1 - t0), "ms"); - instance.emit("warmup"); - resolve(res); - }); -} - -// src/human.ts -var _numTensors, _analyzeMemoryLeaks, _checkSanity, _sanity, _loops; -var Human = class { - constructor(userConfig) { - __publicField(this, "version"); - __publicField(this, "config"); - __publicField(this, "result"); - __publicField(this, "state"); - __publicField(this, "process"); - __publicField(this, "tf"); - __publicField(this, "env", env); - __publicField(this, "draw", draw_exports); - __publicField(this, "match", match_exports); - __publicField(this, "models"); - __publicField(this, "events"); - __publicField(this, "faceTriangulation"); - __publicField(this, "faceUVMap"); - __publicField(this, "performance"); - __privateAdd(this, _numTensors, void 0); - __privateAdd(this, _analyzeMemoryLeaks, void 0); - __privateAdd(this, _checkSanity, void 0); - __publicField(this, "analyze", (...msg) => { - if (!__privateGet(this, _analyzeMemoryLeaks)) - return; - const currentTensors = this.tf.engine().state.numTensors; - const previousTensors = __privateGet(this, _numTensors); - __privateSet(this, _numTensors, currentTensors); - const leaked = currentTensors - previousTensors; - if (leaked !== 0) - log(...msg, leaked); - }); - __privateAdd(this, _sanity, (input) => { - if (!__privateGet(this, _checkSanity)) - return null; - if (!input) - return "input is not defined"; - if (this.env.node && !(input instanceof tf38.Tensor)) - return "input must be a tensor"; - try { - this.tf.getBackend(); - } catch (e) { - return "backend not loaded"; - } - return null; - }); - __publicField(this, "webcam", new WebCam()); - __publicField(this, "emit", (event) => { - var _a; - if ((_a = this.events) == null ? void 0 : _a.dispatchEvent) - this.events.dispatchEvent(new Event(event)); - }); - __privateAdd(this, _loops, {}); - const tfVersion = (tf38.version.tfjs || tf38.version_core).replace(/-(.*)/, ""); - config.wasmPath = `https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${tfVersion}/dist/`; - config.modelBasePath = env.browser ? "../models/" : "file://models/"; - this.version = version2; - Object.defineProperty(this, "version", { value: version2 }); - this.config = JSON.parse(JSON.stringify(config)); - Object.seal(this.config); - this.config.cacheModels = typeof indexedDB !== "undefined"; - if (userConfig) - this.config = mergeDeep(this.config, userConfig); - setModelLoadOptions(this.config); - this.tf = tf38; - this.state = "idle"; - __privateSet(this, _numTensors, 0); - __privateSet(this, _analyzeMemoryLeaks, false); - __privateSet(this, _checkSanity, false); - this.performance = {}; - this.events = typeof EventTarget !== "undefined" ? new EventTarget() : void 0; - this.models = new Models(this); - init2(); - this.result = empty(); - this.process = { tensor: null, canvas: null }; - this.faceTriangulation = triangulation; - this.faceUVMap = uvmap; - validateModel(this, null, ""); - this.emit("create"); - if (this.config.debug || this.env.browser) - log(`version: ${this.version}`); - if (this.config.debug) - log(`tfjs version: ${this.tf.version["tfjs-core"]}`); - const envTemp = JSON.parse(JSON.stringify(this.env)); - delete envTemp.kernels; - delete envTemp.initial; - delete envTemp.perfadd; - if (this.config.debug) - log("environment:", envTemp); - } - reset() { - const currentBackend = this.config.backend; - this.config = JSON.parse(JSON.stringify(config)); - this.config.backend = currentBackend; - reset(); - env.initial = true; - } - validate(userConfig) { - const msgs = validate(config, userConfig || this.config); - if (msgs.length === 0) - this.config = mergeDeep(this.config, userConfig); - return msgs; - } - now() { - return now(); - } - image(input, getTensor = false) { - return process2(input, this.config, getTensor); - } - async segmentation(input, userConfig) { - var _a, _b, _c; - if (userConfig) - this.config = mergeDeep(this.config, userConfig); - if (!this.config.segmentation.enabled) - return null; - const processed = await process2(input, this.config); - if (!processed.tensor) - return null; - let tensor6 = null; - if ((_a = this.config.segmentation.modelPath) == null ? void 0 : _a.includes("rvm")) - tensor6 = await predict20(processed.tensor, this.config); - if ((_b = this.config.segmentation.modelPath) == null ? void 0 : _b.includes("meet")) - tensor6 = await predict16(processed.tensor, this.config); - if ((_c = this.config.segmentation.modelPath) == null ? void 0 : _c.includes("selfie")) - tensor6 = await predict21(processed.tensor, this.config); - tf38.dispose(processed.tensor); - return tensor6; - } - compare(firstImageTensor, secondImageTensor) { - return compare(this.config, firstImageTensor, secondImageTensor); - } - async init() { - await check(this, true); - await this.tf.ready(); - reset(); - } - async load(userConfig) { - this.state = "load"; - const timeStamp = now(); - const count2 = Object.values(this.models.models).filter((model23) => model23).length; - if (userConfig) - this.config = mergeDeep(this.config, userConfig); - if (this.env.initial) { - if (!await check(this, false)) - log("error: backend check failed"); - await tf38.ready(); - if (this.env.browser) { - if (this.config.debug) - log("configuration:", this.config); - if (this.config.debug) - log("tf flags:", this.tf.ENV.flags); - } - } - await this.models.load(this); - if (this.env.initial && this.config.debug) - log("tf engine state:", this.tf.engine().state.numBytes, "bytes", this.tf.engine().state.numTensors, "tensors"); - this.env.initial = false; - const loaded = Object.values(this.models.models).filter((model23) => model23).length; - if (loaded !== count2) { - this.models.validate(); - this.emit("load"); - } - const current = Math.trunc(now() - timeStamp); - if (current > (this.performance.loadModels || 0)) - this.performance.loadModels = this.env.perfadd ? (this.performance.loadModels || 0) + current : current; - } - next(result = this.result) { - return calc2(result, this.config); - } - async warmup(userConfig) { - const t0 = now(); - const res = await warmup(this, userConfig); - const t1 = now(); - this.performance.warmup = Math.trunc(t1 - t0); - return res; - } - async profile(input, userConfig) { - const profile = await this.tf.profile(() => this.detect(input, userConfig)); - const kernels = {}; - let total = 0; - for (const kernel of profile.kernels) { - const ms = Number(kernel.kernelTimeMs) || 0; - if (kernels[kernel.name]) - kernels[kernel.name] += ms; - else - kernels[kernel.name] = ms; - total += ms; - } - const kernelArr = []; - Object.entries(kernels).forEach((key) => kernelArr.push({ kernel: key[0], time: key[1], perc: 0 })); - for (const kernel of kernelArr) { - kernel.perc = Math.round(1e3 * kernel.time / total) / 1e3; - kernel.time = Math.round(1e3 * kernel.time) / 1e3; - } - kernelArr.sort((a, b) => b.time - a.time); - kernelArr.length = 20; - return kernelArr; - } - async detect(input, userConfig) { - this.state = "detect"; - return new Promise(async (resolve) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u; - this.state = "config"; - let timeStamp; - this.config = mergeDeep(this.config, userConfig); - this.state = "check"; - const error = __privateGet(this, _sanity).call(this, input); - if (error) { - log(error, input); - this.emit("error"); - resolve(empty(error)); - } - const timeStart = now(); - await this.load(); - timeStamp = now(); - this.state = "image"; - const img = await process2(input, this.config); - this.process = img; - this.performance.inputProcess = this.env.perfadd ? (this.performance.inputProcess || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - this.analyze("Get Image:"); - if (!img.tensor) { - if (this.config.debug) - log("could not convert input to tensor"); - this.emit("error"); - resolve(empty("could not convert input to tensor")); - return; - } - this.emit("image"); - timeStamp = now(); - this.config.skipAllowed = await skip(this.config, img.tensor); - this.config.filter.autoBrightness = (this.config.filter.autoBrightness || false) && this.config.skipAllowed; - if (!this.performance.totalFrames) - this.performance.totalFrames = 0; - if (!this.performance.cachedFrames) - this.performance.cachedFrames = 0; - this.performance.totalFrames++; - if (this.config.skipAllowed) - this.performance.cachedFrames++; - this.performance.cacheCheck = this.env.perfadd ? (this.performance.cacheCheck || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - this.analyze("Check Changed:"); - let faceRes = []; - let bodyRes = []; - let handRes = []; - let objectRes = []; - this.state = "detect:face"; - if (this.config.async) { - faceRes = this.config.face.enabled ? detectFace(this, img.tensor) : []; - if (this.performance.face) - delete this.performance.face; - } else { - timeStamp = now(); - faceRes = this.config.face.enabled ? await detectFace(this, img.tensor) : []; - this.performance.face = this.env.perfadd ? (this.performance.face || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - if (this.config.async && (this.config.body.maxDetected === -1 || this.config.hand.maxDetected === -1)) - faceRes = await faceRes; - this.analyze("Start Body:"); - this.state = "detect:body"; - const bodyConfig = this.config.body.maxDetected === -1 ? mergeDeep(this.config, { body: { maxDetected: this.config.face.enabled ? 1 * faceRes.length : 1 } }) : this.config; - if (this.config.async) { - if ((_a = this.config.body.modelPath) == null ? void 0 : _a.includes("posenet")) - bodyRes = this.config.body.enabled ? predict19(img.tensor, bodyConfig) : []; - else if ((_b = this.config.body.modelPath) == null ? void 0 : _b.includes("blazepose")) - bodyRes = this.config.body.enabled ? predict(img.tensor, bodyConfig) : []; - else if ((_c = this.config.body.modelPath) == null ? void 0 : _c.includes("efficientpose")) - bodyRes = this.config.body.enabled ? predict3(img.tensor, bodyConfig) : []; - else if ((_d = this.config.body.modelPath) == null ? void 0 : _d.includes("movenet")) - bodyRes = this.config.body.enabled ? predict17(img.tensor, bodyConfig) : []; - if (this.performance.body) - delete this.performance.body; - } else { - timeStamp = now(); - if ((_e = this.config.body.modelPath) == null ? void 0 : _e.includes("posenet")) - bodyRes = this.config.body.enabled ? await predict19(img.tensor, bodyConfig) : []; - else if ((_f = this.config.body.modelPath) == null ? void 0 : _f.includes("blazepose")) - bodyRes = this.config.body.enabled ? await predict(img.tensor, bodyConfig) : []; - else if ((_g = this.config.body.modelPath) == null ? void 0 : _g.includes("efficientpose")) - bodyRes = this.config.body.enabled ? await predict3(img.tensor, bodyConfig) : []; - else if ((_h = this.config.body.modelPath) == null ? void 0 : _h.includes("movenet")) - bodyRes = this.config.body.enabled ? await predict17(img.tensor, bodyConfig) : []; - this.performance.body = this.env.perfadd ? (this.performance.body || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - this.analyze("End Body:"); - this.analyze("Start Hand:"); - this.state = "detect:hand"; - const handConfig = this.config.hand.maxDetected === -1 ? mergeDeep(this.config, { hand: { maxDetected: this.config.face.enabled ? 2 * faceRes.length : 1 } }) : this.config; - if (this.config.async) { - if ((_j = (_i = this.config.hand.detector) == null ? void 0 : _i.modelPath) == null ? void 0 : _j.includes("handdetect")) - handRes = this.config.hand.enabled ? predict14(img.tensor, handConfig) : []; - else if ((_l = (_k = this.config.hand.detector) == null ? void 0 : _k.modelPath) == null ? void 0 : _l.includes("handtrack")) - handRes = this.config.hand.enabled ? predict15(img.tensor, handConfig) : []; - if (this.performance.hand) - delete this.performance.hand; - } else { - timeStamp = now(); - if ((_n = (_m = this.config.hand.detector) == null ? void 0 : _m.modelPath) == null ? void 0 : _n.includes("handdetect")) - handRes = this.config.hand.enabled ? await predict14(img.tensor, handConfig) : []; - else if ((_p = (_o = this.config.hand.detector) == null ? void 0 : _o.modelPath) == null ? void 0 : _p.includes("handtrack")) - handRes = this.config.hand.enabled ? await predict15(img.tensor, handConfig) : []; - this.performance.hand = this.env.perfadd ? (this.performance.hand || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - this.analyze("End Hand:"); - this.analyze("Start Object:"); - this.state = "detect:object"; - if (this.config.async) { - if ((_q = this.config.object.modelPath) == null ? void 0 : _q.includes("nanodet")) - objectRes = this.config.object.enabled ? predict18(img.tensor, this.config) : []; - else if ((_r = this.config.object.modelPath) == null ? void 0 : _r.includes("centernet")) - objectRes = this.config.object.enabled ? predict2(img.tensor, this.config) : []; - if (this.performance.object) - delete this.performance.object; - } else { - timeStamp = now(); - if ((_s = this.config.object.modelPath) == null ? void 0 : _s.includes("nanodet")) - objectRes = this.config.object.enabled ? await predict18(img.tensor, this.config) : []; - else if ((_t = this.config.object.modelPath) == null ? void 0 : _t.includes("centernet")) - objectRes = this.config.object.enabled ? await predict2(img.tensor, this.config) : []; - this.performance.object = this.env.perfadd ? (this.performance.object || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - this.analyze("End Object:"); - this.state = "detect:await"; - if (this.config.async) - [faceRes, bodyRes, handRes, objectRes] = await Promise.all([faceRes, bodyRes, handRes, objectRes]); - this.state = "detect:gesture"; - let gestureRes = []; - if (this.config.gesture.enabled) { - timeStamp = now(); - gestureRes = [...face2(faceRes), ...body2(bodyRes), ...hand2(handRes), ...iris2(faceRes)]; - if (!this.config.async) - this.performance.gesture = this.env.perfadd ? (this.performance.gesture || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - else if (this.performance.gesture) - delete this.performance.gesture; - } - this.performance.total = this.env.perfadd ? (this.performance.total || 0) + Math.trunc(now() - timeStart) : Math.trunc(now() - timeStart); - const shape = ((_u = this.process.tensor) == null ? void 0 : _u.shape) || [0, 0, 0, 0]; - this.result = { - face: faceRes, - body: bodyRes, - hand: handRes, - gesture: gestureRes, - object: objectRes, - performance: this.performance, - canvas: this.process.canvas, - timestamp: Date.now(), - error: null, - width: shape[2], - height: shape[1], - get persons() { - return join2(faceRes, bodyRes, handRes, gestureRes, shape); - } - }; - tf38.dispose(img.tensor); - this.emit("detect"); - this.state = "idle"; - resolve(this.result); - }); - } - async sleep(ms) { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); - } - async video(element, run = true, delay = 0) { - if (run) { - if (!__privateGet(this, _loops)[element.id]) { - if (this.config.debug) - log("video start", element.id); - __privateGet(this, _loops)[element.id] = true; - } - if (!element.paused && __privateGet(this, _loops)[element.id] && element.readyState >= 2) - await this.detect(element); - if (delay > 0) - await this.sleep(delay); - if (__privateGet(this, _loops)[element.id]) - requestAnimationFrame(() => this.video(element, run, delay)); - } else { - if (this.config.debug) - log("video stop", element.id); - __privateGet(this, _loops)[element.id] = false; - } - } -}; -_numTensors = new WeakMap(); -_analyzeMemoryLeaks = new WeakMap(); -_checkSanity = new WeakMap(); -_sanity = new WeakMap(); -_loops = new WeakMap(); -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = { - Env, - Human, - defaults, - draw, - empty, - env, - match, - models -}); +2Q==`;async function sa(e){let t=(r,s="application/octet-stream")=>fetch(`data:${s};base64,${r}`).then(A=>A.blob()),n,o;switch(e.config.warmup){case"face":n=await t(Gt);break;case"body":case"full":n=await t(Vt);break;default:n=null}if(n){let r=await createImageBitmap(n);o=await e.detect(r,e.config),r.close()}return o}async function Aa(e){return new Promise(t=>{let n;switch(e.config.warmup){case"face":n="data:image/jpeg;base64,"+Gt;break;case"full":case"body":n="data:image/jpeg;base64,"+Vt;break;default:n=""}let o;if(typeof Image!="undefined")o=new Image;else if(R.Image)o=new R.Image;else{t(void 0);return}o.onload=async()=>{let r=te(o.naturalWidth,o.naturalHeight);if(!r)u("Warmup: Canvas not found"),t(void 0);else{let s=r.getContext("2d");s&&s.drawImage(o,0,0);let A=await e.image(r,!0),a=A.tensor?await e.detect(A.tensor,e.config):void 0;t(a)}},n?o.src=n:t(void 0)})}async function aa(e){let t=r=>Buffer.from(r,"base64"),n;e.config.warmup==="face"?n=t(Gt):n=t(Vt);let o;if("node"in d0&&d0.getBackend()==="tensorflow"){let r=d0.node.decodeJpeg(n),s=d0.expandDims(r,0);e.tf.dispose(r),o=await e.detect(s,e.config),e.tf.dispose(s)}else e.config.debug&&u("Warmup tfjs-node not loaded");return o}async function ia(e){let t;return typeof createImageBitmap=="function"?t=await sa(e):typeof Image!="undefined"||R.Canvas!==void 0?t=await Aa(e):t=await aa(e),t}async function la(e){var a,l,c,x;if(!d0.env().flagRegistry.ENGINE_COMPILE_ONLY)return;let t=d0.getBackend(),n=d0.backend();if(t!=="webgl"&&t!=="humangl"||!(n!=null&&n.checkCompileCompletion))return;d0.env().set("ENGINE_COMPILE_ONLY",!0);let o=d0.engine().state.numTensors,r=[];for(let[i,y]of Object.entries(e.models.models)){if(!y)continue;let d=(y==null?void 0:y.modelSignature)&&((l=(a=y==null?void 0:y.inputs)==null?void 0:a[0])==null?void 0:l.shape)?[...y.inputs[0].shape]:[1,64,64,3],p=(y==null?void 0:y.modelSignature)&&((x=(c=y==null?void 0:y.inputs)==null?void 0:c[0])==null?void 0:x.dtype)?y.inputs[0].dtype:"float32";for(let b=0;bd0.dispose(M)):d0.dispose(b)}catch(b){e.config.debug&&u("compile fail model:",i)}d0.dispose(f)}let s=await n.checkCompileCompletionAsync();n.getUniformLocations(),e.config.debug&&u("compile pass:",{models:r,kernels:s.length}),d0.env().set("ENGINE_COMPILE_ONLY",!1);let A=d0.engine().state.numTensors;A-o>0&&u("tensor leak:",A-o)}async function No(e,t){await I2(e,!1);let n=g();return e.state="warmup",t&&(e.config=a0(e.config,t)),!e.config.warmup||e.config.warmup.length===0||e.config.warmup==="none"?he():new Promise(async o=>{await e.models.load(),await la(e);let r=await ia(e),s=g();e.config.debug&&u("warmup",e.config.warmup,Math.round(s-n),"ms"),e.emit("warmup"),o(r)})}var M2,G2,V2,Zt,Ue,R1=class{constructor(t){k(this,"version");k(this,"config");k(this,"result");k(this,"state");k(this,"process");k(this,"tf");k(this,"env",R);k(this,"draw",nt);k(this,"match",Ot);k(this,"models");k(this,"events");k(this,"faceTriangulation");k(this,"faceUVMap");k(this,"performance");me(this,M2,void 0);me(this,G2,void 0);me(this,V2,void 0);k(this,"analyze",(...t)=>{if(!G0(this,G2))return;let n=this.tf.engine().state.numTensors,o=G0(this,M2);ge(this,M2,n);let r=n-o;r!==0&&u(...t,r)});me(this,Zt,t=>{if(!G0(this,V2))return null;if(!t)return"input is not defined";if(this.env.node&&!(t instanceof ae.Tensor))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});k(this,"webcam",new K2);k(this,"emit",t=>{var n;(n=this.events)!=null&&n.dispatchEvent&&this.events.dispatchEvent(new Event(t))});me(this,Ue,{});let n=(ae.version.tfjs||ae.version_core).replace(/-(.*)/,"");Ye.wasmPath=`https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${n}/dist/`,Ye.modelBasePath=R.browser?"../models/":"file://models/",this.version=$t,Object.defineProperty(this,"version",{value:$t}),this.config=JSON.parse(JSON.stringify(Ye)),Object.seal(this.config),this.config.cacheModels=typeof indexedDB!="undefined",t&&(this.config=a0(this.config,t)),B1(this.config),this.tf=ae,this.state="idle",ge(this,M2,0),ge(this,G2,!1),ge(this,V2,!1),this.performance={},this.events=typeof EventTarget!="undefined"?new EventTarget:void 0,this.models=new H2(this),A5(),this.result=he(),this.process={tensor:null,canvas:null},this.faceTriangulation=N3,this.faceUVMap=I3,Ht(this,null,""),this.emit("create"),(this.config.debug||this.env.browser)&&u(`version: ${this.version}`),this.config.debug&&u(`tfjs version: ${this.tf.version["tfjs-core"]}`);let o=JSON.parse(JSON.stringify(this.env));delete o.kernels,delete o.initial,delete o.perfadd,this.config.debug&&u("environment:",o)}reset(){let t=this.config.backend;this.config=JSON.parse(JSON.stringify(Ye)),this.config.backend=t,Qt(),R.initial=!0}validate(t){let n=Yt(Ye,t||this.config);return n.length===0&&(this.config=a0(this.config,t)),n}now(){return g()}image(t,n=!1){return U2(t,this.config,n)}async segmentation(t,n){var s,A,a;if(n&&(this.config=a0(this.config,n)),!this.config.segmentation.enabled)return null;let o=await U2(t,this.config);if(!o.tensor)return null;let r=null;return(s=this.config.segmentation.modelPath)!=null&&s.includes("rvm")&&(r=await wo(o.tensor,this.config)),(A=this.config.segmentation.modelPath)!=null&&A.includes("meet")&&(r=await oo(o.tensor,this.config)),(a=this.config.segmentation.modelPath)!=null&&a.includes("selfie")&&(r=await zo(o.tensor,this.config)),ae.dispose(o.tensor),r}compare(t,n){return F1(this.config,t,n)}async init(){await I2(this,!0),await this.tf.ready(),Qt()}async load(t){this.state="load";let n=g(),o=Object.values(this.models.models).filter(A=>A).length;t&&(this.config=a0(this.config,t)),this.env.initial&&(await I2(this,!1)||u("error: backend check failed"),await ae.ready(),this.env.browser&&(this.config.debug&&u("configuration:",this.config),this.config.debug&&u("tf flags:",this.tf.ENV.flags))),await this.models.load(this),this.env.initial&&this.config.debug&&u("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),this.env.initial=!1,Object.values(this.models.models).filter(A=>A).length!==o&&(this.models.validate(),this.emit("load"));let s=Math.trunc(g()-n);s>(this.performance.loadModels||0)&&(this.performance.loadModels=this.env.perfadd?(this.performance.loadModels||0)+s:s)}next(t=this.result){return no(t,this.config)}async warmup(t){let n=g(),o=await No(this,t),r=g();return this.performance.warmup=Math.trunc(r-n),o}async profile(t,n){let o=await this.tf.profile(()=>this.detect(t,n)),r={},s=0;for(let a of o.kernels){let l=Number(a.kernelTimeMs)||0;r[a.name]?r[a.name]+=l:r[a.name]=l,s+=l}let A=[];Object.entries(r).forEach(a=>A.push({kernel:a[0],time:a[1],perc:0}));for(let a of A)a.perc=Math.round(1e3*a.time/s)/1e3,a.time=Math.round(1e3*a.time)/1e3;return A.sort((a,l)=>l.time-a.time),A.length=20,A}async detect(t,n){return this.state="detect",new Promise(async o=>{var b,M,T,m,h,S,P,I,q,t0,G,$,A0,v,V,n0,U,g0,m0,B,X;this.state="config";let r;this.config=a0(this.config,n),this.state="check";let s=G0(this,Zt).call(this,t);s&&(u(s,t),this.emit("error"),o(he(s)));let A=g();await this.load(),r=g(),this.state="image";let a=await U2(t,this.config);if(this.process=a,this.performance.inputProcess=this.env.perfadd?(this.performance.inputProcess||0)+Math.trunc(g()-r):Math.trunc(g()-r),this.analyze("Get Image:"),!a.tensor){this.config.debug&&u("could not convert input to tensor"),this.emit("error"),o(he("could not convert input to tensor"));return}this.emit("image"),r=g(),this.config.skipAllowed=await D1(this.config,a.tensor),this.config.filter.autoBrightness=(this.config.filter.autoBrightness||!1)&&this.config.skipAllowed,this.performance.totalFrames||(this.performance.totalFrames=0),this.performance.cachedFrames||(this.performance.cachedFrames=0),this.performance.totalFrames++,this.config.skipAllowed&&this.performance.cachedFrames++,this.performance.cacheCheck=this.env.perfadd?(this.performance.cacheCheck||0)+Math.trunc(g()-r):Math.trunc(g()-r),this.analyze("Check Changed:");let l=[],c=[],x=[],i=[];this.state="detect:face",this.config.async?(l=this.config.face.enabled?U5(this,a.tensor):[],this.performance.face&&delete this.performance.face):(r=g(),l=this.config.face.enabled?await U5(this,a.tensor):[],this.performance.face=this.env.perfadd?(this.performance.face||0)+Math.trunc(g()-r):Math.trunc(g()-r)),this.config.async&&(this.config.body.maxDetected===-1||this.config.hand.maxDetected===-1)&&(l=await l),this.analyze("Start Body:"),this.state="detect:body";let y=this.config.body.maxDetected===-1?a0(this.config,{body:{maxDetected:this.config.face.enabled?1*l.length:1}}):this.config;this.config.async?((b=this.config.body.modelPath)!=null&&b.includes("posenet")?c=this.config.body.enabled?u1(a.tensor,y):[]:(M=this.config.body.modelPath)!=null&&M.includes("blazepose")?c=this.config.body.enabled?d5(a.tensor,y):[]:(T=this.config.body.modelPath)!=null&&T.includes("efficientpose")?c=this.config.body.enabled?h5(a.tensor,y):[]:(m=this.config.body.modelPath)!=null&&m.includes("movenet")&&(c=this.config.body.enabled?c1(a.tensor,y):[]),this.performance.body&&delete this.performance.body):(r=g(),(h=this.config.body.modelPath)!=null&&h.includes("posenet")?c=this.config.body.enabled?await u1(a.tensor,y):[]:(S=this.config.body.modelPath)!=null&&S.includes("blazepose")?c=this.config.body.enabled?await d5(a.tensor,y):[]:(P=this.config.body.modelPath)!=null&&P.includes("efficientpose")?c=this.config.body.enabled?await h5(a.tensor,y):[]:(I=this.config.body.modelPath)!=null&&I.includes("movenet")&&(c=this.config.body.enabled?await c1(a.tensor,y):[]),this.performance.body=this.env.perfadd?(this.performance.body||0)+Math.trunc(g()-r):Math.trunc(g()-r)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.state="detect:hand";let d=this.config.hand.maxDetected===-1?a0(this.config,{hand:{maxDetected:this.config.face.enabled?2*l.length:1}}):this.config;this.config.async?((t0=(q=this.config.hand.detector)==null?void 0:q.modelPath)!=null&&t0.includes("handdetect")?x=this.config.hand.enabled?_5(a.tensor,d):[]:($=(G=this.config.hand.detector)==null?void 0:G.modelPath)!=null&&$.includes("handtrack")&&(x=this.config.hand.enabled?t1(a.tensor,d):[]),this.performance.hand&&delete this.performance.hand):(r=g(),(v=(A0=this.config.hand.detector)==null?void 0:A0.modelPath)!=null&&v.includes("handdetect")?x=this.config.hand.enabled?await _5(a.tensor,d):[]:(n0=(V=this.config.hand.detector)==null?void 0:V.modelPath)!=null&&n0.includes("handtrack")&&(x=this.config.hand.enabled?await t1(a.tensor,d):[]),this.performance.hand=this.env.perfadd?(this.performance.hand||0)+Math.trunc(g()-r):Math.trunc(g()-r)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.state="detect:object",this.config.async?((U=this.config.object.modelPath)!=null&&U.includes("nanodet")?i=this.config.object.enabled?x1(a.tensor,this.config):[]:(g0=this.config.object.modelPath)!=null&&g0.includes("centernet")&&(i=this.config.object.enabled?f5(a.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(r=g(),(m0=this.config.object.modelPath)!=null&&m0.includes("nanodet")?i=this.config.object.enabled?await x1(a.tensor,this.config):[]:(B=this.config.object.modelPath)!=null&&B.includes("centernet")&&(i=this.config.object.enabled?await f5(a.tensor,this.config):[]),this.performance.object=this.env.perfadd?(this.performance.object||0)+Math.trunc(g()-r):Math.trunc(g()-r)),this.analyze("End Object:"),this.state="detect:await",this.config.async&&([l,c,x,i]=await Promise.all([l,c,x,i])),this.state="detect:gesture";let p=[];this.config.gesture.enabled&&(r=g(),p=[...jn(l),...Sn(c),...In(x),...Nn(l)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=this.env.perfadd?(this.performance.gesture||0)+Math.trunc(g()-r):Math.trunc(g()-r)),this.performance.total=this.env.perfadd?(this.performance.total||0)+Math.trunc(g()-A):Math.trunc(g()-A);let f=((X=this.process.tensor)==null?void 0:X.shape)||[0,0,0,0];this.result={face:l,body:c,hand:x,gesture:p,object:i,performance:this.performance,canvas:this.process.canvas,timestamp:Date.now(),error:null,width:f[2],height:f[1],get persons(){return jo(l,c,x,p,f)}},ae.dispose(a.tensor),this.emit("detect"),this.state="idle",o(this.result)})}async sleep(t){return new Promise(n=>{setTimeout(n,t)})}async video(t,n=!0,o=0){n?(G0(this,Ue)[t.id]||(this.config.debug&&u("video start",t.id),G0(this,Ue)[t.id]=!0),!t.paused&&G0(this,Ue)[t.id]&&t.readyState>=2&&await this.detect(t),o>0&&await this.sleep(o),G0(this,Ue)[t.id]&&requestAnimationFrame(()=>this.video(t,n,o))):(this.config.debug&&u("video stop",t.id),G0(this,Ue)[t.id]=!1)}};M2=new WeakMap,G2=new WeakMap,V2=new WeakMap,Zt=new WeakMap,Ue=new WeakMap;0&&(module.exports={Env,Human,defaults,draw,empty,env,match,models}); diff --git a/dist/human.node.js b/dist/human.node.js index 41bccddb..aabc2f7f 100644 --- a/dist/human.node.js +++ b/dist/human.node.js @@ -4,316 +4,7 @@ author: ' */ -"use strict"; -var __create = Object.create; -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __getProtoOf = Object.getPrototypeOf; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; -var __commonJS = (cb, mod3) => function __require() { - return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports; -}; -var __export = (target, all2) => { - for (var name in all2) - __defProp(target, name, { get: all2[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toESM = (mod3, isNodeMode, target) => (target = mod3 != null ? __create(__getProtoOf(mod3)) : {}, __copyProps( - isNodeMode || !mod3 || !mod3.__esModule ? __defProp(target, "default", { value: mod3, enumerable: true }) : target, - mod3 -)); -var __toCommonJS = (mod3) => __copyProps(__defProp({}, "__esModule", { value: true }), mod3); -var __publicField = (obj, key, value) => { - __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); - return value; -}; -var __accessCheck = (obj, member, msg) => { - if (!member.has(obj)) - throw TypeError("Cannot " + msg); -}; -var __privateGet = (obj, member, getter) => { - __accessCheck(obj, member, "read from private field"); - return getter ? getter.call(obj) : member.get(obj); -}; -var __privateAdd = (obj, member, value) => { - if (member.has(obj)) - throw TypeError("Cannot add the same private member more than once"); - member instanceof WeakSet ? member.add(obj) : member.set(obj, value); -}; -var __privateSet = (obj, member, value, setter) => { - __accessCheck(obj, member, "write to private field"); - setter ? setter.call(obj, value) : member.set(obj, value); - return value; -}; - -// dist/tfjs.esm.js -var require_tfjs_esm = __commonJS({ - "dist/tfjs.esm.js"(exports, module2) { - "use strict"; - var __defProp2 = Object.defineProperty; - var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor; - var __getOwnPropNames2 = Object.getOwnPropertyNames; - var __hasOwnProp2 = Object.prototype.hasOwnProperty; - var __export2 = (target, all2) => { - for (var name in all2) - __defProp2(target, name, { get: all2[name], enumerable: true }); - }; - var __copyProps2 = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames2(from)) - if (!__hasOwnProp2.call(to, key) && key !== except) - __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable }); - } - return to; - }; - var __reExport = (target, mod3, secondTarget) => (__copyProps2(target, mod3, "default"), secondTarget && __copyProps2(secondTarget, mod3, "default")); - var __toCommonJS2 = (mod3) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod3); - var tf_node_exports = {}; - __export2(tf_node_exports, { - version: () => version7 - }); - module2.exports = __toCommonJS2(tf_node_exports); - __reExport(tf_node_exports, require("@tensorflow/tfjs-node"), module2.exports); - var version4 = "4.2.0"; - var version22 = "4.2.0"; - var version32 = "4.2.0"; - var version42 = "4.2.0"; - var version5 = "4.2.0"; - var version6 = "0.0.1-alpha.17"; - var version7 = { - tfjs: version4, - "tfjs-core": version4, - "tfjs-converter": version22, - "tfjs-backend-cpu": version32, - "tfjs-backend-webgl": version42, - "tfjs-backend-wasm": version5, - "tfjs-backend-webgpu": version6 - }; - } -}); - -// src/human.ts -var human_exports = {}; -__export(human_exports, { - Env: () => Env, - Human: () => Human, - default: () => Human, - defaults: () => config, - draw: () => draw_exports, - empty: () => empty, - env: () => env, - match: () => match_exports, - models: () => models_exports2 -}); -module.exports = __toCommonJS(human_exports); -var tf38 = __toESM(require_tfjs_esm()); - -// src/util/util.ts -function log(...msg) { - const dt = new Date(); - const ts = `${dt.getHours().toString().padStart(2, "0")}:${dt.getMinutes().toString().padStart(2, "0")}:${dt.getSeconds().toString().padStart(2, "0")}.${dt.getMilliseconds().toString().padStart(3, "0")}`; - if (msg) - console.log(ts, "Human:", ...msg); -} -function join(folder, file) { - const separator = folder.endsWith("/") ? "" : "/"; - const skipJoin = file.startsWith(".") || file.startsWith("/") || file.startsWith("http:") || file.startsWith("https:") || file.startsWith("file:"); - const path = skipJoin ? `${file}` : `${folder}${separator}${file}`; - if (!path.toLocaleLowerCase().includes(".json")) - throw new Error(`modelpath error: expecting json file: ${path}`); - return path; -} -var now = () => { - if (typeof performance !== "undefined") - return performance.now(); - return parseInt((Number(process.hrtime.bigint()) / 1e3 / 1e3).toString()); -}; -function validate(defaults, config3, parent = "config", msgs = []) { - for (const key of Object.keys(config3)) { - if (typeof config3[key] === "object") { - validate(defaults[key], config3[key], key, msgs); - } else { - const defined = defaults && typeof defaults[key] !== "undefined"; - if (!defined) - msgs.push({ reason: "unknown property", where: `${parent}.${key} = ${config3[key]}` }); - const same = defaults && typeof defaults[key] === typeof config3[key]; - if (defined && !same) - msgs.push({ reason: "property type mismatch", where: `${parent}.${key} = ${config3[key]}`, expected: typeof defaults[key] }); - } - } - if (config3.debug && parent === "config" && msgs.length > 0) - log("invalid configuration", msgs); - return msgs; -} -function mergeDeep(...objects) { - const isObject = (obj) => obj && typeof obj === "object"; - return objects.reduce((prev, obj) => { - Object.keys(obj || {}).forEach((key) => { - const pVal = prev[key]; - const oVal = obj[key]; - if (Array.isArray(pVal) && Array.isArray(oVal)) - prev[key] = pVal.concat(...oVal); - else if (isObject(pVal) && isObject(oVal)) - prev[key] = mergeDeep(pVal, oVal); - else - prev[key] = oVal; - }); - return prev; - }, {}); -} - -// src/config.ts -var config = { - backend: "", - modelBasePath: "", - cacheModels: true, - validateModels: true, - wasmPath: "", - wasmPlatformFetch: false, - debug: false, - async: true, - warmup: "full", - cacheSensitivity: 0.7, - skipAllowed: false, - deallocate: false, - flags: {}, - softwareKernels: false, - filter: { - enabled: true, - equalization: false, - width: 0, - height: 0, - flip: false, - return: true, - autoBrightness: true, - brightness: 0, - contrast: 0, - sharpness: 0, - blur: 0, - saturation: 0, - hue: 0, - negative: false, - sepia: false, - vintage: false, - kodachrome: false, - technicolor: false, - polaroid: false, - pixelate: 0 - }, - gesture: { - enabled: true - }, - face: { - enabled: true, - detector: { - modelPath: "blazeface.json", - rotation: false, - maxDetected: 1, - skipFrames: 99, - skipTime: 2500, - minConfidence: 0.2, - iouThreshold: 0.1, - mask: false, - return: false - }, - mesh: { - enabled: true, - modelPath: "facemesh.json", - keepInvalid: false - }, - attention: { - enabled: false, - modelPath: "facemesh-attention.json" - }, - iris: { - enabled: true, - modelPath: "iris.json" - }, - emotion: { - enabled: true, - minConfidence: 0.1, - skipFrames: 99, - skipTime: 1500, - modelPath: "emotion.json" - }, - description: { - enabled: true, - modelPath: "faceres.json", - skipFrames: 99, - skipTime: 3e3, - minConfidence: 0.1 - }, - antispoof: { - enabled: false, - skipFrames: 99, - skipTime: 4e3, - modelPath: "antispoof.json" - }, - liveness: { - enabled: false, - skipFrames: 99, - skipTime: 4e3, - modelPath: "liveness.json" - } - }, - body: { - enabled: true, - modelPath: "movenet-lightning.json", - maxDetected: -1, - minConfidence: 0.3, - skipFrames: 1, - skipTime: 200 - }, - hand: { - enabled: true, - rotation: true, - skipFrames: 99, - skipTime: 1e3, - minConfidence: 0.5, - iouThreshold: 0.2, - maxDetected: -1, - landmarks: true, - detector: { - modelPath: "handtrack.json" - }, - skeleton: { - modelPath: "handlandmark-lite.json" - } - }, - object: { - enabled: false, - modelPath: "centernet.json", - minConfidence: 0.2, - iouThreshold: 0.4, - maxDetected: 10, - skipFrames: 99, - skipTime: 2e3 - }, - segmentation: { - enabled: false, - modelPath: "rvm.json", - ratio: 0.5, - mode: "default" - } -}; - -// src/util/env.ts -var tf3 = __toESM(require_tfjs_esm()); - -// src/image/image.ts -var tf2 = __toESM(require_tfjs_esm()); - -// src/image/imagefxshaders.ts -var vertexIdentity = ` +"use strict";var No=Object.create;var k2=Object.defineProperty;var Io=Object.getOwnPropertyDescriptor;var Oo=Object.getOwnPropertyNames;var Lo=Object.getPrototypeOf,Co=Object.prototype.hasOwnProperty;var Wo=(e,t,n)=>t in e?k2(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Do=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ze=(e,t)=>{for(var n in t)k2(e,n,{get:t[n],enumerable:!0})},k1=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Oo(t))!Co.call(e,r)&&r!==n&&k2(e,r,{get:()=>t[r],enumerable:!(o=Io(t,r))||o.enumerable});return e};var Z=(e,t,n)=>(n=e!=null?No(Lo(e)):{},k1(t||!e||!e.__esModule?k2(n,"default",{value:e,enumerable:!0}):n,e)),Fo=e=>k1(k2({},"__esModule",{value:!0}),e);var k=(e,t,n)=>(Wo(e,typeof t!="symbol"?t+"":t,n),n),w1=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)};var G0=(e,t,n)=>(w1(e,t,"read from private field"),n?n.call(e):t.get(e)),me=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},ge=(e,t,n,o)=>(w1(e,t,"write to private field"),o?o.call(e,n):t.set(e,n),n);var H=Do((ya,qt)=>{"use strict";var Zt=Object.defineProperty,Bo=Object.getOwnPropertyDescriptor,Ho=Object.getOwnPropertyNames,Go=Object.prototype.hasOwnProperty,Vo=(e,t)=>{for(var n in t)Zt(e,n,{get:t[n],enumerable:!0})},Vt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ho(t))!Go.call(e,r)&&r!==n&&Zt(e,r,{get:()=>t[r],enumerable:!(o=Bo(t,r))||o.enumerable});return e},Zo=(e,t,n)=>(Vt(e,t,"default"),n&&Vt(n,t,"default")),Xo=e=>Vt(Zt({},"__esModule",{value:!0}),e),Xt={};Vo(Xt,{version:()=>Qo});qt.exports=Xo(Xt);Zo(Xt,require("@tensorflow/tfjs-node"),qt.exports);var E1="4.2.0",qo="4.2.0",Uo="4.2.0",Yo="4.2.0",Ko="4.2.0",Jo="0.0.1-alpha.17",Qo={tfjs:E1,"tfjs-core":E1,"tfjs-converter":qo,"tfjs-backend-cpu":Uo,"tfjs-backend-webgl":Yo,"tfjs-backend-wasm":Ko,"tfjs-backend-webgpu":Jo}});var da={};ze(da,{Env:()=>w2,Human:()=>v1,default:()=>v1,defaults:()=>Ye,draw:()=>et,empty:()=>he,env:()=>R,match:()=>Nt,models:()=>T1});module.exports=Fo(da);var ae=Z(H());function u(...e){let t=new Date,n=`${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}:${t.getSeconds().toString().padStart(2,"0")}.${t.getMilliseconds().toString().padStart(3,"0")}`;e&&console.log(n,"Human:",...e)}function z1(e,t){let n=e.endsWith("/")?"":"/",r=t.startsWith(".")||t.startsWith("/")||t.startsWith("http:")||t.startsWith("https:")||t.startsWith("file:")?`${t}`:`${e}${n}${t}`;if(!r.toLocaleLowerCase().includes(".json"))throw new Error(`modelpath error: expecting json file: ${r}`);return r}var g=()=>typeof performance!="undefined"?performance.now():parseInt((Number(process.hrtime.bigint())/1e3/1e3).toString());function Ut(e,t,n="config",o=[]){for(let r of Object.keys(t))if(typeof t[r]=="object")Ut(e[r],t[r],r,o);else{let s=e&&typeof e[r]!="undefined";s||o.push({reason:"unknown property",where:`${n}.${r} = ${t[r]}`});let A=e&&typeof e[r]==typeof t[r];s&&!A&&o.push({reason:"property type mismatch",where:`${n}.${r} = ${t[r]}`,expected:typeof e[r]})}return t.debug&&n==="config"&&o.length>0&&u("invalid configuration",o),o}function a0(...e){let t=n=>n&&typeof n=="object";return e.reduce((n,o)=>(Object.keys(o||{}).forEach(r=>{let s=n[r],A=o[r];Array.isArray(s)&&Array.isArray(A)?n[r]=s.concat(...A):t(s)&&t(A)?n[r]=a0(s,A):n[r]=A}),n),{})}var Ye={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,iouThreshold:.1,mask:!1,return:!1},mesh:{enabled:!0,modelPath:"facemesh.json",keepInvalid:!1},attention:{enabled:!1,modelPath:"facemesh-attention.json"},iris:{enabled:!0,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"}};var I0=Z(H());var N=Z(H());var S1=` precision highp float; attribute vec2 pos; attribute vec2 uv; @@ -323,8 +14,7 @@ var vertexIdentity = ` vUv = uv; gl_Position = vec4(pos.x, pos.y*flipY, 0.0, 1.); } -`; -var colorMatrixWithAlpha = ` +`;var j1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -336,8 +26,7 @@ var colorMatrixWithAlpha = ` 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]; } -`; -var colorMatrixWithoutAlpha = ` +`,N1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -349,8 +38,7 @@ var colorMatrixWithoutAlpha = ` gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[14]; gl_FragColor.a = c.a; } -`; -var pixelate = ` +`,I1=` precision highp float; varying vec2 vUv; uniform vec2 size; @@ -363,8 +51,7 @@ var pixelate = ` vec2 coord = pixelate(vUv, size); gl_FragColor += texture2D(texture, coord); } -`; -var blur = ` +`,O1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -387,8 +74,7 @@ var blur = ` 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; } -`; -var convolution = ` +`,L1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; @@ -410,6055 +96,20 @@ var convolution = ` c31 * m[6] + c32 * m[7] + c33 * m[8]; gl_FragColor.a = c22.a; } -`; - -// src/image/imagefx.ts -var collect = (source, prefix, collection) => { - const r = new RegExp("\\b" + prefix + " \\w+ (\\w+)", "ig"); - source.replace(r, (match2, name) => { - collection[name] = 0; - return match2; - }); -}; -var GLProgram = class { - constructor(gl, vertexSource, fragmentSource) { - __publicField(this, "uniform", {}); - __publicField(this, "attribute", {}); - __publicField(this, "gl"); - __publicField(this, "id"); - __publicField(this, "compile", (source, type) => { - const shader = this.gl.createShader(type); - if (!shader) { - log("filter: could not create shader"); - return null; - } - this.gl.shaderSource(shader, source); - this.gl.compileShader(shader); - if (!this.gl.getShaderParameter(shader, this.gl.COMPILE_STATUS)) { - log(`filter: gl compile failed: ${this.gl.getShaderInfoLog(shader) || "unknown"}`); - return null; - } - return shader; - }); - this.gl = gl; - const vertexShader = this.compile(vertexSource, this.gl.VERTEX_SHADER); - const fragmentShader = this.compile(fragmentSource, this.gl.FRAGMENT_SHADER); - this.id = this.gl.createProgram(); - if (!vertexShader || !fragmentShader) - return; - if (!this.id) { - log("filter: could not create webgl program"); - return; - } - this.gl.attachShader(this.id, vertexShader); - this.gl.attachShader(this.id, fragmentShader); - this.gl.linkProgram(this.id); - if (!this.gl.getProgramParameter(this.id, this.gl.LINK_STATUS)) { - log(`filter: gl link failed: ${this.gl.getProgramInfoLog(this.id) || "unknown"}`); - return; - } - this.gl.useProgram(this.id); - collect(vertexSource, "attribute", this.attribute); - for (const a in this.attribute) - this.attribute[a] = this.gl.getAttribLocation(this.id, a); - collect(vertexSource, "uniform", this.uniform); - collect(fragmentSource, "uniform", this.uniform); - for (const u in this.uniform) - this.uniform[u] = this.gl.getUniformLocation(this.id, u); - } -}; -function GLImageFilter() { - let drawCount = 0; - let sourceTexture = null; - let lastInChain = false; - let currentFramebufferIndex = -1; - let tempFramebuffers = [null, null]; - let filterChain = []; - let vertexBuffer = null; - let currentProgram = null; - const fxcanvas = canvas(100, 100); - const shaderProgramCache = {}; - const DRAW = { INTERMEDIATE: 1 }; - const gl = fxcanvas.getContext("webgl"); - if (!gl) { - log("filter: cannot get webgl context"); - return; - } - this.gl = gl; - function resize(width, height) { - if (width === fxcanvas.width && height === fxcanvas.height) - return; - fxcanvas.width = width; - fxcanvas.height = height; - if (!vertexBuffer) { - const vertices = 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]); - vertexBuffer = gl.createBuffer(); - gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true); - } - gl.viewport(0, 0, fxcanvas.width, fxcanvas.height); - tempFramebuffers = [null, null]; - } - function createFramebufferTexture(width, height) { - const fbo = gl.createFramebuffer(); - gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); - const renderbuffer = gl.createRenderbuffer(); - gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer); - const texture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, texture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); - gl.bindTexture(gl.TEXTURE_2D, null); - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - return { fbo, texture }; - } - function getTempFramebuffer(index2) { - tempFramebuffers[index2] = tempFramebuffers[index2] || createFramebufferTexture(fxcanvas.width, fxcanvas.height); - return tempFramebuffers[index2]; - } - function draw(flags = 0) { - if (!currentProgram) - return; - let source = null; - let target = null; - let flipY = false; - if (drawCount === 0) - source = sourceTexture; - else - source = getTempFramebuffer(currentFramebufferIndex).texture || null; - drawCount++; - if (lastInChain && !(flags & DRAW.INTERMEDIATE)) { - target = null; - flipY = drawCount % 2 === 0; - } else { - currentFramebufferIndex = (currentFramebufferIndex + 1) % 2; - target = getTempFramebuffer(currentFramebufferIndex).fbo || null; - } - gl.bindTexture(gl.TEXTURE_2D, source); - gl.bindFramebuffer(gl.FRAMEBUFFER, target); - gl.uniform1f(currentProgram.uniform["flipY"], flipY ? -1 : 1); - gl.drawArrays(gl.TRIANGLES, 0, 6); - } - function compileShader(fragmentSource) { - if (shaderProgramCache[fragmentSource]) { - currentProgram = shaderProgramCache[fragmentSource]; - gl.useProgram((currentProgram ? currentProgram.id : null) || null); - return currentProgram; - } - currentProgram = new GLProgram(gl, vertexIdentity, fragmentSource); - if (!currentProgram) { - log("filter: could not get webgl program"); - return null; - } - const floatSize = Float32Array.BYTES_PER_ELEMENT; - const vertSize = 4 * floatSize; - gl.enableVertexAttribArray(currentProgram.attribute["pos"]); - gl.vertexAttribPointer(currentProgram.attribute["pos"], 2, gl.FLOAT, false, vertSize, 0 * floatSize); - gl.enableVertexAttribArray(currentProgram.attribute["uv"]); - gl.vertexAttribPointer(currentProgram.attribute["uv"], 2, gl.FLOAT, false, vertSize, 2 * floatSize); - shaderProgramCache[fragmentSource] = currentProgram; - return currentProgram; - } - const filter = { - colorMatrix: (matrix) => { - const m = new Float32Array(matrix); - m[4] /= 255; - m[9] /= 255; - m[14] /= 255; - m[19] /= 255; - const shader = m[18] === 1 && m[3] === 0 && m[8] === 0 && m[13] === 0 && m[15] === 0 && m[16] === 0 && m[17] === 0 && m[19] === 0 ? colorMatrixWithoutAlpha : colorMatrixWithAlpha; - const program = compileShader(shader); - if (!program) - return; - gl.uniform1fv(program.uniform["m"], m); - draw(); - }, - brightness: (brightness) => { - const b = (brightness || 0) + 1; - filter.colorMatrix([ - b, - 0, - 0, - 0, - 0, - 0, - b, - 0, - 0, - 0, - 0, - 0, - b, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - saturation: (amount) => { - const x = (amount || 0) * 2 / 3 + 1; - const y = (x - 1) * -0.5; - filter.colorMatrix([ - x, - y, - y, - 0, - 0, - y, - x, - y, - 0, - 0, - y, - y, - x, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - desaturate: () => { - filter.saturation(-1); - }, - contrast: (amount) => { - const v = (amount || 0) + 1; - const o = -128 * (v - 1); - filter.colorMatrix([ - v, - 0, - 0, - 0, - o, - 0, - v, - 0, - 0, - o, - 0, - 0, - v, - 0, - o, - 0, - 0, - 0, - 1, - 0 - ]); - }, - negative: () => { - filter.contrast(-2); - }, - hue: (rotation) => { - rotation = (rotation || 0) / 180 * Math.PI; - const cos = Math.cos(rotation); - const sin = Math.sin(rotation); - const lumR = 0.213; - const lumG = 0.715; - const lumB = 0.072; - filter.colorMatrix([ - lumR + cos * (1 - lumR) + sin * -lumR, - lumG + cos * -lumG + sin * -lumG, - lumB + cos * -lumB + sin * (1 - lumB), - 0, - 0, - lumR + cos * -lumR + sin * 0.143, - lumG + cos * (1 - lumG) + sin * 0.14, - lumB + cos * -lumB + sin * -0.283, - 0, - 0, - lumR + cos * -lumR + sin * -(1 - lumR), - lumG + cos * -lumG + sin * lumG, - lumB + cos * (1 - lumB) + sin * lumB, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - desaturateLuminance: () => { - filter.colorMatrix([ - 0.2764723, - 0.929708, - 0.0938197, - 0, - -37.1, - 0.2764723, - 0.929708, - 0.0938197, - 0, - -37.1, - 0.2764723, - 0.929708, - 0.0938197, - 0, - -37.1, - 0, - 0, - 0, - 1, - 0 - ]); - }, - sepia: () => { - filter.colorMatrix([ - 0.393, - 0.7689999, - 0.18899999, - 0, - 0, - 0.349, - 0.6859999, - 0.16799999, - 0, - 0, - 0.272, - 0.5339999, - 0.13099999, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - brownie: () => { - filter.colorMatrix([ - 0.5997023498159715, - 0.34553243048391263, - -0.2708298674538042, - 0, - 47.43192855600873, - -0.037703249837783157, - 0.8609577587992641, - 0.15059552388459913, - 0, - -36.96841498319127, - 0.24113635128153335, - -0.07441037908422492, - 0.44972182064877153, - 0, - -7.562075277591283, - 0, - 0, - 0, - 1, - 0 - ]); - }, - vintagePinhole: () => { - filter.colorMatrix([ - 0.6279345635605994, - 0.3202183420819367, - -0.03965408211312453, - 0, - 9.651285835294123, - 0.02578397704808868, - 0.6441188644374771, - 0.03259127616149294, - 0, - 7.462829176470591, - 0.0466055556782719, - -0.0851232987247891, - 0.5241648018700465, - 0, - 5.159190588235296, - 0, - 0, - 0, - 1, - 0 - ]); - }, - kodachrome: () => { - filter.colorMatrix([ - 1.1285582396593525, - -0.3967382283601348, - -0.03992559172921793, - 0, - 63.72958762196502, - -0.16404339962244616, - 1.0835251566291304, - -0.05498805115633132, - 0, - 24.732407896706203, - -0.16786010706155763, - -0.5603416277695248, - 1.6014850761964943, - 0, - 35.62982807460946, - 0, - 0, - 0, - 1, - 0 - ]); - }, - technicolor: () => { - filter.colorMatrix([ - 1.9125277891456083, - -0.8545344976951645, - -0.09155508482755585, - 0, - 11.793603434377337, - -0.3087833385928097, - 1.7658908555458428, - -0.10601743074722245, - 0, - -70.35205161461398, - -0.231103377548616, - -0.7501899197440212, - 1.847597816108189, - 0, - 30.950940869491138, - 0, - 0, - 0, - 1, - 0 - ]); - }, - polaroid: () => { - filter.colorMatrix([ - 1.438, - -0.062, - -0.062, - 0, - 0, - -0.122, - 1.378, - -0.122, - 0, - 0, - -0.016, - -0.016, - 1.483, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - shiftToBGR: () => { - filter.colorMatrix([ - 0, - 0, - 1, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 0 - ]); - }, - convolution: (matrix) => { - const m = new Float32Array(matrix); - const pixelSizeX = 1 / fxcanvas.width; - const pixelSizeY = 1 / fxcanvas.height; - const program = compileShader(convolution); - if (!program) - return; - gl.uniform1fv(program.uniform["m"], m); - gl.uniform2f(program.uniform["px"], pixelSizeX, pixelSizeY); - draw(); - }, - detectEdges: () => { - filter.convolution.call(this, [ - 0, - 1, - 0, - 1, - -4, - 1, - 0, - 1, - 0 - ]); - }, - sobelX: () => { - filter.convolution.call(this, [ - -1, - 0, - 1, - -2, - 0, - 2, - -1, - 0, - 1 - ]); - }, - sobelY: () => { - filter.convolution.call(this, [ - -1, - -2, - -1, - 0, - 0, - 0, - 1, - 2, - 1 - ]); - }, - sharpen: (amount) => { - const a = amount || 1; - filter.convolution.call(this, [ - 0, - -1 * a, - 0, - -1 * a, - 1 + 4 * a, - -1 * a, - 0, - -1 * a, - 0 - ]); - }, - emboss: (size2) => { - const s = size2 || 1; - filter.convolution.call(this, [ - -2 * s, - -1 * s, - 0, - -1 * s, - 1, - 1 * s, - 0, - 1 * s, - 2 * s - ]); - }, - blur: (size2) => { - const blurSizeX = size2 / 7 / fxcanvas.width; - const blurSizeY = size2 / 7 / fxcanvas.height; - const program = compileShader(blur); - if (!program) - return; - gl.uniform2f(program.uniform["px"], 0, blurSizeY); - draw(DRAW.INTERMEDIATE); - gl.uniform2f(program.uniform["px"], blurSizeX, 0); - draw(); - }, - pixelate: (size2) => { - const blurSizeX = size2 / fxcanvas.width; - const blurSizeY = size2 / fxcanvas.height; - const program = compileShader(pixelate); - if (!program) - return; - gl.uniform2f(program.uniform["size"], blurSizeX, blurSizeY); - draw(); - } - }; - this.add = function(name) { - const args = Array.prototype.slice.call(arguments, 1); - const func = filter[name]; - filterChain.push({ func, args }); - }; - this.reset = function() { - filterChain = []; - }; - this.get = function() { - return filterChain; - }; - this.apply = function(image28) { - resize(image28.width, image28.height); - drawCount = 0; - if (!sourceTexture) - sourceTexture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, sourceTexture); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image28); - for (let i = 0; i < filterChain.length; i++) { - lastInChain = i === filterChain.length - 1; - const f = filterChain[i]; - f.func.apply(this, f.args || []); - } - return fxcanvas; - }; - this.draw = function(image28) { - this.add("brightness", 0); - return this.apply(image28); - }; -} - -// src/image/enhance.ts -var tf = __toESM(require_tfjs_esm()); -async function histogramEqualization(inputImage) { - const squeeze14 = inputImage.shape.length === 4 ? tf.squeeze(inputImage) : inputImage; - const rgb2 = tf.split(squeeze14, 3, 2); - const min2 = [tf.min(rgb2[0]), tf.min(rgb2[1]), tf.min(rgb2[2])]; - const max5 = [tf.max(rgb2[0]), tf.max(rgb2[1]), tf.max(rgb2[2])]; - const absMax = await Promise.all(max5.map((channel) => channel.data())); - const maxValue = Math.max(absMax[0][0], absMax[1][0], absMax[2][0]); - const maxRange = maxValue > 1 ? 255 : 1; - const factor = maxRange / maxValue; - let final; - if (factor > 1) { - const sub11 = [tf.sub(rgb2[0], min2[0]), tf.sub(rgb2[1], min2[1]), tf.sub(rgb2[2], min2[2])]; - const range = [tf.sub(max5[0], min2[0]), tf.sub(max5[1], min2[1]), tf.sub(max5[2], min2[2])]; - const enh = [tf.mul(sub11[0], factor), tf.mul(sub11[1], factor), tf.mul(sub11[2], factor)]; - const stack5 = tf.stack([enh[0], enh[1], enh[2]], 2); - final = tf.reshape(stack5, [1, squeeze14.shape[0] || 0, squeeze14.shape[1] || 0, 3]); - tf.dispose([...sub11, ...range, ...enh]); - } else { - final = tf.expandDims(squeeze14, 0); - } - tf.dispose([...rgb2, ...min2, ...max5, rgb2, squeeze14, inputImage]); - return final; -} - -// src/image/image.ts -var maxSize = 3840; -var inCanvas = null; -var outCanvas = null; -var tmpCanvas = null; -var fx; -var last = { - inputSum: 0, - cacheDiff: 1, - sumMethod: 0, - inputTensor: void 0 -}; -function reset() { - last.inputSum = 0; - last.cacheDiff = 1; - last.sumMethod = 0; - last.inputTensor = void 0; -} -function canvas(width, height) { - let c; - if (env.browser) { - if (env.worker) { - if (typeof OffscreenCanvas === "undefined") - throw new Error("canvas error: attempted to run in web worker but OffscreenCanvas is not supported"); - c = new OffscreenCanvas(width, height); - } else { - if (typeof document === "undefined") - throw new Error("canvas error: attempted to run in browser but DOM is not defined"); - c = document.createElement("canvas"); - c.width = width; - c.height = height; - } - } else { - if (typeof env.Canvas !== "undefined") - c = new env.Canvas(width, height); - else if (typeof globalThis.Canvas !== "undefined") - c = new globalThis.Canvas(width, height); - } - return c; -} -function copy(input, output) { - const outputCanvas = output || canvas(input.width, input.height); - const ctx = outputCanvas.getContext("2d"); - ctx.drawImage(input, 0, 0); - return outputCanvas; -} -async function process2(input, config3, getTensor = true) { - var _a, _b, _c; - if (!input) { - if (config3.debug) - log("input error: input is missing"); - return { tensor: null, canvas: null }; - } - if (!(input instanceof tf2.Tensor) && !(typeof Image !== "undefined" && input instanceof Image) && !(typeof globalThis.Canvas !== "undefined" && input instanceof globalThis.Canvas) && !(typeof ImageData !== "undefined" && input instanceof ImageData) && !(typeof ImageBitmap !== "undefined" && input instanceof ImageBitmap) && !(typeof HTMLImageElement !== "undefined" && input instanceof HTMLImageElement) && !(typeof HTMLMediaElement !== "undefined" && input instanceof HTMLMediaElement) && !(typeof HTMLVideoElement !== "undefined" && input instanceof HTMLVideoElement) && !(typeof HTMLCanvasElement !== "undefined" && input instanceof HTMLCanvasElement) && !(typeof OffscreenCanvas !== "undefined" && input instanceof OffscreenCanvas)) { - throw new Error("input error: type not recognized"); - } - if (input instanceof tf2.Tensor) { - let tensor7 = null; - if (input["isDisposedInternal"]) - throw new Error("input error: attempted to use tensor but it is disposed"); - if (!input.shape) - throw new Error("input error: attempted to use tensor without a shape"); - if (input.shape.length === 3) { - if (input.shape[2] === 3) { - tensor7 = tf2.expandDims(input, 0); - } else if (input.shape[2] === 4) { - const rgb2 = tf2.slice3d(input, [0, 0, 0], [-1, -1, 3]); - tensor7 = tf2.expandDims(rgb2, 0); - tf2.dispose(rgb2); - } - } else if (input.shape.length === 4) { - if (input.shape[3] === 3) { - tensor7 = tf2.clone(input); - } else if (input.shape[3] === 4) { - tensor7 = tf2.slice4d(input, [0, 0, 0, 0], [-1, -1, -1, 3]); - } - } - if (tensor7 == null || tensor7.shape.length !== 4 || tensor7.shape[0] !== 1 || tensor7.shape[3] !== 3) - throw new Error(`input error: attempted to use tensor with unrecognized shape: ${input.shape.toString()}`); - if (tensor7.dtype === "int32") { - const cast8 = tf2.cast(tensor7, "float32"); - tf2.dispose(tensor7); - tensor7 = cast8; - } - return { tensor: tensor7, canvas: config3.filter.return ? outCanvas : null }; - } - if (typeof input["readyState"] !== "undefined" && input.readyState <= 2) { - if (config3.debug) - log("input stream is not ready"); - return { tensor: null, canvas: inCanvas }; - } - const originalWidth = input["naturalWidth"] || input["videoWidth"] || input["width"] || input["shape"] && input["shape"][1] > 0; - const originalHeight = input["naturalHeight"] || input["videoHeight"] || input["height"] || input["shape"] && input["shape"][2] > 0; - if (!originalWidth || !originalHeight) { - if (config3.debug) - log("cannot determine input dimensions"); - return { tensor: null, canvas: inCanvas }; - } - let targetWidth = originalWidth; - let targetHeight = originalHeight; - if (targetWidth > maxSize) { - targetWidth = maxSize; - targetHeight = Math.trunc(targetWidth * originalHeight / originalWidth); - } - if (targetHeight > maxSize) { - targetHeight = maxSize; - targetWidth = Math.trunc(targetHeight * originalWidth / originalHeight); - } - if ((((_a = config3.filter) == null ? void 0 : _a.width) || 0) > 0) - targetWidth = config3.filter.width; - else if ((((_b = config3.filter) == null ? void 0 : _b.height) || 0) > 0) - targetWidth = originalWidth * ((config3.filter.height || 0) / originalHeight); - if ((config3.filter.height || 0) > 0) - targetHeight = config3.filter.height; - else if ((config3.filter.width || 0) > 0) - targetHeight = originalHeight * ((config3.filter.width || 0) / originalWidth); - if (!targetWidth || !targetHeight) - throw new Error("input error: cannot determine dimension"); - if (!inCanvas || inCanvas.width !== targetWidth || inCanvas.height !== targetHeight) - inCanvas = canvas(targetWidth, targetHeight); - const inCtx = inCanvas.getContext("2d"); - if (typeof ImageData !== "undefined" && input instanceof ImageData) { - inCtx.putImageData(input, 0, 0); - } else { - if (config3.filter.flip && typeof inCtx.translate !== "undefined") { - inCtx.translate(originalWidth, 0); - inCtx.scale(-1, 1); - inCtx.drawImage(input, 0, 0, originalWidth, originalHeight, 0, 0, inCanvas.width, inCanvas.height); - inCtx.setTransform(1, 0, 0, 1, 0, 0); - } else { - inCtx.drawImage(input, 0, 0, originalWidth, originalHeight, 0, 0, inCanvas.width, inCanvas.height); - } - } - if (!outCanvas || inCanvas.width !== outCanvas.width || inCanvas.height !== outCanvas.height) - outCanvas = canvas(inCanvas.width, inCanvas.height); - if (config3.filter.enabled && env.webgl.supported) { - if (!fx) - fx = env.browser ? new GLImageFilter() : null; - env.filter = !!fx; - if (!(fx == null ? void 0 : fx.add)) { - if (config3.debug) - log("input process error: cannot initialize filters"); - env.webgl.supported = false; - config3.filter.enabled = false; - copy(inCanvas, outCanvas); - } else { - fx.reset(); - if (config3.filter.brightness !== 0) - fx.add("brightness", config3.filter.brightness); - if (config3.filter.contrast !== 0) - fx.add("contrast", config3.filter.contrast); - if (config3.filter.sharpness !== 0) - fx.add("sharpen", config3.filter.sharpness); - if (config3.filter.blur !== 0) - fx.add("blur", config3.filter.blur); - if (config3.filter.saturation !== 0) - fx.add("saturation", config3.filter.saturation); - if (config3.filter.hue !== 0) - fx.add("hue", config3.filter.hue); - if (config3.filter.negative) - fx.add("negative"); - if (config3.filter.sepia) - fx.add("sepia"); - if (config3.filter.vintage) - fx.add("brownie"); - if (config3.filter.sepia) - fx.add("sepia"); - if (config3.filter.kodachrome) - fx.add("kodachrome"); - if (config3.filter.technicolor) - fx.add("technicolor"); - if (config3.filter.polaroid) - fx.add("polaroid"); - if (config3.filter.pixelate !== 0) - fx.add("pixelate", config3.filter.pixelate); - if (((_c = fx.get()) == null ? void 0 : _c.length) > 1) - outCanvas = fx.apply(inCanvas); - else - outCanvas = fx.draw(inCanvas); - } - } else { - copy(inCanvas, outCanvas); - if (fx) - fx = null; - env.filter = !!fx; - } - if (!getTensor) - return { tensor: null, canvas: outCanvas }; - if (!outCanvas) - throw new Error("canvas error: cannot create output"); - let pixels; - let depth = 3; - if (typeof ImageData !== "undefined" && input instanceof ImageData || input.data && input.width && input.height) { - if (env.browser && tf2.browser) { - pixels = tf2.browser ? tf2.browser.fromPixels(input) : null; - } else { - depth = input.data.length / input.height / input.width; - const arr = new Uint8Array(input.data.buffer); - pixels = tf2.tensor(arr, [input.height, input.width, depth], "int32"); - } - } else { - if (!tmpCanvas || outCanvas.width !== tmpCanvas.width || outCanvas.height !== tmpCanvas.height) - tmpCanvas = canvas(outCanvas.width, outCanvas.height); - if (tf2.browser && env.browser) { - if (config3.backend === "webgl" || config3.backend === "humangl" || config3.backend === "webgpu") { - pixels = tf2.browser.fromPixels(outCanvas); - } else { - tmpCanvas = copy(outCanvas); - pixels = tf2.browser.fromPixels(tmpCanvas); - } - } else { - const tempCanvas = copy(outCanvas); - const tempCtx = tempCanvas.getContext("2d"); - const tempData = tempCtx.getImageData(0, 0, targetWidth, targetHeight); - depth = tempData.data.length / targetWidth / targetHeight; - const arr = new Uint8Array(tempData.data.buffer); - pixels = tf2.tensor(arr, [targetWidth, targetHeight, depth]); - } - } - if (depth === 4) { - const rgb2 = tf2.slice3d(pixels, [0, 0, 0], [-1, -1, 3]); - tf2.dispose(pixels); - pixels = rgb2; - } - if (!pixels) - throw new Error("input error: cannot create tensor"); - const casted = tf2.cast(pixels, "float32"); - const tensor6 = config3.filter.equalization ? await histogramEqualization(casted) : tf2.expandDims(casted, 0); - tf2.dispose([pixels, casted]); - if (config3.filter.autoBrightness) { - const max5 = tf2.max(tensor6); - const maxVal = await max5.data(); - config3.filter.brightness = maxVal[0] > 1 ? 1 - maxVal[0] / 255 : 1 - maxVal[0]; - tf2.dispose(max5); - } - return { tensor: tensor6, canvas: config3.filter.return ? outCanvas : null }; -} -async function skip(config3, input) { - let skipFrame = false; - if (config3.cacheSensitivity === 0 || !input.shape || input.shape.length !== 4 || input.shape[1] > 3840 || input.shape[2] > 2160) - return skipFrame; - if (!last.inputTensor) { - last.inputTensor = tf2.clone(input); - } else if (last.inputTensor.shape[1] !== input.shape[1] || last.inputTensor.shape[2] !== input.shape[2]) { - tf2.dispose(last.inputTensor); - last.inputTensor = tf2.clone(input); - } else { - const t2 = {}; - t2.diff = tf2.sub(input, last.inputTensor); - t2.squared = tf2.mul(t2.diff, t2.diff); - t2.sum = tf2.sum(t2.squared); - const diffSum = await t2.sum.data(); - const diffRelative = diffSum[0] / (input.shape[1] || 1) / (input.shape[2] || 1) / 255 / 3; - tf2.dispose([last.inputTensor, t2.diff, t2.squared, t2.sum]); - last.inputTensor = tf2.clone(input); - skipFrame = diffRelative <= (config3.cacheSensitivity || 0); - } - return skipFrame; -} -async function compare(config3, input1, input2) { - const t2 = {}; - if (!input1 || !input2 || input1.shape.length !== 4 || input1.shape.length !== input2.shape.length) { - if (!config3.debug) - log("invalid input tensor or tensor shapes do not match:", input1.shape, input2.shape); - return 0; - } - if (input1.shape[0] !== 1 || input2.shape[0] !== 1 || input1.shape[3] !== 3 || input2.shape[3] !== 3) { - if (!config3.debug) - log("input tensors must be of shape [1, height, width, 3]:", input1.shape, input2.shape); - return 0; - } - t2.input1 = tf2.clone(input1); - t2.input2 = input1.shape[1] !== input2.shape[1] || input1.shape[2] !== input2.shape[2] ? tf2.image.resizeBilinear(input2, [input1.shape[1], input1.shape[2]]) : tf2.clone(input2); - t2.diff = tf2.sub(t2.input1, t2.input2); - t2.squared = tf2.mul(t2.diff, t2.diff); - t2.sum = tf2.sum(t2.squared); - const diffSum = await t2.sum.data(); - const diffRelative = diffSum[0] / (input1.shape[1] || 1) / (input1.shape[2] || 1) / 255 / 3; - tf2.dispose([t2.input1, t2.input2, t2.diff, t2.squared, t2.sum]); - return diffRelative; -} - -// src/util/env.ts -var _canvas, _image, _imageData; -var Env = class { - constructor() { - __publicField(this, "browser"); - __publicField(this, "node"); - __publicField(this, "worker"); - __publicField(this, "platform", ""); - __publicField(this, "agent", ""); - __publicField(this, "backends", []); - __publicField(this, "initial"); - __publicField(this, "filter"); - __publicField(this, "tfjs"); - __publicField(this, "offscreen"); - __publicField(this, "perfadd", false); - __publicField(this, "tensorflow", { - version: void 0, - gpu: void 0 - }); - __publicField(this, "wasm", { - supported: void 0, - backend: void 0, - simd: void 0, - multithread: void 0 - }); - __publicField(this, "webgl", { - supported: void 0, - backend: void 0, - version: void 0, - renderer: void 0, - shader: void 0, - vendor: void 0 - }); - __publicField(this, "webgpu", { - supported: void 0, - backend: void 0, - adapter: void 0 - }); - __publicField(this, "cpu", { - model: void 0, - flags: [] - }); - __publicField(this, "kernels", []); - __privateAdd(this, _canvas, void 0); - __privateAdd(this, _image, void 0); - __privateAdd(this, _imageData, void 0); - this.browser = typeof navigator !== "undefined"; - this.node = typeof process !== "undefined" && typeof process.versions !== "undefined" && typeof process.versions.node !== "undefined"; - this.tfjs = { version: tf3.version["tfjs-core"] }; - this.offscreen = typeof OffscreenCanvas !== "undefined"; - this.initial = true; - this.worker = this.browser && this.offscreen ? typeof WorkerGlobalScope !== "undefined" : void 0; - if (typeof navigator !== "undefined") { - const raw = navigator.userAgent.match(/\(([^()]+)\)/g); - if (raw == null ? void 0 : raw[0]) { - const platformMatch = raw[0].match(/\(([^()]+)\)/g); - this.platform = (platformMatch == null ? void 0 : platformMatch[0]) ? platformMatch[0].replace(/\(|\)/g, "") : ""; - this.agent = navigator.userAgent.replace(raw[0], ""); - if (this.platform[1]) - this.agent = this.agent.replace(raw[1], ""); - this.agent = this.agent.replace(/ /g, " "); - } - } else if (typeof process !== "undefined") { - this.platform = `${process.platform} ${process.arch}`; - this.agent = `NodeJS ${process.version}`; - } - } - get Canvas() { - return __privateGet(this, _canvas); - } - set Canvas(val) { - __privateSet(this, _canvas, val); - globalThis.Canvas = val; - } - get Image() { - return __privateGet(this, _image); - } - set Image(val) { - __privateSet(this, _image, val); - globalThis.Image = val; - } - get ImageData() { - return __privateGet(this, _imageData); - } - set ImageData(val) { - __privateSet(this, _imageData, val); - globalThis.ImageData = val; - } - async updateBackend() { - this.backends = Object.keys(tf3.engine().registryFactory); - try { - this.tensorflow = { - version: tf3.backend()["binding"] ? tf3.backend()["binding"].TF_Version : void 0, - gpu: tf3.backend()["binding"] ? tf3.backend()["binding"].isUsingGpuDevice() : void 0 - }; - } catch (e) { - } - this.wasm.supported = typeof WebAssembly !== "undefined"; - this.wasm.backend = this.backends.includes("wasm"); - if (this.wasm.supported && this.wasm.backend) { - this.wasm.simd = await tf3.env().getAsync("WASM_HAS_SIMD_SUPPORT"); - this.wasm.multithread = await tf3.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"); - } - const c = canvas(100, 100); - const gl = c ? c.getContext("webgl2") : void 0; - this.webgl.supported = typeof gl !== "undefined"; - this.webgl.backend = this.backends.includes("webgl"); - if (this.webgl.supported && this.webgl.backend && gl) { - this.webgl.version = gl.getParameter(gl.VERSION); - this.webgl.vendor = gl.getParameter(gl.VENDOR); - this.webgl.renderer = gl.getParameter(gl.RENDERER); - this.webgl.shader = gl.getParameter(gl.SHADING_LANGUAGE_VERSION); - } - this.webgpu.supported = this.browser && typeof navigator.gpu !== "undefined"; - this.webgpu.backend = this.backends.includes("webgpu"); - try { - if (this.webgpu.supported) { - const adapter = await navigator.gpu.requestAdapter(); - this.webgpu.adapter = await (adapter == null ? void 0 : adapter.requestAdapterInfo()); - } - } catch (e) { - this.webgpu.supported = false; - } - try { - this.kernels = tf3.getKernelsForBackend(tf3.getBackend()).map((kernel) => kernel.kernelName.toLowerCase()); - } catch (e) { - } - } - updateCPU() { - const cpu = { model: "", flags: [] }; - if (this.node && this.platform.startsWith("linux")) { - } - if (!this.cpu) - Object.defineProperty(this, "cpu", { value: cpu }); - else - this.cpu = cpu; - } -}; -_canvas = new WeakMap(); -_image = new WeakMap(); -_imageData = new WeakMap(); -var env = new Env(); - -// src/util/webcam.ts -var WebCam = class { - constructor() { - __publicField(this, "config"); - __publicField(this, "element"); - __publicField(this, "stream"); - __publicField(this, "devices", []); - __publicField(this, "enumerate", async () => { - try { - const devices = await navigator.mediaDevices.enumerateDevices(); - this.devices = devices.filter((device) => device.kind === "videoinput"); - } catch (e) { - this.devices = []; - } - return this.devices; - }); - __publicField(this, "start", async (webcamConfig) => { - var _a, _b; - if (webcamConfig == null ? void 0 : webcamConfig.debug) - this.config.debug = webcamConfig == null ? void 0 : webcamConfig.debug; - if (webcamConfig == null ? void 0 : webcamConfig.crop) - this.config.crop = webcamConfig == null ? void 0 : webcamConfig.crop; - if (webcamConfig == null ? void 0 : webcamConfig.mode) - this.config.mode = webcamConfig == null ? void 0 : webcamConfig.mode; - if (webcamConfig == null ? void 0 : webcamConfig.width) - this.config.width = webcamConfig == null ? void 0 : webcamConfig.width; - if (webcamConfig == null ? void 0 : webcamConfig.height) - this.config.height = webcamConfig == null ? void 0 : webcamConfig.height; - if (webcamConfig == null ? void 0 : webcamConfig.id) - this.config.id = webcamConfig == null ? void 0 : webcamConfig.id; - if (webcamConfig == null ? void 0 : webcamConfig.element) { - if (typeof webcamConfig.element === "string") { - const el = document.getElementById(webcamConfig.element); - if (el && el instanceof HTMLVideoElement) { - this.element = el; - } else { - if (this.config.debug) - log("webcam", "cannot get dom element", webcamConfig.element); - return; - } - } else if (webcamConfig.element instanceof HTMLVideoElement) { - this.element = webcamConfig.element; - } else { - if (this.config.debug) - log("webcam", "unknown dom element", webcamConfig.element); - return; - } - } else { - this.element = document.createElement("video"); - } - const requestedConstraints = { - audio: false, - video: { - facingMode: this.config.mode === "front" ? "user" : "environment", - resizeMode: this.config.crop ? "crop-and-scale" : "none" - } - }; - if (((_a = this.config) == null ? void 0 : _a.width) > 0) - requestedConstraints.video.width = { ideal: this.config.width }; - if (((_b = this.config) == null ? void 0 : _b.height) > 0) - requestedConstraints.video.height = { ideal: this.config.height }; - if (this.config.id) - requestedConstraints.video.deviceId = this.config.id; - this.element.addEventListener("play", () => { - if (this.config.debug) - log("webcam", "play"); - }); - this.element.addEventListener("pause", () => { - if (this.config.debug) - log("webcam", "pause"); - }); - this.element.addEventListener("click", async () => { - if (!this.element || !this.stream) - return; - if (this.element.paused) - await this.element.play(); - else - this.element.pause(); - }); - if (!(navigator == null ? void 0 : navigator.mediaDevices)) { - if (this.config.debug) - log("webcam", "no devices"); - return; - } - try { - this.stream = await navigator.mediaDevices.getUserMedia(requestedConstraints); - } catch (err) { - log("webcam", err); - return; - } - if (!this.stream) { - if (this.config.debug) - log("webcam", "no stream"); - return; - } - this.element.srcObject = this.stream; - const ready3 = new Promise((resolve) => { - if (!this.element) - resolve(false); - else - this.element.onloadeddata = () => resolve(true); - }); - await ready3; - await this.element.play(); - if (this.config.debug) { - log("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 - }); - } - }); - __publicField(this, "pause", () => { - if (this.element) - this.element.pause(); - }); - __publicField(this, "play", async () => { - if (this.element) - await this.element.play(); - }); - __publicField(this, "stop", () => { - if (this.config.debug) - log("webcam", "stop"); - if (this.track) - this.track.stop(); - }); - this.config = { - element: void 0, - debug: true, - mode: "front", - crop: false, - width: 0, - height: 0 - }; - } - get track() { - if (!this.stream) - return void 0; - return this.stream.getVideoTracks()[0]; - } - get capabilities() { - if (!this.track) - return void 0; - return this.track.getCapabilities ? this.track.getCapabilities() : void 0; - } - get constraints() { - if (!this.track) - return void 0; - return this.track.getConstraints ? this.track.getConstraints() : void 0; - } - get settings() { - if (!this.stream) - return void 0; - const track = this.stream.getVideoTracks()[0]; - return track.getSettings ? track.getSettings() : void 0; - } - get label() { - if (!this.track) - return ""; - return this.track.label; - } - get paused() { - var _a; - return ((_a = this.element) == null ? void 0 : _a.paused) || false; - } - get width() { - var _a; - return ((_a = this.element) == null ? void 0 : _a.videoWidth) || 0; - } - get height() { - var _a; - return ((_a = this.element) == null ? void 0 : _a.videoHeight) || 0; - } -}; - -// src/tfjs/load.ts -var tf4 = __toESM(require_tfjs_esm()); - -// models/models.json -var models_exports = {}; -__export(models_exports, { - age: () => age, - "anti-spoofing": () => anti_spoofing, - antispoof: () => antispoof, - blazeface: () => blazeface, - "blazeface-back": () => blazeface_back, - "blazeface-front": () => blazeface_front, - "blazepose-detector": () => blazepose_detector, - "blazepose-full": () => blazepose_full, - "blazepose-heavy": () => blazepose_heavy, - "blazepose-lite": () => blazepose_lite, - centernet: () => centernet, - default: () => models_default, - efficientpose: () => efficientpose, - "efficientpose-i-lite": () => efficientpose_i_lite, - "efficientpose-ii-lite": () => efficientpose_ii_lite, - "efficientpose-iv": () => efficientpose_iv, - emotion: () => emotion, - faceboxes: () => faceboxes, - facemesh: () => facemesh, - "facemesh-attention": () => facemesh_attention, - "facemesh-attention-pinto": () => facemesh_attention_pinto, - "facemesh-detection-full": () => facemesh_detection_full, - "facemesh-detection-short": () => facemesh_detection_short, - faceres: () => faceres, - "faceres-deep": () => faceres_deep, - gear: () => gear, - gender: () => gender, - "gender-ssrnet-imdb": () => gender_ssrnet_imdb, - handdetect: () => handdetect, - "handlandmark-full": () => handlandmark_full, - "handlandmark-lite": () => handlandmark_lite, - "handlandmark-sparse": () => handlandmark_sparse, - handskeleton: () => handskeleton, - handtrack: () => handtrack, - "insightface-efficientnet-b0": () => insightface_efficientnet_b0, - "insightface-ghostnet-strides1": () => insightface_ghostnet_strides1, - "insightface-ghostnet-strides2": () => insightface_ghostnet_strides2, - "insightface-mobilenet-emore": () => insightface_mobilenet_emore, - "insightface-mobilenet-swish": () => insightface_mobilenet_swish, - iris: () => iris, - liveness: () => liveness, - meet: () => meet, - mobileface: () => mobileface, - mobilefacenet: () => mobilefacenet, - models: () => models, - "movenet-lightning": () => movenet_lightning, - "movenet-multipose": () => movenet_multipose, - "movenet-thunder": () => movenet_thunder, - nanodet: () => nanodet, - "nanodet-e": () => nanodet_e, - "nanodet-g": () => nanodet_g, - "nanodet-m": () => nanodet_m, - "nanodet-t": () => nanodet_t, - posenet: () => posenet, - rvm: () => rvm, - selfie: () => selfie -}); -var antispoof = 853098; -var blazeface = 538928; -var centernet = 4030290; -var emotion = 820516; -var facemesh = 1477958; -var faceres = 6978814; -var handlandmark_lite = 2023432; -var handtrack = 2964837; -var iris = 2599092; -var liveness = 592976; -var models = 0; -var movenet_lightning = 4650216; -var age = 161240; -var blazeface_back = 538928; -var blazeface_front = 402048; -var blazepose_detector = 5928856; -var blazepose_full = 6339202; -var blazepose_heavy = 27502466; -var blazepose_lite = 2726402; -var efficientpose = 5651240; -var faceboxes = 2013002; -var facemesh_attention_pinto = 2387598; -var facemesh_attention = 2382414; -var facemesh_detection_full = 1026192; -var facemesh_detection_short = 201268; -var faceres_deep = 13957620; -var gear = 1498916; -var gender_ssrnet_imdb = 161236; -var gender = 201808; -var handdetect = 3515612; -var handlandmark_full = 5431368; -var handlandmark_sparse = 5286322; -var handskeleton = 5502280; -var meet = 372228; -var mobileface = 2183192; -var mobilefacenet = 5171976; -var movenet_multipose = 9448838; -var movenet_thunder = 12477112; -var nanodet = 7574558; -var posenet = 5032780; -var rvm = 3739355; -var selfie = 212886; -var anti_spoofing = 853098; -var efficientpose_i_lite = 2269064; -var efficientpose_ii_lite = 5651240; -var efficientpose_iv = 25643252; -var insightface_efficientnet_b0 = 13013224; -var insightface_ghostnet_strides1 = 8093408; -var insightface_ghostnet_strides2 = 8049584; -var insightface_mobilenet_emore = 6938536; -var insightface_mobilenet_swish = 12168584; -var nanodet_e = 12319156; -var nanodet_g = 7574558; -var nanodet_m = 1887474; -var nanodet_t = 5294216; -var models_default = { - antispoof, - blazeface, - centernet, - emotion, - facemesh, - faceres, - "handlandmark-lite": handlandmark_lite, - handtrack, - iris, - liveness, - models, - "movenet-lightning": movenet_lightning, - age, - "blazeface-back": blazeface_back, - "blazeface-front": blazeface_front, - "blazepose-detector": blazepose_detector, - "blazepose-full": blazepose_full, - "blazepose-heavy": blazepose_heavy, - "blazepose-lite": blazepose_lite, - efficientpose, - faceboxes, - "facemesh-attention-pinto": facemesh_attention_pinto, - "facemesh-attention": facemesh_attention, - "facemesh-detection-full": facemesh_detection_full, - "facemesh-detection-short": facemesh_detection_short, - "faceres-deep": faceres_deep, - gear, - "gender-ssrnet-imdb": gender_ssrnet_imdb, - gender, - handdetect, - "handlandmark-full": handlandmark_full, - "handlandmark-sparse": handlandmark_sparse, - handskeleton, - meet, - mobileface, - mobilefacenet, - "movenet-multipose": movenet_multipose, - "movenet-thunder": movenet_thunder, - nanodet, - posenet, - rvm, - selfie, - "anti-spoofing": anti_spoofing, - "efficientpose-i-lite": efficientpose_i_lite, - "efficientpose-ii-lite": efficientpose_ii_lite, - "efficientpose-iv": efficientpose_iv, - "insightface-efficientnet-b0": insightface_efficientnet_b0, - "insightface-ghostnet-strides1": insightface_ghostnet_strides1, - "insightface-ghostnet-strides2": insightface_ghostnet_strides2, - "insightface-mobilenet-emore": insightface_mobilenet_emore, - "insightface-mobilenet-swish": insightface_mobilenet_swish, - "nanodet-e": nanodet_e, - "nanodet-g": nanodet_g, - "nanodet-m": nanodet_m, - "nanodet-t": nanodet_t -}; - -// src/tfjs/load.ts -var options = { - cacheModels: true, - cacheSupported: true, - verbose: true, - debug: false, - modelBasePath: "" -}; -var modelStats = {}; -async function httpHandler(url, init4) { - if (options.debug) - log("load model fetch:", url, init4); - return fetch(url, init4); -} -function setModelLoadOptions(config3) { - options.cacheModels = config3.cacheModels; - options.verbose = config3.debug; - options.modelBasePath = config3.modelBasePath; -} -async function loadModel(modelPath) { - var _a, _b, _c, _d; - let modelUrl = join(options.modelBasePath, modelPath || ""); - if (!modelUrl.toLowerCase().endsWith(".json")) - modelUrl += ".json"; - const modelPathSegments = modelUrl.includes("/") ? modelUrl.split("/") : modelUrl.split("\\"); - const shortModelName = modelPathSegments[modelPathSegments.length - 1].replace(".json", ""); - const cachedModelName = "indexeddb://" + shortModelName; - modelStats[shortModelName] = { - name: shortModelName, - sizeFromManifest: 0, - sizeLoadedWeights: 0, - sizeDesired: models_exports[shortModelName], - inCache: false, - url: "" - }; - options.cacheSupported = typeof indexedDB !== "undefined"; - let cachedModels = {}; - try { - cachedModels = options.cacheSupported && options.cacheModels ? await tf4.io.listModels() : {}; - } catch (e) { - options.cacheSupported = false; - } - modelStats[shortModelName].inCache = options.cacheSupported && options.cacheModels && Object.keys(cachedModels).includes(cachedModelName); - modelStats[shortModelName].url = modelStats[shortModelName].inCache ? cachedModelName : modelUrl; - const tfLoadOptions = typeof fetch === "undefined" ? {} : { fetchFunc: (url, init4) => httpHandler(url, init4) }; - let model23 = new tf4.GraphModel(modelStats[shortModelName].url, tfLoadOptions); - let loaded = false; - try { - model23.findIOHandler(); - if (options.debug) - log("model load handler:", model23["handler"]); - } catch (err) { - log("error finding model i/o handler:", modelUrl, err); - } - try { - const artifacts = await ((_a = model23.handler) == null ? void 0 : _a.load()) || null; - modelStats[shortModelName].sizeFromManifest = ((_b = artifacts == null ? void 0 : artifacts.weightData) == null ? void 0 : _b.byteLength) || 0; - if (artifacts) - model23.loadSync(artifacts); - else - model23 = await tf4.loadGraphModel(modelStats[shortModelName].inCache ? cachedModelName : modelUrl, tfLoadOptions); - modelStats[shortModelName].sizeLoadedWeights = ((_d = (_c = model23.artifacts) == null ? void 0 : _c.weightData) == null ? void 0 : _d.byteLength) || 0; - if (options.verbose) - log("load:", { model: shortModelName, url: model23["modelUrl"], bytes: modelStats[shortModelName].sizeLoadedWeights }); - loaded = true; - } catch (err) { - log("error loading model:", modelUrl, err); - } - if (loaded && options.cacheModels && options.cacheSupported && !modelStats[shortModelName].inCache) { - try { - const saveResult = await model23.save(cachedModelName); - if (options.debug) - log("model saved:", cachedModelName, saveResult); - } catch (err) { - log("error saving model:", modelUrl, err); - } - } - return model23; -} - -// package.json -var version2 = "3.0.2"; - -// src/tfjs/backend.ts -var tf7 = __toESM(require_tfjs_esm()); - -// src/tfjs/humangl.ts -var tf5 = __toESM(require_tfjs_esm()); -var config2 = { - name: "humangl", - priority: 999, - canvas: null, - gl: null, - extensions: [], - webGLattr: { - alpha: false, - antialias: false, - premultipliedAlpha: false, - preserveDrawingBuffer: false, - depth: false, - stencil: false, - failIfMajorPerformanceCaveat: false, - desynchronized: true - } -}; -function extensions() { - const gl = config2.gl; - if (!gl) - return; - config2.extensions = gl.getSupportedExtensions(); -} -function register(instance) { - var _a; - if (instance.config.backend !== "humangl") - return; - if (config2.name in tf5.engine().registry && !((_a = config2 == null ? void 0 : config2.gl) == null ? void 0 : _a.getParameter(config2.gl.VERSION))) { - log("humangl error: backend invalid context"); - instance.models.reset(); - } - if (!tf5.findBackend(config2.name)) { - try { - config2.canvas = canvas(100, 100); - } catch (err) { - log("humangl error: cannot create canvas:", err); - return; - } - try { - config2.gl = config2.canvas.getContext("webgl2", config2.webGLattr); - if (!config2.gl) { - log("humangl error: cannot get webgl context"); - return; - } - const glv2 = config2.gl.getParameter(config2.gl.VERSION).includes("2.0"); - if (!glv2) { - log("backend override: using fallback webgl backend as webgl 2.0 is not detected"); - instance.config.backend = "webgl"; - return; - } - if (config2.canvas) { - config2.canvas.addEventListener("webglcontextlost", (e) => { - log("humangl error:", e.type); - log("possible browser memory leak using webgl or conflict with multiple backend registrations"); - instance.emit("error"); - throw new Error("backend error: webgl context lost"); - }); - config2.canvas.addEventListener("webglcontextrestored", (e) => { - log("humangl error: context restored:", e); - }); - config2.canvas.addEventListener("webglcontextcreationerror", (e) => { - log("humangl error: context create:", e); - }); - } - } catch (err) { - log("humangl error: cannot get webgl context:", err); - return; - } - try { - tf5.setWebGLContext(2, config2.gl); - } catch (err) { - log("humangl error: cannot set webgl context:", err); - return; - } - try { - const ctx = new tf5.GPGPUContext(config2.gl); - tf5.registerBackend(config2.name, () => new tf5.MathBackendWebGL(ctx), config2.priority); - } catch (err) { - log("humangl error: cannot register webgl backend:", err); - return; - } - try { - const kernels = tf5.getKernelsForBackend("webgl"); - kernels.forEach((kernelConfig) => { - const newKernelConfig = { ...kernelConfig, backendName: config2.name }; - tf5.registerKernel(newKernelConfig); - }); - } catch (err) { - log("humangl error: cannot update webgl backend registration:", err); - return; - } - try { - if (tf5.env().flagRegistry.WEBGL_VERSION) - tf5.env().set("WEBGL_VERSION", 2); - } catch (err) { - log("humangl error: cannot set WebGL backend flags:", err); - return; - } - extensions(); - const backend4 = tf5.backend(); - const current = typeof backend4["gpgpu"] !== "undefined" ? backend4["getGPGPUContext"]().gl : null; - if (current) { - if (instance.config.debug) - log("humangl backend registered:", { webgl: current.getParameter(current.VERSION), renderer: current.getParameter(current.RENDERER) }); - } else { - log("humangl error: no current gl context:", current, config2.gl); - } - } -} - -// src/tfjs/constants.ts -var tf6 = __toESM(require_tfjs_esm()); -var constants = { - tf255: 255, - tf1: 1, - tf2: 2, - tf05: 0.5, - tf127: 127.5, - rgb: [0.2989, 0.587, 0.114] -}; -function init() { - constants.tf255 = tf6.scalar(255, "float32"); - constants.tf1 = tf6.scalar(1, "float32"); - constants.tf2 = tf6.scalar(2, "float32"); - constants.tf05 = tf6.scalar(0.5, "float32"); - constants.tf127 = tf6.scalar(127.5, "float32"); - constants.rgb = tf6.tensor1d([0.2989, 0.587, 0.114], "float32"); -} - -// src/tfjs/backend.ts -async function getBestBackend() { - var _a; - await env.updateBackend(); - if ((_a = env.tensorflow) == null ? void 0 : _a.version) - return "tensorflow"; - if (env.webgpu.supported && env.webgpu.backend) - return "webgpu"; - if (env.webgl.supported && env.webgl.backend) - return "webgl"; - if (env.wasm.supported && env.wasm.backend) - return "wasm"; - return "cpu"; -} -function registerCustomOps(config3) { - const newKernels = []; - if (!env.kernels.includes("mod")) { - const kernelMod = { - kernelName: "Mod", - backendName: tf7.getBackend(), - kernelFunc: (op) => tf7.tidy(() => tf7.sub(op.inputs.a, tf7.mul(tf7.div(op.inputs.a, op.inputs.b), op.inputs.b))) - }; - tf7.registerKernel(kernelMod); - env.kernels.push("mod"); - newKernels.push("mod"); - } - if (!env.kernels.includes("floormod")) { - const kernelFloorMod = { - kernelName: "FloorMod", - backendName: tf7.getBackend(), - kernelFunc: (op) => tf7.tidy(() => tf7.add(tf7.mul(tf7.floorDiv(op.inputs.a, op.inputs.b), op.inputs.b), tf7.mod(op.inputs.a, op.inputs.b))) - }; - tf7.registerKernel(kernelFloorMod); - env.kernels.push("floormod"); - newKernels.push("floormod"); - } - if (!env.kernels.includes("rotatewithoffset") && config3.softwareKernels) { - const kernelRotateWithOffset = { - kernelName: "RotateWithOffset", - backendName: tf7.getBackend(), - kernelFunc: (op) => tf7.tidy(() => { - const backend4 = tf7.getBackend(); - tf7.setBackend("cpu"); - const t2 = tf7.image.rotateWithOffset(op.inputs.image, op.attrs.radians, op.attrs.fillValue, op.attrs.center); - tf7.setBackend(backend4); - return t2; - }) - }; - tf7.registerKernel(kernelRotateWithOffset); - env.kernels.push("rotatewithoffset"); - newKernels.push("rotatewithoffset"); - } - if (newKernels.length > 0 && config3.debug) - log("registered kernels:", newKernels); -} -var defaultFlags = {}; -async function check(instance, force = false) { - var _a; - instance.state = "backend"; - if (((_a = instance.config.backend) == null ? void 0 : _a.length) === 0) - instance.config.backend = await getBestBackend(); - if (force || env.initial || instance.config.backend && instance.config.backend.length > 0 && tf7.getBackend() !== instance.config.backend) { - const timeStamp = now(); - if (instance.config.backend && instance.config.backend.length > 0) { - if (typeof window === "undefined" && typeof WorkerGlobalScope !== "undefined" && instance.config.debug) { - if (instance.config.debug) - log("running inside web worker"); - } - if (env.browser && instance.config.backend === "tensorflow") { - if (instance.config.debug) - log("override: backend set to tensorflow while running in browser"); - instance.config.backend = "webgl"; - } - if (env.node && (instance.config.backend === "webgl" || instance.config.backend === "humangl")) { - if (instance.config.debug) - log(`override: backend set to ${instance.config.backend} while running in nodejs`); - instance.config.backend = "tensorflow"; - } - if (env.browser && instance.config.backend === "webgpu") { - if (typeof navigator === "undefined" || typeof navigator.gpu === "undefined") { - log("override: backend set to webgpu but browser does not support webgpu"); - instance.config.backend = "webgl"; - } else { - const adapter = await navigator.gpu.requestAdapter(); - if (instance.config.debug) - log("enumerated webgpu adapter:", adapter); - if (!adapter) { - log("override: backend set to webgpu but browser reports no available gpu"); - instance.config.backend = "webgl"; - } else { - const adapterInfo = "requestAdapterInfo" in adapter ? await adapter.requestAdapterInfo() : void 0; - log("webgpu adapter info:", adapterInfo); - } - } - } - let available = Object.keys(tf7.engine().registryFactory); - if (instance.config.backend === "humangl" && !available.includes("humangl")) { - register(instance); - available = Object.keys(tf7.engine().registryFactory); - } - if (instance.config.debug) - log("available backends:", available); - if (!available.includes(instance.config.backend)) { - log(`error: backend ${instance.config.backend} not found in registry`); - instance.config.backend = env.node ? "tensorflow" : "webgl"; - if (instance.config.debug) - log(`override: setting backend ${instance.config.backend}`); - } - if (instance.config.debug) - log("setting backend:", [instance.config.backend]); - if (instance.config.backend === "wasm") { - if (tf7.env().flagRegistry.CANVAS2D_WILL_READ_FREQUENTLY) - tf7.env().set("CANVAS2D_WILL_READ_FREQUENTLY", true); - if (instance.config.debug) - log("wasm path:", instance.config.wasmPath); - if (typeof tf7.setWasmPaths !== "undefined") - tf7.setWasmPaths(instance.config.wasmPath, instance.config.wasmPlatformFetch); - else - throw new Error("backend error: attempting to use wasm backend but wasm path is not set"); - let mt = false; - let simd = false; - try { - mt = await tf7.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"); - simd = await tf7.env().getAsync("WASM_HAS_SIMD_SUPPORT"); - if (instance.config.debug) - log(`wasm execution: ${simd ? "simd" : "no simd"} ${mt ? "multithreaded" : "singlethreaded"}`); - if (instance.config.debug && !simd) - log("warning: wasm simd support is not enabled"); - } catch (e) { - log("wasm detection failed"); - } - } - try { - await tf7.setBackend(instance.config.backend); - await tf7.ready(); - } catch (err) { - log("error: cannot set backend:", instance.config.backend, err); - return false; - } - if (instance.config.debug) - defaultFlags = JSON.parse(JSON.stringify(tf7.env().flags)); - } - if (tf7.getBackend() === "humangl" || tf7.getBackend() === "webgl") { - if (tf7.env().flagRegistry.WEBGL_USE_SHAPES_UNIFORMS) - tf7.env().set("WEBGL_USE_SHAPES_UNIFORMS", true); - if (tf7.env().flagRegistry.WEBGL_EXP_CONV) - tf7.env().set("WEBGL_EXP_CONV", true); - if (instance.config.debug && typeof instance.config.deallocate !== "undefined" && instance.config.deallocate) { - log("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:", true); - tf7.env().set("WEBGL_DELETE_TEXTURE_THRESHOLD", 0); - } - } - if (tf7.getBackend() === "webgpu") { - } - if (instance.config.debug) { - const newFlags = tf7.env().flags; - const updatedFlags = {}; - for (const key of Object.keys(newFlags)) { - if (defaultFlags[key] === newFlags[key]) - continue; - updatedFlags[key] = newFlags[key]; - } - if (instance.config.debug && Object.keys(updatedFlags).length > 0) - log("backend:", tf7.getBackend(), "flags:", updatedFlags); - } - if (instance.config.flags && Object.keys(instance.config.flags).length > 0) { - if (instance.config.debug) - log("flags:", instance.config["flags"]); - for (const [key, val] of Object.entries(instance.config.flags)) { - tf7.env().set(key, val); - } - } - tf7.enableProdMode(); - init(); - instance.performance.initBackend = Math.trunc(now() - timeStamp); - instance.config.backend = tf7.getBackend(); - await env.updateBackend(); - registerCustomOps(instance.config); - env.initial = false; - } - return true; -} -function fakeOps(kernelNames, config3) { - for (const kernelName of kernelNames) { - const kernelConfig = { - kernelName, - backendName: config3.backend, - kernelFunc: (param) => { - var _a; - if (config3.debug) - log("kernelFunc", kernelName, config3.backend, param); - return (_a = param == null ? void 0 : param.inputs) == null ? void 0 : _a.info; - } - }; - tf7.registerKernel(kernelConfig); - } - env.kernels = tf7.getKernelsForBackend(tf7.getBackend()).map((kernel) => kernel.kernelName.toLowerCase()); -} - -// src/draw/draw.ts -var draw_exports = {}; -__export(draw_exports, { - all: () => all, - body: () => body, - canvas: () => canvas2, - face: () => face, - gesture: () => gesture, - hand: () => hand, - init: () => init2, - object: () => object, - options: () => options2, - person: () => person -}); - -// src/draw/primitives.ts -var getCanvasContext = (input) => { - if (!input) - log("draw error: invalid canvas"); - else if (!input.getContext) - log("draw error: canvas context not defined"); - else { - const ctx = input.getContext("2d"); - if (!ctx) - log("draw error: cannot get canvas context"); - else - return ctx; - } - return null; -}; -var rad2deg = (theta) => Math.round(theta * 180 / Math.PI); -var replace = (str, source, target) => str.replace(source, typeof target === "number" ? target.toFixed(1) : target); -var colorDepth = (z, opt) => { - if (!opt.useDepth || typeof z === "undefined") - return opt.color; - const rgb2 = Uint8ClampedArray.from([127 + 2 * z, 127 - 2 * z, 255]); - return `rgba(${rgb2[0]}, ${rgb2[1]}, ${rgb2[2]}, ${opt.alpha})`; -}; -function labels(ctx, str, startX, startY, localOptions2) { - const line = str.replace(/\[.*\]/g, "").split("\n").map((l) => l.trim()); - const x = Math.max(0, startX); - for (let i = line.length - 1; i >= 0; i--) { - const y = i * localOptions2.lineHeight + startY; - if (localOptions2.shadowColor && localOptions2.shadowColor !== "") { - ctx.fillStyle = localOptions2.shadowColor; - ctx.fillText(line[i], x + 5, y + 16); - } - ctx.fillStyle = localOptions2.labelColor; - ctx.fillText(line[i], x + 4, y + 15); - } -} -function point(ctx, x, y, z, localOptions2) { - ctx.fillStyle = colorDepth(z, localOptions2); - ctx.beginPath(); - ctx.arc(x, y, localOptions2.pointSize, 0, 2 * Math.PI); - ctx.fill(); -} -function rect(ctx, x, y, width, height, localOptions2) { - ctx.beginPath(); - ctx.lineWidth = localOptions2.lineWidth; - if (localOptions2.useCurves) { - const cx = (x + x + width) / 2; - const cy = (y + y + height) / 2; - ctx.ellipse(cx, cy, width / 2, height / 2, 0, 0, 2 * Math.PI); - } else { - ctx.moveTo(x + localOptions2.roundRect, y); - ctx.lineTo(x + width - localOptions2.roundRect, y); - ctx.quadraticCurveTo(x + width, y, x + width, y + localOptions2.roundRect); - ctx.lineTo(x + width, y + height - localOptions2.roundRect); - ctx.quadraticCurveTo(x + width, y + height, x + width - localOptions2.roundRect, y + height); - ctx.lineTo(x + localOptions2.roundRect, y + height); - ctx.quadraticCurveTo(x, y + height, x, y + height - localOptions2.roundRect); - ctx.lineTo(x, y + localOptions2.roundRect); - ctx.quadraticCurveTo(x, y, x + localOptions2.roundRect, y); - ctx.closePath(); - } - ctx.stroke(); -} -function lines(ctx, points, localOptions2) { - if (points.length < 2) - return; - ctx.beginPath(); - ctx.moveTo(points[0][0], points[0][1]); - for (const pt of points) { - ctx.strokeStyle = colorDepth(pt[2] || 0, localOptions2); - ctx.lineTo(Math.trunc(pt[0]), Math.trunc(pt[1])); - } - ctx.stroke(); - if (localOptions2.fillPolygons) { - ctx.closePath(); - ctx.fill(); - } -} -function curves(ctx, points, localOptions2) { - if (points.length < 2) - return; - ctx.lineWidth = localOptions2.lineWidth; - if (!localOptions2.useCurves || points.length <= 2) { - lines(ctx, points, localOptions2); - return; - } - ctx.moveTo(points[0][0], points[0][1]); - for (let i = 0; i < points.length - 2; i++) { - const xc = (points[i][0] + points[i + 1][0]) / 2; - const yc = (points[i][1] + points[i + 1][1]) / 2; - ctx.quadraticCurveTo(points[i][0], points[i][1], xc, yc); - } - ctx.quadraticCurveTo(points[points.length - 2][0], points[points.length - 2][1], points[points.length - 1][0], points[points.length - 1][1]); - ctx.stroke(); - if (localOptions2.fillPolygons) { - ctx.closePath(); - ctx.fill(); - } -} -function arrow(ctx, from, to, radius = 5) { - let angle; - let x; - let y; - ctx.beginPath(); - ctx.moveTo(from[0], from[1]); - ctx.lineTo(to[0], to[1]); - angle = Math.atan2(to[1] - from[1], to[0] - from[0]); - x = radius * Math.cos(angle) + to[0]; - y = radius * Math.sin(angle) + to[1]; - ctx.moveTo(x, y); - angle += 1 / 3 * (2 * Math.PI); - x = radius * Math.cos(angle) + to[0]; - y = radius * Math.sin(angle) + to[1]; - ctx.lineTo(x, y); - angle += 1 / 3 * (2 * Math.PI); - x = radius * Math.cos(angle) + to[0]; - y = radius * Math.sin(angle) + to[1]; - ctx.lineTo(x, y); - ctx.closePath(); - ctx.stroke(); - ctx.fill(); -} - -// src/draw/options.ts -var options2 = { - color: "rgba(173, 216, 230, 0.6)", - labelColor: "rgba(173, 216, 230, 1)", - shadowColor: "black", - alpha: 0.5, - font: 'small-caps 16px "Segoe UI"', - lineHeight: 18, - lineWidth: 4, - pointSize: 2, - roundRect: 8, - drawPoints: false, - drawLabels: true, - drawBoxes: true, - drawAttention: true, - drawGestures: true, - drawPolygons: true, - drawGaze: true, - fillPolygons: false, - useDepth: true, - useCurves: false, - faceLabels: "", - bodyLabels: "", - bodyPartLabels: "", - objectLabels: "", - handLabels: "", - fingerLabels: "", - gestureLabels: "" -}; - -// src/face/facemeshcoords.ts -var meshAnnotations = { - 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], - noseTip: [1], - noseBottom: [2], - noseRightCorner: [98], - noseLeftCorner: [327], - rightCheek: [205], - leftCheek: [425] -}; -var meshLandmarks = { - count: 468, - mouth: 13, - symmetryLine: [13, meshAnnotations.midwayBetweenEyes[0]] -}; -var blazeFaceLandmarks = { - leftEye: 0, - rightEye: 1, - nose: 2, - mouth: 3, - leftEar: 4, - rightEar: 5, - symmetryLine: [3, 2] -}; -var irisIndices = [ - { key: "EyeUpper0", indices: [9, 10, 11, 12, 13, 14, 15] }, - { key: "EyeUpper1", indices: [25, 26, 27, 28, 29, 30, 31] }, - { key: "EyeUpper2", indices: [41, 42, 43, 44, 45, 46, 47] }, - { key: "EyeLower0", indices: [0, 1, 2, 3, 4, 5, 6, 7, 8] }, - { key: "EyeLower1", indices: [16, 17, 18, 19, 20, 21, 22, 23, 24] }, - { key: "EyeLower2", indices: [32, 33, 34, 35, 36, 37, 38, 39, 40] }, - { key: "EyeLower3", indices: [54, 55, 56, 57, 58, 59, 60, 61, 62] }, - { key: "EyebrowUpper", indices: [63, 64, 65, 66, 67, 68, 69, 70] }, - { key: "EyebrowLower", indices: [48, 49, 50, 51, 52, 53] } -]; -var UV468 = [ - [0.499976992607117, 0.652534008026123], - [0.500025987625122, 0.547487020492554], - [0.499974012374878, 0.602371990680695], - [0.482113003730774, 0.471979022026062], - [0.500150978565216, 0.527155995368958], - [0.499909996986389, 0.498252987861633], - [0.499523013830185, 0.40106201171875], - [0.289712011814117, 0.380764007568359], - [0.499954998493195, 0.312398016452789], - [0.499987006187439, 0.269918978214264], - [0.500023007392883, 0.107050001621246], - [0.500023007392883, 0.666234016418457], - [0.5000159740448, 0.679224014282227], - [0.500023007392883, 0.692348003387451], - [0.499976992607117, 0.695277988910675], - [0.499976992607117, 0.70593398809433], - [0.499976992607117, 0.719385027885437], - [0.499976992607117, 0.737019002437592], - [0.499967992305756, 0.781370997428894], - [0.499816000461578, 0.562981009483337], - [0.473773002624512, 0.573909997940063], - [0.104906998574734, 0.254140973091125], - [0.365929991006851, 0.409575998783112], - [0.338757991790771, 0.41302502155304], - [0.311120003461838, 0.409460008144379], - [0.274657994508743, 0.389131009578705], - [0.393361985683441, 0.403706014156342], - [0.345234006643295, 0.344011008739471], - [0.370094001293182, 0.346076011657715], - [0.319321990013123, 0.347265005111694], - [0.297903001308441, 0.353591024875641], - [0.24779200553894, 0.410809993743896], - [0.396889001131058, 0.842755019664764], - [0.280097991228104, 0.375599980354309], - [0.106310002505779, 0.399955987930298], - [0.2099249958992, 0.391353011131287], - [0.355807989835739, 0.534406006336212], - [0.471751004457474, 0.65040397644043], - [0.474155008792877, 0.680191993713379], - [0.439785003662109, 0.657229006290436], - [0.414617002010345, 0.66654098033905], - [0.450374007225037, 0.680860996246338], - [0.428770989179611, 0.682690978050232], - [0.374971002340317, 0.727805018424988], - [0.486716985702515, 0.547628998756409], - [0.485300987958908, 0.527395009994507], - [0.257764995098114, 0.314490020275116], - [0.401223003864288, 0.455172002315521], - [0.429818987846375, 0.548614978790283], - [0.421351999044418, 0.533740997314453], - [0.276895999908447, 0.532056987285614], - [0.483370006084442, 0.499586999416351], - [0.33721199631691, 0.282882988452911], - [0.296391993761063, 0.293242990970612], - [0.169294998049736, 0.193813979625702], - [0.447580009698868, 0.302609980106354], - [0.392390012741089, 0.353887975215912], - [0.354490011930466, 0.696784019470215], - [0.067304998636246, 0.730105042457581], - [0.442739009857178, 0.572826027870178], - [0.457098007202148, 0.584792017936707], - [0.381974011659622, 0.694710969924927], - [0.392388999462128, 0.694203019142151], - [0.277076005935669, 0.271932005882263], - [0.422551989555359, 0.563233017921448], - [0.385919004678726, 0.281364023685455], - [0.383103013038635, 0.255840003490448], - [0.331431001424789, 0.119714021682739], - [0.229923993349075, 0.232002973556519], - [0.364500999450684, 0.189113974571228], - [0.229622006416321, 0.299540996551514], - [0.173287004232407, 0.278747975826263], - [0.472878992557526, 0.666198015213013], - [0.446828007698059, 0.668527007102966], - [0.422762006521225, 0.673889994621277], - [0.445307999849319, 0.580065965652466], - [0.388103008270264, 0.693961024284363], - [0.403039008378983, 0.706539988517761], - [0.403629004955292, 0.693953037261963], - [0.460041999816895, 0.557139039039612], - [0.431158006191254, 0.692366003990173], - [0.452181994915009, 0.692366003990173], - [0.475387006998062, 0.692366003990173], - [0.465828001499176, 0.779190003871918], - [0.472328990697861, 0.736225962638855], - [0.473087012767792, 0.717857003211975], - [0.473122000694275, 0.704625964164734], - [0.473033010959625, 0.695277988910675], - [0.427942007780075, 0.695277988910675], - [0.426479011774063, 0.703539967536926], - [0.423162013292313, 0.711845993995667], - [0.4183090031147, 0.720062971115112], - [0.390094995498657, 0.639572978019714], - [0.013953999616206, 0.560034036636353], - [0.499913990497589, 0.58014702796936], - [0.413199990987778, 0.69539999961853], - [0.409626007080078, 0.701822996139526], - [0.468080013990402, 0.601534962654114], - [0.422728985548019, 0.585985004901886], - [0.463079988956451, 0.593783974647522], - [0.37211999297142, 0.47341400384903], - [0.334562003612518, 0.496073007583618], - [0.411671012639999, 0.546965003013611], - [0.242175996303558, 0.14767599105835], - [0.290776997804642, 0.201445996761322], - [0.327338010072708, 0.256527006626129], - [0.399509996175766, 0.748921036720276], - [0.441727995872498, 0.261676013469696], - [0.429764986038208, 0.187834024429321], - [0.412198007106781, 0.108901023864746], - [0.288955003023148, 0.398952007293701], - [0.218936994671822, 0.435410976409912], - [0.41278201341629, 0.398970007896423], - [0.257135003805161, 0.355440020561218], - [0.427684992551804, 0.437960982322693], - [0.448339998722076, 0.536936044692993], - [0.178560003638268, 0.45755398273468], - [0.247308000922203, 0.457193970680237], - [0.286267012357712, 0.467674970626831], - [0.332827985286713, 0.460712015628815], - [0.368755996227264, 0.447206974029541], - [0.398963987827301, 0.432654976844788], - [0.476410001516342, 0.405806005001068], - [0.189241006970406, 0.523923993110657], - [0.228962004184723, 0.348950982093811], - [0.490725994110107, 0.562400996685028], - [0.404670000076294, 0.485132992267609], - [0.019469000399113, 0.401564002037048], - [0.426243007183075, 0.420431017875671], - [0.396993011236191, 0.548797011375427], - [0.266469985246658, 0.376977026462555], - [0.439121007919312, 0.51895797252655], - [0.032313998788595, 0.644356966018677], - [0.419054001569748, 0.387154996395111], - [0.462783008813858, 0.505746960639954], - [0.238978996872902, 0.779744982719421], - [0.198220998048782, 0.831938028335571], - [0.107550002634525, 0.540755033493042], - [0.183610007166862, 0.740257024765015], - [0.134409993886948, 0.333683013916016], - [0.385764002799988, 0.883153975009918], - [0.490967005491257, 0.579378008842468], - [0.382384985685349, 0.508572995662689], - [0.174399003386497, 0.397670984268188], - [0.318785011768341, 0.39623498916626], - [0.343364000320435, 0.400596976280212], - [0.396100014448166, 0.710216999053955], - [0.187885001301765, 0.588537991046906], - [0.430987000465393, 0.944064974784851], - [0.318993002176285, 0.898285031318665], - [0.266247987747192, 0.869701027870178], - [0.500023007392883, 0.190576016902924], - [0.499976992607117, 0.954452991485596], - [0.366169989109039, 0.398822009563446], - [0.393207013607025, 0.39553701877594], - [0.410373002290726, 0.391080021858215], - [0.194993004202843, 0.342101991176605], - [0.388664990663528, 0.362284004688263], - [0.365961998701096, 0.355970978736877], - [0.343364000320435, 0.355356991291046], - [0.318785011768341, 0.35834002494812], - [0.301414996385574, 0.363156020641327], - [0.058132998645306, 0.319076001644135], - [0.301414996385574, 0.387449026107788], - [0.499987989664078, 0.618434011936188], - [0.415838003158569, 0.624195992946625], - [0.445681989192963, 0.566076993942261], - [0.465844005346298, 0.620640993118286], - [0.49992299079895, 0.351523995399475], - [0.288718998432159, 0.819945991039276], - [0.335278987884521, 0.852819979190826], - [0.440512001514435, 0.902418971061707], - [0.128294005990028, 0.791940987110138], - [0.408771991729736, 0.373893976211548], - [0.455606997013092, 0.451801002025604], - [0.499877005815506, 0.908990025520325], - [0.375436991453171, 0.924192011356354], - [0.11421000212431, 0.615022003650665], - [0.448662012815475, 0.695277988910675], - [0.4480200111866, 0.704632043838501], - [0.447111994028091, 0.715808033943176], - [0.444831997156143, 0.730794012546539], - [0.430011987686157, 0.766808986663818], - [0.406787008047104, 0.685672998428345], - [0.400738000869751, 0.681069016456604], - [0.392399996519089, 0.677703022956848], - [0.367855995893478, 0.663918972015381], - [0.247923001646996, 0.601333022117615], - [0.452769994735718, 0.420849978923798], - [0.43639200925827, 0.359887003898621], - [0.416164010763168, 0.368713974952698], - [0.413385987281799, 0.692366003990173], - [0.228018000721931, 0.683571994304657], - [0.468268007040024, 0.352671027183533], - [0.411361992359161, 0.804327011108398], - [0.499989002943039, 0.469825029373169], - [0.479153990745544, 0.442654013633728], - [0.499974012374878, 0.439637005329132], - [0.432112008333206, 0.493588984012604], - [0.499886006116867, 0.866917014122009], - [0.49991300702095, 0.821729004383087], - [0.456548988819122, 0.819200992584229], - [0.344549000263214, 0.745438992977142], - [0.37890899181366, 0.574010014533997], - [0.374292999505997, 0.780184984207153], - [0.319687992334366, 0.570737957954407], - [0.357154995203018, 0.604269981384277], - [0.295284003019333, 0.621580958366394], - [0.447750002145767, 0.862477004528046], - [0.410986006259918, 0.508723020553589], - [0.31395098567009, 0.775308012962341], - [0.354128003120422, 0.812552988529205], - [0.324548006057739, 0.703992962837219], - [0.189096003770828, 0.646299958229065], - [0.279776990413666, 0.71465802192688], - [0.1338230073452, 0.682700991630554], - [0.336768001317978, 0.644733011722565], - [0.429883986711502, 0.466521978378296], - [0.455527991056442, 0.548622965812683], - [0.437114000320435, 0.558896005153656], - [0.467287987470627, 0.529924988746643], - [0.414712011814117, 0.335219979286194], - [0.37704598903656, 0.322777986526489], - [0.344107985496521, 0.320150971412659], - [0.312875986099243, 0.32233202457428], - [0.283526003360748, 0.333190023899078], - [0.241245999932289, 0.382785975933075], - [0.102986000478268, 0.468762993812561], - [0.267612010240555, 0.424560010433197], - [0.297879010438919, 0.433175981044769], - [0.333433985710144, 0.433878004550934], - [0.366427004337311, 0.426115989685059], - [0.396012008190155, 0.416696012020111], - [0.420121014118195, 0.41022801399231], - [0.007561000064015, 0.480777025222778], - [0.432949006557465, 0.569517970085144], - [0.458638995885849, 0.479089021682739], - [0.473466008901596, 0.545744001865387], - [0.476087987422943, 0.563830018043518], - [0.468472003936768, 0.555056989192963], - [0.433990985155106, 0.582361996173859], - [0.483518004417419, 0.562983989715576], - [0.482482999563217, 0.57784903049469], - [0.42645001411438, 0.389798998832703], - [0.438998997211456, 0.39649498462677], - [0.450067013502121, 0.400434017181396], - [0.289712011814117, 0.368252992630005], - [0.276670008897781, 0.363372981548309], - [0.517862021923065, 0.471948027610779], - [0.710287988185883, 0.380764007568359], - [0.526226997375488, 0.573909997940063], - [0.895093023777008, 0.254140973091125], - [0.634069979190826, 0.409575998783112], - [0.661242008209229, 0.41302502155304], - [0.688880026340485, 0.409460008144379], - [0.725341975688934, 0.389131009578705], - [0.606630027294159, 0.40370500087738], - [0.654766023159027, 0.344011008739471], - [0.629905998706818, 0.346076011657715], - [0.680678009986877, 0.347265005111694], - [0.702096998691559, 0.353591024875641], - [0.75221198797226, 0.410804986953735], - [0.602918028831482, 0.842862963676453], - [0.719901978969574, 0.375599980354309], - [0.893692970275879, 0.399959981441498], - [0.790081977844238, 0.391354024410248], - [0.643998026847839, 0.534487962722778], - [0.528249025344849, 0.65040397644043], - [0.525849997997284, 0.680191040039062], - [0.560214996337891, 0.657229006290436], - [0.585384011268616, 0.66654098033905], - [0.549625992774963, 0.680860996246338], - [0.57122802734375, 0.682691991329193], - [0.624852001667023, 0.72809898853302], - [0.513050019741058, 0.547281980514526], - [0.51509702205658, 0.527251958847046], - [0.742246985435486, 0.314507007598877], - [0.598631024360657, 0.454979002475739], - [0.570338010787964, 0.548575043678284], - [0.578631997108459, 0.533622980117798], - [0.723087012767792, 0.532054007053375], - [0.516445994377136, 0.499638974666595], - [0.662801027297974, 0.282917976379395], - [0.70362401008606, 0.293271005153656], - [0.830704987049103, 0.193813979625702], - [0.552385985851288, 0.302568018436432], - [0.607609987258911, 0.353887975215912], - [0.645429015159607, 0.696707010269165], - [0.932694971561432, 0.730105042457581], - [0.557260990142822, 0.572826027870178], - [0.542901992797852, 0.584792017936707], - [0.6180260181427, 0.694710969924927], - [0.607590973377228, 0.694203019142151], - [0.722943007946014, 0.271963000297546], - [0.577413976192474, 0.563166975975037], - [0.614082992076874, 0.281386971473694], - [0.616907000541687, 0.255886018276215], - [0.668509006500244, 0.119913995265961], - [0.770092010498047, 0.232020974159241], - [0.635536015033722, 0.189248979091644], - [0.77039098739624, 0.299556016921997], - [0.826722025871277, 0.278755009174347], - [0.527121007442474, 0.666198015213013], - [0.553171992301941, 0.668527007102966], - [0.577238023281097, 0.673889994621277], - [0.554691970348358, 0.580065965652466], - [0.611896991729736, 0.693961024284363], - [0.59696102142334, 0.706539988517761], - [0.596370995044708, 0.693953037261963], - [0.539958000183105, 0.557139039039612], - [0.568841993808746, 0.692366003990173], - [0.547818005084991, 0.692366003990173], - [0.52461302280426, 0.692366003990173], - [0.534089982509613, 0.779141008853912], - [0.527670979499817, 0.736225962638855], - [0.526912987232208, 0.717857003211975], - [0.526877999305725, 0.704625964164734], - [0.526966989040375, 0.695277988910675], - [0.572058022022247, 0.695277988910675], - [0.573521018028259, 0.703539967536926], - [0.57683801651001, 0.711845993995667], - [0.581691026687622, 0.720062971115112], - [0.609944999217987, 0.639909982681274], - [0.986046016216278, 0.560034036636353], - [0.5867999792099, 0.69539999961853], - [0.590372025966644, 0.701822996139526], - [0.531915009021759, 0.601536989212036], - [0.577268004417419, 0.585934996604919], - [0.536915004253387, 0.593786001205444], - [0.627542972564697, 0.473352015018463], - [0.665585994720459, 0.495950996875763], - [0.588353991508484, 0.546862006187439], - [0.757824003696442, 0.14767599105835], - [0.709249973297119, 0.201507985591888], - [0.672684013843536, 0.256581008434296], - [0.600408971309662, 0.74900496006012], - [0.55826598405838, 0.261672019958496], - [0.570303976535797, 0.187870979309082], - [0.588165998458862, 0.109044015407562], - [0.711045026779175, 0.398952007293701], - [0.781069993972778, 0.435405015945435], - [0.587247014045715, 0.398931980133057], - [0.742869973182678, 0.355445981025696], - [0.572156012058258, 0.437651991844177], - [0.55186802148819, 0.536570012569427], - [0.821442008018494, 0.457556009292603], - [0.752701997756958, 0.457181990146637], - [0.71375697851181, 0.467626988887787], - [0.66711300611496, 0.460672974586487], - [0.631101012229919, 0.447153985500336], - [0.6008620262146, 0.432473003864288], - [0.523481011390686, 0.405627012252808], - [0.810747981071472, 0.523926019668579], - [0.771045982837677, 0.348959028720856], - [0.509127020835876, 0.562718033790588], - [0.595292985439301, 0.485023975372314], - [0.980530977249146, 0.401564002037048], - [0.573499977588654, 0.420000016689301], - [0.602994978427887, 0.548687994480133], - [0.733529984951019, 0.376977026462555], - [0.560611009597778, 0.519016981124878], - [0.967685997486115, 0.644356966018677], - [0.580985009670258, 0.387160003185272], - [0.537728011608124, 0.505385041236877], - [0.760966002941132, 0.779752969741821], - [0.801778972148895, 0.831938028335571], - [0.892440974712372, 0.54076099395752], - [0.816350996494293, 0.740260004997253], - [0.865594983100891, 0.333687007427216], - [0.614073991775513, 0.883246004581451], - [0.508952975273132, 0.579437971115112], - [0.617941975593567, 0.508316040039062], - [0.825608015060425, 0.397674977779388], - [0.681214988231659, 0.39623498916626], - [0.656635999679565, 0.400596976280212], - [0.603900015354156, 0.710216999053955], - [0.81208598613739, 0.588539004325867], - [0.56801301240921, 0.944564998149872], - [0.681007981300354, 0.898285031318665], - [0.733752012252808, 0.869701027870178], - [0.633830010890961, 0.398822009563446], - [0.606792986392975, 0.39553701877594], - [0.589659988880157, 0.391062021255493], - [0.805015981197357, 0.342108011245728], - [0.611334979534149, 0.362284004688263], - [0.634037971496582, 0.355970978736877], - [0.656635999679565, 0.355356991291046], - [0.681214988231659, 0.35834002494812], - [0.698584973812103, 0.363156020641327], - [0.941866993904114, 0.319076001644135], - [0.698584973812103, 0.387449026107788], - [0.584177017211914, 0.624107003211975], - [0.554318010807037, 0.566076993942261], - [0.534153997898102, 0.62064003944397], - [0.711217999458313, 0.819975018501282], - [0.664629995822906, 0.852871000766754], - [0.559099972248077, 0.902631998062134], - [0.871706008911133, 0.791940987110138], - [0.591234028339386, 0.373893976211548], - [0.544341027736664, 0.451583981513977], - [0.624562978744507, 0.924192011356354], - [0.88577002286911, 0.615028977394104], - [0.551338016986847, 0.695277988910675], - [0.551980018615723, 0.704632043838501], - [0.552887976169586, 0.715808033943176], - [0.555167973041534, 0.730794012546539], - [0.569944024085999, 0.767035007476807], - [0.593203008174896, 0.685675978660583], - [0.599261999130249, 0.681069016456604], - [0.607599973678589, 0.677703022956848], - [0.631937980651855, 0.663500010967255], - [0.752032995223999, 0.601315021514893], - [0.547226011753082, 0.420395016670227], - [0.563543975353241, 0.359827995300293], - [0.583841025829315, 0.368713974952698], - [0.586614012718201, 0.692366003990173], - [0.771915018558502, 0.683578014373779], - [0.531597018241882, 0.352482974529266], - [0.588370978832245, 0.804440975189209], - [0.52079701423645, 0.442565023899078], - [0.567984998226166, 0.493479013442993], - [0.543282985687256, 0.819254994392395], - [0.655317008495331, 0.745514988899231], - [0.621008992195129, 0.574018001556396], - [0.625559985637665, 0.78031200170517], - [0.680198013782501, 0.570719003677368], - [0.64276397228241, 0.604337990283966], - [0.704662978649139, 0.621529996395111], - [0.552012026309967, 0.862591981887817], - [0.589071989059448, 0.508637011051178], - [0.685944974422455, 0.775357007980347], - [0.645735025405884, 0.812640011310577], - [0.675342977046967, 0.703978002071381], - [0.810858011245728, 0.646304965019226], - [0.72012197971344, 0.714666962623596], - [0.866151988506317, 0.682704985141754], - [0.663187026977539, 0.644596993923187], - [0.570082008838654, 0.466325998306274], - [0.544561982154846, 0.548375964164734], - [0.562758982181549, 0.558784961700439], - [0.531987011432648, 0.530140042304993], - [0.585271000862122, 0.335177004337311], - [0.622952997684479, 0.32277899980545], - [0.655896008014679, 0.320163011550903], - [0.687132000923157, 0.322345972061157], - [0.716481983661652, 0.333200991153717], - [0.758756995201111, 0.382786989212036], - [0.897013008594513, 0.468769013881683], - [0.732392013072968, 0.424547016620636], - [0.70211398601532, 0.433162987232208], - [0.66652500629425, 0.433866024017334], - [0.633504986763, 0.426087975502014], - [0.603875994682312, 0.416586995124817], - [0.579657971858978, 0.409945011138916], - [0.992439985275269, 0.480777025222778], - [0.567192018032074, 0.569419980049133], - [0.54136598110199, 0.478899002075195], - [0.526564002037048, 0.546118021011353], - [0.523913025856018, 0.563830018043518], - [0.531529009342194, 0.555056989192963], - [0.566035985946655, 0.582329034805298], - [0.51631098985672, 0.563053965568542], - [0.5174720287323, 0.577877044677734], - [0.573594987392426, 0.389806985855103], - [0.560697972774506, 0.395331978797913], - [0.549755990505219, 0.399751007556915], - [0.710287988185883, 0.368252992630005], - [0.723330020904541, 0.363372981548309] -]; -var TRI468 = [ - 127, - 34, - 139, - 11, - 0, - 37, - 232, - 231, - 120, - 72, - 37, - 39, - 128, - 121, - 47, - 232, - 121, - 128, - 104, - 69, - 67, - 175, - 171, - 148, - 157, - 154, - 155, - 118, - 50, - 101, - 73, - 39, - 40, - 9, - 151, - 108, - 48, - 115, - 131, - 194, - 204, - 211, - 74, - 40, - 185, - 80, - 42, - 183, - 40, - 92, - 186, - 230, - 229, - 118, - 202, - 212, - 214, - 83, - 18, - 17, - 76, - 61, - 146, - 160, - 29, - 30, - 56, - 157, - 173, - 106, - 204, - 194, - 135, - 214, - 192, - 203, - 165, - 98, - 21, - 71, - 68, - 51, - 45, - 4, - 144, - 24, - 23, - 77, - 146, - 91, - 205, - 50, - 187, - 201, - 200, - 18, - 91, - 106, - 182, - 90, - 91, - 181, - 85, - 84, - 17, - 206, - 203, - 36, - 148, - 171, - 140, - 92, - 40, - 39, - 193, - 189, - 244, - 159, - 158, - 28, - 247, - 246, - 161, - 236, - 3, - 196, - 54, - 68, - 104, - 193, - 168, - 8, - 117, - 228, - 31, - 189, - 193, - 55, - 98, - 97, - 99, - 126, - 47, - 100, - 166, - 79, - 218, - 155, - 154, - 26, - 209, - 49, - 131, - 135, - 136, - 150, - 47, - 126, - 217, - 223, - 52, - 53, - 45, - 51, - 134, - 211, - 170, - 140, - 67, - 69, - 108, - 43, - 106, - 91, - 230, - 119, - 120, - 226, - 130, - 247, - 63, - 53, - 52, - 238, - 20, - 242, - 46, - 70, - 156, - 78, - 62, - 96, - 46, - 53, - 63, - 143, - 34, - 227, - 173, - 155, - 133, - 123, - 117, - 111, - 44, - 125, - 19, - 236, - 134, - 51, - 216, - 206, - 205, - 154, - 153, - 22, - 39, - 37, - 167, - 200, - 201, - 208, - 36, - 142, - 100, - 57, - 212, - 202, - 20, - 60, - 99, - 28, - 158, - 157, - 35, - 226, - 113, - 160, - 159, - 27, - 204, - 202, - 210, - 113, - 225, - 46, - 43, - 202, - 204, - 62, - 76, - 77, - 137, - 123, - 116, - 41, - 38, - 72, - 203, - 129, - 142, - 64, - 98, - 240, - 49, - 102, - 64, - 41, - 73, - 74, - 212, - 216, - 207, - 42, - 74, - 184, - 169, - 170, - 211, - 170, - 149, - 176, - 105, - 66, - 69, - 122, - 6, - 168, - 123, - 147, - 187, - 96, - 77, - 90, - 65, - 55, - 107, - 89, - 90, - 180, - 101, - 100, - 120, - 63, - 105, - 104, - 93, - 137, - 227, - 15, - 86, - 85, - 129, - 102, - 49, - 14, - 87, - 86, - 55, - 8, - 9, - 100, - 47, - 121, - 145, - 23, - 22, - 88, - 89, - 179, - 6, - 122, - 196, - 88, - 95, - 96, - 138, - 172, - 136, - 215, - 58, - 172, - 115, - 48, - 219, - 42, - 80, - 81, - 195, - 3, - 51, - 43, - 146, - 61, - 171, - 175, - 199, - 81, - 82, - 38, - 53, - 46, - 225, - 144, - 163, - 110, - 246, - 33, - 7, - 52, - 65, - 66, - 229, - 228, - 117, - 34, - 127, - 234, - 107, - 108, - 69, - 109, - 108, - 151, - 48, - 64, - 235, - 62, - 78, - 191, - 129, - 209, - 126, - 111, - 35, - 143, - 163, - 161, - 246, - 117, - 123, - 50, - 222, - 65, - 52, - 19, - 125, - 141, - 221, - 55, - 65, - 3, - 195, - 197, - 25, - 7, - 33, - 220, - 237, - 44, - 70, - 71, - 139, - 122, - 193, - 245, - 247, - 130, - 33, - 71, - 21, - 162, - 153, - 158, - 159, - 170, - 169, - 150, - 188, - 174, - 196, - 216, - 186, - 92, - 144, - 160, - 161, - 2, - 97, - 167, - 141, - 125, - 241, - 164, - 167, - 37, - 72, - 38, - 12, - 145, - 159, - 160, - 38, - 82, - 13, - 63, - 68, - 71, - 226, - 35, - 111, - 158, - 153, - 154, - 101, - 50, - 205, - 206, - 92, - 165, - 209, - 198, - 217, - 165, - 167, - 97, - 220, - 115, - 218, - 133, - 112, - 243, - 239, - 238, - 241, - 214, - 135, - 169, - 190, - 173, - 133, - 171, - 208, - 32, - 125, - 44, - 237, - 86, - 87, - 178, - 85, - 86, - 179, - 84, - 85, - 180, - 83, - 84, - 181, - 201, - 83, - 182, - 137, - 93, - 132, - 76, - 62, - 183, - 61, - 76, - 184, - 57, - 61, - 185, - 212, - 57, - 186, - 214, - 207, - 187, - 34, - 143, - 156, - 79, - 239, - 237, - 123, - 137, - 177, - 44, - 1, - 4, - 201, - 194, - 32, - 64, - 102, - 129, - 213, - 215, - 138, - 59, - 166, - 219, - 242, - 99, - 97, - 2, - 94, - 141, - 75, - 59, - 235, - 24, - 110, - 228, - 25, - 130, - 226, - 23, - 24, - 229, - 22, - 23, - 230, - 26, - 22, - 231, - 112, - 26, - 232, - 189, - 190, - 243, - 221, - 56, - 190, - 28, - 56, - 221, - 27, - 28, - 222, - 29, - 27, - 223, - 30, - 29, - 224, - 247, - 30, - 225, - 238, - 79, - 20, - 166, - 59, - 75, - 60, - 75, - 240, - 147, - 177, - 215, - 20, - 79, - 166, - 187, - 147, - 213, - 112, - 233, - 244, - 233, - 128, - 245, - 128, - 114, - 188, - 114, - 217, - 174, - 131, - 115, - 220, - 217, - 198, - 236, - 198, - 131, - 134, - 177, - 132, - 58, - 143, - 35, - 124, - 110, - 163, - 7, - 228, - 110, - 25, - 356, - 389, - 368, - 11, - 302, - 267, - 452, - 350, - 349, - 302, - 303, - 269, - 357, - 343, - 277, - 452, - 453, - 357, - 333, - 332, - 297, - 175, - 152, - 377, - 384, - 398, - 382, - 347, - 348, - 330, - 303, - 304, - 270, - 9, - 336, - 337, - 278, - 279, - 360, - 418, - 262, - 431, - 304, - 408, - 409, - 310, - 415, - 407, - 270, - 409, - 410, - 450, - 348, - 347, - 422, - 430, - 434, - 313, - 314, - 17, - 306, - 307, - 375, - 387, - 388, - 260, - 286, - 414, - 398, - 335, - 406, - 418, - 364, - 367, - 416, - 423, - 358, - 327, - 251, - 284, - 298, - 281, - 5, - 4, - 373, - 374, - 253, - 307, - 320, - 321, - 425, - 427, - 411, - 421, - 313, - 18, - 321, - 405, - 406, - 320, - 404, - 405, - 315, - 16, - 17, - 426, - 425, - 266, - 377, - 400, - 369, - 322, - 391, - 269, - 417, - 465, - 464, - 386, - 257, - 258, - 466, - 260, - 388, - 456, - 399, - 419, - 284, - 332, - 333, - 417, - 285, - 8, - 346, - 340, - 261, - 413, - 441, - 285, - 327, - 460, - 328, - 355, - 371, - 329, - 392, - 439, - 438, - 382, - 341, - 256, - 429, - 420, - 360, - 364, - 394, - 379, - 277, - 343, - 437, - 443, - 444, - 283, - 275, - 440, - 363, - 431, - 262, - 369, - 297, - 338, - 337, - 273, - 375, - 321, - 450, - 451, - 349, - 446, - 342, - 467, - 293, - 334, - 282, - 458, - 461, - 462, - 276, - 353, - 383, - 308, - 324, - 325, - 276, - 300, - 293, - 372, - 345, - 447, - 382, - 398, - 362, - 352, - 345, - 340, - 274, - 1, - 19, - 456, - 248, - 281, - 436, - 427, - 425, - 381, - 256, - 252, - 269, - 391, - 393, - 200, - 199, - 428, - 266, - 330, - 329, - 287, - 273, - 422, - 250, - 462, - 328, - 258, - 286, - 384, - 265, - 353, - 342, - 387, - 259, - 257, - 424, - 431, - 430, - 342, - 353, - 276, - 273, - 335, - 424, - 292, - 325, - 307, - 366, - 447, - 345, - 271, - 303, - 302, - 423, - 266, - 371, - 294, - 455, - 460, - 279, - 278, - 294, - 271, - 272, - 304, - 432, - 434, - 427, - 272, - 407, - 408, - 394, - 430, - 431, - 395, - 369, - 400, - 334, - 333, - 299, - 351, - 417, - 168, - 352, - 280, - 411, - 325, - 319, - 320, - 295, - 296, - 336, - 319, - 403, - 404, - 330, - 348, - 349, - 293, - 298, - 333, - 323, - 454, - 447, - 15, - 16, - 315, - 358, - 429, - 279, - 14, - 15, - 316, - 285, - 336, - 9, - 329, - 349, - 350, - 374, - 380, - 252, - 318, - 402, - 403, - 6, - 197, - 419, - 318, - 319, - 325, - 367, - 364, - 365, - 435, - 367, - 397, - 344, - 438, - 439, - 272, - 271, - 311, - 195, - 5, - 281, - 273, - 287, - 291, - 396, - 428, - 199, - 311, - 271, - 268, - 283, - 444, - 445, - 373, - 254, - 339, - 263, - 466, - 249, - 282, - 334, - 296, - 449, - 347, - 346, - 264, - 447, - 454, - 336, - 296, - 299, - 338, - 10, - 151, - 278, - 439, - 455, - 292, - 407, - 415, - 358, - 371, - 355, - 340, - 345, - 372, - 390, - 249, - 466, - 346, - 347, - 280, - 442, - 443, - 282, - 19, - 94, - 370, - 441, - 442, - 295, - 248, - 419, - 197, - 263, - 255, - 359, - 440, - 275, - 274, - 300, - 383, - 368, - 351, - 412, - 465, - 263, - 467, - 466, - 301, - 368, - 389, - 380, - 374, - 386, - 395, - 378, - 379, - 412, - 351, - 419, - 436, - 426, - 322, - 373, - 390, - 388, - 2, - 164, - 393, - 370, - 462, - 461, - 164, - 0, - 267, - 302, - 11, - 12, - 374, - 373, - 387, - 268, - 12, - 13, - 293, - 300, - 301, - 446, - 261, - 340, - 385, - 384, - 381, - 330, - 266, - 425, - 426, - 423, - 391, - 429, - 355, - 437, - 391, - 327, - 326, - 440, - 457, - 438, - 341, - 382, - 362, - 459, - 457, - 461, - 434, - 430, - 394, - 414, - 463, - 362, - 396, - 369, - 262, - 354, - 461, - 457, - 316, - 403, - 402, - 315, - 404, - 403, - 314, - 405, - 404, - 313, - 406, - 405, - 421, - 418, - 406, - 366, - 401, - 361, - 306, - 408, - 407, - 291, - 409, - 408, - 287, - 410, - 409, - 432, - 436, - 410, - 434, - 416, - 411, - 264, - 368, - 383, - 309, - 438, - 457, - 352, - 376, - 401, - 274, - 275, - 4, - 421, - 428, - 262, - 294, - 327, - 358, - 433, - 416, - 367, - 289, - 455, - 439, - 462, - 370, - 326, - 2, - 326, - 370, - 305, - 460, - 455, - 254, - 449, - 448, - 255, - 261, - 446, - 253, - 450, - 449, - 252, - 451, - 450, - 256, - 452, - 451, - 341, - 453, - 452, - 413, - 464, - 463, - 441, - 413, - 414, - 258, - 442, - 441, - 257, - 443, - 442, - 259, - 444, - 443, - 260, - 445, - 444, - 467, - 342, - 445, - 459, - 458, - 250, - 289, - 392, - 290, - 290, - 328, - 460, - 376, - 433, - 435, - 250, - 290, - 392, - 411, - 416, - 433, - 341, - 463, - 464, - 453, - 464, - 465, - 357, - 465, - 412, - 343, - 412, - 399, - 360, - 363, - 440, - 437, - 399, - 456, - 420, - 456, - 363, - 401, - 435, - 288, - 372, - 383, - 353, - 339, - 255, - 249, - 448, - 261, - 255, - 133, - 243, - 190, - 133, - 155, - 112, - 33, - 246, - 247, - 33, - 130, - 25, - 398, - 384, - 286, - 362, - 398, - 414, - 362, - 463, - 341, - 263, - 359, - 467, - 263, - 249, - 255, - 466, - 467, - 260, - 75, - 60, - 166, - 238, - 239, - 79, - 162, - 127, - 139, - 72, - 11, - 37, - 121, - 232, - 120, - 73, - 72, - 39, - 114, - 128, - 47, - 233, - 232, - 128, - 103, - 104, - 67, - 152, - 175, - 148, - 173, - 157, - 155, - 119, - 118, - 101, - 74, - 73, - 40, - 107, - 9, - 108, - 49, - 48, - 131, - 32, - 194, - 211, - 184, - 74, - 185, - 191, - 80, - 183, - 185, - 40, - 186, - 119, - 230, - 118, - 210, - 202, - 214, - 84, - 83, - 17, - 77, - 76, - 146, - 161, - 160, - 30, - 190, - 56, - 173, - 182, - 106, - 194, - 138, - 135, - 192, - 129, - 203, - 98, - 54, - 21, - 68, - 5, - 51, - 4, - 145, - 144, - 23, - 90, - 77, - 91, - 207, - 205, - 187, - 83, - 201, - 18, - 181, - 91, - 182, - 180, - 90, - 181, - 16, - 85, - 17, - 205, - 206, - 36, - 176, - 148, - 140, - 165, - 92, - 39, - 245, - 193, - 244, - 27, - 159, - 28, - 30, - 247, - 161, - 174, - 236, - 196, - 103, - 54, - 104, - 55, - 193, - 8, - 111, - 117, - 31, - 221, - 189, - 55, - 240, - 98, - 99, - 142, - 126, - 100, - 219, - 166, - 218, - 112, - 155, - 26, - 198, - 209, - 131, - 169, - 135, - 150, - 114, - 47, - 217, - 224, - 223, - 53, - 220, - 45, - 134, - 32, - 211, - 140, - 109, - 67, - 108, - 146, - 43, - 91, - 231, - 230, - 120, - 113, - 226, - 247, - 105, - 63, - 52, - 241, - 238, - 242, - 124, - 46, - 156, - 95, - 78, - 96, - 70, - 46, - 63, - 116, - 143, - 227, - 116, - 123, - 111, - 1, - 44, - 19, - 3, - 236, - 51, - 207, - 216, - 205, - 26, - 154, - 22, - 165, - 39, - 167, - 199, - 200, - 208, - 101, - 36, - 100, - 43, - 57, - 202, - 242, - 20, - 99, - 56, - 28, - 157, - 124, - 35, - 113, - 29, - 160, - 27, - 211, - 204, - 210, - 124, - 113, - 46, - 106, - 43, - 204, - 96, - 62, - 77, - 227, - 137, - 116, - 73, - 41, - 72, - 36, - 203, - 142, - 235, - 64, - 240, - 48, - 49, - 64, - 42, - 41, - 74, - 214, - 212, - 207, - 183, - 42, - 184, - 210, - 169, - 211, - 140, - 170, - 176, - 104, - 105, - 69, - 193, - 122, - 168, - 50, - 123, - 187, - 89, - 96, - 90, - 66, - 65, - 107, - 179, - 89, - 180, - 119, - 101, - 120, - 68, - 63, - 104, - 234, - 93, - 227, - 16, - 15, - 85, - 209, - 129, - 49, - 15, - 14, - 86, - 107, - 55, - 9, - 120, - 100, - 121, - 153, - 145, - 22, - 178, - 88, - 179, - 197, - 6, - 196, - 89, - 88, - 96, - 135, - 138, - 136, - 138, - 215, - 172, - 218, - 115, - 219, - 41, - 42, - 81, - 5, - 195, - 51, - 57, - 43, - 61, - 208, - 171, - 199, - 41, - 81, - 38, - 224, - 53, - 225, - 24, - 144, - 110, - 105, - 52, - 66, - 118, - 229, - 117, - 227, - 34, - 234, - 66, - 107, - 69, - 10, - 109, - 151, - 219, - 48, - 235, - 183, - 62, - 191, - 142, - 129, - 126, - 116, - 111, - 143, - 7, - 163, - 246, - 118, - 117, - 50, - 223, - 222, - 52, - 94, - 19, - 141, - 222, - 221, - 65, - 196, - 3, - 197, - 45, - 220, - 44, - 156, - 70, - 139, - 188, - 122, - 245, - 139, - 71, - 162, - 145, - 153, - 159, - 149, - 170, - 150, - 122, - 188, - 196, - 206, - 216, - 92, - 163, - 144, - 161, - 164, - 2, - 167, - 242, - 141, - 241, - 0, - 164, - 37, - 11, - 72, - 12, - 144, - 145, - 160, - 12, - 38, - 13, - 70, - 63, - 71, - 31, - 226, - 111, - 157, - 158, - 154, - 36, - 101, - 205, - 203, - 206, - 165, - 126, - 209, - 217, - 98, - 165, - 97, - 237, - 220, - 218, - 237, - 239, - 241, - 210, - 214, - 169, - 140, - 171, - 32, - 241, - 125, - 237, - 179, - 86, - 178, - 180, - 85, - 179, - 181, - 84, - 180, - 182, - 83, - 181, - 194, - 201, - 182, - 177, - 137, - 132, - 184, - 76, - 183, - 185, - 61, - 184, - 186, - 57, - 185, - 216, - 212, - 186, - 192, - 214, - 187, - 139, - 34, - 156, - 218, - 79, - 237, - 147, - 123, - 177, - 45, - 44, - 4, - 208, - 201, - 32, - 98, - 64, - 129, - 192, - 213, - 138, - 235, - 59, - 219, - 141, - 242, - 97, - 97, - 2, - 141, - 240, - 75, - 235, - 229, - 24, - 228, - 31, - 25, - 226, - 230, - 23, - 229, - 231, - 22, - 230, - 232, - 26, - 231, - 233, - 112, - 232, - 244, - 189, - 243, - 189, - 221, - 190, - 222, - 28, - 221, - 223, - 27, - 222, - 224, - 29, - 223, - 225, - 30, - 224, - 113, - 247, - 225, - 99, - 60, - 240, - 213, - 147, - 215, - 60, - 20, - 166, - 192, - 187, - 213, - 243, - 112, - 244, - 244, - 233, - 245, - 245, - 128, - 188, - 188, - 114, - 174, - 134, - 131, - 220, - 174, - 217, - 236, - 236, - 198, - 134, - 215, - 177, - 58, - 156, - 143, - 124, - 25, - 110, - 7, - 31, - 228, - 25, - 264, - 356, - 368, - 0, - 11, - 267, - 451, - 452, - 349, - 267, - 302, - 269, - 350, - 357, - 277, - 350, - 452, - 357, - 299, - 333, - 297, - 396, - 175, - 377, - 381, - 384, - 382, - 280, - 347, - 330, - 269, - 303, - 270, - 151, - 9, - 337, - 344, - 278, - 360, - 424, - 418, - 431, - 270, - 304, - 409, - 272, - 310, - 407, - 322, - 270, - 410, - 449, - 450, - 347, - 432, - 422, - 434, - 18, - 313, - 17, - 291, - 306, - 375, - 259, - 387, - 260, - 424, - 335, - 418, - 434, - 364, - 416, - 391, - 423, - 327, - 301, - 251, - 298, - 275, - 281, - 4, - 254, - 373, - 253, - 375, - 307, - 321, - 280, - 425, - 411, - 200, - 421, - 18, - 335, - 321, - 406, - 321, - 320, - 405, - 314, - 315, - 17, - 423, - 426, - 266, - 396, - 377, - 369, - 270, - 322, - 269, - 413, - 417, - 464, - 385, - 386, - 258, - 248, - 456, - 419, - 298, - 284, - 333, - 168, - 417, - 8, - 448, - 346, - 261, - 417, - 413, - 285, - 326, - 327, - 328, - 277, - 355, - 329, - 309, - 392, - 438, - 381, - 382, - 256, - 279, - 429, - 360, - 365, - 364, - 379, - 355, - 277, - 437, - 282, - 443, - 283, - 281, - 275, - 363, - 395, - 431, - 369, - 299, - 297, - 337, - 335, - 273, - 321, - 348, - 450, - 349, - 359, - 446, - 467, - 283, - 293, - 282, - 250, - 458, - 462, - 300, - 276, - 383, - 292, - 308, - 325, - 283, - 276, - 293, - 264, - 372, - 447, - 346, - 352, - 340, - 354, - 274, - 19, - 363, - 456, - 281, - 426, - 436, - 425, - 380, - 381, - 252, - 267, - 269, - 393, - 421, - 200, - 428, - 371, - 266, - 329, - 432, - 287, - 422, - 290, - 250, - 328, - 385, - 258, - 384, - 446, - 265, - 342, - 386, - 387, - 257, - 422, - 424, - 430, - 445, - 342, - 276, - 422, - 273, - 424, - 306, - 292, - 307, - 352, - 366, - 345, - 268, - 271, - 302, - 358, - 423, - 371, - 327, - 294, - 460, - 331, - 279, - 294, - 303, - 271, - 304, - 436, - 432, - 427, - 304, - 272, - 408, - 395, - 394, - 431, - 378, - 395, - 400, - 296, - 334, - 299, - 6, - 351, - 168, - 376, - 352, - 411, - 307, - 325, - 320, - 285, - 295, - 336, - 320, - 319, - 404, - 329, - 330, - 349, - 334, - 293, - 333, - 366, - 323, - 447, - 316, - 15, - 315, - 331, - 358, - 279, - 317, - 14, - 316, - 8, - 285, - 9, - 277, - 329, - 350, - 253, - 374, - 252, - 319, - 318, - 403, - 351, - 6, - 419, - 324, - 318, - 325, - 397, - 367, - 365, - 288, - 435, - 397, - 278, - 344, - 439, - 310, - 272, - 311, - 248, - 195, - 281, - 375, - 273, - 291, - 175, - 396, - 199, - 312, - 311, - 268, - 276, - 283, - 445, - 390, - 373, - 339, - 295, - 282, - 296, - 448, - 449, - 346, - 356, - 264, - 454, - 337, - 336, - 299, - 337, - 338, - 151, - 294, - 278, - 455, - 308, - 292, - 415, - 429, - 358, - 355, - 265, - 340, - 372, - 388, - 390, - 466, - 352, - 346, - 280, - 295, - 442, - 282, - 354, - 19, - 370, - 285, - 441, - 295, - 195, - 248, - 197, - 457, - 440, - 274, - 301, - 300, - 368, - 417, - 351, - 465, - 251, - 301, - 389, - 385, - 380, - 386, - 394, - 395, - 379, - 399, - 412, - 419, - 410, - 436, - 322, - 387, - 373, - 388, - 326, - 2, - 393, - 354, - 370, - 461, - 393, - 164, - 267, - 268, - 302, - 12, - 386, - 374, - 387, - 312, - 268, - 13, - 298, - 293, - 301, - 265, - 446, - 340, - 380, - 385, - 381, - 280, - 330, - 425, - 322, - 426, - 391, - 420, - 429, - 437, - 393, - 391, - 326, - 344, - 440, - 438, - 458, - 459, - 461, - 364, - 434, - 394, - 428, - 396, - 262, - 274, - 354, - 457, - 317, - 316, - 402, - 316, - 315, - 403, - 315, - 314, - 404, - 314, - 313, - 405, - 313, - 421, - 406, - 323, - 366, - 361, - 292, - 306, - 407, - 306, - 291, - 408, - 291, - 287, - 409, - 287, - 432, - 410, - 427, - 434, - 411, - 372, - 264, - 383, - 459, - 309, - 457, - 366, - 352, - 401, - 1, - 274, - 4, - 418, - 421, - 262, - 331, - 294, - 358, - 435, - 433, - 367, - 392, - 289, - 439, - 328, - 462, - 326, - 94, - 2, - 370, - 289, - 305, - 455, - 339, - 254, - 448, - 359, - 255, - 446, - 254, - 253, - 449, - 253, - 252, - 450, - 252, - 256, - 451, - 256, - 341, - 452, - 414, - 413, - 463, - 286, - 441, - 414, - 286, - 258, - 441, - 258, - 257, - 442, - 257, - 259, - 443, - 259, - 260, - 444, - 260, - 467, - 445, - 309, - 459, - 250, - 305, - 289, - 290, - 305, - 290, - 460, - 401, - 376, - 435, - 309, - 250, - 392, - 376, - 411, - 433, - 453, - 341, - 464, - 357, - 453, - 465, - 343, - 357, - 412, - 437, - 343, - 399, - 344, - 360, - 440, - 420, - 437, - 456, - 360, - 420, - 363, - 361, - 401, - 288, - 265, - 372, - 353, - 390, - 339, - 249, - 339, - 448, - 255 -]; -var VTX68 = [ - 127, - 234, - 132, - 58, - 172, - 150, - 149, - 148, - 152, - 377, - 378, - 379, - 397, - 288, - 361, - 454, - 356, - 70, - 63, - 105, - 66, - 107, - 336, - 296, - 334, - 293, - 300, - 168, - 6, - 195, - 4, - 98, - 97, - 2, - 326, - 327, - 33, - 160, - 158, - 133, - 153, - 144, - 362, - 385, - 387, - 263, - 373, - 380, - 57, - 40, - 37, - 0, - 267, - 270, - 287, - 321, - 314, - 17, - 84, - 91, - 78, - 81, - 13, - 311, - 308, - 402, - 14, - 178 -]; -var VTX33 = [33, 133, 362, 263, 1, 62, 308, 159, 145, 386, 374, 6, 102, 331, 2, 13, 14, 70, 105, 107, 336, 334, 300, 54, 10, 284, 50, 280, 234, 454, 58, 288, 152]; -var VTX7 = [33, 133, 362, 263, 1, 78, 308]; -var UV68 = VTX68.map((x) => UV468[x]); -var UV33 = VTX33.map((x) => UV468[x]); -var UV7 = VTX7.map((x) => UV468[x]); -function connectionsToIndices(connections) { - const indices = connections.map((connection) => connection[0]); - indices.push(connections[connections.length - 1][1]); - return indices; -} -var pairsLips = [ - [61, 146], - [146, 91], - [91, 181], - [181, 84], - [84, 17], - [17, 314], - [314, 405], - [405, 321], - [321, 375], - [375, 291], - [61, 185], - [185, 40], - [40, 39], - [39, 37], - [37, 0], - [0, 267], - [267, 269], - [269, 270], - [270, 409], - [409, 291], - [78, 95], - [95, 88], - [88, 178], - [178, 87], - [87, 14], - [14, 317], - [317, 402], - [402, 318], - [318, 324], - [324, 308], - [78, 191], - [191, 80], - [80, 81], - [81, 82], - [82, 13], - [13, 312], - [312, 311], - [311, 310], - [310, 415], - [415, 308] -]; -var pairsLeftEye = [[263, 249], [249, 390], [390, 373], [373, 374], [374, 380], [380, 381], [381, 382], [382, 362], [263, 466], [466, 388], [388, 387], [387, 386], [386, 385], [385, 384], [384, 398], [398, 362]]; -var pairsLeftEyebrow = [[276, 283], [283, 282], [282, 295], [295, 285], [300, 293], [293, 334], [334, 296], [296, 336]]; -var pairsLeftIris = [[474, 475], [475, 476], [476, 477], [477, 474]]; -var pairsRightEye = [[33, 7], [7, 163], [163, 144], [144, 145], [145, 153], [153, 154], [154, 155], [155, 133], [33, 246], [246, 161], [161, 160], [160, 159], [159, 158], [158, 157], [157, 173], [173, 133]]; -var pairsRightEyebrow = [[46, 53], [53, 52], [52, 65], [65, 55], [70, 63], [63, 105], [105, 66], [66, 107]]; -var pairsRightIris = [[469, 470], [470, 471], [471, 472], [472, 469]]; -var pairsFaceContour = [ - [10, 338], - [338, 297], - [297, 332], - [332, 284], - [284, 251], - [251, 389], - [389, 356], - [356, 454], - [454, 323], - [323, 361], - [361, 288], - [288, 397], - [397, 365], - [365, 379], - [379, 378], - [378, 400], - [400, 377], - [377, 152], - [152, 148], - [148, 176], - [176, 149], - [149, 150], - [150, 136], - [136, 172], - [172, 58], - [58, 132], - [132, 93], - [93, 234], - [234, 127], - [127, 162], - [162, 21], - [21, 54], - [54, 103], - [103, 67], - [67, 109], - [109, 10] -]; -var contourKeypoints = { - lips: connectionsToIndices(pairsLips), - leftEye: connectionsToIndices(pairsLeftEye), - leftEyebrow: connectionsToIndices(pairsLeftEyebrow), - leftIris: connectionsToIndices(pairsLeftIris), - rightEye: connectionsToIndices(pairsRightEye), - rightEyebrow: connectionsToIndices(pairsRightEyebrow), - rightIris: connectionsToIndices(pairsRightIris), - faceOval: connectionsToIndices(pairsFaceContour) -}; - -// src/face/constants.ts -var LIPS_CONNECTIONS = [ - [61, 146], - [146, 91], - [91, 181], - [181, 84], - [84, 17], - [17, 314], - [314, 405], - [405, 321], - [321, 375], - [375, 291], - [61, 185], - [185, 40], - [40, 39], - [39, 37], - [37, 0], - [0, 267], - [267, 269], - [269, 270], - [270, 409], - [409, 291], - [78, 95], - [95, 88], - [88, 178], - [178, 87], - [87, 14], - [14, 317], - [317, 402], - [402, 318], - [318, 324], - [324, 308], - [78, 191], - [191, 80], - [80, 81], - [81, 82], - [82, 13], - [13, 312], - [312, 311], - [311, 310], - [310, 415], - [415, 308] -]; -var LEFT_EYE_CONNECTIONS = [[263, 249], [249, 390], [390, 373], [373, 374], [374, 380], [380, 381], [381, 382], [382, 362], [263, 466], [466, 388], [388, 387], [387, 386], [386, 385], [385, 384], [384, 398], [398, 362]]; -var LEFT_EYEBROW_CONNECTIONS = [[276, 283], [283, 282], [282, 295], [295, 285], [300, 293], [293, 334], [334, 296], [296, 336]]; -var LEFT_IRIS_CONNECTIONS = [[474, 475], [475, 476], [476, 477], [477, 474]]; -var RIGHT_EYE_CONNECTIONS = [[33, 7], [7, 163], [163, 144], [144, 145], [145, 153], [153, 154], [154, 155], [155, 133], [33, 246], [246, 161], [161, 160], [160, 159], [159, 158], [158, 157], [157, 173], [173, 133]]; -var RIGHT_EYEBROW_CONNECTIONS = [[46, 53], [53, 52], [52, 65], [65, 55], [70, 63], [63, 105], [105, 66], [66, 107]]; -var RIGHT_IRIS_CONNECTIONS = [[469, 470], [470, 471], [471, 472], [472, 469]]; -var FACE_OVAL_CONNECTIONS = [ - [10, 338], - [338, 297], - [297, 332], - [332, 284], - [284, 251], - [251, 389], - [389, 356], - [356, 454], - [454, 323], - [323, 361], - [361, 288], - [288, 397], - [397, 365], - [365, 379], - [379, 378], - [378, 400], - [400, 377], - [377, 152], - [152, 148], - [148, 176], - [176, 149], - [149, 150], - [150, 136], - [136, 172], - [172, 58], - [58, 132], - [132, 93], - [93, 234], - [234, 127], - [127, 162], - [162, 21], - [21, 54], - [54, 103], - [103, 67], - [67, 109], - [109, 10] -]; -function connectionsToIndices2(connections) { - const indices = connections.map((connection) => connection[0]); - indices.push(connections[connections.length - 1][1]); - return indices; -} -var MEDIAPIPE_FACE_MESH_KEYPOINTS_BY_CONTOUR = { - lips: connectionsToIndices2(LIPS_CONNECTIONS), - leftEye: connectionsToIndices2(LEFT_EYE_CONNECTIONS), - leftEyebrow: connectionsToIndices2(LEFT_EYEBROW_CONNECTIONS), - leftIris: connectionsToIndices2(LEFT_IRIS_CONNECTIONS), - rightEye: connectionsToIndices2(RIGHT_EYE_CONNECTIONS), - rightEyebrow: connectionsToIndices2(RIGHT_EYEBROW_CONNECTIONS), - rightIris: connectionsToIndices2(RIGHT_IRIS_CONNECTIONS), - faceOval: connectionsToIndices2(FACE_OVAL_CONNECTIONS) -}; -var indexLabelPairs = Object.entries(MEDIAPIPE_FACE_MESH_KEYPOINTS_BY_CONTOUR).map(([label, indices]) => indices.map((index2) => [index2, label])).flat(); -var MEDIAPIPE_FACE_MESH_KEYPOINTS = new Map(indexLabelPairs); -var LANDMARKS_REFINEMENT_LIPS_CONFIG = [ - 61, - 146, - 91, - 181, - 84, - 17, - 314, - 405, - 321, - 375, - 291, - 185, - 40, - 39, - 37, - 0, - 267, - 269, - 270, - 409, - 78, - 95, - 88, - 178, - 87, - 14, - 317, - 402, - 318, - 324, - 308, - 191, - 80, - 81, - 82, - 13, - 312, - 311, - 310, - 415, - 76, - 77, - 90, - 180, - 85, - 16, - 315, - 404, - 320, - 307, - 306, - 184, - 74, - 73, - 72, - 11, - 302, - 303, - 304, - 408, - 62, - 96, - 89, - 179, - 86, - 15, - 316, - 403, - 319, - 325, - 292, - 183, - 42, - 41, - 38, - 12, - 268, - 271, - 272, - 407 -]; -var LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG = [ - 33, - 7, - 163, - 144, - 145, - 153, - 154, - 155, - 133, - 246, - 161, - 160, - 159, - 158, - 157, - 173, - 130, - 25, - 110, - 24, - 23, - 22, - 26, - 112, - 243, - 247, - 30, - 29, - 27, - 28, - 56, - 190, - 226, - 31, - 228, - 229, - 230, - 231, - 232, - 233, - 244, - 113, - 225, - 224, - 223, - 222, - 221, - 189, - 35, - 124, - 46, - 53, - 52, - 65, - 143, - 111, - 117, - 118, - 119, - 120, - 121, - 128, - 245, - 156, - 70, - 63, - 105, - 66, - 107, - 55, - 193 -]; -var LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG = [ - 263, - 249, - 390, - 373, - 374, - 380, - 381, - 382, - 362, - 466, - 388, - 387, - 386, - 385, - 384, - 398, - 359, - 255, - 339, - 254, - 253, - 252, - 256, - 341, - 463, - 467, - 260, - 259, - 257, - 258, - 286, - 414, - 446, - 261, - 448, - 449, - 450, - 451, - 452, - 453, - 464, - 342, - 445, - 444, - 443, - 442, - 441, - 413, - 265, - 353, - 276, - 283, - 282, - 295, - 372, - 340, - 346, - 347, - 348, - 349, - 350, - 357, - 465, - 383, - 300, - 293, - 334, - 296, - 336, - 285, - 417 -]; - -// src/draw/face.ts -var localOptions; -function drawLabels(f, ctx) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i; - if (!localOptions.drawLabels || ((_a = localOptions.faceLabels) == null ? void 0 : _a.length) === 0) - return; - let l = localOptions.faceLabels.slice(); - if (f.score) - l = replace(l, "[score]", 100 * f.score); - if (f.gender) - l = replace(l, "[gender]", f.gender); - if (f.genderScore) - l = replace(l, "[genderScore]", 100 * f.genderScore); - if (f.age) - l = replace(l, "[age]", f.age); - if (f.distance) - l = replace(l, "[distance]", 100 * f.distance); - if (f.real) - l = replace(l, "[real]", 100 * f.real); - if (f.live) - l = replace(l, "[live]", 100 * f.live); - if (f.emotion && f.emotion.length > 0) { - const emotion2 = f.emotion.map((a) => `${Math.trunc(100 * a.score)}% ${a.emotion}`); - if (emotion2.length > 3) - emotion2.length = 3; - l = replace(l, "[emotions]", emotion2.join(" ")); - } - if ((_c = (_b = f.rotation) == null ? void 0 : _b.angle) == null ? void 0 : _c.roll) - l = replace(l, "[roll]", rad2deg(f.rotation.angle.roll)); - if ((_e = (_d = f.rotation) == null ? void 0 : _d.angle) == null ? void 0 : _e.yaw) - l = replace(l, "[yaw]", rad2deg(f.rotation.angle.yaw)); - if ((_g = (_f = f.rotation) == null ? void 0 : _f.angle) == null ? void 0 : _g.pitch) - l = replace(l, "[pitch]", rad2deg(f.rotation.angle.pitch)); - if ((_i = (_h = f.rotation) == null ? void 0 : _h.gaze) == null ? void 0 : _i.bearing) - l = replace(l, "[gaze]", rad2deg(f.rotation.gaze.bearing)); - labels(ctx, l, f.box[0], f.box[1], localOptions); -} -function drawIrisElipse(f, ctx) { - var _a, _b, _c, _d; - if (((_a = f.annotations) == null ? void 0 : _a.leftEyeIris) && ((_b = f.annotations) == null ? void 0 : _b.leftEyeIris[0])) { - ctx.strokeStyle = localOptions.useDepth ? "rgba(255, 200, 255, 0.3)" : localOptions.color; - ctx.beginPath(); - const sizeX = Math.abs(f.annotations.leftEyeIris[3][0] - f.annotations.leftEyeIris[1][0]) / 2; - const sizeY = Math.abs(f.annotations.leftEyeIris[4][1] - f.annotations.leftEyeIris[2][1]) / 2; - ctx.ellipse(f.annotations.leftEyeIris[0][0], f.annotations.leftEyeIris[0][1], sizeX, sizeY, 0, 0, 2 * Math.PI); - ctx.stroke(); - if (localOptions.fillPolygons) { - ctx.fillStyle = localOptions.useDepth ? "rgba(255, 255, 200, 0.3)" : localOptions.color; - ctx.fill(); - } - } - if (((_c = f.annotations) == null ? void 0 : _c.rightEyeIris) && ((_d = f.annotations) == null ? void 0 : _d.rightEyeIris[0])) { - ctx.strokeStyle = localOptions.useDepth ? "rgba(255, 200, 255, 0.3)" : localOptions.color; - ctx.beginPath(); - const sizeX = Math.abs(f.annotations.rightEyeIris[3][0] - f.annotations.rightEyeIris[1][0]) / 2; - const sizeY = Math.abs(f.annotations.rightEyeIris[4][1] - f.annotations.rightEyeIris[2][1]) / 2; - ctx.ellipse(f.annotations.rightEyeIris[0][0], f.annotations.rightEyeIris[0][1], sizeX, sizeY, 0, 0, 2 * Math.PI); - ctx.stroke(); - if (localOptions.fillPolygons) { - ctx.fillStyle = localOptions.useDepth ? "rgba(255, 255, 200, 0.3)" : localOptions.color; - ctx.fill(); - } - } -} -function drawGazeSpheres(f, ctx) { - var _a; - if (localOptions.drawGaze && ((_a = f.rotation) == null ? void 0 : _a.angle) && typeof Path2D !== "undefined") { - ctx.strokeStyle = "pink"; - const valX = f.box[0] + f.box[2] / 2 - f.box[3] * rad2deg(f.rotation.angle.yaw) / 90; - const valY = f.box[1] + f.box[3] / 2 + f.box[2] * rad2deg(f.rotation.angle.pitch) / 90; - const pathV = new Path2D(` - M ${f.box[0] + f.box[2] / 2} ${f.box[1]} +`;var Yt=(e,t,n)=>{let o=new RegExp("\\b"+t+" \\w+ (\\w+)","ig");e.replace(o,(r,s)=>(n[s]=0,r))},Kt=class{constructor(t,n,o){k(this,"uniform",{});k(this,"attribute",{});k(this,"gl");k(this,"id");k(this,"compile",(t,n)=>{let o=this.gl.createShader(n);return o?(this.gl.shaderSource(o,t),this.gl.compileShader(o),this.gl.getShaderParameter(o,this.gl.COMPILE_STATUS)?o:(u(`filter: gl compile failed: ${this.gl.getShaderInfoLog(o)||"unknown"}`),null)):(u("filter: could not create shader"),null)});this.gl=t;let r=this.compile(n,this.gl.VERTEX_SHADER),s=this.compile(o,this.gl.FRAGMENT_SHADER);if(this.id=this.gl.createProgram(),!(!r||!s)){if(!this.id){u("filter: could not create webgl program");return}if(this.gl.attachShader(this.id,r),this.gl.attachShader(this.id,s),this.gl.linkProgram(this.id),!this.gl.getProgramParameter(this.id,this.gl.LINK_STATUS)){u(`filter: gl link failed: ${this.gl.getProgramInfoLog(this.id)||"unknown"}`);return}this.gl.useProgram(this.id),Yt(n,"attribute",this.attribute);for(let A in this.attribute)this.attribute[A]=this.gl.getAttribLocation(this.id,A);Yt(n,"uniform",this.uniform),Yt(o,"uniform",this.uniform);for(let A in this.uniform)this.uniform[A]=this.gl.getUniformLocation(this.id,A)}}};function C1(){let e=0,t=null,n=!1,o=-1,r=[null,null],s=[],A=null,a=null,l=te(100,100),c={},x={INTERMEDIATE:1},i=l.getContext("webgl");if(!i){u("filter: cannot get webgl context");return}this.gl=i;function y(T,m){if(!(T===l.width&&m===l.height)){if(l.width=T,l.height=m,!A){let h=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]);A=i.createBuffer(),i.bindBuffer(i.ARRAY_BUFFER,A),i.bufferData(i.ARRAY_BUFFER,h,i.STATIC_DRAW),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0)}i.viewport(0,0,l.width,l.height),r=[null,null]}}function d(T,m){let h=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,h);let S=i.createRenderbuffer();i.bindRenderbuffer(i.RENDERBUFFER,S);let P=i.createTexture();return i.bindTexture(i.TEXTURE_2D,P),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,T,m,0,i.RGBA,i.UNSIGNED_BYTE,null),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,P,0),i.bindTexture(i.TEXTURE_2D,null),i.bindFramebuffer(i.FRAMEBUFFER,null),{fbo:h,texture:P}}function p(T){return r[T]=r[T]||d(l.width,l.height),r[T]}function f(T=0){if(!a)return;let m=null,h=null,S=!1;e===0?m=t:m=p(o).texture||null,e++,n&&!(T&x.INTERMEDIATE)?(h=null,S=e%2===0):(o=(o+1)%2,h=p(o).fbo||null),i.bindTexture(i.TEXTURE_2D,m),i.bindFramebuffer(i.FRAMEBUFFER,h),i.uniform1f(a.uniform.flipY,S?-1:1),i.drawArrays(i.TRIANGLES,0,6)}function b(T){if(c[T])return a=c[T],i.useProgram((a?a.id:null)||null),a;if(a=new Kt(i,S1,T),!a)return u("filter: could not get webgl program"),null;let m=Float32Array.BYTES_PER_ELEMENT,h=4*m;return i.enableVertexAttribArray(a.attribute.pos),i.vertexAttribPointer(a.attribute.pos,2,i.FLOAT,!1,h,0*m),i.enableVertexAttribArray(a.attribute.uv),i.vertexAttribPointer(a.attribute.uv,2,i.FLOAT,!1,h,2*m),c[T]=a,a}let M={colorMatrix:T=>{let m=new Float32Array(T);m[4]/=255,m[9]/=255,m[14]/=255,m[19]/=255;let h=m[18]===1&&m[3]===0&&m[8]===0&&m[13]===0&&m[15]===0&&m[16]===0&&m[17]===0&&m[19]===0?N1:j1,S=b(h);!S||(i.uniform1fv(S.uniform.m,m),f())},brightness:T=>{let m=(T||0)+1;M.colorMatrix([m,0,0,0,0,0,m,0,0,0,0,0,m,0,0,0,0,0,1,0])},saturation:T=>{let m=(T||0)*2/3+1,h=(m-1)*-.5;M.colorMatrix([m,h,h,0,0,h,m,h,0,0,h,h,m,0,0,0,0,0,1,0])},desaturate:()=>{M.saturation(-1)},contrast:T=>{let m=(T||0)+1,h=-128*(m-1);M.colorMatrix([m,0,0,0,h,0,m,0,0,h,0,0,m,0,h,0,0,0,1,0])},negative:()=>{M.contrast(-2)},hue:T=>{T=(T||0)/180*Math.PI;let m=Math.cos(T),h=Math.sin(T),S=.213,P=.715,I=.072;M.colorMatrix([S+m*(1-S)+h*-S,P+m*-P+h*-P,I+m*-I+h*(1-I),0,0,S+m*-S+h*.143,P+m*(1-P)+h*.14,I+m*-I+h*-.283,0,0,S+m*-S+h*-(1-S),P+m*-P+h*P,I+m*(1-I)+h*I,0,0,0,0,0,1,0])},desaturateLuminance:()=>{M.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:()=>{M.colorMatrix([.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0])},brownie:()=>{M.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:()=>{M.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:()=>{M.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:()=>{M.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:()=>{M.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:()=>{M.colorMatrix([0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0])},convolution:T=>{let m=new Float32Array(T),h=1/l.width,S=1/l.height,P=b(L1);!P||(i.uniform1fv(P.uniform.m,m),i.uniform2f(P.uniform.px,h,S),f())},detectEdges:()=>{M.convolution.call(this,[0,1,0,1,-4,1,0,1,0])},sobelX:()=>{M.convolution.call(this,[-1,0,1,-2,0,2,-1,0,1])},sobelY:()=>{M.convolution.call(this,[-1,-2,-1,0,0,0,1,2,1])},sharpen:T=>{let m=T||1;M.convolution.call(this,[0,-1*m,0,-1*m,1+4*m,-1*m,0,-1*m,0])},emboss:T=>{let m=T||1;M.convolution.call(this,[-2*m,-1*m,0,-1*m,1,1*m,0,1*m,2*m])},blur:T=>{let m=T/7/l.width,h=T/7/l.height,S=b(O1);!S||(i.uniform2f(S.uniform.px,0,h),f(x.INTERMEDIATE),i.uniform2f(S.uniform.px,m,0),f())},pixelate:T=>{let m=T/l.width,h=T/l.height,S=b(I1);!S||(i.uniform2f(S.uniform.size,m,h),f())}};this.add=function(T){let m=Array.prototype.slice.call(arguments,1),h=M[T];s.push({func:h,args:m})},this.reset=function(){s=[]},this.get=function(){return s},this.apply=function(T){y(T.width,T.height),e=0,t||(t=i.createTexture()),i.bindTexture(i.TEXTURE_2D,t),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,T);for(let m=0;mx.data())),A=Math.max(s[0][0],s[1][0],s[2][0]),l=(A>1?255:1)/A,c;if(l>1){let x=[Y.sub(n[0],o[0]),Y.sub(n[1],o[1]),Y.sub(n[2],o[2])],i=[Y.sub(r[0],o[0]),Y.sub(r[1],o[1]),Y.sub(r[2],o[2])],y=[Y.mul(x[0],l),Y.mul(x[1],l),Y.mul(x[2],l)],d=Y.stack([y[0],y[1],y[2]],2);c=Y.reshape(d,[1,t.shape[0]||0,t.shape[1]||0,3]),Y.dispose([...x,...i,...y])}else c=Y.expandDims(t,0);return Y.dispose([...n,...o,...r,n,t,e]),c}var V2=3840,v0=null,R0=null,c2=null,e0,J0={inputSum:0,cacheDiff:1,sumMethod:0,inputTensor:void 0};function Jt(){J0.inputSum=0,J0.cacheDiff=1,J0.sumMethod=0,J0.inputTensor=void 0}function te(e,t){let n;if(R.browser)if(R.worker){if(typeof OffscreenCanvas=="undefined")throw new Error("canvas error: attempted to run in web worker but OffscreenCanvas is not supported");n=new OffscreenCanvas(e,t)}else{if(typeof document=="undefined")throw new Error("canvas error: attempted to run in browser but DOM is not defined");n=document.createElement("canvas"),n.width=e,n.height=t}else typeof R.Canvas!="undefined"?n=new R.Canvas(e,t):typeof globalThis.Canvas!="undefined"&&(n=new globalThis.Canvas(e,t));return n}function Z2(e,t){let n=t||te(e.width,e.height);return n.getContext("2d").drawImage(e,0,0),n}async function X2(e,t,n=!0){var y,d,p;if(!e)return t.debug&&u("input error: input is missing"),{tensor:null,canvas:null};if(!(e instanceof N.Tensor)&&!(typeof Image!="undefined"&&e instanceof Image)&&!(typeof globalThis.Canvas!="undefined"&&e instanceof globalThis.Canvas)&&!(typeof ImageData!="undefined"&&e instanceof ImageData)&&!(typeof ImageBitmap!="undefined"&&e instanceof ImageBitmap)&&!(typeof HTMLImageElement!="undefined"&&e instanceof HTMLImageElement)&&!(typeof HTMLMediaElement!="undefined"&&e instanceof HTMLMediaElement)&&!(typeof HTMLVideoElement!="undefined"&&e instanceof HTMLVideoElement)&&!(typeof HTMLCanvasElement!="undefined"&&e instanceof HTMLCanvasElement)&&!(typeof OffscreenCanvas!="undefined"&&e instanceof OffscreenCanvas))throw new Error("input error: type not recognized");if(e instanceof N.Tensor){let f=null;if(e.isDisposedInternal)throw new Error("input error: attempted to use tensor but it is disposed");if(!e.shape)throw new Error("input error: attempted to use tensor without a shape");if(e.shape.length===3){if(e.shape[2]===3)f=N.expandDims(e,0);else if(e.shape[2]===4){let b=N.slice3d(e,[0,0,0],[-1,-1,3]);f=N.expandDims(b,0),N.dispose(b)}}else e.shape.length===4&&(e.shape[3]===3?f=N.clone(e):e.shape[3]===4&&(f=N.slice4d(e,[0,0,0,0],[-1,-1,-1,3])));if(f==null||f.shape.length!==4||f.shape[0]!==1||f.shape[3]!==3)throw new Error(`input error: attempted to use tensor with unrecognized shape: ${e.shape.toString()}`);if(f.dtype==="int32"){let b=N.cast(f,"float32");N.dispose(f),f=b}return{tensor:f,canvas:t.filter.return?R0:null}}if(typeof e.readyState!="undefined"&&e.readyState<=2)return t.debug&&u("input stream is not ready"),{tensor:null,canvas:v0};let o=e.naturalWidth||e.videoWidth||e.width||e.shape&&e.shape[1]>0,r=e.naturalHeight||e.videoHeight||e.height||e.shape&&e.shape[2]>0;if(!o||!r)return t.debug&&u("cannot determine input dimensions"),{tensor:null,canvas:v0};let s=o,A=r;if(s>V2&&(s=V2,A=Math.trunc(s*r/o)),A>V2&&(A=V2,s=Math.trunc(A*o/r)),(((y=t.filter)==null?void 0:y.width)||0)>0?s=t.filter.width:(((d=t.filter)==null?void 0:d.height)||0)>0&&(s=o*((t.filter.height||0)/r)),(t.filter.height||0)>0?A=t.filter.height:(t.filter.width||0)>0&&(A=r*((t.filter.width||0)/o)),!s||!A)throw new Error("input error: cannot determine dimension");(!v0||v0.width!==s||v0.height!==A)&&(v0=te(s,A));let a=v0.getContext("2d");if(typeof ImageData!="undefined"&&e instanceof ImageData?a.putImageData(e,0,0):t.filter.flip&&typeof a.translate!="undefined"?(a.translate(o,0),a.scale(-1,1),a.drawImage(e,0,0,o,r,0,0,v0.width,v0.height),a.setTransform(1,0,0,1,0,0)):a.drawImage(e,0,0,o,r,0,0,v0.width,v0.height),(!R0||v0.width!==R0.width||v0.height!==R0.height)&&(R0=te(v0.width,v0.height)),t.filter.enabled&&R.webgl.supported?(e0||(e0=R.browser?new C1:null),R.filter=!!e0,e0!=null&&e0.add?(e0.reset(),t.filter.brightness!==0&&e0.add("brightness",t.filter.brightness),t.filter.contrast!==0&&e0.add("contrast",t.filter.contrast),t.filter.sharpness!==0&&e0.add("sharpen",t.filter.sharpness),t.filter.blur!==0&&e0.add("blur",t.filter.blur),t.filter.saturation!==0&&e0.add("saturation",t.filter.saturation),t.filter.hue!==0&&e0.add("hue",t.filter.hue),t.filter.negative&&e0.add("negative"),t.filter.sepia&&e0.add("sepia"),t.filter.vintage&&e0.add("brownie"),t.filter.sepia&&e0.add("sepia"),t.filter.kodachrome&&e0.add("kodachrome"),t.filter.technicolor&&e0.add("technicolor"),t.filter.polaroid&&e0.add("polaroid"),t.filter.pixelate!==0&&e0.add("pixelate",t.filter.pixelate),((p=e0.get())==null?void 0:p.length)>1?R0=e0.apply(v0):R0=e0.draw(v0)):(t.debug&&u("input process error: cannot initialize filters"),R.webgl.supported=!1,t.filter.enabled=!1,Z2(v0,R0))):(Z2(v0,R0),e0&&(e0=null),R.filter=!!e0),!n)return{tensor:null,canvas:R0};if(!R0)throw new Error("canvas error: cannot create output");let l,c=3;if(typeof ImageData!="undefined"&&e instanceof ImageData||e.data&&e.width&&e.height)if(R.browser&&N.browser)l=N.browser?N.browser.fromPixels(e):null;else{c=e.data.length/e.height/e.width;let f=new Uint8Array(e.data.buffer);l=N.tensor(f,[e.height,e.width,c],"int32")}else if((!c2||R0.width!==c2.width||R0.height!==c2.height)&&(c2=te(R0.width,R0.height)),N.browser&&R.browser)t.backend==="webgl"||t.backend==="humangl"||t.backend==="webgpu"?l=N.browser.fromPixels(R0):(c2=Z2(R0),l=N.browser.fromPixels(c2));else{let M=Z2(R0).getContext("2d").getImageData(0,0,s,A);c=M.data.length/s/A;let T=new Uint8Array(M.data.buffer);l=N.tensor(T,[s,A,c])}if(c===4){let f=N.slice3d(l,[0,0,0],[-1,-1,3]);N.dispose(l),l=f}if(!l)throw new Error("input error: cannot create tensor");let x=N.cast(l,"float32"),i=t.filter.equalization?await G2(x):N.expandDims(x,0);if(N.dispose([l,x]),t.filter.autoBrightness){let f=N.max(i),b=await f.data();t.filter.brightness=b[0]>1?1-b[0]/255:1-b[0],N.dispose(f)}return{tensor:i,canvas:t.filter.return?R0:null}}async function W1(e,t){let n=!1;if(e.cacheSensitivity===0||!t.shape||t.shape.length!==4||t.shape[1]>3840||t.shape[2]>2160)return n;if(!J0.inputTensor)J0.inputTensor=N.clone(t);else if(J0.inputTensor.shape[1]!==t.shape[1]||J0.inputTensor.shape[2]!==t.shape[2])N.dispose(J0.inputTensor),J0.inputTensor=N.clone(t);else{let o={};o.diff=N.sub(t,J0.inputTensor),o.squared=N.mul(o.diff,o.diff),o.sum=N.sum(o.squared);let s=(await o.sum.data())[0]/(t.shape[1]||1)/(t.shape[2]||1)/255/3;N.dispose([J0.inputTensor,o.diff,o.squared,o.sum]),J0.inputTensor=N.clone(t),n=s<=(e.cacheSensitivity||0)}return n}async function D1(e,t,n){let o={};if(!t||!n||t.shape.length!==4||t.shape.length!==n.shape.length)return e.debug||u("invalid input tensor or tensor shapes do not match:",t.shape,n.shape),0;if(t.shape[0]!==1||n.shape[0]!==1||t.shape[3]!==3||n.shape[3]!==3)return e.debug||u("input tensors must be of shape [1, height, width, 3]:",t.shape,n.shape),0;o.input1=N.clone(t),o.input2=t.shape[1]!==n.shape[1]||t.shape[2]!==n.shape[2]?N.image.resizeBilinear(n,[t.shape[1],t.shape[2]]):N.clone(n),o.diff=N.sub(o.input1,o.input2),o.squared=N.mul(o.diff,o.diff),o.sum=N.sum(o.squared);let s=(await o.sum.data())[0]/(t.shape[1]||1)/(t.shape[2]||1)/255/3;return N.dispose([o.input1,o.input2,o.diff,o.squared,o.sum]),s}var E2,z2,S2,w2=class{constructor(){k(this,"browser");k(this,"node");k(this,"worker");k(this,"platform","");k(this,"agent","");k(this,"backends",[]);k(this,"initial");k(this,"filter");k(this,"tfjs");k(this,"offscreen");k(this,"perfadd",!1);k(this,"tensorflow",{version:void 0,gpu:void 0});k(this,"wasm",{supported:void 0,backend:void 0,simd:void 0,multithread:void 0});k(this,"webgl",{supported:void 0,backend:void 0,version:void 0,renderer:void 0,shader:void 0,vendor:void 0});k(this,"webgpu",{supported:void 0,backend:void 0,adapter:void 0});k(this,"cpu",{model:void 0,flags:[]});k(this,"kernels",[]);me(this,E2,void 0);me(this,z2,void 0);me(this,S2,void 0);if(this.browser=typeof navigator!="undefined",this.node=typeof process!="undefined"&&typeof process.versions!="undefined"&&typeof process.versions.node!="undefined",this.tfjs={version:I0.version["tfjs-core"]},this.offscreen=typeof OffscreenCanvas!="undefined",this.initial=!0,this.worker=this.browser&&this.offscreen?typeof WorkerGlobalScope!="undefined":void 0,typeof navigator!="undefined"){let t=navigator.userAgent.match(/\(([^()]+)\)/g);if(t!=null&&t[0]){let n=t[0].match(/\(([^()]+)\)/g);this.platform=n!=null&&n[0]?n[0].replace(/\(|\)/g,""):"",this.agent=navigator.userAgent.replace(t[0],""),this.platform[1]&&(this.agent=this.agent.replace(t[1],"")),this.agent=this.agent.replace(/ /g," ")}}else typeof process!="undefined"&&(this.platform=`${process.platform} ${process.arch}`,this.agent=`NodeJS ${process.version}`)}get Canvas(){return G0(this,E2)}set Canvas(t){ge(this,E2,t),globalThis.Canvas=t}get Image(){return G0(this,z2)}set Image(t){ge(this,z2,t),globalThis.Image=t}get ImageData(){return G0(this,S2)}set ImageData(t){ge(this,S2,t),globalThis.ImageData=t}async updateBackend(){this.backends=Object.keys(I0.engine().registryFactory);try{this.tensorflow={version:I0.backend().binding?I0.backend().binding.TF_Version:void 0,gpu:I0.backend().binding?I0.backend().binding.isUsingGpuDevice():void 0}}catch(o){}this.wasm.supported=typeof WebAssembly!="undefined",this.wasm.backend=this.backends.includes("wasm"),this.wasm.supported&&this.wasm.backend&&(this.wasm.simd=await I0.env().getAsync("WASM_HAS_SIMD_SUPPORT"),this.wasm.multithread=await I0.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"));let t=te(100,100),n=t?t.getContext("webgl2"):void 0;this.webgl.supported=typeof n!="undefined",this.webgl.backend=this.backends.includes("webgl"),this.webgl.supported&&this.webgl.backend&&n&&(this.webgl.version=n.getParameter(n.VERSION),this.webgl.vendor=n.getParameter(n.VENDOR),this.webgl.renderer=n.getParameter(n.RENDERER),this.webgl.shader=n.getParameter(n.SHADING_LANGUAGE_VERSION)),this.webgpu.supported=this.browser&&typeof navigator.gpu!="undefined",this.webgpu.backend=this.backends.includes("webgpu");try{if(this.webgpu.supported){let o=await navigator.gpu.requestAdapter();this.webgpu.adapter=await(o==null?void 0:o.requestAdapterInfo())}}catch(o){this.webgpu.supported=!1}try{this.kernels=I0.getKernelsForBackend(I0.getBackend()).map(o=>o.kernelName.toLowerCase())}catch(o){}}updateCPU(){let t={model:"",flags:[]};this.node&&this.platform.startsWith("linux"),this.cpu?this.cpu=t:Object.defineProperty(this,"cpu",{value:t})}};E2=new WeakMap,z2=new WeakMap,S2=new WeakMap;var R=new w2;var U2=class{constructor(){k(this,"config");k(this,"element");k(this,"stream");k(this,"devices",[]);k(this,"enumerate",async()=>{try{let t=await navigator.mediaDevices.enumerateDevices();this.devices=t.filter(n=>n.kind==="videoinput")}catch(t){this.devices=[]}return this.devices});k(this,"start",async t=>{var r,s;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{this.config.debug&&u("webcam","cannot get dom element",t.element);return}}else if(t.element instanceof HTMLVideoElement)this.element=t.element;else{this.config.debug&&u("webcam","unknown dom element",t.element);return}else this.element=document.createElement("video");let n={audio:!1,video:{facingMode:this.config.mode==="front"?"user":"environment",resizeMode:this.config.crop?"crop-and-scale":"none"}};if(((r=this.config)==null?void 0:r.width)>0&&(n.video.width={ideal:this.config.width}),((s=this.config)==null?void 0:s.height)>0&&(n.video.height={ideal:this.config.height}),this.config.id&&(n.video.deviceId=this.config.id),this.element.addEventListener("play",()=>{this.config.debug&&u("webcam","play")}),this.element.addEventListener("pause",()=>{this.config.debug&&u("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)){this.config.debug&&u("webcam","no devices");return}try{this.stream=await navigator.mediaDevices.getUserMedia(n)}catch(A){u("webcam",A);return}if(!this.stream){this.config.debug&&u("webcam","no stream");return}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&&u("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})});k(this,"pause",()=>{this.element&&this.element.pause()});k(this,"play",async()=>{this.element&&await this.element.play()});k(this,"stop",()=>{this.config.debug&&u("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}};var d2=Z(H());var Qt={};ze(Qt,{age:()=>yr,"anti-spoofing":()=>Vr,antispoof:()=>tr,blazeface:()=>nr,"blazeface-back":()=>fr,"blazeface-front":()=>mr,"blazepose-detector":()=>pr,"blazepose-full":()=>ur,"blazepose-heavy":()=>hr,"blazepose-lite":()=>br,centernet:()=>or,default:()=>ns,efficientpose:()=>gr,"efficientpose-i-lite":()=>Zr,"efficientpose-ii-lite":()=>Xr,"efficientpose-iv":()=>qr,emotion:()=>rr,faceboxes:()=>Tr,facemesh:()=>sr,"facemesh-attention":()=>Rr,"facemesh-attention-pinto":()=>vr,"facemesh-detection-full":()=>Mr,"facemesh-detection-short":()=>Pr,faceres:()=>Ar,"faceres-deep":()=>kr,gear:()=>wr,gender:()=>zr,"gender-ssrnet-imdb":()=>Er,handdetect:()=>Sr,"handlandmark-full":()=>jr,"handlandmark-lite":()=>ar,"handlandmark-sparse":()=>Nr,handskeleton:()=>Ir,handtrack:()=>ir,"insightface-efficientnet-b0":()=>Ur,"insightface-ghostnet-strides1":()=>Yr,"insightface-ghostnet-strides2":()=>Kr,"insightface-mobilenet-emore":()=>Jr,"insightface-mobilenet-swish":()=>Qr,iris:()=>lr,liveness:()=>cr,meet:()=>Or,mobileface:()=>Lr,mobilefacenet:()=>Cr,models:()=>dr,"movenet-lightning":()=>xr,"movenet-multipose":()=>Wr,"movenet-thunder":()=>Dr,nanodet:()=>Fr,"nanodet-e":()=>_r,"nanodet-g":()=>$r,"nanodet-m":()=>es,"nanodet-t":()=>ts,posenet:()=>Br,rvm:()=>Hr,selfie:()=>Gr});var tr=853098,nr=538928,or=4030290,rr=820516,sr=1477958,Ar=6978814,ar=2023432,ir=2964837,lr=2599092,cr=592976,dr=0,xr=4650216,yr=161240,fr=538928,mr=402048,pr=5928856,ur=6339202,hr=27502466,br=2726402,gr=5651240,Tr=2013002,vr=2387598,Rr=2382414,Mr=1026192,Pr=201268,kr=13957620,wr=1498916,Er=161236,zr=201808,Sr=3515612,jr=5431368,Nr=5286322,Ir=5502280,Or=372228,Lr=2183192,Cr=5171976,Wr=9448838,Dr=12477112,Fr=7574558,Br=5032780,Hr=3739355,Gr=212886,Vr=853098,Zr=2269064,Xr=5651240,qr=25643252,Ur=13013224,Yr=8093408,Kr=8049584,Jr=6938536,Qr=12168584,_r=12319156,$r=7574558,es=1887474,ts=5294216,ns={antispoof:tr,blazeface:nr,centernet:or,emotion:rr,facemesh:sr,faceres:Ar,"handlandmark-lite":ar,handtrack:ir,iris:lr,liveness:cr,models:dr,"movenet-lightning":xr,age:yr,"blazeface-back":fr,"blazeface-front":mr,"blazepose-detector":pr,"blazepose-full":ur,"blazepose-heavy":hr,"blazepose-lite":br,efficientpose:gr,faceboxes:Tr,"facemesh-attention-pinto":vr,"facemesh-attention":Rr,"facemesh-detection-full":Mr,"facemesh-detection-short":Pr,"faceres-deep":kr,gear:wr,"gender-ssrnet-imdb":Er,gender:zr,handdetect:Sr,"handlandmark-full":jr,"handlandmark-sparse":Nr,handskeleton:Ir,meet:Or,mobileface:Lr,mobilefacenet:Cr,"movenet-multipose":Wr,"movenet-thunder":Dr,nanodet:Fr,posenet:Br,rvm:Hr,selfie:Gr,"anti-spoofing":Vr,"efficientpose-i-lite":Zr,"efficientpose-ii-lite":Xr,"efficientpose-iv":qr,"insightface-efficientnet-b0":Ur,"insightface-ghostnet-strides1":Yr,"insightface-ghostnet-strides2":Kr,"insightface-mobilenet-emore":Jr,"insightface-mobilenet-swish":Qr,"nanodet-e":_r,"nanodet-g":$r,"nanodet-m":es,"nanodet-t":ts};var O0={cacheModels:!0,cacheSupported:!0,verbose:!0,debug:!1,modelBasePath:""},E0={};async function os(e,t){return O0.debug&&u("load model fetch:",e,t),fetch(e,t)}function F1(e){O0.cacheModels=e.cacheModels,O0.verbose=e.debug,O0.modelBasePath=e.modelBasePath}async function O(e){var c,x,i,y;let t=z1(O0.modelBasePath,e||"");t.toLowerCase().endsWith(".json")||(t+=".json");let n=t.includes("/")?t.split("/"):t.split("\\"),o=n[n.length-1].replace(".json",""),r="indexeddb://"+o;E0[o]={name:o,sizeFromManifest:0,sizeLoadedWeights:0,sizeDesired:Qt[o],inCache:!1,url:""},O0.cacheSupported=typeof indexedDB!="undefined";let s={};try{s=O0.cacheSupported&&O0.cacheModels?await d2.io.listModels():{}}catch(d){O0.cacheSupported=!1}E0[o].inCache=O0.cacheSupported&&O0.cacheModels&&Object.keys(s).includes(r),E0[o].url=E0[o].inCache?r:t;let A=typeof fetch=="undefined"?{}:{fetchFunc:(d,p)=>os(d,p)},a=new d2.GraphModel(E0[o].url,A),l=!1;try{a.findIOHandler(),O0.debug&&u("model load handler:",a.handler)}catch(d){u("error finding model i/o handler:",t,d)}try{let d=await((c=a.handler)==null?void 0:c.load())||null;E0[o].sizeFromManifest=((x=d==null?void 0:d.weightData)==null?void 0:x.byteLength)||0,d?a.loadSync(d):a=await d2.loadGraphModel(E0[o].inCache?r:t,A),E0[o].sizeLoadedWeights=((y=(i=a.artifacts)==null?void 0:i.weightData)==null?void 0:y.byteLength)||0,O0.verbose&&u("load:",{model:o,url:a.modelUrl,bytes:E0[o].sizeLoadedWeights}),l=!0}catch(d){u("error loading model:",t,d)}if(l&&O0.cacheModels&&O0.cacheSupported&&!E0[o].inCache)try{let d=await a.save(r);O0.debug&&u("model saved:",r,d)}catch(d){u("error saving model:",t,d)}return a}var _t="3.0.2";var E=Z(H());var p0=Z(H());var o0={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 As(){let e=o0.gl;!e||(o0.extensions=e.getSupportedExtensions())}function B1(e){var t;if(e.config.backend==="humangl"&&(o0.name in p0.engine().registry&&!((t=o0==null?void 0:o0.gl)!=null&&t.getParameter(o0.gl.VERSION))&&(u("humangl error: backend invalid context"),e.models.reset()),!p0.findBackend(o0.name))){try{o0.canvas=te(100,100)}catch(r){u("humangl error: cannot create canvas:",r);return}try{if(o0.gl=o0.canvas.getContext("webgl2",o0.webGLattr),!o0.gl){u("humangl error: cannot get webgl context");return}if(!o0.gl.getParameter(o0.gl.VERSION).includes("2.0")){u("backend override: using fallback webgl backend as webgl 2.0 is not detected"),e.config.backend="webgl";return}o0.canvas&&(o0.canvas.addEventListener("webglcontextlost",s=>{throw u("humangl error:",s.type),u("possible browser memory leak using webgl or conflict with multiple backend registrations"),e.emit("error"),new Error("backend error: webgl context lost")}),o0.canvas.addEventListener("webglcontextrestored",s=>{u("humangl error: context restored:",s)}),o0.canvas.addEventListener("webglcontextcreationerror",s=>{u("humangl error: context create:",s)}))}catch(r){u("humangl error: cannot get webgl context:",r);return}try{p0.setWebGLContext(2,o0.gl)}catch(r){u("humangl error: cannot set webgl context:",r);return}try{let r=new p0.GPGPUContext(o0.gl);p0.registerBackend(o0.name,()=>new p0.MathBackendWebGL(r),o0.priority)}catch(r){u("humangl error: cannot register webgl backend:",r);return}try{p0.getKernelsForBackend("webgl").forEach(s=>{let A={...s,backendName:o0.name};p0.registerKernel(A)})}catch(r){u("humangl error: cannot update webgl backend registration:",r);return}try{p0.env().flagRegistry.WEBGL_VERSION&&p0.env().set("WEBGL_VERSION",2)}catch(r){u("humangl error: cannot set WebGL backend flags:",r);return}As();let n=p0.backend(),o=typeof n.gpgpu!="undefined"?n.getGPGPUContext().gl:null;o?e.config.debug&&u("humangl backend registered:",{webgl:o.getParameter(o.VERSION),renderer:o.getParameter(o.RENDERER)}):u("humangl error: no current gl context:",o,o0.gl)}}var Se=Z(H()),C={tf255:255,tf1:1,tf2:2,tf05:.5,tf127:127.5,rgb:[.2989,.587,.114]};function H1(){C.tf255=Se.scalar(255,"float32"),C.tf1=Se.scalar(1,"float32"),C.tf2=Se.scalar(2,"float32"),C.tf05=Se.scalar(.5,"float32"),C.tf127=Se.scalar(127.5,"float32"),C.rgb=Se.tensor1d([.2989,.587,.114],"float32")}async function ls(){var e;return await R.updateBackend(),(e=R.tensorflow)!=null&&e.version?"tensorflow":R.webgpu.supported&&R.webgpu.backend?"webgpu":R.webgl.supported&&R.webgl.backend?"webgl":R.wasm.supported&&R.wasm.backend?"wasm":"cpu"}function cs(e){let t=[];if(!R.kernels.includes("mod")){let n={kernelName:"Mod",backendName:E.getBackend(),kernelFunc:o=>E.tidy(()=>E.sub(o.inputs.a,E.mul(E.div(o.inputs.a,o.inputs.b),o.inputs.b)))};E.registerKernel(n),R.kernels.push("mod"),t.push("mod")}if(!R.kernels.includes("floormod")){let n={kernelName:"FloorMod",backendName:E.getBackend(),kernelFunc:o=>E.tidy(()=>E.add(E.mul(E.floorDiv(o.inputs.a,o.inputs.b),o.inputs.b),E.mod(o.inputs.a,o.inputs.b)))};E.registerKernel(n),R.kernels.push("floormod"),t.push("floormod")}if(!R.kernels.includes("rotatewithoffset")&&e.softwareKernels){let n={kernelName:"RotateWithOffset",backendName:E.getBackend(),kernelFunc:o=>E.tidy(()=>{let r=E.getBackend();E.setBackend("cpu");let s=E.image.rotateWithOffset(o.inputs.image,o.attrs.radians,o.attrs.fillValue,o.attrs.center);return E.setBackend(r),s})};E.registerKernel(n),R.kernels.push("rotatewithoffset"),t.push("rotatewithoffset")}t.length>0&&e.debug&&u("registered kernels:",t)}var G1={};async function j2(e,t=!1){var n;if(e.state="backend",((n=e.config.backend)==null?void 0:n.length)===0&&(e.config.backend=await ls()),t||R.initial||e.config.backend&&e.config.backend.length>0&&E.getBackend()!==e.config.backend){let o=g();if(e.config.backend&&e.config.backend.length>0){if(typeof window=="undefined"&&typeof WorkerGlobalScope!="undefined"&&e.config.debug&&e.config.debug&&u("running inside web worker"),R.browser&&e.config.backend==="tensorflow"&&(e.config.debug&&u("override: backend set to tensorflow while running in browser"),e.config.backend="webgl"),R.node&&(e.config.backend==="webgl"||e.config.backend==="humangl")&&(e.config.debug&&u(`override: backend set to ${e.config.backend} while running in nodejs`),e.config.backend="tensorflow"),R.browser&&e.config.backend==="webgpu")if(typeof navigator=="undefined"||typeof navigator.gpu=="undefined")u("override: backend set to webgpu but browser does not support webgpu"),e.config.backend="webgl";else{let s=await navigator.gpu.requestAdapter();if(e.config.debug&&u("enumerated webgpu adapter:",s),!s)u("override: backend set to webgpu but browser reports no available gpu"),e.config.backend="webgl";else{let A="requestAdapterInfo"in s?await s.requestAdapterInfo():void 0;u("webgpu adapter info:",A)}}let r=Object.keys(E.engine().registryFactory);if(e.config.backend==="humangl"&&!r.includes("humangl")&&(B1(e),r=Object.keys(E.engine().registryFactory)),e.config.debug&&u("available backends:",r),r.includes(e.config.backend)||(u(`error: backend ${e.config.backend} not found in registry`),e.config.backend=R.node?"tensorflow":"webgl",e.config.debug&&u(`override: setting backend ${e.config.backend}`)),e.config.debug&&u("setting backend:",[e.config.backend]),e.config.backend==="wasm"){if(E.env().flagRegistry.CANVAS2D_WILL_READ_FREQUENTLY&&E.env().set("CANVAS2D_WILL_READ_FREQUENTLY",!0),e.config.debug&&u("wasm path:",e.config.wasmPath),typeof E.setWasmPaths!="undefined")E.setWasmPaths(e.config.wasmPath,e.config.wasmPlatformFetch);else throw new Error("backend error: attempting to use wasm backend but wasm path is not set");let s=!1,A=!1;try{s=await E.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"),A=await E.env().getAsync("WASM_HAS_SIMD_SUPPORT"),e.config.debug&&u(`wasm execution: ${A?"simd":"no simd"} ${s?"multithreaded":"singlethreaded"}`),e.config.debug&&!A&&u("warning: wasm simd support is not enabled")}catch(a){u("wasm detection failed")}}try{await E.setBackend(e.config.backend),await E.ready()}catch(s){return u("error: cannot set backend:",e.config.backend,s),!1}e.config.debug&&(G1=JSON.parse(JSON.stringify(E.env().flags)))}if((E.getBackend()==="humangl"||E.getBackend()==="webgl")&&(E.env().flagRegistry.WEBGL_USE_SHAPES_UNIFORMS&&E.env().set("WEBGL_USE_SHAPES_UNIFORMS",!0),E.env().flagRegistry.WEBGL_EXP_CONV&&E.env().set("WEBGL_EXP_CONV",!0),e.config.debug&&typeof e.config.deallocate!="undefined"&&e.config.deallocate&&(u("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",!0),E.env().set("WEBGL_DELETE_TEXTURE_THRESHOLD",0))),E.getBackend(),e.config.debug){let r=E.env().flags,s={};for(let A of Object.keys(r))G1[A]!==r[A]&&(s[A]=r[A]);e.config.debug&&Object.keys(s).length>0&&u("backend:",E.getBackend(),"flags:",s)}if(e.config.flags&&Object.keys(e.config.flags).length>0){e.config.debug&&u("flags:",e.config.flags);for(let[r,s]of Object.entries(e.config.flags))E.env().set(r,s)}E.enableProdMode(),H1(),e.performance.initBackend=Math.trunc(g()-o),e.config.backend=E.getBackend(),await R.updateBackend(),cs(e.config),R.initial=!1}return!0}function Y2(e,t){for(let n of e){let o={kernelName:n,backendName:t.backend,kernelFunc:r=>{var s;return t.debug&&u("kernelFunc",n,t.backend,r),(s=r==null?void 0:r.inputs)==null?void 0:s.info}};E.registerKernel(o)}R.kernels=E.getKernelsForBackend(E.getBackend()).map(n=>n.kernelName.toLowerCase())}var et={};ze(et,{all:()=>Hs,body:()=>J2,canvas:()=>Bs,face:()=>K2,gesture:()=>$2,hand:()=>Q2,init:()=>s5,object:()=>_2,options:()=>x0,person:()=>Fs});var Q0=e=>{if(!e)u("draw error: invalid canvas");else if(!e.getContext)u("draw error: canvas context not defined");else{let t=e.getContext("2d");if(!t)u("draw error: cannot get canvas context");else return t}return null},Ke=e=>Math.round(e*180/Math.PI),_=(e,t,n)=>e.replace(t,typeof n=="number"?n.toFixed(1):n),Je=(e,t)=>{if(!t.useDepth||typeof e=="undefined")return t.color;let n=Uint8ClampedArray.from([127+2*e,127-2*e,255]);return`rgba(${n[0]}, ${n[1]}, ${n[2]}, ${t.alpha})`};function ne(e,t,n,o,r){let s=t.replace(/\[.*\]/g,"").split(` +`).map(a=>a.trim()),A=Math.max(0,n);for(let a=s.length-1;a>=0;a--){let l=a*r.lineHeight+o;r.shadowColor&&r.shadowColor!==""&&(e.fillStyle=r.shadowColor,e.fillText(s[a],A+5,l+16)),e.fillStyle=r.labelColor,e.fillText(s[a],A+4,l+15)}}function Te(e,t,n,o,r){e.fillStyle=Je(o,r),e.beginPath(),e.arc(t,n,r.pointSize,0,2*Math.PI),e.fill()}function pe(e,t,n,o,r,s){if(e.beginPath(),e.lineWidth=s.lineWidth,s.useCurves){let A=(t+t+o)/2,a=(n+n+r)/2;e.ellipse(A,a,o/2,r/2,0,0,2*Math.PI)}else e.moveTo(t+s.roundRect,n),e.lineTo(t+o-s.roundRect,n),e.quadraticCurveTo(t+o,n,t+o,n+s.roundRect),e.lineTo(t+o,n+r-s.roundRect),e.quadraticCurveTo(t+o,n+r,t+o-s.roundRect,n+r),e.lineTo(t+s.roundRect,n+r),e.quadraticCurveTo(t,n+r,t,n+r-s.roundRect),e.lineTo(t,n+s.roundRect),e.quadraticCurveTo(t,n,t+s.roundRect,n),e.closePath();e.stroke()}function $t(e,t,n){if(!(t.length<2)){e.beginPath(),e.moveTo(t[0][0],t[0][1]);for(let o of t)e.strokeStyle=Je(o[2]||0,n),e.lineTo(Math.trunc(o[0]),Math.trunc(o[1]));e.stroke(),n.fillPolygons&&(e.closePath(),e.fill())}}function Z1(e,t,n){if(!(t.length<2)){if(e.lineWidth=n.lineWidth,!n.useCurves||t.length<=2){$t(e,t,n);return}e.moveTo(t[0][0],t[0][1]);for(let o=0;oN2[e]),La=xs.map(e=>N2[e]),Ca=ys.map(e=>N2[e]);function je(e){let t=e.map(n=>n[0]);return t.push(e[e.length-1][1]),t}var fs=[[61,146],[146,91],[91,181],[181,84],[84,17],[17,314],[314,405],[405,321],[321,375],[375,291],[61,185],[185,40],[40,39],[39,37],[37,0],[0,267],[267,269],[269,270],[270,409],[409,291],[78,95],[95,88],[88,178],[178,87],[87,14],[14,317],[317,402],[402,318],[318,324],[324,308],[78,191],[191,80],[80,81],[81,82],[82,13],[13,312],[312,311],[311,310],[310,415],[415,308]],ms=[[263,249],[249,390],[390,373],[373,374],[374,380],[380,381],[381,382],[382,362],[263,466],[466,388],[388,387],[387,386],[386,385],[385,384],[384,398],[398,362]],ps=[[276,283],[283,282],[282,295],[295,285],[300,293],[293,334],[334,296],[296,336]],us=[[474,475],[475,476],[476,477],[477,474]],hs=[[33,7],[7,163],[163,144],[144,145],[145,153],[153,154],[154,155],[155,133],[33,246],[246,161],[161,160],[160,159],[159,158],[158,157],[157,173],[173,133]],bs=[[46,53],[53,52],[52,65],[65,55],[70,63],[63,105],[105,66],[66,107]],gs=[[469,470],[470,471],[471,472],[472,469]],Ts=[[10,338],[338,297],[297,332],[332,284],[284,251],[251,389],[389,356],[356,454],[454,323],[323,361],[361,288],[288,397],[397,365],[365,379],[379,378],[378,400],[400,377],[377,152],[152,148],[148,176],[176,149],[149,150],[150,136],[136,172],[172,58],[58,132],[132,93],[93,234],[234,127],[127,162],[162,21],[21,54],[54,103],[103,67],[67,109],[109,10]],Wa={lips:je(fs),leftEye:je(ms),leftEyebrow:je(ps),leftIris:je(us),rightEye:je(hs),rightEyebrow:je(bs),rightIris:je(gs),faceOval:je(Ts)};var vs=[[61,146],[146,91],[91,181],[181,84],[84,17],[17,314],[314,405],[405,321],[321,375],[375,291],[61,185],[185,40],[40,39],[39,37],[37,0],[0,267],[267,269],[269,270],[270,409],[409,291],[78,95],[95,88],[88,178],[178,87],[87,14],[14,317],[317,402],[402,318],[318,324],[324,308],[78,191],[191,80],[80,81],[81,82],[82,13],[13,312],[312,311],[311,310],[310,415],[415,308]],Rs=[[263,249],[249,390],[390,373],[373,374],[374,380],[380,381],[381,382],[382,362],[263,466],[466,388],[388,387],[387,386],[386,385],[385,384],[384,398],[398,362]],Ms=[[276,283],[283,282],[282,295],[295,285],[300,293],[293,334],[334,296],[296,336]],Ps=[[474,475],[475,476],[476,477],[477,474]],ks=[[33,7],[7,163],[163,144],[144,145],[145,153],[153,154],[154,155],[155,133],[33,246],[246,161],[161,160],[160,159],[159,158],[158,157],[157,173],[173,133]],ws=[[46,53],[53,52],[52,65],[65,55],[70,63],[63,105],[105,66],[66,107]],Es=[[469,470],[470,471],[471,472],[472,469]],zs=[[10,338],[338,297],[297,332],[332,284],[284,251],[251,389],[389,356],[356,454],[454,323],[323,361],[361,288],[288,397],[397,365],[365,379],[379,378],[378,400],[400,377],[377,152],[152,148],[148,176],[176,149],[149,150],[150,136],[136,172],[172,58],[58,132],[132,93],[93,234],[234,127],[127,162],[162,21],[21,54],[54,103],[103,67],[67,109],[109,10]];function Ne(e){let t=e.map(n=>n[0]);return t.push(e[e.length-1][1]),t}var Ss={lips:Ne(vs),leftEye:Ne(Rs),leftEyebrow:Ne(Ms),leftIris:Ne(Ps),rightEye:Ne(ks),rightEyebrow:Ne(ws),rightIris:Ne(Es),faceOval:Ne(zs)},js=Object.entries(Ss).map(([e,t])=>t.map(n=>[n,e])).flat(),Da=new Map(js),I2=[61,146,91,181,84,17,314,405,321,375,291,185,40,39,37,0,267,269,270,409,78,95,88,178,87,14,317,402,318,324,308,191,80,81,82,13,312,311,310,415,76,77,90,180,85,16,315,404,320,307,306,184,74,73,72,11,302,303,304,408,62,96,89,179,86,15,316,403,319,325,292,183,42,41,38,12,268,271,272,407],$e=[33,7,163,144,145,153,154,155,133,246,161,160,159,158,157,173,130,25,110,24,23,22,26,112,243,247,30,29,27,28,56,190,226,31,228,229,230,231,232,233,244,113,225,224,223,222,221,189,35,124,46,53,52,65,143,111,117,118,119,120,121,128,245,156,70,63,105,66,107,55,193],e2=[263,249,390,373,374,380,381,382,362,466,388,387,386,385,384,398,359,255,339,254,253,252,256,341,463,467,260,259,257,258,286,414,446,261,448,449,450,451,452,453,464,342,445,444,443,442,441,413,265,353,276,283,282,295,372,340,346,347,348,349,350,357,465,383,300,293,334,296,336,285,417];var K;function Ns(e,t){var o,r,s,A,a,l,c,x,i;if(!K.drawLabels||((o=K.faceLabels)==null?void 0:o.length)===0)return;let n=K.faceLabels.slice();if(e.score&&(n=_(n,"[score]",100*e.score)),e.gender&&(n=_(n,"[gender]",e.gender)),e.genderScore&&(n=_(n,"[genderScore]",100*e.genderScore)),e.age&&(n=_(n,"[age]",e.age)),e.distance&&(n=_(n,"[distance]",100*e.distance)),e.real&&(n=_(n,"[real]",100*e.real)),e.live&&(n=_(n,"[live]",100*e.live)),e.emotion&&e.emotion.length>0){let y=e.emotion.map(d=>`${Math.trunc(100*d.score)}% ${d.emotion}`);y.length>3&&(y.length=3),n=_(n,"[emotions]",y.join(" "))}(s=(r=e.rotation)==null?void 0:r.angle)!=null&&s.roll&&(n=_(n,"[roll]",Ke(e.rotation.angle.roll))),(a=(A=e.rotation)==null?void 0:A.angle)!=null&&a.yaw&&(n=_(n,"[yaw]",Ke(e.rotation.angle.yaw))),(c=(l=e.rotation)==null?void 0:l.angle)!=null&&c.pitch&&(n=_(n,"[pitch]",Ke(e.rotation.angle.pitch))),(i=(x=e.rotation)==null?void 0:x.gaze)!=null&&i.bearing&&(n=_(n,"[gaze]",Ke(e.rotation.gaze.bearing))),ne(t,n,e.box[0],e.box[1],K)}function Is(e,t){var n,o,r,s;if(((n=e.annotations)==null?void 0:n.leftEyeIris)&&((o=e.annotations)==null?void 0:o.leftEyeIris[0])){t.strokeStyle=K.useDepth?"rgba(255, 200, 255, 0.3)":K.color,t.beginPath();let A=Math.abs(e.annotations.leftEyeIris[3][0]-e.annotations.leftEyeIris[1][0])/2,a=Math.abs(e.annotations.leftEyeIris[4][1]-e.annotations.leftEyeIris[2][1])/2;t.ellipse(e.annotations.leftEyeIris[0][0],e.annotations.leftEyeIris[0][1],A,a,0,0,2*Math.PI),t.stroke(),K.fillPolygons&&(t.fillStyle=K.useDepth?"rgba(255, 255, 200, 0.3)":K.color,t.fill())}if(((r=e.annotations)==null?void 0:r.rightEyeIris)&&((s=e.annotations)==null?void 0:s.rightEyeIris[0])){t.strokeStyle=K.useDepth?"rgba(255, 200, 255, 0.3)":K.color,t.beginPath();let A=Math.abs(e.annotations.rightEyeIris[3][0]-e.annotations.rightEyeIris[1][0])/2,a=Math.abs(e.annotations.rightEyeIris[4][1]-e.annotations.rightEyeIris[2][1])/2;t.ellipse(e.annotations.rightEyeIris[0][0],e.annotations.rightEyeIris[0][1],A,a,0,0,2*Math.PI),t.stroke(),K.fillPolygons&&(t.fillStyle=K.useDepth?"rgba(255, 255, 200, 0.3)":K.color,t.fill())}}function Os(e,t){var n;if(K.drawGaze&&((n=e.rotation)==null?void 0:n.angle)&&typeof Path2D!="undefined"){t.strokeStyle="pink";let o=e.box[0]+e.box[2]/2-e.box[3]*Ke(e.rotation.angle.yaw)/90,r=e.box[1]+e.box[3]/2+e.box[2]*Ke(e.rotation.angle.pitch)/90,s=new Path2D(` + M ${e.box[0]+e.box[2]/2} ${e.box[1]} C - ${valX} ${f.box[1]}, - ${valX} ${f.box[1] + f.box[3]}, - ${f.box[0] + f.box[2] / 2} ${f.box[1] + f.box[3]} - `); - const pathH = new Path2D(` - M ${f.box[0]} ${f.box[1] + f.box[3] / 2} + ${o} ${e.box[1]}, + ${o} ${e.box[1]+e.box[3]}, + ${e.box[0]+e.box[2]/2} ${e.box[1]+e.box[3]} + `),A=new Path2D(` + M ${e.box[0]} ${e.box[1]+e.box[3]/2} C - ${f.box[0]} ${valY}, - ${f.box[0] + f.box[2]} ${valY}, - ${f.box[0] + f.box[2]} ${f.box[1] + f.box[3] / 2} - `); - ctx.stroke(pathH); - ctx.stroke(pathV); - } -} -function drawGazeArrows(f, ctx) { - var _a; - if (localOptions.drawGaze && ((_a = f.rotation) == null ? void 0 : _a.gaze.strength) && f.rotation.gaze.bearing && f.annotations.leftEyeIris && f.annotations.rightEyeIris && f.annotations.leftEyeIris[0] && f.annotations.rightEyeIris[0]) { - ctx.strokeStyle = "pink"; - ctx.fillStyle = "pink"; - const leftGaze = [ - f.annotations.leftEyeIris[0][0] + Math.sin(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[3], - f.annotations.leftEyeIris[0][1] + Math.cos(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[2] - ]; - arrow(ctx, [f.annotations.leftEyeIris[0][0], f.annotations.leftEyeIris[0][1]], [leftGaze[0], leftGaze[1]], 4); - const rightGaze = [ - f.annotations.rightEyeIris[0][0] + Math.sin(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[3], - f.annotations.rightEyeIris[0][1] + Math.cos(f.rotation.gaze.bearing) * f.rotation.gaze.strength * f.box[2] - ]; - arrow(ctx, [f.annotations.rightEyeIris[0][0], f.annotations.rightEyeIris[0][1]], [rightGaze[0], rightGaze[1]], 4); - } -} -function drawFacePolygons(f, ctx) { - if (localOptions.drawPolygons && f.mesh.length >= 468) { - ctx.lineWidth = 1; - for (let i = 0; i < TRI468.length / 3; i++) { - const points = [TRI468[i * 3 + 0], TRI468[i * 3 + 1], TRI468[i * 3 + 2]].map((index2) => f.mesh[index2]); - lines(ctx, points, localOptions); - } - drawIrisElipse(f, ctx); - } -} -function drawFacePoints(f, ctx) { - if (localOptions.drawPoints && f.mesh.length >= 468) { - for (let i = 0; i < f.mesh.length; i++) { - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2], localOptions); - if (localOptions.drawAttention) { - if (LANDMARKS_REFINEMENT_LIPS_CONFIG.includes(i)) - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2] + 127, localOptions); - if (LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG.includes(i)) - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2] - 127, localOptions); - if (LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG.includes(i)) - point(ctx, f.mesh[i][0], f.mesh[i][1], f.mesh[i][2] - 127, localOptions); - } - } - } -} -function drawFaceBoxes(f, ctx) { - if (localOptions.drawBoxes) { - rect(ctx, f.box[0], f.box[1], f.box[2], f.box[3], localOptions); - } -} -function face(inCanvas2, result, drawOptions) { - localOptions = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.font = localOptions.font; - ctx.strokeStyle = localOptions.color; - ctx.fillStyle = localOptions.color; - for (const f of result) { - drawFaceBoxes(f, ctx); - drawLabels(f, ctx); - if (f.mesh && f.mesh.length > 0) { - drawFacePoints(f, ctx); - drawFacePolygons(f, ctx); - drawGazeSpheres(f, ctx); - drawGazeArrows(f, ctx); - } - } -} - -// src/draw/body.ts -function body(inCanvas2, result, drawOptions) { - var _a, _b; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - for (let i = 0; i < result.length; i++) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - ctx.lineWidth = localOptions2.lineWidth; - ctx.font = localOptions2.font; - if (localOptions2.drawBoxes && result[i].box && result[i].box.length === 4) { - rect(ctx, result[i].box[0], result[i].box[1], result[i].box[2], result[i].box[3], localOptions2); - if (localOptions2.drawLabels && ((_a = localOptions2.bodyLabels) == null ? void 0 : _a.length) > 0) { - let l = localOptions2.bodyLabels.slice(); - l = replace(l, "[score]", 100 * result[i].score); - labels(ctx, l, result[i].box[0], result[i].box[1], localOptions2); - } - } - if (localOptions2.drawPoints && result[i].keypoints) { - for (let pt = 0; pt < result[i].keypoints.length; pt++) { - if (!result[i].keypoints[pt].score || result[i].keypoints[pt].score === 0) - continue; - ctx.fillStyle = colorDepth(result[i].keypoints[pt].position[2], localOptions2); - point(ctx, result[i].keypoints[pt].position[0], result[i].keypoints[pt].position[1], 0, localOptions2); - } - } - if (localOptions2.drawLabels && ((_b = localOptions2.bodyPartLabels) == null ? void 0 : _b.length) > 0 && result[i].keypoints) { - ctx.font = localOptions2.font; - for (const pt of result[i].keypoints) { - if (!pt.score || pt.score === 0) - continue; - let l = localOptions2.bodyPartLabels.slice(); - l = replace(l, "[label]", pt.part); - l = replace(l, "[score]", 100 * pt.score); - labels(ctx, l, pt.position[0], pt.position[1], localOptions2); - } - } - if (localOptions2.drawPolygons && result[i].keypoints && result[i].annotations) { - for (const part of Object.values(result[i].annotations)) { - for (const connected4 of part) - curves(ctx, connected4, localOptions2); - } - } - } -} - -// src/draw/hand.ts -function hand(inCanvas2, result, drawOptions) { - var _a, _b; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - ctx.font = localOptions2.font; - for (const h of result) { - if (localOptions2.drawBoxes) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - rect(ctx, h.box[0], h.box[1], h.box[2], h.box[3], localOptions2); - if (localOptions2.drawLabels && ((_a = localOptions2.handLabels) == null ? void 0 : _a.length) > 0) { - let l = localOptions2.handLabels.slice(); - l = replace(l, "[label]", h.label); - l = replace(l, "[score]", 100 * h.score); - labels(ctx, l, h.box[0], h.box[1], localOptions2); - } - ctx.stroke(); - } - if (localOptions2.drawPoints) { - if (h.keypoints && h.keypoints.length > 0) { - for (const pt of h.keypoints) { - ctx.fillStyle = colorDepth(pt[2], localOptions2); - point(ctx, pt[0], pt[1], 0, localOptions2); - } - } - } - if (localOptions2.drawLabels && h.annotations && ((_b = localOptions2.fingerLabels) == null ? void 0 : _b.length) > 0) { - for (const [part, pt] of Object.entries(h.annotations)) { - let l = localOptions2.fingerLabels.slice(); - l = replace(l, "[label]", part); - labels(ctx, l, pt[pt.length - 1][0], pt[pt.length - 1][1], localOptions2); - } - } - if (localOptions2.drawPolygons && h.annotations) { - const addHandLine = (part) => { - if (!part || part.length === 0 || !part[0]) - return; - for (let i = 0; i < part.length; i++) { - ctx.beginPath(); - const z = part[i][2] || 0; - ctx.strokeStyle = colorDepth(i * z, localOptions2); - ctx.moveTo(part[i > 0 ? i - 1 : 0][0], part[i > 0 ? i - 1 : 0][1]); - ctx.lineTo(part[i][0], part[i][1]); - ctx.stroke(); - } - }; - ctx.lineWidth = localOptions2.lineWidth; - addHandLine(h.annotations.index); - addHandLine(h.annotations.middle); - addHandLine(h.annotations.ring); - addHandLine(h.annotations.pinky); - addHandLine(h.annotations.thumb); - } - } -} - -// src/draw/object.ts -function object(inCanvas2, result, drawOptions) { - var _a; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - ctx.font = localOptions2.font; - for (const h of result) { - if (localOptions2.drawBoxes) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - rect(ctx, h.box[0], h.box[1], h.box[2], h.box[3], localOptions2); - if (localOptions2.drawLabels && ((_a = localOptions2.objectLabels) == null ? void 0 : _a.length) > 0) { - let l = localOptions2.objectLabels.slice(); - l = replace(l, "[label]", h.label); - l = replace(l, "[score]", 100 * h.score); - labels(ctx, l, h.box[0], h.box[1], localOptions2); - } - ctx.stroke(); - } - } -} - -// src/draw/gesture.ts -function gesture(inCanvas2, result, drawOptions) { - var _a; - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - if (localOptions2.drawGestures && ((_a = localOptions2.gestureLabels) == null ? void 0 : _a.length) > 0) { - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.font = localOptions2.font; - ctx.fillStyle = localOptions2.color; - let i = 1; - for (let j = 0; j < result.length; j++) { - const [where, what] = Object.entries(result[j]); - if (what.length > 1 && what[1].length > 0) { - const who = where[1] > 0 ? `#${where[1]}` : ""; - let l = localOptions2.gestureLabels.slice(); - l = replace(l, "[where]", where[0]); - l = replace(l, "[who]", who); - l = replace(l, "[what]", what[1]); - labels(ctx, l, 8, 2 + i * localOptions2.lineHeight, localOptions2); - i += 1; - } - } - } -} - -// src/draw/labels.ts -var defaultLabels = { - face: `face + ${e.box[0]} ${r}, + ${e.box[0]+e.box[2]} ${r}, + ${e.box[0]+e.box[2]} ${e.box[1]+e.box[3]/2} + `);t.stroke(A),t.stroke(s)}}function Ls(e,t){var n;if(K.drawGaze&&((n=e.rotation)==null?void 0:n.gaze.strength)&&e.rotation.gaze.bearing&&e.annotations.leftEyeIris&&e.annotations.rightEyeIris&&e.annotations.leftEyeIris[0]&&e.annotations.rightEyeIris[0]){t.strokeStyle="pink",t.fillStyle="pink";let o=[e.annotations.leftEyeIris[0][0]+Math.sin(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[3],e.annotations.leftEyeIris[0][1]+Math.cos(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[2]];e5(t,[e.annotations.leftEyeIris[0][0],e.annotations.leftEyeIris[0][1]],[o[0],o[1]],4);let r=[e.annotations.rightEyeIris[0][0]+Math.sin(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[3],e.annotations.rightEyeIris[0][1]+Math.cos(e.rotation.gaze.bearing)*e.rotation.gaze.strength*e.box[2]];e5(t,[e.annotations.rightEyeIris[0][0],e.annotations.rightEyeIris[0][1]],[r[0],r[1]],4)}}function Cs(e,t){if(K.drawPolygons&&e.mesh.length>=468){t.lineWidth=1;for(let n=0;n<_e.length/3;n++){let o=[_e[n*3+0],_e[n*3+1],_e[n*3+2]].map(r=>e.mesh[r]);$t(t,o,K)}Is(e,t)}}function Ws(e,t){if(K.drawPoints&&e.mesh.length>=468)for(let n=0;n0&&(Ws(r,o),Cs(r,o),Os(r,o),Ls(r,o))}}function J2(e,t,n){var s,A;let o=a0(x0,n);if(!t||!e)return;let r=Q0(e);if(!!r){r.lineJoin="round";for(let a=0;a0)){let l=o.bodyLabels.slice();l=_(l,"[score]",100*t[a].score),ne(r,l,t[a].box[0],t[a].box[1],o)}if(o.drawPoints&&t[a].keypoints)for(let l=0;l0&&t[a].keypoints){r.font=o.font;for(let l of t[a].keypoints){if(!l.score||l.score===0)continue;let c=o.bodyPartLabels.slice();c=_(c,"[label]",l.part),c=_(c,"[score]",100*l.score),ne(r,c,l.position[0],l.position[1],o)}}if(o.drawPolygons&&t[a].keypoints&&t[a].annotations)for(let l of Object.values(t[a].annotations))for(let c of l)Z1(r,c,o)}}}function Q2(e,t,n){var s,A;let o=a0(x0,n);if(!t||!e)return;let r=Q0(e);if(!!r){r.lineJoin="round",r.font=o.font;for(let a of t){if(o.drawBoxes){if(r.strokeStyle=o.color,r.fillStyle=o.color,pe(r,a.box[0],a.box[1],a.box[2],a.box[3],o),o.drawLabels&&((s=o.handLabels)==null?void 0:s.length)>0){let l=o.handLabels.slice();l=_(l,"[label]",a.label),l=_(l,"[score]",100*a.score),ne(r,l,a.box[0],a.box[1],o)}r.stroke()}if(o.drawPoints&&a.keypoints&&a.keypoints.length>0)for(let l of a.keypoints)r.fillStyle=Je(l[2],o),Te(r,l[0],l[1],0,o);if(o.drawLabels&&a.annotations&&((A=o.fingerLabels)==null?void 0:A.length)>0)for(let[l,c]of Object.entries(a.annotations)){let x=o.fingerLabels.slice();x=_(x,"[label]",l),ne(r,x,c[c.length-1][0],c[c.length-1][1],o)}if(o.drawPolygons&&a.annotations){let l=c=>{if(!(!c||c.length===0||!c[0]))for(let x=0;x0?x-1:0][0],c[x>0?x-1:0][1]),r.lineTo(c[x][0],c[x][1]),r.stroke()}};r.lineWidth=o.lineWidth,l(a.annotations.index),l(a.annotations.middle),l(a.annotations.ring),l(a.annotations.pinky),l(a.annotations.thumb)}}}}function _2(e,t,n){var s;let o=a0(x0,n);if(!t||!e)return;let r=Q0(e);if(!!r){r.lineJoin="round",r.font=o.font;for(let A of t)if(o.drawBoxes){if(r.strokeStyle=o.color,r.fillStyle=o.color,pe(r,A.box[0],A.box[1],A.box[2],A.box[3],o),o.drawLabels&&((s=o.objectLabels)==null?void 0:s.length)>0){let a=o.objectLabels.slice();a=_(a,"[label]",A.label),a=_(a,"[score]",100*A.score),ne(r,a,A.box[0],A.box[1],o)}r.stroke()}}}function $2(e,t,n){var r;let o=a0(x0,n);if(!(!t||!e)&&o.drawGestures&&((r=o.gestureLabels)==null?void 0:r.length)>0){let s=Q0(e);if(!s)return;s.font=o.font,s.fillStyle=o.color;let A=1;for(let a=0;a1&&c[1].length>0){let x=l[1]>0?`#${l[1]}`:"",i=o.gestureLabels.slice();i=_(i,"[where]",l[0]),i=_(i,"[who]",x),i=_(i,"[what]",c[1]),ne(s,i,8,2+A*o.lineHeight,o),A+=1}}}}var Ie={face:`face confidence: [score]% [gender] [genderScore]% age: [age] years @@ -6467,7523 +118,7 @@ var defaultLabels = { live: [live]% [emotions] roll: [roll]\xB0 yaw:[yaw]\xB0 pitch:[pitch]\xB0 - gaze: [gaze]\xB0`, - body: "body [score]%", - bodyPart: "[label] [score]%", - object: "[label] [score]%", - hand: "[label] [score]%", - finger: "[label]", - gesture: "[where] [who]: [what]" -}; - -// src/draw/draw.ts -var drawTime = 0; -function person(inCanvas2, result, drawOptions) { - const localOptions2 = mergeDeep(options2, drawOptions); - if (!result || !inCanvas2) - return; - const ctx = getCanvasContext(inCanvas2); - if (!ctx) - return; - ctx.lineJoin = "round"; - ctx.font = localOptions2.font; - for (let i = 0; i < result.length; i++) { - if (localOptions2.drawBoxes) { - ctx.strokeStyle = localOptions2.color; - ctx.fillStyle = localOptions2.color; - rect(ctx, result[i].box[0], result[i].box[1], result[i].box[2], result[i].box[3], localOptions2); - if (localOptions2.drawLabels) { - const label = `person #${i}`; - if (localOptions2.shadowColor && localOptions2.shadowColor !== "") { - ctx.fillStyle = localOptions2.shadowColor; - ctx.fillText(label, result[i].box[0] + 3, 1 + result[i].box[1] + localOptions2.lineHeight, result[i].box[2]); - } - ctx.fillStyle = localOptions2.labelColor; - ctx.fillText(label, result[i].box[0] + 2, 0 + result[i].box[1] + localOptions2.lineHeight, result[i].box[2]); - } - ctx.stroke(); - } - } -} -function canvas2(input, output) { - if (!input || !output) - return; - const ctx = getCanvasContext(output); - if (!ctx) - return; - ctx.drawImage(input, 0, 0); -} -async function all(inCanvas2, result, drawOptions) { - if (!(result == null ? void 0 : result.performance) || !inCanvas2) - return null; - const timeStamp = now(); - const localOptions2 = mergeDeep(options2, drawOptions); - const promise = Promise.all([ - face(inCanvas2, result.face, localOptions2), - body(inCanvas2, result.body, localOptions2), - hand(inCanvas2, result.hand, localOptions2), - object(inCanvas2, result.object, localOptions2), - gesture(inCanvas2, result.gesture, localOptions2) - ]); - drawTime = env.perfadd ? drawTime + Math.round(now() - timeStamp) : Math.round(now() - timeStamp); - result.performance.draw = drawTime; - return promise; -} -function init2() { - options2.faceLabels = defaultLabels.face; - options2.bodyLabels = defaultLabels.body; - options2.bodyPartLabels = defaultLabels.bodyPart; - options2.handLabels = defaultLabels.hand; - options2.fingerLabels = defaultLabels.finger; - options2.objectLabels = defaultLabels.object; - options2.gestureLabels = defaultLabels.gesture; -} - -// src/body/blazepose.ts -var tf9 = __toESM(require_tfjs_esm()); - -// src/body/blazeposecoords.ts -var blazeposecoords_exports = {}; -__export(blazeposecoords_exports, { - connected: () => connected, - kpt: () => kpt -}); -var kpt = [ - "nose", - "leftEyeInside", - "leftEye", - "leftEyeOutside", - "rightEyeInside", - "rightEye", - "rightEyeOutside", - "leftEar", - "rightEar", - "leftMouth", - "rightMouth", - "leftShoulder", - "rightShoulder", - "leftElbow", - "rightElbow", - "leftWrist", - "rightWrist", - "leftPinky", - "rightPinky", - "leftIndex", - "rightIndex", - "leftThumb", - "rightThumb", - "leftHip", - "rightHip", - "leftKnee", - "rightKnee", - "leftAnkle", - "rightAnkle", - "leftHeel", - "rightHeel", - "leftFoot", - "rightFoot", - "bodyCenter", - "bodyTop", - "leftPalm", - "leftHand", - "rightPalm", - "rightHand" -]; -var connected = { - shoulders: ["leftShoulder", "rightShoulder"], - hips: ["rightHip", "leftHip"], - mouth: ["leftMouth", "rightMouth"], - leftLegUpper: ["leftHip", "leftKnee"], - leftLegLower: ["leftKnee", "leftAnkle"], - leftFoot: ["leftAnkle", "leftHeel", "leftFoot"], - leftTorso: ["leftShoulder", "leftHip"], - leftArmUpper: ["leftShoulder", "leftElbow"], - leftArmLower: ["leftElbow", "leftWrist"], - leftHand: ["leftWrist", "leftPalm"], - leftHandPinky: ["leftPalm", "leftPinky"], - leftHandIndex: ["leftPalm", "leftIndex"], - leftHandThumb: ["leftPalm", "leftThumb"], - leftEyeOutline: ["leftEyeInside", "leftEyeOutside"], - rightLegUpper: ["rightHip", "rightKnee"], - rightLegLower: ["rightKnee", "rightAnkle"], - rightFoot: ["rightAnkle", "rightHeel", "rightFoot"], - rightTorso: ["rightShoulder", "rightHip"], - rightArmUpper: ["rightShoulder", "rightElbow"], - rightArmLower: ["rightElbow", "rightWrist"], - rightHand: ["rightWrist", "rightPalm"], - rightHandPinky: ["rightPalm", "rightPinky"], - rightHandIndex: ["rightPalm", "rightIndex"], - rightHandThumb: ["rightPalm", "rightThumb"], - rightEyeOutline: ["rightEyeInside", "rightEyeOutside"] -}; - -// src/body/blazeposedetector.ts -var tf8 = __toESM(require_tfjs_esm()); -var model; -var inputSize = 224; -var anchorTensor; -var numLayers = 5; -var strides = [8, 16, 32, 32, 32]; -function createAnchors() { - const anchors3 = []; - let layerId = 0; - while (layerId < numLayers) { - let anchorCount = 0; - let lastSameStrideLayer = layerId; - while (lastSameStrideLayer < strides.length && strides[lastSameStrideLayer] === strides[layerId]) { - anchorCount += 2; - lastSameStrideLayer++; - } - const stride = strides[layerId]; - const featureMapHeight = Math.ceil(inputSize / stride); - const featureMapWidth = Math.ceil(inputSize / stride); - for (let y = 0; y < featureMapHeight; ++y) { - for (let x = 0; x < featureMapWidth; ++x) { - for (let anchorId = 0; anchorId < anchorCount; ++anchorId) { - anchors3.push({ x: (x + 0.5) / featureMapWidth, y: (y + 0.5) / featureMapHeight }); - } - } - } - layerId = lastSameStrideLayer; - } - anchorTensor = { x: tf8.tensor1d(anchors3.map((a) => a.x)), y: tf8.tensor1d(anchors3.map((a) => a.y)) }; -} -async function loadDetector(config3) { - if (env.initial) - model = null; - if (!model && config3.body["detector"] && config3.body["detector"].modelPath || "") { - model = await loadModel(config3.body["detector"].modelPath); - const inputs = (model == null ? void 0 : model["executor"]) ? Object.values(model.modelSignature["inputs"]) : void 0; - inputSize = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - } else if (config3.debug && model) - log("cached model:", model["modelUrl"]); - createAnchors(); - return model; -} -var cropFactor = [5, 5]; -function decodeBoxes(boxesTensor, anchor) { - return tf8.tidy(() => { - const split6 = tf8.split(boxesTensor, 12, 1); - let xCenter = tf8.squeeze(split6[0]); - let yCenter = tf8.squeeze(split6[1]); - let width = tf8.squeeze(split6[2]); - let height = tf8.squeeze(split6[3]); - xCenter = tf8.add(tf8.div(xCenter, inputSize), anchor.x); - yCenter = tf8.add(tf8.div(yCenter, inputSize), anchor.y); - width = tf8.mul(tf8.div(width, inputSize), cropFactor[0]); - height = tf8.mul(tf8.div(height, inputSize), cropFactor[1]); - const xMin = tf8.sub(xCenter, tf8.div(width, 2)); - const yMin = tf8.sub(yCenter, tf8.div(height, 2)); - const xMax = tf8.add(xMin, width); - const yMax = tf8.add(yMin, height); - const boxes = tf8.stack([xMin, yMin, xMax, yMax], 1); - return boxes; - }); -} -async function decodeResults(boxesTensor, logitsTensor, config3, outputSize2) { - var _a, _b; - const detectedBoxes = []; - const t2 = {}; - t2.boxes = decodeBoxes(boxesTensor, anchorTensor); - t2.scores = tf8.sigmoid(logitsTensor); - t2.nms = await tf8.image.nonMaxSuppressionAsync(t2.boxes, t2.scores, 1, ((_a = config3.body["detector"]) == null ? void 0 : _a.minConfidence) || 0.1, ((_b = config3.body["detector"]) == null ? void 0 : _b.iouThreshold) || 0.1); - const nms = await t2.nms.data(); - const scores = await t2.scores.data(); - const boxes = await t2.boxes.array(); - for (const i of Array.from(nms)) { - const score = scores[i]; - const boxRaw = boxes[i]; - const box = [Math.round(boxRaw[0] * outputSize2[0]), Math.round(boxRaw[1] * outputSize2[1]), Math.round(boxRaw[2] * outputSize2[0]), Math.round(boxRaw[3] * outputSize2[1])]; - const detectedBox = { score, boxRaw, box }; - detectedBoxes.push(detectedBox); - } - Object.keys(t2).forEach((tensor6) => tf8.dispose(t2[tensor6])); - return detectedBoxes; -} -async function detectBoxes(input, config3, outputSize2) { - const t2 = {}; - t2.res = model == null ? void 0 : model.execute(input, ["Identity"]); - t2.logitsRaw = tf8.slice(t2.res, [0, 0, 0], [1, -1, 1]); - t2.boxesRaw = tf8.slice(t2.res, [0, 0, 1], [1, -1, -1]); - t2.logits = tf8.squeeze(t2.logitsRaw); - t2.boxes = tf8.squeeze(t2.boxesRaw); - const boxes = await decodeResults(t2.boxes, t2.logits, config3, outputSize2); - Object.keys(t2).forEach((tensor6) => tf8.dispose(t2[tensor6])); - return boxes; -} - -// src/util/box.ts -function calc(keypoints, outputSize2 = [1, 1]) { - const coords = [keypoints.map((pt) => pt[0]), keypoints.map((pt) => pt[1])]; - const min2 = [Math.min(...coords[0]), Math.min(...coords[1])]; - const max5 = [Math.max(...coords[0]), Math.max(...coords[1])]; - const box = [min2[0], min2[1], max5[0] - min2[0], max5[1] - min2[1]]; - const boxRaw = [box[0] / outputSize2[0], box[1] / outputSize2[1], box[2] / outputSize2[0], box[3] / outputSize2[1]]; - return { box, boxRaw }; -} -function square(keypoints, outputSize2 = [1, 1]) { - const coords = [keypoints.map((pt) => pt[0]), keypoints.map((pt) => pt[1])]; - const min2 = [Math.min(...coords[0]), Math.min(...coords[1])]; - const max5 = [Math.max(...coords[0]), Math.max(...coords[1])]; - const center = [(min2[0] + max5[0]) / 2, (min2[1] + max5[1]) / 2]; - const dist = Math.max(center[0] - min2[0], center[1] - min2[1], -center[0] + max5[0], -center[1] + max5[1]); - const box = [Math.trunc(center[0] - dist), Math.trunc(center[1] - dist), Math.trunc(2 * dist), Math.trunc(2 * dist)]; - const boxRaw = [box[0] / outputSize2[0], box[1] / outputSize2[1], box[2] / outputSize2[0], box[3] / outputSize2[1]]; - return { box, boxRaw }; -} -function scale(box, scaleFact) { - const dist = [box[2] * scaleFact, box[3] * scaleFact]; - const newBox = [ - box[0] - (dist[0] - box[2]) / 2, - box[1] - (dist[1] - box[3]) / 2, - dist[0], - dist[1] - ]; - return newBox; -} - -// src/body/blazepose.ts -var model2; -var inputSize2 = 256; -var skipped = Number.MAX_SAFE_INTEGER; -var outputNodes = { - landmarks: ["ld_3d", "activation_segmentation", "activation_heatmap", "world_3d", "output_poseflag"], - detector: [] -}; -var cache = []; -var padding = [[0, 0], [0, 0], [0, 0], [0, 0]]; -var lastTime = 0; -var sigmoid2 = (x) => 1 - 1 / (1 + Math.exp(x)); -var loadDetect = (config3) => loadDetector(config3); -async function loadPose(config3) { - if (env.initial) - model2 = null; - if (!model2) { - model2 = await loadModel(config3.body.modelPath); - const inputs = (model2 == null ? void 0 : model2["executor"]) ? Object.values(model2.modelSignature["inputs"]) : void 0; - inputSize2 = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - } else if (config3.debug) - log("cached model:", model2["modelUrl"]); - return model2; -} -function prepareImage(input, size2, cropBox) { - var _a, _b; - const t2 = {}; - if (!((_a = input == null ? void 0 : input.shape) == null ? void 0 : _a[1]) || !((_b = input == null ? void 0 : input.shape) == null ? void 0 : _b[2])) - return input; - let final; - if (cropBox) { - t2.cropped = tf9.image.cropAndResize(input, [cropBox], [0], [input.shape[1], input.shape[2]]); - } - if (input.shape[1] !== input.shape[2]) { - const height = [ - input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0, - input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0 - ]; - const width = [ - input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0, - input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0 - ]; - padding = [ - [0, 0], - height, - width, - [0, 0] - ]; - t2.pad = tf9.pad(t2.cropped || input, padding); - t2.resize = tf9.image.resizeBilinear(t2.pad, [size2, size2]); - final = tf9.div(t2.resize, constants.tf255); - } else if (input.shape[1] !== size2) { - t2.resize = tf9.image.resizeBilinear(t2.cropped || input, [size2, size2]); - final = tf9.div(t2.resize, constants.tf255); - } else { - final = tf9.div(t2.cropped || input, constants.tf255); - } - Object.keys(t2).forEach((tensor6) => tf9.dispose(t2[tensor6])); - return final; -} -function rescaleKeypoints(keypoints, outputSize2, cropBox) { - for (const kpt4 of keypoints) { - kpt4.position = [ - Math.trunc(kpt4.position[0] * (outputSize2[0] + padding[2][0] + padding[2][1]) / outputSize2[0] - padding[2][0]), - Math.trunc(kpt4.position[1] * (outputSize2[1] + padding[1][0] + padding[1][1]) / outputSize2[1] - padding[1][0]), - kpt4.position[2] - ]; - kpt4.positionRaw = [kpt4.position[0] / outputSize2[0], kpt4.position[1] / outputSize2[1], 2 * kpt4.position[2] / (outputSize2[0] + outputSize2[1])]; - } - if (cropBox) { - const width = cropBox[2] - cropBox[0]; - const height = cropBox[3] - cropBox[1]; - for (const kpt4 of keypoints) { - kpt4.positionRaw = [ - kpt4.positionRaw[0] / height + cropBox[1], - kpt4.positionRaw[1] / width + cropBox[0], - kpt4.positionRaw[2] - ]; - kpt4.position = [ - Math.trunc(kpt4.positionRaw[0] * outputSize2[0]), - Math.trunc(kpt4.positionRaw[1] * outputSize2[1]), - kpt4.positionRaw[2] - ]; - } - } - return keypoints; -} -function fixKeypoints(keypoints) { - const leftPalm = keypoints.find((k) => k.part === "leftPalm"); - const leftWrist = keypoints.find((k) => k.part === "leftWrist"); - const leftIndex = keypoints.find((k) => k.part === "leftIndex"); - leftPalm.position[2] = ((leftWrist.position[2] || 0) + (leftIndex.position[2] || 0)) / 2; - const rightPalm = keypoints.find((k) => k.part === "rightPalm"); - const rightWrist = keypoints.find((k) => k.part === "rightWrist"); - const rightIndex = keypoints.find((k) => k.part === "rightIndex"); - rightPalm.position[2] = ((rightWrist.position[2] || 0) + (rightIndex.position[2] || 0)) / 2; -} -async function detectLandmarks(input, config3, outputSize2) { - if (!(model2 == null ? void 0 : model2["executor"])) - return null; - const t2 = {}; - [t2.ld, t2.segmentation, t2.heatmap, t2.world, t2.poseflag] = model2 == null ? void 0 : model2.execute(input, outputNodes.landmarks); - const poseScore = (await t2.poseflag.data())[0]; - const points = await t2.ld.data(); - const distances = await t2.world.data(); - Object.keys(t2).forEach((tensor6) => tf9.dispose(t2[tensor6])); - const keypointsRelative = []; - const depth = 5; - for (let i = 0; i < points.length / depth; i++) { - const score = sigmoid2(points[depth * i + 3]); - const presence = sigmoid2(points[depth * i + 4]); - const adjScore = Math.trunc(100 * score * presence * poseScore) / 100; - const positionRaw = [points[depth * i + 0] / inputSize2, points[depth * i + 1] / inputSize2, points[depth * i + 2] + 0]; - const position = [Math.trunc(outputSize2[0] * positionRaw[0]), Math.trunc(outputSize2[1] * positionRaw[1]), positionRaw[2]]; - const distance2 = [distances[depth * i + 0], distances[depth * i + 1], distances[depth * i + 2] + 0]; - keypointsRelative.push({ part: kpt[i], positionRaw, position, distance: distance2, score: adjScore }); - } - if (poseScore < (config3.body.minConfidence || 0)) - return null; - fixKeypoints(keypointsRelative); - const keypoints = rescaleKeypoints(keypointsRelative, outputSize2); - const kpts = keypoints.map((k) => k.position); - const boxes = calc(kpts, [outputSize2[0], outputSize2[1]]); - const annotations2 = {}; - for (const [name, indexes] of Object.entries(connected)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = keypoints.find((kpt4) => kpt4.part === indexes[i]); - const pt1 = keypoints.find((kpt4) => kpt4.part === indexes[i + 1]); - if (pt0 && pt1) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - const body4 = { id: 0, score: Math.trunc(100 * poseScore) / 100, box: boxes.box, boxRaw: boxes.boxRaw, keypoints, annotations: annotations2 }; - return body4; -} -async function predict(input, config3) { - var _a, _b, _c; - const outputSize2 = [input.shape[2] || 0, input.shape[1] || 0]; - const skipTime = (config3.body.skipTime || 0) > now() - lastTime; - const skipFrame = skipped < (config3.body.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && cache !== null) { - skipped++; - } else { - let boxes = []; - if ((_b = (_a = config3.body) == null ? void 0 : _a["detector"]) == null ? void 0 : _b["enabled"]) { - const preparedImage = prepareImage(input, 224); - boxes = await detectBoxes(preparedImage, config3, outputSize2); - tf9.dispose(preparedImage); - } else { - boxes = [{ box: [0, 0, 0, 0], boxRaw: [0, 0, 1, 1], score: 0 }]; - } - for (let i = 0; i < boxes.length; i++) { - const preparedBox = prepareImage(input, 256, (_c = boxes[i]) == null ? void 0 : _c.boxRaw); - cache.length = 0; - const bodyResult = await detectLandmarks(preparedBox, config3, outputSize2); - tf9.dispose(preparedBox); - if (!bodyResult) - continue; - bodyResult.id = i; - cache.push(bodyResult); - } - lastTime = now(); - skipped = 0; - } - return cache; -} - -// src/object/centernet.ts -var tf10 = __toESM(require_tfjs_esm()); - -// src/object/labels.ts -var labels2 = [ - { class: 1, label: "person" }, - { class: 2, label: "bicycle" }, - { class: 3, label: "car" }, - { class: 4, label: "motorcycle" }, - { class: 5, label: "airplane" }, - { class: 6, label: "bus" }, - { class: 7, label: "train" }, - { class: 8, label: "truck" }, - { class: 9, label: "boat" }, - { class: 10, label: "traffic light" }, - { class: 11, label: "fire hydrant" }, - { class: 12, label: "stop sign" }, - { class: 13, label: "parking meter" }, - { class: 14, label: "bench" }, - { class: 15, label: "bird" }, - { class: 16, label: "cat" }, - { class: 17, label: "dog" }, - { class: 18, label: "horse" }, - { class: 19, label: "sheep" }, - { class: 20, label: "cow" }, - { class: 21, label: "elephant" }, - { class: 22, label: "bear" }, - { class: 23, label: "zebra" }, - { class: 24, label: "giraffe" }, - { class: 25, label: "backpack" }, - { class: 26, label: "umbrella" }, - { class: 27, label: "handbag" }, - { class: 28, label: "tie" }, - { class: 29, label: "suitcase" }, - { class: 30, label: "frisbee" }, - { class: 31, label: "skis" }, - { class: 32, label: "snowboard" }, - { class: 33, label: "sports ball" }, - { class: 34, label: "kite" }, - { class: 35, label: "baseball bat" }, - { class: 36, label: "baseball glove" }, - { class: 37, label: "skateboard" }, - { class: 38, label: "surfboard" }, - { class: 39, label: "tennis racket" }, - { class: 40, label: "bottle" }, - { class: 41, label: "wine glass" }, - { class: 42, label: "cup" }, - { class: 43, label: "fork" }, - { class: 44, label: "knife" }, - { class: 45, label: "spoon" }, - { class: 46, label: "bowl" }, - { class: 47, label: "banana" }, - { class: 48, label: "apple" }, - { class: 49, label: "sandwich" }, - { class: 50, label: "orange" }, - { class: 51, label: "broccoli" }, - { class: 52, label: "carrot" }, - { class: 53, label: "hot dog" }, - { class: 54, label: "pizza" }, - { class: 55, label: "donut" }, - { class: 56, label: "cake" }, - { class: 57, label: "chair" }, - { class: 58, label: "couch" }, - { class: 59, label: "potted plant" }, - { class: 60, label: "bed" }, - { class: 61, label: "dining table" }, - { class: 62, label: "toilet" }, - { class: 63, label: "tv" }, - { class: 64, label: "laptop" }, - { class: 65, label: "mouse" }, - { class: 66, label: "remote" }, - { class: 67, label: "keyboard" }, - { class: 68, label: "cell phone" }, - { class: 69, label: "microwave" }, - { class: 70, label: "oven" }, - { class: 71, label: "toaster" }, - { class: 72, label: "sink" }, - { class: 73, label: "refrigerator" }, - { class: 74, label: "book" }, - { class: 75, label: "clock" }, - { class: 76, label: "vase" }, - { class: 77, label: "scissors" }, - { class: 78, label: "teddy bear" }, - { class: 79, label: "hair drier" }, - { class: 80, label: "toothbrush" } -]; - -// src/object/centernet.ts -var model3; -var inputSize3 = 0; -var last2 = []; -var lastTime2 = 0; -var skipped2 = Number.MAX_SAFE_INTEGER; -async function load(config3) { - if (env.initial) - model3 = null; - if (!model3) { - model3 = await loadModel(config3.object.modelPath); - const inputs = (model3 == null ? void 0 : model3["executor"]) ? Object.values(model3.modelSignature["inputs"]) : void 0; - inputSize3 = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 0; - } else if (config3.debug) - log("cached model:", model3["modelUrl"]); - return model3; -} -async function process3(res, outputShape, config3) { - if (!res) - return []; - const t2 = {}; - const results = []; - const detections = await res.array(); - t2.squeeze = tf10.squeeze(res); - const arr = tf10.split(t2.squeeze, 6, 1); - t2.stack = tf10.stack([arr[1], arr[0], arr[3], arr[2]], 1); - t2.boxes = tf10.squeeze(t2.stack); - t2.scores = tf10.squeeze(arr[4]); - t2.classes = tf10.squeeze(arr[5]); - tf10.dispose([res, ...arr]); - t2.nms = await tf10.image.nonMaxSuppressionAsync(t2.boxes, t2.scores, config3.object.maxDetected || 0, config3.object.iouThreshold, config3.object.minConfidence || 0); - const nms = await t2.nms.data(); - let i = 0; - for (const id of Array.from(nms)) { - const score = Math.trunc(100 * detections[0][id][4]) / 100; - const classVal = detections[0][id][5]; - if (Number.isNaN(classVal)) - continue; - const label = labels2[classVal].label; - const [x, y] = [ - detections[0][id][0] / inputSize3, - detections[0][id][1] / inputSize3 - ]; - const boxRaw = [ - x, - y, - detections[0][id][2] / inputSize3 - x, - detections[0][id][3] / inputSize3 - y - ]; - const box = [ - Math.trunc(boxRaw[0] * outputShape[0]), - Math.trunc(boxRaw[1] * outputShape[1]), - Math.trunc(boxRaw[2] * outputShape[0]), - Math.trunc(boxRaw[3] * outputShape[1]) - ]; - results.push({ id: i++, score, class: classVal, label, box, boxRaw }); - } - Object.keys(t2).forEach((tensor6) => tf10.dispose(t2[tensor6])); - return results; -} -async function predict2(input, config3) { - if (!(model3 == null ? void 0 : model3["executor"])) - return []; - const skipTime = (config3.object.skipTime || 0) > now() - lastTime2; - const skipFrame = skipped2 < (config3.object.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && last2.length > 0) { - skipped2++; - return last2; - } - skipped2 = 0; - return new Promise(async (resolve) => { - const outputSize2 = [input.shape[2] || 0, input.shape[1] || 0]; - const resize = tf10.image.resizeBilinear(input, [inputSize3, inputSize3]); - const objectT = config3.object.enabled ? model3 == null ? void 0 : model3.execute(resize, ["tower_0/detections"]) : null; - lastTime2 = now(); - tf10.dispose(resize); - const obj = await process3(objectT, outputSize2, config3); - last2 = obj; - resolve(obj); - }); -} - -// src/body/efficientpose.ts -var tf11 = __toESM(require_tfjs_esm()); - -// src/body/efficientposecoords.ts -var efficientposecoords_exports = {}; -__export(efficientposecoords_exports, { - connected: () => connected2, - kpt: () => kpt2 -}); -var kpt2 = [ - "head", - "neck", - "rightShoulder", - "rightElbow", - "rightWrist", - "chest", - "leftShoulder", - "leftElbow", - "leftWrist", - "bodyCenter", - "rightHip", - "rightKnee", - "rightAnkle", - "leftHip", - "leftKnee", - "leftAnkle" -]; -var connected2 = { - leftLeg: ["leftHip", "leftKnee", "leftAnkle"], - rightLeg: ["rightHip", "rightKnee", "rightAnkle"], - torso: ["leftShoulder", "rightShoulder", "rightHip", "leftHip", "leftShoulder"], - leftArm: ["leftShoulder", "leftElbow", "leftWrist"], - rightArm: ["rightShoulder", "rightElbow", "rightWrist"], - head: [] -}; - -// src/body/efficientpose.ts -var model4; -var lastTime3 = 0; -var cache2 = { id: 0, keypoints: [], box: [0, 0, 0, 0], boxRaw: [0, 0, 0, 0], score: 0, annotations: {} }; -var skipped3 = Number.MAX_SAFE_INTEGER; -async function load2(config3) { - if (env.initial) - model4 = null; - if (!model4) - model4 = await loadModel(config3.body.modelPath); - else if (config3.debug) - log("cached model:", model4["modelUrl"]); - return model4; -} -async function max2d(inputs, minScore) { - const [width, height] = inputs.shape; - const reshaped = tf11.reshape(inputs, [height * width]); - const max5 = tf11.max(reshaped, 0); - const newScore = (await max5.data())[0]; - if (newScore > minScore) { - const coordinates = tf11.argMax(reshaped, 0); - const mod3 = tf11.mod(coordinates, width); - const x = (await mod3.data())[0]; - const div15 = tf11.div(coordinates, width); - const y = (await div15.data())[0]; - tf11.dispose([reshaped, max5, coordinates, mod3, div15]); - return [x, y, newScore]; - } - tf11.dispose([reshaped, max5]); - return [0, 0, newScore]; -} -async function predict3(image28, config3) { - if (!(model4 == null ? void 0 : model4["executor"]) || !(model4 == null ? void 0 : model4.inputs[0].shape)) - return []; - const skipTime = (config3.body.skipTime || 0) > now() - lastTime3; - const skipFrame = skipped3 < (config3.body.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && Object.keys(cache2.keypoints).length > 0) { - skipped3++; - return [cache2]; - } - skipped3 = 0; - return new Promise(async (resolve) => { - const tensor6 = tf11.tidy(() => { - var _a, _b; - const resize = tf11.image.resizeBilinear(image28, [((_a = model4 == null ? void 0 : model4.inputs[0].shape) == null ? void 0 : _a[2]) || 0, ((_b = model4 == null ? void 0 : model4.inputs[0].shape) == null ? void 0 : _b[1]) || 0], false); - const enhance2 = tf11.mul(resize, constants.tf2); - const norm = tf11.sub(enhance2, constants.tf1); - return norm; - }); - let resT; - if (config3.body.enabled) - resT = model4 == null ? void 0 : model4.execute(tensor6); - lastTime3 = now(); - tf11.dispose(tensor6); - if (resT) { - cache2.keypoints.length = 0; - const squeeze14 = tf11.squeeze(resT); - tf11.dispose(resT); - const stack5 = tf11.unstack(squeeze14, 2); - tf11.dispose(squeeze14); - for (let id = 0; id < stack5.length; id++) { - const [x2, y2, partScore] = await max2d(stack5[id], config3.body.minConfidence); - if (partScore > (config3.body.minConfidence || 0)) { - cache2.keypoints.push({ - score: Math.round(100 * partScore) / 100, - part: kpt2[id], - positionRaw: [ - x2 / model4.inputs[0].shape[2], - y2 / model4.inputs[0].shape[1] - ], - position: [ - Math.round(image28.shape[2] * x2 / model4.inputs[0].shape[2]), - Math.round(image28.shape[1] * y2 / model4.inputs[0].shape[1]) - ] - }); - } - } - stack5.forEach((s) => tf11.dispose(s)); - } - cache2.score = cache2.keypoints.reduce((prev, curr) => curr.score > prev ? curr.score : prev, 0); - const x = cache2.keypoints.map((a) => a.position[0]); - const y = cache2.keypoints.map((a) => a.position[1]); - cache2.box = [ - Math.min(...x), - Math.min(...y), - Math.max(...x) - Math.min(...x), - Math.max(...y) - Math.min(...y) - ]; - const xRaw = cache2.keypoints.map((a) => a.positionRaw[0]); - const yRaw = cache2.keypoints.map((a) => a.positionRaw[1]); - cache2.boxRaw = [ - Math.min(...xRaw), - Math.min(...yRaw), - Math.max(...xRaw) - Math.min(...xRaw), - Math.max(...yRaw) - Math.min(...yRaw) - ]; - for (const [name, indexes] of Object.entries(connected2)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = cache2.keypoints.find((kpt4) => kpt4.part === indexes[i]); - const pt1 = cache2.keypoints.find((kpt4) => kpt4.part === indexes[i + 1]); - if (pt0 && pt1 && pt0.score > (config3.body.minConfidence || 0) && pt1.score > (config3.body.minConfidence || 0)) - pt.push([pt0.position, pt1.position]); - } - cache2.annotations[name] = pt; - } - resolve([cache2]); - }); -} - -// src/face/face.ts -var tf25 = __toESM(require_tfjs_esm()); - -// src/face/facemesh.ts -var tf15 = __toESM(require_tfjs_esm()); - -// src/face/blazeface.ts -var tf13 = __toESM(require_tfjs_esm()); - -// src/face/facemeshutil.ts -var tf12 = __toESM(require_tfjs_esm()); -var getBoxSize = (box) => [Math.abs(box.endPoint[0] - box.startPoint[0]), Math.abs(box.endPoint[1] - box.startPoint[1])]; -var getBoxCenter = (box) => [box.startPoint[0] + (box.endPoint[0] - box.startPoint[0]) / 2, box.startPoint[1] + (box.endPoint[1] - box.startPoint[1]) / 2, 1]; -var clampBox = (box, input) => box ? [ - Math.trunc(Math.max(0, box.startPoint[0])), - Math.trunc(Math.max(0, box.startPoint[1])), - Math.trunc(Math.min(input.shape[2] || 0, box.endPoint[0]) - Math.max(0, box.startPoint[0])), - Math.trunc(Math.min(input.shape[1] || 0, box.endPoint[1]) - Math.max(0, box.startPoint[1])) -] : [0, 0, 0, 0]; -var getRawBox = (box, input) => box ? [ - box.startPoint[0] / (input.shape[2] || 0), - box.startPoint[1] / (input.shape[1] || 0), - (box.endPoint[0] - box.startPoint[0]) / (input.shape[2] || 0), - (box.endPoint[1] - box.startPoint[1]) / (input.shape[1] || 0) -] : [0, 0, 0, 0]; -var scaleBoxCoordinates = (box, factor) => { - const startPoint = [box.startPoint[0] * factor[0], box.startPoint[1] * factor[1]]; - const endPoint = [box.endPoint[0] * factor[0], box.endPoint[1] * factor[1]]; - return { startPoint, endPoint, landmarks: box.landmarks, confidence: box.confidence }; -}; -var cutAndResize = (box, image28, cropSize) => { - const h = image28.shape[1]; - const w = image28.shape[2]; - const cutBox = [box.startPoint[1] / h, box.startPoint[0] / w, box.endPoint[1] / h, box.endPoint[0] / w]; - const crop = tf12.image.cropAndResize(image28, [cutBox], [0], cropSize); - const norm = tf12.div(crop, constants.tf255); - tf12.dispose(crop); - return norm; -}; -var enlargeBox = (box, factor) => { - const center = getBoxCenter(box); - const size2 = getBoxSize(box); - const halfSize = [factor * size2[0] / 2, factor * size2[1] / 2]; - return { startPoint: [center[0] - halfSize[0], center[1] - halfSize[1]], endPoint: [center[0] + halfSize[0], center[1] + halfSize[1]], landmarks: box.landmarks, confidence: box.confidence }; -}; -var squarifyBox = (box) => { - const centers = getBoxCenter(box); - const size2 = getBoxSize(box); - const halfSize = Math.max(...size2) / 2; - return { startPoint: [Math.round(centers[0] - halfSize), Math.round(centers[1] - halfSize)], endPoint: [Math.round(centers[0] + halfSize), Math.round(centers[1] + halfSize)], landmarks: box.landmarks, confidence: box.confidence }; -}; -var calculateLandmarksBoundingBox = (landmarks) => { - const x = landmarks.map((d) => d[0]); - const y = landmarks.map((d) => d[1]); - return { startPoint: [Math.min(...x), Math.min(...y)], endPoint: [Math.max(...x), Math.max(...y)], landmarks }; -}; -var fixedRotationMatrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; -var normalizeRadians = (angle) => angle - 2 * Math.PI * Math.floor((angle + Math.PI) / (2 * Math.PI)); -var computeRotation = (point1, point2) => normalizeRadians(Math.PI / 2 - Math.atan2(-(point2[1] - point1[1]), point2[0] - point1[0])); -var buildTranslationMatrix = (x, y) => [[1, 0, x], [0, 1, y], [0, 0, 1]]; -var dot = (v1, v2) => { - let product = 0; - for (let i = 0; i < v1.length; i++) - product += v1[i] * v2[i]; - return product; -}; -var getColumnFrom2DArr = (arr, columnIndex) => { - const column = []; - for (let i = 0; i < arr.length; i++) - column.push(arr[i][columnIndex]); - return column; -}; -var multiplyTransformMatrices = (mat1, mat2) => { - const product = []; - const size2 = mat1.length; - for (let row = 0; row < size2; row++) { - product.push([]); - for (let col = 0; col < size2; col++) - product[row].push(dot(mat1[row], getColumnFrom2DArr(mat2, col))); - } - return product; -}; -var buildRotationMatrix = (rotation, center) => { - const cosA = Math.cos(rotation); - const sinA = Math.sin(rotation); - const rotationMatrix = [[cosA, -sinA, 0], [sinA, cosA, 0], [0, 0, 1]]; - const translationMatrix = buildTranslationMatrix(center[0], center[1]); - const translationTimesRotation = multiplyTransformMatrices(translationMatrix, rotationMatrix); - const negativeTranslationMatrix = buildTranslationMatrix(-center[0], -center[1]); - return multiplyTransformMatrices(translationTimesRotation, negativeTranslationMatrix); -}; -var invertTransformMatrix = (matrix) => { - const rotationComponent = [[matrix[0][0], matrix[1][0]], [matrix[0][1], matrix[1][1]]]; - const translationComponent = [matrix[0][2], matrix[1][2]]; - const invertedTranslation = [-dot(rotationComponent[0], translationComponent), -dot(rotationComponent[1], translationComponent)]; - return [rotationComponent[0].concat(invertedTranslation[0]), rotationComponent[1].concat(invertedTranslation[1]), [0, 0, 1]]; -}; -var rotatePoint = (homogeneousCoordinate, rotationMatrix) => [dot(homogeneousCoordinate, rotationMatrix[0]), dot(homogeneousCoordinate, rotationMatrix[1])]; -function generateAnchors(inputSize10) { - const spec = inputSize10 === 192 ? { strides: [4], anchors: [1] } : { strides: [inputSize10 / 16, inputSize10 / 8], anchors: [2, 6] }; - const anchors3 = []; - for (let i = 0; i < spec.strides.length; i++) { - const stride = spec.strides[i]; - const gridRows = Math.floor((inputSize10 + stride - 1) / stride); - const gridCols = Math.floor((inputSize10 + stride - 1) / stride); - const anchorsNum = spec.anchors[i]; - for (let gridY = 0; gridY < gridRows; gridY++) { - const anchorY = stride * (gridY + 0.5); - for (let gridX = 0; gridX < gridCols; gridX++) { - const anchorX = stride * (gridX + 0.5); - for (let n = 0; n < anchorsNum; n++) - anchors3.push([anchorX, anchorY]); - } - } - } - return anchors3; -} -function transformRawCoords(coordsRaw, box, angle, rotationMatrix, inputSize10) { - const boxSize = getBoxSize(box); - const coordsScaled = coordsRaw.map((coord) => [ - boxSize[0] / inputSize10 * (coord[0] - inputSize10 / 2), - boxSize[1] / inputSize10 * (coord[1] - inputSize10 / 2), - coord[2] || 0 - ]); - const largeAngle = angle && angle !== 0 && Math.abs(angle) > 0.2; - const coordsRotationMatrix = largeAngle ? buildRotationMatrix(angle, [0, 0]) : fixedRotationMatrix; - const coordsRotated = largeAngle ? coordsScaled.map((coord) => [...rotatePoint(coord, coordsRotationMatrix), coord[2]]) : coordsScaled; - const inverseRotationMatrix = largeAngle ? invertTransformMatrix(rotationMatrix) : fixedRotationMatrix; - const boxCenter = getBoxCenter(box); - const offsets = [dot(boxCenter, inverseRotationMatrix[0]), dot(boxCenter, inverseRotationMatrix[1])]; - return coordsRotated.map((coord) => [ - Math.trunc(coord[0] + offsets[0]), - Math.trunc(coord[1] + offsets[1]), - Math.trunc(coord[2] || 0) - ]); -} -function correctFaceRotation(rotate, box, input, inputSize10) { - const symmetryLine = box.landmarks.length >= meshLandmarks.count ? meshLandmarks.symmetryLine : blazeFaceLandmarks.symmetryLine; - let angle = 0; - let rotationMatrix = fixedRotationMatrix; - let face4; - if (rotate && env.kernels.includes("rotatewithoffset")) { - angle = computeRotation(box.landmarks[symmetryLine[0]], box.landmarks[symmetryLine[1]]); - const largeAngle = angle && angle !== 0 && Math.abs(angle) > 0.2; - if (largeAngle) { - const center = getBoxCenter(box); - const centerRaw = [center[0] / input.shape[2], center[1] / input.shape[1]]; - const rotated = tf12.image.rotateWithOffset(input, angle, 0, [centerRaw[0], centerRaw[1]]); - rotationMatrix = buildRotationMatrix(-angle, center); - face4 = cutAndResize(box, rotated, [inputSize10, inputSize10]); - tf12.dispose(rotated); - } else { - face4 = cutAndResize(box, input, [inputSize10, inputSize10]); - } - } else { - face4 = cutAndResize(box, input, [inputSize10, inputSize10]); - } - return [angle, rotationMatrix, face4]; -} -var findFaceCenter = (mesh) => { - const x = mesh.map((m) => m[0]); - const y = mesh.map((m) => m[1]); - return [Math.min(...x) + (Math.max(...x) - Math.min(...x)) / 2, Math.min(...y) + (Math.max(...y) - Math.min(...y)) / 2]; -}; -var calculateFaceBox = (mesh, previousBox) => { - const center = findFaceCenter(mesh); - const boxSize = getBoxSize(previousBox); - const calculatedBox = { - startPoint: [center[0] - boxSize[0] / 2, center[1] - boxSize[1] / 2], - endPoint: [center[0] + boxSize[0] / 2, center[1] + boxSize[1] / 2] - }; - return calculatedBox; -}; - -// src/face/blazeface.ts -var keypointsCount = 6; -var faceBoxScaleFactor = 1.4; -var model5; -var anchors = null; -var inputSize4 = 0; -var inputSizeT = null; -var size = () => inputSize4; -async function load3(config3) { - var _a; - if (env.initial) - model5 = null; - if (!model5) - model5 = await loadModel((_a = config3.face.detector) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model5["modelUrl"]); - inputSize4 = model5["executor"] && model5.inputs[0].shape ? model5.inputs[0].shape[2] : 256; - inputSizeT = tf13.scalar(inputSize4, "int32"); - anchors = tf13.tensor2d(generateAnchors(inputSize4)); - return model5; -} -function decodeBoxes2(boxOutputs) { - if (!anchors || !inputSizeT) - return tf13.zeros([0, 0]); - const t2 = {}; - t2.boxStarts = tf13.slice(boxOutputs, [0, 1], [-1, 2]); - t2.centers = tf13.add(t2.boxStarts, anchors); - t2.boxSizes = tf13.slice(boxOutputs, [0, 3], [-1, 2]); - t2.boxSizesNormalized = tf13.div(t2.boxSizes, inputSizeT); - t2.centersNormalized = tf13.div(t2.centers, inputSizeT); - t2.halfBoxSize = tf13.div(t2.boxSizesNormalized, constants.tf2); - t2.starts = tf13.sub(t2.centersNormalized, t2.halfBoxSize); - t2.ends = tf13.add(t2.centersNormalized, t2.halfBoxSize); - t2.startNormalized = tf13.mul(t2.starts, inputSizeT); - t2.endNormalized = tf13.mul(t2.ends, inputSizeT); - const boxes = tf13.concat2d([t2.startNormalized, t2.endNormalized], 1); - Object.keys(t2).forEach((tensor6) => tf13.dispose(t2[tensor6])); - return boxes; -} -async function getBoxes(inputImage, config3) { - var _a, _b, _c, _d; - if (!inputImage || inputImage["isDisposedInternal"] || inputImage.shape.length !== 4 || inputImage.shape[1] < 1 || inputImage.shape[2] < 1) - return []; - const t2 = {}; - t2.resized = tf13.image.resizeBilinear(inputImage, [inputSize4, inputSize4]); - t2.div = tf13.div(t2.resized, constants.tf127); - t2.normalized = tf13.sub(t2.div, constants.tf05); - const res = model5 == null ? void 0 : model5.execute(t2.normalized); - if (Array.isArray(res) && res.length > 2) { - const sorted = res.sort((a, b) => a.size - b.size); - t2.concat384 = tf13.concat([sorted[0], sorted[2]], 2); - t2.concat512 = tf13.concat([sorted[1], sorted[3]], 2); - t2.concat = tf13.concat([t2.concat512, t2.concat384], 1); - t2.batch = tf13.squeeze(t2.concat, [0]); - } else if (Array.isArray(res)) { - t2.batch = tf13.squeeze(res[0]); - } else { - t2.batch = tf13.squeeze(res); - } - tf13.dispose(res); - t2.boxes = decodeBoxes2(t2.batch); - t2.logits = tf13.slice(t2.batch, [0, 0], [-1, 1]); - t2.sigmoid = tf13.sigmoid(t2.logits); - t2.scores = tf13.squeeze(t2.sigmoid); - t2.nms = await tf13.image.nonMaxSuppressionAsync(t2.boxes, t2.scores, ((_a = config3.face.detector) == null ? void 0 : _a.maxDetected) || 0, ((_b = config3.face.detector) == null ? void 0 : _b.iouThreshold) || 0, ((_c = config3.face.detector) == null ? void 0 : _c.minConfidence) || 0); - const nms = await t2.nms.array(); - const boxes = []; - const scores = await t2.scores.data(); - for (let i = 0; i < nms.length; i++) { - const confidence = scores[nms[i]]; - if (confidence > (((_d = config3.face.detector) == null ? void 0 : _d.minConfidence) || 0)) { - const b = {}; - b.bbox = tf13.slice(t2.boxes, [nms[i], 0], [1, -1]); - b.slice = tf13.slice(t2.batch, [nms[i], keypointsCount - 1], [1, -1]); - b.squeeze = tf13.squeeze(b.slice); - b.landmarks = tf13.reshape(b.squeeze, [keypointsCount, -1]); - const points = await b.bbox.data(); - const rawBox = { - startPoint: [points[0], points[1]], - endPoint: [points[2], points[3]], - landmarks: await b.landmarks.array(), - confidence - }; - const scaledBox = scaleBoxCoordinates(rawBox, [(inputImage.shape[2] || 0) / inputSize4, (inputImage.shape[1] || 0) / inputSize4]); - const enlargedBox = enlargeBox(scaledBox, config3.face["scale"] || faceBoxScaleFactor); - const squaredBox = squarifyBox(enlargedBox); - boxes.push(squaredBox); - Object.keys(b).forEach((tensor6) => tf13.dispose(b[tensor6])); - } - } - Object.keys(t2).forEach((tensor6) => tf13.dispose(t2[tensor6])); - return boxes; -} - -// src/face/iris.ts -var tf14 = __toESM(require_tfjs_esm()); -var model6; -var inputSize5 = 0; -var irisEnlarge = 2.3; -var leftOutline = meshAnnotations.leftEyeLower0; -var rightOutline = meshAnnotations.rightEyeLower0; -var eyeLandmarks = { - leftBounds: [leftOutline[0], leftOutline[leftOutline.length - 1]], - rightBounds: [rightOutline[0], rightOutline[rightOutline.length - 1]] -}; -var irisLandmarks = { - upperCenter: 3, - lowerCenter: 4, - index: 71, - numCoordinates: 76 -}; -async function load4(config3) { - var _a, _b; - if (env.initial) - model6 = null; - if (!model6) - model6 = await loadModel((_a = config3.face.iris) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model6["modelUrl"]); - inputSize5 = (model6 == null ? void 0 : model6["executor"]) && ((_b = model6.inputs) == null ? void 0 : _b[0].shape) ? model6.inputs[0].shape[2] : 0; - if (inputSize5 === -1) - inputSize5 = 64; - return model6; -} -function replaceIrisCoords(rawCoords, newCoords, prefix, keys) { - for (let i = 0; i < irisIndices.length; i++) { - const { key, indices } = irisIndices[i]; - const originalIndices = meshAnnotations[`${prefix}${key}`]; - if (!keys || keys.includes(key)) { - for (let j = 0; j < indices.length; j++) { - const index2 = indices[j]; - rawCoords[originalIndices[j]] = [ - newCoords[index2][0], - newCoords[index2][1], - (newCoords[index2][2] + rawCoords[originalIndices[j]][2]) / 2 - ]; - } - } - } -} -var getLeftToRightEyeDepthDifference = (rawCoords) => { - const leftEyeZ = rawCoords[eyeLandmarks.leftBounds[0]][2]; - const rightEyeZ = rawCoords[eyeLandmarks.rightBounds[0]][2]; - return leftEyeZ - rightEyeZ; -}; -var getEyeBox = (rawCoords, face4, eyeInnerCornerIndex, eyeOuterCornerIndex, meshSize, flip = false) => { - const box = squarifyBox(enlargeBox(calculateLandmarksBoundingBox([rawCoords[eyeInnerCornerIndex], rawCoords[eyeOuterCornerIndex]]), irisEnlarge)); - const boxSize = getBoxSize(box); - let crop = tf14.image.cropAndResize(face4, [[ - box.startPoint[1] / meshSize, - box.startPoint[0] / meshSize, - box.endPoint[1] / meshSize, - box.endPoint[0] / meshSize - ]], [0], [inputSize5, inputSize5]); - if (flip && env.kernels.includes("flipleftright")) { - const flipped = tf14.image.flipLeftRight(crop); - tf14.dispose(crop); - crop = flipped; - } - return { box, boxSize, crop }; -}; -var getEyeCoords = (eyeData, eyeBox, eyeBoxSize, flip = false) => { - const eyeRawCoords = []; - for (let i = 0; i < irisLandmarks.numCoordinates; i++) { - const x = eyeData[i * 3]; - const y = eyeData[i * 3 + 1]; - const z = eyeData[i * 3 + 2]; - eyeRawCoords.push([ - (flip ? 1 - x / inputSize5 : x / inputSize5) * eyeBoxSize[0] + eyeBox.startPoint[0], - y / inputSize5 * eyeBoxSize[1] + eyeBox.startPoint[1], - z - ]); - } - return { rawCoords: eyeRawCoords, iris: eyeRawCoords.slice(irisLandmarks.index) }; -}; -var getAdjustedIrisCoords = (rawCoords, irisCoords, direction) => { - const upperCenterZ = rawCoords[meshAnnotations[`${direction}EyeUpper0`][irisLandmarks.upperCenter]][2]; - const lowerCenterZ = rawCoords[meshAnnotations[`${direction}EyeLower0`][irisLandmarks.lowerCenter]][2]; - const averageZ = (upperCenterZ + lowerCenterZ) / 2; - return irisCoords.map((coord, i) => { - let z = averageZ; - if (i === 2) { - z = upperCenterZ; - } else if (i === 4) { - z = lowerCenterZ; - } - return [coord[0], coord[1], z]; - }); -}; -async function augmentIris(rawCoords, face4, meshSize) { - if (!(model6 == null ? void 0 : model6["executor"])) - return rawCoords; - const { box: leftEyeBox, boxSize: leftEyeBoxSize, crop: leftEyeCrop } = getEyeBox(rawCoords, face4, eyeLandmarks.leftBounds[0], eyeLandmarks.leftBounds[1], meshSize, true); - const { box: rightEyeBox, boxSize: rightEyeBoxSize, crop: rightEyeCrop } = getEyeBox(rawCoords, face4, eyeLandmarks.rightBounds[0], eyeLandmarks.rightBounds[1], meshSize, true); - const combined = tf14.concat([leftEyeCrop, rightEyeCrop]); - tf14.dispose(leftEyeCrop); - tf14.dispose(rightEyeCrop); - const eyePredictions = model6.execute(combined); - tf14.dispose(combined); - const eyePredictionsData = await eyePredictions.data(); - tf14.dispose(eyePredictions); - const leftEyeData = eyePredictionsData.slice(0, irisLandmarks.numCoordinates * 3); - const { rawCoords: leftEyeRawCoords, iris: leftIrisRawCoords } = getEyeCoords(leftEyeData, leftEyeBox, leftEyeBoxSize, true); - const rightEyeData = eyePredictionsData.slice(irisLandmarks.numCoordinates * 3); - const { rawCoords: rightEyeRawCoords, iris: rightIrisRawCoords } = getEyeCoords(rightEyeData, rightEyeBox, rightEyeBoxSize, false); - const leftToRightEyeDepthDifference = getLeftToRightEyeDepthDifference(rawCoords); - if (Math.abs(leftToRightEyeDepthDifference) < 30) { - replaceIrisCoords(rawCoords, leftEyeRawCoords, "left", null); - replaceIrisCoords(rawCoords, rightEyeRawCoords, "right", null); - } else if (leftToRightEyeDepthDifference < 1) { - replaceIrisCoords(rawCoords, leftEyeRawCoords, "left", ["EyeUpper0", "EyeLower0"]); - } else { - replaceIrisCoords(rawCoords, rightEyeRawCoords, "right", ["EyeUpper0", "EyeLower0"]); - } - const adjustedLeftIrisCoords = getAdjustedIrisCoords(rawCoords, leftIrisRawCoords, "left"); - const adjustedRightIrisCoords = getAdjustedIrisCoords(rawCoords, rightIrisRawCoords, "right"); - const newCoords = rawCoords.concat(adjustedLeftIrisCoords).concat(adjustedRightIrisCoords); - return newCoords; -} - -// src/face/attention.ts -async function augment(rawCoords, results) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; - const t2 = { - lips: await ((_b = (_a = results.filter((r) => r.size === 160)) == null ? void 0 : _a[0]) == null ? void 0 : _b.data()), - irisL: await ((_d = (_c = results.filter((r) => r.size === 10)) == null ? void 0 : _c[0]) == null ? void 0 : _d.data()), - eyeL: await ((_f = (_e = results.filter((r) => r.size === 142)) == null ? void 0 : _e[0]) == null ? void 0 : _f.data()), - irisR: await ((_h = (_g = results.filter((r) => r.size === 10)) == null ? void 0 : _g[1]) == null ? void 0 : _h.data()), - eyeR: await ((_j = (_i = results.filter((r) => r.size === 142)) == null ? void 0 : _i[1]) == null ? void 0 : _j.data()) - }; - for (const val of Object.values(t2)) { - if (!val) - return rawCoords; - } - const irisLDepth = LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG.reduce((prev, curr) => prev += rawCoords[curr][2], 0) / LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG.length; - for (let i = 0; i < t2.irisL.length / 2; i++) - rawCoords.push([t2.irisL[2 * i + 0], t2.irisL[2 * i + 1], irisLDepth]); - const irisRDepth = LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG.reduce((prev, curr) => prev += rawCoords[curr][2], 0) / LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG.length; - for (let i = 0; i < t2.irisR.length / 2; i++) - rawCoords.push([t2.irisR[2 * i + 0], t2.irisR[2 * i + 1], irisRDepth]); - for (let i = 0; i < t2.eyeL.length / 2; i++) - rawCoords[LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG[i]] = [t2.eyeL[2 * i + 0], t2.eyeL[2 * i + 1], rawCoords[LANDMARKS_REFINEMENT_LEFT_EYE_CONFIG[i]][2]]; - for (let i = 0; i < t2.eyeR.length / 2; i++) - rawCoords[LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG[i]] = [t2.eyeR[2 * i + 0], t2.eyeR[2 * i + 1], rawCoords[LANDMARKS_REFINEMENT_RIGHT_EYE_CONFIG[i]][2]]; - for (let i = 0; i < t2.lips.length / 2; i++) - rawCoords[LANDMARKS_REFINEMENT_LIPS_CONFIG[i]] = [t2.lips[2 * i + 0], t2.lips[2 * i + 1], rawCoords[LANDMARKS_REFINEMENT_LIPS_CONFIG[i]][2]]; - return rawCoords; -} - -// src/face/facemesh.ts -var cache3 = { - boxes: [], - skipped: Number.MAX_SAFE_INTEGER, - timestamp: 0 -}; -var model7 = null; -var inputSize6 = 0; -async function predict4(input, config3) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; - if (!(model7 == null ? void 0 : model7["executor"])) - return []; - const skipTime = (((_a = config3.face.detector) == null ? void 0 : _a.skipTime) || 0) > now() - cache3.timestamp; - const skipFrame = cache3.skipped < (((_b = config3.face.detector) == null ? void 0 : _b.skipFrames) || 0); - if (!config3.skipAllowed || !skipTime || !skipFrame || cache3.boxes.length === 0) { - cache3.boxes = await getBoxes(input, config3); - cache3.timestamp = now(); - cache3.skipped = 0; - } else { - cache3.skipped++; - } - const faces = []; - const newCache = []; - let id = 0; - const size2 = inputSize6; - for (let i = 0; i < cache3.boxes.length; i++) { - const box = cache3.boxes[i]; - let angle = 0; - let rotationMatrix; - const face4 = { - id: id++, - mesh: [], - meshRaw: [], - box: [0, 0, 0, 0], - boxRaw: [0, 0, 0, 0], - score: 0, - boxScore: 0, - faceScore: 0, - annotations: {} - }; - [angle, rotationMatrix, face4.tensor] = correctFaceRotation((_c = config3.face.detector) == null ? void 0 : _c.rotation, box, input, ((_d = config3.face.mesh) == null ? void 0 : _d.enabled) ? inputSize6 : size()); - if (config3.filter.equalization) { - const equilized = face4.tensor ? await histogramEqualization(face4.tensor) : void 0; - tf15.dispose(face4.tensor); - if (equilized) - face4.tensor = equilized; - } - face4.boxScore = Math.round(100 * box.confidence) / 100; - if (!((_e = config3.face.mesh) == null ? void 0 : _e.enabled)) { - face4.box = clampBox(box, input); - face4.boxRaw = getRawBox(box, input); - face4.score = face4.boxScore; - face4.mesh = box.landmarks.map((pt) => [ - (box.startPoint[0] + box.endPoint[0]) / 2 + (box.endPoint[0] + box.startPoint[0]) * pt[0] / size(), - (box.startPoint[1] + box.endPoint[1]) / 2 + (box.endPoint[1] + box.startPoint[1]) * pt[1] / size() - ]); - face4.meshRaw = face4.mesh.map((pt) => [pt[0] / (input.shape[2] || 0), pt[1] / (input.shape[1] || 0), (pt[2] || 0) / size2]); - for (const key of Object.keys(blazeFaceLandmarks)) { - face4.annotations[key] = [face4.mesh[blazeFaceLandmarks[key]]]; - } - } else if (!model7) { - if (config3.debug) - log("face mesh detection requested, but model is not loaded"); - } else { - if (((_f = config3.face.attention) == null ? void 0 : _f.enabled) && !env.kernels.includes("atan2")) { - config3.face.attention.enabled = false; - tf15.dispose(face4.tensor); - return faces; - } - const results = model7.execute(face4.tensor); - const confidenceT = results.find((t2) => t2.shape[t2.shape.length - 1] === 1); - const faceConfidence = await confidenceT.data(); - face4.faceScore = Math.round(100 * faceConfidence[0]) / 100; - if (face4.faceScore < (((_g = config3.face.detector) == null ? void 0 : _g.minConfidence) || 1)) { - box.confidence = face4.faceScore; - if (config3.face.mesh.keepInvalid) { - face4.box = clampBox(box, input); - face4.boxRaw = getRawBox(box, input); - face4.score = face4.boxScore; - face4.mesh = box.landmarks.map((pt) => [ - (box.startPoint[0] + box.endPoint[0]) / 2 + (box.endPoint[0] + box.startPoint[0]) * pt[0] / size(), - (box.startPoint[1] + box.endPoint[1]) / 2 + (box.endPoint[1] + box.startPoint[1]) * pt[1] / size() - ]); - face4.meshRaw = face4.mesh.map((pt) => [pt[0] / (input.shape[2] || 1), pt[1] / (input.shape[1] || 1), (pt[2] || 0) / size2]); - for (const key of Object.keys(blazeFaceLandmarks)) { - face4.annotations[key] = [face4.mesh[blazeFaceLandmarks[key]]]; - } - } - } else { - const meshT = results.find((t2) => t2.shape[t2.shape.length - 1] === 1404); - const coordsReshaped = tf15.reshape(meshT, [-1, 3]); - let rawCoords = await coordsReshaped.array(); - tf15.dispose(coordsReshaped); - if ((_h = config3.face.attention) == null ? void 0 : _h.enabled) { - rawCoords = await augment(rawCoords, results); - } else if ((_i = config3.face.iris) == null ? void 0 : _i.enabled) { - rawCoords = await augmentIris(rawCoords, face4.tensor, inputSize6); - } - face4.mesh = transformRawCoords(rawCoords, box, angle, rotationMatrix, inputSize6); - face4.meshRaw = face4.mesh.map((pt) => [pt[0] / (input.shape[2] || 0), pt[1] / (input.shape[1] || 0), (pt[2] || 0) / size2]); - for (const key of Object.keys(meshAnnotations)) - face4.annotations[key] = meshAnnotations[key].map((index2) => face4.mesh[index2]); - face4.score = face4.faceScore; - const calculatedBox = { ...calculateFaceBox(face4.mesh, box), confidence: box.confidence, landmarks: box.landmarks }; - face4.box = clampBox(calculatedBox, input); - face4.boxRaw = getRawBox(calculatedBox, input); - newCache.push(calculatedBox); - } - tf15.dispose(results); - } - if (face4.score > (((_j = config3.face.detector) == null ? void 0 : _j.minConfidence) || 1)) - faces.push(face4); - else - tf15.dispose(face4.tensor); - } - cache3.boxes = newCache; - return faces; -} -async function load5(config3) { - var _a, _b, _c, _d, _e, _f; - if (env.initial) - model7 = null; - if (((_a = config3.face.attention) == null ? void 0 : _a.enabled) && (model7 == null ? void 0 : model7["signature"])) { - if (Object.keys(((_b = model7 == null ? void 0 : model7["signature"]) == null ? void 0 : _b.outputs) || {}).length < 6) - model7 = null; - } - if (!model7) { - if ((_c = config3.face.attention) == null ? void 0 : _c.enabled) - model7 = await loadModel(config3.face.attention.modelPath); - else - model7 = await loadModel((_d = config3.face.mesh) == null ? void 0 : _d.modelPath); - } else if (config3.debug) { - log("cached model:", model7["modelUrl"]); - } - inputSize6 = model7["executor"] && ((_e = model7 == null ? void 0 : model7.inputs) == null ? void 0 : _e[0].shape) ? (_f = model7 == null ? void 0 : model7.inputs) == null ? void 0 : _f[0].shape[2] : 256; - return model7; -} -var triangulation = TRI468; -var uvmap = UV468; - -// src/gear/emotion.ts -var tf16 = __toESM(require_tfjs_esm()); -var annotations = ["angry", "disgust", "fear", "happy", "sad", "surprise", "neutral"]; -var model8; -var last3 = []; -var lastCount = 0; -var lastTime4 = 0; -var skipped4 = Number.MAX_SAFE_INTEGER; -async function load6(config3) { - var _a; - if (env.initial) - model8 = null; - if (!model8) - model8 = await loadModel((_a = config3.face.emotion) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model8["modelUrl"]); - return model8; -} -async function predict5(image28, config3, idx, count2) { - var _a, _b; - if (!model8) - return []; - const skipFrame = skipped4 < (((_a = config3.face.emotion) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face.emotion) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime4; - if (config3.skipAllowed && skipTime && skipFrame && lastCount === count2 && last3[idx] && last3[idx].length > 0) { - skipped4++; - return last3[idx]; - } - skipped4 = 0; - return new Promise(async (resolve) => { - var _a2; - const obj = []; - if ((_a2 = config3.face.emotion) == null ? void 0 : _a2.enabled) { - const t2 = {}; - const inputSize10 = (model8 == null ? void 0 : model8.inputs[0].shape) ? model8.inputs[0].shape[2] : 0; - t2.resize = tf16.image.resizeBilinear(image28, [inputSize10, inputSize10], false); - t2.channels = tf16.mul(t2.resize, constants.rgb); - t2.grayscale = tf16.sum(t2.channels, 3, true); - t2.grayscaleSub = tf16.sub(t2.grayscale, constants.tf05); - t2.grayscaleMul = tf16.mul(t2.grayscaleSub, constants.tf2); - t2.emotion = model8 == null ? void 0 : model8.execute(t2.grayscaleMul); - lastTime4 = now(); - const data = await t2.emotion.data(); - for (let i = 0; i < data.length; i++) { - if (data[i] > (config3.face.emotion.minConfidence || 0)) - obj.push({ score: Math.min(0.99, Math.trunc(100 * data[i]) / 100), emotion: annotations[i] }); - } - obj.sort((a, b) => b.score - a.score); - Object.keys(t2).forEach((tensor6) => tf16.dispose(t2[tensor6])); - } - last3[idx] = obj; - lastCount = count2; - resolve(obj); - }); -} - -// src/face/faceres.ts -var tf17 = __toESM(require_tfjs_esm()); -var model9; -var last4 = []; -var lastTime5 = 0; -var lastCount2 = 0; -var skipped5 = Number.MAX_SAFE_INTEGER; -async function load7(config3) { - var _a; - if (env.initial) - model9 = null; - if (!model9) - model9 = await loadModel((_a = config3.face.description) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model9["modelUrl"]); - return model9; -} -function enhance(input) { - const tensor6 = input.image || input.tensor || input; - if (!(model9 == null ? void 0 : model9.inputs[0].shape)) - return tensor6; - const crop = tf17.image.resizeBilinear(tensor6, [model9.inputs[0].shape[2], model9.inputs[0].shape[1]], false); - const norm = tf17.mul(crop, constants.tf255); - tf17.dispose(crop); - return norm; -} -async function predict6(image28, config3, idx, count2) { - var _a, _b, _c, _d; - const obj = { - age: 0, - gender: "unknown", - genderScore: 0, - descriptor: [] - }; - if (!(model9 == null ? void 0 : model9["executor"])) - return obj; - const skipFrame = skipped5 < (((_a = config3.face.description) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face.description) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime5; - if (config3.skipAllowed && skipFrame && skipTime && lastCount2 === count2 && ((_c = last4 == null ? void 0 : last4[idx]) == null ? void 0 : _c.age) > 0 && ((_d = last4 == null ? void 0 : last4[idx]) == null ? void 0 : _d.genderScore) > 0) { - skipped5++; - return last4[idx]; - } - skipped5 = 0; - return new Promise(async (resolve) => { - var _a2; - if ((_a2 = config3.face.description) == null ? void 0 : _a2.enabled) { - const enhanced = enhance(image28); - const resT = model9 == null ? void 0 : model9.execute(enhanced); - lastTime5 = now(); - tf17.dispose(enhanced); - const genderT = resT.find((t2) => t2.shape[1] === 1); - const gender2 = await genderT.data(); - const confidence = Math.trunc(200 * Math.abs(gender2[0] - 0.5)) / 100; - if (confidence > (config3.face.description.minConfidence || 0)) { - obj.gender = gender2[0] <= 0.5 ? "female" : "male"; - obj.genderScore = Math.min(0.99, confidence); - } - const argmax = tf17.argMax(resT.find((t2) => t2.shape[1] === 100), 1); - const ageIdx = (await argmax.data())[0]; - tf17.dispose(argmax); - const ageT = resT.find((t2) => t2.shape[1] === 100); - const all2 = await ageT.data(); - obj.age = Math.round(all2[ageIdx - 1] > all2[ageIdx + 1] ? 10 * ageIdx - 100 * all2[ageIdx - 1] : 10 * ageIdx + 100 * all2[ageIdx + 1]) / 10; - if (Number.isNaN(gender2[0]) || Number.isNaN(all2[0])) - log("faceres error:", { model: model9, result: resT }); - const desc = resT.find((t2) => t2.shape[1] === 1024); - const descriptor = desc ? await desc.data() : []; - obj.descriptor = Array.from(descriptor); - resT.forEach((t2) => tf17.dispose(t2)); - } - last4[idx] = obj; - lastCount2 = count2; - resolve(obj); - }); -} - -// src/face/mask.ts -var expandFact = 0.1; -var alpha = 0.5; -function insidePoly(x, y, polygon) { - let inside = false; - let j = polygon.length - 1; - for (let i = 0; i < polygon.length; j = i++) { - if (polygon[i].y > y !== polygon[j].y > y && x < (polygon[j].x - polygon[i].x) * (y - polygon[i].y) / (polygon[j].y - polygon[i].y) + polygon[i].x) - inside = !inside; - } - return inside; -} -async function mask(face4) { - if (!face4.tensor) - return face4.tensor; - if (!face4.mesh || face4.mesh.length < 100) - return face4.tensor; - const width = face4.tensor.shape[2] || 0; - const height = face4.tensor.shape[1] || 0; - const buffer = await face4.tensor.buffer(); - let silhouette = []; - for (const pt of meshAnnotations.silhouette) - silhouette.push({ x: (face4.mesh[pt][0] - face4.box[0]) / face4.box[2], y: (face4.mesh[pt][1] - face4.box[1]) / face4.box[3] }); - if (expandFact && expandFact > 0) - silhouette = silhouette.map((pt) => ({ x: pt.x > 0.5 ? pt.x + expandFact : pt.x - expandFact, y: pt.y > 0.5 ? pt.y + expandFact : pt.y - expandFact })); - for (let x = 0; x < width; x++) { - for (let y = 0; y < height; y++) { - const inside = insidePoly(x / width, y / width, silhouette); - if (!inside) { - buffer.set(alpha * buffer.get(0, y, x, 0), 0, y, x, 0); - buffer.set(alpha * buffer.get(0, y, x, 1), 0, y, x, 1); - buffer.set(alpha * buffer.get(0, y, x, 2), 0, y, x, 2); - } - } - } - const output = buffer.toTensor(); - return output; -} - -// src/face/antispoof.ts -var tf18 = __toESM(require_tfjs_esm()); -var model10; -var cached = []; -var skipped6 = Number.MAX_SAFE_INTEGER; -var lastCount3 = 0; -var lastTime6 = 0; -async function load8(config3) { - var _a; - if (env.initial) - model10 = null; - if (!model10) - model10 = await loadModel((_a = config3.face.antispoof) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model10["modelUrl"]); - return model10; -} -async function predict7(image28, config3, idx, count2) { - var _a, _b; - if (!(model10 == null ? void 0 : model10["executor"])) - return 0; - const skipTime = (((_a = config3.face.antispoof) == null ? void 0 : _a.skipTime) || 0) > now() - lastTime6; - const skipFrame = skipped6 < (((_b = config3.face.antispoof) == null ? void 0 : _b.skipFrames) || 0); - if (config3.skipAllowed && skipTime && skipFrame && lastCount3 === count2 && cached[idx]) { - skipped6++; - return cached[idx]; - } - skipped6 = 0; - return new Promise(async (resolve) => { - const resize = tf18.image.resizeBilinear(image28, [(model10 == null ? void 0 : model10.inputs[0].shape) ? model10.inputs[0].shape[2] : 0, (model10 == null ? void 0 : model10.inputs[0].shape) ? model10.inputs[0].shape[1] : 0], false); - const res = model10 == null ? void 0 : model10.execute(resize); - const num = (await res.data())[0]; - cached[idx] = Math.round(100 * num) / 100; - lastCount3 = count2; - lastTime6 = now(); - tf18.dispose([resize, res]); - resolve(cached[idx]); - }); -} - -// src/face/liveness.ts -var tf19 = __toESM(require_tfjs_esm()); -var model11; -var cached2 = []; -var skipped7 = Number.MAX_SAFE_INTEGER; -var lastCount4 = 0; -var lastTime7 = 0; -async function load9(config3) { - var _a; - if (env.initial) - model11 = null; - if (!model11) - model11 = await loadModel((_a = config3.face.liveness) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model11["modelUrl"]); - return model11; -} -async function predict8(image28, config3, idx, count2) { - var _a, _b; - if (!(model11 == null ? void 0 : model11["executor"])) - return 0; - const skipTime = (((_a = config3.face.liveness) == null ? void 0 : _a.skipTime) || 0) > now() - lastTime7; - const skipFrame = skipped7 < (((_b = config3.face.liveness) == null ? void 0 : _b.skipFrames) || 0); - if (config3.skipAllowed && skipTime && skipFrame && lastCount4 === count2 && cached2[idx]) { - skipped7++; - return cached2[idx]; - } - skipped7 = 0; - return new Promise(async (resolve) => { - const resize = tf19.image.resizeBilinear(image28, [(model11 == null ? void 0 : model11.inputs[0].shape) ? model11.inputs[0].shape[2] : 0, (model11 == null ? void 0 : model11.inputs[0].shape) ? model11.inputs[0].shape[1] : 0], false); - const res = model11 == null ? void 0 : model11.execute(resize); - const num = (await res.data())[0]; - cached2[idx] = Math.round(100 * num) / 100; - lastCount4 = count2; - lastTime7 = now(); - tf19.dispose([resize, res]); - resolve(cached2[idx]); - }); -} - -// src/gear/gear.ts -var tf20 = __toESM(require_tfjs_esm()); -var model12; -var last5 = []; -var raceNames = ["white", "black", "asian", "indian", "other"]; -var ageWeights = [15, 23, 28, 35.5, 45.5, 55.5, 65]; -var lastCount5 = 0; -var lastTime8 = 0; -var skipped8 = Number.MAX_SAFE_INTEGER; -async function load10(config3) { - var _a; - if (env.initial) - model12 = null; - if (!model12) - model12 = await loadModel((_a = config3.face.gear) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model12["modelUrl"]); - return model12; -} -async function predict9(image28, config3, idx, count2) { - var _a, _b; - if (!model12) - return { age: 0, gender: "unknown", genderScore: 0, race: [] }; - const skipFrame = skipped8 < (((_a = config3.face.gear) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face.gear) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime8; - if (config3.skipAllowed && skipTime && skipFrame && lastCount5 === count2 && last5[idx]) { - skipped8++; - return last5[idx]; - } - skipped8 = 0; - return new Promise(async (resolve) => { - var _a2, _b2; - if (!(model12 == null ? void 0 : model12.inputs[0].shape)) - return; - const t2 = {}; - const box = [[0, 0.1, 0.9, 0.9]]; - t2.resize = tf20.image.cropAndResize(image28, box, [0], [model12.inputs[0].shape[2], model12.inputs[0].shape[1]]); - const obj = { age: 0, gender: "unknown", genderScore: 0, race: [] }; - if ((_a2 = config3.face.gear) == null ? void 0 : _a2.enabled) - [t2.age, t2.gender, t2.race] = model12.execute(t2.resize, ["age_output", "gender_output", "race_output"]); - const gender2 = await t2.gender.data(); - obj.gender = gender2[0] > gender2[1] ? "male" : "female"; - obj.genderScore = Math.round(100 * (gender2[0] > gender2[1] ? gender2[0] : gender2[1])) / 100; - const race = await t2.race.data(); - for (let i = 0; i < race.length; i++) { - if (race[i] > (((_b2 = config3.face.gear) == null ? void 0 : _b2.minConfidence) || 0.2)) - obj.race.push({ score: Math.round(100 * race[i]) / 100, race: raceNames[i] }); - } - obj.race.sort((a, b) => b.score - a.score); - const ageDistribution = Array.from(await t2.age.data()); - const ageSorted = ageDistribution.map((a, i) => [ageWeights[i], a]).sort((a, b) => b[1] - a[1]); - let age2 = ageSorted[0][0]; - for (let i = 1; i < ageSorted.length; i++) - age2 += ageSorted[i][1] * (ageSorted[i][0] - age2); - obj.age = Math.round(10 * age2) / 10; - Object.keys(t2).forEach((tensor6) => tf20.dispose(t2[tensor6])); - last5[idx] = obj; - lastCount5 = count2; - lastTime8 = now(); - resolve(obj); - }); -} - -// src/gear/ssrnet-age.ts -var tf21 = __toESM(require_tfjs_esm()); -var model13; -var last6 = []; -var lastCount6 = 0; -var lastTime9 = 0; -var skipped9 = Number.MAX_SAFE_INTEGER; -async function load11(config3) { - if (env.initial) - model13 = null; - if (!model13) - model13 = await loadModel(config3.face["ssrnet"].modelPathAge); - else if (config3.debug) - log("cached model:", model13["modelUrl"]); - return model13; -} -async function predict10(image28, config3, idx, count2) { - var _a, _b, _c, _d; - if (!model13) - return { age: 0 }; - const skipFrame = skipped9 < (((_a = config3.face["ssrnet"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["ssrnet"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime9; - if (config3.skipAllowed && skipFrame && skipTime && lastCount6 === count2 && ((_c = last6[idx]) == null ? void 0 : _c.age) && ((_d = last6[idx]) == null ? void 0 : _d.age) > 0) { - skipped9++; - return last6[idx]; - } - skipped9 = 0; - return new Promise(async (resolve) => { - var _a2; - if (!(model13 == null ? void 0 : model13.inputs) || !model13.inputs[0] || !model13.inputs[0].shape) - return; - const t2 = {}; - t2.resize = tf21.image.resizeBilinear(image28, [model13.inputs[0].shape[2], model13.inputs[0].shape[1]], false); - t2.enhance = tf21.mul(t2.resize, constants.tf255); - const obj = { age: 0 }; - if ((_a2 = config3.face["ssrnet"]) == null ? void 0 : _a2.enabled) - t2.age = model13.execute(t2.enhance); - if (t2.age) { - const data = await t2.age.data(); - obj.age = Math.trunc(10 * data[0]) / 10; - } - Object.keys(t2).forEach((tensor6) => tf21.dispose(t2[tensor6])); - last6[idx] = obj; - lastCount6 = count2; - lastTime9 = now(); - resolve(obj); - }); -} - -// src/gear/ssrnet-gender.ts -var tf22 = __toESM(require_tfjs_esm()); -var model14; -var last7 = []; -var lastCount7 = 0; -var lastTime10 = 0; -var skipped10 = Number.MAX_SAFE_INTEGER; -var rgb = [0.2989, 0.587, 0.114]; -async function load12(config3) { - var _a; - if (env.initial) - model14 = null; - if (!model14) - model14 = await loadModel((_a = config3.face["ssrnet"]) == null ? void 0 : _a.modelPathGender); - else if (config3.debug) - log("cached model:", model14["modelUrl"]); - return model14; -} -async function predict11(image28, config3, idx, count2) { - var _a, _b, _c, _d; - if (!model14) - return { gender: "unknown", genderScore: 0 }; - const skipFrame = skipped10 < (((_a = config3.face["ssrnet"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["ssrnet"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime10; - if (config3.skipAllowed && skipFrame && skipTime && lastCount7 === count2 && ((_c = last7[idx]) == null ? void 0 : _c.gender) && ((_d = last7[idx]) == null ? void 0 : _d.genderScore) > 0) { - skipped10++; - return last7[idx]; - } - skipped10 = 0; - return new Promise(async (resolve) => { - var _a2; - if (!(model14 == null ? void 0 : model14.inputs[0].shape)) - return; - const t2 = {}; - t2.resize = tf22.image.resizeBilinear(image28, [model14.inputs[0].shape[2], model14.inputs[0].shape[1]], false); - t2.enhance = tf22.tidy(() => { - const [red, green, blue] = tf22.split(t2.resize, 3, 3); - const redNorm = tf22.mul(red, rgb[0]); - const greenNorm = tf22.mul(green, rgb[1]); - const blueNorm = tf22.mul(blue, rgb[2]); - const grayscale = tf22.addN([redNorm, greenNorm, blueNorm]); - const normalize2 = tf22.mul(tf22.sub(grayscale, constants.tf05), 2); - return normalize2; - }); - const obj = { gender: "unknown", genderScore: 0 }; - if ((_a2 = config3.face["ssrnet"]) == null ? void 0 : _a2.enabled) - t2.gender = model14.execute(t2.enhance); - const data = await t2.gender.data(); - obj.gender = data[0] > data[1] ? "female" : "male"; - obj.genderScore = data[0] > data[1] ? Math.trunc(100 * data[0]) / 100 : Math.trunc(100 * data[1]) / 100; - Object.keys(t2).forEach((tensor6) => tf22.dispose(t2[tensor6])); - last7[idx] = obj; - lastCount7 = count2; - lastTime10 = now(); - resolve(obj); - }); -} - -// src/face/mobilefacenet.ts -var tf23 = __toESM(require_tfjs_esm()); -var model15; -var last8 = []; -var lastCount8 = 0; -var lastTime11 = 0; -var skipped11 = Number.MAX_SAFE_INTEGER; -async function load13(config3) { - var _a; - if (env.initial) - model15 = null; - if (!model15) - model15 = await loadModel((_a = config3.face["mobilefacenet"]) == null ? void 0 : _a.modelPath); - else if (config3.debug) - log("cached model:", model15["modelUrl"]); - return model15; -} -async function predict12(input, config3, idx, count2) { - var _a, _b; - if (!(model15 == null ? void 0 : model15["executor"])) - return []; - const skipFrame = skipped11 < (((_a = config3.face["mobilefacenet"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["mobilefacenet"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime11; - if (config3.skipAllowed && skipTime && skipFrame && lastCount8 === count2 && last8[idx]) { - skipped11++; - return last8[idx]; - } - return new Promise(async (resolve) => { - var _a2; - let data = []; - if (((_a2 = config3.face["mobilefacenet"]) == null ? void 0 : _a2.enabled) && (model15 == null ? void 0 : model15.inputs[0].shape)) { - const t2 = {}; - t2.crop = tf23.image.resizeBilinear(input, [model15.inputs[0].shape[2], model15.inputs[0].shape[1]], false); - t2.data = model15.execute(t2.crop); - const output = await t2.data.data(); - data = Array.from(output); - Object.keys(t2).forEach((tensor6) => tf23.dispose(t2[tensor6])); - } - last8[idx] = data; - lastCount8 = count2; - lastTime11 = now(); - resolve(data); - }); -} - -// src/face/insightface.ts -var tf24 = __toESM(require_tfjs_esm()); -var model16; -var last9 = []; -var lastCount9 = 0; -var lastTime12 = 0; -var skipped12 = Number.MAX_SAFE_INTEGER; -async function load14(config3) { - if (env.initial) - model16 = null; - if (!model16) - model16 = await loadModel(config3.face["insightface"].modelPath); - else if (config3.debug) - log("cached model:", model16["modelUrl"]); - return model16; -} -async function predict13(input, config3, idx, count2) { - var _a, _b; - if (!(model16 == null ? void 0 : model16["executor"])) - return []; - const skipFrame = skipped12 < (((_a = config3.face["insightface"]) == null ? void 0 : _a.skipFrames) || 0); - const skipTime = (((_b = config3.face["insightface"]) == null ? void 0 : _b.skipTime) || 0) > now() - lastTime12; - if (config3.skipAllowed && skipTime && skipFrame && lastCount9 === count2 && last9[idx]) { - skipped12++; - return last9[idx]; - } - return new Promise(async (resolve) => { - var _a2; - let data = []; - if (((_a2 = config3.face["insightface"]) == null ? void 0 : _a2.enabled) && (model16 == null ? void 0 : model16.inputs[0].shape)) { - const t2 = {}; - t2.crop = tf24.image.resizeBilinear(input, [model16.inputs[0].shape[2], model16.inputs[0].shape[1]], false); - t2.data = model16.execute(t2.crop); - const output = await t2.data.data(); - data = Array.from(output); - Object.keys(t2).forEach((tensor6) => tf24.dispose(t2[tensor6])); - } - last9[idx] = data; - lastCount9 = count2; - lastTime12 = now(); - resolve(data); - }); -} - -// src/face/angles.ts -var calculateGaze = (face4) => { - const radians = (pt1, pt2) => Math.atan2(pt1[1] - pt2[1], pt1[0] - pt2[0]); - if (!face4.annotations.rightEyeIris || !face4.annotations.leftEyeIris) - return { bearing: 0, strength: 0 }; - const offsetIris = [0, -0.1]; - const eyeRatio = 1; - const left = (face4.mesh[33][2] || 0) > (face4.mesh[263][2] || 0); - const irisCenter = left ? face4.mesh[473] : face4.mesh[468]; - const eyeCenter = left ? [(face4.mesh[133][0] + face4.mesh[33][0]) / 2, (face4.mesh[133][1] + face4.mesh[33][1]) / 2] : [(face4.mesh[263][0] + face4.mesh[362][0]) / 2, (face4.mesh[263][1] + face4.mesh[362][1]) / 2]; - const eyeSize = left ? [face4.mesh[133][0] - face4.mesh[33][0], face4.mesh[23][1] - face4.mesh[27][1]] : [face4.mesh[263][0] - face4.mesh[362][0], face4.mesh[253][1] - face4.mesh[257][1]]; - const eyeDiff = [ - (eyeCenter[0] - irisCenter[0]) / eyeSize[0] - offsetIris[0], - eyeRatio * (irisCenter[1] - eyeCenter[1]) / eyeSize[1] - offsetIris[1] - ]; - let strength = Math.sqrt(eyeDiff[0] * eyeDiff[0] + eyeDiff[1] * eyeDiff[1]); - strength = Math.min(strength, face4.boxRaw[2] / 2, face4.boxRaw[3] / 2); - const bearing = (radians([0, 0], eyeDiff) + Math.PI / 2) % Math.PI; - return { bearing, strength }; -}; -var calculateFaceAngle = (face4, imageSize) => { - const normalize2 = (v) => { - const length = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); - v[0] /= length; - v[1] /= length; - v[2] /= length; - return v; - }; - const subVectors = (a, b) => { - const x = a[0] - b[0]; - const y = a[1] - b[1]; - const z = a[2] - b[2]; - return [x, y, z]; - }; - const crossVectors = (a, b) => { - const x = a[1] * b[2] - a[2] * b[1]; - const y = a[2] * b[0] - a[0] * b[2]; - const z = a[0] * b[1] - a[1] * b[0]; - return [x, y, z]; - }; - const rotationMatrixToEulerAngle = (r) => { - const [r00, _r01, _r02, r10, r11, r12, r20, r21, r22] = r; - let thetaX; - let thetaY; - let thetaZ; - if (r10 < 1) { - if (r10 > -1) { - thetaZ = Math.asin(r10); - thetaY = Math.atan2(-r20, r00); - thetaX = Math.atan2(-r12, r11); - } else { - thetaZ = -Math.PI / 2; - thetaY = -Math.atan2(r21, r22); - thetaX = 0; - } - } else { - thetaZ = Math.PI / 2; - thetaY = Math.atan2(r21, r22); - thetaX = 0; - } - if (Number.isNaN(thetaX)) - thetaX = 0; - if (Number.isNaN(thetaY)) - thetaY = 0; - if (Number.isNaN(thetaZ)) - thetaZ = 0; - return { pitch: 2 * -thetaX, yaw: 2 * -thetaY, roll: 2 * -thetaZ }; - }; - const mesh = face4.meshRaw; - if (!mesh || mesh.length < 300) - return { angle: { pitch: 0, yaw: 0, roll: 0 }, matrix: [1, 0, 0, 0, 1, 0, 0, 0, 1], gaze: { bearing: 0, strength: 0 } }; - const size2 = Math.max(face4.boxRaw[2] * imageSize[0], face4.boxRaw[3] * imageSize[1]) / 1.5; - const pts = [mesh[10], mesh[152], mesh[234], mesh[454]].map((pt) => [pt[0] * imageSize[0] / size2, pt[1] * imageSize[1] / size2, pt[2]]); - const yAxis = normalize2(subVectors(pts[1], pts[0])); - let xAxis = normalize2(subVectors(pts[3], pts[2])); - const zAxis = normalize2(crossVectors(xAxis, yAxis)); - xAxis = crossVectors(yAxis, zAxis); - const matrix = [ - xAxis[0], - xAxis[1], - xAxis[2], - yAxis[0], - yAxis[1], - yAxis[2], - zAxis[0], - zAxis[1], - zAxis[2] - ]; - const angle = rotationMatrixToEulerAngle(matrix); - const gaze = mesh.length === 478 ? calculateGaze(face4) : { bearing: 0, strength: 0 }; - return { angle, matrix, gaze }; -}; - -// src/face/anthropometry.ts -function calculateCameraDistance(face4, width) { - const f = face4 == null ? void 0 : face4.annotations; - if (!f) - return 0; - const irisSize = Math.max(Math.abs(f.leftEyeIris[3][0] - f.leftEyeIris[1][0]), Math.abs(f.rightEyeIris[3][0] - f.rightEyeIris[1][0])) / width; - const cameraDistance = Math.round(1.17 / irisSize) / 100; - return cameraDistance; -} - -// src/face/face.ts -var detectFace = async (instance, input) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w; - let timeStamp = now(); - let ageRes; - let gearRes; - let genderRes; - let emotionRes; - let mobilefacenetRes; - let insightfaceRes; - let antispoofRes; - let livenessRes; - let descRes; - const faceRes = []; - instance.state = "run:face"; - const faces = await predict4(input, instance.config); - instance.performance.face = env.perfadd ? (instance.performance.face || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - if (!input.shape || input.shape.length !== 4) - return []; - if (!faces) - return []; - for (let i = 0; i < faces.length; i++) { - instance.analyze("Get Face"); - if (!faces[i].tensor || faces[i].tensor.isDisposedInternal) { - log("Face object is disposed:", faces[i].tensor); - continue; - } - if ((_a = instance.config.face.detector) == null ? void 0 : _a.mask) { - const masked = await mask(faces[i]); - tf25.dispose(faces[i].tensor); - if (masked) - faces[i].tensor = masked; - } - const rotation = faces[i].mesh && faces[i].mesh.length > 200 ? calculateFaceAngle(faces[i], [input.shape[2], input.shape[1]]) : null; - instance.analyze("Start Emotion:"); - if (instance.config.async) { - emotionRes = ((_b = instance.config.face.emotion) == null ? void 0 : _b.enabled) ? predict5(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : []; - } else { - instance.state = "run:emotion"; - timeStamp = now(); - emotionRes = ((_c = instance.config.face.emotion) == null ? void 0 : _c.enabled) ? await predict5(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : []; - instance.performance.emotion = env.perfadd ? (instance.performance.emotion || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End Emotion:"); - instance.analyze("Start AntiSpoof:"); - if (instance.config.async) { - antispoofRes = ((_d = instance.config.face.antispoof) == null ? void 0 : _d.enabled) ? predict7(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : 0; - } else { - instance.state = "run:antispoof"; - timeStamp = now(); - antispoofRes = ((_e = instance.config.face.antispoof) == null ? void 0 : _e.enabled) ? await predict7(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : 0; - instance.performance.antispoof = env.perfadd ? (instance.performance.antispoof || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End AntiSpoof:"); - instance.analyze("Start Liveness:"); - if (instance.config.async) { - livenessRes = ((_f = instance.config.face.liveness) == null ? void 0 : _f.enabled) ? predict8(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : 0; - } else { - instance.state = "run:liveness"; - timeStamp = now(); - livenessRes = ((_g = instance.config.face.liveness) == null ? void 0 : _g.enabled) ? await predict8(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : 0; - instance.performance.liveness = env.perfadd ? (instance.performance.antispoof || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End Liveness:"); - instance.analyze("Start GEAR:"); - if (instance.config.async) { - gearRes = ((_h = instance.config.face.gear) == null ? void 0 : _h.enabled) ? predict9(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:gear"; - timeStamp = now(); - gearRes = ((_i = instance.config.face.gear) == null ? void 0 : _i.enabled) ? await predict9(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - instance.performance.gear = Math.trunc(now() - timeStamp); - } - instance.analyze("End GEAR:"); - instance.analyze("Start SSRNet:"); - if (instance.config.async) { - ageRes = ((_j = instance.config.face["ssrnet"]) == null ? void 0 : _j.enabled) ? predict10(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - genderRes = ((_k = instance.config.face["ssrnet"]) == null ? void 0 : _k.enabled) ? predict11(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:ssrnet"; - timeStamp = now(); - ageRes = ((_l = instance.config.face["ssrnet"]) == null ? void 0 : _l.enabled) ? await predict10(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - genderRes = ((_m = instance.config.face["ssrnet"]) == null ? void 0 : _m.enabled) ? await predict11(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - instance.performance.ssrnet = Math.trunc(now() - timeStamp); - } - instance.analyze("End SSRNet:"); - instance.analyze("Start MobileFaceNet:"); - if (instance.config.async) { - mobilefacenetRes = ((_n = instance.config.face["mobilefacenet"]) == null ? void 0 : _n.enabled) ? predict12(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:mobilefacenet"; - timeStamp = now(); - mobilefacenetRes = ((_o = instance.config.face["mobilefacenet"]) == null ? void 0 : _o.enabled) ? await predict12(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - instance.performance.mobilefacenet = Math.trunc(now() - timeStamp); - } - instance.analyze("End MobileFaceNet:"); - instance.analyze("Start InsightFace:"); - if (instance.config.async) { - insightfaceRes = ((_p = instance.config.face["insightface"]) == null ? void 0 : _p.enabled) ? predict13(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - } else { - instance.state = "run:mobilefacenet"; - timeStamp = now(); - insightfaceRes = ((_q = instance.config.face["insightface"]) == null ? void 0 : _q.enabled) ? await predict13(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length) : null; - instance.performance.mobilefacenet = Math.trunc(now() - timeStamp); - } - instance.analyze("End InsightFace:"); - instance.analyze("Start Description:"); - if (instance.config.async) { - descRes = predict6(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length); - } else { - instance.state = "run:description"; - timeStamp = now(); - descRes = await predict6(faces[i].tensor || tf25.tensor([]), instance.config, i, faces.length); - instance.performance.description = env.perfadd ? (instance.performance.description || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - instance.analyze("End Description:"); - if (instance.config.async) { - [ageRes, genderRes, emotionRes, mobilefacenetRes, insightfaceRes, descRes, gearRes, antispoofRes, livenessRes] = await Promise.all([ageRes, genderRes, emotionRes, mobilefacenetRes, insightfaceRes, descRes, gearRes, antispoofRes, livenessRes]); - } - instance.analyze("Finish Face:"); - if (((_r = instance.config.face["ssrnet"]) == null ? void 0 : _r.enabled) && ageRes && genderRes) { - descRes = { - ...descRes, - age: ageRes.age, - gender: genderRes.gender, - genderScore: genderRes.genderScore - }; - } - if (((_s = instance.config.face.gear) == null ? void 0 : _s.enabled) && gearRes) { - descRes = { - ...descRes, - age: gearRes.age, - gender: gearRes.gender, - genderScore: gearRes.genderScore, - race: gearRes.race - }; - } - if (((_t = instance.config.face["mobilefacenet"]) == null ? void 0 : _t.enabled) && mobilefacenetRes) { - descRes.descriptor = mobilefacenetRes; - } - if (((_u = instance.config.face["insightface"]) == null ? void 0 : _u.enabled) && insightfaceRes) { - descRes.descriptor = insightfaceRes; - } - const irisSize = ((_v = instance.config.face.iris) == null ? void 0 : _v.enabled) ? calculateCameraDistance(faces[i], input.shape[2]) : 0; - const tensor6 = ((_w = instance.config.face.detector) == null ? void 0 : _w.return) ? tf25.squeeze(faces[i].tensor) : null; - tf25.dispose(faces[i].tensor); - if (faces[i].tensor) - delete faces[i].tensor; - const res = { - ...faces[i], - id: i - }; - if (descRes.age) - res.age = descRes.age; - if (descRes.gender) - res.gender = descRes.gender; - if (descRes.genderScore) - res.genderScore = descRes.genderScore; - if (descRes.descriptor) - res.embedding = descRes.descriptor; - if (descRes.race) - res.race = descRes.race; - if (emotionRes) - res.emotion = emotionRes; - if (antispoofRes) - res.real = antispoofRes; - if (livenessRes) - res.live = livenessRes; - if (irisSize > 0) - res.distance = irisSize; - if (rotation) - res.rotation = rotation; - if (tensor6) - res.tensor = tensor6; - faceRes.push(res); - instance.analyze("End Face"); - } - instance.analyze("End FaceMesh:"); - if (instance.config.async) { - if (instance.performance.face) - delete instance.performance.face; - if (instance.performance.age) - delete instance.performance.age; - if (instance.performance.gender) - delete instance.performance.gender; - if (instance.performance.emotion) - delete instance.performance.emotion; - } - return faceRes; -}; - -// src/hand/fingerdef.ts -var Finger = { - thumb: 0, - index: 1, - middle: 2, - ring: 3, - pinky: 4, - all: [0, 1, 2, 3, 4], - nameMapping: { 0: "thumb", 1: "index", 2: "middle", 3: "ring", 4: "pinky" }, - pointsMapping: { - 0: [[0, 1], [1, 2], [2, 3], [3, 4]], - 1: [[0, 5], [5, 6], [6, 7], [7, 8]], - 2: [[0, 9], [9, 10], [10, 11], [11, 12]], - 3: [[0, 13], [13, 14], [14, 15], [15, 16]], - 4: [[0, 17], [17, 18], [18, 19], [19, 20]] - }, - getName: (value) => Finger.nameMapping[value], - getPoints: (value) => Finger.pointsMapping[value] -}; -var FingerCurl = { - none: 0, - half: 1, - full: 2, - nameMapping: { 0: "none", 1: "half", 2: "full" }, - getName: (value) => FingerCurl.nameMapping[value] -}; -var FingerDirection = { - verticalUp: 0, - verticalDown: 1, - horizontalLeft: 2, - horizontalRight: 3, - diagonalUpRight: 4, - diagonalUpLeft: 5, - diagonalDownRight: 6, - diagonalDownLeft: 7, - nameMapping: { 0: "verticalUp", 1: "verticalDown", 2: "horizontalLeft", 3: "horizontalRight", 4: "diagonalUpRight", 5: "diagonalUpLeft", 6: "diagonalDownRight", 7: "diagonalDownLeft" }, - getName: (value) => FingerDirection.nameMapping[value] -}; -var FingerGesture = class { - constructor(name) { - __publicField(this, "name"); - __publicField(this, "curls"); - __publicField(this, "directions"); - __publicField(this, "weights"); - __publicField(this, "weightsRelative"); - this.name = name; - this.curls = {}; - this.directions = {}; - this.weights = [1, 1, 1, 1, 1]; - this.weightsRelative = [1, 1, 1, 1, 1]; - } - curl(finger, curl, confidence) { - if (typeof this.curls[finger] === "undefined") - this.curls[finger] = []; - this.curls[finger].push([curl, confidence]); - } - direction(finger, position, confidence) { - if (!this.directions[finger]) - this.directions[finger] = []; - this.directions[finger].push([position, confidence]); - } - weight(finger, weight) { - this.weights[finger] = weight; - const total = this.weights.reduce((a, b) => a + b, 0); - this.weightsRelative = this.weights.map((el) => el * 5 / total); - } - matchAgainst(detectedCurls, detectedDirections) { - let confidence = 0; - for (const fingerIdx in detectedCurls) { - const detectedCurl = detectedCurls[fingerIdx]; - const expectedCurls = this.curls[fingerIdx]; - if (typeof expectedCurls === "undefined") { - confidence += this.weightsRelative[fingerIdx]; - continue; - } - for (const [expectedCurl, score] of expectedCurls) { - if (detectedCurl === expectedCurl) { - confidence += score * this.weightsRelative[fingerIdx]; - break; - } - } - } - for (const fingerIdx in detectedDirections) { - const detectedDirection = detectedDirections[fingerIdx]; - const expectedDirections = this.directions[fingerIdx]; - if (typeof expectedDirections === "undefined") { - confidence += this.weightsRelative[fingerIdx]; - continue; - } - for (const [expectedDirection, score] of expectedDirections) { - if (detectedDirection === expectedDirection) { - confidence += score * this.weightsRelative[fingerIdx]; - break; - } - } - } - return confidence / 10; - } -}; - -// src/hand/fingergesture.ts -var { thumb, index, middle, ring, pinky } = Finger; -var { none, half, full } = FingerCurl; -var { verticalUp, verticalDown, horizontalLeft, horizontalRight, diagonalUpRight, diagonalUpLeft, diagonalDownRight, diagonalDownLeft } = FingerDirection; -var ThumbsUp = new FingerGesture("thumbs up"); -ThumbsUp.curl(thumb, none, 1); -ThumbsUp.direction(thumb, verticalUp, 1); -ThumbsUp.direction(thumb, diagonalUpLeft, 0.25); -ThumbsUp.direction(thumb, diagonalUpRight, 0.25); -for (const finger of [Finger.index, Finger.middle, Finger.ring, Finger.pinky]) { - ThumbsUp.curl(finger, full, 1); - ThumbsUp.direction(finger, horizontalLeft, 1); - ThumbsUp.direction(finger, horizontalRight, 1); -} -var Victory = new FingerGesture("victory"); -Victory.curl(thumb, half, 0.5); -Victory.curl(thumb, none, 0.5); -Victory.direction(thumb, verticalUp, 1); -Victory.direction(thumb, diagonalUpLeft, 1); -Victory.curl(index, none, 1); -Victory.direction(index, verticalUp, 0.75); -Victory.direction(index, diagonalUpLeft, 1); -Victory.curl(middle, none, 1); -Victory.direction(middle, verticalUp, 1); -Victory.direction(middle, diagonalUpLeft, 0.75); -Victory.curl(ring, full, 1); -Victory.direction(ring, verticalUp, 0.2); -Victory.direction(ring, diagonalUpLeft, 1); -Victory.direction(ring, horizontalLeft, 0.2); -Victory.curl(pinky, full, 1); -Victory.direction(pinky, verticalUp, 0.2); -Victory.direction(pinky, diagonalUpLeft, 1); -Victory.direction(pinky, horizontalLeft, 0.2); -Victory.weight(index, 2); -Victory.weight(middle, 2); -var Point = new FingerGesture("point"); -Point.curl(thumb, full, 1); -Point.curl(index, none, 0.5); -Point.curl(middle, full, 0.5); -Point.curl(ring, full, 0.5); -Point.curl(pinky, full, 0.5); -Point.weight(index, 2); -Point.weight(middle, 2); -var MiddleFinger = new FingerGesture("middle finger"); -MiddleFinger.curl(thumb, none, 1); -MiddleFinger.curl(index, full, 0.5); -MiddleFinger.curl(middle, full, 0.5); -MiddleFinger.curl(ring, full, 0.5); -MiddleFinger.curl(pinky, full, 0.5); -MiddleFinger.weight(index, 2); -MiddleFinger.weight(middle, 2); -var OpenPalm = new FingerGesture("open palm"); -OpenPalm.curl(thumb, none, 0.75); -OpenPalm.curl(index, none, 0.75); -OpenPalm.curl(middle, none, 0.75); -OpenPalm.curl(ring, none, 0.75); -OpenPalm.curl(pinky, none, 0.75); -var fingergesture_default = [ThumbsUp, Victory, Point, MiddleFinger, OpenPalm]; - -// src/hand/fingerpose.ts -var minConfidence = 0.7; -var options3 = { - HALF_CURL_START_LIMIT: 60, - NO_CURL_START_LIMIT: 130, - DISTANCE_VOTE_POWER: 1.1, - SINGLE_ANGLE_VOTE_POWER: 0.9, - TOTAL_ANGLE_VOTE_POWER: 1.6 -}; -function calculateSlope(point1x, point1y, point2x, point2y) { - const value = (point1y - point2y) / (point1x - point2x); - let slope = Math.atan(value) * 180 / Math.PI; - if (slope <= 0) - slope = -slope; - else if (slope > 0) - slope = 180 - slope; - return slope; -} -function getSlopes(point1, point2) { - if (!point1 || !point2) - return [0, 0]; - const slopeXY = calculateSlope(point1[0], point1[1], point2[0], point2[1]); - if (point1.length === 2) - return slopeXY; - const slopeYZ = calculateSlope(point1[1], point1[2], point2[1], point2[2]); - return [slopeXY, slopeYZ]; -} -function angleOrientationAt(angle, weightageAt = 1) { - let isVertical = 0; - let isDiagonal = 0; - let isHorizontal = 0; - if (angle >= 75 && angle <= 105) - isVertical = 1 * weightageAt; - else if (angle >= 25 && angle <= 155) - isDiagonal = 1 * weightageAt; - else - isHorizontal = 1 * weightageAt; - return [isVertical, isDiagonal, isHorizontal]; -} -function estimateFingerCurl(startPoint, midPoint, endPoint) { - const start_mid_x_dist = startPoint[0] - midPoint[0]; - const start_end_x_dist = startPoint[0] - endPoint[0]; - const mid_end_x_dist = midPoint[0] - endPoint[0]; - const start_mid_y_dist = startPoint[1] - midPoint[1]; - const start_end_y_dist = startPoint[1] - endPoint[1]; - const mid_end_y_dist = midPoint[1] - endPoint[1]; - const start_mid_z_dist = startPoint[2] - midPoint[2]; - const start_end_z_dist = startPoint[2] - endPoint[2]; - const mid_end_z_dist = midPoint[2] - endPoint[2]; - const start_mid_dist = Math.sqrt(start_mid_x_dist * start_mid_x_dist + start_mid_y_dist * start_mid_y_dist + start_mid_z_dist * start_mid_z_dist); - const start_end_dist = Math.sqrt(start_end_x_dist * start_end_x_dist + start_end_y_dist * start_end_y_dist + start_end_z_dist * start_end_z_dist); - const mid_end_dist = Math.sqrt(mid_end_x_dist * mid_end_x_dist + mid_end_y_dist * mid_end_y_dist + mid_end_z_dist * mid_end_z_dist); - let cos_in = (mid_end_dist * mid_end_dist + start_mid_dist * start_mid_dist - start_end_dist * start_end_dist) / (2 * mid_end_dist * start_mid_dist); - if (cos_in > 1) - cos_in = 1; - else if (cos_in < -1) - cos_in = -1; - let angleOfCurve = Math.acos(cos_in); - angleOfCurve = 57.2958 * angleOfCurve % 180; - let fingerCurl; - if (angleOfCurve > options3.NO_CURL_START_LIMIT) - fingerCurl = FingerCurl.none; - else if (angleOfCurve > options3.HALF_CURL_START_LIMIT) - fingerCurl = FingerCurl.half; - else - fingerCurl = FingerCurl.full; - return fingerCurl; -} -function estimateHorizontalDirection(start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x) { - let estimatedDirection; - if (max_dist_x === Math.abs(start_end_x_dist)) { - if (start_end_x_dist > 0) - estimatedDirection = FingerDirection.horizontalLeft; - else - estimatedDirection = FingerDirection.horizontalRight; - } else if (max_dist_x === Math.abs(start_mid_x_dist)) { - if (start_mid_x_dist > 0) - estimatedDirection = FingerDirection.horizontalLeft; - else - estimatedDirection = FingerDirection.horizontalRight; - } else { - if (mid_end_x_dist > 0) - estimatedDirection = FingerDirection.horizontalLeft; - else - estimatedDirection = FingerDirection.horizontalRight; - } - return estimatedDirection; -} -function estimateVerticalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y) { - let estimatedDirection; - if (max_dist_y === Math.abs(start_end_y_dist)) { - if (start_end_y_dist < 0) - estimatedDirection = FingerDirection.verticalDown; - else - estimatedDirection = FingerDirection.verticalUp; - } else if (max_dist_y === Math.abs(start_mid_y_dist)) { - if (start_mid_y_dist < 0) - estimatedDirection = FingerDirection.verticalDown; - else - estimatedDirection = FingerDirection.verticalUp; - } else { - if (mid_end_y_dist < 0) - estimatedDirection = FingerDirection.verticalDown; - else - estimatedDirection = FingerDirection.verticalUp; - } - return estimatedDirection; -} -function estimateDiagonalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y, start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x) { - let estimatedDirection; - const reqd_vertical_direction = estimateVerticalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y); - const reqd_horizontal_direction = estimateHorizontalDirection(start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x); - if (reqd_vertical_direction === FingerDirection.verticalUp) { - if (reqd_horizontal_direction === FingerDirection.horizontalLeft) - estimatedDirection = FingerDirection.diagonalUpLeft; - else - estimatedDirection = FingerDirection.diagonalUpRight; - } else { - if (reqd_horizontal_direction === FingerDirection.horizontalLeft) - estimatedDirection = FingerDirection.diagonalDownLeft; - else - estimatedDirection = FingerDirection.diagonalDownRight; - } - return estimatedDirection; -} -function calculateFingerDirection(startPoint, midPoint, endPoint, fingerSlopes) { - const start_mid_x_dist = startPoint[0] - midPoint[0]; - const start_end_x_dist = startPoint[0] - endPoint[0]; - const mid_end_x_dist = midPoint[0] - endPoint[0]; - const start_mid_y_dist = startPoint[1] - midPoint[1]; - const start_end_y_dist = startPoint[1] - endPoint[1]; - const mid_end_y_dist = midPoint[1] - endPoint[1]; - const max_dist_x = Math.max(Math.abs(start_mid_x_dist), Math.abs(start_end_x_dist), Math.abs(mid_end_x_dist)); - const max_dist_y = Math.max(Math.abs(start_mid_y_dist), Math.abs(start_end_y_dist), Math.abs(mid_end_y_dist)); - let voteVertical = 0; - let voteDiagonal = 0; - let voteHorizontal = 0; - const start_end_x_y_dist_ratio = max_dist_y / (max_dist_x + 1e-5); - if (start_end_x_y_dist_ratio > 1.5) - voteVertical += options3.DISTANCE_VOTE_POWER; - else if (start_end_x_y_dist_ratio > 0.66) - voteDiagonal += options3.DISTANCE_VOTE_POWER; - else - voteHorizontal += options3.DISTANCE_VOTE_POWER; - const start_mid_dist = Math.sqrt(start_mid_x_dist * start_mid_x_dist + start_mid_y_dist * start_mid_y_dist); - const start_end_dist = Math.sqrt(start_end_x_dist * start_end_x_dist + start_end_y_dist * start_end_y_dist); - const mid_end_dist = Math.sqrt(mid_end_x_dist * mid_end_x_dist + mid_end_y_dist * mid_end_y_dist); - const max_dist = Math.max(start_mid_dist, start_end_dist, mid_end_dist); - let calc_start_point_x = startPoint[0]; - let calc_start_point_y = startPoint[1]; - let calc_end_point_x = endPoint[0]; - let calc_end_point_y = endPoint[1]; - if (max_dist === start_mid_dist) { - calc_end_point_x = endPoint[0]; - calc_end_point_y = endPoint[1]; - } else if (max_dist === mid_end_dist) { - calc_start_point_x = midPoint[0]; - calc_start_point_y = midPoint[1]; - } - const calcStartPoint = [calc_start_point_x, calc_start_point_y]; - const calcEndPoint = [calc_end_point_x, calc_end_point_y]; - const totalAngle = getSlopes(calcStartPoint, calcEndPoint); - const votes = angleOrientationAt(totalAngle, options3.TOTAL_ANGLE_VOTE_POWER); - voteVertical += votes[0]; - voteDiagonal += votes[1]; - voteHorizontal += votes[2]; - for (const fingerSlope of fingerSlopes) { - const fingerVotes = angleOrientationAt(fingerSlope, options3.SINGLE_ANGLE_VOTE_POWER); - voteVertical += fingerVotes[0]; - voteDiagonal += fingerVotes[1]; - voteHorizontal += fingerVotes[2]; - } - let estimatedDirection; - if (voteVertical === Math.max(voteVertical, voteDiagonal, voteHorizontal)) { - estimatedDirection = estimateVerticalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y); - } else if (voteHorizontal === Math.max(voteDiagonal, voteHorizontal)) { - estimatedDirection = estimateHorizontalDirection(start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x); - } else { - estimatedDirection = estimateDiagonalDirection(start_end_y_dist, start_mid_y_dist, mid_end_y_dist, max_dist_y, start_end_x_dist, start_mid_x_dist, mid_end_x_dist, max_dist_x); - } - return estimatedDirection; -} -function estimate(landmarks) { - const slopesXY = []; - const slopesYZ = []; - const fingerCurls = []; - const fingerDirections = []; - if (!landmarks) - return { curls: fingerCurls, directions: fingerDirections }; - for (const finger of Finger.all) { - const points = Finger.getPoints(finger); - const slopeAtXY = []; - const slopeAtYZ = []; - for (const point2 of points) { - const point1 = landmarks[point2[0]]; - const point22 = landmarks[point2[1]]; - const slopes = getSlopes(point1, point22); - const slopeXY = slopes[0]; - const slopeYZ = slopes[1]; - slopeAtXY.push(slopeXY); - slopeAtYZ.push(slopeYZ); - } - slopesXY.push(slopeAtXY); - slopesYZ.push(slopeAtYZ); - } - for (const finger of Finger.all) { - const pointIndexAt = finger === Finger.thumb ? 1 : 0; - const fingerPointsAt = Finger.getPoints(finger); - const startPoint = landmarks[fingerPointsAt[pointIndexAt][0]]; - const midPoint = landmarks[fingerPointsAt[pointIndexAt + 1][1]]; - const endPoint = landmarks[fingerPointsAt[3][1]]; - const fingerCurled = estimateFingerCurl(startPoint, midPoint, endPoint); - const fingerPosition = calculateFingerDirection(startPoint, midPoint, endPoint, slopesXY[finger].slice(pointIndexAt)); - fingerCurls[finger] = fingerCurled; - fingerDirections[finger] = fingerPosition; - } - return { curls: fingerCurls, directions: fingerDirections }; -} -function analyze(keypoints) { - if (!keypoints || keypoints.length === 0) - return null; - const estimatorRes = estimate(keypoints); - const landmarks = {}; - for (const fingerIdx of Finger.all) { - landmarks[Finger.getName(fingerIdx)] = { - curl: FingerCurl.getName(estimatorRes.curls[fingerIdx]), - direction: FingerDirection.getName(estimatorRes.directions[fingerIdx]) - }; - } - return landmarks; -} -function match(keypoints) { - const poses = []; - if (!keypoints || keypoints.length === 0) - return poses; - const estimatorRes = estimate(keypoints); - for (const gesture2 of fingergesture_default) { - const confidence = gesture2.matchAgainst(estimatorRes.curls, estimatorRes.directions); - if (confidence >= minConfidence) - poses.push({ name: gesture2.name, confidence }); - } - return poses; -} - -// src/gesture/gesture.ts -var body2 = (res) => { - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - const leftWrist = res[i].keypoints.find((a) => a.part === "leftWrist"); - const rightWrist = res[i].keypoints.find((a) => a.part === "rightWrist"); - const nose = res[i].keypoints.find((a) => a.part === "nose"); - if (nose && leftWrist && rightWrist && leftWrist.position[1] < nose.position[1] && rightWrist.position[1] < nose.position[1]) - gestures.push({ body: i, gesture: "i give up" }); - else if (nose && leftWrist && leftWrist.position[1] < nose.position[1]) - gestures.push({ body: i, gesture: "raise left hand" }); - else if (nose && rightWrist && rightWrist.position[1] < nose.position[1]) - gestures.push({ body: i, gesture: "raise right hand" }); - const leftShoulder = res[i].keypoints.find((a) => a.part === "leftShoulder"); - const rightShoulder = res[i].keypoints.find((a) => a.part === "rightShoulder"); - if (leftShoulder && rightShoulder && Math.abs(leftShoulder.positionRaw[1] - rightShoulder.positionRaw[1]) > 0.1) { - gestures.push({ body: i, gesture: `leaning ${leftShoulder.position[1] > rightShoulder.position[1] ? "left" : "right"}` }); - } - } - return gestures; -}; -var face2 = (res) => { - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - if (res[i].mesh && res[i].mesh.length > 450) { - const zDiff = (res[i].mesh[33][2] || 0) - (res[i].mesh[263][2] || 0); - const xDiff = res[i].mesh[33][0] - res[i].mesh[263][0]; - if (Math.abs(zDiff / xDiff) <= 0.15) - gestures.push({ face: i, gesture: "facing center" }); - else - gestures.push({ face: i, gesture: `facing ${zDiff < 0 ? "left" : "right"}` }); - const openLeft = Math.abs(res[i].mesh[374][1] - res[i].mesh[386][1]) / Math.abs(res[i].mesh[443][1] - res[i].mesh[450][1]); - if (openLeft < 0.2) - gestures.push({ face: i, gesture: "blink left eye" }); - const openRight = Math.abs(res[i].mesh[145][1] - res[i].mesh[159][1]) / Math.abs(res[i].mesh[223][1] - res[i].mesh[230][1]); - if (openRight < 0.2) - gestures.push({ face: i, gesture: "blink right eye" }); - const mouthOpen = Math.min(100, 500 * Math.abs(res[i].mesh[13][1] - res[i].mesh[14][1]) / Math.abs(res[i].mesh[10][1] - res[i].mesh[152][1])); - if (mouthOpen > 10) - gestures.push({ face: i, gesture: `mouth ${Math.trunc(mouthOpen)}% open` }); - const chinDepth = res[i].mesh[152][2] || 0; - if (Math.abs(chinDepth) > 10) - gestures.push({ face: i, gesture: `head ${chinDepth < 0 ? "up" : "down"}` }); - } - } - return gestures; -}; -var iris2 = (res) => { - var _a, _b, _c, _d; - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - if (!((_b = (_a = res[i].annotations) == null ? void 0 : _a.leftEyeIris) == null ? void 0 : _b[0]) || !((_d = (_c = res[i].annotations) == null ? void 0 : _c.rightEyeIris) == null ? void 0 : _d[0])) - continue; - const sizeXLeft = res[i].annotations.leftEyeIris[3][0] - res[i].annotations.leftEyeIris[1][0]; - const sizeYLeft = res[i].annotations.leftEyeIris[4][1] - res[i].annotations.leftEyeIris[2][1]; - const areaLeft = Math.abs(sizeXLeft * sizeYLeft); - const sizeXRight = res[i].annotations.rightEyeIris[3][0] - res[i].annotations.rightEyeIris[1][0]; - const sizeYRight = res[i].annotations.rightEyeIris[4][1] - res[i].annotations.rightEyeIris[2][1]; - const areaRight = Math.abs(sizeXRight * sizeYRight); - let center = false; - const difference = Math.abs(areaLeft - areaRight) / Math.max(areaLeft, areaRight); - if (difference < 0.25) { - center = true; - gestures.push({ iris: i, gesture: "facing center" }); - } - const leftIrisCenterX = Math.abs(res[i].mesh[263][0] - res[i].annotations.leftEyeIris[0][0]) / res[i].box[2]; - const rightIrisCenterX = Math.abs(res[i].mesh[33][0] - res[i].annotations.rightEyeIris[0][0]) / res[i].box[2]; - if (leftIrisCenterX > 0.06 || rightIrisCenterX > 0.06) - center = false; - if (leftIrisCenterX > rightIrisCenterX) { - if (leftIrisCenterX > 0.05) - gestures.push({ iris: i, gesture: "looking right" }); - } else { - if (rightIrisCenterX > 0.05) - gestures.push({ iris: i, gesture: "looking left" }); - } - const rightIrisCenterY = Math.abs(res[i].mesh[145][1] - res[i].annotations.rightEyeIris[0][1]) / res[i].box[3]; - const leftIrisCenterY = Math.abs(res[i].mesh[374][1] - res[i].annotations.leftEyeIris[0][1]) / res[i].box[3]; - if (leftIrisCenterY < 0.01 || rightIrisCenterY < 0.01 || leftIrisCenterY > 0.022 || rightIrisCenterY > 0.022) - center = false; - if (leftIrisCenterY < 0.01 || rightIrisCenterY < 0.01) - gestures.push({ iris: i, gesture: "looking down" }); - if (leftIrisCenterY > 0.022 || rightIrisCenterY > 0.022) - gestures.push({ iris: i, gesture: "looking up" }); - if (center) - gestures.push({ iris: i, gesture: "looking center" }); - } - return gestures; -}; -var hand2 = (res) => { - if (!res) - return []; - const gestures = []; - for (let i = 0; i < res.length; i++) { - const fingers = []; - if (res[i].annotations) { - for (const [finger, pos] of Object.entries(res[i].annotations)) { - if (finger !== "palmBase" && Array.isArray(pos) && pos[0]) - fingers.push({ name: finger.toLowerCase(), position: pos[0] }); - } - } - if (fingers && fingers.length > 0) { - const closest = fingers.reduce((best, a) => (best.position[2] || 0) < (a.position[2] || 0) ? best : a); - gestures.push({ hand: i, gesture: `${closest.name} forward` }); - const highest = fingers.reduce((best, a) => best.position[1] < a.position[1] ? best : a); - gestures.push({ hand: i, gesture: `${highest.name} up` }); - } - if (res[i].keypoints) { - const poses = match(res[i].keypoints); - for (const pose of poses) - gestures.push({ hand: i, gesture: pose.name }); - } - } - return gestures; -}; - -// src/hand/handposedetector.ts -var tf27 = __toESM(require_tfjs_esm()); - -// src/hand/handposeutil.ts -var tf26 = __toESM(require_tfjs_esm()); -function getBoxSize2(box) { - return [ - Math.abs(box.endPoint[0] - box.startPoint[0]), - Math.abs(box.endPoint[1] - box.startPoint[1]) - ]; -} -function getBoxCenter2(box) { - return [ - box.startPoint[0] + (box.endPoint[0] - box.startPoint[0]) / 2, - box.startPoint[1] + (box.endPoint[1] - box.startPoint[1]) / 2 - ]; -} -function cutBoxFromImageAndResize(box, image28, cropSize) { - const h = image28.shape[1]; - const w = image28.shape[2]; - const boxes = [[ - box.startPoint[1] / h, - box.startPoint[0] / w, - box.endPoint[1] / h, - box.endPoint[0] / w - ]]; - return tf26.image.cropAndResize(image28, boxes, [0], cropSize); -} -function scaleBoxCoordinates2(box, factor) { - const startPoint = [box.startPoint[0] * factor[0], box.startPoint[1] * factor[1]]; - const endPoint = [box.endPoint[0] * factor[0], box.endPoint[1] * factor[1]]; - const palmLandmarks = box.palmLandmarks.map((coord) => { - const scaledCoord = [coord[0] * factor[0], coord[1] * factor[1]]; - return scaledCoord; - }); - return { startPoint, endPoint, palmLandmarks, confidence: box.confidence }; -} -function enlargeBox2(box, factor = 1.5) { - const center = getBoxCenter2(box); - const size2 = getBoxSize2(box); - const newHalfSize = [factor * size2[0] / 2, factor * size2[1] / 2]; - const startPoint = [center[0] - newHalfSize[0], center[1] - newHalfSize[1]]; - const endPoint = [center[0] + newHalfSize[0], center[1] + newHalfSize[1]]; - return { startPoint, endPoint, palmLandmarks: box.palmLandmarks }; -} -function squarifyBox2(box) { - const centers = getBoxCenter2(box); - const size2 = getBoxSize2(box); - const maxEdge = Math.max(...size2); - const halfSize = maxEdge / 2; - const startPoint = [centers[0] - halfSize, centers[1] - halfSize]; - const endPoint = [centers[0] + halfSize, centers[1] + halfSize]; - return { startPoint, endPoint, palmLandmarks: box.palmLandmarks }; -} -function normalizeRadians2(angle) { - return angle - 2 * Math.PI * Math.floor((angle + Math.PI) / (2 * Math.PI)); -} -function computeRotation2(point1, point2) { - const radians = Math.PI / 2 - Math.atan2(-(point2[1] - point1[1]), point2[0] - point1[0]); - return normalizeRadians2(radians); -} -var buildTranslationMatrix2 = (x, y) => [[1, 0, x], [0, 1, y], [0, 0, 1]]; -function dot2(v1, v2) { - let product = 0; - for (let i = 0; i < v1.length; i++) { - product += v1[i] * v2[i]; - } - return product; -} -function getColumnFrom2DArr2(arr, columnIndex) { - const column = []; - for (let i = 0; i < arr.length; i++) { - column.push(arr[i][columnIndex]); - } - return column; -} -function multiplyTransformMatrices2(mat1, mat2) { - const product = []; - const size2 = mat1.length; - for (let row = 0; row < size2; row++) { - product.push([]); - for (let col = 0; col < size2; col++) { - product[row].push(dot2(mat1[row], getColumnFrom2DArr2(mat2, col))); - } - } - return product; -} -function buildRotationMatrix2(rotation, center) { - const cosA = Math.cos(rotation); - const sinA = Math.sin(rotation); - const rotationMatrix = [[cosA, -sinA, 0], [sinA, cosA, 0], [0, 0, 1]]; - const translationMatrix = buildTranslationMatrix2(center[0], center[1]); - const translationTimesRotation = multiplyTransformMatrices2(translationMatrix, rotationMatrix); - const negativeTranslationMatrix = buildTranslationMatrix2(-center[0], -center[1]); - return multiplyTransformMatrices2(translationTimesRotation, negativeTranslationMatrix); -} -function invertTransformMatrix2(matrix) { - const rotationComponent = [[matrix[0][0], matrix[1][0]], [matrix[0][1], matrix[1][1]]]; - const translationComponent = [matrix[0][2], matrix[1][2]]; - const invertedTranslation = [ - -dot2(rotationComponent[0], translationComponent), - -dot2(rotationComponent[1], translationComponent) - ]; - return [ - rotationComponent[0].concat(invertedTranslation[0]), - rotationComponent[1].concat(invertedTranslation[1]), - [0, 0, 1] - ]; -} -function rotatePoint2(homogeneousCoordinate, rotationMatrix) { - return [ - dot2(homogeneousCoordinate, rotationMatrix[0]), - dot2(homogeneousCoordinate, rotationMatrix[1]) - ]; -} - -// src/hand/handposeanchors.ts -var anchors2 = [ - { x: 0.015625, y: 0.015625 }, - { x: 0.015625, y: 0.015625 }, - { x: 0.046875, y: 0.015625 }, - { x: 0.046875, y: 0.015625 }, - { x: 0.078125, y: 0.015625 }, - { x: 0.078125, y: 0.015625 }, - { x: 0.109375, y: 0.015625 }, - { x: 0.109375, y: 0.015625 }, - { x: 0.140625, y: 0.015625 }, - { x: 0.140625, y: 0.015625 }, - { x: 0.171875, y: 0.015625 }, - { x: 0.171875, y: 0.015625 }, - { x: 0.203125, y: 0.015625 }, - { x: 0.203125, y: 0.015625 }, - { x: 0.234375, y: 0.015625 }, - { x: 0.234375, y: 0.015625 }, - { x: 0.265625, y: 0.015625 }, - { x: 0.265625, y: 0.015625 }, - { x: 0.296875, y: 0.015625 }, - { x: 0.296875, y: 0.015625 }, - { x: 0.328125, y: 0.015625 }, - { x: 0.328125, y: 0.015625 }, - { x: 0.359375, y: 0.015625 }, - { x: 0.359375, y: 0.015625 }, - { x: 0.390625, y: 0.015625 }, - { x: 0.390625, y: 0.015625 }, - { x: 0.421875, y: 0.015625 }, - { x: 0.421875, y: 0.015625 }, - { x: 0.453125, y: 0.015625 }, - { x: 0.453125, y: 0.015625 }, - { x: 0.484375, y: 0.015625 }, - { x: 0.484375, y: 0.015625 }, - { x: 0.515625, y: 0.015625 }, - { x: 0.515625, y: 0.015625 }, - { x: 0.546875, y: 0.015625 }, - { x: 0.546875, y: 0.015625 }, - { x: 0.578125, y: 0.015625 }, - { x: 0.578125, y: 0.015625 }, - { x: 0.609375, y: 0.015625 }, - { x: 0.609375, y: 0.015625 }, - { x: 0.640625, y: 0.015625 }, - { x: 0.640625, y: 0.015625 }, - { x: 0.671875, y: 0.015625 }, - { x: 0.671875, y: 0.015625 }, - { x: 0.703125, y: 0.015625 }, - { x: 0.703125, y: 0.015625 }, - { x: 0.734375, y: 0.015625 }, - { x: 0.734375, y: 0.015625 }, - { x: 0.765625, y: 0.015625 }, - { x: 0.765625, y: 0.015625 }, - { x: 0.796875, y: 0.015625 }, - { x: 0.796875, y: 0.015625 }, - { x: 0.828125, y: 0.015625 }, - { x: 0.828125, y: 0.015625 }, - { x: 0.859375, y: 0.015625 }, - { x: 0.859375, y: 0.015625 }, - { x: 0.890625, y: 0.015625 }, - { x: 0.890625, y: 0.015625 }, - { x: 0.921875, y: 0.015625 }, - { x: 0.921875, y: 0.015625 }, - { x: 0.953125, y: 0.015625 }, - { x: 0.953125, y: 0.015625 }, - { x: 0.984375, y: 0.015625 }, - { x: 0.984375, y: 0.015625 }, - { x: 0.015625, y: 0.046875 }, - { x: 0.015625, y: 0.046875 }, - { x: 0.046875, y: 0.046875 }, - { x: 0.046875, y: 0.046875 }, - { x: 0.078125, y: 0.046875 }, - { x: 0.078125, y: 0.046875 }, - { x: 0.109375, y: 0.046875 }, - { x: 0.109375, y: 0.046875 }, - { x: 0.140625, y: 0.046875 }, - { x: 0.140625, y: 0.046875 }, - { x: 0.171875, y: 0.046875 }, - { x: 0.171875, y: 0.046875 }, - { x: 0.203125, y: 0.046875 }, - { x: 0.203125, y: 0.046875 }, - { x: 0.234375, y: 0.046875 }, - { x: 0.234375, y: 0.046875 }, - { x: 0.265625, y: 0.046875 }, - { x: 0.265625, y: 0.046875 }, - { x: 0.296875, y: 0.046875 }, - { x: 0.296875, y: 0.046875 }, - { x: 0.328125, y: 0.046875 }, - { x: 0.328125, y: 0.046875 }, - { x: 0.359375, y: 0.046875 }, - { x: 0.359375, y: 0.046875 }, - { x: 0.390625, y: 0.046875 }, - { x: 0.390625, y: 0.046875 }, - { x: 0.421875, y: 0.046875 }, - { x: 0.421875, y: 0.046875 }, - { x: 0.453125, y: 0.046875 }, - { x: 0.453125, y: 0.046875 }, - { x: 0.484375, y: 0.046875 }, - { x: 0.484375, y: 0.046875 }, - { x: 0.515625, y: 0.046875 }, - { x: 0.515625, y: 0.046875 }, - { x: 0.546875, y: 0.046875 }, - { x: 0.546875, y: 0.046875 }, - { x: 0.578125, y: 0.046875 }, - { x: 0.578125, y: 0.046875 }, - { x: 0.609375, y: 0.046875 }, - { x: 0.609375, y: 0.046875 }, - { x: 0.640625, y: 0.046875 }, - { x: 0.640625, y: 0.046875 }, - { x: 0.671875, y: 0.046875 }, - { x: 0.671875, y: 0.046875 }, - { x: 0.703125, y: 0.046875 }, - { x: 0.703125, y: 0.046875 }, - { x: 0.734375, y: 0.046875 }, - { x: 0.734375, y: 0.046875 }, - { x: 0.765625, y: 0.046875 }, - { x: 0.765625, y: 0.046875 }, - { x: 0.796875, y: 0.046875 }, - { x: 0.796875, y: 0.046875 }, - { x: 0.828125, y: 0.046875 }, - { x: 0.828125, y: 0.046875 }, - { x: 0.859375, y: 0.046875 }, - { x: 0.859375, y: 0.046875 }, - { x: 0.890625, y: 0.046875 }, - { x: 0.890625, y: 0.046875 }, - { x: 0.921875, y: 0.046875 }, - { x: 0.921875, y: 0.046875 }, - { x: 0.953125, y: 0.046875 }, - { x: 0.953125, y: 0.046875 }, - { x: 0.984375, y: 0.046875 }, - { x: 0.984375, y: 0.046875 }, - { x: 0.015625, y: 0.078125 }, - { x: 0.015625, y: 0.078125 }, - { x: 0.046875, y: 0.078125 }, - { x: 0.046875, y: 0.078125 }, - { x: 0.078125, y: 0.078125 }, - { x: 0.078125, y: 0.078125 }, - { x: 0.109375, y: 0.078125 }, - { x: 0.109375, y: 0.078125 }, - { x: 0.140625, y: 0.078125 }, - { x: 0.140625, y: 0.078125 }, - { x: 0.171875, y: 0.078125 }, - { x: 0.171875, y: 0.078125 }, - { x: 0.203125, y: 0.078125 }, - { x: 0.203125, y: 0.078125 }, - { x: 0.234375, y: 0.078125 }, - { x: 0.234375, y: 0.078125 }, - { x: 0.265625, y: 0.078125 }, - { x: 0.265625, y: 0.078125 }, - { x: 0.296875, y: 0.078125 }, - { x: 0.296875, y: 0.078125 }, - { x: 0.328125, y: 0.078125 }, - { x: 0.328125, y: 0.078125 }, - { x: 0.359375, y: 0.078125 }, - { x: 0.359375, y: 0.078125 }, - { x: 0.390625, y: 0.078125 }, - { x: 0.390625, y: 0.078125 }, - { x: 0.421875, y: 0.078125 }, - { x: 0.421875, y: 0.078125 }, - { x: 0.453125, y: 0.078125 }, - { x: 0.453125, y: 0.078125 }, - { x: 0.484375, y: 0.078125 }, - { x: 0.484375, y: 0.078125 }, - { x: 0.515625, y: 0.078125 }, - { x: 0.515625, y: 0.078125 }, - { x: 0.546875, y: 0.078125 }, - { x: 0.546875, y: 0.078125 }, - { x: 0.578125, y: 0.078125 }, - { x: 0.578125, y: 0.078125 }, - { x: 0.609375, y: 0.078125 }, - { x: 0.609375, y: 0.078125 }, - { x: 0.640625, y: 0.078125 }, - { x: 0.640625, y: 0.078125 }, - { x: 0.671875, y: 0.078125 }, - { x: 0.671875, y: 0.078125 }, - { x: 0.703125, y: 0.078125 }, - { x: 0.703125, y: 0.078125 }, - { x: 0.734375, y: 0.078125 }, - { x: 0.734375, y: 0.078125 }, - { x: 0.765625, y: 0.078125 }, - { x: 0.765625, y: 0.078125 }, - { x: 0.796875, y: 0.078125 }, - { x: 0.796875, y: 0.078125 }, - { x: 0.828125, y: 0.078125 }, - { x: 0.828125, y: 0.078125 }, - { x: 0.859375, y: 0.078125 }, - { x: 0.859375, y: 0.078125 }, - { x: 0.890625, y: 0.078125 }, - { x: 0.890625, y: 0.078125 }, - { x: 0.921875, y: 0.078125 }, - { x: 0.921875, y: 0.078125 }, - { x: 0.953125, y: 0.078125 }, - { x: 0.953125, y: 0.078125 }, - { x: 0.984375, y: 0.078125 }, - { x: 0.984375, y: 0.078125 }, - { x: 0.015625, y: 0.109375 }, - { x: 0.015625, y: 0.109375 }, - { x: 0.046875, y: 0.109375 }, - { x: 0.046875, y: 0.109375 }, - { x: 0.078125, y: 0.109375 }, - { x: 0.078125, y: 0.109375 }, - { x: 0.109375, y: 0.109375 }, - { x: 0.109375, y: 0.109375 }, - { x: 0.140625, y: 0.109375 }, - { x: 0.140625, y: 0.109375 }, - { x: 0.171875, y: 0.109375 }, - { x: 0.171875, y: 0.109375 }, - { x: 0.203125, y: 0.109375 }, - { x: 0.203125, y: 0.109375 }, - { x: 0.234375, y: 0.109375 }, - { x: 0.234375, y: 0.109375 }, - { x: 0.265625, y: 0.109375 }, - { x: 0.265625, y: 0.109375 }, - { x: 0.296875, y: 0.109375 }, - { x: 0.296875, y: 0.109375 }, - { x: 0.328125, y: 0.109375 }, - { x: 0.328125, y: 0.109375 }, - { x: 0.359375, y: 0.109375 }, - { x: 0.359375, y: 0.109375 }, - { x: 0.390625, y: 0.109375 }, - { x: 0.390625, y: 0.109375 }, - { x: 0.421875, y: 0.109375 }, - { x: 0.421875, y: 0.109375 }, - { x: 0.453125, y: 0.109375 }, - { x: 0.453125, y: 0.109375 }, - { x: 0.484375, y: 0.109375 }, - { x: 0.484375, y: 0.109375 }, - { x: 0.515625, y: 0.109375 }, - { x: 0.515625, y: 0.109375 }, - { x: 0.546875, y: 0.109375 }, - { x: 0.546875, y: 0.109375 }, - { x: 0.578125, y: 0.109375 }, - { x: 0.578125, y: 0.109375 }, - { x: 0.609375, y: 0.109375 }, - { x: 0.609375, y: 0.109375 }, - { x: 0.640625, y: 0.109375 }, - { x: 0.640625, y: 0.109375 }, - { x: 0.671875, y: 0.109375 }, - { x: 0.671875, y: 0.109375 }, - { x: 0.703125, y: 0.109375 }, - { x: 0.703125, y: 0.109375 }, - { x: 0.734375, y: 0.109375 }, - { x: 0.734375, y: 0.109375 }, - { x: 0.765625, y: 0.109375 }, - { x: 0.765625, y: 0.109375 }, - { x: 0.796875, y: 0.109375 }, - { x: 0.796875, y: 0.109375 }, - { x: 0.828125, y: 0.109375 }, - { x: 0.828125, y: 0.109375 }, - { x: 0.859375, y: 0.109375 }, - { x: 0.859375, y: 0.109375 }, - { x: 0.890625, y: 0.109375 }, - { x: 0.890625, y: 0.109375 }, - { x: 0.921875, y: 0.109375 }, - { x: 0.921875, y: 0.109375 }, - { x: 0.953125, y: 0.109375 }, - { x: 0.953125, y: 0.109375 }, - { x: 0.984375, y: 0.109375 }, - { x: 0.984375, y: 0.109375 }, - { x: 0.015625, y: 0.140625 }, - { x: 0.015625, y: 0.140625 }, - { x: 0.046875, y: 0.140625 }, - { x: 0.046875, y: 0.140625 }, - { x: 0.078125, y: 0.140625 }, - { x: 0.078125, y: 0.140625 }, - { x: 0.109375, y: 0.140625 }, - { x: 0.109375, y: 0.140625 }, - { x: 0.140625, y: 0.140625 }, - { x: 0.140625, y: 0.140625 }, - { x: 0.171875, y: 0.140625 }, - { x: 0.171875, y: 0.140625 }, - { x: 0.203125, y: 0.140625 }, - { x: 0.203125, y: 0.140625 }, - { x: 0.234375, y: 0.140625 }, - { x: 0.234375, y: 0.140625 }, - { x: 0.265625, y: 0.140625 }, - { x: 0.265625, y: 0.140625 }, - { x: 0.296875, y: 0.140625 }, - { x: 0.296875, y: 0.140625 }, - { x: 0.328125, y: 0.140625 }, - { x: 0.328125, y: 0.140625 }, - { x: 0.359375, y: 0.140625 }, - { x: 0.359375, y: 0.140625 }, - { x: 0.390625, y: 0.140625 }, - { x: 0.390625, y: 0.140625 }, - { x: 0.421875, y: 0.140625 }, - { x: 0.421875, y: 0.140625 }, - { x: 0.453125, y: 0.140625 }, - { x: 0.453125, y: 0.140625 }, - { x: 0.484375, y: 0.140625 }, - { x: 0.484375, y: 0.140625 }, - { x: 0.515625, y: 0.140625 }, - { x: 0.515625, y: 0.140625 }, - { x: 0.546875, y: 0.140625 }, - { x: 0.546875, y: 0.140625 }, - { x: 0.578125, y: 0.140625 }, - { x: 0.578125, y: 0.140625 }, - { x: 0.609375, y: 0.140625 }, - { x: 0.609375, y: 0.140625 }, - { x: 0.640625, y: 0.140625 }, - { x: 0.640625, y: 0.140625 }, - { x: 0.671875, y: 0.140625 }, - { x: 0.671875, y: 0.140625 }, - { x: 0.703125, y: 0.140625 }, - { x: 0.703125, y: 0.140625 }, - { x: 0.734375, y: 0.140625 }, - { x: 0.734375, y: 0.140625 }, - { x: 0.765625, y: 0.140625 }, - { x: 0.765625, y: 0.140625 }, - { x: 0.796875, y: 0.140625 }, - { x: 0.796875, y: 0.140625 }, - { x: 0.828125, y: 0.140625 }, - { x: 0.828125, y: 0.140625 }, - { x: 0.859375, y: 0.140625 }, - { x: 0.859375, y: 0.140625 }, - { x: 0.890625, y: 0.140625 }, - { x: 0.890625, y: 0.140625 }, - { x: 0.921875, y: 0.140625 }, - { x: 0.921875, y: 0.140625 }, - { x: 0.953125, y: 0.140625 }, - { x: 0.953125, y: 0.140625 }, - { x: 0.984375, y: 0.140625 }, - { x: 0.984375, y: 0.140625 }, - { x: 0.015625, y: 0.171875 }, - { x: 0.015625, y: 0.171875 }, - { x: 0.046875, y: 0.171875 }, - { x: 0.046875, y: 0.171875 }, - { x: 0.078125, y: 0.171875 }, - { x: 0.078125, y: 0.171875 }, - { x: 0.109375, y: 0.171875 }, - { x: 0.109375, y: 0.171875 }, - { x: 0.140625, y: 0.171875 }, - { x: 0.140625, y: 0.171875 }, - { x: 0.171875, y: 0.171875 }, - { x: 0.171875, y: 0.171875 }, - { x: 0.203125, y: 0.171875 }, - { x: 0.203125, y: 0.171875 }, - { x: 0.234375, y: 0.171875 }, - { x: 0.234375, y: 0.171875 }, - { x: 0.265625, y: 0.171875 }, - { x: 0.265625, y: 0.171875 }, - { x: 0.296875, y: 0.171875 }, - { x: 0.296875, y: 0.171875 }, - { x: 0.328125, y: 0.171875 }, - { x: 0.328125, y: 0.171875 }, - { x: 0.359375, y: 0.171875 }, - { x: 0.359375, y: 0.171875 }, - { x: 0.390625, y: 0.171875 }, - { x: 0.390625, y: 0.171875 }, - { x: 0.421875, y: 0.171875 }, - { x: 0.421875, y: 0.171875 }, - { x: 0.453125, y: 0.171875 }, - { x: 0.453125, y: 0.171875 }, - { x: 0.484375, y: 0.171875 }, - { x: 0.484375, y: 0.171875 }, - { x: 0.515625, y: 0.171875 }, - { x: 0.515625, y: 0.171875 }, - { x: 0.546875, y: 0.171875 }, - { x: 0.546875, y: 0.171875 }, - { x: 0.578125, y: 0.171875 }, - { x: 0.578125, y: 0.171875 }, - { x: 0.609375, y: 0.171875 }, - { x: 0.609375, y: 0.171875 }, - { x: 0.640625, y: 0.171875 }, - { x: 0.640625, y: 0.171875 }, - { x: 0.671875, y: 0.171875 }, - { x: 0.671875, y: 0.171875 }, - { x: 0.703125, y: 0.171875 }, - { x: 0.703125, y: 0.171875 }, - { x: 0.734375, y: 0.171875 }, - { x: 0.734375, y: 0.171875 }, - { x: 0.765625, y: 0.171875 }, - { x: 0.765625, y: 0.171875 }, - { x: 0.796875, y: 0.171875 }, - { x: 0.796875, y: 0.171875 }, - { x: 0.828125, y: 0.171875 }, - { x: 0.828125, y: 0.171875 }, - { x: 0.859375, y: 0.171875 }, - { x: 0.859375, y: 0.171875 }, - { x: 0.890625, y: 0.171875 }, - { x: 0.890625, y: 0.171875 }, - { x: 0.921875, y: 0.171875 }, - { x: 0.921875, y: 0.171875 }, - { x: 0.953125, y: 0.171875 }, - { x: 0.953125, y: 0.171875 }, - { x: 0.984375, y: 0.171875 }, - { x: 0.984375, y: 0.171875 }, - { x: 0.015625, y: 0.203125 }, - { x: 0.015625, y: 0.203125 }, - { x: 0.046875, y: 0.203125 }, - { x: 0.046875, y: 0.203125 }, - { x: 0.078125, y: 0.203125 }, - { x: 0.078125, y: 0.203125 }, - { x: 0.109375, y: 0.203125 }, - { x: 0.109375, y: 0.203125 }, - { x: 0.140625, y: 0.203125 }, - { x: 0.140625, y: 0.203125 }, - { x: 0.171875, y: 0.203125 }, - { x: 0.171875, y: 0.203125 }, - { x: 0.203125, y: 0.203125 }, - { x: 0.203125, y: 0.203125 }, - { x: 0.234375, y: 0.203125 }, - { x: 0.234375, y: 0.203125 }, - { x: 0.265625, y: 0.203125 }, - { x: 0.265625, y: 0.203125 }, - { x: 0.296875, y: 0.203125 }, - { x: 0.296875, y: 0.203125 }, - { x: 0.328125, y: 0.203125 }, - { x: 0.328125, y: 0.203125 }, - { x: 0.359375, y: 0.203125 }, - { x: 0.359375, y: 0.203125 }, - { x: 0.390625, y: 0.203125 }, - { x: 0.390625, y: 0.203125 }, - { x: 0.421875, y: 0.203125 }, - { x: 0.421875, y: 0.203125 }, - { x: 0.453125, y: 0.203125 }, - { x: 0.453125, y: 0.203125 }, - { x: 0.484375, y: 0.203125 }, - { x: 0.484375, y: 0.203125 }, - { x: 0.515625, y: 0.203125 }, - { x: 0.515625, y: 0.203125 }, - { x: 0.546875, y: 0.203125 }, - { x: 0.546875, y: 0.203125 }, - { x: 0.578125, y: 0.203125 }, - { x: 0.578125, y: 0.203125 }, - { x: 0.609375, y: 0.203125 }, - { x: 0.609375, y: 0.203125 }, - { x: 0.640625, y: 0.203125 }, - { x: 0.640625, y: 0.203125 }, - { x: 0.671875, y: 0.203125 }, - { x: 0.671875, y: 0.203125 }, - { x: 0.703125, y: 0.203125 }, - { x: 0.703125, y: 0.203125 }, - { x: 0.734375, y: 0.203125 }, - { x: 0.734375, y: 0.203125 }, - { x: 0.765625, y: 0.203125 }, - { x: 0.765625, y: 0.203125 }, - { x: 0.796875, y: 0.203125 }, - { x: 0.796875, y: 0.203125 }, - { x: 0.828125, y: 0.203125 }, - { x: 0.828125, y: 0.203125 }, - { x: 0.859375, y: 0.203125 }, - { x: 0.859375, y: 0.203125 }, - { x: 0.890625, y: 0.203125 }, - { x: 0.890625, y: 0.203125 }, - { x: 0.921875, y: 0.203125 }, - { x: 0.921875, y: 0.203125 }, - { x: 0.953125, y: 0.203125 }, - { x: 0.953125, y: 0.203125 }, - { x: 0.984375, y: 0.203125 }, - { x: 0.984375, y: 0.203125 }, - { x: 0.015625, y: 0.234375 }, - { x: 0.015625, y: 0.234375 }, - { x: 0.046875, y: 0.234375 }, - { x: 0.046875, y: 0.234375 }, - { x: 0.078125, y: 0.234375 }, - { x: 0.078125, y: 0.234375 }, - { x: 0.109375, y: 0.234375 }, - { x: 0.109375, y: 0.234375 }, - { x: 0.140625, y: 0.234375 }, - { x: 0.140625, y: 0.234375 }, - { x: 0.171875, y: 0.234375 }, - { x: 0.171875, y: 0.234375 }, - { x: 0.203125, y: 0.234375 }, - { x: 0.203125, y: 0.234375 }, - { x: 0.234375, y: 0.234375 }, - { x: 0.234375, y: 0.234375 }, - { x: 0.265625, y: 0.234375 }, - { x: 0.265625, y: 0.234375 }, - { x: 0.296875, y: 0.234375 }, - { x: 0.296875, y: 0.234375 }, - { x: 0.328125, y: 0.234375 }, - { x: 0.328125, y: 0.234375 }, - { x: 0.359375, y: 0.234375 }, - { x: 0.359375, y: 0.234375 }, - { x: 0.390625, y: 0.234375 }, - { x: 0.390625, y: 0.234375 }, - { x: 0.421875, y: 0.234375 }, - { x: 0.421875, y: 0.234375 }, - { x: 0.453125, y: 0.234375 }, - { x: 0.453125, y: 0.234375 }, - { x: 0.484375, y: 0.234375 }, - { x: 0.484375, y: 0.234375 }, - { x: 0.515625, y: 0.234375 }, - { x: 0.515625, y: 0.234375 }, - { x: 0.546875, y: 0.234375 }, - { x: 0.546875, y: 0.234375 }, - { x: 0.578125, y: 0.234375 }, - { x: 0.578125, y: 0.234375 }, - { x: 0.609375, y: 0.234375 }, - { x: 0.609375, y: 0.234375 }, - { x: 0.640625, y: 0.234375 }, - { x: 0.640625, y: 0.234375 }, - { x: 0.671875, y: 0.234375 }, - { x: 0.671875, y: 0.234375 }, - { x: 0.703125, y: 0.234375 }, - { x: 0.703125, y: 0.234375 }, - { x: 0.734375, y: 0.234375 }, - { x: 0.734375, y: 0.234375 }, - { x: 0.765625, y: 0.234375 }, - { x: 0.765625, y: 0.234375 }, - { x: 0.796875, y: 0.234375 }, - { x: 0.796875, y: 0.234375 }, - { x: 0.828125, y: 0.234375 }, - { x: 0.828125, y: 0.234375 }, - { x: 0.859375, y: 0.234375 }, - { x: 0.859375, y: 0.234375 }, - { x: 0.890625, y: 0.234375 }, - { x: 0.890625, y: 0.234375 }, - { x: 0.921875, y: 0.234375 }, - { x: 0.921875, y: 0.234375 }, - { x: 0.953125, y: 0.234375 }, - { x: 0.953125, y: 0.234375 }, - { x: 0.984375, y: 0.234375 }, - { x: 0.984375, y: 0.234375 }, - { x: 0.015625, y: 0.265625 }, - { x: 0.015625, y: 0.265625 }, - { x: 0.046875, y: 0.265625 }, - { x: 0.046875, y: 0.265625 }, - { x: 0.078125, y: 0.265625 }, - { x: 0.078125, y: 0.265625 }, - { x: 0.109375, y: 0.265625 }, - { x: 0.109375, y: 0.265625 }, - { x: 0.140625, y: 0.265625 }, - { x: 0.140625, y: 0.265625 }, - { x: 0.171875, y: 0.265625 }, - { x: 0.171875, y: 0.265625 }, - { x: 0.203125, y: 0.265625 }, - { x: 0.203125, y: 0.265625 }, - { x: 0.234375, y: 0.265625 }, - { x: 0.234375, y: 0.265625 }, - { x: 0.265625, y: 0.265625 }, - { x: 0.265625, y: 0.265625 }, - { x: 0.296875, y: 0.265625 }, - { x: 0.296875, y: 0.265625 }, - { x: 0.328125, y: 0.265625 }, - { x: 0.328125, y: 0.265625 }, - { x: 0.359375, y: 0.265625 }, - { x: 0.359375, y: 0.265625 }, - { x: 0.390625, y: 0.265625 }, - { x: 0.390625, y: 0.265625 }, - { x: 0.421875, y: 0.265625 }, - { x: 0.421875, y: 0.265625 }, - { x: 0.453125, y: 0.265625 }, - { x: 0.453125, y: 0.265625 }, - { x: 0.484375, y: 0.265625 }, - { x: 0.484375, y: 0.265625 }, - { x: 0.515625, y: 0.265625 }, - { x: 0.515625, y: 0.265625 }, - { x: 0.546875, y: 0.265625 }, - { x: 0.546875, y: 0.265625 }, - { x: 0.578125, y: 0.265625 }, - { x: 0.578125, y: 0.265625 }, - { x: 0.609375, y: 0.265625 }, - { x: 0.609375, y: 0.265625 }, - { x: 0.640625, y: 0.265625 }, - { x: 0.640625, y: 0.265625 }, - { x: 0.671875, y: 0.265625 }, - { x: 0.671875, y: 0.265625 }, - { x: 0.703125, y: 0.265625 }, - { x: 0.703125, y: 0.265625 }, - { x: 0.734375, y: 0.265625 }, - { x: 0.734375, y: 0.265625 }, - { x: 0.765625, y: 0.265625 }, - { x: 0.765625, y: 0.265625 }, - { x: 0.796875, y: 0.265625 }, - { x: 0.796875, y: 0.265625 }, - { x: 0.828125, y: 0.265625 }, - { x: 0.828125, y: 0.265625 }, - { x: 0.859375, y: 0.265625 }, - { x: 0.859375, y: 0.265625 }, - { x: 0.890625, y: 0.265625 }, - { x: 0.890625, y: 0.265625 }, - { x: 0.921875, y: 0.265625 }, - { x: 0.921875, y: 0.265625 }, - { x: 0.953125, y: 0.265625 }, - { x: 0.953125, y: 0.265625 }, - { x: 0.984375, y: 0.265625 }, - { x: 0.984375, y: 0.265625 }, - { x: 0.015625, y: 0.296875 }, - { x: 0.015625, y: 0.296875 }, - { x: 0.046875, y: 0.296875 }, - { x: 0.046875, y: 0.296875 }, - { x: 0.078125, y: 0.296875 }, - { x: 0.078125, y: 0.296875 }, - { x: 0.109375, y: 0.296875 }, - { x: 0.109375, y: 0.296875 }, - { x: 0.140625, y: 0.296875 }, - { x: 0.140625, y: 0.296875 }, - { x: 0.171875, y: 0.296875 }, - { x: 0.171875, y: 0.296875 }, - { x: 0.203125, y: 0.296875 }, - { x: 0.203125, y: 0.296875 }, - { x: 0.234375, y: 0.296875 }, - { x: 0.234375, y: 0.296875 }, - { x: 0.265625, y: 0.296875 }, - { x: 0.265625, y: 0.296875 }, - { x: 0.296875, y: 0.296875 }, - { x: 0.296875, y: 0.296875 }, - { x: 0.328125, y: 0.296875 }, - { x: 0.328125, y: 0.296875 }, - { x: 0.359375, y: 0.296875 }, - { x: 0.359375, y: 0.296875 }, - { x: 0.390625, y: 0.296875 }, - { x: 0.390625, y: 0.296875 }, - { x: 0.421875, y: 0.296875 }, - { x: 0.421875, y: 0.296875 }, - { x: 0.453125, y: 0.296875 }, - { x: 0.453125, y: 0.296875 }, - { x: 0.484375, y: 0.296875 }, - { x: 0.484375, y: 0.296875 }, - { x: 0.515625, y: 0.296875 }, - { x: 0.515625, y: 0.296875 }, - { x: 0.546875, y: 0.296875 }, - { x: 0.546875, y: 0.296875 }, - { x: 0.578125, y: 0.296875 }, - { x: 0.578125, y: 0.296875 }, - { x: 0.609375, y: 0.296875 }, - { x: 0.609375, y: 0.296875 }, - { x: 0.640625, y: 0.296875 }, - { x: 0.640625, y: 0.296875 }, - { x: 0.671875, y: 0.296875 }, - { x: 0.671875, y: 0.296875 }, - { x: 0.703125, y: 0.296875 }, - { x: 0.703125, y: 0.296875 }, - { x: 0.734375, y: 0.296875 }, - { x: 0.734375, y: 0.296875 }, - { x: 0.765625, y: 0.296875 }, - { x: 0.765625, y: 0.296875 }, - { x: 0.796875, y: 0.296875 }, - { x: 0.796875, y: 0.296875 }, - { x: 0.828125, y: 0.296875 }, - { x: 0.828125, y: 0.296875 }, - { x: 0.859375, y: 0.296875 }, - { x: 0.859375, y: 0.296875 }, - { x: 0.890625, y: 0.296875 }, - { x: 0.890625, y: 0.296875 }, - { x: 0.921875, y: 0.296875 }, - { x: 0.921875, y: 0.296875 }, - { x: 0.953125, y: 0.296875 }, - { x: 0.953125, y: 0.296875 }, - { x: 0.984375, y: 0.296875 }, - { x: 0.984375, y: 0.296875 }, - { x: 0.015625, y: 0.328125 }, - { x: 0.015625, y: 0.328125 }, - { x: 0.046875, y: 0.328125 }, - { x: 0.046875, y: 0.328125 }, - { x: 0.078125, y: 0.328125 }, - { x: 0.078125, y: 0.328125 }, - { x: 0.109375, y: 0.328125 }, - { x: 0.109375, y: 0.328125 }, - { x: 0.140625, y: 0.328125 }, - { x: 0.140625, y: 0.328125 }, - { x: 0.171875, y: 0.328125 }, - { x: 0.171875, y: 0.328125 }, - { x: 0.203125, y: 0.328125 }, - { x: 0.203125, y: 0.328125 }, - { x: 0.234375, y: 0.328125 }, - { x: 0.234375, y: 0.328125 }, - { x: 0.265625, y: 0.328125 }, - { x: 0.265625, y: 0.328125 }, - { x: 0.296875, y: 0.328125 }, - { x: 0.296875, y: 0.328125 }, - { x: 0.328125, y: 0.328125 }, - { x: 0.328125, y: 0.328125 }, - { x: 0.359375, y: 0.328125 }, - { x: 0.359375, y: 0.328125 }, - { x: 0.390625, y: 0.328125 }, - { x: 0.390625, y: 0.328125 }, - { x: 0.421875, y: 0.328125 }, - { x: 0.421875, y: 0.328125 }, - { x: 0.453125, y: 0.328125 }, - { x: 0.453125, y: 0.328125 }, - { x: 0.484375, y: 0.328125 }, - { x: 0.484375, y: 0.328125 }, - { x: 0.515625, y: 0.328125 }, - { x: 0.515625, y: 0.328125 }, - { x: 0.546875, y: 0.328125 }, - { x: 0.546875, y: 0.328125 }, - { x: 0.578125, y: 0.328125 }, - { x: 0.578125, y: 0.328125 }, - { x: 0.609375, y: 0.328125 }, - { x: 0.609375, y: 0.328125 }, - { x: 0.640625, y: 0.328125 }, - { x: 0.640625, y: 0.328125 }, - { x: 0.671875, y: 0.328125 }, - { x: 0.671875, y: 0.328125 }, - { x: 0.703125, y: 0.328125 }, - { x: 0.703125, y: 0.328125 }, - { x: 0.734375, y: 0.328125 }, - { x: 0.734375, y: 0.328125 }, - { x: 0.765625, y: 0.328125 }, - { x: 0.765625, y: 0.328125 }, - { x: 0.796875, y: 0.328125 }, - { x: 0.796875, y: 0.328125 }, - { x: 0.828125, y: 0.328125 }, - { x: 0.828125, y: 0.328125 }, - { x: 0.859375, y: 0.328125 }, - { x: 0.859375, y: 0.328125 }, - { x: 0.890625, y: 0.328125 }, - { x: 0.890625, y: 0.328125 }, - { x: 0.921875, y: 0.328125 }, - { x: 0.921875, y: 0.328125 }, - { x: 0.953125, y: 0.328125 }, - { x: 0.953125, y: 0.328125 }, - { x: 0.984375, y: 0.328125 }, - { x: 0.984375, y: 0.328125 }, - { x: 0.015625, y: 0.359375 }, - { x: 0.015625, y: 0.359375 }, - { x: 0.046875, y: 0.359375 }, - { x: 0.046875, y: 0.359375 }, - { x: 0.078125, y: 0.359375 }, - { x: 0.078125, y: 0.359375 }, - { x: 0.109375, y: 0.359375 }, - { x: 0.109375, y: 0.359375 }, - { x: 0.140625, y: 0.359375 }, - { x: 0.140625, y: 0.359375 }, - { x: 0.171875, y: 0.359375 }, - { x: 0.171875, y: 0.359375 }, - { x: 0.203125, y: 0.359375 }, - { x: 0.203125, y: 0.359375 }, - { x: 0.234375, y: 0.359375 }, - { x: 0.234375, y: 0.359375 }, - { x: 0.265625, y: 0.359375 }, - { x: 0.265625, y: 0.359375 }, - { x: 0.296875, y: 0.359375 }, - { x: 0.296875, y: 0.359375 }, - { x: 0.328125, y: 0.359375 }, - { x: 0.328125, y: 0.359375 }, - { x: 0.359375, y: 0.359375 }, - { x: 0.359375, y: 0.359375 }, - { x: 0.390625, y: 0.359375 }, - { x: 0.390625, y: 0.359375 }, - { x: 0.421875, y: 0.359375 }, - { x: 0.421875, y: 0.359375 }, - { x: 0.453125, y: 0.359375 }, - { x: 0.453125, y: 0.359375 }, - { x: 0.484375, y: 0.359375 }, - { x: 0.484375, y: 0.359375 }, - { x: 0.515625, y: 0.359375 }, - { x: 0.515625, y: 0.359375 }, - { x: 0.546875, y: 0.359375 }, - { x: 0.546875, y: 0.359375 }, - { x: 0.578125, y: 0.359375 }, - { x: 0.578125, y: 0.359375 }, - { x: 0.609375, y: 0.359375 }, - { x: 0.609375, y: 0.359375 }, - { x: 0.640625, y: 0.359375 }, - { x: 0.640625, y: 0.359375 }, - { x: 0.671875, y: 0.359375 }, - { x: 0.671875, y: 0.359375 }, - { x: 0.703125, y: 0.359375 }, - { x: 0.703125, y: 0.359375 }, - { x: 0.734375, y: 0.359375 }, - { x: 0.734375, y: 0.359375 }, - { x: 0.765625, y: 0.359375 }, - { x: 0.765625, y: 0.359375 }, - { x: 0.796875, y: 0.359375 }, - { x: 0.796875, y: 0.359375 }, - { x: 0.828125, y: 0.359375 }, - { x: 0.828125, y: 0.359375 }, - { x: 0.859375, y: 0.359375 }, - { x: 0.859375, y: 0.359375 }, - { x: 0.890625, y: 0.359375 }, - { x: 0.890625, y: 0.359375 }, - { x: 0.921875, y: 0.359375 }, - { x: 0.921875, y: 0.359375 }, - { x: 0.953125, y: 0.359375 }, - { x: 0.953125, y: 0.359375 }, - { x: 0.984375, y: 0.359375 }, - { x: 0.984375, y: 0.359375 }, - { x: 0.015625, y: 0.390625 }, - { x: 0.015625, y: 0.390625 }, - { x: 0.046875, y: 0.390625 }, - { x: 0.046875, y: 0.390625 }, - { x: 0.078125, y: 0.390625 }, - { x: 0.078125, y: 0.390625 }, - { x: 0.109375, y: 0.390625 }, - { x: 0.109375, y: 0.390625 }, - { x: 0.140625, y: 0.390625 }, - { x: 0.140625, y: 0.390625 }, - { x: 0.171875, y: 0.390625 }, - { x: 0.171875, y: 0.390625 }, - { x: 0.203125, y: 0.390625 }, - { x: 0.203125, y: 0.390625 }, - { x: 0.234375, y: 0.390625 }, - { x: 0.234375, y: 0.390625 }, - { x: 0.265625, y: 0.390625 }, - { x: 0.265625, y: 0.390625 }, - { x: 0.296875, y: 0.390625 }, - { x: 0.296875, y: 0.390625 }, - { x: 0.328125, y: 0.390625 }, - { x: 0.328125, y: 0.390625 }, - { x: 0.359375, y: 0.390625 }, - { x: 0.359375, y: 0.390625 }, - { x: 0.390625, y: 0.390625 }, - { x: 0.390625, y: 0.390625 }, - { x: 0.421875, y: 0.390625 }, - { x: 0.421875, y: 0.390625 }, - { x: 0.453125, y: 0.390625 }, - { x: 0.453125, y: 0.390625 }, - { x: 0.484375, y: 0.390625 }, - { x: 0.484375, y: 0.390625 }, - { x: 0.515625, y: 0.390625 }, - { x: 0.515625, y: 0.390625 }, - { x: 0.546875, y: 0.390625 }, - { x: 0.546875, y: 0.390625 }, - { x: 0.578125, y: 0.390625 }, - { x: 0.578125, y: 0.390625 }, - { x: 0.609375, y: 0.390625 }, - { x: 0.609375, y: 0.390625 }, - { x: 0.640625, y: 0.390625 }, - { x: 0.640625, y: 0.390625 }, - { x: 0.671875, y: 0.390625 }, - { x: 0.671875, y: 0.390625 }, - { x: 0.703125, y: 0.390625 }, - { x: 0.703125, y: 0.390625 }, - { x: 0.734375, y: 0.390625 }, - { x: 0.734375, y: 0.390625 }, - { x: 0.765625, y: 0.390625 }, - { x: 0.765625, y: 0.390625 }, - { x: 0.796875, y: 0.390625 }, - { x: 0.796875, y: 0.390625 }, - { x: 0.828125, y: 0.390625 }, - { x: 0.828125, y: 0.390625 }, - { x: 0.859375, y: 0.390625 }, - { x: 0.859375, y: 0.390625 }, - { x: 0.890625, y: 0.390625 }, - { x: 0.890625, y: 0.390625 }, - { x: 0.921875, y: 0.390625 }, - { x: 0.921875, y: 0.390625 }, - { x: 0.953125, y: 0.390625 }, - { x: 0.953125, y: 0.390625 }, - { x: 0.984375, y: 0.390625 }, - { x: 0.984375, y: 0.390625 }, - { x: 0.015625, y: 0.421875 }, - { x: 0.015625, y: 0.421875 }, - { x: 0.046875, y: 0.421875 }, - { x: 0.046875, y: 0.421875 }, - { x: 0.078125, y: 0.421875 }, - { x: 0.078125, y: 0.421875 }, - { x: 0.109375, y: 0.421875 }, - { x: 0.109375, y: 0.421875 }, - { x: 0.140625, y: 0.421875 }, - { x: 0.140625, y: 0.421875 }, - { x: 0.171875, y: 0.421875 }, - { x: 0.171875, y: 0.421875 }, - { x: 0.203125, y: 0.421875 }, - { x: 0.203125, y: 0.421875 }, - { x: 0.234375, y: 0.421875 }, - { x: 0.234375, y: 0.421875 }, - { x: 0.265625, y: 0.421875 }, - { x: 0.265625, y: 0.421875 }, - { x: 0.296875, y: 0.421875 }, - { x: 0.296875, y: 0.421875 }, - { x: 0.328125, y: 0.421875 }, - { x: 0.328125, y: 0.421875 }, - { x: 0.359375, y: 0.421875 }, - { x: 0.359375, y: 0.421875 }, - { x: 0.390625, y: 0.421875 }, - { x: 0.390625, y: 0.421875 }, - { x: 0.421875, y: 0.421875 }, - { x: 0.421875, y: 0.421875 }, - { x: 0.453125, y: 0.421875 }, - { x: 0.453125, y: 0.421875 }, - { x: 0.484375, y: 0.421875 }, - { x: 0.484375, y: 0.421875 }, - { x: 0.515625, y: 0.421875 }, - { x: 0.515625, y: 0.421875 }, - { x: 0.546875, y: 0.421875 }, - { x: 0.546875, y: 0.421875 }, - { x: 0.578125, y: 0.421875 }, - { x: 0.578125, y: 0.421875 }, - { x: 0.609375, y: 0.421875 }, - { x: 0.609375, y: 0.421875 }, - { x: 0.640625, y: 0.421875 }, - { x: 0.640625, y: 0.421875 }, - { x: 0.671875, y: 0.421875 }, - { x: 0.671875, y: 0.421875 }, - { x: 0.703125, y: 0.421875 }, - { x: 0.703125, y: 0.421875 }, - { x: 0.734375, y: 0.421875 }, - { x: 0.734375, y: 0.421875 }, - { x: 0.765625, y: 0.421875 }, - { x: 0.765625, y: 0.421875 }, - { x: 0.796875, y: 0.421875 }, - { x: 0.796875, y: 0.421875 }, - { x: 0.828125, y: 0.421875 }, - { x: 0.828125, y: 0.421875 }, - { x: 0.859375, y: 0.421875 }, - { x: 0.859375, y: 0.421875 }, - { x: 0.890625, y: 0.421875 }, - { x: 0.890625, y: 0.421875 }, - { x: 0.921875, y: 0.421875 }, - { x: 0.921875, y: 0.421875 }, - { x: 0.953125, y: 0.421875 }, - { x: 0.953125, y: 0.421875 }, - { x: 0.984375, y: 0.421875 }, - { x: 0.984375, y: 0.421875 }, - { x: 0.015625, y: 0.453125 }, - { x: 0.015625, y: 0.453125 }, - { x: 0.046875, y: 0.453125 }, - { x: 0.046875, y: 0.453125 }, - { x: 0.078125, y: 0.453125 }, - { x: 0.078125, y: 0.453125 }, - { x: 0.109375, y: 0.453125 }, - { x: 0.109375, y: 0.453125 }, - { x: 0.140625, y: 0.453125 }, - { x: 0.140625, y: 0.453125 }, - { x: 0.171875, y: 0.453125 }, - { x: 0.171875, y: 0.453125 }, - { x: 0.203125, y: 0.453125 }, - { x: 0.203125, y: 0.453125 }, - { x: 0.234375, y: 0.453125 }, - { x: 0.234375, y: 0.453125 }, - { x: 0.265625, y: 0.453125 }, - { x: 0.265625, y: 0.453125 }, - { x: 0.296875, y: 0.453125 }, - { x: 0.296875, y: 0.453125 }, - { x: 0.328125, y: 0.453125 }, - { x: 0.328125, y: 0.453125 }, - { x: 0.359375, y: 0.453125 }, - { x: 0.359375, y: 0.453125 }, - { x: 0.390625, y: 0.453125 }, - { x: 0.390625, y: 0.453125 }, - { x: 0.421875, y: 0.453125 }, - { x: 0.421875, y: 0.453125 }, - { x: 0.453125, y: 0.453125 }, - { x: 0.453125, y: 0.453125 }, - { x: 0.484375, y: 0.453125 }, - { x: 0.484375, y: 0.453125 }, - { x: 0.515625, y: 0.453125 }, - { x: 0.515625, y: 0.453125 }, - { x: 0.546875, y: 0.453125 }, - { x: 0.546875, y: 0.453125 }, - { x: 0.578125, y: 0.453125 }, - { x: 0.578125, y: 0.453125 }, - { x: 0.609375, y: 0.453125 }, - { x: 0.609375, y: 0.453125 }, - { x: 0.640625, y: 0.453125 }, - { x: 0.640625, y: 0.453125 }, - { x: 0.671875, y: 0.453125 }, - { x: 0.671875, y: 0.453125 }, - { x: 0.703125, y: 0.453125 }, - { x: 0.703125, y: 0.453125 }, - { x: 0.734375, y: 0.453125 }, - { x: 0.734375, y: 0.453125 }, - { x: 0.765625, y: 0.453125 }, - { x: 0.765625, y: 0.453125 }, - { x: 0.796875, y: 0.453125 }, - { x: 0.796875, y: 0.453125 }, - { x: 0.828125, y: 0.453125 }, - { x: 0.828125, y: 0.453125 }, - { x: 0.859375, y: 0.453125 }, - { x: 0.859375, y: 0.453125 }, - { x: 0.890625, y: 0.453125 }, - { x: 0.890625, y: 0.453125 }, - { x: 0.921875, y: 0.453125 }, - { x: 0.921875, y: 0.453125 }, - { x: 0.953125, y: 0.453125 }, - { x: 0.953125, y: 0.453125 }, - { x: 0.984375, y: 0.453125 }, - { x: 0.984375, y: 0.453125 }, - { x: 0.015625, y: 0.484375 }, - { x: 0.015625, y: 0.484375 }, - { x: 0.046875, y: 0.484375 }, - { x: 0.046875, y: 0.484375 }, - { x: 0.078125, y: 0.484375 }, - { x: 0.078125, y: 0.484375 }, - { x: 0.109375, y: 0.484375 }, - { x: 0.109375, y: 0.484375 }, - { x: 0.140625, y: 0.484375 }, - { x: 0.140625, y: 0.484375 }, - { x: 0.171875, y: 0.484375 }, - { x: 0.171875, y: 0.484375 }, - { x: 0.203125, y: 0.484375 }, - { x: 0.203125, y: 0.484375 }, - { x: 0.234375, y: 0.484375 }, - { x: 0.234375, y: 0.484375 }, - { x: 0.265625, y: 0.484375 }, - { x: 0.265625, y: 0.484375 }, - { x: 0.296875, y: 0.484375 }, - { x: 0.296875, y: 0.484375 }, - { x: 0.328125, y: 0.484375 }, - { x: 0.328125, y: 0.484375 }, - { x: 0.359375, y: 0.484375 }, - { x: 0.359375, y: 0.484375 }, - { x: 0.390625, y: 0.484375 }, - { x: 0.390625, y: 0.484375 }, - { x: 0.421875, y: 0.484375 }, - { x: 0.421875, y: 0.484375 }, - { x: 0.453125, y: 0.484375 }, - { x: 0.453125, y: 0.484375 }, - { x: 0.484375, y: 0.484375 }, - { x: 0.484375, y: 0.484375 }, - { x: 0.515625, y: 0.484375 }, - { x: 0.515625, y: 0.484375 }, - { x: 0.546875, y: 0.484375 }, - { x: 0.546875, y: 0.484375 }, - { x: 0.578125, y: 0.484375 }, - { x: 0.578125, y: 0.484375 }, - { x: 0.609375, y: 0.484375 }, - { x: 0.609375, y: 0.484375 }, - { x: 0.640625, y: 0.484375 }, - { x: 0.640625, y: 0.484375 }, - { x: 0.671875, y: 0.484375 }, - { x: 0.671875, y: 0.484375 }, - { x: 0.703125, y: 0.484375 }, - { x: 0.703125, y: 0.484375 }, - { x: 0.734375, y: 0.484375 }, - { x: 0.734375, y: 0.484375 }, - { x: 0.765625, y: 0.484375 }, - { x: 0.765625, y: 0.484375 }, - { x: 0.796875, y: 0.484375 }, - { x: 0.796875, y: 0.484375 }, - { x: 0.828125, y: 0.484375 }, - { x: 0.828125, y: 0.484375 }, - { x: 0.859375, y: 0.484375 }, - { x: 0.859375, y: 0.484375 }, - { x: 0.890625, y: 0.484375 }, - { x: 0.890625, y: 0.484375 }, - { x: 0.921875, y: 0.484375 }, - { x: 0.921875, y: 0.484375 }, - { x: 0.953125, y: 0.484375 }, - { x: 0.953125, y: 0.484375 }, - { x: 0.984375, y: 0.484375 }, - { x: 0.984375, y: 0.484375 }, - { x: 0.015625, y: 0.515625 }, - { x: 0.015625, y: 0.515625 }, - { x: 0.046875, y: 0.515625 }, - { x: 0.046875, y: 0.515625 }, - { x: 0.078125, y: 0.515625 }, - { x: 0.078125, y: 0.515625 }, - { x: 0.109375, y: 0.515625 }, - { x: 0.109375, y: 0.515625 }, - { x: 0.140625, y: 0.515625 }, - { x: 0.140625, y: 0.515625 }, - { x: 0.171875, y: 0.515625 }, - { x: 0.171875, y: 0.515625 }, - { x: 0.203125, y: 0.515625 }, - { x: 0.203125, y: 0.515625 }, - { x: 0.234375, y: 0.515625 }, - { x: 0.234375, y: 0.515625 }, - { x: 0.265625, y: 0.515625 }, - { x: 0.265625, y: 0.515625 }, - { x: 0.296875, y: 0.515625 }, - { x: 0.296875, y: 0.515625 }, - { x: 0.328125, y: 0.515625 }, - { x: 0.328125, y: 0.515625 }, - { x: 0.359375, y: 0.515625 }, - { x: 0.359375, y: 0.515625 }, - { x: 0.390625, y: 0.515625 }, - { x: 0.390625, y: 0.515625 }, - { x: 0.421875, y: 0.515625 }, - { x: 0.421875, y: 0.515625 }, - { x: 0.453125, y: 0.515625 }, - { x: 0.453125, y: 0.515625 }, - { x: 0.484375, y: 0.515625 }, - { x: 0.484375, y: 0.515625 }, - { x: 0.515625, y: 0.515625 }, - { x: 0.515625, y: 0.515625 }, - { x: 0.546875, y: 0.515625 }, - { x: 0.546875, y: 0.515625 }, - { x: 0.578125, y: 0.515625 }, - { x: 0.578125, y: 0.515625 }, - { x: 0.609375, y: 0.515625 }, - { x: 0.609375, y: 0.515625 }, - { x: 0.640625, y: 0.515625 }, - { x: 0.640625, y: 0.515625 }, - { x: 0.671875, y: 0.515625 }, - { x: 0.671875, y: 0.515625 }, - { x: 0.703125, y: 0.515625 }, - { x: 0.703125, y: 0.515625 }, - { x: 0.734375, y: 0.515625 }, - { x: 0.734375, y: 0.515625 }, - { x: 0.765625, y: 0.515625 }, - { x: 0.765625, y: 0.515625 }, - { x: 0.796875, y: 0.515625 }, - { x: 0.796875, y: 0.515625 }, - { x: 0.828125, y: 0.515625 }, - { x: 0.828125, y: 0.515625 }, - { x: 0.859375, y: 0.515625 }, - { x: 0.859375, y: 0.515625 }, - { x: 0.890625, y: 0.515625 }, - { x: 0.890625, y: 0.515625 }, - { x: 0.921875, y: 0.515625 }, - { x: 0.921875, y: 0.515625 }, - { x: 0.953125, y: 0.515625 }, - { x: 0.953125, y: 0.515625 }, - { x: 0.984375, y: 0.515625 }, - { x: 0.984375, y: 0.515625 }, - { x: 0.015625, y: 0.546875 }, - { x: 0.015625, y: 0.546875 }, - { x: 0.046875, y: 0.546875 }, - { x: 0.046875, y: 0.546875 }, - { x: 0.078125, y: 0.546875 }, - { x: 0.078125, y: 0.546875 }, - { x: 0.109375, y: 0.546875 }, - { x: 0.109375, y: 0.546875 }, - { x: 0.140625, y: 0.546875 }, - { x: 0.140625, y: 0.546875 }, - { x: 0.171875, y: 0.546875 }, - { x: 0.171875, y: 0.546875 }, - { x: 0.203125, y: 0.546875 }, - { x: 0.203125, y: 0.546875 }, - { x: 0.234375, y: 0.546875 }, - { x: 0.234375, y: 0.546875 }, - { x: 0.265625, y: 0.546875 }, - { x: 0.265625, y: 0.546875 }, - { x: 0.296875, y: 0.546875 }, - { x: 0.296875, y: 0.546875 }, - { x: 0.328125, y: 0.546875 }, - { x: 0.328125, y: 0.546875 }, - { x: 0.359375, y: 0.546875 }, - { x: 0.359375, y: 0.546875 }, - { x: 0.390625, y: 0.546875 }, - { x: 0.390625, y: 0.546875 }, - { x: 0.421875, y: 0.546875 }, - { x: 0.421875, y: 0.546875 }, - { x: 0.453125, y: 0.546875 }, - { x: 0.453125, y: 0.546875 }, - { x: 0.484375, y: 0.546875 }, - { x: 0.484375, y: 0.546875 }, - { x: 0.515625, y: 0.546875 }, - { x: 0.515625, y: 0.546875 }, - { x: 0.546875, y: 0.546875 }, - { x: 0.546875, y: 0.546875 }, - { x: 0.578125, y: 0.546875 }, - { x: 0.578125, y: 0.546875 }, - { x: 0.609375, y: 0.546875 }, - { x: 0.609375, y: 0.546875 }, - { x: 0.640625, y: 0.546875 }, - { x: 0.640625, y: 0.546875 }, - { x: 0.671875, y: 0.546875 }, - { x: 0.671875, y: 0.546875 }, - { x: 0.703125, y: 0.546875 }, - { x: 0.703125, y: 0.546875 }, - { x: 0.734375, y: 0.546875 }, - { x: 0.734375, y: 0.546875 }, - { x: 0.765625, y: 0.546875 }, - { x: 0.765625, y: 0.546875 }, - { x: 0.796875, y: 0.546875 }, - { x: 0.796875, y: 0.546875 }, - { x: 0.828125, y: 0.546875 }, - { x: 0.828125, y: 0.546875 }, - { x: 0.859375, y: 0.546875 }, - { x: 0.859375, y: 0.546875 }, - { x: 0.890625, y: 0.546875 }, - { x: 0.890625, y: 0.546875 }, - { x: 0.921875, y: 0.546875 }, - { x: 0.921875, y: 0.546875 }, - { x: 0.953125, y: 0.546875 }, - { x: 0.953125, y: 0.546875 }, - { x: 0.984375, y: 0.546875 }, - { x: 0.984375, y: 0.546875 }, - { x: 0.015625, y: 0.578125 }, - { x: 0.015625, y: 0.578125 }, - { x: 0.046875, y: 0.578125 }, - { x: 0.046875, y: 0.578125 }, - { x: 0.078125, y: 0.578125 }, - { x: 0.078125, y: 0.578125 }, - { x: 0.109375, y: 0.578125 }, - { x: 0.109375, y: 0.578125 }, - { x: 0.140625, y: 0.578125 }, - { x: 0.140625, y: 0.578125 }, - { x: 0.171875, y: 0.578125 }, - { x: 0.171875, y: 0.578125 }, - { x: 0.203125, y: 0.578125 }, - { x: 0.203125, y: 0.578125 }, - { x: 0.234375, y: 0.578125 }, - { x: 0.234375, y: 0.578125 }, - { x: 0.265625, y: 0.578125 }, - { x: 0.265625, y: 0.578125 }, - { x: 0.296875, y: 0.578125 }, - { x: 0.296875, y: 0.578125 }, - { x: 0.328125, y: 0.578125 }, - { x: 0.328125, y: 0.578125 }, - { x: 0.359375, y: 0.578125 }, - { x: 0.359375, y: 0.578125 }, - { x: 0.390625, y: 0.578125 }, - { x: 0.390625, y: 0.578125 }, - { x: 0.421875, y: 0.578125 }, - { x: 0.421875, y: 0.578125 }, - { x: 0.453125, y: 0.578125 }, - { x: 0.453125, y: 0.578125 }, - { x: 0.484375, y: 0.578125 }, - { x: 0.484375, y: 0.578125 }, - { x: 0.515625, y: 0.578125 }, - { x: 0.515625, y: 0.578125 }, - { x: 0.546875, y: 0.578125 }, - { x: 0.546875, y: 0.578125 }, - { x: 0.578125, y: 0.578125 }, - { x: 0.578125, y: 0.578125 }, - { x: 0.609375, y: 0.578125 }, - { x: 0.609375, y: 0.578125 }, - { x: 0.640625, y: 0.578125 }, - { x: 0.640625, y: 0.578125 }, - { x: 0.671875, y: 0.578125 }, - { x: 0.671875, y: 0.578125 }, - { x: 0.703125, y: 0.578125 }, - { x: 0.703125, y: 0.578125 }, - { x: 0.734375, y: 0.578125 }, - { x: 0.734375, y: 0.578125 }, - { x: 0.765625, y: 0.578125 }, - { x: 0.765625, y: 0.578125 }, - { x: 0.796875, y: 0.578125 }, - { x: 0.796875, y: 0.578125 }, - { x: 0.828125, y: 0.578125 }, - { x: 0.828125, y: 0.578125 }, - { x: 0.859375, y: 0.578125 }, - { x: 0.859375, y: 0.578125 }, - { x: 0.890625, y: 0.578125 }, - { x: 0.890625, y: 0.578125 }, - { x: 0.921875, y: 0.578125 }, - { x: 0.921875, y: 0.578125 }, - { x: 0.953125, y: 0.578125 }, - { x: 0.953125, y: 0.578125 }, - { x: 0.984375, y: 0.578125 }, - { x: 0.984375, y: 0.578125 }, - { x: 0.015625, y: 0.609375 }, - { x: 0.015625, y: 0.609375 }, - { x: 0.046875, y: 0.609375 }, - { x: 0.046875, y: 0.609375 }, - { x: 0.078125, y: 0.609375 }, - { x: 0.078125, y: 0.609375 }, - { x: 0.109375, y: 0.609375 }, - { x: 0.109375, y: 0.609375 }, - { x: 0.140625, y: 0.609375 }, - { x: 0.140625, y: 0.609375 }, - { x: 0.171875, y: 0.609375 }, - { x: 0.171875, y: 0.609375 }, - { x: 0.203125, y: 0.609375 }, - { x: 0.203125, y: 0.609375 }, - { x: 0.234375, y: 0.609375 }, - { x: 0.234375, y: 0.609375 }, - { x: 0.265625, y: 0.609375 }, - { x: 0.265625, y: 0.609375 }, - { x: 0.296875, y: 0.609375 }, - { x: 0.296875, y: 0.609375 }, - { x: 0.328125, y: 0.609375 }, - { x: 0.328125, y: 0.609375 }, - { x: 0.359375, y: 0.609375 }, - { x: 0.359375, y: 0.609375 }, - { x: 0.390625, y: 0.609375 }, - { x: 0.390625, y: 0.609375 }, - { x: 0.421875, y: 0.609375 }, - { x: 0.421875, y: 0.609375 }, - { x: 0.453125, y: 0.609375 }, - { x: 0.453125, y: 0.609375 }, - { x: 0.484375, y: 0.609375 }, - { x: 0.484375, y: 0.609375 }, - { x: 0.515625, y: 0.609375 }, - { x: 0.515625, y: 0.609375 }, - { x: 0.546875, y: 0.609375 }, - { x: 0.546875, y: 0.609375 }, - { x: 0.578125, y: 0.609375 }, - { x: 0.578125, y: 0.609375 }, - { x: 0.609375, y: 0.609375 }, - { x: 0.609375, y: 0.609375 }, - { x: 0.640625, y: 0.609375 }, - { x: 0.640625, y: 0.609375 }, - { x: 0.671875, y: 0.609375 }, - { x: 0.671875, y: 0.609375 }, - { x: 0.703125, y: 0.609375 }, - { x: 0.703125, y: 0.609375 }, - { x: 0.734375, y: 0.609375 }, - { x: 0.734375, y: 0.609375 }, - { x: 0.765625, y: 0.609375 }, - { x: 0.765625, y: 0.609375 }, - { x: 0.796875, y: 0.609375 }, - { x: 0.796875, y: 0.609375 }, - { x: 0.828125, y: 0.609375 }, - { x: 0.828125, y: 0.609375 }, - { x: 0.859375, y: 0.609375 }, - { x: 0.859375, y: 0.609375 }, - { x: 0.890625, y: 0.609375 }, - { x: 0.890625, y: 0.609375 }, - { x: 0.921875, y: 0.609375 }, - { x: 0.921875, y: 0.609375 }, - { x: 0.953125, y: 0.609375 }, - { x: 0.953125, y: 0.609375 }, - { x: 0.984375, y: 0.609375 }, - { x: 0.984375, y: 0.609375 }, - { x: 0.015625, y: 0.640625 }, - { x: 0.015625, y: 0.640625 }, - { x: 0.046875, y: 0.640625 }, - { x: 0.046875, y: 0.640625 }, - { x: 0.078125, y: 0.640625 }, - { x: 0.078125, y: 0.640625 }, - { x: 0.109375, y: 0.640625 }, - { x: 0.109375, y: 0.640625 }, - { x: 0.140625, y: 0.640625 }, - { x: 0.140625, y: 0.640625 }, - { x: 0.171875, y: 0.640625 }, - { x: 0.171875, y: 0.640625 }, - { x: 0.203125, y: 0.640625 }, - { x: 0.203125, y: 0.640625 }, - { x: 0.234375, y: 0.640625 }, - { x: 0.234375, y: 0.640625 }, - { x: 0.265625, y: 0.640625 }, - { x: 0.265625, y: 0.640625 }, - { x: 0.296875, y: 0.640625 }, - { x: 0.296875, y: 0.640625 }, - { x: 0.328125, y: 0.640625 }, - { x: 0.328125, y: 0.640625 }, - { x: 0.359375, y: 0.640625 }, - { x: 0.359375, y: 0.640625 }, - { x: 0.390625, y: 0.640625 }, - { x: 0.390625, y: 0.640625 }, - { x: 0.421875, y: 0.640625 }, - { x: 0.421875, y: 0.640625 }, - { x: 0.453125, y: 0.640625 }, - { x: 0.453125, y: 0.640625 }, - { x: 0.484375, y: 0.640625 }, - { x: 0.484375, y: 0.640625 }, - { x: 0.515625, y: 0.640625 }, - { x: 0.515625, y: 0.640625 }, - { x: 0.546875, y: 0.640625 }, - { x: 0.546875, y: 0.640625 }, - { x: 0.578125, y: 0.640625 }, - { x: 0.578125, y: 0.640625 }, - { x: 0.609375, y: 0.640625 }, - { x: 0.609375, y: 0.640625 }, - { x: 0.640625, y: 0.640625 }, - { x: 0.640625, y: 0.640625 }, - { x: 0.671875, y: 0.640625 }, - { x: 0.671875, y: 0.640625 }, - { x: 0.703125, y: 0.640625 }, - { x: 0.703125, y: 0.640625 }, - { x: 0.734375, y: 0.640625 }, - { x: 0.734375, y: 0.640625 }, - { x: 0.765625, y: 0.640625 }, - { x: 0.765625, y: 0.640625 }, - { x: 0.796875, y: 0.640625 }, - { x: 0.796875, y: 0.640625 }, - { x: 0.828125, y: 0.640625 }, - { x: 0.828125, y: 0.640625 }, - { x: 0.859375, y: 0.640625 }, - { x: 0.859375, y: 0.640625 }, - { x: 0.890625, y: 0.640625 }, - { x: 0.890625, y: 0.640625 }, - { x: 0.921875, y: 0.640625 }, - { x: 0.921875, y: 0.640625 }, - { x: 0.953125, y: 0.640625 }, - { x: 0.953125, y: 0.640625 }, - { x: 0.984375, y: 0.640625 }, - { x: 0.984375, y: 0.640625 }, - { x: 0.015625, y: 0.671875 }, - { x: 0.015625, y: 0.671875 }, - { x: 0.046875, y: 0.671875 }, - { x: 0.046875, y: 0.671875 }, - { x: 0.078125, y: 0.671875 }, - { x: 0.078125, y: 0.671875 }, - { x: 0.109375, y: 0.671875 }, - { x: 0.109375, y: 0.671875 }, - { x: 0.140625, y: 0.671875 }, - { x: 0.140625, y: 0.671875 }, - { x: 0.171875, y: 0.671875 }, - { x: 0.171875, y: 0.671875 }, - { x: 0.203125, y: 0.671875 }, - { x: 0.203125, y: 0.671875 }, - { x: 0.234375, y: 0.671875 }, - { x: 0.234375, y: 0.671875 }, - { x: 0.265625, y: 0.671875 }, - { x: 0.265625, y: 0.671875 }, - { x: 0.296875, y: 0.671875 }, - { x: 0.296875, y: 0.671875 }, - { x: 0.328125, y: 0.671875 }, - { x: 0.328125, y: 0.671875 }, - { x: 0.359375, y: 0.671875 }, - { x: 0.359375, y: 0.671875 }, - { x: 0.390625, y: 0.671875 }, - { x: 0.390625, y: 0.671875 }, - { x: 0.421875, y: 0.671875 }, - { x: 0.421875, y: 0.671875 }, - { x: 0.453125, y: 0.671875 }, - { x: 0.453125, y: 0.671875 }, - { x: 0.484375, y: 0.671875 }, - { x: 0.484375, y: 0.671875 }, - { x: 0.515625, y: 0.671875 }, - { x: 0.515625, y: 0.671875 }, - { x: 0.546875, y: 0.671875 }, - { x: 0.546875, y: 0.671875 }, - { x: 0.578125, y: 0.671875 }, - { x: 0.578125, y: 0.671875 }, - { x: 0.609375, y: 0.671875 }, - { x: 0.609375, y: 0.671875 }, - { x: 0.640625, y: 0.671875 }, - { x: 0.640625, y: 0.671875 }, - { x: 0.671875, y: 0.671875 }, - { x: 0.671875, y: 0.671875 }, - { x: 0.703125, y: 0.671875 }, - { x: 0.703125, y: 0.671875 }, - { x: 0.734375, y: 0.671875 }, - { x: 0.734375, y: 0.671875 }, - { x: 0.765625, y: 0.671875 }, - { x: 0.765625, y: 0.671875 }, - { x: 0.796875, y: 0.671875 }, - { x: 0.796875, y: 0.671875 }, - { x: 0.828125, y: 0.671875 }, - { x: 0.828125, y: 0.671875 }, - { x: 0.859375, y: 0.671875 }, - { x: 0.859375, y: 0.671875 }, - { x: 0.890625, y: 0.671875 }, - { x: 0.890625, y: 0.671875 }, - { x: 0.921875, y: 0.671875 }, - { x: 0.921875, y: 0.671875 }, - { x: 0.953125, y: 0.671875 }, - { x: 0.953125, y: 0.671875 }, - { x: 0.984375, y: 0.671875 }, - { x: 0.984375, y: 0.671875 }, - { x: 0.015625, y: 0.703125 }, - { x: 0.015625, y: 0.703125 }, - { x: 0.046875, y: 0.703125 }, - { x: 0.046875, y: 0.703125 }, - { x: 0.078125, y: 0.703125 }, - { x: 0.078125, y: 0.703125 }, - { x: 0.109375, y: 0.703125 }, - { x: 0.109375, y: 0.703125 }, - { x: 0.140625, y: 0.703125 }, - { x: 0.140625, y: 0.703125 }, - { x: 0.171875, y: 0.703125 }, - { x: 0.171875, y: 0.703125 }, - { x: 0.203125, y: 0.703125 }, - { x: 0.203125, y: 0.703125 }, - { x: 0.234375, y: 0.703125 }, - { x: 0.234375, y: 0.703125 }, - { x: 0.265625, y: 0.703125 }, - { x: 0.265625, y: 0.703125 }, - { x: 0.296875, y: 0.703125 }, - { x: 0.296875, y: 0.703125 }, - { x: 0.328125, y: 0.703125 }, - { x: 0.328125, y: 0.703125 }, - { x: 0.359375, y: 0.703125 }, - { x: 0.359375, y: 0.703125 }, - { x: 0.390625, y: 0.703125 }, - { x: 0.390625, y: 0.703125 }, - { x: 0.421875, y: 0.703125 }, - { x: 0.421875, y: 0.703125 }, - { x: 0.453125, y: 0.703125 }, - { x: 0.453125, y: 0.703125 }, - { x: 0.484375, y: 0.703125 }, - { x: 0.484375, y: 0.703125 }, - { x: 0.515625, y: 0.703125 }, - { x: 0.515625, y: 0.703125 }, - { x: 0.546875, y: 0.703125 }, - { x: 0.546875, y: 0.703125 }, - { x: 0.578125, y: 0.703125 }, - { x: 0.578125, y: 0.703125 }, - { x: 0.609375, y: 0.703125 }, - { x: 0.609375, y: 0.703125 }, - { x: 0.640625, y: 0.703125 }, - { x: 0.640625, y: 0.703125 }, - { x: 0.671875, y: 0.703125 }, - { x: 0.671875, y: 0.703125 }, - { x: 0.703125, y: 0.703125 }, - { x: 0.703125, y: 0.703125 }, - { x: 0.734375, y: 0.703125 }, - { x: 0.734375, y: 0.703125 }, - { x: 0.765625, y: 0.703125 }, - { x: 0.765625, y: 0.703125 }, - { x: 0.796875, y: 0.703125 }, - { x: 0.796875, y: 0.703125 }, - { x: 0.828125, y: 0.703125 }, - { x: 0.828125, y: 0.703125 }, - { x: 0.859375, y: 0.703125 }, - { x: 0.859375, y: 0.703125 }, - { x: 0.890625, y: 0.703125 }, - { x: 0.890625, y: 0.703125 }, - { x: 0.921875, y: 0.703125 }, - { x: 0.921875, y: 0.703125 }, - { x: 0.953125, y: 0.703125 }, - { x: 0.953125, y: 0.703125 }, - { x: 0.984375, y: 0.703125 }, - { x: 0.984375, y: 0.703125 }, - { x: 0.015625, y: 0.734375 }, - { x: 0.015625, y: 0.734375 }, - { x: 0.046875, y: 0.734375 }, - { x: 0.046875, y: 0.734375 }, - { x: 0.078125, y: 0.734375 }, - { x: 0.078125, y: 0.734375 }, - { x: 0.109375, y: 0.734375 }, - { x: 0.109375, y: 0.734375 }, - { x: 0.140625, y: 0.734375 }, - { x: 0.140625, y: 0.734375 }, - { x: 0.171875, y: 0.734375 }, - { x: 0.171875, y: 0.734375 }, - { x: 0.203125, y: 0.734375 }, - { x: 0.203125, y: 0.734375 }, - { x: 0.234375, y: 0.734375 }, - { x: 0.234375, y: 0.734375 }, - { x: 0.265625, y: 0.734375 }, - { x: 0.265625, y: 0.734375 }, - { x: 0.296875, y: 0.734375 }, - { x: 0.296875, y: 0.734375 }, - { x: 0.328125, y: 0.734375 }, - { x: 0.328125, y: 0.734375 }, - { x: 0.359375, y: 0.734375 }, - { x: 0.359375, y: 0.734375 }, - { x: 0.390625, y: 0.734375 }, - { x: 0.390625, y: 0.734375 }, - { x: 0.421875, y: 0.734375 }, - { x: 0.421875, y: 0.734375 }, - { x: 0.453125, y: 0.734375 }, - { x: 0.453125, y: 0.734375 }, - { x: 0.484375, y: 0.734375 }, - { x: 0.484375, y: 0.734375 }, - { x: 0.515625, y: 0.734375 }, - { x: 0.515625, y: 0.734375 }, - { x: 0.546875, y: 0.734375 }, - { x: 0.546875, y: 0.734375 }, - { x: 0.578125, y: 0.734375 }, - { x: 0.578125, y: 0.734375 }, - { x: 0.609375, y: 0.734375 }, - { x: 0.609375, y: 0.734375 }, - { x: 0.640625, y: 0.734375 }, - { x: 0.640625, y: 0.734375 }, - { x: 0.671875, y: 0.734375 }, - { x: 0.671875, y: 0.734375 }, - { x: 0.703125, y: 0.734375 }, - { x: 0.703125, y: 0.734375 }, - { x: 0.734375, y: 0.734375 }, - { x: 0.734375, y: 0.734375 }, - { x: 0.765625, y: 0.734375 }, - { x: 0.765625, y: 0.734375 }, - { x: 0.796875, y: 0.734375 }, - { x: 0.796875, y: 0.734375 }, - { x: 0.828125, y: 0.734375 }, - { x: 0.828125, y: 0.734375 }, - { x: 0.859375, y: 0.734375 }, - { x: 0.859375, y: 0.734375 }, - { x: 0.890625, y: 0.734375 }, - { x: 0.890625, y: 0.734375 }, - { x: 0.921875, y: 0.734375 }, - { x: 0.921875, y: 0.734375 }, - { x: 0.953125, y: 0.734375 }, - { x: 0.953125, y: 0.734375 }, - { x: 0.984375, y: 0.734375 }, - { x: 0.984375, y: 0.734375 }, - { x: 0.015625, y: 0.765625 }, - { x: 0.015625, y: 0.765625 }, - { x: 0.046875, y: 0.765625 }, - { x: 0.046875, y: 0.765625 }, - { x: 0.078125, y: 0.765625 }, - { x: 0.078125, y: 0.765625 }, - { x: 0.109375, y: 0.765625 }, - { x: 0.109375, y: 0.765625 }, - { x: 0.140625, y: 0.765625 }, - { x: 0.140625, y: 0.765625 }, - { x: 0.171875, y: 0.765625 }, - { x: 0.171875, y: 0.765625 }, - { x: 0.203125, y: 0.765625 }, - { x: 0.203125, y: 0.765625 }, - { x: 0.234375, y: 0.765625 }, - { x: 0.234375, y: 0.765625 }, - { x: 0.265625, y: 0.765625 }, - { x: 0.265625, y: 0.765625 }, - { x: 0.296875, y: 0.765625 }, - { x: 0.296875, y: 0.765625 }, - { x: 0.328125, y: 0.765625 }, - { x: 0.328125, y: 0.765625 }, - { x: 0.359375, y: 0.765625 }, - { x: 0.359375, y: 0.765625 }, - { x: 0.390625, y: 0.765625 }, - { x: 0.390625, y: 0.765625 }, - { x: 0.421875, y: 0.765625 }, - { x: 0.421875, y: 0.765625 }, - { x: 0.453125, y: 0.765625 }, - { x: 0.453125, y: 0.765625 }, - { x: 0.484375, y: 0.765625 }, - { x: 0.484375, y: 0.765625 }, - { x: 0.515625, y: 0.765625 }, - { x: 0.515625, y: 0.765625 }, - { x: 0.546875, y: 0.765625 }, - { x: 0.546875, y: 0.765625 }, - { x: 0.578125, y: 0.765625 }, - { x: 0.578125, y: 0.765625 }, - { x: 0.609375, y: 0.765625 }, - { x: 0.609375, y: 0.765625 }, - { x: 0.640625, y: 0.765625 }, - { x: 0.640625, y: 0.765625 }, - { x: 0.671875, y: 0.765625 }, - { x: 0.671875, y: 0.765625 }, - { x: 0.703125, y: 0.765625 }, - { x: 0.703125, y: 0.765625 }, - { x: 0.734375, y: 0.765625 }, - { x: 0.734375, y: 0.765625 }, - { x: 0.765625, y: 0.765625 }, - { x: 0.765625, y: 0.765625 }, - { x: 0.796875, y: 0.765625 }, - { x: 0.796875, y: 0.765625 }, - { x: 0.828125, y: 0.765625 }, - { x: 0.828125, y: 0.765625 }, - { x: 0.859375, y: 0.765625 }, - { x: 0.859375, y: 0.765625 }, - { x: 0.890625, y: 0.765625 }, - { x: 0.890625, y: 0.765625 }, - { x: 0.921875, y: 0.765625 }, - { x: 0.921875, y: 0.765625 }, - { x: 0.953125, y: 0.765625 }, - { x: 0.953125, y: 0.765625 }, - { x: 0.984375, y: 0.765625 }, - { x: 0.984375, y: 0.765625 }, - { x: 0.015625, y: 0.796875 }, - { x: 0.015625, y: 0.796875 }, - { x: 0.046875, y: 0.796875 }, - { x: 0.046875, y: 0.796875 }, - { x: 0.078125, y: 0.796875 }, - { x: 0.078125, y: 0.796875 }, - { x: 0.109375, y: 0.796875 }, - { x: 0.109375, y: 0.796875 }, - { x: 0.140625, y: 0.796875 }, - { x: 0.140625, y: 0.796875 }, - { x: 0.171875, y: 0.796875 }, - { x: 0.171875, y: 0.796875 }, - { x: 0.203125, y: 0.796875 }, - { x: 0.203125, y: 0.796875 }, - { x: 0.234375, y: 0.796875 }, - { x: 0.234375, y: 0.796875 }, - { x: 0.265625, y: 0.796875 }, - { x: 0.265625, y: 0.796875 }, - { x: 0.296875, y: 0.796875 }, - { x: 0.296875, y: 0.796875 }, - { x: 0.328125, y: 0.796875 }, - { x: 0.328125, y: 0.796875 }, - { x: 0.359375, y: 0.796875 }, - { x: 0.359375, y: 0.796875 }, - { x: 0.390625, y: 0.796875 }, - { x: 0.390625, y: 0.796875 }, - { x: 0.421875, y: 0.796875 }, - { x: 0.421875, y: 0.796875 }, - { x: 0.453125, y: 0.796875 }, - { x: 0.453125, y: 0.796875 }, - { x: 0.484375, y: 0.796875 }, - { x: 0.484375, y: 0.796875 }, - { x: 0.515625, y: 0.796875 }, - { x: 0.515625, y: 0.796875 }, - { x: 0.546875, y: 0.796875 }, - { x: 0.546875, y: 0.796875 }, - { x: 0.578125, y: 0.796875 }, - { x: 0.578125, y: 0.796875 }, - { x: 0.609375, y: 0.796875 }, - { x: 0.609375, y: 0.796875 }, - { x: 0.640625, y: 0.796875 }, - { x: 0.640625, y: 0.796875 }, - { x: 0.671875, y: 0.796875 }, - { x: 0.671875, y: 0.796875 }, - { x: 0.703125, y: 0.796875 }, - { x: 0.703125, y: 0.796875 }, - { x: 0.734375, y: 0.796875 }, - { x: 0.734375, y: 0.796875 }, - { x: 0.765625, y: 0.796875 }, - { x: 0.765625, y: 0.796875 }, - { x: 0.796875, y: 0.796875 }, - { x: 0.796875, y: 0.796875 }, - { x: 0.828125, y: 0.796875 }, - { x: 0.828125, y: 0.796875 }, - { x: 0.859375, y: 0.796875 }, - { x: 0.859375, y: 0.796875 }, - { x: 0.890625, y: 0.796875 }, - { x: 0.890625, y: 0.796875 }, - { x: 0.921875, y: 0.796875 }, - { x: 0.921875, y: 0.796875 }, - { x: 0.953125, y: 0.796875 }, - { x: 0.953125, y: 0.796875 }, - { x: 0.984375, y: 0.796875 }, - { x: 0.984375, y: 0.796875 }, - { x: 0.015625, y: 0.828125 }, - { x: 0.015625, y: 0.828125 }, - { x: 0.046875, y: 0.828125 }, - { x: 0.046875, y: 0.828125 }, - { x: 0.078125, y: 0.828125 }, - { x: 0.078125, y: 0.828125 }, - { x: 0.109375, y: 0.828125 }, - { x: 0.109375, y: 0.828125 }, - { x: 0.140625, y: 0.828125 }, - { x: 0.140625, y: 0.828125 }, - { x: 0.171875, y: 0.828125 }, - { x: 0.171875, y: 0.828125 }, - { x: 0.203125, y: 0.828125 }, - { x: 0.203125, y: 0.828125 }, - { x: 0.234375, y: 0.828125 }, - { x: 0.234375, y: 0.828125 }, - { x: 0.265625, y: 0.828125 }, - { x: 0.265625, y: 0.828125 }, - { x: 0.296875, y: 0.828125 }, - { x: 0.296875, y: 0.828125 }, - { x: 0.328125, y: 0.828125 }, - { x: 0.328125, y: 0.828125 }, - { x: 0.359375, y: 0.828125 }, - { x: 0.359375, y: 0.828125 }, - { x: 0.390625, y: 0.828125 }, - { x: 0.390625, y: 0.828125 }, - { x: 0.421875, y: 0.828125 }, - { x: 0.421875, y: 0.828125 }, - { x: 0.453125, y: 0.828125 }, - { x: 0.453125, y: 0.828125 }, - { x: 0.484375, y: 0.828125 }, - { x: 0.484375, y: 0.828125 }, - { x: 0.515625, y: 0.828125 }, - { x: 0.515625, y: 0.828125 }, - { x: 0.546875, y: 0.828125 }, - { x: 0.546875, y: 0.828125 }, - { x: 0.578125, y: 0.828125 }, - { x: 0.578125, y: 0.828125 }, - { x: 0.609375, y: 0.828125 }, - { x: 0.609375, y: 0.828125 }, - { x: 0.640625, y: 0.828125 }, - { x: 0.640625, y: 0.828125 }, - { x: 0.671875, y: 0.828125 }, - { x: 0.671875, y: 0.828125 }, - { x: 0.703125, y: 0.828125 }, - { x: 0.703125, y: 0.828125 }, - { x: 0.734375, y: 0.828125 }, - { x: 0.734375, y: 0.828125 }, - { x: 0.765625, y: 0.828125 }, - { x: 0.765625, y: 0.828125 }, - { x: 0.796875, y: 0.828125 }, - { x: 0.796875, y: 0.828125 }, - { x: 0.828125, y: 0.828125 }, - { x: 0.828125, y: 0.828125 }, - { x: 0.859375, y: 0.828125 }, - { x: 0.859375, y: 0.828125 }, - { x: 0.890625, y: 0.828125 }, - { x: 0.890625, y: 0.828125 }, - { x: 0.921875, y: 0.828125 }, - { x: 0.921875, y: 0.828125 }, - { x: 0.953125, y: 0.828125 }, - { x: 0.953125, y: 0.828125 }, - { x: 0.984375, y: 0.828125 }, - { x: 0.984375, y: 0.828125 }, - { x: 0.015625, y: 0.859375 }, - { x: 0.015625, y: 0.859375 }, - { x: 0.046875, y: 0.859375 }, - { x: 0.046875, y: 0.859375 }, - { x: 0.078125, y: 0.859375 }, - { x: 0.078125, y: 0.859375 }, - { x: 0.109375, y: 0.859375 }, - { x: 0.109375, y: 0.859375 }, - { x: 0.140625, y: 0.859375 }, - { x: 0.140625, y: 0.859375 }, - { x: 0.171875, y: 0.859375 }, - { x: 0.171875, y: 0.859375 }, - { x: 0.203125, y: 0.859375 }, - { x: 0.203125, y: 0.859375 }, - { x: 0.234375, y: 0.859375 }, - { x: 0.234375, y: 0.859375 }, - { x: 0.265625, y: 0.859375 }, - { x: 0.265625, y: 0.859375 }, - { x: 0.296875, y: 0.859375 }, - { x: 0.296875, y: 0.859375 }, - { x: 0.328125, y: 0.859375 }, - { x: 0.328125, y: 0.859375 }, - { x: 0.359375, y: 0.859375 }, - { x: 0.359375, y: 0.859375 }, - { x: 0.390625, y: 0.859375 }, - { x: 0.390625, y: 0.859375 }, - { x: 0.421875, y: 0.859375 }, - { x: 0.421875, y: 0.859375 }, - { x: 0.453125, y: 0.859375 }, - { x: 0.453125, y: 0.859375 }, - { x: 0.484375, y: 0.859375 }, - { x: 0.484375, y: 0.859375 }, - { x: 0.515625, y: 0.859375 }, - { x: 0.515625, y: 0.859375 }, - { x: 0.546875, y: 0.859375 }, - { x: 0.546875, y: 0.859375 }, - { x: 0.578125, y: 0.859375 }, - { x: 0.578125, y: 0.859375 }, - { x: 0.609375, y: 0.859375 }, - { x: 0.609375, y: 0.859375 }, - { x: 0.640625, y: 0.859375 }, - { x: 0.640625, y: 0.859375 }, - { x: 0.671875, y: 0.859375 }, - { x: 0.671875, y: 0.859375 }, - { x: 0.703125, y: 0.859375 }, - { x: 0.703125, y: 0.859375 }, - { x: 0.734375, y: 0.859375 }, - { x: 0.734375, y: 0.859375 }, - { x: 0.765625, y: 0.859375 }, - { x: 0.765625, y: 0.859375 }, - { x: 0.796875, y: 0.859375 }, - { x: 0.796875, y: 0.859375 }, - { x: 0.828125, y: 0.859375 }, - { x: 0.828125, y: 0.859375 }, - { x: 0.859375, y: 0.859375 }, - { x: 0.859375, y: 0.859375 }, - { x: 0.890625, y: 0.859375 }, - { x: 0.890625, y: 0.859375 }, - { x: 0.921875, y: 0.859375 }, - { x: 0.921875, y: 0.859375 }, - { x: 0.953125, y: 0.859375 }, - { x: 0.953125, y: 0.859375 }, - { x: 0.984375, y: 0.859375 }, - { x: 0.984375, y: 0.859375 }, - { x: 0.015625, y: 0.890625 }, - { x: 0.015625, y: 0.890625 }, - { x: 0.046875, y: 0.890625 }, - { x: 0.046875, y: 0.890625 }, - { x: 0.078125, y: 0.890625 }, - { x: 0.078125, y: 0.890625 }, - { x: 0.109375, y: 0.890625 }, - { x: 0.109375, y: 0.890625 }, - { x: 0.140625, y: 0.890625 }, - { x: 0.140625, y: 0.890625 }, - { x: 0.171875, y: 0.890625 }, - { x: 0.171875, y: 0.890625 }, - { x: 0.203125, y: 0.890625 }, - { x: 0.203125, y: 0.890625 }, - { x: 0.234375, y: 0.890625 }, - { x: 0.234375, y: 0.890625 }, - { x: 0.265625, y: 0.890625 }, - { x: 0.265625, y: 0.890625 }, - { x: 0.296875, y: 0.890625 }, - { x: 0.296875, y: 0.890625 }, - { x: 0.328125, y: 0.890625 }, - { x: 0.328125, y: 0.890625 }, - { x: 0.359375, y: 0.890625 }, - { x: 0.359375, y: 0.890625 }, - { x: 0.390625, y: 0.890625 }, - { x: 0.390625, y: 0.890625 }, - { x: 0.421875, y: 0.890625 }, - { x: 0.421875, y: 0.890625 }, - { x: 0.453125, y: 0.890625 }, - { x: 0.453125, y: 0.890625 }, - { x: 0.484375, y: 0.890625 }, - { x: 0.484375, y: 0.890625 }, - { x: 0.515625, y: 0.890625 }, - { x: 0.515625, y: 0.890625 }, - { x: 0.546875, y: 0.890625 }, - { x: 0.546875, y: 0.890625 }, - { x: 0.578125, y: 0.890625 }, - { x: 0.578125, y: 0.890625 }, - { x: 0.609375, y: 0.890625 }, - { x: 0.609375, y: 0.890625 }, - { x: 0.640625, y: 0.890625 }, - { x: 0.640625, y: 0.890625 }, - { x: 0.671875, y: 0.890625 }, - { x: 0.671875, y: 0.890625 }, - { x: 0.703125, y: 0.890625 }, - { x: 0.703125, y: 0.890625 }, - { x: 0.734375, y: 0.890625 }, - { x: 0.734375, y: 0.890625 }, - { x: 0.765625, y: 0.890625 }, - { x: 0.765625, y: 0.890625 }, - { x: 0.796875, y: 0.890625 }, - { x: 0.796875, y: 0.890625 }, - { x: 0.828125, y: 0.890625 }, - { x: 0.828125, y: 0.890625 }, - { x: 0.859375, y: 0.890625 }, - { x: 0.859375, y: 0.890625 }, - { x: 0.890625, y: 0.890625 }, - { x: 0.890625, y: 0.890625 }, - { x: 0.921875, y: 0.890625 }, - { x: 0.921875, y: 0.890625 }, - { x: 0.953125, y: 0.890625 }, - { x: 0.953125, y: 0.890625 }, - { x: 0.984375, y: 0.890625 }, - { x: 0.984375, y: 0.890625 }, - { x: 0.015625, y: 0.921875 }, - { x: 0.015625, y: 0.921875 }, - { x: 0.046875, y: 0.921875 }, - { x: 0.046875, y: 0.921875 }, - { x: 0.078125, y: 0.921875 }, - { x: 0.078125, y: 0.921875 }, - { x: 0.109375, y: 0.921875 }, - { x: 0.109375, y: 0.921875 }, - { x: 0.140625, y: 0.921875 }, - { x: 0.140625, y: 0.921875 }, - { x: 0.171875, y: 0.921875 }, - { x: 0.171875, y: 0.921875 }, - { x: 0.203125, y: 0.921875 }, - { x: 0.203125, y: 0.921875 }, - { x: 0.234375, y: 0.921875 }, - { x: 0.234375, y: 0.921875 }, - { x: 0.265625, y: 0.921875 }, - { x: 0.265625, y: 0.921875 }, - { x: 0.296875, y: 0.921875 }, - { x: 0.296875, y: 0.921875 }, - { x: 0.328125, y: 0.921875 }, - { x: 0.328125, y: 0.921875 }, - { x: 0.359375, y: 0.921875 }, - { x: 0.359375, y: 0.921875 }, - { x: 0.390625, y: 0.921875 }, - { x: 0.390625, y: 0.921875 }, - { x: 0.421875, y: 0.921875 }, - { x: 0.421875, y: 0.921875 }, - { x: 0.453125, y: 0.921875 }, - { x: 0.453125, y: 0.921875 }, - { x: 0.484375, y: 0.921875 }, - { x: 0.484375, y: 0.921875 }, - { x: 0.515625, y: 0.921875 }, - { x: 0.515625, y: 0.921875 }, - { x: 0.546875, y: 0.921875 }, - { x: 0.546875, y: 0.921875 }, - { x: 0.578125, y: 0.921875 }, - { x: 0.578125, y: 0.921875 }, - { x: 0.609375, y: 0.921875 }, - { x: 0.609375, y: 0.921875 }, - { x: 0.640625, y: 0.921875 }, - { x: 0.640625, y: 0.921875 }, - { x: 0.671875, y: 0.921875 }, - { x: 0.671875, y: 0.921875 }, - { x: 0.703125, y: 0.921875 }, - { x: 0.703125, y: 0.921875 }, - { x: 0.734375, y: 0.921875 }, - { x: 0.734375, y: 0.921875 }, - { x: 0.765625, y: 0.921875 }, - { x: 0.765625, y: 0.921875 }, - { x: 0.796875, y: 0.921875 }, - { x: 0.796875, y: 0.921875 }, - { x: 0.828125, y: 0.921875 }, - { x: 0.828125, y: 0.921875 }, - { x: 0.859375, y: 0.921875 }, - { x: 0.859375, y: 0.921875 }, - { x: 0.890625, y: 0.921875 }, - { x: 0.890625, y: 0.921875 }, - { x: 0.921875, y: 0.921875 }, - { x: 0.921875, y: 0.921875 }, - { x: 0.953125, y: 0.921875 }, - { x: 0.953125, y: 0.921875 }, - { x: 0.984375, y: 0.921875 }, - { x: 0.984375, y: 0.921875 }, - { x: 0.015625, y: 0.953125 }, - { x: 0.015625, y: 0.953125 }, - { x: 0.046875, y: 0.953125 }, - { x: 0.046875, y: 0.953125 }, - { x: 0.078125, y: 0.953125 }, - { x: 0.078125, y: 0.953125 }, - { x: 0.109375, y: 0.953125 }, - { x: 0.109375, y: 0.953125 }, - { x: 0.140625, y: 0.953125 }, - { x: 0.140625, y: 0.953125 }, - { x: 0.171875, y: 0.953125 }, - { x: 0.171875, y: 0.953125 }, - { x: 0.203125, y: 0.953125 }, - { x: 0.203125, y: 0.953125 }, - { x: 0.234375, y: 0.953125 }, - { x: 0.234375, y: 0.953125 }, - { x: 0.265625, y: 0.953125 }, - { x: 0.265625, y: 0.953125 }, - { x: 0.296875, y: 0.953125 }, - { x: 0.296875, y: 0.953125 }, - { x: 0.328125, y: 0.953125 }, - { x: 0.328125, y: 0.953125 }, - { x: 0.359375, y: 0.953125 }, - { x: 0.359375, y: 0.953125 }, - { x: 0.390625, y: 0.953125 }, - { x: 0.390625, y: 0.953125 }, - { x: 0.421875, y: 0.953125 }, - { x: 0.421875, y: 0.953125 }, - { x: 0.453125, y: 0.953125 }, - { x: 0.453125, y: 0.953125 }, - { x: 0.484375, y: 0.953125 }, - { x: 0.484375, y: 0.953125 }, - { x: 0.515625, y: 0.953125 }, - { x: 0.515625, y: 0.953125 }, - { x: 0.546875, y: 0.953125 }, - { x: 0.546875, y: 0.953125 }, - { x: 0.578125, y: 0.953125 }, - { x: 0.578125, y: 0.953125 }, - { x: 0.609375, y: 0.953125 }, - { x: 0.609375, y: 0.953125 }, - { x: 0.640625, y: 0.953125 }, - { x: 0.640625, y: 0.953125 }, - { x: 0.671875, y: 0.953125 }, - { x: 0.671875, y: 0.953125 }, - { x: 0.703125, y: 0.953125 }, - { x: 0.703125, y: 0.953125 }, - { x: 0.734375, y: 0.953125 }, - { x: 0.734375, y: 0.953125 }, - { x: 0.765625, y: 0.953125 }, - { x: 0.765625, y: 0.953125 }, - { x: 0.796875, y: 0.953125 }, - { x: 0.796875, y: 0.953125 }, - { x: 0.828125, y: 0.953125 }, - { x: 0.828125, y: 0.953125 }, - { x: 0.859375, y: 0.953125 }, - { x: 0.859375, y: 0.953125 }, - { x: 0.890625, y: 0.953125 }, - { x: 0.890625, y: 0.953125 }, - { x: 0.921875, y: 0.953125 }, - { x: 0.921875, y: 0.953125 }, - { x: 0.953125, y: 0.953125 }, - { x: 0.953125, y: 0.953125 }, - { x: 0.984375, y: 0.953125 }, - { x: 0.984375, y: 0.953125 }, - { x: 0.015625, y: 0.984375 }, - { x: 0.015625, y: 0.984375 }, - { x: 0.046875, y: 0.984375 }, - { x: 0.046875, y: 0.984375 }, - { x: 0.078125, y: 0.984375 }, - { x: 0.078125, y: 0.984375 }, - { x: 0.109375, y: 0.984375 }, - { x: 0.109375, y: 0.984375 }, - { x: 0.140625, y: 0.984375 }, - { x: 0.140625, y: 0.984375 }, - { x: 0.171875, y: 0.984375 }, - { x: 0.171875, y: 0.984375 }, - { x: 0.203125, y: 0.984375 }, - { x: 0.203125, y: 0.984375 }, - { x: 0.234375, y: 0.984375 }, - { x: 0.234375, y: 0.984375 }, - { x: 0.265625, y: 0.984375 }, - { x: 0.265625, y: 0.984375 }, - { x: 0.296875, y: 0.984375 }, - { x: 0.296875, y: 0.984375 }, - { x: 0.328125, y: 0.984375 }, - { x: 0.328125, y: 0.984375 }, - { x: 0.359375, y: 0.984375 }, - { x: 0.359375, y: 0.984375 }, - { x: 0.390625, y: 0.984375 }, - { x: 0.390625, y: 0.984375 }, - { x: 0.421875, y: 0.984375 }, - { x: 0.421875, y: 0.984375 }, - { x: 0.453125, y: 0.984375 }, - { x: 0.453125, y: 0.984375 }, - { x: 0.484375, y: 0.984375 }, - { x: 0.484375, y: 0.984375 }, - { x: 0.515625, y: 0.984375 }, - { x: 0.515625, y: 0.984375 }, - { x: 0.546875, y: 0.984375 }, - { x: 0.546875, y: 0.984375 }, - { x: 0.578125, y: 0.984375 }, - { x: 0.578125, y: 0.984375 }, - { x: 0.609375, y: 0.984375 }, - { x: 0.609375, y: 0.984375 }, - { x: 0.640625, y: 0.984375 }, - { x: 0.640625, y: 0.984375 }, - { x: 0.671875, y: 0.984375 }, - { x: 0.671875, y: 0.984375 }, - { x: 0.703125, y: 0.984375 }, - { x: 0.703125, y: 0.984375 }, - { x: 0.734375, y: 0.984375 }, - { x: 0.734375, y: 0.984375 }, - { x: 0.765625, y: 0.984375 }, - { x: 0.765625, y: 0.984375 }, - { x: 0.796875, y: 0.984375 }, - { x: 0.796875, y: 0.984375 }, - { x: 0.828125, y: 0.984375 }, - { x: 0.828125, y: 0.984375 }, - { x: 0.859375, y: 0.984375 }, - { x: 0.859375, y: 0.984375 }, - { x: 0.890625, y: 0.984375 }, - { x: 0.890625, y: 0.984375 }, - { x: 0.921875, y: 0.984375 }, - { x: 0.921875, y: 0.984375 }, - { x: 0.953125, y: 0.984375 }, - { x: 0.953125, y: 0.984375 }, - { x: 0.984375, y: 0.984375 }, - { x: 0.984375, y: 0.984375 }, - { x: 0.03125, y: 0.03125 }, - { x: 0.03125, y: 0.03125 }, - { x: 0.09375, y: 0.03125 }, - { x: 0.09375, y: 0.03125 }, - { x: 0.15625, y: 0.03125 }, - { x: 0.15625, y: 0.03125 }, - { x: 0.21875, y: 0.03125 }, - { x: 0.21875, y: 0.03125 }, - { x: 0.28125, y: 0.03125 }, - { x: 0.28125, y: 0.03125 }, - { x: 0.34375, y: 0.03125 }, - { x: 0.34375, y: 0.03125 }, - { x: 0.40625, y: 0.03125 }, - { x: 0.40625, y: 0.03125 }, - { x: 0.46875, y: 0.03125 }, - { x: 0.46875, y: 0.03125 }, - { x: 0.53125, y: 0.03125 }, - { x: 0.53125, y: 0.03125 }, - { x: 0.59375, y: 0.03125 }, - { x: 0.59375, y: 0.03125 }, - { x: 0.65625, y: 0.03125 }, - { x: 0.65625, y: 0.03125 }, - { x: 0.71875, y: 0.03125 }, - { x: 0.71875, y: 0.03125 }, - { x: 0.78125, y: 0.03125 }, - { x: 0.78125, y: 0.03125 }, - { x: 0.84375, y: 0.03125 }, - { x: 0.84375, y: 0.03125 }, - { x: 0.90625, y: 0.03125 }, - { x: 0.90625, y: 0.03125 }, - { x: 0.96875, y: 0.03125 }, - { x: 0.96875, y: 0.03125 }, - { x: 0.03125, y: 0.09375 }, - { x: 0.03125, y: 0.09375 }, - { x: 0.09375, y: 0.09375 }, - { x: 0.09375, y: 0.09375 }, - { x: 0.15625, y: 0.09375 }, - { x: 0.15625, y: 0.09375 }, - { x: 0.21875, y: 0.09375 }, - { x: 0.21875, y: 0.09375 }, - { x: 0.28125, y: 0.09375 }, - { x: 0.28125, y: 0.09375 }, - { x: 0.34375, y: 0.09375 }, - { x: 0.34375, y: 0.09375 }, - { x: 0.40625, y: 0.09375 }, - { x: 0.40625, y: 0.09375 }, - { x: 0.46875, y: 0.09375 }, - { x: 0.46875, y: 0.09375 }, - { x: 0.53125, y: 0.09375 }, - { x: 0.53125, y: 0.09375 }, - { x: 0.59375, y: 0.09375 }, - { x: 0.59375, y: 0.09375 }, - { x: 0.65625, y: 0.09375 }, - { x: 0.65625, y: 0.09375 }, - { x: 0.71875, y: 0.09375 }, - { x: 0.71875, y: 0.09375 }, - { x: 0.78125, y: 0.09375 }, - { x: 0.78125, y: 0.09375 }, - { x: 0.84375, y: 0.09375 }, - { x: 0.84375, y: 0.09375 }, - { x: 0.90625, y: 0.09375 }, - { x: 0.90625, y: 0.09375 }, - { x: 0.96875, y: 0.09375 }, - { x: 0.96875, y: 0.09375 }, - { x: 0.03125, y: 0.15625 }, - { x: 0.03125, y: 0.15625 }, - { x: 0.09375, y: 0.15625 }, - { x: 0.09375, y: 0.15625 }, - { x: 0.15625, y: 0.15625 }, - { x: 0.15625, y: 0.15625 }, - { x: 0.21875, y: 0.15625 }, - { x: 0.21875, y: 0.15625 }, - { x: 0.28125, y: 0.15625 }, - { x: 0.28125, y: 0.15625 }, - { x: 0.34375, y: 0.15625 }, - { x: 0.34375, y: 0.15625 }, - { x: 0.40625, y: 0.15625 }, - { x: 0.40625, y: 0.15625 }, - { x: 0.46875, y: 0.15625 }, - { x: 0.46875, y: 0.15625 }, - { x: 0.53125, y: 0.15625 }, - { x: 0.53125, y: 0.15625 }, - { x: 0.59375, y: 0.15625 }, - { x: 0.59375, y: 0.15625 }, - { x: 0.65625, y: 0.15625 }, - { x: 0.65625, y: 0.15625 }, - { x: 0.71875, y: 0.15625 }, - { x: 0.71875, y: 0.15625 }, - { x: 0.78125, y: 0.15625 }, - { x: 0.78125, y: 0.15625 }, - { x: 0.84375, y: 0.15625 }, - { x: 0.84375, y: 0.15625 }, - { x: 0.90625, y: 0.15625 }, - { x: 0.90625, y: 0.15625 }, - { x: 0.96875, y: 0.15625 }, - { x: 0.96875, y: 0.15625 }, - { x: 0.03125, y: 0.21875 }, - { x: 0.03125, y: 0.21875 }, - { x: 0.09375, y: 0.21875 }, - { x: 0.09375, y: 0.21875 }, - { x: 0.15625, y: 0.21875 }, - { x: 0.15625, y: 0.21875 }, - { x: 0.21875, y: 0.21875 }, - { x: 0.21875, y: 0.21875 }, - { x: 0.28125, y: 0.21875 }, - { x: 0.28125, y: 0.21875 }, - { x: 0.34375, y: 0.21875 }, - { x: 0.34375, y: 0.21875 }, - { x: 0.40625, y: 0.21875 }, - { x: 0.40625, y: 0.21875 }, - { x: 0.46875, y: 0.21875 }, - { x: 0.46875, y: 0.21875 }, - { x: 0.53125, y: 0.21875 }, - { x: 0.53125, y: 0.21875 }, - { x: 0.59375, y: 0.21875 }, - { x: 0.59375, y: 0.21875 }, - { x: 0.65625, y: 0.21875 }, - { x: 0.65625, y: 0.21875 }, - { x: 0.71875, y: 0.21875 }, - { x: 0.71875, y: 0.21875 }, - { x: 0.78125, y: 0.21875 }, - { x: 0.78125, y: 0.21875 }, - { x: 0.84375, y: 0.21875 }, - { x: 0.84375, y: 0.21875 }, - { x: 0.90625, y: 0.21875 }, - { x: 0.90625, y: 0.21875 }, - { x: 0.96875, y: 0.21875 }, - { x: 0.96875, y: 0.21875 }, - { x: 0.03125, y: 0.28125 }, - { x: 0.03125, y: 0.28125 }, - { x: 0.09375, y: 0.28125 }, - { x: 0.09375, y: 0.28125 }, - { x: 0.15625, y: 0.28125 }, - { x: 0.15625, y: 0.28125 }, - { x: 0.21875, y: 0.28125 }, - { x: 0.21875, y: 0.28125 }, - { x: 0.28125, y: 0.28125 }, - { x: 0.28125, y: 0.28125 }, - { x: 0.34375, y: 0.28125 }, - { x: 0.34375, y: 0.28125 }, - { x: 0.40625, y: 0.28125 }, - { x: 0.40625, y: 0.28125 }, - { x: 0.46875, y: 0.28125 }, - { x: 0.46875, y: 0.28125 }, - { x: 0.53125, y: 0.28125 }, - { x: 0.53125, y: 0.28125 }, - { x: 0.59375, y: 0.28125 }, - { x: 0.59375, y: 0.28125 }, - { x: 0.65625, y: 0.28125 }, - { x: 0.65625, y: 0.28125 }, - { x: 0.71875, y: 0.28125 }, - { x: 0.71875, y: 0.28125 }, - { x: 0.78125, y: 0.28125 }, - { x: 0.78125, y: 0.28125 }, - { x: 0.84375, y: 0.28125 }, - { x: 0.84375, y: 0.28125 }, - { x: 0.90625, y: 0.28125 }, - { x: 0.90625, y: 0.28125 }, - { x: 0.96875, y: 0.28125 }, - { x: 0.96875, y: 0.28125 }, - { x: 0.03125, y: 0.34375 }, - { x: 0.03125, y: 0.34375 }, - { x: 0.09375, y: 0.34375 }, - { x: 0.09375, y: 0.34375 }, - { x: 0.15625, y: 0.34375 }, - { x: 0.15625, y: 0.34375 }, - { x: 0.21875, y: 0.34375 }, - { x: 0.21875, y: 0.34375 }, - { x: 0.28125, y: 0.34375 }, - { x: 0.28125, y: 0.34375 }, - { x: 0.34375, y: 0.34375 }, - { x: 0.34375, y: 0.34375 }, - { x: 0.40625, y: 0.34375 }, - { x: 0.40625, y: 0.34375 }, - { x: 0.46875, y: 0.34375 }, - { x: 0.46875, y: 0.34375 }, - { x: 0.53125, y: 0.34375 }, - { x: 0.53125, y: 0.34375 }, - { x: 0.59375, y: 0.34375 }, - { x: 0.59375, y: 0.34375 }, - { x: 0.65625, y: 0.34375 }, - { x: 0.65625, y: 0.34375 }, - { x: 0.71875, y: 0.34375 }, - { x: 0.71875, y: 0.34375 }, - { x: 0.78125, y: 0.34375 }, - { x: 0.78125, y: 0.34375 }, - { x: 0.84375, y: 0.34375 }, - { x: 0.84375, y: 0.34375 }, - { x: 0.90625, y: 0.34375 }, - { x: 0.90625, y: 0.34375 }, - { x: 0.96875, y: 0.34375 }, - { x: 0.96875, y: 0.34375 }, - { x: 0.03125, y: 0.40625 }, - { x: 0.03125, y: 0.40625 }, - { x: 0.09375, y: 0.40625 }, - { x: 0.09375, y: 0.40625 }, - { x: 0.15625, y: 0.40625 }, - { x: 0.15625, y: 0.40625 }, - { x: 0.21875, y: 0.40625 }, - { x: 0.21875, y: 0.40625 }, - { x: 0.28125, y: 0.40625 }, - { x: 0.28125, y: 0.40625 }, - { x: 0.34375, y: 0.40625 }, - { x: 0.34375, y: 0.40625 }, - { x: 0.40625, y: 0.40625 }, - { x: 0.40625, y: 0.40625 }, - { x: 0.46875, y: 0.40625 }, - { x: 0.46875, y: 0.40625 }, - { x: 0.53125, y: 0.40625 }, - { x: 0.53125, y: 0.40625 }, - { x: 0.59375, y: 0.40625 }, - { x: 0.59375, y: 0.40625 }, - { x: 0.65625, y: 0.40625 }, - { x: 0.65625, y: 0.40625 }, - { x: 0.71875, y: 0.40625 }, - { x: 0.71875, y: 0.40625 }, - { x: 0.78125, y: 0.40625 }, - { x: 0.78125, y: 0.40625 }, - { x: 0.84375, y: 0.40625 }, - { x: 0.84375, y: 0.40625 }, - { x: 0.90625, y: 0.40625 }, - { x: 0.90625, y: 0.40625 }, - { x: 0.96875, y: 0.40625 }, - { x: 0.96875, y: 0.40625 }, - { x: 0.03125, y: 0.46875 }, - { x: 0.03125, y: 0.46875 }, - { x: 0.09375, y: 0.46875 }, - { x: 0.09375, y: 0.46875 }, - { x: 0.15625, y: 0.46875 }, - { x: 0.15625, y: 0.46875 }, - { x: 0.21875, y: 0.46875 }, - { x: 0.21875, y: 0.46875 }, - { x: 0.28125, y: 0.46875 }, - { x: 0.28125, y: 0.46875 }, - { x: 0.34375, y: 0.46875 }, - { x: 0.34375, y: 0.46875 }, - { x: 0.40625, y: 0.46875 }, - { x: 0.40625, y: 0.46875 }, - { x: 0.46875, y: 0.46875 }, - { x: 0.46875, y: 0.46875 }, - { x: 0.53125, y: 0.46875 }, - { x: 0.53125, y: 0.46875 }, - { x: 0.59375, y: 0.46875 }, - { x: 0.59375, y: 0.46875 }, - { x: 0.65625, y: 0.46875 }, - { x: 0.65625, y: 0.46875 }, - { x: 0.71875, y: 0.46875 }, - { x: 0.71875, y: 0.46875 }, - { x: 0.78125, y: 0.46875 }, - { x: 0.78125, y: 0.46875 }, - { x: 0.84375, y: 0.46875 }, - { x: 0.84375, y: 0.46875 }, - { x: 0.90625, y: 0.46875 }, - { x: 0.90625, y: 0.46875 }, - { x: 0.96875, y: 0.46875 }, - { x: 0.96875, y: 0.46875 }, - { x: 0.03125, y: 0.53125 }, - { x: 0.03125, y: 0.53125 }, - { x: 0.09375, y: 0.53125 }, - { x: 0.09375, y: 0.53125 }, - { x: 0.15625, y: 0.53125 }, - { x: 0.15625, y: 0.53125 }, - { x: 0.21875, y: 0.53125 }, - { x: 0.21875, y: 0.53125 }, - { x: 0.28125, y: 0.53125 }, - { x: 0.28125, y: 0.53125 }, - { x: 0.34375, y: 0.53125 }, - { x: 0.34375, y: 0.53125 }, - { x: 0.40625, y: 0.53125 }, - { x: 0.40625, y: 0.53125 }, - { x: 0.46875, y: 0.53125 }, - { x: 0.46875, y: 0.53125 }, - { x: 0.53125, y: 0.53125 }, - { x: 0.53125, y: 0.53125 }, - { x: 0.59375, y: 0.53125 }, - { x: 0.59375, y: 0.53125 }, - { x: 0.65625, y: 0.53125 }, - { x: 0.65625, y: 0.53125 }, - { x: 0.71875, y: 0.53125 }, - { x: 0.71875, y: 0.53125 }, - { x: 0.78125, y: 0.53125 }, - { x: 0.78125, y: 0.53125 }, - { x: 0.84375, y: 0.53125 }, - { x: 0.84375, y: 0.53125 }, - { x: 0.90625, y: 0.53125 }, - { x: 0.90625, y: 0.53125 }, - { x: 0.96875, y: 0.53125 }, - { x: 0.96875, y: 0.53125 }, - { x: 0.03125, y: 0.59375 }, - { x: 0.03125, y: 0.59375 }, - { x: 0.09375, y: 0.59375 }, - { x: 0.09375, y: 0.59375 }, - { x: 0.15625, y: 0.59375 }, - { x: 0.15625, y: 0.59375 }, - { x: 0.21875, y: 0.59375 }, - { x: 0.21875, y: 0.59375 }, - { x: 0.28125, y: 0.59375 }, - { x: 0.28125, y: 0.59375 }, - { x: 0.34375, y: 0.59375 }, - { x: 0.34375, y: 0.59375 }, - { x: 0.40625, y: 0.59375 }, - { x: 0.40625, y: 0.59375 }, - { x: 0.46875, y: 0.59375 }, - { x: 0.46875, y: 0.59375 }, - { x: 0.53125, y: 0.59375 }, - { x: 0.53125, y: 0.59375 }, - { x: 0.59375, y: 0.59375 }, - { x: 0.59375, y: 0.59375 }, - { x: 0.65625, y: 0.59375 }, - { x: 0.65625, y: 0.59375 }, - { x: 0.71875, y: 0.59375 }, - { x: 0.71875, y: 0.59375 }, - { x: 0.78125, y: 0.59375 }, - { x: 0.78125, y: 0.59375 }, - { x: 0.84375, y: 0.59375 }, - { x: 0.84375, y: 0.59375 }, - { x: 0.90625, y: 0.59375 }, - { x: 0.90625, y: 0.59375 }, - { x: 0.96875, y: 0.59375 }, - { x: 0.96875, y: 0.59375 }, - { x: 0.03125, y: 0.65625 }, - { x: 0.03125, y: 0.65625 }, - { x: 0.09375, y: 0.65625 }, - { x: 0.09375, y: 0.65625 }, - { x: 0.15625, y: 0.65625 }, - { x: 0.15625, y: 0.65625 }, - { x: 0.21875, y: 0.65625 }, - { x: 0.21875, y: 0.65625 }, - { x: 0.28125, y: 0.65625 }, - { x: 0.28125, y: 0.65625 }, - { x: 0.34375, y: 0.65625 }, - { x: 0.34375, y: 0.65625 }, - { x: 0.40625, y: 0.65625 }, - { x: 0.40625, y: 0.65625 }, - { x: 0.46875, y: 0.65625 }, - { x: 0.46875, y: 0.65625 }, - { x: 0.53125, y: 0.65625 }, - { x: 0.53125, y: 0.65625 }, - { x: 0.59375, y: 0.65625 }, - { x: 0.59375, y: 0.65625 }, - { x: 0.65625, y: 0.65625 }, - { x: 0.65625, y: 0.65625 }, - { x: 0.71875, y: 0.65625 }, - { x: 0.71875, y: 0.65625 }, - { x: 0.78125, y: 0.65625 }, - { x: 0.78125, y: 0.65625 }, - { x: 0.84375, y: 0.65625 }, - { x: 0.84375, y: 0.65625 }, - { x: 0.90625, y: 0.65625 }, - { x: 0.90625, y: 0.65625 }, - { x: 0.96875, y: 0.65625 }, - { x: 0.96875, y: 0.65625 }, - { x: 0.03125, y: 0.71875 }, - { x: 0.03125, y: 0.71875 }, - { x: 0.09375, y: 0.71875 }, - { x: 0.09375, y: 0.71875 }, - { x: 0.15625, y: 0.71875 }, - { x: 0.15625, y: 0.71875 }, - { x: 0.21875, y: 0.71875 }, - { x: 0.21875, y: 0.71875 }, - { x: 0.28125, y: 0.71875 }, - { x: 0.28125, y: 0.71875 }, - { x: 0.34375, y: 0.71875 }, - { x: 0.34375, y: 0.71875 }, - { x: 0.40625, y: 0.71875 }, - { x: 0.40625, y: 0.71875 }, - { x: 0.46875, y: 0.71875 }, - { x: 0.46875, y: 0.71875 }, - { x: 0.53125, y: 0.71875 }, - { x: 0.53125, y: 0.71875 }, - { x: 0.59375, y: 0.71875 }, - { x: 0.59375, y: 0.71875 }, - { x: 0.65625, y: 0.71875 }, - { x: 0.65625, y: 0.71875 }, - { x: 0.71875, y: 0.71875 }, - { x: 0.71875, y: 0.71875 }, - { x: 0.78125, y: 0.71875 }, - { x: 0.78125, y: 0.71875 }, - { x: 0.84375, y: 0.71875 }, - { x: 0.84375, y: 0.71875 }, - { x: 0.90625, y: 0.71875 }, - { x: 0.90625, y: 0.71875 }, - { x: 0.96875, y: 0.71875 }, - { x: 0.96875, y: 0.71875 }, - { x: 0.03125, y: 0.78125 }, - { x: 0.03125, y: 0.78125 }, - { x: 0.09375, y: 0.78125 }, - { x: 0.09375, y: 0.78125 }, - { x: 0.15625, y: 0.78125 }, - { x: 0.15625, y: 0.78125 }, - { x: 0.21875, y: 0.78125 }, - { x: 0.21875, y: 0.78125 }, - { x: 0.28125, y: 0.78125 }, - { x: 0.28125, y: 0.78125 }, - { x: 0.34375, y: 0.78125 }, - { x: 0.34375, y: 0.78125 }, - { x: 0.40625, y: 0.78125 }, - { x: 0.40625, y: 0.78125 }, - { x: 0.46875, y: 0.78125 }, - { x: 0.46875, y: 0.78125 }, - { x: 0.53125, y: 0.78125 }, - { x: 0.53125, y: 0.78125 }, - { x: 0.59375, y: 0.78125 }, - { x: 0.59375, y: 0.78125 }, - { x: 0.65625, y: 0.78125 }, - { x: 0.65625, y: 0.78125 }, - { x: 0.71875, y: 0.78125 }, - { x: 0.71875, y: 0.78125 }, - { x: 0.78125, y: 0.78125 }, - { x: 0.78125, y: 0.78125 }, - { x: 0.84375, y: 0.78125 }, - { x: 0.84375, y: 0.78125 }, - { x: 0.90625, y: 0.78125 }, - { x: 0.90625, y: 0.78125 }, - { x: 0.96875, y: 0.78125 }, - { x: 0.96875, y: 0.78125 }, - { x: 0.03125, y: 0.84375 }, - { x: 0.03125, y: 0.84375 }, - { x: 0.09375, y: 0.84375 }, - { x: 0.09375, y: 0.84375 }, - { x: 0.15625, y: 0.84375 }, - { x: 0.15625, y: 0.84375 }, - { x: 0.21875, y: 0.84375 }, - { x: 0.21875, y: 0.84375 }, - { x: 0.28125, y: 0.84375 }, - { x: 0.28125, y: 0.84375 }, - { x: 0.34375, y: 0.84375 }, - { x: 0.34375, y: 0.84375 }, - { x: 0.40625, y: 0.84375 }, - { x: 0.40625, y: 0.84375 }, - { x: 0.46875, y: 0.84375 }, - { x: 0.46875, y: 0.84375 }, - { x: 0.53125, y: 0.84375 }, - { x: 0.53125, y: 0.84375 }, - { x: 0.59375, y: 0.84375 }, - { x: 0.59375, y: 0.84375 }, - { x: 0.65625, y: 0.84375 }, - { x: 0.65625, y: 0.84375 }, - { x: 0.71875, y: 0.84375 }, - { x: 0.71875, y: 0.84375 }, - { x: 0.78125, y: 0.84375 }, - { x: 0.78125, y: 0.84375 }, - { x: 0.84375, y: 0.84375 }, - { x: 0.84375, y: 0.84375 }, - { x: 0.90625, y: 0.84375 }, - { x: 0.90625, y: 0.84375 }, - { x: 0.96875, y: 0.84375 }, - { x: 0.96875, y: 0.84375 }, - { x: 0.03125, y: 0.90625 }, - { x: 0.03125, y: 0.90625 }, - { x: 0.09375, y: 0.90625 }, - { x: 0.09375, y: 0.90625 }, - { x: 0.15625, y: 0.90625 }, - { x: 0.15625, y: 0.90625 }, - { x: 0.21875, y: 0.90625 }, - { x: 0.21875, y: 0.90625 }, - { x: 0.28125, y: 0.90625 }, - { x: 0.28125, y: 0.90625 }, - { x: 0.34375, y: 0.90625 }, - { x: 0.34375, y: 0.90625 }, - { x: 0.40625, y: 0.90625 }, - { x: 0.40625, y: 0.90625 }, - { x: 0.46875, y: 0.90625 }, - { x: 0.46875, y: 0.90625 }, - { x: 0.53125, y: 0.90625 }, - { x: 0.53125, y: 0.90625 }, - { x: 0.59375, y: 0.90625 }, - { x: 0.59375, y: 0.90625 }, - { x: 0.65625, y: 0.90625 }, - { x: 0.65625, y: 0.90625 }, - { x: 0.71875, y: 0.90625 }, - { x: 0.71875, y: 0.90625 }, - { x: 0.78125, y: 0.90625 }, - { x: 0.78125, y: 0.90625 }, - { x: 0.84375, y: 0.90625 }, - { x: 0.84375, y: 0.90625 }, - { x: 0.90625, y: 0.90625 }, - { x: 0.90625, y: 0.90625 }, - { x: 0.96875, y: 0.90625 }, - { x: 0.96875, y: 0.90625 }, - { x: 0.03125, y: 0.96875 }, - { x: 0.03125, y: 0.96875 }, - { x: 0.09375, y: 0.96875 }, - { x: 0.09375, y: 0.96875 }, - { x: 0.15625, y: 0.96875 }, - { x: 0.15625, y: 0.96875 }, - { x: 0.21875, y: 0.96875 }, - { x: 0.21875, y: 0.96875 }, - { x: 0.28125, y: 0.96875 }, - { x: 0.28125, y: 0.96875 }, - { x: 0.34375, y: 0.96875 }, - { x: 0.34375, y: 0.96875 }, - { x: 0.40625, y: 0.96875 }, - { x: 0.40625, y: 0.96875 }, - { x: 0.46875, y: 0.96875 }, - { x: 0.46875, y: 0.96875 }, - { x: 0.53125, y: 0.96875 }, - { x: 0.53125, y: 0.96875 }, - { x: 0.59375, y: 0.96875 }, - { x: 0.59375, y: 0.96875 }, - { x: 0.65625, y: 0.96875 }, - { x: 0.65625, y: 0.96875 }, - { x: 0.71875, y: 0.96875 }, - { x: 0.71875, y: 0.96875 }, - { x: 0.78125, y: 0.96875 }, - { x: 0.78125, y: 0.96875 }, - { x: 0.84375, y: 0.96875 }, - { x: 0.84375, y: 0.96875 }, - { x: 0.90625, y: 0.96875 }, - { x: 0.90625, y: 0.96875 }, - { x: 0.96875, y: 0.96875 }, - { x: 0.96875, y: 0.96875 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.0625, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.1875, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.3125, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.4375, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.5625, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.6875, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.8125, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.9375, y: 0.0625 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.0625, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.1875, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.3125, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.4375, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.5625, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.6875, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.8125, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.9375, y: 0.1875 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.0625, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.1875, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.3125, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.4375, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.5625, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.6875, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.8125, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.9375, y: 0.3125 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.0625, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.1875, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.3125, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.4375, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.5625, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.6875, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.8125, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.9375, y: 0.4375 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.0625, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.1875, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.3125, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.4375, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.5625, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.6875, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.8125, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.9375, y: 0.5625 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.0625, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.1875, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.3125, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.4375, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.5625, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.6875, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.8125, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.9375, y: 0.6875 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.0625, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.1875, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.3125, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.4375, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.5625, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.6875, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.8125, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.9375, y: 0.8125 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.0625, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.1875, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.3125, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.4375, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.5625, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.6875, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.8125, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 }, - { x: 0.9375, y: 0.9375 } -]; - -// src/hand/handposedetector.ts -var HandDetector = class { - constructor(model23) { - __publicField(this, "model"); - __publicField(this, "anchors"); - __publicField(this, "anchorsTensor"); - __publicField(this, "inputSize"); - __publicField(this, "inputSizeTensor"); - __publicField(this, "doubleInputSizeTensor"); - var _a, _b, _c, _d; - this.model = model23; - this.anchors = anchors2.map((anchor) => [anchor.x, anchor.y]); - this.anchorsTensor = tf27.tensor2d(this.anchors); - this.inputSize = ((_d = (_c = (_b = (_a = this == null ? void 0 : this.model) == null ? void 0 : _a.inputs) == null ? void 0 : _b[0]) == null ? void 0 : _c.shape) == null ? void 0 : _d[2]) || 0; - this.inputSizeTensor = tf27.tensor1d([this.inputSize, this.inputSize]); - this.doubleInputSizeTensor = tf27.tensor1d([this.inputSize * 2, this.inputSize * 2]); - } - normalizeBoxes(boxes) { - const t2 = {}; - t2.boxOffsets = tf27.slice(boxes, [0, 0], [-1, 2]); - t2.boxSizes = tf27.slice(boxes, [0, 2], [-1, 2]); - t2.div = tf27.div(t2.boxOffsets, this.inputSizeTensor); - t2.boxCenterPoints = tf27.add(t2.div, this.anchorsTensor); - t2.halfBoxSizes = tf27.div(t2.boxSizes, this.doubleInputSizeTensor); - t2.sub = tf27.sub(t2.boxCenterPoints, t2.halfBoxSizes); - t2.startPoints = tf27.mul(t2.sub, this.inputSizeTensor); - t2.add = tf27.add(t2.boxCenterPoints, t2.halfBoxSizes); - t2.endPoints = tf27.mul(t2.add, this.inputSizeTensor); - const res = tf27.concat2d([t2.startPoints, t2.endPoints], 1); - Object.keys(t2).forEach((tensor6) => tf27.dispose(t2[tensor6])); - return res; - } - normalizeLandmarks(rawPalmLandmarks, index2) { - const t2 = {}; - t2.reshape = tf27.reshape(rawPalmLandmarks, [-1, 7, 2]); - t2.div = tf27.div(t2.reshape, this.inputSizeTensor); - t2.landmarks = tf27.add(t2.div, this.anchors[index2] ? this.anchors[index2] : 0); - const res = tf27.mul(t2.landmarks, this.inputSizeTensor); - Object.keys(t2).forEach((tensor6) => tf27.dispose(t2[tensor6])); - return res; - } - async predict(input, config3) { - var _a; - const t2 = {}; - t2.resize = tf27.image.resizeBilinear(input, [this.inputSize, this.inputSize]); - t2.div = tf27.div(t2.resize, constants.tf127); - t2.image = tf27.sub(t2.div, constants.tf1); - t2.batched = this.model.execute(t2.image); - t2.predictions = tf27.squeeze(t2.batched); - t2.slice = tf27.slice(t2.predictions, [0, 0], [-1, 1]); - t2.sigmoid = tf27.sigmoid(t2.slice); - t2.scores = tf27.squeeze(t2.sigmoid); - const scores = await t2.scores.data(); - t2.boxes = tf27.slice(t2.predictions, [0, 1], [-1, 4]); - t2.norm = this.normalizeBoxes(t2.boxes); - t2.nms = await tf27.image.nonMaxSuppressionAsync(t2.norm, t2.scores, 3 * (((_a = config3.hand) == null ? void 0 : _a.maxDetected) || 1), config3.hand.iouThreshold, config3.hand.minConfidence); - const nms = await t2.nms.array(); - const hands = []; - for (const index2 of nms) { - const p = {}; - p.box = tf27.slice(t2.norm, [index2, 0], [1, -1]); - p.slice = tf27.slice(t2.predictions, [index2, 5], [1, 14]); - p.norm = this.normalizeLandmarks(p.slice, index2); - p.palmLandmarks = tf27.reshape(p.norm, [-1, 2]); - const box = await p.box.data(); - const startPoint = box.slice(0, 2); - const endPoint = box.slice(2, 4); - const palmLandmarks = await p.palmLandmarks.array(); - const hand3 = { startPoint, endPoint, palmLandmarks, confidence: scores[index2] }; - const scaled = scaleBoxCoordinates2(hand3, [(input.shape[2] || 1) / this.inputSize, (input.shape[1] || 0) / this.inputSize]); - hands.push(scaled); - Object.keys(p).forEach((tensor6) => tf27.dispose(p[tensor6])); - } - Object.keys(t2).forEach((tensor6) => tf27.dispose(t2[tensor6])); - return hands; - } -}; - -// src/hand/handposepipeline.ts -var tf28 = __toESM(require_tfjs_esm()); -var palmBoxEnlargeFactor = 5; -var handBoxEnlargeFactor = 1.65; -var palmLandmarkIds = [0, 5, 9, 13, 17, 1, 2]; -var palmLandmarksPalmBase = 0; -var palmLandmarksMiddleFingerBase = 2; -var lastTime13 = 0; -var HandPipeline = class { - constructor(handDetector, handPoseModel2) { - __publicField(this, "handDetector"); - __publicField(this, "handPoseModel"); - __publicField(this, "inputSize"); - __publicField(this, "storedBoxes"); - __publicField(this, "skipped"); - __publicField(this, "detectedHands"); - var _a, _b, _c; - this.handDetector = handDetector; - this.handPoseModel = handPoseModel2; - this.inputSize = ((_c = (_b = (_a = this.handPoseModel) == null ? void 0 : _a.inputs) == null ? void 0 : _b[0].shape) == null ? void 0 : _c[2]) || 0; - this.storedBoxes = []; - this.skipped = Number.MAX_SAFE_INTEGER; - this.detectedHands = 0; - } - calculateLandmarksBoundingBox(landmarks) { - const xs = landmarks.map((d) => d[0]); - const ys = landmarks.map((d) => d[1]); - const startPoint = [Math.min(...xs), Math.min(...ys)]; - const endPoint = [Math.max(...xs), Math.max(...ys)]; - return { startPoint, endPoint }; - } - getBoxForPalmLandmarks(palmLandmarks, rotationMatrix) { - const rotatedPalmLandmarks = palmLandmarks.map((coord) => rotatePoint2([...coord, 1], rotationMatrix)); - const boxAroundPalm = this.calculateLandmarksBoundingBox(rotatedPalmLandmarks); - return enlargeBox2(squarifyBox2(boxAroundPalm), palmBoxEnlargeFactor); - } - getBoxForHandLandmarks(landmarks) { - const boundingBox = this.calculateLandmarksBoundingBox(landmarks); - const boxAroundHand = enlargeBox2(squarifyBox2(boundingBox), handBoxEnlargeFactor); - boxAroundHand.palmLandmarks = []; - for (let i = 0; i < palmLandmarkIds.length; i++) { - boxAroundHand.palmLandmarks.push(landmarks[palmLandmarkIds[i]].slice(0, 2)); - } - return boxAroundHand; - } - transformRawCoords(rawCoords, box2, angle, rotationMatrix) { - const boxSize = getBoxSize2(box2); - const scaleFactor = [boxSize[0] / this.inputSize, boxSize[1] / this.inputSize, (boxSize[0] + boxSize[1]) / this.inputSize / 2]; - const coordsScaled = rawCoords.map((coord) => [ - scaleFactor[0] * (coord[0] - this.inputSize / 2), - scaleFactor[1] * (coord[1] - this.inputSize / 2), - scaleFactor[2] * coord[2] - ]); - const coordsRotationMatrix = buildRotationMatrix2(angle, [0, 0]); - const coordsRotated = coordsScaled.map((coord) => { - const rotated = rotatePoint2(coord, coordsRotationMatrix); - return [...rotated, coord[2]]; - }); - const inverseRotationMatrix = invertTransformMatrix2(rotationMatrix); - const boxCenter = [...getBoxCenter2(box2), 1]; - const originalBoxCenter = [ - dot2(boxCenter, inverseRotationMatrix[0]), - dot2(boxCenter, inverseRotationMatrix[1]) - ]; - return coordsRotated.map((coord) => [ - Math.trunc(coord[0] + originalBoxCenter[0]), - Math.trunc(coord[1] + originalBoxCenter[1]), - Math.trunc(coord[2]) - ]); - } - async estimateHands(image28, config3) { - let useFreshBox = false; - let boxes; - const skipTime = (config3.hand.skipTime || 0) > now() - lastTime13; - const skipFrame = this.skipped < (config3.hand.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame) { - boxes = await this.handDetector.predict(image28, config3); - this.skipped = 0; - } - if (config3.skipAllowed) - this.skipped++; - if (boxes && boxes.length > 0 && (boxes.length !== this.detectedHands && this.detectedHands !== config3.hand.maxDetected || !config3.hand.landmarks)) { - this.detectedHands = 0; - this.storedBoxes = [...boxes]; - if (this.storedBoxes.length > 0) - useFreshBox = true; - } - const hands = []; - for (let i = 0; i < this.storedBoxes.length; i++) { - const currentBox = this.storedBoxes[i]; - if (!currentBox) - continue; - if (config3.hand.landmarks) { - const angle = config3.hand.rotation ? computeRotation2(currentBox.palmLandmarks[palmLandmarksPalmBase], currentBox.palmLandmarks[palmLandmarksMiddleFingerBase]) : 0; - const palmCenter = getBoxCenter2(currentBox); - const palmCenterNormalized = [palmCenter[0] / image28.shape[2], palmCenter[1] / image28.shape[1]]; - const rotatedImage = config3.hand.rotation && env.kernels.includes("rotatewithoffset") ? tf28.image.rotateWithOffset(image28, angle, 0, palmCenterNormalized) : image28.clone(); - const rotationMatrix = buildRotationMatrix2(-angle, palmCenter); - const newBox = useFreshBox ? this.getBoxForPalmLandmarks(currentBox.palmLandmarks, rotationMatrix) : currentBox; - const croppedInput = cutBoxFromImageAndResize(newBox, rotatedImage, [this.inputSize, this.inputSize]); - const handImage = tf28.div(croppedInput, constants.tf255); - tf28.dispose(croppedInput); - tf28.dispose(rotatedImage); - const [confidenceT, keypoints] = this.handPoseModel.execute(handImage); - lastTime13 = now(); - tf28.dispose(handImage); - const confidence = (await confidenceT.data())[0]; - tf28.dispose(confidenceT); - if (confidence >= config3.hand.minConfidence / 4) { - const keypointsReshaped = tf28.reshape(keypoints, [-1, 3]); - const rawCoords = await keypointsReshaped.array(); - tf28.dispose(keypoints); - tf28.dispose(keypointsReshaped); - const coords = this.transformRawCoords(rawCoords, newBox, angle, rotationMatrix); - const nextBoundingBox = this.getBoxForHandLandmarks(coords); - this.storedBoxes[i] = { ...nextBoundingBox, confidence }; - const result = { - landmarks: coords, - confidence, - boxConfidence: currentBox.confidence, - fingerConfidence: confidence, - box: { topLeft: nextBoundingBox.startPoint, bottomRight: nextBoundingBox.endPoint } - }; - hands.push(result); - } else { - this.storedBoxes[i] = null; - } - tf28.dispose(keypoints); - } else { - const enlarged = enlargeBox2(squarifyBox2(currentBox), handBoxEnlargeFactor); - const result = { - confidence: currentBox.confidence, - boxConfidence: currentBox.confidence, - fingerConfidence: 0, - box: { topLeft: enlarged.startPoint, bottomRight: enlarged.endPoint }, - landmarks: [] - }; - hands.push(result); - } - } - this.storedBoxes = this.storedBoxes.filter((a) => a !== null); - this.detectedHands = hands.length; - if (hands.length > config3.hand.maxDetected) - hands.length = config3.hand.maxDetected; - return hands; - } -}; - -// src/hand/handpose.ts -var meshAnnotations2 = { - thumb: [1, 2, 3, 4], - index: [5, 6, 7, 8], - middle: [9, 10, 11, 12], - ring: [13, 14, 15, 16], - pinky: [17, 18, 19, 20], - palm: [0] -}; -var handDetectorModel; -var handPoseModel; -var handPipeline; -async function predict14(input, config3) { - const predictions = await handPipeline.estimateHands(input, config3); - if (!predictions) - return []; - const hands = []; - for (let i = 0; i < predictions.length; i++) { - const annotations2 = {}; - if (predictions[i].landmarks) { - for (const key of Object.keys(meshAnnotations2)) { - annotations2[key] = meshAnnotations2[key].map((index2) => predictions[i].landmarks[index2]); - } - } - const keypoints = predictions[i].landmarks; - let box = [Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, 0, 0]; - let boxRaw = [0, 0, 0, 0]; - if (keypoints && keypoints.length > 0) { - for (const pt of keypoints) { - if (pt[0] < box[0]) - box[0] = pt[0]; - if (pt[1] < box[1]) - box[1] = pt[1]; - if (pt[0] > box[2]) - box[2] = pt[0]; - if (pt[1] > box[3]) - box[3] = pt[1]; - } - box[2] -= box[0]; - box[3] -= box[1]; - boxRaw = [box[0] / (input.shape[2] || 0), box[1] / (input.shape[1] || 0), box[2] / (input.shape[2] || 0), box[3] / (input.shape[1] || 0)]; - } else { - box = predictions[i].box ? [ - Math.trunc(Math.max(0, predictions[i].box.topLeft[0])), - Math.trunc(Math.max(0, predictions[i].box.topLeft[1])), - Math.trunc(Math.min(input.shape[2] || 0, predictions[i].box.bottomRight[0]) - Math.max(0, predictions[i].box.topLeft[0])), - Math.trunc(Math.min(input.shape[1] || 0, predictions[i].box.bottomRight[1]) - Math.max(0, predictions[i].box.topLeft[1])) - ] : [0, 0, 0, 0]; - boxRaw = [ - predictions[i].box.topLeft[0] / (input.shape[2] || 0), - predictions[i].box.topLeft[1] / (input.shape[1] || 0), - (predictions[i].box.bottomRight[0] - predictions[i].box.topLeft[0]) / (input.shape[2] || 0), - (predictions[i].box.bottomRight[1] - predictions[i].box.topLeft[1]) / (input.shape[1] || 0) - ]; - } - const landmarks = analyze(keypoints); - hands.push({ - id: i, - score: Math.round(100 * predictions[i].confidence) / 100, - boxScore: Math.round(100 * predictions[i].boxConfidence) / 100, - fingerScore: Math.round(100 * predictions[i].fingerConfidence) / 100, - label: "hand", - box, - boxRaw, - keypoints, - annotations: annotations2, - landmarks - }); - } - return hands; -} -async function load15(config3) { - var _a, _b; - if (env.initial) { - handDetectorModel = null; - handPoseModel = null; - } - if (!handDetectorModel || !handPoseModel) { - [handDetectorModel, handPoseModel] = await Promise.all([ - config3.hand.enabled ? loadModel((_a = config3.hand.detector) == null ? void 0 : _a.modelPath) : null, - config3.hand.landmarks ? loadModel((_b = config3.hand.skeleton) == null ? void 0 : _b.modelPath) : null - ]); - } else { - if (config3.debug) - log("cached model:", handDetectorModel["modelUrl"]); - if (config3.debug) - log("cached model:", handPoseModel["modelUrl"]); - } - const handDetector = handDetectorModel ? new HandDetector(handDetectorModel) : void 0; - if (handDetector && handPoseModel) - handPipeline = new HandPipeline(handDetector, handPoseModel); - return [handDetectorModel, handPoseModel]; -} - -// src/hand/handtrack.ts -var tf29 = __toESM(require_tfjs_esm()); -var models2 = [null, null]; -var modelOutputNodes = ["StatefulPartitionedCall/Postprocessor/Slice", "StatefulPartitionedCall/Postprocessor/ExpandDims_1"]; -var inputSize7 = [[0, 0], [0, 0]]; -var classes = ["hand", "fist", "pinch", "point", "face", "tip", "pinchtip"]; -var faceIndex = 4; -var boxExpandFact = 1.6; -var maxDetectorResolution = 512; -var detectorExpandFact = 1.4; -var skipped13 = Number.MAX_SAFE_INTEGER; -var lastTime14 = 0; -var outputSize = [0, 0]; -var cache4 = { - boxes: [], - hands: [] -}; -var fingerMap = { - thumb: [1, 2, 3, 4], - index: [5, 6, 7, 8], - middle: [9, 10, 11, 12], - ring: [13, 14, 15, 16], - pinky: [17, 18, 19, 20], - base: [0], - palm: [0, 17, 13, 9, 5, 1, 0] -}; -async function loadDetect2(config3) { - var _a; - if (env.initial) - models2[0] = null; - if (!models2[0]) { - fakeOps(["tensorlistreserve", "enter", "tensorlistfromtensor", "merge", "loopcond", "switch", "exit", "tensorliststack", "nextiteration", "tensorlistsetitem", "tensorlistgetitem", "reciprocal", "shape", "split", "where"], config3); - models2[0] = await loadModel((_a = config3.hand.detector) == null ? void 0 : _a.modelPath); - const inputs = models2[0]["executor"] ? Object.values(models2[0].modelSignature["inputs"]) : void 0; - inputSize7[0][0] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - inputSize7[0][1] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 0; - } else if (config3.debug) - log("cached model:", models2[0]["modelUrl"]); - return models2[0]; -} -async function loadSkeleton(config3) { - var _a; - if (env.initial) - models2[1] = null; - if (!models2[1]) { - models2[1] = await loadModel((_a = config3.hand.skeleton) == null ? void 0 : _a.modelPath); - const inputs = models2[1]["executor"] ? Object.values(models2[1].modelSignature["inputs"]) : void 0; - inputSize7[1][0] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[1].size) : 0; - inputSize7[1][1] = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 0; - } else if (config3.debug) - log("cached model:", models2[1]["modelUrl"]); - return models2[1]; -} -async function detectHands(input, config3) { - const hands = []; - if (!input || !models2[0]) - return hands; - const t2 = {}; - const ratio2 = (input.shape[2] || 1) / (input.shape[1] || 1); - const height = Math.min(Math.round((input.shape[1] || 0) / 8) * 8, maxDetectorResolution); - const width = Math.round(height * ratio2 / 8) * 8; - t2.resize = tf29.image.resizeBilinear(input, [height, width]); - t2.cast = tf29.cast(t2.resize, "int32"); - [t2.rawScores, t2.rawBoxes] = await models2[0].executeAsync(t2.cast, modelOutputNodes); - t2.boxes = tf29.squeeze(t2.rawBoxes, [0, 2]); - t2.scores = tf29.squeeze(t2.rawScores, [0]); - const classScores = tf29.unstack(t2.scores, 1); - tf29.dispose(classScores[faceIndex]); - classScores.splice(faceIndex, 1); - t2.filtered = tf29.stack(classScores, 1); - tf29.dispose(classScores); - t2.max = tf29.max(t2.filtered, 1); - t2.argmax = tf29.argMax(t2.filtered, 1); - let id = 0; - t2.nms = await tf29.image.nonMaxSuppressionAsync(t2.boxes, t2.max, (config3.hand.maxDetected || 0) + 1, config3.hand.iouThreshold || 0, config3.hand.minConfidence || 1); - const nms = await t2.nms.data(); - const scores = await t2.max.data(); - const classNum = await t2.argmax.data(); - for (const nmsIndex of Array.from(nms)) { - const boxSlice = tf29.slice(t2.boxes, nmsIndex, 1); - const boxYX = await boxSlice.data(); - tf29.dispose(boxSlice); - const boxData = [boxYX[1], boxYX[0], boxYX[3] - boxYX[1], boxYX[2] - boxYX[0]]; - const boxRaw = scale(boxData, detectorExpandFact); - const boxFull = [Math.trunc(boxData[0] * outputSize[0]), Math.trunc(boxData[1] * outputSize[1]), Math.trunc(boxData[2] * outputSize[0]), Math.trunc(boxData[3] * outputSize[1])]; - const score = scores[nmsIndex]; - const label = classes[classNum[nmsIndex]]; - const hand3 = { id: id++, score, box: boxFull, boxRaw, label }; - hands.push(hand3); - } - Object.keys(t2).forEach((tensor6) => tf29.dispose(t2[tensor6])); - hands.sort((a, b) => b.score - a.score); - if (hands.length > (config3.hand.maxDetected || 1)) - hands.length = config3.hand.maxDetected || 1; - return hands; -} -async function detectFingers(input, h, config3) { - const hand3 = { - id: h.id, - score: Math.round(100 * h.score) / 100, - boxScore: Math.round(100 * h.score) / 100, - fingerScore: 0, - box: h.box, - boxRaw: h.boxRaw, - label: h.label, - keypoints: [], - landmarks: {}, - annotations: {} - }; - if (input && models2[1] && config3.hand.landmarks && h.score > (config3.hand.minConfidence || 0)) { - const t2 = {}; - const boxCrop = [h.boxRaw[1], h.boxRaw[0], h.boxRaw[3] + h.boxRaw[1], h.boxRaw[2] + h.boxRaw[0]]; - t2.crop = tf29.image.cropAndResize(input, [boxCrop], [0], [inputSize7[1][0], inputSize7[1][1]], "bilinear"); - t2.div = tf29.div(t2.crop, constants.tf255); - [t2.score, t2.keypoints] = models2[1].execute(t2.div, ["Identity_1", "Identity"]); - const rawScore = (await t2.score.data())[0]; - const score = (100 - Math.trunc(100 / (1 + Math.exp(rawScore)))) / 100; - if (score >= (config3.hand.minConfidence || 0)) { - hand3.fingerScore = score; - t2.reshaped = tf29.reshape(t2.keypoints, [-1, 3]); - const coordsData = await t2.reshaped.array(); - const coordsRaw = coordsData.map((kpt4) => [kpt4[0] / inputSize7[1][1], kpt4[1] / inputSize7[1][0], kpt4[2] || 0]); - const coordsNorm = coordsRaw.map((kpt4) => [kpt4[0] * h.boxRaw[2], kpt4[1] * h.boxRaw[3], kpt4[2] || 0]); - hand3.keypoints = coordsNorm.map((kpt4) => [outputSize[0] * (kpt4[0] + h.boxRaw[0]), outputSize[1] * (kpt4[1] + h.boxRaw[1]), kpt4[2] || 0]); - hand3.landmarks = analyze(hand3.keypoints); - for (const key of Object.keys(fingerMap)) { - hand3.annotations[key] = fingerMap[key].map((index2) => hand3.landmarks && hand3.keypoints[index2] ? hand3.keypoints[index2] : null); - } - } - Object.keys(t2).forEach((tensor6) => tf29.dispose(t2[tensor6])); - } - return hand3; -} -async function predict15(input, config3) { - var _a, _b; - if (!((_a = models2[0]) == null ? void 0 : _a["executor"]) || !((_b = models2[1]) == null ? void 0 : _b["executor"]) || !models2[0].inputs[0].shape || !models2[1].inputs[0].shape) - return []; - outputSize = [input.shape[2] || 0, input.shape[1] || 0]; - skipped13++; - const skipTime = (config3.hand.skipTime || 0) > now() - lastTime14; - const skipFrame = skipped13 < (config3.hand.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame) { - return cache4.hands; - } - return new Promise(async (resolve) => { - const skipTimeExtended = 3 * (config3.hand.skipTime || 0) > now() - lastTime14; - const skipFrameExtended = skipped13 < 3 * (config3.hand.skipFrames || 0); - if (config3.skipAllowed && cache4.hands.length === config3.hand.maxDetected) { - cache4.hands = await Promise.all(cache4.boxes.map((handBox) => detectFingers(input, handBox, config3))); - } else if (config3.skipAllowed && skipTimeExtended && skipFrameExtended && cache4.hands.length > 0) { - cache4.hands = await Promise.all(cache4.boxes.map((handBox) => detectFingers(input, handBox, config3))); - } else { - cache4.boxes = await detectHands(input, config3); - lastTime14 = now(); - cache4.hands = await Promise.all(cache4.boxes.map((handBox) => detectFingers(input, handBox, config3))); - skipped13 = 0; - } - const oldCache = [...cache4.boxes]; - cache4.boxes.length = 0; - if (config3.cacheSensitivity > 0) { - for (let i = 0; i < cache4.hands.length; i++) { - const boxKpt = square(cache4.hands[i].keypoints, outputSize); - if (boxKpt.box[2] / (input.shape[2] || 1) > 0.05 && boxKpt.box[3] / (input.shape[1] || 1) > 0.05 && cache4.hands[i].fingerScore && cache4.hands[i].fingerScore > (config3.hand.minConfidence || 0)) { - const boxScale = scale(boxKpt.box, boxExpandFact); - const boxScaleRaw = scale(boxKpt.boxRaw, boxExpandFact); - cache4.boxes.push({ ...oldCache[i], box: boxScale, boxRaw: boxScaleRaw }); - } - } - } - for (let i = 0; i < cache4.hands.length; i++) { - const bbox = calc(cache4.hands[i].keypoints, outputSize); - cache4.hands[i].box = bbox.box; - cache4.hands[i].boxRaw = bbox.boxRaw; - } - resolve(cache4.hands); - }); -} - -// src/result.ts -var empty = (error = null) => ({ face: [], body: [], hand: [], gesture: [], object: [], persons: [], performance: {}, timestamp: 0, width: 0, height: 0, error }); - -// src/body/movenetcoords.ts -var movenetcoords_exports = {}; -__export(movenetcoords_exports, { - connected: () => connected3, - horizontal: () => horizontal, - kpt: () => kpt3, - relative: () => relative, - vertical: () => vertical -}); -var kpt3 = [ - "nose", - "leftEye", - "rightEye", - "leftEar", - "rightEar", - "leftShoulder", - "rightShoulder", - "leftElbow", - "rightElbow", - "leftWrist", - "rightWrist", - "leftHip", - "rightHip", - "leftKnee", - "rightKnee", - "leftAnkle", - "rightAnkle" -]; -var horizontal = [ - ["leftEye", "rightEye"], - ["leftEar", "rightEar"], - ["leftShoulder", "rightShoulder"], - ["leftElbow", "rightElbow"], - ["leftWrist", "rightWrist"], - ["leftHip", "rightHip"], - ["leftKnee", "rightKnee"], - ["leftAnkle", "rightAnkle"] -]; -var vertical = [ - ["leftKnee", "leftShoulder"], - ["rightKnee", "rightShoulder"], - ["leftAnkle", "leftKnee"], - ["rightAnkle", "rightKnee"] -]; -var relative = [ - [["leftHip", "rightHip"], ["leftShoulder", "rightShoulder"]], - [["leftElbow", "rightElbow"], ["leftShoulder", "rightShoulder"]] -]; -var connected3 = { - leftLeg: ["leftHip", "leftKnee", "leftAnkle"], - rightLeg: ["rightHip", "rightKnee", "rightAnkle"], - torso: ["leftShoulder", "rightShoulder", "rightHip", "leftHip", "leftShoulder"], - leftArm: ["leftShoulder", "leftElbow", "leftWrist"], - rightArm: ["rightShoulder", "rightElbow", "rightWrist"], - head: [] -}; - -// src/util/interpolate.ts -var bufferedResult = empty(); -var interpolateTime = 0; -function calc2(newResult, config3) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w; - const t0 = now(); - if (!newResult) - return empty(); - const elapsed = Date.now() - newResult.timestamp; - const bufferedFactor = elapsed < 1e3 ? 8 - Math.log(elapsed + 1) : 1; - if (newResult.canvas) - bufferedResult.canvas = newResult.canvas; - if (newResult.error) - bufferedResult.error = newResult.error; - if (!bufferedResult.body || newResult.body.length !== bufferedResult.body.length) { - bufferedResult.body = JSON.parse(JSON.stringify(newResult.body)); - } else { - for (let i = 0; i < newResult.body.length; i++) { - const box = newResult.body[i].box.map((newBoxCoord, j) => ((bufferedFactor - 1) * bufferedResult.body[i].box[j] + newBoxCoord) / bufferedFactor); - const boxRaw = newResult.body[i].boxRaw.map((newBoxCoord, j) => ((bufferedFactor - 1) * bufferedResult.body[i].boxRaw[j] + newBoxCoord) / bufferedFactor); - const keypoints = newResult.body[i].keypoints.map((newKpt, j) => { - var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2; - return { - score: newKpt.score, - part: newKpt.part, - position: [ - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].position[0] || 0) + (newKpt.position[0] || 0)) / bufferedFactor : newKpt.position[0], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].position[1] || 0) + (newKpt.position[1] || 0)) / bufferedFactor : newKpt.position[1], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].position[2] || 0) + (newKpt.position[2] || 0)) / bufferedFactor : newKpt.position[2] - ], - positionRaw: [ - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].positionRaw[0] || 0) + (newKpt.positionRaw[0] || 0)) / bufferedFactor : newKpt.positionRaw[0], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].positionRaw[1] || 0) + (newKpt.positionRaw[1] || 0)) / bufferedFactor : newKpt.positionRaw[1], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].positionRaw[2] || 0) + (newKpt.positionRaw[2] || 0)) / bufferedFactor : newKpt.positionRaw[2] - ], - distance: [ - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (((_a2 = bufferedResult.body[i].keypoints[j].distance) == null ? void 0 : _a2[0]) || 0) + (((_b2 = newKpt.distance) == null ? void 0 : _b2[0]) || 0)) / bufferedFactor : (_c2 = newKpt.distance) == null ? void 0 : _c2[0], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (((_d2 = bufferedResult.body[i].keypoints[j].distance) == null ? void 0 : _d2[1]) || 0) + (((_e2 = newKpt.distance) == null ? void 0 : _e2[1]) || 0)) / bufferedFactor : (_f2 = newKpt.distance) == null ? void 0 : _f2[1], - bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (((_g2 = bufferedResult.body[i].keypoints[j].distance) == null ? void 0 : _g2[2]) || 0) + (((_h2 = newKpt.distance) == null ? void 0 : _h2[2]) || 0)) / bufferedFactor : (_i2 = newKpt.distance) == null ? void 0 : _i2[2] - ] - }; - }); - const annotations2 = {}; - let coords = { connected: {} }; - if ((_a = config3.body.modelPath) == null ? void 0 : _a.includes("efficientpose")) - coords = efficientposecoords_exports; - else if ((_b = config3.body.modelPath) == null ? void 0 : _b.includes("blazepose")) - coords = blazeposecoords_exports; - else if ((_c = config3.body.modelPath) == null ? void 0 : _c.includes("movenet")) - coords = movenetcoords_exports; - for (const [name, indexes] of Object.entries(coords.connected)) { - const pt = []; - for (let j = 0; j < indexes.length - 1; j++) { - const pt0 = keypoints.find((kp) => kp.part === indexes[j]); - const pt1 = keypoints.find((kp) => kp.part === indexes[j + 1]); - if (pt0 && pt1) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - bufferedResult.body[i] = { ...newResult.body[i], box, boxRaw, keypoints, annotations: annotations2 }; - } - } - if (!bufferedResult.hand || newResult.hand.length !== bufferedResult.hand.length) { - bufferedResult.hand = JSON.parse(JSON.stringify(newResult.hand)); - } else { - for (let i = 0; i < newResult.hand.length; i++) { - const box = newResult.hand[i].box.map((b, j) => ((bufferedFactor - 1) * bufferedResult.hand[i].box[j] + b) / bufferedFactor); - const boxRaw = newResult.hand[i].boxRaw.map((b, j) => ((bufferedFactor - 1) * bufferedResult.hand[i].boxRaw[j] + b) / bufferedFactor); - if (bufferedResult.hand[i].keypoints.length !== newResult.hand[i].keypoints.length) - bufferedResult.hand[i].keypoints = newResult.hand[i].keypoints; - const keypoints = newResult.hand[i].keypoints && newResult.hand[i].keypoints.length > 0 ? newResult.hand[i].keypoints.map((landmark, j) => landmark.map((coord, k) => ((bufferedFactor - 1) * (bufferedResult.hand[i].keypoints[j][k] || 1) + (coord || 0)) / bufferedFactor)) : []; - let annotations2 = {}; - if (Object.keys(bufferedResult.hand[i].annotations).length !== Object.keys(newResult.hand[i].annotations).length) { - bufferedResult.hand[i].annotations = newResult.hand[i].annotations; - annotations2 = bufferedResult.hand[i].annotations; - } else if (newResult.hand[i].annotations) { - for (const key of Object.keys(newResult.hand[i].annotations)) { - annotations2[key] = ((_f = (_e = (_d = newResult.hand[i]) == null ? void 0 : _d.annotations) == null ? void 0 : _e[key]) == null ? void 0 : _f[0]) ? newResult.hand[i].annotations[key].map((val, j) => val.map((coord, k) => ((bufferedFactor - 1) * bufferedResult.hand[i].annotations[key][j][k] + coord) / bufferedFactor)) : null; - } - } - bufferedResult.hand[i] = { ...newResult.hand[i], box, boxRaw, keypoints, annotations: annotations2 }; - } - } - if (!bufferedResult.face || newResult.face.length !== bufferedResult.face.length) { - bufferedResult.face = JSON.parse(JSON.stringify(newResult.face)); - } else { - for (let i = 0; i < newResult.face.length; i++) { - const box = newResult.face[i].box.map((b, j) => ((bufferedFactor - 1) * bufferedResult.face[i].box[j] + b) / bufferedFactor); - const boxRaw = newResult.face[i].boxRaw.map((b, j) => ((bufferedFactor - 1) * bufferedResult.face[i].boxRaw[j] + b) / bufferedFactor); - if (newResult.face[i].rotation) { - const rotation = { matrix: [0, 0, 0, 0, 0, 0, 0, 0, 0], angle: { roll: 0, yaw: 0, pitch: 0 }, gaze: { bearing: 0, strength: 0 } }; - rotation.matrix = (_g = newResult.face[i].rotation) == null ? void 0 : _g.matrix; - rotation.angle = { - roll: ((bufferedFactor - 1) * (((_i = (_h = bufferedResult.face[i].rotation) == null ? void 0 : _h.angle) == null ? void 0 : _i.roll) || 0) + (((_k = (_j = newResult.face[i].rotation) == null ? void 0 : _j.angle) == null ? void 0 : _k.roll) || 0)) / bufferedFactor, - yaw: ((bufferedFactor - 1) * (((_m = (_l = bufferedResult.face[i].rotation) == null ? void 0 : _l.angle) == null ? void 0 : _m.yaw) || 0) + (((_o = (_n = newResult.face[i].rotation) == null ? void 0 : _n.angle) == null ? void 0 : _o.yaw) || 0)) / bufferedFactor, - pitch: ((bufferedFactor - 1) * (((_q = (_p = bufferedResult.face[i].rotation) == null ? void 0 : _p.angle) == null ? void 0 : _q.pitch) || 0) + (((_s = (_r = newResult.face[i].rotation) == null ? void 0 : _r.angle) == null ? void 0 : _s.pitch) || 0)) / bufferedFactor - }; - rotation.gaze = { - bearing: ((bufferedFactor - 1) * (((_t = bufferedResult.face[i].rotation) == null ? void 0 : _t.gaze.bearing) || 0) + (((_u = newResult.face[i].rotation) == null ? void 0 : _u.gaze.bearing) || 0)) / bufferedFactor, - strength: ((bufferedFactor - 1) * (((_v = bufferedResult.face[i].rotation) == null ? void 0 : _v.gaze.strength) || 0) + (((_w = newResult.face[i].rotation) == null ? void 0 : _w.gaze.strength) || 0)) / bufferedFactor - }; - bufferedResult.face[i] = { ...newResult.face[i], rotation, box, boxRaw }; - } else { - bufferedResult.face[i] = { ...newResult.face[i], box, boxRaw }; - } - } - } - if (!bufferedResult.object || newResult.object.length !== bufferedResult.object.length) { - bufferedResult.object = JSON.parse(JSON.stringify(newResult.object)); - } else { - for (let i = 0; i < newResult.object.length; i++) { - const box = newResult.object[i].box.map((b, j) => ((bufferedFactor - 1) * bufferedResult.object[i].box[j] + b) / bufferedFactor); - const boxRaw = newResult.object[i].boxRaw.map((b, j) => ((bufferedFactor - 1) * bufferedResult.object[i].boxRaw[j] + b) / bufferedFactor); - bufferedResult.object[i] = { ...newResult.object[i], box, boxRaw }; - } - } - if (newResult.persons) { - const newPersons = newResult.persons; - if (!bufferedResult.persons || newPersons.length !== bufferedResult.persons.length) { - bufferedResult.persons = JSON.parse(JSON.stringify(newPersons)); - } else { - for (let i = 0; i < newPersons.length; i++) { - bufferedResult.persons[i].box = newPersons[i].box.map((box, j) => ((bufferedFactor - 1) * bufferedResult.persons[i].box[j] + box) / bufferedFactor); - } - } - } - if (newResult.gesture) - bufferedResult.gesture = newResult.gesture; - bufferedResult.width = newResult.width; - bufferedResult.height = newResult.height; - const t1 = now(); - interpolateTime = env.perfadd ? interpolateTime + Math.round(t1 - t0) : Math.round(t1 - t0); - if (newResult.performance) - bufferedResult.performance = { ...newResult.performance, interpolate: interpolateTime }; - return bufferedResult; -} - -// src/segmentation/meet.ts -var tf30 = __toESM(require_tfjs_esm()); -var model17; -async function load16(config3) { - if (!model17 || env.initial) - model17 = await loadModel(config3.segmentation.modelPath); - else if (config3.debug) - log("cached model:", model17["modelUrl"]); - return model17; -} -async function predict16(input, config3) { - var _a; - if (!model17) - model17 = await load16(config3); - if (!(model17 == null ? void 0 : model17["executor"]) || !((_a = model17 == null ? void 0 : model17.inputs) == null ? void 0 : _a[0].shape)) - return null; - const t2 = {}; - t2.resize = tf30.image.resizeBilinear(input, [model17.inputs[0].shape ? model17.inputs[0].shape[1] : 0, model17.inputs[0].shape ? model17.inputs[0].shape[2] : 0], false); - t2.norm = tf30.div(t2.resize, constants.tf255); - t2.res = model17.execute(t2.norm); - t2.squeeze = tf30.squeeze(t2.res, [0]); - [t2.bgRaw, t2.fgRaw] = tf30.unstack(t2.squeeze, 2); - t2.fg = tf30.softmax(t2.fgRaw); - t2.mul = tf30.mul(t2.fg, constants.tf255); - t2.expand = tf30.expandDims(t2.mul, 2); - t2.output = tf30.image.resizeBilinear(t2.expand, [input.shape[1] || 0, input.shape[2] || 0]); - let rgba; - switch (config3.segmentation.mode || "default") { - case "default": - t2.input = tf30.squeeze(input); - t2.concat = tf30.concat([t2.input, t2.output], -1); - rgba = tf30.cast(t2.concat, "int32"); - break; - case "alpha": - rgba = tf30.cast(t2.output, "int32"); - break; - default: - rgba = tf30.tensor(0); - } - Object.keys(t2).forEach((tensor6) => tf30.dispose(t2[tensor6])); - return rgba; -} - -// src/face/match.ts -var match_exports = {}; -__export(match_exports, { - distance: () => distance, - find: () => find, - similarity: () => similarity -}); -function distance(descriptor1, descriptor2, options4 = { order: 2, multiplier: 25 }) { - if (!descriptor1 || !descriptor1) - return Number.MAX_SAFE_INTEGER; - let sum3 = 0; - for (let i = 0; i < descriptor1.length; i++) { - const diff = !options4.order || options4.order === 2 ? descriptor1[i] - descriptor2[i] : Math.abs(descriptor1[i] - descriptor2[i]); - sum3 += !options4.order || options4.order === 2 ? diff * diff : diff ** options4.order; - } - return (options4.multiplier || 20) * sum3; -} -var normalizeDistance = (dist, order, min2, max5) => { - if (dist === 0) - return 1; - const root = order === 2 ? Math.sqrt(dist) : dist ** (1 / order); - const norm = (1 - root / 100 - min2) / (max5 - min2); - const clamp2 = Math.max(Math.min(norm, 1), 0); - return clamp2; -}; -function similarity(descriptor1, descriptor2, options4 = { order: 2, multiplier: 25, min: 0.2, max: 0.8 }) { - const dist = distance(descriptor1, descriptor2, options4); - return normalizeDistance(dist, options4.order || 2, options4.min || 0, options4.max || 1); -} -function find(descriptor, descriptors, options4 = { order: 2, multiplier: 25, threshold: 0, min: 0.2, max: 0.8 }) { - if (!Array.isArray(descriptor) || !Array.isArray(descriptors) || descriptor.length < 64 || descriptors.length === 0) { - return { index: -1, distance: Number.POSITIVE_INFINITY, similarity: 0 }; - } - let lowestDistance = Number.MAX_SAFE_INTEGER; - let index2 = -1; - for (let i = 0; i < descriptors.length; i++) { - const res = descriptors[i].length === descriptor.length ? distance(descriptor, descriptors[i], options4) : Number.MAX_SAFE_INTEGER; - if (res < lowestDistance) { - lowestDistance = res; - index2 = i; - } - if (lowestDistance < (options4.threshold || 0)) - break; - } - const normalizedSimilarity = normalizeDistance(lowestDistance, options4.order || 2, options4.min || 0, options4.max || 1); - return { index: index2, distance: lowestDistance, similarity: normalizedSimilarity }; -} - -// src/models.ts -var models_exports2 = {}; -__export(models_exports2, { - Models: () => Models, - validateModel: () => validateModel -}); - -// src/body/movenet.ts -var tf32 = __toESM(require_tfjs_esm()); - -// src/body/movenetfix.ts -var tf31 = __toESM(require_tfjs_esm()); -var maxJitter = 5e-3; -var cache5 = { - keypoints: [], - padding: [[0, 0], [0, 0], [0, 0], [0, 0]] -}; -function bodyParts(body4) { - for (const pair of horizontal) { - const left = body4.keypoints.findIndex((kp) => kp.part === pair[0]); - const right = body4.keypoints.findIndex((kp) => kp.part === pair[1]); - if (body4.keypoints[left] && body4.keypoints[right]) { - if (body4.keypoints[left].position[0] < body4.keypoints[right].position[0]) { - const tmp = body4.keypoints[left]; - body4.keypoints[left] = body4.keypoints[right]; - body4.keypoints[right] = tmp; - } - } - } - for (const pair of vertical) { - const lower = body4.keypoints.findIndex((kp) => kp && kp.part === pair[0]); - const higher = body4.keypoints.findIndex((kp) => kp && kp.part === pair[1]); - if (body4.keypoints[lower] && body4.keypoints[higher]) { - if (body4.keypoints[lower].position[1] < body4.keypoints[higher].position[1]) { - body4.keypoints.splice(lower, 1); - } - } - } - for (const [pair, compare2] of relative) { - const left = body4.keypoints.findIndex((kp) => kp && kp.part === pair[0]); - const right = body4.keypoints.findIndex((kp) => kp && kp.part === pair[1]); - const leftTo = body4.keypoints.findIndex((kp) => kp && kp.part === compare2[0]); - const rightTo = body4.keypoints.findIndex((kp) => kp && kp.part === compare2[1]); - if (!body4.keypoints[leftTo] || !body4.keypoints[rightTo]) - continue; - const distanceLeft = body4.keypoints[left] ? [ - Math.abs(body4.keypoints[leftTo].position[0] - body4.keypoints[left].position[0]), - Math.abs(body4.keypoints[rightTo].position[0] - body4.keypoints[left].position[0]) - ] : [0, 0]; - const distanceRight = body4.keypoints[right] ? [ - Math.abs(body4.keypoints[rightTo].position[0] - body4.keypoints[right].position[0]), - Math.abs(body4.keypoints[leftTo].position[0] - body4.keypoints[right].position[0]) - ] : [0, 0]; - if (distanceLeft[0] > distanceLeft[1] || distanceRight[0] > distanceRight[1]) { - const tmp = body4.keypoints[left]; - body4.keypoints[left] = body4.keypoints[right]; - body4.keypoints[right] = tmp; - } - } -} -function jitter(keypoints) { - for (let i = 0; i < keypoints.length; i++) { - if (keypoints[i] && cache5.keypoints[i]) { - const diff = [Math.abs(keypoints[i].positionRaw[0] - cache5.keypoints[i].positionRaw[0]), Math.abs(keypoints[i].positionRaw[1] - cache5.keypoints[i].positionRaw[1])]; - if (diff[0] < maxJitter && diff[1] < maxJitter) { - keypoints[i] = cache5.keypoints[i]; - } else { - cache5.keypoints[i] = keypoints[i]; - } - } else { - cache5.keypoints[i] = keypoints[i]; - } - } - return keypoints; -} -function padInput(input, inputSize10) { - var _a, _b; - const t2 = {}; - if (!((_a = input == null ? void 0 : input.shape) == null ? void 0 : _a[1]) || !((_b = input == null ? void 0 : input.shape) == null ? void 0 : _b[2])) - return input; - cache5.padding = [ - [0, 0], - [input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0, input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0], - [input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0, input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0], - [0, 0] - ]; - t2.pad = tf31.pad(input, cache5.padding); - t2.resize = tf31.image.resizeBilinear(t2.pad, [inputSize10, inputSize10]); - const final = tf31.cast(t2.resize, "int32"); - Object.keys(t2).forEach((tensor6) => tf31.dispose(t2[tensor6])); - return final; -} -function rescaleBody(body4, outputSize2) { - body4.keypoints = body4.keypoints.filter((kpt4) => kpt4 == null ? void 0 : kpt4.position); - for (const kpt4 of body4.keypoints) { - kpt4.position = [ - kpt4.position[0] * (outputSize2[0] + cache5.padding[2][0] + cache5.padding[2][1]) / outputSize2[0] - cache5.padding[2][0], - kpt4.position[1] * (outputSize2[1] + cache5.padding[1][0] + cache5.padding[1][1]) / outputSize2[1] - cache5.padding[1][0] - ]; - kpt4.positionRaw = [ - kpt4.position[0] / outputSize2[0], - kpt4.position[1] / outputSize2[1] - ]; - } - const rescaledBoxes = calc(body4.keypoints.map((pt) => pt.position), outputSize2); - body4.box = rescaledBoxes.box; - body4.boxRaw = rescaledBoxes.boxRaw; - return body4; -} - -// src/body/movenet.ts -var model18; -var inputSize8 = 0; -var skipped14 = Number.MAX_SAFE_INTEGER; -var cache6 = { - boxes: [], - bodies: [], - last: 0 -}; -async function load17(config3) { - var _a; - if (env.initial) - model18 = null; - if (!model18) { - fakeOps(["size"], config3); - model18 = await loadModel(config3.body.modelPath); - } else if (config3.debug) - log("cached model:", model18["modelUrl"]); - inputSize8 = (model18 == null ? void 0 : model18["executor"]) && ((_a = model18 == null ? void 0 : model18.inputs) == null ? void 0 : _a[0].shape) ? model18.inputs[0].shape[2] : 0; - if (inputSize8 < 64) - inputSize8 = 256; - return model18; -} -function parseSinglePose(res, config3, image28) { - const kpt4 = res[0][0]; - const keypoints = []; - let score = 0; - for (let id = 0; id < kpt4.length; id++) { - score = kpt4[id][2]; - if (score > config3.body.minConfidence) { - const positionRaw = [kpt4[id][1], kpt4[id][0]]; - keypoints.push({ - score: Math.round(100 * score) / 100, - part: kpt3[id], - positionRaw, - position: [ - Math.round((image28.shape[2] || 0) * positionRaw[0]), - Math.round((image28.shape[1] || 0) * positionRaw[1]) - ] - }); - } - } - score = keypoints.reduce((prev, curr) => curr.score > prev ? curr.score : prev, 0); - const bodies = []; - const newBox = calc(keypoints.map((pt) => pt.position), [image28.shape[2], image28.shape[1]]); - const annotations2 = {}; - for (const [name, indexes] of Object.entries(connected3)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = keypoints.find((kp) => kp.part === indexes[i]); - const pt1 = keypoints.find((kp) => kp.part === indexes[i + 1]); - if (pt0 && pt1 && pt0.score > (config3.body.minConfidence || 0) && pt1.score > (config3.body.minConfidence || 0)) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - const body4 = { id: 0, score, box: newBox.box, boxRaw: newBox.boxRaw, keypoints, annotations: annotations2 }; - bodyParts(body4); - bodies.push(body4); - return bodies; -} -function parseMultiPose(res, config3, image28) { - const bodies = []; - for (let id = 0; id < res[0].length; id++) { - const kpt4 = res[0][id]; - const totalScore = Math.round(100 * kpt4[51 + 4]) / 100; - if (totalScore > config3.body.minConfidence) { - const keypoints = []; - for (let i = 0; i < 17; i++) { - const score = kpt4[3 * i + 2]; - if (score > config3.body.minConfidence) { - const positionRaw = [kpt4[3 * i + 1], kpt4[3 * i + 0]]; - keypoints.push({ - part: kpt3[i], - score: Math.round(100 * score) / 100, - positionRaw, - position: [Math.round((image28.shape[2] || 0) * positionRaw[0]), Math.round((image28.shape[1] || 0) * positionRaw[1])] - }); - } - } - const newBox = calc(keypoints.map((pt) => pt.position), [image28.shape[2], image28.shape[1]]); - const annotations2 = {}; - for (const [name, indexes] of Object.entries(connected3)) { - const pt = []; - for (let i = 0; i < indexes.length - 1; i++) { - const pt0 = keypoints.find((kp) => kp.part === indexes[i]); - const pt1 = keypoints.find((kp) => kp.part === indexes[i + 1]); - if (pt0 && pt1 && pt0.score > (config3.body.minConfidence || 0) && pt1.score > (config3.body.minConfidence || 0)) - pt.push([pt0.position, pt1.position]); - } - annotations2[name] = pt; - } - const body4 = { id, score: totalScore, box: newBox.box, boxRaw: newBox.boxRaw, keypoints: [...keypoints], annotations: annotations2 }; - bodyParts(body4); - bodies.push(body4); - } - } - bodies.sort((a, b) => b.score - a.score); - if (bodies.length > config3.body.maxDetected) - bodies.length = config3.body.maxDetected; - return bodies; -} -async function predict17(input, config3) { - var _a; - if (!(model18 == null ? void 0 : model18["executor"]) || !((_a = model18 == null ? void 0 : model18.inputs) == null ? void 0 : _a[0].shape)) - return []; - if (!config3.skipAllowed) - cache6.boxes.length = 0; - skipped14++; - const skipTime = (config3.body.skipTime || 0) > now() - cache6.last; - const skipFrame = skipped14 < (config3.body.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame) { - return cache6.bodies; - } - return new Promise(async (resolve) => { - const t2 = {}; - skipped14 = 0; - t2.input = padInput(input, inputSize8); - t2.res = model18 == null ? void 0 : model18.execute(t2.input); - cache6.last = now(); - const res = await t2.res.array(); - cache6.bodies = t2.res.shape[2] === 17 ? parseSinglePose(res, config3, input) : parseMultiPose(res, config3, input); - for (const body4 of cache6.bodies) { - rescaleBody(body4, [input.shape[2] || 1, input.shape[1] || 1]); - jitter(body4.keypoints); - } - Object.keys(t2).forEach((tensor6) => tf32.dispose(t2[tensor6])); - resolve(cache6.bodies); - }); -} - -// src/object/nanodet.ts -var tf33 = __toESM(require_tfjs_esm()); -var model19; -var last10 = []; -var lastTime15 = 0; -var skipped15 = Number.MAX_SAFE_INTEGER; -var inputSize9 = 0; -var scaleBox = 2.5; -async function load18(config3) { - if (!model19 || env.initial) { - model19 = await loadModel(config3.object.modelPath); - const inputs = (model19 == null ? void 0 : model19["executor"]) ? Object.values(model19.modelSignature["inputs"]) : void 0; - inputSize9 = Array.isArray(inputs) ? parseInt(inputs[0].tensorShape.dim[2].size) : 416; - } else if (config3.debug) - log("cached model:", model19["modelUrl"]); - return model19; -} -async function process4(res, outputShape, config3) { - var _a, _b; - let id = 0; - let results = []; - const size2 = inputSize9; - for (const strideSize of [1, 2, 4]) { - const baseSize = strideSize * 13; - const scoresT = tf33.squeeze(res.find((a) => a.shape[1] === baseSize ** 2 && (a.shape[2] || 0) === labels2.length)); - const scores = await scoresT.array(); - const featuresT = tf33.squeeze(res.find((a) => a.shape[1] === baseSize ** 2 && (a.shape[2] || 0) < labels2.length)); - const boxesMaxT = tf33.reshape(featuresT, [-1, 4, (((_a = featuresT.shape) == null ? void 0 : _a[1]) || 0) / 4]); - const boxIdxT = tf33.argMax(boxesMaxT, 2); - const boxIdx = await boxIdxT.array(); - for (let i = 0; i < scoresT.shape[0]; i++) { - for (let j = 0; j < (((_b = scoresT.shape) == null ? void 0 : _b[1]) || 0); j++) { - const score = scores[i][j]; - if (score > (config3.object.minConfidence || 0) && j !== 61) { - const cx = (0.5 + Math.trunc(i % baseSize)) / baseSize; - const cy = (0.5 + Math.trunc(i / baseSize)) / baseSize; - const boxOffset = boxIdx[i].map((a) => a * (baseSize / strideSize / size2)); - const [x, y] = [ - cx - scaleBox / strideSize * boxOffset[0], - cy - scaleBox / strideSize * boxOffset[1] - ]; - const [w, h] = [ - cx + scaleBox / strideSize * boxOffset[2] - x, - cy + scaleBox / strideSize * boxOffset[3] - y - ]; - let boxRaw = [x, y, w, h]; - boxRaw = boxRaw.map((a) => Math.max(0, Math.min(a, 1))); - const box = [ - boxRaw[0] * outputShape[0], - boxRaw[1] * outputShape[1], - boxRaw[2] * outputShape[0], - boxRaw[3] * outputShape[1] - ]; - const result = { - id: id++, - score: Math.round(100 * score) / 100, - class: j + 1, - label: labels2[j].label, - box: box.map((a) => Math.trunc(a)), - boxRaw - }; - results.push(result); - } - } - } - tf33.dispose([scoresT, featuresT, boxesMaxT, boxIdxT]); - } - const nmsBoxes = results.map((a) => [a.boxRaw[1], a.boxRaw[0], a.boxRaw[3], a.boxRaw[2]]); - const nmsScores = results.map((a) => a.score); - let nmsIdx = []; - if (nmsBoxes && nmsBoxes.length > 0) { - const nms = await tf33.image.nonMaxSuppressionAsync(nmsBoxes, nmsScores, config3.object.maxDetected || 0, config3.object.iouThreshold, config3.object.minConfidence); - nmsIdx = Array.from(await nms.data()); - tf33.dispose(nms); - } - results = results.filter((_val, idx) => nmsIdx.includes(idx)).sort((a, b) => b.score - a.score); - return results; -} -async function predict18(image28, config3) { - if (!(model19 == null ? void 0 : model19["executor"])) - return []; - const skipTime = (config3.object.skipTime || 0) > now() - lastTime15; - const skipFrame = skipped15 < (config3.object.skipFrames || 0); - if (config3.skipAllowed && skipTime && skipFrame && last10.length > 0) { - skipped15++; - return last10; - } - skipped15 = 0; - if (!env.kernels.includes("mod") || !env.kernels.includes("sparsetodense")) - return last10; - return new Promise(async (resolve) => { - const outputSize2 = [image28.shape[2] || 0, image28.shape[1] || 0]; - const resizeT = tf33.image.resizeBilinear(image28, [inputSize9, inputSize9], false); - const normT = tf33.div(resizeT, constants.tf255); - const transposeT = tf33.transpose(normT, [0, 3, 1, 2]); - let objectT; - if (config3.object.enabled) - objectT = model19.execute(transposeT); - lastTime15 = now(); - const obj = await process4(objectT, outputSize2, config3); - last10 = obj; - tf33.dispose([resizeT, normT, transposeT, ...objectT]); - resolve(obj); - }); -} - -// src/body/posenet.ts -var tf34 = __toESM(require_tfjs_esm()); - -// src/body/posenetutils.ts -var partNames = [ - "nose", - "leftEye", - "rightEye", - "leftEar", - "rightEar", - "leftShoulder", - "rightShoulder", - "leftElbow", - "rightElbow", - "leftWrist", - "rightWrist", - "leftHip", - "rightHip", - "leftKnee", - "rightKnee", - "leftAnkle", - "rightAnkle" -]; -var count = partNames.length; -var partIds = partNames.reduce((result, jointName, i) => { - result[jointName] = i; - return result; -}, {}); -var connectedPartNames = [ - ["leftHip", "leftShoulder"], - ["leftElbow", "leftShoulder"], - ["leftElbow", "leftWrist"], - ["leftHip", "leftKnee"], - ["leftKnee", "leftAnkle"], - ["rightHip", "rightShoulder"], - ["rightElbow", "rightShoulder"], - ["rightElbow", "rightWrist"], - ["rightHip", "rightKnee"], - ["rightKnee", "rightAnkle"], - ["leftShoulder", "rightShoulder"], - ["leftHip", "rightHip"] -]; -var connectedPartIndices = connectedPartNames.map(([jointNameA, jointNameB]) => [partIds[jointNameA], partIds[jointNameB]]); -var poseChain = [ - ["nose", "leftEye"], - ["leftEye", "leftEar"], - ["nose", "rightEye"], - ["rightEye", "rightEar"], - ["nose", "leftShoulder"], - ["leftShoulder", "leftElbow"], - ["leftElbow", "leftWrist"], - ["leftShoulder", "leftHip"], - ["leftHip", "leftKnee"], - ["leftKnee", "leftAnkle"], - ["nose", "rightShoulder"], - ["rightShoulder", "rightElbow"], - ["rightElbow", "rightWrist"], - ["rightShoulder", "rightHip"], - ["rightHip", "rightKnee"], - ["rightKnee", "rightAnkle"] -]; -function getBoundingBox(keypoints) { - const coord = keypoints.reduce(({ maxX, maxY, minX, minY }, { position: { x, y } }) => ({ - maxX: Math.max(maxX, x), - maxY: Math.max(maxY, y), - minX: Math.min(minX, x), - minY: Math.min(minY, y) - }), { - maxX: Number.NEGATIVE_INFINITY, - maxY: Number.NEGATIVE_INFINITY, - minX: Number.POSITIVE_INFINITY, - minY: Number.POSITIVE_INFINITY - }); - return [coord.minX, coord.minY, coord.maxX - coord.minX, coord.maxY - coord.minY]; -} -function scalePoses(poses, [height, width], [inputResolutionHeight, inputResolutionWidth]) { - const scaleY = height / inputResolutionHeight; - const scaleX = width / inputResolutionWidth; - const scalePose = (pose, i) => ({ - id: i, - score: pose.score, - boxRaw: [pose.box[0] / inputResolutionWidth, pose.box[1] / inputResolutionHeight, pose.box[2] / inputResolutionWidth, pose.box[3] / inputResolutionHeight], - box: [Math.trunc(pose.box[0] * scaleX), Math.trunc(pose.box[1] * scaleY), Math.trunc(pose.box[2] * scaleX), Math.trunc(pose.box[3] * scaleY)], - keypoints: pose.keypoints.map(({ score, part, position }) => ({ - score, - part, - position: [Math.trunc(position.x * scaleX), Math.trunc(position.y * scaleY)], - positionRaw: [position.x / inputResolutionHeight, position.y / inputResolutionHeight] - })), - annotations: {} - }); - const scaledPoses = poses.map((pose, i) => scalePose(pose, i)); - return scaledPoses; -} -var MaxHeap = class { - constructor(maxSize2, getElementValue) { - __publicField(this, "priorityQueue"); - __publicField(this, "numberOfElements"); - __publicField(this, "getElementValue"); - this.priorityQueue = new Array(maxSize2); - this.numberOfElements = -1; - this.getElementValue = getElementValue; - } - enqueue(x) { - this.priorityQueue[++this.numberOfElements] = x; - this.swim(this.numberOfElements); - } - dequeue() { - const max5 = this.priorityQueue[0]; - this.exchange(0, this.numberOfElements--); - this.sink(0); - this.priorityQueue[this.numberOfElements + 1] = null; - return max5; - } - empty() { - return this.numberOfElements === -1; - } - size() { - return this.numberOfElements + 1; - } - all() { - return this.priorityQueue.slice(0, this.numberOfElements + 1); - } - max() { - return this.priorityQueue[0]; - } - swim(k) { - while (k > 0 && this.less(Math.floor(k / 2), k)) { - this.exchange(k, Math.floor(k / 2)); - k = Math.floor(k / 2); - } - } - sink(k) { - while (2 * k <= this.numberOfElements) { - let j = 2 * k; - if (j < this.numberOfElements && this.less(j, j + 1)) - j++; - if (!this.less(k, j)) - break; - this.exchange(k, j); - k = j; - } - } - getValueAt(i) { - return this.getElementValue(this.priorityQueue[i]); - } - less(i, j) { - return this.getValueAt(i) < this.getValueAt(j); - } - exchange(i, j) { - const t2 = this.priorityQueue[i]; - this.priorityQueue[i] = this.priorityQueue[j]; - this.priorityQueue[j] = t2; - } -}; -function getOffsetPoint(y, x, keypoint, offsets) { - return { - y: offsets.get(y, x, keypoint), - x: offsets.get(y, x, keypoint + count) - }; -} -function getImageCoords(part, outputStride2, offsets) { - const { heatmapY, heatmapX, id: keypoint } = part; - const { y, x } = getOffsetPoint(heatmapY, heatmapX, keypoint, offsets); - return { - x: part.heatmapX * outputStride2 + x, - y: part.heatmapY * outputStride2 + y - }; -} -function clamp(a, min2, max5) { - if (a < min2) - return min2; - if (a > max5) - return max5; - return a; -} -function squaredDistance(y1, x1, y2, x2) { - const dy = y2 - y1; - const dx = x2 - x1; - return dy * dy + dx * dx; -} -function addVectors(a, b) { - return { x: a.x + b.x, y: a.y + b.y }; -} - -// src/body/posenet.ts -var model20; -var poseNetOutputs = ["MobilenetV1/offset_2/BiasAdd", "MobilenetV1/heatmap_2/BiasAdd", "MobilenetV1/displacement_fwd_2/BiasAdd", "MobilenetV1/displacement_bwd_2/BiasAdd"]; -var localMaximumRadius = 1; -var outputStride = 16; -var squaredNmsRadius = 50 ** 2; -function traverse(edgeId, sourceKeypoint, targetId, scores, offsets, displacements, offsetRefineStep = 2) { - const getDisplacement = (point2) => ({ - y: displacements.get(point2.y, point2.x, edgeId), - x: displacements.get(point2.y, point2.x, displacements.shape[2] / 2 + edgeId) - }); - const getStridedIndexNearPoint = (point2, height2, width2) => ({ - y: clamp(Math.round(point2.y / outputStride), 0, height2 - 1), - x: clamp(Math.round(point2.x / outputStride), 0, width2 - 1) - }); - const [height, width] = scores.shape; - const sourceKeypointIndices = getStridedIndexNearPoint(sourceKeypoint.position, height, width); - const displacement = getDisplacement(sourceKeypointIndices); - const displacedPoint = addVectors(sourceKeypoint.position, displacement); - let targetKeypoint = displacedPoint; - for (let i = 0; i < offsetRefineStep; i++) { - const targetKeypointIndices = getStridedIndexNearPoint(targetKeypoint, height, width); - const offsetPoint = getOffsetPoint(targetKeypointIndices.y, targetKeypointIndices.x, targetId, offsets); - targetKeypoint = addVectors( - { x: targetKeypointIndices.x * outputStride, y: targetKeypointIndices.y * outputStride }, - { x: offsetPoint.x, y: offsetPoint.y } - ); - } - const targetKeyPointIndices = getStridedIndexNearPoint(targetKeypoint, height, width); - const score = scores.get(targetKeyPointIndices.y, targetKeyPointIndices.x, targetId); - return { position: targetKeypoint, part: partNames[targetId], score }; -} -function decodePose(root, scores, offsets, displacementsFwd, displacementsBwd) { - const tuples = poseChain.map(([parentJoinName, childJoinName]) => [partIds[parentJoinName], partIds[childJoinName]]); - const edgesFwd = tuples.map(([, childJointId]) => childJointId); - const edgesBwd = tuples.map(([parentJointId]) => parentJointId); - const numParts = scores.shape[2]; - const numEdges = edgesFwd.length; - const keypoints = new Array(numParts); - const rootPoint = getImageCoords(root.part, outputStride, offsets); - keypoints[root.part.id] = { - score: root.score, - part: partNames[root.part.id], - position: rootPoint - }; - for (let edge = numEdges - 1; edge >= 0; --edge) { - const sourceId = edgesFwd[edge]; - const targetId = edgesBwd[edge]; - if (keypoints[sourceId] && !keypoints[targetId]) { - keypoints[targetId] = traverse(edge, keypoints[sourceId], targetId, scores, offsets, displacementsBwd); - } - } - for (let edge = 0; edge < numEdges; ++edge) { - const sourceId = edgesBwd[edge]; - const targetId = edgesFwd[edge]; - if (keypoints[sourceId] && !keypoints[targetId]) { - keypoints[targetId] = traverse(edge, keypoints[sourceId], targetId, scores, offsets, displacementsFwd); - } - } - return keypoints; -} -function scoreIsMaximumInLocalWindow(keypointId, score, heatmapY, heatmapX, scores) { - const [height, width] = scores.shape; - let localMaximum = true; - const yStart = Math.max(heatmapY - localMaximumRadius, 0); - const yEnd = Math.min(heatmapY + localMaximumRadius + 1, height); - for (let yCurrent = yStart; yCurrent < yEnd; ++yCurrent) { - const xStart = Math.max(heatmapX - localMaximumRadius, 0); - const xEnd = Math.min(heatmapX + localMaximumRadius + 1, width); - for (let xCurrent = xStart; xCurrent < xEnd; ++xCurrent) { - if (scores.get(yCurrent, xCurrent, keypointId) > score) { - localMaximum = false; - break; - } - } - if (!localMaximum) - break; - } - return localMaximum; -} -function buildPartWithScoreQueue(minConfidence2, scores) { - const [height, width, numKeypoints] = scores.shape; - const queue = new MaxHeap(height * width * numKeypoints, ({ score }) => score); - for (let heatmapY = 0; heatmapY < height; ++heatmapY) { - for (let heatmapX = 0; heatmapX < width; ++heatmapX) { - for (let keypointId = 0; keypointId < numKeypoints; ++keypointId) { - const score = scores.get(heatmapY, heatmapX, keypointId); - if (score < minConfidence2) - continue; - if (scoreIsMaximumInLocalWindow(keypointId, score, heatmapY, heatmapX, scores)) - queue.enqueue({ score, part: { heatmapY, heatmapX, id: keypointId } }); - } - } - } - return queue; -} -function withinRadius(poses, { x, y }, keypointId) { - return poses.some(({ keypoints }) => { - var _a; - const correspondingKeypoint = (_a = keypoints[keypointId]) == null ? void 0 : _a.position; - if (!correspondingKeypoint) - return false; - return squaredDistance(y, x, correspondingKeypoint.y, correspondingKeypoint.x) <= squaredNmsRadius; - }); -} -function getInstanceScore(existingPoses, keypoints) { - const notOverlappedKeypointScores = keypoints.reduce((result, { position, score }, keypointId) => { - if (!withinRadius(existingPoses, position, keypointId)) - result += score; - return result; - }, 0); - return notOverlappedKeypointScores / keypoints.length; -} -function decode(offsets, scores, displacementsFwd, displacementsBwd, maxDetected, minConfidence2) { - const poses = []; - const queue = buildPartWithScoreQueue(minConfidence2, scores); - while (poses.length < maxDetected && !queue.empty()) { - const root = queue.dequeue(); - const rootImageCoords = getImageCoords(root.part, outputStride, offsets); - if (withinRadius(poses, rootImageCoords, root.part.id)) - continue; - let keypoints = decodePose(root, scores, offsets, displacementsFwd, displacementsBwd); - keypoints = keypoints.filter((a) => a.score > minConfidence2); - const score = getInstanceScore(poses, keypoints); - const box = getBoundingBox(keypoints); - if (score > minConfidence2) - poses.push({ keypoints, box, score: Math.round(100 * score) / 100 }); - } - return poses; -} -async function predict19(input, config3) { - if (!(model20 == null ? void 0 : model20["executor"])) - return []; - const res = tf34.tidy(() => { - if (!model20.inputs[0].shape) - return []; - const resized = tf34.image.resizeBilinear(input, [model20.inputs[0].shape[2], model20.inputs[0].shape[1]]); - const normalized = tf34.sub(tf34.div(tf34.cast(resized, "float32"), 127.5), 1); - const results = model20.execute(normalized, poseNetOutputs); - const results3d = results.map((y) => tf34.squeeze(y, [0])); - results3d[1] = tf34.sigmoid(results3d[1]); - return results3d; - }); - const buffers = await Promise.all(res.map((tensor6) => tensor6.buffer())); - for (const t2 of res) - tf34.dispose(t2); - const decoded = decode(buffers[0], buffers[1], buffers[2], buffers[3], config3.body.maxDetected, config3.body.minConfidence); - if (!model20.inputs[0].shape) - return []; - const scaled = scalePoses(decoded, [input.shape[1], input.shape[2]], [model20.inputs[0].shape[2], model20.inputs[0].shape[1]]); - return scaled; -} -async function load19(config3) { - if (!model20 || env.initial) - model20 = await loadModel(config3.body.modelPath); - else if (config3.debug) - log("cached model:", model20["modelUrl"]); - return model20; -} - -// src/segmentation/rvm.ts -var tf35 = __toESM(require_tfjs_esm()); -var model21; -var outputNodes2 = ["fgr", "pha", "r1o", "r2o", "r3o", "r4o"]; -var t = {}; -var ratio = 0; -function init3(config3) { - tf35.dispose([t.r1i, t.r2i, t.r3i, t.r4i, t.downsample_ratio]); - t.r1i = tf35.tensor(0); - t.r2i = tf35.tensor(0); - t.r3i = tf35.tensor(0); - t.r4i = tf35.tensor(0); - ratio = config3.segmentation.ratio || 0.5; - t.downsample_ratio = tf35.tensor(ratio); -} -async function load20(config3) { - if (!model21 || env.initial) - model21 = await loadModel(config3.segmentation.modelPath); - else if (config3.debug) - log("cached model:", model21["modelUrl"]); - init3(config3); - return model21; -} -var normalize = (r) => tf35.tidy(() => { - const squeeze14 = tf35.squeeze(r, [0]); - const mul15 = tf35.mul(squeeze14, constants.tf255); - const cast8 = tf35.cast(mul15, "int32"); - return cast8; -}); -function getRGBA(fgr, pha) { - const rgb2 = fgr ? normalize(fgr) : tf35.fill([pha.shape[1] || 0, pha.shape[2] || 0, 3], 255, "int32"); - const a = pha ? normalize(pha) : tf35.fill([fgr.shape[1] || 0, fgr.shape[2] || 0, 1], 255, "int32"); - const rgba = tf35.concat([rgb2, a], -1); - tf35.dispose([rgb2, a]); - return rgba; -} -function getState(state) { - return tf35.tidy(() => { - const r = {}; - r.unstack = tf35.unstack(state, -1); - r.concat = tf35.concat(r.unstack, 1); - r.split = tf35.split(r.concat, 4, 1); - r.stack = tf35.concat(r.split, 2); - r.squeeze = tf35.squeeze(r.stack, [0]); - r.expand = tf35.expandDims(r.squeeze, -1); - r.add = tf35.add(r.expand, 1); - r.mul = tf35.mul(r.add, 127.5); - r.cast = tf35.cast(r.mul, "int32"); - r.tile = tf35.tile(r.cast, [1, 1, 3]); - r.alpha = tf35.fill([r.tile.shape[0] || 0, r.tile.shape[1] || 0, 1], 255, "int32"); - return tf35.concat([r.tile, r.alpha], -1); - }); -} -async function predict20(input, config3) { - if (!model21) - model21 = await load20(config3); - if (!(model21 == null ? void 0 : model21["executor"])) - return null; - t.src = tf35.div(input, 255); - if (ratio !== config3.segmentation.ratio) - init3(config3); - const [fgr, pha, r1o, r2o, r3o, r4o] = await model21.executeAsync(t, outputNodes2); - let rgba; - switch (config3.segmentation.mode || "default") { - case "default": - rgba = getRGBA(fgr, pha); - break; - case "alpha": - rgba = getRGBA(null, pha); - break; - case "foreground": - rgba = getRGBA(fgr, null); - break; - case "state": - rgba = getState(r1o); - break; - default: - rgba = tf35.tensor(0); - } - tf35.dispose([t.src, fgr, pha, t.r1i, t.r2i, t.r3i, t.r4i]); - [t.r1i, t.r2i, t.r3i, t.r4i] = [r1o, r2o, r3o, r4o]; - return rgba; -} - -// src/segmentation/selfie.ts -var tf36 = __toESM(require_tfjs_esm()); -var model22; -async function load21(config3) { - if (!model22 || env.initial) - model22 = await loadModel(config3.segmentation.modelPath); - else if (config3.debug) - log("cached model:", model22["modelUrl"]); - return model22; -} -async function predict21(input, config3) { - var _a; - if (!model22) - model22 = await load21(config3); - if (!(model22 == null ? void 0 : model22["executor"]) || !((_a = model22 == null ? void 0 : model22.inputs) == null ? void 0 : _a[0].shape)) - return null; - const t2 = {}; - t2.resize = tf36.image.resizeBilinear(input, [model22.inputs[0].shape ? model22.inputs[0].shape[1] : 0, model22.inputs[0].shape ? model22.inputs[0].shape[2] : 0], false); - t2.norm = tf36.div(t2.resize, constants.tf255); - t2.res = model22.execute(t2.norm); - t2.squeeze = tf36.squeeze(t2.res, [0]); - t2.alpha = tf36.image.resizeBilinear(t2.squeeze, [input.shape[1] || 0, input.shape[2] || 0]); - t2.mul = tf36.mul(t2.alpha, constants.tf255); - let rgba; - switch (config3.segmentation.mode || "default") { - case "default": - t2.input = tf36.squeeze(input); - t2.concat = tf36.concat([t2.input, t2.mul], -1); - rgba = tf36.cast(t2.concat, "int32"); - break; - case "alpha": - rgba = tf36.cast(t2.mul, "int32"); - break; - default: - rgba = tf36.tensor(0); - } - Object.keys(t2).forEach((tensor6) => tf36.dispose(t2[tensor6])); - return rgba; -} - -// src/models.ts -function validateModel(instance, model23, name) { - var _a, _b; - if (!model23) - return null; - if (!((_a = instance == null ? void 0 : instance.config) == null ? void 0 : _a.validateModels)) - return null; - const simpleOps = ["const", "placeholder", "noop", "pad", "squeeze", "add", "sub", "mul", "div"]; - const ignoreOps = ["biasadd", "fusedbatchnormv3", "matmul", "switch", "shape", "merge", "split", "broadcastto"]; - const ops = []; - const missing = []; - const url = model23["modelUrl"]; - const executor = model23["executor"]; - if ((_b = executor == null ? void 0 : executor.graph) == null ? void 0 : _b.nodes) { - for (const kernel of Object.values(executor.graph.nodes)) { - const op = kernel.op.toLowerCase(); - if (!ops.includes(op)) - ops.push(op); - } - } else { - if (!executor && instance.config.debug) { - log("model not loaded", name); - } - } - for (const op of ops) { - if (!simpleOps.includes(op) && !ignoreOps.includes(op) && !instance.env.kernels.includes(op) && !instance.env.kernels.includes(op.replace("_", "")) && !instance.env.kernels.includes(op.replace("native", "")) && !instance.env.kernels.includes(op.replace("v2", ""))) { - missing.push(op); - } - } - if (instance.config.debug && missing.length > 0) - log("model validation failed:", name, missing); - return missing.length > 0 ? { name, missing, ops, url } : null; -} -var Models = class { - constructor(currentInstance) { - __publicField(this, "instance"); - __publicField(this, "models", {}); - this.models = {}; - this.instance = currentInstance; - } - stats() { - let totalSizeFromManifest = 0; - let totalSizeWeights = 0; - let totalSizeLoading = 0; - for (const m of Object.values(modelStats)) { - totalSizeFromManifest += m.sizeFromManifest; - totalSizeWeights += m.sizeLoadedWeights; - totalSizeLoading += m.sizeDesired; - } - const percentageLoaded = totalSizeLoading > 0 ? totalSizeWeights / totalSizeLoading : 0; - return { - numLoadedModels: Object.values(modelStats).length, - numDefinedModels: Object.keys(this.models).length, - percentageLoaded, - totalSizeFromManifest, - totalSizeWeights, - totalSizeLoading, - modelStats: Object.values(modelStats) - }; - } - reset() { - for (const model23 of Object.keys(this.models)) - this.models[model23] = null; - } - async load(instance) { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A; - if (env.initial) - this.reset(); - if (instance) - this.instance = instance; - const m = {}; - m.blazeface = this.instance.config.face.enabled && !this.models.blazeface ? load3(this.instance.config) : null; - m.antispoof = this.instance.config.face.enabled && ((_a = this.instance.config.face.antispoof) == null ? void 0 : _a.enabled) && !this.models.antispoof ? load8(this.instance.config) : null; - m.liveness = this.instance.config.face.enabled && ((_b = this.instance.config.face.liveness) == null ? void 0 : _b.enabled) && !this.models.liveness ? load9(this.instance.config) : null; - m.faceres = this.instance.config.face.enabled && ((_c = this.instance.config.face.description) == null ? void 0 : _c.enabled) && !this.models.faceres ? load7(this.instance.config) : null; - m.emotion = this.instance.config.face.enabled && ((_d = this.instance.config.face.emotion) == null ? void 0 : _d.enabled) && !this.models.emotion ? load6(this.instance.config) : null; - m.iris = this.instance.config.face.enabled && ((_e = this.instance.config.face.iris) == null ? void 0 : _e.enabled) && !((_f = this.instance.config.face.attention) == null ? void 0 : _f.enabled) && !this.models.iris ? load4(this.instance.config) : null; - m.facemesh = this.instance.config.face.enabled && ((_g = this.instance.config.face.mesh) == null ? void 0 : _g.enabled) && !this.models.facemesh ? load5(this.instance.config) : null; - m.gear = this.instance.config.face.enabled && ((_h = this.instance.config.face["gear"]) == null ? void 0 : _h.enabled) && !this.models.gear ? load10(this.instance.config) : null; - m.ssrnetage = this.instance.config.face.enabled && ((_i = this.instance.config.face["ssrnet"]) == null ? void 0 : _i.enabled) && !this.models.ssrnetage ? load11(this.instance.config) : null; - m.ssrnetgender = this.instance.config.face.enabled && ((_j = this.instance.config.face["ssrnet"]) == null ? void 0 : _j.enabled) && !this.models.ssrnetgender ? load12(this.instance.config) : null; - m.mobilefacenet = this.instance.config.face.enabled && ((_k = this.instance.config.face["mobilefacenet"]) == null ? void 0 : _k.enabled) && !this.models.mobilefacenet ? load13(this.instance.config) : null; - m.insightface = this.instance.config.face.enabled && ((_l = this.instance.config.face["insightface"]) == null ? void 0 : _l.enabled) && !this.models.insightface ? load14(this.instance.config) : null; - m.blazepose = this.instance.config.body.enabled && !this.models.blazepose && ((_m = this.instance.config.body.modelPath) == null ? void 0 : _m.includes("blazepose")) ? loadPose(this.instance.config) : null; - m.blazeposedetect = this.instance.config.body.enabled && !this.models.blazeposedetect && this.instance.config.body["detector"] && this.instance.config.body["detector"].modelPath ? loadDetect(this.instance.config) : null; - m.efficientpose = this.instance.config.body.enabled && !this.models.efficientpose && ((_n = this.instance.config.body.modelPath) == null ? void 0 : _n.includes("efficientpose")) ? load2(this.instance.config) : null; - m.movenet = this.instance.config.body.enabled && !this.models.movenet && ((_o = this.instance.config.body.modelPath) == null ? void 0 : _o.includes("movenet")) ? load17(this.instance.config) : null; - m.posenet = this.instance.config.body.enabled && !this.models.posenet && ((_p = this.instance.config.body.modelPath) == null ? void 0 : _p.includes("posenet")) ? load19(this.instance.config) : null; - m.handtrack = this.instance.config.hand.enabled && !this.models.handtrack && ((_r = (_q = this.instance.config.hand.detector) == null ? void 0 : _q.modelPath) == null ? void 0 : _r.includes("handtrack")) ? loadDetect2(this.instance.config) : null; - m.handskeleton = this.instance.config.hand.enabled && this.instance.config.hand.landmarks && !this.models.handskeleton && ((_t = (_s = this.instance.config.hand.detector) == null ? void 0 : _s.modelPath) == null ? void 0 : _t.includes("handtrack")) ? loadSkeleton(this.instance.config) : null; - if ((_v = (_u = this.instance.config.hand.detector) == null ? void 0 : _u.modelPath) == null ? void 0 : _v.includes("handdetect")) - [m.handpose, m.handskeleton] = !this.models.handpose ? await load15(this.instance.config) : [null, null]; - m.centernet = this.instance.config.object.enabled && !this.models.centernet && ((_w = this.instance.config.object.modelPath) == null ? void 0 : _w.includes("centernet")) ? load(this.instance.config) : null; - m.nanodet = this.instance.config.object.enabled && !this.models.nanodet && ((_x = this.instance.config.object.modelPath) == null ? void 0 : _x.includes("nanodet")) ? load18(this.instance.config) : null; - m.selfie = this.instance.config.segmentation.enabled && !this.models.selfie && ((_y = this.instance.config.segmentation.modelPath) == null ? void 0 : _y.includes("selfie")) ? load21(this.instance.config) : null; - m.meet = this.instance.config.segmentation.enabled && !this.models.meet && ((_z = this.instance.config.segmentation.modelPath) == null ? void 0 : _z.includes("meet")) ? load16(this.instance.config) : null; - m.rvm = this.instance.config.segmentation.enabled && !this.models.rvm && ((_A = this.instance.config.segmentation.modelPath) == null ? void 0 : _A.includes("rvm")) ? load20(this.instance.config) : null; - for (const [model23, promise] of Object.entries(m)) { - if (promise == null ? void 0 : promise["then"]) - promise["then"]((val) => this.models[model23] = val); - } - await Promise.all(Object.values(m)); - } - list() { - const models3 = Object.keys(this.models).map((model23) => { - var _a; - return { name: model23, loaded: this.models[model23] !== null, size: 0, url: this.models[model23] ? (_a = this.models[model23]) == null ? void 0 : _a["modelUrl"] : null }; - }); - for (const m of models3) { - const stats = Object.keys(modelStats).find((s) => s.startsWith(m.name)); - if (!stats) - continue; - m.size = modelStats[stats].sizeLoadedWeights; - m.url = modelStats[stats].url; - } - return models3; - } - loaded() { - const list = this.list(); - const loaded = list.filter((model23) => model23.loaded).map((model23) => model23.name); - return loaded; - } - validate() { - const missing = []; - for (const defined of Object.keys(this.models)) { - const model23 = this.models[defined]; - if (!model23) - continue; - const res = validateModel(this.instance, model23, defined); - if (res) - missing.push(res); - } - return missing; - } -}; - -// src/util/persons.ts -function join2(faces, bodies, hands, gestures, shape) { - var _a, _b, _c, _d, _e, _f; - let id = 0; - const persons = []; - for (const face4 of faces) { - const person2 = { id: id++, face: face4, body: null, hands: { left: null, right: null }, gestures: [], box: [0, 0, 0, 0] }; - for (const body4 of bodies) { - if (face4.box[0] > body4.box[0] && face4.box[0] < body4.box[0] + body4.box[2] && face4.box[1] + face4.box[3] > body4.box[1] && face4.box[1] + face4.box[3] < body4.box[1] + body4.box[3]) { - person2.body = body4; - } - } - if (person2.body) { - for (const hand3 of hands) { - if (hand3.box[0] + hand3.box[2] > person2.body.box[0] && hand3.box[0] + hand3.box[2] < person2.body.box[0] + person2.body.box[2] && hand3.box[1] + hand3.box[3] > person2.body.box[1] && hand3.box[1] + hand3.box[3] < person2.body.box[1] + person2.body.box[3]) { - if (person2.hands) - person2.hands.left = hand3; - } - if (hand3.box[0] < person2.body.box[0] + person2.body.box[2] && hand3.box[0] > person2.body.box[0] && hand3.box[1] + hand3.box[3] > person2.body.box[1] && hand3.box[1] + hand3.box[3] < person2.body.box[1] + person2.body.box[3]) { - if (person2.hands) - person2.hands.right = hand3; - } - } - } - for (const gesture2 of gestures) { - if (gesture2["face"] !== void 0 && gesture2["face"] === face4.id) - person2.gestures.push(gesture2); - else if (gesture2["iris"] !== void 0 && gesture2["iris"] === face4.id) - person2.gestures.push(gesture2); - else if (gesture2["body"] !== void 0 && gesture2["body"] === ((_a = person2.body) == null ? void 0 : _a.id)) - person2.gestures.push(gesture2); - else if (gesture2["hand"] !== void 0 && gesture2["hand"] === ((_b = person2.hands.left) == null ? void 0 : _b.id)) - person2.gestures.push(gesture2); - else if (gesture2["hand"] !== void 0 && gesture2["hand"] === ((_c = person2.hands.right) == null ? void 0 : _c.id)) - person2.gestures.push(gesture2); - } - const x = []; - const y = []; - const extractXY = (box) => { - if (box && box.length === 4) { - x.push(box[0], box[0] + box[2]); - y.push(box[1], box[1] + box[3]); - } - }; - extractXY(person2.face.box); - extractXY((_d = person2.body) == null ? void 0 : _d.box); - extractXY((_e = person2.hands.left) == null ? void 0 : _e.box); - extractXY((_f = person2.hands.right) == null ? void 0 : _f.box); - const minX = Math.min(...x); - const minY = Math.min(...y); - person2.box = [minX, minY, Math.max(...x) - minX, Math.max(...y) - minY]; - if ((shape == null ? void 0 : shape[1]) && (shape == null ? void 0 : shape[2])) - person2.boxRaw = [person2.box[0] / shape[2], person2.box[1] / shape[1], person2.box[2] / shape[2], person2.box[3] / shape[1]]; - persons.push(person2); - } - return persons; -} - -// src/warmup.ts -var tf37 = __toESM(require_tfjs_esm()); - -// src/sample.ts -var face3 = ` + gaze: [gaze]\xB0`,body:"body [score]%",bodyPart:"[label] [score]%",object:"[label] [score]%",hand:"[label] [score]%",finger:"[label]",gesture:"[where] [who]: [what]"};var r5=0;function Fs(e,t,n){let o=a0(x0,n);if(!t||!e)return;let r=Q0(e);if(!!r){r.lineJoin="round",r.font=o.font;for(let s=0;sa5,kpt:()=>A5});var A5=["nose","leftEyeInside","leftEye","leftEyeOutside","rightEyeInside","rightEye","rightEyeOutside","leftEar","rightEar","leftMouth","rightMouth","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftPinky","rightPinky","leftIndex","rightIndex","leftThumb","rightThumb","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle","leftHeel","rightHeel","leftFoot","rightFoot","bodyCenter","bodyTop","leftPalm","leftHand","rightPalm","rightHand"],a5={shoulders:["leftShoulder","rightShoulder"],hips:["rightHip","leftHip"],mouth:["leftMouth","rightMouth"],leftLegUpper:["leftHip","leftKnee"],leftLegLower:["leftKnee","leftAnkle"],leftFoot:["leftAnkle","leftHeel","leftFoot"],leftTorso:["leftShoulder","leftHip"],leftArmUpper:["leftShoulder","leftElbow"],leftArmLower:["leftElbow","leftWrist"],leftHand:["leftWrist","leftPalm"],leftHandPinky:["leftPalm","leftPinky"],leftHandIndex:["leftPalm","leftIndex"],leftHandThumb:["leftPalm","leftThumb"],leftEyeOutline:["leftEyeInside","leftEyeOutside"],rightLegUpper:["rightHip","rightKnee"],rightLegLower:["rightKnee","rightAnkle"],rightFoot:["rightAnkle","rightHeel","rightFoot"],rightTorso:["rightShoulder","rightHip"],rightArmUpper:["rightShoulder","rightElbow"],rightArmLower:["rightElbow","rightWrist"],rightHand:["rightWrist","rightPalm"],rightHandPinky:["rightPalm","rightPinky"],rightHandIndex:["rightPalm","rightIndex"],rightHandThumb:["rightPalm","rightThumb"],rightEyeOutline:["rightEyeInside","rightEyeOutside"]};var D=Z(H());var _0,t2=224,U1,Gs=5,nt=[8,16,32,32,32];function Vs(){let e=[],t=0;for(;tn.x)),y:D.tensor1d(e.map(n=>n.y))}}async function Y1(e){if(R.initial&&(_0=null),!_0&&e.body.detector&&e.body.detector.modelPath){_0=await O(e.body.detector.modelPath);let t=_0!=null&&_0.executor?Object.values(_0.modelSignature.inputs):void 0;t2=Array.isArray(t)?parseInt(t[0].tensorShape.dim[1].size):0}else e.debug&&_0&&u("cached model:",_0.modelUrl);return Vs(),_0}var q1=[5,5];function Zs(e,t){return D.tidy(()=>{let n=D.split(e,12,1),o=D.squeeze(n[0]),r=D.squeeze(n[1]),s=D.squeeze(n[2]),A=D.squeeze(n[3]);o=D.add(D.div(o,t2),t.x),r=D.add(D.div(r,t2),t.y),s=D.mul(D.div(s,t2),q1[0]),A=D.mul(D.div(A,t2),q1[1]);let a=D.sub(o,D.div(s,2)),l=D.sub(r,D.div(A,2)),c=D.add(a,s),x=D.add(l,A);return D.stack([a,l,c,x],1)})}async function Xs(e,t,n,o){var c,x;let r=[],s={};s.boxes=Zs(e,U1),s.scores=D.sigmoid(t),s.nms=await D.image.nonMaxSuppressionAsync(s.boxes,s.scores,1,((c=n.body.detector)==null?void 0:c.minConfidence)||.1,((x=n.body.detector)==null?void 0:x.iouThreshold)||.1);let A=await s.nms.data(),a=await s.scores.data(),l=await s.boxes.array();for(let i of Array.from(A)){let y=a[i],d=l[i],p=[Math.round(d[0]*o[0]),Math.round(d[1]*o[1]),Math.round(d[2]*o[0]),Math.round(d[3]*o[1])],f={score:y,boxRaw:d,box:p};r.push(f)}return Object.keys(s).forEach(i=>D.dispose(s[i])),r}async function K1(e,t,n){let o={};o.res=_0==null?void 0:_0.execute(e,["Identity"]),o.logitsRaw=D.slice(o.res,[0,0,0],[1,-1,1]),o.boxesRaw=D.slice(o.res,[0,0,1],[1,-1,-1]),o.logits=D.squeeze(o.logitsRaw),o.boxes=D.squeeze(o.boxesRaw);let r=await Xs(o.boxes,o.logits,t,n);return Object.keys(o).forEach(s=>D.dispose(o[s])),r}function ve(e,t=[1,1]){let n=[e.map(a=>a[0]),e.map(a=>a[1])],o=[Math.min(...n[0]),Math.min(...n[1])],r=[Math.max(...n[0]),Math.max(...n[1])],s=[o[0],o[1],r[0]-o[0],r[1]-o[1]],A=[s[0]/t[0],s[1]/t[1],s[2]/t[0],s[3]/t[1]];return{box:s,boxRaw:A}}function J1(e,t=[1,1]){let n=[e.map(c=>c[0]),e.map(c=>c[1])],o=[Math.min(...n[0]),Math.min(...n[1])],r=[Math.max(...n[0]),Math.max(...n[1])],s=[(o[0]+r[0])/2,(o[1]+r[1])/2],A=Math.max(s[0]-o[0],s[1]-o[1],-s[0]+r[0],-s[1]+r[1]),a=[Math.trunc(s[0]-A),Math.trunc(s[1]-A),Math.trunc(2*A),Math.trunc(2*A)],l=[a[0]/t[0],a[1]/t[1],a[2]/t[0],a[3]/t[1]];return{box:a,boxRaw:l}}function ot(e,t){let n=[e[2]*t,e[3]*t];return[e[0]-(n[0]-e[2])/2,e[1]-(n[1]-e[3])/2,n[0],n[1]]}var F0,l5=256,i5=Number.MAX_SAFE_INTEGER,qs={landmarks:["ld_3d","activation_segmentation","activation_heatmap","world_3d","output_poseflag"],detector:[]},st=[],Oe=[[0,0],[0,0],[0,0],[0,0]],Q1=0,_1=e=>1-1/(1+Math.exp(e)),e3=e=>Y1(e);async function t3(e){if(R.initial&&(F0=null),F0)e.debug&&u("cached model:",F0.modelUrl);else{F0=await O(e.body.modelPath);let t=F0!=null&&F0.executor?Object.values(F0.modelSignature.inputs):void 0;l5=Array.isArray(t)?parseInt(t[0].tensorShape.dim[1].size):0}return F0}function $1(e,t,n){var s,A;let o={};if(!((s=e==null?void 0:e.shape)!=null&&s[1])||!((A=e==null?void 0:e.shape)!=null&&A[2]))return e;let r;if(n&&(o.cropped=B0.image.cropAndResize(e,[n],[0],[e.shape[1],e.shape[2]])),e.shape[1]!==e.shape[2]){let a=[e.shape[2]>e.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0,e.shape[2]>e.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0],l=[e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0,e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0];Oe=[[0,0],a,l,[0,0]],o.pad=B0.pad(o.cropped||e,Oe),o.resize=B0.image.resizeBilinear(o.pad,[t,t]),r=B0.div(o.resize,C.tf255)}else e.shape[1]!==t?(o.resize=B0.image.resizeBilinear(o.cropped||e,[t,t]),r=B0.div(o.resize,C.tf255)):r=B0.div(o.cropped||e,C.tf255);return Object.keys(o).forEach(a=>B0.dispose(o[a])),r}function Us(e,t,n){for(let o of e)o.position=[Math.trunc(o.position[0]*(t[0]+Oe[2][0]+Oe[2][1])/t[0]-Oe[2][0]),Math.trunc(o.position[1]*(t[1]+Oe[1][0]+Oe[1][1])/t[1]-Oe[1][0]),o.position[2]],o.positionRaw=[o.position[0]/t[0],o.position[1]/t[1],2*o.position[2]/(t[0]+t[1])];if(n){let o=n[2]-n[0],r=n[3]-n[1];for(let s of e)s.positionRaw=[s.positionRaw[0]/r+n[1],s.positionRaw[1]/o+n[0],s.positionRaw[2]],s.position=[Math.trunc(s.positionRaw[0]*t[0]),Math.trunc(s.positionRaw[1]*t[1]),s.positionRaw[2]]}return e}function Ys(e){let t=e.find(a=>a.part==="leftPalm"),n=e.find(a=>a.part==="leftWrist"),o=e.find(a=>a.part==="leftIndex");t.position[2]=((n.position[2]||0)+(o.position[2]||0))/2;let r=e.find(a=>a.part==="rightPalm"),s=e.find(a=>a.part==="rightWrist"),A=e.find(a=>a.part==="rightIndex");r.position[2]=((s.position[2]||0)+(A.position[2]||0))/2}async function Ks(e,t,n){if(!(F0!=null&&F0.executor))return null;let o={};[o.ld,o.segmentation,o.heatmap,o.world,o.poseflag]=F0==null?void 0:F0.execute(e,qs.landmarks);let r=(await o.poseflag.data())[0],s=await o.ld.data(),A=await o.world.data();Object.keys(o).forEach(p=>B0.dispose(o[p]));let a=[],l=5;for(let p=0;pp.position),i=ve(x,[n[0],n[1]]),y={};for(let[p,f]of Object.entries(a5)){let b=[];for(let M=0;Mh.part===f[M]),m=c.find(h=>h.part===f[M+1]);T&&m&&b.push([T.position,m.position])}y[p]=b}return{id:0,score:Math.trunc(100*r)/100,box:i.box,boxRaw:i.boxRaw,keypoints:c,annotations:y}}async function c5(e,t){var s,A,a;let n=[e.shape[2]||0,e.shape[1]||0],o=(t.body.skipTime||0)>g()-Q1,r=i5<(t.body.skipFrames||0);if(t.skipAllowed&&o&&r&&st!==null)i5++;else{let l=[];if((A=(s=t.body)==null?void 0:s.detector)!=null&&A.enabled){let c=$1(e,224);l=await K1(c,t,n),B0.dispose(c)}else l=[{box:[0,0,0,0],boxRaw:[0,0,1,1],score:0}];for(let c=0;cL0.dispose(o[c])),r}async function y5(e,t){if(!(H0!=null&&H0.executor))return[];let n=(t.object.skipTime||0)>g()-o3,o=x5<(t.object.skipFrames||0);return t.skipAllowed&&n&&o&&d5.length>0?(x5++,d5):(x5=0,new Promise(async r=>{let s=[e.shape[2]||0,e.shape[1]||0],A=L0.image.resizeBilinear(e,[n2,n2]),a=t.object.enabled?H0==null?void 0:H0.execute(A,["tower_0/detections"]):null;o3=g(),L0.dispose(A);let l=await Js(a,s,t);d5=l,r(l)}))}var J=Z(H());var At={};ze(At,{connected:()=>m5,kpt:()=>f5});var f5=["head","neck","rightShoulder","rightElbow","rightWrist","chest","leftShoulder","leftElbow","leftWrist","bodyCenter","rightHip","rightKnee","rightAnkle","leftHip","leftKnee","leftAnkle"],m5={leftLeg:["leftHip","leftKnee","leftAnkle"],rightLeg:["rightHip","rightKnee","rightAnkle"],torso:["leftShoulder","rightShoulder","rightHip","leftHip","leftShoulder"],leftArm:["leftShoulder","leftElbow","leftWrist"],rightArm:["rightShoulder","rightElbow","rightWrist"],head:[]};var i0,A3=0,C0={id:0,keypoints:[],box:[0,0,0,0],boxRaw:[0,0,0,0],score:0,annotations:{}},p5=Number.MAX_SAFE_INTEGER;async function a3(e){return R.initial&&(i0=null),i0?e.debug&&u("cached model:",i0.modelUrl):i0=await O(e.body.modelPath),i0}async function Qs(e,t){let[n,o]=e.shape,r=J.reshape(e,[o*n]),s=J.max(r,0),A=(await s.data())[0];if(A>t){let a=J.argMax(r,0),l=J.mod(a,n),c=(await l.data())[0],x=J.div(a,n),i=(await x.data())[0];return J.dispose([r,s,a,l,x]),[c,i,A]}return J.dispose([r,s]),[0,0,A]}async function u5(e,t){if(!(i0!=null&&i0.executor)||!(i0!=null&&i0.inputs[0].shape))return[];let n=(t.body.skipTime||0)>g()-A3,o=p5<(t.body.skipFrames||0);return t.skipAllowed&&n&&o&&Object.keys(C0.keypoints).length>0?(p5++,[C0]):(p5=0,new Promise(async r=>{let s=J.tidy(()=>{var p,f;let i=J.image.resizeBilinear(e,[((p=i0==null?void 0:i0.inputs[0].shape)==null?void 0:p[2])||0,((f=i0==null?void 0:i0.inputs[0].shape)==null?void 0:f[1])||0],!1),y=J.mul(i,C.tf2);return J.sub(y,C.tf1)}),A;if(t.body.enabled&&(A=i0==null?void 0:i0.execute(s)),A3=g(),J.dispose(s),A){C0.keypoints.length=0;let i=J.squeeze(A);J.dispose(A);let y=J.unstack(i,2);J.dispose(i);for(let d=0;d(t.body.minConfidence||0)&&C0.keypoints.push({score:Math.round(100*b)/100,part:f5[d],positionRaw:[p/i0.inputs[0].shape[2],f/i0.inputs[0].shape[1]],position:[Math.round(e.shape[2]*p/i0.inputs[0].shape[2]),Math.round(e.shape[1]*f/i0.inputs[0].shape[1])]})}y.forEach(d=>J.dispose(d))}C0.score=C0.keypoints.reduce((i,y)=>y.score>i?y.score:i,0);let a=C0.keypoints.map(i=>i.position[0]),l=C0.keypoints.map(i=>i.position[1]);C0.box=[Math.min(...a),Math.min(...l),Math.max(...a)-Math.min(...a),Math.max(...l)-Math.min(...l)];let c=C0.keypoints.map(i=>i.positionRaw[0]),x=C0.keypoints.map(i=>i.positionRaw[1]);C0.boxRaw=[Math.min(...c),Math.min(...x),Math.max(...c)-Math.min(...c),Math.max(...x)-Math.min(...x)];for(let[i,y]of Object.entries(m5)){let d=[];for(let p=0;pM.part===y[p]),b=C0.keypoints.find(M=>M.part===y[p+1]);f&&b&&f.score>(t.body.minConfidence||0)&&b.score>(t.body.minConfidence||0)&&d.push([f.position,b.position])}C0.annotations[i]=d}r([C0])}))}var l0=Z(H());var We=Z(H());var L=Z(H());var Re=Z(H());var y2=e=>[Math.abs(e.endPoint[0]-e.startPoint[0]),Math.abs(e.endPoint[1]-e.startPoint[1])],at=e=>[e.startPoint[0]+(e.endPoint[0]-e.startPoint[0])/2,e.startPoint[1]+(e.endPoint[1]-e.startPoint[1])/2,1],it=(e,t)=>e?[Math.trunc(Math.max(0,e.startPoint[0])),Math.trunc(Math.max(0,e.startPoint[1])),Math.trunc(Math.min(t.shape[2]||0,e.endPoint[0])-Math.max(0,e.startPoint[0])),Math.trunc(Math.min(t.shape[1]||0,e.endPoint[1])-Math.max(0,e.startPoint[1]))]:[0,0,0,0],lt=(e,t)=>e?[e.startPoint[0]/(t.shape[2]||0),e.startPoint[1]/(t.shape[1]||0),(e.endPoint[0]-e.startPoint[0])/(t.shape[2]||0),(e.endPoint[1]-e.startPoint[1])/(t.shape[1]||0)]:[0,0,0,0],d3=(e,t)=>{let n=[e.startPoint[0]*t[0],e.startPoint[1]*t[1]],o=[e.endPoint[0]*t[0],e.endPoint[1]*t[1]];return{startPoint:n,endPoint:o,landmarks:e.landmarks,confidence:e.confidence}},h5=(e,t,n)=>{let o=t.shape[1],r=t.shape[2],s=[e.startPoint[1]/o,e.startPoint[0]/r,e.endPoint[1]/o,e.endPoint[0]/r],A=Re.image.cropAndResize(t,[s],[0],n),a=Re.div(A,C.tf255);return Re.dispose(A),a},ct=(e,t)=>{let n=at(e),o=y2(e),r=[t*o[0]/2,t*o[1]/2];return{startPoint:[n[0]-r[0],n[1]-r[1]],endPoint:[n[0]+r[0],n[1]+r[1]],landmarks:e.landmarks,confidence:e.confidence}},dt=e=>{let t=at(e),n=y2(e),o=Math.max(...n)/2;return{startPoint:[Math.round(t[0]-o),Math.round(t[1]-o)],endPoint:[Math.round(t[0]+o),Math.round(t[1]+o)],landmarks:e.landmarks,confidence:e.confidence}},x3=e=>{let t=e.map(o=>o[0]),n=e.map(o=>o[1]);return{startPoint:[Math.min(...t),Math.min(...n)],endPoint:[Math.max(...t),Math.max(...n)],landmarks:e}},b5=[[1,0,0],[0,1,0],[0,0,1]],_s=e=>e-2*Math.PI*Math.floor((e+Math.PI)/(2*Math.PI)),$s=(e,t)=>_s(Math.PI/2-Math.atan2(-(t[1]-e[1]),t[0]-e[0]));var l3=(e,t)=>[[1,0,e],[0,1,t],[0,0,1]],o2=(e,t)=>{let n=0;for(let o=0;o{let n=[];for(let o=0;o{let n=[],o=e.length;for(let r=0;r{let n=Math.cos(e),o=Math.sin(e),r=[[n,-o,0],[o,n,0],[0,0,1]],s=l3(t[0],t[1]),A=c3(s,r),a=l3(-t[0],-t[1]);return c3(A,a)},tA=e=>{let t=[[e[0][0],e[1][0]],[e[0][1],e[1][1]]],n=[e[0][2],e[1][2]],o=[-o2(t[0],n),-o2(t[1],n)];return[t[0].concat(o[0]),t[1].concat(o[1]),[0,0,1]]},nA=(e,t)=>[o2(e,t[0]),o2(e,t[1])];function f3(e){let t=e===192?{strides:[4],anchors:[1]}:{strides:[e/16,e/8],anchors:[2,6]},n=[];for(let o=0;o[s[0]/r*(d[0]-r/2),s[1]/r*(d[1]-r/2),d[2]||0]),a=n&&n!==0&&Math.abs(n)>.2,l=a?y3(n,[0,0]):b5,c=a?A.map(d=>[...nA(d,l),d[2]]):A,x=a?tA(o):b5,i=at(t),y=[o2(i,x[0]),o2(i,x[1])];return c.map(d=>[Math.trunc(d[0]+y[0]),Math.trunc(d[1]+y[1]),Math.trunc(d[2]||0)])}function p3(e,t,n,o){let r=t.landmarks.length>=t5.count?t5.symmetryLine:Qe.symmetryLine,s=0,A=b5,a;if(e&&R.kernels.includes("rotatewithoffset"))if(s=$s(t.landmarks[r[0]],t.landmarks[r[1]]),s&&s!==0&&Math.abs(s)>.2){let c=at(t),x=[c[0]/n.shape[2],c[1]/n.shape[1]],i=Re.image.rotateWithOffset(n,s,0,[x[0],x[1]]);A=y3(-s,c),a=h5(t,i,[o,o]),Re.dispose(i)}else a=h5(t,n,[o,o]);else a=h5(t,n,[o,o]);return[s,A,a]}var oA=e=>{let t=e.map(o=>o[0]),n=e.map(o=>o[1]);return[Math.min(...t)+(Math.max(...t)-Math.min(...t))/2,Math.min(...n)+(Math.max(...n)-Math.min(...n))/2]},u3=(e,t)=>{let n=oA(e),o=y2(t);return{startPoint:[n[0]-o[0]/2,n[1]-o[1]/2],endPoint:[n[0]+o[0]/2,n[1]+o[1]/2]}};var h3=6,rA=1.4,ie,T5=null,Le=0,f2=null,m2=()=>Le;async function b3(e){var t;return R.initial&&(ie=null),ie?e.debug&&u("cached model:",ie.modelUrl):ie=await O((t=e.face.detector)==null?void 0:t.modelPath),Le=ie.executor&&ie.inputs[0].shape?ie.inputs[0].shape[2]:256,f2=L.scalar(Le,"int32"),T5=L.tensor2d(f3(Le)),ie}function sA(e){if(!T5||!f2)return L.zeros([0,0]);let t={};t.boxStarts=L.slice(e,[0,1],[-1,2]),t.centers=L.add(t.boxStarts,T5),t.boxSizes=L.slice(e,[0,3],[-1,2]),t.boxSizesNormalized=L.div(t.boxSizes,f2),t.centersNormalized=L.div(t.centers,f2),t.halfBoxSize=L.div(t.boxSizesNormalized,C.tf2),t.starts=L.sub(t.centersNormalized,t.halfBoxSize),t.ends=L.add(t.centersNormalized,t.halfBoxSize),t.startNormalized=L.mul(t.starts,f2),t.endNormalized=L.mul(t.ends,f2);let n=L.concat2d([t.startNormalized,t.endNormalized],1);return Object.keys(t).forEach(o=>L.dispose(t[o])),n}async function g3(e,t){var a,l,c,x;if(!e||e.isDisposedInternal||e.shape.length!==4||e.shape[1]<1||e.shape[2]<1)return[];let n={};n.resized=L.image.resizeBilinear(e,[Le,Le]),n.div=L.div(n.resized,C.tf127),n.normalized=L.sub(n.div,C.tf05);let o=ie==null?void 0:ie.execute(n.normalized);if(Array.isArray(o)&&o.length>2){let i=o.sort((y,d)=>y.size-d.size);n.concat384=L.concat([i[0],i[2]],2),n.concat512=L.concat([i[1],i[3]],2),n.concat=L.concat([n.concat512,n.concat384],1),n.batch=L.squeeze(n.concat,[0])}else Array.isArray(o)?n.batch=L.squeeze(o[0]):n.batch=L.squeeze(o);L.dispose(o),n.boxes=sA(n.batch),n.logits=L.slice(n.batch,[0,0],[-1,1]),n.sigmoid=L.sigmoid(n.logits),n.scores=L.squeeze(n.sigmoid),n.nms=await L.image.nonMaxSuppressionAsync(n.boxes,n.scores,((a=t.face.detector)==null?void 0:a.maxDetected)||0,((l=t.face.detector)==null?void 0:l.iouThreshold)||0,((c=t.face.detector)==null?void 0:c.minConfidence)||0);let r=await n.nms.array(),s=[],A=await n.scores.data();for(let i=0;i(((x=t.face.detector)==null?void 0:x.minConfidence)||0)){let d={};d.bbox=L.slice(n.boxes,[r[i],0],[1,-1]),d.slice=L.slice(n.batch,[r[i],h3-1],[1,-1]),d.squeeze=L.squeeze(d.slice),d.landmarks=L.reshape(d.squeeze,[h3,-1]);let p=await d.bbox.data(),f={startPoint:[p[0],p[1]],endPoint:[p[2],p[3]],landmarks:await d.landmarks.array(),confidence:y},b=d3(f,[(e.shape[2]||0)/Le,(e.shape[1]||0)/Le]),M=ct(b,t.face.scale||rA),T=dt(M);s.push(T),Object.keys(d).forEach(m=>L.dispose(d[m]))}}return Object.keys(n).forEach(i=>L.dispose(n[i])),s}var le=Z(H());var V0,Ce=0,AA=2.3,v5=oe.leftEyeLower0,R5=oe.rightEyeLower0,p2={leftBounds:[v5[0],v5[v5.length-1]],rightBounds:[R5[0],R5[R5.length-1]]},u2={upperCenter:3,lowerCenter:4,index:71,numCoordinates:76};async function P3(e){var t,n;return R.initial&&(V0=null),V0?e.debug&&u("cached model:",V0.modelUrl):V0=await O((t=e.face.iris)==null?void 0:t.modelPath),Ce=(V0==null?void 0:V0.executor)&&((n=V0.inputs)==null?void 0:n[0].shape)?V0.inputs[0].shape[2]:0,Ce===-1&&(Ce=64),V0}function xt(e,t,n,o){for(let r=0;r{let t=e[p2.leftBounds[0]][2],n=e[p2.rightBounds[0]][2];return t-n},v3=(e,t,n,o,r,s=!1)=>{let A=dt(ct(x3([e[n],e[o]]),AA)),a=y2(A),l=le.image.cropAndResize(t,[[A.startPoint[1]/r,A.startPoint[0]/r,A.endPoint[1]/r,A.endPoint[0]/r]],[0],[Ce,Ce]);if(s&&R.kernels.includes("flipleftright")){let c=le.image.flipLeftRight(l);le.dispose(l),l=c}return{box:A,boxSize:a,crop:l}},R3=(e,t,n,o=!1)=>{let r=[];for(let s=0;s{let o=e[oe[`${n}EyeUpper0`][u2.upperCenter]][2],r=e[oe[`${n}EyeLower0`][u2.lowerCenter]][2],s=(o+r)/2;return t.map((A,a)=>{let l=s;return a===2?l=o:a===4&&(l=r),[A[0],A[1],l]})};async function k3(e,t,n){if(!(V0!=null&&V0.executor))return e;let{box:o,boxSize:r,crop:s}=v3(e,t,p2.leftBounds[0],p2.leftBounds[1],n,!0),{box:A,boxSize:a,crop:l}=v3(e,t,p2.rightBounds[0],p2.rightBounds[1],n,!0),c=le.concat([s,l]);le.dispose(s),le.dispose(l);let x=V0.execute(c);le.dispose(c);let i=await x.data();le.dispose(x);let y=i.slice(0,u2.numCoordinates*3),{rawCoords:d,iris:p}=R3(y,o,r,!0),f=i.slice(u2.numCoordinates*3),{rawCoords:b,iris:M}=R3(f,A,a,!1),T=aA(e);Math.abs(T)<30?(xt(e,d,"left",null),xt(e,b,"right",null)):T<1?xt(e,d,"left",["EyeUpper0","EyeLower0"]):xt(e,b,"right",["EyeUpper0","EyeLower0"]);let m=M3(e,p,"left"),h=M3(e,M,"right");return e.concat(m).concat(h)}async function E3(e,t){var s,A,a,l,c,x,i,y,d,p;let n={lips:await((A=(s=t.filter(f=>f.size===160))==null?void 0:s[0])==null?void 0:A.data()),irisL:await((l=(a=t.filter(f=>f.size===10))==null?void 0:a[0])==null?void 0:l.data()),eyeL:await((x=(c=t.filter(f=>f.size===142))==null?void 0:c[0])==null?void 0:x.data()),irisR:await((y=(i=t.filter(f=>f.size===10))==null?void 0:i[1])==null?void 0:y.data()),eyeR:await((p=(d=t.filter(f=>f.size===142))==null?void 0:d[1])==null?void 0:p.data())};for(let f of Object.values(n))if(!f)return e;let o=$e.reduce((f,b)=>f+=e[b][2],0)/$e.length;for(let f=0;ff+=e[b][2],0)/e2.length;for(let f=0;fg()-ue.timestamp,o=ue.skipped<(((c=t.face.detector)==null?void 0:c.skipFrames)||0);!t.skipAllowed||!n||!o||ue.boxes.length===0?(ue.boxes=await g3(e,t),ue.timestamp=g(),ue.skipped=0):ue.skipped++;let r=[],s=[],A=0,a=O2;for(let T=0;TG.shape[G.shape.length-1]===1).data();if(P.faceScore=Math.round(100*t0[0])/100,P.faceScore<(((p=t.face.detector)==null?void 0:p.minConfidence)||1)){if(m.confidence=P.faceScore,t.face.mesh.keepInvalid){P.box=it(m,e),P.boxRaw=lt(m,e),P.score=P.boxScore,P.mesh=m.landmarks.map(G=>[(m.startPoint[0]+m.endPoint[0])/2+(m.endPoint[0]+m.startPoint[0])*G[0]/m2(),(m.startPoint[1]+m.endPoint[1])/2+(m.endPoint[1]+m.startPoint[1])*G[1]/m2()]),P.meshRaw=P.mesh.map(G=>[G[0]/(e.shape[2]||1),G[1]/(e.shape[1]||1),(G[2]||0)/a]);for(let G of Object.keys(Qe))P.annotations[G]=[P.mesh[Qe[G]]]}}else{let G=I.find(V=>V.shape[V.shape.length-1]===1404),$=We.reshape(G,[-1,3]),A0=await $.array();We.dispose($),(f=t.face.attention)!=null&&f.enabled?A0=await E3(A0,I):(b=t.face.iris)!=null&&b.enabled&&(A0=await k3(A0,P.tensor,O2)),P.mesh=m3(A0,m,h,S,O2),P.meshRaw=P.mesh.map(V=>[V[0]/(e.shape[2]||0),V[1]/(e.shape[1]||0),(V[2]||0)/a]);for(let V of Object.keys(oe))P.annotations[V]=oe[V].map(n0=>P.mesh[n0]);P.score=P.faceScore;let v={...u3(P.mesh,m),confidence:m.confidence,landmarks:m.landmarks};P.box=it(v,e),P.boxRaw=lt(v,e),s.push(v)}We.dispose(I)}else{P.box=it(m,e),P.boxRaw=lt(m,e),P.score=P.boxScore,P.mesh=m.landmarks.map(I=>[(m.startPoint[0]+m.endPoint[0])/2+(m.endPoint[0]+m.startPoint[0])*I[0]/m2(),(m.startPoint[1]+m.endPoint[1])/2+(m.endPoint[1]+m.startPoint[1])*I[1]/m2()]),P.meshRaw=P.mesh.map(I=>[I[0]/(e.shape[2]||0),I[1]/(e.shape[1]||0),(I[2]||0)/a]);for(let I of Object.keys(Qe))P.annotations[I]=[P.mesh[Qe[I]]]}P.score>(((M=t.face.detector)==null?void 0:M.minConfidence)||1)?r.push(P):We.dispose(P.tensor)}return ue.boxes=s,r}async function S3(e){var t,n,o,r,s,A;return R.initial&&(r0=null),((t=e.face.attention)==null?void 0:t.enabled)&&(r0==null?void 0:r0.signature)&&Object.keys(((n=r0==null?void 0:r0.signature)==null?void 0:n.outputs)||{}).length<6&&(r0=null),r0?e.debug&&u("cached model:",r0.modelUrl):(o=e.face.attention)!=null&&o.enabled?r0=await O(e.face.attention.modelPath):r0=await O((r=e.face.mesh)==null?void 0:r.modelPath),O2=r0.executor&&((s=r0==null?void 0:r0.inputs)==null?void 0:s[0].shape)?(A=r0==null?void 0:r0.inputs)==null?void 0:A[0].shape[2]:256,r0}var j3=_e,N3=N2;var ce=Z(H());var lA=["angry","disgust","fear","happy","sad","surprise","neutral"],$0,yt=[],I3=0,O3=0,P5=Number.MAX_SAFE_INTEGER;async function L3(e){var t;return R.initial&&($0=null),$0?e.debug&&u("cached model:",$0.modelUrl):$0=await O((t=e.face.emotion)==null?void 0:t.modelPath),$0}async function k5(e,t,n,o){var A,a;if(!$0)return[];let r=P5<(((A=t.face.emotion)==null?void 0:A.skipFrames)||0),s=(((a=t.face.emotion)==null?void 0:a.skipTime)||0)>g()-O3;return t.skipAllowed&&s&&r&&I3===o&&yt[n]&&yt[n].length>0?(P5++,yt[n]):(P5=0,new Promise(async l=>{var x;let c=[];if((x=t.face.emotion)!=null&&x.enabled){let i={},y=$0!=null&&$0.inputs[0].shape?$0.inputs[0].shape[2]:0;i.resize=ce.image.resizeBilinear(e,[y,y],!1),i.channels=ce.mul(i.resize,C.rgb),i.grayscale=ce.sum(i.channels,3,!0),i.grayscaleSub=ce.sub(i.grayscale,C.tf05),i.grayscaleMul=ce.mul(i.grayscaleSub,C.tf2),i.emotion=$0==null?void 0:$0.execute(i.grayscaleMul),O3=g();let d=await i.emotion.data();for(let p=0;p(t.face.emotion.minConfidence||0)&&c.push({score:Math.min(.99,Math.trunc(100*d[p])/100),emotion:lA[p]});c.sort((p,f)=>f.score-p.score),Object.keys(i).forEach(p=>ce.dispose(i[p]))}yt[n]=c,I3=o,l(c)}))}var de=Z(H());var z0,De=[],W3=0,D3=0,w5=Number.MAX_SAFE_INTEGER;async function F3(e){var t;return R.initial&&(z0=null),z0?e.debug&&u("cached model:",z0.modelUrl):z0=await O((t=e.face.description)==null?void 0:t.modelPath),z0}function cA(e){let t=e.image||e.tensor||e;if(!(z0!=null&&z0.inputs[0].shape))return t;let n=de.image.resizeBilinear(t,[z0.inputs[0].shape[2],z0.inputs[0].shape[1]],!1),o=de.mul(n,C.tf255);return de.dispose(n),o}async function E5(e,t,n,o){var a,l,c,x;let r={age:0,gender:"unknown",genderScore:0,descriptor:[]};if(!(z0!=null&&z0.executor))return r;let s=w5<(((a=t.face.description)==null?void 0:a.skipFrames)||0),A=(((l=t.face.description)==null?void 0:l.skipTime)||0)>g()-W3;return t.skipAllowed&&s&&A&&D3===o&&((c=De==null?void 0:De[n])==null?void 0:c.age)>0&&((x=De==null?void 0:De[n])==null?void 0:x.genderScore)>0?(w5++,De[n]):(w5=0,new Promise(async i=>{var y;if((y=t.face.description)!=null&&y.enabled){let d=cA(e),p=z0==null?void 0:z0.execute(d);W3=g(),de.dispose(d);let b=await p.find(q=>q.shape[1]===1).data(),M=Math.trunc(200*Math.abs(b[0]-.5))/100;M>(t.face.description.minConfidence||0)&&(r.gender=b[0]<=.5?"female":"male",r.genderScore=Math.min(.99,M));let T=de.argMax(p.find(q=>q.shape[1]===100),1),m=(await T.data())[0];de.dispose(T);let S=await p.find(q=>q.shape[1]===100).data();r.age=Math.round(S[m-1]>S[m+1]?10*m-100*S[m-1]:10*m+100*S[m+1])/10,(Number.isNaN(b[0])||Number.isNaN(S[0]))&&u("faceres error:",{model:z0,result:p});let P=p.find(q=>q.shape[1]===1024),I=P?await P.data():[];r.descriptor=Array.from(I),p.forEach(q=>de.dispose(q))}De[n]=r,D3=o,i(r)}))}var h2=.1,z5=.5;function dA(e,t,n){let o=!1,r=n.length-1;for(let s=0;st!=n[r].y>t&&e<(n[r].x-n[s].x)*(t-n[s].y)/(n[r].y-n[s].y)+n[s].x&&(o=!o);return o}async function H3(e){if(!e.tensor||!e.mesh||e.mesh.length<100)return e.tensor;let t=e.tensor.shape[2]||0,n=e.tensor.shape[1]||0,o=await e.tensor.buffer(),r=[];for(let A of oe.silhouette)r.push({x:(e.mesh[A][0]-e.box[0])/e.box[2],y:(e.mesh[A][1]-e.box[1])/e.box[3]});h2&&h2>0&&(r=r.map(A=>({x:A.x>.5?A.x+h2:A.x-h2,y:A.y>.5?A.y+h2:A.y-h2})));for(let A=0;Ag()-V3,s=S5<(((a=t.face.antispoof)==null?void 0:a.skipFrames)||0);return t.skipAllowed&&r&&s&&G3===o&&ft[n]?(S5++,ft[n]):(S5=0,new Promise(async l=>{let c=mt.image.resizeBilinear(e,[M0!=null&&M0.inputs[0].shape?M0.inputs[0].shape[2]:0,M0!=null&&M0.inputs[0].shape?M0.inputs[0].shape[1]:0],!1),x=M0==null?void 0:M0.execute(c),i=(await x.data())[0];ft[n]=Math.round(100*i)/100,G3=o,V3=g(),mt.dispose([c,x]),l(ft[n])}))}var ut=Z(H());var P0,pt=[],N5=Number.MAX_SAFE_INTEGER,q3=0,U3=0;async function Y3(e){var t;return R.initial&&(P0=null),P0?e.debug&&u("cached model:",P0.modelUrl):P0=await O((t=e.face.liveness)==null?void 0:t.modelPath),P0}async function I5(e,t,n,o){var A,a;if(!(P0!=null&&P0.executor))return 0;let r=(((A=t.face.liveness)==null?void 0:A.skipTime)||0)>g()-U3,s=N5<(((a=t.face.liveness)==null?void 0:a.skipFrames)||0);return t.skipAllowed&&r&&s&&q3===o&&pt[n]?(N5++,pt[n]):(N5=0,new Promise(async l=>{let c=ut.image.resizeBilinear(e,[P0!=null&&P0.inputs[0].shape?P0.inputs[0].shape[2]:0,P0!=null&&P0.inputs[0].shape?P0.inputs[0].shape[1]:0],!1),x=P0==null?void 0:P0.execute(c),i=(await x.data())[0];pt[n]=Math.round(100*i)/100,q3=o,U3=g(),ut.dispose([c,x]),l(pt[n])}))}var ht=Z(H());var re,O5=[],yA=["white","black","asian","indian","other"],fA=[15,23,28,35.5,45.5,55.5,65],J3=0,Q3=0,L5=Number.MAX_SAFE_INTEGER;async function _3(e){var t;return R.initial&&(re=null),re?e.debug&&u("cached model:",re.modelUrl):re=await O((t=e.face.gear)==null?void 0:t.modelPath),re}async function C5(e,t,n,o){var A,a;if(!re)return{age:0,gender:"unknown",genderScore:0,race:[]};let r=L5<(((A=t.face.gear)==null?void 0:A.skipFrames)||0),s=(((a=t.face.gear)==null?void 0:a.skipTime)||0)>g()-Q3;return t.skipAllowed&&s&&r&&J3===o&&O5[n]?(L5++,O5[n]):(L5=0,new Promise(async l=>{var M,T;if(!(re!=null&&re.inputs[0].shape))return;let c={},x=[[0,.1,.9,.9]];c.resize=ht.image.cropAndResize(e,x,[0],[re.inputs[0].shape[2],re.inputs[0].shape[1]]);let i={age:0,gender:"unknown",genderScore:0,race:[]};(M=t.face.gear)!=null&&M.enabled&&([c.age,c.gender,c.race]=re.execute(c.resize,["age_output","gender_output","race_output"]));let y=await c.gender.data();i.gender=y[0]>y[1]?"male":"female",i.genderScore=Math.round(100*(y[0]>y[1]?y[0]:y[1]))/100;let d=await c.race.data();for(let m=0;m(((T=t.face.gear)==null?void 0:T.minConfidence)||.2)&&i.race.push({score:Math.round(100*d[m])/100,race:yA[m]});i.race.sort((m,h)=>h.score-m.score);let f=Array.from(await c.age.data()).map((m,h)=>[fA[h],m]).sort((m,h)=>h[1]-m[1]),b=f[0][0];for(let m=1;mht.dispose(c[m])),O5[n]=i,J3=o,Q3=g(),l(i)}))}var b2=Z(H());var Z0,bt=[],en=0,tn=0,W5=Number.MAX_SAFE_INTEGER;async function nn(e){return R.initial&&(Z0=null),Z0?e.debug&&u("cached model:",Z0.modelUrl):Z0=await O(e.face.ssrnet.modelPathAge),Z0}async function D5(e,t,n,o){var A,a,l,c;if(!Z0)return{age:0};let r=W5<(((A=t.face.ssrnet)==null?void 0:A.skipFrames)||0),s=(((a=t.face.ssrnet)==null?void 0:a.skipTime)||0)>g()-tn;return t.skipAllowed&&r&&s&&en===o&&((l=bt[n])==null?void 0:l.age)&&((c=bt[n])==null?void 0:c.age)>0?(W5++,bt[n]):(W5=0,new Promise(async x=>{var d;if(!(Z0!=null&&Z0.inputs)||!Z0.inputs[0]||!Z0.inputs[0].shape)return;let i={};i.resize=b2.image.resizeBilinear(e,[Z0.inputs[0].shape[2],Z0.inputs[0].shape[1]],!1),i.enhance=b2.mul(i.resize,C.tf255);let y={age:0};if((d=t.face.ssrnet)!=null&&d.enabled&&(i.age=Z0.execute(i.enhance)),i.age){let p=await i.age.data();y.age=Math.trunc(10*p[0])/10}Object.keys(i).forEach(p=>b2.dispose(i[p])),bt[n]=y,en=o,tn=g(),x(y)}))}var S0=Z(H());var se,gt=[],rn=0,sn=0,F5=Number.MAX_SAFE_INTEGER,B5=[.2989,.587,.114];async function An(e){var t;return R.initial&&(se=null),se?e.debug&&u("cached model:",se.modelUrl):se=await O((t=e.face.ssrnet)==null?void 0:t.modelPathGender),se}async function H5(e,t,n,o){var A,a,l,c;if(!se)return{gender:"unknown",genderScore:0};let r=F5<(((A=t.face.ssrnet)==null?void 0:A.skipFrames)||0),s=(((a=t.face.ssrnet)==null?void 0:a.skipTime)||0)>g()-sn;return t.skipAllowed&&r&&s&&rn===o&&((l=gt[n])==null?void 0:l.gender)&&((c=gt[n])==null?void 0:c.genderScore)>0?(F5++,gt[n]):(F5=0,new Promise(async x=>{var p;if(!(se!=null&&se.inputs[0].shape))return;let i={};i.resize=S0.image.resizeBilinear(e,[se.inputs[0].shape[2],se.inputs[0].shape[1]],!1),i.enhance=S0.tidy(()=>{let[f,b,M]=S0.split(i.resize,3,3),T=S0.mul(f,B5[0]),m=S0.mul(b,B5[1]),h=S0.mul(M,B5[2]),S=S0.addN([T,m,h]);return S0.mul(S0.sub(S,C.tf05),2)});let y={gender:"unknown",genderScore:0};(p=t.face.ssrnet)!=null&&p.enabled&&(i.gender=se.execute(i.enhance));let d=await i.gender.data();y.gender=d[0]>d[1]?"female":"male",y.genderScore=d[0]>d[1]?Math.trunc(100*d[0])/100:Math.trunc(100*d[1])/100,Object.keys(i).forEach(f=>S0.dispose(i[f])),gt[n]=y,rn=o,sn=g(),x(y)}))}var Tt=Z(H());var X0,G5=[],ln=0,cn=0,dn=Number.MAX_SAFE_INTEGER;async function xn(e){var t;return R.initial&&(X0=null),X0?e.debug&&u("cached model:",X0.modelUrl):X0=await O((t=e.face.mobilefacenet)==null?void 0:t.modelPath),X0}async function V5(e,t,n,o){var A,a;if(!(X0!=null&&X0.executor))return[];let r=dn<(((A=t.face.mobilefacenet)==null?void 0:A.skipFrames)||0),s=(((a=t.face.mobilefacenet)==null?void 0:a.skipTime)||0)>g()-cn;return t.skipAllowed&&s&&r&&ln===o&&G5[n]?(dn++,G5[n]):new Promise(async l=>{var x;let c=[];if(((x=t.face.mobilefacenet)==null?void 0:x.enabled)&&(X0==null?void 0:X0.inputs[0].shape)){let i={};i.crop=Tt.image.resizeBilinear(e,[X0.inputs[0].shape[2],X0.inputs[0].shape[1]],!1),i.data=X0.execute(i.crop);let y=await i.data.data();c=Array.from(y),Object.keys(i).forEach(d=>Tt.dispose(i[d]))}G5[n]=c,ln=o,cn=g(),l(c)})}var vt=Z(H());var q0,Z5=[],fn=0,mn=0,pn=Number.MAX_SAFE_INTEGER;async function un(e){return R.initial&&(q0=null),q0?e.debug&&u("cached model:",q0.modelUrl):q0=await O(e.face.insightface.modelPath),q0}async function X5(e,t,n,o){var A,a;if(!(q0!=null&&q0.executor))return[];let r=pn<(((A=t.face.insightface)==null?void 0:A.skipFrames)||0),s=(((a=t.face.insightface)==null?void 0:a.skipTime)||0)>g()-mn;return t.skipAllowed&&s&&r&&fn===o&&Z5[n]?(pn++,Z5[n]):new Promise(async l=>{var x;let c=[];if(((x=t.face.insightface)==null?void 0:x.enabled)&&(q0==null?void 0:q0.inputs[0].shape)){let i={};i.crop=vt.image.resizeBilinear(e,[q0.inputs[0].shape[2],q0.inputs[0].shape[1]],!1),i.data=q0.execute(i.crop);let y=await i.data.data();c=Array.from(y),Object.keys(i).forEach(d=>vt.dispose(i[d]))}Z5[n]=c,fn=o,mn=g(),l(c)})}var mA=e=>{let t=(i,y)=>Math.atan2(i[1]-y[1],i[0]-y[0]);if(!e.annotations.rightEyeIris||!e.annotations.leftEyeIris)return{bearing:0,strength:0};let n=[0,-.1],o=1,r=(e.mesh[33][2]||0)>(e.mesh[263][2]||0),s=r?e.mesh[473]:e.mesh[468],A=r?[(e.mesh[133][0]+e.mesh[33][0])/2,(e.mesh[133][1]+e.mesh[33][1])/2]:[(e.mesh[263][0]+e.mesh[362][0])/2,(e.mesh[263][1]+e.mesh[362][1])/2],a=r?[e.mesh[133][0]-e.mesh[33][0],e.mesh[23][1]-e.mesh[27][1]]:[e.mesh[263][0]-e.mesh[362][0],e.mesh[253][1]-e.mesh[257][1]],l=[(A[0]-s[0])/a[0]-n[0],o*(s[1]-A[1])/a[1]-n[1]],c=Math.sqrt(l[0]*l[0]+l[1]*l[1]);return c=Math.min(c,e.boxRaw[2]/2,e.boxRaw[3]/2),{bearing:(t([0,0],l)+Math.PI/2)%Math.PI,strength:c}},bn=(e,t)=>{let n=f=>{let b=Math.sqrt(f[0]*f[0]+f[1]*f[1]+f[2]*f[2]);return f[0]/=b,f[1]/=b,f[2]/=b,f},o=(f,b)=>{let M=f[0]-b[0],T=f[1]-b[1],m=f[2]-b[2];return[M,T,m]},r=(f,b)=>{let M=f[1]*b[2]-f[2]*b[1],T=f[2]*b[0]-f[0]*b[2],m=f[0]*b[1]-f[1]*b[0];return[M,T,m]},s=f=>{let[b,M,T,m,h,S,P,I,q]=f,t0,G,$;return m<1?m>-1?($=Math.asin(m),G=Math.atan2(-P,b),t0=Math.atan2(-S,h)):($=-Math.PI/2,G=-Math.atan2(I,q),t0=0):($=Math.PI/2,G=Math.atan2(I,q),t0=0),Number.isNaN(t0)&&(t0=0),Number.isNaN(G)&&(G=0),Number.isNaN($)&&($=0),{pitch:2*-t0,yaw:2*-G,roll:2*-$}},A=e.meshRaw;if(!A||A.length<300)return{angle:{pitch:0,yaw:0,roll:0},matrix:[1,0,0,0,1,0,0,0,1],gaze:{bearing:0,strength:0}};let a=Math.max(e.boxRaw[2]*t[0],e.boxRaw[3]*t[1])/1.5,l=[A[10],A[152],A[234],A[454]].map(f=>[f[0]*t[0]/a,f[1]*t[1]/a,f[2]]),c=n(o(l[1],l[0])),x=n(o(l[3],l[2])),i=n(r(x,c));x=r(c,i);let y=[x[0],x[1],x[2],c[0],c[1],c[2],i[0],i[1],i[2]],d=s(y),p=A.length===478?mA(e):{bearing:0,strength:0};return{angle:d,matrix:y,gaze:p}};function gn(e,t){let n=e==null?void 0:e.annotations;if(!n)return 0;let o=Math.max(Math.abs(n.leftEyeIris[3][0]-n.leftEyeIris[1][0]),Math.abs(n.rightEyeIris[3][0]-n.rightEyeIris[1][0]))/t;return Math.round(1.17/o)/100}var q5=async(e,t)=>{var p,f,b,M,T,m,h,S,P,I,q,t0,G,$,A0,v,V,n0,U,g0,m0,B,X;let n=g(),o,r,s,A,a,l,c,x,i,y=[];e.state="run:face";let d=await z3(t,e.config);if(e.performance.face=R.perfadd?(e.performance.face||0)+Math.trunc(g()-n):Math.trunc(g()-n),!t.shape||t.shape.length!==4)return[];if(!d)return[];for(let z=0;z200?bn(d[z],[t.shape[2],t.shape[1]]):null;e.analyze("Start Emotion:"),e.config.async?A=(f=e.config.face.emotion)!=null&&f.enabled?k5(d[z].tensor||l0.tensor([]),e.config,z,d.length):[]:(e.state="run:emotion",n=g(),A=(b=e.config.face.emotion)!=null&&b.enabled?await k5(d[z].tensor||l0.tensor([]),e.config,z,d.length):[],e.performance.emotion=R.perfadd?(e.performance.emotion||0)+Math.trunc(g()-n):Math.trunc(g()-n)),e.analyze("End Emotion:"),e.analyze("Start AntiSpoof:"),e.config.async?c=(M=e.config.face.antispoof)!=null&&M.enabled?j5(d[z].tensor||l0.tensor([]),e.config,z,d.length):0:(e.state="run:antispoof",n=g(),c=(T=e.config.face.antispoof)!=null&&T.enabled?await j5(d[z].tensor||l0.tensor([]),e.config,z,d.length):0,e.performance.antispoof=R.perfadd?(e.performance.antispoof||0)+Math.trunc(g()-n):Math.trunc(g()-n)),e.analyze("End AntiSpoof:"),e.analyze("Start Liveness:"),e.config.async?x=(m=e.config.face.liveness)!=null&&m.enabled?I5(d[z].tensor||l0.tensor([]),e.config,z,d.length):0:(e.state="run:liveness",n=g(),x=(h=e.config.face.liveness)!=null&&h.enabled?await I5(d[z].tensor||l0.tensor([]),e.config,z,d.length):0,e.performance.liveness=R.perfadd?(e.performance.antispoof||0)+Math.trunc(g()-n):Math.trunc(g()-n)),e.analyze("End Liveness:"),e.analyze("Start GEAR:"),e.config.async?r=(S=e.config.face.gear)!=null&&S.enabled?C5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null:(e.state="run:gear",n=g(),r=(P=e.config.face.gear)!=null&&P.enabled?await C5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,e.performance.gear=Math.trunc(g()-n)),e.analyze("End GEAR:"),e.analyze("Start SSRNet:"),e.config.async?(o=(I=e.config.face.ssrnet)!=null&&I.enabled?D5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,s=(q=e.config.face.ssrnet)!=null&&q.enabled?H5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null):(e.state="run:ssrnet",n=g(),o=(t0=e.config.face.ssrnet)!=null&&t0.enabled?await D5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,s=(G=e.config.face.ssrnet)!=null&&G.enabled?await H5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,e.performance.ssrnet=Math.trunc(g()-n)),e.analyze("End SSRNet:"),e.analyze("Start MobileFaceNet:"),e.config.async?a=($=e.config.face.mobilefacenet)!=null&&$.enabled?V5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null:(e.state="run:mobilefacenet",n=g(),a=(A0=e.config.face.mobilefacenet)!=null&&A0.enabled?await V5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,e.performance.mobilefacenet=Math.trunc(g()-n)),e.analyze("End MobileFaceNet:"),e.analyze("Start InsightFace:"),e.config.async?l=(v=e.config.face.insightface)!=null&&v.enabled?X5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null:(e.state="run:mobilefacenet",n=g(),l=(V=e.config.face.insightface)!=null&&V.enabled?await X5(d[z].tensor||l0.tensor([]),e.config,z,d.length):null,e.performance.mobilefacenet=Math.trunc(g()-n)),e.analyze("End InsightFace:"),e.analyze("Start Description:"),e.config.async?i=E5(d[z].tensor||l0.tensor([]),e.config,z,d.length):(e.state="run:description",n=g(),i=await E5(d[z].tensor||l0.tensor([]),e.config,z,d.length),e.performance.description=R.perfadd?(e.performance.description||0)+Math.trunc(g()-n):Math.trunc(g()-n)),e.analyze("End Description:"),e.config.async&&([o,s,A,a,l,i,r,c,x]=await Promise.all([o,s,A,a,l,i,r,c,x])),e.analyze("Finish Face:"),((n0=e.config.face.ssrnet)==null?void 0:n0.enabled)&&o&&s&&(i={...i,age:o.age,gender:s.gender,genderScore:s.genderScore}),((U=e.config.face.gear)==null?void 0:U.enabled)&&r&&(i={...i,age:r.age,gender:r.gender,genderScore:r.genderScore,race:r.race}),((g0=e.config.face.mobilefacenet)==null?void 0:g0.enabled)&&a&&(i.descriptor=a),((m0=e.config.face.insightface)==null?void 0:m0.enabled)&&l&&(i.descriptor=l);let we=(B=e.config.face.iris)!=null&&B.enabled?gn(d[z],t.shape[2]):0,Ee=(X=e.config.face.detector)!=null&&X.return?l0.squeeze(d[z].tensor):null;l0.dispose(d[z].tensor),d[z].tensor&&delete d[z].tensor;let T0={...d[z],id:z};i.age&&(T0.age=i.age),i.gender&&(T0.gender=i.gender),i.genderScore&&(T0.genderScore=i.genderScore),i.descriptor&&(T0.embedding=i.descriptor),i.race&&(T0.race=i.race),A&&(T0.emotion=A),c&&(T0.real=c),x&&(T0.live=x),we>0&&(T0.distance=we),ee&&(T0.rotation=ee),Ee&&(T0.tensor=Ee),y.push(T0),e.analyze("End Face")}return e.analyze("End FaceMesh:"),e.config.async&&(e.performance.face&&delete e.performance.face,e.performance.age&&delete e.performance.age,e.performance.gender&&delete e.performance.gender,e.performance.emotion&&delete e.performance.emotion),y};var W0={thumb:0,index:1,middle:2,ring:3,pinky:4,all:[0,1,2,3,4],nameMapping:{0:"thumb",1:"index",2:"middle",3:"ring",4:"pinky"},pointsMapping:{0:[[0,1],[1,2],[2,3],[3,4]],1:[[0,5],[5,6],[6,7],[7,8]],2:[[0,9],[9,10],[10,11],[11,12]],3:[[0,13],[13,14],[14,15],[15,16]],4:[[0,17],[17,18],[18,19],[19,20]]},getName:e=>W0.nameMapping[e],getPoints:e=>W0.pointsMapping[e]},Be={none:0,half:1,full:2,nameMapping:{0:"none",1:"half",2:"full"},getName:e=>Be.nameMapping[e]},c0={verticalUp:0,verticalDown:1,horizontalLeft:2,horizontalRight:3,diagonalUpRight:4,diagonalUpLeft:5,diagonalDownRight:6,diagonalDownLeft:7,nameMapping:{0:"verticalUp",1:"verticalDown",2:"horizontalLeft",3:"horizontalRight",4:"diagonalUpRight",5:"diagonalUpLeft",6:"diagonalDownRight",7:"diagonalDownLeft"},getName:e=>c0.nameMapping[e]},Fe=class{constructor(t){k(this,"name");k(this,"curls");k(this,"directions");k(this,"weights");k(this,"weightsRelative");this.name=t,this.curls={},this.directions={},this.weights=[1,1,1,1,1],this.weightsRelative=[1,1,1,1,1]}curl(t,n,o){typeof this.curls[t]=="undefined"&&(this.curls[t]=[]),this.curls[t].push([n,o])}direction(t,n,o){this.directions[t]||(this.directions[t]=[]),this.directions[t].push([n,o])}weight(t,n){this.weights[t]=n;let o=this.weights.reduce((r,s)=>r+s,0);this.weightsRelative=this.weights.map(r=>r*5/o)}matchAgainst(t,n){let o=0;for(let r in t){let s=t[r],A=this.curls[r];if(typeof A=="undefined"){o+=this.weightsRelative[r];continue}for(let[a,l]of A)if(s===a){o+=l*this.weightsRelative[r];break}}for(let r in n){let s=n[r],A=this.directions[r];if(typeof A=="undefined"){o+=this.weightsRelative[r];continue}for(let[a,l]of A)if(s===a){o+=l*this.weightsRelative[r];break}}return o/10}};var{thumb:xe,index:Me,middle:Pe,ring:r2,pinky:s2}=W0,{none:ye,half:uA,full:fe}=Be,{verticalUp:g2,verticalDown:G7,horizontalLeft:U5,horizontalRight:hA,diagonalUpRight:bA,diagonalUpLeft:T2,diagonalDownRight:V7,diagonalDownLeft:Z7}=c0,He=new Fe("thumbs up");He.curl(xe,ye,1);He.direction(xe,g2,1);He.direction(xe,T2,.25);He.direction(xe,bA,.25);for(let e of[W0.index,W0.middle,W0.ring,W0.pinky])He.curl(e,fe,1),He.direction(e,U5,1),He.direction(e,hA,1);var u0=new Fe("victory");u0.curl(xe,uA,.5);u0.curl(xe,ye,.5);u0.direction(xe,g2,1);u0.direction(xe,T2,1);u0.curl(Me,ye,1);u0.direction(Me,g2,.75);u0.direction(Me,T2,1);u0.curl(Pe,ye,1);u0.direction(Pe,g2,1);u0.direction(Pe,T2,.75);u0.curl(r2,fe,1);u0.direction(r2,g2,.2);u0.direction(r2,T2,1);u0.direction(r2,U5,.2);u0.curl(s2,fe,1);u0.direction(s2,g2,.2);u0.direction(s2,T2,1);u0.direction(s2,U5,.2);u0.weight(Me,2);u0.weight(Pe,2);var Ge=new Fe("point");Ge.curl(xe,fe,1);Ge.curl(Me,ye,.5);Ge.curl(Pe,fe,.5);Ge.curl(r2,fe,.5);Ge.curl(s2,fe,.5);Ge.weight(Me,2);Ge.weight(Pe,2);var Ve=new Fe("middle finger");Ve.curl(xe,ye,1);Ve.curl(Me,fe,.5);Ve.curl(Pe,fe,.5);Ve.curl(r2,fe,.5);Ve.curl(s2,fe,.5);Ve.weight(Me,2);Ve.weight(Pe,2);var v2=new Fe("open palm");v2.curl(xe,ye,.75);v2.curl(Me,ye,.75);v2.curl(Pe,ye,.75);v2.curl(r2,ye,.75);v2.curl(s2,ye,.75);var Tn=[He,u0,Ge,Ve,v2];var gA=.7,A2={HALF_CURL_START_LIMIT:60,NO_CURL_START_LIMIT:130,DISTANCE_VOTE_POWER:1.1,SINGLE_ANGLE_VOTE_POWER:.9,TOTAL_ANGLE_VOTE_POWER:1.6};function vn(e,t,n,o){let r=(t-o)/(e-n),s=Math.atan(r)*180/Math.PI;return s<=0?s=-s:s>0&&(s=180-s),s}function Mn(e,t){if(!e||!t)return[0,0];let n=vn(e[0],e[1],t[0],t[1]);if(e.length===2)return n;let o=vn(e[1],e[2],t[1],t[2]);return[n,o]}function Rn(e,t=1){let n=0,o=0,r=0;return e>=75&&e<=105?n=1*t:e>=25&&e<=155?o=1*t:r=1*t,[n,o,r]}function TA(e,t,n){let o=e[0]-t[0],r=e[0]-n[0],s=t[0]-n[0],A=e[1]-t[1],a=e[1]-n[1],l=t[1]-n[1],c=e[2]-t[2],x=e[2]-n[2],i=t[2]-n[2],y=Math.sqrt(o*o+A*A+c*c),d=Math.sqrt(r*r+a*a+x*x),p=Math.sqrt(s*s+l*l+i*i),f=(p*p+y*y-d*d)/(2*p*y);f>1?f=1:f<-1&&(f=-1);let b=Math.acos(f);b=57.2958*b%180;let M;return b>A2.NO_CURL_START_LIMIT?M=Be.none:b>A2.HALF_CURL_START_LIMIT?M=Be.half:M=Be.full,M}function Pn(e,t,n,o){let r;return o===Math.abs(e)?e>0?r=c0.horizontalLeft:r=c0.horizontalRight:o===Math.abs(t)?t>0?r=c0.horizontalLeft:r=c0.horizontalRight:n>0?r=c0.horizontalLeft:r=c0.horizontalRight,r}function kn(e,t,n,o){let r;return o===Math.abs(e)?e<0?r=c0.verticalDown:r=c0.verticalUp:o===Math.abs(t)?t<0?r=c0.verticalDown:r=c0.verticalUp:n<0?r=c0.verticalDown:r=c0.verticalUp,r}function vA(e,t,n,o,r,s,A,a){let l,c=kn(e,t,n,o),x=Pn(r,s,A,a);return c===c0.verticalUp?x===c0.horizontalLeft?l=c0.diagonalUpLeft:l=c0.diagonalUpRight:x===c0.horizontalLeft?l=c0.diagonalDownLeft:l=c0.diagonalDownRight,l}function RA(e,t,n,o){let r=e[0]-t[0],s=e[0]-n[0],A=t[0]-n[0],a=e[1]-t[1],l=e[1]-n[1],c=t[1]-n[1],x=Math.max(Math.abs(r),Math.abs(s),Math.abs(A)),i=Math.max(Math.abs(a),Math.abs(l),Math.abs(c)),y=0,d=0,p=0,f=i/(x+1e-5);f>1.5?y+=A2.DISTANCE_VOTE_POWER:f>.66?d+=A2.DISTANCE_VOTE_POWER:p+=A2.DISTANCE_VOTE_POWER;let b=Math.sqrt(r*r+a*a),M=Math.sqrt(s*s+l*l),T=Math.sqrt(A*A+c*c),m=Math.max(b,M,T),h=e[0],S=e[1],P=n[0],I=n[1];m===b?(P=n[0],I=n[1]):m===T&&(h=t[0],S=t[1]);let G=Mn([h,S],[P,I]),$=Rn(G,A2.TOTAL_ANGLE_VOTE_POWER);y+=$[0],d+=$[1],p+=$[2];for(let v of o){let V=Rn(v,A2.SINGLE_ANGLE_VOTE_POWER);y+=V[0],d+=V[1],p+=V[2]}let A0;return y===Math.max(y,d,p)?A0=kn(l,a,c,i):p===Math.max(d,p)?A0=Pn(s,r,A,x):A0=vA(l,a,c,i,s,r,A,x),A0}function wn(e){let t=[],n=[],o=[],r=[];if(!e)return{curls:o,directions:r};for(let s of W0.all){let A=W0.getPoints(s),a=[],l=[];for(let c of A){let x=e[c[0]],i=e[c[1]],y=Mn(x,i),d=y[0],p=y[1];a.push(d),l.push(p)}t.push(a),n.push(l)}for(let s of W0.all){let A=s===W0.thumb?1:0,a=W0.getPoints(s),l=e[a[A][0]],c=e[a[A+1][1]],x=e[a[3][1]],i=TA(l,c,x),y=RA(l,c,x,t[s].slice(A));o[s]=i,r[s]=y}return{curls:o,directions:r}}function Rt(e){if(!e||e.length===0)return null;let t=wn(e),n={};for(let o of W0.all)n[W0.getName(o)]={curl:Be.getName(t.curls[o]),direction:c0.getName(t.directions[o])};return n}function En(e){let t=[];if(!e||e.length===0)return t;let n=wn(e);for(let o of Tn){let r=o.matchAgainst(n.curls,n.directions);r>=gA&&t.push({name:o.name,confidence:r})}return t}var zn=e=>{if(!e)return[];let t=[];for(let n=0;nl.part==="leftWrist"),r=e[n].keypoints.find(l=>l.part==="rightWrist"),s=e[n].keypoints.find(l=>l.part==="nose");s&&o&&r&&o.position[1]l.part==="leftShoulder"),a=e[n].keypoints.find(l=>l.part==="rightShoulder");A&&a&&Math.abs(A.positionRaw[1]-a.positionRaw[1])>.1&&t.push({body:n,gesture:`leaning ${A.position[1]>a.position[1]?"left":"right"}`})}return t},Sn=e=>{if(!e)return[];let t=[];for(let n=0;n450){let o=(e[n].mesh[33][2]||0)-(e[n].mesh[263][2]||0),r=e[n].mesh[33][0]-e[n].mesh[263][0];Math.abs(o/r)<=.15?t.push({face:n,gesture:"facing center"}):t.push({face:n,gesture:`facing ${o<0?"left":"right"}`}),Math.abs(e[n].mesh[374][1]-e[n].mesh[386][1])/Math.abs(e[n].mesh[443][1]-e[n].mesh[450][1])<.2&&t.push({face:n,gesture:"blink left eye"}),Math.abs(e[n].mesh[145][1]-e[n].mesh[159][1])/Math.abs(e[n].mesh[223][1]-e[n].mesh[230][1])<.2&&t.push({face:n,gesture:"blink right eye"});let a=Math.min(100,500*Math.abs(e[n].mesh[13][1]-e[n].mesh[14][1])/Math.abs(e[n].mesh[10][1]-e[n].mesh[152][1]));a>10&&t.push({face:n,gesture:`mouth ${Math.trunc(a)}% open`});let l=e[n].mesh[152][2]||0;Math.abs(l)>10&&t.push({face:n,gesture:`head ${l<0?"up":"down"}`})}return t},jn=e=>{var n,o,r,s;if(!e)return[];let t=[];for(let A=0;A.06||b>.06)&&(d=!1),f>b?f>.05&&t.push({iris:A,gesture:"looking right"}):b>.05&&t.push({iris:A,gesture:"looking left"});let M=Math.abs(e[A].mesh[145][1]-e[A].annotations.rightEyeIris[0][1])/e[A].box[3],T=Math.abs(e[A].mesh[374][1]-e[A].annotations.leftEyeIris[0][1])/e[A].box[3];(T<.01||M<.01||T>.022||M>.022)&&(d=!1),(T<.01||M<.01)&&t.push({iris:A,gesture:"looking down"}),(T>.022||M>.022)&&t.push({iris:A,gesture:"looking up"}),d&&t.push({iris:A,gesture:"looking center"})}return t},Nn=e=>{if(!e)return[];let t=[];for(let n=0;n0){let r=o.reduce((A,a)=>(A.position[2]||0)<(a.position[2]||0)?A:a);t.push({hand:n,gesture:`${r.name} forward`});let s=o.reduce((A,a)=>A.position[1][s[0]*t[0],s[1]*t[1]]);return{startPoint:n,endPoint:o,palmLandmarks:r,confidence:e.confidence}}function Pt(e,t=1.5){let n=L2(e),o=Mt(e),r=[t*o[0]/2,t*o[1]/2],s=[n[0]-r[0],n[1]-r[1]],A=[n[0]+r[0],n[1]+r[1]];return{startPoint:s,endPoint:A,palmLandmarks:e.palmLandmarks}}function kt(e){let t=L2(e),n=Mt(e),r=Math.max(...n)/2,s=[t[0]-r,t[1]-r],A=[t[0]+r,t[1]+r];return{startPoint:s,endPoint:A,palmLandmarks:e.palmLandmarks}}function PA(e){return e-2*Math.PI*Math.floor((e+Math.PI)/(2*Math.PI))}function Dn(e,t){let n=Math.PI/2-Math.atan2(-(t[1]-e[1]),t[0]-e[0]);return PA(n)}var In=(e,t)=>[[1,0,e],[0,1,t],[0,0,1]];function Ze(e,t){let n=0;for(let o=0;o[A.x,A.y]),this.anchorsTensor=W.tensor2d(this.anchors),this.inputSize=((s=(r=(o=(n=this==null?void 0:this.model)==null?void 0:n.inputs)==null?void 0:o[0])==null?void 0:r.shape)==null?void 0:s[2])||0,this.inputSizeTensor=W.tensor1d([this.inputSize,this.inputSize]),this.doubleInputSizeTensor=W.tensor1d([this.inputSize*2,this.inputSize*2])}normalizeBoxes(t){let n={};n.boxOffsets=W.slice(t,[0,0],[-1,2]),n.boxSizes=W.slice(t,[0,2],[-1,2]),n.div=W.div(n.boxOffsets,this.inputSizeTensor),n.boxCenterPoints=W.add(n.div,this.anchorsTensor),n.halfBoxSizes=W.div(n.boxSizes,this.doubleInputSizeTensor),n.sub=W.sub(n.boxCenterPoints,n.halfBoxSizes),n.startPoints=W.mul(n.sub,this.inputSizeTensor),n.add=W.add(n.boxCenterPoints,n.halfBoxSizes),n.endPoints=W.mul(n.add,this.inputSizeTensor);let o=W.concat2d([n.startPoints,n.endPoints],1);return Object.keys(n).forEach(r=>W.dispose(n[r])),o}normalizeLandmarks(t,n){let o={};o.reshape=W.reshape(t,[-1,7,2]),o.div=W.div(o.reshape,this.inputSizeTensor),o.landmarks=W.add(o.div,this.anchors[n]?this.anchors[n]:0);let r=W.mul(o.landmarks,this.inputSizeTensor);return Object.keys(o).forEach(s=>W.dispose(o[s])),r}async predict(t,n){var a;let o={};o.resize=W.image.resizeBilinear(t,[this.inputSize,this.inputSize]),o.div=W.div(o.resize,C.tf127),o.image=W.sub(o.div,C.tf1),o.batched=this.model.execute(o.image),o.predictions=W.squeeze(o.batched),o.slice=W.slice(o.predictions,[0,0],[-1,1]),o.sigmoid=W.sigmoid(o.slice),o.scores=W.squeeze(o.sigmoid);let r=await o.scores.data();o.boxes=W.slice(o.predictions,[0,1],[-1,4]),o.norm=this.normalizeBoxes(o.boxes),o.nms=await W.image.nonMaxSuppressionAsync(o.norm,o.scores,3*(((a=n.hand)==null?void 0:a.maxDetected)||1),n.hand.iouThreshold,n.hand.minConfidence);let s=await o.nms.array(),A=[];for(let l of s){let c={};c.box=W.slice(o.norm,[l,0],[1,-1]),c.slice=W.slice(o.predictions,[l,5],[1,14]),c.norm=this.normalizeLandmarks(c.slice,l),c.palmLandmarks=W.reshape(c.norm,[-1,2]);let x=await c.box.data(),i=x.slice(0,2),y=x.slice(2,4),d=await c.palmLandmarks.array(),p={startPoint:i,endPoint:y,palmLandmarks:d,confidence:r[l]},f=Wn(p,[(t.shape[2]||1)/this.inputSize,(t.shape[1]||0)/this.inputSize]);A.push(f),Object.keys(c).forEach(b=>W.dispose(c[b]))}return Object.keys(o).forEach(l=>W.dispose(o[l])),A}};var U0=Z(H());var zA=5,Gn=1.65,Vn=[0,5,9,13,17,1,2],SA=0,jA=2,Zn=0,Et=class{constructor(t,n){k(this,"handDetector");k(this,"handPoseModel");k(this,"inputSize");k(this,"storedBoxes");k(this,"skipped");k(this,"detectedHands");var o,r,s;this.handDetector=t,this.handPoseModel=n,this.inputSize=((s=(r=(o=this.handPoseModel)==null?void 0:o.inputs)==null?void 0:r[0].shape)==null?void 0:s[2])||0,this.storedBoxes=[],this.skipped=Number.MAX_SAFE_INTEGER,this.detectedHands=0}calculateLandmarksBoundingBox(t){let n=t.map(A=>A[0]),o=t.map(A=>A[1]),r=[Math.min(...n),Math.min(...o)],s=[Math.max(...n),Math.max(...o)];return{startPoint:r,endPoint:s}}getBoxForPalmLandmarks(t,n){let o=t.map(s=>J5([...s,1],n)),r=this.calculateLandmarksBoundingBox(o);return Pt(kt(r),zA)}getBoxForHandLandmarks(t){let n=this.calculateLandmarksBoundingBox(t),o=Pt(kt(n),Gn);o.palmLandmarks=[];for(let r=0;r[A[0]*(d[0]-this.inputSize/2),A[1]*(d[1]-this.inputSize/2),A[2]*d[2]]),l=K5(o,[0,0]),c=a.map(d=>[...J5(d,l),d[2]]),x=Fn(r),i=[...L2(n),1],y=[Ze(i,x[0]),Ze(i,x[1])];return c.map(d=>[Math.trunc(d[0]+y[0]),Math.trunc(d[1]+y[1]),Math.trunc(d[2])])}async estimateHands(t,n){let o=!1,r,s=(n.hand.skipTime||0)>g()-Zn,A=this.skipped<(n.hand.skipFrames||0);n.skipAllowed&&s&&A&&(r=await this.handDetector.predict(t,n),this.skipped=0),n.skipAllowed&&this.skipped++,r&&r.length>0&&(r.length!==this.detectedHands&&this.detectedHands!==n.hand.maxDetected||!n.hand.landmarks)&&(this.detectedHands=0,this.storedBoxes=[...r],this.storedBoxes.length>0&&(o=!0));let a=[];for(let l=0;l=n.hand.minConfidence/4){let S=U0.reshape(m,[-1,3]),P=await S.array();U0.dispose(m),U0.dispose(S);let I=this.transformRawCoords(P,f,x,p),q=this.getBoxForHandLandmarks(I);this.storedBoxes[l]={...q,confidence:h};let t0={landmarks:I,confidence:h,boxConfidence:c.confidence,fingerConfidence:h,box:{topLeft:q.startPoint,bottomRight:q.endPoint}};a.push(t0)}else this.storedBoxes[l]=null;U0.dispose(m)}else{let x=Pt(kt(c),Gn),i={confidence:c.confidence,boxConfidence:c.confidence,fingerConfidence:0,box:{topLeft:x.startPoint,bottomRight:x.endPoint},landmarks:[]};a.push(i)}}return this.storedBoxes=this.storedBoxes.filter(l=>l!==null),this.detectedHands=a.length,a.length>n.hand.maxDetected&&(a.length=n.hand.maxDetected),a}};var Xn={thumb:[1,2,3,4],index:[5,6,7,8],middle:[9,10,11,12],ring:[13,14,15,16],pinky:[17,18,19,20],palm:[0]},a2,i2,qn;async function Q5(e,t){let n=await qn.estimateHands(e,t);if(!n)return[];let o=[];for(let r=0;rn[r].landmarks[i]);let A=n[r].landmarks,a=[Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,0,0],l=[0,0,0,0];if(A&&A.length>0){for(let x of A)x[0]a[2]&&(a[2]=x[0]),x[1]>a[3]&&(a[3]=x[1]);a[2]-=a[0],a[3]-=a[1],l=[a[0]/(e.shape[2]||0),a[1]/(e.shape[1]||0),a[2]/(e.shape[2]||0),a[3]/(e.shape[1]||0)]}else a=n[r].box?[Math.trunc(Math.max(0,n[r].box.topLeft[0])),Math.trunc(Math.max(0,n[r].box.topLeft[1])),Math.trunc(Math.min(e.shape[2]||0,n[r].box.bottomRight[0])-Math.max(0,n[r].box.topLeft[0])),Math.trunc(Math.min(e.shape[1]||0,n[r].box.bottomRight[1])-Math.max(0,n[r].box.topLeft[1]))]:[0,0,0,0],l=[n[r].box.topLeft[0]/(e.shape[2]||0),n[r].box.topLeft[1]/(e.shape[1]||0),(n[r].box.bottomRight[0]-n[r].box.topLeft[0])/(e.shape[2]||0),(n[r].box.bottomRight[1]-n[r].box.topLeft[1])/(e.shape[1]||0)];let c=Rt(A);o.push({id:r,score:Math.round(100*n[r].confidence)/100,boxScore:Math.round(100*n[r].boxConfidence)/100,fingerScore:Math.round(100*n[r].fingerConfidence)/100,label:"hand",box:a,boxRaw:l,keypoints:A,annotations:s,landmarks:c})}return o}async function Un(e){var n,o;R.initial&&(a2=null,i2=null),!a2||!i2?[a2,i2]=await Promise.all([e.hand.enabled?O((n=e.hand.detector)==null?void 0:n.modelPath):null,e.hand.landmarks?O((o=e.hand.skeleton)==null?void 0:o.modelPath):null]):(e.debug&&u("cached model:",a2.modelUrl),e.debug&&u("cached model:",i2.modelUrl));let t=a2?new wt(a2):void 0;return t&&i2&&(qn=new Et(t,i2)),[a2,i2]}var Q=Z(H());var f0=[null,null],IA=["StatefulPartitionedCall/Postprocessor/Slice","StatefulPartitionedCall/Postprocessor/ExpandDims_1"],Xe=[[0,0],[0,0]],OA=["hand","fist","pinch","point","face","tip","pinchtip"],Kn=4,Jn=1.6,LA=512,CA=1.4,zt=Number.MAX_SAFE_INTEGER,_5=0,ke=[0,0],y0={boxes:[],hands:[]},Qn={thumb:[1,2,3,4],index:[5,6,7,8],middle:[9,10,11,12],ring:[13,14,15,16],pinky:[17,18,19,20],base:[0],palm:[0,17,13,9,5,1,0]};async function _n(e){var t;if(R.initial&&(f0[0]=null),f0[0])e.debug&&u("cached model:",f0[0].modelUrl);else{Y2(["tensorlistreserve","enter","tensorlistfromtensor","merge","loopcond","switch","exit","tensorliststack","nextiteration","tensorlistsetitem","tensorlistgetitem","reciprocal","shape","split","where"],e),f0[0]=await O((t=e.hand.detector)==null?void 0:t.modelPath);let n=f0[0].executor?Object.values(f0[0].modelSignature.inputs):void 0;Xe[0][0]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[1].size):0,Xe[0][1]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[2].size):0}return f0[0]}async function $n(e){var t;if(R.initial&&(f0[1]=null),f0[1])e.debug&&u("cached model:",f0[1].modelUrl);else{f0[1]=await O((t=e.hand.skeleton)==null?void 0:t.modelPath);let n=f0[1].executor?Object.values(f0[1].modelSignature.inputs):void 0;Xe[1][0]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[1].size):0,Xe[1][1]=Array.isArray(n)?parseInt(n[0].tensorShape.dim[2].size):0}return f0[1]}async function WA(e,t){let n=[];if(!e||!f0[0])return n;let o={},r=(e.shape[2]||1)/(e.shape[1]||1),s=Math.min(Math.round((e.shape[1]||0)/8)*8,LA),A=Math.round(s*r/8)*8;o.resize=Q.image.resizeBilinear(e,[s,A]),o.cast=Q.cast(o.resize,"int32"),[o.rawScores,o.rawBoxes]=await f0[0].executeAsync(o.cast,IA),o.boxes=Q.squeeze(o.rawBoxes,[0,2]),o.scores=Q.squeeze(o.rawScores,[0]);let a=Q.unstack(o.scores,1);Q.dispose(a[Kn]),a.splice(Kn,1),o.filtered=Q.stack(a,1),Q.dispose(a),o.max=Q.max(o.filtered,1),o.argmax=Q.argMax(o.filtered,1);let l=0;o.nms=await Q.image.nonMaxSuppressionAsync(o.boxes,o.max,(t.hand.maxDetected||0)+1,t.hand.iouThreshold||0,t.hand.minConfidence||1);let c=await o.nms.data(),x=await o.max.data(),i=await o.argmax.data();for(let y of Array.from(c)){let d=Q.slice(o.boxes,y,1),p=await d.data();Q.dispose(d);let f=[p[1],p[0],p[3]-p[1],p[2]-p[0]],b=ot(f,CA),M=[Math.trunc(f[0]*ke[0]),Math.trunc(f[1]*ke[1]),Math.trunc(f[2]*ke[0]),Math.trunc(f[3]*ke[1])],T=x[y],m=OA[i[y]],h={id:l++,score:T,box:M,boxRaw:b,label:m};n.push(h)}return Object.keys(o).forEach(y=>Q.dispose(o[y])),n.sort((y,d)=>d.score-y.score),n.length>(t.hand.maxDetected||1)&&(n.length=t.hand.maxDetected||1),n}async function $5(e,t,n){let o={id:t.id,score:Math.round(100*t.score)/100,boxScore:Math.round(100*t.score)/100,fingerScore:0,box:t.box,boxRaw:t.boxRaw,label:t.label,keypoints:[],landmarks:{},annotations:{}};if(e&&f0[1]&&n.hand.landmarks&&t.score>(n.hand.minConfidence||0)){let r={},s=[t.boxRaw[1],t.boxRaw[0],t.boxRaw[3]+t.boxRaw[1],t.boxRaw[2]+t.boxRaw[0]];r.crop=Q.image.cropAndResize(e,[s],[0],[Xe[1][0],Xe[1][1]],"bilinear"),r.div=Q.div(r.crop,C.tf255),[r.score,r.keypoints]=f0[1].execute(r.div,["Identity_1","Identity"]);let A=(await r.score.data())[0],a=(100-Math.trunc(100/(1+Math.exp(A))))/100;if(a>=(n.hand.minConfidence||0)){o.fingerScore=a,r.reshaped=Q.reshape(r.keypoints,[-1,3]);let x=(await r.reshaped.array()).map(i=>[i[0]/Xe[1][1],i[1]/Xe[1][0],i[2]||0]).map(i=>[i[0]*t.boxRaw[2],i[1]*t.boxRaw[3],i[2]||0]);o.keypoints=x.map(i=>[ke[0]*(i[0]+t.boxRaw[0]),ke[1]*(i[1]+t.boxRaw[1]),i[2]||0]),o.landmarks=Rt(o.keypoints);for(let i of Object.keys(Qn))o.annotations[i]=Qn[i].map(y=>o.landmarks&&o.keypoints[y]?o.keypoints[y]:null)}Object.keys(r).forEach(l=>Q.dispose(r[l]))}return o}async function e1(e,t){var r,s;if(!((r=f0[0])!=null&&r.executor)||!((s=f0[1])!=null&&s.executor)||!f0[0].inputs[0].shape||!f0[1].inputs[0].shape)return[];ke=[e.shape[2]||0,e.shape[1]||0],zt++;let n=(t.hand.skipTime||0)>g()-_5,o=zt<(t.hand.skipFrames||0);return t.skipAllowed&&n&&o?y0.hands:new Promise(async A=>{let a=3*(t.hand.skipTime||0)>g()-_5,l=zt<3*(t.hand.skipFrames||0);t.skipAllowed&&y0.hands.length===t.hand.maxDetected?y0.hands=await Promise.all(y0.boxes.map(x=>$5(e,x,t))):t.skipAllowed&&a&&l&&y0.hands.length>0?y0.hands=await Promise.all(y0.boxes.map(x=>$5(e,x,t))):(y0.boxes=await WA(e,t),_5=g(),y0.hands=await Promise.all(y0.boxes.map(x=>$5(e,x,t))),zt=0);let c=[...y0.boxes];if(y0.boxes.length=0,t.cacheSensitivity>0)for(let x=0;x.05&&i.box[3]/(e.shape[1]||1)>.05&&y0.hands[x].fingerScore&&y0.hands[x].fingerScore>(t.hand.minConfidence||0)){let y=ot(i.box,Jn),d=ot(i.boxRaw,Jn);y0.boxes.push({...c[x],box:y,boxRaw:d})}}for(let x=0;x({face:[],body:[],hand:[],gesture:[],object:[],persons:[],performance:{},timestamp:0,width:0,height:0,error:e});var C2={};ze(C2,{connected:()=>jt,horizontal:()=>t1,kpt:()=>St,relative:()=>o1,vertical:()=>n1});var St=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"],t1=[["leftEye","rightEye"],["leftEar","rightEar"],["leftShoulder","rightShoulder"],["leftElbow","rightElbow"],["leftWrist","rightWrist"],["leftHip","rightHip"],["leftKnee","rightKnee"],["leftAnkle","rightAnkle"]],n1=[["leftKnee","leftShoulder"],["rightKnee","rightShoulder"],["leftAnkle","leftKnee"],["rightAnkle","rightKnee"]],o1=[[["leftHip","rightHip"],["leftShoulder","rightShoulder"]],[["leftElbow","rightElbow"],["leftShoulder","rightShoulder"]]],jt={leftLeg:["leftHip","leftKnee","leftAnkle"],rightLeg:["rightHip","rightKnee","rightAnkle"],torso:["leftShoulder","rightShoulder","rightHip","leftHip","leftShoulder"],leftArm:["leftShoulder","leftElbow","leftWrist"],rightArm:["rightShoulder","rightElbow","rightWrist"],head:[]};var w=he(),r1=0;function to(e,t){var A,a,l,c,x,i,y,d,p,f,b,M,T,m,h,S,P,I,q,t0,G,$,A0;let n=g();if(!e)return he();let o=Date.now()-e.timestamp,r=o<1e3?8-Math.log(o+1):1;if(e.canvas&&(w.canvas=e.canvas),e.error&&(w.error=e.error),!w.body||e.body.length!==w.body.length)w.body=JSON.parse(JSON.stringify(e.body));else for(let v=0;v((r-1)*w.body[v].box[X]+B)/r),n0=e.body[v].boxRaw.map((B,X)=>((r-1)*w.body[v].boxRaw[X]+B)/r),U=e.body[v].keypoints.map((B,X)=>{var z,ee,we,Ee,T0,P2,R1,M1,P1;return{score:B.score,part:B.part,position:[w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].position[0]||0)+(B.position[0]||0))/r:B.position[0],w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].position[1]||0)+(B.position[1]||0))/r:B.position[1],w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].position[2]||0)+(B.position[2]||0))/r:B.position[2]],positionRaw:[w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].positionRaw[0]||0)+(B.positionRaw[0]||0))/r:B.positionRaw[0],w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].positionRaw[1]||0)+(B.positionRaw[1]||0))/r:B.positionRaw[1],w.body[v].keypoints[X]?((r-1)*(w.body[v].keypoints[X].positionRaw[2]||0)+(B.positionRaw[2]||0))/r:B.positionRaw[2]],distance:[w.body[v].keypoints[X]?((r-1)*(((z=w.body[v].keypoints[X].distance)==null?void 0:z[0])||0)+(((ee=B.distance)==null?void 0:ee[0])||0))/r:(we=B.distance)==null?void 0:we[0],w.body[v].keypoints[X]?((r-1)*(((Ee=w.body[v].keypoints[X].distance)==null?void 0:Ee[1])||0)+(((T0=B.distance)==null?void 0:T0[1])||0))/r:(P2=B.distance)==null?void 0:P2[1],w.body[v].keypoints[X]?((r-1)*(((R1=w.body[v].keypoints[X].distance)==null?void 0:R1[2])||0)+(((M1=B.distance)==null?void 0:M1[2])||0))/r:(P1=B.distance)==null?void 0:P1[2]]}}),g0={},m0={connected:{}};(A=t.body.modelPath)!=null&&A.includes("efficientpose")?m0=At:(a=t.body.modelPath)!=null&&a.includes("blazepose")?m0=tt:(l=t.body.modelPath)!=null&&l.includes("movenet")&&(m0=C2);for(let[B,X]of Object.entries(m0.connected)){let z=[];for(let ee=0;eeT0.part===X[ee]),Ee=U.find(T0=>T0.part===X[ee+1]);we&&Ee&&z.push([we.position,Ee.position])}g0[B]=z}w.body[v]={...e.body[v],box:V,boxRaw:n0,keypoints:U,annotations:g0}}if(!w.hand||e.hand.length!==w.hand.length)w.hand=JSON.parse(JSON.stringify(e.hand));else for(let v=0;v((r-1)*w.hand[v].box[B]+m0)/r),n0=e.hand[v].boxRaw.map((m0,B)=>((r-1)*w.hand[v].boxRaw[B]+m0)/r);w.hand[v].keypoints.length!==e.hand[v].keypoints.length&&(w.hand[v].keypoints=e.hand[v].keypoints);let U=e.hand[v].keypoints&&e.hand[v].keypoints.length>0?e.hand[v].keypoints.map((m0,B)=>m0.map((X,z)=>((r-1)*(w.hand[v].keypoints[B][z]||1)+(X||0))/r)):[],g0={};if(Object.keys(w.hand[v].annotations).length!==Object.keys(e.hand[v].annotations).length)w.hand[v].annotations=e.hand[v].annotations,g0=w.hand[v].annotations;else if(e.hand[v].annotations)for(let m0 of Object.keys(e.hand[v].annotations))g0[m0]=(i=(x=(c=e.hand[v])==null?void 0:c.annotations)==null?void 0:x[m0])!=null&&i[0]?e.hand[v].annotations[m0].map((B,X)=>B.map((z,ee)=>((r-1)*w.hand[v].annotations[m0][X][ee]+z)/r)):null;w.hand[v]={...e.hand[v],box:V,boxRaw:n0,keypoints:U,annotations:g0}}if(!w.face||e.face.length!==w.face.length)w.face=JSON.parse(JSON.stringify(e.face));else for(let v=0;v((r-1)*w.face[v].box[g0]+U)/r),n0=e.face[v].boxRaw.map((U,g0)=>((r-1)*w.face[v].boxRaw[g0]+U)/r);if(e.face[v].rotation){let U={matrix:[0,0,0,0,0,0,0,0,0],angle:{roll:0,yaw:0,pitch:0},gaze:{bearing:0,strength:0}};U.matrix=(y=e.face[v].rotation)==null?void 0:y.matrix,U.angle={roll:((r-1)*(((p=(d=w.face[v].rotation)==null?void 0:d.angle)==null?void 0:p.roll)||0)+(((b=(f=e.face[v].rotation)==null?void 0:f.angle)==null?void 0:b.roll)||0))/r,yaw:((r-1)*(((T=(M=w.face[v].rotation)==null?void 0:M.angle)==null?void 0:T.yaw)||0)+(((h=(m=e.face[v].rotation)==null?void 0:m.angle)==null?void 0:h.yaw)||0))/r,pitch:((r-1)*(((P=(S=w.face[v].rotation)==null?void 0:S.angle)==null?void 0:P.pitch)||0)+(((q=(I=e.face[v].rotation)==null?void 0:I.angle)==null?void 0:q.pitch)||0))/r},U.gaze={bearing:((r-1)*(((t0=w.face[v].rotation)==null?void 0:t0.gaze.bearing)||0)+(((G=e.face[v].rotation)==null?void 0:G.gaze.bearing)||0))/r,strength:((r-1)*((($=w.face[v].rotation)==null?void 0:$.gaze.strength)||0)+(((A0=e.face[v].rotation)==null?void 0:A0.gaze.strength)||0))/r},w.face[v]={...e.face[v],rotation:U,box:V,boxRaw:n0}}else w.face[v]={...e.face[v],box:V,boxRaw:n0}}if(!w.object||e.object.length!==w.object.length)w.object=JSON.parse(JSON.stringify(e.object));else for(let v=0;v((r-1)*w.object[v].box[g0]+U)/r),n0=e.object[v].boxRaw.map((U,g0)=>((r-1)*w.object[v].boxRaw[g0]+U)/r);w.object[v]={...e.object[v],box:V,boxRaw:n0}}if(e.persons){let v=e.persons;if(!w.persons||v.length!==w.persons.length)w.persons=JSON.parse(JSON.stringify(v));else for(let V=0;V((r-1)*w.persons[V].box[U]+n0)/r)}e.gesture&&(w.gesture=e.gesture),w.width=e.width,w.height=e.height;let s=g();return r1=R.perfadd?r1+Math.round(s-n):Math.round(s-n),e.performance&&(w.performance={...e.performance,interpolate:r1}),w}var s0=Z(H());var j0;async function s1(e){return!j0||R.initial?j0=await O(e.segmentation.modelPath):e.debug&&u("cached model:",j0.modelUrl),j0}async function no(e,t){var r;if(j0||(j0=await s1(t)),!(j0!=null&&j0.executor)||!((r=j0==null?void 0:j0.inputs)!=null&&r[0].shape))return null;let n={};n.resize=s0.image.resizeBilinear(e,[j0.inputs[0].shape?j0.inputs[0].shape[1]:0,j0.inputs[0].shape?j0.inputs[0].shape[2]:0],!1),n.norm=s0.div(n.resize,C.tf255),n.res=j0.execute(n.norm),n.squeeze=s0.squeeze(n.res,[0]),[n.bgRaw,n.fgRaw]=s0.unstack(n.squeeze,2),n.fg=s0.softmax(n.fgRaw),n.mul=s0.mul(n.fg,C.tf255),n.expand=s0.expandDims(n.mul,2),n.output=s0.image.resizeBilinear(n.expand,[e.shape[1]||0,e.shape[2]||0]);let o;switch(t.segmentation.mode||"default"){case"default":n.input=s0.squeeze(e),n.concat=s0.concat([n.input,n.output],-1),o=s0.cast(n.concat,"int32");break;case"alpha":o=s0.cast(n.output,"int32");break;default:o=s0.tensor(0)}return Object.keys(n).forEach(s=>s0.dispose(n[s])),o}var Nt={};ze(Nt,{distance:()=>A1,find:()=>BA,similarity:()=>FA});function A1(e,t,n={order:2,multiplier:25}){if(!e||!e)return Number.MAX_SAFE_INTEGER;let o=0;for(let r=0;r{if(e===0)return 1;let s=(1-(t===2?Math.sqrt(e):e**(1/t))/100-n)/(o-n);return Math.max(Math.min(s,1),0)};function FA(e,t,n={order:2,multiplier:25,min:.2,max:.8}){let o=A1(e,t,n);return ro(o,n.order||2,n.min||0,n.max||1)}function BA(e,t,n={order:2,multiplier:25,threshold:0,min:.2,max:.8}){if(!Array.isArray(e)||!Array.isArray(t)||e.length<64||t.length===0)return{index:-1,distance:Number.POSITIVE_INFINITY,similarity:0};let o=Number.MAX_SAFE_INTEGER,r=-1;for(let A=0;AF2,validateModel:()=>Ft});var lo=Z(H());var qe=Z(H());var so=.005,Y0={keypoints:[],padding:[[0,0],[0,0],[0,0],[0,0]]};function a1(e){for(let t of t1){let n=e.keypoints.findIndex(r=>r.part===t[0]),o=e.keypoints.findIndex(r=>r.part===t[1]);if(e.keypoints[n]&&e.keypoints[o]&&e.keypoints[n].position[0]r&&r.part===t[0]),o=e.keypoints.findIndex(r=>r&&r.part===t[1]);e.keypoints[n]&&e.keypoints[o]&&e.keypoints[n].position[1]c&&c.part===t[0]),r=e.keypoints.findIndex(c=>c&&c.part===t[1]),s=e.keypoints.findIndex(c=>c&&c.part===n[0]),A=e.keypoints.findIndex(c=>c&&c.part===n[1]);if(!e.keypoints[s]||!e.keypoints[A])continue;let a=e.keypoints[o]?[Math.abs(e.keypoints[s].position[0]-e.keypoints[o].position[0]),Math.abs(e.keypoints[A].position[0]-e.keypoints[o].position[0])]:[0,0],l=e.keypoints[r]?[Math.abs(e.keypoints[A].position[0]-e.keypoints[r].position[0]),Math.abs(e.keypoints[s].position[0]-e.keypoints[r].position[0])]:[0,0];if(a[0]>a[1]||l[0]>l[1]){let c=e.keypoints[o];e.keypoints[o]=e.keypoints[r],e.keypoints[r]=c}}}function Ao(e){for(let t=0;te.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0,e.shape[2]>e.shape[1]?Math.trunc((e.shape[2]-e.shape[1])/2):0],[e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0,e.shape[1]>e.shape[2]?Math.trunc((e.shape[1]-e.shape[2])/2):0],[0,0]],n.pad=qe.pad(e,Y0.padding),n.resize=qe.image.resizeBilinear(n.pad,[t,t]);let o=qe.cast(n.resize,"int32");return Object.keys(n).forEach(A=>qe.dispose(n[A])),o}function io(e,t){e.keypoints=e.keypoints.filter(o=>o==null?void 0:o.position);for(let o of e.keypoints)o.position=[o.position[0]*(t[0]+Y0.padding[2][0]+Y0.padding[2][1])/t[0]-Y0.padding[2][0],o.position[1]*(t[1]+Y0.padding[1][0]+Y0.padding[1][1])/t[1]-Y0.padding[1][0]],o.positionRaw=[o.position[0]/t[0],o.position[1]/t[1]];let n=ve(e.keypoints.map(o=>o.position),t);return e.box=n.box,e.boxRaw=n.boxRaw,e}var h0,It=0,i1=Number.MAX_SAFE_INTEGER,l2={boxes:[],bodies:[],last:0};async function co(e){var t;return R.initial&&(h0=null),h0?e.debug&&u("cached model:",h0.modelUrl):(Y2(["size"],e),h0=await O(e.body.modelPath)),It=(h0==null?void 0:h0.executor)&&((t=h0==null?void 0:h0.inputs)==null?void 0:t[0].shape)?h0.inputs[0].shape[2]:0,It<64&&(It=256),h0}function GA(e,t,n){let o=e[0][0],r=[],s=0;for(let x=0;xt.body.minConfidence){let i=[o[x][1],o[x][0]];r.push({score:Math.round(100*s)/100,part:St[x],positionRaw:i,position:[Math.round((n.shape[2]||0)*i[0]),Math.round((n.shape[1]||0)*i[1])]})}s=r.reduce((x,i)=>i.score>x?i.score:x,0);let A=[],a=ve(r.map(x=>x.position),[n.shape[2],n.shape[1]]),l={};for(let[x,i]of Object.entries(jt)){let y=[];for(let d=0;db.part===i[d]),f=r.find(b=>b.part===i[d+1]);p&&f&&p.score>(t.body.minConfidence||0)&&f.score>(t.body.minConfidence||0)&&y.push([p.position,f.position])}l[x]=y}let c={id:0,score:s,box:a.box,boxRaw:a.boxRaw,keypoints:r,annotations:l};return a1(c),A.push(c),A}function VA(e,t,n){let o=[];for(let r=0;rt.body.minConfidence){let a=[];for(let i=0;i<17;i++){let y=s[3*i+2];if(y>t.body.minConfidence){let d=[s[3*i+1],s[3*i+0]];a.push({part:St[i],score:Math.round(100*y)/100,positionRaw:d,position:[Math.round((n.shape[2]||0)*d[0]),Math.round((n.shape[1]||0)*d[1])]})}}let l=ve(a.map(i=>i.position),[n.shape[2],n.shape[1]]),c={};for(let[i,y]of Object.entries(jt)){let d=[];for(let p=0;pM.part===y[p]),b=a.find(M=>M.part===y[p+1]);f&&b&&f.score>(t.body.minConfidence||0)&&b.score>(t.body.minConfidence||0)&&d.push([f.position,b.position])}c[i]=d}let x={id:r,score:A,box:l.box,boxRaw:l.boxRaw,keypoints:[...a],annotations:c};a1(x),o.push(x)}}return o.sort((r,s)=>s.score-r.score),o.length>t.body.maxDetected&&(o.length=t.body.maxDetected),o}async function l1(e,t){var r;if(!(h0!=null&&h0.executor)||!((r=h0==null?void 0:h0.inputs)!=null&&r[0].shape))return[];t.skipAllowed||(l2.boxes.length=0),i1++;let n=(t.body.skipTime||0)>g()-l2.last,o=i1<(t.body.skipFrames||0);return t.skipAllowed&&n&&o?l2.bodies:new Promise(async s=>{let A={};i1=0,A.input=ao(e,It),A.res=h0==null?void 0:h0.execute(A.input),l2.last=g();let a=await A.res.array();l2.bodies=A.res.shape[2]===17?GA(a,t,e):VA(a,t,e);for(let l of l2.bodies)io(l,[e.shape[2]||1,e.shape[1]||1]),Ao(l.keypoints);Object.keys(A).forEach(l=>lo.dispose(A[l])),s(l2.bodies)})}var w0=Z(H());var Ae,Ot=[],yo=0,c1=Number.MAX_SAFE_INTEGER,Ct=0,Lt=2.5;async function fo(e){if(!Ae||R.initial){Ae=await O(e.object.modelPath);let t=Ae!=null&&Ae.executor?Object.values(Ae.modelSignature.inputs):void 0;Ct=Array.isArray(t)?parseInt(t[0].tensorShape.dim[2].size):416}else e.debug&&u("cached model:",Ae.modelUrl);return Ae}async function ZA(e,t,n){var c,x;let o=0,r=[],s=Ct;for(let i of[1,2,4]){let y=i*13,d=w0.squeeze(e.find(m=>m.shape[1]===y**2&&(m.shape[2]||0)===x2.length)),p=await d.array(),f=w0.squeeze(e.find(m=>m.shape[1]===y**2&&(m.shape[2]||0)(n.object.minConfidence||0)&&h!==61){let P=(.5+Math.trunc(m%y))/y,I=(.5+Math.trunc(m/y))/y,q=T[m].map(U=>U*(y/i/s)),[t0,G]=[P-Lt/i*q[0],I-Lt/i*q[1]],[$,A0]=[P+Lt/i*q[2]-t0,I+Lt/i*q[3]-G],v=[t0,G,$,A0];v=v.map(U=>Math.max(0,Math.min(U,1)));let V=[v[0]*t[0],v[1]*t[1],v[2]*t[0],v[3]*t[1]],n0={id:o++,score:Math.round(100*S)/100,class:h+1,label:x2[h].label,box:V.map(U=>Math.trunc(U)),boxRaw:v};r.push(n0)}}w0.dispose([d,f,b,M])}let A=r.map(i=>[i.boxRaw[1],i.boxRaw[0],i.boxRaw[3],i.boxRaw[2]]),a=r.map(i=>i.score),l=[];if(A&&A.length>0){let i=await w0.image.nonMaxSuppressionAsync(A,a,n.object.maxDetected||0,n.object.iouThreshold,n.object.minConfidence);l=Array.from(await i.data()),w0.dispose(i)}return r=r.filter((i,y)=>l.includes(y)).sort((i,y)=>y.score-i.score),r}async function d1(e,t){if(!(Ae!=null&&Ae.executor))return[];let n=(t.object.skipTime||0)>g()-yo,o=c1<(t.object.skipFrames||0);return t.skipAllowed&&n&&o&&Ot.length>0?(c1++,Ot):(c1=0,!R.kernels.includes("mod")||!R.kernels.includes("sparsetodense")?Ot:new Promise(async r=>{let s=[e.shape[2]||0,e.shape[1]||0],A=w0.image.resizeBilinear(e,[Ct,Ct],!1),a=w0.div(A,C.tf255),l=w0.transpose(a,[0,3,1,2]),c;t.object.enabled&&(c=Ae.execute(l)),yo=g();let x=await ZA(c,s,t);Ot=x,w0.dispose([A,a,l,...c]),r(x)}))}var D0=Z(H());var D2=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"],XA=D2.length,W2=D2.reduce((e,t,n)=>(e[t]=n,e),{}),qA=[["leftHip","leftShoulder"],["leftElbow","leftShoulder"],["leftElbow","leftWrist"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["rightHip","rightShoulder"],["rightElbow","rightShoulder"],["rightElbow","rightWrist"],["rightHip","rightKnee"],["rightKnee","rightAnkle"],["leftShoulder","rightShoulder"],["leftHip","rightHip"]],Li=qA.map(([e,t])=>[W2[e],W2[t]]),po=[["nose","leftEye"],["leftEye","leftEar"],["nose","rightEye"],["rightEye","rightEar"],["nose","leftShoulder"],["leftShoulder","leftElbow"],["leftElbow","leftWrist"],["leftShoulder","leftHip"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["nose","rightShoulder"],["rightShoulder","rightElbow"],["rightElbow","rightWrist"],["rightShoulder","rightHip"],["rightHip","rightKnee"],["rightKnee","rightAnkle"]];function uo(e){let t=e.reduce(({maxX:n,maxY:o,minX:r,minY:s},{position:{x:A,y:a}})=>({maxX:Math.max(n,A),maxY:Math.max(o,a),minX:Math.min(r,A),minY:Math.min(s,a)}),{maxX:Number.NEGATIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY,minX:Number.POSITIVE_INFINITY,minY:Number.POSITIVE_INFINITY});return[t.minX,t.minY,t.maxX-t.minX,t.maxY-t.minY]}function ho(e,[t,n],[o,r]){let s=t/o,A=n/r,a=(c,x)=>({id:x,score:c.score,boxRaw:[c.box[0]/r,c.box[1]/o,c.box[2]/r,c.box[3]/o],box:[Math.trunc(c.box[0]*A),Math.trunc(c.box[1]*s),Math.trunc(c.box[2]*A),Math.trunc(c.box[3]*s)],keypoints:c.keypoints.map(({score:i,part:y,position:d})=>({score:i,part:y,position:[Math.trunc(d.x*A),Math.trunc(d.y*s)],positionRaw:[d.x/o,d.y/o]})),annotations:{}});return e.map((c,x)=>a(c,x))}var Wt=class{constructor(t,n){k(this,"priorityQueue");k(this,"numberOfElements");k(this,"getElementValue");this.priorityQueue=new Array(t),this.numberOfElements=-1,this.getElementValue=n}enqueue(t){this.priorityQueue[++this.numberOfElements]=t,this.swim(this.numberOfElements)}dequeue(){let t=this.priorityQueue[0];return this.exchange(0,this.numberOfElements--),this.sink(0),this.priorityQueue[this.numberOfElements+1]=null,t}empty(){return this.numberOfElements===-1}size(){return this.numberOfElements+1}all(){return this.priorityQueue.slice(0,this.numberOfElements+1)}max(){return this.priorityQueue[0]}swim(t){for(;t>0&&this.less(Math.floor(t/2),t);)this.exchange(t,Math.floor(t/2)),t=Math.floor(t/2)}sink(t){for(;2*t<=this.numberOfElements;){let n=2*t;if(nn?n:e}function bo(e,t,n,o){let r=n-e,s=o-t;return r*r+s*s}function m1(e,t){return{x:e.x+t.x,y:e.y+t.y}}var K0,YA=["MobilenetV1/offset_2/BiasAdd","MobilenetV1/heatmap_2/BiasAdd","MobilenetV1/displacement_fwd_2/BiasAdd","MobilenetV1/displacement_bwd_2/BiasAdd"],Dt=1,R2=16,KA=50**2;function go(e,t,n,o,r,s,A=2){let a=M=>({y:s.get(M.y,M.x,e),x:s.get(M.y,M.x,s.shape[2]/2+e)}),l=(M,T,m)=>({y:f1(Math.round(M.y/R2),0,T-1),x:f1(Math.round(M.x/R2),0,m-1)}),[c,x]=o.shape,i=l(t.position,c,x),y=a(i),p=m1(t.position,y);for(let M=0;M[W2[y],W2[d]]),A=s.map(([,y])=>y),a=s.map(([y])=>y),l=t.shape[2],c=A.length,x=new Array(l),i=y1(e.part,R2,n);x[e.part.id]={score:e.score,part:D2[e.part.id],position:i};for(let y=c-1;y>=0;--y){let d=A[y],p=a[y];x[d]&&!x[p]&&(x[p]=go(y,x[d],p,t,n,r))}for(let y=0;yt){a=!1;break}if(!a)break}return a}function _A(e,t){let[n,o,r]=t.shape,s=new Wt(n*o*r,({score:A})=>A);for(let A=0;A{var A;let s=(A=r[o])==null?void 0:A.position;return s?bo(n,t,s.y,s.x)<=KA:!1})}function $A(e,t){return t.reduce((o,{position:r,score:s},A)=>(To(e,r,A)||(o+=s),o),0)/t.length}function ea(e,t,n,o,r,s){let A=[],a=_A(s,t);for(;A.lengthd.score>s);let i=$A(A,x),y=uo(x);i>s&&A.push({keypoints:x,box:y,score:Math.round(100*i)/100})}return A}async function p1(e,t){if(!(K0!=null&&K0.executor))return[];let n=D0.tidy(()=>{if(!K0.inputs[0].shape)return[];let A=D0.image.resizeBilinear(e,[K0.inputs[0].shape[2],K0.inputs[0].shape[1]]),a=D0.sub(D0.div(D0.cast(A,"float32"),127.5),1),c=K0.execute(a,YA).map(x=>D0.squeeze(x,[0]));return c[1]=D0.sigmoid(c[1]),c}),o=await Promise.all(n.map(A=>A.buffer()));for(let A of n)D0.dispose(A);let r=ea(o[0],o[1],o[2],o[3],t.body.maxDetected,t.body.minConfidence);return K0.inputs[0].shape?ho(r,[e.shape[1],e.shape[2]],[K0.inputs[0].shape[2],K0.inputs[0].shape[1]]):[]}async function vo(e){return!K0||R.initial?K0=await O(e.body.modelPath):e.debug&&u("cached model:",K0.modelUrl),K0}var F=Z(H());var be,ta=["fgr","pha","r1o","r2o","r3o","r4o"],b0={},h1=0;function Po(e){F.dispose([b0.r1i,b0.r2i,b0.r3i,b0.r4i,b0.downsample_ratio]),b0.r1i=F.tensor(0),b0.r2i=F.tensor(0),b0.r3i=F.tensor(0),b0.r4i=F.tensor(0),h1=e.segmentation.ratio||.5,b0.downsample_ratio=F.tensor(h1)}async function b1(e){return!be||R.initial?be=await O(e.segmentation.modelPath):e.debug&&u("cached model:",be.modelUrl),Po(e),be}var Mo=e=>F.tidy(()=>{let t=F.squeeze(e,[0]),n=F.mul(t,C.tf255);return F.cast(n,"int32")});function u1(e,t){let n=e?Mo(e):F.fill([t.shape[1]||0,t.shape[2]||0,3],255,"int32"),o=t?Mo(t):F.fill([e.shape[1]||0,e.shape[2]||0,1],255,"int32"),r=F.concat([n,o],-1);return F.dispose([n,o]),r}function na(e){return F.tidy(()=>{let t={};return t.unstack=F.unstack(e,-1),t.concat=F.concat(t.unstack,1),t.split=F.split(t.concat,4,1),t.stack=F.concat(t.split,2),t.squeeze=F.squeeze(t.stack,[0]),t.expand=F.expandDims(t.squeeze,-1),t.add=F.add(t.expand,1),t.mul=F.mul(t.add,127.5),t.cast=F.cast(t.mul,"int32"),t.tile=F.tile(t.cast,[1,1,3]),t.alpha=F.fill([t.tile.shape[0]||0,t.tile.shape[1]||0,1],255,"int32"),F.concat([t.tile,t.alpha],-1)})}async function ko(e,t){if(be||(be=await b1(t)),!(be!=null&&be.executor))return null;b0.src=F.div(e,255),h1!==t.segmentation.ratio&&Po(t);let[n,o,r,s,A,a]=await be.executeAsync(b0,ta),l;switch(t.segmentation.mode||"default"){case"default":l=u1(n,o);break;case"alpha":l=u1(null,o);break;case"foreground":l=u1(n,null);break;case"state":l=na(r);break;default:l=F.tensor(0)}return F.dispose([b0.src,n,o,b0.r1i,b0.r2i,b0.r3i,b0.r4i]),[b0.r1i,b0.r2i,b0.r3i,b0.r4i]=[r,s,A,a],l}var k0=Z(H());var N0;async function g1(e){return!N0||R.initial?N0=await O(e.segmentation.modelPath):e.debug&&u("cached model:",N0.modelUrl),N0}async function Eo(e,t){var r;if(N0||(N0=await g1(t)),!(N0!=null&&N0.executor)||!((r=N0==null?void 0:N0.inputs)!=null&&r[0].shape))return null;let n={};n.resize=k0.image.resizeBilinear(e,[N0.inputs[0].shape?N0.inputs[0].shape[1]:0,N0.inputs[0].shape?N0.inputs[0].shape[2]:0],!1),n.norm=k0.div(n.resize,C.tf255),n.res=N0.execute(n.norm),n.squeeze=k0.squeeze(n.res,[0]),n.alpha=k0.image.resizeBilinear(n.squeeze,[e.shape[1]||0,e.shape[2]||0]),n.mul=k0.mul(n.alpha,C.tf255);let o;switch(t.segmentation.mode||"default"){case"default":n.input=k0.squeeze(e),n.concat=k0.concat([n.input,n.mul],-1),o=k0.cast(n.concat,"int32");break;case"alpha":o=k0.cast(n.mul,"int32");break;default:o=k0.tensor(0)}return Object.keys(n).forEach(s=>k0.dispose(n[s])),o}function Ft(e,t,n){var c,x;if(!t||!((c=e==null?void 0:e.config)!=null&&c.validateModels))return null;let o=["const","placeholder","noop","pad","squeeze","add","sub","mul","div"],r=["biasadd","fusedbatchnormv3","matmul","switch","shape","merge","split","broadcastto"],s=[],A=[],a=t.modelUrl,l=t.executor;if((x=l==null?void 0:l.graph)!=null&&x.nodes)for(let i of Object.values(l.graph.nodes)){let y=i.op.toLowerCase();s.includes(y)||s.push(y)}else!l&&e.config.debug&&u("model not loaded",n);for(let i of s)!o.includes(i)&&!r.includes(i)&&!e.env.kernels.includes(i)&&!e.env.kernels.includes(i.replace("_",""))&&!e.env.kernels.includes(i.replace("native",""))&&!e.env.kernels.includes(i.replace("v2",""))&&A.push(i);return e.config.debug&&A.length>0&&u("model validation failed:",n,A),A.length>0?{name:n,missing:A,ops:s,url:a}:null}var F2=class{constructor(t){k(this,"instance");k(this,"models",{});this.models={},this.instance=t}stats(){let t=0,n=0,o=0;for(let s of Object.values(E0))t+=s.sizeFromManifest,n+=s.sizeLoadedWeights,o+=s.sizeDesired;let r=o>0?n/o:0;return{numLoadedModels:Object.values(E0).length,numDefinedModels:Object.keys(this.models).length,percentageLoaded:r,totalSizeFromManifest:t,totalSizeWeights:n,totalSizeLoading:o,modelStats:Object.values(E0)}}reset(){for(let t of Object.keys(this.models))this.models[t]=null}async load(t){var o,r,s,A,a,l,c,x,i,y,d,p,f,b,M,T,m,h,S,P,I,q,t0,G,$,A0,v;R.initial&&this.reset(),t&&(this.instance=t);let n={};n.blazeface=this.instance.config.face.enabled&&!this.models.blazeface?b3(this.instance.config):null,n.antispoof=this.instance.config.face.enabled&&((o=this.instance.config.face.antispoof)==null?void 0:o.enabled)&&!this.models.antispoof?Z3(this.instance.config):null,n.liveness=this.instance.config.face.enabled&&((r=this.instance.config.face.liveness)==null?void 0:r.enabled)&&!this.models.liveness?Y3(this.instance.config):null,n.faceres=this.instance.config.face.enabled&&((s=this.instance.config.face.description)==null?void 0:s.enabled)&&!this.models.faceres?F3(this.instance.config):null,n.emotion=this.instance.config.face.enabled&&((A=this.instance.config.face.emotion)==null?void 0:A.enabled)&&!this.models.emotion?L3(this.instance.config):null,n.iris=this.instance.config.face.enabled&&((a=this.instance.config.face.iris)==null?void 0:a.enabled)&&!((l=this.instance.config.face.attention)!=null&&l.enabled)&&!this.models.iris?P3(this.instance.config):null,n.facemesh=this.instance.config.face.enabled&&((c=this.instance.config.face.mesh)==null?void 0:c.enabled)&&!this.models.facemesh?S3(this.instance.config):null,n.gear=this.instance.config.face.enabled&&((x=this.instance.config.face.gear)==null?void 0:x.enabled)&&!this.models.gear?_3(this.instance.config):null,n.ssrnetage=this.instance.config.face.enabled&&((i=this.instance.config.face.ssrnet)==null?void 0:i.enabled)&&!this.models.ssrnetage?nn(this.instance.config):null,n.ssrnetgender=this.instance.config.face.enabled&&((y=this.instance.config.face.ssrnet)==null?void 0:y.enabled)&&!this.models.ssrnetgender?An(this.instance.config):null,n.mobilefacenet=this.instance.config.face.enabled&&((d=this.instance.config.face.mobilefacenet)==null?void 0:d.enabled)&&!this.models.mobilefacenet?xn(this.instance.config):null,n.insightface=this.instance.config.face.enabled&&((p=this.instance.config.face.insightface)==null?void 0:p.enabled)&&!this.models.insightface?un(this.instance.config):null,n.blazepose=this.instance.config.body.enabled&&!this.models.blazepose&&((f=this.instance.config.body.modelPath)==null?void 0:f.includes("blazepose"))?t3(this.instance.config):null,n.blazeposedetect=this.instance.config.body.enabled&&!this.models.blazeposedetect&&this.instance.config.body.detector&&this.instance.config.body.detector.modelPath?e3(this.instance.config):null,n.efficientpose=this.instance.config.body.enabled&&!this.models.efficientpose&&((b=this.instance.config.body.modelPath)==null?void 0:b.includes("efficientpose"))?a3(this.instance.config):null,n.movenet=this.instance.config.body.enabled&&!this.models.movenet&&((M=this.instance.config.body.modelPath)==null?void 0:M.includes("movenet"))?co(this.instance.config):null,n.posenet=this.instance.config.body.enabled&&!this.models.posenet&&((T=this.instance.config.body.modelPath)==null?void 0:T.includes("posenet"))?vo(this.instance.config):null,n.handtrack=this.instance.config.hand.enabled&&!this.models.handtrack&&((h=(m=this.instance.config.hand.detector)==null?void 0:m.modelPath)==null?void 0:h.includes("handtrack"))?_n(this.instance.config):null,n.handskeleton=this.instance.config.hand.enabled&&this.instance.config.hand.landmarks&&!this.models.handskeleton&&((P=(S=this.instance.config.hand.detector)==null?void 0:S.modelPath)==null?void 0:P.includes("handtrack"))?$n(this.instance.config):null,(q=(I=this.instance.config.hand.detector)==null?void 0:I.modelPath)!=null&&q.includes("handdetect")&&([n.handpose,n.handskeleton]=this.models.handpose?[null,null]:await Un(this.instance.config)),n.centernet=this.instance.config.object.enabled&&!this.models.centernet&&((t0=this.instance.config.object.modelPath)==null?void 0:t0.includes("centernet"))?r3(this.instance.config):null,n.nanodet=this.instance.config.object.enabled&&!this.models.nanodet&&((G=this.instance.config.object.modelPath)==null?void 0:G.includes("nanodet"))?fo(this.instance.config):null,n.selfie=this.instance.config.segmentation.enabled&&!this.models.selfie&&(($=this.instance.config.segmentation.modelPath)==null?void 0:$.includes("selfie"))?g1(this.instance.config):null,n.meet=this.instance.config.segmentation.enabled&&!this.models.meet&&((A0=this.instance.config.segmentation.modelPath)==null?void 0:A0.includes("meet"))?s1(this.instance.config):null,n.rvm=this.instance.config.segmentation.enabled&&!this.models.rvm&&((v=this.instance.config.segmentation.modelPath)==null?void 0:v.includes("rvm"))?b1(this.instance.config):null;for(let[V,n0]of Object.entries(n))n0!=null&&n0.then&&n0.then(U=>this.models[V]=U);await Promise.all(Object.values(n))}list(){let t=Object.keys(this.models).map(n=>{var o;return{name:n,loaded:this.models[n]!==null,size:0,url:this.models[n]?(o=this.models[n])==null?void 0:o.modelUrl:null}});for(let n of t){let o=Object.keys(E0).find(r=>r.startsWith(n.name));!o||(n.size=E0[o].sizeLoadedWeights,n.url=E0[o].url)}return t}loaded(){return this.list().filter(o=>o.loaded).map(o=>o.name)}validate(){let t=[];for(let n of Object.keys(this.models)){let o=this.models[n];if(!o)continue;let r=Ft(this.instance,o,n);r&&t.push(r)}return t}};function So(e,t,n,o,r){var a,l,c,x,i,y;let s=0,A=[];for(let d of e){let p={id:s++,face:d,body:null,hands:{left:null,right:null},gestures:[],box:[0,0,0,0]};for(let h of t)d.box[0]>h.box[0]&&d.box[0]h.box[1]&&d.box[1]+d.box[3]p.body.box[0]&&h.box[0]+h.box[2]p.body.box[1]&&h.box[1]+h.box[3]p.body.box[0]&&h.box[1]+h.box[3]>p.body.box[1]&&h.box[1]+h.box[3]{h&&h.length===4&&(f.push(h[0],h[0]+h[2]),b.push(h[1],h[1]+h[3]))};M(p.face.box),M((x=p.body)==null?void 0:x.box),M((i=p.hands.left)==null?void 0:i.box),M((y=p.hands.right)==null?void 0:y.box);let T=Math.min(...f),m=Math.min(...b);p.box=[T,m,Math.max(...f)-T,Math.max(...b)-m],(r==null?void 0:r[1])&&(r==null?void 0:r[2])&&(p.boxRaw=[p.box[0]/r[2],p.box[1]/r[1],p.box[2]/r[2],p.box[3]/r[1]]),A.push(p)}return A}var d0=Z(H());var Bt=` /9j/4AAQSkZJRgABAQEAYABgAAD/4QBoRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUA AAABAAAARgEoAAMAAAABAAIAAAExAAIAAAARAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQu bmV0IDQuMi4xMwAA/9sAQwAGBAUGBQQGBgUGBwcGCAoQCgoJCQoUDg8MEBcUGBgXFBYWGh0lHxob @@ -14134,8 +269,7 @@ PQ4GJ+ashuK0MhWaoWcA0AaOmASMK7jRNPWYBmHyiuepO2x10qfcv6vYxCzYqoGK4HVYVTJrmb5l c6oaM5TUJ8EgGsG4kLNUHT0M64OaqMMikSRsuKbnFMRLG3zVehOaGNE445NNlnVFpDMu6uie9Vo1 8z5mOAOST2pDK91cNN+5tsrH3PrW54a06KxT7fdrlh/q1Pc+tJ6IUdZGvHPLezMcnBOWbsPap5r3 ylFtbdT1xUWNWzU0/Zbwlgfmx8zGsHWtRHmMqE59aAMyNifvHPc1f0gtPdqkY5JosJHeNci2tktY -euPnNY+oXWZEVJNrZ9aun8SIq/CzodHuriIokhDIR1ronbKZr0o6o8ipoz//2Q==`; -var body3 = ` +euPnNY+oXWZEVJNrZ9aun8SIq/CzodHuriIokhDIR1ronbKZr0o6o8ipoz//2Q==`,Ht=` /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAsICAoIBwsKCQoNDAsNERwSEQ8PESIZGhQcKSQrKigk JyctMkA3LTA9MCcnOEw5PUNFSElIKzZPVU5GVEBHSEX/2wBDAQwNDREPESESEiFFLicuRUVFRUVF RUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUX/wAARCASwBLADASIA @@ -14703,563 +837,4 @@ AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp+bfwab+vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2 SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD/ -2Q==`; - -// src/warmup.ts -async function warmupBitmap(instance) { - const b64toBlob = (base64, type = "application/octet-stream") => fetch(`data:${type};base64,${base64}`).then((res2) => res2.blob()); - let blob; - let res; - switch (instance.config.warmup) { - case "face": - blob = await b64toBlob(face3); - break; - case "body": - case "full": - blob = await b64toBlob(body3); - break; - default: - blob = null; - } - if (blob) { - const bitmap = await createImageBitmap(blob); - res = await instance.detect(bitmap, instance.config); - bitmap.close(); - } - return res; -} -async function warmupCanvas(instance) { - return new Promise((resolve) => { - let src; - switch (instance.config.warmup) { - case "face": - src = "data:image/jpeg;base64," + face3; - break; - case "full": - case "body": - src = "data:image/jpeg;base64," + body3; - break; - default: - src = ""; - } - let img; - if (typeof Image !== "undefined") - img = new Image(); - else if (env.Image) - img = new env.Image(); - else { - resolve(void 0); - return; - } - img.onload = async () => { - const canvas3 = canvas(img.naturalWidth, img.naturalHeight); - if (!canvas3) { - log("Warmup: Canvas not found"); - resolve(void 0); - } else { - const ctx = canvas3.getContext("2d"); - if (ctx) - ctx.drawImage(img, 0, 0); - const tensor6 = await instance.image(canvas3, true); - const res = tensor6.tensor ? await instance.detect(tensor6.tensor, instance.config) : void 0; - resolve(res); - } - }; - if (src) - img.src = src; - else - resolve(void 0); - }); -} -async function warmupNode(instance) { - const atob = (str) => Buffer.from(str, "base64"); - let img; - if (instance.config.warmup === "face") - img = atob(face3); - else - img = atob(body3); - let res; - if ("node" in tf37 && tf37.getBackend() === "tensorflow") { - const data = tf37["node"].decodeJpeg(img); - const expanded = tf37.expandDims(data, 0); - instance.tf.dispose(data); - res = await instance.detect(expanded, instance.config); - instance.tf.dispose(expanded); - } else { - if (instance.config.debug) - log("Warmup tfjs-node not loaded"); - } - return res; -} -async function runInference(instance) { - let res; - if (typeof createImageBitmap === "function") - res = await warmupBitmap(instance); - else if (typeof Image !== "undefined" || env.Canvas !== void 0) - res = await warmupCanvas(instance); - else - res = await warmupNode(instance); - return res; -} -async function runCompile(instance) { - var _a, _b, _c, _d; - if (!tf37.env().flagRegistry.ENGINE_COMPILE_ONLY) - return; - const backendType = tf37.getBackend(); - const webGLBackend = tf37.backend(); - if (backendType !== "webgl" && backendType !== "humangl" || !(webGLBackend == null ? void 0 : webGLBackend["checkCompileCompletion"])) { - return; - } - tf37.env().set("ENGINE_COMPILE_ONLY", true); - const numTensorsStart = tf37.engine().state.numTensors; - const compiledModels = []; - for (const [modelName, model23] of Object.entries(instance.models.models)) { - if (!model23) - continue; - const shape = (model23 == null ? void 0 : model23.modelSignature) && ((_b = (_a = model23 == null ? void 0 : model23.inputs) == null ? void 0 : _a[0]) == null ? void 0 : _b.shape) ? [...model23.inputs[0].shape] : [1, 64, 64, 3]; - const dtype = (model23 == null ? void 0 : model23.modelSignature) && ((_d = (_c = model23 == null ? void 0 : model23.inputs) == null ? void 0 : _c[0]) == null ? void 0 : _d.dtype) ? model23.inputs[0].dtype : "float32"; - for (let dim = 0; dim < shape.length; dim++) { - if (shape[dim] === -1) - shape[dim] = dim === 0 ? 1 : 64; - } - const tensor6 = tf37.zeros(shape, dtype); - try { - const res = model23.execute(tensor6); - compiledModels.push(modelName); - if (Array.isArray(res)) - res.forEach((t2) => tf37.dispose(t2)); - else - tf37.dispose(res); - } catch (e) { - if (instance.config.debug) - log("compile fail model:", modelName); - } - tf37.dispose(tensor6); - } - const kernels = await webGLBackend["checkCompileCompletionAsync"](); - webGLBackend["getUniformLocations"](); - if (instance.config.debug) - log("compile pass:", { models: compiledModels, kernels: kernels.length }); - tf37.env().set("ENGINE_COMPILE_ONLY", false); - const numTensorsEnd = tf37.engine().state.numTensors; - if (numTensorsEnd - numTensorsStart > 0) - log("tensor leak:", numTensorsEnd - numTensorsStart); -} -async function warmup(instance, userConfig) { - await check(instance, false); - const t0 = now(); - instance.state = "warmup"; - if (userConfig) - instance.config = mergeDeep(instance.config, userConfig); - if (!instance.config.warmup || instance.config.warmup.length === 0 || instance.config.warmup === "none") { - return empty(); - } - return new Promise(async (resolve) => { - await instance.models.load(); - await runCompile(instance); - const res = await runInference(instance); - const t1 = now(); - if (instance.config.debug) - log("warmup", instance.config.warmup, Math.round(t1 - t0), "ms"); - instance.emit("warmup"); - resolve(res); - }); -} - -// src/human.ts -var _numTensors, _analyzeMemoryLeaks, _checkSanity, _sanity, _loops; -var Human = class { - constructor(userConfig) { - __publicField(this, "version"); - __publicField(this, "config"); - __publicField(this, "result"); - __publicField(this, "state"); - __publicField(this, "process"); - __publicField(this, "tf"); - __publicField(this, "env", env); - __publicField(this, "draw", draw_exports); - __publicField(this, "match", match_exports); - __publicField(this, "models"); - __publicField(this, "events"); - __publicField(this, "faceTriangulation"); - __publicField(this, "faceUVMap"); - __publicField(this, "performance"); - __privateAdd(this, _numTensors, void 0); - __privateAdd(this, _analyzeMemoryLeaks, void 0); - __privateAdd(this, _checkSanity, void 0); - __publicField(this, "analyze", (...msg) => { - if (!__privateGet(this, _analyzeMemoryLeaks)) - return; - const currentTensors = this.tf.engine().state.numTensors; - const previousTensors = __privateGet(this, _numTensors); - __privateSet(this, _numTensors, currentTensors); - const leaked = currentTensors - previousTensors; - if (leaked !== 0) - log(...msg, leaked); - }); - __privateAdd(this, _sanity, (input) => { - if (!__privateGet(this, _checkSanity)) - return null; - if (!input) - return "input is not defined"; - if (this.env.node && !(input instanceof tf38.Tensor)) - return "input must be a tensor"; - try { - this.tf.getBackend(); - } catch (e) { - return "backend not loaded"; - } - return null; - }); - __publicField(this, "webcam", new WebCam()); - __publicField(this, "emit", (event) => { - var _a; - if ((_a = this.events) == null ? void 0 : _a.dispatchEvent) - this.events.dispatchEvent(new Event(event)); - }); - __privateAdd(this, _loops, {}); - const tfVersion = (tf38.version.tfjs || tf38.version_core).replace(/-(.*)/, ""); - config.wasmPath = `https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${tfVersion}/dist/`; - config.modelBasePath = env.browser ? "../models/" : "file://models/"; - this.version = version2; - Object.defineProperty(this, "version", { value: version2 }); - this.config = JSON.parse(JSON.stringify(config)); - Object.seal(this.config); - this.config.cacheModels = typeof indexedDB !== "undefined"; - if (userConfig) - this.config = mergeDeep(this.config, userConfig); - setModelLoadOptions(this.config); - this.tf = tf38; - this.state = "idle"; - __privateSet(this, _numTensors, 0); - __privateSet(this, _analyzeMemoryLeaks, false); - __privateSet(this, _checkSanity, false); - this.performance = {}; - this.events = typeof EventTarget !== "undefined" ? new EventTarget() : void 0; - this.models = new Models(this); - init2(); - this.result = empty(); - this.process = { tensor: null, canvas: null }; - this.faceTriangulation = triangulation; - this.faceUVMap = uvmap; - validateModel(this, null, ""); - this.emit("create"); - if (this.config.debug || this.env.browser) - log(`version: ${this.version}`); - if (this.config.debug) - log(`tfjs version: ${this.tf.version["tfjs-core"]}`); - const envTemp = JSON.parse(JSON.stringify(this.env)); - delete envTemp.kernels; - delete envTemp.initial; - delete envTemp.perfadd; - if (this.config.debug) - log("environment:", envTemp); - } - reset() { - const currentBackend = this.config.backend; - this.config = JSON.parse(JSON.stringify(config)); - this.config.backend = currentBackend; - reset(); - env.initial = true; - } - validate(userConfig) { - const msgs = validate(config, userConfig || this.config); - if (msgs.length === 0) - this.config = mergeDeep(this.config, userConfig); - return msgs; - } - now() { - return now(); - } - image(input, getTensor = false) { - return process2(input, this.config, getTensor); - } - async segmentation(input, userConfig) { - var _a, _b, _c; - if (userConfig) - this.config = mergeDeep(this.config, userConfig); - if (!this.config.segmentation.enabled) - return null; - const processed = await process2(input, this.config); - if (!processed.tensor) - return null; - let tensor6 = null; - if ((_a = this.config.segmentation.modelPath) == null ? void 0 : _a.includes("rvm")) - tensor6 = await predict20(processed.tensor, this.config); - if ((_b = this.config.segmentation.modelPath) == null ? void 0 : _b.includes("meet")) - tensor6 = await predict16(processed.tensor, this.config); - if ((_c = this.config.segmentation.modelPath) == null ? void 0 : _c.includes("selfie")) - tensor6 = await predict21(processed.tensor, this.config); - tf38.dispose(processed.tensor); - return tensor6; - } - compare(firstImageTensor, secondImageTensor) { - return compare(this.config, firstImageTensor, secondImageTensor); - } - async init() { - await check(this, true); - await this.tf.ready(); - reset(); - } - async load(userConfig) { - this.state = "load"; - const timeStamp = now(); - const count2 = Object.values(this.models.models).filter((model23) => model23).length; - if (userConfig) - this.config = mergeDeep(this.config, userConfig); - if (this.env.initial) { - if (!await check(this, false)) - log("error: backend check failed"); - await tf38.ready(); - if (this.env.browser) { - if (this.config.debug) - log("configuration:", this.config); - if (this.config.debug) - log("tf flags:", this.tf.ENV.flags); - } - } - await this.models.load(this); - if (this.env.initial && this.config.debug) - log("tf engine state:", this.tf.engine().state.numBytes, "bytes", this.tf.engine().state.numTensors, "tensors"); - this.env.initial = false; - const loaded = Object.values(this.models.models).filter((model23) => model23).length; - if (loaded !== count2) { - this.models.validate(); - this.emit("load"); - } - const current = Math.trunc(now() - timeStamp); - if (current > (this.performance.loadModels || 0)) - this.performance.loadModels = this.env.perfadd ? (this.performance.loadModels || 0) + current : current; - } - next(result = this.result) { - return calc2(result, this.config); - } - async warmup(userConfig) { - const t0 = now(); - const res = await warmup(this, userConfig); - const t1 = now(); - this.performance.warmup = Math.trunc(t1 - t0); - return res; - } - async profile(input, userConfig) { - const profile = await this.tf.profile(() => this.detect(input, userConfig)); - const kernels = {}; - let total = 0; - for (const kernel of profile.kernels) { - const ms = Number(kernel.kernelTimeMs) || 0; - if (kernels[kernel.name]) - kernels[kernel.name] += ms; - else - kernels[kernel.name] = ms; - total += ms; - } - const kernelArr = []; - Object.entries(kernels).forEach((key) => kernelArr.push({ kernel: key[0], time: key[1], perc: 0 })); - for (const kernel of kernelArr) { - kernel.perc = Math.round(1e3 * kernel.time / total) / 1e3; - kernel.time = Math.round(1e3 * kernel.time) / 1e3; - } - kernelArr.sort((a, b) => b.time - a.time); - kernelArr.length = 20; - return kernelArr; - } - async detect(input, userConfig) { - this.state = "detect"; - return new Promise(async (resolve) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u; - this.state = "config"; - let timeStamp; - this.config = mergeDeep(this.config, userConfig); - this.state = "check"; - const error = __privateGet(this, _sanity).call(this, input); - if (error) { - log(error, input); - this.emit("error"); - resolve(empty(error)); - } - const timeStart = now(); - await this.load(); - timeStamp = now(); - this.state = "image"; - const img = await process2(input, this.config); - this.process = img; - this.performance.inputProcess = this.env.perfadd ? (this.performance.inputProcess || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - this.analyze("Get Image:"); - if (!img.tensor) { - if (this.config.debug) - log("could not convert input to tensor"); - this.emit("error"); - resolve(empty("could not convert input to tensor")); - return; - } - this.emit("image"); - timeStamp = now(); - this.config.skipAllowed = await skip(this.config, img.tensor); - this.config.filter.autoBrightness = (this.config.filter.autoBrightness || false) && this.config.skipAllowed; - if (!this.performance.totalFrames) - this.performance.totalFrames = 0; - if (!this.performance.cachedFrames) - this.performance.cachedFrames = 0; - this.performance.totalFrames++; - if (this.config.skipAllowed) - this.performance.cachedFrames++; - this.performance.cacheCheck = this.env.perfadd ? (this.performance.cacheCheck || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - this.analyze("Check Changed:"); - let faceRes = []; - let bodyRes = []; - let handRes = []; - let objectRes = []; - this.state = "detect:face"; - if (this.config.async) { - faceRes = this.config.face.enabled ? detectFace(this, img.tensor) : []; - if (this.performance.face) - delete this.performance.face; - } else { - timeStamp = now(); - faceRes = this.config.face.enabled ? await detectFace(this, img.tensor) : []; - this.performance.face = this.env.perfadd ? (this.performance.face || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - if (this.config.async && (this.config.body.maxDetected === -1 || this.config.hand.maxDetected === -1)) - faceRes = await faceRes; - this.analyze("Start Body:"); - this.state = "detect:body"; - const bodyConfig = this.config.body.maxDetected === -1 ? mergeDeep(this.config, { body: { maxDetected: this.config.face.enabled ? 1 * faceRes.length : 1 } }) : this.config; - if (this.config.async) { - if ((_a = this.config.body.modelPath) == null ? void 0 : _a.includes("posenet")) - bodyRes = this.config.body.enabled ? predict19(img.tensor, bodyConfig) : []; - else if ((_b = this.config.body.modelPath) == null ? void 0 : _b.includes("blazepose")) - bodyRes = this.config.body.enabled ? predict(img.tensor, bodyConfig) : []; - else if ((_c = this.config.body.modelPath) == null ? void 0 : _c.includes("efficientpose")) - bodyRes = this.config.body.enabled ? predict3(img.tensor, bodyConfig) : []; - else if ((_d = this.config.body.modelPath) == null ? void 0 : _d.includes("movenet")) - bodyRes = this.config.body.enabled ? predict17(img.tensor, bodyConfig) : []; - if (this.performance.body) - delete this.performance.body; - } else { - timeStamp = now(); - if ((_e = this.config.body.modelPath) == null ? void 0 : _e.includes("posenet")) - bodyRes = this.config.body.enabled ? await predict19(img.tensor, bodyConfig) : []; - else if ((_f = this.config.body.modelPath) == null ? void 0 : _f.includes("blazepose")) - bodyRes = this.config.body.enabled ? await predict(img.tensor, bodyConfig) : []; - else if ((_g = this.config.body.modelPath) == null ? void 0 : _g.includes("efficientpose")) - bodyRes = this.config.body.enabled ? await predict3(img.tensor, bodyConfig) : []; - else if ((_h = this.config.body.modelPath) == null ? void 0 : _h.includes("movenet")) - bodyRes = this.config.body.enabled ? await predict17(img.tensor, bodyConfig) : []; - this.performance.body = this.env.perfadd ? (this.performance.body || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - this.analyze("End Body:"); - this.analyze("Start Hand:"); - this.state = "detect:hand"; - const handConfig = this.config.hand.maxDetected === -1 ? mergeDeep(this.config, { hand: { maxDetected: this.config.face.enabled ? 2 * faceRes.length : 1 } }) : this.config; - if (this.config.async) { - if ((_j = (_i = this.config.hand.detector) == null ? void 0 : _i.modelPath) == null ? void 0 : _j.includes("handdetect")) - handRes = this.config.hand.enabled ? predict14(img.tensor, handConfig) : []; - else if ((_l = (_k = this.config.hand.detector) == null ? void 0 : _k.modelPath) == null ? void 0 : _l.includes("handtrack")) - handRes = this.config.hand.enabled ? predict15(img.tensor, handConfig) : []; - if (this.performance.hand) - delete this.performance.hand; - } else { - timeStamp = now(); - if ((_n = (_m = this.config.hand.detector) == null ? void 0 : _m.modelPath) == null ? void 0 : _n.includes("handdetect")) - handRes = this.config.hand.enabled ? await predict14(img.tensor, handConfig) : []; - else if ((_p = (_o = this.config.hand.detector) == null ? void 0 : _o.modelPath) == null ? void 0 : _p.includes("handtrack")) - handRes = this.config.hand.enabled ? await predict15(img.tensor, handConfig) : []; - this.performance.hand = this.env.perfadd ? (this.performance.hand || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - this.analyze("End Hand:"); - this.analyze("Start Object:"); - this.state = "detect:object"; - if (this.config.async) { - if ((_q = this.config.object.modelPath) == null ? void 0 : _q.includes("nanodet")) - objectRes = this.config.object.enabled ? predict18(img.tensor, this.config) : []; - else if ((_r = this.config.object.modelPath) == null ? void 0 : _r.includes("centernet")) - objectRes = this.config.object.enabled ? predict2(img.tensor, this.config) : []; - if (this.performance.object) - delete this.performance.object; - } else { - timeStamp = now(); - if ((_s = this.config.object.modelPath) == null ? void 0 : _s.includes("nanodet")) - objectRes = this.config.object.enabled ? await predict18(img.tensor, this.config) : []; - else if ((_t = this.config.object.modelPath) == null ? void 0 : _t.includes("centernet")) - objectRes = this.config.object.enabled ? await predict2(img.tensor, this.config) : []; - this.performance.object = this.env.perfadd ? (this.performance.object || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - } - this.analyze("End Object:"); - this.state = "detect:await"; - if (this.config.async) - [faceRes, bodyRes, handRes, objectRes] = await Promise.all([faceRes, bodyRes, handRes, objectRes]); - this.state = "detect:gesture"; - let gestureRes = []; - if (this.config.gesture.enabled) { - timeStamp = now(); - gestureRes = [...face2(faceRes), ...body2(bodyRes), ...hand2(handRes), ...iris2(faceRes)]; - if (!this.config.async) - this.performance.gesture = this.env.perfadd ? (this.performance.gesture || 0) + Math.trunc(now() - timeStamp) : Math.trunc(now() - timeStamp); - else if (this.performance.gesture) - delete this.performance.gesture; - } - this.performance.total = this.env.perfadd ? (this.performance.total || 0) + Math.trunc(now() - timeStart) : Math.trunc(now() - timeStart); - const shape = ((_u = this.process.tensor) == null ? void 0 : _u.shape) || [0, 0, 0, 0]; - this.result = { - face: faceRes, - body: bodyRes, - hand: handRes, - gesture: gestureRes, - object: objectRes, - performance: this.performance, - canvas: this.process.canvas, - timestamp: Date.now(), - error: null, - width: shape[2], - height: shape[1], - get persons() { - return join2(faceRes, bodyRes, handRes, gestureRes, shape); - } - }; - tf38.dispose(img.tensor); - this.emit("detect"); - this.state = "idle"; - resolve(this.result); - }); - } - async sleep(ms) { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); - } - async video(element, run = true, delay = 0) { - if (run) { - if (!__privateGet(this, _loops)[element.id]) { - if (this.config.debug) - log("video start", element.id); - __privateGet(this, _loops)[element.id] = true; - } - if (!element.paused && __privateGet(this, _loops)[element.id] && element.readyState >= 2) - await this.detect(element); - if (delay > 0) - await this.sleep(delay); - if (__privateGet(this, _loops)[element.id]) - requestAnimationFrame(() => this.video(element, run, delay)); - } else { - if (this.config.debug) - log("video stop", element.id); - __privateGet(this, _loops)[element.id] = false; - } - } -}; -_numTensors = new WeakMap(); -_analyzeMemoryLeaks = new WeakMap(); -_checkSanity = new WeakMap(); -_sanity = new WeakMap(); -_loops = new WeakMap(); -// Annotate the CommonJS export names for ESM import in node: -0 && (module.exports = { - Env, - Human, - defaults, - draw, - empty, - env, - match, - models -}); +2Q==`;async function sa(e){let t=(r,s="application/octet-stream")=>fetch(`data:${s};base64,${r}`).then(A=>A.blob()),n,o;switch(e.config.warmup){case"face":n=await t(Bt);break;case"body":case"full":n=await t(Ht);break;default:n=null}if(n){let r=await createImageBitmap(n);o=await e.detect(r,e.config),r.close()}return o}async function Aa(e){return new Promise(t=>{let n;switch(e.config.warmup){case"face":n="data:image/jpeg;base64,"+Bt;break;case"full":case"body":n="data:image/jpeg;base64,"+Ht;break;default:n=""}let o;if(typeof Image!="undefined")o=new Image;else if(R.Image)o=new R.Image;else{t(void 0);return}o.onload=async()=>{let r=te(o.naturalWidth,o.naturalHeight);if(!r)u("Warmup: Canvas not found"),t(void 0);else{let s=r.getContext("2d");s&&s.drawImage(o,0,0);let A=await e.image(r,!0),a=A.tensor?await e.detect(A.tensor,e.config):void 0;t(a)}},n?o.src=n:t(void 0)})}async function aa(e){let t=r=>Buffer.from(r,"base64"),n;e.config.warmup==="face"?n=t(Bt):n=t(Ht);let o;if("node"in d0&&d0.getBackend()==="tensorflow"){let r=d0.node.decodeJpeg(n),s=d0.expandDims(r,0);e.tf.dispose(r),o=await e.detect(s,e.config),e.tf.dispose(s)}else e.config.debug&&u("Warmup tfjs-node not loaded");return o}async function ia(e){let t;return typeof createImageBitmap=="function"?t=await sa(e):typeof Image!="undefined"||R.Canvas!==void 0?t=await Aa(e):t=await aa(e),t}async function la(e){var a,l,c,x;if(!d0.env().flagRegistry.ENGINE_COMPILE_ONLY)return;let t=d0.getBackend(),n=d0.backend();if(t!=="webgl"&&t!=="humangl"||!(n!=null&&n.checkCompileCompletion))return;d0.env().set("ENGINE_COMPILE_ONLY",!0);let o=d0.engine().state.numTensors,r=[];for(let[i,y]of Object.entries(e.models.models)){if(!y)continue;let d=(y==null?void 0:y.modelSignature)&&((l=(a=y==null?void 0:y.inputs)==null?void 0:a[0])==null?void 0:l.shape)?[...y.inputs[0].shape]:[1,64,64,3],p=(y==null?void 0:y.modelSignature)&&((x=(c=y==null?void 0:y.inputs)==null?void 0:c[0])==null?void 0:x.dtype)?y.inputs[0].dtype:"float32";for(let b=0;bd0.dispose(M)):d0.dispose(b)}catch(b){e.config.debug&&u("compile fail model:",i)}d0.dispose(f)}let s=await n.checkCompileCompletionAsync();n.getUniformLocations(),e.config.debug&&u("compile pass:",{models:r,kernels:s.length}),d0.env().set("ENGINE_COMPILE_ONLY",!1);let A=d0.engine().state.numTensors;A-o>0&&u("tensor leak:",A-o)}async function jo(e,t){await j2(e,!1);let n=g();return e.state="warmup",t&&(e.config=a0(e.config,t)),!e.config.warmup||e.config.warmup.length===0||e.config.warmup==="none"?he():new Promise(async o=>{await e.models.load(),await la(e);let r=await ia(e),s=g();e.config.debug&&u("warmup",e.config.warmup,Math.round(s-n),"ms"),e.emit("warmup"),o(r)})}var M2,B2,H2,Gt,Ue,v1=class{constructor(t){k(this,"version");k(this,"config");k(this,"result");k(this,"state");k(this,"process");k(this,"tf");k(this,"env",R);k(this,"draw",et);k(this,"match",Nt);k(this,"models");k(this,"events");k(this,"faceTriangulation");k(this,"faceUVMap");k(this,"performance");me(this,M2,void 0);me(this,B2,void 0);me(this,H2,void 0);k(this,"analyze",(...t)=>{if(!G0(this,B2))return;let n=this.tf.engine().state.numTensors,o=G0(this,M2);ge(this,M2,n);let r=n-o;r!==0&&u(...t,r)});me(this,Gt,t=>{if(!G0(this,H2))return null;if(!t)return"input is not defined";if(this.env.node&&!(t instanceof ae.Tensor))return"input must be a tensor";try{this.tf.getBackend()}catch(n){return"backend not loaded"}return null});k(this,"webcam",new U2);k(this,"emit",t=>{var n;(n=this.events)!=null&&n.dispatchEvent&&this.events.dispatchEvent(new Event(t))});me(this,Ue,{});let n=(ae.version.tfjs||ae.version_core).replace(/-(.*)/,"");Ye.wasmPath=`https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${n}/dist/`,Ye.modelBasePath=R.browser?"../models/":"file://models/",this.version=_t,Object.defineProperty(this,"version",{value:_t}),this.config=JSON.parse(JSON.stringify(Ye)),Object.seal(this.config),this.config.cacheModels=typeof indexedDB!="undefined",t&&(this.config=a0(this.config,t)),F1(this.config),this.tf=ae,this.state="idle",ge(this,M2,0),ge(this,B2,!1),ge(this,H2,!1),this.performance={},this.events=typeof EventTarget!="undefined"?new EventTarget:void 0,this.models=new F2(this),s5(),this.result=he(),this.process={tensor:null,canvas:null},this.faceTriangulation=j3,this.faceUVMap=N3,Ft(this,null,""),this.emit("create"),(this.config.debug||this.env.browser)&&u(`version: ${this.version}`),this.config.debug&&u(`tfjs version: ${this.tf.version["tfjs-core"]}`);let o=JSON.parse(JSON.stringify(this.env));delete o.kernels,delete o.initial,delete o.perfadd,this.config.debug&&u("environment:",o)}reset(){let t=this.config.backend;this.config=JSON.parse(JSON.stringify(Ye)),this.config.backend=t,Jt(),R.initial=!0}validate(t){let n=Ut(Ye,t||this.config);return n.length===0&&(this.config=a0(this.config,t)),n}now(){return g()}image(t,n=!1){return X2(t,this.config,n)}async segmentation(t,n){var s,A,a;if(n&&(this.config=a0(this.config,n)),!this.config.segmentation.enabled)return null;let o=await X2(t,this.config);if(!o.tensor)return null;let r=null;return(s=this.config.segmentation.modelPath)!=null&&s.includes("rvm")&&(r=await ko(o.tensor,this.config)),(A=this.config.segmentation.modelPath)!=null&&A.includes("meet")&&(r=await no(o.tensor,this.config)),(a=this.config.segmentation.modelPath)!=null&&a.includes("selfie")&&(r=await Eo(o.tensor,this.config)),ae.dispose(o.tensor),r}compare(t,n){return D1(this.config,t,n)}async init(){await j2(this,!0),await this.tf.ready(),Jt()}async load(t){this.state="load";let n=g(),o=Object.values(this.models.models).filter(A=>A).length;t&&(this.config=a0(this.config,t)),this.env.initial&&(await j2(this,!1)||u("error: backend check failed"),await ae.ready(),this.env.browser&&(this.config.debug&&u("configuration:",this.config),this.config.debug&&u("tf flags:",this.tf.ENV.flags))),await this.models.load(this),this.env.initial&&this.config.debug&&u("tf engine state:",this.tf.engine().state.numBytes,"bytes",this.tf.engine().state.numTensors,"tensors"),this.env.initial=!1,Object.values(this.models.models).filter(A=>A).length!==o&&(this.models.validate(),this.emit("load"));let s=Math.trunc(g()-n);s>(this.performance.loadModels||0)&&(this.performance.loadModels=this.env.perfadd?(this.performance.loadModels||0)+s:s)}next(t=this.result){return to(t,this.config)}async warmup(t){let n=g(),o=await jo(this,t),r=g();return this.performance.warmup=Math.trunc(r-n),o}async profile(t,n){let o=await this.tf.profile(()=>this.detect(t,n)),r={},s=0;for(let a of o.kernels){let l=Number(a.kernelTimeMs)||0;r[a.name]?r[a.name]+=l:r[a.name]=l,s+=l}let A=[];Object.entries(r).forEach(a=>A.push({kernel:a[0],time:a[1],perc:0}));for(let a of A)a.perc=Math.round(1e3*a.time/s)/1e3,a.time=Math.round(1e3*a.time)/1e3;return A.sort((a,l)=>l.time-a.time),A.length=20,A}async detect(t,n){return this.state="detect",new Promise(async o=>{var b,M,T,m,h,S,P,I,q,t0,G,$,A0,v,V,n0,U,g0,m0,B,X;this.state="config";let r;this.config=a0(this.config,n),this.state="check";let s=G0(this,Gt).call(this,t);s&&(u(s,t),this.emit("error"),o(he(s)));let A=g();await this.load(),r=g(),this.state="image";let a=await X2(t,this.config);if(this.process=a,this.performance.inputProcess=this.env.perfadd?(this.performance.inputProcess||0)+Math.trunc(g()-r):Math.trunc(g()-r),this.analyze("Get Image:"),!a.tensor){this.config.debug&&u("could not convert input to tensor"),this.emit("error"),o(he("could not convert input to tensor"));return}this.emit("image"),r=g(),this.config.skipAllowed=await W1(this.config,a.tensor),this.config.filter.autoBrightness=(this.config.filter.autoBrightness||!1)&&this.config.skipAllowed,this.performance.totalFrames||(this.performance.totalFrames=0),this.performance.cachedFrames||(this.performance.cachedFrames=0),this.performance.totalFrames++,this.config.skipAllowed&&this.performance.cachedFrames++,this.performance.cacheCheck=this.env.perfadd?(this.performance.cacheCheck||0)+Math.trunc(g()-r):Math.trunc(g()-r),this.analyze("Check Changed:");let l=[],c=[],x=[],i=[];this.state="detect:face",this.config.async?(l=this.config.face.enabled?q5(this,a.tensor):[],this.performance.face&&delete this.performance.face):(r=g(),l=this.config.face.enabled?await q5(this,a.tensor):[],this.performance.face=this.env.perfadd?(this.performance.face||0)+Math.trunc(g()-r):Math.trunc(g()-r)),this.config.async&&(this.config.body.maxDetected===-1||this.config.hand.maxDetected===-1)&&(l=await l),this.analyze("Start Body:"),this.state="detect:body";let y=this.config.body.maxDetected===-1?a0(this.config,{body:{maxDetected:this.config.face.enabled?1*l.length:1}}):this.config;this.config.async?((b=this.config.body.modelPath)!=null&&b.includes("posenet")?c=this.config.body.enabled?p1(a.tensor,y):[]:(M=this.config.body.modelPath)!=null&&M.includes("blazepose")?c=this.config.body.enabled?c5(a.tensor,y):[]:(T=this.config.body.modelPath)!=null&&T.includes("efficientpose")?c=this.config.body.enabled?u5(a.tensor,y):[]:(m=this.config.body.modelPath)!=null&&m.includes("movenet")&&(c=this.config.body.enabled?l1(a.tensor,y):[]),this.performance.body&&delete this.performance.body):(r=g(),(h=this.config.body.modelPath)!=null&&h.includes("posenet")?c=this.config.body.enabled?await p1(a.tensor,y):[]:(S=this.config.body.modelPath)!=null&&S.includes("blazepose")?c=this.config.body.enabled?await c5(a.tensor,y):[]:(P=this.config.body.modelPath)!=null&&P.includes("efficientpose")?c=this.config.body.enabled?await u5(a.tensor,y):[]:(I=this.config.body.modelPath)!=null&&I.includes("movenet")&&(c=this.config.body.enabled?await l1(a.tensor,y):[]),this.performance.body=this.env.perfadd?(this.performance.body||0)+Math.trunc(g()-r):Math.trunc(g()-r)),this.analyze("End Body:"),this.analyze("Start Hand:"),this.state="detect:hand";let d=this.config.hand.maxDetected===-1?a0(this.config,{hand:{maxDetected:this.config.face.enabled?2*l.length:1}}):this.config;this.config.async?((t0=(q=this.config.hand.detector)==null?void 0:q.modelPath)!=null&&t0.includes("handdetect")?x=this.config.hand.enabled?Q5(a.tensor,d):[]:($=(G=this.config.hand.detector)==null?void 0:G.modelPath)!=null&&$.includes("handtrack")&&(x=this.config.hand.enabled?e1(a.tensor,d):[]),this.performance.hand&&delete this.performance.hand):(r=g(),(v=(A0=this.config.hand.detector)==null?void 0:A0.modelPath)!=null&&v.includes("handdetect")?x=this.config.hand.enabled?await Q5(a.tensor,d):[]:(n0=(V=this.config.hand.detector)==null?void 0:V.modelPath)!=null&&n0.includes("handtrack")&&(x=this.config.hand.enabled?await e1(a.tensor,d):[]),this.performance.hand=this.env.perfadd?(this.performance.hand||0)+Math.trunc(g()-r):Math.trunc(g()-r)),this.analyze("End Hand:"),this.analyze("Start Object:"),this.state="detect:object",this.config.async?((U=this.config.object.modelPath)!=null&&U.includes("nanodet")?i=this.config.object.enabled?d1(a.tensor,this.config):[]:(g0=this.config.object.modelPath)!=null&&g0.includes("centernet")&&(i=this.config.object.enabled?y5(a.tensor,this.config):[]),this.performance.object&&delete this.performance.object):(r=g(),(m0=this.config.object.modelPath)!=null&&m0.includes("nanodet")?i=this.config.object.enabled?await d1(a.tensor,this.config):[]:(B=this.config.object.modelPath)!=null&&B.includes("centernet")&&(i=this.config.object.enabled?await y5(a.tensor,this.config):[]),this.performance.object=this.env.perfadd?(this.performance.object||0)+Math.trunc(g()-r):Math.trunc(g()-r)),this.analyze("End Object:"),this.state="detect:await",this.config.async&&([l,c,x,i]=await Promise.all([l,c,x,i])),this.state="detect:gesture";let p=[];this.config.gesture.enabled&&(r=g(),p=[...Sn(l),...zn(c),...Nn(x),...jn(l)],this.config.async?this.performance.gesture&&delete this.performance.gesture:this.performance.gesture=this.env.perfadd?(this.performance.gesture||0)+Math.trunc(g()-r):Math.trunc(g()-r)),this.performance.total=this.env.perfadd?(this.performance.total||0)+Math.trunc(g()-A):Math.trunc(g()-A);let f=((X=this.process.tensor)==null?void 0:X.shape)||[0,0,0,0];this.result={face:l,body:c,hand:x,gesture:p,object:i,performance:this.performance,canvas:this.process.canvas,timestamp:Date.now(),error:null,width:f[2],height:f[1],get persons(){return So(l,c,x,p,f)}},ae.dispose(a.tensor),this.emit("detect"),this.state="idle",o(this.result)})}async sleep(t){return new Promise(n=>{setTimeout(n,t)})}async video(t,n=!0,o=0){n?(G0(this,Ue)[t.id]||(this.config.debug&&u("video start",t.id),G0(this,Ue)[t.id]=!0),!t.paused&&G0(this,Ue)[t.id]&&t.readyState>=2&&await this.detect(t),o>0&&await this.sleep(o),G0(this,Ue)[t.id]&&requestAnimationFrame(()=>this.video(t,n,o))):(this.config.debug&&u("video stop",t.id),G0(this,Ue)[t.id]=!1)}};M2=new WeakMap,B2=new WeakMap,H2=new WeakMap,Gt=new WeakMap,Ue=new WeakMap;0&&(module.exports={Env,Human,defaults,draw,empty,env,match,models}); diff --git a/dist/tfjs.version.js b/dist/tfjs.version.js index ebe296c6..b881048e 100644 --- a/dist/tfjs.version.js +++ b/dist/tfjs.version.js @@ -4,35 +4,4 @@ author: ' */ - -// node_modules/.pnpm/@tensorflow+tfjs-core@4.2.0/node_modules/@tensorflow/tfjs-core/package.json -var version = "4.2.0"; - -// node_modules/.pnpm/@tensorflow+tfjs-converter@4.2.0_tkoh6rxfpzme3tc2ndqbqcrg7y/node_modules/@tensorflow/tfjs-converter/package.json -var version2 = "4.2.0"; - -// node_modules/.pnpm/@tensorflow+tfjs-backend-cpu@4.2.0_tkoh6rxfpzme3tc2ndqbqcrg7y/node_modules/@tensorflow/tfjs-backend-cpu/package.json -var version3 = "4.2.0"; - -// node_modules/.pnpm/@tensorflow+tfjs-backend-webgl@4.2.0_tkoh6rxfpzme3tc2ndqbqcrg7y/node_modules/@tensorflow/tfjs-backend-webgl/package.json -var version4 = "4.2.0"; - -// node_modules/.pnpm/@tensorflow+tfjs-backend-wasm@4.2.0_tkoh6rxfpzme3tc2ndqbqcrg7y/node_modules/@tensorflow/tfjs-backend-wasm/package.json -var version5 = "4.2.0"; - -// node_modules/.pnpm/@tensorflow+tfjs-backend-webgpu@0.0.1-alpha.17_tkoh6rxfpzme3tc2ndqbqcrg7y/node_modules/@tensorflow/tfjs-backend-webgpu/package.json -var version6 = "0.0.1-alpha.17"; - -// tfjs/tf-version.ts -var version7 = { - tfjs: version, - "tfjs-core": version, - "tfjs-converter": version2, - "tfjs-backend-cpu": version3, - "tfjs-backend-webgl": version4, - "tfjs-backend-wasm": version5, - "tfjs-backend-webgpu": version6 -}; -export { - version7 as version -}; +var e="4.2.0";var s="4.2.0";var t="4.2.0";var n="4.2.0";var r="4.2.0";var i="0.0.1-alpha.17";var h={tfjs:e,"tfjs-core":e,"tfjs-converter":s,"tfjs-backend-cpu":t,"tfjs-backend-webgl":n,"tfjs-backend-wasm":r,"tfjs-backend-webgpu":i};export{h as version}; diff --git a/test/build.log b/test/build.log index ad64ff65..9f777630 100644 --- a/test/build.log +++ b/test/build.log @@ -1,104 +1,50 @@ -2023-01-06 12:59:00 DATA:  Build {"name":"@vladmandic/human","version":"3.0.1"} -2023-01-06 12:59:00 INFO:  Application: {"name":"@vladmandic/human","version":"3.0.1"} -2023-01-06 12:59:00 INFO:  Environment: {"profile":"production","config":".build.json","package":"package.json","tsconfig":true,"eslintrc":true,"git":true} -2023-01-06 12:59:00 INFO:  Toolchain: {"build":"0.7.14","esbuild":"0.15.18","typescript":"4.9.4","typedoc":"0.23.23","eslint":"8.31.0"} -2023-01-06 12:59:00 INFO:  Build: {"profile":"production","steps":["clean","compile","typings","typedoc","lint","changelog"]} -2023-01-06 12:59:00 STATE: Clean: {"locations":["dist/*","types/*","typedoc/*"]} -2023-01-06 12:59:00 STATE: Compile: {"name":"tfjs/browser/version","format":"esm","platform":"browser","input":"tfjs/tf-version.ts","output":"dist/tfjs.version.js","files":1,"inputBytes":1289,"outputBytes":361} -2023-01-06 12:59:00 STATE: Compile: {"name":"tfjs/nodejs/cpu","format":"cjs","platform":"node","input":"tfjs/tf-node.ts","output":"dist/tfjs.esm.js","files":2,"inputBytes":569,"outputBytes":924} -2023-01-06 12:59:00 STATE: Compile: {"name":"human/nodejs/cpu","format":"cjs","platform":"node","input":"src/human.ts","output":"dist/human.node.js","files":80,"inputBytes":670848,"outputBytes":317619} -2023-01-06 12:59:00 STATE: Compile: {"name":"tfjs/nodejs/gpu","format":"cjs","platform":"node","input":"tfjs/tf-node-gpu.ts","output":"dist/tfjs.esm.js","files":2,"inputBytes":577,"outputBytes":928} -2023-01-06 12:59:00 STATE: Compile: {"name":"human/nodejs/gpu","format":"cjs","platform":"node","input":"src/human.ts","output":"dist/human.node-gpu.js","files":80,"inputBytes":670852,"outputBytes":317623} -2023-01-06 12:59:00 STATE: Compile: {"name":"tfjs/nodejs/wasm","format":"cjs","platform":"node","input":"tfjs/tf-node-wasm.ts","output":"dist/tfjs.esm.js","files":2,"inputBytes":665,"outputBytes":1876} -2023-01-06 12:59:00 STATE: Compile: {"name":"human/nodejs/wasm","format":"cjs","platform":"node","input":"src/human.ts","output":"dist/human.node-wasm.js","files":80,"inputBytes":671800,"outputBytes":317734} -2023-01-06 12:59:00 STATE: Compile: {"name":"tfjs/browser/esm/nobundle","format":"esm","platform":"browser","input":"tfjs/tf-browser.ts","output":"dist/tfjs.esm.js","files":2,"inputBytes":1375,"outputBytes":670} -2023-01-06 12:59:00 STATE: Compile: {"name":"human/browser/esm/nobundle","format":"esm","platform":"browser","input":"src/human.ts","output":"dist/human.esm-nobundle.js","files":80,"inputBytes":670594,"outputBytes":316195} -2023-01-06 12:59:00 STATE: Compile: {"name":"tfjs/browser/esm/bundle","format":"esm","platform":"browser","input":"tfjs/tf-browser.ts","output":"dist/tfjs.esm.js","files":10,"inputBytes":1375,"outputBytes":1151353} -2023-01-06 12:59:00 STATE: Compile: {"name":"human/browser/iife/bundle","format":"iife","platform":"browser","input":"src/human.ts","output":"dist/human.js","files":80,"inputBytes":1821277,"outputBytes":1463493} -2023-01-06 12:59:00 STATE: Compile: {"name":"human/browser/esm/bundle","format":"esm","platform":"browser","input":"src/human.ts","output":"dist/human.esm.js","files":80,"inputBytes":1821277,"outputBytes":1915983} -2023-01-06 12:59:04 STATE: Typings: {"input":"src/human.ts","output":"types/lib","files":15} -2023-01-06 12:59:05 STATE: TypeDoc: {"input":"src/human.ts","output":"typedoc","objects":77,"generated":true} -2023-01-06 12:59:05 STATE: Compile: {"name":"demo/typescript","format":"esm","platform":"browser","input":"demo/typescript/index.ts","output":"demo/typescript/index.js","files":1,"inputBytes":6082,"outputBytes":2872} -2023-01-06 12:59:05 STATE: Compile: {"name":"demo/faceid","format":"esm","platform":"browser","input":"demo/faceid/index.ts","output":"demo/faceid/index.js","files":2,"inputBytes":17503,"outputBytes":9403} -2023-01-06 12:59:15 STATE: Lint: {"locations":["**/*.json","src/**/*.ts","test/**/*.js","demo/**/*.js","**/*.md"],"files":169,"errors":0,"warnings":0} -2023-01-06 12:59:15 STATE: ChangeLog: {"repository":"https://github.com/vladmandic/human","branch":"main","output":"CHANGELOG.md"} -2023-01-06 12:59:15 STATE: Copy: {"input":"node_modules/@vladmandic/tfjs/types/tfjs-core.d.ts","output":"types/tfjs-core.d.ts"} -2023-01-06 12:59:15 INFO:  Done... -2023-01-06 12:59:15 STATE: Copy: {"input":"node_modules/@vladmandic/tfjs/types/tfjs.d.ts","output":"types/tfjs.esm.d.ts"} -2023-01-06 12:59:15 STATE: Copy: {"input":"src/types/tsconfig.json","output":"types/tsconfig.json"} -2023-01-06 12:59:15 STATE: Copy: {"input":"src/types/eslint.json","output":"types/.eslintrc.json"} -2023-01-06 12:59:15 STATE: Copy: {"input":"src/types/tfjs.esm.d.ts","output":"dist/tfjs.esm.d.ts"} -2023-01-06 12:59:15 STATE: Filter: {"input":"types/tfjs-core.d.ts"} -2023-01-06 12:59:16 STATE: API-Extractor: {"succeeeded":true,"errors":0,"warnings":204} -2023-01-06 12:59:16 STATE: Filter: {"input":"types/human.d.ts"} -2023-01-06 12:59:16 STATE: Write: {"output":"dist/human.esm-nobundle.d.ts"} -2023-01-06 12:59:16 STATE: Write: {"output":"dist/human.esm.d.ts"} -2023-01-06 12:59:16 STATE: Write: {"output":"dist/human.d.ts"} -2023-01-06 12:59:16 STATE: Write: {"output":"dist/human.node-gpu.d.ts"} -2023-01-06 12:59:16 STATE: Write: {"output":"dist/human.node.d.ts"} -2023-01-06 12:59:16 STATE: Write: {"output":"dist/human.node-wasm.d.ts"} -2023-01-06 12:59:16 INFO:  Analyze models: {"folders":8,"result":"models/models.json"} -2023-01-06 12:59:16 STATE: Models {"folder":"./models","models":12} -2023-01-06 12:59:16 STATE: Models {"folder":"../human-models/models","models":41} -2023-01-06 12:59:16 STATE: Models {"folder":"../blazepose/model/","models":4} -2023-01-06 12:59:16 STATE: Models {"folder":"../anti-spoofing/model","models":1} -2023-01-06 12:59:16 STATE: Models {"folder":"../efficientpose/models","models":3} -2023-01-06 12:59:16 STATE: Models {"folder":"../insightface/models","models":5} -2023-01-06 12:59:16 STATE: Models {"folder":"../movenet/models","models":3} -2023-01-06 12:59:16 STATE: Models {"folder":"../nanodet/models","models":4} -2023-01-06 12:59:16 STATE: Models: {"count":55,"totalSize":372917743} -2023-01-06 12:59:16 INFO:  Human Build complete... {"logFile":"test/build.log"} -2023-01-06 13:08:59 INFO:  @vladmandic/human version 3.0.2 -2023-01-06 13:08:59 INFO:  User: vlado Platform: linux Arch: x64 Node: v19.1.0 -2023-01-06 13:08:59 INFO:  Application: {"name":"@vladmandic/human","version":"3.0.2"} -2023-01-06 13:08:59 INFO:  Environment: {"profile":"development","config":".build.json","package":"package.json","tsconfig":true,"eslintrc":true,"git":true} -2023-01-06 13:08:59 INFO:  Toolchain: {"build":"0.7.14","esbuild":"0.15.18","typescript":"4.9.4","typedoc":"0.23.23","eslint":"8.31.0"} -2023-01-06 13:08:59 INFO:  Build: {"profile":"development","steps":["serve","watch","compile"]} -2023-01-06 13:08:59 STATE: WebServer: {"ssl":false,"port":8000,"root":"."} -2023-01-06 13:08:59 STATE: WebServer: {"ssl":true,"port":8001,"root":".","sslKey":"node_modules/@vladmandic/build/cert/https.key","sslCrt":"node_modules/@vladmandic/build/cert/https.crt"} -2023-01-06 13:08:59 STATE: Watch: {"locations":["src/**/*","tfjs/**/*","demo/**/*.ts"]} -2023-01-06 13:08:59 STATE: Compile: {"name":"tfjs/browser/version","format":"esm","platform":"browser","input":"tfjs/tf-version.ts","output":"dist/tfjs.version.js","files":1,"inputBytes":1289,"outputBytes":1357} -2023-01-06 13:08:59 STATE: Compile: {"name":"tfjs/nodejs/cpu","format":"cjs","platform":"node","input":"tfjs/tf-node.ts","output":"dist/tfjs.esm.js","files":2,"inputBytes":1565,"outputBytes":1786} -2023-01-06 13:08:59 STATE: Compile: {"name":"human/nodejs/cpu","format":"cjs","platform":"node","input":"src/human.ts","output":"dist/human.node.js","files":80,"inputBytes":671710,"outputBytes":505424} -2023-01-06 13:08:59 STATE: Compile: {"name":"tfjs/nodejs/gpu","format":"cjs","platform":"node","input":"tfjs/tf-node-gpu.ts","output":"dist/tfjs.esm.js","files":2,"inputBytes":1573,"outputBytes":1810} -2023-01-06 13:08:59 STATE: Compile: {"name":"human/nodejs/gpu","format":"cjs","platform":"node","input":"src/human.ts","output":"dist/human.node-gpu.js","files":80,"inputBytes":671734,"outputBytes":505444} -2023-01-06 13:08:59 STATE: Compile: {"name":"tfjs/nodejs/wasm","format":"cjs","platform":"node","input":"tfjs/tf-node-wasm.ts","output":"dist/tfjs.esm.js","files":2,"inputBytes":1661,"outputBytes":1992} -2023-01-06 13:08:59 STATE: Compile: {"name":"human/nodejs/wasm","format":"cjs","platform":"node","input":"src/human.ts","output":"dist/human.node-wasm.js","files":80,"inputBytes":671916,"outputBytes":505635} -2023-01-06 13:08:59 STATE: Compile: {"name":"tfjs/browser/esm/nobundle","format":"esm","platform":"browser","input":"tfjs/tf-browser.ts","output":"dist/tfjs.esm.js","files":2,"inputBytes":2371,"outputBytes":923} -2023-01-06 13:08:59 STATE: Compile: {"name":"human/browser/esm/nobundle","format":"esm","platform":"browser","input":"src/human.ts","output":"dist/human.esm-nobundle.js","files":80,"inputBytes":670847,"outputBytes":508116} -2023-01-06 13:08:59 STATE: Compile: {"name":"tfjs/browser/esm/bundle","format":"esm","platform":"browser","input":"tfjs/tf-browser.ts","output":"dist/tfjs.esm.js","files":10,"inputBytes":2371,"outputBytes":1151353} -2023-01-06 13:08:59 STATE: Compile: {"name":"human/browser/iife/bundle","format":"iife","platform":"browser","input":"src/human.ts","output":"dist/human.js","files":80,"inputBytes":1821277,"outputBytes":1463493} -2023-01-06 13:09:00 STATE: Compile: {"name":"human/browser/esm/bundle","format":"esm","platform":"browser","input":"src/human.ts","output":"dist/human.esm.js","files":80,"inputBytes":1821277,"outputBytes":1915983} -2023-01-06 13:09:00 STATE: Compile: {"name":"demo/typescript","format":"esm","platform":"browser","input":"demo/typescript/index.ts","output":"demo/typescript/index.js","files":1,"inputBytes":6082,"outputBytes":4154} -2023-01-06 13:09:00 STATE: Compile: {"name":"demo/faceid","format":"esm","platform":"browser","input":"demo/faceid/index.ts","output":"demo/faceid/index.js","files":2,"inputBytes":17503,"outputBytes":13850} -2023-01-06 13:09:00 INFO:  Listening... -2023-01-06 13:11:10 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":301,"url":"/demo/typescript","redirect":"/demo/typescript/index.html","remote":"::1"} -2023-01-06 13:11:10 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"text/html","size":1954,"url":"/demo/typescript/index.html","remote":"::1"} -2023-01-06 13:11:11 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"text/javascript","size":4154,"url":"/demo/typescript/index.js","remote":"::1"} -2023-01-06 13:11:11 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"text/javascript","size":1915983,"url":"/dist/human.esm.js","remote":"::1"} -2023-01-06 13:11:11 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"font/woff2","size":181500,"url":"/assets/lato-light.woff2","remote":"::1"} -2023-01-06 13:11:11 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"application/octet-stream","size":9376,"url":"/demo/typescript/index.js.map","remote":"::1"} -2023-01-06 13:11:11 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"application/octet-stream","size":3379703,"url":"/dist/human.esm.js.map","remote":"::1"} -2023-01-06 13:11:11 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"image/x-icon","size":261950,"url":"/favicon.ico","remote":"::1"} -2023-01-06 13:11:11 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"application/manifest+json","size":304,"url":"/demo/manifest.webmanifest","remote":"::1"} -2023-01-06 13:11:11 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"image/png","size":142790,"url":"/assets/icon.png","remote":"::1"} -2023-01-06 13:12:05 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"text/html","size":1954,"url":"/demo/typescript/index.html","remote":"::1"} -2023-01-06 13:12:05 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"text/javascript","size":4154,"url":"/demo/typescript/index.js","remote":"::1"} -2023-01-06 13:12:05 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"font/woff2","size":181500,"url":"/assets/lato-light.woff2","remote":"::1"} -2023-01-06 13:12:05 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"text/javascript","size":1915983,"url":"/dist/human.esm.js","remote":"::1"} -2023-01-06 13:12:05 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"image/x-icon","size":261950,"url":"/favicon.ico","remote":"::1"} -2023-01-06 13:12:05 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"application/manifest+json","size":304,"url":"/demo/manifest.webmanifest","remote":"::1"} -2023-01-06 13:12:05 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"image/png","size":142790,"url":"/assets/icon.png","remote":"::1"} -2023-01-06 13:12:08 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"application/manifest+json","size":304,"url":"/demo/manifest.webmanifest","remote":"::1"} -2023-01-06 13:12:08 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"application/octet-stream","size":9376,"url":"/demo/typescript/index.js.map","remote":"::1"} -2023-01-06 13:12:08 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"application/octet-stream","size":3379703,"url":"/dist/human.esm.js.map","remote":"::1"} -2023-01-06 13:13:14 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"text/html","size":1954,"url":"/demo/typescript/index.html","remote":"::1"} -2023-01-06 13:13:14 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"text/javascript","size":4154,"url":"/demo/typescript/index.js","remote":"::1"} -2023-01-06 13:13:14 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"text/javascript","size":1915983,"url":"/dist/human.esm.js","remote":"::1"} -2023-01-06 13:13:14 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"font/woff2","size":181500,"url":"/assets/lato-light.woff2","remote":"::1"} -2023-01-06 13:13:14 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"application/manifest+json","size":304,"url":"/demo/manifest.webmanifest","remote":"::1"} -2023-01-06 13:13:14 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"image/png","size":142790,"url":"/assets/icon.png","remote":"::1"} -2023-01-06 13:13:21 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"application/manifest+json","size":304,"url":"/demo/manifest.webmanifest","remote":"::1"} -2023-01-06 13:13:21 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"text/html","size":1954,"url":"/demo/typescript/index.html","remote":"::1"} -2023-01-06 13:13:21 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"application/octet-stream","size":9376,"url":"/demo/typescript/index.js.map","remote":"::1"} -2023-01-06 13:13:21 DATA:  HTTPS: {"method":"GET","ver":"2.0","status":200,"mime":"application/octet-stream","size":3379703,"url":"/dist/human.esm.js.map","remote":"::1"} +2023-01-06 13:26:13 DATA:  Build {"name":"@vladmandic/human","version":"3.0.2"} +2023-01-06 13:26:13 INFO:  Application: {"name":"@vladmandic/human","version":"3.0.2"} +2023-01-06 13:26:13 INFO:  Environment: {"profile":"production","config":".build.json","package":"package.json","tsconfig":true,"eslintrc":true,"git":true} +2023-01-06 13:26:13 INFO:  Toolchain: {"build":"0.7.14","esbuild":"0.15.18","typescript":"4.9.4","typedoc":"0.23.23","eslint":"8.31.0"} +2023-01-06 13:26:13 INFO:  Build: {"profile":"production","steps":["clean","compile","typings","typedoc","lint","changelog"]} +2023-01-06 13:26:13 STATE: Clean: {"locations":["dist/*","types/*","typedoc/*"]} +2023-01-06 13:26:13 STATE: Compile: {"name":"tfjs/browser/version","format":"esm","platform":"browser","input":"tfjs/tf-version.ts","output":"dist/tfjs.version.js","files":1,"inputBytes":1289,"outputBytes":361} +2023-01-06 13:26:13 STATE: Compile: {"name":"tfjs/nodejs/cpu","format":"cjs","platform":"node","input":"tfjs/tf-node.ts","output":"dist/tfjs.esm.js","files":2,"inputBytes":569,"outputBytes":924} +2023-01-06 13:26:13 STATE: Compile: {"name":"human/nodejs/cpu","format":"cjs","platform":"node","input":"src/human.ts","output":"dist/human.node.js","files":80,"inputBytes":670848,"outputBytes":317619} +2023-01-06 13:26:13 STATE: Compile: {"name":"tfjs/nodejs/gpu","format":"cjs","platform":"node","input":"tfjs/tf-node-gpu.ts","output":"dist/tfjs.esm.js","files":2,"inputBytes":577,"outputBytes":928} +2023-01-06 13:26:13 STATE: Compile: {"name":"human/nodejs/gpu","format":"cjs","platform":"node","input":"src/human.ts","output":"dist/human.node-gpu.js","files":80,"inputBytes":670852,"outputBytes":317623} +2023-01-06 13:26:13 STATE: Compile: {"name":"tfjs/nodejs/wasm","format":"cjs","platform":"node","input":"tfjs/tf-node-wasm.ts","output":"dist/tfjs.esm.js","files":2,"inputBytes":665,"outputBytes":1876} +2023-01-06 13:26:13 STATE: Compile: {"name":"human/nodejs/wasm","format":"cjs","platform":"node","input":"src/human.ts","output":"dist/human.node-wasm.js","files":80,"inputBytes":671800,"outputBytes":317734} +2023-01-06 13:26:13 STATE: Compile: {"name":"tfjs/browser/esm/nobundle","format":"esm","platform":"browser","input":"tfjs/tf-browser.ts","output":"dist/tfjs.esm.js","files":2,"inputBytes":1375,"outputBytes":670} +2023-01-06 13:26:13 STATE: Compile: {"name":"human/browser/esm/nobundle","format":"esm","platform":"browser","input":"src/human.ts","output":"dist/human.esm-nobundle.js","files":80,"inputBytes":670594,"outputBytes":316195} +2023-01-06 13:26:14 STATE: Compile: {"name":"tfjs/browser/esm/bundle","format":"esm","platform":"browser","input":"tfjs/tf-browser.ts","output":"dist/tfjs.esm.js","files":10,"inputBytes":1375,"outputBytes":1151353} +2023-01-06 13:26:14 STATE: Compile: {"name":"human/browser/iife/bundle","format":"iife","platform":"browser","input":"src/human.ts","output":"dist/human.js","files":80,"inputBytes":1821277,"outputBytes":1463493} +2023-01-06 13:26:14 STATE: Compile: {"name":"human/browser/esm/bundle","format":"esm","platform":"browser","input":"src/human.ts","output":"dist/human.esm.js","files":80,"inputBytes":1821277,"outputBytes":1915983} +2023-01-06 13:26:17 STATE: Typings: {"input":"src/human.ts","output":"types/lib","files":15} +2023-01-06 13:26:19 STATE: TypeDoc: {"input":"src/human.ts","output":"typedoc","objects":77,"generated":true} +2023-01-06 13:26:19 STATE: Compile: {"name":"demo/typescript","format":"esm","platform":"browser","input":"demo/typescript/index.ts","output":"demo/typescript/index.js","files":1,"inputBytes":6082,"outputBytes":2872} +2023-01-06 13:26:19 STATE: Compile: {"name":"demo/faceid","format":"esm","platform":"browser","input":"demo/faceid/index.ts","output":"demo/faceid/index.js","files":2,"inputBytes":17503,"outputBytes":9403} +2023-01-06 13:26:28 STATE: Lint: {"locations":["**/*.json","src/**/*.ts","test/**/*.js","demo/**/*.js","**/*.md"],"files":169,"errors":0,"warnings":0} +2023-01-06 13:26:28 STATE: ChangeLog: {"repository":"https://github.com/vladmandic/human","branch":"main","output":"CHANGELOG.md"} +2023-01-06 13:26:28 STATE: Copy: {"input":"node_modules/@vladmandic/tfjs/types/tfjs-core.d.ts","output":"types/tfjs-core.d.ts"} +2023-01-06 13:26:28 INFO:  Done... +2023-01-06 13:26:28 STATE: Copy: {"input":"node_modules/@vladmandic/tfjs/types/tfjs.d.ts","output":"types/tfjs.esm.d.ts"} +2023-01-06 13:26:28 STATE: Copy: {"input":"src/types/tsconfig.json","output":"types/tsconfig.json"} +2023-01-06 13:26:28 STATE: Copy: {"input":"src/types/eslint.json","output":"types/.eslintrc.json"} +2023-01-06 13:26:28 STATE: Copy: {"input":"src/types/tfjs.esm.d.ts","output":"dist/tfjs.esm.d.ts"} +2023-01-06 13:26:28 STATE: Filter: {"input":"types/tfjs-core.d.ts"} +2023-01-06 13:26:29 STATE: API-Extractor: {"succeeeded":true,"errors":0,"warnings":204} +2023-01-06 13:26:29 STATE: Filter: {"input":"types/human.d.ts"} +2023-01-06 13:26:29 STATE: Write: {"output":"dist/human.esm-nobundle.d.ts"} +2023-01-06 13:26:29 STATE: Write: {"output":"dist/human.esm.d.ts"} +2023-01-06 13:26:29 STATE: Write: {"output":"dist/human.d.ts"} +2023-01-06 13:26:29 STATE: Write: {"output":"dist/human.node-gpu.d.ts"} +2023-01-06 13:26:29 STATE: Write: {"output":"dist/human.node.d.ts"} +2023-01-06 13:26:29 STATE: Write: {"output":"dist/human.node-wasm.d.ts"} +2023-01-06 13:26:29 INFO:  Analyze models: {"folders":8,"result":"models/models.json"} +2023-01-06 13:26:29 STATE: Models {"folder":"./models","models":12} +2023-01-06 13:26:29 STATE: Models {"folder":"../human-models/models","models":41} +2023-01-06 13:26:29 STATE: Models {"folder":"../blazepose/model/","models":4} +2023-01-06 13:26:29 STATE: Models {"folder":"../anti-spoofing/model","models":1} +2023-01-06 13:26:29 STATE: Models {"folder":"../efficientpose/models","models":3} +2023-01-06 13:26:29 STATE: Models {"folder":"../insightface/models","models":5} +2023-01-06 13:26:29 STATE: Models {"folder":"../movenet/models","models":3} +2023-01-06 13:26:29 STATE: Models {"folder":"../nanodet/models","models":4} +2023-01-06 13:26:30 STATE: Models: {"count":55,"totalSize":372917743} +2023-01-06 13:26:30 INFO:  Human Build complete... {"logFile":"test/build.log"} diff --git a/typedoc/classes/Env.html b/typedoc/classes/Env.html index 1d84d6d4..990c9ff3 100644 --- a/typedoc/classes/Env.html +++ b/typedoc/classes/Env.html @@ -1,4 +1,4 @@ -Env | @vladmandic/human - v3.0.1
+Env | @vladmandic/human - v3.0.2
  • Preparing search index...
  • -
  • The search index is not available
@vladmandic/human - v3.0.1
+
  • The search index is not available
  • @vladmandic/human - v3.0.2
    @@ -343,7 +343,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/classes/GraphModel.html b/typedoc/classes/GraphModel.html index 8d52adb5..1794b0ac 100644 --- a/typedoc/classes/GraphModel.html +++ b/typedoc/classes/GraphModel.html @@ -1,4 +1,4 @@ -GraphModel | @vladmandic/human - v3.0.1
        +GraphModel | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -449,7 +449,7 @@ scheme-based string shortcut for IOHandler.

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/classes/Human.html b/typedoc/classes/Human.html index 7770a9e5..3d4aea5c 100644 --- a/typedoc/classes/Human.html +++ b/typedoc/classes/Human.html @@ -1,4 +1,4 @@ -Human | @vladmandic/human - v3.0.1
        +Human | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -558,7 +558,7 @@ Returns tensor which contains image data in RGBA format

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/classes/Tensor-1.html b/typedoc/classes/Tensor-1.html index d4a27d6e..b83d6d8c 100644 --- a/typedoc/classes/Tensor-1.html +++ b/typedoc/classes/Tensor-1.html @@ -1,4 +1,4 @@ -Tensor | @vladmandic/human - v3.0.1
        +Tensor | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -3378,7 +3378,7 @@ parameter, so can not use a user-defined size to create the buffer.

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/classes/WebCam.html b/typedoc/classes/WebCam.html index 3dca3517..71e2c954 100644 --- a/typedoc/classes/WebCam.html +++ b/typedoc/classes/WebCam.html @@ -1,4 +1,4 @@ -WebCam | @vladmandic/human - v3.0.1
        +WebCam | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -249,7 +249,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/classes/models.Models.html b/typedoc/classes/models.Models.html index e3a91ffd..ea1d0a3c 100644 --- a/typedoc/classes/models.Models.html +++ b/typedoc/classes/models.Models.html @@ -1,4 +1,4 @@ -Models | @vladmandic/human - v3.0.1
        +Models | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -148,7 +148,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/enums/Rank.html b/typedoc/enums/Rank.html index 6fb68a67..7a3649a8 100644 --- a/typedoc/enums/Rank.html +++ b/typedoc/enums/Rank.html @@ -1,4 +1,4 @@ -Rank | @vladmandic/human - v3.0.1
        +Rank | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -50,7 +50,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/functions/draw.body.html b/typedoc/functions/draw.body.html index 3e5d6fce..6a0524eb 100644 --- a/typedoc/functions/draw.body.html +++ b/typedoc/functions/draw.body.html @@ -1,4 +1,4 @@ -body | @vladmandic/human - v3.0.1
        +body | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -50,7 +50,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/functions/draw.canvas.html b/typedoc/functions/draw.canvas.html index 8af69ca4..6b087e40 100644 --- a/typedoc/functions/draw.canvas.html +++ b/typedoc/functions/draw.canvas.html @@ -1,4 +1,4 @@ -canvas | @vladmandic/human - v3.0.1
        +canvas | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -48,7 +48,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/functions/draw.face.html b/typedoc/functions/draw.face.html index 49f32868..9197694d 100644 --- a/typedoc/functions/draw.face.html +++ b/typedoc/functions/draw.face.html @@ -1,4 +1,4 @@ -face | @vladmandic/human - v3.0.1
        +face | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -50,7 +50,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/functions/draw.gesture.html b/typedoc/functions/draw.gesture.html index 537b1287..ac5ce13d 100644 --- a/typedoc/functions/draw.gesture.html +++ b/typedoc/functions/draw.gesture.html @@ -1,4 +1,4 @@ -gesture | @vladmandic/human - v3.0.1
        +gesture | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -50,7 +50,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/functions/draw.hand.html b/typedoc/functions/draw.hand.html index 160f5807..469f30e9 100644 --- a/typedoc/functions/draw.hand.html +++ b/typedoc/functions/draw.hand.html @@ -1,4 +1,4 @@ -hand | @vladmandic/human - v3.0.1
        +hand | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -50,7 +50,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/functions/draw.init.html b/typedoc/functions/draw.init.html index 8fc05132..1702bb2c 100644 --- a/typedoc/functions/draw.init.html +++ b/typedoc/functions/draw.init.html @@ -1,4 +1,4 @@ -init | @vladmandic/human - v3.0.1
        +init | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -41,7 +41,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/functions/draw.object.html b/typedoc/functions/draw.object.html index 09ea8567..3ad12466 100644 --- a/typedoc/functions/draw.object.html +++ b/typedoc/functions/draw.object.html @@ -1,4 +1,4 @@ -object | @vladmandic/human - v3.0.1
        +object | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -50,7 +50,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/functions/draw.person.html b/typedoc/functions/draw.person.html index 32ac2953..9e3d8069 100644 --- a/typedoc/functions/draw.person.html +++ b/typedoc/functions/draw.person.html @@ -1,4 +1,4 @@ -person | @vladmandic/human - v3.0.1
        +person | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -50,7 +50,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/functions/empty.html b/typedoc/functions/empty.html index b5ec0516..7366755f 100644 --- a/typedoc/functions/empty.html +++ b/typedoc/functions/empty.html @@ -1,4 +1,4 @@ -empty | @vladmandic/human - v3.0.1
        +empty | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -43,7 +43,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/functions/match.distance.html b/typedoc/functions/match.distance.html index 8c7398a2..8d3376cf 100644 --- a/typedoc/functions/match.distance.html +++ b/typedoc/functions/match.distance.html @@ -1,4 +1,4 @@ -distance | @vladmandic/human - v3.0.1
        +distance | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -58,7 +58,7 @@ default is 20 which normalizes results to similarity above 0.5 can be considered

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/functions/match.find.html b/typedoc/functions/match.find.html index e3263570..f3221f5b 100644 --- a/typedoc/functions/match.find.html +++ b/typedoc/functions/match.find.html @@ -1,4 +1,4 @@ -find | @vladmandic/human - v3.0.1
        +find | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -69,7 +69,7 @@ Returns

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/functions/match.similarity.html b/typedoc/functions/match.similarity.html index dced75c4..b720d305 100644 --- a/typedoc/functions/match.similarity.html +++ b/typedoc/functions/match.similarity.html @@ -1,4 +1,4 @@ -similarity | @vladmandic/human - v3.0.1
        +similarity | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -62,7 +62,7 @@ Returns similarity between two face descriptors normalized to 0..1 range where 0

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/functions/models.validateModel.html b/typedoc/functions/models.validateModel.html index 1288b52f..3b2ac930 100644 --- a/typedoc/functions/models.validateModel.html +++ b/typedoc/functions/models.validateModel.html @@ -1,4 +1,4 @@ -validateModel | @vladmandic/human - v3.0.1
        +validateModel | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -48,7 +48,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/index.html b/typedoc/index.html index 124b968c..579e2849 100644 --- a/typedoc/index.html +++ b/typedoc/index.html @@ -1,4 +1,4 @@ -@vladmandic/human - v3.0.1
        +@vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    -

    @vladmandic/human - v3.0.1

    +

    @vladmandic/human - v3.0.2

    @@ -138,7 +138,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/BodyConfig.html b/typedoc/interfaces/BodyConfig.html index c81258a0..4c38d16f 100644 --- a/typedoc/interfaces/BodyConfig.html +++ b/typedoc/interfaces/BodyConfig.html @@ -1,4 +1,4 @@ -BodyConfig | @vladmandic/human - v3.0.1
        +BodyConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -106,7 +106,7 @@ for two-phase models such as face and hand caching applies to bounding boxes det

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/BodyKeypoint.html b/typedoc/interfaces/BodyKeypoint.html index 05b42c9e..23aaf82b 100644 --- a/typedoc/interfaces/BodyKeypoint.html +++ b/typedoc/interfaces/BodyKeypoint.html @@ -1,4 +1,4 @@ -BodyKeypoint | @vladmandic/human - v3.0.1
        +BodyKeypoint | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -90,7 +90,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/BodyResult.html b/typedoc/interfaces/BodyResult.html index 7d4eb31a..66a647b2 100644 --- a/typedoc/interfaces/BodyResult.html +++ b/typedoc/interfaces/BodyResult.html @@ -1,4 +1,4 @@ -BodyResult | @vladmandic/human - v3.0.1
        +BodyResult | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -98,7 +98,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/Config.html b/typedoc/interfaces/Config.html index acd32c7b..1bde7cb2 100644 --- a/typedoc/interfaces/Config.html +++ b/typedoc/interfaces/Config.html @@ -1,4 +1,4 @@ -Config | @vladmandic/human - v3.0.1
        +Config | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -248,7 +248,7 @@ any errors will be printed on console but will be treated as non-fatal

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/DrawOptions.html b/typedoc/interfaces/DrawOptions.html index 29a5b9ea..d82bdff3 100644 --- a/typedoc/interfaces/DrawOptions.html +++ b/typedoc/interfaces/DrawOptions.html @@ -1,4 +1,4 @@ -DrawOptions | @vladmandic/human - v3.0.1
        +DrawOptions | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -261,7 +261,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/FaceAntiSpoofConfig.html b/typedoc/interfaces/FaceAntiSpoofConfig.html index 9df10c27..45be94cb 100644 --- a/typedoc/interfaces/FaceAntiSpoofConfig.html +++ b/typedoc/interfaces/FaceAntiSpoofConfig.html @@ -1,4 +1,4 @@ -FaceAntiSpoofConfig | @vladmandic/human - v3.0.1
        +FaceAntiSpoofConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -90,7 +90,7 @@ for two-phase models such as face and hand caching applies to bounding boxes det

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/FaceAttentionConfig.html b/typedoc/interfaces/FaceAttentionConfig.html index 851d7af5..10480518 100644 --- a/typedoc/interfaces/FaceAttentionConfig.html +++ b/typedoc/interfaces/FaceAttentionConfig.html @@ -1,4 +1,4 @@ -FaceAttentionConfig | @vladmandic/human - v3.0.1
        +FaceAttentionConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -90,7 +90,7 @@ for two-phase models such as face and hand caching applies to bounding boxes det

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/FaceConfig.html b/typedoc/interfaces/FaceConfig.html index 08f18b1a..d556b599 100644 --- a/typedoc/interfaces/FaceConfig.html +++ b/typedoc/interfaces/FaceConfig.html @@ -1,4 +1,4 @@ -FaceConfig | @vladmandic/human - v3.0.1
        +FaceConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -144,7 +144,7 @@ for two-phase models such as face and hand caching applies to bounding boxes det

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/FaceDescriptionConfig.html b/typedoc/interfaces/FaceDescriptionConfig.html index c66ab4f9..849e205d 100644 --- a/typedoc/interfaces/FaceDescriptionConfig.html +++ b/typedoc/interfaces/FaceDescriptionConfig.html @@ -1,4 +1,4 @@ -FaceDescriptionConfig | @vladmandic/human - v3.0.1
        +FaceDescriptionConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -101,7 +101,7 @@ for two-phase models such as face and hand caching applies to bounding boxes det

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/FaceDetectorConfig.html b/typedoc/interfaces/FaceDetectorConfig.html index 52d37ff3..db092ee6 100644 --- a/typedoc/interfaces/FaceDetectorConfig.html +++ b/typedoc/interfaces/FaceDetectorConfig.html @@ -1,4 +1,4 @@ -FaceDetectorConfig | @vladmandic/human - v3.0.1
        +FaceDetectorConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -140,7 +140,7 @@ for two-phase models such as face and hand caching applies to bounding boxes det

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/FaceEmotionConfig.html b/typedoc/interfaces/FaceEmotionConfig.html index d7427d12..625d1351 100644 --- a/typedoc/interfaces/FaceEmotionConfig.html +++ b/typedoc/interfaces/FaceEmotionConfig.html @@ -1,4 +1,4 @@ -FaceEmotionConfig | @vladmandic/human - v3.0.1
        +FaceEmotionConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -98,7 +98,7 @@ for two-phase models such as face and hand caching applies to bounding boxes det

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/FaceGearConfig.html b/typedoc/interfaces/FaceGearConfig.html index 5c1284e6..1afe0509 100644 --- a/typedoc/interfaces/FaceGearConfig.html +++ b/typedoc/interfaces/FaceGearConfig.html @@ -1,4 +1,4 @@ -FaceGearConfig | @vladmandic/human - v3.0.1
        +FaceGearConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -98,7 +98,7 @@ for two-phase models such as face and hand caching applies to bounding boxes det

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/FaceIrisConfig.html b/typedoc/interfaces/FaceIrisConfig.html index fb342b7b..c55a9da7 100644 --- a/typedoc/interfaces/FaceIrisConfig.html +++ b/typedoc/interfaces/FaceIrisConfig.html @@ -1,4 +1,4 @@ -FaceIrisConfig | @vladmandic/human - v3.0.1
        +FaceIrisConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -90,7 +90,7 @@ for two-phase models such as face and hand caching applies to bounding boxes det

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/FaceLivenessConfig.html b/typedoc/interfaces/FaceLivenessConfig.html index 7e71fd9b..10f9123d 100644 --- a/typedoc/interfaces/FaceLivenessConfig.html +++ b/typedoc/interfaces/FaceLivenessConfig.html @@ -1,4 +1,4 @@ -FaceLivenessConfig | @vladmandic/human - v3.0.1
        +FaceLivenessConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -90,7 +90,7 @@ for two-phase models such as face and hand caching applies to bounding boxes det

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/FaceMeshConfig.html b/typedoc/interfaces/FaceMeshConfig.html index 77698904..ecc0c880 100644 --- a/typedoc/interfaces/FaceMeshConfig.html +++ b/typedoc/interfaces/FaceMeshConfig.html @@ -1,4 +1,4 @@ -FaceMeshConfig | @vladmandic/human - v3.0.1
        +FaceMeshConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -98,7 +98,7 @@ for two-phase models such as face and hand caching applies to bounding boxes det

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/FaceResult.html b/typedoc/interfaces/FaceResult.html index 5681c1a2..03474960 100644 --- a/typedoc/interfaces/FaceResult.html +++ b/typedoc/interfaces/FaceResult.html @@ -1,4 +1,4 @@ -FaceResult | @vladmandic/human - v3.0.1
        +FaceResult | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -214,7 +214,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/FilterConfig.html b/typedoc/interfaces/FilterConfig.html index 8b646ea5..870e6273 100644 --- a/typedoc/interfaces/FilterConfig.html +++ b/typedoc/interfaces/FilterConfig.html @@ -1,4 +1,4 @@ -FilterConfig | @vladmandic/human - v3.0.1
        +FilterConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -227,7 +227,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/GenericConfig.html b/typedoc/interfaces/GenericConfig.html index 34cef1e1..df57d5be 100644 --- a/typedoc/interfaces/GenericConfig.html +++ b/typedoc/interfaces/GenericConfig.html @@ -1,4 +1,4 @@ -GenericConfig | @vladmandic/human - v3.0.1
        +GenericConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -99,7 +99,7 @@ for two-phase models such as face and hand caching applies to bounding boxes det

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/GestureConfig.html b/typedoc/interfaces/GestureConfig.html index 9e2b5088..c7c1d3cc 100644 --- a/typedoc/interfaces/GestureConfig.html +++ b/typedoc/interfaces/GestureConfig.html @@ -1,4 +1,4 @@ -GestureConfig | @vladmandic/human - v3.0.1
        +GestureConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -58,7 +58,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/HandConfig.html b/typedoc/interfaces/HandConfig.html index 0425d779..cc7d9cc3 100644 --- a/typedoc/interfaces/HandConfig.html +++ b/typedoc/interfaces/HandConfig.html @@ -1,4 +1,4 @@ -HandConfig | @vladmandic/human - v3.0.1
        +HandConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -156,7 +156,7 @@ for two-phase models such as face and hand caching applies to bounding boxes det

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/HandResult.html b/typedoc/interfaces/HandResult.html index 1d23f6bb..d5c40e58 100644 --- a/typedoc/interfaces/HandResult.html +++ b/typedoc/interfaces/HandResult.html @@ -1,4 +1,4 @@ -HandResult | @vladmandic/human - v3.0.1
        +HandResult | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -130,7 +130,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/ModelInfo.html b/typedoc/interfaces/ModelInfo.html index ec7e0a19..889499b0 100644 --- a/typedoc/interfaces/ModelInfo.html +++ b/typedoc/interfaces/ModelInfo.html @@ -1,4 +1,4 @@ -ModelInfo | @vladmandic/human - v3.0.1
        +ModelInfo | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -83,7 +83,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/ObjectConfig.html b/typedoc/interfaces/ObjectConfig.html index 6f985de6..c2b50b81 100644 --- a/typedoc/interfaces/ObjectConfig.html +++ b/typedoc/interfaces/ObjectConfig.html @@ -1,4 +1,4 @@ -ObjectConfig | @vladmandic/human - v3.0.1
        +ObjectConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -114,7 +114,7 @@ for two-phase models such as face and hand caching applies to bounding boxes det

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/ObjectResult.html b/typedoc/interfaces/ObjectResult.html index 0c26b2db..6f729cc8 100644 --- a/typedoc/interfaces/ObjectResult.html +++ b/typedoc/interfaces/ObjectResult.html @@ -1,4 +1,4 @@ -ObjectResult | @vladmandic/human - v3.0.1
        +ObjectResult | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -98,7 +98,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/PersonResult.html b/typedoc/interfaces/PersonResult.html index e9893110..f8663db2 100644 --- a/typedoc/interfaces/PersonResult.html +++ b/typedoc/interfaces/PersonResult.html @@ -1,4 +1,4 @@ -PersonResult | @vladmandic/human - v3.0.1
        +PersonResult | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -116,7 +116,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/Result.html b/typedoc/interfaces/Result.html index 2b06d8b3..c6542f1b 100644 --- a/typedoc/interfaces/Result.html +++ b/typedoc/interfaces/Result.html @@ -1,4 +1,4 @@ -Result | @vladmandic/human - v3.0.1
        +Result | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -147,7 +147,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/SegmentationConfig.html b/typedoc/interfaces/SegmentationConfig.html index e1fabc47..c7b5c701 100644 --- a/typedoc/interfaces/SegmentationConfig.html +++ b/typedoc/interfaces/SegmentationConfig.html @@ -1,4 +1,4 @@ -SegmentationConfig | @vladmandic/human - v3.0.1
        +SegmentationConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -110,7 +110,7 @@ for two-phase models such as face and hand caching applies to bounding boxes det

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/WebCamConfig.html b/typedoc/interfaces/WebCamConfig.html index 50c0dd10..5d5df8d8 100644 --- a/typedoc/interfaces/WebCamConfig.html +++ b/typedoc/interfaces/WebCamConfig.html @@ -1,4 +1,4 @@ -WebCamConfig | @vladmandic/human - v3.0.1
        +WebCamConfig | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -111,7 +111,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/models.KernelOps.html b/typedoc/interfaces/models.KernelOps.html index 1a08822f..5e406258 100644 --- a/typedoc/interfaces/models.KernelOps.html +++ b/typedoc/interfaces/models.KernelOps.html @@ -1,4 +1,4 @@ -KernelOps | @vladmandic/human - v3.0.1
        +KernelOps | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -72,7 +72,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/interfaces/models.ModelStats.html b/typedoc/interfaces/models.ModelStats.html index 9940ca23..01d86734 100644 --- a/typedoc/interfaces/models.ModelStats.html +++ b/typedoc/interfaces/models.ModelStats.html @@ -1,4 +1,4 @@ -ModelStats | @vladmandic/human - v3.0.1
        +ModelStats | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -93,7 +93,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/modules/Tensor.html b/typedoc/modules/Tensor.html index 0263b07f..e5902e94 100644 --- a/typedoc/modules/Tensor.html +++ b/typedoc/modules/Tensor.html @@ -1,4 +1,4 @@ -Tensor | @vladmandic/human - v3.0.1
        +Tensor | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -174,7 +174,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/modules/draw.html b/typedoc/modules/draw.html index ee5febde..cce1b551 100644 --- a/typedoc/modules/draw.html +++ b/typedoc/modules/draw.html @@ -1,4 +1,4 @@ -draw | @vladmandic/human - v3.0.1
        +draw | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -55,7 +55,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/modules/match.html b/typedoc/modules/match.html index 27e79ef0..d1fcf9ac 100644 --- a/typedoc/modules/match.html +++ b/typedoc/modules/match.html @@ -1,4 +1,4 @@ -match | @vladmandic/human - v3.0.1
        +match | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -50,7 +50,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/modules/models.html b/typedoc/modules/models.html index c91a6ba8..f614b4d7 100644 --- a/typedoc/modules/models.html +++ b/typedoc/modules/models.html @@ -1,4 +1,4 @@ -models | @vladmandic/human - v3.0.1
        +models | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -52,7 +52,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/AnyCanvas.html b/typedoc/types/AnyCanvas.html index 5dbd6172..fb782438 100644 --- a/typedoc/types/AnyCanvas.html +++ b/typedoc/types/AnyCanvas.html @@ -1,4 +1,4 @@ -AnyCanvas | @vladmandic/human - v3.0.1
        +AnyCanvas | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    AnyCanvas: HTMLCanvasElement | OffscreenCanvas
    @@ -36,7 +36,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/AnyImage.html b/typedoc/types/AnyImage.html index 01d72448..4d399e9a 100644 --- a/typedoc/types/AnyImage.html +++ b/typedoc/types/AnyImage.html @@ -1,4 +1,4 @@ -AnyImage | @vladmandic/human - v3.0.1
        +AnyImage | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    AnyImage: HTMLImageElement | typeof Image
    @@ -36,7 +36,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/AnyVideo.html b/typedoc/types/AnyVideo.html index f0d06249..86b5dfcf 100644 --- a/typedoc/types/AnyVideo.html +++ b/typedoc/types/AnyVideo.html @@ -1,4 +1,4 @@ -AnyVideo | @vladmandic/human - v3.0.1
        +AnyVideo | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    AnyVideo: HTMLMediaElement | HTMLVideoElement
    @@ -36,7 +36,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/BackendEnum.html b/typedoc/types/BackendEnum.html index 97ebd654..a37c823f 100644 --- a/typedoc/types/BackendEnum.html +++ b/typedoc/types/BackendEnum.html @@ -1,4 +1,4 @@ -BackendEnum | @vladmandic/human - v3.0.1
        +BackendEnum | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    BackendEnum: "" | "cpu" | "wasm" | "webgl" | "humangl" | "tensorflow" | "webgpu"
    @@ -36,7 +36,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/BodyAnnotation.html b/typedoc/types/BodyAnnotation.html index 28f6113d..47f8fb2d 100644 --- a/typedoc/types/BodyAnnotation.html +++ b/typedoc/types/BodyAnnotation.html @@ -1,4 +1,4 @@ -BodyAnnotation | @vladmandic/human - v3.0.1
        +BodyAnnotation | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    BodyAnnotationBlazePose: "leftLeg" | "rightLeg" | "torso" | "leftArm" | "rightArm" | "leftEye" | "rightEye" | "mouth"
    BodyAnnotationEfficientPose: "leftLeg" | "rightLeg" | "torso" | "leftArm" | "rightArm" | "head"
    BodyGesture: `leaning ${"left" | "right"}` | `raise ${"left" | "right"} hand` | "i give up"
    @@ -36,7 +36,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/BodyLandmark.html b/typedoc/types/BodyLandmark.html index 702bd87e..2027d61b 100644 --- a/typedoc/types/BodyLandmark.html +++ b/typedoc/types/BodyLandmark.html @@ -1,4 +1,4 @@ -BodyLandmark | @vladmandic/human - v3.0.1
        +BodyLandmark | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    BodyLandmarkBlazePose: "nose" | "leftEyeInside" | "leftEye" | "leftEyeOutside" | "rightEyeInside" | "rightEye" | "rightEyeOutside" | "leftEar" | "rightEar" | "leftMouth" | "rightMouth" | "leftShoulder" | "rightShoulder" | "leftElbow" | "rightElbow" | "leftWrist" | "rightWrist" | "leftPinky" | "rightPinky" | "leftIndex" | "rightIndex" | "leftThumb" | "rightThumb" | "leftHip" | "rightHip" | "leftKnee" | "rightKnee" | "leftAnkle" | "rightAnkle" | "leftHeel" | "rightHeel" | "leftFoot" | "rightFoot" | "bodyCenter" | "bodyTop" | "leftPalm" | "leftHand" | "rightPalm" | "rightHand"
    BodyLandmarkEfficientNet: "head" | "neck" | "rightShoulder" | "rightElbow" | "rightWrist" | "chest" | "leftShoulder" | "leftElbow" | "leftWrist" | "bodyCenter" | "rightHip" | "rightKnee" | "rightAnkle" | "leftHip" | "leftKnee" | "leftAnkle"
    BodyLandmarkMoveNet: "nose" | "leftEye" | "rightEye" | "leftEar" | "rightEar" | "leftShoulder" | "rightShoulder" | "leftElbow" | "rightElbow" | "leftWrist" | "rightWrist" | "leftHip" | "rightHip" | "leftKnee" | "rightKnee" | "leftAnkle" | "rightAnkle"
    BodyLandmarkPoseNet: "nose" | "leftEye" | "rightEye" | "leftEar" | "rightEar" | "leftShoulder" | "rightShoulder" | "leftElbow" | "rightElbow" | "leftWrist" | "rightWrist" | "leftHip" | "rightHip" | "leftKnee" | "rightKnee" | "leftAnkle" | "rightAnkle"
    Box: [number, number, number, number]
    @@ -36,7 +36,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/Emotion.html b/typedoc/types/Emotion.html index 0111851b..6200dfe5 100644 --- a/typedoc/types/Emotion.html +++ b/typedoc/types/Emotion.html @@ -1,4 +1,4 @@ -Emotion | @vladmandic/human - v3.0.1
        +Emotion | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    Emotion: "angry" | "disgust" | "fear" | "happy" | "sad" | "surprise" | "neutral"
    Events: "create" | "load" | "image" | "result" | "warmup" | "error"
    @@ -43,7 +43,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/ExternalCanvas.html b/typedoc/types/ExternalCanvas.html index 110bf90d..d7d85d73 100644 --- a/typedoc/types/ExternalCanvas.html +++ b/typedoc/types/ExternalCanvas.html @@ -1,4 +1,4 @@ -ExternalCanvas | @vladmandic/human - v3.0.1
        +ExternalCanvas | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    ExternalCanvas: typeof Canvas
    @@ -36,7 +36,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/FaceGesture.html b/typedoc/types/FaceGesture.html index 47058bb0..a42c5c4e 100644 --- a/typedoc/types/FaceGesture.html +++ b/typedoc/types/FaceGesture.html @@ -1,4 +1,4 @@ -FaceGesture | @vladmandic/human - v3.0.1
        +FaceGesture | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    FaceGesture: `facing ${"left" | "center" | "right"}` | `blink ${"left" | "right"} eye` | `mouth ${number}% open` | `head ${"up" | "down"}`
    @@ -36,7 +36,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/FaceLandmark.html b/typedoc/types/FaceLandmark.html index fa1ae05e..87c0436c 100644 --- a/typedoc/types/FaceLandmark.html +++ b/typedoc/types/FaceLandmark.html @@ -1,4 +1,4 @@ -FaceLandmark | @vladmandic/human - v3.0.1
        +FaceLandmark | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    FaceLandmark: "leftEye" | "rightEye" | "nose" | "mouth" | "leftEar" | "rightEar" | "symmetryLine" | "silhouette" | "lipsUpperOuter" | "lipsLowerOuter" | "lipsUpperInner" | "lipsLowerInner" | "rightEyeUpper0" | "rightEyeLower0" | "rightEyeUpper1" | "rightEyeLower1" | "rightEyeUpper2" | "rightEyeLower2" | "rightEyeLower3" | "rightEyebrowUpper" | "rightEyebrowLower" | "rightEyeIris" | "leftEyeUpper0" | "leftEyeLower0" | "leftEyeUpper1" | "leftEyeLower1" | "leftEyeUpper2" | "leftEyeLower2" | "leftEyeLower3" | "leftEyebrowUpper" | "leftEyebrowLower" | "leftEyeIris" | "midwayBetweenEyes" | "noseTip" | "noseBottom" | "noseRightCorner" | "noseLeftCorner" | "rightCheek" | "leftCheek"
    Finger: "index" | "middle" | "pinky" | "ring" | "thumb" | "palm"
    FingerCurl: "none" | "half" | "full"
    FingerDirection: "verticalUp" | "verticalDown" | "horizontalLeft" | "horizontalRight" | "diagonalUpRight" | "diagonalUpLeft" | "diagonalDownRight" | "diagonalDownLeft"
    Gender: "male" | "female" | "unknown"
    GestureResult: {
        face: number;
        gesture: FaceGesture;
    } | {
        gesture: IrisGesture;
        iris: number;
    } | {
        body: number;
        gesture: BodyGesture;
    } | {
        gesture: HandGesture;
        hand: number;
    }
    @@ -41,7 +41,7 @@ Each result has:

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/HandGesture.html b/typedoc/types/HandGesture.html index aa2c52d1..85bab5ac 100644 --- a/typedoc/types/HandGesture.html +++ b/typedoc/types/HandGesture.html @@ -1,4 +1,4 @@ -HandGesture | @vladmandic/human - v3.0.1
        +HandGesture | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    HandGesture: `${"thumb" | "index" | "middle" | "ring" | "pinky"} forward` | `${"thumb" | "index" | "middle" | "ring" | "pinky"} up` | "victory" | "thumbs up"
    @@ -36,7 +36,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/HandType.html b/typedoc/types/HandType.html index e3fb477c..d8fcdac6 100644 --- a/typedoc/types/HandType.html +++ b/typedoc/types/HandType.html @@ -1,4 +1,4 @@ -HandType | @vladmandic/human - v3.0.1
        +HandType | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    HandType: "hand" | "fist" | "pinch" | "point" | "face" | "tip" | "pinchtip"
    ImageObjects: ImageData | ImageBitmap
    @@ -36,7 +36,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/Input.html b/typedoc/types/Input.html index 139d66d1..85eb6ba0 100644 --- a/typedoc/types/Input.html +++ b/typedoc/types/Input.html @@ -1,4 +1,4 @@ -Input | @vladmandic/human - v3.0.1
        +Input | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -36,7 +36,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/IrisGesture.html b/typedoc/types/IrisGesture.html index d5182d3d..d8a66661 100644 --- a/typedoc/types/IrisGesture.html +++ b/typedoc/types/IrisGesture.html @@ -1,4 +1,4 @@ -IrisGesture | @vladmandic/human - v3.0.1
        +IrisGesture | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    IrisGesture: "facing center" | `looking ${"left" | "right" | "up" | "down"}` | "looking center"
    @@ -36,7 +36,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/ObjectType.html b/typedoc/types/ObjectType.html index 234f0405..d1707c4b 100644 --- a/typedoc/types/ObjectType.html +++ b/typedoc/types/ObjectType.html @@ -1,4 +1,4 @@ -ObjectType | @vladmandic/human - v3.0.1
        +ObjectType | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    ObjectType: "person" | "bicycle" | "car" | "motorcycle" | "airplane" | "bus" | "train" | "truck" | "boat" | "traffic light" | "fire hydrant" | "stop sign" | "parking meter" | "bench" | "bird" | "cat" | "dog" | "horse" | "sheep" | "cow" | "elephant" | "bear" | "zebra" | "giraffe" | "backpack" | "umbrella" | "handbag" | "tie" | "suitcase" | "frisbee" | "skis" | "snowboard" | "sports ball" | "kite" | "baseball bat" | "baseball glove" | "skateboard" | "surfboard" | "tennis racket" | "bottle" | "wine glass" | "cup" | "fork" | "knife" | "spoon" | "bowl" | "banana" | "apple" | "sandwich" | "orange" | "broccoli" | "carrot" | "hot dog" | "pizza" | "donut" | "cake" | "chair" | "couch" | "potted plant" | "bed" | "dining table" | "toilet" | "tv" | "laptop" | "mouse" | "remote" | "keyboard" | "cell phone" | "microwave" | "oven" | "toaster" | "sink" | "refrigerator" | "book" | "clock" | "vase" | "scissors" | "teddy bear" | "hair drier" | "toothbrush"
    Point: [number, number, number?]
    @@ -36,7 +36,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/Race.html b/typedoc/types/Race.html index 439557c0..67bfafcd 100644 --- a/typedoc/types/Race.html +++ b/typedoc/types/Race.html @@ -1,4 +1,4 @@ -Race | @vladmandic/human - v3.0.1
        +Race | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    Race: "white" | "black" | "asian" | "indian" | "other"
    SegmentationEnum: "default" | "alpha" | "foreground" | "state"
    @@ -36,7 +36,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/Tensor4D.html b/typedoc/types/Tensor4D.html index 427556de..0ed27aab 100644 --- a/typedoc/types/Tensor4D.html +++ b/typedoc/types/Tensor4D.html @@ -1,4 +1,4 @@ -Tensor4D | @vladmandic/human - v3.0.1
        +Tensor4D | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    Tensor4D: Tensor<R4>
    @@ -37,7 +37,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/WarmupEnum.html b/typedoc/types/WarmupEnum.html index c8bab1c5..6a560f9a 100644 --- a/typedoc/types/WarmupEnum.html +++ b/typedoc/types/WarmupEnum.html @@ -1,4 +1,4 @@ -WarmupEnum | @vladmandic/human - v3.0.1
        +WarmupEnum | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    WarmupEnum: "" | "none" | "face" | "full" | "body"
    @@ -36,7 +36,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/match.Descriptor.html b/typedoc/types/match.Descriptor.html index 6937340b..fde81b91 100644 --- a/typedoc/types/match.Descriptor.html +++ b/typedoc/types/match.Descriptor.html @@ -1,4 +1,4 @@ -Descriptor | @vladmandic/human - v3.0.1
        +Descriptor | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -37,7 +37,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/types/match.MatchOptions.html b/typedoc/types/match.MatchOptions.html index 16ed686a..a1a147bb 100644 --- a/typedoc/types/match.MatchOptions.html +++ b/typedoc/types/match.MatchOptions.html @@ -1,4 +1,4 @@ -MatchOptions | @vladmandic/human - v3.0.1
        +MatchOptions | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -35,7 +35,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/variables/defaults.html b/typedoc/variables/defaults.html index 0e0f61d3..c9667f73 100644 --- a/typedoc/variables/defaults.html +++ b/typedoc/variables/defaults.html @@ -1,4 +1,4 @@ -defaults | @vladmandic/human - v3.0.1
        +defaults | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    defaults: Config = ...
    @@ -38,7 +38,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/variables/draw.options.html b/typedoc/variables/draw.options.html index c3cf98c1..6e7a952b 100644 --- a/typedoc/variables/draw.options.html +++ b/typedoc/variables/draw.options.html @@ -1,4 +1,4 @@ -options | @vladmandic/human - v3.0.1
        +options | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2
    @@ -37,7 +37,7 @@

    Modules

      -
    • @vladmandic/human - v3.0.1 +
    • @vladmandic/human - v3.0.2
      • Tensor
      • draw
      • diff --git a/typedoc/variables/env-1.html b/typedoc/variables/env-1.html index b023707c..0db215a7 100644 --- a/typedoc/variables/env-1.html +++ b/typedoc/variables/env-1.html @@ -1,4 +1,4 @@ -env | @vladmandic/human - v3.0.1
        +env | @vladmandic/human - v3.0.2
        • Preparing search index...
        • -
        • The search index is not available
        @vladmandic/human - v3.0.1
        +
      • The search index is not available
      @vladmandic/human - v3.0.2