@techlabi/kycrazy-ui-kit 0.39.0 → 0.40.0

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/dist/index.umd.js CHANGED
@@ -3926,7 +3926,7 @@ Manifest JSON has weights with names: `+u.join(", ")+".");return l=a.reduce(func
3926
3926
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
3927
3927
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
3928
3928
  PERFORMANCE OF THIS SOFTWARE.
3929
- ***************************************************************************** */var Gh=function(n,t){return Gh=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o])},Gh(n,t)};function De(n,t){Gh(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}var pn=function(){return pn=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++){e=arguments[r];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a])}return t},pn.apply(this,arguments)};function $e(n,t,e,r){function o(a){return a instanceof e?a:new e(function(i){i(a)})}return new(e||(e=Promise))(function(a,i){function s(l){try{c(r.next(l))}catch(d){i(d)}}function u(l){try{c(r.throw(l))}catch(d){i(d)}}function c(l){l.done?a(l.value):o(l.value).then(s,u)}c((r=r.apply(n,[])).next())})}function ke(n,t){var e={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,o,a,i;return i={next:s(0),throw:s(1),return:s(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function s(c){return function(l){return u([c,l])}}function u(c){if(r)throw new TypeError("Generator is already executing.");for(;e;)try{if(r=1,o&&(a=c[0]&2?o.return:c[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,c[1])).done)return a;switch(o=0,a&&(c=[c[0]&2,a.value]),c[0]){case 0:case 1:a=c;break;case 4:return e.label++,{value:c[1],done:!1};case 5:e.label++,o=c[1],c=[0];continue;case 7:c=e.ops.pop(),e.trys.pop();continue;default:if(a=e.trys,!(a=a.length>0&&a[a.length-1])&&(c[0]===6||c[0]===2)){e=0;continue}if(c[0]===3&&(!a||c[1]>a[0]&&c[1]<a[3])){e.label=c[1];break}if(c[0]===6&&e.label<a[1]){e.label=a[1],a=c;break}if(a&&e.label<a[2]){e.label=a[2],e.ops.push(c);break}a[2]&&e.ops.pop(),e.trys.pop();continue}c=t.call(n,e)}catch(l){c=[6,l],o=0}finally{r=a=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}function lu(){for(var n=0,t=0,e=arguments.length;t<e;t++)n+=arguments[t].length;for(var r=Array(n),o=0,t=0;t<e;t++)for(var a=arguments[t],i=0,s=a.length;i<s;i++,o++)r[o]=a[i];return r}var Vi=function(){function n(t,e){if(!Ua(t)||!Ua(e))throw new Error("Dimensions.constructor - expected width and height to be valid numbers, instead have "+JSON.stringify({width:t,height:e}));this._width=t,this._height=e}return Object.defineProperty(n.prototype,"width",{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this._height},enumerable:!0,configurable:!0}),n.prototype.reverse=function(){return new n(1/this.width,1/this.height)},n}();function bl(n,t){return n instanceof Nt&&n.shape.length===t}function h5(n){return bl(n,2)}function xl(n){return bl(n,3)}function Ho(n){return bl(n,4)}function p5(n){return n%1!==0}function qb(n){return n%2===0}function v5(n,t){t===void 0&&(t=2);var e=Math.pow(10,t);return Math.floor(n*e)/e}function Kb(n){return n&&n.width&&n.height}function m5(n,t){var e=n.width,r=n.height,o=t/Math.max(r,e);return new Vi(Math.round(e*o),Math.round(r*o))}function qh(n){return n.reduce(function(t,e){return t.add(e)},new ct(0,0)).div(new ct(n.length,n.length))}function du(n,t,e){return Array(n).fill(0).map(function(r,o){return t+o*e})}function Ua(n){return!!n&&n!==1/0&&n!==-1/0&&!isNaN(n)||n===0}function Yb(n){return Ua(n)&&0<=n&&n<=1}var ct=function(){function n(t,e){this._x=t,this._y=e}return Object.defineProperty(n.prototype,"x",{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"y",{get:function(){return this._y},enumerable:!0,configurable:!0}),n.prototype.add=function(t){return new n(this.x+t.x,this.y+t.y)},n.prototype.sub=function(t){return new n(this.x-t.x,this.y-t.y)},n.prototype.mul=function(t){return new n(this.x*t.x,this.y*t.y)},n.prototype.div=function(t){return new n(this.x/t.x,this.y/t.y)},n.prototype.abs=function(){return new n(Math.abs(this.x),Math.abs(this.y))},n.prototype.magnitude=function(){return Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2))},n.prototype.floor=function(){return new n(Math.floor(this.x),Math.floor(this.y))},n}(),Go=function(){function n(t,e){e===void 0&&(e=!0);var r=t||{},o=[r.left,r.top,r.right,r.bottom].every(Ua),a=[r.x,r.y,r.width,r.height].every(Ua);if(!a&&!o)throw new Error("Box.constructor - expected box to be IBoundingBox | IRect, instead have "+JSON.stringify(r));var i=a?[r.x,r.y,r.width,r.height]:[r.left,r.top,r.right-r.left,r.bottom-r.top],s=i[0],u=i[1],c=i[2],l=i[3];n.assertIsValidBox({x:s,y:u,width:c,height:l},"Box.constructor",e),this._x=s,this._y=u,this._width=c,this._height=l}return n.isRect=function(t){return!!t&&[t.x,t.y,t.width,t.height].every(Ua)},n.assertIsValidBox=function(t,e,r){if(r===void 0&&(r=!1),!n.isRect(t))throw new Error(e+" - invalid box: "+JSON.stringify(t)+", expected object with properties x, y, width, height");if(!r&&(t.width<0||t.height<0))throw new Error(e+" - width ("+t.width+") and height ("+t.height+") must be positive numbers")},Object.defineProperty(n.prototype,"x",{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"y",{get:function(){return this._y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"width",{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this._height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"area",{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"topLeft",{get:function(){return new ct(this.left,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"topRight",{get:function(){return new ct(this.right,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bottomLeft",{get:function(){return new ct(this.left,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bottomRight",{get:function(){return new ct(this.right,this.bottom)},enumerable:!0,configurable:!0}),n.prototype.round=function(){var t=[this.x,this.y,this.width,this.height].map(function(i){return Math.round(i)}),e=t[0],r=t[1],o=t[2],a=t[3];return new n({x:e,y:r,width:o,height:a})},n.prototype.floor=function(){var t=[this.x,this.y,this.width,this.height].map(function(i){return Math.floor(i)}),e=t[0],r=t[1],o=t[2],a=t[3];return new n({x:e,y:r,width:o,height:a})},n.prototype.toSquare=function(){var t=this,e=t.x,r=t.y,o=t.width,a=t.height,i=Math.abs(o-a);return o<a&&(e-=i/2,o+=i),a<o&&(r-=i/2,a+=i),new n({x:e,y:r,width:o,height:a})},n.prototype.rescale=function(t){var e=Kb(t)?t.width:t,r=Kb(t)?t.height:t;return new n({x:this.x*e,y:this.y*r,width:this.width*e,height:this.height*r})},n.prototype.pad=function(t,e){var r=[this.x-t/2,this.y-e/2,this.width+t,this.height+e],o=r[0],a=r[1],i=r[2],s=r[3];return new n({x:o,y:a,width:i,height:s})},n.prototype.clipAtImageBorders=function(t,e){var r=this,o=r.x,a=r.y,i=r.right,s=r.bottom,u=Math.max(o,0),c=Math.max(a,0),l=i-u,d=s-c,f=Math.min(l,t-u),h=Math.min(d,e-c);return new n({x:u,y:c,width:f,height:h}).floor()},n.prototype.shift=function(t,e){var r=this,o=r.width,a=r.height,i=this.x+t,s=this.y+e;return new n({x:i,y:s,width:o,height:a})},n.prototype.padAtBorders=function(t,e){var r=this.width+1,o=this.height+1,a=1,i=1,s=r,u=o,c=this.left,l=this.top,d=this.right,f=this.bottom;return d>e&&(s=-d+e+r,d=e),f>t&&(u=-f+t+o,f=t),c<1&&(u=2-c,c=1),l<1&&(u=2-l,l=1),{dy:i,edy:u,dx:a,edx:s,y:l,ey:f,x:c,ex:d,w:r,h:o}},n.prototype.calibrate=function(t){return new n({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()},n}(),wl=function(n){De(t,n);function t(e,r,o,a,i){return i===void 0&&(i=!1),n.call(this,{left:e,top:r,right:o,bottom:a},i)||this}return t}(Go),Xb=function(){function n(t,e,r,o,a){this._imageDims=new Vi(a.width,a.height),this._score=t,this._classScore=e,this._className=r,this._box=new Go(o).rescale(this._imageDims)}return Object.defineProperty(n.prototype,"score",{get:function(){return this._score},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"classScore",{get:function(){return this._classScore},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"className",{get:function(){return this._className},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"box",{get:function(){return this._box},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"imageDims",{get:function(){return this._imageDims},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"imageWidth",{get:function(){return this.imageDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"imageHeight",{get:function(){return this.imageDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"relativeBox",{get:function(){return new Go(this._box).rescale(this.imageDims.reverse())},enumerable:!0,configurable:!0}),n.prototype.forSize=function(t,e){return new n(this.score,this.classScore,this.className,this.relativeBox,{width:t,height:e})},n}(),Wr=function(n){De(t,n);function t(e,r,o){return n.call(this,e,e,"",r,o)||this}return t.prototype.forSize=function(e,r){var o=n.prototype.forSize.call(this,e,r),a=o.score,i=o.relativeBox,s=o.imageDims;return new t(a,i,s)},t}(Xb);function g5(n,t,e){e===void 0&&(e=!0);var r=Math.max(0,Math.min(n.right,t.right)-Math.max(n.left,t.left)),o=Math.max(0,Math.min(n.bottom,t.bottom)-Math.max(n.top,t.top)),a=r*o;return e?a/(n.area+t.area-a):a/Math.min(n.area,t.area)}function y5(n){var t=n.map(function(s){return s.x}),e=n.map(function(s){return s.y}),r=t.reduce(function(s,u){return u<s?u:s},1/0),o=e.reduce(function(s,u){return u<s?u:s},1/0),a=t.reduce(function(s,u){return s<u?u:s},0),i=e.reduce(function(s,u){return s<u?u:s},0);return new wl(r,o,a,i)}function fu(n,t,e,r){r===void 0&&(r=!0);for(var o=t.map(function(s,u){return{score:s,boxIndex:u}}).sort(function(s,u){return s.score-u.score}).map(function(s){return s.boxIndex}),a=[],i=function(){var s=o.pop();a.push(s);for(var u=o,c=[],l=0;l<u.length;l++){var d=u[l],f=n[s],h=n[d];c.push(g5(f,h,r))}o=o.filter(function(m,v){return c[v]<=e})};o.length>0;)i();return a}function hu(n,t){return xe(function(){var e=t[0],r=t[1],o=t[2],a=Lr(lu(n.shape.slice(0,3),[1]),e),i=Lr(lu(n.shape.slice(0,3),[1]),r),s=Lr(lu(n.shape.slice(0,3),[1]),o),u=jt([a,i,s],3);return Ht(n,u)})}function b5(n,t){return t===void 0&&(t=!1),xe(function(){var e=n.shape.slice(1),r=e[0],o=e[1];if(r===o)return n;var a=Math.abs(r-o),i=Math.round(a*(t?.5:1)),s=r>o?2:1,u=function(h){var m=n.shape.slice();return m[s]=h,Lr(m,0)},c=u(i),l=a-c.shape[s],d=t&&l?u(l):null,f=[d,n,c].filter(function(h){return!!h}).map(function(h){return h.toFloat()});return jt(f,s)})}function Kh(n){return 1/(1+Math.exp(-n))}var Yh=function(n){De(t,n);function t(e,r,o,a,i){return i===void 0&&(i=!1),n.call(this,{x:e,y:r,width:o,height:a},i)||this}return t}(Go),x5=.5,w5=.43,C5=.45,Cl=function(){function n(t,e,r){r===void 0&&(r=new ct(0,0));var o=e.width,a=e.height;this._imgDims=new Vi(o,a),this._shift=r,this._positions=t.map(function(i){return i.mul(new ct(o,a)).add(r)})}return Object.defineProperty(n.prototype,"shift",{get:function(){return new ct(this._shift.x,this._shift.y)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"imageWidth",{get:function(){return this._imgDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"imageHeight",{get:function(){return this._imgDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"positions",{get:function(){return this._positions},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"relativePositions",{get:function(){var t=this;return this._positions.map(function(e){return e.sub(t._shift).div(new ct(t.imageWidth,t.imageHeight))})},enumerable:!0,configurable:!0}),n.prototype.forSize=function(t,e){return new this.constructor(this.relativePositions,{width:t,height:e})},n.prototype.shiftBy=function(t,e){return new this.constructor(this.relativePositions,this._imgDims,new ct(t,e))},n.prototype.shiftByPoint=function(t){return this.shiftBy(t.x,t.y)},n.prototype.align=function(t,e){if(e===void 0&&(e={}),t){var r=t instanceof Wr?t.box.floor():new Go(t);return this.shiftBy(r.x,r.y).align(null,e)}var o=Object.assign({},{useDlibAlignment:!1,minBoxPadding:.2},e),a=o.useDlibAlignment,i=o.minBoxPadding;return a?this.alignDlib():this.alignMinBbox(i)},n.prototype.alignDlib=function(){var t=this.getRefPointsForAlignment(),e=t[0],r=t[1],o=t[2],a=function(d){return o.sub(d).magnitude()},i=(a(e)+a(r))/2,s=Math.floor(i/C5),u=qh(t),c=Math.floor(Math.max(0,u.x-x5*s)),l=Math.floor(Math.max(0,u.y-w5*s));return new Yh(c,l,Math.min(s,this.imageWidth+c),Math.min(s,this.imageHeight+l))},n.prototype.alignMinBbox=function(t){var e=y5(this.positions);return e.pad(e.width*t,e.height*t)},n.prototype.getRefPointsForAlignment=function(){throw new Error("getRefPointsForAlignment not implemented by base class")},n}(),_5=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.getRefPointsForAlignment=function(){var e=this.positions;return[e[0],e[1],qh([e[3],e[4]])]},t}(Cl),E5=function(n){De(t,n);function t(){return n!==null&&n.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(qh)},t}(Cl),Zb=function(){function n(t,e){this._label=t,this._distance=e}return Object.defineProperty(n.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"distance",{get:function(){return this._distance},enumerable:!0,configurable:!0}),n.prototype.toString=function(t){return t===void 0&&(t=!0),""+this.label+(t?" ("+v5(this.distance)+")":"")},n}(),Qb=function(n){De(t,n);function t(e,r){var o=n.call(this,e)||this;return o._label=r,o}return t.assertIsValidLabeledBox=function(e,r){if(Go.assertIsValidBox(e,r),!Ua(e.label))throw new Error(r+" - expected property label ("+e.label+") to be a number")},Object.defineProperty(t.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),t}(Go),_l=function(){function n(t,e){if(typeof t!="string")throw new Error("LabeledFaceDescriptors - constructor expected label to be a string");if(!Array.isArray(e)||e.some(function(r){return!(r instanceof Float32Array)}))throw new Error("LabeledFaceDescriptors - constructor expected descriptors to be an array of Float32Array");this._label=t,this._descriptors=e}return Object.defineProperty(n.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"descriptors",{get:function(){return this._descriptors},enumerable:!0,configurable:!0}),n.prototype.toJSON=function(){return{label:this.label,descriptors:this.descriptors.map(function(t){return Array.from(t)})}},n.fromJSON=function(t){var e=t.descriptors.map(function(r){return new Float32Array(r)});return new n(t.label,e)},n}();(function(n){De(t,n);function t(e,r,o,a){var i=n.call(this,e,r)||this;return i._score=o,i._classScore=a,i}return t.assertIsValidPredictedBox=function(e,r){if(Qb.assertIsValidLabeledBox(e,r),!Yb(e.score)||!Yb(e.classScore))throw new Error(r+" - 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})(Qb);function S5(n){return n.detection instanceof Wr}function Xh(n,t){var e={detection:t};return Object.assign({},n,e)}function Jb(){var n=window.fetch||function(){throw new Error("fetch - missing fetch implementation for browser environment")},t=function(){throw new Error("readFile - filesystem not available 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:n,readFile:t}}function e2(n){var t="";if(!n)try{n=require("fs")}catch(r){t=r.toString()}var e=n?function(r){return new Promise(function(o,a){n.readFile(r,function(i,s){return i?a(i):o(s)})})}:function(){throw new Error("readFile - failed to require fs in nodejs environment with error: "+t)};return{readFile:e}}function t2(){var n=global.Canvas||global.HTMLCanvasElement,t=global.Image||global.HTMLImageElement,e=function(){if(n)return new n;throw new Error("createCanvasElement - missing Canvas implementation for nodejs environment")},r=function(){if(t)return new t;throw new Error("createImageElement - missing Image implementation for nodejs environment")},o=global.fetch||function(){throw new Error("fetch - missing fetch implementation for nodejs environment")},a=e2();return pn({Canvas:n||function(){function i(){}return i}(),CanvasRenderingContext2D:global.CanvasRenderingContext2D||function(){function i(){}return i}(),Image:t||function(){function i(){}return i}(),ImageData:global.ImageData||function(){function i(){}return i}(),Video:global.HTMLVideoElement||function(){function i(){}return i}(),createCanvasElement:e,createImageElement:r,fetch:o},a)}function n2(){return typeof window=="object"&&typeof document<"u"&&typeof HTMLImageElement<"u"&&typeof HTMLCanvasElement<"u"&&typeof HTMLVideoElement<"u"&&typeof ImageData<"u"&&typeof CanvasRenderingContext2D<"u"}function r2(){return typeof global=="object"&&typeof require=="function"&&typeof module<"u"&&typeof process<"u"&&!!process.version}var Gt;function N5(){if(!Gt)throw new Error("getEnv - environment is not defined, check isNodejs() and isBrowser()");return Gt}function Zh(n){Gt=n}function Qh(){n2()&&Zh(Jb()),r2()&&Zh(t2())}function $5(n){if(Gt||Qh(),!Gt)throw new Error("monkeyPatch - environment is not defined, check isNodejs() and isBrowser()");var t=n.Canvas,e=t===void 0?Gt.Canvas:t,r=n.Image,o=r===void 0?Gt.Image:r;Gt.Canvas=e,Gt.Image=o,Gt.createCanvasElement=n.createCanvasElement||function(){return new e},Gt.createImageElement=n.createImageElement||function(){return new o},Gt.ImageData=n.ImageData||Gt.ImageData,Gt.Video=n.Video||Gt.Video,Gt.fetch=n.fetch||Gt.fetch,Gt.readFile=n.readFile||Gt.readFile}var on={getEnv:N5,setEnv:Zh,initialize:Qh,createBrowserEnv:Jb,createFileSystem:e2,createNodejsEnv:t2,monkeyPatch:$5,isBrowser:n2,isNodejs:r2};Qh();function o2(n){return!on.isNodejs()&&typeof n=="string"?document.getElementById(n):n}function za(n){var t=on.getEnv(),e=t.Canvas,r=t.CanvasRenderingContext2D;if(n instanceof r)return n;var o=o2(n);if(!(o instanceof e))throw new Error("resolveContext2d - expected canvas to be of instance of Canvas");var a=o.getContext("2d");if(!a)throw new Error("resolveContext2d - canvas 2d context is null");return a}var a2;(function(n){n.TOP_LEFT="TOP_LEFT",n.TOP_RIGHT="TOP_RIGHT",n.BOTTOM_LEFT="BOTTOM_LEFT",n.BOTTOM_RIGHT="BOTTOM_RIGHT"})(a2||(a2={}));function i2(n){var t=on.getEnv(),e=t.Image,r=t.Video;return n instanceof e&&n.complete||n instanceof r&&n.readyState>=3}function k5(n){return new Promise(function(t,e){if(n instanceof on.getEnv().Canvas||i2(n))return t();function r(a){a.currentTarget&&(a.currentTarget.removeEventListener("load",r),a.currentTarget.removeEventListener("error",o),t(a))}function o(a){a.currentTarget&&(a.currentTarget.removeEventListener("load",r),a.currentTarget.removeEventListener("error",o),e(a))}n.addEventListener("load",r),n.addEventListener("error",o)})}function s2(n){var t=on.getEnv(),e=t.Image,r=t.Video;return n instanceof e?new Vi(n.naturalWidth,n.naturalHeight):n instanceof r?new Vi(n.videoWidth,n.videoHeight):new Vi(n.width,n.height)}function El(n){var t=n.width,e=n.height,r=on.getEnv().createCanvasElement,o=r();return o.width=t,o.height=e,o}function Jh(n,t){var e=on.getEnv().ImageData;if(!(n instanceof e)&&!i2(n))throw new Error("createCanvasFromMedia - media has not finished loading yet");var r=s2(n),o=r.width,a=r.height,i=El({width:o,height:a});return n instanceof e?za(i).putImageData(n,0,0):za(i).drawImage(n,0,0,o,a),i}function P5(n,t){return $e(this,void 0,void 0,function(){var e,r,o,a,i,s;return ke(this,function(u){switch(u.label){case 0:return e=on.getEnv().createCanvasElement(),r=n.shape.slice(Ho(n)?1:0),o=r[0],a=r[1],i=r[2],s=xe(function(){return n.as3D(o,a,i).toInt()}),[4,Hh.toPixels(s,e)];case 1:return u.sent(),s.dispose(),[2,e]}})})}function u2(n){var t=on.getEnv(),e=t.Image,r=t.Canvas,o=t.Video;return n instanceof e||n instanceof r||n instanceof o}function I5(n,t,e){e===void 0&&(e=!1);var r=on.getEnv(),o=r.Image,a=r.Canvas;if(!(n instanceof o||n instanceof a))throw new Error("imageToSquare - expected arg0 to be HTMLImageElement | HTMLCanvasElement");var i=s2(n),s=t/Math.max(i.height,i.width),u=s*i.width,c=s*i.height,l=El({width:t,height:t}),d=n instanceof a?n:Jh(n),f=Math.abs(u-c)/2,h=e&&u<c?f:0,m=e&&c<u?f:0;return za(l).drawImage(d,h,m,u,c),l}var Sl=function(){function n(t,e){var r=this;if(e===void 0&&(e=!1),this._imageTensors=[],this._canvases=[],this._treatAsBatchInput=!1,this._inputDimensions=[],!Array.isArray(t))throw new Error("NetInput.constructor - expected inputs to be an Array of TResolvedNetInput or to be instanceof tf.Tensor4D, instead have "+t);this._treatAsBatchInput=e,this._batchSize=t.length,t.forEach(function(o,a){if(xl(o)){r._imageTensors[a]=o,r._inputDimensions[a]=o.shape;return}if(Ho(o)){var i=o.shape[0];if(i!==1)throw new Error("NetInput - tf.Tensor4D with batchSize "+i+" passed, but not supported in input array");r._imageTensors[a]=o,r._inputDimensions[a]=o.shape.slice(1);return}var s=o instanceof on.getEnv().Canvas?o:Jh(o);r._canvases[a]=s,r._inputDimensions[a]=[s.height,s.width,3]})}return Object.defineProperty(n.prototype,"imageTensors",{get:function(){return this._imageTensors},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"canvases",{get:function(){return this._canvases},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isBatchInput",{get:function(){return this.batchSize>1||this._treatAsBatchInput},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"batchSize",{get:function(){return this._batchSize},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"inputDimensions",{get:function(){return this._inputDimensions},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"inputSize",{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"reshapedInputDimensions",{get:function(){var t=this;return du(this.batchSize,0,1).map(function(e,r){return t.getReshapedInputDimensions(r)})},enumerable:!0,configurable:!0}),n.prototype.getInput=function(t){return this.canvases[t]||this.imageTensors[t]},n.prototype.getInputDimensions=function(t){return this._inputDimensions[t]},n.prototype.getInputHeight=function(t){return this._inputDimensions[t][0]},n.prototype.getInputWidth=function(t){return this._inputDimensions[t][1]},n.prototype.getReshapedInputDimensions=function(t){if(typeof this.inputSize!="number")throw new Error("getReshapedInputDimensions - inputSize not set, toBatchTensor has not been called yet");var e=this.getInputWidth(t),r=this.getInputHeight(t);return m5({width:e,height:r},this.inputSize)},n.prototype.toBatchTensor=function(t,e){var r=this;return e===void 0&&(e=!0),this._inputSize=t,xe(function(){var o=du(r.batchSize,0,1).map(function(i){var s=r.getInput(i);if(s instanceof Nt){var u=Ho(s)?s:s.expandDims();return u=b5(u,e),(u.shape[1]!==t||u.shape[2]!==t)&&(u=$h.resizeBilinear(u,[t,t])),u.as3D(t,t,3)}if(s instanceof on.getEnv().Canvas)return Hh.fromPixels(I5(s,t,e));throw new Error("toBatchTensor - at batchIdx "+i+", expected input to be instanceof tf.Tensor or instanceof HTMLCanvasElement, instead have "+s)}),a=Bn(o.map(function(i){return i.toFloat()})).as4D(r.batchSize,t,t,3);return a})},n}();function Zt(n){return $e(this,void 0,void 0,function(){var t,e,r;return ke(this,function(o){switch(o.label){case 0:if(n instanceof Sl)return[2,n];if(t=Array.isArray(n)?n:[n],!t.length)throw new Error("toNetInput - empty array passed as input");return e=function(a){return Array.isArray(n)?" at input index "+a+":":""},r=t.map(o2),r.forEach(function(a,i){if(!u2(a)&&!xl(a)&&!Ho(a))throw typeof t[i]=="string"?new Error("toNetInput -"+e(i)+" string passed, but could not resolve HTMLElement for element id "+t[i]):new Error("toNetInput -"+e(i)+" expected media to be of type HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | tf.Tensor3D, or to be an element id");if(Ho(a)){var s=a.shape[0];if(s!==1)throw new Error("toNetInput -"+e(i)+" tf.Tensor4D with batchSize "+s+" passed, but not supported in input array")}}),[4,Promise.all(r.map(function(a){return u2(a)&&k5(a)}))];case 1:return o.sent(),[2,new Sl(r,Array.isArray(n))]}})})}function ep(n,t){return $e(this,void 0,void 0,function(){var e,r,o,a,i,s,u;return ke(this,function(c){switch(c.label){case 0:return e=on.getEnv().Canvas,r=n,n instanceof e?[3,5]:[4,Zt(n)];case 1:if(o=c.sent(),o.batchSize>1)throw new Error("extractFaces - batchSize > 1 not supported");return a=o.getInput(0),a instanceof e?(i=a,[3,4]):[3,2];case 2:return[4,P5(a)];case 3:i=c.sent(),c.label=4;case 4:r=i,c.label=5;case 5:return s=za(r),u=t.map(function(l){return l instanceof Wr?l.forSize(r.width,r.height).box.floor():l}).map(function(l){return l.clipAtImageBorders(r.width,r.height)}),[2,u.map(function(l){var d=l.x,f=l.y,h=l.width,m=l.height,v=El({width:h,height:m});return za(v).putImageData(s.getImageData(d,f,h,m),0,0),v})]}})})}function tp(n,t){return $e(this,void 0,void 0,function(){return ke(this,function(e){if(!xl(n)&&!Ho(n))throw new Error("extractFaceTensors - expected image tensor to be 3D or 4D");if(Ho(n)&&n.shape[0]>1)throw new Error("extractFaceTensors - batchSize > 1 not supported");return[2,xe(function(){var r=n.shape.slice(Ho(n)?1:0),o=r[0],a=r[1],i=r[2],s=t.map(function(c){return c instanceof Wr?c.forSize(a,o).box:c}).map(function(c){return c.clipAtImageBorders(a,o)}),u=s.map(function(c){var l=c.x,d=c.y,f=c.width,h=c.height;return vb(n.as3D(o,a,i),[d,l,0],[h,f,i])});return u})]})})}function A5(n,t){return $e(this,void 0,void 0,function(){var e,r;return ke(this,function(o){switch(o.label){case 0:return e=on.getEnv().fetch,[4,e(n,t)];case 1:if(r=o.sent(),!(r.status<400))throw new Error("failed to fetch: ("+r.status+") "+r.statusText+", from url: "+r.url);return[2,r]}})})}function T5(n){return $e(this,void 0,void 0,function(){return ke(this,function(t){switch(t.label){case 0:return[4,A5(n)];case 1:return[2,t.sent().json()]}})})}function c2(n,t){var e=t+"-weights_manifest.json";if(!n)return{modelBaseUri:"",manifestUri:e};if(n==="/")return{modelBaseUri:"/",manifestUri:"/"+e};var r=n.startsWith("http://")?"http://":n.startsWith("https://")?"https://":"";n=n.replace(r,"");var o=n.split("/").filter(function(s){return s}),a=n.endsWith(".json")?o[o.length-1]:e,i=r+(n.endsWith(".json")?o.slice(0,o.length-1):o).join("/");return i=n.startsWith("/")?"/"+i:i,{modelBaseUri:i,manifestUri:i==="/"?"/"+a:i+"/"+a}}function O5(n,t){return $e(this,void 0,void 0,function(){var e,r,o,a;return ke(this,function(i){switch(i.label){case 0:return e=c2(n,t),r=e.manifestUri,o=e.modelBaseUri,[4,T5(r)];case 1:return a=i.sent(),[2,Hb.loadWeights(a,o)]}})})}var lo=function(){function n(t){this._name=t,this._params=void 0,this._paramMappings=[]}return Object.defineProperty(n.prototype,"params",{get:function(){return this._params},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"paramMappings",{get:function(){return this._paramMappings},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isLoaded",{get:function(){return!!this.params},enumerable:!0,configurable:!0}),n.prototype.getParamFromPath=function(t){var e=this.traversePropertyPath(t),r=e.obj,o=e.objProp;return r[o]},n.prototype.reassignParamFromPath=function(t,e){var r=this.traversePropertyPath(t),o=r.obj,a=r.objProp;o[a].dispose(),o[a]=e},n.prototype.getParamList=function(){var t=this;return this._paramMappings.map(function(e){var r=e.paramPath;return{path:r,tensor:t.getParamFromPath(r)}})},n.prototype.getTrainableParams=function(){return this.getParamList().filter(function(t){return t.tensor instanceof Si})},n.prototype.getFrozenParams=function(){return this.getParamList().filter(function(t){return!(t.tensor instanceof Si)})},n.prototype.variable=function(){var t=this;this.getFrozenParams().forEach(function(e){var r=e.path,o=e.tensor;t.reassignParamFromPath(r,o.variable())})},n.prototype.freeze=function(){var t=this;this.getTrainableParams().forEach(function(e){var r=e.path,o=e.tensor,a=rn(o.dataSync());o.dispose(),t.reassignParamFromPath(r,a)})},n.prototype.dispose=function(t){t===void 0&&(t=!0),this.getParamList().forEach(function(e){if(t&&e.tensor.isDisposed)throw new Error("param tensor has already been disposed for path "+e.path);e.tensor.dispose()}),this._params=void 0},n.prototype.serializeParams=function(){return new Float32Array(this.getParamList().map(function(t){var e=t.tensor;return Array.from(e.dataSync())}).reduce(function(t,e){return t.concat(e)}))},n.prototype.load=function(t){return $e(this,void 0,void 0,function(){return ke(this,function(e){switch(e.label){case 0:return t instanceof Float32Array?(this.extractWeights(t),[2]):[4,this.loadFromUri(t)];case 1:return e.sent(),[2]}})})},n.prototype.loadFromUri=function(t){return $e(this,void 0,void 0,function(){var e;return ke(this,function(r){switch(r.label){case 0:if(t&&typeof t!="string")throw new Error(this._name+".loadFromUri - expected model uri");return[4,O5(t,this.getDefaultModelName())];case 1:return e=r.sent(),this.loadFromWeightMap(e),[2]}})})},n.prototype.loadFromDisk=function(t){return $e(this,void 0,void 0,function(){var e,r,o,a,i,s,u,c,l,d;return ke(this,function(f){switch(f.label){case 0:if(t&&typeof t!="string")throw new Error(this._name+".loadFromDisk - expected model file path");return e=on.getEnv().readFile,r=c2(t,this.getDefaultModelName()),o=r.manifestUri,a=r.modelBaseUri,i=function(h){return Promise.all(h.map(function(m){return e(m).then(function(v){return v.buffer})}))},s=Hb.weightsLoaderFactory(i),l=(c=JSON).parse,[4,e(o)];case 1:return u=l.apply(c,[f.sent().toString()]),[4,s(u,a)];case 2:return d=f.sent(),this.loadFromWeightMap(d),[2]}})})},n.prototype.loadFromWeightMap=function(t){var e=this.extractParamsFromWeigthMap(t),r=e.paramMappings,o=e.params;this._paramMappings=r,this._params=o},n.prototype.extractWeights=function(t){var e=this.extractParams(t),r=e.paramMappings,o=e.params;this._paramMappings=r,this._params=o},n.prototype.traversePropertyPath=function(t){if(!this.params)throw new Error("traversePropertyPath - model has no loaded params");var e=t.split("/").reduce(function(a,i){if(!a.nextObj.hasOwnProperty(i))throw new Error("traversePropertyPath - object does not have property "+i+", for path "+t);return{obj:a.nextObj,objProp:i,nextObj:a.nextObj[i]}},{nextObj:this.params}),r=e.obj,o=e.objProp;if(!r||!o||!(r[o]instanceof Nt))throw new Error("traversePropertyPath - parameter is not a tensor, for path "+t);return{obj:r,objProp:o}},n}();function Vn(n,t,e){return xe(function(){var r=Ch(n,t.depthwise_filter,t.pointwise_filter,e,"same");return r=qe(r,t.bias),r})}function np(n,t,e){return e===void 0&&(e=!1),xe(function(){var r=kt(e?qe(Zn(n,t.conv0.filters,[2,2],"same"),t.conv0.bias):Vn(n,t.conv0,[2,2])),o=Vn(r,t.conv1,[1,1]),a=kt(qe(r,o)),i=Vn(a,t.conv2,[1,1]);return kt(qe(r,qe(o,i)))})}function Nl(n,t,e,r){return e===void 0&&(e=!1),r===void 0&&(r=!0),xe(function(){var o=kt(e?qe(Zn(n,t.conv0.filters,r?[2,2]:[1,1],"same"),t.conv0.bias):Vn(n,t.conv0,r?[2,2]:[1,1])),a=Vn(o,t.conv1,[1,1]),i=kt(qe(o,a)),s=Vn(i,t.conv2,[1,1]),u=kt(qe(o,qe(a,s))),c=Vn(u,t.conv3,[1,1]);return kt(qe(o,qe(a,qe(s,c))))})}function cr(n,t,e,r){return e===void 0&&(e="same"),r===void 0&&(r=!1),xe(function(){var o=qe(Zn(n,t.filters,[1,1],e),t.bias);return r?kt(o):o})}function fo(n,t){Object.keys(n).forEach(function(e){t.some(function(r){return r.originalPath===e})||n[e].dispose()})}function $l(n,t){return function(e,r,o,a){var i=Sn(n(e*r*o*o),[o,o,e,r]),s=Dt(n(r));return t.push({paramPath:a+"/filters"},{paramPath:a+"/bias"}),{filters:i,bias:s}}}function rp(n,t){return function(e,r,o){var a=Wo(n(e*r),[e,r]),i=Dt(n(r));return t.push({paramPath:o+"/weights"},{paramPath:o+"/bias"}),{weights:a,bias:i}}}var l2=function(){function n(t,e,r){this.depthwise_filter=t,this.pointwise_filter=e,this.bias=r}return n}();function op(n,t){return function(e,r,o){var a=Sn(n(9*e),[3,3,e,1]),i=Sn(n(e*r),[1,1,e,r]),s=Dt(n(r));return t.push({paramPath:o+"/depthwise_filter"},{paramPath:o+"/pointwise_filter"},{paramPath:o+"/bias"}),new l2(a,i,s)}}function ap(n){return function(t){var e=n(t+"/depthwise_filter",4),r=n(t+"/pointwise_filter",4),o=n(t+"/bias",1);return new l2(e,r,o)}}function qo(n,t){return function(e,r,o){var a=n[e];if(!bl(a,r))throw new Error("expected weightMap["+e+"] to be a Tensor"+r+"D, instead have "+a);return t.push({originalPath:e,paramPath:o||e}),a}}function ho(n){var t=n;function e(o){var a=t.slice(0,o);return t=t.slice(o),a}function r(){return t}return{extractWeights:e,getRemainingWeights:r}}function d2(n,t){var e=$l(n,t),r=op(n,t);function o(i,s,u,c){c===void 0&&(c=!1);var l=c?e(i,s,3,u+"/conv0"):r(i,s,u+"/conv0"),d=r(s,s,u+"/conv1"),f=r(s,s,u+"/conv2");return{conv0:l,conv1:d,conv2:f}}function a(i,s,u,c){c===void 0&&(c=!1);var l=o(i,s,u,c),d=l.conv0,f=l.conv1,h=l.conv2,m=r(s,s,u+"/conv3");return{conv0:d,conv1:f,conv2:h,conv3:m}}return{extractDenseBlock3Params:o,extractDenseBlock4Params:a}}function D5(n){var t=[],e=ho(n),r=e.extractWeights,o=e.getRemainingWeights,a=d2(r,t).extractDenseBlock4Params,i=a(3,32,"dense0",!0),s=a(32,64,"dense1"),u=a(64,128,"dense2"),c=a(128,256,"dense3");if(o().length!==0)throw new Error("weights remaing after extract: "+o().length);return{paramMappings:t,params:{dense0:i,dense1:s,dense2:u,dense3:c}}}function f2(n){return function(t){var e=n(t+"/filters",4),r=n(t+"/bias",1);return{filters:e,bias:r}}}function h2(n,t){var e=qo(n,t),r=f2(e),o=ap(e);function a(s,u){u===void 0&&(u=!1);var c=u?r(s+"/conv0"):o(s+"/conv0"),l=o(s+"/conv1"),d=o(s+"/conv2");return{conv0:c,conv1:l,conv2:d}}function i(s,u){u===void 0&&(u=!1);var c=u?r(s+"/conv0"):o(s+"/conv0"),l=o(s+"/conv1"),d=o(s+"/conv2"),f=o(s+"/conv3");return{conv0:c,conv1:l,conv2:d,conv3:f}}return{extractDenseBlock3Params:a,extractDenseBlock4Params:i}}function F5(n){var t=[],e=h2(n,t).extractDenseBlock4Params,r={dense0:e("dense0",!0),dense1:e("dense1"),dense2:e("dense2"),dense3:e("dense3")};return fo(n,t),{params:r,paramMappings:t}}var p2=function(n){De(t,n);function t(){return n.call(this,"FaceFeatureExtractor")||this}return t.prototype.forwardInput=function(e){var r=this.params;if(!r)throw new Error("FaceFeatureExtractor - load model before inference");return xe(function(){var o=e.toBatchTensor(112,!0),a=[122.782,117.001,104.298],i=hu(o,a).div(ve(255)),s=Nl(i,r.dense0,!0);return s=Nl(s,r.dense1),s=Nl(s,r.dense2),s=Nl(s,r.dense3),s=uu(s,[7,7],[2,2],"valid"),s})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.getDefaultModelName=function(){return"face_feature_extractor_model"},t.prototype.extractParamsFromWeigthMap=function(e){return F5(e)},t.prototype.extractParams=function(e){return D5(e)},t}(lo);function Vr(n,t){return xe(function(){return qe(hl(n,t.weights),t.bias)})}function M5(n,t,e){var r=[],o=ho(n),a=o.extractWeights,i=o.getRemainingWeights,s=rp(a,r),u=s(t,e,"fc");if(i().length!==0)throw new Error("weights remaing after extract: "+i().length);return{paramMappings:r,params:{fc:u}}}function R5(n){var t=[],e=qo(n,t);function r(a){var i=e(a+"/weights",2),s=e(a+"/bias",1);return{weights:i,bias:s}}var o={fc:r("fc")};return fo(n,t),{params:o,paramMappings:t}}function v2(n){var t={},e={};return Object.keys(n).forEach(function(r){var o=r.startsWith("fc")?e:t;o[r]=n[r]}),{featureExtractorMap:t,classifierMap:e}}var m2=function(n){De(t,n);function t(e,r){var o=n.call(this,e)||this;return o._faceFeatureExtractor=r,o}return Object.defineProperty(t.prototype,"faceFeatureExtractor",{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),t.prototype.runNet=function(e){var r=this,o=this.params;if(!o)throw new Error(this._name+" - load model before inference");return xe(function(){var a=e instanceof Sl?r.faceFeatureExtractor.forwardInput(e):e;return Vr(a.as2D(a.shape[0],-1),o.fc)})},t.prototype.dispose=function(e){e===void 0&&(e=!0),this.faceFeatureExtractor.dispose(e),n.prototype.dispose.call(this,e)},t.prototype.loadClassifierParams=function(e){var r=this.extractClassifierParams(e),o=r.params,a=r.paramMappings;this._params=o,this._paramMappings=a},t.prototype.extractClassifierParams=function(e){return M5(e,this.getClassifierChannelsIn(),this.getClassifierChannelsOut())},t.prototype.extractParamsFromWeigthMap=function(e){var r=v2(e),o=r.featureExtractorMap,a=r.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(o),R5(a)},t.prototype.extractParams=function(e){var r=this.getClassifierChannelsIn(),o=this.getClassifierChannelsOut(),a=o*r+o,i=e.slice(0,e.length-a),s=e.slice(e.length-a);return this.faceFeatureExtractor.extractWeights(i),this.extractClassifierParams(s)},t}(lo),g2=["neutral","happy","sad","angry","fearful","disgusted","surprised"],L5=function(){function n(t){var e=this;if(t.length!==7)throw new Error("FaceExpressions.constructor - expected probabilities.length to be 7, have: "+t.length);g2.forEach(function(r,o){e[r]=t[o]})}return n.prototype.asSortedArray=function(){var t=this;return g2.map(function(e){return{expression:e,probability:t[e]}}).sort(function(e,r){return r.probability-e.probability})},n}(),B5=function(n){De(t,n);function t(e){return e===void 0&&(e=new p2),n.call(this,"FaceExpressionNet",e)||this}return t.prototype.forwardInput=function(e){var r=this;return xe(function(){return io(r.runNet(e))})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.predictExpressions=function(e){return $e(this,void 0,void 0,function(){var r,o,a,i,s=this;return ke(this,function(u){switch(u.label){case 0:return[4,Zt(e)];case 1:return r=u.sent(),[4,this.forwardInput(r)];case 2:return o=u.sent(),[4,Promise.all(Ut(o).map(function(c){return $e(s,void 0,void 0,function(){var l;return ke(this,function(d){switch(d.label){case 0:return[4,c.data()];case 1:return l=d.sent(),c.dispose(),[2,l]}})})}))];case 3:return a=u.sent(),o.dispose(),i=a.map(function(c){return new L5(c)}),[2,r.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}(m2);function y2(n,t){var e={expressions:t};return Object.assign({},n,e)}function W5(n){return S5(n)&&n.landmarks instanceof Cl&&n.unshiftedLandmarks instanceof Cl&&n.alignedRect instanceof Wr}function ip(n,t){var e=n.detection.box,r=t.shiftBy(e.x,e.y),o=r.align(),a=n.detection.imageDims,i=new Wr(n.detection.score,o.rescale(a.reverse()),a),s={landmarks:r,unshiftedLandmarks:t,alignedRect:i};return Object.assign({},n,s)}function V5(n,t){var e=$l(n,t),r=op(n,t);function o(i,s,u){var c=r(i,s,u+"/separable_conv0"),l=r(s,s,u+"/separable_conv1"),d=e(i,s,1,u+"/expansion_conv");return{separable_conv0:c,separable_conv1:l,expansion_conv:d}}function a(i,s){var u=r(i,i,s+"/separable_conv0"),c=r(i,i,s+"/separable_conv1"),l=r(i,i,s+"/separable_conv2");return{separable_conv0:u,separable_conv1:c,separable_conv2:l}}return{extractConvParams:e,extractSeparableConvParams:r,extractReductionBlockParams:o,extractMainBlockParams:a}}function j5(n,t){var e=[],r=ho(n),o=r.extractWeights,a=r.getRemainingWeights,i=V5(o,e),s=i.extractConvParams,u=i.extractSeparableConvParams,c=i.extractReductionBlockParams,l=i.extractMainBlockParams,d=s(3,32,3,"entry_flow/conv_in"),f=c(32,64,"entry_flow/reduction_block_0"),h=c(64,128,"entry_flow/reduction_block_1"),m={conv_in:d,reduction_block_0:f,reduction_block_1:h},v={};du(t,0,1).forEach(function(w){v["main_block_"+w]=l(128,"middle_flow/main_block_"+w)});var p=c(128,256,"exit_flow/reduction_block"),g=u(256,512,"exit_flow/separable_conv"),b={reduction_block:p,separable_conv:g};if(a().length!==0)throw new Error("weights remaing after extract: "+a().length);return{paramMappings:e,params:{entry_flow:m,middle_flow:v,exit_flow:b}}}function U5(n,t){var e=qo(n,t),r=f2(e),o=ap(e);function a(s){var u=o(s+"/separable_conv0"),c=o(s+"/separable_conv1"),l=r(s+"/expansion_conv");return{separable_conv0:u,separable_conv1:c,expansion_conv:l}}function i(s){var u=o(s+"/separable_conv0"),c=o(s+"/separable_conv1"),l=o(s+"/separable_conv2");return{separable_conv0:u,separable_conv1:c,separable_conv2:l}}return{extractConvParams:r,extractSeparableConvParams:o,extractReductionBlockParams:a,extractMainBlockParams:i}}function z5(n,t){var e=[],r=U5(n,e),o=r.extractConvParams,a=r.extractSeparableConvParams,i=r.extractReductionBlockParams,s=r.extractMainBlockParams,u=o("entry_flow/conv_in"),c=i("entry_flow/reduction_block_0"),l=i("entry_flow/reduction_block_1"),d={conv_in:u,reduction_block_0:c,reduction_block_1:l},f={};du(t,0,1).forEach(function(p){f["main_block_"+p]=s("middle_flow/main_block_"+p)});var h=i("exit_flow/reduction_block"),m=a("exit_flow/separable_conv"),v={reduction_block:h,separable_conv:m};return fo(n,e),{params:{entry_flow:d,middle_flow:f,exit_flow:v},paramMappings:e}}function b2(n,t,e){return qe(Zn(n,t.filters,e,"same"),t.bias)}function sp(n,t,e){e===void 0&&(e=!0);var r=e?kt(n):n;return r=Vn(r,t.separable_conv0,[1,1]),r=Vn(kt(r),t.separable_conv1,[1,1]),r=Xt(r,[3,3],[2,2],"same"),r=qe(r,b2(n,t.expansion_conv,[2,2])),r}function H5(n,t){var e=Vn(kt(n),t.separable_conv0,[1,1]);return e=Vn(kt(e),t.separable_conv1,[1,1]),e=Vn(kt(e),t.separable_conv2,[1,1]),e=qe(e,n),e}var G5=function(n){De(t,n);function t(e){var r=n.call(this,"TinyXception")||this;return r._numMainBlocks=e,r}return t.prototype.forwardInput=function(e){var r=this,o=this.params;if(!o)throw new Error("TinyXception - load model before inference");return xe(function(){var a=e.toBatchTensor(112,!0),i=[122.782,117.001,104.298],s=hu(a,i).div(ve(256)),u=kt(b2(s,o.entry_flow.conv_in,[2,2]));return u=sp(u,o.entry_flow.reduction_block_0,!1),u=sp(u,o.entry_flow.reduction_block_1),du(r._numMainBlocks,0,1).forEach(function(c){u=H5(u,o.middle_flow["main_block_"+c])}),u=sp(u,o.exit_flow.reduction_block),u=kt(Vn(u,o.exit_flow.separable_conv,[1,1])),u})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.getDefaultModelName=function(){return"tiny_xception_model"},t.prototype.extractParamsFromWeigthMap=function(e){return z5(e,this._numMainBlocks)},t.prototype.extractParams=function(e){return j5(e,this._numMainBlocks)},t}(lo);function q5(n){var t=[],e=ho(n),r=e.extractWeights,o=e.getRemainingWeights,a=rp(r,t),i=a(512,1,"fc/age"),s=a(512,2,"fc/gender");if(o().length!==0)throw new Error("weights remaing after extract: "+o().length);return{paramMappings:t,params:{fc:{age:i,gender:s}}}}function K5(n){var t=[],e=qo(n,t);function r(a){var i=e(a+"/weights",2),s=e(a+"/bias",1);return{weights:i,bias:s}}var o={fc:{age:r("fc/age"),gender:r("fc/gender")}};return fo(n,t),{params:o,paramMappings:t}}var kl;(function(n){n.FEMALE="female",n.MALE="male"})(kl||(kl={}));var Y5=function(n){De(t,n);function t(e){e===void 0&&(e=new G5(2));var r=n.call(this,"AgeGenderNet")||this;return r._faceFeatureExtractor=e,r}return Object.defineProperty(t.prototype,"faceFeatureExtractor",{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),t.prototype.runNet=function(e){var r=this,o=this.params;if(!o)throw new Error(this._name+" - load model before inference");return xe(function(){var a=e instanceof Sl?r.faceFeatureExtractor.forwardInput(e):e,i=uu(a,[7,7],[2,2],"valid").as2D(a.shape[0],-1),s=Vr(i,o.fc.age).as1D(),u=Vr(i,o.fc.gender);return{age:s,gender:u}})},t.prototype.forwardInput=function(e){var r=this;return xe(function(){var o=r.runNet(e),a=o.age,i=o.gender;return{age:a,gender:io(i)}})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.predictAgeAndGender=function(e){return $e(this,void 0,void 0,function(){var r,o,a,i,s,u,c=this;return ke(this,function(l){switch(l.label){case 0:return[4,Zt(e)];case 1:return r=l.sent(),[4,this.forwardInput(r)];case 2:return o=l.sent(),a=Ut(o.age),i=Ut(o.gender),s=a.map(function(d,f){return{ageTensor:d,genderTensor:i[f]}}),[4,Promise.all(s.map(function(d){var f=d.ageTensor,h=d.genderTensor;return $e(c,void 0,void 0,function(){var m,v,p,g,b;return ke(this,function(w){switch(w.label){case 0:return[4,f.data()];case 1:return m=w.sent()[0],[4,h.data()];case 2:return v=w.sent()[0],p=v>.5,g=p?kl.MALE:kl.FEMALE,b=p?v:1-v,f.dispose(),h.dispose(),[2,{age:m,gender:g,genderProbability:b}]}})})}))];case 3:return u=l.sent(),o.age.dispose(),o.gender.dispose(),[2,r.isBatchInput?u:u[0]]}})})},t.prototype.getDefaultModelName=function(){return"age_gender_model"},t.prototype.dispose=function(e){e===void 0&&(e=!0),this.faceFeatureExtractor.dispose(e),n.prototype.dispose.call(this,e)},t.prototype.loadClassifierParams=function(e){var r=this.extractClassifierParams(e),o=r.params,a=r.paramMappings;this._params=o,this._paramMappings=a},t.prototype.extractClassifierParams=function(e){return q5(e)},t.prototype.extractParamsFromWeigthMap=function(e){var r=v2(e),o=r.featureExtractorMap,a=r.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(o),K5(a)},t.prototype.extractParams=function(e){var r=1539,o=e.slice(0,e.length-r),a=e.slice(e.length-r);return this.faceFeatureExtractor.extractWeights(o),this.extractClassifierParams(a)},t}(lo),x2=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.postProcess=function(e,r,o){var a=o.map(function(s){var u=s.width,c=s.height,l=r/Math.max(c,u);return{width:u*l,height:c*l}}),i=a.length;return xe(function(){var s=function(f,h){return Bn([Lr([68],f),Lr([68],h)],1).as2D(1,136).as1D()},u=function(f,h){var m=a[f],v=m.width,p=m.height;return h(v,p)?Math.abs(v-p)/2:0},c=function(f){return u(f,function(h,m){return h<m})},l=function(f){return u(f,function(h,m){return m<h})},d=e.mul(Lr([i,136],r)).sub(Bn(Array.from(Array(i),function(f,h){return s(c(h),l(h))}))).div(Bn(Array.from(Array(i),function(f,h){return s(a[h].width,a[h].height)})));return d})},t.prototype.forwardInput=function(e){var r=this;return xe(function(){var o=r.runNet(e);return r.postProcess(o,e.inputSize,e.inputDimensions.map(function(a){var i=a[0],s=a[1];return{height:i,width:s}}))})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.detectLandmarks=function(e){return $e(this,void 0,void 0,function(){var r,o,a,i=this;return ke(this,function(s){switch(s.label){case 0:return[4,Zt(e)];case 1:return r=s.sent(),o=xe(function(){return Ut(i.forwardInput(r))}),[4,Promise.all(o.map(function(u,c){return $e(i,void 0,void 0,function(){var l,d,f,h,m;return ke(this,function(v){switch(v.label){case 0:return f=(d=Array).from,[4,u.data()];case 1:return l=f.apply(d,[v.sent()]),h=l.filter(function(p,g){return qb(g)}),m=l.filter(function(p,g){return!qb(g)}),[2,new E5(Array(68).fill(0).map(function(p,g){return new ct(h[g],m[g])}),{height:r.getInputHeight(c),width:r.getInputWidth(c)})]}})})}))];case 2:return a=s.sent(),o.forEach(function(u){return u.dispose()}),[2,r.isBatchInput?a:a[0]]}})})},t.prototype.getClassifierChannelsOut=function(){return 136},t}(m2),w2=function(n){De(t,n);function t(e){return e===void 0&&(e=new p2),n.call(this,"FaceLandmark68Net",e)||this}return t.prototype.getDefaultModelName=function(){return"face_landmark_68_model"},t.prototype.getClassifierChannelsIn=function(){return 256},t}(x2);function X5(n){var t=[],e=h2(n,t).extractDenseBlock3Params,r={dense0:e("dense0",!0),dense1:e("dense1"),dense2:e("dense2")};return fo(n,t),{params:r,paramMappings:t}}function Z5(n){var t=[],e=ho(n),r=e.extractWeights,o=e.getRemainingWeights,a=d2(r,t).extractDenseBlock3Params,i=a(3,32,"dense0",!0),s=a(32,64,"dense1"),u=a(64,128,"dense2");if(o().length!==0)throw new Error("weights remaing after extract: "+o().length);return{paramMappings:t,params:{dense0:i,dense1:s,dense2:u}}}var Q5=function(n){De(t,n);function t(){return n.call(this,"TinyFaceFeatureExtractor")||this}return t.prototype.forwardInput=function(e){var r=this.params;if(!r)throw new Error("TinyFaceFeatureExtractor - load model before inference");return xe(function(){var o=e.toBatchTensor(112,!0),a=[122.782,117.001,104.298],i=hu(o,a).div(ve(255)),s=np(i,r.dense0,!0);return s=np(s,r.dense1),s=np(s,r.dense2),s=uu(s,[14,14],[2,2],"valid"),s})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.getDefaultModelName=function(){return"face_feature_extractor_tiny_model"},t.prototype.extractParamsFromWeigthMap=function(e){return X5(e)},t.prototype.extractParams=function(e){return Z5(e)},t}(lo),J5=function(n){De(t,n);function t(e){return e===void 0&&(e=new Q5),n.call(this,"FaceLandmark68TinyNet",e)||this}return t.prototype.getDefaultModelName=function(){return"face_landmark_68_tiny_model"},t.prototype.getClassifierChannelsIn=function(){return 128},t}(x2);(function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t})(w2);function e9(n,t){return qe(fn(n,t.weights),t.biases)}function up(n,t,e,r,o){o===void 0&&(o="same");var a=t.conv,i=a.filters,s=a.bias,u=Zn(n,i,e,o);return u=qe(u,s),u=e9(u,t.scale),r?kt(u):u}function t9(n,t){return up(n,t,[1,1],!0)}function C2(n,t){return up(n,t,[1,1],!1)}function _2(n,t){return up(n,t,[2,2],!0,"valid")}function n9(n,t){function e(s,u,c){var l=n(s),d=l.length/(u*c*c);if(p5(d))throw new Error("depth has to be an integer: "+d+", weights.length: "+l.length+", numFilters: "+u+", filterSize: "+c);return xe(function(){return jo(Sn(l,[u,d,c,c]),[2,3,1,0])})}function r(s,u,c,l){var d=e(s,u,c),f=Dt(n(u));return t.push({paramPath:l+"/filters"},{paramPath:l+"/bias"}),{filters:d,bias:f}}function o(s,u){var c=Dt(n(s)),l=Dt(n(s));return t.push({paramPath:u+"/weights"},{paramPath:u+"/biases"}),{weights:c,biases:l}}function a(s,u,c,l){var d=r(s,u,c,l+"/conv"),f=o(u,l+"/scale");return{conv:d,scale:f}}function i(s,u,c,l,d){d===void 0&&(d=!1);var f=a((d?.5:1)*s,u,c,l+"/conv1"),h=a(s,u,c,l+"/conv2");return{conv1:f,conv2:h}}return{extractConvLayerParams:a,extractResidualLayerParams:i}}function r9(n){var t=ho(n),e=t.extractWeights,r=t.getRemainingWeights,o=[],a=n9(e,o),i=a.extractConvLayerParams,s=a.extractResidualLayerParams,u=i(4704,32,7,"conv32_down"),c=s(9216,32,3,"conv32_1"),l=s(9216,32,3,"conv32_2"),d=s(9216,32,3,"conv32_3"),f=s(36864,64,3,"conv64_down",!0),h=s(36864,64,3,"conv64_1"),m=s(36864,64,3,"conv64_2"),v=s(36864,64,3,"conv64_3"),p=s(147456,128,3,"conv128_down",!0),g=s(147456,128,3,"conv128_1"),b=s(147456,128,3,"conv128_2"),w=s(589824,256,3,"conv256_down",!0),x=s(589824,256,3,"conv256_1"),C=s(589824,256,3,"conv256_2"),_=s(589824,256,3,"conv256_down_out"),E=xe(function(){return jo(Wo(e(256*128),[128,256]),[1,0])});if(o.push({paramPath:"fc"}),r().length!==0)throw new Error("weights remaing after extract: "+r().length);var $={conv32_down:u,conv32_1:c,conv32_2:l,conv32_3:d,conv64_down:f,conv64_1:h,conv64_2:m,conv64_3:v,conv128_down:p,conv128_1:g,conv128_2:b,conv256_down:w,conv256_1:x,conv256_2:C,conv256_down_out:_,fc:E};return{params:$,paramMappings:o}}function o9(n,t){var e=qo(n,t);function r(i){var s=e(i+"/scale/weights",1),u=e(i+"/scale/biases",1);return{weights:s,biases:u}}function o(i){var s=e(i+"/conv/filters",4),u=e(i+"/conv/bias",1),c=r(i);return{conv:{filters:s,bias:u},scale:c}}function a(i){return{conv1:o(i+"/conv1"),conv2:o(i+"/conv2")}}return{extractConvLayerParams:o,extractResidualLayerParams:a}}function a9(n){var t=[],e=o9(n,t),r=e.extractConvLayerParams,o=e.extractResidualLayerParams,a=r("conv32_down"),i=o("conv32_1"),s=o("conv32_2"),u=o("conv32_3"),c=o("conv64_down"),l=o("conv64_1"),d=o("conv64_2"),f=o("conv64_3"),h=o("conv128_down"),m=o("conv128_1"),v=o("conv128_2"),p=o("conv256_down"),g=o("conv256_1"),b=o("conv256_2"),w=o("conv256_down_out"),x=n.fc;if(t.push({originalPath:"fc",paramPath:"fc"}),!h5(x))throw new Error("expected weightMap[fc] to be a Tensor2D, instead have "+x);var C={conv32_down:a,conv32_1:i,conv32_2:s,conv32_3:u,conv64_down:c,conv64_1:l,conv64_2:d,conv64_3:f,conv128_down:h,conv128_1:m,conv128_2:v,conv256_down:p,conv256_1:g,conv256_2:b,conv256_down_out:w,fc:x};return fo(n,t),{params:C,paramMappings:t}}function jr(n,t){var e=t9(n,t.conv1);return e=C2(e,t.conv2),e=qe(e,n),e=kt(e),e}function Pl(n,t){var e=_2(n,t.conv1);e=C2(e,t.conv2);var r=uu(n,2,2,"valid"),o=wt(r.shape),a=r.shape[3]!==e.shape[3],i=r.shape[1]!==e.shape[1]||r.shape[2]!==e.shape[2];if(i){var s=lu(e.shape);s[1]=1;var u=wt(s);e=jt([e,u],1);var c=lu(e.shape);c[2]=1;var l=wt(c);e=jt([e,l],2)}return r=a?jt([r,o],3):r,e=qe(r,e),e=kt(e),e}var i9=function(n){De(t,n);function t(){return n.call(this,"FaceRecognitionNet")||this}return t.prototype.forwardInput=function(e){var r=this.params;if(!r)throw new Error("FaceRecognitionNet - load model before inference");return xe(function(){var o=e.toBatchTensor(150,!0).toFloat(),a=[122.782,117.001,104.298],i=hu(o,a).div(ve(256)),s=_2(i,r.conv32_down);s=Xt(s,3,2,"valid"),s=jr(s,r.conv32_1),s=jr(s,r.conv32_2),s=jr(s,r.conv32_3),s=Pl(s,r.conv64_down),s=jr(s,r.conv64_1),s=jr(s,r.conv64_2),s=jr(s,r.conv64_3),s=Pl(s,r.conv128_down),s=jr(s,r.conv128_1),s=jr(s,r.conv128_2),s=Pl(s,r.conv256_down),s=jr(s,r.conv256_1),s=jr(s,r.conv256_2),s=Pl(s,r.conv256_down_out);var u=s.mean([1,2]),c=hl(u,r.fc);return c})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.computeFaceDescriptor=function(e){return $e(this,void 0,void 0,function(){var r,o,a,i=this;return ke(this,function(s){switch(s.label){case 0:return[4,Zt(e)];case 1:return r=s.sent(),o=xe(function(){return Ut(i.forwardInput(r))}),[4,Promise.all(o.map(function(u){return u.data()}))];case 2:return a=s.sent(),o.forEach(function(u){return u.dispose()}),[2,r.isBatchInput?a:a[0]]}})})},t.prototype.getDefaultModelName=function(){return"face_recognition_model"},t.prototype.extractParamsFromWeigthMap=function(e){return a9(e)},t.prototype.extractParams=function(e){return r9(e)},t}(lo);function E2(n,t){var e={descriptor:t};return Object.assign({},n,e)}function S2(n,t){var e={age:t};return Object.assign({},n,e)}function N2(n,t,e){var r={gender:t,genderProbability:e};return Object.assign({},n,r)}var $2=function(){function n(t){var e=t===void 0?{}:t,r=e.minFaceSize,o=e.scaleFactor,a=e.maxNumScales,i=e.scoreThresholds,s=e.scaleSteps;if(this._name="MtcnnOptions",this._minFaceSize=r||20,this._scaleFactor=o||.709,this._maxNumScales=a||10,this._scoreThresholds=i||[.6,.7,.7],this._scaleSteps=s,typeof this._minFaceSize!="number"||this._minFaceSize<0)throw new Error(this._name+" - expected minFaceSize to be a number > 0");if(typeof this._scaleFactor!="number"||this._scaleFactor<=0||this._scaleFactor>=1)throw new Error(this._name+" - expected scaleFactor to be a number between 0 and 1");if(typeof this._maxNumScales!="number"||this._maxNumScales<0)throw new Error(this._name+" - expected maxNumScales to be a number > 0");if(!Array.isArray(this._scoreThresholds)||this._scoreThresholds.length!==3||this._scoreThresholds.some(function(u){return typeof u!="number"}))throw new 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(u){return typeof u!="number"})))throw new Error(this._name+" - expected scaleSteps to be an array of numbers")}return Object.defineProperty(n.prototype,"minFaceSize",{get:function(){return this._minFaceSize},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"scaleFactor",{get:function(){return this._scaleFactor},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"maxNumScales",{get:function(){return this._maxNumScales},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"scoreThresholds",{get:function(){return this._scoreThresholds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"scaleSteps",{get:function(){return this._scaleSteps},enumerable:!0,configurable:!0}),n}();function s9(n,t){function e(u,c){var l=Sn(n(9*u),[3,3,u,1]),d=Dt(n(u)),f=Dt(n(u)),h=Dt(n(u)),m=Dt(n(u));return t.push({paramPath:c+"/filters"},{paramPath:c+"/batch_norm_scale"},{paramPath:c+"/batch_norm_offset"},{paramPath:c+"/batch_norm_mean"},{paramPath:c+"/batch_norm_variance"}),{filters:l,batch_norm_scale:d,batch_norm_offset:f,batch_norm_mean:h,batch_norm_variance:m}}function r(u,c,l,d,f){var h=Sn(n(u*c*l*l),[l,l,u,c]),m=Dt(n(c));return t.push({paramPath:d+"/filters"},{paramPath:d+"/"+(f?"batch_norm_offset":"bias")}),{filters:h,bias:m}}function o(u,c,l,d){var f=r(u,c,l,d,!0),h=f.filters,m=f.bias;return{filters:h,batch_norm_offset:m}}function a(u,c,l){var d=e(u,l+"/depthwise_conv"),f=o(u,c,1,l+"/pointwise_conv");return{depthwise_conv:d,pointwise_conv:f}}function i(){var u=o(3,32,3,"mobilenetv1/conv_0"),c=a(32,64,"mobilenetv1/conv_1"),l=a(64,128,"mobilenetv1/conv_2"),d=a(128,128,"mobilenetv1/conv_3"),f=a(128,256,"mobilenetv1/conv_4"),h=a(256,256,"mobilenetv1/conv_5"),m=a(256,512,"mobilenetv1/conv_6"),v=a(512,512,"mobilenetv1/conv_7"),p=a(512,512,"mobilenetv1/conv_8"),g=a(512,512,"mobilenetv1/conv_9"),b=a(512,512,"mobilenetv1/conv_10"),w=a(512,512,"mobilenetv1/conv_11"),x=a(512,1024,"mobilenetv1/conv_12"),C=a(1024,1024,"mobilenetv1/conv_13");return{conv_0:u,conv_1:c,conv_2:l,conv_3:d,conv_4:f,conv_5:h,conv_6:m,conv_7:v,conv_8:p,conv_9:g,conv_10:b,conv_11:w,conv_12:x,conv_13:C}}function s(){var u=o(1024,256,1,"prediction_layer/conv_0"),c=o(256,512,3,"prediction_layer/conv_1"),l=o(512,128,1,"prediction_layer/conv_2"),d=o(128,256,3,"prediction_layer/conv_3"),f=o(256,128,1,"prediction_layer/conv_4"),h=o(128,256,3,"prediction_layer/conv_5"),m=o(256,64,1,"prediction_layer/conv_6"),v=o(64,128,3,"prediction_layer/conv_7"),p=r(512,12,1,"prediction_layer/box_predictor_0/box_encoding_predictor"),g=r(512,9,1,"prediction_layer/box_predictor_0/class_predictor"),b=r(1024,24,1,"prediction_layer/box_predictor_1/box_encoding_predictor"),w=r(1024,18,1,"prediction_layer/box_predictor_1/class_predictor"),x=r(512,24,1,"prediction_layer/box_predictor_2/box_encoding_predictor"),C=r(512,18,1,"prediction_layer/box_predictor_2/class_predictor"),_=r(256,24,1,"prediction_layer/box_predictor_3/box_encoding_predictor"),E=r(256,18,1,"prediction_layer/box_predictor_3/class_predictor"),$=r(256,24,1,"prediction_layer/box_predictor_4/box_encoding_predictor"),S=r(256,18,1,"prediction_layer/box_predictor_4/class_predictor"),N=r(128,24,1,"prediction_layer/box_predictor_5/box_encoding_predictor"),F=r(128,18,1,"prediction_layer/box_predictor_5/class_predictor"),I={box_encoding_predictor:p,class_predictor:g},j={box_encoding_predictor:b,class_predictor:w},L={box_encoding_predictor:x,class_predictor:C},z={box_encoding_predictor:_,class_predictor:E},H={box_encoding_predictor:$,class_predictor:S},M={box_encoding_predictor:N,class_predictor:F};return{conv_0:u,conv_1:c,conv_2:l,conv_3:d,conv_4:f,conv_5:h,conv_6:m,conv_7:v,box_predictor_0:I,box_predictor_1:j,box_predictor_2:L,box_predictor_3:z,box_predictor_4:H,box_predictor_5:M}}return{extractMobilenetV1Params:i,extractPredictionLayerParams:s}}function u9(n){var t=[],e=ho(n),r=e.extractWeights,o=e.getRemainingWeights,a=s9(r,t),i=a.extractMobilenetV1Params,s=a.extractPredictionLayerParams,u=i(),c=s(),l=Kf(r(5118*4),[1,5118,4]),d={extra_dim:l};if(t.push({paramPath:"output_layer/extra_dim"}),o().length!==0)throw new Error("weights remaing after extract: "+o().length);return{params:{mobilenetv1:u,prediction_layer:c,output_layer:d},paramMappings:t}}function c9(n,t){var e=qo(n,t);function r(c,l,d){var f=e(c+"/Conv2d_"+l+"_pointwise/weights",4,d+"/filters"),h=e(c+"/Conv2d_"+l+"_pointwise/convolution_bn_offset",1,d+"/batch_norm_offset");return{filters:f,batch_norm_offset:h}}function o(c){var l="mobilenetv1/conv_"+c,d="MobilenetV1/Conv2d_"+c+"_depthwise",f=l+"/depthwise_conv",h=l+"/pointwise_conv",m=e(d+"/depthwise_weights",4,f+"/filters"),v=e(d+"/BatchNorm/gamma",1,f+"/batch_norm_scale"),p=e(d+"/BatchNorm/beta",1,f+"/batch_norm_offset"),g=e(d+"/BatchNorm/moving_mean",1,f+"/batch_norm_mean"),b=e(d+"/BatchNorm/moving_variance",1,f+"/batch_norm_variance");return{depthwise_conv:{filters:m,batch_norm_scale:v,batch_norm_offset:p,batch_norm_mean:g,batch_norm_variance:b},pointwise_conv:r("MobilenetV1",c,h)}}function a(){return{conv_0:r("MobilenetV1",0,"mobilenetv1/conv_0"),conv_1:o(1),conv_2:o(2),conv_3:o(3),conv_4:o(4),conv_5:o(5),conv_6:o(6),conv_7:o(7),conv_8:o(8),conv_9:o(9),conv_10:o(10),conv_11:o(11),conv_12:o(12),conv_13:o(13)}}function i(c,l){var d=e(c+"/weights",4,l+"/filters"),f=e(c+"/biases",1,l+"/bias");return{filters:d,bias:f}}function s(c){var l=i("Prediction/BoxPredictor_"+c+"/BoxEncodingPredictor","prediction_layer/box_predictor_"+c+"/box_encoding_predictor"),d=i("Prediction/BoxPredictor_"+c+"/ClassPredictor","prediction_layer/box_predictor_"+c+"/class_predictor");return{box_encoding_predictor:l,class_predictor:d}}function u(){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:u}}function l9(n){var t=[],e=c9(n,t),r=e.extractMobilenetV1Params,o=e.extractPredictionLayerParams,a=n["Output/extra_dim"];if(t.push({originalPath:"Output/extra_dim",paramPath:"output_layer/extra_dim"}),!xl(a))throw new Error("expected weightMap['Output/extra_dim'] to be a Tensor3D, instead have "+a);var i={mobilenetv1:r(),prediction_layer:o(),output_layer:{extra_dim:a}};return fo(n,t),{params:i,paramMappings:t}}function Ur(n,t,e){return xe(function(){var r=Zn(n,t.filters,e,"same");return r=qe(r,t.batch_norm_offset),mh(r,0,6)})}var d9=.0010000000474974513;function f9(n,t,e){return xe(function(){var r=fl(n,t.filters,e,"same");return r=Q1(r,t.batch_norm_mean,t.batch_norm_variance,t.batch_norm_offset,t.batch_norm_scale,d9),mh(r,0,6)})}function h9(n){return[2,4,6,12].some(function(t){return t===n})?[2,2]:[1,1]}function p9(n,t){return xe(function(){var e=null,r=Ur(n,t.conv_0,[2,2]),o=[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];if(o.forEach(function(a,i){var s=i+1,u=h9(s);r=f9(r,a.depthwise_conv,u),r=Ur(r,a.pointwise_conv,[1,1]),s===11&&(e=r)}),e===null)throw new Error("mobileNetV1 - output of conv layer 11 is null");return{out:r,conv11:e}})}function v9(n,t,e,r,o){var a=n.shape[0],i=Math.min(e,a),s=t.map(function(l,d){return{score:l,boxIndex:d}}).filter(function(l){return l.score>o}).sort(function(l,d){return d.score-l.score}),u=function(l){return l<=r?1:0},c=[];return s.forEach(function(l){if(!(c.length>=i)){for(var d=l.score,f=c.length-1;f>=0;--f){var h=m9(n,l.boxIndex,c[f]);if(h!==0&&(l.score*=u(h),l.score<=o))break}d===l.score&&c.push(l.boxIndex)}}),c}function m9(n,t,e){var r=n.arraySync(),o=Math.min(r[t][0],r[t][2]),a=Math.min(r[t][1],r[t][3]),i=Math.max(r[t][0],r[t][2]),s=Math.max(r[t][1],r[t][3]),u=Math.min(r[e][0],r[e][2]),c=Math.min(r[e][1],r[e][3]),l=Math.max(r[e][0],r[e][2]),d=Math.max(r[e][1],r[e][3]),f=(i-o)*(s-a),h=(l-u)*(d-c);if(f<=0||h<=0)return 0;var m=Math.max(o,u),v=Math.max(a,c),p=Math.min(i,l),g=Math.min(s,d),b=Math.max(p-m,0)*Math.max(g-v,0);return b/(f+h-b)}function g9(n){var t=Ut(jo(n,[1,0])),e=[Ht(t[2],t[0]),Ht(t[3],t[1])],r=[qe(t[0],ur(e[0],ve(2))),qe(t[1],ur(e[1],ve(2)))];return{sizes:e,centers:r}}function y9(n,t){var e=g9(n),r=e.sizes,o=e.centers,a=Ut(jo(t,[1,0])),i=ur(fn(gh(ur(a[2],ve(5))),r[0]),ve(2)),s=qe(fn(ur(a[0],ve(10)),r[0]),o[0]),u=ur(fn(gh(ur(a[3],ve(5))),r[1]),ve(2)),c=qe(fn(ur(a[1],ve(10)),r[1]),o[1]);return jo(Bn([Ht(s,i),Ht(c,u),qe(s,i),qe(c,u)]),[1,0])}function b9(n,t,e){return xe(function(){var r=n.shape[0],o=y9(ir(ki(e.extra_dim,[r,1,1]),[-1,4]),ir(n,[-1,4]));o=ir(o,[r,o.shape[0]/r,4]);var a=K1(Br(t,[0,0,1],[-1,-1,-1])),i=Br(a,[0,0,0],[-1,-1,1]);i=ir(i,[r,i.shape[1]]);var s=Ut(o),u=Ut(i);return{boxes:s,scores:u}})}function ji(n,t){return xe(function(){var e=n.shape[0],r=ir(cr(n,t.box_encoding_predictor),[e,-1,1,4]),o=ir(cr(n,t.class_predictor),[e,-1,3]);return{boxPredictionEncoding:r,classPrediction:o}})}function x9(n,t,e){return xe(function(){var r=Ur(n,e.conv_0,[1,1]),o=Ur(r,e.conv_1,[2,2]),a=Ur(o,e.conv_2,[1,1]),i=Ur(a,e.conv_3,[2,2]),s=Ur(i,e.conv_4,[1,1]),u=Ur(s,e.conv_5,[2,2]),c=Ur(u,e.conv_6,[1,1]),l=Ur(c,e.conv_7,[2,2]),d=ji(t,e.box_predictor_0),f=ji(n,e.box_predictor_1),h=ji(o,e.box_predictor_2),m=ji(i,e.box_predictor_3),v=ji(u,e.box_predictor_4),p=ji(l,e.box_predictor_5),g=jt([d.boxPredictionEncoding,f.boxPredictionEncoding,h.boxPredictionEncoding,m.boxPredictionEncoding,v.boxPredictionEncoding,p.boxPredictionEncoding],1),b=jt([d.classPrediction,f.classPrediction,h.classPrediction,m.classPrediction,v.classPrediction,p.classPrediction],1);return{boxPredictions:g,classPredictions:b}})}var pu=function(){function n(t){var e=t===void 0?{}:t,r=e.minConfidence,o=e.maxResults;if(this._name="SsdMobilenetv1Options",this._minConfidence=r||.5,this._maxResults=o||100,typeof this._minConfidence!="number"||this._minConfidence<=0||this._minConfidence>=1)throw new Error(this._name+" - expected minConfidence to be a number between 0 and 1");if(typeof this._maxResults!="number")throw new Error(this._name+" - expected maxResults to be a number")}return Object.defineProperty(n.prototype,"minConfidence",{get:function(){return this._minConfidence},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"maxResults",{get:function(){return this._maxResults},enumerable:!0,configurable:!0}),n}(),k2=function(n){De(t,n);function t(){return n.call(this,"SsdMobilenetv1")||this}return t.prototype.forwardInput=function(e){var r=this.params;if(!r)throw new Error("SsdMobilenetv1 - load model before inference");return xe(function(){var o=e.toBatchTensor(512,!1).toFloat(),a=Ht(fn(o,ve(.007843137718737125)),ve(1)),i=p9(a,r.mobilenetv1),s=x9(i.out,i.conv11,r.prediction_layer),u=s.boxPredictions,c=s.classPredictions;return b9(u,c,r.output_layer)})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.locateFaces=function(e,r){return r===void 0&&(r={}),$e(this,void 0,void 0,function(){var o,a,i,s,u,c,l,d,f,h,m,v,p,g,b,w,x,C,_,E,$;return ke(this,function(S){switch(S.label){case 0:return o=new pu(r),a=o.maxResults,i=o.minConfidence,[4,Zt(e)];case 1:for(s=S.sent(),u=this.forwardInput(s),c=u.boxes,l=u.scores,d=c[0],f=l[0],h=1;h<c.length;h++)c[h].dispose(),l[h].dispose();return p=(v=Array).from,[4,f.data()];case 2:return m=p.apply(v,[S.sent()]),g=.5,b=v9(d,m,a,g,i),w=s.getReshapedInputDimensions(0),x=s.inputSize,C=x/w.width,_=x/w.height,E=d.arraySync(),$=b.map(function(N){var F=[Math.max(0,E[N][0]),Math.min(1,E[N][2])].map(function(M){return M*_}),I=F[0],j=F[1],L=[Math.max(0,E[N][1]),Math.min(1,E[N][3])].map(function(M){return M*C}),z=L[0],H=L[1];return new Wr(m[N],new Yh(z,I,H-z,j-I),{height:s.getInputHeight(0),width:s.getInputWidth(0)})}),d.dispose(),f.dispose(),[2,$]}})})},t.prototype.getDefaultModelName=function(){return"ssd_mobilenetv1_model"},t.prototype.extractParamsFromWeigthMap=function(e){return l9(e)},t.prototype.extractParams=function(e){return u9(e)},t}(lo);(function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t})(k2);var w9=.4,C9=[new ct(.738768,.874946),new ct(2.42204,2.65704),new ct(4.30971,7.04493),new ct(10.246,4.59428),new ct(12.6868,11.8741)],_9=[new ct(1.603231,2.094468),new ct(6.041143,7.080126),new ct(2.882459,3.518061),new ct(4.266906,5.178857),new ct(9.041765,10.66308)],E9=[117.001,114.697,97.404],S9="tiny_yolov2_model",N9="tiny_yolov2_separable_conv_model",Il=function(n){return typeof n=="number"};function $9(n){if(!n)throw new Error("invalid config: "+n);if(typeof n.withSeparableConvs!="boolean")throw new Error("config.withSeparableConvs has to be a boolean, have: "+n.withSeparableConvs);if(!Il(n.iouThreshold)||n.iouThreshold<0||n.iouThreshold>1)throw new Error("config.iouThreshold has to be a number between [0, 1], have: "+n.iouThreshold);if(!Array.isArray(n.classes)||!n.classes.length||!n.classes.every(function(t){return typeof t=="string"}))throw new Error("config.classes has to be an array class names: string[], have: "+JSON.stringify(n.classes));if(!Array.isArray(n.anchors)||!n.anchors.length||!n.anchors.map(function(t){return t||{}}).every(function(t){return Il(t.x)&&Il(t.y)}))throw new Error("config.anchors has to be an array of { x: number, y: number }, have: "+JSON.stringify(n.anchors));if(n.meanRgb&&(!Array.isArray(n.meanRgb)||n.meanRgb.length!==3||!n.meanRgb.every(Il)))throw new Error("config.meanRgb has to be an array of shape [number, number, number], have: "+JSON.stringify(n.meanRgb))}function cp(n){return xe(function(){var t=fn(n,ve(.10000000149011612));return qe(kt(Ht(n,t)),t)})}function Ko(n,t){return xe(function(){var e=Fa(n,[[0,0],[1,1],[1,1],[0,0]]);return e=Zn(e,t.conv.filters,[1,1],"valid"),e=Ht(e,t.bn.sub),e=fn(e,t.bn.truediv),e=qe(e,t.conv.bias),cp(e)})}function Yo(n,t){return xe(function(){var e=Fa(n,[[0,0],[1,1],[1,1],[0,0]]);return e=Ch(e,t.depthwise_filter,t.pointwise_filter,[1,1],"valid"),e=qe(e,t.bias),cp(e)})}function k9(n,t){var e=$l(n,t);function r(i,s){var u=Dt(n(i)),c=Dt(n(i));return t.push({paramPath:s+"/sub"},{paramPath:s+"/truediv"}),{sub:u,truediv:c}}function o(i,s,u){var c=e(i,s,3,u+"/conv"),l=r(s,u+"/bn");return{conv:c,bn:l}}var a=op(n,t);return{extractConvParams:e,extractConvWithBatchNormParams:o,extractSeparableConvParams:a}}function P9(n,t,e,r){var o=ho(n),a=o.extractWeights,i=o.getRemainingWeights,s=[],u=k9(a,s),c=u.extractConvParams,l=u.extractConvWithBatchNormParams,d=u.extractSeparableConvParams,f;if(t.withSeparableConvs){var h=r[0],m=r[1],v=r[2],p=r[3],g=r[4],b=r[5],w=r[6],x=r[7],C=r[8],_=t.isFirstLayerConv2d?c(h,m,3,"conv0"):d(h,m,"conv0"),E=d(m,v,"conv1"),$=d(v,p,"conv2"),S=d(p,g,"conv3"),N=d(g,b,"conv4"),F=d(b,w,"conv5"),I=x?d(w,x,"conv6"):void 0,j=C?d(x,C,"conv7"):void 0,L=c(C||x||w,5*e,1,"conv8");f={conv0:_,conv1:E,conv2:$,conv3:S,conv4:N,conv5:F,conv6:I,conv7:j,conv8:L}}else{var h=r[0],m=r[1],v=r[2],p=r[3],g=r[4],b=r[5],w=r[6],x=r[7],C=r[8],_=l(h,m,"conv0"),E=l(m,v,"conv1"),$=l(v,p,"conv2"),S=l(p,g,"conv3"),N=l(g,b,"conv4"),F=l(b,w,"conv5"),I=l(w,x,"conv6"),j=l(x,C,"conv7"),L=c(C,5*e,1,"conv8");f={conv0:_,conv1:E,conv2:$,conv3:S,conv4:N,conv5:F,conv6:I,conv7:j,conv8:L}}if(i().length!==0)throw new Error("weights remaing after extract: "+i().length);return{params:f,paramMappings:s}}function I9(n,t){var e=qo(n,t);function r(s){var u=e(s+"/sub",1),c=e(s+"/truediv",1);return{sub:u,truediv:c}}function o(s){var u=e(s+"/filters",4),c=e(s+"/bias",1);return{filters:u,bias:c}}function a(s){var u=o(s+"/conv"),c=r(s+"/bn");return{conv:u,bn:c}}var i=ap(e);return{extractConvParams:o,extractConvWithBatchNormParams:a,extractSeparableConvParams:i}}function A9(n,t){var e=[],r=I9(n,e),o=r.extractConvParams,a=r.extractConvWithBatchNormParams,i=r.extractSeparableConvParams,s;if(t.withSeparableConvs){var u=t.filterSizes&&t.filterSizes.length||9;s={conv0:t.isFirstLayerConv2d?o("conv0"):i("conv0"),conv1:i("conv1"),conv2:i("conv2"),conv3:i("conv3"),conv4:i("conv4"),conv5:i("conv5"),conv6:u>7?i("conv6"):void 0,conv7:u>8?i("conv7"):void 0,conv8:o("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:o("conv8")};return fo(n,e),{params:s,paramMappings:e}}var P2;(function(n){n[n.XS=224]="XS",n[n.SM=320]="SM",n[n.MD=416]="MD",n[n.LG=608]="LG"})(P2||(P2={}));var lp=function(){function n(t){var e=t===void 0?{}:t,r=e.inputSize,o=e.scoreThreshold;if(this._name="TinyYolov2Options",this._inputSize=r||416,this._scoreThreshold=o||.5,typeof this._inputSize!="number"||this._inputSize%32!==0)throw new Error(this._name+" - expected inputSize to be a number divisible by 32");if(typeof this._scoreThreshold!="number"||this._scoreThreshold<=0||this._scoreThreshold>=1)throw new Error(this._name+" - expected scoreThreshold to be a number between 0 and 1")}return Object.defineProperty(n.prototype,"inputSize",{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"scoreThreshold",{get:function(){return this._scoreThreshold},enumerable:!0,configurable:!0}),n}(),I2=function(n){De(t,n);function t(e){var r=n.call(this,"TinyYolov2")||this;return $9(e),r._config=e,r}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,r){var o=Ko(e,r.conv0);return o=Xt(o,[2,2],[2,2],"same"),o=Ko(o,r.conv1),o=Xt(o,[2,2],[2,2],"same"),o=Ko(o,r.conv2),o=Xt(o,[2,2],[2,2],"same"),o=Ko(o,r.conv3),o=Xt(o,[2,2],[2,2],"same"),o=Ko(o,r.conv4),o=Xt(o,[2,2],[2,2],"same"),o=Ko(o,r.conv5),o=Xt(o,[2,2],[1,1],"same"),o=Ko(o,r.conv6),o=Ko(o,r.conv7),cr(o,r.conv8,"valid",!1)},t.prototype.runMobilenet=function(e,r){var o=this.config.isFirstLayerConv2d?cp(cr(e,r.conv0,"valid",!1)):Yo(e,r.conv0);return o=Xt(o,[2,2],[2,2],"same"),o=Yo(o,r.conv1),o=Xt(o,[2,2],[2,2],"same"),o=Yo(o,r.conv2),o=Xt(o,[2,2],[2,2],"same"),o=Yo(o,r.conv3),o=Xt(o,[2,2],[2,2],"same"),o=Yo(o,r.conv4),o=Xt(o,[2,2],[2,2],"same"),o=Yo(o,r.conv5),o=Xt(o,[2,2],[1,1],"same"),o=r.conv6?Yo(o,r.conv6):o,o=r.conv7?Yo(o,r.conv7):o,cr(o,r.conv8,"valid",!1)},t.prototype.forwardInput=function(e,r){var o=this,a=this.params;if(!a)throw new Error("TinyYolov2 - load model before inference");return xe(function(){var i=e.toBatchTensor(r,!1).toFloat();return i=o.config.meanRgb?hu(i,o.config.meanRgb):i,i=i.div(ve(256)),o.config.withSeparableConvs?o.runMobilenet(i,a):o.runTinyYolov2(i,a)})},t.prototype.forward=function(e,r){return $e(this,void 0,void 0,function(){var o;return ke(this,function(a){switch(a.label){case 0:return o=this.forwardInput,[4,Zt(e)];case 1:return[4,o.apply(this,[a.sent(),r])];case 2:return[2,a.sent()]}})})},t.prototype.detect=function(e,r){return r===void 0&&(r={}),$e(this,void 0,void 0,function(){var o,a,i,s,u,c,l,d,f,h,m,v,p,g,b=this;return ke(this,function(w){switch(w.label){case 0:return o=new lp(r),a=o.inputSize,i=o.scoreThreshold,[4,Zt(e)];case 1:return s=w.sent(),[4,this.forwardInput(s,a)];case 2:return u=w.sent(),c=xe(function(){return Ut(u)[0].expandDims()}),l={width:s.getInputWidth(0),height:s.getInputHeight(0)},[4,this.extractBoxes(c,s.getReshapedInputDimensions(0),i)];case 3:return d=w.sent(),u.dispose(),c.dispose(),f=d.map(function(x){return x.box}),h=d.map(function(x){return x.score}),m=d.map(function(x){return x.classScore}),v=d.map(function(x){return b.config.classes[x.label]}),p=fu(f.map(function(x){return x.rescale(a)}),h,this.config.iouThreshold,!0),g=p.map(function(x){return new Xb(h[x],m[x],v[x],f[x],l)}),[2,g]}})})},t.prototype.getDefaultModelName=function(){return""},t.prototype.extractParamsFromWeigthMap=function(e){return A9(e,this.config)},t.prototype.extractParams=function(e){var r=this.config.filterSizes||t.DEFAULT_FILTER_SIZES,o=r?r.length:void 0;if(o!==7&&o!==8&&o!==9)throw new Error("TinyYolov2 - expected 7 | 8 | 9 convolutional filters, but found "+o+" filterSizes in config");return P9(e,this.config,this.boxEncodingSize,r)},t.prototype.extractBoxes=function(e,r,o){return $e(this,void 0,void 0,function(){var a,i,s,u,c,l,d,f,h,m,v,p,g,b,w,x,C,_,E,$,S,N,F,I,j,L,z,H,M,T=this;return ke(this,function(A){switch(A.label){case 0:return a=r.width,i=r.height,s=Math.max(a,i),u=s/a,c=s/i,l=e.shape[1],d=this.config.anchors.length,f=xe(function(){var P=e.reshape([l,l,d,T.boxEncodingSize]),B=P.slice([0,0,0,0],[l,l,d,4]),K=P.slice([0,0,0,4],[l,l,d,1]),q=T.withClassScores?io(P.slice([0,0,0,5],[l,l,d,T.config.classes.length]),3):ve(0);return[B,K,q]}),h=f[0],m=f[1],v=f[2],p=[],[4,m.array()];case 1:return g=A.sent(),[4,h.array()];case 2:b=A.sent(),w=0,A.label=3;case 3:if(!(w<l))return[3,12];x=0,A.label=4;case 4:if(!(x<l))return[3,11];C=0,A.label=5;case 5:return C<d?(_=Kh(g[w][x][C][0]),!o||_>o?(E=(x+Kh(b[w][x][C][0]))/l*u,$=(w+Kh(b[w][x][C][1]))/l*c,S=Math.exp(b[w][x][C][2])*this.config.anchors[C].x/l*u,N=Math.exp(b[w][x][C][3])*this.config.anchors[C].y/l*c,F=E-S/2,I=$-N/2,j={row:w,col:x,anchor:C},this.withClassScores?[4,this.extractPredictedClass(v,j)]:[3,7]):[3,9]):[3,10];case 6:return M=A.sent(),[3,8];case 7:M={classScore:1,label:0},A.label=8;case 8:L=M,z=L.classScore,H=L.label,p.push(pn({box:new wl(F,I,F+S,I+N),score:_,classScore:_*z,label:H},j)),A.label=9;case 9:return C++,[3,5];case 10:return x++,[3,4];case 11:return w++,[3,3];case 12:return h.dispose(),m.dispose(),v.dispose(),[2,p]}})})},t.prototype.extractPredictedClass=function(e,r){return $e(this,void 0,void 0,function(){var o,a,i,s;return ke(this,function(u){switch(u.label){case 0:return o=r.row,a=r.col,i=r.anchor,[4,e.array()];case 1:return s=u.sent(),[2,Array(this.config.classes.length).fill(0).map(function(c,l){return s[o][a][i][l]}).map(function(c,l){return{classScore:c,label:l}}).reduce(function(c,l){return c.classScore>l.classScore?c:l})]}})})},t.DEFAULT_FILTER_SIZES=[3,16,32,64,128,256,512,1024,1024],t}(lo),T9=function(n){De(t,n);function t(e){e===void 0&&(e=!0);var r=this,o=Object.assign({},{withSeparableConvs:e,iouThreshold:w9,classes:["face"]},e?{anchors:_9,meanRgb:E9}:{anchors:C9,withClassScores:!0});return r=n.call(this,o)||this,r}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,r){return $e(this,void 0,void 0,function(){var o;return ke(this,function(a){switch(a.label){case 0:return[4,this.detect(e,r)];case 1:return o=a.sent(),[2,o.map(function(i){return new Wr(i.score,i.relativeBox,{width:i.imageWidth,height:i.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return this.withSeparableConvs?N9:S9},t.prototype.extractParamsFromWeigthMap=function(e){return n.prototype.extractParamsFromWeigthMap.call(this,e)},t}(I2),O9=function(n){De(t,n);function t(){var e=n!==null&&n.apply(this,arguments)||this;return e._name="TinyFaceDetectorOptions",e}return t}(lp),vu=function(){function n(){}return n.prototype.then=function(t){return $e(this,void 0,void 0,function(){var e;return ke(this,function(r){switch(r.label){case 0:return e=t,[4,this.run()];case 1:return[2,e.apply(void 0,[r.sent()])]}})})},n.prototype.run=function(){return $e(this,void 0,void 0,function(){return ke(this,function(t){throw new Error("ComposableTask - run is not implemented")})})},n}();function Al(n,t,e,r,o){return o===void 0&&(o=function(a){var i=a.alignedRect;return i}),$e(this,void 0,void 0,function(){var a,i,s,u,c;return ke(this,function(l){switch(l.label){case 0:return a=n.map(function(d){return W5(d)?o(d):d.detection}),s=r,s?[3,5]:t instanceof Nt?[4,tp(t,a)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,ep(t,a)];case 3:u=l.sent(),l.label=4;case 4:s=u,l.label=5;case 5:return i=s,[4,e(i)];case 6:return c=l.sent(),i.forEach(function(d){return d instanceof Nt&&d.dispose()}),[2,c]}})})}function dp(n,t,e,r,o){return $e(this,void 0,void 0,function(){var a=this;return ke(this,function(i){return[2,Al([n],t,function(s){return $e(a,void 0,void 0,function(){return ke(this,function(u){return[2,e(s[0])]})})},r,o)]})})}function D9(n){return xe(function(){return Bn(Ut(n,3).reverse(),3)})}var Tl=2,Ol=12;function F9(n,t){var e=$l(n,t),r=rp(n,t);function o(c,l){var d=Dt(n(c));return t.push({paramPath:l}),d}function a(c,l,d){d===void 0&&(d=!1);var f=e(c[0],c[1],3,l+"/conv1"),h=o(c[1],l+"/prelu1_alpha"),m=e(c[1],c[2],3,l+"/conv2"),v=o(c[2],l+"/prelu2_alpha"),p=e(c[2],c[3],d?2:3,l+"/conv3"),g=o(c[3],l+"/prelu3_alpha");return{conv1:f,prelu1_alpha:h,conv2:m,prelu2_alpha:v,conv3:p,prelu3_alpha:g}}function i(){var c=a([3,10,16,32],"pnet"),l=e(32,2,1,"pnet/conv4_1"),d=e(32,4,1,"pnet/conv4_2");return pn(pn({},c),{conv4_1:l,conv4_2:d})}function s(){var c=a([3,28,48,64],"rnet",!0),l=r(576,128,"rnet/fc1"),d=o(128,"rnet/prelu4_alpha"),f=r(128,2,"rnet/fc2_1"),h=r(128,4,"rnet/fc2_2");return pn(pn({},c),{fc1:l,prelu4_alpha:d,fc2_1:f,fc2_2:h})}function u(){var c=a([3,32,64,64],"onet"),l=e(64,128,2,"onet/conv4"),d=o(128,"onet/prelu4_alpha"),f=r(1152,256,"onet/fc1"),h=o(256,"onet/prelu5_alpha"),m=r(256,2,"onet/fc2_1"),v=r(256,4,"onet/fc2_2"),p=r(256,10,"onet/fc2_3");return pn(pn({},c),{conv4:l,prelu4_alpha:d,fc1:f,prelu5_alpha:h,fc2_1:m,fc2_2:v,fc2_3:p})}return{extractPNetParams:i,extractRNetParams:s,extractONetParams:u}}function M9(n){var t=ho(n),e=t.extractWeights,r=t.getRemainingWeights,o=[],a=F9(e,o),i=a.extractPNetParams,s=a.extractRNetParams,u=a.extractONetParams,c=i(),l=s(),d=u();if(r().length!==0)throw new Error("weights remaing after extract: "+r().length);return{params:{pnet:c,rnet:l,onet:d},paramMappings:o}}function R9(n,t){var e=qo(n,t);function r(l){var d=e(l+"/weights",4,l+"/filters"),f=e(l+"/bias",1);return{filters:d,bias:f}}function o(l){var d=e(l+"/weights",2),f=e(l+"/bias",1);return{weights:d,bias:f}}function a(l){return e(l,1)}function i(l){var d=r(l+"/conv1"),f=a(l+"/prelu1_alpha"),h=r(l+"/conv2"),m=a(l+"/prelu2_alpha"),v=r(l+"/conv3"),p=a(l+"/prelu3_alpha");return{conv1:d,prelu1_alpha:f,conv2:h,prelu2_alpha:m,conv3:v,prelu3_alpha:p}}function s(){var l=i("pnet"),d=r("pnet/conv4_1"),f=r("pnet/conv4_2");return pn(pn({},l),{conv4_1:d,conv4_2:f})}function u(){var l=i("rnet"),d=o("rnet/fc1"),f=a("rnet/prelu4_alpha"),h=o("rnet/fc2_1"),m=o("rnet/fc2_2");return pn(pn({},l),{fc1:d,prelu4_alpha:f,fc2_1:h,fc2_2:m})}function c(){var l=i("onet"),d=r("onet/conv4"),f=a("onet/prelu4_alpha"),h=o("onet/fc1"),m=a("onet/prelu5_alpha"),v=o("onet/fc2_1"),p=o("onet/fc2_2"),g=o("onet/fc2_3");return pn(pn({},l),{conv4:d,prelu4_alpha:f,fc1:h,prelu5_alpha:m,fc2_1:v,fc2_2:p,fc2_3:g})}return{extractPNetParams:s,extractRNetParams:u,extractONetParams:c}}function L9(n){var t=[],e=R9(n,t),r=e.extractPNetParams,o=e.extractRNetParams,a=e.extractONetParams,i=r(),s=o(),u=a();return fo(n,t),{params:{pnet:i,rnet:s,onet:u},paramMappings:t}}function fp(n,t){var e=t[0],r=t[1];return{height:Math.floor(e*n),width:Math.floor(r*n)}}function B9(n,t,e){for(var r=e[0],o=e[1],a=Ol/n,i=[],s=Math.min(r,o)*a,u=0;s>=12;)i.push(a*Math.pow(t,u)),s=s*t,u+=1;return i}var hp=function(n){De(t,n);function t(e,r,o,a){return n.call(this,{left:e,top:r,right:o,bottom:a},!0)||this}return t}(Go);function A2(n){return xe(function(){return fn(Ht(n,ve(127.5)),ve(.0078125))})}function Ui(n,t){return xe(function(){return qe(kt(n),fn(t,sl(kt(sl(n)))))})}function pp(n,t,e){return e===void 0&&(e=!1),xe(function(){var r=cr(n,t.conv1,"valid");return r=Ui(r,t.prelu1_alpha),r=Xt(r,e?[2,2]:[3,3],[2,2],"same"),r=cr(r,t.conv2,"valid"),r=Ui(r,t.prelu2_alpha),r=e?r:Xt(r,[3,3],[2,2],"valid"),r=cr(r,t.conv3,"valid"),r=Ui(r,t.prelu3_alpha),r})}function W9(n,t){return xe(function(){var e=pp(n,t,!0),r=cr(e,t.conv4_1,"valid"),o=Xn(pl(r,3),3),a=io(Ht(r,o),3),i=cr(e,t.conv4_2,"valid");return{prob:a,regions:i}})}function V9(n,t){return xe(function(){var e=fp(t,n.shape.slice(1)),r=e.height,o=e.width,a=$h.resizeBilinear(n,[r,o]),i=A2(a);return jo(i,[0,2,1,3])})}function j9(n,t,e,r){for(var o=[],a=n.arraySync(),i=0;i<n.shape[0];i++)for(var s=0;s<n.shape[1];s++)a[i][s]>=r&&o.push(new ct(s,i));var u=o.map(function(c){var l=new wl(Math.round((c.y*Tl+1)/e),Math.round((c.x*Tl+1)/e),Math.round((c.y*Tl+Ol)/e),Math.round((c.x*Tl+Ol)/e)),d=a[c.y][c.x],f=t.arraySync(),h=new hp(f[c.y][c.x][0],f[c.y][c.x][1],f[c.y][c.x][2],f[c.y][c.x][3]);return{cell:l,score:d,region:h}});return u}function U9(n,t,e,r,o){o.stage1=[];var a=t.map(function(f){return xe(function(){var h={scale:f},m=V9(n,f),v=Date.now(),p=W9(m,r),g=p.prob,b=p.regions;h.pnet=Date.now()-v;var w=Ut(Ut(g,3)[1])[0],x=Ut(b)[0];return{scoresTensor:w,regionsTensor:x,scale:f,statsForScale:h}})}),i=a.map(function(f){var h=f.scoresTensor,m=f.regionsTensor,v=f.scale,p=f.statsForScale,g=j9(h,m,v,e);if(h.dispose(),m.dispose(),!g.length)return o.stage1.push(p),[];var b=Date.now(),w=fu(g.map(function(x){return x.cell}),g.map(function(x){return x.score}),.5);return p.nms=Date.now()-b,p.numBoxes=w.length,o.stage1.push(p),w.map(function(x){return g[x]})}),s=i.reduce(function(f,h){return f.concat(h)},[]),u=[],c=[];if(s.length>0){var l=Date.now(),d=fu(s.map(function(f){return f.cell}),s.map(function(f){return f.score}),.7);o.stage1_nms=Date.now()-l,c=d.map(function(f){return s[f].score}),u=d.map(function(f){return s[f]}).map(function(f){var h=f.cell,m=f.region;return new wl(h.left+m.left*h.width,h.top+m.top*h.height,h.right+m.right*h.width,h.bottom+m.bottom*h.height).toSquare().round()})}return{boxes:u,scores:c}}function T2(n,t,e){var r=e.width,o=e.height;return $e(this,void 0,void 0,function(){var a,i,s,u=this;return ke(this,function(c){switch(c.label){case 0:return a=za(n),[4,Promise.all(t.map(function(l){return $e(u,void 0,void 0,function(){var d,f,h,m,v,p,g,b;return ke(this,function(w){return d=l.padAtBorders(n.height,n.width),f=d.y,h=d.ey,m=d.x,v=d.ex,p=m-1,g=f-1,b=a.getImageData(p,g,v-p,h-g),[2,on.isNodejs()?Jh(b):createImageBitmap(b)]})})}))];case 1:return i=c.sent(),s=[],i.forEach(function(l){var d=El({width:r,height:o}),f=za(d);f.drawImage(l,0,0,r,o);for(var h=f.getImageData(0,0,r,o).data,m=[],v=0;v<h.length;v+=4)m.push(h[v+2]),m.push(h[v+1]),m.push(h[v]);s.push(m)}),[2,s.map(function(l){var d=xe(function(){var f=jo(Sn(l,[1,r,o,3]),[0,2,1,3]).toFloat();return A2(f)});return d})]}})})}function z9(n,t){return xe(function(){var e=pp(n,t),r=ir(e,[e.shape[0],t.fc1.weights.shape[0]]),o=Vr(r,t.fc1),a=Ui(o,t.prelu4_alpha),i=Vr(a,t.fc2_1),s=Xn(pl(i,1),1),u=io(Ht(i,s),1),c=Vr(a,t.fc2_2),l=Ut(u,1)[1];return{scores:l,regions:c}})}function H9(n,t,e,r,o){return $e(this,void 0,void 0,function(){var a,i,s,u,c,l,d,f,h,m,v,p,g,b;return ke(this,function(w){switch(w.label){case 0:return a=Date.now(),[4,T2(n,t,{width:24,height:24})];case 1:return i=w.sent(),o.stage2_extractImagePatches=Date.now()-a,a=Date.now(),s=i.map(function(x){var C=z9(x,r);return x.dispose(),C}),o.stage2_rnet=Date.now()-a,u=s.length>1?jt(s.map(function(x){return x.scores})):s[0].scores,d=(l=Array).from,[4,u.data()];case 2:return c=d.apply(l,[w.sent()]),u.dispose(),f=c.map(function(x,C){return{score:x,idx:C}}).filter(function(x){return x.score>e}).map(function(x){var C=x.idx;return C}),h=f.map(function(x){return t[x]}),m=f.map(function(x){return c[x]}),v=[],p=[],h.length>0&&(a=Date.now(),g=fu(h,m,.7),o.stage2_nms=Date.now()-a,b=g.map(function(x){var C=s[f[x]].regions.arraySync();return new hp(C[0][0],C[0][1],C[0][2],C[0][3])}),p=g.map(function(x){return m[x]}),v=g.map(function(x,C){return h[x].calibrate(b[C])})),s.forEach(function(x){x.regions.dispose(),x.scores.dispose()}),[2,{boxes:v,scores:p}]}})})}function G9(n,t){return xe(function(){var e=pp(n,t);e=Xt(e,[2,2],[2,2],"same"),e=cr(e,t.conv4,"valid"),e=Ui(e,t.prelu4_alpha);var r=ir(e,[e.shape[0],t.fc1.weights.shape[0]]),o=Vr(r,t.fc1),a=Ui(o,t.prelu5_alpha),i=Vr(a,t.fc2_1),s=Xn(pl(i,1),1),u=io(Ht(i,s),1),c=Vr(a,t.fc2_2),l=Vr(a,t.fc2_3),d=Ut(u,1)[1];return{scores:d,regions:c,points:l}})}function q9(n,t,e,r,o){return $e(this,void 0,void 0,function(){var a,i,s,u,c,l,d,f,h,m,v,p,g,b,w;return ke(this,function(x){switch(x.label){case 0:return a=Date.now(),[4,T2(n,t,{width:48,height:48})];case 1:return i=x.sent(),o.stage3_extractImagePatches=Date.now()-a,a=Date.now(),s=i.map(function(C){var _=G9(C,r);return C.dispose(),_}),o.stage3_onet=Date.now()-a,u=s.length>1?jt(s.map(function(C){return C.scores})):s[0].scores,d=(l=Array).from,[4,u.data()];case 2:return c=d.apply(l,[x.sent()]),u.dispose(),f=c.map(function(C,_){return{score:C,idx:_}}).filter(function(C){return C.score>e}).map(function(C){var _=C.idx;return _}),h=f.map(function(C){var _=s[C].regions.arraySync();return new hp(_[0][0],_[0][1],_[0][2],_[0][3])}),m=f.map(function(C,_){return t[C].calibrate(h[_])}),v=f.map(function(C){return c[C]}),p=[],g=[],b=[],m.length>0&&(a=Date.now(),w=fu(m,v,.7,!1),o.stage3_nms=Date.now()-a,p=w.map(function(C){return m[C]}),g=w.map(function(C){return v[C]}),b=w.map(function(C,_){return Array(5).fill(0).map(function(E,$){var S=s[C].points.arraySync();return new ct(S[0][$]*(p[_].width+1)+p[_].left,S[0][$+5]*(p[_].height+1)+p[_].top)})})),s.forEach(function(C){C.regions.dispose(),C.scores.dispose(),C.points.dispose()}),[2,{boxes:p,scores:g,points:b}]}})})}var K9=function(n){De(t,n);function t(){return n.call(this,"Mtcnn")||this}return t.prototype.load=function(e){return $e(this,void 0,void 0,function(){return ke(this,function(r){return console.warn("mtcnn is deprecated and will be removed soon"),[2,n.prototype.load.call(this,e)]})})},t.prototype.loadFromDisk=function(e){return $e(this,void 0,void 0,function(){return ke(this,function(r){return console.warn("mtcnn is deprecated and will be removed soon"),[2,n.prototype.loadFromDisk.call(this,e)]})})},t.prototype.forwardInput=function(e,r){return r===void 0&&(r={}),$e(this,void 0,void 0,function(){var o,a,i,s,u,c,l,d,f,h,m,v,p,g,b,w,x,C,_,E,$;return ke(this,function(S){switch(S.label){case 0:if(o=this.params,!o)throw new Error("Mtcnn - load model before inference");if(a=e.canvases[0],!a)throw new Error("Mtcnn - inputCanvas is not defined, note that passing tensors into Mtcnn.forwardInput is not supported yet.");return i={},s=Date.now(),u=xe(function(){return D9(Xn(Hh.fromPixels(a)).toFloat())}),c=function(N){return u.dispose(),i.total=Date.now()-s,N},l=u.shape.slice(1),d=l[0],f=l[1],h=new $2(r),m=h.minFaceSize,v=h.scaleFactor,p=h.maxNumScales,g=h.scoreThresholds,b=h.scaleSteps,w=(b||B9(m,v,[d,f])).filter(function(N){var F=fp(N,[d,f]);return Math.min(F.width,F.height)>Ol}).slice(0,p),i.scales=w,i.pyramid=w.map(function(N){return fp(N,[d,f])}),x=Date.now(),[4,U9(u,w,g[0],o.pnet,i)];case 1:return C=S.sent(),i.total_stage1=Date.now()-x,C.boxes.length?(i.stage2_numInputBoxes=C.boxes.length,x=Date.now(),[4,H9(a,C.boxes,g[1],o.rnet,i)]):[2,c({results:[],stats:i})];case 2:return _=S.sent(),i.total_stage2=Date.now()-x,_.boxes.length?(i.stage3_numInputBoxes=_.boxes.length,x=Date.now(),[4,q9(a,_.boxes,g[2],o.onet,i)]):[2,c({results:[],stats:i})];case 3:return E=S.sent(),i.total_stage3=Date.now()-x,$=E.boxes.map(function(N,F){return ip(Xh({},new Wr(E.scores[F],new Yh(N.left/f,N.top/d,N.width/f,N.height/d),{height:d,width:f})),new _5(E.points[F].map(function(I){return I.sub(new ct(N.left,N.top)).div(new ct(N.width,N.height))}),{width:N.width,height:N.height}))}),[2,c({results:$,stats:i})]}})})},t.prototype.forward=function(e,r){return r===void 0&&(r={}),$e(this,void 0,void 0,function(){var o;return ke(this,function(a){switch(a.label){case 0:return o=this.forwardInput,[4,Zt(e)];case 1:return[4,o.apply(this,[a.sent(),r])];case 2:return[2,a.sent().results]}})})},t.prototype.forwardWithStats=function(e,r){return r===void 0&&(r={}),$e(this,void 0,void 0,function(){var o;return ke(this,function(a){switch(a.label){case 0:return o=this.forwardInput,[4,Zt(e)];case 1:return[2,o.apply(this,[a.sent(),r])]}})})},t.prototype.getDefaultModelName=function(){return"mtcnn_model"},t.prototype.extractParamsFromWeigthMap=function(e){return L9(e)},t.prototype.extractParams=function(e){return M9(e)},t}(lo),Y9=.4,X9=[new ct(1.603231,2.094468),new ct(6.041143,7.080126),new ct(2.882459,3.518061),new ct(4.266906,5.178857),new ct(9.041765,10.66308)],Z9=[117.001,114.697,97.404],Q9=function(n){De(t,n);function t(){var e=this,r={withSeparableConvs:!0,iouThreshold:Y9,classes:["face"],anchors:X9,meanRgb:Z9,isFirstLayerConv2d:!0,filterSizes:[3,16,32,64,128,256,512]};return e=n.call(this,r)||this,e}return Object.defineProperty(t.prototype,"anchors",{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),t.prototype.locateFaces=function(e,r){return $e(this,void 0,void 0,function(){var o;return ke(this,function(a){switch(a.label){case 0:return[4,this.detect(e,r)];case 1:return o=a.sent(),[2,o.map(function(i){return new Wr(i.score,i.relativeBox,{width:i.imageWidth,height:i.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return"tiny_face_detector_model"},t.prototype.extractParamsFromWeigthMap=function(e){return n.prototype.extractParamsFromWeigthMap.call(this,e)},t}(I2),mn={ssdMobilenetv1:new k2,tinyFaceDetector:new Q9,tinyYolov2:new T9,mtcnn:new K9,faceLandmark68Net:new w2,faceLandmark68TinyNet:new J5,faceRecognitionNet:new i9,faceExpressionNet:new B5,ageGenderNet:new Y5},O2=function(n){De(t,n);function t(e,r,o){var a=n.call(this)||this;return a.parentTask=e,a.input=r,a.extractedFaces=o,a}return t}(vu),vp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r,o=this;return ke(this,function(a){switch(a.label){case 0:return[4,this.parentTask];case 1:return e=a.sent(),[4,Al(e,this.input,function(i){return $e(o,void 0,void 0,function(){return ke(this,function(s){switch(s.label){case 0:return[4,Promise.all(i.map(function(u){return mn.faceExpressionNet.predictExpressions(u)}))];case 1:return[2,s.sent()]}})})},this.extractedFaces)];case 2:return r=a.sent(),[2,e.map(function(i,s){return y2(i,r[s])})]}})})},t.prototype.withAgeAndGender=function(){return new bp(this,this.input)},t}(O2),mp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r;return ke(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return e=o.sent(),e?[4,dp(e,this.input,function(a){return mn.faceExpressionNet.predictExpressions(a)},this.extractedFaces)]:[2];case 2:return r=o.sent(),[2,y2(e,r)]}})})},t.prototype.withAgeAndGender=function(){return new xp(this,this.input)},t}(O2),gp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new wp(this,this.input)},t.prototype.withFaceDescriptors=function(){return new _p(this,this.input)},t}(vp),yp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new Cp(this,this.input)},t.prototype.withFaceDescriptor=function(){return new Ep(this,this.input)},t}(mp),D2=function(n){De(t,n);function t(e,r,o){var a=n.call(this)||this;return a.parentTask=e,a.input=r,a.extractedFaces=o,a}return t}(vu),bp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r,o=this;return ke(this,function(a){switch(a.label){case 0:return[4,this.parentTask];case 1:return e=a.sent(),[4,Al(e,this.input,function(i){return $e(o,void 0,void 0,function(){return ke(this,function(s){switch(s.label){case 0:return[4,Promise.all(i.map(function(u){return mn.ageGenderNet.predictAgeAndGender(u)}))];case 1:return[2,s.sent()]}})})},this.extractedFaces)];case 2:return r=a.sent(),[2,e.map(function(i,s){var u=r[s],c=u.age,l=u.gender,d=u.genderProbability;return S2(N2(i,l,d),c)})]}})})},t.prototype.withFaceExpressions=function(){return new vp(this,this.input)},t}(D2),xp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r,o,a,i;return ke(this,function(s){switch(s.label){case 0:return[4,this.parentTask];case 1:return e=s.sent(),e?[4,dp(e,this.input,function(u){return mn.ageGenderNet.predictAgeAndGender(u)},this.extractedFaces)]:[2];case 2:return r=s.sent(),o=r.age,a=r.gender,i=r.genderProbability,[2,S2(N2(e,a,i),o)]}})})},t.prototype.withFaceExpressions=function(){return new mp(this,this.input)},t}(D2),wp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new gp(this,this.input)},t.prototype.withFaceDescriptors=function(){return new _p(this,this.input)},t}(bp),Cp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new yp(this,this.input)},t.prototype.withFaceDescriptor=function(){return new Ep(this,this.input)},t}(xp),F2=function(n){De(t,n);function t(e,r){var o=n.call(this)||this;return o.parentTask=e,o.input=r,o}return t}(vu),_p=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r;return ke(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return e=o.sent(),[4,Al(e,this.input,function(a){return Promise.all(a.map(function(i){return mn.faceRecognitionNet.computeFaceDescriptor(i)}))},null,function(a){return a.landmarks.align(null,{useDlibAlignment:!0})})];case 2:return r=o.sent(),[2,r.map(function(a,i){return E2(e[i],a)})]}})})},t.prototype.withFaceExpressions=function(){return new gp(this,this.input)},t.prototype.withAgeAndGender=function(){return new wp(this,this.input)},t}(F2),Ep=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r;return ke(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return e=o.sent(),e?[4,dp(e,this.input,function(a){return mn.faceRecognitionNet.computeFaceDescriptor(a)},null,function(a){return a.landmarks.align(null,{useDlibAlignment:!0})})]:[2];case 2:return r=o.sent(),[2,E2(e,r)]}})})},t.prototype.withFaceExpressions=function(){return new yp(this,this.input)},t.prototype.withAgeAndGender=function(){return new Cp(this,this.input)},t}(F2),M2=function(n){De(t,n);function t(e,r,o){var a=n.call(this)||this;return a.parentTask=e,a.input=r,a.useTinyLandmarkNet=o,a}return Object.defineProperty(t.prototype,"landmarkNet",{get:function(){return this.useTinyLandmarkNet?mn.faceLandmark68TinyNet:mn.faceLandmark68Net},enumerable:!0,configurable:!0}),t}(vu),J9=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r,o,a,i,s=this;return ke(this,function(u){switch(u.label){case 0:return[4,this.parentTask];case 1:return e=u.sent(),r=e.map(function(c){return c.detection}),this.input instanceof Nt?[4,tp(this.input,r)]:[3,3];case 2:return a=u.sent(),[3,5];case 3:return[4,ep(this.input,r)];case 4:a=u.sent(),u.label=5;case 5:return o=a,[4,Promise.all(o.map(function(c){return s.landmarkNet.detectLandmarks(c)}))];case 6:return i=u.sent(),o.forEach(function(c){return c instanceof Nt&&c.dispose()}),[2,e.map(function(c,l){return ip(c,i[l])})]}})})},t.prototype.withFaceExpressions=function(){return new gp(this,this.input)},t.prototype.withAgeAndGender=function(){return new wp(this,this.input)},t.prototype.withFaceDescriptors=function(){return new _p(this,this.input)},t}(M2),eD=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r,o,a,i;return ke(this,function(s){switch(s.label){case 0:return[4,this.parentTask];case 1:return e=s.sent(),e?(r=e.detection,this.input instanceof Nt?[4,tp(this.input,[r])]:[3,3]):[2];case 2:return a=s.sent(),[3,5];case 3:return[4,ep(this.input,[r])];case 4:a=s.sent(),s.label=5;case 5:return o=a,[4,this.landmarkNet.detectLandmarks(o[0])];case 6:return i=s.sent(),o.forEach(function(u){return u instanceof Nt&&u.dispose()}),[2,ip(e,i)]}})})},t.prototype.withFaceExpressions=function(){return new yp(this,this.input)},t.prototype.withAgeAndGender=function(){return new Cp(this,this.input)},t.prototype.withFaceDescriptor=function(){return new Ep(this,this.input)},t}(M2),R2=function(n){De(t,n);function t(e,r){r===void 0&&(r=new pu);var o=n.call(this)||this;return o.input=e,o.options=r,o}return t}(vu),L2=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r,o,a;return ke(this,function(i){switch(i.label){case 0:return e=this,r=e.input,o=e.options,o instanceof $2?[4,mn.mtcnn.forward(r,o)]:[3,2];case 1:return[2,i.sent().map(function(s){return s.detection})];case 2:if(a=o instanceof O9?function(s){return mn.tinyFaceDetector.locateFaces(s,o)}:o instanceof pu?function(s){return mn.ssdMobilenetv1.locateFaces(s,o)}:o instanceof lp?function(s){return mn.tinyYolov2.locateFaces(s,o)}:null,!a)throw new Error("detectFaces - expected options to be instance of TinyFaceDetectorOptions | SsdMobilenetv1Options | MtcnnOptions | TinyYolov2Options");return[2,a(r)]}})})},t.prototype.runAndExtendWithFaceDetections=function(){var e=this;return new Promise(function(r){return $e(e,void 0,void 0,function(){var o;return ke(this,function(a){switch(a.label){case 0:return[4,this.run()];case 1:return o=a.sent(),[2,r(o.map(function(i){return Xh({},i)}))]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new J9(this.runAndExtendWithFaceDetections(),this.input,e)},t.prototype.withFaceExpressions=function(){return new vp(this.runAndExtendWithFaceDetections(),this.input)},t.prototype.withAgeAndGender=function(){return new bp(this.runAndExtendWithFaceDetections(),this.input)},t}(R2);(function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r;return ke(this,function(o){switch(o.label){case 0:return[4,new L2(this.input,this.options)];case 1:return e=o.sent(),r=e[0],e.forEach(function(a){a.score>r.score&&(r=a)}),[2,r]}})})},t.prototype.runAndExtendWithFaceDetection=function(){var e=this;return new Promise(function(r){return $e(e,void 0,void 0,function(){var o;return ke(this,function(a){switch(a.label){case 0:return[4,this.run()];case 1:return o=a.sent(),[2,r(o?Xh({},o):void 0)]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new eD(this.runAndExtendWithFaceDetection(),this.input,e)},t.prototype.withFaceExpressions=function(){return new mp(this.runAndExtendWithFaceDetection(),this.input)},t.prototype.withAgeAndGender=function(){return new xp(this.runAndExtendWithFaceDetection(),this.input)},t})(R2);function tD(n,t){return t===void 0&&(t=new pu),new L2(n,t)}function nD(n,t){if(n.length!==t.length)throw new Error("euclideanDistance: arr1.length !== arr2.length");var e=Array.from(n),r=Array.from(t);return Math.sqrt(e.map(function(o,a){return o-r[a]}).reduce(function(o,a){return o+Math.pow(a,2)},0))}(function(){function n(t,e){e===void 0&&(e=.6),this._distanceThreshold=e;var r=Array.isArray(t)?t:[t];if(!r.length)throw new Error("FaceRecognizer.constructor - expected atleast one input");var o=1,a=function(){return"person "+o++};this._labeledDescriptors=r.map(function(i){if(i instanceof _l)return i;if(i instanceof Float32Array)return new _l(a(),[i]);if(i.descriptor&&i.descriptor instanceof Float32Array)return new _l(a(),[i.descriptor]);throw new Error("FaceRecognizer.constructor - expected inputs to be of type LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array | Array<LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array>")})}return Object.defineProperty(n.prototype,"labeledDescriptors",{get:function(){return this._labeledDescriptors},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"distanceThreshold",{get:function(){return this._distanceThreshold},enumerable:!0,configurable:!0}),n.prototype.computeMeanDistance=function(t,e){return e.map(function(r){return nD(r,t)}).reduce(function(r,o){return r+o},0)/(e.length||1)},n.prototype.matchDescriptor=function(t){var e=this;return this.labeledDescriptors.map(function(r){var o=r.descriptors,a=r.label;return new Zb(a,e.computeMeanDistance(t,o))}).reduce(function(r,o){return r.distance<o.distance?r:o})},n.prototype.findBestMatch=function(t){var e=this.matchDescriptor(t);return e.distance<this.distanceThreshold?e:new Zb("unknown",e.distance)},n.prototype.toJSON=function(){return{distanceThreshold:this.distanceThreshold,labeledDescriptors:this.labeledDescriptors.map(function(t){return t.toJSON()})}},n.fromJSON=function(t){var e=t.labeledDescriptors.map(function(r){return _l.fromJSON(r)});return new n(e,t.distanceThreshold)},n})();function po(n){return Array.isArray?Array.isArray(n):V2(n)==="[object Array]"}function rD(n){if(typeof n=="string")return n;let t=n+"";return t=="0"&&1/n==-1/0?"-0":t}function oD(n){return n==null?"":rD(n)}function zr(n){return typeof n=="string"}function B2(n){return typeof n=="number"}function aD(n){return n===!0||n===!1||iD(n)&&V2(n)=="[object Boolean]"}function W2(n){return typeof n=="object"}function iD(n){return W2(n)&&n!==null}function jn(n){return n!=null}function Sp(n){return!n.trim().length}function V2(n){return n==null?n===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(n)}const sD="Incorrect 'index' type",uD=n=>`Invalid value for key ${n}`,cD=n=>`Pattern length exceeds max of ${n}.`,lD=n=>`Missing ${n} property in key`,dD=n=>`Property 'weight' in key '${n}' must be a positive integer`,j2=Object.prototype.hasOwnProperty;class fD{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(r=>{let o=U2(r);this._keys.push(o),this._keyMap[o.id]=o,e+=o.weight}),this._keys.forEach(r=>{r.weight/=e})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function U2(n){let t=null,e=null,r=null,o=1,a=null;if(zr(n)||po(n))r=n,t=z2(n),e=Np(n);else{if(!j2.call(n,"name"))throw new Error(lD("name"));const i=n.name;if(r=i,j2.call(n,"weight")&&(o=n.weight,o<=0))throw new Error(dD(i));t=z2(i),e=Np(i),a=n.getFn}return{path:t,id:e,weight:o,src:r,getFn:a}}function z2(n){return po(n)?n:n.split(".")}function Np(n){return po(n)?n.join("."):n}function hD(n,t){let e=[],r=!1;const o=(a,i,s)=>{if(jn(a))if(!i[s])e.push(a);else{let u=i[s];const c=a[u];if(!jn(c))return;if(s===i.length-1&&(zr(c)||B2(c)||aD(c)))e.push(oD(c));else if(po(c)){r=!0;for(let l=0,d=c.length;l<d;l+=1)o(c[l],i,s+1)}else i.length&&o(c,i,s+1)}};return o(n,zr(t)?t.split("."):t,0),r?e:e[0]}var Ae={...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(n,t)=>n.score===t.score?n.idx<t.idx?-1:1:n.score<t.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,getFn:hD,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}};const pD=/[^ ]+/g;function vD(n=1,t=3){const e=new Map,r=Math.pow(10,t);return{get(o){const a=o.match(pD).length;if(e.has(a))return e.get(a);const i=1/Math.pow(a,.5*n),s=parseFloat(Math.round(i*r)/r);return e.set(a,s),s},clear(){e.clear()}}}class $p{constructor({getFn:t=Ae.getFn,fieldNormWeight:e=Ae.fieldNormWeight}={}){this.norm=vD(e,3),this.getFn=t,this.isCreated=!1,this.setIndexRecords()}setSources(t=[]){this.docs=t}setIndexRecords(t=[]){this.records=t}setKeys(t=[]){this.keys=t,this._keysMap={},t.forEach((e,r)=>{this._keysMap[e.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,zr(this.docs[0])?this.docs.forEach((t,e)=>{this._addString(t,e)}):this.docs.forEach((t,e)=>{this._addObject(t,e)}),this.norm.clear())}add(t){const e=this.size();zr(t)?this._addString(t,e):this._addObject(t,e)}removeAt(t){this.records.splice(t,1);for(let e=t,r=this.size();e<r;e+=1)this.records[e].i-=1}getValueForItemAtKeyId(t,e){return t[this._keysMap[e]]}size(){return this.records.length}_addString(t,e){if(!jn(t)||Sp(t))return;let r={v:t,i:e,n:this.norm.get(t)};this.records.push(r)}_addObject(t,e){let r={i:e,$:{}};this.keys.forEach((o,a)=>{let i=o.getFn?o.getFn(t):this.getFn(t,o.path);if(jn(i)){if(po(i)){let s=[];const u=[{nestedArrIndex:-1,value:i}];for(;u.length;){const{nestedArrIndex:c,value:l}=u.pop();if(jn(l))if(zr(l)&&!Sp(l)){let d={v:l,i:c,n:this.norm.get(l)};s.push(d)}else po(l)&&l.forEach((d,f)=>{u.push({nestedArrIndex:f,value:d})})}r.$[a]=s}else if(zr(i)&&!Sp(i)){let s={v:i,n:this.norm.get(i)};r.$[a]=s}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function H2(n,t,{getFn:e=Ae.getFn,fieldNormWeight:r=Ae.fieldNormWeight}={}){const o=new $p({getFn:e,fieldNormWeight:r});return o.setKeys(n.map(U2)),o.setSources(t),o.create(),o}function mD(n,{getFn:t=Ae.getFn,fieldNormWeight:e=Ae.fieldNormWeight}={}){const{keys:r,records:o}=n,a=new $p({getFn:t,fieldNormWeight:e});return a.setKeys(r),a.setIndexRecords(o),a}function Dl(n,{errors:t=0,currentLocation:e=0,expectedLocation:r=0,distance:o=Ae.distance,ignoreLocation:a=Ae.ignoreLocation}={}){const i=t/n.length;if(a)return i;const s=Math.abs(r-e);return o?i+s/o:s?1:i}function gD(n=[],t=Ae.minMatchCharLength){let e=[],r=-1,o=-1,a=0;for(let i=n.length;a<i;a+=1){let s=n[a];s&&r===-1?r=a:!s&&r!==-1&&(o=a-1,o-r+1>=t&&e.push([r,o]),r=-1)}return n[a-1]&&a-r>=t&&e.push([r,a-1]),e}const Ha=32;function yD(n,t,e,{location:r=Ae.location,distance:o=Ae.distance,threshold:a=Ae.threshold,findAllMatches:i=Ae.findAllMatches,minMatchCharLength:s=Ae.minMatchCharLength,includeMatches:u=Ae.includeMatches,ignoreLocation:c=Ae.ignoreLocation}={}){if(t.length>Ha)throw new Error(cD(Ha));const l=t.length,d=n.length,f=Math.max(0,Math.min(r,d));let h=a,m=f;const v=s>1||u,p=v?Array(d):[];let g;for(;(g=n.indexOf(t,m))>-1;){let E=Dl(t,{currentLocation:g,expectedLocation:f,distance:o,ignoreLocation:c});if(h=Math.min(E,h),m=g+l,v){let $=0;for(;$<l;)p[g+$]=1,$+=1}}m=-1;let b=[],w=1,x=l+d;const C=1<<l-1;for(let E=0;E<l;E+=1){let $=0,S=x;for(;$<S;)Dl(t,{errors:E,currentLocation:f+S,expectedLocation:f,distance:o,ignoreLocation:c})<=h?$=S:x=S,S=Math.floor((x-$)/2+$);x=S;let N=Math.max(1,f-S+1),F=i?d:Math.min(f+S,d)+l,I=Array(F+2);I[F+1]=(1<<E)-1;for(let L=F;L>=N;L-=1){let z=L-1,H=e[n.charAt(z)];if(v&&(p[z]=+!!H),I[L]=(I[L+1]<<1|1)&H,E&&(I[L]|=(b[L+1]|b[L])<<1|1|b[L+1]),I[L]&C&&(w=Dl(t,{errors:E,currentLocation:z,expectedLocation:f,distance:o,ignoreLocation:c}),w<=h)){if(h=w,m=z,m<=f)break;N=Math.max(1,2*f-m)}}if(Dl(t,{errors:E+1,currentLocation:f,expectedLocation:f,distance:o,ignoreLocation:c})>h)break;b=I}const _={isMatch:m>=0,score:Math.max(.001,w)};if(v){const E=gD(p,s);E.length?u&&(_.indices=E):_.isMatch=!1}return _}function bD(n){let t={};for(let e=0,r=n.length;e<r;e+=1){const o=n.charAt(e);t[o]=(t[o]||0)|1<<r-e-1}return t}const Fl=String.prototype.normalize?n=>n.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,""):n=>n;class G2{constructor(t,{location:e=Ae.location,threshold:r=Ae.threshold,distance:o=Ae.distance,includeMatches:a=Ae.includeMatches,findAllMatches:i=Ae.findAllMatches,minMatchCharLength:s=Ae.minMatchCharLength,isCaseSensitive:u=Ae.isCaseSensitive,ignoreDiacritics:c=Ae.ignoreDiacritics,ignoreLocation:l=Ae.ignoreLocation}={}){if(this.options={location:e,threshold:r,distance:o,includeMatches:a,findAllMatches:i,minMatchCharLength:s,isCaseSensitive:u,ignoreDiacritics:c,ignoreLocation:l},t=u?t:t.toLowerCase(),t=c?Fl(t):t,this.pattern=t,this.chunks=[],!this.pattern.length)return;const d=(h,m)=>{this.chunks.push({pattern:h,alphabet:bD(h),startIndex:m})},f=this.pattern.length;if(f>Ha){let h=0;const m=f%Ha,v=f-m;for(;h<v;)d(this.pattern.substr(h,Ha),h),h+=Ha;if(m){const p=f-Ha;d(this.pattern.substr(p),p)}}else d(this.pattern,0)}searchIn(t){const{isCaseSensitive:e,ignoreDiacritics:r,includeMatches:o}=this.options;if(t=e?t:t.toLowerCase(),t=r?Fl(t):t,this.pattern===t){let v={isMatch:!0,score:0};return o&&(v.indices=[[0,t.length-1]]),v}const{location:a,distance:i,threshold:s,findAllMatches:u,minMatchCharLength:c,ignoreLocation:l}=this.options;let d=[],f=0,h=!1;this.chunks.forEach(({pattern:v,alphabet:p,startIndex:g})=>{const{isMatch:b,score:w,indices:x}=yD(t,v,p,{location:a+g,distance:i,threshold:s,findAllMatches:u,minMatchCharLength:c,includeMatches:o,ignoreLocation:l});b&&(h=!0),f+=w,b&&x&&(d=[...d,...x])});let m={isMatch:h,score:h?f/this.chunks.length:1};return h&&o&&(m.indices=d),m}}class Xo{constructor(t){this.pattern=t}static isMultiMatch(t){return q2(t,this.multiRegex)}static isSingleMatch(t){return q2(t,this.singleRegex)}search(){}}function q2(n,t){const e=n.match(t);return e?e[1]:null}class xD extends Xo{constructor(t){super(t)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(t){const e=t===this.pattern;return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}}class wD extends Xo{constructor(t){super(t)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(t){const r=t.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,t.length-1]}}}class CD extends Xo{constructor(t){super(t)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(t){const e=t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}}class _D extends Xo{constructor(t){super(t)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(t){const e=!t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}}class ED extends Xo{constructor(t){super(t)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(t){const e=t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[t.length-this.pattern.length,t.length-1]}}}class SD extends Xo{constructor(t){super(t)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(t){const e=!t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}}class K2 extends Xo{constructor(t,{location:e=Ae.location,threshold:r=Ae.threshold,distance:o=Ae.distance,includeMatches:a=Ae.includeMatches,findAllMatches:i=Ae.findAllMatches,minMatchCharLength:s=Ae.minMatchCharLength,isCaseSensitive:u=Ae.isCaseSensitive,ignoreDiacritics:c=Ae.ignoreDiacritics,ignoreLocation:l=Ae.ignoreLocation}={}){super(t),this._bitapSearch=new G2(t,{location:e,threshold:r,distance:o,includeMatches:a,findAllMatches:i,minMatchCharLength:s,isCaseSensitive:u,ignoreDiacritics:c,ignoreLocation:l})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(t){return this._bitapSearch.searchIn(t)}}class Y2 extends Xo{constructor(t){super(t)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(t){let e=0,r;const o=[],a=this.pattern.length;for(;(r=t.indexOf(this.pattern,e))>-1;)e=r+a,o.push([r,e-1]);const i=!!o.length;return{isMatch:i,score:i?0:1,indices:o}}}const kp=[xD,Y2,CD,_D,SD,ED,wD,K2],X2=kp.length,ND=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,$D="|";function kD(n,t={}){return n.split($D).map(e=>{let r=e.trim().split(ND).filter(a=>a&&!!a.trim()),o=[];for(let a=0,i=r.length;a<i;a+=1){const s=r[a];let u=!1,c=-1;for(;!u&&++c<X2;){const l=kp[c];let d=l.isMultiMatch(s);d&&(o.push(new l(d,t)),u=!0)}if(!u)for(c=-1;++c<X2;){const l=kp[c];let d=l.isSingleMatch(s);if(d){o.push(new l(d,t));break}}}return o})}const PD=new Set([K2.type,Y2.type]);class ID{constructor(t,{isCaseSensitive:e=Ae.isCaseSensitive,ignoreDiacritics:r=Ae.ignoreDiacritics,includeMatches:o=Ae.includeMatches,minMatchCharLength:a=Ae.minMatchCharLength,ignoreLocation:i=Ae.ignoreLocation,findAllMatches:s=Ae.findAllMatches,location:u=Ae.location,threshold:c=Ae.threshold,distance:l=Ae.distance}={}){this.query=null,this.options={isCaseSensitive:e,ignoreDiacritics:r,includeMatches:o,minMatchCharLength:a,findAllMatches:s,ignoreLocation:i,location:u,threshold:c,distance:l},t=e?t:t.toLowerCase(),t=r?Fl(t):t,this.pattern=t,this.query=kD(this.pattern,this.options)}static condition(t,e){return e.useExtendedSearch}searchIn(t){const e=this.query;if(!e)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:o,ignoreDiacritics:a}=this.options;t=o?t:t.toLowerCase(),t=a?Fl(t):t;let i=0,s=[],u=0;for(let c=0,l=e.length;c<l;c+=1){const d=e[c];s.length=0,i=0;for(let f=0,h=d.length;f<h;f+=1){const m=d[f],{isMatch:v,indices:p,score:g}=m.search(t);if(v){if(i+=1,u+=g,r){const b=m.constructor.type;PD.has(b)?s=[...s,...p]:s.push(p)}}else{u=0,i=0,s.length=0;break}}if(i){let f={isMatch:!0,score:u/i};return r&&(f.indices=s),f}}return{isMatch:!1,score:1}}}const Pp=[];function AD(...n){Pp.push(...n)}function Ip(n,t){for(let e=0,r=Pp.length;e<r;e+=1){let o=Pp[e];if(o.condition(n,t))return new o(n,t)}return new G2(n,t)}const Ml={AND:"$and",OR:"$or"},Ap={PATH:"$path",PATTERN:"$val"},Tp=n=>!!(n[Ml.AND]||n[Ml.OR]),TD=n=>!!n[Ap.PATH],OD=n=>!po(n)&&W2(n)&&!Tp(n),Z2=n=>({[Ml.AND]:Object.keys(n).map(t=>({[t]:n[t]}))});function Q2(n,t,{auto:e=!0}={}){const r=o=>{let a=Object.keys(o);const i=TD(o);if(!i&&a.length>1&&!Tp(o))return r(Z2(o));if(OD(o)){const u=i?o[Ap.PATH]:a[0],c=i?o[Ap.PATTERN]:o[u];if(!zr(c))throw new Error(uD(u));const l={keyId:Np(u),pattern:c};return e&&(l.searcher=Ip(c,t)),l}let s={children:[],operator:a[0]};return a.forEach(u=>{const c=o[u];po(c)&&c.forEach(l=>{s.children.push(r(l))})}),s};return Tp(n)||(n=Z2(n)),r(n)}function DD(n,{ignoreFieldNorm:t=Ae.ignoreFieldNorm}){n.forEach(e=>{let r=1;e.matches.forEach(({key:o,norm:a,score:i})=>{const s=o?o.weight:null;r*=Math.pow(i===0&&s?Number.EPSILON:i,(s||1)*(t?1:a))}),e.score=r})}function FD(n,t){const e=n.matches;t.matches=[],jn(e)&&e.forEach(r=>{if(!jn(r.indices)||!r.indices.length)return;const{indices:o,value:a}=r;let i={indices:o,value:a};r.key&&(i.key=r.key.src),r.idx>-1&&(i.refIndex=r.idx),t.matches.push(i)})}function MD(n,t){t.score=n.score}function RD(n,t,{includeMatches:e=Ae.includeMatches,includeScore:r=Ae.includeScore}={}){const o=[];return e&&o.push(FD),r&&o.push(MD),n.map(a=>{const{idx:i}=a,s={item:t[i],refIndex:i};return o.length&&o.forEach(u=>{u(a,s)}),s})}class zi{constructor(t,e={},r){this.options={...Ae,...e},this.options.useExtendedSearch,this._keyStore=new fD(this.options.keys),this.setCollection(t,r)}setCollection(t,e){if(this._docs=t,e&&!(e instanceof $p))throw new Error(sD);this._myIndex=e||H2(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(t){jn(t)&&(this._docs.push(t),this._myIndex.add(t))}remove(t=()=>!1){const e=[];for(let r=0,o=this._docs.length;r<o;r+=1){const a=this._docs[r];t(a,r)&&(this.removeAt(r),r-=1,o-=1,e.push(a))}return e}removeAt(t){this._docs.splice(t,1),this._myIndex.removeAt(t)}getIndex(){return this._myIndex}search(t,{limit:e=-1}={}){const{includeMatches:r,includeScore:o,shouldSort:a,sortFn:i,ignoreFieldNorm:s}=this.options;let u=zr(t)?zr(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t);return DD(u,{ignoreFieldNorm:s}),a&&u.sort(i),B2(e)&&e>-1&&(u=u.slice(0,e)),RD(u,this._docs,{includeMatches:r,includeScore:o})}_searchStringList(t){const e=Ip(t,this.options),{records:r}=this._myIndex,o=[];return r.forEach(({v:a,i,n:s})=>{if(!jn(a))return;const{isMatch:u,score:c,indices:l}=e.searchIn(a);u&&o.push({item:a,idx:i,matches:[{score:c,value:a,norm:s,indices:l}]})}),o}_searchLogical(t){const e=Q2(t,this.options),r=(s,u,c)=>{if(!s.children){const{keyId:d,searcher:f}=s,h=this._findMatches({key:this._keyStore.get(d),value:this._myIndex.getValueForItemAtKeyId(u,d),searcher:f});return h&&h.length?[{idx:c,item:u,matches:h}]:[]}const l=[];for(let d=0,f=s.children.length;d<f;d+=1){const h=s.children[d],m=r(h,u,c);if(m.length)l.push(...m);else if(s.operator===Ml.AND)return[]}return l},o=this._myIndex.records,a={},i=[];return o.forEach(({$:s,i:u})=>{if(jn(s)){let c=r(e,s,u);c.length&&(a[u]||(a[u]={idx:u,item:s,matches:[]},i.push(a[u])),c.forEach(({matches:l})=>{a[u].matches.push(...l)}))}}),i}_searchObjectList(t){const e=Ip(t,this.options),{keys:r,records:o}=this._myIndex,a=[];return o.forEach(({$:i,i:s})=>{if(!jn(i))return;let u=[];r.forEach((c,l)=>{u.push(...this._findMatches({key:c,value:i[l],searcher:e}))}),u.length&&a.push({idx:s,item:i,matches:u})}),a}_findMatches({key:t,value:e,searcher:r}){if(!jn(e))return[];let o=[];if(po(e))e.forEach(({v:a,i,n:s})=>{if(!jn(a))return;const{isMatch:u,score:c,indices:l}=r.searchIn(a);u&&o.push({score:c,key:t,value:a,idx:i,norm:s,indices:l})});else{const{v:a,n:i}=e,{isMatch:s,score:u,indices:c}=r.searchIn(a);s&&o.push({score:u,key:t,value:a,norm:i,indices:c})}return o}}zi.version="7.1.0",zi.createIndex=H2,zi.parseIndex=mD,zi.config=Ae,zi.parseQuery=Q2,AD(ID);const LD=D.createContext(void 0);let Op;const BD=({apiEndpoint:n,children:t})=>(D.useEffect(()=>{Op=n},[n]),y.jsx(LD.Provider,{value:{apiEndpoint:n},children:t})),WD=()=>{if(!Op)throw new Error("ApiEndpoint not initialized. Make sure ApiProvider is mounted.");return Op};typeof window>"u"&&(async()=>{const{Canvas:n,Image:t,ImageData:e,loadImage:r}=await Promise.resolve().then(()=>yz);global.Image=t,global.HTMLImageElement=t,global.ImageData=e,global.HTMLCanvasElement=n,global.CanvasRenderingContext2D=n,global.loadImage=r,on.monkeyPatch({Canvas:n,Image:t,ImageData:e,createCanvasElement:()=>new n(1,1),createImageElement:()=>new t})})();class VD{constructor(){Dm(this,"signalMap");Dm(this,"modelsLoaded",!1);this.signalMap={id:["date of birth","birth date","place of birth","id","identification","identity card","permit","valid until","expiration date","given name","surname","sex","gender","height","weight","address","issuing authority","issued by","card number","personal number","nationality"],passport:["passport","passport number","country code","issuing country","issuing state","place of issue","place of birth","date of issue","date of expiry","expiry date","valid until","authority","surname","given name","name","sex","nationality","type","holder","mrz","document","travel","abroad","citizen"],license:["license","driver","driver license","dl number","licence number","permit","valid until","date of birth","birth date","issue date","expiration date","holder's signature","authority","class","restrictions","endorsements","sex","eyes","hair","height","weight","organ donor","address"],voterId:["voter","voting","voter id","voter card","elector","elector's name","father's name","electoral roll","polling station","constituency","elector id","serial number","sex","age","dob","date of birth","part number","section","epic","identity card","address"],default:["name","id","date","dob","expiry","number","document","issued"]}}async toBase64(t){if(typeof window>"u")return(await(await Promise.resolve().then(()=>bz)).readFile(t)).toString("base64");if(t instanceof File)return new Promise((e,r)=>{const o=new FileReader;o.onload=()=>{const i=o.result.split(",")[1];e(i)},o.onerror=r,o.readAsDataURL(t)});throw new Error("Unsupported input type for base64 conversion")}async validateIdCard(t,e){let r=t;if(typeof t!="string"){const s=await this.toBase64(t);r=`data:${t.type||"image/jpeg"};base64,${s}`}const{data:{text:o}}=await Dk.recognize(r,"eng"),a=this.signalMap[e]||this.signalMap.default;console.log("OCR Result:",{text:o});let i=a.some(s=>{const u=o.toLowerCase().includes(s);return u&&console.log(`Found ${e} match:`,s),u});if(!i){const u=new zi(a,{includeScore:!0,threshold:.6}).search(o.toLowerCase());i=u.length>0,i&&console.log("Found fuzzy match:",u[0].item,u[0].score,{found:u})}return{type:e,passed:i,textSnippet:o.slice(0,200),fullText:o}}async loadModels(){if(this.modelsLoaded)return;const e=`${WD()}/api/models`;await Promise.all([mn.ssdMobilenetv1.loadFromUri(e),mn.faceLandmark68Net.loadFromUri(e),mn.faceRecognitionNet.loadFromUri(e)]),this.modelsLoaded=!0}async validateFace(t){await this.loadModels();let e=t;if(typeof t!="string"){const i=await this.toBase64(t);e=`data:${t.type||"image/jpeg"};base64,${i}`}const r=await this.fileToImage(e),o=await tD(r,new pu);return{type:"face",passed:o.length===1,facesDetected:o.length}}async fileToImage(t){return new Promise((e,r)=>{const o=new Image;if(o.onload=()=>e(o),o.onerror=r,typeof t=="string")o.src=t;else{const a=new FileReader;a.onload=()=>{o.src=a.result},a.onerror=r,a.readAsDataURL(t)}})}}const J2=new VD,jD=(n,t,e,r,o,a,i)=>{const[s,u]=D.useState(null),[c,l]=D.useState(null),[d,f]=D.useState({x:0,y:0,w:320,h:192}),h=D.useRef(`frameMask-${Math.random().toString(36).slice(2)}`),{toast:m}=oc(),v=D.useMemo(()=>c?URL.createObjectURL(c):null,[c]),p=xi.find(x=>x.id===i);D.useEffect(()=>{e.current&&s&&(e.current.srcObject=s)},[s]),D.useEffect(()=>()=>{v&&URL.revokeObjectURL(v)},[v]);const g=D.useCallback(async()=>{try{const x=await navigator.mediaDevices.getUserMedia({video:{facingMode:n==="selfie"?"user":"environment",width:{ideal:9999},height:{ideal:9999}}});u(x)}catch{try{const x=await navigator.mediaDevices.getUserMedia({video:{facingMode:n==="selfie"?"user":"environment",width:{ideal:1280},height:{ideal:720}}});u(x)}catch{m({title:"Camera Error",description:"Unable to access camera. Please check permissions.",variant:"destructive"})}}},[n,m]),b=D.useCallback(()=>{s&&(s.getTracks().forEach(x=>x.stop()),u(null))},[s]),w=D.useCallback(async()=>{if(!e.current||!r.current||!o.current)return;const x=e.current,C=r.current,_=C.getContext("2d");if(!_)return;const E=x.videoWidth,$=x.videoHeight;if(n==="selfie"){C.width=E,C.height=$,_.drawImage(x,0,0,E,$),C.toBlob(async B=>{if(!B)return;const K=new File([B],`${n}-${Date.now()}.jpg`,{type:"image/jpeg"});try{const q=document.createElement("canvas"),Z=q.getContext("2d");if(!Z)return;const oe=x.getBoundingClientRect(),ae=E/oe.width,X=$/oe.height,re=10,ce=(d.x-re)*ae,ue=(d.y-re)*X,se=(d.w+2*re)*ae,ee=(d.h+2*re)*X;q.width=se,q.height=ee,Z.drawImage(x,ce,ue,se,ee,0,0,se,ee);const _e=await new Promise(Ze=>q.toBlob(Ze,"image/jpeg",.8));if(!_e)return;const Fe=new File([_e],`crop-${Date.now()}.jpg`,{type:"image/jpeg"});if(m({title:"Validating...",description:"Checking if the photo has a face..."}),!(await J2.validateFace(Fe)).passed){m({title:"Validation Failed",description:"No face detected. Please retake your selfie.",variant:"destructive"});return}m({title:"Photo Captured",description:"Selfie captured successfully"}),l(K),b()}catch(q){console.error("Face validation error:",q),m({title:"Validation Error",description:"We couldn’t process the selfie. Please try again.",variant:"destructive"})}},"image/jpeg",.8);return}const S=x.getBoundingClientRect(),N=E/S.width,F=$/S.height,I=10,j=(d.x-I)*N,L=(d.y-I)*F,z=(d.w+2*I)*N,H=(d.h+2*I)*F,M=Math.max(0,Math.min(j,E-z)),T=Math.max(0,Math.min(L,$-H)),A=Math.min(z,E-M),P=Math.min(H,$-T);if(C.width=t==="circular"?Math.max(A,P):A,C.height=t==="circular"?Math.max(A,P):P,t==="circular"){const B=Math.min(A,P)/2;_.beginPath(),_.arc(C.width/2,C.height/2,B+I*N,0,Math.PI*2),_.clip(),_.drawImage(x,M-(C.width-A)/2,T-(C.height-P)/2,C.width,C.height,0,0,C.width,C.height)}else _.drawImage(x,M,T,A,P,0,0,C.width,C.height);C.toBlob(async B=>{if(!B)return;const K=new File([B],`${n}-${Date.now()}.jpg`,{type:"image/jpeg"});try{if(m({title:"Validating...",description:`Checking if the photo looks like ${p.title} ...`}),!(await J2.validateIdCard(K,i)).passed){m({title:"Validation Failed",description:`This doesn’t look like ${p.title} card. Try again.`,variant:"destructive"});return}l(K),b(),m({title:"Photo Captured",description:`${p.title} validated successfully`})}catch(q){console.error(q),m({title:"OCR Error",description:"We couldn’t process the photo. Please try again.",variant:"destructive"})}},"image/jpeg",.8)},[n,b,m,t,d,e,r,o]);return D.useEffect(()=>(!c&&!s&&g(),()=>{b()}),[c,s,g,b]),D.useEffect(()=>{if(!o.current||!a.current)return;const x=()=>{const _=o.current.getBoundingClientRect(),E=a.current.getBoundingClientRect();f({x:Math.round(E.left-_.left),y:Math.round(E.top-_.top),w:Math.round(E.width),h:Math.round(E.height)})};x();const C=new ResizeObserver(x);return C.observe(a.current),C.observe(o.current),window.addEventListener("resize",x),window.addEventListener("scroll",x,!0),()=>{C.disconnect(),window.removeEventListener("resize",x),window.removeEventListener("scroll",x,!0)}},[t,s,o,a]),{stream:s,photo:c,setPhoto:l,hole:d,maskId:h.current,photoUrl:v,capturePhoto:w}},Dp=768;function UD(){const[n,t]=k.useState(void 0);return k.useEffect(()=>{const e=window.matchMedia(`(max-width: ${Dp-1}px)`),r=()=>{t(window.innerWidth<Dp)};return e.addEventListener("change",r),t(window.innerWidth<Dp),()=>e.removeEventListener("change",r)},[]),!!n}const zD={"id-front":"ID Front","id-back":"ID Back",selfie:"Selfie"},Hi=({currentStep:n,onRetake:t,onConfirm:e,onBack:r,title:o,description:a,frameType:i,documentTypeId:s})=>{const u=D.useRef(null),c=D.useRef(null),l=D.useRef(null),d=D.useRef(null),f=UD(),{stream:h,photo:m,setPhoto:v,hole:p,maskId:g,photoUrl:b,capturePhoto:w}=jD(n,i,u,c,l,d,s),x=!!h,C=()=>{v(null),r()},_=()=>{v(null),t()},E=()=>{m&&e(m),m&&e(m),v(null)},$=p.x+p.w/2,S=p.y+p.h/2,N=Math.max(p.w,p.h)/2,F=()=>{const I=zD[n]||"Photo";return y.jsx(un,{className:"w-full max-w-md mx-auto",children:y.jsxs(cn,{className:"p-6",children:[y.jsx(ro,{title:`Review ${I}`,subTitle:"Make sure the information is seen clearly, with no blur or glare.",onBack:C}),y.jsx("div",{className:"mb-8",children:y.jsx("div",{className:"relative",children:b&&y.jsx("img",{src:b,alt:"Captured photo",className:`w-full h-64 object-cover ${n==="selfie"?"":i==="circular"?"rounded-full":"rounded-2xl"} bg-muted`})})}),y.jsxs("div",{className:"flex gap-4",children:[y.jsx(_t,{variant:"outline",onClick:_,className:"flex-1 text-md",children:"Take again"}),y.jsx(_t,{onClick:E,className:"flex-1 text-md",children:"Looks good"})]})]})})};return m?F():y.jsxs(un,{className:"relative w-full max-w-md mx-auto bg-gray-900 border-gray-900 overflow-hidden",children:[x&&y.jsx("video",{ref:u,autoPlay:!0,playsInline:!0,muted:!0,loop:!0,className:`absolute inset-0 w-full h-full object-cover z-0 ${!f&&"scale-x-[-1]"}`}),y.jsx("div",{ref:l,className:"absolute inset-0 z-5 pointer-events-none","aria-hidden":!0,children:y.jsxs("svg",{className:"w-full h-full",children:[y.jsx("defs",{children:y.jsxs("mask",{id:g,children:[y.jsx("rect",{width:"100%",height:"100%",fill:"white"}),i==="circular"?y.jsx("circle",{cx:$,cy:S,r:N,fill:"black"}):y.jsx("rect",{x:p.x,y:p.y,width:p.w,height:p.h,fill:"black"})]})}),y.jsx("rect",{width:"100%",height:"100%",fill:"rgba(17,24,39,0.7)",mask:`url(#${g})`})]})}),y.jsx("canvas",{ref:c,className:"hidden"}),y.jsxs(cn,{className:"relative z-10 text-white flex flex-col h-full",children:[y.jsxs("div",{className:"flex items-center p-6",children:[y.jsx(_t,{variant:"ghost",size:"sm",onClick:C,className:"text-white hover:bg-gray-600",children:y.jsx(kg,{className:"h-6 w-6"})}),y.jsx("h1",{className:"text-xl font-semibold ml-4",children:o})]}),y.jsx("div",{className:"px-6 mb-8",children:y.jsx("p",{className:"text-gray-300 text-center",children:a})}),y.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center px-6",children:[y.jsx("div",{className:"relative mb-16",children:x?y.jsxs("div",{ref:d,className:`relative z-20 ${i==="circular"?"w-80 h-80 rounded-full":s==="passport"?"w-80 h-[350px]":"w-80 h-48"}`,children:[y.jsx("div",{className:`absolute inset-0 opacity-0 ${i==="circular"?"rounded-full":""} z-10`}),i==="circular"?null:y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"absolute w-6 h-6 border-t-4 border-l-4 border-white z-30",style:{top:"-4px",left:"-4px"}}),y.jsx("div",{className:"absolute w-6 h-6 border-t-4 border-r-4 border-white z-30",style:{top:"-4px",right:"-4px"}}),y.jsx("div",{className:"absolute w-6 h-6 border-b-4 border-l-4 border-white z-30",style:{bottom:"-4px",left:"-4px"}}),y.jsx("div",{className:"absolute w-6 h-6 border-b-4 border-r-4 border-white z-30",style:{bottom:"-4px",right:"-4px"}})]})]}):y.jsx("div",{className:`bg-gray-700 flex items-center justify-center ${i==="circular"?"w-80 h-80 rounded-full":s==="passport"?"w-80 h-[350px]":"w-80 h-48"}`,children:y.jsx("p",{className:"text-gray-400",children:"Camera loading..."})})}),y.jsx(_t,{onClick:w,size:"lg",className:"w-16 h-16 rounded-full bg-white hover:bg-gray-100 border-4 border-gray-600 p-0",disabled:!x,children:y.jsx("div",{className:"w-8 h-8 rounded-full bg-white"})})]})]})]})},HD=({apiEndpoint:n,apiKey:t,onComplete:e,onDoneClick:r,userEmail:o})=>{const[a,i]=D.useState("landing"),[s,u]=D.useState(""),[c,l]=D.useState(""),[d,f]=D.useState(null),[h,m]=D.useState(null),[v,p]=D.useState(null),{data:g}=KD(n,t),b=oy({mutationFn:GD}),{toast:w}=oc(),x=D.useMemo(()=>[...g!=null&&g.hide_name_step?[]:["name"],...g!=null&&g.hide_document_selection_step?[]:["document-selection"],"selfie","pre-selfie","id-front","id-back","verify"],[g]),C=()=>g.hide_name_step?g.hide_document_selection_step?"id-front":"document-selection":"name",_=async()=>{if((g.hide_name_step||!!s)&&d&&h&&v){const N={full_name:s,email:o,selfie_photo:d,id_photo:h,id_photo_back:v},F=await b.mutateAsync({apiEndpoint:n,apiKey:t,data:N});e(F.data.token,N),w({title:"KYC Complete",description:"Identity verification completed successfully"}),u(""),f(null),m(null),p(null),i("done")}},E=()=>y.jsx(y.Fragment,{children:a!=="landing"&&y.jsx("div",{className:"flex justify-center",children:y.jsx("div",{className:"flex space-x-2",children:x.map((S,N)=>y.jsx("div",{className:`w-3 h-3 rounded-full ${x.indexOf(a)>=N?"bg-primary":"bg-muted"}`},S))})})}),$=()=>{switch(console.log("currentStep",a),a){case"landing":return y.jsx(ay,{onContinue:()=>i(C())});case"name":return y.jsx(Y$,{fullName:s,onNameChange:u,onContinue:()=>i(g.hide_document_selection_step?"id-front":"document-selection"),renderProgress:E});case"document-selection":return y.jsx(uy,{selectedDocumentType:c,onDocumentTypeChange:l,onContinue:()=>i("id-front"),onBack:()=>i(g.hide_name_step?"landing":"name"),renderProgress:E});case"id-front":return y.jsx(Hi,{title:"Upload ID",description:"Place your ID inside the frame and take a picture. Make sure it is not cut or has any glare.",frameType:"rectangular",documentTypeId:c,currentStep:a,onRetake:()=>{m(null)},onConfirm:S=>{m(S),i(c==="passport"?"pre-selfie":"id-back")},onBack:()=>{m(null),i(g.hide_document_selection_step?g.hide_name_step?"landing":"name":"document-selection")}});case"id-back":return y.jsx(Hi,{title:"Upload ID Back",description:"Place the back of your ID inside the frame and take a picture. Make sure it is not cut or has any glare.",frameType:"rectangular",documentTypeId:c,currentStep:a,onRetake:()=>{p(null)},onConfirm:S=>{p(S),i("pre-selfie")},onBack:()=>{p(null),i("id-front")}});case"pre-selfie":return y.jsx(cy,{onContinue:()=>i("selfie"),onBack:()=>i("id-back")});case"selfie":return y.jsx(Hi,{title:"Selfie",description:"Place your face inside the frame and take a picture. Make sure it is clearly visible.",frameType:"circular",documentTypeId:c,currentStep:a,onRetake:()=>{f(null)},onConfirm:S=>{f(S),i("verify")},onBack:()=>{f(null),i("id-back")}});case"verify":return y.jsx(X$,{fullName:s,onComplete:()=>i("processing"),onStartOver:()=>i("landing")});case"processing":return y.jsx(ly,{onComplete:_});case"done":return y.jsx(dy,{onDoneClick:r});default:return null}};return y.jsx("div",{className:"w-[430px]",children:$()})};async function GD({apiEndpoint:n,apiKey:t,data:e}){const r=new FormData;r.append("full_name",e.full_name),r.append("email",e.email),r.append("selfie_photo",e.selfie_photo,e.selfie_photo.name),r.append("id_photo",e.id_photo,e.id_photo.name),r.append("id_photo_back",e.id_photo_back,e.id_photo_back.name);const o=await fetch(`${n}/api/kyc`,{method:"POST",headers:{"X-API-Key":t},body:r});if(!o.ok)throw new Error("Network response was not ok");return o.json()}const qD=async(n,t)=>{const e=await fetch(`${n}/api/settings`,{method:"GET",headers:{"X-API-Key":t,"Content-Type":"application/json"}});if(!e.ok)throw new Error("Network response was not ok");return(await e.json()).data},KD=(n,t)=>z$({queryKey:["settings",n,t],queryFn:()=>qD(n,t),enabled:!!n&&!!t});var mu=n=>n.type==="checkbox",Ga=n=>n instanceof Date,gn=n=>n==null;const ex=n=>typeof n=="object";var Ft=n=>!gn(n)&&!Array.isArray(n)&&ex(n)&&!Ga(n),tx=n=>Ft(n)&&n.target?mu(n.target)?n.target.checked:n.target.value:n,YD=n=>n.substring(0,n.search(/\.\d+(\.|$)/))||n,nx=(n,t)=>n.has(YD(t)),XD=n=>{const t=n.constructor&&n.constructor.prototype;return Ft(t)&&t.hasOwnProperty("isPrototypeOf")},Fp=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function qt(n){let t;const e=Array.isArray(n),r=typeof FileList<"u"?n instanceof FileList:!1;if(n instanceof Date)t=new Date(n);else if(!(Fp&&(n instanceof Blob||r))&&(e||Ft(n)))if(t=e?[]:Object.create(Object.getPrototypeOf(n)),!e&&!XD(n))t=n;else for(const o in n)n.hasOwnProperty(o)&&(t[o]=qt(n[o]));else return n;return t}var Rl=n=>/^\w*$/.test(n),Ot=n=>n===void 0,Mp=n=>Array.isArray(n)?n.filter(Boolean):[],Rp=n=>Mp(n.replace(/["|']|\]/g,"").split(/\.|\[/)),me=(n,t,e)=>{if(!t||!Ft(n))return e;const r=(Rl(t)?[t]:Rp(t)).reduce((o,a)=>gn(o)?o:o[a],n);return Ot(r)||r===n?Ot(n[t])?e:n[t]:r},Un=n=>typeof n=="boolean",pt=(n,t,e)=>{let r=-1;const o=Rl(t)?[t]:Rp(t),a=o.length,i=a-1;for(;++r<a;){const s=o[r];let u=e;if(r!==i){const c=n[s];u=Ft(c)||Array.isArray(c)?c:isNaN(+o[r+1])?{}:[]}if(s==="__proto__"||s==="constructor"||s==="prototype")return;n[s]=u,n=n[s]}};const Ll={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},lr={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},vo={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},Lp=D.createContext(null);Lp.displayName="HookFormContext";const Bl=()=>D.useContext(Lp),ZD=n=>{const{children:t,...e}=n;return D.createElement(Lp.Provider,{value:e},t)};var rx=(n,t,e,r=!0)=>{const o={defaultValues:t._defaultValues};for(const a in n)Object.defineProperty(o,a,{get:()=>{const i=a;return t._proxyFormState[i]!==lr.all&&(t._proxyFormState[i]=!r||lr.all),e&&(e[i]=!0),n[i]}});return o};const Bp=typeof window<"u"?D.useLayoutEffect:D.useEffect;function QD(n){const t=Bl(),{control:e=t.control,disabled:r,name:o,exact:a}=n||{},[i,s]=D.useState(e._formState),u=D.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1});return Bp(()=>e._subscribe({name:o,formState:u.current,exact:a,callback:c=>{!r&&s({...e._formState,...c})}}),[o,r,a]),D.useEffect(()=>{u.current.isValid&&e._setValid(!0)},[e]),D.useMemo(()=>rx(i,e,u.current,!1),[i,e])}var zn=n=>typeof n=="string",ox=(n,t,e,r,o)=>zn(n)?(r&&t.watch.add(n),me(e,n,o)):Array.isArray(n)?n.map(a=>(r&&t.watch.add(a),me(e,a))):(r&&(t.watchAll=!0),e),Wp=n=>gn(n)||!ex(n);function mo(n,t,e=new WeakSet){if(Wp(n)||Wp(t))return n===t;if(Ga(n)&&Ga(t))return n.getTime()===t.getTime();const r=Object.keys(n),o=Object.keys(t);if(r.length!==o.length)return!1;if(e.has(n)||e.has(t))return!0;e.add(n),e.add(t);for(const a of r){const i=n[a];if(!o.includes(a))return!1;if(a!=="ref"){const s=t[a];if(Ga(i)&&Ga(s)||Ft(i)&&Ft(s)||Array.isArray(i)&&Array.isArray(s)?!mo(i,s,e):i!==s)return!1}}return!0}function JD(n){const t=Bl(),{control:e=t.control,name:r,defaultValue:o,disabled:a,exact:i,compute:s}=n||{},u=D.useRef(o),c=D.useRef(s),l=D.useRef(void 0);c.current=s;const d=D.useMemo(()=>e._getWatch(r,u.current),[e,r]),[f,h]=D.useState(c.current?c.current(d):d);return Bp(()=>e._subscribe({name:r,formState:{values:!0},exact:i,callback:m=>{if(!a){const v=ox(r,e._names,m.values||e._formValues,!1,u.current);if(c.current){const p=c.current(v);mo(p,l.current)||(h(p),l.current=p)}else h(v)}}}),[e,a,r,i]),D.useEffect(()=>e._removeUnmounted()),f}function ax(n){const t=Bl(),{name:e,disabled:r,control:o=t.control,shouldUnregister:a,defaultValue:i}=n,s=nx(o._names.array,e),u=D.useMemo(()=>me(o._formValues,e,me(o._defaultValues,e,i)),[o,e,i]),c=JD({control:o,name:e,defaultValue:u,exact:!0}),l=QD({control:o,name:e,exact:!0}),d=D.useRef(n),f=D.useRef(void 0),h=D.useRef(o.register(e,{...n.rules,value:c,...Un(n.disabled)?{disabled:n.disabled}:{}}));d.current=n;const m=D.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!me(l.errors,e)},isDirty:{enumerable:!0,get:()=>!!me(l.dirtyFields,e)},isTouched:{enumerable:!0,get:()=>!!me(l.touchedFields,e)},isValidating:{enumerable:!0,get:()=>!!me(l.validatingFields,e)},error:{enumerable:!0,get:()=>me(l.errors,e)}}),[l,e]),v=D.useCallback(w=>h.current.onChange({target:{value:tx(w),name:e},type:Ll.CHANGE}),[e]),p=D.useCallback(()=>h.current.onBlur({target:{value:me(o._formValues,e),name:e},type:Ll.BLUR}),[e,o._formValues]),g=D.useCallback(w=>{const x=me(o._fields,e);x&&w&&(x._f.ref={focus:()=>w.focus&&w.focus(),select:()=>w.select&&w.select(),setCustomValidity:C=>w.setCustomValidity(C),reportValidity:()=>w.reportValidity()})},[o._fields,e]),b=D.useMemo(()=>({name:e,value:c,...Un(r)||l.disabled?{disabled:l.disabled||r}:{},onChange:v,onBlur:p,ref:g}),[e,r,l.disabled,v,p,g,c]);return D.useEffect(()=>{const w=o._options.shouldUnregister||a,x=f.current;x&&x!==e&&!s&&o.unregister(x),o.register(e,{...d.current.rules,...Un(d.current.disabled)?{disabled:d.current.disabled}:{}});const C=(_,E)=>{const $=me(o._fields,_);$&&$._f&&($._f.mount=E)};if(C(e,!0),w){const _=qt(me(o._options.defaultValues,e));pt(o._defaultValues,e,_),Ot(me(o._formValues,e))&&pt(o._formValues,e,_)}return!s&&o.register(e),f.current=e,()=>{(s?w&&!o._state.action:w)?o.unregister(e):C(e,!1)}},[e,o,s,a]),D.useEffect(()=>{o._setDisabledField({disabled:r,name:e})},[r,e,o]),D.useMemo(()=>({field:b,formState:l,fieldState:m}),[b,l,m])}const e8=n=>n.render(ax(n));var ix=(n,t,e,r,o)=>t?{...e[n],types:{...e[n]&&e[n].types?e[n].types:{},[r]:o||!0}}:{},gu=n=>Array.isArray(n)?n:[n],sx=()=>{let n=[];return{get observers(){return n},next:o=>{for(const a of n)a.next&&a.next(o)},subscribe:o=>(n.push(o),{unsubscribe:()=>{n=n.filter(a=>a!==o)}}),unsubscribe:()=>{n=[]}}};function ux(n,t){const e={};for(const r in n)if(n.hasOwnProperty(r)){const o=n[r],a=t[r];if(o&&Ft(o)&&a){const i=ux(o,a);Ft(i)&&(e[r]=i)}else n[r]&&(e[r]=a)}return e}var kn=n=>Ft(n)&&!Object.keys(n).length,Vp=n=>n.type==="file",dr=n=>typeof n=="function",Wl=n=>{if(!Fp)return!1;const t=n?n.ownerDocument:0;return n instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},cx=n=>n.type==="select-multiple",jp=n=>n.type==="radio",t8=n=>jp(n)||mu(n),Up=n=>Wl(n)&&n.isConnected;function n8(n,t){const e=t.slice(0,-1).length;let r=0;for(;r<e;)n=Ot(n)?r++:n[t[r++]];return n}function r8(n){for(const t in n)if(n.hasOwnProperty(t)&&!Ot(n[t]))return!1;return!0}function Mt(n,t){const e=Array.isArray(t)?t:Rl(t)?[t]:Rp(t),r=e.length===1?n:n8(n,e),o=e.length-1,a=e[o];return r&&delete r[a],o!==0&&(Ft(r)&&kn(r)||Array.isArray(r)&&r8(r))&&Mt(n,e.slice(0,-1)),n}var o8=n=>{for(const t in n)if(dr(n[t]))return!0;return!1};function lx(n){return Array.isArray(n)||Ft(n)&&!o8(n)}function zp(n,t={}){for(const e in n)lx(n[e])?(t[e]=Array.isArray(n[e])?[]:{},zp(n[e],t[e])):gn(n[e])||(t[e]=!0);return t}function Gi(n,t,e){e||(e=zp(t));for(const r in n)lx(n[r])?Ot(t)||Wp(e[r])?e[r]=zp(n[r],Array.isArray(n[r])?[]:{}):Gi(n[r],gn(t)?{}:t[r],e[r]):e[r]=!mo(n[r],t[r]);return e}const dx={value:!1,isValid:!1},fx={value:!0,isValid:!0};var hx=n=>{if(Array.isArray(n)){if(n.length>1){const t=n.filter(e=>e&&e.checked&&!e.disabled).map(e=>e.value);return{value:t,isValid:!!t.length}}return n[0].checked&&!n[0].disabled?n[0].attributes&&!Ot(n[0].attributes.value)?Ot(n[0].value)||n[0].value===""?fx:{value:n[0].value,isValid:!0}:fx:dx}return dx},px=(n,{valueAsNumber:t,valueAsDate:e,setValueAs:r})=>Ot(n)?n:t?n===""?NaN:n&&+n:e&&zn(n)?new Date(n):r?r(n):n;const vx={isValid:!1,value:null};var mx=n=>Array.isArray(n)?n.reduce((t,e)=>e&&e.checked&&!e.disabled?{isValid:!0,value:e.value}:t,vx):vx;function gx(n){const t=n.ref;return Vp(t)?t.files:jp(t)?mx(n.refs).value:cx(t)?[...t.selectedOptions].map(({value:e})=>e):mu(t)?hx(n.refs).value:px(Ot(t.value)?n.ref.value:t.value,n)}var a8=(n,t,e,r)=>{const o={};for(const a of n){const i=me(t,a);i&&pt(o,a,i._f)}return{criteriaMode:e,names:[...n],fields:o,shouldUseNativeValidation:r}},Vl=n=>n instanceof RegExp,yu=n=>Ot(n)?n:Vl(n)?n.source:Ft(n)?Vl(n.value)?n.value.source:n.value:n,yx=n=>({isOnSubmit:!n||n===lr.onSubmit,isOnBlur:n===lr.onBlur,isOnChange:n===lr.onChange,isOnAll:n===lr.all,isOnTouch:n===lr.onTouched});const bx="AsyncFunction";var i8=n=>!!n&&!!n.validate&&!!(dr(n.validate)&&n.validate.constructor.name===bx||Ft(n.validate)&&Object.values(n.validate).find(t=>t.constructor.name===bx)),s8=n=>n.mount&&(n.required||n.min||n.max||n.maxLength||n.minLength||n.pattern||n.validate),xx=(n,t,e)=>!e&&(t.watchAll||t.watch.has(n)||[...t.watch].some(r=>n.startsWith(r)&&/^\.\w+/.test(n.slice(r.length))));const bu=(n,t,e,r)=>{for(const o of e||Object.keys(n)){const a=me(n,o);if(a){const{_f:i,...s}=a;if(i){if(i.refs&&i.refs[0]&&t(i.refs[0],o)&&!r)return!0;if(i.ref&&t(i.ref,i.name)&&!r)return!0;if(bu(s,t))break}else if(Ft(s)&&bu(s,t))break}}};function wx(n,t,e){const r=me(n,e);if(r||Rl(e))return{error:r,name:e};const o=e.split(".");for(;o.length;){const a=o.join("."),i=me(t,a),s=me(n,a);if(i&&!Array.isArray(i)&&e!==a)return{name:e};if(s&&s.type)return{name:a,error:s};if(s&&s.root&&s.root.type)return{name:`${a}.root`,error:s.root};o.pop()}return{name:e}}var u8=(n,t,e,r)=>{e(n);const{name:o,...a}=n;return kn(a)||Object.keys(a).length>=Object.keys(t).length||Object.keys(a).find(i=>t[i]===(!r||lr.all))},c8=(n,t,e)=>!n||!t||n===t||gu(n).some(r=>r&&(e?r===t:r.startsWith(t)||t.startsWith(r))),l8=(n,t,e,r,o)=>o.isOnAll?!1:!e&&o.isOnTouch?!(t||n):(e?r.isOnBlur:o.isOnBlur)?!n:(e?r.isOnChange:o.isOnChange)?n:!0,d8=(n,t)=>!Mp(me(n,t)).length&&Mt(n,t),f8=(n,t,e)=>{const r=gu(me(n,e));return pt(r,"root",t[e]),pt(n,e,r),n};function Cx(n,t,e="validate"){if(zn(n)||Array.isArray(n)&&n.every(zn)||Un(n)&&!n)return{type:e,message:zn(n)?n:"",ref:t}}var qi=n=>Ft(n)&&!Vl(n)?n:{value:n,message:""},_x=async(n,t,e,r,o,a)=>{const{ref:i,refs:s,required:u,maxLength:c,minLength:l,min:d,max:f,pattern:h,validate:m,name:v,valueAsNumber:p,mount:g}=n._f,b=me(e,v);if(!g||t.has(v))return{};const w=s?s[0]:i,x=I=>{o&&w.reportValidity&&(w.setCustomValidity(Un(I)?"":I||""),w.reportValidity())},C={},_=jp(i),E=mu(i),$=_||E,S=(p||Vp(i))&&Ot(i.value)&&Ot(b)||Wl(i)&&i.value===""||b===""||Array.isArray(b)&&!b.length,N=ix.bind(null,v,r,C),F=(I,j,L,z=vo.maxLength,H=vo.minLength)=>{const M=I?j:L;C[v]={type:I?z:H,message:M,ref:i,...N(I?z:H,M)}};if(a?!Array.isArray(b)||!b.length:u&&(!$&&(S||gn(b))||Un(b)&&!b||E&&!hx(s).isValid||_&&!mx(s).isValid)){const{value:I,message:j}=zn(u)?{value:!!u,message:u}:qi(u);if(I&&(C[v]={type:vo.required,message:j,ref:w,...N(vo.required,j)},!r))return x(j),C}if(!S&&(!gn(d)||!gn(f))){let I,j;const L=qi(f),z=qi(d);if(!gn(b)&&!isNaN(b)){const H=i.valueAsNumber||b&&+b;gn(L.value)||(I=H>L.value),gn(z.value)||(j=H<z.value)}else{const H=i.valueAsDate||new Date(b),M=P=>new Date(new Date().toDateString()+" "+P),T=i.type=="time",A=i.type=="week";zn(L.value)&&b&&(I=T?M(b)>M(L.value):A?b>L.value:H>new Date(L.value)),zn(z.value)&&b&&(j=T?M(b)<M(z.value):A?b<z.value:H<new Date(z.value))}if((I||j)&&(F(!!I,L.message,z.message,vo.max,vo.min),!r))return x(C[v].message),C}if((c||l)&&!S&&(zn(b)||a&&Array.isArray(b))){const I=qi(c),j=qi(l),L=!gn(I.value)&&b.length>+I.value,z=!gn(j.value)&&b.length<+j.value;if((L||z)&&(F(L,I.message,j.message),!r))return x(C[v].message),C}if(h&&!S&&zn(b)){const{value:I,message:j}=qi(h);if(Vl(I)&&!b.match(I)&&(C[v]={type:vo.pattern,message:j,ref:i,...N(vo.pattern,j)},!r))return x(j),C}if(m){if(dr(m)){const I=await m(b,e),j=Cx(I,w);if(j&&(C[v]={...j,...N(vo.validate,j.message)},!r))return x(j.message),C}else if(Ft(m)){let I={};for(const j in m){if(!kn(I)&&!r)break;const L=Cx(await m[j](b,e),w,j);L&&(I={...L,...N(j,L.message)},x(L.message),r&&(C[v]=I))}if(!kn(I)&&(C[v]={ref:w,...I},!r))return C}}return x(!0),C};const h8={mode:lr.onSubmit,reValidateMode:lr.onChange,shouldFocusError:!0};function p8(n={}){let t={...h8,...n},e={submitCount:0,isDirty:!1,isReady:!1,isLoading:dr(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},o=Ft(t.defaultValues)||Ft(t.values)?qt(t.defaultValues||t.values)||{}:{},a=t.shouldUnregister?{}:qt(o),i={action:!1,mount:!1,watch:!1},s={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},u,c=0;const l={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1};let d={...l};const f={array:sx(),state:sx()},h=t.criteriaMode===lr.all,m=V=>Y=>{clearTimeout(c),c=setTimeout(V,Y)},v=async V=>{if(!t.disabled&&(l.isValid||d.isValid||V)){const Y=t.resolver?kn((await E()).errors):await S(r,!0);Y!==e.isValid&&f.state.next({isValid:Y})}},p=(V,Y)=>{!t.disabled&&(l.isValidating||l.validatingFields||d.isValidating||d.validatingFields)&&((V||Array.from(s.mount)).forEach(te=>{te&&(Y?pt(e.validatingFields,te,Y):Mt(e.validatingFields,te))}),f.state.next({validatingFields:e.validatingFields,isValidating:!kn(e.validatingFields)}))},g=(V,Y=[],te,he,pe=!0,le=!0)=>{if(he&&te&&!t.disabled){if(i.action=!0,le&&Array.isArray(me(r,V))){const ye=te(me(r,V),he.argA,he.argB);pe&&pt(r,V,ye)}if(le&&Array.isArray(me(e.errors,V))){const ye=te(me(e.errors,V),he.argA,he.argB);pe&&pt(e.errors,V,ye),d8(e.errors,V)}if((l.touchedFields||d.touchedFields)&&le&&Array.isArray(me(e.touchedFields,V))){const ye=te(me(e.touchedFields,V),he.argA,he.argB);pe&&pt(e.touchedFields,V,ye)}(l.dirtyFields||d.dirtyFields)&&(e.dirtyFields=Gi(o,a)),f.state.next({name:V,isDirty:F(V,Y),dirtyFields:e.dirtyFields,errors:e.errors,isValid:e.isValid})}else pt(a,V,Y)},b=(V,Y)=>{pt(e.errors,V,Y),f.state.next({errors:e.errors})},w=V=>{e.errors=V,f.state.next({errors:e.errors,isValid:!1})},x=(V,Y,te,he)=>{const pe=me(r,V);if(pe){const le=me(a,V,Ot(te)?me(o,V):te);Ot(le)||he&&he.defaultChecked||Y?pt(a,V,Y?le:gx(pe._f)):L(V,le),i.mount&&v()}},C=(V,Y,te,he,pe)=>{let le=!1,ye=!1;const We={name:V};if(!t.disabled){if(!te||he){(l.isDirty||d.isDirty)&&(ye=e.isDirty,e.isDirty=We.isDirty=F(),le=ye!==We.isDirty);const Ge=mo(me(o,V),Y);ye=!!me(e.dirtyFields,V),Ge?Mt(e.dirtyFields,V):pt(e.dirtyFields,V,!0),We.dirtyFields=e.dirtyFields,le=le||(l.dirtyFields||d.dirtyFields)&&ye!==!Ge}if(te){const Ge=me(e.touchedFields,V);Ge||(pt(e.touchedFields,V,te),We.touchedFields=e.touchedFields,le=le||(l.touchedFields||d.touchedFields)&&Ge!==te)}le&&pe&&f.state.next(We)}return le?We:{}},_=(V,Y,te,he)=>{const pe=me(e.errors,V),le=(l.isValid||d.isValid)&&Un(Y)&&e.isValid!==Y;if(t.delayError&&te?(u=m(()=>b(V,te)),u(t.delayError)):(clearTimeout(c),u=null,te?pt(e.errors,V,te):Mt(e.errors,V)),(te?!mo(pe,te):pe)||!kn(he)||le){const ye={...he,...le&&Un(Y)?{isValid:Y}:{},errors:e.errors,name:V};e={...e,...ye},f.state.next(ye)}},E=async V=>{p(V,!0);const Y=await t.resolver(a,t.context,a8(V||s.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return p(V),Y},$=async V=>{const{errors:Y}=await E(V);if(V)for(const te of V){const he=me(Y,te);he?pt(e.errors,te,he):Mt(e.errors,te)}else e.errors=Y;return Y},S=async(V,Y,te={valid:!0})=>{for(const he in V){const pe=V[he];if(pe){const{_f:le,...ye}=pe;if(le){const We=s.array.has(le.name),Ge=pe._f&&i8(pe._f);Ge&&l.validatingFields&&p([le.name],!0);const Jt=await _x(pe,s.disabled,a,h,t.shouldUseNativeValidation&&!Y,We);if(Ge&&l.validatingFields&&p([le.name]),Jt[le.name]&&(te.valid=!1,Y))break;!Y&&(me(Jt,le.name)?We?f8(e.errors,Jt,le.name):pt(e.errors,le.name,Jt[le.name]):Mt(e.errors,le.name))}!kn(ye)&&await S(ye,Y,te)}}return te.valid},N=()=>{for(const V of s.unMount){const Y=me(r,V);Y&&(Y._f.refs?Y._f.refs.every(te=>!Up(te)):!Up(Y._f.ref))&&X(V)}s.unMount=new Set},F=(V,Y)=>!t.disabled&&(V&&Y&&pt(a,V,Y),!mo(P(),o)),I=(V,Y,te)=>ox(V,s,{...i.mount?a:Ot(Y)?o:zn(V)?{[V]:Y}:Y},te,Y),j=V=>Mp(me(i.mount?a:o,V,t.shouldUnregister?me(o,V,[]):[])),L=(V,Y,te={})=>{const he=me(r,V);let pe=Y;if(he){const le=he._f;le&&(!le.disabled&&pt(a,V,px(Y,le)),pe=Wl(le.ref)&&gn(Y)?"":Y,cx(le.ref)?[...le.ref.options].forEach(ye=>ye.selected=pe.includes(ye.value)):le.refs?mu(le.ref)?le.refs.forEach(ye=>{(!ye.defaultChecked||!ye.disabled)&&(Array.isArray(pe)?ye.checked=!!pe.find(We=>We===ye.value):ye.checked=pe===ye.value||!!pe)}):le.refs.forEach(ye=>ye.checked=ye.value===pe):Vp(le.ref)?le.ref.value="":(le.ref.value=pe,le.ref.type||f.state.next({name:V,values:qt(a)})))}(te.shouldDirty||te.shouldTouch)&&C(V,pe,te.shouldTouch,te.shouldDirty,!0),te.shouldValidate&&A(V)},z=(V,Y,te)=>{for(const he in Y){if(!Y.hasOwnProperty(he))return;const pe=Y[he],le=V+"."+he,ye=me(r,le);(s.array.has(V)||Ft(pe)||ye&&!ye._f)&&!Ga(pe)?z(le,pe,te):L(le,pe,te)}},H=(V,Y,te={})=>{const he=me(r,V),pe=s.array.has(V),le=qt(Y);pt(a,V,le),pe?(f.array.next({name:V,values:qt(a)}),(l.isDirty||l.dirtyFields||d.isDirty||d.dirtyFields)&&te.shouldDirty&&f.state.next({name:V,dirtyFields:Gi(o,a),isDirty:F(V,le)})):he&&!he._f&&!gn(le)?z(V,le,te):L(V,le,te),xx(V,s)&&f.state.next({...e,name:V}),f.state.next({name:i.mount?V:void 0,values:qt(a)})},M=async V=>{i.mount=!0;const Y=V.target;let te=Y.name,he=!0;const pe=me(r,te),le=Ge=>{he=Number.isNaN(Ge)||Ga(Ge)&&isNaN(Ge.getTime())||mo(Ge,me(a,te,Ge))},ye=yx(t.mode),We=yx(t.reValidateMode);if(pe){let Ge,Jt;const xr=Y.type?gx(pe._f):tx(V),er=V.type===Ll.BLUR||V.type===Ll.FOCUS_OUT,Os=!s8(pe._f)&&!t.resolver&&!me(e.errors,te)&&!pe._f.deps||l8(er,me(e.touchedFields,te),e.isSubmitted,We,ye),wr=xx(te,s,er);pt(a,te,xr),er?(!Y||!Y.readOnly)&&(pe._f.onBlur&&pe._f.onBlur(V),u&&u(0)):pe._f.onChange&&pe._f.onChange(V);const On=C(te,xr,er),ya=!kn(On)||wr;if(!er&&f.state.next({name:te,type:V.type,values:qt(a)}),Os)return(l.isValid||d.isValid)&&(t.mode==="onBlur"?er&&v():er||v()),ya&&f.state.next({name:te,...wr?{}:On});if(!er&&wr&&f.state.next({...e}),t.resolver){const{errors:Ao}=await E([te]);if(le(xr),he){const Tm=wx(e.errors,r,te),$d=wx(Ao,r,Tm.name||te);Ge=$d.error,te=$d.name,Jt=kn(Ao)}}else p([te],!0),Ge=(await _x(pe,s.disabled,a,h,t.shouldUseNativeValidation))[te],p([te]),le(xr),he&&(Ge?Jt=!1:(l.isValid||d.isValid)&&(Jt=await S(r,!0)));he&&(pe._f.deps&&(!Array.isArray(pe._f.deps)||pe._f.deps.length>0)&&A(pe._f.deps),_(te,Jt,Ge,On))}},T=(V,Y)=>{if(me(e.errors,Y)&&V.focus)return V.focus(),1},A=async(V,Y={})=>{let te,he;const pe=gu(V);if(t.resolver){const le=await $(Ot(V)?V:pe);te=kn(le),he=V?!pe.some(ye=>me(le,ye)):te}else V?(he=(await Promise.all(pe.map(async le=>{const ye=me(r,le);return await S(ye&&ye._f?{[le]:ye}:ye)}))).every(Boolean),!(!he&&!e.isValid)&&v()):he=te=await S(r);return f.state.next({...!zn(V)||(l.isValid||d.isValid)&&te!==e.isValid?{}:{name:V},...t.resolver||!V?{isValid:te}:{},errors:e.errors}),Y.shouldFocus&&!he&&bu(r,T,V?pe:s.mount),he},P=(V,Y)=>{let te={...i.mount?a:o};return Y&&(te=ux(Y.dirtyFields?e.dirtyFields:e.touchedFields,te)),Ot(V)?te:zn(V)?me(te,V):V.map(he=>me(te,he))},B=(V,Y)=>({invalid:!!me((Y||e).errors,V),isDirty:!!me((Y||e).dirtyFields,V),error:me((Y||e).errors,V),isValidating:!!me(e.validatingFields,V),isTouched:!!me((Y||e).touchedFields,V)}),K=V=>{V&&gu(V).forEach(Y=>Mt(e.errors,Y)),f.state.next({errors:V?e.errors:{}})},q=(V,Y,te)=>{const he=(me(r,V,{_f:{}})._f||{}).ref,pe=me(e.errors,V)||{},{ref:le,message:ye,type:We,...Ge}=pe;pt(e.errors,V,{...Ge,...Y,ref:he}),f.state.next({name:V,errors:e.errors,isValid:!1}),te&&te.shouldFocus&&he&&he.focus&&he.focus()},Z=(V,Y)=>dr(V)?f.state.subscribe({next:te=>"values"in te&&V(I(void 0,Y),te)}):I(V,Y,!0),oe=V=>f.state.subscribe({next:Y=>{c8(V.name,Y.name,V.exact)&&u8(Y,V.formState||l,Bt,V.reRenderRoot)&&V.callback({values:{...a},...e,...Y,defaultValues:o})}}).unsubscribe,ae=V=>(i.mount=!0,d={...d,...V.formState},oe({...V,formState:d})),X=(V,Y={})=>{for(const te of V?gu(V):s.mount)s.mount.delete(te),s.array.delete(te),Y.keepValue||(Mt(r,te),Mt(a,te)),!Y.keepError&&Mt(e.errors,te),!Y.keepDirty&&Mt(e.dirtyFields,te),!Y.keepTouched&&Mt(e.touchedFields,te),!Y.keepIsValidating&&Mt(e.validatingFields,te),!t.shouldUnregister&&!Y.keepDefaultValue&&Mt(o,te);f.state.next({values:qt(a)}),f.state.next({...e,...Y.keepDirty?{isDirty:F()}:{}}),!Y.keepIsValid&&v()},re=({disabled:V,name:Y})=>{(Un(V)&&i.mount||V||s.disabled.has(Y))&&(V?s.disabled.add(Y):s.disabled.delete(Y))},ce=(V,Y={})=>{let te=me(r,V);const he=Un(Y.disabled)||Un(t.disabled);return pt(r,V,{...te||{},_f:{...te&&te._f?te._f:{ref:{name:V}},name:V,mount:!0,...Y}}),s.mount.add(V),te?re({disabled:Un(Y.disabled)?Y.disabled:t.disabled,name:V}):x(V,!0,Y.value),{...he?{disabled:Y.disabled||t.disabled}:{},...t.progressive?{required:!!Y.required,min:yu(Y.min),max:yu(Y.max),minLength:yu(Y.minLength),maxLength:yu(Y.maxLength),pattern:yu(Y.pattern)}:{},name:V,onChange:M,onBlur:M,ref:pe=>{if(pe){ce(V,Y),te=me(r,V);const le=Ot(pe.value)&&pe.querySelectorAll&&pe.querySelectorAll("input,select,textarea")[0]||pe,ye=t8(le),We=te._f.refs||[];if(ye?We.find(Ge=>Ge===le):le===te._f.ref)return;pt(r,V,{_f:{...te._f,...ye?{refs:[...We.filter(Up),le,...Array.isArray(me(o,V))?[{}]:[]],ref:{type:le.type,name:V}}:{ref:le}}}),x(V,!1,void 0,le)}else te=me(r,V,{}),te._f&&(te._f.mount=!1),(t.shouldUnregister||Y.shouldUnregister)&&!(nx(s.array,V)&&i.action)&&s.unMount.add(V)}}},ue=()=>t.shouldFocusError&&bu(r,T,s.mount),se=V=>{Un(V)&&(f.state.next({disabled:V}),bu(r,(Y,te)=>{const he=me(r,te);he&&(Y.disabled=he._f.disabled||V,Array.isArray(he._f.refs)&&he._f.refs.forEach(pe=>{pe.disabled=he._f.disabled||V}))},0,!1))},ee=(V,Y)=>async te=>{let he;te&&(te.preventDefault&&te.preventDefault(),te.persist&&te.persist());let pe=qt(a);if(f.state.next({isSubmitting:!0}),t.resolver){const{errors:le,values:ye}=await E();e.errors=le,pe=qt(ye)}else await S(r);if(s.disabled.size)for(const le of s.disabled)Mt(pe,le);if(Mt(e.errors,"root"),kn(e.errors)){f.state.next({errors:{}});try{await V(pe,te)}catch(le){he=le}}else Y&&await Y({...e.errors},te),ue(),setTimeout(ue);if(f.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:kn(e.errors)&&!he,submitCount:e.submitCount+1,errors:e.errors}),he)throw he},_e=(V,Y={})=>{me(r,V)&&(Ot(Y.defaultValue)?H(V,qt(me(o,V))):(H(V,Y.defaultValue),pt(o,V,qt(Y.defaultValue))),Y.keepTouched||Mt(e.touchedFields,V),Y.keepDirty||(Mt(e.dirtyFields,V),e.isDirty=Y.defaultValue?F(V,qt(me(o,V))):F()),Y.keepError||(Mt(e.errors,V),l.isValid&&v()),f.state.next({...e}))},Fe=(V,Y={})=>{const te=V?qt(V):o,he=qt(te),pe=kn(V),le=pe?o:he;if(Y.keepDefaultValues||(o=te),!Y.keepValues){if(Y.keepDirtyValues){const ye=new Set([...s.mount,...Object.keys(Gi(o,a))]);for(const We of Array.from(ye))me(e.dirtyFields,We)?pt(le,We,me(a,We)):H(We,me(le,We))}else{if(Fp&&Ot(V))for(const ye of s.mount){const We=me(r,ye);if(We&&We._f){const Ge=Array.isArray(We._f.refs)?We._f.refs[0]:We._f.ref;if(Wl(Ge)){const Jt=Ge.closest("form");if(Jt){Jt.reset();break}}}}if(Y.keepFieldsRef)for(const ye of s.mount)H(ye,me(le,ye));else r={}}a=t.shouldUnregister?Y.keepDefaultValues?qt(o):{}:qt(le),f.array.next({values:{...le}}),f.state.next({values:{...le}})}s={mount:Y.keepDirtyValues?s.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},i.mount=!l.isValid||!!Y.keepIsValid||!!Y.keepDirtyValues,i.watch=!!t.shouldUnregister,f.state.next({submitCount:Y.keepSubmitCount?e.submitCount:0,isDirty:pe?!1:Y.keepDirty?e.isDirty:!!(Y.keepDefaultValues&&!mo(V,o)),isSubmitted:Y.keepIsSubmitted?e.isSubmitted:!1,dirtyFields:pe?{}:Y.keepDirtyValues?Y.keepDefaultValues&&a?Gi(o,a):e.dirtyFields:Y.keepDefaultValues&&V?Gi(o,V):Y.keepDirty?e.dirtyFields:{},touchedFields:Y.keepTouched?e.touchedFields:{},errors:Y.keepErrors?e.errors:{},isSubmitSuccessful:Y.keepIsSubmitSuccessful?e.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:o})},Ye=(V,Y)=>Fe(dr(V)?V(a):V,Y),Ze=(V,Y={})=>{const te=me(r,V),he=te&&te._f;if(he){const pe=he.refs?he.refs[0]:he.ref;pe.focus&&(pe.focus(),Y.shouldSelect&&dr(pe.select)&&pe.select())}},Bt=V=>{e={...e,...V}},Pt={control:{register:ce,unregister:X,getFieldState:B,handleSubmit:ee,setError:q,_subscribe:oe,_runSchema:E,_focusError:ue,_getWatch:I,_getDirty:F,_setValid:v,_setFieldArray:g,_setDisabledField:re,_setErrors:w,_getFieldArray:j,_reset:Fe,_resetDefaultValues:()=>dr(t.defaultValues)&&t.defaultValues().then(V=>{Ye(V,t.resetOptions),f.state.next({isLoading:!1})}),_removeUnmounted:N,_disableForm:se,_subjects:f,_proxyFormState:l,get _fields(){return r},get _formValues(){return a},get _state(){return i},set _state(V){i=V},get _defaultValues(){return o},get _names(){return s},set _names(V){s=V},get _formState(){return e},get _options(){return t},set _options(V){t={...t,...V}}},subscribe:ae,trigger:A,register:ce,handleSubmit:ee,watch:Z,setValue:H,getValues:P,reset:Ye,resetField:_e,clearErrors:K,unregister:X,setError:q,setFocus:Ze,getFieldState:B};return{...Pt,formControl:Pt}}function Ki(n={}){const t=D.useRef(void 0),e=D.useRef(void 0),[r,o]=D.useState({isDirty:!1,isValidating:!1,isLoading:dr(n.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:n.errors||{},disabled:n.disabled||!1,isReady:!1,defaultValues:dr(n.defaultValues)?void 0:n.defaultValues});if(!t.current)if(n.formControl)t.current={...n.formControl,formState:r},n.defaultValues&&!dr(n.defaultValues)&&n.formControl.reset(n.defaultValues,n.resetOptions);else{const{formControl:i,...s}=p8(n);t.current={...s,formState:r}}const a=t.current.control;return a._options=n,Bp(()=>{const i=a._subscribe({formState:a._proxyFormState,callback:()=>o({...a._formState}),reRenderRoot:!0});return o(s=>({...s,isReady:!0})),a._formState.isReady=!0,i},[a]),D.useEffect(()=>a._disableForm(n.disabled),[a,n.disabled]),D.useEffect(()=>{n.mode&&(a._options.mode=n.mode),n.reValidateMode&&(a._options.reValidateMode=n.reValidateMode)},[a,n.mode,n.reValidateMode]),D.useEffect(()=>{n.errors&&(a._setErrors(n.errors),a._focusError())},[a,n.errors]),D.useEffect(()=>{n.shouldUnregister&&a._subjects.state.next({values:a._getWatch()})},[a,n.shouldUnregister]),D.useEffect(()=>{if(a._proxyFormState.isDirty){const i=a._getDirty();i!==r.isDirty&&a._subjects.state.next({isDirty:i})}},[a,r.isDirty]),D.useEffect(()=>{n.values&&!mo(n.values,e.current)?(a._reset(n.values,{keepFieldsRef:!0,...a._options.resetOptions}),e.current=n.values,o(i=>({...i}))):a._resetDefaultValues()},[a,n.values]),D.useEffect(()=>{a._state.mount||(a._setValid(),a._state.mount=!0),a._state.watch&&(a._state.watch=!1,a._subjects.state.next({...a._formState})),a._removeUnmounted()}),t.current.formState=rx(r,a),t.current}const Ex=(n,t,e)=>{if(n&&"reportValidity"in n){const r=me(e,t);n.setCustomValidity(r&&r.message||""),n.reportValidity()}},Sx=(n,t)=>{for(const e in t.fields){const r=t.fields[e];r&&r.ref&&"reportValidity"in r.ref?Ex(r.ref,e,n):r.refs&&r.refs.forEach(o=>Ex(o,e,n))}},v8=(n,t)=>{t.shouldUseNativeValidation&&Sx(n,t);const e={};for(const r in n){const o=me(t.fields,r),a=Object.assign(n[r]||{},{ref:o&&o.ref});if(m8(t.names||Object.keys(n),r)){const i=Object.assign({},me(e,r));pt(i,"root",a),pt(e,r,i)}else pt(e,r,a)}return e},m8=(n,t)=>n.some(e=>e.startsWith(t+"."));var g8=function(n,t){for(var e={};n.length;){var r=n[0],o=r.code,a=r.message,i=r.path.join(".");if(!e[i])if("unionErrors"in r){var s=r.unionErrors[0].errors[0];e[i]={message:s.message,type:s.code}}else e[i]={message:a,type:o};if("unionErrors"in r&&r.unionErrors.forEach(function(l){return l.errors.forEach(function(d){return n.push(d)})}),t){var u=e[i].types,c=u&&u[r.code];e[i]=ix(i,t,e,o,c?[].concat(c,r.message):r.message)}n.shift()}return e},Yi=function(n,t,e){return e===void 0&&(e={}),function(r,o,a){try{return Promise.resolve(function(i,s){try{var u=Promise.resolve(n[e.mode==="sync"?"parse":"parseAsync"](r,t)).then(function(c){return a.shouldUseNativeValidation&&Sx({},a),{errors:{},values:e.raw?r:c}})}catch(c){return s(c)}return u&&u.then?u.then(void 0,s):u}(0,function(i){if(function(s){return Array.isArray(s==null?void 0:s.errors)}(i))return{values:{},errors:v8(g8(i.errors,!a.shouldUseNativeValidation&&a.criteriaMode==="all"),a)};throw i}))}catch(i){return Promise.reject(i)}}},st;(function(n){n.assertEqual=o=>{};function t(o){}n.assertIs=t;function e(o){throw new Error}n.assertNever=e,n.arrayToEnum=o=>{const a={};for(const i of o)a[i]=i;return a},n.getValidEnumValues=o=>{const a=n.objectKeys(o).filter(s=>typeof o[o[s]]!="number"),i={};for(const s of a)i[s]=o[s];return n.objectValues(i)},n.objectValues=o=>n.objectKeys(o).map(function(a){return o[a]}),n.objectKeys=typeof Object.keys=="function"?o=>Object.keys(o):o=>{const a=[];for(const i in o)Object.prototype.hasOwnProperty.call(o,i)&&a.push(i);return a},n.find=(o,a)=>{for(const i of o)if(a(i))return i},n.isInteger=typeof Number.isInteger=="function"?o=>Number.isInteger(o):o=>typeof o=="number"&&Number.isFinite(o)&&Math.floor(o)===o;function r(o,a=" | "){return o.map(i=>typeof i=="string"?`'${i}'`:i).join(a)}n.joinValues=r,n.jsonStringifyReplacer=(o,a)=>typeof a=="bigint"?a.toString():a})(st||(st={}));var Nx;(function(n){n.mergeShapes=(t,e)=>({...t,...e})})(Nx||(Nx={}));const Ee=st.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Zo=n=>{switch(typeof n){case"undefined":return Ee.undefined;case"string":return Ee.string;case"number":return Number.isNaN(n)?Ee.nan:Ee.number;case"boolean":return Ee.boolean;case"function":return Ee.function;case"bigint":return Ee.bigint;case"symbol":return Ee.symbol;case"object":return Array.isArray(n)?Ee.array:n===null?Ee.null:n.then&&typeof n.then=="function"&&n.catch&&typeof n.catch=="function"?Ee.promise:typeof Map<"u"&&n instanceof Map?Ee.map:typeof Set<"u"&&n instanceof Set?Ee.set:typeof Date<"u"&&n instanceof Date?Ee.date:Ee.object;default:return Ee.unknown}},de=st.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class go extends Error{get errors(){return this.issues}constructor(t){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const e=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,e):this.__proto__=e,this.name="ZodError",this.issues=t}format(t){const e=t||function(a){return a.message},r={_errors:[]},o=a=>{for(const i of a.issues)if(i.code==="invalid_union")i.unionErrors.map(o);else if(i.code==="invalid_return_type")o(i.returnTypeError);else if(i.code==="invalid_arguments")o(i.argumentsError);else if(i.path.length===0)r._errors.push(e(i));else{let s=r,u=0;for(;u<i.path.length;){const c=i.path[u];u===i.path.length-1?(s[c]=s[c]||{_errors:[]},s[c]._errors.push(e(i))):s[c]=s[c]||{_errors:[]},s=s[c],u++}}};return o(this),r}static assert(t){if(!(t instanceof go))throw new Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,st.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(t=e=>e.message){const e={},r=[];for(const o of this.issues)if(o.path.length>0){const a=o.path[0];e[a]=e[a]||[],e[a].push(t(o))}else r.push(t(o));return{formErrors:r,fieldErrors:e}}get formErrors(){return this.flatten()}}go.create=n=>new go(n);const Hp=(n,t)=>{let e;switch(n.code){case de.invalid_type:n.received===Ee.undefined?e="Required":e=`Expected ${n.expected}, received ${n.received}`;break;case de.invalid_literal:e=`Invalid literal value, expected ${JSON.stringify(n.expected,st.jsonStringifyReplacer)}`;break;case de.unrecognized_keys:e=`Unrecognized key(s) in object: ${st.joinValues(n.keys,", ")}`;break;case de.invalid_union:e="Invalid input";break;case de.invalid_union_discriminator:e=`Invalid discriminator value. Expected ${st.joinValues(n.options)}`;break;case de.invalid_enum_value:e=`Invalid enum value. Expected ${st.joinValues(n.options)}, received '${n.received}'`;break;case de.invalid_arguments:e="Invalid function arguments";break;case de.invalid_return_type:e="Invalid function return type";break;case de.invalid_date:e="Invalid date";break;case de.invalid_string:typeof n.validation=="object"?"includes"in n.validation?(e=`Invalid input: must include "${n.validation.includes}"`,typeof n.validation.position=="number"&&(e=`${e} at one or more positions greater than or equal to ${n.validation.position}`)):"startsWith"in n.validation?e=`Invalid input: must start with "${n.validation.startsWith}"`:"endsWith"in n.validation?e=`Invalid input: must end with "${n.validation.endsWith}"`:st.assertNever(n.validation):n.validation!=="regex"?e=`Invalid ${n.validation}`:e="Invalid";break;case de.too_small:n.type==="array"?e=`Array must contain ${n.exact?"exactly":n.inclusive?"at least":"more than"} ${n.minimum} element(s)`:n.type==="string"?e=`String must contain ${n.exact?"exactly":n.inclusive?"at least":"over"} ${n.minimum} character(s)`:n.type==="number"?e=`Number must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${n.minimum}`:n.type==="bigint"?e=`Number must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${n.minimum}`:n.type==="date"?e=`Date must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(n.minimum))}`:e="Invalid input";break;case de.too_big:n.type==="array"?e=`Array must contain ${n.exact?"exactly":n.inclusive?"at most":"less than"} ${n.maximum} element(s)`:n.type==="string"?e=`String must contain ${n.exact?"exactly":n.inclusive?"at most":"under"} ${n.maximum} character(s)`:n.type==="number"?e=`Number must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="bigint"?e=`BigInt must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="date"?e=`Date must be ${n.exact?"exactly":n.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(n.maximum))}`:e="Invalid input";break;case de.custom:e="Invalid input";break;case de.invalid_intersection_types:e="Intersection results could not be merged";break;case de.not_multiple_of:e=`Number must be a multiple of ${n.multipleOf}`;break;case de.not_finite:e="Number must be finite";break;default:e=t.defaultError,st.assertNever(n)}return{message:e}};let y8=Hp;function b8(){return y8}const x8=n=>{const{data:t,path:e,errorMaps:r,issueData:o}=n,a=[...e,...o.path||[]],i={...o,path:a};if(o.message!==void 0)return{...o,path:a,message:o.message};let s="";const u=r.filter(c=>!!c).slice().reverse();for(const c of u)s=c(i,{data:t,defaultError:s}).message;return{...o,path:a,message:s}};function be(n,t){const e=b8(),r=x8({issueData:t,data:n.data,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,e,e===Hp?void 0:Hp].filter(o=>!!o)});n.common.issues.push(r)}class Hn{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(t,e){const r=[];for(const o of e){if(o.status==="aborted")return Re;o.status==="dirty"&&t.dirty(),r.push(o.value)}return{status:t.value,value:r}}static async mergeObjectAsync(t,e){const r=[];for(const o of e){const a=await o.key,i=await o.value;r.push({key:a,value:i})}return Hn.mergeObjectSync(t,r)}static mergeObjectSync(t,e){const r={};for(const o of e){const{key:a,value:i}=o;if(a.status==="aborted"||i.status==="aborted")return Re;a.status==="dirty"&&t.dirty(),i.status==="dirty"&&t.dirty(),a.value!=="__proto__"&&(typeof i.value<"u"||o.alwaysSet)&&(r[a.value]=i.value)}return{status:t.value,value:r}}}const Re=Object.freeze({status:"aborted"}),xu=n=>({status:"dirty",value:n}),Qn=n=>({status:"valid",value:n}),$x=n=>n.status==="aborted",kx=n=>n.status==="dirty",Xi=n=>n.status==="valid",jl=n=>typeof Promise<"u"&&n instanceof Promise;var Pe;(function(n){n.errToObj=t=>typeof t=="string"?{message:t}:t||{},n.toString=t=>typeof t=="string"?t:t==null?void 0:t.message})(Pe||(Pe={}));class Qo{constructor(t,e,r,o){this._cachedPath=[],this.parent=t,this.data=e,this._path=r,this._key=o}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Px=(n,t)=>{if(Xi(t))return{success:!0,data:t.value};if(!n.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const e=new go(n.common.issues);return this._error=e,this._error}}};function Ke(n){if(!n)return{};const{errorMap:t,invalid_type_error:e,required_error:r,description:o}=n;if(t&&(e||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return t?{errorMap:t,description:o}:{errorMap:(i,s)=>{const{message:u}=n;return i.code==="invalid_enum_value"?{message:u??s.defaultError}:typeof s.data>"u"?{message:u??r??s.defaultError}:i.code!=="invalid_type"?{message:s.defaultError}:{message:u??e??s.defaultError}},description:o}}class tt{get description(){return this._def.description}_getType(t){return Zo(t.data)}_getOrReturnCtx(t,e){return e||{common:t.parent.common,data:t.data,parsedType:Zo(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new Hn,ctx:{common:t.parent.common,data:t.data,parsedType:Zo(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){const e=this._parse(t);if(jl(e))throw new Error("Synchronous parse encountered promise.");return e}_parseAsync(t){const e=this._parse(t);return Promise.resolve(e)}parse(t,e){const r=this.safeParse(t,e);if(r.success)return r.data;throw r.error}safeParse(t,e){const r={common:{issues:[],async:(e==null?void 0:e.async)??!1,contextualErrorMap:e==null?void 0:e.errorMap},path:(e==null?void 0:e.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:Zo(t)},o=this._parseSync({data:t,path:r.path,parent:r});return Px(r,o)}"~validate"(t){var r,o;const e={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:Zo(t)};if(!this["~standard"].async)try{const a=this._parseSync({data:t,path:[],parent:e});return Xi(a)?{value:a.value}:{issues:e.common.issues}}catch(a){(o=(r=a==null?void 0:a.message)==null?void 0:r.toLowerCase())!=null&&o.includes("encountered")&&(this["~standard"].async=!0),e.common={issues:[],async:!0}}return this._parseAsync({data:t,path:[],parent:e}).then(a=>Xi(a)?{value:a.value}:{issues:e.common.issues})}async parseAsync(t,e){const r=await this.safeParseAsync(t,e);if(r.success)return r.data;throw r.error}async safeParseAsync(t,e){const r={common:{issues:[],contextualErrorMap:e==null?void 0:e.errorMap,async:!0},path:(e==null?void 0:e.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:Zo(t)},o=this._parse({data:t,path:r.path,parent:r}),a=await(jl(o)?o:Promise.resolve(o));return Px(r,a)}refine(t,e){const r=o=>typeof e=="string"||typeof e>"u"?{message:e}:typeof e=="function"?e(o):e;return this._refinement((o,a)=>{const i=t(o),s=()=>a.addIssue({code:de.custom,...r(o)});return typeof Promise<"u"&&i instanceof Promise?i.then(u=>u?!0:(s(),!1)):i?!0:(s(),!1)})}refinement(t,e){return this._refinement((r,o)=>t(r)?!0:(o.addIssue(typeof e=="function"?e(r,o):e),!1))}_refinement(t){return new Ji({schema:this,typeName:Le.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}constructor(t){this.spa=this.safeParseAsync,this._def=t,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return ta.create(this,this._def)}nullable(){return es.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Hr.create(this)}promise(){return Hl.create(this,this._def)}or(t){return Ul.create([this,t],this._def)}and(t){return zl.create(this,t,this._def)}transform(t){return new Ji({...Ke(this._def),schema:this,typeName:Le.ZodEffects,effect:{type:"transform",transform:t}})}default(t){const e=typeof t=="function"?t:()=>t;return new Yp({...Ke(this._def),innerType:this,defaultValue:e,typeName:Le.ZodDefault})}brand(){return new U8({typeName:Le.ZodBranded,type:this,...Ke(this._def)})}catch(t){const e=typeof t=="function"?t:()=>t;return new Xp({...Ke(this._def),innerType:this,catchValue:e,typeName:Le.ZodCatch})}describe(t){const e=this.constructor;return new e({...this._def,description:t})}pipe(t){return Zp.create(this,t)}readonly(){return Qp.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const w8=/^c[^\s-]{8,}$/i,C8=/^[0-9a-z]+$/,_8=/^[0-9A-HJKMNP-TV-Z]{26}$/i,E8=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,S8=/^[a-z0-9_-]{21}$/i,N8=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,$8=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,k8=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,P8="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Gp;const I8=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,A8=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,T8=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,O8=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,D8=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,F8=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Ix="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",M8=new RegExp(`^${Ix}$`);function Ax(n){let t="[0-5]\\d";n.precision?t=`${t}\\.\\d{${n.precision}}`:n.precision==null&&(t=`${t}(\\.\\d+)?`);const e=n.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${e}`}function R8(n){return new RegExp(`^${Ax(n)}$`)}function L8(n){let t=`${Ix}T${Ax(n)}`;const e=[];return e.push(n.local?"Z?":"Z"),n.offset&&e.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${e.join("|")})`,new RegExp(`^${t}$`)}function B8(n,t){return!!((t==="v4"||!t)&&I8.test(n)||(t==="v6"||!t)&&T8.test(n))}function W8(n,t){if(!N8.test(n))return!1;try{const[e]=n.split(".");if(!e)return!1;const r=e.replace(/-/g,"+").replace(/_/g,"/").padEnd(e.length+(4-e.length%4)%4,"="),o=JSON.parse(atob(r));return!(typeof o!="object"||o===null||"typ"in o&&(o==null?void 0:o.typ)!=="JWT"||!o.alg||t&&o.alg!==t)}catch{return!1}}function V8(n,t){return!!((t==="v4"||!t)&&A8.test(n)||(t==="v6"||!t)&&O8.test(n))}class Jo extends tt{_parse(t){if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==Ee.string){const a=this._getOrReturnCtx(t);return be(a,{code:de.invalid_type,expected:Ee.string,received:a.parsedType}),Re}const r=new Hn;let o;for(const a of this._def.checks)if(a.kind==="min")t.data.length<a.value&&(o=this._getOrReturnCtx(t,o),be(o,{code:de.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),r.dirty());else if(a.kind==="max")t.data.length>a.value&&(o=this._getOrReturnCtx(t,o),be(o,{code:de.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),r.dirty());else if(a.kind==="length"){const i=t.data.length>a.value,s=t.data.length<a.value;(i||s)&&(o=this._getOrReturnCtx(t,o),i?be(o,{code:de.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):s&&be(o,{code:de.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),r.dirty())}else if(a.kind==="email")k8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"email",code:de.invalid_string,message:a.message}),r.dirty());else if(a.kind==="emoji")Gp||(Gp=new RegExp(P8,"u")),Gp.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"emoji",code:de.invalid_string,message:a.message}),r.dirty());else if(a.kind==="uuid")E8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"uuid",code:de.invalid_string,message:a.message}),r.dirty());else if(a.kind==="nanoid")S8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"nanoid",code:de.invalid_string,message:a.message}),r.dirty());else if(a.kind==="cuid")w8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"cuid",code:de.invalid_string,message:a.message}),r.dirty());else if(a.kind==="cuid2")C8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"cuid2",code:de.invalid_string,message:a.message}),r.dirty());else if(a.kind==="ulid")_8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"ulid",code:de.invalid_string,message:a.message}),r.dirty());else if(a.kind==="url")try{new URL(t.data)}catch{o=this._getOrReturnCtx(t,o),be(o,{validation:"url",code:de.invalid_string,message:a.message}),r.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"regex",code:de.invalid_string,message:a.message}),r.dirty())):a.kind==="trim"?t.data=t.data.trim():a.kind==="includes"?t.data.includes(a.value,a.position)||(o=this._getOrReturnCtx(t,o),be(o,{code:de.invalid_string,validation:{includes:a.value,position:a.position},message:a.message}),r.dirty()):a.kind==="toLowerCase"?t.data=t.data.toLowerCase():a.kind==="toUpperCase"?t.data=t.data.toUpperCase():a.kind==="startsWith"?t.data.startsWith(a.value)||(o=this._getOrReturnCtx(t,o),be(o,{code:de.invalid_string,validation:{startsWith:a.value},message:a.message}),r.dirty()):a.kind==="endsWith"?t.data.endsWith(a.value)||(o=this._getOrReturnCtx(t,o),be(o,{code:de.invalid_string,validation:{endsWith:a.value},message:a.message}),r.dirty()):a.kind==="datetime"?L8(a).test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{code:de.invalid_string,validation:"datetime",message:a.message}),r.dirty()):a.kind==="date"?M8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{code:de.invalid_string,validation:"date",message:a.message}),r.dirty()):a.kind==="time"?R8(a).test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{code:de.invalid_string,validation:"time",message:a.message}),r.dirty()):a.kind==="duration"?$8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"duration",code:de.invalid_string,message:a.message}),r.dirty()):a.kind==="ip"?B8(t.data,a.version)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"ip",code:de.invalid_string,message:a.message}),r.dirty()):a.kind==="jwt"?W8(t.data,a.alg)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"jwt",code:de.invalid_string,message:a.message}),r.dirty()):a.kind==="cidr"?V8(t.data,a.version)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"cidr",code:de.invalid_string,message:a.message}),r.dirty()):a.kind==="base64"?D8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"base64",code:de.invalid_string,message:a.message}),r.dirty()):a.kind==="base64url"?F8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"base64url",code:de.invalid_string,message:a.message}),r.dirty()):st.assertNever(a);return{status:r.value,value:t.data}}_regex(t,e,r){return this.refinement(o=>t.test(o),{validation:e,code:de.invalid_string,...Pe.errToObj(r)})}_addCheck(t){return new Jo({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...Pe.errToObj(t)})}url(t){return this._addCheck({kind:"url",...Pe.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...Pe.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...Pe.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...Pe.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...Pe.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...Pe.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...Pe.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...Pe.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...Pe.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...Pe.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...Pe.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...Pe.errToObj(t)})}datetime(t){return typeof t=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:t}):this._addCheck({kind:"datetime",precision:typeof(t==null?void 0:t.precision)>"u"?null:t==null?void 0:t.precision,offset:(t==null?void 0:t.offset)??!1,local:(t==null?void 0:t.local)??!1,...Pe.errToObj(t==null?void 0:t.message)})}date(t){return this._addCheck({kind:"date",message:t})}time(t){return typeof t=="string"?this._addCheck({kind:"time",precision:null,message:t}):this._addCheck({kind:"time",precision:typeof(t==null?void 0:t.precision)>"u"?null:t==null?void 0:t.precision,...Pe.errToObj(t==null?void 0:t.message)})}duration(t){return this._addCheck({kind:"duration",...Pe.errToObj(t)})}regex(t,e){return this._addCheck({kind:"regex",regex:t,...Pe.errToObj(e)})}includes(t,e){return this._addCheck({kind:"includes",value:t,position:e==null?void 0:e.position,...Pe.errToObj(e==null?void 0:e.message)})}startsWith(t,e){return this._addCheck({kind:"startsWith",value:t,...Pe.errToObj(e)})}endsWith(t,e){return this._addCheck({kind:"endsWith",value:t,...Pe.errToObj(e)})}min(t,e){return this._addCheck({kind:"min",value:t,...Pe.errToObj(e)})}max(t,e){return this._addCheck({kind:"max",value:t,...Pe.errToObj(e)})}length(t,e){return this._addCheck({kind:"length",value:t,...Pe.errToObj(e)})}nonempty(t){return this.min(1,Pe.errToObj(t))}trim(){return new Jo({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Jo({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Jo({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(t=>t.kind==="datetime")}get isDate(){return!!this._def.checks.find(t=>t.kind==="date")}get isTime(){return!!this._def.checks.find(t=>t.kind==="time")}get isDuration(){return!!this._def.checks.find(t=>t.kind==="duration")}get isEmail(){return!!this._def.checks.find(t=>t.kind==="email")}get isURL(){return!!this._def.checks.find(t=>t.kind==="url")}get isEmoji(){return!!this._def.checks.find(t=>t.kind==="emoji")}get isUUID(){return!!this._def.checks.find(t=>t.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(t=>t.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(t=>t.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(t=>t.kind==="cuid2")}get isULID(){return!!this._def.checks.find(t=>t.kind==="ulid")}get isIP(){return!!this._def.checks.find(t=>t.kind==="ip")}get isCIDR(){return!!this._def.checks.find(t=>t.kind==="cidr")}get isBase64(){return!!this._def.checks.find(t=>t.kind==="base64")}get isBase64url(){return!!this._def.checks.find(t=>t.kind==="base64url")}get minLength(){let t=null;for(const e of this._def.checks)e.kind==="min"&&(t===null||e.value>t)&&(t=e.value);return t}get maxLength(){let t=null;for(const e of this._def.checks)e.kind==="max"&&(t===null||e.value<t)&&(t=e.value);return t}}Jo.create=n=>new Jo({checks:[],typeName:Le.ZodString,coerce:(n==null?void 0:n.coerce)??!1,...Ke(n)});function j8(n,t){const e=(n.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,o=e>r?e:r,a=Number.parseInt(n.toFixed(o).replace(".","")),i=Number.parseInt(t.toFixed(o).replace(".",""));return a%i/10**o}class wu extends tt{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){if(this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==Ee.number){const a=this._getOrReturnCtx(t);return be(a,{code:de.invalid_type,expected:Ee.number,received:a.parsedType}),Re}let r;const o=new Hn;for(const a of this._def.checks)a.kind==="int"?st.isInteger(t.data)||(r=this._getOrReturnCtx(t,r),be(r,{code:de.invalid_type,expected:"integer",received:"float",message:a.message}),o.dirty()):a.kind==="min"?(a.inclusive?t.data<a.value:t.data<=a.value)&&(r=this._getOrReturnCtx(t,r),be(r,{code:de.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),o.dirty()):a.kind==="max"?(a.inclusive?t.data>a.value:t.data>=a.value)&&(r=this._getOrReturnCtx(t,r),be(r,{code:de.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),o.dirty()):a.kind==="multipleOf"?j8(t.data,a.value)!==0&&(r=this._getOrReturnCtx(t,r),be(r,{code:de.not_multiple_of,multipleOf:a.value,message:a.message}),o.dirty()):a.kind==="finite"?Number.isFinite(t.data)||(r=this._getOrReturnCtx(t,r),be(r,{code:de.not_finite,message:a.message}),o.dirty()):st.assertNever(a);return{status:o.value,value:t.data}}gte(t,e){return this.setLimit("min",t,!0,Pe.toString(e))}gt(t,e){return this.setLimit("min",t,!1,Pe.toString(e))}lte(t,e){return this.setLimit("max",t,!0,Pe.toString(e))}lt(t,e){return this.setLimit("max",t,!1,Pe.toString(e))}setLimit(t,e,r,o){return new wu({...this._def,checks:[...this._def.checks,{kind:t,value:e,inclusive:r,message:Pe.toString(o)}]})}_addCheck(t){return new wu({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:Pe.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:Pe.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:Pe.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:Pe.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:Pe.toString(t)})}multipleOf(t,e){return this._addCheck({kind:"multipleOf",value:t,message:Pe.toString(e)})}finite(t){return this._addCheck({kind:"finite",message:Pe.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:Pe.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:Pe.toString(t)})}get minValue(){let t=null;for(const e of this._def.checks)e.kind==="min"&&(t===null||e.value>t)&&(t=e.value);return t}get maxValue(){let t=null;for(const e of this._def.checks)e.kind==="max"&&(t===null||e.value<t)&&(t=e.value);return t}get isInt(){return!!this._def.checks.find(t=>t.kind==="int"||t.kind==="multipleOf"&&st.isInteger(t.value))}get isFinite(){let t=null,e=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(e===null||r.value>e)&&(e=r.value):r.kind==="max"&&(t===null||r.value<t)&&(t=r.value)}return Number.isFinite(e)&&Number.isFinite(t)}}wu.create=n=>new wu({checks:[],typeName:Le.ZodNumber,coerce:(n==null?void 0:n.coerce)||!1,...Ke(n)});class Cu extends tt{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){if(this._def.coerce)try{t.data=BigInt(t.data)}catch{return this._getInvalidInput(t)}if(this._getType(t)!==Ee.bigint)return this._getInvalidInput(t);let r;const o=new Hn;for(const a of this._def.checks)a.kind==="min"?(a.inclusive?t.data<a.value:t.data<=a.value)&&(r=this._getOrReturnCtx(t,r),be(r,{code:de.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),o.dirty()):a.kind==="max"?(a.inclusive?t.data>a.value:t.data>=a.value)&&(r=this._getOrReturnCtx(t,r),be(r,{code:de.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),o.dirty()):a.kind==="multipleOf"?t.data%a.value!==BigInt(0)&&(r=this._getOrReturnCtx(t,r),be(r,{code:de.not_multiple_of,multipleOf:a.value,message:a.message}),o.dirty()):st.assertNever(a);return{status:o.value,value:t.data}}_getInvalidInput(t){const e=this._getOrReturnCtx(t);return be(e,{code:de.invalid_type,expected:Ee.bigint,received:e.parsedType}),Re}gte(t,e){return this.setLimit("min",t,!0,Pe.toString(e))}gt(t,e){return this.setLimit("min",t,!1,Pe.toString(e))}lte(t,e){return this.setLimit("max",t,!0,Pe.toString(e))}lt(t,e){return this.setLimit("max",t,!1,Pe.toString(e))}setLimit(t,e,r,o){return new Cu({...this._def,checks:[...this._def.checks,{kind:t,value:e,inclusive:r,message:Pe.toString(o)}]})}_addCheck(t){return new Cu({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:Pe.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:Pe.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:Pe.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:Pe.toString(t)})}multipleOf(t,e){return this._addCheck({kind:"multipleOf",value:t,message:Pe.toString(e)})}get minValue(){let t=null;for(const e of this._def.checks)e.kind==="min"&&(t===null||e.value>t)&&(t=e.value);return t}get maxValue(){let t=null;for(const e of this._def.checks)e.kind==="max"&&(t===null||e.value<t)&&(t=e.value);return t}}Cu.create=n=>new Cu({checks:[],typeName:Le.ZodBigInt,coerce:(n==null?void 0:n.coerce)??!1,...Ke(n)});class Tx extends tt{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==Ee.boolean){const r=this._getOrReturnCtx(t);return be(r,{code:de.invalid_type,expected:Ee.boolean,received:r.parsedType}),Re}return Qn(t.data)}}Tx.create=n=>new Tx({typeName:Le.ZodBoolean,coerce:(n==null?void 0:n.coerce)||!1,...Ke(n)});class _u extends tt{_parse(t){if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==Ee.date){const a=this._getOrReturnCtx(t);return be(a,{code:de.invalid_type,expected:Ee.date,received:a.parsedType}),Re}if(Number.isNaN(t.data.getTime())){const a=this._getOrReturnCtx(t);return be(a,{code:de.invalid_date}),Re}const r=new Hn;let o;for(const a of this._def.checks)a.kind==="min"?t.data.getTime()<a.value&&(o=this._getOrReturnCtx(t,o),be(o,{code:de.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),r.dirty()):a.kind==="max"?t.data.getTime()>a.value&&(o=this._getOrReturnCtx(t,o),be(o,{code:de.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),r.dirty()):st.assertNever(a);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new _u({...this._def,checks:[...this._def.checks,t]})}min(t,e){return this._addCheck({kind:"min",value:t.getTime(),message:Pe.toString(e)})}max(t,e){return this._addCheck({kind:"max",value:t.getTime(),message:Pe.toString(e)})}get minDate(){let t=null;for(const e of this._def.checks)e.kind==="min"&&(t===null||e.value>t)&&(t=e.value);return t!=null?new Date(t):null}get maxDate(){let t=null;for(const e of this._def.checks)e.kind==="max"&&(t===null||e.value<t)&&(t=e.value);return t!=null?new Date(t):null}}_u.create=n=>new _u({checks:[],coerce:(n==null?void 0:n.coerce)||!1,typeName:Le.ZodDate,...Ke(n)});class Ox extends tt{_parse(t){if(this._getType(t)!==Ee.symbol){const r=this._getOrReturnCtx(t);return be(r,{code:de.invalid_type,expected:Ee.symbol,received:r.parsedType}),Re}return Qn(t.data)}}Ox.create=n=>new Ox({typeName:Le.ZodSymbol,...Ke(n)});class Dx extends tt{_parse(t){if(this._getType(t)!==Ee.undefined){const r=this._getOrReturnCtx(t);return be(r,{code:de.invalid_type,expected:Ee.undefined,received:r.parsedType}),Re}return Qn(t.data)}}Dx.create=n=>new Dx({typeName:Le.ZodUndefined,...Ke(n)});class Fx extends tt{_parse(t){if(this._getType(t)!==Ee.null){const r=this._getOrReturnCtx(t);return be(r,{code:de.invalid_type,expected:Ee.null,received:r.parsedType}),Re}return Qn(t.data)}}Fx.create=n=>new Fx({typeName:Le.ZodNull,...Ke(n)});class Eu extends tt{constructor(){super(...arguments),this._any=!0}_parse(t){return Qn(t.data)}}Eu.create=n=>new Eu({typeName:Le.ZodAny,...Ke(n)});class Mx extends tt{constructor(){super(...arguments),this._unknown=!0}_parse(t){return Qn(t.data)}}Mx.create=n=>new Mx({typeName:Le.ZodUnknown,...Ke(n)});class ea extends tt{_parse(t){const e=this._getOrReturnCtx(t);return be(e,{code:de.invalid_type,expected:Ee.never,received:e.parsedType}),Re}}ea.create=n=>new ea({typeName:Le.ZodNever,...Ke(n)});class Rx extends tt{_parse(t){if(this._getType(t)!==Ee.undefined){const r=this._getOrReturnCtx(t);return be(r,{code:de.invalid_type,expected:Ee.void,received:r.parsedType}),Re}return Qn(t.data)}}Rx.create=n=>new Rx({typeName:Le.ZodVoid,...Ke(n)});class Hr extends tt{_parse(t){const{ctx:e,status:r}=this._processInputParams(t),o=this._def;if(e.parsedType!==Ee.array)return be(e,{code:de.invalid_type,expected:Ee.array,received:e.parsedType}),Re;if(o.exactLength!==null){const i=e.data.length>o.exactLength.value,s=e.data.length<o.exactLength.value;(i||s)&&(be(e,{code:i?de.too_big:de.too_small,minimum:s?o.exactLength.value:void 0,maximum:i?o.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:o.exactLength.message}),r.dirty())}if(o.minLength!==null&&e.data.length<o.minLength.value&&(be(e,{code:de.too_small,minimum:o.minLength.value,type:"array",inclusive:!0,exact:!1,message:o.minLength.message}),r.dirty()),o.maxLength!==null&&e.data.length>o.maxLength.value&&(be(e,{code:de.too_big,maximum:o.maxLength.value,type:"array",inclusive:!0,exact:!1,message:o.maxLength.message}),r.dirty()),e.common.async)return Promise.all([...e.data].map((i,s)=>o.type._parseAsync(new Qo(e,i,e.path,s)))).then(i=>Hn.mergeArray(r,i));const a=[...e.data].map((i,s)=>o.type._parseSync(new Qo(e,i,e.path,s)));return Hn.mergeArray(r,a)}get element(){return this._def.type}min(t,e){return new Hr({...this._def,minLength:{value:t,message:Pe.toString(e)}})}max(t,e){return new Hr({...this._def,maxLength:{value:t,message:Pe.toString(e)}})}length(t,e){return new Hr({...this._def,exactLength:{value:t,message:Pe.toString(e)}})}nonempty(t){return this.min(1,t)}}Hr.create=(n,t)=>new Hr({type:n,minLength:null,maxLength:null,exactLength:null,typeName:Le.ZodArray,...Ke(t)});function Zi(n){if(n instanceof Rt){const t={};for(const e in n.shape){const r=n.shape[e];t[e]=ta.create(Zi(r))}return new Rt({...n._def,shape:()=>t})}else return n instanceof Hr?new Hr({...n._def,type:Zi(n.element)}):n instanceof ta?ta.create(Zi(n.unwrap())):n instanceof es?es.create(Zi(n.unwrap())):n instanceof qa?qa.create(n.items.map(t=>Zi(t))):n}class Rt extends tt{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const t=this._def.shape(),e=st.objectKeys(t);return this._cached={shape:t,keys:e},this._cached}_parse(t){if(this._getType(t)!==Ee.object){const c=this._getOrReturnCtx(t);return be(c,{code:de.invalid_type,expected:Ee.object,received:c.parsedType}),Re}const{status:r,ctx:o}=this._processInputParams(t),{shape:a,keys:i}=this._getCached(),s=[];if(!(this._def.catchall instanceof ea&&this._def.unknownKeys==="strip"))for(const c in o.data)i.includes(c)||s.push(c);const u=[];for(const c of i){const l=a[c],d=o.data[c];u.push({key:{status:"valid",value:c},value:l._parse(new Qo(o,d,o.path,c)),alwaysSet:c in o.data})}if(this._def.catchall instanceof ea){const c=this._def.unknownKeys;if(c==="passthrough")for(const l of s)u.push({key:{status:"valid",value:l},value:{status:"valid",value:o.data[l]}});else if(c==="strict")s.length>0&&(be(o,{code:de.unrecognized_keys,keys:s}),r.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const c=this._def.catchall;for(const l of s){const d=o.data[l];u.push({key:{status:"valid",value:l},value:c._parse(new Qo(o,d,o.path,l)),alwaysSet:l in o.data})}}return o.common.async?Promise.resolve().then(async()=>{const c=[];for(const l of u){const d=await l.key,f=await l.value;c.push({key:d,value:f,alwaysSet:l.alwaysSet})}return c}).then(c=>Hn.mergeObjectSync(r,c)):Hn.mergeObjectSync(r,u)}get shape(){return this._def.shape()}strict(t){return Pe.errToObj,new Rt({...this._def,unknownKeys:"strict",...t!==void 0?{errorMap:(e,r)=>{var a,i;const o=((i=(a=this._def).errorMap)==null?void 0:i.call(a,e,r).message)??r.defaultError;return e.code==="unrecognized_keys"?{message:Pe.errToObj(t).message??o}:{message:o}}}:{}})}strip(){return new Rt({...this._def,unknownKeys:"strip"})}passthrough(){return new Rt({...this._def,unknownKeys:"passthrough"})}extend(t){return new Rt({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new Rt({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:Le.ZodObject})}setKey(t,e){return this.augment({[t]:e})}catchall(t){return new Rt({...this._def,catchall:t})}pick(t){const e={};for(const r of st.objectKeys(t))t[r]&&this.shape[r]&&(e[r]=this.shape[r]);return new Rt({...this._def,shape:()=>e})}omit(t){const e={};for(const r of st.objectKeys(this.shape))t[r]||(e[r]=this.shape[r]);return new Rt({...this._def,shape:()=>e})}deepPartial(){return Zi(this)}partial(t){const e={};for(const r of st.objectKeys(this.shape)){const o=this.shape[r];t&&!t[r]?e[r]=o:e[r]=o.optional()}return new Rt({...this._def,shape:()=>e})}required(t){const e={};for(const r of st.objectKeys(this.shape))if(t&&!t[r])e[r]=this.shape[r];else{let a=this.shape[r];for(;a instanceof ta;)a=a._def.innerType;e[r]=a}return new Rt({...this._def,shape:()=>e})}keyof(){return Wx(st.objectKeys(this.shape))}}Rt.create=(n,t)=>new Rt({shape:()=>n,unknownKeys:"strip",catchall:ea.create(),typeName:Le.ZodObject,...Ke(t)}),Rt.strictCreate=(n,t)=>new Rt({shape:()=>n,unknownKeys:"strict",catchall:ea.create(),typeName:Le.ZodObject,...Ke(t)}),Rt.lazycreate=(n,t)=>new Rt({shape:n,unknownKeys:"strip",catchall:ea.create(),typeName:Le.ZodObject,...Ke(t)});class Ul extends tt{_parse(t){const{ctx:e}=this._processInputParams(t),r=this._def.options;function o(a){for(const s of a)if(s.result.status==="valid")return s.result;for(const s of a)if(s.result.status==="dirty")return e.common.issues.push(...s.ctx.common.issues),s.result;const i=a.map(s=>new go(s.ctx.common.issues));return be(e,{code:de.invalid_union,unionErrors:i}),Re}if(e.common.async)return Promise.all(r.map(async a=>{const i={...e,common:{...e.common,issues:[]},parent:null};return{result:await a._parseAsync({data:e.data,path:e.path,parent:i}),ctx:i}})).then(o);{let a;const i=[];for(const u of r){const c={...e,common:{...e.common,issues:[]},parent:null},l=u._parseSync({data:e.data,path:e.path,parent:c});if(l.status==="valid")return l;l.status==="dirty"&&!a&&(a={result:l,ctx:c}),c.common.issues.length&&i.push(c.common.issues)}if(a)return e.common.issues.push(...a.ctx.common.issues),a.result;const s=i.map(u=>new go(u));return be(e,{code:de.invalid_union,unionErrors:s}),Re}}get options(){return this._def.options}}Ul.create=(n,t)=>new Ul({options:n,typeName:Le.ZodUnion,...Ke(t)});function qp(n,t){const e=Zo(n),r=Zo(t);if(n===t)return{valid:!0,data:n};if(e===Ee.object&&r===Ee.object){const o=st.objectKeys(t),a=st.objectKeys(n).filter(s=>o.indexOf(s)!==-1),i={...n,...t};for(const s of a){const u=qp(n[s],t[s]);if(!u.valid)return{valid:!1};i[s]=u.data}return{valid:!0,data:i}}else if(e===Ee.array&&r===Ee.array){if(n.length!==t.length)return{valid:!1};const o=[];for(let a=0;a<n.length;a++){const i=n[a],s=t[a],u=qp(i,s);if(!u.valid)return{valid:!1};o.push(u.data)}return{valid:!0,data:o}}else return e===Ee.date&&r===Ee.date&&+n==+t?{valid:!0,data:n}:{valid:!1}}class zl extends tt{_parse(t){const{status:e,ctx:r}=this._processInputParams(t),o=(a,i)=>{if($x(a)||$x(i))return Re;const s=qp(a.value,i.value);return s.valid?((kx(a)||kx(i))&&e.dirty(),{status:e.value,value:s.data}):(be(r,{code:de.invalid_intersection_types}),Re)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([a,i])=>o(a,i)):o(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}zl.create=(n,t,e)=>new zl({left:n,right:t,typeName:Le.ZodIntersection,...Ke(e)});class qa extends tt{_parse(t){const{status:e,ctx:r}=this._processInputParams(t);if(r.parsedType!==Ee.array)return be(r,{code:de.invalid_type,expected:Ee.array,received:r.parsedType}),Re;if(r.data.length<this._def.items.length)return be(r,{code:de.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),Re;!this._def.rest&&r.data.length>this._def.items.length&&(be(r,{code:de.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),e.dirty());const a=[...r.data].map((i,s)=>{const u=this._def.items[s]||this._def.rest;return u?u._parse(new Qo(r,i,r.path,s)):null}).filter(i=>!!i);return r.common.async?Promise.all(a).then(i=>Hn.mergeArray(e,i)):Hn.mergeArray(e,a)}get items(){return this._def.items}rest(t){return new qa({...this._def,rest:t})}}qa.create=(n,t)=>{if(!Array.isArray(n))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new qa({items:n,typeName:Le.ZodTuple,rest:null,...Ke(t)})};class Lx extends tt{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){const{status:e,ctx:r}=this._processInputParams(t);if(r.parsedType!==Ee.map)return be(r,{code:de.invalid_type,expected:Ee.map,received:r.parsedType}),Re;const o=this._def.keyType,a=this._def.valueType,i=[...r.data.entries()].map(([s,u],c)=>({key:o._parse(new Qo(r,s,r.path,[c,"key"])),value:a._parse(new Qo(r,u,r.path,[c,"value"]))}));if(r.common.async){const s=new Map;return Promise.resolve().then(async()=>{for(const u of i){const c=await u.key,l=await u.value;if(c.status==="aborted"||l.status==="aborted")return Re;(c.status==="dirty"||l.status==="dirty")&&e.dirty(),s.set(c.value,l.value)}return{status:e.value,value:s}})}else{const s=new Map;for(const u of i){const c=u.key,l=u.value;if(c.status==="aborted"||l.status==="aborted")return Re;(c.status==="dirty"||l.status==="dirty")&&e.dirty(),s.set(c.value,l.value)}return{status:e.value,value:s}}}}Lx.create=(n,t,e)=>new Lx({valueType:t,keyType:n,typeName:Le.ZodMap,...Ke(e)});class Su extends tt{_parse(t){const{status:e,ctx:r}=this._processInputParams(t);if(r.parsedType!==Ee.set)return be(r,{code:de.invalid_type,expected:Ee.set,received:r.parsedType}),Re;const o=this._def;o.minSize!==null&&r.data.size<o.minSize.value&&(be(r,{code:de.too_small,minimum:o.minSize.value,type:"set",inclusive:!0,exact:!1,message:o.minSize.message}),e.dirty()),o.maxSize!==null&&r.data.size>o.maxSize.value&&(be(r,{code:de.too_big,maximum:o.maxSize.value,type:"set",inclusive:!0,exact:!1,message:o.maxSize.message}),e.dirty());const a=this._def.valueType;function i(u){const c=new Set;for(const l of u){if(l.status==="aborted")return Re;l.status==="dirty"&&e.dirty(),c.add(l.value)}return{status:e.value,value:c}}const s=[...r.data.values()].map((u,c)=>a._parse(new Qo(r,u,r.path,c)));return r.common.async?Promise.all(s).then(u=>i(u)):i(s)}min(t,e){return new Su({...this._def,minSize:{value:t,message:Pe.toString(e)}})}max(t,e){return new Su({...this._def,maxSize:{value:t,message:Pe.toString(e)}})}size(t,e){return this.min(t,e).max(t,e)}nonempty(t){return this.min(1,t)}}Su.create=(n,t)=>new Su({valueType:n,minSize:null,maxSize:null,typeName:Le.ZodSet,...Ke(t)});class Bx extends tt{get schema(){return this._def.getter()}_parse(t){const{ctx:e}=this._processInputParams(t);return this._def.getter()._parse({data:e.data,path:e.path,parent:e})}}Bx.create=(n,t)=>new Bx({getter:n,typeName:Le.ZodLazy,...Ke(t)});class Kp extends tt{_parse(t){if(t.data!==this._def.value){const e=this._getOrReturnCtx(t);return be(e,{received:e.data,code:de.invalid_literal,expected:this._def.value}),Re}return{status:"valid",value:t.data}}get value(){return this._def.value}}Kp.create=(n,t)=>new Kp({value:n,typeName:Le.ZodLiteral,...Ke(t)});function Wx(n,t){return new Qi({values:n,typeName:Le.ZodEnum,...Ke(t)})}class Qi extends tt{_parse(t){if(typeof t.data!="string"){const e=this._getOrReturnCtx(t),r=this._def.values;return be(e,{expected:st.joinValues(r),received:e.parsedType,code:de.invalid_type}),Re}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(t.data)){const e=this._getOrReturnCtx(t),r=this._def.values;return be(e,{received:e.data,code:de.invalid_enum_value,options:r}),Re}return Qn(t.data)}get options(){return this._def.values}get enum(){const t={};for(const e of this._def.values)t[e]=e;return t}get Values(){const t={};for(const e of this._def.values)t[e]=e;return t}get Enum(){const t={};for(const e of this._def.values)t[e]=e;return t}extract(t,e=this._def){return Qi.create(t,{...this._def,...e})}exclude(t,e=this._def){return Qi.create(this.options.filter(r=>!t.includes(r)),{...this._def,...e})}}Qi.create=Wx;class Vx extends tt{_parse(t){const e=st.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==Ee.string&&r.parsedType!==Ee.number){const o=st.objectValues(e);return be(r,{expected:st.joinValues(o),received:r.parsedType,code:de.invalid_type}),Re}if(this._cache||(this._cache=new Set(st.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){const o=st.objectValues(e);return be(r,{received:r.data,code:de.invalid_enum_value,options:o}),Re}return Qn(t.data)}get enum(){return this._def.values}}Vx.create=(n,t)=>new Vx({values:n,typeName:Le.ZodNativeEnum,...Ke(t)});class Hl extends tt{unwrap(){return this._def.type}_parse(t){const{ctx:e}=this._processInputParams(t);if(e.parsedType!==Ee.promise&&e.common.async===!1)return be(e,{code:de.invalid_type,expected:Ee.promise,received:e.parsedType}),Re;const r=e.parsedType===Ee.promise?e.data:Promise.resolve(e.data);return Qn(r.then(o=>this._def.type.parseAsync(o,{path:e.path,errorMap:e.common.contextualErrorMap})))}}Hl.create=(n,t)=>new Hl({type:n,typeName:Le.ZodPromise,...Ke(t)});class Ji extends tt{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===Le.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){const{status:e,ctx:r}=this._processInputParams(t),o=this._def.effect||null,a={addIssue:i=>{be(r,i),i.fatal?e.abort():e.dirty()},get path(){return r.path}};if(a.addIssue=a.addIssue.bind(a),o.type==="preprocess"){const i=o.transform(r.data,a);if(r.common.async)return Promise.resolve(i).then(async s=>{if(e.value==="aborted")return Re;const u=await this._def.schema._parseAsync({data:s,path:r.path,parent:r});return u.status==="aborted"?Re:u.status==="dirty"||e.value==="dirty"?xu(u.value):u});{if(e.value==="aborted")return Re;const s=this._def.schema._parseSync({data:i,path:r.path,parent:r});return s.status==="aborted"?Re:s.status==="dirty"||e.value==="dirty"?xu(s.value):s}}if(o.type==="refinement"){const i=s=>{const u=o.refinement(s,a);if(r.common.async)return Promise.resolve(u);if(u instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return s};if(r.common.async===!1){const s=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?Re:(s.status==="dirty"&&e.dirty(),i(s.value),{status:e.value,value:s.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(s=>s.status==="aborted"?Re:(s.status==="dirty"&&e.dirty(),i(s.value).then(()=>({status:e.value,value:s.value}))))}if(o.type==="transform")if(r.common.async===!1){const i=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Xi(i))return Re;const s=o.transform(i.value,a);if(s instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:e.value,value:s}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(i=>Xi(i)?Promise.resolve(o.transform(i.value,a)).then(s=>({status:e.value,value:s})):Re);st.assertNever(o)}}Ji.create=(n,t,e)=>new Ji({schema:n,typeName:Le.ZodEffects,effect:t,...Ke(e)}),Ji.createWithPreprocess=(n,t,e)=>new Ji({schema:t,effect:{type:"preprocess",transform:n},typeName:Le.ZodEffects,...Ke(e)});class ta extends tt{_parse(t){return this._getType(t)===Ee.undefined?Qn(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}ta.create=(n,t)=>new ta({innerType:n,typeName:Le.ZodOptional,...Ke(t)});class es extends tt{_parse(t){return this._getType(t)===Ee.null?Qn(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}es.create=(n,t)=>new es({innerType:n,typeName:Le.ZodNullable,...Ke(t)});class Yp extends tt{_parse(t){const{ctx:e}=this._processInputParams(t);let r=e.data;return e.parsedType===Ee.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:e.path,parent:e})}removeDefault(){return this._def.innerType}}Yp.create=(n,t)=>new Yp({innerType:n,typeName:Le.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...Ke(t)});class Xp extends tt{_parse(t){const{ctx:e}=this._processInputParams(t),r={...e,common:{...e.common,issues:[]}},o=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return jl(o)?o.then(a=>({status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new go(r.common.issues)},input:r.data})})):{status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new go(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Xp.create=(n,t)=>new Xp({innerType:n,typeName:Le.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...Ke(t)});class jx extends tt{_parse(t){if(this._getType(t)!==Ee.nan){const r=this._getOrReturnCtx(t);return be(r,{code:de.invalid_type,expected:Ee.nan,received:r.parsedType}),Re}return{status:"valid",value:t.data}}}jx.create=n=>new jx({typeName:Le.ZodNaN,...Ke(n)});class U8 extends tt{_parse(t){const{ctx:e}=this._processInputParams(t),r=e.data;return this._def.type._parse({data:r,path:e.path,parent:e})}unwrap(){return this._def.type}}class Zp extends tt{_parse(t){const{status:e,ctx:r}=this._processInputParams(t);if(r.common.async)return(async()=>{const a=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?Re:a.status==="dirty"?(e.dirty(),xu(a.value)):this._def.out._parseAsync({data:a.value,path:r.path,parent:r})})();{const o=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?Re:o.status==="dirty"?(e.dirty(),{status:"dirty",value:o.value}):this._def.out._parseSync({data:o.value,path:r.path,parent:r})}}static create(t,e){return new Zp({in:t,out:e,typeName:Le.ZodPipeline})}}class Qp extends tt{_parse(t){const e=this._def.innerType._parse(t),r=o=>(Xi(o)&&(o.value=Object.freeze(o.value)),o);return jl(e)?e.then(o=>r(o)):r(e)}unwrap(){return this._def.innerType}}Qp.create=(n,t)=>new Qp({innerType:n,typeName:Le.ZodReadonly,...Ke(t)});function Ux(n,t){const e=typeof n=="function"?n(t):typeof n=="string"?{message:n}:n;return typeof e=="string"?{message:e}:e}function z8(n,t={},e){return n?Eu.create().superRefine((r,o)=>{const a=n(r);if(a instanceof Promise)return a.then(i=>{if(!i){const s=Ux(t,r),u=s.fatal??e??!0;o.addIssue({code:"custom",...s,fatal:u})}});if(!a){const i=Ux(t,r),s=i.fatal??e??!0;o.addIssue({code:"custom",...i,fatal:s})}}):Eu.create()}var Le;(function(n){n.ZodString="ZodString",n.ZodNumber="ZodNumber",n.ZodNaN="ZodNaN",n.ZodBigInt="ZodBigInt",n.ZodBoolean="ZodBoolean",n.ZodDate="ZodDate",n.ZodSymbol="ZodSymbol",n.ZodUndefined="ZodUndefined",n.ZodNull="ZodNull",n.ZodAny="ZodAny",n.ZodUnknown="ZodUnknown",n.ZodNever="ZodNever",n.ZodVoid="ZodVoid",n.ZodArray="ZodArray",n.ZodObject="ZodObject",n.ZodUnion="ZodUnion",n.ZodDiscriminatedUnion="ZodDiscriminatedUnion",n.ZodIntersection="ZodIntersection",n.ZodTuple="ZodTuple",n.ZodRecord="ZodRecord",n.ZodMap="ZodMap",n.ZodSet="ZodSet",n.ZodFunction="ZodFunction",n.ZodLazy="ZodLazy",n.ZodLiteral="ZodLiteral",n.ZodEnum="ZodEnum",n.ZodEffects="ZodEffects",n.ZodNativeEnum="ZodNativeEnum",n.ZodOptional="ZodOptional",n.ZodNullable="ZodNullable",n.ZodDefault="ZodDefault",n.ZodCatch="ZodCatch",n.ZodPromise="ZodPromise",n.ZodBranded="ZodBranded",n.ZodPipeline="ZodPipeline",n.ZodReadonly="ZodReadonly"})(Le||(Le={}));const ts=(n,t={message:`Input not instance of ${n.name}`})=>z8(e=>e instanceof n,t),mt=Jo.create,zx=_u.create;Eu.create,ea.create,Hr.create;const ns=Rt.create;Ul.create,zl.create,qa.create;const H8=Kp.create;Qi.create,Hl.create,ta.create,es.create;const rs=ZD,Hx=k.createContext({}),ut=({...n})=>y.jsx(Hx.Provider,{value:{name:n.name},children:y.jsx(e8,{...n})}),Gl=()=>{const n=k.useContext(Hx),t=k.useContext(Gx),{getFieldState:e,formState:r}=Bl(),o=e(n.name,r);if(!n)throw new Error("useFormField should be used within <FormField>");const{id:a}=t;return{id:a,name:n.name,formItemId:`${a}-form-item`,formDescriptionId:`${a}-form-item-description`,formMessageId:`${a}-form-item-message`,...o}},Gx=k.createContext({}),nt=k.forwardRef(({className:n,...t},e)=>{const r=k.useId();return y.jsx(Gx.Provider,{value:{id:r},children:y.jsx("div",{ref:e,className:Be("space-y-2",n),...t})})});nt.displayName="FormItem";const rt=k.forwardRef(({className:n,...t},e)=>{const{error:r,formItemId:o}=Gl();return y.jsx(Pa,{ref:e,className:Be(r&&"text-destructive",n),htmlFor:o,...t})});rt.displayName="FormLabel";const ot=k.forwardRef(({...n},t)=>{const{error:e,formItemId:r,formDescriptionId:o,formMessageId:a}=Gl();return y.jsx(qm,{ref:t,id:r,"aria-describedby":e?`${o} ${a}`:`${o}`,"aria-invalid":!!e,...n})});ot.displayName="FormControl";const G8=k.forwardRef(({className:n,...t},e)=>{const{formDescriptionId:r}=Gl();return y.jsx("p",{ref:e,id:r,className:Be("text-sm text-muted-foreground",n),...t})});G8.displayName="FormDescription";const at=k.forwardRef(({className:n,children:t,...e},r)=>{const{error:o,formMessageId:a}=Gl(),i=o?String(o==null?void 0:o.message):t;return i?y.jsx("p",{ref:r,id:a,className:Be("text-sm font-medium text-destructive",n),...e,children:i}):null});at.displayName="FormMessage";const q8=ns({bank_statement:ts(File).optional().refine(n=>n!==void 0,"Bank statement is required"),company_structure:ts(File).optional().refine(n=>n!==void 0,"Company structure document is required"),certificate_of_registration:ts(File).optional().refine(n=>n!==void 0,"Certificate of registration is required")}),K8=({data:n,onDataChange:t,onContinue:e,onBack:r,renderProgress:o})=>{const a=D.useRef(null),i=D.useRef(null),s=D.useRef(null),u=Ki({resolver:Yi(q8),defaultValues:{bank_statement:n.bank_statement||void 0,company_structure:n.company_structure||void 0,certificate_of_registration:n.certificate_of_registration||void 0}}),c=f=>{t(f),e()},l=(f,h)=>{u.setValue(f,h),t({[f]:h})},d=({field:f,label:h,description:m,inputRef:v})=>{const p=u.watch(f);return y.jsx(ut,{control:u.control,name:f,render:()=>y.jsxs(nt,{children:[y.jsx(rt,{children:h}),y.jsx(ot,{children:y.jsxs("div",{className:"border-2 border-dashed border-muted-foreground/25 rounded-lg p-6",children:[y.jsx("input",{ref:v,type:"file",accept:".pdf,.jpg,.jpeg,.png,.doc,.docx",className:"hidden",onChange:g=>{var w;const b=((w=g.target.files)==null?void 0:w[0])||null;l(f,b)}}),p?y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsxs("div",{className:"flex items-center space-x-2",children:[y.jsx(Tg,{className:"w-5 h-5 text-primary"}),y.jsx("span",{className:"text-sm font-medium",children:p.name})]}),y.jsx(_t,{type:"button",variant:"ghost",size:"sm",onClick:()=>{l(f,null),v.current&&(v.current.value="")},children:y.jsx(hc,{className:"w-4 h-4"})})]}):y.jsxs("div",{className:"text-center cursor-pointer",onClick:()=>{var g;return(g=v.current)==null?void 0:g.click()},children:[y.jsx(Og,{className:"w-8 h-8 mx-auto mb-2 text-muted-foreground"}),y.jsx("p",{className:"font-medium",children:h}),y.jsx("p",{className:"text-sm text-muted-foreground",children:m}),y.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Supported: PDF, JPG, PNG, DOC, DOCX"})]})]})}),y.jsx(at,{})]})})};return y.jsxs(un,{className:"w-full max-w-2xl mx-auto",children:[y.jsx(no,{children:y.jsx(ro,{title:"Company Documents",subTitle:"Please upload the required company documents",onBack:r})}),y.jsxs(cn,{children:[y.jsx(rs,{...u,children:y.jsxs("form",{onSubmit:u.handleSubmit(c),className:"space-y-6",children:[y.jsx(d,{field:"bank_statement",label:"Bank Statement",description:"Upload your latest bank statement",inputRef:a}),y.jsx(d,{field:"company_structure",label:"Company Structure",description:"Upload document showing directors & legal representatives",inputRef:i}),y.jsx(d,{field:"certificate_of_registration",label:"Certificate of Registration",description:"Upload your company's certificate of registration",inputRef:s}),y.jsx(_t,{type:"submit",className:"w-full",children:"Complete Verification"})]})}),y.jsx("div",{className:"mt-6",children:o()})]})]})};function qx(n,[t,e]){return Math.min(e,Math.max(t,n))}var Y8=k.createContext(void 0);function X8(n){const t=k.useContext(Y8);return n||t||"ltr"}var Jp=0;function Kx(){k.useEffect(()=>{const n=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",n[0]??Yx()),document.body.insertAdjacentElement("beforeend",n[1]??Yx()),Jp++,()=>{Jp===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Jp--}},[])}function Yx(){const n=document.createElement("span");return n.setAttribute("data-radix-focus-guard",""),n.tabIndex=0,n.style.outline="none",n.style.opacity="0",n.style.position="fixed",n.style.pointerEvents="none",n}var ev="focusScope.autoFocusOnMount",tv="focusScope.autoFocusOnUnmount",Xx={bubbles:!1,cancelable:!0},Z8="FocusScope",nv=k.forwardRef((n,t)=>{const{loop:e=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:a,...i}=n,[s,u]=k.useState(null),c=tr(o),l=tr(a),d=k.useRef(null),f=Ct(t,v=>u(v)),h=k.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;k.useEffect(()=>{if(r){let v=function(w){if(h.paused||!s)return;const x=w.target;s.contains(x)?d.current=x:na(d.current,{select:!0})},p=function(w){if(h.paused||!s)return;const x=w.relatedTarget;x!==null&&(s.contains(x)||na(d.current,{select:!0}))},g=function(w){if(document.activeElement===document.body)for(const C of w)C.removedNodes.length>0&&na(s)};document.addEventListener("focusin",v),document.addEventListener("focusout",p);const b=new MutationObserver(g);return s&&b.observe(s,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",p),b.disconnect()}}},[r,s,h.paused]),k.useEffect(()=>{if(s){Jx.add(h);const v=document.activeElement;if(!s.contains(v)){const g=new CustomEvent(ev,Xx);s.addEventListener(ev,c),s.dispatchEvent(g),g.defaultPrevented||(Q8(rF(Zx(s)),{select:!0}),document.activeElement===v&&na(s))}return()=>{s.removeEventListener(ev,c),setTimeout(()=>{const g=new CustomEvent(tv,Xx);s.addEventListener(tv,l),s.dispatchEvent(g),g.defaultPrevented||na(v??document.body,{select:!0}),s.removeEventListener(tv,l),Jx.remove(h)},0)}}},[s,c,l,h]);const m=k.useCallback(v=>{if(!e&&!r||h.paused)return;const p=v.key==="Tab"&&!v.altKey&&!v.ctrlKey&&!v.metaKey,g=document.activeElement;if(p&&g){const b=v.currentTarget,[w,x]=J8(b);w&&x?!v.shiftKey&&g===x?(v.preventDefault(),e&&na(w,{select:!0})):v.shiftKey&&g===w&&(v.preventDefault(),e&&na(x,{select:!0})):g===b&&v.preventDefault()}},[e,r,h.paused]);return y.jsx(et.div,{tabIndex:-1,...i,ref:f,onKeyDown:m})});nv.displayName=Z8;function Q8(n,{select:t=!1}={}){const e=document.activeElement;for(const r of n)if(na(r,{select:t}),document.activeElement!==e)return}function J8(n){const t=Zx(n),e=Qx(t,n),r=Qx(t.reverse(),n);return[e,r]}function Zx(n){const t=[],e=document.createTreeWalker(n,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;e.nextNode();)t.push(e.currentNode);return t}function Qx(n,t){for(const e of n)if(!eF(e,{upTo:t}))return e}function eF(n,{upTo:t}){if(getComputedStyle(n).visibility==="hidden")return!0;for(;n;){if(t!==void 0&&n===t)return!1;if(getComputedStyle(n).display==="none")return!0;n=n.parentElement}return!1}function tF(n){return n instanceof HTMLInputElement&&"select"in n}function na(n,{select:t=!1}={}){if(n&&n.focus){const e=document.activeElement;n.focus({preventScroll:!0}),n!==e&&tF(n)&&t&&n.select()}}var Jx=nF();function nF(){let n=[];return{add(t){const e=n[0];t!==e&&(e==null||e.pause()),n=ew(n,t),n.unshift(t)},remove(t){var e;n=ew(n,t),(e=n[0])==null||e.resume()}}}function ew(n,t){const e=[...n],r=e.indexOf(t);return r!==-1&&e.splice(r,1),e}function rF(n){return n.filter(t=>t.tagName!=="A")}function oF(n){const t=k.useRef({value:n,previous:n});return k.useMemo(()=>(t.current.value!==n&&(t.current.previous=t.current.value,t.current.value=n),t.current.previous),[n])}var aF=function(n){if(typeof document>"u")return null;var t=Array.isArray(n)?n[0]:n;return t.ownerDocument.body},os=new WeakMap,ql=new WeakMap,Kl={},rv=0,tw=function(n){return n&&(n.host||tw(n.parentNode))},iF=function(n,t){return t.map(function(e){if(n.contains(e))return e;var r=tw(e);return r&&n.contains(r)?r:(console.error("aria-hidden",e,"in not contained inside",n,". Doing nothing"),null)}).filter(function(e){return!!e})},sF=function(n,t,e,r){var o=iF(t,Array.isArray(n)?n:[n]);Kl[e]||(Kl[e]=new WeakMap);var a=Kl[e],i=[],s=new Set,u=new Set(o),c=function(d){!d||s.has(d)||(s.add(d),c(d.parentNode))};o.forEach(c);var l=function(d){!d||u.has(d)||Array.prototype.forEach.call(d.children,function(f){if(s.has(f))l(f);else try{var h=f.getAttribute(r),m=h!==null&&h!=="false",v=(os.get(f)||0)+1,p=(a.get(f)||0)+1;os.set(f,v),a.set(f,p),i.push(f),v===1&&m&&ql.set(f,!0),p===1&&f.setAttribute(e,"true"),m||f.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",f,g)}})};return l(t),s.clear(),rv++,function(){i.forEach(function(d){var f=os.get(d)-1,h=a.get(d)-1;os.set(d,f),a.set(d,h),f||(ql.has(d)||d.removeAttribute(r),ql.delete(d)),h||d.removeAttribute(e)}),rv--,rv||(os=new WeakMap,os=new WeakMap,ql=new WeakMap,Kl={})}},nw=function(n,t,e){e===void 0&&(e="data-aria-hidden");var r=Array.from(Array.isArray(n)?n:[n]),o=aF(n);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),sF(r,o,e,"aria-hidden")):function(){return null}},Gr=function(){return Gr=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++){e=arguments[r];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a])}return t},Gr.apply(this,arguments)};function rw(n,t){var e={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(n);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(n,r[o])&&(e[r[o]]=n[r[o]]);return e}function uF(n,t,e){if(e||arguments.length===2)for(var r=0,o=t.length,a;r<o;r++)(a||!(r in t))&&(a||(a=Array.prototype.slice.call(t,0,r)),a[r]=t[r]);return n.concat(a||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var Yl="right-scroll-bar-position",Xl="width-before-scroll-bar",cF="with-scroll-bars-hidden",lF="--removed-body-scroll-bar-size";function ov(n,t){return typeof n=="function"?n(t):n&&(n.current=t),n}function dF(n,t){var e=D.useState(function(){return{value:n,callback:t,facade:{get current(){return e.value},set current(r){var o=e.value;o!==r&&(e.value=r,e.callback(r,o))}}}})[0];return e.callback=t,e.facade}var fF=typeof window<"u"?k.useLayoutEffect:k.useEffect,ow=new WeakMap;function hF(n,t){var e=dF(null,function(r){return n.forEach(function(o){return ov(o,r)})});return fF(function(){var r=ow.get(e);if(r){var o=new Set(r),a=new Set(n),i=e.current;o.forEach(function(s){a.has(s)||ov(s,null)}),a.forEach(function(s){o.has(s)||ov(s,i)})}ow.set(e,n)},[n]),e}function pF(n){return n}function vF(n,t){t===void 0&&(t=pF);var e=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return e.length?e[e.length-1]:n},useMedium:function(a){var i=t(a,r);return e.push(i),function(){e=e.filter(function(s){return s!==i})}},assignSyncMedium:function(a){for(r=!0;e.length;){var i=e;e=[],i.forEach(a)}e={push:function(s){return a(s)},filter:function(){return e}}},assignMedium:function(a){r=!0;var i=[];if(e.length){var s=e;e=[],s.forEach(a),i=e}var u=function(){var l=i;i=[],l.forEach(a)},c=function(){return Promise.resolve().then(u)};c(),e={push:function(l){i.push(l),c()},filter:function(l){return i=i.filter(l),e}}}};return o}function mF(n){n===void 0&&(n={});var t=vF(null);return t.options=Gr({async:!0,ssr:!1},n),t}var aw=function(n){var t=n.sideCar,e=rw(n,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return k.createElement(r,Gr({},e))};aw.isSideCarExport=!0;function gF(n,t){return n.useMedium(t),aw}var iw=mF(),av=function(){},Zl=k.forwardRef(function(n,t){var e=k.useRef(null),r=k.useState({onScrollCapture:av,onWheelCapture:av,onTouchMoveCapture:av}),o=r[0],a=r[1],i=n.forwardProps,s=n.children,u=n.className,c=n.removeScrollBar,l=n.enabled,d=n.shards,f=n.sideCar,h=n.noRelative,m=n.noIsolation,v=n.inert,p=n.allowPinchZoom,g=n.as,b=g===void 0?"div":g,w=n.gapMode,x=rw(n,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=f,_=hF([e,t]),E=Gr(Gr({},x),o);return k.createElement(k.Fragment,null,l&&k.createElement(C,{sideCar:iw,removeScrollBar:c,shards:d,noRelative:h,noIsolation:m,inert:v,setCallbacks:a,allowPinchZoom:!!p,lockRef:e,gapMode:w}),i?k.cloneElement(k.Children.only(s),Gr(Gr({},E),{ref:_})):k.createElement(b,Gr({},E,{className:u,ref:_}),s))});Zl.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Zl.classNames={fullWidth:Xl,zeroRight:Yl};var yF=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function bF(){if(!document)return null;var n=document.createElement("style");n.type="text/css";var t=yF();return t&&n.setAttribute("nonce",t),n}function xF(n,t){n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}function wF(n){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(n)}var CF=function(){var n=0,t=null;return{add:function(e){n==0&&(t=bF())&&(xF(t,e),wF(t)),n++},remove:function(){n--,!n&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},_F=function(){var n=CF();return function(t,e){k.useEffect(function(){return n.add(t),function(){n.remove()}},[t&&e])}},sw=function(){var n=_F(),t=function(e){var r=e.styles,o=e.dynamic;return n(r,o),null};return t},EF={left:0,top:0,right:0,gap:0},iv=function(n){return parseInt(n||"",10)||0},SF=function(n){var t=window.getComputedStyle(document.body),e=t[n==="padding"?"paddingLeft":"marginLeft"],r=t[n==="padding"?"paddingTop":"marginTop"],o=t[n==="padding"?"paddingRight":"marginRight"];return[iv(e),iv(r),iv(o)]},NF=function(n){if(n===void 0&&(n="margin"),typeof window>"u")return EF;var t=SF(n),e=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-e+t[2]-t[0])}},$F=sw(),as="data-scroll-locked",kF=function(n,t,e,r){var o=n.left,a=n.top,i=n.right,s=n.gap;return e===void 0&&(e="margin"),`
3929
+ ***************************************************************************** */var Gh=function(n,t){return Gh=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o])},Gh(n,t)};function De(n,t){Gh(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}var pn=function(){return pn=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++){e=arguments[r];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a])}return t},pn.apply(this,arguments)};function $e(n,t,e,r){function o(a){return a instanceof e?a:new e(function(i){i(a)})}return new(e||(e=Promise))(function(a,i){function s(l){try{c(r.next(l))}catch(d){i(d)}}function u(l){try{c(r.throw(l))}catch(d){i(d)}}function c(l){l.done?a(l.value):o(l.value).then(s,u)}c((r=r.apply(n,[])).next())})}function ke(n,t){var e={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,o,a,i;return i={next:s(0),throw:s(1),return:s(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function s(c){return function(l){return u([c,l])}}function u(c){if(r)throw new TypeError("Generator is already executing.");for(;e;)try{if(r=1,o&&(a=c[0]&2?o.return:c[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,c[1])).done)return a;switch(o=0,a&&(c=[c[0]&2,a.value]),c[0]){case 0:case 1:a=c;break;case 4:return e.label++,{value:c[1],done:!1};case 5:e.label++,o=c[1],c=[0];continue;case 7:c=e.ops.pop(),e.trys.pop();continue;default:if(a=e.trys,!(a=a.length>0&&a[a.length-1])&&(c[0]===6||c[0]===2)){e=0;continue}if(c[0]===3&&(!a||c[1]>a[0]&&c[1]<a[3])){e.label=c[1];break}if(c[0]===6&&e.label<a[1]){e.label=a[1],a=c;break}if(a&&e.label<a[2]){e.label=a[2],e.ops.push(c);break}a[2]&&e.ops.pop(),e.trys.pop();continue}c=t.call(n,e)}catch(l){c=[6,l],o=0}finally{r=a=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}function lu(){for(var n=0,t=0,e=arguments.length;t<e;t++)n+=arguments[t].length;for(var r=Array(n),o=0,t=0;t<e;t++)for(var a=arguments[t],i=0,s=a.length;i<s;i++,o++)r[o]=a[i];return r}var Vi=function(){function n(t,e){if(!Ua(t)||!Ua(e))throw new Error("Dimensions.constructor - expected width and height to be valid numbers, instead have "+JSON.stringify({width:t,height:e}));this._width=t,this._height=e}return Object.defineProperty(n.prototype,"width",{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this._height},enumerable:!0,configurable:!0}),n.prototype.reverse=function(){return new n(1/this.width,1/this.height)},n}();function bl(n,t){return n instanceof Nt&&n.shape.length===t}function h5(n){return bl(n,2)}function xl(n){return bl(n,3)}function Ho(n){return bl(n,4)}function p5(n){return n%1!==0}function qb(n){return n%2===0}function v5(n,t){t===void 0&&(t=2);var e=Math.pow(10,t);return Math.floor(n*e)/e}function Kb(n){return n&&n.width&&n.height}function m5(n,t){var e=n.width,r=n.height,o=t/Math.max(r,e);return new Vi(Math.round(e*o),Math.round(r*o))}function qh(n){return n.reduce(function(t,e){return t.add(e)},new ct(0,0)).div(new ct(n.length,n.length))}function du(n,t,e){return Array(n).fill(0).map(function(r,o){return t+o*e})}function Ua(n){return!!n&&n!==1/0&&n!==-1/0&&!isNaN(n)||n===0}function Yb(n){return Ua(n)&&0<=n&&n<=1}var ct=function(){function n(t,e){this._x=t,this._y=e}return Object.defineProperty(n.prototype,"x",{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"y",{get:function(){return this._y},enumerable:!0,configurable:!0}),n.prototype.add=function(t){return new n(this.x+t.x,this.y+t.y)},n.prototype.sub=function(t){return new n(this.x-t.x,this.y-t.y)},n.prototype.mul=function(t){return new n(this.x*t.x,this.y*t.y)},n.prototype.div=function(t){return new n(this.x/t.x,this.y/t.y)},n.prototype.abs=function(){return new n(Math.abs(this.x),Math.abs(this.y))},n.prototype.magnitude=function(){return Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2))},n.prototype.floor=function(){return new n(Math.floor(this.x),Math.floor(this.y))},n}(),Go=function(){function n(t,e){e===void 0&&(e=!0);var r=t||{},o=[r.left,r.top,r.right,r.bottom].every(Ua),a=[r.x,r.y,r.width,r.height].every(Ua);if(!a&&!o)throw new Error("Box.constructor - expected box to be IBoundingBox | IRect, instead have "+JSON.stringify(r));var i=a?[r.x,r.y,r.width,r.height]:[r.left,r.top,r.right-r.left,r.bottom-r.top],s=i[0],u=i[1],c=i[2],l=i[3];n.assertIsValidBox({x:s,y:u,width:c,height:l},"Box.constructor",e),this._x=s,this._y=u,this._width=c,this._height=l}return n.isRect=function(t){return!!t&&[t.x,t.y,t.width,t.height].every(Ua)},n.assertIsValidBox=function(t,e,r){if(r===void 0&&(r=!1),!n.isRect(t))throw new Error(e+" - invalid box: "+JSON.stringify(t)+", expected object with properties x, y, width, height");if(!r&&(t.width<0||t.height<0))throw new Error(e+" - width ("+t.width+") and height ("+t.height+") must be positive numbers")},Object.defineProperty(n.prototype,"x",{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"y",{get:function(){return this._y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"width",{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this._height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"area",{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"topLeft",{get:function(){return new ct(this.left,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"topRight",{get:function(){return new ct(this.right,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bottomLeft",{get:function(){return new ct(this.left,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bottomRight",{get:function(){return new ct(this.right,this.bottom)},enumerable:!0,configurable:!0}),n.prototype.round=function(){var t=[this.x,this.y,this.width,this.height].map(function(i){return Math.round(i)}),e=t[0],r=t[1],o=t[2],a=t[3];return new n({x:e,y:r,width:o,height:a})},n.prototype.floor=function(){var t=[this.x,this.y,this.width,this.height].map(function(i){return Math.floor(i)}),e=t[0],r=t[1],o=t[2],a=t[3];return new n({x:e,y:r,width:o,height:a})},n.prototype.toSquare=function(){var t=this,e=t.x,r=t.y,o=t.width,a=t.height,i=Math.abs(o-a);return o<a&&(e-=i/2,o+=i),a<o&&(r-=i/2,a+=i),new n({x:e,y:r,width:o,height:a})},n.prototype.rescale=function(t){var e=Kb(t)?t.width:t,r=Kb(t)?t.height:t;return new n({x:this.x*e,y:this.y*r,width:this.width*e,height:this.height*r})},n.prototype.pad=function(t,e){var r=[this.x-t/2,this.y-e/2,this.width+t,this.height+e],o=r[0],a=r[1],i=r[2],s=r[3];return new n({x:o,y:a,width:i,height:s})},n.prototype.clipAtImageBorders=function(t,e){var r=this,o=r.x,a=r.y,i=r.right,s=r.bottom,u=Math.max(o,0),c=Math.max(a,0),l=i-u,d=s-c,f=Math.min(l,t-u),h=Math.min(d,e-c);return new n({x:u,y:c,width:f,height:h}).floor()},n.prototype.shift=function(t,e){var r=this,o=r.width,a=r.height,i=this.x+t,s=this.y+e;return new n({x:i,y:s,width:o,height:a})},n.prototype.padAtBorders=function(t,e){var r=this.width+1,o=this.height+1,a=1,i=1,s=r,u=o,c=this.left,l=this.top,d=this.right,f=this.bottom;return d>e&&(s=-d+e+r,d=e),f>t&&(u=-f+t+o,f=t),c<1&&(u=2-c,c=1),l<1&&(u=2-l,l=1),{dy:i,edy:u,dx:a,edx:s,y:l,ey:f,x:c,ex:d,w:r,h:o}},n.prototype.calibrate=function(t){return new n({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()},n}(),wl=function(n){De(t,n);function t(e,r,o,a,i){return i===void 0&&(i=!1),n.call(this,{left:e,top:r,right:o,bottom:a},i)||this}return t}(Go),Xb=function(){function n(t,e,r,o,a){this._imageDims=new Vi(a.width,a.height),this._score=t,this._classScore=e,this._className=r,this._box=new Go(o).rescale(this._imageDims)}return Object.defineProperty(n.prototype,"score",{get:function(){return this._score},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"classScore",{get:function(){return this._classScore},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"className",{get:function(){return this._className},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"box",{get:function(){return this._box},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"imageDims",{get:function(){return this._imageDims},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"imageWidth",{get:function(){return this.imageDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"imageHeight",{get:function(){return this.imageDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"relativeBox",{get:function(){return new Go(this._box).rescale(this.imageDims.reverse())},enumerable:!0,configurable:!0}),n.prototype.forSize=function(t,e){return new n(this.score,this.classScore,this.className,this.relativeBox,{width:t,height:e})},n}(),Wr=function(n){De(t,n);function t(e,r,o){return n.call(this,e,e,"",r,o)||this}return t.prototype.forSize=function(e,r){var o=n.prototype.forSize.call(this,e,r),a=o.score,i=o.relativeBox,s=o.imageDims;return new t(a,i,s)},t}(Xb);function g5(n,t,e){e===void 0&&(e=!0);var r=Math.max(0,Math.min(n.right,t.right)-Math.max(n.left,t.left)),o=Math.max(0,Math.min(n.bottom,t.bottom)-Math.max(n.top,t.top)),a=r*o;return e?a/(n.area+t.area-a):a/Math.min(n.area,t.area)}function y5(n){var t=n.map(function(s){return s.x}),e=n.map(function(s){return s.y}),r=t.reduce(function(s,u){return u<s?u:s},1/0),o=e.reduce(function(s,u){return u<s?u:s},1/0),a=t.reduce(function(s,u){return s<u?u:s},0),i=e.reduce(function(s,u){return s<u?u:s},0);return new wl(r,o,a,i)}function fu(n,t,e,r){r===void 0&&(r=!0);for(var o=t.map(function(s,u){return{score:s,boxIndex:u}}).sort(function(s,u){return s.score-u.score}).map(function(s){return s.boxIndex}),a=[],i=function(){var s=o.pop();a.push(s);for(var u=o,c=[],l=0;l<u.length;l++){var d=u[l],f=n[s],h=n[d];c.push(g5(f,h,r))}o=o.filter(function(m,v){return c[v]<=e})};o.length>0;)i();return a}function hu(n,t){return xe(function(){var e=t[0],r=t[1],o=t[2],a=Lr(lu(n.shape.slice(0,3),[1]),e),i=Lr(lu(n.shape.slice(0,3),[1]),r),s=Lr(lu(n.shape.slice(0,3),[1]),o),u=jt([a,i,s],3);return Ht(n,u)})}function b5(n,t){return t===void 0&&(t=!1),xe(function(){var e=n.shape.slice(1),r=e[0],o=e[1];if(r===o)return n;var a=Math.abs(r-o),i=Math.round(a*(t?.5:1)),s=r>o?2:1,u=function(h){var m=n.shape.slice();return m[s]=h,Lr(m,0)},c=u(i),l=a-c.shape[s],d=t&&l?u(l):null,f=[d,n,c].filter(function(h){return!!h}).map(function(h){return h.toFloat()});return jt(f,s)})}function Kh(n){return 1/(1+Math.exp(-n))}var Yh=function(n){De(t,n);function t(e,r,o,a,i){return i===void 0&&(i=!1),n.call(this,{x:e,y:r,width:o,height:a},i)||this}return t}(Go),x5=.5,w5=.43,C5=.45,Cl=function(){function n(t,e,r){r===void 0&&(r=new ct(0,0));var o=e.width,a=e.height;this._imgDims=new Vi(o,a),this._shift=r,this._positions=t.map(function(i){return i.mul(new ct(o,a)).add(r)})}return Object.defineProperty(n.prototype,"shift",{get:function(){return new ct(this._shift.x,this._shift.y)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"imageWidth",{get:function(){return this._imgDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"imageHeight",{get:function(){return this._imgDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"positions",{get:function(){return this._positions},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"relativePositions",{get:function(){var t=this;return this._positions.map(function(e){return e.sub(t._shift).div(new ct(t.imageWidth,t.imageHeight))})},enumerable:!0,configurable:!0}),n.prototype.forSize=function(t,e){return new this.constructor(this.relativePositions,{width:t,height:e})},n.prototype.shiftBy=function(t,e){return new this.constructor(this.relativePositions,this._imgDims,new ct(t,e))},n.prototype.shiftByPoint=function(t){return this.shiftBy(t.x,t.y)},n.prototype.align=function(t,e){if(e===void 0&&(e={}),t){var r=t instanceof Wr?t.box.floor():new Go(t);return this.shiftBy(r.x,r.y).align(null,e)}var o=Object.assign({},{useDlibAlignment:!1,minBoxPadding:.2},e),a=o.useDlibAlignment,i=o.minBoxPadding;return a?this.alignDlib():this.alignMinBbox(i)},n.prototype.alignDlib=function(){var t=this.getRefPointsForAlignment(),e=t[0],r=t[1],o=t[2],a=function(d){return o.sub(d).magnitude()},i=(a(e)+a(r))/2,s=Math.floor(i/C5),u=qh(t),c=Math.floor(Math.max(0,u.x-x5*s)),l=Math.floor(Math.max(0,u.y-w5*s));return new Yh(c,l,Math.min(s,this.imageWidth+c),Math.min(s,this.imageHeight+l))},n.prototype.alignMinBbox=function(t){var e=y5(this.positions);return e.pad(e.width*t,e.height*t)},n.prototype.getRefPointsForAlignment=function(){throw new Error("getRefPointsForAlignment not implemented by base class")},n}(),_5=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.getRefPointsForAlignment=function(){var e=this.positions;return[e[0],e[1],qh([e[3],e[4]])]},t}(Cl),E5=function(n){De(t,n);function t(){return n!==null&&n.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(qh)},t}(Cl),Zb=function(){function n(t,e){this._label=t,this._distance=e}return Object.defineProperty(n.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"distance",{get:function(){return this._distance},enumerable:!0,configurable:!0}),n.prototype.toString=function(t){return t===void 0&&(t=!0),""+this.label+(t?" ("+v5(this.distance)+")":"")},n}(),Qb=function(n){De(t,n);function t(e,r){var o=n.call(this,e)||this;return o._label=r,o}return t.assertIsValidLabeledBox=function(e,r){if(Go.assertIsValidBox(e,r),!Ua(e.label))throw new Error(r+" - expected property label ("+e.label+") to be a number")},Object.defineProperty(t.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),t}(Go),_l=function(){function n(t,e){if(typeof t!="string")throw new Error("LabeledFaceDescriptors - constructor expected label to be a string");if(!Array.isArray(e)||e.some(function(r){return!(r instanceof Float32Array)}))throw new Error("LabeledFaceDescriptors - constructor expected descriptors to be an array of Float32Array");this._label=t,this._descriptors=e}return Object.defineProperty(n.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"descriptors",{get:function(){return this._descriptors},enumerable:!0,configurable:!0}),n.prototype.toJSON=function(){return{label:this.label,descriptors:this.descriptors.map(function(t){return Array.from(t)})}},n.fromJSON=function(t){var e=t.descriptors.map(function(r){return new Float32Array(r)});return new n(t.label,e)},n}();(function(n){De(t,n);function t(e,r,o,a){var i=n.call(this,e,r)||this;return i._score=o,i._classScore=a,i}return t.assertIsValidPredictedBox=function(e,r){if(Qb.assertIsValidLabeledBox(e,r),!Yb(e.score)||!Yb(e.classScore))throw new Error(r+" - 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})(Qb);function S5(n){return n.detection instanceof Wr}function Xh(n,t){var e={detection:t};return Object.assign({},n,e)}function Jb(){var n=window.fetch||function(){throw new Error("fetch - missing fetch implementation for browser environment")},t=function(){throw new Error("readFile - filesystem not available 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:n,readFile:t}}function e2(n){var t="";if(!n)try{n=require("fs")}catch(r){t=r.toString()}var e=n?function(r){return new Promise(function(o,a){n.readFile(r,function(i,s){return i?a(i):o(s)})})}:function(){throw new Error("readFile - failed to require fs in nodejs environment with error: "+t)};return{readFile:e}}function t2(){var n=global.Canvas||global.HTMLCanvasElement,t=global.Image||global.HTMLImageElement,e=function(){if(n)return new n;throw new Error("createCanvasElement - missing Canvas implementation for nodejs environment")},r=function(){if(t)return new t;throw new Error("createImageElement - missing Image implementation for nodejs environment")},o=global.fetch||function(){throw new Error("fetch - missing fetch implementation for nodejs environment")},a=e2();return pn({Canvas:n||function(){function i(){}return i}(),CanvasRenderingContext2D:global.CanvasRenderingContext2D||function(){function i(){}return i}(),Image:t||function(){function i(){}return i}(),ImageData:global.ImageData||function(){function i(){}return i}(),Video:global.HTMLVideoElement||function(){function i(){}return i}(),createCanvasElement:e,createImageElement:r,fetch:o},a)}function n2(){return typeof window=="object"&&typeof document<"u"&&typeof HTMLImageElement<"u"&&typeof HTMLCanvasElement<"u"&&typeof HTMLVideoElement<"u"&&typeof ImageData<"u"&&typeof CanvasRenderingContext2D<"u"}function r2(){return typeof global=="object"&&typeof require=="function"&&typeof module<"u"&&typeof process<"u"&&!!process.version}var Gt;function N5(){if(!Gt)throw new Error("getEnv - environment is not defined, check isNodejs() and isBrowser()");return Gt}function Zh(n){Gt=n}function Qh(){n2()&&Zh(Jb()),r2()&&Zh(t2())}function $5(n){if(Gt||Qh(),!Gt)throw new Error("monkeyPatch - environment is not defined, check isNodejs() and isBrowser()");var t=n.Canvas,e=t===void 0?Gt.Canvas:t,r=n.Image,o=r===void 0?Gt.Image:r;Gt.Canvas=e,Gt.Image=o,Gt.createCanvasElement=n.createCanvasElement||function(){return new e},Gt.createImageElement=n.createImageElement||function(){return new o},Gt.ImageData=n.ImageData||Gt.ImageData,Gt.Video=n.Video||Gt.Video,Gt.fetch=n.fetch||Gt.fetch,Gt.readFile=n.readFile||Gt.readFile}var on={getEnv:N5,setEnv:Zh,initialize:Qh,createBrowserEnv:Jb,createFileSystem:e2,createNodejsEnv:t2,monkeyPatch:$5,isBrowser:n2,isNodejs:r2};Qh();function o2(n){return!on.isNodejs()&&typeof n=="string"?document.getElementById(n):n}function za(n){var t=on.getEnv(),e=t.Canvas,r=t.CanvasRenderingContext2D;if(n instanceof r)return n;var o=o2(n);if(!(o instanceof e))throw new Error("resolveContext2d - expected canvas to be of instance of Canvas");var a=o.getContext("2d");if(!a)throw new Error("resolveContext2d - canvas 2d context is null");return a}var a2;(function(n){n.TOP_LEFT="TOP_LEFT",n.TOP_RIGHT="TOP_RIGHT",n.BOTTOM_LEFT="BOTTOM_LEFT",n.BOTTOM_RIGHT="BOTTOM_RIGHT"})(a2||(a2={}));function i2(n){var t=on.getEnv(),e=t.Image,r=t.Video;return n instanceof e&&n.complete||n instanceof r&&n.readyState>=3}function k5(n){return new Promise(function(t,e){if(n instanceof on.getEnv().Canvas||i2(n))return t();function r(a){a.currentTarget&&(a.currentTarget.removeEventListener("load",r),a.currentTarget.removeEventListener("error",o),t(a))}function o(a){a.currentTarget&&(a.currentTarget.removeEventListener("load",r),a.currentTarget.removeEventListener("error",o),e(a))}n.addEventListener("load",r),n.addEventListener("error",o)})}function s2(n){var t=on.getEnv(),e=t.Image,r=t.Video;return n instanceof e?new Vi(n.naturalWidth,n.naturalHeight):n instanceof r?new Vi(n.videoWidth,n.videoHeight):new Vi(n.width,n.height)}function El(n){var t=n.width,e=n.height,r=on.getEnv().createCanvasElement,o=r();return o.width=t,o.height=e,o}function Jh(n,t){var e=on.getEnv().ImageData;if(!(n instanceof e)&&!i2(n))throw new Error("createCanvasFromMedia - media has not finished loading yet");var r=s2(n),o=r.width,a=r.height,i=El({width:o,height:a});return n instanceof e?za(i).putImageData(n,0,0):za(i).drawImage(n,0,0,o,a),i}function P5(n,t){return $e(this,void 0,void 0,function(){var e,r,o,a,i,s;return ke(this,function(u){switch(u.label){case 0:return e=on.getEnv().createCanvasElement(),r=n.shape.slice(Ho(n)?1:0),o=r[0],a=r[1],i=r[2],s=xe(function(){return n.as3D(o,a,i).toInt()}),[4,Hh.toPixels(s,e)];case 1:return u.sent(),s.dispose(),[2,e]}})})}function u2(n){var t=on.getEnv(),e=t.Image,r=t.Canvas,o=t.Video;return n instanceof e||n instanceof r||n instanceof o}function I5(n,t,e){e===void 0&&(e=!1);var r=on.getEnv(),o=r.Image,a=r.Canvas;if(!(n instanceof o||n instanceof a))throw new Error("imageToSquare - expected arg0 to be HTMLImageElement | HTMLCanvasElement");var i=s2(n),s=t/Math.max(i.height,i.width),u=s*i.width,c=s*i.height,l=El({width:t,height:t}),d=n instanceof a?n:Jh(n),f=Math.abs(u-c)/2,h=e&&u<c?f:0,m=e&&c<u?f:0;return za(l).drawImage(d,h,m,u,c),l}var Sl=function(){function n(t,e){var r=this;if(e===void 0&&(e=!1),this._imageTensors=[],this._canvases=[],this._treatAsBatchInput=!1,this._inputDimensions=[],!Array.isArray(t))throw new Error("NetInput.constructor - expected inputs to be an Array of TResolvedNetInput or to be instanceof tf.Tensor4D, instead have "+t);this._treatAsBatchInput=e,this._batchSize=t.length,t.forEach(function(o,a){if(xl(o)){r._imageTensors[a]=o,r._inputDimensions[a]=o.shape;return}if(Ho(o)){var i=o.shape[0];if(i!==1)throw new Error("NetInput - tf.Tensor4D with batchSize "+i+" passed, but not supported in input array");r._imageTensors[a]=o,r._inputDimensions[a]=o.shape.slice(1);return}var s=o instanceof on.getEnv().Canvas?o:Jh(o);r._canvases[a]=s,r._inputDimensions[a]=[s.height,s.width,3]})}return Object.defineProperty(n.prototype,"imageTensors",{get:function(){return this._imageTensors},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"canvases",{get:function(){return this._canvases},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isBatchInput",{get:function(){return this.batchSize>1||this._treatAsBatchInput},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"batchSize",{get:function(){return this._batchSize},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"inputDimensions",{get:function(){return this._inputDimensions},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"inputSize",{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"reshapedInputDimensions",{get:function(){var t=this;return du(this.batchSize,0,1).map(function(e,r){return t.getReshapedInputDimensions(r)})},enumerable:!0,configurable:!0}),n.prototype.getInput=function(t){return this.canvases[t]||this.imageTensors[t]},n.prototype.getInputDimensions=function(t){return this._inputDimensions[t]},n.prototype.getInputHeight=function(t){return this._inputDimensions[t][0]},n.prototype.getInputWidth=function(t){return this._inputDimensions[t][1]},n.prototype.getReshapedInputDimensions=function(t){if(typeof this.inputSize!="number")throw new Error("getReshapedInputDimensions - inputSize not set, toBatchTensor has not been called yet");var e=this.getInputWidth(t),r=this.getInputHeight(t);return m5({width:e,height:r},this.inputSize)},n.prototype.toBatchTensor=function(t,e){var r=this;return e===void 0&&(e=!0),this._inputSize=t,xe(function(){var o=du(r.batchSize,0,1).map(function(i){var s=r.getInput(i);if(s instanceof Nt){var u=Ho(s)?s:s.expandDims();return u=b5(u,e),(u.shape[1]!==t||u.shape[2]!==t)&&(u=$h.resizeBilinear(u,[t,t])),u.as3D(t,t,3)}if(s instanceof on.getEnv().Canvas)return Hh.fromPixels(I5(s,t,e));throw new Error("toBatchTensor - at batchIdx "+i+", expected input to be instanceof tf.Tensor or instanceof HTMLCanvasElement, instead have "+s)}),a=Bn(o.map(function(i){return i.toFloat()})).as4D(r.batchSize,t,t,3);return a})},n}();function Zt(n){return $e(this,void 0,void 0,function(){var t,e,r;return ke(this,function(o){switch(o.label){case 0:if(n instanceof Sl)return[2,n];if(t=Array.isArray(n)?n:[n],!t.length)throw new Error("toNetInput - empty array passed as input");return e=function(a){return Array.isArray(n)?" at input index "+a+":":""},r=t.map(o2),r.forEach(function(a,i){if(!u2(a)&&!xl(a)&&!Ho(a))throw typeof t[i]=="string"?new Error("toNetInput -"+e(i)+" string passed, but could not resolve HTMLElement for element id "+t[i]):new Error("toNetInput -"+e(i)+" expected media to be of type HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | tf.Tensor3D, or to be an element id");if(Ho(a)){var s=a.shape[0];if(s!==1)throw new Error("toNetInput -"+e(i)+" tf.Tensor4D with batchSize "+s+" passed, but not supported in input array")}}),[4,Promise.all(r.map(function(a){return u2(a)&&k5(a)}))];case 1:return o.sent(),[2,new Sl(r,Array.isArray(n))]}})})}function ep(n,t){return $e(this,void 0,void 0,function(){var e,r,o,a,i,s,u;return ke(this,function(c){switch(c.label){case 0:return e=on.getEnv().Canvas,r=n,n instanceof e?[3,5]:[4,Zt(n)];case 1:if(o=c.sent(),o.batchSize>1)throw new Error("extractFaces - batchSize > 1 not supported");return a=o.getInput(0),a instanceof e?(i=a,[3,4]):[3,2];case 2:return[4,P5(a)];case 3:i=c.sent(),c.label=4;case 4:r=i,c.label=5;case 5:return s=za(r),u=t.map(function(l){return l instanceof Wr?l.forSize(r.width,r.height).box.floor():l}).map(function(l){return l.clipAtImageBorders(r.width,r.height)}),[2,u.map(function(l){var d=l.x,f=l.y,h=l.width,m=l.height,v=El({width:h,height:m});return za(v).putImageData(s.getImageData(d,f,h,m),0,0),v})]}})})}function tp(n,t){return $e(this,void 0,void 0,function(){return ke(this,function(e){if(!xl(n)&&!Ho(n))throw new Error("extractFaceTensors - expected image tensor to be 3D or 4D");if(Ho(n)&&n.shape[0]>1)throw new Error("extractFaceTensors - batchSize > 1 not supported");return[2,xe(function(){var r=n.shape.slice(Ho(n)?1:0),o=r[0],a=r[1],i=r[2],s=t.map(function(c){return c instanceof Wr?c.forSize(a,o).box:c}).map(function(c){return c.clipAtImageBorders(a,o)}),u=s.map(function(c){var l=c.x,d=c.y,f=c.width,h=c.height;return vb(n.as3D(o,a,i),[d,l,0],[h,f,i])});return u})]})})}function A5(n,t){return $e(this,void 0,void 0,function(){var e,r;return ke(this,function(o){switch(o.label){case 0:return e=on.getEnv().fetch,[4,e(n,t)];case 1:if(r=o.sent(),!(r.status<400))throw new Error("failed to fetch: ("+r.status+") "+r.statusText+", from url: "+r.url);return[2,r]}})})}function T5(n){return $e(this,void 0,void 0,function(){return ke(this,function(t){switch(t.label){case 0:return[4,A5(n)];case 1:return[2,t.sent().json()]}})})}function c2(n,t){var e=t+"-weights_manifest.json";if(!n)return{modelBaseUri:"",manifestUri:e};if(n==="/")return{modelBaseUri:"/",manifestUri:"/"+e};var r=n.startsWith("http://")?"http://":n.startsWith("https://")?"https://":"";n=n.replace(r,"");var o=n.split("/").filter(function(s){return s}),a=n.endsWith(".json")?o[o.length-1]:e,i=r+(n.endsWith(".json")?o.slice(0,o.length-1):o).join("/");return i=n.startsWith("/")?"/"+i:i,{modelBaseUri:i,manifestUri:i==="/"?"/"+a:i+"/"+a}}function O5(n,t){return $e(this,void 0,void 0,function(){var e,r,o,a;return ke(this,function(i){switch(i.label){case 0:return e=c2(n,t),r=e.manifestUri,o=e.modelBaseUri,[4,T5(r)];case 1:return a=i.sent(),[2,Hb.loadWeights(a,o)]}})})}var lo=function(){function n(t){this._name=t,this._params=void 0,this._paramMappings=[]}return Object.defineProperty(n.prototype,"params",{get:function(){return this._params},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"paramMappings",{get:function(){return this._paramMappings},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isLoaded",{get:function(){return!!this.params},enumerable:!0,configurable:!0}),n.prototype.getParamFromPath=function(t){var e=this.traversePropertyPath(t),r=e.obj,o=e.objProp;return r[o]},n.prototype.reassignParamFromPath=function(t,e){var r=this.traversePropertyPath(t),o=r.obj,a=r.objProp;o[a].dispose(),o[a]=e},n.prototype.getParamList=function(){var t=this;return this._paramMappings.map(function(e){var r=e.paramPath;return{path:r,tensor:t.getParamFromPath(r)}})},n.prototype.getTrainableParams=function(){return this.getParamList().filter(function(t){return t.tensor instanceof Si})},n.prototype.getFrozenParams=function(){return this.getParamList().filter(function(t){return!(t.tensor instanceof Si)})},n.prototype.variable=function(){var t=this;this.getFrozenParams().forEach(function(e){var r=e.path,o=e.tensor;t.reassignParamFromPath(r,o.variable())})},n.prototype.freeze=function(){var t=this;this.getTrainableParams().forEach(function(e){var r=e.path,o=e.tensor,a=rn(o.dataSync());o.dispose(),t.reassignParamFromPath(r,a)})},n.prototype.dispose=function(t){t===void 0&&(t=!0),this.getParamList().forEach(function(e){if(t&&e.tensor.isDisposed)throw new Error("param tensor has already been disposed for path "+e.path);e.tensor.dispose()}),this._params=void 0},n.prototype.serializeParams=function(){return new Float32Array(this.getParamList().map(function(t){var e=t.tensor;return Array.from(e.dataSync())}).reduce(function(t,e){return t.concat(e)}))},n.prototype.load=function(t){return $e(this,void 0,void 0,function(){return ke(this,function(e){switch(e.label){case 0:return t instanceof Float32Array?(this.extractWeights(t),[2]):[4,this.loadFromUri(t)];case 1:return e.sent(),[2]}})})},n.prototype.loadFromUri=function(t){return $e(this,void 0,void 0,function(){var e;return ke(this,function(r){switch(r.label){case 0:if(t&&typeof t!="string")throw new Error(this._name+".loadFromUri - expected model uri");return[4,O5(t,this.getDefaultModelName())];case 1:return e=r.sent(),this.loadFromWeightMap(e),[2]}})})},n.prototype.loadFromDisk=function(t){return $e(this,void 0,void 0,function(){var e,r,o,a,i,s,u,c,l,d;return ke(this,function(f){switch(f.label){case 0:if(t&&typeof t!="string")throw new Error(this._name+".loadFromDisk - expected model file path");return e=on.getEnv().readFile,r=c2(t,this.getDefaultModelName()),o=r.manifestUri,a=r.modelBaseUri,i=function(h){return Promise.all(h.map(function(m){return e(m).then(function(v){return v.buffer})}))},s=Hb.weightsLoaderFactory(i),l=(c=JSON).parse,[4,e(o)];case 1:return u=l.apply(c,[f.sent().toString()]),[4,s(u,a)];case 2:return d=f.sent(),this.loadFromWeightMap(d),[2]}})})},n.prototype.loadFromWeightMap=function(t){var e=this.extractParamsFromWeigthMap(t),r=e.paramMappings,o=e.params;this._paramMappings=r,this._params=o},n.prototype.extractWeights=function(t){var e=this.extractParams(t),r=e.paramMappings,o=e.params;this._paramMappings=r,this._params=o},n.prototype.traversePropertyPath=function(t){if(!this.params)throw new Error("traversePropertyPath - model has no loaded params");var e=t.split("/").reduce(function(a,i){if(!a.nextObj.hasOwnProperty(i))throw new Error("traversePropertyPath - object does not have property "+i+", for path "+t);return{obj:a.nextObj,objProp:i,nextObj:a.nextObj[i]}},{nextObj:this.params}),r=e.obj,o=e.objProp;if(!r||!o||!(r[o]instanceof Nt))throw new Error("traversePropertyPath - parameter is not a tensor, for path "+t);return{obj:r,objProp:o}},n}();function Vn(n,t,e){return xe(function(){var r=Ch(n,t.depthwise_filter,t.pointwise_filter,e,"same");return r=qe(r,t.bias),r})}function np(n,t,e){return e===void 0&&(e=!1),xe(function(){var r=kt(e?qe(Zn(n,t.conv0.filters,[2,2],"same"),t.conv0.bias):Vn(n,t.conv0,[2,2])),o=Vn(r,t.conv1,[1,1]),a=kt(qe(r,o)),i=Vn(a,t.conv2,[1,1]);return kt(qe(r,qe(o,i)))})}function Nl(n,t,e,r){return e===void 0&&(e=!1),r===void 0&&(r=!0),xe(function(){var o=kt(e?qe(Zn(n,t.conv0.filters,r?[2,2]:[1,1],"same"),t.conv0.bias):Vn(n,t.conv0,r?[2,2]:[1,1])),a=Vn(o,t.conv1,[1,1]),i=kt(qe(o,a)),s=Vn(i,t.conv2,[1,1]),u=kt(qe(o,qe(a,s))),c=Vn(u,t.conv3,[1,1]);return kt(qe(o,qe(a,qe(s,c))))})}function cr(n,t,e,r){return e===void 0&&(e="same"),r===void 0&&(r=!1),xe(function(){var o=qe(Zn(n,t.filters,[1,1],e),t.bias);return r?kt(o):o})}function fo(n,t){Object.keys(n).forEach(function(e){t.some(function(r){return r.originalPath===e})||n[e].dispose()})}function $l(n,t){return function(e,r,o,a){var i=Sn(n(e*r*o*o),[o,o,e,r]),s=Dt(n(r));return t.push({paramPath:a+"/filters"},{paramPath:a+"/bias"}),{filters:i,bias:s}}}function rp(n,t){return function(e,r,o){var a=Wo(n(e*r),[e,r]),i=Dt(n(r));return t.push({paramPath:o+"/weights"},{paramPath:o+"/bias"}),{weights:a,bias:i}}}var l2=function(){function n(t,e,r){this.depthwise_filter=t,this.pointwise_filter=e,this.bias=r}return n}();function op(n,t){return function(e,r,o){var a=Sn(n(9*e),[3,3,e,1]),i=Sn(n(e*r),[1,1,e,r]),s=Dt(n(r));return t.push({paramPath:o+"/depthwise_filter"},{paramPath:o+"/pointwise_filter"},{paramPath:o+"/bias"}),new l2(a,i,s)}}function ap(n){return function(t){var e=n(t+"/depthwise_filter",4),r=n(t+"/pointwise_filter",4),o=n(t+"/bias",1);return new l2(e,r,o)}}function qo(n,t){return function(e,r,o){var a=n[e];if(!bl(a,r))throw new Error("expected weightMap["+e+"] to be a Tensor"+r+"D, instead have "+a);return t.push({originalPath:e,paramPath:o||e}),a}}function ho(n){var t=n;function e(o){var a=t.slice(0,o);return t=t.slice(o),a}function r(){return t}return{extractWeights:e,getRemainingWeights:r}}function d2(n,t){var e=$l(n,t),r=op(n,t);function o(i,s,u,c){c===void 0&&(c=!1);var l=c?e(i,s,3,u+"/conv0"):r(i,s,u+"/conv0"),d=r(s,s,u+"/conv1"),f=r(s,s,u+"/conv2");return{conv0:l,conv1:d,conv2:f}}function a(i,s,u,c){c===void 0&&(c=!1);var l=o(i,s,u,c),d=l.conv0,f=l.conv1,h=l.conv2,m=r(s,s,u+"/conv3");return{conv0:d,conv1:f,conv2:h,conv3:m}}return{extractDenseBlock3Params:o,extractDenseBlock4Params:a}}function D5(n){var t=[],e=ho(n),r=e.extractWeights,o=e.getRemainingWeights,a=d2(r,t).extractDenseBlock4Params,i=a(3,32,"dense0",!0),s=a(32,64,"dense1"),u=a(64,128,"dense2"),c=a(128,256,"dense3");if(o().length!==0)throw new Error("weights remaing after extract: "+o().length);return{paramMappings:t,params:{dense0:i,dense1:s,dense2:u,dense3:c}}}function f2(n){return function(t){var e=n(t+"/filters",4),r=n(t+"/bias",1);return{filters:e,bias:r}}}function h2(n,t){var e=qo(n,t),r=f2(e),o=ap(e);function a(s,u){u===void 0&&(u=!1);var c=u?r(s+"/conv0"):o(s+"/conv0"),l=o(s+"/conv1"),d=o(s+"/conv2");return{conv0:c,conv1:l,conv2:d}}function i(s,u){u===void 0&&(u=!1);var c=u?r(s+"/conv0"):o(s+"/conv0"),l=o(s+"/conv1"),d=o(s+"/conv2"),f=o(s+"/conv3");return{conv0:c,conv1:l,conv2:d,conv3:f}}return{extractDenseBlock3Params:a,extractDenseBlock4Params:i}}function F5(n){var t=[],e=h2(n,t).extractDenseBlock4Params,r={dense0:e("dense0",!0),dense1:e("dense1"),dense2:e("dense2"),dense3:e("dense3")};return fo(n,t),{params:r,paramMappings:t}}var p2=function(n){De(t,n);function t(){return n.call(this,"FaceFeatureExtractor")||this}return t.prototype.forwardInput=function(e){var r=this.params;if(!r)throw new Error("FaceFeatureExtractor - load model before inference");return xe(function(){var o=e.toBatchTensor(112,!0),a=[122.782,117.001,104.298],i=hu(o,a).div(ve(255)),s=Nl(i,r.dense0,!0);return s=Nl(s,r.dense1),s=Nl(s,r.dense2),s=Nl(s,r.dense3),s=uu(s,[7,7],[2,2],"valid"),s})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.getDefaultModelName=function(){return"face_feature_extractor_model"},t.prototype.extractParamsFromWeigthMap=function(e){return F5(e)},t.prototype.extractParams=function(e){return D5(e)},t}(lo);function Vr(n,t){return xe(function(){return qe(hl(n,t.weights),t.bias)})}function M5(n,t,e){var r=[],o=ho(n),a=o.extractWeights,i=o.getRemainingWeights,s=rp(a,r),u=s(t,e,"fc");if(i().length!==0)throw new Error("weights remaing after extract: "+i().length);return{paramMappings:r,params:{fc:u}}}function R5(n){var t=[],e=qo(n,t);function r(a){var i=e(a+"/weights",2),s=e(a+"/bias",1);return{weights:i,bias:s}}var o={fc:r("fc")};return fo(n,t),{params:o,paramMappings:t}}function v2(n){var t={},e={};return Object.keys(n).forEach(function(r){var o=r.startsWith("fc")?e:t;o[r]=n[r]}),{featureExtractorMap:t,classifierMap:e}}var m2=function(n){De(t,n);function t(e,r){var o=n.call(this,e)||this;return o._faceFeatureExtractor=r,o}return Object.defineProperty(t.prototype,"faceFeatureExtractor",{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),t.prototype.runNet=function(e){var r=this,o=this.params;if(!o)throw new Error(this._name+" - load model before inference");return xe(function(){var a=e instanceof Sl?r.faceFeatureExtractor.forwardInput(e):e;return Vr(a.as2D(a.shape[0],-1),o.fc)})},t.prototype.dispose=function(e){e===void 0&&(e=!0),this.faceFeatureExtractor.dispose(e),n.prototype.dispose.call(this,e)},t.prototype.loadClassifierParams=function(e){var r=this.extractClassifierParams(e),o=r.params,a=r.paramMappings;this._params=o,this._paramMappings=a},t.prototype.extractClassifierParams=function(e){return M5(e,this.getClassifierChannelsIn(),this.getClassifierChannelsOut())},t.prototype.extractParamsFromWeigthMap=function(e){var r=v2(e),o=r.featureExtractorMap,a=r.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(o),R5(a)},t.prototype.extractParams=function(e){var r=this.getClassifierChannelsIn(),o=this.getClassifierChannelsOut(),a=o*r+o,i=e.slice(0,e.length-a),s=e.slice(e.length-a);return this.faceFeatureExtractor.extractWeights(i),this.extractClassifierParams(s)},t}(lo),g2=["neutral","happy","sad","angry","fearful","disgusted","surprised"],L5=function(){function n(t){var e=this;if(t.length!==7)throw new Error("FaceExpressions.constructor - expected probabilities.length to be 7, have: "+t.length);g2.forEach(function(r,o){e[r]=t[o]})}return n.prototype.asSortedArray=function(){var t=this;return g2.map(function(e){return{expression:e,probability:t[e]}}).sort(function(e,r){return r.probability-e.probability})},n}(),B5=function(n){De(t,n);function t(e){return e===void 0&&(e=new p2),n.call(this,"FaceExpressionNet",e)||this}return t.prototype.forwardInput=function(e){var r=this;return xe(function(){return io(r.runNet(e))})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.predictExpressions=function(e){return $e(this,void 0,void 0,function(){var r,o,a,i,s=this;return ke(this,function(u){switch(u.label){case 0:return[4,Zt(e)];case 1:return r=u.sent(),[4,this.forwardInput(r)];case 2:return o=u.sent(),[4,Promise.all(Ut(o).map(function(c){return $e(s,void 0,void 0,function(){var l;return ke(this,function(d){switch(d.label){case 0:return[4,c.data()];case 1:return l=d.sent(),c.dispose(),[2,l]}})})}))];case 3:return a=u.sent(),o.dispose(),i=a.map(function(c){return new L5(c)}),[2,r.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}(m2);function y2(n,t){var e={expressions:t};return Object.assign({},n,e)}function W5(n){return S5(n)&&n.landmarks instanceof Cl&&n.unshiftedLandmarks instanceof Cl&&n.alignedRect instanceof Wr}function ip(n,t){var e=n.detection.box,r=t.shiftBy(e.x,e.y),o=r.align(),a=n.detection.imageDims,i=new Wr(n.detection.score,o.rescale(a.reverse()),a),s={landmarks:r,unshiftedLandmarks:t,alignedRect:i};return Object.assign({},n,s)}function V5(n,t){var e=$l(n,t),r=op(n,t);function o(i,s,u){var c=r(i,s,u+"/separable_conv0"),l=r(s,s,u+"/separable_conv1"),d=e(i,s,1,u+"/expansion_conv");return{separable_conv0:c,separable_conv1:l,expansion_conv:d}}function a(i,s){var u=r(i,i,s+"/separable_conv0"),c=r(i,i,s+"/separable_conv1"),l=r(i,i,s+"/separable_conv2");return{separable_conv0:u,separable_conv1:c,separable_conv2:l}}return{extractConvParams:e,extractSeparableConvParams:r,extractReductionBlockParams:o,extractMainBlockParams:a}}function j5(n,t){var e=[],r=ho(n),o=r.extractWeights,a=r.getRemainingWeights,i=V5(o,e),s=i.extractConvParams,u=i.extractSeparableConvParams,c=i.extractReductionBlockParams,l=i.extractMainBlockParams,d=s(3,32,3,"entry_flow/conv_in"),f=c(32,64,"entry_flow/reduction_block_0"),h=c(64,128,"entry_flow/reduction_block_1"),m={conv_in:d,reduction_block_0:f,reduction_block_1:h},v={};du(t,0,1).forEach(function(w){v["main_block_"+w]=l(128,"middle_flow/main_block_"+w)});var p=c(128,256,"exit_flow/reduction_block"),g=u(256,512,"exit_flow/separable_conv"),b={reduction_block:p,separable_conv:g};if(a().length!==0)throw new Error("weights remaing after extract: "+a().length);return{paramMappings:e,params:{entry_flow:m,middle_flow:v,exit_flow:b}}}function U5(n,t){var e=qo(n,t),r=f2(e),o=ap(e);function a(s){var u=o(s+"/separable_conv0"),c=o(s+"/separable_conv1"),l=r(s+"/expansion_conv");return{separable_conv0:u,separable_conv1:c,expansion_conv:l}}function i(s){var u=o(s+"/separable_conv0"),c=o(s+"/separable_conv1"),l=o(s+"/separable_conv2");return{separable_conv0:u,separable_conv1:c,separable_conv2:l}}return{extractConvParams:r,extractSeparableConvParams:o,extractReductionBlockParams:a,extractMainBlockParams:i}}function z5(n,t){var e=[],r=U5(n,e),o=r.extractConvParams,a=r.extractSeparableConvParams,i=r.extractReductionBlockParams,s=r.extractMainBlockParams,u=o("entry_flow/conv_in"),c=i("entry_flow/reduction_block_0"),l=i("entry_flow/reduction_block_1"),d={conv_in:u,reduction_block_0:c,reduction_block_1:l},f={};du(t,0,1).forEach(function(p){f["main_block_"+p]=s("middle_flow/main_block_"+p)});var h=i("exit_flow/reduction_block"),m=a("exit_flow/separable_conv"),v={reduction_block:h,separable_conv:m};return fo(n,e),{params:{entry_flow:d,middle_flow:f,exit_flow:v},paramMappings:e}}function b2(n,t,e){return qe(Zn(n,t.filters,e,"same"),t.bias)}function sp(n,t,e){e===void 0&&(e=!0);var r=e?kt(n):n;return r=Vn(r,t.separable_conv0,[1,1]),r=Vn(kt(r),t.separable_conv1,[1,1]),r=Xt(r,[3,3],[2,2],"same"),r=qe(r,b2(n,t.expansion_conv,[2,2])),r}function H5(n,t){var e=Vn(kt(n),t.separable_conv0,[1,1]);return e=Vn(kt(e),t.separable_conv1,[1,1]),e=Vn(kt(e),t.separable_conv2,[1,1]),e=qe(e,n),e}var G5=function(n){De(t,n);function t(e){var r=n.call(this,"TinyXception")||this;return r._numMainBlocks=e,r}return t.prototype.forwardInput=function(e){var r=this,o=this.params;if(!o)throw new Error("TinyXception - load model before inference");return xe(function(){var a=e.toBatchTensor(112,!0),i=[122.782,117.001,104.298],s=hu(a,i).div(ve(256)),u=kt(b2(s,o.entry_flow.conv_in,[2,2]));return u=sp(u,o.entry_flow.reduction_block_0,!1),u=sp(u,o.entry_flow.reduction_block_1),du(r._numMainBlocks,0,1).forEach(function(c){u=H5(u,o.middle_flow["main_block_"+c])}),u=sp(u,o.exit_flow.reduction_block),u=kt(Vn(u,o.exit_flow.separable_conv,[1,1])),u})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.getDefaultModelName=function(){return"tiny_xception_model"},t.prototype.extractParamsFromWeigthMap=function(e){return z5(e,this._numMainBlocks)},t.prototype.extractParams=function(e){return j5(e,this._numMainBlocks)},t}(lo);function q5(n){var t=[],e=ho(n),r=e.extractWeights,o=e.getRemainingWeights,a=rp(r,t),i=a(512,1,"fc/age"),s=a(512,2,"fc/gender");if(o().length!==0)throw new Error("weights remaing after extract: "+o().length);return{paramMappings:t,params:{fc:{age:i,gender:s}}}}function K5(n){var t=[],e=qo(n,t);function r(a){var i=e(a+"/weights",2),s=e(a+"/bias",1);return{weights:i,bias:s}}var o={fc:{age:r("fc/age"),gender:r("fc/gender")}};return fo(n,t),{params:o,paramMappings:t}}var kl;(function(n){n.FEMALE="female",n.MALE="male"})(kl||(kl={}));var Y5=function(n){De(t,n);function t(e){e===void 0&&(e=new G5(2));var r=n.call(this,"AgeGenderNet")||this;return r._faceFeatureExtractor=e,r}return Object.defineProperty(t.prototype,"faceFeatureExtractor",{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),t.prototype.runNet=function(e){var r=this,o=this.params;if(!o)throw new Error(this._name+" - load model before inference");return xe(function(){var a=e instanceof Sl?r.faceFeatureExtractor.forwardInput(e):e,i=uu(a,[7,7],[2,2],"valid").as2D(a.shape[0],-1),s=Vr(i,o.fc.age).as1D(),u=Vr(i,o.fc.gender);return{age:s,gender:u}})},t.prototype.forwardInput=function(e){var r=this;return xe(function(){var o=r.runNet(e),a=o.age,i=o.gender;return{age:a,gender:io(i)}})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.predictAgeAndGender=function(e){return $e(this,void 0,void 0,function(){var r,o,a,i,s,u,c=this;return ke(this,function(l){switch(l.label){case 0:return[4,Zt(e)];case 1:return r=l.sent(),[4,this.forwardInput(r)];case 2:return o=l.sent(),a=Ut(o.age),i=Ut(o.gender),s=a.map(function(d,f){return{ageTensor:d,genderTensor:i[f]}}),[4,Promise.all(s.map(function(d){var f=d.ageTensor,h=d.genderTensor;return $e(c,void 0,void 0,function(){var m,v,p,g,b;return ke(this,function(w){switch(w.label){case 0:return[4,f.data()];case 1:return m=w.sent()[0],[4,h.data()];case 2:return v=w.sent()[0],p=v>.5,g=p?kl.MALE:kl.FEMALE,b=p?v:1-v,f.dispose(),h.dispose(),[2,{age:m,gender:g,genderProbability:b}]}})})}))];case 3:return u=l.sent(),o.age.dispose(),o.gender.dispose(),[2,r.isBatchInput?u:u[0]]}})})},t.prototype.getDefaultModelName=function(){return"age_gender_model"},t.prototype.dispose=function(e){e===void 0&&(e=!0),this.faceFeatureExtractor.dispose(e),n.prototype.dispose.call(this,e)},t.prototype.loadClassifierParams=function(e){var r=this.extractClassifierParams(e),o=r.params,a=r.paramMappings;this._params=o,this._paramMappings=a},t.prototype.extractClassifierParams=function(e){return q5(e)},t.prototype.extractParamsFromWeigthMap=function(e){var r=v2(e),o=r.featureExtractorMap,a=r.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(o),K5(a)},t.prototype.extractParams=function(e){var r=1539,o=e.slice(0,e.length-r),a=e.slice(e.length-r);return this.faceFeatureExtractor.extractWeights(o),this.extractClassifierParams(a)},t}(lo),x2=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.postProcess=function(e,r,o){var a=o.map(function(s){var u=s.width,c=s.height,l=r/Math.max(c,u);return{width:u*l,height:c*l}}),i=a.length;return xe(function(){var s=function(f,h){return Bn([Lr([68],f),Lr([68],h)],1).as2D(1,136).as1D()},u=function(f,h){var m=a[f],v=m.width,p=m.height;return h(v,p)?Math.abs(v-p)/2:0},c=function(f){return u(f,function(h,m){return h<m})},l=function(f){return u(f,function(h,m){return m<h})},d=e.mul(Lr([i,136],r)).sub(Bn(Array.from(Array(i),function(f,h){return s(c(h),l(h))}))).div(Bn(Array.from(Array(i),function(f,h){return s(a[h].width,a[h].height)})));return d})},t.prototype.forwardInput=function(e){var r=this;return xe(function(){var o=r.runNet(e);return r.postProcess(o,e.inputSize,e.inputDimensions.map(function(a){var i=a[0],s=a[1];return{height:i,width:s}}))})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.detectLandmarks=function(e){return $e(this,void 0,void 0,function(){var r,o,a,i=this;return ke(this,function(s){switch(s.label){case 0:return[4,Zt(e)];case 1:return r=s.sent(),o=xe(function(){return Ut(i.forwardInput(r))}),[4,Promise.all(o.map(function(u,c){return $e(i,void 0,void 0,function(){var l,d,f,h,m;return ke(this,function(v){switch(v.label){case 0:return f=(d=Array).from,[4,u.data()];case 1:return l=f.apply(d,[v.sent()]),h=l.filter(function(p,g){return qb(g)}),m=l.filter(function(p,g){return!qb(g)}),[2,new E5(Array(68).fill(0).map(function(p,g){return new ct(h[g],m[g])}),{height:r.getInputHeight(c),width:r.getInputWidth(c)})]}})})}))];case 2:return a=s.sent(),o.forEach(function(u){return u.dispose()}),[2,r.isBatchInput?a:a[0]]}})})},t.prototype.getClassifierChannelsOut=function(){return 136},t}(m2),w2=function(n){De(t,n);function t(e){return e===void 0&&(e=new p2),n.call(this,"FaceLandmark68Net",e)||this}return t.prototype.getDefaultModelName=function(){return"face_landmark_68_model"},t.prototype.getClassifierChannelsIn=function(){return 256},t}(x2);function X5(n){var t=[],e=h2(n,t).extractDenseBlock3Params,r={dense0:e("dense0",!0),dense1:e("dense1"),dense2:e("dense2")};return fo(n,t),{params:r,paramMappings:t}}function Z5(n){var t=[],e=ho(n),r=e.extractWeights,o=e.getRemainingWeights,a=d2(r,t).extractDenseBlock3Params,i=a(3,32,"dense0",!0),s=a(32,64,"dense1"),u=a(64,128,"dense2");if(o().length!==0)throw new Error("weights remaing after extract: "+o().length);return{paramMappings:t,params:{dense0:i,dense1:s,dense2:u}}}var Q5=function(n){De(t,n);function t(){return n.call(this,"TinyFaceFeatureExtractor")||this}return t.prototype.forwardInput=function(e){var r=this.params;if(!r)throw new Error("TinyFaceFeatureExtractor - load model before inference");return xe(function(){var o=e.toBatchTensor(112,!0),a=[122.782,117.001,104.298],i=hu(o,a).div(ve(255)),s=np(i,r.dense0,!0);return s=np(s,r.dense1),s=np(s,r.dense2),s=uu(s,[14,14],[2,2],"valid"),s})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.getDefaultModelName=function(){return"face_feature_extractor_tiny_model"},t.prototype.extractParamsFromWeigthMap=function(e){return X5(e)},t.prototype.extractParams=function(e){return Z5(e)},t}(lo),J5=function(n){De(t,n);function t(e){return e===void 0&&(e=new Q5),n.call(this,"FaceLandmark68TinyNet",e)||this}return t.prototype.getDefaultModelName=function(){return"face_landmark_68_tiny_model"},t.prototype.getClassifierChannelsIn=function(){return 128},t}(x2);(function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t})(w2);function e9(n,t){return qe(fn(n,t.weights),t.biases)}function up(n,t,e,r,o){o===void 0&&(o="same");var a=t.conv,i=a.filters,s=a.bias,u=Zn(n,i,e,o);return u=qe(u,s),u=e9(u,t.scale),r?kt(u):u}function t9(n,t){return up(n,t,[1,1],!0)}function C2(n,t){return up(n,t,[1,1],!1)}function _2(n,t){return up(n,t,[2,2],!0,"valid")}function n9(n,t){function e(s,u,c){var l=n(s),d=l.length/(u*c*c);if(p5(d))throw new Error("depth has to be an integer: "+d+", weights.length: "+l.length+", numFilters: "+u+", filterSize: "+c);return xe(function(){return jo(Sn(l,[u,d,c,c]),[2,3,1,0])})}function r(s,u,c,l){var d=e(s,u,c),f=Dt(n(u));return t.push({paramPath:l+"/filters"},{paramPath:l+"/bias"}),{filters:d,bias:f}}function o(s,u){var c=Dt(n(s)),l=Dt(n(s));return t.push({paramPath:u+"/weights"},{paramPath:u+"/biases"}),{weights:c,biases:l}}function a(s,u,c,l){var d=r(s,u,c,l+"/conv"),f=o(u,l+"/scale");return{conv:d,scale:f}}function i(s,u,c,l,d){d===void 0&&(d=!1);var f=a((d?.5:1)*s,u,c,l+"/conv1"),h=a(s,u,c,l+"/conv2");return{conv1:f,conv2:h}}return{extractConvLayerParams:a,extractResidualLayerParams:i}}function r9(n){var t=ho(n),e=t.extractWeights,r=t.getRemainingWeights,o=[],a=n9(e,o),i=a.extractConvLayerParams,s=a.extractResidualLayerParams,u=i(4704,32,7,"conv32_down"),c=s(9216,32,3,"conv32_1"),l=s(9216,32,3,"conv32_2"),d=s(9216,32,3,"conv32_3"),f=s(36864,64,3,"conv64_down",!0),h=s(36864,64,3,"conv64_1"),m=s(36864,64,3,"conv64_2"),v=s(36864,64,3,"conv64_3"),p=s(147456,128,3,"conv128_down",!0),g=s(147456,128,3,"conv128_1"),b=s(147456,128,3,"conv128_2"),w=s(589824,256,3,"conv256_down",!0),x=s(589824,256,3,"conv256_1"),C=s(589824,256,3,"conv256_2"),_=s(589824,256,3,"conv256_down_out"),E=xe(function(){return jo(Wo(e(256*128),[128,256]),[1,0])});if(o.push({paramPath:"fc"}),r().length!==0)throw new Error("weights remaing after extract: "+r().length);var $={conv32_down:u,conv32_1:c,conv32_2:l,conv32_3:d,conv64_down:f,conv64_1:h,conv64_2:m,conv64_3:v,conv128_down:p,conv128_1:g,conv128_2:b,conv256_down:w,conv256_1:x,conv256_2:C,conv256_down_out:_,fc:E};return{params:$,paramMappings:o}}function o9(n,t){var e=qo(n,t);function r(i){var s=e(i+"/scale/weights",1),u=e(i+"/scale/biases",1);return{weights:s,biases:u}}function o(i){var s=e(i+"/conv/filters",4),u=e(i+"/conv/bias",1),c=r(i);return{conv:{filters:s,bias:u},scale:c}}function a(i){return{conv1:o(i+"/conv1"),conv2:o(i+"/conv2")}}return{extractConvLayerParams:o,extractResidualLayerParams:a}}function a9(n){var t=[],e=o9(n,t),r=e.extractConvLayerParams,o=e.extractResidualLayerParams,a=r("conv32_down"),i=o("conv32_1"),s=o("conv32_2"),u=o("conv32_3"),c=o("conv64_down"),l=o("conv64_1"),d=o("conv64_2"),f=o("conv64_3"),h=o("conv128_down"),m=o("conv128_1"),v=o("conv128_2"),p=o("conv256_down"),g=o("conv256_1"),b=o("conv256_2"),w=o("conv256_down_out"),x=n.fc;if(t.push({originalPath:"fc",paramPath:"fc"}),!h5(x))throw new Error("expected weightMap[fc] to be a Tensor2D, instead have "+x);var C={conv32_down:a,conv32_1:i,conv32_2:s,conv32_3:u,conv64_down:c,conv64_1:l,conv64_2:d,conv64_3:f,conv128_down:h,conv128_1:m,conv128_2:v,conv256_down:p,conv256_1:g,conv256_2:b,conv256_down_out:w,fc:x};return fo(n,t),{params:C,paramMappings:t}}function jr(n,t){var e=t9(n,t.conv1);return e=C2(e,t.conv2),e=qe(e,n),e=kt(e),e}function Pl(n,t){var e=_2(n,t.conv1);e=C2(e,t.conv2);var r=uu(n,2,2,"valid"),o=wt(r.shape),a=r.shape[3]!==e.shape[3],i=r.shape[1]!==e.shape[1]||r.shape[2]!==e.shape[2];if(i){var s=lu(e.shape);s[1]=1;var u=wt(s);e=jt([e,u],1);var c=lu(e.shape);c[2]=1;var l=wt(c);e=jt([e,l],2)}return r=a?jt([r,o],3):r,e=qe(r,e),e=kt(e),e}var i9=function(n){De(t,n);function t(){return n.call(this,"FaceRecognitionNet")||this}return t.prototype.forwardInput=function(e){var r=this.params;if(!r)throw new Error("FaceRecognitionNet - load model before inference");return xe(function(){var o=e.toBatchTensor(150,!0).toFloat(),a=[122.782,117.001,104.298],i=hu(o,a).div(ve(256)),s=_2(i,r.conv32_down);s=Xt(s,3,2,"valid"),s=jr(s,r.conv32_1),s=jr(s,r.conv32_2),s=jr(s,r.conv32_3),s=Pl(s,r.conv64_down),s=jr(s,r.conv64_1),s=jr(s,r.conv64_2),s=jr(s,r.conv64_3),s=Pl(s,r.conv128_down),s=jr(s,r.conv128_1),s=jr(s,r.conv128_2),s=Pl(s,r.conv256_down),s=jr(s,r.conv256_1),s=jr(s,r.conv256_2),s=Pl(s,r.conv256_down_out);var u=s.mean([1,2]),c=hl(u,r.fc);return c})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.computeFaceDescriptor=function(e){return $e(this,void 0,void 0,function(){var r,o,a,i=this;return ke(this,function(s){switch(s.label){case 0:return[4,Zt(e)];case 1:return r=s.sent(),o=xe(function(){return Ut(i.forwardInput(r))}),[4,Promise.all(o.map(function(u){return u.data()}))];case 2:return a=s.sent(),o.forEach(function(u){return u.dispose()}),[2,r.isBatchInput?a:a[0]]}})})},t.prototype.getDefaultModelName=function(){return"face_recognition_model"},t.prototype.extractParamsFromWeigthMap=function(e){return a9(e)},t.prototype.extractParams=function(e){return r9(e)},t}(lo);function E2(n,t){var e={descriptor:t};return Object.assign({},n,e)}function S2(n,t){var e={age:t};return Object.assign({},n,e)}function N2(n,t,e){var r={gender:t,genderProbability:e};return Object.assign({},n,r)}var $2=function(){function n(t){var e=t===void 0?{}:t,r=e.minFaceSize,o=e.scaleFactor,a=e.maxNumScales,i=e.scoreThresholds,s=e.scaleSteps;if(this._name="MtcnnOptions",this._minFaceSize=r||20,this._scaleFactor=o||.709,this._maxNumScales=a||10,this._scoreThresholds=i||[.6,.7,.7],this._scaleSteps=s,typeof this._minFaceSize!="number"||this._minFaceSize<0)throw new Error(this._name+" - expected minFaceSize to be a number > 0");if(typeof this._scaleFactor!="number"||this._scaleFactor<=0||this._scaleFactor>=1)throw new Error(this._name+" - expected scaleFactor to be a number between 0 and 1");if(typeof this._maxNumScales!="number"||this._maxNumScales<0)throw new Error(this._name+" - expected maxNumScales to be a number > 0");if(!Array.isArray(this._scoreThresholds)||this._scoreThresholds.length!==3||this._scoreThresholds.some(function(u){return typeof u!="number"}))throw new 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(u){return typeof u!="number"})))throw new Error(this._name+" - expected scaleSteps to be an array of numbers")}return Object.defineProperty(n.prototype,"minFaceSize",{get:function(){return this._minFaceSize},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"scaleFactor",{get:function(){return this._scaleFactor},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"maxNumScales",{get:function(){return this._maxNumScales},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"scoreThresholds",{get:function(){return this._scoreThresholds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"scaleSteps",{get:function(){return this._scaleSteps},enumerable:!0,configurable:!0}),n}();function s9(n,t){function e(u,c){var l=Sn(n(9*u),[3,3,u,1]),d=Dt(n(u)),f=Dt(n(u)),h=Dt(n(u)),m=Dt(n(u));return t.push({paramPath:c+"/filters"},{paramPath:c+"/batch_norm_scale"},{paramPath:c+"/batch_norm_offset"},{paramPath:c+"/batch_norm_mean"},{paramPath:c+"/batch_norm_variance"}),{filters:l,batch_norm_scale:d,batch_norm_offset:f,batch_norm_mean:h,batch_norm_variance:m}}function r(u,c,l,d,f){var h=Sn(n(u*c*l*l),[l,l,u,c]),m=Dt(n(c));return t.push({paramPath:d+"/filters"},{paramPath:d+"/"+(f?"batch_norm_offset":"bias")}),{filters:h,bias:m}}function o(u,c,l,d){var f=r(u,c,l,d,!0),h=f.filters,m=f.bias;return{filters:h,batch_norm_offset:m}}function a(u,c,l){var d=e(u,l+"/depthwise_conv"),f=o(u,c,1,l+"/pointwise_conv");return{depthwise_conv:d,pointwise_conv:f}}function i(){var u=o(3,32,3,"mobilenetv1/conv_0"),c=a(32,64,"mobilenetv1/conv_1"),l=a(64,128,"mobilenetv1/conv_2"),d=a(128,128,"mobilenetv1/conv_3"),f=a(128,256,"mobilenetv1/conv_4"),h=a(256,256,"mobilenetv1/conv_5"),m=a(256,512,"mobilenetv1/conv_6"),v=a(512,512,"mobilenetv1/conv_7"),p=a(512,512,"mobilenetv1/conv_8"),g=a(512,512,"mobilenetv1/conv_9"),b=a(512,512,"mobilenetv1/conv_10"),w=a(512,512,"mobilenetv1/conv_11"),x=a(512,1024,"mobilenetv1/conv_12"),C=a(1024,1024,"mobilenetv1/conv_13");return{conv_0:u,conv_1:c,conv_2:l,conv_3:d,conv_4:f,conv_5:h,conv_6:m,conv_7:v,conv_8:p,conv_9:g,conv_10:b,conv_11:w,conv_12:x,conv_13:C}}function s(){var u=o(1024,256,1,"prediction_layer/conv_0"),c=o(256,512,3,"prediction_layer/conv_1"),l=o(512,128,1,"prediction_layer/conv_2"),d=o(128,256,3,"prediction_layer/conv_3"),f=o(256,128,1,"prediction_layer/conv_4"),h=o(128,256,3,"prediction_layer/conv_5"),m=o(256,64,1,"prediction_layer/conv_6"),v=o(64,128,3,"prediction_layer/conv_7"),p=r(512,12,1,"prediction_layer/box_predictor_0/box_encoding_predictor"),g=r(512,9,1,"prediction_layer/box_predictor_0/class_predictor"),b=r(1024,24,1,"prediction_layer/box_predictor_1/box_encoding_predictor"),w=r(1024,18,1,"prediction_layer/box_predictor_1/class_predictor"),x=r(512,24,1,"prediction_layer/box_predictor_2/box_encoding_predictor"),C=r(512,18,1,"prediction_layer/box_predictor_2/class_predictor"),_=r(256,24,1,"prediction_layer/box_predictor_3/box_encoding_predictor"),E=r(256,18,1,"prediction_layer/box_predictor_3/class_predictor"),$=r(256,24,1,"prediction_layer/box_predictor_4/box_encoding_predictor"),S=r(256,18,1,"prediction_layer/box_predictor_4/class_predictor"),N=r(128,24,1,"prediction_layer/box_predictor_5/box_encoding_predictor"),F=r(128,18,1,"prediction_layer/box_predictor_5/class_predictor"),I={box_encoding_predictor:p,class_predictor:g},j={box_encoding_predictor:b,class_predictor:w},L={box_encoding_predictor:x,class_predictor:C},z={box_encoding_predictor:_,class_predictor:E},H={box_encoding_predictor:$,class_predictor:S},M={box_encoding_predictor:N,class_predictor:F};return{conv_0:u,conv_1:c,conv_2:l,conv_3:d,conv_4:f,conv_5:h,conv_6:m,conv_7:v,box_predictor_0:I,box_predictor_1:j,box_predictor_2:L,box_predictor_3:z,box_predictor_4:H,box_predictor_5:M}}return{extractMobilenetV1Params:i,extractPredictionLayerParams:s}}function u9(n){var t=[],e=ho(n),r=e.extractWeights,o=e.getRemainingWeights,a=s9(r,t),i=a.extractMobilenetV1Params,s=a.extractPredictionLayerParams,u=i(),c=s(),l=Kf(r(5118*4),[1,5118,4]),d={extra_dim:l};if(t.push({paramPath:"output_layer/extra_dim"}),o().length!==0)throw new Error("weights remaing after extract: "+o().length);return{params:{mobilenetv1:u,prediction_layer:c,output_layer:d},paramMappings:t}}function c9(n,t){var e=qo(n,t);function r(c,l,d){var f=e(c+"/Conv2d_"+l+"_pointwise/weights",4,d+"/filters"),h=e(c+"/Conv2d_"+l+"_pointwise/convolution_bn_offset",1,d+"/batch_norm_offset");return{filters:f,batch_norm_offset:h}}function o(c){var l="mobilenetv1/conv_"+c,d="MobilenetV1/Conv2d_"+c+"_depthwise",f=l+"/depthwise_conv",h=l+"/pointwise_conv",m=e(d+"/depthwise_weights",4,f+"/filters"),v=e(d+"/BatchNorm/gamma",1,f+"/batch_norm_scale"),p=e(d+"/BatchNorm/beta",1,f+"/batch_norm_offset"),g=e(d+"/BatchNorm/moving_mean",1,f+"/batch_norm_mean"),b=e(d+"/BatchNorm/moving_variance",1,f+"/batch_norm_variance");return{depthwise_conv:{filters:m,batch_norm_scale:v,batch_norm_offset:p,batch_norm_mean:g,batch_norm_variance:b},pointwise_conv:r("MobilenetV1",c,h)}}function a(){return{conv_0:r("MobilenetV1",0,"mobilenetv1/conv_0"),conv_1:o(1),conv_2:o(2),conv_3:o(3),conv_4:o(4),conv_5:o(5),conv_6:o(6),conv_7:o(7),conv_8:o(8),conv_9:o(9),conv_10:o(10),conv_11:o(11),conv_12:o(12),conv_13:o(13)}}function i(c,l){var d=e(c+"/weights",4,l+"/filters"),f=e(c+"/biases",1,l+"/bias");return{filters:d,bias:f}}function s(c){var l=i("Prediction/BoxPredictor_"+c+"/BoxEncodingPredictor","prediction_layer/box_predictor_"+c+"/box_encoding_predictor"),d=i("Prediction/BoxPredictor_"+c+"/ClassPredictor","prediction_layer/box_predictor_"+c+"/class_predictor");return{box_encoding_predictor:l,class_predictor:d}}function u(){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:u}}function l9(n){var t=[],e=c9(n,t),r=e.extractMobilenetV1Params,o=e.extractPredictionLayerParams,a=n["Output/extra_dim"];if(t.push({originalPath:"Output/extra_dim",paramPath:"output_layer/extra_dim"}),!xl(a))throw new Error("expected weightMap['Output/extra_dim'] to be a Tensor3D, instead have "+a);var i={mobilenetv1:r(),prediction_layer:o(),output_layer:{extra_dim:a}};return fo(n,t),{params:i,paramMappings:t}}function Ur(n,t,e){return xe(function(){var r=Zn(n,t.filters,e,"same");return r=qe(r,t.batch_norm_offset),mh(r,0,6)})}var d9=.0010000000474974513;function f9(n,t,e){return xe(function(){var r=fl(n,t.filters,e,"same");return r=Q1(r,t.batch_norm_mean,t.batch_norm_variance,t.batch_norm_offset,t.batch_norm_scale,d9),mh(r,0,6)})}function h9(n){return[2,4,6,12].some(function(t){return t===n})?[2,2]:[1,1]}function p9(n,t){return xe(function(){var e=null,r=Ur(n,t.conv_0,[2,2]),o=[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];if(o.forEach(function(a,i){var s=i+1,u=h9(s);r=f9(r,a.depthwise_conv,u),r=Ur(r,a.pointwise_conv,[1,1]),s===11&&(e=r)}),e===null)throw new Error("mobileNetV1 - output of conv layer 11 is null");return{out:r,conv11:e}})}function v9(n,t,e,r,o){var a=n.shape[0],i=Math.min(e,a),s=t.map(function(l,d){return{score:l,boxIndex:d}}).filter(function(l){return l.score>o}).sort(function(l,d){return d.score-l.score}),u=function(l){return l<=r?1:0},c=[];return s.forEach(function(l){if(!(c.length>=i)){for(var d=l.score,f=c.length-1;f>=0;--f){var h=m9(n,l.boxIndex,c[f]);if(h!==0&&(l.score*=u(h),l.score<=o))break}d===l.score&&c.push(l.boxIndex)}}),c}function m9(n,t,e){var r=n.arraySync(),o=Math.min(r[t][0],r[t][2]),a=Math.min(r[t][1],r[t][3]),i=Math.max(r[t][0],r[t][2]),s=Math.max(r[t][1],r[t][3]),u=Math.min(r[e][0],r[e][2]),c=Math.min(r[e][1],r[e][3]),l=Math.max(r[e][0],r[e][2]),d=Math.max(r[e][1],r[e][3]),f=(i-o)*(s-a),h=(l-u)*(d-c);if(f<=0||h<=0)return 0;var m=Math.max(o,u),v=Math.max(a,c),p=Math.min(i,l),g=Math.min(s,d),b=Math.max(p-m,0)*Math.max(g-v,0);return b/(f+h-b)}function g9(n){var t=Ut(jo(n,[1,0])),e=[Ht(t[2],t[0]),Ht(t[3],t[1])],r=[qe(t[0],ur(e[0],ve(2))),qe(t[1],ur(e[1],ve(2)))];return{sizes:e,centers:r}}function y9(n,t){var e=g9(n),r=e.sizes,o=e.centers,a=Ut(jo(t,[1,0])),i=ur(fn(gh(ur(a[2],ve(5))),r[0]),ve(2)),s=qe(fn(ur(a[0],ve(10)),r[0]),o[0]),u=ur(fn(gh(ur(a[3],ve(5))),r[1]),ve(2)),c=qe(fn(ur(a[1],ve(10)),r[1]),o[1]);return jo(Bn([Ht(s,i),Ht(c,u),qe(s,i),qe(c,u)]),[1,0])}function b9(n,t,e){return xe(function(){var r=n.shape[0],o=y9(ir(ki(e.extra_dim,[r,1,1]),[-1,4]),ir(n,[-1,4]));o=ir(o,[r,o.shape[0]/r,4]);var a=K1(Br(t,[0,0,1],[-1,-1,-1])),i=Br(a,[0,0,0],[-1,-1,1]);i=ir(i,[r,i.shape[1]]);var s=Ut(o),u=Ut(i);return{boxes:s,scores:u}})}function ji(n,t){return xe(function(){var e=n.shape[0],r=ir(cr(n,t.box_encoding_predictor),[e,-1,1,4]),o=ir(cr(n,t.class_predictor),[e,-1,3]);return{boxPredictionEncoding:r,classPrediction:o}})}function x9(n,t,e){return xe(function(){var r=Ur(n,e.conv_0,[1,1]),o=Ur(r,e.conv_1,[2,2]),a=Ur(o,e.conv_2,[1,1]),i=Ur(a,e.conv_3,[2,2]),s=Ur(i,e.conv_4,[1,1]),u=Ur(s,e.conv_5,[2,2]),c=Ur(u,e.conv_6,[1,1]),l=Ur(c,e.conv_7,[2,2]),d=ji(t,e.box_predictor_0),f=ji(n,e.box_predictor_1),h=ji(o,e.box_predictor_2),m=ji(i,e.box_predictor_3),v=ji(u,e.box_predictor_4),p=ji(l,e.box_predictor_5),g=jt([d.boxPredictionEncoding,f.boxPredictionEncoding,h.boxPredictionEncoding,m.boxPredictionEncoding,v.boxPredictionEncoding,p.boxPredictionEncoding],1),b=jt([d.classPrediction,f.classPrediction,h.classPrediction,m.classPrediction,v.classPrediction,p.classPrediction],1);return{boxPredictions:g,classPredictions:b}})}var pu=function(){function n(t){var e=t===void 0?{}:t,r=e.minConfidence,o=e.maxResults;if(this._name="SsdMobilenetv1Options",this._minConfidence=r||.5,this._maxResults=o||100,typeof this._minConfidence!="number"||this._minConfidence<=0||this._minConfidence>=1)throw new Error(this._name+" - expected minConfidence to be a number between 0 and 1");if(typeof this._maxResults!="number")throw new Error(this._name+" - expected maxResults to be a number")}return Object.defineProperty(n.prototype,"minConfidence",{get:function(){return this._minConfidence},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"maxResults",{get:function(){return this._maxResults},enumerable:!0,configurable:!0}),n}(),k2=function(n){De(t,n);function t(){return n.call(this,"SsdMobilenetv1")||this}return t.prototype.forwardInput=function(e){var r=this.params;if(!r)throw new Error("SsdMobilenetv1 - load model before inference");return xe(function(){var o=e.toBatchTensor(512,!1).toFloat(),a=Ht(fn(o,ve(.007843137718737125)),ve(1)),i=p9(a,r.mobilenetv1),s=x9(i.out,i.conv11,r.prediction_layer),u=s.boxPredictions,c=s.classPredictions;return b9(u,c,r.output_layer)})},t.prototype.forward=function(e){return $e(this,void 0,void 0,function(){var r;return ke(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,Zt(e)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.locateFaces=function(e,r){return r===void 0&&(r={}),$e(this,void 0,void 0,function(){var o,a,i,s,u,c,l,d,f,h,m,v,p,g,b,w,x,C,_,E,$;return ke(this,function(S){switch(S.label){case 0:return o=new pu(r),a=o.maxResults,i=o.minConfidence,[4,Zt(e)];case 1:for(s=S.sent(),u=this.forwardInput(s),c=u.boxes,l=u.scores,d=c[0],f=l[0],h=1;h<c.length;h++)c[h].dispose(),l[h].dispose();return p=(v=Array).from,[4,f.data()];case 2:return m=p.apply(v,[S.sent()]),g=.5,b=v9(d,m,a,g,i),w=s.getReshapedInputDimensions(0),x=s.inputSize,C=x/w.width,_=x/w.height,E=d.arraySync(),$=b.map(function(N){var F=[Math.max(0,E[N][0]),Math.min(1,E[N][2])].map(function(M){return M*_}),I=F[0],j=F[1],L=[Math.max(0,E[N][1]),Math.min(1,E[N][3])].map(function(M){return M*C}),z=L[0],H=L[1];return new Wr(m[N],new Yh(z,I,H-z,j-I),{height:s.getInputHeight(0),width:s.getInputWidth(0)})}),d.dispose(),f.dispose(),[2,$]}})})},t.prototype.getDefaultModelName=function(){return"ssd_mobilenetv1_model"},t.prototype.extractParamsFromWeigthMap=function(e){return l9(e)},t.prototype.extractParams=function(e){return u9(e)},t}(lo);(function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t})(k2);var w9=.4,C9=[new ct(.738768,.874946),new ct(2.42204,2.65704),new ct(4.30971,7.04493),new ct(10.246,4.59428),new ct(12.6868,11.8741)],_9=[new ct(1.603231,2.094468),new ct(6.041143,7.080126),new ct(2.882459,3.518061),new ct(4.266906,5.178857),new ct(9.041765,10.66308)],E9=[117.001,114.697,97.404],S9="tiny_yolov2_model",N9="tiny_yolov2_separable_conv_model",Il=function(n){return typeof n=="number"};function $9(n){if(!n)throw new Error("invalid config: "+n);if(typeof n.withSeparableConvs!="boolean")throw new Error("config.withSeparableConvs has to be a boolean, have: "+n.withSeparableConvs);if(!Il(n.iouThreshold)||n.iouThreshold<0||n.iouThreshold>1)throw new Error("config.iouThreshold has to be a number between [0, 1], have: "+n.iouThreshold);if(!Array.isArray(n.classes)||!n.classes.length||!n.classes.every(function(t){return typeof t=="string"}))throw new Error("config.classes has to be an array class names: string[], have: "+JSON.stringify(n.classes));if(!Array.isArray(n.anchors)||!n.anchors.length||!n.anchors.map(function(t){return t||{}}).every(function(t){return Il(t.x)&&Il(t.y)}))throw new Error("config.anchors has to be an array of { x: number, y: number }, have: "+JSON.stringify(n.anchors));if(n.meanRgb&&(!Array.isArray(n.meanRgb)||n.meanRgb.length!==3||!n.meanRgb.every(Il)))throw new Error("config.meanRgb has to be an array of shape [number, number, number], have: "+JSON.stringify(n.meanRgb))}function cp(n){return xe(function(){var t=fn(n,ve(.10000000149011612));return qe(kt(Ht(n,t)),t)})}function Ko(n,t){return xe(function(){var e=Fa(n,[[0,0],[1,1],[1,1],[0,0]]);return e=Zn(e,t.conv.filters,[1,1],"valid"),e=Ht(e,t.bn.sub),e=fn(e,t.bn.truediv),e=qe(e,t.conv.bias),cp(e)})}function Yo(n,t){return xe(function(){var e=Fa(n,[[0,0],[1,1],[1,1],[0,0]]);return e=Ch(e,t.depthwise_filter,t.pointwise_filter,[1,1],"valid"),e=qe(e,t.bias),cp(e)})}function k9(n,t){var e=$l(n,t);function r(i,s){var u=Dt(n(i)),c=Dt(n(i));return t.push({paramPath:s+"/sub"},{paramPath:s+"/truediv"}),{sub:u,truediv:c}}function o(i,s,u){var c=e(i,s,3,u+"/conv"),l=r(s,u+"/bn");return{conv:c,bn:l}}var a=op(n,t);return{extractConvParams:e,extractConvWithBatchNormParams:o,extractSeparableConvParams:a}}function P9(n,t,e,r){var o=ho(n),a=o.extractWeights,i=o.getRemainingWeights,s=[],u=k9(a,s),c=u.extractConvParams,l=u.extractConvWithBatchNormParams,d=u.extractSeparableConvParams,f;if(t.withSeparableConvs){var h=r[0],m=r[1],v=r[2],p=r[3],g=r[4],b=r[5],w=r[6],x=r[7],C=r[8],_=t.isFirstLayerConv2d?c(h,m,3,"conv0"):d(h,m,"conv0"),E=d(m,v,"conv1"),$=d(v,p,"conv2"),S=d(p,g,"conv3"),N=d(g,b,"conv4"),F=d(b,w,"conv5"),I=x?d(w,x,"conv6"):void 0,j=C?d(x,C,"conv7"):void 0,L=c(C||x||w,5*e,1,"conv8");f={conv0:_,conv1:E,conv2:$,conv3:S,conv4:N,conv5:F,conv6:I,conv7:j,conv8:L}}else{var h=r[0],m=r[1],v=r[2],p=r[3],g=r[4],b=r[5],w=r[6],x=r[7],C=r[8],_=l(h,m,"conv0"),E=l(m,v,"conv1"),$=l(v,p,"conv2"),S=l(p,g,"conv3"),N=l(g,b,"conv4"),F=l(b,w,"conv5"),I=l(w,x,"conv6"),j=l(x,C,"conv7"),L=c(C,5*e,1,"conv8");f={conv0:_,conv1:E,conv2:$,conv3:S,conv4:N,conv5:F,conv6:I,conv7:j,conv8:L}}if(i().length!==0)throw new Error("weights remaing after extract: "+i().length);return{params:f,paramMappings:s}}function I9(n,t){var e=qo(n,t);function r(s){var u=e(s+"/sub",1),c=e(s+"/truediv",1);return{sub:u,truediv:c}}function o(s){var u=e(s+"/filters",4),c=e(s+"/bias",1);return{filters:u,bias:c}}function a(s){var u=o(s+"/conv"),c=r(s+"/bn");return{conv:u,bn:c}}var i=ap(e);return{extractConvParams:o,extractConvWithBatchNormParams:a,extractSeparableConvParams:i}}function A9(n,t){var e=[],r=I9(n,e),o=r.extractConvParams,a=r.extractConvWithBatchNormParams,i=r.extractSeparableConvParams,s;if(t.withSeparableConvs){var u=t.filterSizes&&t.filterSizes.length||9;s={conv0:t.isFirstLayerConv2d?o("conv0"):i("conv0"),conv1:i("conv1"),conv2:i("conv2"),conv3:i("conv3"),conv4:i("conv4"),conv5:i("conv5"),conv6:u>7?i("conv6"):void 0,conv7:u>8?i("conv7"):void 0,conv8:o("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:o("conv8")};return fo(n,e),{params:s,paramMappings:e}}var P2;(function(n){n[n.XS=224]="XS",n[n.SM=320]="SM",n[n.MD=416]="MD",n[n.LG=608]="LG"})(P2||(P2={}));var lp=function(){function n(t){var e=t===void 0?{}:t,r=e.inputSize,o=e.scoreThreshold;if(this._name="TinyYolov2Options",this._inputSize=r||416,this._scoreThreshold=o||.5,typeof this._inputSize!="number"||this._inputSize%32!==0)throw new Error(this._name+" - expected inputSize to be a number divisible by 32");if(typeof this._scoreThreshold!="number"||this._scoreThreshold<=0||this._scoreThreshold>=1)throw new Error(this._name+" - expected scoreThreshold to be a number between 0 and 1")}return Object.defineProperty(n.prototype,"inputSize",{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"scoreThreshold",{get:function(){return this._scoreThreshold},enumerable:!0,configurable:!0}),n}(),I2=function(n){De(t,n);function t(e){var r=n.call(this,"TinyYolov2")||this;return $9(e),r._config=e,r}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,r){var o=Ko(e,r.conv0);return o=Xt(o,[2,2],[2,2],"same"),o=Ko(o,r.conv1),o=Xt(o,[2,2],[2,2],"same"),o=Ko(o,r.conv2),o=Xt(o,[2,2],[2,2],"same"),o=Ko(o,r.conv3),o=Xt(o,[2,2],[2,2],"same"),o=Ko(o,r.conv4),o=Xt(o,[2,2],[2,2],"same"),o=Ko(o,r.conv5),o=Xt(o,[2,2],[1,1],"same"),o=Ko(o,r.conv6),o=Ko(o,r.conv7),cr(o,r.conv8,"valid",!1)},t.prototype.runMobilenet=function(e,r){var o=this.config.isFirstLayerConv2d?cp(cr(e,r.conv0,"valid",!1)):Yo(e,r.conv0);return o=Xt(o,[2,2],[2,2],"same"),o=Yo(o,r.conv1),o=Xt(o,[2,2],[2,2],"same"),o=Yo(o,r.conv2),o=Xt(o,[2,2],[2,2],"same"),o=Yo(o,r.conv3),o=Xt(o,[2,2],[2,2],"same"),o=Yo(o,r.conv4),o=Xt(o,[2,2],[2,2],"same"),o=Yo(o,r.conv5),o=Xt(o,[2,2],[1,1],"same"),o=r.conv6?Yo(o,r.conv6):o,o=r.conv7?Yo(o,r.conv7):o,cr(o,r.conv8,"valid",!1)},t.prototype.forwardInput=function(e,r){var o=this,a=this.params;if(!a)throw new Error("TinyYolov2 - load model before inference");return xe(function(){var i=e.toBatchTensor(r,!1).toFloat();return i=o.config.meanRgb?hu(i,o.config.meanRgb):i,i=i.div(ve(256)),o.config.withSeparableConvs?o.runMobilenet(i,a):o.runTinyYolov2(i,a)})},t.prototype.forward=function(e,r){return $e(this,void 0,void 0,function(){var o;return ke(this,function(a){switch(a.label){case 0:return o=this.forwardInput,[4,Zt(e)];case 1:return[4,o.apply(this,[a.sent(),r])];case 2:return[2,a.sent()]}})})},t.prototype.detect=function(e,r){return r===void 0&&(r={}),$e(this,void 0,void 0,function(){var o,a,i,s,u,c,l,d,f,h,m,v,p,g,b=this;return ke(this,function(w){switch(w.label){case 0:return o=new lp(r),a=o.inputSize,i=o.scoreThreshold,[4,Zt(e)];case 1:return s=w.sent(),[4,this.forwardInput(s,a)];case 2:return u=w.sent(),c=xe(function(){return Ut(u)[0].expandDims()}),l={width:s.getInputWidth(0),height:s.getInputHeight(0)},[4,this.extractBoxes(c,s.getReshapedInputDimensions(0),i)];case 3:return d=w.sent(),u.dispose(),c.dispose(),f=d.map(function(x){return x.box}),h=d.map(function(x){return x.score}),m=d.map(function(x){return x.classScore}),v=d.map(function(x){return b.config.classes[x.label]}),p=fu(f.map(function(x){return x.rescale(a)}),h,this.config.iouThreshold,!0),g=p.map(function(x){return new Xb(h[x],m[x],v[x],f[x],l)}),[2,g]}})})},t.prototype.getDefaultModelName=function(){return""},t.prototype.extractParamsFromWeigthMap=function(e){return A9(e,this.config)},t.prototype.extractParams=function(e){var r=this.config.filterSizes||t.DEFAULT_FILTER_SIZES,o=r?r.length:void 0;if(o!==7&&o!==8&&o!==9)throw new Error("TinyYolov2 - expected 7 | 8 | 9 convolutional filters, but found "+o+" filterSizes in config");return P9(e,this.config,this.boxEncodingSize,r)},t.prototype.extractBoxes=function(e,r,o){return $e(this,void 0,void 0,function(){var a,i,s,u,c,l,d,f,h,m,v,p,g,b,w,x,C,_,E,$,S,N,F,I,j,L,z,H,M,T=this;return ke(this,function(A){switch(A.label){case 0:return a=r.width,i=r.height,s=Math.max(a,i),u=s/a,c=s/i,l=e.shape[1],d=this.config.anchors.length,f=xe(function(){var P=e.reshape([l,l,d,T.boxEncodingSize]),B=P.slice([0,0,0,0],[l,l,d,4]),K=P.slice([0,0,0,4],[l,l,d,1]),q=T.withClassScores?io(P.slice([0,0,0,5],[l,l,d,T.config.classes.length]),3):ve(0);return[B,K,q]}),h=f[0],m=f[1],v=f[2],p=[],[4,m.array()];case 1:return g=A.sent(),[4,h.array()];case 2:b=A.sent(),w=0,A.label=3;case 3:if(!(w<l))return[3,12];x=0,A.label=4;case 4:if(!(x<l))return[3,11];C=0,A.label=5;case 5:return C<d?(_=Kh(g[w][x][C][0]),!o||_>o?(E=(x+Kh(b[w][x][C][0]))/l*u,$=(w+Kh(b[w][x][C][1]))/l*c,S=Math.exp(b[w][x][C][2])*this.config.anchors[C].x/l*u,N=Math.exp(b[w][x][C][3])*this.config.anchors[C].y/l*c,F=E-S/2,I=$-N/2,j={row:w,col:x,anchor:C},this.withClassScores?[4,this.extractPredictedClass(v,j)]:[3,7]):[3,9]):[3,10];case 6:return M=A.sent(),[3,8];case 7:M={classScore:1,label:0},A.label=8;case 8:L=M,z=L.classScore,H=L.label,p.push(pn({box:new wl(F,I,F+S,I+N),score:_,classScore:_*z,label:H},j)),A.label=9;case 9:return C++,[3,5];case 10:return x++,[3,4];case 11:return w++,[3,3];case 12:return h.dispose(),m.dispose(),v.dispose(),[2,p]}})})},t.prototype.extractPredictedClass=function(e,r){return $e(this,void 0,void 0,function(){var o,a,i,s;return ke(this,function(u){switch(u.label){case 0:return o=r.row,a=r.col,i=r.anchor,[4,e.array()];case 1:return s=u.sent(),[2,Array(this.config.classes.length).fill(0).map(function(c,l){return s[o][a][i][l]}).map(function(c,l){return{classScore:c,label:l}}).reduce(function(c,l){return c.classScore>l.classScore?c:l})]}})})},t.DEFAULT_FILTER_SIZES=[3,16,32,64,128,256,512,1024,1024],t}(lo),T9=function(n){De(t,n);function t(e){e===void 0&&(e=!0);var r=this,o=Object.assign({},{withSeparableConvs:e,iouThreshold:w9,classes:["face"]},e?{anchors:_9,meanRgb:E9}:{anchors:C9,withClassScores:!0});return r=n.call(this,o)||this,r}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,r){return $e(this,void 0,void 0,function(){var o;return ke(this,function(a){switch(a.label){case 0:return[4,this.detect(e,r)];case 1:return o=a.sent(),[2,o.map(function(i){return new Wr(i.score,i.relativeBox,{width:i.imageWidth,height:i.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return this.withSeparableConvs?N9:S9},t.prototype.extractParamsFromWeigthMap=function(e){return n.prototype.extractParamsFromWeigthMap.call(this,e)},t}(I2),O9=function(n){De(t,n);function t(){var e=n!==null&&n.apply(this,arguments)||this;return e._name="TinyFaceDetectorOptions",e}return t}(lp),vu=function(){function n(){}return n.prototype.then=function(t){return $e(this,void 0,void 0,function(){var e;return ke(this,function(r){switch(r.label){case 0:return e=t,[4,this.run()];case 1:return[2,e.apply(void 0,[r.sent()])]}})})},n.prototype.run=function(){return $e(this,void 0,void 0,function(){return ke(this,function(t){throw new Error("ComposableTask - run is not implemented")})})},n}();function Al(n,t,e,r,o){return o===void 0&&(o=function(a){var i=a.alignedRect;return i}),$e(this,void 0,void 0,function(){var a,i,s,u,c;return ke(this,function(l){switch(l.label){case 0:return a=n.map(function(d){return W5(d)?o(d):d.detection}),s=r,s?[3,5]:t instanceof Nt?[4,tp(t,a)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,ep(t,a)];case 3:u=l.sent(),l.label=4;case 4:s=u,l.label=5;case 5:return i=s,[4,e(i)];case 6:return c=l.sent(),i.forEach(function(d){return d instanceof Nt&&d.dispose()}),[2,c]}})})}function dp(n,t,e,r,o){return $e(this,void 0,void 0,function(){var a=this;return ke(this,function(i){return[2,Al([n],t,function(s){return $e(a,void 0,void 0,function(){return ke(this,function(u){return[2,e(s[0])]})})},r,o)]})})}function D9(n){return xe(function(){return Bn(Ut(n,3).reverse(),3)})}var Tl=2,Ol=12;function F9(n,t){var e=$l(n,t),r=rp(n,t);function o(c,l){var d=Dt(n(c));return t.push({paramPath:l}),d}function a(c,l,d){d===void 0&&(d=!1);var f=e(c[0],c[1],3,l+"/conv1"),h=o(c[1],l+"/prelu1_alpha"),m=e(c[1],c[2],3,l+"/conv2"),v=o(c[2],l+"/prelu2_alpha"),p=e(c[2],c[3],d?2:3,l+"/conv3"),g=o(c[3],l+"/prelu3_alpha");return{conv1:f,prelu1_alpha:h,conv2:m,prelu2_alpha:v,conv3:p,prelu3_alpha:g}}function i(){var c=a([3,10,16,32],"pnet"),l=e(32,2,1,"pnet/conv4_1"),d=e(32,4,1,"pnet/conv4_2");return pn(pn({},c),{conv4_1:l,conv4_2:d})}function s(){var c=a([3,28,48,64],"rnet",!0),l=r(576,128,"rnet/fc1"),d=o(128,"rnet/prelu4_alpha"),f=r(128,2,"rnet/fc2_1"),h=r(128,4,"rnet/fc2_2");return pn(pn({},c),{fc1:l,prelu4_alpha:d,fc2_1:f,fc2_2:h})}function u(){var c=a([3,32,64,64],"onet"),l=e(64,128,2,"onet/conv4"),d=o(128,"onet/prelu4_alpha"),f=r(1152,256,"onet/fc1"),h=o(256,"onet/prelu5_alpha"),m=r(256,2,"onet/fc2_1"),v=r(256,4,"onet/fc2_2"),p=r(256,10,"onet/fc2_3");return pn(pn({},c),{conv4:l,prelu4_alpha:d,fc1:f,prelu5_alpha:h,fc2_1:m,fc2_2:v,fc2_3:p})}return{extractPNetParams:i,extractRNetParams:s,extractONetParams:u}}function M9(n){var t=ho(n),e=t.extractWeights,r=t.getRemainingWeights,o=[],a=F9(e,o),i=a.extractPNetParams,s=a.extractRNetParams,u=a.extractONetParams,c=i(),l=s(),d=u();if(r().length!==0)throw new Error("weights remaing after extract: "+r().length);return{params:{pnet:c,rnet:l,onet:d},paramMappings:o}}function R9(n,t){var e=qo(n,t);function r(l){var d=e(l+"/weights",4,l+"/filters"),f=e(l+"/bias",1);return{filters:d,bias:f}}function o(l){var d=e(l+"/weights",2),f=e(l+"/bias",1);return{weights:d,bias:f}}function a(l){return e(l,1)}function i(l){var d=r(l+"/conv1"),f=a(l+"/prelu1_alpha"),h=r(l+"/conv2"),m=a(l+"/prelu2_alpha"),v=r(l+"/conv3"),p=a(l+"/prelu3_alpha");return{conv1:d,prelu1_alpha:f,conv2:h,prelu2_alpha:m,conv3:v,prelu3_alpha:p}}function s(){var l=i("pnet"),d=r("pnet/conv4_1"),f=r("pnet/conv4_2");return pn(pn({},l),{conv4_1:d,conv4_2:f})}function u(){var l=i("rnet"),d=o("rnet/fc1"),f=a("rnet/prelu4_alpha"),h=o("rnet/fc2_1"),m=o("rnet/fc2_2");return pn(pn({},l),{fc1:d,prelu4_alpha:f,fc2_1:h,fc2_2:m})}function c(){var l=i("onet"),d=r("onet/conv4"),f=a("onet/prelu4_alpha"),h=o("onet/fc1"),m=a("onet/prelu5_alpha"),v=o("onet/fc2_1"),p=o("onet/fc2_2"),g=o("onet/fc2_3");return pn(pn({},l),{conv4:d,prelu4_alpha:f,fc1:h,prelu5_alpha:m,fc2_1:v,fc2_2:p,fc2_3:g})}return{extractPNetParams:s,extractRNetParams:u,extractONetParams:c}}function L9(n){var t=[],e=R9(n,t),r=e.extractPNetParams,o=e.extractRNetParams,a=e.extractONetParams,i=r(),s=o(),u=a();return fo(n,t),{params:{pnet:i,rnet:s,onet:u},paramMappings:t}}function fp(n,t){var e=t[0],r=t[1];return{height:Math.floor(e*n),width:Math.floor(r*n)}}function B9(n,t,e){for(var r=e[0],o=e[1],a=Ol/n,i=[],s=Math.min(r,o)*a,u=0;s>=12;)i.push(a*Math.pow(t,u)),s=s*t,u+=1;return i}var hp=function(n){De(t,n);function t(e,r,o,a){return n.call(this,{left:e,top:r,right:o,bottom:a},!0)||this}return t}(Go);function A2(n){return xe(function(){return fn(Ht(n,ve(127.5)),ve(.0078125))})}function Ui(n,t){return xe(function(){return qe(kt(n),fn(t,sl(kt(sl(n)))))})}function pp(n,t,e){return e===void 0&&(e=!1),xe(function(){var r=cr(n,t.conv1,"valid");return r=Ui(r,t.prelu1_alpha),r=Xt(r,e?[2,2]:[3,3],[2,2],"same"),r=cr(r,t.conv2,"valid"),r=Ui(r,t.prelu2_alpha),r=e?r:Xt(r,[3,3],[2,2],"valid"),r=cr(r,t.conv3,"valid"),r=Ui(r,t.prelu3_alpha),r})}function W9(n,t){return xe(function(){var e=pp(n,t,!0),r=cr(e,t.conv4_1,"valid"),o=Xn(pl(r,3),3),a=io(Ht(r,o),3),i=cr(e,t.conv4_2,"valid");return{prob:a,regions:i}})}function V9(n,t){return xe(function(){var e=fp(t,n.shape.slice(1)),r=e.height,o=e.width,a=$h.resizeBilinear(n,[r,o]),i=A2(a);return jo(i,[0,2,1,3])})}function j9(n,t,e,r){for(var o=[],a=n.arraySync(),i=0;i<n.shape[0];i++)for(var s=0;s<n.shape[1];s++)a[i][s]>=r&&o.push(new ct(s,i));var u=o.map(function(c){var l=new wl(Math.round((c.y*Tl+1)/e),Math.round((c.x*Tl+1)/e),Math.round((c.y*Tl+Ol)/e),Math.round((c.x*Tl+Ol)/e)),d=a[c.y][c.x],f=t.arraySync(),h=new hp(f[c.y][c.x][0],f[c.y][c.x][1],f[c.y][c.x][2],f[c.y][c.x][3]);return{cell:l,score:d,region:h}});return u}function U9(n,t,e,r,o){o.stage1=[];var a=t.map(function(f){return xe(function(){var h={scale:f},m=V9(n,f),v=Date.now(),p=W9(m,r),g=p.prob,b=p.regions;h.pnet=Date.now()-v;var w=Ut(Ut(g,3)[1])[0],x=Ut(b)[0];return{scoresTensor:w,regionsTensor:x,scale:f,statsForScale:h}})}),i=a.map(function(f){var h=f.scoresTensor,m=f.regionsTensor,v=f.scale,p=f.statsForScale,g=j9(h,m,v,e);if(h.dispose(),m.dispose(),!g.length)return o.stage1.push(p),[];var b=Date.now(),w=fu(g.map(function(x){return x.cell}),g.map(function(x){return x.score}),.5);return p.nms=Date.now()-b,p.numBoxes=w.length,o.stage1.push(p),w.map(function(x){return g[x]})}),s=i.reduce(function(f,h){return f.concat(h)},[]),u=[],c=[];if(s.length>0){var l=Date.now(),d=fu(s.map(function(f){return f.cell}),s.map(function(f){return f.score}),.7);o.stage1_nms=Date.now()-l,c=d.map(function(f){return s[f].score}),u=d.map(function(f){return s[f]}).map(function(f){var h=f.cell,m=f.region;return new wl(h.left+m.left*h.width,h.top+m.top*h.height,h.right+m.right*h.width,h.bottom+m.bottom*h.height).toSquare().round()})}return{boxes:u,scores:c}}function T2(n,t,e){var r=e.width,o=e.height;return $e(this,void 0,void 0,function(){var a,i,s,u=this;return ke(this,function(c){switch(c.label){case 0:return a=za(n),[4,Promise.all(t.map(function(l){return $e(u,void 0,void 0,function(){var d,f,h,m,v,p,g,b;return ke(this,function(w){return d=l.padAtBorders(n.height,n.width),f=d.y,h=d.ey,m=d.x,v=d.ex,p=m-1,g=f-1,b=a.getImageData(p,g,v-p,h-g),[2,on.isNodejs()?Jh(b):createImageBitmap(b)]})})}))];case 1:return i=c.sent(),s=[],i.forEach(function(l){var d=El({width:r,height:o}),f=za(d);f.drawImage(l,0,0,r,o);for(var h=f.getImageData(0,0,r,o).data,m=[],v=0;v<h.length;v+=4)m.push(h[v+2]),m.push(h[v+1]),m.push(h[v]);s.push(m)}),[2,s.map(function(l){var d=xe(function(){var f=jo(Sn(l,[1,r,o,3]),[0,2,1,3]).toFloat();return A2(f)});return d})]}})})}function z9(n,t){return xe(function(){var e=pp(n,t),r=ir(e,[e.shape[0],t.fc1.weights.shape[0]]),o=Vr(r,t.fc1),a=Ui(o,t.prelu4_alpha),i=Vr(a,t.fc2_1),s=Xn(pl(i,1),1),u=io(Ht(i,s),1),c=Vr(a,t.fc2_2),l=Ut(u,1)[1];return{scores:l,regions:c}})}function H9(n,t,e,r,o){return $e(this,void 0,void 0,function(){var a,i,s,u,c,l,d,f,h,m,v,p,g,b;return ke(this,function(w){switch(w.label){case 0:return a=Date.now(),[4,T2(n,t,{width:24,height:24})];case 1:return i=w.sent(),o.stage2_extractImagePatches=Date.now()-a,a=Date.now(),s=i.map(function(x){var C=z9(x,r);return x.dispose(),C}),o.stage2_rnet=Date.now()-a,u=s.length>1?jt(s.map(function(x){return x.scores})):s[0].scores,d=(l=Array).from,[4,u.data()];case 2:return c=d.apply(l,[w.sent()]),u.dispose(),f=c.map(function(x,C){return{score:x,idx:C}}).filter(function(x){return x.score>e}).map(function(x){var C=x.idx;return C}),h=f.map(function(x){return t[x]}),m=f.map(function(x){return c[x]}),v=[],p=[],h.length>0&&(a=Date.now(),g=fu(h,m,.7),o.stage2_nms=Date.now()-a,b=g.map(function(x){var C=s[f[x]].regions.arraySync();return new hp(C[0][0],C[0][1],C[0][2],C[0][3])}),p=g.map(function(x){return m[x]}),v=g.map(function(x,C){return h[x].calibrate(b[C])})),s.forEach(function(x){x.regions.dispose(),x.scores.dispose()}),[2,{boxes:v,scores:p}]}})})}function G9(n,t){return xe(function(){var e=pp(n,t);e=Xt(e,[2,2],[2,2],"same"),e=cr(e,t.conv4,"valid"),e=Ui(e,t.prelu4_alpha);var r=ir(e,[e.shape[0],t.fc1.weights.shape[0]]),o=Vr(r,t.fc1),a=Ui(o,t.prelu5_alpha),i=Vr(a,t.fc2_1),s=Xn(pl(i,1),1),u=io(Ht(i,s),1),c=Vr(a,t.fc2_2),l=Vr(a,t.fc2_3),d=Ut(u,1)[1];return{scores:d,regions:c,points:l}})}function q9(n,t,e,r,o){return $e(this,void 0,void 0,function(){var a,i,s,u,c,l,d,f,h,m,v,p,g,b,w;return ke(this,function(x){switch(x.label){case 0:return a=Date.now(),[4,T2(n,t,{width:48,height:48})];case 1:return i=x.sent(),o.stage3_extractImagePatches=Date.now()-a,a=Date.now(),s=i.map(function(C){var _=G9(C,r);return C.dispose(),_}),o.stage3_onet=Date.now()-a,u=s.length>1?jt(s.map(function(C){return C.scores})):s[0].scores,d=(l=Array).from,[4,u.data()];case 2:return c=d.apply(l,[x.sent()]),u.dispose(),f=c.map(function(C,_){return{score:C,idx:_}}).filter(function(C){return C.score>e}).map(function(C){var _=C.idx;return _}),h=f.map(function(C){var _=s[C].regions.arraySync();return new hp(_[0][0],_[0][1],_[0][2],_[0][3])}),m=f.map(function(C,_){return t[C].calibrate(h[_])}),v=f.map(function(C){return c[C]}),p=[],g=[],b=[],m.length>0&&(a=Date.now(),w=fu(m,v,.7,!1),o.stage3_nms=Date.now()-a,p=w.map(function(C){return m[C]}),g=w.map(function(C){return v[C]}),b=w.map(function(C,_){return Array(5).fill(0).map(function(E,$){var S=s[C].points.arraySync();return new ct(S[0][$]*(p[_].width+1)+p[_].left,S[0][$+5]*(p[_].height+1)+p[_].top)})})),s.forEach(function(C){C.regions.dispose(),C.scores.dispose(),C.points.dispose()}),[2,{boxes:p,scores:g,points:b}]}})})}var K9=function(n){De(t,n);function t(){return n.call(this,"Mtcnn")||this}return t.prototype.load=function(e){return $e(this,void 0,void 0,function(){return ke(this,function(r){return console.warn("mtcnn is deprecated and will be removed soon"),[2,n.prototype.load.call(this,e)]})})},t.prototype.loadFromDisk=function(e){return $e(this,void 0,void 0,function(){return ke(this,function(r){return console.warn("mtcnn is deprecated and will be removed soon"),[2,n.prototype.loadFromDisk.call(this,e)]})})},t.prototype.forwardInput=function(e,r){return r===void 0&&(r={}),$e(this,void 0,void 0,function(){var o,a,i,s,u,c,l,d,f,h,m,v,p,g,b,w,x,C,_,E,$;return ke(this,function(S){switch(S.label){case 0:if(o=this.params,!o)throw new Error("Mtcnn - load model before inference");if(a=e.canvases[0],!a)throw new Error("Mtcnn - inputCanvas is not defined, note that passing tensors into Mtcnn.forwardInput is not supported yet.");return i={},s=Date.now(),u=xe(function(){return D9(Xn(Hh.fromPixels(a)).toFloat())}),c=function(N){return u.dispose(),i.total=Date.now()-s,N},l=u.shape.slice(1),d=l[0],f=l[1],h=new $2(r),m=h.minFaceSize,v=h.scaleFactor,p=h.maxNumScales,g=h.scoreThresholds,b=h.scaleSteps,w=(b||B9(m,v,[d,f])).filter(function(N){var F=fp(N,[d,f]);return Math.min(F.width,F.height)>Ol}).slice(0,p),i.scales=w,i.pyramid=w.map(function(N){return fp(N,[d,f])}),x=Date.now(),[4,U9(u,w,g[0],o.pnet,i)];case 1:return C=S.sent(),i.total_stage1=Date.now()-x,C.boxes.length?(i.stage2_numInputBoxes=C.boxes.length,x=Date.now(),[4,H9(a,C.boxes,g[1],o.rnet,i)]):[2,c({results:[],stats:i})];case 2:return _=S.sent(),i.total_stage2=Date.now()-x,_.boxes.length?(i.stage3_numInputBoxes=_.boxes.length,x=Date.now(),[4,q9(a,_.boxes,g[2],o.onet,i)]):[2,c({results:[],stats:i})];case 3:return E=S.sent(),i.total_stage3=Date.now()-x,$=E.boxes.map(function(N,F){return ip(Xh({},new Wr(E.scores[F],new Yh(N.left/f,N.top/d,N.width/f,N.height/d),{height:d,width:f})),new _5(E.points[F].map(function(I){return I.sub(new ct(N.left,N.top)).div(new ct(N.width,N.height))}),{width:N.width,height:N.height}))}),[2,c({results:$,stats:i})]}})})},t.prototype.forward=function(e,r){return r===void 0&&(r={}),$e(this,void 0,void 0,function(){var o;return ke(this,function(a){switch(a.label){case 0:return o=this.forwardInput,[4,Zt(e)];case 1:return[4,o.apply(this,[a.sent(),r])];case 2:return[2,a.sent().results]}})})},t.prototype.forwardWithStats=function(e,r){return r===void 0&&(r={}),$e(this,void 0,void 0,function(){var o;return ke(this,function(a){switch(a.label){case 0:return o=this.forwardInput,[4,Zt(e)];case 1:return[2,o.apply(this,[a.sent(),r])]}})})},t.prototype.getDefaultModelName=function(){return"mtcnn_model"},t.prototype.extractParamsFromWeigthMap=function(e){return L9(e)},t.prototype.extractParams=function(e){return M9(e)},t}(lo),Y9=.4,X9=[new ct(1.603231,2.094468),new ct(6.041143,7.080126),new ct(2.882459,3.518061),new ct(4.266906,5.178857),new ct(9.041765,10.66308)],Z9=[117.001,114.697,97.404],Q9=function(n){De(t,n);function t(){var e=this,r={withSeparableConvs:!0,iouThreshold:Y9,classes:["face"],anchors:X9,meanRgb:Z9,isFirstLayerConv2d:!0,filterSizes:[3,16,32,64,128,256,512]};return e=n.call(this,r)||this,e}return Object.defineProperty(t.prototype,"anchors",{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),t.prototype.locateFaces=function(e,r){return $e(this,void 0,void 0,function(){var o;return ke(this,function(a){switch(a.label){case 0:return[4,this.detect(e,r)];case 1:return o=a.sent(),[2,o.map(function(i){return new Wr(i.score,i.relativeBox,{width:i.imageWidth,height:i.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return"tiny_face_detector_model"},t.prototype.extractParamsFromWeigthMap=function(e){return n.prototype.extractParamsFromWeigthMap.call(this,e)},t}(I2),mn={ssdMobilenetv1:new k2,tinyFaceDetector:new Q9,tinyYolov2:new T9,mtcnn:new K9,faceLandmark68Net:new w2,faceLandmark68TinyNet:new J5,faceRecognitionNet:new i9,faceExpressionNet:new B5,ageGenderNet:new Y5},O2=function(n){De(t,n);function t(e,r,o){var a=n.call(this)||this;return a.parentTask=e,a.input=r,a.extractedFaces=o,a}return t}(vu),vp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r,o=this;return ke(this,function(a){switch(a.label){case 0:return[4,this.parentTask];case 1:return e=a.sent(),[4,Al(e,this.input,function(i){return $e(o,void 0,void 0,function(){return ke(this,function(s){switch(s.label){case 0:return[4,Promise.all(i.map(function(u){return mn.faceExpressionNet.predictExpressions(u)}))];case 1:return[2,s.sent()]}})})},this.extractedFaces)];case 2:return r=a.sent(),[2,e.map(function(i,s){return y2(i,r[s])})]}})})},t.prototype.withAgeAndGender=function(){return new bp(this,this.input)},t}(O2),mp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r;return ke(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return e=o.sent(),e?[4,dp(e,this.input,function(a){return mn.faceExpressionNet.predictExpressions(a)},this.extractedFaces)]:[2];case 2:return r=o.sent(),[2,y2(e,r)]}})})},t.prototype.withAgeAndGender=function(){return new xp(this,this.input)},t}(O2),gp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new wp(this,this.input)},t.prototype.withFaceDescriptors=function(){return new _p(this,this.input)},t}(vp),yp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new Cp(this,this.input)},t.prototype.withFaceDescriptor=function(){return new Ep(this,this.input)},t}(mp),D2=function(n){De(t,n);function t(e,r,o){var a=n.call(this)||this;return a.parentTask=e,a.input=r,a.extractedFaces=o,a}return t}(vu),bp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r,o=this;return ke(this,function(a){switch(a.label){case 0:return[4,this.parentTask];case 1:return e=a.sent(),[4,Al(e,this.input,function(i){return $e(o,void 0,void 0,function(){return ke(this,function(s){switch(s.label){case 0:return[4,Promise.all(i.map(function(u){return mn.ageGenderNet.predictAgeAndGender(u)}))];case 1:return[2,s.sent()]}})})},this.extractedFaces)];case 2:return r=a.sent(),[2,e.map(function(i,s){var u=r[s],c=u.age,l=u.gender,d=u.genderProbability;return S2(N2(i,l,d),c)})]}})})},t.prototype.withFaceExpressions=function(){return new vp(this,this.input)},t}(D2),xp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r,o,a,i;return ke(this,function(s){switch(s.label){case 0:return[4,this.parentTask];case 1:return e=s.sent(),e?[4,dp(e,this.input,function(u){return mn.ageGenderNet.predictAgeAndGender(u)},this.extractedFaces)]:[2];case 2:return r=s.sent(),o=r.age,a=r.gender,i=r.genderProbability,[2,S2(N2(e,a,i),o)]}})})},t.prototype.withFaceExpressions=function(){return new mp(this,this.input)},t}(D2),wp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new gp(this,this.input)},t.prototype.withFaceDescriptors=function(){return new _p(this,this.input)},t}(bp),Cp=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new yp(this,this.input)},t.prototype.withFaceDescriptor=function(){return new Ep(this,this.input)},t}(xp),F2=function(n){De(t,n);function t(e,r){var o=n.call(this)||this;return o.parentTask=e,o.input=r,o}return t}(vu),_p=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r;return ke(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return e=o.sent(),[4,Al(e,this.input,function(a){return Promise.all(a.map(function(i){return mn.faceRecognitionNet.computeFaceDescriptor(i)}))},null,function(a){return a.landmarks.align(null,{useDlibAlignment:!0})})];case 2:return r=o.sent(),[2,r.map(function(a,i){return E2(e[i],a)})]}})})},t.prototype.withFaceExpressions=function(){return new gp(this,this.input)},t.prototype.withAgeAndGender=function(){return new wp(this,this.input)},t}(F2),Ep=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r;return ke(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return e=o.sent(),e?[4,dp(e,this.input,function(a){return mn.faceRecognitionNet.computeFaceDescriptor(a)},null,function(a){return a.landmarks.align(null,{useDlibAlignment:!0})})]:[2];case 2:return r=o.sent(),[2,E2(e,r)]}})})},t.prototype.withFaceExpressions=function(){return new yp(this,this.input)},t.prototype.withAgeAndGender=function(){return new Cp(this,this.input)},t}(F2),M2=function(n){De(t,n);function t(e,r,o){var a=n.call(this)||this;return a.parentTask=e,a.input=r,a.useTinyLandmarkNet=o,a}return Object.defineProperty(t.prototype,"landmarkNet",{get:function(){return this.useTinyLandmarkNet?mn.faceLandmark68TinyNet:mn.faceLandmark68Net},enumerable:!0,configurable:!0}),t}(vu),J9=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r,o,a,i,s=this;return ke(this,function(u){switch(u.label){case 0:return[4,this.parentTask];case 1:return e=u.sent(),r=e.map(function(c){return c.detection}),this.input instanceof Nt?[4,tp(this.input,r)]:[3,3];case 2:return a=u.sent(),[3,5];case 3:return[4,ep(this.input,r)];case 4:a=u.sent(),u.label=5;case 5:return o=a,[4,Promise.all(o.map(function(c){return s.landmarkNet.detectLandmarks(c)}))];case 6:return i=u.sent(),o.forEach(function(c){return c instanceof Nt&&c.dispose()}),[2,e.map(function(c,l){return ip(c,i[l])})]}})})},t.prototype.withFaceExpressions=function(){return new gp(this,this.input)},t.prototype.withAgeAndGender=function(){return new wp(this,this.input)},t.prototype.withFaceDescriptors=function(){return new _p(this,this.input)},t}(M2),eD=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r,o,a,i;return ke(this,function(s){switch(s.label){case 0:return[4,this.parentTask];case 1:return e=s.sent(),e?(r=e.detection,this.input instanceof Nt?[4,tp(this.input,[r])]:[3,3]):[2];case 2:return a=s.sent(),[3,5];case 3:return[4,ep(this.input,[r])];case 4:a=s.sent(),s.label=5;case 5:return o=a,[4,this.landmarkNet.detectLandmarks(o[0])];case 6:return i=s.sent(),o.forEach(function(u){return u instanceof Nt&&u.dispose()}),[2,ip(e,i)]}})})},t.prototype.withFaceExpressions=function(){return new yp(this,this.input)},t.prototype.withAgeAndGender=function(){return new Cp(this,this.input)},t.prototype.withFaceDescriptor=function(){return new Ep(this,this.input)},t}(M2),R2=function(n){De(t,n);function t(e,r){r===void 0&&(r=new pu);var o=n.call(this)||this;return o.input=e,o.options=r,o}return t}(vu),L2=function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r,o,a;return ke(this,function(i){switch(i.label){case 0:return e=this,r=e.input,o=e.options,o instanceof $2?[4,mn.mtcnn.forward(r,o)]:[3,2];case 1:return[2,i.sent().map(function(s){return s.detection})];case 2:if(a=o instanceof O9?function(s){return mn.tinyFaceDetector.locateFaces(s,o)}:o instanceof pu?function(s){return mn.ssdMobilenetv1.locateFaces(s,o)}:o instanceof lp?function(s){return mn.tinyYolov2.locateFaces(s,o)}:null,!a)throw new Error("detectFaces - expected options to be instance of TinyFaceDetectorOptions | SsdMobilenetv1Options | MtcnnOptions | TinyYolov2Options");return[2,a(r)]}})})},t.prototype.runAndExtendWithFaceDetections=function(){var e=this;return new Promise(function(r){return $e(e,void 0,void 0,function(){var o;return ke(this,function(a){switch(a.label){case 0:return[4,this.run()];case 1:return o=a.sent(),[2,r(o.map(function(i){return Xh({},i)}))]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new J9(this.runAndExtendWithFaceDetections(),this.input,e)},t.prototype.withFaceExpressions=function(){return new vp(this.runAndExtendWithFaceDetections(),this.input)},t.prototype.withAgeAndGender=function(){return new bp(this.runAndExtendWithFaceDetections(),this.input)},t}(R2);(function(n){De(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.run=function(){return $e(this,void 0,void 0,function(){var e,r;return ke(this,function(o){switch(o.label){case 0:return[4,new L2(this.input,this.options)];case 1:return e=o.sent(),r=e[0],e.forEach(function(a){a.score>r.score&&(r=a)}),[2,r]}})})},t.prototype.runAndExtendWithFaceDetection=function(){var e=this;return new Promise(function(r){return $e(e,void 0,void 0,function(){var o;return ke(this,function(a){switch(a.label){case 0:return[4,this.run()];case 1:return o=a.sent(),[2,r(o?Xh({},o):void 0)]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new eD(this.runAndExtendWithFaceDetection(),this.input,e)},t.prototype.withFaceExpressions=function(){return new mp(this.runAndExtendWithFaceDetection(),this.input)},t.prototype.withAgeAndGender=function(){return new xp(this.runAndExtendWithFaceDetection(),this.input)},t})(R2);function tD(n,t){return t===void 0&&(t=new pu),new L2(n,t)}function nD(n,t){if(n.length!==t.length)throw new Error("euclideanDistance: arr1.length !== arr2.length");var e=Array.from(n),r=Array.from(t);return Math.sqrt(e.map(function(o,a){return o-r[a]}).reduce(function(o,a){return o+Math.pow(a,2)},0))}(function(){function n(t,e){e===void 0&&(e=.6),this._distanceThreshold=e;var r=Array.isArray(t)?t:[t];if(!r.length)throw new Error("FaceRecognizer.constructor - expected atleast one input");var o=1,a=function(){return"person "+o++};this._labeledDescriptors=r.map(function(i){if(i instanceof _l)return i;if(i instanceof Float32Array)return new _l(a(),[i]);if(i.descriptor&&i.descriptor instanceof Float32Array)return new _l(a(),[i.descriptor]);throw new Error("FaceRecognizer.constructor - expected inputs to be of type LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array | Array<LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array>")})}return Object.defineProperty(n.prototype,"labeledDescriptors",{get:function(){return this._labeledDescriptors},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"distanceThreshold",{get:function(){return this._distanceThreshold},enumerable:!0,configurable:!0}),n.prototype.computeMeanDistance=function(t,e){return e.map(function(r){return nD(r,t)}).reduce(function(r,o){return r+o},0)/(e.length||1)},n.prototype.matchDescriptor=function(t){var e=this;return this.labeledDescriptors.map(function(r){var o=r.descriptors,a=r.label;return new Zb(a,e.computeMeanDistance(t,o))}).reduce(function(r,o){return r.distance<o.distance?r:o})},n.prototype.findBestMatch=function(t){var e=this.matchDescriptor(t);return e.distance<this.distanceThreshold?e:new Zb("unknown",e.distance)},n.prototype.toJSON=function(){return{distanceThreshold:this.distanceThreshold,labeledDescriptors:this.labeledDescriptors.map(function(t){return t.toJSON()})}},n.fromJSON=function(t){var e=t.labeledDescriptors.map(function(r){return _l.fromJSON(r)});return new n(e,t.distanceThreshold)},n})();function po(n){return Array.isArray?Array.isArray(n):V2(n)==="[object Array]"}function rD(n){if(typeof n=="string")return n;let t=n+"";return t=="0"&&1/n==-1/0?"-0":t}function oD(n){return n==null?"":rD(n)}function zr(n){return typeof n=="string"}function B2(n){return typeof n=="number"}function aD(n){return n===!0||n===!1||iD(n)&&V2(n)=="[object Boolean]"}function W2(n){return typeof n=="object"}function iD(n){return W2(n)&&n!==null}function jn(n){return n!=null}function Sp(n){return!n.trim().length}function V2(n){return n==null?n===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(n)}const sD="Incorrect 'index' type",uD=n=>`Invalid value for key ${n}`,cD=n=>`Pattern length exceeds max of ${n}.`,lD=n=>`Missing ${n} property in key`,dD=n=>`Property 'weight' in key '${n}' must be a positive integer`,j2=Object.prototype.hasOwnProperty;class fD{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(r=>{let o=U2(r);this._keys.push(o),this._keyMap[o.id]=o,e+=o.weight}),this._keys.forEach(r=>{r.weight/=e})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function U2(n){let t=null,e=null,r=null,o=1,a=null;if(zr(n)||po(n))r=n,t=z2(n),e=Np(n);else{if(!j2.call(n,"name"))throw new Error(lD("name"));const i=n.name;if(r=i,j2.call(n,"weight")&&(o=n.weight,o<=0))throw new Error(dD(i));t=z2(i),e=Np(i),a=n.getFn}return{path:t,id:e,weight:o,src:r,getFn:a}}function z2(n){return po(n)?n:n.split(".")}function Np(n){return po(n)?n.join("."):n}function hD(n,t){let e=[],r=!1;const o=(a,i,s)=>{if(jn(a))if(!i[s])e.push(a);else{let u=i[s];const c=a[u];if(!jn(c))return;if(s===i.length-1&&(zr(c)||B2(c)||aD(c)))e.push(oD(c));else if(po(c)){r=!0;for(let l=0,d=c.length;l<d;l+=1)o(c[l],i,s+1)}else i.length&&o(c,i,s+1)}};return o(n,zr(t)?t.split("."):t,0),r?e:e[0]}var Ae={...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(n,t)=>n.score===t.score?n.idx<t.idx?-1:1:n.score<t.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,getFn:hD,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}};const pD=/[^ ]+/g;function vD(n=1,t=3){const e=new Map,r=Math.pow(10,t);return{get(o){const a=o.match(pD).length;if(e.has(a))return e.get(a);const i=1/Math.pow(a,.5*n),s=parseFloat(Math.round(i*r)/r);return e.set(a,s),s},clear(){e.clear()}}}class $p{constructor({getFn:t=Ae.getFn,fieldNormWeight:e=Ae.fieldNormWeight}={}){this.norm=vD(e,3),this.getFn=t,this.isCreated=!1,this.setIndexRecords()}setSources(t=[]){this.docs=t}setIndexRecords(t=[]){this.records=t}setKeys(t=[]){this.keys=t,this._keysMap={},t.forEach((e,r)=>{this._keysMap[e.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,zr(this.docs[0])?this.docs.forEach((t,e)=>{this._addString(t,e)}):this.docs.forEach((t,e)=>{this._addObject(t,e)}),this.norm.clear())}add(t){const e=this.size();zr(t)?this._addString(t,e):this._addObject(t,e)}removeAt(t){this.records.splice(t,1);for(let e=t,r=this.size();e<r;e+=1)this.records[e].i-=1}getValueForItemAtKeyId(t,e){return t[this._keysMap[e]]}size(){return this.records.length}_addString(t,e){if(!jn(t)||Sp(t))return;let r={v:t,i:e,n:this.norm.get(t)};this.records.push(r)}_addObject(t,e){let r={i:e,$:{}};this.keys.forEach((o,a)=>{let i=o.getFn?o.getFn(t):this.getFn(t,o.path);if(jn(i)){if(po(i)){let s=[];const u=[{nestedArrIndex:-1,value:i}];for(;u.length;){const{nestedArrIndex:c,value:l}=u.pop();if(jn(l))if(zr(l)&&!Sp(l)){let d={v:l,i:c,n:this.norm.get(l)};s.push(d)}else po(l)&&l.forEach((d,f)=>{u.push({nestedArrIndex:f,value:d})})}r.$[a]=s}else if(zr(i)&&!Sp(i)){let s={v:i,n:this.norm.get(i)};r.$[a]=s}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function H2(n,t,{getFn:e=Ae.getFn,fieldNormWeight:r=Ae.fieldNormWeight}={}){const o=new $p({getFn:e,fieldNormWeight:r});return o.setKeys(n.map(U2)),o.setSources(t),o.create(),o}function mD(n,{getFn:t=Ae.getFn,fieldNormWeight:e=Ae.fieldNormWeight}={}){const{keys:r,records:o}=n,a=new $p({getFn:t,fieldNormWeight:e});return a.setKeys(r),a.setIndexRecords(o),a}function Dl(n,{errors:t=0,currentLocation:e=0,expectedLocation:r=0,distance:o=Ae.distance,ignoreLocation:a=Ae.ignoreLocation}={}){const i=t/n.length;if(a)return i;const s=Math.abs(r-e);return o?i+s/o:s?1:i}function gD(n=[],t=Ae.minMatchCharLength){let e=[],r=-1,o=-1,a=0;for(let i=n.length;a<i;a+=1){let s=n[a];s&&r===-1?r=a:!s&&r!==-1&&(o=a-1,o-r+1>=t&&e.push([r,o]),r=-1)}return n[a-1]&&a-r>=t&&e.push([r,a-1]),e}const Ha=32;function yD(n,t,e,{location:r=Ae.location,distance:o=Ae.distance,threshold:a=Ae.threshold,findAllMatches:i=Ae.findAllMatches,minMatchCharLength:s=Ae.minMatchCharLength,includeMatches:u=Ae.includeMatches,ignoreLocation:c=Ae.ignoreLocation}={}){if(t.length>Ha)throw new Error(cD(Ha));const l=t.length,d=n.length,f=Math.max(0,Math.min(r,d));let h=a,m=f;const v=s>1||u,p=v?Array(d):[];let g;for(;(g=n.indexOf(t,m))>-1;){let E=Dl(t,{currentLocation:g,expectedLocation:f,distance:o,ignoreLocation:c});if(h=Math.min(E,h),m=g+l,v){let $=0;for(;$<l;)p[g+$]=1,$+=1}}m=-1;let b=[],w=1,x=l+d;const C=1<<l-1;for(let E=0;E<l;E+=1){let $=0,S=x;for(;$<S;)Dl(t,{errors:E,currentLocation:f+S,expectedLocation:f,distance:o,ignoreLocation:c})<=h?$=S:x=S,S=Math.floor((x-$)/2+$);x=S;let N=Math.max(1,f-S+1),F=i?d:Math.min(f+S,d)+l,I=Array(F+2);I[F+1]=(1<<E)-1;for(let L=F;L>=N;L-=1){let z=L-1,H=e[n.charAt(z)];if(v&&(p[z]=+!!H),I[L]=(I[L+1]<<1|1)&H,E&&(I[L]|=(b[L+1]|b[L])<<1|1|b[L+1]),I[L]&C&&(w=Dl(t,{errors:E,currentLocation:z,expectedLocation:f,distance:o,ignoreLocation:c}),w<=h)){if(h=w,m=z,m<=f)break;N=Math.max(1,2*f-m)}}if(Dl(t,{errors:E+1,currentLocation:f,expectedLocation:f,distance:o,ignoreLocation:c})>h)break;b=I}const _={isMatch:m>=0,score:Math.max(.001,w)};if(v){const E=gD(p,s);E.length?u&&(_.indices=E):_.isMatch=!1}return _}function bD(n){let t={};for(let e=0,r=n.length;e<r;e+=1){const o=n.charAt(e);t[o]=(t[o]||0)|1<<r-e-1}return t}const Fl=String.prototype.normalize?n=>n.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,""):n=>n;class G2{constructor(t,{location:e=Ae.location,threshold:r=Ae.threshold,distance:o=Ae.distance,includeMatches:a=Ae.includeMatches,findAllMatches:i=Ae.findAllMatches,minMatchCharLength:s=Ae.minMatchCharLength,isCaseSensitive:u=Ae.isCaseSensitive,ignoreDiacritics:c=Ae.ignoreDiacritics,ignoreLocation:l=Ae.ignoreLocation}={}){if(this.options={location:e,threshold:r,distance:o,includeMatches:a,findAllMatches:i,minMatchCharLength:s,isCaseSensitive:u,ignoreDiacritics:c,ignoreLocation:l},t=u?t:t.toLowerCase(),t=c?Fl(t):t,this.pattern=t,this.chunks=[],!this.pattern.length)return;const d=(h,m)=>{this.chunks.push({pattern:h,alphabet:bD(h),startIndex:m})},f=this.pattern.length;if(f>Ha){let h=0;const m=f%Ha,v=f-m;for(;h<v;)d(this.pattern.substr(h,Ha),h),h+=Ha;if(m){const p=f-Ha;d(this.pattern.substr(p),p)}}else d(this.pattern,0)}searchIn(t){const{isCaseSensitive:e,ignoreDiacritics:r,includeMatches:o}=this.options;if(t=e?t:t.toLowerCase(),t=r?Fl(t):t,this.pattern===t){let v={isMatch:!0,score:0};return o&&(v.indices=[[0,t.length-1]]),v}const{location:a,distance:i,threshold:s,findAllMatches:u,minMatchCharLength:c,ignoreLocation:l}=this.options;let d=[],f=0,h=!1;this.chunks.forEach(({pattern:v,alphabet:p,startIndex:g})=>{const{isMatch:b,score:w,indices:x}=yD(t,v,p,{location:a+g,distance:i,threshold:s,findAllMatches:u,minMatchCharLength:c,includeMatches:o,ignoreLocation:l});b&&(h=!0),f+=w,b&&x&&(d=[...d,...x])});let m={isMatch:h,score:h?f/this.chunks.length:1};return h&&o&&(m.indices=d),m}}class Xo{constructor(t){this.pattern=t}static isMultiMatch(t){return q2(t,this.multiRegex)}static isSingleMatch(t){return q2(t,this.singleRegex)}search(){}}function q2(n,t){const e=n.match(t);return e?e[1]:null}class xD extends Xo{constructor(t){super(t)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(t){const e=t===this.pattern;return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}}class wD extends Xo{constructor(t){super(t)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(t){const r=t.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,t.length-1]}}}class CD extends Xo{constructor(t){super(t)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(t){const e=t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}}class _D extends Xo{constructor(t){super(t)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(t){const e=!t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}}class ED extends Xo{constructor(t){super(t)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(t){const e=t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[t.length-this.pattern.length,t.length-1]}}}class SD extends Xo{constructor(t){super(t)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(t){const e=!t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}}class K2 extends Xo{constructor(t,{location:e=Ae.location,threshold:r=Ae.threshold,distance:o=Ae.distance,includeMatches:a=Ae.includeMatches,findAllMatches:i=Ae.findAllMatches,minMatchCharLength:s=Ae.minMatchCharLength,isCaseSensitive:u=Ae.isCaseSensitive,ignoreDiacritics:c=Ae.ignoreDiacritics,ignoreLocation:l=Ae.ignoreLocation}={}){super(t),this._bitapSearch=new G2(t,{location:e,threshold:r,distance:o,includeMatches:a,findAllMatches:i,minMatchCharLength:s,isCaseSensitive:u,ignoreDiacritics:c,ignoreLocation:l})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(t){return this._bitapSearch.searchIn(t)}}class Y2 extends Xo{constructor(t){super(t)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(t){let e=0,r;const o=[],a=this.pattern.length;for(;(r=t.indexOf(this.pattern,e))>-1;)e=r+a,o.push([r,e-1]);const i=!!o.length;return{isMatch:i,score:i?0:1,indices:o}}}const kp=[xD,Y2,CD,_D,SD,ED,wD,K2],X2=kp.length,ND=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,$D="|";function kD(n,t={}){return n.split($D).map(e=>{let r=e.trim().split(ND).filter(a=>a&&!!a.trim()),o=[];for(let a=0,i=r.length;a<i;a+=1){const s=r[a];let u=!1,c=-1;for(;!u&&++c<X2;){const l=kp[c];let d=l.isMultiMatch(s);d&&(o.push(new l(d,t)),u=!0)}if(!u)for(c=-1;++c<X2;){const l=kp[c];let d=l.isSingleMatch(s);if(d){o.push(new l(d,t));break}}}return o})}const PD=new Set([K2.type,Y2.type]);class ID{constructor(t,{isCaseSensitive:e=Ae.isCaseSensitive,ignoreDiacritics:r=Ae.ignoreDiacritics,includeMatches:o=Ae.includeMatches,minMatchCharLength:a=Ae.minMatchCharLength,ignoreLocation:i=Ae.ignoreLocation,findAllMatches:s=Ae.findAllMatches,location:u=Ae.location,threshold:c=Ae.threshold,distance:l=Ae.distance}={}){this.query=null,this.options={isCaseSensitive:e,ignoreDiacritics:r,includeMatches:o,minMatchCharLength:a,findAllMatches:s,ignoreLocation:i,location:u,threshold:c,distance:l},t=e?t:t.toLowerCase(),t=r?Fl(t):t,this.pattern=t,this.query=kD(this.pattern,this.options)}static condition(t,e){return e.useExtendedSearch}searchIn(t){const e=this.query;if(!e)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:o,ignoreDiacritics:a}=this.options;t=o?t:t.toLowerCase(),t=a?Fl(t):t;let i=0,s=[],u=0;for(let c=0,l=e.length;c<l;c+=1){const d=e[c];s.length=0,i=0;for(let f=0,h=d.length;f<h;f+=1){const m=d[f],{isMatch:v,indices:p,score:g}=m.search(t);if(v){if(i+=1,u+=g,r){const b=m.constructor.type;PD.has(b)?s=[...s,...p]:s.push(p)}}else{u=0,i=0,s.length=0;break}}if(i){let f={isMatch:!0,score:u/i};return r&&(f.indices=s),f}}return{isMatch:!1,score:1}}}const Pp=[];function AD(...n){Pp.push(...n)}function Ip(n,t){for(let e=0,r=Pp.length;e<r;e+=1){let o=Pp[e];if(o.condition(n,t))return new o(n,t)}return new G2(n,t)}const Ml={AND:"$and",OR:"$or"},Ap={PATH:"$path",PATTERN:"$val"},Tp=n=>!!(n[Ml.AND]||n[Ml.OR]),TD=n=>!!n[Ap.PATH],OD=n=>!po(n)&&W2(n)&&!Tp(n),Z2=n=>({[Ml.AND]:Object.keys(n).map(t=>({[t]:n[t]}))});function Q2(n,t,{auto:e=!0}={}){const r=o=>{let a=Object.keys(o);const i=TD(o);if(!i&&a.length>1&&!Tp(o))return r(Z2(o));if(OD(o)){const u=i?o[Ap.PATH]:a[0],c=i?o[Ap.PATTERN]:o[u];if(!zr(c))throw new Error(uD(u));const l={keyId:Np(u),pattern:c};return e&&(l.searcher=Ip(c,t)),l}let s={children:[],operator:a[0]};return a.forEach(u=>{const c=o[u];po(c)&&c.forEach(l=>{s.children.push(r(l))})}),s};return Tp(n)||(n=Z2(n)),r(n)}function DD(n,{ignoreFieldNorm:t=Ae.ignoreFieldNorm}){n.forEach(e=>{let r=1;e.matches.forEach(({key:o,norm:a,score:i})=>{const s=o?o.weight:null;r*=Math.pow(i===0&&s?Number.EPSILON:i,(s||1)*(t?1:a))}),e.score=r})}function FD(n,t){const e=n.matches;t.matches=[],jn(e)&&e.forEach(r=>{if(!jn(r.indices)||!r.indices.length)return;const{indices:o,value:a}=r;let i={indices:o,value:a};r.key&&(i.key=r.key.src),r.idx>-1&&(i.refIndex=r.idx),t.matches.push(i)})}function MD(n,t){t.score=n.score}function RD(n,t,{includeMatches:e=Ae.includeMatches,includeScore:r=Ae.includeScore}={}){const o=[];return e&&o.push(FD),r&&o.push(MD),n.map(a=>{const{idx:i}=a,s={item:t[i],refIndex:i};return o.length&&o.forEach(u=>{u(a,s)}),s})}class zi{constructor(t,e={},r){this.options={...Ae,...e},this.options.useExtendedSearch,this._keyStore=new fD(this.options.keys),this.setCollection(t,r)}setCollection(t,e){if(this._docs=t,e&&!(e instanceof $p))throw new Error(sD);this._myIndex=e||H2(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(t){jn(t)&&(this._docs.push(t),this._myIndex.add(t))}remove(t=()=>!1){const e=[];for(let r=0,o=this._docs.length;r<o;r+=1){const a=this._docs[r];t(a,r)&&(this.removeAt(r),r-=1,o-=1,e.push(a))}return e}removeAt(t){this._docs.splice(t,1),this._myIndex.removeAt(t)}getIndex(){return this._myIndex}search(t,{limit:e=-1}={}){const{includeMatches:r,includeScore:o,shouldSort:a,sortFn:i,ignoreFieldNorm:s}=this.options;let u=zr(t)?zr(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t);return DD(u,{ignoreFieldNorm:s}),a&&u.sort(i),B2(e)&&e>-1&&(u=u.slice(0,e)),RD(u,this._docs,{includeMatches:r,includeScore:o})}_searchStringList(t){const e=Ip(t,this.options),{records:r}=this._myIndex,o=[];return r.forEach(({v:a,i,n:s})=>{if(!jn(a))return;const{isMatch:u,score:c,indices:l}=e.searchIn(a);u&&o.push({item:a,idx:i,matches:[{score:c,value:a,norm:s,indices:l}]})}),o}_searchLogical(t){const e=Q2(t,this.options),r=(s,u,c)=>{if(!s.children){const{keyId:d,searcher:f}=s,h=this._findMatches({key:this._keyStore.get(d),value:this._myIndex.getValueForItemAtKeyId(u,d),searcher:f});return h&&h.length?[{idx:c,item:u,matches:h}]:[]}const l=[];for(let d=0,f=s.children.length;d<f;d+=1){const h=s.children[d],m=r(h,u,c);if(m.length)l.push(...m);else if(s.operator===Ml.AND)return[]}return l},o=this._myIndex.records,a={},i=[];return o.forEach(({$:s,i:u})=>{if(jn(s)){let c=r(e,s,u);c.length&&(a[u]||(a[u]={idx:u,item:s,matches:[]},i.push(a[u])),c.forEach(({matches:l})=>{a[u].matches.push(...l)}))}}),i}_searchObjectList(t){const e=Ip(t,this.options),{keys:r,records:o}=this._myIndex,a=[];return o.forEach(({$:i,i:s})=>{if(!jn(i))return;let u=[];r.forEach((c,l)=>{u.push(...this._findMatches({key:c,value:i[l],searcher:e}))}),u.length&&a.push({idx:s,item:i,matches:u})}),a}_findMatches({key:t,value:e,searcher:r}){if(!jn(e))return[];let o=[];if(po(e))e.forEach(({v:a,i,n:s})=>{if(!jn(a))return;const{isMatch:u,score:c,indices:l}=r.searchIn(a);u&&o.push({score:c,key:t,value:a,idx:i,norm:s,indices:l})});else{const{v:a,n:i}=e,{isMatch:s,score:u,indices:c}=r.searchIn(a);s&&o.push({score:u,key:t,value:a,norm:i,indices:c})}return o}}zi.version="7.1.0",zi.createIndex=H2,zi.parseIndex=mD,zi.config=Ae,zi.parseQuery=Q2,AD(ID);const LD=D.createContext(void 0);let Op;const BD=({apiEndpoint:n,children:t})=>(D.useEffect(()=>{Op=n},[n]),y.jsx(LD.Provider,{value:{apiEndpoint:n},children:t})),WD=()=>{if(!Op)throw new Error("ApiEndpoint not initialized. Make sure ApiProvider is mounted.");return Op};typeof window>"u"&&(async()=>{const{Canvas:n,Image:t,ImageData:e,loadImage:r}=await Promise.resolve().then(()=>yz);global.Image=t,global.HTMLImageElement=t,global.ImageData=e,global.HTMLCanvasElement=n,global.CanvasRenderingContext2D=n,global.loadImage=r,on.monkeyPatch({Canvas:n,Image:t,ImageData:e,createCanvasElement:()=>new n(1,1),createImageElement:()=>new t})})();class VD{constructor(){Dm(this,"signalMap");Dm(this,"modelsLoaded",!1);this.signalMap={id:["date of birth","birth date","place of birth","id","identification","identity card","permit","valid until","expiration date","given name","surname","sex","gender","height","weight","address","issuing authority","issued by","card number","personal number","nationality"],passport:["passport","passport number","country code","issuing country","issuing state","place of issue","place of birth","date of issue","date of expiry","expiry date","valid until","authority","surname","given name","name","sex","nationality","type","holder","mrz","document","travel","abroad","citizen"],license:["license","driver","driver license","dl number","licence number","permit","valid until","date of birth","birth date","issue date","expiration date","holder's signature","authority","class","restrictions","endorsements","sex","eyes","hair","height","weight","organ donor","address"],voterId:["voter","voting","voter id","voter card","elector","elector's name","father's name","electoral roll","polling station","constituency","elector id","serial number","sex","age","dob","date of birth","part number","section","epic","identity card","address"],default:["name","id","date","dob","expiry","number","document","issued"]}}async toBase64(t){if(typeof window>"u")return(await(await Promise.resolve().then(()=>bz)).readFile(t)).toString("base64");if(t instanceof File)return new Promise((e,r)=>{const o=new FileReader;o.onload=()=>{const i=o.result.split(",")[1];e(i)},o.onerror=r,o.readAsDataURL(t)});throw new Error("Unsupported input type for base64 conversion")}async validateIdCard(t,e){let r=t;if(typeof t!="string"){const s=await this.toBase64(t);r=`data:${t.type||"image/jpeg"};base64,${s}`}const{data:{text:o}}=await Dk.recognize(r,"eng"),a=this.signalMap[e]||this.signalMap.default;console.log("OCR Result:",{text:o});let i=a.some(s=>{const u=o.toLowerCase().includes(s);return u&&console.log(`Found ${e} match:`,s),u});if(!i){const u=new zi(a,{includeScore:!0,threshold:.6}).search(o.toLowerCase());i=u.length>0,i&&console.log("Found fuzzy match:",u[0].item,u[0].score,{found:u})}return{type:e,passed:i,textSnippet:o.slice(0,200),fullText:o}}async loadModels(){if(this.modelsLoaded)return;const e=`${WD()}/api/models`;await Promise.all([mn.ssdMobilenetv1.loadFromUri(e),mn.faceLandmark68Net.loadFromUri(e),mn.faceRecognitionNet.loadFromUri(e)]),this.modelsLoaded=!0}async validateFace(t){await this.loadModels();let e=t;if(typeof t!="string"){const i=await this.toBase64(t);e=`data:${t.type||"image/jpeg"};base64,${i}`}const r=await this.fileToImage(e),o=await tD(r,new pu);return{type:"face",passed:o.length===1,facesDetected:o.length}}async fileToImage(t){return new Promise((e,r)=>{const o=new Image;if(o.onload=()=>e(o),o.onerror=r,typeof t=="string")o.src=t;else{const a=new FileReader;a.onload=()=>{o.src=a.result},a.onerror=r,a.readAsDataURL(t)}})}}const J2=new VD,jD=(n,t,e,r,o,a,i)=>{const[s,u]=D.useState(null),[c,l]=D.useState(null),[d,f]=D.useState({x:0,y:0,w:320,h:192}),h=D.useRef(`frameMask-${Math.random().toString(36).slice(2)}`),{toast:m}=oc(),v=D.useMemo(()=>c?URL.createObjectURL(c):null,[c]),p=xi.find(x=>x.id===i);D.useEffect(()=>{e.current&&s&&(e.current.srcObject=s)},[s]),D.useEffect(()=>()=>{v&&URL.revokeObjectURL(v)},[v]);const g=D.useCallback(async()=>{try{const x=await navigator.mediaDevices.getUserMedia({video:{facingMode:n==="selfie"?"user":"environment",width:{ideal:9999},height:{ideal:9999}}});u(x)}catch{try{const x=await navigator.mediaDevices.getUserMedia({video:{facingMode:n==="selfie"?"user":"environment",width:{ideal:1280},height:{ideal:720}}});u(x)}catch{m({title:"Camera Error",description:"Unable to access camera. Please check permissions.",variant:"destructive"})}}},[n,m]),b=D.useCallback(()=>{s&&(s.getTracks().forEach(x=>x.stop()),u(null))},[s]),w=D.useCallback(async()=>{if(!e.current||!r.current||!o.current)return;const x=e.current,C=r.current,_=C.getContext("2d");if(!_)return;const E=x.videoWidth,$=x.videoHeight;if(n==="selfie"){C.width=E,C.height=$,_.drawImage(x,0,0,E,$),C.toBlob(async B=>{if(!B)return;const K=new File([B],`${n}-${Date.now()}.jpg`,{type:"image/jpeg"});try{const q=document.createElement("canvas"),Z=q.getContext("2d");if(!Z)return;const oe=x.getBoundingClientRect(),ae=E/oe.width,X=$/oe.height,re=10,ce=(d.x-re)*ae,ue=(d.y-re)*X,se=(d.w+2*re)*ae,ee=(d.h+2*re)*X;q.width=se,q.height=ee,Z.drawImage(x,ce,ue,se,ee,0,0,se,ee);const _e=await new Promise(Ze=>q.toBlob(Ze,"image/jpeg",.8));if(!_e)return;const Fe=new File([_e],`crop-${Date.now()}.jpg`,{type:"image/jpeg"});if(m({title:"Validating...",description:"Checking if the photo has a face..."}),!(await J2.validateFace(Fe)).passed){m({title:"Validation Failed",description:"No face detected. Please retake your selfie.",variant:"destructive"});return}m({title:"Photo Captured",description:"Selfie captured successfully"}),l(K),b()}catch(q){console.error("Face validation error:",q),m({title:"Validation Error",description:"We couldn’t process the selfie. Please try again.",variant:"destructive"})}},"image/jpeg",.8);return}const S=x.getBoundingClientRect(),N=E/S.width,F=$/S.height,I=10,j=(d.x-I)*N,L=(d.y-I)*F,z=(d.w+2*I)*N,H=(d.h+2*I)*F,M=Math.max(0,Math.min(j,E-z)),T=Math.max(0,Math.min(L,$-H)),A=Math.min(z,E-M),P=Math.min(H,$-T);if(C.width=t==="circular"?Math.max(A,P):A,C.height=t==="circular"?Math.max(A,P):P,t==="circular"){const B=Math.min(A,P)/2;_.beginPath(),_.arc(C.width/2,C.height/2,B+I*N,0,Math.PI*2),_.clip(),_.drawImage(x,M-(C.width-A)/2,T-(C.height-P)/2,C.width,C.height,0,0,C.width,C.height)}else _.drawImage(x,M,T,A,P,0,0,C.width,C.height);C.toBlob(async B=>{if(!B)return;const K=new File([B],`${n}-${Date.now()}.jpg`,{type:"image/jpeg"});try{if(m({title:"Validating...",description:`Checking if the photo looks like ${p.title} ...`}),!(await J2.validateIdCard(K,i)).passed){m({title:"Validation Failed",description:`This doesn’t look like ${p.title} card. Try again.`,variant:"destructive"});return}l(K),b(),m({title:"Photo Captured",description:`${p.title} validated successfully`})}catch(q){console.error(q),m({title:"OCR Error",description:"We couldn’t process the photo. Please try again.",variant:"destructive"})}},"image/jpeg",.8)},[n,b,m,t,d,e,r,o]);return D.useEffect(()=>(!c&&!s&&g(),()=>{b()}),[c,s,g,b]),D.useEffect(()=>{if(!o.current||!a.current)return;const x=()=>{const _=o.current.getBoundingClientRect(),E=a.current.getBoundingClientRect();f({x:Math.round(E.left-_.left),y:Math.round(E.top-_.top),w:Math.round(E.width),h:Math.round(E.height)})};x();const C=new ResizeObserver(x);return C.observe(a.current),C.observe(o.current),window.addEventListener("resize",x),window.addEventListener("scroll",x,!0),()=>{C.disconnect(),window.removeEventListener("resize",x),window.removeEventListener("scroll",x,!0)}},[t,s,o,a]),{stream:s,photo:c,setPhoto:l,hole:d,maskId:h.current,photoUrl:v,capturePhoto:w}},Dp=768;function UD(){const[n,t]=k.useState(void 0);return k.useEffect(()=>{const e=window.matchMedia(`(max-width: ${Dp-1}px)`),r=()=>{t(window.innerWidth<Dp)};return e.addEventListener("change",r),t(window.innerWidth<Dp),()=>e.removeEventListener("change",r)},[]),!!n}const zD={"id-front":"ID Front","id-back":"ID Back",selfie:"Selfie"},Hi=({currentStep:n,onRetake:t,onConfirm:e,onBack:r,title:o,description:a,frameType:i,documentTypeId:s})=>{const u=D.useRef(null),c=D.useRef(null),l=D.useRef(null),d=D.useRef(null),f=UD(),{stream:h,photo:m,setPhoto:v,hole:p,maskId:g,photoUrl:b,capturePhoto:w}=jD(n,i,u,c,l,d,s),x=!!h,C=()=>{v(null),r()},_=()=>{v(null),t()},E=()=>{m&&e(m),m&&e(m),v(null)},$=p.x+p.w/2,S=p.y+p.h/2,N=Math.max(p.w,p.h)/2,F=()=>{const I=zD[n]||"Photo";return y.jsx(un,{className:"w-full max-w-md mx-auto",children:y.jsxs(cn,{className:"p-6",children:[y.jsx(ro,{title:`Review ${I}`,subTitle:"Make sure the information is seen clearly, with no blur or glare.",onBack:C}),y.jsx("div",{className:"mb-8",children:y.jsx("div",{className:"relative",children:b&&y.jsx("img",{src:b,alt:"Captured photo",className:`w-full h-64 object-cover ${n==="selfie"?"":i==="circular"?"rounded-full":"rounded-2xl"} bg-muted`})})}),y.jsxs("div",{className:"flex gap-4",children:[y.jsx(_t,{variant:"outline",onClick:_,className:"flex-1 text-md",children:"Take again"}),y.jsx(_t,{onClick:E,className:"flex-1 text-md",children:"Looks good"})]})]})})};return m?F():y.jsxs(un,{className:"relative w-full max-w-md mx-auto bg-gray-900 border-gray-900 overflow-hidden",children:[x&&y.jsx("video",{ref:u,autoPlay:!0,playsInline:!0,muted:!0,loop:!0,className:`absolute inset-0 w-full h-full object-cover z-0 ${!f&&"scale-x-[-1]"}`}),y.jsx("div",{ref:l,className:"absolute inset-0 z-5 pointer-events-none","aria-hidden":!0,children:y.jsxs("svg",{className:"w-full h-full",children:[y.jsx("defs",{children:y.jsxs("mask",{id:g,children:[y.jsx("rect",{width:"100%",height:"100%",fill:"white"}),i==="circular"?y.jsx("circle",{cx:$,cy:S,r:N,fill:"black"}):y.jsx("rect",{x:p.x,y:p.y,width:p.w,height:p.h,fill:"black"})]})}),y.jsx("rect",{width:"100%",height:"100%",fill:"rgba(17,24,39,0.7)",mask:`url(#${g})`})]})}),y.jsx("canvas",{ref:c,className:"hidden"}),y.jsxs(cn,{className:"relative z-10 text-white flex flex-col h-full",children:[y.jsxs("div",{className:"flex items-center p-6",children:[y.jsx(_t,{variant:"ghost",size:"sm",onClick:C,className:"text-white hover:bg-gray-600",children:y.jsx(kg,{className:"h-6 w-6"})}),y.jsx("h1",{className:"text-xl font-semibold ml-4",children:o})]}),y.jsx("div",{className:"px-6 mb-8",children:y.jsx("p",{className:"text-gray-300 text-center",children:a})}),y.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center px-6",children:[y.jsx("div",{className:"relative mb-16",children:x?y.jsxs("div",{ref:d,className:`relative z-20 ${i==="circular"?"w-80 h-80 rounded-full":s==="passport"?"w-80 h-[350px]":"w-80 h-48"}`,children:[y.jsx("div",{className:`absolute inset-0 opacity-0 ${i==="circular"?"rounded-full":""} z-10`}),i==="circular"?null:y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"absolute w-6 h-6 border-t-4 border-l-4 border-white z-30",style:{top:"-4px",left:"-4px"}}),y.jsx("div",{className:"absolute w-6 h-6 border-t-4 border-r-4 border-white z-30",style:{top:"-4px",right:"-4px"}}),y.jsx("div",{className:"absolute w-6 h-6 border-b-4 border-l-4 border-white z-30",style:{bottom:"-4px",left:"-4px"}}),y.jsx("div",{className:"absolute w-6 h-6 border-b-4 border-r-4 border-white z-30",style:{bottom:"-4px",right:"-4px"}})]})]}):y.jsx("div",{className:`bg-gray-700 flex items-center justify-center ${i==="circular"?"w-80 h-80 rounded-full":s==="passport"?"w-80 h-[350px]":"w-80 h-48"}`,children:y.jsx("p",{className:"text-gray-400",children:"Camera loading..."})})}),y.jsx(_t,{onClick:w,size:"lg",className:"w-16 h-16 rounded-full bg-white hover:bg-gray-100 border-4 border-gray-600 p-0",disabled:!x,children:y.jsx("div",{className:"w-8 h-8 rounded-full bg-white"})})]})]})]})},HD=({apiEndpoint:n,apiKey:t,onComplete:e,onDoneClick:r,userEmail:o})=>{const[a,i]=D.useState("landing"),[s,u]=D.useState(""),[c,l]=D.useState(""),[d,f]=D.useState(null),[h,m]=D.useState(null),[v,p]=D.useState(null),{data:g}=KD(n,t),b=oy({mutationFn:GD}),{toast:w}=oc(),x=D.useMemo(()=>[...g!=null&&g.hide_name_step?[]:["name"],...g!=null&&g.hide_document_selection_step?[]:["document-selection"],"selfie","pre-selfie","id-front","id-back","verify"],[g]),C=()=>g.hide_name_step?g.hide_document_selection_step?"id-front":"document-selection":"name",_=async()=>{if((g.hide_name_step||!!s)&&d&&h&&(!(c!=="passport")||v)){const F={full_name:s,email:o,selfie_photo:d,id_photo:h,id_photo_back:v};try{const I=await b.mutateAsync({apiEndpoint:n,apiKey:t,data:F});e(I.data.token,F),w({title:"KYC Complete",description:"Identity verification completed successfully."}),u(""),f(null),m(null),p(null),i("done")}catch{w({title:"Submission failed",description:"There was an error submitting your verification. Please try again.",variant:"destructive"})}}else console.warn("Missing data for KYC",{fullName:s,selfiePhoto:d,idCardFront:h,idCardBack:v,selectedDocumentType:c})},E=()=>y.jsx(y.Fragment,{children:a!=="landing"&&y.jsx("div",{className:"flex justify-center",children:y.jsx("div",{className:"flex space-x-2",children:x.map((S,N)=>y.jsx("div",{className:`w-3 h-3 rounded-full ${x.indexOf(a)>=N?"bg-primary":"bg-muted"}`},S))})})}),$=()=>{switch(console.log("currentStep",a),a){case"landing":return y.jsx(ay,{onContinue:()=>i(C())});case"name":return y.jsx(Y$,{fullName:s,onNameChange:u,onContinue:()=>i(g.hide_document_selection_step?"id-front":"document-selection"),renderProgress:E});case"document-selection":return y.jsx(uy,{selectedDocumentType:c,onDocumentTypeChange:l,onContinue:()=>i("id-front"),onBack:()=>i(g.hide_name_step?"landing":"name"),renderProgress:E});case"id-front":return y.jsx(Hi,{title:"Upload ID",description:"Place your ID inside the frame and take a picture. Make sure it is not cut or has any glare.",frameType:"rectangular",documentTypeId:c,currentStep:a,onRetake:()=>{m(null)},onConfirm:S=>{m(S),i(c==="passport"?"pre-selfie":"id-back")},onBack:()=>{m(null),i(g.hide_document_selection_step?g.hide_name_step?"landing":"name":"document-selection")}});case"id-back":return y.jsx(Hi,{title:"Upload ID Back",description:"Place the back of your ID inside the frame and take a picture. Make sure it is not cut or has any glare.",frameType:"rectangular",documentTypeId:c,currentStep:a,onRetake:()=>{p(null)},onConfirm:S=>{p(S),i("pre-selfie")},onBack:()=>{p(null),i("id-front")}});case"pre-selfie":return y.jsx(cy,{onContinue:()=>i("selfie"),onBack:()=>i("id-back")});case"selfie":return y.jsx(Hi,{title:"Selfie",description:"Place your face inside the frame and take a picture. Make sure it is clearly visible.",frameType:"circular",documentTypeId:c,currentStep:a,onRetake:()=>{f(null)},onConfirm:S=>{f(S),i("verify")},onBack:()=>{f(null),i("id-back")}});case"verify":return y.jsx(X$,{fullName:s,onComplete:()=>i("processing"),onStartOver:()=>i("landing")});case"processing":return y.jsx(ly,{onComplete:_});case"done":return y.jsx(dy,{onDoneClick:r});default:return null}};return y.jsx("div",{className:"w-[430px]",children:$()})};async function GD({apiEndpoint:n,apiKey:t,data:e}){const r=new FormData;r.append("full_name",e.full_name),r.append("email",e.email),e.selfie_photo&&r.append("selfie_photo",e.selfie_photo,e.selfie_photo.name),e.id_photo&&r.append("id_photo",e.id_photo,e.id_photo.name),e.id_photo_back&&r.append("id_photo_back",e.id_photo_back,e.id_photo_back.name);const o=await fetch(`${n}/api/kyc`,{method:"POST",headers:{"X-API-Key":t},body:r});if(!o.ok)throw new Error("Network response was not ok");return o.json()}const qD=async(n,t)=>{const e=await fetch(`${n}/api/settings`,{method:"GET",headers:{"X-API-Key":t,"Content-Type":"application/json"}});if(!e.ok)throw new Error("Network response was not ok");return(await e.json()).data},KD=(n,t)=>z$({queryKey:["settings",n,t],queryFn:()=>qD(n,t),enabled:!!n&&!!t});var mu=n=>n.type==="checkbox",Ga=n=>n instanceof Date,gn=n=>n==null;const ex=n=>typeof n=="object";var Ft=n=>!gn(n)&&!Array.isArray(n)&&ex(n)&&!Ga(n),tx=n=>Ft(n)&&n.target?mu(n.target)?n.target.checked:n.target.value:n,YD=n=>n.substring(0,n.search(/\.\d+(\.|$)/))||n,nx=(n,t)=>n.has(YD(t)),XD=n=>{const t=n.constructor&&n.constructor.prototype;return Ft(t)&&t.hasOwnProperty("isPrototypeOf")},Fp=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function qt(n){let t;const e=Array.isArray(n),r=typeof FileList<"u"?n instanceof FileList:!1;if(n instanceof Date)t=new Date(n);else if(!(Fp&&(n instanceof Blob||r))&&(e||Ft(n)))if(t=e?[]:Object.create(Object.getPrototypeOf(n)),!e&&!XD(n))t=n;else for(const o in n)n.hasOwnProperty(o)&&(t[o]=qt(n[o]));else return n;return t}var Rl=n=>/^\w*$/.test(n),Ot=n=>n===void 0,Mp=n=>Array.isArray(n)?n.filter(Boolean):[],Rp=n=>Mp(n.replace(/["|']|\]/g,"").split(/\.|\[/)),me=(n,t,e)=>{if(!t||!Ft(n))return e;const r=(Rl(t)?[t]:Rp(t)).reduce((o,a)=>gn(o)?o:o[a],n);return Ot(r)||r===n?Ot(n[t])?e:n[t]:r},Un=n=>typeof n=="boolean",pt=(n,t,e)=>{let r=-1;const o=Rl(t)?[t]:Rp(t),a=o.length,i=a-1;for(;++r<a;){const s=o[r];let u=e;if(r!==i){const c=n[s];u=Ft(c)||Array.isArray(c)?c:isNaN(+o[r+1])?{}:[]}if(s==="__proto__"||s==="constructor"||s==="prototype")return;n[s]=u,n=n[s]}};const Ll={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},lr={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},vo={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},Lp=D.createContext(null);Lp.displayName="HookFormContext";const Bl=()=>D.useContext(Lp),ZD=n=>{const{children:t,...e}=n;return D.createElement(Lp.Provider,{value:e},t)};var rx=(n,t,e,r=!0)=>{const o={defaultValues:t._defaultValues};for(const a in n)Object.defineProperty(o,a,{get:()=>{const i=a;return t._proxyFormState[i]!==lr.all&&(t._proxyFormState[i]=!r||lr.all),e&&(e[i]=!0),n[i]}});return o};const Bp=typeof window<"u"?D.useLayoutEffect:D.useEffect;function QD(n){const t=Bl(),{control:e=t.control,disabled:r,name:o,exact:a}=n||{},[i,s]=D.useState(e._formState),u=D.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1});return Bp(()=>e._subscribe({name:o,formState:u.current,exact:a,callback:c=>{!r&&s({...e._formState,...c})}}),[o,r,a]),D.useEffect(()=>{u.current.isValid&&e._setValid(!0)},[e]),D.useMemo(()=>rx(i,e,u.current,!1),[i,e])}var zn=n=>typeof n=="string",ox=(n,t,e,r,o)=>zn(n)?(r&&t.watch.add(n),me(e,n,o)):Array.isArray(n)?n.map(a=>(r&&t.watch.add(a),me(e,a))):(r&&(t.watchAll=!0),e),Wp=n=>gn(n)||!ex(n);function mo(n,t,e=new WeakSet){if(Wp(n)||Wp(t))return n===t;if(Ga(n)&&Ga(t))return n.getTime()===t.getTime();const r=Object.keys(n),o=Object.keys(t);if(r.length!==o.length)return!1;if(e.has(n)||e.has(t))return!0;e.add(n),e.add(t);for(const a of r){const i=n[a];if(!o.includes(a))return!1;if(a!=="ref"){const s=t[a];if(Ga(i)&&Ga(s)||Ft(i)&&Ft(s)||Array.isArray(i)&&Array.isArray(s)?!mo(i,s,e):i!==s)return!1}}return!0}function JD(n){const t=Bl(),{control:e=t.control,name:r,defaultValue:o,disabled:a,exact:i,compute:s}=n||{},u=D.useRef(o),c=D.useRef(s),l=D.useRef(void 0);c.current=s;const d=D.useMemo(()=>e._getWatch(r,u.current),[e,r]),[f,h]=D.useState(c.current?c.current(d):d);return Bp(()=>e._subscribe({name:r,formState:{values:!0},exact:i,callback:m=>{if(!a){const v=ox(r,e._names,m.values||e._formValues,!1,u.current);if(c.current){const p=c.current(v);mo(p,l.current)||(h(p),l.current=p)}else h(v)}}}),[e,a,r,i]),D.useEffect(()=>e._removeUnmounted()),f}function ax(n){const t=Bl(),{name:e,disabled:r,control:o=t.control,shouldUnregister:a,defaultValue:i}=n,s=nx(o._names.array,e),u=D.useMemo(()=>me(o._formValues,e,me(o._defaultValues,e,i)),[o,e,i]),c=JD({control:o,name:e,defaultValue:u,exact:!0}),l=QD({control:o,name:e,exact:!0}),d=D.useRef(n),f=D.useRef(void 0),h=D.useRef(o.register(e,{...n.rules,value:c,...Un(n.disabled)?{disabled:n.disabled}:{}}));d.current=n;const m=D.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!me(l.errors,e)},isDirty:{enumerable:!0,get:()=>!!me(l.dirtyFields,e)},isTouched:{enumerable:!0,get:()=>!!me(l.touchedFields,e)},isValidating:{enumerable:!0,get:()=>!!me(l.validatingFields,e)},error:{enumerable:!0,get:()=>me(l.errors,e)}}),[l,e]),v=D.useCallback(w=>h.current.onChange({target:{value:tx(w),name:e},type:Ll.CHANGE}),[e]),p=D.useCallback(()=>h.current.onBlur({target:{value:me(o._formValues,e),name:e},type:Ll.BLUR}),[e,o._formValues]),g=D.useCallback(w=>{const x=me(o._fields,e);x&&w&&(x._f.ref={focus:()=>w.focus&&w.focus(),select:()=>w.select&&w.select(),setCustomValidity:C=>w.setCustomValidity(C),reportValidity:()=>w.reportValidity()})},[o._fields,e]),b=D.useMemo(()=>({name:e,value:c,...Un(r)||l.disabled?{disabled:l.disabled||r}:{},onChange:v,onBlur:p,ref:g}),[e,r,l.disabled,v,p,g,c]);return D.useEffect(()=>{const w=o._options.shouldUnregister||a,x=f.current;x&&x!==e&&!s&&o.unregister(x),o.register(e,{...d.current.rules,...Un(d.current.disabled)?{disabled:d.current.disabled}:{}});const C=(_,E)=>{const $=me(o._fields,_);$&&$._f&&($._f.mount=E)};if(C(e,!0),w){const _=qt(me(o._options.defaultValues,e));pt(o._defaultValues,e,_),Ot(me(o._formValues,e))&&pt(o._formValues,e,_)}return!s&&o.register(e),f.current=e,()=>{(s?w&&!o._state.action:w)?o.unregister(e):C(e,!1)}},[e,o,s,a]),D.useEffect(()=>{o._setDisabledField({disabled:r,name:e})},[r,e,o]),D.useMemo(()=>({field:b,formState:l,fieldState:m}),[b,l,m])}const e8=n=>n.render(ax(n));var ix=(n,t,e,r,o)=>t?{...e[n],types:{...e[n]&&e[n].types?e[n].types:{},[r]:o||!0}}:{},gu=n=>Array.isArray(n)?n:[n],sx=()=>{let n=[];return{get observers(){return n},next:o=>{for(const a of n)a.next&&a.next(o)},subscribe:o=>(n.push(o),{unsubscribe:()=>{n=n.filter(a=>a!==o)}}),unsubscribe:()=>{n=[]}}};function ux(n,t){const e={};for(const r in n)if(n.hasOwnProperty(r)){const o=n[r],a=t[r];if(o&&Ft(o)&&a){const i=ux(o,a);Ft(i)&&(e[r]=i)}else n[r]&&(e[r]=a)}return e}var kn=n=>Ft(n)&&!Object.keys(n).length,Vp=n=>n.type==="file",dr=n=>typeof n=="function",Wl=n=>{if(!Fp)return!1;const t=n?n.ownerDocument:0;return n instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},cx=n=>n.type==="select-multiple",jp=n=>n.type==="radio",t8=n=>jp(n)||mu(n),Up=n=>Wl(n)&&n.isConnected;function n8(n,t){const e=t.slice(0,-1).length;let r=0;for(;r<e;)n=Ot(n)?r++:n[t[r++]];return n}function r8(n){for(const t in n)if(n.hasOwnProperty(t)&&!Ot(n[t]))return!1;return!0}function Mt(n,t){const e=Array.isArray(t)?t:Rl(t)?[t]:Rp(t),r=e.length===1?n:n8(n,e),o=e.length-1,a=e[o];return r&&delete r[a],o!==0&&(Ft(r)&&kn(r)||Array.isArray(r)&&r8(r))&&Mt(n,e.slice(0,-1)),n}var o8=n=>{for(const t in n)if(dr(n[t]))return!0;return!1};function lx(n){return Array.isArray(n)||Ft(n)&&!o8(n)}function zp(n,t={}){for(const e in n)lx(n[e])?(t[e]=Array.isArray(n[e])?[]:{},zp(n[e],t[e])):gn(n[e])||(t[e]=!0);return t}function Gi(n,t,e){e||(e=zp(t));for(const r in n)lx(n[r])?Ot(t)||Wp(e[r])?e[r]=zp(n[r],Array.isArray(n[r])?[]:{}):Gi(n[r],gn(t)?{}:t[r],e[r]):e[r]=!mo(n[r],t[r]);return e}const dx={value:!1,isValid:!1},fx={value:!0,isValid:!0};var hx=n=>{if(Array.isArray(n)){if(n.length>1){const t=n.filter(e=>e&&e.checked&&!e.disabled).map(e=>e.value);return{value:t,isValid:!!t.length}}return n[0].checked&&!n[0].disabled?n[0].attributes&&!Ot(n[0].attributes.value)?Ot(n[0].value)||n[0].value===""?fx:{value:n[0].value,isValid:!0}:fx:dx}return dx},px=(n,{valueAsNumber:t,valueAsDate:e,setValueAs:r})=>Ot(n)?n:t?n===""?NaN:n&&+n:e&&zn(n)?new Date(n):r?r(n):n;const vx={isValid:!1,value:null};var mx=n=>Array.isArray(n)?n.reduce((t,e)=>e&&e.checked&&!e.disabled?{isValid:!0,value:e.value}:t,vx):vx;function gx(n){const t=n.ref;return Vp(t)?t.files:jp(t)?mx(n.refs).value:cx(t)?[...t.selectedOptions].map(({value:e})=>e):mu(t)?hx(n.refs).value:px(Ot(t.value)?n.ref.value:t.value,n)}var a8=(n,t,e,r)=>{const o={};for(const a of n){const i=me(t,a);i&&pt(o,a,i._f)}return{criteriaMode:e,names:[...n],fields:o,shouldUseNativeValidation:r}},Vl=n=>n instanceof RegExp,yu=n=>Ot(n)?n:Vl(n)?n.source:Ft(n)?Vl(n.value)?n.value.source:n.value:n,yx=n=>({isOnSubmit:!n||n===lr.onSubmit,isOnBlur:n===lr.onBlur,isOnChange:n===lr.onChange,isOnAll:n===lr.all,isOnTouch:n===lr.onTouched});const bx="AsyncFunction";var i8=n=>!!n&&!!n.validate&&!!(dr(n.validate)&&n.validate.constructor.name===bx||Ft(n.validate)&&Object.values(n.validate).find(t=>t.constructor.name===bx)),s8=n=>n.mount&&(n.required||n.min||n.max||n.maxLength||n.minLength||n.pattern||n.validate),xx=(n,t,e)=>!e&&(t.watchAll||t.watch.has(n)||[...t.watch].some(r=>n.startsWith(r)&&/^\.\w+/.test(n.slice(r.length))));const bu=(n,t,e,r)=>{for(const o of e||Object.keys(n)){const a=me(n,o);if(a){const{_f:i,...s}=a;if(i){if(i.refs&&i.refs[0]&&t(i.refs[0],o)&&!r)return!0;if(i.ref&&t(i.ref,i.name)&&!r)return!0;if(bu(s,t))break}else if(Ft(s)&&bu(s,t))break}}};function wx(n,t,e){const r=me(n,e);if(r||Rl(e))return{error:r,name:e};const o=e.split(".");for(;o.length;){const a=o.join("."),i=me(t,a),s=me(n,a);if(i&&!Array.isArray(i)&&e!==a)return{name:e};if(s&&s.type)return{name:a,error:s};if(s&&s.root&&s.root.type)return{name:`${a}.root`,error:s.root};o.pop()}return{name:e}}var u8=(n,t,e,r)=>{e(n);const{name:o,...a}=n;return kn(a)||Object.keys(a).length>=Object.keys(t).length||Object.keys(a).find(i=>t[i]===(!r||lr.all))},c8=(n,t,e)=>!n||!t||n===t||gu(n).some(r=>r&&(e?r===t:r.startsWith(t)||t.startsWith(r))),l8=(n,t,e,r,o)=>o.isOnAll?!1:!e&&o.isOnTouch?!(t||n):(e?r.isOnBlur:o.isOnBlur)?!n:(e?r.isOnChange:o.isOnChange)?n:!0,d8=(n,t)=>!Mp(me(n,t)).length&&Mt(n,t),f8=(n,t,e)=>{const r=gu(me(n,e));return pt(r,"root",t[e]),pt(n,e,r),n};function Cx(n,t,e="validate"){if(zn(n)||Array.isArray(n)&&n.every(zn)||Un(n)&&!n)return{type:e,message:zn(n)?n:"",ref:t}}var qi=n=>Ft(n)&&!Vl(n)?n:{value:n,message:""},_x=async(n,t,e,r,o,a)=>{const{ref:i,refs:s,required:u,maxLength:c,minLength:l,min:d,max:f,pattern:h,validate:m,name:v,valueAsNumber:p,mount:g}=n._f,b=me(e,v);if(!g||t.has(v))return{};const w=s?s[0]:i,x=I=>{o&&w.reportValidity&&(w.setCustomValidity(Un(I)?"":I||""),w.reportValidity())},C={},_=jp(i),E=mu(i),$=_||E,S=(p||Vp(i))&&Ot(i.value)&&Ot(b)||Wl(i)&&i.value===""||b===""||Array.isArray(b)&&!b.length,N=ix.bind(null,v,r,C),F=(I,j,L,z=vo.maxLength,H=vo.minLength)=>{const M=I?j:L;C[v]={type:I?z:H,message:M,ref:i,...N(I?z:H,M)}};if(a?!Array.isArray(b)||!b.length:u&&(!$&&(S||gn(b))||Un(b)&&!b||E&&!hx(s).isValid||_&&!mx(s).isValid)){const{value:I,message:j}=zn(u)?{value:!!u,message:u}:qi(u);if(I&&(C[v]={type:vo.required,message:j,ref:w,...N(vo.required,j)},!r))return x(j),C}if(!S&&(!gn(d)||!gn(f))){let I,j;const L=qi(f),z=qi(d);if(!gn(b)&&!isNaN(b)){const H=i.valueAsNumber||b&&+b;gn(L.value)||(I=H>L.value),gn(z.value)||(j=H<z.value)}else{const H=i.valueAsDate||new Date(b),M=P=>new Date(new Date().toDateString()+" "+P),T=i.type=="time",A=i.type=="week";zn(L.value)&&b&&(I=T?M(b)>M(L.value):A?b>L.value:H>new Date(L.value)),zn(z.value)&&b&&(j=T?M(b)<M(z.value):A?b<z.value:H<new Date(z.value))}if((I||j)&&(F(!!I,L.message,z.message,vo.max,vo.min),!r))return x(C[v].message),C}if((c||l)&&!S&&(zn(b)||a&&Array.isArray(b))){const I=qi(c),j=qi(l),L=!gn(I.value)&&b.length>+I.value,z=!gn(j.value)&&b.length<+j.value;if((L||z)&&(F(L,I.message,j.message),!r))return x(C[v].message),C}if(h&&!S&&zn(b)){const{value:I,message:j}=qi(h);if(Vl(I)&&!b.match(I)&&(C[v]={type:vo.pattern,message:j,ref:i,...N(vo.pattern,j)},!r))return x(j),C}if(m){if(dr(m)){const I=await m(b,e),j=Cx(I,w);if(j&&(C[v]={...j,...N(vo.validate,j.message)},!r))return x(j.message),C}else if(Ft(m)){let I={};for(const j in m){if(!kn(I)&&!r)break;const L=Cx(await m[j](b,e),w,j);L&&(I={...L,...N(j,L.message)},x(L.message),r&&(C[v]=I))}if(!kn(I)&&(C[v]={ref:w,...I},!r))return C}}return x(!0),C};const h8={mode:lr.onSubmit,reValidateMode:lr.onChange,shouldFocusError:!0};function p8(n={}){let t={...h8,...n},e={submitCount:0,isDirty:!1,isReady:!1,isLoading:dr(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},o=Ft(t.defaultValues)||Ft(t.values)?qt(t.defaultValues||t.values)||{}:{},a=t.shouldUnregister?{}:qt(o),i={action:!1,mount:!1,watch:!1},s={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},u,c=0;const l={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1};let d={...l};const f={array:sx(),state:sx()},h=t.criteriaMode===lr.all,m=V=>Y=>{clearTimeout(c),c=setTimeout(V,Y)},v=async V=>{if(!t.disabled&&(l.isValid||d.isValid||V)){const Y=t.resolver?kn((await E()).errors):await S(r,!0);Y!==e.isValid&&f.state.next({isValid:Y})}},p=(V,Y)=>{!t.disabled&&(l.isValidating||l.validatingFields||d.isValidating||d.validatingFields)&&((V||Array.from(s.mount)).forEach(te=>{te&&(Y?pt(e.validatingFields,te,Y):Mt(e.validatingFields,te))}),f.state.next({validatingFields:e.validatingFields,isValidating:!kn(e.validatingFields)}))},g=(V,Y=[],te,he,pe=!0,le=!0)=>{if(he&&te&&!t.disabled){if(i.action=!0,le&&Array.isArray(me(r,V))){const ye=te(me(r,V),he.argA,he.argB);pe&&pt(r,V,ye)}if(le&&Array.isArray(me(e.errors,V))){const ye=te(me(e.errors,V),he.argA,he.argB);pe&&pt(e.errors,V,ye),d8(e.errors,V)}if((l.touchedFields||d.touchedFields)&&le&&Array.isArray(me(e.touchedFields,V))){const ye=te(me(e.touchedFields,V),he.argA,he.argB);pe&&pt(e.touchedFields,V,ye)}(l.dirtyFields||d.dirtyFields)&&(e.dirtyFields=Gi(o,a)),f.state.next({name:V,isDirty:F(V,Y),dirtyFields:e.dirtyFields,errors:e.errors,isValid:e.isValid})}else pt(a,V,Y)},b=(V,Y)=>{pt(e.errors,V,Y),f.state.next({errors:e.errors})},w=V=>{e.errors=V,f.state.next({errors:e.errors,isValid:!1})},x=(V,Y,te,he)=>{const pe=me(r,V);if(pe){const le=me(a,V,Ot(te)?me(o,V):te);Ot(le)||he&&he.defaultChecked||Y?pt(a,V,Y?le:gx(pe._f)):L(V,le),i.mount&&v()}},C=(V,Y,te,he,pe)=>{let le=!1,ye=!1;const We={name:V};if(!t.disabled){if(!te||he){(l.isDirty||d.isDirty)&&(ye=e.isDirty,e.isDirty=We.isDirty=F(),le=ye!==We.isDirty);const Ge=mo(me(o,V),Y);ye=!!me(e.dirtyFields,V),Ge?Mt(e.dirtyFields,V):pt(e.dirtyFields,V,!0),We.dirtyFields=e.dirtyFields,le=le||(l.dirtyFields||d.dirtyFields)&&ye!==!Ge}if(te){const Ge=me(e.touchedFields,V);Ge||(pt(e.touchedFields,V,te),We.touchedFields=e.touchedFields,le=le||(l.touchedFields||d.touchedFields)&&Ge!==te)}le&&pe&&f.state.next(We)}return le?We:{}},_=(V,Y,te,he)=>{const pe=me(e.errors,V),le=(l.isValid||d.isValid)&&Un(Y)&&e.isValid!==Y;if(t.delayError&&te?(u=m(()=>b(V,te)),u(t.delayError)):(clearTimeout(c),u=null,te?pt(e.errors,V,te):Mt(e.errors,V)),(te?!mo(pe,te):pe)||!kn(he)||le){const ye={...he,...le&&Un(Y)?{isValid:Y}:{},errors:e.errors,name:V};e={...e,...ye},f.state.next(ye)}},E=async V=>{p(V,!0);const Y=await t.resolver(a,t.context,a8(V||s.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return p(V),Y},$=async V=>{const{errors:Y}=await E(V);if(V)for(const te of V){const he=me(Y,te);he?pt(e.errors,te,he):Mt(e.errors,te)}else e.errors=Y;return Y},S=async(V,Y,te={valid:!0})=>{for(const he in V){const pe=V[he];if(pe){const{_f:le,...ye}=pe;if(le){const We=s.array.has(le.name),Ge=pe._f&&i8(pe._f);Ge&&l.validatingFields&&p([le.name],!0);const Jt=await _x(pe,s.disabled,a,h,t.shouldUseNativeValidation&&!Y,We);if(Ge&&l.validatingFields&&p([le.name]),Jt[le.name]&&(te.valid=!1,Y))break;!Y&&(me(Jt,le.name)?We?f8(e.errors,Jt,le.name):pt(e.errors,le.name,Jt[le.name]):Mt(e.errors,le.name))}!kn(ye)&&await S(ye,Y,te)}}return te.valid},N=()=>{for(const V of s.unMount){const Y=me(r,V);Y&&(Y._f.refs?Y._f.refs.every(te=>!Up(te)):!Up(Y._f.ref))&&X(V)}s.unMount=new Set},F=(V,Y)=>!t.disabled&&(V&&Y&&pt(a,V,Y),!mo(P(),o)),I=(V,Y,te)=>ox(V,s,{...i.mount?a:Ot(Y)?o:zn(V)?{[V]:Y}:Y},te,Y),j=V=>Mp(me(i.mount?a:o,V,t.shouldUnregister?me(o,V,[]):[])),L=(V,Y,te={})=>{const he=me(r,V);let pe=Y;if(he){const le=he._f;le&&(!le.disabled&&pt(a,V,px(Y,le)),pe=Wl(le.ref)&&gn(Y)?"":Y,cx(le.ref)?[...le.ref.options].forEach(ye=>ye.selected=pe.includes(ye.value)):le.refs?mu(le.ref)?le.refs.forEach(ye=>{(!ye.defaultChecked||!ye.disabled)&&(Array.isArray(pe)?ye.checked=!!pe.find(We=>We===ye.value):ye.checked=pe===ye.value||!!pe)}):le.refs.forEach(ye=>ye.checked=ye.value===pe):Vp(le.ref)?le.ref.value="":(le.ref.value=pe,le.ref.type||f.state.next({name:V,values:qt(a)})))}(te.shouldDirty||te.shouldTouch)&&C(V,pe,te.shouldTouch,te.shouldDirty,!0),te.shouldValidate&&A(V)},z=(V,Y,te)=>{for(const he in Y){if(!Y.hasOwnProperty(he))return;const pe=Y[he],le=V+"."+he,ye=me(r,le);(s.array.has(V)||Ft(pe)||ye&&!ye._f)&&!Ga(pe)?z(le,pe,te):L(le,pe,te)}},H=(V,Y,te={})=>{const he=me(r,V),pe=s.array.has(V),le=qt(Y);pt(a,V,le),pe?(f.array.next({name:V,values:qt(a)}),(l.isDirty||l.dirtyFields||d.isDirty||d.dirtyFields)&&te.shouldDirty&&f.state.next({name:V,dirtyFields:Gi(o,a),isDirty:F(V,le)})):he&&!he._f&&!gn(le)?z(V,le,te):L(V,le,te),xx(V,s)&&f.state.next({...e,name:V}),f.state.next({name:i.mount?V:void 0,values:qt(a)})},M=async V=>{i.mount=!0;const Y=V.target;let te=Y.name,he=!0;const pe=me(r,te),le=Ge=>{he=Number.isNaN(Ge)||Ga(Ge)&&isNaN(Ge.getTime())||mo(Ge,me(a,te,Ge))},ye=yx(t.mode),We=yx(t.reValidateMode);if(pe){let Ge,Jt;const xr=Y.type?gx(pe._f):tx(V),er=V.type===Ll.BLUR||V.type===Ll.FOCUS_OUT,Os=!s8(pe._f)&&!t.resolver&&!me(e.errors,te)&&!pe._f.deps||l8(er,me(e.touchedFields,te),e.isSubmitted,We,ye),wr=xx(te,s,er);pt(a,te,xr),er?(!Y||!Y.readOnly)&&(pe._f.onBlur&&pe._f.onBlur(V),u&&u(0)):pe._f.onChange&&pe._f.onChange(V);const On=C(te,xr,er),ya=!kn(On)||wr;if(!er&&f.state.next({name:te,type:V.type,values:qt(a)}),Os)return(l.isValid||d.isValid)&&(t.mode==="onBlur"?er&&v():er||v()),ya&&f.state.next({name:te,...wr?{}:On});if(!er&&wr&&f.state.next({...e}),t.resolver){const{errors:Ao}=await E([te]);if(le(xr),he){const Tm=wx(e.errors,r,te),$d=wx(Ao,r,Tm.name||te);Ge=$d.error,te=$d.name,Jt=kn(Ao)}}else p([te],!0),Ge=(await _x(pe,s.disabled,a,h,t.shouldUseNativeValidation))[te],p([te]),le(xr),he&&(Ge?Jt=!1:(l.isValid||d.isValid)&&(Jt=await S(r,!0)));he&&(pe._f.deps&&(!Array.isArray(pe._f.deps)||pe._f.deps.length>0)&&A(pe._f.deps),_(te,Jt,Ge,On))}},T=(V,Y)=>{if(me(e.errors,Y)&&V.focus)return V.focus(),1},A=async(V,Y={})=>{let te,he;const pe=gu(V);if(t.resolver){const le=await $(Ot(V)?V:pe);te=kn(le),he=V?!pe.some(ye=>me(le,ye)):te}else V?(he=(await Promise.all(pe.map(async le=>{const ye=me(r,le);return await S(ye&&ye._f?{[le]:ye}:ye)}))).every(Boolean),!(!he&&!e.isValid)&&v()):he=te=await S(r);return f.state.next({...!zn(V)||(l.isValid||d.isValid)&&te!==e.isValid?{}:{name:V},...t.resolver||!V?{isValid:te}:{},errors:e.errors}),Y.shouldFocus&&!he&&bu(r,T,V?pe:s.mount),he},P=(V,Y)=>{let te={...i.mount?a:o};return Y&&(te=ux(Y.dirtyFields?e.dirtyFields:e.touchedFields,te)),Ot(V)?te:zn(V)?me(te,V):V.map(he=>me(te,he))},B=(V,Y)=>({invalid:!!me((Y||e).errors,V),isDirty:!!me((Y||e).dirtyFields,V),error:me((Y||e).errors,V),isValidating:!!me(e.validatingFields,V),isTouched:!!me((Y||e).touchedFields,V)}),K=V=>{V&&gu(V).forEach(Y=>Mt(e.errors,Y)),f.state.next({errors:V?e.errors:{}})},q=(V,Y,te)=>{const he=(me(r,V,{_f:{}})._f||{}).ref,pe=me(e.errors,V)||{},{ref:le,message:ye,type:We,...Ge}=pe;pt(e.errors,V,{...Ge,...Y,ref:he}),f.state.next({name:V,errors:e.errors,isValid:!1}),te&&te.shouldFocus&&he&&he.focus&&he.focus()},Z=(V,Y)=>dr(V)?f.state.subscribe({next:te=>"values"in te&&V(I(void 0,Y),te)}):I(V,Y,!0),oe=V=>f.state.subscribe({next:Y=>{c8(V.name,Y.name,V.exact)&&u8(Y,V.formState||l,Bt,V.reRenderRoot)&&V.callback({values:{...a},...e,...Y,defaultValues:o})}}).unsubscribe,ae=V=>(i.mount=!0,d={...d,...V.formState},oe({...V,formState:d})),X=(V,Y={})=>{for(const te of V?gu(V):s.mount)s.mount.delete(te),s.array.delete(te),Y.keepValue||(Mt(r,te),Mt(a,te)),!Y.keepError&&Mt(e.errors,te),!Y.keepDirty&&Mt(e.dirtyFields,te),!Y.keepTouched&&Mt(e.touchedFields,te),!Y.keepIsValidating&&Mt(e.validatingFields,te),!t.shouldUnregister&&!Y.keepDefaultValue&&Mt(o,te);f.state.next({values:qt(a)}),f.state.next({...e,...Y.keepDirty?{isDirty:F()}:{}}),!Y.keepIsValid&&v()},re=({disabled:V,name:Y})=>{(Un(V)&&i.mount||V||s.disabled.has(Y))&&(V?s.disabled.add(Y):s.disabled.delete(Y))},ce=(V,Y={})=>{let te=me(r,V);const he=Un(Y.disabled)||Un(t.disabled);return pt(r,V,{...te||{},_f:{...te&&te._f?te._f:{ref:{name:V}},name:V,mount:!0,...Y}}),s.mount.add(V),te?re({disabled:Un(Y.disabled)?Y.disabled:t.disabled,name:V}):x(V,!0,Y.value),{...he?{disabled:Y.disabled||t.disabled}:{},...t.progressive?{required:!!Y.required,min:yu(Y.min),max:yu(Y.max),minLength:yu(Y.minLength),maxLength:yu(Y.maxLength),pattern:yu(Y.pattern)}:{},name:V,onChange:M,onBlur:M,ref:pe=>{if(pe){ce(V,Y),te=me(r,V);const le=Ot(pe.value)&&pe.querySelectorAll&&pe.querySelectorAll("input,select,textarea")[0]||pe,ye=t8(le),We=te._f.refs||[];if(ye?We.find(Ge=>Ge===le):le===te._f.ref)return;pt(r,V,{_f:{...te._f,...ye?{refs:[...We.filter(Up),le,...Array.isArray(me(o,V))?[{}]:[]],ref:{type:le.type,name:V}}:{ref:le}}}),x(V,!1,void 0,le)}else te=me(r,V,{}),te._f&&(te._f.mount=!1),(t.shouldUnregister||Y.shouldUnregister)&&!(nx(s.array,V)&&i.action)&&s.unMount.add(V)}}},ue=()=>t.shouldFocusError&&bu(r,T,s.mount),se=V=>{Un(V)&&(f.state.next({disabled:V}),bu(r,(Y,te)=>{const he=me(r,te);he&&(Y.disabled=he._f.disabled||V,Array.isArray(he._f.refs)&&he._f.refs.forEach(pe=>{pe.disabled=he._f.disabled||V}))},0,!1))},ee=(V,Y)=>async te=>{let he;te&&(te.preventDefault&&te.preventDefault(),te.persist&&te.persist());let pe=qt(a);if(f.state.next({isSubmitting:!0}),t.resolver){const{errors:le,values:ye}=await E();e.errors=le,pe=qt(ye)}else await S(r);if(s.disabled.size)for(const le of s.disabled)Mt(pe,le);if(Mt(e.errors,"root"),kn(e.errors)){f.state.next({errors:{}});try{await V(pe,te)}catch(le){he=le}}else Y&&await Y({...e.errors},te),ue(),setTimeout(ue);if(f.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:kn(e.errors)&&!he,submitCount:e.submitCount+1,errors:e.errors}),he)throw he},_e=(V,Y={})=>{me(r,V)&&(Ot(Y.defaultValue)?H(V,qt(me(o,V))):(H(V,Y.defaultValue),pt(o,V,qt(Y.defaultValue))),Y.keepTouched||Mt(e.touchedFields,V),Y.keepDirty||(Mt(e.dirtyFields,V),e.isDirty=Y.defaultValue?F(V,qt(me(o,V))):F()),Y.keepError||(Mt(e.errors,V),l.isValid&&v()),f.state.next({...e}))},Fe=(V,Y={})=>{const te=V?qt(V):o,he=qt(te),pe=kn(V),le=pe?o:he;if(Y.keepDefaultValues||(o=te),!Y.keepValues){if(Y.keepDirtyValues){const ye=new Set([...s.mount,...Object.keys(Gi(o,a))]);for(const We of Array.from(ye))me(e.dirtyFields,We)?pt(le,We,me(a,We)):H(We,me(le,We))}else{if(Fp&&Ot(V))for(const ye of s.mount){const We=me(r,ye);if(We&&We._f){const Ge=Array.isArray(We._f.refs)?We._f.refs[0]:We._f.ref;if(Wl(Ge)){const Jt=Ge.closest("form");if(Jt){Jt.reset();break}}}}if(Y.keepFieldsRef)for(const ye of s.mount)H(ye,me(le,ye));else r={}}a=t.shouldUnregister?Y.keepDefaultValues?qt(o):{}:qt(le),f.array.next({values:{...le}}),f.state.next({values:{...le}})}s={mount:Y.keepDirtyValues?s.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},i.mount=!l.isValid||!!Y.keepIsValid||!!Y.keepDirtyValues,i.watch=!!t.shouldUnregister,f.state.next({submitCount:Y.keepSubmitCount?e.submitCount:0,isDirty:pe?!1:Y.keepDirty?e.isDirty:!!(Y.keepDefaultValues&&!mo(V,o)),isSubmitted:Y.keepIsSubmitted?e.isSubmitted:!1,dirtyFields:pe?{}:Y.keepDirtyValues?Y.keepDefaultValues&&a?Gi(o,a):e.dirtyFields:Y.keepDefaultValues&&V?Gi(o,V):Y.keepDirty?e.dirtyFields:{},touchedFields:Y.keepTouched?e.touchedFields:{},errors:Y.keepErrors?e.errors:{},isSubmitSuccessful:Y.keepIsSubmitSuccessful?e.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:o})},Ye=(V,Y)=>Fe(dr(V)?V(a):V,Y),Ze=(V,Y={})=>{const te=me(r,V),he=te&&te._f;if(he){const pe=he.refs?he.refs[0]:he.ref;pe.focus&&(pe.focus(),Y.shouldSelect&&dr(pe.select)&&pe.select())}},Bt=V=>{e={...e,...V}},Pt={control:{register:ce,unregister:X,getFieldState:B,handleSubmit:ee,setError:q,_subscribe:oe,_runSchema:E,_focusError:ue,_getWatch:I,_getDirty:F,_setValid:v,_setFieldArray:g,_setDisabledField:re,_setErrors:w,_getFieldArray:j,_reset:Fe,_resetDefaultValues:()=>dr(t.defaultValues)&&t.defaultValues().then(V=>{Ye(V,t.resetOptions),f.state.next({isLoading:!1})}),_removeUnmounted:N,_disableForm:se,_subjects:f,_proxyFormState:l,get _fields(){return r},get _formValues(){return a},get _state(){return i},set _state(V){i=V},get _defaultValues(){return o},get _names(){return s},set _names(V){s=V},get _formState(){return e},get _options(){return t},set _options(V){t={...t,...V}}},subscribe:ae,trigger:A,register:ce,handleSubmit:ee,watch:Z,setValue:H,getValues:P,reset:Ye,resetField:_e,clearErrors:K,unregister:X,setError:q,setFocus:Ze,getFieldState:B};return{...Pt,formControl:Pt}}function Ki(n={}){const t=D.useRef(void 0),e=D.useRef(void 0),[r,o]=D.useState({isDirty:!1,isValidating:!1,isLoading:dr(n.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:n.errors||{},disabled:n.disabled||!1,isReady:!1,defaultValues:dr(n.defaultValues)?void 0:n.defaultValues});if(!t.current)if(n.formControl)t.current={...n.formControl,formState:r},n.defaultValues&&!dr(n.defaultValues)&&n.formControl.reset(n.defaultValues,n.resetOptions);else{const{formControl:i,...s}=p8(n);t.current={...s,formState:r}}const a=t.current.control;return a._options=n,Bp(()=>{const i=a._subscribe({formState:a._proxyFormState,callback:()=>o({...a._formState}),reRenderRoot:!0});return o(s=>({...s,isReady:!0})),a._formState.isReady=!0,i},[a]),D.useEffect(()=>a._disableForm(n.disabled),[a,n.disabled]),D.useEffect(()=>{n.mode&&(a._options.mode=n.mode),n.reValidateMode&&(a._options.reValidateMode=n.reValidateMode)},[a,n.mode,n.reValidateMode]),D.useEffect(()=>{n.errors&&(a._setErrors(n.errors),a._focusError())},[a,n.errors]),D.useEffect(()=>{n.shouldUnregister&&a._subjects.state.next({values:a._getWatch()})},[a,n.shouldUnregister]),D.useEffect(()=>{if(a._proxyFormState.isDirty){const i=a._getDirty();i!==r.isDirty&&a._subjects.state.next({isDirty:i})}},[a,r.isDirty]),D.useEffect(()=>{n.values&&!mo(n.values,e.current)?(a._reset(n.values,{keepFieldsRef:!0,...a._options.resetOptions}),e.current=n.values,o(i=>({...i}))):a._resetDefaultValues()},[a,n.values]),D.useEffect(()=>{a._state.mount||(a._setValid(),a._state.mount=!0),a._state.watch&&(a._state.watch=!1,a._subjects.state.next({...a._formState})),a._removeUnmounted()}),t.current.formState=rx(r,a),t.current}const Ex=(n,t,e)=>{if(n&&"reportValidity"in n){const r=me(e,t);n.setCustomValidity(r&&r.message||""),n.reportValidity()}},Sx=(n,t)=>{for(const e in t.fields){const r=t.fields[e];r&&r.ref&&"reportValidity"in r.ref?Ex(r.ref,e,n):r.refs&&r.refs.forEach(o=>Ex(o,e,n))}},v8=(n,t)=>{t.shouldUseNativeValidation&&Sx(n,t);const e={};for(const r in n){const o=me(t.fields,r),a=Object.assign(n[r]||{},{ref:o&&o.ref});if(m8(t.names||Object.keys(n),r)){const i=Object.assign({},me(e,r));pt(i,"root",a),pt(e,r,i)}else pt(e,r,a)}return e},m8=(n,t)=>n.some(e=>e.startsWith(t+"."));var g8=function(n,t){for(var e={};n.length;){var r=n[0],o=r.code,a=r.message,i=r.path.join(".");if(!e[i])if("unionErrors"in r){var s=r.unionErrors[0].errors[0];e[i]={message:s.message,type:s.code}}else e[i]={message:a,type:o};if("unionErrors"in r&&r.unionErrors.forEach(function(l){return l.errors.forEach(function(d){return n.push(d)})}),t){var u=e[i].types,c=u&&u[r.code];e[i]=ix(i,t,e,o,c?[].concat(c,r.message):r.message)}n.shift()}return e},Yi=function(n,t,e){return e===void 0&&(e={}),function(r,o,a){try{return Promise.resolve(function(i,s){try{var u=Promise.resolve(n[e.mode==="sync"?"parse":"parseAsync"](r,t)).then(function(c){return a.shouldUseNativeValidation&&Sx({},a),{errors:{},values:e.raw?r:c}})}catch(c){return s(c)}return u&&u.then?u.then(void 0,s):u}(0,function(i){if(function(s){return Array.isArray(s==null?void 0:s.errors)}(i))return{values:{},errors:v8(g8(i.errors,!a.shouldUseNativeValidation&&a.criteriaMode==="all"),a)};throw i}))}catch(i){return Promise.reject(i)}}},st;(function(n){n.assertEqual=o=>{};function t(o){}n.assertIs=t;function e(o){throw new Error}n.assertNever=e,n.arrayToEnum=o=>{const a={};for(const i of o)a[i]=i;return a},n.getValidEnumValues=o=>{const a=n.objectKeys(o).filter(s=>typeof o[o[s]]!="number"),i={};for(const s of a)i[s]=o[s];return n.objectValues(i)},n.objectValues=o=>n.objectKeys(o).map(function(a){return o[a]}),n.objectKeys=typeof Object.keys=="function"?o=>Object.keys(o):o=>{const a=[];for(const i in o)Object.prototype.hasOwnProperty.call(o,i)&&a.push(i);return a},n.find=(o,a)=>{for(const i of o)if(a(i))return i},n.isInteger=typeof Number.isInteger=="function"?o=>Number.isInteger(o):o=>typeof o=="number"&&Number.isFinite(o)&&Math.floor(o)===o;function r(o,a=" | "){return o.map(i=>typeof i=="string"?`'${i}'`:i).join(a)}n.joinValues=r,n.jsonStringifyReplacer=(o,a)=>typeof a=="bigint"?a.toString():a})(st||(st={}));var Nx;(function(n){n.mergeShapes=(t,e)=>({...t,...e})})(Nx||(Nx={}));const Ee=st.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Zo=n=>{switch(typeof n){case"undefined":return Ee.undefined;case"string":return Ee.string;case"number":return Number.isNaN(n)?Ee.nan:Ee.number;case"boolean":return Ee.boolean;case"function":return Ee.function;case"bigint":return Ee.bigint;case"symbol":return Ee.symbol;case"object":return Array.isArray(n)?Ee.array:n===null?Ee.null:n.then&&typeof n.then=="function"&&n.catch&&typeof n.catch=="function"?Ee.promise:typeof Map<"u"&&n instanceof Map?Ee.map:typeof Set<"u"&&n instanceof Set?Ee.set:typeof Date<"u"&&n instanceof Date?Ee.date:Ee.object;default:return Ee.unknown}},de=st.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class go extends Error{get errors(){return this.issues}constructor(t){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const e=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,e):this.__proto__=e,this.name="ZodError",this.issues=t}format(t){const e=t||function(a){return a.message},r={_errors:[]},o=a=>{for(const i of a.issues)if(i.code==="invalid_union")i.unionErrors.map(o);else if(i.code==="invalid_return_type")o(i.returnTypeError);else if(i.code==="invalid_arguments")o(i.argumentsError);else if(i.path.length===0)r._errors.push(e(i));else{let s=r,u=0;for(;u<i.path.length;){const c=i.path[u];u===i.path.length-1?(s[c]=s[c]||{_errors:[]},s[c]._errors.push(e(i))):s[c]=s[c]||{_errors:[]},s=s[c],u++}}};return o(this),r}static assert(t){if(!(t instanceof go))throw new Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,st.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(t=e=>e.message){const e={},r=[];for(const o of this.issues)if(o.path.length>0){const a=o.path[0];e[a]=e[a]||[],e[a].push(t(o))}else r.push(t(o));return{formErrors:r,fieldErrors:e}}get formErrors(){return this.flatten()}}go.create=n=>new go(n);const Hp=(n,t)=>{let e;switch(n.code){case de.invalid_type:n.received===Ee.undefined?e="Required":e=`Expected ${n.expected}, received ${n.received}`;break;case de.invalid_literal:e=`Invalid literal value, expected ${JSON.stringify(n.expected,st.jsonStringifyReplacer)}`;break;case de.unrecognized_keys:e=`Unrecognized key(s) in object: ${st.joinValues(n.keys,", ")}`;break;case de.invalid_union:e="Invalid input";break;case de.invalid_union_discriminator:e=`Invalid discriminator value. Expected ${st.joinValues(n.options)}`;break;case de.invalid_enum_value:e=`Invalid enum value. Expected ${st.joinValues(n.options)}, received '${n.received}'`;break;case de.invalid_arguments:e="Invalid function arguments";break;case de.invalid_return_type:e="Invalid function return type";break;case de.invalid_date:e="Invalid date";break;case de.invalid_string:typeof n.validation=="object"?"includes"in n.validation?(e=`Invalid input: must include "${n.validation.includes}"`,typeof n.validation.position=="number"&&(e=`${e} at one or more positions greater than or equal to ${n.validation.position}`)):"startsWith"in n.validation?e=`Invalid input: must start with "${n.validation.startsWith}"`:"endsWith"in n.validation?e=`Invalid input: must end with "${n.validation.endsWith}"`:st.assertNever(n.validation):n.validation!=="regex"?e=`Invalid ${n.validation}`:e="Invalid";break;case de.too_small:n.type==="array"?e=`Array must contain ${n.exact?"exactly":n.inclusive?"at least":"more than"} ${n.minimum} element(s)`:n.type==="string"?e=`String must contain ${n.exact?"exactly":n.inclusive?"at least":"over"} ${n.minimum} character(s)`:n.type==="number"?e=`Number must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${n.minimum}`:n.type==="bigint"?e=`Number must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${n.minimum}`:n.type==="date"?e=`Date must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(n.minimum))}`:e="Invalid input";break;case de.too_big:n.type==="array"?e=`Array must contain ${n.exact?"exactly":n.inclusive?"at most":"less than"} ${n.maximum} element(s)`:n.type==="string"?e=`String must contain ${n.exact?"exactly":n.inclusive?"at most":"under"} ${n.maximum} character(s)`:n.type==="number"?e=`Number must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="bigint"?e=`BigInt must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="date"?e=`Date must be ${n.exact?"exactly":n.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(n.maximum))}`:e="Invalid input";break;case de.custom:e="Invalid input";break;case de.invalid_intersection_types:e="Intersection results could not be merged";break;case de.not_multiple_of:e=`Number must be a multiple of ${n.multipleOf}`;break;case de.not_finite:e="Number must be finite";break;default:e=t.defaultError,st.assertNever(n)}return{message:e}};let y8=Hp;function b8(){return y8}const x8=n=>{const{data:t,path:e,errorMaps:r,issueData:o}=n,a=[...e,...o.path||[]],i={...o,path:a};if(o.message!==void 0)return{...o,path:a,message:o.message};let s="";const u=r.filter(c=>!!c).slice().reverse();for(const c of u)s=c(i,{data:t,defaultError:s}).message;return{...o,path:a,message:s}};function be(n,t){const e=b8(),r=x8({issueData:t,data:n.data,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,e,e===Hp?void 0:Hp].filter(o=>!!o)});n.common.issues.push(r)}class Hn{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(t,e){const r=[];for(const o of e){if(o.status==="aborted")return Re;o.status==="dirty"&&t.dirty(),r.push(o.value)}return{status:t.value,value:r}}static async mergeObjectAsync(t,e){const r=[];for(const o of e){const a=await o.key,i=await o.value;r.push({key:a,value:i})}return Hn.mergeObjectSync(t,r)}static mergeObjectSync(t,e){const r={};for(const o of e){const{key:a,value:i}=o;if(a.status==="aborted"||i.status==="aborted")return Re;a.status==="dirty"&&t.dirty(),i.status==="dirty"&&t.dirty(),a.value!=="__proto__"&&(typeof i.value<"u"||o.alwaysSet)&&(r[a.value]=i.value)}return{status:t.value,value:r}}}const Re=Object.freeze({status:"aborted"}),xu=n=>({status:"dirty",value:n}),Qn=n=>({status:"valid",value:n}),$x=n=>n.status==="aborted",kx=n=>n.status==="dirty",Xi=n=>n.status==="valid",jl=n=>typeof Promise<"u"&&n instanceof Promise;var Pe;(function(n){n.errToObj=t=>typeof t=="string"?{message:t}:t||{},n.toString=t=>typeof t=="string"?t:t==null?void 0:t.message})(Pe||(Pe={}));class Qo{constructor(t,e,r,o){this._cachedPath=[],this.parent=t,this.data=e,this._path=r,this._key=o}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Px=(n,t)=>{if(Xi(t))return{success:!0,data:t.value};if(!n.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const e=new go(n.common.issues);return this._error=e,this._error}}};function Ke(n){if(!n)return{};const{errorMap:t,invalid_type_error:e,required_error:r,description:o}=n;if(t&&(e||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return t?{errorMap:t,description:o}:{errorMap:(i,s)=>{const{message:u}=n;return i.code==="invalid_enum_value"?{message:u??s.defaultError}:typeof s.data>"u"?{message:u??r??s.defaultError}:i.code!=="invalid_type"?{message:s.defaultError}:{message:u??e??s.defaultError}},description:o}}class tt{get description(){return this._def.description}_getType(t){return Zo(t.data)}_getOrReturnCtx(t,e){return e||{common:t.parent.common,data:t.data,parsedType:Zo(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new Hn,ctx:{common:t.parent.common,data:t.data,parsedType:Zo(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){const e=this._parse(t);if(jl(e))throw new Error("Synchronous parse encountered promise.");return e}_parseAsync(t){const e=this._parse(t);return Promise.resolve(e)}parse(t,e){const r=this.safeParse(t,e);if(r.success)return r.data;throw r.error}safeParse(t,e){const r={common:{issues:[],async:(e==null?void 0:e.async)??!1,contextualErrorMap:e==null?void 0:e.errorMap},path:(e==null?void 0:e.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:Zo(t)},o=this._parseSync({data:t,path:r.path,parent:r});return Px(r,o)}"~validate"(t){var r,o;const e={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:Zo(t)};if(!this["~standard"].async)try{const a=this._parseSync({data:t,path:[],parent:e});return Xi(a)?{value:a.value}:{issues:e.common.issues}}catch(a){(o=(r=a==null?void 0:a.message)==null?void 0:r.toLowerCase())!=null&&o.includes("encountered")&&(this["~standard"].async=!0),e.common={issues:[],async:!0}}return this._parseAsync({data:t,path:[],parent:e}).then(a=>Xi(a)?{value:a.value}:{issues:e.common.issues})}async parseAsync(t,e){const r=await this.safeParseAsync(t,e);if(r.success)return r.data;throw r.error}async safeParseAsync(t,e){const r={common:{issues:[],contextualErrorMap:e==null?void 0:e.errorMap,async:!0},path:(e==null?void 0:e.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:Zo(t)},o=this._parse({data:t,path:r.path,parent:r}),a=await(jl(o)?o:Promise.resolve(o));return Px(r,a)}refine(t,e){const r=o=>typeof e=="string"||typeof e>"u"?{message:e}:typeof e=="function"?e(o):e;return this._refinement((o,a)=>{const i=t(o),s=()=>a.addIssue({code:de.custom,...r(o)});return typeof Promise<"u"&&i instanceof Promise?i.then(u=>u?!0:(s(),!1)):i?!0:(s(),!1)})}refinement(t,e){return this._refinement((r,o)=>t(r)?!0:(o.addIssue(typeof e=="function"?e(r,o):e),!1))}_refinement(t){return new Ji({schema:this,typeName:Le.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}constructor(t){this.spa=this.safeParseAsync,this._def=t,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return ta.create(this,this._def)}nullable(){return es.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Hr.create(this)}promise(){return Hl.create(this,this._def)}or(t){return Ul.create([this,t],this._def)}and(t){return zl.create(this,t,this._def)}transform(t){return new Ji({...Ke(this._def),schema:this,typeName:Le.ZodEffects,effect:{type:"transform",transform:t}})}default(t){const e=typeof t=="function"?t:()=>t;return new Yp({...Ke(this._def),innerType:this,defaultValue:e,typeName:Le.ZodDefault})}brand(){return new U8({typeName:Le.ZodBranded,type:this,...Ke(this._def)})}catch(t){const e=typeof t=="function"?t:()=>t;return new Xp({...Ke(this._def),innerType:this,catchValue:e,typeName:Le.ZodCatch})}describe(t){const e=this.constructor;return new e({...this._def,description:t})}pipe(t){return Zp.create(this,t)}readonly(){return Qp.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const w8=/^c[^\s-]{8,}$/i,C8=/^[0-9a-z]+$/,_8=/^[0-9A-HJKMNP-TV-Z]{26}$/i,E8=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,S8=/^[a-z0-9_-]{21}$/i,N8=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,$8=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,k8=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,P8="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Gp;const I8=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,A8=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,T8=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,O8=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,D8=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,F8=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Ix="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",M8=new RegExp(`^${Ix}$`);function Ax(n){let t="[0-5]\\d";n.precision?t=`${t}\\.\\d{${n.precision}}`:n.precision==null&&(t=`${t}(\\.\\d+)?`);const e=n.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${e}`}function R8(n){return new RegExp(`^${Ax(n)}$`)}function L8(n){let t=`${Ix}T${Ax(n)}`;const e=[];return e.push(n.local?"Z?":"Z"),n.offset&&e.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${e.join("|")})`,new RegExp(`^${t}$`)}function B8(n,t){return!!((t==="v4"||!t)&&I8.test(n)||(t==="v6"||!t)&&T8.test(n))}function W8(n,t){if(!N8.test(n))return!1;try{const[e]=n.split(".");if(!e)return!1;const r=e.replace(/-/g,"+").replace(/_/g,"/").padEnd(e.length+(4-e.length%4)%4,"="),o=JSON.parse(atob(r));return!(typeof o!="object"||o===null||"typ"in o&&(o==null?void 0:o.typ)!=="JWT"||!o.alg||t&&o.alg!==t)}catch{return!1}}function V8(n,t){return!!((t==="v4"||!t)&&A8.test(n)||(t==="v6"||!t)&&O8.test(n))}class Jo extends tt{_parse(t){if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==Ee.string){const a=this._getOrReturnCtx(t);return be(a,{code:de.invalid_type,expected:Ee.string,received:a.parsedType}),Re}const r=new Hn;let o;for(const a of this._def.checks)if(a.kind==="min")t.data.length<a.value&&(o=this._getOrReturnCtx(t,o),be(o,{code:de.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),r.dirty());else if(a.kind==="max")t.data.length>a.value&&(o=this._getOrReturnCtx(t,o),be(o,{code:de.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),r.dirty());else if(a.kind==="length"){const i=t.data.length>a.value,s=t.data.length<a.value;(i||s)&&(o=this._getOrReturnCtx(t,o),i?be(o,{code:de.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):s&&be(o,{code:de.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),r.dirty())}else if(a.kind==="email")k8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"email",code:de.invalid_string,message:a.message}),r.dirty());else if(a.kind==="emoji")Gp||(Gp=new RegExp(P8,"u")),Gp.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"emoji",code:de.invalid_string,message:a.message}),r.dirty());else if(a.kind==="uuid")E8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"uuid",code:de.invalid_string,message:a.message}),r.dirty());else if(a.kind==="nanoid")S8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"nanoid",code:de.invalid_string,message:a.message}),r.dirty());else if(a.kind==="cuid")w8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"cuid",code:de.invalid_string,message:a.message}),r.dirty());else if(a.kind==="cuid2")C8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"cuid2",code:de.invalid_string,message:a.message}),r.dirty());else if(a.kind==="ulid")_8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"ulid",code:de.invalid_string,message:a.message}),r.dirty());else if(a.kind==="url")try{new URL(t.data)}catch{o=this._getOrReturnCtx(t,o),be(o,{validation:"url",code:de.invalid_string,message:a.message}),r.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"regex",code:de.invalid_string,message:a.message}),r.dirty())):a.kind==="trim"?t.data=t.data.trim():a.kind==="includes"?t.data.includes(a.value,a.position)||(o=this._getOrReturnCtx(t,o),be(o,{code:de.invalid_string,validation:{includes:a.value,position:a.position},message:a.message}),r.dirty()):a.kind==="toLowerCase"?t.data=t.data.toLowerCase():a.kind==="toUpperCase"?t.data=t.data.toUpperCase():a.kind==="startsWith"?t.data.startsWith(a.value)||(o=this._getOrReturnCtx(t,o),be(o,{code:de.invalid_string,validation:{startsWith:a.value},message:a.message}),r.dirty()):a.kind==="endsWith"?t.data.endsWith(a.value)||(o=this._getOrReturnCtx(t,o),be(o,{code:de.invalid_string,validation:{endsWith:a.value},message:a.message}),r.dirty()):a.kind==="datetime"?L8(a).test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{code:de.invalid_string,validation:"datetime",message:a.message}),r.dirty()):a.kind==="date"?M8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{code:de.invalid_string,validation:"date",message:a.message}),r.dirty()):a.kind==="time"?R8(a).test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{code:de.invalid_string,validation:"time",message:a.message}),r.dirty()):a.kind==="duration"?$8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"duration",code:de.invalid_string,message:a.message}),r.dirty()):a.kind==="ip"?B8(t.data,a.version)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"ip",code:de.invalid_string,message:a.message}),r.dirty()):a.kind==="jwt"?W8(t.data,a.alg)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"jwt",code:de.invalid_string,message:a.message}),r.dirty()):a.kind==="cidr"?V8(t.data,a.version)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"cidr",code:de.invalid_string,message:a.message}),r.dirty()):a.kind==="base64"?D8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"base64",code:de.invalid_string,message:a.message}),r.dirty()):a.kind==="base64url"?F8.test(t.data)||(o=this._getOrReturnCtx(t,o),be(o,{validation:"base64url",code:de.invalid_string,message:a.message}),r.dirty()):st.assertNever(a);return{status:r.value,value:t.data}}_regex(t,e,r){return this.refinement(o=>t.test(o),{validation:e,code:de.invalid_string,...Pe.errToObj(r)})}_addCheck(t){return new Jo({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...Pe.errToObj(t)})}url(t){return this._addCheck({kind:"url",...Pe.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...Pe.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...Pe.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...Pe.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...Pe.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...Pe.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...Pe.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...Pe.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...Pe.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...Pe.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...Pe.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...Pe.errToObj(t)})}datetime(t){return typeof t=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:t}):this._addCheck({kind:"datetime",precision:typeof(t==null?void 0:t.precision)>"u"?null:t==null?void 0:t.precision,offset:(t==null?void 0:t.offset)??!1,local:(t==null?void 0:t.local)??!1,...Pe.errToObj(t==null?void 0:t.message)})}date(t){return this._addCheck({kind:"date",message:t})}time(t){return typeof t=="string"?this._addCheck({kind:"time",precision:null,message:t}):this._addCheck({kind:"time",precision:typeof(t==null?void 0:t.precision)>"u"?null:t==null?void 0:t.precision,...Pe.errToObj(t==null?void 0:t.message)})}duration(t){return this._addCheck({kind:"duration",...Pe.errToObj(t)})}regex(t,e){return this._addCheck({kind:"regex",regex:t,...Pe.errToObj(e)})}includes(t,e){return this._addCheck({kind:"includes",value:t,position:e==null?void 0:e.position,...Pe.errToObj(e==null?void 0:e.message)})}startsWith(t,e){return this._addCheck({kind:"startsWith",value:t,...Pe.errToObj(e)})}endsWith(t,e){return this._addCheck({kind:"endsWith",value:t,...Pe.errToObj(e)})}min(t,e){return this._addCheck({kind:"min",value:t,...Pe.errToObj(e)})}max(t,e){return this._addCheck({kind:"max",value:t,...Pe.errToObj(e)})}length(t,e){return this._addCheck({kind:"length",value:t,...Pe.errToObj(e)})}nonempty(t){return this.min(1,Pe.errToObj(t))}trim(){return new Jo({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Jo({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Jo({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(t=>t.kind==="datetime")}get isDate(){return!!this._def.checks.find(t=>t.kind==="date")}get isTime(){return!!this._def.checks.find(t=>t.kind==="time")}get isDuration(){return!!this._def.checks.find(t=>t.kind==="duration")}get isEmail(){return!!this._def.checks.find(t=>t.kind==="email")}get isURL(){return!!this._def.checks.find(t=>t.kind==="url")}get isEmoji(){return!!this._def.checks.find(t=>t.kind==="emoji")}get isUUID(){return!!this._def.checks.find(t=>t.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(t=>t.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(t=>t.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(t=>t.kind==="cuid2")}get isULID(){return!!this._def.checks.find(t=>t.kind==="ulid")}get isIP(){return!!this._def.checks.find(t=>t.kind==="ip")}get isCIDR(){return!!this._def.checks.find(t=>t.kind==="cidr")}get isBase64(){return!!this._def.checks.find(t=>t.kind==="base64")}get isBase64url(){return!!this._def.checks.find(t=>t.kind==="base64url")}get minLength(){let t=null;for(const e of this._def.checks)e.kind==="min"&&(t===null||e.value>t)&&(t=e.value);return t}get maxLength(){let t=null;for(const e of this._def.checks)e.kind==="max"&&(t===null||e.value<t)&&(t=e.value);return t}}Jo.create=n=>new Jo({checks:[],typeName:Le.ZodString,coerce:(n==null?void 0:n.coerce)??!1,...Ke(n)});function j8(n,t){const e=(n.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,o=e>r?e:r,a=Number.parseInt(n.toFixed(o).replace(".","")),i=Number.parseInt(t.toFixed(o).replace(".",""));return a%i/10**o}class wu extends tt{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){if(this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==Ee.number){const a=this._getOrReturnCtx(t);return be(a,{code:de.invalid_type,expected:Ee.number,received:a.parsedType}),Re}let r;const o=new Hn;for(const a of this._def.checks)a.kind==="int"?st.isInteger(t.data)||(r=this._getOrReturnCtx(t,r),be(r,{code:de.invalid_type,expected:"integer",received:"float",message:a.message}),o.dirty()):a.kind==="min"?(a.inclusive?t.data<a.value:t.data<=a.value)&&(r=this._getOrReturnCtx(t,r),be(r,{code:de.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),o.dirty()):a.kind==="max"?(a.inclusive?t.data>a.value:t.data>=a.value)&&(r=this._getOrReturnCtx(t,r),be(r,{code:de.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),o.dirty()):a.kind==="multipleOf"?j8(t.data,a.value)!==0&&(r=this._getOrReturnCtx(t,r),be(r,{code:de.not_multiple_of,multipleOf:a.value,message:a.message}),o.dirty()):a.kind==="finite"?Number.isFinite(t.data)||(r=this._getOrReturnCtx(t,r),be(r,{code:de.not_finite,message:a.message}),o.dirty()):st.assertNever(a);return{status:o.value,value:t.data}}gte(t,e){return this.setLimit("min",t,!0,Pe.toString(e))}gt(t,e){return this.setLimit("min",t,!1,Pe.toString(e))}lte(t,e){return this.setLimit("max",t,!0,Pe.toString(e))}lt(t,e){return this.setLimit("max",t,!1,Pe.toString(e))}setLimit(t,e,r,o){return new wu({...this._def,checks:[...this._def.checks,{kind:t,value:e,inclusive:r,message:Pe.toString(o)}]})}_addCheck(t){return new wu({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:Pe.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:Pe.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:Pe.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:Pe.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:Pe.toString(t)})}multipleOf(t,e){return this._addCheck({kind:"multipleOf",value:t,message:Pe.toString(e)})}finite(t){return this._addCheck({kind:"finite",message:Pe.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:Pe.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:Pe.toString(t)})}get minValue(){let t=null;for(const e of this._def.checks)e.kind==="min"&&(t===null||e.value>t)&&(t=e.value);return t}get maxValue(){let t=null;for(const e of this._def.checks)e.kind==="max"&&(t===null||e.value<t)&&(t=e.value);return t}get isInt(){return!!this._def.checks.find(t=>t.kind==="int"||t.kind==="multipleOf"&&st.isInteger(t.value))}get isFinite(){let t=null,e=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(e===null||r.value>e)&&(e=r.value):r.kind==="max"&&(t===null||r.value<t)&&(t=r.value)}return Number.isFinite(e)&&Number.isFinite(t)}}wu.create=n=>new wu({checks:[],typeName:Le.ZodNumber,coerce:(n==null?void 0:n.coerce)||!1,...Ke(n)});class Cu extends tt{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){if(this._def.coerce)try{t.data=BigInt(t.data)}catch{return this._getInvalidInput(t)}if(this._getType(t)!==Ee.bigint)return this._getInvalidInput(t);let r;const o=new Hn;for(const a of this._def.checks)a.kind==="min"?(a.inclusive?t.data<a.value:t.data<=a.value)&&(r=this._getOrReturnCtx(t,r),be(r,{code:de.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),o.dirty()):a.kind==="max"?(a.inclusive?t.data>a.value:t.data>=a.value)&&(r=this._getOrReturnCtx(t,r),be(r,{code:de.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),o.dirty()):a.kind==="multipleOf"?t.data%a.value!==BigInt(0)&&(r=this._getOrReturnCtx(t,r),be(r,{code:de.not_multiple_of,multipleOf:a.value,message:a.message}),o.dirty()):st.assertNever(a);return{status:o.value,value:t.data}}_getInvalidInput(t){const e=this._getOrReturnCtx(t);return be(e,{code:de.invalid_type,expected:Ee.bigint,received:e.parsedType}),Re}gte(t,e){return this.setLimit("min",t,!0,Pe.toString(e))}gt(t,e){return this.setLimit("min",t,!1,Pe.toString(e))}lte(t,e){return this.setLimit("max",t,!0,Pe.toString(e))}lt(t,e){return this.setLimit("max",t,!1,Pe.toString(e))}setLimit(t,e,r,o){return new Cu({...this._def,checks:[...this._def.checks,{kind:t,value:e,inclusive:r,message:Pe.toString(o)}]})}_addCheck(t){return new Cu({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:Pe.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:Pe.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:Pe.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:Pe.toString(t)})}multipleOf(t,e){return this._addCheck({kind:"multipleOf",value:t,message:Pe.toString(e)})}get minValue(){let t=null;for(const e of this._def.checks)e.kind==="min"&&(t===null||e.value>t)&&(t=e.value);return t}get maxValue(){let t=null;for(const e of this._def.checks)e.kind==="max"&&(t===null||e.value<t)&&(t=e.value);return t}}Cu.create=n=>new Cu({checks:[],typeName:Le.ZodBigInt,coerce:(n==null?void 0:n.coerce)??!1,...Ke(n)});class Tx extends tt{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==Ee.boolean){const r=this._getOrReturnCtx(t);return be(r,{code:de.invalid_type,expected:Ee.boolean,received:r.parsedType}),Re}return Qn(t.data)}}Tx.create=n=>new Tx({typeName:Le.ZodBoolean,coerce:(n==null?void 0:n.coerce)||!1,...Ke(n)});class _u extends tt{_parse(t){if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==Ee.date){const a=this._getOrReturnCtx(t);return be(a,{code:de.invalid_type,expected:Ee.date,received:a.parsedType}),Re}if(Number.isNaN(t.data.getTime())){const a=this._getOrReturnCtx(t);return be(a,{code:de.invalid_date}),Re}const r=new Hn;let o;for(const a of this._def.checks)a.kind==="min"?t.data.getTime()<a.value&&(o=this._getOrReturnCtx(t,o),be(o,{code:de.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),r.dirty()):a.kind==="max"?t.data.getTime()>a.value&&(o=this._getOrReturnCtx(t,o),be(o,{code:de.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),r.dirty()):st.assertNever(a);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new _u({...this._def,checks:[...this._def.checks,t]})}min(t,e){return this._addCheck({kind:"min",value:t.getTime(),message:Pe.toString(e)})}max(t,e){return this._addCheck({kind:"max",value:t.getTime(),message:Pe.toString(e)})}get minDate(){let t=null;for(const e of this._def.checks)e.kind==="min"&&(t===null||e.value>t)&&(t=e.value);return t!=null?new Date(t):null}get maxDate(){let t=null;for(const e of this._def.checks)e.kind==="max"&&(t===null||e.value<t)&&(t=e.value);return t!=null?new Date(t):null}}_u.create=n=>new _u({checks:[],coerce:(n==null?void 0:n.coerce)||!1,typeName:Le.ZodDate,...Ke(n)});class Ox extends tt{_parse(t){if(this._getType(t)!==Ee.symbol){const r=this._getOrReturnCtx(t);return be(r,{code:de.invalid_type,expected:Ee.symbol,received:r.parsedType}),Re}return Qn(t.data)}}Ox.create=n=>new Ox({typeName:Le.ZodSymbol,...Ke(n)});class Dx extends tt{_parse(t){if(this._getType(t)!==Ee.undefined){const r=this._getOrReturnCtx(t);return be(r,{code:de.invalid_type,expected:Ee.undefined,received:r.parsedType}),Re}return Qn(t.data)}}Dx.create=n=>new Dx({typeName:Le.ZodUndefined,...Ke(n)});class Fx extends tt{_parse(t){if(this._getType(t)!==Ee.null){const r=this._getOrReturnCtx(t);return be(r,{code:de.invalid_type,expected:Ee.null,received:r.parsedType}),Re}return Qn(t.data)}}Fx.create=n=>new Fx({typeName:Le.ZodNull,...Ke(n)});class Eu extends tt{constructor(){super(...arguments),this._any=!0}_parse(t){return Qn(t.data)}}Eu.create=n=>new Eu({typeName:Le.ZodAny,...Ke(n)});class Mx extends tt{constructor(){super(...arguments),this._unknown=!0}_parse(t){return Qn(t.data)}}Mx.create=n=>new Mx({typeName:Le.ZodUnknown,...Ke(n)});class ea extends tt{_parse(t){const e=this._getOrReturnCtx(t);return be(e,{code:de.invalid_type,expected:Ee.never,received:e.parsedType}),Re}}ea.create=n=>new ea({typeName:Le.ZodNever,...Ke(n)});class Rx extends tt{_parse(t){if(this._getType(t)!==Ee.undefined){const r=this._getOrReturnCtx(t);return be(r,{code:de.invalid_type,expected:Ee.void,received:r.parsedType}),Re}return Qn(t.data)}}Rx.create=n=>new Rx({typeName:Le.ZodVoid,...Ke(n)});class Hr extends tt{_parse(t){const{ctx:e,status:r}=this._processInputParams(t),o=this._def;if(e.parsedType!==Ee.array)return be(e,{code:de.invalid_type,expected:Ee.array,received:e.parsedType}),Re;if(o.exactLength!==null){const i=e.data.length>o.exactLength.value,s=e.data.length<o.exactLength.value;(i||s)&&(be(e,{code:i?de.too_big:de.too_small,minimum:s?o.exactLength.value:void 0,maximum:i?o.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:o.exactLength.message}),r.dirty())}if(o.minLength!==null&&e.data.length<o.minLength.value&&(be(e,{code:de.too_small,minimum:o.minLength.value,type:"array",inclusive:!0,exact:!1,message:o.minLength.message}),r.dirty()),o.maxLength!==null&&e.data.length>o.maxLength.value&&(be(e,{code:de.too_big,maximum:o.maxLength.value,type:"array",inclusive:!0,exact:!1,message:o.maxLength.message}),r.dirty()),e.common.async)return Promise.all([...e.data].map((i,s)=>o.type._parseAsync(new Qo(e,i,e.path,s)))).then(i=>Hn.mergeArray(r,i));const a=[...e.data].map((i,s)=>o.type._parseSync(new Qo(e,i,e.path,s)));return Hn.mergeArray(r,a)}get element(){return this._def.type}min(t,e){return new Hr({...this._def,minLength:{value:t,message:Pe.toString(e)}})}max(t,e){return new Hr({...this._def,maxLength:{value:t,message:Pe.toString(e)}})}length(t,e){return new Hr({...this._def,exactLength:{value:t,message:Pe.toString(e)}})}nonempty(t){return this.min(1,t)}}Hr.create=(n,t)=>new Hr({type:n,minLength:null,maxLength:null,exactLength:null,typeName:Le.ZodArray,...Ke(t)});function Zi(n){if(n instanceof Rt){const t={};for(const e in n.shape){const r=n.shape[e];t[e]=ta.create(Zi(r))}return new Rt({...n._def,shape:()=>t})}else return n instanceof Hr?new Hr({...n._def,type:Zi(n.element)}):n instanceof ta?ta.create(Zi(n.unwrap())):n instanceof es?es.create(Zi(n.unwrap())):n instanceof qa?qa.create(n.items.map(t=>Zi(t))):n}class Rt extends tt{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const t=this._def.shape(),e=st.objectKeys(t);return this._cached={shape:t,keys:e},this._cached}_parse(t){if(this._getType(t)!==Ee.object){const c=this._getOrReturnCtx(t);return be(c,{code:de.invalid_type,expected:Ee.object,received:c.parsedType}),Re}const{status:r,ctx:o}=this._processInputParams(t),{shape:a,keys:i}=this._getCached(),s=[];if(!(this._def.catchall instanceof ea&&this._def.unknownKeys==="strip"))for(const c in o.data)i.includes(c)||s.push(c);const u=[];for(const c of i){const l=a[c],d=o.data[c];u.push({key:{status:"valid",value:c},value:l._parse(new Qo(o,d,o.path,c)),alwaysSet:c in o.data})}if(this._def.catchall instanceof ea){const c=this._def.unknownKeys;if(c==="passthrough")for(const l of s)u.push({key:{status:"valid",value:l},value:{status:"valid",value:o.data[l]}});else if(c==="strict")s.length>0&&(be(o,{code:de.unrecognized_keys,keys:s}),r.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const c=this._def.catchall;for(const l of s){const d=o.data[l];u.push({key:{status:"valid",value:l},value:c._parse(new Qo(o,d,o.path,l)),alwaysSet:l in o.data})}}return o.common.async?Promise.resolve().then(async()=>{const c=[];for(const l of u){const d=await l.key,f=await l.value;c.push({key:d,value:f,alwaysSet:l.alwaysSet})}return c}).then(c=>Hn.mergeObjectSync(r,c)):Hn.mergeObjectSync(r,u)}get shape(){return this._def.shape()}strict(t){return Pe.errToObj,new Rt({...this._def,unknownKeys:"strict",...t!==void 0?{errorMap:(e,r)=>{var a,i;const o=((i=(a=this._def).errorMap)==null?void 0:i.call(a,e,r).message)??r.defaultError;return e.code==="unrecognized_keys"?{message:Pe.errToObj(t).message??o}:{message:o}}}:{}})}strip(){return new Rt({...this._def,unknownKeys:"strip"})}passthrough(){return new Rt({...this._def,unknownKeys:"passthrough"})}extend(t){return new Rt({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new Rt({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:Le.ZodObject})}setKey(t,e){return this.augment({[t]:e})}catchall(t){return new Rt({...this._def,catchall:t})}pick(t){const e={};for(const r of st.objectKeys(t))t[r]&&this.shape[r]&&(e[r]=this.shape[r]);return new Rt({...this._def,shape:()=>e})}omit(t){const e={};for(const r of st.objectKeys(this.shape))t[r]||(e[r]=this.shape[r]);return new Rt({...this._def,shape:()=>e})}deepPartial(){return Zi(this)}partial(t){const e={};for(const r of st.objectKeys(this.shape)){const o=this.shape[r];t&&!t[r]?e[r]=o:e[r]=o.optional()}return new Rt({...this._def,shape:()=>e})}required(t){const e={};for(const r of st.objectKeys(this.shape))if(t&&!t[r])e[r]=this.shape[r];else{let a=this.shape[r];for(;a instanceof ta;)a=a._def.innerType;e[r]=a}return new Rt({...this._def,shape:()=>e})}keyof(){return Wx(st.objectKeys(this.shape))}}Rt.create=(n,t)=>new Rt({shape:()=>n,unknownKeys:"strip",catchall:ea.create(),typeName:Le.ZodObject,...Ke(t)}),Rt.strictCreate=(n,t)=>new Rt({shape:()=>n,unknownKeys:"strict",catchall:ea.create(),typeName:Le.ZodObject,...Ke(t)}),Rt.lazycreate=(n,t)=>new Rt({shape:n,unknownKeys:"strip",catchall:ea.create(),typeName:Le.ZodObject,...Ke(t)});class Ul extends tt{_parse(t){const{ctx:e}=this._processInputParams(t),r=this._def.options;function o(a){for(const s of a)if(s.result.status==="valid")return s.result;for(const s of a)if(s.result.status==="dirty")return e.common.issues.push(...s.ctx.common.issues),s.result;const i=a.map(s=>new go(s.ctx.common.issues));return be(e,{code:de.invalid_union,unionErrors:i}),Re}if(e.common.async)return Promise.all(r.map(async a=>{const i={...e,common:{...e.common,issues:[]},parent:null};return{result:await a._parseAsync({data:e.data,path:e.path,parent:i}),ctx:i}})).then(o);{let a;const i=[];for(const u of r){const c={...e,common:{...e.common,issues:[]},parent:null},l=u._parseSync({data:e.data,path:e.path,parent:c});if(l.status==="valid")return l;l.status==="dirty"&&!a&&(a={result:l,ctx:c}),c.common.issues.length&&i.push(c.common.issues)}if(a)return e.common.issues.push(...a.ctx.common.issues),a.result;const s=i.map(u=>new go(u));return be(e,{code:de.invalid_union,unionErrors:s}),Re}}get options(){return this._def.options}}Ul.create=(n,t)=>new Ul({options:n,typeName:Le.ZodUnion,...Ke(t)});function qp(n,t){const e=Zo(n),r=Zo(t);if(n===t)return{valid:!0,data:n};if(e===Ee.object&&r===Ee.object){const o=st.objectKeys(t),a=st.objectKeys(n).filter(s=>o.indexOf(s)!==-1),i={...n,...t};for(const s of a){const u=qp(n[s],t[s]);if(!u.valid)return{valid:!1};i[s]=u.data}return{valid:!0,data:i}}else if(e===Ee.array&&r===Ee.array){if(n.length!==t.length)return{valid:!1};const o=[];for(let a=0;a<n.length;a++){const i=n[a],s=t[a],u=qp(i,s);if(!u.valid)return{valid:!1};o.push(u.data)}return{valid:!0,data:o}}else return e===Ee.date&&r===Ee.date&&+n==+t?{valid:!0,data:n}:{valid:!1}}class zl extends tt{_parse(t){const{status:e,ctx:r}=this._processInputParams(t),o=(a,i)=>{if($x(a)||$x(i))return Re;const s=qp(a.value,i.value);return s.valid?((kx(a)||kx(i))&&e.dirty(),{status:e.value,value:s.data}):(be(r,{code:de.invalid_intersection_types}),Re)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([a,i])=>o(a,i)):o(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}zl.create=(n,t,e)=>new zl({left:n,right:t,typeName:Le.ZodIntersection,...Ke(e)});class qa extends tt{_parse(t){const{status:e,ctx:r}=this._processInputParams(t);if(r.parsedType!==Ee.array)return be(r,{code:de.invalid_type,expected:Ee.array,received:r.parsedType}),Re;if(r.data.length<this._def.items.length)return be(r,{code:de.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),Re;!this._def.rest&&r.data.length>this._def.items.length&&(be(r,{code:de.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),e.dirty());const a=[...r.data].map((i,s)=>{const u=this._def.items[s]||this._def.rest;return u?u._parse(new Qo(r,i,r.path,s)):null}).filter(i=>!!i);return r.common.async?Promise.all(a).then(i=>Hn.mergeArray(e,i)):Hn.mergeArray(e,a)}get items(){return this._def.items}rest(t){return new qa({...this._def,rest:t})}}qa.create=(n,t)=>{if(!Array.isArray(n))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new qa({items:n,typeName:Le.ZodTuple,rest:null,...Ke(t)})};class Lx extends tt{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){const{status:e,ctx:r}=this._processInputParams(t);if(r.parsedType!==Ee.map)return be(r,{code:de.invalid_type,expected:Ee.map,received:r.parsedType}),Re;const o=this._def.keyType,a=this._def.valueType,i=[...r.data.entries()].map(([s,u],c)=>({key:o._parse(new Qo(r,s,r.path,[c,"key"])),value:a._parse(new Qo(r,u,r.path,[c,"value"]))}));if(r.common.async){const s=new Map;return Promise.resolve().then(async()=>{for(const u of i){const c=await u.key,l=await u.value;if(c.status==="aborted"||l.status==="aborted")return Re;(c.status==="dirty"||l.status==="dirty")&&e.dirty(),s.set(c.value,l.value)}return{status:e.value,value:s}})}else{const s=new Map;for(const u of i){const c=u.key,l=u.value;if(c.status==="aborted"||l.status==="aborted")return Re;(c.status==="dirty"||l.status==="dirty")&&e.dirty(),s.set(c.value,l.value)}return{status:e.value,value:s}}}}Lx.create=(n,t,e)=>new Lx({valueType:t,keyType:n,typeName:Le.ZodMap,...Ke(e)});class Su extends tt{_parse(t){const{status:e,ctx:r}=this._processInputParams(t);if(r.parsedType!==Ee.set)return be(r,{code:de.invalid_type,expected:Ee.set,received:r.parsedType}),Re;const o=this._def;o.minSize!==null&&r.data.size<o.minSize.value&&(be(r,{code:de.too_small,minimum:o.minSize.value,type:"set",inclusive:!0,exact:!1,message:o.minSize.message}),e.dirty()),o.maxSize!==null&&r.data.size>o.maxSize.value&&(be(r,{code:de.too_big,maximum:o.maxSize.value,type:"set",inclusive:!0,exact:!1,message:o.maxSize.message}),e.dirty());const a=this._def.valueType;function i(u){const c=new Set;for(const l of u){if(l.status==="aborted")return Re;l.status==="dirty"&&e.dirty(),c.add(l.value)}return{status:e.value,value:c}}const s=[...r.data.values()].map((u,c)=>a._parse(new Qo(r,u,r.path,c)));return r.common.async?Promise.all(s).then(u=>i(u)):i(s)}min(t,e){return new Su({...this._def,minSize:{value:t,message:Pe.toString(e)}})}max(t,e){return new Su({...this._def,maxSize:{value:t,message:Pe.toString(e)}})}size(t,e){return this.min(t,e).max(t,e)}nonempty(t){return this.min(1,t)}}Su.create=(n,t)=>new Su({valueType:n,minSize:null,maxSize:null,typeName:Le.ZodSet,...Ke(t)});class Bx extends tt{get schema(){return this._def.getter()}_parse(t){const{ctx:e}=this._processInputParams(t);return this._def.getter()._parse({data:e.data,path:e.path,parent:e})}}Bx.create=(n,t)=>new Bx({getter:n,typeName:Le.ZodLazy,...Ke(t)});class Kp extends tt{_parse(t){if(t.data!==this._def.value){const e=this._getOrReturnCtx(t);return be(e,{received:e.data,code:de.invalid_literal,expected:this._def.value}),Re}return{status:"valid",value:t.data}}get value(){return this._def.value}}Kp.create=(n,t)=>new Kp({value:n,typeName:Le.ZodLiteral,...Ke(t)});function Wx(n,t){return new Qi({values:n,typeName:Le.ZodEnum,...Ke(t)})}class Qi extends tt{_parse(t){if(typeof t.data!="string"){const e=this._getOrReturnCtx(t),r=this._def.values;return be(e,{expected:st.joinValues(r),received:e.parsedType,code:de.invalid_type}),Re}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(t.data)){const e=this._getOrReturnCtx(t),r=this._def.values;return be(e,{received:e.data,code:de.invalid_enum_value,options:r}),Re}return Qn(t.data)}get options(){return this._def.values}get enum(){const t={};for(const e of this._def.values)t[e]=e;return t}get Values(){const t={};for(const e of this._def.values)t[e]=e;return t}get Enum(){const t={};for(const e of this._def.values)t[e]=e;return t}extract(t,e=this._def){return Qi.create(t,{...this._def,...e})}exclude(t,e=this._def){return Qi.create(this.options.filter(r=>!t.includes(r)),{...this._def,...e})}}Qi.create=Wx;class Vx extends tt{_parse(t){const e=st.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==Ee.string&&r.parsedType!==Ee.number){const o=st.objectValues(e);return be(r,{expected:st.joinValues(o),received:r.parsedType,code:de.invalid_type}),Re}if(this._cache||(this._cache=new Set(st.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){const o=st.objectValues(e);return be(r,{received:r.data,code:de.invalid_enum_value,options:o}),Re}return Qn(t.data)}get enum(){return this._def.values}}Vx.create=(n,t)=>new Vx({values:n,typeName:Le.ZodNativeEnum,...Ke(t)});class Hl extends tt{unwrap(){return this._def.type}_parse(t){const{ctx:e}=this._processInputParams(t);if(e.parsedType!==Ee.promise&&e.common.async===!1)return be(e,{code:de.invalid_type,expected:Ee.promise,received:e.parsedType}),Re;const r=e.parsedType===Ee.promise?e.data:Promise.resolve(e.data);return Qn(r.then(o=>this._def.type.parseAsync(o,{path:e.path,errorMap:e.common.contextualErrorMap})))}}Hl.create=(n,t)=>new Hl({type:n,typeName:Le.ZodPromise,...Ke(t)});class Ji extends tt{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===Le.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){const{status:e,ctx:r}=this._processInputParams(t),o=this._def.effect||null,a={addIssue:i=>{be(r,i),i.fatal?e.abort():e.dirty()},get path(){return r.path}};if(a.addIssue=a.addIssue.bind(a),o.type==="preprocess"){const i=o.transform(r.data,a);if(r.common.async)return Promise.resolve(i).then(async s=>{if(e.value==="aborted")return Re;const u=await this._def.schema._parseAsync({data:s,path:r.path,parent:r});return u.status==="aborted"?Re:u.status==="dirty"||e.value==="dirty"?xu(u.value):u});{if(e.value==="aborted")return Re;const s=this._def.schema._parseSync({data:i,path:r.path,parent:r});return s.status==="aborted"?Re:s.status==="dirty"||e.value==="dirty"?xu(s.value):s}}if(o.type==="refinement"){const i=s=>{const u=o.refinement(s,a);if(r.common.async)return Promise.resolve(u);if(u instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return s};if(r.common.async===!1){const s=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?Re:(s.status==="dirty"&&e.dirty(),i(s.value),{status:e.value,value:s.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(s=>s.status==="aborted"?Re:(s.status==="dirty"&&e.dirty(),i(s.value).then(()=>({status:e.value,value:s.value}))))}if(o.type==="transform")if(r.common.async===!1){const i=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Xi(i))return Re;const s=o.transform(i.value,a);if(s instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:e.value,value:s}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(i=>Xi(i)?Promise.resolve(o.transform(i.value,a)).then(s=>({status:e.value,value:s})):Re);st.assertNever(o)}}Ji.create=(n,t,e)=>new Ji({schema:n,typeName:Le.ZodEffects,effect:t,...Ke(e)}),Ji.createWithPreprocess=(n,t,e)=>new Ji({schema:t,effect:{type:"preprocess",transform:n},typeName:Le.ZodEffects,...Ke(e)});class ta extends tt{_parse(t){return this._getType(t)===Ee.undefined?Qn(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}ta.create=(n,t)=>new ta({innerType:n,typeName:Le.ZodOptional,...Ke(t)});class es extends tt{_parse(t){return this._getType(t)===Ee.null?Qn(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}es.create=(n,t)=>new es({innerType:n,typeName:Le.ZodNullable,...Ke(t)});class Yp extends tt{_parse(t){const{ctx:e}=this._processInputParams(t);let r=e.data;return e.parsedType===Ee.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:e.path,parent:e})}removeDefault(){return this._def.innerType}}Yp.create=(n,t)=>new Yp({innerType:n,typeName:Le.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...Ke(t)});class Xp extends tt{_parse(t){const{ctx:e}=this._processInputParams(t),r={...e,common:{...e.common,issues:[]}},o=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return jl(o)?o.then(a=>({status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new go(r.common.issues)},input:r.data})})):{status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new go(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Xp.create=(n,t)=>new Xp({innerType:n,typeName:Le.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...Ke(t)});class jx extends tt{_parse(t){if(this._getType(t)!==Ee.nan){const r=this._getOrReturnCtx(t);return be(r,{code:de.invalid_type,expected:Ee.nan,received:r.parsedType}),Re}return{status:"valid",value:t.data}}}jx.create=n=>new jx({typeName:Le.ZodNaN,...Ke(n)});class U8 extends tt{_parse(t){const{ctx:e}=this._processInputParams(t),r=e.data;return this._def.type._parse({data:r,path:e.path,parent:e})}unwrap(){return this._def.type}}class Zp extends tt{_parse(t){const{status:e,ctx:r}=this._processInputParams(t);if(r.common.async)return(async()=>{const a=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?Re:a.status==="dirty"?(e.dirty(),xu(a.value)):this._def.out._parseAsync({data:a.value,path:r.path,parent:r})})();{const o=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?Re:o.status==="dirty"?(e.dirty(),{status:"dirty",value:o.value}):this._def.out._parseSync({data:o.value,path:r.path,parent:r})}}static create(t,e){return new Zp({in:t,out:e,typeName:Le.ZodPipeline})}}class Qp extends tt{_parse(t){const e=this._def.innerType._parse(t),r=o=>(Xi(o)&&(o.value=Object.freeze(o.value)),o);return jl(e)?e.then(o=>r(o)):r(e)}unwrap(){return this._def.innerType}}Qp.create=(n,t)=>new Qp({innerType:n,typeName:Le.ZodReadonly,...Ke(t)});function Ux(n,t){const e=typeof n=="function"?n(t):typeof n=="string"?{message:n}:n;return typeof e=="string"?{message:e}:e}function z8(n,t={},e){return n?Eu.create().superRefine((r,o)=>{const a=n(r);if(a instanceof Promise)return a.then(i=>{if(!i){const s=Ux(t,r),u=s.fatal??e??!0;o.addIssue({code:"custom",...s,fatal:u})}});if(!a){const i=Ux(t,r),s=i.fatal??e??!0;o.addIssue({code:"custom",...i,fatal:s})}}):Eu.create()}var Le;(function(n){n.ZodString="ZodString",n.ZodNumber="ZodNumber",n.ZodNaN="ZodNaN",n.ZodBigInt="ZodBigInt",n.ZodBoolean="ZodBoolean",n.ZodDate="ZodDate",n.ZodSymbol="ZodSymbol",n.ZodUndefined="ZodUndefined",n.ZodNull="ZodNull",n.ZodAny="ZodAny",n.ZodUnknown="ZodUnknown",n.ZodNever="ZodNever",n.ZodVoid="ZodVoid",n.ZodArray="ZodArray",n.ZodObject="ZodObject",n.ZodUnion="ZodUnion",n.ZodDiscriminatedUnion="ZodDiscriminatedUnion",n.ZodIntersection="ZodIntersection",n.ZodTuple="ZodTuple",n.ZodRecord="ZodRecord",n.ZodMap="ZodMap",n.ZodSet="ZodSet",n.ZodFunction="ZodFunction",n.ZodLazy="ZodLazy",n.ZodLiteral="ZodLiteral",n.ZodEnum="ZodEnum",n.ZodEffects="ZodEffects",n.ZodNativeEnum="ZodNativeEnum",n.ZodOptional="ZodOptional",n.ZodNullable="ZodNullable",n.ZodDefault="ZodDefault",n.ZodCatch="ZodCatch",n.ZodPromise="ZodPromise",n.ZodBranded="ZodBranded",n.ZodPipeline="ZodPipeline",n.ZodReadonly="ZodReadonly"})(Le||(Le={}));const ts=(n,t={message:`Input not instance of ${n.name}`})=>z8(e=>e instanceof n,t),mt=Jo.create,zx=_u.create;Eu.create,ea.create,Hr.create;const ns=Rt.create;Ul.create,zl.create,qa.create;const H8=Kp.create;Qi.create,Hl.create,ta.create,es.create;const rs=ZD,Hx=k.createContext({}),ut=({...n})=>y.jsx(Hx.Provider,{value:{name:n.name},children:y.jsx(e8,{...n})}),Gl=()=>{const n=k.useContext(Hx),t=k.useContext(Gx),{getFieldState:e,formState:r}=Bl(),o=e(n.name,r);if(!n)throw new Error("useFormField should be used within <FormField>");const{id:a}=t;return{id:a,name:n.name,formItemId:`${a}-form-item`,formDescriptionId:`${a}-form-item-description`,formMessageId:`${a}-form-item-message`,...o}},Gx=k.createContext({}),nt=k.forwardRef(({className:n,...t},e)=>{const r=k.useId();return y.jsx(Gx.Provider,{value:{id:r},children:y.jsx("div",{ref:e,className:Be("space-y-2",n),...t})})});nt.displayName="FormItem";const rt=k.forwardRef(({className:n,...t},e)=>{const{error:r,formItemId:o}=Gl();return y.jsx(Pa,{ref:e,className:Be(r&&"text-destructive",n),htmlFor:o,...t})});rt.displayName="FormLabel";const ot=k.forwardRef(({...n},t)=>{const{error:e,formItemId:r,formDescriptionId:o,formMessageId:a}=Gl();return y.jsx(qm,{ref:t,id:r,"aria-describedby":e?`${o} ${a}`:`${o}`,"aria-invalid":!!e,...n})});ot.displayName="FormControl";const G8=k.forwardRef(({className:n,...t},e)=>{const{formDescriptionId:r}=Gl();return y.jsx("p",{ref:e,id:r,className:Be("text-sm text-muted-foreground",n),...t})});G8.displayName="FormDescription";const at=k.forwardRef(({className:n,children:t,...e},r)=>{const{error:o,formMessageId:a}=Gl(),i=o?String(o==null?void 0:o.message):t;return i?y.jsx("p",{ref:r,id:a,className:Be("text-sm font-medium text-destructive",n),...e,children:i}):null});at.displayName="FormMessage";const q8=ns({bank_statement:ts(File).optional().refine(n=>n!==void 0,"Bank statement is required"),company_structure:ts(File).optional().refine(n=>n!==void 0,"Company structure document is required"),certificate_of_registration:ts(File).optional().refine(n=>n!==void 0,"Certificate of registration is required")}),K8=({data:n,onDataChange:t,onContinue:e,onBack:r,renderProgress:o})=>{const a=D.useRef(null),i=D.useRef(null),s=D.useRef(null),u=Ki({resolver:Yi(q8),defaultValues:{bank_statement:n.bank_statement||void 0,company_structure:n.company_structure||void 0,certificate_of_registration:n.certificate_of_registration||void 0}}),c=f=>{t(f),e()},l=(f,h)=>{u.setValue(f,h),t({[f]:h})},d=({field:f,label:h,description:m,inputRef:v})=>{const p=u.watch(f);return y.jsx(ut,{control:u.control,name:f,render:()=>y.jsxs(nt,{children:[y.jsx(rt,{children:h}),y.jsx(ot,{children:y.jsxs("div",{className:"border-2 border-dashed border-muted-foreground/25 rounded-lg p-6",children:[y.jsx("input",{ref:v,type:"file",accept:".pdf,.jpg,.jpeg,.png,.doc,.docx",className:"hidden",onChange:g=>{var w;const b=((w=g.target.files)==null?void 0:w[0])||null;l(f,b)}}),p?y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsxs("div",{className:"flex items-center space-x-2",children:[y.jsx(Tg,{className:"w-5 h-5 text-primary"}),y.jsx("span",{className:"text-sm font-medium",children:p.name})]}),y.jsx(_t,{type:"button",variant:"ghost",size:"sm",onClick:()=>{l(f,null),v.current&&(v.current.value="")},children:y.jsx(hc,{className:"w-4 h-4"})})]}):y.jsxs("div",{className:"text-center cursor-pointer",onClick:()=>{var g;return(g=v.current)==null?void 0:g.click()},children:[y.jsx(Og,{className:"w-8 h-8 mx-auto mb-2 text-muted-foreground"}),y.jsx("p",{className:"font-medium",children:h}),y.jsx("p",{className:"text-sm text-muted-foreground",children:m}),y.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Supported: PDF, JPG, PNG, DOC, DOCX"})]})]})}),y.jsx(at,{})]})})};return y.jsxs(un,{className:"w-full max-w-2xl mx-auto",children:[y.jsx(no,{children:y.jsx(ro,{title:"Company Documents",subTitle:"Please upload the required company documents",onBack:r})}),y.jsxs(cn,{children:[y.jsx(rs,{...u,children:y.jsxs("form",{onSubmit:u.handleSubmit(c),className:"space-y-6",children:[y.jsx(d,{field:"bank_statement",label:"Bank Statement",description:"Upload your latest bank statement",inputRef:a}),y.jsx(d,{field:"company_structure",label:"Company Structure",description:"Upload document showing directors & legal representatives",inputRef:i}),y.jsx(d,{field:"certificate_of_registration",label:"Certificate of Registration",description:"Upload your company's certificate of registration",inputRef:s}),y.jsx(_t,{type:"submit",className:"w-full",children:"Complete Verification"})]})}),y.jsx("div",{className:"mt-6",children:o()})]})]})};function qx(n,[t,e]){return Math.min(e,Math.max(t,n))}var Y8=k.createContext(void 0);function X8(n){const t=k.useContext(Y8);return n||t||"ltr"}var Jp=0;function Kx(){k.useEffect(()=>{const n=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",n[0]??Yx()),document.body.insertAdjacentElement("beforeend",n[1]??Yx()),Jp++,()=>{Jp===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Jp--}},[])}function Yx(){const n=document.createElement("span");return n.setAttribute("data-radix-focus-guard",""),n.tabIndex=0,n.style.outline="none",n.style.opacity="0",n.style.position="fixed",n.style.pointerEvents="none",n}var ev="focusScope.autoFocusOnMount",tv="focusScope.autoFocusOnUnmount",Xx={bubbles:!1,cancelable:!0},Z8="FocusScope",nv=k.forwardRef((n,t)=>{const{loop:e=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:a,...i}=n,[s,u]=k.useState(null),c=tr(o),l=tr(a),d=k.useRef(null),f=Ct(t,v=>u(v)),h=k.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;k.useEffect(()=>{if(r){let v=function(w){if(h.paused||!s)return;const x=w.target;s.contains(x)?d.current=x:na(d.current,{select:!0})},p=function(w){if(h.paused||!s)return;const x=w.relatedTarget;x!==null&&(s.contains(x)||na(d.current,{select:!0}))},g=function(w){if(document.activeElement===document.body)for(const C of w)C.removedNodes.length>0&&na(s)};document.addEventListener("focusin",v),document.addEventListener("focusout",p);const b=new MutationObserver(g);return s&&b.observe(s,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",p),b.disconnect()}}},[r,s,h.paused]),k.useEffect(()=>{if(s){Jx.add(h);const v=document.activeElement;if(!s.contains(v)){const g=new CustomEvent(ev,Xx);s.addEventListener(ev,c),s.dispatchEvent(g),g.defaultPrevented||(Q8(rF(Zx(s)),{select:!0}),document.activeElement===v&&na(s))}return()=>{s.removeEventListener(ev,c),setTimeout(()=>{const g=new CustomEvent(tv,Xx);s.addEventListener(tv,l),s.dispatchEvent(g),g.defaultPrevented||na(v??document.body,{select:!0}),s.removeEventListener(tv,l),Jx.remove(h)},0)}}},[s,c,l,h]);const m=k.useCallback(v=>{if(!e&&!r||h.paused)return;const p=v.key==="Tab"&&!v.altKey&&!v.ctrlKey&&!v.metaKey,g=document.activeElement;if(p&&g){const b=v.currentTarget,[w,x]=J8(b);w&&x?!v.shiftKey&&g===x?(v.preventDefault(),e&&na(w,{select:!0})):v.shiftKey&&g===w&&(v.preventDefault(),e&&na(x,{select:!0})):g===b&&v.preventDefault()}},[e,r,h.paused]);return y.jsx(et.div,{tabIndex:-1,...i,ref:f,onKeyDown:m})});nv.displayName=Z8;function Q8(n,{select:t=!1}={}){const e=document.activeElement;for(const r of n)if(na(r,{select:t}),document.activeElement!==e)return}function J8(n){const t=Zx(n),e=Qx(t,n),r=Qx(t.reverse(),n);return[e,r]}function Zx(n){const t=[],e=document.createTreeWalker(n,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;e.nextNode();)t.push(e.currentNode);return t}function Qx(n,t){for(const e of n)if(!eF(e,{upTo:t}))return e}function eF(n,{upTo:t}){if(getComputedStyle(n).visibility==="hidden")return!0;for(;n;){if(t!==void 0&&n===t)return!1;if(getComputedStyle(n).display==="none")return!0;n=n.parentElement}return!1}function tF(n){return n instanceof HTMLInputElement&&"select"in n}function na(n,{select:t=!1}={}){if(n&&n.focus){const e=document.activeElement;n.focus({preventScroll:!0}),n!==e&&tF(n)&&t&&n.select()}}var Jx=nF();function nF(){let n=[];return{add(t){const e=n[0];t!==e&&(e==null||e.pause()),n=ew(n,t),n.unshift(t)},remove(t){var e;n=ew(n,t),(e=n[0])==null||e.resume()}}}function ew(n,t){const e=[...n],r=e.indexOf(t);return r!==-1&&e.splice(r,1),e}function rF(n){return n.filter(t=>t.tagName!=="A")}function oF(n){const t=k.useRef({value:n,previous:n});return k.useMemo(()=>(t.current.value!==n&&(t.current.previous=t.current.value,t.current.value=n),t.current.previous),[n])}var aF=function(n){if(typeof document>"u")return null;var t=Array.isArray(n)?n[0]:n;return t.ownerDocument.body},os=new WeakMap,ql=new WeakMap,Kl={},rv=0,tw=function(n){return n&&(n.host||tw(n.parentNode))},iF=function(n,t){return t.map(function(e){if(n.contains(e))return e;var r=tw(e);return r&&n.contains(r)?r:(console.error("aria-hidden",e,"in not contained inside",n,". Doing nothing"),null)}).filter(function(e){return!!e})},sF=function(n,t,e,r){var o=iF(t,Array.isArray(n)?n:[n]);Kl[e]||(Kl[e]=new WeakMap);var a=Kl[e],i=[],s=new Set,u=new Set(o),c=function(d){!d||s.has(d)||(s.add(d),c(d.parentNode))};o.forEach(c);var l=function(d){!d||u.has(d)||Array.prototype.forEach.call(d.children,function(f){if(s.has(f))l(f);else try{var h=f.getAttribute(r),m=h!==null&&h!=="false",v=(os.get(f)||0)+1,p=(a.get(f)||0)+1;os.set(f,v),a.set(f,p),i.push(f),v===1&&m&&ql.set(f,!0),p===1&&f.setAttribute(e,"true"),m||f.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",f,g)}})};return l(t),s.clear(),rv++,function(){i.forEach(function(d){var f=os.get(d)-1,h=a.get(d)-1;os.set(d,f),a.set(d,h),f||(ql.has(d)||d.removeAttribute(r),ql.delete(d)),h||d.removeAttribute(e)}),rv--,rv||(os=new WeakMap,os=new WeakMap,ql=new WeakMap,Kl={})}},nw=function(n,t,e){e===void 0&&(e="data-aria-hidden");var r=Array.from(Array.isArray(n)?n:[n]),o=aF(n);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),sF(r,o,e,"aria-hidden")):function(){return null}},Gr=function(){return Gr=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++){e=arguments[r];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a])}return t},Gr.apply(this,arguments)};function rw(n,t){var e={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(n);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(n,r[o])&&(e[r[o]]=n[r[o]]);return e}function uF(n,t,e){if(e||arguments.length===2)for(var r=0,o=t.length,a;r<o;r++)(a||!(r in t))&&(a||(a=Array.prototype.slice.call(t,0,r)),a[r]=t[r]);return n.concat(a||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var Yl="right-scroll-bar-position",Xl="width-before-scroll-bar",cF="with-scroll-bars-hidden",lF="--removed-body-scroll-bar-size";function ov(n,t){return typeof n=="function"?n(t):n&&(n.current=t),n}function dF(n,t){var e=D.useState(function(){return{value:n,callback:t,facade:{get current(){return e.value},set current(r){var o=e.value;o!==r&&(e.value=r,e.callback(r,o))}}}})[0];return e.callback=t,e.facade}var fF=typeof window<"u"?k.useLayoutEffect:k.useEffect,ow=new WeakMap;function hF(n,t){var e=dF(null,function(r){return n.forEach(function(o){return ov(o,r)})});return fF(function(){var r=ow.get(e);if(r){var o=new Set(r),a=new Set(n),i=e.current;o.forEach(function(s){a.has(s)||ov(s,null)}),a.forEach(function(s){o.has(s)||ov(s,i)})}ow.set(e,n)},[n]),e}function pF(n){return n}function vF(n,t){t===void 0&&(t=pF);var e=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return e.length?e[e.length-1]:n},useMedium:function(a){var i=t(a,r);return e.push(i),function(){e=e.filter(function(s){return s!==i})}},assignSyncMedium:function(a){for(r=!0;e.length;){var i=e;e=[],i.forEach(a)}e={push:function(s){return a(s)},filter:function(){return e}}},assignMedium:function(a){r=!0;var i=[];if(e.length){var s=e;e=[],s.forEach(a),i=e}var u=function(){var l=i;i=[],l.forEach(a)},c=function(){return Promise.resolve().then(u)};c(),e={push:function(l){i.push(l),c()},filter:function(l){return i=i.filter(l),e}}}};return o}function mF(n){n===void 0&&(n={});var t=vF(null);return t.options=Gr({async:!0,ssr:!1},n),t}var aw=function(n){var t=n.sideCar,e=rw(n,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return k.createElement(r,Gr({},e))};aw.isSideCarExport=!0;function gF(n,t){return n.useMedium(t),aw}var iw=mF(),av=function(){},Zl=k.forwardRef(function(n,t){var e=k.useRef(null),r=k.useState({onScrollCapture:av,onWheelCapture:av,onTouchMoveCapture:av}),o=r[0],a=r[1],i=n.forwardProps,s=n.children,u=n.className,c=n.removeScrollBar,l=n.enabled,d=n.shards,f=n.sideCar,h=n.noRelative,m=n.noIsolation,v=n.inert,p=n.allowPinchZoom,g=n.as,b=g===void 0?"div":g,w=n.gapMode,x=rw(n,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=f,_=hF([e,t]),E=Gr(Gr({},x),o);return k.createElement(k.Fragment,null,l&&k.createElement(C,{sideCar:iw,removeScrollBar:c,shards:d,noRelative:h,noIsolation:m,inert:v,setCallbacks:a,allowPinchZoom:!!p,lockRef:e,gapMode:w}),i?k.cloneElement(k.Children.only(s),Gr(Gr({},E),{ref:_})):k.createElement(b,Gr({},E,{className:u,ref:_}),s))});Zl.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Zl.classNames={fullWidth:Xl,zeroRight:Yl};var yF=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function bF(){if(!document)return null;var n=document.createElement("style");n.type="text/css";var t=yF();return t&&n.setAttribute("nonce",t),n}function xF(n,t){n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}function wF(n){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(n)}var CF=function(){var n=0,t=null;return{add:function(e){n==0&&(t=bF())&&(xF(t,e),wF(t)),n++},remove:function(){n--,!n&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},_F=function(){var n=CF();return function(t,e){k.useEffect(function(){return n.add(t),function(){n.remove()}},[t&&e])}},sw=function(){var n=_F(),t=function(e){var r=e.styles,o=e.dynamic;return n(r,o),null};return t},EF={left:0,top:0,right:0,gap:0},iv=function(n){return parseInt(n||"",10)||0},SF=function(n){var t=window.getComputedStyle(document.body),e=t[n==="padding"?"paddingLeft":"marginLeft"],r=t[n==="padding"?"paddingTop":"marginTop"],o=t[n==="padding"?"paddingRight":"marginRight"];return[iv(e),iv(r),iv(o)]},NF=function(n){if(n===void 0&&(n="margin"),typeof window>"u")return EF;var t=SF(n),e=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-e+t[2]-t[0])}},$F=sw(),as="data-scroll-locked",kF=function(n,t,e,r){var o=n.left,a=n.top,i=n.right,s=n.gap;return e===void 0&&(e="margin"),`
3930
3930
  .`.concat(cF,` {
3931
3931
  overflow: hidden `).concat(r,`;
3932
3932
  padding-right: `).concat(s,"px ").concat(r,`;