alphavalid-sdk 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/alphavalid.js CHANGED
@@ -35,7 +35,17 @@ function copyModels() {
35
35
  try {
36
36
  const projectRoot = process.cwd();
37
37
  const sdkRoot = path.join(__dirname, '..');
38
- const loaderSrc = path.join(sdkRoot, 'demo', 'public', 'images', 'alphaloader.gif');
38
+
39
+ // Primeiro tenta usar o GIF empacotado em public/images dentro do SDK publicado.
40
+ let loaderSrc = path.join(sdkRoot, 'public', 'images', 'alphaloader.gif');
41
+
42
+ // Fallback para ambiente de desenvolvimento (monorepo), onde o GIF pode estar na pasta demo.
43
+ if (!fs.existsSync(loaderSrc)) {
44
+ const demoLoader = path.join(sdkRoot, 'demo', 'public', 'images', 'alphaloader.gif');
45
+ if (fs.existsSync(demoLoader)) {
46
+ loaderSrc = demoLoader;
47
+ }
48
+ }
39
49
 
40
50
  if (fs.existsSync(loaderSrc)) {
41
51
  // Angular: src/assets/images
@@ -48,14 +58,18 @@ try {
48
58
 
49
59
  // Vite / SPA genérica: public/images
50
60
  const viteImages = path.join(projectRoot, 'public', 'images');
51
- if (fs.existsSync(path.join(projectRoot, 'vite.config.js')) || fs.existsSync(path.join(projectRoot, 'vite.config.ts')) || fs.existsSync(path.join(projectRoot, 'index.html'))) {
61
+ if (
62
+ fs.existsSync(path.join(projectRoot, 'vite.config.js')) ||
63
+ fs.existsSync(path.join(projectRoot, 'vite.config.ts')) ||
64
+ fs.existsSync(path.join(projectRoot, 'index.html'))
65
+ ) {
52
66
  fs.mkdirSync(viteImages, { recursive: true });
53
67
  fs.copyFileSync(loaderSrc, path.join(viteImages, 'alphaloader.gif'));
54
68
  console.log('[AlphaValid] Loader GIF copiado para', viteImages);
55
69
  }
56
70
  }
57
71
  } catch (e) {
58
- // silencioso: se falhar, o app pode configurar loader.src manualmente
72
+ // silencioso: se falhar, o app pode configurar loader.src manualmente ou confiar no fallback interno do SDK
59
73
  }
60
74
 
61
75
  try {
@@ -19140,15 +19140,17 @@ function O_(e) {
19140
19140
  }
19141
19141
  //#endregion
19142
19142
  //#region src/ui/loader.ts
19143
- var k_ = "/images/alphaloader.gif";
19144
- function A_(e, t = {}) {
19143
+ var k_ = "/assets/images/alphaloader.gif", A_ = "data:image/gif;base64,R0lGODlhAQABAAAAACw=";
19144
+ function j_(e, t = {}) {
19145
19145
  let n = t.src ?? k_, r = t.sizePx ?? 120, i = t.minVisibleMs ?? 900, a = null, o = 0, s = null, c = () => {
19146
19146
  getComputedStyle(e).position === "static" && (e.style.position = "relative");
19147
19147
  }, l = () => {
19148
19148
  if (a) return a;
19149
19149
  c(), a = document.createElement("div"), a.className = "alphavalid-camera-loader", a.style.position = "absolute", a.style.inset = "0", a.style.display = "flex", a.style.alignItems = "center", a.style.justifyContent = "center", a.style.background = "transparent", a.style.zIndex = "999";
19150
19150
  let t = document.createElement("img");
19151
- return t.alt = "Carregando...", t.src = n, t.style.width = `${r}px`, t.style.height = `${r}px`, a.appendChild(t), e.appendChild(a), a;
19151
+ return t.alt = "Carregando...", t.style.width = `${r}px`, t.style.height = `${r}px`, t.onerror = () => {
19152
+ t.onerror = null, t.src = A_;
19153
+ }, t.src = n, a.appendChild(t), e.appendChild(a), a;
19152
19154
  };
19153
19155
  return {
19154
19156
  show: () => {
@@ -19172,12 +19174,12 @@ function A_(e, t = {}) {
19172
19174
  }
19173
19175
  //#endregion
19174
19176
  //#region src/ui/captureButtonCoxinha.ts
19175
- function j_(e) {
19177
+ function M_(e) {
19176
19178
  getComputedStyle(e).position === "static" && (e.style.position = "relative");
19177
19179
  }
19178
- function M_(e) {
19180
+ function N_(e) {
19179
19181
  let { container: t, text: n, color: r, onClick: i } = e;
19180
- j_(t);
19182
+ M_(t);
19181
19183
  let a = document.createElement("button");
19182
19184
  return a.type = "button", a.className = "alphavalid-captureBtn", a.textContent = n ?? "Capturar imagem", a.style.position = "absolute", a.style.left = "50%", a.style.bottom = "calc(env(safe-area-inset-bottom, 0px) + 24px)", a.style.transform = "translateX(-50%)", a.style.width = "88%", a.style.maxWidth = "340px", a.style.height = "56px", a.style.borderRadius = "18px", a.style.border = "none", a.style.background = r ?? "#00bcd4", a.style.color = "#fff", a.style.fontWeight = "800", a.style.fontSize = "1.05rem", a.style.cursor = "pointer", a.style.zIndex = "999998", a.style.boxShadow = "0 10px 22px rgba(0,0,0,0.28)", a.style.touchAction = "manipulation", a.style["-webkit-tap-highlight-color"] = "transparent", a.addEventListener("click", (e) => {
19183
19185
  e.preventDefault(), e.stopPropagation(), !a.disabled && i();
@@ -19198,7 +19200,7 @@ function M_(e) {
19198
19200
  }
19199
19201
  //#endregion
19200
19202
  //#region src/ui/baseStyles.ts
19201
- function N_(e) {
19203
+ function P_(e) {
19202
19204
  if (!(typeof document > "u")) {
19203
19205
  if (!document.getElementById("alphavalid-base-styles")) {
19204
19206
  let e = document.createElement("style");
@@ -19211,8 +19213,8 @@ function N_(e) {
19211
19213
  }
19212
19214
  //#endregion
19213
19215
  //#region src/index.ts
19214
- var P_ = ["/assets/alphavalid-models", "/alphavalid-models"], F_ = "cameraContainer";
19215
- async function I_(e) {
19216
+ var F_ = ["/assets/alphavalid-models", "/alphavalid-models"], I_ = "cameraContainer";
19217
+ async function L_(e) {
19216
19218
  for (let t of [
19217
19219
  "face_landmark_68_tiny_model-weights_manifest.json",
19218
19220
  "face_landmark_68_tiny_model-shard1.bin",
@@ -19225,11 +19227,11 @@ async function I_(e) {
19225
19227
  }
19226
19228
  return e;
19227
19229
  }
19228
- async function L_() {
19230
+ async function R_() {
19229
19231
  let { setupModels: e } = await import("./setupModels-RA6BN3uf.mjs");
19230
19232
  return e();
19231
19233
  }
19232
- var R_ = class {
19234
+ var z_ = class {
19233
19235
  _camera = null;
19234
19236
  _overlay = null;
19235
19237
  _container = null;
@@ -19305,7 +19307,7 @@ var R_ = class {
19305
19307
  this._captureBtn && this._disposeCaptureButton();
19306
19308
  return;
19307
19309
  }
19308
- this._captureBtn ||= M_({
19310
+ this._captureBtn ||= N_({
19309
19311
  container: this._container,
19310
19312
  text: t.captureButton?.text ?? "Capturar imagem",
19311
19313
  color: t.captureButton?.color ?? "#00bcd4",
@@ -19430,8 +19432,8 @@ var R_ = class {
19430
19432
  async start(e) {
19431
19433
  if (this._lifecycle === "running" || this._lifecycle === "preview") return;
19432
19434
  this._debug = typeof e.debug == "boolean" ? e.debug : !!e.debug?.enabled;
19433
- let t = e.container ?? document.getElementById(F_);
19434
- if (!t) throw Error(`[AlphaValid] Container nao encontrado. Informe options.container ou crie <div id="${F_}"></div>.`);
19435
+ let t = e.container ?? document.getElementById(I_);
19436
+ if (!t) throw Error(`[AlphaValid] Container nao encontrado. Informe options.container ou crie <div id="${I_}"></div>.`);
19435
19437
  n(t, "options.container");
19436
19438
  let r = e.liveness;
19437
19439
  if (e.livenessPreset) {
@@ -19474,9 +19476,9 @@ var R_ = class {
19474
19476
  let s = t;
19475
19477
  if (!s) throw Error("[AlphaValid] Container nao encontrado apos inicializacao.");
19476
19478
  try {
19477
- N_(s);
19479
+ P_(s);
19478
19480
  } catch {}
19479
- o.loader?.enabled !== !1 && (this._loader?.dispose(), this._loader = A_(s, o.loader), this._loader.show()), this._disposeCaptureButton(), this._status = "initializing", o.onStateChange?.({
19481
+ o.loader?.enabled !== !1 && (this._loader?.dispose(), this._loader = j_(s, o.loader), this._loader.show()), this._disposeCaptureButton(), this._status = "initializing", o.onStateChange?.({
19480
19482
  status: this._status,
19481
19483
  feedback: {
19482
19484
  code: "INITIALIZING",
@@ -19497,15 +19499,18 @@ var R_ = class {
19497
19499
  message: "Inicializando câmera..."
19498
19500
  }), this._camera = await i(s), this._setVideoVisibility(!1), o.uiMode !== "headless" && o.overlay !== !1 && (o.uiMode === "Mobile" ? this._overlay = T_(s) : this._overlay = u(s, o.guideCircleRatio));
19499
19501
  let t = o.modelsPath;
19500
- if (t) await I_(t);
19501
- else {
19502
- for (let n of P_) try {
19503
- await I_(n), t = n, e.debug && console.log(`[AlphaValid] Models encontrados em: ${n}`);
19504
- break;
19502
+ t && t.trim() === "" && (t = void 0);
19503
+ let n = await (async () => {
19504
+ let e = t;
19505
+ if (e) try {
19506
+ return await L_(e), e;
19505
19507
  } catch {}
19506
- if (!t) throw Error("\n[AlphaValid] Models não encontrados.\n\nExecute automaticamente:\nnpx alphavalid-sdk setup\n\nOu configure manualmente:\nmodelsPath: '/assets/alphavalid-models'\n");
19507
- }
19508
- await this._faceDetector.load(t), this._loader?.hide(), this._setVideoVisibility(!0), this._syncCaptureButton(null), o.onReady?.(), this._status = "running", this._setLifecycle("running"), this.startDetectionLoop();
19508
+ for (let e of F_) try {
19509
+ return await L_(e), e;
19510
+ } catch {}
19511
+ throw Error("\n[AlphaValid] Models não encontrados.\n\nExecute automaticamente (Angular / Vite):\nnpx alphavalid-sdk setup\n\nOu configure manualmente no start():\nmodelsPath: '/assets/alphavalid-models'\n");
19512
+ })();
19513
+ e.debug && console.log("[AlphaValid] modelsPath resolvido:", n), await this._faceDetector.load(n), this._loader?.hide(), this._setVideoVisibility(!0), this._syncCaptureButton(null), o.onReady?.(), this._status = "running", this._setLifecycle("running"), this.startDetectionLoop();
19509
19514
  } catch (e) {
19510
19515
  this._loader?.hide(), this._disposeCaptureButton(), this._setVideoVisibility(!1), this._status = "error";
19511
19516
  let t = e, n = t && typeof t == "object" && typeof t.code == "string" && typeof t.message == "string" ? t : {
@@ -20053,4 +20058,4 @@ var R_ = class {
20053
20058
  }
20054
20059
  };
20055
20060
  //#endregion
20056
- export { R_ as AlphaValid, L_ as setupModels };
20061
+ export { z_ as AlphaValid, R_ as setupModels };
@@ -3801,7 +3801,7 @@ Manifest JSON has weights with names: `+s.join(`, `)+`.`);return l=t.reduce((fun
3801
3801
  Actual: `+c+`.
3802
3802
  Expected: `+l+`.`);for(var u=0;u<l.length;++u){var d=c[u],f=l[u];if(!n(d,f))throw Error(`Arrays differ: actual[`+u+`] = `+d+`, expected[`+u+`] = `+f+`.
3803
3803
  Actual: `+c+`.
3804
- Expected: `+l+`.`)}}function cp(e,t,n){return!isFinite(e)&&!isFinite(t)||!(isNaN(e)||isNaN(t)||Math.abs(e-t)>n)}Object.freeze({TEST_EPSILON_FLOAT16:ap,expectArraysClose:function(e,t,n){return n??=op(),sp(e,t,(function(e,t){return cp(e,t,n)}))},testEpsilon:op,expectPromiseToFail:function(e,t){e().then((function(){return t.fail()}),(function(){return t()}))},expectArraysEqual:function(e,t){var n=typeof t==`string`||typeof t==`number`||typeof t==`boolean`?[t]:t;return we(e)||we(e[0])||we(t)||we(t[0])?sp(e,n,(function(e,t){return e==t})):sp(e,t,(function(e,t){return cp(e,t,0)}))},expectNumbersClose:function(e,t,n){if(n??=op(),!cp(e,t,n))throw Error(`Numbers differ: actual === `+e+`, expected === `+t)},expectValuesInRange:function(e,t,n){for(var r=0;r<e.length;r++)if(e[r]<t||e[r]>n)throw Error(`Value out of range:`+e[r]+` low: `+t+`, high: `+n)},expectArrayBuffersEqual:function(e,t){expect(new Float32Array(e)).toEqual(new Float32Array(t))}}),Object.freeze({gpgpu_util:jo,webgl_util:yn,forceHalfFloat:function(){O().set(`WEBGL_FORCE_F16_TEXTURES`,!0)},MathBackendWebGL:Ys,setWebGLContext:St,GPGPUContext:Mo});var lp=function(e){function t(){return e!==null&&e.apply(this,arguments)||this}return C(t,e),t.prototype.minimize=function(e,t,n){t===void 0&&(t=!1);var r=this.computeGradients(e,n),i=r.value,a=r.grads;if(n!=null){var o=n.map((function(e){return{name:e.name,tensor:a[e.name]}}));this.applyGradients(o)}else this.applyGradients(a);return xn(a),t?i:(i.dispose(),null)},Object.defineProperty(t.prototype,`iterations`,{get:function(){return this.iterations_??=0,this.iterations_},enumerable:!0,configurable:!0}),t.prototype.incrementIterations=function(){this.iterations_=this.iterations+1},t.prototype.computeGradients=function(e,t){return fi(e,t)},t.prototype.dispose=function(){this.iterations_!=null&&xn(this.iterations_)},t.prototype.saveIterations=function(){return w(this,void 0,void 0,(function(){return T(this,(function(e){return this.iterations_??=0,[2,{name:`iter`,tensor:q(this.iterations_,`int32`)}]}))}))},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){return T(this,(function(e){throw Error(`getWeights() is not implemented for this optimizer yet.`)}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){return T(this,(function(e){throw Error(`setWeights() is not implemented for this optimizer class `+this.getClassName())}))}))},t.prototype.extractIterations=function(e){return w(this,void 0,void 0,(function(){var t;return T(this,(function(n){switch(n.label){case 0:return t=this,[4,e[0].tensor.data()];case 1:return t.iterations_=n.sent()[0],[2,e.slice(1)]}}))}))},t}(tp);Object.defineProperty(lp,Symbol.hasInstance,{value:function(e){return e.minimize!=null&&e.computeGradients!=null&&e.applyGradients!=null}});var up=function(e){function t(t,n,r){r===void 0&&(r=null);var i=e.call(this)||this;return i.learningRate=t,i.rho=n,i.epsilon=r,i.accumulatedGrads=[],i.accumulatedUpdates=[],r??(i.epsilon=V.backend.epsilon()),i}return C(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=V.registeredVariables[n];t.accumulatedGrads[r]??(t.accumulatedGrads[r]={originalName:n+`/accum_grad`,variable:W((function(){return tr(i).variable(!1)}))}),t.accumulatedUpdates[r]??(t.accumulatedUpdates[r]={originalName:n+`/accum_var`,variable:W((function(){return tr(i).variable(!1)}))});var a=Array.isArray(e)?e[r].tensor:e[n];if(a!=null){var o=t.accumulatedGrads[r].variable,s=t.accumulatedUpdates[r].variable;W((function(){var e=o.mul(t.rho).add(a.square().mul(1-t.rho)),n=s.add(t.epsilon).sqrt().div(o.add(t.epsilon).sqrt()).mul(a),r=s.mul(t.rho).add(n.square().mul(1-t.rho));o.assign(e),s.assign(r);var c=n.mul(-t.learningRate).add(i);i.assign(c)}))}})),this.incrementIterations()},t.prototype.dispose=function(){this.accumulatedUpdates!=null&&(xn(this.accumulatedGrads.map((function(e){return e.variable}))),xn(this.accumulatedUpdates.map((function(e){return e.variable}))))},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){var e;return T(this,(function(t){switch(t.label){case 0:return e=this.accumulatedGrads.concat(this.accumulatedUpdates),[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(e.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){var t;return T(this,(function(n){switch(n.label){case 0:return[4,this.extractIterations(e)];case 1:return e=n.sent(),t=e.length/2,this.accumulatedGrads=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.accumulatedUpdates=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,rho:this.rho,epsilon:this.epsilon}},t.fromConfig=function(e,t){return new e(t.learningRate,t.rho,t.epsilon)},t.className=`Adadelta`,t}(lp);rp(up);var dp=function(e){function t(t,n){n===void 0&&(n=.1);var r=e.call(this)||this;return r.learningRate=t,r.initialAccumulatorValue=n,r.accumulatedGrads=[],r}return C(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=V.registeredVariables[n];t.accumulatedGrads[r]??(t.accumulatedGrads[r]={originalName:n+`/accumulator`,variable:W((function(){return Zn(i.shape,t.initialAccumulatorValue).variable(!1)}))});var a=Array.isArray(e)?e[r].tensor:e[n];if(a!=null){var o=t.accumulatedGrads[r].variable;W((function(){var e=o.add(a.square());o.assign(e);var n=a.div(e.add(V.backend.epsilon()).sqrt()).mul(-t.learningRate).add(i);i.assign(n)}))}})),this.incrementIterations()},t.prototype.dispose=function(){this.accumulatedGrads!=null&&xn(this.accumulatedGrads.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){return T(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(this.accumulatedGrads.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){return T(this,(function(t){switch(t.label){case 0:return[4,this.extractIterations(e)];case 1:return e=t.sent(),this.accumulatedGrads=e.map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,initialAccumulatorValue:this.initialAccumulatorValue}},t.fromConfig=function(e,t){return new e(t.learningRate,t.initialAccumulatorValue)},t.className=`Adagrad`,t}(lp);rp(dp);var fp=function(e){function t(t,n,r,i){i===void 0&&(i=null);var a=e.call(this)||this;return a.learningRate=t,a.beta1=n,a.beta2=r,a.epsilon=i,a.accumulatedFirstMoment=[],a.accumulatedSecondMoment=[],W((function(){a.accBeta1=q(n).variable(),a.accBeta2=q(r).variable()})),i??(a.epsilon=V.backend.epsilon()),a}return C(t,e),t.prototype.applyGradients=function(e){var t=this,n=Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e);W((function(){var r=vl(1,t.accBeta1),i=vl(1,t.accBeta2);n.forEach((function(n,a){var o=V.registeredVariables[n];t.accumulatedFirstMoment[a]??(t.accumulatedFirstMoment[a]={originalName:n+`/m`,variable:W((function(){return tr(o).variable(!1)}))}),t.accumulatedSecondMoment[a]??(t.accumulatedSecondMoment[a]={originalName:n+`/v`,variable:W((function(){return tr(o).variable(!1)}))});var s=Array.isArray(e)?e[a].tensor:e[n];if(s!=null){var c=t.accumulatedFirstMoment[a].variable,l=t.accumulatedSecondMoment[a].variable,u=c.mul(t.beta1).add(s.mul(1-t.beta1)),d=l.mul(t.beta2).add(s.square().mul(1-t.beta2)),f=u.div(r),p=d.div(i);c.assign(u),l.assign(d);var m=f.div(p.sqrt().add(t.epsilon)).mul(-t.learningRate).add(o);o.assign(m)}})),t.accBeta1.assign(t.accBeta1.mul(t.beta1)),t.accBeta2.assign(t.accBeta2.mul(t.beta2))})),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.accBeta2.dispose(),this.accumulatedFirstMoment!=null&&xn(this.accumulatedFirstMoment.map((function(e){return e.variable}))),this.accumulatedSecondMoment!=null&&xn(this.accumulatedSecondMoment.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){var e;return T(this,(function(t){switch(t.label){case 0:return e=this.accumulatedFirstMoment.concat(this.accumulatedSecondMoment),[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(e.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){var t,n=this;return T(this,(function(r){switch(r.label){case 0:return[4,this.extractIterations(e)];case 1:return e=r.sent(),W((function(){n.accBeta1.assign(hl(n.beta1,n.iterations_+1)),n.accBeta2.assign(hl(n.beta2,n.iterations_+1))})),t=e.length/2,this.accumulatedFirstMoment=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.accumulatedSecondMoment=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon}},t.fromConfig=function(e,t){return new e(t.learningRate,t.beta1,t.beta2,t.epsilon)},t.className=`Adam`,t}(lp);rp(fp);var pp=function(e){function t(t,n,r,i,a){i===void 0&&(i=null),a===void 0&&(a=0);var o=e.call(this)||this;return o.learningRate=t,o.beta1=n,o.beta2=r,o.epsilon=i,o.decay=a,o.accumulatedFirstMoment=[],o.accumulatedWeightedInfNorm=[],W((function(){o.iteration=q(0).variable(),o.accBeta1=q(n).variable()})),i??(o.epsilon=V.backend.epsilon()),o}return C(t,e),t.prototype.applyGradients=function(e){var t=this,n=Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e);W((function(){var r=vl(1,t.accBeta1),i=rl(-t.learningRate,t.iteration.mul(t.decay).add(1));n.forEach((function(n,a){var o=V.registeredVariables[n];t.accumulatedFirstMoment[a]??(t.accumulatedFirstMoment[a]={originalName:n+`/m`,variable:tr(o).variable(!1)}),t.accumulatedWeightedInfNorm[a]??(t.accumulatedWeightedInfNorm[a]={originalName:n+`/v`,variable:tr(o).variable(!1)});var s=Array.isArray(e)?e[a].tensor:e[n];if(s!=null){var c=t.accumulatedFirstMoment[a].variable,l=t.accumulatedWeightedInfNorm[a].variable,u=c.mul(t.beta1).add(s.mul(1-t.beta1)),d=l.mul(t.beta2),f=s.abs(),p=d.maximum(f);c.assign(u),l.assign(p);var m=i.div(r).mul(u.div(p.add(t.epsilon))).add(o);o.assign(m)}})),t.iteration.assign(t.iteration.add(1)),t.accBeta1.assign(t.accBeta1.mul(t.beta1))})),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.iteration.dispose(),this.accumulatedFirstMoment!=null&&xn(this.accumulatedFirstMoment.map((function(e){return e.variable}))),this.accumulatedWeightedInfNorm!=null&&xn(this.accumulatedWeightedInfNorm.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){return T(this,(function(e){throw Error(`getWeights() is not implemented for Adamax yet.`)}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){return T(this,(function(e){throw Error(`setWeights() is not implemented for Adamax yet.`)}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon,decay:this.decay}},t.fromConfig=function(e,t){return new e(t.learningRate,t.beta1,t.beta2,t.epsilon,t.decay)},t.className=`Adamax`,t}(lp);rp(pp);var mp=function(e){function t(t){var n=e.call(this)||this;return n.learningRate=t,n.setLearningRate(t),n}return C(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=Array.isArray(e)?e[r].tensor:e[n];if(i!=null){var a=V.registeredVariables[n];W((function(){var e=t.c.mul(i).add(a);a.assign(e)}))}})),this.incrementIterations()},t.prototype.setLearningRate=function(e){this.learningRate=e,this.c!=null&&this.c.dispose(),this.c=Sn(q(-e))},t.prototype.dispose=function(){this.c.dispose()},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){return T(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()]]}}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){return T(this,(function(t){switch(t.label){case 0:return[4,this.extractIterations(e)];case 1:if((e=t.sent()).length!==0)throw Error(`SGD optimizer does not have settable weights.`);return[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate}},t.fromConfig=function(e,t){return new e(t.learningRate)},t.className=`SGD`,t}(lp);rp(mp);var hp=function(e){function t(t,n,r){r===void 0&&(r=!1);var i=e.call(this,t)||this;return i.learningRate=t,i.momentum=n,i.useNesterov=r,i.accumulations=[],i.m=q(i.momentum),i}return C(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=V.registeredVariables[n];t.accumulations[r]??(t.accumulations[r]={originalName:n+`/momentum`,variable:W((function(){return tr(i).variable(!1)}))});var a=t.accumulations[r].variable,o=Array.isArray(e)?e[r].tensor:e[n];o!=null&&W((function(){var e,n=t.m.mul(a).add(o);e=t.useNesterov?t.c.mul(o.add(n.mul(t.m))).add(i):t.c.mul(n).add(i),a.assign(n),i.assign(e)}))})),this.incrementIterations()},t.prototype.dispose=function(){this.m.dispose(),this.accumulations!=null&&xn(this.accumulations.map((function(e){return e.variable})))},t.prototype.setMomentum=function(e){this.momentum=e},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){return T(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(this.accumulations.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){return T(this,(function(t){switch(t.label){case 0:return[4,this.extractIterations(e)];case 1:return e=t.sent(),this.accumulations=e.map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,momentum:this.momentum,useNesterov:this.useNesterov}},t.fromConfig=function(e,t){return new e(t.learningRate,t.momentum,t.useNesterov)},t.className=`Momentum`,t}(mp);rp(hp);var gp=function(e){function t(t,n,r,i,a){n===void 0&&(n=.9),r===void 0&&(r=0),i===void 0&&(i=null),a===void 0&&(a=!1);var o=e.call(this)||this;if(o.learningRate=t,o.decay=n,o.momentum=r,o.epsilon=i,o.accumulatedMeanSquares=[],o.accumulatedMoments=[],o.accumulatedMeanGrads=[],o.centered=a,i??(o.epsilon=V.backend.epsilon()),t==null)throw Error(`learningRate for RMSPropOptimizer must be defined.`);return o}return C(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=V.registeredVariables[n];t.accumulatedMeanSquares[r]??(t.accumulatedMeanSquares[r]={originalName:n+`/rms`,variable:W((function(){return tr(i).variable(!1)}))}),t.accumulatedMoments[r]??(t.accumulatedMoments[r]={originalName:n+`/momentum`,variable:W((function(){return tr(i).variable(!1)}))}),t.accumulatedMeanGrads[r]==null&&t.centered&&(t.accumulatedMeanGrads[r]={originalName:n+`/mg`,variable:W((function(){return tr(i).variable(!1)}))});var a=Array.isArray(e)?e[r].tensor:e[n];if(a!=null){var o=t.accumulatedMeanSquares[r].variable,s=t.accumulatedMoments[r].variable;W((function(){var e=o.mul(t.decay).add(a.square().mul(1-t.decay));if(t.centered){var n=t.accumulatedMeanGrads[r].variable,c=n.mul(t.decay).add(a.mul(1-t.decay)),l=s.mul(t.momentum).add(a.mul(t.learningRate).div(e.sub(c.square().add(t.epsilon)).sqrt()));o.assign(e),n.assign(c),s.assign(l);var u=i.sub(l);i.assign(u)}else{var d=o.mul(t.decay).add(a.square().mul(1-t.decay));l=s.mul(t.momentum).add(a.mul(t.learningRate).div(d.add(t.epsilon).sqrt())),o.assign(d),s.assign(l),u=i.sub(l),i.assign(u)}}))}})),this.incrementIterations()},t.prototype.dispose=function(){this.accumulatedMeanSquares!=null&&xn(this.accumulatedMeanSquares.map((function(e){return e.variable}))),this.accumulatedMeanGrads!=null&&this.centered&&xn(this.accumulatedMeanGrads.map((function(e){return e.variable}))),this.accumulatedMoments!=null&&xn(this.accumulatedMoments.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){var e;return T(this,(function(t){switch(t.label){case 0:return e=this.accumulatedMeanSquares.concat(this.accumulatedMoments),this.centered&&e.push.apply(e,this.accumulatedMeanGrads),[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(e.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){var t;return T(this,(function(n){switch(n.label){case 0:return[4,this.extractIterations(e)];case 1:return e=n.sent(),t=this.centered?e.length/3:e.length/2,this.accumulatedMeanSquares=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.accumulatedMoments=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.centered&&(this.accumulatedMeanGrads=e.slice(2*t,3*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}}))),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,decay:this.decay,momentum:this.momentum,epsilon:this.epsilon,centered:this.centered}},t.fromConfig=function(e,t){return new e(t.learningRate,t.decay,t.momentum,t.epsilon,t.centered)},t.className=`RMSProp`,t}(lp);rp(gp);var _p=function(){function e(){}return e.sgd=function(e){return new mp(e)},e.momentum=function(e,t,n){return n===void 0&&(n=!1),new hp(e,t,n)},e.rmsprop=function(e,t,n,r,i){return t===void 0&&(t=.9),n===void 0&&(n=0),r===void 0&&(r=null),i===void 0&&(i=!1),new gp(e,t,n,r,i)},e.adam=function(e,t,n,r){return e===void 0&&(e=.001),t===void 0&&(t=.9),n===void 0&&(n=.999),r===void 0&&(r=null),new fp(e,t,n,r)},e.adadelta=function(e,t,n){return e===void 0&&(e=.001),t===void 0&&(t=.95),n===void 0&&(n=null),new up(e,t,n)},e.adamax=function(e,t,n,r,i){return e===void 0&&(e=.002),t===void 0&&(t=.9),n===void 0&&(n=.999),r===void 0&&(r=null),i===void 0&&(i=0),new pp(e,t,n,r,i)},e.adagrad=function(e,t){return t===void 0&&(t=.1),new dp(e,t)},e}();_p.sgd,_p.momentum,_p.adadelta,_p.adagrad,_p.rmsprop,_p.adamax,_p.adam,$e.prototype.squaredDifference=function(e){return Qs(this,e)},B=zd;function vp(e,t,n){if(n===void 0&&(n=!1),e.beginPath(),t.slice(1).forEach(function(n,r){var i=n.x,a=n.y,o=t[r];e.moveTo(o.x,o.y),e.lineTo(i,a)}),n){var r=t[t.length-1],i=t[0];if(!r||!i)return;e.moveTo(r.x,r.y),e.lineTo(i.x,i.y)}e.stroke()}var yp=function(e,t){return yp=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])},yp(e,t)};function Z(e,t){yp(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}var bp=function(){return bp=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},bp.apply(this,arguments)};function Q(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})}function $(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(o){if(r)throw TypeError(`Generator is already executing.`);for(;n;)try{if(r=1,i&&(a=o[0]&2?i.return:o[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,o[1])).done)return a;switch(i=0,a&&(o=[o[0]&2,a.value]),o[0]){case 0:case 1:a=o;break;case 4:return n.label++,{value:o[1],done:!1};case 5:n.label++,i=o[1],o=[0];continue;case 7:o=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(o[0]===6||o[0]===2)){n=0;continue}if(o[0]===3&&(!a||o[1]>a[0]&&o[1]<a[3])){n.label=o[1];break}if(o[0]===6&&n.label<a[1]){n.label=a[1],a=o;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(o);break}a[2]&&n.ops.pop(),n.trys.pop();continue}o=t.call(e,n)}catch(e){o=[6,e],i=0}finally{r=a=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}}function xp(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var r=Array(e),i=0,t=0;t<n;t++)for(var a=arguments[t],o=0,s=a.length;o<s;o++,i++)r[i]=a[o];return r}var Sp=function(){function e(e,t){if(!Pp(e)||!Pp(t))throw Error(`Dimensions.constructor - expected width and height to be valid numbers, instead have `+JSON.stringify({width:e,height:t}));this._width=e,this._height=t}return Object.defineProperty(e.prototype,`width`,{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`height`,{get:function(){return this._height},enumerable:!0,configurable:!0}),e.prototype.reverse=function(){return new e(1/this.width,1/this.height)},e}();function Cp(e,t){return e instanceof $e&&e.shape.length===t}function wp(e){return Cp(e,2)}function Tp(e){return Cp(e,3)}function Ep(e){return Cp(e,4)}function Dp(e){return e%1!=0}function Op(e){return e%2==0}function kp(e,t){t===void 0&&(t=2);var n=10**t;return Math.floor(e*n)/n}function Ap(e){return e&&e.width&&e.height}function jp(e,t){var n=e.width,r=e.height,i=t/Math.max(r,n);return new Sp(Math.round(n*i),Math.round(r*i))}function Mp(e){return e.reduce(function(e,t){return e.add(t)},new Ip(0,0)).div(new Ip(e.length,e.length))}function Np(e,t,n){return Array(e).fill(0).map(function(e,r){return t+r*n})}function Pp(e){return!!e&&e!==1/0&&e!==-1/0&&!isNaN(e)||e===0}function Fp(e){return Pp(e)&&0<=e&&e<=1}var Ip=function(){function e(e,t){this._x=e,this._y=t}return Object.defineProperty(e.prototype,`x`,{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`y`,{get:function(){return this._y},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return new e(this.x+t.x,this.y+t.y)},e.prototype.sub=function(t){return new e(this.x-t.x,this.y-t.y)},e.prototype.mul=function(t){return new e(this.x*t.x,this.y*t.y)},e.prototype.div=function(t){return new e(this.x/t.x,this.y/t.y)},e.prototype.abs=function(){return new e(Math.abs(this.x),Math.abs(this.y))},e.prototype.magnitude=function(){return Math.sqrt(this.x**2+this.y**2)},e.prototype.floor=function(){return new e(Math.floor(this.x),Math.floor(this.y))},e}(),Lp=function(){function e(t,n){n===void 0&&(n=!0);var r=t||{},i=[r.left,r.top,r.right,r.bottom].every(Pp),a=[r.x,r.y,r.width,r.height].every(Pp);if(!a&&!i)throw Error(`Box.constructor - expected box to be IBoundingBox | IRect, instead have `+JSON.stringify(r));var o=a?[r.x,r.y,r.width,r.height]:[r.left,r.top,r.right-r.left,r.bottom-r.top],s=o[0],c=o[1],l=o[2],u=o[3];e.assertIsValidBox({x:s,y:c,width:l,height:u},`Box.constructor`,n),this._x=s,this._y=c,this._width=l,this._height=u}return e.isRect=function(e){return!!e&&[e.x,e.y,e.width,e.height].every(Pp)},e.assertIsValidBox=function(t,n,r){if(r===void 0&&(r=!1),!e.isRect(t))throw Error(n+` - invalid box: `+JSON.stringify(t)+`, expected object with properties x, y, width, height`);if(!r&&(t.width<0||t.height<0))throw Error(n+` - width (`+t.width+`) and height (`+t.height+`) must be positive numbers`)},Object.defineProperty(e.prototype,`x`,{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`y`,{get:function(){return this._y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`width`,{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`height`,{get:function(){return this._height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`left`,{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`top`,{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`right`,{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottom`,{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`area`,{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`topLeft`,{get:function(){return new Ip(this.left,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`topRight`,{get:function(){return new Ip(this.right,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottomLeft`,{get:function(){return new Ip(this.left,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottomRight`,{get:function(){return new Ip(this.right,this.bottom)},enumerable:!0,configurable:!0}),e.prototype.round=function(){var t=[this.x,this.y,this.width,this.height].map(function(e){return Math.round(e)}),n=t[0],r=t[1],i=t[2],a=t[3];return new e({x:n,y:r,width:i,height:a})},e.prototype.floor=function(){var t=[this.x,this.y,this.width,this.height].map(function(e){return Math.floor(e)}),n=t[0],r=t[1],i=t[2],a=t[3];return new e({x:n,y:r,width:i,height:a})},e.prototype.toSquare=function(){var t=this,n=t.x,r=t.y,i=t.width,a=t.height,o=Math.abs(i-a);return i<a&&(n-=o/2,i+=o),a<i&&(r-=o/2,a+=o),new e({x:n,y:r,width:i,height:a})},e.prototype.rescale=function(t){var n=Ap(t)?t.width:t,r=Ap(t)?t.height:t;return new e({x:this.x*n,y:this.y*r,width:this.width*n,height:this.height*r})},e.prototype.pad=function(t,n){var r=[this.x-t/2,this.y-n/2,this.width+t,this.height+n],i=r[0],a=r[1],o=r[2],s=r[3];return new e({x:i,y:a,width:o,height:s})},e.prototype.clipAtImageBorders=function(t,n){var r=this,i=r.x,a=r.y,o=r.right,s=r.bottom,c=Math.max(i,0),l=Math.max(a,0),u=o-c,d=s-l;return new e({x:c,y:l,width:Math.min(u,t-c),height:Math.min(d,n-l)}).floor()},e.prototype.shift=function(t,n){var r=this,i=r.width,a=r.height;return new e({x:this.x+t,y:this.y+n,width:i,height:a})},e.prototype.padAtBorders=function(e,t){var n=this.width+1,r=this.height+1,i=1,a=1,o=n,s=r,c=this.left,l=this.top,u=this.right,d=this.bottom;return u>t&&(o=-u+t+n,u=t),d>e&&(s=-d+e+r,d=e),c<1&&(s=2-c,c=1),l<1&&(s=2-l,l=1),{dy:a,edy:s,dx:i,edx:o,y:l,ey:d,x:c,ex:u,w:n,h:r}},e.prototype.calibrate=function(t){return new e({left:this.left+t.left*this.width,top:this.top+t.top*this.height,right:this.right+t.right*this.width,bottom:this.bottom+t.bottom*this.height}).toSquare().round()},e}(),Rp=function(e){Z(t,e);function t(t,n,r,i,a){return a===void 0&&(a=!1),e.call(this,{left:t,top:n,right:r,bottom:i},a)||this}return t}(Lp),zp=function(){function e(e,t,n,r,i){this._imageDims=new Sp(i.width,i.height),this._score=e,this._classScore=t,this._className=n,this._box=new Lp(r).rescale(this._imageDims)}return Object.defineProperty(e.prototype,`score`,{get:function(){return this._score},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`classScore`,{get:function(){return this._classScore},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`className`,{get:function(){return this._className},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`box`,{get:function(){return this._box},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`imageDims`,{get:function(){return this._imageDims},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`imageWidth`,{get:function(){return this.imageDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`imageHeight`,{get:function(){return this.imageDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`relativeBox`,{get:function(){return new Lp(this._box).rescale(this.imageDims.reverse())},enumerable:!0,configurable:!0}),e.prototype.forSize=function(t,n){return new e(this.score,this.classScore,this.className,this.relativeBox,{width:t,height:n})},e}(),Bp=function(e){Z(t,e);function t(t,n,r){return e.call(this,t,t,``,n,r)||this}return t.prototype.forSize=function(n,r){var i=e.prototype.forSize.call(this,n,r),a=i.score,o=i.relativeBox,s=i.imageDims;return new t(a,o,s)},t}(zp);function Vp(e,t,n){n===void 0&&(n=!0);var r=Math.max(0,Math.min(e.right,t.right)-Math.max(e.left,t.left))*Math.max(0,Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top));return n?r/(e.area+t.area-r):r/Math.min(e.area,t.area)}function Hp(e){var t=e.map(function(e){return e.x}),n=e.map(function(e){return e.y});return new Rp(t.reduce(function(e,t){return t<e?t:e},1/0),n.reduce(function(e,t){return t<e?t:e},1/0),t.reduce(function(e,t){return e<t?t:e},0),n.reduce(function(e,t){return e<t?t:e},0))}function Up(e,t,n,r){r===void 0&&(r=!0);for(var i=t.map(function(e,t){return{score:e,boxIndex:t}}).sort(function(e,t){return e.score-t.score}).map(function(e){return e.boxIndex}),a=[],o=function(){var t=i.pop();a.push(t);for(var o=i,s=[],c=0;c<o.length;c++){var l=o[c],u=e[t],d=e[l];s.push(Vp(u,d,r))}i=i.filter(function(e,t){return s[t]<=n})};i.length>0;)o();return a}function Wp(e,t){return W(function(){var n=t[0],r=t[1],i=t[2];return vl(e,nr([Zn(xp(e.shape.slice(0,3),[1]),n),Zn(xp(e.shape.slice(0,3),[1]),r),Zn(xp(e.shape.slice(0,3),[1]),i)],3))})}function Gp(e,t){return t===void 0&&(t=!1),W(function(){var n=e.shape.slice(1),r=n[0],i=n[1];if(r===i)return e;var a=Math.abs(r-i),o=Math.round(a*(t?.5:1)),s=r>i?2:1,c=function(t){var n=e.shape.slice();return n[s]=t,Zn(n,0)},l=c(o),u=a-l.shape[s];return nr([t&&u?c(u):null,e,l].filter(function(e){return!!e}).map(function(e){return e.toFloat()}),s)})}function Kp(e){return 1/(1+Math.exp(-e))}var qp=function(e){Z(t,e);function t(t,n,r,i,a){return a===void 0&&(a=!1),e.call(this,{x:t,y:n,width:r,height:i},a)||this}return t}(Lp),Jp=.5,Yp=.43,Xp=.45,Zp=function(){function e(e,t,n){n===void 0&&(n=new Ip(0,0));var r=t.width,i=t.height;this._imgDims=new Sp(r,i),this._shift=n,this._positions=e.map(function(e){return e.mul(new Ip(r,i)).add(n)})}return Object.defineProperty(e.prototype,`shift`,{get:function(){return new Ip(this._shift.x,this._shift.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`imageWidth`,{get:function(){return this._imgDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`imageHeight`,{get:function(){return this._imgDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`positions`,{get:function(){return this._positions},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`relativePositions`,{get:function(){var e=this;return this._positions.map(function(t){return t.sub(e._shift).div(new Ip(e.imageWidth,e.imageHeight))})},enumerable:!0,configurable:!0}),e.prototype.forSize=function(e,t){return new this.constructor(this.relativePositions,{width:e,height:t})},e.prototype.shiftBy=function(e,t){return new this.constructor(this.relativePositions,this._imgDims,new Ip(e,t))},e.prototype.shiftByPoint=function(e){return this.shiftBy(e.x,e.y)},e.prototype.align=function(e,t){if(t===void 0&&(t={}),e){var n=e instanceof Bp?e.box.floor():new Lp(e);return this.shiftBy(n.x,n.y).align(null,t)}var r=Object.assign({},{useDlibAlignment:!1,minBoxPadding:.2},t),i=r.useDlibAlignment,a=r.minBoxPadding;return i?this.alignDlib():this.alignMinBbox(a)},e.prototype.alignDlib=function(){var e=this.getRefPointsForAlignment(),t=e[0],n=e[1],r=e[2],i=function(e){return r.sub(e).magnitude()},a=(i(t)+i(n))/2,o=Math.floor(a/Xp),s=Mp(e),c=Math.floor(Math.max(0,s.x-Jp*o)),l=Math.floor(Math.max(0,s.y-Yp*o));return new qp(c,l,Math.min(o,this.imageWidth+c),Math.min(o,this.imageHeight+l))},e.prototype.alignMinBbox=function(e){var t=Hp(this.positions);return t.pad(t.width*e,t.height*e)},e.prototype.getRefPointsForAlignment=function(){throw Error(`getRefPointsForAlignment not implemented by base class`)},e}(),Qp=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.getRefPointsForAlignment=function(){var e=this.positions;return[e[0],e[1],Mp([e[3],e[4]])]},t}(Zp),$p=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.getJawOutline=function(){return this.positions.slice(0,17)},t.prototype.getLeftEyeBrow=function(){return this.positions.slice(17,22)},t.prototype.getRightEyeBrow=function(){return this.positions.slice(22,27)},t.prototype.getNose=function(){return this.positions.slice(27,36)},t.prototype.getLeftEye=function(){return this.positions.slice(36,42)},t.prototype.getRightEye=function(){return this.positions.slice(42,48)},t.prototype.getMouth=function(){return this.positions.slice(48,68)},t.prototype.getRefPointsForAlignment=function(){return[this.getLeftEye(),this.getRightEye(),this.getMouth()].map(Mp)},t}(Zp),em=function(){function e(e,t){this._label=e,this._distance=t}return Object.defineProperty(e.prototype,`label`,{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`distance`,{get:function(){return this._distance},enumerable:!0,configurable:!0}),e.prototype.toString=function(e){return e===void 0&&(e=!0),``+this.label+(e?` (`+kp(this.distance)+`)`:``)},e}(),tm=function(e){Z(t,e);function t(t,n){var r=e.call(this,t)||this;return r._label=n,r}return t.assertIsValidLabeledBox=function(e,t){if(Lp.assertIsValidBox(e,t),!Pp(e.label))throw Error(t+` - expected property label (`+e.label+`) to be a number`)},Object.defineProperty(t.prototype,`label`,{get:function(){return this._label},enumerable:!0,configurable:!0}),t}(Lp),nm=function(){function e(e,t){if(typeof e!=`string`)throw Error(`LabeledFaceDescriptors - constructor expected label to be a string`);if(!Array.isArray(t)||t.some(function(e){return!(e instanceof Float32Array)}))throw Error(`LabeledFaceDescriptors - constructor expected descriptors to be an array of Float32Array`);this._label=e,this._descriptors=t}return Object.defineProperty(e.prototype,`label`,{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`descriptors`,{get:function(){return this._descriptors},enumerable:!0,configurable:!0}),e.prototype.toJSON=function(){return{label:this.label,descriptors:this.descriptors.map(function(e){return Array.from(e)})}},e.fromJSON=function(t){var n=t.descriptors.map(function(e){return new Float32Array(e)});return new e(t.label,n)},e}();(function(e){Z(t,e);function t(t,n,r,i){var a=e.call(this,t,n)||this;return a._score=r,a._classScore=i,a}return t.assertIsValidPredictedBox=function(e,t){if(tm.assertIsValidLabeledBox(e,t),!Fp(e.score)||!Fp(e.classScore))throw Error(t+` - expected properties score (`+e.score+`) and (`+e.classScore+`) to be a number between [0, 1]`)},Object.defineProperty(t.prototype,`score`,{get:function(){return this._score},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,`classScore`,{get:function(){return this._classScore},enumerable:!0,configurable:!0}),t})(tm);function rm(e){return e.detection instanceof Bp}function im(e,t){return Object.assign({},e,{detection:t})}function am(){var e=window.fetch||function(){throw Error(`fetch - missing fetch implementation for browser environment`)};return{Canvas:HTMLCanvasElement,CanvasRenderingContext2D,Image:HTMLImageElement,ImageData,Video:HTMLVideoElement,createCanvasElement:function(){return document.createElement(`canvas`)},createImageElement:function(){return document.createElement(`img`)},fetch:e,readFile:function(){throw Error(`readFile - filesystem not available for browser environment`)}}}function om(e){var t=``;if(!e)try{e=x()}catch(e){t=e.toString()}return{readFile:e?function(t){return new Promise(function(n,r){e.readFile(t,function(e,t){return e?r(e):n(t)})})}:function(){throw Error(`readFile - failed to require fs in nodejs environment with error: `+t)}}}function sm(){var e=global.Canvas||global.HTMLCanvasElement,t=global.Image||global.HTMLImageElement,n=function(){if(e)return new e;throw Error(`createCanvasElement - missing Canvas implementation for nodejs environment`)},r=function(){if(t)return new t;throw Error(`createImageElement - missing Image implementation for nodejs environment`)},i=global.fetch||function(){throw Error(`fetch - missing fetch implementation for nodejs environment`)},a=om();return bp({Canvas:e||function(){function e(){}return e}(),CanvasRenderingContext2D:global.CanvasRenderingContext2D||function(){function e(){}return e}(),Image:t||function(){function e(){}return e}(),ImageData:global.ImageData||function(){function e(){}return e}(),Video:global.HTMLVideoElement||function(){function e(){}return e}(),createCanvasElement:n,createImageElement:r,fetch:i},a)}function cm(){return typeof window==`object`&&typeof document<`u`&&typeof HTMLImageElement<`u`&&typeof HTMLCanvasElement<`u`&&typeof HTMLVideoElement<`u`&&typeof ImageData<`u`&&typeof CanvasRenderingContext2D<`u`}function lm(){return typeof global==`object`&&typeof require==`function`&&typeof module<`u`&&typeof process<`u`&&!!process.version}var um;function dm(){if(!um)throw Error(`getEnv - environment is not defined, check isNodejs() and isBrowser()`);return um}function fm(e){um=e}function pm(){cm()&&fm(am()),lm()&&fm(sm())}function mm(e){if(um||pm(),!um)throw Error(`monkeyPatch - environment is not defined, check isNodejs() and isBrowser()`);var t=e.Canvas,n=t===void 0?um.Canvas:t,r=e.Image,i=r===void 0?um.Image:r;um.Canvas=n,um.Image=i,um.createCanvasElement=e.createCanvasElement||(function(){return new n}),um.createImageElement=e.createImageElement||(function(){return new i}),um.ImageData=e.ImageData||um.ImageData,um.Video=e.Video||um.Video,um.fetch=e.fetch||um.fetch,um.readFile=e.readFile||um.readFile}var hm={getEnv:dm,setEnv:fm,initialize:pm,createBrowserEnv:am,createFileSystem:om,createNodejsEnv:sm,monkeyPatch:mm,isBrowser:cm,isNodejs:lm};pm();function gm(e){return!hm.isNodejs()&&typeof e==`string`?document.getElementById(e):e}function _m(e){var t=hm.getEnv(),n=t.Canvas;if(e instanceof t.CanvasRenderingContext2D)return e;var r=gm(e);if(!(r instanceof n))throw Error(`resolveContext2d - expected canvas to be of instance of Canvas`);var i=r.getContext(`2d`);if(!i)throw Error(`resolveContext2d - canvas 2d context is null`);return i}var vm;(function(e){e.TOP_LEFT=`TOP_LEFT`,e.TOP_RIGHT=`TOP_RIGHT`,e.BOTTOM_LEFT=`BOTTOM_LEFT`,e.BOTTOM_RIGHT=`BOTTOM_RIGHT`})(vm||={});var ym=function(){function e(e){e===void 0&&(e={});var t=e.anchorPosition,n=e.backgroundColor,r=e.fontColor,i=e.fontSize,a=e.fontStyle,o=e.padding;this.anchorPosition=t||vm.TOP_LEFT,this.backgroundColor=n||`rgba(0, 0, 0, 0.5)`,this.fontColor=r||`rgba(255, 255, 255, 1)`,this.fontSize=i||14,this.fontStyle=a||`Georgia`,this.padding=o||4}return e}(),bm=function(){function e(t,n,r){r===void 0&&(r={}),this.text=typeof t==`string`?[t]:t instanceof e?t.text:t,this.anchor=n,this.options=new ym(r)}return e.prototype.measureWidth=function(e){var t=this.options.padding;return this.text.map(function(t){return e.measureText(t).width}).reduce(function(e,t){return e<t?t:e},0)+2*t},e.prototype.measureHeight=function(){var e=this.options,t=e.fontSize,n=e.padding;return this.text.length*t+2*n},e.prototype.getUpperLeft=function(e,t){var n=this.options.anchorPosition,r=n===vm.BOTTOM_RIGHT||n===vm.TOP_RIGHT,i=n===vm.BOTTOM_LEFT||n===vm.BOTTOM_RIGHT,a=this.measureWidth(e),o=this.measureHeight(),s=r?this.anchor.x-a:this.anchor.x,c=i?this.anchor.y-o:this.anchor.y;if(t){var l=t.width,u=t.height;return{x:Math.max(Math.min(s,l-a),0),y:Math.max(Math.min(c,u-o),0)}}return{x:s,y:c}},e.prototype.draw=function(e){var t=gm(e),n=_m(t),r=this.options,i=r.backgroundColor,a=r.fontColor,o=r.fontSize,s=r.fontStyle,c=r.padding;n.font=o+`px `+s;var l=this.measureWidth(n),u=this.measureHeight();n.fillStyle=i;var d=this.getUpperLeft(n,t);n.fillRect(d.x,d.y,l,u),n.fillStyle=a,this.text.forEach(function(e,t){var r=c+d.x,i=c+d.y+(t+1)*o;n.fillText(e,r,i)})},e}(),xm=function(){function e(e){e===void 0&&(e={});var t=e.boxColor,n=e.lineWidth,r=e.label,i=e.drawLabelOptions;this.boxColor=t||`rgba(0, 0, 255, 1)`,this.lineWidth=n||2,this.label=r;var a={anchorPosition:vm.BOTTOM_LEFT,backgroundColor:this.boxColor};this.drawLabelOptions=new ym(Object.assign({},a,i))}return e}();(function(){function e(e,t){t===void 0&&(t={}),this.box=new Lp(e),this.options=new xm(t)}return e.prototype.draw=function(e){var t=_m(e),n=this.options,r=n.boxColor,i=n.lineWidth,a=this.box,o=a.x,s=a.y,c=a.width,l=a.height;t.strokeStyle=r,t.lineWidth=i,t.strokeRect(o,s,c,l);var u=this.options.label;u&&new bm([u],{x:o-i/2,y:s},this.options.drawLabelOptions).draw(e)},e})();function Sm(e){var t=hm.getEnv(),n=t.Image,r=t.Video;return e instanceof n&&e.complete||e instanceof r&&e.readyState>=3}function Cm(e){return new Promise(function(t,n){if(e instanceof hm.getEnv().Canvas||Sm(e))return t();function r(e){e.currentTarget&&(e.currentTarget.removeEventListener(`load`,r),e.currentTarget.removeEventListener(`error`,i),t(e))}function i(e){e.currentTarget&&(e.currentTarget.removeEventListener(`load`,r),e.currentTarget.removeEventListener(`error`,i),n(e))}e.addEventListener(`load`,r),e.addEventListener(`error`,i)})}function wm(e){var t=hm.getEnv(),n=t.Image,r=t.Video;return e instanceof n?new Sp(e.naturalWidth,e.naturalHeight):e instanceof r?new Sp(e.videoWidth,e.videoHeight):new Sp(e.width,e.height)}function Tm(e){var t=e.width,n=e.height,r=hm.getEnv().createCanvasElement,i=r();return i.width=t,i.height=n,i}function Em(e,t){var n=hm.getEnv().ImageData;if(!(e instanceof n)&&!Sm(e))throw Error(`createCanvasFromMedia - media has not finished loading yet`);var r=t||wm(e),i=r.width,a=r.height,o=Tm({width:i,height:a});return e instanceof n?_m(o).putImageData(e,0,0):_m(o).drawImage(e,0,0,i,a),o}function Dm(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a,o,s;return $(this,function(c){switch(c.label){case 0:return n=t||hm.getEnv().createCanvasElement(),r=e.shape.slice(Ep(e)?1:0),i=r[0],a=r[1],o=r[2],s=W(function(){return e.as3D(i,a,o).toInt()}),[4,ep.toPixels(s,n)];case 1:return c.sent(),s.dispose(),[2,n]}})})}function Om(e){var t=hm.getEnv(),n=t.Image,r=t.Canvas,i=t.Video;return e instanceof n||e instanceof r||e instanceof i}function km(e,t,n){n===void 0&&(n=!1);var r=hm.getEnv(),i=r.Image,a=r.Canvas;if(!(e instanceof i||e instanceof a))throw Error(`imageToSquare - expected arg0 to be HTMLImageElement | HTMLCanvasElement`);var o=wm(e),s=t/Math.max(o.height,o.width),c=s*o.width,l=s*o.height,u=Tm({width:t,height:t}),d=e instanceof a?e:Em(e),f=Math.abs(c-l)/2,p=n&&c<l?f:0,m=n&&l<c?f:0;return _m(u).drawImage(d,p,m,c,l),u}var Am=function(){function e(e,t){var n=this;if(t===void 0&&(t=!1),this._imageTensors=[],this._canvases=[],this._treatAsBatchInput=!1,this._inputDimensions=[],!Array.isArray(e))throw Error(`NetInput.constructor - expected inputs to be an Array of TResolvedNetInput or to be instanceof tf.Tensor4D, instead have `+e);this._treatAsBatchInput=t,this._batchSize=e.length,e.forEach(function(e,t){if(Tp(e)){n._imageTensors[t]=e,n._inputDimensions[t]=e.shape;return}if(Ep(e)){var r=e.shape[0];if(r!==1)throw Error(`NetInput - tf.Tensor4D with batchSize `+r+` passed, but not supported in input array`);n._imageTensors[t]=e,n._inputDimensions[t]=e.shape.slice(1);return}var i=e instanceof hm.getEnv().Canvas?e:Em(e);n._canvases[t]=i,n._inputDimensions[t]=[i.height,i.width,3]})}return Object.defineProperty(e.prototype,`imageTensors`,{get:function(){return this._imageTensors},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`canvases`,{get:function(){return this._canvases},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`isBatchInput`,{get:function(){return this.batchSize>1||this._treatAsBatchInput},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`batchSize`,{get:function(){return this._batchSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`inputDimensions`,{get:function(){return this._inputDimensions},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`inputSize`,{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`reshapedInputDimensions`,{get:function(){var e=this;return Np(this.batchSize,0,1).map(function(t,n){return e.getReshapedInputDimensions(n)})},enumerable:!0,configurable:!0}),e.prototype.getInput=function(e){return this.canvases[e]||this.imageTensors[e]},e.prototype.getInputDimensions=function(e){return this._inputDimensions[e]},e.prototype.getInputHeight=function(e){return this._inputDimensions[e][0]},e.prototype.getInputWidth=function(e){return this._inputDimensions[e][1]},e.prototype.getReshapedInputDimensions=function(e){if(typeof this.inputSize!=`number`)throw Error(`getReshapedInputDimensions - inputSize not set, toBatchTensor has not been called yet`);return jp({width:this.getInputWidth(e),height:this.getInputHeight(e)},this.inputSize)},e.prototype.toBatchTensor=function(e,t){var n=this;return t===void 0&&(t=!0),this._inputSize=e,W(function(){return Ur(Np(n.batchSize,0,1).map(function(r){var i=n.getInput(r);if(i instanceof $e){var a=Ep(i)?i:i.expandDims();return a=Gp(a,t),(a.shape[1]!==e||a.shape[2]!==e)&&(a=Ad.resizeBilinear(a,[e,e])),a.as3D(e,e,3)}if(i instanceof hm.getEnv().Canvas)return ep.fromPixels(km(i,e,t));throw Error(`toBatchTensor - at batchIdx `+r+`, expected input to be instanceof tf.Tensor or instanceof HTMLCanvasElement, instead have `+i)}).map(function(e){return e.toFloat()})).as4D(n.batchSize,e,e,3)})},e}();function jm(e){return Q(this,void 0,void 0,function(){var t,n,r;return $(this,function(i){switch(i.label){case 0:if(e instanceof Am)return[2,e];if(t=Array.isArray(e)?e:[e],!t.length)throw Error(`toNetInput - empty array passed as input`);return n=function(t){return Array.isArray(e)?` at input index `+t+`:`:``},r=t.map(gm),r.forEach(function(e,r){if(!Om(e)&&!Tp(e)&&!Ep(e))throw typeof t[r]==`string`?Error(`toNetInput -`+n(r)+` string passed, but could not resolve HTMLElement for element id `+t[r]):Error(`toNetInput -`+n(r)+` expected media to be of type HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | tf.Tensor3D, or to be an element id`);if(Ep(e)){var i=e.shape[0];if(i!==1)throw Error(`toNetInput -`+n(r)+` tf.Tensor4D with batchSize `+i+` passed, but not supported in input array`)}}),[4,Promise.all(r.map(function(e){return Om(e)&&Cm(e)}))];case 1:return i.sent(),[2,new Am(r,Array.isArray(e))]}})})}function Mm(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c;return $(this,function(l){switch(l.label){case 0:return n=hm.getEnv().Canvas,r=e,e instanceof n?[3,5]:[4,jm(e)];case 1:if(i=l.sent(),i.batchSize>1)throw Error(`extractFaces - batchSize > 1 not supported`);return a=i.getInput(0),a instanceof n?(o=a,[3,4]):[3,2];case 2:return[4,Dm(a)];case 3:o=l.sent(),l.label=4;case 4:r=o,l.label=5;case 5:return s=_m(r),c=t.map(function(e){return e instanceof Bp?e.forSize(r.width,r.height).box.floor():e}).map(function(e){return e.clipAtImageBorders(r.width,r.height)}),[2,c.map(function(e){var t=e.x,n=e.y,r=e.width,i=e.height,a=Tm({width:r,height:i});return _m(a).putImageData(s.getImageData(t,n,r,i),0,0),a})]}})})}function Nm(e,t){return Q(this,void 0,void 0,function(){return $(this,function(n){if(!Tp(e)&&!Ep(e))throw Error(`extractFaceTensors - expected image tensor to be 3D or 4D`);if(Ep(e)&&e.shape[0]>1)throw Error(`extractFaceTensors - batchSize > 1 not supported`);return[2,W(function(){var n=e.shape.slice(Ep(e)?1:0),r=n[0],i=n[1],a=n[2];return t.map(function(e){return e instanceof Bp?e.forSize(i,r).box:e}).map(function(e){return e.clipAtImageBorders(i,r)}).map(function(t){var n=t.x,o=t.y,s=t.width,c=t.height;return hu(e.as3D(r,i,a),[o,n,0],[c,s,a])})})]})})}function Pm(e,t){return Q(this,void 0,void 0,function(){var n,r;return $(this,function(i){switch(i.label){case 0:return n=hm.getEnv().fetch,[4,n(e,t)];case 1:if(r=i.sent(),!(r.status<400))throw Error(`failed to fetch: (`+r.status+`) `+r.statusText+`, from url: `+r.url);return[2,r]}})})}function Fm(e){return Q(this,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,Pm(e)];case 1:return[2,t.sent().json()]}})})}function Im(e,t){var n=t+`-weights_manifest.json`;if(!e)return{modelBaseUri:``,manifestUri:n};if(e===`/`)return{modelBaseUri:`/`,manifestUri:`/`+n};var r=e.startsWith(`http://`)?`http://`:e.startsWith(`https://`)?`https://`:``;e=e.replace(r,``);var i=e.split(`/`).filter(function(e){return e}),a=e.endsWith(`.json`)?i[i.length-1]:n,o=r+(e.endsWith(`.json`)?i.slice(0,i.length-1):i).join(`/`);return o=e.startsWith(`/`)?`/`+o:o,{modelBaseUri:o,manifestUri:o===`/`?`/`+a:o+`/`+a}}function Lm(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a;return $(this,function(o){switch(o.label){case 0:return n=Im(e,t),r=n.manifestUri,i=n.modelBaseUri,[4,Fm(r)];case 1:return a=o.sent(),[2,Xf.loadWeights(a,i)]}})})}var Rm=function(){function e(e){this._name=e,this._params=void 0,this._paramMappings=[]}return Object.defineProperty(e.prototype,`params`,{get:function(){return this._params},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`paramMappings`,{get:function(){return this._paramMappings},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`isLoaded`,{get:function(){return!!this.params},enumerable:!0,configurable:!0}),e.prototype.getParamFromPath=function(e){var t=this.traversePropertyPath(e);return t.obj[t.objProp]},e.prototype.reassignParamFromPath=function(e,t){var n=this.traversePropertyPath(e),r=n.obj,i=n.objProp;r[i].dispose(),r[i]=t},e.prototype.getParamList=function(){var e=this;return this._paramMappings.map(function(t){var n=t.paramPath;return{path:n,tensor:e.getParamFromPath(n)}})},e.prototype.getTrainableParams=function(){return this.getParamList().filter(function(e){return e.tensor instanceof at})},e.prototype.getFrozenParams=function(){return this.getParamList().filter(function(e){return!(e.tensor instanceof at)})},e.prototype.variable=function(){var e=this;this.getFrozenParams().forEach(function(t){var n=t.path,r=t.tensor;e.reassignParamFromPath(n,r.variable())})},e.prototype.freeze=function(){var e=this;this.getTrainableParams().forEach(function(t){var n=t.path,r=t.tensor,i=Bn(r.dataSync());r.dispose(),e.reassignParamFromPath(n,i)})},e.prototype.dispose=function(e){e===void 0&&(e=!0),this.getParamList().forEach(function(t){if(e&&t.tensor.isDisposed)throw Error(`param tensor has already been disposed for path `+t.path);t.tensor.dispose()}),this._params=void 0},e.prototype.serializeParams=function(){return new Float32Array(this.getParamList().map(function(e){var t=e.tensor;return Array.from(t.dataSync())}).reduce(function(e,t){return e.concat(t)}))},e.prototype.load=function(e){return Q(this,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return e instanceof Float32Array?(this.extractWeights(e),[2]):[4,this.loadFromUri(e)];case 1:return t.sent(),[2]}})})},e.prototype.loadFromUri=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:if(e&&typeof e!=`string`)throw Error(this._name+`.loadFromUri - expected model uri`);return[4,Lm(e,this.getDefaultModelName())];case 1:return t=n.sent(),this.loadFromWeightMap(t),[2]}})})},e.prototype.loadFromDisk=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i,a,o,s,c,l,u;return $(this,function(d){switch(d.label){case 0:if(e&&typeof e!=`string`)throw Error(this._name+`.loadFromDisk - expected model file path`);return t=hm.getEnv().readFile,n=Im(e,this.getDefaultModelName()),r=n.manifestUri,i=n.modelBaseUri,a=function(e){return Promise.all(e.map(function(e){return t(e).then(function(e){return e.buffer})}))},o=Xf.weightsLoaderFactory(a),l=(c=JSON).parse,[4,t(r)];case 1:return s=l.apply(c,[d.sent().toString()]),[4,o(s,i)];case 2:return u=d.sent(),this.loadFromWeightMap(u),[2]}})})},e.prototype.loadFromWeightMap=function(e){var t=this.extractParamsFromWeigthMap(e),n=t.paramMappings,r=t.params;this._paramMappings=n,this._params=r},e.prototype.extractWeights=function(e){var t=this.extractParams(e),n=t.paramMappings,r=t.params;this._paramMappings=n,this._params=r},e.prototype.traversePropertyPath=function(e){if(!this.params)throw Error(`traversePropertyPath - model has no loaded params`);var t=e.split(`/`).reduce(function(t,n){if(!t.nextObj.hasOwnProperty(n))throw Error(`traversePropertyPath - object does not have property `+n+`, for path `+e);return{obj:t.nextObj,objProp:n,nextObj:t.nextObj[n]}},{nextObj:this.params}),n=t.obj,r=t.objProp;if(!n||!r||!(n[r]instanceof $e))throw Error(`traversePropertyPath - parameter is not a tensor, for path `+e);return{obj:n,objProp:r}},e}();function zm(e,t,n){return W(function(){var r=Jl(e,t.depthwise_filter,t.pointwise_filter,n,`same`);return r=$c(r,t.bias),r})}function Bm(e,t,n){return n===void 0&&(n=!1),W(function(){var r=Mu(n?$c(Vl(e,t.conv0.filters,[2,2],`same`),t.conv0.bias):zm(e,t.conv0,[2,2])),i=zm(r,t.conv1,[1,1]);return Mu($c(r,$c(i,zm(Mu($c(r,i)),t.conv2,[1,1]))))})}function Vm(e,t,n,r){return n===void 0&&(n=!1),r===void 0&&(r=!0),W(function(){var i=Mu(n?$c(Vl(e,t.conv0.filters,r?[2,2]:[1,1],`same`),t.conv0.bias):zm(e,t.conv0,r?[2,2]:[1,1])),a=zm(i,t.conv1,[1,1]),o=zm(Mu($c(i,a)),t.conv2,[1,1]);return Mu($c(i,$c(a,$c(o,zm(Mu($c(i,$c(a,o))),t.conv3,[1,1])))))})}function Hm(e,t,n,r){return n===void 0&&(n=`same`),r===void 0&&(r=!1),W(function(){var i=$c(Vl(e,t.filters,[1,1],n),t.bias);return r?Mu(i):i})}function Um(e,t){Object.keys(e).forEach(function(n){t.some(function(e){return e.originalPath===n})||e[n].dispose()})}function Wm(e,t){return function(n,r,i,a){var o=Gn(e(n*r*i*i),[i,i,n,r]),s=Hn(e(r));return t.push({paramPath:a+`/filters`},{paramPath:a+`/bias`}),{filters:o,bias:s}}}function Gm(e,t){return function(n,r,i){var a=Un(e(n*r),[n,r]),o=Hn(e(r));return t.push({paramPath:i+`/weights`},{paramPath:i+`/bias`}),{weights:a,bias:o}}}var Km=function(){function e(e,t,n){this.depthwise_filter=e,this.pointwise_filter=t,this.bias=n}return e}();function qm(e,t){return function(n,r,i){var a=Gn(e(9*n),[3,3,n,1]),o=Gn(e(n*r),[1,1,n,r]),s=Hn(e(r));return t.push({paramPath:i+`/depthwise_filter`},{paramPath:i+`/pointwise_filter`},{paramPath:i+`/bias`}),new Km(a,o,s)}}function Jm(e){return function(t){return new Km(e(t+`/depthwise_filter`,4),e(t+`/pointwise_filter`,4),e(t+`/bias`,1))}}function Ym(e,t){return function(n,r,i){var a=e[n];if(!Cp(a,r))throw Error(`expected weightMap[`+n+`] to be a Tensor`+r+`D, instead have `+a);return t.push({originalPath:n,paramPath:i||n}),a}}function Xm(e){var t=e;function n(e){var n=t.slice(0,e);return t=t.slice(e),n}function r(){return t}return{extractWeights:n,getRemainingWeights:r}}function Zm(e,t){var n=Wm(e,t),r=qm(e,t);function i(e,t,i,a){return a===void 0&&(a=!1),{conv0:a?n(e,t,3,i+`/conv0`):r(e,t,i+`/conv0`),conv1:r(t,t,i+`/conv1`),conv2:r(t,t,i+`/conv2`)}}function a(e,t,n,a){a===void 0&&(a=!1);var o=i(e,t,n,a);return{conv0:o.conv0,conv1:o.conv1,conv2:o.conv2,conv3:r(t,t,n+`/conv3`)}}return{extractDenseBlock3Params:i,extractDenseBlock4Params:a}}function Qm(e){var t=[],n=Xm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Zm(r,t).extractDenseBlock4Params,o=a(3,32,`dense0`,!0),s=a(32,64,`dense1`),c=a(64,128,`dense2`),l=a(128,256,`dense3`);if(i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{paramMappings:t,params:{dense0:o,dense1:s,dense2:c,dense3:l}}}function $m(e){return function(t){return{filters:e(t+`/filters`,4),bias:e(t+`/bias`,1)}}}function eh(e,t){var n=Ym(e,t),r=$m(n),i=Jm(n);function a(e,t){return t===void 0&&(t=!1),{conv0:t?r(e+`/conv0`):i(e+`/conv0`),conv1:i(e+`/conv1`),conv2:i(e+`/conv2`)}}function o(e,t){return t===void 0&&(t=!1),{conv0:t?r(e+`/conv0`):i(e+`/conv0`),conv1:i(e+`/conv1`),conv2:i(e+`/conv2`),conv3:i(e+`/conv3`)}}return{extractDenseBlock3Params:a,extractDenseBlock4Params:o}}function th(e){var t=[],n=eh(e,t).extractDenseBlock4Params,r={dense0:n(`dense0`,!0),dense1:n(`dense1`),dense2:n(`dense2`),dense3:n(`dense3`)};return Um(e,t),{params:r,paramMappings:t}}var nh=function(e){Z(t,e);function t(){return e.call(this,`FaceFeatureExtractor`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`FaceFeatureExtractor - load model before inference`);return W(function(){var n=Vm(Wp(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(q(255)),t.dense0,!0);return n=Vm(n,t.dense1),n=Vm(n,t.dense2),n=Vm(n,t.dense3),n=cu(n,[7,7],[2,2],`valid`),n})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.getDefaultModelName=function(){return`face_feature_extractor_model`},t.prototype.extractParamsFromWeigthMap=function(e){return th(e)},t.prototype.extractParams=function(e){return Qm(e)},t}(Rm);function rh(e,t){return W(function(){return $c(Zl(e,t.weights),t.bias)})}function ih(e,t,n){var r=[],i=Xm(e),a=i.extractWeights,o=i.getRemainingWeights,s=Gm(a,r)(t,n,`fc`);if(o().length!==0)throw Error(`weights remaing after extract: `+o().length);return{paramMappings:r,params:{fc:s}}}function ah(e){var t=[],n=Ym(e,t);function r(e){return{weights:n(e+`/weights`,2),bias:n(e+`/bias`,1)}}var i={fc:r(`fc`)};return Um(e,t),{params:i,paramMappings:t}}function oh(e){var t={},n={};return Object.keys(e).forEach(function(r){var i=r.startsWith(`fc`)?n:t;i[r]=e[r]}),{featureExtractorMap:t,classifierMap:n}}var sh=function(e){Z(t,e);function t(t,n){var r=e.call(this,t)||this;return r._faceFeatureExtractor=n,r}return Object.defineProperty(t.prototype,`faceFeatureExtractor`,{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),t.prototype.runNet=function(e){var t=this,n=this.params;if(!n)throw Error(this._name+` - load model before inference`);return W(function(){var r=e instanceof Am?t.faceFeatureExtractor.forwardInput(e):e;return rh(r.as2D(r.shape[0],-1),n.fc)})},t.prototype.dispose=function(t){t===void 0&&(t=!0),this.faceFeatureExtractor.dispose(t),e.prototype.dispose.call(this,t)},t.prototype.loadClassifierParams=function(e){var t=this.extractClassifierParams(e),n=t.params,r=t.paramMappings;this._params=n,this._paramMappings=r},t.prototype.extractClassifierParams=function(e){return ih(e,this.getClassifierChannelsIn(),this.getClassifierChannelsOut())},t.prototype.extractParamsFromWeigthMap=function(e){var t=oh(e),n=t.featureExtractorMap,r=t.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(n),ah(r)},t.prototype.extractParams=function(e){var t=this.getClassifierChannelsIn(),n=this.getClassifierChannelsOut(),r=n*t+n,i=e.slice(0,e.length-r),a=e.slice(e.length-r);return this.faceFeatureExtractor.extractWeights(i),this.extractClassifierParams(a)},t}(Rm),ch=[`neutral`,`happy`,`sad`,`angry`,`fearful`,`disgusted`,`surprised`],lh=function(){function e(e){var t=this;if(e.length!==7)throw Error(`FaceExpressions.constructor - expected probabilities.length to be 7, have: `+e.length);ch.forEach(function(n,r){t[n]=e[r]})}return e.prototype.asSortedArray=function(){var e=this;return ch.map(function(t){return{expression:t,probability:e[t]}}).sort(function(e,t){return t.probability-e.probability})},e}(),uh=function(e){Z(t,e);function t(t){return t===void 0&&(t=new nh),e.call(this,`FaceExpressionNet`,t)||this}return t.prototype.forwardInput=function(e){var t=this;return W(function(){return mi(t.runNet(e))})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.predictExpressions=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i,a=this;return $(this,function(o){switch(o.label){case 0:return[4,jm(e)];case 1:return t=o.sent(),[4,this.forwardInput(t)];case 2:return n=o.sent(),[4,Promise.all(Kr(n).map(function(e){return Q(a,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return[4,e.data()];case 1:return t=n.sent(),e.dispose(),[2,t]}})})}))];case 3:return r=o.sent(),n.dispose(),i=r.map(function(e){return new lh(e)}),[2,t.isBatchInput?i:i[0]]}})})},t.prototype.getDefaultModelName=function(){return`face_expression_model`},t.prototype.getClassifierChannelsIn=function(){return 256},t.prototype.getClassifierChannelsOut=function(){return 7},t}(sh);function dh(e,t){return Object.assign({},e,{expressions:t})}function fh(e){return rm(e)&&e.landmarks instanceof Zp&&e.unshiftedLandmarks instanceof Zp&&e.alignedRect instanceof Bp}function ph(e,t){var n=e.detection.box,r=t.shiftBy(n.x,n.y),i=r.align(),a=e.detection.imageDims,o={landmarks:r,unshiftedLandmarks:t,alignedRect:new Bp(e.detection.score,i.rescale(a.reverse()),a)};return Object.assign({},e,o)}var mh=function(){function e(e){e===void 0&&(e={});var t=e.drawLines,n=t===void 0?!0:t,r=e.drawPoints,i=r===void 0?!0:r,a=e.lineWidth,o=e.lineColor,s=e.pointSize,c=e.pointColor;this.drawLines=n,this.drawPoints=i,this.lineWidth=a||1,this.pointSize=s||2,this.lineColor=o||`rgba(0, 255, 255, 1)`,this.pointColor=c||`rgba(255, 0, 255, 1)`}return e}();(function(){function e(e,t){t===void 0&&(t={}),this.faceLandmarks=e,this.options=new mh(t)}return e.prototype.draw=function(e){var t=_m(e),n=this.options,r=n.drawLines,i=n.drawPoints,a=n.lineWidth,o=n.lineColor,s=n.pointSize,c=n.pointColor;r&&this.faceLandmarks instanceof $p&&(t.strokeStyle=o,t.lineWidth=a,vp(t,this.faceLandmarks.getJawOutline()),vp(t,this.faceLandmarks.getLeftEyeBrow()),vp(t,this.faceLandmarks.getRightEyeBrow()),vp(t,this.faceLandmarks.getNose()),vp(t,this.faceLandmarks.getLeftEye(),!0),vp(t,this.faceLandmarks.getRightEye(),!0),vp(t,this.faceLandmarks.getMouth(),!0)),i&&(t.strokeStyle=c,t.fillStyle=c,this.faceLandmarks.positions.forEach(function(e){t.beginPath(),t.arc(e.x,e.y,s,0,2*Math.PI),t.fill()}))},e})();function hh(e,t){var n=Wm(e,t),r=qm(e,t);function i(e,t,i){return{separable_conv0:r(e,t,i+`/separable_conv0`),separable_conv1:r(t,t,i+`/separable_conv1`),expansion_conv:n(e,t,1,i+`/expansion_conv`)}}function a(e,t){return{separable_conv0:r(e,e,t+`/separable_conv0`),separable_conv1:r(e,e,t+`/separable_conv1`),separable_conv2:r(e,e,t+`/separable_conv2`)}}return{extractConvParams:n,extractSeparableConvParams:r,extractReductionBlockParams:i,extractMainBlockParams:a}}function gh(e,t){var n=[],r=Xm(e),i=r.extractWeights,a=r.getRemainingWeights,o=hh(i,n),s=o.extractConvParams,c=o.extractSeparableConvParams,l=o.extractReductionBlockParams,u=o.extractMainBlockParams,d={conv_in:s(3,32,3,`entry_flow/conv_in`),reduction_block_0:l(32,64,`entry_flow/reduction_block_0`),reduction_block_1:l(64,128,`entry_flow/reduction_block_1`)},f={};Np(t,0,1).forEach(function(e){f[`main_block_`+e]=u(128,`middle_flow/main_block_`+e)});var p={reduction_block:l(128,256,`exit_flow/reduction_block`),separable_conv:c(256,512,`exit_flow/separable_conv`)};if(a().length!==0)throw Error(`weights remaing after extract: `+a().length);return{paramMappings:n,params:{entry_flow:d,middle_flow:f,exit_flow:p}}}function _h(e,t){var n=Ym(e,t),r=$m(n),i=Jm(n);function a(e){return{separable_conv0:i(e+`/separable_conv0`),separable_conv1:i(e+`/separable_conv1`),expansion_conv:r(e+`/expansion_conv`)}}function o(e){return{separable_conv0:i(e+`/separable_conv0`),separable_conv1:i(e+`/separable_conv1`),separable_conv2:i(e+`/separable_conv2`)}}return{extractConvParams:r,extractSeparableConvParams:i,extractReductionBlockParams:a,extractMainBlockParams:o}}function vh(e,t){var n=[],r=_h(e,n),i=r.extractConvParams,a=r.extractSeparableConvParams,o=r.extractReductionBlockParams,s=r.extractMainBlockParams,c={conv_in:i(`entry_flow/conv_in`),reduction_block_0:o(`entry_flow/reduction_block_0`),reduction_block_1:o(`entry_flow/reduction_block_1`)},l={};Np(t,0,1).forEach(function(e){l[`main_block_`+e]=s(`middle_flow/main_block_`+e)});var u={reduction_block:o(`exit_flow/reduction_block`),separable_conv:a(`exit_flow/separable_conv`)};return Um(e,n),{params:{entry_flow:c,middle_flow:l,exit_flow:u},paramMappings:n}}function yh(e,t,n){return $c(Vl(e,t.filters,n,`same`),t.bias)}function bh(e,t,n){n===void 0&&(n=!0);var r=n?Mu(e):e;return r=zm(r,t.separable_conv0,[1,1]),r=zm(Mu(r),t.separable_conv1,[1,1]),r=su(r,[3,3],[2,2],`same`),r=$c(r,yh(e,t.expansion_conv,[2,2])),r}function xh(e,t){var n=zm(Mu(e),t.separable_conv0,[1,1]);return n=zm(Mu(n),t.separable_conv1,[1,1]),n=zm(Mu(n),t.separable_conv2,[1,1]),n=$c(n,e),n}var Sh=function(e){Z(t,e);function t(t){var n=e.call(this,`TinyXception`)||this;return n._numMainBlocks=t,n}return t.prototype.forwardInput=function(e){var t=this,n=this.params;if(!n)throw Error(`TinyXception - load model before inference`);return W(function(){var r=Mu(yh(Wp(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(q(256)),n.entry_flow.conv_in,[2,2]));return r=bh(r,n.entry_flow.reduction_block_0,!1),r=bh(r,n.entry_flow.reduction_block_1),Np(t._numMainBlocks,0,1).forEach(function(e){r=xh(r,n.middle_flow[`main_block_`+e])}),r=bh(r,n.exit_flow.reduction_block),r=Mu(zm(r,n.exit_flow.separable_conv,[1,1])),r})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.getDefaultModelName=function(){return`tiny_xception_model`},t.prototype.extractParamsFromWeigthMap=function(e){return vh(e,this._numMainBlocks)},t.prototype.extractParams=function(e){return gh(e,this._numMainBlocks)},t}(Rm);function Ch(e){var t=[],n=Xm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Gm(r,t),o=a(512,1,`fc/age`),s=a(512,2,`fc/gender`);if(i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{paramMappings:t,params:{fc:{age:o,gender:s}}}}function wh(e){var t=[],n=Ym(e,t);function r(e){return{weights:n(e+`/weights`,2),bias:n(e+`/bias`,1)}}var i={fc:{age:r(`fc/age`),gender:r(`fc/gender`)}};return Um(e,t),{params:i,paramMappings:t}}var Th;(function(e){e.FEMALE=`female`,e.MALE=`male`})(Th||={});var Eh=function(e){Z(t,e);function t(t){t===void 0&&(t=new Sh(2));var n=e.call(this,`AgeGenderNet`)||this;return n._faceFeatureExtractor=t,n}return Object.defineProperty(t.prototype,`faceFeatureExtractor`,{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),t.prototype.runNet=function(e){var t=this,n=this.params;if(!n)throw Error(this._name+` - load model before inference`);return W(function(){var r=e instanceof Am?t.faceFeatureExtractor.forwardInput(e):e,i=cu(r,[7,7],[2,2],`valid`).as2D(r.shape[0],-1);return{age:rh(i,n.fc.age).as1D(),gender:rh(i,n.fc.gender)}})},t.prototype.forwardInput=function(e){var t=this;return W(function(){var n=t.runNet(e),r=n.age,i=n.gender;return{age:r,gender:mi(i)}})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.predictAgeAndGender=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i,a,o,s=this;return $(this,function(c){switch(c.label){case 0:return[4,jm(e)];case 1:return t=c.sent(),[4,this.forwardInput(t)];case 2:return n=c.sent(),r=Kr(n.age),i=Kr(n.gender),a=r.map(function(e,t){return{ageTensor:e,genderTensor:i[t]}}),[4,Promise.all(a.map(function(e){var t=e.ageTensor,n=e.genderTensor;return Q(s,void 0,void 0,function(){var e,r,i,a,o;return $(this,function(s){switch(s.label){case 0:return[4,t.data()];case 1:return e=s.sent()[0],[4,n.data()];case 2:return r=s.sent()[0],i=r>.5,a=i?Th.MALE:Th.FEMALE,o=i?r:1-r,t.dispose(),n.dispose(),[2,{age:e,gender:a,genderProbability:o}]}})})}))];case 3:return o=c.sent(),n.age.dispose(),n.gender.dispose(),[2,t.isBatchInput?o:o[0]]}})})},t.prototype.getDefaultModelName=function(){return`age_gender_model`},t.prototype.dispose=function(t){t===void 0&&(t=!0),this.faceFeatureExtractor.dispose(t),e.prototype.dispose.call(this,t)},t.prototype.loadClassifierParams=function(e){var t=this.extractClassifierParams(e),n=t.params,r=t.paramMappings;this._params=n,this._paramMappings=r},t.prototype.extractClassifierParams=function(e){return Ch(e)},t.prototype.extractParamsFromWeigthMap=function(e){var t=oh(e),n=t.featureExtractorMap,r=t.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(n),wh(r)},t.prototype.extractParams=function(e){var t=1539,n=e.slice(0,e.length-t),r=e.slice(e.length-t);return this.faceFeatureExtractor.extractWeights(n),this.extractClassifierParams(r)},t}(Rm),Dh=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.postProcess=function(e,t,n){var r=n.map(function(e){var n=e.width,r=e.height,i=t/Math.max(r,n);return{width:n*i,height:r*i}}),i=r.length;return W(function(){var n=function(e,t){return Ur([Zn([68],e),Zn([68],t)],1).as2D(1,136).as1D()},a=function(e,t){var n=r[e],i=n.width,a=n.height;return t(i,a)?Math.abs(i-a)/2:0},o=function(e){return a(e,function(e,t){return e<t})},s=function(e){return a(e,function(e,t){return t<e})};return e.mul(Zn([i,136],t)).sub(Ur(Array.from(Array(i),function(e,t){return n(o(t),s(t))}))).div(Ur(Array.from(Array(i),function(e,t){return n(r[t].width,r[t].height)})))})},t.prototype.forwardInput=function(e){var t=this;return W(function(){var n=t.runNet(e);return t.postProcess(n,e.inputSize,e.inputDimensions.map(function(e){return{height:e[0],width:e[1]}}))})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.detectLandmarks=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i=this;return $(this,function(a){switch(a.label){case 0:return[4,jm(e)];case 1:return t=a.sent(),n=W(function(){return Kr(i.forwardInput(t))}),[4,Promise.all(n.map(function(e,n){return Q(i,void 0,void 0,function(){var r,i,a,o,s;return $(this,function(c){switch(c.label){case 0:return a=(i=Array).from,[4,e.data()];case 1:return r=a.apply(i,[c.sent()]),o=r.filter(function(e,t){return Op(t)}),s=r.filter(function(e,t){return!Op(t)}),[2,new $p(Array(68).fill(0).map(function(e,t){return new Ip(o[t],s[t])}),{height:t.getInputHeight(n),width:t.getInputWidth(n)})]}})})}))];case 2:return r=a.sent(),n.forEach(function(e){return e.dispose()}),[2,t.isBatchInput?r:r[0]]}})})},t.prototype.getClassifierChannelsOut=function(){return 136},t}(sh),Oh=function(e){Z(t,e);function t(t){return t===void 0&&(t=new nh),e.call(this,`FaceLandmark68Net`,t)||this}return t.prototype.getDefaultModelName=function(){return`face_landmark_68_model`},t.prototype.getClassifierChannelsIn=function(){return 256},t}(Dh);function kh(e){var t=[],n=eh(e,t).extractDenseBlock3Params,r={dense0:n(`dense0`,!0),dense1:n(`dense1`),dense2:n(`dense2`)};return Um(e,t),{params:r,paramMappings:t}}function Ah(e){var t=[],n=Xm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Zm(r,t).extractDenseBlock3Params,o=a(3,32,`dense0`,!0),s=a(32,64,`dense1`),c=a(64,128,`dense2`);if(i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{paramMappings:t,params:{dense0:o,dense1:s,dense2:c}}}var jh=function(e){Z(t,e);function t(){return e.call(this,`TinyFaceFeatureExtractor`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`TinyFaceFeatureExtractor - load model before inference`);return W(function(){var n=Bm(Wp(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(q(255)),t.dense0,!0);return n=Bm(n,t.dense1),n=Bm(n,t.dense2),n=cu(n,[14,14],[2,2],`valid`),n})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.getDefaultModelName=function(){return`face_feature_extractor_tiny_model`},t.prototype.extractParamsFromWeigthMap=function(e){return kh(e)},t.prototype.extractParams=function(e){return Ah(e)},t}(Rm),Mh=function(e){Z(t,e);function t(t){return t===void 0&&(t=new jh),e.call(this,`FaceLandmark68TinyNet`,t)||this}return t.prototype.getDefaultModelName=function(){return`face_landmark_68_tiny_model`},t.prototype.getClassifierChannelsIn=function(){return 128},t}(Dh);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t})(Oh);function Nh(e,t){return $c(pl(e,t.weights),t.biases)}function Ph(e,t,n,r,i){i===void 0&&(i=`same`);var a=t.conv,o=a.filters,s=a.bias,c=Vl(e,o,n,i);return c=$c(c,s),c=Nh(c,t.scale),r?Mu(c):c}function Fh(e,t){return Ph(e,t,[1,1],!0)}function Ih(e,t){return Ph(e,t,[1,1],!1)}function Lh(e,t){return Ph(e,t,[2,2],!0,`valid`)}function Rh(e,t){function n(t,n,r){var i=e(t),a=i.length/(n*r*r);if(Dp(a))throw Error(`depth has to be an integer: `+a+`, weights.length: `+i.length+`, numFilters: `+n+`, filterSize: `+r);return W(function(){return Fu(Gn(i,[n,a,r,r]),[2,3,1,0])})}function r(r,i,a,o){var s=n(r,i,a),c=Hn(e(i));return t.push({paramPath:o+`/filters`},{paramPath:o+`/bias`}),{filters:s,bias:c}}function i(n,r){var i=Hn(e(n)),a=Hn(e(n));return t.push({paramPath:r+`/weights`},{paramPath:r+`/biases`}),{weights:i,biases:a}}function a(e,t,n,a){return{conv:r(e,t,n,a+`/conv`),scale:i(t,a+`/scale`)}}function o(e,t,n,r,i){return i===void 0&&(i=!1),{conv1:a((i?.5:1)*e,t,n,r+`/conv1`),conv2:a(e,t,n,r+`/conv2`)}}return{extractConvLayerParams:a,extractResidualLayerParams:o}}function zh(e){var t=Xm(e),n=t.extractWeights,r=t.getRemainingWeights,i=[],a=Rh(n,i),o=a.extractConvLayerParams,s=a.extractResidualLayerParams,c=o(4704,32,7,`conv32_down`),l=s(9216,32,3,`conv32_1`),u=s(9216,32,3,`conv32_2`),d=s(9216,32,3,`conv32_3`),f=s(36864,64,3,`conv64_down`,!0),p=s(36864,64,3,`conv64_1`),m=s(36864,64,3,`conv64_2`),h=s(36864,64,3,`conv64_3`),g=s(147456,128,3,`conv128_down`,!0),_=s(147456,128,3,`conv128_1`),v=s(147456,128,3,`conv128_2`),y=s(589824,256,3,`conv256_down`,!0),b=s(589824,256,3,`conv256_1`),x=s(589824,256,3,`conv256_2`),S=s(589824,256,3,`conv256_down_out`),C=W(function(){return Fu(Un(n(256*128),[128,256]),[1,0])});if(i.push({paramPath:`fc`}),r().length!==0)throw Error(`weights remaing after extract: `+r().length);return{params:{conv32_down:c,conv32_1:l,conv32_2:u,conv32_3:d,conv64_down:f,conv64_1:p,conv64_2:m,conv64_3:h,conv128_down:g,conv128_1:_,conv128_2:v,conv256_down:y,conv256_1:b,conv256_2:x,conv256_down_out:S,fc:C},paramMappings:i}}function Bh(e,t){var n=Ym(e,t);function r(e){return{weights:n(e+`/scale/weights`,1),biases:n(e+`/scale/biases`,1)}}function i(e){var t=n(e+`/conv/filters`,4),i=n(e+`/conv/bias`,1),a=r(e);return{conv:{filters:t,bias:i},scale:a}}function a(e){return{conv1:i(e+`/conv1`),conv2:i(e+`/conv2`)}}return{extractConvLayerParams:i,extractResidualLayerParams:a}}function Vh(e){var t=[],n=Bh(e,t),r=n.extractConvLayerParams,i=n.extractResidualLayerParams,a=r(`conv32_down`),o=i(`conv32_1`),s=i(`conv32_2`),c=i(`conv32_3`),l=i(`conv64_down`),u=i(`conv64_1`),d=i(`conv64_2`),f=i(`conv64_3`),p=i(`conv128_down`),m=i(`conv128_1`),h=i(`conv128_2`),g=i(`conv256_down`),_=i(`conv256_1`),v=i(`conv256_2`),y=i(`conv256_down_out`),b=e.fc;if(t.push({originalPath:`fc`,paramPath:`fc`}),!wp(b))throw Error(`expected weightMap[fc] to be a Tensor2D, instead have `+b);var x={conv32_down:a,conv32_1:o,conv32_2:s,conv32_3:c,conv64_down:l,conv64_1:u,conv64_2:d,conv64_3:f,conv128_down:p,conv128_1:m,conv128_2:h,conv256_down:g,conv256_1:_,conv256_2:v,conv256_down_out:y,fc:b};return Um(e,t),{params:x,paramMappings:t}}function Hh(e,t){var n=Fh(e,t.conv1);return n=Ih(n,t.conv2),n=$c(n,e),n=Mu(n),n}function Uh(e,t){var n=Lh(e,t.conv1);n=Ih(n,t.conv2);var r=cu(e,2,2,`valid`),i=Xn(r.shape),a=r.shape[3]!==n.shape[3];if(r.shape[1]!==n.shape[1]||r.shape[2]!==n.shape[2]){var o=xp(n.shape);o[1]=1;var s=Xn(o);n=nr([n,s],1);var c=xp(n.shape);c[2]=1;var l=Xn(c);n=nr([n,l],2)}return r=a?nr([r,i],3):r,n=$c(r,n),n=Mu(n),n}var Wh=function(e){Z(t,e);function t(){return e.call(this,`FaceRecognitionNet`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`FaceRecognitionNet - load model before inference`);return W(function(){var n=Lh(Wp(e.toBatchTensor(150,!0).toFloat(),[122.782,117.001,104.298]).div(q(256)),t.conv32_down);return n=su(n,3,2,`valid`),n=Hh(n,t.conv32_1),n=Hh(n,t.conv32_2),n=Hh(n,t.conv32_3),n=Uh(n,t.conv64_down),n=Hh(n,t.conv64_1),n=Hh(n,t.conv64_2),n=Hh(n,t.conv64_3),n=Uh(n,t.conv128_down),n=Hh(n,t.conv128_1),n=Hh(n,t.conv128_2),n=Uh(n,t.conv256_down),n=Hh(n,t.conv256_1),n=Hh(n,t.conv256_2),n=Uh(n,t.conv256_down_out),Zl(n.mean([1,2]),t.fc)})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.computeFaceDescriptor=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i=this;return $(this,function(a){switch(a.label){case 0:return[4,jm(e)];case 1:return t=a.sent(),n=W(function(){return Kr(i.forwardInput(t))}),[4,Promise.all(n.map(function(e){return e.data()}))];case 2:return r=a.sent(),n.forEach(function(e){return e.dispose()}),[2,t.isBatchInput?r:r[0]]}})})},t.prototype.getDefaultModelName=function(){return`face_recognition_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Vh(e)},t.prototype.extractParams=function(e){return zh(e)},t}(Rm);function Gh(e,t){return Object.assign({},e,{descriptor:t})}function Kh(e,t){return Object.assign({},e,{age:t})}function qh(e,t,n){return Object.assign({},e,{gender:t,genderProbability:n})}var Jh=function(){function e(e){var t=e===void 0?{}:e,n=t.minFaceSize,r=t.scaleFactor,i=t.maxNumScales,a=t.scoreThresholds,o=t.scaleSteps;if(this._name=`MtcnnOptions`,this._minFaceSize=n||20,this._scaleFactor=r||.709,this._maxNumScales=i||10,this._scoreThresholds=a||[.6,.7,.7],this._scaleSteps=o,typeof this._minFaceSize!=`number`||this._minFaceSize<0)throw Error(this._name+` - expected minFaceSize to be a number > 0`);if(typeof this._scaleFactor!=`number`||this._scaleFactor<=0||this._scaleFactor>=1)throw Error(this._name+` - expected scaleFactor to be a number between 0 and 1`);if(typeof this._maxNumScales!=`number`||this._maxNumScales<0)throw Error(this._name+` - expected maxNumScales to be a number > 0`);if(!Array.isArray(this._scoreThresholds)||this._scoreThresholds.length!==3||this._scoreThresholds.some(function(e){return typeof e!=`number`}))throw Error(this._name+` - expected scoreThresholds to be an array of numbers of length 3`);if(this._scaleSteps&&(!Array.isArray(this._scaleSteps)||this._scaleSteps.some(function(e){return typeof e!=`number`})))throw Error(this._name+` - expected scaleSteps to be an array of numbers`)}return Object.defineProperty(e.prototype,`minFaceSize`,{get:function(){return this._minFaceSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`scaleFactor`,{get:function(){return this._scaleFactor},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`maxNumScales`,{get:function(){return this._maxNumScales},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`scoreThresholds`,{get:function(){return this._scoreThresholds},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`scaleSteps`,{get:function(){return this._scaleSteps},enumerable:!0,configurable:!0}),e}();function Yh(e,t){function n(n,r){var i=Gn(e(9*n),[3,3,n,1]),a=Hn(e(n)),o=Hn(e(n)),s=Hn(e(n)),c=Hn(e(n));return t.push({paramPath:r+`/filters`},{paramPath:r+`/batch_norm_scale`},{paramPath:r+`/batch_norm_offset`},{paramPath:r+`/batch_norm_mean`},{paramPath:r+`/batch_norm_variance`}),{filters:i,batch_norm_scale:a,batch_norm_offset:o,batch_norm_mean:s,batch_norm_variance:c}}function r(n,r,i,a,o){var s=Gn(e(n*r*i*i),[i,i,n,r]),c=Hn(e(r));return t.push({paramPath:a+`/filters`},{paramPath:a+`/`+(o?`batch_norm_offset`:`bias`)}),{filters:s,bias:c}}function i(e,t,n,i){var a=r(e,t,n,i,!0);return{filters:a.filters,batch_norm_offset:a.bias}}function a(e,t,r){return{depthwise_conv:n(e,r+`/depthwise_conv`),pointwise_conv:i(e,t,1,r+`/pointwise_conv`)}}function o(){return{conv_0:i(3,32,3,`mobilenetv1/conv_0`),conv_1:a(32,64,`mobilenetv1/conv_1`),conv_2:a(64,128,`mobilenetv1/conv_2`),conv_3:a(128,128,`mobilenetv1/conv_3`),conv_4:a(128,256,`mobilenetv1/conv_4`),conv_5:a(256,256,`mobilenetv1/conv_5`),conv_6:a(256,512,`mobilenetv1/conv_6`),conv_7:a(512,512,`mobilenetv1/conv_7`),conv_8:a(512,512,`mobilenetv1/conv_8`),conv_9:a(512,512,`mobilenetv1/conv_9`),conv_10:a(512,512,`mobilenetv1/conv_10`),conv_11:a(512,512,`mobilenetv1/conv_11`),conv_12:a(512,1024,`mobilenetv1/conv_12`),conv_13:a(1024,1024,`mobilenetv1/conv_13`)}}function s(){var e=i(1024,256,1,`prediction_layer/conv_0`),t=i(256,512,3,`prediction_layer/conv_1`),n=i(512,128,1,`prediction_layer/conv_2`),a=i(128,256,3,`prediction_layer/conv_3`),o=i(256,128,1,`prediction_layer/conv_4`),s=i(128,256,3,`prediction_layer/conv_5`),c=i(256,64,1,`prediction_layer/conv_6`),l=i(64,128,3,`prediction_layer/conv_7`),u=r(512,12,1,`prediction_layer/box_predictor_0/box_encoding_predictor`),d=r(512,9,1,`prediction_layer/box_predictor_0/class_predictor`),f=r(1024,24,1,`prediction_layer/box_predictor_1/box_encoding_predictor`),p=r(1024,18,1,`prediction_layer/box_predictor_1/class_predictor`),m=r(512,24,1,`prediction_layer/box_predictor_2/box_encoding_predictor`),h=r(512,18,1,`prediction_layer/box_predictor_2/class_predictor`),g=r(256,24,1,`prediction_layer/box_predictor_3/box_encoding_predictor`),_=r(256,18,1,`prediction_layer/box_predictor_3/class_predictor`),v=r(256,24,1,`prediction_layer/box_predictor_4/box_encoding_predictor`),y=r(256,18,1,`prediction_layer/box_predictor_4/class_predictor`),b=r(128,24,1,`prediction_layer/box_predictor_5/box_encoding_predictor`),x=r(128,18,1,`prediction_layer/box_predictor_5/class_predictor`);return{conv_0:e,conv_1:t,conv_2:n,conv_3:a,conv_4:o,conv_5:s,conv_6:c,conv_7:l,box_predictor_0:{box_encoding_predictor:u,class_predictor:d},box_predictor_1:{box_encoding_predictor:f,class_predictor:p},box_predictor_2:{box_encoding_predictor:m,class_predictor:h},box_predictor_3:{box_encoding_predictor:g,class_predictor:_},box_predictor_4:{box_encoding_predictor:v,class_predictor:y},box_predictor_5:{box_encoding_predictor:b,class_predictor:x}}}return{extractMobilenetV1Params:o,extractPredictionLayerParams:s}}function Xh(e){var t=[],n=Xm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Yh(r,t),o=a.extractMobilenetV1Params,s=a.extractPredictionLayerParams,c=o(),l=s(),u={extra_dim:Wn(r(5118*4),[1,5118,4])};if(t.push({paramPath:`output_layer/extra_dim`}),i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{params:{mobilenetv1:c,prediction_layer:l,output_layer:u},paramMappings:t}}function Zh(e,t){var n=Ym(e,t);function r(e,t,r){return{filters:n(e+`/Conv2d_`+t+`_pointwise/weights`,4,r+`/filters`),batch_norm_offset:n(e+`/Conv2d_`+t+`_pointwise/convolution_bn_offset`,1,r+`/batch_norm_offset`)}}function i(e){var t=`mobilenetv1/conv_`+e,i=`MobilenetV1/Conv2d_`+e+`_depthwise`,a=t+`/depthwise_conv`,o=t+`/pointwise_conv`;return{depthwise_conv:{filters:n(i+`/depthwise_weights`,4,a+`/filters`),batch_norm_scale:n(i+`/BatchNorm/gamma`,1,a+`/batch_norm_scale`),batch_norm_offset:n(i+`/BatchNorm/beta`,1,a+`/batch_norm_offset`),batch_norm_mean:n(i+`/BatchNorm/moving_mean`,1,a+`/batch_norm_mean`),batch_norm_variance:n(i+`/BatchNorm/moving_variance`,1,a+`/batch_norm_variance`)},pointwise_conv:r(`MobilenetV1`,e,o)}}function a(){return{conv_0:r(`MobilenetV1`,0,`mobilenetv1/conv_0`),conv_1:i(1),conv_2:i(2),conv_3:i(3),conv_4:i(4),conv_5:i(5),conv_6:i(6),conv_7:i(7),conv_8:i(8),conv_9:i(9),conv_10:i(10),conv_11:i(11),conv_12:i(12),conv_13:i(13)}}function o(e,t){return{filters:n(e+`/weights`,4,t+`/filters`),bias:n(e+`/biases`,1,t+`/bias`)}}function s(e){return{box_encoding_predictor:o(`Prediction/BoxPredictor_`+e+`/BoxEncodingPredictor`,`prediction_layer/box_predictor_`+e+`/box_encoding_predictor`),class_predictor:o(`Prediction/BoxPredictor_`+e+`/ClassPredictor`,`prediction_layer/box_predictor_`+e+`/class_predictor`)}}function c(){return{conv_0:r(`Prediction`,0,`prediction_layer/conv_0`),conv_1:r(`Prediction`,1,`prediction_layer/conv_1`),conv_2:r(`Prediction`,2,`prediction_layer/conv_2`),conv_3:r(`Prediction`,3,`prediction_layer/conv_3`),conv_4:r(`Prediction`,4,`prediction_layer/conv_4`),conv_5:r(`Prediction`,5,`prediction_layer/conv_5`),conv_6:r(`Prediction`,6,`prediction_layer/conv_6`),conv_7:r(`Prediction`,7,`prediction_layer/conv_7`),box_predictor_0:s(0),box_predictor_1:s(1),box_predictor_2:s(2),box_predictor_3:s(3),box_predictor_4:s(4),box_predictor_5:s(5)}}return{extractMobilenetV1Params:a,extractPredictionLayerParams:c}}function Qh(e){var t=[],n=Zh(e,t),r=n.extractMobilenetV1Params,i=n.extractPredictionLayerParams,a=e[`Output/extra_dim`];if(t.push({originalPath:`Output/extra_dim`,paramPath:`output_layer/extra_dim`}),!Tp(a))throw Error(`expected weightMap['Output/extra_dim'] to be a Tensor3D, instead have `+a);var o={mobilenetv1:r(),prediction_layer:i(),output_layer:{extra_dim:a}};return Um(e,t),{params:o,paramMappings:t}}function $h(e,t,n){return W(function(){var r=Vl(e,t.filters,n,`same`);return r=$c(r,t.batch_norm_offset),sc(r,0,6)})}var eg=.0010000000474974513;function tg(e,t,n){return W(function(){var r=Gl(e,t.filters,n,`same`);return r=Uc(r,t.batch_norm_mean,t.batch_norm_variance,t.batch_norm_offset,t.batch_norm_scale,eg),sc(r,0,6)})}function ng(e){return[2,4,6,12].some(function(t){return t===e})?[2,2]:[1,1]}function rg(e,t){return W(function(){var n=null,r=$h(e,t.conv_0,[2,2]);if([t.conv_1,t.conv_2,t.conv_3,t.conv_4,t.conv_5,t.conv_6,t.conv_7,t.conv_8,t.conv_9,t.conv_10,t.conv_11,t.conv_12,t.conv_13].forEach(function(e,t){var i=t+1,a=ng(i);r=tg(r,e.depthwise_conv,a),r=$h(r,e.pointwise_conv,[1,1]),i===11&&(n=r)}),n===null)throw Error(`mobileNetV1 - output of conv layer 11 is null`);return{out:r,conv11:n}})}function ig(e,t,n,r,i){var a=e.shape[0],o=Math.min(n,a),s=t.map(function(e,t){return{score:e,boxIndex:t}}).filter(function(e){return e.score>i}).sort(function(e,t){return t.score-e.score}),c=function(e){return e<=r?1:0},l=[];return s.forEach(function(t){if(!(l.length>=o)){for(var n=t.score,r=l.length-1;r>=0;--r){var a=ag(e,t.boxIndex,l[r]);if(a!==0&&(t.score*=c(a),t.score<=i))break}n===t.score&&l.push(t.boxIndex)}}),l}function ag(e,t,n){var r=e.arraySync(),i=Math.min(r[t][0],r[t][2]),a=Math.min(r[t][1],r[t][3]),o=Math.max(r[t][0],r[t][2]),s=Math.max(r[t][1],r[t][3]),c=Math.min(r[n][0],r[n][2]),l=Math.min(r[n][1],r[n][3]),u=Math.max(r[n][0],r[n][2]),d=Math.max(r[n][1],r[n][3]),f=(o-i)*(s-a),p=(u-c)*(d-l);if(f<=0||p<=0)return 0;var m=Math.max(i,c),h=Math.max(a,l),g=Math.min(o,u),_=Math.min(s,d),v=Math.max(g-m,0)*Math.max(_-h,0);return v/(f+p-v)}function og(e){var t=Kr(Fu(e,[1,0])),n=[vl(t[2],t[0]),vl(t[3],t[1])];return{sizes:n,centers:[$c(t[0],rl(n[0],q(2))),$c(t[1],rl(n[1],q(2)))]}}function sg(e,t){var n=og(e),r=n.sizes,i=n.centers,a=Kr(Fu(t,[1,0])),o=rl(pl(dc(rl(a[2],q(5))),r[0]),q(2)),s=$c(pl(rl(a[0],q(10)),r[0]),i[0]),c=rl(pl(dc(rl(a[3],q(5))),r[1]),q(2)),l=$c(pl(rl(a[1],q(10)),r[1]),i[1]);return Fu(Ur([vl(s,o),vl(l,c),$c(s,o),$c(l,c)]),[1,0])}function cg(e,t,n){return W(function(){var r=e.shape[0],i=sg(Br(Wr(n.extra_dim,[r,1,1]),[-1,4]),Br(e,[-1,4]));i=Br(i,[r,i.shape[0]/r,4]);var a=fu(xc(fu(t,[0,0,1],[-1,-1,-1])),[0,0,0],[-1,-1,1]);return a=Br(a,[r,a.shape[1]]),{boxes:Kr(i),scores:Kr(a)}})}function lg(e,t){return W(function(){var n=e.shape[0];return{boxPredictionEncoding:Br(Hm(e,t.box_encoding_predictor),[n,-1,1,4]),classPrediction:Br(Hm(e,t.class_predictor),[n,-1,3])}})}function ug(e,t,n){return W(function(){var r=$h($h(e,n.conv_0,[1,1]),n.conv_1,[2,2]),i=$h($h(r,n.conv_2,[1,1]),n.conv_3,[2,2]),a=$h($h(i,n.conv_4,[1,1]),n.conv_5,[2,2]),o=$h($h(a,n.conv_6,[1,1]),n.conv_7,[2,2]),s=lg(t,n.box_predictor_0),c=lg(e,n.box_predictor_1),l=lg(r,n.box_predictor_2),u=lg(i,n.box_predictor_3),d=lg(a,n.box_predictor_4),f=lg(o,n.box_predictor_5);return{boxPredictions:nr([s.boxPredictionEncoding,c.boxPredictionEncoding,l.boxPredictionEncoding,u.boxPredictionEncoding,d.boxPredictionEncoding,f.boxPredictionEncoding],1),classPredictions:nr([s.classPrediction,c.classPrediction,l.classPrediction,u.classPrediction,d.classPrediction,f.classPrediction],1)}})}var dg=function(){function e(e){var t=e===void 0?{}:e,n=t.minConfidence,r=t.maxResults;if(this._name=`SsdMobilenetv1Options`,this._minConfidence=n||.5,this._maxResults=r||100,typeof this._minConfidence!=`number`||this._minConfidence<=0||this._minConfidence>=1)throw Error(this._name+` - expected minConfidence to be a number between 0 and 1`);if(typeof this._maxResults!=`number`)throw Error(this._name+` - expected maxResults to be a number`)}return Object.defineProperty(e.prototype,`minConfidence`,{get:function(){return this._minConfidence},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`maxResults`,{get:function(){return this._maxResults},enumerable:!0,configurable:!0}),e}(),fg=function(e){Z(t,e);function t(){return e.call(this,`SsdMobilenetv1`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`SsdMobilenetv1 - load model before inference`);return W(function(){var n=rg(vl(pl(e.toBatchTensor(512,!1).toFloat(),q(.007843137718737125)),q(1)),t.mobilenetv1),r=ug(n.out,n.conv11,t.prediction_layer),i=r.boxPredictions,a=r.classPredictions;return cg(i,a,t.output_layer)})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.locateFaces=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S;return $(this,function(C){switch(C.label){case 0:return n=new dg(t),r=n.maxResults,i=n.minConfidence,[4,jm(e)];case 1:for(a=C.sent(),o=this.forwardInput(a),s=o.boxes,c=o.scores,l=s[0],u=c[0],d=1;d<s.length;d++)s[d].dispose(),c[d].dispose();return m=(p=Array).from,[4,u.data()];case 2:return f=m.apply(p,[C.sent()]),h=.5,g=ig(l,f,r,h,i),_=a.getReshapedInputDimensions(0),v=a.inputSize,y=v/_.width,b=v/_.height,x=l.arraySync(),S=g.map(function(e){var t=[Math.max(0,x[e][0]),Math.min(1,x[e][2])].map(function(e){return e*b}),n=t[0],r=t[1],i=[Math.max(0,x[e][1]),Math.min(1,x[e][3])].map(function(e){return e*y}),o=i[0],s=i[1];return new Bp(f[e],new qp(o,n,s-o,r-n),{height:a.getInputHeight(0),width:a.getInputWidth(0)})}),l.dispose(),u.dispose(),[2,S]}})})},t.prototype.getDefaultModelName=function(){return`ssd_mobilenetv1_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Qh(e)},t.prototype.extractParams=function(e){return Xh(e)},t}(Rm);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t})(fg);var pg=.4,mg=[new Ip(.738768,.874946),new Ip(2.42204,2.65704),new Ip(4.30971,7.04493),new Ip(10.246,4.59428),new Ip(12.6868,11.8741)],hg=[new Ip(1.603231,2.094468),new Ip(6.041143,7.080126),new Ip(2.882459,3.518061),new Ip(4.266906,5.178857),new Ip(9.041765,10.66308)],gg=[117.001,114.697,97.404],_g=`tiny_yolov2_model`,vg=`tiny_yolov2_separable_conv_model`,yg=function(e){return typeof e==`number`};function bg(e){if(!e)throw Error(`invalid config: `+e);if(typeof e.withSeparableConvs!=`boolean`)throw Error(`config.withSeparableConvs has to be a boolean, have: `+e.withSeparableConvs);if(!yg(e.iouThreshold)||e.iouThreshold<0||e.iouThreshold>1)throw Error(`config.iouThreshold has to be a number between [0, 1], have: `+e.iouThreshold);if(!Array.isArray(e.classes)||!e.classes.length||!e.classes.every(function(e){return typeof e==`string`}))throw Error(`config.classes has to be an array class names: string[], have: `+JSON.stringify(e.classes));if(!Array.isArray(e.anchors)||!e.anchors.length||!e.anchors.map(function(e){return e||{}}).every(function(e){return yg(e.x)&&yg(e.y)}))throw Error(`config.anchors has to be an array of { x: number, y: number }, have: `+JSON.stringify(e.anchors));if(e.meanRgb&&(!Array.isArray(e.meanRgb)||e.meanRgb.length!==3||!e.meanRgb.every(yg)))throw Error(`config.meanRgb has to be an array of shape [number, number, number], have: `+JSON.stringify(e.meanRgb))}function xg(e){return W(function(){var t=pl(e,q(.10000000149011612));return $c(Mu(vl(e,t)),t)})}function Sg(e,t){return W(function(){var n=jr(e,[[0,0],[1,1],[1,1],[0,0]]);return n=Vl(n,t.conv.filters,[1,1],`valid`),n=vl(n,t.bn.sub),n=pl(n,t.bn.truediv),n=$c(n,t.conv.bias),xg(n)})}function Cg(e,t){return W(function(){var n=jr(e,[[0,0],[1,1],[1,1],[0,0]]);return n=Jl(n,t.depthwise_filter,t.pointwise_filter,[1,1],`valid`),n=$c(n,t.bias),xg(n)})}function wg(e,t){var n=Wm(e,t);function r(n,r){var i=Hn(e(n)),a=Hn(e(n));return t.push({paramPath:r+`/sub`},{paramPath:r+`/truediv`}),{sub:i,truediv:a}}function i(e,t,i){return{conv:n(e,t,3,i+`/conv`),bn:r(t,i+`/bn`)}}return{extractConvParams:n,extractConvWithBatchNormParams:i,extractSeparableConvParams:qm(e,t)}}function Tg(e,t,n,r){var i=Xm(e),a=i.extractWeights,o=i.getRemainingWeights,s=[],c=wg(a,s),l=c.extractConvParams,u=c.extractConvWithBatchNormParams,d=c.extractSeparableConvParams,f;if(t.withSeparableConvs){var p=r[0],m=r[1],h=r[2],g=r[3],_=r[4],v=r[5],y=r[6],b=r[7],x=r[8],S=t.isFirstLayerConv2d?l(p,m,3,`conv0`):d(p,m,`conv0`),C=d(m,h,`conv1`),w=d(h,g,`conv2`),T=d(g,_,`conv3`),E=d(_,v,`conv4`),D=d(v,y,`conv5`),O=b?d(y,b,`conv6`):void 0,k=x?d(b,x,`conv7`):void 0,A=l(x||b||y,5*n,1,`conv8`);f={conv0:S,conv1:C,conv2:w,conv3:T,conv4:E,conv5:D,conv6:O,conv7:k,conv8:A}}else{var p=r[0],m=r[1],h=r[2],g=r[3],_=r[4],v=r[5],y=r[6],b=r[7],x=r[8],S=u(p,m,`conv0`),C=u(m,h,`conv1`),w=u(h,g,`conv2`),T=u(g,_,`conv3`),E=u(_,v,`conv4`),D=u(v,y,`conv5`),O=u(y,b,`conv6`),k=u(b,x,`conv7`),A=l(x,5*n,1,`conv8`);f={conv0:S,conv1:C,conv2:w,conv3:T,conv4:E,conv5:D,conv6:O,conv7:k,conv8:A}}if(o().length!==0)throw Error(`weights remaing after extract: `+o().length);return{params:f,paramMappings:s}}function Eg(e,t){var n=Ym(e,t);function r(e){return{sub:n(e+`/sub`,1),truediv:n(e+`/truediv`,1)}}function i(e){return{filters:n(e+`/filters`,4),bias:n(e+`/bias`,1)}}function a(e){return{conv:i(e+`/conv`),bn:r(e+`/bn`)}}return{extractConvParams:i,extractConvWithBatchNormParams:a,extractSeparableConvParams:Jm(n)}}function Dg(e,t){var n=[],r=Eg(e,n),i=r.extractConvParams,a=r.extractConvWithBatchNormParams,o=r.extractSeparableConvParams,s;if(t.withSeparableConvs){var c=t.filterSizes&&t.filterSizes.length||9;s={conv0:t.isFirstLayerConv2d?i(`conv0`):o(`conv0`),conv1:o(`conv1`),conv2:o(`conv2`),conv3:o(`conv3`),conv4:o(`conv4`),conv5:o(`conv5`),conv6:c>7?o(`conv6`):void 0,conv7:c>8?o(`conv7`):void 0,conv8:i(`conv8`)}}else s={conv0:a(`conv0`),conv1:a(`conv1`),conv2:a(`conv2`),conv3:a(`conv3`),conv4:a(`conv4`),conv5:a(`conv5`),conv6:a(`conv6`),conv7:a(`conv7`),conv8:i(`conv8`)};return Um(e,n),{params:s,paramMappings:n}}var Og;(function(e){e[e.XS=224]=`XS`,e[e.SM=320]=`SM`,e[e.MD=416]=`MD`,e[e.LG=608]=`LG`})(Og||={});var kg=function(){function e(e){var t=e===void 0?{}:e,n=t.inputSize,r=t.scoreThreshold;if(this._name=`TinyYolov2Options`,this._inputSize=n||416,this._scoreThreshold=r||.5,typeof this._inputSize!=`number`||this._inputSize%32!=0)throw Error(this._name+` - expected inputSize to be a number divisible by 32`);if(typeof this._scoreThreshold!=`number`||this._scoreThreshold<=0||this._scoreThreshold>=1)throw Error(this._name+` - expected scoreThreshold to be a number between 0 and 1`)}return Object.defineProperty(e.prototype,`inputSize`,{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`scoreThreshold`,{get:function(){return this._scoreThreshold},enumerable:!0,configurable:!0}),e}(),Ag=function(e){Z(t,e);function t(t){var n=e.call(this,`TinyYolov2`)||this;return bg(t),n._config=t,n}return Object.defineProperty(t.prototype,`config`,{get:function(){return this._config},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,`withClassScores`,{get:function(){return this.config.withClassScores||this.config.classes.length>1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,`boxEncodingSize`,{get:function(){return 5+(this.withClassScores?this.config.classes.length:0)},enumerable:!0,configurable:!0}),t.prototype.runTinyYolov2=function(e,t){var n=Sg(e,t.conv0);return n=su(n,[2,2],[2,2],`same`),n=Sg(n,t.conv1),n=su(n,[2,2],[2,2],`same`),n=Sg(n,t.conv2),n=su(n,[2,2],[2,2],`same`),n=Sg(n,t.conv3),n=su(n,[2,2],[2,2],`same`),n=Sg(n,t.conv4),n=su(n,[2,2],[2,2],`same`),n=Sg(n,t.conv5),n=su(n,[2,2],[1,1],`same`),n=Sg(n,t.conv6),n=Sg(n,t.conv7),Hm(n,t.conv8,`valid`,!1)},t.prototype.runMobilenet=function(e,t){var n=this.config.isFirstLayerConv2d?xg(Hm(e,t.conv0,`valid`,!1)):Cg(e,t.conv0);return n=su(n,[2,2],[2,2],`same`),n=Cg(n,t.conv1),n=su(n,[2,2],[2,2],`same`),n=Cg(n,t.conv2),n=su(n,[2,2],[2,2],`same`),n=Cg(n,t.conv3),n=su(n,[2,2],[2,2],`same`),n=Cg(n,t.conv4),n=su(n,[2,2],[2,2],`same`),n=Cg(n,t.conv5),n=su(n,[2,2],[1,1],`same`),n=t.conv6?Cg(n,t.conv6):n,n=t.conv7?Cg(n,t.conv7):n,Hm(n,t.conv8,`valid`,!1)},t.prototype.forwardInput=function(e,t){var n=this,r=this.params;if(!r)throw Error(`TinyYolov2 - load model before inference`);return W(function(){var i=e.toBatchTensor(t,!1).toFloat();return i=n.config.meanRgb?Wp(i,n.config.meanRgb):i,i=i.div(q(256)),n.config.withSeparableConvs?n.runMobilenet(i,r):n.runTinyYolov2(i,r)})},t.prototype.forward=function(e,t){return Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return n=this.forwardInput,[4,jm(e)];case 1:return[4,n.apply(this,[r.sent(),t])];case 2:return[2,r.sent()]}})})},t.prototype.detect=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c,l,u,d,f,p,m,h,g=this;return $(this,function(_){switch(_.label){case 0:return n=new kg(t),r=n.inputSize,i=n.scoreThreshold,[4,jm(e)];case 1:return a=_.sent(),[4,this.forwardInput(a,r)];case 2:return o=_.sent(),s=W(function(){return Kr(o)[0].expandDims()}),c={width:a.getInputWidth(0),height:a.getInputHeight(0)},[4,this.extractBoxes(s,a.getReshapedInputDimensions(0),i)];case 3:return l=_.sent(),o.dispose(),s.dispose(),u=l.map(function(e){return e.box}),d=l.map(function(e){return e.score}),f=l.map(function(e){return e.classScore}),p=l.map(function(e){return g.config.classes[e.label]}),m=Up(u.map(function(e){return e.rescale(r)}),d,this.config.iouThreshold,!0),h=m.map(function(e){return new zp(d[e],f[e],p[e],u[e],c)}),[2,h]}})})},t.prototype.getDefaultModelName=function(){return``},t.prototype.extractParamsFromWeigthMap=function(e){return Dg(e,this.config)},t.prototype.extractParams=function(e){var n=this.config.filterSizes||t.DEFAULT_FILTER_SIZES,r=n?n.length:void 0;if(r!==7&&r!==8&&r!==9)throw Error(`TinyYolov2 - expected 7 | 8 | 9 convolutional filters, but found `+r+` filterSizes in config`);return Tg(e,this.config,this.boxEncodingSize,n)},t.prototype.extractBoxes=function(e,t,n){return Q(this,void 0,void 0,function(){var r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M=this;return $(this,function(N){switch(N.label){case 0:return r=t.width,i=t.height,a=Math.max(r,i),o=a/r,s=a/i,c=e.shape[1],l=this.config.anchors.length,u=W(function(){var t=e.reshape([c,c,l,M.boxEncodingSize]);return[t.slice([0,0,0,0],[c,c,l,4]),t.slice([0,0,0,4],[c,c,l,1]),M.withClassScores?mi(t.slice([0,0,0,5],[c,c,l,M.config.classes.length]),3):q(0)]}),d=u[0],f=u[1],p=u[2],m=[],[4,f.array()];case 1:return h=N.sent(),[4,d.array()];case 2:g=N.sent(),_=0,N.label=3;case 3:if(!(_<c))return[3,12];v=0,N.label=4;case 4:if(!(v<c))return[3,11];y=0,N.label=5;case 5:return y<l?(b=Kp(h[_][v][y][0]),!n||b>n?(x=(v+Kp(g[_][v][y][0]))/c*o,S=(_+Kp(g[_][v][y][1]))/c*s,C=Math.exp(g[_][v][y][2])*this.config.anchors[y].x/c*o,w=Math.exp(g[_][v][y][3])*this.config.anchors[y].y/c*s,T=x-C/2,E=S-w/2,D={row:_,col:v,anchor:y},this.withClassScores?[4,this.extractPredictedClass(p,D)]:[3,7]):[3,9]):[3,10];case 6:return j=N.sent(),[3,8];case 7:j={classScore:1,label:0},N.label=8;case 8:O=j,k=O.classScore,A=O.label,m.push(bp({box:new Rp(T,E,T+C,E+w),score:b,classScore:b*k,label:A},D)),N.label=9;case 9:return y++,[3,5];case 10:return v++,[3,4];case 11:return _++,[3,3];case 12:return d.dispose(),f.dispose(),p.dispose(),[2,m]}})})},t.prototype.extractPredictedClass=function(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a;return $(this,function(o){switch(o.label){case 0:return n=t.row,r=t.col,i=t.anchor,[4,e.array()];case 1:return a=o.sent(),[2,Array(this.config.classes.length).fill(0).map(function(e,t){return a[n][r][i][t]}).map(function(e,t){return{classScore:e,label:t}}).reduce(function(e,t){return e.classScore>t.classScore?e:t})]}})})},t.DEFAULT_FILTER_SIZES=[3,16,32,64,128,256,512,1024,1024],t}(Rm),jg=function(e){Z(t,e);function t(t){t===void 0&&(t=!0);var n=this,r=Object.assign({},{withSeparableConvs:t,iouThreshold:pg,classes:[`face`]},t?{anchors:hg,meanRgb:gg}:{anchors:mg,withClassScores:!0});return n=e.call(this,r)||this,n}return Object.defineProperty(t.prototype,`withSeparableConvs`,{get:function(){return this.config.withSeparableConvs},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,`anchors`,{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),t.prototype.locateFaces=function(e,t){return Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return[4,this.detect(e,t)];case 1:return n=r.sent(),[2,n.map(function(e){return new Bp(e.score,e.relativeBox,{width:e.imageWidth,height:e.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return this.withSeparableConvs?vg:_g},t.prototype.extractParamsFromWeigthMap=function(t){return e.prototype.extractParamsFromWeigthMap.call(this,t)},t}(Ag),Mg=function(e){Z(t,e);function t(){var t=e!==null&&e.apply(this,arguments)||this;return t._name=`TinyFaceDetectorOptions`,t}return t}(kg),Ng=function(){function e(){}return e.prototype.then=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=e,[4,this.run()];case 1:return[2,t.apply(void 0,[n.sent()])]}})})},e.prototype.run=function(){return Q(this,void 0,void 0,function(){return $(this,function(e){throw Error(`ComposableTask - run is not implemented`)})})},e}();function Pg(e,t,n,r,i){return i===void 0&&(i=function(e){return e.alignedRect}),Q(this,void 0,void 0,function(){var a,o,s,c,l;return $(this,function(u){switch(u.label){case 0:return a=e.map(function(e){return fh(e)?i(e):e.detection}),s=r,s?[3,5]:t instanceof $e?[4,Nm(t,a)]:[3,2];case 1:return c=u.sent(),[3,4];case 2:return[4,Mm(t,a)];case 3:c=u.sent(),u.label=4;case 4:s=c,u.label=5;case 5:return o=s,[4,n(o)];case 6:return l=u.sent(),o.forEach(function(e){return e instanceof $e&&e.dispose()}),[2,l]}})})}function Fg(e,t,n,r,i){return Q(this,void 0,void 0,function(){var a=this;return $(this,function(o){return[2,Pg([e],t,function(e){return Q(a,void 0,void 0,function(){return $(this,function(t){return[2,n(e[0])]})})},r,i)]})})}function Ig(e){return W(function(){return Ur(Kr(e,3).reverse(),3)})}function Lg(e,t){var n=Wm(e,t),r=Gm(e,t);function i(n,r){var i=Hn(e(n));return t.push({paramPath:r}),i}function a(e,t,r){return r===void 0&&(r=!1),{conv1:n(e[0],e[1],3,t+`/conv1`),prelu1_alpha:i(e[1],t+`/prelu1_alpha`),conv2:n(e[1],e[2],3,t+`/conv2`),prelu2_alpha:i(e[2],t+`/prelu2_alpha`),conv3:n(e[2],e[3],r?2:3,t+`/conv3`),prelu3_alpha:i(e[3],t+`/prelu3_alpha`)}}function o(){var e=a([3,10,16,32],`pnet`),t=n(32,2,1,`pnet/conv4_1`),r=n(32,4,1,`pnet/conv4_2`);return bp(bp({},e),{conv4_1:t,conv4_2:r})}function s(){var e=a([3,28,48,64],`rnet`,!0),t=r(576,128,`rnet/fc1`),n=i(128,`rnet/prelu4_alpha`),o=r(128,2,`rnet/fc2_1`),s=r(128,4,`rnet/fc2_2`);return bp(bp({},e),{fc1:t,prelu4_alpha:n,fc2_1:o,fc2_2:s})}function c(){var e=a([3,32,64,64],`onet`),t=n(64,128,2,`onet/conv4`),o=i(128,`onet/prelu4_alpha`),s=r(1152,256,`onet/fc1`),c=i(256,`onet/prelu5_alpha`),l=r(256,2,`onet/fc2_1`),u=r(256,4,`onet/fc2_2`),d=r(256,10,`onet/fc2_3`);return bp(bp({},e),{conv4:t,prelu4_alpha:o,fc1:s,prelu5_alpha:c,fc2_1:l,fc2_2:u,fc2_3:d})}return{extractPNetParams:o,extractRNetParams:s,extractONetParams:c}}function Rg(e){var t=Xm(e),n=t.extractWeights,r=t.getRemainingWeights,i=[],a=Lg(n,i),o=a.extractPNetParams,s=a.extractRNetParams,c=a.extractONetParams,l=o(),u=s(),d=c();if(r().length!==0)throw Error(`weights remaing after extract: `+r().length);return{params:{pnet:l,rnet:u,onet:d},paramMappings:i}}function zg(e,t){var n=Ym(e,t);function r(e){return{filters:n(e+`/weights`,4,e+`/filters`),bias:n(e+`/bias`,1)}}function i(e){return{weights:n(e+`/weights`,2),bias:n(e+`/bias`,1)}}function a(e){return n(e,1)}function o(e){return{conv1:r(e+`/conv1`),prelu1_alpha:a(e+`/prelu1_alpha`),conv2:r(e+`/conv2`),prelu2_alpha:a(e+`/prelu2_alpha`),conv3:r(e+`/conv3`),prelu3_alpha:a(e+`/prelu3_alpha`)}}function s(){var e=o(`pnet`),t=r(`pnet/conv4_1`),n=r(`pnet/conv4_2`);return bp(bp({},e),{conv4_1:t,conv4_2:n})}function c(){var e=o(`rnet`),t=i(`rnet/fc1`),n=a(`rnet/prelu4_alpha`),r=i(`rnet/fc2_1`),s=i(`rnet/fc2_2`);return bp(bp({},e),{fc1:t,prelu4_alpha:n,fc2_1:r,fc2_2:s})}function l(){var e=o(`onet`),t=r(`onet/conv4`),n=a(`onet/prelu4_alpha`),s=i(`onet/fc1`),c=a(`onet/prelu5_alpha`),l=i(`onet/fc2_1`),u=i(`onet/fc2_2`),d=i(`onet/fc2_3`);return bp(bp({},e),{conv4:t,prelu4_alpha:n,fc1:s,prelu5_alpha:c,fc2_1:l,fc2_2:u,fc2_3:d})}return{extractPNetParams:s,extractRNetParams:c,extractONetParams:l}}function Bg(e){var t=[],n=zg(e,t),r=n.extractPNetParams,i=n.extractRNetParams,a=n.extractONetParams,o=r(),s=i(),c=a();return Um(e,t),{params:{pnet:o,rnet:s,onet:c},paramMappings:t}}function Vg(e,t){var n=t[0],r=t[1];return{height:Math.floor(n*e),width:Math.floor(r*e)}}function Hg(e,t,n){for(var r=n[0],i=n[1],a=12/e,o=[],s=Math.min(r,i)*a,c=0;s>=12;)o.push(a*t**+c),s*=t,c+=1;return o}var Ug=function(e){Z(t,e);function t(t,n,r,i){return e.call(this,{left:t,top:n,right:r,bottom:i},!0)||this}return t}(Lp);function Wg(e){return W(function(){return pl(vl(e,q(127.5)),q(.0078125))})}function Gg(e,t){return W(function(){return $c(Mu(e),pl(t,_c(Mu(_c(e)))))})}function Kg(e,t,n){return n===void 0&&(n=!1),W(function(){var r=Hm(e,t.conv1,`valid`);return r=Gg(r,t.prelu1_alpha),r=su(r,n?[2,2]:[3,3],[2,2],`same`),r=Hm(r,t.conv2,`valid`),r=Gg(r,t.prelu2_alpha),r=n?r:su(r,[3,3],[2,2],`valid`),r=Hm(r,t.conv3,`valid`),r=Gg(r,t.prelu3_alpha),r})}function qg(e,t){return W(function(){var n=Kg(e,t,!0),r=Hm(n,t.conv4_1,`valid`);return{prob:mi(vl(r,Dr(Cu(r,3),3)),3),regions:Hm(n,t.conv4_2,`valid`)}})}function Jg(e,t){return W(function(){var n=Vg(t,e.shape.slice(1)),r=n.height,i=n.width;return Fu(Wg(Ad.resizeBilinear(e,[r,i])),[0,2,1,3])})}function Yg(e,t,n,r){for(var i=[],a=e.arraySync(),o=0;o<e.shape[0];o++)for(var s=0;s<e.shape[1];s++)a[o][s]>=r&&i.push(new Ip(s,o));return i.map(function(e){var r=new Rp(Math.round((e.y*2+1)/n),Math.round((e.x*2+1)/n),Math.round((e.y*2+12)/n),Math.round((e.x*2+12)/n)),i=a[e.y][e.x],o=t.arraySync();return{cell:r,score:i,region:new Ug(o[e.y][e.x][0],o[e.y][e.x][1],o[e.y][e.x][2],o[e.y][e.x][3])}})}function Xg(e,t,n,r,i){i.stage1=[];var a=t.map(function(t){return W(function(){var n={scale:t},i=Jg(e,t),a=Date.now(),o=qg(i,r),s=o.prob,c=o.regions;return n.pnet=Date.now()-a,{scoresTensor:Kr(Kr(s,3)[1])[0],regionsTensor:Kr(c)[0],scale:t,statsForScale:n}})}).map(function(e){var t=e.scoresTensor,r=e.regionsTensor,a=e.scale,o=e.statsForScale,s=Yg(t,r,a,n);if(t.dispose(),r.dispose(),!s.length)return i.stage1.push(o),[];var c=Date.now(),l=Up(s.map(function(e){return e.cell}),s.map(function(e){return e.score}),.5);return o.nms=Date.now()-c,o.numBoxes=l.length,i.stage1.push(o),l.map(function(e){return s[e]})}).reduce(function(e,t){return e.concat(t)},[]),o=[],s=[];if(a.length>0){var c=Date.now(),l=Up(a.map(function(e){return e.cell}),a.map(function(e){return e.score}),.7);i.stage1_nms=Date.now()-c,s=l.map(function(e){return a[e].score}),o=l.map(function(e){return a[e]}).map(function(e){var t=e.cell,n=e.region;return new Rp(t.left+n.left*t.width,t.top+n.top*t.height,t.right+n.right*t.width,t.bottom+n.bottom*t.height).toSquare().round()})}return{boxes:o,scores:s}}function Zg(e,t,n){var r=n.width,i=n.height;return Q(this,void 0,void 0,function(){var n,a,o,s=this;return $(this,function(c){switch(c.label){case 0:return n=_m(e),[4,Promise.all(t.map(function(t){return Q(s,void 0,void 0,function(){var r,i,a,o,s,c,l,u;return $(this,function(d){return r=t.padAtBorders(e.height,e.width),i=r.y,a=r.ey,o=r.x,s=r.ex,c=o-1,l=i-1,u=n.getImageData(c,l,s-c,a-l),[2,hm.isNodejs()?Em(u):createImageBitmap(u)]})})}))];case 1:return a=c.sent(),o=[],a.forEach(function(e){var t=_m(Tm({width:r,height:i}));t.drawImage(e,0,0,r,i);for(var n=t.getImageData(0,0,r,i).data,a=[],s=0;s<n.length;s+=4)a.push(n[s+2]),a.push(n[s+1]),a.push(n[s]);o.push(a)}),[2,o.map(function(e){return W(function(){return Wg(Fu(Gn(e,[1,r,i,3]),[0,2,1,3]).toFloat())})})]}})})}function Qg(e,t){return W(function(){var n=Kg(e,t),r=Gg(rh(Br(n,[n.shape[0],t.fc1.weights.shape[0]]),t.fc1),t.prelu4_alpha),i=rh(r,t.fc2_1),a=mi(vl(i,Dr(Cu(i,1),1)),1),o=rh(r,t.fc2_2);return{scores:Kr(a,1)[1],regions:o}})}function $g(e,t,n,r,i){return Q(this,void 0,void 0,function(){var a,o,s,c,l,u,d,f,p,m,h,g,_,v;return $(this,function(y){switch(y.label){case 0:return a=Date.now(),[4,Zg(e,t,{width:24,height:24})];case 1:return o=y.sent(),i.stage2_extractImagePatches=Date.now()-a,a=Date.now(),s=o.map(function(e){var t=Qg(e,r);return e.dispose(),t}),i.stage2_rnet=Date.now()-a,c=s.length>1?nr(s.map(function(e){return e.scores})):s[0].scores,d=(u=Array).from,[4,c.data()];case 2:return l=d.apply(u,[y.sent()]),c.dispose(),f=l.map(function(e,t){return{score:e,idx:t}}).filter(function(e){return e.score>n}).map(function(e){return e.idx}),p=f.map(function(e){return t[e]}),m=f.map(function(e){return l[e]}),h=[],g=[],p.length>0&&(a=Date.now(),_=Up(p,m,.7),i.stage2_nms=Date.now()-a,v=_.map(function(e){var t=s[f[e]].regions.arraySync();return new Ug(t[0][0],t[0][1],t[0][2],t[0][3])}),g=_.map(function(e){return m[e]}),h=_.map(function(e,t){return p[e].calibrate(v[t])})),s.forEach(function(e){e.regions.dispose(),e.scores.dispose()}),[2,{boxes:h,scores:g}]}})})}function e_(e,t){return W(function(){var n=Kg(e,t);n=su(n,[2,2],[2,2],`same`),n=Hm(n,t.conv4,`valid`),n=Gg(n,t.prelu4_alpha);var r=Gg(rh(Br(n,[n.shape[0],t.fc1.weights.shape[0]]),t.fc1),t.prelu5_alpha),i=rh(r,t.fc2_1),a=mi(vl(i,Dr(Cu(i,1),1)),1),o=rh(r,t.fc2_2),s=rh(r,t.fc2_3);return{scores:Kr(a,1)[1],regions:o,points:s}})}function t_(e,t,n,r,i){return Q(this,void 0,void 0,function(){var a,o,s,c,l,u,d,f,p,m,h,g,_,v,y;return $(this,function(b){switch(b.label){case 0:return a=Date.now(),[4,Zg(e,t,{width:48,height:48})];case 1:return o=b.sent(),i.stage3_extractImagePatches=Date.now()-a,a=Date.now(),s=o.map(function(e){var t=e_(e,r);return e.dispose(),t}),i.stage3_onet=Date.now()-a,c=s.length>1?nr(s.map(function(e){return e.scores})):s[0].scores,d=(u=Array).from,[4,c.data()];case 2:return l=d.apply(u,[b.sent()]),c.dispose(),f=l.map(function(e,t){return{score:e,idx:t}}).filter(function(e){return e.score>n}).map(function(e){return e.idx}),p=f.map(function(e){var t=s[e].regions.arraySync();return new Ug(t[0][0],t[0][1],t[0][2],t[0][3])}),m=f.map(function(e,n){return t[e].calibrate(p[n])}),h=f.map(function(e){return l[e]}),g=[],_=[],v=[],m.length>0&&(a=Date.now(),y=Up(m,h,.7,!1),i.stage3_nms=Date.now()-a,g=y.map(function(e){return m[e]}),_=y.map(function(e){return h[e]}),v=y.map(function(e,t){return[,,,,,].fill(0).map(function(n,r){var i=s[e].points.arraySync();return new Ip(i[0][r]*(g[t].width+1)+g[t].left,i[0][r+5]*(g[t].height+1)+g[t].top)})})),s.forEach(function(e){e.regions.dispose(),e.scores.dispose(),e.points.dispose()}),[2,{boxes:g,scores:_,points:v}]}})})}var n_=function(e){Z(t,e);function t(){return e.call(this,`Mtcnn`)||this}return t.prototype.load=function(t){return Q(this,void 0,void 0,function(){return $(this,function(n){return console.warn(`mtcnn is deprecated and will be removed soon`),[2,e.prototype.load.call(this,t)]})})},t.prototype.loadFromDisk=function(t){return Q(this,void 0,void 0,function(){return $(this,function(n){return console.warn(`mtcnn is deprecated and will be removed soon`),[2,e.prototype.loadFromDisk.call(this,t)]})})},t.prototype.forwardInput=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S;return $(this,function(C){switch(C.label){case 0:if(n=this.params,!n)throw Error(`Mtcnn - load model before inference`);if(r=e.canvases[0],!r)throw Error(`Mtcnn - inputCanvas is not defined, note that passing tensors into Mtcnn.forwardInput is not supported yet.`);return i={},a=Date.now(),o=W(function(){return Ig(Dr(ep.fromPixels(r)).toFloat())}),s=function(e){return o.dispose(),i.total=Date.now()-a,e},c=o.shape.slice(1),l=c[0],u=c[1],d=new Jh(t),f=d.minFaceSize,p=d.scaleFactor,m=d.maxNumScales,h=d.scoreThresholds,g=d.scaleSteps,_=(g||Hg(f,p,[l,u])).filter(function(e){var t=Vg(e,[l,u]);return Math.min(t.width,t.height)>12}).slice(0,m),i.scales=_,i.pyramid=_.map(function(e){return Vg(e,[l,u])}),v=Date.now(),[4,Xg(o,_,h[0],n.pnet,i)];case 1:return y=C.sent(),i.total_stage1=Date.now()-v,y.boxes.length?(i.stage2_numInputBoxes=y.boxes.length,v=Date.now(),[4,$g(r,y.boxes,h[1],n.rnet,i)]):[2,s({results:[],stats:i})];case 2:return b=C.sent(),i.total_stage2=Date.now()-v,b.boxes.length?(i.stage3_numInputBoxes=b.boxes.length,v=Date.now(),[4,t_(r,b.boxes,h[2],n.onet,i)]):[2,s({results:[],stats:i})];case 3:return x=C.sent(),i.total_stage3=Date.now()-v,S=x.boxes.map(function(e,t){return ph(im({},new Bp(x.scores[t],new qp(e.left/u,e.top/l,e.width/u,e.height/l),{height:l,width:u})),new Qp(x.points[t].map(function(t){return t.sub(new Ip(e.left,e.top)).div(new Ip(e.width,e.height))}),{width:e.width,height:e.height}))}),[2,s({results:S,stats:i})]}})})},t.prototype.forward=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return n=this.forwardInput,[4,jm(e)];case 1:return[4,n.apply(this,[r.sent(),t])];case 2:return[2,r.sent().results]}})})},t.prototype.forwardWithStats=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return n=this.forwardInput,[4,jm(e)];case 1:return[2,n.apply(this,[r.sent(),t])]}})})},t.prototype.getDefaultModelName=function(){return`mtcnn_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Bg(e)},t.prototype.extractParams=function(e){return Rg(e)},t}(Rm),r_=.4,i_=[new Ip(1.603231,2.094468),new Ip(6.041143,7.080126),new Ip(2.882459,3.518061),new Ip(4.266906,5.178857),new Ip(9.041765,10.66308)],a_=[117.001,114.697,97.404],o_=function(e){Z(t,e);function t(){var t=this,n={withSeparableConvs:!0,iouThreshold:r_,classes:[`face`],anchors:i_,meanRgb:a_,isFirstLayerConv2d:!0,filterSizes:[3,16,32,64,128,256,512]};return t=e.call(this,n)||this,t}return Object.defineProperty(t.prototype,`anchors`,{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),t.prototype.locateFaces=function(e,t){return Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return[4,this.detect(e,t)];case 1:return n=r.sent(),[2,n.map(function(e){return new Bp(e.score,e.relativeBox,{width:e.imageWidth,height:e.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return`tiny_face_detector_model`},t.prototype.extractParamsFromWeigthMap=function(t){return e.prototype.extractParamsFromWeigthMap.call(this,t)},t}(Ag),s_={ssdMobilenetv1:new fg,tinyFaceDetector:new o_,tinyYolov2:new jg,mtcnn:new n_,faceLandmark68Net:new Oh,faceLandmark68TinyNet:new Mh,faceRecognitionNet:new Wh,faceExpressionNet:new uh,ageGenderNet:new Eh},c_=function(e){Z(t,e);function t(t,n,r){var i=e.call(this)||this;return i.parentTask=t,i.input=n,i.extractedFaces=r,i}return t}(Ng),l_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n=this;return $(this,function(r){switch(r.label){case 0:return[4,this.parentTask];case 1:return e=r.sent(),[4,Pg(e,this.input,function(e){return Q(n,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,Promise.all(e.map(function(e){return s_.faceExpressionNet.predictExpressions(e)}))];case 1:return[2,t.sent()]}})})},this.extractedFaces)];case 2:return t=r.sent(),[2,e.map(function(e,n){return dh(e,t[n])})]}})})},t.prototype.withAgeAndGender=function(){return new m_(this,this.input)},t}(c_),u_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,this.parentTask];case 1:return e=n.sent(),e?[4,Fg(e,this.input,function(e){return s_.faceExpressionNet.predictExpressions(e)},this.extractedFaces)]:[2];case 2:return t=n.sent(),[2,dh(e,t)]}})})},t.prototype.withAgeAndGender=function(){return new h_(this,this.input)},t}(c_),d_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new g_(this,this.input)},t.prototype.withFaceDescriptors=function(){return new y_(this,this.input)},t}(l_),f_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new __(this,this.input)},t.prototype.withFaceDescriptor=function(){return new b_(this,this.input)},t}(u_),p_=function(e){Z(t,e);function t(t,n,r){var i=e.call(this)||this;return i.parentTask=t,i.input=n,i.extractedFaces=r,i}return t}(Ng),m_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n=this;return $(this,function(r){switch(r.label){case 0:return[4,this.parentTask];case 1:return e=r.sent(),[4,Pg(e,this.input,function(e){return Q(n,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,Promise.all(e.map(function(e){return s_.ageGenderNet.predictAgeAndGender(e)}))];case 1:return[2,t.sent()]}})})},this.extractedFaces)];case 2:return t=r.sent(),[2,e.map(function(e,n){var r=t[n],i=r.age,a=r.gender,o=r.genderProbability;return Kh(qh(e,a,o),i)})]}})})},t.prototype.withFaceExpressions=function(){return new l_(this,this.input)},t}(p_),h_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r,i;return $(this,function(a){switch(a.label){case 0:return[4,this.parentTask];case 1:return e=a.sent(),e?[4,Fg(e,this.input,function(e){return s_.ageGenderNet.predictAgeAndGender(e)},this.extractedFaces)]:[2];case 2:return t=a.sent(),n=t.age,r=t.gender,i=t.genderProbability,[2,Kh(qh(e,r,i),n)]}})})},t.prototype.withFaceExpressions=function(){return new u_(this,this.input)},t}(p_),g_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new d_(this,this.input)},t.prototype.withFaceDescriptors=function(){return new y_(this,this.input)},t}(m_),__=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new f_(this,this.input)},t.prototype.withFaceDescriptor=function(){return new b_(this,this.input)},t}(h_),v_=function(e){Z(t,e);function t(t,n){var r=e.call(this)||this;return r.parentTask=t,r.input=n,r}return t}(Ng),y_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,this.parentTask];case 1:return e=n.sent(),[4,Pg(e,this.input,function(e){return Promise.all(e.map(function(e){return s_.faceRecognitionNet.computeFaceDescriptor(e)}))},null,function(e){return e.landmarks.align(null,{useDlibAlignment:!0})})];case 2:return t=n.sent(),[2,t.map(function(t,n){return Gh(e[n],t)})]}})})},t.prototype.withFaceExpressions=function(){return new d_(this,this.input)},t.prototype.withAgeAndGender=function(){return new g_(this,this.input)},t}(v_),b_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,this.parentTask];case 1:return e=n.sent(),e?[4,Fg(e,this.input,function(e){return s_.faceRecognitionNet.computeFaceDescriptor(e)},null,function(e){return e.landmarks.align(null,{useDlibAlignment:!0})})]:[2];case 2:return t=n.sent(),[2,Gh(e,t)]}})})},t.prototype.withFaceExpressions=function(){return new f_(this,this.input)},t.prototype.withAgeAndGender=function(){return new __(this,this.input)},t}(v_),x_=function(e){Z(t,e);function t(t,n,r){var i=e.call(this)||this;return i.parentTask=t,i.input=n,i.useTinyLandmarkNet=r,i}return Object.defineProperty(t.prototype,`landmarkNet`,{get:function(){return this.useTinyLandmarkNet?s_.faceLandmark68TinyNet:s_.faceLandmark68Net},enumerable:!0,configurable:!0}),t}(Ng),S_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r,i,a=this;return $(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return e=o.sent(),t=e.map(function(e){return e.detection}),this.input instanceof $e?[4,Nm(this.input,t)]:[3,3];case 2:return r=o.sent(),[3,5];case 3:return[4,Mm(this.input,t)];case 4:r=o.sent(),o.label=5;case 5:return n=r,[4,Promise.all(n.map(function(e){return a.landmarkNet.detectLandmarks(e)}))];case 6:return i=o.sent(),n.forEach(function(e){return e instanceof $e&&e.dispose()}),[2,e.map(function(e,t){return ph(e,i[t])})]}})})},t.prototype.withFaceExpressions=function(){return new d_(this,this.input)},t.prototype.withAgeAndGender=function(){return new g_(this,this.input)},t.prototype.withFaceDescriptors=function(){return new y_(this,this.input)},t}(x_),C_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r,i;return $(this,function(a){switch(a.label){case 0:return[4,this.parentTask];case 1:return e=a.sent(),e?(t=e.detection,this.input instanceof $e?[4,Nm(this.input,[t])]:[3,3]):[2];case 2:return r=a.sent(),[3,5];case 3:return[4,Mm(this.input,[t])];case 4:r=a.sent(),a.label=5;case 5:return n=r,[4,this.landmarkNet.detectLandmarks(n[0])];case 6:return i=a.sent(),n.forEach(function(e){return e instanceof $e&&e.dispose()}),[2,ph(e,i)]}})})},t.prototype.withFaceExpressions=function(){return new f_(this,this.input)},t.prototype.withAgeAndGender=function(){return new __(this,this.input)},t.prototype.withFaceDescriptor=function(){return new b_(this,this.input)},t}(x_),w_=function(e){Z(t,e);function t(t,n){n===void 0&&(n=new dg);var r=e.call(this)||this;return r.input=t,r.options=n,r}return t}(Ng),T_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r;return $(this,function(i){switch(i.label){case 0:return e=this,t=e.input,n=e.options,n instanceof Jh?[4,s_.mtcnn.forward(t,n)]:[3,2];case 1:return[2,i.sent().map(function(e){return e.detection})];case 2:if(r=n instanceof Mg?function(e){return s_.tinyFaceDetector.locateFaces(e,n)}:n instanceof dg?function(e){return s_.ssdMobilenetv1.locateFaces(e,n)}:n instanceof kg?function(e){return s_.tinyYolov2.locateFaces(e,n)}:null,!r)throw Error(`detectFaces - expected options to be instance of TinyFaceDetectorOptions | SsdMobilenetv1Options | MtcnnOptions | TinyYolov2Options`);return[2,r(t)]}})})},t.prototype.runAndExtendWithFaceDetections=function(){var e=this;return new Promise(function(t){return Q(e,void 0,void 0,function(){var e;return $(this,function(n){switch(n.label){case 0:return[4,this.run()];case 1:return e=n.sent(),[2,t(e.map(function(e){return im({},e)}))]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new S_(this.runAndExtendWithFaceDetections(),this.input,e)},t.prototype.withFaceExpressions=function(){return new l_(this.runAndExtendWithFaceDetections(),this.input)},t.prototype.withAgeAndGender=function(){return new m_(this.runAndExtendWithFaceDetections(),this.input)},t}(w_);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,new T_(this.input,this.options)];case 1:return e=n.sent(),t=e[0],e.forEach(function(e){e.score>t.score&&(t=e)}),[2,t]}})})},t.prototype.runAndExtendWithFaceDetection=function(){var e=this;return new Promise(function(t){return Q(e,void 0,void 0,function(){var e;return $(this,function(n){switch(n.label){case 0:return[4,this.run()];case 1:return e=n.sent(),[2,t(e?im({},e):void 0)]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new C_(this.runAndExtendWithFaceDetection(),this.input,e)},t.prototype.withFaceExpressions=function(){return new u_(this.runAndExtendWithFaceDetection(),this.input)},t.prototype.withAgeAndGender=function(){return new h_(this.runAndExtendWithFaceDetection(),this.input)},t})(w_);function E_(e,t){return t===void 0&&(t=new dg),new T_(e,t)}function D_(e,t){if(e.length!==t.length)throw Error(`euclideanDistance: arr1.length !== arr2.length`);var n=Array.from(e),r=Array.from(t);return Math.sqrt(n.map(function(e,t){return e-r[t]}).reduce(function(e,t){return e+t**2},0))}(function(){function e(e,t){t===void 0&&(t=.6),this._distanceThreshold=t;var n=Array.isArray(e)?e:[e];if(!n.length)throw Error(`FaceRecognizer.constructor - expected atleast one input`);var r=1,i=function(){return`person `+ r++};this._labeledDescriptors=n.map(function(e){if(e instanceof nm)return e;if(e instanceof Float32Array)return new nm(i(),[e]);if(e.descriptor&&e.descriptor instanceof Float32Array)return new nm(i(),[e.descriptor]);throw Error(`FaceRecognizer.constructor - expected inputs to be of type LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array | Array<LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array>`)})}return Object.defineProperty(e.prototype,`labeledDescriptors`,{get:function(){return this._labeledDescriptors},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`distanceThreshold`,{get:function(){return this._distanceThreshold},enumerable:!0,configurable:!0}),e.prototype.computeMeanDistance=function(e,t){return t.map(function(t){return D_(t,e)}).reduce(function(e,t){return e+t},0)/(t.length||1)},e.prototype.matchDescriptor=function(e){var t=this;return this.labeledDescriptors.map(function(n){var r=n.descriptors,i=n.label;return new em(i,t.computeMeanDistance(e,r))}).reduce(function(e,t){return e.distance<t.distance?e:t})},e.prototype.findBestMatch=function(e){var t=this.matchDescriptor(e);return t.distance<this.distanceThreshold?t:new em(`unknown`,t.distance)},e.prototype.toJSON=function(){return{distanceThreshold:this.distanceThreshold,labeledDescriptors:this.labeledDescriptors.map(function(e){return e.toJSON()})}},e.fromJSON=function(t){return new e(t.labeledDescriptors.map(function(e){return nm.fromJSON(e)}),t.distanceThreshold)},e})();function O_(e){return Math.max(0,Math.min(1,e))}function k_(e){let t=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],s=e[5];return(t(r,s)+t(i,o))/(2*t(n,a))}function A_(e,t,n){return!t||t<=0?e:new Promise((r,i)=>{let a=setTimeout(()=>i(n()),t);e.then(e=>{clearTimeout(a),r(e)},e=>{clearTimeout(a),i(e)})})}function j_(){let e=!1;return{load:async(t,n)=>{if(!e)try{let r=n?.timeoutMs??15e3;await A_(s_.tinyFaceDetector.loadFromUri(t),r,()=>({code:`MODEL_LOAD_TIMEOUT`,message:`Timeout ao carregar modelo TinyFaceDetector em: ${t}`})),await A_(s_.faceLandmark68TinyNet.loadFromUri(t),r,()=>({code:`MODEL_LOAD_TIMEOUT`,message:`Timeout ao carregar modelo faceLandmark68TinyNet em: ${t}`})),e=!0}catch(e){throw e?.code===`MODEL_LOAD_TIMEOUT`?e:{code:`MODEL_LOAD_FAILED`,message:`Falha ao carregar modelos face-api.js em: ${t}`,cause:e}}},detect:async(t,n)=>{if(!e)return{faces:0};let r=new Mg({inputSize:416,scoreThreshold:.45}),i=t.videoWidth||1,a=t.videoHeight||1,o=e=>{let t=e.x/i,n=e.y/a,r=e.width/i,o=e.height/a;return{faces:1,box:{x:t,y:n,width:r,height:o},centerX:O_(t+r/2),area:r*o,poseSource:`bbox`}},s=async()=>{let e=await E_(t,r);return e&&e.length>0?e:await E_(t,r)};if(n?.withLandmarks){let e=[];try{e=await E_(t,r).withFaceLandmarks(!0)}catch{e=[]}if(!e||e.length===0){let e=await s();return!e||e.length===0?{faces:0}:e.length>1?{faces:e.length}:o(e[0].box)}if(e.length>1)return{faces:e.length};let n=e[0].detection.box,c=e[0].landmarks,l=c.getLeftEye(),u=c.getRightEye(),d=c.getNose(),f=c.getJawOutline(),p=c.getMouth(),m=e=>e.map(e=>({x:O_(e.x/i),y:O_(e.y/a)})),h=e=>({x:O_(e.x/i),y:O_(e.y/a)}),g=e=>e.reduce((t,n)=>({x:t.x+n.x/e.length,y:t.y+n.y/e.length}),{x:0,y:0}),_=g(l),v=g(u),y=Math.hypot(_.x-v.x,_.y-v.y),b=g(f),x=d&&d.length>0?d[Math.floor(d.length/2)]:void 0,S=(_.x+v.x)/2,C=x?(x.x-S)/Math.max(1e-6,y):void 0,w=k_(l),T=k_(u),E=e=>O_((e-.16)/.12),D=n.x/i,O=n.y/a,k=n.width/i,A=n.height/a,j=p&&p.length>0?p.reduce((e,t)=>t.x<e.x?t:e,p[0]):void 0,M=p&&p.length>0?p.reduce((e,t)=>t.x>e.x?t:e,p[0]):void 0,N=f&&f.length>0?f[Math.max(0,Math.min(f.length-1,4))]:void 0,P=f&&f.length>0?f[Math.max(0,Math.min(f.length-1,f.length-5))]:void 0,F=p&&p.length>=9?p[2]:void 0,ee=p&&p.length>=9?p[8]:void 0,te=F?h(F):void 0,ne=ee?h(ee):void 0,re=F&&ee?Math.abs(F.y-ee.y):0,ie=y>1e-6?re/y:0,ae=(e,t)=>e&&t?Math.hypot(e.x-t.x,e.y-t.y):0,I=ae(j,N),L=ae(M,P),oe=y>1e-6?I/y:0,se=y>1e-6?L/y:0,R,z;f&&f.length>=2&&(R=f.slice(0,5).reduce((e,t)=>t.y<e.y?t:e,f[0]),z=f.slice(-5).reduce((e,t)=>t.y<e.y?t:e,f[f.length-1]));let ce=R?h(R):void 0,le=z?h(z):void 0;return{faces:1,box:{x:D,y:O,width:k,height:A},centerX:O_(D+k/2),area:k*A,leftEyeOpenProb:E(w),rightEyeOpenProb:E(T),leftEyeCenter:{x:O_(_.x/i),y:O_(_.y/a)},rightEyeCenter:{x:O_(v.x/i),y:O_(v.y/a)},eyeDist:O_(y/Math.max(i,a)),yawProxy:C,mouthLeft:j?h(j):void 0,mouthRight:M?h(M):void 0,jawLeft:N?h(N):void 0,jawRight:P?h(P):void 0,mouthUpper:te,mouthLower:ne,mouthOpenPx:re,mouthOpenNorm:ie,mouthJawLeftDist:oe,mouthJawRightDist:se,jawTopL:ce,jawTopR:le,mouthJawLeftDistPx:I,mouthJawRightDistPx:L,leftEyePoints:m(l),rightEyePoints:m(u),noseTip:x?{x:O_(x.x/i),y:O_(x.y/a)}:void 0,nosePoints:d?m(d):void 0,mouthPoints:p?m(p):void 0,jawPoints:f?m(f):void 0,jawCenter:{x:O_(b.x/i),y:O_(b.y/a)},poseSource:`landmarks`}}let c=await s();return!c||c.length===0?{faces:0}:c.length>1?{faces:c.length}:o(c[0].box)}}}function M_(e,t){return{code:e,message:t}}function N_(e){return _(e?.strictness??.5)}function P_(e){let t=N_(e),n=e?.lookForwardTolerance;return _(typeof n==`number`?n:1-t)}function F_(e,t,n){let r=!!n?.current,i=n?.current??null,a=(t?.mirrorMode??`mirrored`)===`mirrored`;if(e.faces===0)return{feedback:M_(`FACE_NOT_FOUND`,`Centralize seu rosto`),valid:!1,frameOk:!1,stepOk:!1};if(e.faces>1)return{feedback:M_(`MULTIPLE_FACES`,`Apenas 1 rosto por vez`),valid:!1,frameOk:!1,stepOk:!1};if(!e.box)return{feedback:M_(`FACE_NOT_FOUND`,`Centralize seu rosto`),valid:!1,frameOk:!1,stepOk:!1};let o=N_(t),s=P_(t),{x:c,y:l,width:u,height:d}=e.box,f=c+u/2,p=l+d/2,m=e.centerX??f,h=p,v=e.area??u*d,y=u/Math.max(1e-6,d),b=.07+o*.02,x=.22-o*.03,S=.12-o*.03+(r?.16:0),C=t?.lookSideTol??.18-o*.05,w=t?.lookUpDownTol??.12-o*.03,T=t?.zoomInMinArea??.16+o*.02,E=t?.zoomOutMaxArea??.12-o*.02;if(i===`zoomIn`){let t=v>=T,n=_((v-E)/Math.max(1e-6,T-E));return{feedback:M_(`ZOOM_IN`,t?`Mantenha...`:`Aproxime-se da câmera`),valid:t,frameOk:!0,stepOk:t,debug:{strict:o,lfTol:s,forwardTol:0,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:e.eyeDist??0,noseDx:e.noseTip?e.noseTip.x-m:null,cx:f,cy:p,centerTol:S,faceArea:v,zoomInMinArea:T,zoomOutMaxArea:E,zoomProgress:n}}}if(i===`zoomOut`){let t=v<=E,n=_((T-v)/Math.max(1e-6,T-E));return{feedback:M_(`ZOOM_OUT`,t?`Mantenha...`:`Afaste-se da câmera`),valid:t,frameOk:!0,stepOk:t,debug:{strict:o,lfTol:s,forwardTol:0,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:e.eyeDist??0,noseDx:e.noseTip?e.noseTip.x-m:null,cx:f,cy:p,centerTol:S,faceArea:v,zoomInMinArea:T,zoomOutMaxArea:E,zoomProgress:n}}}let D=t?.blinkClosedThreshold??.65;t?.cheeseThreshold;let O=t?.openMouthThreshold??.5,k=e.eyeDist??0,A=e.noseTip?e.noseTip.x-m:null,j=.1-o*.02,M=typeof t?.lookForwardCenterTol==`number`?_(t.lookForwardCenterTol):_(j+s*.08);if(v<b)return{feedback:M_(`FACE_TOO_FAR`,`Aproxime o rosto`),valid:!1,frameOk:!1,stepOk:!1,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A}};if(v>x)return{feedback:M_(`FACE_TOO_CLOSE`,`Afaste o rosto`),valid:!1,frameOk:!1,stepOk:!1,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A}};if(Math.abs(f-.5)>S||Math.abs(p-.5)>S)return{feedback:M_(`FACE_OFF_CENTER`,`Centralize seu rosto`),valid:!1,frameOk:!1,stepOk:!1,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A}};let N=e.mouthLeft,P=e.mouthRight,F=e.jawLeft,ee=e.jawRight,te=N&&P?{x:(N.x+P.x)/2,y:(N.y+P.y)/2}:null,ne=F&&ee?{x:(F.x+ee.x)/2,y:(F.y+ee.y)/2}:null,re=e.box?.height??null,ie=te&&ne&&typeof re==`number`&&re>1e-6?(ne.y-te.y)/re:null,ae=ie==null?null:g(ie,-1,1),I=typeof e.mouthJawLeftDistPx==`number`?e.mouthJawLeftDistPx:null,L=typeof e.mouthJawRightDistPx==`number`?e.mouthJawRightDistPx:null,oe=1e3,se=(I!=null&&L!=null?I>500&&I<oe&&L>500&&L<oe:!1)&&(ie==null?!1:ie>=-.5&&ie<=.5),R=typeof t?.lookForwardOkSince==`number`?t.lookForwardOkSince:null,z=se&&R!=null?Date.now()-R>=1e3:!1,ce=n?.current??null;if(!ce)return{feedback:M_(`READY`,`Pronto para capturar`),valid:!0,frameOk:!0,stepOk:!0,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A}};_(t?.poseProgressAccept??.65);let le=typeof e.mouthJawLeftDist==`number`?e.mouthJawLeftDist:null,ue=typeof e.mouthJawRightDist==`number`?e.mouthJawRightDist:null,de=typeof t?.mouthJawBaselineLeft==`number`?t.mouthJawBaselineLeft:null,fe=typeof t?.mouthJawBaselineRight==`number`?t.mouthJawBaselineRight:null,pe=le!=null&&ue!=null,me=de!=null&&fe!=null,he=pe&&me?le-de:null,ge=pe&&me?ue-fe:null,_e=t?.lookSideNearThr??.3,ve=t?.lookSideFarThr??1,ye=pe?a?ue:le:null,be=pe?a?le:ue:null,xe=ye!=null&&be!=null&&ye<_e&&be>ve,Se=ye!=null&&be!=null&&be<_e&&ye>ve,Ce=Math.max(1e-6,ve-_e),we=e=>_((ve-e)/Ce),Te=e=>_((e-_e)/Ce),Ee=ye!=null&&be!=null?Math.min(we(ye),Te(be)):0,De=ye!=null&&be!=null?Math.min(we(be),Te(ye)):0,Oe=ae??null,ke=typeof t?.lookUpDownFullScaleEps==`number`?t.lookUpDownFullScaleEps:.02,Ae=typeof t?.lookUpDownFullThr==`number`?g(t.lookUpDownFullThr,.1,1):1;if(Oe!=null&&Oe>0&&_((Oe-0)/Math.max(1e-6,Ae)),Oe!=null&&Oe<0&&_((-Oe-0)/Math.max(1e-6,Ae)),1-ke,1-ke,ce===`lookForward`){let n=e.jawTopL,r=e.jawTopR,a=e.leftEyeCenter,c=e.rightEyeCenter,l,u,d,f;n&&a&&r&&c&&(l=Math.hypot(n.x-a.x,n.y-a.y),u=Math.hypot(r.x-c.x,r.y-c.y),d=Math.abs(l-u),f=d/Math.max(l,u,1e-6));let p=ie==null?!1:ie>=-.5&&ie<=.5,m=typeof f==`number`?f<=.25:!1,h=ie==null?!1:ie>=-.6&&ie<=.6,g=typeof f==`number`?f<=.3:!1,_=p&&m,v=h&&g,b=typeof t?.lookForwardHoldMs==`number`?t.lookForwardHoldMs:1e3,x=typeof t?.lookForwardOkSince==`number`?t.lookForwardOkSince:null;v?_&&x==null&&(x=Date.now()):x=null;let S=_&&x!=null?Date.now()-x:0,T=_&&x!=null?S>=b:!1,E=``;return E=T?`Pronto para capturar`:v?`Mantenha...`:`Olhe para frente`,{feedback:M_(T?`READY`:`LOOK_FORWARD`,E),valid:T,frameOk:T,stepOk:T,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,jawTopL:n,jawTopR:r,leftEyeCenter:a,rightEyeCenter:c,jawEyeDistL:l,jawEyeDistR:u,jawEyeDistDiff:d,jawEyeDistRelDiff:f,jawEyeRelTol:.25,mouthAvg:te,jawMid:ne,faceH:re,mouthVsJawMidRaw:ie,yOk:p,distOk:m,lookForwardOkInstant:_,lookForwardHeld:T,lookForwardHoldMs:b,lookForwardHeldMs:S,lookForwardOkSince:x,currentStep:i,stepPassed:T}}}if(i===`lookUp`||i===`lookDown`){let e=ae,n=typeof t?.lookUpDownThreshold==`number`?g(Math.abs(t.lookUpDownThreshold),.02,.9):.06,r=i===`lookUp`?typeof e==`number`?e>=n:!1:typeof e==`number`?e<=-n:!1,a=typeof e==`number`?_(i===`lookUp`?(e-n)/Math.max(1e-6,.1-n):(-e-n)/Math.max(1e-6,.1-n)):0;return{feedback:r?M_(i===`lookUp`?`LOOK_UP`:`LOOK_DOWN`,`Mantenha...`):i===`lookUp`?M_(`LOOK_UP`,`Olhe para cima`):M_(`LOOK_DOWN`,`Olhe para baixo`),valid:r,frameOk:r,stepOk:r,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,cx:m,cy:h,centerTol:S,currentStep:i,stepPassed:r,mouthAvg:te,jawMid:ne,faceH:re,mouthVsJawMidRaw:ie,mouthVsJawMidClamped:ae,lookUpProgress:i===`lookUp`?a:0,lookDownProgress:i===`lookDown`?a:0,lookUpDownThreshold:n,poseProgressSource:`mouthJaw`}}}if(ce===`lookLeft`){let e=xe;return{feedback:M_(`LOOK_LEFT`,`Olhe para a esquerda`),valid:e,frameOk:!0,stepOk:e,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,cx:f,cy:p,centerTol:S,lookForwardOk:z,lookLeftProgress:Ee,lookRightProgress:De,lookLeftRule:`L<${_e.toFixed(2)} && R>${ve.toFixed(2)}`,lookRightRule:`R<${_e.toFixed(2)} && L>${ve.toFixed(2)}`,lookLeftActualTarget:`L:${(ye??0).toFixed(3)}/${_e.toFixed(2)} R:${(be??0).toFixed(3)}/${ve.toFixed(2)}`,mouthJawLeftDist:le??void 0,mouthJawRightDist:ue??void 0,mouthJawBaselineLeft:de??void 0,mouthJawBaselineRight:fe??void 0,mouthJawDeltaLeft:he??void 0,mouthJawDeltaRight:ge??void 0,mouthJawThr:void 0,mouthJawRatioNormLeft:void 0,mouthJawRatioNormRight:void 0,mouthJawRatioNowLeftOverRight:void 0,mouthJawRatioNowRightOverLeft:void 0,mouthJawRatioBaseLeftOverRight:void 0,mouthJawRatioBaseRightOverLeft:void 0}}}if(ce===`lookRight`){let e=Se;return{feedback:M_(`LOOK_RIGHT`,`Olhe para a direita`),valid:e,frameOk:!0,stepOk:e,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,cx:f,cy:p,centerTol:S,lookForwardOk:z,lookLeftProgress:Ee,lookRightProgress:De,lookLeftRule:`L<${_e.toFixed(2)} && R>${ve.toFixed(2)}`,lookRightRule:`R<${_e.toFixed(2)} && L>${ve.toFixed(2)}`,lookRightActualTarget:`R:${(be??0).toFixed(3)}/${_e.toFixed(2)} L:${(ye??0).toFixed(3)}/${ve.toFixed(2)}`,mouthJawLeftDist:le??void 0,mouthJawRightDist:ue??void 0,mouthJawBaselineLeft:de??void 0,mouthJawBaselineRight:fe??void 0,mouthJawDeltaLeft:he??void 0,mouthJawDeltaRight:ge??void 0,mouthJawThr:void 0,mouthJawRatioNormLeft:void 0,mouthJawRatioNormRight:void 0,mouthJawRatioNowLeftOverRight:void 0,mouthJawRatioNowRightOverLeft:void 0,mouthJawRatioBaseLeftOverRight:void 0,mouthJawRatioBaseRightOverLeft:void 0}}}if(ce===`blink`){let t=e.leftEyeOpenProb,n=e.rightEyeOpenProb,r=typeof t==`number`&&typeof n==`number`&&t<D&&n<D,i=!!r;return{feedback:M_(`BLINK`,`Pisque`),valid:i,frameOk:!0,stepOk:i,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,leftEyeOpenProb:typeof t==`number`?t:void 0,rightEyeOpenProb:typeof n==`number`?n:void 0,blinkClosedThreshold:D,blinkIsClosed:!!r}}}if(ce===`cheese`){let n=e.mouthPoints,r=Array.isArray(n)&&n.length>=8,i=0;if(r){let e=n.map(e=>e.x),t=n.map(e=>e.y);i=(Math.max(...e)-Math.min(...e))/Math.max(1e-6,Math.max(...t)-Math.min(...t))}let a=t?.cheeseUseBaseline!==!1,c=typeof t?.cheeseBaseline==`number`?t.cheeseBaseline:void 0,l=t?.cheeseThreshold??.05,u;u=a&&typeof c==`number`?c+l:l;let d=r&&i>=u;return{feedback:M_(`CHEESE`,`Sorria`),valid:d,frameOk:!0,stepOk:d,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,mouthSmileRatio:r?i:void 0,cheeseThreshold:l,cheeseBaseline:typeof c==`number`?c:void 0,cheeseTarget:u}}}if(ce===`openMouth`){let t=e.mouthPoints,n=Array.isArray(t)&&t.length>=8,r=0;if(n){let e=t.map(e=>e.x),n=t.map(e=>e.y),i=Math.max(...e)-Math.min(...e);r=Math.max(1e-6,Math.max(...n)-Math.min(...n))/Math.max(1e-6,i)}let i=e.mouthUpper,a=e.mouthLower,c=e.mouthOpenPx,l=e.mouthOpenNorm,u=typeof l==`number`&&i&&a?l:r,d=n&&i&&a&&u>=O;return{feedback:M_(`OPEN_MOUTH`,`Abra a boca`),valid:d,frameOk:!0,stepOk:d,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,mouthOpenRatio:n&&i&&a?u:void 0,openMouthThreshold:O,...i===void 0?{}:{mouthUpper:i},...a===void 0?{}:{mouthLower:a},...c===void 0?{}:{mouthOpenPx:c},...l===void 0?{}:{mouthOpenNorm:u}}}}if(ce===`mouthWidth`){let t=e.mouthPoints,n=Array.isArray(t)&&t.length>=8,r=0;if(n){let e=t.map(e=>e.x),n=Math.max(...e)-Math.min(...e);r=k>1e-6?n/k:0}let i=.55,a=n&&r>i;return{feedback:M_(`CHEESE`,`Sorria (abra a boca lateralmente)`),valid:a,frameOk:a,stepOk:a,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,mouthWidthRatio:n?r:void 0,smileThreshold:i}}}return{feedback:M_(`READY`,`Pronto para capturar`),valid:!0,frameOk:!0,stepOk:!0,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,cx:f,cy:p,centerTol:S,lookForwardOk:z}}}function I_(e){let t=document.createElement(`canvas`),n=t.getContext(`2d`),r=null;t.style.position=`absolute`,t.style.left=`0`,t.style.top=`0`,t.style.width=`100%`,t.style.height=`100%`,t.style.pointerEvents=`none`,getComputedStyle(e).position===`static`&&(e.style.position=`relative`),e.appendChild(t);function i(e,t,n,r){e.beginPath(),e.moveTo(t,n-r*.78),e.bezierCurveTo(t+r*1.15,n-r*.78,t+r*.65,n+r*1.1,t,n+r*1.18),e.bezierCurveTo(t-r*.65,n+r*1.1,t-r*1.15,n-r*.78,t,n-r*.78),e.closePath()}function a(e,t,n){let r=new Path2D;return r.moveTo(e,t-n*.78),r.bezierCurveTo(e+n*1.15,t-n*.78,e+n*.65,t+n*1.1,e,t+n*1.18),r.bezierCurveTo(e-n*.65,t+n*1.1,e-n*1.15,t-n*.78,e,t-n*.78),r.closePath(),r}function o(e,t,n,r=80){let i={x:e,y:t-n*.78},a={x:e,y:t+n*1.18},o={x:e+n*1.15,y:t-n*.78},s={x:e+n*.65,y:t+n*1.1},c={x:e-n*.65,y:t+n*1.1},l={x:e-n*1.15,y:t-n*.78},u=(e,t,n,r,i)=>{let a=1-i,o=i*i,s=a*a,c=s*a,l=o*i;return{x:c*e.x+3*s*i*t.x+3*a*o*n.x+l*r.x,y:c*e.y+3*s*i*t.y+3*a*o*n.y+l*r.y}},d=[],f=Math.max(2,Math.floor(r/2)),p=Math.max(2,r-f);for(let e=0;e<=f;e++){let t=e/f;d.push(u(i,o,s,a,t))}for(let e=1;e<=p;e++){let t=e/p;d.push(u(a,c,l,i,t))}return d}function s(e,t,n,r){let i=Math.max(0,Math.min(1,r));if(i<=0)return;let a=o(t/2,n*.36,Math.min(t,n)*.46*x,80),s=a.length,c=Math.max(1,Math.floor(i*(s-1)));e.save(),e.globalCompositeOperation=`source-over`,e.lineWidth=5,e.lineCap=`round`,e.lineJoin=`round`,e.strokeStyle=`#2ee59d`,e.shadowColor=`#2ee59d`,e.shadowBlur=i>=.999?14:8,e.beginPath(),e.moveTo(a[0].x,a[0].y);for(let t=1;t<=c;t++)e.lineTo(a[t].x,a[t].y);e.stroke(),e.restore()}function c(e,t){if(!n)return;k(n,e,t),n.save();let a=e/2,o=t*.36,c=Math.min(e,t)*.46*x;i(n,a,o,c),n.globalCompositeOperation=`destination-out`,n.fillStyle=`#fff`,n.fill(),n.restore(),n.save(),n.globalCompositeOperation=`source-over`,n.lineWidth=4,n.strokeStyle=A(),n.shadowColor=A(),n.shadowBlur=10,i(n,a,o,c),n.stroke(),n.restore();let l=typeof r?.debug?.challengeHoldProgress==`number`?r.debug.challengeHoldProgress:0;l>0&&s(n,e,t,l)}function l(e,t){if(!n)return;n.save();let r=e/2,a=t*.36,o=Math.min(e,t)*.46*x;n.save(),i(n,r,a,o),n.clip(),n.strokeStyle=`#fff`,n.lineWidth=2.2,n.shadowColor=`transparent`,n.shadowBlur=0;let s=u.x*o*.45,c=u.y*o*.45;n.beginPath(),n.moveTo(r,a-o*.78),n.bezierCurveTo(r+s*.5,a-o*.25+c*.2,r+s*.5,a+o*.65+c*.2,r,a+o*1.18),n.stroke(),n.beginPath(),n.moveTo(r-o*.95,a),n.bezierCurveTo(r-o*.25,a+o*.1+c,r+o*.25,a+o*.1+c,r+o*.95,a),n.stroke(),n.restore(),n.restore()}let u={x:0,y:0},d={x:0,y:0},f=0,p=`idle`,m=0,h={x:0,y:0},g=1.25;function _(e,t){let n=0,r=0,i=e.challenge?.direction;!i&&e.hint?.type===`arrow`&&(i=e.hint.direction),i===`left`?n=-1:i===`right`?n=1:i===`up`?r=-1:i===`down`&&(r=1),(n!==h.x||r!==h.y)&&(p=`hold`,m=0,h.x=n,h.y=r),n!==0||r!==0?p===`hold`?(d.x=n*g,d.y=r*g,m+=t,m>.7&&(p=`boomerang`,m=0)):p===`boomerang`?(d.x=0,d.y=0,m+=t,m>.28&&(p=`hold`,m=0)):(d.x=0,d.y=0):(d.x=0,d.y=0,p=`idle`)}function b(e){let t=8.5;u.x+=(d.x-u.x)*Math.min(1,e*t),u.y+=(d.y-u.y)*Math.min(1,e*t)}let x=1,S=1;function C(e){let t=e.debug?.feedbackCode;S=e.challenge?.direction===`zoomIn`||t===`ZOOM_IN`?1.28:e.challenge?.direction===`zoomOut`||t===`ZOOM_OUT`?.72:1}function w(e){x+=(S-x)*Math.min(1,e*3.8),Math.abs(x-S)<.001&&(x=S)}let T={IDLE:`IDLE`,CAMERA_ON:`CAMERA_ON`,FACE_DETECTED:`FACE_DETECTED`,ALIGNED:`ALIGNED`,SUCCESS:`SUCCESS`,FAIL:`FAIL`},E=T.IDLE;function D(e){if(!e.video){E=T.IDLE;return}if(!e.box){E=T.CAMERA_ON;return}if(e.box&&!e.valid){E=T.FACE_DETECTED;return}if(e.box&&e.valid){if(E=T.ALIGNED,e.debug?.stepPassed===!0){E=T.SUCCESS;return}if(e.debug?.stepPassed===!1){E=T.FAIL;return}return}E=T.IDLE}function O(e,t,r,i){let o=a(r/2,i*.36,Math.min(r,i)*.46*x);return n?.isPointInPath(o,e,t)??!1}function k(e,t,n){e.save(),e.clearRect(0,0,t,n),e.globalAlpha=.7,e.fillStyle=`#222`,e.fillRect(0,0,t,n),e.globalAlpha=1,e.restore()}function A(){switch(E){case T.FACE_DETECTED:return`#FF9800`;case T.ALIGNED:return`#FFD44D`;case T.SUCCESS:return`#2ee59d`;default:return`#FFD44D`}}function j(i){r=i,D(i);let{w:a,h:o}=v(t,e,n||void 0);if(!n)return;let s=y(a,o,i.video,i.videoObjectFit,!i.mirrored),u=performance.now(),d=f?(u-f)/1e3:.016;d>.1&&(d=.016),f=u;let p=i.landmarkDraw?.eyes!==!1,m=i.landmarkDraw?.mouth!==!1,h=i.landmarkDraw?.nose!==!1,g=i.landmarkDraw?.jaw!==!1,T=i.landmarkDraw?.mouthJaw!==!1,k=i.landmarkDraw||{};_(i,d),b(d),C(i),w(d),(i.challenge?.direction===`zoomIn`||i.challenge?.direction===`zoomOut`)&&console.log(`challenge.direction:`,i.challenge.direction,`guideScale:`,x,`targetScale:`,S),c(a,o),l(a,o),i.message&&(n.save(),n.font=`600 1.1rem system-ui, sans-serif`,n.textAlign=`center`,n.fillStyle=`#fff`,n.shadowColor=`#222`,n.shadowBlur=8,n.fillText(i.message,a/2,o*.76),n.restore());let A=p||m||h||g||T,j=i.debug?.extra?.showCoxinhaCenterDot===!0;if(i.box&&A&&j){let e=i.box.x+i.box.width/2,t=i.box.y+i.box.height/2,r=s.mapPt({x:e,y:t});n.save(),n.beginPath(),n.arc(r.x,r.y,7,0,Math.PI*2),n.fillStyle=O(r.x,r.y,a,o)?`#4caf50`:`#ff5252`,n.globalAlpha=.7,n.fill(),n.restore()}let M=i.landmarks;if(M){if(p&&(M.leftEye||M.rightEye)&&(n.save(),n.strokeStyle=`#4fc3f7`,n.lineWidth=2,M.leftEye&&(n.beginPath(),M.leftEye.forEach((e,t)=>{let r=s.mapPt(e);t===0?n.moveTo(r.x,r.y):n.lineTo(r.x,r.y)}),n.closePath(),n.stroke()),M.rightEye&&(n.beginPath(),M.rightEye.forEach((e,t)=>{let r=s.mapPt(e);t===0?n.moveTo(r.x,r.y):n.lineTo(r.x,r.y)}),n.closePath(),n.stroke()),n.restore()),m&&M.mouthPoints&&(n.save(),n.strokeStyle=`#ffb300`,n.lineWidth=2,n.beginPath(),M.mouthPoints.forEach((e,t)=>{let r=s.mapPt(e);t===0?n.moveTo(r.x,r.y):n.lineTo(r.x,r.y)}),n.closePath(),n.stroke(),n.restore()),g&&M.jawPoints&&(n.save(),n.strokeStyle=`#81c784`,n.lineWidth=2,n.beginPath(),M.jawPoints.forEach((e,t)=>{let r=s.mapPt(e);t===0?n.moveTo(r.x,r.y):n.lineTo(r.x,r.y)}),n.stroke(),n.restore()),h&&M.nosePoints&&(n.save(),n.strokeStyle=`#ba68c8`,n.lineWidth=2,n.beginPath(),M.nosePoints.forEach((e,t)=>{let r=s.mapPt(e);t===0?n.moveTo(r.x,r.y):n.lineTo(r.x,r.y)}),n.stroke(),n.restore()),T&&M.mouthLeft&&M.jawLeft){n.save(),n.strokeStyle=`#e57373`,n.lineWidth=2,n.beginPath();let e=s.mapPt(M.mouthLeft),t=s.mapPt(M.jawLeft);n.moveTo(e.x,e.y),n.lineTo(t.x,t.y),n.stroke(),n.restore()}if(T&&M.mouthRight&&M.jawRight){n.save(),n.strokeStyle=`#e57373`,n.lineWidth=2,n.beginPath();let e=s.mapPt(M.mouthRight),t=s.mapPt(M.jawRight);n.moveTo(e.x,e.y),n.lineTo(t.x,t.y),n.stroke(),n.restore()}}if(k.cheese&&i.debug?.cheeseBaseline!=null&&(n.save(),n.font=`bold 1rem system-ui, sans-serif`,n.fillStyle=`#FFD44D`,n.shadowColor=`#222`,n.shadowBlur=6,n.fillText(`cheese baseline: ${i.debug.cheeseBaseline.toFixed(3)}`,a/2,o*.08),i.debug.cheeseTarget!=null&&n.fillText(`cheese target: ${i.debug.cheeseTarget.toFixed(3)}`,a/2,o*.13),n.restore()),i.debug&&i.debug.extra?.showOverlayTableCanvas){let e=Math.min(520,Math.round(a*.62)),t=[];t.push(`drawLandmarks: ${i.debug.drawLandmarks===!1?`OFF`:`ON`}`),t.push(`draw: eyes=${p?`ON`:`OFF`} | mouth=${m?`ON`:`OFF`} | jaw=${g?`ON`:`OFF`} | nose=${h?`ON`:`OFF`} | mouth↔jaw=${T?`ON`:`OFF`}`),t.push(`cheese panel: ${k.cheese?`ON`:`OFF`}`),t.push(``),t.push(`Overlay State: ${E}`),typeof i.debug.status==`string`&&t.push(`Status: ${i.debug.status}`),typeof i.debug.ready==`boolean`&&t.push(`Ready: ${i.debug.ready}`),typeof i.debug.feedbackCode==`string`&&t.push(`Feedback: ${i.debug.feedbackCode}`),typeof i.debug.challenge==`string`&&t.push(`Challenge: ${i.debug.challenge}`);let r=typeof i.debug.faces==`number`?i.debug.faces:void 0,s=typeof i.debug.eyeL==`number`?i.debug.eyeL:void 0,c=typeof i.debug.eyeR==`number`?i.debug.eyeR:void 0;(r!=null||s!=null||c!=null)&&t.push(`Debug: faces=${r??`-`} | eyeL=${s==null?`-`:s.toFixed(2)} | eyeR=${c==null?`-`:c.toFixed(2)}`);let l=typeof i.debug.blinkCount==`number`?i.debug.blinkCount:void 0,u=typeof i.debug.blinkClosedNow==`boolean`?i.debug.blinkClosedNow:void 0,d=typeof i.debug.blinkClosedThreshold==`number`?i.debug.blinkClosedThreshold:void 0;(l!=null||u!=null||d!=null)&&t.push(`Blink: count=${l??`-`} | closedNow=${u??`-`} | thr=${d==null?`-`:d.toFixed(2)}`);let f=i.debug.mouthVsJawMidRaw,_=i.debug.mouthVsJawMidClamped;(typeof _==`number`||typeof f==`number`)&&t.push(`mouthAvg vs jawMid: ${typeof _==`number`?_.toFixed(2):`-`} (raw ${typeof f==`number`?f.toFixed(3):`-`})`);let v=i.debug.faceH;if(typeof v==`number`&&t.push(`faceH: ${v.toFixed(3)}`),typeof i.debug.stepPassed==`boolean`&&t.push(`stepPassed(${i.debug.currentStep??`-`}) = ${i.debug.stepPassed}`),i.debug.debugDraw?.cheese!==!1){let e=i.debug.mouthSmileRatio,n=i.debug.cheeseBaseline,r=i.debug.cheeseTarget;(typeof e==`number`||typeof n==`number`||typeof r==`number`)&&t.push(`Cheese: ratio=${typeof e==`number`?e.toFixed(3):`-`} | base=${typeof n==`number`?n.toFixed(3):`-`} | target=${typeof r==`number`?r.toFixed(3):`-`}`)}t.length===0&&t.push(`Debug ativo (nenhum dado)`);let y=24+t.length*16,b=Math.max(8,o-y-88);n.save(),n.fillStyle=`rgba(0,0,0,0.72)`,n.strokeStyle=`#FFD44D`,n.lineWidth=2,n.beginPath(),typeof n.roundRect==`function`?n.roundRect(12,b,e,y,10):n.rect(12,b,e,y),n.fill(),n.stroke(),n.fillStyle=`rgba(255,255,255,0.92)`,n.font=`12px ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace`,n.textAlign=`left`,n.textBaseline=`top`;for(let e=0;e<t.length;e++)n.fillText(t[e],24,b+12+e*16);n.restore()}}function M(){t.remove()}return{canvas:t,dispose:M,render:j}}function L_(e){getComputedStyle(e).position===`static`&&(e.style.position=`relative`)}function R_(e){let{container:t,labels:n,onOk:r,onRetake:i}=e;L_(t);let a=document.createElement(`div`);a.className=`alphavalid-userPreview`,a.style.position=`absolute`,a.style.inset=`0`,a.style.display=`none`,a.style.alignItems=`center`,a.style.justifyContent=`center`,a.style.flexDirection=`column`,a.style.gap=`10px`,a.style.background=`rgba(0,0,0,0.45)`,a.style.backdropFilter=`blur(2px)`,a.style.zIndex=`999999`,a.style.pointerEvents=`auto`,a.style.touchAction=`manipulation`;let o=document.createElement(`img`);o.className=`alphavalid-userPreview-img`,o.alt=`preview`,o.style.width=`88%`,o.style.maxWidth=`360px`,o.style.maxHeight=`70%`,o.style.objectFit=`contain`,o.style.borderRadius=`16px`,o.style.boxShadow=`0 10px 28px rgba(0,0,0,0.35)`;let s=document.createElement(`div`);s.className=`alphavalid-userPreview-meta`,s.style.color=`#fff`,s.style.fontWeight=`600`,s.style.textAlign=`center`,s.style.fontSize=`0.95rem`,s.style.padding=`0 16px`;let c=document.createElement(`div`);c.className=`alphavalid-userPreview-actions`,c.style.display=`flex`,c.style.gap=`10px`,c.style.marginTop=`6px`,c.style.pointerEvents=`auto`,c.style.zIndex=`1000000`;let l=document.createElement(`button`);l.type=`button`,l.className=`alphavalid-userPreview-retake`,l.textContent=n?.retake??`Tirar outra`,l.style.padding=`10px 14px`,l.style.borderRadius=`12px`,l.style.border=`1px solid rgba(255,255,255,0.35)`,l.style.background=`rgba(0,0,0,0.35)`,l.style.color=`#fff`,l.style.fontWeight=`700`,l.style.cursor=`pointer`,l.style.pointerEvents=`auto`,l.style.touchAction=`manipulation`;let u=document.createElement(`button`);return u.type=`button`,u.className=`alphavalid-userPreview-ok`,u.textContent=n?.ok??`OK`,u.style.padding=`10px 16px`,u.style.borderRadius=`12px`,u.style.border=`1px solid rgba(255,255,255,0.35)`,u.style.background=`#ffffff`,u.style.color=`#111`,u.style.fontWeight=`800`,u.style.cursor=`pointer`,u.style.pointerEvents=`auto`,u.style.touchAction=`manipulation`,l.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),i()}),u.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),r()}),c.appendChild(l),c.appendChild(u),a.appendChild(o),a.appendChild(s),a.appendChild(c),t.appendChild(a),{show:(e,t)=>{o.src=e,s.textContent=t??``,a.style.display=`flex`},hide:()=>{a.style.display=`none`,o.removeAttribute(`src`),s.textContent=``},dispose:()=>{a.remove()}}}function z_(e){return{ok:e.previewOkText,retake:e.previewRetakeText}}var B_=`/images/alphaloader.gif`;function V_(e,t={}){let n=t.src??B_,r=t.sizePx??120,i=t.minVisibleMs??900,a=null,o=0,s=null,c=()=>{getComputedStyle(e).position===`static`&&(e.style.position=`relative`)},l=()=>{if(a)return a;c(),a=document.createElement(`div`),a.className=`alphavalid-camera-loader`,a.style.position=`absolute`,a.style.inset=`0`,a.style.display=`flex`,a.style.alignItems=`center`,a.style.justifyContent=`center`,a.style.background=`transparent`,a.style.zIndex=`999`;let t=document.createElement(`img`);return t.alt=`Carregando...`,t.src=n,t.style.width=`${r}px`,t.style.height=`${r}px`,a.appendChild(t),e.appendChild(a),a};return{show:()=>{s!=null&&(window.clearTimeout(s),s=null),l(),o=Date.now(),a&&(a.style.display=`flex`)},hide:()=>{if(!a)return;let e=Date.now()-o,t=Math.max(0,i-e);if(t>0){s!=null&&window.clearTimeout(s),s=window.setTimeout(()=>{s=null,a&&(a.style.display=`none`)},t);return}a.style.display=`none`},dispose:()=>{s!=null&&(window.clearTimeout(s),s=null),a?.remove(),a=null}}}function H_(e){getComputedStyle(e).position===`static`&&(e.style.position=`relative`)}function U_(e){let{container:t,text:n,color:r,onClick:i}=e;H_(t);let a=document.createElement(`button`);return a.type=`button`,a.className=`alphavalid-captureBtn`,a.textContent=n??`Capturar imagem`,a.style.position=`absolute`,a.style.left=`50%`,a.style.bottom=`calc(env(safe-area-inset-bottom, 0px) + 24px)`,a.style.transform=`translateX(-50%)`,a.style.width=`88%`,a.style.maxWidth=`340px`,a.style.height=`56px`,a.style.borderRadius=`18px`,a.style.border=`none`,a.style.background=r??`#00bcd4`,a.style.color=`#fff`,a.style.fontWeight=`800`,a.style.fontSize=`1.05rem`,a.style.cursor=`pointer`,a.style.zIndex=`999998`,a.style.boxShadow=`0 10px 22px rgba(0,0,0,0.28)`,a.style.touchAction=`manipulation`,a.style[`-webkit-tap-highlight-color`]=`transparent`,a.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),!a.disabled&&i()}),t.appendChild(a),{show:()=>{a.style.display=`block`},hide:()=>{a.style.display=`none`},dispose:()=>{a.remove()},setEnabled:e=>{a.disabled=!e,a.style.opacity=e?`1`:`0.55`}}}function W_(e){if(!(typeof document>`u`)){if(!document.getElementById(`alphavalid-base-styles`)){let e=document.createElement(`style`);e.id=`alphavalid-base-styles`,e.textContent=`
3804
+ Expected: `+l+`.`)}}function cp(e,t,n){return!isFinite(e)&&!isFinite(t)||!(isNaN(e)||isNaN(t)||Math.abs(e-t)>n)}Object.freeze({TEST_EPSILON_FLOAT16:ap,expectArraysClose:function(e,t,n){return n??=op(),sp(e,t,(function(e,t){return cp(e,t,n)}))},testEpsilon:op,expectPromiseToFail:function(e,t){e().then((function(){return t.fail()}),(function(){return t()}))},expectArraysEqual:function(e,t){var n=typeof t==`string`||typeof t==`number`||typeof t==`boolean`?[t]:t;return we(e)||we(e[0])||we(t)||we(t[0])?sp(e,n,(function(e,t){return e==t})):sp(e,t,(function(e,t){return cp(e,t,0)}))},expectNumbersClose:function(e,t,n){if(n??=op(),!cp(e,t,n))throw Error(`Numbers differ: actual === `+e+`, expected === `+t)},expectValuesInRange:function(e,t,n){for(var r=0;r<e.length;r++)if(e[r]<t||e[r]>n)throw Error(`Value out of range:`+e[r]+` low: `+t+`, high: `+n)},expectArrayBuffersEqual:function(e,t){expect(new Float32Array(e)).toEqual(new Float32Array(t))}}),Object.freeze({gpgpu_util:jo,webgl_util:yn,forceHalfFloat:function(){O().set(`WEBGL_FORCE_F16_TEXTURES`,!0)},MathBackendWebGL:Ys,setWebGLContext:St,GPGPUContext:Mo});var lp=function(e){function t(){return e!==null&&e.apply(this,arguments)||this}return C(t,e),t.prototype.minimize=function(e,t,n){t===void 0&&(t=!1);var r=this.computeGradients(e,n),i=r.value,a=r.grads;if(n!=null){var o=n.map((function(e){return{name:e.name,tensor:a[e.name]}}));this.applyGradients(o)}else this.applyGradients(a);return xn(a),t?i:(i.dispose(),null)},Object.defineProperty(t.prototype,`iterations`,{get:function(){return this.iterations_??=0,this.iterations_},enumerable:!0,configurable:!0}),t.prototype.incrementIterations=function(){this.iterations_=this.iterations+1},t.prototype.computeGradients=function(e,t){return fi(e,t)},t.prototype.dispose=function(){this.iterations_!=null&&xn(this.iterations_)},t.prototype.saveIterations=function(){return w(this,void 0,void 0,(function(){return T(this,(function(e){return this.iterations_??=0,[2,{name:`iter`,tensor:q(this.iterations_,`int32`)}]}))}))},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){return T(this,(function(e){throw Error(`getWeights() is not implemented for this optimizer yet.`)}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){return T(this,(function(e){throw Error(`setWeights() is not implemented for this optimizer class `+this.getClassName())}))}))},t.prototype.extractIterations=function(e){return w(this,void 0,void 0,(function(){var t;return T(this,(function(n){switch(n.label){case 0:return t=this,[4,e[0].tensor.data()];case 1:return t.iterations_=n.sent()[0],[2,e.slice(1)]}}))}))},t}(tp);Object.defineProperty(lp,Symbol.hasInstance,{value:function(e){return e.minimize!=null&&e.computeGradients!=null&&e.applyGradients!=null}});var up=function(e){function t(t,n,r){r===void 0&&(r=null);var i=e.call(this)||this;return i.learningRate=t,i.rho=n,i.epsilon=r,i.accumulatedGrads=[],i.accumulatedUpdates=[],r??(i.epsilon=V.backend.epsilon()),i}return C(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=V.registeredVariables[n];t.accumulatedGrads[r]??(t.accumulatedGrads[r]={originalName:n+`/accum_grad`,variable:W((function(){return tr(i).variable(!1)}))}),t.accumulatedUpdates[r]??(t.accumulatedUpdates[r]={originalName:n+`/accum_var`,variable:W((function(){return tr(i).variable(!1)}))});var a=Array.isArray(e)?e[r].tensor:e[n];if(a!=null){var o=t.accumulatedGrads[r].variable,s=t.accumulatedUpdates[r].variable;W((function(){var e=o.mul(t.rho).add(a.square().mul(1-t.rho)),n=s.add(t.epsilon).sqrt().div(o.add(t.epsilon).sqrt()).mul(a),r=s.mul(t.rho).add(n.square().mul(1-t.rho));o.assign(e),s.assign(r);var c=n.mul(-t.learningRate).add(i);i.assign(c)}))}})),this.incrementIterations()},t.prototype.dispose=function(){this.accumulatedUpdates!=null&&(xn(this.accumulatedGrads.map((function(e){return e.variable}))),xn(this.accumulatedUpdates.map((function(e){return e.variable}))))},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){var e;return T(this,(function(t){switch(t.label){case 0:return e=this.accumulatedGrads.concat(this.accumulatedUpdates),[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(e.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){var t;return T(this,(function(n){switch(n.label){case 0:return[4,this.extractIterations(e)];case 1:return e=n.sent(),t=e.length/2,this.accumulatedGrads=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.accumulatedUpdates=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,rho:this.rho,epsilon:this.epsilon}},t.fromConfig=function(e,t){return new e(t.learningRate,t.rho,t.epsilon)},t.className=`Adadelta`,t}(lp);rp(up);var dp=function(e){function t(t,n){n===void 0&&(n=.1);var r=e.call(this)||this;return r.learningRate=t,r.initialAccumulatorValue=n,r.accumulatedGrads=[],r}return C(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=V.registeredVariables[n];t.accumulatedGrads[r]??(t.accumulatedGrads[r]={originalName:n+`/accumulator`,variable:W((function(){return Zn(i.shape,t.initialAccumulatorValue).variable(!1)}))});var a=Array.isArray(e)?e[r].tensor:e[n];if(a!=null){var o=t.accumulatedGrads[r].variable;W((function(){var e=o.add(a.square());o.assign(e);var n=a.div(e.add(V.backend.epsilon()).sqrt()).mul(-t.learningRate).add(i);i.assign(n)}))}})),this.incrementIterations()},t.prototype.dispose=function(){this.accumulatedGrads!=null&&xn(this.accumulatedGrads.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){return T(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(this.accumulatedGrads.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){return T(this,(function(t){switch(t.label){case 0:return[4,this.extractIterations(e)];case 1:return e=t.sent(),this.accumulatedGrads=e.map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,initialAccumulatorValue:this.initialAccumulatorValue}},t.fromConfig=function(e,t){return new e(t.learningRate,t.initialAccumulatorValue)},t.className=`Adagrad`,t}(lp);rp(dp);var fp=function(e){function t(t,n,r,i){i===void 0&&(i=null);var a=e.call(this)||this;return a.learningRate=t,a.beta1=n,a.beta2=r,a.epsilon=i,a.accumulatedFirstMoment=[],a.accumulatedSecondMoment=[],W((function(){a.accBeta1=q(n).variable(),a.accBeta2=q(r).variable()})),i??(a.epsilon=V.backend.epsilon()),a}return C(t,e),t.prototype.applyGradients=function(e){var t=this,n=Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e);W((function(){var r=vl(1,t.accBeta1),i=vl(1,t.accBeta2);n.forEach((function(n,a){var o=V.registeredVariables[n];t.accumulatedFirstMoment[a]??(t.accumulatedFirstMoment[a]={originalName:n+`/m`,variable:W((function(){return tr(o).variable(!1)}))}),t.accumulatedSecondMoment[a]??(t.accumulatedSecondMoment[a]={originalName:n+`/v`,variable:W((function(){return tr(o).variable(!1)}))});var s=Array.isArray(e)?e[a].tensor:e[n];if(s!=null){var c=t.accumulatedFirstMoment[a].variable,l=t.accumulatedSecondMoment[a].variable,u=c.mul(t.beta1).add(s.mul(1-t.beta1)),d=l.mul(t.beta2).add(s.square().mul(1-t.beta2)),f=u.div(r),p=d.div(i);c.assign(u),l.assign(d);var m=f.div(p.sqrt().add(t.epsilon)).mul(-t.learningRate).add(o);o.assign(m)}})),t.accBeta1.assign(t.accBeta1.mul(t.beta1)),t.accBeta2.assign(t.accBeta2.mul(t.beta2))})),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.accBeta2.dispose(),this.accumulatedFirstMoment!=null&&xn(this.accumulatedFirstMoment.map((function(e){return e.variable}))),this.accumulatedSecondMoment!=null&&xn(this.accumulatedSecondMoment.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){var e;return T(this,(function(t){switch(t.label){case 0:return e=this.accumulatedFirstMoment.concat(this.accumulatedSecondMoment),[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(e.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){var t,n=this;return T(this,(function(r){switch(r.label){case 0:return[4,this.extractIterations(e)];case 1:return e=r.sent(),W((function(){n.accBeta1.assign(hl(n.beta1,n.iterations_+1)),n.accBeta2.assign(hl(n.beta2,n.iterations_+1))})),t=e.length/2,this.accumulatedFirstMoment=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.accumulatedSecondMoment=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon}},t.fromConfig=function(e,t){return new e(t.learningRate,t.beta1,t.beta2,t.epsilon)},t.className=`Adam`,t}(lp);rp(fp);var pp=function(e){function t(t,n,r,i,a){i===void 0&&(i=null),a===void 0&&(a=0);var o=e.call(this)||this;return o.learningRate=t,o.beta1=n,o.beta2=r,o.epsilon=i,o.decay=a,o.accumulatedFirstMoment=[],o.accumulatedWeightedInfNorm=[],W((function(){o.iteration=q(0).variable(),o.accBeta1=q(n).variable()})),i??(o.epsilon=V.backend.epsilon()),o}return C(t,e),t.prototype.applyGradients=function(e){var t=this,n=Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e);W((function(){var r=vl(1,t.accBeta1),i=rl(-t.learningRate,t.iteration.mul(t.decay).add(1));n.forEach((function(n,a){var o=V.registeredVariables[n];t.accumulatedFirstMoment[a]??(t.accumulatedFirstMoment[a]={originalName:n+`/m`,variable:tr(o).variable(!1)}),t.accumulatedWeightedInfNorm[a]??(t.accumulatedWeightedInfNorm[a]={originalName:n+`/v`,variable:tr(o).variable(!1)});var s=Array.isArray(e)?e[a].tensor:e[n];if(s!=null){var c=t.accumulatedFirstMoment[a].variable,l=t.accumulatedWeightedInfNorm[a].variable,u=c.mul(t.beta1).add(s.mul(1-t.beta1)),d=l.mul(t.beta2),f=s.abs(),p=d.maximum(f);c.assign(u),l.assign(p);var m=i.div(r).mul(u.div(p.add(t.epsilon))).add(o);o.assign(m)}})),t.iteration.assign(t.iteration.add(1)),t.accBeta1.assign(t.accBeta1.mul(t.beta1))})),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.iteration.dispose(),this.accumulatedFirstMoment!=null&&xn(this.accumulatedFirstMoment.map((function(e){return e.variable}))),this.accumulatedWeightedInfNorm!=null&&xn(this.accumulatedWeightedInfNorm.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){return T(this,(function(e){throw Error(`getWeights() is not implemented for Adamax yet.`)}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){return T(this,(function(e){throw Error(`setWeights() is not implemented for Adamax yet.`)}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon,decay:this.decay}},t.fromConfig=function(e,t){return new e(t.learningRate,t.beta1,t.beta2,t.epsilon,t.decay)},t.className=`Adamax`,t}(lp);rp(pp);var mp=function(e){function t(t){var n=e.call(this)||this;return n.learningRate=t,n.setLearningRate(t),n}return C(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=Array.isArray(e)?e[r].tensor:e[n];if(i!=null){var a=V.registeredVariables[n];W((function(){var e=t.c.mul(i).add(a);a.assign(e)}))}})),this.incrementIterations()},t.prototype.setLearningRate=function(e){this.learningRate=e,this.c!=null&&this.c.dispose(),this.c=Sn(q(-e))},t.prototype.dispose=function(){this.c.dispose()},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){return T(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()]]}}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){return T(this,(function(t){switch(t.label){case 0:return[4,this.extractIterations(e)];case 1:if((e=t.sent()).length!==0)throw Error(`SGD optimizer does not have settable weights.`);return[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate}},t.fromConfig=function(e,t){return new e(t.learningRate)},t.className=`SGD`,t}(lp);rp(mp);var hp=function(e){function t(t,n,r){r===void 0&&(r=!1);var i=e.call(this,t)||this;return i.learningRate=t,i.momentum=n,i.useNesterov=r,i.accumulations=[],i.m=q(i.momentum),i}return C(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=V.registeredVariables[n];t.accumulations[r]??(t.accumulations[r]={originalName:n+`/momentum`,variable:W((function(){return tr(i).variable(!1)}))});var a=t.accumulations[r].variable,o=Array.isArray(e)?e[r].tensor:e[n];o!=null&&W((function(){var e,n=t.m.mul(a).add(o);e=t.useNesterov?t.c.mul(o.add(n.mul(t.m))).add(i):t.c.mul(n).add(i),a.assign(n),i.assign(e)}))})),this.incrementIterations()},t.prototype.dispose=function(){this.m.dispose(),this.accumulations!=null&&xn(this.accumulations.map((function(e){return e.variable})))},t.prototype.setMomentum=function(e){this.momentum=e},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){return T(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(this.accumulations.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){return T(this,(function(t){switch(t.label){case 0:return[4,this.extractIterations(e)];case 1:return e=t.sent(),this.accumulations=e.map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,momentum:this.momentum,useNesterov:this.useNesterov}},t.fromConfig=function(e,t){return new e(t.learningRate,t.momentum,t.useNesterov)},t.className=`Momentum`,t}(mp);rp(hp);var gp=function(e){function t(t,n,r,i,a){n===void 0&&(n=.9),r===void 0&&(r=0),i===void 0&&(i=null),a===void 0&&(a=!1);var o=e.call(this)||this;if(o.learningRate=t,o.decay=n,o.momentum=r,o.epsilon=i,o.accumulatedMeanSquares=[],o.accumulatedMoments=[],o.accumulatedMeanGrads=[],o.centered=a,i??(o.epsilon=V.backend.epsilon()),t==null)throw Error(`learningRate for RMSPropOptimizer must be defined.`);return o}return C(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=V.registeredVariables[n];t.accumulatedMeanSquares[r]??(t.accumulatedMeanSquares[r]={originalName:n+`/rms`,variable:W((function(){return tr(i).variable(!1)}))}),t.accumulatedMoments[r]??(t.accumulatedMoments[r]={originalName:n+`/momentum`,variable:W((function(){return tr(i).variable(!1)}))}),t.accumulatedMeanGrads[r]==null&&t.centered&&(t.accumulatedMeanGrads[r]={originalName:n+`/mg`,variable:W((function(){return tr(i).variable(!1)}))});var a=Array.isArray(e)?e[r].tensor:e[n];if(a!=null){var o=t.accumulatedMeanSquares[r].variable,s=t.accumulatedMoments[r].variable;W((function(){var e=o.mul(t.decay).add(a.square().mul(1-t.decay));if(t.centered){var n=t.accumulatedMeanGrads[r].variable,c=n.mul(t.decay).add(a.mul(1-t.decay)),l=s.mul(t.momentum).add(a.mul(t.learningRate).div(e.sub(c.square().add(t.epsilon)).sqrt()));o.assign(e),n.assign(c),s.assign(l);var u=i.sub(l);i.assign(u)}else{var d=o.mul(t.decay).add(a.square().mul(1-t.decay));l=s.mul(t.momentum).add(a.mul(t.learningRate).div(d.add(t.epsilon).sqrt())),o.assign(d),s.assign(l),u=i.sub(l),i.assign(u)}}))}})),this.incrementIterations()},t.prototype.dispose=function(){this.accumulatedMeanSquares!=null&&xn(this.accumulatedMeanSquares.map((function(e){return e.variable}))),this.accumulatedMeanGrads!=null&&this.centered&&xn(this.accumulatedMeanGrads.map((function(e){return e.variable}))),this.accumulatedMoments!=null&&xn(this.accumulatedMoments.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return w(this,void 0,void 0,(function(){var e;return T(this,(function(t){switch(t.label){case 0:return e=this.accumulatedMeanSquares.concat(this.accumulatedMoments),this.centered&&e.push.apply(e,this.accumulatedMeanGrads),[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(e.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return w(this,void 0,void 0,(function(){var t;return T(this,(function(n){switch(n.label){case 0:return[4,this.extractIterations(e)];case 1:return e=n.sent(),t=this.centered?e.length/3:e.length/2,this.accumulatedMeanSquares=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.accumulatedMoments=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.centered&&(this.accumulatedMeanGrads=e.slice(2*t,3*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}}))),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,decay:this.decay,momentum:this.momentum,epsilon:this.epsilon,centered:this.centered}},t.fromConfig=function(e,t){return new e(t.learningRate,t.decay,t.momentum,t.epsilon,t.centered)},t.className=`RMSProp`,t}(lp);rp(gp);var _p=function(){function e(){}return e.sgd=function(e){return new mp(e)},e.momentum=function(e,t,n){return n===void 0&&(n=!1),new hp(e,t,n)},e.rmsprop=function(e,t,n,r,i){return t===void 0&&(t=.9),n===void 0&&(n=0),r===void 0&&(r=null),i===void 0&&(i=!1),new gp(e,t,n,r,i)},e.adam=function(e,t,n,r){return e===void 0&&(e=.001),t===void 0&&(t=.9),n===void 0&&(n=.999),r===void 0&&(r=null),new fp(e,t,n,r)},e.adadelta=function(e,t,n){return e===void 0&&(e=.001),t===void 0&&(t=.95),n===void 0&&(n=null),new up(e,t,n)},e.adamax=function(e,t,n,r,i){return e===void 0&&(e=.002),t===void 0&&(t=.9),n===void 0&&(n=.999),r===void 0&&(r=null),i===void 0&&(i=0),new pp(e,t,n,r,i)},e.adagrad=function(e,t){return t===void 0&&(t=.1),new dp(e,t)},e}();_p.sgd,_p.momentum,_p.adadelta,_p.adagrad,_p.rmsprop,_p.adamax,_p.adam,$e.prototype.squaredDifference=function(e){return Qs(this,e)},B=zd;function vp(e,t,n){if(n===void 0&&(n=!1),e.beginPath(),t.slice(1).forEach(function(n,r){var i=n.x,a=n.y,o=t[r];e.moveTo(o.x,o.y),e.lineTo(i,a)}),n){var r=t[t.length-1],i=t[0];if(!r||!i)return;e.moveTo(r.x,r.y),e.lineTo(i.x,i.y)}e.stroke()}var yp=function(e,t){return yp=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])},yp(e,t)};function Z(e,t){yp(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}var bp=function(){return bp=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},bp.apply(this,arguments)};function Q(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})}function $(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(o){if(r)throw TypeError(`Generator is already executing.`);for(;n;)try{if(r=1,i&&(a=o[0]&2?i.return:o[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,o[1])).done)return a;switch(i=0,a&&(o=[o[0]&2,a.value]),o[0]){case 0:case 1:a=o;break;case 4:return n.label++,{value:o[1],done:!1};case 5:n.label++,i=o[1],o=[0];continue;case 7:o=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(o[0]===6||o[0]===2)){n=0;continue}if(o[0]===3&&(!a||o[1]>a[0]&&o[1]<a[3])){n.label=o[1];break}if(o[0]===6&&n.label<a[1]){n.label=a[1],a=o;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(o);break}a[2]&&n.ops.pop(),n.trys.pop();continue}o=t.call(e,n)}catch(e){o=[6,e],i=0}finally{r=a=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}}function xp(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var r=Array(e),i=0,t=0;t<n;t++)for(var a=arguments[t],o=0,s=a.length;o<s;o++,i++)r[i]=a[o];return r}var Sp=function(){function e(e,t){if(!Pp(e)||!Pp(t))throw Error(`Dimensions.constructor - expected width and height to be valid numbers, instead have `+JSON.stringify({width:e,height:t}));this._width=e,this._height=t}return Object.defineProperty(e.prototype,`width`,{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`height`,{get:function(){return this._height},enumerable:!0,configurable:!0}),e.prototype.reverse=function(){return new e(1/this.width,1/this.height)},e}();function Cp(e,t){return e instanceof $e&&e.shape.length===t}function wp(e){return Cp(e,2)}function Tp(e){return Cp(e,3)}function Ep(e){return Cp(e,4)}function Dp(e){return e%1!=0}function Op(e){return e%2==0}function kp(e,t){t===void 0&&(t=2);var n=10**t;return Math.floor(e*n)/n}function Ap(e){return e&&e.width&&e.height}function jp(e,t){var n=e.width,r=e.height,i=t/Math.max(r,n);return new Sp(Math.round(n*i),Math.round(r*i))}function Mp(e){return e.reduce(function(e,t){return e.add(t)},new Ip(0,0)).div(new Ip(e.length,e.length))}function Np(e,t,n){return Array(e).fill(0).map(function(e,r){return t+r*n})}function Pp(e){return!!e&&e!==1/0&&e!==-1/0&&!isNaN(e)||e===0}function Fp(e){return Pp(e)&&0<=e&&e<=1}var Ip=function(){function e(e,t){this._x=e,this._y=t}return Object.defineProperty(e.prototype,`x`,{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`y`,{get:function(){return this._y},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return new e(this.x+t.x,this.y+t.y)},e.prototype.sub=function(t){return new e(this.x-t.x,this.y-t.y)},e.prototype.mul=function(t){return new e(this.x*t.x,this.y*t.y)},e.prototype.div=function(t){return new e(this.x/t.x,this.y/t.y)},e.prototype.abs=function(){return new e(Math.abs(this.x),Math.abs(this.y))},e.prototype.magnitude=function(){return Math.sqrt(this.x**2+this.y**2)},e.prototype.floor=function(){return new e(Math.floor(this.x),Math.floor(this.y))},e}(),Lp=function(){function e(t,n){n===void 0&&(n=!0);var r=t||{},i=[r.left,r.top,r.right,r.bottom].every(Pp),a=[r.x,r.y,r.width,r.height].every(Pp);if(!a&&!i)throw Error(`Box.constructor - expected box to be IBoundingBox | IRect, instead have `+JSON.stringify(r));var o=a?[r.x,r.y,r.width,r.height]:[r.left,r.top,r.right-r.left,r.bottom-r.top],s=o[0],c=o[1],l=o[2],u=o[3];e.assertIsValidBox({x:s,y:c,width:l,height:u},`Box.constructor`,n),this._x=s,this._y=c,this._width=l,this._height=u}return e.isRect=function(e){return!!e&&[e.x,e.y,e.width,e.height].every(Pp)},e.assertIsValidBox=function(t,n,r){if(r===void 0&&(r=!1),!e.isRect(t))throw Error(n+` - invalid box: `+JSON.stringify(t)+`, expected object with properties x, y, width, height`);if(!r&&(t.width<0||t.height<0))throw Error(n+` - width (`+t.width+`) and height (`+t.height+`) must be positive numbers`)},Object.defineProperty(e.prototype,`x`,{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`y`,{get:function(){return this._y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`width`,{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`height`,{get:function(){return this._height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`left`,{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`top`,{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`right`,{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottom`,{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`area`,{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`topLeft`,{get:function(){return new Ip(this.left,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`topRight`,{get:function(){return new Ip(this.right,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottomLeft`,{get:function(){return new Ip(this.left,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottomRight`,{get:function(){return new Ip(this.right,this.bottom)},enumerable:!0,configurable:!0}),e.prototype.round=function(){var t=[this.x,this.y,this.width,this.height].map(function(e){return Math.round(e)}),n=t[0],r=t[1],i=t[2],a=t[3];return new e({x:n,y:r,width:i,height:a})},e.prototype.floor=function(){var t=[this.x,this.y,this.width,this.height].map(function(e){return Math.floor(e)}),n=t[0],r=t[1],i=t[2],a=t[3];return new e({x:n,y:r,width:i,height:a})},e.prototype.toSquare=function(){var t=this,n=t.x,r=t.y,i=t.width,a=t.height,o=Math.abs(i-a);return i<a&&(n-=o/2,i+=o),a<i&&(r-=o/2,a+=o),new e({x:n,y:r,width:i,height:a})},e.prototype.rescale=function(t){var n=Ap(t)?t.width:t,r=Ap(t)?t.height:t;return new e({x:this.x*n,y:this.y*r,width:this.width*n,height:this.height*r})},e.prototype.pad=function(t,n){var r=[this.x-t/2,this.y-n/2,this.width+t,this.height+n],i=r[0],a=r[1],o=r[2],s=r[3];return new e({x:i,y:a,width:o,height:s})},e.prototype.clipAtImageBorders=function(t,n){var r=this,i=r.x,a=r.y,o=r.right,s=r.bottom,c=Math.max(i,0),l=Math.max(a,0),u=o-c,d=s-l;return new e({x:c,y:l,width:Math.min(u,t-c),height:Math.min(d,n-l)}).floor()},e.prototype.shift=function(t,n){var r=this,i=r.width,a=r.height;return new e({x:this.x+t,y:this.y+n,width:i,height:a})},e.prototype.padAtBorders=function(e,t){var n=this.width+1,r=this.height+1,i=1,a=1,o=n,s=r,c=this.left,l=this.top,u=this.right,d=this.bottom;return u>t&&(o=-u+t+n,u=t),d>e&&(s=-d+e+r,d=e),c<1&&(s=2-c,c=1),l<1&&(s=2-l,l=1),{dy:a,edy:s,dx:i,edx:o,y:l,ey:d,x:c,ex:u,w:n,h:r}},e.prototype.calibrate=function(t){return new e({left:this.left+t.left*this.width,top:this.top+t.top*this.height,right:this.right+t.right*this.width,bottom:this.bottom+t.bottom*this.height}).toSquare().round()},e}(),Rp=function(e){Z(t,e);function t(t,n,r,i,a){return a===void 0&&(a=!1),e.call(this,{left:t,top:n,right:r,bottom:i},a)||this}return t}(Lp),zp=function(){function e(e,t,n,r,i){this._imageDims=new Sp(i.width,i.height),this._score=e,this._classScore=t,this._className=n,this._box=new Lp(r).rescale(this._imageDims)}return Object.defineProperty(e.prototype,`score`,{get:function(){return this._score},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`classScore`,{get:function(){return this._classScore},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`className`,{get:function(){return this._className},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`box`,{get:function(){return this._box},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`imageDims`,{get:function(){return this._imageDims},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`imageWidth`,{get:function(){return this.imageDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`imageHeight`,{get:function(){return this.imageDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`relativeBox`,{get:function(){return new Lp(this._box).rescale(this.imageDims.reverse())},enumerable:!0,configurable:!0}),e.prototype.forSize=function(t,n){return new e(this.score,this.classScore,this.className,this.relativeBox,{width:t,height:n})},e}(),Bp=function(e){Z(t,e);function t(t,n,r){return e.call(this,t,t,``,n,r)||this}return t.prototype.forSize=function(n,r){var i=e.prototype.forSize.call(this,n,r),a=i.score,o=i.relativeBox,s=i.imageDims;return new t(a,o,s)},t}(zp);function Vp(e,t,n){n===void 0&&(n=!0);var r=Math.max(0,Math.min(e.right,t.right)-Math.max(e.left,t.left))*Math.max(0,Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top));return n?r/(e.area+t.area-r):r/Math.min(e.area,t.area)}function Hp(e){var t=e.map(function(e){return e.x}),n=e.map(function(e){return e.y});return new Rp(t.reduce(function(e,t){return t<e?t:e},1/0),n.reduce(function(e,t){return t<e?t:e},1/0),t.reduce(function(e,t){return e<t?t:e},0),n.reduce(function(e,t){return e<t?t:e},0))}function Up(e,t,n,r){r===void 0&&(r=!0);for(var i=t.map(function(e,t){return{score:e,boxIndex:t}}).sort(function(e,t){return e.score-t.score}).map(function(e){return e.boxIndex}),a=[],o=function(){var t=i.pop();a.push(t);for(var o=i,s=[],c=0;c<o.length;c++){var l=o[c],u=e[t],d=e[l];s.push(Vp(u,d,r))}i=i.filter(function(e,t){return s[t]<=n})};i.length>0;)o();return a}function Wp(e,t){return W(function(){var n=t[0],r=t[1],i=t[2];return vl(e,nr([Zn(xp(e.shape.slice(0,3),[1]),n),Zn(xp(e.shape.slice(0,3),[1]),r),Zn(xp(e.shape.slice(0,3),[1]),i)],3))})}function Gp(e,t){return t===void 0&&(t=!1),W(function(){var n=e.shape.slice(1),r=n[0],i=n[1];if(r===i)return e;var a=Math.abs(r-i),o=Math.round(a*(t?.5:1)),s=r>i?2:1,c=function(t){var n=e.shape.slice();return n[s]=t,Zn(n,0)},l=c(o),u=a-l.shape[s];return nr([t&&u?c(u):null,e,l].filter(function(e){return!!e}).map(function(e){return e.toFloat()}),s)})}function Kp(e){return 1/(1+Math.exp(-e))}var qp=function(e){Z(t,e);function t(t,n,r,i,a){return a===void 0&&(a=!1),e.call(this,{x:t,y:n,width:r,height:i},a)||this}return t}(Lp),Jp=.5,Yp=.43,Xp=.45,Zp=function(){function e(e,t,n){n===void 0&&(n=new Ip(0,0));var r=t.width,i=t.height;this._imgDims=new Sp(r,i),this._shift=n,this._positions=e.map(function(e){return e.mul(new Ip(r,i)).add(n)})}return Object.defineProperty(e.prototype,`shift`,{get:function(){return new Ip(this._shift.x,this._shift.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`imageWidth`,{get:function(){return this._imgDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`imageHeight`,{get:function(){return this._imgDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`positions`,{get:function(){return this._positions},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`relativePositions`,{get:function(){var e=this;return this._positions.map(function(t){return t.sub(e._shift).div(new Ip(e.imageWidth,e.imageHeight))})},enumerable:!0,configurable:!0}),e.prototype.forSize=function(e,t){return new this.constructor(this.relativePositions,{width:e,height:t})},e.prototype.shiftBy=function(e,t){return new this.constructor(this.relativePositions,this._imgDims,new Ip(e,t))},e.prototype.shiftByPoint=function(e){return this.shiftBy(e.x,e.y)},e.prototype.align=function(e,t){if(t===void 0&&(t={}),e){var n=e instanceof Bp?e.box.floor():new Lp(e);return this.shiftBy(n.x,n.y).align(null,t)}var r=Object.assign({},{useDlibAlignment:!1,minBoxPadding:.2},t),i=r.useDlibAlignment,a=r.minBoxPadding;return i?this.alignDlib():this.alignMinBbox(a)},e.prototype.alignDlib=function(){var e=this.getRefPointsForAlignment(),t=e[0],n=e[1],r=e[2],i=function(e){return r.sub(e).magnitude()},a=(i(t)+i(n))/2,o=Math.floor(a/Xp),s=Mp(e),c=Math.floor(Math.max(0,s.x-Jp*o)),l=Math.floor(Math.max(0,s.y-Yp*o));return new qp(c,l,Math.min(o,this.imageWidth+c),Math.min(o,this.imageHeight+l))},e.prototype.alignMinBbox=function(e){var t=Hp(this.positions);return t.pad(t.width*e,t.height*e)},e.prototype.getRefPointsForAlignment=function(){throw Error(`getRefPointsForAlignment not implemented by base class`)},e}(),Qp=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.getRefPointsForAlignment=function(){var e=this.positions;return[e[0],e[1],Mp([e[3],e[4]])]},t}(Zp),$p=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.getJawOutline=function(){return this.positions.slice(0,17)},t.prototype.getLeftEyeBrow=function(){return this.positions.slice(17,22)},t.prototype.getRightEyeBrow=function(){return this.positions.slice(22,27)},t.prototype.getNose=function(){return this.positions.slice(27,36)},t.prototype.getLeftEye=function(){return this.positions.slice(36,42)},t.prototype.getRightEye=function(){return this.positions.slice(42,48)},t.prototype.getMouth=function(){return this.positions.slice(48,68)},t.prototype.getRefPointsForAlignment=function(){return[this.getLeftEye(),this.getRightEye(),this.getMouth()].map(Mp)},t}(Zp),em=function(){function e(e,t){this._label=e,this._distance=t}return Object.defineProperty(e.prototype,`label`,{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`distance`,{get:function(){return this._distance},enumerable:!0,configurable:!0}),e.prototype.toString=function(e){return e===void 0&&(e=!0),``+this.label+(e?` (`+kp(this.distance)+`)`:``)},e}(),tm=function(e){Z(t,e);function t(t,n){var r=e.call(this,t)||this;return r._label=n,r}return t.assertIsValidLabeledBox=function(e,t){if(Lp.assertIsValidBox(e,t),!Pp(e.label))throw Error(t+` - expected property label (`+e.label+`) to be a number`)},Object.defineProperty(t.prototype,`label`,{get:function(){return this._label},enumerable:!0,configurable:!0}),t}(Lp),nm=function(){function e(e,t){if(typeof e!=`string`)throw Error(`LabeledFaceDescriptors - constructor expected label to be a string`);if(!Array.isArray(t)||t.some(function(e){return!(e instanceof Float32Array)}))throw Error(`LabeledFaceDescriptors - constructor expected descriptors to be an array of Float32Array`);this._label=e,this._descriptors=t}return Object.defineProperty(e.prototype,`label`,{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`descriptors`,{get:function(){return this._descriptors},enumerable:!0,configurable:!0}),e.prototype.toJSON=function(){return{label:this.label,descriptors:this.descriptors.map(function(e){return Array.from(e)})}},e.fromJSON=function(t){var n=t.descriptors.map(function(e){return new Float32Array(e)});return new e(t.label,n)},e}();(function(e){Z(t,e);function t(t,n,r,i){var a=e.call(this,t,n)||this;return a._score=r,a._classScore=i,a}return t.assertIsValidPredictedBox=function(e,t){if(tm.assertIsValidLabeledBox(e,t),!Fp(e.score)||!Fp(e.classScore))throw Error(t+` - expected properties score (`+e.score+`) and (`+e.classScore+`) to be a number between [0, 1]`)},Object.defineProperty(t.prototype,`score`,{get:function(){return this._score},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,`classScore`,{get:function(){return this._classScore},enumerable:!0,configurable:!0}),t})(tm);function rm(e){return e.detection instanceof Bp}function im(e,t){return Object.assign({},e,{detection:t})}function am(){var e=window.fetch||function(){throw Error(`fetch - missing fetch implementation for browser environment`)};return{Canvas:HTMLCanvasElement,CanvasRenderingContext2D,Image:HTMLImageElement,ImageData,Video:HTMLVideoElement,createCanvasElement:function(){return document.createElement(`canvas`)},createImageElement:function(){return document.createElement(`img`)},fetch:e,readFile:function(){throw Error(`readFile - filesystem not available for browser environment`)}}}function om(e){var t=``;if(!e)try{e=x()}catch(e){t=e.toString()}return{readFile:e?function(t){return new Promise(function(n,r){e.readFile(t,function(e,t){return e?r(e):n(t)})})}:function(){throw Error(`readFile - failed to require fs in nodejs environment with error: `+t)}}}function sm(){var e=global.Canvas||global.HTMLCanvasElement,t=global.Image||global.HTMLImageElement,n=function(){if(e)return new e;throw Error(`createCanvasElement - missing Canvas implementation for nodejs environment`)},r=function(){if(t)return new t;throw Error(`createImageElement - missing Image implementation for nodejs environment`)},i=global.fetch||function(){throw Error(`fetch - missing fetch implementation for nodejs environment`)},a=om();return bp({Canvas:e||function(){function e(){}return e}(),CanvasRenderingContext2D:global.CanvasRenderingContext2D||function(){function e(){}return e}(),Image:t||function(){function e(){}return e}(),ImageData:global.ImageData||function(){function e(){}return e}(),Video:global.HTMLVideoElement||function(){function e(){}return e}(),createCanvasElement:n,createImageElement:r,fetch:i},a)}function cm(){return typeof window==`object`&&typeof document<`u`&&typeof HTMLImageElement<`u`&&typeof HTMLCanvasElement<`u`&&typeof HTMLVideoElement<`u`&&typeof ImageData<`u`&&typeof CanvasRenderingContext2D<`u`}function lm(){return typeof global==`object`&&typeof require==`function`&&typeof module<`u`&&typeof process<`u`&&!!process.version}var um;function dm(){if(!um)throw Error(`getEnv - environment is not defined, check isNodejs() and isBrowser()`);return um}function fm(e){um=e}function pm(){cm()&&fm(am()),lm()&&fm(sm())}function mm(e){if(um||pm(),!um)throw Error(`monkeyPatch - environment is not defined, check isNodejs() and isBrowser()`);var t=e.Canvas,n=t===void 0?um.Canvas:t,r=e.Image,i=r===void 0?um.Image:r;um.Canvas=n,um.Image=i,um.createCanvasElement=e.createCanvasElement||(function(){return new n}),um.createImageElement=e.createImageElement||(function(){return new i}),um.ImageData=e.ImageData||um.ImageData,um.Video=e.Video||um.Video,um.fetch=e.fetch||um.fetch,um.readFile=e.readFile||um.readFile}var hm={getEnv:dm,setEnv:fm,initialize:pm,createBrowserEnv:am,createFileSystem:om,createNodejsEnv:sm,monkeyPatch:mm,isBrowser:cm,isNodejs:lm};pm();function gm(e){return!hm.isNodejs()&&typeof e==`string`?document.getElementById(e):e}function _m(e){var t=hm.getEnv(),n=t.Canvas;if(e instanceof t.CanvasRenderingContext2D)return e;var r=gm(e);if(!(r instanceof n))throw Error(`resolveContext2d - expected canvas to be of instance of Canvas`);var i=r.getContext(`2d`);if(!i)throw Error(`resolveContext2d - canvas 2d context is null`);return i}var vm;(function(e){e.TOP_LEFT=`TOP_LEFT`,e.TOP_RIGHT=`TOP_RIGHT`,e.BOTTOM_LEFT=`BOTTOM_LEFT`,e.BOTTOM_RIGHT=`BOTTOM_RIGHT`})(vm||={});var ym=function(){function e(e){e===void 0&&(e={});var t=e.anchorPosition,n=e.backgroundColor,r=e.fontColor,i=e.fontSize,a=e.fontStyle,o=e.padding;this.anchorPosition=t||vm.TOP_LEFT,this.backgroundColor=n||`rgba(0, 0, 0, 0.5)`,this.fontColor=r||`rgba(255, 255, 255, 1)`,this.fontSize=i||14,this.fontStyle=a||`Georgia`,this.padding=o||4}return e}(),bm=function(){function e(t,n,r){r===void 0&&(r={}),this.text=typeof t==`string`?[t]:t instanceof e?t.text:t,this.anchor=n,this.options=new ym(r)}return e.prototype.measureWidth=function(e){var t=this.options.padding;return this.text.map(function(t){return e.measureText(t).width}).reduce(function(e,t){return e<t?t:e},0)+2*t},e.prototype.measureHeight=function(){var e=this.options,t=e.fontSize,n=e.padding;return this.text.length*t+2*n},e.prototype.getUpperLeft=function(e,t){var n=this.options.anchorPosition,r=n===vm.BOTTOM_RIGHT||n===vm.TOP_RIGHT,i=n===vm.BOTTOM_LEFT||n===vm.BOTTOM_RIGHT,a=this.measureWidth(e),o=this.measureHeight(),s=r?this.anchor.x-a:this.anchor.x,c=i?this.anchor.y-o:this.anchor.y;if(t){var l=t.width,u=t.height;return{x:Math.max(Math.min(s,l-a),0),y:Math.max(Math.min(c,u-o),0)}}return{x:s,y:c}},e.prototype.draw=function(e){var t=gm(e),n=_m(t),r=this.options,i=r.backgroundColor,a=r.fontColor,o=r.fontSize,s=r.fontStyle,c=r.padding;n.font=o+`px `+s;var l=this.measureWidth(n),u=this.measureHeight();n.fillStyle=i;var d=this.getUpperLeft(n,t);n.fillRect(d.x,d.y,l,u),n.fillStyle=a,this.text.forEach(function(e,t){var r=c+d.x,i=c+d.y+(t+1)*o;n.fillText(e,r,i)})},e}(),xm=function(){function e(e){e===void 0&&(e={});var t=e.boxColor,n=e.lineWidth,r=e.label,i=e.drawLabelOptions;this.boxColor=t||`rgba(0, 0, 255, 1)`,this.lineWidth=n||2,this.label=r;var a={anchorPosition:vm.BOTTOM_LEFT,backgroundColor:this.boxColor};this.drawLabelOptions=new ym(Object.assign({},a,i))}return e}();(function(){function e(e,t){t===void 0&&(t={}),this.box=new Lp(e),this.options=new xm(t)}return e.prototype.draw=function(e){var t=_m(e),n=this.options,r=n.boxColor,i=n.lineWidth,a=this.box,o=a.x,s=a.y,c=a.width,l=a.height;t.strokeStyle=r,t.lineWidth=i,t.strokeRect(o,s,c,l);var u=this.options.label;u&&new bm([u],{x:o-i/2,y:s},this.options.drawLabelOptions).draw(e)},e})();function Sm(e){var t=hm.getEnv(),n=t.Image,r=t.Video;return e instanceof n&&e.complete||e instanceof r&&e.readyState>=3}function Cm(e){return new Promise(function(t,n){if(e instanceof hm.getEnv().Canvas||Sm(e))return t();function r(e){e.currentTarget&&(e.currentTarget.removeEventListener(`load`,r),e.currentTarget.removeEventListener(`error`,i),t(e))}function i(e){e.currentTarget&&(e.currentTarget.removeEventListener(`load`,r),e.currentTarget.removeEventListener(`error`,i),n(e))}e.addEventListener(`load`,r),e.addEventListener(`error`,i)})}function wm(e){var t=hm.getEnv(),n=t.Image,r=t.Video;return e instanceof n?new Sp(e.naturalWidth,e.naturalHeight):e instanceof r?new Sp(e.videoWidth,e.videoHeight):new Sp(e.width,e.height)}function Tm(e){var t=e.width,n=e.height,r=hm.getEnv().createCanvasElement,i=r();return i.width=t,i.height=n,i}function Em(e,t){var n=hm.getEnv().ImageData;if(!(e instanceof n)&&!Sm(e))throw Error(`createCanvasFromMedia - media has not finished loading yet`);var r=t||wm(e),i=r.width,a=r.height,o=Tm({width:i,height:a});return e instanceof n?_m(o).putImageData(e,0,0):_m(o).drawImage(e,0,0,i,a),o}function Dm(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a,o,s;return $(this,function(c){switch(c.label){case 0:return n=t||hm.getEnv().createCanvasElement(),r=e.shape.slice(Ep(e)?1:0),i=r[0],a=r[1],o=r[2],s=W(function(){return e.as3D(i,a,o).toInt()}),[4,ep.toPixels(s,n)];case 1:return c.sent(),s.dispose(),[2,n]}})})}function Om(e){var t=hm.getEnv(),n=t.Image,r=t.Canvas,i=t.Video;return e instanceof n||e instanceof r||e instanceof i}function km(e,t,n){n===void 0&&(n=!1);var r=hm.getEnv(),i=r.Image,a=r.Canvas;if(!(e instanceof i||e instanceof a))throw Error(`imageToSquare - expected arg0 to be HTMLImageElement | HTMLCanvasElement`);var o=wm(e),s=t/Math.max(o.height,o.width),c=s*o.width,l=s*o.height,u=Tm({width:t,height:t}),d=e instanceof a?e:Em(e),f=Math.abs(c-l)/2,p=n&&c<l?f:0,m=n&&l<c?f:0;return _m(u).drawImage(d,p,m,c,l),u}var Am=function(){function e(e,t){var n=this;if(t===void 0&&(t=!1),this._imageTensors=[],this._canvases=[],this._treatAsBatchInput=!1,this._inputDimensions=[],!Array.isArray(e))throw Error(`NetInput.constructor - expected inputs to be an Array of TResolvedNetInput or to be instanceof tf.Tensor4D, instead have `+e);this._treatAsBatchInput=t,this._batchSize=e.length,e.forEach(function(e,t){if(Tp(e)){n._imageTensors[t]=e,n._inputDimensions[t]=e.shape;return}if(Ep(e)){var r=e.shape[0];if(r!==1)throw Error(`NetInput - tf.Tensor4D with batchSize `+r+` passed, but not supported in input array`);n._imageTensors[t]=e,n._inputDimensions[t]=e.shape.slice(1);return}var i=e instanceof hm.getEnv().Canvas?e:Em(e);n._canvases[t]=i,n._inputDimensions[t]=[i.height,i.width,3]})}return Object.defineProperty(e.prototype,`imageTensors`,{get:function(){return this._imageTensors},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`canvases`,{get:function(){return this._canvases},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`isBatchInput`,{get:function(){return this.batchSize>1||this._treatAsBatchInput},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`batchSize`,{get:function(){return this._batchSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`inputDimensions`,{get:function(){return this._inputDimensions},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`inputSize`,{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`reshapedInputDimensions`,{get:function(){var e=this;return Np(this.batchSize,0,1).map(function(t,n){return e.getReshapedInputDimensions(n)})},enumerable:!0,configurable:!0}),e.prototype.getInput=function(e){return this.canvases[e]||this.imageTensors[e]},e.prototype.getInputDimensions=function(e){return this._inputDimensions[e]},e.prototype.getInputHeight=function(e){return this._inputDimensions[e][0]},e.prototype.getInputWidth=function(e){return this._inputDimensions[e][1]},e.prototype.getReshapedInputDimensions=function(e){if(typeof this.inputSize!=`number`)throw Error(`getReshapedInputDimensions - inputSize not set, toBatchTensor has not been called yet`);return jp({width:this.getInputWidth(e),height:this.getInputHeight(e)},this.inputSize)},e.prototype.toBatchTensor=function(e,t){var n=this;return t===void 0&&(t=!0),this._inputSize=e,W(function(){return Ur(Np(n.batchSize,0,1).map(function(r){var i=n.getInput(r);if(i instanceof $e){var a=Ep(i)?i:i.expandDims();return a=Gp(a,t),(a.shape[1]!==e||a.shape[2]!==e)&&(a=Ad.resizeBilinear(a,[e,e])),a.as3D(e,e,3)}if(i instanceof hm.getEnv().Canvas)return ep.fromPixels(km(i,e,t));throw Error(`toBatchTensor - at batchIdx `+r+`, expected input to be instanceof tf.Tensor or instanceof HTMLCanvasElement, instead have `+i)}).map(function(e){return e.toFloat()})).as4D(n.batchSize,e,e,3)})},e}();function jm(e){return Q(this,void 0,void 0,function(){var t,n,r;return $(this,function(i){switch(i.label){case 0:if(e instanceof Am)return[2,e];if(t=Array.isArray(e)?e:[e],!t.length)throw Error(`toNetInput - empty array passed as input`);return n=function(t){return Array.isArray(e)?` at input index `+t+`:`:``},r=t.map(gm),r.forEach(function(e,r){if(!Om(e)&&!Tp(e)&&!Ep(e))throw typeof t[r]==`string`?Error(`toNetInput -`+n(r)+` string passed, but could not resolve HTMLElement for element id `+t[r]):Error(`toNetInput -`+n(r)+` expected media to be of type HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | tf.Tensor3D, or to be an element id`);if(Ep(e)){var i=e.shape[0];if(i!==1)throw Error(`toNetInput -`+n(r)+` tf.Tensor4D with batchSize `+i+` passed, but not supported in input array`)}}),[4,Promise.all(r.map(function(e){return Om(e)&&Cm(e)}))];case 1:return i.sent(),[2,new Am(r,Array.isArray(e))]}})})}function Mm(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c;return $(this,function(l){switch(l.label){case 0:return n=hm.getEnv().Canvas,r=e,e instanceof n?[3,5]:[4,jm(e)];case 1:if(i=l.sent(),i.batchSize>1)throw Error(`extractFaces - batchSize > 1 not supported`);return a=i.getInput(0),a instanceof n?(o=a,[3,4]):[3,2];case 2:return[4,Dm(a)];case 3:o=l.sent(),l.label=4;case 4:r=o,l.label=5;case 5:return s=_m(r),c=t.map(function(e){return e instanceof Bp?e.forSize(r.width,r.height).box.floor():e}).map(function(e){return e.clipAtImageBorders(r.width,r.height)}),[2,c.map(function(e){var t=e.x,n=e.y,r=e.width,i=e.height,a=Tm({width:r,height:i});return _m(a).putImageData(s.getImageData(t,n,r,i),0,0),a})]}})})}function Nm(e,t){return Q(this,void 0,void 0,function(){return $(this,function(n){if(!Tp(e)&&!Ep(e))throw Error(`extractFaceTensors - expected image tensor to be 3D or 4D`);if(Ep(e)&&e.shape[0]>1)throw Error(`extractFaceTensors - batchSize > 1 not supported`);return[2,W(function(){var n=e.shape.slice(Ep(e)?1:0),r=n[0],i=n[1],a=n[2];return t.map(function(e){return e instanceof Bp?e.forSize(i,r).box:e}).map(function(e){return e.clipAtImageBorders(i,r)}).map(function(t){var n=t.x,o=t.y,s=t.width,c=t.height;return hu(e.as3D(r,i,a),[o,n,0],[c,s,a])})})]})})}function Pm(e,t){return Q(this,void 0,void 0,function(){var n,r;return $(this,function(i){switch(i.label){case 0:return n=hm.getEnv().fetch,[4,n(e,t)];case 1:if(r=i.sent(),!(r.status<400))throw Error(`failed to fetch: (`+r.status+`) `+r.statusText+`, from url: `+r.url);return[2,r]}})})}function Fm(e){return Q(this,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,Pm(e)];case 1:return[2,t.sent().json()]}})})}function Im(e,t){var n=t+`-weights_manifest.json`;if(!e)return{modelBaseUri:``,manifestUri:n};if(e===`/`)return{modelBaseUri:`/`,manifestUri:`/`+n};var r=e.startsWith(`http://`)?`http://`:e.startsWith(`https://`)?`https://`:``;e=e.replace(r,``);var i=e.split(`/`).filter(function(e){return e}),a=e.endsWith(`.json`)?i[i.length-1]:n,o=r+(e.endsWith(`.json`)?i.slice(0,i.length-1):i).join(`/`);return o=e.startsWith(`/`)?`/`+o:o,{modelBaseUri:o,manifestUri:o===`/`?`/`+a:o+`/`+a}}function Lm(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a;return $(this,function(o){switch(o.label){case 0:return n=Im(e,t),r=n.manifestUri,i=n.modelBaseUri,[4,Fm(r)];case 1:return a=o.sent(),[2,Xf.loadWeights(a,i)]}})})}var Rm=function(){function e(e){this._name=e,this._params=void 0,this._paramMappings=[]}return Object.defineProperty(e.prototype,`params`,{get:function(){return this._params},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`paramMappings`,{get:function(){return this._paramMappings},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`isLoaded`,{get:function(){return!!this.params},enumerable:!0,configurable:!0}),e.prototype.getParamFromPath=function(e){var t=this.traversePropertyPath(e);return t.obj[t.objProp]},e.prototype.reassignParamFromPath=function(e,t){var n=this.traversePropertyPath(e),r=n.obj,i=n.objProp;r[i].dispose(),r[i]=t},e.prototype.getParamList=function(){var e=this;return this._paramMappings.map(function(t){var n=t.paramPath;return{path:n,tensor:e.getParamFromPath(n)}})},e.prototype.getTrainableParams=function(){return this.getParamList().filter(function(e){return e.tensor instanceof at})},e.prototype.getFrozenParams=function(){return this.getParamList().filter(function(e){return!(e.tensor instanceof at)})},e.prototype.variable=function(){var e=this;this.getFrozenParams().forEach(function(t){var n=t.path,r=t.tensor;e.reassignParamFromPath(n,r.variable())})},e.prototype.freeze=function(){var e=this;this.getTrainableParams().forEach(function(t){var n=t.path,r=t.tensor,i=Bn(r.dataSync());r.dispose(),e.reassignParamFromPath(n,i)})},e.prototype.dispose=function(e){e===void 0&&(e=!0),this.getParamList().forEach(function(t){if(e&&t.tensor.isDisposed)throw Error(`param tensor has already been disposed for path `+t.path);t.tensor.dispose()}),this._params=void 0},e.prototype.serializeParams=function(){return new Float32Array(this.getParamList().map(function(e){var t=e.tensor;return Array.from(t.dataSync())}).reduce(function(e,t){return e.concat(t)}))},e.prototype.load=function(e){return Q(this,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return e instanceof Float32Array?(this.extractWeights(e),[2]):[4,this.loadFromUri(e)];case 1:return t.sent(),[2]}})})},e.prototype.loadFromUri=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:if(e&&typeof e!=`string`)throw Error(this._name+`.loadFromUri - expected model uri`);return[4,Lm(e,this.getDefaultModelName())];case 1:return t=n.sent(),this.loadFromWeightMap(t),[2]}})})},e.prototype.loadFromDisk=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i,a,o,s,c,l,u;return $(this,function(d){switch(d.label){case 0:if(e&&typeof e!=`string`)throw Error(this._name+`.loadFromDisk - expected model file path`);return t=hm.getEnv().readFile,n=Im(e,this.getDefaultModelName()),r=n.manifestUri,i=n.modelBaseUri,a=function(e){return Promise.all(e.map(function(e){return t(e).then(function(e){return e.buffer})}))},o=Xf.weightsLoaderFactory(a),l=(c=JSON).parse,[4,t(r)];case 1:return s=l.apply(c,[d.sent().toString()]),[4,o(s,i)];case 2:return u=d.sent(),this.loadFromWeightMap(u),[2]}})})},e.prototype.loadFromWeightMap=function(e){var t=this.extractParamsFromWeigthMap(e),n=t.paramMappings,r=t.params;this._paramMappings=n,this._params=r},e.prototype.extractWeights=function(e){var t=this.extractParams(e),n=t.paramMappings,r=t.params;this._paramMappings=n,this._params=r},e.prototype.traversePropertyPath=function(e){if(!this.params)throw Error(`traversePropertyPath - model has no loaded params`);var t=e.split(`/`).reduce(function(t,n){if(!t.nextObj.hasOwnProperty(n))throw Error(`traversePropertyPath - object does not have property `+n+`, for path `+e);return{obj:t.nextObj,objProp:n,nextObj:t.nextObj[n]}},{nextObj:this.params}),n=t.obj,r=t.objProp;if(!n||!r||!(n[r]instanceof $e))throw Error(`traversePropertyPath - parameter is not a tensor, for path `+e);return{obj:n,objProp:r}},e}();function zm(e,t,n){return W(function(){var r=Jl(e,t.depthwise_filter,t.pointwise_filter,n,`same`);return r=$c(r,t.bias),r})}function Bm(e,t,n){return n===void 0&&(n=!1),W(function(){var r=Mu(n?$c(Vl(e,t.conv0.filters,[2,2],`same`),t.conv0.bias):zm(e,t.conv0,[2,2])),i=zm(r,t.conv1,[1,1]);return Mu($c(r,$c(i,zm(Mu($c(r,i)),t.conv2,[1,1]))))})}function Vm(e,t,n,r){return n===void 0&&(n=!1),r===void 0&&(r=!0),W(function(){var i=Mu(n?$c(Vl(e,t.conv0.filters,r?[2,2]:[1,1],`same`),t.conv0.bias):zm(e,t.conv0,r?[2,2]:[1,1])),a=zm(i,t.conv1,[1,1]),o=zm(Mu($c(i,a)),t.conv2,[1,1]);return Mu($c(i,$c(a,$c(o,zm(Mu($c(i,$c(a,o))),t.conv3,[1,1])))))})}function Hm(e,t,n,r){return n===void 0&&(n=`same`),r===void 0&&(r=!1),W(function(){var i=$c(Vl(e,t.filters,[1,1],n),t.bias);return r?Mu(i):i})}function Um(e,t){Object.keys(e).forEach(function(n){t.some(function(e){return e.originalPath===n})||e[n].dispose()})}function Wm(e,t){return function(n,r,i,a){var o=Gn(e(n*r*i*i),[i,i,n,r]),s=Hn(e(r));return t.push({paramPath:a+`/filters`},{paramPath:a+`/bias`}),{filters:o,bias:s}}}function Gm(e,t){return function(n,r,i){var a=Un(e(n*r),[n,r]),o=Hn(e(r));return t.push({paramPath:i+`/weights`},{paramPath:i+`/bias`}),{weights:a,bias:o}}}var Km=function(){function e(e,t,n){this.depthwise_filter=e,this.pointwise_filter=t,this.bias=n}return e}();function qm(e,t){return function(n,r,i){var a=Gn(e(9*n),[3,3,n,1]),o=Gn(e(n*r),[1,1,n,r]),s=Hn(e(r));return t.push({paramPath:i+`/depthwise_filter`},{paramPath:i+`/pointwise_filter`},{paramPath:i+`/bias`}),new Km(a,o,s)}}function Jm(e){return function(t){return new Km(e(t+`/depthwise_filter`,4),e(t+`/pointwise_filter`,4),e(t+`/bias`,1))}}function Ym(e,t){return function(n,r,i){var a=e[n];if(!Cp(a,r))throw Error(`expected weightMap[`+n+`] to be a Tensor`+r+`D, instead have `+a);return t.push({originalPath:n,paramPath:i||n}),a}}function Xm(e){var t=e;function n(e){var n=t.slice(0,e);return t=t.slice(e),n}function r(){return t}return{extractWeights:n,getRemainingWeights:r}}function Zm(e,t){var n=Wm(e,t),r=qm(e,t);function i(e,t,i,a){return a===void 0&&(a=!1),{conv0:a?n(e,t,3,i+`/conv0`):r(e,t,i+`/conv0`),conv1:r(t,t,i+`/conv1`),conv2:r(t,t,i+`/conv2`)}}function a(e,t,n,a){a===void 0&&(a=!1);var o=i(e,t,n,a);return{conv0:o.conv0,conv1:o.conv1,conv2:o.conv2,conv3:r(t,t,n+`/conv3`)}}return{extractDenseBlock3Params:i,extractDenseBlock4Params:a}}function Qm(e){var t=[],n=Xm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Zm(r,t).extractDenseBlock4Params,o=a(3,32,`dense0`,!0),s=a(32,64,`dense1`),c=a(64,128,`dense2`),l=a(128,256,`dense3`);if(i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{paramMappings:t,params:{dense0:o,dense1:s,dense2:c,dense3:l}}}function $m(e){return function(t){return{filters:e(t+`/filters`,4),bias:e(t+`/bias`,1)}}}function eh(e,t){var n=Ym(e,t),r=$m(n),i=Jm(n);function a(e,t){return t===void 0&&(t=!1),{conv0:t?r(e+`/conv0`):i(e+`/conv0`),conv1:i(e+`/conv1`),conv2:i(e+`/conv2`)}}function o(e,t){return t===void 0&&(t=!1),{conv0:t?r(e+`/conv0`):i(e+`/conv0`),conv1:i(e+`/conv1`),conv2:i(e+`/conv2`),conv3:i(e+`/conv3`)}}return{extractDenseBlock3Params:a,extractDenseBlock4Params:o}}function th(e){var t=[],n=eh(e,t).extractDenseBlock4Params,r={dense0:n(`dense0`,!0),dense1:n(`dense1`),dense2:n(`dense2`),dense3:n(`dense3`)};return Um(e,t),{params:r,paramMappings:t}}var nh=function(e){Z(t,e);function t(){return e.call(this,`FaceFeatureExtractor`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`FaceFeatureExtractor - load model before inference`);return W(function(){var n=Vm(Wp(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(q(255)),t.dense0,!0);return n=Vm(n,t.dense1),n=Vm(n,t.dense2),n=Vm(n,t.dense3),n=cu(n,[7,7],[2,2],`valid`),n})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.getDefaultModelName=function(){return`face_feature_extractor_model`},t.prototype.extractParamsFromWeigthMap=function(e){return th(e)},t.prototype.extractParams=function(e){return Qm(e)},t}(Rm);function rh(e,t){return W(function(){return $c(Zl(e,t.weights),t.bias)})}function ih(e,t,n){var r=[],i=Xm(e),a=i.extractWeights,o=i.getRemainingWeights,s=Gm(a,r)(t,n,`fc`);if(o().length!==0)throw Error(`weights remaing after extract: `+o().length);return{paramMappings:r,params:{fc:s}}}function ah(e){var t=[],n=Ym(e,t);function r(e){return{weights:n(e+`/weights`,2),bias:n(e+`/bias`,1)}}var i={fc:r(`fc`)};return Um(e,t),{params:i,paramMappings:t}}function oh(e){var t={},n={};return Object.keys(e).forEach(function(r){var i=r.startsWith(`fc`)?n:t;i[r]=e[r]}),{featureExtractorMap:t,classifierMap:n}}var sh=function(e){Z(t,e);function t(t,n){var r=e.call(this,t)||this;return r._faceFeatureExtractor=n,r}return Object.defineProperty(t.prototype,`faceFeatureExtractor`,{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),t.prototype.runNet=function(e){var t=this,n=this.params;if(!n)throw Error(this._name+` - load model before inference`);return W(function(){var r=e instanceof Am?t.faceFeatureExtractor.forwardInput(e):e;return rh(r.as2D(r.shape[0],-1),n.fc)})},t.prototype.dispose=function(t){t===void 0&&(t=!0),this.faceFeatureExtractor.dispose(t),e.prototype.dispose.call(this,t)},t.prototype.loadClassifierParams=function(e){var t=this.extractClassifierParams(e),n=t.params,r=t.paramMappings;this._params=n,this._paramMappings=r},t.prototype.extractClassifierParams=function(e){return ih(e,this.getClassifierChannelsIn(),this.getClassifierChannelsOut())},t.prototype.extractParamsFromWeigthMap=function(e){var t=oh(e),n=t.featureExtractorMap,r=t.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(n),ah(r)},t.prototype.extractParams=function(e){var t=this.getClassifierChannelsIn(),n=this.getClassifierChannelsOut(),r=n*t+n,i=e.slice(0,e.length-r),a=e.slice(e.length-r);return this.faceFeatureExtractor.extractWeights(i),this.extractClassifierParams(a)},t}(Rm),ch=[`neutral`,`happy`,`sad`,`angry`,`fearful`,`disgusted`,`surprised`],lh=function(){function e(e){var t=this;if(e.length!==7)throw Error(`FaceExpressions.constructor - expected probabilities.length to be 7, have: `+e.length);ch.forEach(function(n,r){t[n]=e[r]})}return e.prototype.asSortedArray=function(){var e=this;return ch.map(function(t){return{expression:t,probability:e[t]}}).sort(function(e,t){return t.probability-e.probability})},e}(),uh=function(e){Z(t,e);function t(t){return t===void 0&&(t=new nh),e.call(this,`FaceExpressionNet`,t)||this}return t.prototype.forwardInput=function(e){var t=this;return W(function(){return mi(t.runNet(e))})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.predictExpressions=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i,a=this;return $(this,function(o){switch(o.label){case 0:return[4,jm(e)];case 1:return t=o.sent(),[4,this.forwardInput(t)];case 2:return n=o.sent(),[4,Promise.all(Kr(n).map(function(e){return Q(a,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return[4,e.data()];case 1:return t=n.sent(),e.dispose(),[2,t]}})})}))];case 3:return r=o.sent(),n.dispose(),i=r.map(function(e){return new lh(e)}),[2,t.isBatchInput?i:i[0]]}})})},t.prototype.getDefaultModelName=function(){return`face_expression_model`},t.prototype.getClassifierChannelsIn=function(){return 256},t.prototype.getClassifierChannelsOut=function(){return 7},t}(sh);function dh(e,t){return Object.assign({},e,{expressions:t})}function fh(e){return rm(e)&&e.landmarks instanceof Zp&&e.unshiftedLandmarks instanceof Zp&&e.alignedRect instanceof Bp}function ph(e,t){var n=e.detection.box,r=t.shiftBy(n.x,n.y),i=r.align(),a=e.detection.imageDims,o={landmarks:r,unshiftedLandmarks:t,alignedRect:new Bp(e.detection.score,i.rescale(a.reverse()),a)};return Object.assign({},e,o)}var mh=function(){function e(e){e===void 0&&(e={});var t=e.drawLines,n=t===void 0?!0:t,r=e.drawPoints,i=r===void 0?!0:r,a=e.lineWidth,o=e.lineColor,s=e.pointSize,c=e.pointColor;this.drawLines=n,this.drawPoints=i,this.lineWidth=a||1,this.pointSize=s||2,this.lineColor=o||`rgba(0, 255, 255, 1)`,this.pointColor=c||`rgba(255, 0, 255, 1)`}return e}();(function(){function e(e,t){t===void 0&&(t={}),this.faceLandmarks=e,this.options=new mh(t)}return e.prototype.draw=function(e){var t=_m(e),n=this.options,r=n.drawLines,i=n.drawPoints,a=n.lineWidth,o=n.lineColor,s=n.pointSize,c=n.pointColor;r&&this.faceLandmarks instanceof $p&&(t.strokeStyle=o,t.lineWidth=a,vp(t,this.faceLandmarks.getJawOutline()),vp(t,this.faceLandmarks.getLeftEyeBrow()),vp(t,this.faceLandmarks.getRightEyeBrow()),vp(t,this.faceLandmarks.getNose()),vp(t,this.faceLandmarks.getLeftEye(),!0),vp(t,this.faceLandmarks.getRightEye(),!0),vp(t,this.faceLandmarks.getMouth(),!0)),i&&(t.strokeStyle=c,t.fillStyle=c,this.faceLandmarks.positions.forEach(function(e){t.beginPath(),t.arc(e.x,e.y,s,0,2*Math.PI),t.fill()}))},e})();function hh(e,t){var n=Wm(e,t),r=qm(e,t);function i(e,t,i){return{separable_conv0:r(e,t,i+`/separable_conv0`),separable_conv1:r(t,t,i+`/separable_conv1`),expansion_conv:n(e,t,1,i+`/expansion_conv`)}}function a(e,t){return{separable_conv0:r(e,e,t+`/separable_conv0`),separable_conv1:r(e,e,t+`/separable_conv1`),separable_conv2:r(e,e,t+`/separable_conv2`)}}return{extractConvParams:n,extractSeparableConvParams:r,extractReductionBlockParams:i,extractMainBlockParams:a}}function gh(e,t){var n=[],r=Xm(e),i=r.extractWeights,a=r.getRemainingWeights,o=hh(i,n),s=o.extractConvParams,c=o.extractSeparableConvParams,l=o.extractReductionBlockParams,u=o.extractMainBlockParams,d={conv_in:s(3,32,3,`entry_flow/conv_in`),reduction_block_0:l(32,64,`entry_flow/reduction_block_0`),reduction_block_1:l(64,128,`entry_flow/reduction_block_1`)},f={};Np(t,0,1).forEach(function(e){f[`main_block_`+e]=u(128,`middle_flow/main_block_`+e)});var p={reduction_block:l(128,256,`exit_flow/reduction_block`),separable_conv:c(256,512,`exit_flow/separable_conv`)};if(a().length!==0)throw Error(`weights remaing after extract: `+a().length);return{paramMappings:n,params:{entry_flow:d,middle_flow:f,exit_flow:p}}}function _h(e,t){var n=Ym(e,t),r=$m(n),i=Jm(n);function a(e){return{separable_conv0:i(e+`/separable_conv0`),separable_conv1:i(e+`/separable_conv1`),expansion_conv:r(e+`/expansion_conv`)}}function o(e){return{separable_conv0:i(e+`/separable_conv0`),separable_conv1:i(e+`/separable_conv1`),separable_conv2:i(e+`/separable_conv2`)}}return{extractConvParams:r,extractSeparableConvParams:i,extractReductionBlockParams:a,extractMainBlockParams:o}}function vh(e,t){var n=[],r=_h(e,n),i=r.extractConvParams,a=r.extractSeparableConvParams,o=r.extractReductionBlockParams,s=r.extractMainBlockParams,c={conv_in:i(`entry_flow/conv_in`),reduction_block_0:o(`entry_flow/reduction_block_0`),reduction_block_1:o(`entry_flow/reduction_block_1`)},l={};Np(t,0,1).forEach(function(e){l[`main_block_`+e]=s(`middle_flow/main_block_`+e)});var u={reduction_block:o(`exit_flow/reduction_block`),separable_conv:a(`exit_flow/separable_conv`)};return Um(e,n),{params:{entry_flow:c,middle_flow:l,exit_flow:u},paramMappings:n}}function yh(e,t,n){return $c(Vl(e,t.filters,n,`same`),t.bias)}function bh(e,t,n){n===void 0&&(n=!0);var r=n?Mu(e):e;return r=zm(r,t.separable_conv0,[1,1]),r=zm(Mu(r),t.separable_conv1,[1,1]),r=su(r,[3,3],[2,2],`same`),r=$c(r,yh(e,t.expansion_conv,[2,2])),r}function xh(e,t){var n=zm(Mu(e),t.separable_conv0,[1,1]);return n=zm(Mu(n),t.separable_conv1,[1,1]),n=zm(Mu(n),t.separable_conv2,[1,1]),n=$c(n,e),n}var Sh=function(e){Z(t,e);function t(t){var n=e.call(this,`TinyXception`)||this;return n._numMainBlocks=t,n}return t.prototype.forwardInput=function(e){var t=this,n=this.params;if(!n)throw Error(`TinyXception - load model before inference`);return W(function(){var r=Mu(yh(Wp(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(q(256)),n.entry_flow.conv_in,[2,2]));return r=bh(r,n.entry_flow.reduction_block_0,!1),r=bh(r,n.entry_flow.reduction_block_1),Np(t._numMainBlocks,0,1).forEach(function(e){r=xh(r,n.middle_flow[`main_block_`+e])}),r=bh(r,n.exit_flow.reduction_block),r=Mu(zm(r,n.exit_flow.separable_conv,[1,1])),r})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.getDefaultModelName=function(){return`tiny_xception_model`},t.prototype.extractParamsFromWeigthMap=function(e){return vh(e,this._numMainBlocks)},t.prototype.extractParams=function(e){return gh(e,this._numMainBlocks)},t}(Rm);function Ch(e){var t=[],n=Xm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Gm(r,t),o=a(512,1,`fc/age`),s=a(512,2,`fc/gender`);if(i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{paramMappings:t,params:{fc:{age:o,gender:s}}}}function wh(e){var t=[],n=Ym(e,t);function r(e){return{weights:n(e+`/weights`,2),bias:n(e+`/bias`,1)}}var i={fc:{age:r(`fc/age`),gender:r(`fc/gender`)}};return Um(e,t),{params:i,paramMappings:t}}var Th;(function(e){e.FEMALE=`female`,e.MALE=`male`})(Th||={});var Eh=function(e){Z(t,e);function t(t){t===void 0&&(t=new Sh(2));var n=e.call(this,`AgeGenderNet`)||this;return n._faceFeatureExtractor=t,n}return Object.defineProperty(t.prototype,`faceFeatureExtractor`,{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),t.prototype.runNet=function(e){var t=this,n=this.params;if(!n)throw Error(this._name+` - load model before inference`);return W(function(){var r=e instanceof Am?t.faceFeatureExtractor.forwardInput(e):e,i=cu(r,[7,7],[2,2],`valid`).as2D(r.shape[0],-1);return{age:rh(i,n.fc.age).as1D(),gender:rh(i,n.fc.gender)}})},t.prototype.forwardInput=function(e){var t=this;return W(function(){var n=t.runNet(e),r=n.age,i=n.gender;return{age:r,gender:mi(i)}})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.predictAgeAndGender=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i,a,o,s=this;return $(this,function(c){switch(c.label){case 0:return[4,jm(e)];case 1:return t=c.sent(),[4,this.forwardInput(t)];case 2:return n=c.sent(),r=Kr(n.age),i=Kr(n.gender),a=r.map(function(e,t){return{ageTensor:e,genderTensor:i[t]}}),[4,Promise.all(a.map(function(e){var t=e.ageTensor,n=e.genderTensor;return Q(s,void 0,void 0,function(){var e,r,i,a,o;return $(this,function(s){switch(s.label){case 0:return[4,t.data()];case 1:return e=s.sent()[0],[4,n.data()];case 2:return r=s.sent()[0],i=r>.5,a=i?Th.MALE:Th.FEMALE,o=i?r:1-r,t.dispose(),n.dispose(),[2,{age:e,gender:a,genderProbability:o}]}})})}))];case 3:return o=c.sent(),n.age.dispose(),n.gender.dispose(),[2,t.isBatchInput?o:o[0]]}})})},t.prototype.getDefaultModelName=function(){return`age_gender_model`},t.prototype.dispose=function(t){t===void 0&&(t=!0),this.faceFeatureExtractor.dispose(t),e.prototype.dispose.call(this,t)},t.prototype.loadClassifierParams=function(e){var t=this.extractClassifierParams(e),n=t.params,r=t.paramMappings;this._params=n,this._paramMappings=r},t.prototype.extractClassifierParams=function(e){return Ch(e)},t.prototype.extractParamsFromWeigthMap=function(e){var t=oh(e),n=t.featureExtractorMap,r=t.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(n),wh(r)},t.prototype.extractParams=function(e){var t=1539,n=e.slice(0,e.length-t),r=e.slice(e.length-t);return this.faceFeatureExtractor.extractWeights(n),this.extractClassifierParams(r)},t}(Rm),Dh=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.postProcess=function(e,t,n){var r=n.map(function(e){var n=e.width,r=e.height,i=t/Math.max(r,n);return{width:n*i,height:r*i}}),i=r.length;return W(function(){var n=function(e,t){return Ur([Zn([68],e),Zn([68],t)],1).as2D(1,136).as1D()},a=function(e,t){var n=r[e],i=n.width,a=n.height;return t(i,a)?Math.abs(i-a)/2:0},o=function(e){return a(e,function(e,t){return e<t})},s=function(e){return a(e,function(e,t){return t<e})};return e.mul(Zn([i,136],t)).sub(Ur(Array.from(Array(i),function(e,t){return n(o(t),s(t))}))).div(Ur(Array.from(Array(i),function(e,t){return n(r[t].width,r[t].height)})))})},t.prototype.forwardInput=function(e){var t=this;return W(function(){var n=t.runNet(e);return t.postProcess(n,e.inputSize,e.inputDimensions.map(function(e){return{height:e[0],width:e[1]}}))})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.detectLandmarks=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i=this;return $(this,function(a){switch(a.label){case 0:return[4,jm(e)];case 1:return t=a.sent(),n=W(function(){return Kr(i.forwardInput(t))}),[4,Promise.all(n.map(function(e,n){return Q(i,void 0,void 0,function(){var r,i,a,o,s;return $(this,function(c){switch(c.label){case 0:return a=(i=Array).from,[4,e.data()];case 1:return r=a.apply(i,[c.sent()]),o=r.filter(function(e,t){return Op(t)}),s=r.filter(function(e,t){return!Op(t)}),[2,new $p(Array(68).fill(0).map(function(e,t){return new Ip(o[t],s[t])}),{height:t.getInputHeight(n),width:t.getInputWidth(n)})]}})})}))];case 2:return r=a.sent(),n.forEach(function(e){return e.dispose()}),[2,t.isBatchInput?r:r[0]]}})})},t.prototype.getClassifierChannelsOut=function(){return 136},t}(sh),Oh=function(e){Z(t,e);function t(t){return t===void 0&&(t=new nh),e.call(this,`FaceLandmark68Net`,t)||this}return t.prototype.getDefaultModelName=function(){return`face_landmark_68_model`},t.prototype.getClassifierChannelsIn=function(){return 256},t}(Dh);function kh(e){var t=[],n=eh(e,t).extractDenseBlock3Params,r={dense0:n(`dense0`,!0),dense1:n(`dense1`),dense2:n(`dense2`)};return Um(e,t),{params:r,paramMappings:t}}function Ah(e){var t=[],n=Xm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Zm(r,t).extractDenseBlock3Params,o=a(3,32,`dense0`,!0),s=a(32,64,`dense1`),c=a(64,128,`dense2`);if(i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{paramMappings:t,params:{dense0:o,dense1:s,dense2:c}}}var jh=function(e){Z(t,e);function t(){return e.call(this,`TinyFaceFeatureExtractor`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`TinyFaceFeatureExtractor - load model before inference`);return W(function(){var n=Bm(Wp(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(q(255)),t.dense0,!0);return n=Bm(n,t.dense1),n=Bm(n,t.dense2),n=cu(n,[14,14],[2,2],`valid`),n})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.getDefaultModelName=function(){return`face_feature_extractor_tiny_model`},t.prototype.extractParamsFromWeigthMap=function(e){return kh(e)},t.prototype.extractParams=function(e){return Ah(e)},t}(Rm),Mh=function(e){Z(t,e);function t(t){return t===void 0&&(t=new jh),e.call(this,`FaceLandmark68TinyNet`,t)||this}return t.prototype.getDefaultModelName=function(){return`face_landmark_68_tiny_model`},t.prototype.getClassifierChannelsIn=function(){return 128},t}(Dh);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t})(Oh);function Nh(e,t){return $c(pl(e,t.weights),t.biases)}function Ph(e,t,n,r,i){i===void 0&&(i=`same`);var a=t.conv,o=a.filters,s=a.bias,c=Vl(e,o,n,i);return c=$c(c,s),c=Nh(c,t.scale),r?Mu(c):c}function Fh(e,t){return Ph(e,t,[1,1],!0)}function Ih(e,t){return Ph(e,t,[1,1],!1)}function Lh(e,t){return Ph(e,t,[2,2],!0,`valid`)}function Rh(e,t){function n(t,n,r){var i=e(t),a=i.length/(n*r*r);if(Dp(a))throw Error(`depth has to be an integer: `+a+`, weights.length: `+i.length+`, numFilters: `+n+`, filterSize: `+r);return W(function(){return Fu(Gn(i,[n,a,r,r]),[2,3,1,0])})}function r(r,i,a,o){var s=n(r,i,a),c=Hn(e(i));return t.push({paramPath:o+`/filters`},{paramPath:o+`/bias`}),{filters:s,bias:c}}function i(n,r){var i=Hn(e(n)),a=Hn(e(n));return t.push({paramPath:r+`/weights`},{paramPath:r+`/biases`}),{weights:i,biases:a}}function a(e,t,n,a){return{conv:r(e,t,n,a+`/conv`),scale:i(t,a+`/scale`)}}function o(e,t,n,r,i){return i===void 0&&(i=!1),{conv1:a((i?.5:1)*e,t,n,r+`/conv1`),conv2:a(e,t,n,r+`/conv2`)}}return{extractConvLayerParams:a,extractResidualLayerParams:o}}function zh(e){var t=Xm(e),n=t.extractWeights,r=t.getRemainingWeights,i=[],a=Rh(n,i),o=a.extractConvLayerParams,s=a.extractResidualLayerParams,c=o(4704,32,7,`conv32_down`),l=s(9216,32,3,`conv32_1`),u=s(9216,32,3,`conv32_2`),d=s(9216,32,3,`conv32_3`),f=s(36864,64,3,`conv64_down`,!0),p=s(36864,64,3,`conv64_1`),m=s(36864,64,3,`conv64_2`),h=s(36864,64,3,`conv64_3`),g=s(147456,128,3,`conv128_down`,!0),_=s(147456,128,3,`conv128_1`),v=s(147456,128,3,`conv128_2`),y=s(589824,256,3,`conv256_down`,!0),b=s(589824,256,3,`conv256_1`),x=s(589824,256,3,`conv256_2`),S=s(589824,256,3,`conv256_down_out`),C=W(function(){return Fu(Un(n(256*128),[128,256]),[1,0])});if(i.push({paramPath:`fc`}),r().length!==0)throw Error(`weights remaing after extract: `+r().length);return{params:{conv32_down:c,conv32_1:l,conv32_2:u,conv32_3:d,conv64_down:f,conv64_1:p,conv64_2:m,conv64_3:h,conv128_down:g,conv128_1:_,conv128_2:v,conv256_down:y,conv256_1:b,conv256_2:x,conv256_down_out:S,fc:C},paramMappings:i}}function Bh(e,t){var n=Ym(e,t);function r(e){return{weights:n(e+`/scale/weights`,1),biases:n(e+`/scale/biases`,1)}}function i(e){var t=n(e+`/conv/filters`,4),i=n(e+`/conv/bias`,1),a=r(e);return{conv:{filters:t,bias:i},scale:a}}function a(e){return{conv1:i(e+`/conv1`),conv2:i(e+`/conv2`)}}return{extractConvLayerParams:i,extractResidualLayerParams:a}}function Vh(e){var t=[],n=Bh(e,t),r=n.extractConvLayerParams,i=n.extractResidualLayerParams,a=r(`conv32_down`),o=i(`conv32_1`),s=i(`conv32_2`),c=i(`conv32_3`),l=i(`conv64_down`),u=i(`conv64_1`),d=i(`conv64_2`),f=i(`conv64_3`),p=i(`conv128_down`),m=i(`conv128_1`),h=i(`conv128_2`),g=i(`conv256_down`),_=i(`conv256_1`),v=i(`conv256_2`),y=i(`conv256_down_out`),b=e.fc;if(t.push({originalPath:`fc`,paramPath:`fc`}),!wp(b))throw Error(`expected weightMap[fc] to be a Tensor2D, instead have `+b);var x={conv32_down:a,conv32_1:o,conv32_2:s,conv32_3:c,conv64_down:l,conv64_1:u,conv64_2:d,conv64_3:f,conv128_down:p,conv128_1:m,conv128_2:h,conv256_down:g,conv256_1:_,conv256_2:v,conv256_down_out:y,fc:b};return Um(e,t),{params:x,paramMappings:t}}function Hh(e,t){var n=Fh(e,t.conv1);return n=Ih(n,t.conv2),n=$c(n,e),n=Mu(n),n}function Uh(e,t){var n=Lh(e,t.conv1);n=Ih(n,t.conv2);var r=cu(e,2,2,`valid`),i=Xn(r.shape),a=r.shape[3]!==n.shape[3];if(r.shape[1]!==n.shape[1]||r.shape[2]!==n.shape[2]){var o=xp(n.shape);o[1]=1;var s=Xn(o);n=nr([n,s],1);var c=xp(n.shape);c[2]=1;var l=Xn(c);n=nr([n,l],2)}return r=a?nr([r,i],3):r,n=$c(r,n),n=Mu(n),n}var Wh=function(e){Z(t,e);function t(){return e.call(this,`FaceRecognitionNet`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`FaceRecognitionNet - load model before inference`);return W(function(){var n=Lh(Wp(e.toBatchTensor(150,!0).toFloat(),[122.782,117.001,104.298]).div(q(256)),t.conv32_down);return n=su(n,3,2,`valid`),n=Hh(n,t.conv32_1),n=Hh(n,t.conv32_2),n=Hh(n,t.conv32_3),n=Uh(n,t.conv64_down),n=Hh(n,t.conv64_1),n=Hh(n,t.conv64_2),n=Hh(n,t.conv64_3),n=Uh(n,t.conv128_down),n=Hh(n,t.conv128_1),n=Hh(n,t.conv128_2),n=Uh(n,t.conv256_down),n=Hh(n,t.conv256_1),n=Hh(n,t.conv256_2),n=Uh(n,t.conv256_down_out),Zl(n.mean([1,2]),t.fc)})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.computeFaceDescriptor=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i=this;return $(this,function(a){switch(a.label){case 0:return[4,jm(e)];case 1:return t=a.sent(),n=W(function(){return Kr(i.forwardInput(t))}),[4,Promise.all(n.map(function(e){return e.data()}))];case 2:return r=a.sent(),n.forEach(function(e){return e.dispose()}),[2,t.isBatchInput?r:r[0]]}})})},t.prototype.getDefaultModelName=function(){return`face_recognition_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Vh(e)},t.prototype.extractParams=function(e){return zh(e)},t}(Rm);function Gh(e,t){return Object.assign({},e,{descriptor:t})}function Kh(e,t){return Object.assign({},e,{age:t})}function qh(e,t,n){return Object.assign({},e,{gender:t,genderProbability:n})}var Jh=function(){function e(e){var t=e===void 0?{}:e,n=t.minFaceSize,r=t.scaleFactor,i=t.maxNumScales,a=t.scoreThresholds,o=t.scaleSteps;if(this._name=`MtcnnOptions`,this._minFaceSize=n||20,this._scaleFactor=r||.709,this._maxNumScales=i||10,this._scoreThresholds=a||[.6,.7,.7],this._scaleSteps=o,typeof this._minFaceSize!=`number`||this._minFaceSize<0)throw Error(this._name+` - expected minFaceSize to be a number > 0`);if(typeof this._scaleFactor!=`number`||this._scaleFactor<=0||this._scaleFactor>=1)throw Error(this._name+` - expected scaleFactor to be a number between 0 and 1`);if(typeof this._maxNumScales!=`number`||this._maxNumScales<0)throw Error(this._name+` - expected maxNumScales to be a number > 0`);if(!Array.isArray(this._scoreThresholds)||this._scoreThresholds.length!==3||this._scoreThresholds.some(function(e){return typeof e!=`number`}))throw Error(this._name+` - expected scoreThresholds to be an array of numbers of length 3`);if(this._scaleSteps&&(!Array.isArray(this._scaleSteps)||this._scaleSteps.some(function(e){return typeof e!=`number`})))throw Error(this._name+` - expected scaleSteps to be an array of numbers`)}return Object.defineProperty(e.prototype,`minFaceSize`,{get:function(){return this._minFaceSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`scaleFactor`,{get:function(){return this._scaleFactor},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`maxNumScales`,{get:function(){return this._maxNumScales},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`scoreThresholds`,{get:function(){return this._scoreThresholds},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`scaleSteps`,{get:function(){return this._scaleSteps},enumerable:!0,configurable:!0}),e}();function Yh(e,t){function n(n,r){var i=Gn(e(9*n),[3,3,n,1]),a=Hn(e(n)),o=Hn(e(n)),s=Hn(e(n)),c=Hn(e(n));return t.push({paramPath:r+`/filters`},{paramPath:r+`/batch_norm_scale`},{paramPath:r+`/batch_norm_offset`},{paramPath:r+`/batch_norm_mean`},{paramPath:r+`/batch_norm_variance`}),{filters:i,batch_norm_scale:a,batch_norm_offset:o,batch_norm_mean:s,batch_norm_variance:c}}function r(n,r,i,a,o){var s=Gn(e(n*r*i*i),[i,i,n,r]),c=Hn(e(r));return t.push({paramPath:a+`/filters`},{paramPath:a+`/`+(o?`batch_norm_offset`:`bias`)}),{filters:s,bias:c}}function i(e,t,n,i){var a=r(e,t,n,i,!0);return{filters:a.filters,batch_norm_offset:a.bias}}function a(e,t,r){return{depthwise_conv:n(e,r+`/depthwise_conv`),pointwise_conv:i(e,t,1,r+`/pointwise_conv`)}}function o(){return{conv_0:i(3,32,3,`mobilenetv1/conv_0`),conv_1:a(32,64,`mobilenetv1/conv_1`),conv_2:a(64,128,`mobilenetv1/conv_2`),conv_3:a(128,128,`mobilenetv1/conv_3`),conv_4:a(128,256,`mobilenetv1/conv_4`),conv_5:a(256,256,`mobilenetv1/conv_5`),conv_6:a(256,512,`mobilenetv1/conv_6`),conv_7:a(512,512,`mobilenetv1/conv_7`),conv_8:a(512,512,`mobilenetv1/conv_8`),conv_9:a(512,512,`mobilenetv1/conv_9`),conv_10:a(512,512,`mobilenetv1/conv_10`),conv_11:a(512,512,`mobilenetv1/conv_11`),conv_12:a(512,1024,`mobilenetv1/conv_12`),conv_13:a(1024,1024,`mobilenetv1/conv_13`)}}function s(){var e=i(1024,256,1,`prediction_layer/conv_0`),t=i(256,512,3,`prediction_layer/conv_1`),n=i(512,128,1,`prediction_layer/conv_2`),a=i(128,256,3,`prediction_layer/conv_3`),o=i(256,128,1,`prediction_layer/conv_4`),s=i(128,256,3,`prediction_layer/conv_5`),c=i(256,64,1,`prediction_layer/conv_6`),l=i(64,128,3,`prediction_layer/conv_7`),u=r(512,12,1,`prediction_layer/box_predictor_0/box_encoding_predictor`),d=r(512,9,1,`prediction_layer/box_predictor_0/class_predictor`),f=r(1024,24,1,`prediction_layer/box_predictor_1/box_encoding_predictor`),p=r(1024,18,1,`prediction_layer/box_predictor_1/class_predictor`),m=r(512,24,1,`prediction_layer/box_predictor_2/box_encoding_predictor`),h=r(512,18,1,`prediction_layer/box_predictor_2/class_predictor`),g=r(256,24,1,`prediction_layer/box_predictor_3/box_encoding_predictor`),_=r(256,18,1,`prediction_layer/box_predictor_3/class_predictor`),v=r(256,24,1,`prediction_layer/box_predictor_4/box_encoding_predictor`),y=r(256,18,1,`prediction_layer/box_predictor_4/class_predictor`),b=r(128,24,1,`prediction_layer/box_predictor_5/box_encoding_predictor`),x=r(128,18,1,`prediction_layer/box_predictor_5/class_predictor`);return{conv_0:e,conv_1:t,conv_2:n,conv_3:a,conv_4:o,conv_5:s,conv_6:c,conv_7:l,box_predictor_0:{box_encoding_predictor:u,class_predictor:d},box_predictor_1:{box_encoding_predictor:f,class_predictor:p},box_predictor_2:{box_encoding_predictor:m,class_predictor:h},box_predictor_3:{box_encoding_predictor:g,class_predictor:_},box_predictor_4:{box_encoding_predictor:v,class_predictor:y},box_predictor_5:{box_encoding_predictor:b,class_predictor:x}}}return{extractMobilenetV1Params:o,extractPredictionLayerParams:s}}function Xh(e){var t=[],n=Xm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Yh(r,t),o=a.extractMobilenetV1Params,s=a.extractPredictionLayerParams,c=o(),l=s(),u={extra_dim:Wn(r(5118*4),[1,5118,4])};if(t.push({paramPath:`output_layer/extra_dim`}),i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{params:{mobilenetv1:c,prediction_layer:l,output_layer:u},paramMappings:t}}function Zh(e,t){var n=Ym(e,t);function r(e,t,r){return{filters:n(e+`/Conv2d_`+t+`_pointwise/weights`,4,r+`/filters`),batch_norm_offset:n(e+`/Conv2d_`+t+`_pointwise/convolution_bn_offset`,1,r+`/batch_norm_offset`)}}function i(e){var t=`mobilenetv1/conv_`+e,i=`MobilenetV1/Conv2d_`+e+`_depthwise`,a=t+`/depthwise_conv`,o=t+`/pointwise_conv`;return{depthwise_conv:{filters:n(i+`/depthwise_weights`,4,a+`/filters`),batch_norm_scale:n(i+`/BatchNorm/gamma`,1,a+`/batch_norm_scale`),batch_norm_offset:n(i+`/BatchNorm/beta`,1,a+`/batch_norm_offset`),batch_norm_mean:n(i+`/BatchNorm/moving_mean`,1,a+`/batch_norm_mean`),batch_norm_variance:n(i+`/BatchNorm/moving_variance`,1,a+`/batch_norm_variance`)},pointwise_conv:r(`MobilenetV1`,e,o)}}function a(){return{conv_0:r(`MobilenetV1`,0,`mobilenetv1/conv_0`),conv_1:i(1),conv_2:i(2),conv_3:i(3),conv_4:i(4),conv_5:i(5),conv_6:i(6),conv_7:i(7),conv_8:i(8),conv_9:i(9),conv_10:i(10),conv_11:i(11),conv_12:i(12),conv_13:i(13)}}function o(e,t){return{filters:n(e+`/weights`,4,t+`/filters`),bias:n(e+`/biases`,1,t+`/bias`)}}function s(e){return{box_encoding_predictor:o(`Prediction/BoxPredictor_`+e+`/BoxEncodingPredictor`,`prediction_layer/box_predictor_`+e+`/box_encoding_predictor`),class_predictor:o(`Prediction/BoxPredictor_`+e+`/ClassPredictor`,`prediction_layer/box_predictor_`+e+`/class_predictor`)}}function c(){return{conv_0:r(`Prediction`,0,`prediction_layer/conv_0`),conv_1:r(`Prediction`,1,`prediction_layer/conv_1`),conv_2:r(`Prediction`,2,`prediction_layer/conv_2`),conv_3:r(`Prediction`,3,`prediction_layer/conv_3`),conv_4:r(`Prediction`,4,`prediction_layer/conv_4`),conv_5:r(`Prediction`,5,`prediction_layer/conv_5`),conv_6:r(`Prediction`,6,`prediction_layer/conv_6`),conv_7:r(`Prediction`,7,`prediction_layer/conv_7`),box_predictor_0:s(0),box_predictor_1:s(1),box_predictor_2:s(2),box_predictor_3:s(3),box_predictor_4:s(4),box_predictor_5:s(5)}}return{extractMobilenetV1Params:a,extractPredictionLayerParams:c}}function Qh(e){var t=[],n=Zh(e,t),r=n.extractMobilenetV1Params,i=n.extractPredictionLayerParams,a=e[`Output/extra_dim`];if(t.push({originalPath:`Output/extra_dim`,paramPath:`output_layer/extra_dim`}),!Tp(a))throw Error(`expected weightMap['Output/extra_dim'] to be a Tensor3D, instead have `+a);var o={mobilenetv1:r(),prediction_layer:i(),output_layer:{extra_dim:a}};return Um(e,t),{params:o,paramMappings:t}}function $h(e,t,n){return W(function(){var r=Vl(e,t.filters,n,`same`);return r=$c(r,t.batch_norm_offset),sc(r,0,6)})}var eg=.0010000000474974513;function tg(e,t,n){return W(function(){var r=Gl(e,t.filters,n,`same`);return r=Uc(r,t.batch_norm_mean,t.batch_norm_variance,t.batch_norm_offset,t.batch_norm_scale,eg),sc(r,0,6)})}function ng(e){return[2,4,6,12].some(function(t){return t===e})?[2,2]:[1,1]}function rg(e,t){return W(function(){var n=null,r=$h(e,t.conv_0,[2,2]);if([t.conv_1,t.conv_2,t.conv_3,t.conv_4,t.conv_5,t.conv_6,t.conv_7,t.conv_8,t.conv_9,t.conv_10,t.conv_11,t.conv_12,t.conv_13].forEach(function(e,t){var i=t+1,a=ng(i);r=tg(r,e.depthwise_conv,a),r=$h(r,e.pointwise_conv,[1,1]),i===11&&(n=r)}),n===null)throw Error(`mobileNetV1 - output of conv layer 11 is null`);return{out:r,conv11:n}})}function ig(e,t,n,r,i){var a=e.shape[0],o=Math.min(n,a),s=t.map(function(e,t){return{score:e,boxIndex:t}}).filter(function(e){return e.score>i}).sort(function(e,t){return t.score-e.score}),c=function(e){return e<=r?1:0},l=[];return s.forEach(function(t){if(!(l.length>=o)){for(var n=t.score,r=l.length-1;r>=0;--r){var a=ag(e,t.boxIndex,l[r]);if(a!==0&&(t.score*=c(a),t.score<=i))break}n===t.score&&l.push(t.boxIndex)}}),l}function ag(e,t,n){var r=e.arraySync(),i=Math.min(r[t][0],r[t][2]),a=Math.min(r[t][1],r[t][3]),o=Math.max(r[t][0],r[t][2]),s=Math.max(r[t][1],r[t][3]),c=Math.min(r[n][0],r[n][2]),l=Math.min(r[n][1],r[n][3]),u=Math.max(r[n][0],r[n][2]),d=Math.max(r[n][1],r[n][3]),f=(o-i)*(s-a),p=(u-c)*(d-l);if(f<=0||p<=0)return 0;var m=Math.max(i,c),h=Math.max(a,l),g=Math.min(o,u),_=Math.min(s,d),v=Math.max(g-m,0)*Math.max(_-h,0);return v/(f+p-v)}function og(e){var t=Kr(Fu(e,[1,0])),n=[vl(t[2],t[0]),vl(t[3],t[1])];return{sizes:n,centers:[$c(t[0],rl(n[0],q(2))),$c(t[1],rl(n[1],q(2)))]}}function sg(e,t){var n=og(e),r=n.sizes,i=n.centers,a=Kr(Fu(t,[1,0])),o=rl(pl(dc(rl(a[2],q(5))),r[0]),q(2)),s=$c(pl(rl(a[0],q(10)),r[0]),i[0]),c=rl(pl(dc(rl(a[3],q(5))),r[1]),q(2)),l=$c(pl(rl(a[1],q(10)),r[1]),i[1]);return Fu(Ur([vl(s,o),vl(l,c),$c(s,o),$c(l,c)]),[1,0])}function cg(e,t,n){return W(function(){var r=e.shape[0],i=sg(Br(Wr(n.extra_dim,[r,1,1]),[-1,4]),Br(e,[-1,4]));i=Br(i,[r,i.shape[0]/r,4]);var a=fu(xc(fu(t,[0,0,1],[-1,-1,-1])),[0,0,0],[-1,-1,1]);return a=Br(a,[r,a.shape[1]]),{boxes:Kr(i),scores:Kr(a)}})}function lg(e,t){return W(function(){var n=e.shape[0];return{boxPredictionEncoding:Br(Hm(e,t.box_encoding_predictor),[n,-1,1,4]),classPrediction:Br(Hm(e,t.class_predictor),[n,-1,3])}})}function ug(e,t,n){return W(function(){var r=$h($h(e,n.conv_0,[1,1]),n.conv_1,[2,2]),i=$h($h(r,n.conv_2,[1,1]),n.conv_3,[2,2]),a=$h($h(i,n.conv_4,[1,1]),n.conv_5,[2,2]),o=$h($h(a,n.conv_6,[1,1]),n.conv_7,[2,2]),s=lg(t,n.box_predictor_0),c=lg(e,n.box_predictor_1),l=lg(r,n.box_predictor_2),u=lg(i,n.box_predictor_3),d=lg(a,n.box_predictor_4),f=lg(o,n.box_predictor_5);return{boxPredictions:nr([s.boxPredictionEncoding,c.boxPredictionEncoding,l.boxPredictionEncoding,u.boxPredictionEncoding,d.boxPredictionEncoding,f.boxPredictionEncoding],1),classPredictions:nr([s.classPrediction,c.classPrediction,l.classPrediction,u.classPrediction,d.classPrediction,f.classPrediction],1)}})}var dg=function(){function e(e){var t=e===void 0?{}:e,n=t.minConfidence,r=t.maxResults;if(this._name=`SsdMobilenetv1Options`,this._minConfidence=n||.5,this._maxResults=r||100,typeof this._minConfidence!=`number`||this._minConfidence<=0||this._minConfidence>=1)throw Error(this._name+` - expected minConfidence to be a number between 0 and 1`);if(typeof this._maxResults!=`number`)throw Error(this._name+` - expected maxResults to be a number`)}return Object.defineProperty(e.prototype,`minConfidence`,{get:function(){return this._minConfidence},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`maxResults`,{get:function(){return this._maxResults},enumerable:!0,configurable:!0}),e}(),fg=function(e){Z(t,e);function t(){return e.call(this,`SsdMobilenetv1`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`SsdMobilenetv1 - load model before inference`);return W(function(){var n=rg(vl(pl(e.toBatchTensor(512,!1).toFloat(),q(.007843137718737125)),q(1)),t.mobilenetv1),r=ug(n.out,n.conv11,t.prediction_layer),i=r.boxPredictions,a=r.classPredictions;return cg(i,a,t.output_layer)})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,jm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.locateFaces=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S;return $(this,function(C){switch(C.label){case 0:return n=new dg(t),r=n.maxResults,i=n.minConfidence,[4,jm(e)];case 1:for(a=C.sent(),o=this.forwardInput(a),s=o.boxes,c=o.scores,l=s[0],u=c[0],d=1;d<s.length;d++)s[d].dispose(),c[d].dispose();return m=(p=Array).from,[4,u.data()];case 2:return f=m.apply(p,[C.sent()]),h=.5,g=ig(l,f,r,h,i),_=a.getReshapedInputDimensions(0),v=a.inputSize,y=v/_.width,b=v/_.height,x=l.arraySync(),S=g.map(function(e){var t=[Math.max(0,x[e][0]),Math.min(1,x[e][2])].map(function(e){return e*b}),n=t[0],r=t[1],i=[Math.max(0,x[e][1]),Math.min(1,x[e][3])].map(function(e){return e*y}),o=i[0],s=i[1];return new Bp(f[e],new qp(o,n,s-o,r-n),{height:a.getInputHeight(0),width:a.getInputWidth(0)})}),l.dispose(),u.dispose(),[2,S]}})})},t.prototype.getDefaultModelName=function(){return`ssd_mobilenetv1_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Qh(e)},t.prototype.extractParams=function(e){return Xh(e)},t}(Rm);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t})(fg);var pg=.4,mg=[new Ip(.738768,.874946),new Ip(2.42204,2.65704),new Ip(4.30971,7.04493),new Ip(10.246,4.59428),new Ip(12.6868,11.8741)],hg=[new Ip(1.603231,2.094468),new Ip(6.041143,7.080126),new Ip(2.882459,3.518061),new Ip(4.266906,5.178857),new Ip(9.041765,10.66308)],gg=[117.001,114.697,97.404],_g=`tiny_yolov2_model`,vg=`tiny_yolov2_separable_conv_model`,yg=function(e){return typeof e==`number`};function bg(e){if(!e)throw Error(`invalid config: `+e);if(typeof e.withSeparableConvs!=`boolean`)throw Error(`config.withSeparableConvs has to be a boolean, have: `+e.withSeparableConvs);if(!yg(e.iouThreshold)||e.iouThreshold<0||e.iouThreshold>1)throw Error(`config.iouThreshold has to be a number between [0, 1], have: `+e.iouThreshold);if(!Array.isArray(e.classes)||!e.classes.length||!e.classes.every(function(e){return typeof e==`string`}))throw Error(`config.classes has to be an array class names: string[], have: `+JSON.stringify(e.classes));if(!Array.isArray(e.anchors)||!e.anchors.length||!e.anchors.map(function(e){return e||{}}).every(function(e){return yg(e.x)&&yg(e.y)}))throw Error(`config.anchors has to be an array of { x: number, y: number }, have: `+JSON.stringify(e.anchors));if(e.meanRgb&&(!Array.isArray(e.meanRgb)||e.meanRgb.length!==3||!e.meanRgb.every(yg)))throw Error(`config.meanRgb has to be an array of shape [number, number, number], have: `+JSON.stringify(e.meanRgb))}function xg(e){return W(function(){var t=pl(e,q(.10000000149011612));return $c(Mu(vl(e,t)),t)})}function Sg(e,t){return W(function(){var n=jr(e,[[0,0],[1,1],[1,1],[0,0]]);return n=Vl(n,t.conv.filters,[1,1],`valid`),n=vl(n,t.bn.sub),n=pl(n,t.bn.truediv),n=$c(n,t.conv.bias),xg(n)})}function Cg(e,t){return W(function(){var n=jr(e,[[0,0],[1,1],[1,1],[0,0]]);return n=Jl(n,t.depthwise_filter,t.pointwise_filter,[1,1],`valid`),n=$c(n,t.bias),xg(n)})}function wg(e,t){var n=Wm(e,t);function r(n,r){var i=Hn(e(n)),a=Hn(e(n));return t.push({paramPath:r+`/sub`},{paramPath:r+`/truediv`}),{sub:i,truediv:a}}function i(e,t,i){return{conv:n(e,t,3,i+`/conv`),bn:r(t,i+`/bn`)}}return{extractConvParams:n,extractConvWithBatchNormParams:i,extractSeparableConvParams:qm(e,t)}}function Tg(e,t,n,r){var i=Xm(e),a=i.extractWeights,o=i.getRemainingWeights,s=[],c=wg(a,s),l=c.extractConvParams,u=c.extractConvWithBatchNormParams,d=c.extractSeparableConvParams,f;if(t.withSeparableConvs){var p=r[0],m=r[1],h=r[2],g=r[3],_=r[4],v=r[5],y=r[6],b=r[7],x=r[8],S=t.isFirstLayerConv2d?l(p,m,3,`conv0`):d(p,m,`conv0`),C=d(m,h,`conv1`),w=d(h,g,`conv2`),T=d(g,_,`conv3`),E=d(_,v,`conv4`),D=d(v,y,`conv5`),O=b?d(y,b,`conv6`):void 0,k=x?d(b,x,`conv7`):void 0,A=l(x||b||y,5*n,1,`conv8`);f={conv0:S,conv1:C,conv2:w,conv3:T,conv4:E,conv5:D,conv6:O,conv7:k,conv8:A}}else{var p=r[0],m=r[1],h=r[2],g=r[3],_=r[4],v=r[5],y=r[6],b=r[7],x=r[8],S=u(p,m,`conv0`),C=u(m,h,`conv1`),w=u(h,g,`conv2`),T=u(g,_,`conv3`),E=u(_,v,`conv4`),D=u(v,y,`conv5`),O=u(y,b,`conv6`),k=u(b,x,`conv7`),A=l(x,5*n,1,`conv8`);f={conv0:S,conv1:C,conv2:w,conv3:T,conv4:E,conv5:D,conv6:O,conv7:k,conv8:A}}if(o().length!==0)throw Error(`weights remaing after extract: `+o().length);return{params:f,paramMappings:s}}function Eg(e,t){var n=Ym(e,t);function r(e){return{sub:n(e+`/sub`,1),truediv:n(e+`/truediv`,1)}}function i(e){return{filters:n(e+`/filters`,4),bias:n(e+`/bias`,1)}}function a(e){return{conv:i(e+`/conv`),bn:r(e+`/bn`)}}return{extractConvParams:i,extractConvWithBatchNormParams:a,extractSeparableConvParams:Jm(n)}}function Dg(e,t){var n=[],r=Eg(e,n),i=r.extractConvParams,a=r.extractConvWithBatchNormParams,o=r.extractSeparableConvParams,s;if(t.withSeparableConvs){var c=t.filterSizes&&t.filterSizes.length||9;s={conv0:t.isFirstLayerConv2d?i(`conv0`):o(`conv0`),conv1:o(`conv1`),conv2:o(`conv2`),conv3:o(`conv3`),conv4:o(`conv4`),conv5:o(`conv5`),conv6:c>7?o(`conv6`):void 0,conv7:c>8?o(`conv7`):void 0,conv8:i(`conv8`)}}else s={conv0:a(`conv0`),conv1:a(`conv1`),conv2:a(`conv2`),conv3:a(`conv3`),conv4:a(`conv4`),conv5:a(`conv5`),conv6:a(`conv6`),conv7:a(`conv7`),conv8:i(`conv8`)};return Um(e,n),{params:s,paramMappings:n}}var Og;(function(e){e[e.XS=224]=`XS`,e[e.SM=320]=`SM`,e[e.MD=416]=`MD`,e[e.LG=608]=`LG`})(Og||={});var kg=function(){function e(e){var t=e===void 0?{}:e,n=t.inputSize,r=t.scoreThreshold;if(this._name=`TinyYolov2Options`,this._inputSize=n||416,this._scoreThreshold=r||.5,typeof this._inputSize!=`number`||this._inputSize%32!=0)throw Error(this._name+` - expected inputSize to be a number divisible by 32`);if(typeof this._scoreThreshold!=`number`||this._scoreThreshold<=0||this._scoreThreshold>=1)throw Error(this._name+` - expected scoreThreshold to be a number between 0 and 1`)}return Object.defineProperty(e.prototype,`inputSize`,{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`scoreThreshold`,{get:function(){return this._scoreThreshold},enumerable:!0,configurable:!0}),e}(),Ag=function(e){Z(t,e);function t(t){var n=e.call(this,`TinyYolov2`)||this;return bg(t),n._config=t,n}return Object.defineProperty(t.prototype,`config`,{get:function(){return this._config},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,`withClassScores`,{get:function(){return this.config.withClassScores||this.config.classes.length>1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,`boxEncodingSize`,{get:function(){return 5+(this.withClassScores?this.config.classes.length:0)},enumerable:!0,configurable:!0}),t.prototype.runTinyYolov2=function(e,t){var n=Sg(e,t.conv0);return n=su(n,[2,2],[2,2],`same`),n=Sg(n,t.conv1),n=su(n,[2,2],[2,2],`same`),n=Sg(n,t.conv2),n=su(n,[2,2],[2,2],`same`),n=Sg(n,t.conv3),n=su(n,[2,2],[2,2],`same`),n=Sg(n,t.conv4),n=su(n,[2,2],[2,2],`same`),n=Sg(n,t.conv5),n=su(n,[2,2],[1,1],`same`),n=Sg(n,t.conv6),n=Sg(n,t.conv7),Hm(n,t.conv8,`valid`,!1)},t.prototype.runMobilenet=function(e,t){var n=this.config.isFirstLayerConv2d?xg(Hm(e,t.conv0,`valid`,!1)):Cg(e,t.conv0);return n=su(n,[2,2],[2,2],`same`),n=Cg(n,t.conv1),n=su(n,[2,2],[2,2],`same`),n=Cg(n,t.conv2),n=su(n,[2,2],[2,2],`same`),n=Cg(n,t.conv3),n=su(n,[2,2],[2,2],`same`),n=Cg(n,t.conv4),n=su(n,[2,2],[2,2],`same`),n=Cg(n,t.conv5),n=su(n,[2,2],[1,1],`same`),n=t.conv6?Cg(n,t.conv6):n,n=t.conv7?Cg(n,t.conv7):n,Hm(n,t.conv8,`valid`,!1)},t.prototype.forwardInput=function(e,t){var n=this,r=this.params;if(!r)throw Error(`TinyYolov2 - load model before inference`);return W(function(){var i=e.toBatchTensor(t,!1).toFloat();return i=n.config.meanRgb?Wp(i,n.config.meanRgb):i,i=i.div(q(256)),n.config.withSeparableConvs?n.runMobilenet(i,r):n.runTinyYolov2(i,r)})},t.prototype.forward=function(e,t){return Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return n=this.forwardInput,[4,jm(e)];case 1:return[4,n.apply(this,[r.sent(),t])];case 2:return[2,r.sent()]}})})},t.prototype.detect=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c,l,u,d,f,p,m,h,g=this;return $(this,function(_){switch(_.label){case 0:return n=new kg(t),r=n.inputSize,i=n.scoreThreshold,[4,jm(e)];case 1:return a=_.sent(),[4,this.forwardInput(a,r)];case 2:return o=_.sent(),s=W(function(){return Kr(o)[0].expandDims()}),c={width:a.getInputWidth(0),height:a.getInputHeight(0)},[4,this.extractBoxes(s,a.getReshapedInputDimensions(0),i)];case 3:return l=_.sent(),o.dispose(),s.dispose(),u=l.map(function(e){return e.box}),d=l.map(function(e){return e.score}),f=l.map(function(e){return e.classScore}),p=l.map(function(e){return g.config.classes[e.label]}),m=Up(u.map(function(e){return e.rescale(r)}),d,this.config.iouThreshold,!0),h=m.map(function(e){return new zp(d[e],f[e],p[e],u[e],c)}),[2,h]}})})},t.prototype.getDefaultModelName=function(){return``},t.prototype.extractParamsFromWeigthMap=function(e){return Dg(e,this.config)},t.prototype.extractParams=function(e){var n=this.config.filterSizes||t.DEFAULT_FILTER_SIZES,r=n?n.length:void 0;if(r!==7&&r!==8&&r!==9)throw Error(`TinyYolov2 - expected 7 | 8 | 9 convolutional filters, but found `+r+` filterSizes in config`);return Tg(e,this.config,this.boxEncodingSize,n)},t.prototype.extractBoxes=function(e,t,n){return Q(this,void 0,void 0,function(){var r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M=this;return $(this,function(N){switch(N.label){case 0:return r=t.width,i=t.height,a=Math.max(r,i),o=a/r,s=a/i,c=e.shape[1],l=this.config.anchors.length,u=W(function(){var t=e.reshape([c,c,l,M.boxEncodingSize]);return[t.slice([0,0,0,0],[c,c,l,4]),t.slice([0,0,0,4],[c,c,l,1]),M.withClassScores?mi(t.slice([0,0,0,5],[c,c,l,M.config.classes.length]),3):q(0)]}),d=u[0],f=u[1],p=u[2],m=[],[4,f.array()];case 1:return h=N.sent(),[4,d.array()];case 2:g=N.sent(),_=0,N.label=3;case 3:if(!(_<c))return[3,12];v=0,N.label=4;case 4:if(!(v<c))return[3,11];y=0,N.label=5;case 5:return y<l?(b=Kp(h[_][v][y][0]),!n||b>n?(x=(v+Kp(g[_][v][y][0]))/c*o,S=(_+Kp(g[_][v][y][1]))/c*s,C=Math.exp(g[_][v][y][2])*this.config.anchors[y].x/c*o,w=Math.exp(g[_][v][y][3])*this.config.anchors[y].y/c*s,T=x-C/2,E=S-w/2,D={row:_,col:v,anchor:y},this.withClassScores?[4,this.extractPredictedClass(p,D)]:[3,7]):[3,9]):[3,10];case 6:return j=N.sent(),[3,8];case 7:j={classScore:1,label:0},N.label=8;case 8:O=j,k=O.classScore,A=O.label,m.push(bp({box:new Rp(T,E,T+C,E+w),score:b,classScore:b*k,label:A},D)),N.label=9;case 9:return y++,[3,5];case 10:return v++,[3,4];case 11:return _++,[3,3];case 12:return d.dispose(),f.dispose(),p.dispose(),[2,m]}})})},t.prototype.extractPredictedClass=function(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a;return $(this,function(o){switch(o.label){case 0:return n=t.row,r=t.col,i=t.anchor,[4,e.array()];case 1:return a=o.sent(),[2,Array(this.config.classes.length).fill(0).map(function(e,t){return a[n][r][i][t]}).map(function(e,t){return{classScore:e,label:t}}).reduce(function(e,t){return e.classScore>t.classScore?e:t})]}})})},t.DEFAULT_FILTER_SIZES=[3,16,32,64,128,256,512,1024,1024],t}(Rm),jg=function(e){Z(t,e);function t(t){t===void 0&&(t=!0);var n=this,r=Object.assign({},{withSeparableConvs:t,iouThreshold:pg,classes:[`face`]},t?{anchors:hg,meanRgb:gg}:{anchors:mg,withClassScores:!0});return n=e.call(this,r)||this,n}return Object.defineProperty(t.prototype,`withSeparableConvs`,{get:function(){return this.config.withSeparableConvs},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,`anchors`,{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),t.prototype.locateFaces=function(e,t){return Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return[4,this.detect(e,t)];case 1:return n=r.sent(),[2,n.map(function(e){return new Bp(e.score,e.relativeBox,{width:e.imageWidth,height:e.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return this.withSeparableConvs?vg:_g},t.prototype.extractParamsFromWeigthMap=function(t){return e.prototype.extractParamsFromWeigthMap.call(this,t)},t}(Ag),Mg=function(e){Z(t,e);function t(){var t=e!==null&&e.apply(this,arguments)||this;return t._name=`TinyFaceDetectorOptions`,t}return t}(kg),Ng=function(){function e(){}return e.prototype.then=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=e,[4,this.run()];case 1:return[2,t.apply(void 0,[n.sent()])]}})})},e.prototype.run=function(){return Q(this,void 0,void 0,function(){return $(this,function(e){throw Error(`ComposableTask - run is not implemented`)})})},e}();function Pg(e,t,n,r,i){return i===void 0&&(i=function(e){return e.alignedRect}),Q(this,void 0,void 0,function(){var a,o,s,c,l;return $(this,function(u){switch(u.label){case 0:return a=e.map(function(e){return fh(e)?i(e):e.detection}),s=r,s?[3,5]:t instanceof $e?[4,Nm(t,a)]:[3,2];case 1:return c=u.sent(),[3,4];case 2:return[4,Mm(t,a)];case 3:c=u.sent(),u.label=4;case 4:s=c,u.label=5;case 5:return o=s,[4,n(o)];case 6:return l=u.sent(),o.forEach(function(e){return e instanceof $e&&e.dispose()}),[2,l]}})})}function Fg(e,t,n,r,i){return Q(this,void 0,void 0,function(){var a=this;return $(this,function(o){return[2,Pg([e],t,function(e){return Q(a,void 0,void 0,function(){return $(this,function(t){return[2,n(e[0])]})})},r,i)]})})}function Ig(e){return W(function(){return Ur(Kr(e,3).reverse(),3)})}function Lg(e,t){var n=Wm(e,t),r=Gm(e,t);function i(n,r){var i=Hn(e(n));return t.push({paramPath:r}),i}function a(e,t,r){return r===void 0&&(r=!1),{conv1:n(e[0],e[1],3,t+`/conv1`),prelu1_alpha:i(e[1],t+`/prelu1_alpha`),conv2:n(e[1],e[2],3,t+`/conv2`),prelu2_alpha:i(e[2],t+`/prelu2_alpha`),conv3:n(e[2],e[3],r?2:3,t+`/conv3`),prelu3_alpha:i(e[3],t+`/prelu3_alpha`)}}function o(){var e=a([3,10,16,32],`pnet`),t=n(32,2,1,`pnet/conv4_1`),r=n(32,4,1,`pnet/conv4_2`);return bp(bp({},e),{conv4_1:t,conv4_2:r})}function s(){var e=a([3,28,48,64],`rnet`,!0),t=r(576,128,`rnet/fc1`),n=i(128,`rnet/prelu4_alpha`),o=r(128,2,`rnet/fc2_1`),s=r(128,4,`rnet/fc2_2`);return bp(bp({},e),{fc1:t,prelu4_alpha:n,fc2_1:o,fc2_2:s})}function c(){var e=a([3,32,64,64],`onet`),t=n(64,128,2,`onet/conv4`),o=i(128,`onet/prelu4_alpha`),s=r(1152,256,`onet/fc1`),c=i(256,`onet/prelu5_alpha`),l=r(256,2,`onet/fc2_1`),u=r(256,4,`onet/fc2_2`),d=r(256,10,`onet/fc2_3`);return bp(bp({},e),{conv4:t,prelu4_alpha:o,fc1:s,prelu5_alpha:c,fc2_1:l,fc2_2:u,fc2_3:d})}return{extractPNetParams:o,extractRNetParams:s,extractONetParams:c}}function Rg(e){var t=Xm(e),n=t.extractWeights,r=t.getRemainingWeights,i=[],a=Lg(n,i),o=a.extractPNetParams,s=a.extractRNetParams,c=a.extractONetParams,l=o(),u=s(),d=c();if(r().length!==0)throw Error(`weights remaing after extract: `+r().length);return{params:{pnet:l,rnet:u,onet:d},paramMappings:i}}function zg(e,t){var n=Ym(e,t);function r(e){return{filters:n(e+`/weights`,4,e+`/filters`),bias:n(e+`/bias`,1)}}function i(e){return{weights:n(e+`/weights`,2),bias:n(e+`/bias`,1)}}function a(e){return n(e,1)}function o(e){return{conv1:r(e+`/conv1`),prelu1_alpha:a(e+`/prelu1_alpha`),conv2:r(e+`/conv2`),prelu2_alpha:a(e+`/prelu2_alpha`),conv3:r(e+`/conv3`),prelu3_alpha:a(e+`/prelu3_alpha`)}}function s(){var e=o(`pnet`),t=r(`pnet/conv4_1`),n=r(`pnet/conv4_2`);return bp(bp({},e),{conv4_1:t,conv4_2:n})}function c(){var e=o(`rnet`),t=i(`rnet/fc1`),n=a(`rnet/prelu4_alpha`),r=i(`rnet/fc2_1`),s=i(`rnet/fc2_2`);return bp(bp({},e),{fc1:t,prelu4_alpha:n,fc2_1:r,fc2_2:s})}function l(){var e=o(`onet`),t=r(`onet/conv4`),n=a(`onet/prelu4_alpha`),s=i(`onet/fc1`),c=a(`onet/prelu5_alpha`),l=i(`onet/fc2_1`),u=i(`onet/fc2_2`),d=i(`onet/fc2_3`);return bp(bp({},e),{conv4:t,prelu4_alpha:n,fc1:s,prelu5_alpha:c,fc2_1:l,fc2_2:u,fc2_3:d})}return{extractPNetParams:s,extractRNetParams:c,extractONetParams:l}}function Bg(e){var t=[],n=zg(e,t),r=n.extractPNetParams,i=n.extractRNetParams,a=n.extractONetParams,o=r(),s=i(),c=a();return Um(e,t),{params:{pnet:o,rnet:s,onet:c},paramMappings:t}}function Vg(e,t){var n=t[0],r=t[1];return{height:Math.floor(n*e),width:Math.floor(r*e)}}function Hg(e,t,n){for(var r=n[0],i=n[1],a=12/e,o=[],s=Math.min(r,i)*a,c=0;s>=12;)o.push(a*t**+c),s*=t,c+=1;return o}var Ug=function(e){Z(t,e);function t(t,n,r,i){return e.call(this,{left:t,top:n,right:r,bottom:i},!0)||this}return t}(Lp);function Wg(e){return W(function(){return pl(vl(e,q(127.5)),q(.0078125))})}function Gg(e,t){return W(function(){return $c(Mu(e),pl(t,_c(Mu(_c(e)))))})}function Kg(e,t,n){return n===void 0&&(n=!1),W(function(){var r=Hm(e,t.conv1,`valid`);return r=Gg(r,t.prelu1_alpha),r=su(r,n?[2,2]:[3,3],[2,2],`same`),r=Hm(r,t.conv2,`valid`),r=Gg(r,t.prelu2_alpha),r=n?r:su(r,[3,3],[2,2],`valid`),r=Hm(r,t.conv3,`valid`),r=Gg(r,t.prelu3_alpha),r})}function qg(e,t){return W(function(){var n=Kg(e,t,!0),r=Hm(n,t.conv4_1,`valid`);return{prob:mi(vl(r,Dr(Cu(r,3),3)),3),regions:Hm(n,t.conv4_2,`valid`)}})}function Jg(e,t){return W(function(){var n=Vg(t,e.shape.slice(1)),r=n.height,i=n.width;return Fu(Wg(Ad.resizeBilinear(e,[r,i])),[0,2,1,3])})}function Yg(e,t,n,r){for(var i=[],a=e.arraySync(),o=0;o<e.shape[0];o++)for(var s=0;s<e.shape[1];s++)a[o][s]>=r&&i.push(new Ip(s,o));return i.map(function(e){var r=new Rp(Math.round((e.y*2+1)/n),Math.round((e.x*2+1)/n),Math.round((e.y*2+12)/n),Math.round((e.x*2+12)/n)),i=a[e.y][e.x],o=t.arraySync();return{cell:r,score:i,region:new Ug(o[e.y][e.x][0],o[e.y][e.x][1],o[e.y][e.x][2],o[e.y][e.x][3])}})}function Xg(e,t,n,r,i){i.stage1=[];var a=t.map(function(t){return W(function(){var n={scale:t},i=Jg(e,t),a=Date.now(),o=qg(i,r),s=o.prob,c=o.regions;return n.pnet=Date.now()-a,{scoresTensor:Kr(Kr(s,3)[1])[0],regionsTensor:Kr(c)[0],scale:t,statsForScale:n}})}).map(function(e){var t=e.scoresTensor,r=e.regionsTensor,a=e.scale,o=e.statsForScale,s=Yg(t,r,a,n);if(t.dispose(),r.dispose(),!s.length)return i.stage1.push(o),[];var c=Date.now(),l=Up(s.map(function(e){return e.cell}),s.map(function(e){return e.score}),.5);return o.nms=Date.now()-c,o.numBoxes=l.length,i.stage1.push(o),l.map(function(e){return s[e]})}).reduce(function(e,t){return e.concat(t)},[]),o=[],s=[];if(a.length>0){var c=Date.now(),l=Up(a.map(function(e){return e.cell}),a.map(function(e){return e.score}),.7);i.stage1_nms=Date.now()-c,s=l.map(function(e){return a[e].score}),o=l.map(function(e){return a[e]}).map(function(e){var t=e.cell,n=e.region;return new Rp(t.left+n.left*t.width,t.top+n.top*t.height,t.right+n.right*t.width,t.bottom+n.bottom*t.height).toSquare().round()})}return{boxes:o,scores:s}}function Zg(e,t,n){var r=n.width,i=n.height;return Q(this,void 0,void 0,function(){var n,a,o,s=this;return $(this,function(c){switch(c.label){case 0:return n=_m(e),[4,Promise.all(t.map(function(t){return Q(s,void 0,void 0,function(){var r,i,a,o,s,c,l,u;return $(this,function(d){return r=t.padAtBorders(e.height,e.width),i=r.y,a=r.ey,o=r.x,s=r.ex,c=o-1,l=i-1,u=n.getImageData(c,l,s-c,a-l),[2,hm.isNodejs()?Em(u):createImageBitmap(u)]})})}))];case 1:return a=c.sent(),o=[],a.forEach(function(e){var t=_m(Tm({width:r,height:i}));t.drawImage(e,0,0,r,i);for(var n=t.getImageData(0,0,r,i).data,a=[],s=0;s<n.length;s+=4)a.push(n[s+2]),a.push(n[s+1]),a.push(n[s]);o.push(a)}),[2,o.map(function(e){return W(function(){return Wg(Fu(Gn(e,[1,r,i,3]),[0,2,1,3]).toFloat())})})]}})})}function Qg(e,t){return W(function(){var n=Kg(e,t),r=Gg(rh(Br(n,[n.shape[0],t.fc1.weights.shape[0]]),t.fc1),t.prelu4_alpha),i=rh(r,t.fc2_1),a=mi(vl(i,Dr(Cu(i,1),1)),1),o=rh(r,t.fc2_2);return{scores:Kr(a,1)[1],regions:o}})}function $g(e,t,n,r,i){return Q(this,void 0,void 0,function(){var a,o,s,c,l,u,d,f,p,m,h,g,_,v;return $(this,function(y){switch(y.label){case 0:return a=Date.now(),[4,Zg(e,t,{width:24,height:24})];case 1:return o=y.sent(),i.stage2_extractImagePatches=Date.now()-a,a=Date.now(),s=o.map(function(e){var t=Qg(e,r);return e.dispose(),t}),i.stage2_rnet=Date.now()-a,c=s.length>1?nr(s.map(function(e){return e.scores})):s[0].scores,d=(u=Array).from,[4,c.data()];case 2:return l=d.apply(u,[y.sent()]),c.dispose(),f=l.map(function(e,t){return{score:e,idx:t}}).filter(function(e){return e.score>n}).map(function(e){return e.idx}),p=f.map(function(e){return t[e]}),m=f.map(function(e){return l[e]}),h=[],g=[],p.length>0&&(a=Date.now(),_=Up(p,m,.7),i.stage2_nms=Date.now()-a,v=_.map(function(e){var t=s[f[e]].regions.arraySync();return new Ug(t[0][0],t[0][1],t[0][2],t[0][3])}),g=_.map(function(e){return m[e]}),h=_.map(function(e,t){return p[e].calibrate(v[t])})),s.forEach(function(e){e.regions.dispose(),e.scores.dispose()}),[2,{boxes:h,scores:g}]}})})}function e_(e,t){return W(function(){var n=Kg(e,t);n=su(n,[2,2],[2,2],`same`),n=Hm(n,t.conv4,`valid`),n=Gg(n,t.prelu4_alpha);var r=Gg(rh(Br(n,[n.shape[0],t.fc1.weights.shape[0]]),t.fc1),t.prelu5_alpha),i=rh(r,t.fc2_1),a=mi(vl(i,Dr(Cu(i,1),1)),1),o=rh(r,t.fc2_2),s=rh(r,t.fc2_3);return{scores:Kr(a,1)[1],regions:o,points:s}})}function t_(e,t,n,r,i){return Q(this,void 0,void 0,function(){var a,o,s,c,l,u,d,f,p,m,h,g,_,v,y;return $(this,function(b){switch(b.label){case 0:return a=Date.now(),[4,Zg(e,t,{width:48,height:48})];case 1:return o=b.sent(),i.stage3_extractImagePatches=Date.now()-a,a=Date.now(),s=o.map(function(e){var t=e_(e,r);return e.dispose(),t}),i.stage3_onet=Date.now()-a,c=s.length>1?nr(s.map(function(e){return e.scores})):s[0].scores,d=(u=Array).from,[4,c.data()];case 2:return l=d.apply(u,[b.sent()]),c.dispose(),f=l.map(function(e,t){return{score:e,idx:t}}).filter(function(e){return e.score>n}).map(function(e){return e.idx}),p=f.map(function(e){var t=s[e].regions.arraySync();return new Ug(t[0][0],t[0][1],t[0][2],t[0][3])}),m=f.map(function(e,n){return t[e].calibrate(p[n])}),h=f.map(function(e){return l[e]}),g=[],_=[],v=[],m.length>0&&(a=Date.now(),y=Up(m,h,.7,!1),i.stage3_nms=Date.now()-a,g=y.map(function(e){return m[e]}),_=y.map(function(e){return h[e]}),v=y.map(function(e,t){return[,,,,,].fill(0).map(function(n,r){var i=s[e].points.arraySync();return new Ip(i[0][r]*(g[t].width+1)+g[t].left,i[0][r+5]*(g[t].height+1)+g[t].top)})})),s.forEach(function(e){e.regions.dispose(),e.scores.dispose(),e.points.dispose()}),[2,{boxes:g,scores:_,points:v}]}})})}var n_=function(e){Z(t,e);function t(){return e.call(this,`Mtcnn`)||this}return t.prototype.load=function(t){return Q(this,void 0,void 0,function(){return $(this,function(n){return console.warn(`mtcnn is deprecated and will be removed soon`),[2,e.prototype.load.call(this,t)]})})},t.prototype.loadFromDisk=function(t){return Q(this,void 0,void 0,function(){return $(this,function(n){return console.warn(`mtcnn is deprecated and will be removed soon`),[2,e.prototype.loadFromDisk.call(this,t)]})})},t.prototype.forwardInput=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S;return $(this,function(C){switch(C.label){case 0:if(n=this.params,!n)throw Error(`Mtcnn - load model before inference`);if(r=e.canvases[0],!r)throw Error(`Mtcnn - inputCanvas is not defined, note that passing tensors into Mtcnn.forwardInput is not supported yet.`);return i={},a=Date.now(),o=W(function(){return Ig(Dr(ep.fromPixels(r)).toFloat())}),s=function(e){return o.dispose(),i.total=Date.now()-a,e},c=o.shape.slice(1),l=c[0],u=c[1],d=new Jh(t),f=d.minFaceSize,p=d.scaleFactor,m=d.maxNumScales,h=d.scoreThresholds,g=d.scaleSteps,_=(g||Hg(f,p,[l,u])).filter(function(e){var t=Vg(e,[l,u]);return Math.min(t.width,t.height)>12}).slice(0,m),i.scales=_,i.pyramid=_.map(function(e){return Vg(e,[l,u])}),v=Date.now(),[4,Xg(o,_,h[0],n.pnet,i)];case 1:return y=C.sent(),i.total_stage1=Date.now()-v,y.boxes.length?(i.stage2_numInputBoxes=y.boxes.length,v=Date.now(),[4,$g(r,y.boxes,h[1],n.rnet,i)]):[2,s({results:[],stats:i})];case 2:return b=C.sent(),i.total_stage2=Date.now()-v,b.boxes.length?(i.stage3_numInputBoxes=b.boxes.length,v=Date.now(),[4,t_(r,b.boxes,h[2],n.onet,i)]):[2,s({results:[],stats:i})];case 3:return x=C.sent(),i.total_stage3=Date.now()-v,S=x.boxes.map(function(e,t){return ph(im({},new Bp(x.scores[t],new qp(e.left/u,e.top/l,e.width/u,e.height/l),{height:l,width:u})),new Qp(x.points[t].map(function(t){return t.sub(new Ip(e.left,e.top)).div(new Ip(e.width,e.height))}),{width:e.width,height:e.height}))}),[2,s({results:S,stats:i})]}})})},t.prototype.forward=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return n=this.forwardInput,[4,jm(e)];case 1:return[4,n.apply(this,[r.sent(),t])];case 2:return[2,r.sent().results]}})})},t.prototype.forwardWithStats=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return n=this.forwardInput,[4,jm(e)];case 1:return[2,n.apply(this,[r.sent(),t])]}})})},t.prototype.getDefaultModelName=function(){return`mtcnn_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Bg(e)},t.prototype.extractParams=function(e){return Rg(e)},t}(Rm),r_=.4,i_=[new Ip(1.603231,2.094468),new Ip(6.041143,7.080126),new Ip(2.882459,3.518061),new Ip(4.266906,5.178857),new Ip(9.041765,10.66308)],a_=[117.001,114.697,97.404],o_=function(e){Z(t,e);function t(){var t=this,n={withSeparableConvs:!0,iouThreshold:r_,classes:[`face`],anchors:i_,meanRgb:a_,isFirstLayerConv2d:!0,filterSizes:[3,16,32,64,128,256,512]};return t=e.call(this,n)||this,t}return Object.defineProperty(t.prototype,`anchors`,{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),t.prototype.locateFaces=function(e,t){return Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return[4,this.detect(e,t)];case 1:return n=r.sent(),[2,n.map(function(e){return new Bp(e.score,e.relativeBox,{width:e.imageWidth,height:e.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return`tiny_face_detector_model`},t.prototype.extractParamsFromWeigthMap=function(t){return e.prototype.extractParamsFromWeigthMap.call(this,t)},t}(Ag),s_={ssdMobilenetv1:new fg,tinyFaceDetector:new o_,tinyYolov2:new jg,mtcnn:new n_,faceLandmark68Net:new Oh,faceLandmark68TinyNet:new Mh,faceRecognitionNet:new Wh,faceExpressionNet:new uh,ageGenderNet:new Eh},c_=function(e){Z(t,e);function t(t,n,r){var i=e.call(this)||this;return i.parentTask=t,i.input=n,i.extractedFaces=r,i}return t}(Ng),l_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n=this;return $(this,function(r){switch(r.label){case 0:return[4,this.parentTask];case 1:return e=r.sent(),[4,Pg(e,this.input,function(e){return Q(n,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,Promise.all(e.map(function(e){return s_.faceExpressionNet.predictExpressions(e)}))];case 1:return[2,t.sent()]}})})},this.extractedFaces)];case 2:return t=r.sent(),[2,e.map(function(e,n){return dh(e,t[n])})]}})})},t.prototype.withAgeAndGender=function(){return new m_(this,this.input)},t}(c_),u_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,this.parentTask];case 1:return e=n.sent(),e?[4,Fg(e,this.input,function(e){return s_.faceExpressionNet.predictExpressions(e)},this.extractedFaces)]:[2];case 2:return t=n.sent(),[2,dh(e,t)]}})})},t.prototype.withAgeAndGender=function(){return new h_(this,this.input)},t}(c_),d_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new g_(this,this.input)},t.prototype.withFaceDescriptors=function(){return new y_(this,this.input)},t}(l_),f_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new __(this,this.input)},t.prototype.withFaceDescriptor=function(){return new b_(this,this.input)},t}(u_),p_=function(e){Z(t,e);function t(t,n,r){var i=e.call(this)||this;return i.parentTask=t,i.input=n,i.extractedFaces=r,i}return t}(Ng),m_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n=this;return $(this,function(r){switch(r.label){case 0:return[4,this.parentTask];case 1:return e=r.sent(),[4,Pg(e,this.input,function(e){return Q(n,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,Promise.all(e.map(function(e){return s_.ageGenderNet.predictAgeAndGender(e)}))];case 1:return[2,t.sent()]}})})},this.extractedFaces)];case 2:return t=r.sent(),[2,e.map(function(e,n){var r=t[n],i=r.age,a=r.gender,o=r.genderProbability;return Kh(qh(e,a,o),i)})]}})})},t.prototype.withFaceExpressions=function(){return new l_(this,this.input)},t}(p_),h_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r,i;return $(this,function(a){switch(a.label){case 0:return[4,this.parentTask];case 1:return e=a.sent(),e?[4,Fg(e,this.input,function(e){return s_.ageGenderNet.predictAgeAndGender(e)},this.extractedFaces)]:[2];case 2:return t=a.sent(),n=t.age,r=t.gender,i=t.genderProbability,[2,Kh(qh(e,r,i),n)]}})})},t.prototype.withFaceExpressions=function(){return new u_(this,this.input)},t}(p_),g_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new d_(this,this.input)},t.prototype.withFaceDescriptors=function(){return new y_(this,this.input)},t}(m_),__=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new f_(this,this.input)},t.prototype.withFaceDescriptor=function(){return new b_(this,this.input)},t}(h_),v_=function(e){Z(t,e);function t(t,n){var r=e.call(this)||this;return r.parentTask=t,r.input=n,r}return t}(Ng),y_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,this.parentTask];case 1:return e=n.sent(),[4,Pg(e,this.input,function(e){return Promise.all(e.map(function(e){return s_.faceRecognitionNet.computeFaceDescriptor(e)}))},null,function(e){return e.landmarks.align(null,{useDlibAlignment:!0})})];case 2:return t=n.sent(),[2,t.map(function(t,n){return Gh(e[n],t)})]}})})},t.prototype.withFaceExpressions=function(){return new d_(this,this.input)},t.prototype.withAgeAndGender=function(){return new g_(this,this.input)},t}(v_),b_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,this.parentTask];case 1:return e=n.sent(),e?[4,Fg(e,this.input,function(e){return s_.faceRecognitionNet.computeFaceDescriptor(e)},null,function(e){return e.landmarks.align(null,{useDlibAlignment:!0})})]:[2];case 2:return t=n.sent(),[2,Gh(e,t)]}})})},t.prototype.withFaceExpressions=function(){return new f_(this,this.input)},t.prototype.withAgeAndGender=function(){return new __(this,this.input)},t}(v_),x_=function(e){Z(t,e);function t(t,n,r){var i=e.call(this)||this;return i.parentTask=t,i.input=n,i.useTinyLandmarkNet=r,i}return Object.defineProperty(t.prototype,`landmarkNet`,{get:function(){return this.useTinyLandmarkNet?s_.faceLandmark68TinyNet:s_.faceLandmark68Net},enumerable:!0,configurable:!0}),t}(Ng),S_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r,i,a=this;return $(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return e=o.sent(),t=e.map(function(e){return e.detection}),this.input instanceof $e?[4,Nm(this.input,t)]:[3,3];case 2:return r=o.sent(),[3,5];case 3:return[4,Mm(this.input,t)];case 4:r=o.sent(),o.label=5;case 5:return n=r,[4,Promise.all(n.map(function(e){return a.landmarkNet.detectLandmarks(e)}))];case 6:return i=o.sent(),n.forEach(function(e){return e instanceof $e&&e.dispose()}),[2,e.map(function(e,t){return ph(e,i[t])})]}})})},t.prototype.withFaceExpressions=function(){return new d_(this,this.input)},t.prototype.withAgeAndGender=function(){return new g_(this,this.input)},t.prototype.withFaceDescriptors=function(){return new y_(this,this.input)},t}(x_),C_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r,i;return $(this,function(a){switch(a.label){case 0:return[4,this.parentTask];case 1:return e=a.sent(),e?(t=e.detection,this.input instanceof $e?[4,Nm(this.input,[t])]:[3,3]):[2];case 2:return r=a.sent(),[3,5];case 3:return[4,Mm(this.input,[t])];case 4:r=a.sent(),a.label=5;case 5:return n=r,[4,this.landmarkNet.detectLandmarks(n[0])];case 6:return i=a.sent(),n.forEach(function(e){return e instanceof $e&&e.dispose()}),[2,ph(e,i)]}})})},t.prototype.withFaceExpressions=function(){return new f_(this,this.input)},t.prototype.withAgeAndGender=function(){return new __(this,this.input)},t.prototype.withFaceDescriptor=function(){return new b_(this,this.input)},t}(x_),w_=function(e){Z(t,e);function t(t,n){n===void 0&&(n=new dg);var r=e.call(this)||this;return r.input=t,r.options=n,r}return t}(Ng),T_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r;return $(this,function(i){switch(i.label){case 0:return e=this,t=e.input,n=e.options,n instanceof Jh?[4,s_.mtcnn.forward(t,n)]:[3,2];case 1:return[2,i.sent().map(function(e){return e.detection})];case 2:if(r=n instanceof Mg?function(e){return s_.tinyFaceDetector.locateFaces(e,n)}:n instanceof dg?function(e){return s_.ssdMobilenetv1.locateFaces(e,n)}:n instanceof kg?function(e){return s_.tinyYolov2.locateFaces(e,n)}:null,!r)throw Error(`detectFaces - expected options to be instance of TinyFaceDetectorOptions | SsdMobilenetv1Options | MtcnnOptions | TinyYolov2Options`);return[2,r(t)]}})})},t.prototype.runAndExtendWithFaceDetections=function(){var e=this;return new Promise(function(t){return Q(e,void 0,void 0,function(){var e;return $(this,function(n){switch(n.label){case 0:return[4,this.run()];case 1:return e=n.sent(),[2,t(e.map(function(e){return im({},e)}))]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new S_(this.runAndExtendWithFaceDetections(),this.input,e)},t.prototype.withFaceExpressions=function(){return new l_(this.runAndExtendWithFaceDetections(),this.input)},t.prototype.withAgeAndGender=function(){return new m_(this.runAndExtendWithFaceDetections(),this.input)},t}(w_);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,new T_(this.input,this.options)];case 1:return e=n.sent(),t=e[0],e.forEach(function(e){e.score>t.score&&(t=e)}),[2,t]}})})},t.prototype.runAndExtendWithFaceDetection=function(){var e=this;return new Promise(function(t){return Q(e,void 0,void 0,function(){var e;return $(this,function(n){switch(n.label){case 0:return[4,this.run()];case 1:return e=n.sent(),[2,t(e?im({},e):void 0)]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new C_(this.runAndExtendWithFaceDetection(),this.input,e)},t.prototype.withFaceExpressions=function(){return new u_(this.runAndExtendWithFaceDetection(),this.input)},t.prototype.withAgeAndGender=function(){return new h_(this.runAndExtendWithFaceDetection(),this.input)},t})(w_);function E_(e,t){return t===void 0&&(t=new dg),new T_(e,t)}function D_(e,t){if(e.length!==t.length)throw Error(`euclideanDistance: arr1.length !== arr2.length`);var n=Array.from(e),r=Array.from(t);return Math.sqrt(n.map(function(e,t){return e-r[t]}).reduce(function(e,t){return e+t**2},0))}(function(){function e(e,t){t===void 0&&(t=.6),this._distanceThreshold=t;var n=Array.isArray(e)?e:[e];if(!n.length)throw Error(`FaceRecognizer.constructor - expected atleast one input`);var r=1,i=function(){return`person `+ r++};this._labeledDescriptors=n.map(function(e){if(e instanceof nm)return e;if(e instanceof Float32Array)return new nm(i(),[e]);if(e.descriptor&&e.descriptor instanceof Float32Array)return new nm(i(),[e.descriptor]);throw Error(`FaceRecognizer.constructor - expected inputs to be of type LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array | Array<LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array>`)})}return Object.defineProperty(e.prototype,`labeledDescriptors`,{get:function(){return this._labeledDescriptors},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`distanceThreshold`,{get:function(){return this._distanceThreshold},enumerable:!0,configurable:!0}),e.prototype.computeMeanDistance=function(e,t){return t.map(function(t){return D_(t,e)}).reduce(function(e,t){return e+t},0)/(t.length||1)},e.prototype.matchDescriptor=function(e){var t=this;return this.labeledDescriptors.map(function(n){var r=n.descriptors,i=n.label;return new em(i,t.computeMeanDistance(e,r))}).reduce(function(e,t){return e.distance<t.distance?e:t})},e.prototype.findBestMatch=function(e){var t=this.matchDescriptor(e);return t.distance<this.distanceThreshold?t:new em(`unknown`,t.distance)},e.prototype.toJSON=function(){return{distanceThreshold:this.distanceThreshold,labeledDescriptors:this.labeledDescriptors.map(function(e){return e.toJSON()})}},e.fromJSON=function(t){return new e(t.labeledDescriptors.map(function(e){return nm.fromJSON(e)}),t.distanceThreshold)},e})();function O_(e){return Math.max(0,Math.min(1,e))}function k_(e){let t=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],s=e[5];return(t(r,s)+t(i,o))/(2*t(n,a))}function A_(e,t,n){return!t||t<=0?e:new Promise((r,i)=>{let a=setTimeout(()=>i(n()),t);e.then(e=>{clearTimeout(a),r(e)},e=>{clearTimeout(a),i(e)})})}function j_(){let e=!1;return{load:async(t,n)=>{if(!e)try{let r=n?.timeoutMs??15e3;await A_(s_.tinyFaceDetector.loadFromUri(t),r,()=>({code:`MODEL_LOAD_TIMEOUT`,message:`Timeout ao carregar modelo TinyFaceDetector em: ${t}`})),await A_(s_.faceLandmark68TinyNet.loadFromUri(t),r,()=>({code:`MODEL_LOAD_TIMEOUT`,message:`Timeout ao carregar modelo faceLandmark68TinyNet em: ${t}`})),e=!0}catch(e){throw e?.code===`MODEL_LOAD_TIMEOUT`?e:{code:`MODEL_LOAD_FAILED`,message:`Falha ao carregar modelos face-api.js em: ${t}`,cause:e}}},detect:async(t,n)=>{if(!e)return{faces:0};let r=new Mg({inputSize:416,scoreThreshold:.45}),i=t.videoWidth||1,a=t.videoHeight||1,o=e=>{let t=e.x/i,n=e.y/a,r=e.width/i,o=e.height/a;return{faces:1,box:{x:t,y:n,width:r,height:o},centerX:O_(t+r/2),area:r*o,poseSource:`bbox`}},s=async()=>{let e=await E_(t,r);return e&&e.length>0?e:await E_(t,r)};if(n?.withLandmarks){let e=[];try{e=await E_(t,r).withFaceLandmarks(!0)}catch{e=[]}if(!e||e.length===0){let e=await s();return!e||e.length===0?{faces:0}:e.length>1?{faces:e.length}:o(e[0].box)}if(e.length>1)return{faces:e.length};let n=e[0].detection.box,c=e[0].landmarks,l=c.getLeftEye(),u=c.getRightEye(),d=c.getNose(),f=c.getJawOutline(),p=c.getMouth(),m=e=>e.map(e=>({x:O_(e.x/i),y:O_(e.y/a)})),h=e=>({x:O_(e.x/i),y:O_(e.y/a)}),g=e=>e.reduce((t,n)=>({x:t.x+n.x/e.length,y:t.y+n.y/e.length}),{x:0,y:0}),_=g(l),v=g(u),y=Math.hypot(_.x-v.x,_.y-v.y),b=g(f),x=d&&d.length>0?d[Math.floor(d.length/2)]:void 0,S=(_.x+v.x)/2,C=x?(x.x-S)/Math.max(1e-6,y):void 0,w=k_(l),T=k_(u),E=e=>O_((e-.16)/.12),D=n.x/i,O=n.y/a,k=n.width/i,A=n.height/a,j=p&&p.length>0?p.reduce((e,t)=>t.x<e.x?t:e,p[0]):void 0,M=p&&p.length>0?p.reduce((e,t)=>t.x>e.x?t:e,p[0]):void 0,N=f&&f.length>0?f[Math.max(0,Math.min(f.length-1,4))]:void 0,P=f&&f.length>0?f[Math.max(0,Math.min(f.length-1,f.length-5))]:void 0,F=p&&p.length>=9?p[2]:void 0,ee=p&&p.length>=9?p[8]:void 0,te=F?h(F):void 0,ne=ee?h(ee):void 0,re=F&&ee?Math.abs(F.y-ee.y):0,ie=y>1e-6?re/y:0,ae=(e,t)=>e&&t?Math.hypot(e.x-t.x,e.y-t.y):0,I=ae(j,N),L=ae(M,P),oe=y>1e-6?I/y:0,se=y>1e-6?L/y:0,R,z;f&&f.length>=2&&(R=f.slice(0,5).reduce((e,t)=>t.y<e.y?t:e,f[0]),z=f.slice(-5).reduce((e,t)=>t.y<e.y?t:e,f[f.length-1]));let ce=R?h(R):void 0,le=z?h(z):void 0;return{faces:1,box:{x:D,y:O,width:k,height:A},centerX:O_(D+k/2),area:k*A,leftEyeOpenProb:E(w),rightEyeOpenProb:E(T),leftEyeCenter:{x:O_(_.x/i),y:O_(_.y/a)},rightEyeCenter:{x:O_(v.x/i),y:O_(v.y/a)},eyeDist:O_(y/Math.max(i,a)),yawProxy:C,mouthLeft:j?h(j):void 0,mouthRight:M?h(M):void 0,jawLeft:N?h(N):void 0,jawRight:P?h(P):void 0,mouthUpper:te,mouthLower:ne,mouthOpenPx:re,mouthOpenNorm:ie,mouthJawLeftDist:oe,mouthJawRightDist:se,jawTopL:ce,jawTopR:le,mouthJawLeftDistPx:I,mouthJawRightDistPx:L,leftEyePoints:m(l),rightEyePoints:m(u),noseTip:x?{x:O_(x.x/i),y:O_(x.y/a)}:void 0,nosePoints:d?m(d):void 0,mouthPoints:p?m(p):void 0,jawPoints:f?m(f):void 0,jawCenter:{x:O_(b.x/i),y:O_(b.y/a)},poseSource:`landmarks`}}let c=await s();return!c||c.length===0?{faces:0}:c.length>1?{faces:c.length}:o(c[0].box)}}}function M_(e,t){return{code:e,message:t}}function N_(e){return _(e?.strictness??.5)}function P_(e){let t=N_(e),n=e?.lookForwardTolerance;return _(typeof n==`number`?n:1-t)}function F_(e,t,n){let r=!!n?.current,i=n?.current??null,a=(t?.mirrorMode??`mirrored`)===`mirrored`;if(e.faces===0)return{feedback:M_(`FACE_NOT_FOUND`,`Centralize seu rosto`),valid:!1,frameOk:!1,stepOk:!1};if(e.faces>1)return{feedback:M_(`MULTIPLE_FACES`,`Apenas 1 rosto por vez`),valid:!1,frameOk:!1,stepOk:!1};if(!e.box)return{feedback:M_(`FACE_NOT_FOUND`,`Centralize seu rosto`),valid:!1,frameOk:!1,stepOk:!1};let o=N_(t),s=P_(t),{x:c,y:l,width:u,height:d}=e.box,f=c+u/2,p=l+d/2,m=e.centerX??f,h=p,v=e.area??u*d,y=u/Math.max(1e-6,d),b=.07+o*.02,x=.22-o*.03,S=.12-o*.03+(r?.16:0),C=t?.lookSideTol??.18-o*.05,w=t?.lookUpDownTol??.12-o*.03,T=t?.zoomInMinArea??.16+o*.02,E=t?.zoomOutMaxArea??.12-o*.02;if(i===`zoomIn`){let t=v>=T,n=_((v-E)/Math.max(1e-6,T-E));return{feedback:M_(`ZOOM_IN`,t?`Mantenha...`:`Aproxime-se da câmera`),valid:t,frameOk:!0,stepOk:t,debug:{strict:o,lfTol:s,forwardTol:0,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:e.eyeDist??0,noseDx:e.noseTip?e.noseTip.x-m:null,cx:f,cy:p,centerTol:S,faceArea:v,zoomInMinArea:T,zoomOutMaxArea:E,zoomProgress:n}}}if(i===`zoomOut`){let t=v<=E,n=_((T-v)/Math.max(1e-6,T-E));return{feedback:M_(`ZOOM_OUT`,t?`Mantenha...`:`Afaste-se da câmera`),valid:t,frameOk:!0,stepOk:t,debug:{strict:o,lfTol:s,forwardTol:0,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:e.eyeDist??0,noseDx:e.noseTip?e.noseTip.x-m:null,cx:f,cy:p,centerTol:S,faceArea:v,zoomInMinArea:T,zoomOutMaxArea:E,zoomProgress:n}}}let D=t?.blinkClosedThreshold??.65;t?.cheeseThreshold;let O=t?.openMouthThreshold??.5,k=e.eyeDist??0,A=e.noseTip?e.noseTip.x-m:null,j=.1-o*.02,M=typeof t?.lookForwardCenterTol==`number`?_(t.lookForwardCenterTol):_(j+s*.08);if(v<b)return{feedback:M_(`FACE_TOO_FAR`,`Aproxime o rosto`),valid:!1,frameOk:!1,stepOk:!1,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A}};if(v>x)return{feedback:M_(`FACE_TOO_CLOSE`,`Afaste o rosto`),valid:!1,frameOk:!1,stepOk:!1,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A}};if(Math.abs(f-.5)>S||Math.abs(p-.5)>S)return{feedback:M_(`FACE_OFF_CENTER`,`Centralize seu rosto`),valid:!1,frameOk:!1,stepOk:!1,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A}};let N=e.mouthLeft,P=e.mouthRight,F=e.jawLeft,ee=e.jawRight,te=N&&P?{x:(N.x+P.x)/2,y:(N.y+P.y)/2}:null,ne=F&&ee?{x:(F.x+ee.x)/2,y:(F.y+ee.y)/2}:null,re=e.box?.height??null,ie=te&&ne&&typeof re==`number`&&re>1e-6?(ne.y-te.y)/re:null,ae=ie==null?null:g(ie,-1,1),I=typeof e.mouthJawLeftDistPx==`number`?e.mouthJawLeftDistPx:null,L=typeof e.mouthJawRightDistPx==`number`?e.mouthJawRightDistPx:null,oe=1e3,se=(I!=null&&L!=null?I>500&&I<oe&&L>500&&L<oe:!1)&&(ie==null?!1:ie>=-.5&&ie<=.5),R=typeof t?.lookForwardOkSince==`number`?t.lookForwardOkSince:null,z=se&&R!=null?Date.now()-R>=1e3:!1,ce=n?.current??null;if(!ce)return{feedback:M_(`READY`,`Pronto para capturar`),valid:!0,frameOk:!0,stepOk:!0,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A}};_(t?.poseProgressAccept??.65);let le=typeof e.mouthJawLeftDist==`number`?e.mouthJawLeftDist:null,ue=typeof e.mouthJawRightDist==`number`?e.mouthJawRightDist:null,de=typeof t?.mouthJawBaselineLeft==`number`?t.mouthJawBaselineLeft:null,fe=typeof t?.mouthJawBaselineRight==`number`?t.mouthJawBaselineRight:null,pe=le!=null&&ue!=null,me=de!=null&&fe!=null,he=pe&&me?le-de:null,ge=pe&&me?ue-fe:null,_e=t?.lookSideNearThr??.3,ve=t?.lookSideFarThr??1,ye=pe?a?ue:le:null,be=pe?a?le:ue:null,xe=ye!=null&&be!=null&&ye<_e&&be>ve,Se=ye!=null&&be!=null&&be<_e&&ye>ve,Ce=Math.max(1e-6,ve-_e),we=e=>_((ve-e)/Ce),Te=e=>_((e-_e)/Ce),Ee=ye!=null&&be!=null?Math.min(we(ye),Te(be)):0,De=ye!=null&&be!=null?Math.min(we(be),Te(ye)):0,Oe=ae??null,ke=typeof t?.lookUpDownFullScaleEps==`number`?t.lookUpDownFullScaleEps:.02,Ae=typeof t?.lookUpDownFullThr==`number`?g(t.lookUpDownFullThr,.1,1):1;if(Oe!=null&&Oe>0&&_((Oe-0)/Math.max(1e-6,Ae)),Oe!=null&&Oe<0&&_((-Oe-0)/Math.max(1e-6,Ae)),1-ke,1-ke,ce===`lookForward`){let n=e.jawTopL,r=e.jawTopR,a=e.leftEyeCenter,c=e.rightEyeCenter,l,u,d,f;n&&a&&r&&c&&(l=Math.hypot(n.x-a.x,n.y-a.y),u=Math.hypot(r.x-c.x,r.y-c.y),d=Math.abs(l-u),f=d/Math.max(l,u,1e-6));let p=ie==null?!1:ie>=-.5&&ie<=.5,m=typeof f==`number`?f<=.25:!1,h=ie==null?!1:ie>=-.6&&ie<=.6,g=typeof f==`number`?f<=.3:!1,_=p&&m,v=h&&g,b=typeof t?.lookForwardHoldMs==`number`?t.lookForwardHoldMs:1e3,x=typeof t?.lookForwardOkSince==`number`?t.lookForwardOkSince:null;v?_&&x==null&&(x=Date.now()):x=null;let S=_&&x!=null?Date.now()-x:0,T=_&&x!=null?S>=b:!1,E=``;return E=T?`Pronto para capturar`:v?`Mantenha...`:`Olhe para frente`,{feedback:M_(T?`READY`:`LOOK_FORWARD`,E),valid:T,frameOk:T,stepOk:T,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,jawTopL:n,jawTopR:r,leftEyeCenter:a,rightEyeCenter:c,jawEyeDistL:l,jawEyeDistR:u,jawEyeDistDiff:d,jawEyeDistRelDiff:f,jawEyeRelTol:.25,mouthAvg:te,jawMid:ne,faceH:re,mouthVsJawMidRaw:ie,yOk:p,distOk:m,lookForwardOkInstant:_,lookForwardHeld:T,lookForwardHoldMs:b,lookForwardHeldMs:S,lookForwardOkSince:x,currentStep:i,stepPassed:T}}}if(i===`lookUp`||i===`lookDown`){let e=ae,n=typeof t?.lookUpDownThreshold==`number`?g(Math.abs(t.lookUpDownThreshold),.02,.9):.06,r=i===`lookUp`?typeof e==`number`?e>=n:!1:typeof e==`number`?e<=-n:!1,a=typeof e==`number`?_(i===`lookUp`?(e-n)/Math.max(1e-6,.1-n):(-e-n)/Math.max(1e-6,.1-n)):0;return{feedback:r?M_(i===`lookUp`?`LOOK_UP`:`LOOK_DOWN`,`Mantenha...`):i===`lookUp`?M_(`LOOK_UP`,`Olhe para cima`):M_(`LOOK_DOWN`,`Olhe para baixo`),valid:r,frameOk:r,stepOk:r,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,cx:m,cy:h,centerTol:S,currentStep:i,stepPassed:r,mouthAvg:te,jawMid:ne,faceH:re,mouthVsJawMidRaw:ie,mouthVsJawMidClamped:ae,lookUpProgress:i===`lookUp`?a:0,lookDownProgress:i===`lookDown`?a:0,lookUpDownThreshold:n,poseProgressSource:`mouthJaw`}}}if(ce===`lookLeft`){let e=xe;return{feedback:M_(`LOOK_LEFT`,`Olhe para a esquerda`),valid:e,frameOk:!0,stepOk:e,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,cx:f,cy:p,centerTol:S,lookForwardOk:z,lookLeftProgress:Ee,lookRightProgress:De,lookLeftRule:`L<${_e.toFixed(2)} && R>${ve.toFixed(2)}`,lookRightRule:`R<${_e.toFixed(2)} && L>${ve.toFixed(2)}`,lookLeftActualTarget:`L:${(ye??0).toFixed(3)}/${_e.toFixed(2)} R:${(be??0).toFixed(3)}/${ve.toFixed(2)}`,mouthJawLeftDist:le??void 0,mouthJawRightDist:ue??void 0,mouthJawBaselineLeft:de??void 0,mouthJawBaselineRight:fe??void 0,mouthJawDeltaLeft:he??void 0,mouthJawDeltaRight:ge??void 0,mouthJawThr:void 0,mouthJawRatioNormLeft:void 0,mouthJawRatioNormRight:void 0,mouthJawRatioNowLeftOverRight:void 0,mouthJawRatioNowRightOverLeft:void 0,mouthJawRatioBaseLeftOverRight:void 0,mouthJawRatioBaseRightOverLeft:void 0}}}if(ce===`lookRight`){let e=Se;return{feedback:M_(`LOOK_RIGHT`,`Olhe para a direita`),valid:e,frameOk:!0,stepOk:e,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,cx:f,cy:p,centerTol:S,lookForwardOk:z,lookLeftProgress:Ee,lookRightProgress:De,lookLeftRule:`L<${_e.toFixed(2)} && R>${ve.toFixed(2)}`,lookRightRule:`R<${_e.toFixed(2)} && L>${ve.toFixed(2)}`,lookRightActualTarget:`R:${(be??0).toFixed(3)}/${_e.toFixed(2)} L:${(ye??0).toFixed(3)}/${ve.toFixed(2)}`,mouthJawLeftDist:le??void 0,mouthJawRightDist:ue??void 0,mouthJawBaselineLeft:de??void 0,mouthJawBaselineRight:fe??void 0,mouthJawDeltaLeft:he??void 0,mouthJawDeltaRight:ge??void 0,mouthJawThr:void 0,mouthJawRatioNormLeft:void 0,mouthJawRatioNormRight:void 0,mouthJawRatioNowLeftOverRight:void 0,mouthJawRatioNowRightOverLeft:void 0,mouthJawRatioBaseLeftOverRight:void 0,mouthJawRatioBaseRightOverLeft:void 0}}}if(ce===`blink`){let t=e.leftEyeOpenProb,n=e.rightEyeOpenProb,r=typeof t==`number`&&typeof n==`number`&&t<D&&n<D,i=!!r;return{feedback:M_(`BLINK`,`Pisque`),valid:i,frameOk:!0,stepOk:i,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,leftEyeOpenProb:typeof t==`number`?t:void 0,rightEyeOpenProb:typeof n==`number`?n:void 0,blinkClosedThreshold:D,blinkIsClosed:!!r}}}if(ce===`cheese`){let n=e.mouthPoints,r=Array.isArray(n)&&n.length>=8,i=0;if(r){let e=n.map(e=>e.x),t=n.map(e=>e.y);i=(Math.max(...e)-Math.min(...e))/Math.max(1e-6,Math.max(...t)-Math.min(...t))}let a=t?.cheeseUseBaseline!==!1,c=typeof t?.cheeseBaseline==`number`?t.cheeseBaseline:void 0,l=t?.cheeseThreshold??.05,u;u=a&&typeof c==`number`?c+l:l;let d=r&&i>=u;return{feedback:M_(`CHEESE`,`Sorria`),valid:d,frameOk:!0,stepOk:d,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,mouthSmileRatio:r?i:void 0,cheeseThreshold:l,cheeseBaseline:typeof c==`number`?c:void 0,cheeseTarget:u}}}if(ce===`openMouth`){let t=e.mouthPoints,n=Array.isArray(t)&&t.length>=8,r=0;if(n){let e=t.map(e=>e.x),n=t.map(e=>e.y),i=Math.max(...e)-Math.min(...e);r=Math.max(1e-6,Math.max(...n)-Math.min(...n))/Math.max(1e-6,i)}let i=e.mouthUpper,a=e.mouthLower,c=e.mouthOpenPx,l=e.mouthOpenNorm,u=typeof l==`number`&&i&&a?l:r,d=n&&i&&a&&u>=O;return{feedback:M_(`OPEN_MOUTH`,`Abra a boca`),valid:d,frameOk:!0,stepOk:d,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,mouthOpenRatio:n&&i&&a?u:void 0,openMouthThreshold:O,...i===void 0?{}:{mouthUpper:i},...a===void 0?{}:{mouthLower:a},...c===void 0?{}:{mouthOpenPx:c},...l===void 0?{}:{mouthOpenNorm:u}}}}if(ce===`mouthWidth`){let t=e.mouthPoints,n=Array.isArray(t)&&t.length>=8,r=0;if(n){let e=t.map(e=>e.x),n=Math.max(...e)-Math.min(...e);r=k>1e-6?n/k:0}let i=.55,a=n&&r>i;return{feedback:M_(`CHEESE`,`Sorria (abra a boca lateralmente)`),valid:a,frameOk:a,stepOk:a,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,mouthWidthRatio:n?r:void 0,smileThreshold:i}}}return{feedback:M_(`READY`,`Pronto para capturar`),valid:!0,frameOk:!0,stepOk:!0,debug:{strict:o,lfTol:s,forwardTol:M,lookSideTol:C,lookUpDownTol:w,ratio:y,eyeDist:k,noseDx:A,cx:f,cy:p,centerTol:S,lookForwardOk:z}}}function I_(e){let t=document.createElement(`canvas`),n=t.getContext(`2d`),r=null;t.style.position=`absolute`,t.style.left=`0`,t.style.top=`0`,t.style.width=`100%`,t.style.height=`100%`,t.style.pointerEvents=`none`,getComputedStyle(e).position===`static`&&(e.style.position=`relative`),e.appendChild(t);function i(e,t,n,r){e.beginPath(),e.moveTo(t,n-r*.78),e.bezierCurveTo(t+r*1.15,n-r*.78,t+r*.65,n+r*1.1,t,n+r*1.18),e.bezierCurveTo(t-r*.65,n+r*1.1,t-r*1.15,n-r*.78,t,n-r*.78),e.closePath()}function a(e,t,n){let r=new Path2D;return r.moveTo(e,t-n*.78),r.bezierCurveTo(e+n*1.15,t-n*.78,e+n*.65,t+n*1.1,e,t+n*1.18),r.bezierCurveTo(e-n*.65,t+n*1.1,e-n*1.15,t-n*.78,e,t-n*.78),r.closePath(),r}function o(e,t,n,r=80){let i={x:e,y:t-n*.78},a={x:e,y:t+n*1.18},o={x:e+n*1.15,y:t-n*.78},s={x:e+n*.65,y:t+n*1.1},c={x:e-n*.65,y:t+n*1.1},l={x:e-n*1.15,y:t-n*.78},u=(e,t,n,r,i)=>{let a=1-i,o=i*i,s=a*a,c=s*a,l=o*i;return{x:c*e.x+3*s*i*t.x+3*a*o*n.x+l*r.x,y:c*e.y+3*s*i*t.y+3*a*o*n.y+l*r.y}},d=[],f=Math.max(2,Math.floor(r/2)),p=Math.max(2,r-f);for(let e=0;e<=f;e++){let t=e/f;d.push(u(i,o,s,a,t))}for(let e=1;e<=p;e++){let t=e/p;d.push(u(a,c,l,i,t))}return d}function s(e,t,n,r){let i=Math.max(0,Math.min(1,r));if(i<=0)return;let a=o(t/2,n*.36,Math.min(t,n)*.46*x,80),s=a.length,c=Math.max(1,Math.floor(i*(s-1)));e.save(),e.globalCompositeOperation=`source-over`,e.lineWidth=5,e.lineCap=`round`,e.lineJoin=`round`,e.strokeStyle=`#2ee59d`,e.shadowColor=`#2ee59d`,e.shadowBlur=i>=.999?14:8,e.beginPath(),e.moveTo(a[0].x,a[0].y);for(let t=1;t<=c;t++)e.lineTo(a[t].x,a[t].y);e.stroke(),e.restore()}function c(e,t){if(!n)return;k(n,e,t),n.save();let a=e/2,o=t*.36,c=Math.min(e,t)*.46*x;i(n,a,o,c),n.globalCompositeOperation=`destination-out`,n.fillStyle=`#fff`,n.fill(),n.restore(),n.save(),n.globalCompositeOperation=`source-over`,n.lineWidth=4,n.strokeStyle=A(),n.shadowColor=A(),n.shadowBlur=10,i(n,a,o,c),n.stroke(),n.restore();let l=typeof r?.debug?.challengeHoldProgress==`number`?r.debug.challengeHoldProgress:0;l>0&&s(n,e,t,l)}function l(e,t){if(!n)return;n.save();let r=e/2,a=t*.36,o=Math.min(e,t)*.46*x;n.save(),i(n,r,a,o),n.clip(),n.strokeStyle=`#fff`,n.lineWidth=2.2,n.shadowColor=`transparent`,n.shadowBlur=0;let s=u.x*o*.45,c=u.y*o*.45;n.beginPath(),n.moveTo(r,a-o*.78),n.bezierCurveTo(r+s*.5,a-o*.25+c*.2,r+s*.5,a+o*.65+c*.2,r,a+o*1.18),n.stroke(),n.beginPath(),n.moveTo(r-o*.95,a),n.bezierCurveTo(r-o*.25,a+o*.1+c,r+o*.25,a+o*.1+c,r+o*.95,a),n.stroke(),n.restore(),n.restore()}let u={x:0,y:0},d={x:0,y:0},f=0,p=`idle`,m=0,h={x:0,y:0},g=1.25;function _(e,t){let n=0,r=0,i=e.challenge?.direction;!i&&e.hint?.type===`arrow`&&(i=e.hint.direction),i===`left`?n=-1:i===`right`?n=1:i===`up`?r=-1:i===`down`&&(r=1),(n!==h.x||r!==h.y)&&(p=`hold`,m=0,h.x=n,h.y=r),n!==0||r!==0?p===`hold`?(d.x=n*g,d.y=r*g,m+=t,m>.7&&(p=`boomerang`,m=0)):p===`boomerang`?(d.x=0,d.y=0,m+=t,m>.28&&(p=`hold`,m=0)):(d.x=0,d.y=0):(d.x=0,d.y=0,p=`idle`)}function b(e){let t=8.5;u.x+=(d.x-u.x)*Math.min(1,e*t),u.y+=(d.y-u.y)*Math.min(1,e*t)}let x=1,S=1;function C(e){let t=e.debug?.feedbackCode;S=e.challenge?.direction===`zoomIn`||t===`ZOOM_IN`?1.28:e.challenge?.direction===`zoomOut`||t===`ZOOM_OUT`?.72:1}function w(e){x+=(S-x)*Math.min(1,e*3.8),Math.abs(x-S)<.001&&(x=S)}let T={IDLE:`IDLE`,CAMERA_ON:`CAMERA_ON`,FACE_DETECTED:`FACE_DETECTED`,ALIGNED:`ALIGNED`,SUCCESS:`SUCCESS`,FAIL:`FAIL`},E=T.IDLE;function D(e){if(!e.video){E=T.IDLE;return}if(!e.box){E=T.CAMERA_ON;return}if(e.box&&!e.valid){E=T.FACE_DETECTED;return}if(e.box&&e.valid){if(E=T.ALIGNED,e.debug?.stepPassed===!0){E=T.SUCCESS;return}if(e.debug?.stepPassed===!1){E=T.FAIL;return}return}E=T.IDLE}function O(e,t,r,i){let o=a(r/2,i*.36,Math.min(r,i)*.46*x);return n?.isPointInPath(o,e,t)??!1}function k(e,t,n){e.save(),e.clearRect(0,0,t,n),e.globalAlpha=.7,e.fillStyle=`#222`,e.fillRect(0,0,t,n),e.globalAlpha=1,e.restore()}function A(){switch(E){case T.FACE_DETECTED:return`#FF9800`;case T.ALIGNED:return`#FFD44D`;case T.SUCCESS:return`#2ee59d`;default:return`#FFD44D`}}function j(i){r=i,D(i);let{w:a,h:o}=v(t,e,n||void 0);if(!n)return;let s=y(a,o,i.video,i.videoObjectFit,!i.mirrored),u=performance.now(),d=f?(u-f)/1e3:.016;d>.1&&(d=.016),f=u;let p=i.landmarkDraw?.eyes!==!1,m=i.landmarkDraw?.mouth!==!1,h=i.landmarkDraw?.nose!==!1,g=i.landmarkDraw?.jaw!==!1,T=i.landmarkDraw?.mouthJaw!==!1,k=i.landmarkDraw||{};_(i,d),b(d),C(i),w(d),(i.challenge?.direction===`zoomIn`||i.challenge?.direction===`zoomOut`)&&console.log(`challenge.direction:`,i.challenge.direction,`guideScale:`,x,`targetScale:`,S),c(a,o),l(a,o),i.message&&(n.save(),n.font=`600 1.1rem system-ui, sans-serif`,n.textAlign=`center`,n.fillStyle=`#fff`,n.shadowColor=`#222`,n.shadowBlur=8,n.fillText(i.message,a/2,o*.76),n.restore());let A=p||m||h||g||T,j=i.debug?.extra?.showCoxinhaCenterDot===!0;if(i.box&&A&&j){let e=i.box.x+i.box.width/2,t=i.box.y+i.box.height/2,r=s.mapPt({x:e,y:t});n.save(),n.beginPath(),n.arc(r.x,r.y,7,0,Math.PI*2),n.fillStyle=O(r.x,r.y,a,o)?`#4caf50`:`#ff5252`,n.globalAlpha=.7,n.fill(),n.restore()}let M=i.landmarks;if(M){if(p&&(M.leftEye||M.rightEye)&&(n.save(),n.strokeStyle=`#4fc3f7`,n.lineWidth=2,M.leftEye&&(n.beginPath(),M.leftEye.forEach((e,t)=>{let r=s.mapPt(e);t===0?n.moveTo(r.x,r.y):n.lineTo(r.x,r.y)}),n.closePath(),n.stroke()),M.rightEye&&(n.beginPath(),M.rightEye.forEach((e,t)=>{let r=s.mapPt(e);t===0?n.moveTo(r.x,r.y):n.lineTo(r.x,r.y)}),n.closePath(),n.stroke()),n.restore()),m&&M.mouthPoints&&(n.save(),n.strokeStyle=`#ffb300`,n.lineWidth=2,n.beginPath(),M.mouthPoints.forEach((e,t)=>{let r=s.mapPt(e);t===0?n.moveTo(r.x,r.y):n.lineTo(r.x,r.y)}),n.closePath(),n.stroke(),n.restore()),g&&M.jawPoints&&(n.save(),n.strokeStyle=`#81c784`,n.lineWidth=2,n.beginPath(),M.jawPoints.forEach((e,t)=>{let r=s.mapPt(e);t===0?n.moveTo(r.x,r.y):n.lineTo(r.x,r.y)}),n.stroke(),n.restore()),h&&M.nosePoints&&(n.save(),n.strokeStyle=`#ba68c8`,n.lineWidth=2,n.beginPath(),M.nosePoints.forEach((e,t)=>{let r=s.mapPt(e);t===0?n.moveTo(r.x,r.y):n.lineTo(r.x,r.y)}),n.stroke(),n.restore()),T&&M.mouthLeft&&M.jawLeft){n.save(),n.strokeStyle=`#e57373`,n.lineWidth=2,n.beginPath();let e=s.mapPt(M.mouthLeft),t=s.mapPt(M.jawLeft);n.moveTo(e.x,e.y),n.lineTo(t.x,t.y),n.stroke(),n.restore()}if(T&&M.mouthRight&&M.jawRight){n.save(),n.strokeStyle=`#e57373`,n.lineWidth=2,n.beginPath();let e=s.mapPt(M.mouthRight),t=s.mapPt(M.jawRight);n.moveTo(e.x,e.y),n.lineTo(t.x,t.y),n.stroke(),n.restore()}}if(k.cheese&&i.debug?.cheeseBaseline!=null&&(n.save(),n.font=`bold 1rem system-ui, sans-serif`,n.fillStyle=`#FFD44D`,n.shadowColor=`#222`,n.shadowBlur=6,n.fillText(`cheese baseline: ${i.debug.cheeseBaseline.toFixed(3)}`,a/2,o*.08),i.debug.cheeseTarget!=null&&n.fillText(`cheese target: ${i.debug.cheeseTarget.toFixed(3)}`,a/2,o*.13),n.restore()),i.debug&&i.debug.extra?.showOverlayTableCanvas){let e=Math.min(520,Math.round(a*.62)),t=[];t.push(`drawLandmarks: ${i.debug.drawLandmarks===!1?`OFF`:`ON`}`),t.push(`draw: eyes=${p?`ON`:`OFF`} | mouth=${m?`ON`:`OFF`} | jaw=${g?`ON`:`OFF`} | nose=${h?`ON`:`OFF`} | mouth↔jaw=${T?`ON`:`OFF`}`),t.push(`cheese panel: ${k.cheese?`ON`:`OFF`}`),t.push(``),t.push(`Overlay State: ${E}`),typeof i.debug.status==`string`&&t.push(`Status: ${i.debug.status}`),typeof i.debug.ready==`boolean`&&t.push(`Ready: ${i.debug.ready}`),typeof i.debug.feedbackCode==`string`&&t.push(`Feedback: ${i.debug.feedbackCode}`),typeof i.debug.challenge==`string`&&t.push(`Challenge: ${i.debug.challenge}`);let r=typeof i.debug.faces==`number`?i.debug.faces:void 0,s=typeof i.debug.eyeL==`number`?i.debug.eyeL:void 0,c=typeof i.debug.eyeR==`number`?i.debug.eyeR:void 0;(r!=null||s!=null||c!=null)&&t.push(`Debug: faces=${r??`-`} | eyeL=${s==null?`-`:s.toFixed(2)} | eyeR=${c==null?`-`:c.toFixed(2)}`);let l=typeof i.debug.blinkCount==`number`?i.debug.blinkCount:void 0,u=typeof i.debug.blinkClosedNow==`boolean`?i.debug.blinkClosedNow:void 0,d=typeof i.debug.blinkClosedThreshold==`number`?i.debug.blinkClosedThreshold:void 0;(l!=null||u!=null||d!=null)&&t.push(`Blink: count=${l??`-`} | closedNow=${u??`-`} | thr=${d==null?`-`:d.toFixed(2)}`);let f=i.debug.mouthVsJawMidRaw,_=i.debug.mouthVsJawMidClamped;(typeof _==`number`||typeof f==`number`)&&t.push(`mouthAvg vs jawMid: ${typeof _==`number`?_.toFixed(2):`-`} (raw ${typeof f==`number`?f.toFixed(3):`-`})`);let v=i.debug.faceH;if(typeof v==`number`&&t.push(`faceH: ${v.toFixed(3)}`),typeof i.debug.stepPassed==`boolean`&&t.push(`stepPassed(${i.debug.currentStep??`-`}) = ${i.debug.stepPassed}`),i.debug.debugDraw?.cheese!==!1){let e=i.debug.mouthSmileRatio,n=i.debug.cheeseBaseline,r=i.debug.cheeseTarget;(typeof e==`number`||typeof n==`number`||typeof r==`number`)&&t.push(`Cheese: ratio=${typeof e==`number`?e.toFixed(3):`-`} | base=${typeof n==`number`?n.toFixed(3):`-`} | target=${typeof r==`number`?r.toFixed(3):`-`}`)}t.length===0&&t.push(`Debug ativo (nenhum dado)`);let y=24+t.length*16,b=Math.max(8,o-y-88);n.save(),n.fillStyle=`rgba(0,0,0,0.72)`,n.strokeStyle=`#FFD44D`,n.lineWidth=2,n.beginPath(),typeof n.roundRect==`function`?n.roundRect(12,b,e,y,10):n.rect(12,b,e,y),n.fill(),n.stroke(),n.fillStyle=`rgba(255,255,255,0.92)`,n.font=`12px ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace`,n.textAlign=`left`,n.textBaseline=`top`;for(let e=0;e<t.length;e++)n.fillText(t[e],24,b+12+e*16);n.restore()}}function M(){t.remove()}return{canvas:t,dispose:M,render:j}}function L_(e){getComputedStyle(e).position===`static`&&(e.style.position=`relative`)}function R_(e){let{container:t,labels:n,onOk:r,onRetake:i}=e;L_(t);let a=document.createElement(`div`);a.className=`alphavalid-userPreview`,a.style.position=`absolute`,a.style.inset=`0`,a.style.display=`none`,a.style.alignItems=`center`,a.style.justifyContent=`center`,a.style.flexDirection=`column`,a.style.gap=`10px`,a.style.background=`rgba(0,0,0,0.45)`,a.style.backdropFilter=`blur(2px)`,a.style.zIndex=`999999`,a.style.pointerEvents=`auto`,a.style.touchAction=`manipulation`;let o=document.createElement(`img`);o.className=`alphavalid-userPreview-img`,o.alt=`preview`,o.style.width=`88%`,o.style.maxWidth=`360px`,o.style.maxHeight=`70%`,o.style.objectFit=`contain`,o.style.borderRadius=`16px`,o.style.boxShadow=`0 10px 28px rgba(0,0,0,0.35)`;let s=document.createElement(`div`);s.className=`alphavalid-userPreview-meta`,s.style.color=`#fff`,s.style.fontWeight=`600`,s.style.textAlign=`center`,s.style.fontSize=`0.95rem`,s.style.padding=`0 16px`;let c=document.createElement(`div`);c.className=`alphavalid-userPreview-actions`,c.style.display=`flex`,c.style.gap=`10px`,c.style.marginTop=`6px`,c.style.pointerEvents=`auto`,c.style.zIndex=`1000000`;let l=document.createElement(`button`);l.type=`button`,l.className=`alphavalid-userPreview-retake`,l.textContent=n?.retake??`Tirar outra`,l.style.padding=`10px 14px`,l.style.borderRadius=`12px`,l.style.border=`1px solid rgba(255,255,255,0.35)`,l.style.background=`rgba(0,0,0,0.35)`,l.style.color=`#fff`,l.style.fontWeight=`700`,l.style.cursor=`pointer`,l.style.pointerEvents=`auto`,l.style.touchAction=`manipulation`;let u=document.createElement(`button`);return u.type=`button`,u.className=`alphavalid-userPreview-ok`,u.textContent=n?.ok??`OK`,u.style.padding=`10px 16px`,u.style.borderRadius=`12px`,u.style.border=`1px solid rgba(255,255,255,0.35)`,u.style.background=`#ffffff`,u.style.color=`#111`,u.style.fontWeight=`800`,u.style.cursor=`pointer`,u.style.pointerEvents=`auto`,u.style.touchAction=`manipulation`,l.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),i()}),u.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),r()}),c.appendChild(l),c.appendChild(u),a.appendChild(o),a.appendChild(s),a.appendChild(c),t.appendChild(a),{show:(e,t)=>{o.src=e,s.textContent=t??``,a.style.display=`flex`},hide:()=>{a.style.display=`none`,o.removeAttribute(`src`),s.textContent=``},dispose:()=>{a.remove()}}}function z_(e){return{ok:e.previewOkText,retake:e.previewRetakeText}}var B_=`/assets/images/alphaloader.gif`,V_=`data:image/gif;base64,R0lGODlhAQABAAAAACw=`;function H_(e,t={}){let n=t.src??B_,r=t.sizePx??120,i=t.minVisibleMs??900,a=null,o=0,s=null,c=()=>{getComputedStyle(e).position===`static`&&(e.style.position=`relative`)},l=()=>{if(a)return a;c(),a=document.createElement(`div`),a.className=`alphavalid-camera-loader`,a.style.position=`absolute`,a.style.inset=`0`,a.style.display=`flex`,a.style.alignItems=`center`,a.style.justifyContent=`center`,a.style.background=`transparent`,a.style.zIndex=`999`;let t=document.createElement(`img`);return t.alt=`Carregando...`,t.style.width=`${r}px`,t.style.height=`${r}px`,t.onerror=()=>{t.onerror=null,t.src=V_},t.src=n,a.appendChild(t),e.appendChild(a),a};return{show:()=>{s!=null&&(window.clearTimeout(s),s=null),l(),o=Date.now(),a&&(a.style.display=`flex`)},hide:()=>{if(!a)return;let e=Date.now()-o,t=Math.max(0,i-e);if(t>0){s!=null&&window.clearTimeout(s),s=window.setTimeout(()=>{s=null,a&&(a.style.display=`none`)},t);return}a.style.display=`none`},dispose:()=>{s!=null&&(window.clearTimeout(s),s=null),a?.remove(),a=null}}}function U_(e){getComputedStyle(e).position===`static`&&(e.style.position=`relative`)}function W_(e){let{container:t,text:n,color:r,onClick:i}=e;U_(t);let a=document.createElement(`button`);return a.type=`button`,a.className=`alphavalid-captureBtn`,a.textContent=n??`Capturar imagem`,a.style.position=`absolute`,a.style.left=`50%`,a.style.bottom=`calc(env(safe-area-inset-bottom, 0px) + 24px)`,a.style.transform=`translateX(-50%)`,a.style.width=`88%`,a.style.maxWidth=`340px`,a.style.height=`56px`,a.style.borderRadius=`18px`,a.style.border=`none`,a.style.background=r??`#00bcd4`,a.style.color=`#fff`,a.style.fontWeight=`800`,a.style.fontSize=`1.05rem`,a.style.cursor=`pointer`,a.style.zIndex=`999998`,a.style.boxShadow=`0 10px 22px rgba(0,0,0,0.28)`,a.style.touchAction=`manipulation`,a.style[`-webkit-tap-highlight-color`]=`transparent`,a.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),!a.disabled&&i()}),t.appendChild(a),{show:()=>{a.style.display=`block`},hide:()=>{a.style.display=`none`},dispose:()=>{a.remove()},setEnabled:e=>{a.disabled=!e,a.style.opacity=e?`1`:`0.55`}}}function G_(e){if(!(typeof document>`u`)){if(!document.getElementById(`alphavalid-base-styles`)){let e=document.createElement(`style`);e.id=`alphavalid-base-styles`,e.textContent=`
3805
3805
  /* Reset basics for full-screen portrait mobile UX */
3806
3806
  html, body { height: 100%; min-height: 100svh; margin: 0; padding: 0; }
3807
3807
  body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
@@ -3841,12 +3841,12 @@ Expected: `+l+`.`)}}function cp(e,t,n){return!isFinite(e)&&!isFinite(t)||!(isNaN
3841
3841
  .alphavalid-userPreview .alphavalid-userPreview-meta { font-size: 0.95rem; }
3842
3842
  }
3843
3843
 
3844
- `,document.head.appendChild(e)}if(e)try{e.classList.add(`alphavalid-root`)}catch{}}}var G_=l({setupModels:()=>K_});async function K_(){function e(){return q_.default.existsSync(`angular.json`)?`angular`:q_.default.existsSync(`vite.config.js`)||q_.default.existsSync(`vite.config.ts`)||q_.default.existsSync(`index.html`)||q_.default.existsSync(`public`)?`vite`:`unknown`}function t(){let t=e();return t===`angular`?J_.default.join(`src`,`assets`,`alphavalid-models`):t===`vite`?J_.default.join(`public`,`alphavalid-models`):J_.default.join(`alphavalid-models`)}let n=J_.default.join(__dirname,`../models`),r=J_.default.resolve(process.cwd(),t());if(!q_.default.existsSync(n))throw Error(`[AlphaValid] Pasta de models não encontrada: `+n);q_.default.mkdirSync(r,{recursive:!0});for(let e of q_.default.readdirSync(n))q_.default.copyFileSync(J_.default.join(n,e),J_.default.join(r,e));return`[AlphaValid] Models copiados para ${r}`}var q_,J_,Y_=s((()=>{q_=d(x()),J_=d(x())})),X_=[`/assets/alphavalid-models`,`/alphavalid-models`],Z_=`cameraContainer`;async function Q_(e){for(let t of[`face_landmark_68_tiny_model-weights_manifest.json`,`face_landmark_68_tiny_model-shard1.bin`,`tiny_face_detector_model-weights_manifest.json`,`tiny_face_detector_model-shard1.bin`])try{if(!(await fetch(`${e}/${t}`,{method:`HEAD`})).ok)throw Error()}catch{throw Error(`\n[AlphaValid] Models não encontrados.\n\nExecute automaticamente:\nnpx alphavalid-sdk setup\n\nOu configure manualmente:\nmodelsPath: '${e}'\n`)}return e}async function $_(){let{setupModels:e}=await Promise.resolve().then(()=>(Y_(),G_));return e()}e.AlphaValid=class{_camera=null;_overlay=null;_container=null;_faceDetector=j_();_loopTimer=null;_lastStatusValid=!1;_options=null;_status=`idle`;_challengeIndex=0;_challengeStartedAt=null;_challengeEnterAt=null;_challengeCompletedAt=null;_challengeBaselineSeen=!1;_blinkArmed=!1;_state=null;_stableSince=null;_lastStableCx=null;_lastStableCy=null;_lastStableArea=null;_autoCaptureFired=!1;_lastGoodStatus=null;_lastGoodAt=0;_lastStatusForCaptureGate=null;_lastLookForwardGateOk=null;_forcedHintMessage=null;_poseLatch={left:0,right:0,up:0,down:0,at:0};_lastPoseChallenge=null;_mouthJawBaseline=null;_faceLostAt=null;_lookForwardOkSince=null;_blinkCount=0;_blinkPrevClosed=!1;_cheeseBaseline=null;_cheeseBaselineSamples=0;_cheeseBaselineSum=0;_cheeseBaselineStartedAt=null;_challengeHoldSince=null;_challengeLastStepOk=!1;_challengeHoldProgress=0;_challengeUiProgress=0;_startOptions=null;_previewBlob=null;_previewActions=null;_cheeseWindow=[];_cheeseWindowStart=null;_openMouthWindow=[];_openMouthWindowStart=null;_lifecycle=`idle`;_loopActive=!1;_debug=!1;_isCapturing=!1;_userPreviewUi=null;_userPreviewUrl=null;_loader=null;_captureBtn=null;_disposeCaptureButton(){try{this._captureBtn?.dispose()}catch{}this._captureBtn=null}_syncCaptureButton(e){let t=this._options;if(!t||!this._container)return;let n=t.uiMode===`Mobile`,r=t.captureButton?.enabled!==!1,i=t.autoCapture?.enabled===!0;if(!(n&&r&&!i)){this._captureBtn&&this._disposeCaptureButton();return}this._captureBtn||=U_({container:this._container,text:t.captureButton?.text??`Capturar imagem`,color:t.captureButton?.color??`#00bcd4`,onClick:()=>{this.capture().catch(()=>{})}});let a=e??this._state;if(this._lifecycle===`preview`){this._captureBtn.hide();return}let o=a?.challenge?.enabled?a.challenge.completed===!0:!0;this._lifecycle===`running`&&o?this._captureBtn.show():this._captureBtn.hide();let s=a?.isReadyToCapture===!0&&(a?.challenge?.enabled?a.challenge.completed===!0:!0),c=this._options?.requireLookForwardForCapture===!0,l=this._lastStatusForCaptureGate??this._lastGoodStatus??{},u=c?this._isLookForwardForCapture(l,{requireLf:c}):!0;c&&s&&!u?this._forcedHintMessage=`olhe para a camera`:this._forcedHintMessage=null,this._captureBtn.setEnabled(s&&u)}_setLifecycle(e){this._debug&&console.log(`[AlphaValid] lifecycle ${this._lifecycle} → ${e}`),this._lifecycle=e}async _pause(){if(this._lifecycle===`running`){this._loopTimer!=null&&(window.clearTimeout(this._loopTimer),this._loopTimer=null);try{this._camera?.video?.pause()}catch{}this._loopActive=!1,this._setLifecycle(`paused`)}}async _retakeFromPreview(){this._debug&&console.log(`[AlphaValid] preview action: retake()`,{lifecycle:this._lifecycle,hasCamera:!!this._camera,hasOptions:!!this._options,hasStartOptions:!!this._startOptions}),this._previewBlob=null,this._previewActions=null,this._hideUserPreviewUi();let e=this._startOptions;if(!e){this._debug&&console.warn(`[AlphaValid] retake ignored: missing _startOptions (cannot restart)`);return}try{await this.stop(),await this.start(e)}catch(e){throw this._debug&&console.error(`[AlphaValid] retake failed`,e),e}}async _confirmFromPreview(){if(this._debug&&console.log(`[AlphaValid] preview action: confirm()`,{lifecycle:this._lifecycle,hasBlob:!!this._previewBlob}),this._lifecycle!==`preview`){this._debug&&console.warn(`[AlphaValid] confirm ignored: not in preview`,{lifecycle:this._lifecycle});return}let e=this._previewBlob;if(e){if(this._options?.userPreview&&this._options?.uiMode===`Mobile`)try{this._options?.onUserPreviewConfirm?.(e)}catch{}else this._options?.autoCapture?.onCapture?.(e),this._options?.onCapture?.(e);this._hideUserPreviewUi(),this._previewBlob=null,this._previewActions=null,await this.stop()}}_hideUserPreviewUi(){try{this._userPreviewUi?.hide()}catch{}if(this._userPreviewUrl){try{URL.revokeObjectURL(this._userPreviewUrl)}catch{}this._userPreviewUrl=null}}_disposeUserPreviewUi(){this._hideUserPreviewUi();try{this._userPreviewUi?.dispose()}catch{}this._userPreviewUi=null}async _showPreview(e){if(this._debug&&console.log(`[AlphaValid] entering preview`,{lifecycle:this._lifecycle,blobSize:e?.size}),this._lifecycle!==`paused`&&this._lifecycle!==`preview`){this._debug&&console.warn(`[AlphaValid] _showPreview ignored due to lifecycle`,{lifecycle:this._lifecycle});return}this._setLifecycle(`preview`),this._previewBlob=e,this._previewActions={retake:()=>{this._debug&&console.log(`[AlphaValid] preview action clicked: retake`),this._retakeFromPreview()},confirm:()=>{this._debug&&console.log(`[AlphaValid] preview action clicked: confirm`),this._confirmFromPreview()}};let t=this._options;if(t?.userPreview&&t?.uiMode===`Mobile`&&this._container&&t){if(this._userPreviewUi||=R_({container:this._container,labels:z_(t),onOk:()=>this._previewActions?.confirm(),onRetake:()=>this._previewActions?.retake()}),this._userPreviewUrl)try{URL.revokeObjectURL(this._userPreviewUrl)}catch{}this._userPreviewUrl=URL.createObjectURL(e);let n=`preview: ${(e.size/1024).toFixed(1)} KB · ${new Date().toLocaleTimeString()}`;this._userPreviewUi.show(this._userPreviewUrl,n);return}t?.onPreview?.(e,this._previewActions)}_setVideoVisibility(e){let t=this._camera?.video;if(t)try{e?(t.style.visibility=`visible`,t.style.opacity=`1`,t.style.pointerEvents=`auto`):(t.style.visibility=`hidden`,t.style.opacity=`0`,t.style.pointerEvents=`none`),t.style.transition||(t.style.transition=`opacity 160ms ease`)}catch{}}async start(e){if(this._lifecycle===`running`||this._lifecycle===`preview`)return;this._debug=typeof e.debug==`boolean`?e.debug:!!e.debug?.enabled;let t=e.container??document.getElementById(Z_);if(!t)throw Error(`[AlphaValid] Container nao encontrado. Informe options.container ou crie <div id="${Z_}"></div>.`);f(t,`options.container`);let n=e.liveness;if(e.livenessPreset){let t=e.livenessPreset,r={};t===`normal`||(t===`easy`?(r.strictness=.3,r.lookForwardTolerance=.85,r.lookForwardYawTol=.1,r.lookSideTol=.08,r.lookUpDownTol=.16,r.poseProgressAccept=.55):t===`strict`&&(r.strictness=.8,r.lookForwardTolerance=.6,r.lookForwardYawTol=.04,r.lookSideTol=.03,r.lookUpDownTol=.08,r.poseProgressAccept=.8,r.lookForwardHoldMs=1200,r.challengeMinHoldMs=220)),n={...r,...e.liveness}}let r={...e,container:t,liveness:n};this._startOptions=r,await this.stop(),this._blinkCount=0,this._blinkPrevClosed=!1,this._options={overlay:!0,uiMode:`Mobile`,guideCircleRatio:.72,detectionIntervalMs:50,modelsPath:`/assets/alphavalid-models`,userPreview:!0,previewOkText:`OK`,previewRetakeText:`Tirar outra`,loader:{enabled:!0,src:`/assets/images/alphaloader.gif`,sizePx:120,minVisibleMs:900},captureButton:{enabled:!0,text:`Capturar imagem`,color:`#00bcd4`},requireLookForwardForCapture:!0,...r};let i=this._options;this._container=t;let a=t;if(!a)throw Error(`[AlphaValid] Container nao encontrado apos inicializacao.`);try{W_(a)}catch{}i.loader?.enabled!==!1&&(this._loader?.dispose(),this._loader=V_(a,i.loader),this._loader.show()),this._disposeCaptureButton(),this._status=`initializing`,i.onStateChange?.({status:this._status,feedback:{code:`INITIALIZING`,message:`Inicializando câmera...`},message:`Inicializando câmera...`,isReadyToCapture:!1,challenge:{enabled:!1,index:0,total:0,completed:!1}});try{i.onFeedback?.({code:`INITIALIZING`,message:`Inicializando câmera...`}),this._camera=await m(a),this._setVideoVisibility(!1),i.uiMode!==`headless`&&i.overlay!==!1&&(i.uiMode===`Mobile`?this._overlay=I_(a):this._overlay=b(a,i.guideCircleRatio));let t=i.modelsPath;if(t)await Q_(t);else{for(let n of X_)try{await Q_(n),t=n,e.debug&&console.log(`[AlphaValid] Models encontrados em: ${n}`);break}catch{}if(!t)throw Error(`
3844
+ `,document.head.appendChild(e)}if(e)try{e.classList.add(`alphavalid-root`)}catch{}}}var K_=l({setupModels:()=>q_});async function q_(){function e(){return J_.default.existsSync(`angular.json`)?`angular`:J_.default.existsSync(`vite.config.js`)||J_.default.existsSync(`vite.config.ts`)||J_.default.existsSync(`index.html`)||J_.default.existsSync(`public`)?`vite`:`unknown`}function t(){let t=e();return t===`angular`?Y_.default.join(`src`,`assets`,`alphavalid-models`):t===`vite`?Y_.default.join(`public`,`alphavalid-models`):Y_.default.join(`alphavalid-models`)}let n=Y_.default.join(__dirname,`../models`),r=Y_.default.resolve(process.cwd(),t());if(!J_.default.existsSync(n))throw Error(`[AlphaValid] Pasta de models não encontrada: `+n);J_.default.mkdirSync(r,{recursive:!0});for(let e of J_.default.readdirSync(n))J_.default.copyFileSync(Y_.default.join(n,e),Y_.default.join(r,e));return`[AlphaValid] Models copiados para ${r}`}var J_,Y_,X_=s((()=>{J_=d(x()),Y_=d(x())})),Z_=[`/assets/alphavalid-models`,`/alphavalid-models`],Q_=`cameraContainer`;async function $_(e){for(let t of[`face_landmark_68_tiny_model-weights_manifest.json`,`face_landmark_68_tiny_model-shard1.bin`,`tiny_face_detector_model-weights_manifest.json`,`tiny_face_detector_model-shard1.bin`])try{if(!(await fetch(`${e}/${t}`,{method:`HEAD`})).ok)throw Error()}catch{throw Error(`\n[AlphaValid] Models não encontrados.\n\nExecute automaticamente:\nnpx alphavalid-sdk setup\n\nOu configure manualmente:\nmodelsPath: '${e}'\n`)}return e}async function ev(){let{setupModels:e}=await Promise.resolve().then(()=>(X_(),K_));return e()}e.AlphaValid=class{_camera=null;_overlay=null;_container=null;_faceDetector=j_();_loopTimer=null;_lastStatusValid=!1;_options=null;_status=`idle`;_challengeIndex=0;_challengeStartedAt=null;_challengeEnterAt=null;_challengeCompletedAt=null;_challengeBaselineSeen=!1;_blinkArmed=!1;_state=null;_stableSince=null;_lastStableCx=null;_lastStableCy=null;_lastStableArea=null;_autoCaptureFired=!1;_lastGoodStatus=null;_lastGoodAt=0;_lastStatusForCaptureGate=null;_lastLookForwardGateOk=null;_forcedHintMessage=null;_poseLatch={left:0,right:0,up:0,down:0,at:0};_lastPoseChallenge=null;_mouthJawBaseline=null;_faceLostAt=null;_lookForwardOkSince=null;_blinkCount=0;_blinkPrevClosed=!1;_cheeseBaseline=null;_cheeseBaselineSamples=0;_cheeseBaselineSum=0;_cheeseBaselineStartedAt=null;_challengeHoldSince=null;_challengeLastStepOk=!1;_challengeHoldProgress=0;_challengeUiProgress=0;_startOptions=null;_previewBlob=null;_previewActions=null;_cheeseWindow=[];_cheeseWindowStart=null;_openMouthWindow=[];_openMouthWindowStart=null;_lifecycle=`idle`;_loopActive=!1;_debug=!1;_isCapturing=!1;_userPreviewUi=null;_userPreviewUrl=null;_loader=null;_captureBtn=null;_disposeCaptureButton(){try{this._captureBtn?.dispose()}catch{}this._captureBtn=null}_syncCaptureButton(e){let t=this._options;if(!t||!this._container)return;let n=t.uiMode===`Mobile`,r=t.captureButton?.enabled!==!1,i=t.autoCapture?.enabled===!0;if(!(n&&r&&!i)){this._captureBtn&&this._disposeCaptureButton();return}this._captureBtn||=W_({container:this._container,text:t.captureButton?.text??`Capturar imagem`,color:t.captureButton?.color??`#00bcd4`,onClick:()=>{this.capture().catch(()=>{})}});let a=e??this._state;if(this._lifecycle===`preview`){this._captureBtn.hide();return}let o=a?.challenge?.enabled?a.challenge.completed===!0:!0;this._lifecycle===`running`&&o?this._captureBtn.show():this._captureBtn.hide();let s=a?.isReadyToCapture===!0&&(a?.challenge?.enabled?a.challenge.completed===!0:!0),c=this._options?.requireLookForwardForCapture===!0,l=this._lastStatusForCaptureGate??this._lastGoodStatus??{},u=c?this._isLookForwardForCapture(l,{requireLf:c}):!0;c&&s&&!u?this._forcedHintMessage=`olhe para a camera`:this._forcedHintMessage=null,this._captureBtn.setEnabled(s&&u)}_setLifecycle(e){this._debug&&console.log(`[AlphaValid] lifecycle ${this._lifecycle} → ${e}`),this._lifecycle=e}async _pause(){if(this._lifecycle===`running`){this._loopTimer!=null&&(window.clearTimeout(this._loopTimer),this._loopTimer=null);try{this._camera?.video?.pause()}catch{}this._loopActive=!1,this._setLifecycle(`paused`)}}async _retakeFromPreview(){this._debug&&console.log(`[AlphaValid] preview action: retake()`,{lifecycle:this._lifecycle,hasCamera:!!this._camera,hasOptions:!!this._options,hasStartOptions:!!this._startOptions}),this._previewBlob=null,this._previewActions=null,this._hideUserPreviewUi();let e=this._startOptions;if(!e){this._debug&&console.warn(`[AlphaValid] retake ignored: missing _startOptions (cannot restart)`);return}try{await this.stop(),await this.start(e)}catch(e){throw this._debug&&console.error(`[AlphaValid] retake failed`,e),e}}async _confirmFromPreview(){if(this._debug&&console.log(`[AlphaValid] preview action: confirm()`,{lifecycle:this._lifecycle,hasBlob:!!this._previewBlob}),this._lifecycle!==`preview`){this._debug&&console.warn(`[AlphaValid] confirm ignored: not in preview`,{lifecycle:this._lifecycle});return}let e=this._previewBlob;if(e){if(this._options?.userPreview&&this._options?.uiMode===`Mobile`)try{this._options?.onUserPreviewConfirm?.(e)}catch{}else this._options?.autoCapture?.onCapture?.(e),this._options?.onCapture?.(e);this._hideUserPreviewUi(),this._previewBlob=null,this._previewActions=null,await this.stop()}}_hideUserPreviewUi(){try{this._userPreviewUi?.hide()}catch{}if(this._userPreviewUrl){try{URL.revokeObjectURL(this._userPreviewUrl)}catch{}this._userPreviewUrl=null}}_disposeUserPreviewUi(){this._hideUserPreviewUi();try{this._userPreviewUi?.dispose()}catch{}this._userPreviewUi=null}async _showPreview(e){if(this._debug&&console.log(`[AlphaValid] entering preview`,{lifecycle:this._lifecycle,blobSize:e?.size}),this._lifecycle!==`paused`&&this._lifecycle!==`preview`){this._debug&&console.warn(`[AlphaValid] _showPreview ignored due to lifecycle`,{lifecycle:this._lifecycle});return}this._setLifecycle(`preview`),this._previewBlob=e,this._previewActions={retake:()=>{this._debug&&console.log(`[AlphaValid] preview action clicked: retake`),this._retakeFromPreview()},confirm:()=>{this._debug&&console.log(`[AlphaValid] preview action clicked: confirm`),this._confirmFromPreview()}};let t=this._options;if(t?.userPreview&&t?.uiMode===`Mobile`&&this._container&&t){if(this._userPreviewUi||=R_({container:this._container,labels:z_(t),onOk:()=>this._previewActions?.confirm(),onRetake:()=>this._previewActions?.retake()}),this._userPreviewUrl)try{URL.revokeObjectURL(this._userPreviewUrl)}catch{}this._userPreviewUrl=URL.createObjectURL(e);let n=`preview: ${(e.size/1024).toFixed(1)} KB · ${new Date().toLocaleTimeString()}`;this._userPreviewUi.show(this._userPreviewUrl,n);return}t?.onPreview?.(e,this._previewActions)}_setVideoVisibility(e){let t=this._camera?.video;if(t)try{e?(t.style.visibility=`visible`,t.style.opacity=`1`,t.style.pointerEvents=`auto`):(t.style.visibility=`hidden`,t.style.opacity=`0`,t.style.pointerEvents=`none`),t.style.transition||(t.style.transition=`opacity 160ms ease`)}catch{}}async start(e){if(this._lifecycle===`running`||this._lifecycle===`preview`)return;this._debug=typeof e.debug==`boolean`?e.debug:!!e.debug?.enabled;let t=e.container??document.getElementById(Q_);if(!t)throw Error(`[AlphaValid] Container nao encontrado. Informe options.container ou crie <div id="${Q_}"></div>.`);f(t,`options.container`);let n=e.liveness;if(e.livenessPreset){let t=e.livenessPreset,r={};t===`normal`||(t===`easy`?(r.strictness=.3,r.lookForwardTolerance=.85,r.lookForwardYawTol=.1,r.lookSideTol=.08,r.lookUpDownTol=.16,r.poseProgressAccept=.55):t===`strict`&&(r.strictness=.8,r.lookForwardTolerance=.6,r.lookForwardYawTol=.04,r.lookSideTol=.03,r.lookUpDownTol=.08,r.poseProgressAccept=.8,r.lookForwardHoldMs=1200,r.challengeMinHoldMs=220)),n={...r,...e.liveness}}let r={...e,container:t,liveness:n};this._startOptions=r,await this.stop(),this._blinkCount=0,this._blinkPrevClosed=!1,this._options={overlay:!0,uiMode:`Mobile`,guideCircleRatio:.72,detectionIntervalMs:50,modelsPath:`/assets/alphavalid-models`,userPreview:!0,previewOkText:`OK`,previewRetakeText:`Tirar outra`,loader:{enabled:!0,src:`/assets/images/alphaloader.gif`,sizePx:120,minVisibleMs:900},captureButton:{enabled:!0,text:`Capturar imagem`,color:`#00bcd4`},requireLookForwardForCapture:!0,...r};let i=this._options;this._container=t;let a=t;if(!a)throw Error(`[AlphaValid] Container nao encontrado apos inicializacao.`);try{G_(a)}catch{}i.loader?.enabled!==!1&&(this._loader?.dispose(),this._loader=H_(a,i.loader),this._loader.show()),this._disposeCaptureButton(),this._status=`initializing`,i.onStateChange?.({status:this._status,feedback:{code:`INITIALIZING`,message:`Inicializando câmera...`},message:`Inicializando câmera...`,isReadyToCapture:!1,challenge:{enabled:!1,index:0,total:0,completed:!1}});try{i.onFeedback?.({code:`INITIALIZING`,message:`Inicializando câmera...`}),this._camera=await m(a),this._setVideoVisibility(!1),i.uiMode!==`headless`&&i.overlay!==!1&&(i.uiMode===`Mobile`?this._overlay=I_(a):this._overlay=b(a,i.guideCircleRatio));let t=i.modelsPath;t&&t.trim()===``&&(t=void 0);let n=await(async()=>{let e=t;if(e)try{return await $_(e),e}catch{}for(let e of Z_)try{return await $_(e),e}catch{}throw Error(`
3845
3845
  [AlphaValid] Models não encontrados.
3846
3846
 
3847
- Execute automaticamente:
3847
+ Execute automaticamente (Angular / Vite):
3848
3848
  npx alphavalid-sdk setup
3849
3849
 
3850
- Ou configure manualmente:
3850
+ Ou configure manualmente no start():
3851
3851
  modelsPath: '/assets/alphavalid-models'
3852
- `)}await this._faceDetector.load(t),this._loader?.hide(),this._setVideoVisibility(!0),this._syncCaptureButton(null),i.onReady?.(),this._status=`running`,this._setLifecycle(`running`),this.startDetectionLoop()}catch(e){this._loader?.hide(),this._disposeCaptureButton(),this._setVideoVisibility(!1),this._status=`error`;let t=e,n=t&&typeof t==`object`&&typeof t.code==`string`&&typeof t.message==`string`?t:{code:`CAMERA_UNKNOWN`,message:`Erro inesperado ao iniciar o SDK.`,cause:e};throw this._options?.onError?.(n),this._options?.onStateChange?.({status:this._status,feedback:{code:`FACE_NOT_FOUND`,message:`Centralize seu rosto`},message:`Centralize seu rosto`,isReadyToCapture:!1,challenge:{enabled:!1,index:0,total:0,completed:!1}}),await this.stop(),e}e.debug&&(console.log(`[AlphaValid] SDK iniciado`),console.log(`[AlphaValid] modelsPath:`,e.modelsPath))}async stop(){this._loopTimer!=null&&(window.clearTimeout(this._loopTimer),this._loopTimer=null),this._loopActive=!1,this._lastStatusValid=!1,this._overlay&&=(this._overlay.dispose(),null),this._camera&&=(this._setVideoVisibility(!1),this._camera.stop(),null),this._previewBlob=null,this._previewActions=null,this._disposeUserPreviewUi(),this._disposeCaptureButton(),this._loader&&=(this._loader.dispose(),null),this._container=null,this._options=null,this._challengeIndex=0,this._challengeStartedAt=null,this._challengeEnterAt=null,this._challengeCompletedAt=null,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._state=null,this._lifecycle===`idle`?this._status=`idle`:this._status=`stopped`,this._stableSince=null,this._lastStableCx=null,this._lastStableCy=null,this._lastStableArea=null,this._autoCaptureFired=!1,this._lastGoodStatus=null,this._lastGoodAt=0,this._faceLostAt=null,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._mouthJawBaseline=null,this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._challengeUiProgress=0,this._blinkCount=0,this._blinkPrevClosed=!1,this._cheeseBaseline=null,this._cheeseBaselineSamples=0,this._cheeseBaselineSum=0,this._cheeseBaselineStartedAt=null,this._setLifecycle(`stopped`)}get _isInPreview(){return this._lifecycle===`preview`}async capture(){if(this._lifecycle!==`running`)throw Error(`SDK is not running. Call start() first.`);if(this._isCapturing)throw Error(`Capture already in progress.`);this._isCapturing=!0;try{if(!this._camera)throw Error(`Camera not started. Call start() first.`);if(this._options?.requireLookForwardForCapture===!0){let e=this._lastStatusForCaptureGate??this._lastGoodStatus??{},t=this._isLookForwardForCapture(e);if(console.log(`[AlphaValid][capture][lookForwardGate]`,{ok:t,jawTopL:e?.jawTopL,jawTopR:e?.jawTopR,leftEyeCenter:e?.leftEyeCenter,rightEyeCenter:e?.rightEyeCenter,mouthVsJawMidRaw:e?.mouthVsJawMidRaw,poseSource:e?.poseSource,faces:e?.faces}),!t)throw Error(`LookForward gate blocked capture. User is not facing forward.`)}if(!this._lastStatusValid)throw Error(`Face not valid for capture yet. Wait for feedback "Pronto para capturar".`);if(this._isInPreview)throw Error(`Já existe uma captura em preview.`);let e=await h(this._camera.video,.9);return await this._pause(),(this._options?.userPreview&&this._options?.uiMode===`Mobile`||this._options?.onPreview)&&(this._syncCaptureButton({...this._state,isReadyToCapture:!1}),await this._showPreview(e)),e}finally{this._isCapturing=!1}}getState(){return this._state}resetChallenges(){this._challengeIndex=0,this._challengeStartedAt=null,this._challengeEnterAt=null,this._challengeCompletedAt=null,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._stableSince=null,this._autoCaptureFired=!1,this._mouthJawBaseline=null,this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._challengeUiProgress=0}getCurrentChallenge(){let e=this._options?.liveness?.challenges;return!e||e.length===0?null:e[this._challengeIndex]?.type??null}markStepCompletedIfNeeded(e,t){let n=this._options,r=n?.liveness?.challenges;if(!n||!r||r.length===0)return;let i=this.getCurrentChallenge();if(!i)return;let a=n.liveness?.challengeMinHoldMs??350,o=Date.now(),s=`${this._challengeIndex}:${i}`;this._uiStepKey!==s&&(this._uiStepKey=s,this._challengeUiProgress=0);let c=(i===`lookUp`||i===`lookDown`)&&e===!0,l=i!==`lookForward`,u=c?!0:e;if(i===`blink`){let e=t?.leftEyeOpenProb,n=t?.rightEyeOpenProb;if(typeof e!=`number`||typeof n!=`number`)return;let r=.9,i=e<r&&n<r;if(!this._blinkArmed){if(!(e>=r&&n>=r))return;this._blinkArmed=!0;return}if(!i)return;this._blinkCount+=1,l=!1,u=!0}if(i===`cheese`){let e=t?.mouthSmileRatio,n=this._options?.liveness?.cheeseThreshold??.08,r;if(this._options?.liveness?.cheeseUseBaseline!==!1&&this._cheeseBaseline!=null?r=this._cheeseBaseline+n:this._options?.liveness?.cheeseUseBaseline===!1&&(r=n),typeof e==`number`&&typeof r==`number`&&e>r){this._challengeIndex+=1,this._challengeStartedAt=o,this._challengeEnterAt=o,this._challengeCompletedAt=o,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._cheeseWindow=[],this._cheeseWindowStart=null;return}}if(i===`openMouth`){let e=t?.mouthOpenRatio;if(typeof e==`number`&&e>.5){this._challengeIndex+=1,this._challengeStartedAt=o,this._challengeEnterAt=o,this._challengeCompletedAt=o,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._openMouthWindow=[],this._openMouthWindowStart=null;return}}if(i===`mouthWidth`){let e=t?.mouthWidthRatio;window.mouthWidthRatioDebug=e,console.log(`[AlphaValid][mouthWidth][REALTIME] mouthWidthRatio:`,e,`| challengeIndex:`,this._challengeIndex,`| debug:`,t)}if((i===`cheese`||i===`openMouth`)&&!t?.stepPassed&&(u=!1),l){if(i===`lookLeft`||i===`lookRight`||i===`lookUp`||i===`lookDown`){let e=typeof t?.poseProgress==`number`?t.poseProgress:0,n=Math.max(0,Math.min(1,e));if(!(u&&n>=.98)){this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._challengeUiProgress+=(n-this._challengeUiProgress)*.22;return}this._challengeHoldSince||=o;let r=Math.max(0,o-this._challengeHoldSince);if(this._challengeHoldProgress=Math.max(0,Math.min(1,a>0?r/a:1)),this._challengeUiProgress+=(1-this._challengeUiProgress)*.22,r>=a){this._challengeIndex+=1,this._challengeStartedAt=o,this._challengeEnterAt=o,this._challengeCompletedAt=o,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._challengeUiProgress=0;return}this._challengeLastStepOk=!0;return}if(u){(!this._challengeHoldSince||!this._challengeLastStepOk)&&(this._challengeHoldSince=o);let e=Math.max(0,o-(this._challengeHoldSince??o)),t=Math.max(0,Math.min(1,a>0?e/a:1));if(this._challengeHoldProgress=t,this._challengeUiProgress+=(t-this._challengeUiProgress)*.25,e>=a){this._challengeIndex+=1,this._challengeStartedAt=o,this._challengeEnterAt=o,this._challengeCompletedAt=o,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._challengeUiProgress=0;return}this._challengeLastStepOk=!0}else this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._challengeUiProgress+=(0-this._challengeUiProgress)*.35;return}if(i===`lookForward`){if(this._state?.feedback?.code===`READY`){this._challengeIndex+=1,this._challengeStartedAt=o,this._challengeEnterAt=o,this._challengeCompletedAt=o,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1;return}if(!e){this._challengeEnterAt=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1;return}return}if(i===`openMouth`){let e=t?.mouthOpenRatio;if(typeof e==`number`&&e>.5){this._challengeIndex+=1,this._challengeStartedAt=o,this._challengeEnterAt=o,this._challengeCompletedAt=o,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._openMouthWindow=[],this._openMouthWindowStart=null;return}}u&&(this._challengeIndex+=1,this._challengeStartedAt=o,this._challengeEnterAt=o,this._challengeCompletedAt=o,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1)}mapChallengeToHint(e,t){if(e)return e===`lookLeft`?{type:`arrow`,direction:`left`,label:t}:e===`lookRight`?{type:`arrow`,direction:`right`,label:t}:e===`lookUp`?{type:`arrow`,direction:`up`,label:t}:e===`lookDown`?{type:`arrow`,direction:`down`,label:t}:{type:`pulse`,label:t}}isStableFrame(e){let t=e.box;if(!t)return!1;let n=e.centerX??t.x+t.width/2,r=t.y+t.height/2,i=e.area??t.width*t.height,a=.015;if(this._lastStableCx==null||this._lastStableCy==null||this._lastStableArea==null)return this._lastStableCx=n,this._lastStableCy=r,this._lastStableArea=i,!1;let o=Math.abs(n-this._lastStableCx),s=Math.abs(r-this._lastStableCy),c=Math.abs(i-this._lastStableArea),l=o<=a&&s<=a&&c<=.015,u=(e,t,n)=>e+(t-e)*n,d=l?.15:.35;return this._lastStableCx=u(this._lastStableCx,n,d),this._lastStableCy=u(this._lastStableCy,r,d),this._lastStableArea=u(this._lastStableArea,i,d),l}_isLookForwardForCapture(e,t){let n=e?.jawTopL,r=e?.jawTopR,i=e?.leftEyeCenter,a=e?.rightEyeCenter,o=typeof e?.mouthVsJawMidRaw==`number`?e.mouthVsJawMidRaw:null;if(o==null){let t=e?.mouthLeft,n=e?.mouthRight,r=e?.jawLeft,i=e?.jawRight,a=e?.box?.height;if(t&&n&&r&&i&&typeof a==`number`&&a>1e-6){let e=(t.y+n.y)/2;o=((r.y+i.y)/2-e)/a}}let s=t?.requireLf===!0;if(!n||!r||!i||!a)return!s;let c=Math.hypot(n.x-i.x,n.y-i.y),l=Math.hypot(r.x-a.x,r.y-a.y);return Math.abs(c-l)/Math.max(c,l,1e-6)<=.45&&(typeof o==`number`?o>=-.75&&o<=.75:!0)}startDetectionLoop(){if(this._lifecycle!==`running`||this._loopActive)return;this._loopActive=!0;let e=async()=>{if(!this._loopActive)return;if(this._lifecycle!==`running`){this._loopActive=!1;return}let t=this._startOptions;if(!t){this._loopActive=!1;return}try{let e=this._camera,n=this._options;if(!e||!n){this._loopActive=!1;return}if(this._lifecycle!==`running`){this._loopActive=!1;return}let r=n.liveness?.challenges,i=!!r&&r.length>0,a=r?.length??0,o=!i||this._challengeIndex>=a,s=this.getCurrentChallenge(),c=o?null:s,l=n?.requireLookForwardForCapture===!0,u=n.debug?.drawLandmarks===!0||c!=null||l,d=await this._faceDetector.detect(e.video,{withLandmarks:u});this._lastStatusForCaptureGate=d;let f=c===`lookLeft`||c===`lookRight`||c===`lookUp`||c===`lookDown`,p=n.liveness?.poseGraceMs??900,m=Math.max(p,1400),h=n.liveness?.faceLostGraceMs??900,g=Date.now();d.faces===1&&d.box?(this._lastGoodStatus=d,this._lastGoodAt=g,this._faceLostAt=null):(this._faceLostAt??=g,this._lastGoodStatus&&g-(this._faceLostAt??g)<=h||f&&this._lastGoodStatus&&g-this._lastGoodAt<=m?d=this._lastGoodStatus:f&&(this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._poseLatch={left:0,right:0,up:0,down:0,at:0}));let _=this._faceLostAt!=null&&g-this._faceLostAt<=h,v=F_(d,{...n.liveness,mouthJawBaselineLeft:this._mouthJawBaseline?.left,mouthJawBaselineRight:this._mouthJawBaseline?.right,cheeseBaseline:this._cheeseBaseline??void 0,lookForwardOkSince:this._lookForwardOkSince},n.liveness?.challenges?.length?{current:c}:void 0),y=.9,b=d.leftEyeOpenProb,x=d.rightEyeOpenProb,S=typeof b==`number`&&typeof x==`number`?b<y&&x<y:!1;if(S&&!this._blinkPrevClosed&&(this._blinkCount+=1),this._blinkPrevClosed=S,c===`lookForward`&&v?.debug?.lookForwardOkInstant===!0?this._lookForwardOkSince??=Date.now():this._lookForwardOkSince=null,c===`lookForward`){let e=d.mouthJawLeftDist,t=d.mouthJawRightDist,n=v?.debug?.lookForwardOk;if(typeof e==`number`&&typeof t==`number`&&n){let n=Date.now();if(!this._mouthJawBaseline)this._mouthJawBaseline={left:e,right:t,at:n};else{let r=.18;this._mouthJawBaseline.left=this._mouthJawBaseline.left+(e-this._mouthJawBaseline.left)*r,this._mouthJawBaseline.right=this._mouthJawBaseline.right+(t-this._mouthJawBaseline.right)*r,this._mouthJawBaseline.at=n}}}let C=Date.now();if(f){let e=v?.debug,t=typeof e?.lookLeftProgress==`number`?e.lookLeftProgress:0,n=typeof e?.lookRightProgress==`number`?e.lookRightProgress:0,r=typeof e?.lookUpProgress==`number`?e.lookUpProgress:0,i=typeof e?.lookDownProgress==`number`?e.lookDownProgress:0,a=(this._poseLatch.at?Math.max(0,C-this._poseLatch.at):0)*9e-4,o=(e,t)=>{let n=Math.max(0,e-a);return Math.max(0,Math.min(1,Math.max(n,t)))};this._poseLatch.left=o(this._poseLatch.left,t),this._poseLatch.right=o(this._poseLatch.right,n),this._poseLatch.up=o(this._poseLatch.up,r),this._poseLatch.down=o(this._poseLatch.down,i),this._poseLatch.at=C,v?.debug&&(v.debug.lookLeftProgress=this._poseLatch.left,v.debug.lookRightProgress=this._poseLatch.right,v.debug.lookUpProgress=this._poseLatch.up,v.debug.lookDownProgress=this._poseLatch.down)}else this._poseLatch={left:0,right:0,up:0,down:0,at:0};if(this.markStepCompletedIfNeeded(v.stepOk,{leftEyeOpenProb:d.leftEyeOpenProb,rightEyeOpenProb:d.rightEyeOpenProb,stepPassed:v.debug?.stepPassed,mouthOpenRatio:d.mouthOpenNorm,mouthWidthRatio:v.debug?.mouthWidthRatio,poseProgress:c===`lookLeft`?this._poseLatch.left:c===`lookRight`?this._poseLatch.right:c===`lookUp`?this._poseLatch.up:c===`lookDown`?this._poseLatch.down:0}),c===`zoomIn`||c===`zoomOut`){let e=v.debug?.zoomProgress,t=.55*(typeof e==`number`?Math.max(0,Math.min(1,e)):0);if(v.stepOk){let e=this._options?.liveness?.challengeMinHoldMs??350,n=Date.now();this._challengeHoldSince||=n;let r=Math.max(0,n-this._challengeHoldSince),i=Math.max(0,Math.min(1,e>0?r/e:1));this._challengeHoldProgress=i;let a=.55+.45*i;this._challengeUiProgress+=(Math.max(t,a)-this._challengeUiProgress)*.22}else this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._challengeUiProgress+=(t-this._challengeUiProgress)*.22}let w=!i||this._challengeIndex>=a,T=t.autoCapture?.enabled===!0,E=t.autoCapture?.stableMs??650,D=v.frameOk&&w,O=t?.requireLookForwardForCapture===!0,k=this._lastStatusForCaptureGate??d,A=O?this._isLookForwardForCapture(k,{requireLf:O}):!0;this._lastLookForwardGateOk=A,A||(D=!1),O&&v.frameOk&&w&&console.log(`[AlphaValid][readyGate][lookForward]`,{lfOkForCapture:A,jawTopL:d?.jawTopL,jawTopR:d?.jawTopR,leftEyeCenter:d?.leftEyeCenter,rightEyeCenter:d?.rightEyeCenter,mouthVsJawMidRaw:d?.mouthVsJawMidRaw,poseSource:d?.poseSource}),T&&D?this.isStableFrame(d)?(this._stableSince??=Date.now(),Date.now()-this._stableSince<E&&(D=!1)):(this._stableSince=null,D=!1):this._stableSince=null,this._lastStatusValid=D,this._status=D?`ready`:`running`;let j;j=w?v.feedback.message:v.feedback.code===`READY`?`Siga o desafio`:v.feedback.message,O&&w&&this._lastLookForwardGateOk===!1&&(j=`olhe para a camera`,v.feedback={...v.feedback,code:`LOOK_FORWARD`,message:j});let M=t.liveness?.cheeseThreshold??.08;t.liveness?.cheeseUseBaseline!==!1&&this._cheeseBaseline!=null?this._cheeseBaseline+M:t.liveness?.cheeseUseBaseline;let N={status:this._status,feedback:{...v.feedback,message:j},message:j,isReadyToCapture:D,challenge:{enabled:i,index:this._challengeIndex,total:t.liveness?.challenges?.length??0,current:c??void 0,completed:w},debug:{faces:d.faces,centerX:d.centerX,box:d.box,eyeDist:d.eyeDist,yawProxy:d.yawProxy,leftEyeOpenProb:d.leftEyeOpenProb,rightEyeOpenProb:d.rightEyeOpenProb,blinkCount:this._blinkCount,blinkClosedNow:S,blinkClosedThreshold:y,mouthDebug:{mouthPoints:d.mouthPoints,mouthLeft:d.mouthLeft,mouthRight:d.mouthRight,mouthUpper:d.mouthUpper,mouthLower:d.mouthLower,mouthOpenPx:d.mouthOpenPx,mouthOpenNorm:d.mouthOpenNorm,mouthJawLeftDist:d.mouthJawLeftDist,mouthJawRightDist:d.mouthJawRightDist,mouthSmileRatio:v.debug?.mouthSmileRatio,mouthWidthRatio:v.debug?.mouthWidthRatio,mouthAvg:v.debug?.mouthAvg,mouthVsJawMidRaw:v.debug?.mouthVsJawMidRaw,mouthVsJawMidClamped:v.debug?.mouthVsJawMidClamped,cheeseBaseline:v.debug?.cheeseBaseline,cheeseTarget:v.debug?.cheeseTarget,mouthOpenRatio:v.debug?.mouthOpenRatio},debugDraw:{cheese:n.debug?.draw?.cheese??!0},mouthAvg:v.debug?.mouthAvg??null,jawMid:v.debug?.jawMid??null,faceH:v.debug?.faceH??null,mouthVsJawMidRaw:v.debug?.mouthVsJawMidRaw??null,mouthVsJawMidClamped:v.debug?.mouthVsJawMidClamped??null,currentStep:v.debug?.currentStep??c??null,stepPassed:v.debug?.stepPassed,challengeHoldProgress:this._challengeHoldProgress}};if(this._state=N,t.onStateChange?.(N),t.onFeedback?.(N.feedback),this._syncCaptureButton(N),T&&D&&!this._autoCaptureFired&&!this._isInPreview){this._autoCaptureFired=!0;try{let e=await this.capture();t.onPreview||t.autoCapture?.onCapture?.(e)}catch{this._autoCaptureFired=!1}}D||(this._autoCaptureFired=!1);let P=n.debug?.drawLandmarks===!0,F=n.debug?.draw,ee=(F?.eyes??!1)||(F?.mouth??!1)||(F?.nose??!1)||(F?.jaw??!1)||(F?.mouthJaw??!1),te=w?void 0:this.mapChallengeToHint(c,N.feedback.message),ne=typeof d.yawProxy==`number`?d.yawProxy:null,re=ne==null?Math.max(-1,Math.min(1,((d.centerX??.5)-.5)/.18)):Math.max(-1,Math.min(1,ne/.22)),ie=Math.max(-1,Math.min(1,((d.box?.y??0)+(d.box?.height??0)/2-.5)/.18)),ae=ne==null?`centerX`:`yawProxy`;if(c===`mouthWidth`){let e=N.debug?.mouthWidthRatio;typeof e==`number`&&console.log(`[AlphaValid][landmarks] mouthWidthRatio:`,e)}if(this._overlay){let t;c===`zoomIn`&&(t=`zoomIn`),c===`zoomOut`&&(t=`zoomOut`);let r=n.uiMode===`Mobile`,i=n?.debug?.extra??{},a=i?.showCoxinhaGuides===!0;i?.showCoxinhaProgress;let o=this._forcedHintMessage??N.feedback.message;this._overlay.render({message:o,box:d.box,valid:D,hint:te,challenge:t?{direction:t}:void 0,debug:{blinkClosedNow:S,blinkClosedThreshold:y,challengeHoldProgress:this._challengeUiProgress,mouthDebug:{mouthPoints:d.mouthPoints,mouthLeft:d.mouthLeft,mouthRight:d.mouthRight,mouthUpper:d.mouthUpper,mouthLower:d.mouthLower,mouthOpenPx:d.mouthOpenPx,mouthOpenNorm:d.mouthOpenNorm,mouthJawLeftDist:d.mouthJawLeftDist,mouthJawRightDist:d.mouthJawRightDist,mouthSmileRatio:N.debug?.mouthSmileRatio,mouthWidthRatio:N.debug?.mouthWidthRatio,mouthAvg:N.debug?.mouthAvg,mouthVsJawMidRaw:N.debug?.mouthVsJawMidRaw,mouthVsJawMidClamped:N.debug?.mouthVsJawMidClamped,cheeseBaseline:N.debug?.cheeseBaseline,cheeseTarget:N.debug?.cheeseTarget,mouthOpenRatio:N.debug?.mouthOpenRatio},debugDraw:{cheese:N.debug?.debugDraw?.cheese},mouthAvg:N.debug?.mouthAvg??null,jawMid:N.debug?.jawMid??null,faceH:N.debug?.faceH??null,mouthVsJawMidRaw:N.debug?.mouthVsJawMidRaw??null,mouthVsJawMidClamped:N.debug?.mouthVsJawMidClamped??null,currentStep:N.debug?.currentStep??N.challenge?.current??null,stepPassed:N.debug?.stepPassed,extra:n.debug?.extra},video:e.video,mirrored:!1,poseVector:r&&!a?void 0:{x:re,y:ie,label:ae},landmarks:(P||ee)&&!_?{leftEye:d.leftEyePoints,rightEye:d.rightEyePoints,leftEyeCenter:d.leftEyeCenter,rightEyeCenter:d.rightEyeCenter,noseTip:d.noseTip,nosePoints:d.nosePoints,mouthPoints:d.mouthPoints,mouthLeft:d.mouthLeft,mouthRight:d.mouthRight,jawLeft:d.jawLeft,jawRight:d.jawRight,mouthJawLeftDist:d.mouthJawLeftDist,mouthJawRightDist:d.mouthJawRightDist,jawPoints:d.jawPoints,jawCenter:d.jawCenter,mouthUpper:d.mouthUpper,mouthLower:d.mouthLower,mouthOpenPx:d.mouthOpenPx,mouthOpenNorm:d.mouthOpenNorm,jawTopL:d.jawTopL,jawTopR:d.jawTopR}:void 0,landmarkDraw:P?{eyes:!0,mouth:!0,nose:!0,jaw:!0,mouthJaw:!0,cheese:!0}:{eyes:F?.eyes!==!1,mouth:F?.mouth!==!1,nose:F?.nose!==!1,jaw:F?.jaw!==!1,mouthJaw:F?.mouthJaw!==!1,cheese:F?.cheese===!0}})}}catch(e){this._status=`error`;let n=e,r=n&&typeof n==`object`&&typeof n.code==`string`&&typeof n.message==`string`?n:{code:`CAMERA_UNKNOWN`,message:`Erro durante detecção/validação.`,cause:e};t.onError?.(r),t.onStateChange?.({status:this._status,feedback:{code:`FACE_NOT_FOUND`,message:`Centralize seu rosto`},message:`Centralize seu rosto`,isReadyToCapture:!1,challenge:this._state?.challenge})}finally{if(this._lifecycle!==`running`){this._loopActive=!1;return}let t=this._options?.detectionIntervalMs??50;this._loopTimer=window.setTimeout(e,t)}};e()}},e.setupModels=$_});
3852
+ `)})();e.debug&&console.log(`[AlphaValid] modelsPath resolvido:`,n),await this._faceDetector.load(n),this._loader?.hide(),this._setVideoVisibility(!0),this._syncCaptureButton(null),i.onReady?.(),this._status=`running`,this._setLifecycle(`running`),this.startDetectionLoop()}catch(e){this._loader?.hide(),this._disposeCaptureButton(),this._setVideoVisibility(!1),this._status=`error`;let t=e,n=t&&typeof t==`object`&&typeof t.code==`string`&&typeof t.message==`string`?t:{code:`CAMERA_UNKNOWN`,message:`Erro inesperado ao iniciar o SDK.`,cause:e};throw this._options?.onError?.(n),this._options?.onStateChange?.({status:this._status,feedback:{code:`FACE_NOT_FOUND`,message:`Centralize seu rosto`},message:`Centralize seu rosto`,isReadyToCapture:!1,challenge:{enabled:!1,index:0,total:0,completed:!1}}),await this.stop(),e}e.debug&&(console.log(`[AlphaValid] SDK iniciado`),console.log(`[AlphaValid] modelsPath:`,e.modelsPath))}async stop(){this._loopTimer!=null&&(window.clearTimeout(this._loopTimer),this._loopTimer=null),this._loopActive=!1,this._lastStatusValid=!1,this._overlay&&=(this._overlay.dispose(),null),this._camera&&=(this._setVideoVisibility(!1),this._camera.stop(),null),this._previewBlob=null,this._previewActions=null,this._disposeUserPreviewUi(),this._disposeCaptureButton(),this._loader&&=(this._loader.dispose(),null),this._container=null,this._options=null,this._challengeIndex=0,this._challengeStartedAt=null,this._challengeEnterAt=null,this._challengeCompletedAt=null,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._state=null,this._lifecycle===`idle`?this._status=`idle`:this._status=`stopped`,this._stableSince=null,this._lastStableCx=null,this._lastStableCy=null,this._lastStableArea=null,this._autoCaptureFired=!1,this._lastGoodStatus=null,this._lastGoodAt=0,this._faceLostAt=null,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._mouthJawBaseline=null,this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._challengeUiProgress=0,this._blinkCount=0,this._blinkPrevClosed=!1,this._cheeseBaseline=null,this._cheeseBaselineSamples=0,this._cheeseBaselineSum=0,this._cheeseBaselineStartedAt=null,this._setLifecycle(`stopped`)}get _isInPreview(){return this._lifecycle===`preview`}async capture(){if(this._lifecycle!==`running`)throw Error(`SDK is not running. Call start() first.`);if(this._isCapturing)throw Error(`Capture already in progress.`);this._isCapturing=!0;try{if(!this._camera)throw Error(`Camera not started. Call start() first.`);if(this._options?.requireLookForwardForCapture===!0){let e=this._lastStatusForCaptureGate??this._lastGoodStatus??{},t=this._isLookForwardForCapture(e);if(console.log(`[AlphaValid][capture][lookForwardGate]`,{ok:t,jawTopL:e?.jawTopL,jawTopR:e?.jawTopR,leftEyeCenter:e?.leftEyeCenter,rightEyeCenter:e?.rightEyeCenter,mouthVsJawMidRaw:e?.mouthVsJawMidRaw,poseSource:e?.poseSource,faces:e?.faces}),!t)throw Error(`LookForward gate blocked capture. User is not facing forward.`)}if(!this._lastStatusValid)throw Error(`Face not valid for capture yet. Wait for feedback "Pronto para capturar".`);if(this._isInPreview)throw Error(`Já existe uma captura em preview.`);let e=await h(this._camera.video,.9);return await this._pause(),(this._options?.userPreview&&this._options?.uiMode===`Mobile`||this._options?.onPreview)&&(this._syncCaptureButton({...this._state,isReadyToCapture:!1}),await this._showPreview(e)),e}finally{this._isCapturing=!1}}getState(){return this._state}resetChallenges(){this._challengeIndex=0,this._challengeStartedAt=null,this._challengeEnterAt=null,this._challengeCompletedAt=null,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._stableSince=null,this._autoCaptureFired=!1,this._mouthJawBaseline=null,this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._challengeUiProgress=0}getCurrentChallenge(){let e=this._options?.liveness?.challenges;return!e||e.length===0?null:e[this._challengeIndex]?.type??null}markStepCompletedIfNeeded(e,t){let n=this._options,r=n?.liveness?.challenges;if(!n||!r||r.length===0)return;let i=this.getCurrentChallenge();if(!i)return;let a=n.liveness?.challengeMinHoldMs??350,o=Date.now(),s=`${this._challengeIndex}:${i}`;this._uiStepKey!==s&&(this._uiStepKey=s,this._challengeUiProgress=0);let c=(i===`lookUp`||i===`lookDown`)&&e===!0,l=i!==`lookForward`,u=c?!0:e;if(i===`blink`){let e=t?.leftEyeOpenProb,n=t?.rightEyeOpenProb;if(typeof e!=`number`||typeof n!=`number`)return;let r=.9,i=e<r&&n<r;if(!this._blinkArmed){if(!(e>=r&&n>=r))return;this._blinkArmed=!0;return}if(!i)return;this._blinkCount+=1,l=!1,u=!0}if(i===`cheese`){let e=t?.mouthSmileRatio,n=this._options?.liveness?.cheeseThreshold??.08,r;if(this._options?.liveness?.cheeseUseBaseline!==!1&&this._cheeseBaseline!=null?r=this._cheeseBaseline+n:this._options?.liveness?.cheeseUseBaseline===!1&&(r=n),typeof e==`number`&&typeof r==`number`&&e>r){this._challengeIndex+=1,this._challengeStartedAt=o,this._challengeEnterAt=o,this._challengeCompletedAt=o,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._cheeseWindow=[],this._cheeseWindowStart=null;return}}if(i===`openMouth`){let e=t?.mouthOpenRatio;if(typeof e==`number`&&e>.5){this._challengeIndex+=1,this._challengeStartedAt=o,this._challengeEnterAt=o,this._challengeCompletedAt=o,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._openMouthWindow=[],this._openMouthWindowStart=null;return}}if(i===`mouthWidth`){let e=t?.mouthWidthRatio;window.mouthWidthRatioDebug=e,console.log(`[AlphaValid][mouthWidth][REALTIME] mouthWidthRatio:`,e,`| challengeIndex:`,this._challengeIndex,`| debug:`,t)}if((i===`cheese`||i===`openMouth`)&&!t?.stepPassed&&(u=!1),l){if(i===`lookLeft`||i===`lookRight`||i===`lookUp`||i===`lookDown`){let e=typeof t?.poseProgress==`number`?t.poseProgress:0,n=Math.max(0,Math.min(1,e));if(!(u&&n>=.98)){this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._challengeUiProgress+=(n-this._challengeUiProgress)*.22;return}this._challengeHoldSince||=o;let r=Math.max(0,o-this._challengeHoldSince);if(this._challengeHoldProgress=Math.max(0,Math.min(1,a>0?r/a:1)),this._challengeUiProgress+=(1-this._challengeUiProgress)*.22,r>=a){this._challengeIndex+=1,this._challengeStartedAt=o,this._challengeEnterAt=o,this._challengeCompletedAt=o,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._challengeUiProgress=0;return}this._challengeLastStepOk=!0;return}if(u){(!this._challengeHoldSince||!this._challengeLastStepOk)&&(this._challengeHoldSince=o);let e=Math.max(0,o-(this._challengeHoldSince??o)),t=Math.max(0,Math.min(1,a>0?e/a:1));if(this._challengeHoldProgress=t,this._challengeUiProgress+=(t-this._challengeUiProgress)*.25,e>=a){this._challengeIndex+=1,this._challengeStartedAt=o,this._challengeEnterAt=o,this._challengeCompletedAt=o,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._challengeUiProgress=0;return}this._challengeLastStepOk=!0}else this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._challengeUiProgress+=(0-this._challengeUiProgress)*.35;return}if(i===`lookForward`){if(this._state?.feedback?.code===`READY`){this._challengeIndex+=1,this._challengeStartedAt=o,this._challengeEnterAt=o,this._challengeCompletedAt=o,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1;return}if(!e){this._challengeEnterAt=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1;return}return}if(i===`openMouth`){let e=t?.mouthOpenRatio;if(typeof e==`number`&&e>.5){this._challengeIndex+=1,this._challengeStartedAt=o,this._challengeEnterAt=o,this._challengeCompletedAt=o,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._openMouthWindow=[],this._openMouthWindowStart=null;return}}u&&(this._challengeIndex+=1,this._challengeStartedAt=o,this._challengeEnterAt=o,this._challengeCompletedAt=o,this._challengeBaselineSeen=!1,this._blinkArmed=!1,this._poseLatch={left:0,right:0,up:0,down:0,at:0},this._lookForwardOkSince=null,this._challengeHoldSince=null,this._challengeLastStepOk=!1)}mapChallengeToHint(e,t){if(e)return e===`lookLeft`?{type:`arrow`,direction:`left`,label:t}:e===`lookRight`?{type:`arrow`,direction:`right`,label:t}:e===`lookUp`?{type:`arrow`,direction:`up`,label:t}:e===`lookDown`?{type:`arrow`,direction:`down`,label:t}:{type:`pulse`,label:t}}isStableFrame(e){let t=e.box;if(!t)return!1;let n=e.centerX??t.x+t.width/2,r=t.y+t.height/2,i=e.area??t.width*t.height,a=.015;if(this._lastStableCx==null||this._lastStableCy==null||this._lastStableArea==null)return this._lastStableCx=n,this._lastStableCy=r,this._lastStableArea=i,!1;let o=Math.abs(n-this._lastStableCx),s=Math.abs(r-this._lastStableCy),c=Math.abs(i-this._lastStableArea),l=o<=a&&s<=a&&c<=.015,u=(e,t,n)=>e+(t-e)*n,d=l?.15:.35;return this._lastStableCx=u(this._lastStableCx,n,d),this._lastStableCy=u(this._lastStableCy,r,d),this._lastStableArea=u(this._lastStableArea,i,d),l}_isLookForwardForCapture(e,t){let n=e?.jawTopL,r=e?.jawTopR,i=e?.leftEyeCenter,a=e?.rightEyeCenter,o=typeof e?.mouthVsJawMidRaw==`number`?e.mouthVsJawMidRaw:null;if(o==null){let t=e?.mouthLeft,n=e?.mouthRight,r=e?.jawLeft,i=e?.jawRight,a=e?.box?.height;if(t&&n&&r&&i&&typeof a==`number`&&a>1e-6){let e=(t.y+n.y)/2;o=((r.y+i.y)/2-e)/a}}let s=t?.requireLf===!0;if(!n||!r||!i||!a)return!s;let c=Math.hypot(n.x-i.x,n.y-i.y),l=Math.hypot(r.x-a.x,r.y-a.y);return Math.abs(c-l)/Math.max(c,l,1e-6)<=.45&&(typeof o==`number`?o>=-.75&&o<=.75:!0)}startDetectionLoop(){if(this._lifecycle!==`running`||this._loopActive)return;this._loopActive=!0;let e=async()=>{if(!this._loopActive)return;if(this._lifecycle!==`running`){this._loopActive=!1;return}let t=this._startOptions;if(!t){this._loopActive=!1;return}try{let e=this._camera,n=this._options;if(!e||!n){this._loopActive=!1;return}if(this._lifecycle!==`running`){this._loopActive=!1;return}let r=n.liveness?.challenges,i=!!r&&r.length>0,a=r?.length??0,o=!i||this._challengeIndex>=a,s=this.getCurrentChallenge(),c=o?null:s,l=n?.requireLookForwardForCapture===!0,u=n.debug?.drawLandmarks===!0||c!=null||l,d=await this._faceDetector.detect(e.video,{withLandmarks:u});this._lastStatusForCaptureGate=d;let f=c===`lookLeft`||c===`lookRight`||c===`lookUp`||c===`lookDown`,p=n.liveness?.poseGraceMs??900,m=Math.max(p,1400),h=n.liveness?.faceLostGraceMs??900,g=Date.now();d.faces===1&&d.box?(this._lastGoodStatus=d,this._lastGoodAt=g,this._faceLostAt=null):(this._faceLostAt??=g,this._lastGoodStatus&&g-(this._faceLostAt??g)<=h||f&&this._lastGoodStatus&&g-this._lastGoodAt<=m?d=this._lastGoodStatus:f&&(this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._poseLatch={left:0,right:0,up:0,down:0,at:0}));let _=this._faceLostAt!=null&&g-this._faceLostAt<=h,v=F_(d,{...n.liveness,mouthJawBaselineLeft:this._mouthJawBaseline?.left,mouthJawBaselineRight:this._mouthJawBaseline?.right,cheeseBaseline:this._cheeseBaseline??void 0,lookForwardOkSince:this._lookForwardOkSince},n.liveness?.challenges?.length?{current:c}:void 0),y=.9,b=d.leftEyeOpenProb,x=d.rightEyeOpenProb,S=typeof b==`number`&&typeof x==`number`?b<y&&x<y:!1;if(S&&!this._blinkPrevClosed&&(this._blinkCount+=1),this._blinkPrevClosed=S,c===`lookForward`&&v?.debug?.lookForwardOkInstant===!0?this._lookForwardOkSince??=Date.now():this._lookForwardOkSince=null,c===`lookForward`){let e=d.mouthJawLeftDist,t=d.mouthJawRightDist,n=v?.debug?.lookForwardOk;if(typeof e==`number`&&typeof t==`number`&&n){let n=Date.now();if(!this._mouthJawBaseline)this._mouthJawBaseline={left:e,right:t,at:n};else{let r=.18;this._mouthJawBaseline.left=this._mouthJawBaseline.left+(e-this._mouthJawBaseline.left)*r,this._mouthJawBaseline.right=this._mouthJawBaseline.right+(t-this._mouthJawBaseline.right)*r,this._mouthJawBaseline.at=n}}}let C=Date.now();if(f){let e=v?.debug,t=typeof e?.lookLeftProgress==`number`?e.lookLeftProgress:0,n=typeof e?.lookRightProgress==`number`?e.lookRightProgress:0,r=typeof e?.lookUpProgress==`number`?e.lookUpProgress:0,i=typeof e?.lookDownProgress==`number`?e.lookDownProgress:0,a=(this._poseLatch.at?Math.max(0,C-this._poseLatch.at):0)*9e-4,o=(e,t)=>{let n=Math.max(0,e-a);return Math.max(0,Math.min(1,Math.max(n,t)))};this._poseLatch.left=o(this._poseLatch.left,t),this._poseLatch.right=o(this._poseLatch.right,n),this._poseLatch.up=o(this._poseLatch.up,r),this._poseLatch.down=o(this._poseLatch.down,i),this._poseLatch.at=C,v?.debug&&(v.debug.lookLeftProgress=this._poseLatch.left,v.debug.lookRightProgress=this._poseLatch.right,v.debug.lookUpProgress=this._poseLatch.up,v.debug.lookDownProgress=this._poseLatch.down)}else this._poseLatch={left:0,right:0,up:0,down:0,at:0};if(this.markStepCompletedIfNeeded(v.stepOk,{leftEyeOpenProb:d.leftEyeOpenProb,rightEyeOpenProb:d.rightEyeOpenProb,stepPassed:v.debug?.stepPassed,mouthOpenRatio:d.mouthOpenNorm,mouthWidthRatio:v.debug?.mouthWidthRatio,poseProgress:c===`lookLeft`?this._poseLatch.left:c===`lookRight`?this._poseLatch.right:c===`lookUp`?this._poseLatch.up:c===`lookDown`?this._poseLatch.down:0}),c===`zoomIn`||c===`zoomOut`){let e=v.debug?.zoomProgress,t=.55*(typeof e==`number`?Math.max(0,Math.min(1,e)):0);if(v.stepOk){let e=this._options?.liveness?.challengeMinHoldMs??350,n=Date.now();this._challengeHoldSince||=n;let r=Math.max(0,n-this._challengeHoldSince),i=Math.max(0,Math.min(1,e>0?r/e:1));this._challengeHoldProgress=i;let a=.55+.45*i;this._challengeUiProgress+=(Math.max(t,a)-this._challengeUiProgress)*.22}else this._challengeHoldSince=null,this._challengeLastStepOk=!1,this._challengeHoldProgress=0,this._challengeUiProgress+=(t-this._challengeUiProgress)*.22}let w=!i||this._challengeIndex>=a,T=t.autoCapture?.enabled===!0,E=t.autoCapture?.stableMs??650,D=v.frameOk&&w,O=t?.requireLookForwardForCapture===!0,k=this._lastStatusForCaptureGate??d,A=O?this._isLookForwardForCapture(k,{requireLf:O}):!0;this._lastLookForwardGateOk=A,A||(D=!1),O&&v.frameOk&&w&&console.log(`[AlphaValid][readyGate][lookForward]`,{lfOkForCapture:A,jawTopL:d?.jawTopL,jawTopR:d?.jawTopR,leftEyeCenter:d?.leftEyeCenter,rightEyeCenter:d?.rightEyeCenter,mouthVsJawMidRaw:d?.mouthVsJawMidRaw,poseSource:d?.poseSource}),T&&D?this.isStableFrame(d)?(this._stableSince??=Date.now(),Date.now()-this._stableSince<E&&(D=!1)):(this._stableSince=null,D=!1):this._stableSince=null,this._lastStatusValid=D,this._status=D?`ready`:`running`;let j;j=w?v.feedback.message:v.feedback.code===`READY`?`Siga o desafio`:v.feedback.message,O&&w&&this._lastLookForwardGateOk===!1&&(j=`olhe para a camera`,v.feedback={...v.feedback,code:`LOOK_FORWARD`,message:j});let M=t.liveness?.cheeseThreshold??.08;t.liveness?.cheeseUseBaseline!==!1&&this._cheeseBaseline!=null?this._cheeseBaseline+M:t.liveness?.cheeseUseBaseline;let N={status:this._status,feedback:{...v.feedback,message:j},message:j,isReadyToCapture:D,challenge:{enabled:i,index:this._challengeIndex,total:t.liveness?.challenges?.length??0,current:c??void 0,completed:w},debug:{faces:d.faces,centerX:d.centerX,box:d.box,eyeDist:d.eyeDist,yawProxy:d.yawProxy,leftEyeOpenProb:d.leftEyeOpenProb,rightEyeOpenProb:d.rightEyeOpenProb,blinkCount:this._blinkCount,blinkClosedNow:S,blinkClosedThreshold:y,mouthDebug:{mouthPoints:d.mouthPoints,mouthLeft:d.mouthLeft,mouthRight:d.mouthRight,mouthUpper:d.mouthUpper,mouthLower:d.mouthLower,mouthOpenPx:d.mouthOpenPx,mouthOpenNorm:d.mouthOpenNorm,mouthJawLeftDist:d.mouthJawLeftDist,mouthJawRightDist:d.mouthJawRightDist,mouthSmileRatio:v.debug?.mouthSmileRatio,mouthWidthRatio:v.debug?.mouthWidthRatio,mouthAvg:v.debug?.mouthAvg,mouthVsJawMidRaw:v.debug?.mouthVsJawMidRaw,mouthVsJawMidClamped:v.debug?.mouthVsJawMidClamped,cheeseBaseline:v.debug?.cheeseBaseline,cheeseTarget:v.debug?.cheeseTarget,mouthOpenRatio:v.debug?.mouthOpenRatio},debugDraw:{cheese:n.debug?.draw?.cheese??!0},mouthAvg:v.debug?.mouthAvg??null,jawMid:v.debug?.jawMid??null,faceH:v.debug?.faceH??null,mouthVsJawMidRaw:v.debug?.mouthVsJawMidRaw??null,mouthVsJawMidClamped:v.debug?.mouthVsJawMidClamped??null,currentStep:v.debug?.currentStep??c??null,stepPassed:v.debug?.stepPassed,challengeHoldProgress:this._challengeHoldProgress}};if(this._state=N,t.onStateChange?.(N),t.onFeedback?.(N.feedback),this._syncCaptureButton(N),T&&D&&!this._autoCaptureFired&&!this._isInPreview){this._autoCaptureFired=!0;try{let e=await this.capture();t.onPreview||t.autoCapture?.onCapture?.(e)}catch{this._autoCaptureFired=!1}}D||(this._autoCaptureFired=!1);let P=n.debug?.drawLandmarks===!0,F=n.debug?.draw,ee=(F?.eyes??!1)||(F?.mouth??!1)||(F?.nose??!1)||(F?.jaw??!1)||(F?.mouthJaw??!1),te=w?void 0:this.mapChallengeToHint(c,N.feedback.message),ne=typeof d.yawProxy==`number`?d.yawProxy:null,re=ne==null?Math.max(-1,Math.min(1,((d.centerX??.5)-.5)/.18)):Math.max(-1,Math.min(1,ne/.22)),ie=Math.max(-1,Math.min(1,((d.box?.y??0)+(d.box?.height??0)/2-.5)/.18)),ae=ne==null?`centerX`:`yawProxy`;if(c===`mouthWidth`){let e=N.debug?.mouthWidthRatio;typeof e==`number`&&console.log(`[AlphaValid][landmarks] mouthWidthRatio:`,e)}if(this._overlay){let t;c===`zoomIn`&&(t=`zoomIn`),c===`zoomOut`&&(t=`zoomOut`);let r=n.uiMode===`Mobile`,i=n?.debug?.extra??{},a=i?.showCoxinhaGuides===!0;i?.showCoxinhaProgress;let o=this._forcedHintMessage??N.feedback.message;this._overlay.render({message:o,box:d.box,valid:D,hint:te,challenge:t?{direction:t}:void 0,debug:{blinkClosedNow:S,blinkClosedThreshold:y,challengeHoldProgress:this._challengeUiProgress,mouthDebug:{mouthPoints:d.mouthPoints,mouthLeft:d.mouthLeft,mouthRight:d.mouthRight,mouthUpper:d.mouthUpper,mouthLower:d.mouthLower,mouthOpenPx:d.mouthOpenPx,mouthOpenNorm:d.mouthOpenNorm,mouthJawLeftDist:d.mouthJawLeftDist,mouthJawRightDist:d.mouthJawRightDist,mouthSmileRatio:N.debug?.mouthSmileRatio,mouthWidthRatio:N.debug?.mouthWidthRatio,mouthAvg:N.debug?.mouthAvg,mouthVsJawMidRaw:N.debug?.mouthVsJawMidRaw,mouthVsJawMidClamped:N.debug?.mouthVsJawMidClamped,cheeseBaseline:N.debug?.cheeseBaseline,cheeseTarget:N.debug?.cheeseTarget,mouthOpenRatio:N.debug?.mouthOpenRatio},debugDraw:{cheese:N.debug?.debugDraw?.cheese},mouthAvg:N.debug?.mouthAvg??null,jawMid:N.debug?.jawMid??null,faceH:N.debug?.faceH??null,mouthVsJawMidRaw:N.debug?.mouthVsJawMidRaw??null,mouthVsJawMidClamped:N.debug?.mouthVsJawMidClamped??null,currentStep:N.debug?.currentStep??N.challenge?.current??null,stepPassed:N.debug?.stepPassed,extra:n.debug?.extra},video:e.video,mirrored:!1,poseVector:r&&!a?void 0:{x:re,y:ie,label:ae},landmarks:(P||ee)&&!_?{leftEye:d.leftEyePoints,rightEye:d.rightEyePoints,leftEyeCenter:d.leftEyeCenter,rightEyeCenter:d.rightEyeCenter,noseTip:d.noseTip,nosePoints:d.nosePoints,mouthPoints:d.mouthPoints,mouthLeft:d.mouthLeft,mouthRight:d.mouthRight,jawLeft:d.jawLeft,jawRight:d.jawRight,mouthJawLeftDist:d.mouthJawLeftDist,mouthJawRightDist:d.mouthJawRightDist,jawPoints:d.jawPoints,jawCenter:d.jawCenter,mouthUpper:d.mouthUpper,mouthLower:d.mouthLower,mouthOpenPx:d.mouthOpenPx,mouthOpenNorm:d.mouthOpenNorm,jawTopL:d.jawTopL,jawTopR:d.jawTopR}:void 0,landmarkDraw:P?{eyes:!0,mouth:!0,nose:!0,jaw:!0,mouthJaw:!0,cheese:!0}:{eyes:F?.eyes!==!1,mouth:F?.mouth!==!1,nose:F?.nose!==!1,jaw:F?.jaw!==!1,mouthJaw:F?.mouthJaw!==!1,cheese:F?.cheese===!0}})}}catch(e){this._status=`error`;let n=e,r=n&&typeof n==`object`&&typeof n.code==`string`&&typeof n.message==`string`?n:{code:`CAMERA_UNKNOWN`,message:`Erro durante detecção/validação.`,cause:e};t.onError?.(r),t.onStateChange?.({status:this._status,feedback:{code:`FACE_NOT_FOUND`,message:`Centralize seu rosto`},message:`Centralize seu rosto`,isReadyToCapture:!1,challenge:this._state?.challenge})}finally{if(this._lifecycle!==`running`){this._loopActive=!1;return}let t=this._options?.detectionIntervalMs??50;this._loopTimer=window.setTimeout(e,t)}};e()}},e.setupModels=ev});
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,oBAAoB,CAAC,EAAE,MAAM,CAAC;KAC/B;CACF;AAED,OAAO,KAAK,EAA2B,sBAAsB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAqCpG,wBAAsB,WAAW,oBAGhC;AAID,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,UAAU,CAA4B;IAC9C,OAAO,CAAC,aAAa,CAAsC;IAC3D,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAuC;IAEvD,OAAO,CAAC,OAAO,CAAkD;IAEjE,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,mBAAmB,CAAuB;IAClD,OAAO,CAAC,iBAAiB,CAAuB;IAChD,OAAO,CAAC,qBAAqB,CAAuB;IACpD,OAAO,CAAC,sBAAsB,CAAS;IACvC,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO,CAAC,MAAM,CAAgC;IAG9C,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,iBAAiB,CAAS;IAGlC,OAAO,CAAC,eAAe,CAA0D;IACjF,OAAO,CAAC,WAAW,CAAa;IAEhC;;;OAGG;IACH,OAAO,CAAC,yBAAyB,CAA0D;IAC3F,OAAO,CAAC,sBAAsB,CAAwB;IACtD,OAAO,CAAC,kBAAkB,CAAuB;IAGjD,OAAO,CAAC,UAAU,CAMhB;IAEF,OAAO,CAAC,kBAAkB,CAAwC;IAGlE,OAAO,CAAC,iBAAiB,CAA4D;IAGrF,OAAO,CAAC,WAAW,CAAuB;IAG1C,OAAO,CAAC,mBAAmB,CAAuB;IAGlD,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,gBAAgB,CAAkB;IAG1C,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,sBAAsB,CAAK;IACnC,OAAO,CAAC,kBAAkB,CAAK;IAC/B,OAAO,CAAC,wBAAwB,CAAuB;IAGvD,OAAO,CAAC,mBAAmB,CAAuB;IAClD,OAAO,CAAC,oBAAoB,CAAS;IAGrC,OAAO,CAAC,sBAAsB,CAAa;IAG3C,OAAO,CAAC,oBAAoB,CAAa;IAEzC,qGAAqG;IACrG,OAAO,CAAC,aAAa,CAAuC;IAE5D,gEAAgE;IAChE,OAAO,CAAC,YAAY,CAAqB;IACzC,sDAAsD;IACtD,OAAO,CAAC,eAAe,CAA4D;IAGnF,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,kBAAkB,CAAuB;IACjD,OAAO,CAAC,gBAAgB,CAAgB;IACxC,OAAO,CAAC,qBAAqB,CAAuB;IAEpD,4CAA4C;IAC5C,OAAO,CAAC,UAAU,CAAyB;IAE3C,8DAA8D;IAC9D,OAAO,CAAC,WAAW,CAAS;IAE5B,iEAAiE;IACjE,OAAO,CAAC,MAAM,CAAS;IAEvB,+CAA+C;IAC/C,OAAO,CAAC,YAAY,CAAS;IAE7B,0CAA0C;IAC1C,OAAO,CAAC,cAAc,CAAoC;IAC1D,OAAO,CAAC,eAAe,CAAuB;IAE9C,6CAA6C;IAC7C,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,WAAW,CAAsC;IAKzD,OAAO,CAAC,qBAAqB;IAO7B,OAAO,CAAC,kBAAkB;IA4E1B,OAAO,CAAC,aAAa;IASrB;;;OAGG;YACW,MAAM;IAiBpB;;;OAGG;YACW,kBAAkB;IA4ChC;;OAEG;YACW,mBAAmB;IAyCjC,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,qBAAqB;IAQ7B;;OAEG;YACW,YAAY;IAsE1B,uGAAuG;IACvG,OAAO,CAAC,mBAAmB;IAoBrB,KAAK,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAwMrD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAsF3B,6DAA6D;IAC7D,OAAO,KAAK,YAAY,GAEvB;IAEK,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAiE9B,QAAQ,IAAI,eAAe,GAAG,IAAI;IAIlC,yFAAyF;IACzF,eAAe,IAAI,IAAI;IAiBvB,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,yBAAyB;IAoRjC,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,aAAa;IAmCrB;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IA8ChC,OAAO,CAAC,kBAAkB;CAykB3B;AAOD,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,oBAAoB,CAAC,EAAE,MAAM,CAAC;KAC/B;CACF;AAED,OAAO,KAAK,EAA2B,sBAAsB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAqCpG,wBAAsB,WAAW,oBAGhC;AAID,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,UAAU,CAA4B;IAC9C,OAAO,CAAC,aAAa,CAAsC;IAC3D,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAuC;IAEvD,OAAO,CAAC,OAAO,CAAkD;IAEjE,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,mBAAmB,CAAuB;IAClD,OAAO,CAAC,iBAAiB,CAAuB;IAChD,OAAO,CAAC,qBAAqB,CAAuB;IACpD,OAAO,CAAC,sBAAsB,CAAS;IACvC,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO,CAAC,MAAM,CAAgC;IAG9C,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,iBAAiB,CAAS;IAGlC,OAAO,CAAC,eAAe,CAA0D;IACjF,OAAO,CAAC,WAAW,CAAa;IAEhC;;;OAGG;IACH,OAAO,CAAC,yBAAyB,CAA0D;IAC3F,OAAO,CAAC,sBAAsB,CAAwB;IACtD,OAAO,CAAC,kBAAkB,CAAuB;IAGjD,OAAO,CAAC,UAAU,CAMhB;IAEF,OAAO,CAAC,kBAAkB,CAAwC;IAGlE,OAAO,CAAC,iBAAiB,CAA4D;IAGrF,OAAO,CAAC,WAAW,CAAuB;IAG1C,OAAO,CAAC,mBAAmB,CAAuB;IAGlD,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,gBAAgB,CAAkB;IAG1C,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,sBAAsB,CAAK;IACnC,OAAO,CAAC,kBAAkB,CAAK;IAC/B,OAAO,CAAC,wBAAwB,CAAuB;IAGvD,OAAO,CAAC,mBAAmB,CAAuB;IAClD,OAAO,CAAC,oBAAoB,CAAS;IAGrC,OAAO,CAAC,sBAAsB,CAAa;IAG3C,OAAO,CAAC,oBAAoB,CAAa;IAEzC,qGAAqG;IACrG,OAAO,CAAC,aAAa,CAAuC;IAE5D,gEAAgE;IAChE,OAAO,CAAC,YAAY,CAAqB;IACzC,sDAAsD;IACtD,OAAO,CAAC,eAAe,CAA4D;IAGnF,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,kBAAkB,CAAuB;IACjD,OAAO,CAAC,gBAAgB,CAAgB;IACxC,OAAO,CAAC,qBAAqB,CAAuB;IAEpD,4CAA4C;IAC5C,OAAO,CAAC,UAAU,CAAyB;IAE3C,8DAA8D;IAC9D,OAAO,CAAC,WAAW,CAAS;IAE5B,iEAAiE;IACjE,OAAO,CAAC,MAAM,CAAS;IAEvB,+CAA+C;IAC/C,OAAO,CAAC,YAAY,CAAS;IAE7B,0CAA0C;IAC1C,OAAO,CAAC,cAAc,CAAoC;IAC1D,OAAO,CAAC,eAAe,CAAuB;IAE9C,6CAA6C;IAC7C,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,WAAW,CAAsC;IAKzD,OAAO,CAAC,qBAAqB;IAO7B,OAAO,CAAC,kBAAkB;IA4E1B,OAAO,CAAC,aAAa;IASrB;;;OAGG;YACW,MAAM;IAiBpB;;;OAGG;YACW,kBAAkB;IA4ChC;;OAEG;YACW,mBAAmB;IAyCjC,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,qBAAqB;IAQ7B;;OAEG;YACW,YAAY;IAsE1B,uGAAuG;IACvG,OAAO,CAAC,mBAAmB;IAoBrB,KAAK,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmOrD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAsF3B,6DAA6D;IAC7D,OAAO,KAAK,YAAY,GAEvB;IAEK,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAiE9B,QAAQ,IAAI,eAAe,GAAG,IAAI;IAIlC,yFAAyF;IACzF,eAAe,IAAI,IAAI;IAiBvB,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,yBAAyB;IAoRjC,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,aAAa;IAmCrB;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IA8ChC,OAAO,CAAC,kBAAkB;CAykB3B;AAOD,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/ui/loader.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,IAAI,IAAI,IAAI,CAAC;IACb,IAAI,IAAI,IAAI,CAAC;IACb,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,sCAAsC;IACtC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAID,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,WAAW,EAAE,IAAI,GAAE,aAAkB,GAAG,YAAY,CA2EjG"}
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/ui/loader.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,IAAI,IAAI,IAAI,CAAC;IACb,IAAI,IAAI,IAAI,CAAC;IACb,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,sCAAsC;IACtC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAYD,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,WAAW,EAAE,IAAI,GAAE,aAAkB,GAAG,YAAY,CAkFjG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alphavalid-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "SDK de validação facial e liveness",
5
5
  "main": "dist/alphavalid.umd.js",
6
6
  "module": "dist/alphavalid.es.js",
@@ -12,6 +12,7 @@
12
12
  "dist",
13
13
  "models",
14
14
  "scripts",
15
+ "public/images/alphaloader.gif",
15
16
  "README.md",
16
17
  "package.json",
17
18
  "vite.config.ts",
File without changes